blob: 19a9dac8d6c2616605cf4c0327b19aead5504fb1 [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,
997 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
998 },
999 {
1000 testType: serverTest,
1001 name: "SkipChangeCipherSpec-Server",
1002 config: Config{
1003 Bugs: ProtocolBugs{
1004 SkipChangeCipherSpec: true,
1005 },
1006 },
1007 shouldFail: true,
1008 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1009 },
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,
1023 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1024 },
1025 {
1026 name: "FragmentAcrossChangeCipherSpec-Client",
1027 config: Config{
1028 Bugs: ProtocolBugs{
1029 FragmentAcrossChangeCipherSpec: true,
1030 },
1031 },
1032 shouldFail: true,
1033 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1034 },
1035 {
1036 testType: serverTest,
1037 name: "FragmentAcrossChangeCipherSpec-Server",
1038 config: Config{
1039 Bugs: ProtocolBugs{
1040 FragmentAcrossChangeCipherSpec: true,
1041 },
1042 },
1043 shouldFail: true,
1044 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1045 },
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,
1059 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1060 },
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,
1118 expectedError: ":CCS_RECEIVED_EARLY:",
1119 },
1120 {
1121 testType: serverTest,
1122 name: "EarlyChangeCipherSpec-server-2",
1123 config: Config{
1124 Bugs: ProtocolBugs{
1125 EarlyChangeCipherSpec: 2,
1126 },
1127 },
1128 shouldFail: true,
1129 expectedError: ":CCS_RECEIVED_EARLY:",
1130 },
1131 {
1132 name: "SkipNewSessionTicket",
1133 config: Config{
1134 Bugs: ProtocolBugs{
1135 SkipNewSessionTicket: true,
1136 },
1137 },
1138 shouldFail: true,
1139 expectedError: ":CCS_RECEIVED_EARLY:",
1140 },
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,
1416 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1417 },
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,
1426 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1427 },
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 },
Adam Langley7c803a62015-06-15 15:35:05 -07001998 }
Adam Langley7c803a62015-06-15 15:35:05 -07001999 testCases = append(testCases, basicTests...)
2000}
2001
Adam Langley95c29f32014-06-20 12:00:00 -07002002func addCipherSuiteTests() {
2003 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002004 const psk = "12345"
2005 const pskIdentity = "luggage combo"
2006
Adam Langley95c29f32014-06-20 12:00:00 -07002007 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002008 var certFile string
2009 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002010 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002011 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002012 certFile = ecdsaCertificateFile
2013 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002014 } else {
2015 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002016 certFile = rsaCertificateFile
2017 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002018 }
2019
David Benjamin48cae082014-10-27 01:06:24 -04002020 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002021 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002022 flags = append(flags,
2023 "-psk", psk,
2024 "-psk-identity", pskIdentity)
2025 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002026 if hasComponent(suite.name, "NULL") {
2027 // NULL ciphers must be explicitly enabled.
2028 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2029 }
David Benjamin48cae082014-10-27 01:06:24 -04002030
Adam Langley95c29f32014-06-20 12:00:00 -07002031 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002032 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002033 continue
2034 }
2035
David Benjamin025b3d32014-07-01 19:53:04 -04002036 testCases = append(testCases, testCase{
2037 testType: clientTest,
2038 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002039 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002040 MinVersion: ver.version,
2041 MaxVersion: ver.version,
2042 CipherSuites: []uint16{suite.id},
2043 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002044 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002045 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002046 },
David Benjamin48cae082014-10-27 01:06:24 -04002047 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002048 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002049 })
David Benjamin025b3d32014-07-01 19:53:04 -04002050
David Benjamin76d8abe2014-08-14 16:25:34 -04002051 testCases = append(testCases, testCase{
2052 testType: serverTest,
2053 name: ver.name + "-" + suite.name + "-server",
2054 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002055 MinVersion: ver.version,
2056 MaxVersion: ver.version,
2057 CipherSuites: []uint16{suite.id},
2058 Certificates: []Certificate{cert},
2059 PreSharedKey: []byte(psk),
2060 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002061 },
2062 certFile: certFile,
2063 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002064 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002065 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002066 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002067
David Benjamin8b8c0062014-11-23 02:47:52 -05002068 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002069 testCases = append(testCases, testCase{
2070 testType: clientTest,
2071 protocol: dtls,
2072 name: "D" + ver.name + "-" + suite.name + "-client",
2073 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002074 MinVersion: ver.version,
2075 MaxVersion: ver.version,
2076 CipherSuites: []uint16{suite.id},
2077 Certificates: []Certificate{cert},
2078 PreSharedKey: []byte(psk),
2079 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002080 },
David Benjamin48cae082014-10-27 01:06:24 -04002081 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002082 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002083 })
2084 testCases = append(testCases, testCase{
2085 testType: serverTest,
2086 protocol: dtls,
2087 name: "D" + ver.name + "-" + suite.name + "-server",
2088 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002089 MinVersion: ver.version,
2090 MaxVersion: ver.version,
2091 CipherSuites: []uint16{suite.id},
2092 Certificates: []Certificate{cert},
2093 PreSharedKey: []byte(psk),
2094 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002095 },
2096 certFile: certFile,
2097 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002098 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002099 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002100 })
2101 }
Adam Langley95c29f32014-06-20 12:00:00 -07002102 }
David Benjamin2c99d282015-09-01 10:23:00 -04002103
2104 // Ensure both TLS and DTLS accept their maximum record sizes.
2105 testCases = append(testCases, testCase{
2106 name: suite.name + "-LargeRecord",
2107 config: Config{
2108 CipherSuites: []uint16{suite.id},
2109 Certificates: []Certificate{cert},
2110 PreSharedKey: []byte(psk),
2111 PreSharedKeyIdentity: pskIdentity,
2112 },
2113 flags: flags,
2114 messageLen: maxPlaintext,
2115 })
David Benjamin2c99d282015-09-01 10:23:00 -04002116 if isDTLSCipher(suite.name) {
2117 testCases = append(testCases, testCase{
2118 protocol: dtls,
2119 name: suite.name + "-LargeRecord-DTLS",
2120 config: Config{
2121 CipherSuites: []uint16{suite.id},
2122 Certificates: []Certificate{cert},
2123 PreSharedKey: []byte(psk),
2124 PreSharedKeyIdentity: pskIdentity,
2125 },
2126 flags: flags,
2127 messageLen: maxPlaintext,
2128 })
2129 }
Adam Langley95c29f32014-06-20 12:00:00 -07002130 }
Adam Langleya7997f12015-05-14 17:38:50 -07002131
2132 testCases = append(testCases, testCase{
2133 name: "WeakDH",
2134 config: Config{
2135 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2136 Bugs: ProtocolBugs{
2137 // This is a 1023-bit prime number, generated
2138 // with:
2139 // openssl gendh 1023 | openssl asn1parse -i
2140 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2141 },
2142 },
2143 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002144 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002145 })
Adam Langleycef75832015-09-03 14:51:12 -07002146
David Benjamincd24a392015-11-11 13:23:05 -08002147 testCases = append(testCases, testCase{
2148 name: "SillyDH",
2149 config: Config{
2150 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2151 Bugs: ProtocolBugs{
2152 // This is a 4097-bit prime number, generated
2153 // with:
2154 // openssl gendh 4097 | openssl asn1parse -i
2155 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2156 },
2157 },
2158 shouldFail: true,
2159 expectedError: ":DH_P_TOO_LONG:",
2160 })
2161
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002162 // This test ensures that Diffie-Hellman public values are padded with
2163 // zeros so that they're the same length as the prime. This is to avoid
2164 // hitting a bug in yaSSL.
2165 testCases = append(testCases, testCase{
2166 testType: serverTest,
2167 name: "DHPublicValuePadded",
2168 config: Config{
2169 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2170 Bugs: ProtocolBugs{
2171 RequireDHPublicValueLen: (1025 + 7) / 8,
2172 },
2173 },
2174 flags: []string{"-use-sparse-dh-prime"},
2175 })
David Benjamincd24a392015-11-11 13:23:05 -08002176
Adam Langleycef75832015-09-03 14:51:12 -07002177 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2178 // 1.1 specific cipher suite settings. A server is setup with the given
2179 // cipher lists and then a connection is made for each member of
2180 // expectations. The cipher suite that the server selects must match
2181 // the specified one.
2182 var versionSpecificCiphersTest = []struct {
2183 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2184 // expectations is a map from TLS version to cipher suite id.
2185 expectations map[uint16]uint16
2186 }{
2187 {
2188 // Test that the null case (where no version-specific ciphers are set)
2189 // works as expected.
2190 "RC4-SHA:AES128-SHA", // default ciphers
2191 "", // no ciphers specifically for TLS ≥ 1.0
2192 "", // no ciphers specifically for TLS ≥ 1.1
2193 map[uint16]uint16{
2194 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2195 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2196 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2197 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2198 },
2199 },
2200 {
2201 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2202 // cipher.
2203 "RC4-SHA:AES128-SHA", // default
2204 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2205 "", // no ciphers specifically for TLS ≥ 1.1
2206 map[uint16]uint16{
2207 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2208 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2209 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2210 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2211 },
2212 },
2213 {
2214 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2215 // cipher.
2216 "RC4-SHA:AES128-SHA", // default
2217 "", // no ciphers specifically for TLS ≥ 1.0
2218 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2219 map[uint16]uint16{
2220 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2221 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2222 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2223 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2224 },
2225 },
2226 {
2227 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2228 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2229 "RC4-SHA:AES128-SHA", // default
2230 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2231 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2232 map[uint16]uint16{
2233 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2234 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2235 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2236 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2237 },
2238 },
2239 }
2240
2241 for i, test := range versionSpecificCiphersTest {
2242 for version, expectedCipherSuite := range test.expectations {
2243 flags := []string{"-cipher", test.ciphersDefault}
2244 if len(test.ciphersTLS10) > 0 {
2245 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2246 }
2247 if len(test.ciphersTLS11) > 0 {
2248 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2249 }
2250
2251 testCases = append(testCases, testCase{
2252 testType: serverTest,
2253 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2254 config: Config{
2255 MaxVersion: version,
2256 MinVersion: version,
2257 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2258 },
2259 flags: flags,
2260 expectedCipher: expectedCipherSuite,
2261 })
2262 }
2263 }
Adam Langley95c29f32014-06-20 12:00:00 -07002264}
2265
2266func addBadECDSASignatureTests() {
2267 for badR := BadValue(1); badR < NumBadValues; badR++ {
2268 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002269 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002270 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2271 config: Config{
2272 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2273 Certificates: []Certificate{getECDSACertificate()},
2274 Bugs: ProtocolBugs{
2275 BadECDSAR: badR,
2276 BadECDSAS: badS,
2277 },
2278 },
2279 shouldFail: true,
2280 expectedError: "SIGNATURE",
2281 })
2282 }
2283 }
2284}
2285
Adam Langley80842bd2014-06-20 12:00:00 -07002286func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002287 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002288 name: "MaxCBCPadding",
2289 config: Config{
2290 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2291 Bugs: ProtocolBugs{
2292 MaxPadding: true,
2293 },
2294 },
2295 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2296 })
David Benjamin025b3d32014-07-01 19:53:04 -04002297 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002298 name: "BadCBCPadding",
2299 config: Config{
2300 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2301 Bugs: ProtocolBugs{
2302 PaddingFirstByteBad: true,
2303 },
2304 },
2305 shouldFail: true,
2306 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2307 })
2308 // OpenSSL previously had an issue where the first byte of padding in
2309 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002310 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002311 name: "BadCBCPadding255",
2312 config: Config{
2313 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2314 Bugs: ProtocolBugs{
2315 MaxPadding: true,
2316 PaddingFirstByteBadIf255: true,
2317 },
2318 },
2319 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2320 shouldFail: true,
2321 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2322 })
2323}
2324
Kenny Root7fdeaf12014-08-05 15:23:37 -07002325func addCBCSplittingTests() {
2326 testCases = append(testCases, testCase{
2327 name: "CBCRecordSplitting",
2328 config: Config{
2329 MaxVersion: VersionTLS10,
2330 MinVersion: VersionTLS10,
2331 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2332 },
David Benjaminac8302a2015-09-01 17:18:15 -04002333 messageLen: -1, // read until EOF
2334 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002335 flags: []string{
2336 "-async",
2337 "-write-different-record-sizes",
2338 "-cbc-record-splitting",
2339 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002340 })
2341 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002342 name: "CBCRecordSplittingPartialWrite",
2343 config: Config{
2344 MaxVersion: VersionTLS10,
2345 MinVersion: VersionTLS10,
2346 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2347 },
2348 messageLen: -1, // read until EOF
2349 flags: []string{
2350 "-async",
2351 "-write-different-record-sizes",
2352 "-cbc-record-splitting",
2353 "-partial-write",
2354 },
2355 })
2356}
2357
David Benjamin636293b2014-07-08 17:59:18 -04002358func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002359 // Add a dummy cert pool to stress certificate authority parsing.
2360 // TODO(davidben): Add tests that those values parse out correctly.
2361 certPool := x509.NewCertPool()
2362 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2363 if err != nil {
2364 panic(err)
2365 }
2366 certPool.AddCert(cert)
2367
David Benjamin636293b2014-07-08 17:59:18 -04002368 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002369 testCases = append(testCases, testCase{
2370 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002371 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002372 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002373 MinVersion: ver.version,
2374 MaxVersion: ver.version,
2375 ClientAuth: RequireAnyClientCert,
2376 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002377 },
2378 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002379 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2380 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002381 },
2382 })
2383 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002384 testType: serverTest,
2385 name: ver.name + "-Server-ClientAuth-RSA",
2386 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002387 MinVersion: ver.version,
2388 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002389 Certificates: []Certificate{rsaCertificate},
2390 },
2391 flags: []string{"-require-any-client-certificate"},
2392 })
David Benjamine098ec22014-08-27 23:13:20 -04002393 if ver.version != VersionSSL30 {
2394 testCases = append(testCases, testCase{
2395 testType: serverTest,
2396 name: ver.name + "-Server-ClientAuth-ECDSA",
2397 config: Config{
2398 MinVersion: ver.version,
2399 MaxVersion: ver.version,
2400 Certificates: []Certificate{ecdsaCertificate},
2401 },
2402 flags: []string{"-require-any-client-certificate"},
2403 })
2404 testCases = append(testCases, testCase{
2405 testType: clientTest,
2406 name: ver.name + "-Client-ClientAuth-ECDSA",
2407 config: Config{
2408 MinVersion: ver.version,
2409 MaxVersion: ver.version,
2410 ClientAuth: RequireAnyClientCert,
2411 ClientCAs: certPool,
2412 },
2413 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002414 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2415 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002416 },
2417 })
2418 }
David Benjamin636293b2014-07-08 17:59:18 -04002419 }
2420}
2421
Adam Langley75712922014-10-10 16:23:43 -07002422func addExtendedMasterSecretTests() {
2423 const expectEMSFlag = "-expect-extended-master-secret"
2424
2425 for _, with := range []bool{false, true} {
2426 prefix := "No"
2427 var flags []string
2428 if with {
2429 prefix = ""
2430 flags = []string{expectEMSFlag}
2431 }
2432
2433 for _, isClient := range []bool{false, true} {
2434 suffix := "-Server"
2435 testType := serverTest
2436 if isClient {
2437 suffix = "-Client"
2438 testType = clientTest
2439 }
2440
2441 for _, ver := range tlsVersions {
2442 test := testCase{
2443 testType: testType,
2444 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2445 config: Config{
2446 MinVersion: ver.version,
2447 MaxVersion: ver.version,
2448 Bugs: ProtocolBugs{
2449 NoExtendedMasterSecret: !with,
2450 RequireExtendedMasterSecret: with,
2451 },
2452 },
David Benjamin48cae082014-10-27 01:06:24 -04002453 flags: flags,
2454 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002455 }
2456 if test.shouldFail {
2457 test.expectedLocalError = "extended master secret required but not supported by peer"
2458 }
2459 testCases = append(testCases, test)
2460 }
2461 }
2462 }
2463
Adam Langleyba5934b2015-06-02 10:50:35 -07002464 for _, isClient := range []bool{false, true} {
2465 for _, supportedInFirstConnection := range []bool{false, true} {
2466 for _, supportedInResumeConnection := range []bool{false, true} {
2467 boolToWord := func(b bool) string {
2468 if b {
2469 return "Yes"
2470 }
2471 return "No"
2472 }
2473 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2474 if isClient {
2475 suffix += "Client"
2476 } else {
2477 suffix += "Server"
2478 }
2479
2480 supportedConfig := Config{
2481 Bugs: ProtocolBugs{
2482 RequireExtendedMasterSecret: true,
2483 },
2484 }
2485
2486 noSupportConfig := Config{
2487 Bugs: ProtocolBugs{
2488 NoExtendedMasterSecret: true,
2489 },
2490 }
2491
2492 test := testCase{
2493 name: "ExtendedMasterSecret-" + suffix,
2494 resumeSession: true,
2495 }
2496
2497 if !isClient {
2498 test.testType = serverTest
2499 }
2500
2501 if supportedInFirstConnection {
2502 test.config = supportedConfig
2503 } else {
2504 test.config = noSupportConfig
2505 }
2506
2507 if supportedInResumeConnection {
2508 test.resumeConfig = &supportedConfig
2509 } else {
2510 test.resumeConfig = &noSupportConfig
2511 }
2512
2513 switch suffix {
2514 case "YesToYes-Client", "YesToYes-Server":
2515 // When a session is resumed, it should
2516 // still be aware that its master
2517 // secret was generated via EMS and
2518 // thus it's safe to use tls-unique.
2519 test.flags = []string{expectEMSFlag}
2520 case "NoToYes-Server":
2521 // If an original connection did not
2522 // contain EMS, but a resumption
2523 // handshake does, then a server should
2524 // not resume the session.
2525 test.expectResumeRejected = true
2526 case "YesToNo-Server":
2527 // Resuming an EMS session without the
2528 // EMS extension should cause the
2529 // server to abort the connection.
2530 test.shouldFail = true
2531 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2532 case "NoToYes-Client":
2533 // A client should abort a connection
2534 // where the server resumed a non-EMS
2535 // session but echoed the EMS
2536 // extension.
2537 test.shouldFail = true
2538 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2539 case "YesToNo-Client":
2540 // A client should abort a connection
2541 // where the server didn't echo EMS
2542 // when the session used it.
2543 test.shouldFail = true
2544 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2545 }
2546
2547 testCases = append(testCases, test)
2548 }
2549 }
2550 }
Adam Langley75712922014-10-10 16:23:43 -07002551}
2552
David Benjamin43ec06f2014-08-05 02:28:57 -04002553// Adds tests that try to cover the range of the handshake state machine, under
2554// various conditions. Some of these are redundant with other tests, but they
2555// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002556func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002557 var tests []testCase
2558
2559 // Basic handshake, with resumption. Client and server,
2560 // session ID and session ticket.
2561 tests = append(tests, testCase{
2562 name: "Basic-Client",
2563 resumeSession: true,
2564 })
2565 tests = append(tests, testCase{
2566 name: "Basic-Client-RenewTicket",
2567 config: Config{
2568 Bugs: ProtocolBugs{
2569 RenewTicketOnResume: true,
2570 },
2571 },
David Benjaminba4594a2015-06-18 18:36:15 -04002572 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002573 resumeSession: true,
2574 })
2575 tests = append(tests, testCase{
2576 name: "Basic-Client-NoTicket",
2577 config: Config{
2578 SessionTicketsDisabled: true,
2579 },
2580 resumeSession: true,
2581 })
2582 tests = append(tests, testCase{
2583 name: "Basic-Client-Implicit",
2584 flags: []string{"-implicit-handshake"},
2585 resumeSession: true,
2586 })
2587 tests = append(tests, testCase{
2588 testType: serverTest,
2589 name: "Basic-Server",
2590 resumeSession: true,
2591 })
2592 tests = append(tests, testCase{
2593 testType: serverTest,
2594 name: "Basic-Server-NoTickets",
2595 config: Config{
2596 SessionTicketsDisabled: true,
2597 },
2598 resumeSession: true,
2599 })
2600 tests = append(tests, testCase{
2601 testType: serverTest,
2602 name: "Basic-Server-Implicit",
2603 flags: []string{"-implicit-handshake"},
2604 resumeSession: true,
2605 })
2606 tests = append(tests, testCase{
2607 testType: serverTest,
2608 name: "Basic-Server-EarlyCallback",
2609 flags: []string{"-use-early-callback"},
2610 resumeSession: true,
2611 })
2612
2613 // TLS client auth.
2614 tests = append(tests, testCase{
2615 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002616 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002617 config: Config{
2618 ClientAuth: RequireAnyClientCert,
2619 },
2620 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002621 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2622 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002623 },
2624 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002625 tests = append(tests, testCase{
2626 testType: clientTest,
2627 name: "ClientAuth-ECDSA-Client",
2628 config: Config{
2629 ClientAuth: RequireAnyClientCert,
2630 },
2631 flags: []string{
2632 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2633 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2634 },
2635 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002636 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002637 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002638 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002639 testType: serverTest,
2640 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002641 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002642 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002643 },
2644 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002645 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2646 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002647 },
2648 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002649 tests = append(tests, testCase{
2650 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002651 name: "Basic-Server-ECDHE-RSA",
2652 config: Config{
2653 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2654 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002655 flags: []string{
2656 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2657 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002658 },
2659 })
2660 tests = append(tests, testCase{
2661 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002662 name: "Basic-Server-ECDHE-ECDSA",
2663 config: Config{
2664 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2665 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002666 flags: []string{
2667 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2668 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002669 },
2670 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002671 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002672 tests = append(tests, testCase{
2673 testType: serverTest,
2674 name: "ClientAuth-Server",
2675 config: Config{
2676 Certificates: []Certificate{rsaCertificate},
2677 },
2678 flags: []string{"-require-any-client-certificate"},
2679 })
2680
2681 // No session ticket support; server doesn't send NewSessionTicket.
2682 tests = append(tests, testCase{
2683 name: "SessionTicketsDisabled-Client",
2684 config: Config{
2685 SessionTicketsDisabled: true,
2686 },
2687 })
2688 tests = append(tests, testCase{
2689 testType: serverTest,
2690 name: "SessionTicketsDisabled-Server",
2691 config: Config{
2692 SessionTicketsDisabled: true,
2693 },
2694 })
2695
2696 // Skip ServerKeyExchange in PSK key exchange if there's no
2697 // identity hint.
2698 tests = append(tests, testCase{
2699 name: "EmptyPSKHint-Client",
2700 config: Config{
2701 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2702 PreSharedKey: []byte("secret"),
2703 },
2704 flags: []string{"-psk", "secret"},
2705 })
2706 tests = append(tests, testCase{
2707 testType: serverTest,
2708 name: "EmptyPSKHint-Server",
2709 config: Config{
2710 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2711 PreSharedKey: []byte("secret"),
2712 },
2713 flags: []string{"-psk", "secret"},
2714 })
2715
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002716 tests = append(tests, testCase{
2717 testType: clientTest,
2718 name: "OCSPStapling-Client",
2719 flags: []string{
2720 "-enable-ocsp-stapling",
2721 "-expect-ocsp-response",
2722 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002723 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002724 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002725 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002726 })
2727
2728 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002729 testType: serverTest,
2730 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002731 expectedOCSPResponse: testOCSPResponse,
2732 flags: []string{
2733 "-ocsp-response",
2734 base64.StdEncoding.EncodeToString(testOCSPResponse),
2735 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002736 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002737 })
2738
Paul Lietar8f1c2682015-08-18 12:21:54 +01002739 tests = append(tests, testCase{
2740 testType: clientTest,
2741 name: "CertificateVerificationSucceed",
2742 flags: []string{
2743 "-verify-peer",
2744 },
2745 })
2746
2747 tests = append(tests, testCase{
2748 testType: clientTest,
2749 name: "CertificateVerificationFail",
2750 flags: []string{
2751 "-verify-fail",
2752 "-verify-peer",
2753 },
2754 shouldFail: true,
2755 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2756 })
2757
2758 tests = append(tests, testCase{
2759 testType: clientTest,
2760 name: "CertificateVerificationSoftFail",
2761 flags: []string{
2762 "-verify-fail",
2763 "-expect-verify-result",
2764 },
2765 })
2766
David Benjamin760b1dd2015-05-15 23:33:48 -04002767 if protocol == tls {
2768 tests = append(tests, testCase{
2769 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002770 renegotiate: 1,
2771 flags: []string{
2772 "-renegotiate-freely",
2773 "-expect-total-renegotiations", "1",
2774 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002775 })
2776 // NPN on client and server; results in post-handshake message.
2777 tests = append(tests, testCase{
2778 name: "NPN-Client",
2779 config: Config{
2780 NextProtos: []string{"foo"},
2781 },
2782 flags: []string{"-select-next-proto", "foo"},
2783 expectedNextProto: "foo",
2784 expectedNextProtoType: npn,
2785 })
2786 tests = append(tests, testCase{
2787 testType: serverTest,
2788 name: "NPN-Server",
2789 config: Config{
2790 NextProtos: []string{"bar"},
2791 },
2792 flags: []string{
2793 "-advertise-npn", "\x03foo\x03bar\x03baz",
2794 "-expect-next-proto", "bar",
2795 },
2796 expectedNextProto: "bar",
2797 expectedNextProtoType: npn,
2798 })
2799
2800 // TODO(davidben): Add tests for when False Start doesn't trigger.
2801
2802 // Client does False Start and negotiates NPN.
2803 tests = append(tests, testCase{
2804 name: "FalseStart",
2805 config: Config{
2806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2807 NextProtos: []string{"foo"},
2808 Bugs: ProtocolBugs{
2809 ExpectFalseStart: true,
2810 },
2811 },
2812 flags: []string{
2813 "-false-start",
2814 "-select-next-proto", "foo",
2815 },
2816 shimWritesFirst: true,
2817 resumeSession: true,
2818 })
2819
2820 // Client does False Start and negotiates ALPN.
2821 tests = append(tests, testCase{
2822 name: "FalseStart-ALPN",
2823 config: Config{
2824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2825 NextProtos: []string{"foo"},
2826 Bugs: ProtocolBugs{
2827 ExpectFalseStart: true,
2828 },
2829 },
2830 flags: []string{
2831 "-false-start",
2832 "-advertise-alpn", "\x03foo",
2833 },
2834 shimWritesFirst: true,
2835 resumeSession: true,
2836 })
2837
2838 // Client does False Start but doesn't explicitly call
2839 // SSL_connect.
2840 tests = append(tests, testCase{
2841 name: "FalseStart-Implicit",
2842 config: Config{
2843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2844 NextProtos: []string{"foo"},
2845 },
2846 flags: []string{
2847 "-implicit-handshake",
2848 "-false-start",
2849 "-advertise-alpn", "\x03foo",
2850 },
2851 })
2852
2853 // False Start without session tickets.
2854 tests = append(tests, testCase{
2855 name: "FalseStart-SessionTicketsDisabled",
2856 config: Config{
2857 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2858 NextProtos: []string{"foo"},
2859 SessionTicketsDisabled: true,
2860 Bugs: ProtocolBugs{
2861 ExpectFalseStart: true,
2862 },
2863 },
2864 flags: []string{
2865 "-false-start",
2866 "-select-next-proto", "foo",
2867 },
2868 shimWritesFirst: true,
2869 })
2870
2871 // Server parses a V2ClientHello.
2872 tests = append(tests, testCase{
2873 testType: serverTest,
2874 name: "SendV2ClientHello",
2875 config: Config{
2876 // Choose a cipher suite that does not involve
2877 // elliptic curves, so no extensions are
2878 // involved.
2879 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2880 Bugs: ProtocolBugs{
2881 SendV2ClientHello: true,
2882 },
2883 },
2884 })
2885
2886 // Client sends a Channel ID.
2887 tests = append(tests, testCase{
2888 name: "ChannelID-Client",
2889 config: Config{
2890 RequestChannelID: true,
2891 },
Adam Langley7c803a62015-06-15 15:35:05 -07002892 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002893 resumeSession: true,
2894 expectChannelID: true,
2895 })
2896
2897 // Server accepts a Channel ID.
2898 tests = append(tests, testCase{
2899 testType: serverTest,
2900 name: "ChannelID-Server",
2901 config: Config{
2902 ChannelID: channelIDKey,
2903 },
2904 flags: []string{
2905 "-expect-channel-id",
2906 base64.StdEncoding.EncodeToString(channelIDBytes),
2907 },
2908 resumeSession: true,
2909 expectChannelID: true,
2910 })
David Benjamin30789da2015-08-29 22:56:45 -04002911
2912 // Bidirectional shutdown with the runner initiating.
2913 tests = append(tests, testCase{
2914 name: "Shutdown-Runner",
2915 config: Config{
2916 Bugs: ProtocolBugs{
2917 ExpectCloseNotify: true,
2918 },
2919 },
2920 flags: []string{"-check-close-notify"},
2921 })
2922
2923 // Bidirectional shutdown with the shim initiating. The runner,
2924 // in the meantime, sends garbage before the close_notify which
2925 // the shim must ignore.
2926 tests = append(tests, testCase{
2927 name: "Shutdown-Shim",
2928 config: Config{
2929 Bugs: ProtocolBugs{
2930 ExpectCloseNotify: true,
2931 },
2932 },
2933 shimShutsDown: true,
2934 sendEmptyRecords: 1,
2935 sendWarningAlerts: 1,
2936 flags: []string{"-check-close-notify"},
2937 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002938 } else {
2939 tests = append(tests, testCase{
2940 name: "SkipHelloVerifyRequest",
2941 config: Config{
2942 Bugs: ProtocolBugs{
2943 SkipHelloVerifyRequest: true,
2944 },
2945 },
2946 })
2947 }
2948
David Benjamin760b1dd2015-05-15 23:33:48 -04002949 for _, test := range tests {
2950 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05002951 if protocol == dtls {
2952 test.name += "-DTLS"
2953 }
2954 if async {
2955 test.name += "-Async"
2956 test.flags = append(test.flags, "-async")
2957 } else {
2958 test.name += "-Sync"
2959 }
2960 if splitHandshake {
2961 test.name += "-SplitHandshakeRecords"
2962 test.config.Bugs.MaxHandshakeRecordLength = 1
2963 if protocol == dtls {
2964 test.config.Bugs.MaxPacketLength = 256
2965 test.flags = append(test.flags, "-mtu", "256")
2966 }
2967 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002968 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002969 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002970}
2971
Adam Langley524e7172015-02-20 16:04:00 -08002972func addDDoSCallbackTests() {
2973 // DDoS callback.
2974
2975 for _, resume := range []bool{false, true} {
2976 suffix := "Resume"
2977 if resume {
2978 suffix = "No" + suffix
2979 }
2980
2981 testCases = append(testCases, testCase{
2982 testType: serverTest,
2983 name: "Server-DDoS-OK-" + suffix,
2984 flags: []string{"-install-ddos-callback"},
2985 resumeSession: resume,
2986 })
2987
2988 failFlag := "-fail-ddos-callback"
2989 if resume {
2990 failFlag = "-fail-second-ddos-callback"
2991 }
2992 testCases = append(testCases, testCase{
2993 testType: serverTest,
2994 name: "Server-DDoS-Reject-" + suffix,
2995 flags: []string{"-install-ddos-callback", failFlag},
2996 resumeSession: resume,
2997 shouldFail: true,
2998 expectedError: ":CONNECTION_REJECTED:",
2999 })
3000 }
3001}
3002
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003003func addVersionNegotiationTests() {
3004 for i, shimVers := range tlsVersions {
3005 // Assemble flags to disable all newer versions on the shim.
3006 var flags []string
3007 for _, vers := range tlsVersions[i+1:] {
3008 flags = append(flags, vers.flag)
3009 }
3010
3011 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003012 protocols := []protocol{tls}
3013 if runnerVers.hasDTLS && shimVers.hasDTLS {
3014 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003015 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003016 for _, protocol := range protocols {
3017 expectedVersion := shimVers.version
3018 if runnerVers.version < shimVers.version {
3019 expectedVersion = runnerVers.version
3020 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003021
David Benjamin8b8c0062014-11-23 02:47:52 -05003022 suffix := shimVers.name + "-" + runnerVers.name
3023 if protocol == dtls {
3024 suffix += "-DTLS"
3025 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003026
David Benjamin1eb367c2014-12-12 18:17:51 -05003027 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3028
David Benjamin1e29a6b2014-12-10 02:27:24 -05003029 clientVers := shimVers.version
3030 if clientVers > VersionTLS10 {
3031 clientVers = VersionTLS10
3032 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003033 testCases = append(testCases, testCase{
3034 protocol: protocol,
3035 testType: clientTest,
3036 name: "VersionNegotiation-Client-" + suffix,
3037 config: Config{
3038 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003039 Bugs: ProtocolBugs{
3040 ExpectInitialRecordVersion: clientVers,
3041 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003042 },
3043 flags: flags,
3044 expectedVersion: expectedVersion,
3045 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003046 testCases = append(testCases, testCase{
3047 protocol: protocol,
3048 testType: clientTest,
3049 name: "VersionNegotiation-Client2-" + suffix,
3050 config: Config{
3051 MaxVersion: runnerVers.version,
3052 Bugs: ProtocolBugs{
3053 ExpectInitialRecordVersion: clientVers,
3054 },
3055 },
3056 flags: []string{"-max-version", shimVersFlag},
3057 expectedVersion: expectedVersion,
3058 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003059
3060 testCases = append(testCases, testCase{
3061 protocol: protocol,
3062 testType: serverTest,
3063 name: "VersionNegotiation-Server-" + suffix,
3064 config: Config{
3065 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003066 Bugs: ProtocolBugs{
3067 ExpectInitialRecordVersion: expectedVersion,
3068 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003069 },
3070 flags: flags,
3071 expectedVersion: expectedVersion,
3072 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003073 testCases = append(testCases, testCase{
3074 protocol: protocol,
3075 testType: serverTest,
3076 name: "VersionNegotiation-Server2-" + suffix,
3077 config: Config{
3078 MaxVersion: runnerVers.version,
3079 Bugs: ProtocolBugs{
3080 ExpectInitialRecordVersion: expectedVersion,
3081 },
3082 },
3083 flags: []string{"-max-version", shimVersFlag},
3084 expectedVersion: expectedVersion,
3085 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003086 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003087 }
3088 }
3089}
3090
David Benjaminaccb4542014-12-12 23:44:33 -05003091func addMinimumVersionTests() {
3092 for i, shimVers := range tlsVersions {
3093 // Assemble flags to disable all older versions on the shim.
3094 var flags []string
3095 for _, vers := range tlsVersions[:i] {
3096 flags = append(flags, vers.flag)
3097 }
3098
3099 for _, runnerVers := range tlsVersions {
3100 protocols := []protocol{tls}
3101 if runnerVers.hasDTLS && shimVers.hasDTLS {
3102 protocols = append(protocols, dtls)
3103 }
3104 for _, protocol := range protocols {
3105 suffix := shimVers.name + "-" + runnerVers.name
3106 if protocol == dtls {
3107 suffix += "-DTLS"
3108 }
3109 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3110
David Benjaminaccb4542014-12-12 23:44:33 -05003111 var expectedVersion uint16
3112 var shouldFail bool
3113 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003114 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003115 if runnerVers.version >= shimVers.version {
3116 expectedVersion = runnerVers.version
3117 } else {
3118 shouldFail = true
3119 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003120 if runnerVers.version > VersionSSL30 {
3121 expectedLocalError = "remote error: protocol version not supported"
3122 } else {
3123 expectedLocalError = "remote error: handshake failure"
3124 }
David Benjaminaccb4542014-12-12 23:44:33 -05003125 }
3126
3127 testCases = append(testCases, testCase{
3128 protocol: protocol,
3129 testType: clientTest,
3130 name: "MinimumVersion-Client-" + suffix,
3131 config: Config{
3132 MaxVersion: runnerVers.version,
3133 },
David Benjamin87909c02014-12-13 01:55:01 -05003134 flags: flags,
3135 expectedVersion: expectedVersion,
3136 shouldFail: shouldFail,
3137 expectedError: expectedError,
3138 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003139 })
3140 testCases = append(testCases, testCase{
3141 protocol: protocol,
3142 testType: clientTest,
3143 name: "MinimumVersion-Client2-" + suffix,
3144 config: Config{
3145 MaxVersion: runnerVers.version,
3146 },
David Benjamin87909c02014-12-13 01:55:01 -05003147 flags: []string{"-min-version", shimVersFlag},
3148 expectedVersion: expectedVersion,
3149 shouldFail: shouldFail,
3150 expectedError: expectedError,
3151 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003152 })
3153
3154 testCases = append(testCases, testCase{
3155 protocol: protocol,
3156 testType: serverTest,
3157 name: "MinimumVersion-Server-" + suffix,
3158 config: Config{
3159 MaxVersion: runnerVers.version,
3160 },
David Benjamin87909c02014-12-13 01:55:01 -05003161 flags: flags,
3162 expectedVersion: expectedVersion,
3163 shouldFail: shouldFail,
3164 expectedError: expectedError,
3165 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003166 })
3167 testCases = append(testCases, testCase{
3168 protocol: protocol,
3169 testType: serverTest,
3170 name: "MinimumVersion-Server2-" + suffix,
3171 config: Config{
3172 MaxVersion: runnerVers.version,
3173 },
David Benjamin87909c02014-12-13 01:55:01 -05003174 flags: []string{"-min-version", shimVersFlag},
3175 expectedVersion: expectedVersion,
3176 shouldFail: shouldFail,
3177 expectedError: expectedError,
3178 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003179 })
3180 }
3181 }
3182 }
3183}
3184
David Benjamine78bfde2014-09-06 12:45:15 -04003185func addExtensionTests() {
3186 testCases = append(testCases, testCase{
3187 testType: clientTest,
3188 name: "DuplicateExtensionClient",
3189 config: Config{
3190 Bugs: ProtocolBugs{
3191 DuplicateExtension: true,
3192 },
3193 },
3194 shouldFail: true,
3195 expectedLocalError: "remote error: error decoding message",
3196 })
3197 testCases = append(testCases, testCase{
3198 testType: serverTest,
3199 name: "DuplicateExtensionServer",
3200 config: Config{
3201 Bugs: ProtocolBugs{
3202 DuplicateExtension: true,
3203 },
3204 },
3205 shouldFail: true,
3206 expectedLocalError: "remote error: error decoding message",
3207 })
3208 testCases = append(testCases, testCase{
3209 testType: clientTest,
3210 name: "ServerNameExtensionClient",
3211 config: Config{
3212 Bugs: ProtocolBugs{
3213 ExpectServerName: "example.com",
3214 },
3215 },
3216 flags: []string{"-host-name", "example.com"},
3217 })
3218 testCases = append(testCases, testCase{
3219 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003220 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003221 config: Config{
3222 Bugs: ProtocolBugs{
3223 ExpectServerName: "mismatch.com",
3224 },
3225 },
3226 flags: []string{"-host-name", "example.com"},
3227 shouldFail: true,
3228 expectedLocalError: "tls: unexpected server name",
3229 })
3230 testCases = append(testCases, testCase{
3231 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003232 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003233 config: Config{
3234 Bugs: ProtocolBugs{
3235 ExpectServerName: "missing.com",
3236 },
3237 },
3238 shouldFail: true,
3239 expectedLocalError: "tls: unexpected server name",
3240 })
3241 testCases = append(testCases, testCase{
3242 testType: serverTest,
3243 name: "ServerNameExtensionServer",
3244 config: Config{
3245 ServerName: "example.com",
3246 },
3247 flags: []string{"-expect-server-name", "example.com"},
3248 resumeSession: true,
3249 })
David Benjaminae2888f2014-09-06 12:58:58 -04003250 testCases = append(testCases, testCase{
3251 testType: clientTest,
3252 name: "ALPNClient",
3253 config: Config{
3254 NextProtos: []string{"foo"},
3255 },
3256 flags: []string{
3257 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3258 "-expect-alpn", "foo",
3259 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003260 expectedNextProto: "foo",
3261 expectedNextProtoType: alpn,
3262 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003263 })
3264 testCases = append(testCases, testCase{
3265 testType: serverTest,
3266 name: "ALPNServer",
3267 config: Config{
3268 NextProtos: []string{"foo", "bar", "baz"},
3269 },
3270 flags: []string{
3271 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3272 "-select-alpn", "foo",
3273 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003274 expectedNextProto: "foo",
3275 expectedNextProtoType: alpn,
3276 resumeSession: true,
3277 })
3278 // Test that the server prefers ALPN over NPN.
3279 testCases = append(testCases, testCase{
3280 testType: serverTest,
3281 name: "ALPNServer-Preferred",
3282 config: Config{
3283 NextProtos: []string{"foo", "bar", "baz"},
3284 },
3285 flags: []string{
3286 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3287 "-select-alpn", "foo",
3288 "-advertise-npn", "\x03foo\x03bar\x03baz",
3289 },
3290 expectedNextProto: "foo",
3291 expectedNextProtoType: alpn,
3292 resumeSession: true,
3293 })
3294 testCases = append(testCases, testCase{
3295 testType: serverTest,
3296 name: "ALPNServer-Preferred-Swapped",
3297 config: Config{
3298 NextProtos: []string{"foo", "bar", "baz"},
3299 Bugs: ProtocolBugs{
3300 SwapNPNAndALPN: true,
3301 },
3302 },
3303 flags: []string{
3304 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3305 "-select-alpn", "foo",
3306 "-advertise-npn", "\x03foo\x03bar\x03baz",
3307 },
3308 expectedNextProto: "foo",
3309 expectedNextProtoType: alpn,
3310 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003311 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003312 var emptyString string
3313 testCases = append(testCases, testCase{
3314 testType: clientTest,
3315 name: "ALPNClient-EmptyProtocolName",
3316 config: Config{
3317 NextProtos: []string{""},
3318 Bugs: ProtocolBugs{
3319 // A server returning an empty ALPN protocol
3320 // should be rejected.
3321 ALPNProtocol: &emptyString,
3322 },
3323 },
3324 flags: []string{
3325 "-advertise-alpn", "\x03foo",
3326 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003327 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003328 expectedError: ":PARSE_TLSEXT:",
3329 })
3330 testCases = append(testCases, testCase{
3331 testType: serverTest,
3332 name: "ALPNServer-EmptyProtocolName",
3333 config: Config{
3334 // A ClientHello containing an empty ALPN protocol
3335 // should be rejected.
3336 NextProtos: []string{"foo", "", "baz"},
3337 },
3338 flags: []string{
3339 "-select-alpn", "foo",
3340 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003341 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003342 expectedError: ":PARSE_TLSEXT:",
3343 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003344 // Test that negotiating both NPN and ALPN is forbidden.
3345 testCases = append(testCases, testCase{
3346 name: "NegotiateALPNAndNPN",
3347 config: Config{
3348 NextProtos: []string{"foo", "bar", "baz"},
3349 Bugs: ProtocolBugs{
3350 NegotiateALPNAndNPN: true,
3351 },
3352 },
3353 flags: []string{
3354 "-advertise-alpn", "\x03foo",
3355 "-select-next-proto", "foo",
3356 },
3357 shouldFail: true,
3358 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3359 })
3360 testCases = append(testCases, testCase{
3361 name: "NegotiateALPNAndNPN-Swapped",
3362 config: Config{
3363 NextProtos: []string{"foo", "bar", "baz"},
3364 Bugs: ProtocolBugs{
3365 NegotiateALPNAndNPN: true,
3366 SwapNPNAndALPN: true,
3367 },
3368 },
3369 flags: []string{
3370 "-advertise-alpn", "\x03foo",
3371 "-select-next-proto", "foo",
3372 },
3373 shouldFail: true,
3374 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3375 })
David Benjamin091c4b92015-10-26 13:33:21 -04003376 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3377 testCases = append(testCases, testCase{
3378 name: "DisableNPN",
3379 config: Config{
3380 NextProtos: []string{"foo"},
3381 },
3382 flags: []string{
3383 "-select-next-proto", "foo",
3384 "-disable-npn",
3385 },
3386 expectNoNextProto: true,
3387 })
Adam Langley38311732014-10-16 19:04:35 -07003388 // Resume with a corrupt ticket.
3389 testCases = append(testCases, testCase{
3390 testType: serverTest,
3391 name: "CorruptTicket",
3392 config: Config{
3393 Bugs: ProtocolBugs{
3394 CorruptTicket: true,
3395 },
3396 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003397 resumeSession: true,
3398 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003399 })
David Benjamind98452d2015-06-16 14:16:23 -04003400 // Test the ticket callback, with and without renewal.
3401 testCases = append(testCases, testCase{
3402 testType: serverTest,
3403 name: "TicketCallback",
3404 resumeSession: true,
3405 flags: []string{"-use-ticket-callback"},
3406 })
3407 testCases = append(testCases, testCase{
3408 testType: serverTest,
3409 name: "TicketCallback-Renew",
3410 config: Config{
3411 Bugs: ProtocolBugs{
3412 ExpectNewTicket: true,
3413 },
3414 },
3415 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3416 resumeSession: true,
3417 })
Adam Langley38311732014-10-16 19:04:35 -07003418 // Resume with an oversized session id.
3419 testCases = append(testCases, testCase{
3420 testType: serverTest,
3421 name: "OversizedSessionId",
3422 config: Config{
3423 Bugs: ProtocolBugs{
3424 OversizedSessionId: true,
3425 },
3426 },
3427 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003428 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003429 expectedError: ":DECODE_ERROR:",
3430 })
David Benjaminca6c8262014-11-15 19:06:08 -05003431 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3432 // are ignored.
3433 testCases = append(testCases, testCase{
3434 protocol: dtls,
3435 name: "SRTP-Client",
3436 config: Config{
3437 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3438 },
3439 flags: []string{
3440 "-srtp-profiles",
3441 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3442 },
3443 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3444 })
3445 testCases = append(testCases, testCase{
3446 protocol: dtls,
3447 testType: serverTest,
3448 name: "SRTP-Server",
3449 config: Config{
3450 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3451 },
3452 flags: []string{
3453 "-srtp-profiles",
3454 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3455 },
3456 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3457 })
3458 // Test that the MKI is ignored.
3459 testCases = append(testCases, testCase{
3460 protocol: dtls,
3461 testType: serverTest,
3462 name: "SRTP-Server-IgnoreMKI",
3463 config: Config{
3464 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3465 Bugs: ProtocolBugs{
3466 SRTPMasterKeyIdentifer: "bogus",
3467 },
3468 },
3469 flags: []string{
3470 "-srtp-profiles",
3471 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3472 },
3473 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3474 })
3475 // Test that SRTP isn't negotiated on the server if there were
3476 // no matching profiles.
3477 testCases = append(testCases, testCase{
3478 protocol: dtls,
3479 testType: serverTest,
3480 name: "SRTP-Server-NoMatch",
3481 config: Config{
3482 SRTPProtectionProfiles: []uint16{100, 101, 102},
3483 },
3484 flags: []string{
3485 "-srtp-profiles",
3486 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3487 },
3488 expectedSRTPProtectionProfile: 0,
3489 })
3490 // Test that the server returning an invalid SRTP profile is
3491 // flagged as an error by the client.
3492 testCases = append(testCases, testCase{
3493 protocol: dtls,
3494 name: "SRTP-Client-NoMatch",
3495 config: Config{
3496 Bugs: ProtocolBugs{
3497 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3498 },
3499 },
3500 flags: []string{
3501 "-srtp-profiles",
3502 "SRTP_AES128_CM_SHA1_80",
3503 },
3504 shouldFail: true,
3505 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3506 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003507 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003508 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003509 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003510 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003511 flags: []string{
3512 "-enable-signed-cert-timestamps",
3513 "-expect-signed-cert-timestamps",
3514 base64.StdEncoding.EncodeToString(testSCTList),
3515 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003516 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003517 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003518 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003519 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003520 testType: serverTest,
3521 flags: []string{
3522 "-signed-cert-timestamps",
3523 base64.StdEncoding.EncodeToString(testSCTList),
3524 },
3525 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003526 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003527 })
3528 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003529 testType: clientTest,
3530 name: "ClientHelloPadding",
3531 config: Config{
3532 Bugs: ProtocolBugs{
3533 RequireClientHelloSize: 512,
3534 },
3535 },
3536 // This hostname just needs to be long enough to push the
3537 // ClientHello into F5's danger zone between 256 and 511 bytes
3538 // long.
3539 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3540 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003541
3542 // Extensions should not function in SSL 3.0.
3543 testCases = append(testCases, testCase{
3544 testType: serverTest,
3545 name: "SSLv3Extensions-NoALPN",
3546 config: Config{
3547 MaxVersion: VersionSSL30,
3548 NextProtos: []string{"foo", "bar", "baz"},
3549 },
3550 flags: []string{
3551 "-select-alpn", "foo",
3552 },
3553 expectNoNextProto: true,
3554 })
3555
3556 // Test session tickets separately as they follow a different codepath.
3557 testCases = append(testCases, testCase{
3558 testType: serverTest,
3559 name: "SSLv3Extensions-NoTickets",
3560 config: Config{
3561 MaxVersion: VersionSSL30,
3562 Bugs: ProtocolBugs{
3563 // Historically, session tickets in SSL 3.0
3564 // failed in different ways depending on whether
3565 // the client supported renegotiation_info.
3566 NoRenegotiationInfo: true,
3567 },
3568 },
3569 resumeSession: true,
3570 })
3571 testCases = append(testCases, testCase{
3572 testType: serverTest,
3573 name: "SSLv3Extensions-NoTickets2",
3574 config: Config{
3575 MaxVersion: VersionSSL30,
3576 },
3577 resumeSession: true,
3578 })
3579
3580 // But SSL 3.0 does send and process renegotiation_info.
3581 testCases = append(testCases, testCase{
3582 testType: serverTest,
3583 name: "SSLv3Extensions-RenegotiationInfo",
3584 config: Config{
3585 MaxVersion: VersionSSL30,
3586 Bugs: ProtocolBugs{
3587 RequireRenegotiationInfo: true,
3588 },
3589 },
3590 })
3591 testCases = append(testCases, testCase{
3592 testType: serverTest,
3593 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3594 config: Config{
3595 MaxVersion: VersionSSL30,
3596 Bugs: ProtocolBugs{
3597 NoRenegotiationInfo: true,
3598 SendRenegotiationSCSV: true,
3599 RequireRenegotiationInfo: true,
3600 },
3601 },
3602 })
David Benjamine78bfde2014-09-06 12:45:15 -04003603}
3604
David Benjamin01fe8202014-09-24 15:21:44 -04003605func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003606 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003607 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003608 protocols := []protocol{tls}
3609 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3610 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003611 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003612 for _, protocol := range protocols {
3613 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3614 if protocol == dtls {
3615 suffix += "-DTLS"
3616 }
3617
David Benjaminece3de92015-03-16 18:02:20 -04003618 if sessionVers.version == resumeVers.version {
3619 testCases = append(testCases, testCase{
3620 protocol: protocol,
3621 name: "Resume-Client" + suffix,
3622 resumeSession: true,
3623 config: Config{
3624 MaxVersion: sessionVers.version,
3625 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003626 },
David Benjaminece3de92015-03-16 18:02:20 -04003627 expectedVersion: sessionVers.version,
3628 expectedResumeVersion: resumeVers.version,
3629 })
3630 } else {
3631 testCases = append(testCases, testCase{
3632 protocol: protocol,
3633 name: "Resume-Client-Mismatch" + suffix,
3634 resumeSession: true,
3635 config: Config{
3636 MaxVersion: sessionVers.version,
3637 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003638 },
David Benjaminece3de92015-03-16 18:02:20 -04003639 expectedVersion: sessionVers.version,
3640 resumeConfig: &Config{
3641 MaxVersion: resumeVers.version,
3642 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3643 Bugs: ProtocolBugs{
3644 AllowSessionVersionMismatch: true,
3645 },
3646 },
3647 expectedResumeVersion: resumeVers.version,
3648 shouldFail: true,
3649 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3650 })
3651 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003652
3653 testCases = append(testCases, testCase{
3654 protocol: protocol,
3655 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003656 resumeSession: true,
3657 config: Config{
3658 MaxVersion: sessionVers.version,
3659 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3660 },
3661 expectedVersion: sessionVers.version,
3662 resumeConfig: &Config{
3663 MaxVersion: resumeVers.version,
3664 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3665 },
3666 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003667 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003668 expectedResumeVersion: resumeVers.version,
3669 })
3670
David Benjamin8b8c0062014-11-23 02:47:52 -05003671 testCases = append(testCases, testCase{
3672 protocol: protocol,
3673 testType: serverTest,
3674 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003675 resumeSession: true,
3676 config: Config{
3677 MaxVersion: sessionVers.version,
3678 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3679 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003680 expectedVersion: sessionVers.version,
3681 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003682 resumeConfig: &Config{
3683 MaxVersion: resumeVers.version,
3684 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3685 },
3686 expectedResumeVersion: resumeVers.version,
3687 })
3688 }
David Benjamin01fe8202014-09-24 15:21:44 -04003689 }
3690 }
David Benjaminece3de92015-03-16 18:02:20 -04003691
3692 testCases = append(testCases, testCase{
3693 name: "Resume-Client-CipherMismatch",
3694 resumeSession: true,
3695 config: Config{
3696 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3697 },
3698 resumeConfig: &Config{
3699 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3700 Bugs: ProtocolBugs{
3701 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3702 },
3703 },
3704 shouldFail: true,
3705 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3706 })
David Benjamin01fe8202014-09-24 15:21:44 -04003707}
3708
Adam Langley2ae77d22014-10-28 17:29:33 -07003709func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003710 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003711 testCases = append(testCases, testCase{
3712 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003713 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003714 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003715 shouldFail: true,
3716 expectedError: ":NO_RENEGOTIATION:",
3717 expectedLocalError: "remote error: no renegotiation",
3718 })
Adam Langley5021b222015-06-12 18:27:58 -07003719 // The server shouldn't echo the renegotiation extension unless
3720 // requested by the client.
3721 testCases = append(testCases, testCase{
3722 testType: serverTest,
3723 name: "Renegotiate-Server-NoExt",
3724 config: Config{
3725 Bugs: ProtocolBugs{
3726 NoRenegotiationInfo: true,
3727 RequireRenegotiationInfo: true,
3728 },
3729 },
3730 shouldFail: true,
3731 expectedLocalError: "renegotiation extension missing",
3732 })
3733 // The renegotiation SCSV should be sufficient for the server to echo
3734 // the extension.
3735 testCases = append(testCases, testCase{
3736 testType: serverTest,
3737 name: "Renegotiate-Server-NoExt-SCSV",
3738 config: Config{
3739 Bugs: ProtocolBugs{
3740 NoRenegotiationInfo: true,
3741 SendRenegotiationSCSV: true,
3742 RequireRenegotiationInfo: true,
3743 },
3744 },
3745 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003746 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003747 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003748 config: Config{
3749 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003750 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003751 },
3752 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003753 renegotiate: 1,
3754 flags: []string{
3755 "-renegotiate-freely",
3756 "-expect-total-renegotiations", "1",
3757 },
David Benjamincdea40c2015-03-19 14:09:43 -04003758 })
3759 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003760 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003761 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003762 config: Config{
3763 Bugs: ProtocolBugs{
3764 EmptyRenegotiationInfo: true,
3765 },
3766 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003767 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003768 shouldFail: true,
3769 expectedError: ":RENEGOTIATION_MISMATCH:",
3770 })
3771 testCases = append(testCases, testCase{
3772 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003773 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003774 config: Config{
3775 Bugs: ProtocolBugs{
3776 BadRenegotiationInfo: true,
3777 },
3778 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003779 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003780 shouldFail: true,
3781 expectedError: ":RENEGOTIATION_MISMATCH:",
3782 })
3783 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05003784 name: "Renegotiate-Client-Downgrade",
3785 renegotiate: 1,
3786 config: Config{
3787 Bugs: ProtocolBugs{
3788 NoRenegotiationInfoAfterInitial: true,
3789 },
3790 },
3791 flags: []string{"-renegotiate-freely"},
3792 shouldFail: true,
3793 expectedError: ":RENEGOTIATION_MISMATCH:",
3794 })
3795 testCases = append(testCases, testCase{
3796 name: "Renegotiate-Client-Upgrade",
3797 renegotiate: 1,
3798 config: Config{
3799 Bugs: ProtocolBugs{
3800 NoRenegotiationInfoInInitial: true,
3801 },
3802 },
3803 flags: []string{"-renegotiate-freely"},
3804 shouldFail: true,
3805 expectedError: ":RENEGOTIATION_MISMATCH:",
3806 })
3807 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04003808 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003809 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003810 config: Config{
3811 Bugs: ProtocolBugs{
3812 NoRenegotiationInfo: true,
3813 },
3814 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003815 flags: []string{
3816 "-renegotiate-freely",
3817 "-expect-total-renegotiations", "1",
3818 },
David Benjamincff0b902015-05-15 23:09:47 -04003819 })
3820 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003821 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003822 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003823 config: Config{
3824 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3825 },
3826 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003827 flags: []string{
3828 "-renegotiate-freely",
3829 "-expect-total-renegotiations", "1",
3830 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003831 })
3832 testCases = append(testCases, testCase{
3833 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003834 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003835 config: Config{
3836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3837 },
3838 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003839 flags: []string{
3840 "-renegotiate-freely",
3841 "-expect-total-renegotiations", "1",
3842 },
David Benjaminb16346b2015-04-08 19:16:58 -04003843 })
3844 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003845 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003846 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003847 config: Config{
3848 MaxVersion: VersionTLS10,
3849 Bugs: ProtocolBugs{
3850 RequireSameRenegoClientVersion: true,
3851 },
3852 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003853 flags: []string{
3854 "-renegotiate-freely",
3855 "-expect-total-renegotiations", "1",
3856 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003857 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003858 testCases = append(testCases, testCase{
3859 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003860 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003861 config: Config{
3862 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3863 NextProtos: []string{"foo"},
3864 },
3865 flags: []string{
3866 "-false-start",
3867 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003868 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003869 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003870 },
3871 shimWritesFirst: true,
3872 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003873
3874 // Client-side renegotiation controls.
3875 testCases = append(testCases, testCase{
3876 name: "Renegotiate-Client-Forbidden-1",
3877 renegotiate: 1,
3878 shouldFail: true,
3879 expectedError: ":NO_RENEGOTIATION:",
3880 expectedLocalError: "remote error: no renegotiation",
3881 })
3882 testCases = append(testCases, testCase{
3883 name: "Renegotiate-Client-Once-1",
3884 renegotiate: 1,
3885 flags: []string{
3886 "-renegotiate-once",
3887 "-expect-total-renegotiations", "1",
3888 },
3889 })
3890 testCases = append(testCases, testCase{
3891 name: "Renegotiate-Client-Freely-1",
3892 renegotiate: 1,
3893 flags: []string{
3894 "-renegotiate-freely",
3895 "-expect-total-renegotiations", "1",
3896 },
3897 })
3898 testCases = append(testCases, testCase{
3899 name: "Renegotiate-Client-Once-2",
3900 renegotiate: 2,
3901 flags: []string{"-renegotiate-once"},
3902 shouldFail: true,
3903 expectedError: ":NO_RENEGOTIATION:",
3904 expectedLocalError: "remote error: no renegotiation",
3905 })
3906 testCases = append(testCases, testCase{
3907 name: "Renegotiate-Client-Freely-2",
3908 renegotiate: 2,
3909 flags: []string{
3910 "-renegotiate-freely",
3911 "-expect-total-renegotiations", "2",
3912 },
3913 })
Adam Langley27a0d082015-11-03 13:34:10 -08003914 testCases = append(testCases, testCase{
3915 name: "Renegotiate-Client-NoIgnore",
3916 config: Config{
3917 Bugs: ProtocolBugs{
3918 SendHelloRequestBeforeEveryAppDataRecord: true,
3919 },
3920 },
3921 shouldFail: true,
3922 expectedError: ":NO_RENEGOTIATION:",
3923 })
3924 testCases = append(testCases, testCase{
3925 name: "Renegotiate-Client-Ignore",
3926 config: Config{
3927 Bugs: ProtocolBugs{
3928 SendHelloRequestBeforeEveryAppDataRecord: true,
3929 },
3930 },
3931 flags: []string{
3932 "-renegotiate-ignore",
3933 "-expect-total-renegotiations", "0",
3934 },
3935 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003936}
3937
David Benjamin5e961c12014-11-07 01:48:35 -05003938func addDTLSReplayTests() {
3939 // Test that sequence number replays are detected.
3940 testCases = append(testCases, testCase{
3941 protocol: dtls,
3942 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003943 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003944 replayWrites: true,
3945 })
3946
David Benjamin8e6db492015-07-25 18:29:23 -04003947 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003948 // than the retransmit window.
3949 testCases = append(testCases, testCase{
3950 protocol: dtls,
3951 name: "DTLS-Replay-LargeGaps",
3952 config: Config{
3953 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003954 SequenceNumberMapping: func(in uint64) uint64 {
3955 return in * 127
3956 },
David Benjamin5e961c12014-11-07 01:48:35 -05003957 },
3958 },
David Benjamin8e6db492015-07-25 18:29:23 -04003959 messageCount: 200,
3960 replayWrites: true,
3961 })
3962
3963 // Test the incoming sequence number changing non-monotonically.
3964 testCases = append(testCases, testCase{
3965 protocol: dtls,
3966 name: "DTLS-Replay-NonMonotonic",
3967 config: Config{
3968 Bugs: ProtocolBugs{
3969 SequenceNumberMapping: func(in uint64) uint64 {
3970 return in ^ 31
3971 },
3972 },
3973 },
3974 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003975 replayWrites: true,
3976 })
3977}
3978
David Benjamin000800a2014-11-14 01:43:59 -05003979var testHashes = []struct {
3980 name string
3981 id uint8
3982}{
3983 {"SHA1", hashSHA1},
3984 {"SHA224", hashSHA224},
3985 {"SHA256", hashSHA256},
3986 {"SHA384", hashSHA384},
3987 {"SHA512", hashSHA512},
3988}
3989
3990func addSigningHashTests() {
3991 // Make sure each hash works. Include some fake hashes in the list and
3992 // ensure they're ignored.
3993 for _, hash := range testHashes {
3994 testCases = append(testCases, testCase{
3995 name: "SigningHash-ClientAuth-" + hash.name,
3996 config: Config{
3997 ClientAuth: RequireAnyClientCert,
3998 SignatureAndHashes: []signatureAndHash{
3999 {signatureRSA, 42},
4000 {signatureRSA, hash.id},
4001 {signatureRSA, 255},
4002 },
4003 },
4004 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004005 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4006 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004007 },
4008 })
4009
4010 testCases = append(testCases, testCase{
4011 testType: serverTest,
4012 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4013 config: Config{
4014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4015 SignatureAndHashes: []signatureAndHash{
4016 {signatureRSA, 42},
4017 {signatureRSA, hash.id},
4018 {signatureRSA, 255},
4019 },
4020 },
4021 })
David Benjamin6e807652015-11-02 12:02:20 -05004022
4023 testCases = append(testCases, testCase{
4024 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4025 config: Config{
4026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4027 SignatureAndHashes: []signatureAndHash{
4028 {signatureRSA, 42},
4029 {signatureRSA, hash.id},
4030 {signatureRSA, 255},
4031 },
4032 },
4033 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4034 })
David Benjamin000800a2014-11-14 01:43:59 -05004035 }
4036
4037 // Test that hash resolution takes the signature type into account.
4038 testCases = append(testCases, testCase{
4039 name: "SigningHash-ClientAuth-SignatureType",
4040 config: Config{
4041 ClientAuth: RequireAnyClientCert,
4042 SignatureAndHashes: []signatureAndHash{
4043 {signatureECDSA, hashSHA512},
4044 {signatureRSA, hashSHA384},
4045 {signatureECDSA, hashSHA1},
4046 },
4047 },
4048 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004049 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4050 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004051 },
4052 })
4053
4054 testCases = append(testCases, testCase{
4055 testType: serverTest,
4056 name: "SigningHash-ServerKeyExchange-SignatureType",
4057 config: Config{
4058 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4059 SignatureAndHashes: []signatureAndHash{
4060 {signatureECDSA, hashSHA512},
4061 {signatureRSA, hashSHA384},
4062 {signatureECDSA, hashSHA1},
4063 },
4064 },
4065 })
4066
4067 // Test that, if the list is missing, the peer falls back to SHA-1.
4068 testCases = append(testCases, testCase{
4069 name: "SigningHash-ClientAuth-Fallback",
4070 config: Config{
4071 ClientAuth: RequireAnyClientCert,
4072 SignatureAndHashes: []signatureAndHash{
4073 {signatureRSA, hashSHA1},
4074 },
4075 Bugs: ProtocolBugs{
4076 NoSignatureAndHashes: true,
4077 },
4078 },
4079 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004080 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4081 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004082 },
4083 })
4084
4085 testCases = append(testCases, testCase{
4086 testType: serverTest,
4087 name: "SigningHash-ServerKeyExchange-Fallback",
4088 config: Config{
4089 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4090 SignatureAndHashes: []signatureAndHash{
4091 {signatureRSA, hashSHA1},
4092 },
4093 Bugs: ProtocolBugs{
4094 NoSignatureAndHashes: true,
4095 },
4096 },
4097 })
David Benjamin72dc7832015-03-16 17:49:43 -04004098
4099 // Test that hash preferences are enforced. BoringSSL defaults to
4100 // rejecting MD5 signatures.
4101 testCases = append(testCases, testCase{
4102 testType: serverTest,
4103 name: "SigningHash-ClientAuth-Enforced",
4104 config: Config{
4105 Certificates: []Certificate{rsaCertificate},
4106 SignatureAndHashes: []signatureAndHash{
4107 {signatureRSA, hashMD5},
4108 // Advertise SHA-1 so the handshake will
4109 // proceed, but the shim's preferences will be
4110 // ignored in CertificateVerify generation, so
4111 // MD5 will be chosen.
4112 {signatureRSA, hashSHA1},
4113 },
4114 Bugs: ProtocolBugs{
4115 IgnorePeerSignatureAlgorithmPreferences: true,
4116 },
4117 },
4118 flags: []string{"-require-any-client-certificate"},
4119 shouldFail: true,
4120 expectedError: ":WRONG_SIGNATURE_TYPE:",
4121 })
4122
4123 testCases = append(testCases, testCase{
4124 name: "SigningHash-ServerKeyExchange-Enforced",
4125 config: Config{
4126 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4127 SignatureAndHashes: []signatureAndHash{
4128 {signatureRSA, hashMD5},
4129 },
4130 Bugs: ProtocolBugs{
4131 IgnorePeerSignatureAlgorithmPreferences: true,
4132 },
4133 },
4134 shouldFail: true,
4135 expectedError: ":WRONG_SIGNATURE_TYPE:",
4136 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004137
4138 // Test that the agreed upon digest respects the client preferences and
4139 // the server digests.
4140 testCases = append(testCases, testCase{
4141 name: "Agree-Digest-Fallback",
4142 config: Config{
4143 ClientAuth: RequireAnyClientCert,
4144 SignatureAndHashes: []signatureAndHash{
4145 {signatureRSA, hashSHA512},
4146 {signatureRSA, hashSHA1},
4147 },
4148 },
4149 flags: []string{
4150 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4151 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4152 },
4153 digestPrefs: "SHA256",
4154 expectedClientCertSignatureHash: hashSHA1,
4155 })
4156 testCases = append(testCases, testCase{
4157 name: "Agree-Digest-SHA256",
4158 config: Config{
4159 ClientAuth: RequireAnyClientCert,
4160 SignatureAndHashes: []signatureAndHash{
4161 {signatureRSA, hashSHA1},
4162 {signatureRSA, hashSHA256},
4163 },
4164 },
4165 flags: []string{
4166 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4167 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4168 },
4169 digestPrefs: "SHA256,SHA1",
4170 expectedClientCertSignatureHash: hashSHA256,
4171 })
4172 testCases = append(testCases, testCase{
4173 name: "Agree-Digest-SHA1",
4174 config: Config{
4175 ClientAuth: RequireAnyClientCert,
4176 SignatureAndHashes: []signatureAndHash{
4177 {signatureRSA, hashSHA1},
4178 },
4179 },
4180 flags: []string{
4181 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4182 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4183 },
4184 digestPrefs: "SHA512,SHA256,SHA1",
4185 expectedClientCertSignatureHash: hashSHA1,
4186 })
4187 testCases = append(testCases, testCase{
4188 name: "Agree-Digest-Default",
4189 config: Config{
4190 ClientAuth: RequireAnyClientCert,
4191 SignatureAndHashes: []signatureAndHash{
4192 {signatureRSA, hashSHA256},
4193 {signatureECDSA, hashSHA256},
4194 {signatureRSA, hashSHA1},
4195 {signatureECDSA, hashSHA1},
4196 },
4197 },
4198 flags: []string{
4199 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4200 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4201 },
4202 expectedClientCertSignatureHash: hashSHA256,
4203 })
David Benjamin000800a2014-11-14 01:43:59 -05004204}
4205
David Benjamin83f90402015-01-27 01:09:43 -05004206// timeouts is the retransmit schedule for BoringSSL. It doubles and
4207// caps at 60 seconds. On the 13th timeout, it gives up.
4208var timeouts = []time.Duration{
4209 1 * time.Second,
4210 2 * time.Second,
4211 4 * time.Second,
4212 8 * time.Second,
4213 16 * time.Second,
4214 32 * time.Second,
4215 60 * time.Second,
4216 60 * time.Second,
4217 60 * time.Second,
4218 60 * time.Second,
4219 60 * time.Second,
4220 60 * time.Second,
4221 60 * time.Second,
4222}
4223
4224func addDTLSRetransmitTests() {
4225 // Test that this is indeed the timeout schedule. Stress all
4226 // four patterns of handshake.
4227 for i := 1; i < len(timeouts); i++ {
4228 number := strconv.Itoa(i)
4229 testCases = append(testCases, testCase{
4230 protocol: dtls,
4231 name: "DTLS-Retransmit-Client-" + number,
4232 config: Config{
4233 Bugs: ProtocolBugs{
4234 TimeoutSchedule: timeouts[:i],
4235 },
4236 },
4237 resumeSession: true,
4238 flags: []string{"-async"},
4239 })
4240 testCases = append(testCases, testCase{
4241 protocol: dtls,
4242 testType: serverTest,
4243 name: "DTLS-Retransmit-Server-" + number,
4244 config: Config{
4245 Bugs: ProtocolBugs{
4246 TimeoutSchedule: timeouts[:i],
4247 },
4248 },
4249 resumeSession: true,
4250 flags: []string{"-async"},
4251 })
4252 }
4253
4254 // Test that exceeding the timeout schedule hits a read
4255 // timeout.
4256 testCases = append(testCases, testCase{
4257 protocol: dtls,
4258 name: "DTLS-Retransmit-Timeout",
4259 config: Config{
4260 Bugs: ProtocolBugs{
4261 TimeoutSchedule: timeouts,
4262 },
4263 },
4264 resumeSession: true,
4265 flags: []string{"-async"},
4266 shouldFail: true,
4267 expectedError: ":READ_TIMEOUT_EXPIRED:",
4268 })
4269
4270 // Test that timeout handling has a fudge factor, due to API
4271 // problems.
4272 testCases = append(testCases, testCase{
4273 protocol: dtls,
4274 name: "DTLS-Retransmit-Fudge",
4275 config: Config{
4276 Bugs: ProtocolBugs{
4277 TimeoutSchedule: []time.Duration{
4278 timeouts[0] - 10*time.Millisecond,
4279 },
4280 },
4281 },
4282 resumeSession: true,
4283 flags: []string{"-async"},
4284 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004285
4286 // Test that the final Finished retransmitting isn't
4287 // duplicated if the peer badly fragments everything.
4288 testCases = append(testCases, testCase{
4289 testType: serverTest,
4290 protocol: dtls,
4291 name: "DTLS-Retransmit-Fragmented",
4292 config: Config{
4293 Bugs: ProtocolBugs{
4294 TimeoutSchedule: []time.Duration{timeouts[0]},
4295 MaxHandshakeRecordLength: 2,
4296 },
4297 },
4298 flags: []string{"-async"},
4299 })
David Benjamin83f90402015-01-27 01:09:43 -05004300}
4301
David Benjaminc565ebb2015-04-03 04:06:36 -04004302func addExportKeyingMaterialTests() {
4303 for _, vers := range tlsVersions {
4304 if vers.version == VersionSSL30 {
4305 continue
4306 }
4307 testCases = append(testCases, testCase{
4308 name: "ExportKeyingMaterial-" + vers.name,
4309 config: Config{
4310 MaxVersion: vers.version,
4311 },
4312 exportKeyingMaterial: 1024,
4313 exportLabel: "label",
4314 exportContext: "context",
4315 useExportContext: true,
4316 })
4317 testCases = append(testCases, testCase{
4318 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4319 config: Config{
4320 MaxVersion: vers.version,
4321 },
4322 exportKeyingMaterial: 1024,
4323 })
4324 testCases = append(testCases, testCase{
4325 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4326 config: Config{
4327 MaxVersion: vers.version,
4328 },
4329 exportKeyingMaterial: 1024,
4330 useExportContext: true,
4331 })
4332 testCases = append(testCases, testCase{
4333 name: "ExportKeyingMaterial-Small-" + vers.name,
4334 config: Config{
4335 MaxVersion: vers.version,
4336 },
4337 exportKeyingMaterial: 1,
4338 exportLabel: "label",
4339 exportContext: "context",
4340 useExportContext: true,
4341 })
4342 }
4343 testCases = append(testCases, testCase{
4344 name: "ExportKeyingMaterial-SSL3",
4345 config: Config{
4346 MaxVersion: VersionSSL30,
4347 },
4348 exportKeyingMaterial: 1024,
4349 exportLabel: "label",
4350 exportContext: "context",
4351 useExportContext: true,
4352 shouldFail: true,
4353 expectedError: "failed to export keying material",
4354 })
4355}
4356
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004357func addTLSUniqueTests() {
4358 for _, isClient := range []bool{false, true} {
4359 for _, isResumption := range []bool{false, true} {
4360 for _, hasEMS := range []bool{false, true} {
4361 var suffix string
4362 if isResumption {
4363 suffix = "Resume-"
4364 } else {
4365 suffix = "Full-"
4366 }
4367
4368 if hasEMS {
4369 suffix += "EMS-"
4370 } else {
4371 suffix += "NoEMS-"
4372 }
4373
4374 if isClient {
4375 suffix += "Client"
4376 } else {
4377 suffix += "Server"
4378 }
4379
4380 test := testCase{
4381 name: "TLSUnique-" + suffix,
4382 testTLSUnique: true,
4383 config: Config{
4384 Bugs: ProtocolBugs{
4385 NoExtendedMasterSecret: !hasEMS,
4386 },
4387 },
4388 }
4389
4390 if isResumption {
4391 test.resumeSession = true
4392 test.resumeConfig = &Config{
4393 Bugs: ProtocolBugs{
4394 NoExtendedMasterSecret: !hasEMS,
4395 },
4396 }
4397 }
4398
4399 if isResumption && !hasEMS {
4400 test.shouldFail = true
4401 test.expectedError = "failed to get tls-unique"
4402 }
4403
4404 testCases = append(testCases, test)
4405 }
4406 }
4407 }
4408}
4409
Adam Langley09505632015-07-30 18:10:13 -07004410func addCustomExtensionTests() {
4411 expectedContents := "custom extension"
4412 emptyString := ""
4413
4414 for _, isClient := range []bool{false, true} {
4415 suffix := "Server"
4416 flag := "-enable-server-custom-extension"
4417 testType := serverTest
4418 if isClient {
4419 suffix = "Client"
4420 flag = "-enable-client-custom-extension"
4421 testType = clientTest
4422 }
4423
4424 testCases = append(testCases, testCase{
4425 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004426 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004427 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004428 Bugs: ProtocolBugs{
4429 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004430 ExpectedCustomExtension: &expectedContents,
4431 },
4432 },
4433 flags: []string{flag},
4434 })
4435
4436 // If the parse callback fails, the handshake should also fail.
4437 testCases = append(testCases, testCase{
4438 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004439 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004440 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004441 Bugs: ProtocolBugs{
4442 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004443 ExpectedCustomExtension: &expectedContents,
4444 },
4445 },
David Benjamin399e7c92015-07-30 23:01:27 -04004446 flags: []string{flag},
4447 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004448 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4449 })
4450
4451 // If the add callback fails, the handshake should also fail.
4452 testCases = append(testCases, testCase{
4453 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004454 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004455 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004456 Bugs: ProtocolBugs{
4457 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004458 ExpectedCustomExtension: &expectedContents,
4459 },
4460 },
David Benjamin399e7c92015-07-30 23:01:27 -04004461 flags: []string{flag, "-custom-extension-fail-add"},
4462 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004463 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4464 })
4465
4466 // If the add callback returns zero, no extension should be
4467 // added.
4468 skipCustomExtension := expectedContents
4469 if isClient {
4470 // For the case where the client skips sending the
4471 // custom extension, the server must not “echo” it.
4472 skipCustomExtension = ""
4473 }
4474 testCases = append(testCases, testCase{
4475 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004476 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004477 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004478 Bugs: ProtocolBugs{
4479 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004480 ExpectedCustomExtension: &emptyString,
4481 },
4482 },
4483 flags: []string{flag, "-custom-extension-skip"},
4484 })
4485 }
4486
4487 // The custom extension add callback should not be called if the client
4488 // doesn't send the extension.
4489 testCases = append(testCases, testCase{
4490 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004491 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004492 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004493 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004494 ExpectedCustomExtension: &emptyString,
4495 },
4496 },
4497 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4498 })
Adam Langley2deb9842015-08-07 11:15:37 -07004499
4500 // Test an unknown extension from the server.
4501 testCases = append(testCases, testCase{
4502 testType: clientTest,
4503 name: "UnknownExtension-Client",
4504 config: Config{
4505 Bugs: ProtocolBugs{
4506 CustomExtension: expectedContents,
4507 },
4508 },
4509 shouldFail: true,
4510 expectedError: ":UNEXPECTED_EXTENSION:",
4511 })
Adam Langley09505632015-07-30 18:10:13 -07004512}
4513
David Benjaminb36a3952015-12-01 18:53:13 -05004514func addRSAClientKeyExchangeTests() {
4515 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
4516 testCases = append(testCases, testCase{
4517 testType: serverTest,
4518 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
4519 config: Config{
4520 // Ensure the ClientHello version and final
4521 // version are different, to detect if the
4522 // server uses the wrong one.
4523 MaxVersion: VersionTLS11,
4524 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4525 Bugs: ProtocolBugs{
4526 BadRSAClientKeyExchange: bad,
4527 },
4528 },
4529 shouldFail: true,
4530 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
4531 })
4532 }
4533}
4534
Adam Langley7c803a62015-06-15 15:35:05 -07004535func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004536 defer wg.Done()
4537
4538 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004539 var err error
4540
4541 if *mallocTest < 0 {
4542 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004543 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004544 } else {
4545 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4546 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004547 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004548 if err != nil {
4549 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4550 }
4551 break
4552 }
4553 }
4554 }
Adam Langley95c29f32014-06-20 12:00:00 -07004555 statusChan <- statusMsg{test: test, err: err}
4556 }
4557}
4558
4559type statusMsg struct {
4560 test *testCase
4561 started bool
4562 err error
4563}
4564
David Benjamin5f237bc2015-02-11 17:14:15 -05004565func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004566 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004567
David Benjamin5f237bc2015-02-11 17:14:15 -05004568 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004569 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004570 if !*pipe {
4571 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004572 var erase string
4573 for i := 0; i < lineLen; i++ {
4574 erase += "\b \b"
4575 }
4576 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004577 }
4578
Adam Langley95c29f32014-06-20 12:00:00 -07004579 if msg.started {
4580 started++
4581 } else {
4582 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004583
4584 if msg.err != nil {
4585 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4586 failed++
4587 testOutput.addResult(msg.test.name, "FAIL")
4588 } else {
4589 if *pipe {
4590 // Print each test instead of a status line.
4591 fmt.Printf("PASSED (%s)\n", msg.test.name)
4592 }
4593 testOutput.addResult(msg.test.name, "PASS")
4594 }
Adam Langley95c29f32014-06-20 12:00:00 -07004595 }
4596
David Benjamin5f237bc2015-02-11 17:14:15 -05004597 if !*pipe {
4598 // Print a new status line.
4599 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4600 lineLen = len(line)
4601 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004602 }
Adam Langley95c29f32014-06-20 12:00:00 -07004603 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004604
4605 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004606}
4607
4608func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004609 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004610 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004611
Adam Langley7c803a62015-06-15 15:35:05 -07004612 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004613 addCipherSuiteTests()
4614 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004615 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004616 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004617 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004618 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004619 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004620 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004621 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004622 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004623 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004624 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004625 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004626 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004627 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004628 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004629 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004630 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05004631 addRSAClientKeyExchangeTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004632 for _, async := range []bool{false, true} {
4633 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004634 for _, protocol := range []protocol{tls, dtls} {
4635 addStateMachineCoverageTests(async, splitHandshake, protocol)
4636 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004637 }
4638 }
Adam Langley95c29f32014-06-20 12:00:00 -07004639
4640 var wg sync.WaitGroup
4641
Adam Langley7c803a62015-06-15 15:35:05 -07004642 statusChan := make(chan statusMsg, *numWorkers)
4643 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004644 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004645
David Benjamin025b3d32014-07-01 19:53:04 -04004646 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004647
Adam Langley7c803a62015-06-15 15:35:05 -07004648 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004649 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004650 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004651 }
4652
David Benjamin025b3d32014-07-01 19:53:04 -04004653 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004654 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004655 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004656 }
4657 }
4658
4659 close(testChan)
4660 wg.Wait()
4661 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004662 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004663
4664 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004665
4666 if *jsonOutput != "" {
4667 if err := testOutput.writeTo(*jsonOutput); err != nil {
4668 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4669 }
4670 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004671
4672 if !testOutput.allPassed {
4673 os.Exit(1)
4674 }
Adam Langley95c29f32014-06-20 12:00:00 -07004675}