blob: 6ee183e89251ad3a575911c3ae817807e912309c [file] [log] [blame]
Adam Langleydc7e9c42015-09-29 15:21:04 -07001package runner
Adam Langley95c29f32014-06-20 12:00:00 -07002
3import (
4 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -04005 "crypto/ecdsa"
6 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -04007 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -04008 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -04009 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070010 "flag"
11 "fmt"
12 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070013 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070014 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070015 "net"
16 "os"
17 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040018 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040019 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080020 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070021 "strings"
22 "sync"
23 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050024 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070025)
26
Adam Langley69a01602014-11-17 17:26:55 -080027var (
David Benjamin5f237bc2015-02-11 17:14:15 -050028 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
29 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
David Benjamind16bf342015-12-18 00:53:12 -050030 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050031 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
32 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
33 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.")
34 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
35 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070036 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
37 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
38 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
39 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050040 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
Adam Langley69a01602014-11-17 17:26:55 -080041)
Adam Langley95c29f32014-06-20 12:00:00 -070042
David Benjamin025b3d32014-07-01 19:53:04 -040043const (
44 rsaCertificateFile = "cert.pem"
45 ecdsaCertificateFile = "ecdsa_cert.pem"
46)
47
48const (
David Benjamina08e49d2014-08-24 01:46:07 -040049 rsaKeyFile = "key.pem"
50 ecdsaKeyFile = "ecdsa_key.pem"
51 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040052)
53
Adam Langley95c29f32014-06-20 12:00:00 -070054var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040055var channelIDKey *ecdsa.PrivateKey
56var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070057
David Benjamin61f95272014-11-25 01:55:35 -050058var testOCSPResponse = []byte{1, 2, 3, 4}
59var testSCTList = []byte{5, 6, 7, 8}
60
Adam Langley95c29f32014-06-20 12:00:00 -070061func initCertificates() {
62 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070063 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070064 if err != nil {
65 panic(err)
66 }
David Benjamin61f95272014-11-25 01:55:35 -050067 rsaCertificate.OCSPStaple = testOCSPResponse
68 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070069
Adam Langley7c803a62015-06-15 15:35:05 -070070 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070071 if err != nil {
72 panic(err)
73 }
David Benjamin61f95272014-11-25 01:55:35 -050074 ecdsaCertificate.OCSPStaple = testOCSPResponse
75 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040076
Adam Langley7c803a62015-06-15 15:35:05 -070077 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040078 if err != nil {
79 panic(err)
80 }
81 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
82 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
83 panic("bad key type")
84 }
85 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
86 if err != nil {
87 panic(err)
88 }
89 if channelIDKey.Curve != elliptic.P256() {
90 panic("bad curve")
91 }
92
93 channelIDBytes = make([]byte, 64)
94 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
95 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070096}
97
98var certificateOnce sync.Once
99
100func getRSACertificate() Certificate {
101 certificateOnce.Do(initCertificates)
102 return rsaCertificate
103}
104
105func getECDSACertificate() Certificate {
106 certificateOnce.Do(initCertificates)
107 return ecdsaCertificate
108}
109
David Benjamin025b3d32014-07-01 19:53:04 -0400110type testType int
111
112const (
113 clientTest testType = iota
114 serverTest
115)
116
David Benjamin6fd297b2014-08-11 18:43:38 -0400117type protocol int
118
119const (
120 tls protocol = iota
121 dtls
122)
123
David Benjaminfc7b0862014-09-06 13:21:53 -0400124const (
125 alpn = 1
126 npn = 2
127)
128
Adam Langley95c29f32014-06-20 12:00:00 -0700129type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400130 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400131 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700132 name string
133 config Config
134 shouldFail bool
135 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700136 // expectedLocalError, if not empty, contains a substring that must be
137 // found in the local error.
138 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400139 // expectedVersion, if non-zero, specifies the TLS version that must be
140 // negotiated.
141 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400142 // expectedResumeVersion, if non-zero, specifies the TLS version that
143 // must be negotiated on resumption. If zero, expectedVersion is used.
144 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400145 // expectedCipher, if non-zero, specifies the TLS cipher suite that
146 // should be negotiated.
147 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400148 // expectChannelID controls whether the connection should have
149 // negotiated a Channel ID with channelIDKey.
150 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400151 // expectedNextProto controls whether the connection should
152 // negotiate a next protocol via NPN or ALPN.
153 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400154 // expectNoNextProto, if true, means that no next protocol should be
155 // negotiated.
156 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400157 // expectedNextProtoType, if non-zero, is the expected next
158 // protocol negotiation mechanism.
159 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500160 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
161 // should be negotiated. If zero, none should be negotiated.
162 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100163 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
164 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100165 // expectedSCTList, if not nil, is the expected SCT list to be received.
166 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400167 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
168 // hash function that the client should have used when signing the
169 // handshake with a client certificate.
170 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700171 // messageLen is the length, in bytes, of the test message that will be
172 // sent.
173 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400174 // messageCount is the number of test messages that will be sent.
175 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400176 // digestPrefs is the list of digest preferences from the client.
177 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400178 // certFile is the path to the certificate to use for the server.
179 certFile string
180 // keyFile is the path to the private key to use for the server.
181 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400182 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400183 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400184 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700185 // expectResumeRejected, if true, specifies that the attempted
186 // resumption must be rejected by the client. This is only valid for a
187 // serverTest.
188 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400189 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500190 // resumption. Unless newSessionsOnResume is set,
191 // SessionTicketKey, ServerSessionCache, and
192 // ClientSessionCache are copied from the initial connection's
193 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400194 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500195 // newSessionsOnResume, if true, will cause resumeConfig to
196 // use a different session resumption context.
197 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400198 // noSessionCache, if true, will cause the server to run without a
199 // session cache.
200 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400201 // sendPrefix sends a prefix on the socket before actually performing a
202 // handshake.
203 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400204 // shimWritesFirst controls whether the shim sends an initial "hello"
205 // message before doing a roundtrip with the runner.
206 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400207 // shimShutsDown, if true, runs a test where the shim shuts down the
208 // connection immediately after the handshake rather than echoing
209 // messages from the runner.
210 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400211 // renegotiate indicates the number of times the connection should be
212 // renegotiated during the exchange.
213 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700214 // renegotiateCiphers is a list of ciphersuite ids that will be
215 // switched in just before renegotiation.
216 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500217 // replayWrites, if true, configures the underlying transport
218 // to replay every write it makes in DTLS tests.
219 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500220 // damageFirstWrite, if true, configures the underlying transport to
221 // damage the final byte of the first application data write.
222 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400223 // exportKeyingMaterial, if non-zero, configures the test to exchange
224 // keying material and verify they match.
225 exportKeyingMaterial int
226 exportLabel string
227 exportContext string
228 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400229 // flags, if not empty, contains a list of command-line flags that will
230 // be passed to the shim program.
231 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700232 // testTLSUnique, if true, causes the shim to send the tls-unique value
233 // which will be compared against the expected value.
234 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400235 // sendEmptyRecords is the number of consecutive empty records to send
236 // before and after the test message.
237 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400238 // sendWarningAlerts is the number of consecutive warning alerts to send
239 // before and after the test message.
240 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400241 // expectMessageDropped, if true, means the test message is expected to
242 // be dropped by the client rather than echoed back.
243 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700244}
245
Adam Langley7c803a62015-06-15 15:35:05 -0700246var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700247
David Benjamin8e6db492015-07-25 18:29:23 -0400248func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin5fa3eba2015-01-22 16:35:40 -0500249 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500250
David Benjamin6fd297b2014-08-11 18:43:38 -0400251 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500252 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
253 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500254 }
255
256 if *flagDebug {
257 local, peer := "client", "server"
258 if test.testType == clientTest {
259 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500260 }
David Benjaminebda9b32015-11-02 15:33:18 -0500261 connDebug := &recordingConn{
262 Conn: conn,
263 isDatagram: test.protocol == dtls,
264 local: local,
265 peer: peer,
266 }
267 conn = connDebug
268 defer func() {
269 connDebug.WriteTo(os.Stdout)
270 }()
271
272 if config.Bugs.PacketAdaptor != nil {
273 config.Bugs.PacketAdaptor.debug = connDebug
274 }
275 }
276
277 if test.replayWrites {
278 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400279 }
280
David Benjamin5fa3eba2015-01-22 16:35:40 -0500281 if test.damageFirstWrite {
282 connDamage = newDamageAdaptor(conn)
283 conn = connDamage
284 }
285
David Benjamin6fd297b2014-08-11 18:43:38 -0400286 if test.sendPrefix != "" {
287 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
288 return err
289 }
David Benjamin98e882e2014-08-08 13:24:34 -0400290 }
291
David Benjamin1d5c83e2014-07-22 19:20:02 -0400292 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400293 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400294 if test.protocol == dtls {
295 tlsConn = DTLSServer(conn, config)
296 } else {
297 tlsConn = Server(conn, config)
298 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400299 } else {
300 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400301 if test.protocol == dtls {
302 tlsConn = DTLSClient(conn, config)
303 } else {
304 tlsConn = Client(conn, config)
305 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400306 }
David Benjamin30789da2015-08-29 22:56:45 -0400307 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400308
Adam Langley95c29f32014-06-20 12:00:00 -0700309 if err := tlsConn.Handshake(); err != nil {
310 return err
311 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700312
David Benjamin01fe8202014-09-24 15:21:44 -0400313 // TODO(davidben): move all per-connection expectations into a dedicated
314 // expectations struct that can be specified separately for the two
315 // legs.
316 expectedVersion := test.expectedVersion
317 if isResume && test.expectedResumeVersion != 0 {
318 expectedVersion = test.expectedResumeVersion
319 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700320 connState := tlsConn.ConnectionState()
321 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400322 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400323 }
324
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700325 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400326 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
327 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700328 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
329 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
330 }
David Benjamin90da8c82015-04-20 14:57:57 -0400331
David Benjamina08e49d2014-08-24 01:46:07 -0400332 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700333 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400334 if channelID == nil {
335 return fmt.Errorf("no channel ID negotiated")
336 }
337 if channelID.Curve != channelIDKey.Curve ||
338 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
339 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
340 return fmt.Errorf("incorrect channel ID")
341 }
342 }
343
David Benjaminae2888f2014-09-06 12:58:58 -0400344 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700345 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400346 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
347 }
348 }
349
David Benjaminc7ce9772015-10-09 19:32:41 -0400350 if test.expectNoNextProto {
351 if actual := connState.NegotiatedProtocol; actual != "" {
352 return fmt.Errorf("got unexpected next proto %s", actual)
353 }
354 }
355
David Benjaminfc7b0862014-09-06 13:21:53 -0400356 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700357 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400358 return fmt.Errorf("next proto type mismatch")
359 }
360 }
361
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700362 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500363 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
364 }
365
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100366 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
367 return fmt.Errorf("OCSP Response mismatch")
368 }
369
Paul Lietar4fac72e2015-09-09 13:44:55 +0100370 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
371 return fmt.Errorf("SCT list mismatch")
372 }
373
Steven Valdez0d62f262015-09-04 12:41:04 -0400374 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
375 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
376 }
377
David Benjaminc565ebb2015-04-03 04:06:36 -0400378 if test.exportKeyingMaterial > 0 {
379 actual := make([]byte, test.exportKeyingMaterial)
380 if _, err := io.ReadFull(tlsConn, actual); err != nil {
381 return err
382 }
383 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
384 if err != nil {
385 return err
386 }
387 if !bytes.Equal(actual, expected) {
388 return fmt.Errorf("keying material mismatch")
389 }
390 }
391
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700392 if test.testTLSUnique {
393 var peersValue [12]byte
394 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
395 return err
396 }
397 expected := tlsConn.ConnectionState().TLSUnique
398 if !bytes.Equal(peersValue[:], expected) {
399 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
400 }
401 }
402
David Benjamine58c4f52014-08-24 03:47:07 -0400403 if test.shimWritesFirst {
404 var buf [5]byte
405 _, err := io.ReadFull(tlsConn, buf[:])
406 if err != nil {
407 return err
408 }
409 if string(buf[:]) != "hello" {
410 return fmt.Errorf("bad initial message")
411 }
412 }
413
David Benjamina8ebe222015-06-06 03:04:39 -0400414 for i := 0; i < test.sendEmptyRecords; i++ {
415 tlsConn.Write(nil)
416 }
417
David Benjamin24f346d2015-06-06 03:28:08 -0400418 for i := 0; i < test.sendWarningAlerts; i++ {
419 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
420 }
421
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400422 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700423 if test.renegotiateCiphers != nil {
424 config.CipherSuites = test.renegotiateCiphers
425 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400426 for i := 0; i < test.renegotiate; i++ {
427 if err := tlsConn.Renegotiate(); err != nil {
428 return err
429 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700430 }
431 } else if test.renegotiateCiphers != nil {
432 panic("renegotiateCiphers without renegotiate")
433 }
434
David Benjamin5fa3eba2015-01-22 16:35:40 -0500435 if test.damageFirstWrite {
436 connDamage.setDamage(true)
437 tlsConn.Write([]byte("DAMAGED WRITE"))
438 connDamage.setDamage(false)
439 }
440
David Benjamin8e6db492015-07-25 18:29:23 -0400441 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700442 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400443 if test.protocol == dtls {
444 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
445 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700446 // Read until EOF.
447 _, err := io.Copy(ioutil.Discard, tlsConn)
448 return err
449 }
David Benjamin4417d052015-04-05 04:17:25 -0400450 if messageLen == 0 {
451 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700452 }
Adam Langley95c29f32014-06-20 12:00:00 -0700453
David Benjamin8e6db492015-07-25 18:29:23 -0400454 messageCount := test.messageCount
455 if messageCount == 0 {
456 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400457 }
458
David Benjamin8e6db492015-07-25 18:29:23 -0400459 for j := 0; j < messageCount; j++ {
460 testMessage := make([]byte, messageLen)
461 for i := range testMessage {
462 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400463 }
David Benjamin8e6db492015-07-25 18:29:23 -0400464 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700465
David Benjamin8e6db492015-07-25 18:29:23 -0400466 for i := 0; i < test.sendEmptyRecords; i++ {
467 tlsConn.Write(nil)
468 }
469
470 for i := 0; i < test.sendWarningAlerts; i++ {
471 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
472 }
473
David Benjamin4f75aaf2015-09-01 16:53:10 -0400474 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400475 // The shim will not respond.
476 continue
477 }
478
David Benjamin8e6db492015-07-25 18:29:23 -0400479 buf := make([]byte, len(testMessage))
480 if test.protocol == dtls {
481 bufTmp := make([]byte, len(buf)+1)
482 n, err := tlsConn.Read(bufTmp)
483 if err != nil {
484 return err
485 }
486 if n != len(buf) {
487 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
488 }
489 copy(buf, bufTmp)
490 } else {
491 _, err := io.ReadFull(tlsConn, buf)
492 if err != nil {
493 return err
494 }
495 }
496
497 for i, v := range buf {
498 if v != testMessage[i]^0xff {
499 return fmt.Errorf("bad reply contents at byte %d", i)
500 }
Adam Langley95c29f32014-06-20 12:00:00 -0700501 }
502 }
503
504 return nil
505}
506
David Benjamin325b5c32014-07-01 19:40:31 -0400507func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
508 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400510 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700511 }
David Benjamin325b5c32014-07-01 19:40:31 -0400512 valgrindArgs = append(valgrindArgs, path)
513 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700514
David Benjamin325b5c32014-07-01 19:40:31 -0400515 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700516}
517
David Benjamin325b5c32014-07-01 19:40:31 -0400518func gdbOf(path string, args ...string) *exec.Cmd {
519 xtermArgs := []string{"-e", "gdb", "--args"}
520 xtermArgs = append(xtermArgs, path)
521 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700522
David Benjamin325b5c32014-07-01 19:40:31 -0400523 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700524}
525
David Benjamind16bf342015-12-18 00:53:12 -0500526func lldbOf(path string, args ...string) *exec.Cmd {
527 xtermArgs := []string{"-e", "lldb", "--"}
528 xtermArgs = append(xtermArgs, path)
529 xtermArgs = append(xtermArgs, args...)
530
531 return exec.Command("xterm", xtermArgs...)
532}
533
Adam Langley69a01602014-11-17 17:26:55 -0800534type moreMallocsError struct{}
535
536func (moreMallocsError) Error() string {
537 return "child process did not exhaust all allocation calls"
538}
539
540var errMoreMallocs = moreMallocsError{}
541
David Benjamin87c8a642015-02-21 01:54:29 -0500542// accept accepts a connection from listener, unless waitChan signals a process
543// exit first.
544func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
545 type connOrError struct {
546 conn net.Conn
547 err error
548 }
549 connChan := make(chan connOrError, 1)
550 go func() {
551 conn, err := listener.Accept()
552 connChan <- connOrError{conn, err}
553 close(connChan)
554 }()
555 select {
556 case result := <-connChan:
557 return result.conn, result.err
558 case childErr := <-waitChan:
559 waitChan <- childErr
560 return nil, fmt.Errorf("child exited early: %s", childErr)
561 }
562}
563
Adam Langley7c803a62015-06-15 15:35:05 -0700564func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700565 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
566 panic("Error expected without shouldFail in " + test.name)
567 }
568
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700569 if test.expectResumeRejected && !test.resumeSession {
570 panic("expectResumeRejected without resumeSession in " + test.name)
571 }
572
Steven Valdez0d62f262015-09-04 12:41:04 -0400573 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
574 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
575 }
576
David Benjamin87c8a642015-02-21 01:54:29 -0500577 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
578 if err != nil {
579 panic(err)
580 }
581 defer func() {
582 if listener != nil {
583 listener.Close()
584 }
585 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700586
David Benjamin87c8a642015-02-21 01:54:29 -0500587 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400588 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400589 flags = append(flags, "-server")
590
David Benjamin025b3d32014-07-01 19:53:04 -0400591 flags = append(flags, "-key-file")
592 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700593 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400594 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700595 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400596 }
597
598 flags = append(flags, "-cert-file")
599 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700600 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400601 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700602 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400603 }
604 }
David Benjamin5a593af2014-08-11 19:51:50 -0400605
Steven Valdez0d62f262015-09-04 12:41:04 -0400606 if test.digestPrefs != "" {
607 flags = append(flags, "-digest-prefs")
608 flags = append(flags, test.digestPrefs)
609 }
610
David Benjamin6fd297b2014-08-11 18:43:38 -0400611 if test.protocol == dtls {
612 flags = append(flags, "-dtls")
613 }
614
David Benjamin5a593af2014-08-11 19:51:50 -0400615 if test.resumeSession {
616 flags = append(flags, "-resume")
617 }
618
David Benjamine58c4f52014-08-24 03:47:07 -0400619 if test.shimWritesFirst {
620 flags = append(flags, "-shim-writes-first")
621 }
622
David Benjamin30789da2015-08-29 22:56:45 -0400623 if test.shimShutsDown {
624 flags = append(flags, "-shim-shuts-down")
625 }
626
David Benjaminc565ebb2015-04-03 04:06:36 -0400627 if test.exportKeyingMaterial > 0 {
628 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
629 flags = append(flags, "-export-label", test.exportLabel)
630 flags = append(flags, "-export-context", test.exportContext)
631 if test.useExportContext {
632 flags = append(flags, "-use-export-context")
633 }
634 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700635 if test.expectResumeRejected {
636 flags = append(flags, "-expect-session-miss")
637 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400638
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700639 if test.testTLSUnique {
640 flags = append(flags, "-tls-unique")
641 }
642
David Benjamin025b3d32014-07-01 19:53:04 -0400643 flags = append(flags, test.flags...)
644
645 var shim *exec.Cmd
646 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700647 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700648 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700649 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500650 } else if *useLLDB {
651 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400652 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700653 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400654 }
David Benjamin025b3d32014-07-01 19:53:04 -0400655 shim.Stdin = os.Stdin
656 var stdoutBuf, stderrBuf bytes.Buffer
657 shim.Stdout = &stdoutBuf
658 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800659 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500660 shim.Env = os.Environ()
661 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800662 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400663 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800664 }
665 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
666 }
David Benjamin025b3d32014-07-01 19:53:04 -0400667
668 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700669 panic(err)
670 }
David Benjamin87c8a642015-02-21 01:54:29 -0500671 waitChan := make(chan error, 1)
672 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700673
674 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400675 if !test.noSessionCache {
676 config.ClientSessionCache = NewLRUClientSessionCache(1)
677 config.ServerSessionCache = NewLRUServerSessionCache(1)
678 }
David Benjamin025b3d32014-07-01 19:53:04 -0400679 if test.testType == clientTest {
680 if len(config.Certificates) == 0 {
681 config.Certificates = []Certificate{getRSACertificate()}
682 }
David Benjamin87c8a642015-02-21 01:54:29 -0500683 } else {
684 // Supply a ServerName to ensure a constant session cache key,
685 // rather than falling back to net.Conn.RemoteAddr.
686 if len(config.ServerName) == 0 {
687 config.ServerName = "test"
688 }
David Benjamin025b3d32014-07-01 19:53:04 -0400689 }
David Benjaminf2b83632016-03-01 22:57:46 -0500690 if *fuzzer {
691 config.Bugs.NullAllCiphers = true
692 }
Adam Langley95c29f32014-06-20 12:00:00 -0700693
David Benjamin87c8a642015-02-21 01:54:29 -0500694 conn, err := acceptOrWait(listener, waitChan)
695 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400696 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500697 conn.Close()
698 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500699
David Benjamin1d5c83e2014-07-22 19:20:02 -0400700 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400701 var resumeConfig Config
702 if test.resumeConfig != nil {
703 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500704 if len(resumeConfig.ServerName) == 0 {
705 resumeConfig.ServerName = config.ServerName
706 }
David Benjamin01fe8202014-09-24 15:21:44 -0400707 if len(resumeConfig.Certificates) == 0 {
708 resumeConfig.Certificates = []Certificate{getRSACertificate()}
709 }
David Benjaminba4594a2015-06-18 18:36:15 -0400710 if test.newSessionsOnResume {
711 if !test.noSessionCache {
712 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
713 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
714 }
715 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500716 resumeConfig.SessionTicketKey = config.SessionTicketKey
717 resumeConfig.ClientSessionCache = config.ClientSessionCache
718 resumeConfig.ServerSessionCache = config.ServerSessionCache
719 }
David Benjaminf2b83632016-03-01 22:57:46 -0500720 if *fuzzer {
721 resumeConfig.Bugs.NullAllCiphers = true
722 }
David Benjamin01fe8202014-09-24 15:21:44 -0400723 } else {
724 resumeConfig = config
725 }
David Benjamin87c8a642015-02-21 01:54:29 -0500726 var connResume net.Conn
727 connResume, err = acceptOrWait(listener, waitChan)
728 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400729 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500730 connResume.Close()
731 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400732 }
733
David Benjamin87c8a642015-02-21 01:54:29 -0500734 // Close the listener now. This is to avoid hangs should the shim try to
735 // open more connections than expected.
736 listener.Close()
737 listener = nil
738
739 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800740 if exitError, ok := childErr.(*exec.ExitError); ok {
741 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
742 return errMoreMallocs
743 }
744 }
Adam Langley95c29f32014-06-20 12:00:00 -0700745
David Benjamin9bea3492016-03-02 10:59:16 -0500746 // Account for Windows line endings.
747 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
748 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500749
750 // Separate the errors from the shim and those from tools like
751 // AddressSanitizer.
752 var extraStderr string
753 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
754 stderr = stderrParts[0]
755 extraStderr = stderrParts[1]
756 }
757
Adam Langley95c29f32014-06-20 12:00:00 -0700758 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400759 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700760 localError := "none"
761 if err != nil {
762 localError = err.Error()
763 }
764 if len(test.expectedLocalError) != 0 {
765 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
766 }
Adam Langley95c29f32014-06-20 12:00:00 -0700767
768 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700769 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700770 if childErr != nil {
771 childError = childErr.Error()
772 }
773
774 var msg string
775 switch {
776 case failed && !test.shouldFail:
777 msg = "unexpected failure"
778 case !failed && test.shouldFail:
779 msg = "unexpected success"
780 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700781 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700782 default:
783 panic("internal error")
784 }
785
David Benjaminc565ebb2015-04-03 04:06:36 -0400786 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 -0700787 }
788
David Benjaminff3a1492016-03-02 10:12:06 -0500789 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
790 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700791 }
792
793 return nil
794}
795
796var tlsVersions = []struct {
797 name string
798 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400799 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500800 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700801}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500802 {"SSL3", VersionSSL30, "-no-ssl3", false},
803 {"TLS1", VersionTLS10, "-no-tls1", true},
804 {"TLS11", VersionTLS11, "-no-tls11", false},
805 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700806}
807
808var testCipherSuites = []struct {
809 name string
810 id uint16
811}{
812 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400813 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700814 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400815 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400816 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700817 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400818 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400819 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
820 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400821 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400822 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
823 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400824 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700825 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
826 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400827 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
828 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700829 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400830 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500831 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500832 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700833 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700834 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700835 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400836 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400837 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700838 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400839 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500840 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500841 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700842 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400843 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
844 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700845 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
846 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500847 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -0400848 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700849 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400850 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700851 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700852}
853
David Benjamin8b8c0062014-11-23 02:47:52 -0500854func hasComponent(suiteName, component string) bool {
855 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
856}
857
David Benjamin4298d772015-12-19 00:18:25 -0500858func isTLSOnly(suiteName string) bool {
859 // BoringSSL doesn't support ECDHE without a curves extension, and
860 // SSLv3 doesn't contain extensions.
861 return hasComponent(suiteName, "ECDHE") || isTLS12Only(suiteName)
862}
863
David Benjaminf7768e42014-08-31 02:06:47 -0400864func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500865 return hasComponent(suiteName, "GCM") ||
866 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400867 hasComponent(suiteName, "SHA384") ||
868 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500869}
870
871func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700872 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400873}
874
Adam Langleya7997f12015-05-14 17:38:50 -0700875func bigFromHex(hex string) *big.Int {
876 ret, ok := new(big.Int).SetString(hex, 16)
877 if !ok {
878 panic("failed to parse hex number 0x" + hex)
879 }
880 return ret
881}
882
Adam Langley7c803a62015-06-15 15:35:05 -0700883func addBasicTests() {
884 basicTests := []testCase{
885 {
886 name: "BadRSASignature",
887 config: Config{
888 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
889 Bugs: ProtocolBugs{
890 InvalidSKXSignature: true,
891 },
892 },
893 shouldFail: true,
894 expectedError: ":BAD_SIGNATURE:",
895 },
896 {
897 name: "BadECDSASignature",
898 config: Config{
899 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
900 Bugs: ProtocolBugs{
901 InvalidSKXSignature: true,
902 },
903 Certificates: []Certificate{getECDSACertificate()},
904 },
905 shouldFail: true,
906 expectedError: ":BAD_SIGNATURE:",
907 },
908 {
David Benjamin6de0e532015-07-28 22:43:19 -0400909 testType: serverTest,
910 name: "BadRSASignature-ClientAuth",
911 config: Config{
912 Bugs: ProtocolBugs{
913 InvalidCertVerifySignature: true,
914 },
915 Certificates: []Certificate{getRSACertificate()},
916 },
917 shouldFail: true,
918 expectedError: ":BAD_SIGNATURE:",
919 flags: []string{"-require-any-client-certificate"},
920 },
921 {
922 testType: serverTest,
923 name: "BadECDSASignature-ClientAuth",
924 config: Config{
925 Bugs: ProtocolBugs{
926 InvalidCertVerifySignature: true,
927 },
928 Certificates: []Certificate{getECDSACertificate()},
929 },
930 shouldFail: true,
931 expectedError: ":BAD_SIGNATURE:",
932 flags: []string{"-require-any-client-certificate"},
933 },
934 {
Adam Langley7c803a62015-06-15 15:35:05 -0700935 name: "BadECDSACurve",
936 config: Config{
937 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
938 Bugs: ProtocolBugs{
939 InvalidSKXCurve: true,
940 },
941 Certificates: []Certificate{getECDSACertificate()},
942 },
943 shouldFail: true,
944 expectedError: ":WRONG_CURVE:",
945 },
946 {
Adam Langley7c803a62015-06-15 15:35:05 -0700947 name: "NoFallbackSCSV",
948 config: Config{
949 Bugs: ProtocolBugs{
950 FailIfNotFallbackSCSV: true,
951 },
952 },
953 shouldFail: true,
954 expectedLocalError: "no fallback SCSV found",
955 },
956 {
957 name: "SendFallbackSCSV",
958 config: Config{
959 Bugs: ProtocolBugs{
960 FailIfNotFallbackSCSV: true,
961 },
962 },
963 flags: []string{"-fallback-scsv"},
964 },
965 {
966 name: "ClientCertificateTypes",
967 config: Config{
968 ClientAuth: RequestClientCert,
969 ClientCertificateTypes: []byte{
970 CertTypeDSSSign,
971 CertTypeRSASign,
972 CertTypeECDSASign,
973 },
974 },
975 flags: []string{
976 "-expect-certificate-types",
977 base64.StdEncoding.EncodeToString([]byte{
978 CertTypeDSSSign,
979 CertTypeRSASign,
980 CertTypeECDSASign,
981 }),
982 },
983 },
984 {
985 name: "NoClientCertificate",
986 config: Config{
987 ClientAuth: RequireAnyClientCert,
988 },
989 shouldFail: true,
990 expectedLocalError: "client didn't provide a certificate",
991 },
992 {
993 name: "UnauthenticatedECDH",
994 config: Config{
995 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
996 Bugs: ProtocolBugs{
997 UnauthenticatedECDH: true,
998 },
999 },
1000 shouldFail: true,
1001 expectedError: ":UNEXPECTED_MESSAGE:",
1002 },
1003 {
1004 name: "SkipCertificateStatus",
1005 config: Config{
1006 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1007 Bugs: ProtocolBugs{
1008 SkipCertificateStatus: true,
1009 },
1010 },
1011 flags: []string{
1012 "-enable-ocsp-stapling",
1013 },
1014 },
1015 {
1016 name: "SkipServerKeyExchange",
1017 config: Config{
1018 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1019 Bugs: ProtocolBugs{
1020 SkipServerKeyExchange: true,
1021 },
1022 },
1023 shouldFail: true,
1024 expectedError: ":UNEXPECTED_MESSAGE:",
1025 },
1026 {
1027 name: "SkipChangeCipherSpec-Client",
1028 config: Config{
1029 Bugs: ProtocolBugs{
1030 SkipChangeCipherSpec: true,
1031 },
1032 },
1033 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001034 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001035 },
1036 {
1037 testType: serverTest,
1038 name: "SkipChangeCipherSpec-Server",
1039 config: Config{
1040 Bugs: ProtocolBugs{
1041 SkipChangeCipherSpec: true,
1042 },
1043 },
1044 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001045 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001046 },
1047 {
1048 testType: serverTest,
1049 name: "SkipChangeCipherSpec-Server-NPN",
1050 config: Config{
1051 NextProtos: []string{"bar"},
1052 Bugs: ProtocolBugs{
1053 SkipChangeCipherSpec: true,
1054 },
1055 },
1056 flags: []string{
1057 "-advertise-npn", "\x03foo\x03bar\x03baz",
1058 },
1059 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001060 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001061 },
1062 {
1063 name: "FragmentAcrossChangeCipherSpec-Client",
1064 config: Config{
1065 Bugs: ProtocolBugs{
1066 FragmentAcrossChangeCipherSpec: true,
1067 },
1068 },
1069 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001070 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001071 },
1072 {
1073 testType: serverTest,
1074 name: "FragmentAcrossChangeCipherSpec-Server",
1075 config: Config{
1076 Bugs: ProtocolBugs{
1077 FragmentAcrossChangeCipherSpec: true,
1078 },
1079 },
1080 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001081 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001082 },
1083 {
1084 testType: serverTest,
1085 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1086 config: Config{
1087 NextProtos: []string{"bar"},
1088 Bugs: ProtocolBugs{
1089 FragmentAcrossChangeCipherSpec: true,
1090 },
1091 },
1092 flags: []string{
1093 "-advertise-npn", "\x03foo\x03bar\x03baz",
1094 },
1095 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001096 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001097 },
1098 {
1099 testType: serverTest,
1100 name: "Alert",
1101 config: Config{
1102 Bugs: ProtocolBugs{
1103 SendSpuriousAlert: alertRecordOverflow,
1104 },
1105 },
1106 shouldFail: true,
1107 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1108 },
1109 {
1110 protocol: dtls,
1111 testType: serverTest,
1112 name: "Alert-DTLS",
1113 config: Config{
1114 Bugs: ProtocolBugs{
1115 SendSpuriousAlert: alertRecordOverflow,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1120 },
1121 {
1122 testType: serverTest,
1123 name: "FragmentAlert",
1124 config: Config{
1125 Bugs: ProtocolBugs{
1126 FragmentAlert: true,
1127 SendSpuriousAlert: alertRecordOverflow,
1128 },
1129 },
1130 shouldFail: true,
1131 expectedError: ":BAD_ALERT:",
1132 },
1133 {
1134 protocol: dtls,
1135 testType: serverTest,
1136 name: "FragmentAlert-DTLS",
1137 config: Config{
1138 Bugs: ProtocolBugs{
1139 FragmentAlert: true,
1140 SendSpuriousAlert: alertRecordOverflow,
1141 },
1142 },
1143 shouldFail: true,
1144 expectedError: ":BAD_ALERT:",
1145 },
1146 {
1147 testType: serverTest,
1148 name: "EarlyChangeCipherSpec-server-1",
1149 config: Config{
1150 Bugs: ProtocolBugs{
1151 EarlyChangeCipherSpec: 1,
1152 },
1153 },
1154 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001155 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001156 },
1157 {
1158 testType: serverTest,
1159 name: "EarlyChangeCipherSpec-server-2",
1160 config: Config{
1161 Bugs: ProtocolBugs{
1162 EarlyChangeCipherSpec: 2,
1163 },
1164 },
1165 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001166 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001167 },
1168 {
1169 name: "SkipNewSessionTicket",
1170 config: Config{
1171 Bugs: ProtocolBugs{
1172 SkipNewSessionTicket: true,
1173 },
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 testType: serverTest,
1180 name: "FallbackSCSV",
1181 config: Config{
1182 MaxVersion: VersionTLS11,
1183 Bugs: ProtocolBugs{
1184 SendFallbackSCSV: true,
1185 },
1186 },
1187 shouldFail: true,
1188 expectedError: ":INAPPROPRIATE_FALLBACK:",
1189 },
1190 {
1191 testType: serverTest,
1192 name: "FallbackSCSV-VersionMatch",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 SendFallbackSCSV: true,
1196 },
1197 },
1198 },
1199 {
1200 testType: serverTest,
1201 name: "FragmentedClientVersion",
1202 config: Config{
1203 Bugs: ProtocolBugs{
1204 MaxHandshakeRecordLength: 1,
1205 FragmentClientVersion: true,
1206 },
1207 },
1208 expectedVersion: VersionTLS12,
1209 },
1210 {
1211 testType: serverTest,
1212 name: "MinorVersionTolerance",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 SendClientVersion: 0x03ff,
1216 },
1217 },
1218 expectedVersion: VersionTLS12,
1219 },
1220 {
1221 testType: serverTest,
1222 name: "MajorVersionTolerance",
1223 config: Config{
1224 Bugs: ProtocolBugs{
1225 SendClientVersion: 0x0400,
1226 },
1227 },
1228 expectedVersion: VersionTLS12,
1229 },
1230 {
1231 testType: serverTest,
1232 name: "VersionTooLow",
1233 config: Config{
1234 Bugs: ProtocolBugs{
1235 SendClientVersion: 0x0200,
1236 },
1237 },
1238 shouldFail: true,
1239 expectedError: ":UNSUPPORTED_PROTOCOL:",
1240 },
1241 {
1242 testType: serverTest,
1243 name: "HttpGET",
1244 sendPrefix: "GET / HTTP/1.0\n",
1245 shouldFail: true,
1246 expectedError: ":HTTP_REQUEST:",
1247 },
1248 {
1249 testType: serverTest,
1250 name: "HttpPOST",
1251 sendPrefix: "POST / HTTP/1.0\n",
1252 shouldFail: true,
1253 expectedError: ":HTTP_REQUEST:",
1254 },
1255 {
1256 testType: serverTest,
1257 name: "HttpHEAD",
1258 sendPrefix: "HEAD / HTTP/1.0\n",
1259 shouldFail: true,
1260 expectedError: ":HTTP_REQUEST:",
1261 },
1262 {
1263 testType: serverTest,
1264 name: "HttpPUT",
1265 sendPrefix: "PUT / HTTP/1.0\n",
1266 shouldFail: true,
1267 expectedError: ":HTTP_REQUEST:",
1268 },
1269 {
1270 testType: serverTest,
1271 name: "HttpCONNECT",
1272 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1273 shouldFail: true,
1274 expectedError: ":HTTPS_PROXY_REQUEST:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "Garbage",
1279 sendPrefix: "blah",
1280 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001281 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001282 },
1283 {
1284 name: "SkipCipherVersionCheck",
1285 config: Config{
1286 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1287 MaxVersion: VersionTLS11,
1288 Bugs: ProtocolBugs{
1289 SkipCipherVersionCheck: true,
1290 },
1291 },
1292 shouldFail: true,
1293 expectedError: ":WRONG_CIPHER_RETURNED:",
1294 },
1295 {
1296 name: "RSAEphemeralKey",
1297 config: Config{
1298 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1299 Bugs: ProtocolBugs{
1300 RSAEphemeralKey: true,
1301 },
1302 },
1303 shouldFail: true,
1304 expectedError: ":UNEXPECTED_MESSAGE:",
1305 },
1306 {
1307 name: "DisableEverything",
1308 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1309 shouldFail: true,
1310 expectedError: ":WRONG_SSL_VERSION:",
1311 },
1312 {
1313 protocol: dtls,
1314 name: "DisableEverything-DTLS",
1315 flags: []string{"-no-tls12", "-no-tls1"},
1316 shouldFail: true,
1317 expectedError: ":WRONG_SSL_VERSION:",
1318 },
1319 {
1320 name: "NoSharedCipher",
1321 config: Config{
1322 CipherSuites: []uint16{},
1323 },
1324 shouldFail: true,
1325 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1326 },
1327 {
1328 protocol: dtls,
1329 testType: serverTest,
1330 name: "MTU",
1331 config: Config{
1332 Bugs: ProtocolBugs{
1333 MaxPacketLength: 256,
1334 },
1335 },
1336 flags: []string{"-mtu", "256"},
1337 },
1338 {
1339 protocol: dtls,
1340 testType: serverTest,
1341 name: "MTUExceeded",
1342 config: Config{
1343 Bugs: ProtocolBugs{
1344 MaxPacketLength: 255,
1345 },
1346 },
1347 flags: []string{"-mtu", "256"},
1348 shouldFail: true,
1349 expectedLocalError: "dtls: exceeded maximum packet length",
1350 },
1351 {
1352 name: "CertMismatchRSA",
1353 config: Config{
1354 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1355 Certificates: []Certificate{getECDSACertificate()},
1356 Bugs: ProtocolBugs{
1357 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1358 },
1359 },
1360 shouldFail: true,
1361 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1362 },
1363 {
1364 name: "CertMismatchECDSA",
1365 config: Config{
1366 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1367 Certificates: []Certificate{getRSACertificate()},
1368 Bugs: ProtocolBugs{
1369 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1370 },
1371 },
1372 shouldFail: true,
1373 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1374 },
1375 {
1376 name: "EmptyCertificateList",
1377 config: Config{
1378 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1379 Bugs: ProtocolBugs{
1380 EmptyCertificateList: true,
1381 },
1382 },
1383 shouldFail: true,
1384 expectedError: ":DECODE_ERROR:",
1385 },
1386 {
1387 name: "TLSFatalBadPackets",
1388 damageFirstWrite: true,
1389 shouldFail: true,
1390 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1391 },
1392 {
1393 protocol: dtls,
1394 name: "DTLSIgnoreBadPackets",
1395 damageFirstWrite: true,
1396 },
1397 {
1398 protocol: dtls,
1399 name: "DTLSIgnoreBadPackets-Async",
1400 damageFirstWrite: true,
1401 flags: []string{"-async"},
1402 },
1403 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001404 name: "AppDataBeforeHandshake",
1405 config: Config{
1406 Bugs: ProtocolBugs{
1407 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1408 },
1409 },
1410 shouldFail: true,
1411 expectedError: ":UNEXPECTED_RECORD:",
1412 },
1413 {
1414 name: "AppDataBeforeHandshake-Empty",
1415 config: Config{
1416 Bugs: ProtocolBugs{
1417 AppDataBeforeHandshake: []byte{},
1418 },
1419 },
1420 shouldFail: true,
1421 expectedError: ":UNEXPECTED_RECORD:",
1422 },
1423 {
1424 protocol: dtls,
1425 name: "AppDataBeforeHandshake-DTLS",
1426 config: Config{
1427 Bugs: ProtocolBugs{
1428 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":UNEXPECTED_RECORD:",
1433 },
1434 {
1435 protocol: dtls,
1436 name: "AppDataBeforeHandshake-DTLS-Empty",
1437 config: Config{
1438 Bugs: ProtocolBugs{
1439 AppDataBeforeHandshake: []byte{},
1440 },
1441 },
1442 shouldFail: true,
1443 expectedError: ":UNEXPECTED_RECORD:",
1444 },
1445 {
Adam Langley7c803a62015-06-15 15:35:05 -07001446 name: "AppDataAfterChangeCipherSpec",
1447 config: Config{
1448 Bugs: ProtocolBugs{
1449 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1450 },
1451 },
1452 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001453 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001454 },
1455 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001456 name: "AppDataAfterChangeCipherSpec-Empty",
1457 config: Config{
1458 Bugs: ProtocolBugs{
1459 AppDataAfterChangeCipherSpec: []byte{},
1460 },
1461 },
1462 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001463 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001464 },
1465 {
Adam Langley7c803a62015-06-15 15:35:05 -07001466 protocol: dtls,
1467 name: "AppDataAfterChangeCipherSpec-DTLS",
1468 config: Config{
1469 Bugs: ProtocolBugs{
1470 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1471 },
1472 },
1473 // BoringSSL's DTLS implementation will drop the out-of-order
1474 // application data.
1475 },
1476 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001477 protocol: dtls,
1478 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1479 config: Config{
1480 Bugs: ProtocolBugs{
1481 AppDataAfterChangeCipherSpec: []byte{},
1482 },
1483 },
1484 // BoringSSL's DTLS implementation will drop the out-of-order
1485 // application data.
1486 },
1487 {
Adam Langley7c803a62015-06-15 15:35:05 -07001488 name: "AlertAfterChangeCipherSpec",
1489 config: Config{
1490 Bugs: ProtocolBugs{
1491 AlertAfterChangeCipherSpec: alertRecordOverflow,
1492 },
1493 },
1494 shouldFail: true,
1495 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1496 },
1497 {
1498 protocol: dtls,
1499 name: "AlertAfterChangeCipherSpec-DTLS",
1500 config: Config{
1501 Bugs: ProtocolBugs{
1502 AlertAfterChangeCipherSpec: alertRecordOverflow,
1503 },
1504 },
1505 shouldFail: true,
1506 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1507 },
1508 {
1509 protocol: dtls,
1510 name: "ReorderHandshakeFragments-Small-DTLS",
1511 config: Config{
1512 Bugs: ProtocolBugs{
1513 ReorderHandshakeFragments: true,
1514 // Small enough that every handshake message is
1515 // fragmented.
1516 MaxHandshakeRecordLength: 2,
1517 },
1518 },
1519 },
1520 {
1521 protocol: dtls,
1522 name: "ReorderHandshakeFragments-Large-DTLS",
1523 config: Config{
1524 Bugs: ProtocolBugs{
1525 ReorderHandshakeFragments: true,
1526 // Large enough that no handshake message is
1527 // fragmented.
1528 MaxHandshakeRecordLength: 2048,
1529 },
1530 },
1531 },
1532 {
1533 protocol: dtls,
1534 name: "MixCompleteMessageWithFragments-DTLS",
1535 config: Config{
1536 Bugs: ProtocolBugs{
1537 ReorderHandshakeFragments: true,
1538 MixCompleteMessageWithFragments: true,
1539 MaxHandshakeRecordLength: 2,
1540 },
1541 },
1542 },
1543 {
1544 name: "SendInvalidRecordType",
1545 config: Config{
1546 Bugs: ProtocolBugs{
1547 SendInvalidRecordType: true,
1548 },
1549 },
1550 shouldFail: true,
1551 expectedError: ":UNEXPECTED_RECORD:",
1552 },
1553 {
1554 protocol: dtls,
1555 name: "SendInvalidRecordType-DTLS",
1556 config: Config{
1557 Bugs: ProtocolBugs{
1558 SendInvalidRecordType: true,
1559 },
1560 },
1561 shouldFail: true,
1562 expectedError: ":UNEXPECTED_RECORD:",
1563 },
1564 {
1565 name: "FalseStart-SkipServerSecondLeg",
1566 config: Config{
1567 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1568 NextProtos: []string{"foo"},
1569 Bugs: ProtocolBugs{
1570 SkipNewSessionTicket: true,
1571 SkipChangeCipherSpec: true,
1572 SkipFinished: true,
1573 ExpectFalseStart: true,
1574 },
1575 },
1576 flags: []string{
1577 "-false-start",
1578 "-handshake-never-done",
1579 "-advertise-alpn", "\x03foo",
1580 },
1581 shimWritesFirst: true,
1582 shouldFail: true,
1583 expectedError: ":UNEXPECTED_RECORD:",
1584 },
1585 {
1586 name: "FalseStart-SkipServerSecondLeg-Implicit",
1587 config: Config{
1588 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1589 NextProtos: []string{"foo"},
1590 Bugs: ProtocolBugs{
1591 SkipNewSessionTicket: true,
1592 SkipChangeCipherSpec: true,
1593 SkipFinished: true,
1594 },
1595 },
1596 flags: []string{
1597 "-implicit-handshake",
1598 "-false-start",
1599 "-handshake-never-done",
1600 "-advertise-alpn", "\x03foo",
1601 },
1602 shouldFail: true,
1603 expectedError: ":UNEXPECTED_RECORD:",
1604 },
1605 {
1606 testType: serverTest,
1607 name: "FailEarlyCallback",
1608 flags: []string{"-fail-early-callback"},
1609 shouldFail: true,
1610 expectedError: ":CONNECTION_REJECTED:",
1611 expectedLocalError: "remote error: access denied",
1612 },
1613 {
1614 name: "WrongMessageType",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 WrongCertificateMessageType: true,
1618 },
1619 },
1620 shouldFail: true,
1621 expectedError: ":UNEXPECTED_MESSAGE:",
1622 expectedLocalError: "remote error: unexpected message",
1623 },
1624 {
1625 protocol: dtls,
1626 name: "WrongMessageType-DTLS",
1627 config: Config{
1628 Bugs: ProtocolBugs{
1629 WrongCertificateMessageType: true,
1630 },
1631 },
1632 shouldFail: true,
1633 expectedError: ":UNEXPECTED_MESSAGE:",
1634 expectedLocalError: "remote error: unexpected message",
1635 },
1636 {
1637 protocol: dtls,
1638 name: "FragmentMessageTypeMismatch-DTLS",
1639 config: Config{
1640 Bugs: ProtocolBugs{
1641 MaxHandshakeRecordLength: 2,
1642 FragmentMessageTypeMismatch: true,
1643 },
1644 },
1645 shouldFail: true,
1646 expectedError: ":FRAGMENT_MISMATCH:",
1647 },
1648 {
1649 protocol: dtls,
1650 name: "FragmentMessageLengthMismatch-DTLS",
1651 config: Config{
1652 Bugs: ProtocolBugs{
1653 MaxHandshakeRecordLength: 2,
1654 FragmentMessageLengthMismatch: true,
1655 },
1656 },
1657 shouldFail: true,
1658 expectedError: ":FRAGMENT_MISMATCH:",
1659 },
1660 {
1661 protocol: dtls,
1662 name: "SplitFragments-Header-DTLS",
1663 config: Config{
1664 Bugs: ProtocolBugs{
1665 SplitFragments: 2,
1666 },
1667 },
1668 shouldFail: true,
1669 expectedError: ":UNEXPECTED_MESSAGE:",
1670 },
1671 {
1672 protocol: dtls,
1673 name: "SplitFragments-Boundary-DTLS",
1674 config: Config{
1675 Bugs: ProtocolBugs{
1676 SplitFragments: dtlsRecordHeaderLen,
1677 },
1678 },
1679 shouldFail: true,
1680 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1681 },
1682 {
1683 protocol: dtls,
1684 name: "SplitFragments-Body-DTLS",
1685 config: Config{
1686 Bugs: ProtocolBugs{
1687 SplitFragments: dtlsRecordHeaderLen + 1,
1688 },
1689 },
1690 shouldFail: true,
1691 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1692 },
1693 {
1694 protocol: dtls,
1695 name: "SendEmptyFragments-DTLS",
1696 config: Config{
1697 Bugs: ProtocolBugs{
1698 SendEmptyFragments: true,
1699 },
1700 },
1701 },
1702 {
1703 name: "UnsupportedCipherSuite",
1704 config: Config{
1705 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1706 Bugs: ProtocolBugs{
1707 IgnorePeerCipherPreferences: true,
1708 },
1709 },
1710 flags: []string{"-cipher", "DEFAULT:!RC4"},
1711 shouldFail: true,
1712 expectedError: ":WRONG_CIPHER_RETURNED:",
1713 },
1714 {
1715 name: "UnsupportedCurve",
1716 config: Config{
David Benjamin64d92502015-12-19 02:20:57 -05001717 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1718 CurvePreferences: []CurveID{CurveP256},
Adam Langley7c803a62015-06-15 15:35:05 -07001719 Bugs: ProtocolBugs{
1720 IgnorePeerCurvePreferences: true,
1721 },
1722 },
David Benjamin64d92502015-12-19 02:20:57 -05001723 flags: []string{"-p384-only"},
Adam Langley7c803a62015-06-15 15:35:05 -07001724 shouldFail: true,
1725 expectedError: ":WRONG_CURVE:",
1726 },
1727 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001728 name: "BadFinished-Client",
1729 config: Config{
1730 Bugs: ProtocolBugs{
1731 BadFinished: true,
1732 },
1733 },
1734 shouldFail: true,
1735 expectedError: ":DIGEST_CHECK_FAILED:",
1736 },
1737 {
1738 testType: serverTest,
1739 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001740 config: Config{
1741 Bugs: ProtocolBugs{
1742 BadFinished: true,
1743 },
1744 },
1745 shouldFail: true,
1746 expectedError: ":DIGEST_CHECK_FAILED:",
1747 },
1748 {
1749 name: "FalseStart-BadFinished",
1750 config: Config{
1751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1752 NextProtos: []string{"foo"},
1753 Bugs: ProtocolBugs{
1754 BadFinished: true,
1755 ExpectFalseStart: true,
1756 },
1757 },
1758 flags: []string{
1759 "-false-start",
1760 "-handshake-never-done",
1761 "-advertise-alpn", "\x03foo",
1762 },
1763 shimWritesFirst: true,
1764 shouldFail: true,
1765 expectedError: ":DIGEST_CHECK_FAILED:",
1766 },
1767 {
1768 name: "NoFalseStart-NoALPN",
1769 config: Config{
1770 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1771 Bugs: ProtocolBugs{
1772 ExpectFalseStart: true,
1773 AlertBeforeFalseStartTest: alertAccessDenied,
1774 },
1775 },
1776 flags: []string{
1777 "-false-start",
1778 },
1779 shimWritesFirst: true,
1780 shouldFail: true,
1781 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1782 expectedLocalError: "tls: peer did not false start: EOF",
1783 },
1784 {
1785 name: "NoFalseStart-NoAEAD",
1786 config: Config{
1787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1788 NextProtos: []string{"foo"},
1789 Bugs: ProtocolBugs{
1790 ExpectFalseStart: true,
1791 AlertBeforeFalseStartTest: alertAccessDenied,
1792 },
1793 },
1794 flags: []string{
1795 "-false-start",
1796 "-advertise-alpn", "\x03foo",
1797 },
1798 shimWritesFirst: true,
1799 shouldFail: true,
1800 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1801 expectedLocalError: "tls: peer did not false start: EOF",
1802 },
1803 {
1804 name: "NoFalseStart-RSA",
1805 config: Config{
1806 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1807 NextProtos: []string{"foo"},
1808 Bugs: ProtocolBugs{
1809 ExpectFalseStart: true,
1810 AlertBeforeFalseStartTest: alertAccessDenied,
1811 },
1812 },
1813 flags: []string{
1814 "-false-start",
1815 "-advertise-alpn", "\x03foo",
1816 },
1817 shimWritesFirst: true,
1818 shouldFail: true,
1819 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1820 expectedLocalError: "tls: peer did not false start: EOF",
1821 },
1822 {
1823 name: "NoFalseStart-DHE_RSA",
1824 config: Config{
1825 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1826 NextProtos: []string{"foo"},
1827 Bugs: ProtocolBugs{
1828 ExpectFalseStart: true,
1829 AlertBeforeFalseStartTest: alertAccessDenied,
1830 },
1831 },
1832 flags: []string{
1833 "-false-start",
1834 "-advertise-alpn", "\x03foo",
1835 },
1836 shimWritesFirst: true,
1837 shouldFail: true,
1838 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1839 expectedLocalError: "tls: peer did not false start: EOF",
1840 },
1841 {
1842 testType: serverTest,
1843 name: "NoSupportedCurves",
1844 config: Config{
1845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1846 Bugs: ProtocolBugs{
1847 NoSupportedCurves: true,
1848 },
1849 },
David Benjamin4298d772015-12-19 00:18:25 -05001850 shouldFail: true,
1851 expectedError: ":NO_SHARED_CIPHER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001852 },
1853 {
1854 testType: serverTest,
1855 name: "NoCommonCurves",
1856 config: Config{
1857 CipherSuites: []uint16{
1858 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1859 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1860 },
1861 CurvePreferences: []CurveID{CurveP224},
1862 },
1863 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1864 },
1865 {
1866 protocol: dtls,
1867 name: "SendSplitAlert-Sync",
1868 config: Config{
1869 Bugs: ProtocolBugs{
1870 SendSplitAlert: true,
1871 },
1872 },
1873 },
1874 {
1875 protocol: dtls,
1876 name: "SendSplitAlert-Async",
1877 config: Config{
1878 Bugs: ProtocolBugs{
1879 SendSplitAlert: true,
1880 },
1881 },
1882 flags: []string{"-async"},
1883 },
1884 {
1885 protocol: dtls,
1886 name: "PackDTLSHandshake",
1887 config: Config{
1888 Bugs: ProtocolBugs{
1889 MaxHandshakeRecordLength: 2,
1890 PackHandshakeFragments: 20,
1891 PackHandshakeRecords: 200,
1892 },
1893 },
1894 },
1895 {
1896 testType: serverTest,
1897 protocol: dtls,
1898 name: "NoRC4-DTLS",
1899 config: Config{
1900 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1901 Bugs: ProtocolBugs{
1902 EnableAllCiphersInDTLS: true,
1903 },
1904 },
1905 shouldFail: true,
1906 expectedError: ":NO_SHARED_CIPHER:",
1907 },
1908 {
1909 name: "SendEmptyRecords-Pass",
1910 sendEmptyRecords: 32,
1911 },
1912 {
1913 name: "SendEmptyRecords",
1914 sendEmptyRecords: 33,
1915 shouldFail: true,
1916 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1917 },
1918 {
1919 name: "SendEmptyRecords-Async",
1920 sendEmptyRecords: 33,
1921 flags: []string{"-async"},
1922 shouldFail: true,
1923 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1924 },
1925 {
1926 name: "SendWarningAlerts-Pass",
1927 sendWarningAlerts: 4,
1928 },
1929 {
1930 protocol: dtls,
1931 name: "SendWarningAlerts-DTLS-Pass",
1932 sendWarningAlerts: 4,
1933 },
1934 {
1935 name: "SendWarningAlerts",
1936 sendWarningAlerts: 5,
1937 shouldFail: true,
1938 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1939 },
1940 {
1941 name: "SendWarningAlerts-Async",
1942 sendWarningAlerts: 5,
1943 flags: []string{"-async"},
1944 shouldFail: true,
1945 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1946 },
David Benjaminba4594a2015-06-18 18:36:15 -04001947 {
1948 name: "EmptySessionID",
1949 config: Config{
1950 SessionTicketsDisabled: true,
1951 },
1952 noSessionCache: true,
1953 flags: []string{"-expect-no-session"},
1954 },
David Benjamin30789da2015-08-29 22:56:45 -04001955 {
1956 name: "Unclean-Shutdown",
1957 config: Config{
1958 Bugs: ProtocolBugs{
1959 NoCloseNotify: true,
1960 ExpectCloseNotify: true,
1961 },
1962 },
1963 shimShutsDown: true,
1964 flags: []string{"-check-close-notify"},
1965 shouldFail: true,
1966 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1967 },
1968 {
1969 name: "Unclean-Shutdown-Ignored",
1970 config: Config{
1971 Bugs: ProtocolBugs{
1972 NoCloseNotify: true,
1973 },
1974 },
1975 shimShutsDown: true,
1976 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001977 {
1978 name: "LargePlaintext",
1979 config: Config{
1980 Bugs: ProtocolBugs{
1981 SendLargeRecords: true,
1982 },
1983 },
1984 messageLen: maxPlaintext + 1,
1985 shouldFail: true,
1986 expectedError: ":DATA_LENGTH_TOO_LONG:",
1987 },
1988 {
1989 protocol: dtls,
1990 name: "LargePlaintext-DTLS",
1991 config: Config{
1992 Bugs: ProtocolBugs{
1993 SendLargeRecords: true,
1994 },
1995 },
1996 messageLen: maxPlaintext + 1,
1997 shouldFail: true,
1998 expectedError: ":DATA_LENGTH_TOO_LONG:",
1999 },
2000 {
2001 name: "LargeCiphertext",
2002 config: Config{
2003 Bugs: ProtocolBugs{
2004 SendLargeRecords: true,
2005 },
2006 },
2007 messageLen: maxPlaintext * 2,
2008 shouldFail: true,
2009 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2010 },
2011 {
2012 protocol: dtls,
2013 name: "LargeCiphertext-DTLS",
2014 config: Config{
2015 Bugs: ProtocolBugs{
2016 SendLargeRecords: true,
2017 },
2018 },
2019 messageLen: maxPlaintext * 2,
2020 // Unlike the other four cases, DTLS drops records which
2021 // are invalid before authentication, so the connection
2022 // does not fail.
2023 expectMessageDropped: true,
2024 },
David Benjamindd6fed92015-10-23 17:41:12 -04002025 {
2026 name: "SendEmptySessionTicket",
2027 config: Config{
2028 Bugs: ProtocolBugs{
2029 SendEmptySessionTicket: true,
2030 FailIfSessionOffered: true,
2031 },
2032 },
2033 flags: []string{"-expect-no-session"},
2034 resumeSession: true,
2035 expectResumeRejected: true,
2036 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002037 {
2038 name: "CheckLeafCurve",
2039 config: Config{
2040 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2041 Certificates: []Certificate{getECDSACertificate()},
2042 },
2043 flags: []string{"-p384-only"},
2044 shouldFail: true,
2045 expectedError: ":BAD_ECC_CERT:",
2046 },
David Benjamin8411b242015-11-26 12:07:28 -05002047 {
2048 name: "BadChangeCipherSpec-1",
2049 config: Config{
2050 Bugs: ProtocolBugs{
2051 BadChangeCipherSpec: []byte{2},
2052 },
2053 },
2054 shouldFail: true,
2055 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2056 },
2057 {
2058 name: "BadChangeCipherSpec-2",
2059 config: Config{
2060 Bugs: ProtocolBugs{
2061 BadChangeCipherSpec: []byte{1, 1},
2062 },
2063 },
2064 shouldFail: true,
2065 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2066 },
2067 {
2068 protocol: dtls,
2069 name: "BadChangeCipherSpec-DTLS-1",
2070 config: Config{
2071 Bugs: ProtocolBugs{
2072 BadChangeCipherSpec: []byte{2},
2073 },
2074 },
2075 shouldFail: true,
2076 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2077 },
2078 {
2079 protocol: dtls,
2080 name: "BadChangeCipherSpec-DTLS-2",
2081 config: Config{
2082 Bugs: ProtocolBugs{
2083 BadChangeCipherSpec: []byte{1, 1},
2084 },
2085 },
2086 shouldFail: true,
2087 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2088 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002089 {
2090 name: "BadHelloRequest-1",
2091 renegotiate: 1,
2092 config: Config{
2093 Bugs: ProtocolBugs{
2094 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2095 },
2096 },
2097 flags: []string{
2098 "-renegotiate-freely",
2099 "-expect-total-renegotiations", "1",
2100 },
2101 shouldFail: true,
2102 expectedError: ":BAD_HELLO_REQUEST:",
2103 },
2104 {
2105 name: "BadHelloRequest-2",
2106 renegotiate: 1,
2107 config: Config{
2108 Bugs: ProtocolBugs{
2109 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2110 },
2111 },
2112 flags: []string{
2113 "-renegotiate-freely",
2114 "-expect-total-renegotiations", "1",
2115 },
2116 shouldFail: true,
2117 expectedError: ":BAD_HELLO_REQUEST:",
2118 },
David Benjaminef1b0092015-11-21 14:05:44 -05002119 {
2120 testType: serverTest,
2121 name: "SupportTicketsWithSessionID",
2122 config: Config{
2123 SessionTicketsDisabled: true,
2124 },
2125 resumeConfig: &Config{},
2126 resumeSession: true,
2127 },
David Benjamin2b07fa42016-03-02 00:23:57 -05002128 {
2129 name: "InvalidECDHPoint-Client",
2130 config: Config{
2131 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2132 CurvePreferences: []CurveID{CurveP256},
2133 Bugs: ProtocolBugs{
2134 InvalidECDHPoint: true,
2135 },
2136 },
2137 shouldFail: true,
2138 expectedError: ":INVALID_ENCODING:",
2139 },
2140 {
2141 testType: serverTest,
2142 name: "InvalidECDHPoint-Server",
2143 config: Config{
2144 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2145 CurvePreferences: []CurveID{CurveP256},
2146 Bugs: ProtocolBugs{
2147 InvalidECDHPoint: true,
2148 },
2149 },
2150 shouldFail: true,
2151 expectedError: ":INVALID_ENCODING:",
2152 },
Adam Langley7c803a62015-06-15 15:35:05 -07002153 }
Adam Langley7c803a62015-06-15 15:35:05 -07002154 testCases = append(testCases, basicTests...)
2155}
2156
Adam Langley95c29f32014-06-20 12:00:00 -07002157func addCipherSuiteTests() {
2158 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002159 const psk = "12345"
2160 const pskIdentity = "luggage combo"
2161
Adam Langley95c29f32014-06-20 12:00:00 -07002162 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002163 var certFile string
2164 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002165 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002166 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002167 certFile = ecdsaCertificateFile
2168 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002169 } else {
2170 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002171 certFile = rsaCertificateFile
2172 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002173 }
2174
David Benjamin48cae082014-10-27 01:06:24 -04002175 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002176 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002177 flags = append(flags,
2178 "-psk", psk,
2179 "-psk-identity", pskIdentity)
2180 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002181 if hasComponent(suite.name, "NULL") {
2182 // NULL ciphers must be explicitly enabled.
2183 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2184 }
David Benjamin48cae082014-10-27 01:06:24 -04002185
Adam Langley95c29f32014-06-20 12:00:00 -07002186 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002187 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002188 continue
2189 }
2190
David Benjamin4298d772015-12-19 00:18:25 -05002191 shouldFail := isTLSOnly(suite.name) && ver.version == VersionSSL30
2192
2193 expectedError := ""
2194 if shouldFail {
2195 expectedError = ":NO_SHARED_CIPHER:"
2196 }
David Benjamin025b3d32014-07-01 19:53:04 -04002197
David Benjamin76d8abe2014-08-14 16:25:34 -04002198 testCases = append(testCases, testCase{
2199 testType: serverTest,
2200 name: ver.name + "-" + suite.name + "-server",
2201 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002202 MinVersion: ver.version,
2203 MaxVersion: ver.version,
2204 CipherSuites: []uint16{suite.id},
2205 Certificates: []Certificate{cert},
2206 PreSharedKey: []byte(psk),
2207 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002208 },
2209 certFile: certFile,
2210 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002211 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002212 resumeSession: true,
David Benjamin4298d772015-12-19 00:18:25 -05002213 shouldFail: shouldFail,
2214 expectedError: expectedError,
2215 })
2216
2217 if shouldFail {
2218 continue
2219 }
2220
2221 testCases = append(testCases, testCase{
2222 testType: clientTest,
2223 name: ver.name + "-" + suite.name + "-client",
2224 config: Config{
2225 MinVersion: ver.version,
2226 MaxVersion: ver.version,
2227 CipherSuites: []uint16{suite.id},
2228 Certificates: []Certificate{cert},
2229 PreSharedKey: []byte(psk),
2230 PreSharedKeyIdentity: pskIdentity,
2231 },
2232 flags: flags,
2233 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002234 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002235
David Benjamin8b8c0062014-11-23 02:47:52 -05002236 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002237 testCases = append(testCases, testCase{
2238 testType: clientTest,
2239 protocol: dtls,
2240 name: "D" + ver.name + "-" + suite.name + "-client",
2241 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002242 MinVersion: ver.version,
2243 MaxVersion: ver.version,
2244 CipherSuites: []uint16{suite.id},
2245 Certificates: []Certificate{cert},
2246 PreSharedKey: []byte(psk),
2247 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002248 },
David Benjamin48cae082014-10-27 01:06:24 -04002249 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002250 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002251 })
2252 testCases = append(testCases, testCase{
2253 testType: serverTest,
2254 protocol: dtls,
2255 name: "D" + ver.name + "-" + suite.name + "-server",
2256 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002257 MinVersion: ver.version,
2258 MaxVersion: ver.version,
2259 CipherSuites: []uint16{suite.id},
2260 Certificates: []Certificate{cert},
2261 PreSharedKey: []byte(psk),
2262 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002263 },
2264 certFile: certFile,
2265 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002266 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002267 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002268 })
2269 }
Adam Langley95c29f32014-06-20 12:00:00 -07002270 }
David Benjamin2c99d282015-09-01 10:23:00 -04002271
2272 // Ensure both TLS and DTLS accept their maximum record sizes.
2273 testCases = append(testCases, testCase{
2274 name: suite.name + "-LargeRecord",
2275 config: Config{
2276 CipherSuites: []uint16{suite.id},
2277 Certificates: []Certificate{cert},
2278 PreSharedKey: []byte(psk),
2279 PreSharedKeyIdentity: pskIdentity,
2280 },
2281 flags: flags,
2282 messageLen: maxPlaintext,
2283 })
David Benjamin2c99d282015-09-01 10:23:00 -04002284 if isDTLSCipher(suite.name) {
2285 testCases = append(testCases, testCase{
2286 protocol: dtls,
2287 name: suite.name + "-LargeRecord-DTLS",
2288 config: Config{
2289 CipherSuites: []uint16{suite.id},
2290 Certificates: []Certificate{cert},
2291 PreSharedKey: []byte(psk),
2292 PreSharedKeyIdentity: pskIdentity,
2293 },
2294 flags: flags,
2295 messageLen: maxPlaintext,
2296 })
2297 }
Adam Langley95c29f32014-06-20 12:00:00 -07002298 }
Adam Langleya7997f12015-05-14 17:38:50 -07002299
2300 testCases = append(testCases, testCase{
2301 name: "WeakDH",
2302 config: Config{
2303 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2304 Bugs: ProtocolBugs{
2305 // This is a 1023-bit prime number, generated
2306 // with:
2307 // openssl gendh 1023 | openssl asn1parse -i
2308 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2309 },
2310 },
2311 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002312 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002313 })
Adam Langleycef75832015-09-03 14:51:12 -07002314
David Benjamincd24a392015-11-11 13:23:05 -08002315 testCases = append(testCases, testCase{
2316 name: "SillyDH",
2317 config: Config{
2318 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2319 Bugs: ProtocolBugs{
2320 // This is a 4097-bit prime number, generated
2321 // with:
2322 // openssl gendh 4097 | openssl asn1parse -i
2323 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2324 },
2325 },
2326 shouldFail: true,
2327 expectedError: ":DH_P_TOO_LONG:",
2328 })
2329
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002330 // This test ensures that Diffie-Hellman public values are padded with
2331 // zeros so that they're the same length as the prime. This is to avoid
2332 // hitting a bug in yaSSL.
2333 testCases = append(testCases, testCase{
2334 testType: serverTest,
2335 name: "DHPublicValuePadded",
2336 config: Config{
2337 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2338 Bugs: ProtocolBugs{
2339 RequireDHPublicValueLen: (1025 + 7) / 8,
2340 },
2341 },
2342 flags: []string{"-use-sparse-dh-prime"},
2343 })
David Benjamincd24a392015-11-11 13:23:05 -08002344
David Benjamin241ae832016-01-15 03:04:54 -05002345 // The server must be tolerant to bogus ciphers.
2346 const bogusCipher = 0x1234
2347 testCases = append(testCases, testCase{
2348 testType: serverTest,
2349 name: "UnknownCipher",
2350 config: Config{
2351 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2352 },
2353 })
2354
Adam Langleycef75832015-09-03 14:51:12 -07002355 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2356 // 1.1 specific cipher suite settings. A server is setup with the given
2357 // cipher lists and then a connection is made for each member of
2358 // expectations. The cipher suite that the server selects must match
2359 // the specified one.
2360 var versionSpecificCiphersTest = []struct {
2361 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2362 // expectations is a map from TLS version to cipher suite id.
2363 expectations map[uint16]uint16
2364 }{
2365 {
2366 // Test that the null case (where no version-specific ciphers are set)
2367 // works as expected.
2368 "RC4-SHA:AES128-SHA", // default ciphers
2369 "", // no ciphers specifically for TLS ≥ 1.0
2370 "", // no ciphers specifically for TLS ≥ 1.1
2371 map[uint16]uint16{
2372 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2373 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2374 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2375 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2376 },
2377 },
2378 {
2379 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2380 // cipher.
2381 "RC4-SHA:AES128-SHA", // default
2382 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2383 "", // no ciphers specifically for TLS ≥ 1.1
2384 map[uint16]uint16{
2385 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2386 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2387 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2388 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2389 },
2390 },
2391 {
2392 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2393 // cipher.
2394 "RC4-SHA:AES128-SHA", // default
2395 "", // no ciphers specifically for TLS ≥ 1.0
2396 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2397 map[uint16]uint16{
2398 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2399 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2400 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2401 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2402 },
2403 },
2404 {
2405 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2406 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2407 "RC4-SHA:AES128-SHA", // default
2408 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2409 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2410 map[uint16]uint16{
2411 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2412 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2413 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2414 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2415 },
2416 },
2417 }
2418
2419 for i, test := range versionSpecificCiphersTest {
2420 for version, expectedCipherSuite := range test.expectations {
2421 flags := []string{"-cipher", test.ciphersDefault}
2422 if len(test.ciphersTLS10) > 0 {
2423 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2424 }
2425 if len(test.ciphersTLS11) > 0 {
2426 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2427 }
2428
2429 testCases = append(testCases, testCase{
2430 testType: serverTest,
2431 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2432 config: Config{
2433 MaxVersion: version,
2434 MinVersion: version,
2435 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2436 },
2437 flags: flags,
2438 expectedCipher: expectedCipherSuite,
2439 })
2440 }
2441 }
Adam Langley95c29f32014-06-20 12:00:00 -07002442}
2443
2444func addBadECDSASignatureTests() {
2445 for badR := BadValue(1); badR < NumBadValues; badR++ {
2446 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002447 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002448 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2449 config: Config{
2450 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2451 Certificates: []Certificate{getECDSACertificate()},
2452 Bugs: ProtocolBugs{
2453 BadECDSAR: badR,
2454 BadECDSAS: badS,
2455 },
2456 },
2457 shouldFail: true,
2458 expectedError: "SIGNATURE",
2459 })
2460 }
2461 }
2462}
2463
Adam Langley80842bd2014-06-20 12:00:00 -07002464func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002465 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002466 name: "MaxCBCPadding",
2467 config: Config{
2468 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2469 Bugs: ProtocolBugs{
2470 MaxPadding: true,
2471 },
2472 },
2473 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2474 })
David Benjamin025b3d32014-07-01 19:53:04 -04002475 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002476 name: "BadCBCPadding",
2477 config: Config{
2478 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2479 Bugs: ProtocolBugs{
2480 PaddingFirstByteBad: true,
2481 },
2482 },
2483 shouldFail: true,
2484 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2485 })
2486 // OpenSSL previously had an issue where the first byte of padding in
2487 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002488 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002489 name: "BadCBCPadding255",
2490 config: Config{
2491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2492 Bugs: ProtocolBugs{
2493 MaxPadding: true,
2494 PaddingFirstByteBadIf255: true,
2495 },
2496 },
2497 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2498 shouldFail: true,
2499 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2500 })
2501}
2502
Kenny Root7fdeaf12014-08-05 15:23:37 -07002503func addCBCSplittingTests() {
2504 testCases = append(testCases, testCase{
2505 name: "CBCRecordSplitting",
2506 config: Config{
2507 MaxVersion: VersionTLS10,
2508 MinVersion: VersionTLS10,
2509 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2510 },
David Benjaminac8302a2015-09-01 17:18:15 -04002511 messageLen: -1, // read until EOF
2512 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002513 flags: []string{
2514 "-async",
2515 "-write-different-record-sizes",
2516 "-cbc-record-splitting",
2517 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002518 })
2519 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002520 name: "CBCRecordSplittingPartialWrite",
2521 config: Config{
2522 MaxVersion: VersionTLS10,
2523 MinVersion: VersionTLS10,
2524 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2525 },
2526 messageLen: -1, // read until EOF
2527 flags: []string{
2528 "-async",
2529 "-write-different-record-sizes",
2530 "-cbc-record-splitting",
2531 "-partial-write",
2532 },
2533 })
2534}
2535
David Benjamin636293b2014-07-08 17:59:18 -04002536func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002537 // Add a dummy cert pool to stress certificate authority parsing.
2538 // TODO(davidben): Add tests that those values parse out correctly.
2539 certPool := x509.NewCertPool()
2540 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2541 if err != nil {
2542 panic(err)
2543 }
2544 certPool.AddCert(cert)
2545
David Benjamin636293b2014-07-08 17:59:18 -04002546 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002547 testCases = append(testCases, testCase{
2548 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002549 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002550 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002551 MinVersion: ver.version,
2552 MaxVersion: ver.version,
2553 ClientAuth: RequireAnyClientCert,
2554 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002555 },
2556 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002557 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2558 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002559 },
2560 })
2561 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002562 testType: serverTest,
2563 name: ver.name + "-Server-ClientAuth-RSA",
2564 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002565 MinVersion: ver.version,
2566 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002567 Certificates: []Certificate{rsaCertificate},
2568 },
2569 flags: []string{"-require-any-client-certificate"},
2570 })
David Benjamine098ec22014-08-27 23:13:20 -04002571 if ver.version != VersionSSL30 {
2572 testCases = append(testCases, testCase{
2573 testType: serverTest,
2574 name: ver.name + "-Server-ClientAuth-ECDSA",
2575 config: Config{
2576 MinVersion: ver.version,
2577 MaxVersion: ver.version,
2578 Certificates: []Certificate{ecdsaCertificate},
2579 },
2580 flags: []string{"-require-any-client-certificate"},
2581 })
2582 testCases = append(testCases, testCase{
2583 testType: clientTest,
2584 name: ver.name + "-Client-ClientAuth-ECDSA",
2585 config: Config{
2586 MinVersion: ver.version,
2587 MaxVersion: ver.version,
2588 ClientAuth: RequireAnyClientCert,
2589 ClientCAs: certPool,
2590 },
2591 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002592 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2593 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002594 },
2595 })
2596 }
David Benjamin636293b2014-07-08 17:59:18 -04002597 }
2598}
2599
Adam Langley75712922014-10-10 16:23:43 -07002600func addExtendedMasterSecretTests() {
2601 const expectEMSFlag = "-expect-extended-master-secret"
2602
2603 for _, with := range []bool{false, true} {
2604 prefix := "No"
2605 var flags []string
2606 if with {
2607 prefix = ""
2608 flags = []string{expectEMSFlag}
2609 }
2610
2611 for _, isClient := range []bool{false, true} {
2612 suffix := "-Server"
2613 testType := serverTest
2614 if isClient {
2615 suffix = "-Client"
2616 testType = clientTest
2617 }
2618
2619 for _, ver := range tlsVersions {
2620 test := testCase{
2621 testType: testType,
2622 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2623 config: Config{
2624 MinVersion: ver.version,
2625 MaxVersion: ver.version,
2626 Bugs: ProtocolBugs{
2627 NoExtendedMasterSecret: !with,
2628 RequireExtendedMasterSecret: with,
2629 },
2630 },
David Benjamin48cae082014-10-27 01:06:24 -04002631 flags: flags,
2632 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002633 }
2634 if test.shouldFail {
2635 test.expectedLocalError = "extended master secret required but not supported by peer"
2636 }
2637 testCases = append(testCases, test)
2638 }
2639 }
2640 }
2641
Adam Langleyba5934b2015-06-02 10:50:35 -07002642 for _, isClient := range []bool{false, true} {
2643 for _, supportedInFirstConnection := range []bool{false, true} {
2644 for _, supportedInResumeConnection := range []bool{false, true} {
2645 boolToWord := func(b bool) string {
2646 if b {
2647 return "Yes"
2648 }
2649 return "No"
2650 }
2651 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2652 if isClient {
2653 suffix += "Client"
2654 } else {
2655 suffix += "Server"
2656 }
2657
2658 supportedConfig := Config{
2659 Bugs: ProtocolBugs{
2660 RequireExtendedMasterSecret: true,
2661 },
2662 }
2663
2664 noSupportConfig := Config{
2665 Bugs: ProtocolBugs{
2666 NoExtendedMasterSecret: true,
2667 },
2668 }
2669
2670 test := testCase{
2671 name: "ExtendedMasterSecret-" + suffix,
2672 resumeSession: true,
2673 }
2674
2675 if !isClient {
2676 test.testType = serverTest
2677 }
2678
2679 if supportedInFirstConnection {
2680 test.config = supportedConfig
2681 } else {
2682 test.config = noSupportConfig
2683 }
2684
2685 if supportedInResumeConnection {
2686 test.resumeConfig = &supportedConfig
2687 } else {
2688 test.resumeConfig = &noSupportConfig
2689 }
2690
2691 switch suffix {
2692 case "YesToYes-Client", "YesToYes-Server":
2693 // When a session is resumed, it should
2694 // still be aware that its master
2695 // secret was generated via EMS and
2696 // thus it's safe to use tls-unique.
2697 test.flags = []string{expectEMSFlag}
2698 case "NoToYes-Server":
2699 // If an original connection did not
2700 // contain EMS, but a resumption
2701 // handshake does, then a server should
2702 // not resume the session.
2703 test.expectResumeRejected = true
2704 case "YesToNo-Server":
2705 // Resuming an EMS session without the
2706 // EMS extension should cause the
2707 // server to abort the connection.
2708 test.shouldFail = true
2709 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2710 case "NoToYes-Client":
2711 // A client should abort a connection
2712 // where the server resumed a non-EMS
2713 // session but echoed the EMS
2714 // extension.
2715 test.shouldFail = true
2716 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2717 case "YesToNo-Client":
2718 // A client should abort a connection
2719 // where the server didn't echo EMS
2720 // when the session used it.
2721 test.shouldFail = true
2722 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2723 }
2724
2725 testCases = append(testCases, test)
2726 }
2727 }
2728 }
Adam Langley75712922014-10-10 16:23:43 -07002729}
2730
David Benjamin43ec06f2014-08-05 02:28:57 -04002731// Adds tests that try to cover the range of the handshake state machine, under
2732// various conditions. Some of these are redundant with other tests, but they
2733// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002734func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002735 var tests []testCase
2736
2737 // Basic handshake, with resumption. Client and server,
2738 // session ID and session ticket.
2739 tests = append(tests, testCase{
2740 name: "Basic-Client",
2741 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002742 // Ensure session tickets are used, not session IDs.
2743 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002744 })
2745 tests = append(tests, testCase{
2746 name: "Basic-Client-RenewTicket",
2747 config: Config{
2748 Bugs: ProtocolBugs{
2749 RenewTicketOnResume: true,
2750 },
2751 },
David Benjaminba4594a2015-06-18 18:36:15 -04002752 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002753 resumeSession: true,
2754 })
2755 tests = append(tests, testCase{
2756 name: "Basic-Client-NoTicket",
2757 config: Config{
2758 SessionTicketsDisabled: true,
2759 },
2760 resumeSession: true,
2761 })
2762 tests = append(tests, testCase{
2763 name: "Basic-Client-Implicit",
2764 flags: []string{"-implicit-handshake"},
2765 resumeSession: true,
2766 })
2767 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002768 testType: serverTest,
2769 name: "Basic-Server",
2770 config: Config{
2771 Bugs: ProtocolBugs{
2772 RequireSessionTickets: true,
2773 },
2774 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002775 resumeSession: true,
2776 })
2777 tests = append(tests, testCase{
2778 testType: serverTest,
2779 name: "Basic-Server-NoTickets",
2780 config: Config{
2781 SessionTicketsDisabled: true,
2782 },
2783 resumeSession: true,
2784 })
2785 tests = append(tests, testCase{
2786 testType: serverTest,
2787 name: "Basic-Server-Implicit",
2788 flags: []string{"-implicit-handshake"},
2789 resumeSession: true,
2790 })
2791 tests = append(tests, testCase{
2792 testType: serverTest,
2793 name: "Basic-Server-EarlyCallback",
2794 flags: []string{"-use-early-callback"},
2795 resumeSession: true,
2796 })
2797
2798 // TLS client auth.
2799 tests = append(tests, testCase{
2800 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002801 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002802 config: Config{
2803 ClientAuth: RequireAnyClientCert,
2804 },
2805 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002806 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2807 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002808 },
2809 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002810 tests = append(tests, testCase{
2811 testType: clientTest,
2812 name: "ClientAuth-ECDSA-Client",
2813 config: Config{
2814 ClientAuth: RequireAnyClientCert,
2815 },
2816 flags: []string{
2817 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2818 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2819 },
2820 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002821 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002822 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002823 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002824 testType: serverTest,
2825 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002826 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002827 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002828 },
2829 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002830 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2831 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002832 },
2833 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002834 tests = append(tests, testCase{
2835 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002836 name: "Basic-Server-ECDHE-RSA",
2837 config: Config{
2838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2839 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002840 flags: []string{
2841 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2842 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002843 },
2844 })
2845 tests = append(tests, testCase{
2846 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002847 name: "Basic-Server-ECDHE-ECDSA",
2848 config: Config{
2849 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2850 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002851 flags: []string{
2852 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2853 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002854 },
2855 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002856 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002857 tests = append(tests, testCase{
2858 testType: serverTest,
2859 name: "ClientAuth-Server",
2860 config: Config{
2861 Certificates: []Certificate{rsaCertificate},
2862 },
2863 flags: []string{"-require-any-client-certificate"},
2864 })
2865
2866 // No session ticket support; server doesn't send NewSessionTicket.
2867 tests = append(tests, testCase{
2868 name: "SessionTicketsDisabled-Client",
2869 config: Config{
2870 SessionTicketsDisabled: true,
2871 },
2872 })
2873 tests = append(tests, testCase{
2874 testType: serverTest,
2875 name: "SessionTicketsDisabled-Server",
2876 config: Config{
2877 SessionTicketsDisabled: true,
2878 },
2879 })
2880
2881 // Skip ServerKeyExchange in PSK key exchange if there's no
2882 // identity hint.
2883 tests = append(tests, testCase{
2884 name: "EmptyPSKHint-Client",
2885 config: Config{
2886 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2887 PreSharedKey: []byte("secret"),
2888 },
2889 flags: []string{"-psk", "secret"},
2890 })
2891 tests = append(tests, testCase{
2892 testType: serverTest,
2893 name: "EmptyPSKHint-Server",
2894 config: Config{
2895 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2896 PreSharedKey: []byte("secret"),
2897 },
2898 flags: []string{"-psk", "secret"},
2899 })
2900
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002901 tests = append(tests, testCase{
2902 testType: clientTest,
2903 name: "OCSPStapling-Client",
2904 flags: []string{
2905 "-enable-ocsp-stapling",
2906 "-expect-ocsp-response",
2907 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002908 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002909 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002910 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002911 })
2912
2913 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002914 testType: serverTest,
2915 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002916 expectedOCSPResponse: testOCSPResponse,
2917 flags: []string{
2918 "-ocsp-response",
2919 base64.StdEncoding.EncodeToString(testOCSPResponse),
2920 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002921 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002922 })
2923
Paul Lietar8f1c2682015-08-18 12:21:54 +01002924 tests = append(tests, testCase{
2925 testType: clientTest,
2926 name: "CertificateVerificationSucceed",
2927 flags: []string{
2928 "-verify-peer",
2929 },
2930 })
2931
2932 tests = append(tests, testCase{
2933 testType: clientTest,
2934 name: "CertificateVerificationFail",
2935 flags: []string{
2936 "-verify-fail",
2937 "-verify-peer",
2938 },
2939 shouldFail: true,
2940 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2941 })
2942
2943 tests = append(tests, testCase{
2944 testType: clientTest,
2945 name: "CertificateVerificationSoftFail",
2946 flags: []string{
2947 "-verify-fail",
2948 "-expect-verify-result",
2949 },
2950 })
2951
David Benjamin760b1dd2015-05-15 23:33:48 -04002952 if protocol == tls {
2953 tests = append(tests, testCase{
2954 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002955 renegotiate: 1,
2956 flags: []string{
2957 "-renegotiate-freely",
2958 "-expect-total-renegotiations", "1",
2959 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002960 })
2961 // NPN on client and server; results in post-handshake message.
2962 tests = append(tests, testCase{
2963 name: "NPN-Client",
2964 config: Config{
2965 NextProtos: []string{"foo"},
2966 },
2967 flags: []string{"-select-next-proto", "foo"},
2968 expectedNextProto: "foo",
2969 expectedNextProtoType: npn,
2970 })
2971 tests = append(tests, testCase{
2972 testType: serverTest,
2973 name: "NPN-Server",
2974 config: Config{
2975 NextProtos: []string{"bar"},
2976 },
2977 flags: []string{
2978 "-advertise-npn", "\x03foo\x03bar\x03baz",
2979 "-expect-next-proto", "bar",
2980 },
2981 expectedNextProto: "bar",
2982 expectedNextProtoType: npn,
2983 })
2984
2985 // TODO(davidben): Add tests for when False Start doesn't trigger.
2986
2987 // Client does False Start and negotiates NPN.
2988 tests = append(tests, testCase{
2989 name: "FalseStart",
2990 config: Config{
2991 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2992 NextProtos: []string{"foo"},
2993 Bugs: ProtocolBugs{
2994 ExpectFalseStart: true,
2995 },
2996 },
2997 flags: []string{
2998 "-false-start",
2999 "-select-next-proto", "foo",
3000 },
3001 shimWritesFirst: true,
3002 resumeSession: true,
3003 })
3004
3005 // Client does False Start and negotiates ALPN.
3006 tests = append(tests, testCase{
3007 name: "FalseStart-ALPN",
3008 config: Config{
3009 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3010 NextProtos: []string{"foo"},
3011 Bugs: ProtocolBugs{
3012 ExpectFalseStart: true,
3013 },
3014 },
3015 flags: []string{
3016 "-false-start",
3017 "-advertise-alpn", "\x03foo",
3018 },
3019 shimWritesFirst: true,
3020 resumeSession: true,
3021 })
3022
3023 // Client does False Start but doesn't explicitly call
3024 // SSL_connect.
3025 tests = append(tests, testCase{
3026 name: "FalseStart-Implicit",
3027 config: Config{
3028 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3029 NextProtos: []string{"foo"},
3030 },
3031 flags: []string{
3032 "-implicit-handshake",
3033 "-false-start",
3034 "-advertise-alpn", "\x03foo",
3035 },
3036 })
3037
3038 // False Start without session tickets.
3039 tests = append(tests, testCase{
3040 name: "FalseStart-SessionTicketsDisabled",
3041 config: Config{
3042 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3043 NextProtos: []string{"foo"},
3044 SessionTicketsDisabled: true,
3045 Bugs: ProtocolBugs{
3046 ExpectFalseStart: true,
3047 },
3048 },
3049 flags: []string{
3050 "-false-start",
3051 "-select-next-proto", "foo",
3052 },
3053 shimWritesFirst: true,
3054 })
3055
3056 // Server parses a V2ClientHello.
3057 tests = append(tests, testCase{
3058 testType: serverTest,
3059 name: "SendV2ClientHello",
3060 config: Config{
3061 // Choose a cipher suite that does not involve
3062 // elliptic curves, so no extensions are
3063 // involved.
3064 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3065 Bugs: ProtocolBugs{
3066 SendV2ClientHello: true,
3067 },
3068 },
3069 })
3070
3071 // Client sends a Channel ID.
3072 tests = append(tests, testCase{
3073 name: "ChannelID-Client",
3074 config: Config{
3075 RequestChannelID: true,
3076 },
Adam Langley7c803a62015-06-15 15:35:05 -07003077 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003078 resumeSession: true,
3079 expectChannelID: true,
3080 })
3081
3082 // Server accepts a Channel ID.
3083 tests = append(tests, testCase{
3084 testType: serverTest,
3085 name: "ChannelID-Server",
3086 config: Config{
3087 ChannelID: channelIDKey,
3088 },
3089 flags: []string{
3090 "-expect-channel-id",
3091 base64.StdEncoding.EncodeToString(channelIDBytes),
3092 },
3093 resumeSession: true,
3094 expectChannelID: true,
3095 })
David Benjamin30789da2015-08-29 22:56:45 -04003096
3097 // Bidirectional shutdown with the runner initiating.
3098 tests = append(tests, testCase{
3099 name: "Shutdown-Runner",
3100 config: Config{
3101 Bugs: ProtocolBugs{
3102 ExpectCloseNotify: true,
3103 },
3104 },
3105 flags: []string{"-check-close-notify"},
3106 })
3107
3108 // Bidirectional shutdown with the shim initiating. The runner,
3109 // in the meantime, sends garbage before the close_notify which
3110 // the shim must ignore.
3111 tests = append(tests, testCase{
3112 name: "Shutdown-Shim",
3113 config: Config{
3114 Bugs: ProtocolBugs{
3115 ExpectCloseNotify: true,
3116 },
3117 },
3118 shimShutsDown: true,
3119 sendEmptyRecords: 1,
3120 sendWarningAlerts: 1,
3121 flags: []string{"-check-close-notify"},
3122 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003123 } else {
3124 tests = append(tests, testCase{
3125 name: "SkipHelloVerifyRequest",
3126 config: Config{
3127 Bugs: ProtocolBugs{
3128 SkipHelloVerifyRequest: true,
3129 },
3130 },
3131 })
3132 }
3133
David Benjamin760b1dd2015-05-15 23:33:48 -04003134 for _, test := range tests {
3135 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003136 if protocol == dtls {
3137 test.name += "-DTLS"
3138 }
3139 if async {
3140 test.name += "-Async"
3141 test.flags = append(test.flags, "-async")
3142 } else {
3143 test.name += "-Sync"
3144 }
3145 if splitHandshake {
3146 test.name += "-SplitHandshakeRecords"
3147 test.config.Bugs.MaxHandshakeRecordLength = 1
3148 if protocol == dtls {
3149 test.config.Bugs.MaxPacketLength = 256
3150 test.flags = append(test.flags, "-mtu", "256")
3151 }
3152 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003153 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003154 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003155}
3156
Adam Langley524e7172015-02-20 16:04:00 -08003157func addDDoSCallbackTests() {
3158 // DDoS callback.
3159
3160 for _, resume := range []bool{false, true} {
3161 suffix := "Resume"
3162 if resume {
3163 suffix = "No" + suffix
3164 }
3165
3166 testCases = append(testCases, testCase{
3167 testType: serverTest,
3168 name: "Server-DDoS-OK-" + suffix,
3169 flags: []string{"-install-ddos-callback"},
3170 resumeSession: resume,
3171 })
3172
3173 failFlag := "-fail-ddos-callback"
3174 if resume {
3175 failFlag = "-fail-second-ddos-callback"
3176 }
3177 testCases = append(testCases, testCase{
3178 testType: serverTest,
3179 name: "Server-DDoS-Reject-" + suffix,
3180 flags: []string{"-install-ddos-callback", failFlag},
3181 resumeSession: resume,
3182 shouldFail: true,
3183 expectedError: ":CONNECTION_REJECTED:",
3184 })
3185 }
3186}
3187
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003188func addVersionNegotiationTests() {
3189 for i, shimVers := range tlsVersions {
3190 // Assemble flags to disable all newer versions on the shim.
3191 var flags []string
3192 for _, vers := range tlsVersions[i+1:] {
3193 flags = append(flags, vers.flag)
3194 }
3195
3196 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003197 protocols := []protocol{tls}
3198 if runnerVers.hasDTLS && shimVers.hasDTLS {
3199 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003200 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003201 for _, protocol := range protocols {
3202 expectedVersion := shimVers.version
3203 if runnerVers.version < shimVers.version {
3204 expectedVersion = runnerVers.version
3205 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003206
David Benjamin8b8c0062014-11-23 02:47:52 -05003207 suffix := shimVers.name + "-" + runnerVers.name
3208 if protocol == dtls {
3209 suffix += "-DTLS"
3210 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003211
David Benjamin1eb367c2014-12-12 18:17:51 -05003212 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3213
David Benjamin1e29a6b2014-12-10 02:27:24 -05003214 clientVers := shimVers.version
3215 if clientVers > VersionTLS10 {
3216 clientVers = VersionTLS10
3217 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003218 testCases = append(testCases, testCase{
3219 protocol: protocol,
3220 testType: clientTest,
3221 name: "VersionNegotiation-Client-" + suffix,
3222 config: Config{
3223 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003224 Bugs: ProtocolBugs{
3225 ExpectInitialRecordVersion: clientVers,
3226 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003227 },
3228 flags: flags,
3229 expectedVersion: expectedVersion,
3230 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003231 testCases = append(testCases, testCase{
3232 protocol: protocol,
3233 testType: clientTest,
3234 name: "VersionNegotiation-Client2-" + suffix,
3235 config: Config{
3236 MaxVersion: runnerVers.version,
3237 Bugs: ProtocolBugs{
3238 ExpectInitialRecordVersion: clientVers,
3239 },
3240 },
3241 flags: []string{"-max-version", shimVersFlag},
3242 expectedVersion: expectedVersion,
3243 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003244
3245 testCases = append(testCases, testCase{
3246 protocol: protocol,
3247 testType: serverTest,
3248 name: "VersionNegotiation-Server-" + suffix,
3249 config: Config{
3250 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003251 Bugs: ProtocolBugs{
3252 ExpectInitialRecordVersion: expectedVersion,
3253 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003254 },
3255 flags: flags,
3256 expectedVersion: expectedVersion,
3257 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003258 testCases = append(testCases, testCase{
3259 protocol: protocol,
3260 testType: serverTest,
3261 name: "VersionNegotiation-Server2-" + suffix,
3262 config: Config{
3263 MaxVersion: runnerVers.version,
3264 Bugs: ProtocolBugs{
3265 ExpectInitialRecordVersion: expectedVersion,
3266 },
3267 },
3268 flags: []string{"-max-version", shimVersFlag},
3269 expectedVersion: expectedVersion,
3270 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003271 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003272 }
3273 }
3274}
3275
David Benjaminaccb4542014-12-12 23:44:33 -05003276func addMinimumVersionTests() {
3277 for i, shimVers := range tlsVersions {
3278 // Assemble flags to disable all older versions on the shim.
3279 var flags []string
3280 for _, vers := range tlsVersions[:i] {
3281 flags = append(flags, vers.flag)
3282 }
3283
3284 for _, runnerVers := range tlsVersions {
3285 protocols := []protocol{tls}
3286 if runnerVers.hasDTLS && shimVers.hasDTLS {
3287 protocols = append(protocols, dtls)
3288 }
3289 for _, protocol := range protocols {
3290 suffix := shimVers.name + "-" + runnerVers.name
3291 if protocol == dtls {
3292 suffix += "-DTLS"
3293 }
3294 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3295
David Benjaminaccb4542014-12-12 23:44:33 -05003296 var expectedVersion uint16
3297 var shouldFail bool
3298 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003299 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003300 if runnerVers.version >= shimVers.version {
3301 expectedVersion = runnerVers.version
3302 } else {
3303 shouldFail = true
3304 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamina565d292015-12-30 16:51:32 -05003305 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05003306 }
3307
3308 testCases = append(testCases, testCase{
3309 protocol: protocol,
3310 testType: clientTest,
3311 name: "MinimumVersion-Client-" + suffix,
3312 config: Config{
3313 MaxVersion: runnerVers.version,
3314 },
David Benjamin87909c02014-12-13 01:55:01 -05003315 flags: flags,
3316 expectedVersion: expectedVersion,
3317 shouldFail: shouldFail,
3318 expectedError: expectedError,
3319 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003320 })
3321 testCases = append(testCases, testCase{
3322 protocol: protocol,
3323 testType: clientTest,
3324 name: "MinimumVersion-Client2-" + suffix,
3325 config: Config{
3326 MaxVersion: runnerVers.version,
3327 },
David Benjamin87909c02014-12-13 01:55:01 -05003328 flags: []string{"-min-version", shimVersFlag},
3329 expectedVersion: expectedVersion,
3330 shouldFail: shouldFail,
3331 expectedError: expectedError,
3332 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003333 })
3334
3335 testCases = append(testCases, testCase{
3336 protocol: protocol,
3337 testType: serverTest,
3338 name: "MinimumVersion-Server-" + suffix,
3339 config: Config{
3340 MaxVersion: runnerVers.version,
3341 },
David Benjamin87909c02014-12-13 01:55:01 -05003342 flags: flags,
3343 expectedVersion: expectedVersion,
3344 shouldFail: shouldFail,
3345 expectedError: expectedError,
3346 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003347 })
3348 testCases = append(testCases, testCase{
3349 protocol: protocol,
3350 testType: serverTest,
3351 name: "MinimumVersion-Server2-" + suffix,
3352 config: Config{
3353 MaxVersion: runnerVers.version,
3354 },
David Benjamin87909c02014-12-13 01:55:01 -05003355 flags: []string{"-min-version", shimVersFlag},
3356 expectedVersion: expectedVersion,
3357 shouldFail: shouldFail,
3358 expectedError: expectedError,
3359 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003360 })
3361 }
3362 }
3363 }
3364}
3365
David Benjamine78bfde2014-09-06 12:45:15 -04003366func addExtensionTests() {
3367 testCases = append(testCases, testCase{
3368 testType: clientTest,
3369 name: "DuplicateExtensionClient",
3370 config: Config{
3371 Bugs: ProtocolBugs{
3372 DuplicateExtension: true,
3373 },
3374 },
3375 shouldFail: true,
3376 expectedLocalError: "remote error: error decoding message",
3377 })
3378 testCases = append(testCases, testCase{
3379 testType: serverTest,
3380 name: "DuplicateExtensionServer",
3381 config: Config{
3382 Bugs: ProtocolBugs{
3383 DuplicateExtension: true,
3384 },
3385 },
3386 shouldFail: true,
3387 expectedLocalError: "remote error: error decoding message",
3388 })
3389 testCases = append(testCases, testCase{
3390 testType: clientTest,
3391 name: "ServerNameExtensionClient",
3392 config: Config{
3393 Bugs: ProtocolBugs{
3394 ExpectServerName: "example.com",
3395 },
3396 },
3397 flags: []string{"-host-name", "example.com"},
3398 })
3399 testCases = append(testCases, testCase{
3400 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003401 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003402 config: Config{
3403 Bugs: ProtocolBugs{
3404 ExpectServerName: "mismatch.com",
3405 },
3406 },
3407 flags: []string{"-host-name", "example.com"},
3408 shouldFail: true,
3409 expectedLocalError: "tls: unexpected server name",
3410 })
3411 testCases = append(testCases, testCase{
3412 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003413 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003414 config: Config{
3415 Bugs: ProtocolBugs{
3416 ExpectServerName: "missing.com",
3417 },
3418 },
3419 shouldFail: true,
3420 expectedLocalError: "tls: unexpected server name",
3421 })
3422 testCases = append(testCases, testCase{
3423 testType: serverTest,
3424 name: "ServerNameExtensionServer",
3425 config: Config{
3426 ServerName: "example.com",
3427 },
3428 flags: []string{"-expect-server-name", "example.com"},
3429 resumeSession: true,
3430 })
David Benjaminae2888f2014-09-06 12:58:58 -04003431 testCases = append(testCases, testCase{
3432 testType: clientTest,
3433 name: "ALPNClient",
3434 config: Config{
3435 NextProtos: []string{"foo"},
3436 },
3437 flags: []string{
3438 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3439 "-expect-alpn", "foo",
3440 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003441 expectedNextProto: "foo",
3442 expectedNextProtoType: alpn,
3443 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003444 })
3445 testCases = append(testCases, testCase{
3446 testType: serverTest,
3447 name: "ALPNServer",
3448 config: Config{
3449 NextProtos: []string{"foo", "bar", "baz"},
3450 },
3451 flags: []string{
3452 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3453 "-select-alpn", "foo",
3454 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003455 expectedNextProto: "foo",
3456 expectedNextProtoType: alpn,
3457 resumeSession: true,
3458 })
3459 // Test that the server prefers ALPN over NPN.
3460 testCases = append(testCases, testCase{
3461 testType: serverTest,
3462 name: "ALPNServer-Preferred",
3463 config: Config{
3464 NextProtos: []string{"foo", "bar", "baz"},
3465 },
3466 flags: []string{
3467 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3468 "-select-alpn", "foo",
3469 "-advertise-npn", "\x03foo\x03bar\x03baz",
3470 },
3471 expectedNextProto: "foo",
3472 expectedNextProtoType: alpn,
3473 resumeSession: true,
3474 })
3475 testCases = append(testCases, testCase{
3476 testType: serverTest,
3477 name: "ALPNServer-Preferred-Swapped",
3478 config: Config{
3479 NextProtos: []string{"foo", "bar", "baz"},
3480 Bugs: ProtocolBugs{
3481 SwapNPNAndALPN: true,
3482 },
3483 },
3484 flags: []string{
3485 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3486 "-select-alpn", "foo",
3487 "-advertise-npn", "\x03foo\x03bar\x03baz",
3488 },
3489 expectedNextProto: "foo",
3490 expectedNextProtoType: alpn,
3491 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003492 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003493 var emptyString string
3494 testCases = append(testCases, testCase{
3495 testType: clientTest,
3496 name: "ALPNClient-EmptyProtocolName",
3497 config: Config{
3498 NextProtos: []string{""},
3499 Bugs: ProtocolBugs{
3500 // A server returning an empty ALPN protocol
3501 // should be rejected.
3502 ALPNProtocol: &emptyString,
3503 },
3504 },
3505 flags: []string{
3506 "-advertise-alpn", "\x03foo",
3507 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003508 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003509 expectedError: ":PARSE_TLSEXT:",
3510 })
3511 testCases = append(testCases, testCase{
3512 testType: serverTest,
3513 name: "ALPNServer-EmptyProtocolName",
3514 config: Config{
3515 // A ClientHello containing an empty ALPN protocol
3516 // should be rejected.
3517 NextProtos: []string{"foo", "", "baz"},
3518 },
3519 flags: []string{
3520 "-select-alpn", "foo",
3521 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003522 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003523 expectedError: ":PARSE_TLSEXT:",
3524 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003525 // Test that negotiating both NPN and ALPN is forbidden.
3526 testCases = append(testCases, testCase{
3527 name: "NegotiateALPNAndNPN",
3528 config: Config{
3529 NextProtos: []string{"foo", "bar", "baz"},
3530 Bugs: ProtocolBugs{
3531 NegotiateALPNAndNPN: true,
3532 },
3533 },
3534 flags: []string{
3535 "-advertise-alpn", "\x03foo",
3536 "-select-next-proto", "foo",
3537 },
3538 shouldFail: true,
3539 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3540 })
3541 testCases = append(testCases, testCase{
3542 name: "NegotiateALPNAndNPN-Swapped",
3543 config: Config{
3544 NextProtos: []string{"foo", "bar", "baz"},
3545 Bugs: ProtocolBugs{
3546 NegotiateALPNAndNPN: true,
3547 SwapNPNAndALPN: true,
3548 },
3549 },
3550 flags: []string{
3551 "-advertise-alpn", "\x03foo",
3552 "-select-next-proto", "foo",
3553 },
3554 shouldFail: true,
3555 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3556 })
David Benjamin091c4b92015-10-26 13:33:21 -04003557 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3558 testCases = append(testCases, testCase{
3559 name: "DisableNPN",
3560 config: Config{
3561 NextProtos: []string{"foo"},
3562 },
3563 flags: []string{
3564 "-select-next-proto", "foo",
3565 "-disable-npn",
3566 },
3567 expectNoNextProto: true,
3568 })
Adam Langley38311732014-10-16 19:04:35 -07003569 // Resume with a corrupt ticket.
3570 testCases = append(testCases, testCase{
3571 testType: serverTest,
3572 name: "CorruptTicket",
3573 config: Config{
3574 Bugs: ProtocolBugs{
3575 CorruptTicket: true,
3576 },
3577 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003578 resumeSession: true,
3579 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003580 })
David Benjamind98452d2015-06-16 14:16:23 -04003581 // Test the ticket callback, with and without renewal.
3582 testCases = append(testCases, testCase{
3583 testType: serverTest,
3584 name: "TicketCallback",
3585 resumeSession: true,
3586 flags: []string{"-use-ticket-callback"},
3587 })
3588 testCases = append(testCases, testCase{
3589 testType: serverTest,
3590 name: "TicketCallback-Renew",
3591 config: Config{
3592 Bugs: ProtocolBugs{
3593 ExpectNewTicket: true,
3594 },
3595 },
3596 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3597 resumeSession: true,
3598 })
Adam Langley38311732014-10-16 19:04:35 -07003599 // Resume with an oversized session id.
3600 testCases = append(testCases, testCase{
3601 testType: serverTest,
3602 name: "OversizedSessionId",
3603 config: Config{
3604 Bugs: ProtocolBugs{
3605 OversizedSessionId: true,
3606 },
3607 },
3608 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003609 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003610 expectedError: ":DECODE_ERROR:",
3611 })
David Benjaminca6c8262014-11-15 19:06:08 -05003612 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3613 // are ignored.
3614 testCases = append(testCases, testCase{
3615 protocol: dtls,
3616 name: "SRTP-Client",
3617 config: Config{
3618 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3619 },
3620 flags: []string{
3621 "-srtp-profiles",
3622 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3623 },
3624 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3625 })
3626 testCases = append(testCases, testCase{
3627 protocol: dtls,
3628 testType: serverTest,
3629 name: "SRTP-Server",
3630 config: Config{
3631 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3632 },
3633 flags: []string{
3634 "-srtp-profiles",
3635 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3636 },
3637 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3638 })
3639 // Test that the MKI is ignored.
3640 testCases = append(testCases, testCase{
3641 protocol: dtls,
3642 testType: serverTest,
3643 name: "SRTP-Server-IgnoreMKI",
3644 config: Config{
3645 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3646 Bugs: ProtocolBugs{
3647 SRTPMasterKeyIdentifer: "bogus",
3648 },
3649 },
3650 flags: []string{
3651 "-srtp-profiles",
3652 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3653 },
3654 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3655 })
3656 // Test that SRTP isn't negotiated on the server if there were
3657 // no matching profiles.
3658 testCases = append(testCases, testCase{
3659 protocol: dtls,
3660 testType: serverTest,
3661 name: "SRTP-Server-NoMatch",
3662 config: Config{
3663 SRTPProtectionProfiles: []uint16{100, 101, 102},
3664 },
3665 flags: []string{
3666 "-srtp-profiles",
3667 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3668 },
3669 expectedSRTPProtectionProfile: 0,
3670 })
3671 // Test that the server returning an invalid SRTP profile is
3672 // flagged as an error by the client.
3673 testCases = append(testCases, testCase{
3674 protocol: dtls,
3675 name: "SRTP-Client-NoMatch",
3676 config: Config{
3677 Bugs: ProtocolBugs{
3678 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3679 },
3680 },
3681 flags: []string{
3682 "-srtp-profiles",
3683 "SRTP_AES128_CM_SHA1_80",
3684 },
3685 shouldFail: true,
3686 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3687 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003688 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003689 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003690 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003691 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003692 flags: []string{
3693 "-enable-signed-cert-timestamps",
3694 "-expect-signed-cert-timestamps",
3695 base64.StdEncoding.EncodeToString(testSCTList),
3696 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003697 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003698 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003699 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003700 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003701 testType: serverTest,
3702 flags: []string{
3703 "-signed-cert-timestamps",
3704 base64.StdEncoding.EncodeToString(testSCTList),
3705 },
3706 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003707 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003708 })
3709 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003710 testType: clientTest,
3711 name: "ClientHelloPadding",
3712 config: Config{
3713 Bugs: ProtocolBugs{
3714 RequireClientHelloSize: 512,
3715 },
3716 },
3717 // This hostname just needs to be long enough to push the
3718 // ClientHello into F5's danger zone between 256 and 511 bytes
3719 // long.
3720 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3721 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003722
3723 // Extensions should not function in SSL 3.0.
3724 testCases = append(testCases, testCase{
3725 testType: serverTest,
3726 name: "SSLv3Extensions-NoALPN",
3727 config: Config{
3728 MaxVersion: VersionSSL30,
3729 NextProtos: []string{"foo", "bar", "baz"},
3730 },
3731 flags: []string{
3732 "-select-alpn", "foo",
3733 },
3734 expectNoNextProto: true,
3735 })
3736
3737 // Test session tickets separately as they follow a different codepath.
3738 testCases = append(testCases, testCase{
3739 testType: serverTest,
3740 name: "SSLv3Extensions-NoTickets",
3741 config: Config{
3742 MaxVersion: VersionSSL30,
3743 Bugs: ProtocolBugs{
3744 // Historically, session tickets in SSL 3.0
3745 // failed in different ways depending on whether
3746 // the client supported renegotiation_info.
3747 NoRenegotiationInfo: true,
3748 },
3749 },
3750 resumeSession: true,
3751 })
3752 testCases = append(testCases, testCase{
3753 testType: serverTest,
3754 name: "SSLv3Extensions-NoTickets2",
3755 config: Config{
3756 MaxVersion: VersionSSL30,
3757 },
3758 resumeSession: true,
3759 })
3760
3761 // But SSL 3.0 does send and process renegotiation_info.
3762 testCases = append(testCases, testCase{
3763 testType: serverTest,
3764 name: "SSLv3Extensions-RenegotiationInfo",
3765 config: Config{
3766 MaxVersion: VersionSSL30,
3767 Bugs: ProtocolBugs{
3768 RequireRenegotiationInfo: true,
3769 },
3770 },
3771 })
3772 testCases = append(testCases, testCase{
3773 testType: serverTest,
3774 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3775 config: Config{
3776 MaxVersion: VersionSSL30,
3777 Bugs: ProtocolBugs{
3778 NoRenegotiationInfo: true,
3779 SendRenegotiationSCSV: true,
3780 RequireRenegotiationInfo: true,
3781 },
3782 },
3783 })
David Benjamine78bfde2014-09-06 12:45:15 -04003784}
3785
David Benjamin01fe8202014-09-24 15:21:44 -04003786func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003787 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003788 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003789 protocols := []protocol{tls}
3790 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3791 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003792 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003793 for _, protocol := range protocols {
3794 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3795 if protocol == dtls {
3796 suffix += "-DTLS"
3797 }
3798
David Benjaminece3de92015-03-16 18:02:20 -04003799 if sessionVers.version == resumeVers.version {
3800 testCases = append(testCases, testCase{
3801 protocol: protocol,
3802 name: "Resume-Client" + suffix,
3803 resumeSession: true,
3804 config: Config{
3805 MaxVersion: sessionVers.version,
3806 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003807 },
David Benjaminece3de92015-03-16 18:02:20 -04003808 expectedVersion: sessionVers.version,
3809 expectedResumeVersion: resumeVers.version,
3810 })
3811 } else {
3812 testCases = append(testCases, testCase{
3813 protocol: protocol,
3814 name: "Resume-Client-Mismatch" + suffix,
3815 resumeSession: true,
3816 config: Config{
3817 MaxVersion: sessionVers.version,
3818 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003819 },
David Benjaminece3de92015-03-16 18:02:20 -04003820 expectedVersion: sessionVers.version,
3821 resumeConfig: &Config{
3822 MaxVersion: resumeVers.version,
3823 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3824 Bugs: ProtocolBugs{
3825 AllowSessionVersionMismatch: true,
3826 },
3827 },
3828 expectedResumeVersion: resumeVers.version,
3829 shouldFail: true,
3830 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3831 })
3832 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003833
3834 testCases = append(testCases, testCase{
3835 protocol: protocol,
3836 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003837 resumeSession: true,
3838 config: Config{
3839 MaxVersion: sessionVers.version,
3840 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3841 },
3842 expectedVersion: sessionVers.version,
3843 resumeConfig: &Config{
3844 MaxVersion: resumeVers.version,
3845 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3846 },
3847 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003848 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003849 expectedResumeVersion: resumeVers.version,
3850 })
3851
David Benjamin8b8c0062014-11-23 02:47:52 -05003852 testCases = append(testCases, testCase{
3853 protocol: protocol,
3854 testType: serverTest,
3855 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003856 resumeSession: true,
3857 config: Config{
3858 MaxVersion: sessionVers.version,
3859 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3860 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003861 expectedVersion: sessionVers.version,
3862 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003863 resumeConfig: &Config{
3864 MaxVersion: resumeVers.version,
3865 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3866 },
3867 expectedResumeVersion: resumeVers.version,
3868 })
3869 }
David Benjamin01fe8202014-09-24 15:21:44 -04003870 }
3871 }
David Benjaminece3de92015-03-16 18:02:20 -04003872
3873 testCases = append(testCases, testCase{
3874 name: "Resume-Client-CipherMismatch",
3875 resumeSession: true,
3876 config: Config{
3877 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3878 },
3879 resumeConfig: &Config{
3880 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3881 Bugs: ProtocolBugs{
3882 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3883 },
3884 },
3885 shouldFail: true,
3886 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3887 })
David Benjamin01fe8202014-09-24 15:21:44 -04003888}
3889
Adam Langley2ae77d22014-10-28 17:29:33 -07003890func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003891 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003892 testCases = append(testCases, testCase{
3893 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003894 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003895 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003896 shouldFail: true,
3897 expectedError: ":NO_RENEGOTIATION:",
3898 expectedLocalError: "remote error: no renegotiation",
3899 })
Adam Langley5021b222015-06-12 18:27:58 -07003900 // The server shouldn't echo the renegotiation extension unless
3901 // requested by the client.
3902 testCases = append(testCases, testCase{
3903 testType: serverTest,
3904 name: "Renegotiate-Server-NoExt",
3905 config: Config{
3906 Bugs: ProtocolBugs{
3907 NoRenegotiationInfo: true,
3908 RequireRenegotiationInfo: true,
3909 },
3910 },
3911 shouldFail: true,
3912 expectedLocalError: "renegotiation extension missing",
3913 })
3914 // The renegotiation SCSV should be sufficient for the server to echo
3915 // the extension.
3916 testCases = append(testCases, testCase{
3917 testType: serverTest,
3918 name: "Renegotiate-Server-NoExt-SCSV",
3919 config: Config{
3920 Bugs: ProtocolBugs{
3921 NoRenegotiationInfo: true,
3922 SendRenegotiationSCSV: true,
3923 RequireRenegotiationInfo: true,
3924 },
3925 },
3926 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003927 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003928 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003929 config: Config{
3930 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003931 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003932 },
3933 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003934 renegotiate: 1,
3935 flags: []string{
3936 "-renegotiate-freely",
3937 "-expect-total-renegotiations", "1",
3938 },
David Benjamincdea40c2015-03-19 14:09:43 -04003939 })
3940 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003941 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003942 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003943 config: Config{
3944 Bugs: ProtocolBugs{
3945 EmptyRenegotiationInfo: true,
3946 },
3947 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003948 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003949 shouldFail: true,
3950 expectedError: ":RENEGOTIATION_MISMATCH:",
3951 })
3952 testCases = append(testCases, testCase{
3953 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003954 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003955 config: Config{
3956 Bugs: ProtocolBugs{
3957 BadRenegotiationInfo: true,
3958 },
3959 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003960 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003961 shouldFail: true,
3962 expectedError: ":RENEGOTIATION_MISMATCH:",
3963 })
3964 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05003965 name: "Renegotiate-Client-Downgrade",
3966 renegotiate: 1,
3967 config: Config{
3968 Bugs: ProtocolBugs{
3969 NoRenegotiationInfoAfterInitial: true,
3970 },
3971 },
3972 flags: []string{"-renegotiate-freely"},
3973 shouldFail: true,
3974 expectedError: ":RENEGOTIATION_MISMATCH:",
3975 })
3976 testCases = append(testCases, testCase{
3977 name: "Renegotiate-Client-Upgrade",
3978 renegotiate: 1,
3979 config: Config{
3980 Bugs: ProtocolBugs{
3981 NoRenegotiationInfoInInitial: true,
3982 },
3983 },
3984 flags: []string{"-renegotiate-freely"},
3985 shouldFail: true,
3986 expectedError: ":RENEGOTIATION_MISMATCH:",
3987 })
3988 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04003989 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003990 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003991 config: Config{
3992 Bugs: ProtocolBugs{
3993 NoRenegotiationInfo: true,
3994 },
3995 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003996 flags: []string{
3997 "-renegotiate-freely",
3998 "-expect-total-renegotiations", "1",
3999 },
David Benjamincff0b902015-05-15 23:09:47 -04004000 })
4001 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004002 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004003 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004004 config: Config{
4005 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4006 },
4007 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004008 flags: []string{
4009 "-renegotiate-freely",
4010 "-expect-total-renegotiations", "1",
4011 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004012 })
4013 testCases = append(testCases, testCase{
4014 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004015 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004016 config: Config{
4017 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4018 },
4019 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004020 flags: []string{
4021 "-renegotiate-freely",
4022 "-expect-total-renegotiations", "1",
4023 },
David Benjaminb16346b2015-04-08 19:16:58 -04004024 })
4025 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004026 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004027 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004028 config: Config{
4029 MaxVersion: VersionTLS10,
4030 Bugs: ProtocolBugs{
4031 RequireSameRenegoClientVersion: true,
4032 },
4033 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004034 flags: []string{
4035 "-renegotiate-freely",
4036 "-expect-total-renegotiations", "1",
4037 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004038 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004039 testCases = append(testCases, testCase{
4040 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004041 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004042 config: Config{
4043 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4044 NextProtos: []string{"foo"},
4045 },
4046 flags: []string{
4047 "-false-start",
4048 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004049 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004050 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004051 },
4052 shimWritesFirst: true,
4053 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004054
4055 // Client-side renegotiation controls.
4056 testCases = append(testCases, testCase{
4057 name: "Renegotiate-Client-Forbidden-1",
4058 renegotiate: 1,
4059 shouldFail: true,
4060 expectedError: ":NO_RENEGOTIATION:",
4061 expectedLocalError: "remote error: no renegotiation",
4062 })
4063 testCases = append(testCases, testCase{
4064 name: "Renegotiate-Client-Once-1",
4065 renegotiate: 1,
4066 flags: []string{
4067 "-renegotiate-once",
4068 "-expect-total-renegotiations", "1",
4069 },
4070 })
4071 testCases = append(testCases, testCase{
4072 name: "Renegotiate-Client-Freely-1",
4073 renegotiate: 1,
4074 flags: []string{
4075 "-renegotiate-freely",
4076 "-expect-total-renegotiations", "1",
4077 },
4078 })
4079 testCases = append(testCases, testCase{
4080 name: "Renegotiate-Client-Once-2",
4081 renegotiate: 2,
4082 flags: []string{"-renegotiate-once"},
4083 shouldFail: true,
4084 expectedError: ":NO_RENEGOTIATION:",
4085 expectedLocalError: "remote error: no renegotiation",
4086 })
4087 testCases = append(testCases, testCase{
4088 name: "Renegotiate-Client-Freely-2",
4089 renegotiate: 2,
4090 flags: []string{
4091 "-renegotiate-freely",
4092 "-expect-total-renegotiations", "2",
4093 },
4094 })
Adam Langley27a0d082015-11-03 13:34:10 -08004095 testCases = append(testCases, testCase{
4096 name: "Renegotiate-Client-NoIgnore",
4097 config: Config{
4098 Bugs: ProtocolBugs{
4099 SendHelloRequestBeforeEveryAppDataRecord: true,
4100 },
4101 },
4102 shouldFail: true,
4103 expectedError: ":NO_RENEGOTIATION:",
4104 })
4105 testCases = append(testCases, testCase{
4106 name: "Renegotiate-Client-Ignore",
4107 config: Config{
4108 Bugs: ProtocolBugs{
4109 SendHelloRequestBeforeEveryAppDataRecord: true,
4110 },
4111 },
4112 flags: []string{
4113 "-renegotiate-ignore",
4114 "-expect-total-renegotiations", "0",
4115 },
4116 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004117}
4118
David Benjamin5e961c12014-11-07 01:48:35 -05004119func addDTLSReplayTests() {
4120 // Test that sequence number replays are detected.
4121 testCases = append(testCases, testCase{
4122 protocol: dtls,
4123 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004124 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004125 replayWrites: true,
4126 })
4127
David Benjamin8e6db492015-07-25 18:29:23 -04004128 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004129 // than the retransmit window.
4130 testCases = append(testCases, testCase{
4131 protocol: dtls,
4132 name: "DTLS-Replay-LargeGaps",
4133 config: Config{
4134 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004135 SequenceNumberMapping: func(in uint64) uint64 {
4136 return in * 127
4137 },
David Benjamin5e961c12014-11-07 01:48:35 -05004138 },
4139 },
David Benjamin8e6db492015-07-25 18:29:23 -04004140 messageCount: 200,
4141 replayWrites: true,
4142 })
4143
4144 // Test the incoming sequence number changing non-monotonically.
4145 testCases = append(testCases, testCase{
4146 protocol: dtls,
4147 name: "DTLS-Replay-NonMonotonic",
4148 config: Config{
4149 Bugs: ProtocolBugs{
4150 SequenceNumberMapping: func(in uint64) uint64 {
4151 return in ^ 31
4152 },
4153 },
4154 },
4155 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004156 replayWrites: true,
4157 })
4158}
4159
David Benjamin000800a2014-11-14 01:43:59 -05004160var testHashes = []struct {
4161 name string
4162 id uint8
4163}{
4164 {"SHA1", hashSHA1},
David Benjamin000800a2014-11-14 01:43:59 -05004165 {"SHA256", hashSHA256},
4166 {"SHA384", hashSHA384},
4167 {"SHA512", hashSHA512},
4168}
4169
4170func addSigningHashTests() {
4171 // Make sure each hash works. Include some fake hashes in the list and
4172 // ensure they're ignored.
4173 for _, hash := range testHashes {
4174 testCases = append(testCases, testCase{
4175 name: "SigningHash-ClientAuth-" + hash.name,
4176 config: Config{
4177 ClientAuth: RequireAnyClientCert,
4178 SignatureAndHashes: []signatureAndHash{
4179 {signatureRSA, 42},
4180 {signatureRSA, hash.id},
4181 {signatureRSA, 255},
4182 },
4183 },
4184 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004185 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4186 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004187 },
4188 })
4189
4190 testCases = append(testCases, testCase{
4191 testType: serverTest,
4192 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4193 config: Config{
4194 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4195 SignatureAndHashes: []signatureAndHash{
4196 {signatureRSA, 42},
4197 {signatureRSA, hash.id},
4198 {signatureRSA, 255},
4199 },
4200 },
4201 })
David Benjamin6e807652015-11-02 12:02:20 -05004202
4203 testCases = append(testCases, testCase{
4204 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4205 config: Config{
4206 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4207 SignatureAndHashes: []signatureAndHash{
4208 {signatureRSA, 42},
4209 {signatureRSA, hash.id},
4210 {signatureRSA, 255},
4211 },
4212 },
4213 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4214 })
David Benjamin000800a2014-11-14 01:43:59 -05004215 }
4216
4217 // Test that hash resolution takes the signature type into account.
4218 testCases = append(testCases, testCase{
4219 name: "SigningHash-ClientAuth-SignatureType",
4220 config: Config{
4221 ClientAuth: RequireAnyClientCert,
4222 SignatureAndHashes: []signatureAndHash{
4223 {signatureECDSA, hashSHA512},
4224 {signatureRSA, hashSHA384},
4225 {signatureECDSA, hashSHA1},
4226 },
4227 },
4228 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004229 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4230 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004231 },
4232 })
4233
4234 testCases = append(testCases, testCase{
4235 testType: serverTest,
4236 name: "SigningHash-ServerKeyExchange-SignatureType",
4237 config: Config{
4238 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4239 SignatureAndHashes: []signatureAndHash{
4240 {signatureECDSA, hashSHA512},
4241 {signatureRSA, hashSHA384},
4242 {signatureECDSA, hashSHA1},
4243 },
4244 },
4245 })
4246
4247 // Test that, if the list is missing, the peer falls back to SHA-1.
4248 testCases = append(testCases, testCase{
4249 name: "SigningHash-ClientAuth-Fallback",
4250 config: Config{
4251 ClientAuth: RequireAnyClientCert,
4252 SignatureAndHashes: []signatureAndHash{
4253 {signatureRSA, hashSHA1},
4254 },
4255 Bugs: ProtocolBugs{
4256 NoSignatureAndHashes: true,
4257 },
4258 },
4259 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004260 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4261 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004262 },
4263 })
4264
4265 testCases = append(testCases, testCase{
4266 testType: serverTest,
4267 name: "SigningHash-ServerKeyExchange-Fallback",
4268 config: Config{
4269 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4270 SignatureAndHashes: []signatureAndHash{
4271 {signatureRSA, hashSHA1},
4272 },
4273 Bugs: ProtocolBugs{
4274 NoSignatureAndHashes: true,
4275 },
4276 },
4277 })
David Benjamin72dc7832015-03-16 17:49:43 -04004278
4279 // Test that hash preferences are enforced. BoringSSL defaults to
4280 // rejecting MD5 signatures.
4281 testCases = append(testCases, testCase{
4282 testType: serverTest,
4283 name: "SigningHash-ClientAuth-Enforced",
4284 config: Config{
4285 Certificates: []Certificate{rsaCertificate},
4286 SignatureAndHashes: []signatureAndHash{
4287 {signatureRSA, hashMD5},
4288 // Advertise SHA-1 so the handshake will
4289 // proceed, but the shim's preferences will be
4290 // ignored in CertificateVerify generation, so
4291 // MD5 will be chosen.
4292 {signatureRSA, hashSHA1},
4293 },
4294 Bugs: ProtocolBugs{
4295 IgnorePeerSignatureAlgorithmPreferences: true,
4296 },
4297 },
4298 flags: []string{"-require-any-client-certificate"},
4299 shouldFail: true,
4300 expectedError: ":WRONG_SIGNATURE_TYPE:",
4301 })
4302
4303 testCases = append(testCases, testCase{
4304 name: "SigningHash-ServerKeyExchange-Enforced",
4305 config: Config{
4306 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4307 SignatureAndHashes: []signatureAndHash{
4308 {signatureRSA, hashMD5},
4309 },
4310 Bugs: ProtocolBugs{
4311 IgnorePeerSignatureAlgorithmPreferences: true,
4312 },
4313 },
4314 shouldFail: true,
4315 expectedError: ":WRONG_SIGNATURE_TYPE:",
4316 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004317
4318 // Test that the agreed upon digest respects the client preferences and
4319 // the server digests.
4320 testCases = append(testCases, testCase{
4321 name: "Agree-Digest-Fallback",
4322 config: Config{
4323 ClientAuth: RequireAnyClientCert,
4324 SignatureAndHashes: []signatureAndHash{
4325 {signatureRSA, hashSHA512},
4326 {signatureRSA, hashSHA1},
4327 },
4328 },
4329 flags: []string{
4330 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4331 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4332 },
4333 digestPrefs: "SHA256",
4334 expectedClientCertSignatureHash: hashSHA1,
4335 })
4336 testCases = append(testCases, testCase{
4337 name: "Agree-Digest-SHA256",
4338 config: Config{
4339 ClientAuth: RequireAnyClientCert,
4340 SignatureAndHashes: []signatureAndHash{
4341 {signatureRSA, hashSHA1},
4342 {signatureRSA, hashSHA256},
4343 },
4344 },
4345 flags: []string{
4346 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4347 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4348 },
4349 digestPrefs: "SHA256,SHA1",
4350 expectedClientCertSignatureHash: hashSHA256,
4351 })
4352 testCases = append(testCases, testCase{
4353 name: "Agree-Digest-SHA1",
4354 config: Config{
4355 ClientAuth: RequireAnyClientCert,
4356 SignatureAndHashes: []signatureAndHash{
4357 {signatureRSA, hashSHA1},
4358 },
4359 },
4360 flags: []string{
4361 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4362 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4363 },
4364 digestPrefs: "SHA512,SHA256,SHA1",
4365 expectedClientCertSignatureHash: hashSHA1,
4366 })
4367 testCases = append(testCases, testCase{
4368 name: "Agree-Digest-Default",
4369 config: Config{
4370 ClientAuth: RequireAnyClientCert,
4371 SignatureAndHashes: []signatureAndHash{
4372 {signatureRSA, hashSHA256},
4373 {signatureECDSA, hashSHA256},
4374 {signatureRSA, hashSHA1},
4375 {signatureECDSA, hashSHA1},
4376 },
4377 },
4378 flags: []string{
4379 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4380 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4381 },
4382 expectedClientCertSignatureHash: hashSHA256,
4383 })
David Benjamin000800a2014-11-14 01:43:59 -05004384}
4385
David Benjamin83f90402015-01-27 01:09:43 -05004386// timeouts is the retransmit schedule for BoringSSL. It doubles and
4387// caps at 60 seconds. On the 13th timeout, it gives up.
4388var timeouts = []time.Duration{
4389 1 * time.Second,
4390 2 * time.Second,
4391 4 * time.Second,
4392 8 * time.Second,
4393 16 * time.Second,
4394 32 * time.Second,
4395 60 * time.Second,
4396 60 * time.Second,
4397 60 * time.Second,
4398 60 * time.Second,
4399 60 * time.Second,
4400 60 * time.Second,
4401 60 * time.Second,
4402}
4403
4404func addDTLSRetransmitTests() {
4405 // Test that this is indeed the timeout schedule. Stress all
4406 // four patterns of handshake.
4407 for i := 1; i < len(timeouts); i++ {
4408 number := strconv.Itoa(i)
4409 testCases = append(testCases, testCase{
4410 protocol: dtls,
4411 name: "DTLS-Retransmit-Client-" + number,
4412 config: Config{
4413 Bugs: ProtocolBugs{
4414 TimeoutSchedule: timeouts[:i],
4415 },
4416 },
4417 resumeSession: true,
4418 flags: []string{"-async"},
4419 })
4420 testCases = append(testCases, testCase{
4421 protocol: dtls,
4422 testType: serverTest,
4423 name: "DTLS-Retransmit-Server-" + number,
4424 config: Config{
4425 Bugs: ProtocolBugs{
4426 TimeoutSchedule: timeouts[:i],
4427 },
4428 },
4429 resumeSession: true,
4430 flags: []string{"-async"},
4431 })
4432 }
4433
4434 // Test that exceeding the timeout schedule hits a read
4435 // timeout.
4436 testCases = append(testCases, testCase{
4437 protocol: dtls,
4438 name: "DTLS-Retransmit-Timeout",
4439 config: Config{
4440 Bugs: ProtocolBugs{
4441 TimeoutSchedule: timeouts,
4442 },
4443 },
4444 resumeSession: true,
4445 flags: []string{"-async"},
4446 shouldFail: true,
4447 expectedError: ":READ_TIMEOUT_EXPIRED:",
4448 })
4449
4450 // Test that timeout handling has a fudge factor, due to API
4451 // problems.
4452 testCases = append(testCases, testCase{
4453 protocol: dtls,
4454 name: "DTLS-Retransmit-Fudge",
4455 config: Config{
4456 Bugs: ProtocolBugs{
4457 TimeoutSchedule: []time.Duration{
4458 timeouts[0] - 10*time.Millisecond,
4459 },
4460 },
4461 },
4462 resumeSession: true,
4463 flags: []string{"-async"},
4464 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004465
4466 // Test that the final Finished retransmitting isn't
4467 // duplicated if the peer badly fragments everything.
4468 testCases = append(testCases, testCase{
4469 testType: serverTest,
4470 protocol: dtls,
4471 name: "DTLS-Retransmit-Fragmented",
4472 config: Config{
4473 Bugs: ProtocolBugs{
4474 TimeoutSchedule: []time.Duration{timeouts[0]},
4475 MaxHandshakeRecordLength: 2,
4476 },
4477 },
4478 flags: []string{"-async"},
4479 })
David Benjamin83f90402015-01-27 01:09:43 -05004480}
4481
David Benjaminc565ebb2015-04-03 04:06:36 -04004482func addExportKeyingMaterialTests() {
4483 for _, vers := range tlsVersions {
4484 if vers.version == VersionSSL30 {
4485 continue
4486 }
4487 testCases = append(testCases, testCase{
4488 name: "ExportKeyingMaterial-" + vers.name,
4489 config: Config{
4490 MaxVersion: vers.version,
4491 },
4492 exportKeyingMaterial: 1024,
4493 exportLabel: "label",
4494 exportContext: "context",
4495 useExportContext: true,
4496 })
4497 testCases = append(testCases, testCase{
4498 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4499 config: Config{
4500 MaxVersion: vers.version,
4501 },
4502 exportKeyingMaterial: 1024,
4503 })
4504 testCases = append(testCases, testCase{
4505 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4506 config: Config{
4507 MaxVersion: vers.version,
4508 },
4509 exportKeyingMaterial: 1024,
4510 useExportContext: true,
4511 })
4512 testCases = append(testCases, testCase{
4513 name: "ExportKeyingMaterial-Small-" + vers.name,
4514 config: Config{
4515 MaxVersion: vers.version,
4516 },
4517 exportKeyingMaterial: 1,
4518 exportLabel: "label",
4519 exportContext: "context",
4520 useExportContext: true,
4521 })
4522 }
4523 testCases = append(testCases, testCase{
4524 name: "ExportKeyingMaterial-SSL3",
4525 config: Config{
4526 MaxVersion: VersionSSL30,
4527 },
4528 exportKeyingMaterial: 1024,
4529 exportLabel: "label",
4530 exportContext: "context",
4531 useExportContext: true,
4532 shouldFail: true,
4533 expectedError: "failed to export keying material",
4534 })
4535}
4536
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004537func addTLSUniqueTests() {
4538 for _, isClient := range []bool{false, true} {
4539 for _, isResumption := range []bool{false, true} {
4540 for _, hasEMS := range []bool{false, true} {
4541 var suffix string
4542 if isResumption {
4543 suffix = "Resume-"
4544 } else {
4545 suffix = "Full-"
4546 }
4547
4548 if hasEMS {
4549 suffix += "EMS-"
4550 } else {
4551 suffix += "NoEMS-"
4552 }
4553
4554 if isClient {
4555 suffix += "Client"
4556 } else {
4557 suffix += "Server"
4558 }
4559
4560 test := testCase{
4561 name: "TLSUnique-" + suffix,
4562 testTLSUnique: true,
4563 config: Config{
4564 Bugs: ProtocolBugs{
4565 NoExtendedMasterSecret: !hasEMS,
4566 },
4567 },
4568 }
4569
4570 if isResumption {
4571 test.resumeSession = true
4572 test.resumeConfig = &Config{
4573 Bugs: ProtocolBugs{
4574 NoExtendedMasterSecret: !hasEMS,
4575 },
4576 }
4577 }
4578
4579 if isResumption && !hasEMS {
4580 test.shouldFail = true
4581 test.expectedError = "failed to get tls-unique"
4582 }
4583
4584 testCases = append(testCases, test)
4585 }
4586 }
4587 }
4588}
4589
Adam Langley09505632015-07-30 18:10:13 -07004590func addCustomExtensionTests() {
4591 expectedContents := "custom extension"
4592 emptyString := ""
4593
4594 for _, isClient := range []bool{false, true} {
4595 suffix := "Server"
4596 flag := "-enable-server-custom-extension"
4597 testType := serverTest
4598 if isClient {
4599 suffix = "Client"
4600 flag = "-enable-client-custom-extension"
4601 testType = clientTest
4602 }
4603
4604 testCases = append(testCases, testCase{
4605 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004606 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004607 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004608 Bugs: ProtocolBugs{
4609 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004610 ExpectedCustomExtension: &expectedContents,
4611 },
4612 },
4613 flags: []string{flag},
4614 })
4615
4616 // If the parse callback fails, the handshake should also fail.
4617 testCases = append(testCases, testCase{
4618 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004619 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004620 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004621 Bugs: ProtocolBugs{
4622 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004623 ExpectedCustomExtension: &expectedContents,
4624 },
4625 },
David Benjamin399e7c92015-07-30 23:01:27 -04004626 flags: []string{flag},
4627 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004628 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4629 })
4630
4631 // If the add callback fails, the handshake should also fail.
4632 testCases = append(testCases, testCase{
4633 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004634 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004635 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004636 Bugs: ProtocolBugs{
4637 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004638 ExpectedCustomExtension: &expectedContents,
4639 },
4640 },
David Benjamin399e7c92015-07-30 23:01:27 -04004641 flags: []string{flag, "-custom-extension-fail-add"},
4642 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004643 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4644 })
4645
4646 // If the add callback returns zero, no extension should be
4647 // added.
4648 skipCustomExtension := expectedContents
4649 if isClient {
4650 // For the case where the client skips sending the
4651 // custom extension, the server must not “echo” it.
4652 skipCustomExtension = ""
4653 }
4654 testCases = append(testCases, testCase{
4655 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004656 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004657 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004658 Bugs: ProtocolBugs{
4659 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004660 ExpectedCustomExtension: &emptyString,
4661 },
4662 },
4663 flags: []string{flag, "-custom-extension-skip"},
4664 })
4665 }
4666
4667 // The custom extension add callback should not be called if the client
4668 // doesn't send the extension.
4669 testCases = append(testCases, testCase{
4670 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004671 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004672 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004673 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004674 ExpectedCustomExtension: &emptyString,
4675 },
4676 },
4677 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4678 })
Adam Langley2deb9842015-08-07 11:15:37 -07004679
4680 // Test an unknown extension from the server.
4681 testCases = append(testCases, testCase{
4682 testType: clientTest,
4683 name: "UnknownExtension-Client",
4684 config: Config{
4685 Bugs: ProtocolBugs{
4686 CustomExtension: expectedContents,
4687 },
4688 },
4689 shouldFail: true,
4690 expectedError: ":UNEXPECTED_EXTENSION:",
4691 })
Adam Langley09505632015-07-30 18:10:13 -07004692}
4693
David Benjaminb36a3952015-12-01 18:53:13 -05004694func addRSAClientKeyExchangeTests() {
4695 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
4696 testCases = append(testCases, testCase{
4697 testType: serverTest,
4698 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
4699 config: Config{
4700 // Ensure the ClientHello version and final
4701 // version are different, to detect if the
4702 // server uses the wrong one.
4703 MaxVersion: VersionTLS11,
4704 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4705 Bugs: ProtocolBugs{
4706 BadRSAClientKeyExchange: bad,
4707 },
4708 },
4709 shouldFail: true,
4710 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
4711 })
4712 }
4713}
4714
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004715var testCurves = []struct {
4716 name string
4717 id CurveID
4718}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004719 {"P-256", CurveP256},
4720 {"P-384", CurveP384},
4721 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05004722 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004723}
4724
4725func addCurveTests() {
4726 for _, curve := range testCurves {
4727 testCases = append(testCases, testCase{
4728 name: "CurveTest-Client-" + curve.name,
4729 config: Config{
4730 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4731 CurvePreferences: []CurveID{curve.id},
4732 },
4733 flags: []string{"-enable-all-curves"},
4734 })
4735 testCases = append(testCases, testCase{
4736 testType: serverTest,
4737 name: "CurveTest-Server-" + curve.name,
4738 config: Config{
4739 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4740 CurvePreferences: []CurveID{curve.id},
4741 },
4742 flags: []string{"-enable-all-curves"},
4743 })
4744 }
David Benjamin241ae832016-01-15 03:04:54 -05004745
4746 // The server must be tolerant to bogus curves.
4747 const bogusCurve = 0x1234
4748 testCases = append(testCases, testCase{
4749 testType: serverTest,
4750 name: "UnknownCurve",
4751 config: Config{
4752 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4753 CurvePreferences: []CurveID{bogusCurve, CurveP256},
4754 },
4755 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004756}
4757
David Benjamin4cc36ad2015-12-19 14:23:26 -05004758func addKeyExchangeInfoTests() {
4759 testCases = append(testCases, testCase{
4760 name: "KeyExchangeInfo-RSA-Client",
4761 config: Config{
4762 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4763 },
4764 // key.pem is a 1024-bit RSA key.
4765 flags: []string{"-expect-key-exchange-info", "1024"},
4766 })
4767 // TODO(davidben): key_exchange_info doesn't work for plain RSA on the
4768 // server. Either fix this or change the API as it's not very useful in
4769 // this case.
4770
4771 testCases = append(testCases, testCase{
4772 name: "KeyExchangeInfo-DHE-Client",
4773 config: Config{
4774 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
4775 Bugs: ProtocolBugs{
4776 // This is a 1234-bit prime number, generated
4777 // with:
4778 // openssl gendh 1234 | openssl asn1parse -i
4779 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
4780 },
4781 },
4782 flags: []string{"-expect-key-exchange-info", "1234"},
4783 })
4784 testCases = append(testCases, testCase{
4785 testType: serverTest,
4786 name: "KeyExchangeInfo-DHE-Server",
4787 config: Config{
4788 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
4789 },
4790 // bssl_shim as a server configures a 2048-bit DHE group.
4791 flags: []string{"-expect-key-exchange-info", "2048"},
4792 })
4793
4794 testCases = append(testCases, testCase{
4795 name: "KeyExchangeInfo-ECDHE-Client",
4796 config: Config{
4797 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4798 CurvePreferences: []CurveID{CurveX25519},
4799 },
4800 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
4801 })
4802 testCases = append(testCases, testCase{
4803 testType: serverTest,
4804 name: "KeyExchangeInfo-ECDHE-Server",
4805 config: Config{
4806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4807 CurvePreferences: []CurveID{CurveX25519},
4808 },
4809 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
4810 })
4811}
4812
Adam Langley7c803a62015-06-15 15:35:05 -07004813func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004814 defer wg.Done()
4815
4816 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004817 var err error
4818
4819 if *mallocTest < 0 {
4820 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004821 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004822 } else {
4823 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4824 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004825 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004826 if err != nil {
4827 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4828 }
4829 break
4830 }
4831 }
4832 }
Adam Langley95c29f32014-06-20 12:00:00 -07004833 statusChan <- statusMsg{test: test, err: err}
4834 }
4835}
4836
4837type statusMsg struct {
4838 test *testCase
4839 started bool
4840 err error
4841}
4842
David Benjamin5f237bc2015-02-11 17:14:15 -05004843func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004844 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004845
David Benjamin5f237bc2015-02-11 17:14:15 -05004846 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004847 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004848 if !*pipe {
4849 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004850 var erase string
4851 for i := 0; i < lineLen; i++ {
4852 erase += "\b \b"
4853 }
4854 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004855 }
4856
Adam Langley95c29f32014-06-20 12:00:00 -07004857 if msg.started {
4858 started++
4859 } else {
4860 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004861
4862 if msg.err != nil {
4863 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4864 failed++
4865 testOutput.addResult(msg.test.name, "FAIL")
4866 } else {
4867 if *pipe {
4868 // Print each test instead of a status line.
4869 fmt.Printf("PASSED (%s)\n", msg.test.name)
4870 }
4871 testOutput.addResult(msg.test.name, "PASS")
4872 }
Adam Langley95c29f32014-06-20 12:00:00 -07004873 }
4874
David Benjamin5f237bc2015-02-11 17:14:15 -05004875 if !*pipe {
4876 // Print a new status line.
4877 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4878 lineLen = len(line)
4879 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004880 }
Adam Langley95c29f32014-06-20 12:00:00 -07004881 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004882
4883 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004884}
4885
4886func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004887 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004888 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004889
Adam Langley7c803a62015-06-15 15:35:05 -07004890 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004891 addCipherSuiteTests()
4892 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004893 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004894 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004895 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004896 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004897 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004898 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004899 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004900 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004901 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004902 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004903 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004904 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004905 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004906 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004907 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004908 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05004909 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004910 addCurveTests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05004911 addKeyExchangeInfoTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004912 for _, async := range []bool{false, true} {
4913 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004914 for _, protocol := range []protocol{tls, dtls} {
4915 addStateMachineCoverageTests(async, splitHandshake, protocol)
4916 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004917 }
4918 }
Adam Langley95c29f32014-06-20 12:00:00 -07004919
4920 var wg sync.WaitGroup
4921
Adam Langley7c803a62015-06-15 15:35:05 -07004922 statusChan := make(chan statusMsg, *numWorkers)
4923 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004924 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004925
David Benjamin025b3d32014-07-01 19:53:04 -04004926 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004927
Adam Langley7c803a62015-06-15 15:35:05 -07004928 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004929 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004930 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004931 }
4932
David Benjamin025b3d32014-07-01 19:53:04 -04004933 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004934 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004935 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004936 }
4937 }
4938
4939 close(testChan)
4940 wg.Wait()
4941 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004942 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004943
4944 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004945
4946 if *jsonOutput != "" {
4947 if err := testOutput.writeTo(*jsonOutput); err != nil {
4948 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4949 }
4950 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004951
4952 if !testOutput.allPassed {
4953 os.Exit(1)
4954 }
Adam Langley95c29f32014-06-20 12:00:00 -07004955}