blob: b379074a9855435473fe3831ff4961c61903d298 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001package main
2
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")
30 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
31 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
32 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.")
33 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
34 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070035 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
36 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
37 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
38 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
Adam Langley69a01602014-11-17 17:26:55 -080039)
Adam Langley95c29f32014-06-20 12:00:00 -070040
David Benjamin025b3d32014-07-01 19:53:04 -040041const (
42 rsaCertificateFile = "cert.pem"
43 ecdsaCertificateFile = "ecdsa_cert.pem"
44)
45
46const (
David Benjamina08e49d2014-08-24 01:46:07 -040047 rsaKeyFile = "key.pem"
48 ecdsaKeyFile = "ecdsa_key.pem"
49 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040050)
51
Adam Langley95c29f32014-06-20 12:00:00 -070052var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040053var channelIDKey *ecdsa.PrivateKey
54var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070055
David Benjamin61f95272014-11-25 01:55:35 -050056var testOCSPResponse = []byte{1, 2, 3, 4}
57var testSCTList = []byte{5, 6, 7, 8}
58
Adam Langley95c29f32014-06-20 12:00:00 -070059func initCertificates() {
60 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070061 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070062 if err != nil {
63 panic(err)
64 }
David Benjamin61f95272014-11-25 01:55:35 -050065 rsaCertificate.OCSPStaple = testOCSPResponse
66 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070067
Adam Langley7c803a62015-06-15 15:35:05 -070068 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070069 if err != nil {
70 panic(err)
71 }
David Benjamin61f95272014-11-25 01:55:35 -050072 ecdsaCertificate.OCSPStaple = testOCSPResponse
73 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040074
Adam Langley7c803a62015-06-15 15:35:05 -070075 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040076 if err != nil {
77 panic(err)
78 }
79 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
80 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
81 panic("bad key type")
82 }
83 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
84 if err != nil {
85 panic(err)
86 }
87 if channelIDKey.Curve != elliptic.P256() {
88 panic("bad curve")
89 }
90
91 channelIDBytes = make([]byte, 64)
92 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
93 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070094}
95
96var certificateOnce sync.Once
97
98func getRSACertificate() Certificate {
99 certificateOnce.Do(initCertificates)
100 return rsaCertificate
101}
102
103func getECDSACertificate() Certificate {
104 certificateOnce.Do(initCertificates)
105 return ecdsaCertificate
106}
107
David Benjamin025b3d32014-07-01 19:53:04 -0400108type testType int
109
110const (
111 clientTest testType = iota
112 serverTest
113)
114
David Benjamin6fd297b2014-08-11 18:43:38 -0400115type protocol int
116
117const (
118 tls protocol = iota
119 dtls
120)
121
David Benjaminfc7b0862014-09-06 13:21:53 -0400122const (
123 alpn = 1
124 npn = 2
125)
126
Adam Langley95c29f32014-06-20 12:00:00 -0700127type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400128 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400129 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700130 name string
131 config Config
132 shouldFail bool
133 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700134 // expectedLocalError, if not empty, contains a substring that must be
135 // found in the local error.
136 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400137 // expectedVersion, if non-zero, specifies the TLS version that must be
138 // negotiated.
139 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400140 // expectedResumeVersion, if non-zero, specifies the TLS version that
141 // must be negotiated on resumption. If zero, expectedVersion is used.
142 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400143 // expectedCipher, if non-zero, specifies the TLS cipher suite that
144 // should be negotiated.
145 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400146 // expectChannelID controls whether the connection should have
147 // negotiated a Channel ID with channelIDKey.
148 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400149 // expectedNextProto controls whether the connection should
150 // negotiate a next protocol via NPN or ALPN.
151 expectedNextProto string
David Benjaminfc7b0862014-09-06 13:21:53 -0400152 // expectedNextProtoType, if non-zero, is the expected next
153 // protocol negotiation mechanism.
154 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500155 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
156 // should be negotiated. If zero, none should be negotiated.
157 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100158 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
159 expectedOCSPResponse []uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700160 // messageLen is the length, in bytes, of the test message that will be
161 // sent.
162 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400163 // messageCount is the number of test messages that will be sent.
164 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400165 // certFile is the path to the certificate to use for the server.
166 certFile string
167 // keyFile is the path to the private key to use for the server.
168 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400169 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400170 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400171 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700172 // expectResumeRejected, if true, specifies that the attempted
173 // resumption must be rejected by the client. This is only valid for a
174 // serverTest.
175 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400176 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500177 // resumption. Unless newSessionsOnResume is set,
178 // SessionTicketKey, ServerSessionCache, and
179 // ClientSessionCache are copied from the initial connection's
180 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400181 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500182 // newSessionsOnResume, if true, will cause resumeConfig to
183 // use a different session resumption context.
184 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400185 // noSessionCache, if true, will cause the server to run without a
186 // session cache.
187 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400188 // sendPrefix sends a prefix on the socket before actually performing a
189 // handshake.
190 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400191 // shimWritesFirst controls whether the shim sends an initial "hello"
192 // message before doing a roundtrip with the runner.
193 shimWritesFirst bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700194 // renegotiate indicates the the connection should be renegotiated
195 // during the exchange.
196 renegotiate bool
197 // renegotiateCiphers is a list of ciphersuite ids that will be
198 // switched in just before renegotiation.
199 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500200 // replayWrites, if true, configures the underlying transport
201 // to replay every write it makes in DTLS tests.
202 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500203 // damageFirstWrite, if true, configures the underlying transport to
204 // damage the final byte of the first application data write.
205 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400206 // exportKeyingMaterial, if non-zero, configures the test to exchange
207 // keying material and verify they match.
208 exportKeyingMaterial int
209 exportLabel string
210 exportContext string
211 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400212 // flags, if not empty, contains a list of command-line flags that will
213 // be passed to the shim program.
214 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700215 // testTLSUnique, if true, causes the shim to send the tls-unique value
216 // which will be compared against the expected value.
217 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400218 // sendEmptyRecords is the number of consecutive empty records to send
219 // before and after the test message.
220 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400221 // sendWarningAlerts is the number of consecutive warning alerts to send
222 // before and after the test message.
223 sendWarningAlerts int
Adam Langley95c29f32014-06-20 12:00:00 -0700224}
225
Adam Langley7c803a62015-06-15 15:35:05 -0700226var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700227
David Benjamin8e6db492015-07-25 18:29:23 -0400228func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -0500229 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500230 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500231 if *flagDebug {
232 connDebug = &recordingConn{Conn: conn}
233 conn = connDebug
234 defer func() {
235 connDebug.WriteTo(os.Stdout)
236 }()
237 }
238
David Benjamin6fd297b2014-08-11 18:43:38 -0400239 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500240 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
241 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500242 if test.replayWrites {
243 conn = newReplayAdaptor(conn)
244 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400245 }
246
David Benjamin5fa3eba2015-01-22 16:35:40 -0500247 if test.damageFirstWrite {
248 connDamage = newDamageAdaptor(conn)
249 conn = connDamage
250 }
251
David Benjamin6fd297b2014-08-11 18:43:38 -0400252 if test.sendPrefix != "" {
253 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
254 return err
255 }
David Benjamin98e882e2014-08-08 13:24:34 -0400256 }
257
David Benjamin1d5c83e2014-07-22 19:20:02 -0400258 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400259 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400260 if test.protocol == dtls {
261 tlsConn = DTLSServer(conn, config)
262 } else {
263 tlsConn = Server(conn, config)
264 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400265 } else {
266 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400267 if test.protocol == dtls {
268 tlsConn = DTLSClient(conn, config)
269 } else {
270 tlsConn = Client(conn, config)
271 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400272 }
273
Adam Langley95c29f32014-06-20 12:00:00 -0700274 if err := tlsConn.Handshake(); err != nil {
275 return err
276 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700277
David Benjamin01fe8202014-09-24 15:21:44 -0400278 // TODO(davidben): move all per-connection expectations into a dedicated
279 // expectations struct that can be specified separately for the two
280 // legs.
281 expectedVersion := test.expectedVersion
282 if isResume && test.expectedResumeVersion != 0 {
283 expectedVersion = test.expectedResumeVersion
284 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700285 connState := tlsConn.ConnectionState()
286 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400287 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400288 }
289
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700290 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400291 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
292 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700293 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
294 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
295 }
David Benjamin90da8c82015-04-20 14:57:57 -0400296
David Benjamina08e49d2014-08-24 01:46:07 -0400297 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700298 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400299 if channelID == nil {
300 return fmt.Errorf("no channel ID negotiated")
301 }
302 if channelID.Curve != channelIDKey.Curve ||
303 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
304 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
305 return fmt.Errorf("incorrect channel ID")
306 }
307 }
308
David Benjaminae2888f2014-09-06 12:58:58 -0400309 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700310 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400311 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
312 }
313 }
314
David Benjaminfc7b0862014-09-06 13:21:53 -0400315 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700316 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400317 return fmt.Errorf("next proto type mismatch")
318 }
319 }
320
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700321 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500322 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
323 }
324
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100325 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
326 return fmt.Errorf("OCSP Response mismatch")
327 }
328
David Benjaminc565ebb2015-04-03 04:06:36 -0400329 if test.exportKeyingMaterial > 0 {
330 actual := make([]byte, test.exportKeyingMaterial)
331 if _, err := io.ReadFull(tlsConn, actual); err != nil {
332 return err
333 }
334 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
335 if err != nil {
336 return err
337 }
338 if !bytes.Equal(actual, expected) {
339 return fmt.Errorf("keying material mismatch")
340 }
341 }
342
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700343 if test.testTLSUnique {
344 var peersValue [12]byte
345 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
346 return err
347 }
348 expected := tlsConn.ConnectionState().TLSUnique
349 if !bytes.Equal(peersValue[:], expected) {
350 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
351 }
352 }
353
David Benjamine58c4f52014-08-24 03:47:07 -0400354 if test.shimWritesFirst {
355 var buf [5]byte
356 _, err := io.ReadFull(tlsConn, buf[:])
357 if err != nil {
358 return err
359 }
360 if string(buf[:]) != "hello" {
361 return fmt.Errorf("bad initial message")
362 }
363 }
364
David Benjamina8ebe222015-06-06 03:04:39 -0400365 for i := 0; i < test.sendEmptyRecords; i++ {
366 tlsConn.Write(nil)
367 }
368
David Benjamin24f346d2015-06-06 03:28:08 -0400369 for i := 0; i < test.sendWarningAlerts; i++ {
370 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
371 }
372
Adam Langleycf2d4f42014-10-28 19:06:14 -0700373 if test.renegotiate {
374 if test.renegotiateCiphers != nil {
375 config.CipherSuites = test.renegotiateCiphers
376 }
377 if err := tlsConn.Renegotiate(); err != nil {
378 return err
379 }
380 } else if test.renegotiateCiphers != nil {
381 panic("renegotiateCiphers without renegotiate")
382 }
383
David Benjamin5fa3eba2015-01-22 16:35:40 -0500384 if test.damageFirstWrite {
385 connDamage.setDamage(true)
386 tlsConn.Write([]byte("DAMAGED WRITE"))
387 connDamage.setDamage(false)
388 }
389
David Benjamin8e6db492015-07-25 18:29:23 -0400390 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700391 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400392 if test.protocol == dtls {
393 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
394 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700395 // Read until EOF.
396 _, err := io.Copy(ioutil.Discard, tlsConn)
397 return err
398 }
David Benjamin4417d052015-04-05 04:17:25 -0400399 if messageLen == 0 {
400 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700401 }
Adam Langley95c29f32014-06-20 12:00:00 -0700402
David Benjamin8e6db492015-07-25 18:29:23 -0400403 messageCount := test.messageCount
404 if messageCount == 0 {
405 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400406 }
407
David Benjamin8e6db492015-07-25 18:29:23 -0400408 for j := 0; j < messageCount; j++ {
409 testMessage := make([]byte, messageLen)
410 for i := range testMessage {
411 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400412 }
David Benjamin8e6db492015-07-25 18:29:23 -0400413 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700414
David Benjamin8e6db492015-07-25 18:29:23 -0400415 for i := 0; i < test.sendEmptyRecords; i++ {
416 tlsConn.Write(nil)
417 }
418
419 for i := 0; i < test.sendWarningAlerts; i++ {
420 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
421 }
422
423 buf := make([]byte, len(testMessage))
424 if test.protocol == dtls {
425 bufTmp := make([]byte, len(buf)+1)
426 n, err := tlsConn.Read(bufTmp)
427 if err != nil {
428 return err
429 }
430 if n != len(buf) {
431 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
432 }
433 copy(buf, bufTmp)
434 } else {
435 _, err := io.ReadFull(tlsConn, buf)
436 if err != nil {
437 return err
438 }
439 }
440
441 for i, v := range buf {
442 if v != testMessage[i]^0xff {
443 return fmt.Errorf("bad reply contents at byte %d", i)
444 }
Adam Langley95c29f32014-06-20 12:00:00 -0700445 }
446 }
447
448 return nil
449}
450
David Benjamin325b5c32014-07-01 19:40:31 -0400451func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
452 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700453 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400454 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700455 }
David Benjamin325b5c32014-07-01 19:40:31 -0400456 valgrindArgs = append(valgrindArgs, path)
457 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700458
David Benjamin325b5c32014-07-01 19:40:31 -0400459 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700460}
461
David Benjamin325b5c32014-07-01 19:40:31 -0400462func gdbOf(path string, args ...string) *exec.Cmd {
463 xtermArgs := []string{"-e", "gdb", "--args"}
464 xtermArgs = append(xtermArgs, path)
465 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700466
David Benjamin325b5c32014-07-01 19:40:31 -0400467 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700468}
469
Adam Langley69a01602014-11-17 17:26:55 -0800470type moreMallocsError struct{}
471
472func (moreMallocsError) Error() string {
473 return "child process did not exhaust all allocation calls"
474}
475
476var errMoreMallocs = moreMallocsError{}
477
David Benjamin87c8a642015-02-21 01:54:29 -0500478// accept accepts a connection from listener, unless waitChan signals a process
479// exit first.
480func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
481 type connOrError struct {
482 conn net.Conn
483 err error
484 }
485 connChan := make(chan connOrError, 1)
486 go func() {
487 conn, err := listener.Accept()
488 connChan <- connOrError{conn, err}
489 close(connChan)
490 }()
491 select {
492 case result := <-connChan:
493 return result.conn, result.err
494 case childErr := <-waitChan:
495 waitChan <- childErr
496 return nil, fmt.Errorf("child exited early: %s", childErr)
497 }
498}
499
Adam Langley7c803a62015-06-15 15:35:05 -0700500func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700501 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
502 panic("Error expected without shouldFail in " + test.name)
503 }
504
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700505 if test.expectResumeRejected && !test.resumeSession {
506 panic("expectResumeRejected without resumeSession in " + test.name)
507 }
508
David Benjamin87c8a642015-02-21 01:54:29 -0500509 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
510 if err != nil {
511 panic(err)
512 }
513 defer func() {
514 if listener != nil {
515 listener.Close()
516 }
517 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700518
David Benjamin87c8a642015-02-21 01:54:29 -0500519 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400520 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400521 flags = append(flags, "-server")
522
David Benjamin025b3d32014-07-01 19:53:04 -0400523 flags = append(flags, "-key-file")
524 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700525 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400526 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700527 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400528 }
529
530 flags = append(flags, "-cert-file")
531 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700532 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400533 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700534 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400535 }
536 }
David Benjamin5a593af2014-08-11 19:51:50 -0400537
David Benjamin6fd297b2014-08-11 18:43:38 -0400538 if test.protocol == dtls {
539 flags = append(flags, "-dtls")
540 }
541
David Benjamin5a593af2014-08-11 19:51:50 -0400542 if test.resumeSession {
543 flags = append(flags, "-resume")
544 }
545
David Benjamine58c4f52014-08-24 03:47:07 -0400546 if test.shimWritesFirst {
547 flags = append(flags, "-shim-writes-first")
548 }
549
David Benjaminc565ebb2015-04-03 04:06:36 -0400550 if test.exportKeyingMaterial > 0 {
551 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
552 flags = append(flags, "-export-label", test.exportLabel)
553 flags = append(flags, "-export-context", test.exportContext)
554 if test.useExportContext {
555 flags = append(flags, "-use-export-context")
556 }
557 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700558 if test.expectResumeRejected {
559 flags = append(flags, "-expect-session-miss")
560 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400561
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700562 if test.testTLSUnique {
563 flags = append(flags, "-tls-unique")
564 }
565
David Benjamin025b3d32014-07-01 19:53:04 -0400566 flags = append(flags, test.flags...)
567
568 var shim *exec.Cmd
569 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700570 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700571 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700572 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400573 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700574 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400575 }
David Benjamin025b3d32014-07-01 19:53:04 -0400576 shim.Stdin = os.Stdin
577 var stdoutBuf, stderrBuf bytes.Buffer
578 shim.Stdout = &stdoutBuf
579 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800580 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500581 shim.Env = os.Environ()
582 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800583 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400584 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800585 }
586 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
587 }
David Benjamin025b3d32014-07-01 19:53:04 -0400588
589 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700590 panic(err)
591 }
David Benjamin87c8a642015-02-21 01:54:29 -0500592 waitChan := make(chan error, 1)
593 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700594
595 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400596 if !test.noSessionCache {
597 config.ClientSessionCache = NewLRUClientSessionCache(1)
598 config.ServerSessionCache = NewLRUServerSessionCache(1)
599 }
David Benjamin025b3d32014-07-01 19:53:04 -0400600 if test.testType == clientTest {
601 if len(config.Certificates) == 0 {
602 config.Certificates = []Certificate{getRSACertificate()}
603 }
David Benjamin87c8a642015-02-21 01:54:29 -0500604 } else {
605 // Supply a ServerName to ensure a constant session cache key,
606 // rather than falling back to net.Conn.RemoteAddr.
607 if len(config.ServerName) == 0 {
608 config.ServerName = "test"
609 }
David Benjamin025b3d32014-07-01 19:53:04 -0400610 }
Adam Langley95c29f32014-06-20 12:00:00 -0700611
David Benjamin87c8a642015-02-21 01:54:29 -0500612 conn, err := acceptOrWait(listener, waitChan)
613 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400614 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500615 conn.Close()
616 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500617
David Benjamin1d5c83e2014-07-22 19:20:02 -0400618 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400619 var resumeConfig Config
620 if test.resumeConfig != nil {
621 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500622 if len(resumeConfig.ServerName) == 0 {
623 resumeConfig.ServerName = config.ServerName
624 }
David Benjamin01fe8202014-09-24 15:21:44 -0400625 if len(resumeConfig.Certificates) == 0 {
626 resumeConfig.Certificates = []Certificate{getRSACertificate()}
627 }
David Benjaminba4594a2015-06-18 18:36:15 -0400628 if test.newSessionsOnResume {
629 if !test.noSessionCache {
630 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
631 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
632 }
633 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500634 resumeConfig.SessionTicketKey = config.SessionTicketKey
635 resumeConfig.ClientSessionCache = config.ClientSessionCache
636 resumeConfig.ServerSessionCache = config.ServerSessionCache
637 }
David Benjamin01fe8202014-09-24 15:21:44 -0400638 } else {
639 resumeConfig = config
640 }
David Benjamin87c8a642015-02-21 01:54:29 -0500641 var connResume net.Conn
642 connResume, err = acceptOrWait(listener, waitChan)
643 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400644 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500645 connResume.Close()
646 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400647 }
648
David Benjamin87c8a642015-02-21 01:54:29 -0500649 // Close the listener now. This is to avoid hangs should the shim try to
650 // open more connections than expected.
651 listener.Close()
652 listener = nil
653
654 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800655 if exitError, ok := childErr.(*exec.ExitError); ok {
656 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
657 return errMoreMallocs
658 }
659 }
Adam Langley95c29f32014-06-20 12:00:00 -0700660
661 stdout := string(stdoutBuf.Bytes())
662 stderr := string(stderrBuf.Bytes())
663 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400664 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700665 localError := "none"
666 if err != nil {
667 localError = err.Error()
668 }
669 if len(test.expectedLocalError) != 0 {
670 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
671 }
Adam Langley95c29f32014-06-20 12:00:00 -0700672
673 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700674 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700675 if childErr != nil {
676 childError = childErr.Error()
677 }
678
679 var msg string
680 switch {
681 case failed && !test.shouldFail:
682 msg = "unexpected failure"
683 case !failed && test.shouldFail:
684 msg = "unexpected success"
685 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700686 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700687 default:
688 panic("internal error")
689 }
690
David Benjaminc565ebb2015-04-03 04:06:36 -0400691 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 -0700692 }
693
David Benjaminc565ebb2015-04-03 04:06:36 -0400694 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700695 println(stderr)
696 }
697
698 return nil
699}
700
701var tlsVersions = []struct {
702 name string
703 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400704 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500705 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700706}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500707 {"SSL3", VersionSSL30, "-no-ssl3", false},
708 {"TLS1", VersionTLS10, "-no-tls1", true},
709 {"TLS11", VersionTLS11, "-no-tls11", false},
710 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700711}
712
713var testCipherSuites = []struct {
714 name string
715 id uint16
716}{
717 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400718 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700719 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400720 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400721 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700722 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400723 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400724 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
725 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400726 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400727 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
728 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400729 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
David Benjamine9a80ff2015-04-07 00:46:46 -0400730 {"DHE-RSA-CHACHA20-POLY1305", TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700731 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
732 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400733 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
734 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700735 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400736 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400737 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700738 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700739 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700740 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400741 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400742 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700743 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400744 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400745 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700746 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400747 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
748 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700749 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
750 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400751 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700752 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400753 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700754}
755
David Benjamin8b8c0062014-11-23 02:47:52 -0500756func hasComponent(suiteName, component string) bool {
757 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
758}
759
David Benjaminf7768e42014-08-31 02:06:47 -0400760func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500761 return hasComponent(suiteName, "GCM") ||
762 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400763 hasComponent(suiteName, "SHA384") ||
764 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500765}
766
767func isDTLSCipher(suiteName string) bool {
David Benjamine95d20d2014-12-23 11:16:01 -0500768 return !hasComponent(suiteName, "RC4")
David Benjaminf7768e42014-08-31 02:06:47 -0400769}
770
Adam Langleya7997f12015-05-14 17:38:50 -0700771func bigFromHex(hex string) *big.Int {
772 ret, ok := new(big.Int).SetString(hex, 16)
773 if !ok {
774 panic("failed to parse hex number 0x" + hex)
775 }
776 return ret
777}
778
Adam Langley7c803a62015-06-15 15:35:05 -0700779func addBasicTests() {
780 basicTests := []testCase{
781 {
782 name: "BadRSASignature",
783 config: Config{
784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
785 Bugs: ProtocolBugs{
786 InvalidSKXSignature: true,
787 },
788 },
789 shouldFail: true,
790 expectedError: ":BAD_SIGNATURE:",
791 },
792 {
793 name: "BadECDSASignature",
794 config: Config{
795 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
796 Bugs: ProtocolBugs{
797 InvalidSKXSignature: true,
798 },
799 Certificates: []Certificate{getECDSACertificate()},
800 },
801 shouldFail: true,
802 expectedError: ":BAD_SIGNATURE:",
803 },
804 {
David Benjamin6de0e532015-07-28 22:43:19 -0400805 testType: serverTest,
806 name: "BadRSASignature-ClientAuth",
807 config: Config{
808 Bugs: ProtocolBugs{
809 InvalidCertVerifySignature: true,
810 },
811 Certificates: []Certificate{getRSACertificate()},
812 },
813 shouldFail: true,
814 expectedError: ":BAD_SIGNATURE:",
815 flags: []string{"-require-any-client-certificate"},
816 },
817 {
818 testType: serverTest,
819 name: "BadECDSASignature-ClientAuth",
820 config: Config{
821 Bugs: ProtocolBugs{
822 InvalidCertVerifySignature: true,
823 },
824 Certificates: []Certificate{getECDSACertificate()},
825 },
826 shouldFail: true,
827 expectedError: ":BAD_SIGNATURE:",
828 flags: []string{"-require-any-client-certificate"},
829 },
830 {
Adam Langley7c803a62015-06-15 15:35:05 -0700831 name: "BadECDSACurve",
832 config: Config{
833 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
834 Bugs: ProtocolBugs{
835 InvalidSKXCurve: true,
836 },
837 Certificates: []Certificate{getECDSACertificate()},
838 },
839 shouldFail: true,
840 expectedError: ":WRONG_CURVE:",
841 },
842 {
843 testType: serverTest,
844 name: "BadRSAVersion",
845 config: Config{
846 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
847 Bugs: ProtocolBugs{
848 RsaClientKeyExchangeVersion: VersionTLS11,
849 },
850 },
851 shouldFail: true,
852 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
853 },
854 {
855 name: "NoFallbackSCSV",
856 config: Config{
857 Bugs: ProtocolBugs{
858 FailIfNotFallbackSCSV: true,
859 },
860 },
861 shouldFail: true,
862 expectedLocalError: "no fallback SCSV found",
863 },
864 {
865 name: "SendFallbackSCSV",
866 config: Config{
867 Bugs: ProtocolBugs{
868 FailIfNotFallbackSCSV: true,
869 },
870 },
871 flags: []string{"-fallback-scsv"},
872 },
873 {
874 name: "ClientCertificateTypes",
875 config: Config{
876 ClientAuth: RequestClientCert,
877 ClientCertificateTypes: []byte{
878 CertTypeDSSSign,
879 CertTypeRSASign,
880 CertTypeECDSASign,
881 },
882 },
883 flags: []string{
884 "-expect-certificate-types",
885 base64.StdEncoding.EncodeToString([]byte{
886 CertTypeDSSSign,
887 CertTypeRSASign,
888 CertTypeECDSASign,
889 }),
890 },
891 },
892 {
893 name: "NoClientCertificate",
894 config: Config{
895 ClientAuth: RequireAnyClientCert,
896 },
897 shouldFail: true,
898 expectedLocalError: "client didn't provide a certificate",
899 },
900 {
901 name: "UnauthenticatedECDH",
902 config: Config{
903 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
904 Bugs: ProtocolBugs{
905 UnauthenticatedECDH: true,
906 },
907 },
908 shouldFail: true,
909 expectedError: ":UNEXPECTED_MESSAGE:",
910 },
911 {
912 name: "SkipCertificateStatus",
913 config: Config{
914 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
915 Bugs: ProtocolBugs{
916 SkipCertificateStatus: true,
917 },
918 },
919 flags: []string{
920 "-enable-ocsp-stapling",
921 },
922 },
923 {
924 name: "SkipServerKeyExchange",
925 config: Config{
926 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
927 Bugs: ProtocolBugs{
928 SkipServerKeyExchange: true,
929 },
930 },
931 shouldFail: true,
932 expectedError: ":UNEXPECTED_MESSAGE:",
933 },
934 {
935 name: "SkipChangeCipherSpec-Client",
936 config: Config{
937 Bugs: ProtocolBugs{
938 SkipChangeCipherSpec: true,
939 },
940 },
941 shouldFail: true,
942 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
943 },
944 {
945 testType: serverTest,
946 name: "SkipChangeCipherSpec-Server",
947 config: Config{
948 Bugs: ProtocolBugs{
949 SkipChangeCipherSpec: true,
950 },
951 },
952 shouldFail: true,
953 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
954 },
955 {
956 testType: serverTest,
957 name: "SkipChangeCipherSpec-Server-NPN",
958 config: Config{
959 NextProtos: []string{"bar"},
960 Bugs: ProtocolBugs{
961 SkipChangeCipherSpec: true,
962 },
963 },
964 flags: []string{
965 "-advertise-npn", "\x03foo\x03bar\x03baz",
966 },
967 shouldFail: true,
968 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
969 },
970 {
971 name: "FragmentAcrossChangeCipherSpec-Client",
972 config: Config{
973 Bugs: ProtocolBugs{
974 FragmentAcrossChangeCipherSpec: true,
975 },
976 },
977 shouldFail: true,
978 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
979 },
980 {
981 testType: serverTest,
982 name: "FragmentAcrossChangeCipherSpec-Server",
983 config: Config{
984 Bugs: ProtocolBugs{
985 FragmentAcrossChangeCipherSpec: true,
986 },
987 },
988 shouldFail: true,
989 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
990 },
991 {
992 testType: serverTest,
993 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
994 config: Config{
995 NextProtos: []string{"bar"},
996 Bugs: ProtocolBugs{
997 FragmentAcrossChangeCipherSpec: true,
998 },
999 },
1000 flags: []string{
1001 "-advertise-npn", "\x03foo\x03bar\x03baz",
1002 },
1003 shouldFail: true,
1004 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1005 },
1006 {
1007 testType: serverTest,
1008 name: "Alert",
1009 config: Config{
1010 Bugs: ProtocolBugs{
1011 SendSpuriousAlert: alertRecordOverflow,
1012 },
1013 },
1014 shouldFail: true,
1015 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1016 },
1017 {
1018 protocol: dtls,
1019 testType: serverTest,
1020 name: "Alert-DTLS",
1021 config: Config{
1022 Bugs: ProtocolBugs{
1023 SendSpuriousAlert: alertRecordOverflow,
1024 },
1025 },
1026 shouldFail: true,
1027 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1028 },
1029 {
1030 testType: serverTest,
1031 name: "FragmentAlert",
1032 config: Config{
1033 Bugs: ProtocolBugs{
1034 FragmentAlert: true,
1035 SendSpuriousAlert: alertRecordOverflow,
1036 },
1037 },
1038 shouldFail: true,
1039 expectedError: ":BAD_ALERT:",
1040 },
1041 {
1042 protocol: dtls,
1043 testType: serverTest,
1044 name: "FragmentAlert-DTLS",
1045 config: Config{
1046 Bugs: ProtocolBugs{
1047 FragmentAlert: true,
1048 SendSpuriousAlert: alertRecordOverflow,
1049 },
1050 },
1051 shouldFail: true,
1052 expectedError: ":BAD_ALERT:",
1053 },
1054 {
1055 testType: serverTest,
1056 name: "EarlyChangeCipherSpec-server-1",
1057 config: Config{
1058 Bugs: ProtocolBugs{
1059 EarlyChangeCipherSpec: 1,
1060 },
1061 },
1062 shouldFail: true,
1063 expectedError: ":CCS_RECEIVED_EARLY:",
1064 },
1065 {
1066 testType: serverTest,
1067 name: "EarlyChangeCipherSpec-server-2",
1068 config: Config{
1069 Bugs: ProtocolBugs{
1070 EarlyChangeCipherSpec: 2,
1071 },
1072 },
1073 shouldFail: true,
1074 expectedError: ":CCS_RECEIVED_EARLY:",
1075 },
1076 {
1077 name: "SkipNewSessionTicket",
1078 config: Config{
1079 Bugs: ProtocolBugs{
1080 SkipNewSessionTicket: true,
1081 },
1082 },
1083 shouldFail: true,
1084 expectedError: ":CCS_RECEIVED_EARLY:",
1085 },
1086 {
1087 testType: serverTest,
1088 name: "FallbackSCSV",
1089 config: Config{
1090 MaxVersion: VersionTLS11,
1091 Bugs: ProtocolBugs{
1092 SendFallbackSCSV: true,
1093 },
1094 },
1095 shouldFail: true,
1096 expectedError: ":INAPPROPRIATE_FALLBACK:",
1097 },
1098 {
1099 testType: serverTest,
1100 name: "FallbackSCSV-VersionMatch",
1101 config: Config{
1102 Bugs: ProtocolBugs{
1103 SendFallbackSCSV: true,
1104 },
1105 },
1106 },
1107 {
1108 testType: serverTest,
1109 name: "FragmentedClientVersion",
1110 config: Config{
1111 Bugs: ProtocolBugs{
1112 MaxHandshakeRecordLength: 1,
1113 FragmentClientVersion: true,
1114 },
1115 },
1116 expectedVersion: VersionTLS12,
1117 },
1118 {
1119 testType: serverTest,
1120 name: "MinorVersionTolerance",
1121 config: Config{
1122 Bugs: ProtocolBugs{
1123 SendClientVersion: 0x03ff,
1124 },
1125 },
1126 expectedVersion: VersionTLS12,
1127 },
1128 {
1129 testType: serverTest,
1130 name: "MajorVersionTolerance",
1131 config: Config{
1132 Bugs: ProtocolBugs{
1133 SendClientVersion: 0x0400,
1134 },
1135 },
1136 expectedVersion: VersionTLS12,
1137 },
1138 {
1139 testType: serverTest,
1140 name: "VersionTooLow",
1141 config: Config{
1142 Bugs: ProtocolBugs{
1143 SendClientVersion: 0x0200,
1144 },
1145 },
1146 shouldFail: true,
1147 expectedError: ":UNSUPPORTED_PROTOCOL:",
1148 },
1149 {
1150 testType: serverTest,
1151 name: "HttpGET",
1152 sendPrefix: "GET / HTTP/1.0\n",
1153 shouldFail: true,
1154 expectedError: ":HTTP_REQUEST:",
1155 },
1156 {
1157 testType: serverTest,
1158 name: "HttpPOST",
1159 sendPrefix: "POST / HTTP/1.0\n",
1160 shouldFail: true,
1161 expectedError: ":HTTP_REQUEST:",
1162 },
1163 {
1164 testType: serverTest,
1165 name: "HttpHEAD",
1166 sendPrefix: "HEAD / HTTP/1.0\n",
1167 shouldFail: true,
1168 expectedError: ":HTTP_REQUEST:",
1169 },
1170 {
1171 testType: serverTest,
1172 name: "HttpPUT",
1173 sendPrefix: "PUT / HTTP/1.0\n",
1174 shouldFail: true,
1175 expectedError: ":HTTP_REQUEST:",
1176 },
1177 {
1178 testType: serverTest,
1179 name: "HttpCONNECT",
1180 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1181 shouldFail: true,
1182 expectedError: ":HTTPS_PROXY_REQUEST:",
1183 },
1184 {
1185 testType: serverTest,
1186 name: "Garbage",
1187 sendPrefix: "blah",
1188 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001189 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001190 },
1191 {
1192 name: "SkipCipherVersionCheck",
1193 config: Config{
1194 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1195 MaxVersion: VersionTLS11,
1196 Bugs: ProtocolBugs{
1197 SkipCipherVersionCheck: true,
1198 },
1199 },
1200 shouldFail: true,
1201 expectedError: ":WRONG_CIPHER_RETURNED:",
1202 },
1203 {
1204 name: "RSAEphemeralKey",
1205 config: Config{
1206 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1207 Bugs: ProtocolBugs{
1208 RSAEphemeralKey: true,
1209 },
1210 },
1211 shouldFail: true,
1212 expectedError: ":UNEXPECTED_MESSAGE:",
1213 },
1214 {
1215 name: "DisableEverything",
1216 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1217 shouldFail: true,
1218 expectedError: ":WRONG_SSL_VERSION:",
1219 },
1220 {
1221 protocol: dtls,
1222 name: "DisableEverything-DTLS",
1223 flags: []string{"-no-tls12", "-no-tls1"},
1224 shouldFail: true,
1225 expectedError: ":WRONG_SSL_VERSION:",
1226 },
1227 {
1228 name: "NoSharedCipher",
1229 config: Config{
1230 CipherSuites: []uint16{},
1231 },
1232 shouldFail: true,
1233 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1234 },
1235 {
1236 protocol: dtls,
1237 testType: serverTest,
1238 name: "MTU",
1239 config: Config{
1240 Bugs: ProtocolBugs{
1241 MaxPacketLength: 256,
1242 },
1243 },
1244 flags: []string{"-mtu", "256"},
1245 },
1246 {
1247 protocol: dtls,
1248 testType: serverTest,
1249 name: "MTUExceeded",
1250 config: Config{
1251 Bugs: ProtocolBugs{
1252 MaxPacketLength: 255,
1253 },
1254 },
1255 flags: []string{"-mtu", "256"},
1256 shouldFail: true,
1257 expectedLocalError: "dtls: exceeded maximum packet length",
1258 },
1259 {
1260 name: "CertMismatchRSA",
1261 config: Config{
1262 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1263 Certificates: []Certificate{getECDSACertificate()},
1264 Bugs: ProtocolBugs{
1265 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1266 },
1267 },
1268 shouldFail: true,
1269 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1270 },
1271 {
1272 name: "CertMismatchECDSA",
1273 config: Config{
1274 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1275 Certificates: []Certificate{getRSACertificate()},
1276 Bugs: ProtocolBugs{
1277 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1282 },
1283 {
1284 name: "EmptyCertificateList",
1285 config: Config{
1286 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1287 Bugs: ProtocolBugs{
1288 EmptyCertificateList: true,
1289 },
1290 },
1291 shouldFail: true,
1292 expectedError: ":DECODE_ERROR:",
1293 },
1294 {
1295 name: "TLSFatalBadPackets",
1296 damageFirstWrite: true,
1297 shouldFail: true,
1298 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1299 },
1300 {
1301 protocol: dtls,
1302 name: "DTLSIgnoreBadPackets",
1303 damageFirstWrite: true,
1304 },
1305 {
1306 protocol: dtls,
1307 name: "DTLSIgnoreBadPackets-Async",
1308 damageFirstWrite: true,
1309 flags: []string{"-async"},
1310 },
1311 {
1312 name: "AppDataAfterChangeCipherSpec",
1313 config: Config{
1314 Bugs: ProtocolBugs{
1315 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1316 },
1317 },
1318 shouldFail: true,
1319 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1320 },
1321 {
1322 protocol: dtls,
1323 name: "AppDataAfterChangeCipherSpec-DTLS",
1324 config: Config{
1325 Bugs: ProtocolBugs{
1326 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1327 },
1328 },
1329 // BoringSSL's DTLS implementation will drop the out-of-order
1330 // application data.
1331 },
1332 {
1333 name: "AlertAfterChangeCipherSpec",
1334 config: Config{
1335 Bugs: ProtocolBugs{
1336 AlertAfterChangeCipherSpec: alertRecordOverflow,
1337 },
1338 },
1339 shouldFail: true,
1340 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1341 },
1342 {
1343 protocol: dtls,
1344 name: "AlertAfterChangeCipherSpec-DTLS",
1345 config: Config{
1346 Bugs: ProtocolBugs{
1347 AlertAfterChangeCipherSpec: alertRecordOverflow,
1348 },
1349 },
1350 shouldFail: true,
1351 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1352 },
1353 {
1354 protocol: dtls,
1355 name: "ReorderHandshakeFragments-Small-DTLS",
1356 config: Config{
1357 Bugs: ProtocolBugs{
1358 ReorderHandshakeFragments: true,
1359 // Small enough that every handshake message is
1360 // fragmented.
1361 MaxHandshakeRecordLength: 2,
1362 },
1363 },
1364 },
1365 {
1366 protocol: dtls,
1367 name: "ReorderHandshakeFragments-Large-DTLS",
1368 config: Config{
1369 Bugs: ProtocolBugs{
1370 ReorderHandshakeFragments: true,
1371 // Large enough that no handshake message is
1372 // fragmented.
1373 MaxHandshakeRecordLength: 2048,
1374 },
1375 },
1376 },
1377 {
1378 protocol: dtls,
1379 name: "MixCompleteMessageWithFragments-DTLS",
1380 config: Config{
1381 Bugs: ProtocolBugs{
1382 ReorderHandshakeFragments: true,
1383 MixCompleteMessageWithFragments: true,
1384 MaxHandshakeRecordLength: 2,
1385 },
1386 },
1387 },
1388 {
1389 name: "SendInvalidRecordType",
1390 config: Config{
1391 Bugs: ProtocolBugs{
1392 SendInvalidRecordType: true,
1393 },
1394 },
1395 shouldFail: true,
1396 expectedError: ":UNEXPECTED_RECORD:",
1397 },
1398 {
1399 protocol: dtls,
1400 name: "SendInvalidRecordType-DTLS",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 SendInvalidRecordType: true,
1404 },
1405 },
1406 shouldFail: true,
1407 expectedError: ":UNEXPECTED_RECORD:",
1408 },
1409 {
1410 name: "FalseStart-SkipServerSecondLeg",
1411 config: Config{
1412 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1413 NextProtos: []string{"foo"},
1414 Bugs: ProtocolBugs{
1415 SkipNewSessionTicket: true,
1416 SkipChangeCipherSpec: true,
1417 SkipFinished: true,
1418 ExpectFalseStart: true,
1419 },
1420 },
1421 flags: []string{
1422 "-false-start",
1423 "-handshake-never-done",
1424 "-advertise-alpn", "\x03foo",
1425 },
1426 shimWritesFirst: true,
1427 shouldFail: true,
1428 expectedError: ":UNEXPECTED_RECORD:",
1429 },
1430 {
1431 name: "FalseStart-SkipServerSecondLeg-Implicit",
1432 config: Config{
1433 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1434 NextProtos: []string{"foo"},
1435 Bugs: ProtocolBugs{
1436 SkipNewSessionTicket: true,
1437 SkipChangeCipherSpec: true,
1438 SkipFinished: true,
1439 },
1440 },
1441 flags: []string{
1442 "-implicit-handshake",
1443 "-false-start",
1444 "-handshake-never-done",
1445 "-advertise-alpn", "\x03foo",
1446 },
1447 shouldFail: true,
1448 expectedError: ":UNEXPECTED_RECORD:",
1449 },
1450 {
1451 testType: serverTest,
1452 name: "FailEarlyCallback",
1453 flags: []string{"-fail-early-callback"},
1454 shouldFail: true,
1455 expectedError: ":CONNECTION_REJECTED:",
1456 expectedLocalError: "remote error: access denied",
1457 },
1458 {
1459 name: "WrongMessageType",
1460 config: Config{
1461 Bugs: ProtocolBugs{
1462 WrongCertificateMessageType: true,
1463 },
1464 },
1465 shouldFail: true,
1466 expectedError: ":UNEXPECTED_MESSAGE:",
1467 expectedLocalError: "remote error: unexpected message",
1468 },
1469 {
1470 protocol: dtls,
1471 name: "WrongMessageType-DTLS",
1472 config: Config{
1473 Bugs: ProtocolBugs{
1474 WrongCertificateMessageType: true,
1475 },
1476 },
1477 shouldFail: true,
1478 expectedError: ":UNEXPECTED_MESSAGE:",
1479 expectedLocalError: "remote error: unexpected message",
1480 },
1481 {
1482 protocol: dtls,
1483 name: "FragmentMessageTypeMismatch-DTLS",
1484 config: Config{
1485 Bugs: ProtocolBugs{
1486 MaxHandshakeRecordLength: 2,
1487 FragmentMessageTypeMismatch: true,
1488 },
1489 },
1490 shouldFail: true,
1491 expectedError: ":FRAGMENT_MISMATCH:",
1492 },
1493 {
1494 protocol: dtls,
1495 name: "FragmentMessageLengthMismatch-DTLS",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 MaxHandshakeRecordLength: 2,
1499 FragmentMessageLengthMismatch: true,
1500 },
1501 },
1502 shouldFail: true,
1503 expectedError: ":FRAGMENT_MISMATCH:",
1504 },
1505 {
1506 protocol: dtls,
1507 name: "SplitFragments-Header-DTLS",
1508 config: Config{
1509 Bugs: ProtocolBugs{
1510 SplitFragments: 2,
1511 },
1512 },
1513 shouldFail: true,
1514 expectedError: ":UNEXPECTED_MESSAGE:",
1515 },
1516 {
1517 protocol: dtls,
1518 name: "SplitFragments-Boundary-DTLS",
1519 config: Config{
1520 Bugs: ProtocolBugs{
1521 SplitFragments: dtlsRecordHeaderLen,
1522 },
1523 },
1524 shouldFail: true,
1525 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1526 },
1527 {
1528 protocol: dtls,
1529 name: "SplitFragments-Body-DTLS",
1530 config: Config{
1531 Bugs: ProtocolBugs{
1532 SplitFragments: dtlsRecordHeaderLen + 1,
1533 },
1534 },
1535 shouldFail: true,
1536 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1537 },
1538 {
1539 protocol: dtls,
1540 name: "SendEmptyFragments-DTLS",
1541 config: Config{
1542 Bugs: ProtocolBugs{
1543 SendEmptyFragments: true,
1544 },
1545 },
1546 },
1547 {
1548 name: "UnsupportedCipherSuite",
1549 config: Config{
1550 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1551 Bugs: ProtocolBugs{
1552 IgnorePeerCipherPreferences: true,
1553 },
1554 },
1555 flags: []string{"-cipher", "DEFAULT:!RC4"},
1556 shouldFail: true,
1557 expectedError: ":WRONG_CIPHER_RETURNED:",
1558 },
1559 {
1560 name: "UnsupportedCurve",
1561 config: Config{
1562 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1563 // BoringSSL implements P-224 but doesn't enable it by
1564 // default.
1565 CurvePreferences: []CurveID{CurveP224},
1566 Bugs: ProtocolBugs{
1567 IgnorePeerCurvePreferences: true,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":WRONG_CURVE:",
1572 },
1573 {
1574 name: "BadFinished",
1575 config: Config{
1576 Bugs: ProtocolBugs{
1577 BadFinished: true,
1578 },
1579 },
1580 shouldFail: true,
1581 expectedError: ":DIGEST_CHECK_FAILED:",
1582 },
1583 {
1584 name: "FalseStart-BadFinished",
1585 config: Config{
1586 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1587 NextProtos: []string{"foo"},
1588 Bugs: ProtocolBugs{
1589 BadFinished: true,
1590 ExpectFalseStart: true,
1591 },
1592 },
1593 flags: []string{
1594 "-false-start",
1595 "-handshake-never-done",
1596 "-advertise-alpn", "\x03foo",
1597 },
1598 shimWritesFirst: true,
1599 shouldFail: true,
1600 expectedError: ":DIGEST_CHECK_FAILED:",
1601 },
1602 {
1603 name: "NoFalseStart-NoALPN",
1604 config: Config{
1605 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1606 Bugs: ProtocolBugs{
1607 ExpectFalseStart: true,
1608 AlertBeforeFalseStartTest: alertAccessDenied,
1609 },
1610 },
1611 flags: []string{
1612 "-false-start",
1613 },
1614 shimWritesFirst: true,
1615 shouldFail: true,
1616 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1617 expectedLocalError: "tls: peer did not false start: EOF",
1618 },
1619 {
1620 name: "NoFalseStart-NoAEAD",
1621 config: Config{
1622 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1623 NextProtos: []string{"foo"},
1624 Bugs: ProtocolBugs{
1625 ExpectFalseStart: true,
1626 AlertBeforeFalseStartTest: alertAccessDenied,
1627 },
1628 },
1629 flags: []string{
1630 "-false-start",
1631 "-advertise-alpn", "\x03foo",
1632 },
1633 shimWritesFirst: true,
1634 shouldFail: true,
1635 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1636 expectedLocalError: "tls: peer did not false start: EOF",
1637 },
1638 {
1639 name: "NoFalseStart-RSA",
1640 config: Config{
1641 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1642 NextProtos: []string{"foo"},
1643 Bugs: ProtocolBugs{
1644 ExpectFalseStart: true,
1645 AlertBeforeFalseStartTest: alertAccessDenied,
1646 },
1647 },
1648 flags: []string{
1649 "-false-start",
1650 "-advertise-alpn", "\x03foo",
1651 },
1652 shimWritesFirst: true,
1653 shouldFail: true,
1654 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1655 expectedLocalError: "tls: peer did not false start: EOF",
1656 },
1657 {
1658 name: "NoFalseStart-DHE_RSA",
1659 config: Config{
1660 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1661 NextProtos: []string{"foo"},
1662 Bugs: ProtocolBugs{
1663 ExpectFalseStart: true,
1664 AlertBeforeFalseStartTest: alertAccessDenied,
1665 },
1666 },
1667 flags: []string{
1668 "-false-start",
1669 "-advertise-alpn", "\x03foo",
1670 },
1671 shimWritesFirst: true,
1672 shouldFail: true,
1673 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1674 expectedLocalError: "tls: peer did not false start: EOF",
1675 },
1676 {
1677 testType: serverTest,
1678 name: "NoSupportedCurves",
1679 config: Config{
1680 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1681 Bugs: ProtocolBugs{
1682 NoSupportedCurves: true,
1683 },
1684 },
1685 },
1686 {
1687 testType: serverTest,
1688 name: "NoCommonCurves",
1689 config: Config{
1690 CipherSuites: []uint16{
1691 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1692 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1693 },
1694 CurvePreferences: []CurveID{CurveP224},
1695 },
1696 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1697 },
1698 {
1699 protocol: dtls,
1700 name: "SendSplitAlert-Sync",
1701 config: Config{
1702 Bugs: ProtocolBugs{
1703 SendSplitAlert: true,
1704 },
1705 },
1706 },
1707 {
1708 protocol: dtls,
1709 name: "SendSplitAlert-Async",
1710 config: Config{
1711 Bugs: ProtocolBugs{
1712 SendSplitAlert: true,
1713 },
1714 },
1715 flags: []string{"-async"},
1716 },
1717 {
1718 protocol: dtls,
1719 name: "PackDTLSHandshake",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 MaxHandshakeRecordLength: 2,
1723 PackHandshakeFragments: 20,
1724 PackHandshakeRecords: 200,
1725 },
1726 },
1727 },
1728 {
1729 testType: serverTest,
1730 protocol: dtls,
1731 name: "NoRC4-DTLS",
1732 config: Config{
1733 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1734 Bugs: ProtocolBugs{
1735 EnableAllCiphersInDTLS: true,
1736 },
1737 },
1738 shouldFail: true,
1739 expectedError: ":NO_SHARED_CIPHER:",
1740 },
1741 {
1742 name: "SendEmptyRecords-Pass",
1743 sendEmptyRecords: 32,
1744 },
1745 {
1746 name: "SendEmptyRecords",
1747 sendEmptyRecords: 33,
1748 shouldFail: true,
1749 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1750 },
1751 {
1752 name: "SendEmptyRecords-Async",
1753 sendEmptyRecords: 33,
1754 flags: []string{"-async"},
1755 shouldFail: true,
1756 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1757 },
1758 {
1759 name: "SendWarningAlerts-Pass",
1760 sendWarningAlerts: 4,
1761 },
1762 {
1763 protocol: dtls,
1764 name: "SendWarningAlerts-DTLS-Pass",
1765 sendWarningAlerts: 4,
1766 },
1767 {
1768 name: "SendWarningAlerts",
1769 sendWarningAlerts: 5,
1770 shouldFail: true,
1771 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1772 },
1773 {
1774 name: "SendWarningAlerts-Async",
1775 sendWarningAlerts: 5,
1776 flags: []string{"-async"},
1777 shouldFail: true,
1778 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1779 },
David Benjaminba4594a2015-06-18 18:36:15 -04001780 {
1781 name: "EmptySessionID",
1782 config: Config{
1783 SessionTicketsDisabled: true,
1784 },
1785 noSessionCache: true,
1786 flags: []string{"-expect-no-session"},
1787 },
Adam Langley7c803a62015-06-15 15:35:05 -07001788 }
1789
1790 testCases = append(testCases, basicTests...)
1791}
1792
Adam Langley95c29f32014-06-20 12:00:00 -07001793func addCipherSuiteTests() {
1794 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001795 const psk = "12345"
1796 const pskIdentity = "luggage combo"
1797
Adam Langley95c29f32014-06-20 12:00:00 -07001798 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001799 var certFile string
1800 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001801 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001802 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001803 certFile = ecdsaCertificateFile
1804 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001805 } else {
1806 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001807 certFile = rsaCertificateFile
1808 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001809 }
1810
David Benjamin48cae082014-10-27 01:06:24 -04001811 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001812 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001813 flags = append(flags,
1814 "-psk", psk,
1815 "-psk-identity", pskIdentity)
1816 }
1817
Adam Langley95c29f32014-06-20 12:00:00 -07001818 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04001819 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07001820 continue
1821 }
1822
David Benjamin025b3d32014-07-01 19:53:04 -04001823 testCases = append(testCases, testCase{
1824 testType: clientTest,
1825 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07001826 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001827 MinVersion: ver.version,
1828 MaxVersion: ver.version,
1829 CipherSuites: []uint16{suite.id},
1830 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04001831 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04001832 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07001833 },
David Benjamin48cae082014-10-27 01:06:24 -04001834 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001835 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07001836 })
David Benjamin025b3d32014-07-01 19:53:04 -04001837
David Benjamin76d8abe2014-08-14 16:25:34 -04001838 testCases = append(testCases, testCase{
1839 testType: serverTest,
1840 name: ver.name + "-" + suite.name + "-server",
1841 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001842 MinVersion: ver.version,
1843 MaxVersion: ver.version,
1844 CipherSuites: []uint16{suite.id},
1845 Certificates: []Certificate{cert},
1846 PreSharedKey: []byte(psk),
1847 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04001848 },
1849 certFile: certFile,
1850 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001851 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001852 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04001853 })
David Benjamin6fd297b2014-08-11 18:43:38 -04001854
David Benjamin8b8c0062014-11-23 02:47:52 -05001855 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04001856 testCases = append(testCases, testCase{
1857 testType: clientTest,
1858 protocol: dtls,
1859 name: "D" + ver.name + "-" + suite.name + "-client",
1860 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001861 MinVersion: ver.version,
1862 MaxVersion: ver.version,
1863 CipherSuites: []uint16{suite.id},
1864 Certificates: []Certificate{cert},
1865 PreSharedKey: []byte(psk),
1866 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001867 },
David Benjamin48cae082014-10-27 01:06:24 -04001868 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001869 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001870 })
1871 testCases = append(testCases, testCase{
1872 testType: serverTest,
1873 protocol: dtls,
1874 name: "D" + ver.name + "-" + suite.name + "-server",
1875 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001876 MinVersion: ver.version,
1877 MaxVersion: ver.version,
1878 CipherSuites: []uint16{suite.id},
1879 Certificates: []Certificate{cert},
1880 PreSharedKey: []byte(psk),
1881 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04001882 },
1883 certFile: certFile,
1884 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001885 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001886 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04001887 })
1888 }
Adam Langley95c29f32014-06-20 12:00:00 -07001889 }
1890 }
Adam Langleya7997f12015-05-14 17:38:50 -07001891
1892 testCases = append(testCases, testCase{
1893 name: "WeakDH",
1894 config: Config{
1895 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1896 Bugs: ProtocolBugs{
1897 // This is a 1023-bit prime number, generated
1898 // with:
1899 // openssl gendh 1023 | openssl asn1parse -i
1900 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
1901 },
1902 },
1903 shouldFail: true,
1904 expectedError: "BAD_DH_P_LENGTH",
1905 })
Adam Langley95c29f32014-06-20 12:00:00 -07001906}
1907
1908func addBadECDSASignatureTests() {
1909 for badR := BadValue(1); badR < NumBadValues; badR++ {
1910 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04001911 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07001912 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
1913 config: Config{
1914 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1915 Certificates: []Certificate{getECDSACertificate()},
1916 Bugs: ProtocolBugs{
1917 BadECDSAR: badR,
1918 BadECDSAS: badS,
1919 },
1920 },
1921 shouldFail: true,
1922 expectedError: "SIGNATURE",
1923 })
1924 }
1925 }
1926}
1927
Adam Langley80842bd2014-06-20 12:00:00 -07001928func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04001929 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001930 name: "MaxCBCPadding",
1931 config: Config{
1932 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1933 Bugs: ProtocolBugs{
1934 MaxPadding: true,
1935 },
1936 },
1937 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1938 })
David Benjamin025b3d32014-07-01 19:53:04 -04001939 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001940 name: "BadCBCPadding",
1941 config: Config{
1942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1943 Bugs: ProtocolBugs{
1944 PaddingFirstByteBad: true,
1945 },
1946 },
1947 shouldFail: true,
1948 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1949 })
1950 // OpenSSL previously had an issue where the first byte of padding in
1951 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04001952 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07001953 name: "BadCBCPadding255",
1954 config: Config{
1955 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1956 Bugs: ProtocolBugs{
1957 MaxPadding: true,
1958 PaddingFirstByteBadIf255: true,
1959 },
1960 },
1961 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
1962 shouldFail: true,
1963 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
1964 })
1965}
1966
Kenny Root7fdeaf12014-08-05 15:23:37 -07001967func addCBCSplittingTests() {
1968 testCases = append(testCases, testCase{
1969 name: "CBCRecordSplitting",
1970 config: Config{
1971 MaxVersion: VersionTLS10,
1972 MinVersion: VersionTLS10,
1973 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1974 },
1975 messageLen: -1, // read until EOF
1976 flags: []string{
1977 "-async",
1978 "-write-different-record-sizes",
1979 "-cbc-record-splitting",
1980 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04001981 })
1982 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07001983 name: "CBCRecordSplittingPartialWrite",
1984 config: Config{
1985 MaxVersion: VersionTLS10,
1986 MinVersion: VersionTLS10,
1987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1988 },
1989 messageLen: -1, // read until EOF
1990 flags: []string{
1991 "-async",
1992 "-write-different-record-sizes",
1993 "-cbc-record-splitting",
1994 "-partial-write",
1995 },
1996 })
1997}
1998
David Benjamin636293b2014-07-08 17:59:18 -04001999func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002000 // Add a dummy cert pool to stress certificate authority parsing.
2001 // TODO(davidben): Add tests that those values parse out correctly.
2002 certPool := x509.NewCertPool()
2003 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2004 if err != nil {
2005 panic(err)
2006 }
2007 certPool.AddCert(cert)
2008
David Benjamin636293b2014-07-08 17:59:18 -04002009 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002010 testCases = append(testCases, testCase{
2011 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002012 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002013 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002014 MinVersion: ver.version,
2015 MaxVersion: ver.version,
2016 ClientAuth: RequireAnyClientCert,
2017 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002018 },
2019 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002020 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2021 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002022 },
2023 })
2024 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002025 testType: serverTest,
2026 name: ver.name + "-Server-ClientAuth-RSA",
2027 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002028 MinVersion: ver.version,
2029 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002030 Certificates: []Certificate{rsaCertificate},
2031 },
2032 flags: []string{"-require-any-client-certificate"},
2033 })
David Benjamine098ec22014-08-27 23:13:20 -04002034 if ver.version != VersionSSL30 {
2035 testCases = append(testCases, testCase{
2036 testType: serverTest,
2037 name: ver.name + "-Server-ClientAuth-ECDSA",
2038 config: Config{
2039 MinVersion: ver.version,
2040 MaxVersion: ver.version,
2041 Certificates: []Certificate{ecdsaCertificate},
2042 },
2043 flags: []string{"-require-any-client-certificate"},
2044 })
2045 testCases = append(testCases, testCase{
2046 testType: clientTest,
2047 name: ver.name + "-Client-ClientAuth-ECDSA",
2048 config: Config{
2049 MinVersion: ver.version,
2050 MaxVersion: ver.version,
2051 ClientAuth: RequireAnyClientCert,
2052 ClientCAs: certPool,
2053 },
2054 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002055 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2056 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002057 },
2058 })
2059 }
David Benjamin636293b2014-07-08 17:59:18 -04002060 }
2061}
2062
Adam Langley75712922014-10-10 16:23:43 -07002063func addExtendedMasterSecretTests() {
2064 const expectEMSFlag = "-expect-extended-master-secret"
2065
2066 for _, with := range []bool{false, true} {
2067 prefix := "No"
2068 var flags []string
2069 if with {
2070 prefix = ""
2071 flags = []string{expectEMSFlag}
2072 }
2073
2074 for _, isClient := range []bool{false, true} {
2075 suffix := "-Server"
2076 testType := serverTest
2077 if isClient {
2078 suffix = "-Client"
2079 testType = clientTest
2080 }
2081
2082 for _, ver := range tlsVersions {
2083 test := testCase{
2084 testType: testType,
2085 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2086 config: Config{
2087 MinVersion: ver.version,
2088 MaxVersion: ver.version,
2089 Bugs: ProtocolBugs{
2090 NoExtendedMasterSecret: !with,
2091 RequireExtendedMasterSecret: with,
2092 },
2093 },
David Benjamin48cae082014-10-27 01:06:24 -04002094 flags: flags,
2095 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002096 }
2097 if test.shouldFail {
2098 test.expectedLocalError = "extended master secret required but not supported by peer"
2099 }
2100 testCases = append(testCases, test)
2101 }
2102 }
2103 }
2104
Adam Langleyba5934b2015-06-02 10:50:35 -07002105 for _, isClient := range []bool{false, true} {
2106 for _, supportedInFirstConnection := range []bool{false, true} {
2107 for _, supportedInResumeConnection := range []bool{false, true} {
2108 boolToWord := func(b bool) string {
2109 if b {
2110 return "Yes"
2111 }
2112 return "No"
2113 }
2114 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2115 if isClient {
2116 suffix += "Client"
2117 } else {
2118 suffix += "Server"
2119 }
2120
2121 supportedConfig := Config{
2122 Bugs: ProtocolBugs{
2123 RequireExtendedMasterSecret: true,
2124 },
2125 }
2126
2127 noSupportConfig := Config{
2128 Bugs: ProtocolBugs{
2129 NoExtendedMasterSecret: true,
2130 },
2131 }
2132
2133 test := testCase{
2134 name: "ExtendedMasterSecret-" + suffix,
2135 resumeSession: true,
2136 }
2137
2138 if !isClient {
2139 test.testType = serverTest
2140 }
2141
2142 if supportedInFirstConnection {
2143 test.config = supportedConfig
2144 } else {
2145 test.config = noSupportConfig
2146 }
2147
2148 if supportedInResumeConnection {
2149 test.resumeConfig = &supportedConfig
2150 } else {
2151 test.resumeConfig = &noSupportConfig
2152 }
2153
2154 switch suffix {
2155 case "YesToYes-Client", "YesToYes-Server":
2156 // When a session is resumed, it should
2157 // still be aware that its master
2158 // secret was generated via EMS and
2159 // thus it's safe to use tls-unique.
2160 test.flags = []string{expectEMSFlag}
2161 case "NoToYes-Server":
2162 // If an original connection did not
2163 // contain EMS, but a resumption
2164 // handshake does, then a server should
2165 // not resume the session.
2166 test.expectResumeRejected = true
2167 case "YesToNo-Server":
2168 // Resuming an EMS session without the
2169 // EMS extension should cause the
2170 // server to abort the connection.
2171 test.shouldFail = true
2172 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2173 case "NoToYes-Client":
2174 // A client should abort a connection
2175 // where the server resumed a non-EMS
2176 // session but echoed the EMS
2177 // extension.
2178 test.shouldFail = true
2179 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2180 case "YesToNo-Client":
2181 // A client should abort a connection
2182 // where the server didn't echo EMS
2183 // when the session used it.
2184 test.shouldFail = true
2185 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2186 }
2187
2188 testCases = append(testCases, test)
2189 }
2190 }
2191 }
Adam Langley75712922014-10-10 16:23:43 -07002192}
2193
David Benjamin43ec06f2014-08-05 02:28:57 -04002194// Adds tests that try to cover the range of the handshake state machine, under
2195// various conditions. Some of these are redundant with other tests, but they
2196// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002197func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002198 var tests []testCase
2199
2200 // Basic handshake, with resumption. Client and server,
2201 // session ID and session ticket.
2202 tests = append(tests, testCase{
2203 name: "Basic-Client",
2204 resumeSession: true,
2205 })
2206 tests = append(tests, testCase{
2207 name: "Basic-Client-RenewTicket",
2208 config: Config{
2209 Bugs: ProtocolBugs{
2210 RenewTicketOnResume: true,
2211 },
2212 },
David Benjaminba4594a2015-06-18 18:36:15 -04002213 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002214 resumeSession: true,
2215 })
2216 tests = append(tests, testCase{
2217 name: "Basic-Client-NoTicket",
2218 config: Config{
2219 SessionTicketsDisabled: true,
2220 },
2221 resumeSession: true,
2222 })
2223 tests = append(tests, testCase{
2224 name: "Basic-Client-Implicit",
2225 flags: []string{"-implicit-handshake"},
2226 resumeSession: true,
2227 })
2228 tests = append(tests, testCase{
2229 testType: serverTest,
2230 name: "Basic-Server",
2231 resumeSession: true,
2232 })
2233 tests = append(tests, testCase{
2234 testType: serverTest,
2235 name: "Basic-Server-NoTickets",
2236 config: Config{
2237 SessionTicketsDisabled: true,
2238 },
2239 resumeSession: true,
2240 })
2241 tests = append(tests, testCase{
2242 testType: serverTest,
2243 name: "Basic-Server-Implicit",
2244 flags: []string{"-implicit-handshake"},
2245 resumeSession: true,
2246 })
2247 tests = append(tests, testCase{
2248 testType: serverTest,
2249 name: "Basic-Server-EarlyCallback",
2250 flags: []string{"-use-early-callback"},
2251 resumeSession: true,
2252 })
2253
2254 // TLS client auth.
2255 tests = append(tests, testCase{
2256 testType: clientTest,
2257 name: "ClientAuth-Client",
2258 config: Config{
2259 ClientAuth: RequireAnyClientCert,
2260 },
2261 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002262 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2263 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002264 },
2265 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002266 if async {
2267 tests = append(tests, testCase{
2268 testType: clientTest,
2269 name: "ClientAuth-Client-AsyncKey",
2270 config: Config{
2271 ClientAuth: RequireAnyClientCert,
2272 },
2273 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002274 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2275 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002276 "-use-async-private-key",
2277 },
2278 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002279 tests = append(tests, testCase{
2280 testType: serverTest,
2281 name: "Basic-Server-RSAAsyncKey",
2282 flags: []string{
2283 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2284 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2285 "-use-async-private-key",
2286 },
2287 })
2288 tests = append(tests, testCase{
2289 testType: serverTest,
2290 name: "Basic-Server-ECDSAAsyncKey",
2291 flags: []string{
2292 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2293 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2294 "-use-async-private-key",
2295 },
2296 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002297 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002298 tests = append(tests, testCase{
2299 testType: serverTest,
2300 name: "ClientAuth-Server",
2301 config: Config{
2302 Certificates: []Certificate{rsaCertificate},
2303 },
2304 flags: []string{"-require-any-client-certificate"},
2305 })
2306
2307 // No session ticket support; server doesn't send NewSessionTicket.
2308 tests = append(tests, testCase{
2309 name: "SessionTicketsDisabled-Client",
2310 config: Config{
2311 SessionTicketsDisabled: true,
2312 },
2313 })
2314 tests = append(tests, testCase{
2315 testType: serverTest,
2316 name: "SessionTicketsDisabled-Server",
2317 config: Config{
2318 SessionTicketsDisabled: true,
2319 },
2320 })
2321
2322 // Skip ServerKeyExchange in PSK key exchange if there's no
2323 // identity hint.
2324 tests = append(tests, testCase{
2325 name: "EmptyPSKHint-Client",
2326 config: Config{
2327 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2328 PreSharedKey: []byte("secret"),
2329 },
2330 flags: []string{"-psk", "secret"},
2331 })
2332 tests = append(tests, testCase{
2333 testType: serverTest,
2334 name: "EmptyPSKHint-Server",
2335 config: Config{
2336 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2337 PreSharedKey: []byte("secret"),
2338 },
2339 flags: []string{"-psk", "secret"},
2340 })
2341
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002342 tests = append(tests, testCase{
2343 testType: clientTest,
2344 name: "OCSPStapling-Client",
2345 flags: []string{
2346 "-enable-ocsp-stapling",
2347 "-expect-ocsp-response",
2348 base64.StdEncoding.EncodeToString(testOCSPResponse),
2349 },
2350 })
2351
2352 tests = append(tests, testCase{
2353 testType: serverTest,
2354 name: "OCSPStapling-Server",
2355 expectedOCSPResponse: testOCSPResponse,
2356 flags: []string{
2357 "-ocsp-response",
2358 base64.StdEncoding.EncodeToString(testOCSPResponse),
2359 },
2360 })
2361
David Benjamin760b1dd2015-05-15 23:33:48 -04002362 if protocol == tls {
2363 tests = append(tests, testCase{
2364 name: "Renegotiate-Client",
2365 renegotiate: true,
2366 })
2367 // NPN on client and server; results in post-handshake message.
2368 tests = append(tests, testCase{
2369 name: "NPN-Client",
2370 config: Config{
2371 NextProtos: []string{"foo"},
2372 },
2373 flags: []string{"-select-next-proto", "foo"},
2374 expectedNextProto: "foo",
2375 expectedNextProtoType: npn,
2376 })
2377 tests = append(tests, testCase{
2378 testType: serverTest,
2379 name: "NPN-Server",
2380 config: Config{
2381 NextProtos: []string{"bar"},
2382 },
2383 flags: []string{
2384 "-advertise-npn", "\x03foo\x03bar\x03baz",
2385 "-expect-next-proto", "bar",
2386 },
2387 expectedNextProto: "bar",
2388 expectedNextProtoType: npn,
2389 })
2390
2391 // TODO(davidben): Add tests for when False Start doesn't trigger.
2392
2393 // Client does False Start and negotiates NPN.
2394 tests = append(tests, testCase{
2395 name: "FalseStart",
2396 config: Config{
2397 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2398 NextProtos: []string{"foo"},
2399 Bugs: ProtocolBugs{
2400 ExpectFalseStart: true,
2401 },
2402 },
2403 flags: []string{
2404 "-false-start",
2405 "-select-next-proto", "foo",
2406 },
2407 shimWritesFirst: true,
2408 resumeSession: true,
2409 })
2410
2411 // Client does False Start and negotiates ALPN.
2412 tests = append(tests, testCase{
2413 name: "FalseStart-ALPN",
2414 config: Config{
2415 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2416 NextProtos: []string{"foo"},
2417 Bugs: ProtocolBugs{
2418 ExpectFalseStart: true,
2419 },
2420 },
2421 flags: []string{
2422 "-false-start",
2423 "-advertise-alpn", "\x03foo",
2424 },
2425 shimWritesFirst: true,
2426 resumeSession: true,
2427 })
2428
2429 // Client does False Start but doesn't explicitly call
2430 // SSL_connect.
2431 tests = append(tests, testCase{
2432 name: "FalseStart-Implicit",
2433 config: Config{
2434 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2435 NextProtos: []string{"foo"},
2436 },
2437 flags: []string{
2438 "-implicit-handshake",
2439 "-false-start",
2440 "-advertise-alpn", "\x03foo",
2441 },
2442 })
2443
2444 // False Start without session tickets.
2445 tests = append(tests, testCase{
2446 name: "FalseStart-SessionTicketsDisabled",
2447 config: Config{
2448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2449 NextProtos: []string{"foo"},
2450 SessionTicketsDisabled: true,
2451 Bugs: ProtocolBugs{
2452 ExpectFalseStart: true,
2453 },
2454 },
2455 flags: []string{
2456 "-false-start",
2457 "-select-next-proto", "foo",
2458 },
2459 shimWritesFirst: true,
2460 })
2461
2462 // Server parses a V2ClientHello.
2463 tests = append(tests, testCase{
2464 testType: serverTest,
2465 name: "SendV2ClientHello",
2466 config: Config{
2467 // Choose a cipher suite that does not involve
2468 // elliptic curves, so no extensions are
2469 // involved.
2470 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2471 Bugs: ProtocolBugs{
2472 SendV2ClientHello: true,
2473 },
2474 },
2475 })
2476
2477 // Client sends a Channel ID.
2478 tests = append(tests, testCase{
2479 name: "ChannelID-Client",
2480 config: Config{
2481 RequestChannelID: true,
2482 },
Adam Langley7c803a62015-06-15 15:35:05 -07002483 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002484 resumeSession: true,
2485 expectChannelID: true,
2486 })
2487
2488 // Server accepts a Channel ID.
2489 tests = append(tests, testCase{
2490 testType: serverTest,
2491 name: "ChannelID-Server",
2492 config: Config{
2493 ChannelID: channelIDKey,
2494 },
2495 flags: []string{
2496 "-expect-channel-id",
2497 base64.StdEncoding.EncodeToString(channelIDBytes),
2498 },
2499 resumeSession: true,
2500 expectChannelID: true,
2501 })
2502 } else {
2503 tests = append(tests, testCase{
2504 name: "SkipHelloVerifyRequest",
2505 config: Config{
2506 Bugs: ProtocolBugs{
2507 SkipHelloVerifyRequest: true,
2508 },
2509 },
2510 })
2511 }
2512
David Benjamin43ec06f2014-08-05 02:28:57 -04002513 var suffix string
2514 var flags []string
2515 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002516 if protocol == dtls {
2517 suffix = "-DTLS"
2518 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002519 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002520 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002521 flags = append(flags, "-async")
2522 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002523 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002524 }
2525 if splitHandshake {
2526 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002527 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002528 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002529 for _, test := range tests {
2530 test.protocol = protocol
2531 test.name += suffix
2532 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2533 test.flags = append(test.flags, flags...)
2534 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002535 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002536}
2537
Adam Langley524e7172015-02-20 16:04:00 -08002538func addDDoSCallbackTests() {
2539 // DDoS callback.
2540
2541 for _, resume := range []bool{false, true} {
2542 suffix := "Resume"
2543 if resume {
2544 suffix = "No" + suffix
2545 }
2546
2547 testCases = append(testCases, testCase{
2548 testType: serverTest,
2549 name: "Server-DDoS-OK-" + suffix,
2550 flags: []string{"-install-ddos-callback"},
2551 resumeSession: resume,
2552 })
2553
2554 failFlag := "-fail-ddos-callback"
2555 if resume {
2556 failFlag = "-fail-second-ddos-callback"
2557 }
2558 testCases = append(testCases, testCase{
2559 testType: serverTest,
2560 name: "Server-DDoS-Reject-" + suffix,
2561 flags: []string{"-install-ddos-callback", failFlag},
2562 resumeSession: resume,
2563 shouldFail: true,
2564 expectedError: ":CONNECTION_REJECTED:",
2565 })
2566 }
2567}
2568
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002569func addVersionNegotiationTests() {
2570 for i, shimVers := range tlsVersions {
2571 // Assemble flags to disable all newer versions on the shim.
2572 var flags []string
2573 for _, vers := range tlsVersions[i+1:] {
2574 flags = append(flags, vers.flag)
2575 }
2576
2577 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002578 protocols := []protocol{tls}
2579 if runnerVers.hasDTLS && shimVers.hasDTLS {
2580 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002581 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002582 for _, protocol := range protocols {
2583 expectedVersion := shimVers.version
2584 if runnerVers.version < shimVers.version {
2585 expectedVersion = runnerVers.version
2586 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002587
David Benjamin8b8c0062014-11-23 02:47:52 -05002588 suffix := shimVers.name + "-" + runnerVers.name
2589 if protocol == dtls {
2590 suffix += "-DTLS"
2591 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002592
David Benjamin1eb367c2014-12-12 18:17:51 -05002593 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2594
David Benjamin1e29a6b2014-12-10 02:27:24 -05002595 clientVers := shimVers.version
2596 if clientVers > VersionTLS10 {
2597 clientVers = VersionTLS10
2598 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002599 testCases = append(testCases, testCase{
2600 protocol: protocol,
2601 testType: clientTest,
2602 name: "VersionNegotiation-Client-" + suffix,
2603 config: Config{
2604 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002605 Bugs: ProtocolBugs{
2606 ExpectInitialRecordVersion: clientVers,
2607 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002608 },
2609 flags: flags,
2610 expectedVersion: expectedVersion,
2611 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002612 testCases = append(testCases, testCase{
2613 protocol: protocol,
2614 testType: clientTest,
2615 name: "VersionNegotiation-Client2-" + suffix,
2616 config: Config{
2617 MaxVersion: runnerVers.version,
2618 Bugs: ProtocolBugs{
2619 ExpectInitialRecordVersion: clientVers,
2620 },
2621 },
2622 flags: []string{"-max-version", shimVersFlag},
2623 expectedVersion: expectedVersion,
2624 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002625
2626 testCases = append(testCases, testCase{
2627 protocol: protocol,
2628 testType: serverTest,
2629 name: "VersionNegotiation-Server-" + suffix,
2630 config: Config{
2631 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002632 Bugs: ProtocolBugs{
2633 ExpectInitialRecordVersion: expectedVersion,
2634 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002635 },
2636 flags: flags,
2637 expectedVersion: expectedVersion,
2638 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002639 testCases = append(testCases, testCase{
2640 protocol: protocol,
2641 testType: serverTest,
2642 name: "VersionNegotiation-Server2-" + suffix,
2643 config: Config{
2644 MaxVersion: runnerVers.version,
2645 Bugs: ProtocolBugs{
2646 ExpectInitialRecordVersion: expectedVersion,
2647 },
2648 },
2649 flags: []string{"-max-version", shimVersFlag},
2650 expectedVersion: expectedVersion,
2651 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002652 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002653 }
2654 }
2655}
2656
David Benjaminaccb4542014-12-12 23:44:33 -05002657func addMinimumVersionTests() {
2658 for i, shimVers := range tlsVersions {
2659 // Assemble flags to disable all older versions on the shim.
2660 var flags []string
2661 for _, vers := range tlsVersions[:i] {
2662 flags = append(flags, vers.flag)
2663 }
2664
2665 for _, runnerVers := range tlsVersions {
2666 protocols := []protocol{tls}
2667 if runnerVers.hasDTLS && shimVers.hasDTLS {
2668 protocols = append(protocols, dtls)
2669 }
2670 for _, protocol := range protocols {
2671 suffix := shimVers.name + "-" + runnerVers.name
2672 if protocol == dtls {
2673 suffix += "-DTLS"
2674 }
2675 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2676
David Benjaminaccb4542014-12-12 23:44:33 -05002677 var expectedVersion uint16
2678 var shouldFail bool
2679 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05002680 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05002681 if runnerVers.version >= shimVers.version {
2682 expectedVersion = runnerVers.version
2683 } else {
2684 shouldFail = true
2685 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05002686 if runnerVers.version > VersionSSL30 {
2687 expectedLocalError = "remote error: protocol version not supported"
2688 } else {
2689 expectedLocalError = "remote error: handshake failure"
2690 }
David Benjaminaccb4542014-12-12 23:44:33 -05002691 }
2692
2693 testCases = append(testCases, testCase{
2694 protocol: protocol,
2695 testType: clientTest,
2696 name: "MinimumVersion-Client-" + suffix,
2697 config: Config{
2698 MaxVersion: runnerVers.version,
2699 },
David Benjamin87909c02014-12-13 01:55:01 -05002700 flags: flags,
2701 expectedVersion: expectedVersion,
2702 shouldFail: shouldFail,
2703 expectedError: expectedError,
2704 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002705 })
2706 testCases = append(testCases, testCase{
2707 protocol: protocol,
2708 testType: clientTest,
2709 name: "MinimumVersion-Client2-" + suffix,
2710 config: Config{
2711 MaxVersion: runnerVers.version,
2712 },
David Benjamin87909c02014-12-13 01:55:01 -05002713 flags: []string{"-min-version", shimVersFlag},
2714 expectedVersion: expectedVersion,
2715 shouldFail: shouldFail,
2716 expectedError: expectedError,
2717 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002718 })
2719
2720 testCases = append(testCases, testCase{
2721 protocol: protocol,
2722 testType: serverTest,
2723 name: "MinimumVersion-Server-" + suffix,
2724 config: Config{
2725 MaxVersion: runnerVers.version,
2726 },
David Benjamin87909c02014-12-13 01:55:01 -05002727 flags: flags,
2728 expectedVersion: expectedVersion,
2729 shouldFail: shouldFail,
2730 expectedError: expectedError,
2731 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002732 })
2733 testCases = append(testCases, testCase{
2734 protocol: protocol,
2735 testType: serverTest,
2736 name: "MinimumVersion-Server2-" + suffix,
2737 config: Config{
2738 MaxVersion: runnerVers.version,
2739 },
David Benjamin87909c02014-12-13 01:55:01 -05002740 flags: []string{"-min-version", shimVersFlag},
2741 expectedVersion: expectedVersion,
2742 shouldFail: shouldFail,
2743 expectedError: expectedError,
2744 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05002745 })
2746 }
2747 }
2748 }
2749}
2750
David Benjamin5c24a1d2014-08-31 00:59:27 -04002751func addD5BugTests() {
2752 testCases = append(testCases, testCase{
2753 testType: serverTest,
2754 name: "D5Bug-NoQuirk-Reject",
2755 config: Config{
2756 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2757 Bugs: ProtocolBugs{
2758 SSL3RSAKeyExchange: true,
2759 },
2760 },
2761 shouldFail: true,
2762 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
2763 })
2764 testCases = append(testCases, testCase{
2765 testType: serverTest,
2766 name: "D5Bug-Quirk-Normal",
2767 config: Config{
2768 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2769 },
2770 flags: []string{"-tls-d5-bug"},
2771 })
2772 testCases = append(testCases, testCase{
2773 testType: serverTest,
2774 name: "D5Bug-Quirk-Bug",
2775 config: Config{
2776 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2777 Bugs: ProtocolBugs{
2778 SSL3RSAKeyExchange: true,
2779 },
2780 },
2781 flags: []string{"-tls-d5-bug"},
2782 })
2783}
2784
David Benjamine78bfde2014-09-06 12:45:15 -04002785func addExtensionTests() {
2786 testCases = append(testCases, testCase{
2787 testType: clientTest,
2788 name: "DuplicateExtensionClient",
2789 config: Config{
2790 Bugs: ProtocolBugs{
2791 DuplicateExtension: true,
2792 },
2793 },
2794 shouldFail: true,
2795 expectedLocalError: "remote error: error decoding message",
2796 })
2797 testCases = append(testCases, testCase{
2798 testType: serverTest,
2799 name: "DuplicateExtensionServer",
2800 config: Config{
2801 Bugs: ProtocolBugs{
2802 DuplicateExtension: true,
2803 },
2804 },
2805 shouldFail: true,
2806 expectedLocalError: "remote error: error decoding message",
2807 })
2808 testCases = append(testCases, testCase{
2809 testType: clientTest,
2810 name: "ServerNameExtensionClient",
2811 config: Config{
2812 Bugs: ProtocolBugs{
2813 ExpectServerName: "example.com",
2814 },
2815 },
2816 flags: []string{"-host-name", "example.com"},
2817 })
2818 testCases = append(testCases, testCase{
2819 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002820 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04002821 config: Config{
2822 Bugs: ProtocolBugs{
2823 ExpectServerName: "mismatch.com",
2824 },
2825 },
2826 flags: []string{"-host-name", "example.com"},
2827 shouldFail: true,
2828 expectedLocalError: "tls: unexpected server name",
2829 })
2830 testCases = append(testCases, testCase{
2831 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05002832 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04002833 config: Config{
2834 Bugs: ProtocolBugs{
2835 ExpectServerName: "missing.com",
2836 },
2837 },
2838 shouldFail: true,
2839 expectedLocalError: "tls: unexpected server name",
2840 })
2841 testCases = append(testCases, testCase{
2842 testType: serverTest,
2843 name: "ServerNameExtensionServer",
2844 config: Config{
2845 ServerName: "example.com",
2846 },
2847 flags: []string{"-expect-server-name", "example.com"},
2848 resumeSession: true,
2849 })
David Benjaminae2888f2014-09-06 12:58:58 -04002850 testCases = append(testCases, testCase{
2851 testType: clientTest,
2852 name: "ALPNClient",
2853 config: Config{
2854 NextProtos: []string{"foo"},
2855 },
2856 flags: []string{
2857 "-advertise-alpn", "\x03foo\x03bar\x03baz",
2858 "-expect-alpn", "foo",
2859 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002860 expectedNextProto: "foo",
2861 expectedNextProtoType: alpn,
2862 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002863 })
2864 testCases = append(testCases, testCase{
2865 testType: serverTest,
2866 name: "ALPNServer",
2867 config: Config{
2868 NextProtos: []string{"foo", "bar", "baz"},
2869 },
2870 flags: []string{
2871 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2872 "-select-alpn", "foo",
2873 },
David Benjaminfc7b0862014-09-06 13:21:53 -04002874 expectedNextProto: "foo",
2875 expectedNextProtoType: alpn,
2876 resumeSession: true,
2877 })
2878 // Test that the server prefers ALPN over NPN.
2879 testCases = append(testCases, testCase{
2880 testType: serverTest,
2881 name: "ALPNServer-Preferred",
2882 config: Config{
2883 NextProtos: []string{"foo", "bar", "baz"},
2884 },
2885 flags: []string{
2886 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2887 "-select-alpn", "foo",
2888 "-advertise-npn", "\x03foo\x03bar\x03baz",
2889 },
2890 expectedNextProto: "foo",
2891 expectedNextProtoType: alpn,
2892 resumeSession: true,
2893 })
2894 testCases = append(testCases, testCase{
2895 testType: serverTest,
2896 name: "ALPNServer-Preferred-Swapped",
2897 config: Config{
2898 NextProtos: []string{"foo", "bar", "baz"},
2899 Bugs: ProtocolBugs{
2900 SwapNPNAndALPN: true,
2901 },
2902 },
2903 flags: []string{
2904 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
2905 "-select-alpn", "foo",
2906 "-advertise-npn", "\x03foo\x03bar\x03baz",
2907 },
2908 expectedNextProto: "foo",
2909 expectedNextProtoType: alpn,
2910 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04002911 })
Adam Langleyefb0e162015-07-09 11:35:04 -07002912 var emptyString string
2913 testCases = append(testCases, testCase{
2914 testType: clientTest,
2915 name: "ALPNClient-EmptyProtocolName",
2916 config: Config{
2917 NextProtos: []string{""},
2918 Bugs: ProtocolBugs{
2919 // A server returning an empty ALPN protocol
2920 // should be rejected.
2921 ALPNProtocol: &emptyString,
2922 },
2923 },
2924 flags: []string{
2925 "-advertise-alpn", "\x03foo",
2926 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07002927 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07002928 expectedError: ":PARSE_TLSEXT:",
2929 })
2930 testCases = append(testCases, testCase{
2931 testType: serverTest,
2932 name: "ALPNServer-EmptyProtocolName",
2933 config: Config{
2934 // A ClientHello containing an empty ALPN protocol
2935 // should be rejected.
2936 NextProtos: []string{"foo", "", "baz"},
2937 },
2938 flags: []string{
2939 "-select-alpn", "foo",
2940 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07002941 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07002942 expectedError: ":PARSE_TLSEXT:",
2943 })
Adam Langley38311732014-10-16 19:04:35 -07002944 // Resume with a corrupt ticket.
2945 testCases = append(testCases, testCase{
2946 testType: serverTest,
2947 name: "CorruptTicket",
2948 config: Config{
2949 Bugs: ProtocolBugs{
2950 CorruptTicket: true,
2951 },
2952 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07002953 resumeSession: true,
2954 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07002955 })
David Benjamind98452d2015-06-16 14:16:23 -04002956 // Test the ticket callback, with and without renewal.
2957 testCases = append(testCases, testCase{
2958 testType: serverTest,
2959 name: "TicketCallback",
2960 resumeSession: true,
2961 flags: []string{"-use-ticket-callback"},
2962 })
2963 testCases = append(testCases, testCase{
2964 testType: serverTest,
2965 name: "TicketCallback-Renew",
2966 config: Config{
2967 Bugs: ProtocolBugs{
2968 ExpectNewTicket: true,
2969 },
2970 },
2971 flags: []string{"-use-ticket-callback", "-renew-ticket"},
2972 resumeSession: true,
2973 })
Adam Langley38311732014-10-16 19:04:35 -07002974 // Resume with an oversized session id.
2975 testCases = append(testCases, testCase{
2976 testType: serverTest,
2977 name: "OversizedSessionId",
2978 config: Config{
2979 Bugs: ProtocolBugs{
2980 OversizedSessionId: true,
2981 },
2982 },
2983 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07002984 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07002985 expectedError: ":DECODE_ERROR:",
2986 })
David Benjaminca6c8262014-11-15 19:06:08 -05002987 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
2988 // are ignored.
2989 testCases = append(testCases, testCase{
2990 protocol: dtls,
2991 name: "SRTP-Client",
2992 config: Config{
2993 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
2994 },
2995 flags: []string{
2996 "-srtp-profiles",
2997 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
2998 },
2999 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3000 })
3001 testCases = append(testCases, testCase{
3002 protocol: dtls,
3003 testType: serverTest,
3004 name: "SRTP-Server",
3005 config: Config{
3006 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3007 },
3008 flags: []string{
3009 "-srtp-profiles",
3010 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3011 },
3012 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3013 })
3014 // Test that the MKI is ignored.
3015 testCases = append(testCases, testCase{
3016 protocol: dtls,
3017 testType: serverTest,
3018 name: "SRTP-Server-IgnoreMKI",
3019 config: Config{
3020 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3021 Bugs: ProtocolBugs{
3022 SRTPMasterKeyIdentifer: "bogus",
3023 },
3024 },
3025 flags: []string{
3026 "-srtp-profiles",
3027 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3028 },
3029 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3030 })
3031 // Test that SRTP isn't negotiated on the server if there were
3032 // no matching profiles.
3033 testCases = append(testCases, testCase{
3034 protocol: dtls,
3035 testType: serverTest,
3036 name: "SRTP-Server-NoMatch",
3037 config: Config{
3038 SRTPProtectionProfiles: []uint16{100, 101, 102},
3039 },
3040 flags: []string{
3041 "-srtp-profiles",
3042 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3043 },
3044 expectedSRTPProtectionProfile: 0,
3045 })
3046 // Test that the server returning an invalid SRTP profile is
3047 // flagged as an error by the client.
3048 testCases = append(testCases, testCase{
3049 protocol: dtls,
3050 name: "SRTP-Client-NoMatch",
3051 config: Config{
3052 Bugs: ProtocolBugs{
3053 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3054 },
3055 },
3056 flags: []string{
3057 "-srtp-profiles",
3058 "SRTP_AES128_CM_SHA1_80",
3059 },
3060 shouldFail: true,
3061 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3062 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003063 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003064 testCases = append(testCases, testCase{
3065 name: "SignedCertificateTimestampList",
3066 flags: []string{
3067 "-enable-signed-cert-timestamps",
3068 "-expect-signed-cert-timestamps",
3069 base64.StdEncoding.EncodeToString(testSCTList),
3070 },
3071 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003072 testCases = append(testCases, testCase{
3073 testType: clientTest,
3074 name: "ClientHelloPadding",
3075 config: Config{
3076 Bugs: ProtocolBugs{
3077 RequireClientHelloSize: 512,
3078 },
3079 },
3080 // This hostname just needs to be long enough to push the
3081 // ClientHello into F5's danger zone between 256 and 511 bytes
3082 // long.
3083 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3084 })
David Benjamine78bfde2014-09-06 12:45:15 -04003085}
3086
David Benjamin01fe8202014-09-24 15:21:44 -04003087func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003088 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003089 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003090 protocols := []protocol{tls}
3091 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3092 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003093 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003094 for _, protocol := range protocols {
3095 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3096 if protocol == dtls {
3097 suffix += "-DTLS"
3098 }
3099
David Benjaminece3de92015-03-16 18:02:20 -04003100 if sessionVers.version == resumeVers.version {
3101 testCases = append(testCases, testCase{
3102 protocol: protocol,
3103 name: "Resume-Client" + suffix,
3104 resumeSession: true,
3105 config: Config{
3106 MaxVersion: sessionVers.version,
3107 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003108 },
David Benjaminece3de92015-03-16 18:02:20 -04003109 expectedVersion: sessionVers.version,
3110 expectedResumeVersion: resumeVers.version,
3111 })
3112 } else {
3113 testCases = append(testCases, testCase{
3114 protocol: protocol,
3115 name: "Resume-Client-Mismatch" + suffix,
3116 resumeSession: true,
3117 config: Config{
3118 MaxVersion: sessionVers.version,
3119 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003120 },
David Benjaminece3de92015-03-16 18:02:20 -04003121 expectedVersion: sessionVers.version,
3122 resumeConfig: &Config{
3123 MaxVersion: resumeVers.version,
3124 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3125 Bugs: ProtocolBugs{
3126 AllowSessionVersionMismatch: true,
3127 },
3128 },
3129 expectedResumeVersion: resumeVers.version,
3130 shouldFail: true,
3131 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3132 })
3133 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003134
3135 testCases = append(testCases, testCase{
3136 protocol: protocol,
3137 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003138 resumeSession: true,
3139 config: Config{
3140 MaxVersion: sessionVers.version,
3141 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3142 },
3143 expectedVersion: sessionVers.version,
3144 resumeConfig: &Config{
3145 MaxVersion: resumeVers.version,
3146 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3147 },
3148 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003149 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003150 expectedResumeVersion: resumeVers.version,
3151 })
3152
David Benjamin8b8c0062014-11-23 02:47:52 -05003153 testCases = append(testCases, testCase{
3154 protocol: protocol,
3155 testType: serverTest,
3156 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003157 resumeSession: true,
3158 config: Config{
3159 MaxVersion: sessionVers.version,
3160 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3161 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003162 expectedVersion: sessionVers.version,
3163 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003164 resumeConfig: &Config{
3165 MaxVersion: resumeVers.version,
3166 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3167 },
3168 expectedResumeVersion: resumeVers.version,
3169 })
3170 }
David Benjamin01fe8202014-09-24 15:21:44 -04003171 }
3172 }
David Benjaminece3de92015-03-16 18:02:20 -04003173
3174 testCases = append(testCases, testCase{
3175 name: "Resume-Client-CipherMismatch",
3176 resumeSession: true,
3177 config: Config{
3178 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3179 },
3180 resumeConfig: &Config{
3181 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3182 Bugs: ProtocolBugs{
3183 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3184 },
3185 },
3186 shouldFail: true,
3187 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3188 })
David Benjamin01fe8202014-09-24 15:21:44 -04003189}
3190
Adam Langley2ae77d22014-10-28 17:29:33 -07003191func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003192 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003193 testCases = append(testCases, testCase{
3194 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003195 name: "Renegotiate-Server-Forbidden",
David Benjaminb16346b2015-04-08 19:16:58 -04003196 renegotiate: true,
3197 flags: []string{"-reject-peer-renegotiations"},
3198 shouldFail: true,
3199 expectedError: ":NO_RENEGOTIATION:",
3200 expectedLocalError: "remote error: no renegotiation",
3201 })
Adam Langley5021b222015-06-12 18:27:58 -07003202 // The server shouldn't echo the renegotiation extension unless
3203 // requested by the client.
3204 testCases = append(testCases, testCase{
3205 testType: serverTest,
3206 name: "Renegotiate-Server-NoExt",
3207 config: Config{
3208 Bugs: ProtocolBugs{
3209 NoRenegotiationInfo: true,
3210 RequireRenegotiationInfo: true,
3211 },
3212 },
3213 shouldFail: true,
3214 expectedLocalError: "renegotiation extension missing",
3215 })
3216 // The renegotiation SCSV should be sufficient for the server to echo
3217 // the extension.
3218 testCases = append(testCases, testCase{
3219 testType: serverTest,
3220 name: "Renegotiate-Server-NoExt-SCSV",
3221 config: Config{
3222 Bugs: ProtocolBugs{
3223 NoRenegotiationInfo: true,
3224 SendRenegotiationSCSV: true,
3225 RequireRenegotiationInfo: true,
3226 },
3227 },
3228 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003229 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003230 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003231 config: Config{
3232 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003233 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003234 },
3235 },
3236 renegotiate: true,
3237 })
3238 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003239 name: "Renegotiate-Client-EmptyExt",
3240 renegotiate: true,
3241 config: Config{
3242 Bugs: ProtocolBugs{
3243 EmptyRenegotiationInfo: true,
3244 },
3245 },
3246 shouldFail: true,
3247 expectedError: ":RENEGOTIATION_MISMATCH:",
3248 })
3249 testCases = append(testCases, testCase{
3250 name: "Renegotiate-Client-BadExt",
3251 renegotiate: true,
3252 config: Config{
3253 Bugs: ProtocolBugs{
3254 BadRenegotiationInfo: true,
3255 },
3256 },
3257 shouldFail: true,
3258 expectedError: ":RENEGOTIATION_MISMATCH:",
3259 })
3260 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003261 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003262 config: Config{
3263 Bugs: ProtocolBugs{
3264 NoRenegotiationInfo: true,
3265 },
3266 },
3267 shouldFail: true,
3268 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3269 flags: []string{"-no-legacy-server-connect"},
3270 })
3271 testCases = append(testCases, testCase{
3272 name: "Renegotiate-Client-NoExt-Allowed",
3273 renegotiate: true,
3274 config: Config{
3275 Bugs: ProtocolBugs{
3276 NoRenegotiationInfo: true,
3277 },
3278 },
3279 })
3280 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003281 name: "Renegotiate-Client-SwitchCiphers",
3282 renegotiate: true,
3283 config: Config{
3284 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3285 },
3286 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3287 })
3288 testCases = append(testCases, testCase{
3289 name: "Renegotiate-Client-SwitchCiphers2",
3290 renegotiate: true,
3291 config: Config{
3292 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3293 },
3294 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3295 })
David Benjaminc44b1df2014-11-23 12:11:01 -05003296 testCases = append(testCases, testCase{
David Benjaminb16346b2015-04-08 19:16:58 -04003297 name: "Renegotiate-Client-Forbidden",
3298 renegotiate: true,
3299 flags: []string{"-reject-peer-renegotiations"},
3300 shouldFail: true,
3301 expectedError: ":NO_RENEGOTIATION:",
3302 expectedLocalError: "remote error: no renegotiation",
3303 })
3304 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003305 name: "Renegotiate-SameClientVersion",
3306 renegotiate: true,
3307 config: Config{
3308 MaxVersion: VersionTLS10,
3309 Bugs: ProtocolBugs{
3310 RequireSameRenegoClientVersion: true,
3311 },
3312 },
3313 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003314 testCases = append(testCases, testCase{
3315 name: "Renegotiate-FalseStart",
3316 renegotiate: true,
3317 config: Config{
3318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3319 NextProtos: []string{"foo"},
3320 },
3321 flags: []string{
3322 "-false-start",
3323 "-select-next-proto", "foo",
3324 },
3325 shimWritesFirst: true,
3326 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003327}
3328
David Benjamin5e961c12014-11-07 01:48:35 -05003329func addDTLSReplayTests() {
3330 // Test that sequence number replays are detected.
3331 testCases = append(testCases, testCase{
3332 protocol: dtls,
3333 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003334 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003335 replayWrites: true,
3336 })
3337
David Benjamin8e6db492015-07-25 18:29:23 -04003338 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003339 // than the retransmit window.
3340 testCases = append(testCases, testCase{
3341 protocol: dtls,
3342 name: "DTLS-Replay-LargeGaps",
3343 config: Config{
3344 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003345 SequenceNumberMapping: func(in uint64) uint64 {
3346 return in * 127
3347 },
David Benjamin5e961c12014-11-07 01:48:35 -05003348 },
3349 },
David Benjamin8e6db492015-07-25 18:29:23 -04003350 messageCount: 200,
3351 replayWrites: true,
3352 })
3353
3354 // Test the incoming sequence number changing non-monotonically.
3355 testCases = append(testCases, testCase{
3356 protocol: dtls,
3357 name: "DTLS-Replay-NonMonotonic",
3358 config: Config{
3359 Bugs: ProtocolBugs{
3360 SequenceNumberMapping: func(in uint64) uint64 {
3361 return in ^ 31
3362 },
3363 },
3364 },
3365 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003366 replayWrites: true,
3367 })
3368}
3369
David Benjamin000800a2014-11-14 01:43:59 -05003370var testHashes = []struct {
3371 name string
3372 id uint8
3373}{
3374 {"SHA1", hashSHA1},
3375 {"SHA224", hashSHA224},
3376 {"SHA256", hashSHA256},
3377 {"SHA384", hashSHA384},
3378 {"SHA512", hashSHA512},
3379}
3380
3381func addSigningHashTests() {
3382 // Make sure each hash works. Include some fake hashes in the list and
3383 // ensure they're ignored.
3384 for _, hash := range testHashes {
3385 testCases = append(testCases, testCase{
3386 name: "SigningHash-ClientAuth-" + hash.name,
3387 config: Config{
3388 ClientAuth: RequireAnyClientCert,
3389 SignatureAndHashes: []signatureAndHash{
3390 {signatureRSA, 42},
3391 {signatureRSA, hash.id},
3392 {signatureRSA, 255},
3393 },
3394 },
3395 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003396 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3397 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003398 },
3399 })
3400
3401 testCases = append(testCases, testCase{
3402 testType: serverTest,
3403 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3404 config: Config{
3405 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3406 SignatureAndHashes: []signatureAndHash{
3407 {signatureRSA, 42},
3408 {signatureRSA, hash.id},
3409 {signatureRSA, 255},
3410 },
3411 },
3412 })
3413 }
3414
3415 // Test that hash resolution takes the signature type into account.
3416 testCases = append(testCases, testCase{
3417 name: "SigningHash-ClientAuth-SignatureType",
3418 config: Config{
3419 ClientAuth: RequireAnyClientCert,
3420 SignatureAndHashes: []signatureAndHash{
3421 {signatureECDSA, hashSHA512},
3422 {signatureRSA, hashSHA384},
3423 {signatureECDSA, hashSHA1},
3424 },
3425 },
3426 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003427 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3428 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003429 },
3430 })
3431
3432 testCases = append(testCases, testCase{
3433 testType: serverTest,
3434 name: "SigningHash-ServerKeyExchange-SignatureType",
3435 config: Config{
3436 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3437 SignatureAndHashes: []signatureAndHash{
3438 {signatureECDSA, hashSHA512},
3439 {signatureRSA, hashSHA384},
3440 {signatureECDSA, hashSHA1},
3441 },
3442 },
3443 })
3444
3445 // Test that, if the list is missing, the peer falls back to SHA-1.
3446 testCases = append(testCases, testCase{
3447 name: "SigningHash-ClientAuth-Fallback",
3448 config: Config{
3449 ClientAuth: RequireAnyClientCert,
3450 SignatureAndHashes: []signatureAndHash{
3451 {signatureRSA, hashSHA1},
3452 },
3453 Bugs: ProtocolBugs{
3454 NoSignatureAndHashes: true,
3455 },
3456 },
3457 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003458 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3459 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003460 },
3461 })
3462
3463 testCases = append(testCases, testCase{
3464 testType: serverTest,
3465 name: "SigningHash-ServerKeyExchange-Fallback",
3466 config: Config{
3467 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3468 SignatureAndHashes: []signatureAndHash{
3469 {signatureRSA, hashSHA1},
3470 },
3471 Bugs: ProtocolBugs{
3472 NoSignatureAndHashes: true,
3473 },
3474 },
3475 })
David Benjamin72dc7832015-03-16 17:49:43 -04003476
3477 // Test that hash preferences are enforced. BoringSSL defaults to
3478 // rejecting MD5 signatures.
3479 testCases = append(testCases, testCase{
3480 testType: serverTest,
3481 name: "SigningHash-ClientAuth-Enforced",
3482 config: Config{
3483 Certificates: []Certificate{rsaCertificate},
3484 SignatureAndHashes: []signatureAndHash{
3485 {signatureRSA, hashMD5},
3486 // Advertise SHA-1 so the handshake will
3487 // proceed, but the shim's preferences will be
3488 // ignored in CertificateVerify generation, so
3489 // MD5 will be chosen.
3490 {signatureRSA, hashSHA1},
3491 },
3492 Bugs: ProtocolBugs{
3493 IgnorePeerSignatureAlgorithmPreferences: true,
3494 },
3495 },
3496 flags: []string{"-require-any-client-certificate"},
3497 shouldFail: true,
3498 expectedError: ":WRONG_SIGNATURE_TYPE:",
3499 })
3500
3501 testCases = append(testCases, testCase{
3502 name: "SigningHash-ServerKeyExchange-Enforced",
3503 config: Config{
3504 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3505 SignatureAndHashes: []signatureAndHash{
3506 {signatureRSA, hashMD5},
3507 },
3508 Bugs: ProtocolBugs{
3509 IgnorePeerSignatureAlgorithmPreferences: true,
3510 },
3511 },
3512 shouldFail: true,
3513 expectedError: ":WRONG_SIGNATURE_TYPE:",
3514 })
David Benjamin000800a2014-11-14 01:43:59 -05003515}
3516
David Benjamin83f90402015-01-27 01:09:43 -05003517// timeouts is the retransmit schedule for BoringSSL. It doubles and
3518// caps at 60 seconds. On the 13th timeout, it gives up.
3519var timeouts = []time.Duration{
3520 1 * time.Second,
3521 2 * time.Second,
3522 4 * time.Second,
3523 8 * time.Second,
3524 16 * time.Second,
3525 32 * time.Second,
3526 60 * time.Second,
3527 60 * time.Second,
3528 60 * time.Second,
3529 60 * time.Second,
3530 60 * time.Second,
3531 60 * time.Second,
3532 60 * time.Second,
3533}
3534
3535func addDTLSRetransmitTests() {
3536 // Test that this is indeed the timeout schedule. Stress all
3537 // four patterns of handshake.
3538 for i := 1; i < len(timeouts); i++ {
3539 number := strconv.Itoa(i)
3540 testCases = append(testCases, testCase{
3541 protocol: dtls,
3542 name: "DTLS-Retransmit-Client-" + number,
3543 config: Config{
3544 Bugs: ProtocolBugs{
3545 TimeoutSchedule: timeouts[:i],
3546 },
3547 },
3548 resumeSession: true,
3549 flags: []string{"-async"},
3550 })
3551 testCases = append(testCases, testCase{
3552 protocol: dtls,
3553 testType: serverTest,
3554 name: "DTLS-Retransmit-Server-" + number,
3555 config: Config{
3556 Bugs: ProtocolBugs{
3557 TimeoutSchedule: timeouts[:i],
3558 },
3559 },
3560 resumeSession: true,
3561 flags: []string{"-async"},
3562 })
3563 }
3564
3565 // Test that exceeding the timeout schedule hits a read
3566 // timeout.
3567 testCases = append(testCases, testCase{
3568 protocol: dtls,
3569 name: "DTLS-Retransmit-Timeout",
3570 config: Config{
3571 Bugs: ProtocolBugs{
3572 TimeoutSchedule: timeouts,
3573 },
3574 },
3575 resumeSession: true,
3576 flags: []string{"-async"},
3577 shouldFail: true,
3578 expectedError: ":READ_TIMEOUT_EXPIRED:",
3579 })
3580
3581 // Test that timeout handling has a fudge factor, due to API
3582 // problems.
3583 testCases = append(testCases, testCase{
3584 protocol: dtls,
3585 name: "DTLS-Retransmit-Fudge",
3586 config: Config{
3587 Bugs: ProtocolBugs{
3588 TimeoutSchedule: []time.Duration{
3589 timeouts[0] - 10*time.Millisecond,
3590 },
3591 },
3592 },
3593 resumeSession: true,
3594 flags: []string{"-async"},
3595 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05003596
3597 // Test that the final Finished retransmitting isn't
3598 // duplicated if the peer badly fragments everything.
3599 testCases = append(testCases, testCase{
3600 testType: serverTest,
3601 protocol: dtls,
3602 name: "DTLS-Retransmit-Fragmented",
3603 config: Config{
3604 Bugs: ProtocolBugs{
3605 TimeoutSchedule: []time.Duration{timeouts[0]},
3606 MaxHandshakeRecordLength: 2,
3607 },
3608 },
3609 flags: []string{"-async"},
3610 })
David Benjamin83f90402015-01-27 01:09:43 -05003611}
3612
David Benjaminc565ebb2015-04-03 04:06:36 -04003613func addExportKeyingMaterialTests() {
3614 for _, vers := range tlsVersions {
3615 if vers.version == VersionSSL30 {
3616 continue
3617 }
3618 testCases = append(testCases, testCase{
3619 name: "ExportKeyingMaterial-" + vers.name,
3620 config: Config{
3621 MaxVersion: vers.version,
3622 },
3623 exportKeyingMaterial: 1024,
3624 exportLabel: "label",
3625 exportContext: "context",
3626 useExportContext: true,
3627 })
3628 testCases = append(testCases, testCase{
3629 name: "ExportKeyingMaterial-NoContext-" + vers.name,
3630 config: Config{
3631 MaxVersion: vers.version,
3632 },
3633 exportKeyingMaterial: 1024,
3634 })
3635 testCases = append(testCases, testCase{
3636 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
3637 config: Config{
3638 MaxVersion: vers.version,
3639 },
3640 exportKeyingMaterial: 1024,
3641 useExportContext: true,
3642 })
3643 testCases = append(testCases, testCase{
3644 name: "ExportKeyingMaterial-Small-" + vers.name,
3645 config: Config{
3646 MaxVersion: vers.version,
3647 },
3648 exportKeyingMaterial: 1,
3649 exportLabel: "label",
3650 exportContext: "context",
3651 useExportContext: true,
3652 })
3653 }
3654 testCases = append(testCases, testCase{
3655 name: "ExportKeyingMaterial-SSL3",
3656 config: Config{
3657 MaxVersion: VersionSSL30,
3658 },
3659 exportKeyingMaterial: 1024,
3660 exportLabel: "label",
3661 exportContext: "context",
3662 useExportContext: true,
3663 shouldFail: true,
3664 expectedError: "failed to export keying material",
3665 })
3666}
3667
Adam Langleyaf0e32c2015-06-03 09:57:23 -07003668func addTLSUniqueTests() {
3669 for _, isClient := range []bool{false, true} {
3670 for _, isResumption := range []bool{false, true} {
3671 for _, hasEMS := range []bool{false, true} {
3672 var suffix string
3673 if isResumption {
3674 suffix = "Resume-"
3675 } else {
3676 suffix = "Full-"
3677 }
3678
3679 if hasEMS {
3680 suffix += "EMS-"
3681 } else {
3682 suffix += "NoEMS-"
3683 }
3684
3685 if isClient {
3686 suffix += "Client"
3687 } else {
3688 suffix += "Server"
3689 }
3690
3691 test := testCase{
3692 name: "TLSUnique-" + suffix,
3693 testTLSUnique: true,
3694 config: Config{
3695 Bugs: ProtocolBugs{
3696 NoExtendedMasterSecret: !hasEMS,
3697 },
3698 },
3699 }
3700
3701 if isResumption {
3702 test.resumeSession = true
3703 test.resumeConfig = &Config{
3704 Bugs: ProtocolBugs{
3705 NoExtendedMasterSecret: !hasEMS,
3706 },
3707 }
3708 }
3709
3710 if isResumption && !hasEMS {
3711 test.shouldFail = true
3712 test.expectedError = "failed to get tls-unique"
3713 }
3714
3715 testCases = append(testCases, test)
3716 }
3717 }
3718 }
3719}
3720
Adam Langley09505632015-07-30 18:10:13 -07003721func addCustomExtensionTests() {
3722 expectedContents := "custom extension"
3723 emptyString := ""
3724
3725 for _, isClient := range []bool{false, true} {
3726 suffix := "Server"
3727 flag := "-enable-server-custom-extension"
3728 testType := serverTest
3729 if isClient {
3730 suffix = "Client"
3731 flag = "-enable-client-custom-extension"
3732 testType = clientTest
3733 }
3734
3735 testCases = append(testCases, testCase{
3736 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04003737 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07003738 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04003739 Bugs: ProtocolBugs{
3740 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07003741 ExpectedCustomExtension: &expectedContents,
3742 },
3743 },
3744 flags: []string{flag},
3745 })
3746
3747 // If the parse callback fails, the handshake should also fail.
3748 testCases = append(testCases, testCase{
3749 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04003750 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07003751 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04003752 Bugs: ProtocolBugs{
3753 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07003754 ExpectedCustomExtension: &expectedContents,
3755 },
3756 },
David Benjamin399e7c92015-07-30 23:01:27 -04003757 flags: []string{flag},
3758 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07003759 expectedError: ":CUSTOM_EXTENSION_ERROR:",
3760 })
3761
3762 // If the add callback fails, the handshake should also fail.
3763 testCases = append(testCases, testCase{
3764 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04003765 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07003766 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04003767 Bugs: ProtocolBugs{
3768 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07003769 ExpectedCustomExtension: &expectedContents,
3770 },
3771 },
David Benjamin399e7c92015-07-30 23:01:27 -04003772 flags: []string{flag, "-custom-extension-fail-add"},
3773 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07003774 expectedError: ":CUSTOM_EXTENSION_ERROR:",
3775 })
3776
3777 // If the add callback returns zero, no extension should be
3778 // added.
3779 skipCustomExtension := expectedContents
3780 if isClient {
3781 // For the case where the client skips sending the
3782 // custom extension, the server must not “echo” it.
3783 skipCustomExtension = ""
3784 }
3785 testCases = append(testCases, testCase{
3786 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04003787 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07003788 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04003789 Bugs: ProtocolBugs{
3790 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07003791 ExpectedCustomExtension: &emptyString,
3792 },
3793 },
3794 flags: []string{flag, "-custom-extension-skip"},
3795 })
3796 }
3797
3798 // The custom extension add callback should not be called if the client
3799 // doesn't send the extension.
3800 testCases = append(testCases, testCase{
3801 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04003802 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07003803 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04003804 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07003805 ExpectedCustomExtension: &emptyString,
3806 },
3807 },
3808 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
3809 })
Adam Langley2deb9842015-08-07 11:15:37 -07003810
3811 // Test an unknown extension from the server.
3812 testCases = append(testCases, testCase{
3813 testType: clientTest,
3814 name: "UnknownExtension-Client",
3815 config: Config{
3816 Bugs: ProtocolBugs{
3817 CustomExtension: expectedContents,
3818 },
3819 },
3820 shouldFail: true,
3821 expectedError: ":UNEXPECTED_EXTENSION:",
3822 })
Adam Langley09505632015-07-30 18:10:13 -07003823}
3824
Adam Langley7c803a62015-06-15 15:35:05 -07003825func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07003826 defer wg.Done()
3827
3828 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08003829 var err error
3830
3831 if *mallocTest < 0 {
3832 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07003833 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08003834 } else {
3835 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
3836 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07003837 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08003838 if err != nil {
3839 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
3840 }
3841 break
3842 }
3843 }
3844 }
Adam Langley95c29f32014-06-20 12:00:00 -07003845 statusChan <- statusMsg{test: test, err: err}
3846 }
3847}
3848
3849type statusMsg struct {
3850 test *testCase
3851 started bool
3852 err error
3853}
3854
David Benjamin5f237bc2015-02-11 17:14:15 -05003855func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07003856 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07003857
David Benjamin5f237bc2015-02-11 17:14:15 -05003858 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07003859 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05003860 if !*pipe {
3861 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05003862 var erase string
3863 for i := 0; i < lineLen; i++ {
3864 erase += "\b \b"
3865 }
3866 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05003867 }
3868
Adam Langley95c29f32014-06-20 12:00:00 -07003869 if msg.started {
3870 started++
3871 } else {
3872 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05003873
3874 if msg.err != nil {
3875 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
3876 failed++
3877 testOutput.addResult(msg.test.name, "FAIL")
3878 } else {
3879 if *pipe {
3880 // Print each test instead of a status line.
3881 fmt.Printf("PASSED (%s)\n", msg.test.name)
3882 }
3883 testOutput.addResult(msg.test.name, "PASS")
3884 }
Adam Langley95c29f32014-06-20 12:00:00 -07003885 }
3886
David Benjamin5f237bc2015-02-11 17:14:15 -05003887 if !*pipe {
3888 // Print a new status line.
3889 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
3890 lineLen = len(line)
3891 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07003892 }
Adam Langley95c29f32014-06-20 12:00:00 -07003893 }
David Benjamin5f237bc2015-02-11 17:14:15 -05003894
3895 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07003896}
3897
3898func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07003899 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07003900 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07003901
Adam Langley7c803a62015-06-15 15:35:05 -07003902 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07003903 addCipherSuiteTests()
3904 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07003905 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07003906 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04003907 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08003908 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003909 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05003910 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04003911 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04003912 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04003913 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07003914 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07003915 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05003916 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05003917 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05003918 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04003919 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07003920 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07003921 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04003922 for _, async := range []bool{false, true} {
3923 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04003924 for _, protocol := range []protocol{tls, dtls} {
3925 addStateMachineCoverageTests(async, splitHandshake, protocol)
3926 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003927 }
3928 }
Adam Langley95c29f32014-06-20 12:00:00 -07003929
3930 var wg sync.WaitGroup
3931
Adam Langley7c803a62015-06-15 15:35:05 -07003932 statusChan := make(chan statusMsg, *numWorkers)
3933 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05003934 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07003935
David Benjamin025b3d32014-07-01 19:53:04 -04003936 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07003937
Adam Langley7c803a62015-06-15 15:35:05 -07003938 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07003939 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07003940 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07003941 }
3942
David Benjamin025b3d32014-07-01 19:53:04 -04003943 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07003944 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04003945 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07003946 }
3947 }
3948
3949 close(testChan)
3950 wg.Wait()
3951 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05003952 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07003953
3954 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05003955
3956 if *jsonOutput != "" {
3957 if err := testOutput.writeTo(*jsonOutput); err != nil {
3958 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
3959 }
3960 }
David Benjamin2ab7a862015-04-04 17:02:18 -04003961
3962 if !testOutput.allPassed {
3963 os.Exit(1)
3964 }
Adam Langley95c29f32014-06-20 12:00:00 -07003965}