blob: 61c8c572543ac4b54392ece4ebf46436cce42cf1 [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
Adam Langleycf2d4f42014-10-28 19:06:14 -0700209 // renegotiate indicates the the connection should be renegotiated
210 // during the exchange.
211 renegotiate bool
212 // 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
Adam Langleycf2d4f42014-10-28 19:06:14 -0700406 if test.renegotiate {
407 if test.renegotiateCiphers != nil {
408 config.CipherSuites = test.renegotiateCiphers
409 }
410 if err := tlsConn.Renegotiate(); err != nil {
411 return err
412 }
413 } else if test.renegotiateCiphers != nil {
414 panic("renegotiateCiphers without renegotiate")
415 }
416
David Benjamin5fa3eba2015-01-22 16:35:40 -0500417 if test.damageFirstWrite {
418 connDamage.setDamage(true)
419 tlsConn.Write([]byte("DAMAGED WRITE"))
420 connDamage.setDamage(false)
421 }
422
David Benjamin8e6db492015-07-25 18:29:23 -0400423 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700424 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400425 if test.protocol == dtls {
426 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
427 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700428 // Read until EOF.
429 _, err := io.Copy(ioutil.Discard, tlsConn)
430 return err
431 }
David Benjamin4417d052015-04-05 04:17:25 -0400432 if messageLen == 0 {
433 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700434 }
Adam Langley95c29f32014-06-20 12:00:00 -0700435
David Benjamin8e6db492015-07-25 18:29:23 -0400436 messageCount := test.messageCount
437 if messageCount == 0 {
438 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400439 }
440
David Benjamin8e6db492015-07-25 18:29:23 -0400441 for j := 0; j < messageCount; j++ {
442 testMessage := make([]byte, messageLen)
443 for i := range testMessage {
444 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 }
David Benjamin8e6db492015-07-25 18:29:23 -0400446 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700447
David Benjamin8e6db492015-07-25 18:29:23 -0400448 for i := 0; i < test.sendEmptyRecords; i++ {
449 tlsConn.Write(nil)
450 }
451
452 for i := 0; i < test.sendWarningAlerts; i++ {
453 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
454 }
455
David Benjamin4f75aaf2015-09-01 16:53:10 -0400456 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400457 // The shim will not respond.
458 continue
459 }
460
David Benjamin8e6db492015-07-25 18:29:23 -0400461 buf := make([]byte, len(testMessage))
462 if test.protocol == dtls {
463 bufTmp := make([]byte, len(buf)+1)
464 n, err := tlsConn.Read(bufTmp)
465 if err != nil {
466 return err
467 }
468 if n != len(buf) {
469 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
470 }
471 copy(buf, bufTmp)
472 } else {
473 _, err := io.ReadFull(tlsConn, buf)
474 if err != nil {
475 return err
476 }
477 }
478
479 for i, v := range buf {
480 if v != testMessage[i]^0xff {
481 return fmt.Errorf("bad reply contents at byte %d", i)
482 }
Adam Langley95c29f32014-06-20 12:00:00 -0700483 }
484 }
485
486 return nil
487}
488
David Benjamin325b5c32014-07-01 19:40:31 -0400489func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
490 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700491 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400492 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700493 }
David Benjamin325b5c32014-07-01 19:40:31 -0400494 valgrindArgs = append(valgrindArgs, path)
495 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700496
David Benjamin325b5c32014-07-01 19:40:31 -0400497 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700498}
499
David Benjamin325b5c32014-07-01 19:40:31 -0400500func gdbOf(path string, args ...string) *exec.Cmd {
501 xtermArgs := []string{"-e", "gdb", "--args"}
502 xtermArgs = append(xtermArgs, path)
503 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700504
David Benjamin325b5c32014-07-01 19:40:31 -0400505 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700506}
507
Adam Langley69a01602014-11-17 17:26:55 -0800508type moreMallocsError struct{}
509
510func (moreMallocsError) Error() string {
511 return "child process did not exhaust all allocation calls"
512}
513
514var errMoreMallocs = moreMallocsError{}
515
David Benjamin87c8a642015-02-21 01:54:29 -0500516// accept accepts a connection from listener, unless waitChan signals a process
517// exit first.
518func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
519 type connOrError struct {
520 conn net.Conn
521 err error
522 }
523 connChan := make(chan connOrError, 1)
524 go func() {
525 conn, err := listener.Accept()
526 connChan <- connOrError{conn, err}
527 close(connChan)
528 }()
529 select {
530 case result := <-connChan:
531 return result.conn, result.err
532 case childErr := <-waitChan:
533 waitChan <- childErr
534 return nil, fmt.Errorf("child exited early: %s", childErr)
535 }
536}
537
Adam Langley7c803a62015-06-15 15:35:05 -0700538func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700539 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
540 panic("Error expected without shouldFail in " + test.name)
541 }
542
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700543 if test.expectResumeRejected && !test.resumeSession {
544 panic("expectResumeRejected without resumeSession in " + test.name)
545 }
546
Steven Valdez0d62f262015-09-04 12:41:04 -0400547 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
548 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
549 }
550
David Benjamin87c8a642015-02-21 01:54:29 -0500551 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
552 if err != nil {
553 panic(err)
554 }
555 defer func() {
556 if listener != nil {
557 listener.Close()
558 }
559 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700560
David Benjamin87c8a642015-02-21 01:54:29 -0500561 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400562 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400563 flags = append(flags, "-server")
564
David Benjamin025b3d32014-07-01 19:53:04 -0400565 flags = append(flags, "-key-file")
566 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700567 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400568 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700569 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400570 }
571
572 flags = append(flags, "-cert-file")
573 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700574 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400575 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700576 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400577 }
578 }
David Benjamin5a593af2014-08-11 19:51:50 -0400579
Steven Valdez0d62f262015-09-04 12:41:04 -0400580 if test.digestPrefs != "" {
581 flags = append(flags, "-digest-prefs")
582 flags = append(flags, test.digestPrefs)
583 }
584
David Benjamin6fd297b2014-08-11 18:43:38 -0400585 if test.protocol == dtls {
586 flags = append(flags, "-dtls")
587 }
588
David Benjamin5a593af2014-08-11 19:51:50 -0400589 if test.resumeSession {
590 flags = append(flags, "-resume")
591 }
592
David Benjamine58c4f52014-08-24 03:47:07 -0400593 if test.shimWritesFirst {
594 flags = append(flags, "-shim-writes-first")
595 }
596
David Benjamin30789da2015-08-29 22:56:45 -0400597 if test.shimShutsDown {
598 flags = append(flags, "-shim-shuts-down")
599 }
600
David Benjaminc565ebb2015-04-03 04:06:36 -0400601 if test.exportKeyingMaterial > 0 {
602 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
603 flags = append(flags, "-export-label", test.exportLabel)
604 flags = append(flags, "-export-context", test.exportContext)
605 if test.useExportContext {
606 flags = append(flags, "-use-export-context")
607 }
608 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700609 if test.expectResumeRejected {
610 flags = append(flags, "-expect-session-miss")
611 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400612
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700613 if test.testTLSUnique {
614 flags = append(flags, "-tls-unique")
615 }
616
David Benjamin025b3d32014-07-01 19:53:04 -0400617 flags = append(flags, test.flags...)
618
619 var shim *exec.Cmd
620 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700621 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700622 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700623 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400624 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700625 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400626 }
David Benjamin025b3d32014-07-01 19:53:04 -0400627 shim.Stdin = os.Stdin
628 var stdoutBuf, stderrBuf bytes.Buffer
629 shim.Stdout = &stdoutBuf
630 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800631 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500632 shim.Env = os.Environ()
633 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800634 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400635 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800636 }
637 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
638 }
David Benjamin025b3d32014-07-01 19:53:04 -0400639
640 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700641 panic(err)
642 }
David Benjamin87c8a642015-02-21 01:54:29 -0500643 waitChan := make(chan error, 1)
644 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700645
646 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400647 if !test.noSessionCache {
648 config.ClientSessionCache = NewLRUClientSessionCache(1)
649 config.ServerSessionCache = NewLRUServerSessionCache(1)
650 }
David Benjamin025b3d32014-07-01 19:53:04 -0400651 if test.testType == clientTest {
652 if len(config.Certificates) == 0 {
653 config.Certificates = []Certificate{getRSACertificate()}
654 }
David Benjamin87c8a642015-02-21 01:54:29 -0500655 } else {
656 // Supply a ServerName to ensure a constant session cache key,
657 // rather than falling back to net.Conn.RemoteAddr.
658 if len(config.ServerName) == 0 {
659 config.ServerName = "test"
660 }
David Benjamin025b3d32014-07-01 19:53:04 -0400661 }
Adam Langley95c29f32014-06-20 12:00:00 -0700662
David Benjamin87c8a642015-02-21 01:54:29 -0500663 conn, err := acceptOrWait(listener, waitChan)
664 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400665 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500666 conn.Close()
667 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500668
David Benjamin1d5c83e2014-07-22 19:20:02 -0400669 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400670 var resumeConfig Config
671 if test.resumeConfig != nil {
672 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500673 if len(resumeConfig.ServerName) == 0 {
674 resumeConfig.ServerName = config.ServerName
675 }
David Benjamin01fe8202014-09-24 15:21:44 -0400676 if len(resumeConfig.Certificates) == 0 {
677 resumeConfig.Certificates = []Certificate{getRSACertificate()}
678 }
David Benjaminba4594a2015-06-18 18:36:15 -0400679 if test.newSessionsOnResume {
680 if !test.noSessionCache {
681 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
682 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
683 }
684 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500685 resumeConfig.SessionTicketKey = config.SessionTicketKey
686 resumeConfig.ClientSessionCache = config.ClientSessionCache
687 resumeConfig.ServerSessionCache = config.ServerSessionCache
688 }
David Benjamin01fe8202014-09-24 15:21:44 -0400689 } else {
690 resumeConfig = config
691 }
David Benjamin87c8a642015-02-21 01:54:29 -0500692 var connResume net.Conn
693 connResume, err = acceptOrWait(listener, waitChan)
694 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400695 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500696 connResume.Close()
697 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400698 }
699
David Benjamin87c8a642015-02-21 01:54:29 -0500700 // Close the listener now. This is to avoid hangs should the shim try to
701 // open more connections than expected.
702 listener.Close()
703 listener = nil
704
705 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800706 if exitError, ok := childErr.(*exec.ExitError); ok {
707 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
708 return errMoreMallocs
709 }
710 }
Adam Langley95c29f32014-06-20 12:00:00 -0700711
712 stdout := string(stdoutBuf.Bytes())
713 stderr := string(stderrBuf.Bytes())
714 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400715 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700716 localError := "none"
717 if err != nil {
718 localError = err.Error()
719 }
720 if len(test.expectedLocalError) != 0 {
721 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
722 }
Adam Langley95c29f32014-06-20 12:00:00 -0700723
724 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700725 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700726 if childErr != nil {
727 childError = childErr.Error()
728 }
729
730 var msg string
731 switch {
732 case failed && !test.shouldFail:
733 msg = "unexpected failure"
734 case !failed && test.shouldFail:
735 msg = "unexpected success"
736 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700737 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700738 default:
739 panic("internal error")
740 }
741
David Benjaminc565ebb2015-04-03 04:06:36 -0400742 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 -0700743 }
744
David Benjaminc565ebb2015-04-03 04:06:36 -0400745 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700746 println(stderr)
747 }
748
749 return nil
750}
751
752var tlsVersions = []struct {
753 name string
754 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400755 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500756 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700757}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500758 {"SSL3", VersionSSL30, "-no-ssl3", false},
759 {"TLS1", VersionTLS10, "-no-tls1", true},
760 {"TLS11", VersionTLS11, "-no-tls11", false},
761 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700762}
763
764var testCipherSuites = []struct {
765 name string
766 id uint16
767}{
768 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400769 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700770 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400771 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400772 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700773 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400774 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400775 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
776 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400777 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400778 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
779 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400780 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700781 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
782 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400783 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
784 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700785 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400786 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400787 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700788 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700789 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700790 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400791 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400792 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700793 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400794 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400795 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700796 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400797 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
798 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700799 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
800 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400801 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700802 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400803 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700804 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700805}
806
David Benjamin8b8c0062014-11-23 02:47:52 -0500807func hasComponent(suiteName, component string) bool {
808 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
809}
810
David Benjaminf7768e42014-08-31 02:06:47 -0400811func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500812 return hasComponent(suiteName, "GCM") ||
813 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400814 hasComponent(suiteName, "SHA384") ||
815 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500816}
817
818func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700819 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400820}
821
Adam Langleya7997f12015-05-14 17:38:50 -0700822func bigFromHex(hex string) *big.Int {
823 ret, ok := new(big.Int).SetString(hex, 16)
824 if !ok {
825 panic("failed to parse hex number 0x" + hex)
826 }
827 return ret
828}
829
Adam Langley7c803a62015-06-15 15:35:05 -0700830func addBasicTests() {
831 basicTests := []testCase{
832 {
833 name: "BadRSASignature",
834 config: Config{
835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
836 Bugs: ProtocolBugs{
837 InvalidSKXSignature: true,
838 },
839 },
840 shouldFail: true,
841 expectedError: ":BAD_SIGNATURE:",
842 },
843 {
844 name: "BadECDSASignature",
845 config: Config{
846 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
847 Bugs: ProtocolBugs{
848 InvalidSKXSignature: true,
849 },
850 Certificates: []Certificate{getECDSACertificate()},
851 },
852 shouldFail: true,
853 expectedError: ":BAD_SIGNATURE:",
854 },
855 {
David Benjamin6de0e532015-07-28 22:43:19 -0400856 testType: serverTest,
857 name: "BadRSASignature-ClientAuth",
858 config: Config{
859 Bugs: ProtocolBugs{
860 InvalidCertVerifySignature: true,
861 },
862 Certificates: []Certificate{getRSACertificate()},
863 },
864 shouldFail: true,
865 expectedError: ":BAD_SIGNATURE:",
866 flags: []string{"-require-any-client-certificate"},
867 },
868 {
869 testType: serverTest,
870 name: "BadECDSASignature-ClientAuth",
871 config: Config{
872 Bugs: ProtocolBugs{
873 InvalidCertVerifySignature: true,
874 },
875 Certificates: []Certificate{getECDSACertificate()},
876 },
877 shouldFail: true,
878 expectedError: ":BAD_SIGNATURE:",
879 flags: []string{"-require-any-client-certificate"},
880 },
881 {
Adam Langley7c803a62015-06-15 15:35:05 -0700882 name: "BadECDSACurve",
883 config: Config{
884 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
885 Bugs: ProtocolBugs{
886 InvalidSKXCurve: true,
887 },
888 Certificates: []Certificate{getECDSACertificate()},
889 },
890 shouldFail: true,
891 expectedError: ":WRONG_CURVE:",
892 },
893 {
894 testType: serverTest,
895 name: "BadRSAVersion",
896 config: Config{
897 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
898 Bugs: ProtocolBugs{
899 RsaClientKeyExchangeVersion: VersionTLS11,
900 },
901 },
902 shouldFail: true,
903 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
904 },
905 {
906 name: "NoFallbackSCSV",
907 config: Config{
908 Bugs: ProtocolBugs{
909 FailIfNotFallbackSCSV: true,
910 },
911 },
912 shouldFail: true,
913 expectedLocalError: "no fallback SCSV found",
914 },
915 {
916 name: "SendFallbackSCSV",
917 config: Config{
918 Bugs: ProtocolBugs{
919 FailIfNotFallbackSCSV: true,
920 },
921 },
922 flags: []string{"-fallback-scsv"},
923 },
924 {
925 name: "ClientCertificateTypes",
926 config: Config{
927 ClientAuth: RequestClientCert,
928 ClientCertificateTypes: []byte{
929 CertTypeDSSSign,
930 CertTypeRSASign,
931 CertTypeECDSASign,
932 },
933 },
934 flags: []string{
935 "-expect-certificate-types",
936 base64.StdEncoding.EncodeToString([]byte{
937 CertTypeDSSSign,
938 CertTypeRSASign,
939 CertTypeECDSASign,
940 }),
941 },
942 },
943 {
944 name: "NoClientCertificate",
945 config: Config{
946 ClientAuth: RequireAnyClientCert,
947 },
948 shouldFail: true,
949 expectedLocalError: "client didn't provide a certificate",
950 },
951 {
952 name: "UnauthenticatedECDH",
953 config: Config{
954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
955 Bugs: ProtocolBugs{
956 UnauthenticatedECDH: true,
957 },
958 },
959 shouldFail: true,
960 expectedError: ":UNEXPECTED_MESSAGE:",
961 },
962 {
963 name: "SkipCertificateStatus",
964 config: Config{
965 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
966 Bugs: ProtocolBugs{
967 SkipCertificateStatus: true,
968 },
969 },
970 flags: []string{
971 "-enable-ocsp-stapling",
972 },
973 },
974 {
975 name: "SkipServerKeyExchange",
976 config: Config{
977 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
978 Bugs: ProtocolBugs{
979 SkipServerKeyExchange: true,
980 },
981 },
982 shouldFail: true,
983 expectedError: ":UNEXPECTED_MESSAGE:",
984 },
985 {
986 name: "SkipChangeCipherSpec-Client",
987 config: Config{
988 Bugs: ProtocolBugs{
989 SkipChangeCipherSpec: true,
990 },
991 },
992 shouldFail: true,
993 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
994 },
995 {
996 testType: serverTest,
997 name: "SkipChangeCipherSpec-Server",
998 config: Config{
999 Bugs: ProtocolBugs{
1000 SkipChangeCipherSpec: true,
1001 },
1002 },
1003 shouldFail: true,
1004 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1005 },
1006 {
1007 testType: serverTest,
1008 name: "SkipChangeCipherSpec-Server-NPN",
1009 config: Config{
1010 NextProtos: []string{"bar"},
1011 Bugs: ProtocolBugs{
1012 SkipChangeCipherSpec: true,
1013 },
1014 },
1015 flags: []string{
1016 "-advertise-npn", "\x03foo\x03bar\x03baz",
1017 },
1018 shouldFail: true,
1019 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1020 },
1021 {
1022 name: "FragmentAcrossChangeCipherSpec-Client",
1023 config: Config{
1024 Bugs: ProtocolBugs{
1025 FragmentAcrossChangeCipherSpec: true,
1026 },
1027 },
1028 shouldFail: true,
1029 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1030 },
1031 {
1032 testType: serverTest,
1033 name: "FragmentAcrossChangeCipherSpec-Server",
1034 config: Config{
1035 Bugs: ProtocolBugs{
1036 FragmentAcrossChangeCipherSpec: true,
1037 },
1038 },
1039 shouldFail: true,
1040 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1041 },
1042 {
1043 testType: serverTest,
1044 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1045 config: Config{
1046 NextProtos: []string{"bar"},
1047 Bugs: ProtocolBugs{
1048 FragmentAcrossChangeCipherSpec: true,
1049 },
1050 },
1051 flags: []string{
1052 "-advertise-npn", "\x03foo\x03bar\x03baz",
1053 },
1054 shouldFail: true,
1055 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1056 },
1057 {
1058 testType: serverTest,
1059 name: "Alert",
1060 config: Config{
1061 Bugs: ProtocolBugs{
1062 SendSpuriousAlert: alertRecordOverflow,
1063 },
1064 },
1065 shouldFail: true,
1066 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1067 },
1068 {
1069 protocol: dtls,
1070 testType: serverTest,
1071 name: "Alert-DTLS",
1072 config: Config{
1073 Bugs: ProtocolBugs{
1074 SendSpuriousAlert: alertRecordOverflow,
1075 },
1076 },
1077 shouldFail: true,
1078 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1079 },
1080 {
1081 testType: serverTest,
1082 name: "FragmentAlert",
1083 config: Config{
1084 Bugs: ProtocolBugs{
1085 FragmentAlert: true,
1086 SendSpuriousAlert: alertRecordOverflow,
1087 },
1088 },
1089 shouldFail: true,
1090 expectedError: ":BAD_ALERT:",
1091 },
1092 {
1093 protocol: dtls,
1094 testType: serverTest,
1095 name: "FragmentAlert-DTLS",
1096 config: Config{
1097 Bugs: ProtocolBugs{
1098 FragmentAlert: true,
1099 SendSpuriousAlert: alertRecordOverflow,
1100 },
1101 },
1102 shouldFail: true,
1103 expectedError: ":BAD_ALERT:",
1104 },
1105 {
1106 testType: serverTest,
1107 name: "EarlyChangeCipherSpec-server-1",
1108 config: Config{
1109 Bugs: ProtocolBugs{
1110 EarlyChangeCipherSpec: 1,
1111 },
1112 },
1113 shouldFail: true,
1114 expectedError: ":CCS_RECEIVED_EARLY:",
1115 },
1116 {
1117 testType: serverTest,
1118 name: "EarlyChangeCipherSpec-server-2",
1119 config: Config{
1120 Bugs: ProtocolBugs{
1121 EarlyChangeCipherSpec: 2,
1122 },
1123 },
1124 shouldFail: true,
1125 expectedError: ":CCS_RECEIVED_EARLY:",
1126 },
1127 {
1128 name: "SkipNewSessionTicket",
1129 config: Config{
1130 Bugs: ProtocolBugs{
1131 SkipNewSessionTicket: true,
1132 },
1133 },
1134 shouldFail: true,
1135 expectedError: ":CCS_RECEIVED_EARLY:",
1136 },
1137 {
1138 testType: serverTest,
1139 name: "FallbackSCSV",
1140 config: Config{
1141 MaxVersion: VersionTLS11,
1142 Bugs: ProtocolBugs{
1143 SendFallbackSCSV: true,
1144 },
1145 },
1146 shouldFail: true,
1147 expectedError: ":INAPPROPRIATE_FALLBACK:",
1148 },
1149 {
1150 testType: serverTest,
1151 name: "FallbackSCSV-VersionMatch",
1152 config: Config{
1153 Bugs: ProtocolBugs{
1154 SendFallbackSCSV: true,
1155 },
1156 },
1157 },
1158 {
1159 testType: serverTest,
1160 name: "FragmentedClientVersion",
1161 config: Config{
1162 Bugs: ProtocolBugs{
1163 MaxHandshakeRecordLength: 1,
1164 FragmentClientVersion: true,
1165 },
1166 },
1167 expectedVersion: VersionTLS12,
1168 },
1169 {
1170 testType: serverTest,
1171 name: "MinorVersionTolerance",
1172 config: Config{
1173 Bugs: ProtocolBugs{
1174 SendClientVersion: 0x03ff,
1175 },
1176 },
1177 expectedVersion: VersionTLS12,
1178 },
1179 {
1180 testType: serverTest,
1181 name: "MajorVersionTolerance",
1182 config: Config{
1183 Bugs: ProtocolBugs{
1184 SendClientVersion: 0x0400,
1185 },
1186 },
1187 expectedVersion: VersionTLS12,
1188 },
1189 {
1190 testType: serverTest,
1191 name: "VersionTooLow",
1192 config: Config{
1193 Bugs: ProtocolBugs{
1194 SendClientVersion: 0x0200,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":UNSUPPORTED_PROTOCOL:",
1199 },
1200 {
1201 testType: serverTest,
1202 name: "HttpGET",
1203 sendPrefix: "GET / HTTP/1.0\n",
1204 shouldFail: true,
1205 expectedError: ":HTTP_REQUEST:",
1206 },
1207 {
1208 testType: serverTest,
1209 name: "HttpPOST",
1210 sendPrefix: "POST / HTTP/1.0\n",
1211 shouldFail: true,
1212 expectedError: ":HTTP_REQUEST:",
1213 },
1214 {
1215 testType: serverTest,
1216 name: "HttpHEAD",
1217 sendPrefix: "HEAD / HTTP/1.0\n",
1218 shouldFail: true,
1219 expectedError: ":HTTP_REQUEST:",
1220 },
1221 {
1222 testType: serverTest,
1223 name: "HttpPUT",
1224 sendPrefix: "PUT / HTTP/1.0\n",
1225 shouldFail: true,
1226 expectedError: ":HTTP_REQUEST:",
1227 },
1228 {
1229 testType: serverTest,
1230 name: "HttpCONNECT",
1231 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1232 shouldFail: true,
1233 expectedError: ":HTTPS_PROXY_REQUEST:",
1234 },
1235 {
1236 testType: serverTest,
1237 name: "Garbage",
1238 sendPrefix: "blah",
1239 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001240 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001241 },
1242 {
1243 name: "SkipCipherVersionCheck",
1244 config: Config{
1245 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1246 MaxVersion: VersionTLS11,
1247 Bugs: ProtocolBugs{
1248 SkipCipherVersionCheck: true,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":WRONG_CIPHER_RETURNED:",
1253 },
1254 {
1255 name: "RSAEphemeralKey",
1256 config: Config{
1257 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1258 Bugs: ProtocolBugs{
1259 RSAEphemeralKey: true,
1260 },
1261 },
1262 shouldFail: true,
1263 expectedError: ":UNEXPECTED_MESSAGE:",
1264 },
1265 {
1266 name: "DisableEverything",
1267 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1268 shouldFail: true,
1269 expectedError: ":WRONG_SSL_VERSION:",
1270 },
1271 {
1272 protocol: dtls,
1273 name: "DisableEverything-DTLS",
1274 flags: []string{"-no-tls12", "-no-tls1"},
1275 shouldFail: true,
1276 expectedError: ":WRONG_SSL_VERSION:",
1277 },
1278 {
1279 name: "NoSharedCipher",
1280 config: Config{
1281 CipherSuites: []uint16{},
1282 },
1283 shouldFail: true,
1284 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1285 },
1286 {
1287 protocol: dtls,
1288 testType: serverTest,
1289 name: "MTU",
1290 config: Config{
1291 Bugs: ProtocolBugs{
1292 MaxPacketLength: 256,
1293 },
1294 },
1295 flags: []string{"-mtu", "256"},
1296 },
1297 {
1298 protocol: dtls,
1299 testType: serverTest,
1300 name: "MTUExceeded",
1301 config: Config{
1302 Bugs: ProtocolBugs{
1303 MaxPacketLength: 255,
1304 },
1305 },
1306 flags: []string{"-mtu", "256"},
1307 shouldFail: true,
1308 expectedLocalError: "dtls: exceeded maximum packet length",
1309 },
1310 {
1311 name: "CertMismatchRSA",
1312 config: Config{
1313 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1314 Certificates: []Certificate{getECDSACertificate()},
1315 Bugs: ProtocolBugs{
1316 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1317 },
1318 },
1319 shouldFail: true,
1320 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1321 },
1322 {
1323 name: "CertMismatchECDSA",
1324 config: Config{
1325 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1326 Certificates: []Certificate{getRSACertificate()},
1327 Bugs: ProtocolBugs{
1328 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1329 },
1330 },
1331 shouldFail: true,
1332 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1333 },
1334 {
1335 name: "EmptyCertificateList",
1336 config: Config{
1337 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1338 Bugs: ProtocolBugs{
1339 EmptyCertificateList: true,
1340 },
1341 },
1342 shouldFail: true,
1343 expectedError: ":DECODE_ERROR:",
1344 },
1345 {
1346 name: "TLSFatalBadPackets",
1347 damageFirstWrite: true,
1348 shouldFail: true,
1349 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1350 },
1351 {
1352 protocol: dtls,
1353 name: "DTLSIgnoreBadPackets",
1354 damageFirstWrite: true,
1355 },
1356 {
1357 protocol: dtls,
1358 name: "DTLSIgnoreBadPackets-Async",
1359 damageFirstWrite: true,
1360 flags: []string{"-async"},
1361 },
1362 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001363 name: "AppDataBeforeHandshake",
1364 config: Config{
1365 Bugs: ProtocolBugs{
1366 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1367 },
1368 },
1369 shouldFail: true,
1370 expectedError: ":UNEXPECTED_RECORD:",
1371 },
1372 {
1373 name: "AppDataBeforeHandshake-Empty",
1374 config: Config{
1375 Bugs: ProtocolBugs{
1376 AppDataBeforeHandshake: []byte{},
1377 },
1378 },
1379 shouldFail: true,
1380 expectedError: ":UNEXPECTED_RECORD:",
1381 },
1382 {
1383 protocol: dtls,
1384 name: "AppDataBeforeHandshake-DTLS",
1385 config: Config{
1386 Bugs: ProtocolBugs{
1387 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1388 },
1389 },
1390 shouldFail: true,
1391 expectedError: ":UNEXPECTED_RECORD:",
1392 },
1393 {
1394 protocol: dtls,
1395 name: "AppDataBeforeHandshake-DTLS-Empty",
1396 config: Config{
1397 Bugs: ProtocolBugs{
1398 AppDataBeforeHandshake: []byte{},
1399 },
1400 },
1401 shouldFail: true,
1402 expectedError: ":UNEXPECTED_RECORD:",
1403 },
1404 {
Adam Langley7c803a62015-06-15 15:35:05 -07001405 name: "AppDataAfterChangeCipherSpec",
1406 config: Config{
1407 Bugs: ProtocolBugs{
1408 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1413 },
1414 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001415 name: "AppDataAfterChangeCipherSpec-Empty",
1416 config: Config{
1417 Bugs: ProtocolBugs{
1418 AppDataAfterChangeCipherSpec: []byte{},
1419 },
1420 },
1421 shouldFail: true,
1422 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1423 },
1424 {
Adam Langley7c803a62015-06-15 15:35:05 -07001425 protocol: dtls,
1426 name: "AppDataAfterChangeCipherSpec-DTLS",
1427 config: Config{
1428 Bugs: ProtocolBugs{
1429 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1430 },
1431 },
1432 // BoringSSL's DTLS implementation will drop the out-of-order
1433 // application data.
1434 },
1435 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001436 protocol: dtls,
1437 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1438 config: Config{
1439 Bugs: ProtocolBugs{
1440 AppDataAfterChangeCipherSpec: []byte{},
1441 },
1442 },
1443 // BoringSSL's DTLS implementation will drop the out-of-order
1444 // application data.
1445 },
1446 {
Adam Langley7c803a62015-06-15 15:35:05 -07001447 name: "AlertAfterChangeCipherSpec",
1448 config: Config{
1449 Bugs: ProtocolBugs{
1450 AlertAfterChangeCipherSpec: alertRecordOverflow,
1451 },
1452 },
1453 shouldFail: true,
1454 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1455 },
1456 {
1457 protocol: dtls,
1458 name: "AlertAfterChangeCipherSpec-DTLS",
1459 config: Config{
1460 Bugs: ProtocolBugs{
1461 AlertAfterChangeCipherSpec: alertRecordOverflow,
1462 },
1463 },
1464 shouldFail: true,
1465 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1466 },
1467 {
1468 protocol: dtls,
1469 name: "ReorderHandshakeFragments-Small-DTLS",
1470 config: Config{
1471 Bugs: ProtocolBugs{
1472 ReorderHandshakeFragments: true,
1473 // Small enough that every handshake message is
1474 // fragmented.
1475 MaxHandshakeRecordLength: 2,
1476 },
1477 },
1478 },
1479 {
1480 protocol: dtls,
1481 name: "ReorderHandshakeFragments-Large-DTLS",
1482 config: Config{
1483 Bugs: ProtocolBugs{
1484 ReorderHandshakeFragments: true,
1485 // Large enough that no handshake message is
1486 // fragmented.
1487 MaxHandshakeRecordLength: 2048,
1488 },
1489 },
1490 },
1491 {
1492 protocol: dtls,
1493 name: "MixCompleteMessageWithFragments-DTLS",
1494 config: Config{
1495 Bugs: ProtocolBugs{
1496 ReorderHandshakeFragments: true,
1497 MixCompleteMessageWithFragments: true,
1498 MaxHandshakeRecordLength: 2,
1499 },
1500 },
1501 },
1502 {
1503 name: "SendInvalidRecordType",
1504 config: Config{
1505 Bugs: ProtocolBugs{
1506 SendInvalidRecordType: true,
1507 },
1508 },
1509 shouldFail: true,
1510 expectedError: ":UNEXPECTED_RECORD:",
1511 },
1512 {
1513 protocol: dtls,
1514 name: "SendInvalidRecordType-DTLS",
1515 config: Config{
1516 Bugs: ProtocolBugs{
1517 SendInvalidRecordType: true,
1518 },
1519 },
1520 shouldFail: true,
1521 expectedError: ":UNEXPECTED_RECORD:",
1522 },
1523 {
1524 name: "FalseStart-SkipServerSecondLeg",
1525 config: Config{
1526 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1527 NextProtos: []string{"foo"},
1528 Bugs: ProtocolBugs{
1529 SkipNewSessionTicket: true,
1530 SkipChangeCipherSpec: true,
1531 SkipFinished: true,
1532 ExpectFalseStart: true,
1533 },
1534 },
1535 flags: []string{
1536 "-false-start",
1537 "-handshake-never-done",
1538 "-advertise-alpn", "\x03foo",
1539 },
1540 shimWritesFirst: true,
1541 shouldFail: true,
1542 expectedError: ":UNEXPECTED_RECORD:",
1543 },
1544 {
1545 name: "FalseStart-SkipServerSecondLeg-Implicit",
1546 config: Config{
1547 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1548 NextProtos: []string{"foo"},
1549 Bugs: ProtocolBugs{
1550 SkipNewSessionTicket: true,
1551 SkipChangeCipherSpec: true,
1552 SkipFinished: true,
1553 },
1554 },
1555 flags: []string{
1556 "-implicit-handshake",
1557 "-false-start",
1558 "-handshake-never-done",
1559 "-advertise-alpn", "\x03foo",
1560 },
1561 shouldFail: true,
1562 expectedError: ":UNEXPECTED_RECORD:",
1563 },
1564 {
1565 testType: serverTest,
1566 name: "FailEarlyCallback",
1567 flags: []string{"-fail-early-callback"},
1568 shouldFail: true,
1569 expectedError: ":CONNECTION_REJECTED:",
1570 expectedLocalError: "remote error: access denied",
1571 },
1572 {
1573 name: "WrongMessageType",
1574 config: Config{
1575 Bugs: ProtocolBugs{
1576 WrongCertificateMessageType: true,
1577 },
1578 },
1579 shouldFail: true,
1580 expectedError: ":UNEXPECTED_MESSAGE:",
1581 expectedLocalError: "remote error: unexpected message",
1582 },
1583 {
1584 protocol: dtls,
1585 name: "WrongMessageType-DTLS",
1586 config: Config{
1587 Bugs: ProtocolBugs{
1588 WrongCertificateMessageType: true,
1589 },
1590 },
1591 shouldFail: true,
1592 expectedError: ":UNEXPECTED_MESSAGE:",
1593 expectedLocalError: "remote error: unexpected message",
1594 },
1595 {
1596 protocol: dtls,
1597 name: "FragmentMessageTypeMismatch-DTLS",
1598 config: Config{
1599 Bugs: ProtocolBugs{
1600 MaxHandshakeRecordLength: 2,
1601 FragmentMessageTypeMismatch: true,
1602 },
1603 },
1604 shouldFail: true,
1605 expectedError: ":FRAGMENT_MISMATCH:",
1606 },
1607 {
1608 protocol: dtls,
1609 name: "FragmentMessageLengthMismatch-DTLS",
1610 config: Config{
1611 Bugs: ProtocolBugs{
1612 MaxHandshakeRecordLength: 2,
1613 FragmentMessageLengthMismatch: true,
1614 },
1615 },
1616 shouldFail: true,
1617 expectedError: ":FRAGMENT_MISMATCH:",
1618 },
1619 {
1620 protocol: dtls,
1621 name: "SplitFragments-Header-DTLS",
1622 config: Config{
1623 Bugs: ProtocolBugs{
1624 SplitFragments: 2,
1625 },
1626 },
1627 shouldFail: true,
1628 expectedError: ":UNEXPECTED_MESSAGE:",
1629 },
1630 {
1631 protocol: dtls,
1632 name: "SplitFragments-Boundary-DTLS",
1633 config: Config{
1634 Bugs: ProtocolBugs{
1635 SplitFragments: dtlsRecordHeaderLen,
1636 },
1637 },
1638 shouldFail: true,
1639 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1640 },
1641 {
1642 protocol: dtls,
1643 name: "SplitFragments-Body-DTLS",
1644 config: Config{
1645 Bugs: ProtocolBugs{
1646 SplitFragments: dtlsRecordHeaderLen + 1,
1647 },
1648 },
1649 shouldFail: true,
1650 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1651 },
1652 {
1653 protocol: dtls,
1654 name: "SendEmptyFragments-DTLS",
1655 config: Config{
1656 Bugs: ProtocolBugs{
1657 SendEmptyFragments: true,
1658 },
1659 },
1660 },
1661 {
1662 name: "UnsupportedCipherSuite",
1663 config: Config{
1664 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1665 Bugs: ProtocolBugs{
1666 IgnorePeerCipherPreferences: true,
1667 },
1668 },
1669 flags: []string{"-cipher", "DEFAULT:!RC4"},
1670 shouldFail: true,
1671 expectedError: ":WRONG_CIPHER_RETURNED:",
1672 },
1673 {
1674 name: "UnsupportedCurve",
1675 config: Config{
1676 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1677 // BoringSSL implements P-224 but doesn't enable it by
1678 // default.
1679 CurvePreferences: []CurveID{CurveP224},
1680 Bugs: ProtocolBugs{
1681 IgnorePeerCurvePreferences: true,
1682 },
1683 },
1684 shouldFail: true,
1685 expectedError: ":WRONG_CURVE:",
1686 },
1687 {
1688 name: "BadFinished",
1689 config: Config{
1690 Bugs: ProtocolBugs{
1691 BadFinished: true,
1692 },
1693 },
1694 shouldFail: true,
1695 expectedError: ":DIGEST_CHECK_FAILED:",
1696 },
1697 {
1698 name: "FalseStart-BadFinished",
1699 config: Config{
1700 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1701 NextProtos: []string{"foo"},
1702 Bugs: ProtocolBugs{
1703 BadFinished: true,
1704 ExpectFalseStart: true,
1705 },
1706 },
1707 flags: []string{
1708 "-false-start",
1709 "-handshake-never-done",
1710 "-advertise-alpn", "\x03foo",
1711 },
1712 shimWritesFirst: true,
1713 shouldFail: true,
1714 expectedError: ":DIGEST_CHECK_FAILED:",
1715 },
1716 {
1717 name: "NoFalseStart-NoALPN",
1718 config: Config{
1719 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1720 Bugs: ProtocolBugs{
1721 ExpectFalseStart: true,
1722 AlertBeforeFalseStartTest: alertAccessDenied,
1723 },
1724 },
1725 flags: []string{
1726 "-false-start",
1727 },
1728 shimWritesFirst: true,
1729 shouldFail: true,
1730 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1731 expectedLocalError: "tls: peer did not false start: EOF",
1732 },
1733 {
1734 name: "NoFalseStart-NoAEAD",
1735 config: Config{
1736 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1737 NextProtos: []string{"foo"},
1738 Bugs: ProtocolBugs{
1739 ExpectFalseStart: true,
1740 AlertBeforeFalseStartTest: alertAccessDenied,
1741 },
1742 },
1743 flags: []string{
1744 "-false-start",
1745 "-advertise-alpn", "\x03foo",
1746 },
1747 shimWritesFirst: true,
1748 shouldFail: true,
1749 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1750 expectedLocalError: "tls: peer did not false start: EOF",
1751 },
1752 {
1753 name: "NoFalseStart-RSA",
1754 config: Config{
1755 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1756 NextProtos: []string{"foo"},
1757 Bugs: ProtocolBugs{
1758 ExpectFalseStart: true,
1759 AlertBeforeFalseStartTest: alertAccessDenied,
1760 },
1761 },
1762 flags: []string{
1763 "-false-start",
1764 "-advertise-alpn", "\x03foo",
1765 },
1766 shimWritesFirst: true,
1767 shouldFail: true,
1768 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1769 expectedLocalError: "tls: peer did not false start: EOF",
1770 },
1771 {
1772 name: "NoFalseStart-DHE_RSA",
1773 config: Config{
1774 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1775 NextProtos: []string{"foo"},
1776 Bugs: ProtocolBugs{
1777 ExpectFalseStart: true,
1778 AlertBeforeFalseStartTest: alertAccessDenied,
1779 },
1780 },
1781 flags: []string{
1782 "-false-start",
1783 "-advertise-alpn", "\x03foo",
1784 },
1785 shimWritesFirst: true,
1786 shouldFail: true,
1787 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1788 expectedLocalError: "tls: peer did not false start: EOF",
1789 },
1790 {
1791 testType: serverTest,
1792 name: "NoSupportedCurves",
1793 config: Config{
1794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1795 Bugs: ProtocolBugs{
1796 NoSupportedCurves: true,
1797 },
1798 },
1799 },
1800 {
1801 testType: serverTest,
1802 name: "NoCommonCurves",
1803 config: Config{
1804 CipherSuites: []uint16{
1805 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1806 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1807 },
1808 CurvePreferences: []CurveID{CurveP224},
1809 },
1810 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1811 },
1812 {
1813 protocol: dtls,
1814 name: "SendSplitAlert-Sync",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 SendSplitAlert: true,
1818 },
1819 },
1820 },
1821 {
1822 protocol: dtls,
1823 name: "SendSplitAlert-Async",
1824 config: Config{
1825 Bugs: ProtocolBugs{
1826 SendSplitAlert: true,
1827 },
1828 },
1829 flags: []string{"-async"},
1830 },
1831 {
1832 protocol: dtls,
1833 name: "PackDTLSHandshake",
1834 config: Config{
1835 Bugs: ProtocolBugs{
1836 MaxHandshakeRecordLength: 2,
1837 PackHandshakeFragments: 20,
1838 PackHandshakeRecords: 200,
1839 },
1840 },
1841 },
1842 {
1843 testType: serverTest,
1844 protocol: dtls,
1845 name: "NoRC4-DTLS",
1846 config: Config{
1847 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1848 Bugs: ProtocolBugs{
1849 EnableAllCiphersInDTLS: true,
1850 },
1851 },
1852 shouldFail: true,
1853 expectedError: ":NO_SHARED_CIPHER:",
1854 },
1855 {
1856 name: "SendEmptyRecords-Pass",
1857 sendEmptyRecords: 32,
1858 },
1859 {
1860 name: "SendEmptyRecords",
1861 sendEmptyRecords: 33,
1862 shouldFail: true,
1863 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1864 },
1865 {
1866 name: "SendEmptyRecords-Async",
1867 sendEmptyRecords: 33,
1868 flags: []string{"-async"},
1869 shouldFail: true,
1870 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1871 },
1872 {
1873 name: "SendWarningAlerts-Pass",
1874 sendWarningAlerts: 4,
1875 },
1876 {
1877 protocol: dtls,
1878 name: "SendWarningAlerts-DTLS-Pass",
1879 sendWarningAlerts: 4,
1880 },
1881 {
1882 name: "SendWarningAlerts",
1883 sendWarningAlerts: 5,
1884 shouldFail: true,
1885 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1886 },
1887 {
1888 name: "SendWarningAlerts-Async",
1889 sendWarningAlerts: 5,
1890 flags: []string{"-async"},
1891 shouldFail: true,
1892 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1893 },
David Benjaminba4594a2015-06-18 18:36:15 -04001894 {
1895 name: "EmptySessionID",
1896 config: Config{
1897 SessionTicketsDisabled: true,
1898 },
1899 noSessionCache: true,
1900 flags: []string{"-expect-no-session"},
1901 },
David Benjamin30789da2015-08-29 22:56:45 -04001902 {
1903 name: "Unclean-Shutdown",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 NoCloseNotify: true,
1907 ExpectCloseNotify: true,
1908 },
1909 },
1910 shimShutsDown: true,
1911 flags: []string{"-check-close-notify"},
1912 shouldFail: true,
1913 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1914 },
1915 {
1916 name: "Unclean-Shutdown-Ignored",
1917 config: Config{
1918 Bugs: ProtocolBugs{
1919 NoCloseNotify: true,
1920 },
1921 },
1922 shimShutsDown: true,
1923 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001924 {
1925 name: "LargePlaintext",
1926 config: Config{
1927 Bugs: ProtocolBugs{
1928 SendLargeRecords: true,
1929 },
1930 },
1931 messageLen: maxPlaintext + 1,
1932 shouldFail: true,
1933 expectedError: ":DATA_LENGTH_TOO_LONG:",
1934 },
1935 {
1936 protocol: dtls,
1937 name: "LargePlaintext-DTLS",
1938 config: Config{
1939 Bugs: ProtocolBugs{
1940 SendLargeRecords: true,
1941 },
1942 },
1943 messageLen: maxPlaintext + 1,
1944 shouldFail: true,
1945 expectedError: ":DATA_LENGTH_TOO_LONG:",
1946 },
1947 {
1948 name: "LargeCiphertext",
1949 config: Config{
1950 Bugs: ProtocolBugs{
1951 SendLargeRecords: true,
1952 },
1953 },
1954 messageLen: maxPlaintext * 2,
1955 shouldFail: true,
1956 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1957 },
1958 {
1959 protocol: dtls,
1960 name: "LargeCiphertext-DTLS",
1961 config: Config{
1962 Bugs: ProtocolBugs{
1963 SendLargeRecords: true,
1964 },
1965 },
1966 messageLen: maxPlaintext * 2,
1967 // Unlike the other four cases, DTLS drops records which
1968 // are invalid before authentication, so the connection
1969 // does not fail.
1970 expectMessageDropped: true,
1971 },
Adam Langley7c803a62015-06-15 15:35:05 -07001972 }
Adam Langley7c803a62015-06-15 15:35:05 -07001973 testCases = append(testCases, basicTests...)
1974}
1975
Adam Langley95c29f32014-06-20 12:00:00 -07001976func addCipherSuiteTests() {
1977 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001978 const psk = "12345"
1979 const pskIdentity = "luggage combo"
1980
Adam Langley95c29f32014-06-20 12:00:00 -07001981 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001982 var certFile string
1983 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001984 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001985 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001986 certFile = ecdsaCertificateFile
1987 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001988 } else {
1989 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001990 certFile = rsaCertificateFile
1991 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001992 }
1993
David Benjamin48cae082014-10-27 01:06:24 -04001994 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001995 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001996 flags = append(flags,
1997 "-psk", psk,
1998 "-psk-identity", pskIdentity)
1999 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002000 if hasComponent(suite.name, "NULL") {
2001 // NULL ciphers must be explicitly enabled.
2002 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2003 }
David Benjamin48cae082014-10-27 01:06:24 -04002004
Adam Langley95c29f32014-06-20 12:00:00 -07002005 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002006 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002007 continue
2008 }
2009
David Benjamin025b3d32014-07-01 19:53:04 -04002010 testCases = append(testCases, testCase{
2011 testType: clientTest,
2012 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002013 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002014 MinVersion: ver.version,
2015 MaxVersion: ver.version,
2016 CipherSuites: []uint16{suite.id},
2017 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002018 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002019 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002020 },
David Benjamin48cae082014-10-27 01:06:24 -04002021 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002022 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002023 })
David Benjamin025b3d32014-07-01 19:53:04 -04002024
David Benjamin76d8abe2014-08-14 16:25:34 -04002025 testCases = append(testCases, testCase{
2026 testType: serverTest,
2027 name: ver.name + "-" + suite.name + "-server",
2028 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002029 MinVersion: ver.version,
2030 MaxVersion: ver.version,
2031 CipherSuites: []uint16{suite.id},
2032 Certificates: []Certificate{cert},
2033 PreSharedKey: []byte(psk),
2034 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002035 },
2036 certFile: certFile,
2037 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002038 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002039 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002040 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002041
David Benjamin8b8c0062014-11-23 02:47:52 -05002042 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002043 testCases = append(testCases, testCase{
2044 testType: clientTest,
2045 protocol: dtls,
2046 name: "D" + ver.name + "-" + suite.name + "-client",
2047 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002048 MinVersion: ver.version,
2049 MaxVersion: ver.version,
2050 CipherSuites: []uint16{suite.id},
2051 Certificates: []Certificate{cert},
2052 PreSharedKey: []byte(psk),
2053 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002054 },
David Benjamin48cae082014-10-27 01:06:24 -04002055 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002056 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002057 })
2058 testCases = append(testCases, testCase{
2059 testType: serverTest,
2060 protocol: dtls,
2061 name: "D" + ver.name + "-" + suite.name + "-server",
2062 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002063 MinVersion: ver.version,
2064 MaxVersion: ver.version,
2065 CipherSuites: []uint16{suite.id},
2066 Certificates: []Certificate{cert},
2067 PreSharedKey: []byte(psk),
2068 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002069 },
2070 certFile: certFile,
2071 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002072 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002073 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002074 })
2075 }
Adam Langley95c29f32014-06-20 12:00:00 -07002076 }
David Benjamin2c99d282015-09-01 10:23:00 -04002077
2078 // Ensure both TLS and DTLS accept their maximum record sizes.
2079 testCases = append(testCases, testCase{
2080 name: suite.name + "-LargeRecord",
2081 config: Config{
2082 CipherSuites: []uint16{suite.id},
2083 Certificates: []Certificate{cert},
2084 PreSharedKey: []byte(psk),
2085 PreSharedKeyIdentity: pskIdentity,
2086 },
2087 flags: flags,
2088 messageLen: maxPlaintext,
2089 })
2090 testCases = append(testCases, testCase{
2091 name: suite.name + "-LargeRecord-Extra",
2092 config: Config{
2093 CipherSuites: []uint16{suite.id},
2094 Certificates: []Certificate{cert},
2095 PreSharedKey: []byte(psk),
2096 PreSharedKeyIdentity: pskIdentity,
2097 Bugs: ProtocolBugs{
2098 SendLargeRecords: true,
2099 },
2100 },
2101 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2102 messageLen: maxPlaintext + 16384,
2103 })
2104 if isDTLSCipher(suite.name) {
2105 testCases = append(testCases, testCase{
2106 protocol: dtls,
2107 name: suite.name + "-LargeRecord-DTLS",
2108 config: Config{
2109 CipherSuites: []uint16{suite.id},
2110 Certificates: []Certificate{cert},
2111 PreSharedKey: []byte(psk),
2112 PreSharedKeyIdentity: pskIdentity,
2113 },
2114 flags: flags,
2115 messageLen: maxPlaintext,
2116 })
2117 }
Adam Langley95c29f32014-06-20 12:00:00 -07002118 }
Adam Langleya7997f12015-05-14 17:38:50 -07002119
2120 testCases = append(testCases, testCase{
2121 name: "WeakDH",
2122 config: Config{
2123 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2124 Bugs: ProtocolBugs{
2125 // This is a 1023-bit prime number, generated
2126 // with:
2127 // openssl gendh 1023 | openssl asn1parse -i
2128 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2129 },
2130 },
2131 shouldFail: true,
2132 expectedError: "BAD_DH_P_LENGTH",
2133 })
Adam Langleycef75832015-09-03 14:51:12 -07002134
2135 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2136 // 1.1 specific cipher suite settings. A server is setup with the given
2137 // cipher lists and then a connection is made for each member of
2138 // expectations. The cipher suite that the server selects must match
2139 // the specified one.
2140 var versionSpecificCiphersTest = []struct {
2141 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2142 // expectations is a map from TLS version to cipher suite id.
2143 expectations map[uint16]uint16
2144 }{
2145 {
2146 // Test that the null case (where no version-specific ciphers are set)
2147 // works as expected.
2148 "RC4-SHA:AES128-SHA", // default ciphers
2149 "", // no ciphers specifically for TLS ≥ 1.0
2150 "", // no ciphers specifically for TLS ≥ 1.1
2151 map[uint16]uint16{
2152 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2153 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2154 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2155 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2156 },
2157 },
2158 {
2159 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2160 // cipher.
2161 "RC4-SHA:AES128-SHA", // default
2162 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2163 "", // no ciphers specifically for TLS ≥ 1.1
2164 map[uint16]uint16{
2165 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2166 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2167 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2168 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2169 },
2170 },
2171 {
2172 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2173 // cipher.
2174 "RC4-SHA:AES128-SHA", // default
2175 "", // no ciphers specifically for TLS ≥ 1.0
2176 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2177 map[uint16]uint16{
2178 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2179 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2180 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2181 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2182 },
2183 },
2184 {
2185 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2186 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2187 "RC4-SHA:AES128-SHA", // default
2188 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2189 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2190 map[uint16]uint16{
2191 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2192 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2193 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2194 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2195 },
2196 },
2197 }
2198
2199 for i, test := range versionSpecificCiphersTest {
2200 for version, expectedCipherSuite := range test.expectations {
2201 flags := []string{"-cipher", test.ciphersDefault}
2202 if len(test.ciphersTLS10) > 0 {
2203 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2204 }
2205 if len(test.ciphersTLS11) > 0 {
2206 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2207 }
2208
2209 testCases = append(testCases, testCase{
2210 testType: serverTest,
2211 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2212 config: Config{
2213 MaxVersion: version,
2214 MinVersion: version,
2215 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2216 },
2217 flags: flags,
2218 expectedCipher: expectedCipherSuite,
2219 })
2220 }
2221 }
Adam Langley95c29f32014-06-20 12:00:00 -07002222}
2223
2224func addBadECDSASignatureTests() {
2225 for badR := BadValue(1); badR < NumBadValues; badR++ {
2226 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002227 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002228 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2229 config: Config{
2230 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2231 Certificates: []Certificate{getECDSACertificate()},
2232 Bugs: ProtocolBugs{
2233 BadECDSAR: badR,
2234 BadECDSAS: badS,
2235 },
2236 },
2237 shouldFail: true,
2238 expectedError: "SIGNATURE",
2239 })
2240 }
2241 }
2242}
2243
Adam Langley80842bd2014-06-20 12:00:00 -07002244func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002245 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002246 name: "MaxCBCPadding",
2247 config: Config{
2248 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2249 Bugs: ProtocolBugs{
2250 MaxPadding: true,
2251 },
2252 },
2253 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2254 })
David Benjamin025b3d32014-07-01 19:53:04 -04002255 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002256 name: "BadCBCPadding",
2257 config: Config{
2258 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2259 Bugs: ProtocolBugs{
2260 PaddingFirstByteBad: true,
2261 },
2262 },
2263 shouldFail: true,
2264 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2265 })
2266 // OpenSSL previously had an issue where the first byte of padding in
2267 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002268 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002269 name: "BadCBCPadding255",
2270 config: Config{
2271 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2272 Bugs: ProtocolBugs{
2273 MaxPadding: true,
2274 PaddingFirstByteBadIf255: true,
2275 },
2276 },
2277 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2278 shouldFail: true,
2279 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2280 })
2281}
2282
Kenny Root7fdeaf12014-08-05 15:23:37 -07002283func addCBCSplittingTests() {
2284 testCases = append(testCases, testCase{
2285 name: "CBCRecordSplitting",
2286 config: Config{
2287 MaxVersion: VersionTLS10,
2288 MinVersion: VersionTLS10,
2289 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2290 },
David Benjaminac8302a2015-09-01 17:18:15 -04002291 messageLen: -1, // read until EOF
2292 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002293 flags: []string{
2294 "-async",
2295 "-write-different-record-sizes",
2296 "-cbc-record-splitting",
2297 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002298 })
2299 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002300 name: "CBCRecordSplittingPartialWrite",
2301 config: Config{
2302 MaxVersion: VersionTLS10,
2303 MinVersion: VersionTLS10,
2304 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2305 },
2306 messageLen: -1, // read until EOF
2307 flags: []string{
2308 "-async",
2309 "-write-different-record-sizes",
2310 "-cbc-record-splitting",
2311 "-partial-write",
2312 },
2313 })
2314}
2315
David Benjamin636293b2014-07-08 17:59:18 -04002316func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002317 // Add a dummy cert pool to stress certificate authority parsing.
2318 // TODO(davidben): Add tests that those values parse out correctly.
2319 certPool := x509.NewCertPool()
2320 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2321 if err != nil {
2322 panic(err)
2323 }
2324 certPool.AddCert(cert)
2325
David Benjamin636293b2014-07-08 17:59:18 -04002326 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002327 testCases = append(testCases, testCase{
2328 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002329 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002330 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002331 MinVersion: ver.version,
2332 MaxVersion: ver.version,
2333 ClientAuth: RequireAnyClientCert,
2334 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002335 },
2336 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002337 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2338 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002339 },
2340 })
2341 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002342 testType: serverTest,
2343 name: ver.name + "-Server-ClientAuth-RSA",
2344 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002345 MinVersion: ver.version,
2346 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002347 Certificates: []Certificate{rsaCertificate},
2348 },
2349 flags: []string{"-require-any-client-certificate"},
2350 })
David Benjamine098ec22014-08-27 23:13:20 -04002351 if ver.version != VersionSSL30 {
2352 testCases = append(testCases, testCase{
2353 testType: serverTest,
2354 name: ver.name + "-Server-ClientAuth-ECDSA",
2355 config: Config{
2356 MinVersion: ver.version,
2357 MaxVersion: ver.version,
2358 Certificates: []Certificate{ecdsaCertificate},
2359 },
2360 flags: []string{"-require-any-client-certificate"},
2361 })
2362 testCases = append(testCases, testCase{
2363 testType: clientTest,
2364 name: ver.name + "-Client-ClientAuth-ECDSA",
2365 config: Config{
2366 MinVersion: ver.version,
2367 MaxVersion: ver.version,
2368 ClientAuth: RequireAnyClientCert,
2369 ClientCAs: certPool,
2370 },
2371 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002372 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2373 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002374 },
2375 })
2376 }
David Benjamin636293b2014-07-08 17:59:18 -04002377 }
2378}
2379
Adam Langley75712922014-10-10 16:23:43 -07002380func addExtendedMasterSecretTests() {
2381 const expectEMSFlag = "-expect-extended-master-secret"
2382
2383 for _, with := range []bool{false, true} {
2384 prefix := "No"
2385 var flags []string
2386 if with {
2387 prefix = ""
2388 flags = []string{expectEMSFlag}
2389 }
2390
2391 for _, isClient := range []bool{false, true} {
2392 suffix := "-Server"
2393 testType := serverTest
2394 if isClient {
2395 suffix = "-Client"
2396 testType = clientTest
2397 }
2398
2399 for _, ver := range tlsVersions {
2400 test := testCase{
2401 testType: testType,
2402 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2403 config: Config{
2404 MinVersion: ver.version,
2405 MaxVersion: ver.version,
2406 Bugs: ProtocolBugs{
2407 NoExtendedMasterSecret: !with,
2408 RequireExtendedMasterSecret: with,
2409 },
2410 },
David Benjamin48cae082014-10-27 01:06:24 -04002411 flags: flags,
2412 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002413 }
2414 if test.shouldFail {
2415 test.expectedLocalError = "extended master secret required but not supported by peer"
2416 }
2417 testCases = append(testCases, test)
2418 }
2419 }
2420 }
2421
Adam Langleyba5934b2015-06-02 10:50:35 -07002422 for _, isClient := range []bool{false, true} {
2423 for _, supportedInFirstConnection := range []bool{false, true} {
2424 for _, supportedInResumeConnection := range []bool{false, true} {
2425 boolToWord := func(b bool) string {
2426 if b {
2427 return "Yes"
2428 }
2429 return "No"
2430 }
2431 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2432 if isClient {
2433 suffix += "Client"
2434 } else {
2435 suffix += "Server"
2436 }
2437
2438 supportedConfig := Config{
2439 Bugs: ProtocolBugs{
2440 RequireExtendedMasterSecret: true,
2441 },
2442 }
2443
2444 noSupportConfig := Config{
2445 Bugs: ProtocolBugs{
2446 NoExtendedMasterSecret: true,
2447 },
2448 }
2449
2450 test := testCase{
2451 name: "ExtendedMasterSecret-" + suffix,
2452 resumeSession: true,
2453 }
2454
2455 if !isClient {
2456 test.testType = serverTest
2457 }
2458
2459 if supportedInFirstConnection {
2460 test.config = supportedConfig
2461 } else {
2462 test.config = noSupportConfig
2463 }
2464
2465 if supportedInResumeConnection {
2466 test.resumeConfig = &supportedConfig
2467 } else {
2468 test.resumeConfig = &noSupportConfig
2469 }
2470
2471 switch suffix {
2472 case "YesToYes-Client", "YesToYes-Server":
2473 // When a session is resumed, it should
2474 // still be aware that its master
2475 // secret was generated via EMS and
2476 // thus it's safe to use tls-unique.
2477 test.flags = []string{expectEMSFlag}
2478 case "NoToYes-Server":
2479 // If an original connection did not
2480 // contain EMS, but a resumption
2481 // handshake does, then a server should
2482 // not resume the session.
2483 test.expectResumeRejected = true
2484 case "YesToNo-Server":
2485 // Resuming an EMS session without the
2486 // EMS extension should cause the
2487 // server to abort the connection.
2488 test.shouldFail = true
2489 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2490 case "NoToYes-Client":
2491 // A client should abort a connection
2492 // where the server resumed a non-EMS
2493 // session but echoed the EMS
2494 // extension.
2495 test.shouldFail = true
2496 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2497 case "YesToNo-Client":
2498 // A client should abort a connection
2499 // where the server didn't echo EMS
2500 // when the session used it.
2501 test.shouldFail = true
2502 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2503 }
2504
2505 testCases = append(testCases, test)
2506 }
2507 }
2508 }
Adam Langley75712922014-10-10 16:23:43 -07002509}
2510
David Benjamin43ec06f2014-08-05 02:28:57 -04002511// Adds tests that try to cover the range of the handshake state machine, under
2512// various conditions. Some of these are redundant with other tests, but they
2513// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002514func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002515 var tests []testCase
2516
2517 // Basic handshake, with resumption. Client and server,
2518 // session ID and session ticket.
2519 tests = append(tests, testCase{
2520 name: "Basic-Client",
2521 resumeSession: true,
2522 })
2523 tests = append(tests, testCase{
2524 name: "Basic-Client-RenewTicket",
2525 config: Config{
2526 Bugs: ProtocolBugs{
2527 RenewTicketOnResume: true,
2528 },
2529 },
David Benjaminba4594a2015-06-18 18:36:15 -04002530 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002531 resumeSession: true,
2532 })
2533 tests = append(tests, testCase{
2534 name: "Basic-Client-NoTicket",
2535 config: Config{
2536 SessionTicketsDisabled: true,
2537 },
2538 resumeSession: true,
2539 })
2540 tests = append(tests, testCase{
2541 name: "Basic-Client-Implicit",
2542 flags: []string{"-implicit-handshake"},
2543 resumeSession: true,
2544 })
2545 tests = append(tests, testCase{
2546 testType: serverTest,
2547 name: "Basic-Server",
2548 resumeSession: true,
2549 })
2550 tests = append(tests, testCase{
2551 testType: serverTest,
2552 name: "Basic-Server-NoTickets",
2553 config: Config{
2554 SessionTicketsDisabled: true,
2555 },
2556 resumeSession: true,
2557 })
2558 tests = append(tests, testCase{
2559 testType: serverTest,
2560 name: "Basic-Server-Implicit",
2561 flags: []string{"-implicit-handshake"},
2562 resumeSession: true,
2563 })
2564 tests = append(tests, testCase{
2565 testType: serverTest,
2566 name: "Basic-Server-EarlyCallback",
2567 flags: []string{"-use-early-callback"},
2568 resumeSession: true,
2569 })
2570
2571 // TLS client auth.
2572 tests = append(tests, testCase{
2573 testType: clientTest,
2574 name: "ClientAuth-Client",
2575 config: Config{
2576 ClientAuth: RequireAnyClientCert,
2577 },
2578 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002579 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2580 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002581 },
2582 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002583 if async {
2584 tests = append(tests, testCase{
2585 testType: clientTest,
2586 name: "ClientAuth-Client-AsyncKey",
2587 config: Config{
2588 ClientAuth: RequireAnyClientCert,
2589 },
2590 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002591 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2592 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002593 "-use-async-private-key",
2594 },
2595 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002596 tests = append(tests, testCase{
2597 testType: serverTest,
2598 name: "Basic-Server-RSAAsyncKey",
2599 flags: []string{
2600 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2601 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2602 "-use-async-private-key",
2603 },
2604 })
2605 tests = append(tests, testCase{
2606 testType: serverTest,
2607 name: "Basic-Server-ECDSAAsyncKey",
2608 flags: []string{
2609 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2610 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2611 "-use-async-private-key",
2612 },
2613 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002614 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002615 tests = append(tests, testCase{
2616 testType: serverTest,
2617 name: "ClientAuth-Server",
2618 config: Config{
2619 Certificates: []Certificate{rsaCertificate},
2620 },
2621 flags: []string{"-require-any-client-certificate"},
2622 })
2623
2624 // No session ticket support; server doesn't send NewSessionTicket.
2625 tests = append(tests, testCase{
2626 name: "SessionTicketsDisabled-Client",
2627 config: Config{
2628 SessionTicketsDisabled: true,
2629 },
2630 })
2631 tests = append(tests, testCase{
2632 testType: serverTest,
2633 name: "SessionTicketsDisabled-Server",
2634 config: Config{
2635 SessionTicketsDisabled: true,
2636 },
2637 })
2638
2639 // Skip ServerKeyExchange in PSK key exchange if there's no
2640 // identity hint.
2641 tests = append(tests, testCase{
2642 name: "EmptyPSKHint-Client",
2643 config: Config{
2644 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2645 PreSharedKey: []byte("secret"),
2646 },
2647 flags: []string{"-psk", "secret"},
2648 })
2649 tests = append(tests, testCase{
2650 testType: serverTest,
2651 name: "EmptyPSKHint-Server",
2652 config: Config{
2653 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2654 PreSharedKey: []byte("secret"),
2655 },
2656 flags: []string{"-psk", "secret"},
2657 })
2658
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002659 tests = append(tests, testCase{
2660 testType: clientTest,
2661 name: "OCSPStapling-Client",
2662 flags: []string{
2663 "-enable-ocsp-stapling",
2664 "-expect-ocsp-response",
2665 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002666 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002667 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002668 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002669 })
2670
2671 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002672 testType: serverTest,
2673 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002674 expectedOCSPResponse: testOCSPResponse,
2675 flags: []string{
2676 "-ocsp-response",
2677 base64.StdEncoding.EncodeToString(testOCSPResponse),
2678 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002679 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002680 })
2681
Paul Lietar8f1c2682015-08-18 12:21:54 +01002682 tests = append(tests, testCase{
2683 testType: clientTest,
2684 name: "CertificateVerificationSucceed",
2685 flags: []string{
2686 "-verify-peer",
2687 },
2688 })
2689
2690 tests = append(tests, testCase{
2691 testType: clientTest,
2692 name: "CertificateVerificationFail",
2693 flags: []string{
2694 "-verify-fail",
2695 "-verify-peer",
2696 },
2697 shouldFail: true,
2698 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2699 })
2700
2701 tests = append(tests, testCase{
2702 testType: clientTest,
2703 name: "CertificateVerificationSoftFail",
2704 flags: []string{
2705 "-verify-fail",
2706 "-expect-verify-result",
2707 },
2708 })
2709
David Benjamin760b1dd2015-05-15 23:33:48 -04002710 if protocol == tls {
2711 tests = append(tests, testCase{
2712 name: "Renegotiate-Client",
2713 renegotiate: true,
2714 })
2715 // NPN on client and server; results in post-handshake message.
2716 tests = append(tests, testCase{
2717 name: "NPN-Client",
2718 config: Config{
2719 NextProtos: []string{"foo"},
2720 },
2721 flags: []string{"-select-next-proto", "foo"},
2722 expectedNextProto: "foo",
2723 expectedNextProtoType: npn,
2724 })
2725 tests = append(tests, testCase{
2726 testType: serverTest,
2727 name: "NPN-Server",
2728 config: Config{
2729 NextProtos: []string{"bar"},
2730 },
2731 flags: []string{
2732 "-advertise-npn", "\x03foo\x03bar\x03baz",
2733 "-expect-next-proto", "bar",
2734 },
2735 expectedNextProto: "bar",
2736 expectedNextProtoType: npn,
2737 })
2738
2739 // TODO(davidben): Add tests for when False Start doesn't trigger.
2740
2741 // Client does False Start and negotiates NPN.
2742 tests = append(tests, testCase{
2743 name: "FalseStart",
2744 config: Config{
2745 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2746 NextProtos: []string{"foo"},
2747 Bugs: ProtocolBugs{
2748 ExpectFalseStart: true,
2749 },
2750 },
2751 flags: []string{
2752 "-false-start",
2753 "-select-next-proto", "foo",
2754 },
2755 shimWritesFirst: true,
2756 resumeSession: true,
2757 })
2758
2759 // Client does False Start and negotiates ALPN.
2760 tests = append(tests, testCase{
2761 name: "FalseStart-ALPN",
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 "-advertise-alpn", "\x03foo",
2772 },
2773 shimWritesFirst: true,
2774 resumeSession: true,
2775 })
2776
2777 // Client does False Start but doesn't explicitly call
2778 // SSL_connect.
2779 tests = append(tests, testCase{
2780 name: "FalseStart-Implicit",
2781 config: Config{
2782 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2783 NextProtos: []string{"foo"},
2784 },
2785 flags: []string{
2786 "-implicit-handshake",
2787 "-false-start",
2788 "-advertise-alpn", "\x03foo",
2789 },
2790 })
2791
2792 // False Start without session tickets.
2793 tests = append(tests, testCase{
2794 name: "FalseStart-SessionTicketsDisabled",
2795 config: Config{
2796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2797 NextProtos: []string{"foo"},
2798 SessionTicketsDisabled: true,
2799 Bugs: ProtocolBugs{
2800 ExpectFalseStart: true,
2801 },
2802 },
2803 flags: []string{
2804 "-false-start",
2805 "-select-next-proto", "foo",
2806 },
2807 shimWritesFirst: true,
2808 })
2809
2810 // Server parses a V2ClientHello.
2811 tests = append(tests, testCase{
2812 testType: serverTest,
2813 name: "SendV2ClientHello",
2814 config: Config{
2815 // Choose a cipher suite that does not involve
2816 // elliptic curves, so no extensions are
2817 // involved.
2818 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2819 Bugs: ProtocolBugs{
2820 SendV2ClientHello: true,
2821 },
2822 },
2823 })
2824
2825 // Client sends a Channel ID.
2826 tests = append(tests, testCase{
2827 name: "ChannelID-Client",
2828 config: Config{
2829 RequestChannelID: true,
2830 },
Adam Langley7c803a62015-06-15 15:35:05 -07002831 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002832 resumeSession: true,
2833 expectChannelID: true,
2834 })
2835
2836 // Server accepts a Channel ID.
2837 tests = append(tests, testCase{
2838 testType: serverTest,
2839 name: "ChannelID-Server",
2840 config: Config{
2841 ChannelID: channelIDKey,
2842 },
2843 flags: []string{
2844 "-expect-channel-id",
2845 base64.StdEncoding.EncodeToString(channelIDBytes),
2846 },
2847 resumeSession: true,
2848 expectChannelID: true,
2849 })
David Benjamin30789da2015-08-29 22:56:45 -04002850
2851 // Bidirectional shutdown with the runner initiating.
2852 tests = append(tests, testCase{
2853 name: "Shutdown-Runner",
2854 config: Config{
2855 Bugs: ProtocolBugs{
2856 ExpectCloseNotify: true,
2857 },
2858 },
2859 flags: []string{"-check-close-notify"},
2860 })
2861
2862 // Bidirectional shutdown with the shim initiating. The runner,
2863 // in the meantime, sends garbage before the close_notify which
2864 // the shim must ignore.
2865 tests = append(tests, testCase{
2866 name: "Shutdown-Shim",
2867 config: Config{
2868 Bugs: ProtocolBugs{
2869 ExpectCloseNotify: true,
2870 },
2871 },
2872 shimShutsDown: true,
2873 sendEmptyRecords: 1,
2874 sendWarningAlerts: 1,
2875 flags: []string{"-check-close-notify"},
2876 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002877 } else {
2878 tests = append(tests, testCase{
2879 name: "SkipHelloVerifyRequest",
2880 config: Config{
2881 Bugs: ProtocolBugs{
2882 SkipHelloVerifyRequest: true,
2883 },
2884 },
2885 })
2886 }
2887
David Benjamin43ec06f2014-08-05 02:28:57 -04002888 var suffix string
2889 var flags []string
2890 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002891 if protocol == dtls {
2892 suffix = "-DTLS"
2893 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002894 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002895 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002896 flags = append(flags, "-async")
2897 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002898 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002899 }
2900 if splitHandshake {
2901 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002902 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002903 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002904 for _, test := range tests {
2905 test.protocol = protocol
2906 test.name += suffix
2907 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2908 test.flags = append(test.flags, flags...)
2909 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002910 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002911}
2912
Adam Langley524e7172015-02-20 16:04:00 -08002913func addDDoSCallbackTests() {
2914 // DDoS callback.
2915
2916 for _, resume := range []bool{false, true} {
2917 suffix := "Resume"
2918 if resume {
2919 suffix = "No" + suffix
2920 }
2921
2922 testCases = append(testCases, testCase{
2923 testType: serverTest,
2924 name: "Server-DDoS-OK-" + suffix,
2925 flags: []string{"-install-ddos-callback"},
2926 resumeSession: resume,
2927 })
2928
2929 failFlag := "-fail-ddos-callback"
2930 if resume {
2931 failFlag = "-fail-second-ddos-callback"
2932 }
2933 testCases = append(testCases, testCase{
2934 testType: serverTest,
2935 name: "Server-DDoS-Reject-" + suffix,
2936 flags: []string{"-install-ddos-callback", failFlag},
2937 resumeSession: resume,
2938 shouldFail: true,
2939 expectedError: ":CONNECTION_REJECTED:",
2940 })
2941 }
2942}
2943
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002944func addVersionNegotiationTests() {
2945 for i, shimVers := range tlsVersions {
2946 // Assemble flags to disable all newer versions on the shim.
2947 var flags []string
2948 for _, vers := range tlsVersions[i+1:] {
2949 flags = append(flags, vers.flag)
2950 }
2951
2952 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002953 protocols := []protocol{tls}
2954 if runnerVers.hasDTLS && shimVers.hasDTLS {
2955 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002956 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002957 for _, protocol := range protocols {
2958 expectedVersion := shimVers.version
2959 if runnerVers.version < shimVers.version {
2960 expectedVersion = runnerVers.version
2961 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002962
David Benjamin8b8c0062014-11-23 02:47:52 -05002963 suffix := shimVers.name + "-" + runnerVers.name
2964 if protocol == dtls {
2965 suffix += "-DTLS"
2966 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002967
David Benjamin1eb367c2014-12-12 18:17:51 -05002968 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2969
David Benjamin1e29a6b2014-12-10 02:27:24 -05002970 clientVers := shimVers.version
2971 if clientVers > VersionTLS10 {
2972 clientVers = VersionTLS10
2973 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002974 testCases = append(testCases, testCase{
2975 protocol: protocol,
2976 testType: clientTest,
2977 name: "VersionNegotiation-Client-" + suffix,
2978 config: Config{
2979 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002980 Bugs: ProtocolBugs{
2981 ExpectInitialRecordVersion: clientVers,
2982 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002983 },
2984 flags: flags,
2985 expectedVersion: expectedVersion,
2986 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002987 testCases = append(testCases, testCase{
2988 protocol: protocol,
2989 testType: clientTest,
2990 name: "VersionNegotiation-Client2-" + suffix,
2991 config: Config{
2992 MaxVersion: runnerVers.version,
2993 Bugs: ProtocolBugs{
2994 ExpectInitialRecordVersion: clientVers,
2995 },
2996 },
2997 flags: []string{"-max-version", shimVersFlag},
2998 expectedVersion: expectedVersion,
2999 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003000
3001 testCases = append(testCases, testCase{
3002 protocol: protocol,
3003 testType: serverTest,
3004 name: "VersionNegotiation-Server-" + suffix,
3005 config: Config{
3006 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003007 Bugs: ProtocolBugs{
3008 ExpectInitialRecordVersion: expectedVersion,
3009 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003010 },
3011 flags: flags,
3012 expectedVersion: expectedVersion,
3013 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003014 testCases = append(testCases, testCase{
3015 protocol: protocol,
3016 testType: serverTest,
3017 name: "VersionNegotiation-Server2-" + suffix,
3018 config: Config{
3019 MaxVersion: runnerVers.version,
3020 Bugs: ProtocolBugs{
3021 ExpectInitialRecordVersion: expectedVersion,
3022 },
3023 },
3024 flags: []string{"-max-version", shimVersFlag},
3025 expectedVersion: expectedVersion,
3026 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003027 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003028 }
3029 }
3030}
3031
David Benjaminaccb4542014-12-12 23:44:33 -05003032func addMinimumVersionTests() {
3033 for i, shimVers := range tlsVersions {
3034 // Assemble flags to disable all older versions on the shim.
3035 var flags []string
3036 for _, vers := range tlsVersions[:i] {
3037 flags = append(flags, vers.flag)
3038 }
3039
3040 for _, runnerVers := range tlsVersions {
3041 protocols := []protocol{tls}
3042 if runnerVers.hasDTLS && shimVers.hasDTLS {
3043 protocols = append(protocols, dtls)
3044 }
3045 for _, protocol := range protocols {
3046 suffix := shimVers.name + "-" + runnerVers.name
3047 if protocol == dtls {
3048 suffix += "-DTLS"
3049 }
3050 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3051
David Benjaminaccb4542014-12-12 23:44:33 -05003052 var expectedVersion uint16
3053 var shouldFail bool
3054 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003055 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003056 if runnerVers.version >= shimVers.version {
3057 expectedVersion = runnerVers.version
3058 } else {
3059 shouldFail = true
3060 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003061 if runnerVers.version > VersionSSL30 {
3062 expectedLocalError = "remote error: protocol version not supported"
3063 } else {
3064 expectedLocalError = "remote error: handshake failure"
3065 }
David Benjaminaccb4542014-12-12 23:44:33 -05003066 }
3067
3068 testCases = append(testCases, testCase{
3069 protocol: protocol,
3070 testType: clientTest,
3071 name: "MinimumVersion-Client-" + suffix,
3072 config: Config{
3073 MaxVersion: runnerVers.version,
3074 },
David Benjamin87909c02014-12-13 01:55:01 -05003075 flags: flags,
3076 expectedVersion: expectedVersion,
3077 shouldFail: shouldFail,
3078 expectedError: expectedError,
3079 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003080 })
3081 testCases = append(testCases, testCase{
3082 protocol: protocol,
3083 testType: clientTest,
3084 name: "MinimumVersion-Client2-" + suffix,
3085 config: Config{
3086 MaxVersion: runnerVers.version,
3087 },
David Benjamin87909c02014-12-13 01:55:01 -05003088 flags: []string{"-min-version", shimVersFlag},
3089 expectedVersion: expectedVersion,
3090 shouldFail: shouldFail,
3091 expectedError: expectedError,
3092 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003093 })
3094
3095 testCases = append(testCases, testCase{
3096 protocol: protocol,
3097 testType: serverTest,
3098 name: "MinimumVersion-Server-" + suffix,
3099 config: Config{
3100 MaxVersion: runnerVers.version,
3101 },
David Benjamin87909c02014-12-13 01:55:01 -05003102 flags: flags,
3103 expectedVersion: expectedVersion,
3104 shouldFail: shouldFail,
3105 expectedError: expectedError,
3106 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003107 })
3108 testCases = append(testCases, testCase{
3109 protocol: protocol,
3110 testType: serverTest,
3111 name: "MinimumVersion-Server2-" + suffix,
3112 config: Config{
3113 MaxVersion: runnerVers.version,
3114 },
David Benjamin87909c02014-12-13 01:55:01 -05003115 flags: []string{"-min-version", shimVersFlag},
3116 expectedVersion: expectedVersion,
3117 shouldFail: shouldFail,
3118 expectedError: expectedError,
3119 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003120 })
3121 }
3122 }
3123 }
3124}
3125
David Benjamin5c24a1d2014-08-31 00:59:27 -04003126func addD5BugTests() {
3127 testCases = append(testCases, testCase{
3128 testType: serverTest,
3129 name: "D5Bug-NoQuirk-Reject",
3130 config: Config{
3131 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3132 Bugs: ProtocolBugs{
3133 SSL3RSAKeyExchange: true,
3134 },
3135 },
3136 shouldFail: true,
3137 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3138 })
3139 testCases = append(testCases, testCase{
3140 testType: serverTest,
3141 name: "D5Bug-Quirk-Normal",
3142 config: Config{
3143 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3144 },
3145 flags: []string{"-tls-d5-bug"},
3146 })
3147 testCases = append(testCases, testCase{
3148 testType: serverTest,
3149 name: "D5Bug-Quirk-Bug",
3150 config: Config{
3151 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3152 Bugs: ProtocolBugs{
3153 SSL3RSAKeyExchange: true,
3154 },
3155 },
3156 flags: []string{"-tls-d5-bug"},
3157 })
3158}
3159
David Benjamine78bfde2014-09-06 12:45:15 -04003160func addExtensionTests() {
3161 testCases = append(testCases, testCase{
3162 testType: clientTest,
3163 name: "DuplicateExtensionClient",
3164 config: Config{
3165 Bugs: ProtocolBugs{
3166 DuplicateExtension: true,
3167 },
3168 },
3169 shouldFail: true,
3170 expectedLocalError: "remote error: error decoding message",
3171 })
3172 testCases = append(testCases, testCase{
3173 testType: serverTest,
3174 name: "DuplicateExtensionServer",
3175 config: Config{
3176 Bugs: ProtocolBugs{
3177 DuplicateExtension: true,
3178 },
3179 },
3180 shouldFail: true,
3181 expectedLocalError: "remote error: error decoding message",
3182 })
3183 testCases = append(testCases, testCase{
3184 testType: clientTest,
3185 name: "ServerNameExtensionClient",
3186 config: Config{
3187 Bugs: ProtocolBugs{
3188 ExpectServerName: "example.com",
3189 },
3190 },
3191 flags: []string{"-host-name", "example.com"},
3192 })
3193 testCases = append(testCases, testCase{
3194 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003195 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003196 config: Config{
3197 Bugs: ProtocolBugs{
3198 ExpectServerName: "mismatch.com",
3199 },
3200 },
3201 flags: []string{"-host-name", "example.com"},
3202 shouldFail: true,
3203 expectedLocalError: "tls: unexpected server name",
3204 })
3205 testCases = append(testCases, testCase{
3206 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003207 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003208 config: Config{
3209 Bugs: ProtocolBugs{
3210 ExpectServerName: "missing.com",
3211 },
3212 },
3213 shouldFail: true,
3214 expectedLocalError: "tls: unexpected server name",
3215 })
3216 testCases = append(testCases, testCase{
3217 testType: serverTest,
3218 name: "ServerNameExtensionServer",
3219 config: Config{
3220 ServerName: "example.com",
3221 },
3222 flags: []string{"-expect-server-name", "example.com"},
3223 resumeSession: true,
3224 })
David Benjaminae2888f2014-09-06 12:58:58 -04003225 testCases = append(testCases, testCase{
3226 testType: clientTest,
3227 name: "ALPNClient",
3228 config: Config{
3229 NextProtos: []string{"foo"},
3230 },
3231 flags: []string{
3232 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3233 "-expect-alpn", "foo",
3234 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003235 expectedNextProto: "foo",
3236 expectedNextProtoType: alpn,
3237 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003238 })
3239 testCases = append(testCases, testCase{
3240 testType: serverTest,
3241 name: "ALPNServer",
3242 config: Config{
3243 NextProtos: []string{"foo", "bar", "baz"},
3244 },
3245 flags: []string{
3246 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3247 "-select-alpn", "foo",
3248 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003249 expectedNextProto: "foo",
3250 expectedNextProtoType: alpn,
3251 resumeSession: true,
3252 })
3253 // Test that the server prefers ALPN over NPN.
3254 testCases = append(testCases, testCase{
3255 testType: serverTest,
3256 name: "ALPNServer-Preferred",
3257 config: Config{
3258 NextProtos: []string{"foo", "bar", "baz"},
3259 },
3260 flags: []string{
3261 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3262 "-select-alpn", "foo",
3263 "-advertise-npn", "\x03foo\x03bar\x03baz",
3264 },
3265 expectedNextProto: "foo",
3266 expectedNextProtoType: alpn,
3267 resumeSession: true,
3268 })
3269 testCases = append(testCases, testCase{
3270 testType: serverTest,
3271 name: "ALPNServer-Preferred-Swapped",
3272 config: Config{
3273 NextProtos: []string{"foo", "bar", "baz"},
3274 Bugs: ProtocolBugs{
3275 SwapNPNAndALPN: true,
3276 },
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,
David Benjaminae2888f2014-09-06 12:58:58 -04003286 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003287 var emptyString string
3288 testCases = append(testCases, testCase{
3289 testType: clientTest,
3290 name: "ALPNClient-EmptyProtocolName",
3291 config: Config{
3292 NextProtos: []string{""},
3293 Bugs: ProtocolBugs{
3294 // A server returning an empty ALPN protocol
3295 // should be rejected.
3296 ALPNProtocol: &emptyString,
3297 },
3298 },
3299 flags: []string{
3300 "-advertise-alpn", "\x03foo",
3301 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003302 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003303 expectedError: ":PARSE_TLSEXT:",
3304 })
3305 testCases = append(testCases, testCase{
3306 testType: serverTest,
3307 name: "ALPNServer-EmptyProtocolName",
3308 config: Config{
3309 // A ClientHello containing an empty ALPN protocol
3310 // should be rejected.
3311 NextProtos: []string{"foo", "", "baz"},
3312 },
3313 flags: []string{
3314 "-select-alpn", "foo",
3315 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003316 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003317 expectedError: ":PARSE_TLSEXT:",
3318 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003319 // Test that negotiating both NPN and ALPN is forbidden.
3320 testCases = append(testCases, testCase{
3321 name: "NegotiateALPNAndNPN",
3322 config: Config{
3323 NextProtos: []string{"foo", "bar", "baz"},
3324 Bugs: ProtocolBugs{
3325 NegotiateALPNAndNPN: true,
3326 },
3327 },
3328 flags: []string{
3329 "-advertise-alpn", "\x03foo",
3330 "-select-next-proto", "foo",
3331 },
3332 shouldFail: true,
3333 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3334 })
3335 testCases = append(testCases, testCase{
3336 name: "NegotiateALPNAndNPN-Swapped",
3337 config: Config{
3338 NextProtos: []string{"foo", "bar", "baz"},
3339 Bugs: ProtocolBugs{
3340 NegotiateALPNAndNPN: true,
3341 SwapNPNAndALPN: true,
3342 },
3343 },
3344 flags: []string{
3345 "-advertise-alpn", "\x03foo",
3346 "-select-next-proto", "foo",
3347 },
3348 shouldFail: true,
3349 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3350 })
Adam Langley38311732014-10-16 19:04:35 -07003351 // Resume with a corrupt ticket.
3352 testCases = append(testCases, testCase{
3353 testType: serverTest,
3354 name: "CorruptTicket",
3355 config: Config{
3356 Bugs: ProtocolBugs{
3357 CorruptTicket: true,
3358 },
3359 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003360 resumeSession: true,
3361 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003362 })
David Benjamind98452d2015-06-16 14:16:23 -04003363 // Test the ticket callback, with and without renewal.
3364 testCases = append(testCases, testCase{
3365 testType: serverTest,
3366 name: "TicketCallback",
3367 resumeSession: true,
3368 flags: []string{"-use-ticket-callback"},
3369 })
3370 testCases = append(testCases, testCase{
3371 testType: serverTest,
3372 name: "TicketCallback-Renew",
3373 config: Config{
3374 Bugs: ProtocolBugs{
3375 ExpectNewTicket: true,
3376 },
3377 },
3378 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3379 resumeSession: true,
3380 })
Adam Langley38311732014-10-16 19:04:35 -07003381 // Resume with an oversized session id.
3382 testCases = append(testCases, testCase{
3383 testType: serverTest,
3384 name: "OversizedSessionId",
3385 config: Config{
3386 Bugs: ProtocolBugs{
3387 OversizedSessionId: true,
3388 },
3389 },
3390 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003391 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003392 expectedError: ":DECODE_ERROR:",
3393 })
David Benjaminca6c8262014-11-15 19:06:08 -05003394 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3395 // are ignored.
3396 testCases = append(testCases, testCase{
3397 protocol: dtls,
3398 name: "SRTP-Client",
3399 config: Config{
3400 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3401 },
3402 flags: []string{
3403 "-srtp-profiles",
3404 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3405 },
3406 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3407 })
3408 testCases = append(testCases, testCase{
3409 protocol: dtls,
3410 testType: serverTest,
3411 name: "SRTP-Server",
3412 config: Config{
3413 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3414 },
3415 flags: []string{
3416 "-srtp-profiles",
3417 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3418 },
3419 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3420 })
3421 // Test that the MKI is ignored.
3422 testCases = append(testCases, testCase{
3423 protocol: dtls,
3424 testType: serverTest,
3425 name: "SRTP-Server-IgnoreMKI",
3426 config: Config{
3427 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3428 Bugs: ProtocolBugs{
3429 SRTPMasterKeyIdentifer: "bogus",
3430 },
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 // Test that SRTP isn't negotiated on the server if there were
3439 // no matching profiles.
3440 testCases = append(testCases, testCase{
3441 protocol: dtls,
3442 testType: serverTest,
3443 name: "SRTP-Server-NoMatch",
3444 config: Config{
3445 SRTPProtectionProfiles: []uint16{100, 101, 102},
3446 },
3447 flags: []string{
3448 "-srtp-profiles",
3449 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3450 },
3451 expectedSRTPProtectionProfile: 0,
3452 })
3453 // Test that the server returning an invalid SRTP profile is
3454 // flagged as an error by the client.
3455 testCases = append(testCases, testCase{
3456 protocol: dtls,
3457 name: "SRTP-Client-NoMatch",
3458 config: Config{
3459 Bugs: ProtocolBugs{
3460 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3461 },
3462 },
3463 flags: []string{
3464 "-srtp-profiles",
3465 "SRTP_AES128_CM_SHA1_80",
3466 },
3467 shouldFail: true,
3468 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3469 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003470 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003471 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003472 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003473 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003474 flags: []string{
3475 "-enable-signed-cert-timestamps",
3476 "-expect-signed-cert-timestamps",
3477 base64.StdEncoding.EncodeToString(testSCTList),
3478 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003479 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003480 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003481 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003482 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003483 testType: serverTest,
3484 flags: []string{
3485 "-signed-cert-timestamps",
3486 base64.StdEncoding.EncodeToString(testSCTList),
3487 },
3488 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003489 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003490 })
3491 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003492 testType: clientTest,
3493 name: "ClientHelloPadding",
3494 config: Config{
3495 Bugs: ProtocolBugs{
3496 RequireClientHelloSize: 512,
3497 },
3498 },
3499 // This hostname just needs to be long enough to push the
3500 // ClientHello into F5's danger zone between 256 and 511 bytes
3501 // long.
3502 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3503 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003504
3505 // Extensions should not function in SSL 3.0.
3506 testCases = append(testCases, testCase{
3507 testType: serverTest,
3508 name: "SSLv3Extensions-NoALPN",
3509 config: Config{
3510 MaxVersion: VersionSSL30,
3511 NextProtos: []string{"foo", "bar", "baz"},
3512 },
3513 flags: []string{
3514 "-select-alpn", "foo",
3515 },
3516 expectNoNextProto: true,
3517 })
3518
3519 // Test session tickets separately as they follow a different codepath.
3520 testCases = append(testCases, testCase{
3521 testType: serverTest,
3522 name: "SSLv3Extensions-NoTickets",
3523 config: Config{
3524 MaxVersion: VersionSSL30,
3525 Bugs: ProtocolBugs{
3526 // Historically, session tickets in SSL 3.0
3527 // failed in different ways depending on whether
3528 // the client supported renegotiation_info.
3529 NoRenegotiationInfo: true,
3530 },
3531 },
3532 resumeSession: true,
3533 })
3534 testCases = append(testCases, testCase{
3535 testType: serverTest,
3536 name: "SSLv3Extensions-NoTickets2",
3537 config: Config{
3538 MaxVersion: VersionSSL30,
3539 },
3540 resumeSession: true,
3541 })
3542
3543 // But SSL 3.0 does send and process renegotiation_info.
3544 testCases = append(testCases, testCase{
3545 testType: serverTest,
3546 name: "SSLv3Extensions-RenegotiationInfo",
3547 config: Config{
3548 MaxVersion: VersionSSL30,
3549 Bugs: ProtocolBugs{
3550 RequireRenegotiationInfo: true,
3551 },
3552 },
3553 })
3554 testCases = append(testCases, testCase{
3555 testType: serverTest,
3556 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3557 config: Config{
3558 MaxVersion: VersionSSL30,
3559 Bugs: ProtocolBugs{
3560 NoRenegotiationInfo: true,
3561 SendRenegotiationSCSV: true,
3562 RequireRenegotiationInfo: true,
3563 },
3564 },
3565 })
David Benjamine78bfde2014-09-06 12:45:15 -04003566}
3567
David Benjamin01fe8202014-09-24 15:21:44 -04003568func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003569 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003570 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003571 protocols := []protocol{tls}
3572 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3573 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003574 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003575 for _, protocol := range protocols {
3576 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3577 if protocol == dtls {
3578 suffix += "-DTLS"
3579 }
3580
David Benjaminece3de92015-03-16 18:02:20 -04003581 if sessionVers.version == resumeVers.version {
3582 testCases = append(testCases, testCase{
3583 protocol: protocol,
3584 name: "Resume-Client" + suffix,
3585 resumeSession: true,
3586 config: Config{
3587 MaxVersion: sessionVers.version,
3588 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003589 },
David Benjaminece3de92015-03-16 18:02:20 -04003590 expectedVersion: sessionVers.version,
3591 expectedResumeVersion: resumeVers.version,
3592 })
3593 } else {
3594 testCases = append(testCases, testCase{
3595 protocol: protocol,
3596 name: "Resume-Client-Mismatch" + suffix,
3597 resumeSession: true,
3598 config: Config{
3599 MaxVersion: sessionVers.version,
3600 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003601 },
David Benjaminece3de92015-03-16 18:02:20 -04003602 expectedVersion: sessionVers.version,
3603 resumeConfig: &Config{
3604 MaxVersion: resumeVers.version,
3605 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3606 Bugs: ProtocolBugs{
3607 AllowSessionVersionMismatch: true,
3608 },
3609 },
3610 expectedResumeVersion: resumeVers.version,
3611 shouldFail: true,
3612 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3613 })
3614 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003615
3616 testCases = append(testCases, testCase{
3617 protocol: protocol,
3618 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003619 resumeSession: true,
3620 config: Config{
3621 MaxVersion: sessionVers.version,
3622 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3623 },
3624 expectedVersion: sessionVers.version,
3625 resumeConfig: &Config{
3626 MaxVersion: resumeVers.version,
3627 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3628 },
3629 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003630 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003631 expectedResumeVersion: resumeVers.version,
3632 })
3633
David Benjamin8b8c0062014-11-23 02:47:52 -05003634 testCases = append(testCases, testCase{
3635 protocol: protocol,
3636 testType: serverTest,
3637 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003638 resumeSession: true,
3639 config: Config{
3640 MaxVersion: sessionVers.version,
3641 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3642 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003643 expectedVersion: sessionVers.version,
3644 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003645 resumeConfig: &Config{
3646 MaxVersion: resumeVers.version,
3647 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3648 },
3649 expectedResumeVersion: resumeVers.version,
3650 })
3651 }
David Benjamin01fe8202014-09-24 15:21:44 -04003652 }
3653 }
David Benjaminece3de92015-03-16 18:02:20 -04003654
3655 testCases = append(testCases, testCase{
3656 name: "Resume-Client-CipherMismatch",
3657 resumeSession: true,
3658 config: Config{
3659 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3660 },
3661 resumeConfig: &Config{
3662 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3663 Bugs: ProtocolBugs{
3664 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3665 },
3666 },
3667 shouldFail: true,
3668 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3669 })
David Benjamin01fe8202014-09-24 15:21:44 -04003670}
3671
Adam Langley2ae77d22014-10-28 17:29:33 -07003672func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003673 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003674 testCases = append(testCases, testCase{
3675 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003676 name: "Renegotiate-Server-Forbidden",
David Benjaminb16346b2015-04-08 19:16:58 -04003677 renegotiate: true,
3678 flags: []string{"-reject-peer-renegotiations"},
3679 shouldFail: true,
3680 expectedError: ":NO_RENEGOTIATION:",
3681 expectedLocalError: "remote error: no renegotiation",
3682 })
Adam Langley5021b222015-06-12 18:27:58 -07003683 // The server shouldn't echo the renegotiation extension unless
3684 // requested by the client.
3685 testCases = append(testCases, testCase{
3686 testType: serverTest,
3687 name: "Renegotiate-Server-NoExt",
3688 config: Config{
3689 Bugs: ProtocolBugs{
3690 NoRenegotiationInfo: true,
3691 RequireRenegotiationInfo: true,
3692 },
3693 },
3694 shouldFail: true,
3695 expectedLocalError: "renegotiation extension missing",
3696 })
3697 // The renegotiation SCSV should be sufficient for the server to echo
3698 // the extension.
3699 testCases = append(testCases, testCase{
3700 testType: serverTest,
3701 name: "Renegotiate-Server-NoExt-SCSV",
3702 config: Config{
3703 Bugs: ProtocolBugs{
3704 NoRenegotiationInfo: true,
3705 SendRenegotiationSCSV: true,
3706 RequireRenegotiationInfo: true,
3707 },
3708 },
3709 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003710 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003711 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003712 config: Config{
3713 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003714 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003715 },
3716 },
3717 renegotiate: true,
3718 })
3719 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003720 name: "Renegotiate-Client-EmptyExt",
3721 renegotiate: true,
3722 config: Config{
3723 Bugs: ProtocolBugs{
3724 EmptyRenegotiationInfo: true,
3725 },
3726 },
3727 shouldFail: true,
3728 expectedError: ":RENEGOTIATION_MISMATCH:",
3729 })
3730 testCases = append(testCases, testCase{
3731 name: "Renegotiate-Client-BadExt",
3732 renegotiate: true,
3733 config: Config{
3734 Bugs: ProtocolBugs{
3735 BadRenegotiationInfo: true,
3736 },
3737 },
3738 shouldFail: true,
3739 expectedError: ":RENEGOTIATION_MISMATCH:",
3740 })
3741 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003742 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003743 config: Config{
3744 Bugs: ProtocolBugs{
3745 NoRenegotiationInfo: true,
3746 },
3747 },
3748 shouldFail: true,
3749 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3750 flags: []string{"-no-legacy-server-connect"},
3751 })
3752 testCases = append(testCases, testCase{
3753 name: "Renegotiate-Client-NoExt-Allowed",
3754 renegotiate: true,
3755 config: Config{
3756 Bugs: ProtocolBugs{
3757 NoRenegotiationInfo: true,
3758 },
3759 },
3760 })
3761 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003762 name: "Renegotiate-Client-SwitchCiphers",
3763 renegotiate: true,
3764 config: Config{
3765 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3766 },
3767 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3768 })
3769 testCases = append(testCases, testCase{
3770 name: "Renegotiate-Client-SwitchCiphers2",
3771 renegotiate: true,
3772 config: Config{
3773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3774 },
3775 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3776 })
David Benjaminc44b1df2014-11-23 12:11:01 -05003777 testCases = append(testCases, testCase{
David Benjaminb16346b2015-04-08 19:16:58 -04003778 name: "Renegotiate-Client-Forbidden",
3779 renegotiate: true,
3780 flags: []string{"-reject-peer-renegotiations"},
3781 shouldFail: true,
3782 expectedError: ":NO_RENEGOTIATION:",
3783 expectedLocalError: "remote error: no renegotiation",
3784 })
3785 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003786 name: "Renegotiate-SameClientVersion",
3787 renegotiate: true,
3788 config: Config{
3789 MaxVersion: VersionTLS10,
3790 Bugs: ProtocolBugs{
3791 RequireSameRenegoClientVersion: true,
3792 },
3793 },
3794 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003795 testCases = append(testCases, testCase{
3796 name: "Renegotiate-FalseStart",
3797 renegotiate: true,
3798 config: Config{
3799 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3800 NextProtos: []string{"foo"},
3801 },
3802 flags: []string{
3803 "-false-start",
3804 "-select-next-proto", "foo",
3805 },
3806 shimWritesFirst: true,
3807 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003808}
3809
David Benjamin5e961c12014-11-07 01:48:35 -05003810func addDTLSReplayTests() {
3811 // Test that sequence number replays are detected.
3812 testCases = append(testCases, testCase{
3813 protocol: dtls,
3814 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003815 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003816 replayWrites: true,
3817 })
3818
David Benjamin8e6db492015-07-25 18:29:23 -04003819 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003820 // than the retransmit window.
3821 testCases = append(testCases, testCase{
3822 protocol: dtls,
3823 name: "DTLS-Replay-LargeGaps",
3824 config: Config{
3825 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003826 SequenceNumberMapping: func(in uint64) uint64 {
3827 return in * 127
3828 },
David Benjamin5e961c12014-11-07 01:48:35 -05003829 },
3830 },
David Benjamin8e6db492015-07-25 18:29:23 -04003831 messageCount: 200,
3832 replayWrites: true,
3833 })
3834
3835 // Test the incoming sequence number changing non-monotonically.
3836 testCases = append(testCases, testCase{
3837 protocol: dtls,
3838 name: "DTLS-Replay-NonMonotonic",
3839 config: Config{
3840 Bugs: ProtocolBugs{
3841 SequenceNumberMapping: func(in uint64) uint64 {
3842 return in ^ 31
3843 },
3844 },
3845 },
3846 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003847 replayWrites: true,
3848 })
3849}
3850
David Benjamin000800a2014-11-14 01:43:59 -05003851var testHashes = []struct {
3852 name string
3853 id uint8
3854}{
3855 {"SHA1", hashSHA1},
3856 {"SHA224", hashSHA224},
3857 {"SHA256", hashSHA256},
3858 {"SHA384", hashSHA384},
3859 {"SHA512", hashSHA512},
3860}
3861
3862func addSigningHashTests() {
3863 // Make sure each hash works. Include some fake hashes in the list and
3864 // ensure they're ignored.
3865 for _, hash := range testHashes {
3866 testCases = append(testCases, testCase{
3867 name: "SigningHash-ClientAuth-" + hash.name,
3868 config: Config{
3869 ClientAuth: RequireAnyClientCert,
3870 SignatureAndHashes: []signatureAndHash{
3871 {signatureRSA, 42},
3872 {signatureRSA, hash.id},
3873 {signatureRSA, 255},
3874 },
3875 },
3876 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003877 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3878 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003879 },
3880 })
3881
3882 testCases = append(testCases, testCase{
3883 testType: serverTest,
3884 name: "SigningHash-ServerKeyExchange-Sign-" + hash.name,
3885 config: Config{
3886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3887 SignatureAndHashes: []signatureAndHash{
3888 {signatureRSA, 42},
3889 {signatureRSA, hash.id},
3890 {signatureRSA, 255},
3891 },
3892 },
3893 })
3894 }
3895
3896 // Test that hash resolution takes the signature type into account.
3897 testCases = append(testCases, testCase{
3898 name: "SigningHash-ClientAuth-SignatureType",
3899 config: Config{
3900 ClientAuth: RequireAnyClientCert,
3901 SignatureAndHashes: []signatureAndHash{
3902 {signatureECDSA, hashSHA512},
3903 {signatureRSA, hashSHA384},
3904 {signatureECDSA, hashSHA1},
3905 },
3906 },
3907 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003908 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3909 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003910 },
3911 })
3912
3913 testCases = append(testCases, testCase{
3914 testType: serverTest,
3915 name: "SigningHash-ServerKeyExchange-SignatureType",
3916 config: Config{
3917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3918 SignatureAndHashes: []signatureAndHash{
3919 {signatureECDSA, hashSHA512},
3920 {signatureRSA, hashSHA384},
3921 {signatureECDSA, hashSHA1},
3922 },
3923 },
3924 })
3925
3926 // Test that, if the list is missing, the peer falls back to SHA-1.
3927 testCases = append(testCases, testCase{
3928 name: "SigningHash-ClientAuth-Fallback",
3929 config: Config{
3930 ClientAuth: RequireAnyClientCert,
3931 SignatureAndHashes: []signatureAndHash{
3932 {signatureRSA, hashSHA1},
3933 },
3934 Bugs: ProtocolBugs{
3935 NoSignatureAndHashes: true,
3936 },
3937 },
3938 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003939 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3940 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003941 },
3942 })
3943
3944 testCases = append(testCases, testCase{
3945 testType: serverTest,
3946 name: "SigningHash-ServerKeyExchange-Fallback",
3947 config: Config{
3948 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3949 SignatureAndHashes: []signatureAndHash{
3950 {signatureRSA, hashSHA1},
3951 },
3952 Bugs: ProtocolBugs{
3953 NoSignatureAndHashes: true,
3954 },
3955 },
3956 })
David Benjamin72dc7832015-03-16 17:49:43 -04003957
3958 // Test that hash preferences are enforced. BoringSSL defaults to
3959 // rejecting MD5 signatures.
3960 testCases = append(testCases, testCase{
3961 testType: serverTest,
3962 name: "SigningHash-ClientAuth-Enforced",
3963 config: Config{
3964 Certificates: []Certificate{rsaCertificate},
3965 SignatureAndHashes: []signatureAndHash{
3966 {signatureRSA, hashMD5},
3967 // Advertise SHA-1 so the handshake will
3968 // proceed, but the shim's preferences will be
3969 // ignored in CertificateVerify generation, so
3970 // MD5 will be chosen.
3971 {signatureRSA, hashSHA1},
3972 },
3973 Bugs: ProtocolBugs{
3974 IgnorePeerSignatureAlgorithmPreferences: true,
3975 },
3976 },
3977 flags: []string{"-require-any-client-certificate"},
3978 shouldFail: true,
3979 expectedError: ":WRONG_SIGNATURE_TYPE:",
3980 })
3981
3982 testCases = append(testCases, testCase{
3983 name: "SigningHash-ServerKeyExchange-Enforced",
3984 config: Config{
3985 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3986 SignatureAndHashes: []signatureAndHash{
3987 {signatureRSA, hashMD5},
3988 },
3989 Bugs: ProtocolBugs{
3990 IgnorePeerSignatureAlgorithmPreferences: true,
3991 },
3992 },
3993 shouldFail: true,
3994 expectedError: ":WRONG_SIGNATURE_TYPE:",
3995 })
Steven Valdez0d62f262015-09-04 12:41:04 -04003996
3997 // Test that the agreed upon digest respects the client preferences and
3998 // the server digests.
3999 testCases = append(testCases, testCase{
4000 name: "Agree-Digest-Fallback",
4001 config: Config{
4002 ClientAuth: RequireAnyClientCert,
4003 SignatureAndHashes: []signatureAndHash{
4004 {signatureRSA, hashSHA512},
4005 {signatureRSA, hashSHA1},
4006 },
4007 },
4008 flags: []string{
4009 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4010 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4011 },
4012 digestPrefs: "SHA256",
4013 expectedClientCertSignatureHash: hashSHA1,
4014 })
4015 testCases = append(testCases, testCase{
4016 name: "Agree-Digest-SHA256",
4017 config: Config{
4018 ClientAuth: RequireAnyClientCert,
4019 SignatureAndHashes: []signatureAndHash{
4020 {signatureRSA, hashSHA1},
4021 {signatureRSA, hashSHA256},
4022 },
4023 },
4024 flags: []string{
4025 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4026 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4027 },
4028 digestPrefs: "SHA256,SHA1",
4029 expectedClientCertSignatureHash: hashSHA256,
4030 })
4031 testCases = append(testCases, testCase{
4032 name: "Agree-Digest-SHA1",
4033 config: Config{
4034 ClientAuth: RequireAnyClientCert,
4035 SignatureAndHashes: []signatureAndHash{
4036 {signatureRSA, hashSHA1},
4037 },
4038 },
4039 flags: []string{
4040 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4041 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4042 },
4043 digestPrefs: "SHA512,SHA256,SHA1",
4044 expectedClientCertSignatureHash: hashSHA1,
4045 })
4046 testCases = append(testCases, testCase{
4047 name: "Agree-Digest-Default",
4048 config: Config{
4049 ClientAuth: RequireAnyClientCert,
4050 SignatureAndHashes: []signatureAndHash{
4051 {signatureRSA, hashSHA256},
4052 {signatureECDSA, hashSHA256},
4053 {signatureRSA, hashSHA1},
4054 {signatureECDSA, hashSHA1},
4055 },
4056 },
4057 flags: []string{
4058 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4059 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4060 },
4061 expectedClientCertSignatureHash: hashSHA256,
4062 })
David Benjamin000800a2014-11-14 01:43:59 -05004063}
4064
David Benjamin83f90402015-01-27 01:09:43 -05004065// timeouts is the retransmit schedule for BoringSSL. It doubles and
4066// caps at 60 seconds. On the 13th timeout, it gives up.
4067var timeouts = []time.Duration{
4068 1 * time.Second,
4069 2 * time.Second,
4070 4 * time.Second,
4071 8 * time.Second,
4072 16 * time.Second,
4073 32 * time.Second,
4074 60 * time.Second,
4075 60 * time.Second,
4076 60 * time.Second,
4077 60 * time.Second,
4078 60 * time.Second,
4079 60 * time.Second,
4080 60 * time.Second,
4081}
4082
4083func addDTLSRetransmitTests() {
4084 // Test that this is indeed the timeout schedule. Stress all
4085 // four patterns of handshake.
4086 for i := 1; i < len(timeouts); i++ {
4087 number := strconv.Itoa(i)
4088 testCases = append(testCases, testCase{
4089 protocol: dtls,
4090 name: "DTLS-Retransmit-Client-" + number,
4091 config: Config{
4092 Bugs: ProtocolBugs{
4093 TimeoutSchedule: timeouts[:i],
4094 },
4095 },
4096 resumeSession: true,
4097 flags: []string{"-async"},
4098 })
4099 testCases = append(testCases, testCase{
4100 protocol: dtls,
4101 testType: serverTest,
4102 name: "DTLS-Retransmit-Server-" + number,
4103 config: Config{
4104 Bugs: ProtocolBugs{
4105 TimeoutSchedule: timeouts[:i],
4106 },
4107 },
4108 resumeSession: true,
4109 flags: []string{"-async"},
4110 })
4111 }
4112
4113 // Test that exceeding the timeout schedule hits a read
4114 // timeout.
4115 testCases = append(testCases, testCase{
4116 protocol: dtls,
4117 name: "DTLS-Retransmit-Timeout",
4118 config: Config{
4119 Bugs: ProtocolBugs{
4120 TimeoutSchedule: timeouts,
4121 },
4122 },
4123 resumeSession: true,
4124 flags: []string{"-async"},
4125 shouldFail: true,
4126 expectedError: ":READ_TIMEOUT_EXPIRED:",
4127 })
4128
4129 // Test that timeout handling has a fudge factor, due to API
4130 // problems.
4131 testCases = append(testCases, testCase{
4132 protocol: dtls,
4133 name: "DTLS-Retransmit-Fudge",
4134 config: Config{
4135 Bugs: ProtocolBugs{
4136 TimeoutSchedule: []time.Duration{
4137 timeouts[0] - 10*time.Millisecond,
4138 },
4139 },
4140 },
4141 resumeSession: true,
4142 flags: []string{"-async"},
4143 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004144
4145 // Test that the final Finished retransmitting isn't
4146 // duplicated if the peer badly fragments everything.
4147 testCases = append(testCases, testCase{
4148 testType: serverTest,
4149 protocol: dtls,
4150 name: "DTLS-Retransmit-Fragmented",
4151 config: Config{
4152 Bugs: ProtocolBugs{
4153 TimeoutSchedule: []time.Duration{timeouts[0]},
4154 MaxHandshakeRecordLength: 2,
4155 },
4156 },
4157 flags: []string{"-async"},
4158 })
David Benjamin83f90402015-01-27 01:09:43 -05004159}
4160
David Benjaminc565ebb2015-04-03 04:06:36 -04004161func addExportKeyingMaterialTests() {
4162 for _, vers := range tlsVersions {
4163 if vers.version == VersionSSL30 {
4164 continue
4165 }
4166 testCases = append(testCases, testCase{
4167 name: "ExportKeyingMaterial-" + vers.name,
4168 config: Config{
4169 MaxVersion: vers.version,
4170 },
4171 exportKeyingMaterial: 1024,
4172 exportLabel: "label",
4173 exportContext: "context",
4174 useExportContext: true,
4175 })
4176 testCases = append(testCases, testCase{
4177 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4178 config: Config{
4179 MaxVersion: vers.version,
4180 },
4181 exportKeyingMaterial: 1024,
4182 })
4183 testCases = append(testCases, testCase{
4184 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4185 config: Config{
4186 MaxVersion: vers.version,
4187 },
4188 exportKeyingMaterial: 1024,
4189 useExportContext: true,
4190 })
4191 testCases = append(testCases, testCase{
4192 name: "ExportKeyingMaterial-Small-" + vers.name,
4193 config: Config{
4194 MaxVersion: vers.version,
4195 },
4196 exportKeyingMaterial: 1,
4197 exportLabel: "label",
4198 exportContext: "context",
4199 useExportContext: true,
4200 })
4201 }
4202 testCases = append(testCases, testCase{
4203 name: "ExportKeyingMaterial-SSL3",
4204 config: Config{
4205 MaxVersion: VersionSSL30,
4206 },
4207 exportKeyingMaterial: 1024,
4208 exportLabel: "label",
4209 exportContext: "context",
4210 useExportContext: true,
4211 shouldFail: true,
4212 expectedError: "failed to export keying material",
4213 })
4214}
4215
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004216func addTLSUniqueTests() {
4217 for _, isClient := range []bool{false, true} {
4218 for _, isResumption := range []bool{false, true} {
4219 for _, hasEMS := range []bool{false, true} {
4220 var suffix string
4221 if isResumption {
4222 suffix = "Resume-"
4223 } else {
4224 suffix = "Full-"
4225 }
4226
4227 if hasEMS {
4228 suffix += "EMS-"
4229 } else {
4230 suffix += "NoEMS-"
4231 }
4232
4233 if isClient {
4234 suffix += "Client"
4235 } else {
4236 suffix += "Server"
4237 }
4238
4239 test := testCase{
4240 name: "TLSUnique-" + suffix,
4241 testTLSUnique: true,
4242 config: Config{
4243 Bugs: ProtocolBugs{
4244 NoExtendedMasterSecret: !hasEMS,
4245 },
4246 },
4247 }
4248
4249 if isResumption {
4250 test.resumeSession = true
4251 test.resumeConfig = &Config{
4252 Bugs: ProtocolBugs{
4253 NoExtendedMasterSecret: !hasEMS,
4254 },
4255 }
4256 }
4257
4258 if isResumption && !hasEMS {
4259 test.shouldFail = true
4260 test.expectedError = "failed to get tls-unique"
4261 }
4262
4263 testCases = append(testCases, test)
4264 }
4265 }
4266 }
4267}
4268
Adam Langley09505632015-07-30 18:10:13 -07004269func addCustomExtensionTests() {
4270 expectedContents := "custom extension"
4271 emptyString := ""
4272
4273 for _, isClient := range []bool{false, true} {
4274 suffix := "Server"
4275 flag := "-enable-server-custom-extension"
4276 testType := serverTest
4277 if isClient {
4278 suffix = "Client"
4279 flag = "-enable-client-custom-extension"
4280 testType = clientTest
4281 }
4282
4283 testCases = append(testCases, testCase{
4284 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004285 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004286 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004287 Bugs: ProtocolBugs{
4288 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004289 ExpectedCustomExtension: &expectedContents,
4290 },
4291 },
4292 flags: []string{flag},
4293 })
4294
4295 // If the parse callback fails, the handshake should also fail.
4296 testCases = append(testCases, testCase{
4297 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004298 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004299 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004300 Bugs: ProtocolBugs{
4301 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004302 ExpectedCustomExtension: &expectedContents,
4303 },
4304 },
David Benjamin399e7c92015-07-30 23:01:27 -04004305 flags: []string{flag},
4306 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004307 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4308 })
4309
4310 // If the add callback fails, the handshake should also fail.
4311 testCases = append(testCases, testCase{
4312 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004313 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004314 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004315 Bugs: ProtocolBugs{
4316 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004317 ExpectedCustomExtension: &expectedContents,
4318 },
4319 },
David Benjamin399e7c92015-07-30 23:01:27 -04004320 flags: []string{flag, "-custom-extension-fail-add"},
4321 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004322 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4323 })
4324
4325 // If the add callback returns zero, no extension should be
4326 // added.
4327 skipCustomExtension := expectedContents
4328 if isClient {
4329 // For the case where the client skips sending the
4330 // custom extension, the server must not “echo” it.
4331 skipCustomExtension = ""
4332 }
4333 testCases = append(testCases, testCase{
4334 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004335 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004336 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004337 Bugs: ProtocolBugs{
4338 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004339 ExpectedCustomExtension: &emptyString,
4340 },
4341 },
4342 flags: []string{flag, "-custom-extension-skip"},
4343 })
4344 }
4345
4346 // The custom extension add callback should not be called if the client
4347 // doesn't send the extension.
4348 testCases = append(testCases, testCase{
4349 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004350 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004351 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004352 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004353 ExpectedCustomExtension: &emptyString,
4354 },
4355 },
4356 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4357 })
Adam Langley2deb9842015-08-07 11:15:37 -07004358
4359 // Test an unknown extension from the server.
4360 testCases = append(testCases, testCase{
4361 testType: clientTest,
4362 name: "UnknownExtension-Client",
4363 config: Config{
4364 Bugs: ProtocolBugs{
4365 CustomExtension: expectedContents,
4366 },
4367 },
4368 shouldFail: true,
4369 expectedError: ":UNEXPECTED_EXTENSION:",
4370 })
Adam Langley09505632015-07-30 18:10:13 -07004371}
4372
Adam Langley7c803a62015-06-15 15:35:05 -07004373func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004374 defer wg.Done()
4375
4376 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004377 var err error
4378
4379 if *mallocTest < 0 {
4380 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004381 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004382 } else {
4383 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4384 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004385 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004386 if err != nil {
4387 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4388 }
4389 break
4390 }
4391 }
4392 }
Adam Langley95c29f32014-06-20 12:00:00 -07004393 statusChan <- statusMsg{test: test, err: err}
4394 }
4395}
4396
4397type statusMsg struct {
4398 test *testCase
4399 started bool
4400 err error
4401}
4402
David Benjamin5f237bc2015-02-11 17:14:15 -05004403func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004404 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004405
David Benjamin5f237bc2015-02-11 17:14:15 -05004406 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004407 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004408 if !*pipe {
4409 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004410 var erase string
4411 for i := 0; i < lineLen; i++ {
4412 erase += "\b \b"
4413 }
4414 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004415 }
4416
Adam Langley95c29f32014-06-20 12:00:00 -07004417 if msg.started {
4418 started++
4419 } else {
4420 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004421
4422 if msg.err != nil {
4423 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4424 failed++
4425 testOutput.addResult(msg.test.name, "FAIL")
4426 } else {
4427 if *pipe {
4428 // Print each test instead of a status line.
4429 fmt.Printf("PASSED (%s)\n", msg.test.name)
4430 }
4431 testOutput.addResult(msg.test.name, "PASS")
4432 }
Adam Langley95c29f32014-06-20 12:00:00 -07004433 }
4434
David Benjamin5f237bc2015-02-11 17:14:15 -05004435 if !*pipe {
4436 // Print a new status line.
4437 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4438 lineLen = len(line)
4439 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004440 }
Adam Langley95c29f32014-06-20 12:00:00 -07004441 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004442
4443 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004444}
4445
4446func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004447 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004448 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004449
Adam Langley7c803a62015-06-15 15:35:05 -07004450 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004451 addCipherSuiteTests()
4452 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004453 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004454 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004455 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004456 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004457 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004458 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004459 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004460 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004461 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004462 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004463 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004464 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004465 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004466 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004467 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004468 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004469 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004470 for _, async := range []bool{false, true} {
4471 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004472 for _, protocol := range []protocol{tls, dtls} {
4473 addStateMachineCoverageTests(async, splitHandshake, protocol)
4474 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004475 }
4476 }
Adam Langley95c29f32014-06-20 12:00:00 -07004477
4478 var wg sync.WaitGroup
4479
Adam Langley7c803a62015-06-15 15:35:05 -07004480 statusChan := make(chan statusMsg, *numWorkers)
4481 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004482 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004483
David Benjamin025b3d32014-07-01 19:53:04 -04004484 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004485
Adam Langley7c803a62015-06-15 15:35:05 -07004486 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004487 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004488 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004489 }
4490
David Benjamin025b3d32014-07-01 19:53:04 -04004491 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004492 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004493 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004494 }
4495 }
4496
4497 close(testChan)
4498 wg.Wait()
4499 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004500 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004501
4502 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004503
4504 if *jsonOutput != "" {
4505 if err := testOutput.writeTo(*jsonOutput); err != nil {
4506 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4507 }
4508 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004509
4510 if !testOutput.allPassed {
4511 os.Exit(1)
4512 }
Adam Langley95c29f32014-06-20 12:00:00 -07004513}