blob: fb1e46fbb7271fc4ed2f773fda2f6058c1b0dcd0 [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,
2588 name: "ClientAuth-Client",
2589 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 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002597 if async {
2598 tests = append(tests, testCase{
2599 testType: clientTest,
2600 name: "ClientAuth-Client-AsyncKey",
2601 config: Config{
2602 ClientAuth: RequireAnyClientCert,
2603 },
2604 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002605 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2606 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002607 "-use-async-private-key",
2608 },
2609 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002610 tests = append(tests, testCase{
2611 testType: serverTest,
2612 name: "Basic-Server-RSAAsyncKey",
2613 flags: []string{
2614 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2615 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2616 "-use-async-private-key",
2617 },
2618 })
2619 tests = append(tests, testCase{
2620 testType: serverTest,
2621 name: "Basic-Server-ECDSAAsyncKey",
2622 flags: []string{
2623 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2624 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2625 "-use-async-private-key",
2626 },
2627 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002628 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002629 tests = append(tests, testCase{
2630 testType: serverTest,
2631 name: "ClientAuth-Server",
2632 config: Config{
2633 Certificates: []Certificate{rsaCertificate},
2634 },
2635 flags: []string{"-require-any-client-certificate"},
2636 })
2637
2638 // No session ticket support; server doesn't send NewSessionTicket.
2639 tests = append(tests, testCase{
2640 name: "SessionTicketsDisabled-Client",
2641 config: Config{
2642 SessionTicketsDisabled: true,
2643 },
2644 })
2645 tests = append(tests, testCase{
2646 testType: serverTest,
2647 name: "SessionTicketsDisabled-Server",
2648 config: Config{
2649 SessionTicketsDisabled: true,
2650 },
2651 })
2652
2653 // Skip ServerKeyExchange in PSK key exchange if there's no
2654 // identity hint.
2655 tests = append(tests, testCase{
2656 name: "EmptyPSKHint-Client",
2657 config: Config{
2658 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2659 PreSharedKey: []byte("secret"),
2660 },
2661 flags: []string{"-psk", "secret"},
2662 })
2663 tests = append(tests, testCase{
2664 testType: serverTest,
2665 name: "EmptyPSKHint-Server",
2666 config: Config{
2667 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2668 PreSharedKey: []byte("secret"),
2669 },
2670 flags: []string{"-psk", "secret"},
2671 })
2672
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002673 tests = append(tests, testCase{
2674 testType: clientTest,
2675 name: "OCSPStapling-Client",
2676 flags: []string{
2677 "-enable-ocsp-stapling",
2678 "-expect-ocsp-response",
2679 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002680 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002681 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002682 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002683 })
2684
2685 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002686 testType: serverTest,
2687 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002688 expectedOCSPResponse: testOCSPResponse,
2689 flags: []string{
2690 "-ocsp-response",
2691 base64.StdEncoding.EncodeToString(testOCSPResponse),
2692 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002693 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002694 })
2695
Paul Lietar8f1c2682015-08-18 12:21:54 +01002696 tests = append(tests, testCase{
2697 testType: clientTest,
2698 name: "CertificateVerificationSucceed",
2699 flags: []string{
2700 "-verify-peer",
2701 },
2702 })
2703
2704 tests = append(tests, testCase{
2705 testType: clientTest,
2706 name: "CertificateVerificationFail",
2707 flags: []string{
2708 "-verify-fail",
2709 "-verify-peer",
2710 },
2711 shouldFail: true,
2712 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2713 })
2714
2715 tests = append(tests, testCase{
2716 testType: clientTest,
2717 name: "CertificateVerificationSoftFail",
2718 flags: []string{
2719 "-verify-fail",
2720 "-expect-verify-result",
2721 },
2722 })
2723
David Benjamin760b1dd2015-05-15 23:33:48 -04002724 if protocol == tls {
2725 tests = append(tests, testCase{
2726 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002727 renegotiate: 1,
2728 flags: []string{
2729 "-renegotiate-freely",
2730 "-expect-total-renegotiations", "1",
2731 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002732 })
2733 // NPN on client and server; results in post-handshake message.
2734 tests = append(tests, testCase{
2735 name: "NPN-Client",
2736 config: Config{
2737 NextProtos: []string{"foo"},
2738 },
2739 flags: []string{"-select-next-proto", "foo"},
2740 expectedNextProto: "foo",
2741 expectedNextProtoType: npn,
2742 })
2743 tests = append(tests, testCase{
2744 testType: serverTest,
2745 name: "NPN-Server",
2746 config: Config{
2747 NextProtos: []string{"bar"},
2748 },
2749 flags: []string{
2750 "-advertise-npn", "\x03foo\x03bar\x03baz",
2751 "-expect-next-proto", "bar",
2752 },
2753 expectedNextProto: "bar",
2754 expectedNextProtoType: npn,
2755 })
2756
2757 // TODO(davidben): Add tests for when False Start doesn't trigger.
2758
2759 // Client does False Start and negotiates NPN.
2760 tests = append(tests, testCase{
2761 name: "FalseStart",
2762 config: Config{
2763 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2764 NextProtos: []string{"foo"},
2765 Bugs: ProtocolBugs{
2766 ExpectFalseStart: true,
2767 },
2768 },
2769 flags: []string{
2770 "-false-start",
2771 "-select-next-proto", "foo",
2772 },
2773 shimWritesFirst: true,
2774 resumeSession: true,
2775 })
2776
2777 // Client does False Start and negotiates ALPN.
2778 tests = append(tests, testCase{
2779 name: "FalseStart-ALPN",
2780 config: Config{
2781 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2782 NextProtos: []string{"foo"},
2783 Bugs: ProtocolBugs{
2784 ExpectFalseStart: true,
2785 },
2786 },
2787 flags: []string{
2788 "-false-start",
2789 "-advertise-alpn", "\x03foo",
2790 },
2791 shimWritesFirst: true,
2792 resumeSession: true,
2793 })
2794
2795 // Client does False Start but doesn't explicitly call
2796 // SSL_connect.
2797 tests = append(tests, testCase{
2798 name: "FalseStart-Implicit",
2799 config: Config{
2800 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2801 NextProtos: []string{"foo"},
2802 },
2803 flags: []string{
2804 "-implicit-handshake",
2805 "-false-start",
2806 "-advertise-alpn", "\x03foo",
2807 },
2808 })
2809
2810 // False Start without session tickets.
2811 tests = append(tests, testCase{
2812 name: "FalseStart-SessionTicketsDisabled",
2813 config: Config{
2814 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2815 NextProtos: []string{"foo"},
2816 SessionTicketsDisabled: true,
2817 Bugs: ProtocolBugs{
2818 ExpectFalseStart: true,
2819 },
2820 },
2821 flags: []string{
2822 "-false-start",
2823 "-select-next-proto", "foo",
2824 },
2825 shimWritesFirst: true,
2826 })
2827
2828 // Server parses a V2ClientHello.
2829 tests = append(tests, testCase{
2830 testType: serverTest,
2831 name: "SendV2ClientHello",
2832 config: Config{
2833 // Choose a cipher suite that does not involve
2834 // elliptic curves, so no extensions are
2835 // involved.
2836 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2837 Bugs: ProtocolBugs{
2838 SendV2ClientHello: true,
2839 },
2840 },
2841 })
2842
2843 // Client sends a Channel ID.
2844 tests = append(tests, testCase{
2845 name: "ChannelID-Client",
2846 config: Config{
2847 RequestChannelID: true,
2848 },
Adam Langley7c803a62015-06-15 15:35:05 -07002849 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002850 resumeSession: true,
2851 expectChannelID: true,
2852 })
2853
2854 // Server accepts a Channel ID.
2855 tests = append(tests, testCase{
2856 testType: serverTest,
2857 name: "ChannelID-Server",
2858 config: Config{
2859 ChannelID: channelIDKey,
2860 },
2861 flags: []string{
2862 "-expect-channel-id",
2863 base64.StdEncoding.EncodeToString(channelIDBytes),
2864 },
2865 resumeSession: true,
2866 expectChannelID: true,
2867 })
David Benjamin30789da2015-08-29 22:56:45 -04002868
2869 // Bidirectional shutdown with the runner initiating.
2870 tests = append(tests, testCase{
2871 name: "Shutdown-Runner",
2872 config: Config{
2873 Bugs: ProtocolBugs{
2874 ExpectCloseNotify: true,
2875 },
2876 },
2877 flags: []string{"-check-close-notify"},
2878 })
2879
2880 // Bidirectional shutdown with the shim initiating. The runner,
2881 // in the meantime, sends garbage before the close_notify which
2882 // the shim must ignore.
2883 tests = append(tests, testCase{
2884 name: "Shutdown-Shim",
2885 config: Config{
2886 Bugs: ProtocolBugs{
2887 ExpectCloseNotify: true,
2888 },
2889 },
2890 shimShutsDown: true,
2891 sendEmptyRecords: 1,
2892 sendWarningAlerts: 1,
2893 flags: []string{"-check-close-notify"},
2894 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002895 } else {
2896 tests = append(tests, testCase{
2897 name: "SkipHelloVerifyRequest",
2898 config: Config{
2899 Bugs: ProtocolBugs{
2900 SkipHelloVerifyRequest: true,
2901 },
2902 },
2903 })
2904 }
2905
David Benjamin43ec06f2014-08-05 02:28:57 -04002906 var suffix string
2907 var flags []string
2908 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002909 if protocol == dtls {
2910 suffix = "-DTLS"
2911 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002912 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002913 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002914 flags = append(flags, "-async")
2915 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002916 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002917 }
2918 if splitHandshake {
2919 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002920 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002921 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002922 for _, test := range tests {
2923 test.protocol = protocol
2924 test.name += suffix
2925 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2926 test.flags = append(test.flags, flags...)
2927 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002928 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002929}
2930
Adam Langley524e7172015-02-20 16:04:00 -08002931func addDDoSCallbackTests() {
2932 // DDoS callback.
2933
2934 for _, resume := range []bool{false, true} {
2935 suffix := "Resume"
2936 if resume {
2937 suffix = "No" + suffix
2938 }
2939
2940 testCases = append(testCases, testCase{
2941 testType: serverTest,
2942 name: "Server-DDoS-OK-" + suffix,
2943 flags: []string{"-install-ddos-callback"},
2944 resumeSession: resume,
2945 })
2946
2947 failFlag := "-fail-ddos-callback"
2948 if resume {
2949 failFlag = "-fail-second-ddos-callback"
2950 }
2951 testCases = append(testCases, testCase{
2952 testType: serverTest,
2953 name: "Server-DDoS-Reject-" + suffix,
2954 flags: []string{"-install-ddos-callback", failFlag},
2955 resumeSession: resume,
2956 shouldFail: true,
2957 expectedError: ":CONNECTION_REJECTED:",
2958 })
2959 }
2960}
2961
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002962func addVersionNegotiationTests() {
2963 for i, shimVers := range tlsVersions {
2964 // Assemble flags to disable all newer versions on the shim.
2965 var flags []string
2966 for _, vers := range tlsVersions[i+1:] {
2967 flags = append(flags, vers.flag)
2968 }
2969
2970 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002971 protocols := []protocol{tls}
2972 if runnerVers.hasDTLS && shimVers.hasDTLS {
2973 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002974 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002975 for _, protocol := range protocols {
2976 expectedVersion := shimVers.version
2977 if runnerVers.version < shimVers.version {
2978 expectedVersion = runnerVers.version
2979 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002980
David Benjamin8b8c0062014-11-23 02:47:52 -05002981 suffix := shimVers.name + "-" + runnerVers.name
2982 if protocol == dtls {
2983 suffix += "-DTLS"
2984 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002985
David Benjamin1eb367c2014-12-12 18:17:51 -05002986 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2987
David Benjamin1e29a6b2014-12-10 02:27:24 -05002988 clientVers := shimVers.version
2989 if clientVers > VersionTLS10 {
2990 clientVers = VersionTLS10
2991 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002992 testCases = append(testCases, testCase{
2993 protocol: protocol,
2994 testType: clientTest,
2995 name: "VersionNegotiation-Client-" + suffix,
2996 config: Config{
2997 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002998 Bugs: ProtocolBugs{
2999 ExpectInitialRecordVersion: clientVers,
3000 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003001 },
3002 flags: flags,
3003 expectedVersion: expectedVersion,
3004 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003005 testCases = append(testCases, testCase{
3006 protocol: protocol,
3007 testType: clientTest,
3008 name: "VersionNegotiation-Client2-" + suffix,
3009 config: Config{
3010 MaxVersion: runnerVers.version,
3011 Bugs: ProtocolBugs{
3012 ExpectInitialRecordVersion: clientVers,
3013 },
3014 },
3015 flags: []string{"-max-version", shimVersFlag},
3016 expectedVersion: expectedVersion,
3017 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003018
3019 testCases = append(testCases, testCase{
3020 protocol: protocol,
3021 testType: serverTest,
3022 name: "VersionNegotiation-Server-" + suffix,
3023 config: Config{
3024 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003025 Bugs: ProtocolBugs{
3026 ExpectInitialRecordVersion: expectedVersion,
3027 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003028 },
3029 flags: flags,
3030 expectedVersion: expectedVersion,
3031 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003032 testCases = append(testCases, testCase{
3033 protocol: protocol,
3034 testType: serverTest,
3035 name: "VersionNegotiation-Server2-" + suffix,
3036 config: Config{
3037 MaxVersion: runnerVers.version,
3038 Bugs: ProtocolBugs{
3039 ExpectInitialRecordVersion: expectedVersion,
3040 },
3041 },
3042 flags: []string{"-max-version", shimVersFlag},
3043 expectedVersion: expectedVersion,
3044 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003045 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003046 }
3047 }
3048}
3049
David Benjaminaccb4542014-12-12 23:44:33 -05003050func addMinimumVersionTests() {
3051 for i, shimVers := range tlsVersions {
3052 // Assemble flags to disable all older versions on the shim.
3053 var flags []string
3054 for _, vers := range tlsVersions[:i] {
3055 flags = append(flags, vers.flag)
3056 }
3057
3058 for _, runnerVers := range tlsVersions {
3059 protocols := []protocol{tls}
3060 if runnerVers.hasDTLS && shimVers.hasDTLS {
3061 protocols = append(protocols, dtls)
3062 }
3063 for _, protocol := range protocols {
3064 suffix := shimVers.name + "-" + runnerVers.name
3065 if protocol == dtls {
3066 suffix += "-DTLS"
3067 }
3068 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3069
David Benjaminaccb4542014-12-12 23:44:33 -05003070 var expectedVersion uint16
3071 var shouldFail bool
3072 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003073 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003074 if runnerVers.version >= shimVers.version {
3075 expectedVersion = runnerVers.version
3076 } else {
3077 shouldFail = true
3078 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003079 if runnerVers.version > VersionSSL30 {
3080 expectedLocalError = "remote error: protocol version not supported"
3081 } else {
3082 expectedLocalError = "remote error: handshake failure"
3083 }
David Benjaminaccb4542014-12-12 23:44:33 -05003084 }
3085
3086 testCases = append(testCases, testCase{
3087 protocol: protocol,
3088 testType: clientTest,
3089 name: "MinimumVersion-Client-" + suffix,
3090 config: Config{
3091 MaxVersion: runnerVers.version,
3092 },
David Benjamin87909c02014-12-13 01:55:01 -05003093 flags: flags,
3094 expectedVersion: expectedVersion,
3095 shouldFail: shouldFail,
3096 expectedError: expectedError,
3097 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003098 })
3099 testCases = append(testCases, testCase{
3100 protocol: protocol,
3101 testType: clientTest,
3102 name: "MinimumVersion-Client2-" + suffix,
3103 config: Config{
3104 MaxVersion: runnerVers.version,
3105 },
David Benjamin87909c02014-12-13 01:55:01 -05003106 flags: []string{"-min-version", shimVersFlag},
3107 expectedVersion: expectedVersion,
3108 shouldFail: shouldFail,
3109 expectedError: expectedError,
3110 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003111 })
3112
3113 testCases = append(testCases, testCase{
3114 protocol: protocol,
3115 testType: serverTest,
3116 name: "MinimumVersion-Server-" + suffix,
3117 config: Config{
3118 MaxVersion: runnerVers.version,
3119 },
David Benjamin87909c02014-12-13 01:55:01 -05003120 flags: flags,
3121 expectedVersion: expectedVersion,
3122 shouldFail: shouldFail,
3123 expectedError: expectedError,
3124 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003125 })
3126 testCases = append(testCases, testCase{
3127 protocol: protocol,
3128 testType: serverTest,
3129 name: "MinimumVersion-Server2-" + suffix,
3130 config: Config{
3131 MaxVersion: runnerVers.version,
3132 },
David Benjamin87909c02014-12-13 01:55:01 -05003133 flags: []string{"-min-version", shimVersFlag},
3134 expectedVersion: expectedVersion,
3135 shouldFail: shouldFail,
3136 expectedError: expectedError,
3137 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003138 })
3139 }
3140 }
3141 }
3142}
3143
David Benjamin5c24a1d2014-08-31 00:59:27 -04003144func addD5BugTests() {
3145 testCases = append(testCases, testCase{
3146 testType: serverTest,
3147 name: "D5Bug-NoQuirk-Reject",
3148 config: Config{
3149 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3150 Bugs: ProtocolBugs{
3151 SSL3RSAKeyExchange: true,
3152 },
3153 },
3154 shouldFail: true,
3155 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3156 })
3157 testCases = append(testCases, testCase{
3158 testType: serverTest,
3159 name: "D5Bug-Quirk-Normal",
3160 config: Config{
3161 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3162 },
3163 flags: []string{"-tls-d5-bug"},
3164 })
3165 testCases = append(testCases, testCase{
3166 testType: serverTest,
3167 name: "D5Bug-Quirk-Bug",
3168 config: Config{
3169 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3170 Bugs: ProtocolBugs{
3171 SSL3RSAKeyExchange: true,
3172 },
3173 },
3174 flags: []string{"-tls-d5-bug"},
3175 })
3176}
3177
David Benjamine78bfde2014-09-06 12:45:15 -04003178func addExtensionTests() {
3179 testCases = append(testCases, testCase{
3180 testType: clientTest,
3181 name: "DuplicateExtensionClient",
3182 config: Config{
3183 Bugs: ProtocolBugs{
3184 DuplicateExtension: true,
3185 },
3186 },
3187 shouldFail: true,
3188 expectedLocalError: "remote error: error decoding message",
3189 })
3190 testCases = append(testCases, testCase{
3191 testType: serverTest,
3192 name: "DuplicateExtensionServer",
3193 config: Config{
3194 Bugs: ProtocolBugs{
3195 DuplicateExtension: true,
3196 },
3197 },
3198 shouldFail: true,
3199 expectedLocalError: "remote error: error decoding message",
3200 })
3201 testCases = append(testCases, testCase{
3202 testType: clientTest,
3203 name: "ServerNameExtensionClient",
3204 config: Config{
3205 Bugs: ProtocolBugs{
3206 ExpectServerName: "example.com",
3207 },
3208 },
3209 flags: []string{"-host-name", "example.com"},
3210 })
3211 testCases = append(testCases, testCase{
3212 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003213 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003214 config: Config{
3215 Bugs: ProtocolBugs{
3216 ExpectServerName: "mismatch.com",
3217 },
3218 },
3219 flags: []string{"-host-name", "example.com"},
3220 shouldFail: true,
3221 expectedLocalError: "tls: unexpected server name",
3222 })
3223 testCases = append(testCases, testCase{
3224 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003225 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003226 config: Config{
3227 Bugs: ProtocolBugs{
3228 ExpectServerName: "missing.com",
3229 },
3230 },
3231 shouldFail: true,
3232 expectedLocalError: "tls: unexpected server name",
3233 })
3234 testCases = append(testCases, testCase{
3235 testType: serverTest,
3236 name: "ServerNameExtensionServer",
3237 config: Config{
3238 ServerName: "example.com",
3239 },
3240 flags: []string{"-expect-server-name", "example.com"},
3241 resumeSession: true,
3242 })
David Benjaminae2888f2014-09-06 12:58:58 -04003243 testCases = append(testCases, testCase{
3244 testType: clientTest,
3245 name: "ALPNClient",
3246 config: Config{
3247 NextProtos: []string{"foo"},
3248 },
3249 flags: []string{
3250 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3251 "-expect-alpn", "foo",
3252 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003253 expectedNextProto: "foo",
3254 expectedNextProtoType: alpn,
3255 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003256 })
3257 testCases = append(testCases, testCase{
3258 testType: serverTest,
3259 name: "ALPNServer",
3260 config: Config{
3261 NextProtos: []string{"foo", "bar", "baz"},
3262 },
3263 flags: []string{
3264 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3265 "-select-alpn", "foo",
3266 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003267 expectedNextProto: "foo",
3268 expectedNextProtoType: alpn,
3269 resumeSession: true,
3270 })
3271 // Test that the server prefers ALPN over NPN.
3272 testCases = append(testCases, testCase{
3273 testType: serverTest,
3274 name: "ALPNServer-Preferred",
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 "-advertise-npn", "\x03foo\x03bar\x03baz",
3282 },
3283 expectedNextProto: "foo",
3284 expectedNextProtoType: alpn,
3285 resumeSession: true,
3286 })
3287 testCases = append(testCases, testCase{
3288 testType: serverTest,
3289 name: "ALPNServer-Preferred-Swapped",
3290 config: Config{
3291 NextProtos: []string{"foo", "bar", "baz"},
3292 Bugs: ProtocolBugs{
3293 SwapNPNAndALPN: true,
3294 },
3295 },
3296 flags: []string{
3297 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3298 "-select-alpn", "foo",
3299 "-advertise-npn", "\x03foo\x03bar\x03baz",
3300 },
3301 expectedNextProto: "foo",
3302 expectedNextProtoType: alpn,
3303 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003304 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003305 var emptyString string
3306 testCases = append(testCases, testCase{
3307 testType: clientTest,
3308 name: "ALPNClient-EmptyProtocolName",
3309 config: Config{
3310 NextProtos: []string{""},
3311 Bugs: ProtocolBugs{
3312 // A server returning an empty ALPN protocol
3313 // should be rejected.
3314 ALPNProtocol: &emptyString,
3315 },
3316 },
3317 flags: []string{
3318 "-advertise-alpn", "\x03foo",
3319 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003320 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003321 expectedError: ":PARSE_TLSEXT:",
3322 })
3323 testCases = append(testCases, testCase{
3324 testType: serverTest,
3325 name: "ALPNServer-EmptyProtocolName",
3326 config: Config{
3327 // A ClientHello containing an empty ALPN protocol
3328 // should be rejected.
3329 NextProtos: []string{"foo", "", "baz"},
3330 },
3331 flags: []string{
3332 "-select-alpn", "foo",
3333 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003334 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003335 expectedError: ":PARSE_TLSEXT:",
3336 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003337 // Test that negotiating both NPN and ALPN is forbidden.
3338 testCases = append(testCases, testCase{
3339 name: "NegotiateALPNAndNPN",
3340 config: Config{
3341 NextProtos: []string{"foo", "bar", "baz"},
3342 Bugs: ProtocolBugs{
3343 NegotiateALPNAndNPN: true,
3344 },
3345 },
3346 flags: []string{
3347 "-advertise-alpn", "\x03foo",
3348 "-select-next-proto", "foo",
3349 },
3350 shouldFail: true,
3351 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3352 })
3353 testCases = append(testCases, testCase{
3354 name: "NegotiateALPNAndNPN-Swapped",
3355 config: Config{
3356 NextProtos: []string{"foo", "bar", "baz"},
3357 Bugs: ProtocolBugs{
3358 NegotiateALPNAndNPN: true,
3359 SwapNPNAndALPN: true,
3360 },
3361 },
3362 flags: []string{
3363 "-advertise-alpn", "\x03foo",
3364 "-select-next-proto", "foo",
3365 },
3366 shouldFail: true,
3367 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3368 })
David Benjamin091c4b92015-10-26 13:33:21 -04003369 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
3370 testCases = append(testCases, testCase{
3371 name: "DisableNPN",
3372 config: Config{
3373 NextProtos: []string{"foo"},
3374 },
3375 flags: []string{
3376 "-select-next-proto", "foo",
3377 "-disable-npn",
3378 },
3379 expectNoNextProto: true,
3380 })
Adam Langley38311732014-10-16 19:04:35 -07003381 // Resume with a corrupt ticket.
3382 testCases = append(testCases, testCase{
3383 testType: serverTest,
3384 name: "CorruptTicket",
3385 config: Config{
3386 Bugs: ProtocolBugs{
3387 CorruptTicket: true,
3388 },
3389 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003390 resumeSession: true,
3391 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003392 })
David Benjamind98452d2015-06-16 14:16:23 -04003393 // Test the ticket callback, with and without renewal.
3394 testCases = append(testCases, testCase{
3395 testType: serverTest,
3396 name: "TicketCallback",
3397 resumeSession: true,
3398 flags: []string{"-use-ticket-callback"},
3399 })
3400 testCases = append(testCases, testCase{
3401 testType: serverTest,
3402 name: "TicketCallback-Renew",
3403 config: Config{
3404 Bugs: ProtocolBugs{
3405 ExpectNewTicket: true,
3406 },
3407 },
3408 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3409 resumeSession: true,
3410 })
Adam Langley38311732014-10-16 19:04:35 -07003411 // Resume with an oversized session id.
3412 testCases = append(testCases, testCase{
3413 testType: serverTest,
3414 name: "OversizedSessionId",
3415 config: Config{
3416 Bugs: ProtocolBugs{
3417 OversizedSessionId: true,
3418 },
3419 },
3420 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003421 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003422 expectedError: ":DECODE_ERROR:",
3423 })
David Benjaminca6c8262014-11-15 19:06:08 -05003424 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3425 // are ignored.
3426 testCases = append(testCases, testCase{
3427 protocol: dtls,
3428 name: "SRTP-Client",
3429 config: Config{
3430 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3431 },
3432 flags: []string{
3433 "-srtp-profiles",
3434 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3435 },
3436 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3437 })
3438 testCases = append(testCases, testCase{
3439 protocol: dtls,
3440 testType: serverTest,
3441 name: "SRTP-Server",
3442 config: Config{
3443 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3444 },
3445 flags: []string{
3446 "-srtp-profiles",
3447 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3448 },
3449 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3450 })
3451 // Test that the MKI is ignored.
3452 testCases = append(testCases, testCase{
3453 protocol: dtls,
3454 testType: serverTest,
3455 name: "SRTP-Server-IgnoreMKI",
3456 config: Config{
3457 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3458 Bugs: ProtocolBugs{
3459 SRTPMasterKeyIdentifer: "bogus",
3460 },
3461 },
3462 flags: []string{
3463 "-srtp-profiles",
3464 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3465 },
3466 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3467 })
3468 // Test that SRTP isn't negotiated on the server if there were
3469 // no matching profiles.
3470 testCases = append(testCases, testCase{
3471 protocol: dtls,
3472 testType: serverTest,
3473 name: "SRTP-Server-NoMatch",
3474 config: Config{
3475 SRTPProtectionProfiles: []uint16{100, 101, 102},
3476 },
3477 flags: []string{
3478 "-srtp-profiles",
3479 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3480 },
3481 expectedSRTPProtectionProfile: 0,
3482 })
3483 // Test that the server returning an invalid SRTP profile is
3484 // flagged as an error by the client.
3485 testCases = append(testCases, testCase{
3486 protocol: dtls,
3487 name: "SRTP-Client-NoMatch",
3488 config: Config{
3489 Bugs: ProtocolBugs{
3490 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3491 },
3492 },
3493 flags: []string{
3494 "-srtp-profiles",
3495 "SRTP_AES128_CM_SHA1_80",
3496 },
3497 shouldFail: true,
3498 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3499 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003500 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003501 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003502 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003503 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003504 flags: []string{
3505 "-enable-signed-cert-timestamps",
3506 "-expect-signed-cert-timestamps",
3507 base64.StdEncoding.EncodeToString(testSCTList),
3508 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003509 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003510 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003511 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003512 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003513 testType: serverTest,
3514 flags: []string{
3515 "-signed-cert-timestamps",
3516 base64.StdEncoding.EncodeToString(testSCTList),
3517 },
3518 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003519 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003520 })
3521 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003522 testType: clientTest,
3523 name: "ClientHelloPadding",
3524 config: Config{
3525 Bugs: ProtocolBugs{
3526 RequireClientHelloSize: 512,
3527 },
3528 },
3529 // This hostname just needs to be long enough to push the
3530 // ClientHello into F5's danger zone between 256 and 511 bytes
3531 // long.
3532 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3533 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003534
3535 // Extensions should not function in SSL 3.0.
3536 testCases = append(testCases, testCase{
3537 testType: serverTest,
3538 name: "SSLv3Extensions-NoALPN",
3539 config: Config{
3540 MaxVersion: VersionSSL30,
3541 NextProtos: []string{"foo", "bar", "baz"},
3542 },
3543 flags: []string{
3544 "-select-alpn", "foo",
3545 },
3546 expectNoNextProto: true,
3547 })
3548
3549 // Test session tickets separately as they follow a different codepath.
3550 testCases = append(testCases, testCase{
3551 testType: serverTest,
3552 name: "SSLv3Extensions-NoTickets",
3553 config: Config{
3554 MaxVersion: VersionSSL30,
3555 Bugs: ProtocolBugs{
3556 // Historically, session tickets in SSL 3.0
3557 // failed in different ways depending on whether
3558 // the client supported renegotiation_info.
3559 NoRenegotiationInfo: true,
3560 },
3561 },
3562 resumeSession: true,
3563 })
3564 testCases = append(testCases, testCase{
3565 testType: serverTest,
3566 name: "SSLv3Extensions-NoTickets2",
3567 config: Config{
3568 MaxVersion: VersionSSL30,
3569 },
3570 resumeSession: true,
3571 })
3572
3573 // But SSL 3.0 does send and process renegotiation_info.
3574 testCases = append(testCases, testCase{
3575 testType: serverTest,
3576 name: "SSLv3Extensions-RenegotiationInfo",
3577 config: Config{
3578 MaxVersion: VersionSSL30,
3579 Bugs: ProtocolBugs{
3580 RequireRenegotiationInfo: true,
3581 },
3582 },
3583 })
3584 testCases = append(testCases, testCase{
3585 testType: serverTest,
3586 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3587 config: Config{
3588 MaxVersion: VersionSSL30,
3589 Bugs: ProtocolBugs{
3590 NoRenegotiationInfo: true,
3591 SendRenegotiationSCSV: true,
3592 RequireRenegotiationInfo: true,
3593 },
3594 },
3595 })
David Benjamine78bfde2014-09-06 12:45:15 -04003596}
3597
David Benjamin01fe8202014-09-24 15:21:44 -04003598func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003599 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003600 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003601 protocols := []protocol{tls}
3602 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3603 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003604 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003605 for _, protocol := range protocols {
3606 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3607 if protocol == dtls {
3608 suffix += "-DTLS"
3609 }
3610
David Benjaminece3de92015-03-16 18:02:20 -04003611 if sessionVers.version == resumeVers.version {
3612 testCases = append(testCases, testCase{
3613 protocol: protocol,
3614 name: "Resume-Client" + suffix,
3615 resumeSession: true,
3616 config: Config{
3617 MaxVersion: sessionVers.version,
3618 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003619 },
David Benjaminece3de92015-03-16 18:02:20 -04003620 expectedVersion: sessionVers.version,
3621 expectedResumeVersion: resumeVers.version,
3622 })
3623 } else {
3624 testCases = append(testCases, testCase{
3625 protocol: protocol,
3626 name: "Resume-Client-Mismatch" + suffix,
3627 resumeSession: true,
3628 config: Config{
3629 MaxVersion: sessionVers.version,
3630 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003631 },
David Benjaminece3de92015-03-16 18:02:20 -04003632 expectedVersion: sessionVers.version,
3633 resumeConfig: &Config{
3634 MaxVersion: resumeVers.version,
3635 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3636 Bugs: ProtocolBugs{
3637 AllowSessionVersionMismatch: true,
3638 },
3639 },
3640 expectedResumeVersion: resumeVers.version,
3641 shouldFail: true,
3642 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3643 })
3644 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003645
3646 testCases = append(testCases, testCase{
3647 protocol: protocol,
3648 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003649 resumeSession: true,
3650 config: Config{
3651 MaxVersion: sessionVers.version,
3652 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3653 },
3654 expectedVersion: sessionVers.version,
3655 resumeConfig: &Config{
3656 MaxVersion: resumeVers.version,
3657 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3658 },
3659 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003660 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003661 expectedResumeVersion: resumeVers.version,
3662 })
3663
David Benjamin8b8c0062014-11-23 02:47:52 -05003664 testCases = append(testCases, testCase{
3665 protocol: protocol,
3666 testType: serverTest,
3667 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003668 resumeSession: true,
3669 config: Config{
3670 MaxVersion: sessionVers.version,
3671 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3672 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003673 expectedVersion: sessionVers.version,
3674 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003675 resumeConfig: &Config{
3676 MaxVersion: resumeVers.version,
3677 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3678 },
3679 expectedResumeVersion: resumeVers.version,
3680 })
3681 }
David Benjamin01fe8202014-09-24 15:21:44 -04003682 }
3683 }
David Benjaminece3de92015-03-16 18:02:20 -04003684
3685 testCases = append(testCases, testCase{
3686 name: "Resume-Client-CipherMismatch",
3687 resumeSession: true,
3688 config: Config{
3689 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3690 },
3691 resumeConfig: &Config{
3692 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3693 Bugs: ProtocolBugs{
3694 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3695 },
3696 },
3697 shouldFail: true,
3698 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3699 })
David Benjamin01fe8202014-09-24 15:21:44 -04003700}
3701
Adam Langley2ae77d22014-10-28 17:29:33 -07003702func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003703 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003704 testCases = append(testCases, testCase{
3705 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003706 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003707 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003708 shouldFail: true,
3709 expectedError: ":NO_RENEGOTIATION:",
3710 expectedLocalError: "remote error: no renegotiation",
3711 })
Adam Langley5021b222015-06-12 18:27:58 -07003712 // The server shouldn't echo the renegotiation extension unless
3713 // requested by the client.
3714 testCases = append(testCases, testCase{
3715 testType: serverTest,
3716 name: "Renegotiate-Server-NoExt",
3717 config: Config{
3718 Bugs: ProtocolBugs{
3719 NoRenegotiationInfo: true,
3720 RequireRenegotiationInfo: true,
3721 },
3722 },
3723 shouldFail: true,
3724 expectedLocalError: "renegotiation extension missing",
3725 })
3726 // The renegotiation SCSV should be sufficient for the server to echo
3727 // the extension.
3728 testCases = append(testCases, testCase{
3729 testType: serverTest,
3730 name: "Renegotiate-Server-NoExt-SCSV",
3731 config: Config{
3732 Bugs: ProtocolBugs{
3733 NoRenegotiationInfo: true,
3734 SendRenegotiationSCSV: true,
3735 RequireRenegotiationInfo: true,
3736 },
3737 },
3738 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003739 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003740 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003741 config: Config{
3742 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003743 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003744 },
3745 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003746 renegotiate: 1,
3747 flags: []string{
3748 "-renegotiate-freely",
3749 "-expect-total-renegotiations", "1",
3750 },
David Benjamincdea40c2015-03-19 14:09:43 -04003751 })
3752 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003753 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003754 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003755 config: Config{
3756 Bugs: ProtocolBugs{
3757 EmptyRenegotiationInfo: true,
3758 },
3759 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003760 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003761 shouldFail: true,
3762 expectedError: ":RENEGOTIATION_MISMATCH:",
3763 })
3764 testCases = append(testCases, testCase{
3765 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003766 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003767 config: Config{
3768 Bugs: ProtocolBugs{
3769 BadRenegotiationInfo: true,
3770 },
3771 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003772 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003773 shouldFail: true,
3774 expectedError: ":RENEGOTIATION_MISMATCH:",
3775 })
3776 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003777 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003778 config: Config{
3779 Bugs: ProtocolBugs{
3780 NoRenegotiationInfo: true,
3781 },
3782 },
3783 shouldFail: true,
3784 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3785 flags: []string{"-no-legacy-server-connect"},
3786 })
3787 testCases = append(testCases, testCase{
3788 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003789 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003790 config: Config{
3791 Bugs: ProtocolBugs{
3792 NoRenegotiationInfo: true,
3793 },
3794 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003795 flags: []string{
3796 "-renegotiate-freely",
3797 "-expect-total-renegotiations", "1",
3798 },
David Benjamincff0b902015-05-15 23:09:47 -04003799 })
3800 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003801 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003802 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003803 config: Config{
3804 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3805 },
3806 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003807 flags: []string{
3808 "-renegotiate-freely",
3809 "-expect-total-renegotiations", "1",
3810 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003811 })
3812 testCases = append(testCases, testCase{
3813 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003814 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003815 config: Config{
3816 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3817 },
3818 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003819 flags: []string{
3820 "-renegotiate-freely",
3821 "-expect-total-renegotiations", "1",
3822 },
David Benjaminb16346b2015-04-08 19:16:58 -04003823 })
3824 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003825 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003826 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003827 config: Config{
3828 MaxVersion: VersionTLS10,
3829 Bugs: ProtocolBugs{
3830 RequireSameRenegoClientVersion: true,
3831 },
3832 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003833 flags: []string{
3834 "-renegotiate-freely",
3835 "-expect-total-renegotiations", "1",
3836 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003837 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003838 testCases = append(testCases, testCase{
3839 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003840 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003841 config: Config{
3842 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3843 NextProtos: []string{"foo"},
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003848 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003849 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003850 },
3851 shimWritesFirst: true,
3852 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003853
3854 // Client-side renegotiation controls.
3855 testCases = append(testCases, testCase{
3856 name: "Renegotiate-Client-Forbidden-1",
3857 renegotiate: 1,
3858 shouldFail: true,
3859 expectedError: ":NO_RENEGOTIATION:",
3860 expectedLocalError: "remote error: no renegotiation",
3861 })
3862 testCases = append(testCases, testCase{
3863 name: "Renegotiate-Client-Once-1",
3864 renegotiate: 1,
3865 flags: []string{
3866 "-renegotiate-once",
3867 "-expect-total-renegotiations", "1",
3868 },
3869 })
3870 testCases = append(testCases, testCase{
3871 name: "Renegotiate-Client-Freely-1",
3872 renegotiate: 1,
3873 flags: []string{
3874 "-renegotiate-freely",
3875 "-expect-total-renegotiations", "1",
3876 },
3877 })
3878 testCases = append(testCases, testCase{
3879 name: "Renegotiate-Client-Once-2",
3880 renegotiate: 2,
3881 flags: []string{"-renegotiate-once"},
3882 shouldFail: true,
3883 expectedError: ":NO_RENEGOTIATION:",
3884 expectedLocalError: "remote error: no renegotiation",
3885 })
3886 testCases = append(testCases, testCase{
3887 name: "Renegotiate-Client-Freely-2",
3888 renegotiate: 2,
3889 flags: []string{
3890 "-renegotiate-freely",
3891 "-expect-total-renegotiations", "2",
3892 },
3893 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003894}
3895
David Benjamin5e961c12014-11-07 01:48:35 -05003896func addDTLSReplayTests() {
3897 // Test that sequence number replays are detected.
3898 testCases = append(testCases, testCase{
3899 protocol: dtls,
3900 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003901 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003902 replayWrites: true,
3903 })
3904
David Benjamin8e6db492015-07-25 18:29:23 -04003905 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003906 // than the retransmit window.
3907 testCases = append(testCases, testCase{
3908 protocol: dtls,
3909 name: "DTLS-Replay-LargeGaps",
3910 config: Config{
3911 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003912 SequenceNumberMapping: func(in uint64) uint64 {
3913 return in * 127
3914 },
David Benjamin5e961c12014-11-07 01:48:35 -05003915 },
3916 },
David Benjamin8e6db492015-07-25 18:29:23 -04003917 messageCount: 200,
3918 replayWrites: true,
3919 })
3920
3921 // Test the incoming sequence number changing non-monotonically.
3922 testCases = append(testCases, testCase{
3923 protocol: dtls,
3924 name: "DTLS-Replay-NonMonotonic",
3925 config: Config{
3926 Bugs: ProtocolBugs{
3927 SequenceNumberMapping: func(in uint64) uint64 {
3928 return in ^ 31
3929 },
3930 },
3931 },
3932 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003933 replayWrites: true,
3934 })
3935}
3936
David Benjamin000800a2014-11-14 01:43:59 -05003937var testHashes = []struct {
3938 name string
3939 id uint8
3940}{
3941 {"SHA1", hashSHA1},
3942 {"SHA224", hashSHA224},
3943 {"SHA256", hashSHA256},
3944 {"SHA384", hashSHA384},
3945 {"SHA512", hashSHA512},
3946}
3947
3948func addSigningHashTests() {
3949 // Make sure each hash works. Include some fake hashes in the list and
3950 // ensure they're ignored.
3951 for _, hash := range testHashes {
3952 testCases = append(testCases, testCase{
3953 name: "SigningHash-ClientAuth-" + hash.name,
3954 config: Config{
3955 ClientAuth: RequireAnyClientCert,
3956 SignatureAndHashes: []signatureAndHash{
3957 {signatureRSA, 42},
3958 {signatureRSA, hash.id},
3959 {signatureRSA, 255},
3960 },
3961 },
3962 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003963 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3964 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003965 },
3966 })
3967
3968 testCases = append(testCases, testCase{
3969 testType: serverTest,
3970 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3971 config: Config{
3972 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3973 SignatureAndHashes: []signatureAndHash{
3974 {signatureRSA, 42},
3975 {signatureRSA, hash.id},
3976 {signatureRSA, 255},
3977 },
3978 },
3979 })
3980 }
3981
3982 // Test that hash resolution takes the signature type into account.
3983 testCases = append(testCases, testCase{
3984 name: "SigningHash-ClientAuth-SignatureType",
3985 config: Config{
3986 ClientAuth: RequireAnyClientCert,
3987 SignatureAndHashes: []signatureAndHash{
3988 {signatureECDSA, hashSHA512},
3989 {signatureRSA, hashSHA384},
3990 {signatureECDSA, hashSHA1},
3991 },
3992 },
3993 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003996 },
3997 })
3998
3999 testCases = append(testCases, testCase{
4000 testType: serverTest,
4001 name: "SigningHash-ServerKeyExchange-SignatureType",
4002 config: Config{
4003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4004 SignatureAndHashes: []signatureAndHash{
4005 {signatureECDSA, hashSHA512},
4006 {signatureRSA, hashSHA384},
4007 {signatureECDSA, hashSHA1},
4008 },
4009 },
4010 })
4011
4012 // Test that, if the list is missing, the peer falls back to SHA-1.
4013 testCases = append(testCases, testCase{
4014 name: "SigningHash-ClientAuth-Fallback",
4015 config: Config{
4016 ClientAuth: RequireAnyClientCert,
4017 SignatureAndHashes: []signatureAndHash{
4018 {signatureRSA, hashSHA1},
4019 },
4020 Bugs: ProtocolBugs{
4021 NoSignatureAndHashes: true,
4022 },
4023 },
4024 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004025 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4026 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004027 },
4028 })
4029
4030 testCases = append(testCases, testCase{
4031 testType: serverTest,
4032 name: "SigningHash-ServerKeyExchange-Fallback",
4033 config: Config{
4034 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4035 SignatureAndHashes: []signatureAndHash{
4036 {signatureRSA, hashSHA1},
4037 },
4038 Bugs: ProtocolBugs{
4039 NoSignatureAndHashes: true,
4040 },
4041 },
4042 })
David Benjamin72dc7832015-03-16 17:49:43 -04004043
4044 // Test that hash preferences are enforced. BoringSSL defaults to
4045 // rejecting MD5 signatures.
4046 testCases = append(testCases, testCase{
4047 testType: serverTest,
4048 name: "SigningHash-ClientAuth-Enforced",
4049 config: Config{
4050 Certificates: []Certificate{rsaCertificate},
4051 SignatureAndHashes: []signatureAndHash{
4052 {signatureRSA, hashMD5},
4053 // Advertise SHA-1 so the handshake will
4054 // proceed, but the shim's preferences will be
4055 // ignored in CertificateVerify generation, so
4056 // MD5 will be chosen.
4057 {signatureRSA, hashSHA1},
4058 },
4059 Bugs: ProtocolBugs{
4060 IgnorePeerSignatureAlgorithmPreferences: true,
4061 },
4062 },
4063 flags: []string{"-require-any-client-certificate"},
4064 shouldFail: true,
4065 expectedError: ":WRONG_SIGNATURE_TYPE:",
4066 })
4067
4068 testCases = append(testCases, testCase{
4069 name: "SigningHash-ServerKeyExchange-Enforced",
4070 config: Config{
4071 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4072 SignatureAndHashes: []signatureAndHash{
4073 {signatureRSA, hashMD5},
4074 },
4075 Bugs: ProtocolBugs{
4076 IgnorePeerSignatureAlgorithmPreferences: true,
4077 },
4078 },
4079 shouldFail: true,
4080 expectedError: ":WRONG_SIGNATURE_TYPE:",
4081 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004082
4083 // Test that the agreed upon digest respects the client preferences and
4084 // the server digests.
4085 testCases = append(testCases, testCase{
4086 name: "Agree-Digest-Fallback",
4087 config: Config{
4088 ClientAuth: RequireAnyClientCert,
4089 SignatureAndHashes: []signatureAndHash{
4090 {signatureRSA, hashSHA512},
4091 {signatureRSA, hashSHA1},
4092 },
4093 },
4094 flags: []string{
4095 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4096 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4097 },
4098 digestPrefs: "SHA256",
4099 expectedClientCertSignatureHash: hashSHA1,
4100 })
4101 testCases = append(testCases, testCase{
4102 name: "Agree-Digest-SHA256",
4103 config: Config{
4104 ClientAuth: RequireAnyClientCert,
4105 SignatureAndHashes: []signatureAndHash{
4106 {signatureRSA, hashSHA1},
4107 {signatureRSA, hashSHA256},
4108 },
4109 },
4110 flags: []string{
4111 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4112 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4113 },
4114 digestPrefs: "SHA256,SHA1",
4115 expectedClientCertSignatureHash: hashSHA256,
4116 })
4117 testCases = append(testCases, testCase{
4118 name: "Agree-Digest-SHA1",
4119 config: Config{
4120 ClientAuth: RequireAnyClientCert,
4121 SignatureAndHashes: []signatureAndHash{
4122 {signatureRSA, hashSHA1},
4123 },
4124 },
4125 flags: []string{
4126 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4127 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4128 },
4129 digestPrefs: "SHA512,SHA256,SHA1",
4130 expectedClientCertSignatureHash: hashSHA1,
4131 })
4132 testCases = append(testCases, testCase{
4133 name: "Agree-Digest-Default",
4134 config: Config{
4135 ClientAuth: RequireAnyClientCert,
4136 SignatureAndHashes: []signatureAndHash{
4137 {signatureRSA, hashSHA256},
4138 {signatureECDSA, hashSHA256},
4139 {signatureRSA, hashSHA1},
4140 {signatureECDSA, hashSHA1},
4141 },
4142 },
4143 flags: []string{
4144 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4145 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4146 },
4147 expectedClientCertSignatureHash: hashSHA256,
4148 })
David Benjamin000800a2014-11-14 01:43:59 -05004149}
4150
David Benjamin83f90402015-01-27 01:09:43 -05004151// timeouts is the retransmit schedule for BoringSSL. It doubles and
4152// caps at 60 seconds. On the 13th timeout, it gives up.
4153var timeouts = []time.Duration{
4154 1 * time.Second,
4155 2 * time.Second,
4156 4 * time.Second,
4157 8 * time.Second,
4158 16 * time.Second,
4159 32 * time.Second,
4160 60 * time.Second,
4161 60 * time.Second,
4162 60 * time.Second,
4163 60 * time.Second,
4164 60 * time.Second,
4165 60 * time.Second,
4166 60 * time.Second,
4167}
4168
4169func addDTLSRetransmitTests() {
4170 // Test that this is indeed the timeout schedule. Stress all
4171 // four patterns of handshake.
4172 for i := 1; i < len(timeouts); i++ {
4173 number := strconv.Itoa(i)
4174 testCases = append(testCases, testCase{
4175 protocol: dtls,
4176 name: "DTLS-Retransmit-Client-" + number,
4177 config: Config{
4178 Bugs: ProtocolBugs{
4179 TimeoutSchedule: timeouts[:i],
4180 },
4181 },
4182 resumeSession: true,
4183 flags: []string{"-async"},
4184 })
4185 testCases = append(testCases, testCase{
4186 protocol: dtls,
4187 testType: serverTest,
4188 name: "DTLS-Retransmit-Server-" + number,
4189 config: Config{
4190 Bugs: ProtocolBugs{
4191 TimeoutSchedule: timeouts[:i],
4192 },
4193 },
4194 resumeSession: true,
4195 flags: []string{"-async"},
4196 })
4197 }
4198
4199 // Test that exceeding the timeout schedule hits a read
4200 // timeout.
4201 testCases = append(testCases, testCase{
4202 protocol: dtls,
4203 name: "DTLS-Retransmit-Timeout",
4204 config: Config{
4205 Bugs: ProtocolBugs{
4206 TimeoutSchedule: timeouts,
4207 },
4208 },
4209 resumeSession: true,
4210 flags: []string{"-async"},
4211 shouldFail: true,
4212 expectedError: ":READ_TIMEOUT_EXPIRED:",
4213 })
4214
4215 // Test that timeout handling has a fudge factor, due to API
4216 // problems.
4217 testCases = append(testCases, testCase{
4218 protocol: dtls,
4219 name: "DTLS-Retransmit-Fudge",
4220 config: Config{
4221 Bugs: ProtocolBugs{
4222 TimeoutSchedule: []time.Duration{
4223 timeouts[0] - 10*time.Millisecond,
4224 },
4225 },
4226 },
4227 resumeSession: true,
4228 flags: []string{"-async"},
4229 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004230
4231 // Test that the final Finished retransmitting isn't
4232 // duplicated if the peer badly fragments everything.
4233 testCases = append(testCases, testCase{
4234 testType: serverTest,
4235 protocol: dtls,
4236 name: "DTLS-Retransmit-Fragmented",
4237 config: Config{
4238 Bugs: ProtocolBugs{
4239 TimeoutSchedule: []time.Duration{timeouts[0]},
4240 MaxHandshakeRecordLength: 2,
4241 },
4242 },
4243 flags: []string{"-async"},
4244 })
David Benjamin83f90402015-01-27 01:09:43 -05004245}
4246
David Benjaminc565ebb2015-04-03 04:06:36 -04004247func addExportKeyingMaterialTests() {
4248 for _, vers := range tlsVersions {
4249 if vers.version == VersionSSL30 {
4250 continue
4251 }
4252 testCases = append(testCases, testCase{
4253 name: "ExportKeyingMaterial-" + vers.name,
4254 config: Config{
4255 MaxVersion: vers.version,
4256 },
4257 exportKeyingMaterial: 1024,
4258 exportLabel: "label",
4259 exportContext: "context",
4260 useExportContext: true,
4261 })
4262 testCases = append(testCases, testCase{
4263 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4264 config: Config{
4265 MaxVersion: vers.version,
4266 },
4267 exportKeyingMaterial: 1024,
4268 })
4269 testCases = append(testCases, testCase{
4270 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4271 config: Config{
4272 MaxVersion: vers.version,
4273 },
4274 exportKeyingMaterial: 1024,
4275 useExportContext: true,
4276 })
4277 testCases = append(testCases, testCase{
4278 name: "ExportKeyingMaterial-Small-" + vers.name,
4279 config: Config{
4280 MaxVersion: vers.version,
4281 },
4282 exportKeyingMaterial: 1,
4283 exportLabel: "label",
4284 exportContext: "context",
4285 useExportContext: true,
4286 })
4287 }
4288 testCases = append(testCases, testCase{
4289 name: "ExportKeyingMaterial-SSL3",
4290 config: Config{
4291 MaxVersion: VersionSSL30,
4292 },
4293 exportKeyingMaterial: 1024,
4294 exportLabel: "label",
4295 exportContext: "context",
4296 useExportContext: true,
4297 shouldFail: true,
4298 expectedError: "failed to export keying material",
4299 })
4300}
4301
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004302func addTLSUniqueTests() {
4303 for _, isClient := range []bool{false, true} {
4304 for _, isResumption := range []bool{false, true} {
4305 for _, hasEMS := range []bool{false, true} {
4306 var suffix string
4307 if isResumption {
4308 suffix = "Resume-"
4309 } else {
4310 suffix = "Full-"
4311 }
4312
4313 if hasEMS {
4314 suffix += "EMS-"
4315 } else {
4316 suffix += "NoEMS-"
4317 }
4318
4319 if isClient {
4320 suffix += "Client"
4321 } else {
4322 suffix += "Server"
4323 }
4324
4325 test := testCase{
4326 name: "TLSUnique-" + suffix,
4327 testTLSUnique: true,
4328 config: Config{
4329 Bugs: ProtocolBugs{
4330 NoExtendedMasterSecret: !hasEMS,
4331 },
4332 },
4333 }
4334
4335 if isResumption {
4336 test.resumeSession = true
4337 test.resumeConfig = &Config{
4338 Bugs: ProtocolBugs{
4339 NoExtendedMasterSecret: !hasEMS,
4340 },
4341 }
4342 }
4343
4344 if isResumption && !hasEMS {
4345 test.shouldFail = true
4346 test.expectedError = "failed to get tls-unique"
4347 }
4348
4349 testCases = append(testCases, test)
4350 }
4351 }
4352 }
4353}
4354
Adam Langley09505632015-07-30 18:10:13 -07004355func addCustomExtensionTests() {
4356 expectedContents := "custom extension"
4357 emptyString := ""
4358
4359 for _, isClient := range []bool{false, true} {
4360 suffix := "Server"
4361 flag := "-enable-server-custom-extension"
4362 testType := serverTest
4363 if isClient {
4364 suffix = "Client"
4365 flag = "-enable-client-custom-extension"
4366 testType = clientTest
4367 }
4368
4369 testCases = append(testCases, testCase{
4370 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004371 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004372 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004373 Bugs: ProtocolBugs{
4374 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004375 ExpectedCustomExtension: &expectedContents,
4376 },
4377 },
4378 flags: []string{flag},
4379 })
4380
4381 // If the parse callback fails, the handshake should also fail.
4382 testCases = append(testCases, testCase{
4383 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004384 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004385 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004386 Bugs: ProtocolBugs{
4387 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004388 ExpectedCustomExtension: &expectedContents,
4389 },
4390 },
David Benjamin399e7c92015-07-30 23:01:27 -04004391 flags: []string{flag},
4392 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004393 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4394 })
4395
4396 // If the add 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-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004400 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004401 Bugs: ProtocolBugs{
4402 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004403 ExpectedCustomExtension: &expectedContents,
4404 },
4405 },
David Benjamin399e7c92015-07-30 23:01:27 -04004406 flags: []string{flag, "-custom-extension-fail-add"},
4407 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004408 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4409 })
4410
4411 // If the add callback returns zero, no extension should be
4412 // added.
4413 skipCustomExtension := expectedContents
4414 if isClient {
4415 // For the case where the client skips sending the
4416 // custom extension, the server must not “echo” it.
4417 skipCustomExtension = ""
4418 }
4419 testCases = append(testCases, testCase{
4420 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004421 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004422 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004423 Bugs: ProtocolBugs{
4424 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004425 ExpectedCustomExtension: &emptyString,
4426 },
4427 },
4428 flags: []string{flag, "-custom-extension-skip"},
4429 })
4430 }
4431
4432 // The custom extension add callback should not be called if the client
4433 // doesn't send the extension.
4434 testCases = append(testCases, testCase{
4435 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004436 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004437 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004438 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004439 ExpectedCustomExtension: &emptyString,
4440 },
4441 },
4442 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4443 })
Adam Langley2deb9842015-08-07 11:15:37 -07004444
4445 // Test an unknown extension from the server.
4446 testCases = append(testCases, testCase{
4447 testType: clientTest,
4448 name: "UnknownExtension-Client",
4449 config: Config{
4450 Bugs: ProtocolBugs{
4451 CustomExtension: expectedContents,
4452 },
4453 },
4454 shouldFail: true,
4455 expectedError: ":UNEXPECTED_EXTENSION:",
4456 })
Adam Langley09505632015-07-30 18:10:13 -07004457}
4458
Adam Langley7c803a62015-06-15 15:35:05 -07004459func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004460 defer wg.Done()
4461
4462 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004463 var err error
4464
4465 if *mallocTest < 0 {
4466 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004467 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004468 } else {
4469 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4470 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004471 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004472 if err != nil {
4473 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4474 }
4475 break
4476 }
4477 }
4478 }
Adam Langley95c29f32014-06-20 12:00:00 -07004479 statusChan <- statusMsg{test: test, err: err}
4480 }
4481}
4482
4483type statusMsg struct {
4484 test *testCase
4485 started bool
4486 err error
4487}
4488
David Benjamin5f237bc2015-02-11 17:14:15 -05004489func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004490 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004491
David Benjamin5f237bc2015-02-11 17:14:15 -05004492 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004493 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004494 if !*pipe {
4495 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004496 var erase string
4497 for i := 0; i < lineLen; i++ {
4498 erase += "\b \b"
4499 }
4500 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004501 }
4502
Adam Langley95c29f32014-06-20 12:00:00 -07004503 if msg.started {
4504 started++
4505 } else {
4506 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004507
4508 if msg.err != nil {
4509 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4510 failed++
4511 testOutput.addResult(msg.test.name, "FAIL")
4512 } else {
4513 if *pipe {
4514 // Print each test instead of a status line.
4515 fmt.Printf("PASSED (%s)\n", msg.test.name)
4516 }
4517 testOutput.addResult(msg.test.name, "PASS")
4518 }
Adam Langley95c29f32014-06-20 12:00:00 -07004519 }
4520
David Benjamin5f237bc2015-02-11 17:14:15 -05004521 if !*pipe {
4522 // Print a new status line.
4523 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4524 lineLen = len(line)
4525 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004526 }
Adam Langley95c29f32014-06-20 12:00:00 -07004527 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004528
4529 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004530}
4531
4532func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004533 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004534 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004535
Adam Langley7c803a62015-06-15 15:35:05 -07004536 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004537 addCipherSuiteTests()
4538 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004539 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004540 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004541 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004542 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004543 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004544 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004545 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004546 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004547 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004548 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004549 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004550 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004551 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004552 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004553 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004554 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004555 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004556 for _, async := range []bool{false, true} {
4557 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004558 for _, protocol := range []protocol{tls, dtls} {
4559 addStateMachineCoverageTests(async, splitHandshake, protocol)
4560 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004561 }
4562 }
Adam Langley95c29f32014-06-20 12:00:00 -07004563
4564 var wg sync.WaitGroup
4565
Adam Langley7c803a62015-06-15 15:35:05 -07004566 statusChan := make(chan statusMsg, *numWorkers)
4567 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004568 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004569
David Benjamin025b3d32014-07-01 19:53:04 -04004570 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004571
Adam Langley7c803a62015-06-15 15:35:05 -07004572 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004573 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004574 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004575 }
4576
David Benjamin025b3d32014-07-01 19:53:04 -04004577 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004578 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004579 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004580 }
4581 }
4582
4583 close(testChan)
4584 wg.Wait()
4585 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004586 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004587
4588 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004589
4590 if *jsonOutput != "" {
4591 if err := testOutput.writeTo(*jsonOutput); err != nil {
4592 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4593 }
4594 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004595
4596 if !testOutput.allPassed {
4597 os.Exit(1)
4598 }
Adam Langley95c29f32014-06-20 12:00:00 -07004599}