blob: b8f70882a6a52eb65aba6441c15749567311f059 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -040023 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070024 "flag"
25 "fmt"
26 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070027 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070028 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "net"
30 "os"
31 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040032 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040033 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080034 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070035 "strings"
36 "sync"
37 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050038 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070039)
40
Adam Langley69a01602014-11-17 17:26:55 -080041var (
David Benjamin5f237bc2015-02-11 17:14:15 -050042 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
43 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050044 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050045 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
46 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
47 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
48 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
49 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070050 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
51 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
52 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
53 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050054 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050055 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin01784b42016-06-07 18:00:52 -040056 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
David Benjamin2e045a92016-06-08 13:09:56 -040057 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
Adam Langley69a01602014-11-17 17:26:55 -080058)
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin025b3d32014-07-01 19:53:04 -040060const (
61 rsaCertificateFile = "cert.pem"
62 ecdsaCertificateFile = "ecdsa_cert.pem"
63)
64
65const (
David Benjamina08e49d2014-08-24 01:46:07 -040066 rsaKeyFile = "key.pem"
67 ecdsaKeyFile = "ecdsa_key.pem"
68 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040069)
70
Adam Langley95c29f32014-06-20 12:00:00 -070071var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040072var channelIDKey *ecdsa.PrivateKey
73var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070074
David Benjamin61f95272014-11-25 01:55:35 -050075var testOCSPResponse = []byte{1, 2, 3, 4}
76var testSCTList = []byte{5, 6, 7, 8}
77
Adam Langley95c29f32014-06-20 12:00:00 -070078func initCertificates() {
79 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070080 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070081 if err != nil {
82 panic(err)
83 }
David Benjamin61f95272014-11-25 01:55:35 -050084 rsaCertificate.OCSPStaple = testOCSPResponse
85 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070086
Adam Langley7c803a62015-06-15 15:35:05 -070087 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070088 if err != nil {
89 panic(err)
90 }
David Benjamin61f95272014-11-25 01:55:35 -050091 ecdsaCertificate.OCSPStaple = testOCSPResponse
92 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040093
Adam Langley7c803a62015-06-15 15:35:05 -070094 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040095 if err != nil {
96 panic(err)
97 }
98 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
99 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
100 panic("bad key type")
101 }
102 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
103 if err != nil {
104 panic(err)
105 }
106 if channelIDKey.Curve != elliptic.P256() {
107 panic("bad curve")
108 }
109
110 channelIDBytes = make([]byte, 64)
111 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
112 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700113}
114
115var certificateOnce sync.Once
116
117func getRSACertificate() Certificate {
118 certificateOnce.Do(initCertificates)
119 return rsaCertificate
120}
121
122func getECDSACertificate() Certificate {
123 certificateOnce.Do(initCertificates)
124 return ecdsaCertificate
125}
126
David Benjamin025b3d32014-07-01 19:53:04 -0400127type testType int
128
129const (
130 clientTest testType = iota
131 serverTest
132)
133
David Benjamin6fd297b2014-08-11 18:43:38 -0400134type protocol int
135
136const (
137 tls protocol = iota
138 dtls
139)
140
David Benjaminfc7b0862014-09-06 13:21:53 -0400141const (
142 alpn = 1
143 npn = 2
144)
145
Nick Harper60edffd2016-06-21 15:19:24 -0700146type testCert int
147
148const (
149 testCertRSA testCert = iota
150 testCertECDSA
151)
152
153func getRunnerCertificate(t testCert) Certificate {
154 switch t {
155 case testCertRSA:
156 return getRSACertificate()
157 case testCertECDSA:
158 return getECDSACertificate()
159 default:
160 panic("Unknown test certificate")
161 }
162}
163
164func getShimCertificate(t testCert) string {
165 switch t {
166 case testCertRSA:
167 return rsaCertificateFile
168 case testCertECDSA:
169 return ecdsaCertificateFile
170 default:
171 panic("Unknown test certificate")
172 }
173}
174
175func getShimKey(t testCert) string {
176 switch t {
177 case testCertRSA:
178 return rsaKeyFile
179 case testCertECDSA:
180 return ecdsaKeyFile
181 default:
182 panic("Unknown test certificate")
183 }
184}
185
Adam Langley95c29f32014-06-20 12:00:00 -0700186type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400187 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400188 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700189 name string
190 config Config
191 shouldFail bool
192 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700193 // expectedLocalError, if not empty, contains a substring that must be
194 // found in the local error.
195 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400196 // expectedVersion, if non-zero, specifies the TLS version that must be
197 // negotiated.
198 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400199 // expectedResumeVersion, if non-zero, specifies the TLS version that
200 // must be negotiated on resumption. If zero, expectedVersion is used.
201 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400202 // expectedCipher, if non-zero, specifies the TLS cipher suite that
203 // should be negotiated.
204 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400205 // expectChannelID controls whether the connection should have
206 // negotiated a Channel ID with channelIDKey.
207 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400208 // expectedNextProto controls whether the connection should
209 // negotiate a next protocol via NPN or ALPN.
210 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400211 // expectNoNextProto, if true, means that no next protocol should be
212 // negotiated.
213 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400214 // expectedNextProtoType, if non-zero, is the expected next
215 // protocol negotiation mechanism.
216 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500217 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
218 // should be negotiated. If zero, none should be negotiated.
219 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100220 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
221 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100222 // expectedSCTList, if not nil, is the expected SCT list to be received.
223 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700224 // expectedPeerSignatureAlgorithm, if not zero, is the signature
225 // algorithm that the peer should have used in the handshake.
226 expectedPeerSignatureAlgorithm signatureAlgorithm
Adam Langley80842bd2014-06-20 12:00:00 -0700227 // messageLen is the length, in bytes, of the test message that will be
228 // sent.
229 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400230 // messageCount is the number of test messages that will be sent.
231 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400232 // digestPrefs is the list of digest preferences from the client.
233 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400234 // certFile is the path to the certificate to use for the server.
235 certFile string
236 // keyFile is the path to the private key to use for the server.
237 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400238 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400239 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400240 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700241 // expectResumeRejected, if true, specifies that the attempted
242 // resumption must be rejected by the client. This is only valid for a
243 // serverTest.
244 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400245 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500246 // resumption. Unless newSessionsOnResume is set,
247 // SessionTicketKey, ServerSessionCache, and
248 // ClientSessionCache are copied from the initial connection's
249 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400250 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500251 // newSessionsOnResume, if true, will cause resumeConfig to
252 // use a different session resumption context.
253 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400254 // noSessionCache, if true, will cause the server to run without a
255 // session cache.
256 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400257 // sendPrefix sends a prefix on the socket before actually performing a
258 // handshake.
259 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400260 // shimWritesFirst controls whether the shim sends an initial "hello"
261 // message before doing a roundtrip with the runner.
262 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400263 // shimShutsDown, if true, runs a test where the shim shuts down the
264 // connection immediately after the handshake rather than echoing
265 // messages from the runner.
266 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400267 // renegotiate indicates the number of times the connection should be
268 // renegotiated during the exchange.
269 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700270 // renegotiateCiphers is a list of ciphersuite ids that will be
271 // switched in just before renegotiation.
272 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500273 // replayWrites, if true, configures the underlying transport
274 // to replay every write it makes in DTLS tests.
275 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500276 // damageFirstWrite, if true, configures the underlying transport to
277 // damage the final byte of the first application data write.
278 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400279 // exportKeyingMaterial, if non-zero, configures the test to exchange
280 // keying material and verify they match.
281 exportKeyingMaterial int
282 exportLabel string
283 exportContext string
284 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400285 // flags, if not empty, contains a list of command-line flags that will
286 // be passed to the shim program.
287 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700288 // testTLSUnique, if true, causes the shim to send the tls-unique value
289 // which will be compared against the expected value.
290 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400291 // sendEmptyRecords is the number of consecutive empty records to send
292 // before and after the test message.
293 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400294 // sendWarningAlerts is the number of consecutive warning alerts to send
295 // before and after the test message.
296 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400297 // expectMessageDropped, if true, means the test message is expected to
298 // be dropped by the client rather than echoed back.
299 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700300}
301
Adam Langley7c803a62015-06-15 15:35:05 -0700302var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700303
David Benjamin9867b7d2016-03-01 23:25:48 -0500304func writeTranscript(test *testCase, isResume bool, data []byte) {
305 if len(data) == 0 {
306 return
307 }
308
309 protocol := "tls"
310 if test.protocol == dtls {
311 protocol = "dtls"
312 }
313
314 side := "client"
315 if test.testType == serverTest {
316 side = "server"
317 }
318
319 dir := path.Join(*transcriptDir, protocol, side)
320 if err := os.MkdirAll(dir, 0755); err != nil {
321 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
322 return
323 }
324
325 name := test.name
326 if isResume {
327 name += "-Resume"
328 } else {
329 name += "-Normal"
330 }
331
332 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
333 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
334 }
335}
336
David Benjamin3ed59772016-03-08 12:50:21 -0500337// A timeoutConn implements an idle timeout on each Read and Write operation.
338type timeoutConn struct {
339 net.Conn
340 timeout time.Duration
341}
342
343func (t *timeoutConn) Read(b []byte) (int, error) {
344 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
345 return 0, err
346 }
347 return t.Conn.Read(b)
348}
349
350func (t *timeoutConn) Write(b []byte) (int, error) {
351 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
352 return 0, err
353 }
354 return t.Conn.Write(b)
355}
356
David Benjamin8e6db492015-07-25 18:29:23 -0400357func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin01784b42016-06-07 18:00:52 -0400358 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500359
David Benjamin6fd297b2014-08-11 18:43:38 -0400360 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500361 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
362 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500363 }
364
David Benjamin9867b7d2016-03-01 23:25:48 -0500365 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500366 local, peer := "client", "server"
367 if test.testType == clientTest {
368 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500369 }
David Benjaminebda9b32015-11-02 15:33:18 -0500370 connDebug := &recordingConn{
371 Conn: conn,
372 isDatagram: test.protocol == dtls,
373 local: local,
374 peer: peer,
375 }
376 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500377 if *flagDebug {
378 defer connDebug.WriteTo(os.Stdout)
379 }
380 if len(*transcriptDir) != 0 {
381 defer func() {
382 writeTranscript(test, isResume, connDebug.Transcript())
383 }()
384 }
David Benjaminebda9b32015-11-02 15:33:18 -0500385
386 if config.Bugs.PacketAdaptor != nil {
387 config.Bugs.PacketAdaptor.debug = connDebug
388 }
389 }
390
391 if test.replayWrites {
392 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400393 }
394
David Benjamin3ed59772016-03-08 12:50:21 -0500395 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500396 if test.damageFirstWrite {
397 connDamage = newDamageAdaptor(conn)
398 conn = connDamage
399 }
400
David Benjamin6fd297b2014-08-11 18:43:38 -0400401 if test.sendPrefix != "" {
402 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
403 return err
404 }
David Benjamin98e882e2014-08-08 13:24:34 -0400405 }
406
David Benjamin1d5c83e2014-07-22 19:20:02 -0400407 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400408 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400409 if test.protocol == dtls {
410 tlsConn = DTLSServer(conn, config)
411 } else {
412 tlsConn = Server(conn, config)
413 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400414 } else {
415 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400416 if test.protocol == dtls {
417 tlsConn = DTLSClient(conn, config)
418 } else {
419 tlsConn = Client(conn, config)
420 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400421 }
David Benjamin30789da2015-08-29 22:56:45 -0400422 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400423
Adam Langley95c29f32014-06-20 12:00:00 -0700424 if err := tlsConn.Handshake(); err != nil {
425 return err
426 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700427
David Benjamin01fe8202014-09-24 15:21:44 -0400428 // TODO(davidben): move all per-connection expectations into a dedicated
429 // expectations struct that can be specified separately for the two
430 // legs.
431 expectedVersion := test.expectedVersion
432 if isResume && test.expectedResumeVersion != 0 {
433 expectedVersion = test.expectedResumeVersion
434 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700435 connState := tlsConn.ConnectionState()
436 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400437 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400438 }
439
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700440 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400441 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
442 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700443 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
444 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
445 }
David Benjamin90da8c82015-04-20 14:57:57 -0400446
David Benjamina08e49d2014-08-24 01:46:07 -0400447 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700448 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400449 if channelID == nil {
450 return fmt.Errorf("no channel ID negotiated")
451 }
452 if channelID.Curve != channelIDKey.Curve ||
453 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
454 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
455 return fmt.Errorf("incorrect channel ID")
456 }
457 }
458
David Benjaminae2888f2014-09-06 12:58:58 -0400459 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700460 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400461 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
462 }
463 }
464
David Benjaminc7ce9772015-10-09 19:32:41 -0400465 if test.expectNoNextProto {
466 if actual := connState.NegotiatedProtocol; actual != "" {
467 return fmt.Errorf("got unexpected next proto %s", actual)
468 }
469 }
470
David Benjaminfc7b0862014-09-06 13:21:53 -0400471 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700472 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400473 return fmt.Errorf("next proto type mismatch")
474 }
475 }
476
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700477 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500478 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
479 }
480
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100481 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
482 return fmt.Errorf("OCSP Response mismatch")
483 }
484
Paul Lietar4fac72e2015-09-09 13:44:55 +0100485 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
486 return fmt.Errorf("SCT list mismatch")
487 }
488
Nick Harper60edffd2016-06-21 15:19:24 -0700489 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
490 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400491 }
492
David Benjaminc565ebb2015-04-03 04:06:36 -0400493 if test.exportKeyingMaterial > 0 {
494 actual := make([]byte, test.exportKeyingMaterial)
495 if _, err := io.ReadFull(tlsConn, actual); err != nil {
496 return err
497 }
498 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
499 if err != nil {
500 return err
501 }
502 if !bytes.Equal(actual, expected) {
503 return fmt.Errorf("keying material mismatch")
504 }
505 }
506
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700507 if test.testTLSUnique {
508 var peersValue [12]byte
509 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
510 return err
511 }
512 expected := tlsConn.ConnectionState().TLSUnique
513 if !bytes.Equal(peersValue[:], expected) {
514 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
515 }
516 }
517
David Benjamine58c4f52014-08-24 03:47:07 -0400518 if test.shimWritesFirst {
519 var buf [5]byte
520 _, err := io.ReadFull(tlsConn, buf[:])
521 if err != nil {
522 return err
523 }
524 if string(buf[:]) != "hello" {
525 return fmt.Errorf("bad initial message")
526 }
527 }
528
David Benjamina8ebe222015-06-06 03:04:39 -0400529 for i := 0; i < test.sendEmptyRecords; i++ {
530 tlsConn.Write(nil)
531 }
532
David Benjamin24f346d2015-06-06 03:28:08 -0400533 for i := 0; i < test.sendWarningAlerts; i++ {
534 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
535 }
536
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400537 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700538 if test.renegotiateCiphers != nil {
539 config.CipherSuites = test.renegotiateCiphers
540 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400541 for i := 0; i < test.renegotiate; i++ {
542 if err := tlsConn.Renegotiate(); err != nil {
543 return err
544 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700545 }
546 } else if test.renegotiateCiphers != nil {
547 panic("renegotiateCiphers without renegotiate")
548 }
549
David Benjamin5fa3eba2015-01-22 16:35:40 -0500550 if test.damageFirstWrite {
551 connDamage.setDamage(true)
552 tlsConn.Write([]byte("DAMAGED WRITE"))
553 connDamage.setDamage(false)
554 }
555
David Benjamin8e6db492015-07-25 18:29:23 -0400556 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700557 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400558 if test.protocol == dtls {
559 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
560 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700561 // Read until EOF.
562 _, err := io.Copy(ioutil.Discard, tlsConn)
563 return err
564 }
David Benjamin4417d052015-04-05 04:17:25 -0400565 if messageLen == 0 {
566 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700567 }
Adam Langley95c29f32014-06-20 12:00:00 -0700568
David Benjamin8e6db492015-07-25 18:29:23 -0400569 messageCount := test.messageCount
570 if messageCount == 0 {
571 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400572 }
573
David Benjamin8e6db492015-07-25 18:29:23 -0400574 for j := 0; j < messageCount; j++ {
575 testMessage := make([]byte, messageLen)
576 for i := range testMessage {
577 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400578 }
David Benjamin8e6db492015-07-25 18:29:23 -0400579 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700580
David Benjamin8e6db492015-07-25 18:29:23 -0400581 for i := 0; i < test.sendEmptyRecords; i++ {
582 tlsConn.Write(nil)
583 }
584
585 for i := 0; i < test.sendWarningAlerts; i++ {
586 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
587 }
588
David Benjamin4f75aaf2015-09-01 16:53:10 -0400589 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400590 // The shim will not respond.
591 continue
592 }
593
David Benjamin8e6db492015-07-25 18:29:23 -0400594 buf := make([]byte, len(testMessage))
595 if test.protocol == dtls {
596 bufTmp := make([]byte, len(buf)+1)
597 n, err := tlsConn.Read(bufTmp)
598 if err != nil {
599 return err
600 }
601 if n != len(buf) {
602 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
603 }
604 copy(buf, bufTmp)
605 } else {
606 _, err := io.ReadFull(tlsConn, buf)
607 if err != nil {
608 return err
609 }
610 }
611
612 for i, v := range buf {
613 if v != testMessage[i]^0xff {
614 return fmt.Errorf("bad reply contents at byte %d", i)
615 }
Adam Langley95c29f32014-06-20 12:00:00 -0700616 }
617 }
618
619 return nil
620}
621
David Benjamin325b5c32014-07-01 19:40:31 -0400622func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
623 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700624 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400625 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700626 }
David Benjamin325b5c32014-07-01 19:40:31 -0400627 valgrindArgs = append(valgrindArgs, path)
628 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700629
David Benjamin325b5c32014-07-01 19:40:31 -0400630 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700631}
632
David Benjamin325b5c32014-07-01 19:40:31 -0400633func gdbOf(path string, args ...string) *exec.Cmd {
634 xtermArgs := []string{"-e", "gdb", "--args"}
635 xtermArgs = append(xtermArgs, path)
636 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700637
David Benjamin325b5c32014-07-01 19:40:31 -0400638 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700639}
640
David Benjamind16bf342015-12-18 00:53:12 -0500641func lldbOf(path string, args ...string) *exec.Cmd {
642 xtermArgs := []string{"-e", "lldb", "--"}
643 xtermArgs = append(xtermArgs, path)
644 xtermArgs = append(xtermArgs, args...)
645
646 return exec.Command("xterm", xtermArgs...)
647}
648
Adam Langley69a01602014-11-17 17:26:55 -0800649type moreMallocsError struct{}
650
651func (moreMallocsError) Error() string {
652 return "child process did not exhaust all allocation calls"
653}
654
655var errMoreMallocs = moreMallocsError{}
656
David Benjamin87c8a642015-02-21 01:54:29 -0500657// accept accepts a connection from listener, unless waitChan signals a process
658// exit first.
659func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
660 type connOrError struct {
661 conn net.Conn
662 err error
663 }
664 connChan := make(chan connOrError, 1)
665 go func() {
666 conn, err := listener.Accept()
667 connChan <- connOrError{conn, err}
668 close(connChan)
669 }()
670 select {
671 case result := <-connChan:
672 return result.conn, result.err
673 case childErr := <-waitChan:
674 waitChan <- childErr
675 return nil, fmt.Errorf("child exited early: %s", childErr)
676 }
677}
678
Adam Langley7c803a62015-06-15 15:35:05 -0700679func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700680 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
681 panic("Error expected without shouldFail in " + test.name)
682 }
683
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700684 if test.expectResumeRejected && !test.resumeSession {
685 panic("expectResumeRejected without resumeSession in " + test.name)
686 }
687
David Benjamin87c8a642015-02-21 01:54:29 -0500688 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
689 if err != nil {
690 panic(err)
691 }
692 defer func() {
693 if listener != nil {
694 listener.Close()
695 }
696 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700697
David Benjamin87c8a642015-02-21 01:54:29 -0500698 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400699 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400700 flags = append(flags, "-server")
701
David Benjamin025b3d32014-07-01 19:53:04 -0400702 flags = append(flags, "-key-file")
703 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700704 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400705 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700706 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400707 }
708
709 flags = append(flags, "-cert-file")
710 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700711 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400712 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700713 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400714 }
715 }
David Benjamin5a593af2014-08-11 19:51:50 -0400716
Steven Valdez0d62f262015-09-04 12:41:04 -0400717 if test.digestPrefs != "" {
718 flags = append(flags, "-digest-prefs")
719 flags = append(flags, test.digestPrefs)
720 }
721
David Benjamin6fd297b2014-08-11 18:43:38 -0400722 if test.protocol == dtls {
723 flags = append(flags, "-dtls")
724 }
725
David Benjamin5a593af2014-08-11 19:51:50 -0400726 if test.resumeSession {
727 flags = append(flags, "-resume")
728 }
729
David Benjamine58c4f52014-08-24 03:47:07 -0400730 if test.shimWritesFirst {
731 flags = append(flags, "-shim-writes-first")
732 }
733
David Benjamin30789da2015-08-29 22:56:45 -0400734 if test.shimShutsDown {
735 flags = append(flags, "-shim-shuts-down")
736 }
737
David Benjaminc565ebb2015-04-03 04:06:36 -0400738 if test.exportKeyingMaterial > 0 {
739 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
740 flags = append(flags, "-export-label", test.exportLabel)
741 flags = append(flags, "-export-context", test.exportContext)
742 if test.useExportContext {
743 flags = append(flags, "-use-export-context")
744 }
745 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700746 if test.expectResumeRejected {
747 flags = append(flags, "-expect-session-miss")
748 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400749
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700750 if test.testTLSUnique {
751 flags = append(flags, "-tls-unique")
752 }
753
David Benjamin025b3d32014-07-01 19:53:04 -0400754 flags = append(flags, test.flags...)
755
756 var shim *exec.Cmd
757 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700758 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700759 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700760 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500761 } else if *useLLDB {
762 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400763 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700764 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400765 }
David Benjamin025b3d32014-07-01 19:53:04 -0400766 shim.Stdin = os.Stdin
767 var stdoutBuf, stderrBuf bytes.Buffer
768 shim.Stdout = &stdoutBuf
769 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800770 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500771 shim.Env = os.Environ()
772 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800773 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400774 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800775 }
776 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
777 }
David Benjamin025b3d32014-07-01 19:53:04 -0400778
779 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700780 panic(err)
781 }
David Benjamin87c8a642015-02-21 01:54:29 -0500782 waitChan := make(chan error, 1)
783 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700784
785 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400786 if !test.noSessionCache {
787 config.ClientSessionCache = NewLRUClientSessionCache(1)
788 config.ServerSessionCache = NewLRUServerSessionCache(1)
789 }
David Benjamin025b3d32014-07-01 19:53:04 -0400790 if test.testType == clientTest {
791 if len(config.Certificates) == 0 {
792 config.Certificates = []Certificate{getRSACertificate()}
793 }
David Benjamin87c8a642015-02-21 01:54:29 -0500794 } else {
795 // Supply a ServerName to ensure a constant session cache key,
796 // rather than falling back to net.Conn.RemoteAddr.
797 if len(config.ServerName) == 0 {
798 config.ServerName = "test"
799 }
David Benjamin025b3d32014-07-01 19:53:04 -0400800 }
David Benjaminf2b83632016-03-01 22:57:46 -0500801 if *fuzzer {
802 config.Bugs.NullAllCiphers = true
803 }
David Benjamin2e045a92016-06-08 13:09:56 -0400804 if *deterministic {
805 config.Rand = &deterministicRand{}
806 }
Adam Langley95c29f32014-06-20 12:00:00 -0700807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 conn, err := acceptOrWait(listener, waitChan)
809 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400810 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500811 conn.Close()
812 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500813
David Benjamin1d5c83e2014-07-22 19:20:02 -0400814 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400815 var resumeConfig Config
816 if test.resumeConfig != nil {
817 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500818 if len(resumeConfig.ServerName) == 0 {
819 resumeConfig.ServerName = config.ServerName
820 }
David Benjamin01fe8202014-09-24 15:21:44 -0400821 if len(resumeConfig.Certificates) == 0 {
822 resumeConfig.Certificates = []Certificate{getRSACertificate()}
823 }
David Benjaminba4594a2015-06-18 18:36:15 -0400824 if test.newSessionsOnResume {
825 if !test.noSessionCache {
826 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
827 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
828 }
829 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500830 resumeConfig.SessionTicketKey = config.SessionTicketKey
831 resumeConfig.ClientSessionCache = config.ClientSessionCache
832 resumeConfig.ServerSessionCache = config.ServerSessionCache
833 }
David Benjaminf2b83632016-03-01 22:57:46 -0500834 if *fuzzer {
835 resumeConfig.Bugs.NullAllCiphers = true
836 }
David Benjamin2e045a92016-06-08 13:09:56 -0400837 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400838 } else {
839 resumeConfig = config
840 }
David Benjamin87c8a642015-02-21 01:54:29 -0500841 var connResume net.Conn
842 connResume, err = acceptOrWait(listener, waitChan)
843 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400844 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500845 connResume.Close()
846 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400847 }
848
David Benjamin87c8a642015-02-21 01:54:29 -0500849 // Close the listener now. This is to avoid hangs should the shim try to
850 // open more connections than expected.
851 listener.Close()
852 listener = nil
853
854 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800855 if exitError, ok := childErr.(*exec.ExitError); ok {
856 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
857 return errMoreMallocs
858 }
859 }
Adam Langley95c29f32014-06-20 12:00:00 -0700860
David Benjamin9bea3492016-03-02 10:59:16 -0500861 // Account for Windows line endings.
862 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
863 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500864
865 // Separate the errors from the shim and those from tools like
866 // AddressSanitizer.
867 var extraStderr string
868 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
869 stderr = stderrParts[0]
870 extraStderr = stderrParts[1]
871 }
872
Adam Langley95c29f32014-06-20 12:00:00 -0700873 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400874 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700875 localError := "none"
876 if err != nil {
877 localError = err.Error()
878 }
879 if len(test.expectedLocalError) != 0 {
880 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
881 }
Adam Langley95c29f32014-06-20 12:00:00 -0700882
883 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700884 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700885 if childErr != nil {
886 childError = childErr.Error()
887 }
888
889 var msg string
890 switch {
891 case failed && !test.shouldFail:
892 msg = "unexpected failure"
893 case !failed && test.shouldFail:
894 msg = "unexpected success"
895 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700896 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700897 default:
898 panic("internal error")
899 }
900
David Benjaminc565ebb2015-04-03 04:06:36 -0400901 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700902 }
903
David Benjaminff3a1492016-03-02 10:12:06 -0500904 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
905 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700906 }
907
908 return nil
909}
910
911var tlsVersions = []struct {
912 name string
913 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400914 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500915 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700916}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500917 {"SSL3", VersionSSL30, "-no-ssl3", false},
918 {"TLS1", VersionTLS10, "-no-tls1", true},
919 {"TLS11", VersionTLS11, "-no-tls11", false},
920 {"TLS12", VersionTLS12, "-no-tls12", true},
Nick Harper1fd39d82016-06-14 18:14:35 -0700921 // TODO(nharper): Once we have a real implementation of TLS 1.3, update the name here.
922 {"FakeTLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -0700923}
924
925var testCipherSuites = []struct {
926 name string
927 id uint16
928}{
929 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400930 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700931 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400932 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400933 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700934 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400935 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400936 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
937 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400938 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400939 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
940 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400941 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700942 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
943 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400944 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
945 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700946 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400947 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500948 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500949 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700950 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700951 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700952 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400953 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400954 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700955 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400956 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500957 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500958 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700959 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
Matt Braithwaite053931e2016-05-25 12:06:05 -0700960 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
961 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
962 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
963 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400964 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
965 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700966 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
967 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500968 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -0400969 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
970 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -0400971 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700972 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400973 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700974 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700975}
976
David Benjamin8b8c0062014-11-23 02:47:52 -0500977func hasComponent(suiteName, component string) bool {
978 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
979}
980
David Benjaminf7768e42014-08-31 02:06:47 -0400981func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500982 return hasComponent(suiteName, "GCM") ||
983 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400984 hasComponent(suiteName, "SHA384") ||
985 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500986}
987
Nick Harper1fd39d82016-06-14 18:14:35 -0700988func isTLS13Suite(suiteName string) bool {
989 return (hasComponent(suiteName, "GCM") || hasComponent(suiteName, "POLY1305")) && hasComponent(suiteName, "ECDHE") && !hasComponent(suiteName, "OLD")
990}
991
David Benjamin8b8c0062014-11-23 02:47:52 -0500992func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700993 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400994}
995
Adam Langleya7997f12015-05-14 17:38:50 -0700996func bigFromHex(hex string) *big.Int {
997 ret, ok := new(big.Int).SetString(hex, 16)
998 if !ok {
999 panic("failed to parse hex number 0x" + hex)
1000 }
1001 return ret
1002}
1003
Adam Langley7c803a62015-06-15 15:35:05 -07001004func addBasicTests() {
1005 basicTests := []testCase{
1006 {
1007 name: "BadRSASignature",
1008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001009 // TODO(davidben): Add a TLS 1.3 version of this.
1010 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001011 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1012 Bugs: ProtocolBugs{
1013 InvalidSKXSignature: true,
1014 },
1015 },
1016 shouldFail: true,
1017 expectedError: ":BAD_SIGNATURE:",
1018 },
1019 {
1020 name: "BadECDSASignature",
1021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001022 // TODO(davidben): Add a TLS 1.3 version of this.
1023 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001024 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1025 Bugs: ProtocolBugs{
1026 InvalidSKXSignature: true,
1027 },
1028 Certificates: []Certificate{getECDSACertificate()},
1029 },
1030 shouldFail: true,
1031 expectedError: ":BAD_SIGNATURE:",
1032 },
1033 {
David Benjamin6de0e532015-07-28 22:43:19 -04001034 testType: serverTest,
1035 name: "BadRSASignature-ClientAuth",
1036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001037 // TODO(davidben): Add a TLS 1.3 version of this.
1038 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001039 Bugs: ProtocolBugs{
1040 InvalidCertVerifySignature: true,
1041 },
1042 Certificates: []Certificate{getRSACertificate()},
1043 },
1044 shouldFail: true,
1045 expectedError: ":BAD_SIGNATURE:",
1046 flags: []string{"-require-any-client-certificate"},
1047 },
1048 {
1049 testType: serverTest,
1050 name: "BadECDSASignature-ClientAuth",
1051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001052 // TODO(davidben): Add a TLS 1.3 version of this.
1053 MaxVersion: VersionTLS12,
David Benjamin6de0e532015-07-28 22:43:19 -04001054 Bugs: ProtocolBugs{
1055 InvalidCertVerifySignature: true,
1056 },
1057 Certificates: []Certificate{getECDSACertificate()},
1058 },
1059 shouldFail: true,
1060 expectedError: ":BAD_SIGNATURE:",
1061 flags: []string{"-require-any-client-certificate"},
1062 },
1063 {
Adam Langley7c803a62015-06-15 15:35:05 -07001064 name: "NoFallbackSCSV",
1065 config: Config{
1066 Bugs: ProtocolBugs{
1067 FailIfNotFallbackSCSV: true,
1068 },
1069 },
1070 shouldFail: true,
1071 expectedLocalError: "no fallback SCSV found",
1072 },
1073 {
1074 name: "SendFallbackSCSV",
1075 config: Config{
1076 Bugs: ProtocolBugs{
1077 FailIfNotFallbackSCSV: true,
1078 },
1079 },
1080 flags: []string{"-fallback-scsv"},
1081 },
1082 {
1083 name: "ClientCertificateTypes",
1084 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001085 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001086 ClientAuth: RequestClientCert,
1087 ClientCertificateTypes: []byte{
1088 CertTypeDSSSign,
1089 CertTypeRSASign,
1090 CertTypeECDSASign,
1091 },
1092 },
1093 flags: []string{
1094 "-expect-certificate-types",
1095 base64.StdEncoding.EncodeToString([]byte{
1096 CertTypeDSSSign,
1097 CertTypeRSASign,
1098 CertTypeECDSASign,
1099 }),
1100 },
1101 },
1102 {
Adam Langley7c803a62015-06-15 15:35:05 -07001103 name: "UnauthenticatedECDH",
1104 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001105 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001106 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1107 Bugs: ProtocolBugs{
1108 UnauthenticatedECDH: true,
1109 },
1110 },
1111 shouldFail: true,
1112 expectedError: ":UNEXPECTED_MESSAGE:",
1113 },
1114 {
1115 name: "SkipCertificateStatus",
1116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001117 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001118 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1119 Bugs: ProtocolBugs{
1120 SkipCertificateStatus: true,
1121 },
1122 },
1123 flags: []string{
1124 "-enable-ocsp-stapling",
1125 },
1126 },
1127 {
1128 name: "SkipServerKeyExchange",
1129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001130 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001131 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1132 Bugs: ProtocolBugs{
1133 SkipServerKeyExchange: true,
1134 },
1135 },
1136 shouldFail: true,
1137 expectedError: ":UNEXPECTED_MESSAGE:",
1138 },
1139 {
1140 name: "SkipChangeCipherSpec-Client",
1141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001142 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001143 Bugs: ProtocolBugs{
1144 SkipChangeCipherSpec: true,
1145 },
1146 },
1147 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001148 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001149 },
1150 {
1151 testType: serverTest,
1152 name: "SkipChangeCipherSpec-Server",
1153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001154 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001155 Bugs: ProtocolBugs{
1156 SkipChangeCipherSpec: true,
1157 },
1158 },
1159 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001160 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001161 },
1162 {
1163 testType: serverTest,
1164 name: "SkipChangeCipherSpec-Server-NPN",
1165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001166 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001167 NextProtos: []string{"bar"},
1168 Bugs: ProtocolBugs{
1169 SkipChangeCipherSpec: true,
1170 },
1171 },
1172 flags: []string{
1173 "-advertise-npn", "\x03foo\x03bar\x03baz",
1174 },
1175 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001176 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001177 },
1178 {
1179 name: "FragmentAcrossChangeCipherSpec-Client",
1180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001181 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001182 Bugs: ProtocolBugs{
1183 FragmentAcrossChangeCipherSpec: true,
1184 },
1185 },
1186 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001187 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001188 },
1189 {
1190 testType: serverTest,
1191 name: "FragmentAcrossChangeCipherSpec-Server",
1192 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001193 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001194 Bugs: ProtocolBugs{
1195 FragmentAcrossChangeCipherSpec: true,
1196 },
1197 },
1198 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001199 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001200 },
1201 {
1202 testType: serverTest,
1203 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1204 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001205 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001206 NextProtos: []string{"bar"},
1207 Bugs: ProtocolBugs{
1208 FragmentAcrossChangeCipherSpec: true,
1209 },
1210 },
1211 flags: []string{
1212 "-advertise-npn", "\x03foo\x03bar\x03baz",
1213 },
1214 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001215 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001216 },
1217 {
1218 testType: serverTest,
1219 name: "Alert",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 SendSpuriousAlert: alertRecordOverflow,
1223 },
1224 },
1225 shouldFail: true,
1226 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1227 },
1228 {
1229 protocol: dtls,
1230 testType: serverTest,
1231 name: "Alert-DTLS",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 SendSpuriousAlert: alertRecordOverflow,
1235 },
1236 },
1237 shouldFail: true,
1238 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1239 },
1240 {
1241 testType: serverTest,
1242 name: "FragmentAlert",
1243 config: Config{
1244 Bugs: ProtocolBugs{
1245 FragmentAlert: true,
1246 SendSpuriousAlert: alertRecordOverflow,
1247 },
1248 },
1249 shouldFail: true,
1250 expectedError: ":BAD_ALERT:",
1251 },
1252 {
1253 protocol: dtls,
1254 testType: serverTest,
1255 name: "FragmentAlert-DTLS",
1256 config: Config{
1257 Bugs: ProtocolBugs{
1258 FragmentAlert: true,
1259 SendSpuriousAlert: alertRecordOverflow,
1260 },
1261 },
1262 shouldFail: true,
1263 expectedError: ":BAD_ALERT:",
1264 },
1265 {
1266 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001267 name: "DoubleAlert",
1268 config: Config{
1269 Bugs: ProtocolBugs{
1270 DoubleAlert: true,
1271 SendSpuriousAlert: alertRecordOverflow,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":BAD_ALERT:",
1276 },
1277 {
1278 protocol: dtls,
1279 testType: serverTest,
1280 name: "DoubleAlert-DTLS",
1281 config: Config{
1282 Bugs: ProtocolBugs{
1283 DoubleAlert: true,
1284 SendSpuriousAlert: alertRecordOverflow,
1285 },
1286 },
1287 shouldFail: true,
1288 expectedError: ":BAD_ALERT:",
1289 },
1290 {
1291 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001292 name: "EarlyChangeCipherSpec-server-1",
1293 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001294 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001295 Bugs: ProtocolBugs{
1296 EarlyChangeCipherSpec: 1,
1297 },
1298 },
1299 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001300 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001301 },
1302 {
1303 testType: serverTest,
1304 name: "EarlyChangeCipherSpec-server-2",
1305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001306 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 Bugs: ProtocolBugs{
1308 EarlyChangeCipherSpec: 2,
1309 },
1310 },
1311 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001312 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001313 },
1314 {
David Benjamin8144f992016-06-22 17:05:13 -04001315 protocol: dtls,
1316 name: "StrayChangeCipherSpec",
1317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001318 // TODO(davidben): Once DTLS 1.3 exists, test
1319 // that stray ChangeCipherSpec messages are
1320 // rejected.
1321 MaxVersion: VersionTLS12,
David Benjamin8144f992016-06-22 17:05:13 -04001322 Bugs: ProtocolBugs{
1323 StrayChangeCipherSpec: true,
1324 },
1325 },
1326 },
1327 {
Adam Langley7c803a62015-06-15 15:35:05 -07001328 name: "SkipNewSessionTicket",
1329 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001330 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001331 Bugs: ProtocolBugs{
1332 SkipNewSessionTicket: true,
1333 },
1334 },
1335 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001336 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001337 },
1338 {
1339 testType: serverTest,
1340 name: "FallbackSCSV",
1341 config: Config{
1342 MaxVersion: VersionTLS11,
1343 Bugs: ProtocolBugs{
1344 SendFallbackSCSV: true,
1345 },
1346 },
1347 shouldFail: true,
1348 expectedError: ":INAPPROPRIATE_FALLBACK:",
1349 },
1350 {
1351 testType: serverTest,
1352 name: "FallbackSCSV-VersionMatch",
1353 config: Config{
1354 Bugs: ProtocolBugs{
1355 SendFallbackSCSV: true,
1356 },
1357 },
1358 },
1359 {
1360 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001361 name: "FallbackSCSV-VersionMatch-TLS12",
1362 config: Config{
1363 MaxVersion: VersionTLS12,
1364 Bugs: ProtocolBugs{
1365 SendFallbackSCSV: true,
1366 },
1367 },
1368 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1369 },
1370 {
1371 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001372 name: "FragmentedClientVersion",
1373 config: Config{
1374 Bugs: ProtocolBugs{
1375 MaxHandshakeRecordLength: 1,
1376 FragmentClientVersion: true,
1377 },
1378 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001379 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001380 },
1381 {
Adam Langley7c803a62015-06-15 15:35:05 -07001382 testType: serverTest,
1383 name: "HttpGET",
1384 sendPrefix: "GET / HTTP/1.0\n",
1385 shouldFail: true,
1386 expectedError: ":HTTP_REQUEST:",
1387 },
1388 {
1389 testType: serverTest,
1390 name: "HttpPOST",
1391 sendPrefix: "POST / HTTP/1.0\n",
1392 shouldFail: true,
1393 expectedError: ":HTTP_REQUEST:",
1394 },
1395 {
1396 testType: serverTest,
1397 name: "HttpHEAD",
1398 sendPrefix: "HEAD / HTTP/1.0\n",
1399 shouldFail: true,
1400 expectedError: ":HTTP_REQUEST:",
1401 },
1402 {
1403 testType: serverTest,
1404 name: "HttpPUT",
1405 sendPrefix: "PUT / HTTP/1.0\n",
1406 shouldFail: true,
1407 expectedError: ":HTTP_REQUEST:",
1408 },
1409 {
1410 testType: serverTest,
1411 name: "HttpCONNECT",
1412 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1413 shouldFail: true,
1414 expectedError: ":HTTPS_PROXY_REQUEST:",
1415 },
1416 {
1417 testType: serverTest,
1418 name: "Garbage",
1419 sendPrefix: "blah",
1420 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001421 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001422 },
1423 {
Adam Langley7c803a62015-06-15 15:35:05 -07001424 name: "RSAEphemeralKey",
1425 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001426 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001427 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1428 Bugs: ProtocolBugs{
1429 RSAEphemeralKey: true,
1430 },
1431 },
1432 shouldFail: true,
1433 expectedError: ":UNEXPECTED_MESSAGE:",
1434 },
1435 {
1436 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001437 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001438 shouldFail: true,
1439 expectedError: ":WRONG_SSL_VERSION:",
1440 },
1441 {
1442 protocol: dtls,
1443 name: "DisableEverything-DTLS",
1444 flags: []string{"-no-tls12", "-no-tls1"},
1445 shouldFail: true,
1446 expectedError: ":WRONG_SSL_VERSION:",
1447 },
1448 {
Adam Langley7c803a62015-06-15 15:35:05 -07001449 protocol: dtls,
1450 testType: serverTest,
1451 name: "MTU",
1452 config: Config{
1453 Bugs: ProtocolBugs{
1454 MaxPacketLength: 256,
1455 },
1456 },
1457 flags: []string{"-mtu", "256"},
1458 },
1459 {
1460 protocol: dtls,
1461 testType: serverTest,
1462 name: "MTUExceeded",
1463 config: Config{
1464 Bugs: ProtocolBugs{
1465 MaxPacketLength: 255,
1466 },
1467 },
1468 flags: []string{"-mtu", "256"},
1469 shouldFail: true,
1470 expectedLocalError: "dtls: exceeded maximum packet length",
1471 },
1472 {
1473 name: "CertMismatchRSA",
1474 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001475 // TODO(davidben): Add a TLS 1.3 version of this test.
1476 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001477 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1478 Certificates: []Certificate{getECDSACertificate()},
1479 Bugs: ProtocolBugs{
1480 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1485 },
1486 {
1487 name: "CertMismatchECDSA",
1488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001489 // TODO(davidben): Add a TLS 1.3 version of this test.
1490 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1492 Certificates: []Certificate{getRSACertificate()},
1493 Bugs: ProtocolBugs{
1494 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1495 },
1496 },
1497 shouldFail: true,
1498 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1499 },
1500 {
1501 name: "EmptyCertificateList",
1502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001503 // TODO(davidben): Add a TLS 1.3 version of this test.
1504 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001505 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1506 Bugs: ProtocolBugs{
1507 EmptyCertificateList: true,
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":DECODE_ERROR:",
1512 },
1513 {
1514 name: "TLSFatalBadPackets",
1515 damageFirstWrite: true,
1516 shouldFail: true,
1517 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1518 },
1519 {
1520 protocol: dtls,
1521 name: "DTLSIgnoreBadPackets",
1522 damageFirstWrite: true,
1523 },
1524 {
1525 protocol: dtls,
1526 name: "DTLSIgnoreBadPackets-Async",
1527 damageFirstWrite: true,
1528 flags: []string{"-async"},
1529 },
1530 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001531 name: "AppDataBeforeHandshake",
1532 config: Config{
1533 Bugs: ProtocolBugs{
1534 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1535 },
1536 },
1537 shouldFail: true,
1538 expectedError: ":UNEXPECTED_RECORD:",
1539 },
1540 {
1541 name: "AppDataBeforeHandshake-Empty",
1542 config: Config{
1543 Bugs: ProtocolBugs{
1544 AppDataBeforeHandshake: []byte{},
1545 },
1546 },
1547 shouldFail: true,
1548 expectedError: ":UNEXPECTED_RECORD:",
1549 },
1550 {
1551 protocol: dtls,
1552 name: "AppDataBeforeHandshake-DTLS",
1553 config: Config{
1554 Bugs: ProtocolBugs{
1555 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1556 },
1557 },
1558 shouldFail: true,
1559 expectedError: ":UNEXPECTED_RECORD:",
1560 },
1561 {
1562 protocol: dtls,
1563 name: "AppDataBeforeHandshake-DTLS-Empty",
1564 config: Config{
1565 Bugs: ProtocolBugs{
1566 AppDataBeforeHandshake: []byte{},
1567 },
1568 },
1569 shouldFail: true,
1570 expectedError: ":UNEXPECTED_RECORD:",
1571 },
1572 {
Adam Langley7c803a62015-06-15 15:35:05 -07001573 name: "AppDataAfterChangeCipherSpec",
1574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001575 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001576 Bugs: ProtocolBugs{
1577 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1578 },
1579 },
1580 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001581 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001582 },
1583 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001584 name: "AppDataAfterChangeCipherSpec-Empty",
1585 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001586 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001587 Bugs: ProtocolBugs{
1588 AppDataAfterChangeCipherSpec: []byte{},
1589 },
1590 },
1591 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001592 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001593 },
1594 {
Adam Langley7c803a62015-06-15 15:35:05 -07001595 protocol: dtls,
1596 name: "AppDataAfterChangeCipherSpec-DTLS",
1597 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001598 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001599 Bugs: ProtocolBugs{
1600 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1601 },
1602 },
1603 // BoringSSL's DTLS implementation will drop the out-of-order
1604 // application data.
1605 },
1606 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001607 protocol: dtls,
1608 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001610 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001611 Bugs: ProtocolBugs{
1612 AppDataAfterChangeCipherSpec: []byte{},
1613 },
1614 },
1615 // BoringSSL's DTLS implementation will drop the out-of-order
1616 // application data.
1617 },
1618 {
Adam Langley7c803a62015-06-15 15:35:05 -07001619 name: "AlertAfterChangeCipherSpec",
1620 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001621 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001622 Bugs: ProtocolBugs{
1623 AlertAfterChangeCipherSpec: alertRecordOverflow,
1624 },
1625 },
1626 shouldFail: true,
1627 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1628 },
1629 {
1630 protocol: dtls,
1631 name: "AlertAfterChangeCipherSpec-DTLS",
1632 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001633 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001634 Bugs: ProtocolBugs{
1635 AlertAfterChangeCipherSpec: alertRecordOverflow,
1636 },
1637 },
1638 shouldFail: true,
1639 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1640 },
1641 {
1642 protocol: dtls,
1643 name: "ReorderHandshakeFragments-Small-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 ReorderHandshakeFragments: true,
1647 // Small enough that every handshake message is
1648 // fragmented.
1649 MaxHandshakeRecordLength: 2,
1650 },
1651 },
1652 },
1653 {
1654 protocol: dtls,
1655 name: "ReorderHandshakeFragments-Large-DTLS",
1656 config: Config{
1657 Bugs: ProtocolBugs{
1658 ReorderHandshakeFragments: true,
1659 // Large enough that no handshake message is
1660 // fragmented.
1661 MaxHandshakeRecordLength: 2048,
1662 },
1663 },
1664 },
1665 {
1666 protocol: dtls,
1667 name: "MixCompleteMessageWithFragments-DTLS",
1668 config: Config{
1669 Bugs: ProtocolBugs{
1670 ReorderHandshakeFragments: true,
1671 MixCompleteMessageWithFragments: true,
1672 MaxHandshakeRecordLength: 2,
1673 },
1674 },
1675 },
1676 {
1677 name: "SendInvalidRecordType",
1678 config: Config{
1679 Bugs: ProtocolBugs{
1680 SendInvalidRecordType: true,
1681 },
1682 },
1683 shouldFail: true,
1684 expectedError: ":UNEXPECTED_RECORD:",
1685 },
1686 {
1687 protocol: dtls,
1688 name: "SendInvalidRecordType-DTLS",
1689 config: Config{
1690 Bugs: ProtocolBugs{
1691 SendInvalidRecordType: true,
1692 },
1693 },
1694 shouldFail: true,
1695 expectedError: ":UNEXPECTED_RECORD:",
1696 },
1697 {
1698 name: "FalseStart-SkipServerSecondLeg",
1699 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001700 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001701 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1702 NextProtos: []string{"foo"},
1703 Bugs: ProtocolBugs{
1704 SkipNewSessionTicket: true,
1705 SkipChangeCipherSpec: true,
1706 SkipFinished: true,
1707 ExpectFalseStart: true,
1708 },
1709 },
1710 flags: []string{
1711 "-false-start",
1712 "-handshake-never-done",
1713 "-advertise-alpn", "\x03foo",
1714 },
1715 shimWritesFirst: true,
1716 shouldFail: true,
1717 expectedError: ":UNEXPECTED_RECORD:",
1718 },
1719 {
1720 name: "FalseStart-SkipServerSecondLeg-Implicit",
1721 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001722 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001723 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1724 NextProtos: []string{"foo"},
1725 Bugs: ProtocolBugs{
1726 SkipNewSessionTicket: true,
1727 SkipChangeCipherSpec: true,
1728 SkipFinished: true,
1729 },
1730 },
1731 flags: []string{
1732 "-implicit-handshake",
1733 "-false-start",
1734 "-handshake-never-done",
1735 "-advertise-alpn", "\x03foo",
1736 },
1737 shouldFail: true,
1738 expectedError: ":UNEXPECTED_RECORD:",
1739 },
1740 {
1741 testType: serverTest,
1742 name: "FailEarlyCallback",
1743 flags: []string{"-fail-early-callback"},
1744 shouldFail: true,
1745 expectedError: ":CONNECTION_REJECTED:",
1746 expectedLocalError: "remote error: access denied",
1747 },
1748 {
1749 name: "WrongMessageType",
1750 config: Config{
1751 Bugs: ProtocolBugs{
1752 WrongCertificateMessageType: true,
1753 },
1754 },
1755 shouldFail: true,
1756 expectedError: ":UNEXPECTED_MESSAGE:",
1757 expectedLocalError: "remote error: unexpected message",
1758 },
1759 {
1760 protocol: dtls,
1761 name: "WrongMessageType-DTLS",
1762 config: Config{
1763 Bugs: ProtocolBugs{
1764 WrongCertificateMessageType: true,
1765 },
1766 },
1767 shouldFail: true,
1768 expectedError: ":UNEXPECTED_MESSAGE:",
1769 expectedLocalError: "remote error: unexpected message",
1770 },
1771 {
1772 protocol: dtls,
1773 name: "FragmentMessageTypeMismatch-DTLS",
1774 config: Config{
1775 Bugs: ProtocolBugs{
1776 MaxHandshakeRecordLength: 2,
1777 FragmentMessageTypeMismatch: true,
1778 },
1779 },
1780 shouldFail: true,
1781 expectedError: ":FRAGMENT_MISMATCH:",
1782 },
1783 {
1784 protocol: dtls,
1785 name: "FragmentMessageLengthMismatch-DTLS",
1786 config: Config{
1787 Bugs: ProtocolBugs{
1788 MaxHandshakeRecordLength: 2,
1789 FragmentMessageLengthMismatch: true,
1790 },
1791 },
1792 shouldFail: true,
1793 expectedError: ":FRAGMENT_MISMATCH:",
1794 },
1795 {
1796 protocol: dtls,
1797 name: "SplitFragments-Header-DTLS",
1798 config: Config{
1799 Bugs: ProtocolBugs{
1800 SplitFragments: 2,
1801 },
1802 },
1803 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001804 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001805 },
1806 {
1807 protocol: dtls,
1808 name: "SplitFragments-Boundary-DTLS",
1809 config: Config{
1810 Bugs: ProtocolBugs{
1811 SplitFragments: dtlsRecordHeaderLen,
1812 },
1813 },
1814 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001815 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001816 },
1817 {
1818 protocol: dtls,
1819 name: "SplitFragments-Body-DTLS",
1820 config: Config{
1821 Bugs: ProtocolBugs{
1822 SplitFragments: dtlsRecordHeaderLen + 1,
1823 },
1824 },
1825 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001826 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001827 },
1828 {
1829 protocol: dtls,
1830 name: "SendEmptyFragments-DTLS",
1831 config: Config{
1832 Bugs: ProtocolBugs{
1833 SendEmptyFragments: true,
1834 },
1835 },
1836 },
1837 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001838 name: "BadFinished-Client",
1839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001840 // TODO(davidben): Add a TLS 1.3 version of this.
1841 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001842 Bugs: ProtocolBugs{
1843 BadFinished: true,
1844 },
1845 },
1846 shouldFail: true,
1847 expectedError: ":DIGEST_CHECK_FAILED:",
1848 },
1849 {
1850 testType: serverTest,
1851 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001852 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001853 // TODO(davidben): Add a TLS 1.3 version of this.
1854 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001855 Bugs: ProtocolBugs{
1856 BadFinished: true,
1857 },
1858 },
1859 shouldFail: true,
1860 expectedError: ":DIGEST_CHECK_FAILED:",
1861 },
1862 {
1863 name: "FalseStart-BadFinished",
1864 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001865 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1867 NextProtos: []string{"foo"},
1868 Bugs: ProtocolBugs{
1869 BadFinished: true,
1870 ExpectFalseStart: true,
1871 },
1872 },
1873 flags: []string{
1874 "-false-start",
1875 "-handshake-never-done",
1876 "-advertise-alpn", "\x03foo",
1877 },
1878 shimWritesFirst: true,
1879 shouldFail: true,
1880 expectedError: ":DIGEST_CHECK_FAILED:",
1881 },
1882 {
1883 name: "NoFalseStart-NoALPN",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1887 Bugs: ProtocolBugs{
1888 ExpectFalseStart: true,
1889 AlertBeforeFalseStartTest: alertAccessDenied,
1890 },
1891 },
1892 flags: []string{
1893 "-false-start",
1894 },
1895 shimWritesFirst: true,
1896 shouldFail: true,
1897 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1898 expectedLocalError: "tls: peer did not false start: EOF",
1899 },
1900 {
1901 name: "NoFalseStart-NoAEAD",
1902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001903 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1905 NextProtos: []string{"foo"},
1906 Bugs: ProtocolBugs{
1907 ExpectFalseStart: true,
1908 AlertBeforeFalseStartTest: alertAccessDenied,
1909 },
1910 },
1911 flags: []string{
1912 "-false-start",
1913 "-advertise-alpn", "\x03foo",
1914 },
1915 shimWritesFirst: true,
1916 shouldFail: true,
1917 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1918 expectedLocalError: "tls: peer did not false start: EOF",
1919 },
1920 {
1921 name: "NoFalseStart-RSA",
1922 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001923 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001924 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1925 NextProtos: []string{"foo"},
1926 Bugs: ProtocolBugs{
1927 ExpectFalseStart: true,
1928 AlertBeforeFalseStartTest: alertAccessDenied,
1929 },
1930 },
1931 flags: []string{
1932 "-false-start",
1933 "-advertise-alpn", "\x03foo",
1934 },
1935 shimWritesFirst: true,
1936 shouldFail: true,
1937 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1938 expectedLocalError: "tls: peer did not false start: EOF",
1939 },
1940 {
1941 name: "NoFalseStart-DHE_RSA",
1942 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001943 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001944 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1945 NextProtos: []string{"foo"},
1946 Bugs: ProtocolBugs{
1947 ExpectFalseStart: true,
1948 AlertBeforeFalseStartTest: alertAccessDenied,
1949 },
1950 },
1951 flags: []string{
1952 "-false-start",
1953 "-advertise-alpn", "\x03foo",
1954 },
1955 shimWritesFirst: true,
1956 shouldFail: true,
1957 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1958 expectedLocalError: "tls: peer did not false start: EOF",
1959 },
1960 {
Adam Langley7c803a62015-06-15 15:35:05 -07001961 protocol: dtls,
1962 name: "SendSplitAlert-Sync",
1963 config: Config{
1964 Bugs: ProtocolBugs{
1965 SendSplitAlert: true,
1966 },
1967 },
1968 },
1969 {
1970 protocol: dtls,
1971 name: "SendSplitAlert-Async",
1972 config: Config{
1973 Bugs: ProtocolBugs{
1974 SendSplitAlert: true,
1975 },
1976 },
1977 flags: []string{"-async"},
1978 },
1979 {
1980 protocol: dtls,
1981 name: "PackDTLSHandshake",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 MaxHandshakeRecordLength: 2,
1985 PackHandshakeFragments: 20,
1986 PackHandshakeRecords: 200,
1987 },
1988 },
1989 },
1990 {
Adam Langley7c803a62015-06-15 15:35:05 -07001991 name: "SendEmptyRecords-Pass",
1992 sendEmptyRecords: 32,
1993 },
1994 {
1995 name: "SendEmptyRecords",
1996 sendEmptyRecords: 33,
1997 shouldFail: true,
1998 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1999 },
2000 {
2001 name: "SendEmptyRecords-Async",
2002 sendEmptyRecords: 33,
2003 flags: []string{"-async"},
2004 shouldFail: true,
2005 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2006 },
2007 {
2008 name: "SendWarningAlerts-Pass",
2009 sendWarningAlerts: 4,
2010 },
2011 {
2012 protocol: dtls,
2013 name: "SendWarningAlerts-DTLS-Pass",
2014 sendWarningAlerts: 4,
2015 },
2016 {
2017 name: "SendWarningAlerts",
2018 sendWarningAlerts: 5,
2019 shouldFail: true,
2020 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2021 },
2022 {
2023 name: "SendWarningAlerts-Async",
2024 sendWarningAlerts: 5,
2025 flags: []string{"-async"},
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2028 },
David Benjaminba4594a2015-06-18 18:36:15 -04002029 {
2030 name: "EmptySessionID",
2031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002032 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002033 SessionTicketsDisabled: true,
2034 },
2035 noSessionCache: true,
2036 flags: []string{"-expect-no-session"},
2037 },
David Benjamin30789da2015-08-29 22:56:45 -04002038 {
2039 name: "Unclean-Shutdown",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 NoCloseNotify: true,
2043 ExpectCloseNotify: true,
2044 },
2045 },
2046 shimShutsDown: true,
2047 flags: []string{"-check-close-notify"},
2048 shouldFail: true,
2049 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2050 },
2051 {
2052 name: "Unclean-Shutdown-Ignored",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 NoCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002060 {
David Benjaminfa214e42016-05-10 17:03:10 -04002061 name: "Unclean-Shutdown-Alert",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendAlertOnShutdown: alertDecompressionFailure,
2065 ExpectCloseNotify: true,
2066 },
2067 },
2068 shimShutsDown: true,
2069 flags: []string{"-check-close-notify"},
2070 shouldFail: true,
2071 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2072 },
2073 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002074 name: "LargePlaintext",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 SendLargeRecords: true,
2078 },
2079 },
2080 messageLen: maxPlaintext + 1,
2081 shouldFail: true,
2082 expectedError: ":DATA_LENGTH_TOO_LONG:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "LargePlaintext-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 messageLen: maxPlaintext + 1,
2093 shouldFail: true,
2094 expectedError: ":DATA_LENGTH_TOO_LONG:",
2095 },
2096 {
2097 name: "LargeCiphertext",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 messageLen: maxPlaintext * 2,
2104 shouldFail: true,
2105 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2106 },
2107 {
2108 protocol: dtls,
2109 name: "LargeCiphertext-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 messageLen: maxPlaintext * 2,
2116 // Unlike the other four cases, DTLS drops records which
2117 // are invalid before authentication, so the connection
2118 // does not fail.
2119 expectMessageDropped: true,
2120 },
David Benjamindd6fed92015-10-23 17:41:12 -04002121 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 // In TLS 1.2 and below, empty NewSessionTicket messages
2123 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002124 name: "SendEmptySessionTicket",
2125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002127 Bugs: ProtocolBugs{
2128 SendEmptySessionTicket: true,
2129 FailIfSessionOffered: true,
2130 },
2131 },
2132 flags: []string{"-expect-no-session"},
2133 resumeSession: true,
2134 expectResumeRejected: true,
2135 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002136 {
David Benjamin8411b242015-11-26 12:07:28 -05002137 name: "BadChangeCipherSpec-1",
2138 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002139 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002140 Bugs: ProtocolBugs{
2141 BadChangeCipherSpec: []byte{2},
2142 },
2143 },
2144 shouldFail: true,
2145 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2146 },
2147 {
2148 name: "BadChangeCipherSpec-2",
2149 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002150 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002151 Bugs: ProtocolBugs{
2152 BadChangeCipherSpec: []byte{1, 1},
2153 },
2154 },
2155 shouldFail: true,
2156 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2157 },
2158 {
2159 protocol: dtls,
2160 name: "BadChangeCipherSpec-DTLS-1",
2161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002162 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002163 Bugs: ProtocolBugs{
2164 BadChangeCipherSpec: []byte{2},
2165 },
2166 },
2167 shouldFail: true,
2168 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2169 },
2170 {
2171 protocol: dtls,
2172 name: "BadChangeCipherSpec-DTLS-2",
2173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002174 MaxVersion: VersionTLS12,
David Benjamin8411b242015-11-26 12:07:28 -05002175 Bugs: ProtocolBugs{
2176 BadChangeCipherSpec: []byte{1, 1},
2177 },
2178 },
2179 shouldFail: true,
2180 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2181 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002182 {
2183 name: "BadHelloRequest-1",
2184 renegotiate: 1,
2185 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002186 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002187 Bugs: ProtocolBugs{
2188 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2189 },
2190 },
2191 flags: []string{
2192 "-renegotiate-freely",
2193 "-expect-total-renegotiations", "1",
2194 },
2195 shouldFail: true,
2196 expectedError: ":BAD_HELLO_REQUEST:",
2197 },
2198 {
2199 name: "BadHelloRequest-2",
2200 renegotiate: 1,
2201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002202 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002203 Bugs: ProtocolBugs{
2204 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2205 },
2206 },
2207 flags: []string{
2208 "-renegotiate-freely",
2209 "-expect-total-renegotiations", "1",
2210 },
2211 shouldFail: true,
2212 expectedError: ":BAD_HELLO_REQUEST:",
2213 },
David Benjaminef1b0092015-11-21 14:05:44 -05002214 {
2215 testType: serverTest,
2216 name: "SupportTicketsWithSessionID",
2217 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002218 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002219 SessionTicketsDisabled: true,
2220 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002221 resumeConfig: &Config{
2222 MaxVersion: VersionTLS12,
2223 },
David Benjaminef1b0092015-11-21 14:05:44 -05002224 resumeSession: true,
2225 },
Adam Langley7c803a62015-06-15 15:35:05 -07002226 }
Adam Langley7c803a62015-06-15 15:35:05 -07002227 testCases = append(testCases, basicTests...)
2228}
2229
Adam Langley95c29f32014-06-20 12:00:00 -07002230func addCipherSuiteTests() {
2231 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002232 const psk = "12345"
2233 const pskIdentity = "luggage combo"
2234
Adam Langley95c29f32014-06-20 12:00:00 -07002235 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002236 var certFile string
2237 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002238 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002239 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002240 certFile = ecdsaCertificateFile
2241 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002242 } else {
2243 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002244 certFile = rsaCertificateFile
2245 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002246 }
2247
David Benjamin48cae082014-10-27 01:06:24 -04002248 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002249 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002250 flags = append(flags,
2251 "-psk", psk,
2252 "-psk-identity", pskIdentity)
2253 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002254 if hasComponent(suite.name, "NULL") {
2255 // NULL ciphers must be explicitly enabled.
2256 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2257 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002258 if hasComponent(suite.name, "CECPQ1") {
2259 // CECPQ1 ciphers must be explicitly enabled.
2260 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2261 }
David Benjamin48cae082014-10-27 01:06:24 -04002262
Adam Langley95c29f32014-06-20 12:00:00 -07002263 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002264 for _, protocol := range []protocol{tls, dtls} {
2265 var prefix string
2266 if protocol == dtls {
2267 if !ver.hasDTLS {
2268 continue
2269 }
2270 prefix = "D"
2271 }
Adam Langley95c29f32014-06-20 12:00:00 -07002272
David Benjamin0407e762016-06-17 16:41:18 -04002273 var shouldServerFail, shouldClientFail bool
2274 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2275 // BoringSSL clients accept ECDHE on SSLv3, but
2276 // a BoringSSL server will never select it
2277 // because the extension is missing.
2278 shouldServerFail = true
2279 }
2280 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2281 shouldClientFail = true
2282 shouldServerFail = true
2283 }
Nick Harper1fd39d82016-06-14 18:14:35 -07002284 if !isTLS13Suite(suite.name) && ver.version == VersionTLS13 {
2285 shouldClientFail = true
2286 shouldServerFail = true
2287 }
David Benjamin0407e762016-06-17 16:41:18 -04002288 if !isDTLSCipher(suite.name) && protocol == dtls {
2289 shouldClientFail = true
2290 shouldServerFail = true
2291 }
David Benjamin4298d772015-12-19 00:18:25 -05002292
David Benjamin0407e762016-06-17 16:41:18 -04002293 var expectedServerError, expectedClientError string
2294 if shouldServerFail {
2295 expectedServerError = ":NO_SHARED_CIPHER:"
2296 }
2297 if shouldClientFail {
2298 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2299 }
David Benjamin025b3d32014-07-01 19:53:04 -04002300
David Benjamin6fd297b2014-08-11 18:43:38 -04002301 testCases = append(testCases, testCase{
2302 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002303 protocol: protocol,
2304
2305 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002306 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002307 MinVersion: ver.version,
2308 MaxVersion: ver.version,
2309 CipherSuites: []uint16{suite.id},
2310 Certificates: []Certificate{cert},
2311 PreSharedKey: []byte(psk),
2312 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002313 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002314 EnableAllCiphers: shouldServerFail,
2315 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002316 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002317 },
2318 certFile: certFile,
2319 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002320 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002321 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002322 shouldFail: shouldServerFail,
2323 expectedError: expectedServerError,
2324 })
2325
2326 testCases = append(testCases, testCase{
2327 testType: clientTest,
2328 protocol: protocol,
2329 name: prefix + ver.name + "-" + suite.name + "-client",
2330 config: Config{
2331 MinVersion: ver.version,
2332 MaxVersion: ver.version,
2333 CipherSuites: []uint16{suite.id},
2334 Certificates: []Certificate{cert},
2335 PreSharedKey: []byte(psk),
2336 PreSharedKeyIdentity: pskIdentity,
2337 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002338 EnableAllCiphers: shouldClientFail,
2339 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002340 },
2341 },
2342 flags: flags,
2343 resumeSession: true,
2344 shouldFail: shouldClientFail,
2345 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002346 })
David Benjamin2c99d282015-09-01 10:23:00 -04002347
Nick Harper1fd39d82016-06-14 18:14:35 -07002348 if !shouldClientFail {
2349 // Ensure the maximum record size is accepted.
2350 testCases = append(testCases, testCase{
2351 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2352 config: Config{
2353 MinVersion: ver.version,
2354 MaxVersion: ver.version,
2355 CipherSuites: []uint16{suite.id},
2356 Certificates: []Certificate{cert},
2357 PreSharedKey: []byte(psk),
2358 PreSharedKeyIdentity: pskIdentity,
2359 },
2360 flags: flags,
2361 messageLen: maxPlaintext,
2362 })
2363 }
2364 }
David Benjamin2c99d282015-09-01 10:23:00 -04002365 }
Adam Langley95c29f32014-06-20 12:00:00 -07002366 }
Adam Langleya7997f12015-05-14 17:38:50 -07002367
2368 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002369 name: "NoSharedCipher",
2370 config: Config{
2371 // TODO(davidben): Add a TLS 1.3 version of this test.
2372 MaxVersion: VersionTLS12,
2373 CipherSuites: []uint16{},
2374 },
2375 shouldFail: true,
2376 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2377 })
2378
2379 testCases = append(testCases, testCase{
2380 name: "UnsupportedCipherSuite",
2381 config: Config{
2382 MaxVersion: VersionTLS12,
2383 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2384 Bugs: ProtocolBugs{
2385 IgnorePeerCipherPreferences: true,
2386 },
2387 },
2388 flags: []string{"-cipher", "DEFAULT:!RC4"},
2389 shouldFail: true,
2390 expectedError: ":WRONG_CIPHER_RETURNED:",
2391 })
2392
2393 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002394 name: "WeakDH",
2395 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002396 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002397 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2398 Bugs: ProtocolBugs{
2399 // This is a 1023-bit prime number, generated
2400 // with:
2401 // openssl gendh 1023 | openssl asn1parse -i
2402 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2403 },
2404 },
2405 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002406 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002407 })
Adam Langleycef75832015-09-03 14:51:12 -07002408
David Benjamincd24a392015-11-11 13:23:05 -08002409 testCases = append(testCases, testCase{
2410 name: "SillyDH",
2411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002412 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002413 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2414 Bugs: ProtocolBugs{
2415 // This is a 4097-bit prime number, generated
2416 // with:
2417 // openssl gendh 4097 | openssl asn1parse -i
2418 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2419 },
2420 },
2421 shouldFail: true,
2422 expectedError: ":DH_P_TOO_LONG:",
2423 })
2424
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002425 // This test ensures that Diffie-Hellman public values are padded with
2426 // zeros so that they're the same length as the prime. This is to avoid
2427 // hitting a bug in yaSSL.
2428 testCases = append(testCases, testCase{
2429 testType: serverTest,
2430 name: "DHPublicValuePadded",
2431 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002432 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002433 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2434 Bugs: ProtocolBugs{
2435 RequireDHPublicValueLen: (1025 + 7) / 8,
2436 },
2437 },
2438 flags: []string{"-use-sparse-dh-prime"},
2439 })
David Benjamincd24a392015-11-11 13:23:05 -08002440
David Benjamin241ae832016-01-15 03:04:54 -05002441 // The server must be tolerant to bogus ciphers.
2442 const bogusCipher = 0x1234
2443 testCases = append(testCases, testCase{
2444 testType: serverTest,
2445 name: "UnknownCipher",
2446 config: Config{
2447 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2448 },
2449 })
2450
Adam Langleycef75832015-09-03 14:51:12 -07002451 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2452 // 1.1 specific cipher suite settings. A server is setup with the given
2453 // cipher lists and then a connection is made for each member of
2454 // expectations. The cipher suite that the server selects must match
2455 // the specified one.
2456 var versionSpecificCiphersTest = []struct {
2457 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2458 // expectations is a map from TLS version to cipher suite id.
2459 expectations map[uint16]uint16
2460 }{
2461 {
2462 // Test that the null case (where no version-specific ciphers are set)
2463 // works as expected.
2464 "RC4-SHA:AES128-SHA", // default ciphers
2465 "", // no ciphers specifically for TLS ≥ 1.0
2466 "", // no ciphers specifically for TLS ≥ 1.1
2467 map[uint16]uint16{
2468 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2469 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2470 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2471 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2472 },
2473 },
2474 {
2475 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2476 // cipher.
2477 "RC4-SHA:AES128-SHA", // default
2478 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2479 "", // no ciphers specifically for TLS ≥ 1.1
2480 map[uint16]uint16{
2481 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2482 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2483 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2484 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2485 },
2486 },
2487 {
2488 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2489 // cipher.
2490 "RC4-SHA:AES128-SHA", // default
2491 "", // no ciphers specifically for TLS ≥ 1.0
2492 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2493 map[uint16]uint16{
2494 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2495 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2496 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2497 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2498 },
2499 },
2500 {
2501 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2502 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2503 "RC4-SHA:AES128-SHA", // default
2504 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2505 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2506 map[uint16]uint16{
2507 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2508 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2509 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2510 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2511 },
2512 },
2513 }
2514
2515 for i, test := range versionSpecificCiphersTest {
2516 for version, expectedCipherSuite := range test.expectations {
2517 flags := []string{"-cipher", test.ciphersDefault}
2518 if len(test.ciphersTLS10) > 0 {
2519 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2520 }
2521 if len(test.ciphersTLS11) > 0 {
2522 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2523 }
2524
2525 testCases = append(testCases, testCase{
2526 testType: serverTest,
2527 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2528 config: Config{
2529 MaxVersion: version,
2530 MinVersion: version,
2531 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2532 },
2533 flags: flags,
2534 expectedCipher: expectedCipherSuite,
2535 })
2536 }
2537 }
Adam Langley95c29f32014-06-20 12:00:00 -07002538}
2539
2540func addBadECDSASignatureTests() {
2541 for badR := BadValue(1); badR < NumBadValues; badR++ {
2542 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002543 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002544 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2545 config: Config{
2546 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2547 Certificates: []Certificate{getECDSACertificate()},
2548 Bugs: ProtocolBugs{
2549 BadECDSAR: badR,
2550 BadECDSAS: badS,
2551 },
2552 },
2553 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002554 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002555 })
2556 }
2557 }
2558}
2559
Adam Langley80842bd2014-06-20 12:00:00 -07002560func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002561 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002562 name: "MaxCBCPadding",
2563 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002564 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002565 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2566 Bugs: ProtocolBugs{
2567 MaxPadding: true,
2568 },
2569 },
2570 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2571 })
David Benjamin025b3d32014-07-01 19:53:04 -04002572 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002573 name: "BadCBCPadding",
2574 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002575 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002576 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2577 Bugs: ProtocolBugs{
2578 PaddingFirstByteBad: true,
2579 },
2580 },
2581 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002582 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002583 })
2584 // OpenSSL previously had an issue where the first byte of padding in
2585 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002586 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002587 name: "BadCBCPadding255",
2588 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002589 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002590 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2591 Bugs: ProtocolBugs{
2592 MaxPadding: true,
2593 PaddingFirstByteBadIf255: true,
2594 },
2595 },
2596 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2597 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002598 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002599 })
2600}
2601
Kenny Root7fdeaf12014-08-05 15:23:37 -07002602func addCBCSplittingTests() {
2603 testCases = append(testCases, testCase{
2604 name: "CBCRecordSplitting",
2605 config: Config{
2606 MaxVersion: VersionTLS10,
2607 MinVersion: VersionTLS10,
2608 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2609 },
David Benjaminac8302a2015-09-01 17:18:15 -04002610 messageLen: -1, // read until EOF
2611 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002612 flags: []string{
2613 "-async",
2614 "-write-different-record-sizes",
2615 "-cbc-record-splitting",
2616 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002617 })
2618 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002619 name: "CBCRecordSplittingPartialWrite",
2620 config: Config{
2621 MaxVersion: VersionTLS10,
2622 MinVersion: VersionTLS10,
2623 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2624 },
2625 messageLen: -1, // read until EOF
2626 flags: []string{
2627 "-async",
2628 "-write-different-record-sizes",
2629 "-cbc-record-splitting",
2630 "-partial-write",
2631 },
2632 })
2633}
2634
David Benjamin636293b2014-07-08 17:59:18 -04002635func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002636 // Add a dummy cert pool to stress certificate authority parsing.
2637 // TODO(davidben): Add tests that those values parse out correctly.
2638 certPool := x509.NewCertPool()
2639 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2640 if err != nil {
2641 panic(err)
2642 }
2643 certPool.AddCert(cert)
2644
David Benjamin636293b2014-07-08 17:59:18 -04002645 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002646 testCases = append(testCases, testCase{
2647 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002648 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002649 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002650 MinVersion: ver.version,
2651 MaxVersion: ver.version,
2652 ClientAuth: RequireAnyClientCert,
2653 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002654 },
2655 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002656 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2657 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002658 },
2659 })
2660 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002661 testType: serverTest,
2662 name: ver.name + "-Server-ClientAuth-RSA",
2663 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002664 MinVersion: ver.version,
2665 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002666 Certificates: []Certificate{rsaCertificate},
2667 },
2668 flags: []string{"-require-any-client-certificate"},
2669 })
David Benjamine098ec22014-08-27 23:13:20 -04002670 if ver.version != VersionSSL30 {
2671 testCases = append(testCases, testCase{
2672 testType: serverTest,
2673 name: ver.name + "-Server-ClientAuth-ECDSA",
2674 config: Config{
2675 MinVersion: ver.version,
2676 MaxVersion: ver.version,
2677 Certificates: []Certificate{ecdsaCertificate},
2678 },
2679 flags: []string{"-require-any-client-certificate"},
2680 })
2681 testCases = append(testCases, testCase{
2682 testType: clientTest,
2683 name: ver.name + "-Client-ClientAuth-ECDSA",
2684 config: Config{
2685 MinVersion: ver.version,
2686 MaxVersion: ver.version,
2687 ClientAuth: RequireAnyClientCert,
2688 ClientCAs: certPool,
2689 },
2690 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002691 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2692 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002693 },
2694 })
2695 }
David Benjamin636293b2014-07-08 17:59:18 -04002696 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002697
Nick Harper1fd39d82016-06-14 18:14:35 -07002698 // TODO(davidben): These tests will need TLS 1.3 versions when the
2699 // handshake is separate.
2700
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002701 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002702 name: "NoClientCertificate",
2703 config: Config{
2704 MaxVersion: VersionTLS12,
2705 ClientAuth: RequireAnyClientCert,
2706 },
2707 shouldFail: true,
2708 expectedLocalError: "client didn't provide a certificate",
2709 })
2710
2711 testCases = append(testCases, testCase{
Nick Harper1fd39d82016-06-14 18:14:35 -07002712 testType: serverTest,
2713 name: "RequireAnyClientCertificate",
2714 config: Config{
2715 MaxVersion: VersionTLS12,
2716 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002717 flags: []string{"-require-any-client-certificate"},
2718 shouldFail: true,
2719 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2720 })
2721
2722 testCases = append(testCases, testCase{
2723 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002724 name: "RequireAnyClientCertificate-SSL3",
2725 config: Config{
2726 MaxVersion: VersionSSL30,
2727 },
2728 flags: []string{"-require-any-client-certificate"},
2729 shouldFail: true,
2730 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2731 })
2732
2733 testCases = append(testCases, testCase{
2734 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002735 name: "SkipClientCertificate",
2736 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002737 MaxVersion: VersionTLS12,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002738 Bugs: ProtocolBugs{
2739 SkipClientCertificate: true,
2740 },
2741 },
2742 // Setting SSL_VERIFY_PEER allows anonymous clients.
2743 flags: []string{"-verify-peer"},
2744 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002745 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002746 })
David Benjaminc032dfa2016-05-12 14:54:57 -04002747
2748 // Client auth is only legal in certificate-based ciphers.
2749 testCases = append(testCases, testCase{
2750 testType: clientTest,
2751 name: "ClientAuth-PSK",
2752 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002753 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002754 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2755 PreSharedKey: []byte("secret"),
2756 ClientAuth: RequireAnyClientCert,
2757 },
2758 flags: []string{
2759 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2760 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2761 "-psk", "secret",
2762 },
2763 shouldFail: true,
2764 expectedError: ":UNEXPECTED_MESSAGE:",
2765 })
2766 testCases = append(testCases, testCase{
2767 testType: clientTest,
2768 name: "ClientAuth-ECDHE_PSK",
2769 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002770 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002771 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2772 PreSharedKey: []byte("secret"),
2773 ClientAuth: RequireAnyClientCert,
2774 },
2775 flags: []string{
2776 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2777 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2778 "-psk", "secret",
2779 },
2780 shouldFail: true,
2781 expectedError: ":UNEXPECTED_MESSAGE:",
2782 })
David Benjamin636293b2014-07-08 17:59:18 -04002783}
2784
Adam Langley75712922014-10-10 16:23:43 -07002785func addExtendedMasterSecretTests() {
2786 const expectEMSFlag = "-expect-extended-master-secret"
2787
2788 for _, with := range []bool{false, true} {
2789 prefix := "No"
2790 var flags []string
2791 if with {
2792 prefix = ""
2793 flags = []string{expectEMSFlag}
2794 }
2795
2796 for _, isClient := range []bool{false, true} {
2797 suffix := "-Server"
2798 testType := serverTest
2799 if isClient {
2800 suffix = "-Client"
2801 testType = clientTest
2802 }
2803
David Benjamin4c3ddf72016-06-29 18:13:53 -04002804 // TODO(davidben): Once the new TLS 1.3 handshake is in,
2805 // test that the extension is irrelevant, but the API
2806 // acts as if it is enabled.
Adam Langley75712922014-10-10 16:23:43 -07002807 for _, ver := range tlsVersions {
2808 test := testCase{
2809 testType: testType,
2810 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2811 config: Config{
2812 MinVersion: ver.version,
2813 MaxVersion: ver.version,
2814 Bugs: ProtocolBugs{
2815 NoExtendedMasterSecret: !with,
2816 RequireExtendedMasterSecret: with,
2817 },
2818 },
David Benjamin48cae082014-10-27 01:06:24 -04002819 flags: flags,
2820 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002821 }
2822 if test.shouldFail {
2823 test.expectedLocalError = "extended master secret required but not supported by peer"
2824 }
2825 testCases = append(testCases, test)
2826 }
2827 }
2828 }
2829
Adam Langleyba5934b2015-06-02 10:50:35 -07002830 for _, isClient := range []bool{false, true} {
2831 for _, supportedInFirstConnection := range []bool{false, true} {
2832 for _, supportedInResumeConnection := range []bool{false, true} {
2833 boolToWord := func(b bool) string {
2834 if b {
2835 return "Yes"
2836 }
2837 return "No"
2838 }
2839 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2840 if isClient {
2841 suffix += "Client"
2842 } else {
2843 suffix += "Server"
2844 }
2845
2846 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002847 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002848 Bugs: ProtocolBugs{
2849 RequireExtendedMasterSecret: true,
2850 },
2851 }
2852
2853 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002854 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07002855 Bugs: ProtocolBugs{
2856 NoExtendedMasterSecret: true,
2857 },
2858 }
2859
2860 test := testCase{
2861 name: "ExtendedMasterSecret-" + suffix,
2862 resumeSession: true,
2863 }
2864
2865 if !isClient {
2866 test.testType = serverTest
2867 }
2868
2869 if supportedInFirstConnection {
2870 test.config = supportedConfig
2871 } else {
2872 test.config = noSupportConfig
2873 }
2874
2875 if supportedInResumeConnection {
2876 test.resumeConfig = &supportedConfig
2877 } else {
2878 test.resumeConfig = &noSupportConfig
2879 }
2880
2881 switch suffix {
2882 case "YesToYes-Client", "YesToYes-Server":
2883 // When a session is resumed, it should
2884 // still be aware that its master
2885 // secret was generated via EMS and
2886 // thus it's safe to use tls-unique.
2887 test.flags = []string{expectEMSFlag}
2888 case "NoToYes-Server":
2889 // If an original connection did not
2890 // contain EMS, but a resumption
2891 // handshake does, then a server should
2892 // not resume the session.
2893 test.expectResumeRejected = true
2894 case "YesToNo-Server":
2895 // Resuming an EMS session without the
2896 // EMS extension should cause the
2897 // server to abort the connection.
2898 test.shouldFail = true
2899 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2900 case "NoToYes-Client":
2901 // A client should abort a connection
2902 // where the server resumed a non-EMS
2903 // session but echoed the EMS
2904 // extension.
2905 test.shouldFail = true
2906 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2907 case "YesToNo-Client":
2908 // A client should abort a connection
2909 // where the server didn't echo EMS
2910 // when the session used it.
2911 test.shouldFail = true
2912 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2913 }
2914
2915 testCases = append(testCases, test)
2916 }
2917 }
2918 }
Adam Langley75712922014-10-10 16:23:43 -07002919}
2920
David Benjamin582ba042016-07-07 12:33:25 -07002921type stateMachineTestConfig struct {
2922 protocol protocol
2923 async bool
2924 splitHandshake, packHandshakeFlight bool
2925}
2926
David Benjamin43ec06f2014-08-05 02:28:57 -04002927// Adds tests that try to cover the range of the handshake state machine, under
2928// various conditions. Some of these are redundant with other tests, but they
2929// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07002930func addAllStateMachineCoverageTests() {
2931 for _, async := range []bool{false, true} {
2932 for _, protocol := range []protocol{tls, dtls} {
2933 addStateMachineCoverageTests(stateMachineTestConfig{
2934 protocol: protocol,
2935 async: async,
2936 })
2937 addStateMachineCoverageTests(stateMachineTestConfig{
2938 protocol: protocol,
2939 async: async,
2940 splitHandshake: true,
2941 })
2942 if protocol == tls {
2943 addStateMachineCoverageTests(stateMachineTestConfig{
2944 protocol: protocol,
2945 async: async,
2946 packHandshakeFlight: true,
2947 })
2948 }
2949 }
2950 }
2951}
2952
2953func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002954 var tests []testCase
2955
2956 // Basic handshake, with resumption. Client and server,
2957 // session ID and session ticket.
David Benjamin4c3ddf72016-06-29 18:13:53 -04002958 //
2959 // TODO(davidben): Add TLS 1.3 tests for all of its different handshake
2960 // shapes.
David Benjamin760b1dd2015-05-15 23:33:48 -04002961 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002962 name: "Basic-Client",
2963 config: Config{
2964 MaxVersion: VersionTLS12,
2965 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002966 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002967 // Ensure session tickets are used, not session IDs.
2968 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002969 })
2970 tests = append(tests, testCase{
2971 name: "Basic-Client-RenewTicket",
2972 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002973 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002974 Bugs: ProtocolBugs{
2975 RenewTicketOnResume: true,
2976 },
2977 },
David Benjaminba4594a2015-06-18 18:36:15 -04002978 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002979 resumeSession: true,
2980 })
2981 tests = append(tests, testCase{
2982 name: "Basic-Client-NoTicket",
2983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002984 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04002985 SessionTicketsDisabled: true,
2986 },
2987 resumeSession: true,
2988 })
2989 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002990 name: "Basic-Client-Implicit",
2991 config: Config{
2992 MaxVersion: VersionTLS12,
2993 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002994 flags: []string{"-implicit-handshake"},
2995 resumeSession: true,
2996 })
2997 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002998 testType: serverTest,
2999 name: "Basic-Server",
3000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003001 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003002 Bugs: ProtocolBugs{
3003 RequireSessionTickets: true,
3004 },
3005 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003006 resumeSession: true,
3007 })
3008 tests = append(tests, testCase{
3009 testType: serverTest,
3010 name: "Basic-Server-NoTickets",
3011 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003012 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003013 SessionTicketsDisabled: true,
3014 },
3015 resumeSession: true,
3016 })
3017 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003018 testType: serverTest,
3019 name: "Basic-Server-Implicit",
3020 config: Config{
3021 MaxVersion: VersionTLS12,
3022 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003023 flags: []string{"-implicit-handshake"},
3024 resumeSession: true,
3025 })
3026 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003027 testType: serverTest,
3028 name: "Basic-Server-EarlyCallback",
3029 config: Config{
3030 MaxVersion: VersionTLS12,
3031 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003032 flags: []string{"-use-early-callback"},
3033 resumeSession: true,
3034 })
3035
3036 // TLS client auth.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003037 //
3038 // TODO(davidben): Add TLS 1.3 client auth tests.
David Benjamin760b1dd2015-05-15 23:33:48 -04003039 tests = append(tests, testCase{
3040 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003041 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003043 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003044 ClientAuth: RequestClientCert,
3045 },
3046 })
3047 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003048 testType: serverTest,
3049 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 config: Config{
3051 MaxVersion: VersionTLS12,
3052 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003053 // Setting SSL_VERIFY_PEER allows anonymous clients.
3054 flags: []string{"-verify-peer"},
3055 })
David Benjamin582ba042016-07-07 12:33:25 -07003056 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003057 tests = append(tests, testCase{
3058 testType: clientTest,
3059 name: "ClientAuth-NoCertificate-Client-SSL3",
3060 config: Config{
3061 MaxVersion: VersionSSL30,
3062 ClientAuth: RequestClientCert,
3063 },
3064 })
3065 tests = append(tests, testCase{
3066 testType: serverTest,
3067 name: "ClientAuth-NoCertificate-Server-SSL3",
3068 config: Config{
3069 MaxVersion: VersionSSL30,
3070 },
3071 // Setting SSL_VERIFY_PEER allows anonymous clients.
3072 flags: []string{"-verify-peer"},
3073 })
3074 }
3075 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003076 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003077 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003079 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003080 ClientAuth: RequireAnyClientCert,
3081 },
3082 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003083 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3084 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003085 },
3086 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003087 tests = append(tests, testCase{
3088 testType: clientTest,
3089 name: "ClientAuth-ECDSA-Client",
3090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003091 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003092 ClientAuth: RequireAnyClientCert,
3093 },
3094 flags: []string{
3095 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3096 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3097 },
3098 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003099 tests = append(tests, testCase{
3100 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003101 name: "ClientAuth-NoCertificate-OldCallback",
3102 config: Config{
3103 MaxVersion: VersionTLS12,
3104 ClientAuth: RequestClientCert,
3105 },
3106 flags: []string{"-use-old-client-cert-callback"},
3107 })
3108 tests = append(tests, testCase{
3109 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003110 name: "ClientAuth-OldCallback",
3111 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003112 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003113 ClientAuth: RequireAnyClientCert,
3114 },
3115 flags: []string{
3116 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3117 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3118 "-use-old-client-cert-callback",
3119 },
3120 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003121 tests = append(tests, testCase{
3122 testType: serverTest,
3123 name: "ClientAuth-Server",
3124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003125 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003126 Certificates: []Certificate{rsaCertificate},
3127 },
3128 flags: []string{"-require-any-client-certificate"},
3129 })
3130
David Benjamin4c3ddf72016-06-29 18:13:53 -04003131 // Test each key exchange on the server side for async keys.
3132 //
3133 // TODO(davidben): Add TLS 1.3 versions of these.
3134 tests = append(tests, testCase{
3135 testType: serverTest,
3136 name: "Basic-Server-RSA",
3137 config: Config{
3138 MaxVersion: VersionTLS12,
3139 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3140 },
3141 flags: []string{
3142 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3143 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3144 },
3145 })
3146 tests = append(tests, testCase{
3147 testType: serverTest,
3148 name: "Basic-Server-ECDHE-RSA",
3149 config: Config{
3150 MaxVersion: VersionTLS12,
3151 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3152 },
3153 flags: []string{
3154 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3155 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3156 },
3157 })
3158 tests = append(tests, testCase{
3159 testType: serverTest,
3160 name: "Basic-Server-ECDHE-ECDSA",
3161 config: Config{
3162 MaxVersion: VersionTLS12,
3163 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3164 },
3165 flags: []string{
3166 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3167 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
3168 },
3169 })
3170
David Benjamin760b1dd2015-05-15 23:33:48 -04003171 // No session ticket support; server doesn't send NewSessionTicket.
3172 tests = append(tests, testCase{
3173 name: "SessionTicketsDisabled-Client",
3174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003175 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003176 SessionTicketsDisabled: true,
3177 },
3178 })
3179 tests = append(tests, testCase{
3180 testType: serverTest,
3181 name: "SessionTicketsDisabled-Server",
3182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003183 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003184 SessionTicketsDisabled: true,
3185 },
3186 })
3187
3188 // Skip ServerKeyExchange in PSK key exchange if there's no
3189 // identity hint.
3190 tests = append(tests, testCase{
3191 name: "EmptyPSKHint-Client",
3192 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003193 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003194 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3195 PreSharedKey: []byte("secret"),
3196 },
3197 flags: []string{"-psk", "secret"},
3198 })
3199 tests = append(tests, testCase{
3200 testType: serverTest,
3201 name: "EmptyPSKHint-Server",
3202 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003203 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003204 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3205 PreSharedKey: []byte("secret"),
3206 },
3207 flags: []string{"-psk", "secret"},
3208 })
3209
David Benjamin4c3ddf72016-06-29 18:13:53 -04003210 // OCSP stapling tests.
3211 //
3212 // TODO(davidben): Test the TLS 1.3 version of OCSP stapling.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003213 tests = append(tests, testCase{
3214 testType: clientTest,
3215 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003216 config: Config{
3217 MaxVersion: VersionTLS12,
3218 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003219 flags: []string{
3220 "-enable-ocsp-stapling",
3221 "-expect-ocsp-response",
3222 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003223 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003224 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003225 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003226 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003227 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003228 testType: serverTest,
3229 name: "OCSPStapling-Server",
3230 config: Config{
3231 MaxVersion: VersionTLS12,
3232 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003233 expectedOCSPResponse: testOCSPResponse,
3234 flags: []string{
3235 "-ocsp-response",
3236 base64.StdEncoding.EncodeToString(testOCSPResponse),
3237 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003238 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003239 })
3240
David Benjamin4c3ddf72016-06-29 18:13:53 -04003241 // Certificate verification tests.
3242 //
3243 // TODO(davidben): Test the TLS 1.3 version.
Paul Lietar8f1c2682015-08-18 12:21:54 +01003244 tests = append(tests, testCase{
3245 testType: clientTest,
3246 name: "CertificateVerificationSucceed",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003247 config: Config{
3248 MaxVersion: VersionTLS12,
3249 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003250 flags: []string{
3251 "-verify-peer",
3252 },
3253 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003254 tests = append(tests, testCase{
3255 testType: clientTest,
3256 name: "CertificateVerificationFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003257 config: Config{
3258 MaxVersion: VersionTLS12,
3259 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003260 flags: []string{
3261 "-verify-fail",
3262 "-verify-peer",
3263 },
3264 shouldFail: true,
3265 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3266 })
Paul Lietar8f1c2682015-08-18 12:21:54 +01003267 tests = append(tests, testCase{
3268 testType: clientTest,
3269 name: "CertificateVerificationSoftFail",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003270 config: Config{
3271 MaxVersion: VersionTLS12,
3272 },
Paul Lietar8f1c2682015-08-18 12:21:54 +01003273 flags: []string{
3274 "-verify-fail",
3275 "-expect-verify-result",
3276 },
3277 })
3278
David Benjamin582ba042016-07-07 12:33:25 -07003279 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003280 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003281 name: "Renegotiate-Client",
3282 config: Config{
3283 MaxVersion: VersionTLS12,
3284 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003285 renegotiate: 1,
3286 flags: []string{
3287 "-renegotiate-freely",
3288 "-expect-total-renegotiations", "1",
3289 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003290 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003291
David Benjamin760b1dd2015-05-15 23:33:48 -04003292 // NPN on client and server; results in post-handshake message.
3293 tests = append(tests, testCase{
3294 name: "NPN-Client",
3295 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003296 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003297 NextProtos: []string{"foo"},
3298 },
3299 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003300 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003301 expectedNextProto: "foo",
3302 expectedNextProtoType: npn,
3303 })
3304 tests = append(tests, testCase{
3305 testType: serverTest,
3306 name: "NPN-Server",
3307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003308 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003309 NextProtos: []string{"bar"},
3310 },
3311 flags: []string{
3312 "-advertise-npn", "\x03foo\x03bar\x03baz",
3313 "-expect-next-proto", "bar",
3314 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003315 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003316 expectedNextProto: "bar",
3317 expectedNextProtoType: npn,
3318 })
3319
3320 // TODO(davidben): Add tests for when False Start doesn't trigger.
3321
3322 // Client does False Start and negotiates NPN.
3323 tests = append(tests, testCase{
3324 name: "FalseStart",
3325 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003326 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3328 NextProtos: []string{"foo"},
3329 Bugs: ProtocolBugs{
3330 ExpectFalseStart: true,
3331 },
3332 },
3333 flags: []string{
3334 "-false-start",
3335 "-select-next-proto", "foo",
3336 },
3337 shimWritesFirst: true,
3338 resumeSession: true,
3339 })
3340
3341 // Client does False Start and negotiates ALPN.
3342 tests = append(tests, testCase{
3343 name: "FalseStart-ALPN",
3344 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003345 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003346 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3347 NextProtos: []string{"foo"},
3348 Bugs: ProtocolBugs{
3349 ExpectFalseStart: true,
3350 },
3351 },
3352 flags: []string{
3353 "-false-start",
3354 "-advertise-alpn", "\x03foo",
3355 },
3356 shimWritesFirst: true,
3357 resumeSession: true,
3358 })
3359
3360 // Client does False Start but doesn't explicitly call
3361 // SSL_connect.
3362 tests = append(tests, testCase{
3363 name: "FalseStart-Implicit",
3364 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003365 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003366 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3367 NextProtos: []string{"foo"},
3368 },
3369 flags: []string{
3370 "-implicit-handshake",
3371 "-false-start",
3372 "-advertise-alpn", "\x03foo",
3373 },
3374 })
3375
3376 // False Start without session tickets.
3377 tests = append(tests, testCase{
3378 name: "FalseStart-SessionTicketsDisabled",
3379 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003380 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3382 NextProtos: []string{"foo"},
3383 SessionTicketsDisabled: true,
3384 Bugs: ProtocolBugs{
3385 ExpectFalseStart: true,
3386 },
3387 },
3388 flags: []string{
3389 "-false-start",
3390 "-select-next-proto", "foo",
3391 },
3392 shimWritesFirst: true,
3393 })
3394
3395 // Server parses a V2ClientHello.
3396 tests = append(tests, testCase{
3397 testType: serverTest,
3398 name: "SendV2ClientHello",
3399 config: Config{
3400 // Choose a cipher suite that does not involve
3401 // elliptic curves, so no extensions are
3402 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003403 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003404 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3405 Bugs: ProtocolBugs{
3406 SendV2ClientHello: true,
3407 },
3408 },
3409 })
3410
3411 // Client sends a Channel ID.
3412 tests = append(tests, testCase{
3413 name: "ChannelID-Client",
3414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003415 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003416 RequestChannelID: true,
3417 },
Adam Langley7c803a62015-06-15 15:35:05 -07003418 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003419 resumeSession: true,
3420 expectChannelID: true,
3421 })
3422
3423 // Server accepts a Channel ID.
3424 tests = append(tests, testCase{
3425 testType: serverTest,
3426 name: "ChannelID-Server",
3427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003428 MaxVersion: VersionTLS12,
3429 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003430 },
3431 flags: []string{
3432 "-expect-channel-id",
3433 base64.StdEncoding.EncodeToString(channelIDBytes),
3434 },
3435 resumeSession: true,
3436 expectChannelID: true,
3437 })
David Benjamin30789da2015-08-29 22:56:45 -04003438
David Benjaminf8fcdf32016-06-08 15:56:13 -04003439 // Channel ID and NPN at the same time, to ensure their relative
3440 // ordering is correct.
3441 tests = append(tests, testCase{
3442 name: "ChannelID-NPN-Client",
3443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003444 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003445 RequestChannelID: true,
3446 NextProtos: []string{"foo"},
3447 },
3448 flags: []string{
3449 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3450 "-select-next-proto", "foo",
3451 },
3452 resumeSession: true,
3453 expectChannelID: true,
3454 expectedNextProto: "foo",
3455 expectedNextProtoType: npn,
3456 })
3457 tests = append(tests, testCase{
3458 testType: serverTest,
3459 name: "ChannelID-NPN-Server",
3460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003461 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003462 ChannelID: channelIDKey,
3463 NextProtos: []string{"bar"},
3464 },
3465 flags: []string{
3466 "-expect-channel-id",
3467 base64.StdEncoding.EncodeToString(channelIDBytes),
3468 "-advertise-npn", "\x03foo\x03bar\x03baz",
3469 "-expect-next-proto", "bar",
3470 },
3471 resumeSession: true,
3472 expectChannelID: true,
3473 expectedNextProto: "bar",
3474 expectedNextProtoType: npn,
3475 })
3476
David Benjamin30789da2015-08-29 22:56:45 -04003477 // Bidirectional shutdown with the runner initiating.
3478 tests = append(tests, testCase{
3479 name: "Shutdown-Runner",
3480 config: Config{
3481 Bugs: ProtocolBugs{
3482 ExpectCloseNotify: true,
3483 },
3484 },
3485 flags: []string{"-check-close-notify"},
3486 })
3487
3488 // Bidirectional shutdown with the shim initiating. The runner,
3489 // in the meantime, sends garbage before the close_notify which
3490 // the shim must ignore.
3491 tests = append(tests, testCase{
3492 name: "Shutdown-Shim",
3493 config: Config{
3494 Bugs: ProtocolBugs{
3495 ExpectCloseNotify: true,
3496 },
3497 },
3498 shimShutsDown: true,
3499 sendEmptyRecords: 1,
3500 sendWarningAlerts: 1,
3501 flags: []string{"-check-close-notify"},
3502 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003503 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003504 // TODO(davidben): DTLS 1.3 will want a similar thing for
3505 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003506 tests = append(tests, testCase{
3507 name: "SkipHelloVerifyRequest",
3508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003509 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003510 Bugs: ProtocolBugs{
3511 SkipHelloVerifyRequest: true,
3512 },
3513 },
3514 })
3515 }
3516
David Benjamin760b1dd2015-05-15 23:33:48 -04003517 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003518 test.protocol = config.protocol
3519 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003520 test.name += "-DTLS"
3521 }
David Benjamin582ba042016-07-07 12:33:25 -07003522 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003523 test.name += "-Async"
3524 test.flags = append(test.flags, "-async")
3525 } else {
3526 test.name += "-Sync"
3527 }
David Benjamin582ba042016-07-07 12:33:25 -07003528 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003529 test.name += "-SplitHandshakeRecords"
3530 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003531 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003532 test.config.Bugs.MaxPacketLength = 256
3533 test.flags = append(test.flags, "-mtu", "256")
3534 }
3535 }
David Benjamin582ba042016-07-07 12:33:25 -07003536 if config.packHandshakeFlight {
3537 test.name += "-PackHandshakeFlight"
3538 test.config.Bugs.PackHandshakeFlight = true
3539 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003540 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003541 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003542}
3543
Adam Langley524e7172015-02-20 16:04:00 -08003544func addDDoSCallbackTests() {
3545 // DDoS callback.
3546
3547 for _, resume := range []bool{false, true} {
3548 suffix := "Resume"
3549 if resume {
3550 suffix = "No" + suffix
3551 }
3552
David Benjamin4c3ddf72016-06-29 18:13:53 -04003553 // TODO(davidben): Test TLS 1.3's version of the DDoS callback.
3554
Adam Langley524e7172015-02-20 16:04:00 -08003555 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003556 testType: serverTest,
3557 name: "Server-DDoS-OK-" + suffix,
3558 config: Config{
3559 MaxVersion: VersionTLS12,
3560 },
Adam Langley524e7172015-02-20 16:04:00 -08003561 flags: []string{"-install-ddos-callback"},
3562 resumeSession: resume,
3563 })
3564
3565 failFlag := "-fail-ddos-callback"
3566 if resume {
3567 failFlag = "-fail-second-ddos-callback"
3568 }
3569 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003570 testType: serverTest,
3571 name: "Server-DDoS-Reject-" + suffix,
3572 config: Config{
3573 MaxVersion: VersionTLS12,
3574 },
Adam Langley524e7172015-02-20 16:04:00 -08003575 flags: []string{"-install-ddos-callback", failFlag},
3576 resumeSession: resume,
3577 shouldFail: true,
3578 expectedError: ":CONNECTION_REJECTED:",
3579 })
3580 }
3581}
3582
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003583func addVersionNegotiationTests() {
3584 for i, shimVers := range tlsVersions {
3585 // Assemble flags to disable all newer versions on the shim.
3586 var flags []string
3587 for _, vers := range tlsVersions[i+1:] {
3588 flags = append(flags, vers.flag)
3589 }
3590
3591 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003592 protocols := []protocol{tls}
3593 if runnerVers.hasDTLS && shimVers.hasDTLS {
3594 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003595 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003596 for _, protocol := range protocols {
3597 expectedVersion := shimVers.version
3598 if runnerVers.version < shimVers.version {
3599 expectedVersion = runnerVers.version
3600 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003601
David Benjamin8b8c0062014-11-23 02:47:52 -05003602 suffix := shimVers.name + "-" + runnerVers.name
3603 if protocol == dtls {
3604 suffix += "-DTLS"
3605 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003606
David Benjamin1eb367c2014-12-12 18:17:51 -05003607 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3608
David Benjamin1e29a6b2014-12-10 02:27:24 -05003609 clientVers := shimVers.version
3610 if clientVers > VersionTLS10 {
3611 clientVers = VersionTLS10
3612 }
Nick Harper1fd39d82016-06-14 18:14:35 -07003613 serverVers := expectedVersion
3614 if expectedVersion >= VersionTLS13 {
3615 serverVers = VersionTLS10
3616 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003617 testCases = append(testCases, testCase{
3618 protocol: protocol,
3619 testType: clientTest,
3620 name: "VersionNegotiation-Client-" + suffix,
3621 config: Config{
3622 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003623 Bugs: ProtocolBugs{
3624 ExpectInitialRecordVersion: clientVers,
3625 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003626 },
3627 flags: flags,
3628 expectedVersion: expectedVersion,
3629 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003630 testCases = append(testCases, testCase{
3631 protocol: protocol,
3632 testType: clientTest,
3633 name: "VersionNegotiation-Client2-" + suffix,
3634 config: Config{
3635 MaxVersion: runnerVers.version,
3636 Bugs: ProtocolBugs{
3637 ExpectInitialRecordVersion: clientVers,
3638 },
3639 },
3640 flags: []string{"-max-version", shimVersFlag},
3641 expectedVersion: expectedVersion,
3642 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003643
3644 testCases = append(testCases, testCase{
3645 protocol: protocol,
3646 testType: serverTest,
3647 name: "VersionNegotiation-Server-" + suffix,
3648 config: Config{
3649 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003650 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003651 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003652 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003653 },
3654 flags: flags,
3655 expectedVersion: expectedVersion,
3656 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003657 testCases = append(testCases, testCase{
3658 protocol: protocol,
3659 testType: serverTest,
3660 name: "VersionNegotiation-Server2-" + suffix,
3661 config: Config{
3662 MaxVersion: runnerVers.version,
3663 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07003664 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05003665 },
3666 },
3667 flags: []string{"-max-version", shimVersFlag},
3668 expectedVersion: expectedVersion,
3669 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003670 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003671 }
3672 }
David Benjamin95c69562016-06-29 18:15:03 -04003673
3674 // Test for version tolerance.
3675 testCases = append(testCases, testCase{
3676 testType: serverTest,
3677 name: "MinorVersionTolerance",
3678 config: Config{
3679 Bugs: ProtocolBugs{
3680 SendClientVersion: 0x03ff,
3681 },
3682 },
3683 expectedVersion: VersionTLS13,
3684 })
3685 testCases = append(testCases, testCase{
3686 testType: serverTest,
3687 name: "MajorVersionTolerance",
3688 config: Config{
3689 Bugs: ProtocolBugs{
3690 SendClientVersion: 0x0400,
3691 },
3692 },
3693 expectedVersion: VersionTLS13,
3694 })
3695 testCases = append(testCases, testCase{
3696 protocol: dtls,
3697 testType: serverTest,
3698 name: "MinorVersionTolerance-DTLS",
3699 config: Config{
3700 Bugs: ProtocolBugs{
3701 SendClientVersion: 0x03ff,
3702 },
3703 },
3704 expectedVersion: VersionTLS12,
3705 })
3706 testCases = append(testCases, testCase{
3707 protocol: dtls,
3708 testType: serverTest,
3709 name: "MajorVersionTolerance-DTLS",
3710 config: Config{
3711 Bugs: ProtocolBugs{
3712 SendClientVersion: 0x0400,
3713 },
3714 },
3715 expectedVersion: VersionTLS12,
3716 })
3717
3718 // Test that versions below 3.0 are rejected.
3719 testCases = append(testCases, testCase{
3720 testType: serverTest,
3721 name: "VersionTooLow",
3722 config: Config{
3723 Bugs: ProtocolBugs{
3724 SendClientVersion: 0x0200,
3725 },
3726 },
3727 shouldFail: true,
3728 expectedError: ":UNSUPPORTED_PROTOCOL:",
3729 })
3730 testCases = append(testCases, testCase{
3731 protocol: dtls,
3732 testType: serverTest,
3733 name: "VersionTooLow-DTLS",
3734 config: Config{
3735 Bugs: ProtocolBugs{
3736 // 0x0201 is the lowest version expressable in
3737 // DTLS.
3738 SendClientVersion: 0x0201,
3739 },
3740 },
3741 shouldFail: true,
3742 expectedError: ":UNSUPPORTED_PROTOCOL:",
3743 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003744}
3745
David Benjaminaccb4542014-12-12 23:44:33 -05003746func addMinimumVersionTests() {
3747 for i, shimVers := range tlsVersions {
3748 // Assemble flags to disable all older versions on the shim.
3749 var flags []string
3750 for _, vers := range tlsVersions[:i] {
3751 flags = append(flags, vers.flag)
3752 }
3753
3754 for _, runnerVers := range tlsVersions {
3755 protocols := []protocol{tls}
3756 if runnerVers.hasDTLS && shimVers.hasDTLS {
3757 protocols = append(protocols, dtls)
3758 }
3759 for _, protocol := range protocols {
3760 suffix := shimVers.name + "-" + runnerVers.name
3761 if protocol == dtls {
3762 suffix += "-DTLS"
3763 }
3764 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3765
David Benjaminaccb4542014-12-12 23:44:33 -05003766 var expectedVersion uint16
3767 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04003768 var expectedClientError, expectedServerError string
3769 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003770 if runnerVers.version >= shimVers.version {
3771 expectedVersion = runnerVers.version
3772 } else {
3773 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04003774 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
3775 expectedServerLocalError = "remote error: protocol version not supported"
3776 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
3777 // If the client's minimum version is TLS 1.3 and the runner's
3778 // maximum is below TLS 1.2, the runner will fail to select a
3779 // cipher before the shim rejects the selected version.
3780 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
3781 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
3782 } else {
3783 expectedClientError = expectedServerError
3784 expectedClientLocalError = expectedServerLocalError
3785 }
David Benjaminaccb4542014-12-12 23:44:33 -05003786 }
3787
3788 testCases = append(testCases, testCase{
3789 protocol: protocol,
3790 testType: clientTest,
3791 name: "MinimumVersion-Client-" + suffix,
3792 config: Config{
3793 MaxVersion: runnerVers.version,
3794 },
David Benjamin87909c02014-12-13 01:55:01 -05003795 flags: flags,
3796 expectedVersion: expectedVersion,
3797 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003798 expectedError: expectedClientError,
3799 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003800 })
3801 testCases = append(testCases, testCase{
3802 protocol: protocol,
3803 testType: clientTest,
3804 name: "MinimumVersion-Client2-" + suffix,
3805 config: Config{
3806 MaxVersion: runnerVers.version,
3807 },
David Benjamin87909c02014-12-13 01:55:01 -05003808 flags: []string{"-min-version", shimVersFlag},
3809 expectedVersion: expectedVersion,
3810 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003811 expectedError: expectedClientError,
3812 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003813 })
3814
3815 testCases = append(testCases, testCase{
3816 protocol: protocol,
3817 testType: serverTest,
3818 name: "MinimumVersion-Server-" + suffix,
3819 config: Config{
3820 MaxVersion: runnerVers.version,
3821 },
David Benjamin87909c02014-12-13 01:55:01 -05003822 flags: flags,
3823 expectedVersion: expectedVersion,
3824 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003825 expectedError: expectedServerError,
3826 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003827 })
3828 testCases = append(testCases, testCase{
3829 protocol: protocol,
3830 testType: serverTest,
3831 name: "MinimumVersion-Server2-" + suffix,
3832 config: Config{
3833 MaxVersion: runnerVers.version,
3834 },
David Benjamin87909c02014-12-13 01:55:01 -05003835 flags: []string{"-min-version", shimVersFlag},
3836 expectedVersion: expectedVersion,
3837 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04003838 expectedError: expectedServerError,
3839 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003840 })
3841 }
3842 }
3843 }
3844}
3845
David Benjamine78bfde2014-09-06 12:45:15 -04003846func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003847 // TODO(davidben): Extensions, where applicable, all move their server
3848 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
3849 // tests for both. Also test interaction with 0-RTT when implemented.
3850
David Benjamine78bfde2014-09-06 12:45:15 -04003851 testCases = append(testCases, testCase{
3852 testType: clientTest,
3853 name: "DuplicateExtensionClient",
3854 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003855 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003856 Bugs: ProtocolBugs{
3857 DuplicateExtension: true,
3858 },
3859 },
3860 shouldFail: true,
3861 expectedLocalError: "remote error: error decoding message",
3862 })
3863 testCases = append(testCases, testCase{
3864 testType: serverTest,
3865 name: "DuplicateExtensionServer",
3866 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003867 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003868 Bugs: ProtocolBugs{
3869 DuplicateExtension: true,
3870 },
3871 },
3872 shouldFail: true,
3873 expectedLocalError: "remote error: error decoding message",
3874 })
3875 testCases = append(testCases, testCase{
3876 testType: clientTest,
3877 name: "ServerNameExtensionClient",
3878 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003879 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003880 Bugs: ProtocolBugs{
3881 ExpectServerName: "example.com",
3882 },
3883 },
3884 flags: []string{"-host-name", "example.com"},
3885 })
3886 testCases = append(testCases, testCase{
3887 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003888 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003889 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003890 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003891 Bugs: ProtocolBugs{
3892 ExpectServerName: "mismatch.com",
3893 },
3894 },
3895 flags: []string{"-host-name", "example.com"},
3896 shouldFail: true,
3897 expectedLocalError: "tls: unexpected server name",
3898 })
3899 testCases = append(testCases, testCase{
3900 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003901 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003902 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003903 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003904 Bugs: ProtocolBugs{
3905 ExpectServerName: "missing.com",
3906 },
3907 },
3908 shouldFail: true,
3909 expectedLocalError: "tls: unexpected server name",
3910 })
3911 testCases = append(testCases, testCase{
3912 testType: serverTest,
3913 name: "ServerNameExtensionServer",
3914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003915 MaxVersion: VersionTLS12,
David Benjamine78bfde2014-09-06 12:45:15 -04003916 ServerName: "example.com",
3917 },
3918 flags: []string{"-expect-server-name", "example.com"},
3919 resumeSession: true,
3920 })
David Benjaminae2888f2014-09-06 12:58:58 -04003921 testCases = append(testCases, testCase{
3922 testType: clientTest,
3923 name: "ALPNClient",
3924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003925 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003926 NextProtos: []string{"foo"},
3927 },
3928 flags: []string{
3929 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3930 "-expect-alpn", "foo",
3931 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003932 expectedNextProto: "foo",
3933 expectedNextProtoType: alpn,
3934 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003935 })
3936 testCases = append(testCases, testCase{
3937 testType: serverTest,
3938 name: "ALPNServer",
3939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003940 MaxVersion: VersionTLS12,
David Benjaminae2888f2014-09-06 12:58:58 -04003941 NextProtos: []string{"foo", "bar", "baz"},
3942 },
3943 flags: []string{
3944 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3945 "-select-alpn", "foo",
3946 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003947 expectedNextProto: "foo",
3948 expectedNextProtoType: alpn,
3949 resumeSession: true,
3950 })
David Benjamin594e7d22016-03-17 17:49:56 -04003951 testCases = append(testCases, testCase{
3952 testType: serverTest,
3953 name: "ALPNServer-Decline",
3954 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003955 MaxVersion: VersionTLS12,
David Benjamin594e7d22016-03-17 17:49:56 -04003956 NextProtos: []string{"foo", "bar", "baz"},
3957 },
3958 flags: []string{"-decline-alpn"},
3959 expectNoNextProto: true,
3960 resumeSession: true,
3961 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003962 // Test that the server prefers ALPN over NPN.
3963 testCases = append(testCases, testCase{
3964 testType: serverTest,
3965 name: "ALPNServer-Preferred",
3966 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003967 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003968 NextProtos: []string{"foo", "bar", "baz"},
3969 },
3970 flags: []string{
3971 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3972 "-select-alpn", "foo",
3973 "-advertise-npn", "\x03foo\x03bar\x03baz",
3974 },
3975 expectedNextProto: "foo",
3976 expectedNextProtoType: alpn,
3977 resumeSession: true,
3978 })
3979 testCases = append(testCases, testCase{
3980 testType: serverTest,
3981 name: "ALPNServer-Preferred-Swapped",
3982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003983 MaxVersion: VersionTLS12,
David Benjaminfc7b0862014-09-06 13:21:53 -04003984 NextProtos: []string{"foo", "bar", "baz"},
3985 Bugs: ProtocolBugs{
3986 SwapNPNAndALPN: true,
3987 },
3988 },
3989 flags: []string{
3990 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3991 "-select-alpn", "foo",
3992 "-advertise-npn", "\x03foo\x03bar\x03baz",
3993 },
3994 expectedNextProto: "foo",
3995 expectedNextProtoType: alpn,
3996 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003997 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003998 var emptyString string
3999 testCases = append(testCases, testCase{
4000 testType: clientTest,
4001 name: "ALPNClient-EmptyProtocolName",
4002 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004003 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07004004 NextProtos: []string{""},
4005 Bugs: ProtocolBugs{
4006 // A server returning an empty ALPN protocol
4007 // should be rejected.
4008 ALPNProtocol: &emptyString,
4009 },
4010 },
4011 flags: []string{
4012 "-advertise-alpn", "\x03foo",
4013 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07004014 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07004015 expectedError: ":PARSE_TLSEXT:",
4016 })
4017 testCases = append(testCases, testCase{
4018 testType: serverTest,
4019 name: "ALPNServer-EmptyProtocolName",
4020 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021 MaxVersion: VersionTLS12,
Adam Langleyefb0e162015-07-09 11:35:04 -07004022 // A ClientHello containing an empty ALPN protocol
4023 // should be rejected.
4024 NextProtos: []string{"foo", "", "baz"},
4025 },
4026 flags: []string{
4027 "-select-alpn", "foo",
4028 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07004029 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07004030 expectedError: ":PARSE_TLSEXT:",
4031 })
David Benjamin76c2efc2015-08-31 14:24:29 -04004032 // Test that negotiating both NPN and ALPN is forbidden.
4033 testCases = append(testCases, testCase{
4034 name: "NegotiateALPNAndNPN",
4035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04004037 NextProtos: []string{"foo", "bar", "baz"},
4038 Bugs: ProtocolBugs{
4039 NegotiateALPNAndNPN: true,
4040 },
4041 },
4042 flags: []string{
4043 "-advertise-alpn", "\x03foo",
4044 "-select-next-proto", "foo",
4045 },
4046 shouldFail: true,
4047 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4048 })
4049 testCases = append(testCases, testCase{
4050 name: "NegotiateALPNAndNPN-Swapped",
4051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004052 MaxVersion: VersionTLS12,
David Benjamin76c2efc2015-08-31 14:24:29 -04004053 NextProtos: []string{"foo", "bar", "baz"},
4054 Bugs: ProtocolBugs{
4055 NegotiateALPNAndNPN: true,
4056 SwapNPNAndALPN: true,
4057 },
4058 },
4059 flags: []string{
4060 "-advertise-alpn", "\x03foo",
4061 "-select-next-proto", "foo",
4062 },
4063 shouldFail: true,
4064 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4065 })
David Benjamin091c4b92015-10-26 13:33:21 -04004066 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4067 testCases = append(testCases, testCase{
4068 name: "DisableNPN",
4069 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004070 MaxVersion: VersionTLS12,
David Benjamin091c4b92015-10-26 13:33:21 -04004071 NextProtos: []string{"foo"},
4072 },
4073 flags: []string{
4074 "-select-next-proto", "foo",
4075 "-disable-npn",
4076 },
4077 expectNoNextProto: true,
4078 })
Adam Langley38311732014-10-16 19:04:35 -07004079 // Resume with a corrupt ticket.
4080 testCases = append(testCases, testCase{
4081 testType: serverTest,
4082 name: "CorruptTicket",
4083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004084 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004085 Bugs: ProtocolBugs{
4086 CorruptTicket: true,
4087 },
4088 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004089 resumeSession: true,
4090 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07004091 })
David Benjamind98452d2015-06-16 14:16:23 -04004092 // Test the ticket callback, with and without renewal.
4093 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004094 testType: serverTest,
4095 name: "TicketCallback",
4096 config: Config{
4097 MaxVersion: VersionTLS12,
4098 },
David Benjamind98452d2015-06-16 14:16:23 -04004099 resumeSession: true,
4100 flags: []string{"-use-ticket-callback"},
4101 })
4102 testCases = append(testCases, testCase{
4103 testType: serverTest,
4104 name: "TicketCallback-Renew",
4105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004106 MaxVersion: VersionTLS12,
David Benjamind98452d2015-06-16 14:16:23 -04004107 Bugs: ProtocolBugs{
4108 ExpectNewTicket: true,
4109 },
4110 },
4111 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4112 resumeSession: true,
4113 })
Adam Langley38311732014-10-16 19:04:35 -07004114 // Resume with an oversized session id.
4115 testCases = append(testCases, testCase{
4116 testType: serverTest,
4117 name: "OversizedSessionId",
4118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004119 MaxVersion: VersionTLS12,
Adam Langley38311732014-10-16 19:04:35 -07004120 Bugs: ProtocolBugs{
4121 OversizedSessionId: true,
4122 },
4123 },
4124 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07004125 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07004126 expectedError: ":DECODE_ERROR:",
4127 })
David Benjaminca6c8262014-11-15 19:06:08 -05004128 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4129 // are ignored.
4130 testCases = append(testCases, testCase{
4131 protocol: dtls,
4132 name: "SRTP-Client",
4133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004134 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004135 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4136 },
4137 flags: []string{
4138 "-srtp-profiles",
4139 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4140 },
4141 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4142 })
4143 testCases = append(testCases, testCase{
4144 protocol: dtls,
4145 testType: serverTest,
4146 name: "SRTP-Server",
4147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004148 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004149 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4150 },
4151 flags: []string{
4152 "-srtp-profiles",
4153 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4154 },
4155 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4156 })
4157 // Test that the MKI is ignored.
4158 testCases = append(testCases, testCase{
4159 protocol: dtls,
4160 testType: serverTest,
4161 name: "SRTP-Server-IgnoreMKI",
4162 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004163 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004164 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4165 Bugs: ProtocolBugs{
4166 SRTPMasterKeyIdentifer: "bogus",
4167 },
4168 },
4169 flags: []string{
4170 "-srtp-profiles",
4171 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4172 },
4173 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4174 })
4175 // Test that SRTP isn't negotiated on the server if there were
4176 // no matching profiles.
4177 testCases = append(testCases, testCase{
4178 protocol: dtls,
4179 testType: serverTest,
4180 name: "SRTP-Server-NoMatch",
4181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004182 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004183 SRTPProtectionProfiles: []uint16{100, 101, 102},
4184 },
4185 flags: []string{
4186 "-srtp-profiles",
4187 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4188 },
4189 expectedSRTPProtectionProfile: 0,
4190 })
4191 // Test that the server returning an invalid SRTP profile is
4192 // flagged as an error by the client.
4193 testCases = append(testCases, testCase{
4194 protocol: dtls,
4195 name: "SRTP-Client-NoMatch",
4196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004197 MaxVersion: VersionTLS12,
David Benjaminca6c8262014-11-15 19:06:08 -05004198 Bugs: ProtocolBugs{
4199 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4200 },
4201 },
4202 flags: []string{
4203 "-srtp-profiles",
4204 "SRTP_AES128_CM_SHA1_80",
4205 },
4206 shouldFail: true,
4207 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4208 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004209 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05004210 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004211 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004212 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004213 config: Config{
4214 MaxVersion: VersionTLS12,
4215 },
David Benjamin61f95272014-11-25 01:55:35 -05004216 flags: []string{
4217 "-enable-signed-cert-timestamps",
4218 "-expect-signed-cert-timestamps",
4219 base64.StdEncoding.EncodeToString(testSCTList),
4220 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004221 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05004222 })
Adam Langley33ad2b52015-07-20 17:43:53 -07004223 testCases = append(testCases, testCase{
David Benjamin80d1b352016-05-04 19:19:06 -04004224 name: "SendSCTListOnResume",
4225 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004226 MaxVersion: VersionTLS12,
David Benjamin80d1b352016-05-04 19:19:06 -04004227 Bugs: ProtocolBugs{
4228 SendSCTListOnResume: []byte("bogus"),
4229 },
4230 },
4231 flags: []string{
4232 "-enable-signed-cert-timestamps",
4233 "-expect-signed-cert-timestamps",
4234 base64.StdEncoding.EncodeToString(testSCTList),
4235 },
4236 resumeSession: true,
4237 })
4238 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04004239 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01004240 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004241 config: Config{
4242 MaxVersion: VersionTLS12,
4243 },
Paul Lietar4fac72e2015-09-09 13:44:55 +01004244 flags: []string{
4245 "-signed-cert-timestamps",
4246 base64.StdEncoding.EncodeToString(testSCTList),
4247 },
4248 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01004249 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01004250 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004251
Paul Lietar4fac72e2015-09-09 13:44:55 +01004252 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004253 testType: clientTest,
4254 name: "ClientHelloPadding",
4255 config: Config{
4256 Bugs: ProtocolBugs{
4257 RequireClientHelloSize: 512,
4258 },
4259 },
4260 // This hostname just needs to be long enough to push the
4261 // ClientHello into F5's danger zone between 256 and 511 bytes
4262 // long.
4263 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4264 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004265
4266 // Extensions should not function in SSL 3.0.
4267 testCases = append(testCases, testCase{
4268 testType: serverTest,
4269 name: "SSLv3Extensions-NoALPN",
4270 config: Config{
4271 MaxVersion: VersionSSL30,
4272 NextProtos: []string{"foo", "bar", "baz"},
4273 },
4274 flags: []string{
4275 "-select-alpn", "foo",
4276 },
4277 expectNoNextProto: true,
4278 })
4279
4280 // Test session tickets separately as they follow a different codepath.
4281 testCases = append(testCases, testCase{
4282 testType: serverTest,
4283 name: "SSLv3Extensions-NoTickets",
4284 config: Config{
4285 MaxVersion: VersionSSL30,
4286 Bugs: ProtocolBugs{
4287 // Historically, session tickets in SSL 3.0
4288 // failed in different ways depending on whether
4289 // the client supported renegotiation_info.
4290 NoRenegotiationInfo: true,
4291 },
4292 },
4293 resumeSession: true,
4294 })
4295 testCases = append(testCases, testCase{
4296 testType: serverTest,
4297 name: "SSLv3Extensions-NoTickets2",
4298 config: Config{
4299 MaxVersion: VersionSSL30,
4300 },
4301 resumeSession: true,
4302 })
4303
4304 // But SSL 3.0 does send and process renegotiation_info.
4305 testCases = append(testCases, testCase{
4306 testType: serverTest,
4307 name: "SSLv3Extensions-RenegotiationInfo",
4308 config: Config{
4309 MaxVersion: VersionSSL30,
4310 Bugs: ProtocolBugs{
4311 RequireRenegotiationInfo: true,
4312 },
4313 },
4314 })
4315 testCases = append(testCases, testCase{
4316 testType: serverTest,
4317 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4318 config: Config{
4319 MaxVersion: VersionSSL30,
4320 Bugs: ProtocolBugs{
4321 NoRenegotiationInfo: true,
4322 SendRenegotiationSCSV: true,
4323 RequireRenegotiationInfo: true,
4324 },
4325 },
4326 })
David Benjamine78bfde2014-09-06 12:45:15 -04004327}
4328
David Benjamin01fe8202014-09-24 15:21:44 -04004329func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04004330 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04004331 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07004332 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
4333 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
4334 // TLS 1.3 only shares ciphers with TLS 1.2, so
4335 // we skip certain combinations and use a
4336 // different cipher to test with.
4337 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
4338 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
4339 continue
4340 }
4341 }
4342
David Benjamin8b8c0062014-11-23 02:47:52 -05004343 protocols := []protocol{tls}
4344 if sessionVers.hasDTLS && resumeVers.hasDTLS {
4345 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05004346 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004347 for _, protocol := range protocols {
4348 suffix := "-" + sessionVers.name + "-" + resumeVers.name
4349 if protocol == dtls {
4350 suffix += "-DTLS"
4351 }
4352
David Benjaminece3de92015-03-16 18:02:20 -04004353 if sessionVers.version == resumeVers.version {
4354 testCases = append(testCases, testCase{
4355 protocol: protocol,
4356 name: "Resume-Client" + suffix,
4357 resumeSession: true,
4358 config: Config{
4359 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004360 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004361 },
David Benjaminece3de92015-03-16 18:02:20 -04004362 expectedVersion: sessionVers.version,
4363 expectedResumeVersion: resumeVers.version,
4364 })
4365 } else {
4366 testCases = append(testCases, testCase{
4367 protocol: protocol,
4368 name: "Resume-Client-Mismatch" + suffix,
4369 resumeSession: true,
4370 config: Config{
4371 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004372 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004373 },
David Benjaminece3de92015-03-16 18:02:20 -04004374 expectedVersion: sessionVers.version,
4375 resumeConfig: &Config{
4376 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004377 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04004378 Bugs: ProtocolBugs{
4379 AllowSessionVersionMismatch: true,
4380 },
4381 },
4382 expectedResumeVersion: resumeVers.version,
4383 shouldFail: true,
4384 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4385 })
4386 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004387
4388 testCases = append(testCases, testCase{
4389 protocol: protocol,
4390 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004391 resumeSession: true,
4392 config: Config{
4393 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004394 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004395 },
4396 expectedVersion: sessionVers.version,
4397 resumeConfig: &Config{
4398 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004399 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004400 },
4401 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004402 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004403 expectedResumeVersion: resumeVers.version,
4404 })
4405
David Benjamin8b8c0062014-11-23 02:47:52 -05004406 testCases = append(testCases, testCase{
4407 protocol: protocol,
4408 testType: serverTest,
4409 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004410 resumeSession: true,
4411 config: Config{
4412 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004413 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004414 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004415 expectedVersion: sessionVers.version,
4416 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004417 resumeConfig: &Config{
4418 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07004419 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05004420 },
4421 expectedResumeVersion: resumeVers.version,
4422 })
4423 }
David Benjamin01fe8202014-09-24 15:21:44 -04004424 }
4425 }
David Benjaminece3de92015-03-16 18:02:20 -04004426
Nick Harper1fd39d82016-06-14 18:14:35 -07004427 // TODO(davidben): This test should have a TLS 1.3 variant later.
David Benjaminece3de92015-03-16 18:02:20 -04004428 testCases = append(testCases, testCase{
4429 name: "Resume-Client-CipherMismatch",
4430 resumeSession: true,
4431 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004432 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004433 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4434 },
4435 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004436 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04004437 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4438 Bugs: ProtocolBugs{
4439 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4440 },
4441 },
4442 shouldFail: true,
4443 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4444 })
David Benjamin01fe8202014-09-24 15:21:44 -04004445}
4446
Adam Langley2ae77d22014-10-28 17:29:33 -07004447func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004448 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004449 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004450 testType: serverTest,
4451 name: "Renegotiate-Server-Forbidden",
4452 config: Config{
4453 MaxVersion: VersionTLS12,
4454 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004455 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004456 shouldFail: true,
4457 expectedError: ":NO_RENEGOTIATION:",
4458 expectedLocalError: "remote error: no renegotiation",
4459 })
Adam Langley5021b222015-06-12 18:27:58 -07004460 // The server shouldn't echo the renegotiation extension unless
4461 // requested by the client.
4462 testCases = append(testCases, testCase{
4463 testType: serverTest,
4464 name: "Renegotiate-Server-NoExt",
4465 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004466 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004467 Bugs: ProtocolBugs{
4468 NoRenegotiationInfo: true,
4469 RequireRenegotiationInfo: true,
4470 },
4471 },
4472 shouldFail: true,
4473 expectedLocalError: "renegotiation extension missing",
4474 })
4475 // The renegotiation SCSV should be sufficient for the server to echo
4476 // the extension.
4477 testCases = append(testCases, testCase{
4478 testType: serverTest,
4479 name: "Renegotiate-Server-NoExt-SCSV",
4480 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004481 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07004482 Bugs: ProtocolBugs{
4483 NoRenegotiationInfo: true,
4484 SendRenegotiationSCSV: true,
4485 RequireRenegotiationInfo: true,
4486 },
4487 },
4488 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004489 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004490 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004491 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004492 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04004493 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004494 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004495 },
4496 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004497 renegotiate: 1,
4498 flags: []string{
4499 "-renegotiate-freely",
4500 "-expect-total-renegotiations", "1",
4501 },
David Benjamincdea40c2015-03-19 14:09:43 -04004502 })
4503 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004504 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004505 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004507 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004508 Bugs: ProtocolBugs{
4509 EmptyRenegotiationInfo: true,
4510 },
4511 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004512 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004513 shouldFail: true,
4514 expectedError: ":RENEGOTIATION_MISMATCH:",
4515 })
4516 testCases = append(testCases, testCase{
4517 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004518 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004520 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004521 Bugs: ProtocolBugs{
4522 BadRenegotiationInfo: true,
4523 },
4524 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004525 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004526 shouldFail: true,
4527 expectedError: ":RENEGOTIATION_MISMATCH:",
4528 })
4529 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004530 name: "Renegotiate-Client-Downgrade",
4531 renegotiate: 1,
4532 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004533 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004534 Bugs: ProtocolBugs{
4535 NoRenegotiationInfoAfterInitial: true,
4536 },
4537 },
4538 flags: []string{"-renegotiate-freely"},
4539 shouldFail: true,
4540 expectedError: ":RENEGOTIATION_MISMATCH:",
4541 })
4542 testCases = append(testCases, testCase{
4543 name: "Renegotiate-Client-Upgrade",
4544 renegotiate: 1,
4545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004546 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05004547 Bugs: ProtocolBugs{
4548 NoRenegotiationInfoInInitial: true,
4549 },
4550 },
4551 flags: []string{"-renegotiate-freely"},
4552 shouldFail: true,
4553 expectedError: ":RENEGOTIATION_MISMATCH:",
4554 })
4555 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004556 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004557 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004558 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004559 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04004560 Bugs: ProtocolBugs{
4561 NoRenegotiationInfo: true,
4562 },
4563 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004564 flags: []string{
4565 "-renegotiate-freely",
4566 "-expect-total-renegotiations", "1",
4567 },
David Benjamincff0b902015-05-15 23:09:47 -04004568 })
4569 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004570 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004571 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004572 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004573 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004574 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4575 },
4576 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004577 flags: []string{
4578 "-renegotiate-freely",
4579 "-expect-total-renegotiations", "1",
4580 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004581 })
4582 testCases = append(testCases, testCase{
4583 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004584 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004585 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004586 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004587 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4588 },
4589 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004590 flags: []string{
4591 "-renegotiate-freely",
4592 "-expect-total-renegotiations", "1",
4593 },
David Benjaminb16346b2015-04-08 19:16:58 -04004594 })
4595 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004596 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004597 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004598 config: Config{
4599 MaxVersion: VersionTLS10,
4600 Bugs: ProtocolBugs{
4601 RequireSameRenegoClientVersion: true,
4602 },
4603 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004604 flags: []string{
4605 "-renegotiate-freely",
4606 "-expect-total-renegotiations", "1",
4607 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004608 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004609 testCases = append(testCases, testCase{
4610 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004611 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004612 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004613 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004614 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4615 NextProtos: []string{"foo"},
4616 },
4617 flags: []string{
4618 "-false-start",
4619 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004620 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004621 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004622 },
4623 shimWritesFirst: true,
4624 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004625
4626 // Client-side renegotiation controls.
4627 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004628 name: "Renegotiate-Client-Forbidden-1",
4629 config: Config{
4630 MaxVersion: VersionTLS12,
4631 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004632 renegotiate: 1,
4633 shouldFail: true,
4634 expectedError: ":NO_RENEGOTIATION:",
4635 expectedLocalError: "remote error: no renegotiation",
4636 })
4637 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004638 name: "Renegotiate-Client-Once-1",
4639 config: Config{
4640 MaxVersion: VersionTLS12,
4641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004642 renegotiate: 1,
4643 flags: []string{
4644 "-renegotiate-once",
4645 "-expect-total-renegotiations", "1",
4646 },
4647 })
4648 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004649 name: "Renegotiate-Client-Freely-1",
4650 config: Config{
4651 MaxVersion: VersionTLS12,
4652 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004653 renegotiate: 1,
4654 flags: []string{
4655 "-renegotiate-freely",
4656 "-expect-total-renegotiations", "1",
4657 },
4658 })
4659 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004660 name: "Renegotiate-Client-Once-2",
4661 config: Config{
4662 MaxVersion: VersionTLS12,
4663 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004664 renegotiate: 2,
4665 flags: []string{"-renegotiate-once"},
4666 shouldFail: true,
4667 expectedError: ":NO_RENEGOTIATION:",
4668 expectedLocalError: "remote error: no renegotiation",
4669 })
4670 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004671 name: "Renegotiate-Client-Freely-2",
4672 config: Config{
4673 MaxVersion: VersionTLS12,
4674 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004675 renegotiate: 2,
4676 flags: []string{
4677 "-renegotiate-freely",
4678 "-expect-total-renegotiations", "2",
4679 },
4680 })
Adam Langley27a0d082015-11-03 13:34:10 -08004681 testCases = append(testCases, testCase{
4682 name: "Renegotiate-Client-NoIgnore",
4683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004684 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004685 Bugs: ProtocolBugs{
4686 SendHelloRequestBeforeEveryAppDataRecord: true,
4687 },
4688 },
4689 shouldFail: true,
4690 expectedError: ":NO_RENEGOTIATION:",
4691 })
4692 testCases = append(testCases, testCase{
4693 name: "Renegotiate-Client-Ignore",
4694 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004695 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08004696 Bugs: ProtocolBugs{
4697 SendHelloRequestBeforeEveryAppDataRecord: true,
4698 },
4699 },
4700 flags: []string{
4701 "-renegotiate-ignore",
4702 "-expect-total-renegotiations", "0",
4703 },
4704 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004705
4706 // TODO(davidben): Add a test that HelloRequests are illegal in TLS 1.3.
Adam Langley2ae77d22014-10-28 17:29:33 -07004707}
4708
David Benjamin5e961c12014-11-07 01:48:35 -05004709func addDTLSReplayTests() {
4710 // Test that sequence number replays are detected.
4711 testCases = append(testCases, testCase{
4712 protocol: dtls,
4713 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004714 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004715 replayWrites: true,
4716 })
4717
David Benjamin8e6db492015-07-25 18:29:23 -04004718 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004719 // than the retransmit window.
4720 testCases = append(testCases, testCase{
4721 protocol: dtls,
4722 name: "DTLS-Replay-LargeGaps",
4723 config: Config{
4724 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004725 SequenceNumberMapping: func(in uint64) uint64 {
4726 return in * 127
4727 },
David Benjamin5e961c12014-11-07 01:48:35 -05004728 },
4729 },
David Benjamin8e6db492015-07-25 18:29:23 -04004730 messageCount: 200,
4731 replayWrites: true,
4732 })
4733
4734 // Test the incoming sequence number changing non-monotonically.
4735 testCases = append(testCases, testCase{
4736 protocol: dtls,
4737 name: "DTLS-Replay-NonMonotonic",
4738 config: Config{
4739 Bugs: ProtocolBugs{
4740 SequenceNumberMapping: func(in uint64) uint64 {
4741 return in ^ 31
4742 },
4743 },
4744 },
4745 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004746 replayWrites: true,
4747 })
4748}
4749
Nick Harper60edffd2016-06-21 15:19:24 -07004750var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05004751 name string
Nick Harper60edffd2016-06-21 15:19:24 -07004752 id signatureAlgorithm
4753 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05004754}{
Nick Harper60edffd2016-06-21 15:19:24 -07004755 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
4756 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
4757 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
4758 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
4759 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSA},
4760 // TODO(davidben): These signature algorithms are paired with a curve in
4761 // TLS 1.3. Test that, in TLS 1.3, the curves must match and, in TLS
4762 // 1.2, mismatches are tolerated.
4763 {"ECDSA-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSA},
4764 {"ECDSA-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSA},
4765 {"ECDSA-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSA},
David Benjamin000800a2014-11-14 01:43:59 -05004766}
4767
Nick Harper60edffd2016-06-21 15:19:24 -07004768const fakeSigAlg1 signatureAlgorithm = 0x2a01
4769const fakeSigAlg2 signatureAlgorithm = 0xff01
4770
4771func addSignatureAlgorithmTests() {
4772 // Make sure each signature algorithm works. Include some fake values in
4773 // the list and ensure they're ignored.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004774 //
4775 // TODO(davidben): Test each of these against both TLS 1.2 and TLS 1.3.
Nick Harper60edffd2016-06-21 15:19:24 -07004776 for _, alg := range testSignatureAlgorithms {
David Benjamin000800a2014-11-14 01:43:59 -05004777 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004778 name: "SigningHash-ClientAuth-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004780 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004781 // SignatureAlgorithms is shared, so we must
4782 // configure a matching server certificate too.
4783 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4784 ClientAuth: RequireAnyClientCert,
4785 SignatureAlgorithms: []signatureAlgorithm{
4786 fakeSigAlg1,
4787 alg.id,
4788 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004789 },
4790 },
4791 flags: []string{
Nick Harper60edffd2016-06-21 15:19:24 -07004792 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4793 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4794 },
4795 expectedPeerSignatureAlgorithm: alg.id,
4796 })
4797
4798 testCases = append(testCases, testCase{
4799 testType: serverTest,
4800 name: "SigningHash-ClientAuth-Verify-" + alg.name,
4801 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004802 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004803 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4804 SignatureAlgorithms: []signatureAlgorithm{
4805 alg.id,
4806 },
4807 },
4808 flags: []string{
4809 "-require-any-client-certificate",
4810 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
4811 // SignatureAlgorithms is shared, so we must
4812 // configure a matching server certificate too.
4813 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4814 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
David Benjamin000800a2014-11-14 01:43:59 -05004815 },
4816 })
4817
4818 testCases = append(testCases, testCase{
4819 testType: serverTest,
Nick Harper60edffd2016-06-21 15:19:24 -07004820 name: "SigningHash-ServerKeyExchange-Sign-" + alg.name,
David Benjamin000800a2014-11-14 01:43:59 -05004821 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004822 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004823 CipherSuites: []uint16{
4824 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4825 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4826 },
4827 SignatureAlgorithms: []signatureAlgorithm{
4828 fakeSigAlg1,
4829 alg.id,
4830 fakeSigAlg2,
David Benjamin000800a2014-11-14 01:43:59 -05004831 },
4832 },
Nick Harper60edffd2016-06-21 15:19:24 -07004833 flags: []string{
4834 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
4835 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
4836 },
4837 expectedPeerSignatureAlgorithm: alg.id,
David Benjamin000800a2014-11-14 01:43:59 -05004838 })
David Benjamin6e807652015-11-02 12:02:20 -05004839
4840 testCases = append(testCases, testCase{
Nick Harper60edffd2016-06-21 15:19:24 -07004841 name: "SigningHash-ServerKeyExchange-Verify-" + alg.name,
David Benjamin6e807652015-11-02 12:02:20 -05004842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004843 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004844 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
4845 CipherSuites: []uint16{
4846 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
4847 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
4848 },
4849 SignatureAlgorithms: []signatureAlgorithm{
4850 alg.id,
David Benjamin6e807652015-11-02 12:02:20 -05004851 },
4852 },
Nick Harper60edffd2016-06-21 15:19:24 -07004853 flags: []string{"-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id))},
David Benjamin6e807652015-11-02 12:02:20 -05004854 })
David Benjamin000800a2014-11-14 01:43:59 -05004855 }
4856
Nick Harper60edffd2016-06-21 15:19:24 -07004857 // Test that algorithm selection takes the key type into account.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004858 //
4859 // TODO(davidben): Test this in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004860 testCases = append(testCases, testCase{
4861 name: "SigningHash-ClientAuth-SignatureType",
4862 config: Config{
4863 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004864 MaxVersion: VersionTLS12,
Nick Harper60edffd2016-06-21 15:19:24 -07004865 SignatureAlgorithms: []signatureAlgorithm{
4866 signatureECDSAWithP521AndSHA512,
4867 signatureRSAPKCS1WithSHA384,
4868 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004869 },
4870 },
4871 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004872 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4873 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004874 },
Nick Harper60edffd2016-06-21 15:19:24 -07004875 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004876 })
4877
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "SigningHash-ServerKeyExchange-SignatureType",
4881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004882 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004883 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004884 SignatureAlgorithms: []signatureAlgorithm{
4885 signatureECDSAWithP521AndSHA512,
4886 signatureRSAPKCS1WithSHA384,
4887 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004888 },
4889 },
Nick Harper60edffd2016-06-21 15:19:24 -07004890 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05004891 })
4892
4893 // Test that, if the list is missing, the peer falls back to SHA-1.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004894 //
4895 // TODO(davidben): Test this does not happen in TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05004896 testCases = append(testCases, testCase{
4897 name: "SigningHash-ClientAuth-Fallback",
4898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004899 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004900 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004901 SignatureAlgorithms: []signatureAlgorithm{
4902 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004903 },
4904 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004905 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004906 },
4907 },
4908 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004909 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4910 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004911 },
4912 })
4913
4914 testCases = append(testCases, testCase{
4915 testType: serverTest,
4916 name: "SigningHash-ServerKeyExchange-Fallback",
4917 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004918 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05004919 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004920 SignatureAlgorithms: []signatureAlgorithm{
4921 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05004922 },
4923 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07004924 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05004925 },
4926 },
4927 })
David Benjamin72dc7832015-03-16 17:49:43 -04004928
4929 // Test that hash preferences are enforced. BoringSSL defaults to
4930 // rejecting MD5 signatures.
4931 testCases = append(testCases, testCase{
4932 testType: serverTest,
4933 name: "SigningHash-ClientAuth-Enforced",
4934 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004935 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004936 Certificates: []Certificate{rsaCertificate},
Nick Harper60edffd2016-06-21 15:19:24 -07004937 SignatureAlgorithms: []signatureAlgorithm{
4938 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004939 // Advertise SHA-1 so the handshake will
4940 // proceed, but the shim's preferences will be
4941 // ignored in CertificateVerify generation, so
4942 // MD5 will be chosen.
Nick Harper60edffd2016-06-21 15:19:24 -07004943 signatureRSAPKCS1WithSHA1,
David Benjamin72dc7832015-03-16 17:49:43 -04004944 },
4945 Bugs: ProtocolBugs{
4946 IgnorePeerSignatureAlgorithmPreferences: true,
4947 },
4948 },
4949 flags: []string{"-require-any-client-certificate"},
4950 shouldFail: true,
4951 expectedError: ":WRONG_SIGNATURE_TYPE:",
4952 })
4953
4954 testCases = append(testCases, testCase{
4955 name: "SigningHash-ServerKeyExchange-Enforced",
4956 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004957 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04004958 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Nick Harper60edffd2016-06-21 15:19:24 -07004959 SignatureAlgorithms: []signatureAlgorithm{
4960 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04004961 },
4962 Bugs: ProtocolBugs{
4963 IgnorePeerSignatureAlgorithmPreferences: true,
4964 },
4965 },
4966 shouldFail: true,
4967 expectedError: ":WRONG_SIGNATURE_TYPE:",
4968 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004969
4970 // Test that the agreed upon digest respects the client preferences and
4971 // the server digests.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004972 //
4973 // TODO(davidben): Add TLS 1.3 versions of these.
Steven Valdez0d62f262015-09-04 12:41:04 -04004974 testCases = append(testCases, testCase{
4975 name: "Agree-Digest-Fallback",
4976 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004977 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004978 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004979 SignatureAlgorithms: []signatureAlgorithm{
4980 signatureRSAPKCS1WithSHA512,
4981 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004982 },
4983 },
4984 flags: []string{
4985 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4986 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4987 },
Nick Harper60edffd2016-06-21 15:19:24 -07004988 digestPrefs: "SHA256",
4989 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04004990 })
4991 testCases = append(testCases, testCase{
4992 name: "Agree-Digest-SHA256",
4993 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004994 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04004995 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07004996 SignatureAlgorithms: []signatureAlgorithm{
4997 signatureRSAPKCS1WithSHA1,
4998 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04004999 },
5000 },
5001 flags: []string{
5002 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5003 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5004 },
Nick Harper60edffd2016-06-21 15:19:24 -07005005 digestPrefs: "SHA256,SHA1",
5006 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005007 })
5008 testCases = append(testCases, testCase{
5009 name: "Agree-Digest-SHA1",
5010 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005011 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005012 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07005013 SignatureAlgorithms: []signatureAlgorithm{
5014 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005015 },
5016 },
5017 flags: []string{
5018 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5019 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5020 },
Nick Harper60edffd2016-06-21 15:19:24 -07005021 digestPrefs: "SHA512,SHA256,SHA1",
5022 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005023 })
5024 testCases = append(testCases, testCase{
5025 name: "Agree-Digest-Default",
5026 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005027 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04005028 ClientAuth: RequireAnyClientCert,
Nick Harper60edffd2016-06-21 15:19:24 -07005029 SignatureAlgorithms: []signatureAlgorithm{
5030 signatureRSAPKCS1WithSHA256,
5031 signatureECDSAWithP256AndSHA256,
5032 signatureRSAPKCS1WithSHA1,
5033 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04005034 },
5035 },
5036 flags: []string{
5037 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5038 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5039 },
Nick Harper60edffd2016-06-21 15:19:24 -07005040 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04005041 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005042
5043 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
5044 // signature algorithms.
5045 //
5046 // TODO(davidben): Add a TLS 1.3 version of this test where the mismatch
5047 // is allowed.
5048 testCases = append(testCases, testCase{
5049 name: "CheckLeafCurve",
5050 config: Config{
5051 MaxVersion: VersionTLS12,
5052 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
5053 Certificates: []Certificate{getECDSACertificate()},
5054 },
5055 flags: []string{"-p384-only"},
5056 shouldFail: true,
5057 expectedError: ":BAD_ECC_CERT:",
5058 })
David Benjamin000800a2014-11-14 01:43:59 -05005059}
5060
David Benjamin83f90402015-01-27 01:09:43 -05005061// timeouts is the retransmit schedule for BoringSSL. It doubles and
5062// caps at 60 seconds. On the 13th timeout, it gives up.
5063var timeouts = []time.Duration{
5064 1 * time.Second,
5065 2 * time.Second,
5066 4 * time.Second,
5067 8 * time.Second,
5068 16 * time.Second,
5069 32 * time.Second,
5070 60 * time.Second,
5071 60 * time.Second,
5072 60 * time.Second,
5073 60 * time.Second,
5074 60 * time.Second,
5075 60 * time.Second,
5076 60 * time.Second,
5077}
5078
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07005079// shortTimeouts is an alternate set of timeouts which would occur if the
5080// initial timeout duration was set to 250ms.
5081var shortTimeouts = []time.Duration{
5082 250 * time.Millisecond,
5083 500 * time.Millisecond,
5084 1 * time.Second,
5085 2 * time.Second,
5086 4 * time.Second,
5087 8 * time.Second,
5088 16 * time.Second,
5089 32 * time.Second,
5090 60 * time.Second,
5091 60 * time.Second,
5092 60 * time.Second,
5093 60 * time.Second,
5094 60 * time.Second,
5095}
5096
David Benjamin83f90402015-01-27 01:09:43 -05005097func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04005098 // These tests work by coordinating some behavior on both the shim and
5099 // the runner.
5100 //
5101 // TimeoutSchedule configures the runner to send a series of timeout
5102 // opcodes to the shim (see packetAdaptor) immediately before reading
5103 // each peer handshake flight N. The timeout opcode both simulates a
5104 // timeout in the shim and acts as a synchronization point to help the
5105 // runner bracket each handshake flight.
5106 //
5107 // We assume the shim does not read from the channel eagerly. It must
5108 // first wait until it has sent flight N and is ready to receive
5109 // handshake flight N+1. At this point, it will process the timeout
5110 // opcode. It must then immediately respond with a timeout ACK and act
5111 // as if the shim was idle for the specified amount of time.
5112 //
5113 // The runner then drops all packets received before the ACK and
5114 // continues waiting for flight N. This ordering results in one attempt
5115 // at sending flight N to be dropped. For the test to complete, the
5116 // shim must send flight N again, testing that the shim implements DTLS
5117 // retransmit on a timeout.
5118
David Benjamin4c3ddf72016-06-29 18:13:53 -04005119 // TODO(davidben): Add TLS 1.3 versions of these tests. There will
5120 // likely be more epochs to cross and the final message's retransmit may
5121 // be more complex.
5122
David Benjamin585d7a42016-06-02 14:58:00 -04005123 for _, async := range []bool{true, false} {
5124 var tests []testCase
5125
5126 // Test that this is indeed the timeout schedule. Stress all
5127 // four patterns of handshake.
5128 for i := 1; i < len(timeouts); i++ {
5129 number := strconv.Itoa(i)
5130 tests = append(tests, testCase{
5131 protocol: dtls,
5132 name: "DTLS-Retransmit-Client-" + number,
5133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005134 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005135 Bugs: ProtocolBugs{
5136 TimeoutSchedule: timeouts[:i],
5137 },
5138 },
5139 resumeSession: true,
5140 })
5141 tests = append(tests, testCase{
5142 protocol: dtls,
5143 testType: serverTest,
5144 name: "DTLS-Retransmit-Server-" + number,
5145 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005146 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005147 Bugs: ProtocolBugs{
5148 TimeoutSchedule: timeouts[:i],
5149 },
5150 },
5151 resumeSession: true,
5152 })
5153 }
5154
5155 // Test that exceeding the timeout schedule hits a read
5156 // timeout.
5157 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005158 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04005159 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05005160 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005161 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005162 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005163 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05005164 },
5165 },
5166 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005167 shouldFail: true,
5168 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05005169 })
David Benjamin585d7a42016-06-02 14:58:00 -04005170
5171 if async {
5172 // Test that timeout handling has a fudge factor, due to API
5173 // problems.
5174 tests = append(tests, testCase{
5175 protocol: dtls,
5176 name: "DTLS-Retransmit-Fudge",
5177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005178 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005179 Bugs: ProtocolBugs{
5180 TimeoutSchedule: []time.Duration{
5181 timeouts[0] - 10*time.Millisecond,
5182 },
5183 },
5184 },
5185 resumeSession: true,
5186 })
5187 }
5188
5189 // Test that the final Finished retransmitting isn't
5190 // duplicated if the peer badly fragments everything.
5191 tests = append(tests, testCase{
5192 testType: serverTest,
5193 protocol: dtls,
5194 name: "DTLS-Retransmit-Fragmented",
5195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005196 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005197 Bugs: ProtocolBugs{
5198 TimeoutSchedule: []time.Duration{timeouts[0]},
5199 MaxHandshakeRecordLength: 2,
5200 },
5201 },
5202 })
5203
5204 // Test the timeout schedule when a shorter initial timeout duration is set.
5205 tests = append(tests, testCase{
5206 protocol: dtls,
5207 name: "DTLS-Retransmit-Short-Client",
5208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005209 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04005210 Bugs: ProtocolBugs{
5211 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
5212 },
5213 },
5214 resumeSession: true,
5215 flags: []string{"-initial-timeout-duration-ms", "250"},
5216 })
5217 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05005218 protocol: dtls,
5219 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04005220 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05005221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005222 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05005223 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04005224 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05005225 },
5226 },
5227 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04005228 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05005229 })
David Benjamin585d7a42016-06-02 14:58:00 -04005230
5231 for _, test := range tests {
5232 if async {
5233 test.name += "-Async"
5234 test.flags = append(test.flags, "-async")
5235 }
5236
5237 testCases = append(testCases, test)
5238 }
David Benjamin83f90402015-01-27 01:09:43 -05005239 }
David Benjamin83f90402015-01-27 01:09:43 -05005240}
5241
David Benjaminc565ebb2015-04-03 04:06:36 -04005242func addExportKeyingMaterialTests() {
5243 for _, vers := range tlsVersions {
5244 if vers.version == VersionSSL30 {
5245 continue
5246 }
5247 testCases = append(testCases, testCase{
5248 name: "ExportKeyingMaterial-" + vers.name,
5249 config: Config{
5250 MaxVersion: vers.version,
5251 },
5252 exportKeyingMaterial: 1024,
5253 exportLabel: "label",
5254 exportContext: "context",
5255 useExportContext: true,
5256 })
5257 testCases = append(testCases, testCase{
5258 name: "ExportKeyingMaterial-NoContext-" + vers.name,
5259 config: Config{
5260 MaxVersion: vers.version,
5261 },
5262 exportKeyingMaterial: 1024,
5263 })
5264 testCases = append(testCases, testCase{
5265 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
5266 config: Config{
5267 MaxVersion: vers.version,
5268 },
5269 exportKeyingMaterial: 1024,
5270 useExportContext: true,
5271 })
5272 testCases = append(testCases, testCase{
5273 name: "ExportKeyingMaterial-Small-" + vers.name,
5274 config: Config{
5275 MaxVersion: vers.version,
5276 },
5277 exportKeyingMaterial: 1,
5278 exportLabel: "label",
5279 exportContext: "context",
5280 useExportContext: true,
5281 })
5282 }
5283 testCases = append(testCases, testCase{
5284 name: "ExportKeyingMaterial-SSL3",
5285 config: Config{
5286 MaxVersion: VersionSSL30,
5287 },
5288 exportKeyingMaterial: 1024,
5289 exportLabel: "label",
5290 exportContext: "context",
5291 useExportContext: true,
5292 shouldFail: true,
5293 expectedError: "failed to export keying material",
5294 })
5295}
5296
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005297func addTLSUniqueTests() {
5298 for _, isClient := range []bool{false, true} {
5299 for _, isResumption := range []bool{false, true} {
5300 for _, hasEMS := range []bool{false, true} {
5301 var suffix string
5302 if isResumption {
5303 suffix = "Resume-"
5304 } else {
5305 suffix = "Full-"
5306 }
5307
5308 if hasEMS {
5309 suffix += "EMS-"
5310 } else {
5311 suffix += "NoEMS-"
5312 }
5313
5314 if isClient {
5315 suffix += "Client"
5316 } else {
5317 suffix += "Server"
5318 }
5319
5320 test := testCase{
5321 name: "TLSUnique-" + suffix,
5322 testTLSUnique: true,
5323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005324 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005325 Bugs: ProtocolBugs{
5326 NoExtendedMasterSecret: !hasEMS,
5327 },
5328 },
5329 }
5330
5331 if isResumption {
5332 test.resumeSession = true
5333 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005334 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005335 Bugs: ProtocolBugs{
5336 NoExtendedMasterSecret: !hasEMS,
5337 },
5338 }
5339 }
5340
5341 if isResumption && !hasEMS {
5342 test.shouldFail = true
5343 test.expectedError = "failed to get tls-unique"
5344 }
5345
5346 testCases = append(testCases, test)
5347 }
5348 }
5349 }
5350}
5351
Adam Langley09505632015-07-30 18:10:13 -07005352func addCustomExtensionTests() {
5353 expectedContents := "custom extension"
5354 emptyString := ""
5355
David Benjamin4c3ddf72016-06-29 18:13:53 -04005356 // TODO(davidben): Add TLS 1.3 versions of these tests.
Adam Langley09505632015-07-30 18:10:13 -07005357 for _, isClient := range []bool{false, true} {
5358 suffix := "Server"
5359 flag := "-enable-server-custom-extension"
5360 testType := serverTest
5361 if isClient {
5362 suffix = "Client"
5363 flag = "-enable-client-custom-extension"
5364 testType = clientTest
5365 }
5366
5367 testCases = append(testCases, testCase{
5368 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005369 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005370 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005371 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005372 Bugs: ProtocolBugs{
5373 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005374 ExpectedCustomExtension: &expectedContents,
5375 },
5376 },
5377 flags: []string{flag},
5378 })
5379
5380 // If the parse callback fails, the handshake should also fail.
5381 testCases = append(testCases, testCase{
5382 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005383 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005385 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005386 Bugs: ProtocolBugs{
5387 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07005388 ExpectedCustomExtension: &expectedContents,
5389 },
5390 },
David Benjamin399e7c92015-07-30 23:01:27 -04005391 flags: []string{flag},
5392 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005393 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5394 })
5395
5396 // If the add callback fails, the handshake should also fail.
5397 testCases = append(testCases, testCase{
5398 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005399 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005401 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005402 Bugs: ProtocolBugs{
5403 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07005404 ExpectedCustomExtension: &expectedContents,
5405 },
5406 },
David Benjamin399e7c92015-07-30 23:01:27 -04005407 flags: []string{flag, "-custom-extension-fail-add"},
5408 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07005409 expectedError: ":CUSTOM_EXTENSION_ERROR:",
5410 })
5411
5412 // If the add callback returns zero, no extension should be
5413 // added.
5414 skipCustomExtension := expectedContents
5415 if isClient {
5416 // For the case where the client skips sending the
5417 // custom extension, the server must not “echo” it.
5418 skipCustomExtension = ""
5419 }
5420 testCases = append(testCases, testCase{
5421 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04005422 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07005423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005424 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005425 Bugs: ProtocolBugs{
5426 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07005427 ExpectedCustomExtension: &emptyString,
5428 },
5429 },
5430 flags: []string{flag, "-custom-extension-skip"},
5431 })
5432 }
5433
5434 // The custom extension add callback should not be called if the client
5435 // doesn't send the extension.
5436 testCases = append(testCases, testCase{
5437 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04005438 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07005439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005440 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04005441 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07005442 ExpectedCustomExtension: &emptyString,
5443 },
5444 },
5445 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
5446 })
Adam Langley2deb9842015-08-07 11:15:37 -07005447
5448 // Test an unknown extension from the server.
5449 testCases = append(testCases, testCase{
5450 testType: clientTest,
5451 name: "UnknownExtension-Client",
5452 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005453 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07005454 Bugs: ProtocolBugs{
5455 CustomExtension: expectedContents,
5456 },
5457 },
5458 shouldFail: true,
5459 expectedError: ":UNEXPECTED_EXTENSION:",
5460 })
Adam Langley09505632015-07-30 18:10:13 -07005461}
5462
David Benjaminb36a3952015-12-01 18:53:13 -05005463func addRSAClientKeyExchangeTests() {
5464 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
5465 testCases = append(testCases, testCase{
5466 testType: serverTest,
5467 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
5468 config: Config{
5469 // Ensure the ClientHello version and final
5470 // version are different, to detect if the
5471 // server uses the wrong one.
5472 MaxVersion: VersionTLS11,
5473 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
5474 Bugs: ProtocolBugs{
5475 BadRSAClientKeyExchange: bad,
5476 },
5477 },
5478 shouldFail: true,
5479 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5480 })
5481 }
5482}
5483
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005484var testCurves = []struct {
5485 name string
5486 id CurveID
5487}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005488 {"P-256", CurveP256},
5489 {"P-384", CurveP384},
5490 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05005491 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005492}
5493
5494func addCurveTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005495 // TODO(davidben): Add a TLS 1.3 versions of these tests.
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005496 for _, curve := range testCurves {
5497 testCases = append(testCases, testCase{
5498 name: "CurveTest-Client-" + curve.name,
5499 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005500 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005501 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5502 CurvePreferences: []CurveID{curve.id},
5503 },
5504 flags: []string{"-enable-all-curves"},
5505 })
5506 testCases = append(testCases, testCase{
5507 testType: serverTest,
5508 name: "CurveTest-Server-" + curve.name,
5509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005510 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005511 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5512 CurvePreferences: []CurveID{curve.id},
5513 },
5514 flags: []string{"-enable-all-curves"},
5515 })
5516 }
David Benjamin241ae832016-01-15 03:04:54 -05005517
5518 // The server must be tolerant to bogus curves.
5519 const bogusCurve = 0x1234
5520 testCases = append(testCases, testCase{
5521 testType: serverTest,
5522 name: "UnknownCurve",
5523 config: Config{
5524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5525 CurvePreferences: []CurveID{bogusCurve, CurveP256},
5526 },
5527 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005528
5529 // The server must not consider ECDHE ciphers when there are no
5530 // supported curves.
5531 testCases = append(testCases, testCase{
5532 testType: serverTest,
5533 name: "NoSupportedCurves",
5534 config: Config{
5535 // TODO(davidben): Add a TLS 1.3 version of this.
5536 MaxVersion: VersionTLS12,
5537 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5538 Bugs: ProtocolBugs{
5539 NoSupportedCurves: true,
5540 },
5541 },
5542 shouldFail: true,
5543 expectedError: ":NO_SHARED_CIPHER:",
5544 })
5545
5546 // The server must fall back to another cipher when there are no
5547 // supported curves.
5548 testCases = append(testCases, testCase{
5549 testType: serverTest,
5550 name: "NoCommonCurves",
5551 config: Config{
5552 MaxVersion: VersionTLS12,
5553 CipherSuites: []uint16{
5554 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5555 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5556 },
5557 CurvePreferences: []CurveID{CurveP224},
5558 },
5559 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
5560 })
5561
5562 // The client must reject bogus curves and disabled curves.
5563 testCases = append(testCases, testCase{
5564 name: "BadECDHECurve",
5565 config: Config{
5566 // TODO(davidben): Add a TLS 1.3 version of this.
5567 MaxVersion: VersionTLS12,
5568 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5569 Bugs: ProtocolBugs{
5570 SendCurve: bogusCurve,
5571 },
5572 },
5573 shouldFail: true,
5574 expectedError: ":WRONG_CURVE:",
5575 })
5576
5577 testCases = append(testCases, testCase{
5578 name: "UnsupportedCurve",
5579 config: Config{
5580 // TODO(davidben): Add a TLS 1.3 version of this.
5581 MaxVersion: VersionTLS12,
5582 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5583 CurvePreferences: []CurveID{CurveP256},
5584 Bugs: ProtocolBugs{
5585 IgnorePeerCurvePreferences: true,
5586 },
5587 },
5588 flags: []string{"-p384-only"},
5589 shouldFail: true,
5590 expectedError: ":WRONG_CURVE:",
5591 })
5592
5593 // Test invalid curve points.
5594 testCases = append(testCases, testCase{
5595 name: "InvalidECDHPoint-Client",
5596 config: Config{
5597 // TODO(davidben): Add a TLS 1.3 version of this test.
5598 MaxVersion: VersionTLS12,
5599 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5600 CurvePreferences: []CurveID{CurveP256},
5601 Bugs: ProtocolBugs{
5602 InvalidECDHPoint: true,
5603 },
5604 },
5605 shouldFail: true,
5606 expectedError: ":INVALID_ENCODING:",
5607 })
5608 testCases = append(testCases, testCase{
5609 testType: serverTest,
5610 name: "InvalidECDHPoint-Server",
5611 config: Config{
5612 // TODO(davidben): Add a TLS 1.3 version of this test.
5613 MaxVersion: VersionTLS12,
5614 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5615 CurvePreferences: []CurveID{CurveP256},
5616 Bugs: ProtocolBugs{
5617 InvalidECDHPoint: true,
5618 },
5619 },
5620 shouldFail: true,
5621 expectedError: ":INVALID_ENCODING:",
5622 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005623}
5624
Matt Braithwaite54217e42016-06-13 13:03:47 -07005625func addCECPQ1Tests() {
5626 testCases = append(testCases, testCase{
5627 testType: clientTest,
5628 name: "CECPQ1-Client-BadX25519Part",
5629 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005630 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005631 MinVersion: VersionTLS12,
5632 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5633 Bugs: ProtocolBugs{
5634 CECPQ1BadX25519Part: true,
5635 },
5636 },
5637 flags: []string{"-cipher", "kCECPQ1"},
5638 shouldFail: true,
5639 expectedLocalError: "local error: bad record MAC",
5640 })
5641 testCases = append(testCases, testCase{
5642 testType: clientTest,
5643 name: "CECPQ1-Client-BadNewhopePart",
5644 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005645 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005646 MinVersion: VersionTLS12,
5647 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5648 Bugs: ProtocolBugs{
5649 CECPQ1BadNewhopePart: true,
5650 },
5651 },
5652 flags: []string{"-cipher", "kCECPQ1"},
5653 shouldFail: true,
5654 expectedLocalError: "local error: bad record MAC",
5655 })
5656 testCases = append(testCases, testCase{
5657 testType: serverTest,
5658 name: "CECPQ1-Server-BadX25519Part",
5659 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005660 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005661 MinVersion: VersionTLS12,
5662 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5663 Bugs: ProtocolBugs{
5664 CECPQ1BadX25519Part: true,
5665 },
5666 },
5667 flags: []string{"-cipher", "kCECPQ1"},
5668 shouldFail: true,
5669 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5670 })
5671 testCases = append(testCases, testCase{
5672 testType: serverTest,
5673 name: "CECPQ1-Server-BadNewhopePart",
5674 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005675 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07005676 MinVersion: VersionTLS12,
5677 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
5678 Bugs: ProtocolBugs{
5679 CECPQ1BadNewhopePart: true,
5680 },
5681 },
5682 flags: []string{"-cipher", "kCECPQ1"},
5683 shouldFail: true,
5684 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5685 })
5686}
5687
David Benjamin4cc36ad2015-12-19 14:23:26 -05005688func addKeyExchangeInfoTests() {
5689 testCases = append(testCases, testCase{
David Benjamin4cc36ad2015-12-19 14:23:26 -05005690 name: "KeyExchangeInfo-DHE-Client",
5691 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005692 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005693 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5694 Bugs: ProtocolBugs{
5695 // This is a 1234-bit prime number, generated
5696 // with:
5697 // openssl gendh 1234 | openssl asn1parse -i
5698 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
5699 },
5700 },
David Benjamin9e68f192016-06-30 14:55:33 -04005701 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005702 })
5703 testCases = append(testCases, testCase{
5704 testType: serverTest,
5705 name: "KeyExchangeInfo-DHE-Server",
5706 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005707 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005708 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
5709 },
5710 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04005711 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005712 })
5713
Nick Harper1fd39d82016-06-14 18:14:35 -07005714 // TODO(davidben): Add TLS 1.3 versions of these tests once the
5715 // handshake is separate.
5716
David Benjamin4cc36ad2015-12-19 14:23:26 -05005717 testCases = append(testCases, testCase{
5718 name: "KeyExchangeInfo-ECDHE-Client",
5719 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005720 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005721 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5722 CurvePreferences: []CurveID{CurveX25519},
5723 },
David Benjamin9e68f192016-06-30 14:55:33 -04005724 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005725 })
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "KeyExchangeInfo-ECDHE-Server",
5729 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005730 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05005731 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5732 CurvePreferences: []CurveID{CurveX25519},
5733 },
David Benjamin9e68f192016-06-30 14:55:33 -04005734 flags: []string{"-expect-curve-id", "29", "-enable-all-curves"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05005735 })
5736}
5737
David Benjaminc9ae27c2016-06-24 22:56:37 -04005738func addTLS13RecordTests() {
5739 testCases = append(testCases, testCase{
5740 name: "TLS13-RecordPadding",
5741 config: Config{
5742 MaxVersion: VersionTLS13,
5743 MinVersion: VersionTLS13,
5744 Bugs: ProtocolBugs{
5745 RecordPadding: 10,
5746 },
5747 },
5748 })
5749
5750 testCases = append(testCases, testCase{
5751 name: "TLS13-EmptyRecords",
5752 config: Config{
5753 MaxVersion: VersionTLS13,
5754 MinVersion: VersionTLS13,
5755 Bugs: ProtocolBugs{
5756 OmitRecordContents: true,
5757 },
5758 },
5759 shouldFail: true,
5760 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5761 })
5762
5763 testCases = append(testCases, testCase{
5764 name: "TLS13-OnlyPadding",
5765 config: Config{
5766 MaxVersion: VersionTLS13,
5767 MinVersion: VersionTLS13,
5768 Bugs: ProtocolBugs{
5769 OmitRecordContents: true,
5770 RecordPadding: 10,
5771 },
5772 },
5773 shouldFail: true,
5774 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
5775 })
5776
5777 testCases = append(testCases, testCase{
5778 name: "TLS13-WrongOuterRecord",
5779 config: Config{
5780 MaxVersion: VersionTLS13,
5781 MinVersion: VersionTLS13,
5782 Bugs: ProtocolBugs{
5783 OuterRecordType: recordTypeHandshake,
5784 },
5785 },
5786 shouldFail: true,
5787 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
5788 })
5789}
5790
Adam Langley7c803a62015-06-15 15:35:05 -07005791func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07005792 defer wg.Done()
5793
5794 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08005795 var err error
5796
5797 if *mallocTest < 0 {
5798 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005799 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005800 } else {
5801 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5802 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005803 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005804 if err != nil {
5805 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5806 }
5807 break
5808 }
5809 }
5810 }
Adam Langley95c29f32014-06-20 12:00:00 -07005811 statusChan <- statusMsg{test: test, err: err}
5812 }
5813}
5814
5815type statusMsg struct {
5816 test *testCase
5817 started bool
5818 err error
5819}
5820
David Benjamin5f237bc2015-02-11 17:14:15 -05005821func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005822 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005823
David Benjamin5f237bc2015-02-11 17:14:15 -05005824 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005825 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005826 if !*pipe {
5827 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005828 var erase string
5829 for i := 0; i < lineLen; i++ {
5830 erase += "\b \b"
5831 }
5832 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005833 }
5834
Adam Langley95c29f32014-06-20 12:00:00 -07005835 if msg.started {
5836 started++
5837 } else {
5838 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005839
5840 if msg.err != nil {
5841 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5842 failed++
5843 testOutput.addResult(msg.test.name, "FAIL")
5844 } else {
5845 if *pipe {
5846 // Print each test instead of a status line.
5847 fmt.Printf("PASSED (%s)\n", msg.test.name)
5848 }
5849 testOutput.addResult(msg.test.name, "PASS")
5850 }
Adam Langley95c29f32014-06-20 12:00:00 -07005851 }
5852
David Benjamin5f237bc2015-02-11 17:14:15 -05005853 if !*pipe {
5854 // Print a new status line.
5855 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5856 lineLen = len(line)
5857 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005858 }
Adam Langley95c29f32014-06-20 12:00:00 -07005859 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005860
5861 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005862}
5863
5864func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005865 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005866 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005867
Adam Langley7c803a62015-06-15 15:35:05 -07005868 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005869 addCipherSuiteTests()
5870 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005871 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005872 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005873 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005874 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005875 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005876 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005877 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005878 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005879 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005880 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005881 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07005882 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05005883 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005884 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005885 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005886 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005887 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005888 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07005889 addCECPQ1Tests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005890 addKeyExchangeInfoTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04005891 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07005892 addAllStateMachineCoverageTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005893
5894 var wg sync.WaitGroup
5895
Adam Langley7c803a62015-06-15 15:35:05 -07005896 statusChan := make(chan statusMsg, *numWorkers)
5897 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005898 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005899
David Benjamin025b3d32014-07-01 19:53:04 -04005900 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005901
Adam Langley7c803a62015-06-15 15:35:05 -07005902 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005903 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005904 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005905 }
5906
David Benjamin270f0a72016-03-17 14:41:36 -04005907 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005908 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005909 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005910 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005911 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005912 }
5913 }
David Benjamin270f0a72016-03-17 14:41:36 -04005914 if !foundTest {
5915 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5916 os.Exit(1)
5917 }
Adam Langley95c29f32014-06-20 12:00:00 -07005918
5919 close(testChan)
5920 wg.Wait()
5921 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005922 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005923
5924 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005925
5926 if *jsonOutput != "" {
5927 if err := testOutput.writeTo(*jsonOutput); err != nil {
5928 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5929 }
5930 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005931
5932 if !testOutput.allPassed {
5933 os.Exit(1)
5934 }
Adam Langley95c29f32014-06-20 12:00:00 -07005935}