blob: a9823fcd256ca6a3a2281d024e4dab3fbc0b8da1 [file] [log] [blame]
Adam Langleydc7e9c42015-09-29 15:21:04 -07001package runner
Adam Langley95c29f32014-06-20 12:00:00 -07002
3import (
4 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -04005 "crypto/ecdsa"
6 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -04007 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -04008 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -04009 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070010 "flag"
11 "fmt"
12 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070013 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070014 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070015 "net"
16 "os"
17 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040018 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040019 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080020 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070021 "strings"
22 "sync"
23 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050024 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070025)
26
Adam Langley69a01602014-11-17 17:26:55 -080027var (
David Benjamin5f237bc2015-02-11 17:14:15 -050028 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
29 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
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
Paul Lietar4fac72e2015-09-09 13:44:55 +0100160 // expectedSCTList, if not nil, is the expected SCT list to be received.
161 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400162 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
163 // hash function that the client should have used when signing the
164 // handshake with a client certificate.
165 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700166 // messageLen is the length, in bytes, of the test message that will be
167 // sent.
168 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400169 // messageCount is the number of test messages that will be sent.
170 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400171 // digestPrefs is the list of digest preferences from the client.
172 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400173 // certFile is the path to the certificate to use for the server.
174 certFile string
175 // keyFile is the path to the private key to use for the server.
176 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400177 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400178 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400179 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700180 // expectResumeRejected, if true, specifies that the attempted
181 // resumption must be rejected by the client. This is only valid for a
182 // serverTest.
183 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400184 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500185 // resumption. Unless newSessionsOnResume is set,
186 // SessionTicketKey, ServerSessionCache, and
187 // ClientSessionCache are copied from the initial connection's
188 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400189 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500190 // newSessionsOnResume, if true, will cause resumeConfig to
191 // use a different session resumption context.
192 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400193 // noSessionCache, if true, will cause the server to run without a
194 // session cache.
195 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400196 // sendPrefix sends a prefix on the socket before actually performing a
197 // handshake.
198 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400199 // shimWritesFirst controls whether the shim sends an initial "hello"
200 // message before doing a roundtrip with the runner.
201 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400202 // shimShutsDown, if true, runs a test where the shim shuts down the
203 // connection immediately after the handshake rather than echoing
204 // messages from the runner.
205 shimShutsDown bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700206 // renegotiate indicates the the connection should be renegotiated
207 // during the exchange.
208 renegotiate bool
209 // renegotiateCiphers is a list of ciphersuite ids that will be
210 // switched in just before renegotiation.
211 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500212 // replayWrites, if true, configures the underlying transport
213 // to replay every write it makes in DTLS tests.
214 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500215 // damageFirstWrite, if true, configures the underlying transport to
216 // damage the final byte of the first application data write.
217 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400218 // exportKeyingMaterial, if non-zero, configures the test to exchange
219 // keying material and verify they match.
220 exportKeyingMaterial int
221 exportLabel string
222 exportContext string
223 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400224 // flags, if not empty, contains a list of command-line flags that will
225 // be passed to the shim program.
226 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700227 // testTLSUnique, if true, causes the shim to send the tls-unique value
228 // which will be compared against the expected value.
229 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400230 // sendEmptyRecords is the number of consecutive empty records to send
231 // before and after the test message.
232 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400233 // sendWarningAlerts is the number of consecutive warning alerts to send
234 // before and after the test message.
235 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400236 // expectMessageDropped, if true, means the test message is expected to
237 // be dropped by the client rather than echoed back.
238 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700239}
240
Adam Langley7c803a62015-06-15 15:35:05 -0700241var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700242
David Benjamin8e6db492015-07-25 18:29:23 -0400243func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -0500244 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500245 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500246 if *flagDebug {
247 connDebug = &recordingConn{Conn: conn}
248 conn = connDebug
249 defer func() {
250 connDebug.WriteTo(os.Stdout)
251 }()
252 }
253
David Benjamin6fd297b2014-08-11 18:43:38 -0400254 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500255 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
256 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500257 if test.replayWrites {
258 conn = newReplayAdaptor(conn)
259 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400260 }
261
David Benjamin5fa3eba2015-01-22 16:35:40 -0500262 if test.damageFirstWrite {
263 connDamage = newDamageAdaptor(conn)
264 conn = connDamage
265 }
266
David Benjamin6fd297b2014-08-11 18:43:38 -0400267 if test.sendPrefix != "" {
268 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
269 return err
270 }
David Benjamin98e882e2014-08-08 13:24:34 -0400271 }
272
David Benjamin1d5c83e2014-07-22 19:20:02 -0400273 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400274 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400275 if test.protocol == dtls {
276 tlsConn = DTLSServer(conn, config)
277 } else {
278 tlsConn = Server(conn, config)
279 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400280 } else {
281 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400282 if test.protocol == dtls {
283 tlsConn = DTLSClient(conn, config)
284 } else {
285 tlsConn = Client(conn, config)
286 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400287 }
David Benjamin30789da2015-08-29 22:56:45 -0400288 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400289
Adam Langley95c29f32014-06-20 12:00:00 -0700290 if err := tlsConn.Handshake(); err != nil {
291 return err
292 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700293
David Benjamin01fe8202014-09-24 15:21:44 -0400294 // TODO(davidben): move all per-connection expectations into a dedicated
295 // expectations struct that can be specified separately for the two
296 // legs.
297 expectedVersion := test.expectedVersion
298 if isResume && test.expectedResumeVersion != 0 {
299 expectedVersion = test.expectedResumeVersion
300 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700301 connState := tlsConn.ConnectionState()
302 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400303 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400304 }
305
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700306 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400307 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
308 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700309 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
310 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
311 }
David Benjamin90da8c82015-04-20 14:57:57 -0400312
David Benjamina08e49d2014-08-24 01:46:07 -0400313 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700314 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400315 if channelID == nil {
316 return fmt.Errorf("no channel ID negotiated")
317 }
318 if channelID.Curve != channelIDKey.Curve ||
319 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
320 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
321 return fmt.Errorf("incorrect channel ID")
322 }
323 }
324
David Benjaminae2888f2014-09-06 12:58:58 -0400325 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700326 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400327 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
328 }
329 }
330
David Benjaminfc7b0862014-09-06 13:21:53 -0400331 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700332 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400333 return fmt.Errorf("next proto type mismatch")
334 }
335 }
336
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700337 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500338 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
339 }
340
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100341 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
342 return fmt.Errorf("OCSP Response mismatch")
343 }
344
Paul Lietar4fac72e2015-09-09 13:44:55 +0100345 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
346 return fmt.Errorf("SCT list mismatch")
347 }
348
Steven Valdez0d62f262015-09-04 12:41:04 -0400349 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
350 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
351 }
352
David Benjaminc565ebb2015-04-03 04:06:36 -0400353 if test.exportKeyingMaterial > 0 {
354 actual := make([]byte, test.exportKeyingMaterial)
355 if _, err := io.ReadFull(tlsConn, actual); err != nil {
356 return err
357 }
358 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
359 if err != nil {
360 return err
361 }
362 if !bytes.Equal(actual, expected) {
363 return fmt.Errorf("keying material mismatch")
364 }
365 }
366
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700367 if test.testTLSUnique {
368 var peersValue [12]byte
369 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
370 return err
371 }
372 expected := tlsConn.ConnectionState().TLSUnique
373 if !bytes.Equal(peersValue[:], expected) {
374 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
375 }
376 }
377
David Benjamine58c4f52014-08-24 03:47:07 -0400378 if test.shimWritesFirst {
379 var buf [5]byte
380 _, err := io.ReadFull(tlsConn, buf[:])
381 if err != nil {
382 return err
383 }
384 if string(buf[:]) != "hello" {
385 return fmt.Errorf("bad initial message")
386 }
387 }
388
David Benjamina8ebe222015-06-06 03:04:39 -0400389 for i := 0; i < test.sendEmptyRecords; i++ {
390 tlsConn.Write(nil)
391 }
392
David Benjamin24f346d2015-06-06 03:28:08 -0400393 for i := 0; i < test.sendWarningAlerts; i++ {
394 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
395 }
396
Adam Langleycf2d4f42014-10-28 19:06:14 -0700397 if test.renegotiate {
398 if test.renegotiateCiphers != nil {
399 config.CipherSuites = test.renegotiateCiphers
400 }
401 if err := tlsConn.Renegotiate(); err != nil {
402 return err
403 }
404 } else if test.renegotiateCiphers != nil {
405 panic("renegotiateCiphers without renegotiate")
406 }
407
David Benjamin5fa3eba2015-01-22 16:35:40 -0500408 if test.damageFirstWrite {
409 connDamage.setDamage(true)
410 tlsConn.Write([]byte("DAMAGED WRITE"))
411 connDamage.setDamage(false)
412 }
413
David Benjamin8e6db492015-07-25 18:29:23 -0400414 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700415 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400416 if test.protocol == dtls {
417 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
418 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700419 // Read until EOF.
420 _, err := io.Copy(ioutil.Discard, tlsConn)
421 return err
422 }
David Benjamin4417d052015-04-05 04:17:25 -0400423 if messageLen == 0 {
424 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700425 }
Adam Langley95c29f32014-06-20 12:00:00 -0700426
David Benjamin8e6db492015-07-25 18:29:23 -0400427 messageCount := test.messageCount
428 if messageCount == 0 {
429 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400430 }
431
David Benjamin8e6db492015-07-25 18:29:23 -0400432 for j := 0; j < messageCount; j++ {
433 testMessage := make([]byte, messageLen)
434 for i := range testMessage {
435 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400436 }
David Benjamin8e6db492015-07-25 18:29:23 -0400437 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700438
David Benjamin8e6db492015-07-25 18:29:23 -0400439 for i := 0; i < test.sendEmptyRecords; i++ {
440 tlsConn.Write(nil)
441 }
442
443 for i := 0; i < test.sendWarningAlerts; i++ {
444 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
445 }
446
David Benjamin4f75aaf2015-09-01 16:53:10 -0400447 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400448 // The shim will not respond.
449 continue
450 }
451
David Benjamin8e6db492015-07-25 18:29:23 -0400452 buf := make([]byte, len(testMessage))
453 if test.protocol == dtls {
454 bufTmp := make([]byte, len(buf)+1)
455 n, err := tlsConn.Read(bufTmp)
456 if err != nil {
457 return err
458 }
459 if n != len(buf) {
460 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
461 }
462 copy(buf, bufTmp)
463 } else {
464 _, err := io.ReadFull(tlsConn, buf)
465 if err != nil {
466 return err
467 }
468 }
469
470 for i, v := range buf {
471 if v != testMessage[i]^0xff {
472 return fmt.Errorf("bad reply contents at byte %d", i)
473 }
Adam Langley95c29f32014-06-20 12:00:00 -0700474 }
475 }
476
477 return nil
478}
479
David Benjamin325b5c32014-07-01 19:40:31 -0400480func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
481 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700482 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400483 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700484 }
David Benjamin325b5c32014-07-01 19:40:31 -0400485 valgrindArgs = append(valgrindArgs, path)
486 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700487
David Benjamin325b5c32014-07-01 19:40:31 -0400488 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700489}
490
David Benjamin325b5c32014-07-01 19:40:31 -0400491func gdbOf(path string, args ...string) *exec.Cmd {
492 xtermArgs := []string{"-e", "gdb", "--args"}
493 xtermArgs = append(xtermArgs, path)
494 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700495
David Benjamin325b5c32014-07-01 19:40:31 -0400496 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700497}
498
Adam Langley69a01602014-11-17 17:26:55 -0800499type moreMallocsError struct{}
500
501func (moreMallocsError) Error() string {
502 return "child process did not exhaust all allocation calls"
503}
504
505var errMoreMallocs = moreMallocsError{}
506
David Benjamin87c8a642015-02-21 01:54:29 -0500507// accept accepts a connection from listener, unless waitChan signals a process
508// exit first.
509func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
510 type connOrError struct {
511 conn net.Conn
512 err error
513 }
514 connChan := make(chan connOrError, 1)
515 go func() {
516 conn, err := listener.Accept()
517 connChan <- connOrError{conn, err}
518 close(connChan)
519 }()
520 select {
521 case result := <-connChan:
522 return result.conn, result.err
523 case childErr := <-waitChan:
524 waitChan <- childErr
525 return nil, fmt.Errorf("child exited early: %s", childErr)
526 }
527}
528
Adam Langley7c803a62015-06-15 15:35:05 -0700529func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700530 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
531 panic("Error expected without shouldFail in " + test.name)
532 }
533
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700534 if test.expectResumeRejected && !test.resumeSession {
535 panic("expectResumeRejected without resumeSession in " + test.name)
536 }
537
Steven Valdez0d62f262015-09-04 12:41:04 -0400538 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
539 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
540 }
541
David Benjamin87c8a642015-02-21 01:54:29 -0500542 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
543 if err != nil {
544 panic(err)
545 }
546 defer func() {
547 if listener != nil {
548 listener.Close()
549 }
550 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700551
David Benjamin87c8a642015-02-21 01:54:29 -0500552 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400553 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400554 flags = append(flags, "-server")
555
David Benjamin025b3d32014-07-01 19:53:04 -0400556 flags = append(flags, "-key-file")
557 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700558 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400559 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700560 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400561 }
562
563 flags = append(flags, "-cert-file")
564 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700565 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400566 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700567 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400568 }
569 }
David Benjamin5a593af2014-08-11 19:51:50 -0400570
Steven Valdez0d62f262015-09-04 12:41:04 -0400571 if test.digestPrefs != "" {
572 flags = append(flags, "-digest-prefs")
573 flags = append(flags, test.digestPrefs)
574 }
575
David Benjamin6fd297b2014-08-11 18:43:38 -0400576 if test.protocol == dtls {
577 flags = append(flags, "-dtls")
578 }
579
David Benjamin5a593af2014-08-11 19:51:50 -0400580 if test.resumeSession {
581 flags = append(flags, "-resume")
582 }
583
David Benjamine58c4f52014-08-24 03:47:07 -0400584 if test.shimWritesFirst {
585 flags = append(flags, "-shim-writes-first")
586 }
587
David Benjamin30789da2015-08-29 22:56:45 -0400588 if test.shimShutsDown {
589 flags = append(flags, "-shim-shuts-down")
590 }
591
David Benjaminc565ebb2015-04-03 04:06:36 -0400592 if test.exportKeyingMaterial > 0 {
593 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
594 flags = append(flags, "-export-label", test.exportLabel)
595 flags = append(flags, "-export-context", test.exportContext)
596 if test.useExportContext {
597 flags = append(flags, "-use-export-context")
598 }
599 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700600 if test.expectResumeRejected {
601 flags = append(flags, "-expect-session-miss")
602 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400603
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700604 if test.testTLSUnique {
605 flags = append(flags, "-tls-unique")
606 }
607
David Benjamin025b3d32014-07-01 19:53:04 -0400608 flags = append(flags, test.flags...)
609
610 var shim *exec.Cmd
611 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700612 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700613 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700614 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400615 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700616 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400617 }
David Benjamin025b3d32014-07-01 19:53:04 -0400618 shim.Stdin = os.Stdin
619 var stdoutBuf, stderrBuf bytes.Buffer
620 shim.Stdout = &stdoutBuf
621 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800622 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500623 shim.Env = os.Environ()
624 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800625 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400626 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800627 }
628 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
629 }
David Benjamin025b3d32014-07-01 19:53:04 -0400630
631 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700632 panic(err)
633 }
David Benjamin87c8a642015-02-21 01:54:29 -0500634 waitChan := make(chan error, 1)
635 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700636
637 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400638 if !test.noSessionCache {
639 config.ClientSessionCache = NewLRUClientSessionCache(1)
640 config.ServerSessionCache = NewLRUServerSessionCache(1)
641 }
David Benjamin025b3d32014-07-01 19:53:04 -0400642 if test.testType == clientTest {
643 if len(config.Certificates) == 0 {
644 config.Certificates = []Certificate{getRSACertificate()}
645 }
David Benjamin87c8a642015-02-21 01:54:29 -0500646 } else {
647 // Supply a ServerName to ensure a constant session cache key,
648 // rather than falling back to net.Conn.RemoteAddr.
649 if len(config.ServerName) == 0 {
650 config.ServerName = "test"
651 }
David Benjamin025b3d32014-07-01 19:53:04 -0400652 }
Adam Langley95c29f32014-06-20 12:00:00 -0700653
David Benjamin87c8a642015-02-21 01:54:29 -0500654 conn, err := acceptOrWait(listener, waitChan)
655 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400656 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500657 conn.Close()
658 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500659
David Benjamin1d5c83e2014-07-22 19:20:02 -0400660 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400661 var resumeConfig Config
662 if test.resumeConfig != nil {
663 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500664 if len(resumeConfig.ServerName) == 0 {
665 resumeConfig.ServerName = config.ServerName
666 }
David Benjamin01fe8202014-09-24 15:21:44 -0400667 if len(resumeConfig.Certificates) == 0 {
668 resumeConfig.Certificates = []Certificate{getRSACertificate()}
669 }
David Benjaminba4594a2015-06-18 18:36:15 -0400670 if test.newSessionsOnResume {
671 if !test.noSessionCache {
672 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
673 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
674 }
675 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500676 resumeConfig.SessionTicketKey = config.SessionTicketKey
677 resumeConfig.ClientSessionCache = config.ClientSessionCache
678 resumeConfig.ServerSessionCache = config.ServerSessionCache
679 }
David Benjamin01fe8202014-09-24 15:21:44 -0400680 } else {
681 resumeConfig = config
682 }
David Benjamin87c8a642015-02-21 01:54:29 -0500683 var connResume net.Conn
684 connResume, err = acceptOrWait(listener, waitChan)
685 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400686 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500687 connResume.Close()
688 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400689 }
690
David Benjamin87c8a642015-02-21 01:54:29 -0500691 // Close the listener now. This is to avoid hangs should the shim try to
692 // open more connections than expected.
693 listener.Close()
694 listener = nil
695
696 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800697 if exitError, ok := childErr.(*exec.ExitError); ok {
698 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
699 return errMoreMallocs
700 }
701 }
Adam Langley95c29f32014-06-20 12:00:00 -0700702
703 stdout := string(stdoutBuf.Bytes())
704 stderr := string(stderrBuf.Bytes())
705 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400706 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700707 localError := "none"
708 if err != nil {
709 localError = err.Error()
710 }
711 if len(test.expectedLocalError) != 0 {
712 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
713 }
Adam Langley95c29f32014-06-20 12:00:00 -0700714
715 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700716 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700717 if childErr != nil {
718 childError = childErr.Error()
719 }
720
721 var msg string
722 switch {
723 case failed && !test.shouldFail:
724 msg = "unexpected failure"
725 case !failed && test.shouldFail:
726 msg = "unexpected success"
727 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700728 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700729 default:
730 panic("internal error")
731 }
732
David Benjaminc565ebb2015-04-03 04:06:36 -0400733 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 -0700734 }
735
David Benjaminc565ebb2015-04-03 04:06:36 -0400736 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700737 println(stderr)
738 }
739
740 return nil
741}
742
743var tlsVersions = []struct {
744 name string
745 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400746 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500747 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700748}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500749 {"SSL3", VersionSSL30, "-no-ssl3", false},
750 {"TLS1", VersionTLS10, "-no-tls1", true},
751 {"TLS11", VersionTLS11, "-no-tls11", false},
752 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700753}
754
755var testCipherSuites = []struct {
756 name string
757 id uint16
758}{
759 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400760 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700761 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400762 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400763 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700764 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400765 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400766 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
767 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400768 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400769 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
770 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400771 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700772 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
773 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400774 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
775 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700776 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400777 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400778 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700779 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700780 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700781 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400782 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400783 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700784 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400785 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400786 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700787 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400788 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
789 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700790 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
791 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400792 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700793 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400794 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700795 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700796}
797
David Benjamin8b8c0062014-11-23 02:47:52 -0500798func hasComponent(suiteName, component string) bool {
799 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
800}
801
David Benjaminf7768e42014-08-31 02:06:47 -0400802func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500803 return hasComponent(suiteName, "GCM") ||
804 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400805 hasComponent(suiteName, "SHA384") ||
806 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500807}
808
809func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700810 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400811}
812
Adam Langleya7997f12015-05-14 17:38:50 -0700813func bigFromHex(hex string) *big.Int {
814 ret, ok := new(big.Int).SetString(hex, 16)
815 if !ok {
816 panic("failed to parse hex number 0x" + hex)
817 }
818 return ret
819}
820
Adam Langley7c803a62015-06-15 15:35:05 -0700821func addBasicTests() {
822 basicTests := []testCase{
823 {
824 name: "BadRSASignature",
825 config: Config{
826 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
827 Bugs: ProtocolBugs{
828 InvalidSKXSignature: true,
829 },
830 },
831 shouldFail: true,
832 expectedError: ":BAD_SIGNATURE:",
833 },
834 {
835 name: "BadECDSASignature",
836 config: Config{
837 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
838 Bugs: ProtocolBugs{
839 InvalidSKXSignature: true,
840 },
841 Certificates: []Certificate{getECDSACertificate()},
842 },
843 shouldFail: true,
844 expectedError: ":BAD_SIGNATURE:",
845 },
846 {
David Benjamin6de0e532015-07-28 22:43:19 -0400847 testType: serverTest,
848 name: "BadRSASignature-ClientAuth",
849 config: Config{
850 Bugs: ProtocolBugs{
851 InvalidCertVerifySignature: true,
852 },
853 Certificates: []Certificate{getRSACertificate()},
854 },
855 shouldFail: true,
856 expectedError: ":BAD_SIGNATURE:",
857 flags: []string{"-require-any-client-certificate"},
858 },
859 {
860 testType: serverTest,
861 name: "BadECDSASignature-ClientAuth",
862 config: Config{
863 Bugs: ProtocolBugs{
864 InvalidCertVerifySignature: true,
865 },
866 Certificates: []Certificate{getECDSACertificate()},
867 },
868 shouldFail: true,
869 expectedError: ":BAD_SIGNATURE:",
870 flags: []string{"-require-any-client-certificate"},
871 },
872 {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 name: "BadECDSACurve",
874 config: Config{
875 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
876 Bugs: ProtocolBugs{
877 InvalidSKXCurve: true,
878 },
879 Certificates: []Certificate{getECDSACertificate()},
880 },
881 shouldFail: true,
882 expectedError: ":WRONG_CURVE:",
883 },
884 {
885 testType: serverTest,
886 name: "BadRSAVersion",
887 config: Config{
888 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
889 Bugs: ProtocolBugs{
890 RsaClientKeyExchangeVersion: VersionTLS11,
891 },
892 },
893 shouldFail: true,
894 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
895 },
896 {
897 name: "NoFallbackSCSV",
898 config: Config{
899 Bugs: ProtocolBugs{
900 FailIfNotFallbackSCSV: true,
901 },
902 },
903 shouldFail: true,
904 expectedLocalError: "no fallback SCSV found",
905 },
906 {
907 name: "SendFallbackSCSV",
908 config: Config{
909 Bugs: ProtocolBugs{
910 FailIfNotFallbackSCSV: true,
911 },
912 },
913 flags: []string{"-fallback-scsv"},
914 },
915 {
916 name: "ClientCertificateTypes",
917 config: Config{
918 ClientAuth: RequestClientCert,
919 ClientCertificateTypes: []byte{
920 CertTypeDSSSign,
921 CertTypeRSASign,
922 CertTypeECDSASign,
923 },
924 },
925 flags: []string{
926 "-expect-certificate-types",
927 base64.StdEncoding.EncodeToString([]byte{
928 CertTypeDSSSign,
929 CertTypeRSASign,
930 CertTypeECDSASign,
931 }),
932 },
933 },
934 {
935 name: "NoClientCertificate",
936 config: Config{
937 ClientAuth: RequireAnyClientCert,
938 },
939 shouldFail: true,
940 expectedLocalError: "client didn't provide a certificate",
941 },
942 {
943 name: "UnauthenticatedECDH",
944 config: Config{
945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
946 Bugs: ProtocolBugs{
947 UnauthenticatedECDH: true,
948 },
949 },
950 shouldFail: true,
951 expectedError: ":UNEXPECTED_MESSAGE:",
952 },
953 {
954 name: "SkipCertificateStatus",
955 config: Config{
956 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
957 Bugs: ProtocolBugs{
958 SkipCertificateStatus: true,
959 },
960 },
961 flags: []string{
962 "-enable-ocsp-stapling",
963 },
964 },
965 {
966 name: "SkipServerKeyExchange",
967 config: Config{
968 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
969 Bugs: ProtocolBugs{
970 SkipServerKeyExchange: true,
971 },
972 },
973 shouldFail: true,
974 expectedError: ":UNEXPECTED_MESSAGE:",
975 },
976 {
977 name: "SkipChangeCipherSpec-Client",
978 config: Config{
979 Bugs: ProtocolBugs{
980 SkipChangeCipherSpec: true,
981 },
982 },
983 shouldFail: true,
984 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
985 },
986 {
987 testType: serverTest,
988 name: "SkipChangeCipherSpec-Server",
989 config: Config{
990 Bugs: ProtocolBugs{
991 SkipChangeCipherSpec: true,
992 },
993 },
994 shouldFail: true,
995 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
996 },
997 {
998 testType: serverTest,
999 name: "SkipChangeCipherSpec-Server-NPN",
1000 config: Config{
1001 NextProtos: []string{"bar"},
1002 Bugs: ProtocolBugs{
1003 SkipChangeCipherSpec: true,
1004 },
1005 },
1006 flags: []string{
1007 "-advertise-npn", "\x03foo\x03bar\x03baz",
1008 },
1009 shouldFail: true,
1010 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1011 },
1012 {
1013 name: "FragmentAcrossChangeCipherSpec-Client",
1014 config: Config{
1015 Bugs: ProtocolBugs{
1016 FragmentAcrossChangeCipherSpec: true,
1017 },
1018 },
1019 shouldFail: true,
1020 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1021 },
1022 {
1023 testType: serverTest,
1024 name: "FragmentAcrossChangeCipherSpec-Server",
1025 config: Config{
1026 Bugs: ProtocolBugs{
1027 FragmentAcrossChangeCipherSpec: true,
1028 },
1029 },
1030 shouldFail: true,
1031 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1032 },
1033 {
1034 testType: serverTest,
1035 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1036 config: Config{
1037 NextProtos: []string{"bar"},
1038 Bugs: ProtocolBugs{
1039 FragmentAcrossChangeCipherSpec: true,
1040 },
1041 },
1042 flags: []string{
1043 "-advertise-npn", "\x03foo\x03bar\x03baz",
1044 },
1045 shouldFail: true,
1046 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1047 },
1048 {
1049 testType: serverTest,
1050 name: "Alert",
1051 config: Config{
1052 Bugs: ProtocolBugs{
1053 SendSpuriousAlert: alertRecordOverflow,
1054 },
1055 },
1056 shouldFail: true,
1057 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1058 },
1059 {
1060 protocol: dtls,
1061 testType: serverTest,
1062 name: "Alert-DTLS",
1063 config: Config{
1064 Bugs: ProtocolBugs{
1065 SendSpuriousAlert: alertRecordOverflow,
1066 },
1067 },
1068 shouldFail: true,
1069 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1070 },
1071 {
1072 testType: serverTest,
1073 name: "FragmentAlert",
1074 config: Config{
1075 Bugs: ProtocolBugs{
1076 FragmentAlert: true,
1077 SendSpuriousAlert: alertRecordOverflow,
1078 },
1079 },
1080 shouldFail: true,
1081 expectedError: ":BAD_ALERT:",
1082 },
1083 {
1084 protocol: dtls,
1085 testType: serverTest,
1086 name: "FragmentAlert-DTLS",
1087 config: Config{
1088 Bugs: ProtocolBugs{
1089 FragmentAlert: true,
1090 SendSpuriousAlert: alertRecordOverflow,
1091 },
1092 },
1093 shouldFail: true,
1094 expectedError: ":BAD_ALERT:",
1095 },
1096 {
1097 testType: serverTest,
1098 name: "EarlyChangeCipherSpec-server-1",
1099 config: Config{
1100 Bugs: ProtocolBugs{
1101 EarlyChangeCipherSpec: 1,
1102 },
1103 },
1104 shouldFail: true,
1105 expectedError: ":CCS_RECEIVED_EARLY:",
1106 },
1107 {
1108 testType: serverTest,
1109 name: "EarlyChangeCipherSpec-server-2",
1110 config: Config{
1111 Bugs: ProtocolBugs{
1112 EarlyChangeCipherSpec: 2,
1113 },
1114 },
1115 shouldFail: true,
1116 expectedError: ":CCS_RECEIVED_EARLY:",
1117 },
1118 {
1119 name: "SkipNewSessionTicket",
1120 config: Config{
1121 Bugs: ProtocolBugs{
1122 SkipNewSessionTicket: true,
1123 },
1124 },
1125 shouldFail: true,
1126 expectedError: ":CCS_RECEIVED_EARLY:",
1127 },
1128 {
1129 testType: serverTest,
1130 name: "FallbackSCSV",
1131 config: Config{
1132 MaxVersion: VersionTLS11,
1133 Bugs: ProtocolBugs{
1134 SendFallbackSCSV: true,
1135 },
1136 },
1137 shouldFail: true,
1138 expectedError: ":INAPPROPRIATE_FALLBACK:",
1139 },
1140 {
1141 testType: serverTest,
1142 name: "FallbackSCSV-VersionMatch",
1143 config: Config{
1144 Bugs: ProtocolBugs{
1145 SendFallbackSCSV: true,
1146 },
1147 },
1148 },
1149 {
1150 testType: serverTest,
1151 name: "FragmentedClientVersion",
1152 config: Config{
1153 Bugs: ProtocolBugs{
1154 MaxHandshakeRecordLength: 1,
1155 FragmentClientVersion: true,
1156 },
1157 },
1158 expectedVersion: VersionTLS12,
1159 },
1160 {
1161 testType: serverTest,
1162 name: "MinorVersionTolerance",
1163 config: Config{
1164 Bugs: ProtocolBugs{
1165 SendClientVersion: 0x03ff,
1166 },
1167 },
1168 expectedVersion: VersionTLS12,
1169 },
1170 {
1171 testType: serverTest,
1172 name: "MajorVersionTolerance",
1173 config: Config{
1174 Bugs: ProtocolBugs{
1175 SendClientVersion: 0x0400,
1176 },
1177 },
1178 expectedVersion: VersionTLS12,
1179 },
1180 {
1181 testType: serverTest,
1182 name: "VersionTooLow",
1183 config: Config{
1184 Bugs: ProtocolBugs{
1185 SendClientVersion: 0x0200,
1186 },
1187 },
1188 shouldFail: true,
1189 expectedError: ":UNSUPPORTED_PROTOCOL:",
1190 },
1191 {
1192 testType: serverTest,
1193 name: "HttpGET",
1194 sendPrefix: "GET / HTTP/1.0\n",
1195 shouldFail: true,
1196 expectedError: ":HTTP_REQUEST:",
1197 },
1198 {
1199 testType: serverTest,
1200 name: "HttpPOST",
1201 sendPrefix: "POST / HTTP/1.0\n",
1202 shouldFail: true,
1203 expectedError: ":HTTP_REQUEST:",
1204 },
1205 {
1206 testType: serverTest,
1207 name: "HttpHEAD",
1208 sendPrefix: "HEAD / HTTP/1.0\n",
1209 shouldFail: true,
1210 expectedError: ":HTTP_REQUEST:",
1211 },
1212 {
1213 testType: serverTest,
1214 name: "HttpPUT",
1215 sendPrefix: "PUT / HTTP/1.0\n",
1216 shouldFail: true,
1217 expectedError: ":HTTP_REQUEST:",
1218 },
1219 {
1220 testType: serverTest,
1221 name: "HttpCONNECT",
1222 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1223 shouldFail: true,
1224 expectedError: ":HTTPS_PROXY_REQUEST:",
1225 },
1226 {
1227 testType: serverTest,
1228 name: "Garbage",
1229 sendPrefix: "blah",
1230 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001231 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001232 },
1233 {
1234 name: "SkipCipherVersionCheck",
1235 config: Config{
1236 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1237 MaxVersion: VersionTLS11,
1238 Bugs: ProtocolBugs{
1239 SkipCipherVersionCheck: true,
1240 },
1241 },
1242 shouldFail: true,
1243 expectedError: ":WRONG_CIPHER_RETURNED:",
1244 },
1245 {
1246 name: "RSAEphemeralKey",
1247 config: Config{
1248 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1249 Bugs: ProtocolBugs{
1250 RSAEphemeralKey: true,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":UNEXPECTED_MESSAGE:",
1255 },
1256 {
1257 name: "DisableEverything",
1258 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1259 shouldFail: true,
1260 expectedError: ":WRONG_SSL_VERSION:",
1261 },
1262 {
1263 protocol: dtls,
1264 name: "DisableEverything-DTLS",
1265 flags: []string{"-no-tls12", "-no-tls1"},
1266 shouldFail: true,
1267 expectedError: ":WRONG_SSL_VERSION:",
1268 },
1269 {
1270 name: "NoSharedCipher",
1271 config: Config{
1272 CipherSuites: []uint16{},
1273 },
1274 shouldFail: true,
1275 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1276 },
1277 {
1278 protocol: dtls,
1279 testType: serverTest,
1280 name: "MTU",
1281 config: Config{
1282 Bugs: ProtocolBugs{
1283 MaxPacketLength: 256,
1284 },
1285 },
1286 flags: []string{"-mtu", "256"},
1287 },
1288 {
1289 protocol: dtls,
1290 testType: serverTest,
1291 name: "MTUExceeded",
1292 config: Config{
1293 Bugs: ProtocolBugs{
1294 MaxPacketLength: 255,
1295 },
1296 },
1297 flags: []string{"-mtu", "256"},
1298 shouldFail: true,
1299 expectedLocalError: "dtls: exceeded maximum packet length",
1300 },
1301 {
1302 name: "CertMismatchRSA",
1303 config: Config{
1304 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1305 Certificates: []Certificate{getECDSACertificate()},
1306 Bugs: ProtocolBugs{
1307 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1308 },
1309 },
1310 shouldFail: true,
1311 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1312 },
1313 {
1314 name: "CertMismatchECDSA",
1315 config: Config{
1316 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1317 Certificates: []Certificate{getRSACertificate()},
1318 Bugs: ProtocolBugs{
1319 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1320 },
1321 },
1322 shouldFail: true,
1323 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1324 },
1325 {
1326 name: "EmptyCertificateList",
1327 config: Config{
1328 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1329 Bugs: ProtocolBugs{
1330 EmptyCertificateList: true,
1331 },
1332 },
1333 shouldFail: true,
1334 expectedError: ":DECODE_ERROR:",
1335 },
1336 {
1337 name: "TLSFatalBadPackets",
1338 damageFirstWrite: true,
1339 shouldFail: true,
1340 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1341 },
1342 {
1343 protocol: dtls,
1344 name: "DTLSIgnoreBadPackets",
1345 damageFirstWrite: true,
1346 },
1347 {
1348 protocol: dtls,
1349 name: "DTLSIgnoreBadPackets-Async",
1350 damageFirstWrite: true,
1351 flags: []string{"-async"},
1352 },
1353 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001354 name: "AppDataBeforeHandshake",
1355 config: Config{
1356 Bugs: ProtocolBugs{
1357 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1358 },
1359 },
1360 shouldFail: true,
1361 expectedError: ":UNEXPECTED_RECORD:",
1362 },
1363 {
1364 name: "AppDataBeforeHandshake-Empty",
1365 config: Config{
1366 Bugs: ProtocolBugs{
1367 AppDataBeforeHandshake: []byte{},
1368 },
1369 },
1370 shouldFail: true,
1371 expectedError: ":UNEXPECTED_RECORD:",
1372 },
1373 {
1374 protocol: dtls,
1375 name: "AppDataBeforeHandshake-DTLS",
1376 config: Config{
1377 Bugs: ProtocolBugs{
1378 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1379 },
1380 },
1381 shouldFail: true,
1382 expectedError: ":UNEXPECTED_RECORD:",
1383 },
1384 {
1385 protocol: dtls,
1386 name: "AppDataBeforeHandshake-DTLS-Empty",
1387 config: Config{
1388 Bugs: ProtocolBugs{
1389 AppDataBeforeHandshake: []byte{},
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":UNEXPECTED_RECORD:",
1394 },
1395 {
Adam Langley7c803a62015-06-15 15:35:05 -07001396 name: "AppDataAfterChangeCipherSpec",
1397 config: Config{
1398 Bugs: ProtocolBugs{
1399 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1400 },
1401 },
1402 shouldFail: true,
1403 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1404 },
1405 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001406 name: "AppDataAfterChangeCipherSpec-Empty",
1407 config: Config{
1408 Bugs: ProtocolBugs{
1409 AppDataAfterChangeCipherSpec: []byte{},
1410 },
1411 },
1412 shouldFail: true,
1413 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1414 },
1415 {
Adam Langley7c803a62015-06-15 15:35:05 -07001416 protocol: dtls,
1417 name: "AppDataAfterChangeCipherSpec-DTLS",
1418 config: Config{
1419 Bugs: ProtocolBugs{
1420 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1421 },
1422 },
1423 // BoringSSL's DTLS implementation will drop the out-of-order
1424 // application data.
1425 },
1426 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001427 protocol: dtls,
1428 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1429 config: Config{
1430 Bugs: ProtocolBugs{
1431 AppDataAfterChangeCipherSpec: []byte{},
1432 },
1433 },
1434 // BoringSSL's DTLS implementation will drop the out-of-order
1435 // application data.
1436 },
1437 {
Adam Langley7c803a62015-06-15 15:35:05 -07001438 name: "AlertAfterChangeCipherSpec",
1439 config: Config{
1440 Bugs: ProtocolBugs{
1441 AlertAfterChangeCipherSpec: alertRecordOverflow,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1446 },
1447 {
1448 protocol: dtls,
1449 name: "AlertAfterChangeCipherSpec-DTLS",
1450 config: Config{
1451 Bugs: ProtocolBugs{
1452 AlertAfterChangeCipherSpec: alertRecordOverflow,
1453 },
1454 },
1455 shouldFail: true,
1456 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1457 },
1458 {
1459 protocol: dtls,
1460 name: "ReorderHandshakeFragments-Small-DTLS",
1461 config: Config{
1462 Bugs: ProtocolBugs{
1463 ReorderHandshakeFragments: true,
1464 // Small enough that every handshake message is
1465 // fragmented.
1466 MaxHandshakeRecordLength: 2,
1467 },
1468 },
1469 },
1470 {
1471 protocol: dtls,
1472 name: "ReorderHandshakeFragments-Large-DTLS",
1473 config: Config{
1474 Bugs: ProtocolBugs{
1475 ReorderHandshakeFragments: true,
1476 // Large enough that no handshake message is
1477 // fragmented.
1478 MaxHandshakeRecordLength: 2048,
1479 },
1480 },
1481 },
1482 {
1483 protocol: dtls,
1484 name: "MixCompleteMessageWithFragments-DTLS",
1485 config: Config{
1486 Bugs: ProtocolBugs{
1487 ReorderHandshakeFragments: true,
1488 MixCompleteMessageWithFragments: true,
1489 MaxHandshakeRecordLength: 2,
1490 },
1491 },
1492 },
1493 {
1494 name: "SendInvalidRecordType",
1495 config: Config{
1496 Bugs: ProtocolBugs{
1497 SendInvalidRecordType: true,
1498 },
1499 },
1500 shouldFail: true,
1501 expectedError: ":UNEXPECTED_RECORD:",
1502 },
1503 {
1504 protocol: dtls,
1505 name: "SendInvalidRecordType-DTLS",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 SendInvalidRecordType: true,
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 name: "FalseStart-SkipServerSecondLeg",
1516 config: Config{
1517 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1518 NextProtos: []string{"foo"},
1519 Bugs: ProtocolBugs{
1520 SkipNewSessionTicket: true,
1521 SkipChangeCipherSpec: true,
1522 SkipFinished: true,
1523 ExpectFalseStart: true,
1524 },
1525 },
1526 flags: []string{
1527 "-false-start",
1528 "-handshake-never-done",
1529 "-advertise-alpn", "\x03foo",
1530 },
1531 shimWritesFirst: true,
1532 shouldFail: true,
1533 expectedError: ":UNEXPECTED_RECORD:",
1534 },
1535 {
1536 name: "FalseStart-SkipServerSecondLeg-Implicit",
1537 config: Config{
1538 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1539 NextProtos: []string{"foo"},
1540 Bugs: ProtocolBugs{
1541 SkipNewSessionTicket: true,
1542 SkipChangeCipherSpec: true,
1543 SkipFinished: true,
1544 },
1545 },
1546 flags: []string{
1547 "-implicit-handshake",
1548 "-false-start",
1549 "-handshake-never-done",
1550 "-advertise-alpn", "\x03foo",
1551 },
1552 shouldFail: true,
1553 expectedError: ":UNEXPECTED_RECORD:",
1554 },
1555 {
1556 testType: serverTest,
1557 name: "FailEarlyCallback",
1558 flags: []string{"-fail-early-callback"},
1559 shouldFail: true,
1560 expectedError: ":CONNECTION_REJECTED:",
1561 expectedLocalError: "remote error: access denied",
1562 },
1563 {
1564 name: "WrongMessageType",
1565 config: Config{
1566 Bugs: ProtocolBugs{
1567 WrongCertificateMessageType: true,
1568 },
1569 },
1570 shouldFail: true,
1571 expectedError: ":UNEXPECTED_MESSAGE:",
1572 expectedLocalError: "remote error: unexpected message",
1573 },
1574 {
1575 protocol: dtls,
1576 name: "WrongMessageType-DTLS",
1577 config: Config{
1578 Bugs: ProtocolBugs{
1579 WrongCertificateMessageType: true,
1580 },
1581 },
1582 shouldFail: true,
1583 expectedError: ":UNEXPECTED_MESSAGE:",
1584 expectedLocalError: "remote error: unexpected message",
1585 },
1586 {
1587 protocol: dtls,
1588 name: "FragmentMessageTypeMismatch-DTLS",
1589 config: Config{
1590 Bugs: ProtocolBugs{
1591 MaxHandshakeRecordLength: 2,
1592 FragmentMessageTypeMismatch: true,
1593 },
1594 },
1595 shouldFail: true,
1596 expectedError: ":FRAGMENT_MISMATCH:",
1597 },
1598 {
1599 protocol: dtls,
1600 name: "FragmentMessageLengthMismatch-DTLS",
1601 config: Config{
1602 Bugs: ProtocolBugs{
1603 MaxHandshakeRecordLength: 2,
1604 FragmentMessageLengthMismatch: true,
1605 },
1606 },
1607 shouldFail: true,
1608 expectedError: ":FRAGMENT_MISMATCH:",
1609 },
1610 {
1611 protocol: dtls,
1612 name: "SplitFragments-Header-DTLS",
1613 config: Config{
1614 Bugs: ProtocolBugs{
1615 SplitFragments: 2,
1616 },
1617 },
1618 shouldFail: true,
1619 expectedError: ":UNEXPECTED_MESSAGE:",
1620 },
1621 {
1622 protocol: dtls,
1623 name: "SplitFragments-Boundary-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 SplitFragments: dtlsRecordHeaderLen,
1627 },
1628 },
1629 shouldFail: true,
1630 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1631 },
1632 {
1633 protocol: dtls,
1634 name: "SplitFragments-Body-DTLS",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 SplitFragments: dtlsRecordHeaderLen + 1,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1642 },
1643 {
1644 protocol: dtls,
1645 name: "SendEmptyFragments-DTLS",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SendEmptyFragments: true,
1649 },
1650 },
1651 },
1652 {
1653 name: "UnsupportedCipherSuite",
1654 config: Config{
1655 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1656 Bugs: ProtocolBugs{
1657 IgnorePeerCipherPreferences: true,
1658 },
1659 },
1660 flags: []string{"-cipher", "DEFAULT:!RC4"},
1661 shouldFail: true,
1662 expectedError: ":WRONG_CIPHER_RETURNED:",
1663 },
1664 {
1665 name: "UnsupportedCurve",
1666 config: Config{
1667 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1668 // BoringSSL implements P-224 but doesn't enable it by
1669 // default.
1670 CurvePreferences: []CurveID{CurveP224},
1671 Bugs: ProtocolBugs{
1672 IgnorePeerCurvePreferences: true,
1673 },
1674 },
1675 shouldFail: true,
1676 expectedError: ":WRONG_CURVE:",
1677 },
1678 {
1679 name: "BadFinished",
1680 config: Config{
1681 Bugs: ProtocolBugs{
1682 BadFinished: true,
1683 },
1684 },
1685 shouldFail: true,
1686 expectedError: ":DIGEST_CHECK_FAILED:",
1687 },
1688 {
1689 name: "FalseStart-BadFinished",
1690 config: Config{
1691 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1692 NextProtos: []string{"foo"},
1693 Bugs: ProtocolBugs{
1694 BadFinished: true,
1695 ExpectFalseStart: true,
1696 },
1697 },
1698 flags: []string{
1699 "-false-start",
1700 "-handshake-never-done",
1701 "-advertise-alpn", "\x03foo",
1702 },
1703 shimWritesFirst: true,
1704 shouldFail: true,
1705 expectedError: ":DIGEST_CHECK_FAILED:",
1706 },
1707 {
1708 name: "NoFalseStart-NoALPN",
1709 config: Config{
1710 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1711 Bugs: ProtocolBugs{
1712 ExpectFalseStart: true,
1713 AlertBeforeFalseStartTest: alertAccessDenied,
1714 },
1715 },
1716 flags: []string{
1717 "-false-start",
1718 },
1719 shimWritesFirst: true,
1720 shouldFail: true,
1721 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1722 expectedLocalError: "tls: peer did not false start: EOF",
1723 },
1724 {
1725 name: "NoFalseStart-NoAEAD",
1726 config: Config{
1727 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1728 NextProtos: []string{"foo"},
1729 Bugs: ProtocolBugs{
1730 ExpectFalseStart: true,
1731 AlertBeforeFalseStartTest: alertAccessDenied,
1732 },
1733 },
1734 flags: []string{
1735 "-false-start",
1736 "-advertise-alpn", "\x03foo",
1737 },
1738 shimWritesFirst: true,
1739 shouldFail: true,
1740 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1741 expectedLocalError: "tls: peer did not false start: EOF",
1742 },
1743 {
1744 name: "NoFalseStart-RSA",
1745 config: Config{
1746 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1747 NextProtos: []string{"foo"},
1748 Bugs: ProtocolBugs{
1749 ExpectFalseStart: true,
1750 AlertBeforeFalseStartTest: alertAccessDenied,
1751 },
1752 },
1753 flags: []string{
1754 "-false-start",
1755 "-advertise-alpn", "\x03foo",
1756 },
1757 shimWritesFirst: true,
1758 shouldFail: true,
1759 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1760 expectedLocalError: "tls: peer did not false start: EOF",
1761 },
1762 {
1763 name: "NoFalseStart-DHE_RSA",
1764 config: Config{
1765 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1766 NextProtos: []string{"foo"},
1767 Bugs: ProtocolBugs{
1768 ExpectFalseStart: true,
1769 AlertBeforeFalseStartTest: alertAccessDenied,
1770 },
1771 },
1772 flags: []string{
1773 "-false-start",
1774 "-advertise-alpn", "\x03foo",
1775 },
1776 shimWritesFirst: true,
1777 shouldFail: true,
1778 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1779 expectedLocalError: "tls: peer did not false start: EOF",
1780 },
1781 {
1782 testType: serverTest,
1783 name: "NoSupportedCurves",
1784 config: Config{
1785 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1786 Bugs: ProtocolBugs{
1787 NoSupportedCurves: true,
1788 },
1789 },
1790 },
1791 {
1792 testType: serverTest,
1793 name: "NoCommonCurves",
1794 config: Config{
1795 CipherSuites: []uint16{
1796 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1797 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1798 },
1799 CurvePreferences: []CurveID{CurveP224},
1800 },
1801 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1802 },
1803 {
1804 protocol: dtls,
1805 name: "SendSplitAlert-Sync",
1806 config: Config{
1807 Bugs: ProtocolBugs{
1808 SendSplitAlert: true,
1809 },
1810 },
1811 },
1812 {
1813 protocol: dtls,
1814 name: "SendSplitAlert-Async",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 SendSplitAlert: true,
1818 },
1819 },
1820 flags: []string{"-async"},
1821 },
1822 {
1823 protocol: dtls,
1824 name: "PackDTLSHandshake",
1825 config: Config{
1826 Bugs: ProtocolBugs{
1827 MaxHandshakeRecordLength: 2,
1828 PackHandshakeFragments: 20,
1829 PackHandshakeRecords: 200,
1830 },
1831 },
1832 },
1833 {
1834 testType: serverTest,
1835 protocol: dtls,
1836 name: "NoRC4-DTLS",
1837 config: Config{
1838 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1839 Bugs: ProtocolBugs{
1840 EnableAllCiphersInDTLS: true,
1841 },
1842 },
1843 shouldFail: true,
1844 expectedError: ":NO_SHARED_CIPHER:",
1845 },
1846 {
1847 name: "SendEmptyRecords-Pass",
1848 sendEmptyRecords: 32,
1849 },
1850 {
1851 name: "SendEmptyRecords",
1852 sendEmptyRecords: 33,
1853 shouldFail: true,
1854 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1855 },
1856 {
1857 name: "SendEmptyRecords-Async",
1858 sendEmptyRecords: 33,
1859 flags: []string{"-async"},
1860 shouldFail: true,
1861 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1862 },
1863 {
1864 name: "SendWarningAlerts-Pass",
1865 sendWarningAlerts: 4,
1866 },
1867 {
1868 protocol: dtls,
1869 name: "SendWarningAlerts-DTLS-Pass",
1870 sendWarningAlerts: 4,
1871 },
1872 {
1873 name: "SendWarningAlerts",
1874 sendWarningAlerts: 5,
1875 shouldFail: true,
1876 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1877 },
1878 {
1879 name: "SendWarningAlerts-Async",
1880 sendWarningAlerts: 5,
1881 flags: []string{"-async"},
1882 shouldFail: true,
1883 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1884 },
David Benjaminba4594a2015-06-18 18:36:15 -04001885 {
1886 name: "EmptySessionID",
1887 config: Config{
1888 SessionTicketsDisabled: true,
1889 },
1890 noSessionCache: true,
1891 flags: []string{"-expect-no-session"},
1892 },
David Benjamin30789da2015-08-29 22:56:45 -04001893 {
1894 name: "Unclean-Shutdown",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 NoCloseNotify: true,
1898 ExpectCloseNotify: true,
1899 },
1900 },
1901 shimShutsDown: true,
1902 flags: []string{"-check-close-notify"},
1903 shouldFail: true,
1904 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1905 },
1906 {
1907 name: "Unclean-Shutdown-Ignored",
1908 config: Config{
1909 Bugs: ProtocolBugs{
1910 NoCloseNotify: true,
1911 },
1912 },
1913 shimShutsDown: true,
1914 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001915 {
1916 name: "LargePlaintext",
1917 config: Config{
1918 Bugs: ProtocolBugs{
1919 SendLargeRecords: true,
1920 },
1921 },
1922 messageLen: maxPlaintext + 1,
1923 shouldFail: true,
1924 expectedError: ":DATA_LENGTH_TOO_LONG:",
1925 },
1926 {
1927 protocol: dtls,
1928 name: "LargePlaintext-DTLS",
1929 config: Config{
1930 Bugs: ProtocolBugs{
1931 SendLargeRecords: true,
1932 },
1933 },
1934 messageLen: maxPlaintext + 1,
1935 shouldFail: true,
1936 expectedError: ":DATA_LENGTH_TOO_LONG:",
1937 },
1938 {
1939 name: "LargeCiphertext",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 SendLargeRecords: true,
1943 },
1944 },
1945 messageLen: maxPlaintext * 2,
1946 shouldFail: true,
1947 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1948 },
1949 {
1950 protocol: dtls,
1951 name: "LargeCiphertext-DTLS",
1952 config: Config{
1953 Bugs: ProtocolBugs{
1954 SendLargeRecords: true,
1955 },
1956 },
1957 messageLen: maxPlaintext * 2,
1958 // Unlike the other four cases, DTLS drops records which
1959 // are invalid before authentication, so the connection
1960 // does not fail.
1961 expectMessageDropped: true,
1962 },
Adam Langley7c803a62015-06-15 15:35:05 -07001963 }
Adam Langley7c803a62015-06-15 15:35:05 -07001964 testCases = append(testCases, basicTests...)
1965}
1966
Adam Langley95c29f32014-06-20 12:00:00 -07001967func addCipherSuiteTests() {
1968 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001969 const psk = "12345"
1970 const pskIdentity = "luggage combo"
1971
Adam Langley95c29f32014-06-20 12:00:00 -07001972 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001973 var certFile string
1974 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001975 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001976 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001977 certFile = ecdsaCertificateFile
1978 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001979 } else {
1980 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001981 certFile = rsaCertificateFile
1982 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001983 }
1984
David Benjamin48cae082014-10-27 01:06:24 -04001985 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001986 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001987 flags = append(flags,
1988 "-psk", psk,
1989 "-psk-identity", pskIdentity)
1990 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001991 if hasComponent(suite.name, "NULL") {
1992 // NULL ciphers must be explicitly enabled.
1993 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
1994 }
David Benjamin48cae082014-10-27 01:06:24 -04001995
Adam Langley95c29f32014-06-20 12:00:00 -07001996 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04001997 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07001998 continue
1999 }
2000
David Benjamin025b3d32014-07-01 19:53:04 -04002001 testCases = append(testCases, testCase{
2002 testType: clientTest,
2003 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002004 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002005 MinVersion: ver.version,
2006 MaxVersion: ver.version,
2007 CipherSuites: []uint16{suite.id},
2008 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002009 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002010 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002011 },
David Benjamin48cae082014-10-27 01:06:24 -04002012 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002013 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002014 })
David Benjamin025b3d32014-07-01 19:53:04 -04002015
David Benjamin76d8abe2014-08-14 16:25:34 -04002016 testCases = append(testCases, testCase{
2017 testType: serverTest,
2018 name: ver.name + "-" + suite.name + "-server",
2019 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002020 MinVersion: ver.version,
2021 MaxVersion: ver.version,
2022 CipherSuites: []uint16{suite.id},
2023 Certificates: []Certificate{cert},
2024 PreSharedKey: []byte(psk),
2025 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002026 },
2027 certFile: certFile,
2028 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002029 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002030 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002031 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002032
David Benjamin8b8c0062014-11-23 02:47:52 -05002033 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002034 testCases = append(testCases, testCase{
2035 testType: clientTest,
2036 protocol: dtls,
2037 name: "D" + ver.name + "-" + suite.name + "-client",
2038 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002039 MinVersion: ver.version,
2040 MaxVersion: ver.version,
2041 CipherSuites: []uint16{suite.id},
2042 Certificates: []Certificate{cert},
2043 PreSharedKey: []byte(psk),
2044 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002045 },
David Benjamin48cae082014-10-27 01:06:24 -04002046 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002047 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002048 })
2049 testCases = append(testCases, testCase{
2050 testType: serverTest,
2051 protocol: dtls,
2052 name: "D" + ver.name + "-" + suite.name + "-server",
2053 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002054 MinVersion: ver.version,
2055 MaxVersion: ver.version,
2056 CipherSuites: []uint16{suite.id},
2057 Certificates: []Certificate{cert},
2058 PreSharedKey: []byte(psk),
2059 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002060 },
2061 certFile: certFile,
2062 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002063 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002064 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002065 })
2066 }
Adam Langley95c29f32014-06-20 12:00:00 -07002067 }
David Benjamin2c99d282015-09-01 10:23:00 -04002068
2069 // Ensure both TLS and DTLS accept their maximum record sizes.
2070 testCases = append(testCases, testCase{
2071 name: suite.name + "-LargeRecord",
2072 config: Config{
2073 CipherSuites: []uint16{suite.id},
2074 Certificates: []Certificate{cert},
2075 PreSharedKey: []byte(psk),
2076 PreSharedKeyIdentity: pskIdentity,
2077 },
2078 flags: flags,
2079 messageLen: maxPlaintext,
2080 })
2081 testCases = append(testCases, testCase{
2082 name: suite.name + "-LargeRecord-Extra",
2083 config: Config{
2084 CipherSuites: []uint16{suite.id},
2085 Certificates: []Certificate{cert},
2086 PreSharedKey: []byte(psk),
2087 PreSharedKeyIdentity: pskIdentity,
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2093 messageLen: maxPlaintext + 16384,
2094 })
2095 if isDTLSCipher(suite.name) {
2096 testCases = append(testCases, testCase{
2097 protocol: dtls,
2098 name: suite.name + "-LargeRecord-DTLS",
2099 config: Config{
2100 CipherSuites: []uint16{suite.id},
2101 Certificates: []Certificate{cert},
2102 PreSharedKey: []byte(psk),
2103 PreSharedKeyIdentity: pskIdentity,
2104 },
2105 flags: flags,
2106 messageLen: maxPlaintext,
2107 })
2108 }
Adam Langley95c29f32014-06-20 12:00:00 -07002109 }
Adam Langleya7997f12015-05-14 17:38:50 -07002110
2111 testCases = append(testCases, testCase{
2112 name: "WeakDH",
2113 config: Config{
2114 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2115 Bugs: ProtocolBugs{
2116 // This is a 1023-bit prime number, generated
2117 // with:
2118 // openssl gendh 1023 | openssl asn1parse -i
2119 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2120 },
2121 },
2122 shouldFail: true,
2123 expectedError: "BAD_DH_P_LENGTH",
2124 })
Adam Langleycef75832015-09-03 14:51:12 -07002125
2126 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2127 // 1.1 specific cipher suite settings. A server is setup with the given
2128 // cipher lists and then a connection is made for each member of
2129 // expectations. The cipher suite that the server selects must match
2130 // the specified one.
2131 var versionSpecificCiphersTest = []struct {
2132 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2133 // expectations is a map from TLS version to cipher suite id.
2134 expectations map[uint16]uint16
2135 }{
2136 {
2137 // Test that the null case (where no version-specific ciphers are set)
2138 // works as expected.
2139 "RC4-SHA:AES128-SHA", // default ciphers
2140 "", // no ciphers specifically for TLS ≥ 1.0
2141 "", // no ciphers specifically for TLS ≥ 1.1
2142 map[uint16]uint16{
2143 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2144 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2145 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2146 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2147 },
2148 },
2149 {
2150 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2151 // cipher.
2152 "RC4-SHA:AES128-SHA", // default
2153 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2154 "", // no ciphers specifically for TLS ≥ 1.1
2155 map[uint16]uint16{
2156 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2157 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2158 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2159 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2160 },
2161 },
2162 {
2163 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2164 // cipher.
2165 "RC4-SHA:AES128-SHA", // default
2166 "", // no ciphers specifically for TLS ≥ 1.0
2167 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2168 map[uint16]uint16{
2169 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2170 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2171 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2172 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2173 },
2174 },
2175 {
2176 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2177 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2178 "RC4-SHA:AES128-SHA", // default
2179 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2180 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2181 map[uint16]uint16{
2182 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2183 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2184 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2185 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2186 },
2187 },
2188 }
2189
2190 for i, test := range versionSpecificCiphersTest {
2191 for version, expectedCipherSuite := range test.expectations {
2192 flags := []string{"-cipher", test.ciphersDefault}
2193 if len(test.ciphersTLS10) > 0 {
2194 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2195 }
2196 if len(test.ciphersTLS11) > 0 {
2197 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2198 }
2199
2200 testCases = append(testCases, testCase{
2201 testType: serverTest,
2202 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2203 config: Config{
2204 MaxVersion: version,
2205 MinVersion: version,
2206 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2207 },
2208 flags: flags,
2209 expectedCipher: expectedCipherSuite,
2210 })
2211 }
2212 }
Adam Langley95c29f32014-06-20 12:00:00 -07002213}
2214
2215func addBadECDSASignatureTests() {
2216 for badR := BadValue(1); badR < NumBadValues; badR++ {
2217 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002218 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002219 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2220 config: Config{
2221 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2222 Certificates: []Certificate{getECDSACertificate()},
2223 Bugs: ProtocolBugs{
2224 BadECDSAR: badR,
2225 BadECDSAS: badS,
2226 },
2227 },
2228 shouldFail: true,
2229 expectedError: "SIGNATURE",
2230 })
2231 }
2232 }
2233}
2234
Adam Langley80842bd2014-06-20 12:00:00 -07002235func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002236 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002237 name: "MaxCBCPadding",
2238 config: Config{
2239 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2240 Bugs: ProtocolBugs{
2241 MaxPadding: true,
2242 },
2243 },
2244 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2245 })
David Benjamin025b3d32014-07-01 19:53:04 -04002246 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002247 name: "BadCBCPadding",
2248 config: Config{
2249 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2250 Bugs: ProtocolBugs{
2251 PaddingFirstByteBad: true,
2252 },
2253 },
2254 shouldFail: true,
2255 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2256 })
2257 // OpenSSL previously had an issue where the first byte of padding in
2258 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002259 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002260 name: "BadCBCPadding255",
2261 config: Config{
2262 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2263 Bugs: ProtocolBugs{
2264 MaxPadding: true,
2265 PaddingFirstByteBadIf255: true,
2266 },
2267 },
2268 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2269 shouldFail: true,
2270 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2271 })
2272}
2273
Kenny Root7fdeaf12014-08-05 15:23:37 -07002274func addCBCSplittingTests() {
2275 testCases = append(testCases, testCase{
2276 name: "CBCRecordSplitting",
2277 config: Config{
2278 MaxVersion: VersionTLS10,
2279 MinVersion: VersionTLS10,
2280 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2281 },
David Benjaminac8302a2015-09-01 17:18:15 -04002282 messageLen: -1, // read until EOF
2283 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002284 flags: []string{
2285 "-async",
2286 "-write-different-record-sizes",
2287 "-cbc-record-splitting",
2288 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002289 })
2290 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002291 name: "CBCRecordSplittingPartialWrite",
2292 config: Config{
2293 MaxVersion: VersionTLS10,
2294 MinVersion: VersionTLS10,
2295 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2296 },
2297 messageLen: -1, // read until EOF
2298 flags: []string{
2299 "-async",
2300 "-write-different-record-sizes",
2301 "-cbc-record-splitting",
2302 "-partial-write",
2303 },
2304 })
2305}
2306
David Benjamin636293b2014-07-08 17:59:18 -04002307func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002308 // Add a dummy cert pool to stress certificate authority parsing.
2309 // TODO(davidben): Add tests that those values parse out correctly.
2310 certPool := x509.NewCertPool()
2311 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2312 if err != nil {
2313 panic(err)
2314 }
2315 certPool.AddCert(cert)
2316
David Benjamin636293b2014-07-08 17:59:18 -04002317 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002318 testCases = append(testCases, testCase{
2319 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002320 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002321 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002322 MinVersion: ver.version,
2323 MaxVersion: ver.version,
2324 ClientAuth: RequireAnyClientCert,
2325 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002326 },
2327 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002328 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2329 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002330 },
2331 })
2332 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002333 testType: serverTest,
2334 name: ver.name + "-Server-ClientAuth-RSA",
2335 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002336 MinVersion: ver.version,
2337 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002338 Certificates: []Certificate{rsaCertificate},
2339 },
2340 flags: []string{"-require-any-client-certificate"},
2341 })
David Benjamine098ec22014-08-27 23:13:20 -04002342 if ver.version != VersionSSL30 {
2343 testCases = append(testCases, testCase{
2344 testType: serverTest,
2345 name: ver.name + "-Server-ClientAuth-ECDSA",
2346 config: Config{
2347 MinVersion: ver.version,
2348 MaxVersion: ver.version,
2349 Certificates: []Certificate{ecdsaCertificate},
2350 },
2351 flags: []string{"-require-any-client-certificate"},
2352 })
2353 testCases = append(testCases, testCase{
2354 testType: clientTest,
2355 name: ver.name + "-Client-ClientAuth-ECDSA",
2356 config: Config{
2357 MinVersion: ver.version,
2358 MaxVersion: ver.version,
2359 ClientAuth: RequireAnyClientCert,
2360 ClientCAs: certPool,
2361 },
2362 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002363 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2364 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002365 },
2366 })
2367 }
David Benjamin636293b2014-07-08 17:59:18 -04002368 }
2369}
2370
Adam Langley75712922014-10-10 16:23:43 -07002371func addExtendedMasterSecretTests() {
2372 const expectEMSFlag = "-expect-extended-master-secret"
2373
2374 for _, with := range []bool{false, true} {
2375 prefix := "No"
2376 var flags []string
2377 if with {
2378 prefix = ""
2379 flags = []string{expectEMSFlag}
2380 }
2381
2382 for _, isClient := range []bool{false, true} {
2383 suffix := "-Server"
2384 testType := serverTest
2385 if isClient {
2386 suffix = "-Client"
2387 testType = clientTest
2388 }
2389
2390 for _, ver := range tlsVersions {
2391 test := testCase{
2392 testType: testType,
2393 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2394 config: Config{
2395 MinVersion: ver.version,
2396 MaxVersion: ver.version,
2397 Bugs: ProtocolBugs{
2398 NoExtendedMasterSecret: !with,
2399 RequireExtendedMasterSecret: with,
2400 },
2401 },
David Benjamin48cae082014-10-27 01:06:24 -04002402 flags: flags,
2403 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002404 }
2405 if test.shouldFail {
2406 test.expectedLocalError = "extended master secret required but not supported by peer"
2407 }
2408 testCases = append(testCases, test)
2409 }
2410 }
2411 }
2412
Adam Langleyba5934b2015-06-02 10:50:35 -07002413 for _, isClient := range []bool{false, true} {
2414 for _, supportedInFirstConnection := range []bool{false, true} {
2415 for _, supportedInResumeConnection := range []bool{false, true} {
2416 boolToWord := func(b bool) string {
2417 if b {
2418 return "Yes"
2419 }
2420 return "No"
2421 }
2422 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2423 if isClient {
2424 suffix += "Client"
2425 } else {
2426 suffix += "Server"
2427 }
2428
2429 supportedConfig := Config{
2430 Bugs: ProtocolBugs{
2431 RequireExtendedMasterSecret: true,
2432 },
2433 }
2434
2435 noSupportConfig := Config{
2436 Bugs: ProtocolBugs{
2437 NoExtendedMasterSecret: true,
2438 },
2439 }
2440
2441 test := testCase{
2442 name: "ExtendedMasterSecret-" + suffix,
2443 resumeSession: true,
2444 }
2445
2446 if !isClient {
2447 test.testType = serverTest
2448 }
2449
2450 if supportedInFirstConnection {
2451 test.config = supportedConfig
2452 } else {
2453 test.config = noSupportConfig
2454 }
2455
2456 if supportedInResumeConnection {
2457 test.resumeConfig = &supportedConfig
2458 } else {
2459 test.resumeConfig = &noSupportConfig
2460 }
2461
2462 switch suffix {
2463 case "YesToYes-Client", "YesToYes-Server":
2464 // When a session is resumed, it should
2465 // still be aware that its master
2466 // secret was generated via EMS and
2467 // thus it's safe to use tls-unique.
2468 test.flags = []string{expectEMSFlag}
2469 case "NoToYes-Server":
2470 // If an original connection did not
2471 // contain EMS, but a resumption
2472 // handshake does, then a server should
2473 // not resume the session.
2474 test.expectResumeRejected = true
2475 case "YesToNo-Server":
2476 // Resuming an EMS session without the
2477 // EMS extension should cause the
2478 // server to abort the connection.
2479 test.shouldFail = true
2480 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2481 case "NoToYes-Client":
2482 // A client should abort a connection
2483 // where the server resumed a non-EMS
2484 // session but echoed the EMS
2485 // extension.
2486 test.shouldFail = true
2487 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2488 case "YesToNo-Client":
2489 // A client should abort a connection
2490 // where the server didn't echo EMS
2491 // when the session used it.
2492 test.shouldFail = true
2493 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2494 }
2495
2496 testCases = append(testCases, test)
2497 }
2498 }
2499 }
Adam Langley75712922014-10-10 16:23:43 -07002500}
2501
David Benjamin43ec06f2014-08-05 02:28:57 -04002502// Adds tests that try to cover the range of the handshake state machine, under
2503// various conditions. Some of these are redundant with other tests, but they
2504// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002505func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002506 var tests []testCase
2507
2508 // Basic handshake, with resumption. Client and server,
2509 // session ID and session ticket.
2510 tests = append(tests, testCase{
2511 name: "Basic-Client",
2512 resumeSession: true,
2513 })
2514 tests = append(tests, testCase{
2515 name: "Basic-Client-RenewTicket",
2516 config: Config{
2517 Bugs: ProtocolBugs{
2518 RenewTicketOnResume: true,
2519 },
2520 },
David Benjaminba4594a2015-06-18 18:36:15 -04002521 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002522 resumeSession: true,
2523 })
2524 tests = append(tests, testCase{
2525 name: "Basic-Client-NoTicket",
2526 config: Config{
2527 SessionTicketsDisabled: true,
2528 },
2529 resumeSession: true,
2530 })
2531 tests = append(tests, testCase{
2532 name: "Basic-Client-Implicit",
2533 flags: []string{"-implicit-handshake"},
2534 resumeSession: true,
2535 })
2536 tests = append(tests, testCase{
2537 testType: serverTest,
2538 name: "Basic-Server",
2539 resumeSession: true,
2540 })
2541 tests = append(tests, testCase{
2542 testType: serverTest,
2543 name: "Basic-Server-NoTickets",
2544 config: Config{
2545 SessionTicketsDisabled: true,
2546 },
2547 resumeSession: true,
2548 })
2549 tests = append(tests, testCase{
2550 testType: serverTest,
2551 name: "Basic-Server-Implicit",
2552 flags: []string{"-implicit-handshake"},
2553 resumeSession: true,
2554 })
2555 tests = append(tests, testCase{
2556 testType: serverTest,
2557 name: "Basic-Server-EarlyCallback",
2558 flags: []string{"-use-early-callback"},
2559 resumeSession: true,
2560 })
2561
2562 // TLS client auth.
2563 tests = append(tests, testCase{
2564 testType: clientTest,
2565 name: "ClientAuth-Client",
2566 config: Config{
2567 ClientAuth: RequireAnyClientCert,
2568 },
2569 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002570 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2571 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002572 },
2573 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002574 if async {
2575 tests = append(tests, testCase{
2576 testType: clientTest,
2577 name: "ClientAuth-Client-AsyncKey",
2578 config: Config{
2579 ClientAuth: RequireAnyClientCert,
2580 },
2581 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002582 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2583 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002584 "-use-async-private-key",
2585 },
2586 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002587 tests = append(tests, testCase{
2588 testType: serverTest,
2589 name: "Basic-Server-RSAAsyncKey",
2590 flags: []string{
2591 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2592 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2593 "-use-async-private-key",
2594 },
2595 })
2596 tests = append(tests, testCase{
2597 testType: serverTest,
2598 name: "Basic-Server-ECDSAAsyncKey",
2599 flags: []string{
2600 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2601 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2602 "-use-async-private-key",
2603 },
2604 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002605 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002606 tests = append(tests, testCase{
2607 testType: serverTest,
2608 name: "ClientAuth-Server",
2609 config: Config{
2610 Certificates: []Certificate{rsaCertificate},
2611 },
2612 flags: []string{"-require-any-client-certificate"},
2613 })
2614
2615 // No session ticket support; server doesn't send NewSessionTicket.
2616 tests = append(tests, testCase{
2617 name: "SessionTicketsDisabled-Client",
2618 config: Config{
2619 SessionTicketsDisabled: true,
2620 },
2621 })
2622 tests = append(tests, testCase{
2623 testType: serverTest,
2624 name: "SessionTicketsDisabled-Server",
2625 config: Config{
2626 SessionTicketsDisabled: true,
2627 },
2628 })
2629
2630 // Skip ServerKeyExchange in PSK key exchange if there's no
2631 // identity hint.
2632 tests = append(tests, testCase{
2633 name: "EmptyPSKHint-Client",
2634 config: Config{
2635 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2636 PreSharedKey: []byte("secret"),
2637 },
2638 flags: []string{"-psk", "secret"},
2639 })
2640 tests = append(tests, testCase{
2641 testType: serverTest,
2642 name: "EmptyPSKHint-Server",
2643 config: Config{
2644 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2645 PreSharedKey: []byte("secret"),
2646 },
2647 flags: []string{"-psk", "secret"},
2648 })
2649
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002650 tests = append(tests, testCase{
2651 testType: clientTest,
2652 name: "OCSPStapling-Client",
2653 flags: []string{
2654 "-enable-ocsp-stapling",
2655 "-expect-ocsp-response",
2656 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002657 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002658 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002659 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002660 })
2661
2662 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002663 testType: serverTest,
2664 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002665 expectedOCSPResponse: testOCSPResponse,
2666 flags: []string{
2667 "-ocsp-response",
2668 base64.StdEncoding.EncodeToString(testOCSPResponse),
2669 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002670 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002671 })
2672
Paul Lietar8f1c2682015-08-18 12:21:54 +01002673 tests = append(tests, testCase{
2674 testType: clientTest,
2675 name: "CertificateVerificationSucceed",
2676 flags: []string{
2677 "-verify-peer",
2678 },
2679 })
2680
2681 tests = append(tests, testCase{
2682 testType: clientTest,
2683 name: "CertificateVerificationFail",
2684 flags: []string{
2685 "-verify-fail",
2686 "-verify-peer",
2687 },
2688 shouldFail: true,
2689 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2690 })
2691
2692 tests = append(tests, testCase{
2693 testType: clientTest,
2694 name: "CertificateVerificationSoftFail",
2695 flags: []string{
2696 "-verify-fail",
2697 "-expect-verify-result",
2698 },
2699 })
2700
David Benjamin760b1dd2015-05-15 23:33:48 -04002701 if protocol == tls {
2702 tests = append(tests, testCase{
2703 name: "Renegotiate-Client",
2704 renegotiate: true,
2705 })
2706 // NPN on client and server; results in post-handshake message.
2707 tests = append(tests, testCase{
2708 name: "NPN-Client",
2709 config: Config{
2710 NextProtos: []string{"foo"},
2711 },
2712 flags: []string{"-select-next-proto", "foo"},
2713 expectedNextProto: "foo",
2714 expectedNextProtoType: npn,
2715 })
2716 tests = append(tests, testCase{
2717 testType: serverTest,
2718 name: "NPN-Server",
2719 config: Config{
2720 NextProtos: []string{"bar"},
2721 },
2722 flags: []string{
2723 "-advertise-npn", "\x03foo\x03bar\x03baz",
2724 "-expect-next-proto", "bar",
2725 },
2726 expectedNextProto: "bar",
2727 expectedNextProtoType: npn,
2728 })
2729
2730 // TODO(davidben): Add tests for when False Start doesn't trigger.
2731
2732 // Client does False Start and negotiates NPN.
2733 tests = append(tests, testCase{
2734 name: "FalseStart",
2735 config: Config{
2736 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2737 NextProtos: []string{"foo"},
2738 Bugs: ProtocolBugs{
2739 ExpectFalseStart: true,
2740 },
2741 },
2742 flags: []string{
2743 "-false-start",
2744 "-select-next-proto", "foo",
2745 },
2746 shimWritesFirst: true,
2747 resumeSession: true,
2748 })
2749
2750 // Client does False Start and negotiates ALPN.
2751 tests = append(tests, testCase{
2752 name: "FalseStart-ALPN",
2753 config: Config{
2754 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2755 NextProtos: []string{"foo"},
2756 Bugs: ProtocolBugs{
2757 ExpectFalseStart: true,
2758 },
2759 },
2760 flags: []string{
2761 "-false-start",
2762 "-advertise-alpn", "\x03foo",
2763 },
2764 shimWritesFirst: true,
2765 resumeSession: true,
2766 })
2767
2768 // Client does False Start but doesn't explicitly call
2769 // SSL_connect.
2770 tests = append(tests, testCase{
2771 name: "FalseStart-Implicit",
2772 config: Config{
2773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2774 NextProtos: []string{"foo"},
2775 },
2776 flags: []string{
2777 "-implicit-handshake",
2778 "-false-start",
2779 "-advertise-alpn", "\x03foo",
2780 },
2781 })
2782
2783 // False Start without session tickets.
2784 tests = append(tests, testCase{
2785 name: "FalseStart-SessionTicketsDisabled",
2786 config: Config{
2787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2788 NextProtos: []string{"foo"},
2789 SessionTicketsDisabled: true,
2790 Bugs: ProtocolBugs{
2791 ExpectFalseStart: true,
2792 },
2793 },
2794 flags: []string{
2795 "-false-start",
2796 "-select-next-proto", "foo",
2797 },
2798 shimWritesFirst: true,
2799 })
2800
2801 // Server parses a V2ClientHello.
2802 tests = append(tests, testCase{
2803 testType: serverTest,
2804 name: "SendV2ClientHello",
2805 config: Config{
2806 // Choose a cipher suite that does not involve
2807 // elliptic curves, so no extensions are
2808 // involved.
2809 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2810 Bugs: ProtocolBugs{
2811 SendV2ClientHello: true,
2812 },
2813 },
2814 })
2815
2816 // Client sends a Channel ID.
2817 tests = append(tests, testCase{
2818 name: "ChannelID-Client",
2819 config: Config{
2820 RequestChannelID: true,
2821 },
Adam Langley7c803a62015-06-15 15:35:05 -07002822 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002823 resumeSession: true,
2824 expectChannelID: true,
2825 })
2826
2827 // Server accepts a Channel ID.
2828 tests = append(tests, testCase{
2829 testType: serverTest,
2830 name: "ChannelID-Server",
2831 config: Config{
2832 ChannelID: channelIDKey,
2833 },
2834 flags: []string{
2835 "-expect-channel-id",
2836 base64.StdEncoding.EncodeToString(channelIDBytes),
2837 },
2838 resumeSession: true,
2839 expectChannelID: true,
2840 })
David Benjamin30789da2015-08-29 22:56:45 -04002841
2842 // Bidirectional shutdown with the runner initiating.
2843 tests = append(tests, testCase{
2844 name: "Shutdown-Runner",
2845 config: Config{
2846 Bugs: ProtocolBugs{
2847 ExpectCloseNotify: true,
2848 },
2849 },
2850 flags: []string{"-check-close-notify"},
2851 })
2852
2853 // Bidirectional shutdown with the shim initiating. The runner,
2854 // in the meantime, sends garbage before the close_notify which
2855 // the shim must ignore.
2856 tests = append(tests, testCase{
2857 name: "Shutdown-Shim",
2858 config: Config{
2859 Bugs: ProtocolBugs{
2860 ExpectCloseNotify: true,
2861 },
2862 },
2863 shimShutsDown: true,
2864 sendEmptyRecords: 1,
2865 sendWarningAlerts: 1,
2866 flags: []string{"-check-close-notify"},
2867 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002868 } else {
2869 tests = append(tests, testCase{
2870 name: "SkipHelloVerifyRequest",
2871 config: Config{
2872 Bugs: ProtocolBugs{
2873 SkipHelloVerifyRequest: true,
2874 },
2875 },
2876 })
2877 }
2878
David Benjamin43ec06f2014-08-05 02:28:57 -04002879 var suffix string
2880 var flags []string
2881 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002882 if protocol == dtls {
2883 suffix = "-DTLS"
2884 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002885 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002886 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002887 flags = append(flags, "-async")
2888 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002889 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002890 }
2891 if splitHandshake {
2892 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002893 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002894 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002895 for _, test := range tests {
2896 test.protocol = protocol
2897 test.name += suffix
2898 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2899 test.flags = append(test.flags, flags...)
2900 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002901 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002902}
2903
Adam Langley524e7172015-02-20 16:04:00 -08002904func addDDoSCallbackTests() {
2905 // DDoS callback.
2906
2907 for _, resume := range []bool{false, true} {
2908 suffix := "Resume"
2909 if resume {
2910 suffix = "No" + suffix
2911 }
2912
2913 testCases = append(testCases, testCase{
2914 testType: serverTest,
2915 name: "Server-DDoS-OK-" + suffix,
2916 flags: []string{"-install-ddos-callback"},
2917 resumeSession: resume,
2918 })
2919
2920 failFlag := "-fail-ddos-callback"
2921 if resume {
2922 failFlag = "-fail-second-ddos-callback"
2923 }
2924 testCases = append(testCases, testCase{
2925 testType: serverTest,
2926 name: "Server-DDoS-Reject-" + suffix,
2927 flags: []string{"-install-ddos-callback", failFlag},
2928 resumeSession: resume,
2929 shouldFail: true,
2930 expectedError: ":CONNECTION_REJECTED:",
2931 })
2932 }
2933}
2934
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002935func addVersionNegotiationTests() {
2936 for i, shimVers := range tlsVersions {
2937 // Assemble flags to disable all newer versions on the shim.
2938 var flags []string
2939 for _, vers := range tlsVersions[i+1:] {
2940 flags = append(flags, vers.flag)
2941 }
2942
2943 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002944 protocols := []protocol{tls}
2945 if runnerVers.hasDTLS && shimVers.hasDTLS {
2946 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002947 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002948 for _, protocol := range protocols {
2949 expectedVersion := shimVers.version
2950 if runnerVers.version < shimVers.version {
2951 expectedVersion = runnerVers.version
2952 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002953
David Benjamin8b8c0062014-11-23 02:47:52 -05002954 suffix := shimVers.name + "-" + runnerVers.name
2955 if protocol == dtls {
2956 suffix += "-DTLS"
2957 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002958
David Benjamin1eb367c2014-12-12 18:17:51 -05002959 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2960
David Benjamin1e29a6b2014-12-10 02:27:24 -05002961 clientVers := shimVers.version
2962 if clientVers > VersionTLS10 {
2963 clientVers = VersionTLS10
2964 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002965 testCases = append(testCases, testCase{
2966 protocol: protocol,
2967 testType: clientTest,
2968 name: "VersionNegotiation-Client-" + suffix,
2969 config: Config{
2970 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002971 Bugs: ProtocolBugs{
2972 ExpectInitialRecordVersion: clientVers,
2973 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002974 },
2975 flags: flags,
2976 expectedVersion: expectedVersion,
2977 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002978 testCases = append(testCases, testCase{
2979 protocol: protocol,
2980 testType: clientTest,
2981 name: "VersionNegotiation-Client2-" + suffix,
2982 config: Config{
2983 MaxVersion: runnerVers.version,
2984 Bugs: ProtocolBugs{
2985 ExpectInitialRecordVersion: clientVers,
2986 },
2987 },
2988 flags: []string{"-max-version", shimVersFlag},
2989 expectedVersion: expectedVersion,
2990 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002991
2992 testCases = append(testCases, testCase{
2993 protocol: protocol,
2994 testType: serverTest,
2995 name: "VersionNegotiation-Server-" + suffix,
2996 config: Config{
2997 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002998 Bugs: ProtocolBugs{
2999 ExpectInitialRecordVersion: expectedVersion,
3000 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003001 },
3002 flags: flags,
3003 expectedVersion: expectedVersion,
3004 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003005 testCases = append(testCases, testCase{
3006 protocol: protocol,
3007 testType: serverTest,
3008 name: "VersionNegotiation-Server2-" + suffix,
3009 config: Config{
3010 MaxVersion: runnerVers.version,
3011 Bugs: ProtocolBugs{
3012 ExpectInitialRecordVersion: expectedVersion,
3013 },
3014 },
3015 flags: []string{"-max-version", shimVersFlag},
3016 expectedVersion: expectedVersion,
3017 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003018 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003019 }
3020 }
3021}
3022
David Benjaminaccb4542014-12-12 23:44:33 -05003023func addMinimumVersionTests() {
3024 for i, shimVers := range tlsVersions {
3025 // Assemble flags to disable all older versions on the shim.
3026 var flags []string
3027 for _, vers := range tlsVersions[:i] {
3028 flags = append(flags, vers.flag)
3029 }
3030
3031 for _, runnerVers := range tlsVersions {
3032 protocols := []protocol{tls}
3033 if runnerVers.hasDTLS && shimVers.hasDTLS {
3034 protocols = append(protocols, dtls)
3035 }
3036 for _, protocol := range protocols {
3037 suffix := shimVers.name + "-" + runnerVers.name
3038 if protocol == dtls {
3039 suffix += "-DTLS"
3040 }
3041 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3042
David Benjaminaccb4542014-12-12 23:44:33 -05003043 var expectedVersion uint16
3044 var shouldFail bool
3045 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003046 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003047 if runnerVers.version >= shimVers.version {
3048 expectedVersion = runnerVers.version
3049 } else {
3050 shouldFail = true
3051 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003052 if runnerVers.version > VersionSSL30 {
3053 expectedLocalError = "remote error: protocol version not supported"
3054 } else {
3055 expectedLocalError = "remote error: handshake failure"
3056 }
David Benjaminaccb4542014-12-12 23:44:33 -05003057 }
3058
3059 testCases = append(testCases, testCase{
3060 protocol: protocol,
3061 testType: clientTest,
3062 name: "MinimumVersion-Client-" + suffix,
3063 config: Config{
3064 MaxVersion: runnerVers.version,
3065 },
David Benjamin87909c02014-12-13 01:55:01 -05003066 flags: flags,
3067 expectedVersion: expectedVersion,
3068 shouldFail: shouldFail,
3069 expectedError: expectedError,
3070 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003071 })
3072 testCases = append(testCases, testCase{
3073 protocol: protocol,
3074 testType: clientTest,
3075 name: "MinimumVersion-Client2-" + suffix,
3076 config: Config{
3077 MaxVersion: runnerVers.version,
3078 },
David Benjamin87909c02014-12-13 01:55:01 -05003079 flags: []string{"-min-version", shimVersFlag},
3080 expectedVersion: expectedVersion,
3081 shouldFail: shouldFail,
3082 expectedError: expectedError,
3083 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003084 })
3085
3086 testCases = append(testCases, testCase{
3087 protocol: protocol,
3088 testType: serverTest,
3089 name: "MinimumVersion-Server-" + suffix,
3090 config: Config{
3091 MaxVersion: runnerVers.version,
3092 },
David Benjamin87909c02014-12-13 01:55:01 -05003093 flags: flags,
3094 expectedVersion: expectedVersion,
3095 shouldFail: shouldFail,
3096 expectedError: expectedError,
3097 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003098 })
3099 testCases = append(testCases, testCase{
3100 protocol: protocol,
3101 testType: serverTest,
3102 name: "MinimumVersion-Server2-" + suffix,
3103 config: Config{
3104 MaxVersion: runnerVers.version,
3105 },
David Benjamin87909c02014-12-13 01:55:01 -05003106 flags: []string{"-min-version", shimVersFlag},
3107 expectedVersion: expectedVersion,
3108 shouldFail: shouldFail,
3109 expectedError: expectedError,
3110 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003111 })
3112 }
3113 }
3114 }
3115}
3116
David Benjamin5c24a1d2014-08-31 00:59:27 -04003117func addD5BugTests() {
3118 testCases = append(testCases, testCase{
3119 testType: serverTest,
3120 name: "D5Bug-NoQuirk-Reject",
3121 config: Config{
3122 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3123 Bugs: ProtocolBugs{
3124 SSL3RSAKeyExchange: true,
3125 },
3126 },
3127 shouldFail: true,
3128 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3129 })
3130 testCases = append(testCases, testCase{
3131 testType: serverTest,
3132 name: "D5Bug-Quirk-Normal",
3133 config: Config{
3134 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3135 },
3136 flags: []string{"-tls-d5-bug"},
3137 })
3138 testCases = append(testCases, testCase{
3139 testType: serverTest,
3140 name: "D5Bug-Quirk-Bug",
3141 config: Config{
3142 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3143 Bugs: ProtocolBugs{
3144 SSL3RSAKeyExchange: true,
3145 },
3146 },
3147 flags: []string{"-tls-d5-bug"},
3148 })
3149}
3150
David Benjamine78bfde2014-09-06 12:45:15 -04003151func addExtensionTests() {
3152 testCases = append(testCases, testCase{
3153 testType: clientTest,
3154 name: "DuplicateExtensionClient",
3155 config: Config{
3156 Bugs: ProtocolBugs{
3157 DuplicateExtension: true,
3158 },
3159 },
3160 shouldFail: true,
3161 expectedLocalError: "remote error: error decoding message",
3162 })
3163 testCases = append(testCases, testCase{
3164 testType: serverTest,
3165 name: "DuplicateExtensionServer",
3166 config: Config{
3167 Bugs: ProtocolBugs{
3168 DuplicateExtension: true,
3169 },
3170 },
3171 shouldFail: true,
3172 expectedLocalError: "remote error: error decoding message",
3173 })
3174 testCases = append(testCases, testCase{
3175 testType: clientTest,
3176 name: "ServerNameExtensionClient",
3177 config: Config{
3178 Bugs: ProtocolBugs{
3179 ExpectServerName: "example.com",
3180 },
3181 },
3182 flags: []string{"-host-name", "example.com"},
3183 })
3184 testCases = append(testCases, testCase{
3185 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003186 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003187 config: Config{
3188 Bugs: ProtocolBugs{
3189 ExpectServerName: "mismatch.com",
3190 },
3191 },
3192 flags: []string{"-host-name", "example.com"},
3193 shouldFail: true,
3194 expectedLocalError: "tls: unexpected server name",
3195 })
3196 testCases = append(testCases, testCase{
3197 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003198 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003199 config: Config{
3200 Bugs: ProtocolBugs{
3201 ExpectServerName: "missing.com",
3202 },
3203 },
3204 shouldFail: true,
3205 expectedLocalError: "tls: unexpected server name",
3206 })
3207 testCases = append(testCases, testCase{
3208 testType: serverTest,
3209 name: "ServerNameExtensionServer",
3210 config: Config{
3211 ServerName: "example.com",
3212 },
3213 flags: []string{"-expect-server-name", "example.com"},
3214 resumeSession: true,
3215 })
David Benjaminae2888f2014-09-06 12:58:58 -04003216 testCases = append(testCases, testCase{
3217 testType: clientTest,
3218 name: "ALPNClient",
3219 config: Config{
3220 NextProtos: []string{"foo"},
3221 },
3222 flags: []string{
3223 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3224 "-expect-alpn", "foo",
3225 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003226 expectedNextProto: "foo",
3227 expectedNextProtoType: alpn,
3228 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003229 })
3230 testCases = append(testCases, testCase{
3231 testType: serverTest,
3232 name: "ALPNServer",
3233 config: Config{
3234 NextProtos: []string{"foo", "bar", "baz"},
3235 },
3236 flags: []string{
3237 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3238 "-select-alpn", "foo",
3239 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003240 expectedNextProto: "foo",
3241 expectedNextProtoType: alpn,
3242 resumeSession: true,
3243 })
3244 // Test that the server prefers ALPN over NPN.
3245 testCases = append(testCases, testCase{
3246 testType: serverTest,
3247 name: "ALPNServer-Preferred",
3248 config: Config{
3249 NextProtos: []string{"foo", "bar", "baz"},
3250 },
3251 flags: []string{
3252 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3253 "-select-alpn", "foo",
3254 "-advertise-npn", "\x03foo\x03bar\x03baz",
3255 },
3256 expectedNextProto: "foo",
3257 expectedNextProtoType: alpn,
3258 resumeSession: true,
3259 })
3260 testCases = append(testCases, testCase{
3261 testType: serverTest,
3262 name: "ALPNServer-Preferred-Swapped",
3263 config: Config{
3264 NextProtos: []string{"foo", "bar", "baz"},
3265 Bugs: ProtocolBugs{
3266 SwapNPNAndALPN: true,
3267 },
3268 },
3269 flags: []string{
3270 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3271 "-select-alpn", "foo",
3272 "-advertise-npn", "\x03foo\x03bar\x03baz",
3273 },
3274 expectedNextProto: "foo",
3275 expectedNextProtoType: alpn,
3276 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003277 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003278 var emptyString string
3279 testCases = append(testCases, testCase{
3280 testType: clientTest,
3281 name: "ALPNClient-EmptyProtocolName",
3282 config: Config{
3283 NextProtos: []string{""},
3284 Bugs: ProtocolBugs{
3285 // A server returning an empty ALPN protocol
3286 // should be rejected.
3287 ALPNProtocol: &emptyString,
3288 },
3289 },
3290 flags: []string{
3291 "-advertise-alpn", "\x03foo",
3292 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003293 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003294 expectedError: ":PARSE_TLSEXT:",
3295 })
3296 testCases = append(testCases, testCase{
3297 testType: serverTest,
3298 name: "ALPNServer-EmptyProtocolName",
3299 config: Config{
3300 // A ClientHello containing an empty ALPN protocol
3301 // should be rejected.
3302 NextProtos: []string{"foo", "", "baz"},
3303 },
3304 flags: []string{
3305 "-select-alpn", "foo",
3306 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003307 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003308 expectedError: ":PARSE_TLSEXT:",
3309 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003310 // Test that negotiating both NPN and ALPN is forbidden.
3311 testCases = append(testCases, testCase{
3312 name: "NegotiateALPNAndNPN",
3313 config: Config{
3314 NextProtos: []string{"foo", "bar", "baz"},
3315 Bugs: ProtocolBugs{
3316 NegotiateALPNAndNPN: true,
3317 },
3318 },
3319 flags: []string{
3320 "-advertise-alpn", "\x03foo",
3321 "-select-next-proto", "foo",
3322 },
3323 shouldFail: true,
3324 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3325 })
3326 testCases = append(testCases, testCase{
3327 name: "NegotiateALPNAndNPN-Swapped",
3328 config: Config{
3329 NextProtos: []string{"foo", "bar", "baz"},
3330 Bugs: ProtocolBugs{
3331 NegotiateALPNAndNPN: true,
3332 SwapNPNAndALPN: true,
3333 },
3334 },
3335 flags: []string{
3336 "-advertise-alpn", "\x03foo",
3337 "-select-next-proto", "foo",
3338 },
3339 shouldFail: true,
3340 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3341 })
Adam Langley38311732014-10-16 19:04:35 -07003342 // Resume with a corrupt ticket.
3343 testCases = append(testCases, testCase{
3344 testType: serverTest,
3345 name: "CorruptTicket",
3346 config: Config{
3347 Bugs: ProtocolBugs{
3348 CorruptTicket: true,
3349 },
3350 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003351 resumeSession: true,
3352 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003353 })
David Benjamind98452d2015-06-16 14:16:23 -04003354 // Test the ticket callback, with and without renewal.
3355 testCases = append(testCases, testCase{
3356 testType: serverTest,
3357 name: "TicketCallback",
3358 resumeSession: true,
3359 flags: []string{"-use-ticket-callback"},
3360 })
3361 testCases = append(testCases, testCase{
3362 testType: serverTest,
3363 name: "TicketCallback-Renew",
3364 config: Config{
3365 Bugs: ProtocolBugs{
3366 ExpectNewTicket: true,
3367 },
3368 },
3369 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3370 resumeSession: true,
3371 })
Adam Langley38311732014-10-16 19:04:35 -07003372 // Resume with an oversized session id.
3373 testCases = append(testCases, testCase{
3374 testType: serverTest,
3375 name: "OversizedSessionId",
3376 config: Config{
3377 Bugs: ProtocolBugs{
3378 OversizedSessionId: true,
3379 },
3380 },
3381 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003382 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003383 expectedError: ":DECODE_ERROR:",
3384 })
David Benjaminca6c8262014-11-15 19:06:08 -05003385 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3386 // are ignored.
3387 testCases = append(testCases, testCase{
3388 protocol: dtls,
3389 name: "SRTP-Client",
3390 config: Config{
3391 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3392 },
3393 flags: []string{
3394 "-srtp-profiles",
3395 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3396 },
3397 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3398 })
3399 testCases = append(testCases, testCase{
3400 protocol: dtls,
3401 testType: serverTest,
3402 name: "SRTP-Server",
3403 config: Config{
3404 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3405 },
3406 flags: []string{
3407 "-srtp-profiles",
3408 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3409 },
3410 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3411 })
3412 // Test that the MKI is ignored.
3413 testCases = append(testCases, testCase{
3414 protocol: dtls,
3415 testType: serverTest,
3416 name: "SRTP-Server-IgnoreMKI",
3417 config: Config{
3418 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3419 Bugs: ProtocolBugs{
3420 SRTPMasterKeyIdentifer: "bogus",
3421 },
3422 },
3423 flags: []string{
3424 "-srtp-profiles",
3425 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3426 },
3427 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3428 })
3429 // Test that SRTP isn't negotiated on the server if there were
3430 // no matching profiles.
3431 testCases = append(testCases, testCase{
3432 protocol: dtls,
3433 testType: serverTest,
3434 name: "SRTP-Server-NoMatch",
3435 config: Config{
3436 SRTPProtectionProfiles: []uint16{100, 101, 102},
3437 },
3438 flags: []string{
3439 "-srtp-profiles",
3440 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3441 },
3442 expectedSRTPProtectionProfile: 0,
3443 })
3444 // Test that the server returning an invalid SRTP profile is
3445 // flagged as an error by the client.
3446 testCases = append(testCases, testCase{
3447 protocol: dtls,
3448 name: "SRTP-Client-NoMatch",
3449 config: Config{
3450 Bugs: ProtocolBugs{
3451 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3452 },
3453 },
3454 flags: []string{
3455 "-srtp-profiles",
3456 "SRTP_AES128_CM_SHA1_80",
3457 },
3458 shouldFail: true,
3459 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3460 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003461 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003462 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003463 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003464 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003465 flags: []string{
3466 "-enable-signed-cert-timestamps",
3467 "-expect-signed-cert-timestamps",
3468 base64.StdEncoding.EncodeToString(testSCTList),
3469 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003470 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003471 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003472 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003473 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003474 testType: serverTest,
3475 flags: []string{
3476 "-signed-cert-timestamps",
3477 base64.StdEncoding.EncodeToString(testSCTList),
3478 },
3479 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003480 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003481 })
3482 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003483 testType: clientTest,
3484 name: "ClientHelloPadding",
3485 config: Config{
3486 Bugs: ProtocolBugs{
3487 RequireClientHelloSize: 512,
3488 },
3489 },
3490 // This hostname just needs to be long enough to push the
3491 // ClientHello into F5's danger zone between 256 and 511 bytes
3492 // long.
3493 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3494 })
David Benjamine78bfde2014-09-06 12:45:15 -04003495}
3496
David Benjamin01fe8202014-09-24 15:21:44 -04003497func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003498 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003499 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003500 protocols := []protocol{tls}
3501 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3502 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003503 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003504 for _, protocol := range protocols {
3505 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3506 if protocol == dtls {
3507 suffix += "-DTLS"
3508 }
3509
David Benjaminece3de92015-03-16 18:02:20 -04003510 if sessionVers.version == resumeVers.version {
3511 testCases = append(testCases, testCase{
3512 protocol: protocol,
3513 name: "Resume-Client" + suffix,
3514 resumeSession: true,
3515 config: Config{
3516 MaxVersion: sessionVers.version,
3517 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003518 },
David Benjaminece3de92015-03-16 18:02:20 -04003519 expectedVersion: sessionVers.version,
3520 expectedResumeVersion: resumeVers.version,
3521 })
3522 } else {
3523 testCases = append(testCases, testCase{
3524 protocol: protocol,
3525 name: "Resume-Client-Mismatch" + suffix,
3526 resumeSession: true,
3527 config: Config{
3528 MaxVersion: sessionVers.version,
3529 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003530 },
David Benjaminece3de92015-03-16 18:02:20 -04003531 expectedVersion: sessionVers.version,
3532 resumeConfig: &Config{
3533 MaxVersion: resumeVers.version,
3534 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3535 Bugs: ProtocolBugs{
3536 AllowSessionVersionMismatch: true,
3537 },
3538 },
3539 expectedResumeVersion: resumeVers.version,
3540 shouldFail: true,
3541 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3542 })
3543 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003544
3545 testCases = append(testCases, testCase{
3546 protocol: protocol,
3547 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003548 resumeSession: true,
3549 config: Config{
3550 MaxVersion: sessionVers.version,
3551 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3552 },
3553 expectedVersion: sessionVers.version,
3554 resumeConfig: &Config{
3555 MaxVersion: resumeVers.version,
3556 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3557 },
3558 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003559 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003560 expectedResumeVersion: resumeVers.version,
3561 })
3562
David Benjamin8b8c0062014-11-23 02:47:52 -05003563 testCases = append(testCases, testCase{
3564 protocol: protocol,
3565 testType: serverTest,
3566 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003567 resumeSession: true,
3568 config: Config{
3569 MaxVersion: sessionVers.version,
3570 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3571 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003572 expectedVersion: sessionVers.version,
3573 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003574 resumeConfig: &Config{
3575 MaxVersion: resumeVers.version,
3576 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3577 },
3578 expectedResumeVersion: resumeVers.version,
3579 })
3580 }
David Benjamin01fe8202014-09-24 15:21:44 -04003581 }
3582 }
David Benjaminece3de92015-03-16 18:02:20 -04003583
3584 testCases = append(testCases, testCase{
3585 name: "Resume-Client-CipherMismatch",
3586 resumeSession: true,
3587 config: Config{
3588 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3589 },
3590 resumeConfig: &Config{
3591 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3592 Bugs: ProtocolBugs{
3593 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3594 },
3595 },
3596 shouldFail: true,
3597 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3598 })
David Benjamin01fe8202014-09-24 15:21:44 -04003599}
3600
Adam Langley2ae77d22014-10-28 17:29:33 -07003601func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003602 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003603 testCases = append(testCases, testCase{
3604 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003605 name: "Renegotiate-Server-Forbidden",
David Benjaminb16346b2015-04-08 19:16:58 -04003606 renegotiate: true,
3607 flags: []string{"-reject-peer-renegotiations"},
3608 shouldFail: true,
3609 expectedError: ":NO_RENEGOTIATION:",
3610 expectedLocalError: "remote error: no renegotiation",
3611 })
Adam Langley5021b222015-06-12 18:27:58 -07003612 // The server shouldn't echo the renegotiation extension unless
3613 // requested by the client.
3614 testCases = append(testCases, testCase{
3615 testType: serverTest,
3616 name: "Renegotiate-Server-NoExt",
3617 config: Config{
3618 Bugs: ProtocolBugs{
3619 NoRenegotiationInfo: true,
3620 RequireRenegotiationInfo: true,
3621 },
3622 },
3623 shouldFail: true,
3624 expectedLocalError: "renegotiation extension missing",
3625 })
3626 // The renegotiation SCSV should be sufficient for the server to echo
3627 // the extension.
3628 testCases = append(testCases, testCase{
3629 testType: serverTest,
3630 name: "Renegotiate-Server-NoExt-SCSV",
3631 config: Config{
3632 Bugs: ProtocolBugs{
3633 NoRenegotiationInfo: true,
3634 SendRenegotiationSCSV: true,
3635 RequireRenegotiationInfo: true,
3636 },
3637 },
3638 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003639 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003640 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003641 config: Config{
3642 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003643 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003644 },
3645 },
3646 renegotiate: true,
3647 })
3648 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003649 name: "Renegotiate-Client-EmptyExt",
3650 renegotiate: true,
3651 config: Config{
3652 Bugs: ProtocolBugs{
3653 EmptyRenegotiationInfo: true,
3654 },
3655 },
3656 shouldFail: true,
3657 expectedError: ":RENEGOTIATION_MISMATCH:",
3658 })
3659 testCases = append(testCases, testCase{
3660 name: "Renegotiate-Client-BadExt",
3661 renegotiate: true,
3662 config: Config{
3663 Bugs: ProtocolBugs{
3664 BadRenegotiationInfo: true,
3665 },
3666 },
3667 shouldFail: true,
3668 expectedError: ":RENEGOTIATION_MISMATCH:",
3669 })
3670 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003671 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003672 config: Config{
3673 Bugs: ProtocolBugs{
3674 NoRenegotiationInfo: true,
3675 },
3676 },
3677 shouldFail: true,
3678 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3679 flags: []string{"-no-legacy-server-connect"},
3680 })
3681 testCases = append(testCases, testCase{
3682 name: "Renegotiate-Client-NoExt-Allowed",
3683 renegotiate: true,
3684 config: Config{
3685 Bugs: ProtocolBugs{
3686 NoRenegotiationInfo: true,
3687 },
3688 },
3689 })
3690 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003691 name: "Renegotiate-Client-SwitchCiphers",
3692 renegotiate: true,
3693 config: Config{
3694 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3695 },
3696 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3697 })
3698 testCases = append(testCases, testCase{
3699 name: "Renegotiate-Client-SwitchCiphers2",
3700 renegotiate: true,
3701 config: Config{
3702 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3703 },
3704 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3705 })
David Benjaminc44b1df2014-11-23 12:11:01 -05003706 testCases = append(testCases, testCase{
David Benjaminb16346b2015-04-08 19:16:58 -04003707 name: "Renegotiate-Client-Forbidden",
3708 renegotiate: true,
3709 flags: []string{"-reject-peer-renegotiations"},
3710 shouldFail: true,
3711 expectedError: ":NO_RENEGOTIATION:",
3712 expectedLocalError: "remote error: no renegotiation",
3713 })
3714 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003715 name: "Renegotiate-SameClientVersion",
3716 renegotiate: true,
3717 config: Config{
3718 MaxVersion: VersionTLS10,
3719 Bugs: ProtocolBugs{
3720 RequireSameRenegoClientVersion: true,
3721 },
3722 },
3723 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003724 testCases = append(testCases, testCase{
3725 name: "Renegotiate-FalseStart",
3726 renegotiate: true,
3727 config: Config{
3728 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3729 NextProtos: []string{"foo"},
3730 },
3731 flags: []string{
3732 "-false-start",
3733 "-select-next-proto", "foo",
3734 },
3735 shimWritesFirst: true,
3736 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003737}
3738
David Benjamin5e961c12014-11-07 01:48:35 -05003739func addDTLSReplayTests() {
3740 // Test that sequence number replays are detected.
3741 testCases = append(testCases, testCase{
3742 protocol: dtls,
3743 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003744 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003745 replayWrites: true,
3746 })
3747
David Benjamin8e6db492015-07-25 18:29:23 -04003748 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003749 // than the retransmit window.
3750 testCases = append(testCases, testCase{
3751 protocol: dtls,
3752 name: "DTLS-Replay-LargeGaps",
3753 config: Config{
3754 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003755 SequenceNumberMapping: func(in uint64) uint64 {
3756 return in * 127
3757 },
David Benjamin5e961c12014-11-07 01:48:35 -05003758 },
3759 },
David Benjamin8e6db492015-07-25 18:29:23 -04003760 messageCount: 200,
3761 replayWrites: true,
3762 })
3763
3764 // Test the incoming sequence number changing non-monotonically.
3765 testCases = append(testCases, testCase{
3766 protocol: dtls,
3767 name: "DTLS-Replay-NonMonotonic",
3768 config: Config{
3769 Bugs: ProtocolBugs{
3770 SequenceNumberMapping: func(in uint64) uint64 {
3771 return in ^ 31
3772 },
3773 },
3774 },
3775 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003776 replayWrites: true,
3777 })
3778}
3779
David Benjamin000800a2014-11-14 01:43:59 -05003780var testHashes = []struct {
3781 name string
3782 id uint8
3783}{
3784 {"SHA1", hashSHA1},
3785 {"SHA224", hashSHA224},
3786 {"SHA256", hashSHA256},
3787 {"SHA384", hashSHA384},
3788 {"SHA512", hashSHA512},
3789}
3790
3791func addSigningHashTests() {
3792 // Make sure each hash works. Include some fake hashes in the list and
3793 // ensure they're ignored.
3794 for _, hash := range testHashes {
3795 testCases = append(testCases, testCase{
3796 name: "SigningHash-ClientAuth-" + hash.name,
3797 config: Config{
3798 ClientAuth: RequireAnyClientCert,
3799 SignatureAndHashes: []signatureAndHash{
3800 {signatureRSA, 42},
3801 {signatureRSA, hash.id},
3802 {signatureRSA, 255},
3803 },
3804 },
3805 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003806 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3807 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003808 },
3809 })
3810
3811 testCases = append(testCases, testCase{
3812 testType: serverTest,
3813 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3814 config: Config{
3815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3816 SignatureAndHashes: []signatureAndHash{
3817 {signatureRSA, 42},
3818 {signatureRSA, hash.id},
3819 {signatureRSA, 255},
3820 },
3821 },
3822 })
3823 }
3824
3825 // Test that hash resolution takes the signature type into account.
3826 testCases = append(testCases, testCase{
3827 name: "SigningHash-ClientAuth-SignatureType",
3828 config: Config{
3829 ClientAuth: RequireAnyClientCert,
3830 SignatureAndHashes: []signatureAndHash{
3831 {signatureECDSA, hashSHA512},
3832 {signatureRSA, hashSHA384},
3833 {signatureECDSA, hashSHA1},
3834 },
3835 },
3836 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003837 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3838 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003839 },
3840 })
3841
3842 testCases = append(testCases, testCase{
3843 testType: serverTest,
3844 name: "SigningHash-ServerKeyExchange-SignatureType",
3845 config: Config{
3846 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3847 SignatureAndHashes: []signatureAndHash{
3848 {signatureECDSA, hashSHA512},
3849 {signatureRSA, hashSHA384},
3850 {signatureECDSA, hashSHA1},
3851 },
3852 },
3853 })
3854
3855 // Test that, if the list is missing, the peer falls back to SHA-1.
3856 testCases = append(testCases, testCase{
3857 name: "SigningHash-ClientAuth-Fallback",
3858 config: Config{
3859 ClientAuth: RequireAnyClientCert,
3860 SignatureAndHashes: []signatureAndHash{
3861 {signatureRSA, hashSHA1},
3862 },
3863 Bugs: ProtocolBugs{
3864 NoSignatureAndHashes: true,
3865 },
3866 },
3867 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003868 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3869 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003870 },
3871 })
3872
3873 testCases = append(testCases, testCase{
3874 testType: serverTest,
3875 name: "SigningHash-ServerKeyExchange-Fallback",
3876 config: Config{
3877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3878 SignatureAndHashes: []signatureAndHash{
3879 {signatureRSA, hashSHA1},
3880 },
3881 Bugs: ProtocolBugs{
3882 NoSignatureAndHashes: true,
3883 },
3884 },
3885 })
David Benjamin72dc7832015-03-16 17:49:43 -04003886
3887 // Test that hash preferences are enforced. BoringSSL defaults to
3888 // rejecting MD5 signatures.
3889 testCases = append(testCases, testCase{
3890 testType: serverTest,
3891 name: "SigningHash-ClientAuth-Enforced",
3892 config: Config{
3893 Certificates: []Certificate{rsaCertificate},
3894 SignatureAndHashes: []signatureAndHash{
3895 {signatureRSA, hashMD5},
3896 // Advertise SHA-1 so the handshake will
3897 // proceed, but the shim's preferences will be
3898 // ignored in CertificateVerify generation, so
3899 // MD5 will be chosen.
3900 {signatureRSA, hashSHA1},
3901 },
3902 Bugs: ProtocolBugs{
3903 IgnorePeerSignatureAlgorithmPreferences: true,
3904 },
3905 },
3906 flags: []string{"-require-any-client-certificate"},
3907 shouldFail: true,
3908 expectedError: ":WRONG_SIGNATURE_TYPE:",
3909 })
3910
3911 testCases = append(testCases, testCase{
3912 name: "SigningHash-ServerKeyExchange-Enforced",
3913 config: Config{
3914 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3915 SignatureAndHashes: []signatureAndHash{
3916 {signatureRSA, hashMD5},
3917 },
3918 Bugs: ProtocolBugs{
3919 IgnorePeerSignatureAlgorithmPreferences: true,
3920 },
3921 },
3922 shouldFail: true,
3923 expectedError: ":WRONG_SIGNATURE_TYPE:",
3924 })
Steven Valdez0d62f262015-09-04 12:41:04 -04003925
3926 // Test that the agreed upon digest respects the client preferences and
3927 // the server digests.
3928 testCases = append(testCases, testCase{
3929 name: "Agree-Digest-Fallback",
3930 config: Config{
3931 ClientAuth: RequireAnyClientCert,
3932 SignatureAndHashes: []signatureAndHash{
3933 {signatureRSA, hashSHA512},
3934 {signatureRSA, hashSHA1},
3935 },
3936 },
3937 flags: []string{
3938 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3939 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3940 },
3941 digestPrefs: "SHA256",
3942 expectedClientCertSignatureHash: hashSHA1,
3943 })
3944 testCases = append(testCases, testCase{
3945 name: "Agree-Digest-SHA256",
3946 config: Config{
3947 ClientAuth: RequireAnyClientCert,
3948 SignatureAndHashes: []signatureAndHash{
3949 {signatureRSA, hashSHA1},
3950 {signatureRSA, hashSHA256},
3951 },
3952 },
3953 flags: []string{
3954 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3955 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3956 },
3957 digestPrefs: "SHA256,SHA1",
3958 expectedClientCertSignatureHash: hashSHA256,
3959 })
3960 testCases = append(testCases, testCase{
3961 name: "Agree-Digest-SHA1",
3962 config: Config{
3963 ClientAuth: RequireAnyClientCert,
3964 SignatureAndHashes: []signatureAndHash{
3965 {signatureRSA, hashSHA1},
3966 },
3967 },
3968 flags: []string{
3969 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3970 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3971 },
3972 digestPrefs: "SHA512,SHA256,SHA1",
3973 expectedClientCertSignatureHash: hashSHA1,
3974 })
3975 testCases = append(testCases, testCase{
3976 name: "Agree-Digest-Default",
3977 config: Config{
3978 ClientAuth: RequireAnyClientCert,
3979 SignatureAndHashes: []signatureAndHash{
3980 {signatureRSA, hashSHA256},
3981 {signatureECDSA, hashSHA256},
3982 {signatureRSA, hashSHA1},
3983 {signatureECDSA, hashSHA1},
3984 },
3985 },
3986 flags: []string{
3987 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3988 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3989 },
3990 expectedClientCertSignatureHash: hashSHA256,
3991 })
David Benjamin000800a2014-11-14 01:43:59 -05003992}
3993
David Benjamin83f90402015-01-27 01:09:43 -05003994// timeouts is the retransmit schedule for BoringSSL. It doubles and
3995// caps at 60 seconds. On the 13th timeout, it gives up.
3996var timeouts = []time.Duration{
3997 1 * time.Second,
3998 2 * time.Second,
3999 4 * time.Second,
4000 8 * time.Second,
4001 16 * time.Second,
4002 32 * time.Second,
4003 60 * time.Second,
4004 60 * time.Second,
4005 60 * time.Second,
4006 60 * time.Second,
4007 60 * time.Second,
4008 60 * time.Second,
4009 60 * time.Second,
4010}
4011
4012func addDTLSRetransmitTests() {
4013 // Test that this is indeed the timeout schedule. Stress all
4014 // four patterns of handshake.
4015 for i := 1; i < len(timeouts); i++ {
4016 number := strconv.Itoa(i)
4017 testCases = append(testCases, testCase{
4018 protocol: dtls,
4019 name: "DTLS-Retransmit-Client-" + number,
4020 config: Config{
4021 Bugs: ProtocolBugs{
4022 TimeoutSchedule: timeouts[:i],
4023 },
4024 },
4025 resumeSession: true,
4026 flags: []string{"-async"},
4027 })
4028 testCases = append(testCases, testCase{
4029 protocol: dtls,
4030 testType: serverTest,
4031 name: "DTLS-Retransmit-Server-" + number,
4032 config: Config{
4033 Bugs: ProtocolBugs{
4034 TimeoutSchedule: timeouts[:i],
4035 },
4036 },
4037 resumeSession: true,
4038 flags: []string{"-async"},
4039 })
4040 }
4041
4042 // Test that exceeding the timeout schedule hits a read
4043 // timeout.
4044 testCases = append(testCases, testCase{
4045 protocol: dtls,
4046 name: "DTLS-Retransmit-Timeout",
4047 config: Config{
4048 Bugs: ProtocolBugs{
4049 TimeoutSchedule: timeouts,
4050 },
4051 },
4052 resumeSession: true,
4053 flags: []string{"-async"},
4054 shouldFail: true,
4055 expectedError: ":READ_TIMEOUT_EXPIRED:",
4056 })
4057
4058 // Test that timeout handling has a fudge factor, due to API
4059 // problems.
4060 testCases = append(testCases, testCase{
4061 protocol: dtls,
4062 name: "DTLS-Retransmit-Fudge",
4063 config: Config{
4064 Bugs: ProtocolBugs{
4065 TimeoutSchedule: []time.Duration{
4066 timeouts[0] - 10*time.Millisecond,
4067 },
4068 },
4069 },
4070 resumeSession: true,
4071 flags: []string{"-async"},
4072 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004073
4074 // Test that the final Finished retransmitting isn't
4075 // duplicated if the peer badly fragments everything.
4076 testCases = append(testCases, testCase{
4077 testType: serverTest,
4078 protocol: dtls,
4079 name: "DTLS-Retransmit-Fragmented",
4080 config: Config{
4081 Bugs: ProtocolBugs{
4082 TimeoutSchedule: []time.Duration{timeouts[0]},
4083 MaxHandshakeRecordLength: 2,
4084 },
4085 },
4086 flags: []string{"-async"},
4087 })
David Benjamin83f90402015-01-27 01:09:43 -05004088}
4089
David Benjaminc565ebb2015-04-03 04:06:36 -04004090func addExportKeyingMaterialTests() {
4091 for _, vers := range tlsVersions {
4092 if vers.version == VersionSSL30 {
4093 continue
4094 }
4095 testCases = append(testCases, testCase{
4096 name: "ExportKeyingMaterial-" + vers.name,
4097 config: Config{
4098 MaxVersion: vers.version,
4099 },
4100 exportKeyingMaterial: 1024,
4101 exportLabel: "label",
4102 exportContext: "context",
4103 useExportContext: true,
4104 })
4105 testCases = append(testCases, testCase{
4106 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4107 config: Config{
4108 MaxVersion: vers.version,
4109 },
4110 exportKeyingMaterial: 1024,
4111 })
4112 testCases = append(testCases, testCase{
4113 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4114 config: Config{
4115 MaxVersion: vers.version,
4116 },
4117 exportKeyingMaterial: 1024,
4118 useExportContext: true,
4119 })
4120 testCases = append(testCases, testCase{
4121 name: "ExportKeyingMaterial-Small-" + vers.name,
4122 config: Config{
4123 MaxVersion: vers.version,
4124 },
4125 exportKeyingMaterial: 1,
4126 exportLabel: "label",
4127 exportContext: "context",
4128 useExportContext: true,
4129 })
4130 }
4131 testCases = append(testCases, testCase{
4132 name: "ExportKeyingMaterial-SSL3",
4133 config: Config{
4134 MaxVersion: VersionSSL30,
4135 },
4136 exportKeyingMaterial: 1024,
4137 exportLabel: "label",
4138 exportContext: "context",
4139 useExportContext: true,
4140 shouldFail: true,
4141 expectedError: "failed to export keying material",
4142 })
4143}
4144
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004145func addTLSUniqueTests() {
4146 for _, isClient := range []bool{false, true} {
4147 for _, isResumption := range []bool{false, true} {
4148 for _, hasEMS := range []bool{false, true} {
4149 var suffix string
4150 if isResumption {
4151 suffix = "Resume-"
4152 } else {
4153 suffix = "Full-"
4154 }
4155
4156 if hasEMS {
4157 suffix += "EMS-"
4158 } else {
4159 suffix += "NoEMS-"
4160 }
4161
4162 if isClient {
4163 suffix += "Client"
4164 } else {
4165 suffix += "Server"
4166 }
4167
4168 test := testCase{
4169 name: "TLSUnique-" + suffix,
4170 testTLSUnique: true,
4171 config: Config{
4172 Bugs: ProtocolBugs{
4173 NoExtendedMasterSecret: !hasEMS,
4174 },
4175 },
4176 }
4177
4178 if isResumption {
4179 test.resumeSession = true
4180 test.resumeConfig = &Config{
4181 Bugs: ProtocolBugs{
4182 NoExtendedMasterSecret: !hasEMS,
4183 },
4184 }
4185 }
4186
4187 if isResumption && !hasEMS {
4188 test.shouldFail = true
4189 test.expectedError = "failed to get tls-unique"
4190 }
4191
4192 testCases = append(testCases, test)
4193 }
4194 }
4195 }
4196}
4197
Adam Langley09505632015-07-30 18:10:13 -07004198func addCustomExtensionTests() {
4199 expectedContents := "custom extension"
4200 emptyString := ""
4201
4202 for _, isClient := range []bool{false, true} {
4203 suffix := "Server"
4204 flag := "-enable-server-custom-extension"
4205 testType := serverTest
4206 if isClient {
4207 suffix = "Client"
4208 flag = "-enable-client-custom-extension"
4209 testType = clientTest
4210 }
4211
4212 testCases = append(testCases, testCase{
4213 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004214 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004215 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004216 Bugs: ProtocolBugs{
4217 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004218 ExpectedCustomExtension: &expectedContents,
4219 },
4220 },
4221 flags: []string{flag},
4222 })
4223
4224 // If the parse callback fails, the handshake should also fail.
4225 testCases = append(testCases, testCase{
4226 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004227 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004228 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004229 Bugs: ProtocolBugs{
4230 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004231 ExpectedCustomExtension: &expectedContents,
4232 },
4233 },
David Benjamin399e7c92015-07-30 23:01:27 -04004234 flags: []string{flag},
4235 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004236 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4237 })
4238
4239 // If the add callback fails, the handshake should also fail.
4240 testCases = append(testCases, testCase{
4241 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004242 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004243 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004244 Bugs: ProtocolBugs{
4245 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004246 ExpectedCustomExtension: &expectedContents,
4247 },
4248 },
David Benjamin399e7c92015-07-30 23:01:27 -04004249 flags: []string{flag, "-custom-extension-fail-add"},
4250 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004251 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4252 })
4253
4254 // If the add callback returns zero, no extension should be
4255 // added.
4256 skipCustomExtension := expectedContents
4257 if isClient {
4258 // For the case where the client skips sending the
4259 // custom extension, the server must not “echo” it.
4260 skipCustomExtension = ""
4261 }
4262 testCases = append(testCases, testCase{
4263 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004264 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004265 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004266 Bugs: ProtocolBugs{
4267 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004268 ExpectedCustomExtension: &emptyString,
4269 },
4270 },
4271 flags: []string{flag, "-custom-extension-skip"},
4272 })
4273 }
4274
4275 // The custom extension add callback should not be called if the client
4276 // doesn't send the extension.
4277 testCases = append(testCases, testCase{
4278 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004279 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004280 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004281 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004282 ExpectedCustomExtension: &emptyString,
4283 },
4284 },
4285 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4286 })
Adam Langley2deb9842015-08-07 11:15:37 -07004287
4288 // Test an unknown extension from the server.
4289 testCases = append(testCases, testCase{
4290 testType: clientTest,
4291 name: "UnknownExtension-Client",
4292 config: Config{
4293 Bugs: ProtocolBugs{
4294 CustomExtension: expectedContents,
4295 },
4296 },
4297 shouldFail: true,
4298 expectedError: ":UNEXPECTED_EXTENSION:",
4299 })
Adam Langley09505632015-07-30 18:10:13 -07004300}
4301
Adam Langley7c803a62015-06-15 15:35:05 -07004302func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004303 defer wg.Done()
4304
4305 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004306 var err error
4307
4308 if *mallocTest < 0 {
4309 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004310 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004311 } else {
4312 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4313 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004314 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004315 if err != nil {
4316 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4317 }
4318 break
4319 }
4320 }
4321 }
Adam Langley95c29f32014-06-20 12:00:00 -07004322 statusChan <- statusMsg{test: test, err: err}
4323 }
4324}
4325
4326type statusMsg struct {
4327 test *testCase
4328 started bool
4329 err error
4330}
4331
David Benjamin5f237bc2015-02-11 17:14:15 -05004332func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004333 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004334
David Benjamin5f237bc2015-02-11 17:14:15 -05004335 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004336 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004337 if !*pipe {
4338 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004339 var erase string
4340 for i := 0; i < lineLen; i++ {
4341 erase += "\b \b"
4342 }
4343 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004344 }
4345
Adam Langley95c29f32014-06-20 12:00:00 -07004346 if msg.started {
4347 started++
4348 } else {
4349 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004350
4351 if msg.err != nil {
4352 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4353 failed++
4354 testOutput.addResult(msg.test.name, "FAIL")
4355 } else {
4356 if *pipe {
4357 // Print each test instead of a status line.
4358 fmt.Printf("PASSED (%s)\n", msg.test.name)
4359 }
4360 testOutput.addResult(msg.test.name, "PASS")
4361 }
Adam Langley95c29f32014-06-20 12:00:00 -07004362 }
4363
David Benjamin5f237bc2015-02-11 17:14:15 -05004364 if !*pipe {
4365 // Print a new status line.
4366 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4367 lineLen = len(line)
4368 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004369 }
Adam Langley95c29f32014-06-20 12:00:00 -07004370 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004371
4372 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004373}
4374
4375func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004376 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004377 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004378
Adam Langley7c803a62015-06-15 15:35:05 -07004379 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004380 addCipherSuiteTests()
4381 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004382 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004383 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004384 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004385 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004386 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004387 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004388 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004389 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004390 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004391 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004392 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004393 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004394 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004395 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004396 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004397 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004398 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004399 for _, async := range []bool{false, true} {
4400 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004401 for _, protocol := range []protocol{tls, dtls} {
4402 addStateMachineCoverageTests(async, splitHandshake, protocol)
4403 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004404 }
4405 }
Adam Langley95c29f32014-06-20 12:00:00 -07004406
4407 var wg sync.WaitGroup
4408
Adam Langley7c803a62015-06-15 15:35:05 -07004409 statusChan := make(chan statusMsg, *numWorkers)
4410 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004411 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004412
David Benjamin025b3d32014-07-01 19:53:04 -04004413 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004414
Adam Langley7c803a62015-06-15 15:35:05 -07004415 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004416 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004417 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004418 }
4419
David Benjamin025b3d32014-07-01 19:53:04 -04004420 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004421 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004422 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004423 }
4424 }
4425
4426 close(testChan)
4427 wg.Wait()
4428 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004429 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004430
4431 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004432
4433 if *jsonOutput != "" {
4434 if err := testOutput.writeTo(*jsonOutput); err != nil {
4435 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4436 }
4437 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004438
4439 if !testOutput.allPassed {
4440 os.Exit(1)
4441 }
Adam Langley95c29f32014-06-20 12:00:00 -07004442}