blob: 4748dd51386ce5d4dce769c4709345082dd53dfb [file] [log] [blame]
Adam Langleydc7e9c42015-09-29 15:21:04 -07001package runner
Adam Langley95c29f32014-06-20 12:00:00 -07002
3import (
4 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -04005 "crypto/ecdsa"
6 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -04007 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -04008 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -04009 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070010 "flag"
11 "fmt"
12 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070013 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070014 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070015 "net"
16 "os"
17 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040018 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040019 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080020 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070021 "strings"
22 "sync"
23 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050024 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070025)
26
Adam Langley69a01602014-11-17 17:26:55 -080027var (
David Benjamin5f237bc2015-02-11 17:14:15 -050028 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
29 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
30 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
31 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
32 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
33 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
34 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070035 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
36 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
37 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
38 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
Adam Langley69a01602014-11-17 17:26:55 -080039)
Adam Langley95c29f32014-06-20 12:00:00 -070040
David Benjamin025b3d32014-07-01 19:53:04 -040041const (
42 rsaCertificateFile = "cert.pem"
43 ecdsaCertificateFile = "ecdsa_cert.pem"
44)
45
46const (
David Benjamina08e49d2014-08-24 01:46:07 -040047 rsaKeyFile = "key.pem"
48 ecdsaKeyFile = "ecdsa_key.pem"
49 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040050)
51
Adam Langley95c29f32014-06-20 12:00:00 -070052var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040053var channelIDKey *ecdsa.PrivateKey
54var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070055
David Benjamin61f95272014-11-25 01:55:35 -050056var testOCSPResponse = []byte{1, 2, 3, 4}
57var testSCTList = []byte{5, 6, 7, 8}
58
Adam Langley95c29f32014-06-20 12:00:00 -070059func initCertificates() {
60 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070061 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070062 if err != nil {
63 panic(err)
64 }
David Benjamin61f95272014-11-25 01:55:35 -050065 rsaCertificate.OCSPStaple = testOCSPResponse
66 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070067
Adam Langley7c803a62015-06-15 15:35:05 -070068 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070069 if err != nil {
70 panic(err)
71 }
David Benjamin61f95272014-11-25 01:55:35 -050072 ecdsaCertificate.OCSPStaple = testOCSPResponse
73 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040074
Adam Langley7c803a62015-06-15 15:35:05 -070075 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040076 if err != nil {
77 panic(err)
78 }
79 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
80 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
81 panic("bad key type")
82 }
83 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
84 if err != nil {
85 panic(err)
86 }
87 if channelIDKey.Curve != elliptic.P256() {
88 panic("bad curve")
89 }
90
91 channelIDBytes = make([]byte, 64)
92 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
93 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070094}
95
96var certificateOnce sync.Once
97
98func getRSACertificate() Certificate {
99 certificateOnce.Do(initCertificates)
100 return rsaCertificate
101}
102
103func getECDSACertificate() Certificate {
104 certificateOnce.Do(initCertificates)
105 return ecdsaCertificate
106}
107
David Benjamin025b3d32014-07-01 19:53:04 -0400108type testType int
109
110const (
111 clientTest testType = iota
112 serverTest
113)
114
David Benjamin6fd297b2014-08-11 18:43:38 -0400115type protocol int
116
117const (
118 tls protocol = iota
119 dtls
120)
121
David Benjaminfc7b0862014-09-06 13:21:53 -0400122const (
123 alpn = 1
124 npn = 2
125)
126
Adam Langley95c29f32014-06-20 12:00:00 -0700127type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400128 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400129 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700130 name string
131 config Config
132 shouldFail bool
133 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700134 // expectedLocalError, if not empty, contains a substring that must be
135 // found in the local error.
136 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400137 // expectedVersion, if non-zero, specifies the TLS version that must be
138 // negotiated.
139 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400140 // expectedResumeVersion, if non-zero, specifies the TLS version that
141 // must be negotiated on resumption. If zero, expectedVersion is used.
142 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400143 // expectedCipher, if non-zero, specifies the TLS cipher suite that
144 // should be negotiated.
145 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400146 // expectChannelID controls whether the connection should have
147 // negotiated a Channel ID with channelIDKey.
148 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400149 // expectedNextProto controls whether the connection should
150 // negotiate a next protocol via NPN or ALPN.
151 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400152 // expectNoNextProto, if true, means that no next protocol should be
153 // negotiated.
154 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400155 // expectedNextProtoType, if non-zero, is the expected next
156 // protocol negotiation mechanism.
157 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500158 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
159 // should be negotiated. If zero, none should be negotiated.
160 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100161 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
162 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100163 // expectedSCTList, if not nil, is the expected SCT list to be received.
164 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400165 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
166 // hash function that the client should have used when signing the
167 // handshake with a client certificate.
168 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700169 // messageLen is the length, in bytes, of the test message that will be
170 // sent.
171 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400172 // messageCount is the number of test messages that will be sent.
173 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400174 // digestPrefs is the list of digest preferences from the client.
175 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400176 // certFile is the path to the certificate to use for the server.
177 certFile string
178 // keyFile is the path to the private key to use for the server.
179 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400180 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400181 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400182 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700183 // expectResumeRejected, if true, specifies that the attempted
184 // resumption must be rejected by the client. This is only valid for a
185 // serverTest.
186 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400187 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500188 // resumption. Unless newSessionsOnResume is set,
189 // SessionTicketKey, ServerSessionCache, and
190 // ClientSessionCache are copied from the initial connection's
191 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400192 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500193 // newSessionsOnResume, if true, will cause resumeConfig to
194 // use a different session resumption context.
195 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400196 // noSessionCache, if true, will cause the server to run without a
197 // session cache.
198 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400199 // sendPrefix sends a prefix on the socket before actually performing a
200 // handshake.
201 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400202 // shimWritesFirst controls whether the shim sends an initial "hello"
203 // message before doing a roundtrip with the runner.
204 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400205 // shimShutsDown, if true, runs a test where the shim shuts down the
206 // connection immediately after the handshake rather than echoing
207 // messages from the runner.
208 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400209 // renegotiate indicates the number of times the connection should be
210 // renegotiated during the exchange.
211 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700212 // renegotiateCiphers is a list of ciphersuite ids that will be
213 // switched in just before renegotiation.
214 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500215 // replayWrites, if true, configures the underlying transport
216 // to replay every write it makes in DTLS tests.
217 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500218 // damageFirstWrite, if true, configures the underlying transport to
219 // damage the final byte of the first application data write.
220 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400221 // exportKeyingMaterial, if non-zero, configures the test to exchange
222 // keying material and verify they match.
223 exportKeyingMaterial int
224 exportLabel string
225 exportContext string
226 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400227 // flags, if not empty, contains a list of command-line flags that will
228 // be passed to the shim program.
229 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700230 // testTLSUnique, if true, causes the shim to send the tls-unique value
231 // which will be compared against the expected value.
232 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400233 // sendEmptyRecords is the number of consecutive empty records to send
234 // before and after the test message.
235 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400236 // sendWarningAlerts is the number of consecutive warning alerts to send
237 // before and after the test message.
238 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400239 // expectMessageDropped, if true, means the test message is expected to
240 // be dropped by the client rather than echoed back.
241 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700242}
243
Adam Langley7c803a62015-06-15 15:35:05 -0700244var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700245
David Benjamin8e6db492015-07-25 18:29:23 -0400246func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin5fa3eba2015-01-22 16:35:40 -0500247 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500248
David Benjamin6fd297b2014-08-11 18:43:38 -0400249 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500250 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
251 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500252 }
253
254 if *flagDebug {
255 local, peer := "client", "server"
256 if test.testType == clientTest {
257 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500258 }
David Benjaminebda9b32015-11-02 15:33:18 -0500259 connDebug := &recordingConn{
260 Conn: conn,
261 isDatagram: test.protocol == dtls,
262 local: local,
263 peer: peer,
264 }
265 conn = connDebug
266 defer func() {
267 connDebug.WriteTo(os.Stdout)
268 }()
269
270 if config.Bugs.PacketAdaptor != nil {
271 config.Bugs.PacketAdaptor.debug = connDebug
272 }
273 }
274
275 if test.replayWrites {
276 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400277 }
278
David Benjamin5fa3eba2015-01-22 16:35:40 -0500279 if test.damageFirstWrite {
280 connDamage = newDamageAdaptor(conn)
281 conn = connDamage
282 }
283
David Benjamin6fd297b2014-08-11 18:43:38 -0400284 if test.sendPrefix != "" {
285 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
286 return err
287 }
David Benjamin98e882e2014-08-08 13:24:34 -0400288 }
289
David Benjamin1d5c83e2014-07-22 19:20:02 -0400290 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400291 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400292 if test.protocol == dtls {
293 tlsConn = DTLSServer(conn, config)
294 } else {
295 tlsConn = Server(conn, config)
296 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400297 } else {
298 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400299 if test.protocol == dtls {
300 tlsConn = DTLSClient(conn, config)
301 } else {
302 tlsConn = Client(conn, config)
303 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400304 }
David Benjamin30789da2015-08-29 22:56:45 -0400305 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400306
Adam Langley95c29f32014-06-20 12:00:00 -0700307 if err := tlsConn.Handshake(); err != nil {
308 return err
309 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700310
David Benjamin01fe8202014-09-24 15:21:44 -0400311 // TODO(davidben): move all per-connection expectations into a dedicated
312 // expectations struct that can be specified separately for the two
313 // legs.
314 expectedVersion := test.expectedVersion
315 if isResume && test.expectedResumeVersion != 0 {
316 expectedVersion = test.expectedResumeVersion
317 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700318 connState := tlsConn.ConnectionState()
319 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400320 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400321 }
322
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700323 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400324 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
325 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700326 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
327 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
328 }
David Benjamin90da8c82015-04-20 14:57:57 -0400329
David Benjamina08e49d2014-08-24 01:46:07 -0400330 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700331 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400332 if channelID == nil {
333 return fmt.Errorf("no channel ID negotiated")
334 }
335 if channelID.Curve != channelIDKey.Curve ||
336 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
337 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
338 return fmt.Errorf("incorrect channel ID")
339 }
340 }
341
David Benjaminae2888f2014-09-06 12:58:58 -0400342 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700343 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400344 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
345 }
346 }
347
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 if test.expectNoNextProto {
349 if actual := connState.NegotiatedProtocol; actual != "" {
350 return fmt.Errorf("got unexpected next proto %s", actual)
351 }
352 }
353
David Benjaminfc7b0862014-09-06 13:21:53 -0400354 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700355 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400356 return fmt.Errorf("next proto type mismatch")
357 }
358 }
359
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700360 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500361 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
362 }
363
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100364 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
365 return fmt.Errorf("OCSP Response mismatch")
366 }
367
Paul Lietar4fac72e2015-09-09 13:44:55 +0100368 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
369 return fmt.Errorf("SCT list mismatch")
370 }
371
Steven Valdez0d62f262015-09-04 12:41:04 -0400372 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
373 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
374 }
375
David Benjaminc565ebb2015-04-03 04:06:36 -0400376 if test.exportKeyingMaterial > 0 {
377 actual := make([]byte, test.exportKeyingMaterial)
378 if _, err := io.ReadFull(tlsConn, actual); err != nil {
379 return err
380 }
381 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
382 if err != nil {
383 return err
384 }
385 if !bytes.Equal(actual, expected) {
386 return fmt.Errorf("keying material mismatch")
387 }
388 }
389
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700390 if test.testTLSUnique {
391 var peersValue [12]byte
392 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
393 return err
394 }
395 expected := tlsConn.ConnectionState().TLSUnique
396 if !bytes.Equal(peersValue[:], expected) {
397 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
398 }
399 }
400
David Benjamine58c4f52014-08-24 03:47:07 -0400401 if test.shimWritesFirst {
402 var buf [5]byte
403 _, err := io.ReadFull(tlsConn, buf[:])
404 if err != nil {
405 return err
406 }
407 if string(buf[:]) != "hello" {
408 return fmt.Errorf("bad initial message")
409 }
410 }
411
David Benjamina8ebe222015-06-06 03:04:39 -0400412 for i := 0; i < test.sendEmptyRecords; i++ {
413 tlsConn.Write(nil)
414 }
415
David Benjamin24f346d2015-06-06 03:28:08 -0400416 for i := 0; i < test.sendWarningAlerts; i++ {
417 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
418 }
419
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400420 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700421 if test.renegotiateCiphers != nil {
422 config.CipherSuites = test.renegotiateCiphers
423 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400424 for i := 0; i < test.renegotiate; i++ {
425 if err := tlsConn.Renegotiate(); err != nil {
426 return err
427 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700428 }
429 } else if test.renegotiateCiphers != nil {
430 panic("renegotiateCiphers without renegotiate")
431 }
432
David Benjamin5fa3eba2015-01-22 16:35:40 -0500433 if test.damageFirstWrite {
434 connDamage.setDamage(true)
435 tlsConn.Write([]byte("DAMAGED WRITE"))
436 connDamage.setDamage(false)
437 }
438
David Benjamin8e6db492015-07-25 18:29:23 -0400439 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700440 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400441 if test.protocol == dtls {
442 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
443 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700444 // Read until EOF.
445 _, err := io.Copy(ioutil.Discard, tlsConn)
446 return err
447 }
David Benjamin4417d052015-04-05 04:17:25 -0400448 if messageLen == 0 {
449 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700450 }
Adam Langley95c29f32014-06-20 12:00:00 -0700451
David Benjamin8e6db492015-07-25 18:29:23 -0400452 messageCount := test.messageCount
453 if messageCount == 0 {
454 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400455 }
456
David Benjamin8e6db492015-07-25 18:29:23 -0400457 for j := 0; j < messageCount; j++ {
458 testMessage := make([]byte, messageLen)
459 for i := range testMessage {
460 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400461 }
David Benjamin8e6db492015-07-25 18:29:23 -0400462 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700463
David Benjamin8e6db492015-07-25 18:29:23 -0400464 for i := 0; i < test.sendEmptyRecords; i++ {
465 tlsConn.Write(nil)
466 }
467
468 for i := 0; i < test.sendWarningAlerts; i++ {
469 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
470 }
471
David Benjamin4f75aaf2015-09-01 16:53:10 -0400472 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400473 // The shim will not respond.
474 continue
475 }
476
David Benjamin8e6db492015-07-25 18:29:23 -0400477 buf := make([]byte, len(testMessage))
478 if test.protocol == dtls {
479 bufTmp := make([]byte, len(buf)+1)
480 n, err := tlsConn.Read(bufTmp)
481 if err != nil {
482 return err
483 }
484 if n != len(buf) {
485 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
486 }
487 copy(buf, bufTmp)
488 } else {
489 _, err := io.ReadFull(tlsConn, buf)
490 if err != nil {
491 return err
492 }
493 }
494
495 for i, v := range buf {
496 if v != testMessage[i]^0xff {
497 return fmt.Errorf("bad reply contents at byte %d", i)
498 }
Adam Langley95c29f32014-06-20 12:00:00 -0700499 }
500 }
501
502 return nil
503}
504
David Benjamin325b5c32014-07-01 19:40:31 -0400505func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
506 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700507 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400508 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700509 }
David Benjamin325b5c32014-07-01 19:40:31 -0400510 valgrindArgs = append(valgrindArgs, path)
511 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700512
David Benjamin325b5c32014-07-01 19:40:31 -0400513 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700514}
515
David Benjamin325b5c32014-07-01 19:40:31 -0400516func gdbOf(path string, args ...string) *exec.Cmd {
517 xtermArgs := []string{"-e", "gdb", "--args"}
518 xtermArgs = append(xtermArgs, path)
519 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700520
David Benjamin325b5c32014-07-01 19:40:31 -0400521 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700522}
523
Adam Langley69a01602014-11-17 17:26:55 -0800524type moreMallocsError struct{}
525
526func (moreMallocsError) Error() string {
527 return "child process did not exhaust all allocation calls"
528}
529
530var errMoreMallocs = moreMallocsError{}
531
David Benjamin87c8a642015-02-21 01:54:29 -0500532// accept accepts a connection from listener, unless waitChan signals a process
533// exit first.
534func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
535 type connOrError struct {
536 conn net.Conn
537 err error
538 }
539 connChan := make(chan connOrError, 1)
540 go func() {
541 conn, err := listener.Accept()
542 connChan <- connOrError{conn, err}
543 close(connChan)
544 }()
545 select {
546 case result := <-connChan:
547 return result.conn, result.err
548 case childErr := <-waitChan:
549 waitChan <- childErr
550 return nil, fmt.Errorf("child exited early: %s", childErr)
551 }
552}
553
Adam Langley7c803a62015-06-15 15:35:05 -0700554func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700555 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
556 panic("Error expected without shouldFail in " + test.name)
557 }
558
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700559 if test.expectResumeRejected && !test.resumeSession {
560 panic("expectResumeRejected without resumeSession in " + test.name)
561 }
562
Steven Valdez0d62f262015-09-04 12:41:04 -0400563 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
564 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
565 }
566
David Benjamin87c8a642015-02-21 01:54:29 -0500567 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
568 if err != nil {
569 panic(err)
570 }
571 defer func() {
572 if listener != nil {
573 listener.Close()
574 }
575 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700576
David Benjamin87c8a642015-02-21 01:54:29 -0500577 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400578 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400579 flags = append(flags, "-server")
580
David Benjamin025b3d32014-07-01 19:53:04 -0400581 flags = append(flags, "-key-file")
582 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700583 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400584 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700585 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400586 }
587
588 flags = append(flags, "-cert-file")
589 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700590 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400591 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700592 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400593 }
594 }
David Benjamin5a593af2014-08-11 19:51:50 -0400595
Steven Valdez0d62f262015-09-04 12:41:04 -0400596 if test.digestPrefs != "" {
597 flags = append(flags, "-digest-prefs")
598 flags = append(flags, test.digestPrefs)
599 }
600
David Benjamin6fd297b2014-08-11 18:43:38 -0400601 if test.protocol == dtls {
602 flags = append(flags, "-dtls")
603 }
604
David Benjamin5a593af2014-08-11 19:51:50 -0400605 if test.resumeSession {
606 flags = append(flags, "-resume")
607 }
608
David Benjamine58c4f52014-08-24 03:47:07 -0400609 if test.shimWritesFirst {
610 flags = append(flags, "-shim-writes-first")
611 }
612
David Benjamin30789da2015-08-29 22:56:45 -0400613 if test.shimShutsDown {
614 flags = append(flags, "-shim-shuts-down")
615 }
616
David Benjaminc565ebb2015-04-03 04:06:36 -0400617 if test.exportKeyingMaterial > 0 {
618 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
619 flags = append(flags, "-export-label", test.exportLabel)
620 flags = append(flags, "-export-context", test.exportContext)
621 if test.useExportContext {
622 flags = append(flags, "-use-export-context")
623 }
624 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700625 if test.expectResumeRejected {
626 flags = append(flags, "-expect-session-miss")
627 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400628
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700629 if test.testTLSUnique {
630 flags = append(flags, "-tls-unique")
631 }
632
David Benjamin025b3d32014-07-01 19:53:04 -0400633 flags = append(flags, test.flags...)
634
635 var shim *exec.Cmd
636 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700637 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700638 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700639 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400640 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700641 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400642 }
David Benjamin025b3d32014-07-01 19:53:04 -0400643 shim.Stdin = os.Stdin
644 var stdoutBuf, stderrBuf bytes.Buffer
645 shim.Stdout = &stdoutBuf
646 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800647 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500648 shim.Env = os.Environ()
649 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800650 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400651 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800652 }
653 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
654 }
David Benjamin025b3d32014-07-01 19:53:04 -0400655
656 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700657 panic(err)
658 }
David Benjamin87c8a642015-02-21 01:54:29 -0500659 waitChan := make(chan error, 1)
660 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700661
662 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400663 if !test.noSessionCache {
664 config.ClientSessionCache = NewLRUClientSessionCache(1)
665 config.ServerSessionCache = NewLRUServerSessionCache(1)
666 }
David Benjamin025b3d32014-07-01 19:53:04 -0400667 if test.testType == clientTest {
668 if len(config.Certificates) == 0 {
669 config.Certificates = []Certificate{getRSACertificate()}
670 }
David Benjamin87c8a642015-02-21 01:54:29 -0500671 } else {
672 // Supply a ServerName to ensure a constant session cache key,
673 // rather than falling back to net.Conn.RemoteAddr.
674 if len(config.ServerName) == 0 {
675 config.ServerName = "test"
676 }
David Benjamin025b3d32014-07-01 19:53:04 -0400677 }
Adam Langley95c29f32014-06-20 12:00:00 -0700678
David Benjamin87c8a642015-02-21 01:54:29 -0500679 conn, err := acceptOrWait(listener, waitChan)
680 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400681 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500682 conn.Close()
683 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500684
David Benjamin1d5c83e2014-07-22 19:20:02 -0400685 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400686 var resumeConfig Config
687 if test.resumeConfig != nil {
688 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500689 if len(resumeConfig.ServerName) == 0 {
690 resumeConfig.ServerName = config.ServerName
691 }
David Benjamin01fe8202014-09-24 15:21:44 -0400692 if len(resumeConfig.Certificates) == 0 {
693 resumeConfig.Certificates = []Certificate{getRSACertificate()}
694 }
David Benjaminba4594a2015-06-18 18:36:15 -0400695 if test.newSessionsOnResume {
696 if !test.noSessionCache {
697 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
698 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
699 }
700 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500701 resumeConfig.SessionTicketKey = config.SessionTicketKey
702 resumeConfig.ClientSessionCache = config.ClientSessionCache
703 resumeConfig.ServerSessionCache = config.ServerSessionCache
704 }
David Benjamin01fe8202014-09-24 15:21:44 -0400705 } else {
706 resumeConfig = config
707 }
David Benjamin87c8a642015-02-21 01:54:29 -0500708 var connResume net.Conn
709 connResume, err = acceptOrWait(listener, waitChan)
710 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400711 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500712 connResume.Close()
713 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400714 }
715
David Benjamin87c8a642015-02-21 01:54:29 -0500716 // Close the listener now. This is to avoid hangs should the shim try to
717 // open more connections than expected.
718 listener.Close()
719 listener = nil
720
721 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800722 if exitError, ok := childErr.(*exec.ExitError); ok {
723 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
724 return errMoreMallocs
725 }
726 }
Adam Langley95c29f32014-06-20 12:00:00 -0700727
728 stdout := string(stdoutBuf.Bytes())
729 stderr := string(stderrBuf.Bytes())
730 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400731 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700732 localError := "none"
733 if err != nil {
734 localError = err.Error()
735 }
736 if len(test.expectedLocalError) != 0 {
737 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
738 }
Adam Langley95c29f32014-06-20 12:00:00 -0700739
740 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700741 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700742 if childErr != nil {
743 childError = childErr.Error()
744 }
745
746 var msg string
747 switch {
748 case failed && !test.shouldFail:
749 msg = "unexpected failure"
750 case !failed && test.shouldFail:
751 msg = "unexpected success"
752 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700753 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700754 default:
755 panic("internal error")
756 }
757
David Benjaminc565ebb2015-04-03 04:06:36 -0400758 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700759 }
760
David Benjaminc565ebb2015-04-03 04:06:36 -0400761 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700762 println(stderr)
763 }
764
765 return nil
766}
767
768var tlsVersions = []struct {
769 name string
770 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400771 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500772 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700773}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500774 {"SSL3", VersionSSL30, "-no-ssl3", false},
775 {"TLS1", VersionTLS10, "-no-tls1", true},
776 {"TLS11", VersionTLS11, "-no-tls11", false},
777 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700778}
779
780var testCipherSuites = []struct {
781 name string
782 id uint16
783}{
784 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400785 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700786 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400787 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400788 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700789 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400790 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400791 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
792 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400793 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400794 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
795 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400796 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700797 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
798 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400799 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
800 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700801 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400802 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400803 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700804 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700805 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700806 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400807 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400808 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700809 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400810 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400811 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700812 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400813 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
814 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700815 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
816 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400817 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700818 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400819 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700820 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700821}
822
David Benjamin8b8c0062014-11-23 02:47:52 -0500823func hasComponent(suiteName, component string) bool {
824 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
825}
826
David Benjaminf7768e42014-08-31 02:06:47 -0400827func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500828 return hasComponent(suiteName, "GCM") ||
829 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400830 hasComponent(suiteName, "SHA384") ||
831 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500832}
833
834func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700835 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400836}
837
Adam Langleya7997f12015-05-14 17:38:50 -0700838func bigFromHex(hex string) *big.Int {
839 ret, ok := new(big.Int).SetString(hex, 16)
840 if !ok {
841 panic("failed to parse hex number 0x" + hex)
842 }
843 return ret
844}
845
Adam Langley7c803a62015-06-15 15:35:05 -0700846func addBasicTests() {
847 basicTests := []testCase{
848 {
849 name: "BadRSASignature",
850 config: Config{
851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
852 Bugs: ProtocolBugs{
853 InvalidSKXSignature: true,
854 },
855 },
856 shouldFail: true,
857 expectedError: ":BAD_SIGNATURE:",
858 },
859 {
860 name: "BadECDSASignature",
861 config: Config{
862 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
863 Bugs: ProtocolBugs{
864 InvalidSKXSignature: true,
865 },
866 Certificates: []Certificate{getECDSACertificate()},
867 },
868 shouldFail: true,
869 expectedError: ":BAD_SIGNATURE:",
870 },
871 {
David Benjamin6de0e532015-07-28 22:43:19 -0400872 testType: serverTest,
873 name: "BadRSASignature-ClientAuth",
874 config: Config{
875 Bugs: ProtocolBugs{
876 InvalidCertVerifySignature: true,
877 },
878 Certificates: []Certificate{getRSACertificate()},
879 },
880 shouldFail: true,
881 expectedError: ":BAD_SIGNATURE:",
882 flags: []string{"-require-any-client-certificate"},
883 },
884 {
885 testType: serverTest,
886 name: "BadECDSASignature-ClientAuth",
887 config: Config{
888 Bugs: ProtocolBugs{
889 InvalidCertVerifySignature: true,
890 },
891 Certificates: []Certificate{getECDSACertificate()},
892 },
893 shouldFail: true,
894 expectedError: ":BAD_SIGNATURE:",
895 flags: []string{"-require-any-client-certificate"},
896 },
897 {
Adam Langley7c803a62015-06-15 15:35:05 -0700898 name: "BadECDSACurve",
899 config: Config{
900 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
901 Bugs: ProtocolBugs{
902 InvalidSKXCurve: true,
903 },
904 Certificates: []Certificate{getECDSACertificate()},
905 },
906 shouldFail: true,
907 expectedError: ":WRONG_CURVE:",
908 },
909 {
Adam Langley7c803a62015-06-15 15:35:05 -0700910 name: "NoFallbackSCSV",
911 config: Config{
912 Bugs: ProtocolBugs{
913 FailIfNotFallbackSCSV: true,
914 },
915 },
916 shouldFail: true,
917 expectedLocalError: "no fallback SCSV found",
918 },
919 {
920 name: "SendFallbackSCSV",
921 config: Config{
922 Bugs: ProtocolBugs{
923 FailIfNotFallbackSCSV: true,
924 },
925 },
926 flags: []string{"-fallback-scsv"},
927 },
928 {
929 name: "ClientCertificateTypes",
930 config: Config{
931 ClientAuth: RequestClientCert,
932 ClientCertificateTypes: []byte{
933 CertTypeDSSSign,
934 CertTypeRSASign,
935 CertTypeECDSASign,
936 },
937 },
938 flags: []string{
939 "-expect-certificate-types",
940 base64.StdEncoding.EncodeToString([]byte{
941 CertTypeDSSSign,
942 CertTypeRSASign,
943 CertTypeECDSASign,
944 }),
945 },
946 },
947 {
948 name: "NoClientCertificate",
949 config: Config{
950 ClientAuth: RequireAnyClientCert,
951 },
952 shouldFail: true,
953 expectedLocalError: "client didn't provide a certificate",
954 },
955 {
956 name: "UnauthenticatedECDH",
957 config: Config{
958 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
959 Bugs: ProtocolBugs{
960 UnauthenticatedECDH: true,
961 },
962 },
963 shouldFail: true,
964 expectedError: ":UNEXPECTED_MESSAGE:",
965 },
966 {
967 name: "SkipCertificateStatus",
968 config: Config{
969 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
970 Bugs: ProtocolBugs{
971 SkipCertificateStatus: true,
972 },
973 },
974 flags: []string{
975 "-enable-ocsp-stapling",
976 },
977 },
978 {
979 name: "SkipServerKeyExchange",
980 config: Config{
981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
982 Bugs: ProtocolBugs{
983 SkipServerKeyExchange: true,
984 },
985 },
986 shouldFail: true,
987 expectedError: ":UNEXPECTED_MESSAGE:",
988 },
989 {
990 name: "SkipChangeCipherSpec-Client",
991 config: Config{
992 Bugs: ProtocolBugs{
993 SkipChangeCipherSpec: true,
994 },
995 },
996 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -0500997 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -0700998 },
999 {
1000 testType: serverTest,
1001 name: "SkipChangeCipherSpec-Server",
1002 config: Config{
1003 Bugs: ProtocolBugs{
1004 SkipChangeCipherSpec: true,
1005 },
1006 },
1007 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001008 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001009 },
1010 {
1011 testType: serverTest,
1012 name: "SkipChangeCipherSpec-Server-NPN",
1013 config: Config{
1014 NextProtos: []string{"bar"},
1015 Bugs: ProtocolBugs{
1016 SkipChangeCipherSpec: true,
1017 },
1018 },
1019 flags: []string{
1020 "-advertise-npn", "\x03foo\x03bar\x03baz",
1021 },
1022 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001023 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001024 },
1025 {
1026 name: "FragmentAcrossChangeCipherSpec-Client",
1027 config: Config{
1028 Bugs: ProtocolBugs{
1029 FragmentAcrossChangeCipherSpec: true,
1030 },
1031 },
1032 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001033 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001034 },
1035 {
1036 testType: serverTest,
1037 name: "FragmentAcrossChangeCipherSpec-Server",
1038 config: Config{
1039 Bugs: ProtocolBugs{
1040 FragmentAcrossChangeCipherSpec: true,
1041 },
1042 },
1043 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001044 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001045 },
1046 {
1047 testType: serverTest,
1048 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1049 config: Config{
1050 NextProtos: []string{"bar"},
1051 Bugs: ProtocolBugs{
1052 FragmentAcrossChangeCipherSpec: true,
1053 },
1054 },
1055 flags: []string{
1056 "-advertise-npn", "\x03foo\x03bar\x03baz",
1057 },
1058 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001059 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001060 },
1061 {
1062 testType: serverTest,
1063 name: "Alert",
1064 config: Config{
1065 Bugs: ProtocolBugs{
1066 SendSpuriousAlert: alertRecordOverflow,
1067 },
1068 },
1069 shouldFail: true,
1070 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1071 },
1072 {
1073 protocol: dtls,
1074 testType: serverTest,
1075 name: "Alert-DTLS",
1076 config: Config{
1077 Bugs: ProtocolBugs{
1078 SendSpuriousAlert: alertRecordOverflow,
1079 },
1080 },
1081 shouldFail: true,
1082 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1083 },
1084 {
1085 testType: serverTest,
1086 name: "FragmentAlert",
1087 config: Config{
1088 Bugs: ProtocolBugs{
1089 FragmentAlert: true,
1090 SendSpuriousAlert: alertRecordOverflow,
1091 },
1092 },
1093 shouldFail: true,
1094 expectedError: ":BAD_ALERT:",
1095 },
1096 {
1097 protocol: dtls,
1098 testType: serverTest,
1099 name: "FragmentAlert-DTLS",
1100 config: Config{
1101 Bugs: ProtocolBugs{
1102 FragmentAlert: true,
1103 SendSpuriousAlert: alertRecordOverflow,
1104 },
1105 },
1106 shouldFail: true,
1107 expectedError: ":BAD_ALERT:",
1108 },
1109 {
1110 testType: serverTest,
1111 name: "EarlyChangeCipherSpec-server-1",
1112 config: Config{
1113 Bugs: ProtocolBugs{
1114 EarlyChangeCipherSpec: 1,
1115 },
1116 },
1117 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001118 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001119 },
1120 {
1121 testType: serverTest,
1122 name: "EarlyChangeCipherSpec-server-2",
1123 config: Config{
1124 Bugs: ProtocolBugs{
1125 EarlyChangeCipherSpec: 2,
1126 },
1127 },
1128 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001129 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001130 },
1131 {
1132 name: "SkipNewSessionTicket",
1133 config: Config{
1134 Bugs: ProtocolBugs{
1135 SkipNewSessionTicket: true,
1136 },
1137 },
1138 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001139 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001140 },
1141 {
1142 testType: serverTest,
1143 name: "FallbackSCSV",
1144 config: Config{
1145 MaxVersion: VersionTLS11,
1146 Bugs: ProtocolBugs{
1147 SendFallbackSCSV: true,
1148 },
1149 },
1150 shouldFail: true,
1151 expectedError: ":INAPPROPRIATE_FALLBACK:",
1152 },
1153 {
1154 testType: serverTest,
1155 name: "FallbackSCSV-VersionMatch",
1156 config: Config{
1157 Bugs: ProtocolBugs{
1158 SendFallbackSCSV: true,
1159 },
1160 },
1161 },
1162 {
1163 testType: serverTest,
1164 name: "FragmentedClientVersion",
1165 config: Config{
1166 Bugs: ProtocolBugs{
1167 MaxHandshakeRecordLength: 1,
1168 FragmentClientVersion: true,
1169 },
1170 },
1171 expectedVersion: VersionTLS12,
1172 },
1173 {
1174 testType: serverTest,
1175 name: "MinorVersionTolerance",
1176 config: Config{
1177 Bugs: ProtocolBugs{
1178 SendClientVersion: 0x03ff,
1179 },
1180 },
1181 expectedVersion: VersionTLS12,
1182 },
1183 {
1184 testType: serverTest,
1185 name: "MajorVersionTolerance",
1186 config: Config{
1187 Bugs: ProtocolBugs{
1188 SendClientVersion: 0x0400,
1189 },
1190 },
1191 expectedVersion: VersionTLS12,
1192 },
1193 {
1194 testType: serverTest,
1195 name: "VersionTooLow",
1196 config: Config{
1197 Bugs: ProtocolBugs{
1198 SendClientVersion: 0x0200,
1199 },
1200 },
1201 shouldFail: true,
1202 expectedError: ":UNSUPPORTED_PROTOCOL:",
1203 },
1204 {
1205 testType: serverTest,
1206 name: "HttpGET",
1207 sendPrefix: "GET / HTTP/1.0\n",
1208 shouldFail: true,
1209 expectedError: ":HTTP_REQUEST:",
1210 },
1211 {
1212 testType: serverTest,
1213 name: "HttpPOST",
1214 sendPrefix: "POST / HTTP/1.0\n",
1215 shouldFail: true,
1216 expectedError: ":HTTP_REQUEST:",
1217 },
1218 {
1219 testType: serverTest,
1220 name: "HttpHEAD",
1221 sendPrefix: "HEAD / HTTP/1.0\n",
1222 shouldFail: true,
1223 expectedError: ":HTTP_REQUEST:",
1224 },
1225 {
1226 testType: serverTest,
1227 name: "HttpPUT",
1228 sendPrefix: "PUT / HTTP/1.0\n",
1229 shouldFail: true,
1230 expectedError: ":HTTP_REQUEST:",
1231 },
1232 {
1233 testType: serverTest,
1234 name: "HttpCONNECT",
1235 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1236 shouldFail: true,
1237 expectedError: ":HTTPS_PROXY_REQUEST:",
1238 },
1239 {
1240 testType: serverTest,
1241 name: "Garbage",
1242 sendPrefix: "blah",
1243 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001244 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001245 },
1246 {
1247 name: "SkipCipherVersionCheck",
1248 config: Config{
1249 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1250 MaxVersion: VersionTLS11,
1251 Bugs: ProtocolBugs{
1252 SkipCipherVersionCheck: true,
1253 },
1254 },
1255 shouldFail: true,
1256 expectedError: ":WRONG_CIPHER_RETURNED:",
1257 },
1258 {
1259 name: "RSAEphemeralKey",
1260 config: Config{
1261 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1262 Bugs: ProtocolBugs{
1263 RSAEphemeralKey: true,
1264 },
1265 },
1266 shouldFail: true,
1267 expectedError: ":UNEXPECTED_MESSAGE:",
1268 },
1269 {
1270 name: "DisableEverything",
1271 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1272 shouldFail: true,
1273 expectedError: ":WRONG_SSL_VERSION:",
1274 },
1275 {
1276 protocol: dtls,
1277 name: "DisableEverything-DTLS",
1278 flags: []string{"-no-tls12", "-no-tls1"},
1279 shouldFail: true,
1280 expectedError: ":WRONG_SSL_VERSION:",
1281 },
1282 {
1283 name: "NoSharedCipher",
1284 config: Config{
1285 CipherSuites: []uint16{},
1286 },
1287 shouldFail: true,
1288 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1289 },
1290 {
1291 protocol: dtls,
1292 testType: serverTest,
1293 name: "MTU",
1294 config: Config{
1295 Bugs: ProtocolBugs{
1296 MaxPacketLength: 256,
1297 },
1298 },
1299 flags: []string{"-mtu", "256"},
1300 },
1301 {
1302 protocol: dtls,
1303 testType: serverTest,
1304 name: "MTUExceeded",
1305 config: Config{
1306 Bugs: ProtocolBugs{
1307 MaxPacketLength: 255,
1308 },
1309 },
1310 flags: []string{"-mtu", "256"},
1311 shouldFail: true,
1312 expectedLocalError: "dtls: exceeded maximum packet length",
1313 },
1314 {
1315 name: "CertMismatchRSA",
1316 config: Config{
1317 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1318 Certificates: []Certificate{getECDSACertificate()},
1319 Bugs: ProtocolBugs{
1320 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1321 },
1322 },
1323 shouldFail: true,
1324 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1325 },
1326 {
1327 name: "CertMismatchECDSA",
1328 config: Config{
1329 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1330 Certificates: []Certificate{getRSACertificate()},
1331 Bugs: ProtocolBugs{
1332 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1333 },
1334 },
1335 shouldFail: true,
1336 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1337 },
1338 {
1339 name: "EmptyCertificateList",
1340 config: Config{
1341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1342 Bugs: ProtocolBugs{
1343 EmptyCertificateList: true,
1344 },
1345 },
1346 shouldFail: true,
1347 expectedError: ":DECODE_ERROR:",
1348 },
1349 {
1350 name: "TLSFatalBadPackets",
1351 damageFirstWrite: true,
1352 shouldFail: true,
1353 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1354 },
1355 {
1356 protocol: dtls,
1357 name: "DTLSIgnoreBadPackets",
1358 damageFirstWrite: true,
1359 },
1360 {
1361 protocol: dtls,
1362 name: "DTLSIgnoreBadPackets-Async",
1363 damageFirstWrite: true,
1364 flags: []string{"-async"},
1365 },
1366 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001367 name: "AppDataBeforeHandshake",
1368 config: Config{
1369 Bugs: ProtocolBugs{
1370 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1371 },
1372 },
1373 shouldFail: true,
1374 expectedError: ":UNEXPECTED_RECORD:",
1375 },
1376 {
1377 name: "AppDataBeforeHandshake-Empty",
1378 config: Config{
1379 Bugs: ProtocolBugs{
1380 AppDataBeforeHandshake: []byte{},
1381 },
1382 },
1383 shouldFail: true,
1384 expectedError: ":UNEXPECTED_RECORD:",
1385 },
1386 {
1387 protocol: dtls,
1388 name: "AppDataBeforeHandshake-DTLS",
1389 config: Config{
1390 Bugs: ProtocolBugs{
1391 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1392 },
1393 },
1394 shouldFail: true,
1395 expectedError: ":UNEXPECTED_RECORD:",
1396 },
1397 {
1398 protocol: dtls,
1399 name: "AppDataBeforeHandshake-DTLS-Empty",
1400 config: Config{
1401 Bugs: ProtocolBugs{
1402 AppDataBeforeHandshake: []byte{},
1403 },
1404 },
1405 shouldFail: true,
1406 expectedError: ":UNEXPECTED_RECORD:",
1407 },
1408 {
Adam Langley7c803a62015-06-15 15:35:05 -07001409 name: "AppDataAfterChangeCipherSpec",
1410 config: Config{
1411 Bugs: ProtocolBugs{
1412 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1413 },
1414 },
1415 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001416 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001417 },
1418 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001419 name: "AppDataAfterChangeCipherSpec-Empty",
1420 config: Config{
1421 Bugs: ProtocolBugs{
1422 AppDataAfterChangeCipherSpec: []byte{},
1423 },
1424 },
1425 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001426 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001427 },
1428 {
Adam Langley7c803a62015-06-15 15:35:05 -07001429 protocol: dtls,
1430 name: "AppDataAfterChangeCipherSpec-DTLS",
1431 config: Config{
1432 Bugs: ProtocolBugs{
1433 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1434 },
1435 },
1436 // BoringSSL's DTLS implementation will drop the out-of-order
1437 // application data.
1438 },
1439 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001440 protocol: dtls,
1441 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1442 config: Config{
1443 Bugs: ProtocolBugs{
1444 AppDataAfterChangeCipherSpec: []byte{},
1445 },
1446 },
1447 // BoringSSL's DTLS implementation will drop the out-of-order
1448 // application data.
1449 },
1450 {
Adam Langley7c803a62015-06-15 15:35:05 -07001451 name: "AlertAfterChangeCipherSpec",
1452 config: Config{
1453 Bugs: ProtocolBugs{
1454 AlertAfterChangeCipherSpec: alertRecordOverflow,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1459 },
1460 {
1461 protocol: dtls,
1462 name: "AlertAfterChangeCipherSpec-DTLS",
1463 config: Config{
1464 Bugs: ProtocolBugs{
1465 AlertAfterChangeCipherSpec: alertRecordOverflow,
1466 },
1467 },
1468 shouldFail: true,
1469 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1470 },
1471 {
1472 protocol: dtls,
1473 name: "ReorderHandshakeFragments-Small-DTLS",
1474 config: Config{
1475 Bugs: ProtocolBugs{
1476 ReorderHandshakeFragments: true,
1477 // Small enough that every handshake message is
1478 // fragmented.
1479 MaxHandshakeRecordLength: 2,
1480 },
1481 },
1482 },
1483 {
1484 protocol: dtls,
1485 name: "ReorderHandshakeFragments-Large-DTLS",
1486 config: Config{
1487 Bugs: ProtocolBugs{
1488 ReorderHandshakeFragments: true,
1489 // Large enough that no handshake message is
1490 // fragmented.
1491 MaxHandshakeRecordLength: 2048,
1492 },
1493 },
1494 },
1495 {
1496 protocol: dtls,
1497 name: "MixCompleteMessageWithFragments-DTLS",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 ReorderHandshakeFragments: true,
1501 MixCompleteMessageWithFragments: true,
1502 MaxHandshakeRecordLength: 2,
1503 },
1504 },
1505 },
1506 {
1507 name: "SendInvalidRecordType",
1508 config: Config{
1509 Bugs: ProtocolBugs{
1510 SendInvalidRecordType: true,
1511 },
1512 },
1513 shouldFail: true,
1514 expectedError: ":UNEXPECTED_RECORD:",
1515 },
1516 {
1517 protocol: dtls,
1518 name: "SendInvalidRecordType-DTLS",
1519 config: Config{
1520 Bugs: ProtocolBugs{
1521 SendInvalidRecordType: true,
1522 },
1523 },
1524 shouldFail: true,
1525 expectedError: ":UNEXPECTED_RECORD:",
1526 },
1527 {
1528 name: "FalseStart-SkipServerSecondLeg",
1529 config: Config{
1530 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1531 NextProtos: []string{"foo"},
1532 Bugs: ProtocolBugs{
1533 SkipNewSessionTicket: true,
1534 SkipChangeCipherSpec: true,
1535 SkipFinished: true,
1536 ExpectFalseStart: true,
1537 },
1538 },
1539 flags: []string{
1540 "-false-start",
1541 "-handshake-never-done",
1542 "-advertise-alpn", "\x03foo",
1543 },
1544 shimWritesFirst: true,
1545 shouldFail: true,
1546 expectedError: ":UNEXPECTED_RECORD:",
1547 },
1548 {
1549 name: "FalseStart-SkipServerSecondLeg-Implicit",
1550 config: Config{
1551 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1552 NextProtos: []string{"foo"},
1553 Bugs: ProtocolBugs{
1554 SkipNewSessionTicket: true,
1555 SkipChangeCipherSpec: true,
1556 SkipFinished: true,
1557 },
1558 },
1559 flags: []string{
1560 "-implicit-handshake",
1561 "-false-start",
1562 "-handshake-never-done",
1563 "-advertise-alpn", "\x03foo",
1564 },
1565 shouldFail: true,
1566 expectedError: ":UNEXPECTED_RECORD:",
1567 },
1568 {
1569 testType: serverTest,
1570 name: "FailEarlyCallback",
1571 flags: []string{"-fail-early-callback"},
1572 shouldFail: true,
1573 expectedError: ":CONNECTION_REJECTED:",
1574 expectedLocalError: "remote error: access denied",
1575 },
1576 {
1577 name: "WrongMessageType",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 WrongCertificateMessageType: true,
1581 },
1582 },
1583 shouldFail: true,
1584 expectedError: ":UNEXPECTED_MESSAGE:",
1585 expectedLocalError: "remote error: unexpected message",
1586 },
1587 {
1588 protocol: dtls,
1589 name: "WrongMessageType-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 WrongCertificateMessageType: true,
1593 },
1594 },
1595 shouldFail: true,
1596 expectedError: ":UNEXPECTED_MESSAGE:",
1597 expectedLocalError: "remote error: unexpected message",
1598 },
1599 {
1600 protocol: dtls,
1601 name: "FragmentMessageTypeMismatch-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 MaxHandshakeRecordLength: 2,
1605 FragmentMessageTypeMismatch: true,
1606 },
1607 },
1608 shouldFail: true,
1609 expectedError: ":FRAGMENT_MISMATCH:",
1610 },
1611 {
1612 protocol: dtls,
1613 name: "FragmentMessageLengthMismatch-DTLS",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 MaxHandshakeRecordLength: 2,
1617 FragmentMessageLengthMismatch: true,
1618 },
1619 },
1620 shouldFail: true,
1621 expectedError: ":FRAGMENT_MISMATCH:",
1622 },
1623 {
1624 protocol: dtls,
1625 name: "SplitFragments-Header-DTLS",
1626 config: Config{
1627 Bugs: ProtocolBugs{
1628 SplitFragments: 2,
1629 },
1630 },
1631 shouldFail: true,
1632 expectedError: ":UNEXPECTED_MESSAGE:",
1633 },
1634 {
1635 protocol: dtls,
1636 name: "SplitFragments-Boundary-DTLS",
1637 config: Config{
1638 Bugs: ProtocolBugs{
1639 SplitFragments: dtlsRecordHeaderLen,
1640 },
1641 },
1642 shouldFail: true,
1643 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1644 },
1645 {
1646 protocol: dtls,
1647 name: "SplitFragments-Body-DTLS",
1648 config: Config{
1649 Bugs: ProtocolBugs{
1650 SplitFragments: dtlsRecordHeaderLen + 1,
1651 },
1652 },
1653 shouldFail: true,
1654 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1655 },
1656 {
1657 protocol: dtls,
1658 name: "SendEmptyFragments-DTLS",
1659 config: Config{
1660 Bugs: ProtocolBugs{
1661 SendEmptyFragments: true,
1662 },
1663 },
1664 },
1665 {
1666 name: "UnsupportedCipherSuite",
1667 config: Config{
1668 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1669 Bugs: ProtocolBugs{
1670 IgnorePeerCipherPreferences: true,
1671 },
1672 },
1673 flags: []string{"-cipher", "DEFAULT:!RC4"},
1674 shouldFail: true,
1675 expectedError: ":WRONG_CIPHER_RETURNED:",
1676 },
1677 {
1678 name: "UnsupportedCurve",
1679 config: Config{
1680 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1681 // BoringSSL implements P-224 but doesn't enable it by
1682 // default.
1683 CurvePreferences: []CurveID{CurveP224},
1684 Bugs: ProtocolBugs{
1685 IgnorePeerCurvePreferences: true,
1686 },
1687 },
1688 shouldFail: true,
1689 expectedError: ":WRONG_CURVE:",
1690 },
1691 {
1692 name: "BadFinished",
1693 config: Config{
1694 Bugs: ProtocolBugs{
1695 BadFinished: true,
1696 },
1697 },
1698 shouldFail: true,
1699 expectedError: ":DIGEST_CHECK_FAILED:",
1700 },
1701 {
1702 name: "FalseStart-BadFinished",
1703 config: Config{
1704 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1705 NextProtos: []string{"foo"},
1706 Bugs: ProtocolBugs{
1707 BadFinished: true,
1708 ExpectFalseStart: true,
1709 },
1710 },
1711 flags: []string{
1712 "-false-start",
1713 "-handshake-never-done",
1714 "-advertise-alpn", "\x03foo",
1715 },
1716 shimWritesFirst: true,
1717 shouldFail: true,
1718 expectedError: ":DIGEST_CHECK_FAILED:",
1719 },
1720 {
1721 name: "NoFalseStart-NoALPN",
1722 config: Config{
1723 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1724 Bugs: ProtocolBugs{
1725 ExpectFalseStart: true,
1726 AlertBeforeFalseStartTest: alertAccessDenied,
1727 },
1728 },
1729 flags: []string{
1730 "-false-start",
1731 },
1732 shimWritesFirst: true,
1733 shouldFail: true,
1734 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1735 expectedLocalError: "tls: peer did not false start: EOF",
1736 },
1737 {
1738 name: "NoFalseStart-NoAEAD",
1739 config: Config{
1740 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1741 NextProtos: []string{"foo"},
1742 Bugs: ProtocolBugs{
1743 ExpectFalseStart: true,
1744 AlertBeforeFalseStartTest: alertAccessDenied,
1745 },
1746 },
1747 flags: []string{
1748 "-false-start",
1749 "-advertise-alpn", "\x03foo",
1750 },
1751 shimWritesFirst: true,
1752 shouldFail: true,
1753 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1754 expectedLocalError: "tls: peer did not false start: EOF",
1755 },
1756 {
1757 name: "NoFalseStart-RSA",
1758 config: Config{
1759 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1760 NextProtos: []string{"foo"},
1761 Bugs: ProtocolBugs{
1762 ExpectFalseStart: true,
1763 AlertBeforeFalseStartTest: alertAccessDenied,
1764 },
1765 },
1766 flags: []string{
1767 "-false-start",
1768 "-advertise-alpn", "\x03foo",
1769 },
1770 shimWritesFirst: true,
1771 shouldFail: true,
1772 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1773 expectedLocalError: "tls: peer did not false start: EOF",
1774 },
1775 {
1776 name: "NoFalseStart-DHE_RSA",
1777 config: Config{
1778 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1779 NextProtos: []string{"foo"},
1780 Bugs: ProtocolBugs{
1781 ExpectFalseStart: true,
1782 AlertBeforeFalseStartTest: alertAccessDenied,
1783 },
1784 },
1785 flags: []string{
1786 "-false-start",
1787 "-advertise-alpn", "\x03foo",
1788 },
1789 shimWritesFirst: true,
1790 shouldFail: true,
1791 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1792 expectedLocalError: "tls: peer did not false start: EOF",
1793 },
1794 {
1795 testType: serverTest,
1796 name: "NoSupportedCurves",
1797 config: Config{
1798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1799 Bugs: ProtocolBugs{
1800 NoSupportedCurves: true,
1801 },
1802 },
1803 },
1804 {
1805 testType: serverTest,
1806 name: "NoCommonCurves",
1807 config: Config{
1808 CipherSuites: []uint16{
1809 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1810 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1811 },
1812 CurvePreferences: []CurveID{CurveP224},
1813 },
1814 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1815 },
1816 {
1817 protocol: dtls,
1818 name: "SendSplitAlert-Sync",
1819 config: Config{
1820 Bugs: ProtocolBugs{
1821 SendSplitAlert: true,
1822 },
1823 },
1824 },
1825 {
1826 protocol: dtls,
1827 name: "SendSplitAlert-Async",
1828 config: Config{
1829 Bugs: ProtocolBugs{
1830 SendSplitAlert: true,
1831 },
1832 },
1833 flags: []string{"-async"},
1834 },
1835 {
1836 protocol: dtls,
1837 name: "PackDTLSHandshake",
1838 config: Config{
1839 Bugs: ProtocolBugs{
1840 MaxHandshakeRecordLength: 2,
1841 PackHandshakeFragments: 20,
1842 PackHandshakeRecords: 200,
1843 },
1844 },
1845 },
1846 {
1847 testType: serverTest,
1848 protocol: dtls,
1849 name: "NoRC4-DTLS",
1850 config: Config{
1851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1852 Bugs: ProtocolBugs{
1853 EnableAllCiphersInDTLS: true,
1854 },
1855 },
1856 shouldFail: true,
1857 expectedError: ":NO_SHARED_CIPHER:",
1858 },
1859 {
1860 name: "SendEmptyRecords-Pass",
1861 sendEmptyRecords: 32,
1862 },
1863 {
1864 name: "SendEmptyRecords",
1865 sendEmptyRecords: 33,
1866 shouldFail: true,
1867 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1868 },
1869 {
1870 name: "SendEmptyRecords-Async",
1871 sendEmptyRecords: 33,
1872 flags: []string{"-async"},
1873 shouldFail: true,
1874 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1875 },
1876 {
1877 name: "SendWarningAlerts-Pass",
1878 sendWarningAlerts: 4,
1879 },
1880 {
1881 protocol: dtls,
1882 name: "SendWarningAlerts-DTLS-Pass",
1883 sendWarningAlerts: 4,
1884 },
1885 {
1886 name: "SendWarningAlerts",
1887 sendWarningAlerts: 5,
1888 shouldFail: true,
1889 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1890 },
1891 {
1892 name: "SendWarningAlerts-Async",
1893 sendWarningAlerts: 5,
1894 flags: []string{"-async"},
1895 shouldFail: true,
1896 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1897 },
David Benjaminba4594a2015-06-18 18:36:15 -04001898 {
1899 name: "EmptySessionID",
1900 config: Config{
1901 SessionTicketsDisabled: true,
1902 },
1903 noSessionCache: true,
1904 flags: []string{"-expect-no-session"},
1905 },
David Benjamin30789da2015-08-29 22:56:45 -04001906 {
1907 name: "Unclean-Shutdown",
1908 config: Config{
1909 Bugs: ProtocolBugs{
1910 NoCloseNotify: true,
1911 ExpectCloseNotify: true,
1912 },
1913 },
1914 shimShutsDown: true,
1915 flags: []string{"-check-close-notify"},
1916 shouldFail: true,
1917 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1918 },
1919 {
1920 name: "Unclean-Shutdown-Ignored",
1921 config: Config{
1922 Bugs: ProtocolBugs{
1923 NoCloseNotify: true,
1924 },
1925 },
1926 shimShutsDown: true,
1927 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001928 {
1929 name: "LargePlaintext",
1930 config: Config{
1931 Bugs: ProtocolBugs{
1932 SendLargeRecords: true,
1933 },
1934 },
1935 messageLen: maxPlaintext + 1,
1936 shouldFail: true,
1937 expectedError: ":DATA_LENGTH_TOO_LONG:",
1938 },
1939 {
1940 protocol: dtls,
1941 name: "LargePlaintext-DTLS",
1942 config: Config{
1943 Bugs: ProtocolBugs{
1944 SendLargeRecords: true,
1945 },
1946 },
1947 messageLen: maxPlaintext + 1,
1948 shouldFail: true,
1949 expectedError: ":DATA_LENGTH_TOO_LONG:",
1950 },
1951 {
1952 name: "LargeCiphertext",
1953 config: Config{
1954 Bugs: ProtocolBugs{
1955 SendLargeRecords: true,
1956 },
1957 },
1958 messageLen: maxPlaintext * 2,
1959 shouldFail: true,
1960 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1961 },
1962 {
1963 protocol: dtls,
1964 name: "LargeCiphertext-DTLS",
1965 config: Config{
1966 Bugs: ProtocolBugs{
1967 SendLargeRecords: true,
1968 },
1969 },
1970 messageLen: maxPlaintext * 2,
1971 // Unlike the other four cases, DTLS drops records which
1972 // are invalid before authentication, so the connection
1973 // does not fail.
1974 expectMessageDropped: true,
1975 },
David Benjamindd6fed92015-10-23 17:41:12 -04001976 {
1977 name: "SendEmptySessionTicket",
1978 config: Config{
1979 Bugs: ProtocolBugs{
1980 SendEmptySessionTicket: true,
1981 FailIfSessionOffered: true,
1982 },
1983 },
1984 flags: []string{"-expect-no-session"},
1985 resumeSession: true,
1986 expectResumeRejected: true,
1987 },
David Benjamin99fdfb92015-11-02 12:11:35 -05001988 {
1989 name: "CheckLeafCurve",
1990 config: Config{
1991 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1992 Certificates: []Certificate{getECDSACertificate()},
1993 },
1994 flags: []string{"-p384-only"},
1995 shouldFail: true,
1996 expectedError: ":BAD_ECC_CERT:",
1997 },
David Benjamin8411b242015-11-26 12:07:28 -05001998 {
1999 name: "BadChangeCipherSpec-1",
2000 config: Config{
2001 Bugs: ProtocolBugs{
2002 BadChangeCipherSpec: []byte{2},
2003 },
2004 },
2005 shouldFail: true,
2006 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2007 },
2008 {
2009 name: "BadChangeCipherSpec-2",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 BadChangeCipherSpec: []byte{1, 1},
2013 },
2014 },
2015 shouldFail: true,
2016 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2017 },
2018 {
2019 protocol: dtls,
2020 name: "BadChangeCipherSpec-DTLS-1",
2021 config: Config{
2022 Bugs: ProtocolBugs{
2023 BadChangeCipherSpec: []byte{2},
2024 },
2025 },
2026 shouldFail: true,
2027 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2028 },
2029 {
2030 protocol: dtls,
2031 name: "BadChangeCipherSpec-DTLS-2",
2032 config: Config{
2033 Bugs: ProtocolBugs{
2034 BadChangeCipherSpec: []byte{1, 1},
2035 },
2036 },
2037 shouldFail: true,
2038 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2039 },
David Benjaminef5dfd22015-12-06 13:17:07 -05002040 {
2041 name: "BadHelloRequest-1",
2042 renegotiate: 1,
2043 config: Config{
2044 Bugs: ProtocolBugs{
2045 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2046 },
2047 },
2048 flags: []string{
2049 "-renegotiate-freely",
2050 "-expect-total-renegotiations", "1",
2051 },
2052 shouldFail: true,
2053 expectedError: ":BAD_HELLO_REQUEST:",
2054 },
2055 {
2056 name: "BadHelloRequest-2",
2057 renegotiate: 1,
2058 config: Config{
2059 Bugs: ProtocolBugs{
2060 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2061 },
2062 },
2063 flags: []string{
2064 "-renegotiate-freely",
2065 "-expect-total-renegotiations", "1",
2066 },
2067 shouldFail: true,
2068 expectedError: ":BAD_HELLO_REQUEST:",
2069 },
Adam Langley7c803a62015-06-15 15:35:05 -07002070 }
Adam Langley7c803a62015-06-15 15:35:05 -07002071 testCases = append(testCases, basicTests...)
2072}
2073
Adam Langley95c29f32014-06-20 12:00:00 -07002074func addCipherSuiteTests() {
2075 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002076 const psk = "12345"
2077 const pskIdentity = "luggage combo"
2078
Adam Langley95c29f32014-06-20 12:00:00 -07002079 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002080 var certFile string
2081 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002082 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002083 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002084 certFile = ecdsaCertificateFile
2085 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002086 } else {
2087 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002088 certFile = rsaCertificateFile
2089 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002090 }
2091
David Benjamin48cae082014-10-27 01:06:24 -04002092 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002093 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002094 flags = append(flags,
2095 "-psk", psk,
2096 "-psk-identity", pskIdentity)
2097 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002098 if hasComponent(suite.name, "NULL") {
2099 // NULL ciphers must be explicitly enabled.
2100 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2101 }
David Benjamin48cae082014-10-27 01:06:24 -04002102
Adam Langley95c29f32014-06-20 12:00:00 -07002103 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002104 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002105 continue
2106 }
2107
David Benjamin025b3d32014-07-01 19:53:04 -04002108 testCases = append(testCases, testCase{
2109 testType: clientTest,
2110 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002111 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002112 MinVersion: ver.version,
2113 MaxVersion: ver.version,
2114 CipherSuites: []uint16{suite.id},
2115 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002116 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002117 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002118 },
David Benjamin48cae082014-10-27 01:06:24 -04002119 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002120 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002121 })
David Benjamin025b3d32014-07-01 19:53:04 -04002122
David Benjamin76d8abe2014-08-14 16:25:34 -04002123 testCases = append(testCases, testCase{
2124 testType: serverTest,
2125 name: ver.name + "-" + suite.name + "-server",
2126 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002127 MinVersion: ver.version,
2128 MaxVersion: ver.version,
2129 CipherSuites: []uint16{suite.id},
2130 Certificates: []Certificate{cert},
2131 PreSharedKey: []byte(psk),
2132 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002133 },
2134 certFile: certFile,
2135 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002136 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002137 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002138 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002139
David Benjamin8b8c0062014-11-23 02:47:52 -05002140 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002141 testCases = append(testCases, testCase{
2142 testType: clientTest,
2143 protocol: dtls,
2144 name: "D" + ver.name + "-" + suite.name + "-client",
2145 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002146 MinVersion: ver.version,
2147 MaxVersion: ver.version,
2148 CipherSuites: []uint16{suite.id},
2149 Certificates: []Certificate{cert},
2150 PreSharedKey: []byte(psk),
2151 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002152 },
David Benjamin48cae082014-10-27 01:06:24 -04002153 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002154 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002155 })
2156 testCases = append(testCases, testCase{
2157 testType: serverTest,
2158 protocol: dtls,
2159 name: "D" + ver.name + "-" + suite.name + "-server",
2160 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002161 MinVersion: ver.version,
2162 MaxVersion: ver.version,
2163 CipherSuites: []uint16{suite.id},
2164 Certificates: []Certificate{cert},
2165 PreSharedKey: []byte(psk),
2166 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002167 },
2168 certFile: certFile,
2169 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002170 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002171 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002172 })
2173 }
Adam Langley95c29f32014-06-20 12:00:00 -07002174 }
David Benjamin2c99d282015-09-01 10:23:00 -04002175
2176 // Ensure both TLS and DTLS accept their maximum record sizes.
2177 testCases = append(testCases, testCase{
2178 name: suite.name + "-LargeRecord",
2179 config: Config{
2180 CipherSuites: []uint16{suite.id},
2181 Certificates: []Certificate{cert},
2182 PreSharedKey: []byte(psk),
2183 PreSharedKeyIdentity: pskIdentity,
2184 },
2185 flags: flags,
2186 messageLen: maxPlaintext,
2187 })
David Benjamin2c99d282015-09-01 10:23:00 -04002188 if isDTLSCipher(suite.name) {
2189 testCases = append(testCases, testCase{
2190 protocol: dtls,
2191 name: suite.name + "-LargeRecord-DTLS",
2192 config: Config{
2193 CipherSuites: []uint16{suite.id},
2194 Certificates: []Certificate{cert},
2195 PreSharedKey: []byte(psk),
2196 PreSharedKeyIdentity: pskIdentity,
2197 },
2198 flags: flags,
2199 messageLen: maxPlaintext,
2200 })
2201 }
Adam Langley95c29f32014-06-20 12:00:00 -07002202 }
Adam Langleya7997f12015-05-14 17:38:50 -07002203
2204 testCases = append(testCases, testCase{
2205 name: "WeakDH",
2206 config: Config{
2207 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2208 Bugs: ProtocolBugs{
2209 // This is a 1023-bit prime number, generated
2210 // with:
2211 // openssl gendh 1023 | openssl asn1parse -i
2212 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2213 },
2214 },
2215 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002216 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002217 })
Adam Langleycef75832015-09-03 14:51:12 -07002218
David Benjamincd24a392015-11-11 13:23:05 -08002219 testCases = append(testCases, testCase{
2220 name: "SillyDH",
2221 config: Config{
2222 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2223 Bugs: ProtocolBugs{
2224 // This is a 4097-bit prime number, generated
2225 // with:
2226 // openssl gendh 4097 | openssl asn1parse -i
2227 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2228 },
2229 },
2230 shouldFail: true,
2231 expectedError: ":DH_P_TOO_LONG:",
2232 })
2233
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002234 // This test ensures that Diffie-Hellman public values are padded with
2235 // zeros so that they're the same length as the prime. This is to avoid
2236 // hitting a bug in yaSSL.
2237 testCases = append(testCases, testCase{
2238 testType: serverTest,
2239 name: "DHPublicValuePadded",
2240 config: Config{
2241 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2242 Bugs: ProtocolBugs{
2243 RequireDHPublicValueLen: (1025 + 7) / 8,
2244 },
2245 },
2246 flags: []string{"-use-sparse-dh-prime"},
2247 })
David Benjamincd24a392015-11-11 13:23:05 -08002248
Adam Langleycef75832015-09-03 14:51:12 -07002249 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2250 // 1.1 specific cipher suite settings. A server is setup with the given
2251 // cipher lists and then a connection is made for each member of
2252 // expectations. The cipher suite that the server selects must match
2253 // the specified one.
2254 var versionSpecificCiphersTest = []struct {
2255 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2256 // expectations is a map from TLS version to cipher suite id.
2257 expectations map[uint16]uint16
2258 }{
2259 {
2260 // Test that the null case (where no version-specific ciphers are set)
2261 // works as expected.
2262 "RC4-SHA:AES128-SHA", // default ciphers
2263 "", // no ciphers specifically for TLS ≥ 1.0
2264 "", // no ciphers specifically for TLS ≥ 1.1
2265 map[uint16]uint16{
2266 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2267 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2268 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2269 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2270 },
2271 },
2272 {
2273 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2274 // cipher.
2275 "RC4-SHA:AES128-SHA", // default
2276 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2277 "", // no ciphers specifically for TLS ≥ 1.1
2278 map[uint16]uint16{
2279 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2280 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2281 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2282 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2283 },
2284 },
2285 {
2286 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2287 // cipher.
2288 "RC4-SHA:AES128-SHA", // default
2289 "", // no ciphers specifically for TLS ≥ 1.0
2290 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2291 map[uint16]uint16{
2292 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2293 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2294 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2295 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2296 },
2297 },
2298 {
2299 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2300 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2301 "RC4-SHA:AES128-SHA", // default
2302 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2303 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2304 map[uint16]uint16{
2305 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2306 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2307 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2308 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2309 },
2310 },
2311 }
2312
2313 for i, test := range versionSpecificCiphersTest {
2314 for version, expectedCipherSuite := range test.expectations {
2315 flags := []string{"-cipher", test.ciphersDefault}
2316 if len(test.ciphersTLS10) > 0 {
2317 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2318 }
2319 if len(test.ciphersTLS11) > 0 {
2320 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2321 }
2322
2323 testCases = append(testCases, testCase{
2324 testType: serverTest,
2325 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2326 config: Config{
2327 MaxVersion: version,
2328 MinVersion: version,
2329 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2330 },
2331 flags: flags,
2332 expectedCipher: expectedCipherSuite,
2333 })
2334 }
2335 }
Adam Langley95c29f32014-06-20 12:00:00 -07002336}
2337
2338func addBadECDSASignatureTests() {
2339 for badR := BadValue(1); badR < NumBadValues; badR++ {
2340 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002341 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002342 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2343 config: Config{
2344 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2345 Certificates: []Certificate{getECDSACertificate()},
2346 Bugs: ProtocolBugs{
2347 BadECDSAR: badR,
2348 BadECDSAS: badS,
2349 },
2350 },
2351 shouldFail: true,
2352 expectedError: "SIGNATURE",
2353 })
2354 }
2355 }
2356}
2357
Adam Langley80842bd2014-06-20 12:00:00 -07002358func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002359 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002360 name: "MaxCBCPadding",
2361 config: Config{
2362 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2363 Bugs: ProtocolBugs{
2364 MaxPadding: true,
2365 },
2366 },
2367 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2368 })
David Benjamin025b3d32014-07-01 19:53:04 -04002369 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002370 name: "BadCBCPadding",
2371 config: Config{
2372 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2373 Bugs: ProtocolBugs{
2374 PaddingFirstByteBad: true,
2375 },
2376 },
2377 shouldFail: true,
2378 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2379 })
2380 // OpenSSL previously had an issue where the first byte of padding in
2381 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002382 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002383 name: "BadCBCPadding255",
2384 config: Config{
2385 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2386 Bugs: ProtocolBugs{
2387 MaxPadding: true,
2388 PaddingFirstByteBadIf255: true,
2389 },
2390 },
2391 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2392 shouldFail: true,
2393 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2394 })
2395}
2396
Kenny Root7fdeaf12014-08-05 15:23:37 -07002397func addCBCSplittingTests() {
2398 testCases = append(testCases, testCase{
2399 name: "CBCRecordSplitting",
2400 config: Config{
2401 MaxVersion: VersionTLS10,
2402 MinVersion: VersionTLS10,
2403 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2404 },
David Benjaminac8302a2015-09-01 17:18:15 -04002405 messageLen: -1, // read until EOF
2406 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002407 flags: []string{
2408 "-async",
2409 "-write-different-record-sizes",
2410 "-cbc-record-splitting",
2411 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002412 })
2413 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002414 name: "CBCRecordSplittingPartialWrite",
2415 config: Config{
2416 MaxVersion: VersionTLS10,
2417 MinVersion: VersionTLS10,
2418 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2419 },
2420 messageLen: -1, // read until EOF
2421 flags: []string{
2422 "-async",
2423 "-write-different-record-sizes",
2424 "-cbc-record-splitting",
2425 "-partial-write",
2426 },
2427 })
2428}
2429
David Benjamin636293b2014-07-08 17:59:18 -04002430func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002431 // Add a dummy cert pool to stress certificate authority parsing.
2432 // TODO(davidben): Add tests that those values parse out correctly.
2433 certPool := x509.NewCertPool()
2434 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2435 if err != nil {
2436 panic(err)
2437 }
2438 certPool.AddCert(cert)
2439
David Benjamin636293b2014-07-08 17:59:18 -04002440 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002441 testCases = append(testCases, testCase{
2442 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002443 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002444 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002445 MinVersion: ver.version,
2446 MaxVersion: ver.version,
2447 ClientAuth: RequireAnyClientCert,
2448 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002449 },
2450 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002451 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2452 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002453 },
2454 })
2455 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002456 testType: serverTest,
2457 name: ver.name + "-Server-ClientAuth-RSA",
2458 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002459 MinVersion: ver.version,
2460 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002461 Certificates: []Certificate{rsaCertificate},
2462 },
2463 flags: []string{"-require-any-client-certificate"},
2464 })
David Benjamine098ec22014-08-27 23:13:20 -04002465 if ver.version != VersionSSL30 {
2466 testCases = append(testCases, testCase{
2467 testType: serverTest,
2468 name: ver.name + "-Server-ClientAuth-ECDSA",
2469 config: Config{
2470 MinVersion: ver.version,
2471 MaxVersion: ver.version,
2472 Certificates: []Certificate{ecdsaCertificate},
2473 },
2474 flags: []string{"-require-any-client-certificate"},
2475 })
2476 testCases = append(testCases, testCase{
2477 testType: clientTest,
2478 name: ver.name + "-Client-ClientAuth-ECDSA",
2479 config: Config{
2480 MinVersion: ver.version,
2481 MaxVersion: ver.version,
2482 ClientAuth: RequireAnyClientCert,
2483 ClientCAs: certPool,
2484 },
2485 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002486 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2487 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002488 },
2489 })
2490 }
David Benjamin636293b2014-07-08 17:59:18 -04002491 }
2492}
2493
Adam Langley75712922014-10-10 16:23:43 -07002494func addExtendedMasterSecretTests() {
2495 const expectEMSFlag = "-expect-extended-master-secret"
2496
2497 for _, with := range []bool{false, true} {
2498 prefix := "No"
2499 var flags []string
2500 if with {
2501 prefix = ""
2502 flags = []string{expectEMSFlag}
2503 }
2504
2505 for _, isClient := range []bool{false, true} {
2506 suffix := "-Server"
2507 testType := serverTest
2508 if isClient {
2509 suffix = "-Client"
2510 testType = clientTest
2511 }
2512
2513 for _, ver := range tlsVersions {
2514 test := testCase{
2515 testType: testType,
2516 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2517 config: Config{
2518 MinVersion: ver.version,
2519 MaxVersion: ver.version,
2520 Bugs: ProtocolBugs{
2521 NoExtendedMasterSecret: !with,
2522 RequireExtendedMasterSecret: with,
2523 },
2524 },
David Benjamin48cae082014-10-27 01:06:24 -04002525 flags: flags,
2526 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002527 }
2528 if test.shouldFail {
2529 test.expectedLocalError = "extended master secret required but not supported by peer"
2530 }
2531 testCases = append(testCases, test)
2532 }
2533 }
2534 }
2535
Adam Langleyba5934b2015-06-02 10:50:35 -07002536 for _, isClient := range []bool{false, true} {
2537 for _, supportedInFirstConnection := range []bool{false, true} {
2538 for _, supportedInResumeConnection := range []bool{false, true} {
2539 boolToWord := func(b bool) string {
2540 if b {
2541 return "Yes"
2542 }
2543 return "No"
2544 }
2545 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2546 if isClient {
2547 suffix += "Client"
2548 } else {
2549 suffix += "Server"
2550 }
2551
2552 supportedConfig := Config{
2553 Bugs: ProtocolBugs{
2554 RequireExtendedMasterSecret: true,
2555 },
2556 }
2557
2558 noSupportConfig := Config{
2559 Bugs: ProtocolBugs{
2560 NoExtendedMasterSecret: true,
2561 },
2562 }
2563
2564 test := testCase{
2565 name: "ExtendedMasterSecret-" + suffix,
2566 resumeSession: true,
2567 }
2568
2569 if !isClient {
2570 test.testType = serverTest
2571 }
2572
2573 if supportedInFirstConnection {
2574 test.config = supportedConfig
2575 } else {
2576 test.config = noSupportConfig
2577 }
2578
2579 if supportedInResumeConnection {
2580 test.resumeConfig = &supportedConfig
2581 } else {
2582 test.resumeConfig = &noSupportConfig
2583 }
2584
2585 switch suffix {
2586 case "YesToYes-Client", "YesToYes-Server":
2587 // When a session is resumed, it should
2588 // still be aware that its master
2589 // secret was generated via EMS and
2590 // thus it's safe to use tls-unique.
2591 test.flags = []string{expectEMSFlag}
2592 case "NoToYes-Server":
2593 // If an original connection did not
2594 // contain EMS, but a resumption
2595 // handshake does, then a server should
2596 // not resume the session.
2597 test.expectResumeRejected = true
2598 case "YesToNo-Server":
2599 // Resuming an EMS session without the
2600 // EMS extension should cause the
2601 // server to abort the connection.
2602 test.shouldFail = true
2603 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2604 case "NoToYes-Client":
2605 // A client should abort a connection
2606 // where the server resumed a non-EMS
2607 // session but echoed the EMS
2608 // extension.
2609 test.shouldFail = true
2610 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2611 case "YesToNo-Client":
2612 // A client should abort a connection
2613 // where the server didn't echo EMS
2614 // when the session used it.
2615 test.shouldFail = true
2616 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2617 }
2618
2619 testCases = append(testCases, test)
2620 }
2621 }
2622 }
Adam Langley75712922014-10-10 16:23:43 -07002623}
2624
David Benjamin43ec06f2014-08-05 02:28:57 -04002625// Adds tests that try to cover the range of the handshake state machine, under
2626// various conditions. Some of these are redundant with other tests, but they
2627// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002628func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002629 var tests []testCase
2630
2631 // Basic handshake, with resumption. Client and server,
2632 // session ID and session ticket.
2633 tests = append(tests, testCase{
2634 name: "Basic-Client",
2635 resumeSession: true,
2636 })
2637 tests = append(tests, testCase{
2638 name: "Basic-Client-RenewTicket",
2639 config: Config{
2640 Bugs: ProtocolBugs{
2641 RenewTicketOnResume: true,
2642 },
2643 },
David Benjaminba4594a2015-06-18 18:36:15 -04002644 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002645 resumeSession: true,
2646 })
2647 tests = append(tests, testCase{
2648 name: "Basic-Client-NoTicket",
2649 config: Config{
2650 SessionTicketsDisabled: true,
2651 },
2652 resumeSession: true,
2653 })
2654 tests = append(tests, testCase{
2655 name: "Basic-Client-Implicit",
2656 flags: []string{"-implicit-handshake"},
2657 resumeSession: true,
2658 })
2659 tests = append(tests, testCase{
2660 testType: serverTest,
2661 name: "Basic-Server",
2662 resumeSession: true,
2663 })
2664 tests = append(tests, testCase{
2665 testType: serverTest,
2666 name: "Basic-Server-NoTickets",
2667 config: Config{
2668 SessionTicketsDisabled: true,
2669 },
2670 resumeSession: true,
2671 })
2672 tests = append(tests, testCase{
2673 testType: serverTest,
2674 name: "Basic-Server-Implicit",
2675 flags: []string{"-implicit-handshake"},
2676 resumeSession: true,
2677 })
2678 tests = append(tests, testCase{
2679 testType: serverTest,
2680 name: "Basic-Server-EarlyCallback",
2681 flags: []string{"-use-early-callback"},
2682 resumeSession: true,
2683 })
2684
2685 // TLS client auth.
2686 tests = append(tests, testCase{
2687 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002688 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002689 config: Config{
2690 ClientAuth: RequireAnyClientCert,
2691 },
2692 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002695 },
2696 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002697 tests = append(tests, testCase{
2698 testType: clientTest,
2699 name: "ClientAuth-ECDSA-Client",
2700 config: Config{
2701 ClientAuth: RequireAnyClientCert,
2702 },
2703 flags: []string{
2704 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2705 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2706 },
2707 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002708 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002709 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002710 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002711 testType: serverTest,
2712 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002713 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002714 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002715 },
2716 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002717 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2718 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002719 },
2720 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002721 tests = append(tests, testCase{
2722 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002723 name: "Basic-Server-ECDHE-RSA",
2724 config: Config{
2725 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2726 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002727 flags: []string{
2728 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2729 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002730 },
2731 })
2732 tests = append(tests, testCase{
2733 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002734 name: "Basic-Server-ECDHE-ECDSA",
2735 config: Config{
2736 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2737 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002738 flags: []string{
2739 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2740 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002741 },
2742 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002743 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002744 tests = append(tests, testCase{
2745 testType: serverTest,
2746 name: "ClientAuth-Server",
2747 config: Config{
2748 Certificates: []Certificate{rsaCertificate},
2749 },
2750 flags: []string{"-require-any-client-certificate"},
2751 })
2752
2753 // No session ticket support; server doesn't send NewSessionTicket.
2754 tests = append(tests, testCase{
2755 name: "SessionTicketsDisabled-Client",
2756 config: Config{
2757 SessionTicketsDisabled: true,
2758 },
2759 })
2760 tests = append(tests, testCase{
2761 testType: serverTest,
2762 name: "SessionTicketsDisabled-Server",
2763 config: Config{
2764 SessionTicketsDisabled: true,
2765 },
2766 })
2767
2768 // Skip ServerKeyExchange in PSK key exchange if there's no
2769 // identity hint.
2770 tests = append(tests, testCase{
2771 name: "EmptyPSKHint-Client",
2772 config: Config{
2773 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2774 PreSharedKey: []byte("secret"),
2775 },
2776 flags: []string{"-psk", "secret"},
2777 })
2778 tests = append(tests, testCase{
2779 testType: serverTest,
2780 name: "EmptyPSKHint-Server",
2781 config: Config{
2782 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2783 PreSharedKey: []byte("secret"),
2784 },
2785 flags: []string{"-psk", "secret"},
2786 })
2787
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002788 tests = append(tests, testCase{
2789 testType: clientTest,
2790 name: "OCSPStapling-Client",
2791 flags: []string{
2792 "-enable-ocsp-stapling",
2793 "-expect-ocsp-response",
2794 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002795 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002796 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002797 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002798 })
2799
2800 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002801 testType: serverTest,
2802 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002803 expectedOCSPResponse: testOCSPResponse,
2804 flags: []string{
2805 "-ocsp-response",
2806 base64.StdEncoding.EncodeToString(testOCSPResponse),
2807 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002808 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002809 })
2810
Paul Lietar8f1c2682015-08-18 12:21:54 +01002811 tests = append(tests, testCase{
2812 testType: clientTest,
2813 name: "CertificateVerificationSucceed",
2814 flags: []string{
2815 "-verify-peer",
2816 },
2817 })
2818
2819 tests = append(tests, testCase{
2820 testType: clientTest,
2821 name: "CertificateVerificationFail",
2822 flags: []string{
2823 "-verify-fail",
2824 "-verify-peer",
2825 },
2826 shouldFail: true,
2827 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2828 })
2829
2830 tests = append(tests, testCase{
2831 testType: clientTest,
2832 name: "CertificateVerificationSoftFail",
2833 flags: []string{
2834 "-verify-fail",
2835 "-expect-verify-result",
2836 },
2837 })
2838
David Benjamin760b1dd2015-05-15 23:33:48 -04002839 if protocol == tls {
2840 tests = append(tests, testCase{
2841 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002842 renegotiate: 1,
2843 flags: []string{
2844 "-renegotiate-freely",
2845 "-expect-total-renegotiations", "1",
2846 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002847 })
2848 // NPN on client and server; results in post-handshake message.
2849 tests = append(tests, testCase{
2850 name: "NPN-Client",
2851 config: Config{
2852 NextProtos: []string{"foo"},
2853 },
2854 flags: []string{"-select-next-proto", "foo"},
2855 expectedNextProto: "foo",
2856 expectedNextProtoType: npn,
2857 })
2858 tests = append(tests, testCase{
2859 testType: serverTest,
2860 name: "NPN-Server",
2861 config: Config{
2862 NextProtos: []string{"bar"},
2863 },
2864 flags: []string{
2865 "-advertise-npn", "\x03foo\x03bar\x03baz",
2866 "-expect-next-proto", "bar",
2867 },
2868 expectedNextProto: "bar",
2869 expectedNextProtoType: npn,
2870 })
2871
2872 // TODO(davidben): Add tests for when False Start doesn't trigger.
2873
2874 // Client does False Start and negotiates NPN.
2875 tests = append(tests, testCase{
2876 name: "FalseStart",
2877 config: Config{
2878 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2879 NextProtos: []string{"foo"},
2880 Bugs: ProtocolBugs{
2881 ExpectFalseStart: true,
2882 },
2883 },
2884 flags: []string{
2885 "-false-start",
2886 "-select-next-proto", "foo",
2887 },
2888 shimWritesFirst: true,
2889 resumeSession: true,
2890 })
2891
2892 // Client does False Start and negotiates ALPN.
2893 tests = append(tests, testCase{
2894 name: "FalseStart-ALPN",
2895 config: Config{
2896 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2897 NextProtos: []string{"foo"},
2898 Bugs: ProtocolBugs{
2899 ExpectFalseStart: true,
2900 },
2901 },
2902 flags: []string{
2903 "-false-start",
2904 "-advertise-alpn", "\x03foo",
2905 },
2906 shimWritesFirst: true,
2907 resumeSession: true,
2908 })
2909
2910 // Client does False Start but doesn't explicitly call
2911 // SSL_connect.
2912 tests = append(tests, testCase{
2913 name: "FalseStart-Implicit",
2914 config: Config{
2915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2916 NextProtos: []string{"foo"},
2917 },
2918 flags: []string{
2919 "-implicit-handshake",
2920 "-false-start",
2921 "-advertise-alpn", "\x03foo",
2922 },
2923 })
2924
2925 // False Start without session tickets.
2926 tests = append(tests, testCase{
2927 name: "FalseStart-SessionTicketsDisabled",
2928 config: Config{
2929 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2930 NextProtos: []string{"foo"},
2931 SessionTicketsDisabled: true,
2932 Bugs: ProtocolBugs{
2933 ExpectFalseStart: true,
2934 },
2935 },
2936 flags: []string{
2937 "-false-start",
2938 "-select-next-proto", "foo",
2939 },
2940 shimWritesFirst: true,
2941 })
2942
2943 // Server parses a V2ClientHello.
2944 tests = append(tests, testCase{
2945 testType: serverTest,
2946 name: "SendV2ClientHello",
2947 config: Config{
2948 // Choose a cipher suite that does not involve
2949 // elliptic curves, so no extensions are
2950 // involved.
2951 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2952 Bugs: ProtocolBugs{
2953 SendV2ClientHello: true,
2954 },
2955 },
2956 })
2957
2958 // Client sends a Channel ID.
2959 tests = append(tests, testCase{
2960 name: "ChannelID-Client",
2961 config: Config{
2962 RequestChannelID: true,
2963 },
Adam Langley7c803a62015-06-15 15:35:05 -07002964 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002965 resumeSession: true,
2966 expectChannelID: true,
2967 })
2968
2969 // Server accepts a Channel ID.
2970 tests = append(tests, testCase{
2971 testType: serverTest,
2972 name: "ChannelID-Server",
2973 config: Config{
2974 ChannelID: channelIDKey,
2975 },
2976 flags: []string{
2977 "-expect-channel-id",
2978 base64.StdEncoding.EncodeToString(channelIDBytes),
2979 },
2980 resumeSession: true,
2981 expectChannelID: true,
2982 })
David Benjamin30789da2015-08-29 22:56:45 -04002983
2984 // Bidirectional shutdown with the runner initiating.
2985 tests = append(tests, testCase{
2986 name: "Shutdown-Runner",
2987 config: Config{
2988 Bugs: ProtocolBugs{
2989 ExpectCloseNotify: true,
2990 },
2991 },
2992 flags: []string{"-check-close-notify"},
2993 })
2994
2995 // Bidirectional shutdown with the shim initiating. The runner,
2996 // in the meantime, sends garbage before the close_notify which
2997 // the shim must ignore.
2998 tests = append(tests, testCase{
2999 name: "Shutdown-Shim",
3000 config: Config{
3001 Bugs: ProtocolBugs{
3002 ExpectCloseNotify: true,
3003 },
3004 },
3005 shimShutsDown: true,
3006 sendEmptyRecords: 1,
3007 sendWarningAlerts: 1,
3008 flags: []string{"-check-close-notify"},
3009 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003010 } else {
3011 tests = append(tests, testCase{
3012 name: "SkipHelloVerifyRequest",
3013 config: Config{
3014 Bugs: ProtocolBugs{
3015 SkipHelloVerifyRequest: true,
3016 },
3017 },
3018 })
3019 }
3020
David Benjamin760b1dd2015-05-15 23:33:48 -04003021 for _, test := range tests {
3022 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05003023 if protocol == dtls {
3024 test.name += "-DTLS"
3025 }
3026 if async {
3027 test.name += "-Async"
3028 test.flags = append(test.flags, "-async")
3029 } else {
3030 test.name += "-Sync"
3031 }
3032 if splitHandshake {
3033 test.name += "-SplitHandshakeRecords"
3034 test.config.Bugs.MaxHandshakeRecordLength = 1
3035 if protocol == dtls {
3036 test.config.Bugs.MaxPacketLength = 256
3037 test.flags = append(test.flags, "-mtu", "256")
3038 }
3039 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003040 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003041 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003042}
3043
Adam Langley524e7172015-02-20 16:04:00 -08003044func addDDoSCallbackTests() {
3045 // DDoS callback.
3046
3047 for _, resume := range []bool{false, true} {
3048 suffix := "Resume"
3049 if resume {
3050 suffix = "No" + suffix
3051 }
3052
3053 testCases = append(testCases, testCase{
3054 testType: serverTest,
3055 name: "Server-DDoS-OK-" + suffix,
3056 flags: []string{"-install-ddos-callback"},
3057 resumeSession: resume,
3058 })
3059
3060 failFlag := "-fail-ddos-callback"
3061 if resume {
3062 failFlag = "-fail-second-ddos-callback"
3063 }
3064 testCases = append(testCases, testCase{
3065 testType: serverTest,
3066 name: "Server-DDoS-Reject-" + suffix,
3067 flags: []string{"-install-ddos-callback", failFlag},
3068 resumeSession: resume,
3069 shouldFail: true,
3070 expectedError: ":CONNECTION_REJECTED:",
3071 })
3072 }
3073}
3074
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003075func addVersionNegotiationTests() {
3076 for i, shimVers := range tlsVersions {
3077 // Assemble flags to disable all newer versions on the shim.
3078 var flags []string
3079 for _, vers := range tlsVersions[i+1:] {
3080 flags = append(flags, vers.flag)
3081 }
3082
3083 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003084 protocols := []protocol{tls}
3085 if runnerVers.hasDTLS && shimVers.hasDTLS {
3086 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003087 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003088 for _, protocol := range protocols {
3089 expectedVersion := shimVers.version
3090 if runnerVers.version < shimVers.version {
3091 expectedVersion = runnerVers.version
3092 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003093
David Benjamin8b8c0062014-11-23 02:47:52 -05003094 suffix := shimVers.name + "-" + runnerVers.name
3095 if protocol == dtls {
3096 suffix += "-DTLS"
3097 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003098
David Benjamin1eb367c2014-12-12 18:17:51 -05003099 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3100
David Benjamin1e29a6b2014-12-10 02:27:24 -05003101 clientVers := shimVers.version
3102 if clientVers > VersionTLS10 {
3103 clientVers = VersionTLS10
3104 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003105 testCases = append(testCases, testCase{
3106 protocol: protocol,
3107 testType: clientTest,
3108 name: "VersionNegotiation-Client-" + suffix,
3109 config: Config{
3110 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003111 Bugs: ProtocolBugs{
3112 ExpectInitialRecordVersion: clientVers,
3113 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003114 },
3115 flags: flags,
3116 expectedVersion: expectedVersion,
3117 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003118 testCases = append(testCases, testCase{
3119 protocol: protocol,
3120 testType: clientTest,
3121 name: "VersionNegotiation-Client2-" + suffix,
3122 config: Config{
3123 MaxVersion: runnerVers.version,
3124 Bugs: ProtocolBugs{
3125 ExpectInitialRecordVersion: clientVers,
3126 },
3127 },
3128 flags: []string{"-max-version", shimVersFlag},
3129 expectedVersion: expectedVersion,
3130 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003131
3132 testCases = append(testCases, testCase{
3133 protocol: protocol,
3134 testType: serverTest,
3135 name: "VersionNegotiation-Server-" + suffix,
3136 config: Config{
3137 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003138 Bugs: ProtocolBugs{
3139 ExpectInitialRecordVersion: expectedVersion,
3140 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003141 },
3142 flags: flags,
3143 expectedVersion: expectedVersion,
3144 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003145 testCases = append(testCases, testCase{
3146 protocol: protocol,
3147 testType: serverTest,
3148 name: "VersionNegotiation-Server2-" + suffix,
3149 config: Config{
3150 MaxVersion: runnerVers.version,
3151 Bugs: ProtocolBugs{
3152 ExpectInitialRecordVersion: expectedVersion,
3153 },
3154 },
3155 flags: []string{"-max-version", shimVersFlag},
3156 expectedVersion: expectedVersion,
3157 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003158 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003159 }
3160 }
3161}
3162
David Benjaminaccb4542014-12-12 23:44:33 -05003163func addMinimumVersionTests() {
3164 for i, shimVers := range tlsVersions {
3165 // Assemble flags to disable all older versions on the shim.
3166 var flags []string
3167 for _, vers := range tlsVersions[:i] {
3168 flags = append(flags, vers.flag)
3169 }
3170
3171 for _, runnerVers := range tlsVersions {
3172 protocols := []protocol{tls}
3173 if runnerVers.hasDTLS && shimVers.hasDTLS {
3174 protocols = append(protocols, dtls)
3175 }
3176 for _, protocol := range protocols {
3177 suffix := shimVers.name + "-" + runnerVers.name
3178 if protocol == dtls {
3179 suffix += "-DTLS"
3180 }
3181 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3182
David Benjaminaccb4542014-12-12 23:44:33 -05003183 var expectedVersion uint16
3184 var shouldFail bool
3185 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003186 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003187 if runnerVers.version >= shimVers.version {
3188 expectedVersion = runnerVers.version
3189 } else {
3190 shouldFail = true
3191 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003192 if runnerVers.version > VersionSSL30 {
3193 expectedLocalError = "remote error: protocol version not supported"
3194 } else {
3195 expectedLocalError = "remote error: handshake failure"
3196 }
David Benjaminaccb4542014-12-12 23:44:33 -05003197 }
3198
3199 testCases = append(testCases, testCase{
3200 protocol: protocol,
3201 testType: clientTest,
3202 name: "MinimumVersion-Client-" + suffix,
3203 config: Config{
3204 MaxVersion: runnerVers.version,
3205 },
David Benjamin87909c02014-12-13 01:55:01 -05003206 flags: flags,
3207 expectedVersion: expectedVersion,
3208 shouldFail: shouldFail,
3209 expectedError: expectedError,
3210 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003211 })
3212 testCases = append(testCases, testCase{
3213 protocol: protocol,
3214 testType: clientTest,
3215 name: "MinimumVersion-Client2-" + suffix,
3216 config: Config{
3217 MaxVersion: runnerVers.version,
3218 },
David Benjamin87909c02014-12-13 01:55:01 -05003219 flags: []string{"-min-version", shimVersFlag},
3220 expectedVersion: expectedVersion,
3221 shouldFail: shouldFail,
3222 expectedError: expectedError,
3223 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003224 })
3225
3226 testCases = append(testCases, testCase{
3227 protocol: protocol,
3228 testType: serverTest,
3229 name: "MinimumVersion-Server-" + suffix,
3230 config: Config{
3231 MaxVersion: runnerVers.version,
3232 },
David Benjamin87909c02014-12-13 01:55:01 -05003233 flags: flags,
3234 expectedVersion: expectedVersion,
3235 shouldFail: shouldFail,
3236 expectedError: expectedError,
3237 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003238 })
3239 testCases = append(testCases, testCase{
3240 protocol: protocol,
3241 testType: serverTest,
3242 name: "MinimumVersion-Server2-" + suffix,
3243 config: Config{
3244 MaxVersion: runnerVers.version,
3245 },
David Benjamin87909c02014-12-13 01:55:01 -05003246 flags: []string{"-min-version", shimVersFlag},
3247 expectedVersion: expectedVersion,
3248 shouldFail: shouldFail,
3249 expectedError: expectedError,
3250 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003251 })
3252 }
3253 }
3254 }
3255}
3256
David Benjamine78bfde2014-09-06 12:45:15 -04003257func addExtensionTests() {
3258 testCases = append(testCases, testCase{
3259 testType: clientTest,
3260 name: "DuplicateExtensionClient",
3261 config: Config{
3262 Bugs: ProtocolBugs{
3263 DuplicateExtension: true,
3264 },
3265 },
3266 shouldFail: true,
3267 expectedLocalError: "remote error: error decoding message",
3268 })
3269 testCases = append(testCases, testCase{
3270 testType: serverTest,
3271 name: "DuplicateExtensionServer",
3272 config: Config{
3273 Bugs: ProtocolBugs{
3274 DuplicateExtension: true,
3275 },
3276 },
3277 shouldFail: true,
3278 expectedLocalError: "remote error: error decoding message",
3279 })
3280 testCases = append(testCases, testCase{
3281 testType: clientTest,
3282 name: "ServerNameExtensionClient",
3283 config: Config{
3284 Bugs: ProtocolBugs{
3285 ExpectServerName: "example.com",
3286 },
3287 },
3288 flags: []string{"-host-name", "example.com"},
3289 })
3290 testCases = append(testCases, testCase{
3291 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003292 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003293 config: Config{
3294 Bugs: ProtocolBugs{
3295 ExpectServerName: "mismatch.com",
3296 },
3297 },
3298 flags: []string{"-host-name", "example.com"},
3299 shouldFail: true,
3300 expectedLocalError: "tls: unexpected server name",
3301 })
3302 testCases = append(testCases, testCase{
3303 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003304 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003305 config: Config{
3306 Bugs: ProtocolBugs{
3307 ExpectServerName: "missing.com",
3308 },
3309 },
3310 shouldFail: true,
3311 expectedLocalError: "tls: unexpected server name",
3312 })
3313 testCases = append(testCases, testCase{
3314 testType: serverTest,
3315 name: "ServerNameExtensionServer",
3316 config: Config{
3317 ServerName: "example.com",
3318 },
3319 flags: []string{"-expect-server-name", "example.com"},
3320 resumeSession: true,
3321 })
David Benjaminae2888f2014-09-06 12:58:58 -04003322 testCases = append(testCases, testCase{
3323 testType: clientTest,
3324 name: "ALPNClient",
3325 config: Config{
3326 NextProtos: []string{"foo"},
3327 },
3328 flags: []string{
3329 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3330 "-expect-alpn", "foo",
3331 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003332 expectedNextProto: "foo",
3333 expectedNextProtoType: alpn,
3334 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003335 })
3336 testCases = append(testCases, testCase{
3337 testType: serverTest,
3338 name: "ALPNServer",
3339 config: Config{
3340 NextProtos: []string{"foo", "bar", "baz"},
3341 },
3342 flags: []string{
3343 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3344 "-select-alpn", "foo",
3345 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003346 expectedNextProto: "foo",
3347 expectedNextProtoType: alpn,
3348 resumeSession: true,
3349 })
3350 // Test that the server prefers ALPN over NPN.
3351 testCases = append(testCases, testCase{
3352 testType: serverTest,
3353 name: "ALPNServer-Preferred",
3354 config: Config{
3355 NextProtos: []string{"foo", "bar", "baz"},
3356 },
3357 flags: []string{
3358 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3359 "-select-alpn", "foo",
3360 "-advertise-npn", "\x03foo\x03bar\x03baz",
3361 },
3362 expectedNextProto: "foo",
3363 expectedNextProtoType: alpn,
3364 resumeSession: true,
3365 })
3366 testCases = append(testCases, testCase{
3367 testType: serverTest,
3368 name: "ALPNServer-Preferred-Swapped",
3369 config: Config{
3370 NextProtos: []string{"foo", "bar", "baz"},
3371 Bugs: ProtocolBugs{
3372 SwapNPNAndALPN: true,
3373 },
3374 },
3375 flags: []string{
3376 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3377 "-select-alpn", "foo",
3378 "-advertise-npn", "\x03foo\x03bar\x03baz",
3379 },
3380 expectedNextProto: "foo",
3381 expectedNextProtoType: alpn,
3382 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003383 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003384 var emptyString string
3385 testCases = append(testCases, testCase{
3386 testType: clientTest,
3387 name: "ALPNClient-EmptyProtocolName",
3388 config: Config{
3389 NextProtos: []string{""},
3390 Bugs: ProtocolBugs{
3391 // A server returning an empty ALPN protocol
3392 // should be rejected.
3393 ALPNProtocol: &emptyString,
3394 },
3395 },
3396 flags: []string{
3397 "-advertise-alpn", "\x03foo",
3398 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003399 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003400 expectedError: ":PARSE_TLSEXT:",
3401 })
3402 testCases = append(testCases, testCase{
3403 testType: serverTest,
3404 name: "ALPNServer-EmptyProtocolName",
3405 config: Config{
3406 // A ClientHello containing an empty ALPN protocol
3407 // should be rejected.
3408 NextProtos: []string{"foo", "", "baz"},
3409 },
3410 flags: []string{
3411 "-select-alpn", "foo",
3412 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003413 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003414 expectedError: ":PARSE_TLSEXT:",
3415 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003416 // Test that negotiating both NPN and ALPN is forbidden.
3417 testCases = append(testCases, testCase{
3418 name: "NegotiateALPNAndNPN",
3419 config: Config{
3420 NextProtos: []string{"foo", "bar", "baz"},
3421 Bugs: ProtocolBugs{
3422 NegotiateALPNAndNPN: true,
3423 },
3424 },
3425 flags: []string{
3426 "-advertise-alpn", "\x03foo",
3427 "-select-next-proto", "foo",
3428 },
3429 shouldFail: true,
3430 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3431 })
3432 testCases = append(testCases, testCase{
3433 name: "NegotiateALPNAndNPN-Swapped",
3434 config: Config{
3435 NextProtos: []string{"foo", "bar", "baz"},
3436 Bugs: ProtocolBugs{
3437 NegotiateALPNAndNPN: true,
3438 SwapNPNAndALPN: true,
3439 },
3440 },
3441 flags: []string{
3442 "-advertise-alpn", "\x03foo",
3443 "-select-next-proto", "foo",
3444 },
3445 shouldFail: true,
3446 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3447 })
David Benjamin091c4b92015-10-26 13:33:21 -04003448 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3449 testCases = append(testCases, testCase{
3450 name: "DisableNPN",
3451 config: Config{
3452 NextProtos: []string{"foo"},
3453 },
3454 flags: []string{
3455 "-select-next-proto", "foo",
3456 "-disable-npn",
3457 },
3458 expectNoNextProto: true,
3459 })
Adam Langley38311732014-10-16 19:04:35 -07003460 // Resume with a corrupt ticket.
3461 testCases = append(testCases, testCase{
3462 testType: serverTest,
3463 name: "CorruptTicket",
3464 config: Config{
3465 Bugs: ProtocolBugs{
3466 CorruptTicket: true,
3467 },
3468 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003469 resumeSession: true,
3470 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003471 })
David Benjamind98452d2015-06-16 14:16:23 -04003472 // Test the ticket callback, with and without renewal.
3473 testCases = append(testCases, testCase{
3474 testType: serverTest,
3475 name: "TicketCallback",
3476 resumeSession: true,
3477 flags: []string{"-use-ticket-callback"},
3478 })
3479 testCases = append(testCases, testCase{
3480 testType: serverTest,
3481 name: "TicketCallback-Renew",
3482 config: Config{
3483 Bugs: ProtocolBugs{
3484 ExpectNewTicket: true,
3485 },
3486 },
3487 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3488 resumeSession: true,
3489 })
Adam Langley38311732014-10-16 19:04:35 -07003490 // Resume with an oversized session id.
3491 testCases = append(testCases, testCase{
3492 testType: serverTest,
3493 name: "OversizedSessionId",
3494 config: Config{
3495 Bugs: ProtocolBugs{
3496 OversizedSessionId: true,
3497 },
3498 },
3499 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003500 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003501 expectedError: ":DECODE_ERROR:",
3502 })
David Benjaminca6c8262014-11-15 19:06:08 -05003503 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3504 // are ignored.
3505 testCases = append(testCases, testCase{
3506 protocol: dtls,
3507 name: "SRTP-Client",
3508 config: Config{
3509 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3510 },
3511 flags: []string{
3512 "-srtp-profiles",
3513 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3514 },
3515 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3516 })
3517 testCases = append(testCases, testCase{
3518 protocol: dtls,
3519 testType: serverTest,
3520 name: "SRTP-Server",
3521 config: Config{
3522 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3523 },
3524 flags: []string{
3525 "-srtp-profiles",
3526 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3527 },
3528 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3529 })
3530 // Test that the MKI is ignored.
3531 testCases = append(testCases, testCase{
3532 protocol: dtls,
3533 testType: serverTest,
3534 name: "SRTP-Server-IgnoreMKI",
3535 config: Config{
3536 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3537 Bugs: ProtocolBugs{
3538 SRTPMasterKeyIdentifer: "bogus",
3539 },
3540 },
3541 flags: []string{
3542 "-srtp-profiles",
3543 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3544 },
3545 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3546 })
3547 // Test that SRTP isn't negotiated on the server if there were
3548 // no matching profiles.
3549 testCases = append(testCases, testCase{
3550 protocol: dtls,
3551 testType: serverTest,
3552 name: "SRTP-Server-NoMatch",
3553 config: Config{
3554 SRTPProtectionProfiles: []uint16{100, 101, 102},
3555 },
3556 flags: []string{
3557 "-srtp-profiles",
3558 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3559 },
3560 expectedSRTPProtectionProfile: 0,
3561 })
3562 // Test that the server returning an invalid SRTP profile is
3563 // flagged as an error by the client.
3564 testCases = append(testCases, testCase{
3565 protocol: dtls,
3566 name: "SRTP-Client-NoMatch",
3567 config: Config{
3568 Bugs: ProtocolBugs{
3569 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3570 },
3571 },
3572 flags: []string{
3573 "-srtp-profiles",
3574 "SRTP_AES128_CM_SHA1_80",
3575 },
3576 shouldFail: true,
3577 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3578 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003579 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003580 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003581 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003582 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003583 flags: []string{
3584 "-enable-signed-cert-timestamps",
3585 "-expect-signed-cert-timestamps",
3586 base64.StdEncoding.EncodeToString(testSCTList),
3587 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003588 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003589 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003590 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003591 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003592 testType: serverTest,
3593 flags: []string{
3594 "-signed-cert-timestamps",
3595 base64.StdEncoding.EncodeToString(testSCTList),
3596 },
3597 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003598 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003599 })
3600 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003601 testType: clientTest,
3602 name: "ClientHelloPadding",
3603 config: Config{
3604 Bugs: ProtocolBugs{
3605 RequireClientHelloSize: 512,
3606 },
3607 },
3608 // This hostname just needs to be long enough to push the
3609 // ClientHello into F5's danger zone between 256 and 511 bytes
3610 // long.
3611 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3612 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003613
3614 // Extensions should not function in SSL 3.0.
3615 testCases = append(testCases, testCase{
3616 testType: serverTest,
3617 name: "SSLv3Extensions-NoALPN",
3618 config: Config{
3619 MaxVersion: VersionSSL30,
3620 NextProtos: []string{"foo", "bar", "baz"},
3621 },
3622 flags: []string{
3623 "-select-alpn", "foo",
3624 },
3625 expectNoNextProto: true,
3626 })
3627
3628 // Test session tickets separately as they follow a different codepath.
3629 testCases = append(testCases, testCase{
3630 testType: serverTest,
3631 name: "SSLv3Extensions-NoTickets",
3632 config: Config{
3633 MaxVersion: VersionSSL30,
3634 Bugs: ProtocolBugs{
3635 // Historically, session tickets in SSL 3.0
3636 // failed in different ways depending on whether
3637 // the client supported renegotiation_info.
3638 NoRenegotiationInfo: true,
3639 },
3640 },
3641 resumeSession: true,
3642 })
3643 testCases = append(testCases, testCase{
3644 testType: serverTest,
3645 name: "SSLv3Extensions-NoTickets2",
3646 config: Config{
3647 MaxVersion: VersionSSL30,
3648 },
3649 resumeSession: true,
3650 })
3651
3652 // But SSL 3.0 does send and process renegotiation_info.
3653 testCases = append(testCases, testCase{
3654 testType: serverTest,
3655 name: "SSLv3Extensions-RenegotiationInfo",
3656 config: Config{
3657 MaxVersion: VersionSSL30,
3658 Bugs: ProtocolBugs{
3659 RequireRenegotiationInfo: true,
3660 },
3661 },
3662 })
3663 testCases = append(testCases, testCase{
3664 testType: serverTest,
3665 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3666 config: Config{
3667 MaxVersion: VersionSSL30,
3668 Bugs: ProtocolBugs{
3669 NoRenegotiationInfo: true,
3670 SendRenegotiationSCSV: true,
3671 RequireRenegotiationInfo: true,
3672 },
3673 },
3674 })
David Benjamine78bfde2014-09-06 12:45:15 -04003675}
3676
David Benjamin01fe8202014-09-24 15:21:44 -04003677func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003678 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003679 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003680 protocols := []protocol{tls}
3681 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3682 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003683 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003684 for _, protocol := range protocols {
3685 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3686 if protocol == dtls {
3687 suffix += "-DTLS"
3688 }
3689
David Benjaminece3de92015-03-16 18:02:20 -04003690 if sessionVers.version == resumeVers.version {
3691 testCases = append(testCases, testCase{
3692 protocol: protocol,
3693 name: "Resume-Client" + suffix,
3694 resumeSession: true,
3695 config: Config{
3696 MaxVersion: sessionVers.version,
3697 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003698 },
David Benjaminece3de92015-03-16 18:02:20 -04003699 expectedVersion: sessionVers.version,
3700 expectedResumeVersion: resumeVers.version,
3701 })
3702 } else {
3703 testCases = append(testCases, testCase{
3704 protocol: protocol,
3705 name: "Resume-Client-Mismatch" + suffix,
3706 resumeSession: true,
3707 config: Config{
3708 MaxVersion: sessionVers.version,
3709 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003710 },
David Benjaminece3de92015-03-16 18:02:20 -04003711 expectedVersion: sessionVers.version,
3712 resumeConfig: &Config{
3713 MaxVersion: resumeVers.version,
3714 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3715 Bugs: ProtocolBugs{
3716 AllowSessionVersionMismatch: true,
3717 },
3718 },
3719 expectedResumeVersion: resumeVers.version,
3720 shouldFail: true,
3721 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3722 })
3723 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003724
3725 testCases = append(testCases, testCase{
3726 protocol: protocol,
3727 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003728 resumeSession: true,
3729 config: Config{
3730 MaxVersion: sessionVers.version,
3731 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3732 },
3733 expectedVersion: sessionVers.version,
3734 resumeConfig: &Config{
3735 MaxVersion: resumeVers.version,
3736 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3737 },
3738 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003739 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003740 expectedResumeVersion: resumeVers.version,
3741 })
3742
David Benjamin8b8c0062014-11-23 02:47:52 -05003743 testCases = append(testCases, testCase{
3744 protocol: protocol,
3745 testType: serverTest,
3746 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003747 resumeSession: true,
3748 config: Config{
3749 MaxVersion: sessionVers.version,
3750 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3751 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003752 expectedVersion: sessionVers.version,
3753 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003754 resumeConfig: &Config{
3755 MaxVersion: resumeVers.version,
3756 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3757 },
3758 expectedResumeVersion: resumeVers.version,
3759 })
3760 }
David Benjamin01fe8202014-09-24 15:21:44 -04003761 }
3762 }
David Benjaminece3de92015-03-16 18:02:20 -04003763
3764 testCases = append(testCases, testCase{
3765 name: "Resume-Client-CipherMismatch",
3766 resumeSession: true,
3767 config: Config{
3768 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3769 },
3770 resumeConfig: &Config{
3771 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3772 Bugs: ProtocolBugs{
3773 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3774 },
3775 },
3776 shouldFail: true,
3777 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3778 })
David Benjamin01fe8202014-09-24 15:21:44 -04003779}
3780
Adam Langley2ae77d22014-10-28 17:29:33 -07003781func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003782 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003783 testCases = append(testCases, testCase{
3784 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003785 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003786 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003787 shouldFail: true,
3788 expectedError: ":NO_RENEGOTIATION:",
3789 expectedLocalError: "remote error: no renegotiation",
3790 })
Adam Langley5021b222015-06-12 18:27:58 -07003791 // The server shouldn't echo the renegotiation extension unless
3792 // requested by the client.
3793 testCases = append(testCases, testCase{
3794 testType: serverTest,
3795 name: "Renegotiate-Server-NoExt",
3796 config: Config{
3797 Bugs: ProtocolBugs{
3798 NoRenegotiationInfo: true,
3799 RequireRenegotiationInfo: true,
3800 },
3801 },
3802 shouldFail: true,
3803 expectedLocalError: "renegotiation extension missing",
3804 })
3805 // The renegotiation SCSV should be sufficient for the server to echo
3806 // the extension.
3807 testCases = append(testCases, testCase{
3808 testType: serverTest,
3809 name: "Renegotiate-Server-NoExt-SCSV",
3810 config: Config{
3811 Bugs: ProtocolBugs{
3812 NoRenegotiationInfo: true,
3813 SendRenegotiationSCSV: true,
3814 RequireRenegotiationInfo: true,
3815 },
3816 },
3817 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003818 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003819 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003820 config: Config{
3821 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003822 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003823 },
3824 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003825 renegotiate: 1,
3826 flags: []string{
3827 "-renegotiate-freely",
3828 "-expect-total-renegotiations", "1",
3829 },
David Benjamincdea40c2015-03-19 14:09:43 -04003830 })
3831 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003832 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003833 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003834 config: Config{
3835 Bugs: ProtocolBugs{
3836 EmptyRenegotiationInfo: true,
3837 },
3838 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003839 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003840 shouldFail: true,
3841 expectedError: ":RENEGOTIATION_MISMATCH:",
3842 })
3843 testCases = append(testCases, testCase{
3844 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003845 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003846 config: Config{
3847 Bugs: ProtocolBugs{
3848 BadRenegotiationInfo: true,
3849 },
3850 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003851 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003852 shouldFail: true,
3853 expectedError: ":RENEGOTIATION_MISMATCH:",
3854 })
3855 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05003856 name: "Renegotiate-Client-Downgrade",
3857 renegotiate: 1,
3858 config: Config{
3859 Bugs: ProtocolBugs{
3860 NoRenegotiationInfoAfterInitial: true,
3861 },
3862 },
3863 flags: []string{"-renegotiate-freely"},
3864 shouldFail: true,
3865 expectedError: ":RENEGOTIATION_MISMATCH:",
3866 })
3867 testCases = append(testCases, testCase{
3868 name: "Renegotiate-Client-Upgrade",
3869 renegotiate: 1,
3870 config: Config{
3871 Bugs: ProtocolBugs{
3872 NoRenegotiationInfoInInitial: true,
3873 },
3874 },
3875 flags: []string{"-renegotiate-freely"},
3876 shouldFail: true,
3877 expectedError: ":RENEGOTIATION_MISMATCH:",
3878 })
3879 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04003880 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003881 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003882 config: Config{
3883 Bugs: ProtocolBugs{
3884 NoRenegotiationInfo: true,
3885 },
3886 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003887 flags: []string{
3888 "-renegotiate-freely",
3889 "-expect-total-renegotiations", "1",
3890 },
David Benjamincff0b902015-05-15 23:09:47 -04003891 })
3892 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003893 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003894 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003895 config: Config{
3896 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3897 },
3898 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003899 flags: []string{
3900 "-renegotiate-freely",
3901 "-expect-total-renegotiations", "1",
3902 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003903 })
3904 testCases = append(testCases, testCase{
3905 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003906 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003907 config: Config{
3908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3909 },
3910 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003911 flags: []string{
3912 "-renegotiate-freely",
3913 "-expect-total-renegotiations", "1",
3914 },
David Benjaminb16346b2015-04-08 19:16:58 -04003915 })
3916 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003917 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003918 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003919 config: Config{
3920 MaxVersion: VersionTLS10,
3921 Bugs: ProtocolBugs{
3922 RequireSameRenegoClientVersion: true,
3923 },
3924 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003925 flags: []string{
3926 "-renegotiate-freely",
3927 "-expect-total-renegotiations", "1",
3928 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003929 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003930 testCases = append(testCases, testCase{
3931 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003932 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003933 config: Config{
3934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3935 NextProtos: []string{"foo"},
3936 },
3937 flags: []string{
3938 "-false-start",
3939 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003940 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003941 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003942 },
3943 shimWritesFirst: true,
3944 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003945
3946 // Client-side renegotiation controls.
3947 testCases = append(testCases, testCase{
3948 name: "Renegotiate-Client-Forbidden-1",
3949 renegotiate: 1,
3950 shouldFail: true,
3951 expectedError: ":NO_RENEGOTIATION:",
3952 expectedLocalError: "remote error: no renegotiation",
3953 })
3954 testCases = append(testCases, testCase{
3955 name: "Renegotiate-Client-Once-1",
3956 renegotiate: 1,
3957 flags: []string{
3958 "-renegotiate-once",
3959 "-expect-total-renegotiations", "1",
3960 },
3961 })
3962 testCases = append(testCases, testCase{
3963 name: "Renegotiate-Client-Freely-1",
3964 renegotiate: 1,
3965 flags: []string{
3966 "-renegotiate-freely",
3967 "-expect-total-renegotiations", "1",
3968 },
3969 })
3970 testCases = append(testCases, testCase{
3971 name: "Renegotiate-Client-Once-2",
3972 renegotiate: 2,
3973 flags: []string{"-renegotiate-once"},
3974 shouldFail: true,
3975 expectedError: ":NO_RENEGOTIATION:",
3976 expectedLocalError: "remote error: no renegotiation",
3977 })
3978 testCases = append(testCases, testCase{
3979 name: "Renegotiate-Client-Freely-2",
3980 renegotiate: 2,
3981 flags: []string{
3982 "-renegotiate-freely",
3983 "-expect-total-renegotiations", "2",
3984 },
3985 })
Adam Langley27a0d082015-11-03 13:34:10 -08003986 testCases = append(testCases, testCase{
3987 name: "Renegotiate-Client-NoIgnore",
3988 config: Config{
3989 Bugs: ProtocolBugs{
3990 SendHelloRequestBeforeEveryAppDataRecord: true,
3991 },
3992 },
3993 shouldFail: true,
3994 expectedError: ":NO_RENEGOTIATION:",
3995 })
3996 testCases = append(testCases, testCase{
3997 name: "Renegotiate-Client-Ignore",
3998 config: Config{
3999 Bugs: ProtocolBugs{
4000 SendHelloRequestBeforeEveryAppDataRecord: true,
4001 },
4002 },
4003 flags: []string{
4004 "-renegotiate-ignore",
4005 "-expect-total-renegotiations", "0",
4006 },
4007 })
Adam Langley2ae77d22014-10-28 17:29:33 -07004008}
4009
David Benjamin5e961c12014-11-07 01:48:35 -05004010func addDTLSReplayTests() {
4011 // Test that sequence number replays are detected.
4012 testCases = append(testCases, testCase{
4013 protocol: dtls,
4014 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04004015 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004016 replayWrites: true,
4017 })
4018
David Benjamin8e6db492015-07-25 18:29:23 -04004019 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05004020 // than the retransmit window.
4021 testCases = append(testCases, testCase{
4022 protocol: dtls,
4023 name: "DTLS-Replay-LargeGaps",
4024 config: Config{
4025 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04004026 SequenceNumberMapping: func(in uint64) uint64 {
4027 return in * 127
4028 },
David Benjamin5e961c12014-11-07 01:48:35 -05004029 },
4030 },
David Benjamin8e6db492015-07-25 18:29:23 -04004031 messageCount: 200,
4032 replayWrites: true,
4033 })
4034
4035 // Test the incoming sequence number changing non-monotonically.
4036 testCases = append(testCases, testCase{
4037 protocol: dtls,
4038 name: "DTLS-Replay-NonMonotonic",
4039 config: Config{
4040 Bugs: ProtocolBugs{
4041 SequenceNumberMapping: func(in uint64) uint64 {
4042 return in ^ 31
4043 },
4044 },
4045 },
4046 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004047 replayWrites: true,
4048 })
4049}
4050
David Benjamin000800a2014-11-14 01:43:59 -05004051var testHashes = []struct {
4052 name string
4053 id uint8
4054}{
4055 {"SHA1", hashSHA1},
4056 {"SHA224", hashSHA224},
4057 {"SHA256", hashSHA256},
4058 {"SHA384", hashSHA384},
4059 {"SHA512", hashSHA512},
4060}
4061
4062func addSigningHashTests() {
4063 // Make sure each hash works. Include some fake hashes in the list and
4064 // ensure they're ignored.
4065 for _, hash := range testHashes {
4066 testCases = append(testCases, testCase{
4067 name: "SigningHash-ClientAuth-" + hash.name,
4068 config: Config{
4069 ClientAuth: RequireAnyClientCert,
4070 SignatureAndHashes: []signatureAndHash{
4071 {signatureRSA, 42},
4072 {signatureRSA, hash.id},
4073 {signatureRSA, 255},
4074 },
4075 },
4076 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004077 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4078 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004079 },
4080 })
4081
4082 testCases = append(testCases, testCase{
4083 testType: serverTest,
4084 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4085 config: Config{
4086 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4087 SignatureAndHashes: []signatureAndHash{
4088 {signatureRSA, 42},
4089 {signatureRSA, hash.id},
4090 {signatureRSA, 255},
4091 },
4092 },
4093 })
David Benjamin6e807652015-11-02 12:02:20 -05004094
4095 testCases = append(testCases, testCase{
4096 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4097 config: Config{
4098 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4099 SignatureAndHashes: []signatureAndHash{
4100 {signatureRSA, 42},
4101 {signatureRSA, hash.id},
4102 {signatureRSA, 255},
4103 },
4104 },
4105 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4106 })
David Benjamin000800a2014-11-14 01:43:59 -05004107 }
4108
4109 // Test that hash resolution takes the signature type into account.
4110 testCases = append(testCases, testCase{
4111 name: "SigningHash-ClientAuth-SignatureType",
4112 config: Config{
4113 ClientAuth: RequireAnyClientCert,
4114 SignatureAndHashes: []signatureAndHash{
4115 {signatureECDSA, hashSHA512},
4116 {signatureRSA, hashSHA384},
4117 {signatureECDSA, hashSHA1},
4118 },
4119 },
4120 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004121 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4122 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004123 },
4124 })
4125
4126 testCases = append(testCases, testCase{
4127 testType: serverTest,
4128 name: "SigningHash-ServerKeyExchange-SignatureType",
4129 config: Config{
4130 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4131 SignatureAndHashes: []signatureAndHash{
4132 {signatureECDSA, hashSHA512},
4133 {signatureRSA, hashSHA384},
4134 {signatureECDSA, hashSHA1},
4135 },
4136 },
4137 })
4138
4139 // Test that, if the list is missing, the peer falls back to SHA-1.
4140 testCases = append(testCases, testCase{
4141 name: "SigningHash-ClientAuth-Fallback",
4142 config: Config{
4143 ClientAuth: RequireAnyClientCert,
4144 SignatureAndHashes: []signatureAndHash{
4145 {signatureRSA, hashSHA1},
4146 },
4147 Bugs: ProtocolBugs{
4148 NoSignatureAndHashes: true,
4149 },
4150 },
4151 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004152 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4153 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004154 },
4155 })
4156
4157 testCases = append(testCases, testCase{
4158 testType: serverTest,
4159 name: "SigningHash-ServerKeyExchange-Fallback",
4160 config: Config{
4161 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4162 SignatureAndHashes: []signatureAndHash{
4163 {signatureRSA, hashSHA1},
4164 },
4165 Bugs: ProtocolBugs{
4166 NoSignatureAndHashes: true,
4167 },
4168 },
4169 })
David Benjamin72dc7832015-03-16 17:49:43 -04004170
4171 // Test that hash preferences are enforced. BoringSSL defaults to
4172 // rejecting MD5 signatures.
4173 testCases = append(testCases, testCase{
4174 testType: serverTest,
4175 name: "SigningHash-ClientAuth-Enforced",
4176 config: Config{
4177 Certificates: []Certificate{rsaCertificate},
4178 SignatureAndHashes: []signatureAndHash{
4179 {signatureRSA, hashMD5},
4180 // Advertise SHA-1 so the handshake will
4181 // proceed, but the shim's preferences will be
4182 // ignored in CertificateVerify generation, so
4183 // MD5 will be chosen.
4184 {signatureRSA, hashSHA1},
4185 },
4186 Bugs: ProtocolBugs{
4187 IgnorePeerSignatureAlgorithmPreferences: true,
4188 },
4189 },
4190 flags: []string{"-require-any-client-certificate"},
4191 shouldFail: true,
4192 expectedError: ":WRONG_SIGNATURE_TYPE:",
4193 })
4194
4195 testCases = append(testCases, testCase{
4196 name: "SigningHash-ServerKeyExchange-Enforced",
4197 config: Config{
4198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4199 SignatureAndHashes: []signatureAndHash{
4200 {signatureRSA, hashMD5},
4201 },
4202 Bugs: ProtocolBugs{
4203 IgnorePeerSignatureAlgorithmPreferences: true,
4204 },
4205 },
4206 shouldFail: true,
4207 expectedError: ":WRONG_SIGNATURE_TYPE:",
4208 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004209
4210 // Test that the agreed upon digest respects the client preferences and
4211 // the server digests.
4212 testCases = append(testCases, testCase{
4213 name: "Agree-Digest-Fallback",
4214 config: Config{
4215 ClientAuth: RequireAnyClientCert,
4216 SignatureAndHashes: []signatureAndHash{
4217 {signatureRSA, hashSHA512},
4218 {signatureRSA, hashSHA1},
4219 },
4220 },
4221 flags: []string{
4222 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4223 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4224 },
4225 digestPrefs: "SHA256",
4226 expectedClientCertSignatureHash: hashSHA1,
4227 })
4228 testCases = append(testCases, testCase{
4229 name: "Agree-Digest-SHA256",
4230 config: Config{
4231 ClientAuth: RequireAnyClientCert,
4232 SignatureAndHashes: []signatureAndHash{
4233 {signatureRSA, hashSHA1},
4234 {signatureRSA, hashSHA256},
4235 },
4236 },
4237 flags: []string{
4238 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4239 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4240 },
4241 digestPrefs: "SHA256,SHA1",
4242 expectedClientCertSignatureHash: hashSHA256,
4243 })
4244 testCases = append(testCases, testCase{
4245 name: "Agree-Digest-SHA1",
4246 config: Config{
4247 ClientAuth: RequireAnyClientCert,
4248 SignatureAndHashes: []signatureAndHash{
4249 {signatureRSA, hashSHA1},
4250 },
4251 },
4252 flags: []string{
4253 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4254 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4255 },
4256 digestPrefs: "SHA512,SHA256,SHA1",
4257 expectedClientCertSignatureHash: hashSHA1,
4258 })
4259 testCases = append(testCases, testCase{
4260 name: "Agree-Digest-Default",
4261 config: Config{
4262 ClientAuth: RequireAnyClientCert,
4263 SignatureAndHashes: []signatureAndHash{
4264 {signatureRSA, hashSHA256},
4265 {signatureECDSA, hashSHA256},
4266 {signatureRSA, hashSHA1},
4267 {signatureECDSA, hashSHA1},
4268 },
4269 },
4270 flags: []string{
4271 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4272 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4273 },
4274 expectedClientCertSignatureHash: hashSHA256,
4275 })
David Benjamin000800a2014-11-14 01:43:59 -05004276}
4277
David Benjamin83f90402015-01-27 01:09:43 -05004278// timeouts is the retransmit schedule for BoringSSL. It doubles and
4279// caps at 60 seconds. On the 13th timeout, it gives up.
4280var timeouts = []time.Duration{
4281 1 * time.Second,
4282 2 * time.Second,
4283 4 * time.Second,
4284 8 * time.Second,
4285 16 * time.Second,
4286 32 * time.Second,
4287 60 * time.Second,
4288 60 * time.Second,
4289 60 * time.Second,
4290 60 * time.Second,
4291 60 * time.Second,
4292 60 * time.Second,
4293 60 * time.Second,
4294}
4295
4296func addDTLSRetransmitTests() {
4297 // Test that this is indeed the timeout schedule. Stress all
4298 // four patterns of handshake.
4299 for i := 1; i < len(timeouts); i++ {
4300 number := strconv.Itoa(i)
4301 testCases = append(testCases, testCase{
4302 protocol: dtls,
4303 name: "DTLS-Retransmit-Client-" + number,
4304 config: Config{
4305 Bugs: ProtocolBugs{
4306 TimeoutSchedule: timeouts[:i],
4307 },
4308 },
4309 resumeSession: true,
4310 flags: []string{"-async"},
4311 })
4312 testCases = append(testCases, testCase{
4313 protocol: dtls,
4314 testType: serverTest,
4315 name: "DTLS-Retransmit-Server-" + number,
4316 config: Config{
4317 Bugs: ProtocolBugs{
4318 TimeoutSchedule: timeouts[:i],
4319 },
4320 },
4321 resumeSession: true,
4322 flags: []string{"-async"},
4323 })
4324 }
4325
4326 // Test that exceeding the timeout schedule hits a read
4327 // timeout.
4328 testCases = append(testCases, testCase{
4329 protocol: dtls,
4330 name: "DTLS-Retransmit-Timeout",
4331 config: Config{
4332 Bugs: ProtocolBugs{
4333 TimeoutSchedule: timeouts,
4334 },
4335 },
4336 resumeSession: true,
4337 flags: []string{"-async"},
4338 shouldFail: true,
4339 expectedError: ":READ_TIMEOUT_EXPIRED:",
4340 })
4341
4342 // Test that timeout handling has a fudge factor, due to API
4343 // problems.
4344 testCases = append(testCases, testCase{
4345 protocol: dtls,
4346 name: "DTLS-Retransmit-Fudge",
4347 config: Config{
4348 Bugs: ProtocolBugs{
4349 TimeoutSchedule: []time.Duration{
4350 timeouts[0] - 10*time.Millisecond,
4351 },
4352 },
4353 },
4354 resumeSession: true,
4355 flags: []string{"-async"},
4356 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004357
4358 // Test that the final Finished retransmitting isn't
4359 // duplicated if the peer badly fragments everything.
4360 testCases = append(testCases, testCase{
4361 testType: serverTest,
4362 protocol: dtls,
4363 name: "DTLS-Retransmit-Fragmented",
4364 config: Config{
4365 Bugs: ProtocolBugs{
4366 TimeoutSchedule: []time.Duration{timeouts[0]},
4367 MaxHandshakeRecordLength: 2,
4368 },
4369 },
4370 flags: []string{"-async"},
4371 })
David Benjamin83f90402015-01-27 01:09:43 -05004372}
4373
David Benjaminc565ebb2015-04-03 04:06:36 -04004374func addExportKeyingMaterialTests() {
4375 for _, vers := range tlsVersions {
4376 if vers.version == VersionSSL30 {
4377 continue
4378 }
4379 testCases = append(testCases, testCase{
4380 name: "ExportKeyingMaterial-" + vers.name,
4381 config: Config{
4382 MaxVersion: vers.version,
4383 },
4384 exportKeyingMaterial: 1024,
4385 exportLabel: "label",
4386 exportContext: "context",
4387 useExportContext: true,
4388 })
4389 testCases = append(testCases, testCase{
4390 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4391 config: Config{
4392 MaxVersion: vers.version,
4393 },
4394 exportKeyingMaterial: 1024,
4395 })
4396 testCases = append(testCases, testCase{
4397 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4398 config: Config{
4399 MaxVersion: vers.version,
4400 },
4401 exportKeyingMaterial: 1024,
4402 useExportContext: true,
4403 })
4404 testCases = append(testCases, testCase{
4405 name: "ExportKeyingMaterial-Small-" + vers.name,
4406 config: Config{
4407 MaxVersion: vers.version,
4408 },
4409 exportKeyingMaterial: 1,
4410 exportLabel: "label",
4411 exportContext: "context",
4412 useExportContext: true,
4413 })
4414 }
4415 testCases = append(testCases, testCase{
4416 name: "ExportKeyingMaterial-SSL3",
4417 config: Config{
4418 MaxVersion: VersionSSL30,
4419 },
4420 exportKeyingMaterial: 1024,
4421 exportLabel: "label",
4422 exportContext: "context",
4423 useExportContext: true,
4424 shouldFail: true,
4425 expectedError: "failed to export keying material",
4426 })
4427}
4428
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004429func addTLSUniqueTests() {
4430 for _, isClient := range []bool{false, true} {
4431 for _, isResumption := range []bool{false, true} {
4432 for _, hasEMS := range []bool{false, true} {
4433 var suffix string
4434 if isResumption {
4435 suffix = "Resume-"
4436 } else {
4437 suffix = "Full-"
4438 }
4439
4440 if hasEMS {
4441 suffix += "EMS-"
4442 } else {
4443 suffix += "NoEMS-"
4444 }
4445
4446 if isClient {
4447 suffix += "Client"
4448 } else {
4449 suffix += "Server"
4450 }
4451
4452 test := testCase{
4453 name: "TLSUnique-" + suffix,
4454 testTLSUnique: true,
4455 config: Config{
4456 Bugs: ProtocolBugs{
4457 NoExtendedMasterSecret: !hasEMS,
4458 },
4459 },
4460 }
4461
4462 if isResumption {
4463 test.resumeSession = true
4464 test.resumeConfig = &Config{
4465 Bugs: ProtocolBugs{
4466 NoExtendedMasterSecret: !hasEMS,
4467 },
4468 }
4469 }
4470
4471 if isResumption && !hasEMS {
4472 test.shouldFail = true
4473 test.expectedError = "failed to get tls-unique"
4474 }
4475
4476 testCases = append(testCases, test)
4477 }
4478 }
4479 }
4480}
4481
Adam Langley09505632015-07-30 18:10:13 -07004482func addCustomExtensionTests() {
4483 expectedContents := "custom extension"
4484 emptyString := ""
4485
4486 for _, isClient := range []bool{false, true} {
4487 suffix := "Server"
4488 flag := "-enable-server-custom-extension"
4489 testType := serverTest
4490 if isClient {
4491 suffix = "Client"
4492 flag = "-enable-client-custom-extension"
4493 testType = clientTest
4494 }
4495
4496 testCases = append(testCases, testCase{
4497 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004498 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004499 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004500 Bugs: ProtocolBugs{
4501 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004502 ExpectedCustomExtension: &expectedContents,
4503 },
4504 },
4505 flags: []string{flag},
4506 })
4507
4508 // If the parse callback fails, the handshake should also fail.
4509 testCases = append(testCases, testCase{
4510 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004511 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004512 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004513 Bugs: ProtocolBugs{
4514 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004515 ExpectedCustomExtension: &expectedContents,
4516 },
4517 },
David Benjamin399e7c92015-07-30 23:01:27 -04004518 flags: []string{flag},
4519 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004520 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4521 })
4522
4523 // If the add callback fails, the handshake should also fail.
4524 testCases = append(testCases, testCase{
4525 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004526 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004527 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004528 Bugs: ProtocolBugs{
4529 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004530 ExpectedCustomExtension: &expectedContents,
4531 },
4532 },
David Benjamin399e7c92015-07-30 23:01:27 -04004533 flags: []string{flag, "-custom-extension-fail-add"},
4534 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004535 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4536 })
4537
4538 // If the add callback returns zero, no extension should be
4539 // added.
4540 skipCustomExtension := expectedContents
4541 if isClient {
4542 // For the case where the client skips sending the
4543 // custom extension, the server must not “echo” it.
4544 skipCustomExtension = ""
4545 }
4546 testCases = append(testCases, testCase{
4547 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004548 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004549 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004550 Bugs: ProtocolBugs{
4551 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004552 ExpectedCustomExtension: &emptyString,
4553 },
4554 },
4555 flags: []string{flag, "-custom-extension-skip"},
4556 })
4557 }
4558
4559 // The custom extension add callback should not be called if the client
4560 // doesn't send the extension.
4561 testCases = append(testCases, testCase{
4562 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004563 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004564 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004565 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004566 ExpectedCustomExtension: &emptyString,
4567 },
4568 },
4569 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4570 })
Adam Langley2deb9842015-08-07 11:15:37 -07004571
4572 // Test an unknown extension from the server.
4573 testCases = append(testCases, testCase{
4574 testType: clientTest,
4575 name: "UnknownExtension-Client",
4576 config: Config{
4577 Bugs: ProtocolBugs{
4578 CustomExtension: expectedContents,
4579 },
4580 },
4581 shouldFail: true,
4582 expectedError: ":UNEXPECTED_EXTENSION:",
4583 })
Adam Langley09505632015-07-30 18:10:13 -07004584}
4585
David Benjaminb36a3952015-12-01 18:53:13 -05004586func addRSAClientKeyExchangeTests() {
4587 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
4588 testCases = append(testCases, testCase{
4589 testType: serverTest,
4590 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
4591 config: Config{
4592 // Ensure the ClientHello version and final
4593 // version are different, to detect if the
4594 // server uses the wrong one.
4595 MaxVersion: VersionTLS11,
4596 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4597 Bugs: ProtocolBugs{
4598 BadRSAClientKeyExchange: bad,
4599 },
4600 },
4601 shouldFail: true,
4602 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
4603 })
4604 }
4605}
4606
Adam Langley7c803a62015-06-15 15:35:05 -07004607func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004608 defer wg.Done()
4609
4610 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004611 var err error
4612
4613 if *mallocTest < 0 {
4614 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004615 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004616 } else {
4617 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4618 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004619 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004620 if err != nil {
4621 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4622 }
4623 break
4624 }
4625 }
4626 }
Adam Langley95c29f32014-06-20 12:00:00 -07004627 statusChan <- statusMsg{test: test, err: err}
4628 }
4629}
4630
4631type statusMsg struct {
4632 test *testCase
4633 started bool
4634 err error
4635}
4636
David Benjamin5f237bc2015-02-11 17:14:15 -05004637func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004638 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004639
David Benjamin5f237bc2015-02-11 17:14:15 -05004640 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004641 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004642 if !*pipe {
4643 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004644 var erase string
4645 for i := 0; i < lineLen; i++ {
4646 erase += "\b \b"
4647 }
4648 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004649 }
4650
Adam Langley95c29f32014-06-20 12:00:00 -07004651 if msg.started {
4652 started++
4653 } else {
4654 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004655
4656 if msg.err != nil {
4657 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4658 failed++
4659 testOutput.addResult(msg.test.name, "FAIL")
4660 } else {
4661 if *pipe {
4662 // Print each test instead of a status line.
4663 fmt.Printf("PASSED (%s)\n", msg.test.name)
4664 }
4665 testOutput.addResult(msg.test.name, "PASS")
4666 }
Adam Langley95c29f32014-06-20 12:00:00 -07004667 }
4668
David Benjamin5f237bc2015-02-11 17:14:15 -05004669 if !*pipe {
4670 // Print a new status line.
4671 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4672 lineLen = len(line)
4673 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004674 }
Adam Langley95c29f32014-06-20 12:00:00 -07004675 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004676
4677 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004678}
4679
4680func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004681 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004682 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004683
Adam Langley7c803a62015-06-15 15:35:05 -07004684 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004685 addCipherSuiteTests()
4686 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004687 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004688 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004689 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004690 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004691 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004692 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004693 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004694 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004695 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004696 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004697 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004698 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004699 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004700 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004701 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004702 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05004703 addRSAClientKeyExchangeTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004704 for _, async := range []bool{false, true} {
4705 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004706 for _, protocol := range []protocol{tls, dtls} {
4707 addStateMachineCoverageTests(async, splitHandshake, protocol)
4708 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004709 }
4710 }
Adam Langley95c29f32014-06-20 12:00:00 -07004711
4712 var wg sync.WaitGroup
4713
Adam Langley7c803a62015-06-15 15:35:05 -07004714 statusChan := make(chan statusMsg, *numWorkers)
4715 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004716 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004717
David Benjamin025b3d32014-07-01 19:53:04 -04004718 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004719
Adam Langley7c803a62015-06-15 15:35:05 -07004720 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004721 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004722 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004723 }
4724
David Benjamin025b3d32014-07-01 19:53:04 -04004725 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004726 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004727 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004728 }
4729 }
4730
4731 close(testChan)
4732 wg.Wait()
4733 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004734 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004735
4736 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004737
4738 if *jsonOutput != "" {
4739 if err := testOutput.writeTo(*jsonOutput); err != nil {
4740 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4741 }
4742 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004743
4744 if !testOutput.allPassed {
4745 os.Exit(1)
4746 }
Adam Langley95c29f32014-06-20 12:00:00 -07004747}