blob: 3c4e2ea112aaf511a563bc040fa15af27d392b83 [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 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002000 {
2001 name: "CheckLeafCurve",
2002 config: Config{
2003 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2004 Certificates: []Certificate{getECDSACertificate()},
2005 },
2006 flags: []string{"-p384-only"},
2007 shouldFail: true,
2008 expectedError: ":BAD_ECC_CERT:",
2009 },
Adam Langley7c803a62015-06-15 15:35:05 -07002010 }
Adam Langley7c803a62015-06-15 15:35:05 -07002011 testCases = append(testCases, basicTests...)
2012}
2013
Adam Langley95c29f32014-06-20 12:00:00 -07002014func addCipherSuiteTests() {
2015 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002016 const psk = "12345"
2017 const pskIdentity = "luggage combo"
2018
Adam Langley95c29f32014-06-20 12:00:00 -07002019 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002020 var certFile string
2021 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002022 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002023 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002024 certFile = ecdsaCertificateFile
2025 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002026 } else {
2027 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002028 certFile = rsaCertificateFile
2029 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002030 }
2031
David Benjamin48cae082014-10-27 01:06:24 -04002032 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002033 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002034 flags = append(flags,
2035 "-psk", psk,
2036 "-psk-identity", pskIdentity)
2037 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002038 if hasComponent(suite.name, "NULL") {
2039 // NULL ciphers must be explicitly enabled.
2040 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2041 }
David Benjamin48cae082014-10-27 01:06:24 -04002042
Adam Langley95c29f32014-06-20 12:00:00 -07002043 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002044 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002045 continue
2046 }
2047
David Benjamin025b3d32014-07-01 19:53:04 -04002048 testCases = append(testCases, testCase{
2049 testType: clientTest,
2050 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002051 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002052 MinVersion: ver.version,
2053 MaxVersion: ver.version,
2054 CipherSuites: []uint16{suite.id},
2055 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002056 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002057 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002058 },
David Benjamin48cae082014-10-27 01:06:24 -04002059 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002060 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002061 })
David Benjamin025b3d32014-07-01 19:53:04 -04002062
David Benjamin76d8abe2014-08-14 16:25:34 -04002063 testCases = append(testCases, testCase{
2064 testType: serverTest,
2065 name: ver.name + "-" + suite.name + "-server",
2066 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002067 MinVersion: ver.version,
2068 MaxVersion: ver.version,
2069 CipherSuites: []uint16{suite.id},
2070 Certificates: []Certificate{cert},
2071 PreSharedKey: []byte(psk),
2072 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002073 },
2074 certFile: certFile,
2075 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002076 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002077 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002078 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002079
David Benjamin8b8c0062014-11-23 02:47:52 -05002080 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002081 testCases = append(testCases, testCase{
2082 testType: clientTest,
2083 protocol: dtls,
2084 name: "D" + ver.name + "-" + suite.name + "-client",
2085 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002086 MinVersion: ver.version,
2087 MaxVersion: ver.version,
2088 CipherSuites: []uint16{suite.id},
2089 Certificates: []Certificate{cert},
2090 PreSharedKey: []byte(psk),
2091 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002092 },
David Benjamin48cae082014-10-27 01:06:24 -04002093 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002094 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002095 })
2096 testCases = append(testCases, testCase{
2097 testType: serverTest,
2098 protocol: dtls,
2099 name: "D" + ver.name + "-" + suite.name + "-server",
2100 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002101 MinVersion: ver.version,
2102 MaxVersion: ver.version,
2103 CipherSuites: []uint16{suite.id},
2104 Certificates: []Certificate{cert},
2105 PreSharedKey: []byte(psk),
2106 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002107 },
2108 certFile: certFile,
2109 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002110 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002111 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002112 })
2113 }
Adam Langley95c29f32014-06-20 12:00:00 -07002114 }
David Benjamin2c99d282015-09-01 10:23:00 -04002115
2116 // Ensure both TLS and DTLS accept their maximum record sizes.
2117 testCases = append(testCases, testCase{
2118 name: suite.name + "-LargeRecord",
2119 config: Config{
2120 CipherSuites: []uint16{suite.id},
2121 Certificates: []Certificate{cert},
2122 PreSharedKey: []byte(psk),
2123 PreSharedKeyIdentity: pskIdentity,
2124 },
2125 flags: flags,
2126 messageLen: maxPlaintext,
2127 })
David Benjamin2c99d282015-09-01 10:23:00 -04002128 if isDTLSCipher(suite.name) {
2129 testCases = append(testCases, testCase{
2130 protocol: dtls,
2131 name: suite.name + "-LargeRecord-DTLS",
2132 config: Config{
2133 CipherSuites: []uint16{suite.id},
2134 Certificates: []Certificate{cert},
2135 PreSharedKey: []byte(psk),
2136 PreSharedKeyIdentity: pskIdentity,
2137 },
2138 flags: flags,
2139 messageLen: maxPlaintext,
2140 })
2141 }
Adam Langley95c29f32014-06-20 12:00:00 -07002142 }
Adam Langleya7997f12015-05-14 17:38:50 -07002143
2144 testCases = append(testCases, testCase{
2145 name: "WeakDH",
2146 config: Config{
2147 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2148 Bugs: ProtocolBugs{
2149 // This is a 1023-bit prime number, generated
2150 // with:
2151 // openssl gendh 1023 | openssl asn1parse -i
2152 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2153 },
2154 },
2155 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002156 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002157 })
Adam Langleycef75832015-09-03 14:51:12 -07002158
David Benjamincd24a392015-11-11 13:23:05 -08002159 testCases = append(testCases, testCase{
2160 name: "SillyDH",
2161 config: Config{
2162 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2163 Bugs: ProtocolBugs{
2164 // This is a 4097-bit prime number, generated
2165 // with:
2166 // openssl gendh 4097 | openssl asn1parse -i
2167 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2168 },
2169 },
2170 shouldFail: true,
2171 expectedError: ":DH_P_TOO_LONG:",
2172 })
2173
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002174 // This test ensures that Diffie-Hellman public values are padded with
2175 // zeros so that they're the same length as the prime. This is to avoid
2176 // hitting a bug in yaSSL.
2177 testCases = append(testCases, testCase{
2178 testType: serverTest,
2179 name: "DHPublicValuePadded",
2180 config: Config{
2181 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2182 Bugs: ProtocolBugs{
2183 RequireDHPublicValueLen: (1025 + 7) / 8,
2184 },
2185 },
2186 flags: []string{"-use-sparse-dh-prime"},
2187 })
David Benjamincd24a392015-11-11 13:23:05 -08002188
Adam Langleycef75832015-09-03 14:51:12 -07002189 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2190 // 1.1 specific cipher suite settings. A server is setup with the given
2191 // cipher lists and then a connection is made for each member of
2192 // expectations. The cipher suite that the server selects must match
2193 // the specified one.
2194 var versionSpecificCiphersTest = []struct {
2195 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2196 // expectations is a map from TLS version to cipher suite id.
2197 expectations map[uint16]uint16
2198 }{
2199 {
2200 // Test that the null case (where no version-specific ciphers are set)
2201 // works as expected.
2202 "RC4-SHA:AES128-SHA", // default ciphers
2203 "", // no ciphers specifically for TLS ≥ 1.0
2204 "", // no ciphers specifically 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_RC4_128_SHA,
2209 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2210 },
2211 },
2212 {
2213 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2214 // cipher.
2215 "RC4-SHA:AES128-SHA", // default
2216 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2217 "", // no ciphers specifically 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_128_CBC_SHA,
2222 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2223 },
2224 },
2225 {
2226 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2227 // cipher.
2228 "RC4-SHA:AES128-SHA", // default
2229 "", // no ciphers specifically for TLS ≥ 1.0
2230 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2231 map[uint16]uint16{
2232 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2233 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2234 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2235 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2236 },
2237 },
2238 {
2239 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2240 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2241 "RC4-SHA:AES128-SHA", // default
2242 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2243 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2244 map[uint16]uint16{
2245 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2246 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2247 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2248 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2249 },
2250 },
2251 }
2252
2253 for i, test := range versionSpecificCiphersTest {
2254 for version, expectedCipherSuite := range test.expectations {
2255 flags := []string{"-cipher", test.ciphersDefault}
2256 if len(test.ciphersTLS10) > 0 {
2257 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2258 }
2259 if len(test.ciphersTLS11) > 0 {
2260 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2261 }
2262
2263 testCases = append(testCases, testCase{
2264 testType: serverTest,
2265 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2266 config: Config{
2267 MaxVersion: version,
2268 MinVersion: version,
2269 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2270 },
2271 flags: flags,
2272 expectedCipher: expectedCipherSuite,
2273 })
2274 }
2275 }
Adam Langley95c29f32014-06-20 12:00:00 -07002276}
2277
2278func addBadECDSASignatureTests() {
2279 for badR := BadValue(1); badR < NumBadValues; badR++ {
2280 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002281 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002282 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2283 config: Config{
2284 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2285 Certificates: []Certificate{getECDSACertificate()},
2286 Bugs: ProtocolBugs{
2287 BadECDSAR: badR,
2288 BadECDSAS: badS,
2289 },
2290 },
2291 shouldFail: true,
2292 expectedError: "SIGNATURE",
2293 })
2294 }
2295 }
2296}
2297
Adam Langley80842bd2014-06-20 12:00:00 -07002298func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002299 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002300 name: "MaxCBCPadding",
2301 config: Config{
2302 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2303 Bugs: ProtocolBugs{
2304 MaxPadding: true,
2305 },
2306 },
2307 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2308 })
David Benjamin025b3d32014-07-01 19:53:04 -04002309 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002310 name: "BadCBCPadding",
2311 config: Config{
2312 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2313 Bugs: ProtocolBugs{
2314 PaddingFirstByteBad: true,
2315 },
2316 },
2317 shouldFail: true,
2318 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2319 })
2320 // OpenSSL previously had an issue where the first byte of padding in
2321 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002322 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002323 name: "BadCBCPadding255",
2324 config: Config{
2325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2326 Bugs: ProtocolBugs{
2327 MaxPadding: true,
2328 PaddingFirstByteBadIf255: true,
2329 },
2330 },
2331 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2332 shouldFail: true,
2333 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2334 })
2335}
2336
Kenny Root7fdeaf12014-08-05 15:23:37 -07002337func addCBCSplittingTests() {
2338 testCases = append(testCases, testCase{
2339 name: "CBCRecordSplitting",
2340 config: Config{
2341 MaxVersion: VersionTLS10,
2342 MinVersion: VersionTLS10,
2343 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2344 },
David Benjaminac8302a2015-09-01 17:18:15 -04002345 messageLen: -1, // read until EOF
2346 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002347 flags: []string{
2348 "-async",
2349 "-write-different-record-sizes",
2350 "-cbc-record-splitting",
2351 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002352 })
2353 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002354 name: "CBCRecordSplittingPartialWrite",
2355 config: Config{
2356 MaxVersion: VersionTLS10,
2357 MinVersion: VersionTLS10,
2358 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2359 },
2360 messageLen: -1, // read until EOF
2361 flags: []string{
2362 "-async",
2363 "-write-different-record-sizes",
2364 "-cbc-record-splitting",
2365 "-partial-write",
2366 },
2367 })
2368}
2369
David Benjamin636293b2014-07-08 17:59:18 -04002370func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002371 // Add a dummy cert pool to stress certificate authority parsing.
2372 // TODO(davidben): Add tests that those values parse out correctly.
2373 certPool := x509.NewCertPool()
2374 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2375 if err != nil {
2376 panic(err)
2377 }
2378 certPool.AddCert(cert)
2379
David Benjamin636293b2014-07-08 17:59:18 -04002380 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002381 testCases = append(testCases, testCase{
2382 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002383 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002384 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002385 MinVersion: ver.version,
2386 MaxVersion: ver.version,
2387 ClientAuth: RequireAnyClientCert,
2388 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002389 },
2390 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002391 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2392 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002393 },
2394 })
2395 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002396 testType: serverTest,
2397 name: ver.name + "-Server-ClientAuth-RSA",
2398 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002399 MinVersion: ver.version,
2400 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002401 Certificates: []Certificate{rsaCertificate},
2402 },
2403 flags: []string{"-require-any-client-certificate"},
2404 })
David Benjamine098ec22014-08-27 23:13:20 -04002405 if ver.version != VersionSSL30 {
2406 testCases = append(testCases, testCase{
2407 testType: serverTest,
2408 name: ver.name + "-Server-ClientAuth-ECDSA",
2409 config: Config{
2410 MinVersion: ver.version,
2411 MaxVersion: ver.version,
2412 Certificates: []Certificate{ecdsaCertificate},
2413 },
2414 flags: []string{"-require-any-client-certificate"},
2415 })
2416 testCases = append(testCases, testCase{
2417 testType: clientTest,
2418 name: ver.name + "-Client-ClientAuth-ECDSA",
2419 config: Config{
2420 MinVersion: ver.version,
2421 MaxVersion: ver.version,
2422 ClientAuth: RequireAnyClientCert,
2423 ClientCAs: certPool,
2424 },
2425 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002426 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2427 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002428 },
2429 })
2430 }
David Benjamin636293b2014-07-08 17:59:18 -04002431 }
2432}
2433
Adam Langley75712922014-10-10 16:23:43 -07002434func addExtendedMasterSecretTests() {
2435 const expectEMSFlag = "-expect-extended-master-secret"
2436
2437 for _, with := range []bool{false, true} {
2438 prefix := "No"
2439 var flags []string
2440 if with {
2441 prefix = ""
2442 flags = []string{expectEMSFlag}
2443 }
2444
2445 for _, isClient := range []bool{false, true} {
2446 suffix := "-Server"
2447 testType := serverTest
2448 if isClient {
2449 suffix = "-Client"
2450 testType = clientTest
2451 }
2452
2453 for _, ver := range tlsVersions {
2454 test := testCase{
2455 testType: testType,
2456 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2457 config: Config{
2458 MinVersion: ver.version,
2459 MaxVersion: ver.version,
2460 Bugs: ProtocolBugs{
2461 NoExtendedMasterSecret: !with,
2462 RequireExtendedMasterSecret: with,
2463 },
2464 },
David Benjamin48cae082014-10-27 01:06:24 -04002465 flags: flags,
2466 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002467 }
2468 if test.shouldFail {
2469 test.expectedLocalError = "extended master secret required but not supported by peer"
2470 }
2471 testCases = append(testCases, test)
2472 }
2473 }
2474 }
2475
Adam Langleyba5934b2015-06-02 10:50:35 -07002476 for _, isClient := range []bool{false, true} {
2477 for _, supportedInFirstConnection := range []bool{false, true} {
2478 for _, supportedInResumeConnection := range []bool{false, true} {
2479 boolToWord := func(b bool) string {
2480 if b {
2481 return "Yes"
2482 }
2483 return "No"
2484 }
2485 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2486 if isClient {
2487 suffix += "Client"
2488 } else {
2489 suffix += "Server"
2490 }
2491
2492 supportedConfig := Config{
2493 Bugs: ProtocolBugs{
2494 RequireExtendedMasterSecret: true,
2495 },
2496 }
2497
2498 noSupportConfig := Config{
2499 Bugs: ProtocolBugs{
2500 NoExtendedMasterSecret: true,
2501 },
2502 }
2503
2504 test := testCase{
2505 name: "ExtendedMasterSecret-" + suffix,
2506 resumeSession: true,
2507 }
2508
2509 if !isClient {
2510 test.testType = serverTest
2511 }
2512
2513 if supportedInFirstConnection {
2514 test.config = supportedConfig
2515 } else {
2516 test.config = noSupportConfig
2517 }
2518
2519 if supportedInResumeConnection {
2520 test.resumeConfig = &supportedConfig
2521 } else {
2522 test.resumeConfig = &noSupportConfig
2523 }
2524
2525 switch suffix {
2526 case "YesToYes-Client", "YesToYes-Server":
2527 // When a session is resumed, it should
2528 // still be aware that its master
2529 // secret was generated via EMS and
2530 // thus it's safe to use tls-unique.
2531 test.flags = []string{expectEMSFlag}
2532 case "NoToYes-Server":
2533 // If an original connection did not
2534 // contain EMS, but a resumption
2535 // handshake does, then a server should
2536 // not resume the session.
2537 test.expectResumeRejected = true
2538 case "YesToNo-Server":
2539 // Resuming an EMS session without the
2540 // EMS extension should cause the
2541 // server to abort the connection.
2542 test.shouldFail = true
2543 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2544 case "NoToYes-Client":
2545 // A client should abort a connection
2546 // where the server resumed a non-EMS
2547 // session but echoed the EMS
2548 // extension.
2549 test.shouldFail = true
2550 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2551 case "YesToNo-Client":
2552 // A client should abort a connection
2553 // where the server didn't echo EMS
2554 // when the session used it.
2555 test.shouldFail = true
2556 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2557 }
2558
2559 testCases = append(testCases, test)
2560 }
2561 }
2562 }
Adam Langley75712922014-10-10 16:23:43 -07002563}
2564
David Benjamin43ec06f2014-08-05 02:28:57 -04002565// Adds tests that try to cover the range of the handshake state machine, under
2566// various conditions. Some of these are redundant with other tests, but they
2567// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002568func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002569 var tests []testCase
2570
2571 // Basic handshake, with resumption. Client and server,
2572 // session ID and session ticket.
2573 tests = append(tests, testCase{
2574 name: "Basic-Client",
2575 resumeSession: true,
2576 })
2577 tests = append(tests, testCase{
2578 name: "Basic-Client-RenewTicket",
2579 config: Config{
2580 Bugs: ProtocolBugs{
2581 RenewTicketOnResume: true,
2582 },
2583 },
David Benjaminba4594a2015-06-18 18:36:15 -04002584 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002585 resumeSession: true,
2586 })
2587 tests = append(tests, testCase{
2588 name: "Basic-Client-NoTicket",
2589 config: Config{
2590 SessionTicketsDisabled: true,
2591 },
2592 resumeSession: true,
2593 })
2594 tests = append(tests, testCase{
2595 name: "Basic-Client-Implicit",
2596 flags: []string{"-implicit-handshake"},
2597 resumeSession: true,
2598 })
2599 tests = append(tests, testCase{
2600 testType: serverTest,
2601 name: "Basic-Server",
2602 resumeSession: true,
2603 })
2604 tests = append(tests, testCase{
2605 testType: serverTest,
2606 name: "Basic-Server-NoTickets",
2607 config: Config{
2608 SessionTicketsDisabled: true,
2609 },
2610 resumeSession: true,
2611 })
2612 tests = append(tests, testCase{
2613 testType: serverTest,
2614 name: "Basic-Server-Implicit",
2615 flags: []string{"-implicit-handshake"},
2616 resumeSession: true,
2617 })
2618 tests = append(tests, testCase{
2619 testType: serverTest,
2620 name: "Basic-Server-EarlyCallback",
2621 flags: []string{"-use-early-callback"},
2622 resumeSession: true,
2623 })
2624
2625 // TLS client auth.
2626 tests = append(tests, testCase{
2627 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002628 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002629 config: Config{
2630 ClientAuth: RequireAnyClientCert,
2631 },
2632 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002633 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2634 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002635 },
2636 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002637 tests = append(tests, testCase{
2638 testType: clientTest,
2639 name: "ClientAuth-ECDSA-Client",
2640 config: Config{
2641 ClientAuth: RequireAnyClientCert,
2642 },
2643 flags: []string{
2644 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2645 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2646 },
2647 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002648 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002649 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002650 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002651 testType: serverTest,
2652 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002653 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002654 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002655 },
2656 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002657 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2658 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002659 },
2660 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002661 tests = append(tests, testCase{
2662 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002663 name: "Basic-Server-ECDHE-RSA",
2664 config: Config{
2665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2666 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002667 flags: []string{
2668 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2669 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002670 },
2671 })
2672 tests = append(tests, testCase{
2673 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002674 name: "Basic-Server-ECDHE-ECDSA",
2675 config: Config{
2676 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2677 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002678 flags: []string{
2679 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2680 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002681 },
2682 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002683 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002684 tests = append(tests, testCase{
2685 testType: serverTest,
2686 name: "ClientAuth-Server",
2687 config: Config{
2688 Certificates: []Certificate{rsaCertificate},
2689 },
2690 flags: []string{"-require-any-client-certificate"},
2691 })
2692
2693 // No session ticket support; server doesn't send NewSessionTicket.
2694 tests = append(tests, testCase{
2695 name: "SessionTicketsDisabled-Client",
2696 config: Config{
2697 SessionTicketsDisabled: true,
2698 },
2699 })
2700 tests = append(tests, testCase{
2701 testType: serverTest,
2702 name: "SessionTicketsDisabled-Server",
2703 config: Config{
2704 SessionTicketsDisabled: true,
2705 },
2706 })
2707
2708 // Skip ServerKeyExchange in PSK key exchange if there's no
2709 // identity hint.
2710 tests = append(tests, testCase{
2711 name: "EmptyPSKHint-Client",
2712 config: Config{
2713 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2714 PreSharedKey: []byte("secret"),
2715 },
2716 flags: []string{"-psk", "secret"},
2717 })
2718 tests = append(tests, testCase{
2719 testType: serverTest,
2720 name: "EmptyPSKHint-Server",
2721 config: Config{
2722 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2723 PreSharedKey: []byte("secret"),
2724 },
2725 flags: []string{"-psk", "secret"},
2726 })
2727
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002728 tests = append(tests, testCase{
2729 testType: clientTest,
2730 name: "OCSPStapling-Client",
2731 flags: []string{
2732 "-enable-ocsp-stapling",
2733 "-expect-ocsp-response",
2734 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002735 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002736 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002737 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002738 })
2739
2740 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002741 testType: serverTest,
2742 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002743 expectedOCSPResponse: testOCSPResponse,
2744 flags: []string{
2745 "-ocsp-response",
2746 base64.StdEncoding.EncodeToString(testOCSPResponse),
2747 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002748 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002749 })
2750
Paul Lietar8f1c2682015-08-18 12:21:54 +01002751 tests = append(tests, testCase{
2752 testType: clientTest,
2753 name: "CertificateVerificationSucceed",
2754 flags: []string{
2755 "-verify-peer",
2756 },
2757 })
2758
2759 tests = append(tests, testCase{
2760 testType: clientTest,
2761 name: "CertificateVerificationFail",
2762 flags: []string{
2763 "-verify-fail",
2764 "-verify-peer",
2765 },
2766 shouldFail: true,
2767 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2768 })
2769
2770 tests = append(tests, testCase{
2771 testType: clientTest,
2772 name: "CertificateVerificationSoftFail",
2773 flags: []string{
2774 "-verify-fail",
2775 "-expect-verify-result",
2776 },
2777 })
2778
David Benjamin760b1dd2015-05-15 23:33:48 -04002779 if protocol == tls {
2780 tests = append(tests, testCase{
2781 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002782 renegotiate: 1,
2783 flags: []string{
2784 "-renegotiate-freely",
2785 "-expect-total-renegotiations", "1",
2786 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002787 })
2788 // NPN on client and server; results in post-handshake message.
2789 tests = append(tests, testCase{
2790 name: "NPN-Client",
2791 config: Config{
2792 NextProtos: []string{"foo"},
2793 },
2794 flags: []string{"-select-next-proto", "foo"},
2795 expectedNextProto: "foo",
2796 expectedNextProtoType: npn,
2797 })
2798 tests = append(tests, testCase{
2799 testType: serverTest,
2800 name: "NPN-Server",
2801 config: Config{
2802 NextProtos: []string{"bar"},
2803 },
2804 flags: []string{
2805 "-advertise-npn", "\x03foo\x03bar\x03baz",
2806 "-expect-next-proto", "bar",
2807 },
2808 expectedNextProto: "bar",
2809 expectedNextProtoType: npn,
2810 })
2811
2812 // TODO(davidben): Add tests for when False Start doesn't trigger.
2813
2814 // Client does False Start and negotiates NPN.
2815 tests = append(tests, testCase{
2816 name: "FalseStart",
2817 config: Config{
2818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2819 NextProtos: []string{"foo"},
2820 Bugs: ProtocolBugs{
2821 ExpectFalseStart: true,
2822 },
2823 },
2824 flags: []string{
2825 "-false-start",
2826 "-select-next-proto", "foo",
2827 },
2828 shimWritesFirst: true,
2829 resumeSession: true,
2830 })
2831
2832 // Client does False Start and negotiates ALPN.
2833 tests = append(tests, testCase{
2834 name: "FalseStart-ALPN",
2835 config: Config{
2836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2837 NextProtos: []string{"foo"},
2838 Bugs: ProtocolBugs{
2839 ExpectFalseStart: true,
2840 },
2841 },
2842 flags: []string{
2843 "-false-start",
2844 "-advertise-alpn", "\x03foo",
2845 },
2846 shimWritesFirst: true,
2847 resumeSession: true,
2848 })
2849
2850 // Client does False Start but doesn't explicitly call
2851 // SSL_connect.
2852 tests = append(tests, testCase{
2853 name: "FalseStart-Implicit",
2854 config: Config{
2855 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2856 NextProtos: []string{"foo"},
2857 },
2858 flags: []string{
2859 "-implicit-handshake",
2860 "-false-start",
2861 "-advertise-alpn", "\x03foo",
2862 },
2863 })
2864
2865 // False Start without session tickets.
2866 tests = append(tests, testCase{
2867 name: "FalseStart-SessionTicketsDisabled",
2868 config: Config{
2869 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2870 NextProtos: []string{"foo"},
2871 SessionTicketsDisabled: true,
2872 Bugs: ProtocolBugs{
2873 ExpectFalseStart: true,
2874 },
2875 },
2876 flags: []string{
2877 "-false-start",
2878 "-select-next-proto", "foo",
2879 },
2880 shimWritesFirst: true,
2881 })
2882
2883 // Server parses a V2ClientHello.
2884 tests = append(tests, testCase{
2885 testType: serverTest,
2886 name: "SendV2ClientHello",
2887 config: Config{
2888 // Choose a cipher suite that does not involve
2889 // elliptic curves, so no extensions are
2890 // involved.
2891 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2892 Bugs: ProtocolBugs{
2893 SendV2ClientHello: true,
2894 },
2895 },
2896 })
2897
2898 // Client sends a Channel ID.
2899 tests = append(tests, testCase{
2900 name: "ChannelID-Client",
2901 config: Config{
2902 RequestChannelID: true,
2903 },
Adam Langley7c803a62015-06-15 15:35:05 -07002904 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002905 resumeSession: true,
2906 expectChannelID: true,
2907 })
2908
2909 // Server accepts a Channel ID.
2910 tests = append(tests, testCase{
2911 testType: serverTest,
2912 name: "ChannelID-Server",
2913 config: Config{
2914 ChannelID: channelIDKey,
2915 },
2916 flags: []string{
2917 "-expect-channel-id",
2918 base64.StdEncoding.EncodeToString(channelIDBytes),
2919 },
2920 resumeSession: true,
2921 expectChannelID: true,
2922 })
David Benjamin30789da2015-08-29 22:56:45 -04002923
2924 // Bidirectional shutdown with the runner initiating.
2925 tests = append(tests, testCase{
2926 name: "Shutdown-Runner",
2927 config: Config{
2928 Bugs: ProtocolBugs{
2929 ExpectCloseNotify: true,
2930 },
2931 },
2932 flags: []string{"-check-close-notify"},
2933 })
2934
2935 // Bidirectional shutdown with the shim initiating. The runner,
2936 // in the meantime, sends garbage before the close_notify which
2937 // the shim must ignore.
2938 tests = append(tests, testCase{
2939 name: "Shutdown-Shim",
2940 config: Config{
2941 Bugs: ProtocolBugs{
2942 ExpectCloseNotify: true,
2943 },
2944 },
2945 shimShutsDown: true,
2946 sendEmptyRecords: 1,
2947 sendWarningAlerts: 1,
2948 flags: []string{"-check-close-notify"},
2949 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002950 } else {
2951 tests = append(tests, testCase{
2952 name: "SkipHelloVerifyRequest",
2953 config: Config{
2954 Bugs: ProtocolBugs{
2955 SkipHelloVerifyRequest: true,
2956 },
2957 },
2958 })
2959 }
2960
David Benjamin760b1dd2015-05-15 23:33:48 -04002961 for _, test := range tests {
2962 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05002963 if protocol == dtls {
2964 test.name += "-DTLS"
2965 }
2966 if async {
2967 test.name += "-Async"
2968 test.flags = append(test.flags, "-async")
2969 } else {
2970 test.name += "-Sync"
2971 }
2972 if splitHandshake {
2973 test.name += "-SplitHandshakeRecords"
2974 test.config.Bugs.MaxHandshakeRecordLength = 1
2975 if protocol == dtls {
2976 test.config.Bugs.MaxPacketLength = 256
2977 test.flags = append(test.flags, "-mtu", "256")
2978 }
2979 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002980 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002981 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002982}
2983
Adam Langley524e7172015-02-20 16:04:00 -08002984func addDDoSCallbackTests() {
2985 // DDoS callback.
2986
2987 for _, resume := range []bool{false, true} {
2988 suffix := "Resume"
2989 if resume {
2990 suffix = "No" + suffix
2991 }
2992
2993 testCases = append(testCases, testCase{
2994 testType: serverTest,
2995 name: "Server-DDoS-OK-" + suffix,
2996 flags: []string{"-install-ddos-callback"},
2997 resumeSession: resume,
2998 })
2999
3000 failFlag := "-fail-ddos-callback"
3001 if resume {
3002 failFlag = "-fail-second-ddos-callback"
3003 }
3004 testCases = append(testCases, testCase{
3005 testType: serverTest,
3006 name: "Server-DDoS-Reject-" + suffix,
3007 flags: []string{"-install-ddos-callback", failFlag},
3008 resumeSession: resume,
3009 shouldFail: true,
3010 expectedError: ":CONNECTION_REJECTED:",
3011 })
3012 }
3013}
3014
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003015func addVersionNegotiationTests() {
3016 for i, shimVers := range tlsVersions {
3017 // Assemble flags to disable all newer versions on the shim.
3018 var flags []string
3019 for _, vers := range tlsVersions[i+1:] {
3020 flags = append(flags, vers.flag)
3021 }
3022
3023 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003024 protocols := []protocol{tls}
3025 if runnerVers.hasDTLS && shimVers.hasDTLS {
3026 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003027 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003028 for _, protocol := range protocols {
3029 expectedVersion := shimVers.version
3030 if runnerVers.version < shimVers.version {
3031 expectedVersion = runnerVers.version
3032 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003033
David Benjamin8b8c0062014-11-23 02:47:52 -05003034 suffix := shimVers.name + "-" + runnerVers.name
3035 if protocol == dtls {
3036 suffix += "-DTLS"
3037 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003038
David Benjamin1eb367c2014-12-12 18:17:51 -05003039 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3040
David Benjamin1e29a6b2014-12-10 02:27:24 -05003041 clientVers := shimVers.version
3042 if clientVers > VersionTLS10 {
3043 clientVers = VersionTLS10
3044 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003045 testCases = append(testCases, testCase{
3046 protocol: protocol,
3047 testType: clientTest,
3048 name: "VersionNegotiation-Client-" + suffix,
3049 config: Config{
3050 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003051 Bugs: ProtocolBugs{
3052 ExpectInitialRecordVersion: clientVers,
3053 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003054 },
3055 flags: flags,
3056 expectedVersion: expectedVersion,
3057 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003058 testCases = append(testCases, testCase{
3059 protocol: protocol,
3060 testType: clientTest,
3061 name: "VersionNegotiation-Client2-" + suffix,
3062 config: Config{
3063 MaxVersion: runnerVers.version,
3064 Bugs: ProtocolBugs{
3065 ExpectInitialRecordVersion: clientVers,
3066 },
3067 },
3068 flags: []string{"-max-version", shimVersFlag},
3069 expectedVersion: expectedVersion,
3070 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003071
3072 testCases = append(testCases, testCase{
3073 protocol: protocol,
3074 testType: serverTest,
3075 name: "VersionNegotiation-Server-" + suffix,
3076 config: Config{
3077 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003078 Bugs: ProtocolBugs{
3079 ExpectInitialRecordVersion: expectedVersion,
3080 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003081 },
3082 flags: flags,
3083 expectedVersion: expectedVersion,
3084 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003085 testCases = append(testCases, testCase{
3086 protocol: protocol,
3087 testType: serverTest,
3088 name: "VersionNegotiation-Server2-" + suffix,
3089 config: Config{
3090 MaxVersion: runnerVers.version,
3091 Bugs: ProtocolBugs{
3092 ExpectInitialRecordVersion: expectedVersion,
3093 },
3094 },
3095 flags: []string{"-max-version", shimVersFlag},
3096 expectedVersion: expectedVersion,
3097 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003098 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003099 }
3100 }
3101}
3102
David Benjaminaccb4542014-12-12 23:44:33 -05003103func addMinimumVersionTests() {
3104 for i, shimVers := range tlsVersions {
3105 // Assemble flags to disable all older versions on the shim.
3106 var flags []string
3107 for _, vers := range tlsVersions[:i] {
3108 flags = append(flags, vers.flag)
3109 }
3110
3111 for _, runnerVers := range tlsVersions {
3112 protocols := []protocol{tls}
3113 if runnerVers.hasDTLS && shimVers.hasDTLS {
3114 protocols = append(protocols, dtls)
3115 }
3116 for _, protocol := range protocols {
3117 suffix := shimVers.name + "-" + runnerVers.name
3118 if protocol == dtls {
3119 suffix += "-DTLS"
3120 }
3121 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3122
David Benjaminaccb4542014-12-12 23:44:33 -05003123 var expectedVersion uint16
3124 var shouldFail bool
3125 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003126 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003127 if runnerVers.version >= shimVers.version {
3128 expectedVersion = runnerVers.version
3129 } else {
3130 shouldFail = true
3131 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003132 if runnerVers.version > VersionSSL30 {
3133 expectedLocalError = "remote error: protocol version not supported"
3134 } else {
3135 expectedLocalError = "remote error: handshake failure"
3136 }
David Benjaminaccb4542014-12-12 23:44:33 -05003137 }
3138
3139 testCases = append(testCases, testCase{
3140 protocol: protocol,
3141 testType: clientTest,
3142 name: "MinimumVersion-Client-" + suffix,
3143 config: Config{
3144 MaxVersion: runnerVers.version,
3145 },
David Benjamin87909c02014-12-13 01:55:01 -05003146 flags: flags,
3147 expectedVersion: expectedVersion,
3148 shouldFail: shouldFail,
3149 expectedError: expectedError,
3150 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003151 })
3152 testCases = append(testCases, testCase{
3153 protocol: protocol,
3154 testType: clientTest,
3155 name: "MinimumVersion-Client2-" + suffix,
3156 config: Config{
3157 MaxVersion: runnerVers.version,
3158 },
David Benjamin87909c02014-12-13 01:55:01 -05003159 flags: []string{"-min-version", shimVersFlag},
3160 expectedVersion: expectedVersion,
3161 shouldFail: shouldFail,
3162 expectedError: expectedError,
3163 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003164 })
3165
3166 testCases = append(testCases, testCase{
3167 protocol: protocol,
3168 testType: serverTest,
3169 name: "MinimumVersion-Server-" + suffix,
3170 config: Config{
3171 MaxVersion: runnerVers.version,
3172 },
David Benjamin87909c02014-12-13 01:55:01 -05003173 flags: flags,
3174 expectedVersion: expectedVersion,
3175 shouldFail: shouldFail,
3176 expectedError: expectedError,
3177 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003178 })
3179 testCases = append(testCases, testCase{
3180 protocol: protocol,
3181 testType: serverTest,
3182 name: "MinimumVersion-Server2-" + suffix,
3183 config: Config{
3184 MaxVersion: runnerVers.version,
3185 },
David Benjamin87909c02014-12-13 01:55:01 -05003186 flags: []string{"-min-version", shimVersFlag},
3187 expectedVersion: expectedVersion,
3188 shouldFail: shouldFail,
3189 expectedError: expectedError,
3190 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003191 })
3192 }
3193 }
3194 }
3195}
3196
David Benjamine78bfde2014-09-06 12:45:15 -04003197func addExtensionTests() {
3198 testCases = append(testCases, testCase{
3199 testType: clientTest,
3200 name: "DuplicateExtensionClient",
3201 config: Config{
3202 Bugs: ProtocolBugs{
3203 DuplicateExtension: true,
3204 },
3205 },
3206 shouldFail: true,
3207 expectedLocalError: "remote error: error decoding message",
3208 })
3209 testCases = append(testCases, testCase{
3210 testType: serverTest,
3211 name: "DuplicateExtensionServer",
3212 config: Config{
3213 Bugs: ProtocolBugs{
3214 DuplicateExtension: true,
3215 },
3216 },
3217 shouldFail: true,
3218 expectedLocalError: "remote error: error decoding message",
3219 })
3220 testCases = append(testCases, testCase{
3221 testType: clientTest,
3222 name: "ServerNameExtensionClient",
3223 config: Config{
3224 Bugs: ProtocolBugs{
3225 ExpectServerName: "example.com",
3226 },
3227 },
3228 flags: []string{"-host-name", "example.com"},
3229 })
3230 testCases = append(testCases, testCase{
3231 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003232 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003233 config: Config{
3234 Bugs: ProtocolBugs{
3235 ExpectServerName: "mismatch.com",
3236 },
3237 },
3238 flags: []string{"-host-name", "example.com"},
3239 shouldFail: true,
3240 expectedLocalError: "tls: unexpected server name",
3241 })
3242 testCases = append(testCases, testCase{
3243 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003244 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003245 config: Config{
3246 Bugs: ProtocolBugs{
3247 ExpectServerName: "missing.com",
3248 },
3249 },
3250 shouldFail: true,
3251 expectedLocalError: "tls: unexpected server name",
3252 })
3253 testCases = append(testCases, testCase{
3254 testType: serverTest,
3255 name: "ServerNameExtensionServer",
3256 config: Config{
3257 ServerName: "example.com",
3258 },
3259 flags: []string{"-expect-server-name", "example.com"},
3260 resumeSession: true,
3261 })
David Benjaminae2888f2014-09-06 12:58:58 -04003262 testCases = append(testCases, testCase{
3263 testType: clientTest,
3264 name: "ALPNClient",
3265 config: Config{
3266 NextProtos: []string{"foo"},
3267 },
3268 flags: []string{
3269 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3270 "-expect-alpn", "foo",
3271 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003272 expectedNextProto: "foo",
3273 expectedNextProtoType: alpn,
3274 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003275 })
3276 testCases = append(testCases, testCase{
3277 testType: serverTest,
3278 name: "ALPNServer",
3279 config: Config{
3280 NextProtos: []string{"foo", "bar", "baz"},
3281 },
3282 flags: []string{
3283 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3284 "-select-alpn", "foo",
3285 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003286 expectedNextProto: "foo",
3287 expectedNextProtoType: alpn,
3288 resumeSession: true,
3289 })
3290 // Test that the server prefers ALPN over NPN.
3291 testCases = append(testCases, testCase{
3292 testType: serverTest,
3293 name: "ALPNServer-Preferred",
3294 config: Config{
3295 NextProtos: []string{"foo", "bar", "baz"},
3296 },
3297 flags: []string{
3298 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3299 "-select-alpn", "foo",
3300 "-advertise-npn", "\x03foo\x03bar\x03baz",
3301 },
3302 expectedNextProto: "foo",
3303 expectedNextProtoType: alpn,
3304 resumeSession: true,
3305 })
3306 testCases = append(testCases, testCase{
3307 testType: serverTest,
3308 name: "ALPNServer-Preferred-Swapped",
3309 config: Config{
3310 NextProtos: []string{"foo", "bar", "baz"},
3311 Bugs: ProtocolBugs{
3312 SwapNPNAndALPN: true,
3313 },
3314 },
3315 flags: []string{
3316 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3317 "-select-alpn", "foo",
3318 "-advertise-npn", "\x03foo\x03bar\x03baz",
3319 },
3320 expectedNextProto: "foo",
3321 expectedNextProtoType: alpn,
3322 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003323 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003324 var emptyString string
3325 testCases = append(testCases, testCase{
3326 testType: clientTest,
3327 name: "ALPNClient-EmptyProtocolName",
3328 config: Config{
3329 NextProtos: []string{""},
3330 Bugs: ProtocolBugs{
3331 // A server returning an empty ALPN protocol
3332 // should be rejected.
3333 ALPNProtocol: &emptyString,
3334 },
3335 },
3336 flags: []string{
3337 "-advertise-alpn", "\x03foo",
3338 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003339 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003340 expectedError: ":PARSE_TLSEXT:",
3341 })
3342 testCases = append(testCases, testCase{
3343 testType: serverTest,
3344 name: "ALPNServer-EmptyProtocolName",
3345 config: Config{
3346 // A ClientHello containing an empty ALPN protocol
3347 // should be rejected.
3348 NextProtos: []string{"foo", "", "baz"},
3349 },
3350 flags: []string{
3351 "-select-alpn", "foo",
3352 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003353 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003354 expectedError: ":PARSE_TLSEXT:",
3355 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003356 // Test that negotiating both NPN and ALPN is forbidden.
3357 testCases = append(testCases, testCase{
3358 name: "NegotiateALPNAndNPN",
3359 config: Config{
3360 NextProtos: []string{"foo", "bar", "baz"},
3361 Bugs: ProtocolBugs{
3362 NegotiateALPNAndNPN: true,
3363 },
3364 },
3365 flags: []string{
3366 "-advertise-alpn", "\x03foo",
3367 "-select-next-proto", "foo",
3368 },
3369 shouldFail: true,
3370 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3371 })
3372 testCases = append(testCases, testCase{
3373 name: "NegotiateALPNAndNPN-Swapped",
3374 config: Config{
3375 NextProtos: []string{"foo", "bar", "baz"},
3376 Bugs: ProtocolBugs{
3377 NegotiateALPNAndNPN: true,
3378 SwapNPNAndALPN: true,
3379 },
3380 },
3381 flags: []string{
3382 "-advertise-alpn", "\x03foo",
3383 "-select-next-proto", "foo",
3384 },
3385 shouldFail: true,
3386 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3387 })
David Benjamin091c4b92015-10-26 13:33:21 -04003388 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3389 testCases = append(testCases, testCase{
3390 name: "DisableNPN",
3391 config: Config{
3392 NextProtos: []string{"foo"},
3393 },
3394 flags: []string{
3395 "-select-next-proto", "foo",
3396 "-disable-npn",
3397 },
3398 expectNoNextProto: true,
3399 })
Adam Langley38311732014-10-16 19:04:35 -07003400 // Resume with a corrupt ticket.
3401 testCases = append(testCases, testCase{
3402 testType: serverTest,
3403 name: "CorruptTicket",
3404 config: Config{
3405 Bugs: ProtocolBugs{
3406 CorruptTicket: true,
3407 },
3408 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003409 resumeSession: true,
3410 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003411 })
David Benjamind98452d2015-06-16 14:16:23 -04003412 // Test the ticket callback, with and without renewal.
3413 testCases = append(testCases, testCase{
3414 testType: serverTest,
3415 name: "TicketCallback",
3416 resumeSession: true,
3417 flags: []string{"-use-ticket-callback"},
3418 })
3419 testCases = append(testCases, testCase{
3420 testType: serverTest,
3421 name: "TicketCallback-Renew",
3422 config: Config{
3423 Bugs: ProtocolBugs{
3424 ExpectNewTicket: true,
3425 },
3426 },
3427 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3428 resumeSession: true,
3429 })
Adam Langley38311732014-10-16 19:04:35 -07003430 // Resume with an oversized session id.
3431 testCases = append(testCases, testCase{
3432 testType: serverTest,
3433 name: "OversizedSessionId",
3434 config: Config{
3435 Bugs: ProtocolBugs{
3436 OversizedSessionId: true,
3437 },
3438 },
3439 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003440 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003441 expectedError: ":DECODE_ERROR:",
3442 })
David Benjaminca6c8262014-11-15 19:06:08 -05003443 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3444 // are ignored.
3445 testCases = append(testCases, testCase{
3446 protocol: dtls,
3447 name: "SRTP-Client",
3448 config: Config{
3449 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3450 },
3451 flags: []string{
3452 "-srtp-profiles",
3453 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3454 },
3455 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3456 })
3457 testCases = append(testCases, testCase{
3458 protocol: dtls,
3459 testType: serverTest,
3460 name: "SRTP-Server",
3461 config: Config{
3462 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3463 },
3464 flags: []string{
3465 "-srtp-profiles",
3466 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3467 },
3468 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3469 })
3470 // Test that the MKI is ignored.
3471 testCases = append(testCases, testCase{
3472 protocol: dtls,
3473 testType: serverTest,
3474 name: "SRTP-Server-IgnoreMKI",
3475 config: Config{
3476 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3477 Bugs: ProtocolBugs{
3478 SRTPMasterKeyIdentifer: "bogus",
3479 },
3480 },
3481 flags: []string{
3482 "-srtp-profiles",
3483 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3484 },
3485 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3486 })
3487 // Test that SRTP isn't negotiated on the server if there were
3488 // no matching profiles.
3489 testCases = append(testCases, testCase{
3490 protocol: dtls,
3491 testType: serverTest,
3492 name: "SRTP-Server-NoMatch",
3493 config: Config{
3494 SRTPProtectionProfiles: []uint16{100, 101, 102},
3495 },
3496 flags: []string{
3497 "-srtp-profiles",
3498 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3499 },
3500 expectedSRTPProtectionProfile: 0,
3501 })
3502 // Test that the server returning an invalid SRTP profile is
3503 // flagged as an error by the client.
3504 testCases = append(testCases, testCase{
3505 protocol: dtls,
3506 name: "SRTP-Client-NoMatch",
3507 config: Config{
3508 Bugs: ProtocolBugs{
3509 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3510 },
3511 },
3512 flags: []string{
3513 "-srtp-profiles",
3514 "SRTP_AES128_CM_SHA1_80",
3515 },
3516 shouldFail: true,
3517 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3518 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003519 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003520 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003521 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003522 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003523 flags: []string{
3524 "-enable-signed-cert-timestamps",
3525 "-expect-signed-cert-timestamps",
3526 base64.StdEncoding.EncodeToString(testSCTList),
3527 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003528 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003529 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003530 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003531 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003532 testType: serverTest,
3533 flags: []string{
3534 "-signed-cert-timestamps",
3535 base64.StdEncoding.EncodeToString(testSCTList),
3536 },
3537 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003538 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003539 })
3540 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003541 testType: clientTest,
3542 name: "ClientHelloPadding",
3543 config: Config{
3544 Bugs: ProtocolBugs{
3545 RequireClientHelloSize: 512,
3546 },
3547 },
3548 // This hostname just needs to be long enough to push the
3549 // ClientHello into F5's danger zone between 256 and 511 bytes
3550 // long.
3551 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3552 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003553
3554 // Extensions should not function in SSL 3.0.
3555 testCases = append(testCases, testCase{
3556 testType: serverTest,
3557 name: "SSLv3Extensions-NoALPN",
3558 config: Config{
3559 MaxVersion: VersionSSL30,
3560 NextProtos: []string{"foo", "bar", "baz"},
3561 },
3562 flags: []string{
3563 "-select-alpn", "foo",
3564 },
3565 expectNoNextProto: true,
3566 })
3567
3568 // Test session tickets separately as they follow a different codepath.
3569 testCases = append(testCases, testCase{
3570 testType: serverTest,
3571 name: "SSLv3Extensions-NoTickets",
3572 config: Config{
3573 MaxVersion: VersionSSL30,
3574 Bugs: ProtocolBugs{
3575 // Historically, session tickets in SSL 3.0
3576 // failed in different ways depending on whether
3577 // the client supported renegotiation_info.
3578 NoRenegotiationInfo: true,
3579 },
3580 },
3581 resumeSession: true,
3582 })
3583 testCases = append(testCases, testCase{
3584 testType: serverTest,
3585 name: "SSLv3Extensions-NoTickets2",
3586 config: Config{
3587 MaxVersion: VersionSSL30,
3588 },
3589 resumeSession: true,
3590 })
3591
3592 // But SSL 3.0 does send and process renegotiation_info.
3593 testCases = append(testCases, testCase{
3594 testType: serverTest,
3595 name: "SSLv3Extensions-RenegotiationInfo",
3596 config: Config{
3597 MaxVersion: VersionSSL30,
3598 Bugs: ProtocolBugs{
3599 RequireRenegotiationInfo: true,
3600 },
3601 },
3602 })
3603 testCases = append(testCases, testCase{
3604 testType: serverTest,
3605 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3606 config: Config{
3607 MaxVersion: VersionSSL30,
3608 Bugs: ProtocolBugs{
3609 NoRenegotiationInfo: true,
3610 SendRenegotiationSCSV: true,
3611 RequireRenegotiationInfo: true,
3612 },
3613 },
3614 })
David Benjamine78bfde2014-09-06 12:45:15 -04003615}
3616
David Benjamin01fe8202014-09-24 15:21:44 -04003617func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003618 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003619 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003620 protocols := []protocol{tls}
3621 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3622 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003623 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003624 for _, protocol := range protocols {
3625 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3626 if protocol == dtls {
3627 suffix += "-DTLS"
3628 }
3629
David Benjaminece3de92015-03-16 18:02:20 -04003630 if sessionVers.version == resumeVers.version {
3631 testCases = append(testCases, testCase{
3632 protocol: protocol,
3633 name: "Resume-Client" + suffix,
3634 resumeSession: true,
3635 config: Config{
3636 MaxVersion: sessionVers.version,
3637 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003638 },
David Benjaminece3de92015-03-16 18:02:20 -04003639 expectedVersion: sessionVers.version,
3640 expectedResumeVersion: resumeVers.version,
3641 })
3642 } else {
3643 testCases = append(testCases, testCase{
3644 protocol: protocol,
3645 name: "Resume-Client-Mismatch" + suffix,
3646 resumeSession: true,
3647 config: Config{
3648 MaxVersion: sessionVers.version,
3649 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003650 },
David Benjaminece3de92015-03-16 18:02:20 -04003651 expectedVersion: sessionVers.version,
3652 resumeConfig: &Config{
3653 MaxVersion: resumeVers.version,
3654 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3655 Bugs: ProtocolBugs{
3656 AllowSessionVersionMismatch: true,
3657 },
3658 },
3659 expectedResumeVersion: resumeVers.version,
3660 shouldFail: true,
3661 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3662 })
3663 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003664
3665 testCases = append(testCases, testCase{
3666 protocol: protocol,
3667 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003668 resumeSession: true,
3669 config: Config{
3670 MaxVersion: sessionVers.version,
3671 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3672 },
3673 expectedVersion: sessionVers.version,
3674 resumeConfig: &Config{
3675 MaxVersion: resumeVers.version,
3676 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3677 },
3678 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003679 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003680 expectedResumeVersion: resumeVers.version,
3681 })
3682
David Benjamin8b8c0062014-11-23 02:47:52 -05003683 testCases = append(testCases, testCase{
3684 protocol: protocol,
3685 testType: serverTest,
3686 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003687 resumeSession: true,
3688 config: Config{
3689 MaxVersion: sessionVers.version,
3690 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3691 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003692 expectedVersion: sessionVers.version,
3693 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003694 resumeConfig: &Config{
3695 MaxVersion: resumeVers.version,
3696 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3697 },
3698 expectedResumeVersion: resumeVers.version,
3699 })
3700 }
David Benjamin01fe8202014-09-24 15:21:44 -04003701 }
3702 }
David Benjaminece3de92015-03-16 18:02:20 -04003703
3704 testCases = append(testCases, testCase{
3705 name: "Resume-Client-CipherMismatch",
3706 resumeSession: true,
3707 config: Config{
3708 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3709 },
3710 resumeConfig: &Config{
3711 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3712 Bugs: ProtocolBugs{
3713 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3714 },
3715 },
3716 shouldFail: true,
3717 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3718 })
David Benjamin01fe8202014-09-24 15:21:44 -04003719}
3720
Adam Langley2ae77d22014-10-28 17:29:33 -07003721func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003722 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003723 testCases = append(testCases, testCase{
3724 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003725 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003726 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003727 shouldFail: true,
3728 expectedError: ":NO_RENEGOTIATION:",
3729 expectedLocalError: "remote error: no renegotiation",
3730 })
Adam Langley5021b222015-06-12 18:27:58 -07003731 // The server shouldn't echo the renegotiation extension unless
3732 // requested by the client.
3733 testCases = append(testCases, testCase{
3734 testType: serverTest,
3735 name: "Renegotiate-Server-NoExt",
3736 config: Config{
3737 Bugs: ProtocolBugs{
3738 NoRenegotiationInfo: true,
3739 RequireRenegotiationInfo: true,
3740 },
3741 },
3742 shouldFail: true,
3743 expectedLocalError: "renegotiation extension missing",
3744 })
3745 // The renegotiation SCSV should be sufficient for the server to echo
3746 // the extension.
3747 testCases = append(testCases, testCase{
3748 testType: serverTest,
3749 name: "Renegotiate-Server-NoExt-SCSV",
3750 config: Config{
3751 Bugs: ProtocolBugs{
3752 NoRenegotiationInfo: true,
3753 SendRenegotiationSCSV: true,
3754 RequireRenegotiationInfo: true,
3755 },
3756 },
3757 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003758 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003759 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003760 config: Config{
3761 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003762 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003763 },
3764 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003765 renegotiate: 1,
3766 flags: []string{
3767 "-renegotiate-freely",
3768 "-expect-total-renegotiations", "1",
3769 },
David Benjamincdea40c2015-03-19 14:09:43 -04003770 })
3771 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003772 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003773 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003774 config: Config{
3775 Bugs: ProtocolBugs{
3776 EmptyRenegotiationInfo: true,
3777 },
3778 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003779 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003780 shouldFail: true,
3781 expectedError: ":RENEGOTIATION_MISMATCH:",
3782 })
3783 testCases = append(testCases, testCase{
3784 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003785 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003786 config: Config{
3787 Bugs: ProtocolBugs{
3788 BadRenegotiationInfo: true,
3789 },
3790 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003791 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003792 shouldFail: true,
3793 expectedError: ":RENEGOTIATION_MISMATCH:",
3794 })
3795 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003796 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003797 config: Config{
3798 Bugs: ProtocolBugs{
3799 NoRenegotiationInfo: true,
3800 },
3801 },
3802 shouldFail: true,
3803 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3804 flags: []string{"-no-legacy-server-connect"},
3805 })
3806 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05003807 name: "Renegotiate-Client-Downgrade",
3808 renegotiate: 1,
3809 config: Config{
3810 Bugs: ProtocolBugs{
3811 NoRenegotiationInfoAfterInitial: true,
3812 },
3813 },
3814 flags: []string{"-renegotiate-freely"},
3815 shouldFail: true,
3816 expectedError: ":RENEGOTIATION_MISMATCH:",
3817 })
3818 testCases = append(testCases, testCase{
3819 name: "Renegotiate-Client-Upgrade",
3820 renegotiate: 1,
3821 config: Config{
3822 Bugs: ProtocolBugs{
3823 NoRenegotiationInfoInInitial: true,
3824 },
3825 },
3826 flags: []string{"-renegotiate-freely"},
3827 shouldFail: true,
3828 expectedError: ":RENEGOTIATION_MISMATCH:",
3829 })
3830 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04003831 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003832 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003833 config: Config{
3834 Bugs: ProtocolBugs{
3835 NoRenegotiationInfo: true,
3836 },
3837 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003838 flags: []string{
3839 "-renegotiate-freely",
3840 "-expect-total-renegotiations", "1",
3841 },
David Benjamincff0b902015-05-15 23:09:47 -04003842 })
3843 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003844 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003845 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003846 config: Config{
3847 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3848 },
3849 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003850 flags: []string{
3851 "-renegotiate-freely",
3852 "-expect-total-renegotiations", "1",
3853 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003854 })
3855 testCases = append(testCases, testCase{
3856 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003857 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003858 config: Config{
3859 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3860 },
3861 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003862 flags: []string{
3863 "-renegotiate-freely",
3864 "-expect-total-renegotiations", "1",
3865 },
David Benjaminb16346b2015-04-08 19:16:58 -04003866 })
3867 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003868 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003869 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003870 config: Config{
3871 MaxVersion: VersionTLS10,
3872 Bugs: ProtocolBugs{
3873 RequireSameRenegoClientVersion: true,
3874 },
3875 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003876 flags: []string{
3877 "-renegotiate-freely",
3878 "-expect-total-renegotiations", "1",
3879 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003880 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003881 testCases = append(testCases, testCase{
3882 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003883 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003884 config: Config{
3885 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3886 NextProtos: []string{"foo"},
3887 },
3888 flags: []string{
3889 "-false-start",
3890 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003891 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003892 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003893 },
3894 shimWritesFirst: true,
3895 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003896
3897 // Client-side renegotiation controls.
3898 testCases = append(testCases, testCase{
3899 name: "Renegotiate-Client-Forbidden-1",
3900 renegotiate: 1,
3901 shouldFail: true,
3902 expectedError: ":NO_RENEGOTIATION:",
3903 expectedLocalError: "remote error: no renegotiation",
3904 })
3905 testCases = append(testCases, testCase{
3906 name: "Renegotiate-Client-Once-1",
3907 renegotiate: 1,
3908 flags: []string{
3909 "-renegotiate-once",
3910 "-expect-total-renegotiations", "1",
3911 },
3912 })
3913 testCases = append(testCases, testCase{
3914 name: "Renegotiate-Client-Freely-1",
3915 renegotiate: 1,
3916 flags: []string{
3917 "-renegotiate-freely",
3918 "-expect-total-renegotiations", "1",
3919 },
3920 })
3921 testCases = append(testCases, testCase{
3922 name: "Renegotiate-Client-Once-2",
3923 renegotiate: 2,
3924 flags: []string{"-renegotiate-once"},
3925 shouldFail: true,
3926 expectedError: ":NO_RENEGOTIATION:",
3927 expectedLocalError: "remote error: no renegotiation",
3928 })
3929 testCases = append(testCases, testCase{
3930 name: "Renegotiate-Client-Freely-2",
3931 renegotiate: 2,
3932 flags: []string{
3933 "-renegotiate-freely",
3934 "-expect-total-renegotiations", "2",
3935 },
3936 })
Adam Langley27a0d082015-11-03 13:34:10 -08003937 testCases = append(testCases, testCase{
3938 name: "Renegotiate-Client-NoIgnore",
3939 config: Config{
3940 Bugs: ProtocolBugs{
3941 SendHelloRequestBeforeEveryAppDataRecord: true,
3942 },
3943 },
3944 shouldFail: true,
3945 expectedError: ":NO_RENEGOTIATION:",
3946 })
3947 testCases = append(testCases, testCase{
3948 name: "Renegotiate-Client-Ignore",
3949 config: Config{
3950 Bugs: ProtocolBugs{
3951 SendHelloRequestBeforeEveryAppDataRecord: true,
3952 },
3953 },
3954 flags: []string{
3955 "-renegotiate-ignore",
3956 "-expect-total-renegotiations", "0",
3957 },
3958 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003959}
3960
David Benjamin5e961c12014-11-07 01:48:35 -05003961func addDTLSReplayTests() {
3962 // Test that sequence number replays are detected.
3963 testCases = append(testCases, testCase{
3964 protocol: dtls,
3965 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003966 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003967 replayWrites: true,
3968 })
3969
David Benjamin8e6db492015-07-25 18:29:23 -04003970 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003971 // than the retransmit window.
3972 testCases = append(testCases, testCase{
3973 protocol: dtls,
3974 name: "DTLS-Replay-LargeGaps",
3975 config: Config{
3976 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003977 SequenceNumberMapping: func(in uint64) uint64 {
3978 return in * 127
3979 },
David Benjamin5e961c12014-11-07 01:48:35 -05003980 },
3981 },
David Benjamin8e6db492015-07-25 18:29:23 -04003982 messageCount: 200,
3983 replayWrites: true,
3984 })
3985
3986 // Test the incoming sequence number changing non-monotonically.
3987 testCases = append(testCases, testCase{
3988 protocol: dtls,
3989 name: "DTLS-Replay-NonMonotonic",
3990 config: Config{
3991 Bugs: ProtocolBugs{
3992 SequenceNumberMapping: func(in uint64) uint64 {
3993 return in ^ 31
3994 },
3995 },
3996 },
3997 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003998 replayWrites: true,
3999 })
4000}
4001
David Benjamin000800a2014-11-14 01:43:59 -05004002var testHashes = []struct {
4003 name string
4004 id uint8
4005}{
4006 {"SHA1", hashSHA1},
4007 {"SHA224", hashSHA224},
4008 {"SHA256", hashSHA256},
4009 {"SHA384", hashSHA384},
4010 {"SHA512", hashSHA512},
4011}
4012
4013func addSigningHashTests() {
4014 // Make sure each hash works. Include some fake hashes in the list and
4015 // ensure they're ignored.
4016 for _, hash := range testHashes {
4017 testCases = append(testCases, testCase{
4018 name: "SigningHash-ClientAuth-" + hash.name,
4019 config: Config{
4020 ClientAuth: RequireAnyClientCert,
4021 SignatureAndHashes: []signatureAndHash{
4022 {signatureRSA, 42},
4023 {signatureRSA, hash.id},
4024 {signatureRSA, 255},
4025 },
4026 },
4027 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004028 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4029 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004030 },
4031 })
4032
4033 testCases = append(testCases, testCase{
4034 testType: serverTest,
4035 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4036 config: Config{
4037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4038 SignatureAndHashes: []signatureAndHash{
4039 {signatureRSA, 42},
4040 {signatureRSA, hash.id},
4041 {signatureRSA, 255},
4042 },
4043 },
4044 })
David Benjamin6e807652015-11-02 12:02:20 -05004045
4046 testCases = append(testCases, testCase{
4047 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4048 config: Config{
4049 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4050 SignatureAndHashes: []signatureAndHash{
4051 {signatureRSA, 42},
4052 {signatureRSA, hash.id},
4053 {signatureRSA, 255},
4054 },
4055 },
4056 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4057 })
David Benjamin000800a2014-11-14 01:43:59 -05004058 }
4059
4060 // Test that hash resolution takes the signature type into account.
4061 testCases = append(testCases, testCase{
4062 name: "SigningHash-ClientAuth-SignatureType",
4063 config: Config{
4064 ClientAuth: RequireAnyClientCert,
4065 SignatureAndHashes: []signatureAndHash{
4066 {signatureECDSA, hashSHA512},
4067 {signatureRSA, hashSHA384},
4068 {signatureECDSA, hashSHA1},
4069 },
4070 },
4071 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004072 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4073 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004074 },
4075 })
4076
4077 testCases = append(testCases, testCase{
4078 testType: serverTest,
4079 name: "SigningHash-ServerKeyExchange-SignatureType",
4080 config: Config{
4081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4082 SignatureAndHashes: []signatureAndHash{
4083 {signatureECDSA, hashSHA512},
4084 {signatureRSA, hashSHA384},
4085 {signatureECDSA, hashSHA1},
4086 },
4087 },
4088 })
4089
4090 // Test that, if the list is missing, the peer falls back to SHA-1.
4091 testCases = append(testCases, testCase{
4092 name: "SigningHash-ClientAuth-Fallback",
4093 config: Config{
4094 ClientAuth: RequireAnyClientCert,
4095 SignatureAndHashes: []signatureAndHash{
4096 {signatureRSA, hashSHA1},
4097 },
4098 Bugs: ProtocolBugs{
4099 NoSignatureAndHashes: true,
4100 },
4101 },
4102 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004103 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4104 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004105 },
4106 })
4107
4108 testCases = append(testCases, testCase{
4109 testType: serverTest,
4110 name: "SigningHash-ServerKeyExchange-Fallback",
4111 config: Config{
4112 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4113 SignatureAndHashes: []signatureAndHash{
4114 {signatureRSA, hashSHA1},
4115 },
4116 Bugs: ProtocolBugs{
4117 NoSignatureAndHashes: true,
4118 },
4119 },
4120 })
David Benjamin72dc7832015-03-16 17:49:43 -04004121
4122 // Test that hash preferences are enforced. BoringSSL defaults to
4123 // rejecting MD5 signatures.
4124 testCases = append(testCases, testCase{
4125 testType: serverTest,
4126 name: "SigningHash-ClientAuth-Enforced",
4127 config: Config{
4128 Certificates: []Certificate{rsaCertificate},
4129 SignatureAndHashes: []signatureAndHash{
4130 {signatureRSA, hashMD5},
4131 // Advertise SHA-1 so the handshake will
4132 // proceed, but the shim's preferences will be
4133 // ignored in CertificateVerify generation, so
4134 // MD5 will be chosen.
4135 {signatureRSA, hashSHA1},
4136 },
4137 Bugs: ProtocolBugs{
4138 IgnorePeerSignatureAlgorithmPreferences: true,
4139 },
4140 },
4141 flags: []string{"-require-any-client-certificate"},
4142 shouldFail: true,
4143 expectedError: ":WRONG_SIGNATURE_TYPE:",
4144 })
4145
4146 testCases = append(testCases, testCase{
4147 name: "SigningHash-ServerKeyExchange-Enforced",
4148 config: Config{
4149 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4150 SignatureAndHashes: []signatureAndHash{
4151 {signatureRSA, hashMD5},
4152 },
4153 Bugs: ProtocolBugs{
4154 IgnorePeerSignatureAlgorithmPreferences: true,
4155 },
4156 },
4157 shouldFail: true,
4158 expectedError: ":WRONG_SIGNATURE_TYPE:",
4159 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004160
4161 // Test that the agreed upon digest respects the client preferences and
4162 // the server digests.
4163 testCases = append(testCases, testCase{
4164 name: "Agree-Digest-Fallback",
4165 config: Config{
4166 ClientAuth: RequireAnyClientCert,
4167 SignatureAndHashes: []signatureAndHash{
4168 {signatureRSA, hashSHA512},
4169 {signatureRSA, hashSHA1},
4170 },
4171 },
4172 flags: []string{
4173 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4174 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4175 },
4176 digestPrefs: "SHA256",
4177 expectedClientCertSignatureHash: hashSHA1,
4178 })
4179 testCases = append(testCases, testCase{
4180 name: "Agree-Digest-SHA256",
4181 config: Config{
4182 ClientAuth: RequireAnyClientCert,
4183 SignatureAndHashes: []signatureAndHash{
4184 {signatureRSA, hashSHA1},
4185 {signatureRSA, hashSHA256},
4186 },
4187 },
4188 flags: []string{
4189 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4190 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4191 },
4192 digestPrefs: "SHA256,SHA1",
4193 expectedClientCertSignatureHash: hashSHA256,
4194 })
4195 testCases = append(testCases, testCase{
4196 name: "Agree-Digest-SHA1",
4197 config: Config{
4198 ClientAuth: RequireAnyClientCert,
4199 SignatureAndHashes: []signatureAndHash{
4200 {signatureRSA, hashSHA1},
4201 },
4202 },
4203 flags: []string{
4204 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4205 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4206 },
4207 digestPrefs: "SHA512,SHA256,SHA1",
4208 expectedClientCertSignatureHash: hashSHA1,
4209 })
4210 testCases = append(testCases, testCase{
4211 name: "Agree-Digest-Default",
4212 config: Config{
4213 ClientAuth: RequireAnyClientCert,
4214 SignatureAndHashes: []signatureAndHash{
4215 {signatureRSA, hashSHA256},
4216 {signatureECDSA, hashSHA256},
4217 {signatureRSA, hashSHA1},
4218 {signatureECDSA, hashSHA1},
4219 },
4220 },
4221 flags: []string{
4222 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4223 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4224 },
4225 expectedClientCertSignatureHash: hashSHA256,
4226 })
David Benjamin000800a2014-11-14 01:43:59 -05004227}
4228
David Benjamin83f90402015-01-27 01:09:43 -05004229// timeouts is the retransmit schedule for BoringSSL. It doubles and
4230// caps at 60 seconds. On the 13th timeout, it gives up.
4231var timeouts = []time.Duration{
4232 1 * time.Second,
4233 2 * time.Second,
4234 4 * time.Second,
4235 8 * time.Second,
4236 16 * time.Second,
4237 32 * time.Second,
4238 60 * time.Second,
4239 60 * time.Second,
4240 60 * time.Second,
4241 60 * time.Second,
4242 60 * time.Second,
4243 60 * time.Second,
4244 60 * time.Second,
4245}
4246
4247func addDTLSRetransmitTests() {
4248 // Test that this is indeed the timeout schedule. Stress all
4249 // four patterns of handshake.
4250 for i := 1; i < len(timeouts); i++ {
4251 number := strconv.Itoa(i)
4252 testCases = append(testCases, testCase{
4253 protocol: dtls,
4254 name: "DTLS-Retransmit-Client-" + number,
4255 config: Config{
4256 Bugs: ProtocolBugs{
4257 TimeoutSchedule: timeouts[:i],
4258 },
4259 },
4260 resumeSession: true,
4261 flags: []string{"-async"},
4262 })
4263 testCases = append(testCases, testCase{
4264 protocol: dtls,
4265 testType: serverTest,
4266 name: "DTLS-Retransmit-Server-" + number,
4267 config: Config{
4268 Bugs: ProtocolBugs{
4269 TimeoutSchedule: timeouts[:i],
4270 },
4271 },
4272 resumeSession: true,
4273 flags: []string{"-async"},
4274 })
4275 }
4276
4277 // Test that exceeding the timeout schedule hits a read
4278 // timeout.
4279 testCases = append(testCases, testCase{
4280 protocol: dtls,
4281 name: "DTLS-Retransmit-Timeout",
4282 config: Config{
4283 Bugs: ProtocolBugs{
4284 TimeoutSchedule: timeouts,
4285 },
4286 },
4287 resumeSession: true,
4288 flags: []string{"-async"},
4289 shouldFail: true,
4290 expectedError: ":READ_TIMEOUT_EXPIRED:",
4291 })
4292
4293 // Test that timeout handling has a fudge factor, due to API
4294 // problems.
4295 testCases = append(testCases, testCase{
4296 protocol: dtls,
4297 name: "DTLS-Retransmit-Fudge",
4298 config: Config{
4299 Bugs: ProtocolBugs{
4300 TimeoutSchedule: []time.Duration{
4301 timeouts[0] - 10*time.Millisecond,
4302 },
4303 },
4304 },
4305 resumeSession: true,
4306 flags: []string{"-async"},
4307 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004308
4309 // Test that the final Finished retransmitting isn't
4310 // duplicated if the peer badly fragments everything.
4311 testCases = append(testCases, testCase{
4312 testType: serverTest,
4313 protocol: dtls,
4314 name: "DTLS-Retransmit-Fragmented",
4315 config: Config{
4316 Bugs: ProtocolBugs{
4317 TimeoutSchedule: []time.Duration{timeouts[0]},
4318 MaxHandshakeRecordLength: 2,
4319 },
4320 },
4321 flags: []string{"-async"},
4322 })
David Benjamin83f90402015-01-27 01:09:43 -05004323}
4324
David Benjaminc565ebb2015-04-03 04:06:36 -04004325func addExportKeyingMaterialTests() {
4326 for _, vers := range tlsVersions {
4327 if vers.version == VersionSSL30 {
4328 continue
4329 }
4330 testCases = append(testCases, testCase{
4331 name: "ExportKeyingMaterial-" + vers.name,
4332 config: Config{
4333 MaxVersion: vers.version,
4334 },
4335 exportKeyingMaterial: 1024,
4336 exportLabel: "label",
4337 exportContext: "context",
4338 useExportContext: true,
4339 })
4340 testCases = append(testCases, testCase{
4341 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4342 config: Config{
4343 MaxVersion: vers.version,
4344 },
4345 exportKeyingMaterial: 1024,
4346 })
4347 testCases = append(testCases, testCase{
4348 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4349 config: Config{
4350 MaxVersion: vers.version,
4351 },
4352 exportKeyingMaterial: 1024,
4353 useExportContext: true,
4354 })
4355 testCases = append(testCases, testCase{
4356 name: "ExportKeyingMaterial-Small-" + vers.name,
4357 config: Config{
4358 MaxVersion: vers.version,
4359 },
4360 exportKeyingMaterial: 1,
4361 exportLabel: "label",
4362 exportContext: "context",
4363 useExportContext: true,
4364 })
4365 }
4366 testCases = append(testCases, testCase{
4367 name: "ExportKeyingMaterial-SSL3",
4368 config: Config{
4369 MaxVersion: VersionSSL30,
4370 },
4371 exportKeyingMaterial: 1024,
4372 exportLabel: "label",
4373 exportContext: "context",
4374 useExportContext: true,
4375 shouldFail: true,
4376 expectedError: "failed to export keying material",
4377 })
4378}
4379
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004380func addTLSUniqueTests() {
4381 for _, isClient := range []bool{false, true} {
4382 for _, isResumption := range []bool{false, true} {
4383 for _, hasEMS := range []bool{false, true} {
4384 var suffix string
4385 if isResumption {
4386 suffix = "Resume-"
4387 } else {
4388 suffix = "Full-"
4389 }
4390
4391 if hasEMS {
4392 suffix += "EMS-"
4393 } else {
4394 suffix += "NoEMS-"
4395 }
4396
4397 if isClient {
4398 suffix += "Client"
4399 } else {
4400 suffix += "Server"
4401 }
4402
4403 test := testCase{
4404 name: "TLSUnique-" + suffix,
4405 testTLSUnique: true,
4406 config: Config{
4407 Bugs: ProtocolBugs{
4408 NoExtendedMasterSecret: !hasEMS,
4409 },
4410 },
4411 }
4412
4413 if isResumption {
4414 test.resumeSession = true
4415 test.resumeConfig = &Config{
4416 Bugs: ProtocolBugs{
4417 NoExtendedMasterSecret: !hasEMS,
4418 },
4419 }
4420 }
4421
4422 if isResumption && !hasEMS {
4423 test.shouldFail = true
4424 test.expectedError = "failed to get tls-unique"
4425 }
4426
4427 testCases = append(testCases, test)
4428 }
4429 }
4430 }
4431}
4432
Adam Langley09505632015-07-30 18:10:13 -07004433func addCustomExtensionTests() {
4434 expectedContents := "custom extension"
4435 emptyString := ""
4436
4437 for _, isClient := range []bool{false, true} {
4438 suffix := "Server"
4439 flag := "-enable-server-custom-extension"
4440 testType := serverTest
4441 if isClient {
4442 suffix = "Client"
4443 flag = "-enable-client-custom-extension"
4444 testType = clientTest
4445 }
4446
4447 testCases = append(testCases, testCase{
4448 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004449 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004450 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004451 Bugs: ProtocolBugs{
4452 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004453 ExpectedCustomExtension: &expectedContents,
4454 },
4455 },
4456 flags: []string{flag},
4457 })
4458
4459 // If the parse callback fails, the handshake should also fail.
4460 testCases = append(testCases, testCase{
4461 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004462 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004463 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004464 Bugs: ProtocolBugs{
4465 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004466 ExpectedCustomExtension: &expectedContents,
4467 },
4468 },
David Benjamin399e7c92015-07-30 23:01:27 -04004469 flags: []string{flag},
4470 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004471 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4472 })
4473
4474 // If the add callback fails, the handshake should also fail.
4475 testCases = append(testCases, testCase{
4476 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004477 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004478 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004479 Bugs: ProtocolBugs{
4480 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004481 ExpectedCustomExtension: &expectedContents,
4482 },
4483 },
David Benjamin399e7c92015-07-30 23:01:27 -04004484 flags: []string{flag, "-custom-extension-fail-add"},
4485 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004486 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4487 })
4488
4489 // If the add callback returns zero, no extension should be
4490 // added.
4491 skipCustomExtension := expectedContents
4492 if isClient {
4493 // For the case where the client skips sending the
4494 // custom extension, the server must not “echo” it.
4495 skipCustomExtension = ""
4496 }
4497 testCases = append(testCases, testCase{
4498 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004499 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004500 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004501 Bugs: ProtocolBugs{
4502 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004503 ExpectedCustomExtension: &emptyString,
4504 },
4505 },
4506 flags: []string{flag, "-custom-extension-skip"},
4507 })
4508 }
4509
4510 // The custom extension add callback should not be called if the client
4511 // doesn't send the extension.
4512 testCases = append(testCases, testCase{
4513 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004514 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004515 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004516 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004517 ExpectedCustomExtension: &emptyString,
4518 },
4519 },
4520 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4521 })
Adam Langley2deb9842015-08-07 11:15:37 -07004522
4523 // Test an unknown extension from the server.
4524 testCases = append(testCases, testCase{
4525 testType: clientTest,
4526 name: "UnknownExtension-Client",
4527 config: Config{
4528 Bugs: ProtocolBugs{
4529 CustomExtension: expectedContents,
4530 },
4531 },
4532 shouldFail: true,
4533 expectedError: ":UNEXPECTED_EXTENSION:",
4534 })
Adam Langley09505632015-07-30 18:10:13 -07004535}
4536
Adam Langley7c803a62015-06-15 15:35:05 -07004537func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004538 defer wg.Done()
4539
4540 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004541 var err error
4542
4543 if *mallocTest < 0 {
4544 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004545 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004546 } else {
4547 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4548 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004549 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004550 if err != nil {
4551 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4552 }
4553 break
4554 }
4555 }
4556 }
Adam Langley95c29f32014-06-20 12:00:00 -07004557 statusChan <- statusMsg{test: test, err: err}
4558 }
4559}
4560
4561type statusMsg struct {
4562 test *testCase
4563 started bool
4564 err error
4565}
4566
David Benjamin5f237bc2015-02-11 17:14:15 -05004567func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004568 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004569
David Benjamin5f237bc2015-02-11 17:14:15 -05004570 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004571 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004572 if !*pipe {
4573 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004574 var erase string
4575 for i := 0; i < lineLen; i++ {
4576 erase += "\b \b"
4577 }
4578 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004579 }
4580
Adam Langley95c29f32014-06-20 12:00:00 -07004581 if msg.started {
4582 started++
4583 } else {
4584 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004585
4586 if msg.err != nil {
4587 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4588 failed++
4589 testOutput.addResult(msg.test.name, "FAIL")
4590 } else {
4591 if *pipe {
4592 // Print each test instead of a status line.
4593 fmt.Printf("PASSED (%s)\n", msg.test.name)
4594 }
4595 testOutput.addResult(msg.test.name, "PASS")
4596 }
Adam Langley95c29f32014-06-20 12:00:00 -07004597 }
4598
David Benjamin5f237bc2015-02-11 17:14:15 -05004599 if !*pipe {
4600 // Print a new status line.
4601 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4602 lineLen = len(line)
4603 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004604 }
Adam Langley95c29f32014-06-20 12:00:00 -07004605 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004606
4607 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004608}
4609
4610func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004611 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004612 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004613
Adam Langley7c803a62015-06-15 15:35:05 -07004614 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004615 addCipherSuiteTests()
4616 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004617 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004618 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004619 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004620 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004621 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004622 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004623 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004624 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004625 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004626 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004627 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004628 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004629 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004630 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004631 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004632 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004633 for _, async := range []bool{false, true} {
4634 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004635 for _, protocol := range []protocol{tls, dtls} {
4636 addStateMachineCoverageTests(async, splitHandshake, protocol)
4637 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004638 }
4639 }
Adam Langley95c29f32014-06-20 12:00:00 -07004640
4641 var wg sync.WaitGroup
4642
Adam Langley7c803a62015-06-15 15:35:05 -07004643 statusChan := make(chan statusMsg, *numWorkers)
4644 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004645 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004646
David Benjamin025b3d32014-07-01 19:53:04 -04004647 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004648
Adam Langley7c803a62015-06-15 15:35:05 -07004649 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004650 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004651 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004652 }
4653
David Benjamin025b3d32014-07-01 19:53:04 -04004654 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004655 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004656 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004657 }
4658 }
4659
4660 close(testChan)
4661 wg.Wait()
4662 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004663 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004664
4665 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004666
4667 if *jsonOutput != "" {
4668 if err := testOutput.writeTo(*jsonOutput); err != nil {
4669 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4670 }
4671 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004672
4673 if !testOutput.allPassed {
4674 os.Exit(1)
4675 }
Adam Langley95c29f32014-06-20 12:00:00 -07004676}