blob: 17fdff94f37b98abd8609e29027b7e6945e5fd53 [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 Benjamin65ea8ff2014-11-23 03:01:00 -0500247 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500248 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500249 if *flagDebug {
250 connDebug = &recordingConn{Conn: conn}
251 conn = connDebug
252 defer func() {
253 connDebug.WriteTo(os.Stdout)
254 }()
255 }
256
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500258 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
259 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500260 if test.replayWrites {
261 conn = newReplayAdaptor(conn)
262 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400263 }
264
David Benjamin5fa3eba2015-01-22 16:35:40 -0500265 if test.damageFirstWrite {
266 connDamage = newDamageAdaptor(conn)
267 conn = connDamage
268 }
269
David Benjamin6fd297b2014-08-11 18:43:38 -0400270 if test.sendPrefix != "" {
271 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
272 return err
273 }
David Benjamin98e882e2014-08-08 13:24:34 -0400274 }
275
David Benjamin1d5c83e2014-07-22 19:20:02 -0400276 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400277 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400278 if test.protocol == dtls {
279 tlsConn = DTLSServer(conn, config)
280 } else {
281 tlsConn = Server(conn, config)
282 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400283 } else {
284 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400285 if test.protocol == dtls {
286 tlsConn = DTLSClient(conn, config)
287 } else {
288 tlsConn = Client(conn, config)
289 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400290 }
David Benjamin30789da2015-08-29 22:56:45 -0400291 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400292
Adam Langley95c29f32014-06-20 12:00:00 -0700293 if err := tlsConn.Handshake(); err != nil {
294 return err
295 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700296
David Benjamin01fe8202014-09-24 15:21:44 -0400297 // TODO(davidben): move all per-connection expectations into a dedicated
298 // expectations struct that can be specified separately for the two
299 // legs.
300 expectedVersion := test.expectedVersion
301 if isResume && test.expectedResumeVersion != 0 {
302 expectedVersion = test.expectedResumeVersion
303 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700304 connState := tlsConn.ConnectionState()
305 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400306 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400307 }
308
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700309 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400310 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
311 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700312 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
313 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
314 }
David Benjamin90da8c82015-04-20 14:57:57 -0400315
David Benjamina08e49d2014-08-24 01:46:07 -0400316 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700317 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400318 if channelID == nil {
319 return fmt.Errorf("no channel ID negotiated")
320 }
321 if channelID.Curve != channelIDKey.Curve ||
322 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
323 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
324 return fmt.Errorf("incorrect channel ID")
325 }
326 }
327
David Benjaminae2888f2014-09-06 12:58:58 -0400328 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700329 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400330 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
331 }
332 }
333
David Benjaminc7ce9772015-10-09 19:32:41 -0400334 if test.expectNoNextProto {
335 if actual := connState.NegotiatedProtocol; actual != "" {
336 return fmt.Errorf("got unexpected next proto %s", actual)
337 }
338 }
339
David Benjaminfc7b0862014-09-06 13:21:53 -0400340 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700341 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400342 return fmt.Errorf("next proto type mismatch")
343 }
344 }
345
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700346 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500347 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
348 }
349
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100350 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
351 return fmt.Errorf("OCSP Response mismatch")
352 }
353
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
355 return fmt.Errorf("SCT list mismatch")
356 }
357
Steven Valdez0d62f262015-09-04 12:41:04 -0400358 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
359 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
360 }
361
David Benjaminc565ebb2015-04-03 04:06:36 -0400362 if test.exportKeyingMaterial > 0 {
363 actual := make([]byte, test.exportKeyingMaterial)
364 if _, err := io.ReadFull(tlsConn, actual); err != nil {
365 return err
366 }
367 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
368 if err != nil {
369 return err
370 }
371 if !bytes.Equal(actual, expected) {
372 return fmt.Errorf("keying material mismatch")
373 }
374 }
375
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700376 if test.testTLSUnique {
377 var peersValue [12]byte
378 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
379 return err
380 }
381 expected := tlsConn.ConnectionState().TLSUnique
382 if !bytes.Equal(peersValue[:], expected) {
383 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
384 }
385 }
386
David Benjamine58c4f52014-08-24 03:47:07 -0400387 if test.shimWritesFirst {
388 var buf [5]byte
389 _, err := io.ReadFull(tlsConn, buf[:])
390 if err != nil {
391 return err
392 }
393 if string(buf[:]) != "hello" {
394 return fmt.Errorf("bad initial message")
395 }
396 }
397
David Benjamina8ebe222015-06-06 03:04:39 -0400398 for i := 0; i < test.sendEmptyRecords; i++ {
399 tlsConn.Write(nil)
400 }
401
David Benjamin24f346d2015-06-06 03:28:08 -0400402 for i := 0; i < test.sendWarningAlerts; i++ {
403 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
404 }
405
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400406 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700407 if test.renegotiateCiphers != nil {
408 config.CipherSuites = test.renegotiateCiphers
409 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400410 for i := 0; i < test.renegotiate; i++ {
411 if err := tlsConn.Renegotiate(); err != nil {
412 return err
413 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700414 }
415 } else if test.renegotiateCiphers != nil {
416 panic("renegotiateCiphers without renegotiate")
417 }
418
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 if test.damageFirstWrite {
420 connDamage.setDamage(true)
421 tlsConn.Write([]byte("DAMAGED WRITE"))
422 connDamage.setDamage(false)
423 }
424
David Benjamin8e6db492015-07-25 18:29:23 -0400425 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700426 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400427 if test.protocol == dtls {
428 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
429 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700430 // Read until EOF.
431 _, err := io.Copy(ioutil.Discard, tlsConn)
432 return err
433 }
David Benjamin4417d052015-04-05 04:17:25 -0400434 if messageLen == 0 {
435 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700436 }
Adam Langley95c29f32014-06-20 12:00:00 -0700437
David Benjamin8e6db492015-07-25 18:29:23 -0400438 messageCount := test.messageCount
439 if messageCount == 0 {
440 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400441 }
442
David Benjamin8e6db492015-07-25 18:29:23 -0400443 for j := 0; j < messageCount; j++ {
444 testMessage := make([]byte, messageLen)
445 for i := range testMessage {
446 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400447 }
David Benjamin8e6db492015-07-25 18:29:23 -0400448 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700449
David Benjamin8e6db492015-07-25 18:29:23 -0400450 for i := 0; i < test.sendEmptyRecords; i++ {
451 tlsConn.Write(nil)
452 }
453
454 for i := 0; i < test.sendWarningAlerts; i++ {
455 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
456 }
457
David Benjamin4f75aaf2015-09-01 16:53:10 -0400458 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400459 // The shim will not respond.
460 continue
461 }
462
David Benjamin8e6db492015-07-25 18:29:23 -0400463 buf := make([]byte, len(testMessage))
464 if test.protocol == dtls {
465 bufTmp := make([]byte, len(buf)+1)
466 n, err := tlsConn.Read(bufTmp)
467 if err != nil {
468 return err
469 }
470 if n != len(buf) {
471 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
472 }
473 copy(buf, bufTmp)
474 } else {
475 _, err := io.ReadFull(tlsConn, buf)
476 if err != nil {
477 return err
478 }
479 }
480
481 for i, v := range buf {
482 if v != testMessage[i]^0xff {
483 return fmt.Errorf("bad reply contents at byte %d", i)
484 }
Adam Langley95c29f32014-06-20 12:00:00 -0700485 }
486 }
487
488 return nil
489}
490
David Benjamin325b5c32014-07-01 19:40:31 -0400491func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
492 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700493 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400494 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700495 }
David Benjamin325b5c32014-07-01 19:40:31 -0400496 valgrindArgs = append(valgrindArgs, path)
497 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700498
David Benjamin325b5c32014-07-01 19:40:31 -0400499 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700500}
501
David Benjamin325b5c32014-07-01 19:40:31 -0400502func gdbOf(path string, args ...string) *exec.Cmd {
503 xtermArgs := []string{"-e", "gdb", "--args"}
504 xtermArgs = append(xtermArgs, path)
505 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700506
David Benjamin325b5c32014-07-01 19:40:31 -0400507 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700508}
509
Adam Langley69a01602014-11-17 17:26:55 -0800510type moreMallocsError struct{}
511
512func (moreMallocsError) Error() string {
513 return "child process did not exhaust all allocation calls"
514}
515
516var errMoreMallocs = moreMallocsError{}
517
David Benjamin87c8a642015-02-21 01:54:29 -0500518// accept accepts a connection from listener, unless waitChan signals a process
519// exit first.
520func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
521 type connOrError struct {
522 conn net.Conn
523 err error
524 }
525 connChan := make(chan connOrError, 1)
526 go func() {
527 conn, err := listener.Accept()
528 connChan <- connOrError{conn, err}
529 close(connChan)
530 }()
531 select {
532 case result := <-connChan:
533 return result.conn, result.err
534 case childErr := <-waitChan:
535 waitChan <- childErr
536 return nil, fmt.Errorf("child exited early: %s", childErr)
537 }
538}
539
Adam Langley7c803a62015-06-15 15:35:05 -0700540func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700541 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
542 panic("Error expected without shouldFail in " + test.name)
543 }
544
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if test.expectResumeRejected && !test.resumeSession {
546 panic("expectResumeRejected without resumeSession in " + test.name)
547 }
548
Steven Valdez0d62f262015-09-04 12:41:04 -0400549 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
550 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
551 }
552
David Benjamin87c8a642015-02-21 01:54:29 -0500553 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
554 if err != nil {
555 panic(err)
556 }
557 defer func() {
558 if listener != nil {
559 listener.Close()
560 }
561 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700562
David Benjamin87c8a642015-02-21 01:54:29 -0500563 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400564 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400565 flags = append(flags, "-server")
566
David Benjamin025b3d32014-07-01 19:53:04 -0400567 flags = append(flags, "-key-file")
568 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700569 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400570 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700571 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400572 }
573
574 flags = append(flags, "-cert-file")
575 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700576 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400577 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700578 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400579 }
580 }
David Benjamin5a593af2014-08-11 19:51:50 -0400581
Steven Valdez0d62f262015-09-04 12:41:04 -0400582 if test.digestPrefs != "" {
583 flags = append(flags, "-digest-prefs")
584 flags = append(flags, test.digestPrefs)
585 }
586
David Benjamin6fd297b2014-08-11 18:43:38 -0400587 if test.protocol == dtls {
588 flags = append(flags, "-dtls")
589 }
590
David Benjamin5a593af2014-08-11 19:51:50 -0400591 if test.resumeSession {
592 flags = append(flags, "-resume")
593 }
594
David Benjamine58c4f52014-08-24 03:47:07 -0400595 if test.shimWritesFirst {
596 flags = append(flags, "-shim-writes-first")
597 }
598
David Benjamin30789da2015-08-29 22:56:45 -0400599 if test.shimShutsDown {
600 flags = append(flags, "-shim-shuts-down")
601 }
602
David Benjaminc565ebb2015-04-03 04:06:36 -0400603 if test.exportKeyingMaterial > 0 {
604 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
605 flags = append(flags, "-export-label", test.exportLabel)
606 flags = append(flags, "-export-context", test.exportContext)
607 if test.useExportContext {
608 flags = append(flags, "-use-export-context")
609 }
610 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700611 if test.expectResumeRejected {
612 flags = append(flags, "-expect-session-miss")
613 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400614
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700615 if test.testTLSUnique {
616 flags = append(flags, "-tls-unique")
617 }
618
David Benjamin025b3d32014-07-01 19:53:04 -0400619 flags = append(flags, test.flags...)
620
621 var shim *exec.Cmd
622 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700623 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700624 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700625 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400626 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700627 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400628 }
David Benjamin025b3d32014-07-01 19:53:04 -0400629 shim.Stdin = os.Stdin
630 var stdoutBuf, stderrBuf bytes.Buffer
631 shim.Stdout = &stdoutBuf
632 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800633 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500634 shim.Env = os.Environ()
635 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800636 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400637 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800638 }
639 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
640 }
David Benjamin025b3d32014-07-01 19:53:04 -0400641
642 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700643 panic(err)
644 }
David Benjamin87c8a642015-02-21 01:54:29 -0500645 waitChan := make(chan error, 1)
646 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700647
648 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400649 if !test.noSessionCache {
650 config.ClientSessionCache = NewLRUClientSessionCache(1)
651 config.ServerSessionCache = NewLRUServerSessionCache(1)
652 }
David Benjamin025b3d32014-07-01 19:53:04 -0400653 if test.testType == clientTest {
654 if len(config.Certificates) == 0 {
655 config.Certificates = []Certificate{getRSACertificate()}
656 }
David Benjamin87c8a642015-02-21 01:54:29 -0500657 } else {
658 // Supply a ServerName to ensure a constant session cache key,
659 // rather than falling back to net.Conn.RemoteAddr.
660 if len(config.ServerName) == 0 {
661 config.ServerName = "test"
662 }
David Benjamin025b3d32014-07-01 19:53:04 -0400663 }
Adam Langley95c29f32014-06-20 12:00:00 -0700664
David Benjamin87c8a642015-02-21 01:54:29 -0500665 conn, err := acceptOrWait(listener, waitChan)
666 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400667 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500668 conn.Close()
669 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500670
David Benjamin1d5c83e2014-07-22 19:20:02 -0400671 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400672 var resumeConfig Config
673 if test.resumeConfig != nil {
674 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500675 if len(resumeConfig.ServerName) == 0 {
676 resumeConfig.ServerName = config.ServerName
677 }
David Benjamin01fe8202014-09-24 15:21:44 -0400678 if len(resumeConfig.Certificates) == 0 {
679 resumeConfig.Certificates = []Certificate{getRSACertificate()}
680 }
David Benjaminba4594a2015-06-18 18:36:15 -0400681 if test.newSessionsOnResume {
682 if !test.noSessionCache {
683 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
684 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
685 }
686 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500687 resumeConfig.SessionTicketKey = config.SessionTicketKey
688 resumeConfig.ClientSessionCache = config.ClientSessionCache
689 resumeConfig.ServerSessionCache = config.ServerSessionCache
690 }
David Benjamin01fe8202014-09-24 15:21:44 -0400691 } else {
692 resumeConfig = config
693 }
David Benjamin87c8a642015-02-21 01:54:29 -0500694 var connResume net.Conn
695 connResume, err = acceptOrWait(listener, waitChan)
696 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400697 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500698 connResume.Close()
699 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400700 }
701
David Benjamin87c8a642015-02-21 01:54:29 -0500702 // Close the listener now. This is to avoid hangs should the shim try to
703 // open more connections than expected.
704 listener.Close()
705 listener = nil
706
707 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800708 if exitError, ok := childErr.(*exec.ExitError); ok {
709 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
710 return errMoreMallocs
711 }
712 }
Adam Langley95c29f32014-06-20 12:00:00 -0700713
714 stdout := string(stdoutBuf.Bytes())
715 stderr := string(stderrBuf.Bytes())
716 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400717 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700718 localError := "none"
719 if err != nil {
720 localError = err.Error()
721 }
722 if len(test.expectedLocalError) != 0 {
723 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
724 }
Adam Langley95c29f32014-06-20 12:00:00 -0700725
726 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700727 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700728 if childErr != nil {
729 childError = childErr.Error()
730 }
731
732 var msg string
733 switch {
734 case failed && !test.shouldFail:
735 msg = "unexpected failure"
736 case !failed && test.shouldFail:
737 msg = "unexpected success"
738 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700739 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700740 default:
741 panic("internal error")
742 }
743
David Benjaminc565ebb2015-04-03 04:06:36 -0400744 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 -0700745 }
746
David Benjaminc565ebb2015-04-03 04:06:36 -0400747 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700748 println(stderr)
749 }
750
751 return nil
752}
753
754var tlsVersions = []struct {
755 name string
756 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400757 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500758 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700759}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500760 {"SSL3", VersionSSL30, "-no-ssl3", false},
761 {"TLS1", VersionTLS10, "-no-tls1", true},
762 {"TLS11", VersionTLS11, "-no-tls11", false},
763 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700764}
765
766var testCipherSuites = []struct {
767 name string
768 id uint16
769}{
770 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400771 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700772 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400773 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400774 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700775 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400776 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400777 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
778 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400779 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400780 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
781 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400782 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700783 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
784 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400785 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
786 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700787 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400788 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400789 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700790 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700791 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700792 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400793 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400794 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700795 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400796 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400797 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700798 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400799 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
800 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700801 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
802 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400803 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700804 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400805 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700806 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700807}
808
David Benjamin8b8c0062014-11-23 02:47:52 -0500809func hasComponent(suiteName, component string) bool {
810 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
811}
812
David Benjaminf7768e42014-08-31 02:06:47 -0400813func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500814 return hasComponent(suiteName, "GCM") ||
815 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400816 hasComponent(suiteName, "SHA384") ||
817 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500818}
819
820func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700821 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400822}
823
Adam Langleya7997f12015-05-14 17:38:50 -0700824func bigFromHex(hex string) *big.Int {
825 ret, ok := new(big.Int).SetString(hex, 16)
826 if !ok {
827 panic("failed to parse hex number 0x" + hex)
828 }
829 return ret
830}
831
Adam Langley7c803a62015-06-15 15:35:05 -0700832func addBasicTests() {
833 basicTests := []testCase{
834 {
835 name: "BadRSASignature",
836 config: Config{
837 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
838 Bugs: ProtocolBugs{
839 InvalidSKXSignature: true,
840 },
841 },
842 shouldFail: true,
843 expectedError: ":BAD_SIGNATURE:",
844 },
845 {
846 name: "BadECDSASignature",
847 config: Config{
848 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
849 Bugs: ProtocolBugs{
850 InvalidSKXSignature: true,
851 },
852 Certificates: []Certificate{getECDSACertificate()},
853 },
854 shouldFail: true,
855 expectedError: ":BAD_SIGNATURE:",
856 },
857 {
David Benjamin6de0e532015-07-28 22:43:19 -0400858 testType: serverTest,
859 name: "BadRSASignature-ClientAuth",
860 config: Config{
861 Bugs: ProtocolBugs{
862 InvalidCertVerifySignature: true,
863 },
864 Certificates: []Certificate{getRSACertificate()},
865 },
866 shouldFail: true,
867 expectedError: ":BAD_SIGNATURE:",
868 flags: []string{"-require-any-client-certificate"},
869 },
870 {
871 testType: serverTest,
872 name: "BadECDSASignature-ClientAuth",
873 config: Config{
874 Bugs: ProtocolBugs{
875 InvalidCertVerifySignature: true,
876 },
877 Certificates: []Certificate{getECDSACertificate()},
878 },
879 shouldFail: true,
880 expectedError: ":BAD_SIGNATURE:",
881 flags: []string{"-require-any-client-certificate"},
882 },
883 {
Adam Langley7c803a62015-06-15 15:35:05 -0700884 name: "BadECDSACurve",
885 config: Config{
886 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
887 Bugs: ProtocolBugs{
888 InvalidSKXCurve: true,
889 },
890 Certificates: []Certificate{getECDSACertificate()},
891 },
892 shouldFail: true,
893 expectedError: ":WRONG_CURVE:",
894 },
895 {
896 testType: serverTest,
897 name: "BadRSAVersion",
898 config: Config{
899 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
900 Bugs: ProtocolBugs{
901 RsaClientKeyExchangeVersion: VersionTLS11,
902 },
903 },
904 shouldFail: true,
905 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
906 },
907 {
908 name: "NoFallbackSCSV",
909 config: Config{
910 Bugs: ProtocolBugs{
911 FailIfNotFallbackSCSV: true,
912 },
913 },
914 shouldFail: true,
915 expectedLocalError: "no fallback SCSV found",
916 },
917 {
918 name: "SendFallbackSCSV",
919 config: Config{
920 Bugs: ProtocolBugs{
921 FailIfNotFallbackSCSV: true,
922 },
923 },
924 flags: []string{"-fallback-scsv"},
925 },
926 {
927 name: "ClientCertificateTypes",
928 config: Config{
929 ClientAuth: RequestClientCert,
930 ClientCertificateTypes: []byte{
931 CertTypeDSSSign,
932 CertTypeRSASign,
933 CertTypeECDSASign,
934 },
935 },
936 flags: []string{
937 "-expect-certificate-types",
938 base64.StdEncoding.EncodeToString([]byte{
939 CertTypeDSSSign,
940 CertTypeRSASign,
941 CertTypeECDSASign,
942 }),
943 },
944 },
945 {
946 name: "NoClientCertificate",
947 config: Config{
948 ClientAuth: RequireAnyClientCert,
949 },
950 shouldFail: true,
951 expectedLocalError: "client didn't provide a certificate",
952 },
953 {
954 name: "UnauthenticatedECDH",
955 config: Config{
956 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
957 Bugs: ProtocolBugs{
958 UnauthenticatedECDH: true,
959 },
960 },
961 shouldFail: true,
962 expectedError: ":UNEXPECTED_MESSAGE:",
963 },
964 {
965 name: "SkipCertificateStatus",
966 config: Config{
967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
968 Bugs: ProtocolBugs{
969 SkipCertificateStatus: true,
970 },
971 },
972 flags: []string{
973 "-enable-ocsp-stapling",
974 },
975 },
976 {
977 name: "SkipServerKeyExchange",
978 config: Config{
979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
980 Bugs: ProtocolBugs{
981 SkipServerKeyExchange: true,
982 },
983 },
984 shouldFail: true,
985 expectedError: ":UNEXPECTED_MESSAGE:",
986 },
987 {
988 name: "SkipChangeCipherSpec-Client",
989 config: Config{
990 Bugs: ProtocolBugs{
991 SkipChangeCipherSpec: true,
992 },
993 },
994 shouldFail: true,
995 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
996 },
997 {
998 testType: serverTest,
999 name: "SkipChangeCipherSpec-Server",
1000 config: Config{
1001 Bugs: ProtocolBugs{
1002 SkipChangeCipherSpec: true,
1003 },
1004 },
1005 shouldFail: true,
1006 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1007 },
1008 {
1009 testType: serverTest,
1010 name: "SkipChangeCipherSpec-Server-NPN",
1011 config: Config{
1012 NextProtos: []string{"bar"},
1013 Bugs: ProtocolBugs{
1014 SkipChangeCipherSpec: true,
1015 },
1016 },
1017 flags: []string{
1018 "-advertise-npn", "\x03foo\x03bar\x03baz",
1019 },
1020 shouldFail: true,
1021 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1022 },
1023 {
1024 name: "FragmentAcrossChangeCipherSpec-Client",
1025 config: Config{
1026 Bugs: ProtocolBugs{
1027 FragmentAcrossChangeCipherSpec: true,
1028 },
1029 },
1030 shouldFail: true,
1031 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1032 },
1033 {
1034 testType: serverTest,
1035 name: "FragmentAcrossChangeCipherSpec-Server",
1036 config: Config{
1037 Bugs: ProtocolBugs{
1038 FragmentAcrossChangeCipherSpec: true,
1039 },
1040 },
1041 shouldFail: true,
1042 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1043 },
1044 {
1045 testType: serverTest,
1046 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1047 config: Config{
1048 NextProtos: []string{"bar"},
1049 Bugs: ProtocolBugs{
1050 FragmentAcrossChangeCipherSpec: true,
1051 },
1052 },
1053 flags: []string{
1054 "-advertise-npn", "\x03foo\x03bar\x03baz",
1055 },
1056 shouldFail: true,
1057 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1058 },
1059 {
1060 testType: serverTest,
1061 name: "Alert",
1062 config: Config{
1063 Bugs: ProtocolBugs{
1064 SendSpuriousAlert: alertRecordOverflow,
1065 },
1066 },
1067 shouldFail: true,
1068 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1069 },
1070 {
1071 protocol: dtls,
1072 testType: serverTest,
1073 name: "Alert-DTLS",
1074 config: Config{
1075 Bugs: ProtocolBugs{
1076 SendSpuriousAlert: alertRecordOverflow,
1077 },
1078 },
1079 shouldFail: true,
1080 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1081 },
1082 {
1083 testType: serverTest,
1084 name: "FragmentAlert",
1085 config: Config{
1086 Bugs: ProtocolBugs{
1087 FragmentAlert: true,
1088 SendSpuriousAlert: alertRecordOverflow,
1089 },
1090 },
1091 shouldFail: true,
1092 expectedError: ":BAD_ALERT:",
1093 },
1094 {
1095 protocol: dtls,
1096 testType: serverTest,
1097 name: "FragmentAlert-DTLS",
1098 config: Config{
1099 Bugs: ProtocolBugs{
1100 FragmentAlert: true,
1101 SendSpuriousAlert: alertRecordOverflow,
1102 },
1103 },
1104 shouldFail: true,
1105 expectedError: ":BAD_ALERT:",
1106 },
1107 {
1108 testType: serverTest,
1109 name: "EarlyChangeCipherSpec-server-1",
1110 config: Config{
1111 Bugs: ProtocolBugs{
1112 EarlyChangeCipherSpec: 1,
1113 },
1114 },
1115 shouldFail: true,
1116 expectedError: ":CCS_RECEIVED_EARLY:",
1117 },
1118 {
1119 testType: serverTest,
1120 name: "EarlyChangeCipherSpec-server-2",
1121 config: Config{
1122 Bugs: ProtocolBugs{
1123 EarlyChangeCipherSpec: 2,
1124 },
1125 },
1126 shouldFail: true,
1127 expectedError: ":CCS_RECEIVED_EARLY:",
1128 },
1129 {
1130 name: "SkipNewSessionTicket",
1131 config: Config{
1132 Bugs: ProtocolBugs{
1133 SkipNewSessionTicket: true,
1134 },
1135 },
1136 shouldFail: true,
1137 expectedError: ":CCS_RECEIVED_EARLY:",
1138 },
1139 {
1140 testType: serverTest,
1141 name: "FallbackSCSV",
1142 config: Config{
1143 MaxVersion: VersionTLS11,
1144 Bugs: ProtocolBugs{
1145 SendFallbackSCSV: true,
1146 },
1147 },
1148 shouldFail: true,
1149 expectedError: ":INAPPROPRIATE_FALLBACK:",
1150 },
1151 {
1152 testType: serverTest,
1153 name: "FallbackSCSV-VersionMatch",
1154 config: Config{
1155 Bugs: ProtocolBugs{
1156 SendFallbackSCSV: true,
1157 },
1158 },
1159 },
1160 {
1161 testType: serverTest,
1162 name: "FragmentedClientVersion",
1163 config: Config{
1164 Bugs: ProtocolBugs{
1165 MaxHandshakeRecordLength: 1,
1166 FragmentClientVersion: true,
1167 },
1168 },
1169 expectedVersion: VersionTLS12,
1170 },
1171 {
1172 testType: serverTest,
1173 name: "MinorVersionTolerance",
1174 config: Config{
1175 Bugs: ProtocolBugs{
1176 SendClientVersion: 0x03ff,
1177 },
1178 },
1179 expectedVersion: VersionTLS12,
1180 },
1181 {
1182 testType: serverTest,
1183 name: "MajorVersionTolerance",
1184 config: Config{
1185 Bugs: ProtocolBugs{
1186 SendClientVersion: 0x0400,
1187 },
1188 },
1189 expectedVersion: VersionTLS12,
1190 },
1191 {
1192 testType: serverTest,
1193 name: "VersionTooLow",
1194 config: Config{
1195 Bugs: ProtocolBugs{
1196 SendClientVersion: 0x0200,
1197 },
1198 },
1199 shouldFail: true,
1200 expectedError: ":UNSUPPORTED_PROTOCOL:",
1201 },
1202 {
1203 testType: serverTest,
1204 name: "HttpGET",
1205 sendPrefix: "GET / HTTP/1.0\n",
1206 shouldFail: true,
1207 expectedError: ":HTTP_REQUEST:",
1208 },
1209 {
1210 testType: serverTest,
1211 name: "HttpPOST",
1212 sendPrefix: "POST / HTTP/1.0\n",
1213 shouldFail: true,
1214 expectedError: ":HTTP_REQUEST:",
1215 },
1216 {
1217 testType: serverTest,
1218 name: "HttpHEAD",
1219 sendPrefix: "HEAD / HTTP/1.0\n",
1220 shouldFail: true,
1221 expectedError: ":HTTP_REQUEST:",
1222 },
1223 {
1224 testType: serverTest,
1225 name: "HttpPUT",
1226 sendPrefix: "PUT / HTTP/1.0\n",
1227 shouldFail: true,
1228 expectedError: ":HTTP_REQUEST:",
1229 },
1230 {
1231 testType: serverTest,
1232 name: "HttpCONNECT",
1233 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1234 shouldFail: true,
1235 expectedError: ":HTTPS_PROXY_REQUEST:",
1236 },
1237 {
1238 testType: serverTest,
1239 name: "Garbage",
1240 sendPrefix: "blah",
1241 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001242 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001243 },
1244 {
1245 name: "SkipCipherVersionCheck",
1246 config: Config{
1247 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1248 MaxVersion: VersionTLS11,
1249 Bugs: ProtocolBugs{
1250 SkipCipherVersionCheck: true,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":WRONG_CIPHER_RETURNED:",
1255 },
1256 {
1257 name: "RSAEphemeralKey",
1258 config: Config{
1259 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1260 Bugs: ProtocolBugs{
1261 RSAEphemeralKey: true,
1262 },
1263 },
1264 shouldFail: true,
1265 expectedError: ":UNEXPECTED_MESSAGE:",
1266 },
1267 {
1268 name: "DisableEverything",
1269 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1270 shouldFail: true,
1271 expectedError: ":WRONG_SSL_VERSION:",
1272 },
1273 {
1274 protocol: dtls,
1275 name: "DisableEverything-DTLS",
1276 flags: []string{"-no-tls12", "-no-tls1"},
1277 shouldFail: true,
1278 expectedError: ":WRONG_SSL_VERSION:",
1279 },
1280 {
1281 name: "NoSharedCipher",
1282 config: Config{
1283 CipherSuites: []uint16{},
1284 },
1285 shouldFail: true,
1286 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1287 },
1288 {
1289 protocol: dtls,
1290 testType: serverTest,
1291 name: "MTU",
1292 config: Config{
1293 Bugs: ProtocolBugs{
1294 MaxPacketLength: 256,
1295 },
1296 },
1297 flags: []string{"-mtu", "256"},
1298 },
1299 {
1300 protocol: dtls,
1301 testType: serverTest,
1302 name: "MTUExceeded",
1303 config: Config{
1304 Bugs: ProtocolBugs{
1305 MaxPacketLength: 255,
1306 },
1307 },
1308 flags: []string{"-mtu", "256"},
1309 shouldFail: true,
1310 expectedLocalError: "dtls: exceeded maximum packet length",
1311 },
1312 {
1313 name: "CertMismatchRSA",
1314 config: Config{
1315 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1316 Certificates: []Certificate{getECDSACertificate()},
1317 Bugs: ProtocolBugs{
1318 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1319 },
1320 },
1321 shouldFail: true,
1322 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1323 },
1324 {
1325 name: "CertMismatchECDSA",
1326 config: Config{
1327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1328 Certificates: []Certificate{getRSACertificate()},
1329 Bugs: ProtocolBugs{
1330 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1331 },
1332 },
1333 shouldFail: true,
1334 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1335 },
1336 {
1337 name: "EmptyCertificateList",
1338 config: Config{
1339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1340 Bugs: ProtocolBugs{
1341 EmptyCertificateList: true,
1342 },
1343 },
1344 shouldFail: true,
1345 expectedError: ":DECODE_ERROR:",
1346 },
1347 {
1348 name: "TLSFatalBadPackets",
1349 damageFirstWrite: true,
1350 shouldFail: true,
1351 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1352 },
1353 {
1354 protocol: dtls,
1355 name: "DTLSIgnoreBadPackets",
1356 damageFirstWrite: true,
1357 },
1358 {
1359 protocol: dtls,
1360 name: "DTLSIgnoreBadPackets-Async",
1361 damageFirstWrite: true,
1362 flags: []string{"-async"},
1363 },
1364 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001365 name: "AppDataBeforeHandshake",
1366 config: Config{
1367 Bugs: ProtocolBugs{
1368 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1369 },
1370 },
1371 shouldFail: true,
1372 expectedError: ":UNEXPECTED_RECORD:",
1373 },
1374 {
1375 name: "AppDataBeforeHandshake-Empty",
1376 config: Config{
1377 Bugs: ProtocolBugs{
1378 AppDataBeforeHandshake: []byte{},
1379 },
1380 },
1381 shouldFail: true,
1382 expectedError: ":UNEXPECTED_RECORD:",
1383 },
1384 {
1385 protocol: dtls,
1386 name: "AppDataBeforeHandshake-DTLS",
1387 config: Config{
1388 Bugs: ProtocolBugs{
1389 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":UNEXPECTED_RECORD:",
1394 },
1395 {
1396 protocol: dtls,
1397 name: "AppDataBeforeHandshake-DTLS-Empty",
1398 config: Config{
1399 Bugs: ProtocolBugs{
1400 AppDataBeforeHandshake: []byte{},
1401 },
1402 },
1403 shouldFail: true,
1404 expectedError: ":UNEXPECTED_RECORD:",
1405 },
1406 {
Adam Langley7c803a62015-06-15 15:35:05 -07001407 name: "AppDataAfterChangeCipherSpec",
1408 config: Config{
1409 Bugs: ProtocolBugs{
1410 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1411 },
1412 },
1413 shouldFail: true,
1414 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1415 },
1416 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001417 name: "AppDataAfterChangeCipherSpec-Empty",
1418 config: Config{
1419 Bugs: ProtocolBugs{
1420 AppDataAfterChangeCipherSpec: []byte{},
1421 },
1422 },
1423 shouldFail: true,
1424 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1425 },
1426 {
Adam Langley7c803a62015-06-15 15:35:05 -07001427 protocol: dtls,
1428 name: "AppDataAfterChangeCipherSpec-DTLS",
1429 config: Config{
1430 Bugs: ProtocolBugs{
1431 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1432 },
1433 },
1434 // BoringSSL's DTLS implementation will drop the out-of-order
1435 // application data.
1436 },
1437 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001438 protocol: dtls,
1439 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1440 config: Config{
1441 Bugs: ProtocolBugs{
1442 AppDataAfterChangeCipherSpec: []byte{},
1443 },
1444 },
1445 // BoringSSL's DTLS implementation will drop the out-of-order
1446 // application data.
1447 },
1448 {
Adam Langley7c803a62015-06-15 15:35:05 -07001449 name: "AlertAfterChangeCipherSpec",
1450 config: Config{
1451 Bugs: ProtocolBugs{
1452 AlertAfterChangeCipherSpec: alertRecordOverflow,
1453 },
1454 },
1455 shouldFail: true,
1456 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1457 },
1458 {
1459 protocol: dtls,
1460 name: "AlertAfterChangeCipherSpec-DTLS",
1461 config: Config{
1462 Bugs: ProtocolBugs{
1463 AlertAfterChangeCipherSpec: alertRecordOverflow,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1468 },
1469 {
1470 protocol: dtls,
1471 name: "ReorderHandshakeFragments-Small-DTLS",
1472 config: Config{
1473 Bugs: ProtocolBugs{
1474 ReorderHandshakeFragments: true,
1475 // Small enough that every handshake message is
1476 // fragmented.
1477 MaxHandshakeRecordLength: 2,
1478 },
1479 },
1480 },
1481 {
1482 protocol: dtls,
1483 name: "ReorderHandshakeFragments-Large-DTLS",
1484 config: Config{
1485 Bugs: ProtocolBugs{
1486 ReorderHandshakeFragments: true,
1487 // Large enough that no handshake message is
1488 // fragmented.
1489 MaxHandshakeRecordLength: 2048,
1490 },
1491 },
1492 },
1493 {
1494 protocol: dtls,
1495 name: "MixCompleteMessageWithFragments-DTLS",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 ReorderHandshakeFragments: true,
1499 MixCompleteMessageWithFragments: true,
1500 MaxHandshakeRecordLength: 2,
1501 },
1502 },
1503 },
1504 {
1505 name: "SendInvalidRecordType",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 SendInvalidRecordType: true,
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "SendInvalidRecordType-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 SendInvalidRecordType: true,
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 name: "FalseStart-SkipServerSecondLeg",
1527 config: Config{
1528 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1529 NextProtos: []string{"foo"},
1530 Bugs: ProtocolBugs{
1531 SkipNewSessionTicket: true,
1532 SkipChangeCipherSpec: true,
1533 SkipFinished: true,
1534 ExpectFalseStart: true,
1535 },
1536 },
1537 flags: []string{
1538 "-false-start",
1539 "-handshake-never-done",
1540 "-advertise-alpn", "\x03foo",
1541 },
1542 shimWritesFirst: true,
1543 shouldFail: true,
1544 expectedError: ":UNEXPECTED_RECORD:",
1545 },
1546 {
1547 name: "FalseStart-SkipServerSecondLeg-Implicit",
1548 config: Config{
1549 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1550 NextProtos: []string{"foo"},
1551 Bugs: ProtocolBugs{
1552 SkipNewSessionTicket: true,
1553 SkipChangeCipherSpec: true,
1554 SkipFinished: true,
1555 },
1556 },
1557 flags: []string{
1558 "-implicit-handshake",
1559 "-false-start",
1560 "-handshake-never-done",
1561 "-advertise-alpn", "\x03foo",
1562 },
1563 shouldFail: true,
1564 expectedError: ":UNEXPECTED_RECORD:",
1565 },
1566 {
1567 testType: serverTest,
1568 name: "FailEarlyCallback",
1569 flags: []string{"-fail-early-callback"},
1570 shouldFail: true,
1571 expectedError: ":CONNECTION_REJECTED:",
1572 expectedLocalError: "remote error: access denied",
1573 },
1574 {
1575 name: "WrongMessageType",
1576 config: Config{
1577 Bugs: ProtocolBugs{
1578 WrongCertificateMessageType: true,
1579 },
1580 },
1581 shouldFail: true,
1582 expectedError: ":UNEXPECTED_MESSAGE:",
1583 expectedLocalError: "remote error: unexpected message",
1584 },
1585 {
1586 protocol: dtls,
1587 name: "WrongMessageType-DTLS",
1588 config: Config{
1589 Bugs: ProtocolBugs{
1590 WrongCertificateMessageType: true,
1591 },
1592 },
1593 shouldFail: true,
1594 expectedError: ":UNEXPECTED_MESSAGE:",
1595 expectedLocalError: "remote error: unexpected message",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "FragmentMessageTypeMismatch-DTLS",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 MaxHandshakeRecordLength: 2,
1603 FragmentMessageTypeMismatch: true,
1604 },
1605 },
1606 shouldFail: true,
1607 expectedError: ":FRAGMENT_MISMATCH:",
1608 },
1609 {
1610 protocol: dtls,
1611 name: "FragmentMessageLengthMismatch-DTLS",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 MaxHandshakeRecordLength: 2,
1615 FragmentMessageLengthMismatch: true,
1616 },
1617 },
1618 shouldFail: true,
1619 expectedError: ":FRAGMENT_MISMATCH:",
1620 },
1621 {
1622 protocol: dtls,
1623 name: "SplitFragments-Header-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 SplitFragments: 2,
1627 },
1628 },
1629 shouldFail: true,
1630 expectedError: ":UNEXPECTED_MESSAGE:",
1631 },
1632 {
1633 protocol: dtls,
1634 name: "SplitFragments-Boundary-DTLS",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 SplitFragments: dtlsRecordHeaderLen,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1642 },
1643 {
1644 protocol: dtls,
1645 name: "SplitFragments-Body-DTLS",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SplitFragments: dtlsRecordHeaderLen + 1,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1653 },
1654 {
1655 protocol: dtls,
1656 name: "SendEmptyFragments-DTLS",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 SendEmptyFragments: true,
1660 },
1661 },
1662 },
1663 {
1664 name: "UnsupportedCipherSuite",
1665 config: Config{
1666 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1667 Bugs: ProtocolBugs{
1668 IgnorePeerCipherPreferences: true,
1669 },
1670 },
1671 flags: []string{"-cipher", "DEFAULT:!RC4"},
1672 shouldFail: true,
1673 expectedError: ":WRONG_CIPHER_RETURNED:",
1674 },
1675 {
1676 name: "UnsupportedCurve",
1677 config: Config{
1678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1679 // BoringSSL implements P-224 but doesn't enable it by
1680 // default.
1681 CurvePreferences: []CurveID{CurveP224},
1682 Bugs: ProtocolBugs{
1683 IgnorePeerCurvePreferences: true,
1684 },
1685 },
1686 shouldFail: true,
1687 expectedError: ":WRONG_CURVE:",
1688 },
1689 {
1690 name: "BadFinished",
1691 config: Config{
1692 Bugs: ProtocolBugs{
1693 BadFinished: true,
1694 },
1695 },
1696 shouldFail: true,
1697 expectedError: ":DIGEST_CHECK_FAILED:",
1698 },
1699 {
1700 name: "FalseStart-BadFinished",
1701 config: Config{
1702 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1703 NextProtos: []string{"foo"},
1704 Bugs: ProtocolBugs{
1705 BadFinished: true,
1706 ExpectFalseStart: true,
1707 },
1708 },
1709 flags: []string{
1710 "-false-start",
1711 "-handshake-never-done",
1712 "-advertise-alpn", "\x03foo",
1713 },
1714 shimWritesFirst: true,
1715 shouldFail: true,
1716 expectedError: ":DIGEST_CHECK_FAILED:",
1717 },
1718 {
1719 name: "NoFalseStart-NoALPN",
1720 config: Config{
1721 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1722 Bugs: ProtocolBugs{
1723 ExpectFalseStart: true,
1724 AlertBeforeFalseStartTest: alertAccessDenied,
1725 },
1726 },
1727 flags: []string{
1728 "-false-start",
1729 },
1730 shimWritesFirst: true,
1731 shouldFail: true,
1732 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1733 expectedLocalError: "tls: peer did not false start: EOF",
1734 },
1735 {
1736 name: "NoFalseStart-NoAEAD",
1737 config: Config{
1738 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1739 NextProtos: []string{"foo"},
1740 Bugs: ProtocolBugs{
1741 ExpectFalseStart: true,
1742 AlertBeforeFalseStartTest: alertAccessDenied,
1743 },
1744 },
1745 flags: []string{
1746 "-false-start",
1747 "-advertise-alpn", "\x03foo",
1748 },
1749 shimWritesFirst: true,
1750 shouldFail: true,
1751 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1752 expectedLocalError: "tls: peer did not false start: EOF",
1753 },
1754 {
1755 name: "NoFalseStart-RSA",
1756 config: Config{
1757 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1758 NextProtos: []string{"foo"},
1759 Bugs: ProtocolBugs{
1760 ExpectFalseStart: true,
1761 AlertBeforeFalseStartTest: alertAccessDenied,
1762 },
1763 },
1764 flags: []string{
1765 "-false-start",
1766 "-advertise-alpn", "\x03foo",
1767 },
1768 shimWritesFirst: true,
1769 shouldFail: true,
1770 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1771 expectedLocalError: "tls: peer did not false start: EOF",
1772 },
1773 {
1774 name: "NoFalseStart-DHE_RSA",
1775 config: Config{
1776 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1777 NextProtos: []string{"foo"},
1778 Bugs: ProtocolBugs{
1779 ExpectFalseStart: true,
1780 AlertBeforeFalseStartTest: alertAccessDenied,
1781 },
1782 },
1783 flags: []string{
1784 "-false-start",
1785 "-advertise-alpn", "\x03foo",
1786 },
1787 shimWritesFirst: true,
1788 shouldFail: true,
1789 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1790 expectedLocalError: "tls: peer did not false start: EOF",
1791 },
1792 {
1793 testType: serverTest,
1794 name: "NoSupportedCurves",
1795 config: Config{
1796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1797 Bugs: ProtocolBugs{
1798 NoSupportedCurves: true,
1799 },
1800 },
1801 },
1802 {
1803 testType: serverTest,
1804 name: "NoCommonCurves",
1805 config: Config{
1806 CipherSuites: []uint16{
1807 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1808 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1809 },
1810 CurvePreferences: []CurveID{CurveP224},
1811 },
1812 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1813 },
1814 {
1815 protocol: dtls,
1816 name: "SendSplitAlert-Sync",
1817 config: Config{
1818 Bugs: ProtocolBugs{
1819 SendSplitAlert: true,
1820 },
1821 },
1822 },
1823 {
1824 protocol: dtls,
1825 name: "SendSplitAlert-Async",
1826 config: Config{
1827 Bugs: ProtocolBugs{
1828 SendSplitAlert: true,
1829 },
1830 },
1831 flags: []string{"-async"},
1832 },
1833 {
1834 protocol: dtls,
1835 name: "PackDTLSHandshake",
1836 config: Config{
1837 Bugs: ProtocolBugs{
1838 MaxHandshakeRecordLength: 2,
1839 PackHandshakeFragments: 20,
1840 PackHandshakeRecords: 200,
1841 },
1842 },
1843 },
1844 {
1845 testType: serverTest,
1846 protocol: dtls,
1847 name: "NoRC4-DTLS",
1848 config: Config{
1849 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1850 Bugs: ProtocolBugs{
1851 EnableAllCiphersInDTLS: true,
1852 },
1853 },
1854 shouldFail: true,
1855 expectedError: ":NO_SHARED_CIPHER:",
1856 },
1857 {
1858 name: "SendEmptyRecords-Pass",
1859 sendEmptyRecords: 32,
1860 },
1861 {
1862 name: "SendEmptyRecords",
1863 sendEmptyRecords: 33,
1864 shouldFail: true,
1865 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1866 },
1867 {
1868 name: "SendEmptyRecords-Async",
1869 sendEmptyRecords: 33,
1870 flags: []string{"-async"},
1871 shouldFail: true,
1872 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1873 },
1874 {
1875 name: "SendWarningAlerts-Pass",
1876 sendWarningAlerts: 4,
1877 },
1878 {
1879 protocol: dtls,
1880 name: "SendWarningAlerts-DTLS-Pass",
1881 sendWarningAlerts: 4,
1882 },
1883 {
1884 name: "SendWarningAlerts",
1885 sendWarningAlerts: 5,
1886 shouldFail: true,
1887 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1888 },
1889 {
1890 name: "SendWarningAlerts-Async",
1891 sendWarningAlerts: 5,
1892 flags: []string{"-async"},
1893 shouldFail: true,
1894 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1895 },
David Benjaminba4594a2015-06-18 18:36:15 -04001896 {
1897 name: "EmptySessionID",
1898 config: Config{
1899 SessionTicketsDisabled: true,
1900 },
1901 noSessionCache: true,
1902 flags: []string{"-expect-no-session"},
1903 },
David Benjamin30789da2015-08-29 22:56:45 -04001904 {
1905 name: "Unclean-Shutdown",
1906 config: Config{
1907 Bugs: ProtocolBugs{
1908 NoCloseNotify: true,
1909 ExpectCloseNotify: true,
1910 },
1911 },
1912 shimShutsDown: true,
1913 flags: []string{"-check-close-notify"},
1914 shouldFail: true,
1915 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1916 },
1917 {
1918 name: "Unclean-Shutdown-Ignored",
1919 config: Config{
1920 Bugs: ProtocolBugs{
1921 NoCloseNotify: true,
1922 },
1923 },
1924 shimShutsDown: true,
1925 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001926 {
1927 name: "LargePlaintext",
1928 config: Config{
1929 Bugs: ProtocolBugs{
1930 SendLargeRecords: true,
1931 },
1932 },
1933 messageLen: maxPlaintext + 1,
1934 shouldFail: true,
1935 expectedError: ":DATA_LENGTH_TOO_LONG:",
1936 },
1937 {
1938 protocol: dtls,
1939 name: "LargePlaintext-DTLS",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 SendLargeRecords: true,
1943 },
1944 },
1945 messageLen: maxPlaintext + 1,
1946 shouldFail: true,
1947 expectedError: ":DATA_LENGTH_TOO_LONG:",
1948 },
1949 {
1950 name: "LargeCiphertext",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 SendLargeRecords: true,
1954 },
1955 },
1956 messageLen: maxPlaintext * 2,
1957 shouldFail: true,
1958 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1959 },
1960 {
1961 protocol: dtls,
1962 name: "LargeCiphertext-DTLS",
1963 config: Config{
1964 Bugs: ProtocolBugs{
1965 SendLargeRecords: true,
1966 },
1967 },
1968 messageLen: maxPlaintext * 2,
1969 // Unlike the other four cases, DTLS drops records which
1970 // are invalid before authentication, so the connection
1971 // does not fail.
1972 expectMessageDropped: true,
1973 },
David Benjamindd6fed92015-10-23 17:41:12 -04001974 {
1975 name: "SendEmptySessionTicket",
1976 config: Config{
1977 Bugs: ProtocolBugs{
1978 SendEmptySessionTicket: true,
1979 FailIfSessionOffered: true,
1980 },
1981 },
1982 flags: []string{"-expect-no-session"},
1983 resumeSession: true,
1984 expectResumeRejected: true,
1985 },
Adam Langley7c803a62015-06-15 15:35:05 -07001986 }
Adam Langley7c803a62015-06-15 15:35:05 -07001987 testCases = append(testCases, basicTests...)
1988}
1989
Adam Langley95c29f32014-06-20 12:00:00 -07001990func addCipherSuiteTests() {
1991 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001992 const psk = "12345"
1993 const pskIdentity = "luggage combo"
1994
Adam Langley95c29f32014-06-20 12:00:00 -07001995 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001996 var certFile string
1997 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001998 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001999 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002000 certFile = ecdsaCertificateFile
2001 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002002 } else {
2003 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04002004 certFile = rsaCertificateFile
2005 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002006 }
2007
David Benjamin48cae082014-10-27 01:06:24 -04002008 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002009 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002010 flags = append(flags,
2011 "-psk", psk,
2012 "-psk-identity", pskIdentity)
2013 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002014 if hasComponent(suite.name, "NULL") {
2015 // NULL ciphers must be explicitly enabled.
2016 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2017 }
David Benjamin48cae082014-10-27 01:06:24 -04002018
Adam Langley95c29f32014-06-20 12:00:00 -07002019 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002020 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002021 continue
2022 }
2023
David Benjamin025b3d32014-07-01 19:53:04 -04002024 testCases = append(testCases, testCase{
2025 testType: clientTest,
2026 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002027 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002028 MinVersion: ver.version,
2029 MaxVersion: ver.version,
2030 CipherSuites: []uint16{suite.id},
2031 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002032 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002033 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002034 },
David Benjamin48cae082014-10-27 01:06:24 -04002035 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002036 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002037 })
David Benjamin025b3d32014-07-01 19:53:04 -04002038
David Benjamin76d8abe2014-08-14 16:25:34 -04002039 testCases = append(testCases, testCase{
2040 testType: serverTest,
2041 name: ver.name + "-" + suite.name + "-server",
2042 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002043 MinVersion: ver.version,
2044 MaxVersion: ver.version,
2045 CipherSuites: []uint16{suite.id},
2046 Certificates: []Certificate{cert},
2047 PreSharedKey: []byte(psk),
2048 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002049 },
2050 certFile: certFile,
2051 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002052 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002053 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002054 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002055
David Benjamin8b8c0062014-11-23 02:47:52 -05002056 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002057 testCases = append(testCases, testCase{
2058 testType: clientTest,
2059 protocol: dtls,
2060 name: "D" + ver.name + "-" + suite.name + "-client",
2061 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002062 MinVersion: ver.version,
2063 MaxVersion: ver.version,
2064 CipherSuites: []uint16{suite.id},
2065 Certificates: []Certificate{cert},
2066 PreSharedKey: []byte(psk),
2067 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002068 },
David Benjamin48cae082014-10-27 01:06:24 -04002069 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002070 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002071 })
2072 testCases = append(testCases, testCase{
2073 testType: serverTest,
2074 protocol: dtls,
2075 name: "D" + ver.name + "-" + suite.name + "-server",
2076 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002077 MinVersion: ver.version,
2078 MaxVersion: ver.version,
2079 CipherSuites: []uint16{suite.id},
2080 Certificates: []Certificate{cert},
2081 PreSharedKey: []byte(psk),
2082 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002083 },
2084 certFile: certFile,
2085 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002086 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002087 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002088 })
2089 }
Adam Langley95c29f32014-06-20 12:00:00 -07002090 }
David Benjamin2c99d282015-09-01 10:23:00 -04002091
2092 // Ensure both TLS and DTLS accept their maximum record sizes.
2093 testCases = append(testCases, testCase{
2094 name: suite.name + "-LargeRecord",
2095 config: Config{
2096 CipherSuites: []uint16{suite.id},
2097 Certificates: []Certificate{cert},
2098 PreSharedKey: []byte(psk),
2099 PreSharedKeyIdentity: pskIdentity,
2100 },
2101 flags: flags,
2102 messageLen: maxPlaintext,
2103 })
2104 testCases = append(testCases, testCase{
2105 name: suite.name + "-LargeRecord-Extra",
2106 config: Config{
2107 CipherSuites: []uint16{suite.id},
2108 Certificates: []Certificate{cert},
2109 PreSharedKey: []byte(psk),
2110 PreSharedKeyIdentity: pskIdentity,
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2116 messageLen: maxPlaintext + 16384,
2117 })
2118 if isDTLSCipher(suite.name) {
2119 testCases = append(testCases, testCase{
2120 protocol: dtls,
2121 name: suite.name + "-LargeRecord-DTLS",
2122 config: Config{
2123 CipherSuites: []uint16{suite.id},
2124 Certificates: []Certificate{cert},
2125 PreSharedKey: []byte(psk),
2126 PreSharedKeyIdentity: pskIdentity,
2127 },
2128 flags: flags,
2129 messageLen: maxPlaintext,
2130 })
2131 }
Adam Langley95c29f32014-06-20 12:00:00 -07002132 }
Adam Langleya7997f12015-05-14 17:38:50 -07002133
2134 testCases = append(testCases, testCase{
2135 name: "WeakDH",
2136 config: Config{
2137 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2138 Bugs: ProtocolBugs{
2139 // This is a 1023-bit prime number, generated
2140 // with:
2141 // openssl gendh 1023 | openssl asn1parse -i
2142 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2143 },
2144 },
2145 shouldFail: true,
2146 expectedError: "BAD_DH_P_LENGTH",
2147 })
Adam Langleycef75832015-09-03 14:51:12 -07002148
2149 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2150 // 1.1 specific cipher suite settings. A server is setup with the given
2151 // cipher lists and then a connection is made for each member of
2152 // expectations. The cipher suite that the server selects must match
2153 // the specified one.
2154 var versionSpecificCiphersTest = []struct {
2155 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2156 // expectations is a map from TLS version to cipher suite id.
2157 expectations map[uint16]uint16
2158 }{
2159 {
2160 // Test that the null case (where no version-specific ciphers are set)
2161 // works as expected.
2162 "RC4-SHA:AES128-SHA", // default ciphers
2163 "", // no ciphers specifically for TLS ≥ 1.0
2164 "", // no ciphers specifically for TLS ≥ 1.1
2165 map[uint16]uint16{
2166 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2167 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2168 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2169 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2170 },
2171 },
2172 {
2173 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2174 // cipher.
2175 "RC4-SHA:AES128-SHA", // default
2176 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2177 "", // no ciphers specifically for TLS ≥ 1.1
2178 map[uint16]uint16{
2179 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2180 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2181 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2182 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2183 },
2184 },
2185 {
2186 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2187 // cipher.
2188 "RC4-SHA:AES128-SHA", // default
2189 "", // no ciphers specifically for TLS ≥ 1.0
2190 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2191 map[uint16]uint16{
2192 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2193 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2194 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2195 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2196 },
2197 },
2198 {
2199 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2200 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2201 "RC4-SHA:AES128-SHA", // default
2202 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2203 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2204 map[uint16]uint16{
2205 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2206 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2207 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2208 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2209 },
2210 },
2211 }
2212
2213 for i, test := range versionSpecificCiphersTest {
2214 for version, expectedCipherSuite := range test.expectations {
2215 flags := []string{"-cipher", test.ciphersDefault}
2216 if len(test.ciphersTLS10) > 0 {
2217 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2218 }
2219 if len(test.ciphersTLS11) > 0 {
2220 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2221 }
2222
2223 testCases = append(testCases, testCase{
2224 testType: serverTest,
2225 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2226 config: Config{
2227 MaxVersion: version,
2228 MinVersion: version,
2229 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2230 },
2231 flags: flags,
2232 expectedCipher: expectedCipherSuite,
2233 })
2234 }
2235 }
Adam Langley95c29f32014-06-20 12:00:00 -07002236}
2237
2238func addBadECDSASignatureTests() {
2239 for badR := BadValue(1); badR < NumBadValues; badR++ {
2240 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002241 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002242 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2243 config: Config{
2244 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2245 Certificates: []Certificate{getECDSACertificate()},
2246 Bugs: ProtocolBugs{
2247 BadECDSAR: badR,
2248 BadECDSAS: badS,
2249 },
2250 },
2251 shouldFail: true,
2252 expectedError: "SIGNATURE",
2253 })
2254 }
2255 }
2256}
2257
Adam Langley80842bd2014-06-20 12:00:00 -07002258func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002259 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002260 name: "MaxCBCPadding",
2261 config: Config{
2262 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2263 Bugs: ProtocolBugs{
2264 MaxPadding: true,
2265 },
2266 },
2267 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2268 })
David Benjamin025b3d32014-07-01 19:53:04 -04002269 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002270 name: "BadCBCPadding",
2271 config: Config{
2272 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2273 Bugs: ProtocolBugs{
2274 PaddingFirstByteBad: true,
2275 },
2276 },
2277 shouldFail: true,
2278 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2279 })
2280 // OpenSSL previously had an issue where the first byte of padding in
2281 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002282 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002283 name: "BadCBCPadding255",
2284 config: Config{
2285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2286 Bugs: ProtocolBugs{
2287 MaxPadding: true,
2288 PaddingFirstByteBadIf255: true,
2289 },
2290 },
2291 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2292 shouldFail: true,
2293 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2294 })
2295}
2296
Kenny Root7fdeaf12014-08-05 15:23:37 -07002297func addCBCSplittingTests() {
2298 testCases = append(testCases, testCase{
2299 name: "CBCRecordSplitting",
2300 config: Config{
2301 MaxVersion: VersionTLS10,
2302 MinVersion: VersionTLS10,
2303 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2304 },
David Benjaminac8302a2015-09-01 17:18:15 -04002305 messageLen: -1, // read until EOF
2306 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002307 flags: []string{
2308 "-async",
2309 "-write-different-record-sizes",
2310 "-cbc-record-splitting",
2311 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002312 })
2313 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002314 name: "CBCRecordSplittingPartialWrite",
2315 config: Config{
2316 MaxVersion: VersionTLS10,
2317 MinVersion: VersionTLS10,
2318 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2319 },
2320 messageLen: -1, // read until EOF
2321 flags: []string{
2322 "-async",
2323 "-write-different-record-sizes",
2324 "-cbc-record-splitting",
2325 "-partial-write",
2326 },
2327 })
2328}
2329
David Benjamin636293b2014-07-08 17:59:18 -04002330func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002331 // Add a dummy cert pool to stress certificate authority parsing.
2332 // TODO(davidben): Add tests that those values parse out correctly.
2333 certPool := x509.NewCertPool()
2334 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2335 if err != nil {
2336 panic(err)
2337 }
2338 certPool.AddCert(cert)
2339
David Benjamin636293b2014-07-08 17:59:18 -04002340 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002341 testCases = append(testCases, testCase{
2342 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002343 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002344 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002345 MinVersion: ver.version,
2346 MaxVersion: ver.version,
2347 ClientAuth: RequireAnyClientCert,
2348 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002349 },
2350 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002351 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2352 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002353 },
2354 })
2355 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002356 testType: serverTest,
2357 name: ver.name + "-Server-ClientAuth-RSA",
2358 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002359 MinVersion: ver.version,
2360 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002361 Certificates: []Certificate{rsaCertificate},
2362 },
2363 flags: []string{"-require-any-client-certificate"},
2364 })
David Benjamine098ec22014-08-27 23:13:20 -04002365 if ver.version != VersionSSL30 {
2366 testCases = append(testCases, testCase{
2367 testType: serverTest,
2368 name: ver.name + "-Server-ClientAuth-ECDSA",
2369 config: Config{
2370 MinVersion: ver.version,
2371 MaxVersion: ver.version,
2372 Certificates: []Certificate{ecdsaCertificate},
2373 },
2374 flags: []string{"-require-any-client-certificate"},
2375 })
2376 testCases = append(testCases, testCase{
2377 testType: clientTest,
2378 name: ver.name + "-Client-ClientAuth-ECDSA",
2379 config: Config{
2380 MinVersion: ver.version,
2381 MaxVersion: ver.version,
2382 ClientAuth: RequireAnyClientCert,
2383 ClientCAs: certPool,
2384 },
2385 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002386 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2387 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002388 },
2389 })
2390 }
David Benjamin636293b2014-07-08 17:59:18 -04002391 }
2392}
2393
Adam Langley75712922014-10-10 16:23:43 -07002394func addExtendedMasterSecretTests() {
2395 const expectEMSFlag = "-expect-extended-master-secret"
2396
2397 for _, with := range []bool{false, true} {
2398 prefix := "No"
2399 var flags []string
2400 if with {
2401 prefix = ""
2402 flags = []string{expectEMSFlag}
2403 }
2404
2405 for _, isClient := range []bool{false, true} {
2406 suffix := "-Server"
2407 testType := serverTest
2408 if isClient {
2409 suffix = "-Client"
2410 testType = clientTest
2411 }
2412
2413 for _, ver := range tlsVersions {
2414 test := testCase{
2415 testType: testType,
2416 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2417 config: Config{
2418 MinVersion: ver.version,
2419 MaxVersion: ver.version,
2420 Bugs: ProtocolBugs{
2421 NoExtendedMasterSecret: !with,
2422 RequireExtendedMasterSecret: with,
2423 },
2424 },
David Benjamin48cae082014-10-27 01:06:24 -04002425 flags: flags,
2426 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002427 }
2428 if test.shouldFail {
2429 test.expectedLocalError = "extended master secret required but not supported by peer"
2430 }
2431 testCases = append(testCases, test)
2432 }
2433 }
2434 }
2435
Adam Langleyba5934b2015-06-02 10:50:35 -07002436 for _, isClient := range []bool{false, true} {
2437 for _, supportedInFirstConnection := range []bool{false, true} {
2438 for _, supportedInResumeConnection := range []bool{false, true} {
2439 boolToWord := func(b bool) string {
2440 if b {
2441 return "Yes"
2442 }
2443 return "No"
2444 }
2445 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2446 if isClient {
2447 suffix += "Client"
2448 } else {
2449 suffix += "Server"
2450 }
2451
2452 supportedConfig := Config{
2453 Bugs: ProtocolBugs{
2454 RequireExtendedMasterSecret: true,
2455 },
2456 }
2457
2458 noSupportConfig := Config{
2459 Bugs: ProtocolBugs{
2460 NoExtendedMasterSecret: true,
2461 },
2462 }
2463
2464 test := testCase{
2465 name: "ExtendedMasterSecret-" + suffix,
2466 resumeSession: true,
2467 }
2468
2469 if !isClient {
2470 test.testType = serverTest
2471 }
2472
2473 if supportedInFirstConnection {
2474 test.config = supportedConfig
2475 } else {
2476 test.config = noSupportConfig
2477 }
2478
2479 if supportedInResumeConnection {
2480 test.resumeConfig = &supportedConfig
2481 } else {
2482 test.resumeConfig = &noSupportConfig
2483 }
2484
2485 switch suffix {
2486 case "YesToYes-Client", "YesToYes-Server":
2487 // When a session is resumed, it should
2488 // still be aware that its master
2489 // secret was generated via EMS and
2490 // thus it's safe to use tls-unique.
2491 test.flags = []string{expectEMSFlag}
2492 case "NoToYes-Server":
2493 // If an original connection did not
2494 // contain EMS, but a resumption
2495 // handshake does, then a server should
2496 // not resume the session.
2497 test.expectResumeRejected = true
2498 case "YesToNo-Server":
2499 // Resuming an EMS session without the
2500 // EMS extension should cause the
2501 // server to abort the connection.
2502 test.shouldFail = true
2503 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2504 case "NoToYes-Client":
2505 // A client should abort a connection
2506 // where the server resumed a non-EMS
2507 // session but echoed the EMS
2508 // extension.
2509 test.shouldFail = true
2510 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2511 case "YesToNo-Client":
2512 // A client should abort a connection
2513 // where the server didn't echo EMS
2514 // when the session used it.
2515 test.shouldFail = true
2516 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2517 }
2518
2519 testCases = append(testCases, test)
2520 }
2521 }
2522 }
Adam Langley75712922014-10-10 16:23:43 -07002523}
2524
David Benjamin43ec06f2014-08-05 02:28:57 -04002525// Adds tests that try to cover the range of the handshake state machine, under
2526// various conditions. Some of these are redundant with other tests, but they
2527// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002528func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002529 var tests []testCase
2530
2531 // Basic handshake, with resumption. Client and server,
2532 // session ID and session ticket.
2533 tests = append(tests, testCase{
2534 name: "Basic-Client",
2535 resumeSession: true,
2536 })
2537 tests = append(tests, testCase{
2538 name: "Basic-Client-RenewTicket",
2539 config: Config{
2540 Bugs: ProtocolBugs{
2541 RenewTicketOnResume: true,
2542 },
2543 },
David Benjaminba4594a2015-06-18 18:36:15 -04002544 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002545 resumeSession: true,
2546 })
2547 tests = append(tests, testCase{
2548 name: "Basic-Client-NoTicket",
2549 config: Config{
2550 SessionTicketsDisabled: true,
2551 },
2552 resumeSession: true,
2553 })
2554 tests = append(tests, testCase{
2555 name: "Basic-Client-Implicit",
2556 flags: []string{"-implicit-handshake"},
2557 resumeSession: true,
2558 })
2559 tests = append(tests, testCase{
2560 testType: serverTest,
2561 name: "Basic-Server",
2562 resumeSession: true,
2563 })
2564 tests = append(tests, testCase{
2565 testType: serverTest,
2566 name: "Basic-Server-NoTickets",
2567 config: Config{
2568 SessionTicketsDisabled: true,
2569 },
2570 resumeSession: true,
2571 })
2572 tests = append(tests, testCase{
2573 testType: serverTest,
2574 name: "Basic-Server-Implicit",
2575 flags: []string{"-implicit-handshake"},
2576 resumeSession: true,
2577 })
2578 tests = append(tests, testCase{
2579 testType: serverTest,
2580 name: "Basic-Server-EarlyCallback",
2581 flags: []string{"-use-early-callback"},
2582 resumeSession: true,
2583 })
2584
2585 // TLS client auth.
2586 tests = append(tests, testCase{
2587 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002588 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04002589 config: Config{
2590 ClientAuth: RequireAnyClientCert,
2591 },
2592 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002593 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2594 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002595 },
2596 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002597 tests = append(tests, testCase{
2598 testType: clientTest,
2599 name: "ClientAuth-ECDSA-Client",
2600 config: Config{
2601 ClientAuth: RequireAnyClientCert,
2602 },
2603 flags: []string{
2604 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2605 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2606 },
2607 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002608 if async {
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002609 // Test async keys against each key exchange.
David Benjaminb4d65fd2015-05-29 17:11:21 -04002610 tests = append(tests, testCase{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002611 testType: serverTest,
2612 name: "Basic-Server-RSA",
David Benjaminb4d65fd2015-05-29 17:11:21 -04002613 config: Config{
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002614 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
David Benjaminb4d65fd2015-05-29 17:11:21 -04002615 },
2616 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002617 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2618 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002619 },
2620 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002621 tests = append(tests, testCase{
2622 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002623 name: "Basic-Server-ECDHE-RSA",
2624 config: Config{
2625 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2626 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002627 flags: []string{
2628 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2629 "-key-file", path.Join(*resourceDir, rsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002630 },
2631 })
2632 tests = append(tests, testCase{
2633 testType: serverTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07002634 name: "Basic-Server-ECDHE-ECDSA",
2635 config: Config{
2636 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2637 },
nagendra modadugu601448a2015-07-24 09:31:31 -07002638 flags: []string{
2639 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2640 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
nagendra modadugu601448a2015-07-24 09:31:31 -07002641 },
2642 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002643 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002644 tests = append(tests, testCase{
2645 testType: serverTest,
2646 name: "ClientAuth-Server",
2647 config: Config{
2648 Certificates: []Certificate{rsaCertificate},
2649 },
2650 flags: []string{"-require-any-client-certificate"},
2651 })
2652
2653 // No session ticket support; server doesn't send NewSessionTicket.
2654 tests = append(tests, testCase{
2655 name: "SessionTicketsDisabled-Client",
2656 config: Config{
2657 SessionTicketsDisabled: true,
2658 },
2659 })
2660 tests = append(tests, testCase{
2661 testType: serverTest,
2662 name: "SessionTicketsDisabled-Server",
2663 config: Config{
2664 SessionTicketsDisabled: true,
2665 },
2666 })
2667
2668 // Skip ServerKeyExchange in PSK key exchange if there's no
2669 // identity hint.
2670 tests = append(tests, testCase{
2671 name: "EmptyPSKHint-Client",
2672 config: Config{
2673 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2674 PreSharedKey: []byte("secret"),
2675 },
2676 flags: []string{"-psk", "secret"},
2677 })
2678 tests = append(tests, testCase{
2679 testType: serverTest,
2680 name: "EmptyPSKHint-Server",
2681 config: Config{
2682 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2683 PreSharedKey: []byte("secret"),
2684 },
2685 flags: []string{"-psk", "secret"},
2686 })
2687
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002688 tests = append(tests, testCase{
2689 testType: clientTest,
2690 name: "OCSPStapling-Client",
2691 flags: []string{
2692 "-enable-ocsp-stapling",
2693 "-expect-ocsp-response",
2694 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002695 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002696 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002697 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002698 })
2699
2700 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002701 testType: serverTest,
2702 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002703 expectedOCSPResponse: testOCSPResponse,
2704 flags: []string{
2705 "-ocsp-response",
2706 base64.StdEncoding.EncodeToString(testOCSPResponse),
2707 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002708 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002709 })
2710
Paul Lietar8f1c2682015-08-18 12:21:54 +01002711 tests = append(tests, testCase{
2712 testType: clientTest,
2713 name: "CertificateVerificationSucceed",
2714 flags: []string{
2715 "-verify-peer",
2716 },
2717 })
2718
2719 tests = append(tests, testCase{
2720 testType: clientTest,
2721 name: "CertificateVerificationFail",
2722 flags: []string{
2723 "-verify-fail",
2724 "-verify-peer",
2725 },
2726 shouldFail: true,
2727 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2728 })
2729
2730 tests = append(tests, testCase{
2731 testType: clientTest,
2732 name: "CertificateVerificationSoftFail",
2733 flags: []string{
2734 "-verify-fail",
2735 "-expect-verify-result",
2736 },
2737 })
2738
David Benjamin760b1dd2015-05-15 23:33:48 -04002739 if protocol == tls {
2740 tests = append(tests, testCase{
2741 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002742 renegotiate: 1,
2743 flags: []string{
2744 "-renegotiate-freely",
2745 "-expect-total-renegotiations", "1",
2746 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002747 })
2748 // NPN on client and server; results in post-handshake message.
2749 tests = append(tests, testCase{
2750 name: "NPN-Client",
2751 config: Config{
2752 NextProtos: []string{"foo"},
2753 },
2754 flags: []string{"-select-next-proto", "foo"},
2755 expectedNextProto: "foo",
2756 expectedNextProtoType: npn,
2757 })
2758 tests = append(tests, testCase{
2759 testType: serverTest,
2760 name: "NPN-Server",
2761 config: Config{
2762 NextProtos: []string{"bar"},
2763 },
2764 flags: []string{
2765 "-advertise-npn", "\x03foo\x03bar\x03baz",
2766 "-expect-next-proto", "bar",
2767 },
2768 expectedNextProto: "bar",
2769 expectedNextProtoType: npn,
2770 })
2771
2772 // TODO(davidben): Add tests for when False Start doesn't trigger.
2773
2774 // Client does False Start and negotiates NPN.
2775 tests = append(tests, testCase{
2776 name: "FalseStart",
2777 config: Config{
2778 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2779 NextProtos: []string{"foo"},
2780 Bugs: ProtocolBugs{
2781 ExpectFalseStart: true,
2782 },
2783 },
2784 flags: []string{
2785 "-false-start",
2786 "-select-next-proto", "foo",
2787 },
2788 shimWritesFirst: true,
2789 resumeSession: true,
2790 })
2791
2792 // Client does False Start and negotiates ALPN.
2793 tests = append(tests, testCase{
2794 name: "FalseStart-ALPN",
2795 config: Config{
2796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2797 NextProtos: []string{"foo"},
2798 Bugs: ProtocolBugs{
2799 ExpectFalseStart: true,
2800 },
2801 },
2802 flags: []string{
2803 "-false-start",
2804 "-advertise-alpn", "\x03foo",
2805 },
2806 shimWritesFirst: true,
2807 resumeSession: true,
2808 })
2809
2810 // Client does False Start but doesn't explicitly call
2811 // SSL_connect.
2812 tests = append(tests, testCase{
2813 name: "FalseStart-Implicit",
2814 config: Config{
2815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2816 NextProtos: []string{"foo"},
2817 },
2818 flags: []string{
2819 "-implicit-handshake",
2820 "-false-start",
2821 "-advertise-alpn", "\x03foo",
2822 },
2823 })
2824
2825 // False Start without session tickets.
2826 tests = append(tests, testCase{
2827 name: "FalseStart-SessionTicketsDisabled",
2828 config: Config{
2829 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2830 NextProtos: []string{"foo"},
2831 SessionTicketsDisabled: true,
2832 Bugs: ProtocolBugs{
2833 ExpectFalseStart: true,
2834 },
2835 },
2836 flags: []string{
2837 "-false-start",
2838 "-select-next-proto", "foo",
2839 },
2840 shimWritesFirst: true,
2841 })
2842
2843 // Server parses a V2ClientHello.
2844 tests = append(tests, testCase{
2845 testType: serverTest,
2846 name: "SendV2ClientHello",
2847 config: Config{
2848 // Choose a cipher suite that does not involve
2849 // elliptic curves, so no extensions are
2850 // involved.
2851 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2852 Bugs: ProtocolBugs{
2853 SendV2ClientHello: true,
2854 },
2855 },
2856 })
2857
2858 // Client sends a Channel ID.
2859 tests = append(tests, testCase{
2860 name: "ChannelID-Client",
2861 config: Config{
2862 RequestChannelID: true,
2863 },
Adam Langley7c803a62015-06-15 15:35:05 -07002864 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002865 resumeSession: true,
2866 expectChannelID: true,
2867 })
2868
2869 // Server accepts a Channel ID.
2870 tests = append(tests, testCase{
2871 testType: serverTest,
2872 name: "ChannelID-Server",
2873 config: Config{
2874 ChannelID: channelIDKey,
2875 },
2876 flags: []string{
2877 "-expect-channel-id",
2878 base64.StdEncoding.EncodeToString(channelIDBytes),
2879 },
2880 resumeSession: true,
2881 expectChannelID: true,
2882 })
David Benjamin30789da2015-08-29 22:56:45 -04002883
2884 // Bidirectional shutdown with the runner initiating.
2885 tests = append(tests, testCase{
2886 name: "Shutdown-Runner",
2887 config: Config{
2888 Bugs: ProtocolBugs{
2889 ExpectCloseNotify: true,
2890 },
2891 },
2892 flags: []string{"-check-close-notify"},
2893 })
2894
2895 // Bidirectional shutdown with the shim initiating. The runner,
2896 // in the meantime, sends garbage before the close_notify which
2897 // the shim must ignore.
2898 tests = append(tests, testCase{
2899 name: "Shutdown-Shim",
2900 config: Config{
2901 Bugs: ProtocolBugs{
2902 ExpectCloseNotify: true,
2903 },
2904 },
2905 shimShutsDown: true,
2906 sendEmptyRecords: 1,
2907 sendWarningAlerts: 1,
2908 flags: []string{"-check-close-notify"},
2909 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002910 } else {
2911 tests = append(tests, testCase{
2912 name: "SkipHelloVerifyRequest",
2913 config: Config{
2914 Bugs: ProtocolBugs{
2915 SkipHelloVerifyRequest: true,
2916 },
2917 },
2918 })
2919 }
2920
David Benjamin43ec06f2014-08-05 02:28:57 -04002921 var suffix string
2922 var flags []string
2923 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002924 if protocol == dtls {
2925 suffix = "-DTLS"
2926 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002927 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002928 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002929 flags = append(flags, "-async")
2930 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002931 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002932 }
2933 if splitHandshake {
2934 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002935 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002936 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002937 for _, test := range tests {
2938 test.protocol = protocol
2939 test.name += suffix
2940 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2941 test.flags = append(test.flags, flags...)
2942 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002943 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002944}
2945
Adam Langley524e7172015-02-20 16:04:00 -08002946func addDDoSCallbackTests() {
2947 // DDoS callback.
2948
2949 for _, resume := range []bool{false, true} {
2950 suffix := "Resume"
2951 if resume {
2952 suffix = "No" + suffix
2953 }
2954
2955 testCases = append(testCases, testCase{
2956 testType: serverTest,
2957 name: "Server-DDoS-OK-" + suffix,
2958 flags: []string{"-install-ddos-callback"},
2959 resumeSession: resume,
2960 })
2961
2962 failFlag := "-fail-ddos-callback"
2963 if resume {
2964 failFlag = "-fail-second-ddos-callback"
2965 }
2966 testCases = append(testCases, testCase{
2967 testType: serverTest,
2968 name: "Server-DDoS-Reject-" + suffix,
2969 flags: []string{"-install-ddos-callback", failFlag},
2970 resumeSession: resume,
2971 shouldFail: true,
2972 expectedError: ":CONNECTION_REJECTED:",
2973 })
2974 }
2975}
2976
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002977func addVersionNegotiationTests() {
2978 for i, shimVers := range tlsVersions {
2979 // Assemble flags to disable all newer versions on the shim.
2980 var flags []string
2981 for _, vers := range tlsVersions[i+1:] {
2982 flags = append(flags, vers.flag)
2983 }
2984
2985 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002986 protocols := []protocol{tls}
2987 if runnerVers.hasDTLS && shimVers.hasDTLS {
2988 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002989 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002990 for _, protocol := range protocols {
2991 expectedVersion := shimVers.version
2992 if runnerVers.version < shimVers.version {
2993 expectedVersion = runnerVers.version
2994 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002995
David Benjamin8b8c0062014-11-23 02:47:52 -05002996 suffix := shimVers.name + "-" + runnerVers.name
2997 if protocol == dtls {
2998 suffix += "-DTLS"
2999 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003000
David Benjamin1eb367c2014-12-12 18:17:51 -05003001 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3002
David Benjamin1e29a6b2014-12-10 02:27:24 -05003003 clientVers := shimVers.version
3004 if clientVers > VersionTLS10 {
3005 clientVers = VersionTLS10
3006 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003007 testCases = append(testCases, testCase{
3008 protocol: protocol,
3009 testType: clientTest,
3010 name: "VersionNegotiation-Client-" + suffix,
3011 config: Config{
3012 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003013 Bugs: ProtocolBugs{
3014 ExpectInitialRecordVersion: clientVers,
3015 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003016 },
3017 flags: flags,
3018 expectedVersion: expectedVersion,
3019 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003020 testCases = append(testCases, testCase{
3021 protocol: protocol,
3022 testType: clientTest,
3023 name: "VersionNegotiation-Client2-" + suffix,
3024 config: Config{
3025 MaxVersion: runnerVers.version,
3026 Bugs: ProtocolBugs{
3027 ExpectInitialRecordVersion: clientVers,
3028 },
3029 },
3030 flags: []string{"-max-version", shimVersFlag},
3031 expectedVersion: expectedVersion,
3032 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003033
3034 testCases = append(testCases, testCase{
3035 protocol: protocol,
3036 testType: serverTest,
3037 name: "VersionNegotiation-Server-" + suffix,
3038 config: Config{
3039 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003040 Bugs: ProtocolBugs{
3041 ExpectInitialRecordVersion: expectedVersion,
3042 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003043 },
3044 flags: flags,
3045 expectedVersion: expectedVersion,
3046 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003047 testCases = append(testCases, testCase{
3048 protocol: protocol,
3049 testType: serverTest,
3050 name: "VersionNegotiation-Server2-" + suffix,
3051 config: Config{
3052 MaxVersion: runnerVers.version,
3053 Bugs: ProtocolBugs{
3054 ExpectInitialRecordVersion: expectedVersion,
3055 },
3056 },
3057 flags: []string{"-max-version", shimVersFlag},
3058 expectedVersion: expectedVersion,
3059 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003060 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003061 }
3062 }
3063}
3064
David Benjaminaccb4542014-12-12 23:44:33 -05003065func addMinimumVersionTests() {
3066 for i, shimVers := range tlsVersions {
3067 // Assemble flags to disable all older versions on the shim.
3068 var flags []string
3069 for _, vers := range tlsVersions[:i] {
3070 flags = append(flags, vers.flag)
3071 }
3072
3073 for _, runnerVers := range tlsVersions {
3074 protocols := []protocol{tls}
3075 if runnerVers.hasDTLS && shimVers.hasDTLS {
3076 protocols = append(protocols, dtls)
3077 }
3078 for _, protocol := range protocols {
3079 suffix := shimVers.name + "-" + runnerVers.name
3080 if protocol == dtls {
3081 suffix += "-DTLS"
3082 }
3083 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3084
David Benjaminaccb4542014-12-12 23:44:33 -05003085 var expectedVersion uint16
3086 var shouldFail bool
3087 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003088 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003089 if runnerVers.version >= shimVers.version {
3090 expectedVersion = runnerVers.version
3091 } else {
3092 shouldFail = true
3093 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003094 if runnerVers.version > VersionSSL30 {
3095 expectedLocalError = "remote error: protocol version not supported"
3096 } else {
3097 expectedLocalError = "remote error: handshake failure"
3098 }
David Benjaminaccb4542014-12-12 23:44:33 -05003099 }
3100
3101 testCases = append(testCases, testCase{
3102 protocol: protocol,
3103 testType: clientTest,
3104 name: "MinimumVersion-Client-" + suffix,
3105 config: Config{
3106 MaxVersion: runnerVers.version,
3107 },
David Benjamin87909c02014-12-13 01:55:01 -05003108 flags: flags,
3109 expectedVersion: expectedVersion,
3110 shouldFail: shouldFail,
3111 expectedError: expectedError,
3112 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003113 })
3114 testCases = append(testCases, testCase{
3115 protocol: protocol,
3116 testType: clientTest,
3117 name: "MinimumVersion-Client2-" + suffix,
3118 config: Config{
3119 MaxVersion: runnerVers.version,
3120 },
David Benjamin87909c02014-12-13 01:55:01 -05003121 flags: []string{"-min-version", shimVersFlag},
3122 expectedVersion: expectedVersion,
3123 shouldFail: shouldFail,
3124 expectedError: expectedError,
3125 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003126 })
3127
3128 testCases = append(testCases, testCase{
3129 protocol: protocol,
3130 testType: serverTest,
3131 name: "MinimumVersion-Server-" + suffix,
3132 config: Config{
3133 MaxVersion: runnerVers.version,
3134 },
David Benjamin87909c02014-12-13 01:55:01 -05003135 flags: flags,
3136 expectedVersion: expectedVersion,
3137 shouldFail: shouldFail,
3138 expectedError: expectedError,
3139 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003140 })
3141 testCases = append(testCases, testCase{
3142 protocol: protocol,
3143 testType: serverTest,
3144 name: "MinimumVersion-Server2-" + suffix,
3145 config: Config{
3146 MaxVersion: runnerVers.version,
3147 },
David Benjamin87909c02014-12-13 01:55:01 -05003148 flags: []string{"-min-version", shimVersFlag},
3149 expectedVersion: expectedVersion,
3150 shouldFail: shouldFail,
3151 expectedError: expectedError,
3152 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003153 })
3154 }
3155 }
3156 }
3157}
3158
David Benjamin5c24a1d2014-08-31 00:59:27 -04003159func addD5BugTests() {
3160 testCases = append(testCases, testCase{
3161 testType: serverTest,
3162 name: "D5Bug-NoQuirk-Reject",
3163 config: Config{
3164 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3165 Bugs: ProtocolBugs{
3166 SSL3RSAKeyExchange: true,
3167 },
3168 },
3169 shouldFail: true,
3170 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3171 })
3172 testCases = append(testCases, testCase{
3173 testType: serverTest,
3174 name: "D5Bug-Quirk-Normal",
3175 config: Config{
3176 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3177 },
3178 flags: []string{"-tls-d5-bug"},
3179 })
3180 testCases = append(testCases, testCase{
3181 testType: serverTest,
3182 name: "D5Bug-Quirk-Bug",
3183 config: Config{
3184 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3185 Bugs: ProtocolBugs{
3186 SSL3RSAKeyExchange: true,
3187 },
3188 },
3189 flags: []string{"-tls-d5-bug"},
3190 })
3191}
3192
David Benjamine78bfde2014-09-06 12:45:15 -04003193func addExtensionTests() {
3194 testCases = append(testCases, testCase{
3195 testType: clientTest,
3196 name: "DuplicateExtensionClient",
3197 config: Config{
3198 Bugs: ProtocolBugs{
3199 DuplicateExtension: true,
3200 },
3201 },
3202 shouldFail: true,
3203 expectedLocalError: "remote error: error decoding message",
3204 })
3205 testCases = append(testCases, testCase{
3206 testType: serverTest,
3207 name: "DuplicateExtensionServer",
3208 config: Config{
3209 Bugs: ProtocolBugs{
3210 DuplicateExtension: true,
3211 },
3212 },
3213 shouldFail: true,
3214 expectedLocalError: "remote error: error decoding message",
3215 })
3216 testCases = append(testCases, testCase{
3217 testType: clientTest,
3218 name: "ServerNameExtensionClient",
3219 config: Config{
3220 Bugs: ProtocolBugs{
3221 ExpectServerName: "example.com",
3222 },
3223 },
3224 flags: []string{"-host-name", "example.com"},
3225 })
3226 testCases = append(testCases, testCase{
3227 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003228 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003229 config: Config{
3230 Bugs: ProtocolBugs{
3231 ExpectServerName: "mismatch.com",
3232 },
3233 },
3234 flags: []string{"-host-name", "example.com"},
3235 shouldFail: true,
3236 expectedLocalError: "tls: unexpected server name",
3237 })
3238 testCases = append(testCases, testCase{
3239 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003240 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003241 config: Config{
3242 Bugs: ProtocolBugs{
3243 ExpectServerName: "missing.com",
3244 },
3245 },
3246 shouldFail: true,
3247 expectedLocalError: "tls: unexpected server name",
3248 })
3249 testCases = append(testCases, testCase{
3250 testType: serverTest,
3251 name: "ServerNameExtensionServer",
3252 config: Config{
3253 ServerName: "example.com",
3254 },
3255 flags: []string{"-expect-server-name", "example.com"},
3256 resumeSession: true,
3257 })
David Benjaminae2888f2014-09-06 12:58:58 -04003258 testCases = append(testCases, testCase{
3259 testType: clientTest,
3260 name: "ALPNClient",
3261 config: Config{
3262 NextProtos: []string{"foo"},
3263 },
3264 flags: []string{
3265 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3266 "-expect-alpn", "foo",
3267 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003268 expectedNextProto: "foo",
3269 expectedNextProtoType: alpn,
3270 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003271 })
3272 testCases = append(testCases, testCase{
3273 testType: serverTest,
3274 name: "ALPNServer",
3275 config: Config{
3276 NextProtos: []string{"foo", "bar", "baz"},
3277 },
3278 flags: []string{
3279 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3280 "-select-alpn", "foo",
3281 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003282 expectedNextProto: "foo",
3283 expectedNextProtoType: alpn,
3284 resumeSession: true,
3285 })
3286 // Test that the server prefers ALPN over NPN.
3287 testCases = append(testCases, testCase{
3288 testType: serverTest,
3289 name: "ALPNServer-Preferred",
3290 config: Config{
3291 NextProtos: []string{"foo", "bar", "baz"},
3292 },
3293 flags: []string{
3294 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3295 "-select-alpn", "foo",
3296 "-advertise-npn", "\x03foo\x03bar\x03baz",
3297 },
3298 expectedNextProto: "foo",
3299 expectedNextProtoType: alpn,
3300 resumeSession: true,
3301 })
3302 testCases = append(testCases, testCase{
3303 testType: serverTest,
3304 name: "ALPNServer-Preferred-Swapped",
3305 config: Config{
3306 NextProtos: []string{"foo", "bar", "baz"},
3307 Bugs: ProtocolBugs{
3308 SwapNPNAndALPN: true,
3309 },
3310 },
3311 flags: []string{
3312 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3313 "-select-alpn", "foo",
3314 "-advertise-npn", "\x03foo\x03bar\x03baz",
3315 },
3316 expectedNextProto: "foo",
3317 expectedNextProtoType: alpn,
3318 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003319 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003320 var emptyString string
3321 testCases = append(testCases, testCase{
3322 testType: clientTest,
3323 name: "ALPNClient-EmptyProtocolName",
3324 config: Config{
3325 NextProtos: []string{""},
3326 Bugs: ProtocolBugs{
3327 // A server returning an empty ALPN protocol
3328 // should be rejected.
3329 ALPNProtocol: &emptyString,
3330 },
3331 },
3332 flags: []string{
3333 "-advertise-alpn", "\x03foo",
3334 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003335 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003336 expectedError: ":PARSE_TLSEXT:",
3337 })
3338 testCases = append(testCases, testCase{
3339 testType: serverTest,
3340 name: "ALPNServer-EmptyProtocolName",
3341 config: Config{
3342 // A ClientHello containing an empty ALPN protocol
3343 // should be rejected.
3344 NextProtos: []string{"foo", "", "baz"},
3345 },
3346 flags: []string{
3347 "-select-alpn", "foo",
3348 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003349 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003350 expectedError: ":PARSE_TLSEXT:",
3351 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003352 // Test that negotiating both NPN and ALPN is forbidden.
3353 testCases = append(testCases, testCase{
3354 name: "NegotiateALPNAndNPN",
3355 config: Config{
3356 NextProtos: []string{"foo", "bar", "baz"},
3357 Bugs: ProtocolBugs{
3358 NegotiateALPNAndNPN: true,
3359 },
3360 },
3361 flags: []string{
3362 "-advertise-alpn", "\x03foo",
3363 "-select-next-proto", "foo",
3364 },
3365 shouldFail: true,
3366 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3367 })
3368 testCases = append(testCases, testCase{
3369 name: "NegotiateALPNAndNPN-Swapped",
3370 config: Config{
3371 NextProtos: []string{"foo", "bar", "baz"},
3372 Bugs: ProtocolBugs{
3373 NegotiateALPNAndNPN: true,
3374 SwapNPNAndALPN: true,
3375 },
3376 },
3377 flags: []string{
3378 "-advertise-alpn", "\x03foo",
3379 "-select-next-proto", "foo",
3380 },
3381 shouldFail: true,
3382 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3383 })
David Benjamin091c4b92015-10-26 13:33:21 -04003384 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3385 testCases = append(testCases, testCase{
3386 name: "DisableNPN",
3387 config: Config{
3388 NextProtos: []string{"foo"},
3389 },
3390 flags: []string{
3391 "-select-next-proto", "foo",
3392 "-disable-npn",
3393 },
3394 expectNoNextProto: true,
3395 })
Adam Langley38311732014-10-16 19:04:35 -07003396 // Resume with a corrupt ticket.
3397 testCases = append(testCases, testCase{
3398 testType: serverTest,
3399 name: "CorruptTicket",
3400 config: Config{
3401 Bugs: ProtocolBugs{
3402 CorruptTicket: true,
3403 },
3404 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003405 resumeSession: true,
3406 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003407 })
David Benjamind98452d2015-06-16 14:16:23 -04003408 // Test the ticket callback, with and without renewal.
3409 testCases = append(testCases, testCase{
3410 testType: serverTest,
3411 name: "TicketCallback",
3412 resumeSession: true,
3413 flags: []string{"-use-ticket-callback"},
3414 })
3415 testCases = append(testCases, testCase{
3416 testType: serverTest,
3417 name: "TicketCallback-Renew",
3418 config: Config{
3419 Bugs: ProtocolBugs{
3420 ExpectNewTicket: true,
3421 },
3422 },
3423 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3424 resumeSession: true,
3425 })
Adam Langley38311732014-10-16 19:04:35 -07003426 // Resume with an oversized session id.
3427 testCases = append(testCases, testCase{
3428 testType: serverTest,
3429 name: "OversizedSessionId",
3430 config: Config{
3431 Bugs: ProtocolBugs{
3432 OversizedSessionId: true,
3433 },
3434 },
3435 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003436 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003437 expectedError: ":DECODE_ERROR:",
3438 })
David Benjaminca6c8262014-11-15 19:06:08 -05003439 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3440 // are ignored.
3441 testCases = append(testCases, testCase{
3442 protocol: dtls,
3443 name: "SRTP-Client",
3444 config: Config{
3445 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3446 },
3447 flags: []string{
3448 "-srtp-profiles",
3449 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3450 },
3451 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3452 })
3453 testCases = append(testCases, testCase{
3454 protocol: dtls,
3455 testType: serverTest,
3456 name: "SRTP-Server",
3457 config: Config{
3458 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3459 },
3460 flags: []string{
3461 "-srtp-profiles",
3462 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3463 },
3464 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3465 })
3466 // Test that the MKI is ignored.
3467 testCases = append(testCases, testCase{
3468 protocol: dtls,
3469 testType: serverTest,
3470 name: "SRTP-Server-IgnoreMKI",
3471 config: Config{
3472 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3473 Bugs: ProtocolBugs{
3474 SRTPMasterKeyIdentifer: "bogus",
3475 },
3476 },
3477 flags: []string{
3478 "-srtp-profiles",
3479 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3480 },
3481 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3482 })
3483 // Test that SRTP isn't negotiated on the server if there were
3484 // no matching profiles.
3485 testCases = append(testCases, testCase{
3486 protocol: dtls,
3487 testType: serverTest,
3488 name: "SRTP-Server-NoMatch",
3489 config: Config{
3490 SRTPProtectionProfiles: []uint16{100, 101, 102},
3491 },
3492 flags: []string{
3493 "-srtp-profiles",
3494 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3495 },
3496 expectedSRTPProtectionProfile: 0,
3497 })
3498 // Test that the server returning an invalid SRTP profile is
3499 // flagged as an error by the client.
3500 testCases = append(testCases, testCase{
3501 protocol: dtls,
3502 name: "SRTP-Client-NoMatch",
3503 config: Config{
3504 Bugs: ProtocolBugs{
3505 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3506 },
3507 },
3508 flags: []string{
3509 "-srtp-profiles",
3510 "SRTP_AES128_CM_SHA1_80",
3511 },
3512 shouldFail: true,
3513 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3514 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003515 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003516 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003517 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003518 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003519 flags: []string{
3520 "-enable-signed-cert-timestamps",
3521 "-expect-signed-cert-timestamps",
3522 base64.StdEncoding.EncodeToString(testSCTList),
3523 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003524 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003525 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003526 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003527 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003528 testType: serverTest,
3529 flags: []string{
3530 "-signed-cert-timestamps",
3531 base64.StdEncoding.EncodeToString(testSCTList),
3532 },
3533 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003534 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003535 })
3536 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003537 testType: clientTest,
3538 name: "ClientHelloPadding",
3539 config: Config{
3540 Bugs: ProtocolBugs{
3541 RequireClientHelloSize: 512,
3542 },
3543 },
3544 // This hostname just needs to be long enough to push the
3545 // ClientHello into F5's danger zone between 256 and 511 bytes
3546 // long.
3547 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3548 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003549
3550 // Extensions should not function in SSL 3.0.
3551 testCases = append(testCases, testCase{
3552 testType: serverTest,
3553 name: "SSLv3Extensions-NoALPN",
3554 config: Config{
3555 MaxVersion: VersionSSL30,
3556 NextProtos: []string{"foo", "bar", "baz"},
3557 },
3558 flags: []string{
3559 "-select-alpn", "foo",
3560 },
3561 expectNoNextProto: true,
3562 })
3563
3564 // Test session tickets separately as they follow a different codepath.
3565 testCases = append(testCases, testCase{
3566 testType: serverTest,
3567 name: "SSLv3Extensions-NoTickets",
3568 config: Config{
3569 MaxVersion: VersionSSL30,
3570 Bugs: ProtocolBugs{
3571 // Historically, session tickets in SSL 3.0
3572 // failed in different ways depending on whether
3573 // the client supported renegotiation_info.
3574 NoRenegotiationInfo: true,
3575 },
3576 },
3577 resumeSession: true,
3578 })
3579 testCases = append(testCases, testCase{
3580 testType: serverTest,
3581 name: "SSLv3Extensions-NoTickets2",
3582 config: Config{
3583 MaxVersion: VersionSSL30,
3584 },
3585 resumeSession: true,
3586 })
3587
3588 // But SSL 3.0 does send and process renegotiation_info.
3589 testCases = append(testCases, testCase{
3590 testType: serverTest,
3591 name: "SSLv3Extensions-RenegotiationInfo",
3592 config: Config{
3593 MaxVersion: VersionSSL30,
3594 Bugs: ProtocolBugs{
3595 RequireRenegotiationInfo: true,
3596 },
3597 },
3598 })
3599 testCases = append(testCases, testCase{
3600 testType: serverTest,
3601 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3602 config: Config{
3603 MaxVersion: VersionSSL30,
3604 Bugs: ProtocolBugs{
3605 NoRenegotiationInfo: true,
3606 SendRenegotiationSCSV: true,
3607 RequireRenegotiationInfo: true,
3608 },
3609 },
3610 })
David Benjamine78bfde2014-09-06 12:45:15 -04003611}
3612
David Benjamin01fe8202014-09-24 15:21:44 -04003613func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003614 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003615 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003616 protocols := []protocol{tls}
3617 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3618 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003619 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003620 for _, protocol := range protocols {
3621 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3622 if protocol == dtls {
3623 suffix += "-DTLS"
3624 }
3625
David Benjaminece3de92015-03-16 18:02:20 -04003626 if sessionVers.version == resumeVers.version {
3627 testCases = append(testCases, testCase{
3628 protocol: protocol,
3629 name: "Resume-Client" + suffix,
3630 resumeSession: true,
3631 config: Config{
3632 MaxVersion: sessionVers.version,
3633 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003634 },
David Benjaminece3de92015-03-16 18:02:20 -04003635 expectedVersion: sessionVers.version,
3636 expectedResumeVersion: resumeVers.version,
3637 })
3638 } else {
3639 testCases = append(testCases, testCase{
3640 protocol: protocol,
3641 name: "Resume-Client-Mismatch" + suffix,
3642 resumeSession: true,
3643 config: Config{
3644 MaxVersion: sessionVers.version,
3645 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003646 },
David Benjaminece3de92015-03-16 18:02:20 -04003647 expectedVersion: sessionVers.version,
3648 resumeConfig: &Config{
3649 MaxVersion: resumeVers.version,
3650 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3651 Bugs: ProtocolBugs{
3652 AllowSessionVersionMismatch: true,
3653 },
3654 },
3655 expectedResumeVersion: resumeVers.version,
3656 shouldFail: true,
3657 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3658 })
3659 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003660
3661 testCases = append(testCases, testCase{
3662 protocol: protocol,
3663 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003664 resumeSession: true,
3665 config: Config{
3666 MaxVersion: sessionVers.version,
3667 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3668 },
3669 expectedVersion: sessionVers.version,
3670 resumeConfig: &Config{
3671 MaxVersion: resumeVers.version,
3672 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3673 },
3674 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003675 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003676 expectedResumeVersion: resumeVers.version,
3677 })
3678
David Benjamin8b8c0062014-11-23 02:47:52 -05003679 testCases = append(testCases, testCase{
3680 protocol: protocol,
3681 testType: serverTest,
3682 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003683 resumeSession: true,
3684 config: Config{
3685 MaxVersion: sessionVers.version,
3686 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3687 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003688 expectedVersion: sessionVers.version,
3689 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003690 resumeConfig: &Config{
3691 MaxVersion: resumeVers.version,
3692 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3693 },
3694 expectedResumeVersion: resumeVers.version,
3695 })
3696 }
David Benjamin01fe8202014-09-24 15:21:44 -04003697 }
3698 }
David Benjaminece3de92015-03-16 18:02:20 -04003699
3700 testCases = append(testCases, testCase{
3701 name: "Resume-Client-CipherMismatch",
3702 resumeSession: true,
3703 config: Config{
3704 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3705 },
3706 resumeConfig: &Config{
3707 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3708 Bugs: ProtocolBugs{
3709 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3710 },
3711 },
3712 shouldFail: true,
3713 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3714 })
David Benjamin01fe8202014-09-24 15:21:44 -04003715}
3716
Adam Langley2ae77d22014-10-28 17:29:33 -07003717func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003718 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003719 testCases = append(testCases, testCase{
3720 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003721 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003722 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003723 shouldFail: true,
3724 expectedError: ":NO_RENEGOTIATION:",
3725 expectedLocalError: "remote error: no renegotiation",
3726 })
Adam Langley5021b222015-06-12 18:27:58 -07003727 // The server shouldn't echo the renegotiation extension unless
3728 // requested by the client.
3729 testCases = append(testCases, testCase{
3730 testType: serverTest,
3731 name: "Renegotiate-Server-NoExt",
3732 config: Config{
3733 Bugs: ProtocolBugs{
3734 NoRenegotiationInfo: true,
3735 RequireRenegotiationInfo: true,
3736 },
3737 },
3738 shouldFail: true,
3739 expectedLocalError: "renegotiation extension missing",
3740 })
3741 // The renegotiation SCSV should be sufficient for the server to echo
3742 // the extension.
3743 testCases = append(testCases, testCase{
3744 testType: serverTest,
3745 name: "Renegotiate-Server-NoExt-SCSV",
3746 config: Config{
3747 Bugs: ProtocolBugs{
3748 NoRenegotiationInfo: true,
3749 SendRenegotiationSCSV: true,
3750 RequireRenegotiationInfo: true,
3751 },
3752 },
3753 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003754 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003755 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003756 config: Config{
3757 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003758 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003759 },
3760 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003761 renegotiate: 1,
3762 flags: []string{
3763 "-renegotiate-freely",
3764 "-expect-total-renegotiations", "1",
3765 },
David Benjamincdea40c2015-03-19 14:09:43 -04003766 })
3767 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003768 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003769 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003770 config: Config{
3771 Bugs: ProtocolBugs{
3772 EmptyRenegotiationInfo: true,
3773 },
3774 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003775 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003776 shouldFail: true,
3777 expectedError: ":RENEGOTIATION_MISMATCH:",
3778 })
3779 testCases = append(testCases, testCase{
3780 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003781 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003782 config: Config{
3783 Bugs: ProtocolBugs{
3784 BadRenegotiationInfo: true,
3785 },
3786 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003787 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003788 shouldFail: true,
3789 expectedError: ":RENEGOTIATION_MISMATCH:",
3790 })
3791 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003792 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003793 config: Config{
3794 Bugs: ProtocolBugs{
3795 NoRenegotiationInfo: true,
3796 },
3797 },
3798 shouldFail: true,
3799 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3800 flags: []string{"-no-legacy-server-connect"},
3801 })
3802 testCases = append(testCases, testCase{
3803 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003804 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003805 config: Config{
3806 Bugs: ProtocolBugs{
3807 NoRenegotiationInfo: true,
3808 },
3809 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003810 flags: []string{
3811 "-renegotiate-freely",
3812 "-expect-total-renegotiations", "1",
3813 },
David Benjamincff0b902015-05-15 23:09:47 -04003814 })
3815 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003816 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003817 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003818 config: Config{
3819 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3820 },
3821 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003822 flags: []string{
3823 "-renegotiate-freely",
3824 "-expect-total-renegotiations", "1",
3825 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003826 })
3827 testCases = append(testCases, testCase{
3828 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003829 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003830 config: Config{
3831 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3832 },
3833 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003834 flags: []string{
3835 "-renegotiate-freely",
3836 "-expect-total-renegotiations", "1",
3837 },
David Benjaminb16346b2015-04-08 19:16:58 -04003838 })
3839 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003840 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003841 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003842 config: Config{
3843 MaxVersion: VersionTLS10,
3844 Bugs: ProtocolBugs{
3845 RequireSameRenegoClientVersion: true,
3846 },
3847 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003848 flags: []string{
3849 "-renegotiate-freely",
3850 "-expect-total-renegotiations", "1",
3851 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003852 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003853 testCases = append(testCases, testCase{
3854 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003855 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003856 config: Config{
3857 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3858 NextProtos: []string{"foo"},
3859 },
3860 flags: []string{
3861 "-false-start",
3862 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003863 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003864 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003865 },
3866 shimWritesFirst: true,
3867 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003868
3869 // Client-side renegotiation controls.
3870 testCases = append(testCases, testCase{
3871 name: "Renegotiate-Client-Forbidden-1",
3872 renegotiate: 1,
3873 shouldFail: true,
3874 expectedError: ":NO_RENEGOTIATION:",
3875 expectedLocalError: "remote error: no renegotiation",
3876 })
3877 testCases = append(testCases, testCase{
3878 name: "Renegotiate-Client-Once-1",
3879 renegotiate: 1,
3880 flags: []string{
3881 "-renegotiate-once",
3882 "-expect-total-renegotiations", "1",
3883 },
3884 })
3885 testCases = append(testCases, testCase{
3886 name: "Renegotiate-Client-Freely-1",
3887 renegotiate: 1,
3888 flags: []string{
3889 "-renegotiate-freely",
3890 "-expect-total-renegotiations", "1",
3891 },
3892 })
3893 testCases = append(testCases, testCase{
3894 name: "Renegotiate-Client-Once-2",
3895 renegotiate: 2,
3896 flags: []string{"-renegotiate-once"},
3897 shouldFail: true,
3898 expectedError: ":NO_RENEGOTIATION:",
3899 expectedLocalError: "remote error: no renegotiation",
3900 })
3901 testCases = append(testCases, testCase{
3902 name: "Renegotiate-Client-Freely-2",
3903 renegotiate: 2,
3904 flags: []string{
3905 "-renegotiate-freely",
3906 "-expect-total-renegotiations", "2",
3907 },
3908 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003909}
3910
David Benjamin5e961c12014-11-07 01:48:35 -05003911func addDTLSReplayTests() {
3912 // Test that sequence number replays are detected.
3913 testCases = append(testCases, testCase{
3914 protocol: dtls,
3915 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003916 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003917 replayWrites: true,
3918 })
3919
David Benjamin8e6db492015-07-25 18:29:23 -04003920 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003921 // than the retransmit window.
3922 testCases = append(testCases, testCase{
3923 protocol: dtls,
3924 name: "DTLS-Replay-LargeGaps",
3925 config: Config{
3926 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003927 SequenceNumberMapping: func(in uint64) uint64 {
3928 return in * 127
3929 },
David Benjamin5e961c12014-11-07 01:48:35 -05003930 },
3931 },
David Benjamin8e6db492015-07-25 18:29:23 -04003932 messageCount: 200,
3933 replayWrites: true,
3934 })
3935
3936 // Test the incoming sequence number changing non-monotonically.
3937 testCases = append(testCases, testCase{
3938 protocol: dtls,
3939 name: "DTLS-Replay-NonMonotonic",
3940 config: Config{
3941 Bugs: ProtocolBugs{
3942 SequenceNumberMapping: func(in uint64) uint64 {
3943 return in ^ 31
3944 },
3945 },
3946 },
3947 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003948 replayWrites: true,
3949 })
3950}
3951
David Benjamin000800a2014-11-14 01:43:59 -05003952var testHashes = []struct {
3953 name string
3954 id uint8
3955}{
3956 {"SHA1", hashSHA1},
3957 {"SHA224", hashSHA224},
3958 {"SHA256", hashSHA256},
3959 {"SHA384", hashSHA384},
3960 {"SHA512", hashSHA512},
3961}
3962
3963func addSigningHashTests() {
3964 // Make sure each hash works. Include some fake hashes in the list and
3965 // ensure they're ignored.
3966 for _, hash := range testHashes {
3967 testCases = append(testCases, testCase{
3968 name: "SigningHash-ClientAuth-" + hash.name,
3969 config: Config{
3970 ClientAuth: RequireAnyClientCert,
3971 SignatureAndHashes: []signatureAndHash{
3972 {signatureRSA, 42},
3973 {signatureRSA, hash.id},
3974 {signatureRSA, 255},
3975 },
3976 },
3977 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003978 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3979 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003980 },
3981 })
3982
3983 testCases = append(testCases, testCase{
3984 testType: serverTest,
3985 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3986 config: Config{
3987 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3988 SignatureAndHashes: []signatureAndHash{
3989 {signatureRSA, 42},
3990 {signatureRSA, hash.id},
3991 {signatureRSA, 255},
3992 },
3993 },
3994 })
3995 }
3996
3997 // Test that hash resolution takes the signature type into account.
3998 testCases = append(testCases, testCase{
3999 name: "SigningHash-ClientAuth-SignatureType",
4000 config: Config{
4001 ClientAuth: RequireAnyClientCert,
4002 SignatureAndHashes: []signatureAndHash{
4003 {signatureECDSA, hashSHA512},
4004 {signatureRSA, hashSHA384},
4005 {signatureECDSA, hashSHA1},
4006 },
4007 },
4008 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004011 },
4012 })
4013
4014 testCases = append(testCases, testCase{
4015 testType: serverTest,
4016 name: "SigningHash-ServerKeyExchange-SignatureType",
4017 config: Config{
4018 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4019 SignatureAndHashes: []signatureAndHash{
4020 {signatureECDSA, hashSHA512},
4021 {signatureRSA, hashSHA384},
4022 {signatureECDSA, hashSHA1},
4023 },
4024 },
4025 })
4026
4027 // Test that, if the list is missing, the peer falls back to SHA-1.
4028 testCases = append(testCases, testCase{
4029 name: "SigningHash-ClientAuth-Fallback",
4030 config: Config{
4031 ClientAuth: RequireAnyClientCert,
4032 SignatureAndHashes: []signatureAndHash{
4033 {signatureRSA, hashSHA1},
4034 },
4035 Bugs: ProtocolBugs{
4036 NoSignatureAndHashes: true,
4037 },
4038 },
4039 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004040 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4041 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004042 },
4043 })
4044
4045 testCases = append(testCases, testCase{
4046 testType: serverTest,
4047 name: "SigningHash-ServerKeyExchange-Fallback",
4048 config: Config{
4049 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4050 SignatureAndHashes: []signatureAndHash{
4051 {signatureRSA, hashSHA1},
4052 },
4053 Bugs: ProtocolBugs{
4054 NoSignatureAndHashes: true,
4055 },
4056 },
4057 })
David Benjamin72dc7832015-03-16 17:49:43 -04004058
4059 // Test that hash preferences are enforced. BoringSSL defaults to
4060 // rejecting MD5 signatures.
4061 testCases = append(testCases, testCase{
4062 testType: serverTest,
4063 name: "SigningHash-ClientAuth-Enforced",
4064 config: Config{
4065 Certificates: []Certificate{rsaCertificate},
4066 SignatureAndHashes: []signatureAndHash{
4067 {signatureRSA, hashMD5},
4068 // Advertise SHA-1 so the handshake will
4069 // proceed, but the shim's preferences will be
4070 // ignored in CertificateVerify generation, so
4071 // MD5 will be chosen.
4072 {signatureRSA, hashSHA1},
4073 },
4074 Bugs: ProtocolBugs{
4075 IgnorePeerSignatureAlgorithmPreferences: true,
4076 },
4077 },
4078 flags: []string{"-require-any-client-certificate"},
4079 shouldFail: true,
4080 expectedError: ":WRONG_SIGNATURE_TYPE:",
4081 })
4082
4083 testCases = append(testCases, testCase{
4084 name: "SigningHash-ServerKeyExchange-Enforced",
4085 config: Config{
4086 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4087 SignatureAndHashes: []signatureAndHash{
4088 {signatureRSA, hashMD5},
4089 },
4090 Bugs: ProtocolBugs{
4091 IgnorePeerSignatureAlgorithmPreferences: true,
4092 },
4093 },
4094 shouldFail: true,
4095 expectedError: ":WRONG_SIGNATURE_TYPE:",
4096 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004097
4098 // Test that the agreed upon digest respects the client preferences and
4099 // the server digests.
4100 testCases = append(testCases, testCase{
4101 name: "Agree-Digest-Fallback",
4102 config: Config{
4103 ClientAuth: RequireAnyClientCert,
4104 SignatureAndHashes: []signatureAndHash{
4105 {signatureRSA, hashSHA512},
4106 {signatureRSA, hashSHA1},
4107 },
4108 },
4109 flags: []string{
4110 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4111 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4112 },
4113 digestPrefs: "SHA256",
4114 expectedClientCertSignatureHash: hashSHA1,
4115 })
4116 testCases = append(testCases, testCase{
4117 name: "Agree-Digest-SHA256",
4118 config: Config{
4119 ClientAuth: RequireAnyClientCert,
4120 SignatureAndHashes: []signatureAndHash{
4121 {signatureRSA, hashSHA1},
4122 {signatureRSA, hashSHA256},
4123 },
4124 },
4125 flags: []string{
4126 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4127 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4128 },
4129 digestPrefs: "SHA256,SHA1",
4130 expectedClientCertSignatureHash: hashSHA256,
4131 })
4132 testCases = append(testCases, testCase{
4133 name: "Agree-Digest-SHA1",
4134 config: Config{
4135 ClientAuth: RequireAnyClientCert,
4136 SignatureAndHashes: []signatureAndHash{
4137 {signatureRSA, hashSHA1},
4138 },
4139 },
4140 flags: []string{
4141 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4142 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4143 },
4144 digestPrefs: "SHA512,SHA256,SHA1",
4145 expectedClientCertSignatureHash: hashSHA1,
4146 })
4147 testCases = append(testCases, testCase{
4148 name: "Agree-Digest-Default",
4149 config: Config{
4150 ClientAuth: RequireAnyClientCert,
4151 SignatureAndHashes: []signatureAndHash{
4152 {signatureRSA, hashSHA256},
4153 {signatureECDSA, hashSHA256},
4154 {signatureRSA, hashSHA1},
4155 {signatureECDSA, hashSHA1},
4156 },
4157 },
4158 flags: []string{
4159 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4160 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4161 },
4162 expectedClientCertSignatureHash: hashSHA256,
4163 })
David Benjamin000800a2014-11-14 01:43:59 -05004164}
4165
David Benjamin83f90402015-01-27 01:09:43 -05004166// timeouts is the retransmit schedule for BoringSSL. It doubles and
4167// caps at 60 seconds. On the 13th timeout, it gives up.
4168var timeouts = []time.Duration{
4169 1 * time.Second,
4170 2 * time.Second,
4171 4 * time.Second,
4172 8 * time.Second,
4173 16 * time.Second,
4174 32 * time.Second,
4175 60 * time.Second,
4176 60 * time.Second,
4177 60 * time.Second,
4178 60 * time.Second,
4179 60 * time.Second,
4180 60 * time.Second,
4181 60 * time.Second,
4182}
4183
4184func addDTLSRetransmitTests() {
4185 // Test that this is indeed the timeout schedule. Stress all
4186 // four patterns of handshake.
4187 for i := 1; i < len(timeouts); i++ {
4188 number := strconv.Itoa(i)
4189 testCases = append(testCases, testCase{
4190 protocol: dtls,
4191 name: "DTLS-Retransmit-Client-" + number,
4192 config: Config{
4193 Bugs: ProtocolBugs{
4194 TimeoutSchedule: timeouts[:i],
4195 },
4196 },
4197 resumeSession: true,
4198 flags: []string{"-async"},
4199 })
4200 testCases = append(testCases, testCase{
4201 protocol: dtls,
4202 testType: serverTest,
4203 name: "DTLS-Retransmit-Server-" + number,
4204 config: Config{
4205 Bugs: ProtocolBugs{
4206 TimeoutSchedule: timeouts[:i],
4207 },
4208 },
4209 resumeSession: true,
4210 flags: []string{"-async"},
4211 })
4212 }
4213
4214 // Test that exceeding the timeout schedule hits a read
4215 // timeout.
4216 testCases = append(testCases, testCase{
4217 protocol: dtls,
4218 name: "DTLS-Retransmit-Timeout",
4219 config: Config{
4220 Bugs: ProtocolBugs{
4221 TimeoutSchedule: timeouts,
4222 },
4223 },
4224 resumeSession: true,
4225 flags: []string{"-async"},
4226 shouldFail: true,
4227 expectedError: ":READ_TIMEOUT_EXPIRED:",
4228 })
4229
4230 // Test that timeout handling has a fudge factor, due to API
4231 // problems.
4232 testCases = append(testCases, testCase{
4233 protocol: dtls,
4234 name: "DTLS-Retransmit-Fudge",
4235 config: Config{
4236 Bugs: ProtocolBugs{
4237 TimeoutSchedule: []time.Duration{
4238 timeouts[0] - 10*time.Millisecond,
4239 },
4240 },
4241 },
4242 resumeSession: true,
4243 flags: []string{"-async"},
4244 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004245
4246 // Test that the final Finished retransmitting isn't
4247 // duplicated if the peer badly fragments everything.
4248 testCases = append(testCases, testCase{
4249 testType: serverTest,
4250 protocol: dtls,
4251 name: "DTLS-Retransmit-Fragmented",
4252 config: Config{
4253 Bugs: ProtocolBugs{
4254 TimeoutSchedule: []time.Duration{timeouts[0]},
4255 MaxHandshakeRecordLength: 2,
4256 },
4257 },
4258 flags: []string{"-async"},
4259 })
David Benjamin83f90402015-01-27 01:09:43 -05004260}
4261
David Benjaminc565ebb2015-04-03 04:06:36 -04004262func addExportKeyingMaterialTests() {
4263 for _, vers := range tlsVersions {
4264 if vers.version == VersionSSL30 {
4265 continue
4266 }
4267 testCases = append(testCases, testCase{
4268 name: "ExportKeyingMaterial-" + vers.name,
4269 config: Config{
4270 MaxVersion: vers.version,
4271 },
4272 exportKeyingMaterial: 1024,
4273 exportLabel: "label",
4274 exportContext: "context",
4275 useExportContext: true,
4276 })
4277 testCases = append(testCases, testCase{
4278 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4279 config: Config{
4280 MaxVersion: vers.version,
4281 },
4282 exportKeyingMaterial: 1024,
4283 })
4284 testCases = append(testCases, testCase{
4285 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4286 config: Config{
4287 MaxVersion: vers.version,
4288 },
4289 exportKeyingMaterial: 1024,
4290 useExportContext: true,
4291 })
4292 testCases = append(testCases, testCase{
4293 name: "ExportKeyingMaterial-Small-" + vers.name,
4294 config: Config{
4295 MaxVersion: vers.version,
4296 },
4297 exportKeyingMaterial: 1,
4298 exportLabel: "label",
4299 exportContext: "context",
4300 useExportContext: true,
4301 })
4302 }
4303 testCases = append(testCases, testCase{
4304 name: "ExportKeyingMaterial-SSL3",
4305 config: Config{
4306 MaxVersion: VersionSSL30,
4307 },
4308 exportKeyingMaterial: 1024,
4309 exportLabel: "label",
4310 exportContext: "context",
4311 useExportContext: true,
4312 shouldFail: true,
4313 expectedError: "failed to export keying material",
4314 })
4315}
4316
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004317func addTLSUniqueTests() {
4318 for _, isClient := range []bool{false, true} {
4319 for _, isResumption := range []bool{false, true} {
4320 for _, hasEMS := range []bool{false, true} {
4321 var suffix string
4322 if isResumption {
4323 suffix = "Resume-"
4324 } else {
4325 suffix = "Full-"
4326 }
4327
4328 if hasEMS {
4329 suffix += "EMS-"
4330 } else {
4331 suffix += "NoEMS-"
4332 }
4333
4334 if isClient {
4335 suffix += "Client"
4336 } else {
4337 suffix += "Server"
4338 }
4339
4340 test := testCase{
4341 name: "TLSUnique-" + suffix,
4342 testTLSUnique: true,
4343 config: Config{
4344 Bugs: ProtocolBugs{
4345 NoExtendedMasterSecret: !hasEMS,
4346 },
4347 },
4348 }
4349
4350 if isResumption {
4351 test.resumeSession = true
4352 test.resumeConfig = &Config{
4353 Bugs: ProtocolBugs{
4354 NoExtendedMasterSecret: !hasEMS,
4355 },
4356 }
4357 }
4358
4359 if isResumption && !hasEMS {
4360 test.shouldFail = true
4361 test.expectedError = "failed to get tls-unique"
4362 }
4363
4364 testCases = append(testCases, test)
4365 }
4366 }
4367 }
4368}
4369
Adam Langley09505632015-07-30 18:10:13 -07004370func addCustomExtensionTests() {
4371 expectedContents := "custom extension"
4372 emptyString := ""
4373
4374 for _, isClient := range []bool{false, true} {
4375 suffix := "Server"
4376 flag := "-enable-server-custom-extension"
4377 testType := serverTest
4378 if isClient {
4379 suffix = "Client"
4380 flag = "-enable-client-custom-extension"
4381 testType = clientTest
4382 }
4383
4384 testCases = append(testCases, testCase{
4385 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004386 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004387 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004388 Bugs: ProtocolBugs{
4389 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004390 ExpectedCustomExtension: &expectedContents,
4391 },
4392 },
4393 flags: []string{flag},
4394 })
4395
4396 // If the parse callback fails, the handshake should also fail.
4397 testCases = append(testCases, testCase{
4398 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004399 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004400 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004401 Bugs: ProtocolBugs{
4402 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004403 ExpectedCustomExtension: &expectedContents,
4404 },
4405 },
David Benjamin399e7c92015-07-30 23:01:27 -04004406 flags: []string{flag},
4407 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004408 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4409 })
4410
4411 // If the add callback fails, the handshake should also fail.
4412 testCases = append(testCases, testCase{
4413 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004414 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004415 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004416 Bugs: ProtocolBugs{
4417 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004418 ExpectedCustomExtension: &expectedContents,
4419 },
4420 },
David Benjamin399e7c92015-07-30 23:01:27 -04004421 flags: []string{flag, "-custom-extension-fail-add"},
4422 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004423 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4424 })
4425
4426 // If the add callback returns zero, no extension should be
4427 // added.
4428 skipCustomExtension := expectedContents
4429 if isClient {
4430 // For the case where the client skips sending the
4431 // custom extension, the server must not “echo” it.
4432 skipCustomExtension = ""
4433 }
4434 testCases = append(testCases, testCase{
4435 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004436 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004437 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004438 Bugs: ProtocolBugs{
4439 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004440 ExpectedCustomExtension: &emptyString,
4441 },
4442 },
4443 flags: []string{flag, "-custom-extension-skip"},
4444 })
4445 }
4446
4447 // The custom extension add callback should not be called if the client
4448 // doesn't send the extension.
4449 testCases = append(testCases, testCase{
4450 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004451 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004452 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004453 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004454 ExpectedCustomExtension: &emptyString,
4455 },
4456 },
4457 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4458 })
Adam Langley2deb9842015-08-07 11:15:37 -07004459
4460 // Test an unknown extension from the server.
4461 testCases = append(testCases, testCase{
4462 testType: clientTest,
4463 name: "UnknownExtension-Client",
4464 config: Config{
4465 Bugs: ProtocolBugs{
4466 CustomExtension: expectedContents,
4467 },
4468 },
4469 shouldFail: true,
4470 expectedError: ":UNEXPECTED_EXTENSION:",
4471 })
Adam Langley09505632015-07-30 18:10:13 -07004472}
4473
Adam Langley7c803a62015-06-15 15:35:05 -07004474func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004475 defer wg.Done()
4476
4477 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004478 var err error
4479
4480 if *mallocTest < 0 {
4481 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004482 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004483 } else {
4484 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4485 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004486 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004487 if err != nil {
4488 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4489 }
4490 break
4491 }
4492 }
4493 }
Adam Langley95c29f32014-06-20 12:00:00 -07004494 statusChan <- statusMsg{test: test, err: err}
4495 }
4496}
4497
4498type statusMsg struct {
4499 test *testCase
4500 started bool
4501 err error
4502}
4503
David Benjamin5f237bc2015-02-11 17:14:15 -05004504func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004505 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004506
David Benjamin5f237bc2015-02-11 17:14:15 -05004507 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004508 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004509 if !*pipe {
4510 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004511 var erase string
4512 for i := 0; i < lineLen; i++ {
4513 erase += "\b \b"
4514 }
4515 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004516 }
4517
Adam Langley95c29f32014-06-20 12:00:00 -07004518 if msg.started {
4519 started++
4520 } else {
4521 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004522
4523 if msg.err != nil {
4524 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4525 failed++
4526 testOutput.addResult(msg.test.name, "FAIL")
4527 } else {
4528 if *pipe {
4529 // Print each test instead of a status line.
4530 fmt.Printf("PASSED (%s)\n", msg.test.name)
4531 }
4532 testOutput.addResult(msg.test.name, "PASS")
4533 }
Adam Langley95c29f32014-06-20 12:00:00 -07004534 }
4535
David Benjamin5f237bc2015-02-11 17:14:15 -05004536 if !*pipe {
4537 // Print a new status line.
4538 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4539 lineLen = len(line)
4540 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004541 }
Adam Langley95c29f32014-06-20 12:00:00 -07004542 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004543
4544 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004545}
4546
4547func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004548 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004549 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004550
Adam Langley7c803a62015-06-15 15:35:05 -07004551 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004552 addCipherSuiteTests()
4553 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004554 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004555 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004556 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004557 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004558 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004559 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004560 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004561 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004562 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004563 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004564 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004565 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004566 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004567 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004568 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004569 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004570 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004571 for _, async := range []bool{false, true} {
4572 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004573 for _, protocol := range []protocol{tls, dtls} {
4574 addStateMachineCoverageTests(async, splitHandshake, protocol)
4575 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004576 }
4577 }
Adam Langley95c29f32014-06-20 12:00:00 -07004578
4579 var wg sync.WaitGroup
4580
Adam Langley7c803a62015-06-15 15:35:05 -07004581 statusChan := make(chan statusMsg, *numWorkers)
4582 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004583 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004584
David Benjamin025b3d32014-07-01 19:53:04 -04004585 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004586
Adam Langley7c803a62015-06-15 15:35:05 -07004587 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004588 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004589 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004590 }
4591
David Benjamin025b3d32014-07-01 19:53:04 -04004592 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004593 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004594 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004595 }
4596 }
4597
4598 close(testChan)
4599 wg.Wait()
4600 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004601 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004602
4603 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004604
4605 if *jsonOutput != "" {
4606 if err := testOutput.writeTo(*jsonOutput); err != nil {
4607 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4608 }
4609 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004610
4611 if !testOutput.allPassed {
4612 os.Exit(1)
4613 }
Adam Langley95c29f32014-06-20 12:00:00 -07004614}