blob: ad8e12a8f1c5d7e029cc4be787eb796e7f74e045 [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
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400209 // renegotiate indicates the number of times the connection should be
210 // renegotiated during the exchange.
211 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700212 // 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 Benjamin5fa3eba2015-01-22 16:35:40 -0500247 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500248
David Benjamin6fd297b2014-08-11 18:43:38 -0400249 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500250 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
251 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500252 }
253
254 if *flagDebug {
255 local, peer := "client", "server"
256 if test.testType == clientTest {
257 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500258 }
David Benjaminebda9b32015-11-02 15:33:18 -0500259 connDebug := &recordingConn{
260 Conn: conn,
261 isDatagram: test.protocol == dtls,
262 local: local,
263 peer: peer,
264 }
265 conn = connDebug
266 defer func() {
267 connDebug.WriteTo(os.Stdout)
268 }()
269
270 if config.Bugs.PacketAdaptor != nil {
271 config.Bugs.PacketAdaptor.debug = connDebug
272 }
273 }
274
275 if test.replayWrites {
276 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400277 }
278
David Benjamin5fa3eba2015-01-22 16:35:40 -0500279 if test.damageFirstWrite {
280 connDamage = newDamageAdaptor(conn)
281 conn = connDamage
282 }
283
David Benjamin6fd297b2014-08-11 18:43:38 -0400284 if test.sendPrefix != "" {
285 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
286 return err
287 }
David Benjamin98e882e2014-08-08 13:24:34 -0400288 }
289
David Benjamin1d5c83e2014-07-22 19:20:02 -0400290 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400291 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400292 if test.protocol == dtls {
293 tlsConn = DTLSServer(conn, config)
294 } else {
295 tlsConn = Server(conn, config)
296 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400297 } else {
298 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400299 if test.protocol == dtls {
300 tlsConn = DTLSClient(conn, config)
301 } else {
302 tlsConn = Client(conn, config)
303 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400304 }
David Benjamin30789da2015-08-29 22:56:45 -0400305 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400306
Adam Langley95c29f32014-06-20 12:00:00 -0700307 if err := tlsConn.Handshake(); err != nil {
308 return err
309 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700310
David Benjamin01fe8202014-09-24 15:21:44 -0400311 // TODO(davidben): move all per-connection expectations into a dedicated
312 // expectations struct that can be specified separately for the two
313 // legs.
314 expectedVersion := test.expectedVersion
315 if isResume && test.expectedResumeVersion != 0 {
316 expectedVersion = test.expectedResumeVersion
317 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700318 connState := tlsConn.ConnectionState()
319 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400320 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400321 }
322
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700323 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400324 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
325 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700326 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
327 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
328 }
David Benjamin90da8c82015-04-20 14:57:57 -0400329
David Benjamina08e49d2014-08-24 01:46:07 -0400330 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700331 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400332 if channelID == nil {
333 return fmt.Errorf("no channel ID negotiated")
334 }
335 if channelID.Curve != channelIDKey.Curve ||
336 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
337 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
338 return fmt.Errorf("incorrect channel ID")
339 }
340 }
341
David Benjaminae2888f2014-09-06 12:58:58 -0400342 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700343 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400344 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
345 }
346 }
347
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 if test.expectNoNextProto {
349 if actual := connState.NegotiatedProtocol; actual != "" {
350 return fmt.Errorf("got unexpected next proto %s", actual)
351 }
352 }
353
David Benjaminfc7b0862014-09-06 13:21:53 -0400354 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700355 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400356 return fmt.Errorf("next proto type mismatch")
357 }
358 }
359
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700360 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500361 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
362 }
363
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100364 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
365 return fmt.Errorf("OCSP Response mismatch")
366 }
367
Paul Lietar4fac72e2015-09-09 13:44:55 +0100368 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
369 return fmt.Errorf("SCT list mismatch")
370 }
371
Steven Valdez0d62f262015-09-04 12:41:04 -0400372 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
373 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
374 }
375
David Benjaminc565ebb2015-04-03 04:06:36 -0400376 if test.exportKeyingMaterial > 0 {
377 actual := make([]byte, test.exportKeyingMaterial)
378 if _, err := io.ReadFull(tlsConn, actual); err != nil {
379 return err
380 }
381 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
382 if err != nil {
383 return err
384 }
385 if !bytes.Equal(actual, expected) {
386 return fmt.Errorf("keying material mismatch")
387 }
388 }
389
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700390 if test.testTLSUnique {
391 var peersValue [12]byte
392 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
393 return err
394 }
395 expected := tlsConn.ConnectionState().TLSUnique
396 if !bytes.Equal(peersValue[:], expected) {
397 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
398 }
399 }
400
David Benjamine58c4f52014-08-24 03:47:07 -0400401 if test.shimWritesFirst {
402 var buf [5]byte
403 _, err := io.ReadFull(tlsConn, buf[:])
404 if err != nil {
405 return err
406 }
407 if string(buf[:]) != "hello" {
408 return fmt.Errorf("bad initial message")
409 }
410 }
411
David Benjamina8ebe222015-06-06 03:04:39 -0400412 for i := 0; i < test.sendEmptyRecords; i++ {
413 tlsConn.Write(nil)
414 }
415
David Benjamin24f346d2015-06-06 03:28:08 -0400416 for i := 0; i < test.sendWarningAlerts; i++ {
417 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
418 }
419
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400420 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700421 if test.renegotiateCiphers != nil {
422 config.CipherSuites = test.renegotiateCiphers
423 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400424 for i := 0; i < test.renegotiate; i++ {
425 if err := tlsConn.Renegotiate(); err != nil {
426 return err
427 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700428 }
429 } else if test.renegotiateCiphers != nil {
430 panic("renegotiateCiphers without renegotiate")
431 }
432
David Benjamin5fa3eba2015-01-22 16:35:40 -0500433 if test.damageFirstWrite {
434 connDamage.setDamage(true)
435 tlsConn.Write([]byte("DAMAGED WRITE"))
436 connDamage.setDamage(false)
437 }
438
David Benjamin8e6db492015-07-25 18:29:23 -0400439 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700440 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400441 if test.protocol == dtls {
442 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
443 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700444 // Read until EOF.
445 _, err := io.Copy(ioutil.Discard, tlsConn)
446 return err
447 }
David Benjamin4417d052015-04-05 04:17:25 -0400448 if messageLen == 0 {
449 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700450 }
Adam Langley95c29f32014-06-20 12:00:00 -0700451
David Benjamin8e6db492015-07-25 18:29:23 -0400452 messageCount := test.messageCount
453 if messageCount == 0 {
454 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400455 }
456
David Benjamin8e6db492015-07-25 18:29:23 -0400457 for j := 0; j < messageCount; j++ {
458 testMessage := make([]byte, messageLen)
459 for i := range testMessage {
460 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400461 }
David Benjamin8e6db492015-07-25 18:29:23 -0400462 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700463
David Benjamin8e6db492015-07-25 18:29:23 -0400464 for i := 0; i < test.sendEmptyRecords; i++ {
465 tlsConn.Write(nil)
466 }
467
468 for i := 0; i < test.sendWarningAlerts; i++ {
469 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
470 }
471
David Benjamin4f75aaf2015-09-01 16:53:10 -0400472 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400473 // The shim will not respond.
474 continue
475 }
476
David Benjamin8e6db492015-07-25 18:29:23 -0400477 buf := make([]byte, len(testMessage))
478 if test.protocol == dtls {
479 bufTmp := make([]byte, len(buf)+1)
480 n, err := tlsConn.Read(bufTmp)
481 if err != nil {
482 return err
483 }
484 if n != len(buf) {
485 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
486 }
487 copy(buf, bufTmp)
488 } else {
489 _, err := io.ReadFull(tlsConn, buf)
490 if err != nil {
491 return err
492 }
493 }
494
495 for i, v := range buf {
496 if v != testMessage[i]^0xff {
497 return fmt.Errorf("bad reply contents at byte %d", i)
498 }
Adam Langley95c29f32014-06-20 12:00:00 -0700499 }
500 }
501
502 return nil
503}
504
David Benjamin325b5c32014-07-01 19:40:31 -0400505func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
506 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700507 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400508 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700509 }
David Benjamin325b5c32014-07-01 19:40:31 -0400510 valgrindArgs = append(valgrindArgs, path)
511 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700512
David Benjamin325b5c32014-07-01 19:40:31 -0400513 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700514}
515
David Benjamin325b5c32014-07-01 19:40:31 -0400516func gdbOf(path string, args ...string) *exec.Cmd {
517 xtermArgs := []string{"-e", "gdb", "--args"}
518 xtermArgs = append(xtermArgs, path)
519 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700520
David Benjamin325b5c32014-07-01 19:40:31 -0400521 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700522}
523
Adam Langley69a01602014-11-17 17:26:55 -0800524type moreMallocsError struct{}
525
526func (moreMallocsError) Error() string {
527 return "child process did not exhaust all allocation calls"
528}
529
530var errMoreMallocs = moreMallocsError{}
531
David Benjamin87c8a642015-02-21 01:54:29 -0500532// accept accepts a connection from listener, unless waitChan signals a process
533// exit first.
534func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
535 type connOrError struct {
536 conn net.Conn
537 err error
538 }
539 connChan := make(chan connOrError, 1)
540 go func() {
541 conn, err := listener.Accept()
542 connChan <- connOrError{conn, err}
543 close(connChan)
544 }()
545 select {
546 case result := <-connChan:
547 return result.conn, result.err
548 case childErr := <-waitChan:
549 waitChan <- childErr
550 return nil, fmt.Errorf("child exited early: %s", childErr)
551 }
552}
553
Adam Langley7c803a62015-06-15 15:35:05 -0700554func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700555 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
556 panic("Error expected without shouldFail in " + test.name)
557 }
558
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700559 if test.expectResumeRejected && !test.resumeSession {
560 panic("expectResumeRejected without resumeSession in " + test.name)
561 }
562
Steven Valdez0d62f262015-09-04 12:41:04 -0400563 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
564 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
565 }
566
David Benjamin87c8a642015-02-21 01:54:29 -0500567 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
568 if err != nil {
569 panic(err)
570 }
571 defer func() {
572 if listener != nil {
573 listener.Close()
574 }
575 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700576
David Benjamin87c8a642015-02-21 01:54:29 -0500577 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400578 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400579 flags = append(flags, "-server")
580
David Benjamin025b3d32014-07-01 19:53:04 -0400581 flags = append(flags, "-key-file")
582 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700583 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400584 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700585 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400586 }
587
588 flags = append(flags, "-cert-file")
589 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700590 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400591 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700592 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400593 }
594 }
David Benjamin5a593af2014-08-11 19:51:50 -0400595
Steven Valdez0d62f262015-09-04 12:41:04 -0400596 if test.digestPrefs != "" {
597 flags = append(flags, "-digest-prefs")
598 flags = append(flags, test.digestPrefs)
599 }
600
David Benjamin6fd297b2014-08-11 18:43:38 -0400601 if test.protocol == dtls {
602 flags = append(flags, "-dtls")
603 }
604
David Benjamin5a593af2014-08-11 19:51:50 -0400605 if test.resumeSession {
606 flags = append(flags, "-resume")
607 }
608
David Benjamine58c4f52014-08-24 03:47:07 -0400609 if test.shimWritesFirst {
610 flags = append(flags, "-shim-writes-first")
611 }
612
David Benjamin30789da2015-08-29 22:56:45 -0400613 if test.shimShutsDown {
614 flags = append(flags, "-shim-shuts-down")
615 }
616
David Benjaminc565ebb2015-04-03 04:06:36 -0400617 if test.exportKeyingMaterial > 0 {
618 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
619 flags = append(flags, "-export-label", test.exportLabel)
620 flags = append(flags, "-export-context", test.exportContext)
621 if test.useExportContext {
622 flags = append(flags, "-use-export-context")
623 }
624 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700625 if test.expectResumeRejected {
626 flags = append(flags, "-expect-session-miss")
627 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400628
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700629 if test.testTLSUnique {
630 flags = append(flags, "-tls-unique")
631 }
632
David Benjamin025b3d32014-07-01 19:53:04 -0400633 flags = append(flags, test.flags...)
634
635 var shim *exec.Cmd
636 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700637 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700638 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700639 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400640 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700641 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400642 }
David Benjamin025b3d32014-07-01 19:53:04 -0400643 shim.Stdin = os.Stdin
644 var stdoutBuf, stderrBuf bytes.Buffer
645 shim.Stdout = &stdoutBuf
646 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800647 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500648 shim.Env = os.Environ()
649 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800650 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400651 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800652 }
653 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
654 }
David Benjamin025b3d32014-07-01 19:53:04 -0400655
656 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700657 panic(err)
658 }
David Benjamin87c8a642015-02-21 01:54:29 -0500659 waitChan := make(chan error, 1)
660 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700661
662 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400663 if !test.noSessionCache {
664 config.ClientSessionCache = NewLRUClientSessionCache(1)
665 config.ServerSessionCache = NewLRUServerSessionCache(1)
666 }
David Benjamin025b3d32014-07-01 19:53:04 -0400667 if test.testType == clientTest {
668 if len(config.Certificates) == 0 {
669 config.Certificates = []Certificate{getRSACertificate()}
670 }
David Benjamin87c8a642015-02-21 01:54:29 -0500671 } else {
672 // Supply a ServerName to ensure a constant session cache key,
673 // rather than falling back to net.Conn.RemoteAddr.
674 if len(config.ServerName) == 0 {
675 config.ServerName = "test"
676 }
David Benjamin025b3d32014-07-01 19:53:04 -0400677 }
Adam Langley95c29f32014-06-20 12:00:00 -0700678
David Benjamin87c8a642015-02-21 01:54:29 -0500679 conn, err := acceptOrWait(listener, waitChan)
680 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400681 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500682 conn.Close()
683 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500684
David Benjamin1d5c83e2014-07-22 19:20:02 -0400685 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400686 var resumeConfig Config
687 if test.resumeConfig != nil {
688 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500689 if len(resumeConfig.ServerName) == 0 {
690 resumeConfig.ServerName = config.ServerName
691 }
David Benjamin01fe8202014-09-24 15:21:44 -0400692 if len(resumeConfig.Certificates) == 0 {
693 resumeConfig.Certificates = []Certificate{getRSACertificate()}
694 }
David Benjaminba4594a2015-06-18 18:36:15 -0400695 if test.newSessionsOnResume {
696 if !test.noSessionCache {
697 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
698 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
699 }
700 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500701 resumeConfig.SessionTicketKey = config.SessionTicketKey
702 resumeConfig.ClientSessionCache = config.ClientSessionCache
703 resumeConfig.ServerSessionCache = config.ServerSessionCache
704 }
David Benjamin01fe8202014-09-24 15:21:44 -0400705 } else {
706 resumeConfig = config
707 }
David Benjamin87c8a642015-02-21 01:54:29 -0500708 var connResume net.Conn
709 connResume, err = acceptOrWait(listener, waitChan)
710 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400711 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500712 connResume.Close()
713 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400714 }
715
David Benjamin87c8a642015-02-21 01:54:29 -0500716 // Close the listener now. This is to avoid hangs should the shim try to
717 // open more connections than expected.
718 listener.Close()
719 listener = nil
720
721 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800722 if exitError, ok := childErr.(*exec.ExitError); ok {
723 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
724 return errMoreMallocs
725 }
726 }
Adam Langley95c29f32014-06-20 12:00:00 -0700727
728 stdout := string(stdoutBuf.Bytes())
729 stderr := string(stderrBuf.Bytes())
730 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400731 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700732 localError := "none"
733 if err != nil {
734 localError = err.Error()
735 }
736 if len(test.expectedLocalError) != 0 {
737 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
738 }
Adam Langley95c29f32014-06-20 12:00:00 -0700739
740 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700741 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700742 if childErr != nil {
743 childError = childErr.Error()
744 }
745
746 var msg string
747 switch {
748 case failed && !test.shouldFail:
749 msg = "unexpected failure"
750 case !failed && test.shouldFail:
751 msg = "unexpected success"
752 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700753 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700754 default:
755 panic("internal error")
756 }
757
David Benjaminc565ebb2015-04-03 04:06:36 -0400758 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 -0700759 }
760
David Benjaminc565ebb2015-04-03 04:06:36 -0400761 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700762 println(stderr)
763 }
764
765 return nil
766}
767
768var tlsVersions = []struct {
769 name string
770 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400771 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500772 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700773}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500774 {"SSL3", VersionSSL30, "-no-ssl3", false},
775 {"TLS1", VersionTLS10, "-no-tls1", true},
776 {"TLS11", VersionTLS11, "-no-tls11", false},
777 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700778}
779
780var testCipherSuites = []struct {
781 name string
782 id uint16
783}{
784 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400785 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700786 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400787 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400788 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700789 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400790 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400791 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
792 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400793 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400794 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
795 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400796 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700797 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
798 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400799 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
800 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700801 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400802 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400803 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700804 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700805 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700806 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400807 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400808 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700809 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400810 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400811 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700812 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400813 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
814 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700815 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
816 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400817 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700818 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400819 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700820 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700821}
822
David Benjamin8b8c0062014-11-23 02:47:52 -0500823func hasComponent(suiteName, component string) bool {
824 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
825}
826
David Benjaminf7768e42014-08-31 02:06:47 -0400827func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500828 return hasComponent(suiteName, "GCM") ||
829 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400830 hasComponent(suiteName, "SHA384") ||
831 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500832}
833
834func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700835 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400836}
837
Adam Langleya7997f12015-05-14 17:38:50 -0700838func bigFromHex(hex string) *big.Int {
839 ret, ok := new(big.Int).SetString(hex, 16)
840 if !ok {
841 panic("failed to parse hex number 0x" + hex)
842 }
843 return ret
844}
845
Adam Langley7c803a62015-06-15 15:35:05 -0700846func addBasicTests() {
847 basicTests := []testCase{
848 {
849 name: "BadRSASignature",
850 config: Config{
851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
852 Bugs: ProtocolBugs{
853 InvalidSKXSignature: true,
854 },
855 },
856 shouldFail: true,
857 expectedError: ":BAD_SIGNATURE:",
858 },
859 {
860 name: "BadECDSASignature",
861 config: Config{
862 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
863 Bugs: ProtocolBugs{
864 InvalidSKXSignature: true,
865 },
866 Certificates: []Certificate{getECDSACertificate()},
867 },
868 shouldFail: true,
869 expectedError: ":BAD_SIGNATURE:",
870 },
871 {
David Benjamin6de0e532015-07-28 22:43:19 -0400872 testType: serverTest,
873 name: "BadRSASignature-ClientAuth",
874 config: Config{
875 Bugs: ProtocolBugs{
876 InvalidCertVerifySignature: true,
877 },
878 Certificates: []Certificate{getRSACertificate()},
879 },
880 shouldFail: true,
881 expectedError: ":BAD_SIGNATURE:",
882 flags: []string{"-require-any-client-certificate"},
883 },
884 {
885 testType: serverTest,
886 name: "BadECDSASignature-ClientAuth",
887 config: Config{
888 Bugs: ProtocolBugs{
889 InvalidCertVerifySignature: true,
890 },
891 Certificates: []Certificate{getECDSACertificate()},
892 },
893 shouldFail: true,
894 expectedError: ":BAD_SIGNATURE:",
895 flags: []string{"-require-any-client-certificate"},
896 },
897 {
Adam Langley7c803a62015-06-15 15:35:05 -0700898 name: "BadECDSACurve",
899 config: Config{
900 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
901 Bugs: ProtocolBugs{
902 InvalidSKXCurve: true,
903 },
904 Certificates: []Certificate{getECDSACertificate()},
905 },
906 shouldFail: true,
907 expectedError: ":WRONG_CURVE:",
908 },
909 {
910 testType: serverTest,
911 name: "BadRSAVersion",
912 config: Config{
913 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
914 Bugs: ProtocolBugs{
915 RsaClientKeyExchangeVersion: VersionTLS11,
916 },
917 },
918 shouldFail: true,
919 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
920 },
921 {
922 name: "NoFallbackSCSV",
923 config: Config{
924 Bugs: ProtocolBugs{
925 FailIfNotFallbackSCSV: true,
926 },
927 },
928 shouldFail: true,
929 expectedLocalError: "no fallback SCSV found",
930 },
931 {
932 name: "SendFallbackSCSV",
933 config: Config{
934 Bugs: ProtocolBugs{
935 FailIfNotFallbackSCSV: true,
936 },
937 },
938 flags: []string{"-fallback-scsv"},
939 },
940 {
941 name: "ClientCertificateTypes",
942 config: Config{
943 ClientAuth: RequestClientCert,
944 ClientCertificateTypes: []byte{
945 CertTypeDSSSign,
946 CertTypeRSASign,
947 CertTypeECDSASign,
948 },
949 },
950 flags: []string{
951 "-expect-certificate-types",
952 base64.StdEncoding.EncodeToString([]byte{
953 CertTypeDSSSign,
954 CertTypeRSASign,
955 CertTypeECDSASign,
956 }),
957 },
958 },
959 {
960 name: "NoClientCertificate",
961 config: Config{
962 ClientAuth: RequireAnyClientCert,
963 },
964 shouldFail: true,
965 expectedLocalError: "client didn't provide a certificate",
966 },
967 {
968 name: "UnauthenticatedECDH",
969 config: Config{
970 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
971 Bugs: ProtocolBugs{
972 UnauthenticatedECDH: true,
973 },
974 },
975 shouldFail: true,
976 expectedError: ":UNEXPECTED_MESSAGE:",
977 },
978 {
979 name: "SkipCertificateStatus",
980 config: Config{
981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
982 Bugs: ProtocolBugs{
983 SkipCertificateStatus: true,
984 },
985 },
986 flags: []string{
987 "-enable-ocsp-stapling",
988 },
989 },
990 {
991 name: "SkipServerKeyExchange",
992 config: Config{
993 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
994 Bugs: ProtocolBugs{
995 SkipServerKeyExchange: true,
996 },
997 },
998 shouldFail: true,
999 expectedError: ":UNEXPECTED_MESSAGE:",
1000 },
1001 {
1002 name: "SkipChangeCipherSpec-Client",
1003 config: Config{
1004 Bugs: ProtocolBugs{
1005 SkipChangeCipherSpec: true,
1006 },
1007 },
1008 shouldFail: true,
1009 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1010 },
1011 {
1012 testType: serverTest,
1013 name: "SkipChangeCipherSpec-Server",
1014 config: Config{
1015 Bugs: ProtocolBugs{
1016 SkipChangeCipherSpec: true,
1017 },
1018 },
1019 shouldFail: true,
1020 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1021 },
1022 {
1023 testType: serverTest,
1024 name: "SkipChangeCipherSpec-Server-NPN",
1025 config: Config{
1026 NextProtos: []string{"bar"},
1027 Bugs: ProtocolBugs{
1028 SkipChangeCipherSpec: true,
1029 },
1030 },
1031 flags: []string{
1032 "-advertise-npn", "\x03foo\x03bar\x03baz",
1033 },
1034 shouldFail: true,
1035 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1036 },
1037 {
1038 name: "FragmentAcrossChangeCipherSpec-Client",
1039 config: Config{
1040 Bugs: ProtocolBugs{
1041 FragmentAcrossChangeCipherSpec: true,
1042 },
1043 },
1044 shouldFail: true,
1045 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1046 },
1047 {
1048 testType: serverTest,
1049 name: "FragmentAcrossChangeCipherSpec-Server",
1050 config: Config{
1051 Bugs: ProtocolBugs{
1052 FragmentAcrossChangeCipherSpec: true,
1053 },
1054 },
1055 shouldFail: true,
1056 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1057 },
1058 {
1059 testType: serverTest,
1060 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1061 config: Config{
1062 NextProtos: []string{"bar"},
1063 Bugs: ProtocolBugs{
1064 FragmentAcrossChangeCipherSpec: true,
1065 },
1066 },
1067 flags: []string{
1068 "-advertise-npn", "\x03foo\x03bar\x03baz",
1069 },
1070 shouldFail: true,
1071 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1072 },
1073 {
1074 testType: serverTest,
1075 name: "Alert",
1076 config: Config{
1077 Bugs: ProtocolBugs{
1078 SendSpuriousAlert: alertRecordOverflow,
1079 },
1080 },
1081 shouldFail: true,
1082 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1083 },
1084 {
1085 protocol: dtls,
1086 testType: serverTest,
1087 name: "Alert-DTLS",
1088 config: Config{
1089 Bugs: ProtocolBugs{
1090 SendSpuriousAlert: alertRecordOverflow,
1091 },
1092 },
1093 shouldFail: true,
1094 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1095 },
1096 {
1097 testType: serverTest,
1098 name: "FragmentAlert",
1099 config: Config{
1100 Bugs: ProtocolBugs{
1101 FragmentAlert: true,
1102 SendSpuriousAlert: alertRecordOverflow,
1103 },
1104 },
1105 shouldFail: true,
1106 expectedError: ":BAD_ALERT:",
1107 },
1108 {
1109 protocol: dtls,
1110 testType: serverTest,
1111 name: "FragmentAlert-DTLS",
1112 config: Config{
1113 Bugs: ProtocolBugs{
1114 FragmentAlert: true,
1115 SendSpuriousAlert: alertRecordOverflow,
1116 },
1117 },
1118 shouldFail: true,
1119 expectedError: ":BAD_ALERT:",
1120 },
1121 {
1122 testType: serverTest,
1123 name: "EarlyChangeCipherSpec-server-1",
1124 config: Config{
1125 Bugs: ProtocolBugs{
1126 EarlyChangeCipherSpec: 1,
1127 },
1128 },
1129 shouldFail: true,
1130 expectedError: ":CCS_RECEIVED_EARLY:",
1131 },
1132 {
1133 testType: serverTest,
1134 name: "EarlyChangeCipherSpec-server-2",
1135 config: Config{
1136 Bugs: ProtocolBugs{
1137 EarlyChangeCipherSpec: 2,
1138 },
1139 },
1140 shouldFail: true,
1141 expectedError: ":CCS_RECEIVED_EARLY:",
1142 },
1143 {
1144 name: "SkipNewSessionTicket",
1145 config: Config{
1146 Bugs: ProtocolBugs{
1147 SkipNewSessionTicket: true,
1148 },
1149 },
1150 shouldFail: true,
1151 expectedError: ":CCS_RECEIVED_EARLY:",
1152 },
1153 {
1154 testType: serverTest,
1155 name: "FallbackSCSV",
1156 config: Config{
1157 MaxVersion: VersionTLS11,
1158 Bugs: ProtocolBugs{
1159 SendFallbackSCSV: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":INAPPROPRIATE_FALLBACK:",
1164 },
1165 {
1166 testType: serverTest,
1167 name: "FallbackSCSV-VersionMatch",
1168 config: Config{
1169 Bugs: ProtocolBugs{
1170 SendFallbackSCSV: true,
1171 },
1172 },
1173 },
1174 {
1175 testType: serverTest,
1176 name: "FragmentedClientVersion",
1177 config: Config{
1178 Bugs: ProtocolBugs{
1179 MaxHandshakeRecordLength: 1,
1180 FragmentClientVersion: true,
1181 },
1182 },
1183 expectedVersion: VersionTLS12,
1184 },
1185 {
1186 testType: serverTest,
1187 name: "MinorVersionTolerance",
1188 config: Config{
1189 Bugs: ProtocolBugs{
1190 SendClientVersion: 0x03ff,
1191 },
1192 },
1193 expectedVersion: VersionTLS12,
1194 },
1195 {
1196 testType: serverTest,
1197 name: "MajorVersionTolerance",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 SendClientVersion: 0x0400,
1201 },
1202 },
1203 expectedVersion: VersionTLS12,
1204 },
1205 {
1206 testType: serverTest,
1207 name: "VersionTooLow",
1208 config: Config{
1209 Bugs: ProtocolBugs{
1210 SendClientVersion: 0x0200,
1211 },
1212 },
1213 shouldFail: true,
1214 expectedError: ":UNSUPPORTED_PROTOCOL:",
1215 },
1216 {
1217 testType: serverTest,
1218 name: "HttpGET",
1219 sendPrefix: "GET / HTTP/1.0\n",
1220 shouldFail: true,
1221 expectedError: ":HTTP_REQUEST:",
1222 },
1223 {
1224 testType: serverTest,
1225 name: "HttpPOST",
1226 sendPrefix: "POST / HTTP/1.0\n",
1227 shouldFail: true,
1228 expectedError: ":HTTP_REQUEST:",
1229 },
1230 {
1231 testType: serverTest,
1232 name: "HttpHEAD",
1233 sendPrefix: "HEAD / HTTP/1.0\n",
1234 shouldFail: true,
1235 expectedError: ":HTTP_REQUEST:",
1236 },
1237 {
1238 testType: serverTest,
1239 name: "HttpPUT",
1240 sendPrefix: "PUT / HTTP/1.0\n",
1241 shouldFail: true,
1242 expectedError: ":HTTP_REQUEST:",
1243 },
1244 {
1245 testType: serverTest,
1246 name: "HttpCONNECT",
1247 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1248 shouldFail: true,
1249 expectedError: ":HTTPS_PROXY_REQUEST:",
1250 },
1251 {
1252 testType: serverTest,
1253 name: "Garbage",
1254 sendPrefix: "blah",
1255 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001256 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001257 },
1258 {
1259 name: "SkipCipherVersionCheck",
1260 config: Config{
1261 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1262 MaxVersion: VersionTLS11,
1263 Bugs: ProtocolBugs{
1264 SkipCipherVersionCheck: true,
1265 },
1266 },
1267 shouldFail: true,
1268 expectedError: ":WRONG_CIPHER_RETURNED:",
1269 },
1270 {
1271 name: "RSAEphemeralKey",
1272 config: Config{
1273 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1274 Bugs: ProtocolBugs{
1275 RSAEphemeralKey: true,
1276 },
1277 },
1278 shouldFail: true,
1279 expectedError: ":UNEXPECTED_MESSAGE:",
1280 },
1281 {
1282 name: "DisableEverything",
1283 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1284 shouldFail: true,
1285 expectedError: ":WRONG_SSL_VERSION:",
1286 },
1287 {
1288 protocol: dtls,
1289 name: "DisableEverything-DTLS",
1290 flags: []string{"-no-tls12", "-no-tls1"},
1291 shouldFail: true,
1292 expectedError: ":WRONG_SSL_VERSION:",
1293 },
1294 {
1295 name: "NoSharedCipher",
1296 config: Config{
1297 CipherSuites: []uint16{},
1298 },
1299 shouldFail: true,
1300 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1301 },
1302 {
1303 protocol: dtls,
1304 testType: serverTest,
1305 name: "MTU",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 MaxPacketLength: 256,
1309 },
1310 },
1311 flags: []string{"-mtu", "256"},
1312 },
1313 {
1314 protocol: dtls,
1315 testType: serverTest,
1316 name: "MTUExceeded",
1317 config: Config{
1318 Bugs: ProtocolBugs{
1319 MaxPacketLength: 255,
1320 },
1321 },
1322 flags: []string{"-mtu", "256"},
1323 shouldFail: true,
1324 expectedLocalError: "dtls: exceeded maximum packet length",
1325 },
1326 {
1327 name: "CertMismatchRSA",
1328 config: Config{
1329 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1330 Certificates: []Certificate{getECDSACertificate()},
1331 Bugs: ProtocolBugs{
1332 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1333 },
1334 },
1335 shouldFail: true,
1336 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1337 },
1338 {
1339 name: "CertMismatchECDSA",
1340 config: Config{
1341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1342 Certificates: []Certificate{getRSACertificate()},
1343 Bugs: ProtocolBugs{
1344 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1345 },
1346 },
1347 shouldFail: true,
1348 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1349 },
1350 {
1351 name: "EmptyCertificateList",
1352 config: Config{
1353 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1354 Bugs: ProtocolBugs{
1355 EmptyCertificateList: true,
1356 },
1357 },
1358 shouldFail: true,
1359 expectedError: ":DECODE_ERROR:",
1360 },
1361 {
1362 name: "TLSFatalBadPackets",
1363 damageFirstWrite: true,
1364 shouldFail: true,
1365 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1366 },
1367 {
1368 protocol: dtls,
1369 name: "DTLSIgnoreBadPackets",
1370 damageFirstWrite: true,
1371 },
1372 {
1373 protocol: dtls,
1374 name: "DTLSIgnoreBadPackets-Async",
1375 damageFirstWrite: true,
1376 flags: []string{"-async"},
1377 },
1378 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001379 name: "AppDataBeforeHandshake",
1380 config: Config{
1381 Bugs: ProtocolBugs{
1382 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1383 },
1384 },
1385 shouldFail: true,
1386 expectedError: ":UNEXPECTED_RECORD:",
1387 },
1388 {
1389 name: "AppDataBeforeHandshake-Empty",
1390 config: Config{
1391 Bugs: ProtocolBugs{
1392 AppDataBeforeHandshake: []byte{},
1393 },
1394 },
1395 shouldFail: true,
1396 expectedError: ":UNEXPECTED_RECORD:",
1397 },
1398 {
1399 protocol: dtls,
1400 name: "AppDataBeforeHandshake-DTLS",
1401 config: Config{
1402 Bugs: ProtocolBugs{
1403 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1404 },
1405 },
1406 shouldFail: true,
1407 expectedError: ":UNEXPECTED_RECORD:",
1408 },
1409 {
1410 protocol: dtls,
1411 name: "AppDataBeforeHandshake-DTLS-Empty",
1412 config: Config{
1413 Bugs: ProtocolBugs{
1414 AppDataBeforeHandshake: []byte{},
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":UNEXPECTED_RECORD:",
1419 },
1420 {
Adam Langley7c803a62015-06-15 15:35:05 -07001421 name: "AppDataAfterChangeCipherSpec",
1422 config: Config{
1423 Bugs: ProtocolBugs{
1424 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1425 },
1426 },
1427 shouldFail: true,
1428 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1429 },
1430 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001431 name: "AppDataAfterChangeCipherSpec-Empty",
1432 config: Config{
1433 Bugs: ProtocolBugs{
1434 AppDataAfterChangeCipherSpec: []byte{},
1435 },
1436 },
1437 shouldFail: true,
1438 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1439 },
1440 {
Adam Langley7c803a62015-06-15 15:35:05 -07001441 protocol: dtls,
1442 name: "AppDataAfterChangeCipherSpec-DTLS",
1443 config: Config{
1444 Bugs: ProtocolBugs{
1445 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1446 },
1447 },
1448 // BoringSSL's DTLS implementation will drop the out-of-order
1449 // application data.
1450 },
1451 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001452 protocol: dtls,
1453 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1454 config: Config{
1455 Bugs: ProtocolBugs{
1456 AppDataAfterChangeCipherSpec: []byte{},
1457 },
1458 },
1459 // BoringSSL's DTLS implementation will drop the out-of-order
1460 // application data.
1461 },
1462 {
Adam Langley7c803a62015-06-15 15:35:05 -07001463 name: "AlertAfterChangeCipherSpec",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 AlertAfterChangeCipherSpec: alertRecordOverflow,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1471 },
1472 {
1473 protocol: dtls,
1474 name: "AlertAfterChangeCipherSpec-DTLS",
1475 config: Config{
1476 Bugs: ProtocolBugs{
1477 AlertAfterChangeCipherSpec: alertRecordOverflow,
1478 },
1479 },
1480 shouldFail: true,
1481 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1482 },
1483 {
1484 protocol: dtls,
1485 name: "ReorderHandshakeFragments-Small-DTLS",
1486 config: Config{
1487 Bugs: ProtocolBugs{
1488 ReorderHandshakeFragments: true,
1489 // Small enough that every handshake message is
1490 // fragmented.
1491 MaxHandshakeRecordLength: 2,
1492 },
1493 },
1494 },
1495 {
1496 protocol: dtls,
1497 name: "ReorderHandshakeFragments-Large-DTLS",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 ReorderHandshakeFragments: true,
1501 // Large enough that no handshake message is
1502 // fragmented.
1503 MaxHandshakeRecordLength: 2048,
1504 },
1505 },
1506 },
1507 {
1508 protocol: dtls,
1509 name: "MixCompleteMessageWithFragments-DTLS",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 ReorderHandshakeFragments: true,
1513 MixCompleteMessageWithFragments: true,
1514 MaxHandshakeRecordLength: 2,
1515 },
1516 },
1517 },
1518 {
1519 name: "SendInvalidRecordType",
1520 config: Config{
1521 Bugs: ProtocolBugs{
1522 SendInvalidRecordType: true,
1523 },
1524 },
1525 shouldFail: true,
1526 expectedError: ":UNEXPECTED_RECORD:",
1527 },
1528 {
1529 protocol: dtls,
1530 name: "SendInvalidRecordType-DTLS",
1531 config: Config{
1532 Bugs: ProtocolBugs{
1533 SendInvalidRecordType: true,
1534 },
1535 },
1536 shouldFail: true,
1537 expectedError: ":UNEXPECTED_RECORD:",
1538 },
1539 {
1540 name: "FalseStart-SkipServerSecondLeg",
1541 config: Config{
1542 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1543 NextProtos: []string{"foo"},
1544 Bugs: ProtocolBugs{
1545 SkipNewSessionTicket: true,
1546 SkipChangeCipherSpec: true,
1547 SkipFinished: true,
1548 ExpectFalseStart: true,
1549 },
1550 },
1551 flags: []string{
1552 "-false-start",
1553 "-handshake-never-done",
1554 "-advertise-alpn", "\x03foo",
1555 },
1556 shimWritesFirst: true,
1557 shouldFail: true,
1558 expectedError: ":UNEXPECTED_RECORD:",
1559 },
1560 {
1561 name: "FalseStart-SkipServerSecondLeg-Implicit",
1562 config: Config{
1563 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1564 NextProtos: []string{"foo"},
1565 Bugs: ProtocolBugs{
1566 SkipNewSessionTicket: true,
1567 SkipChangeCipherSpec: true,
1568 SkipFinished: true,
1569 },
1570 },
1571 flags: []string{
1572 "-implicit-handshake",
1573 "-false-start",
1574 "-handshake-never-done",
1575 "-advertise-alpn", "\x03foo",
1576 },
1577 shouldFail: true,
1578 expectedError: ":UNEXPECTED_RECORD:",
1579 },
1580 {
1581 testType: serverTest,
1582 name: "FailEarlyCallback",
1583 flags: []string{"-fail-early-callback"},
1584 shouldFail: true,
1585 expectedError: ":CONNECTION_REJECTED:",
1586 expectedLocalError: "remote error: access denied",
1587 },
1588 {
1589 name: "WrongMessageType",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 WrongCertificateMessageType: true,
1593 },
1594 },
1595 shouldFail: true,
1596 expectedError: ":UNEXPECTED_MESSAGE:",
1597 expectedLocalError: "remote error: unexpected message",
1598 },
1599 {
1600 protocol: dtls,
1601 name: "WrongMessageType-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 WrongCertificateMessageType: true,
1605 },
1606 },
1607 shouldFail: true,
1608 expectedError: ":UNEXPECTED_MESSAGE:",
1609 expectedLocalError: "remote error: unexpected message",
1610 },
1611 {
1612 protocol: dtls,
1613 name: "FragmentMessageTypeMismatch-DTLS",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 MaxHandshakeRecordLength: 2,
1617 FragmentMessageTypeMismatch: true,
1618 },
1619 },
1620 shouldFail: true,
1621 expectedError: ":FRAGMENT_MISMATCH:",
1622 },
1623 {
1624 protocol: dtls,
1625 name: "FragmentMessageLengthMismatch-DTLS",
1626 config: Config{
1627 Bugs: ProtocolBugs{
1628 MaxHandshakeRecordLength: 2,
1629 FragmentMessageLengthMismatch: true,
1630 },
1631 },
1632 shouldFail: true,
1633 expectedError: ":FRAGMENT_MISMATCH:",
1634 },
1635 {
1636 protocol: dtls,
1637 name: "SplitFragments-Header-DTLS",
1638 config: Config{
1639 Bugs: ProtocolBugs{
1640 SplitFragments: 2,
1641 },
1642 },
1643 shouldFail: true,
1644 expectedError: ":UNEXPECTED_MESSAGE:",
1645 },
1646 {
1647 protocol: dtls,
1648 name: "SplitFragments-Boundary-DTLS",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SplitFragments: dtlsRecordHeaderLen,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1656 },
1657 {
1658 protocol: dtls,
1659 name: "SplitFragments-Body-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 SplitFragments: dtlsRecordHeaderLen + 1,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1667 },
1668 {
1669 protocol: dtls,
1670 name: "SendEmptyFragments-DTLS",
1671 config: Config{
1672 Bugs: ProtocolBugs{
1673 SendEmptyFragments: true,
1674 },
1675 },
1676 },
1677 {
1678 name: "UnsupportedCipherSuite",
1679 config: Config{
1680 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1681 Bugs: ProtocolBugs{
1682 IgnorePeerCipherPreferences: true,
1683 },
1684 },
1685 flags: []string{"-cipher", "DEFAULT:!RC4"},
1686 shouldFail: true,
1687 expectedError: ":WRONG_CIPHER_RETURNED:",
1688 },
1689 {
1690 name: "UnsupportedCurve",
1691 config: Config{
1692 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1693 // BoringSSL implements P-224 but doesn't enable it by
1694 // default.
1695 CurvePreferences: []CurveID{CurveP224},
1696 Bugs: ProtocolBugs{
1697 IgnorePeerCurvePreferences: true,
1698 },
1699 },
1700 shouldFail: true,
1701 expectedError: ":WRONG_CURVE:",
1702 },
1703 {
1704 name: "BadFinished",
1705 config: Config{
1706 Bugs: ProtocolBugs{
1707 BadFinished: true,
1708 },
1709 },
1710 shouldFail: true,
1711 expectedError: ":DIGEST_CHECK_FAILED:",
1712 },
1713 {
1714 name: "FalseStart-BadFinished",
1715 config: Config{
1716 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1717 NextProtos: []string{"foo"},
1718 Bugs: ProtocolBugs{
1719 BadFinished: true,
1720 ExpectFalseStart: true,
1721 },
1722 },
1723 flags: []string{
1724 "-false-start",
1725 "-handshake-never-done",
1726 "-advertise-alpn", "\x03foo",
1727 },
1728 shimWritesFirst: true,
1729 shouldFail: true,
1730 expectedError: ":DIGEST_CHECK_FAILED:",
1731 },
1732 {
1733 name: "NoFalseStart-NoALPN",
1734 config: Config{
1735 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1736 Bugs: ProtocolBugs{
1737 ExpectFalseStart: true,
1738 AlertBeforeFalseStartTest: alertAccessDenied,
1739 },
1740 },
1741 flags: []string{
1742 "-false-start",
1743 },
1744 shimWritesFirst: true,
1745 shouldFail: true,
1746 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1747 expectedLocalError: "tls: peer did not false start: EOF",
1748 },
1749 {
1750 name: "NoFalseStart-NoAEAD",
1751 config: Config{
1752 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1753 NextProtos: []string{"foo"},
1754 Bugs: ProtocolBugs{
1755 ExpectFalseStart: true,
1756 AlertBeforeFalseStartTest: alertAccessDenied,
1757 },
1758 },
1759 flags: []string{
1760 "-false-start",
1761 "-advertise-alpn", "\x03foo",
1762 },
1763 shimWritesFirst: true,
1764 shouldFail: true,
1765 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1766 expectedLocalError: "tls: peer did not false start: EOF",
1767 },
1768 {
1769 name: "NoFalseStart-RSA",
1770 config: Config{
1771 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1772 NextProtos: []string{"foo"},
1773 Bugs: ProtocolBugs{
1774 ExpectFalseStart: true,
1775 AlertBeforeFalseStartTest: alertAccessDenied,
1776 },
1777 },
1778 flags: []string{
1779 "-false-start",
1780 "-advertise-alpn", "\x03foo",
1781 },
1782 shimWritesFirst: true,
1783 shouldFail: true,
1784 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1785 expectedLocalError: "tls: peer did not false start: EOF",
1786 },
1787 {
1788 name: "NoFalseStart-DHE_RSA",
1789 config: Config{
1790 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1791 NextProtos: []string{"foo"},
1792 Bugs: ProtocolBugs{
1793 ExpectFalseStart: true,
1794 AlertBeforeFalseStartTest: alertAccessDenied,
1795 },
1796 },
1797 flags: []string{
1798 "-false-start",
1799 "-advertise-alpn", "\x03foo",
1800 },
1801 shimWritesFirst: true,
1802 shouldFail: true,
1803 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1804 expectedLocalError: "tls: peer did not false start: EOF",
1805 },
1806 {
1807 testType: serverTest,
1808 name: "NoSupportedCurves",
1809 config: Config{
1810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1811 Bugs: ProtocolBugs{
1812 NoSupportedCurves: true,
1813 },
1814 },
1815 },
1816 {
1817 testType: serverTest,
1818 name: "NoCommonCurves",
1819 config: Config{
1820 CipherSuites: []uint16{
1821 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1822 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1823 },
1824 CurvePreferences: []CurveID{CurveP224},
1825 },
1826 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1827 },
1828 {
1829 protocol: dtls,
1830 name: "SendSplitAlert-Sync",
1831 config: Config{
1832 Bugs: ProtocolBugs{
1833 SendSplitAlert: true,
1834 },
1835 },
1836 },
1837 {
1838 protocol: dtls,
1839 name: "SendSplitAlert-Async",
1840 config: Config{
1841 Bugs: ProtocolBugs{
1842 SendSplitAlert: true,
1843 },
1844 },
1845 flags: []string{"-async"},
1846 },
1847 {
1848 protocol: dtls,
1849 name: "PackDTLSHandshake",
1850 config: Config{
1851 Bugs: ProtocolBugs{
1852 MaxHandshakeRecordLength: 2,
1853 PackHandshakeFragments: 20,
1854 PackHandshakeRecords: 200,
1855 },
1856 },
1857 },
1858 {
1859 testType: serverTest,
1860 protocol: dtls,
1861 name: "NoRC4-DTLS",
1862 config: Config{
1863 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1864 Bugs: ProtocolBugs{
1865 EnableAllCiphersInDTLS: true,
1866 },
1867 },
1868 shouldFail: true,
1869 expectedError: ":NO_SHARED_CIPHER:",
1870 },
1871 {
1872 name: "SendEmptyRecords-Pass",
1873 sendEmptyRecords: 32,
1874 },
1875 {
1876 name: "SendEmptyRecords",
1877 sendEmptyRecords: 33,
1878 shouldFail: true,
1879 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1880 },
1881 {
1882 name: "SendEmptyRecords-Async",
1883 sendEmptyRecords: 33,
1884 flags: []string{"-async"},
1885 shouldFail: true,
1886 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1887 },
1888 {
1889 name: "SendWarningAlerts-Pass",
1890 sendWarningAlerts: 4,
1891 },
1892 {
1893 protocol: dtls,
1894 name: "SendWarningAlerts-DTLS-Pass",
1895 sendWarningAlerts: 4,
1896 },
1897 {
1898 name: "SendWarningAlerts",
1899 sendWarningAlerts: 5,
1900 shouldFail: true,
1901 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1902 },
1903 {
1904 name: "SendWarningAlerts-Async",
1905 sendWarningAlerts: 5,
1906 flags: []string{"-async"},
1907 shouldFail: true,
1908 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1909 },
David Benjaminba4594a2015-06-18 18:36:15 -04001910 {
1911 name: "EmptySessionID",
1912 config: Config{
1913 SessionTicketsDisabled: true,
1914 },
1915 noSessionCache: true,
1916 flags: []string{"-expect-no-session"},
1917 },
David Benjamin30789da2015-08-29 22:56:45 -04001918 {
1919 name: "Unclean-Shutdown",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 NoCloseNotify: true,
1923 ExpectCloseNotify: true,
1924 },
1925 },
1926 shimShutsDown: true,
1927 flags: []string{"-check-close-notify"},
1928 shouldFail: true,
1929 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1930 },
1931 {
1932 name: "Unclean-Shutdown-Ignored",
1933 config: Config{
1934 Bugs: ProtocolBugs{
1935 NoCloseNotify: true,
1936 },
1937 },
1938 shimShutsDown: true,
1939 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001940 {
1941 name: "LargePlaintext",
1942 config: Config{
1943 Bugs: ProtocolBugs{
1944 SendLargeRecords: true,
1945 },
1946 },
1947 messageLen: maxPlaintext + 1,
1948 shouldFail: true,
1949 expectedError: ":DATA_LENGTH_TOO_LONG:",
1950 },
1951 {
1952 protocol: dtls,
1953 name: "LargePlaintext-DTLS",
1954 config: Config{
1955 Bugs: ProtocolBugs{
1956 SendLargeRecords: true,
1957 },
1958 },
1959 messageLen: maxPlaintext + 1,
1960 shouldFail: true,
1961 expectedError: ":DATA_LENGTH_TOO_LONG:",
1962 },
1963 {
1964 name: "LargeCiphertext",
1965 config: Config{
1966 Bugs: ProtocolBugs{
1967 SendLargeRecords: true,
1968 },
1969 },
1970 messageLen: maxPlaintext * 2,
1971 shouldFail: true,
1972 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1973 },
1974 {
1975 protocol: dtls,
1976 name: "LargeCiphertext-DTLS",
1977 config: Config{
1978 Bugs: ProtocolBugs{
1979 SendLargeRecords: true,
1980 },
1981 },
1982 messageLen: maxPlaintext * 2,
1983 // Unlike the other four cases, DTLS drops records which
1984 // are invalid before authentication, so the connection
1985 // does not fail.
1986 expectMessageDropped: true,
1987 },
David Benjamindd6fed92015-10-23 17:41:12 -04001988 {
1989 name: "SendEmptySessionTicket",
1990 config: Config{
1991 Bugs: ProtocolBugs{
1992 SendEmptySessionTicket: true,
1993 FailIfSessionOffered: true,
1994 },
1995 },
1996 flags: []string{"-expect-no-session"},
1997 resumeSession: true,
1998 expectResumeRejected: true,
1999 },
Adam Langley7c803a62015-06-15 15:35:05 -07002000 }
Adam Langley7c803a62015-06-15 15:35:05 -07002001 testCases = append(testCases, basicTests...)
2002}
2003
Adam Langley95c29f32014-06-20 12:00:00 -07002004func addCipherSuiteTests() {
2005 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002006 const psk = "12345"
2007 const pskIdentity = "luggage combo"
2008
Adam Langley95c29f32014-06-20 12:00:00 -07002009 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002010 var certFile string
2011 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002012 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002013 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002014 certFile = ecdsaCertificateFile
2015 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002016 } else {
2017 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002018 certFile = rsaCertificateFile
2019 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002020 }
2021
David Benjamin48cae082014-10-27 01:06:24 -04002022 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002023 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002024 flags = append(flags,
2025 "-psk", psk,
2026 "-psk-identity", pskIdentity)
2027 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002028 if hasComponent(suite.name, "NULL") {
2029 // NULL ciphers must be explicitly enabled.
2030 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2031 }
David Benjamin48cae082014-10-27 01:06:24 -04002032
Adam Langley95c29f32014-06-20 12:00:00 -07002033 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002034 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002035 continue
2036 }
2037
David Benjamin025b3d32014-07-01 19:53:04 -04002038 testCases = append(testCases, testCase{
2039 testType: clientTest,
2040 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002041 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002042 MinVersion: ver.version,
2043 MaxVersion: ver.version,
2044 CipherSuites: []uint16{suite.id},
2045 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002046 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002047 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002048 },
David Benjamin48cae082014-10-27 01:06:24 -04002049 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002050 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002051 })
David Benjamin025b3d32014-07-01 19:53:04 -04002052
David Benjamin76d8abe2014-08-14 16:25:34 -04002053 testCases = append(testCases, testCase{
2054 testType: serverTest,
2055 name: ver.name + "-" + suite.name + "-server",
2056 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002057 MinVersion: ver.version,
2058 MaxVersion: ver.version,
2059 CipherSuites: []uint16{suite.id},
2060 Certificates: []Certificate{cert},
2061 PreSharedKey: []byte(psk),
2062 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002063 },
2064 certFile: certFile,
2065 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002066 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002067 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002068 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002069
David Benjamin8b8c0062014-11-23 02:47:52 -05002070 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002071 testCases = append(testCases, testCase{
2072 testType: clientTest,
2073 protocol: dtls,
2074 name: "D" + ver.name + "-" + suite.name + "-client",
2075 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002076 MinVersion: ver.version,
2077 MaxVersion: ver.version,
2078 CipherSuites: []uint16{suite.id},
2079 Certificates: []Certificate{cert},
2080 PreSharedKey: []byte(psk),
2081 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002082 },
David Benjamin48cae082014-10-27 01:06:24 -04002083 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002084 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002085 })
2086 testCases = append(testCases, testCase{
2087 testType: serverTest,
2088 protocol: dtls,
2089 name: "D" + ver.name + "-" + suite.name + "-server",
2090 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002091 MinVersion: ver.version,
2092 MaxVersion: ver.version,
2093 CipherSuites: []uint16{suite.id},
2094 Certificates: []Certificate{cert},
2095 PreSharedKey: []byte(psk),
2096 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002097 },
2098 certFile: certFile,
2099 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002100 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002101 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002102 })
2103 }
Adam Langley95c29f32014-06-20 12:00:00 -07002104 }
David Benjamin2c99d282015-09-01 10:23:00 -04002105
2106 // Ensure both TLS and DTLS accept their maximum record sizes.
2107 testCases = append(testCases, testCase{
2108 name: suite.name + "-LargeRecord",
2109 config: Config{
2110 CipherSuites: []uint16{suite.id},
2111 Certificates: []Certificate{cert},
2112 PreSharedKey: []byte(psk),
2113 PreSharedKeyIdentity: pskIdentity,
2114 },
2115 flags: flags,
2116 messageLen: maxPlaintext,
2117 })
2118 testCases = append(testCases, testCase{
2119 name: suite.name + "-LargeRecord-Extra",
2120 config: Config{
2121 CipherSuites: []uint16{suite.id},
2122 Certificates: []Certificate{cert},
2123 PreSharedKey: []byte(psk),
2124 PreSharedKeyIdentity: pskIdentity,
2125 Bugs: ProtocolBugs{
2126 SendLargeRecords: true,
2127 },
2128 },
2129 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2130 messageLen: maxPlaintext + 16384,
2131 })
2132 if isDTLSCipher(suite.name) {
2133 testCases = append(testCases, testCase{
2134 protocol: dtls,
2135 name: suite.name + "-LargeRecord-DTLS",
2136 config: Config{
2137 CipherSuites: []uint16{suite.id},
2138 Certificates: []Certificate{cert},
2139 PreSharedKey: []byte(psk),
2140 PreSharedKeyIdentity: pskIdentity,
2141 },
2142 flags: flags,
2143 messageLen: maxPlaintext,
2144 })
2145 }
Adam Langley95c29f32014-06-20 12:00:00 -07002146 }
Adam Langleya7997f12015-05-14 17:38:50 -07002147
2148 testCases = append(testCases, testCase{
2149 name: "WeakDH",
2150 config: Config{
2151 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2152 Bugs: ProtocolBugs{
2153 // This is a 1023-bit prime number, generated
2154 // with:
2155 // openssl gendh 1023 | openssl asn1parse -i
2156 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2157 },
2158 },
2159 shouldFail: true,
2160 expectedError: "BAD_DH_P_LENGTH",
2161 })
Adam Langleycef75832015-09-03 14:51:12 -07002162
2163 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2164 // 1.1 specific cipher suite settings. A server is setup with the given
2165 // cipher lists and then a connection is made for each member of
2166 // expectations. The cipher suite that the server selects must match
2167 // the specified one.
2168 var versionSpecificCiphersTest = []struct {
2169 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2170 // expectations is a map from TLS version to cipher suite id.
2171 expectations map[uint16]uint16
2172 }{
2173 {
2174 // Test that the null case (where no version-specific ciphers are set)
2175 // works as expected.
2176 "RC4-SHA:AES128-SHA", // default ciphers
2177 "", // no ciphers specifically for TLS ≥ 1.0
2178 "", // no ciphers specifically for TLS ≥ 1.1
2179 map[uint16]uint16{
2180 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2181 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2182 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2183 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2184 },
2185 },
2186 {
2187 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2188 // cipher.
2189 "RC4-SHA:AES128-SHA", // default
2190 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2191 "", // no ciphers specifically for TLS ≥ 1.1
2192 map[uint16]uint16{
2193 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2194 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2195 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2196 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2197 },
2198 },
2199 {
2200 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2201 // cipher.
2202 "RC4-SHA:AES128-SHA", // default
2203 "", // no ciphers specifically for TLS ≥ 1.0
2204 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2205 map[uint16]uint16{
2206 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2207 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2208 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2209 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2210 },
2211 },
2212 {
2213 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2214 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2215 "RC4-SHA:AES128-SHA", // default
2216 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2217 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2218 map[uint16]uint16{
2219 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2220 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2221 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2222 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2223 },
2224 },
2225 }
2226
2227 for i, test := range versionSpecificCiphersTest {
2228 for version, expectedCipherSuite := range test.expectations {
2229 flags := []string{"-cipher", test.ciphersDefault}
2230 if len(test.ciphersTLS10) > 0 {
2231 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2232 }
2233 if len(test.ciphersTLS11) > 0 {
2234 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2235 }
2236
2237 testCases = append(testCases, testCase{
2238 testType: serverTest,
2239 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2240 config: Config{
2241 MaxVersion: version,
2242 MinVersion: version,
2243 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2244 },
2245 flags: flags,
2246 expectedCipher: expectedCipherSuite,
2247 })
2248 }
2249 }
Adam Langley95c29f32014-06-20 12:00:00 -07002250}
2251
2252func addBadECDSASignatureTests() {
2253 for badR := BadValue(1); badR < NumBadValues; badR++ {
2254 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002255 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002256 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2257 config: Config{
2258 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2259 Certificates: []Certificate{getECDSACertificate()},
2260 Bugs: ProtocolBugs{
2261 BadECDSAR: badR,
2262 BadECDSAS: badS,
2263 },
2264 },
2265 shouldFail: true,
2266 expectedError: "SIGNATURE",
2267 })
2268 }
2269 }
2270}
2271
Adam Langley80842bd2014-06-20 12:00:00 -07002272func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002273 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002274 name: "MaxCBCPadding",
2275 config: Config{
2276 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2277 Bugs: ProtocolBugs{
2278 MaxPadding: true,
2279 },
2280 },
2281 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2282 })
David Benjamin025b3d32014-07-01 19:53:04 -04002283 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002284 name: "BadCBCPadding",
2285 config: Config{
2286 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2287 Bugs: ProtocolBugs{
2288 PaddingFirstByteBad: true,
2289 },
2290 },
2291 shouldFail: true,
2292 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2293 })
2294 // OpenSSL previously had an issue where the first byte of padding in
2295 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002296 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002297 name: "BadCBCPadding255",
2298 config: Config{
2299 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2300 Bugs: ProtocolBugs{
2301 MaxPadding: true,
2302 PaddingFirstByteBadIf255: true,
2303 },
2304 },
2305 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2306 shouldFail: true,
2307 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2308 })
2309}
2310
Kenny Root7fdeaf12014-08-05 15:23:37 -07002311func addCBCSplittingTests() {
2312 testCases = append(testCases, testCase{
2313 name: "CBCRecordSplitting",
2314 config: Config{
2315 MaxVersion: VersionTLS10,
2316 MinVersion: VersionTLS10,
2317 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2318 },
David Benjaminac8302a2015-09-01 17:18:15 -04002319 messageLen: -1, // read until EOF
2320 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002321 flags: []string{
2322 "-async",
2323 "-write-different-record-sizes",
2324 "-cbc-record-splitting",
2325 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002326 })
2327 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002328 name: "CBCRecordSplittingPartialWrite",
2329 config: Config{
2330 MaxVersion: VersionTLS10,
2331 MinVersion: VersionTLS10,
2332 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2333 },
2334 messageLen: -1, // read until EOF
2335 flags: []string{
2336 "-async",
2337 "-write-different-record-sizes",
2338 "-cbc-record-splitting",
2339 "-partial-write",
2340 },
2341 })
2342}
2343
David Benjamin636293b2014-07-08 17:59:18 -04002344func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002345 // Add a dummy cert pool to stress certificate authority parsing.
2346 // TODO(davidben): Add tests that those values parse out correctly.
2347 certPool := x509.NewCertPool()
2348 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2349 if err != nil {
2350 panic(err)
2351 }
2352 certPool.AddCert(cert)
2353
David Benjamin636293b2014-07-08 17:59:18 -04002354 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002355 testCases = append(testCases, testCase{
2356 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002357 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002358 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002359 MinVersion: ver.version,
2360 MaxVersion: ver.version,
2361 ClientAuth: RequireAnyClientCert,
2362 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002363 },
2364 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002365 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2366 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002367 },
2368 })
2369 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002370 testType: serverTest,
2371 name: ver.name + "-Server-ClientAuth-RSA",
2372 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002373 MinVersion: ver.version,
2374 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002375 Certificates: []Certificate{rsaCertificate},
2376 },
2377 flags: []string{"-require-any-client-certificate"},
2378 })
David Benjamine098ec22014-08-27 23:13:20 -04002379 if ver.version != VersionSSL30 {
2380 testCases = append(testCases, testCase{
2381 testType: serverTest,
2382 name: ver.name + "-Server-ClientAuth-ECDSA",
2383 config: Config{
2384 MinVersion: ver.version,
2385 MaxVersion: ver.version,
2386 Certificates: []Certificate{ecdsaCertificate},
2387 },
2388 flags: []string{"-require-any-client-certificate"},
2389 })
2390 testCases = append(testCases, testCase{
2391 testType: clientTest,
2392 name: ver.name + "-Client-ClientAuth-ECDSA",
2393 config: Config{
2394 MinVersion: ver.version,
2395 MaxVersion: ver.version,
2396 ClientAuth: RequireAnyClientCert,
2397 ClientCAs: certPool,
2398 },
2399 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002400 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2401 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002402 },
2403 })
2404 }
David Benjamin636293b2014-07-08 17:59:18 -04002405 }
2406}
2407
Adam Langley75712922014-10-10 16:23:43 -07002408func addExtendedMasterSecretTests() {
2409 const expectEMSFlag = "-expect-extended-master-secret"
2410
2411 for _, with := range []bool{false, true} {
2412 prefix := "No"
2413 var flags []string
2414 if with {
2415 prefix = ""
2416 flags = []string{expectEMSFlag}
2417 }
2418
2419 for _, isClient := range []bool{false, true} {
2420 suffix := "-Server"
2421 testType := serverTest
2422 if isClient {
2423 suffix = "-Client"
2424 testType = clientTest
2425 }
2426
2427 for _, ver := range tlsVersions {
2428 test := testCase{
2429 testType: testType,
2430 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2431 config: Config{
2432 MinVersion: ver.version,
2433 MaxVersion: ver.version,
2434 Bugs: ProtocolBugs{
2435 NoExtendedMasterSecret: !with,
2436 RequireExtendedMasterSecret: with,
2437 },
2438 },
David Benjamin48cae082014-10-27 01:06:24 -04002439 flags: flags,
2440 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002441 }
2442 if test.shouldFail {
2443 test.expectedLocalError = "extended master secret required but not supported by peer"
2444 }
2445 testCases = append(testCases, test)
2446 }
2447 }
2448 }
2449
Adam Langleyba5934b2015-06-02 10:50:35 -07002450 for _, isClient := range []bool{false, true} {
2451 for _, supportedInFirstConnection := range []bool{false, true} {
2452 for _, supportedInResumeConnection := range []bool{false, true} {
2453 boolToWord := func(b bool) string {
2454 if b {
2455 return "Yes"
2456 }
2457 return "No"
2458 }
2459 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2460 if isClient {
2461 suffix += "Client"
2462 } else {
2463 suffix += "Server"
2464 }
2465
2466 supportedConfig := Config{
2467 Bugs: ProtocolBugs{
2468 RequireExtendedMasterSecret: true,
2469 },
2470 }
2471
2472 noSupportConfig := Config{
2473 Bugs: ProtocolBugs{
2474 NoExtendedMasterSecret: true,
2475 },
2476 }
2477
2478 test := testCase{
2479 name: "ExtendedMasterSecret-" + suffix,
2480 resumeSession: true,
2481 }
2482
2483 if !isClient {
2484 test.testType = serverTest
2485 }
2486
2487 if supportedInFirstConnection {
2488 test.config = supportedConfig
2489 } else {
2490 test.config = noSupportConfig
2491 }
2492
2493 if supportedInResumeConnection {
2494 test.resumeConfig = &supportedConfig
2495 } else {
2496 test.resumeConfig = &noSupportConfig
2497 }
2498
2499 switch suffix {
2500 case "YesToYes-Client", "YesToYes-Server":
2501 // When a session is resumed, it should
2502 // still be aware that its master
2503 // secret was generated via EMS and
2504 // thus it's safe to use tls-unique.
2505 test.flags = []string{expectEMSFlag}
2506 case "NoToYes-Server":
2507 // If an original connection did not
2508 // contain EMS, but a resumption
2509 // handshake does, then a server should
2510 // not resume the session.
2511 test.expectResumeRejected = true
2512 case "YesToNo-Server":
2513 // Resuming an EMS session without the
2514 // EMS extension should cause the
2515 // server to abort the connection.
2516 test.shouldFail = true
2517 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2518 case "NoToYes-Client":
2519 // A client should abort a connection
2520 // where the server resumed a non-EMS
2521 // session but echoed the EMS
2522 // extension.
2523 test.shouldFail = true
2524 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2525 case "YesToNo-Client":
2526 // A client should abort a connection
2527 // where the server didn't echo EMS
2528 // when the session used it.
2529 test.shouldFail = true
2530 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2531 }
2532
2533 testCases = append(testCases, test)
2534 }
2535 }
2536 }
Adam Langley75712922014-10-10 16:23:43 -07002537}
2538
David Benjamin43ec06f2014-08-05 02:28:57 -04002539// Adds tests that try to cover the range of the handshake state machine, under
2540// various conditions. Some of these are redundant with other tests, but they
2541// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002542func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002543 var tests []testCase
2544
2545 // Basic handshake, with resumption. Client and server,
2546 // session ID and session ticket.
2547 tests = append(tests, testCase{
2548 name: "Basic-Client",
2549 resumeSession: true,
2550 })
2551 tests = append(tests, testCase{
2552 name: "Basic-Client-RenewTicket",
2553 config: Config{
2554 Bugs: ProtocolBugs{
2555 RenewTicketOnResume: true,
2556 },
2557 },
David Benjaminba4594a2015-06-18 18:36:15 -04002558 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002559 resumeSession: true,
2560 })
2561 tests = append(tests, testCase{
2562 name: "Basic-Client-NoTicket",
2563 config: Config{
2564 SessionTicketsDisabled: true,
2565 },
2566 resumeSession: true,
2567 })
2568 tests = append(tests, testCase{
2569 name: "Basic-Client-Implicit",
2570 flags: []string{"-implicit-handshake"},
2571 resumeSession: true,
2572 })
2573 tests = append(tests, testCase{
2574 testType: serverTest,
2575 name: "Basic-Server",
2576 resumeSession: true,
2577 })
2578 tests = append(tests, testCase{
2579 testType: serverTest,
2580 name: "Basic-Server-NoTickets",
2581 config: Config{
2582 SessionTicketsDisabled: true,
2583 },
2584 resumeSession: true,
2585 })
2586 tests = append(tests, testCase{
2587 testType: serverTest,
2588 name: "Basic-Server-Implicit",
2589 flags: []string{"-implicit-handshake"},
2590 resumeSession: true,
2591 })
2592 tests = append(tests, testCase{
2593 testType: serverTest,
2594 name: "Basic-Server-EarlyCallback",
2595 flags: []string{"-use-early-callback"},
2596 resumeSession: true,
2597 })
2598
2599 // TLS client auth.
2600 tests = append(tests, testCase{
2601 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002602 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002603 config: Config{
2604 ClientAuth: RequireAnyClientCert,
2605 },
2606 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002607 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2608 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002609 },
2610 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002611 tests = append(tests, testCase{
2612 testType: clientTest,
2613 name: "ClientAuth-ECDSA-Client",
2614 config: Config{
2615 ClientAuth: RequireAnyClientCert,
2616 },
2617 flags: []string{
2618 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2619 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2620 },
2621 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002622 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002623 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002624 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002625 testType: serverTest,
2626 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002627 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002628 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002629 },
2630 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002631 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2632 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002633 },
2634 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002635 tests = append(tests, testCase{
2636 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002637 name: "Basic-Server-ECDHE-RSA",
2638 config: Config{
2639 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2640 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002641 flags: []string{
2642 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2643 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002644 },
2645 })
2646 tests = append(tests, testCase{
2647 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002648 name: "Basic-Server-ECDHE-ECDSA",
2649 config: Config{
2650 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2651 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002652 flags: []string{
2653 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2654 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002655 },
2656 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002657 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002658 tests = append(tests, testCase{
2659 testType: serverTest,
2660 name: "ClientAuth-Server",
2661 config: Config{
2662 Certificates: []Certificate{rsaCertificate},
2663 },
2664 flags: []string{"-require-any-client-certificate"},
2665 })
2666
2667 // No session ticket support; server doesn't send NewSessionTicket.
2668 tests = append(tests, testCase{
2669 name: "SessionTicketsDisabled-Client",
2670 config: Config{
2671 SessionTicketsDisabled: true,
2672 },
2673 })
2674 tests = append(tests, testCase{
2675 testType: serverTest,
2676 name: "SessionTicketsDisabled-Server",
2677 config: Config{
2678 SessionTicketsDisabled: true,
2679 },
2680 })
2681
2682 // Skip ServerKeyExchange in PSK key exchange if there's no
2683 // identity hint.
2684 tests = append(tests, testCase{
2685 name: "EmptyPSKHint-Client",
2686 config: Config{
2687 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2688 PreSharedKey: []byte("secret"),
2689 },
2690 flags: []string{"-psk", "secret"},
2691 })
2692 tests = append(tests, testCase{
2693 testType: serverTest,
2694 name: "EmptyPSKHint-Server",
2695 config: Config{
2696 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2697 PreSharedKey: []byte("secret"),
2698 },
2699 flags: []string{"-psk", "secret"},
2700 })
2701
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002702 tests = append(tests, testCase{
2703 testType: clientTest,
2704 name: "OCSPStapling-Client",
2705 flags: []string{
2706 "-enable-ocsp-stapling",
2707 "-expect-ocsp-response",
2708 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002709 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002710 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002711 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002712 })
2713
2714 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002715 testType: serverTest,
2716 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002717 expectedOCSPResponse: testOCSPResponse,
2718 flags: []string{
2719 "-ocsp-response",
2720 base64.StdEncoding.EncodeToString(testOCSPResponse),
2721 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002722 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002723 })
2724
Paul Lietar8f1c2682015-08-18 12:21:54 +01002725 tests = append(tests, testCase{
2726 testType: clientTest,
2727 name: "CertificateVerificationSucceed",
2728 flags: []string{
2729 "-verify-peer",
2730 },
2731 })
2732
2733 tests = append(tests, testCase{
2734 testType: clientTest,
2735 name: "CertificateVerificationFail",
2736 flags: []string{
2737 "-verify-fail",
2738 "-verify-peer",
2739 },
2740 shouldFail: true,
2741 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2742 })
2743
2744 tests = append(tests, testCase{
2745 testType: clientTest,
2746 name: "CertificateVerificationSoftFail",
2747 flags: []string{
2748 "-verify-fail",
2749 "-expect-verify-result",
2750 },
2751 })
2752
David Benjamin760b1dd2015-05-15 23:33:48 -04002753 if protocol == tls {
2754 tests = append(tests, testCase{
2755 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002756 renegotiate: 1,
2757 flags: []string{
2758 "-renegotiate-freely",
2759 "-expect-total-renegotiations", "1",
2760 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002761 })
2762 // NPN on client and server; results in post-handshake message.
2763 tests = append(tests, testCase{
2764 name: "NPN-Client",
2765 config: Config{
2766 NextProtos: []string{"foo"},
2767 },
2768 flags: []string{"-select-next-proto", "foo"},
2769 expectedNextProto: "foo",
2770 expectedNextProtoType: npn,
2771 })
2772 tests = append(tests, testCase{
2773 testType: serverTest,
2774 name: "NPN-Server",
2775 config: Config{
2776 NextProtos: []string{"bar"},
2777 },
2778 flags: []string{
2779 "-advertise-npn", "\x03foo\x03bar\x03baz",
2780 "-expect-next-proto", "bar",
2781 },
2782 expectedNextProto: "bar",
2783 expectedNextProtoType: npn,
2784 })
2785
2786 // TODO(davidben): Add tests for when False Start doesn't trigger.
2787
2788 // Client does False Start and negotiates NPN.
2789 tests = append(tests, testCase{
2790 name: "FalseStart",
2791 config: Config{
2792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2793 NextProtos: []string{"foo"},
2794 Bugs: ProtocolBugs{
2795 ExpectFalseStart: true,
2796 },
2797 },
2798 flags: []string{
2799 "-false-start",
2800 "-select-next-proto", "foo",
2801 },
2802 shimWritesFirst: true,
2803 resumeSession: true,
2804 })
2805
2806 // Client does False Start and negotiates ALPN.
2807 tests = append(tests, testCase{
2808 name: "FalseStart-ALPN",
2809 config: Config{
2810 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2811 NextProtos: []string{"foo"},
2812 Bugs: ProtocolBugs{
2813 ExpectFalseStart: true,
2814 },
2815 },
2816 flags: []string{
2817 "-false-start",
2818 "-advertise-alpn", "\x03foo",
2819 },
2820 shimWritesFirst: true,
2821 resumeSession: true,
2822 })
2823
2824 // Client does False Start but doesn't explicitly call
2825 // SSL_connect.
2826 tests = append(tests, testCase{
2827 name: "FalseStart-Implicit",
2828 config: Config{
2829 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2830 NextProtos: []string{"foo"},
2831 },
2832 flags: []string{
2833 "-implicit-handshake",
2834 "-false-start",
2835 "-advertise-alpn", "\x03foo",
2836 },
2837 })
2838
2839 // False Start without session tickets.
2840 tests = append(tests, testCase{
2841 name: "FalseStart-SessionTicketsDisabled",
2842 config: Config{
2843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2844 NextProtos: []string{"foo"},
2845 SessionTicketsDisabled: true,
2846 Bugs: ProtocolBugs{
2847 ExpectFalseStart: true,
2848 },
2849 },
2850 flags: []string{
2851 "-false-start",
2852 "-select-next-proto", "foo",
2853 },
2854 shimWritesFirst: true,
2855 })
2856
2857 // Server parses a V2ClientHello.
2858 tests = append(tests, testCase{
2859 testType: serverTest,
2860 name: "SendV2ClientHello",
2861 config: Config{
2862 // Choose a cipher suite that does not involve
2863 // elliptic curves, so no extensions are
2864 // involved.
2865 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2866 Bugs: ProtocolBugs{
2867 SendV2ClientHello: true,
2868 },
2869 },
2870 })
2871
2872 // Client sends a Channel ID.
2873 tests = append(tests, testCase{
2874 name: "ChannelID-Client",
2875 config: Config{
2876 RequestChannelID: true,
2877 },
Adam Langley7c803a62015-06-15 15:35:05 -07002878 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002879 resumeSession: true,
2880 expectChannelID: true,
2881 })
2882
2883 // Server accepts a Channel ID.
2884 tests = append(tests, testCase{
2885 testType: serverTest,
2886 name: "ChannelID-Server",
2887 config: Config{
2888 ChannelID: channelIDKey,
2889 },
2890 flags: []string{
2891 "-expect-channel-id",
2892 base64.StdEncoding.EncodeToString(channelIDBytes),
2893 },
2894 resumeSession: true,
2895 expectChannelID: true,
2896 })
David Benjamin30789da2015-08-29 22:56:45 -04002897
2898 // Bidirectional shutdown with the runner initiating.
2899 tests = append(tests, testCase{
2900 name: "Shutdown-Runner",
2901 config: Config{
2902 Bugs: ProtocolBugs{
2903 ExpectCloseNotify: true,
2904 },
2905 },
2906 flags: []string{"-check-close-notify"},
2907 })
2908
2909 // Bidirectional shutdown with the shim initiating. The runner,
2910 // in the meantime, sends garbage before the close_notify which
2911 // the shim must ignore.
2912 tests = append(tests, testCase{
2913 name: "Shutdown-Shim",
2914 config: Config{
2915 Bugs: ProtocolBugs{
2916 ExpectCloseNotify: true,
2917 },
2918 },
2919 shimShutsDown: true,
2920 sendEmptyRecords: 1,
2921 sendWarningAlerts: 1,
2922 flags: []string{"-check-close-notify"},
2923 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002924 } else {
2925 tests = append(tests, testCase{
2926 name: "SkipHelloVerifyRequest",
2927 config: Config{
2928 Bugs: ProtocolBugs{
2929 SkipHelloVerifyRequest: true,
2930 },
2931 },
2932 })
2933 }
2934
David Benjamin43ec06f2014-08-05 02:28:57 -04002935 var suffix string
2936 var flags []string
2937 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002938 if protocol == dtls {
2939 suffix = "-DTLS"
2940 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002941 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002942 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002943 flags = append(flags, "-async")
2944 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002945 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002946 }
2947 if splitHandshake {
2948 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002949 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002950 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002951 for _, test := range tests {
2952 test.protocol = protocol
2953 test.name += suffix
2954 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2955 test.flags = append(test.flags, flags...)
2956 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002957 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002958}
2959
Adam Langley524e7172015-02-20 16:04:00 -08002960func addDDoSCallbackTests() {
2961 // DDoS callback.
2962
2963 for _, resume := range []bool{false, true} {
2964 suffix := "Resume"
2965 if resume {
2966 suffix = "No" + suffix
2967 }
2968
2969 testCases = append(testCases, testCase{
2970 testType: serverTest,
2971 name: "Server-DDoS-OK-" + suffix,
2972 flags: []string{"-install-ddos-callback"},
2973 resumeSession: resume,
2974 })
2975
2976 failFlag := "-fail-ddos-callback"
2977 if resume {
2978 failFlag = "-fail-second-ddos-callback"
2979 }
2980 testCases = append(testCases, testCase{
2981 testType: serverTest,
2982 name: "Server-DDoS-Reject-" + suffix,
2983 flags: []string{"-install-ddos-callback", failFlag},
2984 resumeSession: resume,
2985 shouldFail: true,
2986 expectedError: ":CONNECTION_REJECTED:",
2987 })
2988 }
2989}
2990
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002991func addVersionNegotiationTests() {
2992 for i, shimVers := range tlsVersions {
2993 // Assemble flags to disable all newer versions on the shim.
2994 var flags []string
2995 for _, vers := range tlsVersions[i+1:] {
2996 flags = append(flags, vers.flag)
2997 }
2998
2999 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003000 protocols := []protocol{tls}
3001 if runnerVers.hasDTLS && shimVers.hasDTLS {
3002 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003003 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003004 for _, protocol := range protocols {
3005 expectedVersion := shimVers.version
3006 if runnerVers.version < shimVers.version {
3007 expectedVersion = runnerVers.version
3008 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003009
David Benjamin8b8c0062014-11-23 02:47:52 -05003010 suffix := shimVers.name + "-" + runnerVers.name
3011 if protocol == dtls {
3012 suffix += "-DTLS"
3013 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003014
David Benjamin1eb367c2014-12-12 18:17:51 -05003015 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3016
David Benjamin1e29a6b2014-12-10 02:27:24 -05003017 clientVers := shimVers.version
3018 if clientVers > VersionTLS10 {
3019 clientVers = VersionTLS10
3020 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003021 testCases = append(testCases, testCase{
3022 protocol: protocol,
3023 testType: clientTest,
3024 name: "VersionNegotiation-Client-" + suffix,
3025 config: Config{
3026 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003027 Bugs: ProtocolBugs{
3028 ExpectInitialRecordVersion: clientVers,
3029 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003030 },
3031 flags: flags,
3032 expectedVersion: expectedVersion,
3033 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003034 testCases = append(testCases, testCase{
3035 protocol: protocol,
3036 testType: clientTest,
3037 name: "VersionNegotiation-Client2-" + suffix,
3038 config: Config{
3039 MaxVersion: runnerVers.version,
3040 Bugs: ProtocolBugs{
3041 ExpectInitialRecordVersion: clientVers,
3042 },
3043 },
3044 flags: []string{"-max-version", shimVersFlag},
3045 expectedVersion: expectedVersion,
3046 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003047
3048 testCases = append(testCases, testCase{
3049 protocol: protocol,
3050 testType: serverTest,
3051 name: "VersionNegotiation-Server-" + suffix,
3052 config: Config{
3053 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003054 Bugs: ProtocolBugs{
3055 ExpectInitialRecordVersion: expectedVersion,
3056 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003057 },
3058 flags: flags,
3059 expectedVersion: expectedVersion,
3060 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003061 testCases = append(testCases, testCase{
3062 protocol: protocol,
3063 testType: serverTest,
3064 name: "VersionNegotiation-Server2-" + suffix,
3065 config: Config{
3066 MaxVersion: runnerVers.version,
3067 Bugs: ProtocolBugs{
3068 ExpectInitialRecordVersion: expectedVersion,
3069 },
3070 },
3071 flags: []string{"-max-version", shimVersFlag},
3072 expectedVersion: expectedVersion,
3073 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003074 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003075 }
3076 }
3077}
3078
David Benjaminaccb4542014-12-12 23:44:33 -05003079func addMinimumVersionTests() {
3080 for i, shimVers := range tlsVersions {
3081 // Assemble flags to disable all older versions on the shim.
3082 var flags []string
3083 for _, vers := range tlsVersions[:i] {
3084 flags = append(flags, vers.flag)
3085 }
3086
3087 for _, runnerVers := range tlsVersions {
3088 protocols := []protocol{tls}
3089 if runnerVers.hasDTLS && shimVers.hasDTLS {
3090 protocols = append(protocols, dtls)
3091 }
3092 for _, protocol := range protocols {
3093 suffix := shimVers.name + "-" + runnerVers.name
3094 if protocol == dtls {
3095 suffix += "-DTLS"
3096 }
3097 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3098
David Benjaminaccb4542014-12-12 23:44:33 -05003099 var expectedVersion uint16
3100 var shouldFail bool
3101 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003102 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003103 if runnerVers.version >= shimVers.version {
3104 expectedVersion = runnerVers.version
3105 } else {
3106 shouldFail = true
3107 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003108 if runnerVers.version > VersionSSL30 {
3109 expectedLocalError = "remote error: protocol version not supported"
3110 } else {
3111 expectedLocalError = "remote error: handshake failure"
3112 }
David Benjaminaccb4542014-12-12 23:44:33 -05003113 }
3114
3115 testCases = append(testCases, testCase{
3116 protocol: protocol,
3117 testType: clientTest,
3118 name: "MinimumVersion-Client-" + suffix,
3119 config: Config{
3120 MaxVersion: runnerVers.version,
3121 },
David Benjamin87909c02014-12-13 01:55:01 -05003122 flags: flags,
3123 expectedVersion: expectedVersion,
3124 shouldFail: shouldFail,
3125 expectedError: expectedError,
3126 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003127 })
3128 testCases = append(testCases, testCase{
3129 protocol: protocol,
3130 testType: clientTest,
3131 name: "MinimumVersion-Client2-" + suffix,
3132 config: Config{
3133 MaxVersion: runnerVers.version,
3134 },
David Benjamin87909c02014-12-13 01:55:01 -05003135 flags: []string{"-min-version", shimVersFlag},
3136 expectedVersion: expectedVersion,
3137 shouldFail: shouldFail,
3138 expectedError: expectedError,
3139 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003140 })
3141
3142 testCases = append(testCases, testCase{
3143 protocol: protocol,
3144 testType: serverTest,
3145 name: "MinimumVersion-Server-" + suffix,
3146 config: Config{
3147 MaxVersion: runnerVers.version,
3148 },
David Benjamin87909c02014-12-13 01:55:01 -05003149 flags: flags,
3150 expectedVersion: expectedVersion,
3151 shouldFail: shouldFail,
3152 expectedError: expectedError,
3153 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003154 })
3155 testCases = append(testCases, testCase{
3156 protocol: protocol,
3157 testType: serverTest,
3158 name: "MinimumVersion-Server2-" + suffix,
3159 config: Config{
3160 MaxVersion: runnerVers.version,
3161 },
David Benjamin87909c02014-12-13 01:55:01 -05003162 flags: []string{"-min-version", shimVersFlag},
3163 expectedVersion: expectedVersion,
3164 shouldFail: shouldFail,
3165 expectedError: expectedError,
3166 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003167 })
3168 }
3169 }
3170 }
3171}
3172
David Benjamin5c24a1d2014-08-31 00:59:27 -04003173func addD5BugTests() {
3174 testCases = append(testCases, testCase{
3175 testType: serverTest,
3176 name: "D5Bug-NoQuirk-Reject",
3177 config: Config{
3178 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3179 Bugs: ProtocolBugs{
3180 SSL3RSAKeyExchange: true,
3181 },
3182 },
3183 shouldFail: true,
3184 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3185 })
3186 testCases = append(testCases, testCase{
3187 testType: serverTest,
3188 name: "D5Bug-Quirk-Normal",
3189 config: Config{
3190 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3191 },
3192 flags: []string{"-tls-d5-bug"},
3193 })
3194 testCases = append(testCases, testCase{
3195 testType: serverTest,
3196 name: "D5Bug-Quirk-Bug",
3197 config: Config{
3198 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3199 Bugs: ProtocolBugs{
3200 SSL3RSAKeyExchange: true,
3201 },
3202 },
3203 flags: []string{"-tls-d5-bug"},
3204 })
3205}
3206
David Benjamine78bfde2014-09-06 12:45:15 -04003207func addExtensionTests() {
3208 testCases = append(testCases, testCase{
3209 testType: clientTest,
3210 name: "DuplicateExtensionClient",
3211 config: Config{
3212 Bugs: ProtocolBugs{
3213 DuplicateExtension: true,
3214 },
3215 },
3216 shouldFail: true,
3217 expectedLocalError: "remote error: error decoding message",
3218 })
3219 testCases = append(testCases, testCase{
3220 testType: serverTest,
3221 name: "DuplicateExtensionServer",
3222 config: Config{
3223 Bugs: ProtocolBugs{
3224 DuplicateExtension: true,
3225 },
3226 },
3227 shouldFail: true,
3228 expectedLocalError: "remote error: error decoding message",
3229 })
3230 testCases = append(testCases, testCase{
3231 testType: clientTest,
3232 name: "ServerNameExtensionClient",
3233 config: Config{
3234 Bugs: ProtocolBugs{
3235 ExpectServerName: "example.com",
3236 },
3237 },
3238 flags: []string{"-host-name", "example.com"},
3239 })
3240 testCases = append(testCases, testCase{
3241 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003242 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003243 config: Config{
3244 Bugs: ProtocolBugs{
3245 ExpectServerName: "mismatch.com",
3246 },
3247 },
3248 flags: []string{"-host-name", "example.com"},
3249 shouldFail: true,
3250 expectedLocalError: "tls: unexpected server name",
3251 })
3252 testCases = append(testCases, testCase{
3253 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003254 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003255 config: Config{
3256 Bugs: ProtocolBugs{
3257 ExpectServerName: "missing.com",
3258 },
3259 },
3260 shouldFail: true,
3261 expectedLocalError: "tls: unexpected server name",
3262 })
3263 testCases = append(testCases, testCase{
3264 testType: serverTest,
3265 name: "ServerNameExtensionServer",
3266 config: Config{
3267 ServerName: "example.com",
3268 },
3269 flags: []string{"-expect-server-name", "example.com"},
3270 resumeSession: true,
3271 })
David Benjaminae2888f2014-09-06 12:58:58 -04003272 testCases = append(testCases, testCase{
3273 testType: clientTest,
3274 name: "ALPNClient",
3275 config: Config{
3276 NextProtos: []string{"foo"},
3277 },
3278 flags: []string{
3279 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3280 "-expect-alpn", "foo",
3281 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003282 expectedNextProto: "foo",
3283 expectedNextProtoType: alpn,
3284 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003285 })
3286 testCases = append(testCases, testCase{
3287 testType: serverTest,
3288 name: "ALPNServer",
3289 config: Config{
3290 NextProtos: []string{"foo", "bar", "baz"},
3291 },
3292 flags: []string{
3293 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3294 "-select-alpn", "foo",
3295 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003296 expectedNextProto: "foo",
3297 expectedNextProtoType: alpn,
3298 resumeSession: true,
3299 })
3300 // Test that the server prefers ALPN over NPN.
3301 testCases = append(testCases, testCase{
3302 testType: serverTest,
3303 name: "ALPNServer-Preferred",
3304 config: Config{
3305 NextProtos: []string{"foo", "bar", "baz"},
3306 },
3307 flags: []string{
3308 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3309 "-select-alpn", "foo",
3310 "-advertise-npn", "\x03foo\x03bar\x03baz",
3311 },
3312 expectedNextProto: "foo",
3313 expectedNextProtoType: alpn,
3314 resumeSession: true,
3315 })
3316 testCases = append(testCases, testCase{
3317 testType: serverTest,
3318 name: "ALPNServer-Preferred-Swapped",
3319 config: Config{
3320 NextProtos: []string{"foo", "bar", "baz"},
3321 Bugs: ProtocolBugs{
3322 SwapNPNAndALPN: true,
3323 },
3324 },
3325 flags: []string{
3326 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3327 "-select-alpn", "foo",
3328 "-advertise-npn", "\x03foo\x03bar\x03baz",
3329 },
3330 expectedNextProto: "foo",
3331 expectedNextProtoType: alpn,
3332 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003333 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003334 var emptyString string
3335 testCases = append(testCases, testCase{
3336 testType: clientTest,
3337 name: "ALPNClient-EmptyProtocolName",
3338 config: Config{
3339 NextProtos: []string{""},
3340 Bugs: ProtocolBugs{
3341 // A server returning an empty ALPN protocol
3342 // should be rejected.
3343 ALPNProtocol: &emptyString,
3344 },
3345 },
3346 flags: []string{
3347 "-advertise-alpn", "\x03foo",
3348 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003349 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003350 expectedError: ":PARSE_TLSEXT:",
3351 })
3352 testCases = append(testCases, testCase{
3353 testType: serverTest,
3354 name: "ALPNServer-EmptyProtocolName",
3355 config: Config{
3356 // A ClientHello containing an empty ALPN protocol
3357 // should be rejected.
3358 NextProtos: []string{"foo", "", "baz"},
3359 },
3360 flags: []string{
3361 "-select-alpn", "foo",
3362 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003363 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003364 expectedError: ":PARSE_TLSEXT:",
3365 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003366 // Test that negotiating both NPN and ALPN is forbidden.
3367 testCases = append(testCases, testCase{
3368 name: "NegotiateALPNAndNPN",
3369 config: Config{
3370 NextProtos: []string{"foo", "bar", "baz"},
3371 Bugs: ProtocolBugs{
3372 NegotiateALPNAndNPN: true,
3373 },
3374 },
3375 flags: []string{
3376 "-advertise-alpn", "\x03foo",
3377 "-select-next-proto", "foo",
3378 },
3379 shouldFail: true,
3380 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3381 })
3382 testCases = append(testCases, testCase{
3383 name: "NegotiateALPNAndNPN-Swapped",
3384 config: Config{
3385 NextProtos: []string{"foo", "bar", "baz"},
3386 Bugs: ProtocolBugs{
3387 NegotiateALPNAndNPN: true,
3388 SwapNPNAndALPN: true,
3389 },
3390 },
3391 flags: []string{
3392 "-advertise-alpn", "\x03foo",
3393 "-select-next-proto", "foo",
3394 },
3395 shouldFail: true,
3396 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3397 })
David Benjamin091c4b92015-10-26 13:33:21 -04003398 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3399 testCases = append(testCases, testCase{
3400 name: "DisableNPN",
3401 config: Config{
3402 NextProtos: []string{"foo"},
3403 },
3404 flags: []string{
3405 "-select-next-proto", "foo",
3406 "-disable-npn",
3407 },
3408 expectNoNextProto: true,
3409 })
Adam Langley38311732014-10-16 19:04:35 -07003410 // Resume with a corrupt ticket.
3411 testCases = append(testCases, testCase{
3412 testType: serverTest,
3413 name: "CorruptTicket",
3414 config: Config{
3415 Bugs: ProtocolBugs{
3416 CorruptTicket: true,
3417 },
3418 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003419 resumeSession: true,
3420 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003421 })
David Benjamind98452d2015-06-16 14:16:23 -04003422 // Test the ticket callback, with and without renewal.
3423 testCases = append(testCases, testCase{
3424 testType: serverTest,
3425 name: "TicketCallback",
3426 resumeSession: true,
3427 flags: []string{"-use-ticket-callback"},
3428 })
3429 testCases = append(testCases, testCase{
3430 testType: serverTest,
3431 name: "TicketCallback-Renew",
3432 config: Config{
3433 Bugs: ProtocolBugs{
3434 ExpectNewTicket: true,
3435 },
3436 },
3437 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3438 resumeSession: true,
3439 })
Adam Langley38311732014-10-16 19:04:35 -07003440 // Resume with an oversized session id.
3441 testCases = append(testCases, testCase{
3442 testType: serverTest,
3443 name: "OversizedSessionId",
3444 config: Config{
3445 Bugs: ProtocolBugs{
3446 OversizedSessionId: true,
3447 },
3448 },
3449 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003450 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003451 expectedError: ":DECODE_ERROR:",
3452 })
David Benjaminca6c8262014-11-15 19:06:08 -05003453 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3454 // are ignored.
3455 testCases = append(testCases, testCase{
3456 protocol: dtls,
3457 name: "SRTP-Client",
3458 config: Config{
3459 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3460 },
3461 flags: []string{
3462 "-srtp-profiles",
3463 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3464 },
3465 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3466 })
3467 testCases = append(testCases, testCase{
3468 protocol: dtls,
3469 testType: serverTest,
3470 name: "SRTP-Server",
3471 config: Config{
3472 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3473 },
3474 flags: []string{
3475 "-srtp-profiles",
3476 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3477 },
3478 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3479 })
3480 // Test that the MKI is ignored.
3481 testCases = append(testCases, testCase{
3482 protocol: dtls,
3483 testType: serverTest,
3484 name: "SRTP-Server-IgnoreMKI",
3485 config: Config{
3486 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3487 Bugs: ProtocolBugs{
3488 SRTPMasterKeyIdentifer: "bogus",
3489 },
3490 },
3491 flags: []string{
3492 "-srtp-profiles",
3493 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3494 },
3495 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3496 })
3497 // Test that SRTP isn't negotiated on the server if there were
3498 // no matching profiles.
3499 testCases = append(testCases, testCase{
3500 protocol: dtls,
3501 testType: serverTest,
3502 name: "SRTP-Server-NoMatch",
3503 config: Config{
3504 SRTPProtectionProfiles: []uint16{100, 101, 102},
3505 },
3506 flags: []string{
3507 "-srtp-profiles",
3508 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3509 },
3510 expectedSRTPProtectionProfile: 0,
3511 })
3512 // Test that the server returning an invalid SRTP profile is
3513 // flagged as an error by the client.
3514 testCases = append(testCases, testCase{
3515 protocol: dtls,
3516 name: "SRTP-Client-NoMatch",
3517 config: Config{
3518 Bugs: ProtocolBugs{
3519 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3520 },
3521 },
3522 flags: []string{
3523 "-srtp-profiles",
3524 "SRTP_AES128_CM_SHA1_80",
3525 },
3526 shouldFail: true,
3527 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3528 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003529 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003530 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003531 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003532 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003533 flags: []string{
3534 "-enable-signed-cert-timestamps",
3535 "-expect-signed-cert-timestamps",
3536 base64.StdEncoding.EncodeToString(testSCTList),
3537 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003538 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003539 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003540 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003541 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003542 testType: serverTest,
3543 flags: []string{
3544 "-signed-cert-timestamps",
3545 base64.StdEncoding.EncodeToString(testSCTList),
3546 },
3547 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003548 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003549 })
3550 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003551 testType: clientTest,
3552 name: "ClientHelloPadding",
3553 config: Config{
3554 Bugs: ProtocolBugs{
3555 RequireClientHelloSize: 512,
3556 },
3557 },
3558 // This hostname just needs to be long enough to push the
3559 // ClientHello into F5's danger zone between 256 and 511 bytes
3560 // long.
3561 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3562 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003563
3564 // Extensions should not function in SSL 3.0.
3565 testCases = append(testCases, testCase{
3566 testType: serverTest,
3567 name: "SSLv3Extensions-NoALPN",
3568 config: Config{
3569 MaxVersion: VersionSSL30,
3570 NextProtos: []string{"foo", "bar", "baz"},
3571 },
3572 flags: []string{
3573 "-select-alpn", "foo",
3574 },
3575 expectNoNextProto: true,
3576 })
3577
3578 // Test session tickets separately as they follow a different codepath.
3579 testCases = append(testCases, testCase{
3580 testType: serverTest,
3581 name: "SSLv3Extensions-NoTickets",
3582 config: Config{
3583 MaxVersion: VersionSSL30,
3584 Bugs: ProtocolBugs{
3585 // Historically, session tickets in SSL 3.0
3586 // failed in different ways depending on whether
3587 // the client supported renegotiation_info.
3588 NoRenegotiationInfo: true,
3589 },
3590 },
3591 resumeSession: true,
3592 })
3593 testCases = append(testCases, testCase{
3594 testType: serverTest,
3595 name: "SSLv3Extensions-NoTickets2",
3596 config: Config{
3597 MaxVersion: VersionSSL30,
3598 },
3599 resumeSession: true,
3600 })
3601
3602 // But SSL 3.0 does send and process renegotiation_info.
3603 testCases = append(testCases, testCase{
3604 testType: serverTest,
3605 name: "SSLv3Extensions-RenegotiationInfo",
3606 config: Config{
3607 MaxVersion: VersionSSL30,
3608 Bugs: ProtocolBugs{
3609 RequireRenegotiationInfo: true,
3610 },
3611 },
3612 })
3613 testCases = append(testCases, testCase{
3614 testType: serverTest,
3615 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3616 config: Config{
3617 MaxVersion: VersionSSL30,
3618 Bugs: ProtocolBugs{
3619 NoRenegotiationInfo: true,
3620 SendRenegotiationSCSV: true,
3621 RequireRenegotiationInfo: true,
3622 },
3623 },
3624 })
David Benjamine78bfde2014-09-06 12:45:15 -04003625}
3626
David Benjamin01fe8202014-09-24 15:21:44 -04003627func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003628 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003629 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003630 protocols := []protocol{tls}
3631 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3632 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003633 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003634 for _, protocol := range protocols {
3635 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3636 if protocol == dtls {
3637 suffix += "-DTLS"
3638 }
3639
David Benjaminece3de92015-03-16 18:02:20 -04003640 if sessionVers.version == resumeVers.version {
3641 testCases = append(testCases, testCase{
3642 protocol: protocol,
3643 name: "Resume-Client" + suffix,
3644 resumeSession: true,
3645 config: Config{
3646 MaxVersion: sessionVers.version,
3647 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003648 },
David Benjaminece3de92015-03-16 18:02:20 -04003649 expectedVersion: sessionVers.version,
3650 expectedResumeVersion: resumeVers.version,
3651 })
3652 } else {
3653 testCases = append(testCases, testCase{
3654 protocol: protocol,
3655 name: "Resume-Client-Mismatch" + suffix,
3656 resumeSession: true,
3657 config: Config{
3658 MaxVersion: sessionVers.version,
3659 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003660 },
David Benjaminece3de92015-03-16 18:02:20 -04003661 expectedVersion: sessionVers.version,
3662 resumeConfig: &Config{
3663 MaxVersion: resumeVers.version,
3664 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3665 Bugs: ProtocolBugs{
3666 AllowSessionVersionMismatch: true,
3667 },
3668 },
3669 expectedResumeVersion: resumeVers.version,
3670 shouldFail: true,
3671 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3672 })
3673 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003674
3675 testCases = append(testCases, testCase{
3676 protocol: protocol,
3677 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003678 resumeSession: true,
3679 config: Config{
3680 MaxVersion: sessionVers.version,
3681 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3682 },
3683 expectedVersion: sessionVers.version,
3684 resumeConfig: &Config{
3685 MaxVersion: resumeVers.version,
3686 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3687 },
3688 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003689 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003690 expectedResumeVersion: resumeVers.version,
3691 })
3692
David Benjamin8b8c0062014-11-23 02:47:52 -05003693 testCases = append(testCases, testCase{
3694 protocol: protocol,
3695 testType: serverTest,
3696 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003697 resumeSession: true,
3698 config: Config{
3699 MaxVersion: sessionVers.version,
3700 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3701 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003702 expectedVersion: sessionVers.version,
3703 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003704 resumeConfig: &Config{
3705 MaxVersion: resumeVers.version,
3706 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3707 },
3708 expectedResumeVersion: resumeVers.version,
3709 })
3710 }
David Benjamin01fe8202014-09-24 15:21:44 -04003711 }
3712 }
David Benjaminece3de92015-03-16 18:02:20 -04003713
3714 testCases = append(testCases, testCase{
3715 name: "Resume-Client-CipherMismatch",
3716 resumeSession: true,
3717 config: Config{
3718 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3719 },
3720 resumeConfig: &Config{
3721 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3722 Bugs: ProtocolBugs{
3723 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3724 },
3725 },
3726 shouldFail: true,
3727 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3728 })
David Benjamin01fe8202014-09-24 15:21:44 -04003729}
3730
Adam Langley2ae77d22014-10-28 17:29:33 -07003731func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003732 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003733 testCases = append(testCases, testCase{
3734 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003735 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003736 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003737 shouldFail: true,
3738 expectedError: ":NO_RENEGOTIATION:",
3739 expectedLocalError: "remote error: no renegotiation",
3740 })
Adam Langley5021b222015-06-12 18:27:58 -07003741 // The server shouldn't echo the renegotiation extension unless
3742 // requested by the client.
3743 testCases = append(testCases, testCase{
3744 testType: serverTest,
3745 name: "Renegotiate-Server-NoExt",
3746 config: Config{
3747 Bugs: ProtocolBugs{
3748 NoRenegotiationInfo: true,
3749 RequireRenegotiationInfo: true,
3750 },
3751 },
3752 shouldFail: true,
3753 expectedLocalError: "renegotiation extension missing",
3754 })
3755 // The renegotiation SCSV should be sufficient for the server to echo
3756 // the extension.
3757 testCases = append(testCases, testCase{
3758 testType: serverTest,
3759 name: "Renegotiate-Server-NoExt-SCSV",
3760 config: Config{
3761 Bugs: ProtocolBugs{
3762 NoRenegotiationInfo: true,
3763 SendRenegotiationSCSV: true,
3764 RequireRenegotiationInfo: true,
3765 },
3766 },
3767 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003768 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003769 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003770 config: Config{
3771 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003772 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003773 },
3774 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003775 renegotiate: 1,
3776 flags: []string{
3777 "-renegotiate-freely",
3778 "-expect-total-renegotiations", "1",
3779 },
David Benjamincdea40c2015-03-19 14:09:43 -04003780 })
3781 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003782 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003783 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003784 config: Config{
3785 Bugs: ProtocolBugs{
3786 EmptyRenegotiationInfo: true,
3787 },
3788 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003789 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003790 shouldFail: true,
3791 expectedError: ":RENEGOTIATION_MISMATCH:",
3792 })
3793 testCases = append(testCases, testCase{
3794 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003795 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003796 config: Config{
3797 Bugs: ProtocolBugs{
3798 BadRenegotiationInfo: true,
3799 },
3800 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003801 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003802 shouldFail: true,
3803 expectedError: ":RENEGOTIATION_MISMATCH:",
3804 })
3805 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003806 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003807 config: Config{
3808 Bugs: ProtocolBugs{
3809 NoRenegotiationInfo: true,
3810 },
3811 },
3812 shouldFail: true,
3813 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3814 flags: []string{"-no-legacy-server-connect"},
3815 })
3816 testCases = append(testCases, testCase{
3817 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003818 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003819 config: Config{
3820 Bugs: ProtocolBugs{
3821 NoRenegotiationInfo: true,
3822 },
3823 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003824 flags: []string{
3825 "-renegotiate-freely",
3826 "-expect-total-renegotiations", "1",
3827 },
David Benjamincff0b902015-05-15 23:09:47 -04003828 })
3829 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003830 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003831 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003832 config: Config{
3833 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3834 },
3835 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003836 flags: []string{
3837 "-renegotiate-freely",
3838 "-expect-total-renegotiations", "1",
3839 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003840 })
3841 testCases = append(testCases, testCase{
3842 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003843 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003844 config: Config{
3845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3846 },
3847 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003848 flags: []string{
3849 "-renegotiate-freely",
3850 "-expect-total-renegotiations", "1",
3851 },
David Benjaminb16346b2015-04-08 19:16:58 -04003852 })
3853 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003854 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003855 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003856 config: Config{
3857 MaxVersion: VersionTLS10,
3858 Bugs: ProtocolBugs{
3859 RequireSameRenegoClientVersion: true,
3860 },
3861 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003862 flags: []string{
3863 "-renegotiate-freely",
3864 "-expect-total-renegotiations", "1",
3865 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003866 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003867 testCases = append(testCases, testCase{
3868 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003869 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003870 config: Config{
3871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3872 NextProtos: []string{"foo"},
3873 },
3874 flags: []string{
3875 "-false-start",
3876 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003877 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003878 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003879 },
3880 shimWritesFirst: true,
3881 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003882
3883 // Client-side renegotiation controls.
3884 testCases = append(testCases, testCase{
3885 name: "Renegotiate-Client-Forbidden-1",
3886 renegotiate: 1,
3887 shouldFail: true,
3888 expectedError: ":NO_RENEGOTIATION:",
3889 expectedLocalError: "remote error: no renegotiation",
3890 })
3891 testCases = append(testCases, testCase{
3892 name: "Renegotiate-Client-Once-1",
3893 renegotiate: 1,
3894 flags: []string{
3895 "-renegotiate-once",
3896 "-expect-total-renegotiations", "1",
3897 },
3898 })
3899 testCases = append(testCases, testCase{
3900 name: "Renegotiate-Client-Freely-1",
3901 renegotiate: 1,
3902 flags: []string{
3903 "-renegotiate-freely",
3904 "-expect-total-renegotiations", "1",
3905 },
3906 })
3907 testCases = append(testCases, testCase{
3908 name: "Renegotiate-Client-Once-2",
3909 renegotiate: 2,
3910 flags: []string{"-renegotiate-once"},
3911 shouldFail: true,
3912 expectedError: ":NO_RENEGOTIATION:",
3913 expectedLocalError: "remote error: no renegotiation",
3914 })
3915 testCases = append(testCases, testCase{
3916 name: "Renegotiate-Client-Freely-2",
3917 renegotiate: 2,
3918 flags: []string{
3919 "-renegotiate-freely",
3920 "-expect-total-renegotiations", "2",
3921 },
3922 })
Adam Langley27a0d082015-11-03 13:34:10 -08003923 testCases = append(testCases, testCase{
3924 name: "Renegotiate-Client-NoIgnore",
3925 config: Config{
3926 Bugs: ProtocolBugs{
3927 SendHelloRequestBeforeEveryAppDataRecord: true,
3928 },
3929 },
3930 shouldFail: true,
3931 expectedError: ":NO_RENEGOTIATION:",
3932 })
3933 testCases = append(testCases, testCase{
3934 name: "Renegotiate-Client-Ignore",
3935 config: Config{
3936 Bugs: ProtocolBugs{
3937 SendHelloRequestBeforeEveryAppDataRecord: true,
3938 },
3939 },
3940 flags: []string{
3941 "-renegotiate-ignore",
3942 "-expect-total-renegotiations", "0",
3943 },
3944 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003945}
3946
David Benjamin5e961c12014-11-07 01:48:35 -05003947func addDTLSReplayTests() {
3948 // Test that sequence number replays are detected.
3949 testCases = append(testCases, testCase{
3950 protocol: dtls,
3951 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003952 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003953 replayWrites: true,
3954 })
3955
David Benjamin8e6db492015-07-25 18:29:23 -04003956 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003957 // than the retransmit window.
3958 testCases = append(testCases, testCase{
3959 protocol: dtls,
3960 name: "DTLS-Replay-LargeGaps",
3961 config: Config{
3962 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003963 SequenceNumberMapping: func(in uint64) uint64 {
3964 return in * 127
3965 },
David Benjamin5e961c12014-11-07 01:48:35 -05003966 },
3967 },
David Benjamin8e6db492015-07-25 18:29:23 -04003968 messageCount: 200,
3969 replayWrites: true,
3970 })
3971
3972 // Test the incoming sequence number changing non-monotonically.
3973 testCases = append(testCases, testCase{
3974 protocol: dtls,
3975 name: "DTLS-Replay-NonMonotonic",
3976 config: Config{
3977 Bugs: ProtocolBugs{
3978 SequenceNumberMapping: func(in uint64) uint64 {
3979 return in ^ 31
3980 },
3981 },
3982 },
3983 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003984 replayWrites: true,
3985 })
3986}
3987
David Benjamin000800a2014-11-14 01:43:59 -05003988var testHashes = []struct {
3989 name string
3990 id uint8
3991}{
3992 {"SHA1", hashSHA1},
3993 {"SHA224", hashSHA224},
3994 {"SHA256", hashSHA256},
3995 {"SHA384", hashSHA384},
3996 {"SHA512", hashSHA512},
3997}
3998
3999func addSigningHashTests() {
4000 // Make sure each hash works. Include some fake hashes in the list and
4001 // ensure they're ignored.
4002 for _, hash := range testHashes {
4003 testCases = append(testCases, testCase{
4004 name: "SigningHash-ClientAuth-" + hash.name,
4005 config: Config{
4006 ClientAuth: RequireAnyClientCert,
4007 SignatureAndHashes: []signatureAndHash{
4008 {signatureRSA, 42},
4009 {signatureRSA, hash.id},
4010 {signatureRSA, 255},
4011 },
4012 },
4013 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004014 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4015 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004016 },
4017 })
4018
4019 testCases = append(testCases, testCase{
4020 testType: serverTest,
4021 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4022 config: Config{
4023 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4024 SignatureAndHashes: []signatureAndHash{
4025 {signatureRSA, 42},
4026 {signatureRSA, hash.id},
4027 {signatureRSA, 255},
4028 },
4029 },
4030 })
4031 }
4032
4033 // Test that hash resolution takes the signature type into account.
4034 testCases = append(testCases, testCase{
4035 name: "SigningHash-ClientAuth-SignatureType",
4036 config: Config{
4037 ClientAuth: RequireAnyClientCert,
4038 SignatureAndHashes: []signatureAndHash{
4039 {signatureECDSA, hashSHA512},
4040 {signatureRSA, hashSHA384},
4041 {signatureECDSA, hashSHA1},
4042 },
4043 },
4044 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004045 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4046 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004047 },
4048 })
4049
4050 testCases = append(testCases, testCase{
4051 testType: serverTest,
4052 name: "SigningHash-ServerKeyExchange-SignatureType",
4053 config: Config{
4054 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4055 SignatureAndHashes: []signatureAndHash{
4056 {signatureECDSA, hashSHA512},
4057 {signatureRSA, hashSHA384},
4058 {signatureECDSA, hashSHA1},
4059 },
4060 },
4061 })
4062
4063 // Test that, if the list is missing, the peer falls back to SHA-1.
4064 testCases = append(testCases, testCase{
4065 name: "SigningHash-ClientAuth-Fallback",
4066 config: Config{
4067 ClientAuth: RequireAnyClientCert,
4068 SignatureAndHashes: []signatureAndHash{
4069 {signatureRSA, hashSHA1},
4070 },
4071 Bugs: ProtocolBugs{
4072 NoSignatureAndHashes: true,
4073 },
4074 },
4075 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004076 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4077 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004078 },
4079 })
4080
4081 testCases = append(testCases, testCase{
4082 testType: serverTest,
4083 name: "SigningHash-ServerKeyExchange-Fallback",
4084 config: Config{
4085 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4086 SignatureAndHashes: []signatureAndHash{
4087 {signatureRSA, hashSHA1},
4088 },
4089 Bugs: ProtocolBugs{
4090 NoSignatureAndHashes: true,
4091 },
4092 },
4093 })
David Benjamin72dc7832015-03-16 17:49:43 -04004094
4095 // Test that hash preferences are enforced. BoringSSL defaults to
4096 // rejecting MD5 signatures.
4097 testCases = append(testCases, testCase{
4098 testType: serverTest,
4099 name: "SigningHash-ClientAuth-Enforced",
4100 config: Config{
4101 Certificates: []Certificate{rsaCertificate},
4102 SignatureAndHashes: []signatureAndHash{
4103 {signatureRSA, hashMD5},
4104 // Advertise SHA-1 so the handshake will
4105 // proceed, but the shim's preferences will be
4106 // ignored in CertificateVerify generation, so
4107 // MD5 will be chosen.
4108 {signatureRSA, hashSHA1},
4109 },
4110 Bugs: ProtocolBugs{
4111 IgnorePeerSignatureAlgorithmPreferences: true,
4112 },
4113 },
4114 flags: []string{"-require-any-client-certificate"},
4115 shouldFail: true,
4116 expectedError: ":WRONG_SIGNATURE_TYPE:",
4117 })
4118
4119 testCases = append(testCases, testCase{
4120 name: "SigningHash-ServerKeyExchange-Enforced",
4121 config: Config{
4122 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4123 SignatureAndHashes: []signatureAndHash{
4124 {signatureRSA, hashMD5},
4125 },
4126 Bugs: ProtocolBugs{
4127 IgnorePeerSignatureAlgorithmPreferences: true,
4128 },
4129 },
4130 shouldFail: true,
4131 expectedError: ":WRONG_SIGNATURE_TYPE:",
4132 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004133
4134 // Test that the agreed upon digest respects the client preferences and
4135 // the server digests.
4136 testCases = append(testCases, testCase{
4137 name: "Agree-Digest-Fallback",
4138 config: Config{
4139 ClientAuth: RequireAnyClientCert,
4140 SignatureAndHashes: []signatureAndHash{
4141 {signatureRSA, hashSHA512},
4142 {signatureRSA, hashSHA1},
4143 },
4144 },
4145 flags: []string{
4146 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4147 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4148 },
4149 digestPrefs: "SHA256",
4150 expectedClientCertSignatureHash: hashSHA1,
4151 })
4152 testCases = append(testCases, testCase{
4153 name: "Agree-Digest-SHA256",
4154 config: Config{
4155 ClientAuth: RequireAnyClientCert,
4156 SignatureAndHashes: []signatureAndHash{
4157 {signatureRSA, hashSHA1},
4158 {signatureRSA, hashSHA256},
4159 },
4160 },
4161 flags: []string{
4162 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4163 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4164 },
4165 digestPrefs: "SHA256,SHA1",
4166 expectedClientCertSignatureHash: hashSHA256,
4167 })
4168 testCases = append(testCases, testCase{
4169 name: "Agree-Digest-SHA1",
4170 config: Config{
4171 ClientAuth: RequireAnyClientCert,
4172 SignatureAndHashes: []signatureAndHash{
4173 {signatureRSA, hashSHA1},
4174 },
4175 },
4176 flags: []string{
4177 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4178 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4179 },
4180 digestPrefs: "SHA512,SHA256,SHA1",
4181 expectedClientCertSignatureHash: hashSHA1,
4182 })
4183 testCases = append(testCases, testCase{
4184 name: "Agree-Digest-Default",
4185 config: Config{
4186 ClientAuth: RequireAnyClientCert,
4187 SignatureAndHashes: []signatureAndHash{
4188 {signatureRSA, hashSHA256},
4189 {signatureECDSA, hashSHA256},
4190 {signatureRSA, hashSHA1},
4191 {signatureECDSA, hashSHA1},
4192 },
4193 },
4194 flags: []string{
4195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4197 },
4198 expectedClientCertSignatureHash: hashSHA256,
4199 })
David Benjamin000800a2014-11-14 01:43:59 -05004200}
4201
David Benjamin83f90402015-01-27 01:09:43 -05004202// timeouts is the retransmit schedule for BoringSSL. It doubles and
4203// caps at 60 seconds. On the 13th timeout, it gives up.
4204var timeouts = []time.Duration{
4205 1 * time.Second,
4206 2 * time.Second,
4207 4 * time.Second,
4208 8 * time.Second,
4209 16 * time.Second,
4210 32 * time.Second,
4211 60 * time.Second,
4212 60 * time.Second,
4213 60 * time.Second,
4214 60 * time.Second,
4215 60 * time.Second,
4216 60 * time.Second,
4217 60 * time.Second,
4218}
4219
4220func addDTLSRetransmitTests() {
4221 // Test that this is indeed the timeout schedule. Stress all
4222 // four patterns of handshake.
4223 for i := 1; i < len(timeouts); i++ {
4224 number := strconv.Itoa(i)
4225 testCases = append(testCases, testCase{
4226 protocol: dtls,
4227 name: "DTLS-Retransmit-Client-" + number,
4228 config: Config{
4229 Bugs: ProtocolBugs{
4230 TimeoutSchedule: timeouts[:i],
4231 },
4232 },
4233 resumeSession: true,
4234 flags: []string{"-async"},
4235 })
4236 testCases = append(testCases, testCase{
4237 protocol: dtls,
4238 testType: serverTest,
4239 name: "DTLS-Retransmit-Server-" + number,
4240 config: Config{
4241 Bugs: ProtocolBugs{
4242 TimeoutSchedule: timeouts[:i],
4243 },
4244 },
4245 resumeSession: true,
4246 flags: []string{"-async"},
4247 })
4248 }
4249
4250 // Test that exceeding the timeout schedule hits a read
4251 // timeout.
4252 testCases = append(testCases, testCase{
4253 protocol: dtls,
4254 name: "DTLS-Retransmit-Timeout",
4255 config: Config{
4256 Bugs: ProtocolBugs{
4257 TimeoutSchedule: timeouts,
4258 },
4259 },
4260 resumeSession: true,
4261 flags: []string{"-async"},
4262 shouldFail: true,
4263 expectedError: ":READ_TIMEOUT_EXPIRED:",
4264 })
4265
4266 // Test that timeout handling has a fudge factor, due to API
4267 // problems.
4268 testCases = append(testCases, testCase{
4269 protocol: dtls,
4270 name: "DTLS-Retransmit-Fudge",
4271 config: Config{
4272 Bugs: ProtocolBugs{
4273 TimeoutSchedule: []time.Duration{
4274 timeouts[0] - 10*time.Millisecond,
4275 },
4276 },
4277 },
4278 resumeSession: true,
4279 flags: []string{"-async"},
4280 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004281
4282 // Test that the final Finished retransmitting isn't
4283 // duplicated if the peer badly fragments everything.
4284 testCases = append(testCases, testCase{
4285 testType: serverTest,
4286 protocol: dtls,
4287 name: "DTLS-Retransmit-Fragmented",
4288 config: Config{
4289 Bugs: ProtocolBugs{
4290 TimeoutSchedule: []time.Duration{timeouts[0]},
4291 MaxHandshakeRecordLength: 2,
4292 },
4293 },
4294 flags: []string{"-async"},
4295 })
David Benjamin83f90402015-01-27 01:09:43 -05004296}
4297
David Benjaminc565ebb2015-04-03 04:06:36 -04004298func addExportKeyingMaterialTests() {
4299 for _, vers := range tlsVersions {
4300 if vers.version == VersionSSL30 {
4301 continue
4302 }
4303 testCases = append(testCases, testCase{
4304 name: "ExportKeyingMaterial-" + vers.name,
4305 config: Config{
4306 MaxVersion: vers.version,
4307 },
4308 exportKeyingMaterial: 1024,
4309 exportLabel: "label",
4310 exportContext: "context",
4311 useExportContext: true,
4312 })
4313 testCases = append(testCases, testCase{
4314 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4315 config: Config{
4316 MaxVersion: vers.version,
4317 },
4318 exportKeyingMaterial: 1024,
4319 })
4320 testCases = append(testCases, testCase{
4321 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4322 config: Config{
4323 MaxVersion: vers.version,
4324 },
4325 exportKeyingMaterial: 1024,
4326 useExportContext: true,
4327 })
4328 testCases = append(testCases, testCase{
4329 name: "ExportKeyingMaterial-Small-" + vers.name,
4330 config: Config{
4331 MaxVersion: vers.version,
4332 },
4333 exportKeyingMaterial: 1,
4334 exportLabel: "label",
4335 exportContext: "context",
4336 useExportContext: true,
4337 })
4338 }
4339 testCases = append(testCases, testCase{
4340 name: "ExportKeyingMaterial-SSL3",
4341 config: Config{
4342 MaxVersion: VersionSSL30,
4343 },
4344 exportKeyingMaterial: 1024,
4345 exportLabel: "label",
4346 exportContext: "context",
4347 useExportContext: true,
4348 shouldFail: true,
4349 expectedError: "failed to export keying material",
4350 })
4351}
4352
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004353func addTLSUniqueTests() {
4354 for _, isClient := range []bool{false, true} {
4355 for _, isResumption := range []bool{false, true} {
4356 for _, hasEMS := range []bool{false, true} {
4357 var suffix string
4358 if isResumption {
4359 suffix = "Resume-"
4360 } else {
4361 suffix = "Full-"
4362 }
4363
4364 if hasEMS {
4365 suffix += "EMS-"
4366 } else {
4367 suffix += "NoEMS-"
4368 }
4369
4370 if isClient {
4371 suffix += "Client"
4372 } else {
4373 suffix += "Server"
4374 }
4375
4376 test := testCase{
4377 name: "TLSUnique-" + suffix,
4378 testTLSUnique: true,
4379 config: Config{
4380 Bugs: ProtocolBugs{
4381 NoExtendedMasterSecret: !hasEMS,
4382 },
4383 },
4384 }
4385
4386 if isResumption {
4387 test.resumeSession = true
4388 test.resumeConfig = &Config{
4389 Bugs: ProtocolBugs{
4390 NoExtendedMasterSecret: !hasEMS,
4391 },
4392 }
4393 }
4394
4395 if isResumption && !hasEMS {
4396 test.shouldFail = true
4397 test.expectedError = "failed to get tls-unique"
4398 }
4399
4400 testCases = append(testCases, test)
4401 }
4402 }
4403 }
4404}
4405
Adam Langley09505632015-07-30 18:10:13 -07004406func addCustomExtensionTests() {
4407 expectedContents := "custom extension"
4408 emptyString := ""
4409
4410 for _, isClient := range []bool{false, true} {
4411 suffix := "Server"
4412 flag := "-enable-server-custom-extension"
4413 testType := serverTest
4414 if isClient {
4415 suffix = "Client"
4416 flag = "-enable-client-custom-extension"
4417 testType = clientTest
4418 }
4419
4420 testCases = append(testCases, testCase{
4421 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004422 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004423 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004424 Bugs: ProtocolBugs{
4425 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004426 ExpectedCustomExtension: &expectedContents,
4427 },
4428 },
4429 flags: []string{flag},
4430 })
4431
4432 // If the parse callback fails, the handshake should also fail.
4433 testCases = append(testCases, testCase{
4434 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004435 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004436 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004437 Bugs: ProtocolBugs{
4438 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004439 ExpectedCustomExtension: &expectedContents,
4440 },
4441 },
David Benjamin399e7c92015-07-30 23:01:27 -04004442 flags: []string{flag},
4443 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004444 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4445 })
4446
4447 // If the add callback fails, the handshake should also fail.
4448 testCases = append(testCases, testCase{
4449 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004450 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004451 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004452 Bugs: ProtocolBugs{
4453 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004454 ExpectedCustomExtension: &expectedContents,
4455 },
4456 },
David Benjamin399e7c92015-07-30 23:01:27 -04004457 flags: []string{flag, "-custom-extension-fail-add"},
4458 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004459 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4460 })
4461
4462 // If the add callback returns zero, no extension should be
4463 // added.
4464 skipCustomExtension := expectedContents
4465 if isClient {
4466 // For the case where the client skips sending the
4467 // custom extension, the server must not “echo” it.
4468 skipCustomExtension = ""
4469 }
4470 testCases = append(testCases, testCase{
4471 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004472 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004473 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004474 Bugs: ProtocolBugs{
4475 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004476 ExpectedCustomExtension: &emptyString,
4477 },
4478 },
4479 flags: []string{flag, "-custom-extension-skip"},
4480 })
4481 }
4482
4483 // The custom extension add callback should not be called if the client
4484 // doesn't send the extension.
4485 testCases = append(testCases, testCase{
4486 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004487 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004488 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004489 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004490 ExpectedCustomExtension: &emptyString,
4491 },
4492 },
4493 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4494 })
Adam Langley2deb9842015-08-07 11:15:37 -07004495
4496 // Test an unknown extension from the server.
4497 testCases = append(testCases, testCase{
4498 testType: clientTest,
4499 name: "UnknownExtension-Client",
4500 config: Config{
4501 Bugs: ProtocolBugs{
4502 CustomExtension: expectedContents,
4503 },
4504 },
4505 shouldFail: true,
4506 expectedError: ":UNEXPECTED_EXTENSION:",
4507 })
Adam Langley09505632015-07-30 18:10:13 -07004508}
4509
Adam Langley7c803a62015-06-15 15:35:05 -07004510func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004511 defer wg.Done()
4512
4513 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004514 var err error
4515
4516 if *mallocTest < 0 {
4517 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004518 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004519 } else {
4520 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4521 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004522 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004523 if err != nil {
4524 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4525 }
4526 break
4527 }
4528 }
4529 }
Adam Langley95c29f32014-06-20 12:00:00 -07004530 statusChan <- statusMsg{test: test, err: err}
4531 }
4532}
4533
4534type statusMsg struct {
4535 test *testCase
4536 started bool
4537 err error
4538}
4539
David Benjamin5f237bc2015-02-11 17:14:15 -05004540func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004541 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004542
David Benjamin5f237bc2015-02-11 17:14:15 -05004543 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004544 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004545 if !*pipe {
4546 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004547 var erase string
4548 for i := 0; i < lineLen; i++ {
4549 erase += "\b \b"
4550 }
4551 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004552 }
4553
Adam Langley95c29f32014-06-20 12:00:00 -07004554 if msg.started {
4555 started++
4556 } else {
4557 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004558
4559 if msg.err != nil {
4560 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4561 failed++
4562 testOutput.addResult(msg.test.name, "FAIL")
4563 } else {
4564 if *pipe {
4565 // Print each test instead of a status line.
4566 fmt.Printf("PASSED (%s)\n", msg.test.name)
4567 }
4568 testOutput.addResult(msg.test.name, "PASS")
4569 }
Adam Langley95c29f32014-06-20 12:00:00 -07004570 }
4571
David Benjamin5f237bc2015-02-11 17:14:15 -05004572 if !*pipe {
4573 // Print a new status line.
4574 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4575 lineLen = len(line)
4576 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004577 }
Adam Langley95c29f32014-06-20 12:00:00 -07004578 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004579
4580 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004581}
4582
4583func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004584 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004585 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004586
Adam Langley7c803a62015-06-15 15:35:05 -07004587 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004588 addCipherSuiteTests()
4589 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004590 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004591 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004592 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004593 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004594 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004595 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004596 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004597 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004598 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004599 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004600 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004601 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004602 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004603 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004604 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004605 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004606 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004607 for _, async := range []bool{false, true} {
4608 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004609 for _, protocol := range []protocol{tls, dtls} {
4610 addStateMachineCoverageTests(async, splitHandshake, protocol)
4611 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004612 }
4613 }
Adam Langley95c29f32014-06-20 12:00:00 -07004614
4615 var wg sync.WaitGroup
4616
Adam Langley7c803a62015-06-15 15:35:05 -07004617 statusChan := make(chan statusMsg, *numWorkers)
4618 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004619 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004620
David Benjamin025b3d32014-07-01 19:53:04 -04004621 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004622
Adam Langley7c803a62015-06-15 15:35:05 -07004623 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004624 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004625 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004626 }
4627
David Benjamin025b3d32014-07-01 19:53:04 -04004628 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004629 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004630 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004631 }
4632 }
4633
4634 close(testChan)
4635 wg.Wait()
4636 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004637 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004638
4639 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004640
4641 if *jsonOutput != "" {
4642 if err := testOutput.writeTo(*jsonOutput); err != nil {
4643 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4644 }
4645 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004646
4647 if !testOutput.allPassed {
4648 os.Exit(1)
4649 }
Adam Langley95c29f32014-06-20 12:00:00 -07004650}