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