blob: 189854ef8cf2dcaf0385fe3de5e8c744cb95a895 [file] [log] [blame]
Adam Langleydc7e9c42015-09-29 15:21:04 -07001package runner
Adam Langley95c29f32014-06-20 12:00:00 -07002
3import (
4 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -04005 "crypto/ecdsa"
6 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -04007 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -04008 "encoding/base64"
David Benjamina08e49d2014-08-24 01:46:07 -04009 "encoding/pem"
Adam Langley95c29f32014-06-20 12:00:00 -070010 "flag"
11 "fmt"
12 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070013 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070014 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070015 "net"
16 "os"
17 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040018 "path"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040019 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080020 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070021 "strings"
22 "sync"
23 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050024 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070025)
26
Adam Langley69a01602014-11-17 17:26:55 -080027var (
David Benjamin5f237bc2015-02-11 17:14:15 -050028 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
29 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
30 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
31 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
32 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
33 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
34 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
Adam Langley7c803a62015-06-15 15:35:05 -070035 testToRun = flag.String("test", "", "The name of a test to run, or empty to run all tests")
36 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
37 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
38 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
Adam Langley69a01602014-11-17 17:26:55 -080039)
Adam Langley95c29f32014-06-20 12:00:00 -070040
David Benjamin025b3d32014-07-01 19:53:04 -040041const (
42 rsaCertificateFile = "cert.pem"
43 ecdsaCertificateFile = "ecdsa_cert.pem"
44)
45
46const (
David Benjamina08e49d2014-08-24 01:46:07 -040047 rsaKeyFile = "key.pem"
48 ecdsaKeyFile = "ecdsa_key.pem"
49 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -040050)
51
Adam Langley95c29f32014-06-20 12:00:00 -070052var rsaCertificate, ecdsaCertificate Certificate
David Benjamina08e49d2014-08-24 01:46:07 -040053var channelIDKey *ecdsa.PrivateKey
54var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -070055
David Benjamin61f95272014-11-25 01:55:35 -050056var testOCSPResponse = []byte{1, 2, 3, 4}
57var testSCTList = []byte{5, 6, 7, 8}
58
Adam Langley95c29f32014-06-20 12:00:00 -070059func initCertificates() {
60 var err error
Adam Langley7c803a62015-06-15 15:35:05 -070061 rsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, rsaCertificateFile), path.Join(*resourceDir, rsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070062 if err != nil {
63 panic(err)
64 }
David Benjamin61f95272014-11-25 01:55:35 -050065 rsaCertificate.OCSPStaple = testOCSPResponse
66 rsaCertificate.SignedCertificateTimestampList = testSCTList
Adam Langley95c29f32014-06-20 12:00:00 -070067
Adam Langley7c803a62015-06-15 15:35:05 -070068 ecdsaCertificate, err = LoadX509KeyPair(path.Join(*resourceDir, ecdsaCertificateFile), path.Join(*resourceDir, ecdsaKeyFile))
Adam Langley95c29f32014-06-20 12:00:00 -070069 if err != nil {
70 panic(err)
71 }
David Benjamin61f95272014-11-25 01:55:35 -050072 ecdsaCertificate.OCSPStaple = testOCSPResponse
73 ecdsaCertificate.SignedCertificateTimestampList = testSCTList
David Benjamina08e49d2014-08-24 01:46:07 -040074
Adam Langley7c803a62015-06-15 15:35:05 -070075 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -040076 if err != nil {
77 panic(err)
78 }
79 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
80 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
81 panic("bad key type")
82 }
83 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
84 if err != nil {
85 panic(err)
86 }
87 if channelIDKey.Curve != elliptic.P256() {
88 panic("bad curve")
89 }
90
91 channelIDBytes = make([]byte, 64)
92 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
93 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -070094}
95
96var certificateOnce sync.Once
97
98func getRSACertificate() Certificate {
99 certificateOnce.Do(initCertificates)
100 return rsaCertificate
101}
102
103func getECDSACertificate() Certificate {
104 certificateOnce.Do(initCertificates)
105 return ecdsaCertificate
106}
107
David Benjamin025b3d32014-07-01 19:53:04 -0400108type testType int
109
110const (
111 clientTest testType = iota
112 serverTest
113)
114
David Benjamin6fd297b2014-08-11 18:43:38 -0400115type protocol int
116
117const (
118 tls protocol = iota
119 dtls
120)
121
David Benjaminfc7b0862014-09-06 13:21:53 -0400122const (
123 alpn = 1
124 npn = 2
125)
126
Adam Langley95c29f32014-06-20 12:00:00 -0700127type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400128 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400129 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700130 name string
131 config Config
132 shouldFail bool
133 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700134 // expectedLocalError, if not empty, contains a substring that must be
135 // found in the local error.
136 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400137 // expectedVersion, if non-zero, specifies the TLS version that must be
138 // negotiated.
139 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400140 // expectedResumeVersion, if non-zero, specifies the TLS version that
141 // must be negotiated on resumption. If zero, expectedVersion is used.
142 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400143 // expectedCipher, if non-zero, specifies the TLS cipher suite that
144 // should be negotiated.
145 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400146 // expectChannelID controls whether the connection should have
147 // negotiated a Channel ID with channelIDKey.
148 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400149 // expectedNextProto controls whether the connection should
150 // negotiate a next protocol via NPN or ALPN.
151 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400152 // expectNoNextProto, if true, means that no next protocol should be
153 // negotiated.
154 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400155 // expectedNextProtoType, if non-zero, is the expected next
156 // protocol negotiation mechanism.
157 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500158 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
159 // should be negotiated. If zero, none should be negotiated.
160 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100161 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
162 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100163 // expectedSCTList, if not nil, is the expected SCT list to be received.
164 expectedSCTList []uint8
Steven Valdez0d62f262015-09-04 12:41:04 -0400165 // expectedClientCertSignatureHash, if not zero, is the TLS id of the
166 // hash function that the client should have used when signing the
167 // handshake with a client certificate.
168 expectedClientCertSignatureHash uint8
Adam Langley80842bd2014-06-20 12:00:00 -0700169 // messageLen is the length, in bytes, of the test message that will be
170 // sent.
171 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400172 // messageCount is the number of test messages that will be sent.
173 messageCount int
Steven Valdez0d62f262015-09-04 12:41:04 -0400174 // digestPrefs is the list of digest preferences from the client.
175 digestPrefs string
David Benjamin025b3d32014-07-01 19:53:04 -0400176 // certFile is the path to the certificate to use for the server.
177 certFile string
178 // keyFile is the path to the private key to use for the server.
179 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400180 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400181 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400182 resumeSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700183 // expectResumeRejected, if true, specifies that the attempted
184 // resumption must be rejected by the client. This is only valid for a
185 // serverTest.
186 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400187 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500188 // resumption. Unless newSessionsOnResume is set,
189 // SessionTicketKey, ServerSessionCache, and
190 // ClientSessionCache are copied from the initial connection's
191 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400192 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500193 // newSessionsOnResume, if true, will cause resumeConfig to
194 // use a different session resumption context.
195 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400196 // noSessionCache, if true, will cause the server to run without a
197 // session cache.
198 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400199 // sendPrefix sends a prefix on the socket before actually performing a
200 // handshake.
201 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400202 // shimWritesFirst controls whether the shim sends an initial "hello"
203 // message before doing a roundtrip with the runner.
204 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400205 // shimShutsDown, if true, runs a test where the shim shuts down the
206 // connection immediately after the handshake rather than echoing
207 // messages from the runner.
208 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400209 // renegotiate indicates the number of times the connection should be
210 // renegotiated during the exchange.
211 renegotiate int
Adam Langleycf2d4f42014-10-28 19:06:14 -0700212 // renegotiateCiphers is a list of ciphersuite ids that will be
213 // switched in just before renegotiation.
214 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500215 // replayWrites, if true, configures the underlying transport
216 // to replay every write it makes in DTLS tests.
217 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500218 // damageFirstWrite, if true, configures the underlying transport to
219 // damage the final byte of the first application data write.
220 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400221 // exportKeyingMaterial, if non-zero, configures the test to exchange
222 // keying material and verify they match.
223 exportKeyingMaterial int
224 exportLabel string
225 exportContext string
226 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400227 // flags, if not empty, contains a list of command-line flags that will
228 // be passed to the shim program.
229 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700230 // testTLSUnique, if true, causes the shim to send the tls-unique value
231 // which will be compared against the expected value.
232 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400233 // sendEmptyRecords is the number of consecutive empty records to send
234 // before and after the test message.
235 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400236 // sendWarningAlerts is the number of consecutive warning alerts to send
237 // before and after the test message.
238 sendWarningAlerts int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400239 // expectMessageDropped, if true, means the test message is expected to
240 // be dropped by the client rather than echoed back.
241 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700242}
243
Adam Langley7c803a62015-06-15 15:35:05 -0700244var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700245
David Benjamin8e6db492015-07-25 18:29:23 -0400246func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamin65ea8ff2014-11-23 03:01:00 -0500247 var connDebug *recordingConn
David Benjamin5fa3eba2015-01-22 16:35:40 -0500248 var connDamage *damageAdaptor
David Benjamin65ea8ff2014-11-23 03:01:00 -0500249 if *flagDebug {
250 connDebug = &recordingConn{Conn: conn}
251 conn = connDebug
252 defer func() {
253 connDebug.WriteTo(os.Stdout)
254 }()
255 }
256
David Benjamin6fd297b2014-08-11 18:43:38 -0400257 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500258 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
259 conn = config.Bugs.PacketAdaptor
David Benjamin5e961c12014-11-07 01:48:35 -0500260 if test.replayWrites {
261 conn = newReplayAdaptor(conn)
262 }
David Benjamin6fd297b2014-08-11 18:43:38 -0400263 }
264
David Benjamin5fa3eba2015-01-22 16:35:40 -0500265 if test.damageFirstWrite {
266 connDamage = newDamageAdaptor(conn)
267 conn = connDamage
268 }
269
David Benjamin6fd297b2014-08-11 18:43:38 -0400270 if test.sendPrefix != "" {
271 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
272 return err
273 }
David Benjamin98e882e2014-08-08 13:24:34 -0400274 }
275
David Benjamin1d5c83e2014-07-22 19:20:02 -0400276 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400277 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400278 if test.protocol == dtls {
279 tlsConn = DTLSServer(conn, config)
280 } else {
281 tlsConn = Server(conn, config)
282 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400283 } else {
284 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400285 if test.protocol == dtls {
286 tlsConn = DTLSClient(conn, config)
287 } else {
288 tlsConn = Client(conn, config)
289 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400290 }
David Benjamin30789da2015-08-29 22:56:45 -0400291 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400292
Adam Langley95c29f32014-06-20 12:00:00 -0700293 if err := tlsConn.Handshake(); err != nil {
294 return err
295 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700296
David Benjamin01fe8202014-09-24 15:21:44 -0400297 // TODO(davidben): move all per-connection expectations into a dedicated
298 // expectations struct that can be specified separately for the two
299 // legs.
300 expectedVersion := test.expectedVersion
301 if isResume && test.expectedResumeVersion != 0 {
302 expectedVersion = test.expectedResumeVersion
303 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700304 connState := tlsConn.ConnectionState()
305 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400306 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400307 }
308
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700309 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400310 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
311 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700312 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
313 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
314 }
David Benjamin90da8c82015-04-20 14:57:57 -0400315
David Benjamina08e49d2014-08-24 01:46:07 -0400316 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700317 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400318 if channelID == nil {
319 return fmt.Errorf("no channel ID negotiated")
320 }
321 if channelID.Curve != channelIDKey.Curve ||
322 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
323 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
324 return fmt.Errorf("incorrect channel ID")
325 }
326 }
327
David Benjaminae2888f2014-09-06 12:58:58 -0400328 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700329 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400330 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
331 }
332 }
333
David Benjaminc7ce9772015-10-09 19:32:41 -0400334 if test.expectNoNextProto {
335 if actual := connState.NegotiatedProtocol; actual != "" {
336 return fmt.Errorf("got unexpected next proto %s", actual)
337 }
338 }
339
David Benjaminfc7b0862014-09-06 13:21:53 -0400340 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700341 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400342 return fmt.Errorf("next proto type mismatch")
343 }
344 }
345
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700346 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500347 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
348 }
349
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100350 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
351 return fmt.Errorf("OCSP Response mismatch")
352 }
353
Paul Lietar4fac72e2015-09-09 13:44:55 +0100354 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
355 return fmt.Errorf("SCT list mismatch")
356 }
357
Steven Valdez0d62f262015-09-04 12:41:04 -0400358 if expected := test.expectedClientCertSignatureHash; expected != 0 && expected != connState.ClientCertSignatureHash {
359 return fmt.Errorf("expected client to sign handshake with hash %d, but got %d", expected, connState.ClientCertSignatureHash)
360 }
361
David Benjaminc565ebb2015-04-03 04:06:36 -0400362 if test.exportKeyingMaterial > 0 {
363 actual := make([]byte, test.exportKeyingMaterial)
364 if _, err := io.ReadFull(tlsConn, actual); err != nil {
365 return err
366 }
367 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
368 if err != nil {
369 return err
370 }
371 if !bytes.Equal(actual, expected) {
372 return fmt.Errorf("keying material mismatch")
373 }
374 }
375
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700376 if test.testTLSUnique {
377 var peersValue [12]byte
378 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
379 return err
380 }
381 expected := tlsConn.ConnectionState().TLSUnique
382 if !bytes.Equal(peersValue[:], expected) {
383 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
384 }
385 }
386
David Benjamine58c4f52014-08-24 03:47:07 -0400387 if test.shimWritesFirst {
388 var buf [5]byte
389 _, err := io.ReadFull(tlsConn, buf[:])
390 if err != nil {
391 return err
392 }
393 if string(buf[:]) != "hello" {
394 return fmt.Errorf("bad initial message")
395 }
396 }
397
David Benjamina8ebe222015-06-06 03:04:39 -0400398 for i := 0; i < test.sendEmptyRecords; i++ {
399 tlsConn.Write(nil)
400 }
401
David Benjamin24f346d2015-06-06 03:28:08 -0400402 for i := 0; i < test.sendWarningAlerts; i++ {
403 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
404 }
405
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400406 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700407 if test.renegotiateCiphers != nil {
408 config.CipherSuites = test.renegotiateCiphers
409 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400410 for i := 0; i < test.renegotiate; i++ {
411 if err := tlsConn.Renegotiate(); err != nil {
412 return err
413 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700414 }
415 } else if test.renegotiateCiphers != nil {
416 panic("renegotiateCiphers without renegotiate")
417 }
418
David Benjamin5fa3eba2015-01-22 16:35:40 -0500419 if test.damageFirstWrite {
420 connDamage.setDamage(true)
421 tlsConn.Write([]byte("DAMAGED WRITE"))
422 connDamage.setDamage(false)
423 }
424
David Benjamin8e6db492015-07-25 18:29:23 -0400425 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700426 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400427 if test.protocol == dtls {
428 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
429 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700430 // Read until EOF.
431 _, err := io.Copy(ioutil.Discard, tlsConn)
432 return err
433 }
David Benjamin4417d052015-04-05 04:17:25 -0400434 if messageLen == 0 {
435 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700436 }
Adam Langley95c29f32014-06-20 12:00:00 -0700437
David Benjamin8e6db492015-07-25 18:29:23 -0400438 messageCount := test.messageCount
439 if messageCount == 0 {
440 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400441 }
442
David Benjamin8e6db492015-07-25 18:29:23 -0400443 for j := 0; j < messageCount; j++ {
444 testMessage := make([]byte, messageLen)
445 for i := range testMessage {
446 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400447 }
David Benjamin8e6db492015-07-25 18:29:23 -0400448 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700449
David Benjamin8e6db492015-07-25 18:29:23 -0400450 for i := 0; i < test.sendEmptyRecords; i++ {
451 tlsConn.Write(nil)
452 }
453
454 for i := 0; i < test.sendWarningAlerts; i++ {
455 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
456 }
457
David Benjamin4f75aaf2015-09-01 16:53:10 -0400458 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400459 // The shim will not respond.
460 continue
461 }
462
David Benjamin8e6db492015-07-25 18:29:23 -0400463 buf := make([]byte, len(testMessage))
464 if test.protocol == dtls {
465 bufTmp := make([]byte, len(buf)+1)
466 n, err := tlsConn.Read(bufTmp)
467 if err != nil {
468 return err
469 }
470 if n != len(buf) {
471 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
472 }
473 copy(buf, bufTmp)
474 } else {
475 _, err := io.ReadFull(tlsConn, buf)
476 if err != nil {
477 return err
478 }
479 }
480
481 for i, v := range buf {
482 if v != testMessage[i]^0xff {
483 return fmt.Errorf("bad reply contents at byte %d", i)
484 }
Adam Langley95c29f32014-06-20 12:00:00 -0700485 }
486 }
487
488 return nil
489}
490
David Benjamin325b5c32014-07-01 19:40:31 -0400491func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
492 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full"}
Adam Langley95c29f32014-06-20 12:00:00 -0700493 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400494 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700495 }
David Benjamin325b5c32014-07-01 19:40:31 -0400496 valgrindArgs = append(valgrindArgs, path)
497 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700498
David Benjamin325b5c32014-07-01 19:40:31 -0400499 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700500}
501
David Benjamin325b5c32014-07-01 19:40:31 -0400502func gdbOf(path string, args ...string) *exec.Cmd {
503 xtermArgs := []string{"-e", "gdb", "--args"}
504 xtermArgs = append(xtermArgs, path)
505 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700506
David Benjamin325b5c32014-07-01 19:40:31 -0400507 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700508}
509
Adam Langley69a01602014-11-17 17:26:55 -0800510type moreMallocsError struct{}
511
512func (moreMallocsError) Error() string {
513 return "child process did not exhaust all allocation calls"
514}
515
516var errMoreMallocs = moreMallocsError{}
517
David Benjamin87c8a642015-02-21 01:54:29 -0500518// accept accepts a connection from listener, unless waitChan signals a process
519// exit first.
520func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
521 type connOrError struct {
522 conn net.Conn
523 err error
524 }
525 connChan := make(chan connOrError, 1)
526 go func() {
527 conn, err := listener.Accept()
528 connChan <- connOrError{conn, err}
529 close(connChan)
530 }()
531 select {
532 case result := <-connChan:
533 return result.conn, result.err
534 case childErr := <-waitChan:
535 waitChan <- childErr
536 return nil, fmt.Errorf("child exited early: %s", childErr)
537 }
538}
539
Adam Langley7c803a62015-06-15 15:35:05 -0700540func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700541 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
542 panic("Error expected without shouldFail in " + test.name)
543 }
544
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if test.expectResumeRejected && !test.resumeSession {
546 panic("expectResumeRejected without resumeSession in " + test.name)
547 }
548
Steven Valdez0d62f262015-09-04 12:41:04 -0400549 if test.testType != clientTest && test.expectedClientCertSignatureHash != 0 {
550 panic("expectedClientCertSignatureHash non-zero with serverTest in " + test.name)
551 }
552
David Benjamin87c8a642015-02-21 01:54:29 -0500553 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
554 if err != nil {
555 panic(err)
556 }
557 defer func() {
558 if listener != nil {
559 listener.Close()
560 }
561 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700562
David Benjamin87c8a642015-02-21 01:54:29 -0500563 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400564 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400565 flags = append(flags, "-server")
566
David Benjamin025b3d32014-07-01 19:53:04 -0400567 flags = append(flags, "-key-file")
568 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700569 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400570 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700571 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400572 }
573
574 flags = append(flags, "-cert-file")
575 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700576 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400577 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700578 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400579 }
580 }
David Benjamin5a593af2014-08-11 19:51:50 -0400581
Steven Valdez0d62f262015-09-04 12:41:04 -0400582 if test.digestPrefs != "" {
583 flags = append(flags, "-digest-prefs")
584 flags = append(flags, test.digestPrefs)
585 }
586
David Benjamin6fd297b2014-08-11 18:43:38 -0400587 if test.protocol == dtls {
588 flags = append(flags, "-dtls")
589 }
590
David Benjamin5a593af2014-08-11 19:51:50 -0400591 if test.resumeSession {
592 flags = append(flags, "-resume")
593 }
594
David Benjamine58c4f52014-08-24 03:47:07 -0400595 if test.shimWritesFirst {
596 flags = append(flags, "-shim-writes-first")
597 }
598
David Benjamin30789da2015-08-29 22:56:45 -0400599 if test.shimShutsDown {
600 flags = append(flags, "-shim-shuts-down")
601 }
602
David Benjaminc565ebb2015-04-03 04:06:36 -0400603 if test.exportKeyingMaterial > 0 {
604 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
605 flags = append(flags, "-export-label", test.exportLabel)
606 flags = append(flags, "-export-context", test.exportContext)
607 if test.useExportContext {
608 flags = append(flags, "-use-export-context")
609 }
610 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700611 if test.expectResumeRejected {
612 flags = append(flags, "-expect-session-miss")
613 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400614
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700615 if test.testTLSUnique {
616 flags = append(flags, "-tls-unique")
617 }
618
David Benjamin025b3d32014-07-01 19:53:04 -0400619 flags = append(flags, test.flags...)
620
621 var shim *exec.Cmd
622 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700623 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700624 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700625 shim = gdbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400626 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700627 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400628 }
David Benjamin025b3d32014-07-01 19:53:04 -0400629 shim.Stdin = os.Stdin
630 var stdoutBuf, stderrBuf bytes.Buffer
631 shim.Stdout = &stdoutBuf
632 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800633 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500634 shim.Env = os.Environ()
635 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800636 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400637 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800638 }
639 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
640 }
David Benjamin025b3d32014-07-01 19:53:04 -0400641
642 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700643 panic(err)
644 }
David Benjamin87c8a642015-02-21 01:54:29 -0500645 waitChan := make(chan error, 1)
646 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700647
648 config := test.config
David Benjaminba4594a2015-06-18 18:36:15 -0400649 if !test.noSessionCache {
650 config.ClientSessionCache = NewLRUClientSessionCache(1)
651 config.ServerSessionCache = NewLRUServerSessionCache(1)
652 }
David Benjamin025b3d32014-07-01 19:53:04 -0400653 if test.testType == clientTest {
654 if len(config.Certificates) == 0 {
655 config.Certificates = []Certificate{getRSACertificate()}
656 }
David Benjamin87c8a642015-02-21 01:54:29 -0500657 } else {
658 // Supply a ServerName to ensure a constant session cache key,
659 // rather than falling back to net.Conn.RemoteAddr.
660 if len(config.ServerName) == 0 {
661 config.ServerName = "test"
662 }
David Benjamin025b3d32014-07-01 19:53:04 -0400663 }
Adam Langley95c29f32014-06-20 12:00:00 -0700664
David Benjamin87c8a642015-02-21 01:54:29 -0500665 conn, err := acceptOrWait(listener, waitChan)
666 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400667 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500668 conn.Close()
669 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500670
David Benjamin1d5c83e2014-07-22 19:20:02 -0400671 if err == nil && test.resumeSession {
David Benjamin01fe8202014-09-24 15:21:44 -0400672 var resumeConfig Config
673 if test.resumeConfig != nil {
674 resumeConfig = *test.resumeConfig
David Benjamin87c8a642015-02-21 01:54:29 -0500675 if len(resumeConfig.ServerName) == 0 {
676 resumeConfig.ServerName = config.ServerName
677 }
David Benjamin01fe8202014-09-24 15:21:44 -0400678 if len(resumeConfig.Certificates) == 0 {
679 resumeConfig.Certificates = []Certificate{getRSACertificate()}
680 }
David Benjaminba4594a2015-06-18 18:36:15 -0400681 if test.newSessionsOnResume {
682 if !test.noSessionCache {
683 resumeConfig.ClientSessionCache = NewLRUClientSessionCache(1)
684 resumeConfig.ServerSessionCache = NewLRUServerSessionCache(1)
685 }
686 } else {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500687 resumeConfig.SessionTicketKey = config.SessionTicketKey
688 resumeConfig.ClientSessionCache = config.ClientSessionCache
689 resumeConfig.ServerSessionCache = config.ServerSessionCache
690 }
David Benjamin01fe8202014-09-24 15:21:44 -0400691 } else {
692 resumeConfig = config
693 }
David Benjamin87c8a642015-02-21 01:54:29 -0500694 var connResume net.Conn
695 connResume, err = acceptOrWait(listener, waitChan)
696 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400697 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500698 connResume.Close()
699 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400700 }
701
David Benjamin87c8a642015-02-21 01:54:29 -0500702 // Close the listener now. This is to avoid hangs should the shim try to
703 // open more connections than expected.
704 listener.Close()
705 listener = nil
706
707 childErr := <-waitChan
Adam Langley69a01602014-11-17 17:26:55 -0800708 if exitError, ok := childErr.(*exec.ExitError); ok {
709 if exitError.Sys().(syscall.WaitStatus).ExitStatus() == 88 {
710 return errMoreMallocs
711 }
712 }
Adam Langley95c29f32014-06-20 12:00:00 -0700713
714 stdout := string(stdoutBuf.Bytes())
715 stderr := string(stderrBuf.Bytes())
716 failed := err != nil || childErr != nil
David Benjaminc565ebb2015-04-03 04:06:36 -0400717 correctFailure := len(test.expectedError) == 0 || strings.Contains(stderr, test.expectedError)
Adam Langleyac61fa32014-06-23 12:03:11 -0700718 localError := "none"
719 if err != nil {
720 localError = err.Error()
721 }
722 if len(test.expectedLocalError) != 0 {
723 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
724 }
Adam Langley95c29f32014-06-20 12:00:00 -0700725
726 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700727 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700728 if childErr != nil {
729 childError = childErr.Error()
730 }
731
732 var msg string
733 switch {
734 case failed && !test.shouldFail:
735 msg = "unexpected failure"
736 case !failed && test.shouldFail:
737 msg = "unexpected success"
738 case failed && !correctFailure:
Adam Langleyac61fa32014-06-23 12:03:11 -0700739 msg = "bad error (wanted '" + test.expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700740 default:
741 panic("internal error")
742 }
743
David Benjaminc565ebb2015-04-03 04:06:36 -0400744 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s", msg, localError, childError, stdout, stderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700745 }
746
David Benjaminc565ebb2015-04-03 04:06:36 -0400747 if !*useValgrind && !failed && len(stderr) > 0 {
Adam Langley95c29f32014-06-20 12:00:00 -0700748 println(stderr)
749 }
750
751 return nil
752}
753
754var tlsVersions = []struct {
755 name string
756 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400757 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -0500758 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -0700759}{
David Benjamin8b8c0062014-11-23 02:47:52 -0500760 {"SSL3", VersionSSL30, "-no-ssl3", false},
761 {"TLS1", VersionTLS10, "-no-tls1", true},
762 {"TLS11", VersionTLS11, "-no-tls11", false},
763 {"TLS12", VersionTLS12, "-no-tls12", true},
Adam Langley95c29f32014-06-20 12:00:00 -0700764}
765
766var testCipherSuites = []struct {
767 name string
768 id uint16
769}{
770 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400771 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700772 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400773 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400774 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700775 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400776 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400777 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
778 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400779 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400780 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
781 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400782 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700783 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
784 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400785 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
786 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700787 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400788 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400789 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700790 {"ECDHE-ECDSA-RC4-SHA", TLS_ECDHE_ECDSA_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700791 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700792 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400793 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400794 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -0700795 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -0400796 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamine9a80ff2015-04-07 00:46:46 -0400797 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -0700798 {"ECDHE-RSA-RC4-SHA", TLS_ECDHE_RSA_WITH_RC4_128_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400799 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
800 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -0700801 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
802 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin48cae082014-10-27 01:06:24 -0400803 {"PSK-RC4-SHA", TLS_PSK_WITH_RC4_128_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700804 {"RC4-MD5", TLS_RSA_WITH_RC4_128_MD5},
David Benjaminf4e5c4e2014-08-02 17:35:45 -0400805 {"RC4-SHA", TLS_RSA_WITH_RC4_128_SHA},
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700806 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -0700807}
808
David Benjamin8b8c0062014-11-23 02:47:52 -0500809func hasComponent(suiteName, component string) bool {
810 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
811}
812
David Benjaminf7768e42014-08-31 02:06:47 -0400813func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -0500814 return hasComponent(suiteName, "GCM") ||
815 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -0400816 hasComponent(suiteName, "SHA384") ||
817 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -0500818}
819
820func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -0700821 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -0400822}
823
Adam Langleya7997f12015-05-14 17:38:50 -0700824func bigFromHex(hex string) *big.Int {
825 ret, ok := new(big.Int).SetString(hex, 16)
826 if !ok {
827 panic("failed to parse hex number 0x" + hex)
828 }
829 return ret
830}
831
Adam Langley7c803a62015-06-15 15:35:05 -0700832func addBasicTests() {
833 basicTests := []testCase{
834 {
835 name: "BadRSASignature",
836 config: Config{
837 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
838 Bugs: ProtocolBugs{
839 InvalidSKXSignature: true,
840 },
841 },
842 shouldFail: true,
843 expectedError: ":BAD_SIGNATURE:",
844 },
845 {
846 name: "BadECDSASignature",
847 config: Config{
848 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
849 Bugs: ProtocolBugs{
850 InvalidSKXSignature: true,
851 },
852 Certificates: []Certificate{getECDSACertificate()},
853 },
854 shouldFail: true,
855 expectedError: ":BAD_SIGNATURE:",
856 },
857 {
David Benjamin6de0e532015-07-28 22:43:19 -0400858 testType: serverTest,
859 name: "BadRSASignature-ClientAuth",
860 config: Config{
861 Bugs: ProtocolBugs{
862 InvalidCertVerifySignature: true,
863 },
864 Certificates: []Certificate{getRSACertificate()},
865 },
866 shouldFail: true,
867 expectedError: ":BAD_SIGNATURE:",
868 flags: []string{"-require-any-client-certificate"},
869 },
870 {
871 testType: serverTest,
872 name: "BadECDSASignature-ClientAuth",
873 config: Config{
874 Bugs: ProtocolBugs{
875 InvalidCertVerifySignature: true,
876 },
877 Certificates: []Certificate{getECDSACertificate()},
878 },
879 shouldFail: true,
880 expectedError: ":BAD_SIGNATURE:",
881 flags: []string{"-require-any-client-certificate"},
882 },
883 {
Adam Langley7c803a62015-06-15 15:35:05 -0700884 name: "BadECDSACurve",
885 config: Config{
886 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
887 Bugs: ProtocolBugs{
888 InvalidSKXCurve: true,
889 },
890 Certificates: []Certificate{getECDSACertificate()},
891 },
892 shouldFail: true,
893 expectedError: ":WRONG_CURVE:",
894 },
895 {
896 testType: serverTest,
897 name: "BadRSAVersion",
898 config: Config{
899 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
900 Bugs: ProtocolBugs{
901 RsaClientKeyExchangeVersion: VersionTLS11,
902 },
903 },
904 shouldFail: true,
905 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
906 },
907 {
908 name: "NoFallbackSCSV",
909 config: Config{
910 Bugs: ProtocolBugs{
911 FailIfNotFallbackSCSV: true,
912 },
913 },
914 shouldFail: true,
915 expectedLocalError: "no fallback SCSV found",
916 },
917 {
918 name: "SendFallbackSCSV",
919 config: Config{
920 Bugs: ProtocolBugs{
921 FailIfNotFallbackSCSV: true,
922 },
923 },
924 flags: []string{"-fallback-scsv"},
925 },
926 {
927 name: "ClientCertificateTypes",
928 config: Config{
929 ClientAuth: RequestClientCert,
930 ClientCertificateTypes: []byte{
931 CertTypeDSSSign,
932 CertTypeRSASign,
933 CertTypeECDSASign,
934 },
935 },
936 flags: []string{
937 "-expect-certificate-types",
938 base64.StdEncoding.EncodeToString([]byte{
939 CertTypeDSSSign,
940 CertTypeRSASign,
941 CertTypeECDSASign,
942 }),
943 },
944 },
945 {
946 name: "NoClientCertificate",
947 config: Config{
948 ClientAuth: RequireAnyClientCert,
949 },
950 shouldFail: true,
951 expectedLocalError: "client didn't provide a certificate",
952 },
953 {
954 name: "UnauthenticatedECDH",
955 config: Config{
956 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
957 Bugs: ProtocolBugs{
958 UnauthenticatedECDH: true,
959 },
960 },
961 shouldFail: true,
962 expectedError: ":UNEXPECTED_MESSAGE:",
963 },
964 {
965 name: "SkipCertificateStatus",
966 config: Config{
967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
968 Bugs: ProtocolBugs{
969 SkipCertificateStatus: true,
970 },
971 },
972 flags: []string{
973 "-enable-ocsp-stapling",
974 },
975 },
976 {
977 name: "SkipServerKeyExchange",
978 config: Config{
979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
980 Bugs: ProtocolBugs{
981 SkipServerKeyExchange: true,
982 },
983 },
984 shouldFail: true,
985 expectedError: ":UNEXPECTED_MESSAGE:",
986 },
987 {
988 name: "SkipChangeCipherSpec-Client",
989 config: Config{
990 Bugs: ProtocolBugs{
991 SkipChangeCipherSpec: true,
992 },
993 },
994 shouldFail: true,
995 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
996 },
997 {
998 testType: serverTest,
999 name: "SkipChangeCipherSpec-Server",
1000 config: Config{
1001 Bugs: ProtocolBugs{
1002 SkipChangeCipherSpec: true,
1003 },
1004 },
1005 shouldFail: true,
1006 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1007 },
1008 {
1009 testType: serverTest,
1010 name: "SkipChangeCipherSpec-Server-NPN",
1011 config: Config{
1012 NextProtos: []string{"bar"},
1013 Bugs: ProtocolBugs{
1014 SkipChangeCipherSpec: true,
1015 },
1016 },
1017 flags: []string{
1018 "-advertise-npn", "\x03foo\x03bar\x03baz",
1019 },
1020 shouldFail: true,
1021 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1022 },
1023 {
1024 name: "FragmentAcrossChangeCipherSpec-Client",
1025 config: Config{
1026 Bugs: ProtocolBugs{
1027 FragmentAcrossChangeCipherSpec: true,
1028 },
1029 },
1030 shouldFail: true,
1031 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1032 },
1033 {
1034 testType: serverTest,
1035 name: "FragmentAcrossChangeCipherSpec-Server",
1036 config: Config{
1037 Bugs: ProtocolBugs{
1038 FragmentAcrossChangeCipherSpec: true,
1039 },
1040 },
1041 shouldFail: true,
1042 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1043 },
1044 {
1045 testType: serverTest,
1046 name: "FragmentAcrossChangeCipherSpec-Server-NPN",
1047 config: Config{
1048 NextProtos: []string{"bar"},
1049 Bugs: ProtocolBugs{
1050 FragmentAcrossChangeCipherSpec: true,
1051 },
1052 },
1053 flags: []string{
1054 "-advertise-npn", "\x03foo\x03bar\x03baz",
1055 },
1056 shouldFail: true,
1057 expectedError: ":HANDSHAKE_RECORD_BEFORE_CCS:",
1058 },
1059 {
1060 testType: serverTest,
1061 name: "Alert",
1062 config: Config{
1063 Bugs: ProtocolBugs{
1064 SendSpuriousAlert: alertRecordOverflow,
1065 },
1066 },
1067 shouldFail: true,
1068 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1069 },
1070 {
1071 protocol: dtls,
1072 testType: serverTest,
1073 name: "Alert-DTLS",
1074 config: Config{
1075 Bugs: ProtocolBugs{
1076 SendSpuriousAlert: alertRecordOverflow,
1077 },
1078 },
1079 shouldFail: true,
1080 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1081 },
1082 {
1083 testType: serverTest,
1084 name: "FragmentAlert",
1085 config: Config{
1086 Bugs: ProtocolBugs{
1087 FragmentAlert: true,
1088 SendSpuriousAlert: alertRecordOverflow,
1089 },
1090 },
1091 shouldFail: true,
1092 expectedError: ":BAD_ALERT:",
1093 },
1094 {
1095 protocol: dtls,
1096 testType: serverTest,
1097 name: "FragmentAlert-DTLS",
1098 config: Config{
1099 Bugs: ProtocolBugs{
1100 FragmentAlert: true,
1101 SendSpuriousAlert: alertRecordOverflow,
1102 },
1103 },
1104 shouldFail: true,
1105 expectedError: ":BAD_ALERT:",
1106 },
1107 {
1108 testType: serverTest,
1109 name: "EarlyChangeCipherSpec-server-1",
1110 config: Config{
1111 Bugs: ProtocolBugs{
1112 EarlyChangeCipherSpec: 1,
1113 },
1114 },
1115 shouldFail: true,
1116 expectedError: ":CCS_RECEIVED_EARLY:",
1117 },
1118 {
1119 testType: serverTest,
1120 name: "EarlyChangeCipherSpec-server-2",
1121 config: Config{
1122 Bugs: ProtocolBugs{
1123 EarlyChangeCipherSpec: 2,
1124 },
1125 },
1126 shouldFail: true,
1127 expectedError: ":CCS_RECEIVED_EARLY:",
1128 },
1129 {
1130 name: "SkipNewSessionTicket",
1131 config: Config{
1132 Bugs: ProtocolBugs{
1133 SkipNewSessionTicket: true,
1134 },
1135 },
1136 shouldFail: true,
1137 expectedError: ":CCS_RECEIVED_EARLY:",
1138 },
1139 {
1140 testType: serverTest,
1141 name: "FallbackSCSV",
1142 config: Config{
1143 MaxVersion: VersionTLS11,
1144 Bugs: ProtocolBugs{
1145 SendFallbackSCSV: true,
1146 },
1147 },
1148 shouldFail: true,
1149 expectedError: ":INAPPROPRIATE_FALLBACK:",
1150 },
1151 {
1152 testType: serverTest,
1153 name: "FallbackSCSV-VersionMatch",
1154 config: Config{
1155 Bugs: ProtocolBugs{
1156 SendFallbackSCSV: true,
1157 },
1158 },
1159 },
1160 {
1161 testType: serverTest,
1162 name: "FragmentedClientVersion",
1163 config: Config{
1164 Bugs: ProtocolBugs{
1165 MaxHandshakeRecordLength: 1,
1166 FragmentClientVersion: true,
1167 },
1168 },
1169 expectedVersion: VersionTLS12,
1170 },
1171 {
1172 testType: serverTest,
1173 name: "MinorVersionTolerance",
1174 config: Config{
1175 Bugs: ProtocolBugs{
1176 SendClientVersion: 0x03ff,
1177 },
1178 },
1179 expectedVersion: VersionTLS12,
1180 },
1181 {
1182 testType: serverTest,
1183 name: "MajorVersionTolerance",
1184 config: Config{
1185 Bugs: ProtocolBugs{
1186 SendClientVersion: 0x0400,
1187 },
1188 },
1189 expectedVersion: VersionTLS12,
1190 },
1191 {
1192 testType: serverTest,
1193 name: "VersionTooLow",
1194 config: Config{
1195 Bugs: ProtocolBugs{
1196 SendClientVersion: 0x0200,
1197 },
1198 },
1199 shouldFail: true,
1200 expectedError: ":UNSUPPORTED_PROTOCOL:",
1201 },
1202 {
1203 testType: serverTest,
1204 name: "HttpGET",
1205 sendPrefix: "GET / HTTP/1.0\n",
1206 shouldFail: true,
1207 expectedError: ":HTTP_REQUEST:",
1208 },
1209 {
1210 testType: serverTest,
1211 name: "HttpPOST",
1212 sendPrefix: "POST / HTTP/1.0\n",
1213 shouldFail: true,
1214 expectedError: ":HTTP_REQUEST:",
1215 },
1216 {
1217 testType: serverTest,
1218 name: "HttpHEAD",
1219 sendPrefix: "HEAD / HTTP/1.0\n",
1220 shouldFail: true,
1221 expectedError: ":HTTP_REQUEST:",
1222 },
1223 {
1224 testType: serverTest,
1225 name: "HttpPUT",
1226 sendPrefix: "PUT / HTTP/1.0\n",
1227 shouldFail: true,
1228 expectedError: ":HTTP_REQUEST:",
1229 },
1230 {
1231 testType: serverTest,
1232 name: "HttpCONNECT",
1233 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1234 shouldFail: true,
1235 expectedError: ":HTTPS_PROXY_REQUEST:",
1236 },
1237 {
1238 testType: serverTest,
1239 name: "Garbage",
1240 sendPrefix: "blah",
1241 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001242 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001243 },
1244 {
1245 name: "SkipCipherVersionCheck",
1246 config: Config{
1247 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1248 MaxVersion: VersionTLS11,
1249 Bugs: ProtocolBugs{
1250 SkipCipherVersionCheck: true,
1251 },
1252 },
1253 shouldFail: true,
1254 expectedError: ":WRONG_CIPHER_RETURNED:",
1255 },
1256 {
1257 name: "RSAEphemeralKey",
1258 config: Config{
1259 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1260 Bugs: ProtocolBugs{
1261 RSAEphemeralKey: true,
1262 },
1263 },
1264 shouldFail: true,
1265 expectedError: ":UNEXPECTED_MESSAGE:",
1266 },
1267 {
1268 name: "DisableEverything",
1269 flags: []string{"-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
1270 shouldFail: true,
1271 expectedError: ":WRONG_SSL_VERSION:",
1272 },
1273 {
1274 protocol: dtls,
1275 name: "DisableEverything-DTLS",
1276 flags: []string{"-no-tls12", "-no-tls1"},
1277 shouldFail: true,
1278 expectedError: ":WRONG_SSL_VERSION:",
1279 },
1280 {
1281 name: "NoSharedCipher",
1282 config: Config{
1283 CipherSuites: []uint16{},
1284 },
1285 shouldFail: true,
1286 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
1287 },
1288 {
1289 protocol: dtls,
1290 testType: serverTest,
1291 name: "MTU",
1292 config: Config{
1293 Bugs: ProtocolBugs{
1294 MaxPacketLength: 256,
1295 },
1296 },
1297 flags: []string{"-mtu", "256"},
1298 },
1299 {
1300 protocol: dtls,
1301 testType: serverTest,
1302 name: "MTUExceeded",
1303 config: Config{
1304 Bugs: ProtocolBugs{
1305 MaxPacketLength: 255,
1306 },
1307 },
1308 flags: []string{"-mtu", "256"},
1309 shouldFail: true,
1310 expectedLocalError: "dtls: exceeded maximum packet length",
1311 },
1312 {
1313 name: "CertMismatchRSA",
1314 config: Config{
1315 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1316 Certificates: []Certificate{getECDSACertificate()},
1317 Bugs: ProtocolBugs{
1318 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1319 },
1320 },
1321 shouldFail: true,
1322 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1323 },
1324 {
1325 name: "CertMismatchECDSA",
1326 config: Config{
1327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1328 Certificates: []Certificate{getRSACertificate()},
1329 Bugs: ProtocolBugs{
1330 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1331 },
1332 },
1333 shouldFail: true,
1334 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1335 },
1336 {
1337 name: "EmptyCertificateList",
1338 config: Config{
1339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1340 Bugs: ProtocolBugs{
1341 EmptyCertificateList: true,
1342 },
1343 },
1344 shouldFail: true,
1345 expectedError: ":DECODE_ERROR:",
1346 },
1347 {
1348 name: "TLSFatalBadPackets",
1349 damageFirstWrite: true,
1350 shouldFail: true,
1351 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1352 },
1353 {
1354 protocol: dtls,
1355 name: "DTLSIgnoreBadPackets",
1356 damageFirstWrite: true,
1357 },
1358 {
1359 protocol: dtls,
1360 name: "DTLSIgnoreBadPackets-Async",
1361 damageFirstWrite: true,
1362 flags: []string{"-async"},
1363 },
1364 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001365 name: "AppDataBeforeHandshake",
1366 config: Config{
1367 Bugs: ProtocolBugs{
1368 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1369 },
1370 },
1371 shouldFail: true,
1372 expectedError: ":UNEXPECTED_RECORD:",
1373 },
1374 {
1375 name: "AppDataBeforeHandshake-Empty",
1376 config: Config{
1377 Bugs: ProtocolBugs{
1378 AppDataBeforeHandshake: []byte{},
1379 },
1380 },
1381 shouldFail: true,
1382 expectedError: ":UNEXPECTED_RECORD:",
1383 },
1384 {
1385 protocol: dtls,
1386 name: "AppDataBeforeHandshake-DTLS",
1387 config: Config{
1388 Bugs: ProtocolBugs{
1389 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":UNEXPECTED_RECORD:",
1394 },
1395 {
1396 protocol: dtls,
1397 name: "AppDataBeforeHandshake-DTLS-Empty",
1398 config: Config{
1399 Bugs: ProtocolBugs{
1400 AppDataBeforeHandshake: []byte{},
1401 },
1402 },
1403 shouldFail: true,
1404 expectedError: ":UNEXPECTED_RECORD:",
1405 },
1406 {
Adam Langley7c803a62015-06-15 15:35:05 -07001407 name: "AppDataAfterChangeCipherSpec",
1408 config: Config{
1409 Bugs: ProtocolBugs{
1410 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1411 },
1412 },
1413 shouldFail: true,
1414 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1415 },
1416 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001417 name: "AppDataAfterChangeCipherSpec-Empty",
1418 config: Config{
1419 Bugs: ProtocolBugs{
1420 AppDataAfterChangeCipherSpec: []byte{},
1421 },
1422 },
1423 shouldFail: true,
1424 expectedError: ":DATA_BETWEEN_CCS_AND_FINISHED:",
1425 },
1426 {
Adam Langley7c803a62015-06-15 15:35:05 -07001427 protocol: dtls,
1428 name: "AppDataAfterChangeCipherSpec-DTLS",
1429 config: Config{
1430 Bugs: ProtocolBugs{
1431 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1432 },
1433 },
1434 // BoringSSL's DTLS implementation will drop the out-of-order
1435 // application data.
1436 },
1437 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001438 protocol: dtls,
1439 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1440 config: Config{
1441 Bugs: ProtocolBugs{
1442 AppDataAfterChangeCipherSpec: []byte{},
1443 },
1444 },
1445 // BoringSSL's DTLS implementation will drop the out-of-order
1446 // application data.
1447 },
1448 {
Adam Langley7c803a62015-06-15 15:35:05 -07001449 name: "AlertAfterChangeCipherSpec",
1450 config: Config{
1451 Bugs: ProtocolBugs{
1452 AlertAfterChangeCipherSpec: alertRecordOverflow,
1453 },
1454 },
1455 shouldFail: true,
1456 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1457 },
1458 {
1459 protocol: dtls,
1460 name: "AlertAfterChangeCipherSpec-DTLS",
1461 config: Config{
1462 Bugs: ProtocolBugs{
1463 AlertAfterChangeCipherSpec: alertRecordOverflow,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1468 },
1469 {
1470 protocol: dtls,
1471 name: "ReorderHandshakeFragments-Small-DTLS",
1472 config: Config{
1473 Bugs: ProtocolBugs{
1474 ReorderHandshakeFragments: true,
1475 // Small enough that every handshake message is
1476 // fragmented.
1477 MaxHandshakeRecordLength: 2,
1478 },
1479 },
1480 },
1481 {
1482 protocol: dtls,
1483 name: "ReorderHandshakeFragments-Large-DTLS",
1484 config: Config{
1485 Bugs: ProtocolBugs{
1486 ReorderHandshakeFragments: true,
1487 // Large enough that no handshake message is
1488 // fragmented.
1489 MaxHandshakeRecordLength: 2048,
1490 },
1491 },
1492 },
1493 {
1494 protocol: dtls,
1495 name: "MixCompleteMessageWithFragments-DTLS",
1496 config: Config{
1497 Bugs: ProtocolBugs{
1498 ReorderHandshakeFragments: true,
1499 MixCompleteMessageWithFragments: true,
1500 MaxHandshakeRecordLength: 2,
1501 },
1502 },
1503 },
1504 {
1505 name: "SendInvalidRecordType",
1506 config: Config{
1507 Bugs: ProtocolBugs{
1508 SendInvalidRecordType: true,
1509 },
1510 },
1511 shouldFail: true,
1512 expectedError: ":UNEXPECTED_RECORD:",
1513 },
1514 {
1515 protocol: dtls,
1516 name: "SendInvalidRecordType-DTLS",
1517 config: Config{
1518 Bugs: ProtocolBugs{
1519 SendInvalidRecordType: true,
1520 },
1521 },
1522 shouldFail: true,
1523 expectedError: ":UNEXPECTED_RECORD:",
1524 },
1525 {
1526 name: "FalseStart-SkipServerSecondLeg",
1527 config: Config{
1528 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1529 NextProtos: []string{"foo"},
1530 Bugs: ProtocolBugs{
1531 SkipNewSessionTicket: true,
1532 SkipChangeCipherSpec: true,
1533 SkipFinished: true,
1534 ExpectFalseStart: true,
1535 },
1536 },
1537 flags: []string{
1538 "-false-start",
1539 "-handshake-never-done",
1540 "-advertise-alpn", "\x03foo",
1541 },
1542 shimWritesFirst: true,
1543 shouldFail: true,
1544 expectedError: ":UNEXPECTED_RECORD:",
1545 },
1546 {
1547 name: "FalseStart-SkipServerSecondLeg-Implicit",
1548 config: Config{
1549 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1550 NextProtos: []string{"foo"},
1551 Bugs: ProtocolBugs{
1552 SkipNewSessionTicket: true,
1553 SkipChangeCipherSpec: true,
1554 SkipFinished: true,
1555 },
1556 },
1557 flags: []string{
1558 "-implicit-handshake",
1559 "-false-start",
1560 "-handshake-never-done",
1561 "-advertise-alpn", "\x03foo",
1562 },
1563 shouldFail: true,
1564 expectedError: ":UNEXPECTED_RECORD:",
1565 },
1566 {
1567 testType: serverTest,
1568 name: "FailEarlyCallback",
1569 flags: []string{"-fail-early-callback"},
1570 shouldFail: true,
1571 expectedError: ":CONNECTION_REJECTED:",
1572 expectedLocalError: "remote error: access denied",
1573 },
1574 {
1575 name: "WrongMessageType",
1576 config: Config{
1577 Bugs: ProtocolBugs{
1578 WrongCertificateMessageType: true,
1579 },
1580 },
1581 shouldFail: true,
1582 expectedError: ":UNEXPECTED_MESSAGE:",
1583 expectedLocalError: "remote error: unexpected message",
1584 },
1585 {
1586 protocol: dtls,
1587 name: "WrongMessageType-DTLS",
1588 config: Config{
1589 Bugs: ProtocolBugs{
1590 WrongCertificateMessageType: true,
1591 },
1592 },
1593 shouldFail: true,
1594 expectedError: ":UNEXPECTED_MESSAGE:",
1595 expectedLocalError: "remote error: unexpected message",
1596 },
1597 {
1598 protocol: dtls,
1599 name: "FragmentMessageTypeMismatch-DTLS",
1600 config: Config{
1601 Bugs: ProtocolBugs{
1602 MaxHandshakeRecordLength: 2,
1603 FragmentMessageTypeMismatch: true,
1604 },
1605 },
1606 shouldFail: true,
1607 expectedError: ":FRAGMENT_MISMATCH:",
1608 },
1609 {
1610 protocol: dtls,
1611 name: "FragmentMessageLengthMismatch-DTLS",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 MaxHandshakeRecordLength: 2,
1615 FragmentMessageLengthMismatch: true,
1616 },
1617 },
1618 shouldFail: true,
1619 expectedError: ":FRAGMENT_MISMATCH:",
1620 },
1621 {
1622 protocol: dtls,
1623 name: "SplitFragments-Header-DTLS",
1624 config: Config{
1625 Bugs: ProtocolBugs{
1626 SplitFragments: 2,
1627 },
1628 },
1629 shouldFail: true,
1630 expectedError: ":UNEXPECTED_MESSAGE:",
1631 },
1632 {
1633 protocol: dtls,
1634 name: "SplitFragments-Boundary-DTLS",
1635 config: Config{
1636 Bugs: ProtocolBugs{
1637 SplitFragments: dtlsRecordHeaderLen,
1638 },
1639 },
1640 shouldFail: true,
1641 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1642 },
1643 {
1644 protocol: dtls,
1645 name: "SplitFragments-Body-DTLS",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 SplitFragments: dtlsRecordHeaderLen + 1,
1649 },
1650 },
1651 shouldFail: true,
1652 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
1653 },
1654 {
1655 protocol: dtls,
1656 name: "SendEmptyFragments-DTLS",
1657 config: Config{
1658 Bugs: ProtocolBugs{
1659 SendEmptyFragments: true,
1660 },
1661 },
1662 },
1663 {
1664 name: "UnsupportedCipherSuite",
1665 config: Config{
1666 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
1667 Bugs: ProtocolBugs{
1668 IgnorePeerCipherPreferences: true,
1669 },
1670 },
1671 flags: []string{"-cipher", "DEFAULT:!RC4"},
1672 shouldFail: true,
1673 expectedError: ":WRONG_CIPHER_RETURNED:",
1674 },
1675 {
1676 name: "UnsupportedCurve",
1677 config: Config{
1678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1679 // BoringSSL implements P-224 but doesn't enable it by
1680 // default.
1681 CurvePreferences: []CurveID{CurveP224},
1682 Bugs: ProtocolBugs{
1683 IgnorePeerCurvePreferences: true,
1684 },
1685 },
1686 shouldFail: true,
1687 expectedError: ":WRONG_CURVE:",
1688 },
1689 {
1690 name: "BadFinished",
1691 config: Config{
1692 Bugs: ProtocolBugs{
1693 BadFinished: true,
1694 },
1695 },
1696 shouldFail: true,
1697 expectedError: ":DIGEST_CHECK_FAILED:",
1698 },
1699 {
1700 name: "FalseStart-BadFinished",
1701 config: Config{
1702 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1703 NextProtos: []string{"foo"},
1704 Bugs: ProtocolBugs{
1705 BadFinished: true,
1706 ExpectFalseStart: true,
1707 },
1708 },
1709 flags: []string{
1710 "-false-start",
1711 "-handshake-never-done",
1712 "-advertise-alpn", "\x03foo",
1713 },
1714 shimWritesFirst: true,
1715 shouldFail: true,
1716 expectedError: ":DIGEST_CHECK_FAILED:",
1717 },
1718 {
1719 name: "NoFalseStart-NoALPN",
1720 config: Config{
1721 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1722 Bugs: ProtocolBugs{
1723 ExpectFalseStart: true,
1724 AlertBeforeFalseStartTest: alertAccessDenied,
1725 },
1726 },
1727 flags: []string{
1728 "-false-start",
1729 },
1730 shimWritesFirst: true,
1731 shouldFail: true,
1732 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1733 expectedLocalError: "tls: peer did not false start: EOF",
1734 },
1735 {
1736 name: "NoFalseStart-NoAEAD",
1737 config: Config{
1738 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1739 NextProtos: []string{"foo"},
1740 Bugs: ProtocolBugs{
1741 ExpectFalseStart: true,
1742 AlertBeforeFalseStartTest: alertAccessDenied,
1743 },
1744 },
1745 flags: []string{
1746 "-false-start",
1747 "-advertise-alpn", "\x03foo",
1748 },
1749 shimWritesFirst: true,
1750 shouldFail: true,
1751 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1752 expectedLocalError: "tls: peer did not false start: EOF",
1753 },
1754 {
1755 name: "NoFalseStart-RSA",
1756 config: Config{
1757 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1758 NextProtos: []string{"foo"},
1759 Bugs: ProtocolBugs{
1760 ExpectFalseStart: true,
1761 AlertBeforeFalseStartTest: alertAccessDenied,
1762 },
1763 },
1764 flags: []string{
1765 "-false-start",
1766 "-advertise-alpn", "\x03foo",
1767 },
1768 shimWritesFirst: true,
1769 shouldFail: true,
1770 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1771 expectedLocalError: "tls: peer did not false start: EOF",
1772 },
1773 {
1774 name: "NoFalseStart-DHE_RSA",
1775 config: Config{
1776 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1777 NextProtos: []string{"foo"},
1778 Bugs: ProtocolBugs{
1779 ExpectFalseStart: true,
1780 AlertBeforeFalseStartTest: alertAccessDenied,
1781 },
1782 },
1783 flags: []string{
1784 "-false-start",
1785 "-advertise-alpn", "\x03foo",
1786 },
1787 shimWritesFirst: true,
1788 shouldFail: true,
1789 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1790 expectedLocalError: "tls: peer did not false start: EOF",
1791 },
1792 {
1793 testType: serverTest,
1794 name: "NoSupportedCurves",
1795 config: Config{
1796 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1797 Bugs: ProtocolBugs{
1798 NoSupportedCurves: true,
1799 },
1800 },
1801 },
1802 {
1803 testType: serverTest,
1804 name: "NoCommonCurves",
1805 config: Config{
1806 CipherSuites: []uint16{
1807 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1808 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1809 },
1810 CurvePreferences: []CurveID{CurveP224},
1811 },
1812 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
1813 },
1814 {
1815 protocol: dtls,
1816 name: "SendSplitAlert-Sync",
1817 config: Config{
1818 Bugs: ProtocolBugs{
1819 SendSplitAlert: true,
1820 },
1821 },
1822 },
1823 {
1824 protocol: dtls,
1825 name: "SendSplitAlert-Async",
1826 config: Config{
1827 Bugs: ProtocolBugs{
1828 SendSplitAlert: true,
1829 },
1830 },
1831 flags: []string{"-async"},
1832 },
1833 {
1834 protocol: dtls,
1835 name: "PackDTLSHandshake",
1836 config: Config{
1837 Bugs: ProtocolBugs{
1838 MaxHandshakeRecordLength: 2,
1839 PackHandshakeFragments: 20,
1840 PackHandshakeRecords: 200,
1841 },
1842 },
1843 },
1844 {
1845 testType: serverTest,
1846 protocol: dtls,
1847 name: "NoRC4-DTLS",
1848 config: Config{
1849 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_RC4_128_SHA},
1850 Bugs: ProtocolBugs{
1851 EnableAllCiphersInDTLS: true,
1852 },
1853 },
1854 shouldFail: true,
1855 expectedError: ":NO_SHARED_CIPHER:",
1856 },
1857 {
1858 name: "SendEmptyRecords-Pass",
1859 sendEmptyRecords: 32,
1860 },
1861 {
1862 name: "SendEmptyRecords",
1863 sendEmptyRecords: 33,
1864 shouldFail: true,
1865 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1866 },
1867 {
1868 name: "SendEmptyRecords-Async",
1869 sendEmptyRecords: 33,
1870 flags: []string{"-async"},
1871 shouldFail: true,
1872 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1873 },
1874 {
1875 name: "SendWarningAlerts-Pass",
1876 sendWarningAlerts: 4,
1877 },
1878 {
1879 protocol: dtls,
1880 name: "SendWarningAlerts-DTLS-Pass",
1881 sendWarningAlerts: 4,
1882 },
1883 {
1884 name: "SendWarningAlerts",
1885 sendWarningAlerts: 5,
1886 shouldFail: true,
1887 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1888 },
1889 {
1890 name: "SendWarningAlerts-Async",
1891 sendWarningAlerts: 5,
1892 flags: []string{"-async"},
1893 shouldFail: true,
1894 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1895 },
David Benjaminba4594a2015-06-18 18:36:15 -04001896 {
1897 name: "EmptySessionID",
1898 config: Config{
1899 SessionTicketsDisabled: true,
1900 },
1901 noSessionCache: true,
1902 flags: []string{"-expect-no-session"},
1903 },
David Benjamin30789da2015-08-29 22:56:45 -04001904 {
1905 name: "Unclean-Shutdown",
1906 config: Config{
1907 Bugs: ProtocolBugs{
1908 NoCloseNotify: true,
1909 ExpectCloseNotify: true,
1910 },
1911 },
1912 shimShutsDown: true,
1913 flags: []string{"-check-close-notify"},
1914 shouldFail: true,
1915 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
1916 },
1917 {
1918 name: "Unclean-Shutdown-Ignored",
1919 config: Config{
1920 Bugs: ProtocolBugs{
1921 NoCloseNotify: true,
1922 },
1923 },
1924 shimShutsDown: true,
1925 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04001926 {
1927 name: "LargePlaintext",
1928 config: Config{
1929 Bugs: ProtocolBugs{
1930 SendLargeRecords: true,
1931 },
1932 },
1933 messageLen: maxPlaintext + 1,
1934 shouldFail: true,
1935 expectedError: ":DATA_LENGTH_TOO_LONG:",
1936 },
1937 {
1938 protocol: dtls,
1939 name: "LargePlaintext-DTLS",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 SendLargeRecords: true,
1943 },
1944 },
1945 messageLen: maxPlaintext + 1,
1946 shouldFail: true,
1947 expectedError: ":DATA_LENGTH_TOO_LONG:",
1948 },
1949 {
1950 name: "LargeCiphertext",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 SendLargeRecords: true,
1954 },
1955 },
1956 messageLen: maxPlaintext * 2,
1957 shouldFail: true,
1958 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
1959 },
1960 {
1961 protocol: dtls,
1962 name: "LargeCiphertext-DTLS",
1963 config: Config{
1964 Bugs: ProtocolBugs{
1965 SendLargeRecords: true,
1966 },
1967 },
1968 messageLen: maxPlaintext * 2,
1969 // Unlike the other four cases, DTLS drops records which
1970 // are invalid before authentication, so the connection
1971 // does not fail.
1972 expectMessageDropped: true,
1973 },
Adam Langley7c803a62015-06-15 15:35:05 -07001974 }
Adam Langley7c803a62015-06-15 15:35:05 -07001975 testCases = append(testCases, basicTests...)
1976}
1977
Adam Langley95c29f32014-06-20 12:00:00 -07001978func addCipherSuiteTests() {
1979 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04001980 const psk = "12345"
1981 const pskIdentity = "luggage combo"
1982
Adam Langley95c29f32014-06-20 12:00:00 -07001983 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04001984 var certFile string
1985 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05001986 if hasComponent(suite.name, "ECDSA") {
Adam Langley95c29f32014-06-20 12:00:00 -07001987 cert = getECDSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001988 certFile = ecdsaCertificateFile
1989 keyFile = ecdsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001990 } else {
1991 cert = getRSACertificate()
David Benjamin025b3d32014-07-01 19:53:04 -04001992 certFile = rsaCertificateFile
1993 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07001994 }
1995
David Benjamin48cae082014-10-27 01:06:24 -04001996 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05001997 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04001998 flags = append(flags,
1999 "-psk", psk,
2000 "-psk-identity", pskIdentity)
2001 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002002 if hasComponent(suite.name, "NULL") {
2003 // NULL ciphers must be explicitly enabled.
2004 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2005 }
David Benjamin48cae082014-10-27 01:06:24 -04002006
Adam Langley95c29f32014-06-20 12:00:00 -07002007 for _, ver := range tlsVersions {
David Benjaminf7768e42014-08-31 02:06:47 -04002008 if ver.version < VersionTLS12 && isTLS12Only(suite.name) {
Adam Langley95c29f32014-06-20 12:00:00 -07002009 continue
2010 }
2011
David Benjamin025b3d32014-07-01 19:53:04 -04002012 testCases = append(testCases, testCase{
2013 testType: clientTest,
2014 name: ver.name + "-" + suite.name + "-client",
Adam Langley95c29f32014-06-20 12:00:00 -07002015 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002016 MinVersion: ver.version,
2017 MaxVersion: ver.version,
2018 CipherSuites: []uint16{suite.id},
2019 Certificates: []Certificate{cert},
David Benjamin68793732015-05-04 20:20:48 -04002020 PreSharedKey: []byte(psk),
David Benjamin48cae082014-10-27 01:06:24 -04002021 PreSharedKeyIdentity: pskIdentity,
Adam Langley95c29f32014-06-20 12:00:00 -07002022 },
David Benjamin48cae082014-10-27 01:06:24 -04002023 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002024 resumeSession: true,
Adam Langley95c29f32014-06-20 12:00:00 -07002025 })
David Benjamin025b3d32014-07-01 19:53:04 -04002026
David Benjamin76d8abe2014-08-14 16:25:34 -04002027 testCases = append(testCases, testCase{
2028 testType: serverTest,
2029 name: ver.name + "-" + suite.name + "-server",
2030 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002031 MinVersion: ver.version,
2032 MaxVersion: ver.version,
2033 CipherSuites: []uint16{suite.id},
2034 Certificates: []Certificate{cert},
2035 PreSharedKey: []byte(psk),
2036 PreSharedKeyIdentity: pskIdentity,
David Benjamin76d8abe2014-08-14 16:25:34 -04002037 },
2038 certFile: certFile,
2039 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002040 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002041 resumeSession: true,
David Benjamin76d8abe2014-08-14 16:25:34 -04002042 })
David Benjamin6fd297b2014-08-11 18:43:38 -04002043
David Benjamin8b8c0062014-11-23 02:47:52 -05002044 if ver.hasDTLS && isDTLSCipher(suite.name) {
David Benjamin6fd297b2014-08-11 18:43:38 -04002045 testCases = append(testCases, testCase{
2046 testType: clientTest,
2047 protocol: dtls,
2048 name: "D" + ver.name + "-" + suite.name + "-client",
2049 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002050 MinVersion: ver.version,
2051 MaxVersion: ver.version,
2052 CipherSuites: []uint16{suite.id},
2053 Certificates: []Certificate{cert},
2054 PreSharedKey: []byte(psk),
2055 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002056 },
David Benjamin48cae082014-10-27 01:06:24 -04002057 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002058 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002059 })
2060 testCases = append(testCases, testCase{
2061 testType: serverTest,
2062 protocol: dtls,
2063 name: "D" + ver.name + "-" + suite.name + "-server",
2064 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002065 MinVersion: ver.version,
2066 MaxVersion: ver.version,
2067 CipherSuites: []uint16{suite.id},
2068 Certificates: []Certificate{cert},
2069 PreSharedKey: []byte(psk),
2070 PreSharedKeyIdentity: pskIdentity,
David Benjamin6fd297b2014-08-11 18:43:38 -04002071 },
2072 certFile: certFile,
2073 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002074 flags: flags,
David Benjaminfe8eb9a2014-11-17 03:19:02 -05002075 resumeSession: true,
David Benjamin6fd297b2014-08-11 18:43:38 -04002076 })
2077 }
Adam Langley95c29f32014-06-20 12:00:00 -07002078 }
David Benjamin2c99d282015-09-01 10:23:00 -04002079
2080 // Ensure both TLS and DTLS accept their maximum record sizes.
2081 testCases = append(testCases, testCase{
2082 name: suite.name + "-LargeRecord",
2083 config: Config{
2084 CipherSuites: []uint16{suite.id},
2085 Certificates: []Certificate{cert},
2086 PreSharedKey: []byte(psk),
2087 PreSharedKeyIdentity: pskIdentity,
2088 },
2089 flags: flags,
2090 messageLen: maxPlaintext,
2091 })
2092 testCases = append(testCases, testCase{
2093 name: suite.name + "-LargeRecord-Extra",
2094 config: Config{
2095 CipherSuites: []uint16{suite.id},
2096 Certificates: []Certificate{cert},
2097 PreSharedKey: []byte(psk),
2098 PreSharedKeyIdentity: pskIdentity,
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 flags: append(flags, "-microsoft-big-sslv3-buffer"),
2104 messageLen: maxPlaintext + 16384,
2105 })
2106 if isDTLSCipher(suite.name) {
2107 testCases = append(testCases, testCase{
2108 protocol: dtls,
2109 name: suite.name + "-LargeRecord-DTLS",
2110 config: Config{
2111 CipherSuites: []uint16{suite.id},
2112 Certificates: []Certificate{cert},
2113 PreSharedKey: []byte(psk),
2114 PreSharedKeyIdentity: pskIdentity,
2115 },
2116 flags: flags,
2117 messageLen: maxPlaintext,
2118 })
2119 }
Adam Langley95c29f32014-06-20 12:00:00 -07002120 }
Adam Langleya7997f12015-05-14 17:38:50 -07002121
2122 testCases = append(testCases, testCase{
2123 name: "WeakDH",
2124 config: Config{
2125 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2126 Bugs: ProtocolBugs{
2127 // This is a 1023-bit prime number, generated
2128 // with:
2129 // openssl gendh 1023 | openssl asn1parse -i
2130 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2131 },
2132 },
2133 shouldFail: true,
2134 expectedError: "BAD_DH_P_LENGTH",
2135 })
Adam Langleycef75832015-09-03 14:51:12 -07002136
2137 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2138 // 1.1 specific cipher suite settings. A server is setup with the given
2139 // cipher lists and then a connection is made for each member of
2140 // expectations. The cipher suite that the server selects must match
2141 // the specified one.
2142 var versionSpecificCiphersTest = []struct {
2143 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2144 // expectations is a map from TLS version to cipher suite id.
2145 expectations map[uint16]uint16
2146 }{
2147 {
2148 // Test that the null case (where no version-specific ciphers are set)
2149 // works as expected.
2150 "RC4-SHA:AES128-SHA", // default ciphers
2151 "", // no ciphers specifically for TLS ≥ 1.0
2152 "", // no ciphers specifically for TLS ≥ 1.1
2153 map[uint16]uint16{
2154 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2155 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2156 VersionTLS11: TLS_RSA_WITH_RC4_128_SHA,
2157 VersionTLS12: TLS_RSA_WITH_RC4_128_SHA,
2158 },
2159 },
2160 {
2161 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2162 // cipher.
2163 "RC4-SHA:AES128-SHA", // default
2164 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2165 "", // no ciphers specifically for TLS ≥ 1.1
2166 map[uint16]uint16{
2167 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2168 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2169 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2170 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2171 },
2172 },
2173 {
2174 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2175 // cipher.
2176 "RC4-SHA:AES128-SHA", // default
2177 "", // no ciphers specifically for TLS ≥ 1.0
2178 "AES128-SHA", // these ciphers for TLS ≥ 1.1
2179 map[uint16]uint16{
2180 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2181 VersionTLS10: TLS_RSA_WITH_RC4_128_SHA,
2182 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2183 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2184 },
2185 },
2186 {
2187 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2188 // mask ciphers_tls10 for TLS 1.1 and 1.2.
2189 "RC4-SHA:AES128-SHA", // default
2190 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2191 "AES256-SHA", // these ciphers for TLS ≥ 1.1
2192 map[uint16]uint16{
2193 VersionSSL30: TLS_RSA_WITH_RC4_128_SHA,
2194 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2195 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2196 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2197 },
2198 },
2199 }
2200
2201 for i, test := range versionSpecificCiphersTest {
2202 for version, expectedCipherSuite := range test.expectations {
2203 flags := []string{"-cipher", test.ciphersDefault}
2204 if len(test.ciphersTLS10) > 0 {
2205 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2206 }
2207 if len(test.ciphersTLS11) > 0 {
2208 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2209 }
2210
2211 testCases = append(testCases, testCase{
2212 testType: serverTest,
2213 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2214 config: Config{
2215 MaxVersion: version,
2216 MinVersion: version,
2217 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
2218 },
2219 flags: flags,
2220 expectedCipher: expectedCipherSuite,
2221 })
2222 }
2223 }
Adam Langley95c29f32014-06-20 12:00:00 -07002224}
2225
2226func addBadECDSASignatureTests() {
2227 for badR := BadValue(1); badR < NumBadValues; badR++ {
2228 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002229 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002230 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2231 config: Config{
2232 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2233 Certificates: []Certificate{getECDSACertificate()},
2234 Bugs: ProtocolBugs{
2235 BadECDSAR: badR,
2236 BadECDSAS: badS,
2237 },
2238 },
2239 shouldFail: true,
2240 expectedError: "SIGNATURE",
2241 })
2242 }
2243 }
2244}
2245
Adam Langley80842bd2014-06-20 12:00:00 -07002246func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002247 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002248 name: "MaxCBCPadding",
2249 config: Config{
2250 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2251 Bugs: ProtocolBugs{
2252 MaxPadding: true,
2253 },
2254 },
2255 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2256 })
David Benjamin025b3d32014-07-01 19:53:04 -04002257 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002258 name: "BadCBCPadding",
2259 config: Config{
2260 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2261 Bugs: ProtocolBugs{
2262 PaddingFirstByteBad: true,
2263 },
2264 },
2265 shouldFail: true,
2266 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2267 })
2268 // OpenSSL previously had an issue where the first byte of padding in
2269 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002270 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002271 name: "BadCBCPadding255",
2272 config: Config{
2273 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2274 Bugs: ProtocolBugs{
2275 MaxPadding: true,
2276 PaddingFirstByteBadIf255: true,
2277 },
2278 },
2279 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2280 shouldFail: true,
2281 expectedError: "DECRYPTION_FAILED_OR_BAD_RECORD_MAC",
2282 })
2283}
2284
Kenny Root7fdeaf12014-08-05 15:23:37 -07002285func addCBCSplittingTests() {
2286 testCases = append(testCases, testCase{
2287 name: "CBCRecordSplitting",
2288 config: Config{
2289 MaxVersion: VersionTLS10,
2290 MinVersion: VersionTLS10,
2291 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2292 },
David Benjaminac8302a2015-09-01 17:18:15 -04002293 messageLen: -1, // read until EOF
2294 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002295 flags: []string{
2296 "-async",
2297 "-write-different-record-sizes",
2298 "-cbc-record-splitting",
2299 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002300 })
2301 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002302 name: "CBCRecordSplittingPartialWrite",
2303 config: Config{
2304 MaxVersion: VersionTLS10,
2305 MinVersion: VersionTLS10,
2306 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2307 },
2308 messageLen: -1, // read until EOF
2309 flags: []string{
2310 "-async",
2311 "-write-different-record-sizes",
2312 "-cbc-record-splitting",
2313 "-partial-write",
2314 },
2315 })
2316}
2317
David Benjamin636293b2014-07-08 17:59:18 -04002318func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002319 // Add a dummy cert pool to stress certificate authority parsing.
2320 // TODO(davidben): Add tests that those values parse out correctly.
2321 certPool := x509.NewCertPool()
2322 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2323 if err != nil {
2324 panic(err)
2325 }
2326 certPool.AddCert(cert)
2327
David Benjamin636293b2014-07-08 17:59:18 -04002328 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002329 testCases = append(testCases, testCase{
2330 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002331 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002332 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002333 MinVersion: ver.version,
2334 MaxVersion: ver.version,
2335 ClientAuth: RequireAnyClientCert,
2336 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002337 },
2338 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002339 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2340 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002341 },
2342 })
2343 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002344 testType: serverTest,
2345 name: ver.name + "-Server-ClientAuth-RSA",
2346 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002347 MinVersion: ver.version,
2348 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002349 Certificates: []Certificate{rsaCertificate},
2350 },
2351 flags: []string{"-require-any-client-certificate"},
2352 })
David Benjamine098ec22014-08-27 23:13:20 -04002353 if ver.version != VersionSSL30 {
2354 testCases = append(testCases, testCase{
2355 testType: serverTest,
2356 name: ver.name + "-Server-ClientAuth-ECDSA",
2357 config: Config{
2358 MinVersion: ver.version,
2359 MaxVersion: ver.version,
2360 Certificates: []Certificate{ecdsaCertificate},
2361 },
2362 flags: []string{"-require-any-client-certificate"},
2363 })
2364 testCases = append(testCases, testCase{
2365 testType: clientTest,
2366 name: ver.name + "-Client-ClientAuth-ECDSA",
2367 config: Config{
2368 MinVersion: ver.version,
2369 MaxVersion: ver.version,
2370 ClientAuth: RequireAnyClientCert,
2371 ClientCAs: certPool,
2372 },
2373 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002374 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2375 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002376 },
2377 })
2378 }
David Benjamin636293b2014-07-08 17:59:18 -04002379 }
2380}
2381
Adam Langley75712922014-10-10 16:23:43 -07002382func addExtendedMasterSecretTests() {
2383 const expectEMSFlag = "-expect-extended-master-secret"
2384
2385 for _, with := range []bool{false, true} {
2386 prefix := "No"
2387 var flags []string
2388 if with {
2389 prefix = ""
2390 flags = []string{expectEMSFlag}
2391 }
2392
2393 for _, isClient := range []bool{false, true} {
2394 suffix := "-Server"
2395 testType := serverTest
2396 if isClient {
2397 suffix = "-Client"
2398 testType = clientTest
2399 }
2400
2401 for _, ver := range tlsVersions {
2402 test := testCase{
2403 testType: testType,
2404 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
2405 config: Config{
2406 MinVersion: ver.version,
2407 MaxVersion: ver.version,
2408 Bugs: ProtocolBugs{
2409 NoExtendedMasterSecret: !with,
2410 RequireExtendedMasterSecret: with,
2411 },
2412 },
David Benjamin48cae082014-10-27 01:06:24 -04002413 flags: flags,
2414 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07002415 }
2416 if test.shouldFail {
2417 test.expectedLocalError = "extended master secret required but not supported by peer"
2418 }
2419 testCases = append(testCases, test)
2420 }
2421 }
2422 }
2423
Adam Langleyba5934b2015-06-02 10:50:35 -07002424 for _, isClient := range []bool{false, true} {
2425 for _, supportedInFirstConnection := range []bool{false, true} {
2426 for _, supportedInResumeConnection := range []bool{false, true} {
2427 boolToWord := func(b bool) string {
2428 if b {
2429 return "Yes"
2430 }
2431 return "No"
2432 }
2433 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
2434 if isClient {
2435 suffix += "Client"
2436 } else {
2437 suffix += "Server"
2438 }
2439
2440 supportedConfig := Config{
2441 Bugs: ProtocolBugs{
2442 RequireExtendedMasterSecret: true,
2443 },
2444 }
2445
2446 noSupportConfig := Config{
2447 Bugs: ProtocolBugs{
2448 NoExtendedMasterSecret: true,
2449 },
2450 }
2451
2452 test := testCase{
2453 name: "ExtendedMasterSecret-" + suffix,
2454 resumeSession: true,
2455 }
2456
2457 if !isClient {
2458 test.testType = serverTest
2459 }
2460
2461 if supportedInFirstConnection {
2462 test.config = supportedConfig
2463 } else {
2464 test.config = noSupportConfig
2465 }
2466
2467 if supportedInResumeConnection {
2468 test.resumeConfig = &supportedConfig
2469 } else {
2470 test.resumeConfig = &noSupportConfig
2471 }
2472
2473 switch suffix {
2474 case "YesToYes-Client", "YesToYes-Server":
2475 // When a session is resumed, it should
2476 // still be aware that its master
2477 // secret was generated via EMS and
2478 // thus it's safe to use tls-unique.
2479 test.flags = []string{expectEMSFlag}
2480 case "NoToYes-Server":
2481 // If an original connection did not
2482 // contain EMS, but a resumption
2483 // handshake does, then a server should
2484 // not resume the session.
2485 test.expectResumeRejected = true
2486 case "YesToNo-Server":
2487 // Resuming an EMS session without the
2488 // EMS extension should cause the
2489 // server to abort the connection.
2490 test.shouldFail = true
2491 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2492 case "NoToYes-Client":
2493 // A client should abort a connection
2494 // where the server resumed a non-EMS
2495 // session but echoed the EMS
2496 // extension.
2497 test.shouldFail = true
2498 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
2499 case "YesToNo-Client":
2500 // A client should abort a connection
2501 // where the server didn't echo EMS
2502 // when the session used it.
2503 test.shouldFail = true
2504 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
2505 }
2506
2507 testCases = append(testCases, test)
2508 }
2509 }
2510 }
Adam Langley75712922014-10-10 16:23:43 -07002511}
2512
David Benjamin43ec06f2014-08-05 02:28:57 -04002513// Adds tests that try to cover the range of the handshake state machine, under
2514// various conditions. Some of these are redundant with other tests, but they
2515// only cover the synchronous case.
David Benjamin6fd297b2014-08-11 18:43:38 -04002516func addStateMachineCoverageTests(async, splitHandshake bool, protocol protocol) {
David Benjamin760b1dd2015-05-15 23:33:48 -04002517 var tests []testCase
2518
2519 // Basic handshake, with resumption. Client and server,
2520 // session ID and session ticket.
2521 tests = append(tests, testCase{
2522 name: "Basic-Client",
2523 resumeSession: true,
2524 })
2525 tests = append(tests, testCase{
2526 name: "Basic-Client-RenewTicket",
2527 config: Config{
2528 Bugs: ProtocolBugs{
2529 RenewTicketOnResume: true,
2530 },
2531 },
David Benjaminba4594a2015-06-18 18:36:15 -04002532 flags: []string{"-expect-ticket-renewal"},
David Benjamin760b1dd2015-05-15 23:33:48 -04002533 resumeSession: true,
2534 })
2535 tests = append(tests, testCase{
2536 name: "Basic-Client-NoTicket",
2537 config: Config{
2538 SessionTicketsDisabled: true,
2539 },
2540 resumeSession: true,
2541 })
2542 tests = append(tests, testCase{
2543 name: "Basic-Client-Implicit",
2544 flags: []string{"-implicit-handshake"},
2545 resumeSession: true,
2546 })
2547 tests = append(tests, testCase{
2548 testType: serverTest,
2549 name: "Basic-Server",
2550 resumeSession: true,
2551 })
2552 tests = append(tests, testCase{
2553 testType: serverTest,
2554 name: "Basic-Server-NoTickets",
2555 config: Config{
2556 SessionTicketsDisabled: true,
2557 },
2558 resumeSession: true,
2559 })
2560 tests = append(tests, testCase{
2561 testType: serverTest,
2562 name: "Basic-Server-Implicit",
2563 flags: []string{"-implicit-handshake"},
2564 resumeSession: true,
2565 })
2566 tests = append(tests, testCase{
2567 testType: serverTest,
2568 name: "Basic-Server-EarlyCallback",
2569 flags: []string{"-use-early-callback"},
2570 resumeSession: true,
2571 })
2572
2573 // TLS client auth.
2574 tests = append(tests, testCase{
2575 testType: clientTest,
2576 name: "ClientAuth-Client",
2577 config: Config{
2578 ClientAuth: RequireAnyClientCert,
2579 },
2580 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002581 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2582 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04002583 },
2584 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002585 if async {
2586 tests = append(tests, testCase{
2587 testType: clientTest,
2588 name: "ClientAuth-Client-AsyncKey",
2589 config: Config{
2590 ClientAuth: RequireAnyClientCert,
2591 },
2592 flags: []string{
Adam Langley288d8d52015-06-18 16:24:31 -07002593 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2594 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminb4d65fd2015-05-29 17:11:21 -04002595 "-use-async-private-key",
2596 },
2597 })
nagendra modadugu601448a2015-07-24 09:31:31 -07002598 tests = append(tests, testCase{
2599 testType: serverTest,
2600 name: "Basic-Server-RSAAsyncKey",
2601 flags: []string{
2602 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2603 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2604 "-use-async-private-key",
2605 },
2606 })
2607 tests = append(tests, testCase{
2608 testType: serverTest,
2609 name: "Basic-Server-ECDSAAsyncKey",
2610 flags: []string{
2611 "-cert-file", path.Join(*resourceDir, ecdsaCertificateFile),
2612 "-key-file", path.Join(*resourceDir, ecdsaKeyFile),
2613 "-use-async-private-key",
2614 },
2615 })
David Benjaminb4d65fd2015-05-29 17:11:21 -04002616 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002617 tests = append(tests, testCase{
2618 testType: serverTest,
2619 name: "ClientAuth-Server",
2620 config: Config{
2621 Certificates: []Certificate{rsaCertificate},
2622 },
2623 flags: []string{"-require-any-client-certificate"},
2624 })
2625
2626 // No session ticket support; server doesn't send NewSessionTicket.
2627 tests = append(tests, testCase{
2628 name: "SessionTicketsDisabled-Client",
2629 config: Config{
2630 SessionTicketsDisabled: true,
2631 },
2632 })
2633 tests = append(tests, testCase{
2634 testType: serverTest,
2635 name: "SessionTicketsDisabled-Server",
2636 config: Config{
2637 SessionTicketsDisabled: true,
2638 },
2639 })
2640
2641 // Skip ServerKeyExchange in PSK key exchange if there's no
2642 // identity hint.
2643 tests = append(tests, testCase{
2644 name: "EmptyPSKHint-Client",
2645 config: Config{
2646 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2647 PreSharedKey: []byte("secret"),
2648 },
2649 flags: []string{"-psk", "secret"},
2650 })
2651 tests = append(tests, testCase{
2652 testType: serverTest,
2653 name: "EmptyPSKHint-Server",
2654 config: Config{
2655 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2656 PreSharedKey: []byte("secret"),
2657 },
2658 flags: []string{"-psk", "secret"},
2659 })
2660
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002661 tests = append(tests, testCase{
2662 testType: clientTest,
2663 name: "OCSPStapling-Client",
2664 flags: []string{
2665 "-enable-ocsp-stapling",
2666 "-expect-ocsp-response",
2667 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01002668 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002669 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002670 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002671 })
2672
2673 tests = append(tests, testCase{
David Benjaminec435342015-08-21 13:44:06 -04002674 testType: serverTest,
2675 name: "OCSPStapling-Server",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002676 expectedOCSPResponse: testOCSPResponse,
2677 flags: []string{
2678 "-ocsp-response",
2679 base64.StdEncoding.EncodeToString(testOCSPResponse),
2680 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01002681 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01002682 })
2683
Paul Lietar8f1c2682015-08-18 12:21:54 +01002684 tests = append(tests, testCase{
2685 testType: clientTest,
2686 name: "CertificateVerificationSucceed",
2687 flags: []string{
2688 "-verify-peer",
2689 },
2690 })
2691
2692 tests = append(tests, testCase{
2693 testType: clientTest,
2694 name: "CertificateVerificationFail",
2695 flags: []string{
2696 "-verify-fail",
2697 "-verify-peer",
2698 },
2699 shouldFail: true,
2700 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
2701 })
2702
2703 tests = append(tests, testCase{
2704 testType: clientTest,
2705 name: "CertificateVerificationSoftFail",
2706 flags: []string{
2707 "-verify-fail",
2708 "-expect-verify-result",
2709 },
2710 })
2711
David Benjamin760b1dd2015-05-15 23:33:48 -04002712 if protocol == tls {
2713 tests = append(tests, testCase{
2714 name: "Renegotiate-Client",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04002715 renegotiate: 1,
2716 flags: []string{
2717 "-renegotiate-freely",
2718 "-expect-total-renegotiations", "1",
2719 },
David Benjamin760b1dd2015-05-15 23:33:48 -04002720 })
2721 // NPN on client and server; results in post-handshake message.
2722 tests = append(tests, testCase{
2723 name: "NPN-Client",
2724 config: Config{
2725 NextProtos: []string{"foo"},
2726 },
2727 flags: []string{"-select-next-proto", "foo"},
2728 expectedNextProto: "foo",
2729 expectedNextProtoType: npn,
2730 })
2731 tests = append(tests, testCase{
2732 testType: serverTest,
2733 name: "NPN-Server",
2734 config: Config{
2735 NextProtos: []string{"bar"},
2736 },
2737 flags: []string{
2738 "-advertise-npn", "\x03foo\x03bar\x03baz",
2739 "-expect-next-proto", "bar",
2740 },
2741 expectedNextProto: "bar",
2742 expectedNextProtoType: npn,
2743 })
2744
2745 // TODO(davidben): Add tests for when False Start doesn't trigger.
2746
2747 // Client does False Start and negotiates NPN.
2748 tests = append(tests, testCase{
2749 name: "FalseStart",
2750 config: Config{
2751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2752 NextProtos: []string{"foo"},
2753 Bugs: ProtocolBugs{
2754 ExpectFalseStart: true,
2755 },
2756 },
2757 flags: []string{
2758 "-false-start",
2759 "-select-next-proto", "foo",
2760 },
2761 shimWritesFirst: true,
2762 resumeSession: true,
2763 })
2764
2765 // Client does False Start and negotiates ALPN.
2766 tests = append(tests, testCase{
2767 name: "FalseStart-ALPN",
2768 config: Config{
2769 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2770 NextProtos: []string{"foo"},
2771 Bugs: ProtocolBugs{
2772 ExpectFalseStart: true,
2773 },
2774 },
2775 flags: []string{
2776 "-false-start",
2777 "-advertise-alpn", "\x03foo",
2778 },
2779 shimWritesFirst: true,
2780 resumeSession: true,
2781 })
2782
2783 // Client does False Start but doesn't explicitly call
2784 // SSL_connect.
2785 tests = append(tests, testCase{
2786 name: "FalseStart-Implicit",
2787 config: Config{
2788 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2789 NextProtos: []string{"foo"},
2790 },
2791 flags: []string{
2792 "-implicit-handshake",
2793 "-false-start",
2794 "-advertise-alpn", "\x03foo",
2795 },
2796 })
2797
2798 // False Start without session tickets.
2799 tests = append(tests, testCase{
2800 name: "FalseStart-SessionTicketsDisabled",
2801 config: Config{
2802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2803 NextProtos: []string{"foo"},
2804 SessionTicketsDisabled: true,
2805 Bugs: ProtocolBugs{
2806 ExpectFalseStart: true,
2807 },
2808 },
2809 flags: []string{
2810 "-false-start",
2811 "-select-next-proto", "foo",
2812 },
2813 shimWritesFirst: true,
2814 })
2815
2816 // Server parses a V2ClientHello.
2817 tests = append(tests, testCase{
2818 testType: serverTest,
2819 name: "SendV2ClientHello",
2820 config: Config{
2821 // Choose a cipher suite that does not involve
2822 // elliptic curves, so no extensions are
2823 // involved.
2824 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
2825 Bugs: ProtocolBugs{
2826 SendV2ClientHello: true,
2827 },
2828 },
2829 })
2830
2831 // Client sends a Channel ID.
2832 tests = append(tests, testCase{
2833 name: "ChannelID-Client",
2834 config: Config{
2835 RequestChannelID: true,
2836 },
Adam Langley7c803a62015-06-15 15:35:05 -07002837 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04002838 resumeSession: true,
2839 expectChannelID: true,
2840 })
2841
2842 // Server accepts a Channel ID.
2843 tests = append(tests, testCase{
2844 testType: serverTest,
2845 name: "ChannelID-Server",
2846 config: Config{
2847 ChannelID: channelIDKey,
2848 },
2849 flags: []string{
2850 "-expect-channel-id",
2851 base64.StdEncoding.EncodeToString(channelIDBytes),
2852 },
2853 resumeSession: true,
2854 expectChannelID: true,
2855 })
David Benjamin30789da2015-08-29 22:56:45 -04002856
2857 // Bidirectional shutdown with the runner initiating.
2858 tests = append(tests, testCase{
2859 name: "Shutdown-Runner",
2860 config: Config{
2861 Bugs: ProtocolBugs{
2862 ExpectCloseNotify: true,
2863 },
2864 },
2865 flags: []string{"-check-close-notify"},
2866 })
2867
2868 // Bidirectional shutdown with the shim initiating. The runner,
2869 // in the meantime, sends garbage before the close_notify which
2870 // the shim must ignore.
2871 tests = append(tests, testCase{
2872 name: "Shutdown-Shim",
2873 config: Config{
2874 Bugs: ProtocolBugs{
2875 ExpectCloseNotify: true,
2876 },
2877 },
2878 shimShutsDown: true,
2879 sendEmptyRecords: 1,
2880 sendWarningAlerts: 1,
2881 flags: []string{"-check-close-notify"},
2882 })
David Benjamin760b1dd2015-05-15 23:33:48 -04002883 } else {
2884 tests = append(tests, testCase{
2885 name: "SkipHelloVerifyRequest",
2886 config: Config{
2887 Bugs: ProtocolBugs{
2888 SkipHelloVerifyRequest: true,
2889 },
2890 },
2891 })
2892 }
2893
David Benjamin43ec06f2014-08-05 02:28:57 -04002894 var suffix string
2895 var flags []string
2896 var maxHandshakeRecordLength int
David Benjamin6fd297b2014-08-11 18:43:38 -04002897 if protocol == dtls {
2898 suffix = "-DTLS"
2899 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002900 if async {
David Benjamin6fd297b2014-08-11 18:43:38 -04002901 suffix += "-Async"
David Benjamin43ec06f2014-08-05 02:28:57 -04002902 flags = append(flags, "-async")
2903 } else {
David Benjamin6fd297b2014-08-11 18:43:38 -04002904 suffix += "-Sync"
David Benjamin43ec06f2014-08-05 02:28:57 -04002905 }
2906 if splitHandshake {
2907 suffix += "-SplitHandshakeRecords"
David Benjamin98214542014-08-07 18:02:39 -04002908 maxHandshakeRecordLength = 1
David Benjamin43ec06f2014-08-05 02:28:57 -04002909 }
David Benjamin760b1dd2015-05-15 23:33:48 -04002910 for _, test := range tests {
2911 test.protocol = protocol
2912 test.name += suffix
2913 test.config.Bugs.MaxHandshakeRecordLength = maxHandshakeRecordLength
2914 test.flags = append(test.flags, flags...)
2915 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04002916 }
David Benjamin43ec06f2014-08-05 02:28:57 -04002917}
2918
Adam Langley524e7172015-02-20 16:04:00 -08002919func addDDoSCallbackTests() {
2920 // DDoS callback.
2921
2922 for _, resume := range []bool{false, true} {
2923 suffix := "Resume"
2924 if resume {
2925 suffix = "No" + suffix
2926 }
2927
2928 testCases = append(testCases, testCase{
2929 testType: serverTest,
2930 name: "Server-DDoS-OK-" + suffix,
2931 flags: []string{"-install-ddos-callback"},
2932 resumeSession: resume,
2933 })
2934
2935 failFlag := "-fail-ddos-callback"
2936 if resume {
2937 failFlag = "-fail-second-ddos-callback"
2938 }
2939 testCases = append(testCases, testCase{
2940 testType: serverTest,
2941 name: "Server-DDoS-Reject-" + suffix,
2942 flags: []string{"-install-ddos-callback", failFlag},
2943 resumeSession: resume,
2944 shouldFail: true,
2945 expectedError: ":CONNECTION_REJECTED:",
2946 })
2947 }
2948}
2949
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002950func addVersionNegotiationTests() {
2951 for i, shimVers := range tlsVersions {
2952 // Assemble flags to disable all newer versions on the shim.
2953 var flags []string
2954 for _, vers := range tlsVersions[i+1:] {
2955 flags = append(flags, vers.flag)
2956 }
2957
2958 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05002959 protocols := []protocol{tls}
2960 if runnerVers.hasDTLS && shimVers.hasDTLS {
2961 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002962 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002963 for _, protocol := range protocols {
2964 expectedVersion := shimVers.version
2965 if runnerVers.version < shimVers.version {
2966 expectedVersion = runnerVers.version
2967 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002968
David Benjamin8b8c0062014-11-23 02:47:52 -05002969 suffix := shimVers.name + "-" + runnerVers.name
2970 if protocol == dtls {
2971 suffix += "-DTLS"
2972 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04002973
David Benjamin1eb367c2014-12-12 18:17:51 -05002974 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
2975
David Benjamin1e29a6b2014-12-10 02:27:24 -05002976 clientVers := shimVers.version
2977 if clientVers > VersionTLS10 {
2978 clientVers = VersionTLS10
2979 }
David Benjamin8b8c0062014-11-23 02:47:52 -05002980 testCases = append(testCases, testCase{
2981 protocol: protocol,
2982 testType: clientTest,
2983 name: "VersionNegotiation-Client-" + suffix,
2984 config: Config{
2985 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05002986 Bugs: ProtocolBugs{
2987 ExpectInitialRecordVersion: clientVers,
2988 },
David Benjamin8b8c0062014-11-23 02:47:52 -05002989 },
2990 flags: flags,
2991 expectedVersion: expectedVersion,
2992 })
David Benjamin1eb367c2014-12-12 18:17:51 -05002993 testCases = append(testCases, testCase{
2994 protocol: protocol,
2995 testType: clientTest,
2996 name: "VersionNegotiation-Client2-" + suffix,
2997 config: Config{
2998 MaxVersion: runnerVers.version,
2999 Bugs: ProtocolBugs{
3000 ExpectInitialRecordVersion: clientVers,
3001 },
3002 },
3003 flags: []string{"-max-version", shimVersFlag},
3004 expectedVersion: expectedVersion,
3005 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003006
3007 testCases = append(testCases, testCase{
3008 protocol: protocol,
3009 testType: serverTest,
3010 name: "VersionNegotiation-Server-" + suffix,
3011 config: Config{
3012 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05003013 Bugs: ProtocolBugs{
3014 ExpectInitialRecordVersion: expectedVersion,
3015 },
David Benjamin8b8c0062014-11-23 02:47:52 -05003016 },
3017 flags: flags,
3018 expectedVersion: expectedVersion,
3019 })
David Benjamin1eb367c2014-12-12 18:17:51 -05003020 testCases = append(testCases, testCase{
3021 protocol: protocol,
3022 testType: serverTest,
3023 name: "VersionNegotiation-Server2-" + suffix,
3024 config: Config{
3025 MaxVersion: runnerVers.version,
3026 Bugs: ProtocolBugs{
3027 ExpectInitialRecordVersion: expectedVersion,
3028 },
3029 },
3030 flags: []string{"-max-version", shimVersFlag},
3031 expectedVersion: expectedVersion,
3032 })
David Benjamin8b8c0062014-11-23 02:47:52 -05003033 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04003034 }
3035 }
3036}
3037
David Benjaminaccb4542014-12-12 23:44:33 -05003038func addMinimumVersionTests() {
3039 for i, shimVers := range tlsVersions {
3040 // Assemble flags to disable all older versions on the shim.
3041 var flags []string
3042 for _, vers := range tlsVersions[:i] {
3043 flags = append(flags, vers.flag)
3044 }
3045
3046 for _, runnerVers := range tlsVersions {
3047 protocols := []protocol{tls}
3048 if runnerVers.hasDTLS && shimVers.hasDTLS {
3049 protocols = append(protocols, dtls)
3050 }
3051 for _, protocol := range protocols {
3052 suffix := shimVers.name + "-" + runnerVers.name
3053 if protocol == dtls {
3054 suffix += "-DTLS"
3055 }
3056 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
3057
David Benjaminaccb4542014-12-12 23:44:33 -05003058 var expectedVersion uint16
3059 var shouldFail bool
3060 var expectedError string
David Benjamin87909c02014-12-13 01:55:01 -05003061 var expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05003062 if runnerVers.version >= shimVers.version {
3063 expectedVersion = runnerVers.version
3064 } else {
3065 shouldFail = true
3066 expectedError = ":UNSUPPORTED_PROTOCOL:"
David Benjamin87909c02014-12-13 01:55:01 -05003067 if runnerVers.version > VersionSSL30 {
3068 expectedLocalError = "remote error: protocol version not supported"
3069 } else {
3070 expectedLocalError = "remote error: handshake failure"
3071 }
David Benjaminaccb4542014-12-12 23:44:33 -05003072 }
3073
3074 testCases = append(testCases, testCase{
3075 protocol: protocol,
3076 testType: clientTest,
3077 name: "MinimumVersion-Client-" + suffix,
3078 config: Config{
3079 MaxVersion: runnerVers.version,
3080 },
David Benjamin87909c02014-12-13 01:55:01 -05003081 flags: flags,
3082 expectedVersion: expectedVersion,
3083 shouldFail: shouldFail,
3084 expectedError: expectedError,
3085 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003086 })
3087 testCases = append(testCases, testCase{
3088 protocol: protocol,
3089 testType: clientTest,
3090 name: "MinimumVersion-Client2-" + suffix,
3091 config: Config{
3092 MaxVersion: runnerVers.version,
3093 },
David Benjamin87909c02014-12-13 01:55:01 -05003094 flags: []string{"-min-version", shimVersFlag},
3095 expectedVersion: expectedVersion,
3096 shouldFail: shouldFail,
3097 expectedError: expectedError,
3098 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003099 })
3100
3101 testCases = append(testCases, testCase{
3102 protocol: protocol,
3103 testType: serverTest,
3104 name: "MinimumVersion-Server-" + suffix,
3105 config: Config{
3106 MaxVersion: runnerVers.version,
3107 },
David Benjamin87909c02014-12-13 01:55:01 -05003108 flags: flags,
3109 expectedVersion: expectedVersion,
3110 shouldFail: shouldFail,
3111 expectedError: expectedError,
3112 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003113 })
3114 testCases = append(testCases, testCase{
3115 protocol: protocol,
3116 testType: serverTest,
3117 name: "MinimumVersion-Server2-" + suffix,
3118 config: Config{
3119 MaxVersion: runnerVers.version,
3120 },
David Benjamin87909c02014-12-13 01:55:01 -05003121 flags: []string{"-min-version", shimVersFlag},
3122 expectedVersion: expectedVersion,
3123 shouldFail: shouldFail,
3124 expectedError: expectedError,
3125 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05003126 })
3127 }
3128 }
3129 }
3130}
3131
David Benjamin5c24a1d2014-08-31 00:59:27 -04003132func addD5BugTests() {
3133 testCases = append(testCases, testCase{
3134 testType: serverTest,
3135 name: "D5Bug-NoQuirk-Reject",
3136 config: Config{
3137 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3138 Bugs: ProtocolBugs{
3139 SSL3RSAKeyExchange: true,
3140 },
3141 },
3142 shouldFail: true,
3143 expectedError: ":TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG:",
3144 })
3145 testCases = append(testCases, testCase{
3146 testType: serverTest,
3147 name: "D5Bug-Quirk-Normal",
3148 config: Config{
3149 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3150 },
3151 flags: []string{"-tls-d5-bug"},
3152 })
3153 testCases = append(testCases, testCase{
3154 testType: serverTest,
3155 name: "D5Bug-Quirk-Bug",
3156 config: Config{
3157 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3158 Bugs: ProtocolBugs{
3159 SSL3RSAKeyExchange: true,
3160 },
3161 },
3162 flags: []string{"-tls-d5-bug"},
3163 })
3164}
3165
David Benjamine78bfde2014-09-06 12:45:15 -04003166func addExtensionTests() {
3167 testCases = append(testCases, testCase{
3168 testType: clientTest,
3169 name: "DuplicateExtensionClient",
3170 config: Config{
3171 Bugs: ProtocolBugs{
3172 DuplicateExtension: true,
3173 },
3174 },
3175 shouldFail: true,
3176 expectedLocalError: "remote error: error decoding message",
3177 })
3178 testCases = append(testCases, testCase{
3179 testType: serverTest,
3180 name: "DuplicateExtensionServer",
3181 config: Config{
3182 Bugs: ProtocolBugs{
3183 DuplicateExtension: true,
3184 },
3185 },
3186 shouldFail: true,
3187 expectedLocalError: "remote error: error decoding message",
3188 })
3189 testCases = append(testCases, testCase{
3190 testType: clientTest,
3191 name: "ServerNameExtensionClient",
3192 config: Config{
3193 Bugs: ProtocolBugs{
3194 ExpectServerName: "example.com",
3195 },
3196 },
3197 flags: []string{"-host-name", "example.com"},
3198 })
3199 testCases = append(testCases, testCase{
3200 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003201 name: "ServerNameExtensionClientMismatch",
David Benjamine78bfde2014-09-06 12:45:15 -04003202 config: Config{
3203 Bugs: ProtocolBugs{
3204 ExpectServerName: "mismatch.com",
3205 },
3206 },
3207 flags: []string{"-host-name", "example.com"},
3208 shouldFail: true,
3209 expectedLocalError: "tls: unexpected server name",
3210 })
3211 testCases = append(testCases, testCase{
3212 testType: clientTest,
David Benjamin5f237bc2015-02-11 17:14:15 -05003213 name: "ServerNameExtensionClientMissing",
David Benjamine78bfde2014-09-06 12:45:15 -04003214 config: Config{
3215 Bugs: ProtocolBugs{
3216 ExpectServerName: "missing.com",
3217 },
3218 },
3219 shouldFail: true,
3220 expectedLocalError: "tls: unexpected server name",
3221 })
3222 testCases = append(testCases, testCase{
3223 testType: serverTest,
3224 name: "ServerNameExtensionServer",
3225 config: Config{
3226 ServerName: "example.com",
3227 },
3228 flags: []string{"-expect-server-name", "example.com"},
3229 resumeSession: true,
3230 })
David Benjaminae2888f2014-09-06 12:58:58 -04003231 testCases = append(testCases, testCase{
3232 testType: clientTest,
3233 name: "ALPNClient",
3234 config: Config{
3235 NextProtos: []string{"foo"},
3236 },
3237 flags: []string{
3238 "-advertise-alpn", "\x03foo\x03bar\x03baz",
3239 "-expect-alpn", "foo",
3240 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003241 expectedNextProto: "foo",
3242 expectedNextProtoType: alpn,
3243 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003244 })
3245 testCases = append(testCases, testCase{
3246 testType: serverTest,
3247 name: "ALPNServer",
3248 config: Config{
3249 NextProtos: []string{"foo", "bar", "baz"},
3250 },
3251 flags: []string{
3252 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3253 "-select-alpn", "foo",
3254 },
David Benjaminfc7b0862014-09-06 13:21:53 -04003255 expectedNextProto: "foo",
3256 expectedNextProtoType: alpn,
3257 resumeSession: true,
3258 })
3259 // Test that the server prefers ALPN over NPN.
3260 testCases = append(testCases, testCase{
3261 testType: serverTest,
3262 name: "ALPNServer-Preferred",
3263 config: Config{
3264 NextProtos: []string{"foo", "bar", "baz"},
3265 },
3266 flags: []string{
3267 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3268 "-select-alpn", "foo",
3269 "-advertise-npn", "\x03foo\x03bar\x03baz",
3270 },
3271 expectedNextProto: "foo",
3272 expectedNextProtoType: alpn,
3273 resumeSession: true,
3274 })
3275 testCases = append(testCases, testCase{
3276 testType: serverTest,
3277 name: "ALPNServer-Preferred-Swapped",
3278 config: Config{
3279 NextProtos: []string{"foo", "bar", "baz"},
3280 Bugs: ProtocolBugs{
3281 SwapNPNAndALPN: true,
3282 },
3283 },
3284 flags: []string{
3285 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
3286 "-select-alpn", "foo",
3287 "-advertise-npn", "\x03foo\x03bar\x03baz",
3288 },
3289 expectedNextProto: "foo",
3290 expectedNextProtoType: alpn,
3291 resumeSession: true,
David Benjaminae2888f2014-09-06 12:58:58 -04003292 })
Adam Langleyefb0e162015-07-09 11:35:04 -07003293 var emptyString string
3294 testCases = append(testCases, testCase{
3295 testType: clientTest,
3296 name: "ALPNClient-EmptyProtocolName",
3297 config: Config{
3298 NextProtos: []string{""},
3299 Bugs: ProtocolBugs{
3300 // A server returning an empty ALPN protocol
3301 // should be rejected.
3302 ALPNProtocol: &emptyString,
3303 },
3304 },
3305 flags: []string{
3306 "-advertise-alpn", "\x03foo",
3307 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003308 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003309 expectedError: ":PARSE_TLSEXT:",
3310 })
3311 testCases = append(testCases, testCase{
3312 testType: serverTest,
3313 name: "ALPNServer-EmptyProtocolName",
3314 config: Config{
3315 // A ClientHello containing an empty ALPN protocol
3316 // should be rejected.
3317 NextProtos: []string{"foo", "", "baz"},
3318 },
3319 flags: []string{
3320 "-select-alpn", "foo",
3321 },
Doug Hoganecdf7f92015-07-09 18:27:28 -07003322 shouldFail: true,
Adam Langleyefb0e162015-07-09 11:35:04 -07003323 expectedError: ":PARSE_TLSEXT:",
3324 })
David Benjamin76c2efc2015-08-31 14:24:29 -04003325 // Test that negotiating both NPN and ALPN is forbidden.
3326 testCases = append(testCases, testCase{
3327 name: "NegotiateALPNAndNPN",
3328 config: Config{
3329 NextProtos: []string{"foo", "bar", "baz"},
3330 Bugs: ProtocolBugs{
3331 NegotiateALPNAndNPN: true,
3332 },
3333 },
3334 flags: []string{
3335 "-advertise-alpn", "\x03foo",
3336 "-select-next-proto", "foo",
3337 },
3338 shouldFail: true,
3339 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3340 })
3341 testCases = append(testCases, testCase{
3342 name: "NegotiateALPNAndNPN-Swapped",
3343 config: Config{
3344 NextProtos: []string{"foo", "bar", "baz"},
3345 Bugs: ProtocolBugs{
3346 NegotiateALPNAndNPN: true,
3347 SwapNPNAndALPN: true,
3348 },
3349 },
3350 flags: []string{
3351 "-advertise-alpn", "\x03foo",
3352 "-select-next-proto", "foo",
3353 },
3354 shouldFail: true,
3355 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
3356 })
Adam Langley38311732014-10-16 19:04:35 -07003357 // Resume with a corrupt ticket.
3358 testCases = append(testCases, testCase{
3359 testType: serverTest,
3360 name: "CorruptTicket",
3361 config: Config{
3362 Bugs: ProtocolBugs{
3363 CorruptTicket: true,
3364 },
3365 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003366 resumeSession: true,
3367 expectResumeRejected: true,
Adam Langley38311732014-10-16 19:04:35 -07003368 })
David Benjamind98452d2015-06-16 14:16:23 -04003369 // Test the ticket callback, with and without renewal.
3370 testCases = append(testCases, testCase{
3371 testType: serverTest,
3372 name: "TicketCallback",
3373 resumeSession: true,
3374 flags: []string{"-use-ticket-callback"},
3375 })
3376 testCases = append(testCases, testCase{
3377 testType: serverTest,
3378 name: "TicketCallback-Renew",
3379 config: Config{
3380 Bugs: ProtocolBugs{
3381 ExpectNewTicket: true,
3382 },
3383 },
3384 flags: []string{"-use-ticket-callback", "-renew-ticket"},
3385 resumeSession: true,
3386 })
Adam Langley38311732014-10-16 19:04:35 -07003387 // Resume with an oversized session id.
3388 testCases = append(testCases, testCase{
3389 testType: serverTest,
3390 name: "OversizedSessionId",
3391 config: Config{
3392 Bugs: ProtocolBugs{
3393 OversizedSessionId: true,
3394 },
3395 },
3396 resumeSession: true,
Adam Langley75712922014-10-10 16:23:43 -07003397 shouldFail: true,
Adam Langley38311732014-10-16 19:04:35 -07003398 expectedError: ":DECODE_ERROR:",
3399 })
David Benjaminca6c8262014-11-15 19:06:08 -05003400 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
3401 // are ignored.
3402 testCases = append(testCases, testCase{
3403 protocol: dtls,
3404 name: "SRTP-Client",
3405 config: Config{
3406 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3407 },
3408 flags: []string{
3409 "-srtp-profiles",
3410 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3411 },
3412 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3413 })
3414 testCases = append(testCases, testCase{
3415 protocol: dtls,
3416 testType: serverTest,
3417 name: "SRTP-Server",
3418 config: Config{
3419 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
3420 },
3421 flags: []string{
3422 "-srtp-profiles",
3423 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3424 },
3425 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3426 })
3427 // Test that the MKI is ignored.
3428 testCases = append(testCases, testCase{
3429 protocol: dtls,
3430 testType: serverTest,
3431 name: "SRTP-Server-IgnoreMKI",
3432 config: Config{
3433 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
3434 Bugs: ProtocolBugs{
3435 SRTPMasterKeyIdentifer: "bogus",
3436 },
3437 },
3438 flags: []string{
3439 "-srtp-profiles",
3440 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3441 },
3442 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
3443 })
3444 // Test that SRTP isn't negotiated on the server if there were
3445 // no matching profiles.
3446 testCases = append(testCases, testCase{
3447 protocol: dtls,
3448 testType: serverTest,
3449 name: "SRTP-Server-NoMatch",
3450 config: Config{
3451 SRTPProtectionProfiles: []uint16{100, 101, 102},
3452 },
3453 flags: []string{
3454 "-srtp-profiles",
3455 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
3456 },
3457 expectedSRTPProtectionProfile: 0,
3458 })
3459 // Test that the server returning an invalid SRTP profile is
3460 // flagged as an error by the client.
3461 testCases = append(testCases, testCase{
3462 protocol: dtls,
3463 name: "SRTP-Client-NoMatch",
3464 config: Config{
3465 Bugs: ProtocolBugs{
3466 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
3467 },
3468 },
3469 flags: []string{
3470 "-srtp-profiles",
3471 "SRTP_AES128_CM_SHA1_80",
3472 },
3473 shouldFail: true,
3474 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
3475 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003476 // Test SCT list.
David Benjamin61f95272014-11-25 01:55:35 -05003477 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003478 name: "SignedCertificateTimestampList-Client",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003479 testType: clientTest,
David Benjamin61f95272014-11-25 01:55:35 -05003480 flags: []string{
3481 "-enable-signed-cert-timestamps",
3482 "-expect-signed-cert-timestamps",
3483 base64.StdEncoding.EncodeToString(testSCTList),
3484 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003485 resumeSession: true,
David Benjamin61f95272014-11-25 01:55:35 -05003486 })
Adam Langley33ad2b52015-07-20 17:43:53 -07003487 testCases = append(testCases, testCase{
David Benjaminc0577622015-09-12 18:28:38 -04003488 name: "SignedCertificateTimestampList-Server",
Paul Lietar4fac72e2015-09-09 13:44:55 +01003489 testType: serverTest,
3490 flags: []string{
3491 "-signed-cert-timestamps",
3492 base64.StdEncoding.EncodeToString(testSCTList),
3493 },
3494 expectedSCTList: testSCTList,
Paul Lietar62be8ac2015-09-16 10:03:30 +01003495 resumeSession: true,
Paul Lietar4fac72e2015-09-09 13:44:55 +01003496 })
3497 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07003498 testType: clientTest,
3499 name: "ClientHelloPadding",
3500 config: Config{
3501 Bugs: ProtocolBugs{
3502 RequireClientHelloSize: 512,
3503 },
3504 },
3505 // This hostname just needs to be long enough to push the
3506 // ClientHello into F5's danger zone between 256 and 511 bytes
3507 // long.
3508 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
3509 })
David Benjaminc7ce9772015-10-09 19:32:41 -04003510
3511 // Extensions should not function in SSL 3.0.
3512 testCases = append(testCases, testCase{
3513 testType: serverTest,
3514 name: "SSLv3Extensions-NoALPN",
3515 config: Config{
3516 MaxVersion: VersionSSL30,
3517 NextProtos: []string{"foo", "bar", "baz"},
3518 },
3519 flags: []string{
3520 "-select-alpn", "foo",
3521 },
3522 expectNoNextProto: true,
3523 })
3524
3525 // Test session tickets separately as they follow a different codepath.
3526 testCases = append(testCases, testCase{
3527 testType: serverTest,
3528 name: "SSLv3Extensions-NoTickets",
3529 config: Config{
3530 MaxVersion: VersionSSL30,
3531 Bugs: ProtocolBugs{
3532 // Historically, session tickets in SSL 3.0
3533 // failed in different ways depending on whether
3534 // the client supported renegotiation_info.
3535 NoRenegotiationInfo: true,
3536 },
3537 },
3538 resumeSession: true,
3539 })
3540 testCases = append(testCases, testCase{
3541 testType: serverTest,
3542 name: "SSLv3Extensions-NoTickets2",
3543 config: Config{
3544 MaxVersion: VersionSSL30,
3545 },
3546 resumeSession: true,
3547 })
3548
3549 // But SSL 3.0 does send and process renegotiation_info.
3550 testCases = append(testCases, testCase{
3551 testType: serverTest,
3552 name: "SSLv3Extensions-RenegotiationInfo",
3553 config: Config{
3554 MaxVersion: VersionSSL30,
3555 Bugs: ProtocolBugs{
3556 RequireRenegotiationInfo: true,
3557 },
3558 },
3559 })
3560 testCases = append(testCases, testCase{
3561 testType: serverTest,
3562 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
3563 config: Config{
3564 MaxVersion: VersionSSL30,
3565 Bugs: ProtocolBugs{
3566 NoRenegotiationInfo: true,
3567 SendRenegotiationSCSV: true,
3568 RequireRenegotiationInfo: true,
3569 },
3570 },
3571 })
David Benjamine78bfde2014-09-06 12:45:15 -04003572}
3573
David Benjamin01fe8202014-09-24 15:21:44 -04003574func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04003575 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04003576 for _, resumeVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05003577 protocols := []protocol{tls}
3578 if sessionVers.hasDTLS && resumeVers.hasDTLS {
3579 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05003580 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003581 for _, protocol := range protocols {
3582 suffix := "-" + sessionVers.name + "-" + resumeVers.name
3583 if protocol == dtls {
3584 suffix += "-DTLS"
3585 }
3586
David Benjaminece3de92015-03-16 18:02:20 -04003587 if sessionVers.version == resumeVers.version {
3588 testCases = append(testCases, testCase{
3589 protocol: protocol,
3590 name: "Resume-Client" + suffix,
3591 resumeSession: true,
3592 config: Config{
3593 MaxVersion: sessionVers.version,
3594 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003595 },
David Benjaminece3de92015-03-16 18:02:20 -04003596 expectedVersion: sessionVers.version,
3597 expectedResumeVersion: resumeVers.version,
3598 })
3599 } else {
3600 testCases = append(testCases, testCase{
3601 protocol: protocol,
3602 name: "Resume-Client-Mismatch" + suffix,
3603 resumeSession: true,
3604 config: Config{
3605 MaxVersion: sessionVers.version,
3606 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin8b8c0062014-11-23 02:47:52 -05003607 },
David Benjaminece3de92015-03-16 18:02:20 -04003608 expectedVersion: sessionVers.version,
3609 resumeConfig: &Config{
3610 MaxVersion: resumeVers.version,
3611 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3612 Bugs: ProtocolBugs{
3613 AllowSessionVersionMismatch: true,
3614 },
3615 },
3616 expectedResumeVersion: resumeVers.version,
3617 shouldFail: true,
3618 expectedError: ":OLD_SESSION_VERSION_NOT_RETURNED:",
3619 })
3620 }
David Benjamin8b8c0062014-11-23 02:47:52 -05003621
3622 testCases = append(testCases, testCase{
3623 protocol: protocol,
3624 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003625 resumeSession: true,
3626 config: Config{
3627 MaxVersion: sessionVers.version,
3628 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3629 },
3630 expectedVersion: sessionVers.version,
3631 resumeConfig: &Config{
3632 MaxVersion: resumeVers.version,
3633 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3634 },
3635 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003636 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05003637 expectedResumeVersion: resumeVers.version,
3638 })
3639
David Benjamin8b8c0062014-11-23 02:47:52 -05003640 testCases = append(testCases, testCase{
3641 protocol: protocol,
3642 testType: serverTest,
3643 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05003644 resumeSession: true,
3645 config: Config{
3646 MaxVersion: sessionVers.version,
3647 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3648 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07003649 expectedVersion: sessionVers.version,
3650 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05003651 resumeConfig: &Config{
3652 MaxVersion: resumeVers.version,
3653 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
3654 },
3655 expectedResumeVersion: resumeVers.version,
3656 })
3657 }
David Benjamin01fe8202014-09-24 15:21:44 -04003658 }
3659 }
David Benjaminece3de92015-03-16 18:02:20 -04003660
3661 testCases = append(testCases, testCase{
3662 name: "Resume-Client-CipherMismatch",
3663 resumeSession: true,
3664 config: Config{
3665 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3666 },
3667 resumeConfig: &Config{
3668 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3669 Bugs: ProtocolBugs{
3670 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
3671 },
3672 },
3673 shouldFail: true,
3674 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
3675 })
David Benjamin01fe8202014-09-24 15:21:44 -04003676}
3677
Adam Langley2ae77d22014-10-28 17:29:33 -07003678func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04003679 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04003680 testCases = append(testCases, testCase{
3681 testType: serverTest,
David Benjamin44d3eed2015-05-21 01:29:55 -04003682 name: "Renegotiate-Server-Forbidden",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003683 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04003684 shouldFail: true,
3685 expectedError: ":NO_RENEGOTIATION:",
3686 expectedLocalError: "remote error: no renegotiation",
3687 })
Adam Langley5021b222015-06-12 18:27:58 -07003688 // The server shouldn't echo the renegotiation extension unless
3689 // requested by the client.
3690 testCases = append(testCases, testCase{
3691 testType: serverTest,
3692 name: "Renegotiate-Server-NoExt",
3693 config: Config{
3694 Bugs: ProtocolBugs{
3695 NoRenegotiationInfo: true,
3696 RequireRenegotiationInfo: true,
3697 },
3698 },
3699 shouldFail: true,
3700 expectedLocalError: "renegotiation extension missing",
3701 })
3702 // The renegotiation SCSV should be sufficient for the server to echo
3703 // the extension.
3704 testCases = append(testCases, testCase{
3705 testType: serverTest,
3706 name: "Renegotiate-Server-NoExt-SCSV",
3707 config: Config{
3708 Bugs: ProtocolBugs{
3709 NoRenegotiationInfo: true,
3710 SendRenegotiationSCSV: true,
3711 RequireRenegotiationInfo: true,
3712 },
3713 },
3714 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07003715 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003716 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04003717 config: Config{
3718 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04003719 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04003720 },
3721 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003722 renegotiate: 1,
3723 flags: []string{
3724 "-renegotiate-freely",
3725 "-expect-total-renegotiations", "1",
3726 },
David Benjamincdea40c2015-03-19 14:09:43 -04003727 })
3728 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003729 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003730 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003731 config: Config{
3732 Bugs: ProtocolBugs{
3733 EmptyRenegotiationInfo: true,
3734 },
3735 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003736 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003737 shouldFail: true,
3738 expectedError: ":RENEGOTIATION_MISMATCH:",
3739 })
3740 testCases = append(testCases, testCase{
3741 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003742 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003743 config: Config{
3744 Bugs: ProtocolBugs{
3745 BadRenegotiationInfo: true,
3746 },
3747 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003748 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07003749 shouldFail: true,
3750 expectedError: ":RENEGOTIATION_MISMATCH:",
3751 })
3752 testCases = append(testCases, testCase{
Adam Langleybe9eda42015-06-12 18:01:50 -07003753 name: "Renegotiate-Client-NoExt",
David Benjamincff0b902015-05-15 23:09:47 -04003754 config: Config{
3755 Bugs: ProtocolBugs{
3756 NoRenegotiationInfo: true,
3757 },
3758 },
3759 shouldFail: true,
3760 expectedError: ":UNSAFE_LEGACY_RENEGOTIATION_DISABLED:",
3761 flags: []string{"-no-legacy-server-connect"},
3762 })
3763 testCases = append(testCases, testCase{
3764 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003765 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04003766 config: Config{
3767 Bugs: ProtocolBugs{
3768 NoRenegotiationInfo: true,
3769 },
3770 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003771 flags: []string{
3772 "-renegotiate-freely",
3773 "-expect-total-renegotiations", "1",
3774 },
David Benjamincff0b902015-05-15 23:09:47 -04003775 })
3776 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07003777 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003778 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003779 config: Config{
3780 CipherSuites: []uint16{TLS_RSA_WITH_RC4_128_SHA},
3781 },
3782 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003783 flags: []string{
3784 "-renegotiate-freely",
3785 "-expect-total-renegotiations", "1",
3786 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07003787 })
3788 testCases = append(testCases, testCase{
3789 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003790 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07003791 config: Config{
3792 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3793 },
3794 renegotiateCiphers: []uint16{TLS_RSA_WITH_RC4_128_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003795 flags: []string{
3796 "-renegotiate-freely",
3797 "-expect-total-renegotiations", "1",
3798 },
David Benjaminb16346b2015-04-08 19:16:58 -04003799 })
3800 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05003801 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003802 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05003803 config: Config{
3804 MaxVersion: VersionTLS10,
3805 Bugs: ProtocolBugs{
3806 RequireSameRenegoClientVersion: true,
3807 },
3808 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003809 flags: []string{
3810 "-renegotiate-freely",
3811 "-expect-total-renegotiations", "1",
3812 },
David Benjaminc44b1df2014-11-23 12:11:01 -05003813 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07003814 testCases = append(testCases, testCase{
3815 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003816 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07003817 config: Config{
3818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3819 NextProtos: []string{"foo"},
3820 },
3821 flags: []string{
3822 "-false-start",
3823 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003824 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04003825 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07003826 },
3827 shimWritesFirst: true,
3828 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003829
3830 // Client-side renegotiation controls.
3831 testCases = append(testCases, testCase{
3832 name: "Renegotiate-Client-Forbidden-1",
3833 renegotiate: 1,
3834 shouldFail: true,
3835 expectedError: ":NO_RENEGOTIATION:",
3836 expectedLocalError: "remote error: no renegotiation",
3837 })
3838 testCases = append(testCases, testCase{
3839 name: "Renegotiate-Client-Once-1",
3840 renegotiate: 1,
3841 flags: []string{
3842 "-renegotiate-once",
3843 "-expect-total-renegotiations", "1",
3844 },
3845 })
3846 testCases = append(testCases, testCase{
3847 name: "Renegotiate-Client-Freely-1",
3848 renegotiate: 1,
3849 flags: []string{
3850 "-renegotiate-freely",
3851 "-expect-total-renegotiations", "1",
3852 },
3853 })
3854 testCases = append(testCases, testCase{
3855 name: "Renegotiate-Client-Once-2",
3856 renegotiate: 2,
3857 flags: []string{"-renegotiate-once"},
3858 shouldFail: true,
3859 expectedError: ":NO_RENEGOTIATION:",
3860 expectedLocalError: "remote error: no renegotiation",
3861 })
3862 testCases = append(testCases, testCase{
3863 name: "Renegotiate-Client-Freely-2",
3864 renegotiate: 2,
3865 flags: []string{
3866 "-renegotiate-freely",
3867 "-expect-total-renegotiations", "2",
3868 },
3869 })
Adam Langley2ae77d22014-10-28 17:29:33 -07003870}
3871
David Benjamin5e961c12014-11-07 01:48:35 -05003872func addDTLSReplayTests() {
3873 // Test that sequence number replays are detected.
3874 testCases = append(testCases, testCase{
3875 protocol: dtls,
3876 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04003877 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003878 replayWrites: true,
3879 })
3880
David Benjamin8e6db492015-07-25 18:29:23 -04003881 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05003882 // than the retransmit window.
3883 testCases = append(testCases, testCase{
3884 protocol: dtls,
3885 name: "DTLS-Replay-LargeGaps",
3886 config: Config{
3887 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04003888 SequenceNumberMapping: func(in uint64) uint64 {
3889 return in * 127
3890 },
David Benjamin5e961c12014-11-07 01:48:35 -05003891 },
3892 },
David Benjamin8e6db492015-07-25 18:29:23 -04003893 messageCount: 200,
3894 replayWrites: true,
3895 })
3896
3897 // Test the incoming sequence number changing non-monotonically.
3898 testCases = append(testCases, testCase{
3899 protocol: dtls,
3900 name: "DTLS-Replay-NonMonotonic",
3901 config: Config{
3902 Bugs: ProtocolBugs{
3903 SequenceNumberMapping: func(in uint64) uint64 {
3904 return in ^ 31
3905 },
3906 },
3907 },
3908 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05003909 replayWrites: true,
3910 })
3911}
3912
David Benjamin000800a2014-11-14 01:43:59 -05003913var testHashes = []struct {
3914 name string
3915 id uint8
3916}{
3917 {"SHA1", hashSHA1},
3918 {"SHA224", hashSHA224},
3919 {"SHA256", hashSHA256},
3920 {"SHA384", hashSHA384},
3921 {"SHA512", hashSHA512},
3922}
3923
3924func addSigningHashTests() {
3925 // Make sure each hash works. Include some fake hashes in the list and
3926 // ensure they're ignored.
3927 for _, hash := range testHashes {
3928 testCases = append(testCases, testCase{
3929 name: "SigningHash-ClientAuth-" + hash.name,
3930 config: Config{
3931 ClientAuth: RequireAnyClientCert,
3932 SignatureAndHashes: []signatureAndHash{
3933 {signatureRSA, 42},
3934 {signatureRSA, hash.id},
3935 {signatureRSA, 255},
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-Sign-" + hash.name,
3947 config: Config{
3948 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3949 SignatureAndHashes: []signatureAndHash{
3950 {signatureRSA, 42},
3951 {signatureRSA, hash.id},
3952 {signatureRSA, 255},
3953 },
3954 },
3955 })
3956 }
3957
3958 // Test that hash resolution takes the signature type into account.
3959 testCases = append(testCases, testCase{
3960 name: "SigningHash-ClientAuth-SignatureType",
3961 config: Config{
3962 ClientAuth: RequireAnyClientCert,
3963 SignatureAndHashes: []signatureAndHash{
3964 {signatureECDSA, hashSHA512},
3965 {signatureRSA, hashSHA384},
3966 {signatureECDSA, hashSHA1},
3967 },
3968 },
3969 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003970 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3971 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05003972 },
3973 })
3974
3975 testCases = append(testCases, testCase{
3976 testType: serverTest,
3977 name: "SigningHash-ServerKeyExchange-SignatureType",
3978 config: Config{
3979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3980 SignatureAndHashes: []signatureAndHash{
3981 {signatureECDSA, hashSHA512},
3982 {signatureRSA, hashSHA384},
3983 {signatureECDSA, hashSHA1},
3984 },
3985 },
3986 })
3987
3988 // Test that, if the list is missing, the peer falls back to SHA-1.
3989 testCases = append(testCases, testCase{
3990 name: "SigningHash-ClientAuth-Fallback",
3991 config: Config{
3992 ClientAuth: RequireAnyClientCert,
3993 SignatureAndHashes: []signatureAndHash{
3994 {signatureRSA, hashSHA1},
3995 },
3996 Bugs: ProtocolBugs{
3997 NoSignatureAndHashes: true,
3998 },
3999 },
4000 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004001 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4002 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05004003 },
4004 })
4005
4006 testCases = append(testCases, testCase{
4007 testType: serverTest,
4008 name: "SigningHash-ServerKeyExchange-Fallback",
4009 config: Config{
4010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4011 SignatureAndHashes: []signatureAndHash{
4012 {signatureRSA, hashSHA1},
4013 },
4014 Bugs: ProtocolBugs{
4015 NoSignatureAndHashes: true,
4016 },
4017 },
4018 })
David Benjamin72dc7832015-03-16 17:49:43 -04004019
4020 // Test that hash preferences are enforced. BoringSSL defaults to
4021 // rejecting MD5 signatures.
4022 testCases = append(testCases, testCase{
4023 testType: serverTest,
4024 name: "SigningHash-ClientAuth-Enforced",
4025 config: Config{
4026 Certificates: []Certificate{rsaCertificate},
4027 SignatureAndHashes: []signatureAndHash{
4028 {signatureRSA, hashMD5},
4029 // Advertise SHA-1 so the handshake will
4030 // proceed, but the shim's preferences will be
4031 // ignored in CertificateVerify generation, so
4032 // MD5 will be chosen.
4033 {signatureRSA, hashSHA1},
4034 },
4035 Bugs: ProtocolBugs{
4036 IgnorePeerSignatureAlgorithmPreferences: true,
4037 },
4038 },
4039 flags: []string{"-require-any-client-certificate"},
4040 shouldFail: true,
4041 expectedError: ":WRONG_SIGNATURE_TYPE:",
4042 })
4043
4044 testCases = append(testCases, testCase{
4045 name: "SigningHash-ServerKeyExchange-Enforced",
4046 config: Config{
4047 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4048 SignatureAndHashes: []signatureAndHash{
4049 {signatureRSA, hashMD5},
4050 },
4051 Bugs: ProtocolBugs{
4052 IgnorePeerSignatureAlgorithmPreferences: true,
4053 },
4054 },
4055 shouldFail: true,
4056 expectedError: ":WRONG_SIGNATURE_TYPE:",
4057 })
Steven Valdez0d62f262015-09-04 12:41:04 -04004058
4059 // Test that the agreed upon digest respects the client preferences and
4060 // the server digests.
4061 testCases = append(testCases, testCase{
4062 name: "Agree-Digest-Fallback",
4063 config: Config{
4064 ClientAuth: RequireAnyClientCert,
4065 SignatureAndHashes: []signatureAndHash{
4066 {signatureRSA, hashSHA512},
4067 {signatureRSA, hashSHA1},
4068 },
4069 },
4070 flags: []string{
4071 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4072 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4073 },
4074 digestPrefs: "SHA256",
4075 expectedClientCertSignatureHash: hashSHA1,
4076 })
4077 testCases = append(testCases, testCase{
4078 name: "Agree-Digest-SHA256",
4079 config: Config{
4080 ClientAuth: RequireAnyClientCert,
4081 SignatureAndHashes: []signatureAndHash{
4082 {signatureRSA, hashSHA1},
4083 {signatureRSA, hashSHA256},
4084 },
4085 },
4086 flags: []string{
4087 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4088 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4089 },
4090 digestPrefs: "SHA256,SHA1",
4091 expectedClientCertSignatureHash: hashSHA256,
4092 })
4093 testCases = append(testCases, testCase{
4094 name: "Agree-Digest-SHA1",
4095 config: Config{
4096 ClientAuth: RequireAnyClientCert,
4097 SignatureAndHashes: []signatureAndHash{
4098 {signatureRSA, hashSHA1},
4099 },
4100 },
4101 flags: []string{
4102 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4103 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4104 },
4105 digestPrefs: "SHA512,SHA256,SHA1",
4106 expectedClientCertSignatureHash: hashSHA1,
4107 })
4108 testCases = append(testCases, testCase{
4109 name: "Agree-Digest-Default",
4110 config: Config{
4111 ClientAuth: RequireAnyClientCert,
4112 SignatureAndHashes: []signatureAndHash{
4113 {signatureRSA, hashSHA256},
4114 {signatureECDSA, hashSHA256},
4115 {signatureRSA, hashSHA1},
4116 {signatureECDSA, hashSHA1},
4117 },
4118 },
4119 flags: []string{
4120 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4121 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4122 },
4123 expectedClientCertSignatureHash: hashSHA256,
4124 })
David Benjamin000800a2014-11-14 01:43:59 -05004125}
4126
David Benjamin83f90402015-01-27 01:09:43 -05004127// timeouts is the retransmit schedule for BoringSSL. It doubles and
4128// caps at 60 seconds. On the 13th timeout, it gives up.
4129var timeouts = []time.Duration{
4130 1 * time.Second,
4131 2 * time.Second,
4132 4 * time.Second,
4133 8 * time.Second,
4134 16 * time.Second,
4135 32 * time.Second,
4136 60 * time.Second,
4137 60 * time.Second,
4138 60 * time.Second,
4139 60 * time.Second,
4140 60 * time.Second,
4141 60 * time.Second,
4142 60 * time.Second,
4143}
4144
4145func addDTLSRetransmitTests() {
4146 // Test that this is indeed the timeout schedule. Stress all
4147 // four patterns of handshake.
4148 for i := 1; i < len(timeouts); i++ {
4149 number := strconv.Itoa(i)
4150 testCases = append(testCases, testCase{
4151 protocol: dtls,
4152 name: "DTLS-Retransmit-Client-" + number,
4153 config: Config{
4154 Bugs: ProtocolBugs{
4155 TimeoutSchedule: timeouts[:i],
4156 },
4157 },
4158 resumeSession: true,
4159 flags: []string{"-async"},
4160 })
4161 testCases = append(testCases, testCase{
4162 protocol: dtls,
4163 testType: serverTest,
4164 name: "DTLS-Retransmit-Server-" + number,
4165 config: Config{
4166 Bugs: ProtocolBugs{
4167 TimeoutSchedule: timeouts[:i],
4168 },
4169 },
4170 resumeSession: true,
4171 flags: []string{"-async"},
4172 })
4173 }
4174
4175 // Test that exceeding the timeout schedule hits a read
4176 // timeout.
4177 testCases = append(testCases, testCase{
4178 protocol: dtls,
4179 name: "DTLS-Retransmit-Timeout",
4180 config: Config{
4181 Bugs: ProtocolBugs{
4182 TimeoutSchedule: timeouts,
4183 },
4184 },
4185 resumeSession: true,
4186 flags: []string{"-async"},
4187 shouldFail: true,
4188 expectedError: ":READ_TIMEOUT_EXPIRED:",
4189 })
4190
4191 // Test that timeout handling has a fudge factor, due to API
4192 // problems.
4193 testCases = append(testCases, testCase{
4194 protocol: dtls,
4195 name: "DTLS-Retransmit-Fudge",
4196 config: Config{
4197 Bugs: ProtocolBugs{
4198 TimeoutSchedule: []time.Duration{
4199 timeouts[0] - 10*time.Millisecond,
4200 },
4201 },
4202 },
4203 resumeSession: true,
4204 flags: []string{"-async"},
4205 })
David Benjamin7eaab4c2015-03-02 19:01:16 -05004206
4207 // Test that the final Finished retransmitting isn't
4208 // duplicated if the peer badly fragments everything.
4209 testCases = append(testCases, testCase{
4210 testType: serverTest,
4211 protocol: dtls,
4212 name: "DTLS-Retransmit-Fragmented",
4213 config: Config{
4214 Bugs: ProtocolBugs{
4215 TimeoutSchedule: []time.Duration{timeouts[0]},
4216 MaxHandshakeRecordLength: 2,
4217 },
4218 },
4219 flags: []string{"-async"},
4220 })
David Benjamin83f90402015-01-27 01:09:43 -05004221}
4222
David Benjaminc565ebb2015-04-03 04:06:36 -04004223func addExportKeyingMaterialTests() {
4224 for _, vers := range tlsVersions {
4225 if vers.version == VersionSSL30 {
4226 continue
4227 }
4228 testCases = append(testCases, testCase{
4229 name: "ExportKeyingMaterial-" + vers.name,
4230 config: Config{
4231 MaxVersion: vers.version,
4232 },
4233 exportKeyingMaterial: 1024,
4234 exportLabel: "label",
4235 exportContext: "context",
4236 useExportContext: true,
4237 })
4238 testCases = append(testCases, testCase{
4239 name: "ExportKeyingMaterial-NoContext-" + vers.name,
4240 config: Config{
4241 MaxVersion: vers.version,
4242 },
4243 exportKeyingMaterial: 1024,
4244 })
4245 testCases = append(testCases, testCase{
4246 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
4247 config: Config{
4248 MaxVersion: vers.version,
4249 },
4250 exportKeyingMaterial: 1024,
4251 useExportContext: true,
4252 })
4253 testCases = append(testCases, testCase{
4254 name: "ExportKeyingMaterial-Small-" + vers.name,
4255 config: Config{
4256 MaxVersion: vers.version,
4257 },
4258 exportKeyingMaterial: 1,
4259 exportLabel: "label",
4260 exportContext: "context",
4261 useExportContext: true,
4262 })
4263 }
4264 testCases = append(testCases, testCase{
4265 name: "ExportKeyingMaterial-SSL3",
4266 config: Config{
4267 MaxVersion: VersionSSL30,
4268 },
4269 exportKeyingMaterial: 1024,
4270 exportLabel: "label",
4271 exportContext: "context",
4272 useExportContext: true,
4273 shouldFail: true,
4274 expectedError: "failed to export keying material",
4275 })
4276}
4277
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004278func addTLSUniqueTests() {
4279 for _, isClient := range []bool{false, true} {
4280 for _, isResumption := range []bool{false, true} {
4281 for _, hasEMS := range []bool{false, true} {
4282 var suffix string
4283 if isResumption {
4284 suffix = "Resume-"
4285 } else {
4286 suffix = "Full-"
4287 }
4288
4289 if hasEMS {
4290 suffix += "EMS-"
4291 } else {
4292 suffix += "NoEMS-"
4293 }
4294
4295 if isClient {
4296 suffix += "Client"
4297 } else {
4298 suffix += "Server"
4299 }
4300
4301 test := testCase{
4302 name: "TLSUnique-" + suffix,
4303 testTLSUnique: true,
4304 config: Config{
4305 Bugs: ProtocolBugs{
4306 NoExtendedMasterSecret: !hasEMS,
4307 },
4308 },
4309 }
4310
4311 if isResumption {
4312 test.resumeSession = true
4313 test.resumeConfig = &Config{
4314 Bugs: ProtocolBugs{
4315 NoExtendedMasterSecret: !hasEMS,
4316 },
4317 }
4318 }
4319
4320 if isResumption && !hasEMS {
4321 test.shouldFail = true
4322 test.expectedError = "failed to get tls-unique"
4323 }
4324
4325 testCases = append(testCases, test)
4326 }
4327 }
4328 }
4329}
4330
Adam Langley09505632015-07-30 18:10:13 -07004331func addCustomExtensionTests() {
4332 expectedContents := "custom extension"
4333 emptyString := ""
4334
4335 for _, isClient := range []bool{false, true} {
4336 suffix := "Server"
4337 flag := "-enable-server-custom-extension"
4338 testType := serverTest
4339 if isClient {
4340 suffix = "Client"
4341 flag = "-enable-client-custom-extension"
4342 testType = clientTest
4343 }
4344
4345 testCases = append(testCases, testCase{
4346 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004347 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004348 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004349 Bugs: ProtocolBugs{
4350 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004351 ExpectedCustomExtension: &expectedContents,
4352 },
4353 },
4354 flags: []string{flag},
4355 })
4356
4357 // If the parse callback fails, the handshake should also fail.
4358 testCases = append(testCases, testCase{
4359 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004360 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004361 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004362 Bugs: ProtocolBugs{
4363 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07004364 ExpectedCustomExtension: &expectedContents,
4365 },
4366 },
David Benjamin399e7c92015-07-30 23:01:27 -04004367 flags: []string{flag},
4368 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004369 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4370 })
4371
4372 // If the add callback fails, the handshake should also fail.
4373 testCases = append(testCases, testCase{
4374 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004375 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004376 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004377 Bugs: ProtocolBugs{
4378 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07004379 ExpectedCustomExtension: &expectedContents,
4380 },
4381 },
David Benjamin399e7c92015-07-30 23:01:27 -04004382 flags: []string{flag, "-custom-extension-fail-add"},
4383 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07004384 expectedError: ":CUSTOM_EXTENSION_ERROR:",
4385 })
4386
4387 // If the add callback returns zero, no extension should be
4388 // added.
4389 skipCustomExtension := expectedContents
4390 if isClient {
4391 // For the case where the client skips sending the
4392 // custom extension, the server must not “echo” it.
4393 skipCustomExtension = ""
4394 }
4395 testCases = append(testCases, testCase{
4396 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04004397 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07004398 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004399 Bugs: ProtocolBugs{
4400 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07004401 ExpectedCustomExtension: &emptyString,
4402 },
4403 },
4404 flags: []string{flag, "-custom-extension-skip"},
4405 })
4406 }
4407
4408 // The custom extension add callback should not be called if the client
4409 // doesn't send the extension.
4410 testCases = append(testCases, testCase{
4411 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04004412 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07004413 config: Config{
David Benjamin399e7c92015-07-30 23:01:27 -04004414 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07004415 ExpectedCustomExtension: &emptyString,
4416 },
4417 },
4418 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
4419 })
Adam Langley2deb9842015-08-07 11:15:37 -07004420
4421 // Test an unknown extension from the server.
4422 testCases = append(testCases, testCase{
4423 testType: clientTest,
4424 name: "UnknownExtension-Client",
4425 config: Config{
4426 Bugs: ProtocolBugs{
4427 CustomExtension: expectedContents,
4428 },
4429 },
4430 shouldFail: true,
4431 expectedError: ":UNEXPECTED_EXTENSION:",
4432 })
Adam Langley09505632015-07-30 18:10:13 -07004433}
4434
Adam Langley7c803a62015-06-15 15:35:05 -07004435func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07004436 defer wg.Done()
4437
4438 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08004439 var err error
4440
4441 if *mallocTest < 0 {
4442 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004443 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08004444 } else {
4445 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
4446 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07004447 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08004448 if err != nil {
4449 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
4450 }
4451 break
4452 }
4453 }
4454 }
Adam Langley95c29f32014-06-20 12:00:00 -07004455 statusChan <- statusMsg{test: test, err: err}
4456 }
4457}
4458
4459type statusMsg struct {
4460 test *testCase
4461 started bool
4462 err error
4463}
4464
David Benjamin5f237bc2015-02-11 17:14:15 -05004465func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
Adam Langley95c29f32014-06-20 12:00:00 -07004466 var started, done, failed, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07004467
David Benjamin5f237bc2015-02-11 17:14:15 -05004468 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07004469 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05004470 if !*pipe {
4471 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05004472 var erase string
4473 for i := 0; i < lineLen; i++ {
4474 erase += "\b \b"
4475 }
4476 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05004477 }
4478
Adam Langley95c29f32014-06-20 12:00:00 -07004479 if msg.started {
4480 started++
4481 } else {
4482 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05004483
4484 if msg.err != nil {
4485 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
4486 failed++
4487 testOutput.addResult(msg.test.name, "FAIL")
4488 } else {
4489 if *pipe {
4490 // Print each test instead of a status line.
4491 fmt.Printf("PASSED (%s)\n", msg.test.name)
4492 }
4493 testOutput.addResult(msg.test.name, "PASS")
4494 }
Adam Langley95c29f32014-06-20 12:00:00 -07004495 }
4496
David Benjamin5f237bc2015-02-11 17:14:15 -05004497 if !*pipe {
4498 // Print a new status line.
4499 line := fmt.Sprintf("%d/%d/%d/%d", failed, done, started, total)
4500 lineLen = len(line)
4501 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07004502 }
Adam Langley95c29f32014-06-20 12:00:00 -07004503 }
David Benjamin5f237bc2015-02-11 17:14:15 -05004504
4505 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07004506}
4507
4508func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07004509 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07004510 *resourceDir = path.Clean(*resourceDir)
Adam Langley95c29f32014-06-20 12:00:00 -07004511
Adam Langley7c803a62015-06-15 15:35:05 -07004512 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07004513 addCipherSuiteTests()
4514 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07004515 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07004516 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04004517 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08004518 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004519 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05004520 addMinimumVersionTests()
David Benjamin5c24a1d2014-08-31 00:59:27 -04004521 addD5BugTests()
David Benjamine78bfde2014-09-06 12:45:15 -04004522 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04004523 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07004524 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07004525 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05004526 addDTLSReplayTests()
David Benjamin000800a2014-11-14 01:43:59 -05004527 addSigningHashTests()
David Benjamin83f90402015-01-27 01:09:43 -05004528 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04004529 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07004530 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07004531 addCustomExtensionTests()
David Benjamin43ec06f2014-08-05 02:28:57 -04004532 for _, async := range []bool{false, true} {
4533 for _, splitHandshake := range []bool{false, true} {
David Benjamin6fd297b2014-08-11 18:43:38 -04004534 for _, protocol := range []protocol{tls, dtls} {
4535 addStateMachineCoverageTests(async, splitHandshake, protocol)
4536 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004537 }
4538 }
Adam Langley95c29f32014-06-20 12:00:00 -07004539
4540 var wg sync.WaitGroup
4541
Adam Langley7c803a62015-06-15 15:35:05 -07004542 statusChan := make(chan statusMsg, *numWorkers)
4543 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05004544 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07004545
David Benjamin025b3d32014-07-01 19:53:04 -04004546 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07004547
Adam Langley7c803a62015-06-15 15:35:05 -07004548 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07004549 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07004550 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07004551 }
4552
David Benjamin025b3d32014-07-01 19:53:04 -04004553 for i := range testCases {
Adam Langley7c803a62015-06-15 15:35:05 -07004554 if len(*testToRun) == 0 || *testToRun == testCases[i].name {
David Benjamin025b3d32014-07-01 19:53:04 -04004555 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07004556 }
4557 }
4558
4559 close(testChan)
4560 wg.Wait()
4561 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05004562 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07004563
4564 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05004565
4566 if *jsonOutput != "" {
4567 if err := testOutput.writeTo(*jsonOutput); err != nil {
4568 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
4569 }
4570 }
David Benjamin2ab7a862015-04-04 17:02:18 -04004571
4572 if !testOutput.allPassed {
4573 os.Exit(1)
4574 }
Adam Langley95c29f32014-06-20 12:00:00 -07004575}