blob: 1e5ffd980e64e97113a1b77f1c5443f71cedb6e6 [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 },
David Benjamin8411b242015-11-26 12:07:28 -05001998 {
1999 name: "BadChangeCipherSpec-1",
2000 config: Config{
2001 Bugs: ProtocolBugs{
2002 BadChangeCipherSpec: []byte{2},
2003 },
2004 },
2005 shouldFail: true,
2006 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2007 },
2008 {
2009 name: "BadChangeCipherSpec-2",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 BadChangeCipherSpec: []byte{1, 1},
2013 },
2014 },
2015 shouldFail: true,
2016 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2017 },
2018 {
2019 protocol: dtls,
2020 name: "BadChangeCipherSpec-DTLS-1",
2021 config: Config{
2022 Bugs: ProtocolBugs{
2023 BadChangeCipherSpec: []byte{2},
2024 },
2025 },
2026 shouldFail: true,
2027 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2028 },
2029 {
2030 protocol: dtls,
2031 name: "BadChangeCipherSpec-DTLS-2",
2032 config: Config{
2033 Bugs: ProtocolBugs{
2034 BadChangeCipherSpec: []byte{1, 1},
2035 },
2036 },
2037 shouldFail: true,
2038 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
2039 },
Adam Langley7c803a62015-06-15 15:35:05 -07002040 }
Adam Langley7c803a62015-06-15 15:35:05 -07002041 testCases = append(testCases, basicTests...)
2042}
2043
Adam Langley95c29f32014-06-20 12:00:00 -07002044func addCipherSuiteTests() {
2045 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002046 const psk = "12345"
2047 const pskIdentity = "luggage combo"
2048
Adam Langley95c29f32014-06-20 12:00:00 -07002049 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002050 var certFile string
2051 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002052 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07002053 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002054 certFile = ecdsaCertificateFile
2055 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002056 } else {
2057 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002058 certFile = rsaCertificateFile
2059 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002060 }
2061
David Benjamin48cae082014-10-27 01:06:24 -04002062 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002063 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002064 flags = append(flags,
2065 "-psk", psk,
2066 "-psk-identity", pskIdentity)
2067 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002068 if hasComponent(suite.name, "NULL") {
2069 // NULL ciphers must be explicitly enabled.
2070 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2071 }
David Benjamin48cae082014-10-27 01:06:24 -04002072
Adam Langley95c29f32014-06-20 12:00:00 -07002073 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002074 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002075 continue
2076 }
2077
David Benjamin025b3d32014-07-01 19:53:04 -04002078 testCases = append(testCases, testCase{
2079 testType: clientTest,
2080 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002081 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002082 MinVersion: ver.version,
2083 MaxVersion: ver.version,
2084 CipherSuites: []uint16{suite.id},
2085 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002086 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002087 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002088 },
David Benjamin48cae082014-10-27 01:06:24 -04002089 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002090 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002091 })
David Benjamin025b3d32014-07-01 19:53:04 -04002092
David Benjamin76d8abe2014-08-14 16:25:34 -04002093 testCases = append(testCases, testCase{
2094 testType: serverTest,
2095 name: ver.name + "-" + suite.name + "-server",
2096 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002097 MinVersion: ver.version,
2098 MaxVersion: ver.version,
2099 CipherSuites: []uint16{suite.id},
2100 Certificates: []Certificate{cert},
2101 PreSharedKey: []byte(psk),
2102 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002103 },
2104 certFile: certFile,
2105 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002106 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002107 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002108 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002109
David Benjamin8b8c0062014-11-23 02:47:52 -05002110 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002111 testCases = append(testCases, testCase{
2112 testType: clientTest,
2113 protocol: dtls,
2114 name: "D" + ver.name + "-" + suite.name + "-client",
2115 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002116 MinVersion: ver.version,
2117 MaxVersion: ver.version,
2118 CipherSuites: []uint16{suite.id},
2119 Certificates: []Certificate{cert},
2120 PreSharedKey: []byte(psk),
2121 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002122 },
David Benjamin48cae082014-10-27 01:06:24 -04002123 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002124 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002125 })
2126 testCases = append(testCases, testCase{
2127 testType: serverTest,
2128 protocol: dtls,
2129 name: "D" + ver.name + "-" + suite.name + "-server",
2130 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002131 MinVersion: ver.version,
2132 MaxVersion: ver.version,
2133 CipherSuites: []uint16{suite.id},
2134 Certificates: []Certificate{cert},
2135 PreSharedKey: []byte(psk),
2136 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002137 },
2138 certFile: certFile,
2139 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002140 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002141 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002142 })
2143 }
Adam Langley95c29f32014-06-20 12:00:00 -07002144 }
David Benjamin2c99d282015-09-01 10:23:00 -04002145
2146 // Ensure both TLS and DTLS accept their maximum record sizes.
2147 testCases = append(testCases, testCase{
2148 name: suite.name + "-LargeRecord",
2149 config: Config{
2150 CipherSuites: []uint16{suite.id},
2151 Certificates: []Certificate{cert},
2152 PreSharedKey: []byte(psk),
2153 PreSharedKeyIdentity: pskIdentity,
2154 },
2155 flags: flags,
2156 messageLen: maxPlaintext,
2157 })
David Benjamin2c99d282015-09-01 10:23:00 -04002158 if isDTLSCipher(suite.name) {
2159 testCases = append(testCases, testCase{
2160 protocol: dtls,
2161 name: suite.name + "-LargeRecord-DTLS",
2162 config: Config{
2163 CipherSuites: []uint16{suite.id},
2164 Certificates: []Certificate{cert},
2165 PreSharedKey: []byte(psk),
2166 PreSharedKeyIdentity: pskIdentity,
2167 },
2168 flags: flags,
2169 messageLen: maxPlaintext,
2170 })
2171 }
Adam Langley95c29f32014-06-20 12:00:00 -07002172 }
Adam Langleya7997f12015-05-14 17:38:50 -07002173
2174 testCases = append(testCases, testCase{
2175 name: "WeakDH",
2176 config: Config{
2177 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2178 Bugs: ProtocolBugs{
2179 // This is a 1023-bit prime number, generated
2180 // with:
2181 // openssl gendh 1023 | openssl asn1parse -i
2182 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2183 },
2184 },
2185 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002186 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002187 })
Adam Langleycef75832015-09-03 14:51:12 -07002188
David Benjamincd24a392015-11-11 13:23:05 -08002189 testCases = append(testCases, testCase{
2190 name: "SillyDH",
2191 config: Config{
2192 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2193 Bugs: ProtocolBugs{
2194 // This is a 4097-bit prime number, generated
2195 // with:
2196 // openssl gendh 4097 | openssl asn1parse -i
2197 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2198 },
2199 },
2200 shouldFail: true,
2201 expectedError: ":DH_P_TOO_LONG:",
2202 })
2203
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002204 // This test ensures that Diffie-Hellman public values are padded with
2205 // zeros so that they're the same length as the prime. This is to avoid
2206 // hitting a bug in yaSSL.
2207 testCases = append(testCases, testCase{
2208 testType: serverTest,
2209 name: "DHPublicValuePadded",
2210 config: Config{
2211 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2212 Bugs: ProtocolBugs{
2213 RequireDHPublicValueLen: (1025 + 7) / 8,
2214 },
2215 },
2216 flags: []string{"-use-sparse-dh-prime"},
2217 })
David Benjamincd24a392015-11-11 13:23:05 -08002218
Adam Langleycef75832015-09-03 14:51:12 -07002219 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2220 // 1.1 specific cipher suite settings. A server is setup with the given
2221 // cipher lists and then a connection is made for each member of
2222 // expectations. The cipher suite that the server selects must match
2223 // the specified one.
2224 var versionSpecificCiphersTest = []struct {
2225 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2226 // expectations is a map from TLS version to cipher suite id.
2227 expectations map[uint16]uint16
2228 }{
2229 {
2230 // Test that the null case (where no version-specific ciphers are set)
2231 // works as expected.
2232 "RC4-SHA:AES128-SHA", // default ciphers
2233 "", // no ciphers specifically for TLS ≥ 1.0
2234 "", // no ciphers specifically for TLS ≥ 1.1
2235 map[uint16]uint16{
2236 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2237 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2238 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2239 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2240 },
2241 },
2242 {
2243 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2244 // cipher.
2245 "RC4-SHA:AES128-SHA", // default
2246 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2247 "", // no ciphers specifically for TLS ≥ 1.1
2248 map[uint16]uint16{
2249 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2250 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2251 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2252 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2253 },
2254 },
2255 {
2256 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2257 // cipher.
2258 "RC4-SHA:AES128-SHA", // default
2259 "", // no ciphers specifically for TLS ≥ 1.0
2260 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2261 map[uint16]uint16{
2262 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2263 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2264 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2265 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2266 },
2267 },
2268 {
2269 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2270 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2271 "RC4-SHA:AES128-SHA", // default
2272 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2273 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2274 map[uint16]uint16{
2275 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2276 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2277 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2278 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2279 },
2280 },
2281 }
2282
2283 for i, test := range versionSpecificCiphersTest {
2284 for version, expectedCipherSuite := range test.expectations {
2285 flags := []string{"-cipher", test.ciphersDefault}
2286 if len(test.ciphersTLS10) > 0 {
2287 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2288 }
2289 if len(test.ciphersTLS11) > 0 {
2290 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2291 }
2292
2293 testCases = append(testCases, testCase{
2294 testType: serverTest,
2295 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2296 config: Config{
2297 MaxVersion: version,
2298 MinVersion: version,
2299 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2300 },
2301 flags: flags,
2302 expectedCipher: expectedCipherSuite,
2303 })
2304 }
2305 }
Adam Langley95c29f32014-06-20 12:00:00 -07002306}
2307
2308func addBadECDSASignatureTests() {
2309 for badR := BadValue(1); badR < NumBadValues; badR++ {
2310 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002311 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002312 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2313 config: Config{
2314 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2315 Certificates: []Certificate{getECDSACertificate()},
2316 Bugs: ProtocolBugs{
2317 BadECDSAR: badR,
2318 BadECDSAS: badS,
2319 },
2320 },
2321 shouldFail: true,
2322 expectedError: "SIGNATURE",
2323 })
2324 }
2325 }
2326}
2327
Adam Langley80842bd2014-06-20 12:00:00 -07002328func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002329 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002330 name: "MaxCBCPadding",
2331 config: Config{
2332 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2333 Bugs: ProtocolBugs{
2334 MaxPadding: true,
2335 },
2336 },
2337 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2338 })
David Benjamin025b3d32014-07-01 19:53:04 -04002339 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002340 name: "BadCBCPadding",
2341 config: Config{
2342 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2343 Bugs: ProtocolBugs{
2344 PaddingFirstByteBad: true,
2345 },
2346 },
2347 shouldFail: true,
2348 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2349 })
2350 // OpenSSL previously had an issue where the first byte of padding in
2351 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002352 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002353 name: "BadCBCPadding255",
2354 config: Config{
2355 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2356 Bugs: ProtocolBugs{
2357 MaxPadding: true,
2358 PaddingFirstByteBadIf255: true,
2359 },
2360 },
2361 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2362 shouldFail: true,
2363 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2364 })
2365}
2366
Kenny Root7fdeaf12014-08-05 15:23:37 -07002367func addCBCSplittingTests() {
2368 testCases = append(testCases, testCase{
2369 name: "CBCRecordSplitting",
2370 config: Config{
2371 MaxVersion: VersionTLS10,
2372 MinVersion: VersionTLS10,
2373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2374 },
David Benjaminac8302a2015-09-01 17:18:15 -04002375 messageLen: -1, // read until EOF
2376 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002377 flags: []string{
2378 "-async",
2379 "-write-different-record-sizes",
2380 "-cbc-record-splitting",
2381 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002382 })
2383 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002384 name: "CBCRecordSplittingPartialWrite",
2385 config: Config{
2386 MaxVersion: VersionTLS10,
2387 MinVersion: VersionTLS10,
2388 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2389 },
2390 messageLen: -1, // read until EOF
2391 flags: []string{
2392 "-async",
2393 "-write-different-record-sizes",
2394 "-cbc-record-splitting",
2395 "-partial-write",
2396 },
2397 })
2398}
2399
David Benjamin636293b2014-07-08 17:59:18 -04002400func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002401 // Add a dummy cert pool to stress certificate authority parsing.
2402 // TODO(davidben): Add tests that those values parse out correctly.
2403 certPool := x509.NewCertPool()
2404 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2405 if err != nil {
2406 panic(err)
2407 }
2408 certPool.AddCert(cert)
2409
David Benjamin636293b2014-07-08 17:59:18 -04002410 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002411 testCases = append(testCases, testCase{
2412 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002413 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002414 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002415 MinVersion: ver.version,
2416 MaxVersion: ver.version,
2417 ClientAuth: RequireAnyClientCert,
2418 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002419 },
2420 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002421 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2422 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002423 },
2424 })
2425 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002426 testType: serverTest,
2427 name: ver.name + "-Server-ClientAuth-RSA",
2428 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002429 MinVersion: ver.version,
2430 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002431 Certificates: []Certificate{rsaCertificate},
2432 },
2433 flags: []string{"-require-any-client-certificate"},
2434 })
David Benjamine098ec22014-08-27 23:13:20 -04002435 if ver.version != VersionSSL30 {
2436 testCases = append(testCases, testCase{
2437 testType: serverTest,
2438 name: ver.name + "-Server-ClientAuth-ECDSA",
2439 config: Config{
2440 MinVersion: ver.version,
2441 MaxVersion: ver.version,
2442 Certificates: []Certificate{ecdsaCertificate},
2443 },
2444 flags: []string{"-require-any-client-certificate"},
2445 })
2446 testCases = append(testCases, testCase{
2447 testType: clientTest,
2448 name: ver.name + "-Client-ClientAuth-ECDSA",
2449 config: Config{
2450 MinVersion: ver.version,
2451 MaxVersion: ver.version,
2452 ClientAuth: RequireAnyClientCert,
2453 ClientCAs: certPool,
2454 },
2455 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002456 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2457 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002458 },
2459 })
2460 }
David Benjamin636293b2014-07-08 17:59:18 -04002461 }
2462}
2463
Adam Langley75712922014-10-10 16:23:43 -07002464func addExtendedMasterSecretTests() {
2465 const expectEMSFlag = "-expect-extended-master-secret"
2466
2467 for _, with := range []bool{false, true} {
2468 prefix := "No"
2469 var flags []string
2470 if with {
2471 prefix = ""
2472 flags = []string{expectEMSFlag}
2473 }
2474
2475 for _, isClient := range []bool{false, true} {
2476 suffix := "-Server"
2477 testType := serverTest
2478 if isClient {
2479 suffix = "-Client"
2480 testType = clientTest
2481 }
2482
2483 for _, ver := range tlsVersions {
2484 test := testCase{
2485 testType: testType,
2486 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2487 config: Config{
2488 MinVersion: ver.version,
2489 MaxVersion: ver.version,
2490 Bugs: ProtocolBugs{
2491 NoExtendedMasterSecret: !with,
2492 RequireExtendedMasterSecret: with,
2493 },
2494 },
David Benjamin48cae082014-10-27 01:06:24 -04002495 flags: flags,
2496 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002497 }
2498 if test.shouldFail {
2499 test.expectedLocalError = "extended master secret required but not supported by peer"
2500 }
2501 testCases = append(testCases, test)
2502 }
2503 }
2504 }
2505
Adam Langleyba5934b2015-06-02 10:50:35 -07002506 for _, isClient := range []bool{false, true} {
2507 for _, supportedInFirstConnection := range []bool{false, true} {
2508 for _, supportedInResumeConnection := range []bool{false, true} {
2509 boolToWord := func(b bool) string {
2510 if b {
2511 return "Yes"
2512 }
2513 return "No"
2514 }
2515 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2516 if isClient {
2517 suffix += "Client"
2518 } else {
2519 suffix += "Server"
2520 }
2521
2522 supportedConfig := Config{
2523 Bugs: ProtocolBugs{
2524 RequireExtendedMasterSecret: true,
2525 },
2526 }
2527
2528 noSupportConfig := Config{
2529 Bugs: ProtocolBugs{
2530 NoExtendedMasterSecret: true,
2531 },
2532 }
2533
2534 test := testCase{
2535 name: "ExtendedMasterSecret-" + suffix,
2536 resumeSession: true,
2537 }
2538
2539 if !isClient {
2540 test.testType = serverTest
2541 }
2542
2543 if supportedInFirstConnection {
2544 test.config = supportedConfig
2545 } else {
2546 test.config = noSupportConfig
2547 }
2548
2549 if supportedInResumeConnection {
2550 test.resumeConfig = &supportedConfig
2551 } else {
2552 test.resumeConfig = &noSupportConfig
2553 }
2554
2555 switch suffix {
2556 case "YesToYes-Client", "YesToYes-Server":
2557 // When a session is resumed, it should
2558 // still be aware that its master
2559 // secret was generated via EMS and
2560 // thus it's safe to use tls-unique.
2561 test.flags = []string{expectEMSFlag}
2562 case "NoToYes-Server":
2563 // If an original connection did not
2564 // contain EMS, but a resumption
2565 // handshake does, then a server should
2566 // not resume the session.
2567 test.expectResumeRejected = true
2568 case "YesToNo-Server":
2569 // Resuming an EMS session without the
2570 // EMS extension should cause the
2571 // server to abort the connection.
2572 test.shouldFail = true
2573 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2574 case "NoToYes-Client":
2575 // A client should abort a connection
2576 // where the server resumed a non-EMS
2577 // session but echoed the EMS
2578 // extension.
2579 test.shouldFail = true
2580 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2581 case "YesToNo-Client":
2582 // A client should abort a connection
2583 // where the server didn't echo EMS
2584 // when the session used it.
2585 test.shouldFail = true
2586 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2587 }
2588
2589 testCases = append(testCases, test)
2590 }
2591 }
2592 }
Adam Langley75712922014-10-10 16:23:43 -07002593}
2594
David Benjamin43ec06f2014-08-05 02:28:57 -04002595// Adds tests that try to cover the range of the handshake state machine, under
2596// various conditions. Some of these are redundant with other tests, but they
2597// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002598func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002599 var tests []testCase
2600
2601 // Basic handshake, with resumption. Client and server,
2602 // session ID and session ticket.
2603 tests = append(tests, testCase{
2604 name: "Basic-Client",
2605 resumeSession: true,
2606 })
2607 tests = append(tests, testCase{
2608 name: "Basic-Client-RenewTicket",
2609 config: Config{
2610 Bugs: ProtocolBugs{
2611 RenewTicketOnResume: true,
2612 },
2613 },
David Benjaminba4594a2015-06-18 18:36:15 -04002614 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002615 resumeSession: true,
2616 })
2617 tests = append(tests, testCase{
2618 name: "Basic-Client-NoTicket",
2619 config: Config{
2620 SessionTicketsDisabled: true,
2621 },
2622 resumeSession: true,
2623 })
2624 tests = append(tests, testCase{
2625 name: "Basic-Client-Implicit",
2626 flags: []string{"-implicit-handshake"},
2627 resumeSession: true,
2628 })
2629 tests = append(tests, testCase{
2630 testType: serverTest,
2631 name: "Basic-Server",
2632 resumeSession: true,
2633 })
2634 tests = append(tests, testCase{
2635 testType: serverTest,
2636 name: "Basic-Server-NoTickets",
2637 config: Config{
2638 SessionTicketsDisabled: true,
2639 },
2640 resumeSession: true,
2641 })
2642 tests = append(tests, testCase{
2643 testType: serverTest,
2644 name: "Basic-Server-Implicit",
2645 flags: []string{"-implicit-handshake"},
2646 resumeSession: true,
2647 })
2648 tests = append(tests, testCase{
2649 testType: serverTest,
2650 name: "Basic-Server-EarlyCallback",
2651 flags: []string{"-use-early-callback"},
2652 resumeSession: true,
2653 })
2654
2655 // TLS client auth.
2656 tests = append(tests, testCase{
2657 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002658 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002659 config: Config{
2660 ClientAuth: RequireAnyClientCert,
2661 },
2662 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002663 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2664 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002665 },
2666 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002667 tests = append(tests, testCase{
2668 testType: clientTest,
2669 name: "ClientAuth-ECDSA-Client",
2670 config: Config{
2671 ClientAuth: RequireAnyClientCert,
2672 },
2673 flags: []string{
2674 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2675 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2676 },
2677 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002678 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002679 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002680 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002681 testType: serverTest,
2682 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002683 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002684 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002685 },
2686 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002687 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2688 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002689 },
2690 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002691 tests = append(tests, testCase{
2692 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002693 name: "Basic-Server-ECDHE-RSA",
2694 config: Config{
2695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2696 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002697 flags: []string{
2698 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2699 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002700 },
2701 })
2702 tests = append(tests, testCase{
2703 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002704 name: "Basic-Server-ECDHE-ECDSA",
2705 config: Config{
2706 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2707 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002708 flags: []string{
2709 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2710 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002711 },
2712 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002713 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002714 tests = append(tests, testCase{
2715 testType: serverTest,
2716 name: "ClientAuth-Server",
2717 config: Config{
2718 Certificates: []Certificate{rsaCertificate},
2719 },
2720 flags: []string{"-require-any-client-certificate"},
2721 })
2722
2723 // No session ticket support; server doesn't send NewSessionTicket.
2724 tests = append(tests, testCase{
2725 name: "SessionTicketsDisabled-Client",
2726 config: Config{
2727 SessionTicketsDisabled: true,
2728 },
2729 })
2730 tests = append(tests, testCase{
2731 testType: serverTest,
2732 name: "SessionTicketsDisabled-Server",
2733 config: Config{
2734 SessionTicketsDisabled: true,
2735 },
2736 })
2737
2738 // Skip ServerKeyExchange in PSK key exchange if there's no
2739 // identity hint.
2740 tests = append(tests, testCase{
2741 name: "EmptyPSKHint-Client",
2742 config: Config{
2743 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2744 PreSharedKey: []byte("secret"),
2745 },
2746 flags: []string{"-psk", "secret"},
2747 })
2748 tests = append(tests, testCase{
2749 testType: serverTest,
2750 name: "EmptyPSKHint-Server",
2751 config: Config{
2752 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2753 PreSharedKey: []byte("secret"),
2754 },
2755 flags: []string{"-psk", "secret"},
2756 })
2757
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002758 tests = append(tests, testCase{
2759 testType: clientTest,
2760 name: "OCSPStapling-Client",
2761 flags: []string{
2762 "-enable-ocsp-stapling",
2763 "-expect-ocsp-response",
2764 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002765 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002766 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002767 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002768 })
2769
2770 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002771 testType: serverTest,
2772 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002773 expectedOCSPResponse: testOCSPResponse,
2774 flags: []string{
2775 "-ocsp-response",
2776 base64.StdEncoding.EncodeToString(testOCSPResponse),
2777 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002778 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002779 })
2780
Paul Lietar8f1c2682015-08-18 12:21:54 +01002781 tests = append(tests, testCase{
2782 testType: clientTest,
2783 name: "CertificateVerificationSucceed",
2784 flags: []string{
2785 "-verify-peer",
2786 },
2787 })
2788
2789 tests = append(tests, testCase{
2790 testType: clientTest,
2791 name: "CertificateVerificationFail",
2792 flags: []string{
2793 "-verify-fail",
2794 "-verify-peer",
2795 },
2796 shouldFail: true,
2797 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2798 })
2799
2800 tests = append(tests, testCase{
2801 testType: clientTest,
2802 name: "CertificateVerificationSoftFail",
2803 flags: []string{
2804 "-verify-fail",
2805 "-expect-verify-result",
2806 },
2807 })
2808
David Benjamin760b1dd2015-05-15 23:33:48 -04002809 if protocol == tls {
2810 tests = append(tests, testCase{
2811 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002812 renegotiate: 1,
2813 flags: []string{
2814 "-renegotiate-freely",
2815 "-expect-total-renegotiations", "1",
2816 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002817 })
2818 // NPN on client and server; results in post-handshake message.
2819 tests = append(tests, testCase{
2820 name: "NPN-Client",
2821 config: Config{
2822 NextProtos: []string{"foo"},
2823 },
2824 flags: []string{"-select-next-proto", "foo"},
2825 expectedNextProto: "foo",
2826 expectedNextProtoType: npn,
2827 })
2828 tests = append(tests, testCase{
2829 testType: serverTest,
2830 name: "NPN-Server",
2831 config: Config{
2832 NextProtos: []string{"bar"},
2833 },
2834 flags: []string{
2835 "-advertise-npn", "\x03foo\x03bar\x03baz",
2836 "-expect-next-proto", "bar",
2837 },
2838 expectedNextProto: "bar",
2839 expectedNextProtoType: npn,
2840 })
2841
2842 // TODO(davidben): Add tests for when False Start doesn't trigger.
2843
2844 // Client does False Start and negotiates NPN.
2845 tests = append(tests, testCase{
2846 name: "FalseStart",
2847 config: Config{
2848 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2849 NextProtos: []string{"foo"},
2850 Bugs: ProtocolBugs{
2851 ExpectFalseStart: true,
2852 },
2853 },
2854 flags: []string{
2855 "-false-start",
2856 "-select-next-proto", "foo",
2857 },
2858 shimWritesFirst: true,
2859 resumeSession: true,
2860 })
2861
2862 // Client does False Start and negotiates ALPN.
2863 tests = append(tests, testCase{
2864 name: "FalseStart-ALPN",
2865 config: Config{
2866 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2867 NextProtos: []string{"foo"},
2868 Bugs: ProtocolBugs{
2869 ExpectFalseStart: true,
2870 },
2871 },
2872 flags: []string{
2873 "-false-start",
2874 "-advertise-alpn", "\x03foo",
2875 },
2876 shimWritesFirst: true,
2877 resumeSession: true,
2878 })
2879
2880 // Client does False Start but doesn't explicitly call
2881 // SSL_connect.
2882 tests = append(tests, testCase{
2883 name: "FalseStart-Implicit",
2884 config: Config{
2885 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2886 NextProtos: []string{"foo"},
2887 },
2888 flags: []string{
2889 "-implicit-handshake",
2890 "-false-start",
2891 "-advertise-alpn", "\x03foo",
2892 },
2893 })
2894
2895 // False Start without session tickets.
2896 tests = append(tests, testCase{
2897 name: "FalseStart-SessionTicketsDisabled",
2898 config: Config{
2899 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2900 NextProtos: []string{"foo"},
2901 SessionTicketsDisabled: true,
2902 Bugs: ProtocolBugs{
2903 ExpectFalseStart: true,
2904 },
2905 },
2906 flags: []string{
2907 "-false-start",
2908 "-select-next-proto", "foo",
2909 },
2910 shimWritesFirst: true,
2911 })
2912
2913 // Server parses a V2ClientHello.
2914 tests = append(tests, testCase{
2915 testType: serverTest,
2916 name: "SendV2ClientHello",
2917 config: Config{
2918 // Choose a cipher suite that does not involve
2919 // elliptic curves, so no extensions are
2920 // involved.
2921 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2922 Bugs: ProtocolBugs{
2923 SendV2ClientHello: true,
2924 },
2925 },
2926 })
2927
2928 // Client sends a Channel ID.
2929 tests = append(tests, testCase{
2930 name: "ChannelID-Client",
2931 config: Config{
2932 RequestChannelID: true,
2933 },
Adam Langley7c803a62015-06-15 15:35:05 -07002934 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002935 resumeSession: true,
2936 expectChannelID: true,
2937 })
2938
2939 // Server accepts a Channel ID.
2940 tests = append(tests, testCase{
2941 testType: serverTest,
2942 name: "ChannelID-Server",
2943 config: Config{
2944 ChannelID: channelIDKey,
2945 },
2946 flags: []string{
2947 "-expect-channel-id",
2948 base64.StdEncoding.EncodeToString(channelIDBytes),
2949 },
2950 resumeSession: true,
2951 expectChannelID: true,
2952 })
David Benjamin30789da2015-08-29 22:56:45 -04002953
2954 // Bidirectional shutdown with the runner initiating.
2955 tests = append(tests, testCase{
2956 name: "Shutdown-Runner",
2957 config: Config{
2958 Bugs: ProtocolBugs{
2959 ExpectCloseNotify: true,
2960 },
2961 },
2962 flags: []string{"-check-close-notify"},
2963 })
2964
2965 // Bidirectional shutdown with the shim initiating. The runner,
2966 // in the meantime, sends garbage before the close_notify which
2967 // the shim must ignore.
2968 tests = append(tests, testCase{
2969 name: "Shutdown-Shim",
2970 config: Config{
2971 Bugs: ProtocolBugs{
2972 ExpectCloseNotify: true,
2973 },
2974 },
2975 shimShutsDown: true,
2976 sendEmptyRecords: 1,
2977 sendWarningAlerts: 1,
2978 flags: []string{"-check-close-notify"},
2979 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002980 } else {
2981 tests = append(tests, testCase{
2982 name: "SkipHelloVerifyRequest",
2983 config: Config{
2984 Bugs: ProtocolBugs{
2985 SkipHelloVerifyRequest: true,
2986 },
2987 },
2988 })
2989 }
2990
David Benjamin760b1dd2015-05-15 23:33:48 -04002991 for _, test := range tests {
2992 test.protocol = protocol
David Benjamin16285ea2015-11-03 15:39:45 -05002993 if protocol == dtls {
2994 test.name += "-DTLS"
2995 }
2996 if async {
2997 test.name += "-Async"
2998 test.flags = append(test.flags, "-async")
2999 } else {
3000 test.name += "-Sync"
3001 }
3002 if splitHandshake {
3003 test.name += "-SplitHandshakeRecords"
3004 test.config.Bugs.MaxHandshakeRecordLength = 1
3005 if protocol == dtls {
3006 test.config.Bugs.MaxPacketLength = 256
3007 test.flags = append(test.flags, "-mtu", "256")
3008 }
3009 }
David Benjamin760b1dd2015-05-15 23:33:48 -04003010 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04003011 }
David Benjamin43ec06f2014-08-05 02:28:57 -04003012}
3013
Adam Langley524e7172015-02-20 16:04:00 -08003014func addDDoSCallbackTests() {
3015 // DDoS callback.
3016
3017 for _, resume := range []bool{false, true} {
3018 suffix := "Resume"
3019 if resume {
3020 suffix = "No" + suffix
3021 }
3022
3023 testCases = append(testCases, testCase{
3024 testType: serverTest,
3025 name: "Server-DDoS-OK-" + suffix,
3026 flags: []string{"-install-ddos-callback"},
3027 resumeSession: resume,
3028 })
3029
3030 failFlag := "-fail-ddos-callback"
3031 if resume {
3032 failFlag = "-fail-second-ddos-callback"
3033 }
3034 testCases = append(testCases, testCase{
3035 testType: serverTest,
3036 name: "Server-DDoS-Reject-" + suffix,
3037 flags: []string{"-install-ddos-callback", failFlag},
3038 resumeSession: resume,
3039 shouldFail: true,
3040 expectedError: ":CONNECTION_REJECTED:",
3041 })
3042 }
3043}
3044
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003045func addVersionNegotiationTests() {
3046 for i, shimVers := range tlsVersions {
3047 // Assemble flags to disable all newer versions on the shim.
3048 var flags []string
3049 for _, vers := range tlsVersions[i+1:] {
3050 flags = append(flags, vers.flag)
3051 }
3052
3053 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003054 protocols := []protocol{tls}
3055 if runnerVers.hasDTLS && shimVers.hasDTLS {
3056 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003057 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003058 for _, protocol := range protocols {
3059 expectedVersion := shimVers.version
3060 if runnerVers.version < shimVers.version {
3061 expectedVersion = runnerVers.version
3062 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003063
David Benjamin8b8c0062014-11-23 02:47:52 -05003064 suffix := shimVers.name + "-" + runnerVers.name
3065 if protocol == dtls {
3066 suffix += "-DTLS"
3067 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003068
David Benjamin1eb367c2014-12-12 18:17:51 -05003069 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3070
David Benjamin1e29a6b2014-12-10 02:27:24 -05003071 clientVers := shimVers.version
3072 if clientVers > VersionTLS10 {
3073 clientVers = VersionTLS10
3074 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003075 testCases = append(testCases, testCase{
3076 protocol: protocol,
3077 testType: clientTest,
3078 name: "VersionNegotiation-Client-" + suffix,
3079 config: Config{
3080 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003081 Bugs: ProtocolBugs{
3082 ExpectInitialRecordVersion: clientVers,
3083 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003084 },
3085 flags: flags,
3086 expectedVersion: expectedVersion,
3087 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003088 testCases = append(testCases, testCase{
3089 protocol: protocol,
3090 testType: clientTest,
3091 name: "VersionNegotiation-Client2-" + suffix,
3092 config: Config{
3093 MaxVersion: runnerVers.version,
3094 Bugs: ProtocolBugs{
3095 ExpectInitialRecordVersion: clientVers,
3096 },
3097 },
3098 flags: []string{"-max-version", shimVersFlag},
3099 expectedVersion: expectedVersion,
3100 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003101
3102 testCases = append(testCases, testCase{
3103 protocol: protocol,
3104 testType: serverTest,
3105 name: "VersionNegotiation-Server-" + suffix,
3106 config: Config{
3107 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003108 Bugs: ProtocolBugs{
3109 ExpectInitialRecordVersion: expectedVersion,
3110 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003111 },
3112 flags: flags,
3113 expectedVersion: expectedVersion,
3114 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003115 testCases = append(testCases, testCase{
3116 protocol: protocol,
3117 testType: serverTest,
3118 name: "VersionNegotiation-Server2-" + suffix,
3119 config: Config{
3120 MaxVersion: runnerVers.version,
3121 Bugs: ProtocolBugs{
3122 ExpectInitialRecordVersion: expectedVersion,
3123 },
3124 },
3125 flags: []string{"-max-version", shimVersFlag},
3126 expectedVersion: expectedVersion,
3127 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003128 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003129 }
3130 }
3131}
3132
David Benjaminaccb4542014-12-12 23:44:33 -05003133func addMinimumVersionTests() {
3134 for i, shimVers := range tlsVersions {
3135 // Assemble flags to disable all older versions on the shim.
3136 var flags []string
3137 for _, vers := range tlsVersions[:i] {
3138 flags = append(flags, vers.flag)
3139 }
3140
3141 for _, runnerVers := range tlsVersions {
3142 protocols := []protocol{tls}
3143 if runnerVers.hasDTLS && shimVers.hasDTLS {
3144 protocols = append(protocols, dtls)
3145 }
3146 for _, protocol := range protocols {
3147 suffix := shimVers.name + "-" + runnerVers.name
3148 if protocol == dtls {
3149 suffix += "-DTLS"
3150 }
3151 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3152
David Benjaminaccb4542014-12-12 23:44:33 -05003153 var expectedVersion uint16
3154 var shouldFail bool
3155 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003156 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003157 if runnerVers.version >= shimVers.version {
3158 expectedVersion = runnerVers.version
3159 } else {
3160 shouldFail = true
3161 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003162 if runnerVers.version > VersionSSL30 {
3163 expectedLocalError = "remote error: protocol version not supported"
3164 } else {
3165 expectedLocalError = "remote error: handshake failure"
3166 }
David Benjaminaccb4542014-12-12 23:44:33 -05003167 }
3168
3169 testCases = append(testCases, testCase{
3170 protocol: protocol,
3171 testType: clientTest,
3172 name: "MinimumVersion-Client-" + suffix,
3173 config: Config{
3174 MaxVersion: runnerVers.version,
3175 },
David Benjamin87909c02014-12-13 01:55:01 -05003176 flags: flags,
3177 expectedVersion: expectedVersion,
3178 shouldFail: shouldFail,
3179 expectedError: expectedError,
3180 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003181 })
3182 testCases = append(testCases, testCase{
3183 protocol: protocol,
3184 testType: clientTest,
3185 name: "MinimumVersion-Client2-" + suffix,
3186 config: Config{
3187 MaxVersion: runnerVers.version,
3188 },
David Benjamin87909c02014-12-13 01:55:01 -05003189 flags: []string{"-min-version", shimVersFlag},
3190 expectedVersion: expectedVersion,
3191 shouldFail: shouldFail,
3192 expectedError: expectedError,
3193 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003194 })
3195
3196 testCases = append(testCases, testCase{
3197 protocol: protocol,
3198 testType: serverTest,
3199 name: "MinimumVersion-Server-" + suffix,
3200 config: Config{
3201 MaxVersion: runnerVers.version,
3202 },
David Benjamin87909c02014-12-13 01:55:01 -05003203 flags: flags,
3204 expectedVersion: expectedVersion,
3205 shouldFail: shouldFail,
3206 expectedError: expectedError,
3207 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003208 })
3209 testCases = append(testCases, testCase{
3210 protocol: protocol,
3211 testType: serverTest,
3212 name: "MinimumVersion-Server2-" + suffix,
3213 config: Config{
3214 MaxVersion: runnerVers.version,
3215 },
David Benjamin87909c02014-12-13 01:55:01 -05003216 flags: []string{"-min-version", shimVersFlag},
3217 expectedVersion: expectedVersion,
3218 shouldFail: shouldFail,
3219 expectedError: expectedError,
3220 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003221 })
3222 }
3223 }
3224 }
3225}
3226
David Benjamine78bfde2014-09-06 12:45:15 -04003227func addExtensionTests() {
3228 testCases = append(testCases, testCase{
3229 testType: clientTest,
3230 name: "DuplicateExtensionClient",
3231 config: Config{
3232 Bugs: ProtocolBugs{
3233 DuplicateExtension: true,
3234 },
3235 },
3236 shouldFail: true,
3237 expectedLocalError: "remote error: error decoding message",
3238 })
3239 testCases = append(testCases, testCase{
3240 testType: serverTest,
3241 name: "DuplicateExtensionServer",
3242 config: Config{
3243 Bugs: ProtocolBugs{
3244 DuplicateExtension: true,
3245 },
3246 },
3247 shouldFail: true,
3248 expectedLocalError: "remote error: error decoding message",
3249 })
3250 testCases = append(testCases, testCase{
3251 testType: clientTest,
3252 name: "ServerNameExtensionClient",
3253 config: Config{
3254 Bugs: ProtocolBugs{
3255 ExpectServerName: "example.com",
3256 },
3257 },
3258 flags: []string{"-host-name", "example.com"},
3259 })
3260 testCases = append(testCases, testCase{
3261 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003262 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003263 config: Config{
3264 Bugs: ProtocolBugs{
3265 ExpectServerName: "mismatch.com",
3266 },
3267 },
3268 flags: []string{"-host-name", "example.com"},
3269 shouldFail: true,
3270 expectedLocalError: "tls: unexpected server name",
3271 })
3272 testCases = append(testCases, testCase{
3273 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003274 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003275 config: Config{
3276 Bugs: ProtocolBugs{
3277 ExpectServerName: "missing.com",
3278 },
3279 },
3280 shouldFail: true,
3281 expectedLocalError: "tls: unexpected server name",
3282 })
3283 testCases = append(testCases, testCase{
3284 testType: serverTest,
3285 name: "ServerNameExtensionServer",
3286 config: Config{
3287 ServerName: "example.com",
3288 },
3289 flags: []string{"-expect-server-name", "example.com"},
3290 resumeSession: true,
3291 })
David Benjaminae2888f2014-09-06 12:58:58 -04003292 testCases = append(testCases, testCase{
3293 testType: clientTest,
3294 name: "ALPNClient",
3295 config: Config{
3296 NextProtos: []string{"foo"},
3297 },
3298 flags: []string{
3299 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3300 "-expect-alpn", "foo",
3301 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003302 expectedNextProto: "foo",
3303 expectedNextProtoType: alpn,
3304 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003305 })
3306 testCases = append(testCases, testCase{
3307 testType: serverTest,
3308 name: "ALPNServer",
3309 config: Config{
3310 NextProtos: []string{"foo", "bar", "baz"},
3311 },
3312 flags: []string{
3313 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3314 "-select-alpn", "foo",
3315 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003316 expectedNextProto: "foo",
3317 expectedNextProtoType: alpn,
3318 resumeSession: true,
3319 })
3320 // Test that the server prefers ALPN over NPN.
3321 testCases = append(testCases, testCase{
3322 testType: serverTest,
3323 name: "ALPNServer-Preferred",
3324 config: Config{
3325 NextProtos: []string{"foo", "bar", "baz"},
3326 },
3327 flags: []string{
3328 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3329 "-select-alpn", "foo",
3330 "-advertise-npn", "\x03foo\x03bar\x03baz",
3331 },
3332 expectedNextProto: "foo",
3333 expectedNextProtoType: alpn,
3334 resumeSession: true,
3335 })
3336 testCases = append(testCases, testCase{
3337 testType: serverTest,
3338 name: "ALPNServer-Preferred-Swapped",
3339 config: Config{
3340 NextProtos: []string{"foo", "bar", "baz"},
3341 Bugs: ProtocolBugs{
3342 SwapNPNAndALPN: true,
3343 },
3344 },
3345 flags: []string{
3346 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3347 "-select-alpn", "foo",
3348 "-advertise-npn", "\x03foo\x03bar\x03baz",
3349 },
3350 expectedNextProto: "foo",
3351 expectedNextProtoType: alpn,
3352 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003353 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003354 var emptyString string
3355 testCases = append(testCases, testCase{
3356 testType: clientTest,
3357 name: "ALPNClient-EmptyProtocolName",
3358 config: Config{
3359 NextProtos: []string{""},
3360 Bugs: ProtocolBugs{
3361 // A server returning an empty ALPN protocol
3362 // should be rejected.
3363 ALPNProtocol: &emptyString,
3364 },
3365 },
3366 flags: []string{
3367 "-advertise-alpn", "\x03foo",
3368 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003369 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003370 expectedError: ":PARSE_TLSEXT:",
3371 })
3372 testCases = append(testCases, testCase{
3373 testType: serverTest,
3374 name: "ALPNServer-EmptyProtocolName",
3375 config: Config{
3376 // A ClientHello containing an empty ALPN protocol
3377 // should be rejected.
3378 NextProtos: []string{"foo", "", "baz"},
3379 },
3380 flags: []string{
3381 "-select-alpn", "foo",
3382 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003383 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003384 expectedError: ":PARSE_TLSEXT:",
3385 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003386 // Test that negotiating both NPN and ALPN is forbidden.
3387 testCases = append(testCases, testCase{
3388 name: "NegotiateALPNAndNPN",
3389 config: Config{
3390 NextProtos: []string{"foo", "bar", "baz"},
3391 Bugs: ProtocolBugs{
3392 NegotiateALPNAndNPN: true,
3393 },
3394 },
3395 flags: []string{
3396 "-advertise-alpn", "\x03foo",
3397 "-select-next-proto", "foo",
3398 },
3399 shouldFail: true,
3400 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3401 })
3402 testCases = append(testCases, testCase{
3403 name: "NegotiateALPNAndNPN-Swapped",
3404 config: Config{
3405 NextProtos: []string{"foo", "bar", "baz"},
3406 Bugs: ProtocolBugs{
3407 NegotiateALPNAndNPN: true,
3408 SwapNPNAndALPN: true,
3409 },
3410 },
3411 flags: []string{
3412 "-advertise-alpn", "\x03foo",
3413 "-select-next-proto", "foo",
3414 },
3415 shouldFail: true,
3416 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3417 })
David Benjamin091c4b92015-10-26 13:33:21 -04003418 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3419 testCases = append(testCases, testCase{
3420 name: "DisableNPN",
3421 config: Config{
3422 NextProtos: []string{"foo"},
3423 },
3424 flags: []string{
3425 "-select-next-proto", "foo",
3426 "-disable-npn",
3427 },
3428 expectNoNextProto: true,
3429 })
Adam Langley38311732014-10-16 19:04:35 -07003430 // Resume with a corrupt ticket.
3431 testCases = append(testCases, testCase{
3432 testType: serverTest,
3433 name: "CorruptTicket",
3434 config: Config{
3435 Bugs: ProtocolBugs{
3436 CorruptTicket: true,
3437 },
3438 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003439 resumeSession: true,
3440 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003441 })
David Benjamind98452d2015-06-16 14:16:23 -04003442 // Test the ticket callback, with and without renewal.
3443 testCases = append(testCases, testCase{
3444 testType: serverTest,
3445 name: "TicketCallback",
3446 resumeSession: true,
3447 flags: []string{"-use-ticket-callback"},
3448 })
3449 testCases = append(testCases, testCase{
3450 testType: serverTest,
3451 name: "TicketCallback-Renew",
3452 config: Config{
3453 Bugs: ProtocolBugs{
3454 ExpectNewTicket: true,
3455 },
3456 },
3457 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3458 resumeSession: true,
3459 })
Adam Langley38311732014-10-16 19:04:35 -07003460 // Resume with an oversized session id.
3461 testCases = append(testCases, testCase{
3462 testType: serverTest,
3463 name: "OversizedSessionId",
3464 config: Config{
3465 Bugs: ProtocolBugs{
3466 OversizedSessionId: true,
3467 },
3468 },
3469 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003470 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003471 expectedError: ":DECODE_ERROR:",
3472 })
David Benjaminca6c8262014-11-15 19:06:08 -05003473 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3474 // are ignored.
3475 testCases = append(testCases, testCase{
3476 protocol: dtls,
3477 name: "SRTP-Client",
3478 config: Config{
3479 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3480 },
3481 flags: []string{
3482 "-srtp-profiles",
3483 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3484 },
3485 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3486 })
3487 testCases = append(testCases, testCase{
3488 protocol: dtls,
3489 testType: serverTest,
3490 name: "SRTP-Server",
3491 config: Config{
3492 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3493 },
3494 flags: []string{
3495 "-srtp-profiles",
3496 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3497 },
3498 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3499 })
3500 // Test that the MKI is ignored.
3501 testCases = append(testCases, testCase{
3502 protocol: dtls,
3503 testType: serverTest,
3504 name: "SRTP-Server-IgnoreMKI",
3505 config: Config{
3506 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3507 Bugs: ProtocolBugs{
3508 SRTPMasterKeyIdentifer: "bogus",
3509 },
3510 },
3511 flags: []string{
3512 "-srtp-profiles",
3513 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3514 },
3515 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3516 })
3517 // Test that SRTP isn't negotiated on the server if there were
3518 // no matching profiles.
3519 testCases = append(testCases, testCase{
3520 protocol: dtls,
3521 testType: serverTest,
3522 name: "SRTP-Server-NoMatch",
3523 config: Config{
3524 SRTPProtectionProfiles: []uint16{100, 101, 102},
3525 },
3526 flags: []string{
3527 "-srtp-profiles",
3528 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3529 },
3530 expectedSRTPProtectionProfile: 0,
3531 })
3532 // Test that the server returning an invalid SRTP profile is
3533 // flagged as an error by the client.
3534 testCases = append(testCases, testCase{
3535 protocol: dtls,
3536 name: "SRTP-Client-NoMatch",
3537 config: Config{
3538 Bugs: ProtocolBugs{
3539 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3540 },
3541 },
3542 flags: []string{
3543 "-srtp-profiles",
3544 "SRTP_AES128_CM_SHA1_80",
3545 },
3546 shouldFail: true,
3547 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3548 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003549 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003550 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003551 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003552 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003553 flags: []string{
3554 "-enable-signed-cert-timestamps",
3555 "-expect-signed-cert-timestamps",
3556 base64.StdEncoding.EncodeToString(testSCTList),
3557 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003558 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003559 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003560 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003561 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003562 testType: serverTest,
3563 flags: []string{
3564 "-signed-cert-timestamps",
3565 base64.StdEncoding.EncodeToString(testSCTList),
3566 },
3567 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003568 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003569 })
3570 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003571 testType: clientTest,
3572 name: "ClientHelloPadding",
3573 config: Config{
3574 Bugs: ProtocolBugs{
3575 RequireClientHelloSize: 512,
3576 },
3577 },
3578 // This hostname just needs to be long enough to push the
3579 // ClientHello into F5's danger zone between 256 and 511 bytes
3580 // long.
3581 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3582 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003583
3584 // Extensions should not function in SSL 3.0.
3585 testCases = append(testCases, testCase{
3586 testType: serverTest,
3587 name: "SSLv3Extensions-NoALPN",
3588 config: Config{
3589 MaxVersion: VersionSSL30,
3590 NextProtos: []string{"foo", "bar", "baz"},
3591 },
3592 flags: []string{
3593 "-select-alpn", "foo",
3594 },
3595 expectNoNextProto: true,
3596 })
3597
3598 // Test session tickets separately as they follow a different codepath.
3599 testCases = append(testCases, testCase{
3600 testType: serverTest,
3601 name: "SSLv3Extensions-NoTickets",
3602 config: Config{
3603 MaxVersion: VersionSSL30,
3604 Bugs: ProtocolBugs{
3605 // Historically, session tickets in SSL 3.0
3606 // failed in different ways depending on whether
3607 // the client supported renegotiation_info.
3608 NoRenegotiationInfo: true,
3609 },
3610 },
3611 resumeSession: true,
3612 })
3613 testCases = append(testCases, testCase{
3614 testType: serverTest,
3615 name: "SSLv3Extensions-NoTickets2",
3616 config: Config{
3617 MaxVersion: VersionSSL30,
3618 },
3619 resumeSession: true,
3620 })
3621
3622 // But SSL 3.0 does send and process renegotiation_info.
3623 testCases = append(testCases, testCase{
3624 testType: serverTest,
3625 name: "SSLv3Extensions-RenegotiationInfo",
3626 config: Config{
3627 MaxVersion: VersionSSL30,
3628 Bugs: ProtocolBugs{
3629 RequireRenegotiationInfo: true,
3630 },
3631 },
3632 })
3633 testCases = append(testCases, testCase{
3634 testType: serverTest,
3635 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3636 config: Config{
3637 MaxVersion: VersionSSL30,
3638 Bugs: ProtocolBugs{
3639 NoRenegotiationInfo: true,
3640 SendRenegotiationSCSV: true,
3641 RequireRenegotiationInfo: true,
3642 },
3643 },
3644 })
David Benjamine78bfde2014-09-06 12:45:15 -04003645}
3646
David Benjamin01fe8202014-09-24 15:21:44 -04003647func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003648 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003649 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003650 protocols := []protocol{tls}
3651 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3652 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003653 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003654 for _, protocol := range protocols {
3655 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3656 if protocol == dtls {
3657 suffix += "-DTLS"
3658 }
3659
David Benjaminece3de92015-03-16 18:02:20 -04003660 if sessionVers.version == resumeVers.version {
3661 testCases = append(testCases, testCase{
3662 protocol: protocol,
3663 name: "Resume-Client" + suffix,
3664 resumeSession: true,
3665 config: Config{
3666 MaxVersion: sessionVers.version,
3667 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003668 },
David Benjaminece3de92015-03-16 18:02:20 -04003669 expectedVersion: sessionVers.version,
3670 expectedResumeVersion: resumeVers.version,
3671 })
3672 } else {
3673 testCases = append(testCases, testCase{
3674 protocol: protocol,
3675 name: "Resume-Client-Mismatch" + suffix,
3676 resumeSession: true,
3677 config: Config{
3678 MaxVersion: sessionVers.version,
3679 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003680 },
David Benjaminece3de92015-03-16 18:02:20 -04003681 expectedVersion: sessionVers.version,
3682 resumeConfig: &Config{
3683 MaxVersion: resumeVers.version,
3684 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3685 Bugs: ProtocolBugs{
3686 AllowSessionVersionMismatch: true,
3687 },
3688 },
3689 expectedResumeVersion: resumeVers.version,
3690 shouldFail: true,
3691 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3692 })
3693 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003694
3695 testCases = append(testCases, testCase{
3696 protocol: protocol,
3697 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003698 resumeSession: true,
3699 config: Config{
3700 MaxVersion: sessionVers.version,
3701 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3702 },
3703 expectedVersion: sessionVers.version,
3704 resumeConfig: &Config{
3705 MaxVersion: resumeVers.version,
3706 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3707 },
3708 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003709 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003710 expectedResumeVersion: resumeVers.version,
3711 })
3712
David Benjamin8b8c0062014-11-23 02:47:52 -05003713 testCases = append(testCases, testCase{
3714 protocol: protocol,
3715 testType: serverTest,
3716 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003717 resumeSession: true,
3718 config: Config{
3719 MaxVersion: sessionVers.version,
3720 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3721 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003722 expectedVersion: sessionVers.version,
3723 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003724 resumeConfig: &Config{
3725 MaxVersion: resumeVers.version,
3726 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3727 },
3728 expectedResumeVersion: resumeVers.version,
3729 })
3730 }
David Benjamin01fe8202014-09-24 15:21:44 -04003731 }
3732 }
David Benjaminece3de92015-03-16 18:02:20 -04003733
3734 testCases = append(testCases, testCase{
3735 name: "Resume-Client-CipherMismatch",
3736 resumeSession: true,
3737 config: Config{
3738 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3739 },
3740 resumeConfig: &Config{
3741 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3742 Bugs: ProtocolBugs{
3743 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3744 },
3745 },
3746 shouldFail: true,
3747 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3748 })
David Benjamin01fe8202014-09-24 15:21:44 -04003749}
3750
Adam Langley2ae77d22014-10-28 17:29:33 -07003751func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003752 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003753 testCases = append(testCases, testCase{
3754 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003755 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003756 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003757 shouldFail: true,
3758 expectedError: ":NO_RENEGOTIATION:",
3759 expectedLocalError: "remote error: no renegotiation",
3760 })
Adam Langley5021b222015-06-12 18:27:58 -07003761 // The server shouldn't echo the renegotiation extension unless
3762 // requested by the client.
3763 testCases = append(testCases, testCase{
3764 testType: serverTest,
3765 name: "Renegotiate-Server-NoExt",
3766 config: Config{
3767 Bugs: ProtocolBugs{
3768 NoRenegotiationInfo: true,
3769 RequireRenegotiationInfo: true,
3770 },
3771 },
3772 shouldFail: true,
3773 expectedLocalError: "renegotiation extension missing",
3774 })
3775 // The renegotiation SCSV should be sufficient for the server to echo
3776 // the extension.
3777 testCases = append(testCases, testCase{
3778 testType: serverTest,
3779 name: "Renegotiate-Server-NoExt-SCSV",
3780 config: Config{
3781 Bugs: ProtocolBugs{
3782 NoRenegotiationInfo: true,
3783 SendRenegotiationSCSV: true,
3784 RequireRenegotiationInfo: true,
3785 },
3786 },
3787 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003788 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003789 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003790 config: Config{
3791 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003792 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003793 },
3794 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003795 renegotiate: 1,
3796 flags: []string{
3797 "-renegotiate-freely",
3798 "-expect-total-renegotiations", "1",
3799 },
David Benjamincdea40c2015-03-19 14:09:43 -04003800 })
3801 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003802 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003803 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003804 config: Config{
3805 Bugs: ProtocolBugs{
3806 EmptyRenegotiationInfo: true,
3807 },
3808 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003809 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003810 shouldFail: true,
3811 expectedError: ":RENEGOTIATION_MISMATCH:",
3812 })
3813 testCases = append(testCases, testCase{
3814 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003815 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003816 config: Config{
3817 Bugs: ProtocolBugs{
3818 BadRenegotiationInfo: true,
3819 },
3820 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003821 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003822 shouldFail: true,
3823 expectedError: ":RENEGOTIATION_MISMATCH:",
3824 })
3825 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05003826 name: "Renegotiate-Client-Downgrade",
3827 renegotiate: 1,
3828 config: Config{
3829 Bugs: ProtocolBugs{
3830 NoRenegotiationInfoAfterInitial: true,
3831 },
3832 },
3833 flags: []string{"-renegotiate-freely"},
3834 shouldFail: true,
3835 expectedError: ":RENEGOTIATION_MISMATCH:",
3836 })
3837 testCases = append(testCases, testCase{
3838 name: "Renegotiate-Client-Upgrade",
3839 renegotiate: 1,
3840 config: Config{
3841 Bugs: ProtocolBugs{
3842 NoRenegotiationInfoInInitial: true,
3843 },
3844 },
3845 flags: []string{"-renegotiate-freely"},
3846 shouldFail: true,
3847 expectedError: ":RENEGOTIATION_MISMATCH:",
3848 })
3849 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04003850 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003851 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003852 config: Config{
3853 Bugs: ProtocolBugs{
3854 NoRenegotiationInfo: true,
3855 },
3856 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003857 flags: []string{
3858 "-renegotiate-freely",
3859 "-expect-total-renegotiations", "1",
3860 },
David Benjamincff0b902015-05-15 23:09:47 -04003861 })
3862 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003863 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003864 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003865 config: Config{
3866 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3867 },
3868 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003869 flags: []string{
3870 "-renegotiate-freely",
3871 "-expect-total-renegotiations", "1",
3872 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003873 })
3874 testCases = append(testCases, testCase{
3875 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003876 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003877 config: Config{
3878 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3879 },
3880 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003881 flags: []string{
3882 "-renegotiate-freely",
3883 "-expect-total-renegotiations", "1",
3884 },
David Benjaminb16346b2015-04-08 19:16:58 -04003885 })
3886 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003887 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003888 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003889 config: Config{
3890 MaxVersion: VersionTLS10,
3891 Bugs: ProtocolBugs{
3892 RequireSameRenegoClientVersion: true,
3893 },
3894 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003895 flags: []string{
3896 "-renegotiate-freely",
3897 "-expect-total-renegotiations", "1",
3898 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003899 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003900 testCases = append(testCases, testCase{
3901 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003902 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003903 config: Config{
3904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3905 NextProtos: []string{"foo"},
3906 },
3907 flags: []string{
3908 "-false-start",
3909 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003910 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003911 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003912 },
3913 shimWritesFirst: true,
3914 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003915
3916 // Client-side renegotiation controls.
3917 testCases = append(testCases, testCase{
3918 name: "Renegotiate-Client-Forbidden-1",
3919 renegotiate: 1,
3920 shouldFail: true,
3921 expectedError: ":NO_RENEGOTIATION:",
3922 expectedLocalError: "remote error: no renegotiation",
3923 })
3924 testCases = append(testCases, testCase{
3925 name: "Renegotiate-Client-Once-1",
3926 renegotiate: 1,
3927 flags: []string{
3928 "-renegotiate-once",
3929 "-expect-total-renegotiations", "1",
3930 },
3931 })
3932 testCases = append(testCases, testCase{
3933 name: "Renegotiate-Client-Freely-1",
3934 renegotiate: 1,
3935 flags: []string{
3936 "-renegotiate-freely",
3937 "-expect-total-renegotiations", "1",
3938 },
3939 })
3940 testCases = append(testCases, testCase{
3941 name: "Renegotiate-Client-Once-2",
3942 renegotiate: 2,
3943 flags: []string{"-renegotiate-once"},
3944 shouldFail: true,
3945 expectedError: ":NO_RENEGOTIATION:",
3946 expectedLocalError: "remote error: no renegotiation",
3947 })
3948 testCases = append(testCases, testCase{
3949 name: "Renegotiate-Client-Freely-2",
3950 renegotiate: 2,
3951 flags: []string{
3952 "-renegotiate-freely",
3953 "-expect-total-renegotiations", "2",
3954 },
3955 })
Adam Langley27a0d082015-11-03 13:34:10 -08003956 testCases = append(testCases, testCase{
3957 name: "Renegotiate-Client-NoIgnore",
3958 config: Config{
3959 Bugs: ProtocolBugs{
3960 SendHelloRequestBeforeEveryAppDataRecord: true,
3961 },
3962 },
3963 shouldFail: true,
3964 expectedError: ":NO_RENEGOTIATION:",
3965 })
3966 testCases = append(testCases, testCase{
3967 name: "Renegotiate-Client-Ignore",
3968 config: Config{
3969 Bugs: ProtocolBugs{
3970 SendHelloRequestBeforeEveryAppDataRecord: true,
3971 },
3972 },
3973 flags: []string{
3974 "-renegotiate-ignore",
3975 "-expect-total-renegotiations", "0",
3976 },
3977 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003978}
3979
David Benjamin5e961c12014-11-07 01:48:35 -05003980func addDTLSReplayTests() {
3981 // Test that sequence number replays are detected.
3982 testCases = append(testCases, testCase{
3983 protocol: dtls,
3984 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003985 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003986 replayWrites: true,
3987 })
3988
David Benjamin8e6db492015-07-25 18:29:23 -04003989 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003990 // than the retransmit window.
3991 testCases = append(testCases, testCase{
3992 protocol: dtls,
3993 name: "DTLS-Replay-LargeGaps",
3994 config: Config{
3995 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003996 SequenceNumberMapping: func(in uint64) uint64 {
3997 return in * 127
3998 },
David Benjamin5e961c12014-11-07 01:48:35 -05003999 },
4000 },
David Benjamin8e6db492015-07-25 18:29:23 -04004001 messageCount: 200,
4002 replayWrites: true,
4003 })
4004
4005 // Test the incoming sequence number changing non-monotonically.
4006 testCases = append(testCases, testCase{
4007 protocol: dtls,
4008 name: "DTLS-Replay-NonMonotonic",
4009 config: Config{
4010 Bugs: ProtocolBugs{
4011 SequenceNumberMapping: func(in uint64) uint64 {
4012 return in ^ 31
4013 },
4014 },
4015 },
4016 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05004017 replayWrites: true,
4018 })
4019}
4020
David Benjamin000800a2014-11-14 01:43:59 -05004021var testHashes = []struct {
4022 name string
4023 id uint8
4024}{
4025 {"SHA1", hashSHA1},
4026 {"SHA224", hashSHA224},
4027 {"SHA256", hashSHA256},
4028 {"SHA384", hashSHA384},
4029 {"SHA512", hashSHA512},
4030}
4031
4032func addSigningHashTests() {
4033 // Make sure each hash works. Include some fake hashes in the list and
4034 // ensure they're ignored.
4035 for _, hash := range testHashes {
4036 testCases = append(testCases, testCase{
4037 name: "SigningHash-ClientAuth-" + hash.name,
4038 config: Config{
4039 ClientAuth: RequireAnyClientCert,
4040 SignatureAndHashes: []signatureAndHash{
4041 {signatureRSA, 42},
4042 {signatureRSA, hash.id},
4043 {signatureRSA, 255},
4044 },
4045 },
4046 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004047 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4048 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004049 },
4050 })
4051
4052 testCases = append(testCases, testCase{
4053 testType: serverTest,
4054 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
4055 config: Config{
4056 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4057 SignatureAndHashes: []signatureAndHash{
4058 {signatureRSA, 42},
4059 {signatureRSA, hash.id},
4060 {signatureRSA, 255},
4061 },
4062 },
4063 })
David Benjamin6e807652015-11-02 12:02:20 -05004064
4065 testCases = append(testCases, testCase{
4066 name: "SigningHash-ServerKeyExchange-Verify-" + hash.name,
4067 config: Config{
4068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4069 SignatureAndHashes: []signatureAndHash{
4070 {signatureRSA, 42},
4071 {signatureRSA, hash.id},
4072 {signatureRSA, 255},
4073 },
4074 },
4075 flags: []string{"-expect-server-key-exchange-hash", strconv.Itoa(int(hash.id))},
4076 })
David Benjamin000800a2014-11-14 01:43:59 -05004077 }
4078
4079 // Test that hash resolution takes the signature type into account.
4080 testCases = append(testCases, testCase{
4081 name: "SigningHash-ClientAuth-SignatureType",
4082 config: Config{
4083 ClientAuth: RequireAnyClientCert,
4084 SignatureAndHashes: []signatureAndHash{
4085 {signatureECDSA, hashSHA512},
4086 {signatureRSA, hashSHA384},
4087 {signatureECDSA, hashSHA1},
4088 },
4089 },
4090 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004093 },
4094 })
4095
4096 testCases = append(testCases, testCase{
4097 testType: serverTest,
4098 name: "SigningHash-ServerKeyExchange-SignatureType",
4099 config: Config{
4100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4101 SignatureAndHashes: []signatureAndHash{
4102 {signatureECDSA, hashSHA512},
4103 {signatureRSA, hashSHA384},
4104 {signatureECDSA, hashSHA1},
4105 },
4106 },
4107 })
4108
4109 // Test that, if the list is missing, the peer falls back to SHA-1.
4110 testCases = append(testCases, testCase{
4111 name: "SigningHash-ClientAuth-Fallback",
4112 config: Config{
4113 ClientAuth: RequireAnyClientCert,
4114 SignatureAndHashes: []signatureAndHash{
4115 {signatureRSA, hashSHA1},
4116 },
4117 Bugs: ProtocolBugs{
4118 NoSignatureAndHashes: true,
4119 },
4120 },
4121 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004122 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4123 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004124 },
4125 })
4126
4127 testCases = append(testCases, testCase{
4128 testType: serverTest,
4129 name: "SigningHash-ServerKeyExchange-Fallback",
4130 config: Config{
4131 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4132 SignatureAndHashes: []signatureAndHash{
4133 {signatureRSA, hashSHA1},
4134 },
4135 Bugs: ProtocolBugs{
4136 NoSignatureAndHashes: true,
4137 },
4138 },
4139 })
David Benjamin72dc7832015-03-16 17:49:43 -04004140
4141 // Test that hash preferences are enforced. BoringSSL defaults to
4142 // rejecting MD5 signatures.
4143 testCases = append(testCases, testCase{
4144 testType: serverTest,
4145 name: "SigningHash-ClientAuth-Enforced",
4146 config: Config{
4147 Certificates: []Certificate{rsaCertificate},
4148 SignatureAndHashes: []signatureAndHash{
4149 {signatureRSA, hashMD5},
4150 // Advertise SHA-1 so the handshake will
4151 // proceed, but the shim's preferences will be
4152 // ignored in CertificateVerify generation, so
4153 // MD5 will be chosen.
4154 {signatureRSA, hashSHA1},
4155 },
4156 Bugs: ProtocolBugs{
4157 IgnorePeerSignatureAlgorithmPreferences: true,
4158 },
4159 },
4160 flags: []string{"-require-any-client-certificate"},
4161 shouldFail: true,
4162 expectedError: ":WRONG_SIGNATURE_TYPE:",
4163 })
4164
4165 testCases = append(testCases, testCase{
4166 name: "SigningHash-ServerKeyExchange-Enforced",
4167 config: Config{
4168 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4169 SignatureAndHashes: []signatureAndHash{
4170 {signatureRSA, hashMD5},
4171 },
4172 Bugs: ProtocolBugs{
4173 IgnorePeerSignatureAlgorithmPreferences: true,
4174 },
4175 },
4176 shouldFail: true,
4177 expectedError: ":WRONG_SIGNATURE_TYPE:",
4178 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004179
4180 // Test that the agreed upon digest respects the client preferences and
4181 // the server digests.
4182 testCases = append(testCases, testCase{
4183 name: "Agree-Digest-Fallback",
4184 config: Config{
4185 ClientAuth: RequireAnyClientCert,
4186 SignatureAndHashes: []signatureAndHash{
4187 {signatureRSA, hashSHA512},
4188 {signatureRSA, hashSHA1},
4189 },
4190 },
4191 flags: []string{
4192 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4193 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4194 },
4195 digestPrefs: "SHA256",
4196 expectedClientCertSignatureHash: hashSHA1,
4197 })
4198 testCases = append(testCases, testCase{
4199 name: "Agree-Digest-SHA256",
4200 config: Config{
4201 ClientAuth: RequireAnyClientCert,
4202 SignatureAndHashes: []signatureAndHash{
4203 {signatureRSA, hashSHA1},
4204 {signatureRSA, hashSHA256},
4205 },
4206 },
4207 flags: []string{
4208 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4209 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4210 },
4211 digestPrefs: "SHA256,SHA1",
4212 expectedClientCertSignatureHash: hashSHA256,
4213 })
4214 testCases = append(testCases, testCase{
4215 name: "Agree-Digest-SHA1",
4216 config: Config{
4217 ClientAuth: RequireAnyClientCert,
4218 SignatureAndHashes: []signatureAndHash{
4219 {signatureRSA, hashSHA1},
4220 },
4221 },
4222 flags: []string{
4223 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4224 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4225 },
4226 digestPrefs: "SHA512,SHA256,SHA1",
4227 expectedClientCertSignatureHash: hashSHA1,
4228 })
4229 testCases = append(testCases, testCase{
4230 name: "Agree-Digest-Default",
4231 config: Config{
4232 ClientAuth: RequireAnyClientCert,
4233 SignatureAndHashes: []signatureAndHash{
4234 {signatureRSA, hashSHA256},
4235 {signatureECDSA, hashSHA256},
4236 {signatureRSA, hashSHA1},
4237 {signatureECDSA, hashSHA1},
4238 },
4239 },
4240 flags: []string{
4241 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4242 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4243 },
4244 expectedClientCertSignatureHash: hashSHA256,
4245 })
David Benjamin000800a2014-11-14 01:43:59 -05004246}
4247
David Benjamin83f90402015-01-27 01:09:43 -05004248// timeouts is the retransmit schedule for BoringSSL. It doubles and
4249// caps at 60 seconds. On the 13th timeout, it gives up.
4250var timeouts = []time.Duration{
4251 1 * time.Second,
4252 2 * time.Second,
4253 4 * time.Second,
4254 8 * time.Second,
4255 16 * time.Second,
4256 32 * time.Second,
4257 60 * time.Second,
4258 60 * time.Second,
4259 60 * time.Second,
4260 60 * time.Second,
4261 60 * time.Second,
4262 60 * time.Second,
4263 60 * time.Second,
4264}
4265
4266func addDTLSRetransmitTests() {
4267 // Test that this is indeed the timeout schedule. Stress all
4268 // four patterns of handshake.
4269 for i := 1; i < len(timeouts); i++ {
4270 number := strconv.Itoa(i)
4271 testCases = append(testCases, testCase{
4272 protocol: dtls,
4273 name: "DTLS-Retransmit-Client-" + number,
4274 config: Config{
4275 Bugs: ProtocolBugs{
4276 TimeoutSchedule: timeouts[:i],
4277 },
4278 },
4279 resumeSession: true,
4280 flags: []string{"-async"},
4281 })
4282 testCases = append(testCases, testCase{
4283 protocol: dtls,
4284 testType: serverTest,
4285 name: "DTLS-Retransmit-Server-" + number,
4286 config: Config{
4287 Bugs: ProtocolBugs{
4288 TimeoutSchedule: timeouts[:i],
4289 },
4290 },
4291 resumeSession: true,
4292 flags: []string{"-async"},
4293 })
4294 }
4295
4296 // Test that exceeding the timeout schedule hits a read
4297 // timeout.
4298 testCases = append(testCases, testCase{
4299 protocol: dtls,
4300 name: "DTLS-Retransmit-Timeout",
4301 config: Config{
4302 Bugs: ProtocolBugs{
4303 TimeoutSchedule: timeouts,
4304 },
4305 },
4306 resumeSession: true,
4307 flags: []string{"-async"},
4308 shouldFail: true,
4309 expectedError: ":READ_TIMEOUT_EXPIRED:",
4310 })
4311
4312 // Test that timeout handling has a fudge factor, due to API
4313 // problems.
4314 testCases = append(testCases, testCase{
4315 protocol: dtls,
4316 name: "DTLS-Retransmit-Fudge",
4317 config: Config{
4318 Bugs: ProtocolBugs{
4319 TimeoutSchedule: []time.Duration{
4320 timeouts[0] - 10*time.Millisecond,
4321 },
4322 },
4323 },
4324 resumeSession: true,
4325 flags: []string{"-async"},
4326 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004327
4328 // Test that the final Finished retransmitting isn't
4329 // duplicated if the peer badly fragments everything.
4330 testCases = append(testCases, testCase{
4331 testType: serverTest,
4332 protocol: dtls,
4333 name: "DTLS-Retransmit-Fragmented",
4334 config: Config{
4335 Bugs: ProtocolBugs{
4336 TimeoutSchedule: []time.Duration{timeouts[0]},
4337 MaxHandshakeRecordLength: 2,
4338 },
4339 },
4340 flags: []string{"-async"},
4341 })
David Benjamin83f90402015-01-27 01:09:43 -05004342}
4343
David Benjaminc565ebb2015-04-03 04:06:36 -04004344func addExportKeyingMaterialTests() {
4345 for _, vers := range tlsVersions {
4346 if vers.version == VersionSSL30 {
4347 continue
4348 }
4349 testCases = append(testCases, testCase{
4350 name: "ExportKeyingMaterial-" + vers.name,
4351 config: Config{
4352 MaxVersion: vers.version,
4353 },
4354 exportKeyingMaterial: 1024,
4355 exportLabel: "label",
4356 exportContext: "context",
4357 useExportContext: true,
4358 })
4359 testCases = append(testCases, testCase{
4360 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4361 config: Config{
4362 MaxVersion: vers.version,
4363 },
4364 exportKeyingMaterial: 1024,
4365 })
4366 testCases = append(testCases, testCase{
4367 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4368 config: Config{
4369 MaxVersion: vers.version,
4370 },
4371 exportKeyingMaterial: 1024,
4372 useExportContext: true,
4373 })
4374 testCases = append(testCases, testCase{
4375 name: "ExportKeyingMaterial-Small-" + vers.name,
4376 config: Config{
4377 MaxVersion: vers.version,
4378 },
4379 exportKeyingMaterial: 1,
4380 exportLabel: "label",
4381 exportContext: "context",
4382 useExportContext: true,
4383 })
4384 }
4385 testCases = append(testCases, testCase{
4386 name: "ExportKeyingMaterial-SSL3",
4387 config: Config{
4388 MaxVersion: VersionSSL30,
4389 },
4390 exportKeyingMaterial: 1024,
4391 exportLabel: "label",
4392 exportContext: "context",
4393 useExportContext: true,
4394 shouldFail: true,
4395 expectedError: "failed to export keying material",
4396 })
4397}
4398
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004399func addTLSUniqueTests() {
4400 for _, isClient := range []bool{false, true} {
4401 for _, isResumption := range []bool{false, true} {
4402 for _, hasEMS := range []bool{false, true} {
4403 var suffix string
4404 if isResumption {
4405 suffix = "Resume-"
4406 } else {
4407 suffix = "Full-"
4408 }
4409
4410 if hasEMS {
4411 suffix += "EMS-"
4412 } else {
4413 suffix += "NoEMS-"
4414 }
4415
4416 if isClient {
4417 suffix += "Client"
4418 } else {
4419 suffix += "Server"
4420 }
4421
4422 test := testCase{
4423 name: "TLSUnique-" + suffix,
4424 testTLSUnique: true,
4425 config: Config{
4426 Bugs: ProtocolBugs{
4427 NoExtendedMasterSecret: !hasEMS,
4428 },
4429 },
4430 }
4431
4432 if isResumption {
4433 test.resumeSession = true
4434 test.resumeConfig = &Config{
4435 Bugs: ProtocolBugs{
4436 NoExtendedMasterSecret: !hasEMS,
4437 },
4438 }
4439 }
4440
4441 if isResumption && !hasEMS {
4442 test.shouldFail = true
4443 test.expectedError = "failed to get tls-unique"
4444 }
4445
4446 testCases = append(testCases, test)
4447 }
4448 }
4449 }
4450}
4451
Adam Langley09505632015-07-30 18:10:13 -07004452func addCustomExtensionTests() {
4453 expectedContents := "custom extension"
4454 emptyString := ""
4455
4456 for _, isClient := range []bool{false, true} {
4457 suffix := "Server"
4458 flag := "-enable-server-custom-extension"
4459 testType := serverTest
4460 if isClient {
4461 suffix = "Client"
4462 flag = "-enable-client-custom-extension"
4463 testType = clientTest
4464 }
4465
4466 testCases = append(testCases, testCase{
4467 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004468 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004469 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004470 Bugs: ProtocolBugs{
4471 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004472 ExpectedCustomExtension: &expectedContents,
4473 },
4474 },
4475 flags: []string{flag},
4476 })
4477
4478 // If the parse callback fails, the handshake should also fail.
4479 testCases = append(testCases, testCase{
4480 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004481 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004482 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004483 Bugs: ProtocolBugs{
4484 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004485 ExpectedCustomExtension: &expectedContents,
4486 },
4487 },
David Benjamin399e7c92015-07-30 23:01:27 -04004488 flags: []string{flag},
4489 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004490 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4491 })
4492
4493 // If the add callback fails, the handshake should also fail.
4494 testCases = append(testCases, testCase{
4495 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004496 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004497 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004498 Bugs: ProtocolBugs{
4499 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004500 ExpectedCustomExtension: &expectedContents,
4501 },
4502 },
David Benjamin399e7c92015-07-30 23:01:27 -04004503 flags: []string{flag, "-custom-extension-fail-add"},
4504 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004505 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4506 })
4507
4508 // If the add callback returns zero, no extension should be
4509 // added.
4510 skipCustomExtension := expectedContents
4511 if isClient {
4512 // For the case where the client skips sending the
4513 // custom extension, the server must not “echo” it.
4514 skipCustomExtension = ""
4515 }
4516 testCases = append(testCases, testCase{
4517 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004518 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004519 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004520 Bugs: ProtocolBugs{
4521 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004522 ExpectedCustomExtension: &emptyString,
4523 },
4524 },
4525 flags: []string{flag, "-custom-extension-skip"},
4526 })
4527 }
4528
4529 // The custom extension add callback should not be called if the client
4530 // doesn't send the extension.
4531 testCases = append(testCases, testCase{
4532 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004533 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004534 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004535 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004536 ExpectedCustomExtension: &emptyString,
4537 },
4538 },
4539 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4540 })
Adam Langley2deb9842015-08-07 11:15:37 -07004541
4542 // Test an unknown extension from the server.
4543 testCases = append(testCases, testCase{
4544 testType: clientTest,
4545 name: "UnknownExtension-Client",
4546 config: Config{
4547 Bugs: ProtocolBugs{
4548 CustomExtension: expectedContents,
4549 },
4550 },
4551 shouldFail: true,
4552 expectedError: ":UNEXPECTED_EXTENSION:",
4553 })
Adam Langley09505632015-07-30 18:10:13 -07004554}
4555
David Benjaminb36a3952015-12-01 18:53:13 -05004556func addRSAClientKeyExchangeTests() {
4557 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
4558 testCases = append(testCases, testCase{
4559 testType: serverTest,
4560 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
4561 config: Config{
4562 // Ensure the ClientHello version and final
4563 // version are different, to detect if the
4564 // server uses the wrong one.
4565 MaxVersion: VersionTLS11,
4566 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
4567 Bugs: ProtocolBugs{
4568 BadRSAClientKeyExchange: bad,
4569 },
4570 },
4571 shouldFail: true,
4572 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
4573 })
4574 }
4575}
4576
Adam Langley7c803a62015-06-15 15:35:05 -07004577func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004578 defer wg.Done()
4579
4580 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004581 var err error
4582
4583 if *mallocTest < 0 {
4584 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004585 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004586 } else {
4587 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4588 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004589 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004590 if err != nil {
4591 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4592 }
4593 break
4594 }
4595 }
4596 }
Adam Langley95c29f32014-06-20 12:00:00 -07004597 statusChan <- statusMsg{test: test, err: err}
4598 }
4599}
4600
4601type statusMsg struct {
4602 test *testCase
4603 started bool
4604 err error
4605}
4606
David Benjamin5f237bc2015-02-11 17:14:15 -05004607func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004608 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004609
David Benjamin5f237bc2015-02-11 17:14:15 -05004610 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004611 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004612 if !*pipe {
4613 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004614 var erase string
4615 for i := 0; i < lineLen; i++ {
4616 erase += "\b \b"
4617 }
4618 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004619 }
4620
Adam Langley95c29f32014-06-20 12:00:00 -07004621 if msg.started {
4622 started++
4623 } else {
4624 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004625
4626 if msg.err != nil {
4627 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4628 failed++
4629 testOutput.addResult(msg.test.name, "FAIL")
4630 } else {
4631 if *pipe {
4632 // Print each test instead of a status line.
4633 fmt.Printf("PASSED (%s)\n", msg.test.name)
4634 }
4635 testOutput.addResult(msg.test.name, "PASS")
4636 }
Adam Langley95c29f32014-06-20 12:00:00 -07004637 }
4638
David Benjamin5f237bc2015-02-11 17:14:15 -05004639 if !*pipe {
4640 // Print a new status line.
4641 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4642 lineLen = len(line)
4643 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004644 }
Adam Langley95c29f32014-06-20 12:00:00 -07004645 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004646
4647 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004648}
4649
4650func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004651 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004652 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004653
Adam Langley7c803a62015-06-15 15:35:05 -07004654 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004655 addCipherSuiteTests()
4656 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004657 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004658 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004659 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004660 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004661 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004662 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004663 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004664 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004665 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004666 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004667 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004668 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004669 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004670 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004671 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004672 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05004673 addRSAClientKeyExchangeTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004674 for _, async := range []bool{false, true} {
4675 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004676 for _, protocol := range []protocol{tls, dtls} {
4677 addStateMachineCoverageTests(async, splitHandshake, protocol)
4678 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004679 }
4680 }
Adam Langley95c29f32014-06-20 12:00:00 -07004681
4682 var wg sync.WaitGroup
4683
Adam Langley7c803a62015-06-15 15:35:05 -07004684 statusChan := make(chan statusMsg, *numWorkers)
4685 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004686 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004687
David Benjamin025b3d32014-07-01 19:53:04 -04004688 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004689
Adam Langley7c803a62015-06-15 15:35:05 -07004690 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004691 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004692 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004693 }
4694
David Benjamin025b3d32014-07-01 19:53:04 -04004695 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004696 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004697 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004698 }
4699 }
4700
4701 close(testChan)
4702 wg.Wait()
4703 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004704 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004705
4706 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004707
4708 if *jsonOutput != "" {
4709 if err := testOutput.writeTo(*jsonOutput); err != nil {
4710 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4711 }
4712 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004713
4714 if !testOutput.allPassed {
4715 os.Exit(1)
4716 }
Adam Langley95c29f32014-06-20 12:00:00 -07004717}