blob: 3c077bf47e58c5773bd0dc458845d982e5e82600 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001package main
2
3import (
4 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -04005 "crypto/ecdsa"
6 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -04007 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -04008 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -04009 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070010 "flag"
11 "fmt"
12 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070013 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070014 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070015 "net"
16 "os"
17 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040018 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040019 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080020 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070021 "strings"
22 "sync"
23 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050024 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070025)
26
Adam Langley69a01602014-11-17 17:26:55 -080027var (
David Benjamin5f237bc2015-02-11 17:14:15 -050028 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
29 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
30 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
31 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
32 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
33 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
34 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070035 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
36 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
37 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
38 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
Adam Langley69a01602014-11-17 17:26:55 -080039)
Adam Langley95c29f32014-06-20 12:00:00 -070040
David Benjamin025b3d32014-07-01 19:53:04 -040041const (
42 rsaCertificateFile = "cert.pem"
43 ecdsaCertificateFile = "ecdsa_cert.pem"
44)
45
46const (
David Benjamina08e49d2014-08-24 01:46:07 -040047 rsaKeyFile = "key.pem"
48 ecdsaKeyFile = "ecdsa_key.pem"
49 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040050)
51
Adam Langley95c29f32014-06-20 12:00:00 -070052var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040053var channelIDKey *ecdsa.PrivateKey
54var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070055
David Benjamin61f95272014-11-25 01:55:35 -050056var testOCSPResponse = []byte{1, 2, 3, 4}
57var testSCTList = []byte{5, 6, 7, 8}
58
Adam Langley95c29f32014-06-20 12:00:00 -070059func initCertificates() {
60 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070061 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070062 if err != nil {
63 panic(err)
64 }
David Benjamin61f95272014-11-25 01:55:35 -050065 rsaCertificate.OCSPStaple = testOCSPResponse
66 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070067
Adam Langley7c803a62015-06-15 15:35:05 -070068 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070069 if err != nil {
70 panic(err)
71 }
David Benjamin61f95272014-11-25 01:55:35 -050072 ecdsaCertificate.OCSPStaple = testOCSPResponse
73 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040074
Adam Langley7c803a62015-06-15 15:35:05 -070075 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040076 if err != nil {
77 panic(err)
78 }
79 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
80 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
81 panic("bad key type")
82 }
83 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
84 if err != nil {
85 panic(err)
86 }
87 if channelIDKey.Curve != elliptic.P256() {
88 panic("bad curve")
89 }
90
91 channelIDBytes = make([]byte, 64)
92 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
93 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070094}
95
96var certificateOnce sync.Once
97
98func getRSACertificate() Certificate {
99 certificateOnce.Do(initCertificates)
100 return rsaCertificate
101}
102
103func getECDSACertificate() Certificate {
104 certificateOnce.Do(initCertificates)
105 return ecdsaCertificate
106}
107
David Benjamin025b3d32014-07-01 19:53:04 -0400108type testType int
109
110const (
111 clientTest testType = iota
112 serverTest
113)
114
David Benjamin6fd297b2014-08-11 18:43:38 -0400115type protocol int
116
117const (
118 tls protocol = iota
119 dtls
120)
121
David Benjaminfc7b0862014-09-06 13:21:53 -0400122const (
123 alpn = 1
124 npn = 2
125)
126
Adam Langley95c29f32014-06-20 12:00:00 -0700127type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400128 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400129 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700130 name string
131 config Config
132 shouldFail bool
133 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700134 // expectedLocalError, if not empty, contains a substring that must be
135 // found in the local error.
136 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400137 // expectedVersion, if non-zero, specifies the TLS version that must be
138 // negotiated.
139 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400140 // expectedResumeVersion, if non-zero, specifies the TLS version that
141 // must be negotiated on resumption. If zero, expectedVersion is used.
142 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400143 // expectedCipher, if non-zero, specifies the TLS cipher suite that
144 // should be negotiated.
145 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400146 // expectChannelID controls whether the connection should have
147 // negotiated a Channel ID with channelIDKey.
148 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400149 // expectedNextProto controls whether the connection should
150 // negotiate a next protocol via NPN or ALPN.
151 expectedNextProto string
David Benjaminfc7b0862014-09-06 13:21:53 -0400152 // expectedNextProtoType, if non-zero, is the expected next
153 // protocol negotiation mechanism.
154 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500155 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
156 // should be negotiated. If zero, none should be negotiated.
157 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100158 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
159 expectedOCSPResponse []uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700160 // messageLen is the length, in bytes, of the test message that will be
161 // sent.
162 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400163 // messageCount is the number of test messages that will be sent.
164 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400165 // certFile is the path to the certificate to use for the server.
166 certFile string
167 // keyFile is the path to the private key to use for the server.
168 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400169 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400170 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400171 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700172 // expectResumeRejected, if true, specifies that the attempted
173 // resumption must be rejected by the client. This is only valid for a
174 // serverTest.
175 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400176 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500177 // resumption. Unless newSessionsOnResume is set,
178 // SessionTicketKey, ServerSessionCache, and
179 // ClientSessionCache are copied from the initial connection's
180 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400181 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500182 // newSessionsOnResume, if true, will cause resumeConfig to
183 // use a different session resumption context.
184 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400185 // noSessionCache, if true, will cause the server to run without a
186 // session cache.
187 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400188 // sendPrefix sends a prefix on the socket before actually performing a
189 // handshake.
190 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400191 // shimWritesFirst controls whether the shim sends an initial "hello"
192 // message before doing a roundtrip with the runner.
193 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400194 // shimShutsDown, if true, runs a test where the shim shuts down the
195 // connection immediately after the handshake rather than echoing
196 // messages from the runner.
197 shimShutsDown bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700198 // renegotiate indicates the the connection should be renegotiated
199 // during the exchange.
200 renegotiate bool
201 // renegotiateCiphers is a list of ciphersuite ids that will be
202 // switched in just before renegotiation.
203 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500204 // replayWrites, if true, configures the underlying transport
205 // to replay every write it makes in DTLS tests.
206 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500207 // damageFirstWrite, if true, configures the underlying transport to
208 // damage the final byte of the first application data write.
209 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400210 // exportKeyingMaterial, if non-zero, configures the test to exchange
211 // keying material and verify they match.
212 exportKeyingMaterial int
213 exportLabel string
214 exportContext string
215 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400216 // flags, if not empty, contains a list of command-line flags that will
217 // be passed to the shim program.
218 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700219 // testTLSUnique, if true, causes the shim to send the tls-unique value
220 // which will be compared against the expected value.
221 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400222 // sendEmptyRecords is the number of consecutive empty records to send
223 // before and after the test message.
224 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400225 // sendWarningAlerts is the number of consecutive warning alerts to send
226 // before and after the test message.
227 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400228 // expectMessageDropped, if true, means the test message is expected to
229 // be dropped by the client rather than echoed back.
230 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700231}
232
Adam Langley7c803a62015-06-15 15:35:05 -0700233var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700234
David Benjamin8e6db492015-07-25 18:29:23 -0400235func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -0500236 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500237 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500238 if *flagDebug {
239 connDebug = &recordingConn{Conn: conn}
240 conn = connDebug
241 defer func() {
242 connDebug.WriteTo(os.Stdout)
243 }()
244 }
245
David Benjamin6fd297b2014-08-11 18:43:38 -0400246 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500247 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
248 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500249 if test.replayWrites {
250 conn = newReplayAdaptor(conn)
251 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400252 }
253
David Benjamin5fa3eba2015-01-22 16:35:40 -0500254 if test.damageFirstWrite {
255 connDamage = newDamageAdaptor(conn)
256 conn = connDamage
257 }
258
David Benjamin6fd297b2014-08-11 18:43:38 -0400259 if test.sendPrefix != "" {
260 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
261 return err
262 }
David Benjamin98e882e2014-08-08 13:24:34 -0400263 }
264
David Benjamin1d5c83e2014-07-22 19:20:02 -0400265 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400266 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400267 if test.protocol == dtls {
268 tlsConn = DTLSServer(conn, config)
269 } else {
270 tlsConn = Server(conn, config)
271 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400272 } else {
273 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400274 if test.protocol == dtls {
275 tlsConn = DTLSClient(conn, config)
276 } else {
277 tlsConn = Client(conn, config)
278 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400279 }
David Benjamin30789da2015-08-29 22:56:45 -0400280 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400281
Adam Langley95c29f32014-06-20 12:00:00 -0700282 if err := tlsConn.Handshake(); err != nil {
283 return err
284 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700285
David Benjamin01fe8202014-09-24 15:21:44 -0400286 // TODO(davidben): move all per-connection expectations into a dedicated
287 // expectations struct that can be specified separately for the two
288 // legs.
289 expectedVersion := test.expectedVersion
290 if isResume && test.expectedResumeVersion != 0 {
291 expectedVersion = test.expectedResumeVersion
292 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700293 connState := tlsConn.ConnectionState()
294 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400295 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400296 }
297
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700298 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400299 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
300 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700301 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
302 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
303 }
David Benjamin90da8c82015-04-20 14:57:57 -0400304
David Benjamina08e49d2014-08-24 01:46:07 -0400305 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700306 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400307 if channelID == nil {
308 return fmt.Errorf("no channel ID negotiated")
309 }
310 if channelID.Curve != channelIDKey.Curve ||
311 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
312 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
313 return fmt.Errorf("incorrect channel ID")
314 }
315 }
316
David Benjaminae2888f2014-09-06 12:58:58 -0400317 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700318 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400319 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
320 }
321 }
322
David Benjaminfc7b0862014-09-06 13:21:53 -0400323 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700324 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400325 return fmt.Errorf("next proto type mismatch")
326 }
327 }
328
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700329 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500330 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
331 }
332
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100333 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
334 return fmt.Errorf("OCSP Response mismatch")
335 }
336
David Benjaminc565ebb2015-04-03 04:06:36 -0400337 if test.exportKeyingMaterial > 0 {
338 actual := make([]byte, test.exportKeyingMaterial)
339 if _, err := io.ReadFull(tlsConn, actual); err != nil {
340 return err
341 }
342 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
343 if err != nil {
344 return err
345 }
346 if !bytes.Equal(actual, expected) {
347 return fmt.Errorf("keying material mismatch")
348 }
349 }
350
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700351 if test.testTLSUnique {
352 var peersValue [12]byte
353 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
354 return err
355 }
356 expected := tlsConn.ConnectionState().TLSUnique
357 if !bytes.Equal(peersValue[:], expected) {
358 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
359 }
360 }
361
David Benjamine58c4f52014-08-24 03:47:07 -0400362 if test.shimWritesFirst {
363 var buf [5]byte
364 _, err := io.ReadFull(tlsConn, buf[:])
365 if err != nil {
366 return err
367 }
368 if string(buf[:]) != "hello" {
369 return fmt.Errorf("bad initial message")
370 }
371 }
372
David Benjamina8ebe222015-06-06 03:04:39 -0400373 for i := 0; i < test.sendEmptyRecords; i++ {
374 tlsConn.Write(nil)
375 }
376
David Benjamin24f346d2015-06-06 03:28:08 -0400377 for i := 0; i < test.sendWarningAlerts; i++ {
378 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
379 }
380
Adam Langleycf2d4f42014-10-28 19:06:14 -0700381 if test.renegotiate {
382 if test.renegotiateCiphers != nil {
383 config.CipherSuites = test.renegotiateCiphers
384 }
385 if err := tlsConn.Renegotiate(); err != nil {
386 return err
387 }
388 } else if test.renegotiateCiphers != nil {
389 panic("renegotiateCiphers without renegotiate")
390 }
391
David Benjamin5fa3eba2015-01-22 16:35:40 -0500392 if test.damageFirstWrite {
393 connDamage.setDamage(true)
394 tlsConn.Write([]byte("DAMAGED WRITE"))
395 connDamage.setDamage(false)
396 }
397
David Benjamin8e6db492015-07-25 18:29:23 -0400398 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700399 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400400 if test.protocol == dtls {
401 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
402 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700403 // Read until EOF.
404 _, err := io.Copy(ioutil.Discard, tlsConn)
405 return err
406 }
David Benjamin4417d052015-04-05 04:17:25 -0400407 if messageLen == 0 {
408 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700409 }
Adam Langley95c29f32014-06-20 12:00:00 -0700410
David Benjamin8e6db492015-07-25 18:29:23 -0400411 messageCount := test.messageCount
412 if messageCount == 0 {
413 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400414 }
415
David Benjamin8e6db492015-07-25 18:29:23 -0400416 for j := 0; j < messageCount; j++ {
417 testMessage := make([]byte, messageLen)
418 for i := range testMessage {
419 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400420 }
David Benjamin8e6db492015-07-25 18:29:23 -0400421 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700422
David Benjamin8e6db492015-07-25 18:29:23 -0400423 for i := 0; i < test.sendEmptyRecords; i++ {
424 tlsConn.Write(nil)
425 }
426
427 for i := 0; i < test.sendWarningAlerts; i++ {
428 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
429 }
430
David Benjamin4f75aaf2015-09-01 16:53:10 -0400431 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400432 // The shim will not respond.
433 continue
434 }
435
David Benjamin8e6db492015-07-25 18:29:23 -0400436 buf := make([]byte, len(testMessage))
437 if test.protocol == dtls {
438 bufTmp := make([]byte, len(buf)+1)
439 n, err := tlsConn.Read(bufTmp)
440 if err != nil {
441 return err
442 }
443 if n != len(buf) {
444 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
445 }
446 copy(buf, bufTmp)
447 } else {
448 _, err := io.ReadFull(tlsConn, buf)
449 if err != nil {
450 return err
451 }
452 }
453
454 for i, v := range buf {
455 if v != testMessage[i]^0xff {
456 return fmt.Errorf("bad reply contents at byte %d", i)
457 }
Adam Langley95c29f32014-06-20 12:00:00 -0700458 }
459 }
460
461 return nil
462}
463
David Benjamin325b5c32014-07-01 19:40:31 -0400464func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
465 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700466 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400467 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700468 }
David Benjamin325b5c32014-07-01 19:40:31 -0400469 valgrindArgs = append(valgrindArgs, path)
470 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700471
David Benjamin325b5c32014-07-01 19:40:31 -0400472 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700473}
474
David Benjamin325b5c32014-07-01 19:40:31 -0400475func gdbOf(path string, args ...string) *exec.Cmd {
476 xtermArgs := []string{"-e", "gdb", "--args"}
477 xtermArgs = append(xtermArgs, path)
478 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700479
David Benjamin325b5c32014-07-01 19:40:31 -0400480 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700481}
482
Adam Langley69a01602014-11-17 17:26:55 -0800483type moreMallocsError struct{}
484
485func (moreMallocsError) Error() string {
486 return "child process did not exhaust all allocation calls"
487}
488
489var errMoreMallocs = moreMallocsError{}
490
David Benjamin87c8a642015-02-21 01:54:29 -0500491// accept accepts a connection from listener, unless waitChan signals a process
492// exit first.
493func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
494 type connOrError struct {
495 conn net.Conn
496 err error
497 }
498 connChan := make(chan connOrError, 1)
499 go func() {
500 conn, err := listener.Accept()
501 connChan <- connOrError{conn, err}
502 close(connChan)
503 }()
504 select {
505 case result := <-connChan:
506 return result.conn, result.err
507 case childErr := <-waitChan:
508 waitChan <- childErr
509 return nil, fmt.Errorf("child exited early: %s", childErr)
510 }
511}
512
Adam Langley7c803a62015-06-15 15:35:05 -0700513func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700514 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
515 panic("Error expected without shouldFail in " + test.name)
516 }
517
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700518 if test.expectResumeRejected && !test.resumeSession {
519 panic("expectResumeRejected without resumeSession in " + test.name)
520 }
521
David Benjamin87c8a642015-02-21 01:54:29 -0500522 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
523 if err != nil {
524 panic(err)
525 }
526 defer func() {
527 if listener != nil {
528 listener.Close()
529 }
530 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700531
David Benjamin87c8a642015-02-21 01:54:29 -0500532 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400533 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400534 flags = append(flags, "-server")
535
David Benjamin025b3d32014-07-01 19:53:04 -0400536 flags = append(flags, "-key-file")
537 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700538 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400539 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700540 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400541 }
542
543 flags = append(flags, "-cert-file")
544 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700545 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400546 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700547 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400548 }
549 }
David Benjamin5a593af2014-08-11 19:51:50 -0400550
David Benjamin6fd297b2014-08-11 18:43:38 -0400551 if test.protocol == dtls {
552 flags = append(flags, "-dtls")
553 }
554
David Benjamin5a593af2014-08-11 19:51:50 -0400555 if test.resumeSession {
556 flags = append(flags, "-resume")
557 }
558
David Benjamine58c4f52014-08-24 03:47:07 -0400559 if test.shimWritesFirst {
560 flags = append(flags, "-shim-writes-first")
561 }
562
David Benjamin30789da2015-08-29 22:56:45 -0400563 if test.shimShutsDown {
564 flags = append(flags, "-shim-shuts-down")
565 }
566
David Benjaminc565ebb2015-04-03 04:06:36 -0400567 if test.exportKeyingMaterial > 0 {
568 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
569 flags = append(flags, "-export-label", test.exportLabel)
570 flags = append(flags, "-export-context", test.exportContext)
571 if test.useExportContext {
572 flags = append(flags, "-use-export-context")
573 }
574 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700575 if test.expectResumeRejected {
576 flags = append(flags, "-expect-session-miss")
577 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400578
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700579 if test.testTLSUnique {
580 flags = append(flags, "-tls-unique")
581 }
582
David Benjamin025b3d32014-07-01 19:53:04 -0400583 flags = append(flags, test.flags...)
584
585 var shim *exec.Cmd
586 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700587 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700588 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700589 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400590 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700591 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400592 }
David Benjamin025b3d32014-07-01 19:53:04 -0400593 shim.Stdin = os.Stdin
594 var stdoutBuf, stderrBuf bytes.Buffer
595 shim.Stdout = &stdoutBuf
596 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800597 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500598 shim.Env = os.Environ()
599 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800600 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400601 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800602 }
603 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
604 }
David Benjamin025b3d32014-07-01 19:53:04 -0400605
606 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700607 panic(err)
608 }
David Benjamin87c8a642015-02-21 01:54:29 -0500609 waitChan := make(chan error, 1)
610 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700611
612 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400613 if !test.noSessionCache {
614 config.ClientSessionCache = NewLRUClientSessionCache(1)
615 config.ServerSessionCache = NewLRUServerSessionCache(1)
616 }
David Benjamin025b3d32014-07-01 19:53:04 -0400617 if test.testType == clientTest {
618 if len(config.Certificates) == 0 {
619 config.Certificates = []Certificate{getRSACertificate()}
620 }
David Benjamin87c8a642015-02-21 01:54:29 -0500621 } else {
622 // Supply a ServerName to ensure a constant session cache key,
623 // rather than falling back to net.Conn.RemoteAddr.
624 if len(config.ServerName) == 0 {
625 config.ServerName = "test"
626 }
David Benjamin025b3d32014-07-01 19:53:04 -0400627 }
Adam Langley95c29f32014-06-20 12:00:00 -0700628
David Benjamin87c8a642015-02-21 01:54:29 -0500629 conn, err := acceptOrWait(listener, waitChan)
630 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400631 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500632 conn.Close()
633 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500634
David Benjamin1d5c83e2014-07-22 19:20:02 -0400635 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400636 var resumeConfig Config
637 if test.resumeConfig != nil {
638 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500639 if len(resumeConfig.ServerName) == 0 {
640 resumeConfig.ServerName = config.ServerName
641 }
David Benjamin01fe8202014-09-24 15:21:44 -0400642 if len(resumeConfig.Certificates) == 0 {
643 resumeConfig.Certificates = []Certificate{getRSACertificate()}
644 }
David Benjaminba4594a2015-06-18 18:36:15 -0400645 if test.newSessionsOnResume {
646 if !test.noSessionCache {
647 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
648 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
649 }
650 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500651 resumeConfig.SessionTicketKey = config.SessionTicketKey
652 resumeConfig.ClientSessionCache = config.ClientSessionCache
653 resumeConfig.ServerSessionCache = config.ServerSessionCache
654 }
David Benjamin01fe8202014-09-24 15:21:44 -0400655 } else {
656 resumeConfig = config
657 }
David Benjamin87c8a642015-02-21 01:54:29 -0500658 var connResume net.Conn
659 connResume, err = acceptOrWait(listener, waitChan)
660 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400661 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500662 connResume.Close()
663 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400664 }
665
David Benjamin87c8a642015-02-21 01:54:29 -0500666 // Close the listener now. This is to avoid hangs should the shim try to
667 // open more connections than expected.
668 listener.Close()
669 listener = nil
670
671 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800672 if exitError, ok := childErr.(*exec.ExitError); ok {
673 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
674 return errMoreMallocs
675 }
676 }
Adam Langley95c29f32014-06-20 12:00:00 -0700677
678 stdout := string(stdoutBuf.Bytes())
679 stderr := string(stderrBuf.Bytes())
680 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400681 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700682 localError := "none"
683 if err != nil {
684 localError = err.Error()
685 }
686 if len(test.expectedLocalError) != 0 {
687 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
688 }
Adam Langley95c29f32014-06-20 12:00:00 -0700689
690 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700691 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700692 if childErr != nil {
693 childError = childErr.Error()
694 }
695
696 var msg string
697 switch {
698 case failed && !test.shouldFail:
699 msg = "unexpected failure"
700 case !failed && test.shouldFail:
701 msg = "unexpected success"
702 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700703 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700704 default:
705 panic("internal error")
706 }
707
David Benjaminc565ebb2015-04-03 04:06:36 -0400708 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 -0700709 }
710
David Benjaminc565ebb2015-04-03 04:06:36 -0400711 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700712 println(stderr)
713 }
714
715 return nil
716}
717
718var tlsVersions = []struct {
719 name string
720 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400721 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500722 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700723}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500724 {"SSL3", VersionSSL30, "-no-ssl3", false},
725 {"TLS1", VersionTLS10, "-no-tls1", true},
726 {"TLS11", VersionTLS11, "-no-tls11", false},
727 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700728}
729
730var testCipherSuites = []struct {
731 name string
732 id uint16
733}{
734 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400735 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700736 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400737 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400738 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700739 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400740 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400741 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
742 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400743 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400744 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
745 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400746 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700747 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
748 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400749 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
750 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700751 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400752 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400753 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700754 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700755 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700756 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400757 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400758 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700759 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400760 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400761 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700762 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400763 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
764 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700765 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
766 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400767 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700768 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400769 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700770}
771
David Benjamin8b8c0062014-11-23 02:47:52 -0500772func hasComponent(suiteName, component string) bool {
773 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
774}
775
David Benjaminf7768e42014-08-31 02:06:47 -0400776func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500777 return hasComponent(suiteName, "GCM") ||
778 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400779 hasComponent(suiteName, "SHA384") ||
780 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500781}
782
783func isDTLSCipher(suiteName string) bool {
David Benjamine95d20d2014-12-23 11:16:01 -0500784 return !hasComponent(suiteName, "RC4")
David Benjaminf7768e42014-08-31 02:06:47 -0400785}
786
Adam Langleya7997f12015-05-14 17:38:50 -0700787func bigFromHex(hex string) *big.Int {
788 ret, ok := new(big.Int).SetString(hex, 16)
789 if !ok {
790 panic("failed to parse hex number 0x" + hex)
791 }
792 return ret
793}
794
Adam Langley7c803a62015-06-15 15:35:05 -0700795func addBasicTests() {
796 basicTests := []testCase{
797 {
798 name: "BadRSASignature",
799 config: Config{
800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
801 Bugs: ProtocolBugs{
802 InvalidSKXSignature: true,
803 },
804 },
805 shouldFail: true,
806 expectedError: ":BAD_SIGNATURE:",
807 },
808 {
809 name: "BadECDSASignature",
810 config: Config{
811 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
812 Bugs: ProtocolBugs{
813 InvalidSKXSignature: true,
814 },
815 Certificates: []Certificate{getECDSACertificate()},
816 },
817 shouldFail: true,
818 expectedError: ":BAD_SIGNATURE:",
819 },
820 {
David Benjamin6de0e532015-07-28 22:43:19 -0400821 testType: serverTest,
822 name: "BadRSASignature-ClientAuth",
823 config: Config{
824 Bugs: ProtocolBugs{
825 InvalidCertVerifySignature: true,
826 },
827 Certificates: []Certificate{getRSACertificate()},
828 },
829 shouldFail: true,
830 expectedError: ":BAD_SIGNATURE:",
831 flags: []string{"-require-any-client-certificate"},
832 },
833 {
834 testType: serverTest,
835 name: "BadECDSASignature-ClientAuth",
836 config: Config{
837 Bugs: ProtocolBugs{
838 InvalidCertVerifySignature: true,
839 },
840 Certificates: []Certificate{getECDSACertificate()},
841 },
842 shouldFail: true,
843 expectedError: ":BAD_SIGNATURE:",
844 flags: []string{"-require-any-client-certificate"},
845 },
846 {
Adam Langley7c803a62015-06-15 15:35:05 -0700847 name: "BadECDSACurve",
848 config: Config{
849 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
850 Bugs: ProtocolBugs{
851 InvalidSKXCurve: true,
852 },
853 Certificates: []Certificate{getECDSACertificate()},
854 },
855 shouldFail: true,
856 expectedError: ":WRONG_CURVE:",
857 },
858 {
859 testType: serverTest,
860 name: "BadRSAVersion",
861 config: Config{
862 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
863 Bugs: ProtocolBugs{
864 RsaClientKeyExchangeVersion: VersionTLS11,
865 },
866 },
867 shouldFail: true,
868 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
869 },
870 {
871 name: "NoFallbackSCSV",
872 config: Config{
873 Bugs: ProtocolBugs{
874 FailIfNotFallbackSCSV: true,
875 },
876 },
877 shouldFail: true,
878 expectedLocalError: "no fallback SCSV found",
879 },
880 {
881 name: "SendFallbackSCSV",
882 config: Config{
883 Bugs: ProtocolBugs{
884 FailIfNotFallbackSCSV: true,
885 },
886 },
887 flags: []string{"-fallback-scsv"},
888 },
889 {
890 name: "ClientCertificateTypes",
891 config: Config{
892 ClientAuth: RequestClientCert,
893 ClientCertificateTypes: []byte{
894 CertTypeDSSSign,
895 CertTypeRSASign,
896 CertTypeECDSASign,
897 },
898 },
899 flags: []string{
900 "-expect-certificate-types",
901 base64.StdEncoding.EncodeToString([]byte{
902 CertTypeDSSSign,
903 CertTypeRSASign,
904 CertTypeECDSASign,
905 }),
906 },
907 },
908 {
909 name: "NoClientCertificate",
910 config: Config{
911 ClientAuth: RequireAnyClientCert,
912 },
913 shouldFail: true,
914 expectedLocalError: "client didn't provide a certificate",
915 },
916 {
917 name: "UnauthenticatedECDH",
918 config: Config{
919 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
920 Bugs: ProtocolBugs{
921 UnauthenticatedECDH: true,
922 },
923 },
924 shouldFail: true,
925 expectedError: ":UNEXPECTED_MESSAGE:",
926 },
927 {
928 name: "SkipCertificateStatus",
929 config: Config{
930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
931 Bugs: ProtocolBugs{
932 SkipCertificateStatus: true,
933 },
934 },
935 flags: []string{
936 "-enable-ocsp-stapling",
937 },
938 },
939 {
940 name: "SkipServerKeyExchange",
941 config: Config{
942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
943 Bugs: ProtocolBugs{
944 SkipServerKeyExchange: true,
945 },
946 },
947 shouldFail: true,
948 expectedError: ":UNEXPECTED_MESSAGE:",
949 },
950 {
951 name: "SkipChangeCipherSpec-Client",
952 config: Config{
953 Bugs: ProtocolBugs{
954 SkipChangeCipherSpec: true,
955 },
956 },
957 shouldFail: true,
958 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
959 },
960 {
961 testType: serverTest,
962 name: "SkipChangeCipherSpec-Server",
963 config: Config{
964 Bugs: ProtocolBugs{
965 SkipChangeCipherSpec: true,
966 },
967 },
968 shouldFail: true,
969 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
970 },
971 {
972 testType: serverTest,
973 name: "SkipChangeCipherSpec-Server-NPN",
974 config: Config{
975 NextProtos: []string{"bar"},
976 Bugs: ProtocolBugs{
977 SkipChangeCipherSpec: true,
978 },
979 },
980 flags: []string{
981 "-advertise-npn", "\x03foo\x03bar\x03baz",
982 },
983 shouldFail: true,
984 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
985 },
986 {
987 name: "FragmentAcrossChangeCipherSpec-Client",
988 config: Config{
989 Bugs: ProtocolBugs{
990 FragmentAcrossChangeCipherSpec: true,
991 },
992 },
993 shouldFail: true,
994 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
995 },
996 {
997 testType: serverTest,
998 name: "FragmentAcrossChangeCipherSpec-Server",
999 config: Config{
1000 Bugs: ProtocolBugs{
1001 FragmentAcrossChangeCipherSpec: true,
1002 },
1003 },
1004 shouldFail: true,
1005 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1006 },
1007 {
1008 testType: serverTest,
1009 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1010 config: Config{
1011 NextProtos: []string{"bar"},
1012 Bugs: ProtocolBugs{
1013 FragmentAcrossChangeCipherSpec: true,
1014 },
1015 },
1016 flags: []string{
1017 "-advertise-npn", "\x03foo\x03bar\x03baz",
1018 },
1019 shouldFail: true,
1020 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1021 },
1022 {
1023 testType: serverTest,
1024 name: "Alert",
1025 config: Config{
1026 Bugs: ProtocolBugs{
1027 SendSpuriousAlert: alertRecordOverflow,
1028 },
1029 },
1030 shouldFail: true,
1031 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1032 },
1033 {
1034 protocol: dtls,
1035 testType: serverTest,
1036 name: "Alert-DTLS",
1037 config: Config{
1038 Bugs: ProtocolBugs{
1039 SendSpuriousAlert: alertRecordOverflow,
1040 },
1041 },
1042 shouldFail: true,
1043 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1044 },
1045 {
1046 testType: serverTest,
1047 name: "FragmentAlert",
1048 config: Config{
1049 Bugs: ProtocolBugs{
1050 FragmentAlert: true,
1051 SendSpuriousAlert: alertRecordOverflow,
1052 },
1053 },
1054 shouldFail: true,
1055 expectedError: ":BAD_ALERT:",
1056 },
1057 {
1058 protocol: dtls,
1059 testType: serverTest,
1060 name: "FragmentAlert-DTLS",
1061 config: Config{
1062 Bugs: ProtocolBugs{
1063 FragmentAlert: true,
1064 SendSpuriousAlert: alertRecordOverflow,
1065 },
1066 },
1067 shouldFail: true,
1068 expectedError: ":BAD_ALERT:",
1069 },
1070 {
1071 testType: serverTest,
1072 name: "EarlyChangeCipherSpec-server-1",
1073 config: Config{
1074 Bugs: ProtocolBugs{
1075 EarlyChangeCipherSpec: 1,
1076 },
1077 },
1078 shouldFail: true,
1079 expectedError: ":CCS_RECEIVED_EARLY:",
1080 },
1081 {
1082 testType: serverTest,
1083 name: "EarlyChangeCipherSpec-server-2",
1084 config: Config{
1085 Bugs: ProtocolBugs{
1086 EarlyChangeCipherSpec: 2,
1087 },
1088 },
1089 shouldFail: true,
1090 expectedError: ":CCS_RECEIVED_EARLY:",
1091 },
1092 {
1093 name: "SkipNewSessionTicket",
1094 config: Config{
1095 Bugs: ProtocolBugs{
1096 SkipNewSessionTicket: true,
1097 },
1098 },
1099 shouldFail: true,
1100 expectedError: ":CCS_RECEIVED_EARLY:",
1101 },
1102 {
1103 testType: serverTest,
1104 name: "FallbackSCSV",
1105 config: Config{
1106 MaxVersion: VersionTLS11,
1107 Bugs: ProtocolBugs{
1108 SendFallbackSCSV: true,
1109 },
1110 },
1111 shouldFail: true,
1112 expectedError: ":INAPPROPRIATE_FALLBACK:",
1113 },
1114 {
1115 testType: serverTest,
1116 name: "FallbackSCSV-VersionMatch",
1117 config: Config{
1118 Bugs: ProtocolBugs{
1119 SendFallbackSCSV: true,
1120 },
1121 },
1122 },
1123 {
1124 testType: serverTest,
1125 name: "FragmentedClientVersion",
1126 config: Config{
1127 Bugs: ProtocolBugs{
1128 MaxHandshakeRecordLength: 1,
1129 FragmentClientVersion: true,
1130 },
1131 },
1132 expectedVersion: VersionTLS12,
1133 },
1134 {
1135 testType: serverTest,
1136 name: "MinorVersionTolerance",
1137 config: Config{
1138 Bugs: ProtocolBugs{
1139 SendClientVersion: 0x03ff,
1140 },
1141 },
1142 expectedVersion: VersionTLS12,
1143 },
1144 {
1145 testType: serverTest,
1146 name: "MajorVersionTolerance",
1147 config: Config{
1148 Bugs: ProtocolBugs{
1149 SendClientVersion: 0x0400,
1150 },
1151 },
1152 expectedVersion: VersionTLS12,
1153 },
1154 {
1155 testType: serverTest,
1156 name: "VersionTooLow",
1157 config: Config{
1158 Bugs: ProtocolBugs{
1159 SendClientVersion: 0x0200,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNSUPPORTED_PROTOCOL:",
1164 },
1165 {
1166 testType: serverTest,
1167 name: "HttpGET",
1168 sendPrefix: "GET / HTTP/1.0\n",
1169 shouldFail: true,
1170 expectedError: ":HTTP_REQUEST:",
1171 },
1172 {
1173 testType: serverTest,
1174 name: "HttpPOST",
1175 sendPrefix: "POST / HTTP/1.0\n",
1176 shouldFail: true,
1177 expectedError: ":HTTP_REQUEST:",
1178 },
1179 {
1180 testType: serverTest,
1181 name: "HttpHEAD",
1182 sendPrefix: "HEAD / HTTP/1.0\n",
1183 shouldFail: true,
1184 expectedError: ":HTTP_REQUEST:",
1185 },
1186 {
1187 testType: serverTest,
1188 name: "HttpPUT",
1189 sendPrefix: "PUT / HTTP/1.0\n",
1190 shouldFail: true,
1191 expectedError: ":HTTP_REQUEST:",
1192 },
1193 {
1194 testType: serverTest,
1195 name: "HttpCONNECT",
1196 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1197 shouldFail: true,
1198 expectedError: ":HTTPS_PROXY_REQUEST:",
1199 },
1200 {
1201 testType: serverTest,
1202 name: "Garbage",
1203 sendPrefix: "blah",
1204 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001205 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001206 },
1207 {
1208 name: "SkipCipherVersionCheck",
1209 config: Config{
1210 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1211 MaxVersion: VersionTLS11,
1212 Bugs: ProtocolBugs{
1213 SkipCipherVersionCheck: true,
1214 },
1215 },
1216 shouldFail: true,
1217 expectedError: ":WRONG_CIPHER_RETURNED:",
1218 },
1219 {
1220 name: "RSAEphemeralKey",
1221 config: Config{
1222 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1223 Bugs: ProtocolBugs{
1224 RSAEphemeralKey: true,
1225 },
1226 },
1227 shouldFail: true,
1228 expectedError: ":UNEXPECTED_MESSAGE:",
1229 },
1230 {
1231 name: "DisableEverything",
1232 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1233 shouldFail: true,
1234 expectedError: ":WRONG_SSL_VERSION:",
1235 },
1236 {
1237 protocol: dtls,
1238 name: "DisableEverything-DTLS",
1239 flags: []string{"-no-tls12", "-no-tls1"},
1240 shouldFail: true,
1241 expectedError: ":WRONG_SSL_VERSION:",
1242 },
1243 {
1244 name: "NoSharedCipher",
1245 config: Config{
1246 CipherSuites: []uint16{},
1247 },
1248 shouldFail: true,
1249 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1250 },
1251 {
1252 protocol: dtls,
1253 testType: serverTest,
1254 name: "MTU",
1255 config: Config{
1256 Bugs: ProtocolBugs{
1257 MaxPacketLength: 256,
1258 },
1259 },
1260 flags: []string{"-mtu", "256"},
1261 },
1262 {
1263 protocol: dtls,
1264 testType: serverTest,
1265 name: "MTUExceeded",
1266 config: Config{
1267 Bugs: ProtocolBugs{
1268 MaxPacketLength: 255,
1269 },
1270 },
1271 flags: []string{"-mtu", "256"},
1272 shouldFail: true,
1273 expectedLocalError: "dtls: exceeded maximum packet length",
1274 },
1275 {
1276 name: "CertMismatchRSA",
1277 config: Config{
1278 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1279 Certificates: []Certificate{getECDSACertificate()},
1280 Bugs: ProtocolBugs{
1281 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1282 },
1283 },
1284 shouldFail: true,
1285 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1286 },
1287 {
1288 name: "CertMismatchECDSA",
1289 config: Config{
1290 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1291 Certificates: []Certificate{getRSACertificate()},
1292 Bugs: ProtocolBugs{
1293 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1294 },
1295 },
1296 shouldFail: true,
1297 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1298 },
1299 {
1300 name: "EmptyCertificateList",
1301 config: Config{
1302 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1303 Bugs: ProtocolBugs{
1304 EmptyCertificateList: true,
1305 },
1306 },
1307 shouldFail: true,
1308 expectedError: ":DECODE_ERROR:",
1309 },
1310 {
1311 name: "TLSFatalBadPackets",
1312 damageFirstWrite: true,
1313 shouldFail: true,
1314 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1315 },
1316 {
1317 protocol: dtls,
1318 name: "DTLSIgnoreBadPackets",
1319 damageFirstWrite: true,
1320 },
1321 {
1322 protocol: dtls,
1323 name: "DTLSIgnoreBadPackets-Async",
1324 damageFirstWrite: true,
1325 flags: []string{"-async"},
1326 },
1327 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001328 name: "AppDataBeforeHandshake",
1329 config: Config{
1330 Bugs: ProtocolBugs{
1331 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1332 },
1333 },
1334 shouldFail: true,
1335 expectedError: ":UNEXPECTED_RECORD:",
1336 },
1337 {
1338 name: "AppDataBeforeHandshake-Empty",
1339 config: Config{
1340 Bugs: ProtocolBugs{
1341 AppDataBeforeHandshake: []byte{},
1342 },
1343 },
1344 shouldFail: true,
1345 expectedError: ":UNEXPECTED_RECORD:",
1346 },
1347 {
1348 protocol: dtls,
1349 name: "AppDataBeforeHandshake-DTLS",
1350 config: Config{
1351 Bugs: ProtocolBugs{
1352 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1353 },
1354 },
1355 shouldFail: true,
1356 expectedError: ":UNEXPECTED_RECORD:",
1357 },
1358 {
1359 protocol: dtls,
1360 name: "AppDataBeforeHandshake-DTLS-Empty",
1361 config: Config{
1362 Bugs: ProtocolBugs{
1363 AppDataBeforeHandshake: []byte{},
1364 },
1365 },
1366 shouldFail: true,
1367 expectedError: ":UNEXPECTED_RECORD:",
1368 },
1369 {
Adam Langley7c803a62015-06-15 15:35:05 -07001370 name: "AppDataAfterChangeCipherSpec",
1371 config: Config{
1372 Bugs: ProtocolBugs{
1373 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1374 },
1375 },
1376 shouldFail: true,
1377 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1378 },
1379 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001380 name: "AppDataAfterChangeCipherSpec-Empty",
1381 config: Config{
1382 Bugs: ProtocolBugs{
1383 AppDataAfterChangeCipherSpec: []byte{},
1384 },
1385 },
1386 shouldFail: true,
1387 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1388 },
1389 {
Adam Langley7c803a62015-06-15 15:35:05 -07001390 protocol: dtls,
1391 name: "AppDataAfterChangeCipherSpec-DTLS",
1392 config: Config{
1393 Bugs: ProtocolBugs{
1394 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1395 },
1396 },
1397 // BoringSSL's DTLS implementation will drop the out-of-order
1398 // application data.
1399 },
1400 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001401 protocol: dtls,
1402 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1403 config: Config{
1404 Bugs: ProtocolBugs{
1405 AppDataAfterChangeCipherSpec: []byte{},
1406 },
1407 },
1408 // BoringSSL's DTLS implementation will drop the out-of-order
1409 // application data.
1410 },
1411 {
Adam Langley7c803a62015-06-15 15:35:05 -07001412 name: "AlertAfterChangeCipherSpec",
1413 config: Config{
1414 Bugs: ProtocolBugs{
1415 AlertAfterChangeCipherSpec: alertRecordOverflow,
1416 },
1417 },
1418 shouldFail: true,
1419 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1420 },
1421 {
1422 protocol: dtls,
1423 name: "AlertAfterChangeCipherSpec-DTLS",
1424 config: Config{
1425 Bugs: ProtocolBugs{
1426 AlertAfterChangeCipherSpec: alertRecordOverflow,
1427 },
1428 },
1429 shouldFail: true,
1430 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1431 },
1432 {
1433 protocol: dtls,
1434 name: "ReorderHandshakeFragments-Small-DTLS",
1435 config: Config{
1436 Bugs: ProtocolBugs{
1437 ReorderHandshakeFragments: true,
1438 // Small enough that every handshake message is
1439 // fragmented.
1440 MaxHandshakeRecordLength: 2,
1441 },
1442 },
1443 },
1444 {
1445 protocol: dtls,
1446 name: "ReorderHandshakeFragments-Large-DTLS",
1447 config: Config{
1448 Bugs: ProtocolBugs{
1449 ReorderHandshakeFragments: true,
1450 // Large enough that no handshake message is
1451 // fragmented.
1452 MaxHandshakeRecordLength: 2048,
1453 },
1454 },
1455 },
1456 {
1457 protocol: dtls,
1458 name: "MixCompleteMessageWithFragments-DTLS",
1459 config: Config{
1460 Bugs: ProtocolBugs{
1461 ReorderHandshakeFragments: true,
1462 MixCompleteMessageWithFragments: true,
1463 MaxHandshakeRecordLength: 2,
1464 },
1465 },
1466 },
1467 {
1468 name: "SendInvalidRecordType",
1469 config: Config{
1470 Bugs: ProtocolBugs{
1471 SendInvalidRecordType: true,
1472 },
1473 },
1474 shouldFail: true,
1475 expectedError: ":UNEXPECTED_RECORD:",
1476 },
1477 {
1478 protocol: dtls,
1479 name: "SendInvalidRecordType-DTLS",
1480 config: Config{
1481 Bugs: ProtocolBugs{
1482 SendInvalidRecordType: true,
1483 },
1484 },
1485 shouldFail: true,
1486 expectedError: ":UNEXPECTED_RECORD:",
1487 },
1488 {
1489 name: "FalseStart-SkipServerSecondLeg",
1490 config: Config{
1491 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1492 NextProtos: []string{"foo"},
1493 Bugs: ProtocolBugs{
1494 SkipNewSessionTicket: true,
1495 SkipChangeCipherSpec: true,
1496 SkipFinished: true,
1497 ExpectFalseStart: true,
1498 },
1499 },
1500 flags: []string{
1501 "-false-start",
1502 "-handshake-never-done",
1503 "-advertise-alpn", "\x03foo",
1504 },
1505 shimWritesFirst: true,
1506 shouldFail: true,
1507 expectedError: ":UNEXPECTED_RECORD:",
1508 },
1509 {
1510 name: "FalseStart-SkipServerSecondLeg-Implicit",
1511 config: Config{
1512 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1513 NextProtos: []string{"foo"},
1514 Bugs: ProtocolBugs{
1515 SkipNewSessionTicket: true,
1516 SkipChangeCipherSpec: true,
1517 SkipFinished: true,
1518 },
1519 },
1520 flags: []string{
1521 "-implicit-handshake",
1522 "-false-start",
1523 "-handshake-never-done",
1524 "-advertise-alpn", "\x03foo",
1525 },
1526 shouldFail: true,
1527 expectedError: ":UNEXPECTED_RECORD:",
1528 },
1529 {
1530 testType: serverTest,
1531 name: "FailEarlyCallback",
1532 flags: []string{"-fail-early-callback"},
1533 shouldFail: true,
1534 expectedError: ":CONNECTION_REJECTED:",
1535 expectedLocalError: "remote error: access denied",
1536 },
1537 {
1538 name: "WrongMessageType",
1539 config: Config{
1540 Bugs: ProtocolBugs{
1541 WrongCertificateMessageType: true,
1542 },
1543 },
1544 shouldFail: true,
1545 expectedError: ":UNEXPECTED_MESSAGE:",
1546 expectedLocalError: "remote error: unexpected message",
1547 },
1548 {
1549 protocol: dtls,
1550 name: "WrongMessageType-DTLS",
1551 config: Config{
1552 Bugs: ProtocolBugs{
1553 WrongCertificateMessageType: true,
1554 },
1555 },
1556 shouldFail: true,
1557 expectedError: ":UNEXPECTED_MESSAGE:",
1558 expectedLocalError: "remote error: unexpected message",
1559 },
1560 {
1561 protocol: dtls,
1562 name: "FragmentMessageTypeMismatch-DTLS",
1563 config: Config{
1564 Bugs: ProtocolBugs{
1565 MaxHandshakeRecordLength: 2,
1566 FragmentMessageTypeMismatch: true,
1567 },
1568 },
1569 shouldFail: true,
1570 expectedError: ":FRAGMENT_MISMATCH:",
1571 },
1572 {
1573 protocol: dtls,
1574 name: "FragmentMessageLengthMismatch-DTLS",
1575 config: Config{
1576 Bugs: ProtocolBugs{
1577 MaxHandshakeRecordLength: 2,
1578 FragmentMessageLengthMismatch: true,
1579 },
1580 },
1581 shouldFail: true,
1582 expectedError: ":FRAGMENT_MISMATCH:",
1583 },
1584 {
1585 protocol: dtls,
1586 name: "SplitFragments-Header-DTLS",
1587 config: Config{
1588 Bugs: ProtocolBugs{
1589 SplitFragments: 2,
1590 },
1591 },
1592 shouldFail: true,
1593 expectedError: ":UNEXPECTED_MESSAGE:",
1594 },
1595 {
1596 protocol: dtls,
1597 name: "SplitFragments-Boundary-DTLS",
1598 config: Config{
1599 Bugs: ProtocolBugs{
1600 SplitFragments: dtlsRecordHeaderLen,
1601 },
1602 },
1603 shouldFail: true,
1604 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1605 },
1606 {
1607 protocol: dtls,
1608 name: "SplitFragments-Body-DTLS",
1609 config: Config{
1610 Bugs: ProtocolBugs{
1611 SplitFragments: dtlsRecordHeaderLen + 1,
1612 },
1613 },
1614 shouldFail: true,
1615 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1616 },
1617 {
1618 protocol: dtls,
1619 name: "SendEmptyFragments-DTLS",
1620 config: Config{
1621 Bugs: ProtocolBugs{
1622 SendEmptyFragments: true,
1623 },
1624 },
1625 },
1626 {
1627 name: "UnsupportedCipherSuite",
1628 config: Config{
1629 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1630 Bugs: ProtocolBugs{
1631 IgnorePeerCipherPreferences: true,
1632 },
1633 },
1634 flags: []string{"-cipher", "DEFAULT:!RC4"},
1635 shouldFail: true,
1636 expectedError: ":WRONG_CIPHER_RETURNED:",
1637 },
1638 {
1639 name: "UnsupportedCurve",
1640 config: Config{
1641 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1642 // BoringSSL implements P-224 but doesn't enable it by
1643 // default.
1644 CurvePreferences: []CurveID{CurveP224},
1645 Bugs: ProtocolBugs{
1646 IgnorePeerCurvePreferences: true,
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":WRONG_CURVE:",
1651 },
1652 {
1653 name: "BadFinished",
1654 config: Config{
1655 Bugs: ProtocolBugs{
1656 BadFinished: true,
1657 },
1658 },
1659 shouldFail: true,
1660 expectedError: ":DIGEST_CHECK_FAILED:",
1661 },
1662 {
1663 name: "FalseStart-BadFinished",
1664 config: Config{
1665 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1666 NextProtos: []string{"foo"},
1667 Bugs: ProtocolBugs{
1668 BadFinished: true,
1669 ExpectFalseStart: true,
1670 },
1671 },
1672 flags: []string{
1673 "-false-start",
1674 "-handshake-never-done",
1675 "-advertise-alpn", "\x03foo",
1676 },
1677 shimWritesFirst: true,
1678 shouldFail: true,
1679 expectedError: ":DIGEST_CHECK_FAILED:",
1680 },
1681 {
1682 name: "NoFalseStart-NoALPN",
1683 config: Config{
1684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1685 Bugs: ProtocolBugs{
1686 ExpectFalseStart: true,
1687 AlertBeforeFalseStartTest: alertAccessDenied,
1688 },
1689 },
1690 flags: []string{
1691 "-false-start",
1692 },
1693 shimWritesFirst: true,
1694 shouldFail: true,
1695 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1696 expectedLocalError: "tls: peer did not false start: EOF",
1697 },
1698 {
1699 name: "NoFalseStart-NoAEAD",
1700 config: Config{
1701 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1702 NextProtos: []string{"foo"},
1703 Bugs: ProtocolBugs{
1704 ExpectFalseStart: true,
1705 AlertBeforeFalseStartTest: alertAccessDenied,
1706 },
1707 },
1708 flags: []string{
1709 "-false-start",
1710 "-advertise-alpn", "\x03foo",
1711 },
1712 shimWritesFirst: true,
1713 shouldFail: true,
1714 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1715 expectedLocalError: "tls: peer did not false start: EOF",
1716 },
1717 {
1718 name: "NoFalseStart-RSA",
1719 config: Config{
1720 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1721 NextProtos: []string{"foo"},
1722 Bugs: ProtocolBugs{
1723 ExpectFalseStart: true,
1724 AlertBeforeFalseStartTest: alertAccessDenied,
1725 },
1726 },
1727 flags: []string{
1728 "-false-start",
1729 "-advertise-alpn", "\x03foo",
1730 },
1731 shimWritesFirst: true,
1732 shouldFail: true,
1733 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1734 expectedLocalError: "tls: peer did not false start: EOF",
1735 },
1736 {
1737 name: "NoFalseStart-DHE_RSA",
1738 config: Config{
1739 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1740 NextProtos: []string{"foo"},
1741 Bugs: ProtocolBugs{
1742 ExpectFalseStart: true,
1743 AlertBeforeFalseStartTest: alertAccessDenied,
1744 },
1745 },
1746 flags: []string{
1747 "-false-start",
1748 "-advertise-alpn", "\x03foo",
1749 },
1750 shimWritesFirst: true,
1751 shouldFail: true,
1752 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1753 expectedLocalError: "tls: peer did not false start: EOF",
1754 },
1755 {
1756 testType: serverTest,
1757 name: "NoSupportedCurves",
1758 config: Config{
1759 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1760 Bugs: ProtocolBugs{
1761 NoSupportedCurves: true,
1762 },
1763 },
1764 },
1765 {
1766 testType: serverTest,
1767 name: "NoCommonCurves",
1768 config: Config{
1769 CipherSuites: []uint16{
1770 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1771 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1772 },
1773 CurvePreferences: []CurveID{CurveP224},
1774 },
1775 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1776 },
1777 {
1778 protocol: dtls,
1779 name: "SendSplitAlert-Sync",
1780 config: Config{
1781 Bugs: ProtocolBugs{
1782 SendSplitAlert: true,
1783 },
1784 },
1785 },
1786 {
1787 protocol: dtls,
1788 name: "SendSplitAlert-Async",
1789 config: Config{
1790 Bugs: ProtocolBugs{
1791 SendSplitAlert: true,
1792 },
1793 },
1794 flags: []string{"-async"},
1795 },
1796 {
1797 protocol: dtls,
1798 name: "PackDTLSHandshake",
1799 config: Config{
1800 Bugs: ProtocolBugs{
1801 MaxHandshakeRecordLength: 2,
1802 PackHandshakeFragments: 20,
1803 PackHandshakeRecords: 200,
1804 },
1805 },
1806 },
1807 {
1808 testType: serverTest,
1809 protocol: dtls,
1810 name: "NoRC4-DTLS",
1811 config: Config{
1812 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1813 Bugs: ProtocolBugs{
1814 EnableAllCiphersInDTLS: true,
1815 },
1816 },
1817 shouldFail: true,
1818 expectedError: ":NO_SHARED_CIPHER:",
1819 },
1820 {
1821 name: "SendEmptyRecords-Pass",
1822 sendEmptyRecords: 32,
1823 },
1824 {
1825 name: "SendEmptyRecords",
1826 sendEmptyRecords: 33,
1827 shouldFail: true,
1828 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1829 },
1830 {
1831 name: "SendEmptyRecords-Async",
1832 sendEmptyRecords: 33,
1833 flags: []string{"-async"},
1834 shouldFail: true,
1835 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1836 },
1837 {
1838 name: "SendWarningAlerts-Pass",
1839 sendWarningAlerts: 4,
1840 },
1841 {
1842 protocol: dtls,
1843 name: "SendWarningAlerts-DTLS-Pass",
1844 sendWarningAlerts: 4,
1845 },
1846 {
1847 name: "SendWarningAlerts",
1848 sendWarningAlerts: 5,
1849 shouldFail: true,
1850 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1851 },
1852 {
1853 name: "SendWarningAlerts-Async",
1854 sendWarningAlerts: 5,
1855 flags: []string{"-async"},
1856 shouldFail: true,
1857 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1858 },
David Benjaminba4594a2015-06-18 18:36:15 -04001859 {
1860 name: "EmptySessionID",
1861 config: Config{
1862 SessionTicketsDisabled: true,
1863 },
1864 noSessionCache: true,
1865 flags: []string{"-expect-no-session"},
1866 },
David Benjamin30789da2015-08-29 22:56:45 -04001867 {
1868 name: "Unclean-Shutdown",
1869 config: Config{
1870 Bugs: ProtocolBugs{
1871 NoCloseNotify: true,
1872 ExpectCloseNotify: true,
1873 },
1874 },
1875 shimShutsDown: true,
1876 flags: []string{"-check-close-notify"},
1877 shouldFail: true,
1878 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1879 },
1880 {
1881 name: "Unclean-Shutdown-Ignored",
1882 config: Config{
1883 Bugs: ProtocolBugs{
1884 NoCloseNotify: true,
1885 },
1886 },
1887 shimShutsDown: true,
1888 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001889 {
1890 name: "LargePlaintext",
1891 config: Config{
1892 Bugs: ProtocolBugs{
1893 SendLargeRecords: true,
1894 },
1895 },
1896 messageLen: maxPlaintext + 1,
1897 shouldFail: true,
1898 expectedError: ":DATA_LENGTH_TOO_LONG:",
1899 },
1900 {
1901 protocol: dtls,
1902 name: "LargePlaintext-DTLS",
1903 config: Config{
1904 Bugs: ProtocolBugs{
1905 SendLargeRecords: true,
1906 },
1907 },
1908 messageLen: maxPlaintext + 1,
1909 shouldFail: true,
1910 expectedError: ":DATA_LENGTH_TOO_LONG:",
1911 },
1912 {
1913 name: "LargeCiphertext",
1914 config: Config{
1915 Bugs: ProtocolBugs{
1916 SendLargeRecords: true,
1917 },
1918 },
1919 messageLen: maxPlaintext * 2,
1920 shouldFail: true,
1921 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1922 },
1923 {
1924 protocol: dtls,
1925 name: "LargeCiphertext-DTLS",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 SendLargeRecords: true,
1929 },
1930 },
1931 messageLen: maxPlaintext * 2,
1932 // Unlike the other four cases, DTLS drops records which
1933 // are invalid before authentication, so the connection
1934 // does not fail.
1935 expectMessageDropped: true,
1936 },
Adam Langley7c803a62015-06-15 15:35:05 -07001937 }
Adam Langley7c803a62015-06-15 15:35:05 -07001938 testCases = append(testCases, basicTests...)
1939}
1940
Adam Langley95c29f32014-06-20 12:00:00 -07001941func addCipherSuiteTests() {
1942 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001943 const psk = "12345"
1944 const pskIdentity = "luggage combo"
1945
Adam Langley95c29f32014-06-20 12:00:00 -07001946 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001947 var certFile string
1948 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001949 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001950 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001951 certFile = ecdsaCertificateFile
1952 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001953 } else {
1954 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001955 certFile = rsaCertificateFile
1956 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001957 }
1958
David Benjamin48cae082014-10-27 01:06:24 -04001959 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001960 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001961 flags = append(flags,
1962 "-psk", psk,
1963 "-psk-identity", pskIdentity)
1964 }
1965
Adam Langley95c29f32014-06-20 12:00:00 -07001966 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04001967 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07001968 continue
1969 }
1970
David Benjamin025b3d32014-07-01 19:53:04 -04001971 testCases = append(testCases, testCase{
1972 testType: clientTest,
1973 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07001974 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001975 MinVersion: ver.version,
1976 MaxVersion: ver.version,
1977 CipherSuites: []uint16{suite.id},
1978 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04001979 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04001980 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07001981 },
David Benjamin48cae082014-10-27 01:06:24 -04001982 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001983 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07001984 })
David Benjamin025b3d32014-07-01 19:53:04 -04001985
David Benjamin76d8abe2014-08-14 16:25:34 -04001986 testCases = append(testCases, testCase{
1987 testType: serverTest,
1988 name: ver.name + "-" + suite.name + "-server",
1989 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04001990 MinVersion: ver.version,
1991 MaxVersion: ver.version,
1992 CipherSuites: []uint16{suite.id},
1993 Certificates: []Certificate{cert},
1994 PreSharedKey: []byte(psk),
1995 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04001996 },
1997 certFile: certFile,
1998 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04001999 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002000 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002001 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002002
David Benjamin8b8c0062014-11-23 02:47:52 -05002003 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002004 testCases = append(testCases, testCase{
2005 testType: clientTest,
2006 protocol: dtls,
2007 name: "D" + ver.name + "-" + suite.name + "-client",
2008 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002009 MinVersion: ver.version,
2010 MaxVersion: ver.version,
2011 CipherSuites: []uint16{suite.id},
2012 Certificates: []Certificate{cert},
2013 PreSharedKey: []byte(psk),
2014 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002015 },
David Benjamin48cae082014-10-27 01:06:24 -04002016 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002017 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002018 })
2019 testCases = append(testCases, testCase{
2020 testType: serverTest,
2021 protocol: dtls,
2022 name: "D" + ver.name + "-" + suite.name + "-server",
2023 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002024 MinVersion: ver.version,
2025 MaxVersion: ver.version,
2026 CipherSuites: []uint16{suite.id},
2027 Certificates: []Certificate{cert},
2028 PreSharedKey: []byte(psk),
2029 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002030 },
2031 certFile: certFile,
2032 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002033 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002034 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002035 })
2036 }
Adam Langley95c29f32014-06-20 12:00:00 -07002037 }
David Benjamin2c99d282015-09-01 10:23:00 -04002038
2039 // Ensure both TLS and DTLS accept their maximum record sizes.
2040 testCases = append(testCases, testCase{
2041 name: suite.name + "-LargeRecord",
2042 config: Config{
2043 CipherSuites: []uint16{suite.id},
2044 Certificates: []Certificate{cert},
2045 PreSharedKey: []byte(psk),
2046 PreSharedKeyIdentity: pskIdentity,
2047 },
2048 flags: flags,
2049 messageLen: maxPlaintext,
2050 })
2051 testCases = append(testCases, testCase{
2052 name: suite.name + "-LargeRecord-Extra",
2053 config: Config{
2054 CipherSuites: []uint16{suite.id},
2055 Certificates: []Certificate{cert},
2056 PreSharedKey: []byte(psk),
2057 PreSharedKeyIdentity: pskIdentity,
2058 Bugs: ProtocolBugs{
2059 SendLargeRecords: true,
2060 },
2061 },
2062 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2063 messageLen: maxPlaintext + 16384,
2064 })
2065 if isDTLSCipher(suite.name) {
2066 testCases = append(testCases, testCase{
2067 protocol: dtls,
2068 name: suite.name + "-LargeRecord-DTLS",
2069 config: Config{
2070 CipherSuites: []uint16{suite.id},
2071 Certificates: []Certificate{cert},
2072 PreSharedKey: []byte(psk),
2073 PreSharedKeyIdentity: pskIdentity,
2074 },
2075 flags: flags,
2076 messageLen: maxPlaintext,
2077 })
2078 }
Adam Langley95c29f32014-06-20 12:00:00 -07002079 }
Adam Langleya7997f12015-05-14 17:38:50 -07002080
2081 testCases = append(testCases, testCase{
2082 name: "WeakDH",
2083 config: Config{
2084 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2085 Bugs: ProtocolBugs{
2086 // This is a 1023-bit prime number, generated
2087 // with:
2088 // openssl gendh 1023 | openssl asn1parse -i
2089 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2090 },
2091 },
2092 shouldFail: true,
2093 expectedError: "BAD_DH_P_LENGTH",
2094 })
Adam Langleycef75832015-09-03 14:51:12 -07002095
2096 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2097 // 1.1 specific cipher suite settings. A server is setup with the given
2098 // cipher lists and then a connection is made for each member of
2099 // expectations. The cipher suite that the server selects must match
2100 // the specified one.
2101 var versionSpecificCiphersTest = []struct {
2102 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2103 // expectations is a map from TLS version to cipher suite id.
2104 expectations map[uint16]uint16
2105 }{
2106 {
2107 // Test that the null case (where no version-specific ciphers are set)
2108 // works as expected.
2109 "RC4-SHA:AES128-SHA", // default ciphers
2110 "", // no ciphers specifically for TLS ≥ 1.0
2111 "", // no ciphers specifically for TLS ≥ 1.1
2112 map[uint16]uint16{
2113 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2114 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2115 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2116 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2117 },
2118 },
2119 {
2120 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2121 // cipher.
2122 "RC4-SHA:AES128-SHA", // default
2123 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2124 "", // no ciphers specifically for TLS ≥ 1.1
2125 map[uint16]uint16{
2126 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2127 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2128 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2129 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2130 },
2131 },
2132 {
2133 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2134 // cipher.
2135 "RC4-SHA:AES128-SHA", // default
2136 "", // no ciphers specifically for TLS ≥ 1.0
2137 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2138 map[uint16]uint16{
2139 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2140 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2141 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2142 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2143 },
2144 },
2145 {
2146 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2147 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2148 "RC4-SHA:AES128-SHA", // default
2149 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2150 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2151 map[uint16]uint16{
2152 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2153 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2154 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2155 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2156 },
2157 },
2158 }
2159
2160 for i, test := range versionSpecificCiphersTest {
2161 for version, expectedCipherSuite := range test.expectations {
2162 flags := []string{"-cipher", test.ciphersDefault}
2163 if len(test.ciphersTLS10) > 0 {
2164 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2165 }
2166 if len(test.ciphersTLS11) > 0 {
2167 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2168 }
2169
2170 testCases = append(testCases, testCase{
2171 testType: serverTest,
2172 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2173 config: Config{
2174 MaxVersion: version,
2175 MinVersion: version,
2176 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2177 },
2178 flags: flags,
2179 expectedCipher: expectedCipherSuite,
2180 })
2181 }
2182 }
Adam Langley95c29f32014-06-20 12:00:00 -07002183}
2184
2185func addBadECDSASignatureTests() {
2186 for badR := BadValue(1); badR < NumBadValues; badR++ {
2187 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002188 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002189 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2190 config: Config{
2191 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2192 Certificates: []Certificate{getECDSACertificate()},
2193 Bugs: ProtocolBugs{
2194 BadECDSAR: badR,
2195 BadECDSAS: badS,
2196 },
2197 },
2198 shouldFail: true,
2199 expectedError: "SIGNATURE",
2200 })
2201 }
2202 }
2203}
2204
Adam Langley80842bd2014-06-20 12:00:00 -07002205func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002206 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002207 name: "MaxCBCPadding",
2208 config: Config{
2209 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2210 Bugs: ProtocolBugs{
2211 MaxPadding: true,
2212 },
2213 },
2214 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2215 })
David Benjamin025b3d32014-07-01 19:53:04 -04002216 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002217 name: "BadCBCPadding",
2218 config: Config{
2219 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2220 Bugs: ProtocolBugs{
2221 PaddingFirstByteBad: true,
2222 },
2223 },
2224 shouldFail: true,
2225 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2226 })
2227 // OpenSSL previously had an issue where the first byte of padding in
2228 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002229 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002230 name: "BadCBCPadding255",
2231 config: Config{
2232 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2233 Bugs: ProtocolBugs{
2234 MaxPadding: true,
2235 PaddingFirstByteBadIf255: true,
2236 },
2237 },
2238 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2239 shouldFail: true,
2240 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2241 })
2242}
2243
Kenny Root7fdeaf12014-08-05 15:23:37 -07002244func addCBCSplittingTests() {
2245 testCases = append(testCases, testCase{
2246 name: "CBCRecordSplitting",
2247 config: Config{
2248 MaxVersion: VersionTLS10,
2249 MinVersion: VersionTLS10,
2250 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2251 },
David Benjaminac8302a2015-09-01 17:18:15 -04002252 messageLen: -1, // read until EOF
2253 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002254 flags: []string{
2255 "-async",
2256 "-write-different-record-sizes",
2257 "-cbc-record-splitting",
2258 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002259 })
2260 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002261 name: "CBCRecordSplittingPartialWrite",
2262 config: Config{
2263 MaxVersion: VersionTLS10,
2264 MinVersion: VersionTLS10,
2265 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2266 },
2267 messageLen: -1, // read until EOF
2268 flags: []string{
2269 "-async",
2270 "-write-different-record-sizes",
2271 "-cbc-record-splitting",
2272 "-partial-write",
2273 },
2274 })
2275}
2276
David Benjamin636293b2014-07-08 17:59:18 -04002277func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002278 // Add a dummy cert pool to stress certificate authority parsing.
2279 // TODO(davidben): Add tests that those values parse out correctly.
2280 certPool := x509.NewCertPool()
2281 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2282 if err != nil {
2283 panic(err)
2284 }
2285 certPool.AddCert(cert)
2286
David Benjamin636293b2014-07-08 17:59:18 -04002287 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002288 testCases = append(testCases, testCase{
2289 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002290 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002291 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002292 MinVersion: ver.version,
2293 MaxVersion: ver.version,
2294 ClientAuth: RequireAnyClientCert,
2295 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002296 },
2297 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002298 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2299 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002300 },
2301 })
2302 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002303 testType: serverTest,
2304 name: ver.name + "-Server-ClientAuth-RSA",
2305 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002306 MinVersion: ver.version,
2307 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002308 Certificates: []Certificate{rsaCertificate},
2309 },
2310 flags: []string{"-require-any-client-certificate"},
2311 })
David Benjamine098ec22014-08-27 23:13:20 -04002312 if ver.version != VersionSSL30 {
2313 testCases = append(testCases, testCase{
2314 testType: serverTest,
2315 name: ver.name + "-Server-ClientAuth-ECDSA",
2316 config: Config{
2317 MinVersion: ver.version,
2318 MaxVersion: ver.version,
2319 Certificates: []Certificate{ecdsaCertificate},
2320 },
2321 flags: []string{"-require-any-client-certificate"},
2322 })
2323 testCases = append(testCases, testCase{
2324 testType: clientTest,
2325 name: ver.name + "-Client-ClientAuth-ECDSA",
2326 config: Config{
2327 MinVersion: ver.version,
2328 MaxVersion: ver.version,
2329 ClientAuth: RequireAnyClientCert,
2330 ClientCAs: certPool,
2331 },
2332 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002333 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2334 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002335 },
2336 })
2337 }
David Benjamin636293b2014-07-08 17:59:18 -04002338 }
2339}
2340
Adam Langley75712922014-10-10 16:23:43 -07002341func addExtendedMasterSecretTests() {
2342 const expectEMSFlag = "-expect-extended-master-secret"
2343
2344 for _, with := range []bool{false, true} {
2345 prefix := "No"
2346 var flags []string
2347 if with {
2348 prefix = ""
2349 flags = []string{expectEMSFlag}
2350 }
2351
2352 for _, isClient := range []bool{false, true} {
2353 suffix := "-Server"
2354 testType := serverTest
2355 if isClient {
2356 suffix = "-Client"
2357 testType = clientTest
2358 }
2359
2360 for _, ver := range tlsVersions {
2361 test := testCase{
2362 testType: testType,
2363 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2364 config: Config{
2365 MinVersion: ver.version,
2366 MaxVersion: ver.version,
2367 Bugs: ProtocolBugs{
2368 NoExtendedMasterSecret: !with,
2369 RequireExtendedMasterSecret: with,
2370 },
2371 },
David Benjamin48cae082014-10-27 01:06:24 -04002372 flags: flags,
2373 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002374 }
2375 if test.shouldFail {
2376 test.expectedLocalError = "extended master secret required but not supported by peer"
2377 }
2378 testCases = append(testCases, test)
2379 }
2380 }
2381 }
2382
Adam Langleyba5934b2015-06-02 10:50:35 -07002383 for _, isClient := range []bool{false, true} {
2384 for _, supportedInFirstConnection := range []bool{false, true} {
2385 for _, supportedInResumeConnection := range []bool{false, true} {
2386 boolToWord := func(b bool) string {
2387 if b {
2388 return "Yes"
2389 }
2390 return "No"
2391 }
2392 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2393 if isClient {
2394 suffix += "Client"
2395 } else {
2396 suffix += "Server"
2397 }
2398
2399 supportedConfig := Config{
2400 Bugs: ProtocolBugs{
2401 RequireExtendedMasterSecret: true,
2402 },
2403 }
2404
2405 noSupportConfig := Config{
2406 Bugs: ProtocolBugs{
2407 NoExtendedMasterSecret: true,
2408 },
2409 }
2410
2411 test := testCase{
2412 name: "ExtendedMasterSecret-" + suffix,
2413 resumeSession: true,
2414 }
2415
2416 if !isClient {
2417 test.testType = serverTest
2418 }
2419
2420 if supportedInFirstConnection {
2421 test.config = supportedConfig
2422 } else {
2423 test.config = noSupportConfig
2424 }
2425
2426 if supportedInResumeConnection {
2427 test.resumeConfig = &supportedConfig
2428 } else {
2429 test.resumeConfig = &noSupportConfig
2430 }
2431
2432 switch suffix {
2433 case "YesToYes-Client", "YesToYes-Server":
2434 // When a session is resumed, it should
2435 // still be aware that its master
2436 // secret was generated via EMS and
2437 // thus it's safe to use tls-unique.
2438 test.flags = []string{expectEMSFlag}
2439 case "NoToYes-Server":
2440 // If an original connection did not
2441 // contain EMS, but a resumption
2442 // handshake does, then a server should
2443 // not resume the session.
2444 test.expectResumeRejected = true
2445 case "YesToNo-Server":
2446 // Resuming an EMS session without the
2447 // EMS extension should cause the
2448 // server to abort the connection.
2449 test.shouldFail = true
2450 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2451 case "NoToYes-Client":
2452 // A client should abort a connection
2453 // where the server resumed a non-EMS
2454 // session but echoed the EMS
2455 // extension.
2456 test.shouldFail = true
2457 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2458 case "YesToNo-Client":
2459 // A client should abort a connection
2460 // where the server didn't echo EMS
2461 // when the session used it.
2462 test.shouldFail = true
2463 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2464 }
2465
2466 testCases = append(testCases, test)
2467 }
2468 }
2469 }
Adam Langley75712922014-10-10 16:23:43 -07002470}
2471
David Benjamin43ec06f2014-08-05 02:28:57 -04002472// Adds tests that try to cover the range of the handshake state machine, under
2473// various conditions. Some of these are redundant with other tests, but they
2474// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002475func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002476 var tests []testCase
2477
2478 // Basic handshake, with resumption. Client and server,
2479 // session ID and session ticket.
2480 tests = append(tests, testCase{
2481 name: "Basic-Client",
2482 resumeSession: true,
2483 })
2484 tests = append(tests, testCase{
2485 name: "Basic-Client-RenewTicket",
2486 config: Config{
2487 Bugs: ProtocolBugs{
2488 RenewTicketOnResume: true,
2489 },
2490 },
David Benjaminba4594a2015-06-18 18:36:15 -04002491 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002492 resumeSession: true,
2493 })
2494 tests = append(tests, testCase{
2495 name: "Basic-Client-NoTicket",
2496 config: Config{
2497 SessionTicketsDisabled: true,
2498 },
2499 resumeSession: true,
2500 })
2501 tests = append(tests, testCase{
2502 name: "Basic-Client-Implicit",
2503 flags: []string{"-implicit-handshake"},
2504 resumeSession: true,
2505 })
2506 tests = append(tests, testCase{
2507 testType: serverTest,
2508 name: "Basic-Server",
2509 resumeSession: true,
2510 })
2511 tests = append(tests, testCase{
2512 testType: serverTest,
2513 name: "Basic-Server-NoTickets",
2514 config: Config{
2515 SessionTicketsDisabled: true,
2516 },
2517 resumeSession: true,
2518 })
2519 tests = append(tests, testCase{
2520 testType: serverTest,
2521 name: "Basic-Server-Implicit",
2522 flags: []string{"-implicit-handshake"},
2523 resumeSession: true,
2524 })
2525 tests = append(tests, testCase{
2526 testType: serverTest,
2527 name: "Basic-Server-EarlyCallback",
2528 flags: []string{"-use-early-callback"},
2529 resumeSession: true,
2530 })
2531
2532 // TLS client auth.
2533 tests = append(tests, testCase{
2534 testType: clientTest,
2535 name: "ClientAuth-Client",
2536 config: Config{
2537 ClientAuth: RequireAnyClientCert,
2538 },
2539 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002540 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2541 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002542 },
2543 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002544 if async {
2545 tests = append(tests, testCase{
2546 testType: clientTest,
2547 name: "ClientAuth-Client-AsyncKey",
2548 config: Config{
2549 ClientAuth: RequireAnyClientCert,
2550 },
2551 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002552 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2553 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002554 "-use-async-private-key",
2555 },
2556 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002557 tests = append(tests, testCase{
2558 testType: serverTest,
2559 name: "Basic-Server-RSAAsyncKey",
2560 flags: []string{
2561 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2562 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2563 "-use-async-private-key",
2564 },
2565 })
2566 tests = append(tests, testCase{
2567 testType: serverTest,
2568 name: "Basic-Server-ECDSAAsyncKey",
2569 flags: []string{
2570 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2571 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2572 "-use-async-private-key",
2573 },
2574 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002575 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002576 tests = append(tests, testCase{
2577 testType: serverTest,
2578 name: "ClientAuth-Server",
2579 config: Config{
2580 Certificates: []Certificate{rsaCertificate},
2581 },
2582 flags: []string{"-require-any-client-certificate"},
2583 })
2584
2585 // No session ticket support; server doesn't send NewSessionTicket.
2586 tests = append(tests, testCase{
2587 name: "SessionTicketsDisabled-Client",
2588 config: Config{
2589 SessionTicketsDisabled: true,
2590 },
2591 })
2592 tests = append(tests, testCase{
2593 testType: serverTest,
2594 name: "SessionTicketsDisabled-Server",
2595 config: Config{
2596 SessionTicketsDisabled: true,
2597 },
2598 })
2599
2600 // Skip ServerKeyExchange in PSK key exchange if there's no
2601 // identity hint.
2602 tests = append(tests, testCase{
2603 name: "EmptyPSKHint-Client",
2604 config: Config{
2605 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2606 PreSharedKey: []byte("secret"),
2607 },
2608 flags: []string{"-psk", "secret"},
2609 })
2610 tests = append(tests, testCase{
2611 testType: serverTest,
2612 name: "EmptyPSKHint-Server",
2613 config: Config{
2614 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2615 PreSharedKey: []byte("secret"),
2616 },
2617 flags: []string{"-psk", "secret"},
2618 })
2619
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002620 tests = append(tests, testCase{
2621 testType: clientTest,
2622 name: "OCSPStapling-Client",
2623 flags: []string{
2624 "-enable-ocsp-stapling",
2625 "-expect-ocsp-response",
2626 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002627 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002628 },
2629 })
2630
2631 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002632 testType: serverTest,
2633 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002634 expectedOCSPResponse: testOCSPResponse,
2635 flags: []string{
2636 "-ocsp-response",
2637 base64.StdEncoding.EncodeToString(testOCSPResponse),
2638 },
2639 })
2640
Paul Lietar8f1c2682015-08-18 12:21:54 +01002641 tests = append(tests, testCase{
2642 testType: clientTest,
2643 name: "CertificateVerificationSucceed",
2644 flags: []string{
2645 "-verify-peer",
2646 },
2647 })
2648
2649 tests = append(tests, testCase{
2650 testType: clientTest,
2651 name: "CertificateVerificationFail",
2652 flags: []string{
2653 "-verify-fail",
2654 "-verify-peer",
2655 },
2656 shouldFail: true,
2657 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2658 })
2659
2660 tests = append(tests, testCase{
2661 testType: clientTest,
2662 name: "CertificateVerificationSoftFail",
2663 flags: []string{
2664 "-verify-fail",
2665 "-expect-verify-result",
2666 },
2667 })
2668
David Benjamin760b1dd2015-05-15 23:33:48 -04002669 if protocol == tls {
2670 tests = append(tests, testCase{
2671 name: "Renegotiate-Client",
2672 renegotiate: true,
2673 })
2674 // NPN on client and server; results in post-handshake message.
2675 tests = append(tests, testCase{
2676 name: "NPN-Client",
2677 config: Config{
2678 NextProtos: []string{"foo"},
2679 },
2680 flags: []string{"-select-next-proto", "foo"},
2681 expectedNextProto: "foo",
2682 expectedNextProtoType: npn,
2683 })
2684 tests = append(tests, testCase{
2685 testType: serverTest,
2686 name: "NPN-Server",
2687 config: Config{
2688 NextProtos: []string{"bar"},
2689 },
2690 flags: []string{
2691 "-advertise-npn", "\x03foo\x03bar\x03baz",
2692 "-expect-next-proto", "bar",
2693 },
2694 expectedNextProto: "bar",
2695 expectedNextProtoType: npn,
2696 })
2697
2698 // TODO(davidben): Add tests for when False Start doesn't trigger.
2699
2700 // Client does False Start and negotiates NPN.
2701 tests = append(tests, testCase{
2702 name: "FalseStart",
2703 config: Config{
2704 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2705 NextProtos: []string{"foo"},
2706 Bugs: ProtocolBugs{
2707 ExpectFalseStart: true,
2708 },
2709 },
2710 flags: []string{
2711 "-false-start",
2712 "-select-next-proto", "foo",
2713 },
2714 shimWritesFirst: true,
2715 resumeSession: true,
2716 })
2717
2718 // Client does False Start and negotiates ALPN.
2719 tests = append(tests, testCase{
2720 name: "FalseStart-ALPN",
2721 config: Config{
2722 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2723 NextProtos: []string{"foo"},
2724 Bugs: ProtocolBugs{
2725 ExpectFalseStart: true,
2726 },
2727 },
2728 flags: []string{
2729 "-false-start",
2730 "-advertise-alpn", "\x03foo",
2731 },
2732 shimWritesFirst: true,
2733 resumeSession: true,
2734 })
2735
2736 // Client does False Start but doesn't explicitly call
2737 // SSL_connect.
2738 tests = append(tests, testCase{
2739 name: "FalseStart-Implicit",
2740 config: Config{
2741 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2742 NextProtos: []string{"foo"},
2743 },
2744 flags: []string{
2745 "-implicit-handshake",
2746 "-false-start",
2747 "-advertise-alpn", "\x03foo",
2748 },
2749 })
2750
2751 // False Start without session tickets.
2752 tests = append(tests, testCase{
2753 name: "FalseStart-SessionTicketsDisabled",
2754 config: Config{
2755 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2756 NextProtos: []string{"foo"},
2757 SessionTicketsDisabled: true,
2758 Bugs: ProtocolBugs{
2759 ExpectFalseStart: true,
2760 },
2761 },
2762 flags: []string{
2763 "-false-start",
2764 "-select-next-proto", "foo",
2765 },
2766 shimWritesFirst: true,
2767 })
2768
2769 // Server parses a V2ClientHello.
2770 tests = append(tests, testCase{
2771 testType: serverTest,
2772 name: "SendV2ClientHello",
2773 config: Config{
2774 // Choose a cipher suite that does not involve
2775 // elliptic curves, so no extensions are
2776 // involved.
2777 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2778 Bugs: ProtocolBugs{
2779 SendV2ClientHello: true,
2780 },
2781 },
2782 })
2783
2784 // Client sends a Channel ID.
2785 tests = append(tests, testCase{
2786 name: "ChannelID-Client",
2787 config: Config{
2788 RequestChannelID: true,
2789 },
Adam Langley7c803a62015-06-15 15:35:05 -07002790 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002791 resumeSession: true,
2792 expectChannelID: true,
2793 })
2794
2795 // Server accepts a Channel ID.
2796 tests = append(tests, testCase{
2797 testType: serverTest,
2798 name: "ChannelID-Server",
2799 config: Config{
2800 ChannelID: channelIDKey,
2801 },
2802 flags: []string{
2803 "-expect-channel-id",
2804 base64.StdEncoding.EncodeToString(channelIDBytes),
2805 },
2806 resumeSession: true,
2807 expectChannelID: true,
2808 })
David Benjamin30789da2015-08-29 22:56:45 -04002809
2810 // Bidirectional shutdown with the runner initiating.
2811 tests = append(tests, testCase{
2812 name: "Shutdown-Runner",
2813 config: Config{
2814 Bugs: ProtocolBugs{
2815 ExpectCloseNotify: true,
2816 },
2817 },
2818 flags: []string{"-check-close-notify"},
2819 })
2820
2821 // Bidirectional shutdown with the shim initiating. The runner,
2822 // in the meantime, sends garbage before the close_notify which
2823 // the shim must ignore.
2824 tests = append(tests, testCase{
2825 name: "Shutdown-Shim",
2826 config: Config{
2827 Bugs: ProtocolBugs{
2828 ExpectCloseNotify: true,
2829 },
2830 },
2831 shimShutsDown: true,
2832 sendEmptyRecords: 1,
2833 sendWarningAlerts: 1,
2834 flags: []string{"-check-close-notify"},
2835 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002836 } else {
2837 tests = append(tests, testCase{
2838 name: "SkipHelloVerifyRequest",
2839 config: Config{
2840 Bugs: ProtocolBugs{
2841 SkipHelloVerifyRequest: true,
2842 },
2843 },
2844 })
2845 }
2846
David Benjamin43ec06f2014-08-05 02:28:57 -04002847 var suffix string
2848 var flags []string
2849 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002850 if protocol == dtls {
2851 suffix = "-DTLS"
2852 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002853 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002854 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002855 flags = append(flags, "-async")
2856 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002857 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002858 }
2859 if splitHandshake {
2860 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002861 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002862 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002863 for _, test := range tests {
2864 test.protocol = protocol
2865 test.name += suffix
2866 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2867 test.flags = append(test.flags, flags...)
2868 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002869 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002870}
2871
Adam Langley524e7172015-02-20 16:04:00 -08002872func addDDoSCallbackTests() {
2873 // DDoS callback.
2874
2875 for _, resume := range []bool{false, true} {
2876 suffix := "Resume"
2877 if resume {
2878 suffix = "No" + suffix
2879 }
2880
2881 testCases = append(testCases, testCase{
2882 testType: serverTest,
2883 name: "Server-DDoS-OK-" + suffix,
2884 flags: []string{"-install-ddos-callback"},
2885 resumeSession: resume,
2886 })
2887
2888 failFlag := "-fail-ddos-callback"
2889 if resume {
2890 failFlag = "-fail-second-ddos-callback"
2891 }
2892 testCases = append(testCases, testCase{
2893 testType: serverTest,
2894 name: "Server-DDoS-Reject-" + suffix,
2895 flags: []string{"-install-ddos-callback", failFlag},
2896 resumeSession: resume,
2897 shouldFail: true,
2898 expectedError: ":CONNECTION_REJECTED:",
2899 })
2900 }
2901}
2902
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002903func addVersionNegotiationTests() {
2904 for i, shimVers := range tlsVersions {
2905 // Assemble flags to disable all newer versions on the shim.
2906 var flags []string
2907 for _, vers := range tlsVersions[i+1:] {
2908 flags = append(flags, vers.flag)
2909 }
2910
2911 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002912 protocols := []protocol{tls}
2913 if runnerVers.hasDTLS && shimVers.hasDTLS {
2914 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002915 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002916 for _, protocol := range protocols {
2917 expectedVersion := shimVers.version
2918 if runnerVers.version < shimVers.version {
2919 expectedVersion = runnerVers.version
2920 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002921
David Benjamin8b8c0062014-11-23 02:47:52 -05002922 suffix := shimVers.name + "-" + runnerVers.name
2923 if protocol == dtls {
2924 suffix += "-DTLS"
2925 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002926
David Benjamin1eb367c2014-12-12 18:17:51 -05002927 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2928
David Benjamin1e29a6b2014-12-10 02:27:24 -05002929 clientVers := shimVers.version
2930 if clientVers > VersionTLS10 {
2931 clientVers = VersionTLS10
2932 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002933 testCases = append(testCases, testCase{
2934 protocol: protocol,
2935 testType: clientTest,
2936 name: "VersionNegotiation-Client-" + suffix,
2937 config: Config{
2938 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002939 Bugs: ProtocolBugs{
2940 ExpectInitialRecordVersion: clientVers,
2941 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002942 },
2943 flags: flags,
2944 expectedVersion: expectedVersion,
2945 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002946 testCases = append(testCases, testCase{
2947 protocol: protocol,
2948 testType: clientTest,
2949 name: "VersionNegotiation-Client2-" + suffix,
2950 config: Config{
2951 MaxVersion: runnerVers.version,
2952 Bugs: ProtocolBugs{
2953 ExpectInitialRecordVersion: clientVers,
2954 },
2955 },
2956 flags: []string{"-max-version", shimVersFlag},
2957 expectedVersion: expectedVersion,
2958 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002959
2960 testCases = append(testCases, testCase{
2961 protocol: protocol,
2962 testType: serverTest,
2963 name: "VersionNegotiation-Server-" + suffix,
2964 config: Config{
2965 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002966 Bugs: ProtocolBugs{
2967 ExpectInitialRecordVersion: expectedVersion,
2968 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002969 },
2970 flags: flags,
2971 expectedVersion: expectedVersion,
2972 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002973 testCases = append(testCases, testCase{
2974 protocol: protocol,
2975 testType: serverTest,
2976 name: "VersionNegotiation-Server2-" + suffix,
2977 config: Config{
2978 MaxVersion: runnerVers.version,
2979 Bugs: ProtocolBugs{
2980 ExpectInitialRecordVersion: expectedVersion,
2981 },
2982 },
2983 flags: []string{"-max-version", shimVersFlag},
2984 expectedVersion: expectedVersion,
2985 })
David Benjamin8b8c0062014-11-23 02:47:52 -05002986 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002987 }
2988 }
2989}
2990
David Benjaminaccb4542014-12-12 23:44:33 -05002991func addMinimumVersionTests() {
2992 for i, shimVers := range tlsVersions {
2993 // Assemble flags to disable all older versions on the shim.
2994 var flags []string
2995 for _, vers := range tlsVersions[:i] {
2996 flags = append(flags, vers.flag)
2997 }
2998
2999 for _, runnerVers := range tlsVersions {
3000 protocols := []protocol{tls}
3001 if runnerVers.hasDTLS && shimVers.hasDTLS {
3002 protocols = append(protocols, dtls)
3003 }
3004 for _, protocol := range protocols {
3005 suffix := shimVers.name + "-" + runnerVers.name
3006 if protocol == dtls {
3007 suffix += "-DTLS"
3008 }
3009 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3010
David Benjaminaccb4542014-12-12 23:44:33 -05003011 var expectedVersion uint16
3012 var shouldFail bool
3013 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003014 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003015 if runnerVers.version >= shimVers.version {
3016 expectedVersion = runnerVers.version
3017 } else {
3018 shouldFail = true
3019 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003020 if runnerVers.version > VersionSSL30 {
3021 expectedLocalError = "remote error: protocol version not supported"
3022 } else {
3023 expectedLocalError = "remote error: handshake failure"
3024 }
David Benjaminaccb4542014-12-12 23:44:33 -05003025 }
3026
3027 testCases = append(testCases, testCase{
3028 protocol: protocol,
3029 testType: clientTest,
3030 name: "MinimumVersion-Client-" + suffix,
3031 config: Config{
3032 MaxVersion: runnerVers.version,
3033 },
David Benjamin87909c02014-12-13 01:55:01 -05003034 flags: flags,
3035 expectedVersion: expectedVersion,
3036 shouldFail: shouldFail,
3037 expectedError: expectedError,
3038 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003039 })
3040 testCases = append(testCases, testCase{
3041 protocol: protocol,
3042 testType: clientTest,
3043 name: "MinimumVersion-Client2-" + suffix,
3044 config: Config{
3045 MaxVersion: runnerVers.version,
3046 },
David Benjamin87909c02014-12-13 01:55:01 -05003047 flags: []string{"-min-version", shimVersFlag},
3048 expectedVersion: expectedVersion,
3049 shouldFail: shouldFail,
3050 expectedError: expectedError,
3051 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003052 })
3053
3054 testCases = append(testCases, testCase{
3055 protocol: protocol,
3056 testType: serverTest,
3057 name: "MinimumVersion-Server-" + suffix,
3058 config: Config{
3059 MaxVersion: runnerVers.version,
3060 },
David Benjamin87909c02014-12-13 01:55:01 -05003061 flags: flags,
3062 expectedVersion: expectedVersion,
3063 shouldFail: shouldFail,
3064 expectedError: expectedError,
3065 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003066 })
3067 testCases = append(testCases, testCase{
3068 protocol: protocol,
3069 testType: serverTest,
3070 name: "MinimumVersion-Server2-" + suffix,
3071 config: Config{
3072 MaxVersion: runnerVers.version,
3073 },
David Benjamin87909c02014-12-13 01:55:01 -05003074 flags: []string{"-min-version", shimVersFlag},
3075 expectedVersion: expectedVersion,
3076 shouldFail: shouldFail,
3077 expectedError: expectedError,
3078 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003079 })
3080 }
3081 }
3082 }
3083}
3084
David Benjamin5c24a1d2014-08-31 00:59:27 -04003085func addD5BugTests() {
3086 testCases = append(testCases, testCase{
3087 testType: serverTest,
3088 name: "D5Bug-NoQuirk-Reject",
3089 config: Config{
3090 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3091 Bugs: ProtocolBugs{
3092 SSL3RSAKeyExchange: true,
3093 },
3094 },
3095 shouldFail: true,
3096 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3097 })
3098 testCases = append(testCases, testCase{
3099 testType: serverTest,
3100 name: "D5Bug-Quirk-Normal",
3101 config: Config{
3102 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3103 },
3104 flags: []string{"-tls-d5-bug"},
3105 })
3106 testCases = append(testCases, testCase{
3107 testType: serverTest,
3108 name: "D5Bug-Quirk-Bug",
3109 config: Config{
3110 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3111 Bugs: ProtocolBugs{
3112 SSL3RSAKeyExchange: true,
3113 },
3114 },
3115 flags: []string{"-tls-d5-bug"},
3116 })
3117}
3118
David Benjamine78bfde2014-09-06 12:45:15 -04003119func addExtensionTests() {
3120 testCases = append(testCases, testCase{
3121 testType: clientTest,
3122 name: "DuplicateExtensionClient",
3123 config: Config{
3124 Bugs: ProtocolBugs{
3125 DuplicateExtension: true,
3126 },
3127 },
3128 shouldFail: true,
3129 expectedLocalError: "remote error: error decoding message",
3130 })
3131 testCases = append(testCases, testCase{
3132 testType: serverTest,
3133 name: "DuplicateExtensionServer",
3134 config: Config{
3135 Bugs: ProtocolBugs{
3136 DuplicateExtension: true,
3137 },
3138 },
3139 shouldFail: true,
3140 expectedLocalError: "remote error: error decoding message",
3141 })
3142 testCases = append(testCases, testCase{
3143 testType: clientTest,
3144 name: "ServerNameExtensionClient",
3145 config: Config{
3146 Bugs: ProtocolBugs{
3147 ExpectServerName: "example.com",
3148 },
3149 },
3150 flags: []string{"-host-name", "example.com"},
3151 })
3152 testCases = append(testCases, testCase{
3153 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003154 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003155 config: Config{
3156 Bugs: ProtocolBugs{
3157 ExpectServerName: "mismatch.com",
3158 },
3159 },
3160 flags: []string{"-host-name", "example.com"},
3161 shouldFail: true,
3162 expectedLocalError: "tls: unexpected server name",
3163 })
3164 testCases = append(testCases, testCase{
3165 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003166 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003167 config: Config{
3168 Bugs: ProtocolBugs{
3169 ExpectServerName: "missing.com",
3170 },
3171 },
3172 shouldFail: true,
3173 expectedLocalError: "tls: unexpected server name",
3174 })
3175 testCases = append(testCases, testCase{
3176 testType: serverTest,
3177 name: "ServerNameExtensionServer",
3178 config: Config{
3179 ServerName: "example.com",
3180 },
3181 flags: []string{"-expect-server-name", "example.com"},
3182 resumeSession: true,
3183 })
David Benjaminae2888f2014-09-06 12:58:58 -04003184 testCases = append(testCases, testCase{
3185 testType: clientTest,
3186 name: "ALPNClient",
3187 config: Config{
3188 NextProtos: []string{"foo"},
3189 },
3190 flags: []string{
3191 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3192 "-expect-alpn", "foo",
3193 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003194 expectedNextProto: "foo",
3195 expectedNextProtoType: alpn,
3196 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003197 })
3198 testCases = append(testCases, testCase{
3199 testType: serverTest,
3200 name: "ALPNServer",
3201 config: Config{
3202 NextProtos: []string{"foo", "bar", "baz"},
3203 },
3204 flags: []string{
3205 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3206 "-select-alpn", "foo",
3207 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003208 expectedNextProto: "foo",
3209 expectedNextProtoType: alpn,
3210 resumeSession: true,
3211 })
3212 // Test that the server prefers ALPN over NPN.
3213 testCases = append(testCases, testCase{
3214 testType: serverTest,
3215 name: "ALPNServer-Preferred",
3216 config: Config{
3217 NextProtos: []string{"foo", "bar", "baz"},
3218 },
3219 flags: []string{
3220 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3221 "-select-alpn", "foo",
3222 "-advertise-npn", "\x03foo\x03bar\x03baz",
3223 },
3224 expectedNextProto: "foo",
3225 expectedNextProtoType: alpn,
3226 resumeSession: true,
3227 })
3228 testCases = append(testCases, testCase{
3229 testType: serverTest,
3230 name: "ALPNServer-Preferred-Swapped",
3231 config: Config{
3232 NextProtos: []string{"foo", "bar", "baz"},
3233 Bugs: ProtocolBugs{
3234 SwapNPNAndALPN: true,
3235 },
3236 },
3237 flags: []string{
3238 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3239 "-select-alpn", "foo",
3240 "-advertise-npn", "\x03foo\x03bar\x03baz",
3241 },
3242 expectedNextProto: "foo",
3243 expectedNextProtoType: alpn,
3244 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003245 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003246 var emptyString string
3247 testCases = append(testCases, testCase{
3248 testType: clientTest,
3249 name: "ALPNClient-EmptyProtocolName",
3250 config: Config{
3251 NextProtos: []string{""},
3252 Bugs: ProtocolBugs{
3253 // A server returning an empty ALPN protocol
3254 // should be rejected.
3255 ALPNProtocol: &emptyString,
3256 },
3257 },
3258 flags: []string{
3259 "-advertise-alpn", "\x03foo",
3260 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003261 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003262 expectedError: ":PARSE_TLSEXT:",
3263 })
3264 testCases = append(testCases, testCase{
3265 testType: serverTest,
3266 name: "ALPNServer-EmptyProtocolName",
3267 config: Config{
3268 // A ClientHello containing an empty ALPN protocol
3269 // should be rejected.
3270 NextProtos: []string{"foo", "", "baz"},
3271 },
3272 flags: []string{
3273 "-select-alpn", "foo",
3274 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003275 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003276 expectedError: ":PARSE_TLSEXT:",
3277 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003278 // Test that negotiating both NPN and ALPN is forbidden.
3279 testCases = append(testCases, testCase{
3280 name: "NegotiateALPNAndNPN",
3281 config: Config{
3282 NextProtos: []string{"foo", "bar", "baz"},
3283 Bugs: ProtocolBugs{
3284 NegotiateALPNAndNPN: true,
3285 },
3286 },
3287 flags: []string{
3288 "-advertise-alpn", "\x03foo",
3289 "-select-next-proto", "foo",
3290 },
3291 shouldFail: true,
3292 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3293 })
3294 testCases = append(testCases, testCase{
3295 name: "NegotiateALPNAndNPN-Swapped",
3296 config: Config{
3297 NextProtos: []string{"foo", "bar", "baz"},
3298 Bugs: ProtocolBugs{
3299 NegotiateALPNAndNPN: true,
3300 SwapNPNAndALPN: true,
3301 },
3302 },
3303 flags: []string{
3304 "-advertise-alpn", "\x03foo",
3305 "-select-next-proto", "foo",
3306 },
3307 shouldFail: true,
3308 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3309 })
Adam Langley38311732014-10-16 19:04:35 -07003310 // Resume with a corrupt ticket.
3311 testCases = append(testCases, testCase{
3312 testType: serverTest,
3313 name: "CorruptTicket",
3314 config: Config{
3315 Bugs: ProtocolBugs{
3316 CorruptTicket: true,
3317 },
3318 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003319 resumeSession: true,
3320 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003321 })
David Benjamind98452d2015-06-16 14:16:23 -04003322 // Test the ticket callback, with and without renewal.
3323 testCases = append(testCases, testCase{
3324 testType: serverTest,
3325 name: "TicketCallback",
3326 resumeSession: true,
3327 flags: []string{"-use-ticket-callback"},
3328 })
3329 testCases = append(testCases, testCase{
3330 testType: serverTest,
3331 name: "TicketCallback-Renew",
3332 config: Config{
3333 Bugs: ProtocolBugs{
3334 ExpectNewTicket: true,
3335 },
3336 },
3337 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3338 resumeSession: true,
3339 })
Adam Langley38311732014-10-16 19:04:35 -07003340 // Resume with an oversized session id.
3341 testCases = append(testCases, testCase{
3342 testType: serverTest,
3343 name: "OversizedSessionId",
3344 config: Config{
3345 Bugs: ProtocolBugs{
3346 OversizedSessionId: true,
3347 },
3348 },
3349 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003350 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003351 expectedError: ":DECODE_ERROR:",
3352 })
David Benjaminca6c8262014-11-15 19:06:08 -05003353 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3354 // are ignored.
3355 testCases = append(testCases, testCase{
3356 protocol: dtls,
3357 name: "SRTP-Client",
3358 config: Config{
3359 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3360 },
3361 flags: []string{
3362 "-srtp-profiles",
3363 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3364 },
3365 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3366 })
3367 testCases = append(testCases, testCase{
3368 protocol: dtls,
3369 testType: serverTest,
3370 name: "SRTP-Server",
3371 config: Config{
3372 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3373 },
3374 flags: []string{
3375 "-srtp-profiles",
3376 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3377 },
3378 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3379 })
3380 // Test that the MKI is ignored.
3381 testCases = append(testCases, testCase{
3382 protocol: dtls,
3383 testType: serverTest,
3384 name: "SRTP-Server-IgnoreMKI",
3385 config: Config{
3386 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3387 Bugs: ProtocolBugs{
3388 SRTPMasterKeyIdentifer: "bogus",
3389 },
3390 },
3391 flags: []string{
3392 "-srtp-profiles",
3393 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3394 },
3395 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3396 })
3397 // Test that SRTP isn't negotiated on the server if there were
3398 // no matching profiles.
3399 testCases = append(testCases, testCase{
3400 protocol: dtls,
3401 testType: serverTest,
3402 name: "SRTP-Server-NoMatch",
3403 config: Config{
3404 SRTPProtectionProfiles: []uint16{100, 101, 102},
3405 },
3406 flags: []string{
3407 "-srtp-profiles",
3408 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3409 },
3410 expectedSRTPProtectionProfile: 0,
3411 })
3412 // Test that the server returning an invalid SRTP profile is
3413 // flagged as an error by the client.
3414 testCases = append(testCases, testCase{
3415 protocol: dtls,
3416 name: "SRTP-Client-NoMatch",
3417 config: Config{
3418 Bugs: ProtocolBugs{
3419 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3420 },
3421 },
3422 flags: []string{
3423 "-srtp-profiles",
3424 "SRTP_AES128_CM_SHA1_80",
3425 },
3426 shouldFail: true,
3427 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3428 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003429 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003430 testCases = append(testCases, testCase{
3431 name: "SignedCertificateTimestampList",
3432 flags: []string{
3433 "-enable-signed-cert-timestamps",
3434 "-expect-signed-cert-timestamps",
3435 base64.StdEncoding.EncodeToString(testSCTList),
3436 },
3437 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003438 testCases = append(testCases, testCase{
3439 testType: clientTest,
3440 name: "ClientHelloPadding",
3441 config: Config{
3442 Bugs: ProtocolBugs{
3443 RequireClientHelloSize: 512,
3444 },
3445 },
3446 // This hostname just needs to be long enough to push the
3447 // ClientHello into F5's danger zone between 256 and 511 bytes
3448 // long.
3449 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3450 })
David Benjamine78bfde2014-09-06 12:45:15 -04003451}
3452
David Benjamin01fe8202014-09-24 15:21:44 -04003453func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003454 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003455 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003456 protocols := []protocol{tls}
3457 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3458 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003459 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003460 for _, protocol := range protocols {
3461 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3462 if protocol == dtls {
3463 suffix += "-DTLS"
3464 }
3465
David Benjaminece3de92015-03-16 18:02:20 -04003466 if sessionVers.version == resumeVers.version {
3467 testCases = append(testCases, testCase{
3468 protocol: protocol,
3469 name: "Resume-Client" + suffix,
3470 resumeSession: true,
3471 config: Config{
3472 MaxVersion: sessionVers.version,
3473 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003474 },
David Benjaminece3de92015-03-16 18:02:20 -04003475 expectedVersion: sessionVers.version,
3476 expectedResumeVersion: resumeVers.version,
3477 })
3478 } else {
3479 testCases = append(testCases, testCase{
3480 protocol: protocol,
3481 name: "Resume-Client-Mismatch" + suffix,
3482 resumeSession: true,
3483 config: Config{
3484 MaxVersion: sessionVers.version,
3485 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003486 },
David Benjaminece3de92015-03-16 18:02:20 -04003487 expectedVersion: sessionVers.version,
3488 resumeConfig: &Config{
3489 MaxVersion: resumeVers.version,
3490 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3491 Bugs: ProtocolBugs{
3492 AllowSessionVersionMismatch: true,
3493 },
3494 },
3495 expectedResumeVersion: resumeVers.version,
3496 shouldFail: true,
3497 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3498 })
3499 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003500
3501 testCases = append(testCases, testCase{
3502 protocol: protocol,
3503 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003504 resumeSession: true,
3505 config: Config{
3506 MaxVersion: sessionVers.version,
3507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3508 },
3509 expectedVersion: sessionVers.version,
3510 resumeConfig: &Config{
3511 MaxVersion: resumeVers.version,
3512 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3513 },
3514 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003515 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003516 expectedResumeVersion: resumeVers.version,
3517 })
3518
David Benjamin8b8c0062014-11-23 02:47:52 -05003519 testCases = append(testCases, testCase{
3520 protocol: protocol,
3521 testType: serverTest,
3522 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003523 resumeSession: true,
3524 config: Config{
3525 MaxVersion: sessionVers.version,
3526 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3527 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003528 expectedVersion: sessionVers.version,
3529 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003530 resumeConfig: &Config{
3531 MaxVersion: resumeVers.version,
3532 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3533 },
3534 expectedResumeVersion: resumeVers.version,
3535 })
3536 }
David Benjamin01fe8202014-09-24 15:21:44 -04003537 }
3538 }
David Benjaminece3de92015-03-16 18:02:20 -04003539
3540 testCases = append(testCases, testCase{
3541 name: "Resume-Client-CipherMismatch",
3542 resumeSession: true,
3543 config: Config{
3544 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3545 },
3546 resumeConfig: &Config{
3547 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3548 Bugs: ProtocolBugs{
3549 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3550 },
3551 },
3552 shouldFail: true,
3553 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3554 })
David Benjamin01fe8202014-09-24 15:21:44 -04003555}
3556
Adam Langley2ae77d22014-10-28 17:29:33 -07003557func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003558 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003559 testCases = append(testCases, testCase{
3560 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003561 name: "Renegotiate-Server-Forbidden",
David Benjaminb16346b2015-04-08 19:16:58 -04003562 renegotiate: true,
3563 flags: []string{"-reject-peer-renegotiations"},
3564 shouldFail: true,
3565 expectedError: ":NO_RENEGOTIATION:",
3566 expectedLocalError: "remote error: no renegotiation",
3567 })
Adam Langley5021b222015-06-12 18:27:58 -07003568 // The server shouldn't echo the renegotiation extension unless
3569 // requested by the client.
3570 testCases = append(testCases, testCase{
3571 testType: serverTest,
3572 name: "Renegotiate-Server-NoExt",
3573 config: Config{
3574 Bugs: ProtocolBugs{
3575 NoRenegotiationInfo: true,
3576 RequireRenegotiationInfo: true,
3577 },
3578 },
3579 shouldFail: true,
3580 expectedLocalError: "renegotiation extension missing",
3581 })
3582 // The renegotiation SCSV should be sufficient for the server to echo
3583 // the extension.
3584 testCases = append(testCases, testCase{
3585 testType: serverTest,
3586 name: "Renegotiate-Server-NoExt-SCSV",
3587 config: Config{
3588 Bugs: ProtocolBugs{
3589 NoRenegotiationInfo: true,
3590 SendRenegotiationSCSV: true,
3591 RequireRenegotiationInfo: true,
3592 },
3593 },
3594 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003595 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003596 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003597 config: Config{
3598 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003599 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003600 },
3601 },
3602 renegotiate: true,
3603 })
3604 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003605 name: "Renegotiate-Client-EmptyExt",
3606 renegotiate: true,
3607 config: Config{
3608 Bugs: ProtocolBugs{
3609 EmptyRenegotiationInfo: true,
3610 },
3611 },
3612 shouldFail: true,
3613 expectedError: ":RENEGOTIATION_MISMATCH:",
3614 })
3615 testCases = append(testCases, testCase{
3616 name: "Renegotiate-Client-BadExt",
3617 renegotiate: true,
3618 config: Config{
3619 Bugs: ProtocolBugs{
3620 BadRenegotiationInfo: true,
3621 },
3622 },
3623 shouldFail: true,
3624 expectedError: ":RENEGOTIATION_MISMATCH:",
3625 })
3626 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003627 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003628 config: Config{
3629 Bugs: ProtocolBugs{
3630 NoRenegotiationInfo: true,
3631 },
3632 },
3633 shouldFail: true,
3634 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3635 flags: []string{"-no-legacy-server-connect"},
3636 })
3637 testCases = append(testCases, testCase{
3638 name: "Renegotiate-Client-NoExt-Allowed",
3639 renegotiate: true,
3640 config: Config{
3641 Bugs: ProtocolBugs{
3642 NoRenegotiationInfo: true,
3643 },
3644 },
3645 })
3646 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003647 name: "Renegotiate-Client-SwitchCiphers",
3648 renegotiate: true,
3649 config: Config{
3650 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3651 },
3652 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3653 })
3654 testCases = append(testCases, testCase{
3655 name: "Renegotiate-Client-SwitchCiphers2",
3656 renegotiate: true,
3657 config: Config{
3658 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3659 },
3660 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3661 })
David Benjaminc44b1df2014-11-23 12:11:01 -05003662 testCases = append(testCases, testCase{
David Benjaminb16346b2015-04-08 19:16:58 -04003663 name: "Renegotiate-Client-Forbidden",
3664 renegotiate: true,
3665 flags: []string{"-reject-peer-renegotiations"},
3666 shouldFail: true,
3667 expectedError: ":NO_RENEGOTIATION:",
3668 expectedLocalError: "remote error: no renegotiation",
3669 })
3670 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003671 name: "Renegotiate-SameClientVersion",
3672 renegotiate: true,
3673 config: Config{
3674 MaxVersion: VersionTLS10,
3675 Bugs: ProtocolBugs{
3676 RequireSameRenegoClientVersion: true,
3677 },
3678 },
3679 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003680 testCases = append(testCases, testCase{
3681 name: "Renegotiate-FalseStart",
3682 renegotiate: true,
3683 config: Config{
3684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3685 NextProtos: []string{"foo"},
3686 },
3687 flags: []string{
3688 "-false-start",
3689 "-select-next-proto", "foo",
3690 },
3691 shimWritesFirst: true,
3692 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003693}
3694
David Benjamin5e961c12014-11-07 01:48:35 -05003695func addDTLSReplayTests() {
3696 // Test that sequence number replays are detected.
3697 testCases = append(testCases, testCase{
3698 protocol: dtls,
3699 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003700 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003701 replayWrites: true,
3702 })
3703
David Benjamin8e6db492015-07-25 18:29:23 -04003704 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003705 // than the retransmit window.
3706 testCases = append(testCases, testCase{
3707 protocol: dtls,
3708 name: "DTLS-Replay-LargeGaps",
3709 config: Config{
3710 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003711 SequenceNumberMapping: func(in uint64) uint64 {
3712 return in * 127
3713 },
David Benjamin5e961c12014-11-07 01:48:35 -05003714 },
3715 },
David Benjamin8e6db492015-07-25 18:29:23 -04003716 messageCount: 200,
3717 replayWrites: true,
3718 })
3719
3720 // Test the incoming sequence number changing non-monotonically.
3721 testCases = append(testCases, testCase{
3722 protocol: dtls,
3723 name: "DTLS-Replay-NonMonotonic",
3724 config: Config{
3725 Bugs: ProtocolBugs{
3726 SequenceNumberMapping: func(in uint64) uint64 {
3727 return in ^ 31
3728 },
3729 },
3730 },
3731 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003732 replayWrites: true,
3733 })
3734}
3735
David Benjamin000800a2014-11-14 01:43:59 -05003736var testHashes = []struct {
3737 name string
3738 id uint8
3739}{
3740 {"SHA1", hashSHA1},
3741 {"SHA224", hashSHA224},
3742 {"SHA256", hashSHA256},
3743 {"SHA384", hashSHA384},
3744 {"SHA512", hashSHA512},
3745}
3746
3747func addSigningHashTests() {
3748 // Make sure each hash works. Include some fake hashes in the list and
3749 // ensure they're ignored.
3750 for _, hash := range testHashes {
3751 testCases = append(testCases, testCase{
3752 name: "SigningHash-ClientAuth-" + hash.name,
3753 config: Config{
3754 ClientAuth: RequireAnyClientCert,
3755 SignatureAndHashes: []signatureAndHash{
3756 {signatureRSA, 42},
3757 {signatureRSA, hash.id},
3758 {signatureRSA, 255},
3759 },
3760 },
3761 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003762 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3763 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003764 },
3765 })
3766
3767 testCases = append(testCases, testCase{
3768 testType: serverTest,
3769 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3770 config: Config{
3771 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3772 SignatureAndHashes: []signatureAndHash{
3773 {signatureRSA, 42},
3774 {signatureRSA, hash.id},
3775 {signatureRSA, 255},
3776 },
3777 },
3778 })
3779 }
3780
3781 // Test that hash resolution takes the signature type into account.
3782 testCases = append(testCases, testCase{
3783 name: "SigningHash-ClientAuth-SignatureType",
3784 config: Config{
3785 ClientAuth: RequireAnyClientCert,
3786 SignatureAndHashes: []signatureAndHash{
3787 {signatureECDSA, hashSHA512},
3788 {signatureRSA, hashSHA384},
3789 {signatureECDSA, hashSHA1},
3790 },
3791 },
3792 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003793 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3794 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003795 },
3796 })
3797
3798 testCases = append(testCases, testCase{
3799 testType: serverTest,
3800 name: "SigningHash-ServerKeyExchange-SignatureType",
3801 config: Config{
3802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3803 SignatureAndHashes: []signatureAndHash{
3804 {signatureECDSA, hashSHA512},
3805 {signatureRSA, hashSHA384},
3806 {signatureECDSA, hashSHA1},
3807 },
3808 },
3809 })
3810
3811 // Test that, if the list is missing, the peer falls back to SHA-1.
3812 testCases = append(testCases, testCase{
3813 name: "SigningHash-ClientAuth-Fallback",
3814 config: Config{
3815 ClientAuth: RequireAnyClientCert,
3816 SignatureAndHashes: []signatureAndHash{
3817 {signatureRSA, hashSHA1},
3818 },
3819 Bugs: ProtocolBugs{
3820 NoSignatureAndHashes: true,
3821 },
3822 },
3823 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003824 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3825 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003826 },
3827 })
3828
3829 testCases = append(testCases, testCase{
3830 testType: serverTest,
3831 name: "SigningHash-ServerKeyExchange-Fallback",
3832 config: Config{
3833 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3834 SignatureAndHashes: []signatureAndHash{
3835 {signatureRSA, hashSHA1},
3836 },
3837 Bugs: ProtocolBugs{
3838 NoSignatureAndHashes: true,
3839 },
3840 },
3841 })
David Benjamin72dc7832015-03-16 17:49:43 -04003842
3843 // Test that hash preferences are enforced. BoringSSL defaults to
3844 // rejecting MD5 signatures.
3845 testCases = append(testCases, testCase{
3846 testType: serverTest,
3847 name: "SigningHash-ClientAuth-Enforced",
3848 config: Config{
3849 Certificates: []Certificate{rsaCertificate},
3850 SignatureAndHashes: []signatureAndHash{
3851 {signatureRSA, hashMD5},
3852 // Advertise SHA-1 so the handshake will
3853 // proceed, but the shim's preferences will be
3854 // ignored in CertificateVerify generation, so
3855 // MD5 will be chosen.
3856 {signatureRSA, hashSHA1},
3857 },
3858 Bugs: ProtocolBugs{
3859 IgnorePeerSignatureAlgorithmPreferences: true,
3860 },
3861 },
3862 flags: []string{"-require-any-client-certificate"},
3863 shouldFail: true,
3864 expectedError: ":WRONG_SIGNATURE_TYPE:",
3865 })
3866
3867 testCases = append(testCases, testCase{
3868 name: "SigningHash-ServerKeyExchange-Enforced",
3869 config: Config{
3870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3871 SignatureAndHashes: []signatureAndHash{
3872 {signatureRSA, hashMD5},
3873 },
3874 Bugs: ProtocolBugs{
3875 IgnorePeerSignatureAlgorithmPreferences: true,
3876 },
3877 },
3878 shouldFail: true,
3879 expectedError: ":WRONG_SIGNATURE_TYPE:",
3880 })
David Benjamin000800a2014-11-14 01:43:59 -05003881}
3882
David Benjamin83f90402015-01-27 01:09:43 -05003883// timeouts is the retransmit schedule for BoringSSL. It doubles and
3884// caps at 60 seconds. On the 13th timeout, it gives up.
3885var timeouts = []time.Duration{
3886 1 * time.Second,
3887 2 * time.Second,
3888 4 * time.Second,
3889 8 * time.Second,
3890 16 * time.Second,
3891 32 * time.Second,
3892 60 * time.Second,
3893 60 * time.Second,
3894 60 * time.Second,
3895 60 * time.Second,
3896 60 * time.Second,
3897 60 * time.Second,
3898 60 * time.Second,
3899}
3900
3901func addDTLSRetransmitTests() {
3902 // Test that this is indeed the timeout schedule. Stress all
3903 // four patterns of handshake.
3904 for i := 1; i < len(timeouts); i++ {
3905 number := strconv.Itoa(i)
3906 testCases = append(testCases, testCase{
3907 protocol: dtls,
3908 name: "DTLS-Retransmit-Client-" + number,
3909 config: Config{
3910 Bugs: ProtocolBugs{
3911 TimeoutSchedule: timeouts[:i],
3912 },
3913 },
3914 resumeSession: true,
3915 flags: []string{"-async"},
3916 })
3917 testCases = append(testCases, testCase{
3918 protocol: dtls,
3919 testType: serverTest,
3920 name: "DTLS-Retransmit-Server-" + number,
3921 config: Config{
3922 Bugs: ProtocolBugs{
3923 TimeoutSchedule: timeouts[:i],
3924 },
3925 },
3926 resumeSession: true,
3927 flags: []string{"-async"},
3928 })
3929 }
3930
3931 // Test that exceeding the timeout schedule hits a read
3932 // timeout.
3933 testCases = append(testCases, testCase{
3934 protocol: dtls,
3935 name: "DTLS-Retransmit-Timeout",
3936 config: Config{
3937 Bugs: ProtocolBugs{
3938 TimeoutSchedule: timeouts,
3939 },
3940 },
3941 resumeSession: true,
3942 flags: []string{"-async"},
3943 shouldFail: true,
3944 expectedError: ":READ_TIMEOUT_EXPIRED:",
3945 })
3946
3947 // Test that timeout handling has a fudge factor, due to API
3948 // problems.
3949 testCases = append(testCases, testCase{
3950 protocol: dtls,
3951 name: "DTLS-Retransmit-Fudge",
3952 config: Config{
3953 Bugs: ProtocolBugs{
3954 TimeoutSchedule: []time.Duration{
3955 timeouts[0] - 10*time.Millisecond,
3956 },
3957 },
3958 },
3959 resumeSession: true,
3960 flags: []string{"-async"},
3961 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05003962
3963 // Test that the final Finished retransmitting isn't
3964 // duplicated if the peer badly fragments everything.
3965 testCases = append(testCases, testCase{
3966 testType: serverTest,
3967 protocol: dtls,
3968 name: "DTLS-Retransmit-Fragmented",
3969 config: Config{
3970 Bugs: ProtocolBugs{
3971 TimeoutSchedule: []time.Duration{timeouts[0]},
3972 MaxHandshakeRecordLength: 2,
3973 },
3974 },
3975 flags: []string{"-async"},
3976 })
David Benjamin83f90402015-01-27 01:09:43 -05003977}
3978
David Benjaminc565ebb2015-04-03 04:06:36 -04003979func addExportKeyingMaterialTests() {
3980 for _, vers := range tlsVersions {
3981 if vers.version == VersionSSL30 {
3982 continue
3983 }
3984 testCases = append(testCases, testCase{
3985 name: "ExportKeyingMaterial-" + vers.name,
3986 config: Config{
3987 MaxVersion: vers.version,
3988 },
3989 exportKeyingMaterial: 1024,
3990 exportLabel: "label",
3991 exportContext: "context",
3992 useExportContext: true,
3993 })
3994 testCases = append(testCases, testCase{
3995 name: "ExportKeyingMaterial-NoContext-" + vers.name,
3996 config: Config{
3997 MaxVersion: vers.version,
3998 },
3999 exportKeyingMaterial: 1024,
4000 })
4001 testCases = append(testCases, testCase{
4002 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4003 config: Config{
4004 MaxVersion: vers.version,
4005 },
4006 exportKeyingMaterial: 1024,
4007 useExportContext: true,
4008 })
4009 testCases = append(testCases, testCase{
4010 name: "ExportKeyingMaterial-Small-" + vers.name,
4011 config: Config{
4012 MaxVersion: vers.version,
4013 },
4014 exportKeyingMaterial: 1,
4015 exportLabel: "label",
4016 exportContext: "context",
4017 useExportContext: true,
4018 })
4019 }
4020 testCases = append(testCases, testCase{
4021 name: "ExportKeyingMaterial-SSL3",
4022 config: Config{
4023 MaxVersion: VersionSSL30,
4024 },
4025 exportKeyingMaterial: 1024,
4026 exportLabel: "label",
4027 exportContext: "context",
4028 useExportContext: true,
4029 shouldFail: true,
4030 expectedError: "failed to export keying material",
4031 })
4032}
4033
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004034func addTLSUniqueTests() {
4035 for _, isClient := range []bool{false, true} {
4036 for _, isResumption := range []bool{false, true} {
4037 for _, hasEMS := range []bool{false, true} {
4038 var suffix string
4039 if isResumption {
4040 suffix = "Resume-"
4041 } else {
4042 suffix = "Full-"
4043 }
4044
4045 if hasEMS {
4046 suffix += "EMS-"
4047 } else {
4048 suffix += "NoEMS-"
4049 }
4050
4051 if isClient {
4052 suffix += "Client"
4053 } else {
4054 suffix += "Server"
4055 }
4056
4057 test := testCase{
4058 name: "TLSUnique-" + suffix,
4059 testTLSUnique: true,
4060 config: Config{
4061 Bugs: ProtocolBugs{
4062 NoExtendedMasterSecret: !hasEMS,
4063 },
4064 },
4065 }
4066
4067 if isResumption {
4068 test.resumeSession = true
4069 test.resumeConfig = &Config{
4070 Bugs: ProtocolBugs{
4071 NoExtendedMasterSecret: !hasEMS,
4072 },
4073 }
4074 }
4075
4076 if isResumption && !hasEMS {
4077 test.shouldFail = true
4078 test.expectedError = "failed to get tls-unique"
4079 }
4080
4081 testCases = append(testCases, test)
4082 }
4083 }
4084 }
4085}
4086
Adam Langley09505632015-07-30 18:10:13 -07004087func addCustomExtensionTests() {
4088 expectedContents := "custom extension"
4089 emptyString := ""
4090
4091 for _, isClient := range []bool{false, true} {
4092 suffix := "Server"
4093 flag := "-enable-server-custom-extension"
4094 testType := serverTest
4095 if isClient {
4096 suffix = "Client"
4097 flag = "-enable-client-custom-extension"
4098 testType = clientTest
4099 }
4100
4101 testCases = append(testCases, testCase{
4102 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004103 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004104 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004105 Bugs: ProtocolBugs{
4106 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004107 ExpectedCustomExtension: &expectedContents,
4108 },
4109 },
4110 flags: []string{flag},
4111 })
4112
4113 // If the parse callback fails, the handshake should also fail.
4114 testCases = append(testCases, testCase{
4115 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004116 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004117 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004118 Bugs: ProtocolBugs{
4119 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004120 ExpectedCustomExtension: &expectedContents,
4121 },
4122 },
David Benjamin399e7c92015-07-30 23:01:27 -04004123 flags: []string{flag},
4124 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004125 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4126 })
4127
4128 // If the add callback fails, the handshake should also fail.
4129 testCases = append(testCases, testCase{
4130 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004131 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004132 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004133 Bugs: ProtocolBugs{
4134 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004135 ExpectedCustomExtension: &expectedContents,
4136 },
4137 },
David Benjamin399e7c92015-07-30 23:01:27 -04004138 flags: []string{flag, "-custom-extension-fail-add"},
4139 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004140 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4141 })
4142
4143 // If the add callback returns zero, no extension should be
4144 // added.
4145 skipCustomExtension := expectedContents
4146 if isClient {
4147 // For the case where the client skips sending the
4148 // custom extension, the server must not “echo” it.
4149 skipCustomExtension = ""
4150 }
4151 testCases = append(testCases, testCase{
4152 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004153 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004154 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004155 Bugs: ProtocolBugs{
4156 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004157 ExpectedCustomExtension: &emptyString,
4158 },
4159 },
4160 flags: []string{flag, "-custom-extension-skip"},
4161 })
4162 }
4163
4164 // The custom extension add callback should not be called if the client
4165 // doesn't send the extension.
4166 testCases = append(testCases, testCase{
4167 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004168 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004169 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004170 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004171 ExpectedCustomExtension: &emptyString,
4172 },
4173 },
4174 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4175 })
Adam Langley2deb9842015-08-07 11:15:37 -07004176
4177 // Test an unknown extension from the server.
4178 testCases = append(testCases, testCase{
4179 testType: clientTest,
4180 name: "UnknownExtension-Client",
4181 config: Config{
4182 Bugs: ProtocolBugs{
4183 CustomExtension: expectedContents,
4184 },
4185 },
4186 shouldFail: true,
4187 expectedError: ":UNEXPECTED_EXTENSION:",
4188 })
Adam Langley09505632015-07-30 18:10:13 -07004189}
4190
Adam Langley7c803a62015-06-15 15:35:05 -07004191func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004192 defer wg.Done()
4193
4194 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004195 var err error
4196
4197 if *mallocTest < 0 {
4198 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004199 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004200 } else {
4201 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4202 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004203 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004204 if err != nil {
4205 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4206 }
4207 break
4208 }
4209 }
4210 }
Adam Langley95c29f32014-06-20 12:00:00 -07004211 statusChan <- statusMsg{test: test, err: err}
4212 }
4213}
4214
4215type statusMsg struct {
4216 test *testCase
4217 started bool
4218 err error
4219}
4220
David Benjamin5f237bc2015-02-11 17:14:15 -05004221func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004222 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004223
David Benjamin5f237bc2015-02-11 17:14:15 -05004224 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004225 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004226 if !*pipe {
4227 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004228 var erase string
4229 for i := 0; i < lineLen; i++ {
4230 erase += "\b \b"
4231 }
4232 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004233 }
4234
Adam Langley95c29f32014-06-20 12:00:00 -07004235 if msg.started {
4236 started++
4237 } else {
4238 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004239
4240 if msg.err != nil {
4241 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4242 failed++
4243 testOutput.addResult(msg.test.name, "FAIL")
4244 } else {
4245 if *pipe {
4246 // Print each test instead of a status line.
4247 fmt.Printf("PASSED (%s)\n", msg.test.name)
4248 }
4249 testOutput.addResult(msg.test.name, "PASS")
4250 }
Adam Langley95c29f32014-06-20 12:00:00 -07004251 }
4252
David Benjamin5f237bc2015-02-11 17:14:15 -05004253 if !*pipe {
4254 // Print a new status line.
4255 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4256 lineLen = len(line)
4257 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004258 }
Adam Langley95c29f32014-06-20 12:00:00 -07004259 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004260
4261 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004262}
4263
4264func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004265 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004266 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004267
Adam Langley7c803a62015-06-15 15:35:05 -07004268 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004269 addCipherSuiteTests()
4270 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004271 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004272 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004273 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004274 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004275 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004276 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004277 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004278 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004279 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004280 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004281 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004282 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004283 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004284 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004285 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004286 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004287 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004288 for _, async := range []bool{false, true} {
4289 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004290 for _, protocol := range []protocol{tls, dtls} {
4291 addStateMachineCoverageTests(async, splitHandshake, protocol)
4292 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004293 }
4294 }
Adam Langley95c29f32014-06-20 12:00:00 -07004295
4296 var wg sync.WaitGroup
4297
Adam Langley7c803a62015-06-15 15:35:05 -07004298 statusChan := make(chan statusMsg, *numWorkers)
4299 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004300 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004301
David Benjamin025b3d32014-07-01 19:53:04 -04004302 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004303
Adam Langley7c803a62015-06-15 15:35:05 -07004304 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004305 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004306 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004307 }
4308
David Benjamin025b3d32014-07-01 19:53:04 -04004309 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004310 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004311 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004312 }
4313 }
4314
4315 close(testChan)
4316 wg.Wait()
4317 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004318 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004319
4320 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004321
4322 if *jsonOutput != "" {
4323 if err := testOutput.writeTo(*jsonOutput); err != nil {
4324 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4325 }
4326 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004327
4328 if !testOutput.allPassed {
4329 os.Exit(1)
4330 }
Adam Langley95c29f32014-06-20 12:00:00 -07004331}