blob: 7c0e38bde49f703bea20130bbbc4f994a96472d1 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin025b3d32014-07-01 19:53:04 -040060const (
61 rsaCertificateFile = "cert.pem"
62 ecdsaCertificateFile = "ecdsa_cert.pem"
63)
64
65const (
David Benjamina08e49d2014-08-24 01:46:07 -040066 rsaKeyFile = "key.pem"
67 ecdsaKeyFile = "ecdsa_key.pem"
68 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040069)
70
Adam Langley95c29f32014-06-20 12:00:00 -070071var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040072var channelIDKey *ecdsa.PrivateKey
73var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070074
David Benjamin61f95272014-11-25 01:55:35 -050075var testOCSPResponse = []byte{1, 2, 3, 4}
76var testSCTList = []byte{5, 6, 7, 8}
77
Adam Langley95c29f32014-06-20 12:00:00 -070078func initCertificates() {
79 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070080 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070081 if err != nil {
82 panic(err)
83 }
David Benjamin61f95272014-11-25 01:55:35 -050084 rsaCertificate.OCSPStaple = testOCSPResponse
85 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070086
Adam Langley7c803a62015-06-15 15:35:05 -070087 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070088 if err != nil {
89 panic(err)
90 }
David Benjamin61f95272014-11-25 01:55:35 -050091 ecdsaCertificate.OCSPStaple = testOCSPResponse
92 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040093
Adam Langley7c803a62015-06-15 15:35:05 -070094 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040095 if err != nil {
96 panic(err)
97 }
98 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
99 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
100 panic("bad key type")
101 }
102 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
103 if err != nil {
104 panic(err)
105 }
106 if channelIDKey.Curve != elliptic.P256() {
107 panic("bad curve")
108 }
109
110 channelIDBytes = make([]byte, 64)
111 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
112 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700113}
114
115var certificateOnce sync.Once
116
117func getRSACertificate() Certificate {
118 certificateOnce.Do(initCertificates)
119 return rsaCertificate
120}
121
122func getECDSACertificate() Certificate {
123 certificateOnce.Do(initCertificates)
124 return ecdsaCertificate
125}
126
David Benjamin025b3d32014-07-01 19:53:04 -0400127type testType int
128
129const (
130 clientTest testType = iota
131 serverTest
132)
133
David Benjamin6fd297b2014-08-11 18:43:38 -0400134type protocol int
135
136const (
137 tls protocol = iota
138 dtls
139)
140
David Benjaminfc7b0862014-09-06 13:21:53 -0400141const (
142 alpn = 1
143 npn = 2
144)
145
Nick Harper60edffd2016-06-21 15:19:24 -0700146type testCert int
147
148const (
149 testCertRSA testCert = iota
150 testCertECDSA
151)
152
153func getRunnerCertificate(t testCert) Certificate {
154 switch t {
155 case testCertRSA:
156 return getRSACertificate()
157 case testCertECDSA:
158 return getECDSACertificate()
159 default:
160 panic("Unknown test certificate")
161 }
162}
163
164func getShimCertificate(t testCert) string {
165 switch t {
166 case testCertRSA:
167 return rsaCertificateFile
168 case testCertECDSA:
169 return ecdsaCertificateFile
170 default:
171 panic("Unknown test certificate")
172 }
173}
174
175func getShimKey(t testCert) string {
176 switch t {
177 case testCertRSA:
178 return rsaKeyFile
179 case testCertECDSA:
180 return ecdsaKeyFile
181 default:
182 panic("Unknown test certificate")
183 }
184}
185
Adam Langley95c29f32014-06-20 12:00:00 -0700186type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400187 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400188 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700189 name string
190 config Config
191 shouldFail bool
192 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700193 // expectedLocalError, if not empty, contains a substring that must be
194 // found in the local error.
195 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400196 // expectedVersion, if non-zero, specifies the TLS version that must be
197 // negotiated.
198 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400199 // expectedResumeVersion, if non-zero, specifies the TLS version that
200 // must be negotiated on resumption. If zero, expectedVersion is used.
201 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400202 // expectedCipher, if non-zero, specifies the TLS cipher suite that
203 // should be negotiated.
204 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400205 // expectChannelID controls whether the connection should have
206 // negotiated a Channel ID with channelIDKey.
207 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400208 // expectedNextProto controls whether the connection should
209 // negotiate a next protocol via NPN or ALPN.
210 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400211 // expectNoNextProto, if true, means that no next protocol should be
212 // negotiated.
213 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400214 // expectedNextProtoType, if non-zero, is the expected next
215 // protocol negotiation mechanism.
216 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500217 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
218 // should be negotiated. If zero, none should be negotiated.
219 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100220 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
221 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100222 // expectedSCTList, if not nil, is the expected SCT list to be received.
223 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700224 // expectedPeerSignatureAlgorithm, if not zero, is the signature
225 // algorithm that the peer should have used in the handshake.
226 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700227 // messageLen is the length, in bytes, of the test message that will be
228 // sent.
229 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400230 // messageCount is the number of test messages that will be sent.
231 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400232 // digestPrefs is the list of digest preferences from the client.
233 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400234 // certFile is the path to the certificate to use for the server.
235 certFile string
236 // keyFile is the path to the private key to use for the server.
237 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400238 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400239 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400240 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700241 // expectResumeRejected, if true, specifies that the attempted
242 // resumption must be rejected by the client. This is only valid for a
243 // serverTest.
244 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400245 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500246 // resumption. Unless newSessionsOnResume is set,
247 // SessionTicketKey, ServerSessionCache, and
248 // ClientSessionCache are copied from the initial connection's
249 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400250 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500251 // newSessionsOnResume, if true, will cause resumeConfig to
252 // use a different session resumption context.
253 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400254 // noSessionCache, if true, will cause the server to run without a
255 // session cache.
256 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400257 // sendPrefix sends a prefix on the socket before actually performing a
258 // handshake.
259 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400260 // shimWritesFirst controls whether the shim sends an initial "hello"
261 // message before doing a roundtrip with the runner.
262 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400263 // shimShutsDown, if true, runs a test where the shim shuts down the
264 // connection immediately after the handshake rather than echoing
265 // messages from the runner.
266 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400267 // renegotiate indicates the number of times the connection should be
268 // renegotiated during the exchange.
269 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700270 // renegotiateCiphers is a list of ciphersuite ids that will be
271 // switched in just before renegotiation.
272 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500273 // replayWrites, if true, configures the underlying transport
274 // to replay every write it makes in DTLS tests.
275 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500276 // damageFirstWrite, if true, configures the underlying transport to
277 // damage the final byte of the first application data write.
278 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400279 // exportKeyingMaterial, if non-zero, configures the test to exchange
280 // keying material and verify they match.
281 exportKeyingMaterial int
282 exportLabel string
283 exportContext string
284 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400285 // flags, if not empty, contains a list of command-line flags that will
286 // be passed to the shim program.
287 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700288 // testTLSUnique, if true, causes the shim to send the tls-unique value
289 // which will be compared against the expected value.
290 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400291 // sendEmptyRecords is the number of consecutive empty records to send
292 // before and after the test message.
293 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400294 // sendWarningAlerts is the number of consecutive warning alerts to send
295 // before and after the test message.
296 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400297 // expectMessageDropped, if true, means the test message is expected to
298 // be dropped by the client rather than echoed back.
299 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700300}
301
Adam Langley7c803a62015-06-15 15:35:05 -0700302var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700303
David Benjamin9867b7d2016-03-01 23:25:48 -0500304func writeTranscript(test *testCase, isResume bool, data []byte) {
305 if len(data) == 0 {
306 return
307 }
308
309 protocol := "tls"
310 if test.protocol == dtls {
311 protocol = "dtls"
312 }
313
314 side := "client"
315 if test.testType == serverTest {
316 side = "server"
317 }
318
319 dir := path.Join(*transcriptDir, protocol, side)
320 if err := os.MkdirAll(dir, 0755); err != nil {
321 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
322 return
323 }
324
325 name := test.name
326 if isResume {
327 name += "-Resume"
328 } else {
329 name += "-Normal"
330 }
331
332 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
333 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
334 }
335}
336
David Benjamin3ed59772016-03-08 12:50:21 -0500337// A timeoutConn implements an idle timeout on each Read and Write operation.
338type timeoutConn struct {
339 net.Conn
340 timeout time.Duration
341}
342
343func (t *timeoutConn) Read(b []byte) (int, error) {
344 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
345 return 0, err
346 }
347 return t.Conn.Read(b)
348}
349
350func (t *timeoutConn) Write(b []byte) (int, error) {
351 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
352 return 0, err
353 }
354 return t.Conn.Write(b)
355}
356
David Benjamin8e6db492015-07-25 18:29:23 -0400357func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400358 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500359
David Benjamin6fd297b2014-08-11 18:43:38 -0400360 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500361 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
362 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500363 }
364
David Benjamin9867b7d2016-03-01 23:25:48 -0500365 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500366 local, peer := "client", "server"
367 if test.testType == clientTest {
368 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500369 }
David Benjaminebda9b32015-11-02 15:33:18 -0500370 connDebug := &recordingConn{
371 Conn: conn,
372 isDatagram: test.protocol == dtls,
373 local: local,
374 peer: peer,
375 }
376 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500377 if *flagDebug {
378 defer connDebug.WriteTo(os.Stdout)
379 }
380 if len(*transcriptDir) != 0 {
381 defer func() {
382 writeTranscript(test, isResume, connDebug.Transcript())
383 }()
384 }
David Benjaminebda9b32015-11-02 15:33:18 -0500385
386 if config.Bugs.PacketAdaptor != nil {
387 config.Bugs.PacketAdaptor.debug = connDebug
388 }
389 }
390
391 if test.replayWrites {
392 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400393 }
394
David Benjamin3ed59772016-03-08 12:50:21 -0500395 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500396 if test.damageFirstWrite {
397 connDamage = newDamageAdaptor(conn)
398 conn = connDamage
399 }
400
David Benjamin6fd297b2014-08-11 18:43:38 -0400401 if test.sendPrefix != "" {
402 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
403 return err
404 }
David Benjamin98e882e2014-08-08 13:24:34 -0400405 }
406
David Benjamin1d5c83e2014-07-22 19:20:02 -0400407 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400408 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400409 if test.protocol == dtls {
410 tlsConn = DTLSServer(conn, config)
411 } else {
412 tlsConn = Server(conn, config)
413 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400414 } else {
415 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400416 if test.protocol == dtls {
417 tlsConn = DTLSClient(conn, config)
418 } else {
419 tlsConn = Client(conn, config)
420 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400421 }
David Benjamin30789da2015-08-29 22:56:45 -0400422 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400423
Adam Langley95c29f32014-06-20 12:00:00 -0700424 if err := tlsConn.Handshake(); err != nil {
425 return err
426 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700427
David Benjamin01fe8202014-09-24 15:21:44 -0400428 // TODO(davidben): move all per-connection expectations into a dedicated
429 // expectations struct that can be specified separately for the two
430 // legs.
431 expectedVersion := test.expectedVersion
432 if isResume && test.expectedResumeVersion != 0 {
433 expectedVersion = test.expectedResumeVersion
434 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700435 connState := tlsConn.ConnectionState()
436 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400437 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400438 }
439
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700440 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400441 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
442 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700443 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
444 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
445 }
David Benjamin90da8c82015-04-20 14:57:57 -0400446
David Benjamina08e49d2014-08-24 01:46:07 -0400447 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700448 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400449 if channelID == nil {
450 return fmt.Errorf("no channel ID negotiated")
451 }
452 if channelID.Curve != channelIDKey.Curve ||
453 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
454 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
455 return fmt.Errorf("incorrect channel ID")
456 }
457 }
458
David Benjaminae2888f2014-09-06 12:58:58 -0400459 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700460 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400461 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
462 }
463 }
464
David Benjaminc7ce9772015-10-09 19:32:41 -0400465 if test.expectNoNextProto {
466 if actual := connState.NegotiatedProtocol; actual != "" {
467 return fmt.Errorf("got unexpected next proto %s", actual)
468 }
469 }
470
David Benjaminfc7b0862014-09-06 13:21:53 -0400471 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700472 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400473 return fmt.Errorf("next proto type mismatch")
474 }
475 }
476
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700477 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500478 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
479 }
480
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100481 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
482 return fmt.Errorf("OCSP Response mismatch")
483 }
484
Paul Lietar4fac72e2015-09-09 13:44:55 +0100485 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
486 return fmt.Errorf("SCT list mismatch")
487 }
488
Nick Harper60edffd2016-06-21 15:19:24 -0700489 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
490 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400491 }
492
David Benjaminc565ebb2015-04-03 04:06:36 -0400493 if test.exportKeyingMaterial > 0 {
494 actual := make([]byte, test.exportKeyingMaterial)
495 if _, err := io.ReadFull(tlsConn, actual); err != nil {
496 return err
497 }
498 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
499 if err != nil {
500 return err
501 }
502 if !bytes.Equal(actual, expected) {
503 return fmt.Errorf("keying material mismatch")
504 }
505 }
506
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700507 if test.testTLSUnique {
508 var peersValue [12]byte
509 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
510 return err
511 }
512 expected := tlsConn.ConnectionState().TLSUnique
513 if !bytes.Equal(peersValue[:], expected) {
514 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
515 }
516 }
517
David Benjamine58c4f52014-08-24 03:47:07 -0400518 if test.shimWritesFirst {
519 var buf [5]byte
520 _, err := io.ReadFull(tlsConn, buf[:])
521 if err != nil {
522 return err
523 }
524 if string(buf[:]) != "hello" {
525 return fmt.Errorf("bad initial message")
526 }
527 }
528
David Benjamina8ebe222015-06-06 03:04:39 -0400529 for i := 0; i < test.sendEmptyRecords; i++ {
530 tlsConn.Write(nil)
531 }
532
David Benjamin24f346d2015-06-06 03:28:08 -0400533 for i := 0; i < test.sendWarningAlerts; i++ {
534 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
535 }
536
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400537 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700538 if test.renegotiateCiphers != nil {
539 config.CipherSuites = test.renegotiateCiphers
540 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400541 for i := 0; i < test.renegotiate; i++ {
542 if err := tlsConn.Renegotiate(); err != nil {
543 return err
544 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700545 }
546 } else if test.renegotiateCiphers != nil {
547 panic("renegotiateCiphers without renegotiate")
548 }
549
David Benjamin5fa3eba2015-01-22 16:35:40 -0500550 if test.damageFirstWrite {
551 connDamage.setDamage(true)
552 tlsConn.Write([]byte("DAMAGED WRITE"))
553 connDamage.setDamage(false)
554 }
555
David Benjamin8e6db492015-07-25 18:29:23 -0400556 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700557 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400558 if test.protocol == dtls {
559 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
560 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700561 // Read until EOF.
562 _, err := io.Copy(ioutil.Discard, tlsConn)
563 return err
564 }
David Benjamin4417d052015-04-05 04:17:25 -0400565 if messageLen == 0 {
566 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700567 }
Adam Langley95c29f32014-06-20 12:00:00 -0700568
David Benjamin8e6db492015-07-25 18:29:23 -0400569 messageCount := test.messageCount
570 if messageCount == 0 {
571 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400572 }
573
David Benjamin8e6db492015-07-25 18:29:23 -0400574 for j := 0; j < messageCount; j++ {
575 testMessage := make([]byte, messageLen)
576 for i := range testMessage {
577 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400578 }
David Benjamin8e6db492015-07-25 18:29:23 -0400579 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700580
David Benjamin8e6db492015-07-25 18:29:23 -0400581 for i := 0; i < test.sendEmptyRecords; i++ {
582 tlsConn.Write(nil)
583 }
584
585 for i := 0; i < test.sendWarningAlerts; i++ {
586 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
587 }
588
David Benjamin4f75aaf2015-09-01 16:53:10 -0400589 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400590 // The shim will not respond.
591 continue
592 }
593
David Benjamin8e6db492015-07-25 18:29:23 -0400594 buf := make([]byte, len(testMessage))
595 if test.protocol == dtls {
596 bufTmp := make([]byte, len(buf)+1)
597 n, err := tlsConn.Read(bufTmp)
598 if err != nil {
599 return err
600 }
601 if n != len(buf) {
602 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
603 }
604 copy(buf, bufTmp)
605 } else {
606 _, err := io.ReadFull(tlsConn, buf)
607 if err != nil {
608 return err
609 }
610 }
611
612 for i, v := range buf {
613 if v != testMessage[i]^0xff {
614 return fmt.Errorf("bad reply contents at byte %d", i)
615 }
Adam Langley95c29f32014-06-20 12:00:00 -0700616 }
617 }
618
619 return nil
620}
621
David Benjamin325b5c32014-07-01 19:40:31 -0400622func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
623 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700624 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400625 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700626 }
David Benjamin325b5c32014-07-01 19:40:31 -0400627 valgrindArgs = append(valgrindArgs, path)
628 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700629
David Benjamin325b5c32014-07-01 19:40:31 -0400630 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700631}
632
David Benjamin325b5c32014-07-01 19:40:31 -0400633func gdbOf(path string, args ...string) *exec.Cmd {
634 xtermArgs := []string{"-e", "gdb", "--args"}
635 xtermArgs = append(xtermArgs, path)
636 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700637
David Benjamin325b5c32014-07-01 19:40:31 -0400638 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700639}
640
David Benjamind16bf342015-12-18 00:53:12 -0500641func lldbOf(path string, args ...string) *exec.Cmd {
642 xtermArgs := []string{"-e", "lldb", "--"}
643 xtermArgs = append(xtermArgs, path)
644 xtermArgs = append(xtermArgs, args...)
645
646 return exec.Command("xterm", xtermArgs...)
647}
648
Adam Langley69a01602014-11-17 17:26:55 -0800649type moreMallocsError struct{}
650
651func (moreMallocsError) Error() string {
652 return "child process did not exhaust all allocation calls"
653}
654
655var errMoreMallocs = moreMallocsError{}
656
David Benjamin87c8a642015-02-21 01:54:29 -0500657// accept accepts a connection from listener, unless waitChan signals a process
658// exit first.
659func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
660 type connOrError struct {
661 conn net.Conn
662 err error
663 }
664 connChan := make(chan connOrError, 1)
665 go func() {
666 conn, err := listener.Accept()
667 connChan <- connOrError{conn, err}
668 close(connChan)
669 }()
670 select {
671 case result := <-connChan:
672 return result.conn, result.err
673 case childErr := <-waitChan:
674 waitChan <- childErr
675 return nil, fmt.Errorf("child exited early: %s", childErr)
676 }
677}
678
Adam Langley7c803a62015-06-15 15:35:05 -0700679func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700680 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
681 panic("Error expected without shouldFail in " + test.name)
682 }
683
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700684 if test.expectResumeRejected && !test.resumeSession {
685 panic("expectResumeRejected without resumeSession in " + test.name)
686 }
687
David Benjamin87c8a642015-02-21 01:54:29 -0500688 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
689 if err != nil {
690 panic(err)
691 }
692 defer func() {
693 if listener != nil {
694 listener.Close()
695 }
696 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin87c8a642015-02-21 01:54:29 -0500698 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400699 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400700 flags = append(flags, "-server")
701
David Benjamin025b3d32014-07-01 19:53:04 -0400702 flags = append(flags, "-key-file")
703 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700704 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400705 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700706 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400707 }
708
709 flags = append(flags, "-cert-file")
710 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700711 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400712 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700713 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400714 }
715 }
David Benjamin5a593af2014-08-11 19:51:50 -0400716
Steven Valdez0d62f262015-09-04 12:41:04 -0400717 if test.digestPrefs != "" {
718 flags = append(flags, "-digest-prefs")
719 flags = append(flags, test.digestPrefs)
720 }
721
David Benjamin6fd297b2014-08-11 18:43:38 -0400722 if test.protocol == dtls {
723 flags = append(flags, "-dtls")
724 }
725
David Benjamin5a593af2014-08-11 19:51:50 -0400726 if test.resumeSession {
727 flags = append(flags, "-resume")
728 }
729
David Benjamine58c4f52014-08-24 03:47:07 -0400730 if test.shimWritesFirst {
731 flags = append(flags, "-shim-writes-first")
732 }
733
David Benjamin30789da2015-08-29 22:56:45 -0400734 if test.shimShutsDown {
735 flags = append(flags, "-shim-shuts-down")
736 }
737
David Benjaminc565ebb2015-04-03 04:06:36 -0400738 if test.exportKeyingMaterial > 0 {
739 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
740 flags = append(flags, "-export-label", test.exportLabel)
741 flags = append(flags, "-export-context", test.exportContext)
742 if test.useExportContext {
743 flags = append(flags, "-use-export-context")
744 }
745 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700746 if test.expectResumeRejected {
747 flags = append(flags, "-expect-session-miss")
748 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400749
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700750 if test.testTLSUnique {
751 flags = append(flags, "-tls-unique")
752 }
753
David Benjamin025b3d32014-07-01 19:53:04 -0400754 flags = append(flags, test.flags...)
755
756 var shim *exec.Cmd
757 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700758 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700759 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700760 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500761 } else if *useLLDB {
762 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400763 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700764 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400765 }
David Benjamin025b3d32014-07-01 19:53:04 -0400766 shim.Stdin = os.Stdin
767 var stdoutBuf, stderrBuf bytes.Buffer
768 shim.Stdout = &stdoutBuf
769 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800770 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500771 shim.Env = os.Environ()
772 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800773 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400774 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800775 }
776 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
777 }
David Benjamin025b3d32014-07-01 19:53:04 -0400778
779 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700780 panic(err)
781 }
David Benjamin87c8a642015-02-21 01:54:29 -0500782 waitChan := make(chan error, 1)
783 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700784
785 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400786 if !test.noSessionCache {
787 config.ClientSessionCache = NewLRUClientSessionCache(1)
788 config.ServerSessionCache = NewLRUServerSessionCache(1)
789 }
David Benjamin025b3d32014-07-01 19:53:04 -0400790 if test.testType == clientTest {
791 if len(config.Certificates) == 0 {
792 config.Certificates = []Certificate{getRSACertificate()}
793 }
David Benjamin87c8a642015-02-21 01:54:29 -0500794 } else {
795 // Supply a ServerName to ensure a constant session cache key,
796 // rather than falling back to net.Conn.RemoteAddr.
797 if len(config.ServerName) == 0 {
798 config.ServerName = "test"
799 }
David Benjamin025b3d32014-07-01 19:53:04 -0400800 }
David Benjaminf2b83632016-03-01 22:57:46 -0500801 if *fuzzer {
802 config.Bugs.NullAllCiphers = true
803 }
David Benjamin2e045a92016-06-08 13:09:56 -0400804 if *deterministic {
805 config.Rand = &deterministicRand{}
806 }
Adam Langley95c29f32014-06-20 12:00:00 -0700807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 conn, err := acceptOrWait(listener, waitChan)
809 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400810 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500811 conn.Close()
812 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500813
David Benjamin1d5c83e2014-07-22 19:20:02 -0400814 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400815 var resumeConfig Config
816 if test.resumeConfig != nil {
817 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500818 if len(resumeConfig.ServerName) == 0 {
819 resumeConfig.ServerName = config.ServerName
820 }
David Benjamin01fe8202014-09-24 15:21:44 -0400821 if len(resumeConfig.Certificates) == 0 {
822 resumeConfig.Certificates = []Certificate{getRSACertificate()}
823 }
David Benjaminba4594a2015-06-18 18:36:15 -0400824 if test.newSessionsOnResume {
825 if !test.noSessionCache {
826 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
827 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
828 }
829 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500830 resumeConfig.SessionTicketKey = config.SessionTicketKey
831 resumeConfig.ClientSessionCache = config.ClientSessionCache
832 resumeConfig.ServerSessionCache = config.ServerSessionCache
833 }
David Benjaminf2b83632016-03-01 22:57:46 -0500834 if *fuzzer {
835 resumeConfig.Bugs.NullAllCiphers = true
836 }
David Benjamin2e045a92016-06-08 13:09:56 -0400837 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400838 } else {
839 resumeConfig = config
840 }
David Benjamin87c8a642015-02-21 01:54:29 -0500841 var connResume net.Conn
842 connResume, err = acceptOrWait(listener, waitChan)
843 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400844 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500845 connResume.Close()
846 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400847 }
848
David Benjamin87c8a642015-02-21 01:54:29 -0500849 // Close the listener now. This is to avoid hangs should the shim try to
850 // open more connections than expected.
851 listener.Close()
852 listener = nil
853
854 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800855 if exitError, ok := childErr.(*exec.ExitError); ok {
856 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
857 return errMoreMallocs
858 }
859 }
Adam Langley95c29f32014-06-20 12:00:00 -0700860
David Benjamin9bea3492016-03-02 10:59:16 -0500861 // Account for Windows line endings.
862 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
863 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500864
865 // Separate the errors from the shim and those from tools like
866 // AddressSanitizer.
867 var extraStderr string
868 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
869 stderr = stderrParts[0]
870 extraStderr = stderrParts[1]
871 }
872
Adam Langley95c29f32014-06-20 12:00:00 -0700873 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400874 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700875 localError := "none"
876 if err != nil {
877 localError = err.Error()
878 }
879 if len(test.expectedLocalError) != 0 {
880 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
881 }
Adam Langley95c29f32014-06-20 12:00:00 -0700882
883 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700884 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700885 if childErr != nil {
886 childError = childErr.Error()
887 }
888
889 var msg string
890 switch {
891 case failed && !test.shouldFail:
892 msg = "unexpected failure"
893 case !failed && test.shouldFail:
894 msg = "unexpected success"
895 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700896 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700897 default:
898 panic("internal error")
899 }
900
David Benjaminc565ebb2015-04-03 04:06:36 -0400901 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700902 }
903
David Benjaminff3a1492016-03-02 10:12:06 -0500904 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
905 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700906 }
907
908 return nil
909}
910
911var tlsVersions = []struct {
912 name string
913 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400914 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500915 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700916}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500917 {"SSL3", VersionSSL30, "-no-ssl3", false},
918 {"TLS1", VersionTLS10, "-no-tls1", true},
919 {"TLS11", VersionTLS11, "-no-tls11", false},
920 {"TLS12", VersionTLS12, "-no-tls12", true},
Nick Harper1fd39d82016-06-14 18:14:35 -0700921 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
922 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700923}
924
925var testCipherSuites = []struct {
926 name string
927 id uint16
928}{
929 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400930 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700931 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400932 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400933 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700934 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400935 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400936 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
937 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400938 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400939 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
940 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400941 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700942 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
943 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400944 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
945 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700946 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400947 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500948 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500949 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700950 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700951 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700952 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400953 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400954 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700955 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400956 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500957 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500958 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700959 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700960 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
961 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
962 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
963 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400964 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
965 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700966 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
967 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500968 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400969 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
970 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400971 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400973 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700974 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700975}
976
David Benjamin8b8c0062014-11-23 02:47:52 -0500977func hasComponent(suiteName, component string) bool {
978 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
979}
980
David Benjaminf7768e42014-08-31 02:06:47 -0400981func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500982 return hasComponent(suiteName, "GCM") ||
983 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400984 hasComponent(suiteName, "SHA384") ||
985 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500986}
987
Nick Harper1fd39d82016-06-14 18:14:35 -0700988func isTLS13Suite(suiteName string) bool {
989 return (hasComponent(suiteName, "GCM") || hasComponent(suiteName, "POLY1305")) && hasComponent(suiteName, "ECDHE") && !hasComponent(suiteName, "OLD")
990}
991
David Benjamin8b8c0062014-11-23 02:47:52 -0500992func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700993 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400994}
995
Adam Langleya7997f12015-05-14 17:38:50 -0700996func bigFromHex(hex string) *big.Int {
997 ret, ok := new(big.Int).SetString(hex, 16)
998 if !ok {
999 panic("failed to parse hex number 0x" + hex)
1000 }
1001 return ret
1002}
1003
Adam Langley7c803a62015-06-15 15:35:05 -07001004func addBasicTests() {
1005 basicTests := []testCase{
1006 {
1007 name: "BadRSASignature",
1008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001009 // TODO(davidben): Add a TLS 1.3 version of this.
1010 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001011 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1012 Bugs: ProtocolBugs{
1013 InvalidSKXSignature: true,
1014 },
1015 },
1016 shouldFail: true,
1017 expectedError: ":BAD_SIGNATURE:",
1018 },
1019 {
1020 name: "BadECDSASignature",
1021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001022 // TODO(davidben): Add a TLS 1.3 version of this.
1023 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001024 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1025 Bugs: ProtocolBugs{
1026 InvalidSKXSignature: true,
1027 },
1028 Certificates: []Certificate{getECDSACertificate()},
1029 },
1030 shouldFail: true,
1031 expectedError: ":BAD_SIGNATURE:",
1032 },
1033 {
David Benjamin6de0e532015-07-28 22:43:19 -04001034 testType: serverTest,
1035 name: "BadRSASignature-ClientAuth",
1036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001037 // TODO(davidben): Add a TLS 1.3 version of this.
1038 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001039 Bugs: ProtocolBugs{
1040 InvalidCertVerifySignature: true,
1041 },
1042 Certificates: []Certificate{getRSACertificate()},
1043 },
1044 shouldFail: true,
1045 expectedError: ":BAD_SIGNATURE:",
1046 flags: []string{"-require-any-client-certificate"},
1047 },
1048 {
1049 testType: serverTest,
1050 name: "BadECDSASignature-ClientAuth",
1051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001052 // TODO(davidben): Add a TLS 1.3 version of this.
1053 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001054 Bugs: ProtocolBugs{
1055 InvalidCertVerifySignature: true,
1056 },
1057 Certificates: []Certificate{getECDSACertificate()},
1058 },
1059 shouldFail: true,
1060 expectedError: ":BAD_SIGNATURE:",
1061 flags: []string{"-require-any-client-certificate"},
1062 },
1063 {
Adam Langley7c803a62015-06-15 15:35:05 -07001064 name: "NoFallbackSCSV",
1065 config: Config{
1066 Bugs: ProtocolBugs{
1067 FailIfNotFallbackSCSV: true,
1068 },
1069 },
1070 shouldFail: true,
1071 expectedLocalError: "no fallback SCSV found",
1072 },
1073 {
1074 name: "SendFallbackSCSV",
1075 config: Config{
1076 Bugs: ProtocolBugs{
1077 FailIfNotFallbackSCSV: true,
1078 },
1079 },
1080 flags: []string{"-fallback-scsv"},
1081 },
1082 {
1083 name: "ClientCertificateTypes",
1084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001085 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001086 ClientAuth: RequestClientCert,
1087 ClientCertificateTypes: []byte{
1088 CertTypeDSSSign,
1089 CertTypeRSASign,
1090 CertTypeECDSASign,
1091 },
1092 },
1093 flags: []string{
1094 "-expect-certificate-types",
1095 base64.StdEncoding.EncodeToString([]byte{
1096 CertTypeDSSSign,
1097 CertTypeRSASign,
1098 CertTypeECDSASign,
1099 }),
1100 },
1101 },
1102 {
Adam Langley7c803a62015-06-15 15:35:05 -07001103 name: "UnauthenticatedECDH",
1104 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001105 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1107 Bugs: ProtocolBugs{
1108 UnauthenticatedECDH: true,
1109 },
1110 },
1111 shouldFail: true,
1112 expectedError: ":UNEXPECTED_MESSAGE:",
1113 },
1114 {
1115 name: "SkipCertificateStatus",
1116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001117 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001118 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1119 Bugs: ProtocolBugs{
1120 SkipCertificateStatus: true,
1121 },
1122 },
1123 flags: []string{
1124 "-enable-ocsp-stapling",
1125 },
1126 },
1127 {
1128 name: "SkipServerKeyExchange",
1129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001130 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001131 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1132 Bugs: ProtocolBugs{
1133 SkipServerKeyExchange: true,
1134 },
1135 },
1136 shouldFail: true,
1137 expectedError: ":UNEXPECTED_MESSAGE:",
1138 },
1139 {
Adam Langley7c803a62015-06-15 15:35:05 -07001140 testType: serverTest,
1141 name: "Alert",
1142 config: Config{
1143 Bugs: ProtocolBugs{
1144 SendSpuriousAlert: alertRecordOverflow,
1145 },
1146 },
1147 shouldFail: true,
1148 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1149 },
1150 {
1151 protocol: dtls,
1152 testType: serverTest,
1153 name: "Alert-DTLS",
1154 config: Config{
1155 Bugs: ProtocolBugs{
1156 SendSpuriousAlert: alertRecordOverflow,
1157 },
1158 },
1159 shouldFail: true,
1160 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1161 },
1162 {
1163 testType: serverTest,
1164 name: "FragmentAlert",
1165 config: Config{
1166 Bugs: ProtocolBugs{
1167 FragmentAlert: true,
1168 SendSpuriousAlert: alertRecordOverflow,
1169 },
1170 },
1171 shouldFail: true,
1172 expectedError: ":BAD_ALERT:",
1173 },
1174 {
1175 protocol: dtls,
1176 testType: serverTest,
1177 name: "FragmentAlert-DTLS",
1178 config: Config{
1179 Bugs: ProtocolBugs{
1180 FragmentAlert: true,
1181 SendSpuriousAlert: alertRecordOverflow,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedError: ":BAD_ALERT:",
1186 },
1187 {
1188 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001189 name: "DoubleAlert",
1190 config: Config{
1191 Bugs: ProtocolBugs{
1192 DoubleAlert: true,
1193 SendSpuriousAlert: alertRecordOverflow,
1194 },
1195 },
1196 shouldFail: true,
1197 expectedError: ":BAD_ALERT:",
1198 },
1199 {
1200 protocol: dtls,
1201 testType: serverTest,
1202 name: "DoubleAlert-DTLS",
1203 config: Config{
1204 Bugs: ProtocolBugs{
1205 DoubleAlert: true,
1206 SendSpuriousAlert: alertRecordOverflow,
1207 },
1208 },
1209 shouldFail: true,
1210 expectedError: ":BAD_ALERT:",
1211 },
1212 {
Adam Langley7c803a62015-06-15 15:35:05 -07001213 name: "SkipNewSessionTicket",
1214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001215 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001216 Bugs: ProtocolBugs{
1217 SkipNewSessionTicket: true,
1218 },
1219 },
1220 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001221 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001222 },
1223 {
1224 testType: serverTest,
1225 name: "FallbackSCSV",
1226 config: Config{
1227 MaxVersion: VersionTLS11,
1228 Bugs: ProtocolBugs{
1229 SendFallbackSCSV: true,
1230 },
1231 },
1232 shouldFail: true,
1233 expectedError: ":INAPPROPRIATE_FALLBACK:",
1234 },
1235 {
1236 testType: serverTest,
1237 name: "FallbackSCSV-VersionMatch",
1238 config: Config{
1239 Bugs: ProtocolBugs{
1240 SendFallbackSCSV: true,
1241 },
1242 },
1243 },
1244 {
1245 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001246 name: "FallbackSCSV-VersionMatch-TLS12",
1247 config: Config{
1248 MaxVersion: VersionTLS12,
1249 Bugs: ProtocolBugs{
1250 SendFallbackSCSV: true,
1251 },
1252 },
1253 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1254 },
1255 {
1256 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001257 name: "FragmentedClientVersion",
1258 config: Config{
1259 Bugs: ProtocolBugs{
1260 MaxHandshakeRecordLength: 1,
1261 FragmentClientVersion: true,
1262 },
1263 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001264 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001265 },
1266 {
Adam Langley7c803a62015-06-15 15:35:05 -07001267 testType: serverTest,
1268 name: "HttpGET",
1269 sendPrefix: "GET / HTTP/1.0\n",
1270 shouldFail: true,
1271 expectedError: ":HTTP_REQUEST:",
1272 },
1273 {
1274 testType: serverTest,
1275 name: "HttpPOST",
1276 sendPrefix: "POST / HTTP/1.0\n",
1277 shouldFail: true,
1278 expectedError: ":HTTP_REQUEST:",
1279 },
1280 {
1281 testType: serverTest,
1282 name: "HttpHEAD",
1283 sendPrefix: "HEAD / HTTP/1.0\n",
1284 shouldFail: true,
1285 expectedError: ":HTTP_REQUEST:",
1286 },
1287 {
1288 testType: serverTest,
1289 name: "HttpPUT",
1290 sendPrefix: "PUT / HTTP/1.0\n",
1291 shouldFail: true,
1292 expectedError: ":HTTP_REQUEST:",
1293 },
1294 {
1295 testType: serverTest,
1296 name: "HttpCONNECT",
1297 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1298 shouldFail: true,
1299 expectedError: ":HTTPS_PROXY_REQUEST:",
1300 },
1301 {
1302 testType: serverTest,
1303 name: "Garbage",
1304 sendPrefix: "blah",
1305 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001306 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001307 },
1308 {
Adam Langley7c803a62015-06-15 15:35:05 -07001309 name: "RSAEphemeralKey",
1310 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001311 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001312 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1313 Bugs: ProtocolBugs{
1314 RSAEphemeralKey: true,
1315 },
1316 },
1317 shouldFail: true,
1318 expectedError: ":UNEXPECTED_MESSAGE:",
1319 },
1320 {
1321 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001322 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001323 shouldFail: true,
1324 expectedError: ":WRONG_SSL_VERSION:",
1325 },
1326 {
1327 protocol: dtls,
1328 name: "DisableEverything-DTLS",
1329 flags: []string{"-no-tls12", "-no-tls1"},
1330 shouldFail: true,
1331 expectedError: ":WRONG_SSL_VERSION:",
1332 },
1333 {
Adam Langley7c803a62015-06-15 15:35:05 -07001334 protocol: dtls,
1335 testType: serverTest,
1336 name: "MTU",
1337 config: Config{
1338 Bugs: ProtocolBugs{
1339 MaxPacketLength: 256,
1340 },
1341 },
1342 flags: []string{"-mtu", "256"},
1343 },
1344 {
1345 protocol: dtls,
1346 testType: serverTest,
1347 name: "MTUExceeded",
1348 config: Config{
1349 Bugs: ProtocolBugs{
1350 MaxPacketLength: 255,
1351 },
1352 },
1353 flags: []string{"-mtu", "256"},
1354 shouldFail: true,
1355 expectedLocalError: "dtls: exceeded maximum packet length",
1356 },
1357 {
1358 name: "CertMismatchRSA",
1359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001360 // TODO(davidben): Add a TLS 1.3 version of this test.
1361 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001362 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1363 Certificates: []Certificate{getECDSACertificate()},
1364 Bugs: ProtocolBugs{
1365 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1370 },
1371 {
1372 name: "CertMismatchECDSA",
1373 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001374 // TODO(davidben): Add a TLS 1.3 version of this test.
1375 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1377 Certificates: []Certificate{getRSACertificate()},
1378 Bugs: ProtocolBugs{
1379 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1380 },
1381 },
1382 shouldFail: true,
1383 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1384 },
1385 {
1386 name: "EmptyCertificateList",
1387 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001388 // TODO(davidben): Add a TLS 1.3 version of this test.
1389 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001390 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1391 Bugs: ProtocolBugs{
1392 EmptyCertificateList: true,
1393 },
1394 },
1395 shouldFail: true,
1396 expectedError: ":DECODE_ERROR:",
1397 },
1398 {
1399 name: "TLSFatalBadPackets",
1400 damageFirstWrite: true,
1401 shouldFail: true,
1402 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1403 },
1404 {
1405 protocol: dtls,
1406 name: "DTLSIgnoreBadPackets",
1407 damageFirstWrite: true,
1408 },
1409 {
1410 protocol: dtls,
1411 name: "DTLSIgnoreBadPackets-Async",
1412 damageFirstWrite: true,
1413 flags: []string{"-async"},
1414 },
1415 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001416 name: "AppDataBeforeHandshake",
1417 config: Config{
1418 Bugs: ProtocolBugs{
1419 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":UNEXPECTED_RECORD:",
1424 },
1425 {
1426 name: "AppDataBeforeHandshake-Empty",
1427 config: Config{
1428 Bugs: ProtocolBugs{
1429 AppDataBeforeHandshake: []byte{},
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":UNEXPECTED_RECORD:",
1434 },
1435 {
1436 protocol: dtls,
1437 name: "AppDataBeforeHandshake-DTLS",
1438 config: Config{
1439 Bugs: ProtocolBugs{
1440 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1441 },
1442 },
1443 shouldFail: true,
1444 expectedError: ":UNEXPECTED_RECORD:",
1445 },
1446 {
1447 protocol: dtls,
1448 name: "AppDataBeforeHandshake-DTLS-Empty",
1449 config: Config{
1450 Bugs: ProtocolBugs{
1451 AppDataBeforeHandshake: []byte{},
1452 },
1453 },
1454 shouldFail: true,
1455 expectedError: ":UNEXPECTED_RECORD:",
1456 },
1457 {
Adam Langley7c803a62015-06-15 15:35:05 -07001458 name: "AppDataAfterChangeCipherSpec",
1459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001460 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001461 Bugs: ProtocolBugs{
1462 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1463 },
1464 },
1465 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001466 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001467 },
1468 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001469 name: "AppDataAfterChangeCipherSpec-Empty",
1470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001471 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001472 Bugs: ProtocolBugs{
1473 AppDataAfterChangeCipherSpec: []byte{},
1474 },
1475 },
1476 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001477 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001478 },
1479 {
Adam Langley7c803a62015-06-15 15:35:05 -07001480 protocol: dtls,
1481 name: "AppDataAfterChangeCipherSpec-DTLS",
1482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001483 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001484 Bugs: ProtocolBugs{
1485 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1486 },
1487 },
1488 // BoringSSL's DTLS implementation will drop the out-of-order
1489 // application data.
1490 },
1491 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001492 protocol: dtls,
1493 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1494 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001495 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001496 Bugs: ProtocolBugs{
1497 AppDataAfterChangeCipherSpec: []byte{},
1498 },
1499 },
1500 // BoringSSL's DTLS implementation will drop the out-of-order
1501 // application data.
1502 },
1503 {
Adam Langley7c803a62015-06-15 15:35:05 -07001504 name: "AlertAfterChangeCipherSpec",
1505 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001506 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001507 Bugs: ProtocolBugs{
1508 AlertAfterChangeCipherSpec: alertRecordOverflow,
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "AlertAfterChangeCipherSpec-DTLS",
1517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001518 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001519 Bugs: ProtocolBugs{
1520 AlertAfterChangeCipherSpec: alertRecordOverflow,
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1525 },
1526 {
1527 protocol: dtls,
1528 name: "ReorderHandshakeFragments-Small-DTLS",
1529 config: Config{
1530 Bugs: ProtocolBugs{
1531 ReorderHandshakeFragments: true,
1532 // Small enough that every handshake message is
1533 // fragmented.
1534 MaxHandshakeRecordLength: 2,
1535 },
1536 },
1537 },
1538 {
1539 protocol: dtls,
1540 name: "ReorderHandshakeFragments-Large-DTLS",
1541 config: Config{
1542 Bugs: ProtocolBugs{
1543 ReorderHandshakeFragments: true,
1544 // Large enough that no handshake message is
1545 // fragmented.
1546 MaxHandshakeRecordLength: 2048,
1547 },
1548 },
1549 },
1550 {
1551 protocol: dtls,
1552 name: "MixCompleteMessageWithFragments-DTLS",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 ReorderHandshakeFragments: true,
1556 MixCompleteMessageWithFragments: true,
1557 MaxHandshakeRecordLength: 2,
1558 },
1559 },
1560 },
1561 {
1562 name: "SendInvalidRecordType",
1563 config: Config{
1564 Bugs: ProtocolBugs{
1565 SendInvalidRecordType: true,
1566 },
1567 },
1568 shouldFail: true,
1569 expectedError: ":UNEXPECTED_RECORD:",
1570 },
1571 {
1572 protocol: dtls,
1573 name: "SendInvalidRecordType-DTLS",
1574 config: Config{
1575 Bugs: ProtocolBugs{
1576 SendInvalidRecordType: true,
1577 },
1578 },
1579 shouldFail: true,
1580 expectedError: ":UNEXPECTED_RECORD:",
1581 },
1582 {
1583 name: "FalseStart-SkipServerSecondLeg",
1584 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001585 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1587 NextProtos: []string{"foo"},
1588 Bugs: ProtocolBugs{
1589 SkipNewSessionTicket: true,
1590 SkipChangeCipherSpec: true,
1591 SkipFinished: true,
1592 ExpectFalseStart: true,
1593 },
1594 },
1595 flags: []string{
1596 "-false-start",
1597 "-handshake-never-done",
1598 "-advertise-alpn", "\x03foo",
1599 },
1600 shimWritesFirst: true,
1601 shouldFail: true,
1602 expectedError: ":UNEXPECTED_RECORD:",
1603 },
1604 {
1605 name: "FalseStart-SkipServerSecondLeg-Implicit",
1606 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001607 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001608 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1609 NextProtos: []string{"foo"},
1610 Bugs: ProtocolBugs{
1611 SkipNewSessionTicket: true,
1612 SkipChangeCipherSpec: true,
1613 SkipFinished: true,
1614 },
1615 },
1616 flags: []string{
1617 "-implicit-handshake",
1618 "-false-start",
1619 "-handshake-never-done",
1620 "-advertise-alpn", "\x03foo",
1621 },
1622 shouldFail: true,
1623 expectedError: ":UNEXPECTED_RECORD:",
1624 },
1625 {
1626 testType: serverTest,
1627 name: "FailEarlyCallback",
1628 flags: []string{"-fail-early-callback"},
1629 shouldFail: true,
1630 expectedError: ":CONNECTION_REJECTED:",
1631 expectedLocalError: "remote error: access denied",
1632 },
1633 {
1634 name: "WrongMessageType",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 WrongCertificateMessageType: true,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":UNEXPECTED_MESSAGE:",
1642 expectedLocalError: "remote error: unexpected message",
1643 },
1644 {
1645 protocol: dtls,
1646 name: "WrongMessageType-DTLS",
1647 config: Config{
1648 Bugs: ProtocolBugs{
1649 WrongCertificateMessageType: true,
1650 },
1651 },
1652 shouldFail: true,
1653 expectedError: ":UNEXPECTED_MESSAGE:",
1654 expectedLocalError: "remote error: unexpected message",
1655 },
1656 {
1657 protocol: dtls,
1658 name: "FragmentMessageTypeMismatch-DTLS",
1659 config: Config{
1660 Bugs: ProtocolBugs{
1661 MaxHandshakeRecordLength: 2,
1662 FragmentMessageTypeMismatch: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":FRAGMENT_MISMATCH:",
1667 },
1668 {
1669 protocol: dtls,
1670 name: "FragmentMessageLengthMismatch-DTLS",
1671 config: Config{
1672 Bugs: ProtocolBugs{
1673 MaxHandshakeRecordLength: 2,
1674 FragmentMessageLengthMismatch: true,
1675 },
1676 },
1677 shouldFail: true,
1678 expectedError: ":FRAGMENT_MISMATCH:",
1679 },
1680 {
1681 protocol: dtls,
1682 name: "SplitFragments-Header-DTLS",
1683 config: Config{
1684 Bugs: ProtocolBugs{
1685 SplitFragments: 2,
1686 },
1687 },
1688 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001689 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001690 },
1691 {
1692 protocol: dtls,
1693 name: "SplitFragments-Boundary-DTLS",
1694 config: Config{
1695 Bugs: ProtocolBugs{
1696 SplitFragments: dtlsRecordHeaderLen,
1697 },
1698 },
1699 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001700 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001701 },
1702 {
1703 protocol: dtls,
1704 name: "SplitFragments-Body-DTLS",
1705 config: Config{
1706 Bugs: ProtocolBugs{
1707 SplitFragments: dtlsRecordHeaderLen + 1,
1708 },
1709 },
1710 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001711 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001712 },
1713 {
1714 protocol: dtls,
1715 name: "SendEmptyFragments-DTLS",
1716 config: Config{
1717 Bugs: ProtocolBugs{
1718 SendEmptyFragments: true,
1719 },
1720 },
1721 },
1722 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001723 name: "BadFinished-Client",
1724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001725 // TODO(davidben): Add a TLS 1.3 version of this.
1726 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001727 Bugs: ProtocolBugs{
1728 BadFinished: true,
1729 },
1730 },
1731 shouldFail: true,
1732 expectedError: ":DIGEST_CHECK_FAILED:",
1733 },
1734 {
1735 testType: serverTest,
1736 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001737 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001738 // TODO(davidben): Add a TLS 1.3 version of this.
1739 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001740 Bugs: ProtocolBugs{
1741 BadFinished: true,
1742 },
1743 },
1744 shouldFail: true,
1745 expectedError: ":DIGEST_CHECK_FAILED:",
1746 },
1747 {
1748 name: "FalseStart-BadFinished",
1749 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001750 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1752 NextProtos: []string{"foo"},
1753 Bugs: ProtocolBugs{
1754 BadFinished: true,
1755 ExpectFalseStart: true,
1756 },
1757 },
1758 flags: []string{
1759 "-false-start",
1760 "-handshake-never-done",
1761 "-advertise-alpn", "\x03foo",
1762 },
1763 shimWritesFirst: true,
1764 shouldFail: true,
1765 expectedError: ":DIGEST_CHECK_FAILED:",
1766 },
1767 {
1768 name: "NoFalseStart-NoALPN",
1769 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001770 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001771 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1772 Bugs: ProtocolBugs{
1773 ExpectFalseStart: true,
1774 AlertBeforeFalseStartTest: alertAccessDenied,
1775 },
1776 },
1777 flags: []string{
1778 "-false-start",
1779 },
1780 shimWritesFirst: true,
1781 shouldFail: true,
1782 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1783 expectedLocalError: "tls: peer did not false start: EOF",
1784 },
1785 {
1786 name: "NoFalseStart-NoAEAD",
1787 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001788 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001789 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1790 NextProtos: []string{"foo"},
1791 Bugs: ProtocolBugs{
1792 ExpectFalseStart: true,
1793 AlertBeforeFalseStartTest: alertAccessDenied,
1794 },
1795 },
1796 flags: []string{
1797 "-false-start",
1798 "-advertise-alpn", "\x03foo",
1799 },
1800 shimWritesFirst: true,
1801 shouldFail: true,
1802 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1803 expectedLocalError: "tls: peer did not false start: EOF",
1804 },
1805 {
1806 name: "NoFalseStart-RSA",
1807 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001808 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001809 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1810 NextProtos: []string{"foo"},
1811 Bugs: ProtocolBugs{
1812 ExpectFalseStart: true,
1813 AlertBeforeFalseStartTest: alertAccessDenied,
1814 },
1815 },
1816 flags: []string{
1817 "-false-start",
1818 "-advertise-alpn", "\x03foo",
1819 },
1820 shimWritesFirst: true,
1821 shouldFail: true,
1822 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1823 expectedLocalError: "tls: peer did not false start: EOF",
1824 },
1825 {
1826 name: "NoFalseStart-DHE_RSA",
1827 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001828 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001829 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1830 NextProtos: []string{"foo"},
1831 Bugs: ProtocolBugs{
1832 ExpectFalseStart: true,
1833 AlertBeforeFalseStartTest: alertAccessDenied,
1834 },
1835 },
1836 flags: []string{
1837 "-false-start",
1838 "-advertise-alpn", "\x03foo",
1839 },
1840 shimWritesFirst: true,
1841 shouldFail: true,
1842 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1843 expectedLocalError: "tls: peer did not false start: EOF",
1844 },
1845 {
Adam Langley7c803a62015-06-15 15:35:05 -07001846 protocol: dtls,
1847 name: "SendSplitAlert-Sync",
1848 config: Config{
1849 Bugs: ProtocolBugs{
1850 SendSplitAlert: true,
1851 },
1852 },
1853 },
1854 {
1855 protocol: dtls,
1856 name: "SendSplitAlert-Async",
1857 config: Config{
1858 Bugs: ProtocolBugs{
1859 SendSplitAlert: true,
1860 },
1861 },
1862 flags: []string{"-async"},
1863 },
1864 {
1865 protocol: dtls,
1866 name: "PackDTLSHandshake",
1867 config: Config{
1868 Bugs: ProtocolBugs{
1869 MaxHandshakeRecordLength: 2,
1870 PackHandshakeFragments: 20,
1871 PackHandshakeRecords: 200,
1872 },
1873 },
1874 },
1875 {
Adam Langley7c803a62015-06-15 15:35:05 -07001876 name: "SendEmptyRecords-Pass",
1877 sendEmptyRecords: 32,
1878 },
1879 {
1880 name: "SendEmptyRecords",
1881 sendEmptyRecords: 33,
1882 shouldFail: true,
1883 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1884 },
1885 {
1886 name: "SendEmptyRecords-Async",
1887 sendEmptyRecords: 33,
1888 flags: []string{"-async"},
1889 shouldFail: true,
1890 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1891 },
1892 {
1893 name: "SendWarningAlerts-Pass",
1894 sendWarningAlerts: 4,
1895 },
1896 {
1897 protocol: dtls,
1898 name: "SendWarningAlerts-DTLS-Pass",
1899 sendWarningAlerts: 4,
1900 },
1901 {
1902 name: "SendWarningAlerts",
1903 sendWarningAlerts: 5,
1904 shouldFail: true,
1905 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1906 },
1907 {
1908 name: "SendWarningAlerts-Async",
1909 sendWarningAlerts: 5,
1910 flags: []string{"-async"},
1911 shouldFail: true,
1912 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1913 },
David Benjaminba4594a2015-06-18 18:36:15 -04001914 {
1915 name: "EmptySessionID",
1916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001917 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001918 SessionTicketsDisabled: true,
1919 },
1920 noSessionCache: true,
1921 flags: []string{"-expect-no-session"},
1922 },
David Benjamin30789da2015-08-29 22:56:45 -04001923 {
1924 name: "Unclean-Shutdown",
1925 config: Config{
1926 Bugs: ProtocolBugs{
1927 NoCloseNotify: true,
1928 ExpectCloseNotify: true,
1929 },
1930 },
1931 shimShutsDown: true,
1932 flags: []string{"-check-close-notify"},
1933 shouldFail: true,
1934 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1935 },
1936 {
1937 name: "Unclean-Shutdown-Ignored",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 NoCloseNotify: true,
1941 },
1942 },
1943 shimShutsDown: true,
1944 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001945 {
David Benjaminfa214e42016-05-10 17:03:10 -04001946 name: "Unclean-Shutdown-Alert",
1947 config: Config{
1948 Bugs: ProtocolBugs{
1949 SendAlertOnShutdown: alertDecompressionFailure,
1950 ExpectCloseNotify: true,
1951 },
1952 },
1953 shimShutsDown: true,
1954 flags: []string{"-check-close-notify"},
1955 shouldFail: true,
1956 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
1957 },
1958 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04001959 name: "LargePlaintext",
1960 config: Config{
1961 Bugs: ProtocolBugs{
1962 SendLargeRecords: true,
1963 },
1964 },
1965 messageLen: maxPlaintext + 1,
1966 shouldFail: true,
1967 expectedError: ":DATA_LENGTH_TOO_LONG:",
1968 },
1969 {
1970 protocol: dtls,
1971 name: "LargePlaintext-DTLS",
1972 config: Config{
1973 Bugs: ProtocolBugs{
1974 SendLargeRecords: true,
1975 },
1976 },
1977 messageLen: maxPlaintext + 1,
1978 shouldFail: true,
1979 expectedError: ":DATA_LENGTH_TOO_LONG:",
1980 },
1981 {
1982 name: "LargeCiphertext",
1983 config: Config{
1984 Bugs: ProtocolBugs{
1985 SendLargeRecords: true,
1986 },
1987 },
1988 messageLen: maxPlaintext * 2,
1989 shouldFail: true,
1990 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1991 },
1992 {
1993 protocol: dtls,
1994 name: "LargeCiphertext-DTLS",
1995 config: Config{
1996 Bugs: ProtocolBugs{
1997 SendLargeRecords: true,
1998 },
1999 },
2000 messageLen: maxPlaintext * 2,
2001 // Unlike the other four cases, DTLS drops records which
2002 // are invalid before authentication, so the connection
2003 // does not fail.
2004 expectMessageDropped: true,
2005 },
David Benjamindd6fed92015-10-23 17:41:12 -04002006 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002007 // In TLS 1.2 and below, empty NewSessionTicket messages
2008 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002009 name: "SendEmptySessionTicket",
2010 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002011 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002012 Bugs: ProtocolBugs{
2013 SendEmptySessionTicket: true,
2014 FailIfSessionOffered: true,
2015 },
2016 },
2017 flags: []string{"-expect-no-session"},
2018 resumeSession: true,
2019 expectResumeRejected: true,
2020 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002021 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002022 name: "BadHelloRequest-1",
2023 renegotiate: 1,
2024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002025 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002026 Bugs: ProtocolBugs{
2027 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2028 },
2029 },
2030 flags: []string{
2031 "-renegotiate-freely",
2032 "-expect-total-renegotiations", "1",
2033 },
2034 shouldFail: true,
2035 expectedError: ":BAD_HELLO_REQUEST:",
2036 },
2037 {
2038 name: "BadHelloRequest-2",
2039 renegotiate: 1,
2040 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002041 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002042 Bugs: ProtocolBugs{
2043 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2044 },
2045 },
2046 flags: []string{
2047 "-renegotiate-freely",
2048 "-expect-total-renegotiations", "1",
2049 },
2050 shouldFail: true,
2051 expectedError: ":BAD_HELLO_REQUEST:",
2052 },
David Benjaminef1b0092015-11-21 14:05:44 -05002053 {
2054 testType: serverTest,
2055 name: "SupportTicketsWithSessionID",
2056 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002057 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002058 SessionTicketsDisabled: true,
2059 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002060 resumeConfig: &Config{
2061 MaxVersion: VersionTLS12,
2062 },
David Benjaminef1b0092015-11-21 14:05:44 -05002063 resumeSession: true,
2064 },
Adam Langley7c803a62015-06-15 15:35:05 -07002065 }
Adam Langley7c803a62015-06-15 15:35:05 -07002066 testCases = append(testCases, basicTests...)
2067}
2068
Adam Langley95c29f32014-06-20 12:00:00 -07002069func addCipherSuiteTests() {
2070 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002071 const psk = "12345"
2072 const pskIdentity = "luggage combo"
2073
Adam Langley95c29f32014-06-20 12:00:00 -07002074 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002075 var certFile string
2076 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002077 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002078 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002079 certFile = ecdsaCertificateFile
2080 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002081 } else {
2082 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002083 certFile = rsaCertificateFile
2084 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002085 }
2086
David Benjamin48cae082014-10-27 01:06:24 -04002087 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002088 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002089 flags = append(flags,
2090 "-psk", psk,
2091 "-psk-identity", pskIdentity)
2092 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002093 if hasComponent(suite.name, "NULL") {
2094 // NULL ciphers must be explicitly enabled.
2095 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2096 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002097 if hasComponent(suite.name, "CECPQ1") {
2098 // CECPQ1 ciphers must be explicitly enabled.
2099 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2100 }
David Benjamin48cae082014-10-27 01:06:24 -04002101
Adam Langley95c29f32014-06-20 12:00:00 -07002102 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002103 for _, protocol := range []protocol{tls, dtls} {
2104 var prefix string
2105 if protocol == dtls {
2106 if !ver.hasDTLS {
2107 continue
2108 }
2109 prefix = "D"
2110 }
Adam Langley95c29f32014-06-20 12:00:00 -07002111
David Benjamin0407e762016-06-17 16:41:18 -04002112 var shouldServerFail, shouldClientFail bool
2113 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2114 // BoringSSL clients accept ECDHE on SSLv3, but
2115 // a BoringSSL server will never select it
2116 // because the extension is missing.
2117 shouldServerFail = true
2118 }
2119 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2120 shouldClientFail = true
2121 shouldServerFail = true
2122 }
Nick Harper1fd39d82016-06-14 18:14:35 -07002123 if !isTLS13Suite(suite.name) && ver.version == VersionTLS13 {
2124 shouldClientFail = true
2125 shouldServerFail = true
2126 }
David Benjamin0407e762016-06-17 16:41:18 -04002127 if !isDTLSCipher(suite.name) && protocol == dtls {
2128 shouldClientFail = true
2129 shouldServerFail = true
2130 }
David Benjamin4298d772015-12-19 00:18:25 -05002131
David Benjamin0407e762016-06-17 16:41:18 -04002132 var expectedServerError, expectedClientError string
2133 if shouldServerFail {
2134 expectedServerError = ":NO_SHARED_CIPHER:"
2135 }
2136 if shouldClientFail {
2137 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2138 }
David Benjamin025b3d32014-07-01 19:53:04 -04002139
David Benjamin6fd297b2014-08-11 18:43:38 -04002140 testCases = append(testCases, testCase{
2141 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002142 protocol: protocol,
2143
2144 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002145 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002146 MinVersion: ver.version,
2147 MaxVersion: ver.version,
2148 CipherSuites: []uint16{suite.id},
2149 Certificates: []Certificate{cert},
2150 PreSharedKey: []byte(psk),
2151 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002152 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002153 EnableAllCiphers: shouldServerFail,
2154 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002155 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002156 },
2157 certFile: certFile,
2158 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002159 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002160 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002161 shouldFail: shouldServerFail,
2162 expectedError: expectedServerError,
2163 })
2164
2165 testCases = append(testCases, testCase{
2166 testType: clientTest,
2167 protocol: protocol,
2168 name: prefix + ver.name + "-" + suite.name + "-client",
2169 config: Config{
2170 MinVersion: ver.version,
2171 MaxVersion: ver.version,
2172 CipherSuites: []uint16{suite.id},
2173 Certificates: []Certificate{cert},
2174 PreSharedKey: []byte(psk),
2175 PreSharedKeyIdentity: pskIdentity,
2176 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002177 EnableAllCiphers: shouldClientFail,
2178 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002179 },
2180 },
2181 flags: flags,
2182 resumeSession: true,
2183 shouldFail: shouldClientFail,
2184 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002185 })
David Benjamin2c99d282015-09-01 10:23:00 -04002186
Nick Harper1fd39d82016-06-14 18:14:35 -07002187 if !shouldClientFail {
2188 // Ensure the maximum record size is accepted.
2189 testCases = append(testCases, testCase{
2190 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2191 config: Config{
2192 MinVersion: ver.version,
2193 MaxVersion: ver.version,
2194 CipherSuites: []uint16{suite.id},
2195 Certificates: []Certificate{cert},
2196 PreSharedKey: []byte(psk),
2197 PreSharedKeyIdentity: pskIdentity,
2198 },
2199 flags: flags,
2200 messageLen: maxPlaintext,
2201 })
2202 }
2203 }
David Benjamin2c99d282015-09-01 10:23:00 -04002204 }
Adam Langley95c29f32014-06-20 12:00:00 -07002205 }
Adam Langleya7997f12015-05-14 17:38:50 -07002206
2207 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002208 name: "NoSharedCipher",
2209 config: Config{
2210 // TODO(davidben): Add a TLS 1.3 version of this test.
2211 MaxVersion: VersionTLS12,
2212 CipherSuites: []uint16{},
2213 },
2214 shouldFail: true,
2215 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2216 })
2217
2218 testCases = append(testCases, testCase{
2219 name: "UnsupportedCipherSuite",
2220 config: Config{
2221 MaxVersion: VersionTLS12,
2222 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2223 Bugs: ProtocolBugs{
2224 IgnorePeerCipherPreferences: true,
2225 },
2226 },
2227 flags: []string{"-cipher", "DEFAULT:!RC4"},
2228 shouldFail: true,
2229 expectedError: ":WRONG_CIPHER_RETURNED:",
2230 })
2231
2232 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002233 name: "WeakDH",
2234 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002235 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002236 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2237 Bugs: ProtocolBugs{
2238 // This is a 1023-bit prime number, generated
2239 // with:
2240 // openssl gendh 1023 | openssl asn1parse -i
2241 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2242 },
2243 },
2244 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002245 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002246 })
Adam Langleycef75832015-09-03 14:51:12 -07002247
David Benjamincd24a392015-11-11 13:23:05 -08002248 testCases = append(testCases, testCase{
2249 name: "SillyDH",
2250 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002251 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002252 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2253 Bugs: ProtocolBugs{
2254 // This is a 4097-bit prime number, generated
2255 // with:
2256 // openssl gendh 4097 | openssl asn1parse -i
2257 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2258 },
2259 },
2260 shouldFail: true,
2261 expectedError: ":DH_P_TOO_LONG:",
2262 })
2263
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002264 // This test ensures that Diffie-Hellman public values are padded with
2265 // zeros so that they're the same length as the prime. This is to avoid
2266 // hitting a bug in yaSSL.
2267 testCases = append(testCases, testCase{
2268 testType: serverTest,
2269 name: "DHPublicValuePadded",
2270 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002271 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002272 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2273 Bugs: ProtocolBugs{
2274 RequireDHPublicValueLen: (1025 + 7) / 8,
2275 },
2276 },
2277 flags: []string{"-use-sparse-dh-prime"},
2278 })
David Benjamincd24a392015-11-11 13:23:05 -08002279
David Benjamin241ae832016-01-15 03:04:54 -05002280 // The server must be tolerant to bogus ciphers.
2281 const bogusCipher = 0x1234
2282 testCases = append(testCases, testCase{
2283 testType: serverTest,
2284 name: "UnknownCipher",
2285 config: Config{
2286 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2287 },
2288 })
2289
Adam Langleycef75832015-09-03 14:51:12 -07002290 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2291 // 1.1 specific cipher suite settings. A server is setup with the given
2292 // cipher lists and then a connection is made for each member of
2293 // expectations. The cipher suite that the server selects must match
2294 // the specified one.
2295 var versionSpecificCiphersTest = []struct {
2296 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2297 // expectations is a map from TLS version to cipher suite id.
2298 expectations map[uint16]uint16
2299 }{
2300 {
2301 // Test that the null case (where no version-specific ciphers are set)
2302 // works as expected.
2303 "RC4-SHA:AES128-SHA", // default ciphers
2304 "", // no ciphers specifically for TLS ≥ 1.0
2305 "", // no ciphers specifically for TLS ≥ 1.1
2306 map[uint16]uint16{
2307 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2308 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2309 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2310 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2311 },
2312 },
2313 {
2314 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2315 // cipher.
2316 "RC4-SHA:AES128-SHA", // default
2317 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2318 "", // no ciphers specifically for TLS ≥ 1.1
2319 map[uint16]uint16{
2320 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2321 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2322 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2323 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2324 },
2325 },
2326 {
2327 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2328 // cipher.
2329 "RC4-SHA:AES128-SHA", // default
2330 "", // no ciphers specifically for TLS ≥ 1.0
2331 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2332 map[uint16]uint16{
2333 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2334 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2335 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2336 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2337 },
2338 },
2339 {
2340 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2341 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2342 "RC4-SHA:AES128-SHA", // default
2343 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2344 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2345 map[uint16]uint16{
2346 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2347 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2348 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2349 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2350 },
2351 },
2352 }
2353
2354 for i, test := range versionSpecificCiphersTest {
2355 for version, expectedCipherSuite := range test.expectations {
2356 flags := []string{"-cipher", test.ciphersDefault}
2357 if len(test.ciphersTLS10) > 0 {
2358 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2359 }
2360 if len(test.ciphersTLS11) > 0 {
2361 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2362 }
2363
2364 testCases = append(testCases, testCase{
2365 testType: serverTest,
2366 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2367 config: Config{
2368 MaxVersion: version,
2369 MinVersion: version,
2370 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2371 },
2372 flags: flags,
2373 expectedCipher: expectedCipherSuite,
2374 })
2375 }
2376 }
Adam Langley95c29f32014-06-20 12:00:00 -07002377}
2378
2379func addBadECDSASignatureTests() {
2380 for badR := BadValue(1); badR < NumBadValues; badR++ {
2381 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002382 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002383 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2384 config: Config{
2385 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2386 Certificates: []Certificate{getECDSACertificate()},
2387 Bugs: ProtocolBugs{
2388 BadECDSAR: badR,
2389 BadECDSAS: badS,
2390 },
2391 },
2392 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002393 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002394 })
2395 }
2396 }
2397}
2398
Adam Langley80842bd2014-06-20 12:00:00 -07002399func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002400 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002401 name: "MaxCBCPadding",
2402 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002403 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002404 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2405 Bugs: ProtocolBugs{
2406 MaxPadding: true,
2407 },
2408 },
2409 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2410 })
David Benjamin025b3d32014-07-01 19:53:04 -04002411 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002412 name: "BadCBCPadding",
2413 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002414 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2416 Bugs: ProtocolBugs{
2417 PaddingFirstByteBad: true,
2418 },
2419 },
2420 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002421 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002422 })
2423 // OpenSSL previously had an issue where the first byte of padding in
2424 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002425 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002426 name: "BadCBCPadding255",
2427 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002428 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002429 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2430 Bugs: ProtocolBugs{
2431 MaxPadding: true,
2432 PaddingFirstByteBadIf255: true,
2433 },
2434 },
2435 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2436 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002437 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002438 })
2439}
2440
Kenny Root7fdeaf12014-08-05 15:23:37 -07002441func addCBCSplittingTests() {
2442 testCases = append(testCases, testCase{
2443 name: "CBCRecordSplitting",
2444 config: Config{
2445 MaxVersion: VersionTLS10,
2446 MinVersion: VersionTLS10,
2447 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2448 },
David Benjaminac8302a2015-09-01 17:18:15 -04002449 messageLen: -1, // read until EOF
2450 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002451 flags: []string{
2452 "-async",
2453 "-write-different-record-sizes",
2454 "-cbc-record-splitting",
2455 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002456 })
2457 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002458 name: "CBCRecordSplittingPartialWrite",
2459 config: Config{
2460 MaxVersion: VersionTLS10,
2461 MinVersion: VersionTLS10,
2462 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2463 },
2464 messageLen: -1, // read until EOF
2465 flags: []string{
2466 "-async",
2467 "-write-different-record-sizes",
2468 "-cbc-record-splitting",
2469 "-partial-write",
2470 },
2471 })
2472}
2473
David Benjamin636293b2014-07-08 17:59:18 -04002474func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002475 // Add a dummy cert pool to stress certificate authority parsing.
2476 // TODO(davidben): Add tests that those values parse out correctly.
2477 certPool := x509.NewCertPool()
2478 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2479 if err != nil {
2480 panic(err)
2481 }
2482 certPool.AddCert(cert)
2483
David Benjamin636293b2014-07-08 17:59:18 -04002484 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002485 testCases = append(testCases, testCase{
2486 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002487 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002488 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002489 MinVersion: ver.version,
2490 MaxVersion: ver.version,
2491 ClientAuth: RequireAnyClientCert,
2492 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002493 },
2494 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002495 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2496 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002497 },
2498 })
2499 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002500 testType: serverTest,
2501 name: ver.name + "-Server-ClientAuth-RSA",
2502 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002503 MinVersion: ver.version,
2504 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002505 Certificates: []Certificate{rsaCertificate},
2506 },
2507 flags: []string{"-require-any-client-certificate"},
2508 })
David Benjamine098ec22014-08-27 23:13:20 -04002509 if ver.version != VersionSSL30 {
2510 testCases = append(testCases, testCase{
2511 testType: serverTest,
2512 name: ver.name + "-Server-ClientAuth-ECDSA",
2513 config: Config{
2514 MinVersion: ver.version,
2515 MaxVersion: ver.version,
2516 Certificates: []Certificate{ecdsaCertificate},
2517 },
2518 flags: []string{"-require-any-client-certificate"},
2519 })
2520 testCases = append(testCases, testCase{
2521 testType: clientTest,
2522 name: ver.name + "-Client-ClientAuth-ECDSA",
2523 config: Config{
2524 MinVersion: ver.version,
2525 MaxVersion: ver.version,
2526 ClientAuth: RequireAnyClientCert,
2527 ClientCAs: certPool,
2528 },
2529 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002530 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2531 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002532 },
2533 })
2534 }
David Benjamin636293b2014-07-08 17:59:18 -04002535 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002536
Nick Harper1fd39d82016-06-14 18:14:35 -07002537 // TODO(davidben): These tests will need TLS 1.3 versions when the
2538 // handshake is separate.
2539
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002540 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002541 name: "NoClientCertificate",
2542 config: Config{
2543 MaxVersion: VersionTLS12,
2544 ClientAuth: RequireAnyClientCert,
2545 },
2546 shouldFail: true,
2547 expectedLocalError: "client didn't provide a certificate",
2548 })
2549
2550 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002551 testType: serverTest,
2552 name: "RequireAnyClientCertificate",
2553 config: Config{
2554 MaxVersion: VersionTLS12,
2555 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002556 flags: []string{"-require-any-client-certificate"},
2557 shouldFail: true,
2558 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2559 })
2560
2561 testCases = append(testCases, testCase{
2562 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002563 name: "RequireAnyClientCertificate-SSL3",
2564 config: Config{
2565 MaxVersion: VersionSSL30,
2566 },
2567 flags: []string{"-require-any-client-certificate"},
2568 shouldFail: true,
2569 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2570 })
2571
2572 testCases = append(testCases, testCase{
2573 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002574 name: "SkipClientCertificate",
2575 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002576 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002577 Bugs: ProtocolBugs{
2578 SkipClientCertificate: true,
2579 },
2580 },
2581 // Setting SSL_VERIFY_PEER allows anonymous clients.
2582 flags: []string{"-verify-peer"},
2583 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002584 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002585 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002586
2587 // Client auth is only legal in certificate-based ciphers.
2588 testCases = append(testCases, testCase{
2589 testType: clientTest,
2590 name: "ClientAuth-PSK",
2591 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002592 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002593 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2594 PreSharedKey: []byte("secret"),
2595 ClientAuth: RequireAnyClientCert,
2596 },
2597 flags: []string{
2598 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2599 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2600 "-psk", "secret",
2601 },
2602 shouldFail: true,
2603 expectedError: ":UNEXPECTED_MESSAGE:",
2604 })
2605 testCases = append(testCases, testCase{
2606 testType: clientTest,
2607 name: "ClientAuth-ECDHE_PSK",
2608 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002609 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002610 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2611 PreSharedKey: []byte("secret"),
2612 ClientAuth: RequireAnyClientCert,
2613 },
2614 flags: []string{
2615 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2616 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2617 "-psk", "secret",
2618 },
2619 shouldFail: true,
2620 expectedError: ":UNEXPECTED_MESSAGE:",
2621 })
David Benjamin636293b2014-07-08 17:59:18 -04002622}
2623
Adam Langley75712922014-10-10 16:23:43 -07002624func addExtendedMasterSecretTests() {
2625 const expectEMSFlag = "-expect-extended-master-secret"
2626
2627 for _, with := range []bool{false, true} {
2628 prefix := "No"
2629 var flags []string
2630 if with {
2631 prefix = ""
2632 flags = []string{expectEMSFlag}
2633 }
2634
2635 for _, isClient := range []bool{false, true} {
2636 suffix := "-Server"
2637 testType := serverTest
2638 if isClient {
2639 suffix = "-Client"
2640 testType = clientTest
2641 }
2642
David Benjamin4c3ddf72016-06-29 18:13:53 -04002643 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2644 // test that the extension is irrelevant, but the API
2645 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002646 for _, ver := range tlsVersions {
2647 test := testCase{
2648 testType: testType,
2649 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2650 config: Config{
2651 MinVersion: ver.version,
2652 MaxVersion: ver.version,
2653 Bugs: ProtocolBugs{
2654 NoExtendedMasterSecret: !with,
2655 RequireExtendedMasterSecret: with,
2656 },
2657 },
David Benjamin48cae082014-10-27 01:06:24 -04002658 flags: flags,
2659 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002660 }
2661 if test.shouldFail {
2662 test.expectedLocalError = "extended master secret required but not supported by peer"
2663 }
2664 testCases = append(testCases, test)
2665 }
2666 }
2667 }
2668
Adam Langleyba5934b2015-06-02 10:50:35 -07002669 for _, isClient := range []bool{false, true} {
2670 for _, supportedInFirstConnection := range []bool{false, true} {
2671 for _, supportedInResumeConnection := range []bool{false, true} {
2672 boolToWord := func(b bool) string {
2673 if b {
2674 return "Yes"
2675 }
2676 return "No"
2677 }
2678 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2679 if isClient {
2680 suffix += "Client"
2681 } else {
2682 suffix += "Server"
2683 }
2684
2685 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002686 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002687 Bugs: ProtocolBugs{
2688 RequireExtendedMasterSecret: true,
2689 },
2690 }
2691
2692 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002693 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002694 Bugs: ProtocolBugs{
2695 NoExtendedMasterSecret: true,
2696 },
2697 }
2698
2699 test := testCase{
2700 name: "ExtendedMasterSecret-" + suffix,
2701 resumeSession: true,
2702 }
2703
2704 if !isClient {
2705 test.testType = serverTest
2706 }
2707
2708 if supportedInFirstConnection {
2709 test.config = supportedConfig
2710 } else {
2711 test.config = noSupportConfig
2712 }
2713
2714 if supportedInResumeConnection {
2715 test.resumeConfig = &supportedConfig
2716 } else {
2717 test.resumeConfig = &noSupportConfig
2718 }
2719
2720 switch suffix {
2721 case "YesToYes-Client", "YesToYes-Server":
2722 // When a session is resumed, it should
2723 // still be aware that its master
2724 // secret was generated via EMS and
2725 // thus it's safe to use tls-unique.
2726 test.flags = []string{expectEMSFlag}
2727 case "NoToYes-Server":
2728 // If an original connection did not
2729 // contain EMS, but a resumption
2730 // handshake does, then a server should
2731 // not resume the session.
2732 test.expectResumeRejected = true
2733 case "YesToNo-Server":
2734 // Resuming an EMS session without the
2735 // EMS extension should cause the
2736 // server to abort the connection.
2737 test.shouldFail = true
2738 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2739 case "NoToYes-Client":
2740 // A client should abort a connection
2741 // where the server resumed a non-EMS
2742 // session but echoed the EMS
2743 // extension.
2744 test.shouldFail = true
2745 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2746 case "YesToNo-Client":
2747 // A client should abort a connection
2748 // where the server didn't echo EMS
2749 // when the session used it.
2750 test.shouldFail = true
2751 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2752 }
2753
2754 testCases = append(testCases, test)
2755 }
2756 }
2757 }
Adam Langley75712922014-10-10 16:23:43 -07002758}
2759
David Benjamin582ba042016-07-07 12:33:25 -07002760type stateMachineTestConfig struct {
2761 protocol protocol
2762 async bool
2763 splitHandshake, packHandshakeFlight bool
2764}
2765
David Benjamin43ec06f2014-08-05 02:28:57 -04002766// Adds tests that try to cover the range of the handshake state machine, under
2767// various conditions. Some of these are redundant with other tests, but they
2768// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002769func addAllStateMachineCoverageTests() {
2770 for _, async := range []bool{false, true} {
2771 for _, protocol := range []protocol{tls, dtls} {
2772 addStateMachineCoverageTests(stateMachineTestConfig{
2773 protocol: protocol,
2774 async: async,
2775 })
2776 addStateMachineCoverageTests(stateMachineTestConfig{
2777 protocol: protocol,
2778 async: async,
2779 splitHandshake: true,
2780 })
2781 if protocol == tls {
2782 addStateMachineCoverageTests(stateMachineTestConfig{
2783 protocol: protocol,
2784 async: async,
2785 packHandshakeFlight: true,
2786 })
2787 }
2788 }
2789 }
2790}
2791
2792func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002793 var tests []testCase
2794
2795 // Basic handshake, with resumption. Client and server,
2796 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002797 //
2798 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2799 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002800 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002801 name: "Basic-Client",
2802 config: Config{
2803 MaxVersion: VersionTLS12,
2804 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002805 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002806 // Ensure session tickets are used, not session IDs.
2807 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002808 })
2809 tests = append(tests, testCase{
2810 name: "Basic-Client-RenewTicket",
2811 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002812 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002813 Bugs: ProtocolBugs{
2814 RenewTicketOnResume: true,
2815 },
2816 },
David Benjaminba4594a2015-06-18 18:36:15 -04002817 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002818 resumeSession: true,
2819 })
2820 tests = append(tests, testCase{
2821 name: "Basic-Client-NoTicket",
2822 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002823 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002824 SessionTicketsDisabled: true,
2825 },
2826 resumeSession: true,
2827 })
2828 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002829 name: "Basic-Client-Implicit",
2830 config: Config{
2831 MaxVersion: VersionTLS12,
2832 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002833 flags: []string{"-implicit-handshake"},
2834 resumeSession: true,
2835 })
2836 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002837 testType: serverTest,
2838 name: "Basic-Server",
2839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002840 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002841 Bugs: ProtocolBugs{
2842 RequireSessionTickets: true,
2843 },
2844 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002845 resumeSession: true,
2846 })
2847 tests = append(tests, testCase{
2848 testType: serverTest,
2849 name: "Basic-Server-NoTickets",
2850 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002851 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002852 SessionTicketsDisabled: true,
2853 },
2854 resumeSession: true,
2855 })
2856 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002857 testType: serverTest,
2858 name: "Basic-Server-Implicit",
2859 config: Config{
2860 MaxVersion: VersionTLS12,
2861 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002862 flags: []string{"-implicit-handshake"},
2863 resumeSession: true,
2864 })
2865 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002866 testType: serverTest,
2867 name: "Basic-Server-EarlyCallback",
2868 config: Config{
2869 MaxVersion: VersionTLS12,
2870 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002871 flags: []string{"-use-early-callback"},
2872 resumeSession: true,
2873 })
2874
2875 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002876 //
2877 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04002878 tests = append(tests, testCase{
2879 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002880 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002882 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002883 ClientAuth: RequestClientCert,
2884 },
2885 })
2886 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002887 testType: serverTest,
2888 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04002889 config: Config{
2890 MaxVersion: VersionTLS12,
2891 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002892 // Setting SSL_VERIFY_PEER allows anonymous clients.
2893 flags: []string{"-verify-peer"},
2894 })
David Benjamin582ba042016-07-07 12:33:25 -07002895 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002896 tests = append(tests, testCase{
2897 testType: clientTest,
2898 name: "ClientAuth-NoCertificate-Client-SSL3",
2899 config: Config{
2900 MaxVersion: VersionSSL30,
2901 ClientAuth: RequestClientCert,
2902 },
2903 })
2904 tests = append(tests, testCase{
2905 testType: serverTest,
2906 name: "ClientAuth-NoCertificate-Server-SSL3",
2907 config: Config{
2908 MaxVersion: VersionSSL30,
2909 },
2910 // Setting SSL_VERIFY_PEER allows anonymous clients.
2911 flags: []string{"-verify-peer"},
2912 })
2913 }
2914 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002915 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002916 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002917 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002918 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002919 ClientAuth: RequireAnyClientCert,
2920 },
2921 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002922 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2923 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002924 },
2925 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002926 tests = append(tests, testCase{
2927 testType: clientTest,
2928 name: "ClientAuth-ECDSA-Client",
2929 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002930 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002931 ClientAuth: RequireAnyClientCert,
2932 },
2933 flags: []string{
2934 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2935 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2936 },
2937 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002938 tests = append(tests, testCase{
2939 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04002940 name: "ClientAuth-NoCertificate-OldCallback",
2941 config: Config{
2942 MaxVersion: VersionTLS12,
2943 ClientAuth: RequestClientCert,
2944 },
2945 flags: []string{"-use-old-client-cert-callback"},
2946 })
2947 tests = append(tests, testCase{
2948 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002949 name: "ClientAuth-OldCallback",
2950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002951 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05002952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-use-old-client-cert-callback",
2958 },
2959 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002960 tests = append(tests, testCase{
2961 testType: serverTest,
2962 name: "ClientAuth-Server",
2963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002964 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002965 Certificates: []Certificate{rsaCertificate},
2966 },
2967 flags: []string{"-require-any-client-certificate"},
2968 })
2969
David Benjamin4c3ddf72016-06-29 18:13:53 -04002970 // Test each key exchange on the server side for async keys.
2971 //
2972 // TODO(davidben): Add TLS 1.3 versions of these.
2973 tests = append(tests, testCase{
2974 testType: serverTest,
2975 name: "Basic-Server-RSA",
2976 config: Config{
2977 MaxVersion: VersionTLS12,
2978 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2979 },
2980 flags: []string{
2981 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2982 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2983 },
2984 })
2985 tests = append(tests, testCase{
2986 testType: serverTest,
2987 name: "Basic-Server-ECDHE-RSA",
2988 config: Config{
2989 MaxVersion: VersionTLS12,
2990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2991 },
2992 flags: []string{
2993 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2994 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2995 },
2996 })
2997 tests = append(tests, testCase{
2998 testType: serverTest,
2999 name: "Basic-Server-ECDHE-ECDSA",
3000 config: Config{
3001 MaxVersion: VersionTLS12,
3002 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3003 },
3004 flags: []string{
3005 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3006 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3007 },
3008 })
3009
David Benjamin760b1dd2015-05-15 23:33:48 -04003010 // No session ticket support; server doesn't send NewSessionTicket.
3011 tests = append(tests, testCase{
3012 name: "SessionTicketsDisabled-Client",
3013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003014 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003015 SessionTicketsDisabled: true,
3016 },
3017 })
3018 tests = append(tests, testCase{
3019 testType: serverTest,
3020 name: "SessionTicketsDisabled-Server",
3021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003022 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003023 SessionTicketsDisabled: true,
3024 },
3025 })
3026
3027 // Skip ServerKeyExchange in PSK key exchange if there's no
3028 // identity hint.
3029 tests = append(tests, testCase{
3030 name: "EmptyPSKHint-Client",
3031 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003032 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003033 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3034 PreSharedKey: []byte("secret"),
3035 },
3036 flags: []string{"-psk", "secret"},
3037 })
3038 tests = append(tests, testCase{
3039 testType: serverTest,
3040 name: "EmptyPSKHint-Server",
3041 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003042 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003043 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3044 PreSharedKey: []byte("secret"),
3045 },
3046 flags: []string{"-psk", "secret"},
3047 })
3048
David Benjamin4c3ddf72016-06-29 18:13:53 -04003049 // OCSP stapling tests.
3050 //
3051 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003052 tests = append(tests, testCase{
3053 testType: clientTest,
3054 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003055 config: Config{
3056 MaxVersion: VersionTLS12,
3057 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003058 flags: []string{
3059 "-enable-ocsp-stapling",
3060 "-expect-ocsp-response",
3061 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003062 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003063 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003064 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003065 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003066 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003067 testType: serverTest,
3068 name: "OCSPStapling-Server",
3069 config: Config{
3070 MaxVersion: VersionTLS12,
3071 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003072 expectedOCSPResponse: testOCSPResponse,
3073 flags: []string{
3074 "-ocsp-response",
3075 base64.StdEncoding.EncodeToString(testOCSPResponse),
3076 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003077 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003078 })
3079
David Benjamin4c3ddf72016-06-29 18:13:53 -04003080 // Certificate verification tests.
3081 //
3082 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003083 tests = append(tests, testCase{
3084 testType: clientTest,
3085 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003086 config: Config{
3087 MaxVersion: VersionTLS12,
3088 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003089 flags: []string{
3090 "-verify-peer",
3091 },
3092 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003093 tests = append(tests, testCase{
3094 testType: clientTest,
3095 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003096 config: Config{
3097 MaxVersion: VersionTLS12,
3098 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003099 flags: []string{
3100 "-verify-fail",
3101 "-verify-peer",
3102 },
3103 shouldFail: true,
3104 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3105 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003106 tests = append(tests, testCase{
3107 testType: clientTest,
3108 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003109 config: Config{
3110 MaxVersion: VersionTLS12,
3111 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003112 flags: []string{
3113 "-verify-fail",
3114 "-expect-verify-result",
3115 },
3116 })
3117
David Benjamin582ba042016-07-07 12:33:25 -07003118 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003119 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003120 name: "Renegotiate-Client",
3121 config: Config{
3122 MaxVersion: VersionTLS12,
3123 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003124 renegotiate: 1,
3125 flags: []string{
3126 "-renegotiate-freely",
3127 "-expect-total-renegotiations", "1",
3128 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003129 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003130
David Benjamin760b1dd2015-05-15 23:33:48 -04003131 // NPN on client and server; results in post-handshake message.
3132 tests = append(tests, testCase{
3133 name: "NPN-Client",
3134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003135 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003136 NextProtos: []string{"foo"},
3137 },
3138 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003139 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003140 expectedNextProto: "foo",
3141 expectedNextProtoType: npn,
3142 })
3143 tests = append(tests, testCase{
3144 testType: serverTest,
3145 name: "NPN-Server",
3146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003147 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003148 NextProtos: []string{"bar"},
3149 },
3150 flags: []string{
3151 "-advertise-npn", "\x03foo\x03bar\x03baz",
3152 "-expect-next-proto", "bar",
3153 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003154 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003155 expectedNextProto: "bar",
3156 expectedNextProtoType: npn,
3157 })
3158
3159 // TODO(davidben): Add tests for when False Start doesn't trigger.
3160
3161 // Client does False Start and negotiates NPN.
3162 tests = append(tests, testCase{
3163 name: "FalseStart",
3164 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003165 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3167 NextProtos: []string{"foo"},
3168 Bugs: ProtocolBugs{
3169 ExpectFalseStart: true,
3170 },
3171 },
3172 flags: []string{
3173 "-false-start",
3174 "-select-next-proto", "foo",
3175 },
3176 shimWritesFirst: true,
3177 resumeSession: true,
3178 })
3179
3180 // Client does False Start and negotiates ALPN.
3181 tests = append(tests, testCase{
3182 name: "FalseStart-ALPN",
3183 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003184 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003185 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3186 NextProtos: []string{"foo"},
3187 Bugs: ProtocolBugs{
3188 ExpectFalseStart: true,
3189 },
3190 },
3191 flags: []string{
3192 "-false-start",
3193 "-advertise-alpn", "\x03foo",
3194 },
3195 shimWritesFirst: true,
3196 resumeSession: true,
3197 })
3198
3199 // Client does False Start but doesn't explicitly call
3200 // SSL_connect.
3201 tests = append(tests, testCase{
3202 name: "FalseStart-Implicit",
3203 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003204 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003205 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3206 NextProtos: []string{"foo"},
3207 },
3208 flags: []string{
3209 "-implicit-handshake",
3210 "-false-start",
3211 "-advertise-alpn", "\x03foo",
3212 },
3213 })
3214
3215 // False Start without session tickets.
3216 tests = append(tests, testCase{
3217 name: "FalseStart-SessionTicketsDisabled",
3218 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003219 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3221 NextProtos: []string{"foo"},
3222 SessionTicketsDisabled: true,
3223 Bugs: ProtocolBugs{
3224 ExpectFalseStart: true,
3225 },
3226 },
3227 flags: []string{
3228 "-false-start",
3229 "-select-next-proto", "foo",
3230 },
3231 shimWritesFirst: true,
3232 })
3233
Adam Langleydf759b52016-07-11 15:24:37 -07003234 tests = append(tests, testCase{
3235 name: "FalseStart-CECPQ1",
3236 config: Config{
3237 MaxVersion: VersionTLS12,
3238 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3239 NextProtos: []string{"foo"},
3240 Bugs: ProtocolBugs{
3241 ExpectFalseStart: true,
3242 },
3243 },
3244 flags: []string{
3245 "-false-start",
3246 "-cipher", "DEFAULT:kCECPQ1",
3247 "-select-next-proto", "foo",
3248 },
3249 shimWritesFirst: true,
3250 resumeSession: true,
3251 })
3252
David Benjamin760b1dd2015-05-15 23:33:48 -04003253 // Server parses a V2ClientHello.
3254 tests = append(tests, testCase{
3255 testType: serverTest,
3256 name: "SendV2ClientHello",
3257 config: Config{
3258 // Choose a cipher suite that does not involve
3259 // elliptic curves, so no extensions are
3260 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003261 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003262 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3263 Bugs: ProtocolBugs{
3264 SendV2ClientHello: true,
3265 },
3266 },
3267 })
3268
3269 // Client sends a Channel ID.
3270 tests = append(tests, testCase{
3271 name: "ChannelID-Client",
3272 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003273 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003274 RequestChannelID: true,
3275 },
Adam Langley7c803a62015-06-15 15:35:05 -07003276 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 resumeSession: true,
3278 expectChannelID: true,
3279 })
3280
3281 // Server accepts a Channel ID.
3282 tests = append(tests, testCase{
3283 testType: serverTest,
3284 name: "ChannelID-Server",
3285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003286 MaxVersion: VersionTLS12,
3287 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003288 },
3289 flags: []string{
3290 "-expect-channel-id",
3291 base64.StdEncoding.EncodeToString(channelIDBytes),
3292 },
3293 resumeSession: true,
3294 expectChannelID: true,
3295 })
David Benjamin30789da2015-08-29 22:56:45 -04003296
David Benjaminf8fcdf32016-06-08 15:56:13 -04003297 // Channel ID and NPN at the same time, to ensure their relative
3298 // ordering is correct.
3299 tests = append(tests, testCase{
3300 name: "ChannelID-NPN-Client",
3301 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003302 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003303 RequestChannelID: true,
3304 NextProtos: []string{"foo"},
3305 },
3306 flags: []string{
3307 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3308 "-select-next-proto", "foo",
3309 },
3310 resumeSession: true,
3311 expectChannelID: true,
3312 expectedNextProto: "foo",
3313 expectedNextProtoType: npn,
3314 })
3315 tests = append(tests, testCase{
3316 testType: serverTest,
3317 name: "ChannelID-NPN-Server",
3318 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003319 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003320 ChannelID: channelIDKey,
3321 NextProtos: []string{"bar"},
3322 },
3323 flags: []string{
3324 "-expect-channel-id",
3325 base64.StdEncoding.EncodeToString(channelIDBytes),
3326 "-advertise-npn", "\x03foo\x03bar\x03baz",
3327 "-expect-next-proto", "bar",
3328 },
3329 resumeSession: true,
3330 expectChannelID: true,
3331 expectedNextProto: "bar",
3332 expectedNextProtoType: npn,
3333 })
3334
David Benjamin30789da2015-08-29 22:56:45 -04003335 // Bidirectional shutdown with the runner initiating.
3336 tests = append(tests, testCase{
3337 name: "Shutdown-Runner",
3338 config: Config{
3339 Bugs: ProtocolBugs{
3340 ExpectCloseNotify: true,
3341 },
3342 },
3343 flags: []string{"-check-close-notify"},
3344 })
3345
3346 // Bidirectional shutdown with the shim initiating. The runner,
3347 // in the meantime, sends garbage before the close_notify which
3348 // the shim must ignore.
3349 tests = append(tests, testCase{
3350 name: "Shutdown-Shim",
3351 config: Config{
3352 Bugs: ProtocolBugs{
3353 ExpectCloseNotify: true,
3354 },
3355 },
3356 shimShutsDown: true,
3357 sendEmptyRecords: 1,
3358 sendWarningAlerts: 1,
3359 flags: []string{"-check-close-notify"},
3360 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003361 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003362 // TODO(davidben): DTLS 1.3 will want a similar thing for
3363 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003364 tests = append(tests, testCase{
3365 name: "SkipHelloVerifyRequest",
3366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003367 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003368 Bugs: ProtocolBugs{
3369 SkipHelloVerifyRequest: true,
3370 },
3371 },
3372 })
3373 }
3374
David Benjamin760b1dd2015-05-15 23:33:48 -04003375 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003376 test.protocol = config.protocol
3377 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003378 test.name += "-DTLS"
3379 }
David Benjamin582ba042016-07-07 12:33:25 -07003380 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003381 test.name += "-Async"
3382 test.flags = append(test.flags, "-async")
3383 } else {
3384 test.name += "-Sync"
3385 }
David Benjamin582ba042016-07-07 12:33:25 -07003386 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003387 test.name += "-SplitHandshakeRecords"
3388 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003389 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003390 test.config.Bugs.MaxPacketLength = 256
3391 test.flags = append(test.flags, "-mtu", "256")
3392 }
3393 }
David Benjamin582ba042016-07-07 12:33:25 -07003394 if config.packHandshakeFlight {
3395 test.name += "-PackHandshakeFlight"
3396 test.config.Bugs.PackHandshakeFlight = true
3397 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003398 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003399 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003400}
3401
Adam Langley524e7172015-02-20 16:04:00 -08003402func addDDoSCallbackTests() {
3403 // DDoS callback.
3404
3405 for _, resume := range []bool{false, true} {
3406 suffix := "Resume"
3407 if resume {
3408 suffix = "No" + suffix
3409 }
3410
David Benjamin4c3ddf72016-06-29 18:13:53 -04003411 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3412
Adam Langley524e7172015-02-20 16:04:00 -08003413 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003414 testType: serverTest,
3415 name: "Server-DDoS-OK-" + suffix,
3416 config: Config{
3417 MaxVersion: VersionTLS12,
3418 },
Adam Langley524e7172015-02-20 16:04:00 -08003419 flags: []string{"-install-ddos-callback"},
3420 resumeSession: resume,
3421 })
3422
3423 failFlag := "-fail-ddos-callback"
3424 if resume {
3425 failFlag = "-fail-second-ddos-callback"
3426 }
3427 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003428 testType: serverTest,
3429 name: "Server-DDoS-Reject-" + suffix,
3430 config: Config{
3431 MaxVersion: VersionTLS12,
3432 },
Adam Langley524e7172015-02-20 16:04:00 -08003433 flags: []string{"-install-ddos-callback", failFlag},
3434 resumeSession: resume,
3435 shouldFail: true,
3436 expectedError: ":CONNECTION_REJECTED:",
3437 })
3438 }
3439}
3440
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003441func addVersionNegotiationTests() {
3442 for i, shimVers := range tlsVersions {
3443 // Assemble flags to disable all newer versions on the shim.
3444 var flags []string
3445 for _, vers := range tlsVersions[i+1:] {
3446 flags = append(flags, vers.flag)
3447 }
3448
3449 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003450 protocols := []protocol{tls}
3451 if runnerVers.hasDTLS && shimVers.hasDTLS {
3452 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003453 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003454 for _, protocol := range protocols {
3455 expectedVersion := shimVers.version
3456 if runnerVers.version < shimVers.version {
3457 expectedVersion = runnerVers.version
3458 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003459
David Benjamin8b8c0062014-11-23 02:47:52 -05003460 suffix := shimVers.name + "-" + runnerVers.name
3461 if protocol == dtls {
3462 suffix += "-DTLS"
3463 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003464
David Benjamin1eb367c2014-12-12 18:17:51 -05003465 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3466
David Benjamin1e29a6b2014-12-10 02:27:24 -05003467 clientVers := shimVers.version
3468 if clientVers > VersionTLS10 {
3469 clientVers = VersionTLS10
3470 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003471 serverVers := expectedVersion
3472 if expectedVersion >= VersionTLS13 {
3473 serverVers = VersionTLS10
3474 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003475 testCases = append(testCases, testCase{
3476 protocol: protocol,
3477 testType: clientTest,
3478 name: "VersionNegotiation-Client-" + suffix,
3479 config: Config{
3480 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003481 Bugs: ProtocolBugs{
3482 ExpectInitialRecordVersion: clientVers,
3483 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003484 },
3485 flags: flags,
3486 expectedVersion: expectedVersion,
3487 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003488 testCases = append(testCases, testCase{
3489 protocol: protocol,
3490 testType: clientTest,
3491 name: "VersionNegotiation-Client2-" + suffix,
3492 config: Config{
3493 MaxVersion: runnerVers.version,
3494 Bugs: ProtocolBugs{
3495 ExpectInitialRecordVersion: clientVers,
3496 },
3497 },
3498 flags: []string{"-max-version", shimVersFlag},
3499 expectedVersion: expectedVersion,
3500 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003501
3502 testCases = append(testCases, testCase{
3503 protocol: protocol,
3504 testType: serverTest,
3505 name: "VersionNegotiation-Server-" + suffix,
3506 config: Config{
3507 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003508 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003509 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003510 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003511 },
3512 flags: flags,
3513 expectedVersion: expectedVersion,
3514 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003515 testCases = append(testCases, testCase{
3516 protocol: protocol,
3517 testType: serverTest,
3518 name: "VersionNegotiation-Server2-" + suffix,
3519 config: Config{
3520 MaxVersion: runnerVers.version,
3521 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003522 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003523 },
3524 },
3525 flags: []string{"-max-version", shimVersFlag},
3526 expectedVersion: expectedVersion,
3527 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003528 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003529 }
3530 }
David Benjamin95c69562016-06-29 18:15:03 -04003531
3532 // Test for version tolerance.
3533 testCases = append(testCases, testCase{
3534 testType: serverTest,
3535 name: "MinorVersionTolerance",
3536 config: Config{
3537 Bugs: ProtocolBugs{
3538 SendClientVersion: 0x03ff,
3539 },
3540 },
3541 expectedVersion: VersionTLS13,
3542 })
3543 testCases = append(testCases, testCase{
3544 testType: serverTest,
3545 name: "MajorVersionTolerance",
3546 config: Config{
3547 Bugs: ProtocolBugs{
3548 SendClientVersion: 0x0400,
3549 },
3550 },
3551 expectedVersion: VersionTLS13,
3552 })
3553 testCases = append(testCases, testCase{
3554 protocol: dtls,
3555 testType: serverTest,
3556 name: "MinorVersionTolerance-DTLS",
3557 config: Config{
3558 Bugs: ProtocolBugs{
3559 SendClientVersion: 0x03ff,
3560 },
3561 },
3562 expectedVersion: VersionTLS12,
3563 })
3564 testCases = append(testCases, testCase{
3565 protocol: dtls,
3566 testType: serverTest,
3567 name: "MajorVersionTolerance-DTLS",
3568 config: Config{
3569 Bugs: ProtocolBugs{
3570 SendClientVersion: 0x0400,
3571 },
3572 },
3573 expectedVersion: VersionTLS12,
3574 })
3575
3576 // Test that versions below 3.0 are rejected.
3577 testCases = append(testCases, testCase{
3578 testType: serverTest,
3579 name: "VersionTooLow",
3580 config: Config{
3581 Bugs: ProtocolBugs{
3582 SendClientVersion: 0x0200,
3583 },
3584 },
3585 shouldFail: true,
3586 expectedError: ":UNSUPPORTED_PROTOCOL:",
3587 })
3588 testCases = append(testCases, testCase{
3589 protocol: dtls,
3590 testType: serverTest,
3591 name: "VersionTooLow-DTLS",
3592 config: Config{
3593 Bugs: ProtocolBugs{
3594 // 0x0201 is the lowest version expressable in
3595 // DTLS.
3596 SendClientVersion: 0x0201,
3597 },
3598 },
3599 shouldFail: true,
3600 expectedError: ":UNSUPPORTED_PROTOCOL:",
3601 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003602}
3603
David Benjaminaccb4542014-12-12 23:44:33 -05003604func addMinimumVersionTests() {
3605 for i, shimVers := range tlsVersions {
3606 // Assemble flags to disable all older versions on the shim.
3607 var flags []string
3608 for _, vers := range tlsVersions[:i] {
3609 flags = append(flags, vers.flag)
3610 }
3611
3612 for _, runnerVers := range tlsVersions {
3613 protocols := []protocol{tls}
3614 if runnerVers.hasDTLS && shimVers.hasDTLS {
3615 protocols = append(protocols, dtls)
3616 }
3617 for _, protocol := range protocols {
3618 suffix := shimVers.name + "-" + runnerVers.name
3619 if protocol == dtls {
3620 suffix += "-DTLS"
3621 }
3622 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3623
David Benjaminaccb4542014-12-12 23:44:33 -05003624 var expectedVersion uint16
3625 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003626 var expectedClientError, expectedServerError string
3627 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003628 if runnerVers.version >= shimVers.version {
3629 expectedVersion = runnerVers.version
3630 } else {
3631 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003632 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3633 expectedServerLocalError = "remote error: protocol version not supported"
3634 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3635 // If the client's minimum version is TLS 1.3 and the runner's
3636 // maximum is below TLS 1.2, the runner will fail to select a
3637 // cipher before the shim rejects the selected version.
3638 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3639 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3640 } else {
3641 expectedClientError = expectedServerError
3642 expectedClientLocalError = expectedServerLocalError
3643 }
David Benjaminaccb4542014-12-12 23:44:33 -05003644 }
3645
3646 testCases = append(testCases, testCase{
3647 protocol: protocol,
3648 testType: clientTest,
3649 name: "MinimumVersion-Client-" + suffix,
3650 config: Config{
3651 MaxVersion: runnerVers.version,
3652 },
David Benjamin87909c02014-12-13 01:55:01 -05003653 flags: flags,
3654 expectedVersion: expectedVersion,
3655 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003656 expectedError: expectedClientError,
3657 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003658 })
3659 testCases = append(testCases, testCase{
3660 protocol: protocol,
3661 testType: clientTest,
3662 name: "MinimumVersion-Client2-" + suffix,
3663 config: Config{
3664 MaxVersion: runnerVers.version,
3665 },
David Benjamin87909c02014-12-13 01:55:01 -05003666 flags: []string{"-min-version", shimVersFlag},
3667 expectedVersion: expectedVersion,
3668 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003669 expectedError: expectedClientError,
3670 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003671 })
3672
3673 testCases = append(testCases, testCase{
3674 protocol: protocol,
3675 testType: serverTest,
3676 name: "MinimumVersion-Server-" + suffix,
3677 config: Config{
3678 MaxVersion: runnerVers.version,
3679 },
David Benjamin87909c02014-12-13 01:55:01 -05003680 flags: flags,
3681 expectedVersion: expectedVersion,
3682 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003683 expectedError: expectedServerError,
3684 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003685 })
3686 testCases = append(testCases, testCase{
3687 protocol: protocol,
3688 testType: serverTest,
3689 name: "MinimumVersion-Server2-" + suffix,
3690 config: Config{
3691 MaxVersion: runnerVers.version,
3692 },
David Benjamin87909c02014-12-13 01:55:01 -05003693 flags: []string{"-min-version", shimVersFlag},
3694 expectedVersion: expectedVersion,
3695 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003696 expectedError: expectedServerError,
3697 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003698 })
3699 }
3700 }
3701 }
3702}
3703
David Benjamine78bfde2014-09-06 12:45:15 -04003704func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003705 // TODO(davidben): Extensions, where applicable, all move their server
3706 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3707 // tests for both. Also test interaction with 0-RTT when implemented.
3708
David Benjamine78bfde2014-09-06 12:45:15 -04003709 testCases = append(testCases, testCase{
3710 testType: clientTest,
3711 name: "DuplicateExtensionClient",
3712 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003713 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003714 Bugs: ProtocolBugs{
3715 DuplicateExtension: true,
3716 },
3717 },
3718 shouldFail: true,
3719 expectedLocalError: "remote error: error decoding message",
3720 })
3721 testCases = append(testCases, testCase{
3722 testType: serverTest,
3723 name: "DuplicateExtensionServer",
3724 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003725 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003726 Bugs: ProtocolBugs{
3727 DuplicateExtension: true,
3728 },
3729 },
3730 shouldFail: true,
3731 expectedLocalError: "remote error: error decoding message",
3732 })
3733 testCases = append(testCases, testCase{
3734 testType: clientTest,
3735 name: "ServerNameExtensionClient",
3736 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003737 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003738 Bugs: ProtocolBugs{
3739 ExpectServerName: "example.com",
3740 },
3741 },
3742 flags: []string{"-host-name", "example.com"},
3743 })
3744 testCases = append(testCases, testCase{
3745 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003746 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003748 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003749 Bugs: ProtocolBugs{
3750 ExpectServerName: "mismatch.com",
3751 },
3752 },
3753 flags: []string{"-host-name", "example.com"},
3754 shouldFail: true,
3755 expectedLocalError: "tls: unexpected server name",
3756 })
3757 testCases = append(testCases, testCase{
3758 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003759 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003760 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003761 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003762 Bugs: ProtocolBugs{
3763 ExpectServerName: "missing.com",
3764 },
3765 },
3766 shouldFail: true,
3767 expectedLocalError: "tls: unexpected server name",
3768 })
3769 testCases = append(testCases, testCase{
3770 testType: serverTest,
3771 name: "ServerNameExtensionServer",
3772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003773 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003774 ServerName: "example.com",
3775 },
3776 flags: []string{"-expect-server-name", "example.com"},
3777 resumeSession: true,
3778 })
David Benjaminae2888f2014-09-06 12:58:58 -04003779 testCases = append(testCases, testCase{
3780 testType: clientTest,
3781 name: "ALPNClient",
3782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003784 NextProtos: []string{"foo"},
3785 },
3786 flags: []string{
3787 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3788 "-expect-alpn", "foo",
3789 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003790 expectedNextProto: "foo",
3791 expectedNextProtoType: alpn,
3792 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003793 })
3794 testCases = append(testCases, testCase{
3795 testType: serverTest,
3796 name: "ALPNServer",
3797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003798 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003799 NextProtos: []string{"foo", "bar", "baz"},
3800 },
3801 flags: []string{
3802 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3803 "-select-alpn", "foo",
3804 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003805 expectedNextProto: "foo",
3806 expectedNextProtoType: alpn,
3807 resumeSession: true,
3808 })
David Benjamin594e7d22016-03-17 17:49:56 -04003809 testCases = append(testCases, testCase{
3810 testType: serverTest,
3811 name: "ALPNServer-Decline",
3812 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003813 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003814 NextProtos: []string{"foo", "bar", "baz"},
3815 },
3816 flags: []string{"-decline-alpn"},
3817 expectNoNextProto: true,
3818 resumeSession: true,
3819 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003820 // Test that the server prefers ALPN over NPN.
3821 testCases = append(testCases, testCase{
3822 testType: serverTest,
3823 name: "ALPNServer-Preferred",
3824 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003825 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003826 NextProtos: []string{"foo", "bar", "baz"},
3827 },
3828 flags: []string{
3829 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3830 "-select-alpn", "foo",
3831 "-advertise-npn", "\x03foo\x03bar\x03baz",
3832 },
3833 expectedNextProto: "foo",
3834 expectedNextProtoType: alpn,
3835 resumeSession: true,
3836 })
3837 testCases = append(testCases, testCase{
3838 testType: serverTest,
3839 name: "ALPNServer-Preferred-Swapped",
3840 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003841 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003842 NextProtos: []string{"foo", "bar", "baz"},
3843 Bugs: ProtocolBugs{
3844 SwapNPNAndALPN: true,
3845 },
3846 },
3847 flags: []string{
3848 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3849 "-select-alpn", "foo",
3850 "-advertise-npn", "\x03foo\x03bar\x03baz",
3851 },
3852 expectedNextProto: "foo",
3853 expectedNextProtoType: alpn,
3854 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003855 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003856 var emptyString string
3857 testCases = append(testCases, testCase{
3858 testType: clientTest,
3859 name: "ALPNClient-EmptyProtocolName",
3860 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003861 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003862 NextProtos: []string{""},
3863 Bugs: ProtocolBugs{
3864 // A server returning an empty ALPN protocol
3865 // should be rejected.
3866 ALPNProtocol: &emptyString,
3867 },
3868 },
3869 flags: []string{
3870 "-advertise-alpn", "\x03foo",
3871 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003872 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003873 expectedError: ":PARSE_TLSEXT:",
3874 })
3875 testCases = append(testCases, testCase{
3876 testType: serverTest,
3877 name: "ALPNServer-EmptyProtocolName",
3878 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003879 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07003880 // A ClientHello containing an empty ALPN protocol
3881 // should be rejected.
3882 NextProtos: []string{"foo", "", "baz"},
3883 },
3884 flags: []string{
3885 "-select-alpn", "foo",
3886 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003887 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003888 expectedError: ":PARSE_TLSEXT:",
3889 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003890 // Test that negotiating both NPN and ALPN is forbidden.
3891 testCases = append(testCases, testCase{
3892 name: "NegotiateALPNAndNPN",
3893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003894 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003895 NextProtos: []string{"foo", "bar", "baz"},
3896 Bugs: ProtocolBugs{
3897 NegotiateALPNAndNPN: true,
3898 },
3899 },
3900 flags: []string{
3901 "-advertise-alpn", "\x03foo",
3902 "-select-next-proto", "foo",
3903 },
3904 shouldFail: true,
3905 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3906 })
3907 testCases = append(testCases, testCase{
3908 name: "NegotiateALPNAndNPN-Swapped",
3909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003910 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04003911 NextProtos: []string{"foo", "bar", "baz"},
3912 Bugs: ProtocolBugs{
3913 NegotiateALPNAndNPN: true,
3914 SwapNPNAndALPN: true,
3915 },
3916 },
3917 flags: []string{
3918 "-advertise-alpn", "\x03foo",
3919 "-select-next-proto", "foo",
3920 },
3921 shouldFail: true,
3922 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3923 })
David Benjamin091c4b92015-10-26 13:33:21 -04003924 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3925 testCases = append(testCases, testCase{
3926 name: "DisableNPN",
3927 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003928 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04003929 NextProtos: []string{"foo"},
3930 },
3931 flags: []string{
3932 "-select-next-proto", "foo",
3933 "-disable-npn",
3934 },
3935 expectNoNextProto: true,
3936 })
Adam Langley38311732014-10-16 19:04:35 -07003937 // Resume with a corrupt ticket.
3938 testCases = append(testCases, testCase{
3939 testType: serverTest,
3940 name: "CorruptTicket",
3941 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003942 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003943 Bugs: ProtocolBugs{
3944 CorruptTicket: true,
3945 },
3946 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003947 resumeSession: true,
3948 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003949 })
David Benjamind98452d2015-06-16 14:16:23 -04003950 // Test the ticket callback, with and without renewal.
3951 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003952 testType: serverTest,
3953 name: "TicketCallback",
3954 config: Config{
3955 MaxVersion: VersionTLS12,
3956 },
David Benjamind98452d2015-06-16 14:16:23 -04003957 resumeSession: true,
3958 flags: []string{"-use-ticket-callback"},
3959 })
3960 testCases = append(testCases, testCase{
3961 testType: serverTest,
3962 name: "TicketCallback-Renew",
3963 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04003965 Bugs: ProtocolBugs{
3966 ExpectNewTicket: true,
3967 },
3968 },
3969 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3970 resumeSession: true,
3971 })
Adam Langley38311732014-10-16 19:04:35 -07003972 // Resume with an oversized session id.
3973 testCases = append(testCases, testCase{
3974 testType: serverTest,
3975 name: "OversizedSessionId",
3976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003977 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07003978 Bugs: ProtocolBugs{
3979 OversizedSessionId: true,
3980 },
3981 },
3982 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003983 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003984 expectedError: ":DECODE_ERROR:",
3985 })
David Benjaminca6c8262014-11-15 19:06:08 -05003986 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3987 // are ignored.
3988 testCases = append(testCases, testCase{
3989 protocol: dtls,
3990 name: "SRTP-Client",
3991 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003992 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05003993 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3994 },
3995 flags: []string{
3996 "-srtp-profiles",
3997 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3998 },
3999 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4000 })
4001 testCases = append(testCases, testCase{
4002 protocol: dtls,
4003 testType: serverTest,
4004 name: "SRTP-Server",
4005 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004006 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004007 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4008 },
4009 flags: []string{
4010 "-srtp-profiles",
4011 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4012 },
4013 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4014 })
4015 // Test that the MKI is ignored.
4016 testCases = append(testCases, testCase{
4017 protocol: dtls,
4018 testType: serverTest,
4019 name: "SRTP-Server-IgnoreMKI",
4020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004022 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4023 Bugs: ProtocolBugs{
4024 SRTPMasterKeyIdentifer: "bogus",
4025 },
4026 },
4027 flags: []string{
4028 "-srtp-profiles",
4029 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4030 },
4031 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4032 })
4033 // Test that SRTP isn't negotiated on the server if there were
4034 // no matching profiles.
4035 testCases = append(testCases, testCase{
4036 protocol: dtls,
4037 testType: serverTest,
4038 name: "SRTP-Server-NoMatch",
4039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004040 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004041 SRTPProtectionProfiles: []uint16{100, 101, 102},
4042 },
4043 flags: []string{
4044 "-srtp-profiles",
4045 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4046 },
4047 expectedSRTPProtectionProfile: 0,
4048 })
4049 // Test that the server returning an invalid SRTP profile is
4050 // flagged as an error by the client.
4051 testCases = append(testCases, testCase{
4052 protocol: dtls,
4053 name: "SRTP-Client-NoMatch",
4054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004055 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004056 Bugs: ProtocolBugs{
4057 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4058 },
4059 },
4060 flags: []string{
4061 "-srtp-profiles",
4062 "SRTP_AES128_CM_SHA1_80",
4063 },
4064 shouldFail: true,
4065 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4066 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004067 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004068 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004069 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004070 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004071 config: Config{
4072 MaxVersion: VersionTLS12,
4073 },
David Benjamin61f95272014-11-25 01:55:35 -05004074 flags: []string{
4075 "-enable-signed-cert-timestamps",
4076 "-expect-signed-cert-timestamps",
4077 base64.StdEncoding.EncodeToString(testSCTList),
4078 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004079 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004080 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004081 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004082 name: "SendSCTListOnResume",
4083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004084 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004085 Bugs: ProtocolBugs{
4086 SendSCTListOnResume: []byte("bogus"),
4087 },
4088 },
4089 flags: []string{
4090 "-enable-signed-cert-timestamps",
4091 "-expect-signed-cert-timestamps",
4092 base64.StdEncoding.EncodeToString(testSCTList),
4093 },
4094 resumeSession: true,
4095 })
4096 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004097 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004098 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004099 config: Config{
4100 MaxVersion: VersionTLS12,
4101 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004102 flags: []string{
4103 "-signed-cert-timestamps",
4104 base64.StdEncoding.EncodeToString(testSCTList),
4105 },
4106 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004107 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004108 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004109
Paul Lietar4fac72e2015-09-09 13:44:55 +01004110 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004111 testType: clientTest,
4112 name: "ClientHelloPadding",
4113 config: Config{
4114 Bugs: ProtocolBugs{
4115 RequireClientHelloSize: 512,
4116 },
4117 },
4118 // This hostname just needs to be long enough to push the
4119 // ClientHello into F5's danger zone between 256 and 511 bytes
4120 // long.
4121 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4122 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004123
4124 // Extensions should not function in SSL 3.0.
4125 testCases = append(testCases, testCase{
4126 testType: serverTest,
4127 name: "SSLv3Extensions-NoALPN",
4128 config: Config{
4129 MaxVersion: VersionSSL30,
4130 NextProtos: []string{"foo", "bar", "baz"},
4131 },
4132 flags: []string{
4133 "-select-alpn", "foo",
4134 },
4135 expectNoNextProto: true,
4136 })
4137
4138 // Test session tickets separately as they follow a different codepath.
4139 testCases = append(testCases, testCase{
4140 testType: serverTest,
4141 name: "SSLv3Extensions-NoTickets",
4142 config: Config{
4143 MaxVersion: VersionSSL30,
4144 Bugs: ProtocolBugs{
4145 // Historically, session tickets in SSL 3.0
4146 // failed in different ways depending on whether
4147 // the client supported renegotiation_info.
4148 NoRenegotiationInfo: true,
4149 },
4150 },
4151 resumeSession: true,
4152 })
4153 testCases = append(testCases, testCase{
4154 testType: serverTest,
4155 name: "SSLv3Extensions-NoTickets2",
4156 config: Config{
4157 MaxVersion: VersionSSL30,
4158 },
4159 resumeSession: true,
4160 })
4161
4162 // But SSL 3.0 does send and process renegotiation_info.
4163 testCases = append(testCases, testCase{
4164 testType: serverTest,
4165 name: "SSLv3Extensions-RenegotiationInfo",
4166 config: Config{
4167 MaxVersion: VersionSSL30,
4168 Bugs: ProtocolBugs{
4169 RequireRenegotiationInfo: true,
4170 },
4171 },
4172 })
4173 testCases = append(testCases, testCase{
4174 testType: serverTest,
4175 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4176 config: Config{
4177 MaxVersion: VersionSSL30,
4178 Bugs: ProtocolBugs{
4179 NoRenegotiationInfo: true,
4180 SendRenegotiationSCSV: true,
4181 RequireRenegotiationInfo: true,
4182 },
4183 },
4184 })
David Benjamine78bfde2014-09-06 12:45:15 -04004185}
4186
David Benjamin01fe8202014-09-24 15:21:44 -04004187func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004188 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004189 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004190 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4191 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4192 // TLS 1.3 only shares ciphers with TLS 1.2, so
4193 // we skip certain combinations and use a
4194 // different cipher to test with.
4195 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4196 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4197 continue
4198 }
4199 }
4200
David Benjamin8b8c0062014-11-23 02:47:52 -05004201 protocols := []protocol{tls}
4202 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4203 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004204 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004205 for _, protocol := range protocols {
4206 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4207 if protocol == dtls {
4208 suffix += "-DTLS"
4209 }
4210
David Benjaminece3de92015-03-16 18:02:20 -04004211 if sessionVers.version == resumeVers.version {
4212 testCases = append(testCases, testCase{
4213 protocol: protocol,
4214 name: "Resume-Client" + suffix,
4215 resumeSession: true,
4216 config: Config{
4217 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004218 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004219 },
David Benjaminece3de92015-03-16 18:02:20 -04004220 expectedVersion: sessionVers.version,
4221 expectedResumeVersion: resumeVers.version,
4222 })
4223 } else {
4224 testCases = append(testCases, testCase{
4225 protocol: protocol,
4226 name: "Resume-Client-Mismatch" + suffix,
4227 resumeSession: true,
4228 config: Config{
4229 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004230 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004231 },
David Benjaminece3de92015-03-16 18:02:20 -04004232 expectedVersion: sessionVers.version,
4233 resumeConfig: &Config{
4234 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004235 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004236 Bugs: ProtocolBugs{
4237 AllowSessionVersionMismatch: true,
4238 },
4239 },
4240 expectedResumeVersion: resumeVers.version,
4241 shouldFail: true,
4242 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4243 })
4244 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004245
4246 testCases = append(testCases, testCase{
4247 protocol: protocol,
4248 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004249 resumeSession: true,
4250 config: Config{
4251 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004252 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004253 },
4254 expectedVersion: sessionVers.version,
4255 resumeConfig: &Config{
4256 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004257 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004258 },
4259 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004260 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004261 expectedResumeVersion: resumeVers.version,
4262 })
4263
David Benjamin8b8c0062014-11-23 02:47:52 -05004264 testCases = append(testCases, testCase{
4265 protocol: protocol,
4266 testType: serverTest,
4267 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004268 resumeSession: true,
4269 config: Config{
4270 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004271 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004272 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004273 expectedVersion: sessionVers.version,
4274 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004275 resumeConfig: &Config{
4276 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004277 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004278 },
4279 expectedResumeVersion: resumeVers.version,
4280 })
4281 }
David Benjamin01fe8202014-09-24 15:21:44 -04004282 }
4283 }
David Benjaminece3de92015-03-16 18:02:20 -04004284
Nick Harper1fd39d82016-06-14 18:14:35 -07004285 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004286 testCases = append(testCases, testCase{
4287 name: "Resume-Client-CipherMismatch",
4288 resumeSession: true,
4289 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004290 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004291 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4292 },
4293 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004294 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004295 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4296 Bugs: ProtocolBugs{
4297 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4298 },
4299 },
4300 shouldFail: true,
4301 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4302 })
David Benjamin01fe8202014-09-24 15:21:44 -04004303}
4304
Adam Langley2ae77d22014-10-28 17:29:33 -07004305func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004306 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004307 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004308 testType: serverTest,
4309 name: "Renegotiate-Server-Forbidden",
4310 config: Config{
4311 MaxVersion: VersionTLS12,
4312 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004313 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004314 shouldFail: true,
4315 expectedError: ":NO_RENEGOTIATION:",
4316 expectedLocalError: "remote error: no renegotiation",
4317 })
Adam Langley5021b222015-06-12 18:27:58 -07004318 // The server shouldn't echo the renegotiation extension unless
4319 // requested by the client.
4320 testCases = append(testCases, testCase{
4321 testType: serverTest,
4322 name: "Renegotiate-Server-NoExt",
4323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004324 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004325 Bugs: ProtocolBugs{
4326 NoRenegotiationInfo: true,
4327 RequireRenegotiationInfo: true,
4328 },
4329 },
4330 shouldFail: true,
4331 expectedLocalError: "renegotiation extension missing",
4332 })
4333 // The renegotiation SCSV should be sufficient for the server to echo
4334 // the extension.
4335 testCases = append(testCases, testCase{
4336 testType: serverTest,
4337 name: "Renegotiate-Server-NoExt-SCSV",
4338 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004339 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004340 Bugs: ProtocolBugs{
4341 NoRenegotiationInfo: true,
4342 SendRenegotiationSCSV: true,
4343 RequireRenegotiationInfo: true,
4344 },
4345 },
4346 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004347 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004348 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004349 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004350 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004351 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004352 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004353 },
4354 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004355 renegotiate: 1,
4356 flags: []string{
4357 "-renegotiate-freely",
4358 "-expect-total-renegotiations", "1",
4359 },
David Benjamincdea40c2015-03-19 14:09:43 -04004360 })
4361 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004362 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004363 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004364 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004365 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004366 Bugs: ProtocolBugs{
4367 EmptyRenegotiationInfo: true,
4368 },
4369 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004370 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004371 shouldFail: true,
4372 expectedError: ":RENEGOTIATION_MISMATCH:",
4373 })
4374 testCases = append(testCases, testCase{
4375 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004376 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004377 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004378 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004379 Bugs: ProtocolBugs{
4380 BadRenegotiationInfo: true,
4381 },
4382 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004383 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004384 shouldFail: true,
4385 expectedError: ":RENEGOTIATION_MISMATCH:",
4386 })
4387 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004388 name: "Renegotiate-Client-Downgrade",
4389 renegotiate: 1,
4390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004391 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004392 Bugs: ProtocolBugs{
4393 NoRenegotiationInfoAfterInitial: true,
4394 },
4395 },
4396 flags: []string{"-renegotiate-freely"},
4397 shouldFail: true,
4398 expectedError: ":RENEGOTIATION_MISMATCH:",
4399 })
4400 testCases = append(testCases, testCase{
4401 name: "Renegotiate-Client-Upgrade",
4402 renegotiate: 1,
4403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004404 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004405 Bugs: ProtocolBugs{
4406 NoRenegotiationInfoInInitial: true,
4407 },
4408 },
4409 flags: []string{"-renegotiate-freely"},
4410 shouldFail: true,
4411 expectedError: ":RENEGOTIATION_MISMATCH:",
4412 })
4413 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004414 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004415 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004417 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004418 Bugs: ProtocolBugs{
4419 NoRenegotiationInfo: true,
4420 },
4421 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004422 flags: []string{
4423 "-renegotiate-freely",
4424 "-expect-total-renegotiations", "1",
4425 },
David Benjamincff0b902015-05-15 23:09:47 -04004426 })
4427 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004428 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004429 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004430 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004431 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004432 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4433 },
4434 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004435 flags: []string{
4436 "-renegotiate-freely",
4437 "-expect-total-renegotiations", "1",
4438 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004439 })
4440 testCases = append(testCases, testCase{
4441 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004442 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004443 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004444 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004445 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4446 },
4447 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004448 flags: []string{
4449 "-renegotiate-freely",
4450 "-expect-total-renegotiations", "1",
4451 },
David Benjaminb16346b2015-04-08 19:16:58 -04004452 })
4453 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004454 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004455 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004456 config: Config{
4457 MaxVersion: VersionTLS10,
4458 Bugs: ProtocolBugs{
4459 RequireSameRenegoClientVersion: true,
4460 },
4461 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004462 flags: []string{
4463 "-renegotiate-freely",
4464 "-expect-total-renegotiations", "1",
4465 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004466 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004467 testCases = append(testCases, testCase{
4468 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004469 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004470 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004471 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4473 NextProtos: []string{"foo"},
4474 },
4475 flags: []string{
4476 "-false-start",
4477 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004478 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004479 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004480 },
4481 shimWritesFirst: true,
4482 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004483
4484 // Client-side renegotiation controls.
4485 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004486 name: "Renegotiate-Client-Forbidden-1",
4487 config: Config{
4488 MaxVersion: VersionTLS12,
4489 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004490 renegotiate: 1,
4491 shouldFail: true,
4492 expectedError: ":NO_RENEGOTIATION:",
4493 expectedLocalError: "remote error: no renegotiation",
4494 })
4495 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004496 name: "Renegotiate-Client-Once-1",
4497 config: Config{
4498 MaxVersion: VersionTLS12,
4499 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004500 renegotiate: 1,
4501 flags: []string{
4502 "-renegotiate-once",
4503 "-expect-total-renegotiations", "1",
4504 },
4505 })
4506 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004507 name: "Renegotiate-Client-Freely-1",
4508 config: Config{
4509 MaxVersion: VersionTLS12,
4510 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004511 renegotiate: 1,
4512 flags: []string{
4513 "-renegotiate-freely",
4514 "-expect-total-renegotiations", "1",
4515 },
4516 })
4517 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004518 name: "Renegotiate-Client-Once-2",
4519 config: Config{
4520 MaxVersion: VersionTLS12,
4521 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004522 renegotiate: 2,
4523 flags: []string{"-renegotiate-once"},
4524 shouldFail: true,
4525 expectedError: ":NO_RENEGOTIATION:",
4526 expectedLocalError: "remote error: no renegotiation",
4527 })
4528 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004529 name: "Renegotiate-Client-Freely-2",
4530 config: Config{
4531 MaxVersion: VersionTLS12,
4532 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004533 renegotiate: 2,
4534 flags: []string{
4535 "-renegotiate-freely",
4536 "-expect-total-renegotiations", "2",
4537 },
4538 })
Adam Langley27a0d082015-11-03 13:34:10 -08004539 testCases = append(testCases, testCase{
4540 name: "Renegotiate-Client-NoIgnore",
4541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004542 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004543 Bugs: ProtocolBugs{
4544 SendHelloRequestBeforeEveryAppDataRecord: true,
4545 },
4546 },
4547 shouldFail: true,
4548 expectedError: ":NO_RENEGOTIATION:",
4549 })
4550 testCases = append(testCases, testCase{
4551 name: "Renegotiate-Client-Ignore",
4552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004553 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004554 Bugs: ProtocolBugs{
4555 SendHelloRequestBeforeEveryAppDataRecord: true,
4556 },
4557 },
4558 flags: []string{
4559 "-renegotiate-ignore",
4560 "-expect-total-renegotiations", "0",
4561 },
4562 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004563
David Benjamin397c8e62016-07-08 14:14:36 -07004564 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07004565 testCases = append(testCases, testCase{
4566 name: "StrayHelloRequest",
4567 config: Config{
4568 MaxVersion: VersionTLS12,
4569 Bugs: ProtocolBugs{
4570 SendHelloRequestBeforeEveryHandshakeMessage: true,
4571 },
4572 },
4573 })
4574 testCases = append(testCases, testCase{
4575 name: "StrayHelloRequest-Packed",
4576 config: Config{
4577 MaxVersion: VersionTLS12,
4578 Bugs: ProtocolBugs{
4579 PackHandshakeFlight: true,
4580 SendHelloRequestBeforeEveryHandshakeMessage: true,
4581 },
4582 },
4583 })
4584
David Benjamin397c8e62016-07-08 14:14:36 -07004585 // Renegotiation is forbidden in TLS 1.3.
4586 testCases = append(testCases, testCase{
4587 name: "Renegotiate-Client-TLS13",
4588 config: Config{
4589 MaxVersion: VersionTLS13,
4590 },
4591 renegotiate: 1,
4592 flags: []string{
4593 "-renegotiate-freely",
4594 },
4595 shouldFail: true,
4596 expectedError: ":NO_RENEGOTIATION:",
4597 })
4598
4599 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
4600 testCases = append(testCases, testCase{
4601 name: "StrayHelloRequest-TLS13",
4602 config: Config{
4603 MaxVersion: VersionTLS13,
4604 Bugs: ProtocolBugs{
4605 SendHelloRequestBeforeEveryHandshakeMessage: true,
4606 },
4607 },
4608 shouldFail: true,
4609 expectedError: ":UNEXPECTED_MESSAGE:",
4610 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004611}
4612
David Benjamin5e961c12014-11-07 01:48:35 -05004613func addDTLSReplayTests() {
4614 // Test that sequence number replays are detected.
4615 testCases = append(testCases, testCase{
4616 protocol: dtls,
4617 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004618 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004619 replayWrites: true,
4620 })
4621
David Benjamin8e6db492015-07-25 18:29:23 -04004622 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004623 // than the retransmit window.
4624 testCases = append(testCases, testCase{
4625 protocol: dtls,
4626 name: "DTLS-Replay-LargeGaps",
4627 config: Config{
4628 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004629 SequenceNumberMapping: func(in uint64) uint64 {
4630 return in * 127
4631 },
David Benjamin5e961c12014-11-07 01:48:35 -05004632 },
4633 },
David Benjamin8e6db492015-07-25 18:29:23 -04004634 messageCount: 200,
4635 replayWrites: true,
4636 })
4637
4638 // Test the incoming sequence number changing non-monotonically.
4639 testCases = append(testCases, testCase{
4640 protocol: dtls,
4641 name: "DTLS-Replay-NonMonotonic",
4642 config: Config{
4643 Bugs: ProtocolBugs{
4644 SequenceNumberMapping: func(in uint64) uint64 {
4645 return in ^ 31
4646 },
4647 },
4648 },
4649 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004650 replayWrites: true,
4651 })
4652}
4653
Nick Harper60edffd2016-06-21 15:19:24 -07004654var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004655 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004656 id signatureAlgorithm
4657 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004658}{
Nick Harper60edffd2016-06-21 15:19:24 -07004659 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4660 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4661 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4662 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
4663 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSA},
4664 // TODO(davidben): These signature algorithms are paired with a curve in
4665 // TLS 1.3. Test that, in TLS 1.3, the curves must match and, in TLS
4666 // 1.2, mismatches are tolerated.
4667 {"ECDSA-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSA},
4668 {"ECDSA-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSA},
4669 {"ECDSA-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSA},
David Benjamin000800a2014-11-14 01:43:59 -05004670}
4671
Nick Harper60edffd2016-06-21 15:19:24 -07004672const fakeSigAlg1 signatureAlgorithm = 0x2a01
4673const fakeSigAlg2 signatureAlgorithm = 0xff01
4674
4675func addSignatureAlgorithmTests() {
4676 // Make sure each signature algorithm works. Include some fake values in
4677 // the list and ensure they're ignored.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004678 //
4679 // TODO(davidben): Test each of these against both TLS 1.2 and TLS 1.3.
Nick Harper60edffd2016-06-21 15:19:24 -07004680 for _, alg := range testSignatureAlgorithms {
David Benjamin000800a2014-11-14 01:43:59 -05004681 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004682 name: "SigningHash-ClientAuth-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004684 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004685 // SignatureAlgorithms is shared, so we must
4686 // configure a matching server certificate too.
4687 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4688 ClientAuth: RequireAnyClientCert,
4689 SignatureAlgorithms: []signatureAlgorithm{
4690 fakeSigAlg1,
4691 alg.id,
4692 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004693 },
4694 },
4695 flags: []string{
Nick Harper60edffd2016-06-21 15:19:24 -07004696 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4697 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4698 },
4699 expectedPeerSignatureAlgorithm: alg.id,
4700 })
4701
4702 testCases = append(testCases, testCase{
4703 testType: serverTest,
4704 name: "SigningHash-ClientAuth-Verify-" + alg.name,
4705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004706 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004707 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4708 SignatureAlgorithms: []signatureAlgorithm{
4709 alg.id,
4710 },
4711 },
4712 flags: []string{
4713 "-require-any-client-certificate",
4714 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4715 // SignatureAlgorithms is shared, so we must
4716 // configure a matching server certificate too.
4717 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4718 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin000800a2014-11-14 01:43:59 -05004719 },
4720 })
4721
4722 testCases = append(testCases, testCase{
4723 testType: serverTest,
Nick Harper60edffd2016-06-21 15:19:24 -07004724 name: "SigningHash-ServerKeyExchange-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004726 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004727 CipherSuites: []uint16{
4728 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4729 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4730 },
4731 SignatureAlgorithms: []signatureAlgorithm{
4732 fakeSigAlg1,
4733 alg.id,
4734 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004735 },
4736 },
Nick Harper60edffd2016-06-21 15:19:24 -07004737 flags: []string{
4738 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4739 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4740 },
4741 expectedPeerSignatureAlgorithm: alg.id,
David Benjamin000800a2014-11-14 01:43:59 -05004742 })
David Benjamin6e807652015-11-02 12:02:20 -05004743
4744 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004745 name: "SigningHash-ServerKeyExchange-Verify-" + alg.name,
David Benjamin6e807652015-11-02 12:02:20 -05004746 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004747 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004748 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4749 CipherSuites: []uint16{
4750 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4751 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4752 },
4753 SignatureAlgorithms: []signatureAlgorithm{
4754 alg.id,
David Benjamin6e807652015-11-02 12:02:20 -05004755 },
4756 },
Nick Harper60edffd2016-06-21 15:19:24 -07004757 flags: []string{"-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id))},
David Benjamin6e807652015-11-02 12:02:20 -05004758 })
David Benjamin000800a2014-11-14 01:43:59 -05004759 }
4760
Nick Harper60edffd2016-06-21 15:19:24 -07004761 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004762 //
4763 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004764 testCases = append(testCases, testCase{
4765 name: "SigningHash-ClientAuth-SignatureType",
4766 config: Config{
4767 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004768 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004769 SignatureAlgorithms: []signatureAlgorithm{
4770 signatureECDSAWithP521AndSHA512,
4771 signatureRSAPKCS1WithSHA384,
4772 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004773 },
4774 },
4775 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004776 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4777 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004778 },
Nick Harper60edffd2016-06-21 15:19:24 -07004779 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004780 })
4781
4782 testCases = append(testCases, testCase{
4783 testType: serverTest,
4784 name: "SigningHash-ServerKeyExchange-SignatureType",
4785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004786 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004788 SignatureAlgorithms: []signatureAlgorithm{
4789 signatureECDSAWithP521AndSHA512,
4790 signatureRSAPKCS1WithSHA384,
4791 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004792 },
4793 },
Nick Harper60edffd2016-06-21 15:19:24 -07004794 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004795 })
4796
David Benjamin51dd7d62016-07-08 16:07:01 -07004797 // Test that, if the list is missing, the peer falls back to SHA-1 in
4798 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004799 testCases = append(testCases, testCase{
4800 name: "SigningHash-ClientAuth-Fallback",
4801 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004802 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004803 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004804 SignatureAlgorithms: []signatureAlgorithm{
4805 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004806 },
4807 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004808 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004809 },
4810 },
4811 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004812 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4813 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004814 },
4815 })
4816
4817 testCases = append(testCases, testCase{
4818 testType: serverTest,
4819 name: "SigningHash-ServerKeyExchange-Fallback",
4820 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004821 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004822 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004823 SignatureAlgorithms: []signatureAlgorithm{
4824 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004825 },
4826 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004827 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004828 },
4829 },
4830 })
David Benjamin72dc7832015-03-16 17:49:43 -04004831
David Benjamin51dd7d62016-07-08 16:07:01 -07004832 testCases = append(testCases, testCase{
4833 name: "SigningHash-ClientAuth-Fallback-TLS13",
4834 config: Config{
4835 MaxVersion: VersionTLS13,
4836 ClientAuth: RequireAnyClientCert,
4837 SignatureAlgorithms: []signatureAlgorithm{
4838 signatureRSAPKCS1WithSHA1,
4839 },
4840 Bugs: ProtocolBugs{
4841 NoSignatureAlgorithms: true,
4842 },
4843 },
4844 flags: []string{
4845 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4846 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4847 },
4848 shouldFail: true,
4849 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4850 })
4851
4852 testCases = append(testCases, testCase{
4853 testType: serverTest,
4854 name: "SigningHash-ServerKeyExchange-Fallback-TLS13",
4855 config: Config{
4856 MaxVersion: VersionTLS13,
4857 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4858 SignatureAlgorithms: []signatureAlgorithm{
4859 signatureRSAPKCS1WithSHA1,
4860 },
4861 Bugs: ProtocolBugs{
4862 NoSignatureAlgorithms: true,
4863 },
4864 },
4865 shouldFail: true,
4866 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
4867 })
4868
David Benjamin72dc7832015-03-16 17:49:43 -04004869 // Test that hash preferences are enforced. BoringSSL defaults to
4870 // rejecting MD5 signatures.
4871 testCases = append(testCases, testCase{
4872 testType: serverTest,
4873 name: "SigningHash-ClientAuth-Enforced",
4874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004875 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004876 Certificates: []Certificate{rsaCertificate},
Nick Harper60edffd2016-06-21 15:19:24 -07004877 SignatureAlgorithms: []signatureAlgorithm{
4878 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004879 // Advertise SHA-1 so the handshake will
4880 // proceed, but the shim's preferences will be
4881 // ignored in CertificateVerify generation, so
4882 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07004883 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04004884 },
4885 Bugs: ProtocolBugs{
4886 IgnorePeerSignatureAlgorithmPreferences: true,
4887 },
4888 },
4889 flags: []string{"-require-any-client-certificate"},
4890 shouldFail: true,
4891 expectedError: ":WRONG_SIGNATURE_TYPE:",
4892 })
4893
4894 testCases = append(testCases, testCase{
4895 name: "SigningHash-ServerKeyExchange-Enforced",
4896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004897 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004898 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004899 SignatureAlgorithms: []signatureAlgorithm{
4900 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004901 },
4902 Bugs: ProtocolBugs{
4903 IgnorePeerSignatureAlgorithmPreferences: true,
4904 },
4905 },
4906 shouldFail: true,
4907 expectedError: ":WRONG_SIGNATURE_TYPE:",
4908 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004909
4910 // Test that the agreed upon digest respects the client preferences and
4911 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004912 //
4913 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04004914 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07004915 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04004916 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004917 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004918 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004919 SignatureAlgorithms: []signatureAlgorithm{
4920 signatureRSAPKCS1WithSHA512,
4921 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004922 },
4923 },
4924 flags: []string{
4925 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4926 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4927 },
David Benjaminea9a0d52016-07-08 15:52:59 -07004928 digestPrefs: "SHA256",
4929 shouldFail: true,
4930 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04004931 })
4932 testCases = append(testCases, testCase{
4933 name: "Agree-Digest-SHA256",
4934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004935 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004936 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004937 SignatureAlgorithms: []signatureAlgorithm{
4938 signatureRSAPKCS1WithSHA1,
4939 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004940 },
4941 },
4942 flags: []string{
4943 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4944 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4945 },
Nick Harper60edffd2016-06-21 15:19:24 -07004946 digestPrefs: "SHA256,SHA1",
4947 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004948 })
4949 testCases = append(testCases, testCase{
4950 name: "Agree-Digest-SHA1",
4951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004952 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004953 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004954 SignatureAlgorithms: []signatureAlgorithm{
4955 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004956 },
4957 },
4958 flags: []string{
4959 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4960 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4961 },
Nick Harper60edffd2016-06-21 15:19:24 -07004962 digestPrefs: "SHA512,SHA256,SHA1",
4963 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004964 })
4965 testCases = append(testCases, testCase{
4966 name: "Agree-Digest-Default",
4967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004968 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004969 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004970 SignatureAlgorithms: []signatureAlgorithm{
4971 signatureRSAPKCS1WithSHA256,
4972 signatureECDSAWithP256AndSHA256,
4973 signatureRSAPKCS1WithSHA1,
4974 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004975 },
4976 },
4977 flags: []string{
4978 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4979 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4980 },
Nick Harper60edffd2016-06-21 15:19:24 -07004981 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004982 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004983
4984 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
4985 // signature algorithms.
4986 //
4987 // TODO(davidben): Add a TLS 1.3 version of this test where the mismatch
4988 // is allowed.
4989 testCases = append(testCases, testCase{
4990 name: "CheckLeafCurve",
4991 config: Config{
4992 MaxVersion: VersionTLS12,
4993 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4994 Certificates: []Certificate{getECDSACertificate()},
4995 },
4996 flags: []string{"-p384-only"},
4997 shouldFail: true,
4998 expectedError: ":BAD_ECC_CERT:",
4999 })
David Benjamin000800a2014-11-14 01:43:59 -05005000}
5001
David Benjamin83f90402015-01-27 01:09:43 -05005002// timeouts is the retransmit schedule for BoringSSL. It doubles and
5003// caps at 60 seconds. On the 13th timeout, it gives up.
5004var timeouts = []time.Duration{
5005 1 * time.Second,
5006 2 * time.Second,
5007 4 * time.Second,
5008 8 * time.Second,
5009 16 * time.Second,
5010 32 * time.Second,
5011 60 * time.Second,
5012 60 * time.Second,
5013 60 * time.Second,
5014 60 * time.Second,
5015 60 * time.Second,
5016 60 * time.Second,
5017 60 * time.Second,
5018}
5019
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005020// shortTimeouts is an alternate set of timeouts which would occur if the
5021// initial timeout duration was set to 250ms.
5022var shortTimeouts = []time.Duration{
5023 250 * time.Millisecond,
5024 500 * time.Millisecond,
5025 1 * time.Second,
5026 2 * time.Second,
5027 4 * time.Second,
5028 8 * time.Second,
5029 16 * time.Second,
5030 32 * time.Second,
5031 60 * time.Second,
5032 60 * time.Second,
5033 60 * time.Second,
5034 60 * time.Second,
5035 60 * time.Second,
5036}
5037
David Benjamin83f90402015-01-27 01:09:43 -05005038func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005039 // These tests work by coordinating some behavior on both the shim and
5040 // the runner.
5041 //
5042 // TimeoutSchedule configures the runner to send a series of timeout
5043 // opcodes to the shim (see packetAdaptor) immediately before reading
5044 // each peer handshake flight N. The timeout opcode both simulates a
5045 // timeout in the shim and acts as a synchronization point to help the
5046 // runner bracket each handshake flight.
5047 //
5048 // We assume the shim does not read from the channel eagerly. It must
5049 // first wait until it has sent flight N and is ready to receive
5050 // handshake flight N+1. At this point, it will process the timeout
5051 // opcode. It must then immediately respond with a timeout ACK and act
5052 // as if the shim was idle for the specified amount of time.
5053 //
5054 // The runner then drops all packets received before the ACK and
5055 // continues waiting for flight N. This ordering results in one attempt
5056 // at sending flight N to be dropped. For the test to complete, the
5057 // shim must send flight N again, testing that the shim implements DTLS
5058 // retransmit on a timeout.
5059
David Benjamin4c3ddf72016-06-29 18:13:53 -04005060 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5061 // likely be more epochs to cross and the final message's retransmit may
5062 // be more complex.
5063
David Benjamin585d7a42016-06-02 14:58:00 -04005064 for _, async := range []bool{true, false} {
5065 var tests []testCase
5066
5067 // Test that this is indeed the timeout schedule. Stress all
5068 // four patterns of handshake.
5069 for i := 1; i < len(timeouts); i++ {
5070 number := strconv.Itoa(i)
5071 tests = append(tests, testCase{
5072 protocol: dtls,
5073 name: "DTLS-Retransmit-Client-" + number,
5074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005075 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005076 Bugs: ProtocolBugs{
5077 TimeoutSchedule: timeouts[:i],
5078 },
5079 },
5080 resumeSession: true,
5081 })
5082 tests = append(tests, testCase{
5083 protocol: dtls,
5084 testType: serverTest,
5085 name: "DTLS-Retransmit-Server-" + number,
5086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005087 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005088 Bugs: ProtocolBugs{
5089 TimeoutSchedule: timeouts[:i],
5090 },
5091 },
5092 resumeSession: true,
5093 })
5094 }
5095
5096 // Test that exceeding the timeout schedule hits a read
5097 // timeout.
5098 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005099 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005100 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005101 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005102 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005103 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005104 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005105 },
5106 },
5107 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005108 shouldFail: true,
5109 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005110 })
David Benjamin585d7a42016-06-02 14:58:00 -04005111
5112 if async {
5113 // Test that timeout handling has a fudge factor, due to API
5114 // problems.
5115 tests = append(tests, testCase{
5116 protocol: dtls,
5117 name: "DTLS-Retransmit-Fudge",
5118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005119 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005120 Bugs: ProtocolBugs{
5121 TimeoutSchedule: []time.Duration{
5122 timeouts[0] - 10*time.Millisecond,
5123 },
5124 },
5125 },
5126 resumeSession: true,
5127 })
5128 }
5129
5130 // Test that the final Finished retransmitting isn't
5131 // duplicated if the peer badly fragments everything.
5132 tests = append(tests, testCase{
5133 testType: serverTest,
5134 protocol: dtls,
5135 name: "DTLS-Retransmit-Fragmented",
5136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005137 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005138 Bugs: ProtocolBugs{
5139 TimeoutSchedule: []time.Duration{timeouts[0]},
5140 MaxHandshakeRecordLength: 2,
5141 },
5142 },
5143 })
5144
5145 // Test the timeout schedule when a shorter initial timeout duration is set.
5146 tests = append(tests, testCase{
5147 protocol: dtls,
5148 name: "DTLS-Retransmit-Short-Client",
5149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005150 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005151 Bugs: ProtocolBugs{
5152 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5153 },
5154 },
5155 resumeSession: true,
5156 flags: []string{"-initial-timeout-duration-ms", "250"},
5157 })
5158 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005159 protocol: dtls,
5160 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005161 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005163 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005164 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005165 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005166 },
5167 },
5168 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005169 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005170 })
David Benjamin585d7a42016-06-02 14:58:00 -04005171
5172 for _, test := range tests {
5173 if async {
5174 test.name += "-Async"
5175 test.flags = append(test.flags, "-async")
5176 }
5177
5178 testCases = append(testCases, test)
5179 }
David Benjamin83f90402015-01-27 01:09:43 -05005180 }
David Benjamin83f90402015-01-27 01:09:43 -05005181}
5182
David Benjaminc565ebb2015-04-03 04:06:36 -04005183func addExportKeyingMaterialTests() {
5184 for _, vers := range tlsVersions {
5185 if vers.version == VersionSSL30 {
5186 continue
5187 }
5188 testCases = append(testCases, testCase{
5189 name: "ExportKeyingMaterial-" + vers.name,
5190 config: Config{
5191 MaxVersion: vers.version,
5192 },
5193 exportKeyingMaterial: 1024,
5194 exportLabel: "label",
5195 exportContext: "context",
5196 useExportContext: true,
5197 })
5198 testCases = append(testCases, testCase{
5199 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5200 config: Config{
5201 MaxVersion: vers.version,
5202 },
5203 exportKeyingMaterial: 1024,
5204 })
5205 testCases = append(testCases, testCase{
5206 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5207 config: Config{
5208 MaxVersion: vers.version,
5209 },
5210 exportKeyingMaterial: 1024,
5211 useExportContext: true,
5212 })
5213 testCases = append(testCases, testCase{
5214 name: "ExportKeyingMaterial-Small-" + vers.name,
5215 config: Config{
5216 MaxVersion: vers.version,
5217 },
5218 exportKeyingMaterial: 1,
5219 exportLabel: "label",
5220 exportContext: "context",
5221 useExportContext: true,
5222 })
5223 }
5224 testCases = append(testCases, testCase{
5225 name: "ExportKeyingMaterial-SSL3",
5226 config: Config{
5227 MaxVersion: VersionSSL30,
5228 },
5229 exportKeyingMaterial: 1024,
5230 exportLabel: "label",
5231 exportContext: "context",
5232 useExportContext: true,
5233 shouldFail: true,
5234 expectedError: "failed to export keying material",
5235 })
5236}
5237
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005238func addTLSUniqueTests() {
5239 for _, isClient := range []bool{false, true} {
5240 for _, isResumption := range []bool{false, true} {
5241 for _, hasEMS := range []bool{false, true} {
5242 var suffix string
5243 if isResumption {
5244 suffix = "Resume-"
5245 } else {
5246 suffix = "Full-"
5247 }
5248
5249 if hasEMS {
5250 suffix += "EMS-"
5251 } else {
5252 suffix += "NoEMS-"
5253 }
5254
5255 if isClient {
5256 suffix += "Client"
5257 } else {
5258 suffix += "Server"
5259 }
5260
5261 test := testCase{
5262 name: "TLSUnique-" + suffix,
5263 testTLSUnique: true,
5264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005265 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005266 Bugs: ProtocolBugs{
5267 NoExtendedMasterSecret: !hasEMS,
5268 },
5269 },
5270 }
5271
5272 if isResumption {
5273 test.resumeSession = true
5274 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005275 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005276 Bugs: ProtocolBugs{
5277 NoExtendedMasterSecret: !hasEMS,
5278 },
5279 }
5280 }
5281
5282 if isResumption && !hasEMS {
5283 test.shouldFail = true
5284 test.expectedError = "failed to get tls-unique"
5285 }
5286
5287 testCases = append(testCases, test)
5288 }
5289 }
5290 }
5291}
5292
Adam Langley09505632015-07-30 18:10:13 -07005293func addCustomExtensionTests() {
5294 expectedContents := "custom extension"
5295 emptyString := ""
5296
David Benjamin4c3ddf72016-06-29 18:13:53 -04005297 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005298 for _, isClient := range []bool{false, true} {
5299 suffix := "Server"
5300 flag := "-enable-server-custom-extension"
5301 testType := serverTest
5302 if isClient {
5303 suffix = "Client"
5304 flag = "-enable-client-custom-extension"
5305 testType = clientTest
5306 }
5307
5308 testCases = append(testCases, testCase{
5309 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005310 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005311 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005312 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005313 Bugs: ProtocolBugs{
5314 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005315 ExpectedCustomExtension: &expectedContents,
5316 },
5317 },
5318 flags: []string{flag},
5319 })
5320
5321 // If the parse callback fails, the handshake should also fail.
5322 testCases = append(testCases, testCase{
5323 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005324 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005326 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005327 Bugs: ProtocolBugs{
5328 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005329 ExpectedCustomExtension: &expectedContents,
5330 },
5331 },
David Benjamin399e7c92015-07-30 23:01:27 -04005332 flags: []string{flag},
5333 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005334 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5335 })
5336
5337 // If the add callback fails, the handshake should also fail.
5338 testCases = append(testCases, testCase{
5339 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005340 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005342 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005343 Bugs: ProtocolBugs{
5344 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005345 ExpectedCustomExtension: &expectedContents,
5346 },
5347 },
David Benjamin399e7c92015-07-30 23:01:27 -04005348 flags: []string{flag, "-custom-extension-fail-add"},
5349 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005350 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5351 })
5352
5353 // If the add callback returns zero, no extension should be
5354 // added.
5355 skipCustomExtension := expectedContents
5356 if isClient {
5357 // For the case where the client skips sending the
5358 // custom extension, the server must not “echo” it.
5359 skipCustomExtension = ""
5360 }
5361 testCases = append(testCases, testCase{
5362 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005363 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005364 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005365 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005366 Bugs: ProtocolBugs{
5367 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005368 ExpectedCustomExtension: &emptyString,
5369 },
5370 },
5371 flags: []string{flag, "-custom-extension-skip"},
5372 })
5373 }
5374
5375 // The custom extension add callback should not be called if the client
5376 // doesn't send the extension.
5377 testCases = append(testCases, testCase{
5378 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005379 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005380 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005381 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005382 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005383 ExpectedCustomExtension: &emptyString,
5384 },
5385 },
5386 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5387 })
Adam Langley2deb9842015-08-07 11:15:37 -07005388
5389 // Test an unknown extension from the server.
5390 testCases = append(testCases, testCase{
5391 testType: clientTest,
5392 name: "UnknownExtension-Client",
5393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005394 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005395 Bugs: ProtocolBugs{
5396 CustomExtension: expectedContents,
5397 },
5398 },
5399 shouldFail: true,
5400 expectedError: ":UNEXPECTED_EXTENSION:",
5401 })
Adam Langley09505632015-07-30 18:10:13 -07005402}
5403
David Benjaminb36a3952015-12-01 18:53:13 -05005404func addRSAClientKeyExchangeTests() {
5405 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5406 testCases = append(testCases, testCase{
5407 testType: serverTest,
5408 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5409 config: Config{
5410 // Ensure the ClientHello version and final
5411 // version are different, to detect if the
5412 // server uses the wrong one.
5413 MaxVersion: VersionTLS11,
5414 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5415 Bugs: ProtocolBugs{
5416 BadRSAClientKeyExchange: bad,
5417 },
5418 },
5419 shouldFail: true,
5420 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5421 })
5422 }
5423}
5424
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005425var testCurves = []struct {
5426 name string
5427 id CurveID
5428}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005429 {"P-256", CurveP256},
5430 {"P-384", CurveP384},
5431 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005432 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005433}
5434
5435func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005436 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005437 for _, curve := range testCurves {
5438 testCases = append(testCases, testCase{
5439 name: "CurveTest-Client-" + curve.name,
5440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005441 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5443 CurvePreferences: []CurveID{curve.id},
5444 },
5445 flags: []string{"-enable-all-curves"},
5446 })
5447 testCases = append(testCases, testCase{
5448 testType: serverTest,
5449 name: "CurveTest-Server-" + curve.name,
5450 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005451 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005452 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5453 CurvePreferences: []CurveID{curve.id},
5454 },
5455 flags: []string{"-enable-all-curves"},
5456 })
5457 }
David Benjamin241ae832016-01-15 03:04:54 -05005458
5459 // The server must be tolerant to bogus curves.
5460 const bogusCurve = 0x1234
5461 testCases = append(testCases, testCase{
5462 testType: serverTest,
5463 name: "UnknownCurve",
5464 config: Config{
5465 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5466 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5467 },
5468 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005469
5470 // The server must not consider ECDHE ciphers when there are no
5471 // supported curves.
5472 testCases = append(testCases, testCase{
5473 testType: serverTest,
5474 name: "NoSupportedCurves",
5475 config: Config{
5476 // TODO(davidben): Add a TLS 1.3 version of this.
5477 MaxVersion: VersionTLS12,
5478 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5479 Bugs: ProtocolBugs{
5480 NoSupportedCurves: true,
5481 },
5482 },
5483 shouldFail: true,
5484 expectedError: ":NO_SHARED_CIPHER:",
5485 })
5486
5487 // The server must fall back to another cipher when there are no
5488 // supported curves.
5489 testCases = append(testCases, testCase{
5490 testType: serverTest,
5491 name: "NoCommonCurves",
5492 config: Config{
5493 MaxVersion: VersionTLS12,
5494 CipherSuites: []uint16{
5495 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5496 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5497 },
5498 CurvePreferences: []CurveID{CurveP224},
5499 },
5500 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5501 })
5502
5503 // The client must reject bogus curves and disabled curves.
5504 testCases = append(testCases, testCase{
5505 name: "BadECDHECurve",
5506 config: Config{
5507 // TODO(davidben): Add a TLS 1.3 version of this.
5508 MaxVersion: VersionTLS12,
5509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5510 Bugs: ProtocolBugs{
5511 SendCurve: bogusCurve,
5512 },
5513 },
5514 shouldFail: true,
5515 expectedError: ":WRONG_CURVE:",
5516 })
5517
5518 testCases = append(testCases, testCase{
5519 name: "UnsupportedCurve",
5520 config: Config{
5521 // TODO(davidben): Add a TLS 1.3 version of this.
5522 MaxVersion: VersionTLS12,
5523 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5524 CurvePreferences: []CurveID{CurveP256},
5525 Bugs: ProtocolBugs{
5526 IgnorePeerCurvePreferences: true,
5527 },
5528 },
5529 flags: []string{"-p384-only"},
5530 shouldFail: true,
5531 expectedError: ":WRONG_CURVE:",
5532 })
5533
5534 // Test invalid curve points.
5535 testCases = append(testCases, testCase{
5536 name: "InvalidECDHPoint-Client",
5537 config: Config{
5538 // TODO(davidben): Add a TLS 1.3 version of this test.
5539 MaxVersion: VersionTLS12,
5540 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5541 CurvePreferences: []CurveID{CurveP256},
5542 Bugs: ProtocolBugs{
5543 InvalidECDHPoint: true,
5544 },
5545 },
5546 shouldFail: true,
5547 expectedError: ":INVALID_ENCODING:",
5548 })
5549 testCases = append(testCases, testCase{
5550 testType: serverTest,
5551 name: "InvalidECDHPoint-Server",
5552 config: Config{
5553 // TODO(davidben): Add a TLS 1.3 version of this test.
5554 MaxVersion: VersionTLS12,
5555 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5556 CurvePreferences: []CurveID{CurveP256},
5557 Bugs: ProtocolBugs{
5558 InvalidECDHPoint: true,
5559 },
5560 },
5561 shouldFail: true,
5562 expectedError: ":INVALID_ENCODING:",
5563 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005564}
5565
Matt Braithwaite54217e42016-06-13 13:03:47 -07005566func addCECPQ1Tests() {
5567 testCases = append(testCases, testCase{
5568 testType: clientTest,
5569 name: "CECPQ1-Client-BadX25519Part",
5570 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005571 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005572 MinVersion: VersionTLS12,
5573 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5574 Bugs: ProtocolBugs{
5575 CECPQ1BadX25519Part: true,
5576 },
5577 },
5578 flags: []string{"-cipher", "kCECPQ1"},
5579 shouldFail: true,
5580 expectedLocalError: "local error: bad record MAC",
5581 })
5582 testCases = append(testCases, testCase{
5583 testType: clientTest,
5584 name: "CECPQ1-Client-BadNewhopePart",
5585 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005586 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005587 MinVersion: VersionTLS12,
5588 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5589 Bugs: ProtocolBugs{
5590 CECPQ1BadNewhopePart: true,
5591 },
5592 },
5593 flags: []string{"-cipher", "kCECPQ1"},
5594 shouldFail: true,
5595 expectedLocalError: "local error: bad record MAC",
5596 })
5597 testCases = append(testCases, testCase{
5598 testType: serverTest,
5599 name: "CECPQ1-Server-BadX25519Part",
5600 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005601 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005602 MinVersion: VersionTLS12,
5603 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5604 Bugs: ProtocolBugs{
5605 CECPQ1BadX25519Part: true,
5606 },
5607 },
5608 flags: []string{"-cipher", "kCECPQ1"},
5609 shouldFail: true,
5610 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5611 })
5612 testCases = append(testCases, testCase{
5613 testType: serverTest,
5614 name: "CECPQ1-Server-BadNewhopePart",
5615 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005616 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005617 MinVersion: VersionTLS12,
5618 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5619 Bugs: ProtocolBugs{
5620 CECPQ1BadNewhopePart: true,
5621 },
5622 },
5623 flags: []string{"-cipher", "kCECPQ1"},
5624 shouldFail: true,
5625 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5626 })
5627}
5628
David Benjamin4cc36ad2015-12-19 14:23:26 -05005629func addKeyExchangeInfoTests() {
5630 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005631 name: "KeyExchangeInfo-DHE-Client",
5632 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005633 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005634 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5635 Bugs: ProtocolBugs{
5636 // This is a 1234-bit prime number, generated
5637 // with:
5638 // openssl gendh 1234 | openssl asn1parse -i
5639 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5640 },
5641 },
David Benjamin9e68f192016-06-30 14:55:33 -04005642 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005643 })
5644 testCases = append(testCases, testCase{
5645 testType: serverTest,
5646 name: "KeyExchangeInfo-DHE-Server",
5647 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005648 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005649 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5650 },
5651 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005652 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005653 })
5654
Nick Harper1fd39d82016-06-14 18:14:35 -07005655 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5656 // handshake is separate.
5657
David Benjamin4cc36ad2015-12-19 14:23:26 -05005658 testCases = append(testCases, testCase{
5659 name: "KeyExchangeInfo-ECDHE-Client",
5660 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005661 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005662 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5663 CurvePreferences: []CurveID{CurveX25519},
5664 },
David Benjamin9e68f192016-06-30 14:55:33 -04005665 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005666 })
5667 testCases = append(testCases, testCase{
5668 testType: serverTest,
5669 name: "KeyExchangeInfo-ECDHE-Server",
5670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005671 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5673 CurvePreferences: []CurveID{CurveX25519},
5674 },
David Benjamin9e68f192016-06-30 14:55:33 -04005675 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005676 })
5677}
5678
David Benjaminc9ae27c2016-06-24 22:56:37 -04005679func addTLS13RecordTests() {
5680 testCases = append(testCases, testCase{
5681 name: "TLS13-RecordPadding",
5682 config: Config{
5683 MaxVersion: VersionTLS13,
5684 MinVersion: VersionTLS13,
5685 Bugs: ProtocolBugs{
5686 RecordPadding: 10,
5687 },
5688 },
5689 })
5690
5691 testCases = append(testCases, testCase{
5692 name: "TLS13-EmptyRecords",
5693 config: Config{
5694 MaxVersion: VersionTLS13,
5695 MinVersion: VersionTLS13,
5696 Bugs: ProtocolBugs{
5697 OmitRecordContents: true,
5698 },
5699 },
5700 shouldFail: true,
5701 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5702 })
5703
5704 testCases = append(testCases, testCase{
5705 name: "TLS13-OnlyPadding",
5706 config: Config{
5707 MaxVersion: VersionTLS13,
5708 MinVersion: VersionTLS13,
5709 Bugs: ProtocolBugs{
5710 OmitRecordContents: true,
5711 RecordPadding: 10,
5712 },
5713 },
5714 shouldFail: true,
5715 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5716 })
5717
5718 testCases = append(testCases, testCase{
5719 name: "TLS13-WrongOuterRecord",
5720 config: Config{
5721 MaxVersion: VersionTLS13,
5722 MinVersion: VersionTLS13,
5723 Bugs: ProtocolBugs{
5724 OuterRecordType: recordTypeHandshake,
5725 },
5726 },
5727 shouldFail: true,
5728 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5729 })
5730}
5731
David Benjamin82261be2016-07-07 14:32:50 -07005732func addChangeCipherSpecTests() {
5733 // Test missing ChangeCipherSpecs.
5734 testCases = append(testCases, testCase{
5735 name: "SkipChangeCipherSpec-Client",
5736 config: Config{
5737 MaxVersion: VersionTLS12,
5738 Bugs: ProtocolBugs{
5739 SkipChangeCipherSpec: true,
5740 },
5741 },
5742 shouldFail: true,
5743 expectedError: ":UNEXPECTED_RECORD:",
5744 })
5745 testCases = append(testCases, testCase{
5746 testType: serverTest,
5747 name: "SkipChangeCipherSpec-Server",
5748 config: Config{
5749 MaxVersion: VersionTLS12,
5750 Bugs: ProtocolBugs{
5751 SkipChangeCipherSpec: true,
5752 },
5753 },
5754 shouldFail: true,
5755 expectedError: ":UNEXPECTED_RECORD:",
5756 })
5757 testCases = append(testCases, testCase{
5758 testType: serverTest,
5759 name: "SkipChangeCipherSpec-Server-NPN",
5760 config: Config{
5761 MaxVersion: VersionTLS12,
5762 NextProtos: []string{"bar"},
5763 Bugs: ProtocolBugs{
5764 SkipChangeCipherSpec: true,
5765 },
5766 },
5767 flags: []string{
5768 "-advertise-npn", "\x03foo\x03bar\x03baz",
5769 },
5770 shouldFail: true,
5771 expectedError: ":UNEXPECTED_RECORD:",
5772 })
5773
5774 // Test synchronization between the handshake and ChangeCipherSpec.
5775 // Partial post-CCS handshake messages before ChangeCipherSpec should be
5776 // rejected. Test both with and without handshake packing to handle both
5777 // when the partial post-CCS message is in its own record and when it is
5778 // attached to the pre-CCS message.
5779 //
5780 // TODO(davidben): Fix and test DTLS as well.
5781 for _, packed := range []bool{false, true} {
5782 var suffix string
5783 if packed {
5784 suffix = "-Packed"
5785 }
5786
5787 testCases = append(testCases, testCase{
5788 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
5789 config: Config{
5790 MaxVersion: VersionTLS12,
5791 Bugs: ProtocolBugs{
5792 FragmentAcrossChangeCipherSpec: true,
5793 PackHandshakeFlight: packed,
5794 },
5795 },
5796 shouldFail: true,
5797 expectedError: ":UNEXPECTED_RECORD:",
5798 })
5799 testCases = append(testCases, testCase{
5800 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
5801 config: Config{
5802 MaxVersion: VersionTLS12,
5803 },
5804 resumeSession: true,
5805 resumeConfig: &Config{
5806 MaxVersion: VersionTLS12,
5807 Bugs: ProtocolBugs{
5808 FragmentAcrossChangeCipherSpec: true,
5809 PackHandshakeFlight: packed,
5810 },
5811 },
5812 shouldFail: true,
5813 expectedError: ":UNEXPECTED_RECORD:",
5814 })
5815 testCases = append(testCases, testCase{
5816 testType: serverTest,
5817 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
5818 config: Config{
5819 MaxVersion: VersionTLS12,
5820 Bugs: ProtocolBugs{
5821 FragmentAcrossChangeCipherSpec: true,
5822 PackHandshakeFlight: packed,
5823 },
5824 },
5825 shouldFail: true,
5826 expectedError: ":UNEXPECTED_RECORD:",
5827 })
5828 testCases = append(testCases, testCase{
5829 testType: serverTest,
5830 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
5831 config: Config{
5832 MaxVersion: VersionTLS12,
5833 },
5834 resumeSession: true,
5835 resumeConfig: &Config{
5836 MaxVersion: VersionTLS12,
5837 Bugs: ProtocolBugs{
5838 FragmentAcrossChangeCipherSpec: true,
5839 PackHandshakeFlight: packed,
5840 },
5841 },
5842 shouldFail: true,
5843 expectedError: ":UNEXPECTED_RECORD:",
5844 })
5845 testCases = append(testCases, testCase{
5846 testType: serverTest,
5847 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
5848 config: Config{
5849 MaxVersion: VersionTLS12,
5850 NextProtos: []string{"bar"},
5851 Bugs: ProtocolBugs{
5852 FragmentAcrossChangeCipherSpec: true,
5853 PackHandshakeFlight: packed,
5854 },
5855 },
5856 flags: []string{
5857 "-advertise-npn", "\x03foo\x03bar\x03baz",
5858 },
5859 shouldFail: true,
5860 expectedError: ":UNEXPECTED_RECORD:",
5861 })
5862 }
5863
5864 // Test that early ChangeCipherSpecs are handled correctly.
5865 testCases = append(testCases, testCase{
5866 testType: serverTest,
5867 name: "EarlyChangeCipherSpec-server-1",
5868 config: Config{
5869 MaxVersion: VersionTLS12,
5870 Bugs: ProtocolBugs{
5871 EarlyChangeCipherSpec: 1,
5872 },
5873 },
5874 shouldFail: true,
5875 expectedError: ":UNEXPECTED_RECORD:",
5876 })
5877 testCases = append(testCases, testCase{
5878 testType: serverTest,
5879 name: "EarlyChangeCipherSpec-server-2",
5880 config: Config{
5881 MaxVersion: VersionTLS12,
5882 Bugs: ProtocolBugs{
5883 EarlyChangeCipherSpec: 2,
5884 },
5885 },
5886 shouldFail: true,
5887 expectedError: ":UNEXPECTED_RECORD:",
5888 })
5889 testCases = append(testCases, testCase{
5890 protocol: dtls,
5891 name: "StrayChangeCipherSpec",
5892 config: Config{
5893 // TODO(davidben): Once DTLS 1.3 exists, test
5894 // that stray ChangeCipherSpec messages are
5895 // rejected.
5896 MaxVersion: VersionTLS12,
5897 Bugs: ProtocolBugs{
5898 StrayChangeCipherSpec: true,
5899 },
5900 },
5901 })
5902
5903 // Test that the contents of ChangeCipherSpec are checked.
5904 testCases = append(testCases, testCase{
5905 name: "BadChangeCipherSpec-1",
5906 config: Config{
5907 MaxVersion: VersionTLS12,
5908 Bugs: ProtocolBugs{
5909 BadChangeCipherSpec: []byte{2},
5910 },
5911 },
5912 shouldFail: true,
5913 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5914 })
5915 testCases = append(testCases, testCase{
5916 name: "BadChangeCipherSpec-2",
5917 config: Config{
5918 MaxVersion: VersionTLS12,
5919 Bugs: ProtocolBugs{
5920 BadChangeCipherSpec: []byte{1, 1},
5921 },
5922 },
5923 shouldFail: true,
5924 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5925 })
5926 testCases = append(testCases, testCase{
5927 protocol: dtls,
5928 name: "BadChangeCipherSpec-DTLS-1",
5929 config: Config{
5930 MaxVersion: VersionTLS12,
5931 Bugs: ProtocolBugs{
5932 BadChangeCipherSpec: []byte{2},
5933 },
5934 },
5935 shouldFail: true,
5936 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5937 })
5938 testCases = append(testCases, testCase{
5939 protocol: dtls,
5940 name: "BadChangeCipherSpec-DTLS-2",
5941 config: Config{
5942 MaxVersion: VersionTLS12,
5943 Bugs: ProtocolBugs{
5944 BadChangeCipherSpec: []byte{1, 1},
5945 },
5946 },
5947 shouldFail: true,
5948 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
5949 })
5950}
5951
Adam Langley7c803a62015-06-15 15:35:05 -07005952func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005953 defer wg.Done()
5954
5955 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005956 var err error
5957
5958 if *mallocTest < 0 {
5959 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005960 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005961 } else {
5962 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5963 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005964 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005965 if err != nil {
5966 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5967 }
5968 break
5969 }
5970 }
5971 }
Adam Langley95c29f32014-06-20 12:00:00 -07005972 statusChan <- statusMsg{test: test, err: err}
5973 }
5974}
5975
5976type statusMsg struct {
5977 test *testCase
5978 started bool
5979 err error
5980}
5981
David Benjamin5f237bc2015-02-11 17:14:15 -05005982func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005983 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005984
David Benjamin5f237bc2015-02-11 17:14:15 -05005985 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005986 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005987 if !*pipe {
5988 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005989 var erase string
5990 for i := 0; i < lineLen; i++ {
5991 erase += "\b \b"
5992 }
5993 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005994 }
5995
Adam Langley95c29f32014-06-20 12:00:00 -07005996 if msg.started {
5997 started++
5998 } else {
5999 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05006000
6001 if msg.err != nil {
6002 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
6003 failed++
6004 testOutput.addResult(msg.test.name, "FAIL")
6005 } else {
6006 if *pipe {
6007 // Print each test instead of a status line.
6008 fmt.Printf("PASSED (%s)\n", msg.test.name)
6009 }
6010 testOutput.addResult(msg.test.name, "PASS")
6011 }
Adam Langley95c29f32014-06-20 12:00:00 -07006012 }
6013
David Benjamin5f237bc2015-02-11 17:14:15 -05006014 if !*pipe {
6015 // Print a new status line.
6016 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
6017 lineLen = len(line)
6018 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07006019 }
Adam Langley95c29f32014-06-20 12:00:00 -07006020 }
David Benjamin5f237bc2015-02-11 17:14:15 -05006021
6022 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07006023}
6024
6025func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07006026 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07006027 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07006028
Adam Langley7c803a62015-06-15 15:35:05 -07006029 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006030 addCipherSuiteTests()
6031 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07006032 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07006033 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04006034 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08006035 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04006036 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05006037 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04006038 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04006039 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07006040 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07006041 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05006042 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07006043 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05006044 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04006045 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006046 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07006047 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05006048 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006049 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07006050 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05006051 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04006052 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07006053 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07006054 addChangeCipherSpecTests()
Adam Langley95c29f32014-06-20 12:00:00 -07006055
6056 var wg sync.WaitGroup
6057
Adam Langley7c803a62015-06-15 15:35:05 -07006058 statusChan := make(chan statusMsg, *numWorkers)
6059 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05006060 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07006061
David Benjamin025b3d32014-07-01 19:53:04 -04006062 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07006063
Adam Langley7c803a62015-06-15 15:35:05 -07006064 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07006065 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07006066 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07006067 }
6068
David Benjamin270f0a72016-03-17 14:41:36 -04006069 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04006070 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07006071 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04006072 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04006073 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07006074 }
6075 }
David Benjamin270f0a72016-03-17 14:41:36 -04006076 if !foundTest {
6077 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
6078 os.Exit(1)
6079 }
Adam Langley95c29f32014-06-20 12:00:00 -07006080
6081 close(testChan)
6082 wg.Wait()
6083 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05006084 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07006085
6086 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05006087
6088 if *jsonOutput != "" {
6089 if err := testOutput.writeTo(*jsonOutput); err != nil {
6090 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
6091 }
6092 }
David Benjamin2ab7a862015-04-04 17:02:18 -04006093
6094 if !testOutput.allPassed {
6095 os.Exit(1)
6096 }
Adam Langley95c29f32014-06-20 12:00:00 -07006097}