blob: 158f0823384230748a6aaec4caf72a061e1bc2b5 [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 Benjamin760b1dd2015-05-15 23:33:48 -04002935 for _, test := range tests {
2936 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05002937 if protocol == dtls {
2938 test.name += "-DTLS"
2939 }
2940 if async {
2941 test.name += "-Async"
2942 test.flags = append(test.flags, "-async")
2943 } else {
2944 test.name += "-Sync"
2945 }
2946 if splitHandshake {
2947 test.name += "-SplitHandshakeRecords"
2948 test.config.Bugs.MaxHandshakeRecordLength = 1
2949 if protocol == dtls {
2950 test.config.Bugs.MaxPacketLength = 256
2951 test.flags = append(test.flags, "-mtu", "256")
2952 }
2953 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002954 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002955 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002956}
2957
Adam Langley524e7172015-02-20 16:04:00 -08002958func addDDoSCallbackTests() {
2959 // DDoS callback.
2960
2961 for _, resume := range []bool{false, true} {
2962 suffix := "Resume"
2963 if resume {
2964 suffix = "No" + suffix
2965 }
2966
2967 testCases = append(testCases, testCase{
2968 testType: serverTest,
2969 name: "Server-DDoS-OK-" + suffix,
2970 flags: []string{"-install-ddos-callback"},
2971 resumeSession: resume,
2972 })
2973
2974 failFlag := "-fail-ddos-callback"
2975 if resume {
2976 failFlag = "-fail-second-ddos-callback"
2977 }
2978 testCases = append(testCases, testCase{
2979 testType: serverTest,
2980 name: "Server-DDoS-Reject-" + suffix,
2981 flags: []string{"-install-ddos-callback", failFlag},
2982 resumeSession: resume,
2983 shouldFail: true,
2984 expectedError: ":CONNECTION_REJECTED:",
2985 })
2986 }
2987}
2988
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002989func addVersionNegotiationTests() {
2990 for i, shimVers := range tlsVersions {
2991 // Assemble flags to disable all newer versions on the shim.
2992 var flags []string
2993 for _, vers := range tlsVersions[i+1:] {
2994 flags = append(flags, vers.flag)
2995 }
2996
2997 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002998 protocols := []protocol{tls}
2999 if runnerVers.hasDTLS && shimVers.hasDTLS {
3000 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003001 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003002 for _, protocol := range protocols {
3003 expectedVersion := shimVers.version
3004 if runnerVers.version < shimVers.version {
3005 expectedVersion = runnerVers.version
3006 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003007
David Benjamin8b8c0062014-11-23 02:47:52 -05003008 suffix := shimVers.name + "-" + runnerVers.name
3009 if protocol == dtls {
3010 suffix += "-DTLS"
3011 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003012
David Benjamin1eb367c2014-12-12 18:17:51 -05003013 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3014
David Benjamin1e29a6b2014-12-10 02:27:24 -05003015 clientVers := shimVers.version
3016 if clientVers > VersionTLS10 {
3017 clientVers = VersionTLS10
3018 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003019 testCases = append(testCases, testCase{
3020 protocol: protocol,
3021 testType: clientTest,
3022 name: "VersionNegotiation-Client-" + suffix,
3023 config: Config{
3024 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003025 Bugs: ProtocolBugs{
3026 ExpectInitialRecordVersion: clientVers,
3027 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003028 },
3029 flags: flags,
3030 expectedVersion: expectedVersion,
3031 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003032 testCases = append(testCases, testCase{
3033 protocol: protocol,
3034 testType: clientTest,
3035 name: "VersionNegotiation-Client2-" + suffix,
3036 config: Config{
3037 MaxVersion: runnerVers.version,
3038 Bugs: ProtocolBugs{
3039 ExpectInitialRecordVersion: clientVers,
3040 },
3041 },
3042 flags: []string{"-max-version", shimVersFlag},
3043 expectedVersion: expectedVersion,
3044 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003045
3046 testCases = append(testCases, testCase{
3047 protocol: protocol,
3048 testType: serverTest,
3049 name: "VersionNegotiation-Server-" + suffix,
3050 config: Config{
3051 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003052 Bugs: ProtocolBugs{
3053 ExpectInitialRecordVersion: expectedVersion,
3054 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003055 },
3056 flags: flags,
3057 expectedVersion: expectedVersion,
3058 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003059 testCases = append(testCases, testCase{
3060 protocol: protocol,
3061 testType: serverTest,
3062 name: "VersionNegotiation-Server2-" + suffix,
3063 config: Config{
3064 MaxVersion: runnerVers.version,
3065 Bugs: ProtocolBugs{
3066 ExpectInitialRecordVersion: expectedVersion,
3067 },
3068 },
3069 flags: []string{"-max-version", shimVersFlag},
3070 expectedVersion: expectedVersion,
3071 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003072 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003073 }
3074 }
3075}
3076
David Benjaminaccb4542014-12-12 23:44:33 -05003077func addMinimumVersionTests() {
3078 for i, shimVers := range tlsVersions {
3079 // Assemble flags to disable all older versions on the shim.
3080 var flags []string
3081 for _, vers := range tlsVersions[:i] {
3082 flags = append(flags, vers.flag)
3083 }
3084
3085 for _, runnerVers := range tlsVersions {
3086 protocols := []protocol{tls}
3087 if runnerVers.hasDTLS && shimVers.hasDTLS {
3088 protocols = append(protocols, dtls)
3089 }
3090 for _, protocol := range protocols {
3091 suffix := shimVers.name + "-" + runnerVers.name
3092 if protocol == dtls {
3093 suffix += "-DTLS"
3094 }
3095 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3096
David Benjaminaccb4542014-12-12 23:44:33 -05003097 var expectedVersion uint16
3098 var shouldFail bool
3099 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003100 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003101 if runnerVers.version >= shimVers.version {
3102 expectedVersion = runnerVers.version
3103 } else {
3104 shouldFail = true
3105 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003106 if runnerVers.version > VersionSSL30 {
3107 expectedLocalError = "remote error: protocol version not supported"
3108 } else {
3109 expectedLocalError = "remote error: handshake failure"
3110 }
David Benjaminaccb4542014-12-12 23:44:33 -05003111 }
3112
3113 testCases = append(testCases, testCase{
3114 protocol: protocol,
3115 testType: clientTest,
3116 name: "MinimumVersion-Client-" + suffix,
3117 config: Config{
3118 MaxVersion: runnerVers.version,
3119 },
David Benjamin87909c02014-12-13 01:55:01 -05003120 flags: flags,
3121 expectedVersion: expectedVersion,
3122 shouldFail: shouldFail,
3123 expectedError: expectedError,
3124 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003125 })
3126 testCases = append(testCases, testCase{
3127 protocol: protocol,
3128 testType: clientTest,
3129 name: "MinimumVersion-Client2-" + suffix,
3130 config: Config{
3131 MaxVersion: runnerVers.version,
3132 },
David Benjamin87909c02014-12-13 01:55:01 -05003133 flags: []string{"-min-version", shimVersFlag},
3134 expectedVersion: expectedVersion,
3135 shouldFail: shouldFail,
3136 expectedError: expectedError,
3137 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003138 })
3139
3140 testCases = append(testCases, testCase{
3141 protocol: protocol,
3142 testType: serverTest,
3143 name: "MinimumVersion-Server-" + suffix,
3144 config: Config{
3145 MaxVersion: runnerVers.version,
3146 },
David Benjamin87909c02014-12-13 01:55:01 -05003147 flags: flags,
3148 expectedVersion: expectedVersion,
3149 shouldFail: shouldFail,
3150 expectedError: expectedError,
3151 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003152 })
3153 testCases = append(testCases, testCase{
3154 protocol: protocol,
3155 testType: serverTest,
3156 name: "MinimumVersion-Server2-" + suffix,
3157 config: Config{
3158 MaxVersion: runnerVers.version,
3159 },
David Benjamin87909c02014-12-13 01:55:01 -05003160 flags: []string{"-min-version", shimVersFlag},
3161 expectedVersion: expectedVersion,
3162 shouldFail: shouldFail,
3163 expectedError: expectedError,
3164 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003165 })
3166 }
3167 }
3168 }
3169}
3170
David Benjamin5c24a1d2014-08-31 00:59:27 -04003171func addD5BugTests() {
3172 testCases = append(testCases, testCase{
3173 testType: serverTest,
3174 name: "D5Bug-NoQuirk-Reject",
3175 config: Config{
3176 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3177 Bugs: ProtocolBugs{
3178 SSL3RSAKeyExchange: true,
3179 },
3180 },
3181 shouldFail: true,
3182 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3183 })
3184 testCases = append(testCases, testCase{
3185 testType: serverTest,
3186 name: "D5Bug-Quirk-Normal",
3187 config: Config{
3188 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3189 },
3190 flags: []string{"-tls-d5-bug"},
3191 })
3192 testCases = append(testCases, testCase{
3193 testType: serverTest,
3194 name: "D5Bug-Quirk-Bug",
3195 config: Config{
3196 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3197 Bugs: ProtocolBugs{
3198 SSL3RSAKeyExchange: true,
3199 },
3200 },
3201 flags: []string{"-tls-d5-bug"},
3202 })
3203}
3204
David Benjamine78bfde2014-09-06 12:45:15 -04003205func addExtensionTests() {
3206 testCases = append(testCases, testCase{
3207 testType: clientTest,
3208 name: "DuplicateExtensionClient",
3209 config: Config{
3210 Bugs: ProtocolBugs{
3211 DuplicateExtension: true,
3212 },
3213 },
3214 shouldFail: true,
3215 expectedLocalError: "remote error: error decoding message",
3216 })
3217 testCases = append(testCases, testCase{
3218 testType: serverTest,
3219 name: "DuplicateExtensionServer",
3220 config: Config{
3221 Bugs: ProtocolBugs{
3222 DuplicateExtension: true,
3223 },
3224 },
3225 shouldFail: true,
3226 expectedLocalError: "remote error: error decoding message",
3227 })
3228 testCases = append(testCases, testCase{
3229 testType: clientTest,
3230 name: "ServerNameExtensionClient",
3231 config: Config{
3232 Bugs: ProtocolBugs{
3233 ExpectServerName: "example.com",
3234 },
3235 },
3236 flags: []string{"-host-name", "example.com"},
3237 })
3238 testCases = append(testCases, testCase{
3239 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003240 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003241 config: Config{
3242 Bugs: ProtocolBugs{
3243 ExpectServerName: "mismatch.com",
3244 },
3245 },
3246 flags: []string{"-host-name", "example.com"},
3247 shouldFail: true,
3248 expectedLocalError: "tls: unexpected server name",
3249 })
3250 testCases = append(testCases, testCase{
3251 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003252 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003253 config: Config{
3254 Bugs: ProtocolBugs{
3255 ExpectServerName: "missing.com",
3256 },
3257 },
3258 shouldFail: true,
3259 expectedLocalError: "tls: unexpected server name",
3260 })
3261 testCases = append(testCases, testCase{
3262 testType: serverTest,
3263 name: "ServerNameExtensionServer",
3264 config: Config{
3265 ServerName: "example.com",
3266 },
3267 flags: []string{"-expect-server-name", "example.com"},
3268 resumeSession: true,
3269 })
David Benjaminae2888f2014-09-06 12:58:58 -04003270 testCases = append(testCases, testCase{
3271 testType: clientTest,
3272 name: "ALPNClient",
3273 config: Config{
3274 NextProtos: []string{"foo"},
3275 },
3276 flags: []string{
3277 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3278 "-expect-alpn", "foo",
3279 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003280 expectedNextProto: "foo",
3281 expectedNextProtoType: alpn,
3282 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003283 })
3284 testCases = append(testCases, testCase{
3285 testType: serverTest,
3286 name: "ALPNServer",
3287 config: Config{
3288 NextProtos: []string{"foo", "bar", "baz"},
3289 },
3290 flags: []string{
3291 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3292 "-select-alpn", "foo",
3293 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003294 expectedNextProto: "foo",
3295 expectedNextProtoType: alpn,
3296 resumeSession: true,
3297 })
3298 // Test that the server prefers ALPN over NPN.
3299 testCases = append(testCases, testCase{
3300 testType: serverTest,
3301 name: "ALPNServer-Preferred",
3302 config: Config{
3303 NextProtos: []string{"foo", "bar", "baz"},
3304 },
3305 flags: []string{
3306 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3307 "-select-alpn", "foo",
3308 "-advertise-npn", "\x03foo\x03bar\x03baz",
3309 },
3310 expectedNextProto: "foo",
3311 expectedNextProtoType: alpn,
3312 resumeSession: true,
3313 })
3314 testCases = append(testCases, testCase{
3315 testType: serverTest,
3316 name: "ALPNServer-Preferred-Swapped",
3317 config: Config{
3318 NextProtos: []string{"foo", "bar", "baz"},
3319 Bugs: ProtocolBugs{
3320 SwapNPNAndALPN: true,
3321 },
3322 },
3323 flags: []string{
3324 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3325 "-select-alpn", "foo",
3326 "-advertise-npn", "\x03foo\x03bar\x03baz",
3327 },
3328 expectedNextProto: "foo",
3329 expectedNextProtoType: alpn,
3330 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003331 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003332 var emptyString string
3333 testCases = append(testCases, testCase{
3334 testType: clientTest,
3335 name: "ALPNClient-EmptyProtocolName",
3336 config: Config{
3337 NextProtos: []string{""},
3338 Bugs: ProtocolBugs{
3339 // A server returning an empty ALPN protocol
3340 // should be rejected.
3341 ALPNProtocol: &emptyString,
3342 },
3343 },
3344 flags: []string{
3345 "-advertise-alpn", "\x03foo",
3346 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003347 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003348 expectedError: ":PARSE_TLSEXT:",
3349 })
3350 testCases = append(testCases, testCase{
3351 testType: serverTest,
3352 name: "ALPNServer-EmptyProtocolName",
3353 config: Config{
3354 // A ClientHello containing an empty ALPN protocol
3355 // should be rejected.
3356 NextProtos: []string{"foo", "", "baz"},
3357 },
3358 flags: []string{
3359 "-select-alpn", "foo",
3360 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003361 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003362 expectedError: ":PARSE_TLSEXT:",
3363 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003364 // Test that negotiating both NPN and ALPN is forbidden.
3365 testCases = append(testCases, testCase{
3366 name: "NegotiateALPNAndNPN",
3367 config: Config{
3368 NextProtos: []string{"foo", "bar", "baz"},
3369 Bugs: ProtocolBugs{
3370 NegotiateALPNAndNPN: true,
3371 },
3372 },
3373 flags: []string{
3374 "-advertise-alpn", "\x03foo",
3375 "-select-next-proto", "foo",
3376 },
3377 shouldFail: true,
3378 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3379 })
3380 testCases = append(testCases, testCase{
3381 name: "NegotiateALPNAndNPN-Swapped",
3382 config: Config{
3383 NextProtos: []string{"foo", "bar", "baz"},
3384 Bugs: ProtocolBugs{
3385 NegotiateALPNAndNPN: true,
3386 SwapNPNAndALPN: true,
3387 },
3388 },
3389 flags: []string{
3390 "-advertise-alpn", "\x03foo",
3391 "-select-next-proto", "foo",
3392 },
3393 shouldFail: true,
3394 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3395 })
David Benjamin091c4b92015-10-26 13:33:21 -04003396 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3397 testCases = append(testCases, testCase{
3398 name: "DisableNPN",
3399 config: Config{
3400 NextProtos: []string{"foo"},
3401 },
3402 flags: []string{
3403 "-select-next-proto", "foo",
3404 "-disable-npn",
3405 },
3406 expectNoNextProto: true,
3407 })
Adam Langley38311732014-10-16 19:04:35 -07003408 // Resume with a corrupt ticket.
3409 testCases = append(testCases, testCase{
3410 testType: serverTest,
3411 name: "CorruptTicket",
3412 config: Config{
3413 Bugs: ProtocolBugs{
3414 CorruptTicket: true,
3415 },
3416 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003417 resumeSession: true,
3418 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003419 })
David Benjamind98452d2015-06-16 14:16:23 -04003420 // Test the ticket callback, with and without renewal.
3421 testCases = append(testCases, testCase{
3422 testType: serverTest,
3423 name: "TicketCallback",
3424 resumeSession: true,
3425 flags: []string{"-use-ticket-callback"},
3426 })
3427 testCases = append(testCases, testCase{
3428 testType: serverTest,
3429 name: "TicketCallback-Renew",
3430 config: Config{
3431 Bugs: ProtocolBugs{
3432 ExpectNewTicket: true,
3433 },
3434 },
3435 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3436 resumeSession: true,
3437 })
Adam Langley38311732014-10-16 19:04:35 -07003438 // Resume with an oversized session id.
3439 testCases = append(testCases, testCase{
3440 testType: serverTest,
3441 name: "OversizedSessionId",
3442 config: Config{
3443 Bugs: ProtocolBugs{
3444 OversizedSessionId: true,
3445 },
3446 },
3447 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003448 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003449 expectedError: ":DECODE_ERROR:",
3450 })
David Benjaminca6c8262014-11-15 19:06:08 -05003451 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3452 // are ignored.
3453 testCases = append(testCases, testCase{
3454 protocol: dtls,
3455 name: "SRTP-Client",
3456 config: Config{
3457 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3458 },
3459 flags: []string{
3460 "-srtp-profiles",
3461 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3462 },
3463 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3464 })
3465 testCases = append(testCases, testCase{
3466 protocol: dtls,
3467 testType: serverTest,
3468 name: "SRTP-Server",
3469 config: Config{
3470 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3471 },
3472 flags: []string{
3473 "-srtp-profiles",
3474 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3475 },
3476 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3477 })
3478 // Test that the MKI is ignored.
3479 testCases = append(testCases, testCase{
3480 protocol: dtls,
3481 testType: serverTest,
3482 name: "SRTP-Server-IgnoreMKI",
3483 config: Config{
3484 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3485 Bugs: ProtocolBugs{
3486 SRTPMasterKeyIdentifer: "bogus",
3487 },
3488 },
3489 flags: []string{
3490 "-srtp-profiles",
3491 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3492 },
3493 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3494 })
3495 // Test that SRTP isn't negotiated on the server if there were
3496 // no matching profiles.
3497 testCases = append(testCases, testCase{
3498 protocol: dtls,
3499 testType: serverTest,
3500 name: "SRTP-Server-NoMatch",
3501 config: Config{
3502 SRTPProtectionProfiles: []uint16{100, 101, 102},
3503 },
3504 flags: []string{
3505 "-srtp-profiles",
3506 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3507 },
3508 expectedSRTPProtectionProfile: 0,
3509 })
3510 // Test that the server returning an invalid SRTP profile is
3511 // flagged as an error by the client.
3512 testCases = append(testCases, testCase{
3513 protocol: dtls,
3514 name: "SRTP-Client-NoMatch",
3515 config: Config{
3516 Bugs: ProtocolBugs{
3517 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3518 },
3519 },
3520 flags: []string{
3521 "-srtp-profiles",
3522 "SRTP_AES128_CM_SHA1_80",
3523 },
3524 shouldFail: true,
3525 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3526 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003527 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003528 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003529 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003530 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003531 flags: []string{
3532 "-enable-signed-cert-timestamps",
3533 "-expect-signed-cert-timestamps",
3534 base64.StdEncoding.EncodeToString(testSCTList),
3535 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003536 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003537 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003538 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003539 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003540 testType: serverTest,
3541 flags: []string{
3542 "-signed-cert-timestamps",
3543 base64.StdEncoding.EncodeToString(testSCTList),
3544 },
3545 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003546 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003547 })
3548 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003549 testType: clientTest,
3550 name: "ClientHelloPadding",
3551 config: Config{
3552 Bugs: ProtocolBugs{
3553 RequireClientHelloSize: 512,
3554 },
3555 },
3556 // This hostname just needs to be long enough to push the
3557 // ClientHello into F5's danger zone between 256 and 511 bytes
3558 // long.
3559 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3560 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003561
3562 // Extensions should not function in SSL 3.0.
3563 testCases = append(testCases, testCase{
3564 testType: serverTest,
3565 name: "SSLv3Extensions-NoALPN",
3566 config: Config{
3567 MaxVersion: VersionSSL30,
3568 NextProtos: []string{"foo", "bar", "baz"},
3569 },
3570 flags: []string{
3571 "-select-alpn", "foo",
3572 },
3573 expectNoNextProto: true,
3574 })
3575
3576 // Test session tickets separately as they follow a different codepath.
3577 testCases = append(testCases, testCase{
3578 testType: serverTest,
3579 name: "SSLv3Extensions-NoTickets",
3580 config: Config{
3581 MaxVersion: VersionSSL30,
3582 Bugs: ProtocolBugs{
3583 // Historically, session tickets in SSL 3.0
3584 // failed in different ways depending on whether
3585 // the client supported renegotiation_info.
3586 NoRenegotiationInfo: true,
3587 },
3588 },
3589 resumeSession: true,
3590 })
3591 testCases = append(testCases, testCase{
3592 testType: serverTest,
3593 name: "SSLv3Extensions-NoTickets2",
3594 config: Config{
3595 MaxVersion: VersionSSL30,
3596 },
3597 resumeSession: true,
3598 })
3599
3600 // But SSL 3.0 does send and process renegotiation_info.
3601 testCases = append(testCases, testCase{
3602 testType: serverTest,
3603 name: "SSLv3Extensions-RenegotiationInfo",
3604 config: Config{
3605 MaxVersion: VersionSSL30,
3606 Bugs: ProtocolBugs{
3607 RequireRenegotiationInfo: true,
3608 },
3609 },
3610 })
3611 testCases = append(testCases, testCase{
3612 testType: serverTest,
3613 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3614 config: Config{
3615 MaxVersion: VersionSSL30,
3616 Bugs: ProtocolBugs{
3617 NoRenegotiationInfo: true,
3618 SendRenegotiationSCSV: true,
3619 RequireRenegotiationInfo: true,
3620 },
3621 },
3622 })
David Benjamine78bfde2014-09-06 12:45:15 -04003623}
3624
David Benjamin01fe8202014-09-24 15:21:44 -04003625func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003626 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003627 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003628 protocols := []protocol{tls}
3629 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3630 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003631 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003632 for _, protocol := range protocols {
3633 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3634 if protocol == dtls {
3635 suffix += "-DTLS"
3636 }
3637
David Benjaminece3de92015-03-16 18:02:20 -04003638 if sessionVers.version == resumeVers.version {
3639 testCases = append(testCases, testCase{
3640 protocol: protocol,
3641 name: "Resume-Client" + suffix,
3642 resumeSession: true,
3643 config: Config{
3644 MaxVersion: sessionVers.version,
3645 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003646 },
David Benjaminece3de92015-03-16 18:02:20 -04003647 expectedVersion: sessionVers.version,
3648 expectedResumeVersion: resumeVers.version,
3649 })
3650 } else {
3651 testCases = append(testCases, testCase{
3652 protocol: protocol,
3653 name: "Resume-Client-Mismatch" + suffix,
3654 resumeSession: true,
3655 config: Config{
3656 MaxVersion: sessionVers.version,
3657 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003658 },
David Benjaminece3de92015-03-16 18:02:20 -04003659 expectedVersion: sessionVers.version,
3660 resumeConfig: &Config{
3661 MaxVersion: resumeVers.version,
3662 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3663 Bugs: ProtocolBugs{
3664 AllowSessionVersionMismatch: true,
3665 },
3666 },
3667 expectedResumeVersion: resumeVers.version,
3668 shouldFail: true,
3669 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3670 })
3671 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003672
3673 testCases = append(testCases, testCase{
3674 protocol: protocol,
3675 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003676 resumeSession: true,
3677 config: Config{
3678 MaxVersion: sessionVers.version,
3679 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3680 },
3681 expectedVersion: sessionVers.version,
3682 resumeConfig: &Config{
3683 MaxVersion: resumeVers.version,
3684 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3685 },
3686 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003687 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003688 expectedResumeVersion: resumeVers.version,
3689 })
3690
David Benjamin8b8c0062014-11-23 02:47:52 -05003691 testCases = append(testCases, testCase{
3692 protocol: protocol,
3693 testType: serverTest,
3694 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003695 resumeSession: true,
3696 config: Config{
3697 MaxVersion: sessionVers.version,
3698 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3699 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003700 expectedVersion: sessionVers.version,
3701 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003702 resumeConfig: &Config{
3703 MaxVersion: resumeVers.version,
3704 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3705 },
3706 expectedResumeVersion: resumeVers.version,
3707 })
3708 }
David Benjamin01fe8202014-09-24 15:21:44 -04003709 }
3710 }
David Benjaminece3de92015-03-16 18:02:20 -04003711
3712 testCases = append(testCases, testCase{
3713 name: "Resume-Client-CipherMismatch",
3714 resumeSession: true,
3715 config: Config{
3716 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3717 },
3718 resumeConfig: &Config{
3719 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3720 Bugs: ProtocolBugs{
3721 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3722 },
3723 },
3724 shouldFail: true,
3725 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3726 })
David Benjamin01fe8202014-09-24 15:21:44 -04003727}
3728
Adam Langley2ae77d22014-10-28 17:29:33 -07003729func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003730 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003731 testCases = append(testCases, testCase{
3732 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003733 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003734 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003735 shouldFail: true,
3736 expectedError: ":NO_RENEGOTIATION:",
3737 expectedLocalError: "remote error: no renegotiation",
3738 })
Adam Langley5021b222015-06-12 18:27:58 -07003739 // The server shouldn't echo the renegotiation extension unless
3740 // requested by the client.
3741 testCases = append(testCases, testCase{
3742 testType: serverTest,
3743 name: "Renegotiate-Server-NoExt",
3744 config: Config{
3745 Bugs: ProtocolBugs{
3746 NoRenegotiationInfo: true,
3747 RequireRenegotiationInfo: true,
3748 },
3749 },
3750 shouldFail: true,
3751 expectedLocalError: "renegotiation extension missing",
3752 })
3753 // The renegotiation SCSV should be sufficient for the server to echo
3754 // the extension.
3755 testCases = append(testCases, testCase{
3756 testType: serverTest,
3757 name: "Renegotiate-Server-NoExt-SCSV",
3758 config: Config{
3759 Bugs: ProtocolBugs{
3760 NoRenegotiationInfo: true,
3761 SendRenegotiationSCSV: true,
3762 RequireRenegotiationInfo: true,
3763 },
3764 },
3765 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003766 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003767 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003768 config: Config{
3769 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003770 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003771 },
3772 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003773 renegotiate: 1,
3774 flags: []string{
3775 "-renegotiate-freely",
3776 "-expect-total-renegotiations", "1",
3777 },
David Benjamincdea40c2015-03-19 14:09:43 -04003778 })
3779 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003780 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003781 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003782 config: Config{
3783 Bugs: ProtocolBugs{
3784 EmptyRenegotiationInfo: true,
3785 },
3786 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003787 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003788 shouldFail: true,
3789 expectedError: ":RENEGOTIATION_MISMATCH:",
3790 })
3791 testCases = append(testCases, testCase{
3792 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003793 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003794 config: Config{
3795 Bugs: ProtocolBugs{
3796 BadRenegotiationInfo: true,
3797 },
3798 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003799 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003800 shouldFail: true,
3801 expectedError: ":RENEGOTIATION_MISMATCH:",
3802 })
3803 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003804 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003805 config: Config{
3806 Bugs: ProtocolBugs{
3807 NoRenegotiationInfo: true,
3808 },
3809 },
3810 shouldFail: true,
3811 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3812 flags: []string{"-no-legacy-server-connect"},
3813 })
3814 testCases = append(testCases, testCase{
3815 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003816 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003817 config: Config{
3818 Bugs: ProtocolBugs{
3819 NoRenegotiationInfo: true,
3820 },
3821 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003822 flags: []string{
3823 "-renegotiate-freely",
3824 "-expect-total-renegotiations", "1",
3825 },
David Benjamincff0b902015-05-15 23:09:47 -04003826 })
3827 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003828 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003829 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003830 config: Config{
3831 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3832 },
3833 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003834 flags: []string{
3835 "-renegotiate-freely",
3836 "-expect-total-renegotiations", "1",
3837 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003838 })
3839 testCases = append(testCases, testCase{
3840 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003841 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003842 config: Config{
3843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3844 },
3845 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003846 flags: []string{
3847 "-renegotiate-freely",
3848 "-expect-total-renegotiations", "1",
3849 },
David Benjaminb16346b2015-04-08 19:16:58 -04003850 })
3851 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003852 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003853 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003854 config: Config{
3855 MaxVersion: VersionTLS10,
3856 Bugs: ProtocolBugs{
3857 RequireSameRenegoClientVersion: true,
3858 },
3859 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003860 flags: []string{
3861 "-renegotiate-freely",
3862 "-expect-total-renegotiations", "1",
3863 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003864 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003865 testCases = append(testCases, testCase{
3866 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003867 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003868 config: Config{
3869 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3870 NextProtos: []string{"foo"},
3871 },
3872 flags: []string{
3873 "-false-start",
3874 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003875 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003876 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003877 },
3878 shimWritesFirst: true,
3879 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003880
3881 // Client-side renegotiation controls.
3882 testCases = append(testCases, testCase{
3883 name: "Renegotiate-Client-Forbidden-1",
3884 renegotiate: 1,
3885 shouldFail: true,
3886 expectedError: ":NO_RENEGOTIATION:",
3887 expectedLocalError: "remote error: no renegotiation",
3888 })
3889 testCases = append(testCases, testCase{
3890 name: "Renegotiate-Client-Once-1",
3891 renegotiate: 1,
3892 flags: []string{
3893 "-renegotiate-once",
3894 "-expect-total-renegotiations", "1",
3895 },
3896 })
3897 testCases = append(testCases, testCase{
3898 name: "Renegotiate-Client-Freely-1",
3899 renegotiate: 1,
3900 flags: []string{
3901 "-renegotiate-freely",
3902 "-expect-total-renegotiations", "1",
3903 },
3904 })
3905 testCases = append(testCases, testCase{
3906 name: "Renegotiate-Client-Once-2",
3907 renegotiate: 2,
3908 flags: []string{"-renegotiate-once"},
3909 shouldFail: true,
3910 expectedError: ":NO_RENEGOTIATION:",
3911 expectedLocalError: "remote error: no renegotiation",
3912 })
3913 testCases = append(testCases, testCase{
3914 name: "Renegotiate-Client-Freely-2",
3915 renegotiate: 2,
3916 flags: []string{
3917 "-renegotiate-freely",
3918 "-expect-total-renegotiations", "2",
3919 },
3920 })
Adam Langley27a0d082015-11-03 13:34:10 -08003921 testCases = append(testCases, testCase{
3922 name: "Renegotiate-Client-NoIgnore",
3923 config: Config{
3924 Bugs: ProtocolBugs{
3925 SendHelloRequestBeforeEveryAppDataRecord: true,
3926 },
3927 },
3928 shouldFail: true,
3929 expectedError: ":NO_RENEGOTIATION:",
3930 })
3931 testCases = append(testCases, testCase{
3932 name: "Renegotiate-Client-Ignore",
3933 config: Config{
3934 Bugs: ProtocolBugs{
3935 SendHelloRequestBeforeEveryAppDataRecord: true,
3936 },
3937 },
3938 flags: []string{
3939 "-renegotiate-ignore",
3940 "-expect-total-renegotiations", "0",
3941 },
3942 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003943}
3944
David Benjamin5e961c12014-11-07 01:48:35 -05003945func addDTLSReplayTests() {
3946 // Test that sequence number replays are detected.
3947 testCases = append(testCases, testCase{
3948 protocol: dtls,
3949 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003950 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003951 replayWrites: true,
3952 })
3953
David Benjamin8e6db492015-07-25 18:29:23 -04003954 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003955 // than the retransmit window.
3956 testCases = append(testCases, testCase{
3957 protocol: dtls,
3958 name: "DTLS-Replay-LargeGaps",
3959 config: Config{
3960 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003961 SequenceNumberMapping: func(in uint64) uint64 {
3962 return in * 127
3963 },
David Benjamin5e961c12014-11-07 01:48:35 -05003964 },
3965 },
David Benjamin8e6db492015-07-25 18:29:23 -04003966 messageCount: 200,
3967 replayWrites: true,
3968 })
3969
3970 // Test the incoming sequence number changing non-monotonically.
3971 testCases = append(testCases, testCase{
3972 protocol: dtls,
3973 name: "DTLS-Replay-NonMonotonic",
3974 config: Config{
3975 Bugs: ProtocolBugs{
3976 SequenceNumberMapping: func(in uint64) uint64 {
3977 return in ^ 31
3978 },
3979 },
3980 },
3981 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003982 replayWrites: true,
3983 })
3984}
3985
David Benjamin000800a2014-11-14 01:43:59 -05003986var testHashes = []struct {
3987 name string
3988 id uint8
3989}{
3990 {"SHA1", hashSHA1},
3991 {"SHA224", hashSHA224},
3992 {"SHA256", hashSHA256},
3993 {"SHA384", hashSHA384},
3994 {"SHA512", hashSHA512},
3995}
3996
3997func addSigningHashTests() {
3998 // Make sure each hash works. Include some fake hashes in the list and
3999 // ensure they're ignored.
4000 for _, hash := range testHashes {
4001 testCases = append(testCases, testCase{
4002 name: "SigningHash-ClientAuth-" + hash.name,
4003 config: Config{
4004 ClientAuth: RequireAnyClientCert,
4005 SignatureAndHashes: []signatureAndHash{
4006 {signatureRSA, 42},
4007 {signatureRSA, hash.id},
4008 {signatureRSA, 255},
4009 },
4010 },
4011 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004012 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4013 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004014 },
4015 })
4016
4017 testCases = append(testCases, testCase{
4018 testType: serverTest,
4019 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4020 config: Config{
4021 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4022 SignatureAndHashes: []signatureAndHash{
4023 {signatureRSA, 42},
4024 {signatureRSA, hash.id},
4025 {signatureRSA, 255},
4026 },
4027 },
4028 })
4029 }
4030
4031 // Test that hash resolution takes the signature type into account.
4032 testCases = append(testCases, testCase{
4033 name: "SigningHash-ClientAuth-SignatureType",
4034 config: Config{
4035 ClientAuth: RequireAnyClientCert,
4036 SignatureAndHashes: []signatureAndHash{
4037 {signatureECDSA, hashSHA512},
4038 {signatureRSA, hashSHA384},
4039 {signatureECDSA, hashSHA1},
4040 },
4041 },
4042 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004043 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4044 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004045 },
4046 })
4047
4048 testCases = append(testCases, testCase{
4049 testType: serverTest,
4050 name: "SigningHash-ServerKeyExchange-SignatureType",
4051 config: Config{
4052 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4053 SignatureAndHashes: []signatureAndHash{
4054 {signatureECDSA, hashSHA512},
4055 {signatureRSA, hashSHA384},
4056 {signatureECDSA, hashSHA1},
4057 },
4058 },
4059 })
4060
4061 // Test that, if the list is missing, the peer falls back to SHA-1.
4062 testCases = append(testCases, testCase{
4063 name: "SigningHash-ClientAuth-Fallback",
4064 config: Config{
4065 ClientAuth: RequireAnyClientCert,
4066 SignatureAndHashes: []signatureAndHash{
4067 {signatureRSA, hashSHA1},
4068 },
4069 Bugs: ProtocolBugs{
4070 NoSignatureAndHashes: true,
4071 },
4072 },
4073 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004074 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4075 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004076 },
4077 })
4078
4079 testCases = append(testCases, testCase{
4080 testType: serverTest,
4081 name: "SigningHash-ServerKeyExchange-Fallback",
4082 config: Config{
4083 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4084 SignatureAndHashes: []signatureAndHash{
4085 {signatureRSA, hashSHA1},
4086 },
4087 Bugs: ProtocolBugs{
4088 NoSignatureAndHashes: true,
4089 },
4090 },
4091 })
David Benjamin72dc7832015-03-16 17:49:43 -04004092
4093 // Test that hash preferences are enforced. BoringSSL defaults to
4094 // rejecting MD5 signatures.
4095 testCases = append(testCases, testCase{
4096 testType: serverTest,
4097 name: "SigningHash-ClientAuth-Enforced",
4098 config: Config{
4099 Certificates: []Certificate{rsaCertificate},
4100 SignatureAndHashes: []signatureAndHash{
4101 {signatureRSA, hashMD5},
4102 // Advertise SHA-1 so the handshake will
4103 // proceed, but the shim's preferences will be
4104 // ignored in CertificateVerify generation, so
4105 // MD5 will be chosen.
4106 {signatureRSA, hashSHA1},
4107 },
4108 Bugs: ProtocolBugs{
4109 IgnorePeerSignatureAlgorithmPreferences: true,
4110 },
4111 },
4112 flags: []string{"-require-any-client-certificate"},
4113 shouldFail: true,
4114 expectedError: ":WRONG_SIGNATURE_TYPE:",
4115 })
4116
4117 testCases = append(testCases, testCase{
4118 name: "SigningHash-ServerKeyExchange-Enforced",
4119 config: Config{
4120 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4121 SignatureAndHashes: []signatureAndHash{
4122 {signatureRSA, hashMD5},
4123 },
4124 Bugs: ProtocolBugs{
4125 IgnorePeerSignatureAlgorithmPreferences: true,
4126 },
4127 },
4128 shouldFail: true,
4129 expectedError: ":WRONG_SIGNATURE_TYPE:",
4130 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004131
4132 // Test that the agreed upon digest respects the client preferences and
4133 // the server digests.
4134 testCases = append(testCases, testCase{
4135 name: "Agree-Digest-Fallback",
4136 config: Config{
4137 ClientAuth: RequireAnyClientCert,
4138 SignatureAndHashes: []signatureAndHash{
4139 {signatureRSA, hashSHA512},
4140 {signatureRSA, hashSHA1},
4141 },
4142 },
4143 flags: []string{
4144 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4145 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4146 },
4147 digestPrefs: "SHA256",
4148 expectedClientCertSignatureHash: hashSHA1,
4149 })
4150 testCases = append(testCases, testCase{
4151 name: "Agree-Digest-SHA256",
4152 config: Config{
4153 ClientAuth: RequireAnyClientCert,
4154 SignatureAndHashes: []signatureAndHash{
4155 {signatureRSA, hashSHA1},
4156 {signatureRSA, hashSHA256},
4157 },
4158 },
4159 flags: []string{
4160 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4161 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4162 },
4163 digestPrefs: "SHA256,SHA1",
4164 expectedClientCertSignatureHash: hashSHA256,
4165 })
4166 testCases = append(testCases, testCase{
4167 name: "Agree-Digest-SHA1",
4168 config: Config{
4169 ClientAuth: RequireAnyClientCert,
4170 SignatureAndHashes: []signatureAndHash{
4171 {signatureRSA, hashSHA1},
4172 },
4173 },
4174 flags: []string{
4175 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4176 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4177 },
4178 digestPrefs: "SHA512,SHA256,SHA1",
4179 expectedClientCertSignatureHash: hashSHA1,
4180 })
4181 testCases = append(testCases, testCase{
4182 name: "Agree-Digest-Default",
4183 config: Config{
4184 ClientAuth: RequireAnyClientCert,
4185 SignatureAndHashes: []signatureAndHash{
4186 {signatureRSA, hashSHA256},
4187 {signatureECDSA, hashSHA256},
4188 {signatureRSA, hashSHA1},
4189 {signatureECDSA, hashSHA1},
4190 },
4191 },
4192 flags: []string{
4193 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4194 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4195 },
4196 expectedClientCertSignatureHash: hashSHA256,
4197 })
David Benjamin000800a2014-11-14 01:43:59 -05004198}
4199
David Benjamin83f90402015-01-27 01:09:43 -05004200// timeouts is the retransmit schedule for BoringSSL. It doubles and
4201// caps at 60 seconds. On the 13th timeout, it gives up.
4202var timeouts = []time.Duration{
4203 1 * time.Second,
4204 2 * time.Second,
4205 4 * time.Second,
4206 8 * time.Second,
4207 16 * time.Second,
4208 32 * time.Second,
4209 60 * time.Second,
4210 60 * time.Second,
4211 60 * time.Second,
4212 60 * time.Second,
4213 60 * time.Second,
4214 60 * time.Second,
4215 60 * time.Second,
4216}
4217
4218func addDTLSRetransmitTests() {
4219 // Test that this is indeed the timeout schedule. Stress all
4220 // four patterns of handshake.
4221 for i := 1; i < len(timeouts); i++ {
4222 number := strconv.Itoa(i)
4223 testCases = append(testCases, testCase{
4224 protocol: dtls,
4225 name: "DTLS-Retransmit-Client-" + number,
4226 config: Config{
4227 Bugs: ProtocolBugs{
4228 TimeoutSchedule: timeouts[:i],
4229 },
4230 },
4231 resumeSession: true,
4232 flags: []string{"-async"},
4233 })
4234 testCases = append(testCases, testCase{
4235 protocol: dtls,
4236 testType: serverTest,
4237 name: "DTLS-Retransmit-Server-" + number,
4238 config: Config{
4239 Bugs: ProtocolBugs{
4240 TimeoutSchedule: timeouts[:i],
4241 },
4242 },
4243 resumeSession: true,
4244 flags: []string{"-async"},
4245 })
4246 }
4247
4248 // Test that exceeding the timeout schedule hits a read
4249 // timeout.
4250 testCases = append(testCases, testCase{
4251 protocol: dtls,
4252 name: "DTLS-Retransmit-Timeout",
4253 config: Config{
4254 Bugs: ProtocolBugs{
4255 TimeoutSchedule: timeouts,
4256 },
4257 },
4258 resumeSession: true,
4259 flags: []string{"-async"},
4260 shouldFail: true,
4261 expectedError: ":READ_TIMEOUT_EXPIRED:",
4262 })
4263
4264 // Test that timeout handling has a fudge factor, due to API
4265 // problems.
4266 testCases = append(testCases, testCase{
4267 protocol: dtls,
4268 name: "DTLS-Retransmit-Fudge",
4269 config: Config{
4270 Bugs: ProtocolBugs{
4271 TimeoutSchedule: []time.Duration{
4272 timeouts[0] - 10*time.Millisecond,
4273 },
4274 },
4275 },
4276 resumeSession: true,
4277 flags: []string{"-async"},
4278 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004279
4280 // Test that the final Finished retransmitting isn't
4281 // duplicated if the peer badly fragments everything.
4282 testCases = append(testCases, testCase{
4283 testType: serverTest,
4284 protocol: dtls,
4285 name: "DTLS-Retransmit-Fragmented",
4286 config: Config{
4287 Bugs: ProtocolBugs{
4288 TimeoutSchedule: []time.Duration{timeouts[0]},
4289 MaxHandshakeRecordLength: 2,
4290 },
4291 },
4292 flags: []string{"-async"},
4293 })
David Benjamin83f90402015-01-27 01:09:43 -05004294}
4295
David Benjaminc565ebb2015-04-03 04:06:36 -04004296func addExportKeyingMaterialTests() {
4297 for _, vers := range tlsVersions {
4298 if vers.version == VersionSSL30 {
4299 continue
4300 }
4301 testCases = append(testCases, testCase{
4302 name: "ExportKeyingMaterial-" + vers.name,
4303 config: Config{
4304 MaxVersion: vers.version,
4305 },
4306 exportKeyingMaterial: 1024,
4307 exportLabel: "label",
4308 exportContext: "context",
4309 useExportContext: true,
4310 })
4311 testCases = append(testCases, testCase{
4312 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4313 config: Config{
4314 MaxVersion: vers.version,
4315 },
4316 exportKeyingMaterial: 1024,
4317 })
4318 testCases = append(testCases, testCase{
4319 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4320 config: Config{
4321 MaxVersion: vers.version,
4322 },
4323 exportKeyingMaterial: 1024,
4324 useExportContext: true,
4325 })
4326 testCases = append(testCases, testCase{
4327 name: "ExportKeyingMaterial-Small-" + vers.name,
4328 config: Config{
4329 MaxVersion: vers.version,
4330 },
4331 exportKeyingMaterial: 1,
4332 exportLabel: "label",
4333 exportContext: "context",
4334 useExportContext: true,
4335 })
4336 }
4337 testCases = append(testCases, testCase{
4338 name: "ExportKeyingMaterial-SSL3",
4339 config: Config{
4340 MaxVersion: VersionSSL30,
4341 },
4342 exportKeyingMaterial: 1024,
4343 exportLabel: "label",
4344 exportContext: "context",
4345 useExportContext: true,
4346 shouldFail: true,
4347 expectedError: "failed to export keying material",
4348 })
4349}
4350
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004351func addTLSUniqueTests() {
4352 for _, isClient := range []bool{false, true} {
4353 for _, isResumption := range []bool{false, true} {
4354 for _, hasEMS := range []bool{false, true} {
4355 var suffix string
4356 if isResumption {
4357 suffix = "Resume-"
4358 } else {
4359 suffix = "Full-"
4360 }
4361
4362 if hasEMS {
4363 suffix += "EMS-"
4364 } else {
4365 suffix += "NoEMS-"
4366 }
4367
4368 if isClient {
4369 suffix += "Client"
4370 } else {
4371 suffix += "Server"
4372 }
4373
4374 test := testCase{
4375 name: "TLSUnique-" + suffix,
4376 testTLSUnique: true,
4377 config: Config{
4378 Bugs: ProtocolBugs{
4379 NoExtendedMasterSecret: !hasEMS,
4380 },
4381 },
4382 }
4383
4384 if isResumption {
4385 test.resumeSession = true
4386 test.resumeConfig = &Config{
4387 Bugs: ProtocolBugs{
4388 NoExtendedMasterSecret: !hasEMS,
4389 },
4390 }
4391 }
4392
4393 if isResumption && !hasEMS {
4394 test.shouldFail = true
4395 test.expectedError = "failed to get tls-unique"
4396 }
4397
4398 testCases = append(testCases, test)
4399 }
4400 }
4401 }
4402}
4403
Adam Langley09505632015-07-30 18:10:13 -07004404func addCustomExtensionTests() {
4405 expectedContents := "custom extension"
4406 emptyString := ""
4407
4408 for _, isClient := range []bool{false, true} {
4409 suffix := "Server"
4410 flag := "-enable-server-custom-extension"
4411 testType := serverTest
4412 if isClient {
4413 suffix = "Client"
4414 flag = "-enable-client-custom-extension"
4415 testType = clientTest
4416 }
4417
4418 testCases = append(testCases, testCase{
4419 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004420 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004421 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004422 Bugs: ProtocolBugs{
4423 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004424 ExpectedCustomExtension: &expectedContents,
4425 },
4426 },
4427 flags: []string{flag},
4428 })
4429
4430 // If the parse callback fails, the handshake should also fail.
4431 testCases = append(testCases, testCase{
4432 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004433 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004434 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004435 Bugs: ProtocolBugs{
4436 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004437 ExpectedCustomExtension: &expectedContents,
4438 },
4439 },
David Benjamin399e7c92015-07-30 23:01:27 -04004440 flags: []string{flag},
4441 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004442 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4443 })
4444
4445 // If the add callback fails, the handshake should also fail.
4446 testCases = append(testCases, testCase{
4447 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004448 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004449 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004450 Bugs: ProtocolBugs{
4451 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004452 ExpectedCustomExtension: &expectedContents,
4453 },
4454 },
David Benjamin399e7c92015-07-30 23:01:27 -04004455 flags: []string{flag, "-custom-extension-fail-add"},
4456 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004457 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4458 })
4459
4460 // If the add callback returns zero, no extension should be
4461 // added.
4462 skipCustomExtension := expectedContents
4463 if isClient {
4464 // For the case where the client skips sending the
4465 // custom extension, the server must not “echo” it.
4466 skipCustomExtension = ""
4467 }
4468 testCases = append(testCases, testCase{
4469 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004470 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004471 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004472 Bugs: ProtocolBugs{
4473 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004474 ExpectedCustomExtension: &emptyString,
4475 },
4476 },
4477 flags: []string{flag, "-custom-extension-skip"},
4478 })
4479 }
4480
4481 // The custom extension add callback should not be called if the client
4482 // doesn't send the extension.
4483 testCases = append(testCases, testCase{
4484 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004485 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004486 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004487 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004488 ExpectedCustomExtension: &emptyString,
4489 },
4490 },
4491 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4492 })
Adam Langley2deb9842015-08-07 11:15:37 -07004493
4494 // Test an unknown extension from the server.
4495 testCases = append(testCases, testCase{
4496 testType: clientTest,
4497 name: "UnknownExtension-Client",
4498 config: Config{
4499 Bugs: ProtocolBugs{
4500 CustomExtension: expectedContents,
4501 },
4502 },
4503 shouldFail: true,
4504 expectedError: ":UNEXPECTED_EXTENSION:",
4505 })
Adam Langley09505632015-07-30 18:10:13 -07004506}
4507
Adam Langley7c803a62015-06-15 15:35:05 -07004508func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004509 defer wg.Done()
4510
4511 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004512 var err error
4513
4514 if *mallocTest < 0 {
4515 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004516 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004517 } else {
4518 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4519 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004520 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004521 if err != nil {
4522 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4523 }
4524 break
4525 }
4526 }
4527 }
Adam Langley95c29f32014-06-20 12:00:00 -07004528 statusChan <- statusMsg{test: test, err: err}
4529 }
4530}
4531
4532type statusMsg struct {
4533 test *testCase
4534 started bool
4535 err error
4536}
4537
David Benjamin5f237bc2015-02-11 17:14:15 -05004538func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004539 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004540
David Benjamin5f237bc2015-02-11 17:14:15 -05004541 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004542 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004543 if !*pipe {
4544 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004545 var erase string
4546 for i := 0; i < lineLen; i++ {
4547 erase += "\b \b"
4548 }
4549 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004550 }
4551
Adam Langley95c29f32014-06-20 12:00:00 -07004552 if msg.started {
4553 started++
4554 } else {
4555 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004556
4557 if msg.err != nil {
4558 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4559 failed++
4560 testOutput.addResult(msg.test.name, "FAIL")
4561 } else {
4562 if *pipe {
4563 // Print each test instead of a status line.
4564 fmt.Printf("PASSED (%s)\n", msg.test.name)
4565 }
4566 testOutput.addResult(msg.test.name, "PASS")
4567 }
Adam Langley95c29f32014-06-20 12:00:00 -07004568 }
4569
David Benjamin5f237bc2015-02-11 17:14:15 -05004570 if !*pipe {
4571 // Print a new status line.
4572 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4573 lineLen = len(line)
4574 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004575 }
Adam Langley95c29f32014-06-20 12:00:00 -07004576 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004577
4578 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004579}
4580
4581func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004582 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004583 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004584
Adam Langley7c803a62015-06-15 15:35:05 -07004585 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004586 addCipherSuiteTests()
4587 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004588 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004589 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004590 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004591 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004592 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004593 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004594 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004595 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004596 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004597 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004598 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004599 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004600 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004601 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004602 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004603 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004604 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004605 for _, async := range []bool{false, true} {
4606 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004607 for _, protocol := range []protocol{tls, dtls} {
4608 addStateMachineCoverageTests(async, splitHandshake, protocol)
4609 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004610 }
4611 }
Adam Langley95c29f32014-06-20 12:00:00 -07004612
4613 var wg sync.WaitGroup
4614
Adam Langley7c803a62015-06-15 15:35:05 -07004615 statusChan := make(chan statusMsg, *numWorkers)
4616 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004617 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004618
David Benjamin025b3d32014-07-01 19:53:04 -04004619 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004620
Adam Langley7c803a62015-06-15 15:35:05 -07004621 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004622 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004623 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004624 }
4625
David Benjamin025b3d32014-07-01 19:53:04 -04004626 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004627 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004628 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004629 }
4630 }
4631
4632 close(testChan)
4633 wg.Wait()
4634 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004635 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004636
4637 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004638
4639 if *jsonOutput != "" {
4640 if err := testOutput.writeTo(*jsonOutput); err != nil {
4641 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4642 }
4643 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004644
4645 if !testOutput.allPassed {
4646 os.Exit(1)
4647 }
Adam Langley95c29f32014-06-20 12:00:00 -07004648}