blob: 5b746c620a32296f5ba5ca2d798631aed2ba93c7 [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")
David Benjamind16bf342015-12-18 00:53:12 -050030 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
David Benjamin5f237bc2015-02-11 17:14:15 -050031 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
32 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
33 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.")
34 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
35 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070036 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
37 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
38 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
39 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
David Benjaminf2b83632016-03-01 22:57:46 -050040 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
David Benjamin9867b7d2016-03-01 23:25:48 -050041 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
David Benjamin3ed59772016-03-08 12:50:21 -050042 timeout = flag.Int("timeout", 15, "The number of seconds to wait for a read or write to bssl_shim.")
Adam Langley69a01602014-11-17 17:26:55 -080043)
Adam Langley95c29f32014-06-20 12:00:00 -070044
David Benjamin025b3d32014-07-01 19:53:04 -040045const (
46 rsaCertificateFile = "cert.pem"
47 ecdsaCertificateFile = "ecdsa_cert.pem"
48)
49
50const (
David Benjamina08e49d2014-08-24 01:46:07 -040051 rsaKeyFile = "key.pem"
52 ecdsaKeyFile = "ecdsa_key.pem"
53 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040054)
55
Adam Langley95c29f32014-06-20 12:00:00 -070056var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040057var channelIDKey *ecdsa.PrivateKey
58var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070059
David Benjamin61f95272014-11-25 01:55:35 -050060var testOCSPResponse = []byte{1, 2, 3, 4}
61var testSCTList = []byte{5, 6, 7, 8}
62
Adam Langley95c29f32014-06-20 12:00:00 -070063func initCertificates() {
64 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070065 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070066 if err != nil {
67 panic(err)
68 }
David Benjamin61f95272014-11-25 01:55:35 -050069 rsaCertificate.OCSPStaple = testOCSPResponse
70 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070071
Adam Langley7c803a62015-06-15 15:35:05 -070072 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070073 if err != nil {
74 panic(err)
75 }
David Benjamin61f95272014-11-25 01:55:35 -050076 ecdsaCertificate.OCSPStaple = testOCSPResponse
77 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040078
Adam Langley7c803a62015-06-15 15:35:05 -070079 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040080 if err != nil {
81 panic(err)
82 }
83 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
84 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
85 panic("bad key type")
86 }
87 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
88 if err != nil {
89 panic(err)
90 }
91 if channelIDKey.Curve != elliptic.P256() {
92 panic("bad curve")
93 }
94
95 channelIDBytes = make([]byte, 64)
96 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
97 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070098}
99
100var certificateOnce sync.Once
101
102func getRSACertificate() Certificate {
103 certificateOnce.Do(initCertificates)
104 return rsaCertificate
105}
106
107func getECDSACertificate() Certificate {
108 certificateOnce.Do(initCertificates)
109 return ecdsaCertificate
110}
111
David Benjamin025b3d32014-07-01 19:53:04 -0400112type testType int
113
114const (
115 clientTest testType = iota
116 serverTest
117)
118
David Benjamin6fd297b2014-08-11 18:43:38 -0400119type protocol int
120
121const (
122 tls protocol = iota
123 dtls
124)
125
David Benjaminfc7b0862014-09-06 13:21:53 -0400126const (
127 alpn = 1
128 npn = 2
129)
130
Adam Langley95c29f32014-06-20 12:00:00 -0700131type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400132 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400133 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700134 name string
135 config Config
136 shouldFail bool
137 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700138 // expectedLocalError, if not empty, contains a substring that must be
139 // found in the local error.
140 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400141 // expectedVersion, if non-zero, specifies the TLS version that must be
142 // negotiated.
143 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400144 // expectedResumeVersion, if non-zero, specifies the TLS version that
145 // must be negotiated on resumption. If zero, expectedVersion is used.
146 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400147 // expectedCipher, if non-zero, specifies the TLS cipher suite that
148 // should be negotiated.
149 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400150 // expectChannelID controls whether the connection should have
151 // negotiated a Channel ID with channelIDKey.
152 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400153 // expectedNextProto controls whether the connection should
154 // negotiate a next protocol via NPN or ALPN.
155 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400156 // expectNoNextProto, if true, means that no next protocol should be
157 // negotiated.
158 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400159 // expectedNextProtoType, if non-zero, is the expected next
160 // protocol negotiation mechanism.
161 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500162 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
163 // should be negotiated. If zero, none should be negotiated.
164 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100165 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
166 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100167 // expectedSCTList, if not nil, is the expected SCT list to be received.
168 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400169 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
170 // hash function that the client should have used when signing the
171 // handshake with a client certificate.
172 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700173 // messageLen is the length, in bytes, of the test message that will be
174 // sent.
175 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400176 // messageCount is the number of test messages that will be sent.
177 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400178 // digestPrefs is the list of digest preferences from the client.
179 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400180 // certFile is the path to the certificate to use for the server.
181 certFile string
182 // keyFile is the path to the private key to use for the server.
183 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400184 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400185 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400186 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700187 // expectResumeRejected, if true, specifies that the attempted
188 // resumption must be rejected by the client. This is only valid for a
189 // serverTest.
190 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400191 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500192 // resumption. Unless newSessionsOnResume is set,
193 // SessionTicketKey, ServerSessionCache, and
194 // ClientSessionCache are copied from the initial connection's
195 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400196 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500197 // newSessionsOnResume, if true, will cause resumeConfig to
198 // use a different session resumption context.
199 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400200 // noSessionCache, if true, will cause the server to run without a
201 // session cache.
202 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400203 // sendPrefix sends a prefix on the socket before actually performing a
204 // handshake.
205 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400206 // shimWritesFirst controls whether the shim sends an initial "hello"
207 // message before doing a roundtrip with the runner.
208 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400209 // shimShutsDown, if true, runs a test where the shim shuts down the
210 // connection immediately after the handshake rather than echoing
211 // messages from the runner.
212 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400213 // renegotiate indicates the number of times the connection should be
214 // renegotiated during the exchange.
215 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700216 // renegotiateCiphers is a list of ciphersuite ids that will be
217 // switched in just before renegotiation.
218 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500219 // replayWrites, if true, configures the underlying transport
220 // to replay every write it makes in DTLS tests.
221 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500222 // damageFirstWrite, if true, configures the underlying transport to
223 // damage the final byte of the first application data write.
224 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400225 // exportKeyingMaterial, if non-zero, configures the test to exchange
226 // keying material and verify they match.
227 exportKeyingMaterial int
228 exportLabel string
229 exportContext string
230 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400231 // flags, if not empty, contains a list of command-line flags that will
232 // be passed to the shim program.
233 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700234 // testTLSUnique, if true, causes the shim to send the tls-unique value
235 // which will be compared against the expected value.
236 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400237 // sendEmptyRecords is the number of consecutive empty records to send
238 // before and after the test message.
239 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400240 // sendWarningAlerts is the number of consecutive warning alerts to send
241 // before and after the test message.
242 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400243 // expectMessageDropped, if true, means the test message is expected to
244 // be dropped by the client rather than echoed back.
245 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
Adam Langley7c803a62015-06-15 15:35:05 -0700248var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700249
David Benjamin9867b7d2016-03-01 23:25:48 -0500250func writeTranscript(test *testCase, isResume bool, data []byte) {
251 if len(data) == 0 {
252 return
253 }
254
255 protocol := "tls"
256 if test.protocol == dtls {
257 protocol = "dtls"
258 }
259
260 side := "client"
261 if test.testType == serverTest {
262 side = "server"
263 }
264
265 dir := path.Join(*transcriptDir, protocol, side)
266 if err := os.MkdirAll(dir, 0755); err != nil {
267 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
268 return
269 }
270
271 name := test.name
272 if isResume {
273 name += "-Resume"
274 } else {
275 name += "-Normal"
276 }
277
278 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
279 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
280 }
281}
282
David Benjamin3ed59772016-03-08 12:50:21 -0500283// A timeoutConn implements an idle timeout on each Read and Write operation.
284type timeoutConn struct {
285 net.Conn
286 timeout time.Duration
287}
288
289func (t *timeoutConn) Read(b []byte) (int, error) {
290 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
291 return 0, err
292 }
293 return t.Conn.Read(b)
294}
295
296func (t *timeoutConn) Write(b []byte) (int, error) {
297 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
298 return 0, err
299 }
300 return t.Conn.Write(b)
301}
302
David Benjamin8e6db492015-07-25 18:29:23 -0400303func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin3ed59772016-03-08 12:50:21 -0500304 conn = &timeoutConn{conn, time.Duration(*timeout) * time.Second}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500305
David Benjamin6fd297b2014-08-11 18:43:38 -0400306 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500307 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
308 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500309 }
310
David Benjamin9867b7d2016-03-01 23:25:48 -0500311 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500312 local, peer := "client", "server"
313 if test.testType == clientTest {
314 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500315 }
David Benjaminebda9b32015-11-02 15:33:18 -0500316 connDebug := &recordingConn{
317 Conn: conn,
318 isDatagram: test.protocol == dtls,
319 local: local,
320 peer: peer,
321 }
322 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500323 if *flagDebug {
324 defer connDebug.WriteTo(os.Stdout)
325 }
326 if len(*transcriptDir) != 0 {
327 defer func() {
328 writeTranscript(test, isResume, connDebug.Transcript())
329 }()
330 }
David Benjaminebda9b32015-11-02 15:33:18 -0500331
332 if config.Bugs.PacketAdaptor != nil {
333 config.Bugs.PacketAdaptor.debug = connDebug
334 }
335 }
336
337 if test.replayWrites {
338 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400339 }
340
David Benjamin3ed59772016-03-08 12:50:21 -0500341 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500342 if test.damageFirstWrite {
343 connDamage = newDamageAdaptor(conn)
344 conn = connDamage
345 }
346
David Benjamin6fd297b2014-08-11 18:43:38 -0400347 if test.sendPrefix != "" {
348 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
349 return err
350 }
David Benjamin98e882e2014-08-08 13:24:34 -0400351 }
352
David Benjamin1d5c83e2014-07-22 19:20:02 -0400353 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400354 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400355 if test.protocol == dtls {
356 tlsConn = DTLSServer(conn, config)
357 } else {
358 tlsConn = Server(conn, config)
359 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400360 } else {
361 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400362 if test.protocol == dtls {
363 tlsConn = DTLSClient(conn, config)
364 } else {
365 tlsConn = Client(conn, config)
366 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400367 }
David Benjamin30789da2015-08-29 22:56:45 -0400368 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400369
Adam Langley95c29f32014-06-20 12:00:00 -0700370 if err := tlsConn.Handshake(); err != nil {
371 return err
372 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700373
David Benjamin01fe8202014-09-24 15:21:44 -0400374 // TODO(davidben): move all per-connection expectations into a dedicated
375 // expectations struct that can be specified separately for the two
376 // legs.
377 expectedVersion := test.expectedVersion
378 if isResume && test.expectedResumeVersion != 0 {
379 expectedVersion = test.expectedResumeVersion
380 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700381 connState := tlsConn.ConnectionState()
382 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400383 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400384 }
385
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700386 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400387 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
388 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700389 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
390 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
391 }
David Benjamin90da8c82015-04-20 14:57:57 -0400392
David Benjamina08e49d2014-08-24 01:46:07 -0400393 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700394 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400395 if channelID == nil {
396 return fmt.Errorf("no channel ID negotiated")
397 }
398 if channelID.Curve != channelIDKey.Curve ||
399 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
400 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
401 return fmt.Errorf("incorrect channel ID")
402 }
403 }
404
David Benjaminae2888f2014-09-06 12:58:58 -0400405 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700406 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400407 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
408 }
409 }
410
David Benjaminc7ce9772015-10-09 19:32:41 -0400411 if test.expectNoNextProto {
412 if actual := connState.NegotiatedProtocol; actual != "" {
413 return fmt.Errorf("got unexpected next proto %s", actual)
414 }
415 }
416
David Benjaminfc7b0862014-09-06 13:21:53 -0400417 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700418 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400419 return fmt.Errorf("next proto type mismatch")
420 }
421 }
422
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700423 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500424 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
425 }
426
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100427 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
428 return fmt.Errorf("OCSP Response mismatch")
429 }
430
Paul Lietar4fac72e2015-09-09 13:44:55 +0100431 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
432 return fmt.Errorf("SCT list mismatch")
433 }
434
Steven Valdez0d62f262015-09-04 12:41:04 -0400435 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
436 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
437 }
438
David Benjaminc565ebb2015-04-03 04:06:36 -0400439 if test.exportKeyingMaterial > 0 {
440 actual := make([]byte, test.exportKeyingMaterial)
441 if _, err := io.ReadFull(tlsConn, actual); err != nil {
442 return err
443 }
444 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
445 if err != nil {
446 return err
447 }
448 if !bytes.Equal(actual, expected) {
449 return fmt.Errorf("keying material mismatch")
450 }
451 }
452
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700453 if test.testTLSUnique {
454 var peersValue [12]byte
455 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
456 return err
457 }
458 expected := tlsConn.ConnectionState().TLSUnique
459 if !bytes.Equal(peersValue[:], expected) {
460 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
461 }
462 }
463
David Benjamine58c4f52014-08-24 03:47:07 -0400464 if test.shimWritesFirst {
465 var buf [5]byte
466 _, err := io.ReadFull(tlsConn, buf[:])
467 if err != nil {
468 return err
469 }
470 if string(buf[:]) != "hello" {
471 return fmt.Errorf("bad initial message")
472 }
473 }
474
David Benjamina8ebe222015-06-06 03:04:39 -0400475 for i := 0; i < test.sendEmptyRecords; i++ {
476 tlsConn.Write(nil)
477 }
478
David Benjamin24f346d2015-06-06 03:28:08 -0400479 for i := 0; i < test.sendWarningAlerts; i++ {
480 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
481 }
482
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400483 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700484 if test.renegotiateCiphers != nil {
485 config.CipherSuites = test.renegotiateCiphers
486 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400487 for i := 0; i < test.renegotiate; i++ {
488 if err := tlsConn.Renegotiate(); err != nil {
489 return err
490 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700491 }
492 } else if test.renegotiateCiphers != nil {
493 panic("renegotiateCiphers without renegotiate")
494 }
495
David Benjamin5fa3eba2015-01-22 16:35:40 -0500496 if test.damageFirstWrite {
497 connDamage.setDamage(true)
498 tlsConn.Write([]byte("DAMAGED WRITE"))
499 connDamage.setDamage(false)
500 }
501
David Benjamin8e6db492015-07-25 18:29:23 -0400502 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700503 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400504 if test.protocol == dtls {
505 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
506 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700507 // Read until EOF.
508 _, err := io.Copy(ioutil.Discard, tlsConn)
509 return err
510 }
David Benjamin4417d052015-04-05 04:17:25 -0400511 if messageLen == 0 {
512 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700513 }
Adam Langley95c29f32014-06-20 12:00:00 -0700514
David Benjamin8e6db492015-07-25 18:29:23 -0400515 messageCount := test.messageCount
516 if messageCount == 0 {
517 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400518 }
519
David Benjamin8e6db492015-07-25 18:29:23 -0400520 for j := 0; j < messageCount; j++ {
521 testMessage := make([]byte, messageLen)
522 for i := range testMessage {
523 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400524 }
David Benjamin8e6db492015-07-25 18:29:23 -0400525 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700526
David Benjamin8e6db492015-07-25 18:29:23 -0400527 for i := 0; i < test.sendEmptyRecords; i++ {
528 tlsConn.Write(nil)
529 }
530
531 for i := 0; i < test.sendWarningAlerts; i++ {
532 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
533 }
534
David Benjamin4f75aaf2015-09-01 16:53:10 -0400535 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400536 // The shim will not respond.
537 continue
538 }
539
David Benjamin8e6db492015-07-25 18:29:23 -0400540 buf := make([]byte, len(testMessage))
541 if test.protocol == dtls {
542 bufTmp := make([]byte, len(buf)+1)
543 n, err := tlsConn.Read(bufTmp)
544 if err != nil {
545 return err
546 }
547 if n != len(buf) {
548 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
549 }
550 copy(buf, bufTmp)
551 } else {
552 _, err := io.ReadFull(tlsConn, buf)
553 if err != nil {
554 return err
555 }
556 }
557
558 for i, v := range buf {
559 if v != testMessage[i]^0xff {
560 return fmt.Errorf("bad reply contents at byte %d", i)
561 }
Adam Langley95c29f32014-06-20 12:00:00 -0700562 }
563 }
564
565 return nil
566}
567
David Benjamin325b5c32014-07-01 19:40:31 -0400568func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
569 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700570 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400571 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700572 }
David Benjamin325b5c32014-07-01 19:40:31 -0400573 valgrindArgs = append(valgrindArgs, path)
574 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700575
David Benjamin325b5c32014-07-01 19:40:31 -0400576 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700577}
578
David Benjamin325b5c32014-07-01 19:40:31 -0400579func gdbOf(path string, args ...string) *exec.Cmd {
580 xtermArgs := []string{"-e", "gdb", "--args"}
581 xtermArgs = append(xtermArgs, path)
582 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700583
David Benjamin325b5c32014-07-01 19:40:31 -0400584 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700585}
586
David Benjamind16bf342015-12-18 00:53:12 -0500587func lldbOf(path string, args ...string) *exec.Cmd {
588 xtermArgs := []string{"-e", "lldb", "--"}
589 xtermArgs = append(xtermArgs, path)
590 xtermArgs = append(xtermArgs, args...)
591
592 return exec.Command("xterm", xtermArgs...)
593}
594
Adam Langley69a01602014-11-17 17:26:55 -0800595type moreMallocsError struct{}
596
597func (moreMallocsError) Error() string {
598 return "child process did not exhaust all allocation calls"
599}
600
601var errMoreMallocs = moreMallocsError{}
602
David Benjamin87c8a642015-02-21 01:54:29 -0500603// accept accepts a connection from listener, unless waitChan signals a process
604// exit first.
605func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
606 type connOrError struct {
607 conn net.Conn
608 err error
609 }
610 connChan := make(chan connOrError, 1)
611 go func() {
612 conn, err := listener.Accept()
613 connChan <- connOrError{conn, err}
614 close(connChan)
615 }()
616 select {
617 case result := <-connChan:
618 return result.conn, result.err
619 case childErr := <-waitChan:
620 waitChan <- childErr
621 return nil, fmt.Errorf("child exited early: %s", childErr)
622 }
623}
624
Adam Langley7c803a62015-06-15 15:35:05 -0700625func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700626 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
627 panic("Error expected without shouldFail in " + test.name)
628 }
629
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700630 if test.expectResumeRejected && !test.resumeSession {
631 panic("expectResumeRejected without resumeSession in " + test.name)
632 }
633
Steven Valdez0d62f262015-09-04 12:41:04 -0400634 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
635 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
636 }
637
David Benjamin87c8a642015-02-21 01:54:29 -0500638 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
639 if err != nil {
640 panic(err)
641 }
642 defer func() {
643 if listener != nil {
644 listener.Close()
645 }
646 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700647
David Benjamin87c8a642015-02-21 01:54:29 -0500648 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400649 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400650 flags = append(flags, "-server")
651
David Benjamin025b3d32014-07-01 19:53:04 -0400652 flags = append(flags, "-key-file")
653 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700654 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400655 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700656 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400657 }
658
659 flags = append(flags, "-cert-file")
660 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700661 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400662 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700663 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400664 }
665 }
David Benjamin5a593af2014-08-11 19:51:50 -0400666
Steven Valdez0d62f262015-09-04 12:41:04 -0400667 if test.digestPrefs != "" {
668 flags = append(flags, "-digest-prefs")
669 flags = append(flags, test.digestPrefs)
670 }
671
David Benjamin6fd297b2014-08-11 18:43:38 -0400672 if test.protocol == dtls {
673 flags = append(flags, "-dtls")
674 }
675
David Benjamin5a593af2014-08-11 19:51:50 -0400676 if test.resumeSession {
677 flags = append(flags, "-resume")
678 }
679
David Benjamine58c4f52014-08-24 03:47:07 -0400680 if test.shimWritesFirst {
681 flags = append(flags, "-shim-writes-first")
682 }
683
David Benjamin30789da2015-08-29 22:56:45 -0400684 if test.shimShutsDown {
685 flags = append(flags, "-shim-shuts-down")
686 }
687
David Benjaminc565ebb2015-04-03 04:06:36 -0400688 if test.exportKeyingMaterial > 0 {
689 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
690 flags = append(flags, "-export-label", test.exportLabel)
691 flags = append(flags, "-export-context", test.exportContext)
692 if test.useExportContext {
693 flags = append(flags, "-use-export-context")
694 }
695 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700696 if test.expectResumeRejected {
697 flags = append(flags, "-expect-session-miss")
698 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400699
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700700 if test.testTLSUnique {
701 flags = append(flags, "-tls-unique")
702 }
703
David Benjamin025b3d32014-07-01 19:53:04 -0400704 flags = append(flags, test.flags...)
705
706 var shim *exec.Cmd
707 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700708 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700709 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700710 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500711 } else if *useLLDB {
712 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400713 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700714 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400715 }
David Benjamin025b3d32014-07-01 19:53:04 -0400716 shim.Stdin = os.Stdin
717 var stdoutBuf, stderrBuf bytes.Buffer
718 shim.Stdout = &stdoutBuf
719 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800720 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500721 shim.Env = os.Environ()
722 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800723 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400724 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800725 }
726 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
727 }
David Benjamin025b3d32014-07-01 19:53:04 -0400728
729 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700730 panic(err)
731 }
David Benjamin87c8a642015-02-21 01:54:29 -0500732 waitChan := make(chan error, 1)
733 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700734
735 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400736 if !test.noSessionCache {
737 config.ClientSessionCache = NewLRUClientSessionCache(1)
738 config.ServerSessionCache = NewLRUServerSessionCache(1)
739 }
David Benjamin025b3d32014-07-01 19:53:04 -0400740 if test.testType == clientTest {
741 if len(config.Certificates) == 0 {
742 config.Certificates = []Certificate{getRSACertificate()}
743 }
David Benjamin87c8a642015-02-21 01:54:29 -0500744 } else {
745 // Supply a ServerName to ensure a constant session cache key,
746 // rather than falling back to net.Conn.RemoteAddr.
747 if len(config.ServerName) == 0 {
748 config.ServerName = "test"
749 }
David Benjamin025b3d32014-07-01 19:53:04 -0400750 }
David Benjaminf2b83632016-03-01 22:57:46 -0500751 if *fuzzer {
752 config.Bugs.NullAllCiphers = true
753 }
Adam Langley95c29f32014-06-20 12:00:00 -0700754
David Benjamin87c8a642015-02-21 01:54:29 -0500755 conn, err := acceptOrWait(listener, waitChan)
756 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400757 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500758 conn.Close()
759 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500760
David Benjamin1d5c83e2014-07-22 19:20:02 -0400761 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400762 var resumeConfig Config
763 if test.resumeConfig != nil {
764 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500765 if len(resumeConfig.ServerName) == 0 {
766 resumeConfig.ServerName = config.ServerName
767 }
David Benjamin01fe8202014-09-24 15:21:44 -0400768 if len(resumeConfig.Certificates) == 0 {
769 resumeConfig.Certificates = []Certificate{getRSACertificate()}
770 }
David Benjaminba4594a2015-06-18 18:36:15 -0400771 if test.newSessionsOnResume {
772 if !test.noSessionCache {
773 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
774 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
775 }
776 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500777 resumeConfig.SessionTicketKey = config.SessionTicketKey
778 resumeConfig.ClientSessionCache = config.ClientSessionCache
779 resumeConfig.ServerSessionCache = config.ServerSessionCache
780 }
David Benjaminf2b83632016-03-01 22:57:46 -0500781 if *fuzzer {
782 resumeConfig.Bugs.NullAllCiphers = true
783 }
David Benjamin01fe8202014-09-24 15:21:44 -0400784 } else {
785 resumeConfig = config
786 }
David Benjamin87c8a642015-02-21 01:54:29 -0500787 var connResume net.Conn
788 connResume, err = acceptOrWait(listener, waitChan)
789 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400790 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500791 connResume.Close()
792 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400793 }
794
David Benjamin87c8a642015-02-21 01:54:29 -0500795 // Close the listener now. This is to avoid hangs should the shim try to
796 // open more connections than expected.
797 listener.Close()
798 listener = nil
799
800 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800801 if exitError, ok := childErr.(*exec.ExitError); ok {
802 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
803 return errMoreMallocs
804 }
805 }
Adam Langley95c29f32014-06-20 12:00:00 -0700806
David Benjamin9bea3492016-03-02 10:59:16 -0500807 // Account for Windows line endings.
808 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
809 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500810
811 // Separate the errors from the shim and those from tools like
812 // AddressSanitizer.
813 var extraStderr string
814 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
815 stderr = stderrParts[0]
816 extraStderr = stderrParts[1]
817 }
818
Adam Langley95c29f32014-06-20 12:00:00 -0700819 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400820 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700821 localError := "none"
822 if err != nil {
823 localError = err.Error()
824 }
825 if len(test.expectedLocalError) != 0 {
826 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
827 }
Adam Langley95c29f32014-06-20 12:00:00 -0700828
829 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700830 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700831 if childErr != nil {
832 childError = childErr.Error()
833 }
834
835 var msg string
836 switch {
837 case failed && !test.shouldFail:
838 msg = "unexpected failure"
839 case !failed && test.shouldFail:
840 msg = "unexpected success"
841 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700842 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700843 default:
844 panic("internal error")
845 }
846
David Benjaminc565ebb2015-04-03 04:06:36 -0400847 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 -0700848 }
849
David Benjaminff3a1492016-03-02 10:12:06 -0500850 if !*useValgrind && (len(extraStderr) > 0 || (!failed && len(stderr) > 0)) {
851 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700852 }
853
854 return nil
855}
856
857var tlsVersions = []struct {
858 name string
859 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400860 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500861 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700862}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500863 {"SSL3", VersionSSL30, "-no-ssl3", false},
864 {"TLS1", VersionTLS10, "-no-tls1", true},
865 {"TLS11", VersionTLS11, "-no-tls11", false},
866 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700867}
868
869var testCipherSuites = []struct {
870 name string
871 id uint16
872}{
873 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400874 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700875 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400876 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400877 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700878 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400879 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400880 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
881 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400882 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400883 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
884 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400885 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700886 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
887 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400888 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
889 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700890 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400891 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500892 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500893 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700894 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700895 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700896 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400897 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400898 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700899 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400900 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -0500901 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -0500902 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -0700903 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400904 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
905 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700906 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
907 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -0500908 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -0400909 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700910 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400911 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700912 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700913}
914
David Benjamin8b8c0062014-11-23 02:47:52 -0500915func hasComponent(suiteName, component string) bool {
916 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
917}
918
David Benjamin4298d772015-12-19 00:18:25 -0500919func isTLSOnly(suiteName string) bool {
920 // BoringSSL doesn't support ECDHE without a curves extension, and
921 // SSLv3 doesn't contain extensions.
922 return hasComponent(suiteName, "ECDHE") || isTLS12Only(suiteName)
923}
924
David Benjaminf7768e42014-08-31 02:06:47 -0400925func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500926 return hasComponent(suiteName, "GCM") ||
927 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400928 hasComponent(suiteName, "SHA384") ||
929 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500930}
931
932func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700933 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400934}
935
Adam Langleya7997f12015-05-14 17:38:50 -0700936func bigFromHex(hex string) *big.Int {
937 ret, ok := new(big.Int).SetString(hex, 16)
938 if !ok {
939 panic("failed to parse hex number 0x" + hex)
940 }
941 return ret
942}
943
Adam Langley7c803a62015-06-15 15:35:05 -0700944func addBasicTests() {
945 basicTests := []testCase{
946 {
947 name: "BadRSASignature",
948 config: Config{
949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
950 Bugs: ProtocolBugs{
951 InvalidSKXSignature: true,
952 },
953 },
954 shouldFail: true,
955 expectedError: ":BAD_SIGNATURE:",
956 },
957 {
958 name: "BadECDSASignature",
959 config: Config{
960 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
961 Bugs: ProtocolBugs{
962 InvalidSKXSignature: true,
963 },
964 Certificates: []Certificate{getECDSACertificate()},
965 },
966 shouldFail: true,
967 expectedError: ":BAD_SIGNATURE:",
968 },
969 {
David Benjamin6de0e532015-07-28 22:43:19 -0400970 testType: serverTest,
971 name: "BadRSASignature-ClientAuth",
972 config: Config{
973 Bugs: ProtocolBugs{
974 InvalidCertVerifySignature: true,
975 },
976 Certificates: []Certificate{getRSACertificate()},
977 },
978 shouldFail: true,
979 expectedError: ":BAD_SIGNATURE:",
980 flags: []string{"-require-any-client-certificate"},
981 },
982 {
983 testType: serverTest,
984 name: "BadECDSASignature-ClientAuth",
985 config: Config{
986 Bugs: ProtocolBugs{
987 InvalidCertVerifySignature: true,
988 },
989 Certificates: []Certificate{getECDSACertificate()},
990 },
991 shouldFail: true,
992 expectedError: ":BAD_SIGNATURE:",
993 flags: []string{"-require-any-client-certificate"},
994 },
995 {
Adam Langley7c803a62015-06-15 15:35:05 -0700996 name: "BadECDSACurve",
997 config: Config{
998 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
999 Bugs: ProtocolBugs{
1000 InvalidSKXCurve: true,
1001 },
1002 Certificates: []Certificate{getECDSACertificate()},
1003 },
1004 shouldFail: true,
1005 expectedError: ":WRONG_CURVE:",
1006 },
1007 {
Adam Langley7c803a62015-06-15 15:35:05 -07001008 name: "NoFallbackSCSV",
1009 config: Config{
1010 Bugs: ProtocolBugs{
1011 FailIfNotFallbackSCSV: true,
1012 },
1013 },
1014 shouldFail: true,
1015 expectedLocalError: "no fallback SCSV found",
1016 },
1017 {
1018 name: "SendFallbackSCSV",
1019 config: Config{
1020 Bugs: ProtocolBugs{
1021 FailIfNotFallbackSCSV: true,
1022 },
1023 },
1024 flags: []string{"-fallback-scsv"},
1025 },
1026 {
1027 name: "ClientCertificateTypes",
1028 config: Config{
1029 ClientAuth: RequestClientCert,
1030 ClientCertificateTypes: []byte{
1031 CertTypeDSSSign,
1032 CertTypeRSASign,
1033 CertTypeECDSASign,
1034 },
1035 },
1036 flags: []string{
1037 "-expect-certificate-types",
1038 base64.StdEncoding.EncodeToString([]byte{
1039 CertTypeDSSSign,
1040 CertTypeRSASign,
1041 CertTypeECDSASign,
1042 }),
1043 },
1044 },
1045 {
1046 name: "NoClientCertificate",
1047 config: Config{
1048 ClientAuth: RequireAnyClientCert,
1049 },
1050 shouldFail: true,
1051 expectedLocalError: "client didn't provide a certificate",
1052 },
1053 {
1054 name: "UnauthenticatedECDH",
1055 config: Config{
1056 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1057 Bugs: ProtocolBugs{
1058 UnauthenticatedECDH: true,
1059 },
1060 },
1061 shouldFail: true,
1062 expectedError: ":UNEXPECTED_MESSAGE:",
1063 },
1064 {
1065 name: "SkipCertificateStatus",
1066 config: Config{
1067 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1068 Bugs: ProtocolBugs{
1069 SkipCertificateStatus: true,
1070 },
1071 },
1072 flags: []string{
1073 "-enable-ocsp-stapling",
1074 },
1075 },
1076 {
1077 name: "SkipServerKeyExchange",
1078 config: Config{
1079 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1080 Bugs: ProtocolBugs{
1081 SkipServerKeyExchange: true,
1082 },
1083 },
1084 shouldFail: true,
1085 expectedError: ":UNEXPECTED_MESSAGE:",
1086 },
1087 {
1088 name: "SkipChangeCipherSpec-Client",
1089 config: Config{
1090 Bugs: ProtocolBugs{
1091 SkipChangeCipherSpec: true,
1092 },
1093 },
1094 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001095 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001096 },
1097 {
1098 testType: serverTest,
1099 name: "SkipChangeCipherSpec-Server",
1100 config: Config{
1101 Bugs: ProtocolBugs{
1102 SkipChangeCipherSpec: true,
1103 },
1104 },
1105 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001106 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001107 },
1108 {
1109 testType: serverTest,
1110 name: "SkipChangeCipherSpec-Server-NPN",
1111 config: Config{
1112 NextProtos: []string{"bar"},
1113 Bugs: ProtocolBugs{
1114 SkipChangeCipherSpec: true,
1115 },
1116 },
1117 flags: []string{
1118 "-advertise-npn", "\x03foo\x03bar\x03baz",
1119 },
1120 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001121 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001122 },
1123 {
1124 name: "FragmentAcrossChangeCipherSpec-Client",
1125 config: Config{
1126 Bugs: ProtocolBugs{
1127 FragmentAcrossChangeCipherSpec: true,
1128 },
1129 },
1130 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001131 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001132 },
1133 {
1134 testType: serverTest,
1135 name: "FragmentAcrossChangeCipherSpec-Server",
1136 config: Config{
1137 Bugs: ProtocolBugs{
1138 FragmentAcrossChangeCipherSpec: true,
1139 },
1140 },
1141 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001142 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001143 },
1144 {
1145 testType: serverTest,
1146 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1147 config: Config{
1148 NextProtos: []string{"bar"},
1149 Bugs: ProtocolBugs{
1150 FragmentAcrossChangeCipherSpec: true,
1151 },
1152 },
1153 flags: []string{
1154 "-advertise-npn", "\x03foo\x03bar\x03baz",
1155 },
1156 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001157 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001158 },
1159 {
1160 testType: serverTest,
1161 name: "Alert",
1162 config: Config{
1163 Bugs: ProtocolBugs{
1164 SendSpuriousAlert: alertRecordOverflow,
1165 },
1166 },
1167 shouldFail: true,
1168 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1169 },
1170 {
1171 protocol: dtls,
1172 testType: serverTest,
1173 name: "Alert-DTLS",
1174 config: Config{
1175 Bugs: ProtocolBugs{
1176 SendSpuriousAlert: alertRecordOverflow,
1177 },
1178 },
1179 shouldFail: true,
1180 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1181 },
1182 {
1183 testType: serverTest,
1184 name: "FragmentAlert",
1185 config: Config{
1186 Bugs: ProtocolBugs{
1187 FragmentAlert: true,
1188 SendSpuriousAlert: alertRecordOverflow,
1189 },
1190 },
1191 shouldFail: true,
1192 expectedError: ":BAD_ALERT:",
1193 },
1194 {
1195 protocol: dtls,
1196 testType: serverTest,
1197 name: "FragmentAlert-DTLS",
1198 config: Config{
1199 Bugs: ProtocolBugs{
1200 FragmentAlert: true,
1201 SendSpuriousAlert: alertRecordOverflow,
1202 },
1203 },
1204 shouldFail: true,
1205 expectedError: ":BAD_ALERT:",
1206 },
1207 {
1208 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001209 name: "DoubleAlert",
1210 config: Config{
1211 Bugs: ProtocolBugs{
1212 DoubleAlert: true,
1213 SendSpuriousAlert: alertRecordOverflow,
1214 },
1215 },
1216 shouldFail: true,
1217 expectedError: ":BAD_ALERT:",
1218 },
1219 {
1220 protocol: dtls,
1221 testType: serverTest,
1222 name: "DoubleAlert-DTLS",
1223 config: Config{
1224 Bugs: ProtocolBugs{
1225 DoubleAlert: true,
1226 SendSpuriousAlert: alertRecordOverflow,
1227 },
1228 },
1229 shouldFail: true,
1230 expectedError: ":BAD_ALERT:",
1231 },
1232 {
1233 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001234 name: "EarlyChangeCipherSpec-server-1",
1235 config: Config{
1236 Bugs: ProtocolBugs{
1237 EarlyChangeCipherSpec: 1,
1238 },
1239 },
1240 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001241 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001242 },
1243 {
1244 testType: serverTest,
1245 name: "EarlyChangeCipherSpec-server-2",
1246 config: Config{
1247 Bugs: ProtocolBugs{
1248 EarlyChangeCipherSpec: 2,
1249 },
1250 },
1251 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001252 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001253 },
1254 {
1255 name: "SkipNewSessionTicket",
1256 config: Config{
1257 Bugs: ProtocolBugs{
1258 SkipNewSessionTicket: true,
1259 },
1260 },
1261 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001262 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001263 },
1264 {
1265 testType: serverTest,
1266 name: "FallbackSCSV",
1267 config: Config{
1268 MaxVersion: VersionTLS11,
1269 Bugs: ProtocolBugs{
1270 SendFallbackSCSV: true,
1271 },
1272 },
1273 shouldFail: true,
1274 expectedError: ":INAPPROPRIATE_FALLBACK:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "FallbackSCSV-VersionMatch",
1279 config: Config{
1280 Bugs: ProtocolBugs{
1281 SendFallbackSCSV: true,
1282 },
1283 },
1284 },
1285 {
1286 testType: serverTest,
1287 name: "FragmentedClientVersion",
1288 config: Config{
1289 Bugs: ProtocolBugs{
1290 MaxHandshakeRecordLength: 1,
1291 FragmentClientVersion: true,
1292 },
1293 },
1294 expectedVersion: VersionTLS12,
1295 },
1296 {
1297 testType: serverTest,
1298 name: "MinorVersionTolerance",
1299 config: Config{
1300 Bugs: ProtocolBugs{
1301 SendClientVersion: 0x03ff,
1302 },
1303 },
1304 expectedVersion: VersionTLS12,
1305 },
1306 {
1307 testType: serverTest,
1308 name: "MajorVersionTolerance",
1309 config: Config{
1310 Bugs: ProtocolBugs{
1311 SendClientVersion: 0x0400,
1312 },
1313 },
1314 expectedVersion: VersionTLS12,
1315 },
1316 {
1317 testType: serverTest,
1318 name: "VersionTooLow",
1319 config: Config{
1320 Bugs: ProtocolBugs{
1321 SendClientVersion: 0x0200,
1322 },
1323 },
1324 shouldFail: true,
1325 expectedError: ":UNSUPPORTED_PROTOCOL:",
1326 },
1327 {
1328 testType: serverTest,
1329 name: "HttpGET",
1330 sendPrefix: "GET / HTTP/1.0\n",
1331 shouldFail: true,
1332 expectedError: ":HTTP_REQUEST:",
1333 },
1334 {
1335 testType: serverTest,
1336 name: "HttpPOST",
1337 sendPrefix: "POST / HTTP/1.0\n",
1338 shouldFail: true,
1339 expectedError: ":HTTP_REQUEST:",
1340 },
1341 {
1342 testType: serverTest,
1343 name: "HttpHEAD",
1344 sendPrefix: "HEAD / HTTP/1.0\n",
1345 shouldFail: true,
1346 expectedError: ":HTTP_REQUEST:",
1347 },
1348 {
1349 testType: serverTest,
1350 name: "HttpPUT",
1351 sendPrefix: "PUT / HTTP/1.0\n",
1352 shouldFail: true,
1353 expectedError: ":HTTP_REQUEST:",
1354 },
1355 {
1356 testType: serverTest,
1357 name: "HttpCONNECT",
1358 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1359 shouldFail: true,
1360 expectedError: ":HTTPS_PROXY_REQUEST:",
1361 },
1362 {
1363 testType: serverTest,
1364 name: "Garbage",
1365 sendPrefix: "blah",
1366 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001367 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001368 },
1369 {
1370 name: "SkipCipherVersionCheck",
1371 config: Config{
1372 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1373 MaxVersion: VersionTLS11,
1374 Bugs: ProtocolBugs{
1375 SkipCipherVersionCheck: true,
1376 },
1377 },
1378 shouldFail: true,
1379 expectedError: ":WRONG_CIPHER_RETURNED:",
1380 },
1381 {
1382 name: "RSAEphemeralKey",
1383 config: Config{
1384 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1385 Bugs: ProtocolBugs{
1386 RSAEphemeralKey: true,
1387 },
1388 },
1389 shouldFail: true,
1390 expectedError: ":UNEXPECTED_MESSAGE:",
1391 },
1392 {
1393 name: "DisableEverything",
1394 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1395 shouldFail: true,
1396 expectedError: ":WRONG_SSL_VERSION:",
1397 },
1398 {
1399 protocol: dtls,
1400 name: "DisableEverything-DTLS",
1401 flags: []string{"-no-tls12", "-no-tls1"},
1402 shouldFail: true,
1403 expectedError: ":WRONG_SSL_VERSION:",
1404 },
1405 {
1406 name: "NoSharedCipher",
1407 config: Config{
1408 CipherSuites: []uint16{},
1409 },
1410 shouldFail: true,
1411 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1412 },
1413 {
1414 protocol: dtls,
1415 testType: serverTest,
1416 name: "MTU",
1417 config: Config{
1418 Bugs: ProtocolBugs{
1419 MaxPacketLength: 256,
1420 },
1421 },
1422 flags: []string{"-mtu", "256"},
1423 },
1424 {
1425 protocol: dtls,
1426 testType: serverTest,
1427 name: "MTUExceeded",
1428 config: Config{
1429 Bugs: ProtocolBugs{
1430 MaxPacketLength: 255,
1431 },
1432 },
1433 flags: []string{"-mtu", "256"},
1434 shouldFail: true,
1435 expectedLocalError: "dtls: exceeded maximum packet length",
1436 },
1437 {
1438 name: "CertMismatchRSA",
1439 config: Config{
1440 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1441 Certificates: []Certificate{getECDSACertificate()},
1442 Bugs: ProtocolBugs{
1443 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1444 },
1445 },
1446 shouldFail: true,
1447 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1448 },
1449 {
1450 name: "CertMismatchECDSA",
1451 config: Config{
1452 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1453 Certificates: []Certificate{getRSACertificate()},
1454 Bugs: ProtocolBugs{
1455 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1456 },
1457 },
1458 shouldFail: true,
1459 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1460 },
1461 {
1462 name: "EmptyCertificateList",
1463 config: Config{
1464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1465 Bugs: ProtocolBugs{
1466 EmptyCertificateList: true,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":DECODE_ERROR:",
1471 },
1472 {
1473 name: "TLSFatalBadPackets",
1474 damageFirstWrite: true,
1475 shouldFail: true,
1476 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1477 },
1478 {
1479 protocol: dtls,
1480 name: "DTLSIgnoreBadPackets",
1481 damageFirstWrite: true,
1482 },
1483 {
1484 protocol: dtls,
1485 name: "DTLSIgnoreBadPackets-Async",
1486 damageFirstWrite: true,
1487 flags: []string{"-async"},
1488 },
1489 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001490 name: "AppDataBeforeHandshake",
1491 config: Config{
1492 Bugs: ProtocolBugs{
1493 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1494 },
1495 },
1496 shouldFail: true,
1497 expectedError: ":UNEXPECTED_RECORD:",
1498 },
1499 {
1500 name: "AppDataBeforeHandshake-Empty",
1501 config: Config{
1502 Bugs: ProtocolBugs{
1503 AppDataBeforeHandshake: []byte{},
1504 },
1505 },
1506 shouldFail: true,
1507 expectedError: ":UNEXPECTED_RECORD:",
1508 },
1509 {
1510 protocol: dtls,
1511 name: "AppDataBeforeHandshake-DTLS",
1512 config: Config{
1513 Bugs: ProtocolBugs{
1514 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1515 },
1516 },
1517 shouldFail: true,
1518 expectedError: ":UNEXPECTED_RECORD:",
1519 },
1520 {
1521 protocol: dtls,
1522 name: "AppDataBeforeHandshake-DTLS-Empty",
1523 config: Config{
1524 Bugs: ProtocolBugs{
1525 AppDataBeforeHandshake: []byte{},
1526 },
1527 },
1528 shouldFail: true,
1529 expectedError: ":UNEXPECTED_RECORD:",
1530 },
1531 {
Adam Langley7c803a62015-06-15 15:35:05 -07001532 name: "AppDataAfterChangeCipherSpec",
1533 config: Config{
1534 Bugs: ProtocolBugs{
1535 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1536 },
1537 },
1538 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001539 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001540 },
1541 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001542 name: "AppDataAfterChangeCipherSpec-Empty",
1543 config: Config{
1544 Bugs: ProtocolBugs{
1545 AppDataAfterChangeCipherSpec: []byte{},
1546 },
1547 },
1548 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001549 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001550 },
1551 {
Adam Langley7c803a62015-06-15 15:35:05 -07001552 protocol: dtls,
1553 name: "AppDataAfterChangeCipherSpec-DTLS",
1554 config: Config{
1555 Bugs: ProtocolBugs{
1556 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1557 },
1558 },
1559 // BoringSSL's DTLS implementation will drop the out-of-order
1560 // application data.
1561 },
1562 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001563 protocol: dtls,
1564 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1565 config: Config{
1566 Bugs: ProtocolBugs{
1567 AppDataAfterChangeCipherSpec: []byte{},
1568 },
1569 },
1570 // BoringSSL's DTLS implementation will drop the out-of-order
1571 // application data.
1572 },
1573 {
Adam Langley7c803a62015-06-15 15:35:05 -07001574 name: "AlertAfterChangeCipherSpec",
1575 config: Config{
1576 Bugs: ProtocolBugs{
1577 AlertAfterChangeCipherSpec: alertRecordOverflow,
1578 },
1579 },
1580 shouldFail: true,
1581 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1582 },
1583 {
1584 protocol: dtls,
1585 name: "AlertAfterChangeCipherSpec-DTLS",
1586 config: Config{
1587 Bugs: ProtocolBugs{
1588 AlertAfterChangeCipherSpec: alertRecordOverflow,
1589 },
1590 },
1591 shouldFail: true,
1592 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1593 },
1594 {
1595 protocol: dtls,
1596 name: "ReorderHandshakeFragments-Small-DTLS",
1597 config: Config{
1598 Bugs: ProtocolBugs{
1599 ReorderHandshakeFragments: true,
1600 // Small enough that every handshake message is
1601 // fragmented.
1602 MaxHandshakeRecordLength: 2,
1603 },
1604 },
1605 },
1606 {
1607 protocol: dtls,
1608 name: "ReorderHandshakeFragments-Large-DTLS",
1609 config: Config{
1610 Bugs: ProtocolBugs{
1611 ReorderHandshakeFragments: true,
1612 // Large enough that no handshake message is
1613 // fragmented.
1614 MaxHandshakeRecordLength: 2048,
1615 },
1616 },
1617 },
1618 {
1619 protocol: dtls,
1620 name: "MixCompleteMessageWithFragments-DTLS",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 ReorderHandshakeFragments: true,
1624 MixCompleteMessageWithFragments: true,
1625 MaxHandshakeRecordLength: 2,
1626 },
1627 },
1628 },
1629 {
1630 name: "SendInvalidRecordType",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 SendInvalidRecordType: true,
1634 },
1635 },
1636 shouldFail: true,
1637 expectedError: ":UNEXPECTED_RECORD:",
1638 },
1639 {
1640 protocol: dtls,
1641 name: "SendInvalidRecordType-DTLS",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 SendInvalidRecordType: true,
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 name: "FalseStart-SkipServerSecondLeg",
1652 config: Config{
1653 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1654 NextProtos: []string{"foo"},
1655 Bugs: ProtocolBugs{
1656 SkipNewSessionTicket: true,
1657 SkipChangeCipherSpec: true,
1658 SkipFinished: true,
1659 ExpectFalseStart: true,
1660 },
1661 },
1662 flags: []string{
1663 "-false-start",
1664 "-handshake-never-done",
1665 "-advertise-alpn", "\x03foo",
1666 },
1667 shimWritesFirst: true,
1668 shouldFail: true,
1669 expectedError: ":UNEXPECTED_RECORD:",
1670 },
1671 {
1672 name: "FalseStart-SkipServerSecondLeg-Implicit",
1673 config: Config{
1674 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1675 NextProtos: []string{"foo"},
1676 Bugs: ProtocolBugs{
1677 SkipNewSessionTicket: true,
1678 SkipChangeCipherSpec: true,
1679 SkipFinished: true,
1680 },
1681 },
1682 flags: []string{
1683 "-implicit-handshake",
1684 "-false-start",
1685 "-handshake-never-done",
1686 "-advertise-alpn", "\x03foo",
1687 },
1688 shouldFail: true,
1689 expectedError: ":UNEXPECTED_RECORD:",
1690 },
1691 {
1692 testType: serverTest,
1693 name: "FailEarlyCallback",
1694 flags: []string{"-fail-early-callback"},
1695 shouldFail: true,
1696 expectedError: ":CONNECTION_REJECTED:",
1697 expectedLocalError: "remote error: access denied",
1698 },
1699 {
1700 name: "WrongMessageType",
1701 config: Config{
1702 Bugs: ProtocolBugs{
1703 WrongCertificateMessageType: true,
1704 },
1705 },
1706 shouldFail: true,
1707 expectedError: ":UNEXPECTED_MESSAGE:",
1708 expectedLocalError: "remote error: unexpected message",
1709 },
1710 {
1711 protocol: dtls,
1712 name: "WrongMessageType-DTLS",
1713 config: Config{
1714 Bugs: ProtocolBugs{
1715 WrongCertificateMessageType: true,
1716 },
1717 },
1718 shouldFail: true,
1719 expectedError: ":UNEXPECTED_MESSAGE:",
1720 expectedLocalError: "remote error: unexpected message",
1721 },
1722 {
1723 protocol: dtls,
1724 name: "FragmentMessageTypeMismatch-DTLS",
1725 config: Config{
1726 Bugs: ProtocolBugs{
1727 MaxHandshakeRecordLength: 2,
1728 FragmentMessageTypeMismatch: true,
1729 },
1730 },
1731 shouldFail: true,
1732 expectedError: ":FRAGMENT_MISMATCH:",
1733 },
1734 {
1735 protocol: dtls,
1736 name: "FragmentMessageLengthMismatch-DTLS",
1737 config: Config{
1738 Bugs: ProtocolBugs{
1739 MaxHandshakeRecordLength: 2,
1740 FragmentMessageLengthMismatch: true,
1741 },
1742 },
1743 shouldFail: true,
1744 expectedError: ":FRAGMENT_MISMATCH:",
1745 },
1746 {
1747 protocol: dtls,
1748 name: "SplitFragments-Header-DTLS",
1749 config: Config{
1750 Bugs: ProtocolBugs{
1751 SplitFragments: 2,
1752 },
1753 },
1754 shouldFail: true,
1755 expectedError: ":UNEXPECTED_MESSAGE:",
1756 },
1757 {
1758 protocol: dtls,
1759 name: "SplitFragments-Boundary-DTLS",
1760 config: Config{
1761 Bugs: ProtocolBugs{
1762 SplitFragments: dtlsRecordHeaderLen,
1763 },
1764 },
1765 shouldFail: true,
1766 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1767 },
1768 {
1769 protocol: dtls,
1770 name: "SplitFragments-Body-DTLS",
1771 config: Config{
1772 Bugs: ProtocolBugs{
1773 SplitFragments: dtlsRecordHeaderLen + 1,
1774 },
1775 },
1776 shouldFail: true,
1777 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1778 },
1779 {
1780 protocol: dtls,
1781 name: "SendEmptyFragments-DTLS",
1782 config: Config{
1783 Bugs: ProtocolBugs{
1784 SendEmptyFragments: true,
1785 },
1786 },
1787 },
1788 {
1789 name: "UnsupportedCipherSuite",
1790 config: Config{
1791 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1792 Bugs: ProtocolBugs{
1793 IgnorePeerCipherPreferences: true,
1794 },
1795 },
1796 flags: []string{"-cipher", "DEFAULT:!RC4"},
1797 shouldFail: true,
1798 expectedError: ":WRONG_CIPHER_RETURNED:",
1799 },
1800 {
1801 name: "UnsupportedCurve",
1802 config: Config{
David Benjamin64d92502015-12-19 02:20:57 -05001803 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1804 CurvePreferences: []CurveID{CurveP256},
Adam Langley7c803a62015-06-15 15:35:05 -07001805 Bugs: ProtocolBugs{
1806 IgnorePeerCurvePreferences: true,
1807 },
1808 },
David Benjamin64d92502015-12-19 02:20:57 -05001809 flags: []string{"-p384-only"},
Adam Langley7c803a62015-06-15 15:35:05 -07001810 shouldFail: true,
1811 expectedError: ":WRONG_CURVE:",
1812 },
1813 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001814 name: "BadFinished-Client",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 BadFinished: true,
1818 },
1819 },
1820 shouldFail: true,
1821 expectedError: ":DIGEST_CHECK_FAILED:",
1822 },
1823 {
1824 testType: serverTest,
1825 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001826 config: Config{
1827 Bugs: ProtocolBugs{
1828 BadFinished: true,
1829 },
1830 },
1831 shouldFail: true,
1832 expectedError: ":DIGEST_CHECK_FAILED:",
1833 },
1834 {
1835 name: "FalseStart-BadFinished",
1836 config: Config{
1837 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1838 NextProtos: []string{"foo"},
1839 Bugs: ProtocolBugs{
1840 BadFinished: true,
1841 ExpectFalseStart: true,
1842 },
1843 },
1844 flags: []string{
1845 "-false-start",
1846 "-handshake-never-done",
1847 "-advertise-alpn", "\x03foo",
1848 },
1849 shimWritesFirst: true,
1850 shouldFail: true,
1851 expectedError: ":DIGEST_CHECK_FAILED:",
1852 },
1853 {
1854 name: "NoFalseStart-NoALPN",
1855 config: Config{
1856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1857 Bugs: ProtocolBugs{
1858 ExpectFalseStart: true,
1859 AlertBeforeFalseStartTest: alertAccessDenied,
1860 },
1861 },
1862 flags: []string{
1863 "-false-start",
1864 },
1865 shimWritesFirst: true,
1866 shouldFail: true,
1867 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1868 expectedLocalError: "tls: peer did not false start: EOF",
1869 },
1870 {
1871 name: "NoFalseStart-NoAEAD",
1872 config: Config{
1873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1874 NextProtos: []string{"foo"},
1875 Bugs: ProtocolBugs{
1876 ExpectFalseStart: true,
1877 AlertBeforeFalseStartTest: alertAccessDenied,
1878 },
1879 },
1880 flags: []string{
1881 "-false-start",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1887 expectedLocalError: "tls: peer did not false start: EOF",
1888 },
1889 {
1890 name: "NoFalseStart-RSA",
1891 config: Config{
1892 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1893 NextProtos: []string{"foo"},
1894 Bugs: ProtocolBugs{
1895 ExpectFalseStart: true,
1896 AlertBeforeFalseStartTest: alertAccessDenied,
1897 },
1898 },
1899 flags: []string{
1900 "-false-start",
1901 "-advertise-alpn", "\x03foo",
1902 },
1903 shimWritesFirst: true,
1904 shouldFail: true,
1905 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1906 expectedLocalError: "tls: peer did not false start: EOF",
1907 },
1908 {
1909 name: "NoFalseStart-DHE_RSA",
1910 config: Config{
1911 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1912 NextProtos: []string{"foo"},
1913 Bugs: ProtocolBugs{
1914 ExpectFalseStart: true,
1915 AlertBeforeFalseStartTest: alertAccessDenied,
1916 },
1917 },
1918 flags: []string{
1919 "-false-start",
1920 "-advertise-alpn", "\x03foo",
1921 },
1922 shimWritesFirst: true,
1923 shouldFail: true,
1924 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1925 expectedLocalError: "tls: peer did not false start: EOF",
1926 },
1927 {
1928 testType: serverTest,
1929 name: "NoSupportedCurves",
1930 config: Config{
1931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1932 Bugs: ProtocolBugs{
1933 NoSupportedCurves: true,
1934 },
1935 },
David Benjamin4298d772015-12-19 00:18:25 -05001936 shouldFail: true,
1937 expectedError: ":NO_SHARED_CIPHER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001938 },
1939 {
1940 testType: serverTest,
1941 name: "NoCommonCurves",
1942 config: Config{
1943 CipherSuites: []uint16{
1944 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1945 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1946 },
1947 CurvePreferences: []CurveID{CurveP224},
1948 },
1949 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1950 },
1951 {
1952 protocol: dtls,
1953 name: "SendSplitAlert-Sync",
1954 config: Config{
1955 Bugs: ProtocolBugs{
1956 SendSplitAlert: true,
1957 },
1958 },
1959 },
1960 {
1961 protocol: dtls,
1962 name: "SendSplitAlert-Async",
1963 config: Config{
1964 Bugs: ProtocolBugs{
1965 SendSplitAlert: true,
1966 },
1967 },
1968 flags: []string{"-async"},
1969 },
1970 {
1971 protocol: dtls,
1972 name: "PackDTLSHandshake",
1973 config: Config{
1974 Bugs: ProtocolBugs{
1975 MaxHandshakeRecordLength: 2,
1976 PackHandshakeFragments: 20,
1977 PackHandshakeRecords: 200,
1978 },
1979 },
1980 },
1981 {
1982 testType: serverTest,
1983 protocol: dtls,
1984 name: "NoRC4-DTLS",
1985 config: Config{
1986 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1987 Bugs: ProtocolBugs{
1988 EnableAllCiphersInDTLS: true,
1989 },
1990 },
1991 shouldFail: true,
1992 expectedError: ":NO_SHARED_CIPHER:",
1993 },
1994 {
1995 name: "SendEmptyRecords-Pass",
1996 sendEmptyRecords: 32,
1997 },
1998 {
1999 name: "SendEmptyRecords",
2000 sendEmptyRecords: 33,
2001 shouldFail: true,
2002 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2003 },
2004 {
2005 name: "SendEmptyRecords-Async",
2006 sendEmptyRecords: 33,
2007 flags: []string{"-async"},
2008 shouldFail: true,
2009 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2010 },
2011 {
2012 name: "SendWarningAlerts-Pass",
2013 sendWarningAlerts: 4,
2014 },
2015 {
2016 protocol: dtls,
2017 name: "SendWarningAlerts-DTLS-Pass",
2018 sendWarningAlerts: 4,
2019 },
2020 {
2021 name: "SendWarningAlerts",
2022 sendWarningAlerts: 5,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2025 },
2026 {
2027 name: "SendWarningAlerts-Async",
2028 sendWarningAlerts: 5,
2029 flags: []string{"-async"},
2030 shouldFail: true,
2031 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2032 },
David Benjaminba4594a2015-06-18 18:36:15 -04002033 {
2034 name: "EmptySessionID",
2035 config: Config{
2036 SessionTicketsDisabled: true,
2037 },
2038 noSessionCache: true,
2039 flags: []string{"-expect-no-session"},
2040 },
David Benjamin30789da2015-08-29 22:56:45 -04002041 {
2042 name: "Unclean-Shutdown",
2043 config: Config{
2044 Bugs: ProtocolBugs{
2045 NoCloseNotify: true,
2046 ExpectCloseNotify: true,
2047 },
2048 },
2049 shimShutsDown: true,
2050 flags: []string{"-check-close-notify"},
2051 shouldFail: true,
2052 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2053 },
2054 {
2055 name: "Unclean-Shutdown-Ignored",
2056 config: Config{
2057 Bugs: ProtocolBugs{
2058 NoCloseNotify: true,
2059 },
2060 },
2061 shimShutsDown: true,
2062 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002063 {
2064 name: "LargePlaintext",
2065 config: Config{
2066 Bugs: ProtocolBugs{
2067 SendLargeRecords: true,
2068 },
2069 },
2070 messageLen: maxPlaintext + 1,
2071 shouldFail: true,
2072 expectedError: ":DATA_LENGTH_TOO_LONG:",
2073 },
2074 {
2075 protocol: dtls,
2076 name: "LargePlaintext-DTLS",
2077 config: Config{
2078 Bugs: ProtocolBugs{
2079 SendLargeRecords: true,
2080 },
2081 },
2082 messageLen: maxPlaintext + 1,
2083 shouldFail: true,
2084 expectedError: ":DATA_LENGTH_TOO_LONG:",
2085 },
2086 {
2087 name: "LargeCiphertext",
2088 config: Config{
2089 Bugs: ProtocolBugs{
2090 SendLargeRecords: true,
2091 },
2092 },
2093 messageLen: maxPlaintext * 2,
2094 shouldFail: true,
2095 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2096 },
2097 {
2098 protocol: dtls,
2099 name: "LargeCiphertext-DTLS",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 SendLargeRecords: true,
2103 },
2104 },
2105 messageLen: maxPlaintext * 2,
2106 // Unlike the other four cases, DTLS drops records which
2107 // are invalid before authentication, so the connection
2108 // does not fail.
2109 expectMessageDropped: true,
2110 },
David Benjamindd6fed92015-10-23 17:41:12 -04002111 {
2112 name: "SendEmptySessionTicket",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendEmptySessionTicket: true,
2116 FailIfSessionOffered: true,
2117 },
2118 },
2119 flags: []string{"-expect-no-session"},
2120 resumeSession: true,
2121 expectResumeRejected: true,
2122 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002123 {
2124 name: "CheckLeafCurve",
2125 config: Config{
2126 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2127 Certificates: []Certificate{getECDSACertificate()},
2128 },
2129 flags: []string{"-p384-only"},
2130 shouldFail: true,
2131 expectedError: ":BAD_ECC_CERT:",
2132 },
David Benjamin8411b242015-11-26 12:07:28 -05002133 {
2134 name: "BadChangeCipherSpec-1",
2135 config: Config{
2136 Bugs: ProtocolBugs{
2137 BadChangeCipherSpec: []byte{2},
2138 },
2139 },
2140 shouldFail: true,
2141 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2142 },
2143 {
2144 name: "BadChangeCipherSpec-2",
2145 config: Config{
2146 Bugs: ProtocolBugs{
2147 BadChangeCipherSpec: []byte{1, 1},
2148 },
2149 },
2150 shouldFail: true,
2151 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2152 },
2153 {
2154 protocol: dtls,
2155 name: "BadChangeCipherSpec-DTLS-1",
2156 config: Config{
2157 Bugs: ProtocolBugs{
2158 BadChangeCipherSpec: []byte{2},
2159 },
2160 },
2161 shouldFail: true,
2162 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2163 },
2164 {
2165 protocol: dtls,
2166 name: "BadChangeCipherSpec-DTLS-2",
2167 config: Config{
2168 Bugs: ProtocolBugs{
2169 BadChangeCipherSpec: []byte{1, 1},
2170 },
2171 },
2172 shouldFail: true,
2173 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2174 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002175 {
2176 name: "BadHelloRequest-1",
2177 renegotiate: 1,
2178 config: Config{
2179 Bugs: ProtocolBugs{
2180 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2181 },
2182 },
2183 flags: []string{
2184 "-renegotiate-freely",
2185 "-expect-total-renegotiations", "1",
2186 },
2187 shouldFail: true,
2188 expectedError: ":BAD_HELLO_REQUEST:",
2189 },
2190 {
2191 name: "BadHelloRequest-2",
2192 renegotiate: 1,
2193 config: Config{
2194 Bugs: ProtocolBugs{
2195 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2196 },
2197 },
2198 flags: []string{
2199 "-renegotiate-freely",
2200 "-expect-total-renegotiations", "1",
2201 },
2202 shouldFail: true,
2203 expectedError: ":BAD_HELLO_REQUEST:",
2204 },
David Benjaminef1b0092015-11-21 14:05:44 -05002205 {
2206 testType: serverTest,
2207 name: "SupportTicketsWithSessionID",
2208 config: Config{
2209 SessionTicketsDisabled: true,
2210 },
2211 resumeConfig: &Config{},
2212 resumeSession: true,
2213 },
David Benjamin2b07fa42016-03-02 00:23:57 -05002214 {
2215 name: "InvalidECDHPoint-Client",
2216 config: Config{
2217 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2218 CurvePreferences: []CurveID{CurveP256},
2219 Bugs: ProtocolBugs{
2220 InvalidECDHPoint: true,
2221 },
2222 },
2223 shouldFail: true,
2224 expectedError: ":INVALID_ENCODING:",
2225 },
2226 {
2227 testType: serverTest,
2228 name: "InvalidECDHPoint-Server",
2229 config: Config{
2230 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2231 CurvePreferences: []CurveID{CurveP256},
2232 Bugs: ProtocolBugs{
2233 InvalidECDHPoint: true,
2234 },
2235 },
2236 shouldFail: true,
2237 expectedError: ":INVALID_ENCODING:",
2238 },
Adam Langley7c803a62015-06-15 15:35:05 -07002239 }
Adam Langley7c803a62015-06-15 15:35:05 -07002240 testCases = append(testCases, basicTests...)
2241}
2242
Adam Langley95c29f32014-06-20 12:00:00 -07002243func addCipherSuiteTests() {
2244 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002245 const psk = "12345"
2246 const pskIdentity = "luggage combo"
2247
Adam Langley95c29f32014-06-20 12:00:00 -07002248 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002249 var certFile string
2250 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002251 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002252 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002253 certFile = ecdsaCertificateFile
2254 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002255 } else {
2256 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002257 certFile = rsaCertificateFile
2258 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002259 }
2260
David Benjamin48cae082014-10-27 01:06:24 -04002261 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002262 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002263 flags = append(flags,
2264 "-psk", psk,
2265 "-psk-identity", pskIdentity)
2266 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002267 if hasComponent(suite.name, "NULL") {
2268 // NULL ciphers must be explicitly enabled.
2269 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2270 }
David Benjamin48cae082014-10-27 01:06:24 -04002271
Adam Langley95c29f32014-06-20 12:00:00 -07002272 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002273 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002274 continue
2275 }
2276
David Benjamin4298d772015-12-19 00:18:25 -05002277 shouldFail := isTLSOnly(suite.name) && ver.version == VersionSSL30
2278
2279 expectedError := ""
2280 if shouldFail {
2281 expectedError = ":NO_SHARED_CIPHER:"
2282 }
David Benjamin025b3d32014-07-01 19:53:04 -04002283
David Benjamin76d8abe2014-08-14 16:25:34 -04002284 testCases = append(testCases, testCase{
2285 testType: serverTest,
2286 name: ver.name + "-" + suite.name + "-server",
2287 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002288 MinVersion: ver.version,
2289 MaxVersion: ver.version,
2290 CipherSuites: []uint16{suite.id},
2291 Certificates: []Certificate{cert},
2292 PreSharedKey: []byte(psk),
2293 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002294 },
2295 certFile: certFile,
2296 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002297 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002298 resumeSession: true,
David Benjamin4298d772015-12-19 00:18:25 -05002299 shouldFail: shouldFail,
2300 expectedError: expectedError,
2301 })
2302
2303 if shouldFail {
2304 continue
2305 }
2306
2307 testCases = append(testCases, testCase{
2308 testType: clientTest,
2309 name: ver.name + "-" + suite.name + "-client",
2310 config: Config{
2311 MinVersion: ver.version,
2312 MaxVersion: ver.version,
2313 CipherSuites: []uint16{suite.id},
2314 Certificates: []Certificate{cert},
2315 PreSharedKey: []byte(psk),
2316 PreSharedKeyIdentity: pskIdentity,
2317 },
2318 flags: flags,
2319 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002320 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002321
David Benjamin8b8c0062014-11-23 02:47:52 -05002322 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002323 testCases = append(testCases, testCase{
2324 testType: clientTest,
2325 protocol: dtls,
2326 name: "D" + ver.name + "-" + suite.name + "-client",
2327 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002328 MinVersion: ver.version,
2329 MaxVersion: ver.version,
2330 CipherSuites: []uint16{suite.id},
2331 Certificates: []Certificate{cert},
2332 PreSharedKey: []byte(psk),
2333 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002334 },
David Benjamin48cae082014-10-27 01:06:24 -04002335 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002336 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002337 })
2338 testCases = append(testCases, testCase{
2339 testType: serverTest,
2340 protocol: dtls,
2341 name: "D" + ver.name + "-" + suite.name + "-server",
2342 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002343 MinVersion: ver.version,
2344 MaxVersion: ver.version,
2345 CipherSuites: []uint16{suite.id},
2346 Certificates: []Certificate{cert},
2347 PreSharedKey: []byte(psk),
2348 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002349 },
2350 certFile: certFile,
2351 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002352 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002353 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002354 })
2355 }
Adam Langley95c29f32014-06-20 12:00:00 -07002356 }
David Benjamin2c99d282015-09-01 10:23:00 -04002357
2358 // Ensure both TLS and DTLS accept their maximum record sizes.
2359 testCases = append(testCases, testCase{
2360 name: suite.name + "-LargeRecord",
2361 config: Config{
2362 CipherSuites: []uint16{suite.id},
2363 Certificates: []Certificate{cert},
2364 PreSharedKey: []byte(psk),
2365 PreSharedKeyIdentity: pskIdentity,
2366 },
2367 flags: flags,
2368 messageLen: maxPlaintext,
2369 })
David Benjamin2c99d282015-09-01 10:23:00 -04002370 if isDTLSCipher(suite.name) {
2371 testCases = append(testCases, testCase{
2372 protocol: dtls,
2373 name: suite.name + "-LargeRecord-DTLS",
2374 config: Config{
2375 CipherSuites: []uint16{suite.id},
2376 Certificates: []Certificate{cert},
2377 PreSharedKey: []byte(psk),
2378 PreSharedKeyIdentity: pskIdentity,
2379 },
2380 flags: flags,
2381 messageLen: maxPlaintext,
2382 })
2383 }
Adam Langley95c29f32014-06-20 12:00:00 -07002384 }
Adam Langleya7997f12015-05-14 17:38:50 -07002385
2386 testCases = append(testCases, testCase{
2387 name: "WeakDH",
2388 config: Config{
2389 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2390 Bugs: ProtocolBugs{
2391 // This is a 1023-bit prime number, generated
2392 // with:
2393 // openssl gendh 1023 | openssl asn1parse -i
2394 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2395 },
2396 },
2397 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002398 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002399 })
Adam Langleycef75832015-09-03 14:51:12 -07002400
David Benjamincd24a392015-11-11 13:23:05 -08002401 testCases = append(testCases, testCase{
2402 name: "SillyDH",
2403 config: Config{
2404 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2405 Bugs: ProtocolBugs{
2406 // This is a 4097-bit prime number, generated
2407 // with:
2408 // openssl gendh 4097 | openssl asn1parse -i
2409 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2410 },
2411 },
2412 shouldFail: true,
2413 expectedError: ":DH_P_TOO_LONG:",
2414 })
2415
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002416 // This test ensures that Diffie-Hellman public values are padded with
2417 // zeros so that they're the same length as the prime. This is to avoid
2418 // hitting a bug in yaSSL.
2419 testCases = append(testCases, testCase{
2420 testType: serverTest,
2421 name: "DHPublicValuePadded",
2422 config: Config{
2423 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2424 Bugs: ProtocolBugs{
2425 RequireDHPublicValueLen: (1025 + 7) / 8,
2426 },
2427 },
2428 flags: []string{"-use-sparse-dh-prime"},
2429 })
David Benjamincd24a392015-11-11 13:23:05 -08002430
David Benjamin241ae832016-01-15 03:04:54 -05002431 // The server must be tolerant to bogus ciphers.
2432 const bogusCipher = 0x1234
2433 testCases = append(testCases, testCase{
2434 testType: serverTest,
2435 name: "UnknownCipher",
2436 config: Config{
2437 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2438 },
2439 })
2440
Adam Langleycef75832015-09-03 14:51:12 -07002441 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2442 // 1.1 specific cipher suite settings. A server is setup with the given
2443 // cipher lists and then a connection is made for each member of
2444 // expectations. The cipher suite that the server selects must match
2445 // the specified one.
2446 var versionSpecificCiphersTest = []struct {
2447 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2448 // expectations is a map from TLS version to cipher suite id.
2449 expectations map[uint16]uint16
2450 }{
2451 {
2452 // Test that the null case (where no version-specific ciphers are set)
2453 // works as expected.
2454 "RC4-SHA:AES128-SHA", // default ciphers
2455 "", // no ciphers specifically for TLS ≥ 1.0
2456 "", // no ciphers specifically for TLS ≥ 1.1
2457 map[uint16]uint16{
2458 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2459 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2460 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2461 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2462 },
2463 },
2464 {
2465 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2466 // cipher.
2467 "RC4-SHA:AES128-SHA", // default
2468 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2469 "", // no ciphers specifically for TLS ≥ 1.1
2470 map[uint16]uint16{
2471 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2472 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2473 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2474 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2475 },
2476 },
2477 {
2478 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2479 // cipher.
2480 "RC4-SHA:AES128-SHA", // default
2481 "", // no ciphers specifically for TLS ≥ 1.0
2482 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2483 map[uint16]uint16{
2484 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2485 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2486 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2487 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2488 },
2489 },
2490 {
2491 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2492 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2493 "RC4-SHA:AES128-SHA", // default
2494 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2495 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2496 map[uint16]uint16{
2497 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2498 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2499 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2500 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2501 },
2502 },
2503 }
2504
2505 for i, test := range versionSpecificCiphersTest {
2506 for version, expectedCipherSuite := range test.expectations {
2507 flags := []string{"-cipher", test.ciphersDefault}
2508 if len(test.ciphersTLS10) > 0 {
2509 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2510 }
2511 if len(test.ciphersTLS11) > 0 {
2512 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2513 }
2514
2515 testCases = append(testCases, testCase{
2516 testType: serverTest,
2517 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2518 config: Config{
2519 MaxVersion: version,
2520 MinVersion: version,
2521 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2522 },
2523 flags: flags,
2524 expectedCipher: expectedCipherSuite,
2525 })
2526 }
2527 }
Adam Langley95c29f32014-06-20 12:00:00 -07002528}
2529
2530func addBadECDSASignatureTests() {
2531 for badR := BadValue(1); badR < NumBadValues; badR++ {
2532 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002533 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002534 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2535 config: Config{
2536 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2537 Certificates: []Certificate{getECDSACertificate()},
2538 Bugs: ProtocolBugs{
2539 BadECDSAR: badR,
2540 BadECDSAS: badS,
2541 },
2542 },
2543 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002544 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002545 })
2546 }
2547 }
2548}
2549
Adam Langley80842bd2014-06-20 12:00:00 -07002550func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002551 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002552 name: "MaxCBCPadding",
2553 config: Config{
2554 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2555 Bugs: ProtocolBugs{
2556 MaxPadding: true,
2557 },
2558 },
2559 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2560 })
David Benjamin025b3d32014-07-01 19:53:04 -04002561 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002562 name: "BadCBCPadding",
2563 config: Config{
2564 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2565 Bugs: ProtocolBugs{
2566 PaddingFirstByteBad: true,
2567 },
2568 },
2569 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002570 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002571 })
2572 // OpenSSL previously had an issue where the first byte of padding in
2573 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002574 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002575 name: "BadCBCPadding255",
2576 config: Config{
2577 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2578 Bugs: ProtocolBugs{
2579 MaxPadding: true,
2580 PaddingFirstByteBadIf255: true,
2581 },
2582 },
2583 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2584 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002585 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002586 })
2587}
2588
Kenny Root7fdeaf12014-08-05 15:23:37 -07002589func addCBCSplittingTests() {
2590 testCases = append(testCases, testCase{
2591 name: "CBCRecordSplitting",
2592 config: Config{
2593 MaxVersion: VersionTLS10,
2594 MinVersion: VersionTLS10,
2595 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2596 },
David Benjaminac8302a2015-09-01 17:18:15 -04002597 messageLen: -1, // read until EOF
2598 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002599 flags: []string{
2600 "-async",
2601 "-write-different-record-sizes",
2602 "-cbc-record-splitting",
2603 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002604 })
2605 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002606 name: "CBCRecordSplittingPartialWrite",
2607 config: Config{
2608 MaxVersion: VersionTLS10,
2609 MinVersion: VersionTLS10,
2610 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2611 },
2612 messageLen: -1, // read until EOF
2613 flags: []string{
2614 "-async",
2615 "-write-different-record-sizes",
2616 "-cbc-record-splitting",
2617 "-partial-write",
2618 },
2619 })
2620}
2621
David Benjamin636293b2014-07-08 17:59:18 -04002622func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002623 // Add a dummy cert pool to stress certificate authority parsing.
2624 // TODO(davidben): Add tests that those values parse out correctly.
2625 certPool := x509.NewCertPool()
2626 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2627 if err != nil {
2628 panic(err)
2629 }
2630 certPool.AddCert(cert)
2631
David Benjamin636293b2014-07-08 17:59:18 -04002632 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002633 testCases = append(testCases, testCase{
2634 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002635 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002636 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002637 MinVersion: ver.version,
2638 MaxVersion: ver.version,
2639 ClientAuth: RequireAnyClientCert,
2640 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002641 },
2642 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002643 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2644 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002645 },
2646 })
2647 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002648 testType: serverTest,
2649 name: ver.name + "-Server-ClientAuth-RSA",
2650 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002651 MinVersion: ver.version,
2652 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002653 Certificates: []Certificate{rsaCertificate},
2654 },
2655 flags: []string{"-require-any-client-certificate"},
2656 })
David Benjamine098ec22014-08-27 23:13:20 -04002657 if ver.version != VersionSSL30 {
2658 testCases = append(testCases, testCase{
2659 testType: serverTest,
2660 name: ver.name + "-Server-ClientAuth-ECDSA",
2661 config: Config{
2662 MinVersion: ver.version,
2663 MaxVersion: ver.version,
2664 Certificates: []Certificate{ecdsaCertificate},
2665 },
2666 flags: []string{"-require-any-client-certificate"},
2667 })
2668 testCases = append(testCases, testCase{
2669 testType: clientTest,
2670 name: ver.name + "-Client-ClientAuth-ECDSA",
2671 config: Config{
2672 MinVersion: ver.version,
2673 MaxVersion: ver.version,
2674 ClientAuth: RequireAnyClientCert,
2675 ClientCAs: certPool,
2676 },
2677 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002678 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2679 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002680 },
2681 })
2682 }
David Benjamin636293b2014-07-08 17:59:18 -04002683 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002684
2685 testCases = append(testCases, testCase{
2686 testType: serverTest,
2687 name: "RequireAnyClientCertificate",
2688 flags: []string{"-require-any-client-certificate"},
2689 shouldFail: true,
2690 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2691 })
2692
2693 testCases = append(testCases, testCase{
2694 testType: serverTest,
David Benjamindf28c3a2016-03-10 16:11:51 -05002695 name: "RequireAnyClientCertificate-SSL3",
2696 config: Config{
2697 MaxVersion: VersionSSL30,
2698 },
2699 flags: []string{"-require-any-client-certificate"},
2700 shouldFail: true,
2701 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2702 })
2703
2704 testCases = append(testCases, testCase{
2705 testType: serverTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002706 name: "SkipClientCertificate",
2707 config: Config{
2708 Bugs: ProtocolBugs{
2709 SkipClientCertificate: true,
2710 },
2711 },
2712 // Setting SSL_VERIFY_PEER allows anonymous clients.
2713 flags: []string{"-verify-peer"},
2714 shouldFail: true,
David Benjamindf28c3a2016-03-10 16:11:51 -05002715 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002716 })
David Benjamin636293b2014-07-08 17:59:18 -04002717}
2718
Adam Langley75712922014-10-10 16:23:43 -07002719func addExtendedMasterSecretTests() {
2720 const expectEMSFlag = "-expect-extended-master-secret"
2721
2722 for _, with := range []bool{false, true} {
2723 prefix := "No"
2724 var flags []string
2725 if with {
2726 prefix = ""
2727 flags = []string{expectEMSFlag}
2728 }
2729
2730 for _, isClient := range []bool{false, true} {
2731 suffix := "-Server"
2732 testType := serverTest
2733 if isClient {
2734 suffix = "-Client"
2735 testType = clientTest
2736 }
2737
2738 for _, ver := range tlsVersions {
2739 test := testCase{
2740 testType: testType,
2741 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2742 config: Config{
2743 MinVersion: ver.version,
2744 MaxVersion: ver.version,
2745 Bugs: ProtocolBugs{
2746 NoExtendedMasterSecret: !with,
2747 RequireExtendedMasterSecret: with,
2748 },
2749 },
David Benjamin48cae082014-10-27 01:06:24 -04002750 flags: flags,
2751 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002752 }
2753 if test.shouldFail {
2754 test.expectedLocalError = "extended master secret required but not supported by peer"
2755 }
2756 testCases = append(testCases, test)
2757 }
2758 }
2759 }
2760
Adam Langleyba5934b2015-06-02 10:50:35 -07002761 for _, isClient := range []bool{false, true} {
2762 for _, supportedInFirstConnection := range []bool{false, true} {
2763 for _, supportedInResumeConnection := range []bool{false, true} {
2764 boolToWord := func(b bool) string {
2765 if b {
2766 return "Yes"
2767 }
2768 return "No"
2769 }
2770 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2771 if isClient {
2772 suffix += "Client"
2773 } else {
2774 suffix += "Server"
2775 }
2776
2777 supportedConfig := Config{
2778 Bugs: ProtocolBugs{
2779 RequireExtendedMasterSecret: true,
2780 },
2781 }
2782
2783 noSupportConfig := Config{
2784 Bugs: ProtocolBugs{
2785 NoExtendedMasterSecret: true,
2786 },
2787 }
2788
2789 test := testCase{
2790 name: "ExtendedMasterSecret-" + suffix,
2791 resumeSession: true,
2792 }
2793
2794 if !isClient {
2795 test.testType = serverTest
2796 }
2797
2798 if supportedInFirstConnection {
2799 test.config = supportedConfig
2800 } else {
2801 test.config = noSupportConfig
2802 }
2803
2804 if supportedInResumeConnection {
2805 test.resumeConfig = &supportedConfig
2806 } else {
2807 test.resumeConfig = &noSupportConfig
2808 }
2809
2810 switch suffix {
2811 case "YesToYes-Client", "YesToYes-Server":
2812 // When a session is resumed, it should
2813 // still be aware that its master
2814 // secret was generated via EMS and
2815 // thus it's safe to use tls-unique.
2816 test.flags = []string{expectEMSFlag}
2817 case "NoToYes-Server":
2818 // If an original connection did not
2819 // contain EMS, but a resumption
2820 // handshake does, then a server should
2821 // not resume the session.
2822 test.expectResumeRejected = true
2823 case "YesToNo-Server":
2824 // Resuming an EMS session without the
2825 // EMS extension should cause the
2826 // server to abort the connection.
2827 test.shouldFail = true
2828 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2829 case "NoToYes-Client":
2830 // A client should abort a connection
2831 // where the server resumed a non-EMS
2832 // session but echoed the EMS
2833 // extension.
2834 test.shouldFail = true
2835 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2836 case "YesToNo-Client":
2837 // A client should abort a connection
2838 // where the server didn't echo EMS
2839 // when the session used it.
2840 test.shouldFail = true
2841 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2842 }
2843
2844 testCases = append(testCases, test)
2845 }
2846 }
2847 }
Adam Langley75712922014-10-10 16:23:43 -07002848}
2849
David Benjamin43ec06f2014-08-05 02:28:57 -04002850// Adds tests that try to cover the range of the handshake state machine, under
2851// various conditions. Some of these are redundant with other tests, but they
2852// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002853func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002854 var tests []testCase
2855
2856 // Basic handshake, with resumption. Client and server,
2857 // session ID and session ticket.
2858 tests = append(tests, testCase{
2859 name: "Basic-Client",
2860 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05002861 // Ensure session tickets are used, not session IDs.
2862 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04002863 })
2864 tests = append(tests, testCase{
2865 name: "Basic-Client-RenewTicket",
2866 config: Config{
2867 Bugs: ProtocolBugs{
2868 RenewTicketOnResume: true,
2869 },
2870 },
David Benjaminba4594a2015-06-18 18:36:15 -04002871 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002872 resumeSession: true,
2873 })
2874 tests = append(tests, testCase{
2875 name: "Basic-Client-NoTicket",
2876 config: Config{
2877 SessionTicketsDisabled: true,
2878 },
2879 resumeSession: true,
2880 })
2881 tests = append(tests, testCase{
2882 name: "Basic-Client-Implicit",
2883 flags: []string{"-implicit-handshake"},
2884 resumeSession: true,
2885 })
2886 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05002887 testType: serverTest,
2888 name: "Basic-Server",
2889 config: Config{
2890 Bugs: ProtocolBugs{
2891 RequireSessionTickets: true,
2892 },
2893 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002894 resumeSession: true,
2895 })
2896 tests = append(tests, testCase{
2897 testType: serverTest,
2898 name: "Basic-Server-NoTickets",
2899 config: Config{
2900 SessionTicketsDisabled: true,
2901 },
2902 resumeSession: true,
2903 })
2904 tests = append(tests, testCase{
2905 testType: serverTest,
2906 name: "Basic-Server-Implicit",
2907 flags: []string{"-implicit-handshake"},
2908 resumeSession: true,
2909 })
2910 tests = append(tests, testCase{
2911 testType: serverTest,
2912 name: "Basic-Server-EarlyCallback",
2913 flags: []string{"-use-early-callback"},
2914 resumeSession: true,
2915 })
2916
2917 // TLS client auth.
2918 tests = append(tests, testCase{
2919 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002920 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05002921 config: Config{
2922 ClientAuth: RequestClientCert,
2923 },
2924 })
2925 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002926 testType: serverTest,
2927 name: "ClientAuth-NoCertificate-Server",
2928 // Setting SSL_VERIFY_PEER allows anonymous clients.
2929 flags: []string{"-verify-peer"},
2930 })
2931 if protocol == tls {
2932 tests = append(tests, testCase{
2933 testType: clientTest,
2934 name: "ClientAuth-NoCertificate-Client-SSL3",
2935 config: Config{
2936 MaxVersion: VersionSSL30,
2937 ClientAuth: RequestClientCert,
2938 },
2939 })
2940 tests = append(tests, testCase{
2941 testType: serverTest,
2942 name: "ClientAuth-NoCertificate-Server-SSL3",
2943 config: Config{
2944 MaxVersion: VersionSSL30,
2945 },
2946 // Setting SSL_VERIFY_PEER allows anonymous clients.
2947 flags: []string{"-verify-peer"},
2948 })
2949 }
2950 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05002951 testType: clientTest,
2952 name: "ClientAuth-NoCertificate-OldCallback",
2953 config: Config{
2954 ClientAuth: RequestClientCert,
2955 },
2956 flags: []string{"-use-old-client-cert-callback"},
2957 })
2958 tests = append(tests, testCase{
2959 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002960 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002961 config: Config{
2962 ClientAuth: RequireAnyClientCert,
2963 },
2964 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002965 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2966 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002967 },
2968 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002969 tests = append(tests, testCase{
2970 testType: clientTest,
2971 name: "ClientAuth-ECDSA-Client",
2972 config: Config{
2973 ClientAuth: RequireAnyClientCert,
2974 },
2975 flags: []string{
2976 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2977 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2978 },
2979 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05002980 tests = append(tests, testCase{
2981 testType: clientTest,
2982 name: "ClientAuth-OldCallback",
2983 config: Config{
2984 ClientAuth: RequireAnyClientCert,
2985 },
2986 flags: []string{
2987 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2988 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2989 "-use-old-client-cert-callback",
2990 },
2991 })
2992
David Benjaminb4d65fd2015-05-29 17:11:21 -04002993 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002994 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002995 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002996 testType: serverTest,
2997 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002998 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002999 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04003000 },
3001 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07003002 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3003 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04003004 },
3005 })
nagendra modadugu601448a2015-07-24 09:31:31 -07003006 tests = append(tests, testCase{
3007 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003008 name: "Basic-Server-ECDHE-RSA",
3009 config: Config{
3010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3011 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003012 flags: []string{
3013 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3014 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003015 },
3016 })
3017 tests = append(tests, testCase{
3018 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003019 name: "Basic-Server-ECDHE-ECDSA",
3020 config: Config{
3021 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3022 },
nagendra modadugu601448a2015-07-24 09:31:31 -07003023 flags: []string{
3024 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
3025 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07003026 },
3027 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04003028 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003029 tests = append(tests, testCase{
3030 testType: serverTest,
3031 name: "ClientAuth-Server",
3032 config: Config{
3033 Certificates: []Certificate{rsaCertificate},
3034 },
3035 flags: []string{"-require-any-client-certificate"},
3036 })
3037
3038 // No session ticket support; server doesn't send NewSessionTicket.
3039 tests = append(tests, testCase{
3040 name: "SessionTicketsDisabled-Client",
3041 config: Config{
3042 SessionTicketsDisabled: true,
3043 },
3044 })
3045 tests = append(tests, testCase{
3046 testType: serverTest,
3047 name: "SessionTicketsDisabled-Server",
3048 config: Config{
3049 SessionTicketsDisabled: true,
3050 },
3051 })
3052
3053 // Skip ServerKeyExchange in PSK key exchange if there's no
3054 // identity hint.
3055 tests = append(tests, testCase{
3056 name: "EmptyPSKHint-Client",
3057 config: Config{
3058 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3059 PreSharedKey: []byte("secret"),
3060 },
3061 flags: []string{"-psk", "secret"},
3062 })
3063 tests = append(tests, testCase{
3064 testType: serverTest,
3065 name: "EmptyPSKHint-Server",
3066 config: Config{
3067 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3068 PreSharedKey: []byte("secret"),
3069 },
3070 flags: []string{"-psk", "secret"},
3071 })
3072
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003073 tests = append(tests, testCase{
3074 testType: clientTest,
3075 name: "OCSPStapling-Client",
3076 flags: []string{
3077 "-enable-ocsp-stapling",
3078 "-expect-ocsp-response",
3079 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003080 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003081 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003082 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003083 })
3084
3085 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04003086 testType: serverTest,
3087 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003088 expectedOCSPResponse: testOCSPResponse,
3089 flags: []string{
3090 "-ocsp-response",
3091 base64.StdEncoding.EncodeToString(testOCSPResponse),
3092 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003093 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003094 })
3095
Paul Lietar8f1c2682015-08-18 12:21:54 +01003096 tests = append(tests, testCase{
3097 testType: clientTest,
3098 name: "CertificateVerificationSucceed",
3099 flags: []string{
3100 "-verify-peer",
3101 },
3102 })
3103
3104 tests = append(tests, testCase{
3105 testType: clientTest,
3106 name: "CertificateVerificationFail",
3107 flags: []string{
3108 "-verify-fail",
3109 "-verify-peer",
3110 },
3111 shouldFail: true,
3112 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3113 })
3114
3115 tests = append(tests, testCase{
3116 testType: clientTest,
3117 name: "CertificateVerificationSoftFail",
3118 flags: []string{
3119 "-verify-fail",
3120 "-expect-verify-result",
3121 },
3122 })
3123
David Benjamin760b1dd2015-05-15 23:33:48 -04003124 if protocol == tls {
3125 tests = append(tests, testCase{
3126 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003127 renegotiate: 1,
3128 flags: []string{
3129 "-renegotiate-freely",
3130 "-expect-total-renegotiations", "1",
3131 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003132 })
3133 // NPN on client and server; results in post-handshake message.
3134 tests = append(tests, testCase{
3135 name: "NPN-Client",
3136 config: Config{
3137 NextProtos: []string{"foo"},
3138 },
3139 flags: []string{"-select-next-proto", "foo"},
3140 expectedNextProto: "foo",
3141 expectedNextProtoType: npn,
3142 })
3143 tests = append(tests, testCase{
3144 testType: serverTest,
3145 name: "NPN-Server",
3146 config: Config{
3147 NextProtos: []string{"bar"},
3148 },
3149 flags: []string{
3150 "-advertise-npn", "\x03foo\x03bar\x03baz",
3151 "-expect-next-proto", "bar",
3152 },
3153 expectedNextProto: "bar",
3154 expectedNextProtoType: npn,
3155 })
3156
3157 // TODO(davidben): Add tests for when False Start doesn't trigger.
3158
3159 // Client does False Start and negotiates NPN.
3160 tests = append(tests, testCase{
3161 name: "FalseStart",
3162 config: Config{
3163 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3164 NextProtos: []string{"foo"},
3165 Bugs: ProtocolBugs{
3166 ExpectFalseStart: true,
3167 },
3168 },
3169 flags: []string{
3170 "-false-start",
3171 "-select-next-proto", "foo",
3172 },
3173 shimWritesFirst: true,
3174 resumeSession: true,
3175 })
3176
3177 // Client does False Start and negotiates ALPN.
3178 tests = append(tests, testCase{
3179 name: "FalseStart-ALPN",
3180 config: Config{
3181 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3182 NextProtos: []string{"foo"},
3183 Bugs: ProtocolBugs{
3184 ExpectFalseStart: true,
3185 },
3186 },
3187 flags: []string{
3188 "-false-start",
3189 "-advertise-alpn", "\x03foo",
3190 },
3191 shimWritesFirst: true,
3192 resumeSession: true,
3193 })
3194
3195 // Client does False Start but doesn't explicitly call
3196 // SSL_connect.
3197 tests = append(tests, testCase{
3198 name: "FalseStart-Implicit",
3199 config: Config{
3200 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3201 NextProtos: []string{"foo"},
3202 },
3203 flags: []string{
3204 "-implicit-handshake",
3205 "-false-start",
3206 "-advertise-alpn", "\x03foo",
3207 },
3208 })
3209
3210 // False Start without session tickets.
3211 tests = append(tests, testCase{
3212 name: "FalseStart-SessionTicketsDisabled",
3213 config: Config{
3214 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3215 NextProtos: []string{"foo"},
3216 SessionTicketsDisabled: true,
3217 Bugs: ProtocolBugs{
3218 ExpectFalseStart: true,
3219 },
3220 },
3221 flags: []string{
3222 "-false-start",
3223 "-select-next-proto", "foo",
3224 },
3225 shimWritesFirst: true,
3226 })
3227
3228 // Server parses a V2ClientHello.
3229 tests = append(tests, testCase{
3230 testType: serverTest,
3231 name: "SendV2ClientHello",
3232 config: Config{
3233 // Choose a cipher suite that does not involve
3234 // elliptic curves, so no extensions are
3235 // involved.
3236 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3237 Bugs: ProtocolBugs{
3238 SendV2ClientHello: true,
3239 },
3240 },
3241 })
3242
3243 // Client sends a Channel ID.
3244 tests = append(tests, testCase{
3245 name: "ChannelID-Client",
3246 config: Config{
3247 RequestChannelID: true,
3248 },
Adam Langley7c803a62015-06-15 15:35:05 -07003249 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003250 resumeSession: true,
3251 expectChannelID: true,
3252 })
3253
3254 // Server accepts a Channel ID.
3255 tests = append(tests, testCase{
3256 testType: serverTest,
3257 name: "ChannelID-Server",
3258 config: Config{
3259 ChannelID: channelIDKey,
3260 },
3261 flags: []string{
3262 "-expect-channel-id",
3263 base64.StdEncoding.EncodeToString(channelIDBytes),
3264 },
3265 resumeSession: true,
3266 expectChannelID: true,
3267 })
David Benjamin30789da2015-08-29 22:56:45 -04003268
3269 // Bidirectional shutdown with the runner initiating.
3270 tests = append(tests, testCase{
3271 name: "Shutdown-Runner",
3272 config: Config{
3273 Bugs: ProtocolBugs{
3274 ExpectCloseNotify: true,
3275 },
3276 },
3277 flags: []string{"-check-close-notify"},
3278 })
3279
3280 // Bidirectional shutdown with the shim initiating. The runner,
3281 // in the meantime, sends garbage before the close_notify which
3282 // the shim must ignore.
3283 tests = append(tests, testCase{
3284 name: "Shutdown-Shim",
3285 config: Config{
3286 Bugs: ProtocolBugs{
3287 ExpectCloseNotify: true,
3288 },
3289 },
3290 shimShutsDown: true,
3291 sendEmptyRecords: 1,
3292 sendWarningAlerts: 1,
3293 flags: []string{"-check-close-notify"},
3294 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003295 } else {
3296 tests = append(tests, testCase{
3297 name: "SkipHelloVerifyRequest",
3298 config: Config{
3299 Bugs: ProtocolBugs{
3300 SkipHelloVerifyRequest: true,
3301 },
3302 },
3303 })
3304 }
3305
David Benjamin760b1dd2015-05-15 23:33:48 -04003306 for _, test := range tests {
3307 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003308 if protocol == dtls {
3309 test.name += "-DTLS"
3310 }
3311 if async {
3312 test.name += "-Async"
3313 test.flags = append(test.flags, "-async")
3314 } else {
3315 test.name += "-Sync"
3316 }
3317 if splitHandshake {
3318 test.name += "-SplitHandshakeRecords"
3319 test.config.Bugs.MaxHandshakeRecordLength = 1
3320 if protocol == dtls {
3321 test.config.Bugs.MaxPacketLength = 256
3322 test.flags = append(test.flags, "-mtu", "256")
3323 }
3324 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003325 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003326 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003327}
3328
Adam Langley524e7172015-02-20 16:04:00 -08003329func addDDoSCallbackTests() {
3330 // DDoS callback.
3331
3332 for _, resume := range []bool{false, true} {
3333 suffix := "Resume"
3334 if resume {
3335 suffix = "No" + suffix
3336 }
3337
3338 testCases = append(testCases, testCase{
3339 testType: serverTest,
3340 name: "Server-DDoS-OK-" + suffix,
3341 flags: []string{"-install-ddos-callback"},
3342 resumeSession: resume,
3343 })
3344
3345 failFlag := "-fail-ddos-callback"
3346 if resume {
3347 failFlag = "-fail-second-ddos-callback"
3348 }
3349 testCases = append(testCases, testCase{
3350 testType: serverTest,
3351 name: "Server-DDoS-Reject-" + suffix,
3352 flags: []string{"-install-ddos-callback", failFlag},
3353 resumeSession: resume,
3354 shouldFail: true,
3355 expectedError: ":CONNECTION_REJECTED:",
3356 })
3357 }
3358}
3359
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003360func addVersionNegotiationTests() {
3361 for i, shimVers := range tlsVersions {
3362 // Assemble flags to disable all newer versions on the shim.
3363 var flags []string
3364 for _, vers := range tlsVersions[i+1:] {
3365 flags = append(flags, vers.flag)
3366 }
3367
3368 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003369 protocols := []protocol{tls}
3370 if runnerVers.hasDTLS && shimVers.hasDTLS {
3371 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003372 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003373 for _, protocol := range protocols {
3374 expectedVersion := shimVers.version
3375 if runnerVers.version < shimVers.version {
3376 expectedVersion = runnerVers.version
3377 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003378
David Benjamin8b8c0062014-11-23 02:47:52 -05003379 suffix := shimVers.name + "-" + runnerVers.name
3380 if protocol == dtls {
3381 suffix += "-DTLS"
3382 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003383
David Benjamin1eb367c2014-12-12 18:17:51 -05003384 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3385
David Benjamin1e29a6b2014-12-10 02:27:24 -05003386 clientVers := shimVers.version
3387 if clientVers > VersionTLS10 {
3388 clientVers = VersionTLS10
3389 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003390 testCases = append(testCases, testCase{
3391 protocol: protocol,
3392 testType: clientTest,
3393 name: "VersionNegotiation-Client-" + suffix,
3394 config: Config{
3395 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003396 Bugs: ProtocolBugs{
3397 ExpectInitialRecordVersion: clientVers,
3398 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003399 },
3400 flags: flags,
3401 expectedVersion: expectedVersion,
3402 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003403 testCases = append(testCases, testCase{
3404 protocol: protocol,
3405 testType: clientTest,
3406 name: "VersionNegotiation-Client2-" + suffix,
3407 config: Config{
3408 MaxVersion: runnerVers.version,
3409 Bugs: ProtocolBugs{
3410 ExpectInitialRecordVersion: clientVers,
3411 },
3412 },
3413 flags: []string{"-max-version", shimVersFlag},
3414 expectedVersion: expectedVersion,
3415 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003416
3417 testCases = append(testCases, testCase{
3418 protocol: protocol,
3419 testType: serverTest,
3420 name: "VersionNegotiation-Server-" + suffix,
3421 config: Config{
3422 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003423 Bugs: ProtocolBugs{
3424 ExpectInitialRecordVersion: expectedVersion,
3425 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003426 },
3427 flags: flags,
3428 expectedVersion: expectedVersion,
3429 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003430 testCases = append(testCases, testCase{
3431 protocol: protocol,
3432 testType: serverTest,
3433 name: "VersionNegotiation-Server2-" + suffix,
3434 config: Config{
3435 MaxVersion: runnerVers.version,
3436 Bugs: ProtocolBugs{
3437 ExpectInitialRecordVersion: expectedVersion,
3438 },
3439 },
3440 flags: []string{"-max-version", shimVersFlag},
3441 expectedVersion: expectedVersion,
3442 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003443 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003444 }
3445 }
3446}
3447
David Benjaminaccb4542014-12-12 23:44:33 -05003448func addMinimumVersionTests() {
3449 for i, shimVers := range tlsVersions {
3450 // Assemble flags to disable all older versions on the shim.
3451 var flags []string
3452 for _, vers := range tlsVersions[:i] {
3453 flags = append(flags, vers.flag)
3454 }
3455
3456 for _, runnerVers := range tlsVersions {
3457 protocols := []protocol{tls}
3458 if runnerVers.hasDTLS && shimVers.hasDTLS {
3459 protocols = append(protocols, dtls)
3460 }
3461 for _, protocol := range protocols {
3462 suffix := shimVers.name + "-" + runnerVers.name
3463 if protocol == dtls {
3464 suffix += "-DTLS"
3465 }
3466 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3467
David Benjaminaccb4542014-12-12 23:44:33 -05003468 var expectedVersion uint16
3469 var shouldFail bool
3470 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003471 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003472 if runnerVers.version >= shimVers.version {
3473 expectedVersion = runnerVers.version
3474 } else {
3475 shouldFail = true
3476 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamina565d292015-12-30 16:51:32 -05003477 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05003478 }
3479
3480 testCases = append(testCases, testCase{
3481 protocol: protocol,
3482 testType: clientTest,
3483 name: "MinimumVersion-Client-" + suffix,
3484 config: Config{
3485 MaxVersion: runnerVers.version,
3486 },
David Benjamin87909c02014-12-13 01:55:01 -05003487 flags: flags,
3488 expectedVersion: expectedVersion,
3489 shouldFail: shouldFail,
3490 expectedError: expectedError,
3491 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003492 })
3493 testCases = append(testCases, testCase{
3494 protocol: protocol,
3495 testType: clientTest,
3496 name: "MinimumVersion-Client2-" + suffix,
3497 config: Config{
3498 MaxVersion: runnerVers.version,
3499 },
David Benjamin87909c02014-12-13 01:55:01 -05003500 flags: []string{"-min-version", shimVersFlag},
3501 expectedVersion: expectedVersion,
3502 shouldFail: shouldFail,
3503 expectedError: expectedError,
3504 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003505 })
3506
3507 testCases = append(testCases, testCase{
3508 protocol: protocol,
3509 testType: serverTest,
3510 name: "MinimumVersion-Server-" + suffix,
3511 config: Config{
3512 MaxVersion: runnerVers.version,
3513 },
David Benjamin87909c02014-12-13 01:55:01 -05003514 flags: flags,
3515 expectedVersion: expectedVersion,
3516 shouldFail: shouldFail,
3517 expectedError: expectedError,
3518 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003519 })
3520 testCases = append(testCases, testCase{
3521 protocol: protocol,
3522 testType: serverTest,
3523 name: "MinimumVersion-Server2-" + suffix,
3524 config: Config{
3525 MaxVersion: runnerVers.version,
3526 },
David Benjamin87909c02014-12-13 01:55:01 -05003527 flags: []string{"-min-version", shimVersFlag},
3528 expectedVersion: expectedVersion,
3529 shouldFail: shouldFail,
3530 expectedError: expectedError,
3531 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003532 })
3533 }
3534 }
3535 }
3536}
3537
David Benjamine78bfde2014-09-06 12:45:15 -04003538func addExtensionTests() {
3539 testCases = append(testCases, testCase{
3540 testType: clientTest,
3541 name: "DuplicateExtensionClient",
3542 config: Config{
3543 Bugs: ProtocolBugs{
3544 DuplicateExtension: true,
3545 },
3546 },
3547 shouldFail: true,
3548 expectedLocalError: "remote error: error decoding message",
3549 })
3550 testCases = append(testCases, testCase{
3551 testType: serverTest,
3552 name: "DuplicateExtensionServer",
3553 config: Config{
3554 Bugs: ProtocolBugs{
3555 DuplicateExtension: true,
3556 },
3557 },
3558 shouldFail: true,
3559 expectedLocalError: "remote error: error decoding message",
3560 })
3561 testCases = append(testCases, testCase{
3562 testType: clientTest,
3563 name: "ServerNameExtensionClient",
3564 config: Config{
3565 Bugs: ProtocolBugs{
3566 ExpectServerName: "example.com",
3567 },
3568 },
3569 flags: []string{"-host-name", "example.com"},
3570 })
3571 testCases = append(testCases, testCase{
3572 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003573 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003574 config: Config{
3575 Bugs: ProtocolBugs{
3576 ExpectServerName: "mismatch.com",
3577 },
3578 },
3579 flags: []string{"-host-name", "example.com"},
3580 shouldFail: true,
3581 expectedLocalError: "tls: unexpected server name",
3582 })
3583 testCases = append(testCases, testCase{
3584 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003585 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003586 config: Config{
3587 Bugs: ProtocolBugs{
3588 ExpectServerName: "missing.com",
3589 },
3590 },
3591 shouldFail: true,
3592 expectedLocalError: "tls: unexpected server name",
3593 })
3594 testCases = append(testCases, testCase{
3595 testType: serverTest,
3596 name: "ServerNameExtensionServer",
3597 config: Config{
3598 ServerName: "example.com",
3599 },
3600 flags: []string{"-expect-server-name", "example.com"},
3601 resumeSession: true,
3602 })
David Benjaminae2888f2014-09-06 12:58:58 -04003603 testCases = append(testCases, testCase{
3604 testType: clientTest,
3605 name: "ALPNClient",
3606 config: Config{
3607 NextProtos: []string{"foo"},
3608 },
3609 flags: []string{
3610 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3611 "-expect-alpn", "foo",
3612 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003613 expectedNextProto: "foo",
3614 expectedNextProtoType: alpn,
3615 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003616 })
3617 testCases = append(testCases, testCase{
3618 testType: serverTest,
3619 name: "ALPNServer",
3620 config: Config{
3621 NextProtos: []string{"foo", "bar", "baz"},
3622 },
3623 flags: []string{
3624 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3625 "-select-alpn", "foo",
3626 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003627 expectedNextProto: "foo",
3628 expectedNextProtoType: alpn,
3629 resumeSession: true,
3630 })
David Benjamin594e7d22016-03-17 17:49:56 -04003631 testCases = append(testCases, testCase{
3632 testType: serverTest,
3633 name: "ALPNServer-Decline",
3634 config: Config{
3635 NextProtos: []string{"foo", "bar", "baz"},
3636 },
3637 flags: []string{"-decline-alpn"},
3638 expectNoNextProto: true,
3639 resumeSession: true,
3640 })
David Benjaminfc7b0862014-09-06 13:21:53 -04003641 // Test that the server prefers ALPN over NPN.
3642 testCases = append(testCases, testCase{
3643 testType: serverTest,
3644 name: "ALPNServer-Preferred",
3645 config: Config{
3646 NextProtos: []string{"foo", "bar", "baz"},
3647 },
3648 flags: []string{
3649 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3650 "-select-alpn", "foo",
3651 "-advertise-npn", "\x03foo\x03bar\x03baz",
3652 },
3653 expectedNextProto: "foo",
3654 expectedNextProtoType: alpn,
3655 resumeSession: true,
3656 })
3657 testCases = append(testCases, testCase{
3658 testType: serverTest,
3659 name: "ALPNServer-Preferred-Swapped",
3660 config: Config{
3661 NextProtos: []string{"foo", "bar", "baz"},
3662 Bugs: ProtocolBugs{
3663 SwapNPNAndALPN: true,
3664 },
3665 },
3666 flags: []string{
3667 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3668 "-select-alpn", "foo",
3669 "-advertise-npn", "\x03foo\x03bar\x03baz",
3670 },
3671 expectedNextProto: "foo",
3672 expectedNextProtoType: alpn,
3673 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003674 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003675 var emptyString string
3676 testCases = append(testCases, testCase{
3677 testType: clientTest,
3678 name: "ALPNClient-EmptyProtocolName",
3679 config: Config{
3680 NextProtos: []string{""},
3681 Bugs: ProtocolBugs{
3682 // A server returning an empty ALPN protocol
3683 // should be rejected.
3684 ALPNProtocol: &emptyString,
3685 },
3686 },
3687 flags: []string{
3688 "-advertise-alpn", "\x03foo",
3689 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003690 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003691 expectedError: ":PARSE_TLSEXT:",
3692 })
3693 testCases = append(testCases, testCase{
3694 testType: serverTest,
3695 name: "ALPNServer-EmptyProtocolName",
3696 config: Config{
3697 // A ClientHello containing an empty ALPN protocol
3698 // should be rejected.
3699 NextProtos: []string{"foo", "", "baz"},
3700 },
3701 flags: []string{
3702 "-select-alpn", "foo",
3703 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003704 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003705 expectedError: ":PARSE_TLSEXT:",
3706 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003707 // Test that negotiating both NPN and ALPN is forbidden.
3708 testCases = append(testCases, testCase{
3709 name: "NegotiateALPNAndNPN",
3710 config: Config{
3711 NextProtos: []string{"foo", "bar", "baz"},
3712 Bugs: ProtocolBugs{
3713 NegotiateALPNAndNPN: true,
3714 },
3715 },
3716 flags: []string{
3717 "-advertise-alpn", "\x03foo",
3718 "-select-next-proto", "foo",
3719 },
3720 shouldFail: true,
3721 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3722 })
3723 testCases = append(testCases, testCase{
3724 name: "NegotiateALPNAndNPN-Swapped",
3725 config: Config{
3726 NextProtos: []string{"foo", "bar", "baz"},
3727 Bugs: ProtocolBugs{
3728 NegotiateALPNAndNPN: true,
3729 SwapNPNAndALPN: true,
3730 },
3731 },
3732 flags: []string{
3733 "-advertise-alpn", "\x03foo",
3734 "-select-next-proto", "foo",
3735 },
3736 shouldFail: true,
3737 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3738 })
David Benjamin091c4b92015-10-26 13:33:21 -04003739 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3740 testCases = append(testCases, testCase{
3741 name: "DisableNPN",
3742 config: Config{
3743 NextProtos: []string{"foo"},
3744 },
3745 flags: []string{
3746 "-select-next-proto", "foo",
3747 "-disable-npn",
3748 },
3749 expectNoNextProto: true,
3750 })
Adam Langley38311732014-10-16 19:04:35 -07003751 // Resume with a corrupt ticket.
3752 testCases = append(testCases, testCase{
3753 testType: serverTest,
3754 name: "CorruptTicket",
3755 config: Config{
3756 Bugs: ProtocolBugs{
3757 CorruptTicket: true,
3758 },
3759 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003760 resumeSession: true,
3761 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003762 })
David Benjamind98452d2015-06-16 14:16:23 -04003763 // Test the ticket callback, with and without renewal.
3764 testCases = append(testCases, testCase{
3765 testType: serverTest,
3766 name: "TicketCallback",
3767 resumeSession: true,
3768 flags: []string{"-use-ticket-callback"},
3769 })
3770 testCases = append(testCases, testCase{
3771 testType: serverTest,
3772 name: "TicketCallback-Renew",
3773 config: Config{
3774 Bugs: ProtocolBugs{
3775 ExpectNewTicket: true,
3776 },
3777 },
3778 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3779 resumeSession: true,
3780 })
Adam Langley38311732014-10-16 19:04:35 -07003781 // Resume with an oversized session id.
3782 testCases = append(testCases, testCase{
3783 testType: serverTest,
3784 name: "OversizedSessionId",
3785 config: Config{
3786 Bugs: ProtocolBugs{
3787 OversizedSessionId: true,
3788 },
3789 },
3790 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003791 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003792 expectedError: ":DECODE_ERROR:",
3793 })
David Benjaminca6c8262014-11-15 19:06:08 -05003794 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3795 // are ignored.
3796 testCases = append(testCases, testCase{
3797 protocol: dtls,
3798 name: "SRTP-Client",
3799 config: Config{
3800 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3801 },
3802 flags: []string{
3803 "-srtp-profiles",
3804 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3805 },
3806 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3807 })
3808 testCases = append(testCases, testCase{
3809 protocol: dtls,
3810 testType: serverTest,
3811 name: "SRTP-Server",
3812 config: Config{
3813 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3814 },
3815 flags: []string{
3816 "-srtp-profiles",
3817 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3818 },
3819 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3820 })
3821 // Test that the MKI is ignored.
3822 testCases = append(testCases, testCase{
3823 protocol: dtls,
3824 testType: serverTest,
3825 name: "SRTP-Server-IgnoreMKI",
3826 config: Config{
3827 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3828 Bugs: ProtocolBugs{
3829 SRTPMasterKeyIdentifer: "bogus",
3830 },
3831 },
3832 flags: []string{
3833 "-srtp-profiles",
3834 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3835 },
3836 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3837 })
3838 // Test that SRTP isn't negotiated on the server if there were
3839 // no matching profiles.
3840 testCases = append(testCases, testCase{
3841 protocol: dtls,
3842 testType: serverTest,
3843 name: "SRTP-Server-NoMatch",
3844 config: Config{
3845 SRTPProtectionProfiles: []uint16{100, 101, 102},
3846 },
3847 flags: []string{
3848 "-srtp-profiles",
3849 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3850 },
3851 expectedSRTPProtectionProfile: 0,
3852 })
3853 // Test that the server returning an invalid SRTP profile is
3854 // flagged as an error by the client.
3855 testCases = append(testCases, testCase{
3856 protocol: dtls,
3857 name: "SRTP-Client-NoMatch",
3858 config: Config{
3859 Bugs: ProtocolBugs{
3860 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3861 },
3862 },
3863 flags: []string{
3864 "-srtp-profiles",
3865 "SRTP_AES128_CM_SHA1_80",
3866 },
3867 shouldFail: true,
3868 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3869 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003870 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003871 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003872 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003873 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003874 flags: []string{
3875 "-enable-signed-cert-timestamps",
3876 "-expect-signed-cert-timestamps",
3877 base64.StdEncoding.EncodeToString(testSCTList),
3878 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003879 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003880 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003881 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003882 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003883 testType: serverTest,
3884 flags: []string{
3885 "-signed-cert-timestamps",
3886 base64.StdEncoding.EncodeToString(testSCTList),
3887 },
3888 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003889 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003890 })
3891 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003892 testType: clientTest,
3893 name: "ClientHelloPadding",
3894 config: Config{
3895 Bugs: ProtocolBugs{
3896 RequireClientHelloSize: 512,
3897 },
3898 },
3899 // This hostname just needs to be long enough to push the
3900 // ClientHello into F5's danger zone between 256 and 511 bytes
3901 // long.
3902 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3903 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003904
3905 // Extensions should not function in SSL 3.0.
3906 testCases = append(testCases, testCase{
3907 testType: serverTest,
3908 name: "SSLv3Extensions-NoALPN",
3909 config: Config{
3910 MaxVersion: VersionSSL30,
3911 NextProtos: []string{"foo", "bar", "baz"},
3912 },
3913 flags: []string{
3914 "-select-alpn", "foo",
3915 },
3916 expectNoNextProto: true,
3917 })
3918
3919 // Test session tickets separately as they follow a different codepath.
3920 testCases = append(testCases, testCase{
3921 testType: serverTest,
3922 name: "SSLv3Extensions-NoTickets",
3923 config: Config{
3924 MaxVersion: VersionSSL30,
3925 Bugs: ProtocolBugs{
3926 // Historically, session tickets in SSL 3.0
3927 // failed in different ways depending on whether
3928 // the client supported renegotiation_info.
3929 NoRenegotiationInfo: true,
3930 },
3931 },
3932 resumeSession: true,
3933 })
3934 testCases = append(testCases, testCase{
3935 testType: serverTest,
3936 name: "SSLv3Extensions-NoTickets2",
3937 config: Config{
3938 MaxVersion: VersionSSL30,
3939 },
3940 resumeSession: true,
3941 })
3942
3943 // But SSL 3.0 does send and process renegotiation_info.
3944 testCases = append(testCases, testCase{
3945 testType: serverTest,
3946 name: "SSLv3Extensions-RenegotiationInfo",
3947 config: Config{
3948 MaxVersion: VersionSSL30,
3949 Bugs: ProtocolBugs{
3950 RequireRenegotiationInfo: true,
3951 },
3952 },
3953 })
3954 testCases = append(testCases, testCase{
3955 testType: serverTest,
3956 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3957 config: Config{
3958 MaxVersion: VersionSSL30,
3959 Bugs: ProtocolBugs{
3960 NoRenegotiationInfo: true,
3961 SendRenegotiationSCSV: true,
3962 RequireRenegotiationInfo: true,
3963 },
3964 },
3965 })
David Benjamine78bfde2014-09-06 12:45:15 -04003966}
3967
David Benjamin01fe8202014-09-24 15:21:44 -04003968func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003969 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003970 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003971 protocols := []protocol{tls}
3972 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3973 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003974 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003975 for _, protocol := range protocols {
3976 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3977 if protocol == dtls {
3978 suffix += "-DTLS"
3979 }
3980
David Benjaminece3de92015-03-16 18:02:20 -04003981 if sessionVers.version == resumeVers.version {
3982 testCases = append(testCases, testCase{
3983 protocol: protocol,
3984 name: "Resume-Client" + suffix,
3985 resumeSession: true,
3986 config: Config{
3987 MaxVersion: sessionVers.version,
3988 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003989 },
David Benjaminece3de92015-03-16 18:02:20 -04003990 expectedVersion: sessionVers.version,
3991 expectedResumeVersion: resumeVers.version,
3992 })
3993 } else {
3994 testCases = append(testCases, testCase{
3995 protocol: protocol,
3996 name: "Resume-Client-Mismatch" + suffix,
3997 resumeSession: true,
3998 config: Config{
3999 MaxVersion: sessionVers.version,
4000 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05004001 },
David Benjaminece3de92015-03-16 18:02:20 -04004002 expectedVersion: sessionVers.version,
4003 resumeConfig: &Config{
4004 MaxVersion: resumeVers.version,
4005 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4006 Bugs: ProtocolBugs{
4007 AllowSessionVersionMismatch: true,
4008 },
4009 },
4010 expectedResumeVersion: resumeVers.version,
4011 shouldFail: true,
4012 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
4013 })
4014 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004015
4016 testCases = append(testCases, testCase{
4017 protocol: protocol,
4018 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004019 resumeSession: true,
4020 config: Config{
4021 MaxVersion: sessionVers.version,
4022 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4023 },
4024 expectedVersion: sessionVers.version,
4025 resumeConfig: &Config{
4026 MaxVersion: resumeVers.version,
4027 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4028 },
4029 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004030 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05004031 expectedResumeVersion: resumeVers.version,
4032 })
4033
David Benjamin8b8c0062014-11-23 02:47:52 -05004034 testCases = append(testCases, testCase{
4035 protocol: protocol,
4036 testType: serverTest,
4037 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05004038 resumeSession: true,
4039 config: Config{
4040 MaxVersion: sessionVers.version,
4041 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4042 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07004043 expectedVersion: sessionVers.version,
4044 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05004045 resumeConfig: &Config{
4046 MaxVersion: resumeVers.version,
4047 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
4048 },
4049 expectedResumeVersion: resumeVers.version,
4050 })
4051 }
David Benjamin01fe8202014-09-24 15:21:44 -04004052 }
4053 }
David Benjaminece3de92015-03-16 18:02:20 -04004054
4055 testCases = append(testCases, testCase{
4056 name: "Resume-Client-CipherMismatch",
4057 resumeSession: true,
4058 config: Config{
4059 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4060 },
4061 resumeConfig: &Config{
4062 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4063 Bugs: ProtocolBugs{
4064 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
4065 },
4066 },
4067 shouldFail: true,
4068 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
4069 })
David Benjamin01fe8202014-09-24 15:21:44 -04004070}
4071
Adam Langley2ae77d22014-10-28 17:29:33 -07004072func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04004073 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04004074 testCases = append(testCases, testCase{
4075 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04004076 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004077 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04004078 shouldFail: true,
4079 expectedError: ":NO_RENEGOTIATION:",
4080 expectedLocalError: "remote error: no renegotiation",
4081 })
Adam Langley5021b222015-06-12 18:27:58 -07004082 // The server shouldn't echo the renegotiation extension unless
4083 // requested by the client.
4084 testCases = append(testCases, testCase{
4085 testType: serverTest,
4086 name: "Renegotiate-Server-NoExt",
4087 config: Config{
4088 Bugs: ProtocolBugs{
4089 NoRenegotiationInfo: true,
4090 RequireRenegotiationInfo: true,
4091 },
4092 },
4093 shouldFail: true,
4094 expectedLocalError: "renegotiation extension missing",
4095 })
4096 // The renegotiation SCSV should be sufficient for the server to echo
4097 // the extension.
4098 testCases = append(testCases, testCase{
4099 testType: serverTest,
4100 name: "Renegotiate-Server-NoExt-SCSV",
4101 config: Config{
4102 Bugs: ProtocolBugs{
4103 NoRenegotiationInfo: true,
4104 SendRenegotiationSCSV: true,
4105 RequireRenegotiationInfo: true,
4106 },
4107 },
4108 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07004109 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004110 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04004111 config: Config{
4112 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04004113 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04004114 },
4115 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004116 renegotiate: 1,
4117 flags: []string{
4118 "-renegotiate-freely",
4119 "-expect-total-renegotiations", "1",
4120 },
David Benjamincdea40c2015-03-19 14:09:43 -04004121 })
4122 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004123 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004124 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004125 config: Config{
4126 Bugs: ProtocolBugs{
4127 EmptyRenegotiationInfo: true,
4128 },
4129 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004130 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004131 shouldFail: true,
4132 expectedError: ":RENEGOTIATION_MISMATCH:",
4133 })
4134 testCases = append(testCases, testCase{
4135 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004136 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004137 config: Config{
4138 Bugs: ProtocolBugs{
4139 BadRenegotiationInfo: true,
4140 },
4141 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004142 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07004143 shouldFail: true,
4144 expectedError: ":RENEGOTIATION_MISMATCH:",
4145 })
4146 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05004147 name: "Renegotiate-Client-Downgrade",
4148 renegotiate: 1,
4149 config: Config{
4150 Bugs: ProtocolBugs{
4151 NoRenegotiationInfoAfterInitial: true,
4152 },
4153 },
4154 flags: []string{"-renegotiate-freely"},
4155 shouldFail: true,
4156 expectedError: ":RENEGOTIATION_MISMATCH:",
4157 })
4158 testCases = append(testCases, testCase{
4159 name: "Renegotiate-Client-Upgrade",
4160 renegotiate: 1,
4161 config: Config{
4162 Bugs: ProtocolBugs{
4163 NoRenegotiationInfoInInitial: true,
4164 },
4165 },
4166 flags: []string{"-renegotiate-freely"},
4167 shouldFail: true,
4168 expectedError: ":RENEGOTIATION_MISMATCH:",
4169 })
4170 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04004171 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004172 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04004173 config: Config{
4174 Bugs: ProtocolBugs{
4175 NoRenegotiationInfo: true,
4176 },
4177 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004178 flags: []string{
4179 "-renegotiate-freely",
4180 "-expect-total-renegotiations", "1",
4181 },
David Benjamincff0b902015-05-15 23:09:47 -04004182 })
4183 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07004184 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004185 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004186 config: Config{
4187 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4188 },
4189 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004190 flags: []string{
4191 "-renegotiate-freely",
4192 "-expect-total-renegotiations", "1",
4193 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07004194 })
4195 testCases = append(testCases, testCase{
4196 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004197 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07004198 config: Config{
4199 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4200 },
4201 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004202 flags: []string{
4203 "-renegotiate-freely",
4204 "-expect-total-renegotiations", "1",
4205 },
David Benjaminb16346b2015-04-08 19:16:58 -04004206 })
4207 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05004208 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004209 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05004210 config: Config{
4211 MaxVersion: VersionTLS10,
4212 Bugs: ProtocolBugs{
4213 RequireSameRenegoClientVersion: true,
4214 },
4215 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004216 flags: []string{
4217 "-renegotiate-freely",
4218 "-expect-total-renegotiations", "1",
4219 },
David Benjaminc44b1df2014-11-23 12:11:01 -05004220 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07004221 testCases = append(testCases, testCase{
4222 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004223 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07004224 config: Config{
4225 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4226 NextProtos: []string{"foo"},
4227 },
4228 flags: []string{
4229 "-false-start",
4230 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004231 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04004232 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07004233 },
4234 shimWritesFirst: true,
4235 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004236
4237 // Client-side renegotiation controls.
4238 testCases = append(testCases, testCase{
4239 name: "Renegotiate-Client-Forbidden-1",
4240 renegotiate: 1,
4241 shouldFail: true,
4242 expectedError: ":NO_RENEGOTIATION:",
4243 expectedLocalError: "remote error: no renegotiation",
4244 })
4245 testCases = append(testCases, testCase{
4246 name: "Renegotiate-Client-Once-1",
4247 renegotiate: 1,
4248 flags: []string{
4249 "-renegotiate-once",
4250 "-expect-total-renegotiations", "1",
4251 },
4252 })
4253 testCases = append(testCases, testCase{
4254 name: "Renegotiate-Client-Freely-1",
4255 renegotiate: 1,
4256 flags: []string{
4257 "-renegotiate-freely",
4258 "-expect-total-renegotiations", "1",
4259 },
4260 })
4261 testCases = append(testCases, testCase{
4262 name: "Renegotiate-Client-Once-2",
4263 renegotiate: 2,
4264 flags: []string{"-renegotiate-once"},
4265 shouldFail: true,
4266 expectedError: ":NO_RENEGOTIATION:",
4267 expectedLocalError: "remote error: no renegotiation",
4268 })
4269 testCases = append(testCases, testCase{
4270 name: "Renegotiate-Client-Freely-2",
4271 renegotiate: 2,
4272 flags: []string{
4273 "-renegotiate-freely",
4274 "-expect-total-renegotiations", "2",
4275 },
4276 })
Adam Langley27a0d082015-11-03 13:34:10 -08004277 testCases = append(testCases, testCase{
4278 name: "Renegotiate-Client-NoIgnore",
4279 config: Config{
4280 Bugs: ProtocolBugs{
4281 SendHelloRequestBeforeEveryAppDataRecord: true,
4282 },
4283 },
4284 shouldFail: true,
4285 expectedError: ":NO_RENEGOTIATION:",
4286 })
4287 testCases = append(testCases, testCase{
4288 name: "Renegotiate-Client-Ignore",
4289 config: Config{
4290 Bugs: ProtocolBugs{
4291 SendHelloRequestBeforeEveryAppDataRecord: true,
4292 },
4293 },
4294 flags: []string{
4295 "-renegotiate-ignore",
4296 "-expect-total-renegotiations", "0",
4297 },
4298 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004299}
4300
David Benjamin5e961c12014-11-07 01:48:35 -05004301func addDTLSReplayTests() {
4302 // Test that sequence number replays are detected.
4303 testCases = append(testCases, testCase{
4304 protocol: dtls,
4305 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004306 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004307 replayWrites: true,
4308 })
4309
David Benjamin8e6db492015-07-25 18:29:23 -04004310 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004311 // than the retransmit window.
4312 testCases = append(testCases, testCase{
4313 protocol: dtls,
4314 name: "DTLS-Replay-LargeGaps",
4315 config: Config{
4316 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004317 SequenceNumberMapping: func(in uint64) uint64 {
4318 return in * 127
4319 },
David Benjamin5e961c12014-11-07 01:48:35 -05004320 },
4321 },
David Benjamin8e6db492015-07-25 18:29:23 -04004322 messageCount: 200,
4323 replayWrites: true,
4324 })
4325
4326 // Test the incoming sequence number changing non-monotonically.
4327 testCases = append(testCases, testCase{
4328 protocol: dtls,
4329 name: "DTLS-Replay-NonMonotonic",
4330 config: Config{
4331 Bugs: ProtocolBugs{
4332 SequenceNumberMapping: func(in uint64) uint64 {
4333 return in ^ 31
4334 },
4335 },
4336 },
4337 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004338 replayWrites: true,
4339 })
4340}
4341
David Benjamin000800a2014-11-14 01:43:59 -05004342var testHashes = []struct {
4343 name string
4344 id uint8
4345}{
4346 {"SHA1", hashSHA1},
David Benjamin000800a2014-11-14 01:43:59 -05004347 {"SHA256", hashSHA256},
4348 {"SHA384", hashSHA384},
4349 {"SHA512", hashSHA512},
4350}
4351
4352func addSigningHashTests() {
4353 // Make sure each hash works. Include some fake hashes in the list and
4354 // ensure they're ignored.
4355 for _, hash := range testHashes {
4356 testCases = append(testCases, testCase{
4357 name: "SigningHash-ClientAuth-" + hash.name,
4358 config: Config{
4359 ClientAuth: RequireAnyClientCert,
4360 SignatureAndHashes: []signatureAndHash{
4361 {signatureRSA, 42},
4362 {signatureRSA, hash.id},
4363 {signatureRSA, 255},
4364 },
4365 },
4366 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004367 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4368 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004369 },
4370 })
4371
4372 testCases = append(testCases, testCase{
4373 testType: serverTest,
4374 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4375 config: Config{
4376 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4377 SignatureAndHashes: []signatureAndHash{
4378 {signatureRSA, 42},
4379 {signatureRSA, hash.id},
4380 {signatureRSA, 255},
4381 },
4382 },
4383 })
David Benjamin6e807652015-11-02 12:02:20 -05004384
4385 testCases = append(testCases, testCase{
4386 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4387 config: Config{
4388 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4389 SignatureAndHashes: []signatureAndHash{
4390 {signatureRSA, 42},
4391 {signatureRSA, hash.id},
4392 {signatureRSA, 255},
4393 },
4394 },
4395 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4396 })
David Benjamin000800a2014-11-14 01:43:59 -05004397 }
4398
4399 // Test that hash resolution takes the signature type into account.
4400 testCases = append(testCases, testCase{
4401 name: "SigningHash-ClientAuth-SignatureType",
4402 config: Config{
4403 ClientAuth: RequireAnyClientCert,
4404 SignatureAndHashes: []signatureAndHash{
4405 {signatureECDSA, hashSHA512},
4406 {signatureRSA, hashSHA384},
4407 {signatureECDSA, hashSHA1},
4408 },
4409 },
4410 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004411 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4412 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004413 },
4414 })
4415
4416 testCases = append(testCases, testCase{
4417 testType: serverTest,
4418 name: "SigningHash-ServerKeyExchange-SignatureType",
4419 config: Config{
4420 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4421 SignatureAndHashes: []signatureAndHash{
4422 {signatureECDSA, hashSHA512},
4423 {signatureRSA, hashSHA384},
4424 {signatureECDSA, hashSHA1},
4425 },
4426 },
4427 })
4428
4429 // Test that, if the list is missing, the peer falls back to SHA-1.
4430 testCases = append(testCases, testCase{
4431 name: "SigningHash-ClientAuth-Fallback",
4432 config: Config{
4433 ClientAuth: RequireAnyClientCert,
4434 SignatureAndHashes: []signatureAndHash{
4435 {signatureRSA, hashSHA1},
4436 },
4437 Bugs: ProtocolBugs{
4438 NoSignatureAndHashes: true,
4439 },
4440 },
4441 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004442 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4443 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004444 },
4445 })
4446
4447 testCases = append(testCases, testCase{
4448 testType: serverTest,
4449 name: "SigningHash-ServerKeyExchange-Fallback",
4450 config: Config{
4451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4452 SignatureAndHashes: []signatureAndHash{
4453 {signatureRSA, hashSHA1},
4454 },
4455 Bugs: ProtocolBugs{
4456 NoSignatureAndHashes: true,
4457 },
4458 },
4459 })
David Benjamin72dc7832015-03-16 17:49:43 -04004460
4461 // Test that hash preferences are enforced. BoringSSL defaults to
4462 // rejecting MD5 signatures.
4463 testCases = append(testCases, testCase{
4464 testType: serverTest,
4465 name: "SigningHash-ClientAuth-Enforced",
4466 config: Config{
4467 Certificates: []Certificate{rsaCertificate},
4468 SignatureAndHashes: []signatureAndHash{
4469 {signatureRSA, hashMD5},
4470 // Advertise SHA-1 so the handshake will
4471 // proceed, but the shim's preferences will be
4472 // ignored in CertificateVerify generation, so
4473 // MD5 will be chosen.
4474 {signatureRSA, hashSHA1},
4475 },
4476 Bugs: ProtocolBugs{
4477 IgnorePeerSignatureAlgorithmPreferences: true,
4478 },
4479 },
4480 flags: []string{"-require-any-client-certificate"},
4481 shouldFail: true,
4482 expectedError: ":WRONG_SIGNATURE_TYPE:",
4483 })
4484
4485 testCases = append(testCases, testCase{
4486 name: "SigningHash-ServerKeyExchange-Enforced",
4487 config: Config{
4488 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4489 SignatureAndHashes: []signatureAndHash{
4490 {signatureRSA, hashMD5},
4491 },
4492 Bugs: ProtocolBugs{
4493 IgnorePeerSignatureAlgorithmPreferences: true,
4494 },
4495 },
4496 shouldFail: true,
4497 expectedError: ":WRONG_SIGNATURE_TYPE:",
4498 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004499
4500 // Test that the agreed upon digest respects the client preferences and
4501 // the server digests.
4502 testCases = append(testCases, testCase{
4503 name: "Agree-Digest-Fallback",
4504 config: Config{
4505 ClientAuth: RequireAnyClientCert,
4506 SignatureAndHashes: []signatureAndHash{
4507 {signatureRSA, hashSHA512},
4508 {signatureRSA, hashSHA1},
4509 },
4510 },
4511 flags: []string{
4512 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4513 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4514 },
4515 digestPrefs: "SHA256",
4516 expectedClientCertSignatureHash: hashSHA1,
4517 })
4518 testCases = append(testCases, testCase{
4519 name: "Agree-Digest-SHA256",
4520 config: Config{
4521 ClientAuth: RequireAnyClientCert,
4522 SignatureAndHashes: []signatureAndHash{
4523 {signatureRSA, hashSHA1},
4524 {signatureRSA, hashSHA256},
4525 },
4526 },
4527 flags: []string{
4528 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4529 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4530 },
4531 digestPrefs: "SHA256,SHA1",
4532 expectedClientCertSignatureHash: hashSHA256,
4533 })
4534 testCases = append(testCases, testCase{
4535 name: "Agree-Digest-SHA1",
4536 config: Config{
4537 ClientAuth: RequireAnyClientCert,
4538 SignatureAndHashes: []signatureAndHash{
4539 {signatureRSA, hashSHA1},
4540 },
4541 },
4542 flags: []string{
4543 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4544 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4545 },
4546 digestPrefs: "SHA512,SHA256,SHA1",
4547 expectedClientCertSignatureHash: hashSHA1,
4548 })
4549 testCases = append(testCases, testCase{
4550 name: "Agree-Digest-Default",
4551 config: Config{
4552 ClientAuth: RequireAnyClientCert,
4553 SignatureAndHashes: []signatureAndHash{
4554 {signatureRSA, hashSHA256},
4555 {signatureECDSA, hashSHA256},
4556 {signatureRSA, hashSHA1},
4557 {signatureECDSA, hashSHA1},
4558 },
4559 },
4560 flags: []string{
4561 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4562 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4563 },
4564 expectedClientCertSignatureHash: hashSHA256,
4565 })
David Benjamin000800a2014-11-14 01:43:59 -05004566}
4567
David Benjamin83f90402015-01-27 01:09:43 -05004568// timeouts is the retransmit schedule for BoringSSL. It doubles and
4569// caps at 60 seconds. On the 13th timeout, it gives up.
4570var timeouts = []time.Duration{
4571 1 * time.Second,
4572 2 * time.Second,
4573 4 * time.Second,
4574 8 * time.Second,
4575 16 * time.Second,
4576 32 * time.Second,
4577 60 * time.Second,
4578 60 * time.Second,
4579 60 * time.Second,
4580 60 * time.Second,
4581 60 * time.Second,
4582 60 * time.Second,
4583 60 * time.Second,
4584}
4585
4586func addDTLSRetransmitTests() {
4587 // Test that this is indeed the timeout schedule. Stress all
4588 // four patterns of handshake.
4589 for i := 1; i < len(timeouts); i++ {
4590 number := strconv.Itoa(i)
4591 testCases = append(testCases, testCase{
4592 protocol: dtls,
4593 name: "DTLS-Retransmit-Client-" + number,
4594 config: Config{
4595 Bugs: ProtocolBugs{
4596 TimeoutSchedule: timeouts[:i],
4597 },
4598 },
4599 resumeSession: true,
4600 flags: []string{"-async"},
4601 })
4602 testCases = append(testCases, testCase{
4603 protocol: dtls,
4604 testType: serverTest,
4605 name: "DTLS-Retransmit-Server-" + number,
4606 config: Config{
4607 Bugs: ProtocolBugs{
4608 TimeoutSchedule: timeouts[:i],
4609 },
4610 },
4611 resumeSession: true,
4612 flags: []string{"-async"},
4613 })
4614 }
4615
4616 // Test that exceeding the timeout schedule hits a read
4617 // timeout.
4618 testCases = append(testCases, testCase{
4619 protocol: dtls,
4620 name: "DTLS-Retransmit-Timeout",
4621 config: Config{
4622 Bugs: ProtocolBugs{
4623 TimeoutSchedule: timeouts,
4624 },
4625 },
4626 resumeSession: true,
4627 flags: []string{"-async"},
4628 shouldFail: true,
4629 expectedError: ":READ_TIMEOUT_EXPIRED:",
4630 })
4631
4632 // Test that timeout handling has a fudge factor, due to API
4633 // problems.
4634 testCases = append(testCases, testCase{
4635 protocol: dtls,
4636 name: "DTLS-Retransmit-Fudge",
4637 config: Config{
4638 Bugs: ProtocolBugs{
4639 TimeoutSchedule: []time.Duration{
4640 timeouts[0] - 10*time.Millisecond,
4641 },
4642 },
4643 },
4644 resumeSession: true,
4645 flags: []string{"-async"},
4646 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004647
4648 // Test that the final Finished retransmitting isn't
4649 // duplicated if the peer badly fragments everything.
4650 testCases = append(testCases, testCase{
4651 testType: serverTest,
4652 protocol: dtls,
4653 name: "DTLS-Retransmit-Fragmented",
4654 config: Config{
4655 Bugs: ProtocolBugs{
4656 TimeoutSchedule: []time.Duration{timeouts[0]},
4657 MaxHandshakeRecordLength: 2,
4658 },
4659 },
4660 flags: []string{"-async"},
4661 })
David Benjamin83f90402015-01-27 01:09:43 -05004662}
4663
David Benjaminc565ebb2015-04-03 04:06:36 -04004664func addExportKeyingMaterialTests() {
4665 for _, vers := range tlsVersions {
4666 if vers.version == VersionSSL30 {
4667 continue
4668 }
4669 testCases = append(testCases, testCase{
4670 name: "ExportKeyingMaterial-" + vers.name,
4671 config: Config{
4672 MaxVersion: vers.version,
4673 },
4674 exportKeyingMaterial: 1024,
4675 exportLabel: "label",
4676 exportContext: "context",
4677 useExportContext: true,
4678 })
4679 testCases = append(testCases, testCase{
4680 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4681 config: Config{
4682 MaxVersion: vers.version,
4683 },
4684 exportKeyingMaterial: 1024,
4685 })
4686 testCases = append(testCases, testCase{
4687 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4688 config: Config{
4689 MaxVersion: vers.version,
4690 },
4691 exportKeyingMaterial: 1024,
4692 useExportContext: true,
4693 })
4694 testCases = append(testCases, testCase{
4695 name: "ExportKeyingMaterial-Small-" + vers.name,
4696 config: Config{
4697 MaxVersion: vers.version,
4698 },
4699 exportKeyingMaterial: 1,
4700 exportLabel: "label",
4701 exportContext: "context",
4702 useExportContext: true,
4703 })
4704 }
4705 testCases = append(testCases, testCase{
4706 name: "ExportKeyingMaterial-SSL3",
4707 config: Config{
4708 MaxVersion: VersionSSL30,
4709 },
4710 exportKeyingMaterial: 1024,
4711 exportLabel: "label",
4712 exportContext: "context",
4713 useExportContext: true,
4714 shouldFail: true,
4715 expectedError: "failed to export keying material",
4716 })
4717}
4718
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004719func addTLSUniqueTests() {
4720 for _, isClient := range []bool{false, true} {
4721 for _, isResumption := range []bool{false, true} {
4722 for _, hasEMS := range []bool{false, true} {
4723 var suffix string
4724 if isResumption {
4725 suffix = "Resume-"
4726 } else {
4727 suffix = "Full-"
4728 }
4729
4730 if hasEMS {
4731 suffix += "EMS-"
4732 } else {
4733 suffix += "NoEMS-"
4734 }
4735
4736 if isClient {
4737 suffix += "Client"
4738 } else {
4739 suffix += "Server"
4740 }
4741
4742 test := testCase{
4743 name: "TLSUnique-" + suffix,
4744 testTLSUnique: true,
4745 config: Config{
4746 Bugs: ProtocolBugs{
4747 NoExtendedMasterSecret: !hasEMS,
4748 },
4749 },
4750 }
4751
4752 if isResumption {
4753 test.resumeSession = true
4754 test.resumeConfig = &Config{
4755 Bugs: ProtocolBugs{
4756 NoExtendedMasterSecret: !hasEMS,
4757 },
4758 }
4759 }
4760
4761 if isResumption && !hasEMS {
4762 test.shouldFail = true
4763 test.expectedError = "failed to get tls-unique"
4764 }
4765
4766 testCases = append(testCases, test)
4767 }
4768 }
4769 }
4770}
4771
Adam Langley09505632015-07-30 18:10:13 -07004772func addCustomExtensionTests() {
4773 expectedContents := "custom extension"
4774 emptyString := ""
4775
4776 for _, isClient := range []bool{false, true} {
4777 suffix := "Server"
4778 flag := "-enable-server-custom-extension"
4779 testType := serverTest
4780 if isClient {
4781 suffix = "Client"
4782 flag = "-enable-client-custom-extension"
4783 testType = clientTest
4784 }
4785
4786 testCases = append(testCases, testCase{
4787 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004788 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004789 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004790 Bugs: ProtocolBugs{
4791 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004792 ExpectedCustomExtension: &expectedContents,
4793 },
4794 },
4795 flags: []string{flag},
4796 })
4797
4798 // If the parse callback fails, the handshake should also fail.
4799 testCases = append(testCases, testCase{
4800 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004801 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004802 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004803 Bugs: ProtocolBugs{
4804 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004805 ExpectedCustomExtension: &expectedContents,
4806 },
4807 },
David Benjamin399e7c92015-07-30 23:01:27 -04004808 flags: []string{flag},
4809 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004810 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4811 })
4812
4813 // If the add callback fails, the handshake should also fail.
4814 testCases = append(testCases, testCase{
4815 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004816 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004817 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004818 Bugs: ProtocolBugs{
4819 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004820 ExpectedCustomExtension: &expectedContents,
4821 },
4822 },
David Benjamin399e7c92015-07-30 23:01:27 -04004823 flags: []string{flag, "-custom-extension-fail-add"},
4824 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004825 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4826 })
4827
4828 // If the add callback returns zero, no extension should be
4829 // added.
4830 skipCustomExtension := expectedContents
4831 if isClient {
4832 // For the case where the client skips sending the
4833 // custom extension, the server must not “echo” it.
4834 skipCustomExtension = ""
4835 }
4836 testCases = append(testCases, testCase{
4837 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004838 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004839 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004840 Bugs: ProtocolBugs{
4841 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004842 ExpectedCustomExtension: &emptyString,
4843 },
4844 },
4845 flags: []string{flag, "-custom-extension-skip"},
4846 })
4847 }
4848
4849 // The custom extension add callback should not be called if the client
4850 // doesn't send the extension.
4851 testCases = append(testCases, testCase{
4852 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004853 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004854 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004855 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004856 ExpectedCustomExtension: &emptyString,
4857 },
4858 },
4859 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4860 })
Adam Langley2deb9842015-08-07 11:15:37 -07004861
4862 // Test an unknown extension from the server.
4863 testCases = append(testCases, testCase{
4864 testType: clientTest,
4865 name: "UnknownExtension-Client",
4866 config: Config{
4867 Bugs: ProtocolBugs{
4868 CustomExtension: expectedContents,
4869 },
4870 },
4871 shouldFail: true,
4872 expectedError: ":UNEXPECTED_EXTENSION:",
4873 })
Adam Langley09505632015-07-30 18:10:13 -07004874}
4875
David Benjaminb36a3952015-12-01 18:53:13 -05004876func addRSAClientKeyExchangeTests() {
4877 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
4881 config: Config{
4882 // Ensure the ClientHello version and final
4883 // version are different, to detect if the
4884 // server uses the wrong one.
4885 MaxVersion: VersionTLS11,
4886 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4887 Bugs: ProtocolBugs{
4888 BadRSAClientKeyExchange: bad,
4889 },
4890 },
4891 shouldFail: true,
4892 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
4893 })
4894 }
4895}
4896
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004897var testCurves = []struct {
4898 name string
4899 id CurveID
4900}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004901 {"P-256", CurveP256},
4902 {"P-384", CurveP384},
4903 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05004904 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004905}
4906
4907func addCurveTests() {
4908 for _, curve := range testCurves {
4909 testCases = append(testCases, testCase{
4910 name: "CurveTest-Client-" + curve.name,
4911 config: Config{
4912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4913 CurvePreferences: []CurveID{curve.id},
4914 },
4915 flags: []string{"-enable-all-curves"},
4916 })
4917 testCases = append(testCases, testCase{
4918 testType: serverTest,
4919 name: "CurveTest-Server-" + curve.name,
4920 config: Config{
4921 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4922 CurvePreferences: []CurveID{curve.id},
4923 },
4924 flags: []string{"-enable-all-curves"},
4925 })
4926 }
David Benjamin241ae832016-01-15 03:04:54 -05004927
4928 // The server must be tolerant to bogus curves.
4929 const bogusCurve = 0x1234
4930 testCases = append(testCases, testCase{
4931 testType: serverTest,
4932 name: "UnknownCurve",
4933 config: Config{
4934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4935 CurvePreferences: []CurveID{bogusCurve, CurveP256},
4936 },
4937 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05004938}
4939
David Benjamin4cc36ad2015-12-19 14:23:26 -05004940func addKeyExchangeInfoTests() {
4941 testCases = append(testCases, testCase{
4942 name: "KeyExchangeInfo-RSA-Client",
4943 config: Config{
4944 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4945 },
4946 // key.pem is a 1024-bit RSA key.
4947 flags: []string{"-expect-key-exchange-info", "1024"},
4948 })
4949 // TODO(davidben): key_exchange_info doesn't work for plain RSA on the
4950 // server. Either fix this or change the API as it's not very useful in
4951 // this case.
4952
4953 testCases = append(testCases, testCase{
4954 name: "KeyExchangeInfo-DHE-Client",
4955 config: Config{
4956 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
4957 Bugs: ProtocolBugs{
4958 // This is a 1234-bit prime number, generated
4959 // with:
4960 // openssl gendh 1234 | openssl asn1parse -i
4961 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
4962 },
4963 },
4964 flags: []string{"-expect-key-exchange-info", "1234"},
4965 })
4966 testCases = append(testCases, testCase{
4967 testType: serverTest,
4968 name: "KeyExchangeInfo-DHE-Server",
4969 config: Config{
4970 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
4971 },
4972 // bssl_shim as a server configures a 2048-bit DHE group.
4973 flags: []string{"-expect-key-exchange-info", "2048"},
4974 })
4975
4976 testCases = append(testCases, testCase{
4977 name: "KeyExchangeInfo-ECDHE-Client",
4978 config: Config{
4979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4980 CurvePreferences: []CurveID{CurveX25519},
4981 },
4982 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
4983 })
4984 testCases = append(testCases, testCase{
4985 testType: serverTest,
4986 name: "KeyExchangeInfo-ECDHE-Server",
4987 config: Config{
4988 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4989 CurvePreferences: []CurveID{CurveX25519},
4990 },
4991 flags: []string{"-expect-key-exchange-info", "29", "-enable-all-curves"},
4992 })
4993}
4994
Adam Langley7c803a62015-06-15 15:35:05 -07004995func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004996 defer wg.Done()
4997
4998 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004999 var err error
5000
5001 if *mallocTest < 0 {
5002 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005003 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08005004 } else {
5005 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
5006 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07005007 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08005008 if err != nil {
5009 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
5010 }
5011 break
5012 }
5013 }
5014 }
Adam Langley95c29f32014-06-20 12:00:00 -07005015 statusChan <- statusMsg{test: test, err: err}
5016 }
5017}
5018
5019type statusMsg struct {
5020 test *testCase
5021 started bool
5022 err error
5023}
5024
David Benjamin5f237bc2015-02-11 17:14:15 -05005025func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07005026 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07005027
David Benjamin5f237bc2015-02-11 17:14:15 -05005028 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07005029 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05005030 if !*pipe {
5031 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05005032 var erase string
5033 for i := 0; i < lineLen; i++ {
5034 erase += "\b \b"
5035 }
5036 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05005037 }
5038
Adam Langley95c29f32014-06-20 12:00:00 -07005039 if msg.started {
5040 started++
5041 } else {
5042 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05005043
5044 if msg.err != nil {
5045 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
5046 failed++
5047 testOutput.addResult(msg.test.name, "FAIL")
5048 } else {
5049 if *pipe {
5050 // Print each test instead of a status line.
5051 fmt.Printf("PASSED (%s)\n", msg.test.name)
5052 }
5053 testOutput.addResult(msg.test.name, "PASS")
5054 }
Adam Langley95c29f32014-06-20 12:00:00 -07005055 }
5056
David Benjamin5f237bc2015-02-11 17:14:15 -05005057 if !*pipe {
5058 // Print a new status line.
5059 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
5060 lineLen = len(line)
5061 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07005062 }
Adam Langley95c29f32014-06-20 12:00:00 -07005063 }
David Benjamin5f237bc2015-02-11 17:14:15 -05005064
5065 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07005066}
5067
5068func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07005069 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07005070 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07005071
Adam Langley7c803a62015-06-15 15:35:05 -07005072 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07005073 addCipherSuiteTests()
5074 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07005075 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07005076 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04005077 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08005078 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005079 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05005080 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04005081 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04005082 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07005083 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07005084 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05005085 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05005086 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05005087 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04005088 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07005089 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07005090 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05005091 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05005092 addCurveTests()
David Benjamin4cc36ad2015-12-19 14:23:26 -05005093 addKeyExchangeInfoTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04005094 for _, async := range []bool{false, true} {
5095 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04005096 for _, protocol := range []protocol{tls, dtls} {
5097 addStateMachineCoverageTests(async, splitHandshake, protocol)
5098 }
David Benjamin43ec06f2014-08-05 02:28:57 -04005099 }
5100 }
Adam Langley95c29f32014-06-20 12:00:00 -07005101
5102 var wg sync.WaitGroup
5103
Adam Langley7c803a62015-06-15 15:35:05 -07005104 statusChan := make(chan statusMsg, *numWorkers)
5105 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05005106 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07005107
David Benjamin025b3d32014-07-01 19:53:04 -04005108 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07005109
Adam Langley7c803a62015-06-15 15:35:05 -07005110 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07005111 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07005112 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07005113 }
5114
David Benjamin270f0a72016-03-17 14:41:36 -04005115 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04005116 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07005117 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin270f0a72016-03-17 14:41:36 -04005118 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04005119 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07005120 }
5121 }
David Benjamin270f0a72016-03-17 14:41:36 -04005122 if !foundTest {
5123 fmt.Fprintf(os.Stderr, "No test named '%s'\n", *testToRun)
5124 os.Exit(1)
5125 }
Adam Langley95c29f32014-06-20 12:00:00 -07005126
5127 close(testChan)
5128 wg.Wait()
5129 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05005130 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07005131
5132 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05005133
5134 if *jsonOutput != "" {
5135 if err := testOutput.writeTo(*jsonOutput); err != nil {
5136 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
5137 }
5138 }
David Benjamin2ab7a862015-04-04 17:02:18 -04005139
5140 if !testOutput.allPassed {
5141 os.Exit(1)
5142 }
Adam Langley95c29f32014-06-20 12:00:00 -07005143}