blob: 7596485ec5435975a7ec09f34180fa99dca9d18d [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 {
1140 name: "SkipChangeCipherSpec-Client",
1141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001142 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001143 Bugs: ProtocolBugs{
1144 SkipChangeCipherSpec: true,
1145 },
1146 },
1147 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001148 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001149 },
1150 {
1151 testType: serverTest,
1152 name: "SkipChangeCipherSpec-Server",
1153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001154 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001155 Bugs: ProtocolBugs{
1156 SkipChangeCipherSpec: true,
1157 },
1158 },
1159 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001160 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001161 },
1162 {
1163 testType: serverTest,
1164 name: "SkipChangeCipherSpec-Server-NPN",
1165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001166 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001167 NextProtos: []string{"bar"},
1168 Bugs: ProtocolBugs{
1169 SkipChangeCipherSpec: true,
1170 },
1171 },
1172 flags: []string{
1173 "-advertise-npn", "\x03foo\x03bar\x03baz",
1174 },
1175 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001176 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001177 },
1178 {
1179 name: "FragmentAcrossChangeCipherSpec-Client",
1180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001181 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001182 Bugs: ProtocolBugs{
1183 FragmentAcrossChangeCipherSpec: true,
1184 },
1185 },
1186 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001187 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001188 },
1189 {
1190 testType: serverTest,
1191 name: "FragmentAcrossChangeCipherSpec-Server",
1192 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001193 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001194 Bugs: ProtocolBugs{
1195 FragmentAcrossChangeCipherSpec: true,
1196 },
1197 },
1198 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001199 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001200 },
1201 {
1202 testType: serverTest,
1203 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1204 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001205 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001206 NextProtos: []string{"bar"},
1207 Bugs: ProtocolBugs{
1208 FragmentAcrossChangeCipherSpec: true,
1209 },
1210 },
1211 flags: []string{
1212 "-advertise-npn", "\x03foo\x03bar\x03baz",
1213 },
1214 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001215 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001216 },
1217 {
1218 testType: serverTest,
1219 name: "Alert",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 SendSpuriousAlert: alertRecordOverflow,
1223 },
1224 },
1225 shouldFail: true,
1226 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1227 },
1228 {
1229 protocol: dtls,
1230 testType: serverTest,
1231 name: "Alert-DTLS",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 SendSpuriousAlert: alertRecordOverflow,
1235 },
1236 },
1237 shouldFail: true,
1238 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1239 },
1240 {
1241 testType: serverTest,
1242 name: "FragmentAlert",
1243 config: Config{
1244 Bugs: ProtocolBugs{
1245 FragmentAlert: true,
1246 SendSpuriousAlert: alertRecordOverflow,
1247 },
1248 },
1249 shouldFail: true,
1250 expectedError: ":BAD_ALERT:",
1251 },
1252 {
1253 protocol: dtls,
1254 testType: serverTest,
1255 name: "FragmentAlert-DTLS",
1256 config: Config{
1257 Bugs: ProtocolBugs{
1258 FragmentAlert: true,
1259 SendSpuriousAlert: alertRecordOverflow,
1260 },
1261 },
1262 shouldFail: true,
1263 expectedError: ":BAD_ALERT:",
1264 },
1265 {
1266 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001267 name: "DoubleAlert",
1268 config: Config{
1269 Bugs: ProtocolBugs{
1270 DoubleAlert: true,
1271 SendSpuriousAlert: alertRecordOverflow,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":BAD_ALERT:",
1276 },
1277 {
1278 protocol: dtls,
1279 testType: serverTest,
1280 name: "DoubleAlert-DTLS",
1281 config: Config{
1282 Bugs: ProtocolBugs{
1283 DoubleAlert: true,
1284 SendSpuriousAlert: alertRecordOverflow,
1285 },
1286 },
1287 shouldFail: true,
1288 expectedError: ":BAD_ALERT:",
1289 },
1290 {
1291 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001292 name: "EarlyChangeCipherSpec-server-1",
1293 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001294 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001295 Bugs: ProtocolBugs{
1296 EarlyChangeCipherSpec: 1,
1297 },
1298 },
1299 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001300 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001301 },
1302 {
1303 testType: serverTest,
1304 name: "EarlyChangeCipherSpec-server-2",
1305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001306 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 Bugs: ProtocolBugs{
1308 EarlyChangeCipherSpec: 2,
1309 },
1310 },
1311 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001312 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001313 },
1314 {
David Benjamin8144f992016-06-22 17:05:13 -04001315 protocol: dtls,
1316 name: "StrayChangeCipherSpec",
1317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001318 // TODO(davidben): Once DTLS 1.3 exists, test
1319 // that stray ChangeCipherSpec messages are
1320 // rejected.
1321 MaxVersion: VersionTLS12,
David Benjamin8144f992016-06-22 17:05:13 -04001322 Bugs: ProtocolBugs{
1323 StrayChangeCipherSpec: true,
1324 },
1325 },
1326 },
1327 {
Adam Langley7c803a62015-06-15 15:35:05 -07001328 name: "SkipNewSessionTicket",
1329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001330 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001331 Bugs: ProtocolBugs{
1332 SkipNewSessionTicket: true,
1333 },
1334 },
1335 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001336 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001337 },
1338 {
1339 testType: serverTest,
1340 name: "FallbackSCSV",
1341 config: Config{
1342 MaxVersion: VersionTLS11,
1343 Bugs: ProtocolBugs{
1344 SendFallbackSCSV: true,
1345 },
1346 },
1347 shouldFail: true,
1348 expectedError: ":INAPPROPRIATE_FALLBACK:",
1349 },
1350 {
1351 testType: serverTest,
1352 name: "FallbackSCSV-VersionMatch",
1353 config: Config{
1354 Bugs: ProtocolBugs{
1355 SendFallbackSCSV: true,
1356 },
1357 },
1358 },
1359 {
1360 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001361 name: "FallbackSCSV-VersionMatch-TLS12",
1362 config: Config{
1363 MaxVersion: VersionTLS12,
1364 Bugs: ProtocolBugs{
1365 SendFallbackSCSV: true,
1366 },
1367 },
1368 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1369 },
1370 {
1371 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001372 name: "FragmentedClientVersion",
1373 config: Config{
1374 Bugs: ProtocolBugs{
1375 MaxHandshakeRecordLength: 1,
1376 FragmentClientVersion: true,
1377 },
1378 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001379 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001380 },
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 testType: serverTest,
1383 name: "HttpGET",
1384 sendPrefix: "GET / HTTP/1.0\n",
1385 shouldFail: true,
1386 expectedError: ":HTTP_REQUEST:",
1387 },
1388 {
1389 testType: serverTest,
1390 name: "HttpPOST",
1391 sendPrefix: "POST / HTTP/1.0\n",
1392 shouldFail: true,
1393 expectedError: ":HTTP_REQUEST:",
1394 },
1395 {
1396 testType: serverTest,
1397 name: "HttpHEAD",
1398 sendPrefix: "HEAD / HTTP/1.0\n",
1399 shouldFail: true,
1400 expectedError: ":HTTP_REQUEST:",
1401 },
1402 {
1403 testType: serverTest,
1404 name: "HttpPUT",
1405 sendPrefix: "PUT / HTTP/1.0\n",
1406 shouldFail: true,
1407 expectedError: ":HTTP_REQUEST:",
1408 },
1409 {
1410 testType: serverTest,
1411 name: "HttpCONNECT",
1412 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1413 shouldFail: true,
1414 expectedError: ":HTTPS_PROXY_REQUEST:",
1415 },
1416 {
1417 testType: serverTest,
1418 name: "Garbage",
1419 sendPrefix: "blah",
1420 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001421 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001422 },
1423 {
Adam Langley7c803a62015-06-15 15:35:05 -07001424 name: "RSAEphemeralKey",
1425 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001426 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001427 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1428 Bugs: ProtocolBugs{
1429 RSAEphemeralKey: true,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":UNEXPECTED_MESSAGE:",
1434 },
1435 {
1436 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001437 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001438 shouldFail: true,
1439 expectedError: ":WRONG_SSL_VERSION:",
1440 },
1441 {
1442 protocol: dtls,
1443 name: "DisableEverything-DTLS",
1444 flags: []string{"-no-tls12", "-no-tls1"},
1445 shouldFail: true,
1446 expectedError: ":WRONG_SSL_VERSION:",
1447 },
1448 {
Adam Langley7c803a62015-06-15 15:35:05 -07001449 protocol: dtls,
1450 testType: serverTest,
1451 name: "MTU",
1452 config: Config{
1453 Bugs: ProtocolBugs{
1454 MaxPacketLength: 256,
1455 },
1456 },
1457 flags: []string{"-mtu", "256"},
1458 },
1459 {
1460 protocol: dtls,
1461 testType: serverTest,
1462 name: "MTUExceeded",
1463 config: Config{
1464 Bugs: ProtocolBugs{
1465 MaxPacketLength: 255,
1466 },
1467 },
1468 flags: []string{"-mtu", "256"},
1469 shouldFail: true,
1470 expectedLocalError: "dtls: exceeded maximum packet length",
1471 },
1472 {
1473 name: "CertMismatchRSA",
1474 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001475 // TODO(davidben): Add a TLS 1.3 version of this test.
1476 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001477 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1478 Certificates: []Certificate{getECDSACertificate()},
1479 Bugs: ProtocolBugs{
1480 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1485 },
1486 {
1487 name: "CertMismatchECDSA",
1488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001489 // TODO(davidben): Add a TLS 1.3 version of this test.
1490 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1492 Certificates: []Certificate{getRSACertificate()},
1493 Bugs: ProtocolBugs{
1494 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1495 },
1496 },
1497 shouldFail: true,
1498 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1499 },
1500 {
1501 name: "EmptyCertificateList",
1502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001503 // TODO(davidben): Add a TLS 1.3 version of this test.
1504 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1506 Bugs: ProtocolBugs{
1507 EmptyCertificateList: true,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":DECODE_ERROR:",
1512 },
1513 {
1514 name: "TLSFatalBadPackets",
1515 damageFirstWrite: true,
1516 shouldFail: true,
1517 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1518 },
1519 {
1520 protocol: dtls,
1521 name: "DTLSIgnoreBadPackets",
1522 damageFirstWrite: true,
1523 },
1524 {
1525 protocol: dtls,
1526 name: "DTLSIgnoreBadPackets-Async",
1527 damageFirstWrite: true,
1528 flags: []string{"-async"},
1529 },
1530 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001531 name: "AppDataBeforeHandshake",
1532 config: Config{
1533 Bugs: ProtocolBugs{
1534 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":UNEXPECTED_RECORD:",
1539 },
1540 {
1541 name: "AppDataBeforeHandshake-Empty",
1542 config: Config{
1543 Bugs: ProtocolBugs{
1544 AppDataBeforeHandshake: []byte{},
1545 },
1546 },
1547 shouldFail: true,
1548 expectedError: ":UNEXPECTED_RECORD:",
1549 },
1550 {
1551 protocol: dtls,
1552 name: "AppDataBeforeHandshake-DTLS",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":UNEXPECTED_RECORD:",
1560 },
1561 {
1562 protocol: dtls,
1563 name: "AppDataBeforeHandshake-DTLS-Empty",
1564 config: Config{
1565 Bugs: ProtocolBugs{
1566 AppDataBeforeHandshake: []byte{},
1567 },
1568 },
1569 shouldFail: true,
1570 expectedError: ":UNEXPECTED_RECORD:",
1571 },
1572 {
Adam Langley7c803a62015-06-15 15:35:05 -07001573 name: "AppDataAfterChangeCipherSpec",
1574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001575 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001576 Bugs: ProtocolBugs{
1577 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1578 },
1579 },
1580 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001581 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001582 },
1583 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001584 name: "AppDataAfterChangeCipherSpec-Empty",
1585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001586 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001587 Bugs: ProtocolBugs{
1588 AppDataAfterChangeCipherSpec: []byte{},
1589 },
1590 },
1591 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001592 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001593 },
1594 {
Adam Langley7c803a62015-06-15 15:35:05 -07001595 protocol: dtls,
1596 name: "AppDataAfterChangeCipherSpec-DTLS",
1597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001598 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001599 Bugs: ProtocolBugs{
1600 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1601 },
1602 },
1603 // BoringSSL's DTLS implementation will drop the out-of-order
1604 // application data.
1605 },
1606 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001607 protocol: dtls,
1608 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001610 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001611 Bugs: ProtocolBugs{
1612 AppDataAfterChangeCipherSpec: []byte{},
1613 },
1614 },
1615 // BoringSSL's DTLS implementation will drop the out-of-order
1616 // application data.
1617 },
1618 {
Adam Langley7c803a62015-06-15 15:35:05 -07001619 name: "AlertAfterChangeCipherSpec",
1620 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001621 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001622 Bugs: ProtocolBugs{
1623 AlertAfterChangeCipherSpec: alertRecordOverflow,
1624 },
1625 },
1626 shouldFail: true,
1627 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1628 },
1629 {
1630 protocol: dtls,
1631 name: "AlertAfterChangeCipherSpec-DTLS",
1632 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001633 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001634 Bugs: ProtocolBugs{
1635 AlertAfterChangeCipherSpec: alertRecordOverflow,
1636 },
1637 },
1638 shouldFail: true,
1639 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1640 },
1641 {
1642 protocol: dtls,
1643 name: "ReorderHandshakeFragments-Small-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 ReorderHandshakeFragments: true,
1647 // Small enough that every handshake message is
1648 // fragmented.
1649 MaxHandshakeRecordLength: 2,
1650 },
1651 },
1652 },
1653 {
1654 protocol: dtls,
1655 name: "ReorderHandshakeFragments-Large-DTLS",
1656 config: Config{
1657 Bugs: ProtocolBugs{
1658 ReorderHandshakeFragments: true,
1659 // Large enough that no handshake message is
1660 // fragmented.
1661 MaxHandshakeRecordLength: 2048,
1662 },
1663 },
1664 },
1665 {
1666 protocol: dtls,
1667 name: "MixCompleteMessageWithFragments-DTLS",
1668 config: Config{
1669 Bugs: ProtocolBugs{
1670 ReorderHandshakeFragments: true,
1671 MixCompleteMessageWithFragments: true,
1672 MaxHandshakeRecordLength: 2,
1673 },
1674 },
1675 },
1676 {
1677 name: "SendInvalidRecordType",
1678 config: Config{
1679 Bugs: ProtocolBugs{
1680 SendInvalidRecordType: true,
1681 },
1682 },
1683 shouldFail: true,
1684 expectedError: ":UNEXPECTED_RECORD:",
1685 },
1686 {
1687 protocol: dtls,
1688 name: "SendInvalidRecordType-DTLS",
1689 config: Config{
1690 Bugs: ProtocolBugs{
1691 SendInvalidRecordType: true,
1692 },
1693 },
1694 shouldFail: true,
1695 expectedError: ":UNEXPECTED_RECORD:",
1696 },
1697 {
1698 name: "FalseStart-SkipServerSecondLeg",
1699 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001700 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001701 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1702 NextProtos: []string{"foo"},
1703 Bugs: ProtocolBugs{
1704 SkipNewSessionTicket: true,
1705 SkipChangeCipherSpec: true,
1706 SkipFinished: true,
1707 ExpectFalseStart: true,
1708 },
1709 },
1710 flags: []string{
1711 "-false-start",
1712 "-handshake-never-done",
1713 "-advertise-alpn", "\x03foo",
1714 },
1715 shimWritesFirst: true,
1716 shouldFail: true,
1717 expectedError: ":UNEXPECTED_RECORD:",
1718 },
1719 {
1720 name: "FalseStart-SkipServerSecondLeg-Implicit",
1721 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001722 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001723 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1724 NextProtos: []string{"foo"},
1725 Bugs: ProtocolBugs{
1726 SkipNewSessionTicket: true,
1727 SkipChangeCipherSpec: true,
1728 SkipFinished: true,
1729 },
1730 },
1731 flags: []string{
1732 "-implicit-handshake",
1733 "-false-start",
1734 "-handshake-never-done",
1735 "-advertise-alpn", "\x03foo",
1736 },
1737 shouldFail: true,
1738 expectedError: ":UNEXPECTED_RECORD:",
1739 },
1740 {
1741 testType: serverTest,
1742 name: "FailEarlyCallback",
1743 flags: []string{"-fail-early-callback"},
1744 shouldFail: true,
1745 expectedError: ":CONNECTION_REJECTED:",
1746 expectedLocalError: "remote error: access denied",
1747 },
1748 {
1749 name: "WrongMessageType",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 WrongCertificateMessageType: true,
1753 },
1754 },
1755 shouldFail: true,
1756 expectedError: ":UNEXPECTED_MESSAGE:",
1757 expectedLocalError: "remote error: unexpected message",
1758 },
1759 {
1760 protocol: dtls,
1761 name: "WrongMessageType-DTLS",
1762 config: Config{
1763 Bugs: ProtocolBugs{
1764 WrongCertificateMessageType: true,
1765 },
1766 },
1767 shouldFail: true,
1768 expectedError: ":UNEXPECTED_MESSAGE:",
1769 expectedLocalError: "remote error: unexpected message",
1770 },
1771 {
1772 protocol: dtls,
1773 name: "FragmentMessageTypeMismatch-DTLS",
1774 config: Config{
1775 Bugs: ProtocolBugs{
1776 MaxHandshakeRecordLength: 2,
1777 FragmentMessageTypeMismatch: true,
1778 },
1779 },
1780 shouldFail: true,
1781 expectedError: ":FRAGMENT_MISMATCH:",
1782 },
1783 {
1784 protocol: dtls,
1785 name: "FragmentMessageLengthMismatch-DTLS",
1786 config: Config{
1787 Bugs: ProtocolBugs{
1788 MaxHandshakeRecordLength: 2,
1789 FragmentMessageLengthMismatch: true,
1790 },
1791 },
1792 shouldFail: true,
1793 expectedError: ":FRAGMENT_MISMATCH:",
1794 },
1795 {
1796 protocol: dtls,
1797 name: "SplitFragments-Header-DTLS",
1798 config: Config{
1799 Bugs: ProtocolBugs{
1800 SplitFragments: 2,
1801 },
1802 },
1803 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001804 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001805 },
1806 {
1807 protocol: dtls,
1808 name: "SplitFragments-Boundary-DTLS",
1809 config: Config{
1810 Bugs: ProtocolBugs{
1811 SplitFragments: dtlsRecordHeaderLen,
1812 },
1813 },
1814 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001815 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001816 },
1817 {
1818 protocol: dtls,
1819 name: "SplitFragments-Body-DTLS",
1820 config: Config{
1821 Bugs: ProtocolBugs{
1822 SplitFragments: dtlsRecordHeaderLen + 1,
1823 },
1824 },
1825 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001826 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001827 },
1828 {
1829 protocol: dtls,
1830 name: "SendEmptyFragments-DTLS",
1831 config: Config{
1832 Bugs: ProtocolBugs{
1833 SendEmptyFragments: true,
1834 },
1835 },
1836 },
1837 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001838 name: "BadFinished-Client",
1839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001840 // TODO(davidben): Add a TLS 1.3 version of this.
1841 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001842 Bugs: ProtocolBugs{
1843 BadFinished: true,
1844 },
1845 },
1846 shouldFail: true,
1847 expectedError: ":DIGEST_CHECK_FAILED:",
1848 },
1849 {
1850 testType: serverTest,
1851 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001853 // TODO(davidben): Add a TLS 1.3 version of this.
1854 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001855 Bugs: ProtocolBugs{
1856 BadFinished: true,
1857 },
1858 },
1859 shouldFail: true,
1860 expectedError: ":DIGEST_CHECK_FAILED:",
1861 },
1862 {
1863 name: "FalseStart-BadFinished",
1864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001865 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1867 NextProtos: []string{"foo"},
1868 Bugs: ProtocolBugs{
1869 BadFinished: true,
1870 ExpectFalseStart: true,
1871 },
1872 },
1873 flags: []string{
1874 "-false-start",
1875 "-handshake-never-done",
1876 "-advertise-alpn", "\x03foo",
1877 },
1878 shimWritesFirst: true,
1879 shouldFail: true,
1880 expectedError: ":DIGEST_CHECK_FAILED:",
1881 },
1882 {
1883 name: "NoFalseStart-NoALPN",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1887 Bugs: ProtocolBugs{
1888 ExpectFalseStart: true,
1889 AlertBeforeFalseStartTest: alertAccessDenied,
1890 },
1891 },
1892 flags: []string{
1893 "-false-start",
1894 },
1895 shimWritesFirst: true,
1896 shouldFail: true,
1897 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1898 expectedLocalError: "tls: peer did not false start: EOF",
1899 },
1900 {
1901 name: "NoFalseStart-NoAEAD",
1902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001903 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1905 NextProtos: []string{"foo"},
1906 Bugs: ProtocolBugs{
1907 ExpectFalseStart: true,
1908 AlertBeforeFalseStartTest: alertAccessDenied,
1909 },
1910 },
1911 flags: []string{
1912 "-false-start",
1913 "-advertise-alpn", "\x03foo",
1914 },
1915 shimWritesFirst: true,
1916 shouldFail: true,
1917 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1918 expectedLocalError: "tls: peer did not false start: EOF",
1919 },
1920 {
1921 name: "NoFalseStart-RSA",
1922 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001923 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001924 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1925 NextProtos: []string{"foo"},
1926 Bugs: ProtocolBugs{
1927 ExpectFalseStart: true,
1928 AlertBeforeFalseStartTest: alertAccessDenied,
1929 },
1930 },
1931 flags: []string{
1932 "-false-start",
1933 "-advertise-alpn", "\x03foo",
1934 },
1935 shimWritesFirst: true,
1936 shouldFail: true,
1937 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1938 expectedLocalError: "tls: peer did not false start: EOF",
1939 },
1940 {
1941 name: "NoFalseStart-DHE_RSA",
1942 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001943 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001944 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1945 NextProtos: []string{"foo"},
1946 Bugs: ProtocolBugs{
1947 ExpectFalseStart: true,
1948 AlertBeforeFalseStartTest: alertAccessDenied,
1949 },
1950 },
1951 flags: []string{
1952 "-false-start",
1953 "-advertise-alpn", "\x03foo",
1954 },
1955 shimWritesFirst: true,
1956 shouldFail: true,
1957 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1958 expectedLocalError: "tls: peer did not false start: EOF",
1959 },
1960 {
Adam Langley7c803a62015-06-15 15:35:05 -07001961 protocol: dtls,
1962 name: "SendSplitAlert-Sync",
1963 config: Config{
1964 Bugs: ProtocolBugs{
1965 SendSplitAlert: true,
1966 },
1967 },
1968 },
1969 {
1970 protocol: dtls,
1971 name: "SendSplitAlert-Async",
1972 config: Config{
1973 Bugs: ProtocolBugs{
1974 SendSplitAlert: true,
1975 },
1976 },
1977 flags: []string{"-async"},
1978 },
1979 {
1980 protocol: dtls,
1981 name: "PackDTLSHandshake",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 MaxHandshakeRecordLength: 2,
1985 PackHandshakeFragments: 20,
1986 PackHandshakeRecords: 200,
1987 },
1988 },
1989 },
1990 {
Adam Langley7c803a62015-06-15 15:35:05 -07001991 name: "SendEmptyRecords-Pass",
1992 sendEmptyRecords: 32,
1993 },
1994 {
1995 name: "SendEmptyRecords",
1996 sendEmptyRecords: 33,
1997 shouldFail: true,
1998 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1999 },
2000 {
2001 name: "SendEmptyRecords-Async",
2002 sendEmptyRecords: 33,
2003 flags: []string{"-async"},
2004 shouldFail: true,
2005 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2006 },
2007 {
2008 name: "SendWarningAlerts-Pass",
2009 sendWarningAlerts: 4,
2010 },
2011 {
2012 protocol: dtls,
2013 name: "SendWarningAlerts-DTLS-Pass",
2014 sendWarningAlerts: 4,
2015 },
2016 {
2017 name: "SendWarningAlerts",
2018 sendWarningAlerts: 5,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2021 },
2022 {
2023 name: "SendWarningAlerts-Async",
2024 sendWarningAlerts: 5,
2025 flags: []string{"-async"},
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2028 },
David Benjaminba4594a2015-06-18 18:36:15 -04002029 {
2030 name: "EmptySessionID",
2031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002032 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002033 SessionTicketsDisabled: true,
2034 },
2035 noSessionCache: true,
2036 flags: []string{"-expect-no-session"},
2037 },
David Benjamin30789da2015-08-29 22:56:45 -04002038 {
2039 name: "Unclean-Shutdown",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 NoCloseNotify: true,
2043 ExpectCloseNotify: true,
2044 },
2045 },
2046 shimShutsDown: true,
2047 flags: []string{"-check-close-notify"},
2048 shouldFail: true,
2049 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2050 },
2051 {
2052 name: "Unclean-Shutdown-Ignored",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 NoCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002060 {
David Benjaminfa214e42016-05-10 17:03:10 -04002061 name: "Unclean-Shutdown-Alert",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendAlertOnShutdown: alertDecompressionFailure,
2065 ExpectCloseNotify: true,
2066 },
2067 },
2068 shimShutsDown: true,
2069 flags: []string{"-check-close-notify"},
2070 shouldFail: true,
2071 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2072 },
2073 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002074 name: "LargePlaintext",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 SendLargeRecords: true,
2078 },
2079 },
2080 messageLen: maxPlaintext + 1,
2081 shouldFail: true,
2082 expectedError: ":DATA_LENGTH_TOO_LONG:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "LargePlaintext-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 messageLen: maxPlaintext + 1,
2093 shouldFail: true,
2094 expectedError: ":DATA_LENGTH_TOO_LONG:",
2095 },
2096 {
2097 name: "LargeCiphertext",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 messageLen: maxPlaintext * 2,
2104 shouldFail: true,
2105 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2106 },
2107 {
2108 protocol: dtls,
2109 name: "LargeCiphertext-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 messageLen: maxPlaintext * 2,
2116 // Unlike the other four cases, DTLS drops records which
2117 // are invalid before authentication, so the connection
2118 // does not fail.
2119 expectMessageDropped: true,
2120 },
David Benjamindd6fed92015-10-23 17:41:12 -04002121 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 // In TLS 1.2 and below, empty NewSessionTicket messages
2123 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002124 name: "SendEmptySessionTicket",
2125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002127 Bugs: ProtocolBugs{
2128 SendEmptySessionTicket: true,
2129 FailIfSessionOffered: true,
2130 },
2131 },
2132 flags: []string{"-expect-no-session"},
2133 resumeSession: true,
2134 expectResumeRejected: true,
2135 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002136 {
David Benjamin8411b242015-11-26 12:07:28 -05002137 name: "BadChangeCipherSpec-1",
2138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002139 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002140 Bugs: ProtocolBugs{
2141 BadChangeCipherSpec: []byte{2},
2142 },
2143 },
2144 shouldFail: true,
2145 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2146 },
2147 {
2148 name: "BadChangeCipherSpec-2",
2149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002150 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002151 Bugs: ProtocolBugs{
2152 BadChangeCipherSpec: []byte{1, 1},
2153 },
2154 },
2155 shouldFail: true,
2156 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2157 },
2158 {
2159 protocol: dtls,
2160 name: "BadChangeCipherSpec-DTLS-1",
2161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002162 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002163 Bugs: ProtocolBugs{
2164 BadChangeCipherSpec: []byte{2},
2165 },
2166 },
2167 shouldFail: true,
2168 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2169 },
2170 {
2171 protocol: dtls,
2172 name: "BadChangeCipherSpec-DTLS-2",
2173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002174 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002175 Bugs: ProtocolBugs{
2176 BadChangeCipherSpec: []byte{1, 1},
2177 },
2178 },
2179 shouldFail: true,
2180 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2181 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002182 {
2183 name: "BadHelloRequest-1",
2184 renegotiate: 1,
2185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002186 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002187 Bugs: ProtocolBugs{
2188 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2189 },
2190 },
2191 flags: []string{
2192 "-renegotiate-freely",
2193 "-expect-total-renegotiations", "1",
2194 },
2195 shouldFail: true,
2196 expectedError: ":BAD_HELLO_REQUEST:",
2197 },
2198 {
2199 name: "BadHelloRequest-2",
2200 renegotiate: 1,
2201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002202 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002203 Bugs: ProtocolBugs{
2204 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2205 },
2206 },
2207 flags: []string{
2208 "-renegotiate-freely",
2209 "-expect-total-renegotiations", "1",
2210 },
2211 shouldFail: true,
2212 expectedError: ":BAD_HELLO_REQUEST:",
2213 },
David Benjaminef1b0092015-11-21 14:05:44 -05002214 {
2215 testType: serverTest,
2216 name: "SupportTicketsWithSessionID",
2217 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002218 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002219 SessionTicketsDisabled: true,
2220 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002221 resumeConfig: &Config{
2222 MaxVersion: VersionTLS12,
2223 },
David Benjaminef1b0092015-11-21 14:05:44 -05002224 resumeSession: true,
2225 },
Adam Langley7c803a62015-06-15 15:35:05 -07002226 }
Adam Langley7c803a62015-06-15 15:35:05 -07002227 testCases = append(testCases, basicTests...)
2228}
2229
Adam Langley95c29f32014-06-20 12:00:00 -07002230func addCipherSuiteTests() {
2231 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002232 const psk = "12345"
2233 const pskIdentity = "luggage combo"
2234
Adam Langley95c29f32014-06-20 12:00:00 -07002235 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002236 var certFile string
2237 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002238 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002239 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002240 certFile = ecdsaCertificateFile
2241 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002242 } else {
2243 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002244 certFile = rsaCertificateFile
2245 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002246 }
2247
David Benjamin48cae082014-10-27 01:06:24 -04002248 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002249 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002250 flags = append(flags,
2251 "-psk", psk,
2252 "-psk-identity", pskIdentity)
2253 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002254 if hasComponent(suite.name, "NULL") {
2255 // NULL ciphers must be explicitly enabled.
2256 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2257 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002258 if hasComponent(suite.name, "CECPQ1") {
2259 // CECPQ1 ciphers must be explicitly enabled.
2260 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2261 }
David Benjamin48cae082014-10-27 01:06:24 -04002262
Adam Langley95c29f32014-06-20 12:00:00 -07002263 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002264 for _, protocol := range []protocol{tls, dtls} {
2265 var prefix string
2266 if protocol == dtls {
2267 if !ver.hasDTLS {
2268 continue
2269 }
2270 prefix = "D"
2271 }
Adam Langley95c29f32014-06-20 12:00:00 -07002272
David Benjamin0407e762016-06-17 16:41:18 -04002273 var shouldServerFail, shouldClientFail bool
2274 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2275 // BoringSSL clients accept ECDHE on SSLv3, but
2276 // a BoringSSL server will never select it
2277 // because the extension is missing.
2278 shouldServerFail = true
2279 }
2280 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2281 shouldClientFail = true
2282 shouldServerFail = true
2283 }
Nick Harper1fd39d82016-06-14 18:14:35 -07002284 if !isTLS13Suite(suite.name) && ver.version == VersionTLS13 {
2285 shouldClientFail = true
2286 shouldServerFail = true
2287 }
David Benjamin0407e762016-06-17 16:41:18 -04002288 if !isDTLSCipher(suite.name) && protocol == dtls {
2289 shouldClientFail = true
2290 shouldServerFail = true
2291 }
David Benjamin4298d772015-12-19 00:18:25 -05002292
David Benjamin0407e762016-06-17 16:41:18 -04002293 var expectedServerError, expectedClientError string
2294 if shouldServerFail {
2295 expectedServerError = ":NO_SHARED_CIPHER:"
2296 }
2297 if shouldClientFail {
2298 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2299 }
David Benjamin025b3d32014-07-01 19:53:04 -04002300
David Benjamin6fd297b2014-08-11 18:43:38 -04002301 testCases = append(testCases, testCase{
2302 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002303 protocol: protocol,
2304
2305 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002306 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002307 MinVersion: ver.version,
2308 MaxVersion: ver.version,
2309 CipherSuites: []uint16{suite.id},
2310 Certificates: []Certificate{cert},
2311 PreSharedKey: []byte(psk),
2312 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002313 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002314 EnableAllCiphers: shouldServerFail,
2315 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002316 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002317 },
2318 certFile: certFile,
2319 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002320 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002321 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002322 shouldFail: shouldServerFail,
2323 expectedError: expectedServerError,
2324 })
2325
2326 testCases = append(testCases, testCase{
2327 testType: clientTest,
2328 protocol: protocol,
2329 name: prefix + ver.name + "-" + suite.name + "-client",
2330 config: Config{
2331 MinVersion: ver.version,
2332 MaxVersion: ver.version,
2333 CipherSuites: []uint16{suite.id},
2334 Certificates: []Certificate{cert},
2335 PreSharedKey: []byte(psk),
2336 PreSharedKeyIdentity: pskIdentity,
2337 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002338 EnableAllCiphers: shouldClientFail,
2339 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002340 },
2341 },
2342 flags: flags,
2343 resumeSession: true,
2344 shouldFail: shouldClientFail,
2345 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002346 })
David Benjamin2c99d282015-09-01 10:23:00 -04002347
Nick Harper1fd39d82016-06-14 18:14:35 -07002348 if !shouldClientFail {
2349 // Ensure the maximum record size is accepted.
2350 testCases = append(testCases, testCase{
2351 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2352 config: Config{
2353 MinVersion: ver.version,
2354 MaxVersion: ver.version,
2355 CipherSuites: []uint16{suite.id},
2356 Certificates: []Certificate{cert},
2357 PreSharedKey: []byte(psk),
2358 PreSharedKeyIdentity: pskIdentity,
2359 },
2360 flags: flags,
2361 messageLen: maxPlaintext,
2362 })
2363 }
2364 }
David Benjamin2c99d282015-09-01 10:23:00 -04002365 }
Adam Langley95c29f32014-06-20 12:00:00 -07002366 }
Adam Langleya7997f12015-05-14 17:38:50 -07002367
2368 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002369 name: "NoSharedCipher",
2370 config: Config{
2371 // TODO(davidben): Add a TLS 1.3 version of this test.
2372 MaxVersion: VersionTLS12,
2373 CipherSuites: []uint16{},
2374 },
2375 shouldFail: true,
2376 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2377 })
2378
2379 testCases = append(testCases, testCase{
2380 name: "UnsupportedCipherSuite",
2381 config: Config{
2382 MaxVersion: VersionTLS12,
2383 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2384 Bugs: ProtocolBugs{
2385 IgnorePeerCipherPreferences: true,
2386 },
2387 },
2388 flags: []string{"-cipher", "DEFAULT:!RC4"},
2389 shouldFail: true,
2390 expectedError: ":WRONG_CIPHER_RETURNED:",
2391 })
2392
2393 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002394 name: "WeakDH",
2395 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002396 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002397 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2398 Bugs: ProtocolBugs{
2399 // This is a 1023-bit prime number, generated
2400 // with:
2401 // openssl gendh 1023 | openssl asn1parse -i
2402 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2403 },
2404 },
2405 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002406 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002407 })
Adam Langleycef75832015-09-03 14:51:12 -07002408
David Benjamincd24a392015-11-11 13:23:05 -08002409 testCases = append(testCases, testCase{
2410 name: "SillyDH",
2411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002412 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002413 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2414 Bugs: ProtocolBugs{
2415 // This is a 4097-bit prime number, generated
2416 // with:
2417 // openssl gendh 4097 | openssl asn1parse -i
2418 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2419 },
2420 },
2421 shouldFail: true,
2422 expectedError: ":DH_P_TOO_LONG:",
2423 })
2424
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002425 // This test ensures that Diffie-Hellman public values are padded with
2426 // zeros so that they're the same length as the prime. This is to avoid
2427 // hitting a bug in yaSSL.
2428 testCases = append(testCases, testCase{
2429 testType: serverTest,
2430 name: "DHPublicValuePadded",
2431 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002432 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002433 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2434 Bugs: ProtocolBugs{
2435 RequireDHPublicValueLen: (1025 + 7) / 8,
2436 },
2437 },
2438 flags: []string{"-use-sparse-dh-prime"},
2439 })
David Benjamincd24a392015-11-11 13:23:05 -08002440
David Benjamin241ae832016-01-15 03:04:54 -05002441 // The server must be tolerant to bogus ciphers.
2442 const bogusCipher = 0x1234
2443 testCases = append(testCases, testCase{
2444 testType: serverTest,
2445 name: "UnknownCipher",
2446 config: Config{
2447 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2448 },
2449 })
2450
Adam Langleycef75832015-09-03 14:51:12 -07002451 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2452 // 1.1 specific cipher suite settings. A server is setup with the given
2453 // cipher lists and then a connection is made for each member of
2454 // expectations. The cipher suite that the server selects must match
2455 // the specified one.
2456 var versionSpecificCiphersTest = []struct {
2457 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2458 // expectations is a map from TLS version to cipher suite id.
2459 expectations map[uint16]uint16
2460 }{
2461 {
2462 // Test that the null case (where no version-specific ciphers are set)
2463 // works as expected.
2464 "RC4-SHA:AES128-SHA", // default ciphers
2465 "", // no ciphers specifically for TLS ≥ 1.0
2466 "", // no ciphers specifically for TLS ≥ 1.1
2467 map[uint16]uint16{
2468 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2469 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2470 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2471 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2472 },
2473 },
2474 {
2475 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2476 // cipher.
2477 "RC4-SHA:AES128-SHA", // default
2478 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2479 "", // no ciphers specifically for TLS ≥ 1.1
2480 map[uint16]uint16{
2481 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2482 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2483 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2484 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2485 },
2486 },
2487 {
2488 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2489 // cipher.
2490 "RC4-SHA:AES128-SHA", // default
2491 "", // no ciphers specifically for TLS ≥ 1.0
2492 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2493 map[uint16]uint16{
2494 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2495 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2496 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2497 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2498 },
2499 },
2500 {
2501 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2502 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2503 "RC4-SHA:AES128-SHA", // default
2504 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2505 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2506 map[uint16]uint16{
2507 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2508 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2509 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2510 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2511 },
2512 },
2513 }
2514
2515 for i, test := range versionSpecificCiphersTest {
2516 for version, expectedCipherSuite := range test.expectations {
2517 flags := []string{"-cipher", test.ciphersDefault}
2518 if len(test.ciphersTLS10) > 0 {
2519 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2520 }
2521 if len(test.ciphersTLS11) > 0 {
2522 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2523 }
2524
2525 testCases = append(testCases, testCase{
2526 testType: serverTest,
2527 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2528 config: Config{
2529 MaxVersion: version,
2530 MinVersion: version,
2531 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2532 },
2533 flags: flags,
2534 expectedCipher: expectedCipherSuite,
2535 })
2536 }
2537 }
Adam Langley95c29f32014-06-20 12:00:00 -07002538}
2539
2540func addBadECDSASignatureTests() {
2541 for badR := BadValue(1); badR < NumBadValues; badR++ {
2542 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002543 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002544 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2545 config: Config{
2546 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2547 Certificates: []Certificate{getECDSACertificate()},
2548 Bugs: ProtocolBugs{
2549 BadECDSAR: badR,
2550 BadECDSAS: badS,
2551 },
2552 },
2553 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002554 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002555 })
2556 }
2557 }
2558}
2559
Adam Langley80842bd2014-06-20 12:00:00 -07002560func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002561 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002562 name: "MaxCBCPadding",
2563 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002564 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002565 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2566 Bugs: ProtocolBugs{
2567 MaxPadding: true,
2568 },
2569 },
2570 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2571 })
David Benjamin025b3d32014-07-01 19:53:04 -04002572 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002573 name: "BadCBCPadding",
2574 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002575 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2577 Bugs: ProtocolBugs{
2578 PaddingFirstByteBad: true,
2579 },
2580 },
2581 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002582 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002583 })
2584 // OpenSSL previously had an issue where the first byte of padding in
2585 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002586 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002587 name: "BadCBCPadding255",
2588 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002589 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002590 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2591 Bugs: ProtocolBugs{
2592 MaxPadding: true,
2593 PaddingFirstByteBadIf255: true,
2594 },
2595 },
2596 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2597 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002598 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002599 })
2600}
2601
Kenny Root7fdeaf12014-08-05 15:23:37 -07002602func addCBCSplittingTests() {
2603 testCases = append(testCases, testCase{
2604 name: "CBCRecordSplitting",
2605 config: Config{
2606 MaxVersion: VersionTLS10,
2607 MinVersion: VersionTLS10,
2608 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2609 },
David Benjaminac8302a2015-09-01 17:18:15 -04002610 messageLen: -1, // read until EOF
2611 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002612 flags: []string{
2613 "-async",
2614 "-write-different-record-sizes",
2615 "-cbc-record-splitting",
2616 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002617 })
2618 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002619 name: "CBCRecordSplittingPartialWrite",
2620 config: Config{
2621 MaxVersion: VersionTLS10,
2622 MinVersion: VersionTLS10,
2623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2624 },
2625 messageLen: -1, // read until EOF
2626 flags: []string{
2627 "-async",
2628 "-write-different-record-sizes",
2629 "-cbc-record-splitting",
2630 "-partial-write",
2631 },
2632 })
2633}
2634
David Benjamin636293b2014-07-08 17:59:18 -04002635func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002636 // Add a dummy cert pool to stress certificate authority parsing.
2637 // TODO(davidben): Add tests that those values parse out correctly.
2638 certPool := x509.NewCertPool()
2639 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2640 if err != nil {
2641 panic(err)
2642 }
2643 certPool.AddCert(cert)
2644
David Benjamin636293b2014-07-08 17:59:18 -04002645 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002646 testCases = append(testCases, testCase{
2647 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002648 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002649 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002650 MinVersion: ver.version,
2651 MaxVersion: ver.version,
2652 ClientAuth: RequireAnyClientCert,
2653 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002654 },
2655 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002656 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2657 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002658 },
2659 })
2660 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002661 testType: serverTest,
2662 name: ver.name + "-Server-ClientAuth-RSA",
2663 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002664 MinVersion: ver.version,
2665 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002666 Certificates: []Certificate{rsaCertificate},
2667 },
2668 flags: []string{"-require-any-client-certificate"},
2669 })
David Benjamine098ec22014-08-27 23:13:20 -04002670 if ver.version != VersionSSL30 {
2671 testCases = append(testCases, testCase{
2672 testType: serverTest,
2673 name: ver.name + "-Server-ClientAuth-ECDSA",
2674 config: Config{
2675 MinVersion: ver.version,
2676 MaxVersion: ver.version,
2677 Certificates: []Certificate{ecdsaCertificate},
2678 },
2679 flags: []string{"-require-any-client-certificate"},
2680 })
2681 testCases = append(testCases, testCase{
2682 testType: clientTest,
2683 name: ver.name + "-Client-ClientAuth-ECDSA",
2684 config: Config{
2685 MinVersion: ver.version,
2686 MaxVersion: ver.version,
2687 ClientAuth: RequireAnyClientCert,
2688 ClientCAs: certPool,
2689 },
2690 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002691 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2692 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002693 },
2694 })
2695 }
David Benjamin636293b2014-07-08 17:59:18 -04002696 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002697
Nick Harper1fd39d82016-06-14 18:14:35 -07002698 // TODO(davidben): These tests will need TLS 1.3 versions when the
2699 // handshake is separate.
2700
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002701 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002702 name: "NoClientCertificate",
2703 config: Config{
2704 MaxVersion: VersionTLS12,
2705 ClientAuth: RequireAnyClientCert,
2706 },
2707 shouldFail: true,
2708 expectedLocalError: "client didn't provide a certificate",
2709 })
2710
2711 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002712 testType: serverTest,
2713 name: "RequireAnyClientCertificate",
2714 config: Config{
2715 MaxVersion: VersionTLS12,
2716 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002717 flags: []string{"-require-any-client-certificate"},
2718 shouldFail: true,
2719 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2720 })
2721
2722 testCases = append(testCases, testCase{
2723 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002724 name: "RequireAnyClientCertificate-SSL3",
2725 config: Config{
2726 MaxVersion: VersionSSL30,
2727 },
2728 flags: []string{"-require-any-client-certificate"},
2729 shouldFail: true,
2730 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2731 })
2732
2733 testCases = append(testCases, testCase{
2734 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002735 name: "SkipClientCertificate",
2736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002737 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002738 Bugs: ProtocolBugs{
2739 SkipClientCertificate: true,
2740 },
2741 },
2742 // Setting SSL_VERIFY_PEER allows anonymous clients.
2743 flags: []string{"-verify-peer"},
2744 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002745 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002746 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002747
2748 // Client auth is only legal in certificate-based ciphers.
2749 testCases = append(testCases, testCase{
2750 testType: clientTest,
2751 name: "ClientAuth-PSK",
2752 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002753 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002754 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2755 PreSharedKey: []byte("secret"),
2756 ClientAuth: RequireAnyClientCert,
2757 },
2758 flags: []string{
2759 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2760 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2761 "-psk", "secret",
2762 },
2763 shouldFail: true,
2764 expectedError: ":UNEXPECTED_MESSAGE:",
2765 })
2766 testCases = append(testCases, testCase{
2767 testType: clientTest,
2768 name: "ClientAuth-ECDHE_PSK",
2769 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002770 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002771 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2772 PreSharedKey: []byte("secret"),
2773 ClientAuth: RequireAnyClientCert,
2774 },
2775 flags: []string{
2776 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2777 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2778 "-psk", "secret",
2779 },
2780 shouldFail: true,
2781 expectedError: ":UNEXPECTED_MESSAGE:",
2782 })
David Benjamin636293b2014-07-08 17:59:18 -04002783}
2784
Adam Langley75712922014-10-10 16:23:43 -07002785func addExtendedMasterSecretTests() {
2786 const expectEMSFlag = "-expect-extended-master-secret"
2787
2788 for _, with := range []bool{false, true} {
2789 prefix := "No"
2790 var flags []string
2791 if with {
2792 prefix = ""
2793 flags = []string{expectEMSFlag}
2794 }
2795
2796 for _, isClient := range []bool{false, true} {
2797 suffix := "-Server"
2798 testType := serverTest
2799 if isClient {
2800 suffix = "-Client"
2801 testType = clientTest
2802 }
2803
David Benjamin4c3ddf72016-06-29 18:13:53 -04002804 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2805 // test that the extension is irrelevant, but the API
2806 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002807 for _, ver := range tlsVersions {
2808 test := testCase{
2809 testType: testType,
2810 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2811 config: Config{
2812 MinVersion: ver.version,
2813 MaxVersion: ver.version,
2814 Bugs: ProtocolBugs{
2815 NoExtendedMasterSecret: !with,
2816 RequireExtendedMasterSecret: with,
2817 },
2818 },
David Benjamin48cae082014-10-27 01:06:24 -04002819 flags: flags,
2820 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002821 }
2822 if test.shouldFail {
2823 test.expectedLocalError = "extended master secret required but not supported by peer"
2824 }
2825 testCases = append(testCases, test)
2826 }
2827 }
2828 }
2829
Adam Langleyba5934b2015-06-02 10:50:35 -07002830 for _, isClient := range []bool{false, true} {
2831 for _, supportedInFirstConnection := range []bool{false, true} {
2832 for _, supportedInResumeConnection := range []bool{false, true} {
2833 boolToWord := func(b bool) string {
2834 if b {
2835 return "Yes"
2836 }
2837 return "No"
2838 }
2839 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2840 if isClient {
2841 suffix += "Client"
2842 } else {
2843 suffix += "Server"
2844 }
2845
2846 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002847 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002848 Bugs: ProtocolBugs{
2849 RequireExtendedMasterSecret: true,
2850 },
2851 }
2852
2853 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002854 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002855 Bugs: ProtocolBugs{
2856 NoExtendedMasterSecret: true,
2857 },
2858 }
2859
2860 test := testCase{
2861 name: "ExtendedMasterSecret-" + suffix,
2862 resumeSession: true,
2863 }
2864
2865 if !isClient {
2866 test.testType = serverTest
2867 }
2868
2869 if supportedInFirstConnection {
2870 test.config = supportedConfig
2871 } else {
2872 test.config = noSupportConfig
2873 }
2874
2875 if supportedInResumeConnection {
2876 test.resumeConfig = &supportedConfig
2877 } else {
2878 test.resumeConfig = &noSupportConfig
2879 }
2880
2881 switch suffix {
2882 case "YesToYes-Client", "YesToYes-Server":
2883 // When a session is resumed, it should
2884 // still be aware that its master
2885 // secret was generated via EMS and
2886 // thus it's safe to use tls-unique.
2887 test.flags = []string{expectEMSFlag}
2888 case "NoToYes-Server":
2889 // If an original connection did not
2890 // contain EMS, but a resumption
2891 // handshake does, then a server should
2892 // not resume the session.
2893 test.expectResumeRejected = true
2894 case "YesToNo-Server":
2895 // Resuming an EMS session without the
2896 // EMS extension should cause the
2897 // server to abort the connection.
2898 test.shouldFail = true
2899 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2900 case "NoToYes-Client":
2901 // A client should abort a connection
2902 // where the server resumed a non-EMS
2903 // session but echoed the EMS
2904 // extension.
2905 test.shouldFail = true
2906 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2907 case "YesToNo-Client":
2908 // A client should abort a connection
2909 // where the server didn't echo EMS
2910 // when the session used it.
2911 test.shouldFail = true
2912 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2913 }
2914
2915 testCases = append(testCases, test)
2916 }
2917 }
2918 }
Adam Langley75712922014-10-10 16:23:43 -07002919}
2920
David Benjamin43ec06f2014-08-05 02:28:57 -04002921// Adds tests that try to cover the range of the handshake state machine, under
2922// various conditions. Some of these are redundant with other tests, but they
2923// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002924func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002925 var tests []testCase
2926
2927 // Basic handshake, with resumption. Client and server,
2928 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002929 //
2930 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2931 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002932 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002933 name: "Basic-Client",
2934 config: Config{
2935 MaxVersion: VersionTLS12,
2936 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002937 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002938 // Ensure session tickets are used, not session IDs.
2939 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002940 })
2941 tests = append(tests, testCase{
2942 name: "Basic-Client-RenewTicket",
2943 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002944 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002945 Bugs: ProtocolBugs{
2946 RenewTicketOnResume: true,
2947 },
2948 },
David Benjaminba4594a2015-06-18 18:36:15 -04002949 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002950 resumeSession: true,
2951 })
2952 tests = append(tests, testCase{
2953 name: "Basic-Client-NoTicket",
2954 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002955 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002956 SessionTicketsDisabled: true,
2957 },
2958 resumeSession: true,
2959 })
2960 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002961 name: "Basic-Client-Implicit",
2962 config: Config{
2963 MaxVersion: VersionTLS12,
2964 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002965 flags: []string{"-implicit-handshake"},
2966 resumeSession: true,
2967 })
2968 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002969 testType: serverTest,
2970 name: "Basic-Server",
2971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002972 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002973 Bugs: ProtocolBugs{
2974 RequireSessionTickets: true,
2975 },
2976 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002977 resumeSession: true,
2978 })
2979 tests = append(tests, testCase{
2980 testType: serverTest,
2981 name: "Basic-Server-NoTickets",
2982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002983 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002984 SessionTicketsDisabled: true,
2985 },
2986 resumeSession: true,
2987 })
2988 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002989 testType: serverTest,
2990 name: "Basic-Server-Implicit",
2991 config: Config{
2992 MaxVersion: VersionTLS12,
2993 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002994 flags: []string{"-implicit-handshake"},
2995 resumeSession: true,
2996 })
2997 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002998 testType: serverTest,
2999 name: "Basic-Server-EarlyCallback",
3000 config: Config{
3001 MaxVersion: VersionTLS12,
3002 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003003 flags: []string{"-use-early-callback"},
3004 resumeSession: true,
3005 })
3006
3007 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003008 //
3009 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04003010 tests = append(tests, testCase{
3011 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003012 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003014 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003015 ClientAuth: RequestClientCert,
3016 },
3017 })
3018 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003019 testType: serverTest,
3020 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003021 config: Config{
3022 MaxVersion: VersionTLS12,
3023 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003024 // Setting SSL_VERIFY_PEER allows anonymous clients.
3025 flags: []string{"-verify-peer"},
3026 })
3027 if protocol == tls {
3028 tests = append(tests, testCase{
3029 testType: clientTest,
3030 name: "ClientAuth-NoCertificate-Client-SSL3",
3031 config: Config{
3032 MaxVersion: VersionSSL30,
3033 ClientAuth: RequestClientCert,
3034 },
3035 })
3036 tests = append(tests, testCase{
3037 testType: serverTest,
3038 name: "ClientAuth-NoCertificate-Server-SSL3",
3039 config: Config{
3040 MaxVersion: VersionSSL30,
3041 },
3042 // Setting SSL_VERIFY_PEER allows anonymous clients.
3043 flags: []string{"-verify-peer"},
3044 })
3045 }
3046 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003047 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003048 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003051 ClientAuth: RequireAnyClientCert,
3052 },
3053 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003054 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3055 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003056 },
3057 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003058 tests = append(tests, testCase{
3059 testType: clientTest,
3060 name: "ClientAuth-ECDSA-Client",
3061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003062 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003063 ClientAuth: RequireAnyClientCert,
3064 },
3065 flags: []string{
3066 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3067 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3068 },
3069 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003070 tests = append(tests, testCase{
3071 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003072 name: "ClientAuth-NoCertificate-OldCallback",
3073 config: Config{
3074 MaxVersion: VersionTLS12,
3075 ClientAuth: RequestClientCert,
3076 },
3077 flags: []string{"-use-old-client-cert-callback"},
3078 })
3079 tests = append(tests, testCase{
3080 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003081 name: "ClientAuth-OldCallback",
3082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003083 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003084 ClientAuth: RequireAnyClientCert,
3085 },
3086 flags: []string{
3087 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3088 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3089 "-use-old-client-cert-callback",
3090 },
3091 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003092 tests = append(tests, testCase{
3093 testType: serverTest,
3094 name: "ClientAuth-Server",
3095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003096 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003097 Certificates: []Certificate{rsaCertificate},
3098 },
3099 flags: []string{"-require-any-client-certificate"},
3100 })
3101
David Benjamin4c3ddf72016-06-29 18:13:53 -04003102 // Test each key exchange on the server side for async keys.
3103 //
3104 // TODO(davidben): Add TLS 1.3 versions of these.
3105 tests = append(tests, testCase{
3106 testType: serverTest,
3107 name: "Basic-Server-RSA",
3108 config: Config{
3109 MaxVersion: VersionTLS12,
3110 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3111 },
3112 flags: []string{
3113 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3114 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3115 },
3116 })
3117 tests = append(tests, testCase{
3118 testType: serverTest,
3119 name: "Basic-Server-ECDHE-RSA",
3120 config: Config{
3121 MaxVersion: VersionTLS12,
3122 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3123 },
3124 flags: []string{
3125 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3126 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3127 },
3128 })
3129 tests = append(tests, testCase{
3130 testType: serverTest,
3131 name: "Basic-Server-ECDHE-ECDSA",
3132 config: Config{
3133 MaxVersion: VersionTLS12,
3134 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3135 },
3136 flags: []string{
3137 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3138 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3139 },
3140 })
3141
David Benjamin760b1dd2015-05-15 23:33:48 -04003142 // No session ticket support; server doesn't send NewSessionTicket.
3143 tests = append(tests, testCase{
3144 name: "SessionTicketsDisabled-Client",
3145 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003146 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003147 SessionTicketsDisabled: true,
3148 },
3149 })
3150 tests = append(tests, testCase{
3151 testType: serverTest,
3152 name: "SessionTicketsDisabled-Server",
3153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003154 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003155 SessionTicketsDisabled: true,
3156 },
3157 })
3158
3159 // Skip ServerKeyExchange in PSK key exchange if there's no
3160 // identity hint.
3161 tests = append(tests, testCase{
3162 name: "EmptyPSKHint-Client",
3163 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003164 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003165 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3166 PreSharedKey: []byte("secret"),
3167 },
3168 flags: []string{"-psk", "secret"},
3169 })
3170 tests = append(tests, testCase{
3171 testType: serverTest,
3172 name: "EmptyPSKHint-Server",
3173 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003174 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003175 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3176 PreSharedKey: []byte("secret"),
3177 },
3178 flags: []string{"-psk", "secret"},
3179 })
3180
David Benjamin4c3ddf72016-06-29 18:13:53 -04003181 // OCSP stapling tests.
3182 //
3183 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003184 tests = append(tests, testCase{
3185 testType: clientTest,
3186 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003187 config: Config{
3188 MaxVersion: VersionTLS12,
3189 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003190 flags: []string{
3191 "-enable-ocsp-stapling",
3192 "-expect-ocsp-response",
3193 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003194 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003195 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003196 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003197 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003198 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003199 testType: serverTest,
3200 name: "OCSPStapling-Server",
3201 config: Config{
3202 MaxVersion: VersionTLS12,
3203 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003204 expectedOCSPResponse: testOCSPResponse,
3205 flags: []string{
3206 "-ocsp-response",
3207 base64.StdEncoding.EncodeToString(testOCSPResponse),
3208 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003209 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003210 })
3211
David Benjamin4c3ddf72016-06-29 18:13:53 -04003212 // Certificate verification tests.
3213 //
3214 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003215 tests = append(tests, testCase{
3216 testType: clientTest,
3217 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003218 config: Config{
3219 MaxVersion: VersionTLS12,
3220 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003221 flags: []string{
3222 "-verify-peer",
3223 },
3224 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003225 tests = append(tests, testCase{
3226 testType: clientTest,
3227 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003228 config: Config{
3229 MaxVersion: VersionTLS12,
3230 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003231 flags: []string{
3232 "-verify-fail",
3233 "-verify-peer",
3234 },
3235 shouldFail: true,
3236 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3237 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003238 tests = append(tests, testCase{
3239 testType: clientTest,
3240 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003241 config: Config{
3242 MaxVersion: VersionTLS12,
3243 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003244 flags: []string{
3245 "-verify-fail",
3246 "-expect-verify-result",
3247 },
3248 })
3249
David Benjamin760b1dd2015-05-15 23:33:48 -04003250 if protocol == tls {
3251 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003252 name: "Renegotiate-Client",
3253 config: Config{
3254 MaxVersion: VersionTLS12,
3255 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003256 renegotiate: 1,
3257 flags: []string{
3258 "-renegotiate-freely",
3259 "-expect-total-renegotiations", "1",
3260 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003261 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003262
David Benjamin760b1dd2015-05-15 23:33:48 -04003263 // NPN on client and server; results in post-handshake message.
3264 tests = append(tests, testCase{
3265 name: "NPN-Client",
3266 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003267 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 NextProtos: []string{"foo"},
3269 },
3270 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003271 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003272 expectedNextProto: "foo",
3273 expectedNextProtoType: npn,
3274 })
3275 tests = append(tests, testCase{
3276 testType: serverTest,
3277 name: "NPN-Server",
3278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003279 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003280 NextProtos: []string{"bar"},
3281 },
3282 flags: []string{
3283 "-advertise-npn", "\x03foo\x03bar\x03baz",
3284 "-expect-next-proto", "bar",
3285 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003286 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003287 expectedNextProto: "bar",
3288 expectedNextProtoType: npn,
3289 })
3290
3291 // TODO(davidben): Add tests for when False Start doesn't trigger.
3292
3293 // Client does False Start and negotiates NPN.
3294 tests = append(tests, testCase{
3295 name: "FalseStart",
3296 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003297 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003298 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3299 NextProtos: []string{"foo"},
3300 Bugs: ProtocolBugs{
3301 ExpectFalseStart: true,
3302 },
3303 },
3304 flags: []string{
3305 "-false-start",
3306 "-select-next-proto", "foo",
3307 },
3308 shimWritesFirst: true,
3309 resumeSession: true,
3310 })
3311
3312 // Client does False Start and negotiates ALPN.
3313 tests = append(tests, testCase{
3314 name: "FalseStart-ALPN",
3315 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003316 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003317 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3318 NextProtos: []string{"foo"},
3319 Bugs: ProtocolBugs{
3320 ExpectFalseStart: true,
3321 },
3322 },
3323 flags: []string{
3324 "-false-start",
3325 "-advertise-alpn", "\x03foo",
3326 },
3327 shimWritesFirst: true,
3328 resumeSession: true,
3329 })
3330
3331 // Client does False Start but doesn't explicitly call
3332 // SSL_connect.
3333 tests = append(tests, testCase{
3334 name: "FalseStart-Implicit",
3335 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003336 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003337 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3338 NextProtos: []string{"foo"},
3339 },
3340 flags: []string{
3341 "-implicit-handshake",
3342 "-false-start",
3343 "-advertise-alpn", "\x03foo",
3344 },
3345 })
3346
3347 // False Start without session tickets.
3348 tests = append(tests, testCase{
3349 name: "FalseStart-SessionTicketsDisabled",
3350 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003351 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003352 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3353 NextProtos: []string{"foo"},
3354 SessionTicketsDisabled: true,
3355 Bugs: ProtocolBugs{
3356 ExpectFalseStart: true,
3357 },
3358 },
3359 flags: []string{
3360 "-false-start",
3361 "-select-next-proto", "foo",
3362 },
3363 shimWritesFirst: true,
3364 })
3365
3366 // Server parses a V2ClientHello.
3367 tests = append(tests, testCase{
3368 testType: serverTest,
3369 name: "SendV2ClientHello",
3370 config: Config{
3371 // Choose a cipher suite that does not involve
3372 // elliptic curves, so no extensions are
3373 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003374 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003375 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3376 Bugs: ProtocolBugs{
3377 SendV2ClientHello: true,
3378 },
3379 },
3380 })
3381
3382 // Client sends a Channel ID.
3383 tests = append(tests, testCase{
3384 name: "ChannelID-Client",
3385 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003386 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003387 RequestChannelID: true,
3388 },
Adam Langley7c803a62015-06-15 15:35:05 -07003389 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003390 resumeSession: true,
3391 expectChannelID: true,
3392 })
3393
3394 // Server accepts a Channel ID.
3395 tests = append(tests, testCase{
3396 testType: serverTest,
3397 name: "ChannelID-Server",
3398 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003399 MaxVersion: VersionTLS12,
3400 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003401 },
3402 flags: []string{
3403 "-expect-channel-id",
3404 base64.StdEncoding.EncodeToString(channelIDBytes),
3405 },
3406 resumeSession: true,
3407 expectChannelID: true,
3408 })
David Benjamin30789da2015-08-29 22:56:45 -04003409
David Benjaminf8fcdf32016-06-08 15:56:13 -04003410 // Channel ID and NPN at the same time, to ensure their relative
3411 // ordering is correct.
3412 tests = append(tests, testCase{
3413 name: "ChannelID-NPN-Client",
3414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003415 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003416 RequestChannelID: true,
3417 NextProtos: []string{"foo"},
3418 },
3419 flags: []string{
3420 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3421 "-select-next-proto", "foo",
3422 },
3423 resumeSession: true,
3424 expectChannelID: true,
3425 expectedNextProto: "foo",
3426 expectedNextProtoType: npn,
3427 })
3428 tests = append(tests, testCase{
3429 testType: serverTest,
3430 name: "ChannelID-NPN-Server",
3431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003432 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003433 ChannelID: channelIDKey,
3434 NextProtos: []string{"bar"},
3435 },
3436 flags: []string{
3437 "-expect-channel-id",
3438 base64.StdEncoding.EncodeToString(channelIDBytes),
3439 "-advertise-npn", "\x03foo\x03bar\x03baz",
3440 "-expect-next-proto", "bar",
3441 },
3442 resumeSession: true,
3443 expectChannelID: true,
3444 expectedNextProto: "bar",
3445 expectedNextProtoType: npn,
3446 })
3447
David Benjamin30789da2015-08-29 22:56:45 -04003448 // Bidirectional shutdown with the runner initiating.
3449 tests = append(tests, testCase{
3450 name: "Shutdown-Runner",
3451 config: Config{
3452 Bugs: ProtocolBugs{
3453 ExpectCloseNotify: true,
3454 },
3455 },
3456 flags: []string{"-check-close-notify"},
3457 })
3458
3459 // Bidirectional shutdown with the shim initiating. The runner,
3460 // in the meantime, sends garbage before the close_notify which
3461 // the shim must ignore.
3462 tests = append(tests, testCase{
3463 name: "Shutdown-Shim",
3464 config: Config{
3465 Bugs: ProtocolBugs{
3466 ExpectCloseNotify: true,
3467 },
3468 },
3469 shimShutsDown: true,
3470 sendEmptyRecords: 1,
3471 sendWarningAlerts: 1,
3472 flags: []string{"-check-close-notify"},
3473 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003474 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003475 // TODO(davidben): DTLS 1.3 will want a similar thing for
3476 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003477 tests = append(tests, testCase{
3478 name: "SkipHelloVerifyRequest",
3479 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003480 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003481 Bugs: ProtocolBugs{
3482 SkipHelloVerifyRequest: true,
3483 },
3484 },
3485 })
3486 }
3487
David Benjamin760b1dd2015-05-15 23:33:48 -04003488 for _, test := range tests {
3489 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003490 if protocol == dtls {
3491 test.name += "-DTLS"
3492 }
3493 if async {
3494 test.name += "-Async"
3495 test.flags = append(test.flags, "-async")
3496 } else {
3497 test.name += "-Sync"
3498 }
3499 if splitHandshake {
3500 test.name += "-SplitHandshakeRecords"
3501 test.config.Bugs.MaxHandshakeRecordLength = 1
3502 if protocol == dtls {
3503 test.config.Bugs.MaxPacketLength = 256
3504 test.flags = append(test.flags, "-mtu", "256")
3505 }
3506 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003507 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003508 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003509}
3510
Adam Langley524e7172015-02-20 16:04:00 -08003511func addDDoSCallbackTests() {
3512 // DDoS callback.
3513
3514 for _, resume := range []bool{false, true} {
3515 suffix := "Resume"
3516 if resume {
3517 suffix = "No" + suffix
3518 }
3519
David Benjamin4c3ddf72016-06-29 18:13:53 -04003520 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3521
Adam Langley524e7172015-02-20 16:04:00 -08003522 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003523 testType: serverTest,
3524 name: "Server-DDoS-OK-" + suffix,
3525 config: Config{
3526 MaxVersion: VersionTLS12,
3527 },
Adam Langley524e7172015-02-20 16:04:00 -08003528 flags: []string{"-install-ddos-callback"},
3529 resumeSession: resume,
3530 })
3531
3532 failFlag := "-fail-ddos-callback"
3533 if resume {
3534 failFlag = "-fail-second-ddos-callback"
3535 }
3536 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003537 testType: serverTest,
3538 name: "Server-DDoS-Reject-" + suffix,
3539 config: Config{
3540 MaxVersion: VersionTLS12,
3541 },
Adam Langley524e7172015-02-20 16:04:00 -08003542 flags: []string{"-install-ddos-callback", failFlag},
3543 resumeSession: resume,
3544 shouldFail: true,
3545 expectedError: ":CONNECTION_REJECTED:",
3546 })
3547 }
3548}
3549
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003550func addVersionNegotiationTests() {
3551 for i, shimVers := range tlsVersions {
3552 // Assemble flags to disable all newer versions on the shim.
3553 var flags []string
3554 for _, vers := range tlsVersions[i+1:] {
3555 flags = append(flags, vers.flag)
3556 }
3557
3558 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003559 protocols := []protocol{tls}
3560 if runnerVers.hasDTLS && shimVers.hasDTLS {
3561 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003562 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003563 for _, protocol := range protocols {
3564 expectedVersion := shimVers.version
3565 if runnerVers.version < shimVers.version {
3566 expectedVersion = runnerVers.version
3567 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003568
David Benjamin8b8c0062014-11-23 02:47:52 -05003569 suffix := shimVers.name + "-" + runnerVers.name
3570 if protocol == dtls {
3571 suffix += "-DTLS"
3572 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003573
David Benjamin1eb367c2014-12-12 18:17:51 -05003574 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3575
David Benjamin1e29a6b2014-12-10 02:27:24 -05003576 clientVers := shimVers.version
3577 if clientVers > VersionTLS10 {
3578 clientVers = VersionTLS10
3579 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003580 serverVers := expectedVersion
3581 if expectedVersion >= VersionTLS13 {
3582 serverVers = VersionTLS10
3583 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003584 testCases = append(testCases, testCase{
3585 protocol: protocol,
3586 testType: clientTest,
3587 name: "VersionNegotiation-Client-" + suffix,
3588 config: Config{
3589 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003590 Bugs: ProtocolBugs{
3591 ExpectInitialRecordVersion: clientVers,
3592 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003593 },
3594 flags: flags,
3595 expectedVersion: expectedVersion,
3596 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003597 testCases = append(testCases, testCase{
3598 protocol: protocol,
3599 testType: clientTest,
3600 name: "VersionNegotiation-Client2-" + suffix,
3601 config: Config{
3602 MaxVersion: runnerVers.version,
3603 Bugs: ProtocolBugs{
3604 ExpectInitialRecordVersion: clientVers,
3605 },
3606 },
3607 flags: []string{"-max-version", shimVersFlag},
3608 expectedVersion: expectedVersion,
3609 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003610
3611 testCases = append(testCases, testCase{
3612 protocol: protocol,
3613 testType: serverTest,
3614 name: "VersionNegotiation-Server-" + suffix,
3615 config: Config{
3616 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003617 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003618 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003619 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003620 },
3621 flags: flags,
3622 expectedVersion: expectedVersion,
3623 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003624 testCases = append(testCases, testCase{
3625 protocol: protocol,
3626 testType: serverTest,
3627 name: "VersionNegotiation-Server2-" + suffix,
3628 config: Config{
3629 MaxVersion: runnerVers.version,
3630 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003631 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003632 },
3633 },
3634 flags: []string{"-max-version", shimVersFlag},
3635 expectedVersion: expectedVersion,
3636 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003637 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003638 }
3639 }
David Benjamin95c69562016-06-29 18:15:03 -04003640
3641 // Test for version tolerance.
3642 testCases = append(testCases, testCase{
3643 testType: serverTest,
3644 name: "MinorVersionTolerance",
3645 config: Config{
3646 Bugs: ProtocolBugs{
3647 SendClientVersion: 0x03ff,
3648 },
3649 },
3650 expectedVersion: VersionTLS13,
3651 })
3652 testCases = append(testCases, testCase{
3653 testType: serverTest,
3654 name: "MajorVersionTolerance",
3655 config: Config{
3656 Bugs: ProtocolBugs{
3657 SendClientVersion: 0x0400,
3658 },
3659 },
3660 expectedVersion: VersionTLS13,
3661 })
3662 testCases = append(testCases, testCase{
3663 protocol: dtls,
3664 testType: serverTest,
3665 name: "MinorVersionTolerance-DTLS",
3666 config: Config{
3667 Bugs: ProtocolBugs{
3668 SendClientVersion: 0x03ff,
3669 },
3670 },
3671 expectedVersion: VersionTLS12,
3672 })
3673 testCases = append(testCases, testCase{
3674 protocol: dtls,
3675 testType: serverTest,
3676 name: "MajorVersionTolerance-DTLS",
3677 config: Config{
3678 Bugs: ProtocolBugs{
3679 SendClientVersion: 0x0400,
3680 },
3681 },
3682 expectedVersion: VersionTLS12,
3683 })
3684
3685 // Test that versions below 3.0 are rejected.
3686 testCases = append(testCases, testCase{
3687 testType: serverTest,
3688 name: "VersionTooLow",
3689 config: Config{
3690 Bugs: ProtocolBugs{
3691 SendClientVersion: 0x0200,
3692 },
3693 },
3694 shouldFail: true,
3695 expectedError: ":UNSUPPORTED_PROTOCOL:",
3696 })
3697 testCases = append(testCases, testCase{
3698 protocol: dtls,
3699 testType: serverTest,
3700 name: "VersionTooLow-DTLS",
3701 config: Config{
3702 Bugs: ProtocolBugs{
3703 // 0x0201 is the lowest version expressable in
3704 // DTLS.
3705 SendClientVersion: 0x0201,
3706 },
3707 },
3708 shouldFail: true,
3709 expectedError: ":UNSUPPORTED_PROTOCOL:",
3710 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003711}
3712
David Benjaminaccb4542014-12-12 23:44:33 -05003713func addMinimumVersionTests() {
3714 for i, shimVers := range tlsVersions {
3715 // Assemble flags to disable all older versions on the shim.
3716 var flags []string
3717 for _, vers := range tlsVersions[:i] {
3718 flags = append(flags, vers.flag)
3719 }
3720
3721 for _, runnerVers := range tlsVersions {
3722 protocols := []protocol{tls}
3723 if runnerVers.hasDTLS && shimVers.hasDTLS {
3724 protocols = append(protocols, dtls)
3725 }
3726 for _, protocol := range protocols {
3727 suffix := shimVers.name + "-" + runnerVers.name
3728 if protocol == dtls {
3729 suffix += "-DTLS"
3730 }
3731 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3732
David Benjaminaccb4542014-12-12 23:44:33 -05003733 var expectedVersion uint16
3734 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003735 var expectedClientError, expectedServerError string
3736 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003737 if runnerVers.version >= shimVers.version {
3738 expectedVersion = runnerVers.version
3739 } else {
3740 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003741 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3742 expectedServerLocalError = "remote error: protocol version not supported"
3743 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3744 // If the client's minimum version is TLS 1.3 and the runner's
3745 // maximum is below TLS 1.2, the runner will fail to select a
3746 // cipher before the shim rejects the selected version.
3747 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3748 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3749 } else {
3750 expectedClientError = expectedServerError
3751 expectedClientLocalError = expectedServerLocalError
3752 }
David Benjaminaccb4542014-12-12 23:44:33 -05003753 }
3754
3755 testCases = append(testCases, testCase{
3756 protocol: protocol,
3757 testType: clientTest,
3758 name: "MinimumVersion-Client-" + suffix,
3759 config: Config{
3760 MaxVersion: runnerVers.version,
3761 },
David Benjamin87909c02014-12-13 01:55:01 -05003762 flags: flags,
3763 expectedVersion: expectedVersion,
3764 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003765 expectedError: expectedClientError,
3766 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003767 })
3768 testCases = append(testCases, testCase{
3769 protocol: protocol,
3770 testType: clientTest,
3771 name: "MinimumVersion-Client2-" + suffix,
3772 config: Config{
3773 MaxVersion: runnerVers.version,
3774 },
David Benjamin87909c02014-12-13 01:55:01 -05003775 flags: []string{"-min-version", shimVersFlag},
3776 expectedVersion: expectedVersion,
3777 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003778 expectedError: expectedClientError,
3779 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003780 })
3781
3782 testCases = append(testCases, testCase{
3783 protocol: protocol,
3784 testType: serverTest,
3785 name: "MinimumVersion-Server-" + suffix,
3786 config: Config{
3787 MaxVersion: runnerVers.version,
3788 },
David Benjamin87909c02014-12-13 01:55:01 -05003789 flags: flags,
3790 expectedVersion: expectedVersion,
3791 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003792 expectedError: expectedServerError,
3793 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003794 })
3795 testCases = append(testCases, testCase{
3796 protocol: protocol,
3797 testType: serverTest,
3798 name: "MinimumVersion-Server2-" + suffix,
3799 config: Config{
3800 MaxVersion: runnerVers.version,
3801 },
David Benjamin87909c02014-12-13 01:55:01 -05003802 flags: []string{"-min-version", shimVersFlag},
3803 expectedVersion: expectedVersion,
3804 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003805 expectedError: expectedServerError,
3806 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003807 })
3808 }
3809 }
3810 }
3811}
3812
David Benjamine78bfde2014-09-06 12:45:15 -04003813func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003814 // TODO(davidben): Extensions, where applicable, all move their server
3815 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3816 // tests for both. Also test interaction with 0-RTT when implemented.
3817
David Benjamine78bfde2014-09-06 12:45:15 -04003818 testCases = append(testCases, testCase{
3819 testType: clientTest,
3820 name: "DuplicateExtensionClient",
3821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003822 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003823 Bugs: ProtocolBugs{
3824 DuplicateExtension: true,
3825 },
3826 },
3827 shouldFail: true,
3828 expectedLocalError: "remote error: error decoding message",
3829 })
3830 testCases = append(testCases, testCase{
3831 testType: serverTest,
3832 name: "DuplicateExtensionServer",
3833 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003834 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003835 Bugs: ProtocolBugs{
3836 DuplicateExtension: true,
3837 },
3838 },
3839 shouldFail: true,
3840 expectedLocalError: "remote error: error decoding message",
3841 })
3842 testCases = append(testCases, testCase{
3843 testType: clientTest,
3844 name: "ServerNameExtensionClient",
3845 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003846 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003847 Bugs: ProtocolBugs{
3848 ExpectServerName: "example.com",
3849 },
3850 },
3851 flags: []string{"-host-name", "example.com"},
3852 })
3853 testCases = append(testCases, testCase{
3854 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003855 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003856 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003857 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003858 Bugs: ProtocolBugs{
3859 ExpectServerName: "mismatch.com",
3860 },
3861 },
3862 flags: []string{"-host-name", "example.com"},
3863 shouldFail: true,
3864 expectedLocalError: "tls: unexpected server name",
3865 })
3866 testCases = append(testCases, testCase{
3867 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003868 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003870 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003871 Bugs: ProtocolBugs{
3872 ExpectServerName: "missing.com",
3873 },
3874 },
3875 shouldFail: true,
3876 expectedLocalError: "tls: unexpected server name",
3877 })
3878 testCases = append(testCases, testCase{
3879 testType: serverTest,
3880 name: "ServerNameExtensionServer",
3881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003882 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003883 ServerName: "example.com",
3884 },
3885 flags: []string{"-expect-server-name", "example.com"},
3886 resumeSession: true,
3887 })
David Benjaminae2888f2014-09-06 12:58:58 -04003888 testCases = append(testCases, testCase{
3889 testType: clientTest,
3890 name: "ALPNClient",
3891 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003892 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003893 NextProtos: []string{"foo"},
3894 },
3895 flags: []string{
3896 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3897 "-expect-alpn", "foo",
3898 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003899 expectedNextProto: "foo",
3900 expectedNextProtoType: alpn,
3901 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003902 })
3903 testCases = append(testCases, testCase{
3904 testType: serverTest,
3905 name: "ALPNServer",
3906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003907 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003908 NextProtos: []string{"foo", "bar", "baz"},
3909 },
3910 flags: []string{
3911 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3912 "-select-alpn", "foo",
3913 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003914 expectedNextProto: "foo",
3915 expectedNextProtoType: alpn,
3916 resumeSession: true,
3917 })
David Benjamin594e7d22016-03-17 17:49:56 -04003918 testCases = append(testCases, testCase{
3919 testType: serverTest,
3920 name: "ALPNServer-Decline",
3921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003922 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003923 NextProtos: []string{"foo", "bar", "baz"},
3924 },
3925 flags: []string{"-decline-alpn"},
3926 expectNoNextProto: true,
3927 resumeSession: true,
3928 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003929 // Test that the server prefers ALPN over NPN.
3930 testCases = append(testCases, testCase{
3931 testType: serverTest,
3932 name: "ALPNServer-Preferred",
3933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003934 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003935 NextProtos: []string{"foo", "bar", "baz"},
3936 },
3937 flags: []string{
3938 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3939 "-select-alpn", "foo",
3940 "-advertise-npn", "\x03foo\x03bar\x03baz",
3941 },
3942 expectedNextProto: "foo",
3943 expectedNextProtoType: alpn,
3944 resumeSession: true,
3945 })
3946 testCases = append(testCases, testCase{
3947 testType: serverTest,
3948 name: "ALPNServer-Preferred-Swapped",
3949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003950 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003951 NextProtos: []string{"foo", "bar", "baz"},
3952 Bugs: ProtocolBugs{
3953 SwapNPNAndALPN: true,
3954 },
3955 },
3956 flags: []string{
3957 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3958 "-select-alpn", "foo",
3959 "-advertise-npn", "\x03foo\x03bar\x03baz",
3960 },
3961 expectedNextProto: "foo",
3962 expectedNextProtoType: alpn,
3963 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003964 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003965 var emptyString string
3966 testCases = append(testCases, testCase{
3967 testType: clientTest,
3968 name: "ALPNClient-EmptyProtocolName",
3969 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003970 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003971 NextProtos: []string{""},
3972 Bugs: ProtocolBugs{
3973 // A server returning an empty ALPN protocol
3974 // should be rejected.
3975 ALPNProtocol: &emptyString,
3976 },
3977 },
3978 flags: []string{
3979 "-advertise-alpn", "\x03foo",
3980 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003981 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003982 expectedError: ":PARSE_TLSEXT:",
3983 })
3984 testCases = append(testCases, testCase{
3985 testType: serverTest,
3986 name: "ALPNServer-EmptyProtocolName",
3987 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003988 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003989 // A ClientHello containing an empty ALPN protocol
3990 // should be rejected.
3991 NextProtos: []string{"foo", "", "baz"},
3992 },
3993 flags: []string{
3994 "-select-alpn", "foo",
3995 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003996 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003997 expectedError: ":PARSE_TLSEXT:",
3998 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003999 // Test that negotiating both NPN and ALPN is forbidden.
4000 testCases = append(testCases, testCase{
4001 name: "NegotiateALPNAndNPN",
4002 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004003 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04004004 NextProtos: []string{"foo", "bar", "baz"},
4005 Bugs: ProtocolBugs{
4006 NegotiateALPNAndNPN: true,
4007 },
4008 },
4009 flags: []string{
4010 "-advertise-alpn", "\x03foo",
4011 "-select-next-proto", "foo",
4012 },
4013 shouldFail: true,
4014 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4015 })
4016 testCases = append(testCases, testCase{
4017 name: "NegotiateALPNAndNPN-Swapped",
4018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004019 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04004020 NextProtos: []string{"foo", "bar", "baz"},
4021 Bugs: ProtocolBugs{
4022 NegotiateALPNAndNPN: true,
4023 SwapNPNAndALPN: true,
4024 },
4025 },
4026 flags: []string{
4027 "-advertise-alpn", "\x03foo",
4028 "-select-next-proto", "foo",
4029 },
4030 shouldFail: true,
4031 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4032 })
David Benjamin091c4b92015-10-26 13:33:21 -04004033 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4034 testCases = append(testCases, testCase{
4035 name: "DisableNPN",
4036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004037 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04004038 NextProtos: []string{"foo"},
4039 },
4040 flags: []string{
4041 "-select-next-proto", "foo",
4042 "-disable-npn",
4043 },
4044 expectNoNextProto: true,
4045 })
Adam Langley38311732014-10-16 19:04:35 -07004046 // Resume with a corrupt ticket.
4047 testCases = append(testCases, testCase{
4048 testType: serverTest,
4049 name: "CorruptTicket",
4050 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004051 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004052 Bugs: ProtocolBugs{
4053 CorruptTicket: true,
4054 },
4055 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004056 resumeSession: true,
4057 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07004058 })
David Benjamind98452d2015-06-16 14:16:23 -04004059 // Test the ticket callback, with and without renewal.
4060 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004061 testType: serverTest,
4062 name: "TicketCallback",
4063 config: Config{
4064 MaxVersion: VersionTLS12,
4065 },
David Benjamind98452d2015-06-16 14:16:23 -04004066 resumeSession: true,
4067 flags: []string{"-use-ticket-callback"},
4068 })
4069 testCases = append(testCases, testCase{
4070 testType: serverTest,
4071 name: "TicketCallback-Renew",
4072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004073 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004074 Bugs: ProtocolBugs{
4075 ExpectNewTicket: true,
4076 },
4077 },
4078 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4079 resumeSession: true,
4080 })
Adam Langley38311732014-10-16 19:04:35 -07004081 // Resume with an oversized session id.
4082 testCases = append(testCases, testCase{
4083 testType: serverTest,
4084 name: "OversizedSessionId",
4085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004086 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004087 Bugs: ProtocolBugs{
4088 OversizedSessionId: true,
4089 },
4090 },
4091 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004092 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004093 expectedError: ":DECODE_ERROR:",
4094 })
David Benjaminca6c8262014-11-15 19:06:08 -05004095 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4096 // are ignored.
4097 testCases = append(testCases, testCase{
4098 protocol: dtls,
4099 name: "SRTP-Client",
4100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004101 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004102 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4103 },
4104 flags: []string{
4105 "-srtp-profiles",
4106 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4107 },
4108 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4109 })
4110 testCases = append(testCases, testCase{
4111 protocol: dtls,
4112 testType: serverTest,
4113 name: "SRTP-Server",
4114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004115 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004116 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4117 },
4118 flags: []string{
4119 "-srtp-profiles",
4120 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4121 },
4122 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4123 })
4124 // Test that the MKI is ignored.
4125 testCases = append(testCases, testCase{
4126 protocol: dtls,
4127 testType: serverTest,
4128 name: "SRTP-Server-IgnoreMKI",
4129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004130 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004131 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4132 Bugs: ProtocolBugs{
4133 SRTPMasterKeyIdentifer: "bogus",
4134 },
4135 },
4136 flags: []string{
4137 "-srtp-profiles",
4138 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4139 },
4140 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4141 })
4142 // Test that SRTP isn't negotiated on the server if there were
4143 // no matching profiles.
4144 testCases = append(testCases, testCase{
4145 protocol: dtls,
4146 testType: serverTest,
4147 name: "SRTP-Server-NoMatch",
4148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004149 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004150 SRTPProtectionProfiles: []uint16{100, 101, 102},
4151 },
4152 flags: []string{
4153 "-srtp-profiles",
4154 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4155 },
4156 expectedSRTPProtectionProfile: 0,
4157 })
4158 // Test that the server returning an invalid SRTP profile is
4159 // flagged as an error by the client.
4160 testCases = append(testCases, testCase{
4161 protocol: dtls,
4162 name: "SRTP-Client-NoMatch",
4163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004164 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004165 Bugs: ProtocolBugs{
4166 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4167 },
4168 },
4169 flags: []string{
4170 "-srtp-profiles",
4171 "SRTP_AES128_CM_SHA1_80",
4172 },
4173 shouldFail: true,
4174 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4175 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004176 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004177 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004178 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004179 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004180 config: Config{
4181 MaxVersion: VersionTLS12,
4182 },
David Benjamin61f95272014-11-25 01:55:35 -05004183 flags: []string{
4184 "-enable-signed-cert-timestamps",
4185 "-expect-signed-cert-timestamps",
4186 base64.StdEncoding.EncodeToString(testSCTList),
4187 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004188 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004189 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004190 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004191 name: "SendSCTListOnResume",
4192 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004193 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004194 Bugs: ProtocolBugs{
4195 SendSCTListOnResume: []byte("bogus"),
4196 },
4197 },
4198 flags: []string{
4199 "-enable-signed-cert-timestamps",
4200 "-expect-signed-cert-timestamps",
4201 base64.StdEncoding.EncodeToString(testSCTList),
4202 },
4203 resumeSession: true,
4204 })
4205 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004206 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004207 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004208 config: Config{
4209 MaxVersion: VersionTLS12,
4210 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004211 flags: []string{
4212 "-signed-cert-timestamps",
4213 base64.StdEncoding.EncodeToString(testSCTList),
4214 },
4215 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004216 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004217 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004218
Paul Lietar4fac72e2015-09-09 13:44:55 +01004219 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004220 testType: clientTest,
4221 name: "ClientHelloPadding",
4222 config: Config{
4223 Bugs: ProtocolBugs{
4224 RequireClientHelloSize: 512,
4225 },
4226 },
4227 // This hostname just needs to be long enough to push the
4228 // ClientHello into F5's danger zone between 256 and 511 bytes
4229 // long.
4230 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4231 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004232
4233 // Extensions should not function in SSL 3.0.
4234 testCases = append(testCases, testCase{
4235 testType: serverTest,
4236 name: "SSLv3Extensions-NoALPN",
4237 config: Config{
4238 MaxVersion: VersionSSL30,
4239 NextProtos: []string{"foo", "bar", "baz"},
4240 },
4241 flags: []string{
4242 "-select-alpn", "foo",
4243 },
4244 expectNoNextProto: true,
4245 })
4246
4247 // Test session tickets separately as they follow a different codepath.
4248 testCases = append(testCases, testCase{
4249 testType: serverTest,
4250 name: "SSLv3Extensions-NoTickets",
4251 config: Config{
4252 MaxVersion: VersionSSL30,
4253 Bugs: ProtocolBugs{
4254 // Historically, session tickets in SSL 3.0
4255 // failed in different ways depending on whether
4256 // the client supported renegotiation_info.
4257 NoRenegotiationInfo: true,
4258 },
4259 },
4260 resumeSession: true,
4261 })
4262 testCases = append(testCases, testCase{
4263 testType: serverTest,
4264 name: "SSLv3Extensions-NoTickets2",
4265 config: Config{
4266 MaxVersion: VersionSSL30,
4267 },
4268 resumeSession: true,
4269 })
4270
4271 // But SSL 3.0 does send and process renegotiation_info.
4272 testCases = append(testCases, testCase{
4273 testType: serverTest,
4274 name: "SSLv3Extensions-RenegotiationInfo",
4275 config: Config{
4276 MaxVersion: VersionSSL30,
4277 Bugs: ProtocolBugs{
4278 RequireRenegotiationInfo: true,
4279 },
4280 },
4281 })
4282 testCases = append(testCases, testCase{
4283 testType: serverTest,
4284 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4285 config: Config{
4286 MaxVersion: VersionSSL30,
4287 Bugs: ProtocolBugs{
4288 NoRenegotiationInfo: true,
4289 SendRenegotiationSCSV: true,
4290 RequireRenegotiationInfo: true,
4291 },
4292 },
4293 })
David Benjamine78bfde2014-09-06 12:45:15 -04004294}
4295
David Benjamin01fe8202014-09-24 15:21:44 -04004296func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004297 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004298 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004299 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4300 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4301 // TLS 1.3 only shares ciphers with TLS 1.2, so
4302 // we skip certain combinations and use a
4303 // different cipher to test with.
4304 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4305 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4306 continue
4307 }
4308 }
4309
David Benjamin8b8c0062014-11-23 02:47:52 -05004310 protocols := []protocol{tls}
4311 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4312 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004313 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004314 for _, protocol := range protocols {
4315 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4316 if protocol == dtls {
4317 suffix += "-DTLS"
4318 }
4319
David Benjaminece3de92015-03-16 18:02:20 -04004320 if sessionVers.version == resumeVers.version {
4321 testCases = append(testCases, testCase{
4322 protocol: protocol,
4323 name: "Resume-Client" + suffix,
4324 resumeSession: true,
4325 config: Config{
4326 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004327 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004328 },
David Benjaminece3de92015-03-16 18:02:20 -04004329 expectedVersion: sessionVers.version,
4330 expectedResumeVersion: resumeVers.version,
4331 })
4332 } else {
4333 testCases = append(testCases, testCase{
4334 protocol: protocol,
4335 name: "Resume-Client-Mismatch" + suffix,
4336 resumeSession: true,
4337 config: Config{
4338 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004339 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004340 },
David Benjaminece3de92015-03-16 18:02:20 -04004341 expectedVersion: sessionVers.version,
4342 resumeConfig: &Config{
4343 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004344 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004345 Bugs: ProtocolBugs{
4346 AllowSessionVersionMismatch: true,
4347 },
4348 },
4349 expectedResumeVersion: resumeVers.version,
4350 shouldFail: true,
4351 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4352 })
4353 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004354
4355 testCases = append(testCases, testCase{
4356 protocol: protocol,
4357 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004358 resumeSession: true,
4359 config: Config{
4360 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004361 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004362 },
4363 expectedVersion: sessionVers.version,
4364 resumeConfig: &Config{
4365 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004366 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004367 },
4368 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004369 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004370 expectedResumeVersion: resumeVers.version,
4371 })
4372
David Benjamin8b8c0062014-11-23 02:47:52 -05004373 testCases = append(testCases, testCase{
4374 protocol: protocol,
4375 testType: serverTest,
4376 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004377 resumeSession: true,
4378 config: Config{
4379 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004380 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004381 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004382 expectedVersion: sessionVers.version,
4383 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004384 resumeConfig: &Config{
4385 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004386 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004387 },
4388 expectedResumeVersion: resumeVers.version,
4389 })
4390 }
David Benjamin01fe8202014-09-24 15:21:44 -04004391 }
4392 }
David Benjaminece3de92015-03-16 18:02:20 -04004393
Nick Harper1fd39d82016-06-14 18:14:35 -07004394 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004395 testCases = append(testCases, testCase{
4396 name: "Resume-Client-CipherMismatch",
4397 resumeSession: true,
4398 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004399 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004400 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4401 },
4402 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004403 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004404 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4405 Bugs: ProtocolBugs{
4406 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4407 },
4408 },
4409 shouldFail: true,
4410 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4411 })
David Benjamin01fe8202014-09-24 15:21:44 -04004412}
4413
Adam Langley2ae77d22014-10-28 17:29:33 -07004414func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004415 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004416 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004417 testType: serverTest,
4418 name: "Renegotiate-Server-Forbidden",
4419 config: Config{
4420 MaxVersion: VersionTLS12,
4421 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004422 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004423 shouldFail: true,
4424 expectedError: ":NO_RENEGOTIATION:",
4425 expectedLocalError: "remote error: no renegotiation",
4426 })
Adam Langley5021b222015-06-12 18:27:58 -07004427 // The server shouldn't echo the renegotiation extension unless
4428 // requested by the client.
4429 testCases = append(testCases, testCase{
4430 testType: serverTest,
4431 name: "Renegotiate-Server-NoExt",
4432 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004433 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004434 Bugs: ProtocolBugs{
4435 NoRenegotiationInfo: true,
4436 RequireRenegotiationInfo: true,
4437 },
4438 },
4439 shouldFail: true,
4440 expectedLocalError: "renegotiation extension missing",
4441 })
4442 // The renegotiation SCSV should be sufficient for the server to echo
4443 // the extension.
4444 testCases = append(testCases, testCase{
4445 testType: serverTest,
4446 name: "Renegotiate-Server-NoExt-SCSV",
4447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004448 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004449 Bugs: ProtocolBugs{
4450 NoRenegotiationInfo: true,
4451 SendRenegotiationSCSV: true,
4452 RequireRenegotiationInfo: true,
4453 },
4454 },
4455 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004456 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004457 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004459 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004460 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004461 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004462 },
4463 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004464 renegotiate: 1,
4465 flags: []string{
4466 "-renegotiate-freely",
4467 "-expect-total-renegotiations", "1",
4468 },
David Benjamincdea40c2015-03-19 14:09:43 -04004469 })
4470 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004471 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004472 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004474 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004475 Bugs: ProtocolBugs{
4476 EmptyRenegotiationInfo: true,
4477 },
4478 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004479 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004480 shouldFail: true,
4481 expectedError: ":RENEGOTIATION_MISMATCH:",
4482 })
4483 testCases = append(testCases, testCase{
4484 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004485 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004486 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004487 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004488 Bugs: ProtocolBugs{
4489 BadRenegotiationInfo: true,
4490 },
4491 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004492 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004493 shouldFail: true,
4494 expectedError: ":RENEGOTIATION_MISMATCH:",
4495 })
4496 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004497 name: "Renegotiate-Client-Downgrade",
4498 renegotiate: 1,
4499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004500 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004501 Bugs: ProtocolBugs{
4502 NoRenegotiationInfoAfterInitial: true,
4503 },
4504 },
4505 flags: []string{"-renegotiate-freely"},
4506 shouldFail: true,
4507 expectedError: ":RENEGOTIATION_MISMATCH:",
4508 })
4509 testCases = append(testCases, testCase{
4510 name: "Renegotiate-Client-Upgrade",
4511 renegotiate: 1,
4512 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004513 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004514 Bugs: ProtocolBugs{
4515 NoRenegotiationInfoInInitial: true,
4516 },
4517 },
4518 flags: []string{"-renegotiate-freely"},
4519 shouldFail: true,
4520 expectedError: ":RENEGOTIATION_MISMATCH:",
4521 })
4522 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004523 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004524 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004525 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004526 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004527 Bugs: ProtocolBugs{
4528 NoRenegotiationInfo: true,
4529 },
4530 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004531 flags: []string{
4532 "-renegotiate-freely",
4533 "-expect-total-renegotiations", "1",
4534 },
David Benjamincff0b902015-05-15 23:09:47 -04004535 })
4536 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004537 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004538 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004540 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004541 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4542 },
4543 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004544 flags: []string{
4545 "-renegotiate-freely",
4546 "-expect-total-renegotiations", "1",
4547 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004548 })
4549 testCases = append(testCases, testCase{
4550 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004551 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004552 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004553 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004554 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4555 },
4556 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004557 flags: []string{
4558 "-renegotiate-freely",
4559 "-expect-total-renegotiations", "1",
4560 },
David Benjaminb16346b2015-04-08 19:16:58 -04004561 })
4562 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004563 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004564 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004565 config: Config{
4566 MaxVersion: VersionTLS10,
4567 Bugs: ProtocolBugs{
4568 RequireSameRenegoClientVersion: true,
4569 },
4570 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004571 flags: []string{
4572 "-renegotiate-freely",
4573 "-expect-total-renegotiations", "1",
4574 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004575 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004576 testCases = append(testCases, testCase{
4577 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004578 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004579 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004580 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4582 NextProtos: []string{"foo"},
4583 },
4584 flags: []string{
4585 "-false-start",
4586 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004587 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004588 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004589 },
4590 shimWritesFirst: true,
4591 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004592
4593 // Client-side renegotiation controls.
4594 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004595 name: "Renegotiate-Client-Forbidden-1",
4596 config: Config{
4597 MaxVersion: VersionTLS12,
4598 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004599 renegotiate: 1,
4600 shouldFail: true,
4601 expectedError: ":NO_RENEGOTIATION:",
4602 expectedLocalError: "remote error: no renegotiation",
4603 })
4604 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004605 name: "Renegotiate-Client-Once-1",
4606 config: Config{
4607 MaxVersion: VersionTLS12,
4608 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004609 renegotiate: 1,
4610 flags: []string{
4611 "-renegotiate-once",
4612 "-expect-total-renegotiations", "1",
4613 },
4614 })
4615 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004616 name: "Renegotiate-Client-Freely-1",
4617 config: Config{
4618 MaxVersion: VersionTLS12,
4619 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004620 renegotiate: 1,
4621 flags: []string{
4622 "-renegotiate-freely",
4623 "-expect-total-renegotiations", "1",
4624 },
4625 })
4626 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004627 name: "Renegotiate-Client-Once-2",
4628 config: Config{
4629 MaxVersion: VersionTLS12,
4630 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004631 renegotiate: 2,
4632 flags: []string{"-renegotiate-once"},
4633 shouldFail: true,
4634 expectedError: ":NO_RENEGOTIATION:",
4635 expectedLocalError: "remote error: no renegotiation",
4636 })
4637 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004638 name: "Renegotiate-Client-Freely-2",
4639 config: Config{
4640 MaxVersion: VersionTLS12,
4641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004642 renegotiate: 2,
4643 flags: []string{
4644 "-renegotiate-freely",
4645 "-expect-total-renegotiations", "2",
4646 },
4647 })
Adam Langley27a0d082015-11-03 13:34:10 -08004648 testCases = append(testCases, testCase{
4649 name: "Renegotiate-Client-NoIgnore",
4650 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004651 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004652 Bugs: ProtocolBugs{
4653 SendHelloRequestBeforeEveryAppDataRecord: true,
4654 },
4655 },
4656 shouldFail: true,
4657 expectedError: ":NO_RENEGOTIATION:",
4658 })
4659 testCases = append(testCases, testCase{
4660 name: "Renegotiate-Client-Ignore",
4661 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004662 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004663 Bugs: ProtocolBugs{
4664 SendHelloRequestBeforeEveryAppDataRecord: true,
4665 },
4666 },
4667 flags: []string{
4668 "-renegotiate-ignore",
4669 "-expect-total-renegotiations", "0",
4670 },
4671 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004672
4673 // TODO(davidben): Add a test that HelloRequests are illegal in TLS 1.3.
Adam Langley2ae77d22014-10-28 17:29:33 -07004674}
4675
David Benjamin5e961c12014-11-07 01:48:35 -05004676func addDTLSReplayTests() {
4677 // Test that sequence number replays are detected.
4678 testCases = append(testCases, testCase{
4679 protocol: dtls,
4680 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004681 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004682 replayWrites: true,
4683 })
4684
David Benjamin8e6db492015-07-25 18:29:23 -04004685 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004686 // than the retransmit window.
4687 testCases = append(testCases, testCase{
4688 protocol: dtls,
4689 name: "DTLS-Replay-LargeGaps",
4690 config: Config{
4691 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004692 SequenceNumberMapping: func(in uint64) uint64 {
4693 return in * 127
4694 },
David Benjamin5e961c12014-11-07 01:48:35 -05004695 },
4696 },
David Benjamin8e6db492015-07-25 18:29:23 -04004697 messageCount: 200,
4698 replayWrites: true,
4699 })
4700
4701 // Test the incoming sequence number changing non-monotonically.
4702 testCases = append(testCases, testCase{
4703 protocol: dtls,
4704 name: "DTLS-Replay-NonMonotonic",
4705 config: Config{
4706 Bugs: ProtocolBugs{
4707 SequenceNumberMapping: func(in uint64) uint64 {
4708 return in ^ 31
4709 },
4710 },
4711 },
4712 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004713 replayWrites: true,
4714 })
4715}
4716
Nick Harper60edffd2016-06-21 15:19:24 -07004717var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004718 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004719 id signatureAlgorithm
4720 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004721}{
Nick Harper60edffd2016-06-21 15:19:24 -07004722 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4723 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4724 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4725 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
4726 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSA},
4727 // TODO(davidben): These signature algorithms are paired with a curve in
4728 // TLS 1.3. Test that, in TLS 1.3, the curves must match and, in TLS
4729 // 1.2, mismatches are tolerated.
4730 {"ECDSA-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSA},
4731 {"ECDSA-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSA},
4732 {"ECDSA-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSA},
David Benjamin000800a2014-11-14 01:43:59 -05004733}
4734
Nick Harper60edffd2016-06-21 15:19:24 -07004735const fakeSigAlg1 signatureAlgorithm = 0x2a01
4736const fakeSigAlg2 signatureAlgorithm = 0xff01
4737
4738func addSignatureAlgorithmTests() {
4739 // Make sure each signature algorithm works. Include some fake values in
4740 // the list and ensure they're ignored.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004741 //
4742 // TODO(davidben): Test each of these against both TLS 1.2 and TLS 1.3.
Nick Harper60edffd2016-06-21 15:19:24 -07004743 for _, alg := range testSignatureAlgorithms {
David Benjamin000800a2014-11-14 01:43:59 -05004744 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004745 name: "SigningHash-ClientAuth-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004746 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004747 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004748 // SignatureAlgorithms is shared, so we must
4749 // configure a matching server certificate too.
4750 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4751 ClientAuth: RequireAnyClientCert,
4752 SignatureAlgorithms: []signatureAlgorithm{
4753 fakeSigAlg1,
4754 alg.id,
4755 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004756 },
4757 },
4758 flags: []string{
Nick Harper60edffd2016-06-21 15:19:24 -07004759 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4760 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4761 },
4762 expectedPeerSignatureAlgorithm: alg.id,
4763 })
4764
4765 testCases = append(testCases, testCase{
4766 testType: serverTest,
4767 name: "SigningHash-ClientAuth-Verify-" + alg.name,
4768 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004769 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004770 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4771 SignatureAlgorithms: []signatureAlgorithm{
4772 alg.id,
4773 },
4774 },
4775 flags: []string{
4776 "-require-any-client-certificate",
4777 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4778 // SignatureAlgorithms is shared, so we must
4779 // configure a matching server certificate too.
4780 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4781 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin000800a2014-11-14 01:43:59 -05004782 },
4783 })
4784
4785 testCases = append(testCases, testCase{
4786 testType: serverTest,
Nick Harper60edffd2016-06-21 15:19:24 -07004787 name: "SigningHash-ServerKeyExchange-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004788 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004789 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004790 CipherSuites: []uint16{
4791 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4792 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4793 },
4794 SignatureAlgorithms: []signatureAlgorithm{
4795 fakeSigAlg1,
4796 alg.id,
4797 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004798 },
4799 },
Nick Harper60edffd2016-06-21 15:19:24 -07004800 flags: []string{
4801 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4802 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4803 },
4804 expectedPeerSignatureAlgorithm: alg.id,
David Benjamin000800a2014-11-14 01:43:59 -05004805 })
David Benjamin6e807652015-11-02 12:02:20 -05004806
4807 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004808 name: "SigningHash-ServerKeyExchange-Verify-" + alg.name,
David Benjamin6e807652015-11-02 12:02:20 -05004809 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004810 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004811 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4812 CipherSuites: []uint16{
4813 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4814 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4815 },
4816 SignatureAlgorithms: []signatureAlgorithm{
4817 alg.id,
David Benjamin6e807652015-11-02 12:02:20 -05004818 },
4819 },
Nick Harper60edffd2016-06-21 15:19:24 -07004820 flags: []string{"-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id))},
David Benjamin6e807652015-11-02 12:02:20 -05004821 })
David Benjamin000800a2014-11-14 01:43:59 -05004822 }
4823
Nick Harper60edffd2016-06-21 15:19:24 -07004824 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004825 //
4826 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004827 testCases = append(testCases, testCase{
4828 name: "SigningHash-ClientAuth-SignatureType",
4829 config: Config{
4830 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004831 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004832 SignatureAlgorithms: []signatureAlgorithm{
4833 signatureECDSAWithP521AndSHA512,
4834 signatureRSAPKCS1WithSHA384,
4835 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004836 },
4837 },
4838 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004839 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4840 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004841 },
Nick Harper60edffd2016-06-21 15:19:24 -07004842 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004843 })
4844
4845 testCases = append(testCases, testCase{
4846 testType: serverTest,
4847 name: "SigningHash-ServerKeyExchange-SignatureType",
4848 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004849 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004850 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004851 SignatureAlgorithms: []signatureAlgorithm{
4852 signatureECDSAWithP521AndSHA512,
4853 signatureRSAPKCS1WithSHA384,
4854 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004855 },
4856 },
Nick Harper60edffd2016-06-21 15:19:24 -07004857 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004858 })
4859
4860 // Test that, if the list is missing, the peer falls back to SHA-1.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004861 //
4862 // TODO(davidben): Test this does not happen in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004863 testCases = append(testCases, testCase{
4864 name: "SigningHash-ClientAuth-Fallback",
4865 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004866 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004867 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004868 SignatureAlgorithms: []signatureAlgorithm{
4869 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004870 },
4871 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004872 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004873 },
4874 },
4875 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004876 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4877 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004878 },
4879 })
4880
4881 testCases = append(testCases, testCase{
4882 testType: serverTest,
4883 name: "SigningHash-ServerKeyExchange-Fallback",
4884 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004885 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004887 SignatureAlgorithms: []signatureAlgorithm{
4888 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004889 },
4890 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004891 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004892 },
4893 },
4894 })
David Benjamin72dc7832015-03-16 17:49:43 -04004895
4896 // Test that hash preferences are enforced. BoringSSL defaults to
4897 // rejecting MD5 signatures.
4898 testCases = append(testCases, testCase{
4899 testType: serverTest,
4900 name: "SigningHash-ClientAuth-Enforced",
4901 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004902 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004903 Certificates: []Certificate{rsaCertificate},
Nick Harper60edffd2016-06-21 15:19:24 -07004904 SignatureAlgorithms: []signatureAlgorithm{
4905 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004906 // Advertise SHA-1 so the handshake will
4907 // proceed, but the shim's preferences will be
4908 // ignored in CertificateVerify generation, so
4909 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07004910 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04004911 },
4912 Bugs: ProtocolBugs{
4913 IgnorePeerSignatureAlgorithmPreferences: true,
4914 },
4915 },
4916 flags: []string{"-require-any-client-certificate"},
4917 shouldFail: true,
4918 expectedError: ":WRONG_SIGNATURE_TYPE:",
4919 })
4920
4921 testCases = append(testCases, testCase{
4922 name: "SigningHash-ServerKeyExchange-Enforced",
4923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004924 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004925 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004926 SignatureAlgorithms: []signatureAlgorithm{
4927 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004928 },
4929 Bugs: ProtocolBugs{
4930 IgnorePeerSignatureAlgorithmPreferences: true,
4931 },
4932 },
4933 shouldFail: true,
4934 expectedError: ":WRONG_SIGNATURE_TYPE:",
4935 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004936
4937 // Test that the agreed upon digest respects the client preferences and
4938 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004939 //
4940 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04004941 testCases = append(testCases, testCase{
4942 name: "Agree-Digest-Fallback",
4943 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004944 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004945 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004946 SignatureAlgorithms: []signatureAlgorithm{
4947 signatureRSAPKCS1WithSHA512,
4948 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004949 },
4950 },
4951 flags: []string{
4952 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4953 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4954 },
Nick Harper60edffd2016-06-21 15:19:24 -07004955 digestPrefs: "SHA256",
4956 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004957 })
4958 testCases = append(testCases, testCase{
4959 name: "Agree-Digest-SHA256",
4960 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004961 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004962 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004963 SignatureAlgorithms: []signatureAlgorithm{
4964 signatureRSAPKCS1WithSHA1,
4965 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004966 },
4967 },
4968 flags: []string{
4969 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4970 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4971 },
Nick Harper60edffd2016-06-21 15:19:24 -07004972 digestPrefs: "SHA256,SHA1",
4973 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004974 })
4975 testCases = append(testCases, testCase{
4976 name: "Agree-Digest-SHA1",
4977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004978 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004979 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004980 SignatureAlgorithms: []signatureAlgorithm{
4981 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004982 },
4983 },
4984 flags: []string{
4985 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4986 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4987 },
Nick Harper60edffd2016-06-21 15:19:24 -07004988 digestPrefs: "SHA512,SHA256,SHA1",
4989 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004990 })
4991 testCases = append(testCases, testCase{
4992 name: "Agree-Digest-Default",
4993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004994 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004995 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004996 SignatureAlgorithms: []signatureAlgorithm{
4997 signatureRSAPKCS1WithSHA256,
4998 signatureECDSAWithP256AndSHA256,
4999 signatureRSAPKCS1WithSHA1,
5000 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005001 },
5002 },
5003 flags: []string{
5004 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5005 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5006 },
Nick Harper60edffd2016-06-21 15:19:24 -07005007 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005008 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005009
5010 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5011 // signature algorithms.
5012 //
5013 // TODO(davidben): Add a TLS 1.3 version of this test where the mismatch
5014 // is allowed.
5015 testCases = append(testCases, testCase{
5016 name: "CheckLeafCurve",
5017 config: Config{
5018 MaxVersion: VersionTLS12,
5019 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5020 Certificates: []Certificate{getECDSACertificate()},
5021 },
5022 flags: []string{"-p384-only"},
5023 shouldFail: true,
5024 expectedError: ":BAD_ECC_CERT:",
5025 })
David Benjamin000800a2014-11-14 01:43:59 -05005026}
5027
David Benjamin83f90402015-01-27 01:09:43 -05005028// timeouts is the retransmit schedule for BoringSSL. It doubles and
5029// caps at 60 seconds. On the 13th timeout, it gives up.
5030var timeouts = []time.Duration{
5031 1 * time.Second,
5032 2 * time.Second,
5033 4 * time.Second,
5034 8 * time.Second,
5035 16 * time.Second,
5036 32 * time.Second,
5037 60 * time.Second,
5038 60 * time.Second,
5039 60 * time.Second,
5040 60 * time.Second,
5041 60 * time.Second,
5042 60 * time.Second,
5043 60 * time.Second,
5044}
5045
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005046// shortTimeouts is an alternate set of timeouts which would occur if the
5047// initial timeout duration was set to 250ms.
5048var shortTimeouts = []time.Duration{
5049 250 * time.Millisecond,
5050 500 * time.Millisecond,
5051 1 * time.Second,
5052 2 * time.Second,
5053 4 * time.Second,
5054 8 * time.Second,
5055 16 * time.Second,
5056 32 * time.Second,
5057 60 * time.Second,
5058 60 * time.Second,
5059 60 * time.Second,
5060 60 * time.Second,
5061 60 * time.Second,
5062}
5063
David Benjamin83f90402015-01-27 01:09:43 -05005064func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005065 // These tests work by coordinating some behavior on both the shim and
5066 // the runner.
5067 //
5068 // TimeoutSchedule configures the runner to send a series of timeout
5069 // opcodes to the shim (see packetAdaptor) immediately before reading
5070 // each peer handshake flight N. The timeout opcode both simulates a
5071 // timeout in the shim and acts as a synchronization point to help the
5072 // runner bracket each handshake flight.
5073 //
5074 // We assume the shim does not read from the channel eagerly. It must
5075 // first wait until it has sent flight N and is ready to receive
5076 // handshake flight N+1. At this point, it will process the timeout
5077 // opcode. It must then immediately respond with a timeout ACK and act
5078 // as if the shim was idle for the specified amount of time.
5079 //
5080 // The runner then drops all packets received before the ACK and
5081 // continues waiting for flight N. This ordering results in one attempt
5082 // at sending flight N to be dropped. For the test to complete, the
5083 // shim must send flight N again, testing that the shim implements DTLS
5084 // retransmit on a timeout.
5085
David Benjamin4c3ddf72016-06-29 18:13:53 -04005086 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5087 // likely be more epochs to cross and the final message's retransmit may
5088 // be more complex.
5089
David Benjamin585d7a42016-06-02 14:58:00 -04005090 for _, async := range []bool{true, false} {
5091 var tests []testCase
5092
5093 // Test that this is indeed the timeout schedule. Stress all
5094 // four patterns of handshake.
5095 for i := 1; i < len(timeouts); i++ {
5096 number := strconv.Itoa(i)
5097 tests = append(tests, testCase{
5098 protocol: dtls,
5099 name: "DTLS-Retransmit-Client-" + number,
5100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005101 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005102 Bugs: ProtocolBugs{
5103 TimeoutSchedule: timeouts[:i],
5104 },
5105 },
5106 resumeSession: true,
5107 })
5108 tests = append(tests, testCase{
5109 protocol: dtls,
5110 testType: serverTest,
5111 name: "DTLS-Retransmit-Server-" + number,
5112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005113 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005114 Bugs: ProtocolBugs{
5115 TimeoutSchedule: timeouts[:i],
5116 },
5117 },
5118 resumeSession: true,
5119 })
5120 }
5121
5122 // Test that exceeding the timeout schedule hits a read
5123 // timeout.
5124 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005125 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005126 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005127 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005128 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005129 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005130 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005131 },
5132 },
5133 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005134 shouldFail: true,
5135 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005136 })
David Benjamin585d7a42016-06-02 14:58:00 -04005137
5138 if async {
5139 // Test that timeout handling has a fudge factor, due to API
5140 // problems.
5141 tests = append(tests, testCase{
5142 protocol: dtls,
5143 name: "DTLS-Retransmit-Fudge",
5144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005145 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005146 Bugs: ProtocolBugs{
5147 TimeoutSchedule: []time.Duration{
5148 timeouts[0] - 10*time.Millisecond,
5149 },
5150 },
5151 },
5152 resumeSession: true,
5153 })
5154 }
5155
5156 // Test that the final Finished retransmitting isn't
5157 // duplicated if the peer badly fragments everything.
5158 tests = append(tests, testCase{
5159 testType: serverTest,
5160 protocol: dtls,
5161 name: "DTLS-Retransmit-Fragmented",
5162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005163 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005164 Bugs: ProtocolBugs{
5165 TimeoutSchedule: []time.Duration{timeouts[0]},
5166 MaxHandshakeRecordLength: 2,
5167 },
5168 },
5169 })
5170
5171 // Test the timeout schedule when a shorter initial timeout duration is set.
5172 tests = append(tests, testCase{
5173 protocol: dtls,
5174 name: "DTLS-Retransmit-Short-Client",
5175 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005176 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005177 Bugs: ProtocolBugs{
5178 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5179 },
5180 },
5181 resumeSession: true,
5182 flags: []string{"-initial-timeout-duration-ms", "250"},
5183 })
5184 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005185 protocol: dtls,
5186 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005187 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005188 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005189 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005190 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005191 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005192 },
5193 },
5194 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005195 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005196 })
David Benjamin585d7a42016-06-02 14:58:00 -04005197
5198 for _, test := range tests {
5199 if async {
5200 test.name += "-Async"
5201 test.flags = append(test.flags, "-async")
5202 }
5203
5204 testCases = append(testCases, test)
5205 }
David Benjamin83f90402015-01-27 01:09:43 -05005206 }
David Benjamin83f90402015-01-27 01:09:43 -05005207}
5208
David Benjaminc565ebb2015-04-03 04:06:36 -04005209func addExportKeyingMaterialTests() {
5210 for _, vers := range tlsVersions {
5211 if vers.version == VersionSSL30 {
5212 continue
5213 }
5214 testCases = append(testCases, testCase{
5215 name: "ExportKeyingMaterial-" + vers.name,
5216 config: Config{
5217 MaxVersion: vers.version,
5218 },
5219 exportKeyingMaterial: 1024,
5220 exportLabel: "label",
5221 exportContext: "context",
5222 useExportContext: true,
5223 })
5224 testCases = append(testCases, testCase{
5225 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5226 config: Config{
5227 MaxVersion: vers.version,
5228 },
5229 exportKeyingMaterial: 1024,
5230 })
5231 testCases = append(testCases, testCase{
5232 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5233 config: Config{
5234 MaxVersion: vers.version,
5235 },
5236 exportKeyingMaterial: 1024,
5237 useExportContext: true,
5238 })
5239 testCases = append(testCases, testCase{
5240 name: "ExportKeyingMaterial-Small-" + vers.name,
5241 config: Config{
5242 MaxVersion: vers.version,
5243 },
5244 exportKeyingMaterial: 1,
5245 exportLabel: "label",
5246 exportContext: "context",
5247 useExportContext: true,
5248 })
5249 }
5250 testCases = append(testCases, testCase{
5251 name: "ExportKeyingMaterial-SSL3",
5252 config: Config{
5253 MaxVersion: VersionSSL30,
5254 },
5255 exportKeyingMaterial: 1024,
5256 exportLabel: "label",
5257 exportContext: "context",
5258 useExportContext: true,
5259 shouldFail: true,
5260 expectedError: "failed to export keying material",
5261 })
5262}
5263
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005264func addTLSUniqueTests() {
5265 for _, isClient := range []bool{false, true} {
5266 for _, isResumption := range []bool{false, true} {
5267 for _, hasEMS := range []bool{false, true} {
5268 var suffix string
5269 if isResumption {
5270 suffix = "Resume-"
5271 } else {
5272 suffix = "Full-"
5273 }
5274
5275 if hasEMS {
5276 suffix += "EMS-"
5277 } else {
5278 suffix += "NoEMS-"
5279 }
5280
5281 if isClient {
5282 suffix += "Client"
5283 } else {
5284 suffix += "Server"
5285 }
5286
5287 test := testCase{
5288 name: "TLSUnique-" + suffix,
5289 testTLSUnique: true,
5290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005291 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005292 Bugs: ProtocolBugs{
5293 NoExtendedMasterSecret: !hasEMS,
5294 },
5295 },
5296 }
5297
5298 if isResumption {
5299 test.resumeSession = true
5300 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005301 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005302 Bugs: ProtocolBugs{
5303 NoExtendedMasterSecret: !hasEMS,
5304 },
5305 }
5306 }
5307
5308 if isResumption && !hasEMS {
5309 test.shouldFail = true
5310 test.expectedError = "failed to get tls-unique"
5311 }
5312
5313 testCases = append(testCases, test)
5314 }
5315 }
5316 }
5317}
5318
Adam Langley09505632015-07-30 18:10:13 -07005319func addCustomExtensionTests() {
5320 expectedContents := "custom extension"
5321 emptyString := ""
5322
David Benjamin4c3ddf72016-06-29 18:13:53 -04005323 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005324 for _, isClient := range []bool{false, true} {
5325 suffix := "Server"
5326 flag := "-enable-server-custom-extension"
5327 testType := serverTest
5328 if isClient {
5329 suffix = "Client"
5330 flag = "-enable-client-custom-extension"
5331 testType = clientTest
5332 }
5333
5334 testCases = append(testCases, testCase{
5335 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005336 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005338 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005339 Bugs: ProtocolBugs{
5340 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005341 ExpectedCustomExtension: &expectedContents,
5342 },
5343 },
5344 flags: []string{flag},
5345 })
5346
5347 // If the parse callback fails, the handshake should also fail.
5348 testCases = append(testCases, testCase{
5349 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005350 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005351 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005352 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005353 Bugs: ProtocolBugs{
5354 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005355 ExpectedCustomExtension: &expectedContents,
5356 },
5357 },
David Benjamin399e7c92015-07-30 23:01:27 -04005358 flags: []string{flag},
5359 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005360 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5361 })
5362
5363 // If the add callback fails, the handshake should also fail.
5364 testCases = append(testCases, testCase{
5365 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005366 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005367 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005368 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005369 Bugs: ProtocolBugs{
5370 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005371 ExpectedCustomExtension: &expectedContents,
5372 },
5373 },
David Benjamin399e7c92015-07-30 23:01:27 -04005374 flags: []string{flag, "-custom-extension-fail-add"},
5375 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005376 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5377 })
5378
5379 // If the add callback returns zero, no extension should be
5380 // added.
5381 skipCustomExtension := expectedContents
5382 if isClient {
5383 // For the case where the client skips sending the
5384 // custom extension, the server must not “echo” it.
5385 skipCustomExtension = ""
5386 }
5387 testCases = append(testCases, testCase{
5388 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005389 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005391 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005392 Bugs: ProtocolBugs{
5393 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005394 ExpectedCustomExtension: &emptyString,
5395 },
5396 },
5397 flags: []string{flag, "-custom-extension-skip"},
5398 })
5399 }
5400
5401 // The custom extension add callback should not be called if the client
5402 // doesn't send the extension.
5403 testCases = append(testCases, testCase{
5404 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005405 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005406 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005407 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005408 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005409 ExpectedCustomExtension: &emptyString,
5410 },
5411 },
5412 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5413 })
Adam Langley2deb9842015-08-07 11:15:37 -07005414
5415 // Test an unknown extension from the server.
5416 testCases = append(testCases, testCase{
5417 testType: clientTest,
5418 name: "UnknownExtension-Client",
5419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005420 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005421 Bugs: ProtocolBugs{
5422 CustomExtension: expectedContents,
5423 },
5424 },
5425 shouldFail: true,
5426 expectedError: ":UNEXPECTED_EXTENSION:",
5427 })
Adam Langley09505632015-07-30 18:10:13 -07005428}
5429
David Benjaminb36a3952015-12-01 18:53:13 -05005430func addRSAClientKeyExchangeTests() {
5431 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5432 testCases = append(testCases, testCase{
5433 testType: serverTest,
5434 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5435 config: Config{
5436 // Ensure the ClientHello version and final
5437 // version are different, to detect if the
5438 // server uses the wrong one.
5439 MaxVersion: VersionTLS11,
5440 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5441 Bugs: ProtocolBugs{
5442 BadRSAClientKeyExchange: bad,
5443 },
5444 },
5445 shouldFail: true,
5446 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5447 })
5448 }
5449}
5450
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005451var testCurves = []struct {
5452 name string
5453 id CurveID
5454}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005455 {"P-256", CurveP256},
5456 {"P-384", CurveP384},
5457 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005458 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005459}
5460
5461func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005462 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005463 for _, curve := range testCurves {
5464 testCases = append(testCases, testCase{
5465 name: "CurveTest-Client-" + curve.name,
5466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005467 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005468 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5469 CurvePreferences: []CurveID{curve.id},
5470 },
5471 flags: []string{"-enable-all-curves"},
5472 })
5473 testCases = append(testCases, testCase{
5474 testType: serverTest,
5475 name: "CurveTest-Server-" + curve.name,
5476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005477 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005478 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5479 CurvePreferences: []CurveID{curve.id},
5480 },
5481 flags: []string{"-enable-all-curves"},
5482 })
5483 }
David Benjamin241ae832016-01-15 03:04:54 -05005484
5485 // The server must be tolerant to bogus curves.
5486 const bogusCurve = 0x1234
5487 testCases = append(testCases, testCase{
5488 testType: serverTest,
5489 name: "UnknownCurve",
5490 config: Config{
5491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5492 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5493 },
5494 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005495
5496 // The server must not consider ECDHE ciphers when there are no
5497 // supported curves.
5498 testCases = append(testCases, testCase{
5499 testType: serverTest,
5500 name: "NoSupportedCurves",
5501 config: Config{
5502 // TODO(davidben): Add a TLS 1.3 version of this.
5503 MaxVersion: VersionTLS12,
5504 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5505 Bugs: ProtocolBugs{
5506 NoSupportedCurves: true,
5507 },
5508 },
5509 shouldFail: true,
5510 expectedError: ":NO_SHARED_CIPHER:",
5511 })
5512
5513 // The server must fall back to another cipher when there are no
5514 // supported curves.
5515 testCases = append(testCases, testCase{
5516 testType: serverTest,
5517 name: "NoCommonCurves",
5518 config: Config{
5519 MaxVersion: VersionTLS12,
5520 CipherSuites: []uint16{
5521 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5522 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5523 },
5524 CurvePreferences: []CurveID{CurveP224},
5525 },
5526 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5527 })
5528
5529 // The client must reject bogus curves and disabled curves.
5530 testCases = append(testCases, testCase{
5531 name: "BadECDHECurve",
5532 config: Config{
5533 // TODO(davidben): Add a TLS 1.3 version of this.
5534 MaxVersion: VersionTLS12,
5535 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5536 Bugs: ProtocolBugs{
5537 SendCurve: bogusCurve,
5538 },
5539 },
5540 shouldFail: true,
5541 expectedError: ":WRONG_CURVE:",
5542 })
5543
5544 testCases = append(testCases, testCase{
5545 name: "UnsupportedCurve",
5546 config: Config{
5547 // TODO(davidben): Add a TLS 1.3 version of this.
5548 MaxVersion: VersionTLS12,
5549 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5550 CurvePreferences: []CurveID{CurveP256},
5551 Bugs: ProtocolBugs{
5552 IgnorePeerCurvePreferences: true,
5553 },
5554 },
5555 flags: []string{"-p384-only"},
5556 shouldFail: true,
5557 expectedError: ":WRONG_CURVE:",
5558 })
5559
5560 // Test invalid curve points.
5561 testCases = append(testCases, testCase{
5562 name: "InvalidECDHPoint-Client",
5563 config: Config{
5564 // TODO(davidben): Add a TLS 1.3 version of this test.
5565 MaxVersion: VersionTLS12,
5566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5567 CurvePreferences: []CurveID{CurveP256},
5568 Bugs: ProtocolBugs{
5569 InvalidECDHPoint: true,
5570 },
5571 },
5572 shouldFail: true,
5573 expectedError: ":INVALID_ENCODING:",
5574 })
5575 testCases = append(testCases, testCase{
5576 testType: serverTest,
5577 name: "InvalidECDHPoint-Server",
5578 config: Config{
5579 // TODO(davidben): Add a TLS 1.3 version of this test.
5580 MaxVersion: VersionTLS12,
5581 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5582 CurvePreferences: []CurveID{CurveP256},
5583 Bugs: ProtocolBugs{
5584 InvalidECDHPoint: true,
5585 },
5586 },
5587 shouldFail: true,
5588 expectedError: ":INVALID_ENCODING:",
5589 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005590}
5591
Matt Braithwaite54217e42016-06-13 13:03:47 -07005592func addCECPQ1Tests() {
5593 testCases = append(testCases, testCase{
5594 testType: clientTest,
5595 name: "CECPQ1-Client-BadX25519Part",
5596 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005597 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005598 MinVersion: VersionTLS12,
5599 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5600 Bugs: ProtocolBugs{
5601 CECPQ1BadX25519Part: true,
5602 },
5603 },
5604 flags: []string{"-cipher", "kCECPQ1"},
5605 shouldFail: true,
5606 expectedLocalError: "local error: bad record MAC",
5607 })
5608 testCases = append(testCases, testCase{
5609 testType: clientTest,
5610 name: "CECPQ1-Client-BadNewhopePart",
5611 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005612 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005613 MinVersion: VersionTLS12,
5614 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5615 Bugs: ProtocolBugs{
5616 CECPQ1BadNewhopePart: true,
5617 },
5618 },
5619 flags: []string{"-cipher", "kCECPQ1"},
5620 shouldFail: true,
5621 expectedLocalError: "local error: bad record MAC",
5622 })
5623 testCases = append(testCases, testCase{
5624 testType: serverTest,
5625 name: "CECPQ1-Server-BadX25519Part",
5626 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005627 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005628 MinVersion: VersionTLS12,
5629 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5630 Bugs: ProtocolBugs{
5631 CECPQ1BadX25519Part: true,
5632 },
5633 },
5634 flags: []string{"-cipher", "kCECPQ1"},
5635 shouldFail: true,
5636 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5637 })
5638 testCases = append(testCases, testCase{
5639 testType: serverTest,
5640 name: "CECPQ1-Server-BadNewhopePart",
5641 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005642 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005643 MinVersion: VersionTLS12,
5644 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5645 Bugs: ProtocolBugs{
5646 CECPQ1BadNewhopePart: true,
5647 },
5648 },
5649 flags: []string{"-cipher", "kCECPQ1"},
5650 shouldFail: true,
5651 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5652 })
5653}
5654
David Benjamin4cc36ad2015-12-19 14:23:26 -05005655func addKeyExchangeInfoTests() {
5656 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005657 name: "KeyExchangeInfo-DHE-Client",
5658 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005659 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005660 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5661 Bugs: ProtocolBugs{
5662 // This is a 1234-bit prime number, generated
5663 // with:
5664 // openssl gendh 1234 | openssl asn1parse -i
5665 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5666 },
5667 },
David Benjamin9e68f192016-06-30 14:55:33 -04005668 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005669 })
5670 testCases = append(testCases, testCase{
5671 testType: serverTest,
5672 name: "KeyExchangeInfo-DHE-Server",
5673 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005674 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005675 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5676 },
5677 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005678 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005679 })
5680
Nick Harper1fd39d82016-06-14 18:14:35 -07005681 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5682 // handshake is separate.
5683
David Benjamin4cc36ad2015-12-19 14:23:26 -05005684 testCases = append(testCases, testCase{
5685 name: "KeyExchangeInfo-ECDHE-Client",
5686 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005687 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005688 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5689 CurvePreferences: []CurveID{CurveX25519},
5690 },
David Benjamin9e68f192016-06-30 14:55:33 -04005691 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005692 })
5693 testCases = append(testCases, testCase{
5694 testType: serverTest,
5695 name: "KeyExchangeInfo-ECDHE-Server",
5696 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005697 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5699 CurvePreferences: []CurveID{CurveX25519},
5700 },
David Benjamin9e68f192016-06-30 14:55:33 -04005701 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005702 })
5703}
5704
David Benjaminc9ae27c2016-06-24 22:56:37 -04005705func addTLS13RecordTests() {
5706 testCases = append(testCases, testCase{
5707 name: "TLS13-RecordPadding",
5708 config: Config{
5709 MaxVersion: VersionTLS13,
5710 MinVersion: VersionTLS13,
5711 Bugs: ProtocolBugs{
5712 RecordPadding: 10,
5713 },
5714 },
5715 })
5716
5717 testCases = append(testCases, testCase{
5718 name: "TLS13-EmptyRecords",
5719 config: Config{
5720 MaxVersion: VersionTLS13,
5721 MinVersion: VersionTLS13,
5722 Bugs: ProtocolBugs{
5723 OmitRecordContents: true,
5724 },
5725 },
5726 shouldFail: true,
5727 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5728 })
5729
5730 testCases = append(testCases, testCase{
5731 name: "TLS13-OnlyPadding",
5732 config: Config{
5733 MaxVersion: VersionTLS13,
5734 MinVersion: VersionTLS13,
5735 Bugs: ProtocolBugs{
5736 OmitRecordContents: true,
5737 RecordPadding: 10,
5738 },
5739 },
5740 shouldFail: true,
5741 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5742 })
5743
5744 testCases = append(testCases, testCase{
5745 name: "TLS13-WrongOuterRecord",
5746 config: Config{
5747 MaxVersion: VersionTLS13,
5748 MinVersion: VersionTLS13,
5749 Bugs: ProtocolBugs{
5750 OuterRecordType: recordTypeHandshake,
5751 },
5752 },
5753 shouldFail: true,
5754 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5755 })
5756}
5757
Adam Langley7c803a62015-06-15 15:35:05 -07005758func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005759 defer wg.Done()
5760
5761 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005762 var err error
5763
5764 if *mallocTest < 0 {
5765 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005766 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005767 } else {
5768 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5769 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005770 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005771 if err != nil {
5772 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5773 }
5774 break
5775 }
5776 }
5777 }
Adam Langley95c29f32014-06-20 12:00:00 -07005778 statusChan <- statusMsg{test: test, err: err}
5779 }
5780}
5781
5782type statusMsg struct {
5783 test *testCase
5784 started bool
5785 err error
5786}
5787
David Benjamin5f237bc2015-02-11 17:14:15 -05005788func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005789 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005790
David Benjamin5f237bc2015-02-11 17:14:15 -05005791 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005792 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005793 if !*pipe {
5794 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005795 var erase string
5796 for i := 0; i < lineLen; i++ {
5797 erase += "\b \b"
5798 }
5799 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005800 }
5801
Adam Langley95c29f32014-06-20 12:00:00 -07005802 if msg.started {
5803 started++
5804 } else {
5805 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005806
5807 if msg.err != nil {
5808 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5809 failed++
5810 testOutput.addResult(msg.test.name, "FAIL")
5811 } else {
5812 if *pipe {
5813 // Print each test instead of a status line.
5814 fmt.Printf("PASSED (%s)\n", msg.test.name)
5815 }
5816 testOutput.addResult(msg.test.name, "PASS")
5817 }
Adam Langley95c29f32014-06-20 12:00:00 -07005818 }
5819
David Benjamin5f237bc2015-02-11 17:14:15 -05005820 if !*pipe {
5821 // Print a new status line.
5822 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5823 lineLen = len(line)
5824 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005825 }
Adam Langley95c29f32014-06-20 12:00:00 -07005826 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005827
5828 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005829}
5830
5831func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005832 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005833 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005834
Adam Langley7c803a62015-06-15 15:35:05 -07005835 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005836 addCipherSuiteTests()
5837 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005838 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005839 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005840 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005841 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005842 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005843 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005844 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005845 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005846 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005847 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005848 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07005849 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05005850 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005851 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005852 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005853 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005854 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005855 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07005856 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005857 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04005858 addTLS13RecordTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04005859 for _, async := range []bool{false, true} {
5860 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04005861 for _, protocol := range []protocol{tls, dtls} {
5862 addStateMachineCoverageTests(async, splitHandshake, protocol)
5863 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005864 }
5865 }
Adam Langley95c29f32014-06-20 12:00:00 -07005866
5867 var wg sync.WaitGroup
5868
Adam Langley7c803a62015-06-15 15:35:05 -07005869 statusChan := make(chan statusMsg, *numWorkers)
5870 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005871 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005872
David Benjamin025b3d32014-07-01 19:53:04 -04005873 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005874
Adam Langley7c803a62015-06-15 15:35:05 -07005875 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005876 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005877 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005878 }
5879
David Benjamin270f0a72016-03-17 14:41:36 -04005880 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005881 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005882 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005883 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005884 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005885 }
5886 }
David Benjamin270f0a72016-03-17 14:41:36 -04005887 if !foundTest {
5888 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5889 os.Exit(1)
5890 }
Adam Langley95c29f32014-06-20 12:00:00 -07005891
5892 close(testChan)
5893 wg.Wait()
5894 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005895 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005896
5897 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005898
5899 if *jsonOutput != "" {
5900 if err := testOutput.writeTo(*jsonOutput); err != nil {
5901 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5902 }
5903 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005904
5905 if !testOutput.allPassed {
5906 os.Exit(1)
5907 }
Adam Langley95c29f32014-06-20 12:00:00 -07005908}