blob: ed37b773a0a47e9ac536b39b943addc69d020b2d [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 Benjaminc7ce9772015-10-09 19:32:41 -0400152 // expectNoNextProto, if true, means that no next protocol should be
153 // negotiated.
154 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400155 // expectedNextProtoType, if non-zero, is the expected next
156 // protocol negotiation mechanism.
157 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500158 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
159 // should be negotiated. If zero, none should be negotiated.
160 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100161 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
162 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100163 // expectedSCTList, if not nil, is the expected SCT list to be received.
164 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400165 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
166 // hash function that the client should have used when signing the
167 // handshake with a client certificate.
168 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700169 // messageLen is the length, in bytes, of the test message that will be
170 // sent.
171 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400172 // messageCount is the number of test messages that will be sent.
173 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400174 // digestPrefs is the list of digest preferences from the client.
175 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400176 // certFile is the path to the certificate to use for the server.
177 certFile string
178 // keyFile is the path to the private key to use for the server.
179 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400180 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400181 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400182 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700183 // expectResumeRejected, if true, specifies that the attempted
184 // resumption must be rejected by the client. This is only valid for a
185 // serverTest.
186 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400187 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500188 // resumption. Unless newSessionsOnResume is set,
189 // SessionTicketKey, ServerSessionCache, and
190 // ClientSessionCache are copied from the initial connection's
191 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400192 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500193 // newSessionsOnResume, if true, will cause resumeConfig to
194 // use a different session resumption context.
195 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400196 // noSessionCache, if true, will cause the server to run without a
197 // session cache.
198 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400199 // sendPrefix sends a prefix on the socket before actually performing a
200 // handshake.
201 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400202 // shimWritesFirst controls whether the shim sends an initial "hello"
203 // message before doing a roundtrip with the runner.
204 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400205 // shimShutsDown, if true, runs a test where the shim shuts down the
206 // connection immediately after the handshake rather than echoing
207 // messages from the runner.
208 shimShutsDown bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700209 // renegotiate indicates the the connection should be renegotiated
210 // during the exchange.
211 renegotiate bool
212 // renegotiateCiphers is a list of ciphersuite ids that will be
213 // switched in just before renegotiation.
214 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500215 // replayWrites, if true, configures the underlying transport
216 // to replay every write it makes in DTLS tests.
217 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500218 // damageFirstWrite, if true, configures the underlying transport to
219 // damage the final byte of the first application data write.
220 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400221 // exportKeyingMaterial, if non-zero, configures the test to exchange
222 // keying material and verify they match.
223 exportKeyingMaterial int
224 exportLabel string
225 exportContext string
226 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400227 // flags, if not empty, contains a list of command-line flags that will
228 // be passed to the shim program.
229 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700230 // testTLSUnique, if true, causes the shim to send the tls-unique value
231 // which will be compared against the expected value.
232 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400233 // sendEmptyRecords is the number of consecutive empty records to send
234 // before and after the test message.
235 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400236 // sendWarningAlerts is the number of consecutive warning alerts to send
237 // before and after the test message.
238 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400239 // expectMessageDropped, if true, means the test message is expected to
240 // be dropped by the client rather than echoed back.
241 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700242}
243
Adam Langley7c803a62015-06-15 15:35:05 -0700244var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700245
David Benjamin8e6db492015-07-25 18:29:23 -0400246func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -0500247 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500248 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500249 if *flagDebug {
250 connDebug = &recordingConn{Conn: conn}
251 conn = connDebug
252 defer func() {
253 connDebug.WriteTo(os.Stdout)
254 }()
255 }
256
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500258 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
259 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500260 if test.replayWrites {
261 conn = newReplayAdaptor(conn)
262 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400263 }
264
David Benjamin5fa3eba2015-01-22 16:35:40 -0500265 if test.damageFirstWrite {
266 connDamage = newDamageAdaptor(conn)
267 conn = connDamage
268 }
269
David Benjamin6fd297b2014-08-11 18:43:38 -0400270 if test.sendPrefix != "" {
271 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
272 return err
273 }
David Benjamin98e882e2014-08-08 13:24:34 -0400274 }
275
David Benjamin1d5c83e2014-07-22 19:20:02 -0400276 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400277 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400278 if test.protocol == dtls {
279 tlsConn = DTLSServer(conn, config)
280 } else {
281 tlsConn = Server(conn, config)
282 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400283 } else {
284 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400285 if test.protocol == dtls {
286 tlsConn = DTLSClient(conn, config)
287 } else {
288 tlsConn = Client(conn, config)
289 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400290 }
David Benjamin30789da2015-08-29 22:56:45 -0400291 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400292
Adam Langley95c29f32014-06-20 12:00:00 -0700293 if err := tlsConn.Handshake(); err != nil {
294 return err
295 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700296
David Benjamin01fe8202014-09-24 15:21:44 -0400297 // TODO(davidben): move all per-connection expectations into a dedicated
298 // expectations struct that can be specified separately for the two
299 // legs.
300 expectedVersion := test.expectedVersion
301 if isResume && test.expectedResumeVersion != 0 {
302 expectedVersion = test.expectedResumeVersion
303 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700304 connState := tlsConn.ConnectionState()
305 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400306 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400307 }
308
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700309 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400310 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
311 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700312 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
313 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
314 }
David Benjamin90da8c82015-04-20 14:57:57 -0400315
David Benjamina08e49d2014-08-24 01:46:07 -0400316 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700317 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400318 if channelID == nil {
319 return fmt.Errorf("no channel ID negotiated")
320 }
321 if channelID.Curve != channelIDKey.Curve ||
322 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
323 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
324 return fmt.Errorf("incorrect channel ID")
325 }
326 }
327
David Benjaminae2888f2014-09-06 12:58:58 -0400328 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700329 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400330 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
331 }
332 }
333
David Benjaminc7ce9772015-10-09 19:32:41 -0400334 if test.expectNoNextProto {
335 if actual := connState.NegotiatedProtocol; actual != "" {
336 return fmt.Errorf("got unexpected next proto %s", actual)
337 }
338 }
339
David Benjaminfc7b0862014-09-06 13:21:53 -0400340 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700341 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400342 return fmt.Errorf("next proto type mismatch")
343 }
344 }
345
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700346 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500347 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
348 }
349
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100350 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
351 return fmt.Errorf("OCSP Response mismatch")
352 }
353
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
355 return fmt.Errorf("SCT list mismatch")
356 }
357
Steven Valdez0d62f262015-09-04 12:41:04 -0400358 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
359 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
360 }
361
David Benjaminc565ebb2015-04-03 04:06:36 -0400362 if test.exportKeyingMaterial > 0 {
363 actual := make([]byte, test.exportKeyingMaterial)
364 if _, err := io.ReadFull(tlsConn, actual); err != nil {
365 return err
366 }
367 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
368 if err != nil {
369 return err
370 }
371 if !bytes.Equal(actual, expected) {
372 return fmt.Errorf("keying material mismatch")
373 }
374 }
375
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700376 if test.testTLSUnique {
377 var peersValue [12]byte
378 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
379 return err
380 }
381 expected := tlsConn.ConnectionState().TLSUnique
382 if !bytes.Equal(peersValue[:], expected) {
383 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
384 }
385 }
386
David Benjamine58c4f52014-08-24 03:47:07 -0400387 if test.shimWritesFirst {
388 var buf [5]byte
389 _, err := io.ReadFull(tlsConn, buf[:])
390 if err != nil {
391 return err
392 }
393 if string(buf[:]) != "hello" {
394 return fmt.Errorf("bad initial message")
395 }
396 }
397
David Benjamina8ebe222015-06-06 03:04:39 -0400398 for i := 0; i < test.sendEmptyRecords; i++ {
399 tlsConn.Write(nil)
400 }
401
David Benjamin24f346d2015-06-06 03:28:08 -0400402 for i := 0; i < test.sendWarningAlerts; i++ {
403 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
404 }
405
Adam Langleycf2d4f42014-10-28 19:06:14 -0700406 if test.renegotiate {
407 if test.renegotiateCiphers != nil {
408 config.CipherSuites = test.renegotiateCiphers
409 }
410 if err := tlsConn.Renegotiate(); err != nil {
411 return err
412 }
413 } else if test.renegotiateCiphers != nil {
414 panic("renegotiateCiphers without renegotiate")
415 }
416
David Benjamin5fa3eba2015-01-22 16:35:40 -0500417 if test.damageFirstWrite {
418 connDamage.setDamage(true)
419 tlsConn.Write([]byte("DAMAGED WRITE"))
420 connDamage.setDamage(false)
421 }
422
David Benjamin8e6db492015-07-25 18:29:23 -0400423 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700424 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400425 if test.protocol == dtls {
426 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
427 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700428 // Read until EOF.
429 _, err := io.Copy(ioutil.Discard, tlsConn)
430 return err
431 }
David Benjamin4417d052015-04-05 04:17:25 -0400432 if messageLen == 0 {
433 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700434 }
Adam Langley95c29f32014-06-20 12:00:00 -0700435
David Benjamin8e6db492015-07-25 18:29:23 -0400436 messageCount := test.messageCount
437 if messageCount == 0 {
438 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400439 }
440
David Benjamin8e6db492015-07-25 18:29:23 -0400441 for j := 0; j < messageCount; j++ {
442 testMessage := make([]byte, messageLen)
443 for i := range testMessage {
444 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 }
David Benjamin8e6db492015-07-25 18:29:23 -0400446 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700447
David Benjamin8e6db492015-07-25 18:29:23 -0400448 for i := 0; i < test.sendEmptyRecords; i++ {
449 tlsConn.Write(nil)
450 }
451
452 for i := 0; i < test.sendWarningAlerts; i++ {
453 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
454 }
455
David Benjamin4f75aaf2015-09-01 16:53:10 -0400456 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400457 // The shim will not respond.
458 continue
459 }
460
David Benjamin8e6db492015-07-25 18:29:23 -0400461 buf := make([]byte, len(testMessage))
462 if test.protocol == dtls {
463 bufTmp := make([]byte, len(buf)+1)
464 n, err := tlsConn.Read(bufTmp)
465 if err != nil {
466 return err
467 }
468 if n != len(buf) {
469 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
470 }
471 copy(buf, bufTmp)
472 } else {
473 _, err := io.ReadFull(tlsConn, buf)
474 if err != nil {
475 return err
476 }
477 }
478
479 for i, v := range buf {
480 if v != testMessage[i]^0xff {
481 return fmt.Errorf("bad reply contents at byte %d", i)
482 }
Adam Langley95c29f32014-06-20 12:00:00 -0700483 }
484 }
485
486 return nil
487}
488
David Benjamin325b5c32014-07-01 19:40:31 -0400489func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
490 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700491 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400492 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700493 }
David Benjamin325b5c32014-07-01 19:40:31 -0400494 valgrindArgs = append(valgrindArgs, path)
495 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700496
David Benjamin325b5c32014-07-01 19:40:31 -0400497 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700498}
499
David Benjamin325b5c32014-07-01 19:40:31 -0400500func gdbOf(path string, args ...string) *exec.Cmd {
501 xtermArgs := []string{"-e", "gdb", "--args"}
502 xtermArgs = append(xtermArgs, path)
503 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700504
David Benjamin325b5c32014-07-01 19:40:31 -0400505 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700506}
507
Adam Langley69a01602014-11-17 17:26:55 -0800508type moreMallocsError struct{}
509
510func (moreMallocsError) Error() string {
511 return "child process did not exhaust all allocation calls"
512}
513
514var errMoreMallocs = moreMallocsError{}
515
David Benjamin87c8a642015-02-21 01:54:29 -0500516// accept accepts a connection from listener, unless waitChan signals a process
517// exit first.
518func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
519 type connOrError struct {
520 conn net.Conn
521 err error
522 }
523 connChan := make(chan connOrError, 1)
524 go func() {
525 conn, err := listener.Accept()
526 connChan <- connOrError{conn, err}
527 close(connChan)
528 }()
529 select {
530 case result := <-connChan:
531 return result.conn, result.err
532 case childErr := <-waitChan:
533 waitChan <- childErr
534 return nil, fmt.Errorf("child exited early: %s", childErr)
535 }
536}
537
Adam Langley7c803a62015-06-15 15:35:05 -0700538func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700539 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
540 panic("Error expected without shouldFail in " + test.name)
541 }
542
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700543 if test.expectResumeRejected && !test.resumeSession {
544 panic("expectResumeRejected without resumeSession in " + test.name)
545 }
546
Steven Valdez0d62f262015-09-04 12:41:04 -0400547 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
548 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
549 }
550
David Benjamin87c8a642015-02-21 01:54:29 -0500551 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
552 if err != nil {
553 panic(err)
554 }
555 defer func() {
556 if listener != nil {
557 listener.Close()
558 }
559 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700560
David Benjamin87c8a642015-02-21 01:54:29 -0500561 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400562 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400563 flags = append(flags, "-server")
564
David Benjamin025b3d32014-07-01 19:53:04 -0400565 flags = append(flags, "-key-file")
566 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700567 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400568 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700569 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400570 }
571
572 flags = append(flags, "-cert-file")
573 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700574 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400575 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700576 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400577 }
578 }
David Benjamin5a593af2014-08-11 19:51:50 -0400579
Steven Valdez0d62f262015-09-04 12:41:04 -0400580 if test.digestPrefs != "" {
581 flags = append(flags, "-digest-prefs")
582 flags = append(flags, test.digestPrefs)
583 }
584
David Benjamin6fd297b2014-08-11 18:43:38 -0400585 if test.protocol == dtls {
586 flags = append(flags, "-dtls")
587 }
588
David Benjamin5a593af2014-08-11 19:51:50 -0400589 if test.resumeSession {
590 flags = append(flags, "-resume")
591 }
592
David Benjamine58c4f52014-08-24 03:47:07 -0400593 if test.shimWritesFirst {
594 flags = append(flags, "-shim-writes-first")
595 }
596
David Benjamin30789da2015-08-29 22:56:45 -0400597 if test.shimShutsDown {
598 flags = append(flags, "-shim-shuts-down")
599 }
600
David Benjaminc565ebb2015-04-03 04:06:36 -0400601 if test.exportKeyingMaterial > 0 {
602 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
603 flags = append(flags, "-export-label", test.exportLabel)
604 flags = append(flags, "-export-context", test.exportContext)
605 if test.useExportContext {
606 flags = append(flags, "-use-export-context")
607 }
608 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700609 if test.expectResumeRejected {
610 flags = append(flags, "-expect-session-miss")
611 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400612
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700613 if test.testTLSUnique {
614 flags = append(flags, "-tls-unique")
615 }
616
David Benjamin025b3d32014-07-01 19:53:04 -0400617 flags = append(flags, test.flags...)
618
619 var shim *exec.Cmd
620 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700621 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700622 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700623 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400624 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700625 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400626 }
David Benjamin025b3d32014-07-01 19:53:04 -0400627 shim.Stdin = os.Stdin
628 var stdoutBuf, stderrBuf bytes.Buffer
629 shim.Stdout = &stdoutBuf
630 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800631 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500632 shim.Env = os.Environ()
633 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800634 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400635 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800636 }
637 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
638 }
David Benjamin025b3d32014-07-01 19:53:04 -0400639
640 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700641 panic(err)
642 }
David Benjamin87c8a642015-02-21 01:54:29 -0500643 waitChan := make(chan error, 1)
644 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700645
646 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400647 if !test.noSessionCache {
648 config.ClientSessionCache = NewLRUClientSessionCache(1)
649 config.ServerSessionCache = NewLRUServerSessionCache(1)
650 }
David Benjamin025b3d32014-07-01 19:53:04 -0400651 if test.testType == clientTest {
652 if len(config.Certificates) == 0 {
653 config.Certificates = []Certificate{getRSACertificate()}
654 }
David Benjamin87c8a642015-02-21 01:54:29 -0500655 } else {
656 // Supply a ServerName to ensure a constant session cache key,
657 // rather than falling back to net.Conn.RemoteAddr.
658 if len(config.ServerName) == 0 {
659 config.ServerName = "test"
660 }
David Benjamin025b3d32014-07-01 19:53:04 -0400661 }
Adam Langley95c29f32014-06-20 12:00:00 -0700662
David Benjamin87c8a642015-02-21 01:54:29 -0500663 conn, err := acceptOrWait(listener, waitChan)
664 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400665 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500666 conn.Close()
667 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500668
David Benjamin1d5c83e2014-07-22 19:20:02 -0400669 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400670 var resumeConfig Config
671 if test.resumeConfig != nil {
672 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500673 if len(resumeConfig.ServerName) == 0 {
674 resumeConfig.ServerName = config.ServerName
675 }
David Benjamin01fe8202014-09-24 15:21:44 -0400676 if len(resumeConfig.Certificates) == 0 {
677 resumeConfig.Certificates = []Certificate{getRSACertificate()}
678 }
David Benjaminba4594a2015-06-18 18:36:15 -0400679 if test.newSessionsOnResume {
680 if !test.noSessionCache {
681 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
682 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
683 }
684 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500685 resumeConfig.SessionTicketKey = config.SessionTicketKey
686 resumeConfig.ClientSessionCache = config.ClientSessionCache
687 resumeConfig.ServerSessionCache = config.ServerSessionCache
688 }
David Benjamin01fe8202014-09-24 15:21:44 -0400689 } else {
690 resumeConfig = config
691 }
David Benjamin87c8a642015-02-21 01:54:29 -0500692 var connResume net.Conn
693 connResume, err = acceptOrWait(listener, waitChan)
694 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400695 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500696 connResume.Close()
697 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400698 }
699
David Benjamin87c8a642015-02-21 01:54:29 -0500700 // Close the listener now. This is to avoid hangs should the shim try to
701 // open more connections than expected.
702 listener.Close()
703 listener = nil
704
705 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800706 if exitError, ok := childErr.(*exec.ExitError); ok {
707 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
708 return errMoreMallocs
709 }
710 }
Adam Langley95c29f32014-06-20 12:00:00 -0700711
712 stdout := string(stdoutBuf.Bytes())
713 stderr := string(stderrBuf.Bytes())
714 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400715 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700716 localError := "none"
717 if err != nil {
718 localError = err.Error()
719 }
720 if len(test.expectedLocalError) != 0 {
721 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
722 }
Adam Langley95c29f32014-06-20 12:00:00 -0700723
724 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700725 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700726 if childErr != nil {
727 childError = childErr.Error()
728 }
729
730 var msg string
731 switch {
732 case failed && !test.shouldFail:
733 msg = "unexpected failure"
734 case !failed && test.shouldFail:
735 msg = "unexpected success"
736 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700737 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700738 default:
739 panic("internal error")
740 }
741
David Benjaminc565ebb2015-04-03 04:06:36 -0400742 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 -0700743 }
744
David Benjaminc565ebb2015-04-03 04:06:36 -0400745 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700746 println(stderr)
747 }
748
749 return nil
750}
751
752var tlsVersions = []struct {
753 name string
754 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400755 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500756 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700757}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500758 {"SSL3", VersionSSL30, "-no-ssl3", false},
759 {"TLS1", VersionTLS10, "-no-tls1", true},
760 {"TLS11", VersionTLS11, "-no-tls11", false},
761 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700762}
763
764var testCipherSuites = []struct {
765 name string
766 id uint16
767}{
768 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400769 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700770 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400771 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400772 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700773 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400774 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400775 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
776 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400777 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400778 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
779 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400780 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700781 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
782 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400783 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
784 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700785 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400786 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400787 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700788 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700789 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700790 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400791 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400792 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700793 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400794 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400795 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700796 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400797 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
798 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700799 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
800 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400801 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700802 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400803 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700804 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700805}
806
David Benjamin8b8c0062014-11-23 02:47:52 -0500807func hasComponent(suiteName, component string) bool {
808 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
809}
810
David Benjaminf7768e42014-08-31 02:06:47 -0400811func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500812 return hasComponent(suiteName, "GCM") ||
813 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400814 hasComponent(suiteName, "SHA384") ||
815 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500816}
817
818func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700819 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400820}
821
Adam Langleya7997f12015-05-14 17:38:50 -0700822func bigFromHex(hex string) *big.Int {
823 ret, ok := new(big.Int).SetString(hex, 16)
824 if !ok {
825 panic("failed to parse hex number 0x" + hex)
826 }
827 return ret
828}
829
Adam Langley7c803a62015-06-15 15:35:05 -0700830func addBasicTests() {
831 basicTests := []testCase{
832 {
833 name: "BadRSASignature",
834 config: Config{
835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
836 Bugs: ProtocolBugs{
837 InvalidSKXSignature: true,
838 },
839 },
840 shouldFail: true,
841 expectedError: ":BAD_SIGNATURE:",
842 },
843 {
844 name: "BadECDSASignature",
845 config: Config{
846 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
847 Bugs: ProtocolBugs{
848 InvalidSKXSignature: true,
849 },
850 Certificates: []Certificate{getECDSACertificate()},
851 },
852 shouldFail: true,
853 expectedError: ":BAD_SIGNATURE:",
854 },
855 {
David Benjamin6de0e532015-07-28 22:43:19 -0400856 testType: serverTest,
857 name: "BadRSASignature-ClientAuth",
858 config: Config{
859 Bugs: ProtocolBugs{
860 InvalidCertVerifySignature: true,
861 },
862 Certificates: []Certificate{getRSACertificate()},
863 },
864 shouldFail: true,
865 expectedError: ":BAD_SIGNATURE:",
866 flags: []string{"-require-any-client-certificate"},
867 },
868 {
869 testType: serverTest,
870 name: "BadECDSASignature-ClientAuth",
871 config: Config{
872 Bugs: ProtocolBugs{
873 InvalidCertVerifySignature: true,
874 },
875 Certificates: []Certificate{getECDSACertificate()},
876 },
877 shouldFail: true,
878 expectedError: ":BAD_SIGNATURE:",
879 flags: []string{"-require-any-client-certificate"},
880 },
881 {
Adam Langley7c803a62015-06-15 15:35:05 -0700882 name: "BadECDSACurve",
883 config: Config{
884 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
885 Bugs: ProtocolBugs{
886 InvalidSKXCurve: true,
887 },
888 Certificates: []Certificate{getECDSACertificate()},
889 },
890 shouldFail: true,
891 expectedError: ":WRONG_CURVE:",
892 },
893 {
894 testType: serverTest,
895 name: "BadRSAVersion",
896 config: Config{
897 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
898 Bugs: ProtocolBugs{
899 RsaClientKeyExchangeVersion: VersionTLS11,
900 },
901 },
902 shouldFail: true,
903 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
904 },
905 {
906 name: "NoFallbackSCSV",
907 config: Config{
908 Bugs: ProtocolBugs{
909 FailIfNotFallbackSCSV: true,
910 },
911 },
912 shouldFail: true,
913 expectedLocalError: "no fallback SCSV found",
914 },
915 {
916 name: "SendFallbackSCSV",
917 config: Config{
918 Bugs: ProtocolBugs{
919 FailIfNotFallbackSCSV: true,
920 },
921 },
922 flags: []string{"-fallback-scsv"},
923 },
924 {
925 name: "ClientCertificateTypes",
926 config: Config{
927 ClientAuth: RequestClientCert,
928 ClientCertificateTypes: []byte{
929 CertTypeDSSSign,
930 CertTypeRSASign,
931 CertTypeECDSASign,
932 },
933 },
934 flags: []string{
935 "-expect-certificate-types",
936 base64.StdEncoding.EncodeToString([]byte{
937 CertTypeDSSSign,
938 CertTypeRSASign,
939 CertTypeECDSASign,
940 }),
941 },
942 },
943 {
944 name: "NoClientCertificate",
945 config: Config{
946 ClientAuth: RequireAnyClientCert,
947 },
948 shouldFail: true,
949 expectedLocalError: "client didn't provide a certificate",
950 },
951 {
952 name: "UnauthenticatedECDH",
953 config: Config{
954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
955 Bugs: ProtocolBugs{
956 UnauthenticatedECDH: true,
957 },
958 },
959 shouldFail: true,
960 expectedError: ":UNEXPECTED_MESSAGE:",
961 },
962 {
963 name: "SkipCertificateStatus",
964 config: Config{
965 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
966 Bugs: ProtocolBugs{
967 SkipCertificateStatus: true,
968 },
969 },
970 flags: []string{
971 "-enable-ocsp-stapling",
972 },
973 },
974 {
975 name: "SkipServerKeyExchange",
976 config: Config{
977 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
978 Bugs: ProtocolBugs{
979 SkipServerKeyExchange: true,
980 },
981 },
982 shouldFail: true,
983 expectedError: ":UNEXPECTED_MESSAGE:",
984 },
985 {
986 name: "SkipChangeCipherSpec-Client",
987 config: Config{
988 Bugs: ProtocolBugs{
989 SkipChangeCipherSpec: true,
990 },
991 },
992 shouldFail: true,
993 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
994 },
995 {
996 testType: serverTest,
997 name: "SkipChangeCipherSpec-Server",
998 config: Config{
999 Bugs: ProtocolBugs{
1000 SkipChangeCipherSpec: true,
1001 },
1002 },
1003 shouldFail: true,
1004 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1005 },
1006 {
1007 testType: serverTest,
1008 name: "SkipChangeCipherSpec-Server-NPN",
1009 config: Config{
1010 NextProtos: []string{"bar"},
1011 Bugs: ProtocolBugs{
1012 SkipChangeCipherSpec: true,
1013 },
1014 },
1015 flags: []string{
1016 "-advertise-npn", "\x03foo\x03bar\x03baz",
1017 },
1018 shouldFail: true,
1019 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1020 },
1021 {
1022 name: "FragmentAcrossChangeCipherSpec-Client",
1023 config: Config{
1024 Bugs: ProtocolBugs{
1025 FragmentAcrossChangeCipherSpec: true,
1026 },
1027 },
1028 shouldFail: true,
1029 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1030 },
1031 {
1032 testType: serverTest,
1033 name: "FragmentAcrossChangeCipherSpec-Server",
1034 config: Config{
1035 Bugs: ProtocolBugs{
1036 FragmentAcrossChangeCipherSpec: true,
1037 },
1038 },
1039 shouldFail: true,
1040 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1041 },
1042 {
1043 testType: serverTest,
1044 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1045 config: Config{
1046 NextProtos: []string{"bar"},
1047 Bugs: ProtocolBugs{
1048 FragmentAcrossChangeCipherSpec: true,
1049 },
1050 },
1051 flags: []string{
1052 "-advertise-npn", "\x03foo\x03bar\x03baz",
1053 },
1054 shouldFail: true,
1055 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1056 },
1057 {
1058 testType: serverTest,
1059 name: "Alert",
1060 config: Config{
1061 Bugs: ProtocolBugs{
1062 SendSpuriousAlert: alertRecordOverflow,
1063 },
1064 },
1065 shouldFail: true,
1066 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1067 },
1068 {
1069 protocol: dtls,
1070 testType: serverTest,
1071 name: "Alert-DTLS",
1072 config: Config{
1073 Bugs: ProtocolBugs{
1074 SendSpuriousAlert: alertRecordOverflow,
1075 },
1076 },
1077 shouldFail: true,
1078 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1079 },
1080 {
1081 testType: serverTest,
1082 name: "FragmentAlert",
1083 config: Config{
1084 Bugs: ProtocolBugs{
1085 FragmentAlert: true,
1086 SendSpuriousAlert: alertRecordOverflow,
1087 },
1088 },
1089 shouldFail: true,
1090 expectedError: ":BAD_ALERT:",
1091 },
1092 {
1093 protocol: dtls,
1094 testType: serverTest,
1095 name: "FragmentAlert-DTLS",
1096 config: Config{
1097 Bugs: ProtocolBugs{
1098 FragmentAlert: true,
1099 SendSpuriousAlert: alertRecordOverflow,
1100 },
1101 },
1102 shouldFail: true,
1103 expectedError: ":BAD_ALERT:",
1104 },
1105 {
1106 testType: serverTest,
1107 name: "EarlyChangeCipherSpec-server-1",
1108 config: Config{
1109 Bugs: ProtocolBugs{
1110 EarlyChangeCipherSpec: 1,
1111 },
1112 },
1113 shouldFail: true,
1114 expectedError: ":CCS_RECEIVED_EARLY:",
1115 },
1116 {
1117 testType: serverTest,
1118 name: "EarlyChangeCipherSpec-server-2",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 EarlyChangeCipherSpec: 2,
1122 },
1123 },
1124 shouldFail: true,
1125 expectedError: ":CCS_RECEIVED_EARLY:",
1126 },
1127 {
1128 name: "SkipNewSessionTicket",
1129 config: Config{
1130 Bugs: ProtocolBugs{
1131 SkipNewSessionTicket: true,
1132 },
1133 },
1134 shouldFail: true,
1135 expectedError: ":CCS_RECEIVED_EARLY:",
1136 },
1137 {
1138 testType: serverTest,
1139 name: "FallbackSCSV",
1140 config: Config{
1141 MaxVersion: VersionTLS11,
1142 Bugs: ProtocolBugs{
1143 SendFallbackSCSV: true,
1144 },
1145 },
1146 shouldFail: true,
1147 expectedError: ":INAPPROPRIATE_FALLBACK:",
1148 },
1149 {
1150 testType: serverTest,
1151 name: "FallbackSCSV-VersionMatch",
1152 config: Config{
1153 Bugs: ProtocolBugs{
1154 SendFallbackSCSV: true,
1155 },
1156 },
1157 },
1158 {
1159 testType: serverTest,
1160 name: "FragmentedClientVersion",
1161 config: Config{
1162 Bugs: ProtocolBugs{
1163 MaxHandshakeRecordLength: 1,
1164 FragmentClientVersion: true,
1165 },
1166 },
1167 expectedVersion: VersionTLS12,
1168 },
1169 {
1170 testType: serverTest,
1171 name: "MinorVersionTolerance",
1172 config: Config{
1173 Bugs: ProtocolBugs{
1174 SendClientVersion: 0x03ff,
1175 },
1176 },
1177 expectedVersion: VersionTLS12,
1178 },
1179 {
1180 testType: serverTest,
1181 name: "MajorVersionTolerance",
1182 config: Config{
1183 Bugs: ProtocolBugs{
1184 SendClientVersion: 0x0400,
1185 },
1186 },
1187 expectedVersion: VersionTLS12,
1188 },
1189 {
1190 testType: serverTest,
1191 name: "VersionTooLow",
1192 config: Config{
1193 Bugs: ProtocolBugs{
1194 SendClientVersion: 0x0200,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":UNSUPPORTED_PROTOCOL:",
1199 },
1200 {
1201 testType: serverTest,
1202 name: "HttpGET",
1203 sendPrefix: "GET / HTTP/1.0\n",
1204 shouldFail: true,
1205 expectedError: ":HTTP_REQUEST:",
1206 },
1207 {
1208 testType: serverTest,
1209 name: "HttpPOST",
1210 sendPrefix: "POST / HTTP/1.0\n",
1211 shouldFail: true,
1212 expectedError: ":HTTP_REQUEST:",
1213 },
1214 {
1215 testType: serverTest,
1216 name: "HttpHEAD",
1217 sendPrefix: "HEAD / HTTP/1.0\n",
1218 shouldFail: true,
1219 expectedError: ":HTTP_REQUEST:",
1220 },
1221 {
1222 testType: serverTest,
1223 name: "HttpPUT",
1224 sendPrefix: "PUT / HTTP/1.0\n",
1225 shouldFail: true,
1226 expectedError: ":HTTP_REQUEST:",
1227 },
1228 {
1229 testType: serverTest,
1230 name: "HttpCONNECT",
1231 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1232 shouldFail: true,
1233 expectedError: ":HTTPS_PROXY_REQUEST:",
1234 },
1235 {
1236 testType: serverTest,
1237 name: "Garbage",
1238 sendPrefix: "blah",
1239 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001240 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001241 },
1242 {
1243 name: "SkipCipherVersionCheck",
1244 config: Config{
1245 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1246 MaxVersion: VersionTLS11,
1247 Bugs: ProtocolBugs{
1248 SkipCipherVersionCheck: true,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":WRONG_CIPHER_RETURNED:",
1253 },
1254 {
1255 name: "RSAEphemeralKey",
1256 config: Config{
1257 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1258 Bugs: ProtocolBugs{
1259 RSAEphemeralKey: true,
1260 },
1261 },
1262 shouldFail: true,
1263 expectedError: ":UNEXPECTED_MESSAGE:",
1264 },
1265 {
1266 name: "DisableEverything",
1267 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1268 shouldFail: true,
1269 expectedError: ":WRONG_SSL_VERSION:",
1270 },
1271 {
1272 protocol: dtls,
1273 name: "DisableEverything-DTLS",
1274 flags: []string{"-no-tls12", "-no-tls1"},
1275 shouldFail: true,
1276 expectedError: ":WRONG_SSL_VERSION:",
1277 },
1278 {
1279 name: "NoSharedCipher",
1280 config: Config{
1281 CipherSuites: []uint16{},
1282 },
1283 shouldFail: true,
1284 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1285 },
1286 {
1287 protocol: dtls,
1288 testType: serverTest,
1289 name: "MTU",
1290 config: Config{
1291 Bugs: ProtocolBugs{
1292 MaxPacketLength: 256,
1293 },
1294 },
1295 flags: []string{"-mtu", "256"},
1296 },
1297 {
1298 protocol: dtls,
1299 testType: serverTest,
1300 name: "MTUExceeded",
1301 config: Config{
1302 Bugs: ProtocolBugs{
1303 MaxPacketLength: 255,
1304 },
1305 },
1306 flags: []string{"-mtu", "256"},
1307 shouldFail: true,
1308 expectedLocalError: "dtls: exceeded maximum packet length",
1309 },
1310 {
1311 name: "CertMismatchRSA",
1312 config: Config{
1313 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1314 Certificates: []Certificate{getECDSACertificate()},
1315 Bugs: ProtocolBugs{
1316 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1317 },
1318 },
1319 shouldFail: true,
1320 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1321 },
1322 {
1323 name: "CertMismatchECDSA",
1324 config: Config{
1325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1326 Certificates: []Certificate{getRSACertificate()},
1327 Bugs: ProtocolBugs{
1328 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1329 },
1330 },
1331 shouldFail: true,
1332 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1333 },
1334 {
1335 name: "EmptyCertificateList",
1336 config: Config{
1337 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1338 Bugs: ProtocolBugs{
1339 EmptyCertificateList: true,
1340 },
1341 },
1342 shouldFail: true,
1343 expectedError: ":DECODE_ERROR:",
1344 },
1345 {
1346 name: "TLSFatalBadPackets",
1347 damageFirstWrite: true,
1348 shouldFail: true,
1349 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1350 },
1351 {
1352 protocol: dtls,
1353 name: "DTLSIgnoreBadPackets",
1354 damageFirstWrite: true,
1355 },
1356 {
1357 protocol: dtls,
1358 name: "DTLSIgnoreBadPackets-Async",
1359 damageFirstWrite: true,
1360 flags: []string{"-async"},
1361 },
1362 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001363 name: "AppDataBeforeHandshake",
1364 config: Config{
1365 Bugs: ProtocolBugs{
1366 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1367 },
1368 },
1369 shouldFail: true,
1370 expectedError: ":UNEXPECTED_RECORD:",
1371 },
1372 {
1373 name: "AppDataBeforeHandshake-Empty",
1374 config: Config{
1375 Bugs: ProtocolBugs{
1376 AppDataBeforeHandshake: []byte{},
1377 },
1378 },
1379 shouldFail: true,
1380 expectedError: ":UNEXPECTED_RECORD:",
1381 },
1382 {
1383 protocol: dtls,
1384 name: "AppDataBeforeHandshake-DTLS",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1388 },
1389 },
1390 shouldFail: true,
1391 expectedError: ":UNEXPECTED_RECORD:",
1392 },
1393 {
1394 protocol: dtls,
1395 name: "AppDataBeforeHandshake-DTLS-Empty",
1396 config: Config{
1397 Bugs: ProtocolBugs{
1398 AppDataBeforeHandshake: []byte{},
1399 },
1400 },
1401 shouldFail: true,
1402 expectedError: ":UNEXPECTED_RECORD:",
1403 },
1404 {
Adam Langley7c803a62015-06-15 15:35:05 -07001405 name: "AppDataAfterChangeCipherSpec",
1406 config: Config{
1407 Bugs: ProtocolBugs{
1408 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1413 },
1414 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001415 name: "AppDataAfterChangeCipherSpec-Empty",
1416 config: Config{
1417 Bugs: ProtocolBugs{
1418 AppDataAfterChangeCipherSpec: []byte{},
1419 },
1420 },
1421 shouldFail: true,
1422 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1423 },
1424 {
Adam Langley7c803a62015-06-15 15:35:05 -07001425 protocol: dtls,
1426 name: "AppDataAfterChangeCipherSpec-DTLS",
1427 config: Config{
1428 Bugs: ProtocolBugs{
1429 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1430 },
1431 },
1432 // BoringSSL's DTLS implementation will drop the out-of-order
1433 // application data.
1434 },
1435 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001436 protocol: dtls,
1437 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1438 config: Config{
1439 Bugs: ProtocolBugs{
1440 AppDataAfterChangeCipherSpec: []byte{},
1441 },
1442 },
1443 // BoringSSL's DTLS implementation will drop the out-of-order
1444 // application data.
1445 },
1446 {
Adam Langley7c803a62015-06-15 15:35:05 -07001447 name: "AlertAfterChangeCipherSpec",
1448 config: Config{
1449 Bugs: ProtocolBugs{
1450 AlertAfterChangeCipherSpec: alertRecordOverflow,
1451 },
1452 },
1453 shouldFail: true,
1454 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1455 },
1456 {
1457 protocol: dtls,
1458 name: "AlertAfterChangeCipherSpec-DTLS",
1459 config: Config{
1460 Bugs: ProtocolBugs{
1461 AlertAfterChangeCipherSpec: alertRecordOverflow,
1462 },
1463 },
1464 shouldFail: true,
1465 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1466 },
1467 {
1468 protocol: dtls,
1469 name: "ReorderHandshakeFragments-Small-DTLS",
1470 config: Config{
1471 Bugs: ProtocolBugs{
1472 ReorderHandshakeFragments: true,
1473 // Small enough that every handshake message is
1474 // fragmented.
1475 MaxHandshakeRecordLength: 2,
1476 },
1477 },
1478 },
1479 {
1480 protocol: dtls,
1481 name: "ReorderHandshakeFragments-Large-DTLS",
1482 config: Config{
1483 Bugs: ProtocolBugs{
1484 ReorderHandshakeFragments: true,
1485 // Large enough that no handshake message is
1486 // fragmented.
1487 MaxHandshakeRecordLength: 2048,
1488 },
1489 },
1490 },
1491 {
1492 protocol: dtls,
1493 name: "MixCompleteMessageWithFragments-DTLS",
1494 config: Config{
1495 Bugs: ProtocolBugs{
1496 ReorderHandshakeFragments: true,
1497 MixCompleteMessageWithFragments: true,
1498 MaxHandshakeRecordLength: 2,
1499 },
1500 },
1501 },
1502 {
1503 name: "SendInvalidRecordType",
1504 config: Config{
1505 Bugs: ProtocolBugs{
1506 SendInvalidRecordType: true,
1507 },
1508 },
1509 shouldFail: true,
1510 expectedError: ":UNEXPECTED_RECORD:",
1511 },
1512 {
1513 protocol: dtls,
1514 name: "SendInvalidRecordType-DTLS",
1515 config: Config{
1516 Bugs: ProtocolBugs{
1517 SendInvalidRecordType: true,
1518 },
1519 },
1520 shouldFail: true,
1521 expectedError: ":UNEXPECTED_RECORD:",
1522 },
1523 {
1524 name: "FalseStart-SkipServerSecondLeg",
1525 config: Config{
1526 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1527 NextProtos: []string{"foo"},
1528 Bugs: ProtocolBugs{
1529 SkipNewSessionTicket: true,
1530 SkipChangeCipherSpec: true,
1531 SkipFinished: true,
1532 ExpectFalseStart: true,
1533 },
1534 },
1535 flags: []string{
1536 "-false-start",
1537 "-handshake-never-done",
1538 "-advertise-alpn", "\x03foo",
1539 },
1540 shimWritesFirst: true,
1541 shouldFail: true,
1542 expectedError: ":UNEXPECTED_RECORD:",
1543 },
1544 {
1545 name: "FalseStart-SkipServerSecondLeg-Implicit",
1546 config: Config{
1547 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1548 NextProtos: []string{"foo"},
1549 Bugs: ProtocolBugs{
1550 SkipNewSessionTicket: true,
1551 SkipChangeCipherSpec: true,
1552 SkipFinished: true,
1553 },
1554 },
1555 flags: []string{
1556 "-implicit-handshake",
1557 "-false-start",
1558 "-handshake-never-done",
1559 "-advertise-alpn", "\x03foo",
1560 },
1561 shouldFail: true,
1562 expectedError: ":UNEXPECTED_RECORD:",
1563 },
1564 {
1565 testType: serverTest,
1566 name: "FailEarlyCallback",
1567 flags: []string{"-fail-early-callback"},
1568 shouldFail: true,
1569 expectedError: ":CONNECTION_REJECTED:",
1570 expectedLocalError: "remote error: access denied",
1571 },
1572 {
1573 name: "WrongMessageType",
1574 config: Config{
1575 Bugs: ProtocolBugs{
1576 WrongCertificateMessageType: true,
1577 },
1578 },
1579 shouldFail: true,
1580 expectedError: ":UNEXPECTED_MESSAGE:",
1581 expectedLocalError: "remote error: unexpected message",
1582 },
1583 {
1584 protocol: dtls,
1585 name: "WrongMessageType-DTLS",
1586 config: Config{
1587 Bugs: ProtocolBugs{
1588 WrongCertificateMessageType: true,
1589 },
1590 },
1591 shouldFail: true,
1592 expectedError: ":UNEXPECTED_MESSAGE:",
1593 expectedLocalError: "remote error: unexpected message",
1594 },
1595 {
1596 protocol: dtls,
1597 name: "FragmentMessageTypeMismatch-DTLS",
1598 config: Config{
1599 Bugs: ProtocolBugs{
1600 MaxHandshakeRecordLength: 2,
1601 FragmentMessageTypeMismatch: true,
1602 },
1603 },
1604 shouldFail: true,
1605 expectedError: ":FRAGMENT_MISMATCH:",
1606 },
1607 {
1608 protocol: dtls,
1609 name: "FragmentMessageLengthMismatch-DTLS",
1610 config: Config{
1611 Bugs: ProtocolBugs{
1612 MaxHandshakeRecordLength: 2,
1613 FragmentMessageLengthMismatch: true,
1614 },
1615 },
1616 shouldFail: true,
1617 expectedError: ":FRAGMENT_MISMATCH:",
1618 },
1619 {
1620 protocol: dtls,
1621 name: "SplitFragments-Header-DTLS",
1622 config: Config{
1623 Bugs: ProtocolBugs{
1624 SplitFragments: 2,
1625 },
1626 },
1627 shouldFail: true,
1628 expectedError: ":UNEXPECTED_MESSAGE:",
1629 },
1630 {
1631 protocol: dtls,
1632 name: "SplitFragments-Boundary-DTLS",
1633 config: Config{
1634 Bugs: ProtocolBugs{
1635 SplitFragments: dtlsRecordHeaderLen,
1636 },
1637 },
1638 shouldFail: true,
1639 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1640 },
1641 {
1642 protocol: dtls,
1643 name: "SplitFragments-Body-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 SplitFragments: dtlsRecordHeaderLen + 1,
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1651 },
1652 {
1653 protocol: dtls,
1654 name: "SendEmptyFragments-DTLS",
1655 config: Config{
1656 Bugs: ProtocolBugs{
1657 SendEmptyFragments: true,
1658 },
1659 },
1660 },
1661 {
1662 name: "UnsupportedCipherSuite",
1663 config: Config{
1664 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1665 Bugs: ProtocolBugs{
1666 IgnorePeerCipherPreferences: true,
1667 },
1668 },
1669 flags: []string{"-cipher", "DEFAULT:!RC4"},
1670 shouldFail: true,
1671 expectedError: ":WRONG_CIPHER_RETURNED:",
1672 },
1673 {
1674 name: "UnsupportedCurve",
1675 config: Config{
1676 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1677 // BoringSSL implements P-224 but doesn't enable it by
1678 // default.
1679 CurvePreferences: []CurveID{CurveP224},
1680 Bugs: ProtocolBugs{
1681 IgnorePeerCurvePreferences: true,
1682 },
1683 },
1684 shouldFail: true,
1685 expectedError: ":WRONG_CURVE:",
1686 },
1687 {
1688 name: "BadFinished",
1689 config: Config{
1690 Bugs: ProtocolBugs{
1691 BadFinished: true,
1692 },
1693 },
1694 shouldFail: true,
1695 expectedError: ":DIGEST_CHECK_FAILED:",
1696 },
1697 {
1698 name: "FalseStart-BadFinished",
1699 config: Config{
1700 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1701 NextProtos: []string{"foo"},
1702 Bugs: ProtocolBugs{
1703 BadFinished: true,
1704 ExpectFalseStart: true,
1705 },
1706 },
1707 flags: []string{
1708 "-false-start",
1709 "-handshake-never-done",
1710 "-advertise-alpn", "\x03foo",
1711 },
1712 shimWritesFirst: true,
1713 shouldFail: true,
1714 expectedError: ":DIGEST_CHECK_FAILED:",
1715 },
1716 {
1717 name: "NoFalseStart-NoALPN",
1718 config: Config{
1719 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1720 Bugs: ProtocolBugs{
1721 ExpectFalseStart: true,
1722 AlertBeforeFalseStartTest: alertAccessDenied,
1723 },
1724 },
1725 flags: []string{
1726 "-false-start",
1727 },
1728 shimWritesFirst: true,
1729 shouldFail: true,
1730 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1731 expectedLocalError: "tls: peer did not false start: EOF",
1732 },
1733 {
1734 name: "NoFalseStart-NoAEAD",
1735 config: Config{
1736 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1737 NextProtos: []string{"foo"},
1738 Bugs: ProtocolBugs{
1739 ExpectFalseStart: true,
1740 AlertBeforeFalseStartTest: alertAccessDenied,
1741 },
1742 },
1743 flags: []string{
1744 "-false-start",
1745 "-advertise-alpn", "\x03foo",
1746 },
1747 shimWritesFirst: true,
1748 shouldFail: true,
1749 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1750 expectedLocalError: "tls: peer did not false start: EOF",
1751 },
1752 {
1753 name: "NoFalseStart-RSA",
1754 config: Config{
1755 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1756 NextProtos: []string{"foo"},
1757 Bugs: ProtocolBugs{
1758 ExpectFalseStart: true,
1759 AlertBeforeFalseStartTest: alertAccessDenied,
1760 },
1761 },
1762 flags: []string{
1763 "-false-start",
1764 "-advertise-alpn", "\x03foo",
1765 },
1766 shimWritesFirst: true,
1767 shouldFail: true,
1768 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1769 expectedLocalError: "tls: peer did not false start: EOF",
1770 },
1771 {
1772 name: "NoFalseStart-DHE_RSA",
1773 config: Config{
1774 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1775 NextProtos: []string{"foo"},
1776 Bugs: ProtocolBugs{
1777 ExpectFalseStart: true,
1778 AlertBeforeFalseStartTest: alertAccessDenied,
1779 },
1780 },
1781 flags: []string{
1782 "-false-start",
1783 "-advertise-alpn", "\x03foo",
1784 },
1785 shimWritesFirst: true,
1786 shouldFail: true,
1787 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1788 expectedLocalError: "tls: peer did not false start: EOF",
1789 },
1790 {
1791 testType: serverTest,
1792 name: "NoSupportedCurves",
1793 config: Config{
1794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1795 Bugs: ProtocolBugs{
1796 NoSupportedCurves: true,
1797 },
1798 },
1799 },
1800 {
1801 testType: serverTest,
1802 name: "NoCommonCurves",
1803 config: Config{
1804 CipherSuites: []uint16{
1805 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1806 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1807 },
1808 CurvePreferences: []CurveID{CurveP224},
1809 },
1810 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1811 },
1812 {
1813 protocol: dtls,
1814 name: "SendSplitAlert-Sync",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 SendSplitAlert: true,
1818 },
1819 },
1820 },
1821 {
1822 protocol: dtls,
1823 name: "SendSplitAlert-Async",
1824 config: Config{
1825 Bugs: ProtocolBugs{
1826 SendSplitAlert: true,
1827 },
1828 },
1829 flags: []string{"-async"},
1830 },
1831 {
1832 protocol: dtls,
1833 name: "PackDTLSHandshake",
1834 config: Config{
1835 Bugs: ProtocolBugs{
1836 MaxHandshakeRecordLength: 2,
1837 PackHandshakeFragments: 20,
1838 PackHandshakeRecords: 200,
1839 },
1840 },
1841 },
1842 {
1843 testType: serverTest,
1844 protocol: dtls,
1845 name: "NoRC4-DTLS",
1846 config: Config{
1847 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1848 Bugs: ProtocolBugs{
1849 EnableAllCiphersInDTLS: true,
1850 },
1851 },
1852 shouldFail: true,
1853 expectedError: ":NO_SHARED_CIPHER:",
1854 },
1855 {
1856 name: "SendEmptyRecords-Pass",
1857 sendEmptyRecords: 32,
1858 },
1859 {
1860 name: "SendEmptyRecords",
1861 sendEmptyRecords: 33,
1862 shouldFail: true,
1863 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1864 },
1865 {
1866 name: "SendEmptyRecords-Async",
1867 sendEmptyRecords: 33,
1868 flags: []string{"-async"},
1869 shouldFail: true,
1870 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1871 },
1872 {
1873 name: "SendWarningAlerts-Pass",
1874 sendWarningAlerts: 4,
1875 },
1876 {
1877 protocol: dtls,
1878 name: "SendWarningAlerts-DTLS-Pass",
1879 sendWarningAlerts: 4,
1880 },
1881 {
1882 name: "SendWarningAlerts",
1883 sendWarningAlerts: 5,
1884 shouldFail: true,
1885 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1886 },
1887 {
1888 name: "SendWarningAlerts-Async",
1889 sendWarningAlerts: 5,
1890 flags: []string{"-async"},
1891 shouldFail: true,
1892 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1893 },
David Benjaminba4594a2015-06-18 18:36:15 -04001894 {
1895 name: "EmptySessionID",
1896 config: Config{
1897 SessionTicketsDisabled: true,
1898 },
1899 noSessionCache: true,
1900 flags: []string{"-expect-no-session"},
1901 },
David Benjamin30789da2015-08-29 22:56:45 -04001902 {
1903 name: "Unclean-Shutdown",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 NoCloseNotify: true,
1907 ExpectCloseNotify: true,
1908 },
1909 },
1910 shimShutsDown: true,
1911 flags: []string{"-check-close-notify"},
1912 shouldFail: true,
1913 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1914 },
1915 {
1916 name: "Unclean-Shutdown-Ignored",
1917 config: Config{
1918 Bugs: ProtocolBugs{
1919 NoCloseNotify: true,
1920 },
1921 },
1922 shimShutsDown: true,
1923 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001924 {
1925 name: "LargePlaintext",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 SendLargeRecords: true,
1929 },
1930 },
1931 messageLen: maxPlaintext + 1,
1932 shouldFail: true,
1933 expectedError: ":DATA_LENGTH_TOO_LONG:",
1934 },
1935 {
1936 protocol: dtls,
1937 name: "LargePlaintext-DTLS",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendLargeRecords: true,
1941 },
1942 },
1943 messageLen: maxPlaintext + 1,
1944 shouldFail: true,
1945 expectedError: ":DATA_LENGTH_TOO_LONG:",
1946 },
1947 {
1948 name: "LargeCiphertext",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 SendLargeRecords: true,
1952 },
1953 },
1954 messageLen: maxPlaintext * 2,
1955 shouldFail: true,
1956 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1957 },
1958 {
1959 protocol: dtls,
1960 name: "LargeCiphertext-DTLS",
1961 config: Config{
1962 Bugs: ProtocolBugs{
1963 SendLargeRecords: true,
1964 },
1965 },
1966 messageLen: maxPlaintext * 2,
1967 // Unlike the other four cases, DTLS drops records which
1968 // are invalid before authentication, so the connection
1969 // does not fail.
1970 expectMessageDropped: true,
1971 },
Adam Langley7c803a62015-06-15 15:35:05 -07001972 }
Adam Langley7c803a62015-06-15 15:35:05 -07001973 testCases = append(testCases, basicTests...)
1974}
1975
Adam Langley95c29f32014-06-20 12:00:00 -07001976func addCipherSuiteTests() {
1977 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001978 const psk = "12345"
1979 const pskIdentity = "luggage combo"
1980
Adam Langley95c29f32014-06-20 12:00:00 -07001981 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001982 var certFile string
1983 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001984 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001985 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001986 certFile = ecdsaCertificateFile
1987 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001988 } else {
1989 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001990 certFile = rsaCertificateFile
1991 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001992 }
1993
David Benjamin48cae082014-10-27 01:06:24 -04001994 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001995 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001996 flags = append(flags,
1997 "-psk", psk,
1998 "-psk-identity", pskIdentity)
1999 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002000 if hasComponent(suite.name, "NULL") {
2001 // NULL ciphers must be explicitly enabled.
2002 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2003 }
David Benjamin48cae082014-10-27 01:06:24 -04002004
Adam Langley95c29f32014-06-20 12:00:00 -07002005 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002006 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002007 continue
2008 }
2009
David Benjamin025b3d32014-07-01 19:53:04 -04002010 testCases = append(testCases, testCase{
2011 testType: clientTest,
2012 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002013 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002014 MinVersion: ver.version,
2015 MaxVersion: ver.version,
2016 CipherSuites: []uint16{suite.id},
2017 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002018 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002019 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002020 },
David Benjamin48cae082014-10-27 01:06:24 -04002021 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002022 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002023 })
David Benjamin025b3d32014-07-01 19:53:04 -04002024
David Benjamin76d8abe2014-08-14 16:25:34 -04002025 testCases = append(testCases, testCase{
2026 testType: serverTest,
2027 name: ver.name + "-" + suite.name + "-server",
2028 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002029 MinVersion: ver.version,
2030 MaxVersion: ver.version,
2031 CipherSuites: []uint16{suite.id},
2032 Certificates: []Certificate{cert},
2033 PreSharedKey: []byte(psk),
2034 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002035 },
2036 certFile: certFile,
2037 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002038 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002039 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002040 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002041
David Benjamin8b8c0062014-11-23 02:47:52 -05002042 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002043 testCases = append(testCases, testCase{
2044 testType: clientTest,
2045 protocol: dtls,
2046 name: "D" + ver.name + "-" + suite.name + "-client",
2047 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002048 MinVersion: ver.version,
2049 MaxVersion: ver.version,
2050 CipherSuites: []uint16{suite.id},
2051 Certificates: []Certificate{cert},
2052 PreSharedKey: []byte(psk),
2053 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002054 },
David Benjamin48cae082014-10-27 01:06:24 -04002055 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002056 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002057 })
2058 testCases = append(testCases, testCase{
2059 testType: serverTest,
2060 protocol: dtls,
2061 name: "D" + ver.name + "-" + suite.name + "-server",
2062 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002063 MinVersion: ver.version,
2064 MaxVersion: ver.version,
2065 CipherSuites: []uint16{suite.id},
2066 Certificates: []Certificate{cert},
2067 PreSharedKey: []byte(psk),
2068 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002069 },
2070 certFile: certFile,
2071 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002072 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002073 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002074 })
2075 }
Adam Langley95c29f32014-06-20 12:00:00 -07002076 }
David Benjamin2c99d282015-09-01 10:23:00 -04002077
2078 // Ensure both TLS and DTLS accept their maximum record sizes.
2079 testCases = append(testCases, testCase{
2080 name: suite.name + "-LargeRecord",
2081 config: Config{
2082 CipherSuites: []uint16{suite.id},
2083 Certificates: []Certificate{cert},
2084 PreSharedKey: []byte(psk),
2085 PreSharedKeyIdentity: pskIdentity,
2086 },
2087 flags: flags,
2088 messageLen: maxPlaintext,
2089 })
2090 testCases = append(testCases, testCase{
2091 name: suite.name + "-LargeRecord-Extra",
2092 config: Config{
2093 CipherSuites: []uint16{suite.id},
2094 Certificates: []Certificate{cert},
2095 PreSharedKey: []byte(psk),
2096 PreSharedKeyIdentity: pskIdentity,
2097 Bugs: ProtocolBugs{
2098 SendLargeRecords: true,
2099 },
2100 },
2101 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2102 messageLen: maxPlaintext + 16384,
2103 })
2104 if isDTLSCipher(suite.name) {
2105 testCases = append(testCases, testCase{
2106 protocol: dtls,
2107 name: suite.name + "-LargeRecord-DTLS",
2108 config: Config{
2109 CipherSuites: []uint16{suite.id},
2110 Certificates: []Certificate{cert},
2111 PreSharedKey: []byte(psk),
2112 PreSharedKeyIdentity: pskIdentity,
2113 },
2114 flags: flags,
2115 messageLen: maxPlaintext,
2116 })
2117 }
Adam Langley95c29f32014-06-20 12:00:00 -07002118 }
Adam Langleya7997f12015-05-14 17:38:50 -07002119
2120 testCases = append(testCases, testCase{
2121 name: "WeakDH",
2122 config: Config{
2123 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2124 Bugs: ProtocolBugs{
2125 // This is a 1023-bit prime number, generated
2126 // with:
2127 // openssl gendh 1023 | openssl asn1parse -i
2128 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2129 },
2130 },
2131 shouldFail: true,
2132 expectedError: "BAD_DH_P_LENGTH",
2133 })
Adam Langleycef75832015-09-03 14:51:12 -07002134
2135 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2136 // 1.1 specific cipher suite settings. A server is setup with the given
2137 // cipher lists and then a connection is made for each member of
2138 // expectations. The cipher suite that the server selects must match
2139 // the specified one.
2140 var versionSpecificCiphersTest = []struct {
2141 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2142 // expectations is a map from TLS version to cipher suite id.
2143 expectations map[uint16]uint16
2144 }{
2145 {
2146 // Test that the null case (where no version-specific ciphers are set)
2147 // works as expected.
2148 "RC4-SHA:AES128-SHA", // default ciphers
2149 "", // no ciphers specifically for TLS ≥ 1.0
2150 "", // no ciphers specifically for TLS ≥ 1.1
2151 map[uint16]uint16{
2152 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2153 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2154 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2155 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2156 },
2157 },
2158 {
2159 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2160 // cipher.
2161 "RC4-SHA:AES128-SHA", // default
2162 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2163 "", // no ciphers specifically for TLS ≥ 1.1
2164 map[uint16]uint16{
2165 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2166 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2167 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2168 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2169 },
2170 },
2171 {
2172 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2173 // cipher.
2174 "RC4-SHA:AES128-SHA", // default
2175 "", // no ciphers specifically for TLS ≥ 1.0
2176 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2177 map[uint16]uint16{
2178 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2179 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2180 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2181 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2182 },
2183 },
2184 {
2185 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2186 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2187 "RC4-SHA:AES128-SHA", // default
2188 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2189 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2190 map[uint16]uint16{
2191 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2192 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2193 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2194 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2195 },
2196 },
2197 }
2198
2199 for i, test := range versionSpecificCiphersTest {
2200 for version, expectedCipherSuite := range test.expectations {
2201 flags := []string{"-cipher", test.ciphersDefault}
2202 if len(test.ciphersTLS10) > 0 {
2203 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2204 }
2205 if len(test.ciphersTLS11) > 0 {
2206 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2207 }
2208
2209 testCases = append(testCases, testCase{
2210 testType: serverTest,
2211 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2212 config: Config{
2213 MaxVersion: version,
2214 MinVersion: version,
2215 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2216 },
2217 flags: flags,
2218 expectedCipher: expectedCipherSuite,
2219 })
2220 }
2221 }
Adam Langley95c29f32014-06-20 12:00:00 -07002222}
2223
2224func addBadECDSASignatureTests() {
2225 for badR := BadValue(1); badR < NumBadValues; badR++ {
2226 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002227 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002228 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2229 config: Config{
2230 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2231 Certificates: []Certificate{getECDSACertificate()},
2232 Bugs: ProtocolBugs{
2233 BadECDSAR: badR,
2234 BadECDSAS: badS,
2235 },
2236 },
2237 shouldFail: true,
2238 expectedError: "SIGNATURE",
2239 })
2240 }
2241 }
2242}
2243
Adam Langley80842bd2014-06-20 12:00:00 -07002244func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002245 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002246 name: "MaxCBCPadding",
2247 config: Config{
2248 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2249 Bugs: ProtocolBugs{
2250 MaxPadding: true,
2251 },
2252 },
2253 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2254 })
David Benjamin025b3d32014-07-01 19:53:04 -04002255 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002256 name: "BadCBCPadding",
2257 config: Config{
2258 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2259 Bugs: ProtocolBugs{
2260 PaddingFirstByteBad: true,
2261 },
2262 },
2263 shouldFail: true,
2264 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2265 })
2266 // OpenSSL previously had an issue where the first byte of padding in
2267 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002268 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002269 name: "BadCBCPadding255",
2270 config: Config{
2271 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2272 Bugs: ProtocolBugs{
2273 MaxPadding: true,
2274 PaddingFirstByteBadIf255: true,
2275 },
2276 },
2277 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2278 shouldFail: true,
2279 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2280 })
2281}
2282
Kenny Root7fdeaf12014-08-05 15:23:37 -07002283func addCBCSplittingTests() {
2284 testCases = append(testCases, testCase{
2285 name: "CBCRecordSplitting",
2286 config: Config{
2287 MaxVersion: VersionTLS10,
2288 MinVersion: VersionTLS10,
2289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2290 },
David Benjaminac8302a2015-09-01 17:18:15 -04002291 messageLen: -1, // read until EOF
2292 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002293 flags: []string{
2294 "-async",
2295 "-write-different-record-sizes",
2296 "-cbc-record-splitting",
2297 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002298 })
2299 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002300 name: "CBCRecordSplittingPartialWrite",
2301 config: Config{
2302 MaxVersion: VersionTLS10,
2303 MinVersion: VersionTLS10,
2304 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2305 },
2306 messageLen: -1, // read until EOF
2307 flags: []string{
2308 "-async",
2309 "-write-different-record-sizes",
2310 "-cbc-record-splitting",
2311 "-partial-write",
2312 },
2313 })
2314}
2315
David Benjamin636293b2014-07-08 17:59:18 -04002316func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002317 // Add a dummy cert pool to stress certificate authority parsing.
2318 // TODO(davidben): Add tests that those values parse out correctly.
2319 certPool := x509.NewCertPool()
2320 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2321 if err != nil {
2322 panic(err)
2323 }
2324 certPool.AddCert(cert)
2325
David Benjamin636293b2014-07-08 17:59:18 -04002326 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002327 testCases = append(testCases, testCase{
2328 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002329 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002330 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002331 MinVersion: ver.version,
2332 MaxVersion: ver.version,
2333 ClientAuth: RequireAnyClientCert,
2334 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002335 },
2336 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002337 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2338 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002339 },
2340 })
2341 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002342 testType: serverTest,
2343 name: ver.name + "-Server-ClientAuth-RSA",
2344 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002345 MinVersion: ver.version,
2346 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002347 Certificates: []Certificate{rsaCertificate},
2348 },
2349 flags: []string{"-require-any-client-certificate"},
2350 })
David Benjamine098ec22014-08-27 23:13:20 -04002351 if ver.version != VersionSSL30 {
2352 testCases = append(testCases, testCase{
2353 testType: serverTest,
2354 name: ver.name + "-Server-ClientAuth-ECDSA",
2355 config: Config{
2356 MinVersion: ver.version,
2357 MaxVersion: ver.version,
2358 Certificates: []Certificate{ecdsaCertificate},
2359 },
2360 flags: []string{"-require-any-client-certificate"},
2361 })
2362 testCases = append(testCases, testCase{
2363 testType: clientTest,
2364 name: ver.name + "-Client-ClientAuth-ECDSA",
2365 config: Config{
2366 MinVersion: ver.version,
2367 MaxVersion: ver.version,
2368 ClientAuth: RequireAnyClientCert,
2369 ClientCAs: certPool,
2370 },
2371 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002372 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2373 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002374 },
2375 })
2376 }
David Benjamin636293b2014-07-08 17:59:18 -04002377 }
2378}
2379
Adam Langley75712922014-10-10 16:23:43 -07002380func addExtendedMasterSecretTests() {
2381 const expectEMSFlag = "-expect-extended-master-secret"
2382
2383 for _, with := range []bool{false, true} {
2384 prefix := "No"
2385 var flags []string
2386 if with {
2387 prefix = ""
2388 flags = []string{expectEMSFlag}
2389 }
2390
2391 for _, isClient := range []bool{false, true} {
2392 suffix := "-Server"
2393 testType := serverTest
2394 if isClient {
2395 suffix = "-Client"
2396 testType = clientTest
2397 }
2398
2399 for _, ver := range tlsVersions {
2400 test := testCase{
2401 testType: testType,
2402 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2403 config: Config{
2404 MinVersion: ver.version,
2405 MaxVersion: ver.version,
2406 Bugs: ProtocolBugs{
2407 NoExtendedMasterSecret: !with,
2408 RequireExtendedMasterSecret: with,
2409 },
2410 },
David Benjamin48cae082014-10-27 01:06:24 -04002411 flags: flags,
2412 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002413 }
2414 if test.shouldFail {
2415 test.expectedLocalError = "extended master secret required but not supported by peer"
2416 }
2417 testCases = append(testCases, test)
2418 }
2419 }
2420 }
2421
Adam Langleyba5934b2015-06-02 10:50:35 -07002422 for _, isClient := range []bool{false, true} {
2423 for _, supportedInFirstConnection := range []bool{false, true} {
2424 for _, supportedInResumeConnection := range []bool{false, true} {
2425 boolToWord := func(b bool) string {
2426 if b {
2427 return "Yes"
2428 }
2429 return "No"
2430 }
2431 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2432 if isClient {
2433 suffix += "Client"
2434 } else {
2435 suffix += "Server"
2436 }
2437
2438 supportedConfig := Config{
2439 Bugs: ProtocolBugs{
2440 RequireExtendedMasterSecret: true,
2441 },
2442 }
2443
2444 noSupportConfig := Config{
2445 Bugs: ProtocolBugs{
2446 NoExtendedMasterSecret: true,
2447 },
2448 }
2449
2450 test := testCase{
2451 name: "ExtendedMasterSecret-" + suffix,
2452 resumeSession: true,
2453 }
2454
2455 if !isClient {
2456 test.testType = serverTest
2457 }
2458
2459 if supportedInFirstConnection {
2460 test.config = supportedConfig
2461 } else {
2462 test.config = noSupportConfig
2463 }
2464
2465 if supportedInResumeConnection {
2466 test.resumeConfig = &supportedConfig
2467 } else {
2468 test.resumeConfig = &noSupportConfig
2469 }
2470
2471 switch suffix {
2472 case "YesToYes-Client", "YesToYes-Server":
2473 // When a session is resumed, it should
2474 // still be aware that its master
2475 // secret was generated via EMS and
2476 // thus it's safe to use tls-unique.
2477 test.flags = []string{expectEMSFlag}
2478 case "NoToYes-Server":
2479 // If an original connection did not
2480 // contain EMS, but a resumption
2481 // handshake does, then a server should
2482 // not resume the session.
2483 test.expectResumeRejected = true
2484 case "YesToNo-Server":
2485 // Resuming an EMS session without the
2486 // EMS extension should cause the
2487 // server to abort the connection.
2488 test.shouldFail = true
2489 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2490 case "NoToYes-Client":
2491 // A client should abort a connection
2492 // where the server resumed a non-EMS
2493 // session but echoed the EMS
2494 // extension.
2495 test.shouldFail = true
2496 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2497 case "YesToNo-Client":
2498 // A client should abort a connection
2499 // where the server didn't echo EMS
2500 // when the session used it.
2501 test.shouldFail = true
2502 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2503 }
2504
2505 testCases = append(testCases, test)
2506 }
2507 }
2508 }
Adam Langley75712922014-10-10 16:23:43 -07002509}
2510
David Benjamin43ec06f2014-08-05 02:28:57 -04002511// Adds tests that try to cover the range of the handshake state machine, under
2512// various conditions. Some of these are redundant with other tests, but they
2513// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002514func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002515 var tests []testCase
2516
2517 // Basic handshake, with resumption. Client and server,
2518 // session ID and session ticket.
2519 tests = append(tests, testCase{
2520 name: "Basic-Client",
2521 resumeSession: true,
2522 })
2523 tests = append(tests, testCase{
2524 name: "Basic-Client-RenewTicket",
2525 config: Config{
2526 Bugs: ProtocolBugs{
2527 RenewTicketOnResume: true,
2528 },
2529 },
David Benjaminba4594a2015-06-18 18:36:15 -04002530 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002531 resumeSession: true,
2532 })
2533 tests = append(tests, testCase{
2534 name: "Basic-Client-NoTicket",
2535 config: Config{
2536 SessionTicketsDisabled: true,
2537 },
2538 resumeSession: true,
2539 })
2540 tests = append(tests, testCase{
2541 name: "Basic-Client-Implicit",
2542 flags: []string{"-implicit-handshake"},
2543 resumeSession: true,
2544 })
2545 tests = append(tests, testCase{
2546 testType: serverTest,
2547 name: "Basic-Server",
2548 resumeSession: true,
2549 })
2550 tests = append(tests, testCase{
2551 testType: serverTest,
2552 name: "Basic-Server-NoTickets",
2553 config: Config{
2554 SessionTicketsDisabled: true,
2555 },
2556 resumeSession: true,
2557 })
2558 tests = append(tests, testCase{
2559 testType: serverTest,
2560 name: "Basic-Server-Implicit",
2561 flags: []string{"-implicit-handshake"},
2562 resumeSession: true,
2563 })
2564 tests = append(tests, testCase{
2565 testType: serverTest,
2566 name: "Basic-Server-EarlyCallback",
2567 flags: []string{"-use-early-callback"},
2568 resumeSession: true,
2569 })
2570
2571 // TLS client auth.
2572 tests = append(tests, testCase{
2573 testType: clientTest,
2574 name: "ClientAuth-Client",
2575 config: Config{
2576 ClientAuth: RequireAnyClientCert,
2577 },
2578 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002579 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2580 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002581 },
2582 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002583 if async {
2584 tests = append(tests, testCase{
2585 testType: clientTest,
2586 name: "ClientAuth-Client-AsyncKey",
2587 config: Config{
2588 ClientAuth: RequireAnyClientCert,
2589 },
2590 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002591 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2592 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002593 "-use-async-private-key",
2594 },
2595 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002596 tests = append(tests, testCase{
2597 testType: serverTest,
2598 name: "Basic-Server-RSAAsyncKey",
2599 flags: []string{
2600 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2601 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2602 "-use-async-private-key",
2603 },
2604 })
2605 tests = append(tests, testCase{
2606 testType: serverTest,
2607 name: "Basic-Server-ECDSAAsyncKey",
2608 flags: []string{
2609 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2610 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2611 "-use-async-private-key",
2612 },
2613 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002614 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002615 tests = append(tests, testCase{
2616 testType: serverTest,
2617 name: "ClientAuth-Server",
2618 config: Config{
2619 Certificates: []Certificate{rsaCertificate},
2620 },
2621 flags: []string{"-require-any-client-certificate"},
2622 })
2623
2624 // No session ticket support; server doesn't send NewSessionTicket.
2625 tests = append(tests, testCase{
2626 name: "SessionTicketsDisabled-Client",
2627 config: Config{
2628 SessionTicketsDisabled: true,
2629 },
2630 })
2631 tests = append(tests, testCase{
2632 testType: serverTest,
2633 name: "SessionTicketsDisabled-Server",
2634 config: Config{
2635 SessionTicketsDisabled: true,
2636 },
2637 })
2638
2639 // Skip ServerKeyExchange in PSK key exchange if there's no
2640 // identity hint.
2641 tests = append(tests, testCase{
2642 name: "EmptyPSKHint-Client",
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 tests = append(tests, testCase{
2650 testType: serverTest,
2651 name: "EmptyPSKHint-Server",
2652 config: Config{
2653 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2654 PreSharedKey: []byte("secret"),
2655 },
2656 flags: []string{"-psk", "secret"},
2657 })
2658
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002659 tests = append(tests, testCase{
2660 testType: clientTest,
2661 name: "OCSPStapling-Client",
2662 flags: []string{
2663 "-enable-ocsp-stapling",
2664 "-expect-ocsp-response",
2665 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002666 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002667 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002668 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002669 })
2670
2671 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002672 testType: serverTest,
2673 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002674 expectedOCSPResponse: testOCSPResponse,
2675 flags: []string{
2676 "-ocsp-response",
2677 base64.StdEncoding.EncodeToString(testOCSPResponse),
2678 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002679 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002680 })
2681
Paul Lietar8f1c2682015-08-18 12:21:54 +01002682 tests = append(tests, testCase{
2683 testType: clientTest,
2684 name: "CertificateVerificationSucceed",
2685 flags: []string{
2686 "-verify-peer",
2687 },
2688 })
2689
2690 tests = append(tests, testCase{
2691 testType: clientTest,
2692 name: "CertificateVerificationFail",
2693 flags: []string{
2694 "-verify-fail",
2695 "-verify-peer",
2696 },
2697 shouldFail: true,
2698 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2699 })
2700
2701 tests = append(tests, testCase{
2702 testType: clientTest,
2703 name: "CertificateVerificationSoftFail",
2704 flags: []string{
2705 "-verify-fail",
2706 "-expect-verify-result",
2707 },
2708 })
2709
David Benjamin760b1dd2015-05-15 23:33:48 -04002710 if protocol == tls {
2711 tests = append(tests, testCase{
2712 name: "Renegotiate-Client",
2713 renegotiate: true,
David Benjamin324dce42015-10-12 19:49:00 -04002714 flags: []string{"-expect-total-renegotiations", "1"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002715 })
2716 // NPN on client and server; results in post-handshake message.
2717 tests = append(tests, testCase{
2718 name: "NPN-Client",
2719 config: Config{
2720 NextProtos: []string{"foo"},
2721 },
2722 flags: []string{"-select-next-proto", "foo"},
2723 expectedNextProto: "foo",
2724 expectedNextProtoType: npn,
2725 })
2726 tests = append(tests, testCase{
2727 testType: serverTest,
2728 name: "NPN-Server",
2729 config: Config{
2730 NextProtos: []string{"bar"},
2731 },
2732 flags: []string{
2733 "-advertise-npn", "\x03foo\x03bar\x03baz",
2734 "-expect-next-proto", "bar",
2735 },
2736 expectedNextProto: "bar",
2737 expectedNextProtoType: npn,
2738 })
2739
2740 // TODO(davidben): Add tests for when False Start doesn't trigger.
2741
2742 // Client does False Start and negotiates NPN.
2743 tests = append(tests, testCase{
2744 name: "FalseStart",
2745 config: Config{
2746 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2747 NextProtos: []string{"foo"},
2748 Bugs: ProtocolBugs{
2749 ExpectFalseStart: true,
2750 },
2751 },
2752 flags: []string{
2753 "-false-start",
2754 "-select-next-proto", "foo",
2755 },
2756 shimWritesFirst: true,
2757 resumeSession: true,
2758 })
2759
2760 // Client does False Start and negotiates ALPN.
2761 tests = append(tests, testCase{
2762 name: "FalseStart-ALPN",
2763 config: Config{
2764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2765 NextProtos: []string{"foo"},
2766 Bugs: ProtocolBugs{
2767 ExpectFalseStart: true,
2768 },
2769 },
2770 flags: []string{
2771 "-false-start",
2772 "-advertise-alpn", "\x03foo",
2773 },
2774 shimWritesFirst: true,
2775 resumeSession: true,
2776 })
2777
2778 // Client does False Start but doesn't explicitly call
2779 // SSL_connect.
2780 tests = append(tests, testCase{
2781 name: "FalseStart-Implicit",
2782 config: Config{
2783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2784 NextProtos: []string{"foo"},
2785 },
2786 flags: []string{
2787 "-implicit-handshake",
2788 "-false-start",
2789 "-advertise-alpn", "\x03foo",
2790 },
2791 })
2792
2793 // False Start without session tickets.
2794 tests = append(tests, testCase{
2795 name: "FalseStart-SessionTicketsDisabled",
2796 config: Config{
2797 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2798 NextProtos: []string{"foo"},
2799 SessionTicketsDisabled: true,
2800 Bugs: ProtocolBugs{
2801 ExpectFalseStart: true,
2802 },
2803 },
2804 flags: []string{
2805 "-false-start",
2806 "-select-next-proto", "foo",
2807 },
2808 shimWritesFirst: true,
2809 })
2810
2811 // Server parses a V2ClientHello.
2812 tests = append(tests, testCase{
2813 testType: serverTest,
2814 name: "SendV2ClientHello",
2815 config: Config{
2816 // Choose a cipher suite that does not involve
2817 // elliptic curves, so no extensions are
2818 // involved.
2819 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2820 Bugs: ProtocolBugs{
2821 SendV2ClientHello: true,
2822 },
2823 },
2824 })
2825
2826 // Client sends a Channel ID.
2827 tests = append(tests, testCase{
2828 name: "ChannelID-Client",
2829 config: Config{
2830 RequestChannelID: true,
2831 },
Adam Langley7c803a62015-06-15 15:35:05 -07002832 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002833 resumeSession: true,
2834 expectChannelID: true,
2835 })
2836
2837 // Server accepts a Channel ID.
2838 tests = append(tests, testCase{
2839 testType: serverTest,
2840 name: "ChannelID-Server",
2841 config: Config{
2842 ChannelID: channelIDKey,
2843 },
2844 flags: []string{
2845 "-expect-channel-id",
2846 base64.StdEncoding.EncodeToString(channelIDBytes),
2847 },
2848 resumeSession: true,
2849 expectChannelID: true,
2850 })
David Benjamin30789da2015-08-29 22:56:45 -04002851
2852 // Bidirectional shutdown with the runner initiating.
2853 tests = append(tests, testCase{
2854 name: "Shutdown-Runner",
2855 config: Config{
2856 Bugs: ProtocolBugs{
2857 ExpectCloseNotify: true,
2858 },
2859 },
2860 flags: []string{"-check-close-notify"},
2861 })
2862
2863 // Bidirectional shutdown with the shim initiating. The runner,
2864 // in the meantime, sends garbage before the close_notify which
2865 // the shim must ignore.
2866 tests = append(tests, testCase{
2867 name: "Shutdown-Shim",
2868 config: Config{
2869 Bugs: ProtocolBugs{
2870 ExpectCloseNotify: true,
2871 },
2872 },
2873 shimShutsDown: true,
2874 sendEmptyRecords: 1,
2875 sendWarningAlerts: 1,
2876 flags: []string{"-check-close-notify"},
2877 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002878 } else {
2879 tests = append(tests, testCase{
2880 name: "SkipHelloVerifyRequest",
2881 config: Config{
2882 Bugs: ProtocolBugs{
2883 SkipHelloVerifyRequest: true,
2884 },
2885 },
2886 })
2887 }
2888
David Benjamin43ec06f2014-08-05 02:28:57 -04002889 var suffix string
2890 var flags []string
2891 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002892 if protocol == dtls {
2893 suffix = "-DTLS"
2894 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002895 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002896 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002897 flags = append(flags, "-async")
2898 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002899 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002900 }
2901 if splitHandshake {
2902 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002903 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002904 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002905 for _, test := range tests {
2906 test.protocol = protocol
2907 test.name += suffix
2908 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2909 test.flags = append(test.flags, flags...)
2910 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002911 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002912}
2913
Adam Langley524e7172015-02-20 16:04:00 -08002914func addDDoSCallbackTests() {
2915 // DDoS callback.
2916
2917 for _, resume := range []bool{false, true} {
2918 suffix := "Resume"
2919 if resume {
2920 suffix = "No" + suffix
2921 }
2922
2923 testCases = append(testCases, testCase{
2924 testType: serverTest,
2925 name: "Server-DDoS-OK-" + suffix,
2926 flags: []string{"-install-ddos-callback"},
2927 resumeSession: resume,
2928 })
2929
2930 failFlag := "-fail-ddos-callback"
2931 if resume {
2932 failFlag = "-fail-second-ddos-callback"
2933 }
2934 testCases = append(testCases, testCase{
2935 testType: serverTest,
2936 name: "Server-DDoS-Reject-" + suffix,
2937 flags: []string{"-install-ddos-callback", failFlag},
2938 resumeSession: resume,
2939 shouldFail: true,
2940 expectedError: ":CONNECTION_REJECTED:",
2941 })
2942 }
2943}
2944
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002945func addVersionNegotiationTests() {
2946 for i, shimVers := range tlsVersions {
2947 // Assemble flags to disable all newer versions on the shim.
2948 var flags []string
2949 for _, vers := range tlsVersions[i+1:] {
2950 flags = append(flags, vers.flag)
2951 }
2952
2953 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002954 protocols := []protocol{tls}
2955 if runnerVers.hasDTLS && shimVers.hasDTLS {
2956 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002957 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002958 for _, protocol := range protocols {
2959 expectedVersion := shimVers.version
2960 if runnerVers.version < shimVers.version {
2961 expectedVersion = runnerVers.version
2962 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002963
David Benjamin8b8c0062014-11-23 02:47:52 -05002964 suffix := shimVers.name + "-" + runnerVers.name
2965 if protocol == dtls {
2966 suffix += "-DTLS"
2967 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002968
David Benjamin1eb367c2014-12-12 18:17:51 -05002969 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2970
David Benjamin1e29a6b2014-12-10 02:27:24 -05002971 clientVers := shimVers.version
2972 if clientVers > VersionTLS10 {
2973 clientVers = VersionTLS10
2974 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002975 testCases = append(testCases, testCase{
2976 protocol: protocol,
2977 testType: clientTest,
2978 name: "VersionNegotiation-Client-" + suffix,
2979 config: Config{
2980 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002981 Bugs: ProtocolBugs{
2982 ExpectInitialRecordVersion: clientVers,
2983 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002984 },
2985 flags: flags,
2986 expectedVersion: expectedVersion,
2987 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002988 testCases = append(testCases, testCase{
2989 protocol: protocol,
2990 testType: clientTest,
2991 name: "VersionNegotiation-Client2-" + suffix,
2992 config: Config{
2993 MaxVersion: runnerVers.version,
2994 Bugs: ProtocolBugs{
2995 ExpectInitialRecordVersion: clientVers,
2996 },
2997 },
2998 flags: []string{"-max-version", shimVersFlag},
2999 expectedVersion: expectedVersion,
3000 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003001
3002 testCases = append(testCases, testCase{
3003 protocol: protocol,
3004 testType: serverTest,
3005 name: "VersionNegotiation-Server-" + suffix,
3006 config: Config{
3007 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003008 Bugs: ProtocolBugs{
3009 ExpectInitialRecordVersion: expectedVersion,
3010 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003011 },
3012 flags: flags,
3013 expectedVersion: expectedVersion,
3014 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003015 testCases = append(testCases, testCase{
3016 protocol: protocol,
3017 testType: serverTest,
3018 name: "VersionNegotiation-Server2-" + suffix,
3019 config: Config{
3020 MaxVersion: runnerVers.version,
3021 Bugs: ProtocolBugs{
3022 ExpectInitialRecordVersion: expectedVersion,
3023 },
3024 },
3025 flags: []string{"-max-version", shimVersFlag},
3026 expectedVersion: expectedVersion,
3027 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003028 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003029 }
3030 }
3031}
3032
David Benjaminaccb4542014-12-12 23:44:33 -05003033func addMinimumVersionTests() {
3034 for i, shimVers := range tlsVersions {
3035 // Assemble flags to disable all older versions on the shim.
3036 var flags []string
3037 for _, vers := range tlsVersions[:i] {
3038 flags = append(flags, vers.flag)
3039 }
3040
3041 for _, runnerVers := range tlsVersions {
3042 protocols := []protocol{tls}
3043 if runnerVers.hasDTLS && shimVers.hasDTLS {
3044 protocols = append(protocols, dtls)
3045 }
3046 for _, protocol := range protocols {
3047 suffix := shimVers.name + "-" + runnerVers.name
3048 if protocol == dtls {
3049 suffix += "-DTLS"
3050 }
3051 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3052
David Benjaminaccb4542014-12-12 23:44:33 -05003053 var expectedVersion uint16
3054 var shouldFail bool
3055 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003056 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003057 if runnerVers.version >= shimVers.version {
3058 expectedVersion = runnerVers.version
3059 } else {
3060 shouldFail = true
3061 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003062 if runnerVers.version > VersionSSL30 {
3063 expectedLocalError = "remote error: protocol version not supported"
3064 } else {
3065 expectedLocalError = "remote error: handshake failure"
3066 }
David Benjaminaccb4542014-12-12 23:44:33 -05003067 }
3068
3069 testCases = append(testCases, testCase{
3070 protocol: protocol,
3071 testType: clientTest,
3072 name: "MinimumVersion-Client-" + suffix,
3073 config: Config{
3074 MaxVersion: runnerVers.version,
3075 },
David Benjamin87909c02014-12-13 01:55:01 -05003076 flags: flags,
3077 expectedVersion: expectedVersion,
3078 shouldFail: shouldFail,
3079 expectedError: expectedError,
3080 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003081 })
3082 testCases = append(testCases, testCase{
3083 protocol: protocol,
3084 testType: clientTest,
3085 name: "MinimumVersion-Client2-" + suffix,
3086 config: Config{
3087 MaxVersion: runnerVers.version,
3088 },
David Benjamin87909c02014-12-13 01:55:01 -05003089 flags: []string{"-min-version", shimVersFlag},
3090 expectedVersion: expectedVersion,
3091 shouldFail: shouldFail,
3092 expectedError: expectedError,
3093 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003094 })
3095
3096 testCases = append(testCases, testCase{
3097 protocol: protocol,
3098 testType: serverTest,
3099 name: "MinimumVersion-Server-" + suffix,
3100 config: Config{
3101 MaxVersion: runnerVers.version,
3102 },
David Benjamin87909c02014-12-13 01:55:01 -05003103 flags: flags,
3104 expectedVersion: expectedVersion,
3105 shouldFail: shouldFail,
3106 expectedError: expectedError,
3107 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003108 })
3109 testCases = append(testCases, testCase{
3110 protocol: protocol,
3111 testType: serverTest,
3112 name: "MinimumVersion-Server2-" + suffix,
3113 config: Config{
3114 MaxVersion: runnerVers.version,
3115 },
David Benjamin87909c02014-12-13 01:55:01 -05003116 flags: []string{"-min-version", shimVersFlag},
3117 expectedVersion: expectedVersion,
3118 shouldFail: shouldFail,
3119 expectedError: expectedError,
3120 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003121 })
3122 }
3123 }
3124 }
3125}
3126
David Benjamin5c24a1d2014-08-31 00:59:27 -04003127func addD5BugTests() {
3128 testCases = append(testCases, testCase{
3129 testType: serverTest,
3130 name: "D5Bug-NoQuirk-Reject",
3131 config: Config{
3132 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3133 Bugs: ProtocolBugs{
3134 SSL3RSAKeyExchange: true,
3135 },
3136 },
3137 shouldFail: true,
3138 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3139 })
3140 testCases = append(testCases, testCase{
3141 testType: serverTest,
3142 name: "D5Bug-Quirk-Normal",
3143 config: Config{
3144 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3145 },
3146 flags: []string{"-tls-d5-bug"},
3147 })
3148 testCases = append(testCases, testCase{
3149 testType: serverTest,
3150 name: "D5Bug-Quirk-Bug",
3151 config: Config{
3152 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3153 Bugs: ProtocolBugs{
3154 SSL3RSAKeyExchange: true,
3155 },
3156 },
3157 flags: []string{"-tls-d5-bug"},
3158 })
3159}
3160
David Benjamine78bfde2014-09-06 12:45:15 -04003161func addExtensionTests() {
3162 testCases = append(testCases, testCase{
3163 testType: clientTest,
3164 name: "DuplicateExtensionClient",
3165 config: Config{
3166 Bugs: ProtocolBugs{
3167 DuplicateExtension: true,
3168 },
3169 },
3170 shouldFail: true,
3171 expectedLocalError: "remote error: error decoding message",
3172 })
3173 testCases = append(testCases, testCase{
3174 testType: serverTest,
3175 name: "DuplicateExtensionServer",
3176 config: Config{
3177 Bugs: ProtocolBugs{
3178 DuplicateExtension: true,
3179 },
3180 },
3181 shouldFail: true,
3182 expectedLocalError: "remote error: error decoding message",
3183 })
3184 testCases = append(testCases, testCase{
3185 testType: clientTest,
3186 name: "ServerNameExtensionClient",
3187 config: Config{
3188 Bugs: ProtocolBugs{
3189 ExpectServerName: "example.com",
3190 },
3191 },
3192 flags: []string{"-host-name", "example.com"},
3193 })
3194 testCases = append(testCases, testCase{
3195 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003196 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003197 config: Config{
3198 Bugs: ProtocolBugs{
3199 ExpectServerName: "mismatch.com",
3200 },
3201 },
3202 flags: []string{"-host-name", "example.com"},
3203 shouldFail: true,
3204 expectedLocalError: "tls: unexpected server name",
3205 })
3206 testCases = append(testCases, testCase{
3207 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003208 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003209 config: Config{
3210 Bugs: ProtocolBugs{
3211 ExpectServerName: "missing.com",
3212 },
3213 },
3214 shouldFail: true,
3215 expectedLocalError: "tls: unexpected server name",
3216 })
3217 testCases = append(testCases, testCase{
3218 testType: serverTest,
3219 name: "ServerNameExtensionServer",
3220 config: Config{
3221 ServerName: "example.com",
3222 },
3223 flags: []string{"-expect-server-name", "example.com"},
3224 resumeSession: true,
3225 })
David Benjaminae2888f2014-09-06 12:58:58 -04003226 testCases = append(testCases, testCase{
3227 testType: clientTest,
3228 name: "ALPNClient",
3229 config: Config{
3230 NextProtos: []string{"foo"},
3231 },
3232 flags: []string{
3233 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3234 "-expect-alpn", "foo",
3235 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003236 expectedNextProto: "foo",
3237 expectedNextProtoType: alpn,
3238 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003239 })
3240 testCases = append(testCases, testCase{
3241 testType: serverTest,
3242 name: "ALPNServer",
3243 config: Config{
3244 NextProtos: []string{"foo", "bar", "baz"},
3245 },
3246 flags: []string{
3247 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3248 "-select-alpn", "foo",
3249 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003250 expectedNextProto: "foo",
3251 expectedNextProtoType: alpn,
3252 resumeSession: true,
3253 })
3254 // Test that the server prefers ALPN over NPN.
3255 testCases = append(testCases, testCase{
3256 testType: serverTest,
3257 name: "ALPNServer-Preferred",
3258 config: Config{
3259 NextProtos: []string{"foo", "bar", "baz"},
3260 },
3261 flags: []string{
3262 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3263 "-select-alpn", "foo",
3264 "-advertise-npn", "\x03foo\x03bar\x03baz",
3265 },
3266 expectedNextProto: "foo",
3267 expectedNextProtoType: alpn,
3268 resumeSession: true,
3269 })
3270 testCases = append(testCases, testCase{
3271 testType: serverTest,
3272 name: "ALPNServer-Preferred-Swapped",
3273 config: Config{
3274 NextProtos: []string{"foo", "bar", "baz"},
3275 Bugs: ProtocolBugs{
3276 SwapNPNAndALPN: true,
3277 },
3278 },
3279 flags: []string{
3280 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3281 "-select-alpn", "foo",
3282 "-advertise-npn", "\x03foo\x03bar\x03baz",
3283 },
3284 expectedNextProto: "foo",
3285 expectedNextProtoType: alpn,
3286 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003287 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003288 var emptyString string
3289 testCases = append(testCases, testCase{
3290 testType: clientTest,
3291 name: "ALPNClient-EmptyProtocolName",
3292 config: Config{
3293 NextProtos: []string{""},
3294 Bugs: ProtocolBugs{
3295 // A server returning an empty ALPN protocol
3296 // should be rejected.
3297 ALPNProtocol: &emptyString,
3298 },
3299 },
3300 flags: []string{
3301 "-advertise-alpn", "\x03foo",
3302 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003303 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003304 expectedError: ":PARSE_TLSEXT:",
3305 })
3306 testCases = append(testCases, testCase{
3307 testType: serverTest,
3308 name: "ALPNServer-EmptyProtocolName",
3309 config: Config{
3310 // A ClientHello containing an empty ALPN protocol
3311 // should be rejected.
3312 NextProtos: []string{"foo", "", "baz"},
3313 },
3314 flags: []string{
3315 "-select-alpn", "foo",
3316 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003317 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003318 expectedError: ":PARSE_TLSEXT:",
3319 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003320 // Test that negotiating both NPN and ALPN is forbidden.
3321 testCases = append(testCases, testCase{
3322 name: "NegotiateALPNAndNPN",
3323 config: Config{
3324 NextProtos: []string{"foo", "bar", "baz"},
3325 Bugs: ProtocolBugs{
3326 NegotiateALPNAndNPN: true,
3327 },
3328 },
3329 flags: []string{
3330 "-advertise-alpn", "\x03foo",
3331 "-select-next-proto", "foo",
3332 },
3333 shouldFail: true,
3334 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3335 })
3336 testCases = append(testCases, testCase{
3337 name: "NegotiateALPNAndNPN-Swapped",
3338 config: Config{
3339 NextProtos: []string{"foo", "bar", "baz"},
3340 Bugs: ProtocolBugs{
3341 NegotiateALPNAndNPN: true,
3342 SwapNPNAndALPN: true,
3343 },
3344 },
3345 flags: []string{
3346 "-advertise-alpn", "\x03foo",
3347 "-select-next-proto", "foo",
3348 },
3349 shouldFail: true,
3350 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3351 })
Adam Langley38311732014-10-16 19:04:35 -07003352 // Resume with a corrupt ticket.
3353 testCases = append(testCases, testCase{
3354 testType: serverTest,
3355 name: "CorruptTicket",
3356 config: Config{
3357 Bugs: ProtocolBugs{
3358 CorruptTicket: true,
3359 },
3360 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003361 resumeSession: true,
3362 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003363 })
David Benjamind98452d2015-06-16 14:16:23 -04003364 // Test the ticket callback, with and without renewal.
3365 testCases = append(testCases, testCase{
3366 testType: serverTest,
3367 name: "TicketCallback",
3368 resumeSession: true,
3369 flags: []string{"-use-ticket-callback"},
3370 })
3371 testCases = append(testCases, testCase{
3372 testType: serverTest,
3373 name: "TicketCallback-Renew",
3374 config: Config{
3375 Bugs: ProtocolBugs{
3376 ExpectNewTicket: true,
3377 },
3378 },
3379 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3380 resumeSession: true,
3381 })
Adam Langley38311732014-10-16 19:04:35 -07003382 // Resume with an oversized session id.
3383 testCases = append(testCases, testCase{
3384 testType: serverTest,
3385 name: "OversizedSessionId",
3386 config: Config{
3387 Bugs: ProtocolBugs{
3388 OversizedSessionId: true,
3389 },
3390 },
3391 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003392 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003393 expectedError: ":DECODE_ERROR:",
3394 })
David Benjaminca6c8262014-11-15 19:06:08 -05003395 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3396 // are ignored.
3397 testCases = append(testCases, testCase{
3398 protocol: dtls,
3399 name: "SRTP-Client",
3400 config: Config{
3401 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3402 },
3403 flags: []string{
3404 "-srtp-profiles",
3405 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3406 },
3407 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3408 })
3409 testCases = append(testCases, testCase{
3410 protocol: dtls,
3411 testType: serverTest,
3412 name: "SRTP-Server",
3413 config: Config{
3414 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3415 },
3416 flags: []string{
3417 "-srtp-profiles",
3418 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3419 },
3420 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3421 })
3422 // Test that the MKI is ignored.
3423 testCases = append(testCases, testCase{
3424 protocol: dtls,
3425 testType: serverTest,
3426 name: "SRTP-Server-IgnoreMKI",
3427 config: Config{
3428 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3429 Bugs: ProtocolBugs{
3430 SRTPMasterKeyIdentifer: "bogus",
3431 },
3432 },
3433 flags: []string{
3434 "-srtp-profiles",
3435 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3436 },
3437 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3438 })
3439 // Test that SRTP isn't negotiated on the server if there were
3440 // no matching profiles.
3441 testCases = append(testCases, testCase{
3442 protocol: dtls,
3443 testType: serverTest,
3444 name: "SRTP-Server-NoMatch",
3445 config: Config{
3446 SRTPProtectionProfiles: []uint16{100, 101, 102},
3447 },
3448 flags: []string{
3449 "-srtp-profiles",
3450 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3451 },
3452 expectedSRTPProtectionProfile: 0,
3453 })
3454 // Test that the server returning an invalid SRTP profile is
3455 // flagged as an error by the client.
3456 testCases = append(testCases, testCase{
3457 protocol: dtls,
3458 name: "SRTP-Client-NoMatch",
3459 config: Config{
3460 Bugs: ProtocolBugs{
3461 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3462 },
3463 },
3464 flags: []string{
3465 "-srtp-profiles",
3466 "SRTP_AES128_CM_SHA1_80",
3467 },
3468 shouldFail: true,
3469 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3470 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003471 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003472 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003473 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003474 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003475 flags: []string{
3476 "-enable-signed-cert-timestamps",
3477 "-expect-signed-cert-timestamps",
3478 base64.StdEncoding.EncodeToString(testSCTList),
3479 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003480 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003481 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003482 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003483 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003484 testType: serverTest,
3485 flags: []string{
3486 "-signed-cert-timestamps",
3487 base64.StdEncoding.EncodeToString(testSCTList),
3488 },
3489 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003490 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003491 })
3492 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003493 testType: clientTest,
3494 name: "ClientHelloPadding",
3495 config: Config{
3496 Bugs: ProtocolBugs{
3497 RequireClientHelloSize: 512,
3498 },
3499 },
3500 // This hostname just needs to be long enough to push the
3501 // ClientHello into F5's danger zone between 256 and 511 bytes
3502 // long.
3503 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3504 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003505
3506 // Extensions should not function in SSL 3.0.
3507 testCases = append(testCases, testCase{
3508 testType: serverTest,
3509 name: "SSLv3Extensions-NoALPN",
3510 config: Config{
3511 MaxVersion: VersionSSL30,
3512 NextProtos: []string{"foo", "bar", "baz"},
3513 },
3514 flags: []string{
3515 "-select-alpn", "foo",
3516 },
3517 expectNoNextProto: true,
3518 })
3519
3520 // Test session tickets separately as they follow a different codepath.
3521 testCases = append(testCases, testCase{
3522 testType: serverTest,
3523 name: "SSLv3Extensions-NoTickets",
3524 config: Config{
3525 MaxVersion: VersionSSL30,
3526 Bugs: ProtocolBugs{
3527 // Historically, session tickets in SSL 3.0
3528 // failed in different ways depending on whether
3529 // the client supported renegotiation_info.
3530 NoRenegotiationInfo: true,
3531 },
3532 },
3533 resumeSession: true,
3534 })
3535 testCases = append(testCases, testCase{
3536 testType: serverTest,
3537 name: "SSLv3Extensions-NoTickets2",
3538 config: Config{
3539 MaxVersion: VersionSSL30,
3540 },
3541 resumeSession: true,
3542 })
3543
3544 // But SSL 3.0 does send and process renegotiation_info.
3545 testCases = append(testCases, testCase{
3546 testType: serverTest,
3547 name: "SSLv3Extensions-RenegotiationInfo",
3548 config: Config{
3549 MaxVersion: VersionSSL30,
3550 Bugs: ProtocolBugs{
3551 RequireRenegotiationInfo: true,
3552 },
3553 },
3554 })
3555 testCases = append(testCases, testCase{
3556 testType: serverTest,
3557 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3558 config: Config{
3559 MaxVersion: VersionSSL30,
3560 Bugs: ProtocolBugs{
3561 NoRenegotiationInfo: true,
3562 SendRenegotiationSCSV: true,
3563 RequireRenegotiationInfo: true,
3564 },
3565 },
3566 })
David Benjamine78bfde2014-09-06 12:45:15 -04003567}
3568
David Benjamin01fe8202014-09-24 15:21:44 -04003569func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003570 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003571 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003572 protocols := []protocol{tls}
3573 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3574 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003575 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003576 for _, protocol := range protocols {
3577 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3578 if protocol == dtls {
3579 suffix += "-DTLS"
3580 }
3581
David Benjaminece3de92015-03-16 18:02:20 -04003582 if sessionVers.version == resumeVers.version {
3583 testCases = append(testCases, testCase{
3584 protocol: protocol,
3585 name: "Resume-Client" + suffix,
3586 resumeSession: true,
3587 config: Config{
3588 MaxVersion: sessionVers.version,
3589 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003590 },
David Benjaminece3de92015-03-16 18:02:20 -04003591 expectedVersion: sessionVers.version,
3592 expectedResumeVersion: resumeVers.version,
3593 })
3594 } else {
3595 testCases = append(testCases, testCase{
3596 protocol: protocol,
3597 name: "Resume-Client-Mismatch" + suffix,
3598 resumeSession: true,
3599 config: Config{
3600 MaxVersion: sessionVers.version,
3601 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003602 },
David Benjaminece3de92015-03-16 18:02:20 -04003603 expectedVersion: sessionVers.version,
3604 resumeConfig: &Config{
3605 MaxVersion: resumeVers.version,
3606 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3607 Bugs: ProtocolBugs{
3608 AllowSessionVersionMismatch: true,
3609 },
3610 },
3611 expectedResumeVersion: resumeVers.version,
3612 shouldFail: true,
3613 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3614 })
3615 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003616
3617 testCases = append(testCases, testCase{
3618 protocol: protocol,
3619 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003620 resumeSession: true,
3621 config: Config{
3622 MaxVersion: sessionVers.version,
3623 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3624 },
3625 expectedVersion: sessionVers.version,
3626 resumeConfig: &Config{
3627 MaxVersion: resumeVers.version,
3628 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3629 },
3630 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003631 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003632 expectedResumeVersion: resumeVers.version,
3633 })
3634
David Benjamin8b8c0062014-11-23 02:47:52 -05003635 testCases = append(testCases, testCase{
3636 protocol: protocol,
3637 testType: serverTest,
3638 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003639 resumeSession: true,
3640 config: Config{
3641 MaxVersion: sessionVers.version,
3642 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3643 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003644 expectedVersion: sessionVers.version,
3645 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003646 resumeConfig: &Config{
3647 MaxVersion: resumeVers.version,
3648 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3649 },
3650 expectedResumeVersion: resumeVers.version,
3651 })
3652 }
David Benjamin01fe8202014-09-24 15:21:44 -04003653 }
3654 }
David Benjaminece3de92015-03-16 18:02:20 -04003655
3656 testCases = append(testCases, testCase{
3657 name: "Resume-Client-CipherMismatch",
3658 resumeSession: true,
3659 config: Config{
3660 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3661 },
3662 resumeConfig: &Config{
3663 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3664 Bugs: ProtocolBugs{
3665 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3666 },
3667 },
3668 shouldFail: true,
3669 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3670 })
David Benjamin01fe8202014-09-24 15:21:44 -04003671}
3672
Adam Langley2ae77d22014-10-28 17:29:33 -07003673func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003674 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003675 testCases = append(testCases, testCase{
3676 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003677 name: "Renegotiate-Server-Forbidden",
David Benjaminb16346b2015-04-08 19:16:58 -04003678 renegotiate: true,
3679 flags: []string{"-reject-peer-renegotiations"},
3680 shouldFail: true,
3681 expectedError: ":NO_RENEGOTIATION:",
3682 expectedLocalError: "remote error: no renegotiation",
3683 })
Adam Langley5021b222015-06-12 18:27:58 -07003684 // The server shouldn't echo the renegotiation extension unless
3685 // requested by the client.
3686 testCases = append(testCases, testCase{
3687 testType: serverTest,
3688 name: "Renegotiate-Server-NoExt",
3689 config: Config{
3690 Bugs: ProtocolBugs{
3691 NoRenegotiationInfo: true,
3692 RequireRenegotiationInfo: true,
3693 },
3694 },
3695 shouldFail: true,
3696 expectedLocalError: "renegotiation extension missing",
3697 })
3698 // The renegotiation SCSV should be sufficient for the server to echo
3699 // the extension.
3700 testCases = append(testCases, testCase{
3701 testType: serverTest,
3702 name: "Renegotiate-Server-NoExt-SCSV",
3703 config: Config{
3704 Bugs: ProtocolBugs{
3705 NoRenegotiationInfo: true,
3706 SendRenegotiationSCSV: true,
3707 RequireRenegotiationInfo: true,
3708 },
3709 },
3710 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003711 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003712 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003713 config: Config{
3714 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003715 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003716 },
3717 },
3718 renegotiate: true,
David Benjamin324dce42015-10-12 19:49:00 -04003719 flags: []string{"-expect-total-renegotiations", "1"},
David Benjamincdea40c2015-03-19 14:09:43 -04003720 })
3721 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003722 name: "Renegotiate-Client-EmptyExt",
3723 renegotiate: true,
3724 config: Config{
3725 Bugs: ProtocolBugs{
3726 EmptyRenegotiationInfo: true,
3727 },
3728 },
3729 shouldFail: true,
3730 expectedError: ":RENEGOTIATION_MISMATCH:",
3731 })
3732 testCases = append(testCases, testCase{
3733 name: "Renegotiate-Client-BadExt",
3734 renegotiate: true,
3735 config: Config{
3736 Bugs: ProtocolBugs{
3737 BadRenegotiationInfo: true,
3738 },
3739 },
3740 shouldFail: true,
3741 expectedError: ":RENEGOTIATION_MISMATCH:",
3742 })
3743 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003744 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003745 config: Config{
3746 Bugs: ProtocolBugs{
3747 NoRenegotiationInfo: true,
3748 },
3749 },
3750 shouldFail: true,
3751 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3752 flags: []string{"-no-legacy-server-connect"},
3753 })
3754 testCases = append(testCases, testCase{
3755 name: "Renegotiate-Client-NoExt-Allowed",
3756 renegotiate: true,
3757 config: Config{
3758 Bugs: ProtocolBugs{
3759 NoRenegotiationInfo: true,
3760 },
3761 },
David Benjamin324dce42015-10-12 19:49:00 -04003762 flags: []string{"-expect-total-renegotiations", "1"},
David Benjamincff0b902015-05-15 23:09:47 -04003763 })
3764 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003765 name: "Renegotiate-Client-SwitchCiphers",
3766 renegotiate: true,
3767 config: Config{
3768 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3769 },
3770 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin324dce42015-10-12 19:49:00 -04003771 flags: []string{"-expect-total-renegotiations", "1"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003772 })
3773 testCases = append(testCases, testCase{
3774 name: "Renegotiate-Client-SwitchCiphers2",
3775 renegotiate: true,
3776 config: Config{
3777 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3778 },
3779 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin324dce42015-10-12 19:49:00 -04003780 flags: []string{"-expect-total-renegotiations", "1"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003781 })
David Benjaminc44b1df2014-11-23 12:11:01 -05003782 testCases = append(testCases, testCase{
David Benjaminb16346b2015-04-08 19:16:58 -04003783 name: "Renegotiate-Client-Forbidden",
3784 renegotiate: true,
3785 flags: []string{"-reject-peer-renegotiations"},
3786 shouldFail: true,
3787 expectedError: ":NO_RENEGOTIATION:",
3788 expectedLocalError: "remote error: no renegotiation",
3789 })
3790 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003791 name: "Renegotiate-SameClientVersion",
3792 renegotiate: true,
3793 config: Config{
3794 MaxVersion: VersionTLS10,
3795 Bugs: ProtocolBugs{
3796 RequireSameRenegoClientVersion: true,
3797 },
3798 },
David Benjamin324dce42015-10-12 19:49:00 -04003799 flags: []string{"-expect-total-renegotiations", "1"},
David Benjaminc44b1df2014-11-23 12:11:01 -05003800 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003801 testCases = append(testCases, testCase{
3802 name: "Renegotiate-FalseStart",
3803 renegotiate: true,
3804 config: Config{
3805 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3806 NextProtos: []string{"foo"},
3807 },
3808 flags: []string{
3809 "-false-start",
3810 "-select-next-proto", "foo",
David Benjamin324dce42015-10-12 19:49:00 -04003811 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003812 },
3813 shimWritesFirst: true,
3814 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003815}
3816
David Benjamin5e961c12014-11-07 01:48:35 -05003817func addDTLSReplayTests() {
3818 // Test that sequence number replays are detected.
3819 testCases = append(testCases, testCase{
3820 protocol: dtls,
3821 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003822 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003823 replayWrites: true,
3824 })
3825
David Benjamin8e6db492015-07-25 18:29:23 -04003826 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003827 // than the retransmit window.
3828 testCases = append(testCases, testCase{
3829 protocol: dtls,
3830 name: "DTLS-Replay-LargeGaps",
3831 config: Config{
3832 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003833 SequenceNumberMapping: func(in uint64) uint64 {
3834 return in * 127
3835 },
David Benjamin5e961c12014-11-07 01:48:35 -05003836 },
3837 },
David Benjamin8e6db492015-07-25 18:29:23 -04003838 messageCount: 200,
3839 replayWrites: true,
3840 })
3841
3842 // Test the incoming sequence number changing non-monotonically.
3843 testCases = append(testCases, testCase{
3844 protocol: dtls,
3845 name: "DTLS-Replay-NonMonotonic",
3846 config: Config{
3847 Bugs: ProtocolBugs{
3848 SequenceNumberMapping: func(in uint64) uint64 {
3849 return in ^ 31
3850 },
3851 },
3852 },
3853 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003854 replayWrites: true,
3855 })
3856}
3857
David Benjamin000800a2014-11-14 01:43:59 -05003858var testHashes = []struct {
3859 name string
3860 id uint8
3861}{
3862 {"SHA1", hashSHA1},
3863 {"SHA224", hashSHA224},
3864 {"SHA256", hashSHA256},
3865 {"SHA384", hashSHA384},
3866 {"SHA512", hashSHA512},
3867}
3868
3869func addSigningHashTests() {
3870 // Make sure each hash works. Include some fake hashes in the list and
3871 // ensure they're ignored.
3872 for _, hash := range testHashes {
3873 testCases = append(testCases, testCase{
3874 name: "SigningHash-ClientAuth-" + hash.name,
3875 config: Config{
3876 ClientAuth: RequireAnyClientCert,
3877 SignatureAndHashes: []signatureAndHash{
3878 {signatureRSA, 42},
3879 {signatureRSA, hash.id},
3880 {signatureRSA, 255},
3881 },
3882 },
3883 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003884 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3885 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003886 },
3887 })
3888
3889 testCases = append(testCases, testCase{
3890 testType: serverTest,
3891 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3892 config: Config{
3893 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3894 SignatureAndHashes: []signatureAndHash{
3895 {signatureRSA, 42},
3896 {signatureRSA, hash.id},
3897 {signatureRSA, 255},
3898 },
3899 },
3900 })
3901 }
3902
3903 // Test that hash resolution takes the signature type into account.
3904 testCases = append(testCases, testCase{
3905 name: "SigningHash-ClientAuth-SignatureType",
3906 config: Config{
3907 ClientAuth: RequireAnyClientCert,
3908 SignatureAndHashes: []signatureAndHash{
3909 {signatureECDSA, hashSHA512},
3910 {signatureRSA, hashSHA384},
3911 {signatureECDSA, hashSHA1},
3912 },
3913 },
3914 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003915 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3916 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003917 },
3918 })
3919
3920 testCases = append(testCases, testCase{
3921 testType: serverTest,
3922 name: "SigningHash-ServerKeyExchange-SignatureType",
3923 config: Config{
3924 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3925 SignatureAndHashes: []signatureAndHash{
3926 {signatureECDSA, hashSHA512},
3927 {signatureRSA, hashSHA384},
3928 {signatureECDSA, hashSHA1},
3929 },
3930 },
3931 })
3932
3933 // Test that, if the list is missing, the peer falls back to SHA-1.
3934 testCases = append(testCases, testCase{
3935 name: "SigningHash-ClientAuth-Fallback",
3936 config: Config{
3937 ClientAuth: RequireAnyClientCert,
3938 SignatureAndHashes: []signatureAndHash{
3939 {signatureRSA, hashSHA1},
3940 },
3941 Bugs: ProtocolBugs{
3942 NoSignatureAndHashes: true,
3943 },
3944 },
3945 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003946 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3947 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003948 },
3949 })
3950
3951 testCases = append(testCases, testCase{
3952 testType: serverTest,
3953 name: "SigningHash-ServerKeyExchange-Fallback",
3954 config: Config{
3955 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3956 SignatureAndHashes: []signatureAndHash{
3957 {signatureRSA, hashSHA1},
3958 },
3959 Bugs: ProtocolBugs{
3960 NoSignatureAndHashes: true,
3961 },
3962 },
3963 })
David Benjamin72dc7832015-03-16 17:49:43 -04003964
3965 // Test that hash preferences are enforced. BoringSSL defaults to
3966 // rejecting MD5 signatures.
3967 testCases = append(testCases, testCase{
3968 testType: serverTest,
3969 name: "SigningHash-ClientAuth-Enforced",
3970 config: Config{
3971 Certificates: []Certificate{rsaCertificate},
3972 SignatureAndHashes: []signatureAndHash{
3973 {signatureRSA, hashMD5},
3974 // Advertise SHA-1 so the handshake will
3975 // proceed, but the shim's preferences will be
3976 // ignored in CertificateVerify generation, so
3977 // MD5 will be chosen.
3978 {signatureRSA, hashSHA1},
3979 },
3980 Bugs: ProtocolBugs{
3981 IgnorePeerSignatureAlgorithmPreferences: true,
3982 },
3983 },
3984 flags: []string{"-require-any-client-certificate"},
3985 shouldFail: true,
3986 expectedError: ":WRONG_SIGNATURE_TYPE:",
3987 })
3988
3989 testCases = append(testCases, testCase{
3990 name: "SigningHash-ServerKeyExchange-Enforced",
3991 config: Config{
3992 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3993 SignatureAndHashes: []signatureAndHash{
3994 {signatureRSA, hashMD5},
3995 },
3996 Bugs: ProtocolBugs{
3997 IgnorePeerSignatureAlgorithmPreferences: true,
3998 },
3999 },
4000 shouldFail: true,
4001 expectedError: ":WRONG_SIGNATURE_TYPE:",
4002 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004003
4004 // Test that the agreed upon digest respects the client preferences and
4005 // the server digests.
4006 testCases = append(testCases, testCase{
4007 name: "Agree-Digest-Fallback",
4008 config: Config{
4009 ClientAuth: RequireAnyClientCert,
4010 SignatureAndHashes: []signatureAndHash{
4011 {signatureRSA, hashSHA512},
4012 {signatureRSA, hashSHA1},
4013 },
4014 },
4015 flags: []string{
4016 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4017 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4018 },
4019 digestPrefs: "SHA256",
4020 expectedClientCertSignatureHash: hashSHA1,
4021 })
4022 testCases = append(testCases, testCase{
4023 name: "Agree-Digest-SHA256",
4024 config: Config{
4025 ClientAuth: RequireAnyClientCert,
4026 SignatureAndHashes: []signatureAndHash{
4027 {signatureRSA, hashSHA1},
4028 {signatureRSA, hashSHA256},
4029 },
4030 },
4031 flags: []string{
4032 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4033 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4034 },
4035 digestPrefs: "SHA256,SHA1",
4036 expectedClientCertSignatureHash: hashSHA256,
4037 })
4038 testCases = append(testCases, testCase{
4039 name: "Agree-Digest-SHA1",
4040 config: Config{
4041 ClientAuth: RequireAnyClientCert,
4042 SignatureAndHashes: []signatureAndHash{
4043 {signatureRSA, hashSHA1},
4044 },
4045 },
4046 flags: []string{
4047 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4048 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4049 },
4050 digestPrefs: "SHA512,SHA256,SHA1",
4051 expectedClientCertSignatureHash: hashSHA1,
4052 })
4053 testCases = append(testCases, testCase{
4054 name: "Agree-Digest-Default",
4055 config: Config{
4056 ClientAuth: RequireAnyClientCert,
4057 SignatureAndHashes: []signatureAndHash{
4058 {signatureRSA, hashSHA256},
4059 {signatureECDSA, hashSHA256},
4060 {signatureRSA, hashSHA1},
4061 {signatureECDSA, hashSHA1},
4062 },
4063 },
4064 flags: []string{
4065 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4066 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4067 },
4068 expectedClientCertSignatureHash: hashSHA256,
4069 })
David Benjamin000800a2014-11-14 01:43:59 -05004070}
4071
David Benjamin83f90402015-01-27 01:09:43 -05004072// timeouts is the retransmit schedule for BoringSSL. It doubles and
4073// caps at 60 seconds. On the 13th timeout, it gives up.
4074var timeouts = []time.Duration{
4075 1 * time.Second,
4076 2 * time.Second,
4077 4 * time.Second,
4078 8 * time.Second,
4079 16 * time.Second,
4080 32 * time.Second,
4081 60 * time.Second,
4082 60 * time.Second,
4083 60 * time.Second,
4084 60 * time.Second,
4085 60 * time.Second,
4086 60 * time.Second,
4087 60 * time.Second,
4088}
4089
4090func addDTLSRetransmitTests() {
4091 // Test that this is indeed the timeout schedule. Stress all
4092 // four patterns of handshake.
4093 for i := 1; i < len(timeouts); i++ {
4094 number := strconv.Itoa(i)
4095 testCases = append(testCases, testCase{
4096 protocol: dtls,
4097 name: "DTLS-Retransmit-Client-" + number,
4098 config: Config{
4099 Bugs: ProtocolBugs{
4100 TimeoutSchedule: timeouts[:i],
4101 },
4102 },
4103 resumeSession: true,
4104 flags: []string{"-async"},
4105 })
4106 testCases = append(testCases, testCase{
4107 protocol: dtls,
4108 testType: serverTest,
4109 name: "DTLS-Retransmit-Server-" + number,
4110 config: Config{
4111 Bugs: ProtocolBugs{
4112 TimeoutSchedule: timeouts[:i],
4113 },
4114 },
4115 resumeSession: true,
4116 flags: []string{"-async"},
4117 })
4118 }
4119
4120 // Test that exceeding the timeout schedule hits a read
4121 // timeout.
4122 testCases = append(testCases, testCase{
4123 protocol: dtls,
4124 name: "DTLS-Retransmit-Timeout",
4125 config: Config{
4126 Bugs: ProtocolBugs{
4127 TimeoutSchedule: timeouts,
4128 },
4129 },
4130 resumeSession: true,
4131 flags: []string{"-async"},
4132 shouldFail: true,
4133 expectedError: ":READ_TIMEOUT_EXPIRED:",
4134 })
4135
4136 // Test that timeout handling has a fudge factor, due to API
4137 // problems.
4138 testCases = append(testCases, testCase{
4139 protocol: dtls,
4140 name: "DTLS-Retransmit-Fudge",
4141 config: Config{
4142 Bugs: ProtocolBugs{
4143 TimeoutSchedule: []time.Duration{
4144 timeouts[0] - 10*time.Millisecond,
4145 },
4146 },
4147 },
4148 resumeSession: true,
4149 flags: []string{"-async"},
4150 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004151
4152 // Test that the final Finished retransmitting isn't
4153 // duplicated if the peer badly fragments everything.
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 protocol: dtls,
4157 name: "DTLS-Retransmit-Fragmented",
4158 config: Config{
4159 Bugs: ProtocolBugs{
4160 TimeoutSchedule: []time.Duration{timeouts[0]},
4161 MaxHandshakeRecordLength: 2,
4162 },
4163 },
4164 flags: []string{"-async"},
4165 })
David Benjamin83f90402015-01-27 01:09:43 -05004166}
4167
David Benjaminc565ebb2015-04-03 04:06:36 -04004168func addExportKeyingMaterialTests() {
4169 for _, vers := range tlsVersions {
4170 if vers.version == VersionSSL30 {
4171 continue
4172 }
4173 testCases = append(testCases, testCase{
4174 name: "ExportKeyingMaterial-" + vers.name,
4175 config: Config{
4176 MaxVersion: vers.version,
4177 },
4178 exportKeyingMaterial: 1024,
4179 exportLabel: "label",
4180 exportContext: "context",
4181 useExportContext: true,
4182 })
4183 testCases = append(testCases, testCase{
4184 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4185 config: Config{
4186 MaxVersion: vers.version,
4187 },
4188 exportKeyingMaterial: 1024,
4189 })
4190 testCases = append(testCases, testCase{
4191 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4192 config: Config{
4193 MaxVersion: vers.version,
4194 },
4195 exportKeyingMaterial: 1024,
4196 useExportContext: true,
4197 })
4198 testCases = append(testCases, testCase{
4199 name: "ExportKeyingMaterial-Small-" + vers.name,
4200 config: Config{
4201 MaxVersion: vers.version,
4202 },
4203 exportKeyingMaterial: 1,
4204 exportLabel: "label",
4205 exportContext: "context",
4206 useExportContext: true,
4207 })
4208 }
4209 testCases = append(testCases, testCase{
4210 name: "ExportKeyingMaterial-SSL3",
4211 config: Config{
4212 MaxVersion: VersionSSL30,
4213 },
4214 exportKeyingMaterial: 1024,
4215 exportLabel: "label",
4216 exportContext: "context",
4217 useExportContext: true,
4218 shouldFail: true,
4219 expectedError: "failed to export keying material",
4220 })
4221}
4222
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004223func addTLSUniqueTests() {
4224 for _, isClient := range []bool{false, true} {
4225 for _, isResumption := range []bool{false, true} {
4226 for _, hasEMS := range []bool{false, true} {
4227 var suffix string
4228 if isResumption {
4229 suffix = "Resume-"
4230 } else {
4231 suffix = "Full-"
4232 }
4233
4234 if hasEMS {
4235 suffix += "EMS-"
4236 } else {
4237 suffix += "NoEMS-"
4238 }
4239
4240 if isClient {
4241 suffix += "Client"
4242 } else {
4243 suffix += "Server"
4244 }
4245
4246 test := testCase{
4247 name: "TLSUnique-" + suffix,
4248 testTLSUnique: true,
4249 config: Config{
4250 Bugs: ProtocolBugs{
4251 NoExtendedMasterSecret: !hasEMS,
4252 },
4253 },
4254 }
4255
4256 if isResumption {
4257 test.resumeSession = true
4258 test.resumeConfig = &Config{
4259 Bugs: ProtocolBugs{
4260 NoExtendedMasterSecret: !hasEMS,
4261 },
4262 }
4263 }
4264
4265 if isResumption && !hasEMS {
4266 test.shouldFail = true
4267 test.expectedError = "failed to get tls-unique"
4268 }
4269
4270 testCases = append(testCases, test)
4271 }
4272 }
4273 }
4274}
4275
Adam Langley09505632015-07-30 18:10:13 -07004276func addCustomExtensionTests() {
4277 expectedContents := "custom extension"
4278 emptyString := ""
4279
4280 for _, isClient := range []bool{false, true} {
4281 suffix := "Server"
4282 flag := "-enable-server-custom-extension"
4283 testType := serverTest
4284 if isClient {
4285 suffix = "Client"
4286 flag = "-enable-client-custom-extension"
4287 testType = clientTest
4288 }
4289
4290 testCases = append(testCases, testCase{
4291 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004292 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004293 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004294 Bugs: ProtocolBugs{
4295 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004296 ExpectedCustomExtension: &expectedContents,
4297 },
4298 },
4299 flags: []string{flag},
4300 })
4301
4302 // If the parse callback fails, the handshake should also fail.
4303 testCases = append(testCases, testCase{
4304 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004305 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004306 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004307 Bugs: ProtocolBugs{
4308 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004309 ExpectedCustomExtension: &expectedContents,
4310 },
4311 },
David Benjamin399e7c92015-07-30 23:01:27 -04004312 flags: []string{flag},
4313 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004314 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4315 })
4316
4317 // If the add callback fails, the handshake should also fail.
4318 testCases = append(testCases, testCase{
4319 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004320 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004321 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004322 Bugs: ProtocolBugs{
4323 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004324 ExpectedCustomExtension: &expectedContents,
4325 },
4326 },
David Benjamin399e7c92015-07-30 23:01:27 -04004327 flags: []string{flag, "-custom-extension-fail-add"},
4328 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004329 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4330 })
4331
4332 // If the add callback returns zero, no extension should be
4333 // added.
4334 skipCustomExtension := expectedContents
4335 if isClient {
4336 // For the case where the client skips sending the
4337 // custom extension, the server must not “echo” it.
4338 skipCustomExtension = ""
4339 }
4340 testCases = append(testCases, testCase{
4341 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004342 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004343 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004344 Bugs: ProtocolBugs{
4345 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004346 ExpectedCustomExtension: &emptyString,
4347 },
4348 },
4349 flags: []string{flag, "-custom-extension-skip"},
4350 })
4351 }
4352
4353 // The custom extension add callback should not be called if the client
4354 // doesn't send the extension.
4355 testCases = append(testCases, testCase{
4356 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004357 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004358 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004359 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004360 ExpectedCustomExtension: &emptyString,
4361 },
4362 },
4363 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4364 })
Adam Langley2deb9842015-08-07 11:15:37 -07004365
4366 // Test an unknown extension from the server.
4367 testCases = append(testCases, testCase{
4368 testType: clientTest,
4369 name: "UnknownExtension-Client",
4370 config: Config{
4371 Bugs: ProtocolBugs{
4372 CustomExtension: expectedContents,
4373 },
4374 },
4375 shouldFail: true,
4376 expectedError: ":UNEXPECTED_EXTENSION:",
4377 })
Adam Langley09505632015-07-30 18:10:13 -07004378}
4379
Adam Langley7c803a62015-06-15 15:35:05 -07004380func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004381 defer wg.Done()
4382
4383 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004384 var err error
4385
4386 if *mallocTest < 0 {
4387 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004388 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004389 } else {
4390 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4391 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004392 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004393 if err != nil {
4394 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4395 }
4396 break
4397 }
4398 }
4399 }
Adam Langley95c29f32014-06-20 12:00:00 -07004400 statusChan <- statusMsg{test: test, err: err}
4401 }
4402}
4403
4404type statusMsg struct {
4405 test *testCase
4406 started bool
4407 err error
4408}
4409
David Benjamin5f237bc2015-02-11 17:14:15 -05004410func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004411 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004412
David Benjamin5f237bc2015-02-11 17:14:15 -05004413 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004414 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004415 if !*pipe {
4416 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004417 var erase string
4418 for i := 0; i < lineLen; i++ {
4419 erase += "\b \b"
4420 }
4421 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004422 }
4423
Adam Langley95c29f32014-06-20 12:00:00 -07004424 if msg.started {
4425 started++
4426 } else {
4427 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004428
4429 if msg.err != nil {
4430 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4431 failed++
4432 testOutput.addResult(msg.test.name, "FAIL")
4433 } else {
4434 if *pipe {
4435 // Print each test instead of a status line.
4436 fmt.Printf("PASSED (%s)\n", msg.test.name)
4437 }
4438 testOutput.addResult(msg.test.name, "PASS")
4439 }
Adam Langley95c29f32014-06-20 12:00:00 -07004440 }
4441
David Benjamin5f237bc2015-02-11 17:14:15 -05004442 if !*pipe {
4443 // Print a new status line.
4444 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4445 lineLen = len(line)
4446 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004447 }
Adam Langley95c29f32014-06-20 12:00:00 -07004448 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004449
4450 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004451}
4452
4453func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004454 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004455 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004456
Adam Langley7c803a62015-06-15 15:35:05 -07004457 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004458 addCipherSuiteTests()
4459 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004460 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004461 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004462 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004463 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004464 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004465 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004466 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004467 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004468 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004469 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004470 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004471 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004472 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004473 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004474 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004475 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004476 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004477 for _, async := range []bool{false, true} {
4478 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004479 for _, protocol := range []protocol{tls, dtls} {
4480 addStateMachineCoverageTests(async, splitHandshake, protocol)
4481 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004482 }
4483 }
Adam Langley95c29f32014-06-20 12:00:00 -07004484
4485 var wg sync.WaitGroup
4486
Adam Langley7c803a62015-06-15 15:35:05 -07004487 statusChan := make(chan statusMsg, *numWorkers)
4488 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004489 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004490
David Benjamin025b3d32014-07-01 19:53:04 -04004491 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004492
Adam Langley7c803a62015-06-15 15:35:05 -07004493 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004494 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004495 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004496 }
4497
David Benjamin025b3d32014-07-01 19:53:04 -04004498 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004499 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004500 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004501 }
4502 }
4503
4504 close(testChan)
4505 wg.Wait()
4506 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004507 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004508
4509 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004510
4511 if *jsonOutput != "" {
4512 if err := testOutput.writeTo(*jsonOutput); err != nil {
4513 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4514 }
4515 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004516
4517 if !testOutput.allPassed {
4518 os.Exit(1)
4519 }
Adam Langley95c29f32014-06-20 12:00:00 -07004520}