blob: e164843892f9b0ce818fae1781eb9bf9c0a595c6 [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 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.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjaminc07afb72016-09-22 10:18:58 -0400369func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
David Benjaminc07afb72016-09-22 10:18:58 -0400390 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjaminc07afb72016-09-22 10:18:58 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
David Benjamin01a90572016-09-22 00:11:43 -0400439 if *deterministic {
440 config.Time = func() time.Time { return time.Unix(1234, 1234) }
441 }
David Benjamine54af062016-08-08 19:21:18 -0400442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400467 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
Steven Valdez32635b82016-08-16 11:25:03 -0400618 for i := 0; i < test.sendKeyUpdates; i++ {
David Benjamin7f0965a2016-09-30 15:14:01 -0400619 if err := tlsConn.SendKeyUpdate(); err != nil {
620 return err
621 }
Steven Valdez32635b82016-08-16 11:25:03 -0400622 }
623
David Benjamina8ebe222015-06-06 03:04:39 -0400624 for i := 0; i < test.sendEmptyRecords; i++ {
625 tlsConn.Write(nil)
626 }
627
David Benjamin24f346d2015-06-06 03:28:08 -0400628 for i := 0; i < test.sendWarningAlerts; i++ {
629 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
630 }
631
David Benjamin47921102016-07-28 11:29:18 -0400632 if test.sendHalfHelloRequest {
633 tlsConn.SendHalfHelloRequest()
634 }
635
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400636 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700637 if test.renegotiateCiphers != nil {
638 config.CipherSuites = test.renegotiateCiphers
639 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400640 for i := 0; i < test.renegotiate; i++ {
641 if err := tlsConn.Renegotiate(); err != nil {
642 return err
643 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700644 }
645 } else if test.renegotiateCiphers != nil {
646 panic("renegotiateCiphers without renegotiate")
647 }
648
David Benjamin5fa3eba2015-01-22 16:35:40 -0500649 if test.damageFirstWrite {
650 connDamage.setDamage(true)
651 tlsConn.Write([]byte("DAMAGED WRITE"))
652 connDamage.setDamage(false)
653 }
654
David Benjamin8e6db492015-07-25 18:29:23 -0400655 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700656 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400657 if test.protocol == dtls {
658 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
659 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700660 // Read until EOF.
661 _, err := io.Copy(ioutil.Discard, tlsConn)
662 return err
663 }
David Benjamin4417d052015-04-05 04:17:25 -0400664 if messageLen == 0 {
665 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700666 }
Adam Langley95c29f32014-06-20 12:00:00 -0700667
David Benjamin8e6db492015-07-25 18:29:23 -0400668 messageCount := test.messageCount
669 if messageCount == 0 {
670 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400671 }
672
David Benjamin8e6db492015-07-25 18:29:23 -0400673 for j := 0; j < messageCount; j++ {
674 testMessage := make([]byte, messageLen)
675 for i := range testMessage {
676 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400677 }
David Benjamin8e6db492015-07-25 18:29:23 -0400678 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700679
Steven Valdez32635b82016-08-16 11:25:03 -0400680 for i := 0; i < test.sendKeyUpdates; i++ {
681 tlsConn.SendKeyUpdate()
682 }
683
David Benjamin8e6db492015-07-25 18:29:23 -0400684 for i := 0; i < test.sendEmptyRecords; i++ {
685 tlsConn.Write(nil)
686 }
687
688 for i := 0; i < test.sendWarningAlerts; i++ {
689 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
690 }
691
David Benjamin4f75aaf2015-09-01 16:53:10 -0400692 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400693 // The shim will not respond.
694 continue
695 }
696
David Benjamin8e6db492015-07-25 18:29:23 -0400697 buf := make([]byte, len(testMessage))
698 if test.protocol == dtls {
699 bufTmp := make([]byte, len(buf)+1)
700 n, err := tlsConn.Read(bufTmp)
701 if err != nil {
702 return err
703 }
704 if n != len(buf) {
705 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
706 }
707 copy(buf, bufTmp)
708 } else {
709 _, err := io.ReadFull(tlsConn, buf)
710 if err != nil {
711 return err
712 }
713 }
714
715 for i, v := range buf {
716 if v != testMessage[i]^0xff {
717 return fmt.Errorf("bad reply contents at byte %d", i)
718 }
Adam Langley95c29f32014-06-20 12:00:00 -0700719 }
720 }
721
722 return nil
723}
724
David Benjamin325b5c32014-07-01 19:40:31 -0400725func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400726 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700727 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400728 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700729 }
David Benjamin325b5c32014-07-01 19:40:31 -0400730 valgrindArgs = append(valgrindArgs, path)
731 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732
David Benjamin325b5c32014-07-01 19:40:31 -0400733 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700734}
735
David Benjamin325b5c32014-07-01 19:40:31 -0400736func gdbOf(path string, args ...string) *exec.Cmd {
737 xtermArgs := []string{"-e", "gdb", "--args"}
738 xtermArgs = append(xtermArgs, path)
739 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700740
David Benjamin325b5c32014-07-01 19:40:31 -0400741 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700742}
743
David Benjamind16bf342015-12-18 00:53:12 -0500744func lldbOf(path string, args ...string) *exec.Cmd {
745 xtermArgs := []string{"-e", "lldb", "--"}
746 xtermArgs = append(xtermArgs, path)
747 xtermArgs = append(xtermArgs, args...)
748
749 return exec.Command("xterm", xtermArgs...)
750}
751
EKR842ae6c2016-07-27 09:22:05 +0200752var (
753 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
754 errUnimplemented = errors.New("child process does not implement needed flags")
755)
Adam Langley69a01602014-11-17 17:26:55 -0800756
David Benjamin87c8a642015-02-21 01:54:29 -0500757// accept accepts a connection from listener, unless waitChan signals a process
758// exit first.
759func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
760 type connOrError struct {
761 conn net.Conn
762 err error
763 }
764 connChan := make(chan connOrError, 1)
765 go func() {
766 conn, err := listener.Accept()
767 connChan <- connOrError{conn, err}
768 close(connChan)
769 }()
770 select {
771 case result := <-connChan:
772 return result.conn, result.err
773 case childErr := <-waitChan:
774 waitChan <- childErr
775 return nil, fmt.Errorf("child exited early: %s", childErr)
776 }
777}
778
EKRf71d7ed2016-08-06 13:25:12 -0700779func translateExpectedError(errorStr string) string {
780 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
781 return translated
782 }
783
784 if *looseErrors {
785 return ""
786 }
787
788 return errorStr
789}
790
Adam Langley7c803a62015-06-15 15:35:05 -0700791func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400792 // Help debugging panics on the Go side.
793 defer func() {
794 if r := recover(); r != nil {
795 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
796 panic(r)
797 }
798 }()
799
Adam Langley38311732014-10-16 19:04:35 -0700800 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
801 panic("Error expected without shouldFail in " + test.name)
802 }
803
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700804 if test.expectResumeRejected && !test.resumeSession {
805 panic("expectResumeRejected without resumeSession in " + test.name)
806 }
807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
809 if err != nil {
810 panic(err)
811 }
812 defer func() {
813 if listener != nil {
814 listener.Close()
815 }
816 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700817
David Benjamin87c8a642015-02-21 01:54:29 -0500818 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400819 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400820 flags = append(flags, "-server")
821
David Benjamin025b3d32014-07-01 19:53:04 -0400822 flags = append(flags, "-key-file")
823 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828
829 flags = append(flags, "-cert-file")
830 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700831 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400832 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700833 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400834 }
835 }
David Benjamin5a593af2014-08-11 19:51:50 -0400836
David Benjamin6fd297b2014-08-11 18:43:38 -0400837 if test.protocol == dtls {
838 flags = append(flags, "-dtls")
839 }
840
David Benjamin46662482016-08-17 00:51:00 -0400841 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400842 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400843 resumeCount++
844 if test.resumeRenewedSession {
845 resumeCount++
846 }
847 }
848
849 if resumeCount > 0 {
850 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400851 }
852
David Benjamine58c4f52014-08-24 03:47:07 -0400853 if test.shimWritesFirst {
854 flags = append(flags, "-shim-writes-first")
855 }
856
David Benjamin30789da2015-08-29 22:56:45 -0400857 if test.shimShutsDown {
858 flags = append(flags, "-shim-shuts-down")
859 }
860
David Benjaminc565ebb2015-04-03 04:06:36 -0400861 if test.exportKeyingMaterial > 0 {
862 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
863 flags = append(flags, "-export-label", test.exportLabel)
864 flags = append(flags, "-export-context", test.exportContext)
865 if test.useExportContext {
866 flags = append(flags, "-use-export-context")
867 }
868 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700869 if test.expectResumeRejected {
870 flags = append(flags, "-expect-session-miss")
871 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400872
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700873 if test.testTLSUnique {
874 flags = append(flags, "-tls-unique")
875 }
876
David Benjamin025b3d32014-07-01 19:53:04 -0400877 flags = append(flags, test.flags...)
878
879 var shim *exec.Cmd
880 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700881 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700882 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500884 } else if *useLLDB {
885 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400886 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700887 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400888 }
David Benjamin025b3d32014-07-01 19:53:04 -0400889 shim.Stdin = os.Stdin
890 var stdoutBuf, stderrBuf bytes.Buffer
891 shim.Stdout = &stdoutBuf
892 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800893 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500894 shim.Env = os.Environ()
895 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800896 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400897 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800898 }
899 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
900 }
David Benjamin025b3d32014-07-01 19:53:04 -0400901
902 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700903 panic(err)
904 }
David Benjamin87c8a642015-02-21 01:54:29 -0500905 waitChan := make(chan error, 1)
906 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700907
908 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700909
David Benjamin7a4aaa42016-09-20 17:58:14 -0400910 if *deterministic {
911 config.Rand = &deterministicRand{}
912 }
913
David Benjamin87c8a642015-02-21 01:54:29 -0500914 conn, err := acceptOrWait(listener, waitChan)
915 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400916 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500917 conn.Close()
918 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500919
David Benjamin46662482016-08-17 00:51:00 -0400920 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400921 var resumeConfig Config
922 if test.resumeConfig != nil {
923 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400924 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500925 resumeConfig.SessionTicketKey = config.SessionTicketKey
926 resumeConfig.ClientSessionCache = config.ClientSessionCache
927 resumeConfig.ServerSessionCache = config.ServerSessionCache
928 }
David Benjamin2e045a92016-06-08 13:09:56 -0400929 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400930 } else {
931 resumeConfig = config
932 }
David Benjamin87c8a642015-02-21 01:54:29 -0500933 var connResume net.Conn
934 connResume, err = acceptOrWait(listener, waitChan)
935 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400936 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500937 connResume.Close()
938 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400939 }
940
David Benjamin87c8a642015-02-21 01:54:29 -0500941 // Close the listener now. This is to avoid hangs should the shim try to
942 // open more connections than expected.
943 listener.Close()
944 listener = nil
945
946 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400947 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800948 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200949 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
950 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800951 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200952 case 89:
953 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400954 case 99:
955 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800956 }
957 }
Adam Langley95c29f32014-06-20 12:00:00 -0700958
David Benjamin9bea3492016-03-02 10:59:16 -0500959 // Account for Windows line endings.
960 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
961 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500962
963 // Separate the errors from the shim and those from tools like
964 // AddressSanitizer.
965 var extraStderr string
966 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
967 stderr = stderrParts[0]
968 extraStderr = stderrParts[1]
969 }
970
Adam Langley95c29f32014-06-20 12:00:00 -0700971 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700972 expectedError := translateExpectedError(test.expectedError)
973 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200974
Adam Langleyac61fa32014-06-23 12:03:11 -0700975 localError := "none"
976 if err != nil {
977 localError = err.Error()
978 }
979 if len(test.expectedLocalError) != 0 {
980 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
981 }
Adam Langley95c29f32014-06-20 12:00:00 -0700982
983 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700984 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700985 if childErr != nil {
986 childError = childErr.Error()
987 }
988
989 var msg string
990 switch {
991 case failed && !test.shouldFail:
992 msg = "unexpected failure"
993 case !failed && test.shouldFail:
994 msg = "unexpected success"
995 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700996 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700997 default:
998 panic("internal error")
999 }
1000
David Benjamin9aafb642016-09-20 19:36:53 -04001001 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001002 }
1003
David Benjamind2ba8892016-09-20 19:41:04 -04001004 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001005 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001006 }
1007
David Benjamind2ba8892016-09-20 19:41:04 -04001008 if *useValgrind && isValgrindError {
1009 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1010 }
1011
Adam Langley95c29f32014-06-20 12:00:00 -07001012 return nil
1013}
1014
1015var tlsVersions = []struct {
1016 name string
1017 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001018 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001019 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001020}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001021 {"SSL3", VersionSSL30, "-no-ssl3", false},
1022 {"TLS1", VersionTLS10, "-no-tls1", true},
1023 {"TLS11", VersionTLS11, "-no-tls11", false},
1024 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001025 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001026}
1027
1028var testCipherSuites = []struct {
1029 name string
1030 id uint16
1031}{
1032 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001033 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001034 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001035 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001036 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001037 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001038 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001039 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1040 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1043 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001045 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1046 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001047 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1048 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001049 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001050 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001051 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001052 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001053 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001054 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001055 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001056 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001057 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001058 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001059 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001060 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001061 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1062 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1063 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1064 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001065 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1066 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001067 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1068 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001069 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001070 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1071 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1072 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001073 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001074}
1075
David Benjamin8b8c0062014-11-23 02:47:52 -05001076func hasComponent(suiteName, component string) bool {
1077 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1078}
1079
David Benjaminf7768e42014-08-31 02:06:47 -04001080func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001081 return hasComponent(suiteName, "GCM") ||
1082 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001083 hasComponent(suiteName, "SHA384") ||
1084 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001085}
1086
Nick Harper1fd39d82016-06-14 18:14:35 -07001087func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001088 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001089}
1090
David Benjamin8b8c0062014-11-23 02:47:52 -05001091func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001092 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001093}
1094
Adam Langleya7997f12015-05-14 17:38:50 -07001095func bigFromHex(hex string) *big.Int {
1096 ret, ok := new(big.Int).SetString(hex, 16)
1097 if !ok {
1098 panic("failed to parse hex number 0x" + hex)
1099 }
1100 return ret
1101}
1102
Adam Langley7c803a62015-06-15 15:35:05 -07001103func addBasicTests() {
1104 basicTests := []testCase{
1105 {
Adam Langley7c803a62015-06-15 15:35:05 -07001106 name: "NoFallbackSCSV",
1107 config: Config{
1108 Bugs: ProtocolBugs{
1109 FailIfNotFallbackSCSV: true,
1110 },
1111 },
1112 shouldFail: true,
1113 expectedLocalError: "no fallback SCSV found",
1114 },
1115 {
1116 name: "SendFallbackSCSV",
1117 config: Config{
1118 Bugs: ProtocolBugs{
1119 FailIfNotFallbackSCSV: true,
1120 },
1121 },
1122 flags: []string{"-fallback-scsv"},
1123 },
1124 {
1125 name: "ClientCertificateTypes",
1126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001127 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001128 ClientAuth: RequestClientCert,
1129 ClientCertificateTypes: []byte{
1130 CertTypeDSSSign,
1131 CertTypeRSASign,
1132 CertTypeECDSASign,
1133 },
1134 },
1135 flags: []string{
1136 "-expect-certificate-types",
1137 base64.StdEncoding.EncodeToString([]byte{
1138 CertTypeDSSSign,
1139 CertTypeRSASign,
1140 CertTypeECDSASign,
1141 }),
1142 },
1143 },
1144 {
Adam Langley7c803a62015-06-15 15:35:05 -07001145 name: "UnauthenticatedECDH",
1146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001147 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001148 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1149 Bugs: ProtocolBugs{
1150 UnauthenticatedECDH: true,
1151 },
1152 },
1153 shouldFail: true,
1154 expectedError: ":UNEXPECTED_MESSAGE:",
1155 },
1156 {
1157 name: "SkipCertificateStatus",
1158 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001159 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001160 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1161 Bugs: ProtocolBugs{
1162 SkipCertificateStatus: true,
1163 },
1164 },
1165 flags: []string{
1166 "-enable-ocsp-stapling",
1167 },
1168 },
1169 {
1170 name: "SkipServerKeyExchange",
1171 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001172 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1174 Bugs: ProtocolBugs{
1175 SkipServerKeyExchange: true,
1176 },
1177 },
1178 shouldFail: true,
1179 expectedError: ":UNEXPECTED_MESSAGE:",
1180 },
1181 {
Adam Langley7c803a62015-06-15 15:35:05 -07001182 testType: serverTest,
1183 name: "Alert",
1184 config: Config{
1185 Bugs: ProtocolBugs{
1186 SendSpuriousAlert: alertRecordOverflow,
1187 },
1188 },
1189 shouldFail: true,
1190 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1191 },
1192 {
1193 protocol: dtls,
1194 testType: serverTest,
1195 name: "Alert-DTLS",
1196 config: Config{
1197 Bugs: ProtocolBugs{
1198 SendSpuriousAlert: alertRecordOverflow,
1199 },
1200 },
1201 shouldFail: true,
1202 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1203 },
1204 {
1205 testType: serverTest,
1206 name: "FragmentAlert",
1207 config: Config{
1208 Bugs: ProtocolBugs{
1209 FragmentAlert: true,
1210 SendSpuriousAlert: alertRecordOverflow,
1211 },
1212 },
1213 shouldFail: true,
1214 expectedError: ":BAD_ALERT:",
1215 },
1216 {
1217 protocol: dtls,
1218 testType: serverTest,
1219 name: "FragmentAlert-DTLS",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 FragmentAlert: true,
1223 SendSpuriousAlert: alertRecordOverflow,
1224 },
1225 },
1226 shouldFail: true,
1227 expectedError: ":BAD_ALERT:",
1228 },
1229 {
1230 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001231 name: "DoubleAlert",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 DoubleAlert: true,
1235 SendSpuriousAlert: alertRecordOverflow,
1236 },
1237 },
1238 shouldFail: true,
1239 expectedError: ":BAD_ALERT:",
1240 },
1241 {
1242 protocol: dtls,
1243 testType: serverTest,
1244 name: "DoubleAlert-DTLS",
1245 config: Config{
1246 Bugs: ProtocolBugs{
1247 DoubleAlert: true,
1248 SendSpuriousAlert: alertRecordOverflow,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":BAD_ALERT:",
1253 },
1254 {
Adam Langley7c803a62015-06-15 15:35:05 -07001255 name: "SkipNewSessionTicket",
1256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001257 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001258 Bugs: ProtocolBugs{
1259 SkipNewSessionTicket: true,
1260 },
1261 },
1262 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001263 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001264 },
1265 {
1266 testType: serverTest,
1267 name: "FallbackSCSV",
1268 config: Config{
1269 MaxVersion: VersionTLS11,
1270 Bugs: ProtocolBugs{
1271 SendFallbackSCSV: true,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":INAPPROPRIATE_FALLBACK:",
1276 },
1277 {
1278 testType: serverTest,
1279 name: "FallbackSCSV-VersionMatch",
1280 config: Config{
1281 Bugs: ProtocolBugs{
1282 SendFallbackSCSV: true,
1283 },
1284 },
1285 },
1286 {
1287 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001288 name: "FallbackSCSV-VersionMatch-TLS12",
1289 config: Config{
1290 MaxVersion: VersionTLS12,
1291 Bugs: ProtocolBugs{
1292 SendFallbackSCSV: true,
1293 },
1294 },
1295 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1296 },
1297 {
1298 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001299 name: "FragmentedClientVersion",
1300 config: Config{
1301 Bugs: ProtocolBugs{
1302 MaxHandshakeRecordLength: 1,
1303 FragmentClientVersion: true,
1304 },
1305 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001306 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 },
1308 {
Adam Langley7c803a62015-06-15 15:35:05 -07001309 testType: serverTest,
1310 name: "HttpGET",
1311 sendPrefix: "GET / HTTP/1.0\n",
1312 shouldFail: true,
1313 expectedError: ":HTTP_REQUEST:",
1314 },
1315 {
1316 testType: serverTest,
1317 name: "HttpPOST",
1318 sendPrefix: "POST / HTTP/1.0\n",
1319 shouldFail: true,
1320 expectedError: ":HTTP_REQUEST:",
1321 },
1322 {
1323 testType: serverTest,
1324 name: "HttpHEAD",
1325 sendPrefix: "HEAD / HTTP/1.0\n",
1326 shouldFail: true,
1327 expectedError: ":HTTP_REQUEST:",
1328 },
1329 {
1330 testType: serverTest,
1331 name: "HttpPUT",
1332 sendPrefix: "PUT / HTTP/1.0\n",
1333 shouldFail: true,
1334 expectedError: ":HTTP_REQUEST:",
1335 },
1336 {
1337 testType: serverTest,
1338 name: "HttpCONNECT",
1339 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1340 shouldFail: true,
1341 expectedError: ":HTTPS_PROXY_REQUEST:",
1342 },
1343 {
1344 testType: serverTest,
1345 name: "Garbage",
1346 sendPrefix: "blah",
1347 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001348 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001349 },
1350 {
Adam Langley7c803a62015-06-15 15:35:05 -07001351 name: "RSAEphemeralKey",
1352 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001353 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001354 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1355 Bugs: ProtocolBugs{
1356 RSAEphemeralKey: true,
1357 },
1358 },
1359 shouldFail: true,
1360 expectedError: ":UNEXPECTED_MESSAGE:",
1361 },
1362 {
1363 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001364 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001365 shouldFail: true,
1366 expectedError: ":WRONG_SSL_VERSION:",
1367 },
1368 {
1369 protocol: dtls,
1370 name: "DisableEverything-DTLS",
1371 flags: []string{"-no-tls12", "-no-tls1"},
1372 shouldFail: true,
1373 expectedError: ":WRONG_SSL_VERSION:",
1374 },
1375 {
Adam Langley7c803a62015-06-15 15:35:05 -07001376 protocol: dtls,
1377 testType: serverTest,
1378 name: "MTU",
1379 config: Config{
1380 Bugs: ProtocolBugs{
1381 MaxPacketLength: 256,
1382 },
1383 },
1384 flags: []string{"-mtu", "256"},
1385 },
1386 {
1387 protocol: dtls,
1388 testType: serverTest,
1389 name: "MTUExceeded",
1390 config: Config{
1391 Bugs: ProtocolBugs{
1392 MaxPacketLength: 255,
1393 },
1394 },
1395 flags: []string{"-mtu", "256"},
1396 shouldFail: true,
1397 expectedLocalError: "dtls: exceeded maximum packet length",
1398 },
1399 {
1400 name: "CertMismatchRSA",
1401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001402 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001403 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001404 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001405 Bugs: ProtocolBugs{
1406 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1411 },
1412 {
1413 name: "CertMismatchECDSA",
1414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001415 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001417 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001418 Bugs: ProtocolBugs{
1419 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1424 },
1425 {
1426 name: "EmptyCertificateList",
1427 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001428 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001429 Bugs: ProtocolBugs{
1430 EmptyCertificateList: true,
1431 },
1432 },
1433 shouldFail: true,
1434 expectedError: ":DECODE_ERROR:",
1435 },
1436 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001437 name: "EmptyCertificateList-TLS13",
1438 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001439 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001440 Bugs: ProtocolBugs{
1441 EmptyCertificateList: true,
1442 },
1443 },
1444 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001445 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001446 },
1447 {
Adam Langley7c803a62015-06-15 15:35:05 -07001448 name: "TLSFatalBadPackets",
1449 damageFirstWrite: true,
1450 shouldFail: true,
1451 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1452 },
1453 {
1454 protocol: dtls,
1455 name: "DTLSIgnoreBadPackets",
1456 damageFirstWrite: true,
1457 },
1458 {
1459 protocol: dtls,
1460 name: "DTLSIgnoreBadPackets-Async",
1461 damageFirstWrite: true,
1462 flags: []string{"-async"},
1463 },
1464 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001465 name: "AppDataBeforeHandshake",
1466 config: Config{
1467 Bugs: ProtocolBugs{
1468 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":UNEXPECTED_RECORD:",
1473 },
1474 {
1475 name: "AppDataBeforeHandshake-Empty",
1476 config: Config{
1477 Bugs: ProtocolBugs{
1478 AppDataBeforeHandshake: []byte{},
1479 },
1480 },
1481 shouldFail: true,
1482 expectedError: ":UNEXPECTED_RECORD:",
1483 },
1484 {
1485 protocol: dtls,
1486 name: "AppDataBeforeHandshake-DTLS",
1487 config: Config{
1488 Bugs: ProtocolBugs{
1489 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1490 },
1491 },
1492 shouldFail: true,
1493 expectedError: ":UNEXPECTED_RECORD:",
1494 },
1495 {
1496 protocol: dtls,
1497 name: "AppDataBeforeHandshake-DTLS-Empty",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 AppDataBeforeHandshake: []byte{},
1501 },
1502 },
1503 shouldFail: true,
1504 expectedError: ":UNEXPECTED_RECORD:",
1505 },
1506 {
Adam Langley7c803a62015-06-15 15:35:05 -07001507 name: "AppDataAfterChangeCipherSpec",
1508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001509 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001510 Bugs: ProtocolBugs{
1511 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1512 },
1513 },
1514 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001515 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001516 },
1517 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001518 name: "AppDataAfterChangeCipherSpec-Empty",
1519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001520 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001521 Bugs: ProtocolBugs{
1522 AppDataAfterChangeCipherSpec: []byte{},
1523 },
1524 },
1525 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001526 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001527 },
1528 {
Adam Langley7c803a62015-06-15 15:35:05 -07001529 protocol: dtls,
1530 name: "AppDataAfterChangeCipherSpec-DTLS",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1535 },
1536 },
1537 // BoringSSL's DTLS implementation will drop the out-of-order
1538 // application data.
1539 },
1540 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001541 protocol: dtls,
1542 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001544 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001545 Bugs: ProtocolBugs{
1546 AppDataAfterChangeCipherSpec: []byte{},
1547 },
1548 },
1549 // BoringSSL's DTLS implementation will drop the out-of-order
1550 // application data.
1551 },
1552 {
Adam Langley7c803a62015-06-15 15:35:05 -07001553 name: "AlertAfterChangeCipherSpec",
1554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001555 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001556 Bugs: ProtocolBugs{
1557 AlertAfterChangeCipherSpec: alertRecordOverflow,
1558 },
1559 },
1560 shouldFail: true,
1561 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1562 },
1563 {
1564 protocol: dtls,
1565 name: "AlertAfterChangeCipherSpec-DTLS",
1566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001567 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001568 Bugs: ProtocolBugs{
1569 AlertAfterChangeCipherSpec: alertRecordOverflow,
1570 },
1571 },
1572 shouldFail: true,
1573 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1574 },
1575 {
1576 protocol: dtls,
1577 name: "ReorderHandshakeFragments-Small-DTLS",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 ReorderHandshakeFragments: true,
1581 // Small enough that every handshake message is
1582 // fragmented.
1583 MaxHandshakeRecordLength: 2,
1584 },
1585 },
1586 },
1587 {
1588 protocol: dtls,
1589 name: "ReorderHandshakeFragments-Large-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 ReorderHandshakeFragments: true,
1593 // Large enough that no handshake message is
1594 // fragmented.
1595 MaxHandshakeRecordLength: 2048,
1596 },
1597 },
1598 },
1599 {
1600 protocol: dtls,
1601 name: "MixCompleteMessageWithFragments-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 ReorderHandshakeFragments: true,
1605 MixCompleteMessageWithFragments: true,
1606 MaxHandshakeRecordLength: 2,
1607 },
1608 },
1609 },
1610 {
1611 name: "SendInvalidRecordType",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 SendInvalidRecordType: true,
1615 },
1616 },
1617 shouldFail: true,
1618 expectedError: ":UNEXPECTED_RECORD:",
1619 },
1620 {
1621 protocol: dtls,
1622 name: "SendInvalidRecordType-DTLS",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 SendInvalidRecordType: true,
1626 },
1627 },
1628 shouldFail: true,
1629 expectedError: ":UNEXPECTED_RECORD:",
1630 },
1631 {
1632 name: "FalseStart-SkipServerSecondLeg",
1633 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001634 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1636 NextProtos: []string{"foo"},
1637 Bugs: ProtocolBugs{
1638 SkipNewSessionTicket: true,
1639 SkipChangeCipherSpec: true,
1640 SkipFinished: true,
1641 ExpectFalseStart: true,
1642 },
1643 },
1644 flags: []string{
1645 "-false-start",
1646 "-handshake-never-done",
1647 "-advertise-alpn", "\x03foo",
1648 },
1649 shimWritesFirst: true,
1650 shouldFail: true,
1651 expectedError: ":UNEXPECTED_RECORD:",
1652 },
1653 {
1654 name: "FalseStart-SkipServerSecondLeg-Implicit",
1655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001656 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001657 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1658 NextProtos: []string{"foo"},
1659 Bugs: ProtocolBugs{
1660 SkipNewSessionTicket: true,
1661 SkipChangeCipherSpec: true,
1662 SkipFinished: true,
1663 },
1664 },
1665 flags: []string{
1666 "-implicit-handshake",
1667 "-false-start",
1668 "-handshake-never-done",
1669 "-advertise-alpn", "\x03foo",
1670 },
1671 shouldFail: true,
1672 expectedError: ":UNEXPECTED_RECORD:",
1673 },
1674 {
1675 testType: serverTest,
1676 name: "FailEarlyCallback",
1677 flags: []string{"-fail-early-callback"},
1678 shouldFail: true,
1679 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001680 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001681 },
1682 {
Adam Langley7c803a62015-06-15 15:35:05 -07001683 protocol: dtls,
1684 name: "FragmentMessageTypeMismatch-DTLS",
1685 config: Config{
1686 Bugs: ProtocolBugs{
1687 MaxHandshakeRecordLength: 2,
1688 FragmentMessageTypeMismatch: true,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":FRAGMENT_MISMATCH:",
1693 },
1694 {
1695 protocol: dtls,
1696 name: "FragmentMessageLengthMismatch-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 MaxHandshakeRecordLength: 2,
1700 FragmentMessageLengthMismatch: true,
1701 },
1702 },
1703 shouldFail: true,
1704 expectedError: ":FRAGMENT_MISMATCH:",
1705 },
1706 {
1707 protocol: dtls,
1708 name: "SplitFragments-Header-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 SplitFragments: 2,
1712 },
1713 },
1714 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001715 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001716 },
1717 {
1718 protocol: dtls,
1719 name: "SplitFragments-Boundary-DTLS",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 SplitFragments: dtlsRecordHeaderLen,
1723 },
1724 },
1725 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001726 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001727 },
1728 {
1729 protocol: dtls,
1730 name: "SplitFragments-Body-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 SplitFragments: dtlsRecordHeaderLen + 1,
1734 },
1735 },
1736 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001737 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001738 },
1739 {
1740 protocol: dtls,
1741 name: "SendEmptyFragments-DTLS",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 SendEmptyFragments: true,
1745 },
1746 },
1747 },
1748 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001749 name: "BadFinished-Client",
1750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001751 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001752 Bugs: ProtocolBugs{
1753 BadFinished: true,
1754 },
1755 },
1756 shouldFail: true,
1757 expectedError: ":DIGEST_CHECK_FAILED:",
1758 },
1759 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001760 name: "BadFinished-Client-TLS13",
1761 config: Config{
1762 MaxVersion: VersionTLS13,
1763 Bugs: ProtocolBugs{
1764 BadFinished: true,
1765 },
1766 },
1767 shouldFail: true,
1768 expectedError: ":DIGEST_CHECK_FAILED:",
1769 },
1770 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001771 testType: serverTest,
1772 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001774 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001783 testType: serverTest,
1784 name: "BadFinished-Server-TLS13",
1785 config: Config{
1786 MaxVersion: VersionTLS13,
1787 Bugs: ProtocolBugs{
1788 BadFinished: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":DIGEST_CHECK_FAILED:",
1793 },
1794 {
Adam Langley7c803a62015-06-15 15:35:05 -07001795 name: "FalseStart-BadFinished",
1796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001797 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1799 NextProtos: []string{"foo"},
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 ExpectFalseStart: true,
1803 },
1804 },
1805 flags: []string{
1806 "-false-start",
1807 "-handshake-never-done",
1808 "-advertise-alpn", "\x03foo",
1809 },
1810 shimWritesFirst: true,
1811 shouldFail: true,
1812 expectedError: ":DIGEST_CHECK_FAILED:",
1813 },
1814 {
1815 name: "NoFalseStart-NoALPN",
1816 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001817 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1819 Bugs: ProtocolBugs{
1820 ExpectFalseStart: true,
1821 AlertBeforeFalseStartTest: alertAccessDenied,
1822 },
1823 },
1824 flags: []string{
1825 "-false-start",
1826 },
1827 shimWritesFirst: true,
1828 shouldFail: true,
1829 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1830 expectedLocalError: "tls: peer did not false start: EOF",
1831 },
1832 {
1833 name: "NoFalseStart-NoAEAD",
1834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1837 NextProtos: []string{"foo"},
1838 Bugs: ProtocolBugs{
1839 ExpectFalseStart: true,
1840 AlertBeforeFalseStartTest: alertAccessDenied,
1841 },
1842 },
1843 flags: []string{
1844 "-false-start",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1850 expectedLocalError: "tls: peer did not false start: EOF",
1851 },
1852 {
1853 name: "NoFalseStart-RSA",
1854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001855 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001856 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1857 NextProtos: []string{"foo"},
1858 Bugs: ProtocolBugs{
1859 ExpectFalseStart: true,
1860 AlertBeforeFalseStartTest: alertAccessDenied,
1861 },
1862 },
1863 flags: []string{
1864 "-false-start",
1865 "-advertise-alpn", "\x03foo",
1866 },
1867 shimWritesFirst: true,
1868 shouldFail: true,
1869 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1870 expectedLocalError: "tls: peer did not false start: EOF",
1871 },
1872 {
1873 name: "NoFalseStart-DHE_RSA",
1874 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001875 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001876 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1877 NextProtos: []string{"foo"},
1878 Bugs: ProtocolBugs{
1879 ExpectFalseStart: true,
1880 AlertBeforeFalseStartTest: alertAccessDenied,
1881 },
1882 },
1883 flags: []string{
1884 "-false-start",
1885 "-advertise-alpn", "\x03foo",
1886 },
1887 shimWritesFirst: true,
1888 shouldFail: true,
1889 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1890 expectedLocalError: "tls: peer did not false start: EOF",
1891 },
1892 {
Adam Langley7c803a62015-06-15 15:35:05 -07001893 protocol: dtls,
1894 name: "SendSplitAlert-Sync",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 SendSplitAlert: true,
1898 },
1899 },
1900 },
1901 {
1902 protocol: dtls,
1903 name: "SendSplitAlert-Async",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 SendSplitAlert: true,
1907 },
1908 },
1909 flags: []string{"-async"},
1910 },
1911 {
1912 protocol: dtls,
1913 name: "PackDTLSHandshake",
1914 config: Config{
1915 Bugs: ProtocolBugs{
1916 MaxHandshakeRecordLength: 2,
1917 PackHandshakeFragments: 20,
1918 PackHandshakeRecords: 200,
1919 },
1920 },
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 name: "SendEmptyRecords-Pass",
1924 sendEmptyRecords: 32,
1925 },
1926 {
1927 name: "SendEmptyRecords",
1928 sendEmptyRecords: 33,
1929 shouldFail: true,
1930 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1931 },
1932 {
1933 name: "SendEmptyRecords-Async",
1934 sendEmptyRecords: 33,
1935 flags: []string{"-async"},
1936 shouldFail: true,
1937 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1938 },
1939 {
David Benjamine8e84b92016-08-03 15:39:47 -04001940 name: "SendWarningAlerts-Pass",
1941 config: Config{
1942 MaxVersion: VersionTLS12,
1943 },
Adam Langley7c803a62015-06-15 15:35:05 -07001944 sendWarningAlerts: 4,
1945 },
1946 {
David Benjamine8e84b92016-08-03 15:39:47 -04001947 protocol: dtls,
1948 name: "SendWarningAlerts-DTLS-Pass",
1949 config: Config{
1950 MaxVersion: VersionTLS12,
1951 },
Adam Langley7c803a62015-06-15 15:35:05 -07001952 sendWarningAlerts: 4,
1953 },
1954 {
David Benjamine8e84b92016-08-03 15:39:47 -04001955 name: "SendWarningAlerts-TLS13",
1956 config: Config{
1957 MaxVersion: VersionTLS13,
1958 },
1959 sendWarningAlerts: 4,
1960 shouldFail: true,
1961 expectedError: ":BAD_ALERT:",
1962 expectedLocalError: "remote error: error decoding message",
1963 },
1964 {
1965 name: "SendWarningAlerts",
1966 config: Config{
1967 MaxVersion: VersionTLS12,
1968 },
Adam Langley7c803a62015-06-15 15:35:05 -07001969 sendWarningAlerts: 5,
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Async",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 5,
1979 flags: []string{"-async"},
1980 shouldFail: true,
1981 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1982 },
David Benjaminba4594a2015-06-18 18:36:15 -04001983 {
Steven Valdez32635b82016-08-16 11:25:03 -04001984 name: "SendKeyUpdates",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 },
1988 sendKeyUpdates: 33,
1989 shouldFail: true,
1990 expectedError: ":TOO_MANY_KEY_UPDATES:",
1991 },
1992 {
David Benjaminba4594a2015-06-18 18:36:15 -04001993 name: "EmptySessionID",
1994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001995 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001996 SessionTicketsDisabled: true,
1997 },
1998 noSessionCache: true,
1999 flags: []string{"-expect-no-session"},
2000 },
David Benjamin30789da2015-08-29 22:56:45 -04002001 {
2002 name: "Unclean-Shutdown",
2003 config: Config{
2004 Bugs: ProtocolBugs{
2005 NoCloseNotify: true,
2006 ExpectCloseNotify: true,
2007 },
2008 },
2009 shimShutsDown: true,
2010 flags: []string{"-check-close-notify"},
2011 shouldFail: true,
2012 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2013 },
2014 {
2015 name: "Unclean-Shutdown-Ignored",
2016 config: Config{
2017 Bugs: ProtocolBugs{
2018 NoCloseNotify: true,
2019 },
2020 },
2021 shimShutsDown: true,
2022 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002023 {
David Benjaminfa214e42016-05-10 17:03:10 -04002024 name: "Unclean-Shutdown-Alert",
2025 config: Config{
2026 Bugs: ProtocolBugs{
2027 SendAlertOnShutdown: alertDecompressionFailure,
2028 ExpectCloseNotify: true,
2029 },
2030 },
2031 shimShutsDown: true,
2032 flags: []string{"-check-close-notify"},
2033 shouldFail: true,
2034 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2035 },
2036 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002037 name: "LargePlaintext",
2038 config: Config{
2039 Bugs: ProtocolBugs{
2040 SendLargeRecords: true,
2041 },
2042 },
2043 messageLen: maxPlaintext + 1,
2044 shouldFail: true,
2045 expectedError: ":DATA_LENGTH_TOO_LONG:",
2046 },
2047 {
2048 protocol: dtls,
2049 name: "LargePlaintext-DTLS",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 SendLargeRecords: true,
2053 },
2054 },
2055 messageLen: maxPlaintext + 1,
2056 shouldFail: true,
2057 expectedError: ":DATA_LENGTH_TOO_LONG:",
2058 },
2059 {
2060 name: "LargeCiphertext",
2061 config: Config{
2062 Bugs: ProtocolBugs{
2063 SendLargeRecords: true,
2064 },
2065 },
2066 messageLen: maxPlaintext * 2,
2067 shouldFail: true,
2068 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2069 },
2070 {
2071 protocol: dtls,
2072 name: "LargeCiphertext-DTLS",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SendLargeRecords: true,
2076 },
2077 },
2078 messageLen: maxPlaintext * 2,
2079 // Unlike the other four cases, DTLS drops records which
2080 // are invalid before authentication, so the connection
2081 // does not fail.
2082 expectMessageDropped: true,
2083 },
David Benjamindd6fed92015-10-23 17:41:12 -04002084 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002085 name: "BadHelloRequest-1",
2086 renegotiate: 1,
2087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002088 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002089 Bugs: ProtocolBugs{
2090 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2091 },
2092 },
2093 flags: []string{
2094 "-renegotiate-freely",
2095 "-expect-total-renegotiations", "1",
2096 },
2097 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002098 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002099 },
2100 {
2101 name: "BadHelloRequest-2",
2102 renegotiate: 1,
2103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002104 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002105 Bugs: ProtocolBugs{
2106 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2107 },
2108 },
2109 flags: []string{
2110 "-renegotiate-freely",
2111 "-expect-total-renegotiations", "1",
2112 },
2113 shouldFail: true,
2114 expectedError: ":BAD_HELLO_REQUEST:",
2115 },
David Benjaminef1b0092015-11-21 14:05:44 -05002116 {
2117 testType: serverTest,
2118 name: "SupportTicketsWithSessionID",
2119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002120 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002121 SessionTicketsDisabled: true,
2122 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 resumeConfig: &Config{
2124 MaxVersion: VersionTLS12,
2125 },
David Benjaminef1b0092015-11-21 14:05:44 -05002126 resumeSession: true,
2127 },
David Benjamin02edcd02016-07-27 17:40:37 -04002128 {
2129 protocol: dtls,
2130 name: "DTLS-SendExtraFinished",
2131 config: Config{
2132 Bugs: ProtocolBugs{
2133 SendExtraFinished: true,
2134 },
2135 },
2136 shouldFail: true,
2137 expectedError: ":UNEXPECTED_RECORD:",
2138 },
2139 {
2140 protocol: dtls,
2141 name: "DTLS-SendExtraFinished-Reordered",
2142 config: Config{
2143 Bugs: ProtocolBugs{
2144 MaxHandshakeRecordLength: 2,
2145 ReorderHandshakeFragments: true,
2146 SendExtraFinished: true,
2147 },
2148 },
2149 shouldFail: true,
2150 expectedError: ":UNEXPECTED_RECORD:",
2151 },
David Benjamine97fb482016-07-29 09:23:07 -04002152 {
2153 testType: serverTest,
2154 name: "V2ClientHello-EmptyRecordPrefix",
2155 config: Config{
2156 // Choose a cipher suite that does not involve
2157 // elliptic curves, so no extensions are
2158 // involved.
2159 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002160 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002161 Bugs: ProtocolBugs{
2162 SendV2ClientHello: true,
2163 },
2164 },
2165 sendPrefix: string([]byte{
2166 byte(recordTypeHandshake),
2167 3, 1, // version
2168 0, 0, // length
2169 }),
2170 // A no-op empty record may not be sent before V2ClientHello.
2171 shouldFail: true,
2172 expectedError: ":WRONG_VERSION_NUMBER:",
2173 },
2174 {
2175 testType: serverTest,
2176 name: "V2ClientHello-WarningAlertPrefix",
2177 config: Config{
2178 // Choose a cipher suite that does not involve
2179 // elliptic curves, so no extensions are
2180 // involved.
2181 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002182 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002183 Bugs: ProtocolBugs{
2184 SendV2ClientHello: true,
2185 },
2186 },
2187 sendPrefix: string([]byte{
2188 byte(recordTypeAlert),
2189 3, 1, // version
2190 0, 2, // length
2191 alertLevelWarning, byte(alertDecompressionFailure),
2192 }),
2193 // A no-op warning alert may not be sent before V2ClientHello.
2194 shouldFail: true,
2195 expectedError: ":WRONG_VERSION_NUMBER:",
2196 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002197 {
2198 testType: clientTest,
2199 name: "KeyUpdate",
2200 config: Config{
2201 MaxVersion: VersionTLS13,
2202 Bugs: ProtocolBugs{
2203 SendKeyUpdateBeforeEveryAppDataRecord: true,
2204 },
2205 },
2206 },
David Benjaminabe94e32016-09-04 14:18:58 -04002207 {
2208 name: "SendSNIWarningAlert",
2209 config: Config{
2210 MaxVersion: VersionTLS12,
2211 Bugs: ProtocolBugs{
2212 SendSNIWarningAlert: true,
2213 },
2214 },
2215 },
David Benjaminc241d792016-09-09 10:34:20 -04002216 {
2217 testType: serverTest,
2218 name: "ExtraCompressionMethods-TLS12",
2219 config: Config{
2220 MaxVersion: VersionTLS12,
2221 Bugs: ProtocolBugs{
2222 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2223 },
2224 },
2225 },
2226 {
2227 testType: serverTest,
2228 name: "ExtraCompressionMethods-TLS13",
2229 config: Config{
2230 MaxVersion: VersionTLS13,
2231 Bugs: ProtocolBugs{
2232 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2233 },
2234 },
2235 shouldFail: true,
2236 expectedError: ":INVALID_COMPRESSION_LIST:",
2237 expectedLocalError: "remote error: illegal parameter",
2238 },
2239 {
2240 testType: serverTest,
2241 name: "NoNullCompression-TLS12",
2242 config: Config{
2243 MaxVersion: VersionTLS12,
2244 Bugs: ProtocolBugs{
2245 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2246 },
2247 },
2248 shouldFail: true,
2249 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2250 expectedLocalError: "remote error: illegal parameter",
2251 },
2252 {
2253 testType: serverTest,
2254 name: "NoNullCompression-TLS13",
2255 config: Config{
2256 MaxVersion: VersionTLS13,
2257 Bugs: ProtocolBugs{
2258 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2259 },
2260 },
2261 shouldFail: true,
2262 expectedError: ":INVALID_COMPRESSION_LIST:",
2263 expectedLocalError: "remote error: illegal parameter",
2264 },
David Benjamin65ac9972016-09-02 21:35:25 -04002265 {
2266 name: "GREASE-TLS12",
2267 config: Config{
2268 MaxVersion: VersionTLS12,
2269 Bugs: ProtocolBugs{
2270 ExpectGREASE: true,
2271 },
2272 },
2273 flags: []string{"-enable-grease"},
2274 },
2275 {
2276 name: "GREASE-TLS13",
2277 config: Config{
2278 MaxVersion: VersionTLS13,
2279 Bugs: ProtocolBugs{
2280 ExpectGREASE: true,
2281 },
2282 },
2283 flags: []string{"-enable-grease"},
2284 },
Adam Langley7c803a62015-06-15 15:35:05 -07002285 }
Adam Langley7c803a62015-06-15 15:35:05 -07002286 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002287
2288 // Test that very large messages can be received.
2289 cert := rsaCertificate
2290 for i := 0; i < 50; i++ {
2291 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2292 }
2293 testCases = append(testCases, testCase{
2294 name: "LargeMessage",
2295 config: Config{
2296 Certificates: []Certificate{cert},
2297 },
2298 })
2299 testCases = append(testCases, testCase{
2300 protocol: dtls,
2301 name: "LargeMessage-DTLS",
2302 config: Config{
2303 Certificates: []Certificate{cert},
2304 },
2305 })
2306
2307 // They are rejected if the maximum certificate chain length is capped.
2308 testCases = append(testCases, testCase{
2309 name: "LargeMessage-Reject",
2310 config: Config{
2311 Certificates: []Certificate{cert},
2312 },
2313 flags: []string{"-max-cert-list", "16384"},
2314 shouldFail: true,
2315 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2316 })
2317 testCases = append(testCases, testCase{
2318 protocol: dtls,
2319 name: "LargeMessage-Reject-DTLS",
2320 config: Config{
2321 Certificates: []Certificate{cert},
2322 },
2323 flags: []string{"-max-cert-list", "16384"},
2324 shouldFail: true,
2325 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2326 })
Adam Langley7c803a62015-06-15 15:35:05 -07002327}
2328
Adam Langley95c29f32014-06-20 12:00:00 -07002329func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002330 const bogusCipher = 0xfe00
2331
Adam Langley95c29f32014-06-20 12:00:00 -07002332 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002333 const psk = "12345"
2334 const pskIdentity = "luggage combo"
2335
Adam Langley95c29f32014-06-20 12:00:00 -07002336 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002337 var certFile string
2338 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002339 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002340 cert = ecdsaP256Certificate
2341 certFile = ecdsaP256CertificateFile
2342 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002343 } else {
David Benjamin33863262016-07-08 17:20:12 -07002344 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002345 certFile = rsaCertificateFile
2346 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002347 }
2348
David Benjamin48cae082014-10-27 01:06:24 -04002349 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002350 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002351 flags = append(flags,
2352 "-psk", psk,
2353 "-psk-identity", pskIdentity)
2354 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002355 if hasComponent(suite.name, "NULL") {
2356 // NULL ciphers must be explicitly enabled.
2357 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2358 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002359 if hasComponent(suite.name, "CECPQ1") {
2360 // CECPQ1 ciphers must be explicitly enabled.
2361 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2362 }
David Benjamin881f1962016-08-10 18:29:12 -04002363 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2364 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2365 // for now.
2366 flags = append(flags, "-cipher", suite.name)
2367 }
David Benjamin48cae082014-10-27 01:06:24 -04002368
Adam Langley95c29f32014-06-20 12:00:00 -07002369 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002370 for _, protocol := range []protocol{tls, dtls} {
2371 var prefix string
2372 if protocol == dtls {
2373 if !ver.hasDTLS {
2374 continue
2375 }
2376 prefix = "D"
2377 }
Adam Langley95c29f32014-06-20 12:00:00 -07002378
David Benjamin0407e762016-06-17 16:41:18 -04002379 var shouldServerFail, shouldClientFail bool
2380 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2381 // BoringSSL clients accept ECDHE on SSLv3, but
2382 // a BoringSSL server will never select it
2383 // because the extension is missing.
2384 shouldServerFail = true
2385 }
2386 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2387 shouldClientFail = true
2388 shouldServerFail = true
2389 }
David Benjamin54c217c2016-07-13 12:35:25 -04002390 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002391 shouldClientFail = true
2392 shouldServerFail = true
2393 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002394 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2395 shouldClientFail = true
2396 shouldServerFail = true
2397 }
David Benjamin0407e762016-06-17 16:41:18 -04002398 if !isDTLSCipher(suite.name) && protocol == dtls {
2399 shouldClientFail = true
2400 shouldServerFail = true
2401 }
David Benjamin4298d772015-12-19 00:18:25 -05002402
David Benjamin5ecb88b2016-10-04 17:51:35 -04002403 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002404 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002405 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002406 if shouldServerFail {
2407 expectedServerError = ":NO_SHARED_CIPHER:"
2408 }
2409 if shouldClientFail {
2410 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002411 // Configure the server to select ciphers as normal but
2412 // select an incompatible cipher in ServerHello.
2413 serverCipherSuites = nil
2414 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002415 }
David Benjamin025b3d32014-07-01 19:53:04 -04002416
David Benjamin6fd297b2014-08-11 18:43:38 -04002417 testCases = append(testCases, testCase{
2418 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002419 protocol: protocol,
2420
2421 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002422 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002423 MinVersion: ver.version,
2424 MaxVersion: ver.version,
2425 CipherSuites: []uint16{suite.id},
2426 Certificates: []Certificate{cert},
2427 PreSharedKey: []byte(psk),
2428 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002429 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002430 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002431 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002432 },
2433 certFile: certFile,
2434 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002435 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002436 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002437 shouldFail: shouldServerFail,
2438 expectedError: expectedServerError,
2439 })
2440
2441 testCases = append(testCases, testCase{
2442 testType: clientTest,
2443 protocol: protocol,
2444 name: prefix + ver.name + "-" + suite.name + "-client",
2445 config: Config{
2446 MinVersion: ver.version,
2447 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002448 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002449 Certificates: []Certificate{cert},
2450 PreSharedKey: []byte(psk),
2451 PreSharedKeyIdentity: pskIdentity,
2452 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002453 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002454 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002455 },
2456 },
2457 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002458 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002459 shouldFail: shouldClientFail,
2460 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002461 })
David Benjamin2c99d282015-09-01 10:23:00 -04002462
Nick Harper1fd39d82016-06-14 18:14:35 -07002463 if !shouldClientFail {
2464 // Ensure the maximum record size is accepted.
2465 testCases = append(testCases, testCase{
2466 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2467 config: Config{
2468 MinVersion: ver.version,
2469 MaxVersion: ver.version,
2470 CipherSuites: []uint16{suite.id},
2471 Certificates: []Certificate{cert},
2472 PreSharedKey: []byte(psk),
2473 PreSharedKeyIdentity: pskIdentity,
2474 },
2475 flags: flags,
2476 messageLen: maxPlaintext,
2477 })
2478 }
2479 }
David Benjamin2c99d282015-09-01 10:23:00 -04002480 }
Adam Langley95c29f32014-06-20 12:00:00 -07002481 }
Adam Langleya7997f12015-05-14 17:38:50 -07002482
2483 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002484 name: "NoSharedCipher",
2485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002486 MaxVersion: VersionTLS12,
2487 CipherSuites: []uint16{},
2488 },
2489 shouldFail: true,
2490 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2491 })
2492
2493 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002494 name: "NoSharedCipher-TLS13",
2495 config: Config{
2496 MaxVersion: VersionTLS13,
2497 CipherSuites: []uint16{},
2498 },
2499 shouldFail: true,
2500 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2501 })
2502
2503 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002504 name: "UnsupportedCipherSuite",
2505 config: Config{
2506 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002508 Bugs: ProtocolBugs{
2509 IgnorePeerCipherPreferences: true,
2510 },
2511 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002512 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002513 shouldFail: true,
2514 expectedError: ":WRONG_CIPHER_RETURNED:",
2515 })
2516
2517 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002518 name: "ServerHelloBogusCipher",
2519 config: Config{
2520 MaxVersion: VersionTLS12,
2521 Bugs: ProtocolBugs{
2522 SendCipherSuite: bogusCipher,
2523 },
2524 },
2525 shouldFail: true,
2526 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2527 })
2528 testCases = append(testCases, testCase{
2529 name: "ServerHelloBogusCipher-TLS13",
2530 config: Config{
2531 MaxVersion: VersionTLS13,
2532 Bugs: ProtocolBugs{
2533 SendCipherSuite: bogusCipher,
2534 },
2535 },
2536 shouldFail: true,
2537 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2538 })
2539
2540 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002541 name: "WeakDH",
2542 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002543 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002544 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2545 Bugs: ProtocolBugs{
2546 // This is a 1023-bit prime number, generated
2547 // with:
2548 // openssl gendh 1023 | openssl asn1parse -i
2549 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2550 },
2551 },
2552 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002553 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002554 })
Adam Langleycef75832015-09-03 14:51:12 -07002555
David Benjamincd24a392015-11-11 13:23:05 -08002556 testCases = append(testCases, testCase{
2557 name: "SillyDH",
2558 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002559 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002560 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2561 Bugs: ProtocolBugs{
2562 // This is a 4097-bit prime number, generated
2563 // with:
2564 // openssl gendh 4097 | openssl asn1parse -i
2565 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2566 },
2567 },
2568 shouldFail: true,
2569 expectedError: ":DH_P_TOO_LONG:",
2570 })
2571
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002572 // This test ensures that Diffie-Hellman public values are padded with
2573 // zeros so that they're the same length as the prime. This is to avoid
2574 // hitting a bug in yaSSL.
2575 testCases = append(testCases, testCase{
2576 testType: serverTest,
2577 name: "DHPublicValuePadded",
2578 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002579 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002580 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2581 Bugs: ProtocolBugs{
2582 RequireDHPublicValueLen: (1025 + 7) / 8,
2583 },
2584 },
2585 flags: []string{"-use-sparse-dh-prime"},
2586 })
David Benjamincd24a392015-11-11 13:23:05 -08002587
David Benjamin241ae832016-01-15 03:04:54 -05002588 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002589 testCases = append(testCases, testCase{
2590 testType: serverTest,
2591 name: "UnknownCipher",
2592 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002593 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002594 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002595 Bugs: ProtocolBugs{
2596 AdvertiseAllConfiguredCiphers: true,
2597 },
2598 },
2599 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002600
2601 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002602 testCases = append(testCases, testCase{
2603 testType: serverTest,
2604 name: "UnknownCipher-TLS13",
2605 config: Config{
2606 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002607 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002608 Bugs: ProtocolBugs{
2609 AdvertiseAllConfiguredCiphers: true,
2610 },
David Benjamin241ae832016-01-15 03:04:54 -05002611 },
2612 })
2613
David Benjamin78679342016-09-16 19:42:05 -04002614 // Test empty ECDHE_PSK identity hints work as expected.
2615 testCases = append(testCases, testCase{
2616 name: "EmptyECDHEPSKHint",
2617 config: Config{
2618 MaxVersion: VersionTLS12,
2619 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2620 PreSharedKey: []byte("secret"),
2621 },
2622 flags: []string{"-psk", "secret"},
2623 })
2624
2625 // Test empty PSK identity hints work as expected, even if an explicit
2626 // ServerKeyExchange is sent.
2627 testCases = append(testCases, testCase{
2628 name: "ExplicitEmptyPSKHint",
2629 config: Config{
2630 MaxVersion: VersionTLS12,
2631 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2632 PreSharedKey: []byte("secret"),
2633 Bugs: ProtocolBugs{
2634 AlwaysSendPreSharedKeyIdentityHint: true,
2635 },
2636 },
2637 flags: []string{"-psk", "secret"},
2638 })
2639
Adam Langleycef75832015-09-03 14:51:12 -07002640 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2641 // 1.1 specific cipher suite settings. A server is setup with the given
2642 // cipher lists and then a connection is made for each member of
2643 // expectations. The cipher suite that the server selects must match
2644 // the specified one.
2645 var versionSpecificCiphersTest = []struct {
2646 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2647 // expectations is a map from TLS version to cipher suite id.
2648 expectations map[uint16]uint16
2649 }{
2650 {
2651 // Test that the null case (where no version-specific ciphers are set)
2652 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002653 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2654 "", // no ciphers specifically for TLS ≥ 1.0
2655 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002656 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002657 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2658 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2659 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2660 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002661 },
2662 },
2663 {
2664 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2665 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002666 "DES-CBC3-SHA:AES128-SHA", // default
2667 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2668 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002669 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002670 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002671 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2672 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2673 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2674 },
2675 },
2676 {
2677 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2678 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002679 "DES-CBC3-SHA:AES128-SHA", // default
2680 "", // no ciphers specifically for TLS ≥ 1.0
2681 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002682 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002683 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2684 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002685 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2686 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2687 },
2688 },
2689 {
2690 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2691 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002692 "DES-CBC3-SHA:AES128-SHA", // default
2693 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2694 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002695 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002696 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002697 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2698 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2699 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2700 },
2701 },
2702 }
2703
2704 for i, test := range versionSpecificCiphersTest {
2705 for version, expectedCipherSuite := range test.expectations {
2706 flags := []string{"-cipher", test.ciphersDefault}
2707 if len(test.ciphersTLS10) > 0 {
2708 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2709 }
2710 if len(test.ciphersTLS11) > 0 {
2711 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2712 }
2713
2714 testCases = append(testCases, testCase{
2715 testType: serverTest,
2716 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2717 config: Config{
2718 MaxVersion: version,
2719 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002720 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002721 },
2722 flags: flags,
2723 expectedCipher: expectedCipherSuite,
2724 })
2725 }
2726 }
Adam Langley95c29f32014-06-20 12:00:00 -07002727}
2728
2729func addBadECDSASignatureTests() {
2730 for badR := BadValue(1); badR < NumBadValues; badR++ {
2731 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002732 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002733 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2734 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002735 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002736 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002737 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002738 Bugs: ProtocolBugs{
2739 BadECDSAR: badR,
2740 BadECDSAS: badS,
2741 },
2742 },
2743 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002744 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002745 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002746 testCases = append(testCases, testCase{
2747 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2748 config: Config{
2749 MaxVersion: VersionTLS13,
2750 Certificates: []Certificate{ecdsaP256Certificate},
2751 Bugs: ProtocolBugs{
2752 BadECDSAR: badR,
2753 BadECDSAS: badS,
2754 },
2755 },
2756 shouldFail: true,
2757 expectedError: ":BAD_SIGNATURE:",
2758 })
Adam Langley95c29f32014-06-20 12:00:00 -07002759 }
2760 }
2761}
2762
Adam Langley80842bd2014-06-20 12:00:00 -07002763func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002764 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002765 name: "MaxCBCPadding",
2766 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002767 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002768 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2769 Bugs: ProtocolBugs{
2770 MaxPadding: true,
2771 },
2772 },
2773 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2774 })
David Benjamin025b3d32014-07-01 19:53:04 -04002775 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002776 name: "BadCBCPadding",
2777 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002778 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2780 Bugs: ProtocolBugs{
2781 PaddingFirstByteBad: true,
2782 },
2783 },
2784 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002785 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002786 })
2787 // OpenSSL previously had an issue where the first byte of padding in
2788 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002789 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002790 name: "BadCBCPadding255",
2791 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002792 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002793 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2794 Bugs: ProtocolBugs{
2795 MaxPadding: true,
2796 PaddingFirstByteBadIf255: true,
2797 },
2798 },
2799 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2800 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002801 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002802 })
2803}
2804
Kenny Root7fdeaf12014-08-05 15:23:37 -07002805func addCBCSplittingTests() {
2806 testCases = append(testCases, testCase{
2807 name: "CBCRecordSplitting",
2808 config: Config{
2809 MaxVersion: VersionTLS10,
2810 MinVersion: VersionTLS10,
2811 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2812 },
David Benjaminac8302a2015-09-01 17:18:15 -04002813 messageLen: -1, // read until EOF
2814 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002815 flags: []string{
2816 "-async",
2817 "-write-different-record-sizes",
2818 "-cbc-record-splitting",
2819 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002820 })
2821 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002822 name: "CBCRecordSplittingPartialWrite",
2823 config: Config{
2824 MaxVersion: VersionTLS10,
2825 MinVersion: VersionTLS10,
2826 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2827 },
2828 messageLen: -1, // read until EOF
2829 flags: []string{
2830 "-async",
2831 "-write-different-record-sizes",
2832 "-cbc-record-splitting",
2833 "-partial-write",
2834 },
2835 })
2836}
2837
David Benjamin636293b2014-07-08 17:59:18 -04002838func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002839 // Add a dummy cert pool to stress certificate authority parsing.
2840 // TODO(davidben): Add tests that those values parse out correctly.
2841 certPool := x509.NewCertPool()
2842 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2843 if err != nil {
2844 panic(err)
2845 }
2846 certPool.AddCert(cert)
2847
David Benjamin636293b2014-07-08 17:59:18 -04002848 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002849 testCases = append(testCases, testCase{
2850 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002851 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002852 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002853 MinVersion: ver.version,
2854 MaxVersion: ver.version,
2855 ClientAuth: RequireAnyClientCert,
2856 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002857 },
2858 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002859 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2860 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002861 },
2862 })
2863 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002864 testType: serverTest,
2865 name: ver.name + "-Server-ClientAuth-RSA",
2866 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002867 MinVersion: ver.version,
2868 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002869 Certificates: []Certificate{rsaCertificate},
2870 },
2871 flags: []string{"-require-any-client-certificate"},
2872 })
David Benjamine098ec22014-08-27 23:13:20 -04002873 if ver.version != VersionSSL30 {
2874 testCases = append(testCases, testCase{
2875 testType: serverTest,
2876 name: ver.name + "-Server-ClientAuth-ECDSA",
2877 config: Config{
2878 MinVersion: ver.version,
2879 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002880 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002881 },
2882 flags: []string{"-require-any-client-certificate"},
2883 })
2884 testCases = append(testCases, testCase{
2885 testType: clientTest,
2886 name: ver.name + "-Client-ClientAuth-ECDSA",
2887 config: Config{
2888 MinVersion: ver.version,
2889 MaxVersion: ver.version,
2890 ClientAuth: RequireAnyClientCert,
2891 ClientCAs: certPool,
2892 },
2893 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002894 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2895 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002896 },
2897 })
2898 }
Adam Langley37646832016-08-01 16:16:46 -07002899
2900 testCases = append(testCases, testCase{
2901 name: "NoClientCertificate-" + ver.name,
2902 config: Config{
2903 MinVersion: ver.version,
2904 MaxVersion: ver.version,
2905 ClientAuth: RequireAnyClientCert,
2906 },
2907 shouldFail: true,
2908 expectedLocalError: "client didn't provide a certificate",
2909 })
2910
2911 testCases = append(testCases, testCase{
2912 // Even if not configured to expect a certificate, OpenSSL will
2913 // return X509_V_OK as the verify_result.
2914 testType: serverTest,
2915 name: "NoClientCertificateRequested-Server-" + ver.name,
2916 config: Config{
2917 MinVersion: ver.version,
2918 MaxVersion: ver.version,
2919 },
2920 flags: []string{
2921 "-expect-verify-result",
2922 },
2923 // TODO(davidben): Switch this to true when TLS 1.3
2924 // supports session resumption.
2925 resumeSession: ver.version < VersionTLS13,
2926 })
2927
2928 testCases = append(testCases, testCase{
2929 // If a client certificate is not provided, OpenSSL will still
2930 // return X509_V_OK as the verify_result.
2931 testType: serverTest,
2932 name: "NoClientCertificate-Server-" + ver.name,
2933 config: Config{
2934 MinVersion: ver.version,
2935 MaxVersion: ver.version,
2936 },
2937 flags: []string{
2938 "-expect-verify-result",
2939 "-verify-peer",
2940 },
2941 // TODO(davidben): Switch this to true when TLS 1.3
2942 // supports session resumption.
2943 resumeSession: ver.version < VersionTLS13,
2944 })
2945
2946 testCases = append(testCases, testCase{
2947 testType: serverTest,
2948 name: "RequireAnyClientCertificate-" + ver.name,
2949 config: Config{
2950 MinVersion: ver.version,
2951 MaxVersion: ver.version,
2952 },
2953 flags: []string{"-require-any-client-certificate"},
2954 shouldFail: true,
2955 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2956 })
2957
2958 if ver.version != VersionSSL30 {
2959 testCases = append(testCases, testCase{
2960 testType: serverTest,
2961 name: "SkipClientCertificate-" + ver.name,
2962 config: Config{
2963 MinVersion: ver.version,
2964 MaxVersion: ver.version,
2965 Bugs: ProtocolBugs{
2966 SkipClientCertificate: true,
2967 },
2968 },
2969 // Setting SSL_VERIFY_PEER allows anonymous clients.
2970 flags: []string{"-verify-peer"},
2971 shouldFail: true,
2972 expectedError: ":UNEXPECTED_MESSAGE:",
2973 })
2974 }
David Benjamin636293b2014-07-08 17:59:18 -04002975 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002976
David Benjaminc032dfa2016-05-12 14:54:57 -04002977 // Client auth is only legal in certificate-based ciphers.
2978 testCases = append(testCases, testCase{
2979 testType: clientTest,
2980 name: "ClientAuth-PSK",
2981 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002982 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002983 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2984 PreSharedKey: []byte("secret"),
2985 ClientAuth: RequireAnyClientCert,
2986 },
2987 flags: []string{
2988 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2989 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2990 "-psk", "secret",
2991 },
2992 shouldFail: true,
2993 expectedError: ":UNEXPECTED_MESSAGE:",
2994 })
2995 testCases = append(testCases, testCase{
2996 testType: clientTest,
2997 name: "ClientAuth-ECDHE_PSK",
2998 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002999 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003000 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3001 PreSharedKey: []byte("secret"),
3002 ClientAuth: RequireAnyClientCert,
3003 },
3004 flags: []string{
3005 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3006 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3007 "-psk", "secret",
3008 },
3009 shouldFail: true,
3010 expectedError: ":UNEXPECTED_MESSAGE:",
3011 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003012
3013 // Regression test for a bug where the client CA list, if explicitly
3014 // set to NULL, was mis-encoded.
3015 testCases = append(testCases, testCase{
3016 testType: serverTest,
3017 name: "Null-Client-CA-List",
3018 config: Config{
3019 MaxVersion: VersionTLS12,
3020 Certificates: []Certificate{rsaCertificate},
3021 },
3022 flags: []string{
3023 "-require-any-client-certificate",
3024 "-use-null-client-ca-list",
3025 },
3026 })
David Benjamin636293b2014-07-08 17:59:18 -04003027}
3028
Adam Langley75712922014-10-10 16:23:43 -07003029func addExtendedMasterSecretTests() {
3030 const expectEMSFlag = "-expect-extended-master-secret"
3031
3032 for _, with := range []bool{false, true} {
3033 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003034 if with {
3035 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003036 }
3037
3038 for _, isClient := range []bool{false, true} {
3039 suffix := "-Server"
3040 testType := serverTest
3041 if isClient {
3042 suffix = "-Client"
3043 testType = clientTest
3044 }
3045
3046 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003047 // In TLS 1.3, the extension is irrelevant and
3048 // always reports as enabled.
3049 var flags []string
3050 if with || ver.version >= VersionTLS13 {
3051 flags = []string{expectEMSFlag}
3052 }
3053
Adam Langley75712922014-10-10 16:23:43 -07003054 test := testCase{
3055 testType: testType,
3056 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3057 config: Config{
3058 MinVersion: ver.version,
3059 MaxVersion: ver.version,
3060 Bugs: ProtocolBugs{
3061 NoExtendedMasterSecret: !with,
3062 RequireExtendedMasterSecret: with,
3063 },
3064 },
David Benjamin48cae082014-10-27 01:06:24 -04003065 flags: flags,
3066 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003067 }
3068 if test.shouldFail {
3069 test.expectedLocalError = "extended master secret required but not supported by peer"
3070 }
3071 testCases = append(testCases, test)
3072 }
3073 }
3074 }
3075
Adam Langleyba5934b2015-06-02 10:50:35 -07003076 for _, isClient := range []bool{false, true} {
3077 for _, supportedInFirstConnection := range []bool{false, true} {
3078 for _, supportedInResumeConnection := range []bool{false, true} {
3079 boolToWord := func(b bool) string {
3080 if b {
3081 return "Yes"
3082 }
3083 return "No"
3084 }
3085 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3086 if isClient {
3087 suffix += "Client"
3088 } else {
3089 suffix += "Server"
3090 }
3091
3092 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003093 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003094 Bugs: ProtocolBugs{
3095 RequireExtendedMasterSecret: true,
3096 },
3097 }
3098
3099 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003100 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003101 Bugs: ProtocolBugs{
3102 NoExtendedMasterSecret: true,
3103 },
3104 }
3105
3106 test := testCase{
3107 name: "ExtendedMasterSecret-" + suffix,
3108 resumeSession: true,
3109 }
3110
3111 if !isClient {
3112 test.testType = serverTest
3113 }
3114
3115 if supportedInFirstConnection {
3116 test.config = supportedConfig
3117 } else {
3118 test.config = noSupportConfig
3119 }
3120
3121 if supportedInResumeConnection {
3122 test.resumeConfig = &supportedConfig
3123 } else {
3124 test.resumeConfig = &noSupportConfig
3125 }
3126
3127 switch suffix {
3128 case "YesToYes-Client", "YesToYes-Server":
3129 // When a session is resumed, it should
3130 // still be aware that its master
3131 // secret was generated via EMS and
3132 // thus it's safe to use tls-unique.
3133 test.flags = []string{expectEMSFlag}
3134 case "NoToYes-Server":
3135 // If an original connection did not
3136 // contain EMS, but a resumption
3137 // handshake does, then a server should
3138 // not resume the session.
3139 test.expectResumeRejected = true
3140 case "YesToNo-Server":
3141 // Resuming an EMS session without the
3142 // EMS extension should cause the
3143 // server to abort the connection.
3144 test.shouldFail = true
3145 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3146 case "NoToYes-Client":
3147 // A client should abort a connection
3148 // where the server resumed a non-EMS
3149 // session but echoed the EMS
3150 // extension.
3151 test.shouldFail = true
3152 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3153 case "YesToNo-Client":
3154 // A client should abort a connection
3155 // where the server didn't echo EMS
3156 // when the session used it.
3157 test.shouldFail = true
3158 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3159 }
3160
3161 testCases = append(testCases, test)
3162 }
3163 }
3164 }
David Benjamin163c9562016-08-29 23:14:17 -04003165
3166 // Switching EMS on renegotiation is forbidden.
3167 testCases = append(testCases, testCase{
3168 name: "ExtendedMasterSecret-Renego-NoEMS",
3169 config: Config{
3170 MaxVersion: VersionTLS12,
3171 Bugs: ProtocolBugs{
3172 NoExtendedMasterSecret: true,
3173 NoExtendedMasterSecretOnRenegotiation: true,
3174 },
3175 },
3176 renegotiate: 1,
3177 flags: []string{
3178 "-renegotiate-freely",
3179 "-expect-total-renegotiations", "1",
3180 },
3181 })
3182
3183 testCases = append(testCases, testCase{
3184 name: "ExtendedMasterSecret-Renego-Upgrade",
3185 config: Config{
3186 MaxVersion: VersionTLS12,
3187 Bugs: ProtocolBugs{
3188 NoExtendedMasterSecret: true,
3189 },
3190 },
3191 renegotiate: 1,
3192 flags: []string{
3193 "-renegotiate-freely",
3194 "-expect-total-renegotiations", "1",
3195 },
3196 shouldFail: true,
3197 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3198 })
3199
3200 testCases = append(testCases, testCase{
3201 name: "ExtendedMasterSecret-Renego-Downgrade",
3202 config: Config{
3203 MaxVersion: VersionTLS12,
3204 Bugs: ProtocolBugs{
3205 NoExtendedMasterSecretOnRenegotiation: true,
3206 },
3207 },
3208 renegotiate: 1,
3209 flags: []string{
3210 "-renegotiate-freely",
3211 "-expect-total-renegotiations", "1",
3212 },
3213 shouldFail: true,
3214 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3215 })
Adam Langley75712922014-10-10 16:23:43 -07003216}
3217
David Benjamin582ba042016-07-07 12:33:25 -07003218type stateMachineTestConfig struct {
3219 protocol protocol
3220 async bool
3221 splitHandshake, packHandshakeFlight bool
3222}
3223
David Benjamin43ec06f2014-08-05 02:28:57 -04003224// Adds tests that try to cover the range of the handshake state machine, under
3225// various conditions. Some of these are redundant with other tests, but they
3226// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003227func addAllStateMachineCoverageTests() {
3228 for _, async := range []bool{false, true} {
3229 for _, protocol := range []protocol{tls, dtls} {
3230 addStateMachineCoverageTests(stateMachineTestConfig{
3231 protocol: protocol,
3232 async: async,
3233 })
3234 addStateMachineCoverageTests(stateMachineTestConfig{
3235 protocol: protocol,
3236 async: async,
3237 splitHandshake: true,
3238 })
3239 if protocol == tls {
3240 addStateMachineCoverageTests(stateMachineTestConfig{
3241 protocol: protocol,
3242 async: async,
3243 packHandshakeFlight: true,
3244 })
3245 }
3246 }
3247 }
3248}
3249
3250func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003251 var tests []testCase
3252
3253 // Basic handshake, with resumption. Client and server,
3254 // session ID and session ticket.
3255 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003256 name: "Basic-Client",
3257 config: Config{
3258 MaxVersion: VersionTLS12,
3259 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003260 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003261 // Ensure session tickets are used, not session IDs.
3262 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003263 })
3264 tests = append(tests, testCase{
3265 name: "Basic-Client-RenewTicket",
3266 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003267 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 Bugs: ProtocolBugs{
3269 RenewTicketOnResume: true,
3270 },
3271 },
David Benjamin46662482016-08-17 00:51:00 -04003272 flags: []string{"-expect-ticket-renewal"},
3273 resumeSession: true,
3274 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 })
3276 tests = append(tests, testCase{
3277 name: "Basic-Client-NoTicket",
3278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003279 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003280 SessionTicketsDisabled: true,
3281 },
3282 resumeSession: true,
3283 })
3284 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003285 name: "Basic-Client-Implicit",
3286 config: Config{
3287 MaxVersion: VersionTLS12,
3288 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003289 flags: []string{"-implicit-handshake"},
3290 resumeSession: true,
3291 })
3292 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003293 testType: serverTest,
3294 name: "Basic-Server",
3295 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003296 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003297 Bugs: ProtocolBugs{
3298 RequireSessionTickets: true,
3299 },
3300 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003301 resumeSession: true,
3302 })
3303 tests = append(tests, testCase{
3304 testType: serverTest,
3305 name: "Basic-Server-NoTickets",
3306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003307 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003308 SessionTicketsDisabled: true,
3309 },
3310 resumeSession: true,
3311 })
3312 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003313 testType: serverTest,
3314 name: "Basic-Server-Implicit",
3315 config: Config{
3316 MaxVersion: VersionTLS12,
3317 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003318 flags: []string{"-implicit-handshake"},
3319 resumeSession: true,
3320 })
3321 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003322 testType: serverTest,
3323 name: "Basic-Server-EarlyCallback",
3324 config: Config{
3325 MaxVersion: VersionTLS12,
3326 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003327 flags: []string{"-use-early-callback"},
3328 resumeSession: true,
3329 })
3330
Steven Valdez143e8b32016-07-11 13:19:03 -04003331 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003332 if config.protocol == tls {
3333 tests = append(tests, testCase{
3334 name: "TLS13-1RTT-Client",
3335 config: Config{
3336 MaxVersion: VersionTLS13,
3337 MinVersion: VersionTLS13,
3338 },
David Benjamin46662482016-08-17 00:51:00 -04003339 resumeSession: true,
3340 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003341 })
3342
3343 tests = append(tests, testCase{
3344 testType: serverTest,
3345 name: "TLS13-1RTT-Server",
3346 config: Config{
3347 MaxVersion: VersionTLS13,
3348 MinVersion: VersionTLS13,
3349 },
David Benjamin46662482016-08-17 00:51:00 -04003350 resumeSession: true,
3351 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003352 })
3353
3354 tests = append(tests, testCase{
3355 name: "TLS13-HelloRetryRequest-Client",
3356 config: Config{
3357 MaxVersion: VersionTLS13,
3358 MinVersion: VersionTLS13,
3359 // P-384 requires a HelloRetryRequest against
3360 // BoringSSL's default configuration. Assert
3361 // that we do indeed test this with
3362 // ExpectMissingKeyShare.
3363 CurvePreferences: []CurveID{CurveP384},
3364 Bugs: ProtocolBugs{
3365 ExpectMissingKeyShare: true,
3366 },
3367 },
3368 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3369 resumeSession: true,
3370 })
3371
3372 tests = append(tests, testCase{
3373 testType: serverTest,
3374 name: "TLS13-HelloRetryRequest-Server",
3375 config: Config{
3376 MaxVersion: VersionTLS13,
3377 MinVersion: VersionTLS13,
3378 // Require a HelloRetryRequest for every curve.
3379 DefaultCurves: []CurveID{},
3380 },
3381 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3382 resumeSession: true,
3383 })
3384 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003385
David Benjamin760b1dd2015-05-15 23:33:48 -04003386 // TLS client auth.
3387 tests = append(tests, testCase{
3388 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003389 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003391 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003392 ClientAuth: RequestClientCert,
3393 },
3394 })
3395 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003396 testType: serverTest,
3397 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003398 config: Config{
3399 MaxVersion: VersionTLS12,
3400 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003401 // Setting SSL_VERIFY_PEER allows anonymous clients.
3402 flags: []string{"-verify-peer"},
3403 })
David Benjamin582ba042016-07-07 12:33:25 -07003404 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003405 tests = append(tests, testCase{
3406 testType: clientTest,
3407 name: "ClientAuth-NoCertificate-Client-SSL3",
3408 config: Config{
3409 MaxVersion: VersionSSL30,
3410 ClientAuth: RequestClientCert,
3411 },
3412 })
3413 tests = append(tests, testCase{
3414 testType: serverTest,
3415 name: "ClientAuth-NoCertificate-Server-SSL3",
3416 config: Config{
3417 MaxVersion: VersionSSL30,
3418 },
3419 // Setting SSL_VERIFY_PEER allows anonymous clients.
3420 flags: []string{"-verify-peer"},
3421 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003422 tests = append(tests, testCase{
3423 testType: clientTest,
3424 name: "ClientAuth-NoCertificate-Client-TLS13",
3425 config: Config{
3426 MaxVersion: VersionTLS13,
3427 ClientAuth: RequestClientCert,
3428 },
3429 })
3430 tests = append(tests, testCase{
3431 testType: serverTest,
3432 name: "ClientAuth-NoCertificate-Server-TLS13",
3433 config: Config{
3434 MaxVersion: VersionTLS13,
3435 },
3436 // Setting SSL_VERIFY_PEER allows anonymous clients.
3437 flags: []string{"-verify-peer"},
3438 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003439 }
3440 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003441 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003442 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003444 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003445 ClientAuth: RequireAnyClientCert,
3446 },
3447 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003448 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3449 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003450 },
3451 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003452 tests = append(tests, testCase{
3453 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003454 name: "ClientAuth-RSA-Client-TLS13",
3455 config: Config{
3456 MaxVersion: VersionTLS13,
3457 ClientAuth: RequireAnyClientCert,
3458 },
3459 flags: []string{
3460 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3461 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3462 },
3463 })
3464 tests = append(tests, testCase{
3465 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003466 name: "ClientAuth-ECDSA-Client",
3467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003468 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003469 ClientAuth: RequireAnyClientCert,
3470 },
3471 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003472 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3473 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003474 },
3475 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003476 tests = append(tests, testCase{
3477 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003478 name: "ClientAuth-ECDSA-Client-TLS13",
3479 config: Config{
3480 MaxVersion: VersionTLS13,
3481 ClientAuth: RequireAnyClientCert,
3482 },
3483 flags: []string{
3484 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3485 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3486 },
3487 })
3488 tests = append(tests, testCase{
3489 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003490 name: "ClientAuth-NoCertificate-OldCallback",
3491 config: Config{
3492 MaxVersion: VersionTLS12,
3493 ClientAuth: RequestClientCert,
3494 },
3495 flags: []string{"-use-old-client-cert-callback"},
3496 })
3497 tests = append(tests, testCase{
3498 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003499 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3500 config: Config{
3501 MaxVersion: VersionTLS13,
3502 ClientAuth: RequestClientCert,
3503 },
3504 flags: []string{"-use-old-client-cert-callback"},
3505 })
3506 tests = append(tests, testCase{
3507 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003508 name: "ClientAuth-OldCallback",
3509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003510 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003511 ClientAuth: RequireAnyClientCert,
3512 },
3513 flags: []string{
3514 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3515 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3516 "-use-old-client-cert-callback",
3517 },
3518 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003519 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003520 testType: clientTest,
3521 name: "ClientAuth-OldCallback-TLS13",
3522 config: Config{
3523 MaxVersion: VersionTLS13,
3524 ClientAuth: RequireAnyClientCert,
3525 },
3526 flags: []string{
3527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3529 "-use-old-client-cert-callback",
3530 },
3531 })
3532 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003533 testType: serverTest,
3534 name: "ClientAuth-Server",
3535 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003537 Certificates: []Certificate{rsaCertificate},
3538 },
3539 flags: []string{"-require-any-client-certificate"},
3540 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003541 tests = append(tests, testCase{
3542 testType: serverTest,
3543 name: "ClientAuth-Server-TLS13",
3544 config: Config{
3545 MaxVersion: VersionTLS13,
3546 Certificates: []Certificate{rsaCertificate},
3547 },
3548 flags: []string{"-require-any-client-certificate"},
3549 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003550
David Benjamin4c3ddf72016-06-29 18:13:53 -04003551 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003552 tests = append(tests, testCase{
3553 testType: serverTest,
3554 name: "Basic-Server-RSA",
3555 config: Config{
3556 MaxVersion: VersionTLS12,
3557 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3558 },
3559 flags: []string{
3560 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3561 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3562 },
3563 })
3564 tests = append(tests, testCase{
3565 testType: serverTest,
3566 name: "Basic-Server-ECDHE-RSA",
3567 config: Config{
3568 MaxVersion: VersionTLS12,
3569 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3570 },
3571 flags: []string{
3572 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3573 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3574 },
3575 })
3576 tests = append(tests, testCase{
3577 testType: serverTest,
3578 name: "Basic-Server-ECDHE-ECDSA",
3579 config: Config{
3580 MaxVersion: VersionTLS12,
3581 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3582 },
3583 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003584 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3585 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003586 },
3587 })
3588
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 // No session ticket support; server doesn't send NewSessionTicket.
3590 tests = append(tests, testCase{
3591 name: "SessionTicketsDisabled-Client",
3592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003593 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003594 SessionTicketsDisabled: true,
3595 },
3596 })
3597 tests = append(tests, testCase{
3598 testType: serverTest,
3599 name: "SessionTicketsDisabled-Server",
3600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003601 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003602 SessionTicketsDisabled: true,
3603 },
3604 })
3605
3606 // Skip ServerKeyExchange in PSK key exchange if there's no
3607 // identity hint.
3608 tests = append(tests, testCase{
3609 name: "EmptyPSKHint-Client",
3610 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003611 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003612 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3613 PreSharedKey: []byte("secret"),
3614 },
3615 flags: []string{"-psk", "secret"},
3616 })
3617 tests = append(tests, testCase{
3618 testType: serverTest,
3619 name: "EmptyPSKHint-Server",
3620 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003621 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003622 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3623 PreSharedKey: []byte("secret"),
3624 },
3625 flags: []string{"-psk", "secret"},
3626 })
3627
David Benjamin4c3ddf72016-06-29 18:13:53 -04003628 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003629 tests = append(tests, testCase{
3630 testType: clientTest,
3631 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003632 config: Config{
3633 MaxVersion: VersionTLS12,
3634 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003635 flags: []string{
3636 "-enable-ocsp-stapling",
3637 "-expect-ocsp-response",
3638 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003639 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003640 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003641 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003642 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003643 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003644 testType: serverTest,
3645 name: "OCSPStapling-Server",
3646 config: Config{
3647 MaxVersion: VersionTLS12,
3648 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003649 expectedOCSPResponse: testOCSPResponse,
3650 flags: []string{
3651 "-ocsp-response",
3652 base64.StdEncoding.EncodeToString(testOCSPResponse),
3653 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003654 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003655 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003656 tests = append(tests, testCase{
3657 testType: clientTest,
3658 name: "OCSPStapling-Client-TLS13",
3659 config: Config{
3660 MaxVersion: VersionTLS13,
3661 },
3662 flags: []string{
3663 "-enable-ocsp-stapling",
3664 "-expect-ocsp-response",
3665 base64.StdEncoding.EncodeToString(testOCSPResponse),
3666 "-verify-peer",
3667 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003668 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003669 })
3670 tests = append(tests, testCase{
3671 testType: serverTest,
3672 name: "OCSPStapling-Server-TLS13",
3673 config: Config{
3674 MaxVersion: VersionTLS13,
3675 },
3676 expectedOCSPResponse: testOCSPResponse,
3677 flags: []string{
3678 "-ocsp-response",
3679 base64.StdEncoding.EncodeToString(testOCSPResponse),
3680 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003681 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003682 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003683
David Benjamin4c3ddf72016-06-29 18:13:53 -04003684 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003685 for _, vers := range tlsVersions {
3686 if config.protocol == dtls && !vers.hasDTLS {
3687 continue
3688 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003689 for _, testType := range []testType{clientTest, serverTest} {
3690 suffix := "-Client"
3691 if testType == serverTest {
3692 suffix = "-Server"
3693 }
3694 suffix += "-" + vers.name
3695
3696 flag := "-verify-peer"
3697 if testType == serverTest {
3698 flag = "-require-any-client-certificate"
3699 }
3700
3701 tests = append(tests, testCase{
3702 testType: testType,
3703 name: "CertificateVerificationSucceed" + suffix,
3704 config: Config{
3705 MaxVersion: vers.version,
3706 Certificates: []Certificate{rsaCertificate},
3707 },
3708 flags: []string{
3709 flag,
3710 "-expect-verify-result",
3711 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003712 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003713 })
3714 tests = append(tests, testCase{
3715 testType: testType,
3716 name: "CertificateVerificationFail" + suffix,
3717 config: Config{
3718 MaxVersion: vers.version,
3719 Certificates: []Certificate{rsaCertificate},
3720 },
3721 flags: []string{
3722 flag,
3723 "-verify-fail",
3724 },
3725 shouldFail: true,
3726 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3727 })
3728 }
3729
3730 // By default, the client is in a soft fail mode where the peer
3731 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003732 tests = append(tests, testCase{
3733 testType: clientTest,
3734 name: "CertificateVerificationSoftFail-" + vers.name,
3735 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003736 MaxVersion: vers.version,
3737 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003738 },
3739 flags: []string{
3740 "-verify-fail",
3741 "-expect-verify-result",
3742 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003743 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003744 })
3745 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003746
David Benjamin1d4f4c02016-07-26 18:03:08 -04003747 tests = append(tests, testCase{
3748 name: "ShimSendAlert",
3749 flags: []string{"-send-alert"},
3750 shimWritesFirst: true,
3751 shouldFail: true,
3752 expectedLocalError: "remote error: decompression failure",
3753 })
3754
David Benjamin582ba042016-07-07 12:33:25 -07003755 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003756 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003757 name: "Renegotiate-Client",
3758 config: Config{
3759 MaxVersion: VersionTLS12,
3760 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003761 renegotiate: 1,
3762 flags: []string{
3763 "-renegotiate-freely",
3764 "-expect-total-renegotiations", "1",
3765 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003766 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003767
David Benjamin47921102016-07-28 11:29:18 -04003768 tests = append(tests, testCase{
3769 name: "SendHalfHelloRequest",
3770 config: Config{
3771 MaxVersion: VersionTLS12,
3772 Bugs: ProtocolBugs{
3773 PackHelloRequestWithFinished: config.packHandshakeFlight,
3774 },
3775 },
3776 sendHalfHelloRequest: true,
3777 flags: []string{"-renegotiate-ignore"},
3778 shouldFail: true,
3779 expectedError: ":UNEXPECTED_RECORD:",
3780 })
3781
David Benjamin760b1dd2015-05-15 23:33:48 -04003782 // NPN on client and server; results in post-handshake message.
3783 tests = append(tests, testCase{
3784 name: "NPN-Client",
3785 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003786 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003787 NextProtos: []string{"foo"},
3788 },
3789 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003790 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003791 expectedNextProto: "foo",
3792 expectedNextProtoType: npn,
3793 })
3794 tests = append(tests, testCase{
3795 testType: serverTest,
3796 name: "NPN-Server",
3797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003798 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003799 NextProtos: []string{"bar"},
3800 },
3801 flags: []string{
3802 "-advertise-npn", "\x03foo\x03bar\x03baz",
3803 "-expect-next-proto", "bar",
3804 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003805 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 expectedNextProto: "bar",
3807 expectedNextProtoType: npn,
3808 })
3809
3810 // TODO(davidben): Add tests for when False Start doesn't trigger.
3811
3812 // Client does False Start and negotiates NPN.
3813 tests = append(tests, testCase{
3814 name: "FalseStart",
3815 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003816 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003817 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3818 NextProtos: []string{"foo"},
3819 Bugs: ProtocolBugs{
3820 ExpectFalseStart: true,
3821 },
3822 },
3823 flags: []string{
3824 "-false-start",
3825 "-select-next-proto", "foo",
3826 },
3827 shimWritesFirst: true,
3828 resumeSession: true,
3829 })
3830
3831 // Client does False Start and negotiates ALPN.
3832 tests = append(tests, testCase{
3833 name: "FalseStart-ALPN",
3834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003835 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3837 NextProtos: []string{"foo"},
3838 Bugs: ProtocolBugs{
3839 ExpectFalseStart: true,
3840 },
3841 },
3842 flags: []string{
3843 "-false-start",
3844 "-advertise-alpn", "\x03foo",
3845 },
3846 shimWritesFirst: true,
3847 resumeSession: true,
3848 })
3849
3850 // Client does False Start but doesn't explicitly call
3851 // SSL_connect.
3852 tests = append(tests, testCase{
3853 name: "FalseStart-Implicit",
3854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003855 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3857 NextProtos: []string{"foo"},
3858 },
3859 flags: []string{
3860 "-implicit-handshake",
3861 "-false-start",
3862 "-advertise-alpn", "\x03foo",
3863 },
3864 })
3865
3866 // False Start without session tickets.
3867 tests = append(tests, testCase{
3868 name: "FalseStart-SessionTicketsDisabled",
3869 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003870 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3872 NextProtos: []string{"foo"},
3873 SessionTicketsDisabled: true,
3874 Bugs: ProtocolBugs{
3875 ExpectFalseStart: true,
3876 },
3877 },
3878 flags: []string{
3879 "-false-start",
3880 "-select-next-proto", "foo",
3881 },
3882 shimWritesFirst: true,
3883 })
3884
Adam Langleydf759b52016-07-11 15:24:37 -07003885 tests = append(tests, testCase{
3886 name: "FalseStart-CECPQ1",
3887 config: Config{
3888 MaxVersion: VersionTLS12,
3889 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3890 NextProtos: []string{"foo"},
3891 Bugs: ProtocolBugs{
3892 ExpectFalseStart: true,
3893 },
3894 },
3895 flags: []string{
3896 "-false-start",
3897 "-cipher", "DEFAULT:kCECPQ1",
3898 "-select-next-proto", "foo",
3899 },
3900 shimWritesFirst: true,
3901 resumeSession: true,
3902 })
3903
David Benjamin760b1dd2015-05-15 23:33:48 -04003904 // Server parses a V2ClientHello.
3905 tests = append(tests, testCase{
3906 testType: serverTest,
3907 name: "SendV2ClientHello",
3908 config: Config{
3909 // Choose a cipher suite that does not involve
3910 // elliptic curves, so no extensions are
3911 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003912 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003913 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003914 Bugs: ProtocolBugs{
3915 SendV2ClientHello: true,
3916 },
3917 },
3918 })
3919
3920 // Client sends a Channel ID.
3921 tests = append(tests, testCase{
3922 name: "ChannelID-Client",
3923 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003924 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 RequestChannelID: true,
3926 },
Adam Langley7c803a62015-06-15 15:35:05 -07003927 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003928 resumeSession: true,
3929 expectChannelID: true,
3930 })
3931
3932 // Server accepts a Channel ID.
3933 tests = append(tests, testCase{
3934 testType: serverTest,
3935 name: "ChannelID-Server",
3936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003937 MaxVersion: VersionTLS12,
3938 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003939 },
3940 flags: []string{
3941 "-expect-channel-id",
3942 base64.StdEncoding.EncodeToString(channelIDBytes),
3943 },
3944 resumeSession: true,
3945 expectChannelID: true,
3946 })
David Benjamin30789da2015-08-29 22:56:45 -04003947
David Benjaminf8fcdf32016-06-08 15:56:13 -04003948 // Channel ID and NPN at the same time, to ensure their relative
3949 // ordering is correct.
3950 tests = append(tests, testCase{
3951 name: "ChannelID-NPN-Client",
3952 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003953 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003954 RequestChannelID: true,
3955 NextProtos: []string{"foo"},
3956 },
3957 flags: []string{
3958 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3959 "-select-next-proto", "foo",
3960 },
3961 resumeSession: true,
3962 expectChannelID: true,
3963 expectedNextProto: "foo",
3964 expectedNextProtoType: npn,
3965 })
3966 tests = append(tests, testCase{
3967 testType: serverTest,
3968 name: "ChannelID-NPN-Server",
3969 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003970 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003971 ChannelID: channelIDKey,
3972 NextProtos: []string{"bar"},
3973 },
3974 flags: []string{
3975 "-expect-channel-id",
3976 base64.StdEncoding.EncodeToString(channelIDBytes),
3977 "-advertise-npn", "\x03foo\x03bar\x03baz",
3978 "-expect-next-proto", "bar",
3979 },
3980 resumeSession: true,
3981 expectChannelID: true,
3982 expectedNextProto: "bar",
3983 expectedNextProtoType: npn,
3984 })
3985
David Benjamin30789da2015-08-29 22:56:45 -04003986 // Bidirectional shutdown with the runner initiating.
3987 tests = append(tests, testCase{
3988 name: "Shutdown-Runner",
3989 config: Config{
3990 Bugs: ProtocolBugs{
3991 ExpectCloseNotify: true,
3992 },
3993 },
3994 flags: []string{"-check-close-notify"},
3995 })
3996
3997 // Bidirectional shutdown with the shim initiating. The runner,
3998 // in the meantime, sends garbage before the close_notify which
3999 // the shim must ignore.
4000 tests = append(tests, testCase{
4001 name: "Shutdown-Shim",
4002 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004003 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004004 Bugs: ProtocolBugs{
4005 ExpectCloseNotify: true,
4006 },
4007 },
4008 shimShutsDown: true,
4009 sendEmptyRecords: 1,
4010 sendWarningAlerts: 1,
4011 flags: []string{"-check-close-notify"},
4012 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004013 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004014 // TODO(davidben): DTLS 1.3 will want a similar thing for
4015 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004016 tests = append(tests, testCase{
4017 name: "SkipHelloVerifyRequest",
4018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004019 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004020 Bugs: ProtocolBugs{
4021 SkipHelloVerifyRequest: true,
4022 },
4023 },
4024 })
4025 }
4026
David Benjamin760b1dd2015-05-15 23:33:48 -04004027 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004028 test.protocol = config.protocol
4029 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004030 test.name += "-DTLS"
4031 }
David Benjamin582ba042016-07-07 12:33:25 -07004032 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004033 test.name += "-Async"
4034 test.flags = append(test.flags, "-async")
4035 } else {
4036 test.name += "-Sync"
4037 }
David Benjamin582ba042016-07-07 12:33:25 -07004038 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004039 test.name += "-SplitHandshakeRecords"
4040 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004041 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004042 test.config.Bugs.MaxPacketLength = 256
4043 test.flags = append(test.flags, "-mtu", "256")
4044 }
4045 }
David Benjamin582ba042016-07-07 12:33:25 -07004046 if config.packHandshakeFlight {
4047 test.name += "-PackHandshakeFlight"
4048 test.config.Bugs.PackHandshakeFlight = true
4049 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004050 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004051 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004052}
4053
Adam Langley524e7172015-02-20 16:04:00 -08004054func addDDoSCallbackTests() {
4055 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004056 for _, resume := range []bool{false, true} {
4057 suffix := "Resume"
4058 if resume {
4059 suffix = "No" + suffix
4060 }
4061
4062 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004063 testType: serverTest,
4064 name: "Server-DDoS-OK-" + suffix,
4065 config: Config{
4066 MaxVersion: VersionTLS12,
4067 },
Adam Langley524e7172015-02-20 16:04:00 -08004068 flags: []string{"-install-ddos-callback"},
4069 resumeSession: resume,
4070 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004071 testCases = append(testCases, testCase{
4072 testType: serverTest,
4073 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4074 config: Config{
4075 MaxVersion: VersionTLS13,
4076 },
4077 flags: []string{"-install-ddos-callback"},
4078 resumeSession: resume,
4079 })
Adam Langley524e7172015-02-20 16:04:00 -08004080
4081 failFlag := "-fail-ddos-callback"
4082 if resume {
4083 failFlag = "-fail-second-ddos-callback"
4084 }
4085 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004086 testType: serverTest,
4087 name: "Server-DDoS-Reject-" + suffix,
4088 config: Config{
4089 MaxVersion: VersionTLS12,
4090 },
David Benjamin2c66e072016-09-16 15:58:00 -04004091 flags: []string{"-install-ddos-callback", failFlag},
4092 resumeSession: resume,
4093 shouldFail: true,
4094 expectedError: ":CONNECTION_REJECTED:",
4095 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004096 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004097 testCases = append(testCases, testCase{
4098 testType: serverTest,
4099 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4100 config: Config{
4101 MaxVersion: VersionTLS13,
4102 },
David Benjamin2c66e072016-09-16 15:58:00 -04004103 flags: []string{"-install-ddos-callback", failFlag},
4104 resumeSession: resume,
4105 shouldFail: true,
4106 expectedError: ":CONNECTION_REJECTED:",
4107 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004108 })
Adam Langley524e7172015-02-20 16:04:00 -08004109 }
4110}
4111
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004112func addVersionNegotiationTests() {
4113 for i, shimVers := range tlsVersions {
4114 // Assemble flags to disable all newer versions on the shim.
4115 var flags []string
4116 for _, vers := range tlsVersions[i+1:] {
4117 flags = append(flags, vers.flag)
4118 }
4119
Steven Valdezfdd10992016-09-15 16:27:05 -04004120 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004121 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004122 protocols := []protocol{tls}
4123 if runnerVers.hasDTLS && shimVers.hasDTLS {
4124 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004125 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004126 for _, protocol := range protocols {
4127 expectedVersion := shimVers.version
4128 if runnerVers.version < shimVers.version {
4129 expectedVersion = runnerVers.version
4130 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004131
David Benjamin8b8c0062014-11-23 02:47:52 -05004132 suffix := shimVers.name + "-" + runnerVers.name
4133 if protocol == dtls {
4134 suffix += "-DTLS"
4135 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004136
David Benjamin1eb367c2014-12-12 18:17:51 -05004137 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4138
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004139 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004140 clientVers := shimVers.version
4141 if clientVers > VersionTLS10 {
4142 clientVers = VersionTLS10
4143 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004144 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004145 serverVers := expectedVersion
4146 if expectedVersion >= VersionTLS13 {
4147 serverVers = VersionTLS10
4148 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004149 serverVers = versionToWire(serverVers, protocol == dtls)
4150
David Benjamin8b8c0062014-11-23 02:47:52 -05004151 testCases = append(testCases, testCase{
4152 protocol: protocol,
4153 testType: clientTest,
4154 name: "VersionNegotiation-Client-" + suffix,
4155 config: Config{
4156 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004157 Bugs: ProtocolBugs{
4158 ExpectInitialRecordVersion: clientVers,
4159 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004160 },
4161 flags: flags,
4162 expectedVersion: expectedVersion,
4163 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004164 testCases = append(testCases, testCase{
4165 protocol: protocol,
4166 testType: clientTest,
4167 name: "VersionNegotiation-Client2-" + suffix,
4168 config: Config{
4169 MaxVersion: runnerVers.version,
4170 Bugs: ProtocolBugs{
4171 ExpectInitialRecordVersion: clientVers,
4172 },
4173 },
4174 flags: []string{"-max-version", shimVersFlag},
4175 expectedVersion: expectedVersion,
4176 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004177
4178 testCases = append(testCases, testCase{
4179 protocol: protocol,
4180 testType: serverTest,
4181 name: "VersionNegotiation-Server-" + suffix,
4182 config: Config{
4183 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004184 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004185 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004186 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004187 },
4188 flags: flags,
4189 expectedVersion: expectedVersion,
4190 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004191 testCases = append(testCases, testCase{
4192 protocol: protocol,
4193 testType: serverTest,
4194 name: "VersionNegotiation-Server2-" + suffix,
4195 config: Config{
4196 MaxVersion: runnerVers.version,
4197 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004198 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004199 },
4200 },
4201 flags: []string{"-max-version", shimVersFlag},
4202 expectedVersion: expectedVersion,
4203 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004204 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004205 }
4206 }
David Benjamin95c69562016-06-29 18:15:03 -04004207
Steven Valdezfdd10992016-09-15 16:27:05 -04004208 // Test the version extension at all versions.
4209 for _, vers := range tlsVersions {
4210 protocols := []protocol{tls}
4211 if vers.hasDTLS {
4212 protocols = append(protocols, dtls)
4213 }
4214 for _, protocol := range protocols {
4215 suffix := vers.name
4216 if protocol == dtls {
4217 suffix += "-DTLS"
4218 }
4219
4220 wireVersion := versionToWire(vers.version, protocol == dtls)
4221 testCases = append(testCases, testCase{
4222 protocol: protocol,
4223 testType: serverTest,
4224 name: "VersionNegotiationExtension-" + suffix,
4225 config: Config{
4226 Bugs: ProtocolBugs{
4227 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4228 },
4229 },
4230 expectedVersion: vers.version,
4231 })
4232 }
4233
4234 }
4235
4236 // If all versions are unknown, negotiation fails.
4237 testCases = append(testCases, testCase{
4238 testType: serverTest,
4239 name: "NoSupportedVersions",
4240 config: Config{
4241 Bugs: ProtocolBugs{
4242 SendSupportedVersions: []uint16{0x1111},
4243 },
4244 },
4245 shouldFail: true,
4246 expectedError: ":UNSUPPORTED_PROTOCOL:",
4247 })
4248 testCases = append(testCases, testCase{
4249 protocol: dtls,
4250 testType: serverTest,
4251 name: "NoSupportedVersions-DTLS",
4252 config: Config{
4253 Bugs: ProtocolBugs{
4254 SendSupportedVersions: []uint16{0x1111},
4255 },
4256 },
4257 shouldFail: true,
4258 expectedError: ":UNSUPPORTED_PROTOCOL:",
4259 })
4260
4261 testCases = append(testCases, testCase{
4262 testType: serverTest,
4263 name: "ClientHelloVersionTooHigh",
4264 config: Config{
4265 MaxVersion: VersionTLS13,
4266 Bugs: ProtocolBugs{
4267 SendClientVersion: 0x0304,
4268 OmitSupportedVersions: true,
4269 },
4270 },
4271 expectedVersion: VersionTLS12,
4272 })
4273
4274 testCases = append(testCases, testCase{
4275 testType: serverTest,
4276 name: "ConflictingVersionNegotiation",
4277 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004278 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004279 SendClientVersion: VersionTLS12,
4280 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004281 },
4282 },
David Benjaminad75a662016-09-30 15:42:59 -04004283 // The extension takes precedence over the ClientHello version.
4284 expectedVersion: VersionTLS11,
4285 })
4286
4287 testCases = append(testCases, testCase{
4288 testType: serverTest,
4289 name: "ConflictingVersionNegotiation-2",
4290 config: Config{
4291 Bugs: ProtocolBugs{
4292 SendClientVersion: VersionTLS11,
4293 SendSupportedVersions: []uint16{VersionTLS12},
4294 },
4295 },
4296 // The extension takes precedence over the ClientHello version.
4297 expectedVersion: VersionTLS12,
4298 })
4299
4300 testCases = append(testCases, testCase{
4301 testType: serverTest,
4302 name: "RejectFinalTLS13",
4303 config: Config{
4304 Bugs: ProtocolBugs{
4305 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4306 },
4307 },
4308 // We currently implement a draft TLS 1.3 version. Ensure that
4309 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004310 expectedVersion: VersionTLS12,
4311 })
4312
David Benjamin95c69562016-06-29 18:15:03 -04004313 // Test for version tolerance.
4314 testCases = append(testCases, testCase{
4315 testType: serverTest,
4316 name: "MinorVersionTolerance",
4317 config: Config{
4318 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004319 SendClientVersion: 0x03ff,
4320 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004321 },
4322 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004323 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004324 })
4325 testCases = append(testCases, testCase{
4326 testType: serverTest,
4327 name: "MajorVersionTolerance",
4328 config: Config{
4329 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004330 SendClientVersion: 0x0400,
4331 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004332 },
4333 },
David Benjaminad75a662016-09-30 15:42:59 -04004334 // TLS 1.3 must be negotiated with the supported_versions
4335 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004336 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004337 })
David Benjaminad75a662016-09-30 15:42:59 -04004338 testCases = append(testCases, testCase{
4339 testType: serverTest,
4340 name: "VersionTolerance-TLS13",
4341 config: Config{
4342 Bugs: ProtocolBugs{
4343 // Although TLS 1.3 does not use
4344 // ClientHello.version, it still tolerates high
4345 // values there.
4346 SendClientVersion: 0x0400,
4347 },
4348 },
4349 expectedVersion: VersionTLS13,
4350 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004351
David Benjamin95c69562016-06-29 18:15:03 -04004352 testCases = append(testCases, testCase{
4353 protocol: dtls,
4354 testType: serverTest,
4355 name: "MinorVersionTolerance-DTLS",
4356 config: Config{
4357 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004358 SendClientVersion: 0xfe00,
4359 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004360 },
4361 },
4362 expectedVersion: VersionTLS12,
4363 })
4364 testCases = append(testCases, testCase{
4365 protocol: dtls,
4366 testType: serverTest,
4367 name: "MajorVersionTolerance-DTLS",
4368 config: Config{
4369 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004370 SendClientVersion: 0xfdff,
4371 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004372 },
4373 },
4374 expectedVersion: VersionTLS12,
4375 })
4376
4377 // Test that versions below 3.0 are rejected.
4378 testCases = append(testCases, testCase{
4379 testType: serverTest,
4380 name: "VersionTooLow",
4381 config: Config{
4382 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004383 SendClientVersion: 0x0200,
4384 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004385 },
4386 },
4387 shouldFail: true,
4388 expectedError: ":UNSUPPORTED_PROTOCOL:",
4389 })
4390 testCases = append(testCases, testCase{
4391 protocol: dtls,
4392 testType: serverTest,
4393 name: "VersionTooLow-DTLS",
4394 config: Config{
4395 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004396 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004397 },
4398 },
4399 shouldFail: true,
4400 expectedError: ":UNSUPPORTED_PROTOCOL:",
4401 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004402
David Benjamin2dc02042016-09-19 19:57:37 -04004403 testCases = append(testCases, testCase{
4404 name: "ServerBogusVersion",
4405 config: Config{
4406 Bugs: ProtocolBugs{
4407 SendServerHelloVersion: 0x1234,
4408 },
4409 },
4410 shouldFail: true,
4411 expectedError: ":UNSUPPORTED_PROTOCOL:",
4412 })
4413
David Benjamin1f61f0d2016-07-10 12:20:35 -04004414 // Test TLS 1.3's downgrade signal.
4415 testCases = append(testCases, testCase{
4416 name: "Downgrade-TLS12-Client",
4417 config: Config{
4418 Bugs: ProtocolBugs{
4419 NegotiateVersion: VersionTLS12,
4420 },
4421 },
David Benjamin592b5322016-09-30 15:15:01 -04004422 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004423 // TODO(davidben): This test should fail once TLS 1.3 is final
4424 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004425 })
4426 testCases = append(testCases, testCase{
4427 testType: serverTest,
4428 name: "Downgrade-TLS12-Server",
4429 config: Config{
4430 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004431 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004432 },
4433 },
David Benjamin592b5322016-09-30 15:15:01 -04004434 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004435 // TODO(davidben): This test should fail once TLS 1.3 is final
4436 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004437 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004438}
4439
David Benjaminaccb4542014-12-12 23:44:33 -05004440func addMinimumVersionTests() {
4441 for i, shimVers := range tlsVersions {
4442 // Assemble flags to disable all older versions on the shim.
4443 var flags []string
4444 for _, vers := range tlsVersions[:i] {
4445 flags = append(flags, vers.flag)
4446 }
4447
4448 for _, runnerVers := range tlsVersions {
4449 protocols := []protocol{tls}
4450 if runnerVers.hasDTLS && shimVers.hasDTLS {
4451 protocols = append(protocols, dtls)
4452 }
4453 for _, protocol := range protocols {
4454 suffix := shimVers.name + "-" + runnerVers.name
4455 if protocol == dtls {
4456 suffix += "-DTLS"
4457 }
4458 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4459
David Benjaminaccb4542014-12-12 23:44:33 -05004460 var expectedVersion uint16
4461 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004462 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004463 if runnerVers.version >= shimVers.version {
4464 expectedVersion = runnerVers.version
4465 } else {
4466 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004467 expectedError = ":UNSUPPORTED_PROTOCOL:"
4468 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004469 }
4470
4471 testCases = append(testCases, testCase{
4472 protocol: protocol,
4473 testType: clientTest,
4474 name: "MinimumVersion-Client-" + suffix,
4475 config: Config{
4476 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004477 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004478 // Ensure the server does not decline to
4479 // select a version (versions extension) or
4480 // cipher (some ciphers depend on versions).
4481 NegotiateVersion: runnerVers.version,
4482 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004483 },
David Benjaminaccb4542014-12-12 23:44:33 -05004484 },
David Benjamin87909c02014-12-13 01:55:01 -05004485 flags: flags,
4486 expectedVersion: expectedVersion,
4487 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004488 expectedError: expectedError,
4489 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004490 })
4491 testCases = append(testCases, testCase{
4492 protocol: protocol,
4493 testType: clientTest,
4494 name: "MinimumVersion-Client2-" + suffix,
4495 config: Config{
4496 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004497 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004498 // Ensure the server does not decline to
4499 // select a version (versions extension) or
4500 // cipher (some ciphers depend on versions).
4501 NegotiateVersion: runnerVers.version,
4502 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004503 },
David Benjaminaccb4542014-12-12 23:44:33 -05004504 },
David Benjamin87909c02014-12-13 01:55:01 -05004505 flags: []string{"-min-version", shimVersFlag},
4506 expectedVersion: expectedVersion,
4507 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004508 expectedError: expectedError,
4509 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004510 })
4511
4512 testCases = append(testCases, testCase{
4513 protocol: protocol,
4514 testType: serverTest,
4515 name: "MinimumVersion-Server-" + suffix,
4516 config: Config{
4517 MaxVersion: runnerVers.version,
4518 },
David Benjamin87909c02014-12-13 01:55:01 -05004519 flags: flags,
4520 expectedVersion: expectedVersion,
4521 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004522 expectedError: expectedError,
4523 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004524 })
4525 testCases = append(testCases, testCase{
4526 protocol: protocol,
4527 testType: serverTest,
4528 name: "MinimumVersion-Server2-" + suffix,
4529 config: Config{
4530 MaxVersion: runnerVers.version,
4531 },
David Benjamin87909c02014-12-13 01:55:01 -05004532 flags: []string{"-min-version", shimVersFlag},
4533 expectedVersion: expectedVersion,
4534 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004535 expectedError: expectedError,
4536 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004537 })
4538 }
4539 }
4540 }
4541}
4542
David Benjamine78bfde2014-09-06 12:45:15 -04004543func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004544 // TODO(davidben): Extensions, where applicable, all move their server
4545 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4546 // tests for both. Also test interaction with 0-RTT when implemented.
4547
David Benjamin97d17d92016-07-14 16:12:00 -04004548 // Repeat extensions tests all versions except SSL 3.0.
4549 for _, ver := range tlsVersions {
4550 if ver.version == VersionSSL30 {
4551 continue
4552 }
4553
David Benjamin97d17d92016-07-14 16:12:00 -04004554 // Test that duplicate extensions are rejected.
4555 testCases = append(testCases, testCase{
4556 testType: clientTest,
4557 name: "DuplicateExtensionClient-" + ver.name,
4558 config: Config{
4559 MaxVersion: ver.version,
4560 Bugs: ProtocolBugs{
4561 DuplicateExtension: true,
4562 },
David Benjamine78bfde2014-09-06 12:45:15 -04004563 },
David Benjamin97d17d92016-07-14 16:12:00 -04004564 shouldFail: true,
4565 expectedLocalError: "remote error: error decoding message",
4566 })
4567 testCases = append(testCases, testCase{
4568 testType: serverTest,
4569 name: "DuplicateExtensionServer-" + ver.name,
4570 config: Config{
4571 MaxVersion: ver.version,
4572 Bugs: ProtocolBugs{
4573 DuplicateExtension: true,
4574 },
David Benjamine78bfde2014-09-06 12:45:15 -04004575 },
David Benjamin97d17d92016-07-14 16:12:00 -04004576 shouldFail: true,
4577 expectedLocalError: "remote error: error decoding message",
4578 })
4579
4580 // Test SNI.
4581 testCases = append(testCases, testCase{
4582 testType: clientTest,
4583 name: "ServerNameExtensionClient-" + ver.name,
4584 config: Config{
4585 MaxVersion: ver.version,
4586 Bugs: ProtocolBugs{
4587 ExpectServerName: "example.com",
4588 },
David Benjamine78bfde2014-09-06 12:45:15 -04004589 },
David Benjamin97d17d92016-07-14 16:12:00 -04004590 flags: []string{"-host-name", "example.com"},
4591 })
4592 testCases = append(testCases, testCase{
4593 testType: clientTest,
4594 name: "ServerNameExtensionClientMismatch-" + ver.name,
4595 config: Config{
4596 MaxVersion: ver.version,
4597 Bugs: ProtocolBugs{
4598 ExpectServerName: "mismatch.com",
4599 },
David Benjamine78bfde2014-09-06 12:45:15 -04004600 },
David Benjamin97d17d92016-07-14 16:12:00 -04004601 flags: []string{"-host-name", "example.com"},
4602 shouldFail: true,
4603 expectedLocalError: "tls: unexpected server name",
4604 })
4605 testCases = append(testCases, testCase{
4606 testType: clientTest,
4607 name: "ServerNameExtensionClientMissing-" + ver.name,
4608 config: Config{
4609 MaxVersion: ver.version,
4610 Bugs: ProtocolBugs{
4611 ExpectServerName: "missing.com",
4612 },
David Benjamine78bfde2014-09-06 12:45:15 -04004613 },
David Benjamin97d17d92016-07-14 16:12:00 -04004614 shouldFail: true,
4615 expectedLocalError: "tls: unexpected server name",
4616 })
4617 testCases = append(testCases, testCase{
4618 testType: serverTest,
4619 name: "ServerNameExtensionServer-" + ver.name,
4620 config: Config{
4621 MaxVersion: ver.version,
4622 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004623 },
David Benjamin97d17d92016-07-14 16:12:00 -04004624 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004625 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004626 })
4627
4628 // Test ALPN.
4629 testCases = append(testCases, testCase{
4630 testType: clientTest,
4631 name: "ALPNClient-" + ver.name,
4632 config: Config{
4633 MaxVersion: ver.version,
4634 NextProtos: []string{"foo"},
4635 },
4636 flags: []string{
4637 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4638 "-expect-alpn", "foo",
4639 },
4640 expectedNextProto: "foo",
4641 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004642 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004643 })
4644 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004645 testType: clientTest,
4646 name: "ALPNClient-Mismatch-" + ver.name,
4647 config: Config{
4648 MaxVersion: ver.version,
4649 Bugs: ProtocolBugs{
4650 SendALPN: "baz",
4651 },
4652 },
4653 flags: []string{
4654 "-advertise-alpn", "\x03foo\x03bar",
4655 },
4656 shouldFail: true,
4657 expectedError: ":INVALID_ALPN_PROTOCOL:",
4658 expectedLocalError: "remote error: illegal parameter",
4659 })
4660 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004661 testType: serverTest,
4662 name: "ALPNServer-" + ver.name,
4663 config: Config{
4664 MaxVersion: ver.version,
4665 NextProtos: []string{"foo", "bar", "baz"},
4666 },
4667 flags: []string{
4668 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4669 "-select-alpn", "foo",
4670 },
4671 expectedNextProto: "foo",
4672 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004673 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004674 })
4675 testCases = append(testCases, testCase{
4676 testType: serverTest,
4677 name: "ALPNServer-Decline-" + ver.name,
4678 config: Config{
4679 MaxVersion: ver.version,
4680 NextProtos: []string{"foo", "bar", "baz"},
4681 },
4682 flags: []string{"-decline-alpn"},
4683 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004684 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004685 })
4686
David Benjamin25fe85b2016-08-09 20:00:32 -04004687 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4688 // called once.
4689 testCases = append(testCases, testCase{
4690 testType: serverTest,
4691 name: "ALPNServer-Async-" + ver.name,
4692 config: Config{
4693 MaxVersion: ver.version,
4694 NextProtos: []string{"foo", "bar", "baz"},
4695 },
4696 flags: []string{
4697 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4698 "-select-alpn", "foo",
4699 "-async",
4700 },
4701 expectedNextProto: "foo",
4702 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004703 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004704 })
4705
David Benjamin97d17d92016-07-14 16:12:00 -04004706 var emptyString string
4707 testCases = append(testCases, testCase{
4708 testType: clientTest,
4709 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4710 config: Config{
4711 MaxVersion: ver.version,
4712 NextProtos: []string{""},
4713 Bugs: ProtocolBugs{
4714 // A server returning an empty ALPN protocol
4715 // should be rejected.
4716 ALPNProtocol: &emptyString,
4717 },
4718 },
4719 flags: []string{
4720 "-advertise-alpn", "\x03foo",
4721 },
4722 shouldFail: true,
4723 expectedError: ":PARSE_TLSEXT:",
4724 })
4725 testCases = append(testCases, testCase{
4726 testType: serverTest,
4727 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4728 config: Config{
4729 MaxVersion: ver.version,
4730 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004731 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004732 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004733 },
David Benjamin97d17d92016-07-14 16:12:00 -04004734 flags: []string{
4735 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004736 },
David Benjamin97d17d92016-07-14 16:12:00 -04004737 shouldFail: true,
4738 expectedError: ":PARSE_TLSEXT:",
4739 })
4740
4741 // Test NPN and the interaction with ALPN.
4742 if ver.version < VersionTLS13 {
4743 // Test that the server prefers ALPN over NPN.
4744 testCases = append(testCases, testCase{
4745 testType: serverTest,
4746 name: "ALPNServer-Preferred-" + ver.name,
4747 config: Config{
4748 MaxVersion: ver.version,
4749 NextProtos: []string{"foo", "bar", "baz"},
4750 },
4751 flags: []string{
4752 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4753 "-select-alpn", "foo",
4754 "-advertise-npn", "\x03foo\x03bar\x03baz",
4755 },
4756 expectedNextProto: "foo",
4757 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004758 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004759 })
4760 testCases = append(testCases, testCase{
4761 testType: serverTest,
4762 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4763 config: Config{
4764 MaxVersion: ver.version,
4765 NextProtos: []string{"foo", "bar", "baz"},
4766 Bugs: ProtocolBugs{
4767 SwapNPNAndALPN: true,
4768 },
4769 },
4770 flags: []string{
4771 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4772 "-select-alpn", "foo",
4773 "-advertise-npn", "\x03foo\x03bar\x03baz",
4774 },
4775 expectedNextProto: "foo",
4776 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004777 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004778 })
4779
4780 // Test that negotiating both NPN and ALPN is forbidden.
4781 testCases = append(testCases, testCase{
4782 name: "NegotiateALPNAndNPN-" + ver.name,
4783 config: Config{
4784 MaxVersion: ver.version,
4785 NextProtos: []string{"foo", "bar", "baz"},
4786 Bugs: ProtocolBugs{
4787 NegotiateALPNAndNPN: true,
4788 },
4789 },
4790 flags: []string{
4791 "-advertise-alpn", "\x03foo",
4792 "-select-next-proto", "foo",
4793 },
4794 shouldFail: true,
4795 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4796 })
4797 testCases = append(testCases, testCase{
4798 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4799 config: Config{
4800 MaxVersion: ver.version,
4801 NextProtos: []string{"foo", "bar", "baz"},
4802 Bugs: ProtocolBugs{
4803 NegotiateALPNAndNPN: true,
4804 SwapNPNAndALPN: true,
4805 },
4806 },
4807 flags: []string{
4808 "-advertise-alpn", "\x03foo",
4809 "-select-next-proto", "foo",
4810 },
4811 shouldFail: true,
4812 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4813 })
4814
4815 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4816 testCases = append(testCases, testCase{
4817 name: "DisableNPN-" + ver.name,
4818 config: Config{
4819 MaxVersion: ver.version,
4820 NextProtos: []string{"foo"},
4821 },
4822 flags: []string{
4823 "-select-next-proto", "foo",
4824 "-disable-npn",
4825 },
4826 expectNoNextProto: true,
4827 })
4828 }
4829
4830 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004831
4832 // Resume with a corrupt ticket.
4833 testCases = append(testCases, testCase{
4834 testType: serverTest,
4835 name: "CorruptTicket-" + ver.name,
4836 config: Config{
4837 MaxVersion: ver.version,
4838 Bugs: ProtocolBugs{
4839 CorruptTicket: true,
4840 },
4841 },
4842 resumeSession: true,
4843 expectResumeRejected: true,
4844 })
4845 // Test the ticket callback, with and without renewal.
4846 testCases = append(testCases, testCase{
4847 testType: serverTest,
4848 name: "TicketCallback-" + ver.name,
4849 config: Config{
4850 MaxVersion: ver.version,
4851 },
4852 resumeSession: true,
4853 flags: []string{"-use-ticket-callback"},
4854 })
4855 testCases = append(testCases, testCase{
4856 testType: serverTest,
4857 name: "TicketCallback-Renew-" + ver.name,
4858 config: Config{
4859 MaxVersion: ver.version,
4860 Bugs: ProtocolBugs{
4861 ExpectNewTicket: true,
4862 },
4863 },
4864 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4865 resumeSession: true,
4866 })
4867
4868 // Test that the ticket callback is only called once when everything before
4869 // it in the ClientHello is asynchronous. This corrupts the ticket so
4870 // certificate selection callbacks run.
4871 testCases = append(testCases, testCase{
4872 testType: serverTest,
4873 name: "TicketCallback-SingleCall-" + ver.name,
4874 config: Config{
4875 MaxVersion: ver.version,
4876 Bugs: ProtocolBugs{
4877 CorruptTicket: true,
4878 },
4879 },
4880 resumeSession: true,
4881 expectResumeRejected: true,
4882 flags: []string{
4883 "-use-ticket-callback",
4884 "-async",
4885 },
4886 })
4887
4888 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004889 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004890 testCases = append(testCases, testCase{
4891 testType: serverTest,
4892 name: "OversizedSessionId-" + ver.name,
4893 config: Config{
4894 MaxVersion: ver.version,
4895 Bugs: ProtocolBugs{
4896 OversizedSessionId: true,
4897 },
4898 },
4899 resumeSession: true,
4900 shouldFail: true,
4901 expectedError: ":DECODE_ERROR:",
4902 })
4903 }
4904
4905 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4906 // are ignored.
4907 if ver.hasDTLS {
4908 testCases = append(testCases, testCase{
4909 protocol: dtls,
4910 name: "SRTP-Client-" + ver.name,
4911 config: Config{
4912 MaxVersion: ver.version,
4913 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4914 },
4915 flags: []string{
4916 "-srtp-profiles",
4917 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4918 },
4919 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4920 })
4921 testCases = append(testCases, testCase{
4922 protocol: dtls,
4923 testType: serverTest,
4924 name: "SRTP-Server-" + ver.name,
4925 config: Config{
4926 MaxVersion: ver.version,
4927 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4928 },
4929 flags: []string{
4930 "-srtp-profiles",
4931 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4932 },
4933 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4934 })
4935 // Test that the MKI is ignored.
4936 testCases = append(testCases, testCase{
4937 protocol: dtls,
4938 testType: serverTest,
4939 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4940 config: Config{
4941 MaxVersion: ver.version,
4942 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4943 Bugs: ProtocolBugs{
4944 SRTPMasterKeyIdentifer: "bogus",
4945 },
4946 },
4947 flags: []string{
4948 "-srtp-profiles",
4949 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4950 },
4951 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4952 })
4953 // Test that SRTP isn't negotiated on the server if there were
4954 // no matching profiles.
4955 testCases = append(testCases, testCase{
4956 protocol: dtls,
4957 testType: serverTest,
4958 name: "SRTP-Server-NoMatch-" + ver.name,
4959 config: Config{
4960 MaxVersion: ver.version,
4961 SRTPProtectionProfiles: []uint16{100, 101, 102},
4962 },
4963 flags: []string{
4964 "-srtp-profiles",
4965 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4966 },
4967 expectedSRTPProtectionProfile: 0,
4968 })
4969 // Test that the server returning an invalid SRTP profile is
4970 // flagged as an error by the client.
4971 testCases = append(testCases, testCase{
4972 protocol: dtls,
4973 name: "SRTP-Client-NoMatch-" + ver.name,
4974 config: Config{
4975 MaxVersion: ver.version,
4976 Bugs: ProtocolBugs{
4977 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4978 },
4979 },
4980 flags: []string{
4981 "-srtp-profiles",
4982 "SRTP_AES128_CM_SHA1_80",
4983 },
4984 shouldFail: true,
4985 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4986 })
4987 }
4988
4989 // Test SCT list.
4990 testCases = append(testCases, testCase{
4991 name: "SignedCertificateTimestampList-Client-" + ver.name,
4992 testType: clientTest,
4993 config: Config{
4994 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004995 },
David Benjamin97d17d92016-07-14 16:12:00 -04004996 flags: []string{
4997 "-enable-signed-cert-timestamps",
4998 "-expect-signed-cert-timestamps",
4999 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005000 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005001 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005002 })
David Benjamindaa88502016-10-04 16:32:16 -04005003
5004 // The SCT extension did not specify that it must only be sent on resumption as it
5005 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005006 testCases = append(testCases, testCase{
5007 name: "SendSCTListOnResume-" + ver.name,
5008 config: Config{
5009 MaxVersion: ver.version,
5010 Bugs: ProtocolBugs{
5011 SendSCTListOnResume: []byte("bogus"),
5012 },
David Benjamind98452d2015-06-16 14:16:23 -04005013 },
David Benjamin97d17d92016-07-14 16:12:00 -04005014 flags: []string{
5015 "-enable-signed-cert-timestamps",
5016 "-expect-signed-cert-timestamps",
5017 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005018 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005019 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005020 })
David Benjamindaa88502016-10-04 16:32:16 -04005021
David Benjamin97d17d92016-07-14 16:12:00 -04005022 testCases = append(testCases, testCase{
5023 name: "SignedCertificateTimestampList-Server-" + ver.name,
5024 testType: serverTest,
5025 config: Config{
5026 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005027 },
David Benjamin97d17d92016-07-14 16:12:00 -04005028 flags: []string{
5029 "-signed-cert-timestamps",
5030 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005031 },
David Benjamin97d17d92016-07-14 16:12:00 -04005032 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005033 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005034 })
5035 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005036
Paul Lietar4fac72e2015-09-09 13:44:55 +01005037 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005038 testType: clientTest,
5039 name: "ClientHelloPadding",
5040 config: Config{
5041 Bugs: ProtocolBugs{
5042 RequireClientHelloSize: 512,
5043 },
5044 },
5045 // This hostname just needs to be long enough to push the
5046 // ClientHello into F5's danger zone between 256 and 511 bytes
5047 // long.
5048 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5049 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005050
5051 // Extensions should not function in SSL 3.0.
5052 testCases = append(testCases, testCase{
5053 testType: serverTest,
5054 name: "SSLv3Extensions-NoALPN",
5055 config: Config{
5056 MaxVersion: VersionSSL30,
5057 NextProtos: []string{"foo", "bar", "baz"},
5058 },
5059 flags: []string{
5060 "-select-alpn", "foo",
5061 },
5062 expectNoNextProto: true,
5063 })
5064
5065 // Test session tickets separately as they follow a different codepath.
5066 testCases = append(testCases, testCase{
5067 testType: serverTest,
5068 name: "SSLv3Extensions-NoTickets",
5069 config: Config{
5070 MaxVersion: VersionSSL30,
5071 Bugs: ProtocolBugs{
5072 // Historically, session tickets in SSL 3.0
5073 // failed in different ways depending on whether
5074 // the client supported renegotiation_info.
5075 NoRenegotiationInfo: true,
5076 },
5077 },
5078 resumeSession: true,
5079 })
5080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "SSLv3Extensions-NoTickets2",
5083 config: Config{
5084 MaxVersion: VersionSSL30,
5085 },
5086 resumeSession: true,
5087 })
5088
5089 // But SSL 3.0 does send and process renegotiation_info.
5090 testCases = append(testCases, testCase{
5091 testType: serverTest,
5092 name: "SSLv3Extensions-RenegotiationInfo",
5093 config: Config{
5094 MaxVersion: VersionSSL30,
5095 Bugs: ProtocolBugs{
5096 RequireRenegotiationInfo: true,
5097 },
5098 },
5099 })
5100 testCases = append(testCases, testCase{
5101 testType: serverTest,
5102 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5103 config: Config{
5104 MaxVersion: VersionSSL30,
5105 Bugs: ProtocolBugs{
5106 NoRenegotiationInfo: true,
5107 SendRenegotiationSCSV: true,
5108 RequireRenegotiationInfo: true,
5109 },
5110 },
5111 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005112
5113 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5114 // in ServerHello.
5115 testCases = append(testCases, testCase{
5116 name: "NPN-Forbidden-TLS13",
5117 config: Config{
5118 MaxVersion: VersionTLS13,
5119 NextProtos: []string{"foo"},
5120 Bugs: ProtocolBugs{
5121 NegotiateNPNAtAllVersions: true,
5122 },
5123 },
5124 flags: []string{"-select-next-proto", "foo"},
5125 shouldFail: true,
5126 expectedError: ":ERROR_PARSING_EXTENSION:",
5127 })
5128 testCases = append(testCases, testCase{
5129 name: "EMS-Forbidden-TLS13",
5130 config: Config{
5131 MaxVersion: VersionTLS13,
5132 Bugs: ProtocolBugs{
5133 NegotiateEMSAtAllVersions: true,
5134 },
5135 },
5136 shouldFail: true,
5137 expectedError: ":ERROR_PARSING_EXTENSION:",
5138 })
5139 testCases = append(testCases, testCase{
5140 name: "RenegotiationInfo-Forbidden-TLS13",
5141 config: Config{
5142 MaxVersion: VersionTLS13,
5143 Bugs: ProtocolBugs{
5144 NegotiateRenegotiationInfoAtAllVersions: true,
5145 },
5146 },
5147 shouldFail: true,
5148 expectedError: ":ERROR_PARSING_EXTENSION:",
5149 })
5150 testCases = append(testCases, testCase{
5151 name: "ChannelID-Forbidden-TLS13",
5152 config: Config{
5153 MaxVersion: VersionTLS13,
5154 RequestChannelID: true,
5155 Bugs: ProtocolBugs{
5156 NegotiateChannelIDAtAllVersions: true,
5157 },
5158 },
5159 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5160 shouldFail: true,
5161 expectedError: ":ERROR_PARSING_EXTENSION:",
5162 })
5163 testCases = append(testCases, testCase{
5164 name: "Ticket-Forbidden-TLS13",
5165 config: Config{
5166 MaxVersion: VersionTLS12,
5167 },
5168 resumeConfig: &Config{
5169 MaxVersion: VersionTLS13,
5170 Bugs: ProtocolBugs{
5171 AdvertiseTicketExtension: true,
5172 },
5173 },
5174 resumeSession: true,
5175 shouldFail: true,
5176 expectedError: ":ERROR_PARSING_EXTENSION:",
5177 })
5178
5179 // Test that illegal extensions in TLS 1.3 are declined by the server if
5180 // offered in ClientHello. The runner's server will fail if this occurs,
5181 // so we exercise the offering path. (EMS and Renegotiation Info are
5182 // implicit in every test.)
5183 testCases = append(testCases, testCase{
5184 testType: serverTest,
5185 name: "ChannelID-Declined-TLS13",
5186 config: Config{
5187 MaxVersion: VersionTLS13,
5188 ChannelID: channelIDKey,
5189 },
5190 flags: []string{"-enable-channel-id"},
5191 })
5192 testCases = append(testCases, testCase{
5193 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005194 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005195 config: Config{
5196 MaxVersion: VersionTLS13,
5197 NextProtos: []string{"bar"},
5198 },
5199 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5200 })
David Benjamin196df5b2016-09-21 16:23:27 -04005201
5202 testCases = append(testCases, testCase{
5203 testType: serverTest,
5204 name: "InvalidChannelIDSignature",
5205 config: Config{
5206 MaxVersion: VersionTLS12,
5207 ChannelID: channelIDKey,
5208 Bugs: ProtocolBugs{
5209 InvalidChannelIDSignature: true,
5210 },
5211 },
5212 flags: []string{"-enable-channel-id"},
5213 shouldFail: true,
5214 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5215 expectedLocalError: "remote error: error decrypting message",
5216 })
David Benjamindaa88502016-10-04 16:32:16 -04005217
5218 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5219 // tolerated.
5220 testCases = append(testCases, testCase{
5221 name: "SendOCSPResponseOnResume-TLS12",
5222 config: Config{
5223 MaxVersion: VersionTLS12,
5224 Bugs: ProtocolBugs{
5225 SendOCSPResponseOnResume: []byte("bogus"),
5226 },
5227 },
5228 flags: []string{
5229 "-enable-ocsp-stapling",
5230 "-expect-ocsp-response",
5231 base64.StdEncoding.EncodeToString(testOCSPResponse),
5232 },
5233 resumeSession: true,
5234 })
5235
5236 // Beginning TLS 1.3, enforce this does not happen.
5237 testCases = append(testCases, testCase{
5238 name: "SendOCSPResponseOnResume-TLS13",
5239 config: Config{
5240 MaxVersion: VersionTLS13,
5241 Bugs: ProtocolBugs{
5242 SendOCSPResponseOnResume: []byte("bogus"),
5243 },
5244 },
5245 flags: []string{
5246 "-enable-ocsp-stapling",
5247 "-expect-ocsp-response",
5248 base64.StdEncoding.EncodeToString(testOCSPResponse),
5249 },
5250 resumeSession: true,
5251 shouldFail: true,
5252 expectedError: ":ERROR_PARSING_EXTENSION:",
5253 })
David Benjamine78bfde2014-09-06 12:45:15 -04005254}
5255
David Benjamin01fe8202014-09-24 15:21:44 -04005256func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005257 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005258 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005259 // SSL 3.0 does not have tickets and TLS 1.3 does not
5260 // have session IDs, so skip their cross-resumption
5261 // tests.
5262 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5263 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5264 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005265 }
5266
David Benjamin8b8c0062014-11-23 02:47:52 -05005267 protocols := []protocol{tls}
5268 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5269 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005270 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005271 for _, protocol := range protocols {
5272 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5273 if protocol == dtls {
5274 suffix += "-DTLS"
5275 }
5276
David Benjaminece3de92015-03-16 18:02:20 -04005277 if sessionVers.version == resumeVers.version {
5278 testCases = append(testCases, testCase{
5279 protocol: protocol,
5280 name: "Resume-Client" + suffix,
5281 resumeSession: true,
5282 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005283 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005284 Bugs: ProtocolBugs{
5285 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5286 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5287 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005288 },
David Benjaminece3de92015-03-16 18:02:20 -04005289 expectedVersion: sessionVers.version,
5290 expectedResumeVersion: resumeVers.version,
5291 })
5292 } else {
David Benjamin405da482016-08-08 17:25:07 -04005293 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5294
5295 // Offering a TLS 1.3 session sends an empty session ID, so
5296 // there is no way to convince a non-lookahead client the
5297 // session was resumed. It will appear to the client that a
5298 // stray ChangeCipherSpec was sent.
5299 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5300 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005301 }
5302
David Benjaminece3de92015-03-16 18:02:20 -04005303 testCases = append(testCases, testCase{
5304 protocol: protocol,
5305 name: "Resume-Client-Mismatch" + suffix,
5306 resumeSession: true,
5307 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005308 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005309 },
David Benjaminece3de92015-03-16 18:02:20 -04005310 expectedVersion: sessionVers.version,
5311 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005312 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005313 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005314 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005315 },
5316 },
5317 expectedResumeVersion: resumeVers.version,
5318 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005319 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005320 })
5321 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005322
5323 testCases = append(testCases, testCase{
5324 protocol: protocol,
5325 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005326 resumeSession: true,
5327 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005328 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005329 },
5330 expectedVersion: sessionVers.version,
5331 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005332 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005333 },
5334 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005335 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005336 expectedResumeVersion: resumeVers.version,
5337 })
5338
David Benjamin8b8c0062014-11-23 02:47:52 -05005339 testCases = append(testCases, testCase{
5340 protocol: protocol,
5341 testType: serverTest,
5342 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005343 resumeSession: true,
5344 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005345 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005346 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005347 expectedVersion: sessionVers.version,
5348 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005349 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005350 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005351 Bugs: ProtocolBugs{
5352 SendBothTickets: true,
5353 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005354 },
5355 expectedResumeVersion: resumeVers.version,
5356 })
5357 }
David Benjamin01fe8202014-09-24 15:21:44 -04005358 }
5359 }
David Benjaminece3de92015-03-16 18:02:20 -04005360
5361 testCases = append(testCases, testCase{
5362 name: "Resume-Client-CipherMismatch",
5363 resumeSession: true,
5364 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005365 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005366 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5367 },
5368 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005369 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005370 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5371 Bugs: ProtocolBugs{
5372 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5373 },
5374 },
5375 shouldFail: true,
5376 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5377 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005378
5379 testCases = append(testCases, testCase{
5380 name: "Resume-Client-CipherMismatch-TLS13",
5381 resumeSession: true,
5382 config: Config{
5383 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005384 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005385 },
5386 resumeConfig: &Config{
5387 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005388 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005389 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005390 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005391 },
5392 },
5393 shouldFail: true,
5394 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5395 })
David Benjamin01fe8202014-09-24 15:21:44 -04005396}
5397
Adam Langley2ae77d22014-10-28 17:29:33 -07005398func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005399 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005400 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005401 testType: serverTest,
5402 name: "Renegotiate-Server-Forbidden",
5403 config: Config{
5404 MaxVersion: VersionTLS12,
5405 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005406 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005407 shouldFail: true,
5408 expectedError: ":NO_RENEGOTIATION:",
5409 expectedLocalError: "remote error: no renegotiation",
5410 })
Adam Langley5021b222015-06-12 18:27:58 -07005411 // The server shouldn't echo the renegotiation extension unless
5412 // requested by the client.
5413 testCases = append(testCases, testCase{
5414 testType: serverTest,
5415 name: "Renegotiate-Server-NoExt",
5416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005417 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005418 Bugs: ProtocolBugs{
5419 NoRenegotiationInfo: true,
5420 RequireRenegotiationInfo: true,
5421 },
5422 },
5423 shouldFail: true,
5424 expectedLocalError: "renegotiation extension missing",
5425 })
5426 // The renegotiation SCSV should be sufficient for the server to echo
5427 // the extension.
5428 testCases = append(testCases, testCase{
5429 testType: serverTest,
5430 name: "Renegotiate-Server-NoExt-SCSV",
5431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005432 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005433 Bugs: ProtocolBugs{
5434 NoRenegotiationInfo: true,
5435 SendRenegotiationSCSV: true,
5436 RequireRenegotiationInfo: true,
5437 },
5438 },
5439 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005440 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005441 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005443 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005444 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005445 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005446 },
5447 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005448 renegotiate: 1,
5449 flags: []string{
5450 "-renegotiate-freely",
5451 "-expect-total-renegotiations", "1",
5452 },
David Benjamincdea40c2015-03-19 14:09:43 -04005453 })
5454 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005455 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005456 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005457 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005458 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005459 Bugs: ProtocolBugs{
5460 EmptyRenegotiationInfo: true,
5461 },
5462 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005463 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005464 shouldFail: true,
5465 expectedError: ":RENEGOTIATION_MISMATCH:",
5466 })
5467 testCases = append(testCases, testCase{
5468 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005469 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005471 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005472 Bugs: ProtocolBugs{
5473 BadRenegotiationInfo: true,
5474 },
5475 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005476 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005477 shouldFail: true,
5478 expectedError: ":RENEGOTIATION_MISMATCH:",
5479 })
5480 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005481 name: "Renegotiate-Client-Downgrade",
5482 renegotiate: 1,
5483 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005484 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005485 Bugs: ProtocolBugs{
5486 NoRenegotiationInfoAfterInitial: true,
5487 },
5488 },
5489 flags: []string{"-renegotiate-freely"},
5490 shouldFail: true,
5491 expectedError: ":RENEGOTIATION_MISMATCH:",
5492 })
5493 testCases = append(testCases, testCase{
5494 name: "Renegotiate-Client-Upgrade",
5495 renegotiate: 1,
5496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005497 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005498 Bugs: ProtocolBugs{
5499 NoRenegotiationInfoInInitial: true,
5500 },
5501 },
5502 flags: []string{"-renegotiate-freely"},
5503 shouldFail: true,
5504 expectedError: ":RENEGOTIATION_MISMATCH:",
5505 })
5506 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005507 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005508 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005509 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005510 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005511 Bugs: ProtocolBugs{
5512 NoRenegotiationInfo: true,
5513 },
5514 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005515 flags: []string{
5516 "-renegotiate-freely",
5517 "-expect-total-renegotiations", "1",
5518 },
David Benjamincff0b902015-05-15 23:09:47 -04005519 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005520
5521 // Test that the server may switch ciphers on renegotiation without
5522 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005523 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005524 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005525 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005526 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005527 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005528 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005529 },
5530 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005531 flags: []string{
5532 "-renegotiate-freely",
5533 "-expect-total-renegotiations", "1",
5534 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005535 })
5536 testCases = append(testCases, testCase{
5537 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005538 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005540 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005541 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5542 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005543 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005544 flags: []string{
5545 "-renegotiate-freely",
5546 "-expect-total-renegotiations", "1",
5547 },
David Benjaminb16346b2015-04-08 19:16:58 -04005548 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005549
5550 // Test that the server may not switch versions on renegotiation.
5551 testCases = append(testCases, testCase{
5552 name: "Renegotiate-Client-SwitchVersion",
5553 config: Config{
5554 MaxVersion: VersionTLS12,
5555 // Pick a cipher which exists at both versions.
5556 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5557 Bugs: ProtocolBugs{
5558 NegotiateVersionOnRenego: VersionTLS11,
5559 },
5560 },
5561 renegotiate: 1,
5562 flags: []string{
5563 "-renegotiate-freely",
5564 "-expect-total-renegotiations", "1",
5565 },
5566 shouldFail: true,
5567 expectedError: ":WRONG_SSL_VERSION:",
5568 })
5569
David Benjaminb16346b2015-04-08 19:16:58 -04005570 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005571 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005572 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005573 config: Config{
5574 MaxVersion: VersionTLS10,
5575 Bugs: ProtocolBugs{
5576 RequireSameRenegoClientVersion: true,
5577 },
5578 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005579 flags: []string{
5580 "-renegotiate-freely",
5581 "-expect-total-renegotiations", "1",
5582 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005583 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005584 testCases = append(testCases, testCase{
5585 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005586 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005587 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005588 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005589 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5590 NextProtos: []string{"foo"},
5591 },
5592 flags: []string{
5593 "-false-start",
5594 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005595 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005596 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005597 },
5598 shimWritesFirst: true,
5599 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005600
5601 // Client-side renegotiation controls.
5602 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005603 name: "Renegotiate-Client-Forbidden-1",
5604 config: Config{
5605 MaxVersion: VersionTLS12,
5606 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005607 renegotiate: 1,
5608 shouldFail: true,
5609 expectedError: ":NO_RENEGOTIATION:",
5610 expectedLocalError: "remote error: no renegotiation",
5611 })
5612 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005613 name: "Renegotiate-Client-Once-1",
5614 config: Config{
5615 MaxVersion: VersionTLS12,
5616 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005617 renegotiate: 1,
5618 flags: []string{
5619 "-renegotiate-once",
5620 "-expect-total-renegotiations", "1",
5621 },
5622 })
5623 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005624 name: "Renegotiate-Client-Freely-1",
5625 config: Config{
5626 MaxVersion: VersionTLS12,
5627 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005628 renegotiate: 1,
5629 flags: []string{
5630 "-renegotiate-freely",
5631 "-expect-total-renegotiations", "1",
5632 },
5633 })
5634 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005635 name: "Renegotiate-Client-Once-2",
5636 config: Config{
5637 MaxVersion: VersionTLS12,
5638 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005639 renegotiate: 2,
5640 flags: []string{"-renegotiate-once"},
5641 shouldFail: true,
5642 expectedError: ":NO_RENEGOTIATION:",
5643 expectedLocalError: "remote error: no renegotiation",
5644 })
5645 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005646 name: "Renegotiate-Client-Freely-2",
5647 config: Config{
5648 MaxVersion: VersionTLS12,
5649 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005650 renegotiate: 2,
5651 flags: []string{
5652 "-renegotiate-freely",
5653 "-expect-total-renegotiations", "2",
5654 },
5655 })
Adam Langley27a0d082015-11-03 13:34:10 -08005656 testCases = append(testCases, testCase{
5657 name: "Renegotiate-Client-NoIgnore",
5658 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005659 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005660 Bugs: ProtocolBugs{
5661 SendHelloRequestBeforeEveryAppDataRecord: true,
5662 },
5663 },
5664 shouldFail: true,
5665 expectedError: ":NO_RENEGOTIATION:",
5666 })
5667 testCases = append(testCases, testCase{
5668 name: "Renegotiate-Client-Ignore",
5669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005670 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005671 Bugs: ProtocolBugs{
5672 SendHelloRequestBeforeEveryAppDataRecord: true,
5673 },
5674 },
5675 flags: []string{
5676 "-renegotiate-ignore",
5677 "-expect-total-renegotiations", "0",
5678 },
5679 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005680
David Benjamin397c8e62016-07-08 14:14:36 -07005681 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005682 testCases = append(testCases, testCase{
5683 name: "StrayHelloRequest",
5684 config: Config{
5685 MaxVersion: VersionTLS12,
5686 Bugs: ProtocolBugs{
5687 SendHelloRequestBeforeEveryHandshakeMessage: true,
5688 },
5689 },
5690 })
5691 testCases = append(testCases, testCase{
5692 name: "StrayHelloRequest-Packed",
5693 config: Config{
5694 MaxVersion: VersionTLS12,
5695 Bugs: ProtocolBugs{
5696 PackHandshakeFlight: true,
5697 SendHelloRequestBeforeEveryHandshakeMessage: true,
5698 },
5699 },
5700 })
5701
David Benjamin12d2c482016-07-24 10:56:51 -04005702 // Test renegotiation works if HelloRequest and server Finished come in
5703 // the same record.
5704 testCases = append(testCases, testCase{
5705 name: "Renegotiate-Client-Packed",
5706 config: Config{
5707 MaxVersion: VersionTLS12,
5708 Bugs: ProtocolBugs{
5709 PackHandshakeFlight: true,
5710 PackHelloRequestWithFinished: true,
5711 },
5712 },
5713 renegotiate: 1,
5714 flags: []string{
5715 "-renegotiate-freely",
5716 "-expect-total-renegotiations", "1",
5717 },
5718 })
5719
David Benjamin397c8e62016-07-08 14:14:36 -07005720 // Renegotiation is forbidden in TLS 1.3.
5721 testCases = append(testCases, testCase{
5722 name: "Renegotiate-Client-TLS13",
5723 config: Config{
5724 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005725 Bugs: ProtocolBugs{
5726 SendHelloRequestBeforeEveryAppDataRecord: true,
5727 },
David Benjamin397c8e62016-07-08 14:14:36 -07005728 },
David Benjamin397c8e62016-07-08 14:14:36 -07005729 flags: []string{
5730 "-renegotiate-freely",
5731 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005732 shouldFail: true,
5733 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005734 })
5735
5736 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5737 testCases = append(testCases, testCase{
5738 name: "StrayHelloRequest-TLS13",
5739 config: Config{
5740 MaxVersion: VersionTLS13,
5741 Bugs: ProtocolBugs{
5742 SendHelloRequestBeforeEveryHandshakeMessage: true,
5743 },
5744 },
5745 shouldFail: true,
5746 expectedError: ":UNEXPECTED_MESSAGE:",
5747 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005748}
5749
David Benjamin5e961c12014-11-07 01:48:35 -05005750func addDTLSReplayTests() {
5751 // Test that sequence number replays are detected.
5752 testCases = append(testCases, testCase{
5753 protocol: dtls,
5754 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005755 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005756 replayWrites: true,
5757 })
5758
David Benjamin8e6db492015-07-25 18:29:23 -04005759 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005760 // than the retransmit window.
5761 testCases = append(testCases, testCase{
5762 protocol: dtls,
5763 name: "DTLS-Replay-LargeGaps",
5764 config: Config{
5765 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005766 SequenceNumberMapping: func(in uint64) uint64 {
5767 return in * 127
5768 },
David Benjamin5e961c12014-11-07 01:48:35 -05005769 },
5770 },
David Benjamin8e6db492015-07-25 18:29:23 -04005771 messageCount: 200,
5772 replayWrites: true,
5773 })
5774
5775 // Test the incoming sequence number changing non-monotonically.
5776 testCases = append(testCases, testCase{
5777 protocol: dtls,
5778 name: "DTLS-Replay-NonMonotonic",
5779 config: Config{
5780 Bugs: ProtocolBugs{
5781 SequenceNumberMapping: func(in uint64) uint64 {
5782 return in ^ 31
5783 },
5784 },
5785 },
5786 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005787 replayWrites: true,
5788 })
5789}
5790
Nick Harper60edffd2016-06-21 15:19:24 -07005791var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005792 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005793 id signatureAlgorithm
5794 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005795}{
Nick Harper60edffd2016-06-21 15:19:24 -07005796 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5797 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5798 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5799 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005800 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005801 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5802 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5803 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005804 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5805 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5806 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005807 // Tests for key types prior to TLS 1.2.
5808 {"RSA", 0, testCertRSA},
5809 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005810}
5811
Nick Harper60edffd2016-06-21 15:19:24 -07005812const fakeSigAlg1 signatureAlgorithm = 0x2a01
5813const fakeSigAlg2 signatureAlgorithm = 0xff01
5814
5815func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005816 // Not all ciphers involve a signature. Advertise a list which gives all
5817 // versions a signing cipher.
5818 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04005819 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04005820 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5821 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5822 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5823 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5824 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5825 }
5826
David Benjaminca3d5452016-07-14 12:51:01 -04005827 var allAlgorithms []signatureAlgorithm
5828 for _, alg := range testSignatureAlgorithms {
5829 if alg.id != 0 {
5830 allAlgorithms = append(allAlgorithms, alg.id)
5831 }
5832 }
5833
Nick Harper60edffd2016-06-21 15:19:24 -07005834 // Make sure each signature algorithm works. Include some fake values in
5835 // the list and ensure they're ignored.
5836 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005837 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005838 if (ver.version < VersionTLS12) != (alg.id == 0) {
5839 continue
5840 }
5841
5842 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5843 // or remove it in C.
5844 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005845 continue
5846 }
Nick Harper60edffd2016-06-21 15:19:24 -07005847
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005848 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005849 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005850 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5851 shouldFail = true
5852 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005853 // RSA-PKCS1 does not exist in TLS 1.3.
5854 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5855 shouldFail = true
5856 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005857
5858 var signError, verifyError string
5859 if shouldFail {
5860 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5861 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005862 }
David Benjamin000800a2014-11-14 01:43:59 -05005863
David Benjamin1fb125c2016-07-08 18:52:12 -07005864 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005865
David Benjamin7a41d372016-07-09 11:21:54 -07005866 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005867 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005868 config: Config{
5869 MaxVersion: ver.version,
5870 ClientAuth: RequireAnyClientCert,
5871 VerifySignatureAlgorithms: []signatureAlgorithm{
5872 fakeSigAlg1,
5873 alg.id,
5874 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005875 },
David Benjamin7a41d372016-07-09 11:21:54 -07005876 },
5877 flags: []string{
5878 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5879 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5880 "-enable-all-curves",
5881 },
5882 shouldFail: shouldFail,
5883 expectedError: signError,
5884 expectedPeerSignatureAlgorithm: alg.id,
5885 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005886
David Benjamin7a41d372016-07-09 11:21:54 -07005887 testCases = append(testCases, testCase{
5888 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005889 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005890 config: Config{
5891 MaxVersion: ver.version,
5892 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5893 SignSignatureAlgorithms: []signatureAlgorithm{
5894 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005895 },
David Benjamin7a41d372016-07-09 11:21:54 -07005896 Bugs: ProtocolBugs{
5897 SkipECDSACurveCheck: shouldFail,
5898 IgnoreSignatureVersionChecks: shouldFail,
5899 // The client won't advertise 1.3-only algorithms after
5900 // version negotiation.
5901 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005902 },
David Benjamin7a41d372016-07-09 11:21:54 -07005903 },
5904 flags: []string{
5905 "-require-any-client-certificate",
5906 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5907 "-enable-all-curves",
5908 },
5909 shouldFail: shouldFail,
5910 expectedError: verifyError,
5911 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005912
5913 testCases = append(testCases, testCase{
5914 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005915 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005916 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005917 MaxVersion: ver.version,
5918 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005919 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005920 fakeSigAlg1,
5921 alg.id,
5922 fakeSigAlg2,
5923 },
5924 },
5925 flags: []string{
5926 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5927 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5928 "-enable-all-curves",
5929 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005930 shouldFail: shouldFail,
5931 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005932 expectedPeerSignatureAlgorithm: alg.id,
5933 })
5934
5935 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005936 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005937 config: Config{
5938 MaxVersion: ver.version,
5939 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005940 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005941 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005942 alg.id,
5943 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005944 Bugs: ProtocolBugs{
5945 SkipECDSACurveCheck: shouldFail,
5946 IgnoreSignatureVersionChecks: shouldFail,
5947 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005948 },
5949 flags: []string{
5950 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5951 "-enable-all-curves",
5952 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005953 shouldFail: shouldFail,
5954 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005955 })
David Benjamin5208fd42016-07-13 21:43:25 -04005956
5957 if !shouldFail {
5958 testCases = append(testCases, testCase{
5959 testType: serverTest,
5960 name: "ClientAuth-InvalidSignature" + suffix,
5961 config: Config{
5962 MaxVersion: ver.version,
5963 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5964 SignSignatureAlgorithms: []signatureAlgorithm{
5965 alg.id,
5966 },
5967 Bugs: ProtocolBugs{
5968 InvalidSignature: true,
5969 },
5970 },
5971 flags: []string{
5972 "-require-any-client-certificate",
5973 "-enable-all-curves",
5974 },
5975 shouldFail: true,
5976 expectedError: ":BAD_SIGNATURE:",
5977 })
5978
5979 testCases = append(testCases, testCase{
5980 name: "ServerAuth-InvalidSignature" + suffix,
5981 config: Config{
5982 MaxVersion: ver.version,
5983 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5984 CipherSuites: signingCiphers,
5985 SignSignatureAlgorithms: []signatureAlgorithm{
5986 alg.id,
5987 },
5988 Bugs: ProtocolBugs{
5989 InvalidSignature: true,
5990 },
5991 },
5992 flags: []string{"-enable-all-curves"},
5993 shouldFail: true,
5994 expectedError: ":BAD_SIGNATURE:",
5995 })
5996 }
David Benjaminca3d5452016-07-14 12:51:01 -04005997
5998 if ver.version >= VersionTLS12 && !shouldFail {
5999 testCases = append(testCases, testCase{
6000 name: "ClientAuth-Sign-Negotiate" + suffix,
6001 config: Config{
6002 MaxVersion: ver.version,
6003 ClientAuth: RequireAnyClientCert,
6004 VerifySignatureAlgorithms: allAlgorithms,
6005 },
6006 flags: []string{
6007 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6008 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6009 "-enable-all-curves",
6010 "-signing-prefs", strconv.Itoa(int(alg.id)),
6011 },
6012 expectedPeerSignatureAlgorithm: alg.id,
6013 })
6014
6015 testCases = append(testCases, testCase{
6016 testType: serverTest,
6017 name: "ServerAuth-Sign-Negotiate" + suffix,
6018 config: Config{
6019 MaxVersion: ver.version,
6020 CipherSuites: signingCiphers,
6021 VerifySignatureAlgorithms: allAlgorithms,
6022 },
6023 flags: []string{
6024 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6025 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6026 "-enable-all-curves",
6027 "-signing-prefs", strconv.Itoa(int(alg.id)),
6028 },
6029 expectedPeerSignatureAlgorithm: alg.id,
6030 })
6031 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006032 }
David Benjamin000800a2014-11-14 01:43:59 -05006033 }
6034
Nick Harper60edffd2016-06-21 15:19:24 -07006035 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006036 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006037 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006038 config: Config{
6039 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006040 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006041 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006042 signatureECDSAWithP521AndSHA512,
6043 signatureRSAPKCS1WithSHA384,
6044 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006045 },
6046 },
6047 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006048 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6049 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006050 },
Nick Harper60edffd2016-06-21 15:19:24 -07006051 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006052 })
6053
6054 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006055 name: "ClientAuth-SignatureType-TLS13",
6056 config: Config{
6057 ClientAuth: RequireAnyClientCert,
6058 MaxVersion: VersionTLS13,
6059 VerifySignatureAlgorithms: []signatureAlgorithm{
6060 signatureECDSAWithP521AndSHA512,
6061 signatureRSAPKCS1WithSHA384,
6062 signatureRSAPSSWithSHA384,
6063 signatureECDSAWithSHA1,
6064 },
6065 },
6066 flags: []string{
6067 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6068 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6069 },
6070 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6071 })
6072
6073 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006074 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006075 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006077 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006079 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006080 signatureECDSAWithP521AndSHA512,
6081 signatureRSAPKCS1WithSHA384,
6082 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006083 },
6084 },
Nick Harper60edffd2016-06-21 15:19:24 -07006085 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006086 })
6087
Steven Valdez143e8b32016-07-11 13:19:03 -04006088 testCases = append(testCases, testCase{
6089 testType: serverTest,
6090 name: "ServerAuth-SignatureType-TLS13",
6091 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006092 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006093 VerifySignatureAlgorithms: []signatureAlgorithm{
6094 signatureECDSAWithP521AndSHA512,
6095 signatureRSAPKCS1WithSHA384,
6096 signatureRSAPSSWithSHA384,
6097 signatureECDSAWithSHA1,
6098 },
6099 },
6100 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6101 })
6102
David Benjamina95e9f32016-07-08 16:28:04 -07006103 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006104 testCases = append(testCases, testCase{
6105 testType: serverTest,
6106 name: "Verify-ClientAuth-SignatureType",
6107 config: Config{
6108 MaxVersion: VersionTLS12,
6109 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006110 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006111 signatureRSAPKCS1WithSHA256,
6112 },
6113 Bugs: ProtocolBugs{
6114 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6115 },
6116 },
6117 flags: []string{
6118 "-require-any-client-certificate",
6119 },
6120 shouldFail: true,
6121 expectedError: ":WRONG_SIGNATURE_TYPE:",
6122 })
6123
6124 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006125 testType: serverTest,
6126 name: "Verify-ClientAuth-SignatureType-TLS13",
6127 config: Config{
6128 MaxVersion: VersionTLS13,
6129 Certificates: []Certificate{rsaCertificate},
6130 SignSignatureAlgorithms: []signatureAlgorithm{
6131 signatureRSAPSSWithSHA256,
6132 },
6133 Bugs: ProtocolBugs{
6134 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6135 },
6136 },
6137 flags: []string{
6138 "-require-any-client-certificate",
6139 },
6140 shouldFail: true,
6141 expectedError: ":WRONG_SIGNATURE_TYPE:",
6142 })
6143
6144 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006145 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006146 config: Config{
6147 MaxVersion: VersionTLS12,
6148 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006149 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006150 signatureRSAPKCS1WithSHA256,
6151 },
6152 Bugs: ProtocolBugs{
6153 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6154 },
6155 },
6156 shouldFail: true,
6157 expectedError: ":WRONG_SIGNATURE_TYPE:",
6158 })
6159
Steven Valdez143e8b32016-07-11 13:19:03 -04006160 testCases = append(testCases, testCase{
6161 name: "Verify-ServerAuth-SignatureType-TLS13",
6162 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006163 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006164 SignSignatureAlgorithms: []signatureAlgorithm{
6165 signatureRSAPSSWithSHA256,
6166 },
6167 Bugs: ProtocolBugs{
6168 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6169 },
6170 },
6171 shouldFail: true,
6172 expectedError: ":WRONG_SIGNATURE_TYPE:",
6173 })
6174
David Benjamin51dd7d62016-07-08 16:07:01 -07006175 // Test that, if the list is missing, the peer falls back to SHA-1 in
6176 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006177 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006178 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006179 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006180 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006181 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006182 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006183 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006184 },
6185 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006186 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006187 },
6188 },
6189 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006190 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6191 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006192 },
6193 })
6194
6195 testCases = append(testCases, testCase{
6196 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006197 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006198 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006199 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006200 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006201 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006202 },
6203 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006204 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006205 },
6206 },
David Benjaminee32bea2016-08-17 13:36:44 -04006207 flags: []string{
6208 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6209 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6210 },
6211 })
6212
6213 testCases = append(testCases, testCase{
6214 name: "ClientAuth-SHA1-Fallback-ECDSA",
6215 config: Config{
6216 MaxVersion: VersionTLS12,
6217 ClientAuth: RequireAnyClientCert,
6218 VerifySignatureAlgorithms: []signatureAlgorithm{
6219 signatureECDSAWithSHA1,
6220 },
6221 Bugs: ProtocolBugs{
6222 NoSignatureAlgorithms: true,
6223 },
6224 },
6225 flags: []string{
6226 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6227 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6228 },
6229 })
6230
6231 testCases = append(testCases, testCase{
6232 testType: serverTest,
6233 name: "ServerAuth-SHA1-Fallback-ECDSA",
6234 config: Config{
6235 MaxVersion: VersionTLS12,
6236 VerifySignatureAlgorithms: []signatureAlgorithm{
6237 signatureECDSAWithSHA1,
6238 },
6239 Bugs: ProtocolBugs{
6240 NoSignatureAlgorithms: true,
6241 },
6242 },
6243 flags: []string{
6244 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6245 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6246 },
David Benjamin000800a2014-11-14 01:43:59 -05006247 })
David Benjamin72dc7832015-03-16 17:49:43 -04006248
David Benjamin51dd7d62016-07-08 16:07:01 -07006249 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006250 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006251 config: Config{
6252 MaxVersion: VersionTLS13,
6253 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006254 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006255 signatureRSAPKCS1WithSHA1,
6256 },
6257 Bugs: ProtocolBugs{
6258 NoSignatureAlgorithms: true,
6259 },
6260 },
6261 flags: []string{
6262 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6263 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6264 },
David Benjamin48901652016-08-01 12:12:47 -04006265 shouldFail: true,
6266 // An empty CertificateRequest signature algorithm list is a
6267 // syntax error in TLS 1.3.
6268 expectedError: ":DECODE_ERROR:",
6269 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006270 })
6271
6272 testCases = append(testCases, testCase{
6273 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006274 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006275 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006276 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006277 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006278 signatureRSAPKCS1WithSHA1,
6279 },
6280 Bugs: ProtocolBugs{
6281 NoSignatureAlgorithms: true,
6282 },
6283 },
6284 shouldFail: true,
6285 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6286 })
6287
David Benjaminb62d2872016-07-18 14:55:02 +02006288 // Test that hash preferences are enforced. BoringSSL does not implement
6289 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006290 testCases = append(testCases, testCase{
6291 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006292 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006293 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006294 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006295 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006296 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006297 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006298 },
6299 Bugs: ProtocolBugs{
6300 IgnorePeerSignatureAlgorithmPreferences: true,
6301 },
6302 },
6303 flags: []string{"-require-any-client-certificate"},
6304 shouldFail: true,
6305 expectedError: ":WRONG_SIGNATURE_TYPE:",
6306 })
6307
6308 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006309 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006310 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006311 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006312 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006313 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006314 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006315 },
6316 Bugs: ProtocolBugs{
6317 IgnorePeerSignatureAlgorithmPreferences: true,
6318 },
6319 },
6320 shouldFail: true,
6321 expectedError: ":WRONG_SIGNATURE_TYPE:",
6322 })
David Benjaminb62d2872016-07-18 14:55:02 +02006323 testCases = append(testCases, testCase{
6324 testType: serverTest,
6325 name: "ClientAuth-Enforced-TLS13",
6326 config: Config{
6327 MaxVersion: VersionTLS13,
6328 Certificates: []Certificate{rsaCertificate},
6329 SignSignatureAlgorithms: []signatureAlgorithm{
6330 signatureRSAPKCS1WithMD5,
6331 },
6332 Bugs: ProtocolBugs{
6333 IgnorePeerSignatureAlgorithmPreferences: true,
6334 IgnoreSignatureVersionChecks: true,
6335 },
6336 },
6337 flags: []string{"-require-any-client-certificate"},
6338 shouldFail: true,
6339 expectedError: ":WRONG_SIGNATURE_TYPE:",
6340 })
6341
6342 testCases = append(testCases, testCase{
6343 name: "ServerAuth-Enforced-TLS13",
6344 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006345 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006346 SignSignatureAlgorithms: []signatureAlgorithm{
6347 signatureRSAPKCS1WithMD5,
6348 },
6349 Bugs: ProtocolBugs{
6350 IgnorePeerSignatureAlgorithmPreferences: true,
6351 IgnoreSignatureVersionChecks: true,
6352 },
6353 },
6354 shouldFail: true,
6355 expectedError: ":WRONG_SIGNATURE_TYPE:",
6356 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006357
6358 // Test that the agreed upon digest respects the client preferences and
6359 // the server digests.
6360 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006361 name: "NoCommonAlgorithms-Digests",
6362 config: Config{
6363 MaxVersion: VersionTLS12,
6364 ClientAuth: RequireAnyClientCert,
6365 VerifySignatureAlgorithms: []signatureAlgorithm{
6366 signatureRSAPKCS1WithSHA512,
6367 signatureRSAPKCS1WithSHA1,
6368 },
6369 },
6370 flags: []string{
6371 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6372 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6373 "-digest-prefs", "SHA256",
6374 },
6375 shouldFail: true,
6376 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6377 })
6378 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006379 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006380 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006381 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006382 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006383 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006384 signatureRSAPKCS1WithSHA512,
6385 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006386 },
6387 },
6388 flags: []string{
6389 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6390 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006391 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006392 },
David Benjaminca3d5452016-07-14 12:51:01 -04006393 shouldFail: true,
6394 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6395 })
6396 testCases = append(testCases, testCase{
6397 name: "NoCommonAlgorithms-TLS13",
6398 config: Config{
6399 MaxVersion: VersionTLS13,
6400 ClientAuth: RequireAnyClientCert,
6401 VerifySignatureAlgorithms: []signatureAlgorithm{
6402 signatureRSAPSSWithSHA512,
6403 signatureRSAPSSWithSHA384,
6404 },
6405 },
6406 flags: []string{
6407 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6408 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6409 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6410 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006411 shouldFail: true,
6412 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006413 })
6414 testCases = append(testCases, testCase{
6415 name: "Agree-Digest-SHA256",
6416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006417 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006418 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006419 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006420 signatureRSAPKCS1WithSHA1,
6421 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006422 },
6423 },
6424 flags: []string{
6425 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6426 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006427 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006428 },
Nick Harper60edffd2016-06-21 15:19:24 -07006429 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006430 })
6431 testCases = append(testCases, testCase{
6432 name: "Agree-Digest-SHA1",
6433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006434 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006435 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006436 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006437 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006438 },
6439 },
6440 flags: []string{
6441 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6442 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006443 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006444 },
Nick Harper60edffd2016-06-21 15:19:24 -07006445 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006446 })
6447 testCases = append(testCases, testCase{
6448 name: "Agree-Digest-Default",
6449 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006450 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006451 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006452 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006453 signatureRSAPKCS1WithSHA256,
6454 signatureECDSAWithP256AndSHA256,
6455 signatureRSAPKCS1WithSHA1,
6456 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006457 },
6458 },
6459 flags: []string{
6460 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6461 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6462 },
Nick Harper60edffd2016-06-21 15:19:24 -07006463 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006464 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006465
David Benjaminca3d5452016-07-14 12:51:01 -04006466 // Test that the signing preference list may include extra algorithms
6467 // without negotiation problems.
6468 testCases = append(testCases, testCase{
6469 testType: serverTest,
6470 name: "FilterExtraAlgorithms",
6471 config: Config{
6472 MaxVersion: VersionTLS12,
6473 VerifySignatureAlgorithms: []signatureAlgorithm{
6474 signatureRSAPKCS1WithSHA256,
6475 },
6476 },
6477 flags: []string{
6478 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6479 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6480 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6481 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6482 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6483 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6484 },
6485 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6486 })
6487
David Benjamin4c3ddf72016-06-29 18:13:53 -04006488 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6489 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006490 testCases = append(testCases, testCase{
6491 name: "CheckLeafCurve",
6492 config: Config{
6493 MaxVersion: VersionTLS12,
6494 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006495 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006496 },
6497 flags: []string{"-p384-only"},
6498 shouldFail: true,
6499 expectedError: ":BAD_ECC_CERT:",
6500 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006501
6502 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6503 testCases = append(testCases, testCase{
6504 name: "CheckLeafCurve-TLS13",
6505 config: Config{
6506 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006507 Certificates: []Certificate{ecdsaP256Certificate},
6508 },
6509 flags: []string{"-p384-only"},
6510 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006511
6512 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6513 testCases = append(testCases, testCase{
6514 name: "ECDSACurveMismatch-Verify-TLS12",
6515 config: Config{
6516 MaxVersion: VersionTLS12,
6517 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6518 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006519 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006520 signatureECDSAWithP384AndSHA384,
6521 },
6522 },
6523 })
6524
6525 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6526 testCases = append(testCases, testCase{
6527 name: "ECDSACurveMismatch-Verify-TLS13",
6528 config: Config{
6529 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006530 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006531 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006532 signatureECDSAWithP384AndSHA384,
6533 },
6534 Bugs: ProtocolBugs{
6535 SkipECDSACurveCheck: true,
6536 },
6537 },
6538 shouldFail: true,
6539 expectedError: ":WRONG_SIGNATURE_TYPE:",
6540 })
6541
6542 // Signature algorithm selection in TLS 1.3 should take the curve into
6543 // account.
6544 testCases = append(testCases, testCase{
6545 testType: serverTest,
6546 name: "ECDSACurveMismatch-Sign-TLS13",
6547 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006548 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006549 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006550 signatureECDSAWithP384AndSHA384,
6551 signatureECDSAWithP256AndSHA256,
6552 },
6553 },
6554 flags: []string{
6555 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6556 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6557 },
6558 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6559 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006560
6561 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6562 // server does not attempt to sign in that case.
6563 testCases = append(testCases, testCase{
6564 testType: serverTest,
6565 name: "RSA-PSS-Large",
6566 config: Config{
6567 MaxVersion: VersionTLS13,
6568 VerifySignatureAlgorithms: []signatureAlgorithm{
6569 signatureRSAPSSWithSHA512,
6570 },
6571 },
6572 flags: []string{
6573 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6574 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6575 },
6576 shouldFail: true,
6577 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6578 })
David Benjamin57e929f2016-08-30 00:30:38 -04006579
6580 // Test that RSA-PSS is enabled by default for TLS 1.2.
6581 testCases = append(testCases, testCase{
6582 testType: clientTest,
6583 name: "RSA-PSS-Default-Verify",
6584 config: Config{
6585 MaxVersion: VersionTLS12,
6586 SignSignatureAlgorithms: []signatureAlgorithm{
6587 signatureRSAPSSWithSHA256,
6588 },
6589 },
6590 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6591 })
6592
6593 testCases = append(testCases, testCase{
6594 testType: serverTest,
6595 name: "RSA-PSS-Default-Sign",
6596 config: Config{
6597 MaxVersion: VersionTLS12,
6598 VerifySignatureAlgorithms: []signatureAlgorithm{
6599 signatureRSAPSSWithSHA256,
6600 },
6601 },
6602 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6603 })
David Benjamin000800a2014-11-14 01:43:59 -05006604}
6605
David Benjamin83f90402015-01-27 01:09:43 -05006606// timeouts is the retransmit schedule for BoringSSL. It doubles and
6607// caps at 60 seconds. On the 13th timeout, it gives up.
6608var timeouts = []time.Duration{
6609 1 * time.Second,
6610 2 * time.Second,
6611 4 * time.Second,
6612 8 * time.Second,
6613 16 * time.Second,
6614 32 * time.Second,
6615 60 * time.Second,
6616 60 * time.Second,
6617 60 * time.Second,
6618 60 * time.Second,
6619 60 * time.Second,
6620 60 * time.Second,
6621 60 * time.Second,
6622}
6623
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006624// shortTimeouts is an alternate set of timeouts which would occur if the
6625// initial timeout duration was set to 250ms.
6626var shortTimeouts = []time.Duration{
6627 250 * time.Millisecond,
6628 500 * time.Millisecond,
6629 1 * time.Second,
6630 2 * time.Second,
6631 4 * time.Second,
6632 8 * time.Second,
6633 16 * time.Second,
6634 32 * time.Second,
6635 60 * time.Second,
6636 60 * time.Second,
6637 60 * time.Second,
6638 60 * time.Second,
6639 60 * time.Second,
6640}
6641
David Benjamin83f90402015-01-27 01:09:43 -05006642func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006643 // These tests work by coordinating some behavior on both the shim and
6644 // the runner.
6645 //
6646 // TimeoutSchedule configures the runner to send a series of timeout
6647 // opcodes to the shim (see packetAdaptor) immediately before reading
6648 // each peer handshake flight N. The timeout opcode both simulates a
6649 // timeout in the shim and acts as a synchronization point to help the
6650 // runner bracket each handshake flight.
6651 //
6652 // We assume the shim does not read from the channel eagerly. It must
6653 // first wait until it has sent flight N and is ready to receive
6654 // handshake flight N+1. At this point, it will process the timeout
6655 // opcode. It must then immediately respond with a timeout ACK and act
6656 // as if the shim was idle for the specified amount of time.
6657 //
6658 // The runner then drops all packets received before the ACK and
6659 // continues waiting for flight N. This ordering results in one attempt
6660 // at sending flight N to be dropped. For the test to complete, the
6661 // shim must send flight N again, testing that the shim implements DTLS
6662 // retransmit on a timeout.
6663
Steven Valdez143e8b32016-07-11 13:19:03 -04006664 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006665 // likely be more epochs to cross and the final message's retransmit may
6666 // be more complex.
6667
David Benjamin585d7a42016-06-02 14:58:00 -04006668 for _, async := range []bool{true, false} {
6669 var tests []testCase
6670
6671 // Test that this is indeed the timeout schedule. Stress all
6672 // four patterns of handshake.
6673 for i := 1; i < len(timeouts); i++ {
6674 number := strconv.Itoa(i)
6675 tests = append(tests, testCase{
6676 protocol: dtls,
6677 name: "DTLS-Retransmit-Client-" + number,
6678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006679 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006680 Bugs: ProtocolBugs{
6681 TimeoutSchedule: timeouts[:i],
6682 },
6683 },
6684 resumeSession: true,
6685 })
6686 tests = append(tests, testCase{
6687 protocol: dtls,
6688 testType: serverTest,
6689 name: "DTLS-Retransmit-Server-" + number,
6690 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006691 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006692 Bugs: ProtocolBugs{
6693 TimeoutSchedule: timeouts[:i],
6694 },
6695 },
6696 resumeSession: true,
6697 })
6698 }
6699
6700 // Test that exceeding the timeout schedule hits a read
6701 // timeout.
6702 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006703 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006704 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006706 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006707 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006708 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006709 },
6710 },
6711 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006712 shouldFail: true,
6713 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006714 })
David Benjamin585d7a42016-06-02 14:58:00 -04006715
6716 if async {
6717 // Test that timeout handling has a fudge factor, due to API
6718 // problems.
6719 tests = append(tests, testCase{
6720 protocol: dtls,
6721 name: "DTLS-Retransmit-Fudge",
6722 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006723 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006724 Bugs: ProtocolBugs{
6725 TimeoutSchedule: []time.Duration{
6726 timeouts[0] - 10*time.Millisecond,
6727 },
6728 },
6729 },
6730 resumeSession: true,
6731 })
6732 }
6733
6734 // Test that the final Finished retransmitting isn't
6735 // duplicated if the peer badly fragments everything.
6736 tests = append(tests, testCase{
6737 testType: serverTest,
6738 protocol: dtls,
6739 name: "DTLS-Retransmit-Fragmented",
6740 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006741 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006742 Bugs: ProtocolBugs{
6743 TimeoutSchedule: []time.Duration{timeouts[0]},
6744 MaxHandshakeRecordLength: 2,
6745 },
6746 },
6747 })
6748
6749 // Test the timeout schedule when a shorter initial timeout duration is set.
6750 tests = append(tests, testCase{
6751 protocol: dtls,
6752 name: "DTLS-Retransmit-Short-Client",
6753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006754 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006755 Bugs: ProtocolBugs{
6756 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6757 },
6758 },
6759 resumeSession: true,
6760 flags: []string{"-initial-timeout-duration-ms", "250"},
6761 })
6762 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006763 protocol: dtls,
6764 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006765 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006766 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006767 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006768 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006769 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006770 },
6771 },
6772 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006773 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006774 })
David Benjamin585d7a42016-06-02 14:58:00 -04006775
6776 for _, test := range tests {
6777 if async {
6778 test.name += "-Async"
6779 test.flags = append(test.flags, "-async")
6780 }
6781
6782 testCases = append(testCases, test)
6783 }
David Benjamin83f90402015-01-27 01:09:43 -05006784 }
David Benjamin83f90402015-01-27 01:09:43 -05006785}
6786
David Benjaminc565ebb2015-04-03 04:06:36 -04006787func addExportKeyingMaterialTests() {
6788 for _, vers := range tlsVersions {
6789 if vers.version == VersionSSL30 {
6790 continue
6791 }
6792 testCases = append(testCases, testCase{
6793 name: "ExportKeyingMaterial-" + vers.name,
6794 config: Config{
6795 MaxVersion: vers.version,
6796 },
6797 exportKeyingMaterial: 1024,
6798 exportLabel: "label",
6799 exportContext: "context",
6800 useExportContext: true,
6801 })
6802 testCases = append(testCases, testCase{
6803 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6804 config: Config{
6805 MaxVersion: vers.version,
6806 },
6807 exportKeyingMaterial: 1024,
6808 })
6809 testCases = append(testCases, testCase{
6810 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6811 config: Config{
6812 MaxVersion: vers.version,
6813 },
6814 exportKeyingMaterial: 1024,
6815 useExportContext: true,
6816 })
6817 testCases = append(testCases, testCase{
6818 name: "ExportKeyingMaterial-Small-" + vers.name,
6819 config: Config{
6820 MaxVersion: vers.version,
6821 },
6822 exportKeyingMaterial: 1,
6823 exportLabel: "label",
6824 exportContext: "context",
6825 useExportContext: true,
6826 })
6827 }
6828 testCases = append(testCases, testCase{
6829 name: "ExportKeyingMaterial-SSL3",
6830 config: Config{
6831 MaxVersion: VersionSSL30,
6832 },
6833 exportKeyingMaterial: 1024,
6834 exportLabel: "label",
6835 exportContext: "context",
6836 useExportContext: true,
6837 shouldFail: true,
6838 expectedError: "failed to export keying material",
6839 })
6840}
6841
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006842func addTLSUniqueTests() {
6843 for _, isClient := range []bool{false, true} {
6844 for _, isResumption := range []bool{false, true} {
6845 for _, hasEMS := range []bool{false, true} {
6846 var suffix string
6847 if isResumption {
6848 suffix = "Resume-"
6849 } else {
6850 suffix = "Full-"
6851 }
6852
6853 if hasEMS {
6854 suffix += "EMS-"
6855 } else {
6856 suffix += "NoEMS-"
6857 }
6858
6859 if isClient {
6860 suffix += "Client"
6861 } else {
6862 suffix += "Server"
6863 }
6864
6865 test := testCase{
6866 name: "TLSUnique-" + suffix,
6867 testTLSUnique: true,
6868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006869 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006870 Bugs: ProtocolBugs{
6871 NoExtendedMasterSecret: !hasEMS,
6872 },
6873 },
6874 }
6875
6876 if isResumption {
6877 test.resumeSession = true
6878 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006879 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006880 Bugs: ProtocolBugs{
6881 NoExtendedMasterSecret: !hasEMS,
6882 },
6883 }
6884 }
6885
6886 if isResumption && !hasEMS {
6887 test.shouldFail = true
6888 test.expectedError = "failed to get tls-unique"
6889 }
6890
6891 testCases = append(testCases, test)
6892 }
6893 }
6894 }
6895}
6896
Adam Langley09505632015-07-30 18:10:13 -07006897func addCustomExtensionTests() {
6898 expectedContents := "custom extension"
6899 emptyString := ""
6900
6901 for _, isClient := range []bool{false, true} {
6902 suffix := "Server"
6903 flag := "-enable-server-custom-extension"
6904 testType := serverTest
6905 if isClient {
6906 suffix = "Client"
6907 flag = "-enable-client-custom-extension"
6908 testType = clientTest
6909 }
6910
6911 testCases = append(testCases, testCase{
6912 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006913 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006915 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006916 Bugs: ProtocolBugs{
6917 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006918 ExpectedCustomExtension: &expectedContents,
6919 },
6920 },
6921 flags: []string{flag},
6922 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006923 testCases = append(testCases, testCase{
6924 testType: testType,
6925 name: "CustomExtensions-" + suffix + "-TLS13",
6926 config: Config{
6927 MaxVersion: VersionTLS13,
6928 Bugs: ProtocolBugs{
6929 CustomExtension: expectedContents,
6930 ExpectedCustomExtension: &expectedContents,
6931 },
6932 },
6933 flags: []string{flag},
6934 })
Adam Langley09505632015-07-30 18:10:13 -07006935
6936 // If the parse callback fails, the handshake should also fail.
6937 testCases = append(testCases, testCase{
6938 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006939 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006940 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006941 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006942 Bugs: ProtocolBugs{
6943 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006944 ExpectedCustomExtension: &expectedContents,
6945 },
6946 },
David Benjamin399e7c92015-07-30 23:01:27 -04006947 flags: []string{flag},
6948 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006949 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6950 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006951 testCases = append(testCases, testCase{
6952 testType: testType,
6953 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6954 config: Config{
6955 MaxVersion: VersionTLS13,
6956 Bugs: ProtocolBugs{
6957 CustomExtension: expectedContents + "foo",
6958 ExpectedCustomExtension: &expectedContents,
6959 },
6960 },
6961 flags: []string{flag},
6962 shouldFail: true,
6963 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6964 })
Adam Langley09505632015-07-30 18:10:13 -07006965
6966 // If the add callback fails, the handshake should also fail.
6967 testCases = append(testCases, testCase{
6968 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006969 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006971 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006972 Bugs: ProtocolBugs{
6973 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006974 ExpectedCustomExtension: &expectedContents,
6975 },
6976 },
David Benjamin399e7c92015-07-30 23:01:27 -04006977 flags: []string{flag, "-custom-extension-fail-add"},
6978 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006979 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6980 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006981 testCases = append(testCases, testCase{
6982 testType: testType,
6983 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6984 config: Config{
6985 MaxVersion: VersionTLS13,
6986 Bugs: ProtocolBugs{
6987 CustomExtension: expectedContents,
6988 ExpectedCustomExtension: &expectedContents,
6989 },
6990 },
6991 flags: []string{flag, "-custom-extension-fail-add"},
6992 shouldFail: true,
6993 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6994 })
Adam Langley09505632015-07-30 18:10:13 -07006995
6996 // If the add callback returns zero, no extension should be
6997 // added.
6998 skipCustomExtension := expectedContents
6999 if isClient {
7000 // For the case where the client skips sending the
7001 // custom extension, the server must not “echo” it.
7002 skipCustomExtension = ""
7003 }
7004 testCases = append(testCases, testCase{
7005 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007006 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007007 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007008 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007009 Bugs: ProtocolBugs{
7010 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007011 ExpectedCustomExtension: &emptyString,
7012 },
7013 },
7014 flags: []string{flag, "-custom-extension-skip"},
7015 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007016 testCases = append(testCases, testCase{
7017 testType: testType,
7018 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7019 config: Config{
7020 MaxVersion: VersionTLS13,
7021 Bugs: ProtocolBugs{
7022 CustomExtension: skipCustomExtension,
7023 ExpectedCustomExtension: &emptyString,
7024 },
7025 },
7026 flags: []string{flag, "-custom-extension-skip"},
7027 })
Adam Langley09505632015-07-30 18:10:13 -07007028 }
7029
7030 // The custom extension add callback should not be called if the client
7031 // doesn't send the extension.
7032 testCases = append(testCases, testCase{
7033 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007034 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007035 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007036 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007037 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007038 ExpectedCustomExtension: &emptyString,
7039 },
7040 },
7041 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7042 })
Adam Langley2deb9842015-08-07 11:15:37 -07007043
Steven Valdez143e8b32016-07-11 13:19:03 -04007044 testCases = append(testCases, testCase{
7045 testType: serverTest,
7046 name: "CustomExtensions-NotCalled-Server-TLS13",
7047 config: Config{
7048 MaxVersion: VersionTLS13,
7049 Bugs: ProtocolBugs{
7050 ExpectedCustomExtension: &emptyString,
7051 },
7052 },
7053 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7054 })
7055
Adam Langley2deb9842015-08-07 11:15:37 -07007056 // Test an unknown extension from the server.
7057 testCases = append(testCases, testCase{
7058 testType: clientTest,
7059 name: "UnknownExtension-Client",
7060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007061 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007062 Bugs: ProtocolBugs{
7063 CustomExtension: expectedContents,
7064 },
7065 },
David Benjamin0c40a962016-08-01 12:05:50 -04007066 shouldFail: true,
7067 expectedError: ":UNEXPECTED_EXTENSION:",
7068 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007069 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007070 testCases = append(testCases, testCase{
7071 testType: clientTest,
7072 name: "UnknownExtension-Client-TLS13",
7073 config: Config{
7074 MaxVersion: VersionTLS13,
7075 Bugs: ProtocolBugs{
7076 CustomExtension: expectedContents,
7077 },
7078 },
David Benjamin0c40a962016-08-01 12:05:50 -04007079 shouldFail: true,
7080 expectedError: ":UNEXPECTED_EXTENSION:",
7081 expectedLocalError: "remote error: unsupported extension",
7082 })
7083
7084 // Test a known but unoffered extension from the server.
7085 testCases = append(testCases, testCase{
7086 testType: clientTest,
7087 name: "UnofferedExtension-Client",
7088 config: Config{
7089 MaxVersion: VersionTLS12,
7090 Bugs: ProtocolBugs{
7091 SendALPN: "alpn",
7092 },
7093 },
7094 shouldFail: true,
7095 expectedError: ":UNEXPECTED_EXTENSION:",
7096 expectedLocalError: "remote error: unsupported extension",
7097 })
7098 testCases = append(testCases, testCase{
7099 testType: clientTest,
7100 name: "UnofferedExtension-Client-TLS13",
7101 config: Config{
7102 MaxVersion: VersionTLS13,
7103 Bugs: ProtocolBugs{
7104 SendALPN: "alpn",
7105 },
7106 },
7107 shouldFail: true,
7108 expectedError: ":UNEXPECTED_EXTENSION:",
7109 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007110 })
Adam Langley09505632015-07-30 18:10:13 -07007111}
7112
David Benjaminb36a3952015-12-01 18:53:13 -05007113func addRSAClientKeyExchangeTests() {
7114 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7115 testCases = append(testCases, testCase{
7116 testType: serverTest,
7117 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7118 config: Config{
7119 // Ensure the ClientHello version and final
7120 // version are different, to detect if the
7121 // server uses the wrong one.
7122 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007123 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007124 Bugs: ProtocolBugs{
7125 BadRSAClientKeyExchange: bad,
7126 },
7127 },
7128 shouldFail: true,
7129 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7130 })
7131 }
David Benjamine63d9d72016-09-19 18:27:34 -04007132
7133 // The server must compare whatever was in ClientHello.version for the
7134 // RSA premaster.
7135 testCases = append(testCases, testCase{
7136 testType: serverTest,
7137 name: "SendClientVersion-RSA",
7138 config: Config{
7139 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7140 Bugs: ProtocolBugs{
7141 SendClientVersion: 0x1234,
7142 },
7143 },
7144 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7145 })
David Benjaminb36a3952015-12-01 18:53:13 -05007146}
7147
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007148var testCurves = []struct {
7149 name string
7150 id CurveID
7151}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007152 {"P-256", CurveP256},
7153 {"P-384", CurveP384},
7154 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007155 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007156}
7157
Steven Valdez5440fe02016-07-18 12:40:30 -04007158const bogusCurve = 0x1234
7159
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007160func addCurveTests() {
7161 for _, curve := range testCurves {
7162 testCases = append(testCases, testCase{
7163 name: "CurveTest-Client-" + curve.name,
7164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007165 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7167 CurvePreferences: []CurveID{curve.id},
7168 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007169 flags: []string{
7170 "-enable-all-curves",
7171 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7172 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007173 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007174 })
7175 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007176 name: "CurveTest-Client-" + curve.name + "-TLS13",
7177 config: Config{
7178 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007179 CurvePreferences: []CurveID{curve.id},
7180 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007181 flags: []string{
7182 "-enable-all-curves",
7183 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7184 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007185 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007186 })
7187 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007188 testType: serverTest,
7189 name: "CurveTest-Server-" + curve.name,
7190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007191 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007192 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7193 CurvePreferences: []CurveID{curve.id},
7194 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007195 flags: []string{
7196 "-enable-all-curves",
7197 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7198 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007199 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007200 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007201 testCases = append(testCases, testCase{
7202 testType: serverTest,
7203 name: "CurveTest-Server-" + curve.name + "-TLS13",
7204 config: Config{
7205 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007206 CurvePreferences: []CurveID{curve.id},
7207 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007208 flags: []string{
7209 "-enable-all-curves",
7210 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7211 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007212 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007213 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007214 }
David Benjamin241ae832016-01-15 03:04:54 -05007215
7216 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007217 testCases = append(testCases, testCase{
7218 testType: serverTest,
7219 name: "UnknownCurve",
7220 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007221 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007222 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7223 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7224 },
7225 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007226
Steven Valdez803c77a2016-09-06 14:13:43 -04007227 // The server must be tolerant to bogus curves.
7228 testCases = append(testCases, testCase{
7229 testType: serverTest,
7230 name: "UnknownCurve-TLS13",
7231 config: Config{
7232 MaxVersion: VersionTLS13,
7233 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7234 },
7235 })
7236
David Benjamin4c3ddf72016-06-29 18:13:53 -04007237 // The server must not consider ECDHE ciphers when there are no
7238 // supported curves.
7239 testCases = append(testCases, testCase{
7240 testType: serverTest,
7241 name: "NoSupportedCurves",
7242 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007243 MaxVersion: VersionTLS12,
7244 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7245 Bugs: ProtocolBugs{
7246 NoSupportedCurves: true,
7247 },
7248 },
7249 shouldFail: true,
7250 expectedError: ":NO_SHARED_CIPHER:",
7251 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007252 testCases = append(testCases, testCase{
7253 testType: serverTest,
7254 name: "NoSupportedCurves-TLS13",
7255 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007256 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007257 Bugs: ProtocolBugs{
7258 NoSupportedCurves: true,
7259 },
7260 },
7261 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007262 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007263 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007264
7265 // The server must fall back to another cipher when there are no
7266 // supported curves.
7267 testCases = append(testCases, testCase{
7268 testType: serverTest,
7269 name: "NoCommonCurves",
7270 config: Config{
7271 MaxVersion: VersionTLS12,
7272 CipherSuites: []uint16{
7273 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7274 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7275 },
7276 CurvePreferences: []CurveID{CurveP224},
7277 },
7278 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7279 })
7280
7281 // The client must reject bogus curves and disabled curves.
7282 testCases = append(testCases, testCase{
7283 name: "BadECDHECurve",
7284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007285 MaxVersion: VersionTLS12,
7286 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7287 Bugs: ProtocolBugs{
7288 SendCurve: bogusCurve,
7289 },
7290 },
7291 shouldFail: true,
7292 expectedError: ":WRONG_CURVE:",
7293 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007294 testCases = append(testCases, testCase{
7295 name: "BadECDHECurve-TLS13",
7296 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007297 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007298 Bugs: ProtocolBugs{
7299 SendCurve: bogusCurve,
7300 },
7301 },
7302 shouldFail: true,
7303 expectedError: ":WRONG_CURVE:",
7304 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007305
7306 testCases = append(testCases, testCase{
7307 name: "UnsupportedCurve",
7308 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007309 MaxVersion: VersionTLS12,
7310 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7311 CurvePreferences: []CurveID{CurveP256},
7312 Bugs: ProtocolBugs{
7313 IgnorePeerCurvePreferences: true,
7314 },
7315 },
7316 flags: []string{"-p384-only"},
7317 shouldFail: true,
7318 expectedError: ":WRONG_CURVE:",
7319 })
7320
David Benjamin4f921572016-07-17 14:20:10 +02007321 testCases = append(testCases, testCase{
7322 // TODO(davidben): Add a TLS 1.3 version where
7323 // HelloRetryRequest requests an unsupported curve.
7324 name: "UnsupportedCurve-ServerHello-TLS13",
7325 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007326 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007327 CurvePreferences: []CurveID{CurveP384},
7328 Bugs: ProtocolBugs{
7329 SendCurve: CurveP256,
7330 },
7331 },
7332 flags: []string{"-p384-only"},
7333 shouldFail: true,
7334 expectedError: ":WRONG_CURVE:",
7335 })
7336
David Benjamin4c3ddf72016-06-29 18:13:53 -04007337 // Test invalid curve points.
7338 testCases = append(testCases, testCase{
7339 name: "InvalidECDHPoint-Client",
7340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007341 MaxVersion: VersionTLS12,
7342 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7343 CurvePreferences: []CurveID{CurveP256},
7344 Bugs: ProtocolBugs{
7345 InvalidECDHPoint: true,
7346 },
7347 },
7348 shouldFail: true,
7349 expectedError: ":INVALID_ENCODING:",
7350 })
7351 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007352 name: "InvalidECDHPoint-Client-TLS13",
7353 config: Config{
7354 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007355 CurvePreferences: []CurveID{CurveP256},
7356 Bugs: ProtocolBugs{
7357 InvalidECDHPoint: true,
7358 },
7359 },
7360 shouldFail: true,
7361 expectedError: ":INVALID_ENCODING:",
7362 })
7363 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007364 testType: serverTest,
7365 name: "InvalidECDHPoint-Server",
7366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007367 MaxVersion: VersionTLS12,
7368 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7369 CurvePreferences: []CurveID{CurveP256},
7370 Bugs: ProtocolBugs{
7371 InvalidECDHPoint: true,
7372 },
7373 },
7374 shouldFail: true,
7375 expectedError: ":INVALID_ENCODING:",
7376 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007377 testCases = append(testCases, testCase{
7378 testType: serverTest,
7379 name: "InvalidECDHPoint-Server-TLS13",
7380 config: Config{
7381 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007382 CurvePreferences: []CurveID{CurveP256},
7383 Bugs: ProtocolBugs{
7384 InvalidECDHPoint: true,
7385 },
7386 },
7387 shouldFail: true,
7388 expectedError: ":INVALID_ENCODING:",
7389 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007390}
7391
Matt Braithwaite54217e42016-06-13 13:03:47 -07007392func addCECPQ1Tests() {
7393 testCases = append(testCases, testCase{
7394 testType: clientTest,
7395 name: "CECPQ1-Client-BadX25519Part",
7396 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007397 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007398 MinVersion: VersionTLS12,
7399 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7400 Bugs: ProtocolBugs{
7401 CECPQ1BadX25519Part: true,
7402 },
7403 },
7404 flags: []string{"-cipher", "kCECPQ1"},
7405 shouldFail: true,
7406 expectedLocalError: "local error: bad record MAC",
7407 })
7408 testCases = append(testCases, testCase{
7409 testType: clientTest,
7410 name: "CECPQ1-Client-BadNewhopePart",
7411 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007412 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007413 MinVersion: VersionTLS12,
7414 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7415 Bugs: ProtocolBugs{
7416 CECPQ1BadNewhopePart: true,
7417 },
7418 },
7419 flags: []string{"-cipher", "kCECPQ1"},
7420 shouldFail: true,
7421 expectedLocalError: "local error: bad record MAC",
7422 })
7423 testCases = append(testCases, testCase{
7424 testType: serverTest,
7425 name: "CECPQ1-Server-BadX25519Part",
7426 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007427 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007428 MinVersion: VersionTLS12,
7429 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7430 Bugs: ProtocolBugs{
7431 CECPQ1BadX25519Part: true,
7432 },
7433 },
7434 flags: []string{"-cipher", "kCECPQ1"},
7435 shouldFail: true,
7436 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7437 })
7438 testCases = append(testCases, testCase{
7439 testType: serverTest,
7440 name: "CECPQ1-Server-BadNewhopePart",
7441 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007442 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007443 MinVersion: VersionTLS12,
7444 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7445 Bugs: ProtocolBugs{
7446 CECPQ1BadNewhopePart: true,
7447 },
7448 },
7449 flags: []string{"-cipher", "kCECPQ1"},
7450 shouldFail: true,
7451 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7452 })
7453}
7454
David Benjamin5c4e8572016-08-19 17:44:53 -04007455func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007456 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007457 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007458 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007459 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007460 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7461 Bugs: ProtocolBugs{
7462 // This is a 1234-bit prime number, generated
7463 // with:
7464 // openssl gendh 1234 | openssl asn1parse -i
7465 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7466 },
7467 },
David Benjamin9e68f192016-06-30 14:55:33 -04007468 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007469 })
7470 testCases = append(testCases, testCase{
7471 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007472 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007473 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007474 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007475 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7476 },
7477 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007478 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007479 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007480}
7481
David Benjaminc9ae27c2016-06-24 22:56:37 -04007482func addTLS13RecordTests() {
7483 testCases = append(testCases, testCase{
7484 name: "TLS13-RecordPadding",
7485 config: Config{
7486 MaxVersion: VersionTLS13,
7487 MinVersion: VersionTLS13,
7488 Bugs: ProtocolBugs{
7489 RecordPadding: 10,
7490 },
7491 },
7492 })
7493
7494 testCases = append(testCases, testCase{
7495 name: "TLS13-EmptyRecords",
7496 config: Config{
7497 MaxVersion: VersionTLS13,
7498 MinVersion: VersionTLS13,
7499 Bugs: ProtocolBugs{
7500 OmitRecordContents: true,
7501 },
7502 },
7503 shouldFail: true,
7504 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7505 })
7506
7507 testCases = append(testCases, testCase{
7508 name: "TLS13-OnlyPadding",
7509 config: Config{
7510 MaxVersion: VersionTLS13,
7511 MinVersion: VersionTLS13,
7512 Bugs: ProtocolBugs{
7513 OmitRecordContents: true,
7514 RecordPadding: 10,
7515 },
7516 },
7517 shouldFail: true,
7518 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7519 })
7520
7521 testCases = append(testCases, testCase{
7522 name: "TLS13-WrongOuterRecord",
7523 config: Config{
7524 MaxVersion: VersionTLS13,
7525 MinVersion: VersionTLS13,
7526 Bugs: ProtocolBugs{
7527 OuterRecordType: recordTypeHandshake,
7528 },
7529 },
7530 shouldFail: true,
7531 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7532 })
7533}
7534
Steven Valdez5b986082016-09-01 12:29:49 -04007535func addSessionTicketTests() {
7536 testCases = append(testCases, testCase{
7537 // In TLS 1.2 and below, empty NewSessionTicket messages
7538 // mean the server changed its mind on sending a ticket.
7539 name: "SendEmptySessionTicket",
7540 config: Config{
7541 MaxVersion: VersionTLS12,
7542 Bugs: ProtocolBugs{
7543 SendEmptySessionTicket: true,
7544 },
7545 },
7546 flags: []string{"-expect-no-session"},
7547 })
7548
7549 // Test that the server ignores unknown PSK modes.
7550 testCases = append(testCases, testCase{
7551 testType: serverTest,
7552 name: "TLS13-SendUnknownModeSessionTicket-Server",
7553 config: Config{
7554 MaxVersion: VersionTLS13,
7555 Bugs: ProtocolBugs{
7556 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7557 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7558 },
7559 },
7560 resumeSession: true,
7561 expectedResumeVersion: VersionTLS13,
7562 })
7563
7564 // Test that the server declines sessions with no matching key exchange mode.
7565 testCases = append(testCases, testCase{
7566 testType: serverTest,
7567 name: "TLS13-SendBadKEModeSessionTicket-Server",
7568 config: Config{
7569 MaxVersion: VersionTLS13,
7570 Bugs: ProtocolBugs{
7571 SendPSKKeyExchangeModes: []byte{0x1a},
7572 },
7573 },
7574 resumeSession: true,
7575 expectResumeRejected: true,
7576 })
7577
7578 // Test that the server declines sessions with no matching auth mode.
7579 testCases = append(testCases, testCase{
7580 testType: serverTest,
7581 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7582 config: Config{
7583 MaxVersion: VersionTLS13,
7584 Bugs: ProtocolBugs{
7585 SendPSKAuthModes: []byte{0x1a},
7586 },
7587 },
7588 resumeSession: true,
7589 expectResumeRejected: true,
7590 })
7591
7592 // Test that the client ignores unknown PSK modes.
7593 testCases = append(testCases, testCase{
7594 testType: clientTest,
7595 name: "TLS13-SendUnknownModeSessionTicket-Client",
7596 config: Config{
7597 MaxVersion: VersionTLS13,
7598 Bugs: ProtocolBugs{
7599 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7600 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7601 },
7602 },
7603 resumeSession: true,
7604 expectedResumeVersion: VersionTLS13,
7605 })
7606
7607 // Test that the client ignores tickets with no matching key exchange mode.
7608 testCases = append(testCases, testCase{
7609 testType: clientTest,
7610 name: "TLS13-SendBadKEModeSessionTicket-Client",
7611 config: Config{
7612 MaxVersion: VersionTLS13,
7613 Bugs: ProtocolBugs{
7614 SendPSKKeyExchangeModes: []byte{0x1a},
7615 },
7616 },
7617 flags: []string{"-expect-no-session"},
7618 })
7619
7620 // Test that the client ignores tickets with no matching auth mode.
7621 testCases = append(testCases, testCase{
7622 testType: clientTest,
7623 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7624 config: Config{
7625 MaxVersion: VersionTLS13,
7626 Bugs: ProtocolBugs{
7627 SendPSKAuthModes: []byte{0x1a},
7628 },
7629 },
7630 flags: []string{"-expect-no-session"},
7631 })
7632}
7633
David Benjamin82261be2016-07-07 14:32:50 -07007634func addChangeCipherSpecTests() {
7635 // Test missing ChangeCipherSpecs.
7636 testCases = append(testCases, testCase{
7637 name: "SkipChangeCipherSpec-Client",
7638 config: Config{
7639 MaxVersion: VersionTLS12,
7640 Bugs: ProtocolBugs{
7641 SkipChangeCipherSpec: true,
7642 },
7643 },
7644 shouldFail: true,
7645 expectedError: ":UNEXPECTED_RECORD:",
7646 })
7647 testCases = append(testCases, testCase{
7648 testType: serverTest,
7649 name: "SkipChangeCipherSpec-Server",
7650 config: Config{
7651 MaxVersion: VersionTLS12,
7652 Bugs: ProtocolBugs{
7653 SkipChangeCipherSpec: true,
7654 },
7655 },
7656 shouldFail: true,
7657 expectedError: ":UNEXPECTED_RECORD:",
7658 })
7659 testCases = append(testCases, testCase{
7660 testType: serverTest,
7661 name: "SkipChangeCipherSpec-Server-NPN",
7662 config: Config{
7663 MaxVersion: VersionTLS12,
7664 NextProtos: []string{"bar"},
7665 Bugs: ProtocolBugs{
7666 SkipChangeCipherSpec: true,
7667 },
7668 },
7669 flags: []string{
7670 "-advertise-npn", "\x03foo\x03bar\x03baz",
7671 },
7672 shouldFail: true,
7673 expectedError: ":UNEXPECTED_RECORD:",
7674 })
7675
7676 // Test synchronization between the handshake and ChangeCipherSpec.
7677 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7678 // rejected. Test both with and without handshake packing to handle both
7679 // when the partial post-CCS message is in its own record and when it is
7680 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007681 for _, packed := range []bool{false, true} {
7682 var suffix string
7683 if packed {
7684 suffix = "-Packed"
7685 }
7686
7687 testCases = append(testCases, testCase{
7688 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7689 config: Config{
7690 MaxVersion: VersionTLS12,
7691 Bugs: ProtocolBugs{
7692 FragmentAcrossChangeCipherSpec: true,
7693 PackHandshakeFlight: packed,
7694 },
7695 },
7696 shouldFail: true,
7697 expectedError: ":UNEXPECTED_RECORD:",
7698 })
7699 testCases = append(testCases, testCase{
7700 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7701 config: Config{
7702 MaxVersion: VersionTLS12,
7703 },
7704 resumeSession: true,
7705 resumeConfig: &Config{
7706 MaxVersion: VersionTLS12,
7707 Bugs: ProtocolBugs{
7708 FragmentAcrossChangeCipherSpec: true,
7709 PackHandshakeFlight: packed,
7710 },
7711 },
7712 shouldFail: true,
7713 expectedError: ":UNEXPECTED_RECORD:",
7714 })
7715 testCases = append(testCases, testCase{
7716 testType: serverTest,
7717 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7718 config: Config{
7719 MaxVersion: VersionTLS12,
7720 Bugs: ProtocolBugs{
7721 FragmentAcrossChangeCipherSpec: true,
7722 PackHandshakeFlight: packed,
7723 },
7724 },
7725 shouldFail: true,
7726 expectedError: ":UNEXPECTED_RECORD:",
7727 })
7728 testCases = append(testCases, testCase{
7729 testType: serverTest,
7730 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7731 config: Config{
7732 MaxVersion: VersionTLS12,
7733 },
7734 resumeSession: true,
7735 resumeConfig: &Config{
7736 MaxVersion: VersionTLS12,
7737 Bugs: ProtocolBugs{
7738 FragmentAcrossChangeCipherSpec: true,
7739 PackHandshakeFlight: packed,
7740 },
7741 },
7742 shouldFail: true,
7743 expectedError: ":UNEXPECTED_RECORD:",
7744 })
7745 testCases = append(testCases, testCase{
7746 testType: serverTest,
7747 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7748 config: Config{
7749 MaxVersion: VersionTLS12,
7750 NextProtos: []string{"bar"},
7751 Bugs: ProtocolBugs{
7752 FragmentAcrossChangeCipherSpec: true,
7753 PackHandshakeFlight: packed,
7754 },
7755 },
7756 flags: []string{
7757 "-advertise-npn", "\x03foo\x03bar\x03baz",
7758 },
7759 shouldFail: true,
7760 expectedError: ":UNEXPECTED_RECORD:",
7761 })
7762 }
7763
David Benjamin61672812016-07-14 23:10:43 -04007764 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7765 // messages in the handshake queue. Do this by testing the server
7766 // reading the client Finished, reversing the flight so Finished comes
7767 // first.
7768 testCases = append(testCases, testCase{
7769 protocol: dtls,
7770 testType: serverTest,
7771 name: "SendUnencryptedFinished-DTLS",
7772 config: Config{
7773 MaxVersion: VersionTLS12,
7774 Bugs: ProtocolBugs{
7775 SendUnencryptedFinished: true,
7776 ReverseHandshakeFragments: true,
7777 },
7778 },
7779 shouldFail: true,
7780 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7781 })
7782
Steven Valdez143e8b32016-07-11 13:19:03 -04007783 // Test synchronization between encryption changes and the handshake in
7784 // TLS 1.3, where ChangeCipherSpec is implicit.
7785 testCases = append(testCases, testCase{
7786 name: "PartialEncryptedExtensionsWithServerHello",
7787 config: Config{
7788 MaxVersion: VersionTLS13,
7789 Bugs: ProtocolBugs{
7790 PartialEncryptedExtensionsWithServerHello: true,
7791 },
7792 },
7793 shouldFail: true,
7794 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7795 })
7796 testCases = append(testCases, testCase{
7797 testType: serverTest,
7798 name: "PartialClientFinishedWithClientHello",
7799 config: Config{
7800 MaxVersion: VersionTLS13,
7801 Bugs: ProtocolBugs{
7802 PartialClientFinishedWithClientHello: true,
7803 },
7804 },
7805 shouldFail: true,
7806 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7807 })
7808
David Benjamin82261be2016-07-07 14:32:50 -07007809 // Test that early ChangeCipherSpecs are handled correctly.
7810 testCases = append(testCases, testCase{
7811 testType: serverTest,
7812 name: "EarlyChangeCipherSpec-server-1",
7813 config: Config{
7814 MaxVersion: VersionTLS12,
7815 Bugs: ProtocolBugs{
7816 EarlyChangeCipherSpec: 1,
7817 },
7818 },
7819 shouldFail: true,
7820 expectedError: ":UNEXPECTED_RECORD:",
7821 })
7822 testCases = append(testCases, testCase{
7823 testType: serverTest,
7824 name: "EarlyChangeCipherSpec-server-2",
7825 config: Config{
7826 MaxVersion: VersionTLS12,
7827 Bugs: ProtocolBugs{
7828 EarlyChangeCipherSpec: 2,
7829 },
7830 },
7831 shouldFail: true,
7832 expectedError: ":UNEXPECTED_RECORD:",
7833 })
7834 testCases = append(testCases, testCase{
7835 protocol: dtls,
7836 name: "StrayChangeCipherSpec",
7837 config: Config{
7838 // TODO(davidben): Once DTLS 1.3 exists, test
7839 // that stray ChangeCipherSpec messages are
7840 // rejected.
7841 MaxVersion: VersionTLS12,
7842 Bugs: ProtocolBugs{
7843 StrayChangeCipherSpec: true,
7844 },
7845 },
7846 })
7847
7848 // Test that the contents of ChangeCipherSpec are checked.
7849 testCases = append(testCases, testCase{
7850 name: "BadChangeCipherSpec-1",
7851 config: Config{
7852 MaxVersion: VersionTLS12,
7853 Bugs: ProtocolBugs{
7854 BadChangeCipherSpec: []byte{2},
7855 },
7856 },
7857 shouldFail: true,
7858 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7859 })
7860 testCases = append(testCases, testCase{
7861 name: "BadChangeCipherSpec-2",
7862 config: Config{
7863 MaxVersion: VersionTLS12,
7864 Bugs: ProtocolBugs{
7865 BadChangeCipherSpec: []byte{1, 1},
7866 },
7867 },
7868 shouldFail: true,
7869 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7870 })
7871 testCases = append(testCases, testCase{
7872 protocol: dtls,
7873 name: "BadChangeCipherSpec-DTLS-1",
7874 config: Config{
7875 MaxVersion: VersionTLS12,
7876 Bugs: ProtocolBugs{
7877 BadChangeCipherSpec: []byte{2},
7878 },
7879 },
7880 shouldFail: true,
7881 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7882 })
7883 testCases = append(testCases, testCase{
7884 protocol: dtls,
7885 name: "BadChangeCipherSpec-DTLS-2",
7886 config: Config{
7887 MaxVersion: VersionTLS12,
7888 Bugs: ProtocolBugs{
7889 BadChangeCipherSpec: []byte{1, 1},
7890 },
7891 },
7892 shouldFail: true,
7893 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7894 })
7895}
7896
David Benjamincd2c8062016-09-09 11:28:16 -04007897type perMessageTest struct {
7898 messageType uint8
7899 test testCase
7900}
7901
7902// makePerMessageTests returns a series of test templates which cover each
7903// message in the TLS handshake. These may be used with bugs like
7904// WrongMessageType to fully test a per-message bug.
7905func makePerMessageTests() []perMessageTest {
7906 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007907 for _, protocol := range []protocol{tls, dtls} {
7908 var suffix string
7909 if protocol == dtls {
7910 suffix = "-DTLS"
7911 }
7912
David Benjamincd2c8062016-09-09 11:28:16 -04007913 ret = append(ret, perMessageTest{
7914 messageType: typeClientHello,
7915 test: testCase{
7916 protocol: protocol,
7917 testType: serverTest,
7918 name: "ClientHello" + suffix,
7919 config: Config{
7920 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007921 },
7922 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007923 })
7924
7925 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007926 ret = append(ret, perMessageTest{
7927 messageType: typeHelloVerifyRequest,
7928 test: testCase{
7929 protocol: protocol,
7930 name: "HelloVerifyRequest" + suffix,
7931 config: Config{
7932 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007933 },
7934 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007935 })
7936 }
7937
David Benjamincd2c8062016-09-09 11:28:16 -04007938 ret = append(ret, perMessageTest{
7939 messageType: typeServerHello,
7940 test: testCase{
7941 protocol: protocol,
7942 name: "ServerHello" + suffix,
7943 config: Config{
7944 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007945 },
7946 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007947 })
7948
David Benjamincd2c8062016-09-09 11:28:16 -04007949 ret = append(ret, perMessageTest{
7950 messageType: typeCertificate,
7951 test: testCase{
7952 protocol: protocol,
7953 name: "ServerCertificate" + suffix,
7954 config: Config{
7955 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007956 },
7957 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007958 })
7959
David Benjamincd2c8062016-09-09 11:28:16 -04007960 ret = append(ret, perMessageTest{
7961 messageType: typeCertificateStatus,
7962 test: testCase{
7963 protocol: protocol,
7964 name: "CertificateStatus" + suffix,
7965 config: Config{
7966 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007967 },
David Benjamincd2c8062016-09-09 11:28:16 -04007968 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007969 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007970 })
7971
David Benjamincd2c8062016-09-09 11:28:16 -04007972 ret = append(ret, perMessageTest{
7973 messageType: typeServerKeyExchange,
7974 test: testCase{
7975 protocol: protocol,
7976 name: "ServerKeyExchange" + suffix,
7977 config: Config{
7978 MaxVersion: VersionTLS12,
7979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007980 },
7981 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007982 })
7983
David Benjamincd2c8062016-09-09 11:28:16 -04007984 ret = append(ret, perMessageTest{
7985 messageType: typeCertificateRequest,
7986 test: testCase{
7987 protocol: protocol,
7988 name: "CertificateRequest" + suffix,
7989 config: Config{
7990 MaxVersion: VersionTLS12,
7991 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007992 },
7993 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007994 })
7995
David Benjamincd2c8062016-09-09 11:28:16 -04007996 ret = append(ret, perMessageTest{
7997 messageType: typeServerHelloDone,
7998 test: testCase{
7999 protocol: protocol,
8000 name: "ServerHelloDone" + suffix,
8001 config: Config{
8002 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008003 },
8004 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008005 })
8006
David Benjamincd2c8062016-09-09 11:28:16 -04008007 ret = append(ret, perMessageTest{
8008 messageType: typeCertificate,
8009 test: testCase{
8010 testType: serverTest,
8011 protocol: protocol,
8012 name: "ClientCertificate" + suffix,
8013 config: Config{
8014 Certificates: []Certificate{rsaCertificate},
8015 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008016 },
David Benjamincd2c8062016-09-09 11:28:16 -04008017 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008018 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008019 })
8020
David Benjamincd2c8062016-09-09 11:28:16 -04008021 ret = append(ret, perMessageTest{
8022 messageType: typeCertificateVerify,
8023 test: testCase{
8024 testType: serverTest,
8025 protocol: protocol,
8026 name: "CertificateVerify" + suffix,
8027 config: Config{
8028 Certificates: []Certificate{rsaCertificate},
8029 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008030 },
David Benjamincd2c8062016-09-09 11:28:16 -04008031 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008032 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008033 })
8034
David Benjamincd2c8062016-09-09 11:28:16 -04008035 ret = append(ret, perMessageTest{
8036 messageType: typeClientKeyExchange,
8037 test: testCase{
8038 testType: serverTest,
8039 protocol: protocol,
8040 name: "ClientKeyExchange" + suffix,
8041 config: Config{
8042 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008043 },
8044 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008045 })
8046
8047 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008048 ret = append(ret, perMessageTest{
8049 messageType: typeNextProtocol,
8050 test: testCase{
8051 testType: serverTest,
8052 protocol: protocol,
8053 name: "NextProtocol" + suffix,
8054 config: Config{
8055 MaxVersion: VersionTLS12,
8056 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008057 },
David Benjamincd2c8062016-09-09 11:28:16 -04008058 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008059 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008060 })
8061
David Benjamincd2c8062016-09-09 11:28:16 -04008062 ret = append(ret, perMessageTest{
8063 messageType: typeChannelID,
8064 test: testCase{
8065 testType: serverTest,
8066 protocol: protocol,
8067 name: "ChannelID" + suffix,
8068 config: Config{
8069 MaxVersion: VersionTLS12,
8070 ChannelID: channelIDKey,
8071 },
8072 flags: []string{
8073 "-expect-channel-id",
8074 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008075 },
8076 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008077 })
8078 }
8079
David Benjamincd2c8062016-09-09 11:28:16 -04008080 ret = append(ret, perMessageTest{
8081 messageType: typeFinished,
8082 test: testCase{
8083 testType: serverTest,
8084 protocol: protocol,
8085 name: "ClientFinished" + suffix,
8086 config: Config{
8087 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008088 },
8089 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008090 })
8091
David Benjamincd2c8062016-09-09 11:28:16 -04008092 ret = append(ret, perMessageTest{
8093 messageType: typeNewSessionTicket,
8094 test: testCase{
8095 protocol: protocol,
8096 name: "NewSessionTicket" + suffix,
8097 config: Config{
8098 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008099 },
8100 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008101 })
8102
David Benjamincd2c8062016-09-09 11:28:16 -04008103 ret = append(ret, perMessageTest{
8104 messageType: typeFinished,
8105 test: testCase{
8106 protocol: protocol,
8107 name: "ServerFinished" + suffix,
8108 config: Config{
8109 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008110 },
8111 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008112 })
8113
8114 }
David Benjamincd2c8062016-09-09 11:28:16 -04008115
8116 ret = append(ret, perMessageTest{
8117 messageType: typeClientHello,
8118 test: testCase{
8119 testType: serverTest,
8120 name: "TLS13-ClientHello",
8121 config: Config{
8122 MaxVersion: VersionTLS13,
8123 },
8124 },
8125 })
8126
8127 ret = append(ret, perMessageTest{
8128 messageType: typeServerHello,
8129 test: testCase{
8130 name: "TLS13-ServerHello",
8131 config: Config{
8132 MaxVersion: VersionTLS13,
8133 },
8134 },
8135 })
8136
8137 ret = append(ret, perMessageTest{
8138 messageType: typeEncryptedExtensions,
8139 test: testCase{
8140 name: "TLS13-EncryptedExtensions",
8141 config: Config{
8142 MaxVersion: VersionTLS13,
8143 },
8144 },
8145 })
8146
8147 ret = append(ret, perMessageTest{
8148 messageType: typeCertificateRequest,
8149 test: testCase{
8150 name: "TLS13-CertificateRequest",
8151 config: Config{
8152 MaxVersion: VersionTLS13,
8153 ClientAuth: RequireAnyClientCert,
8154 },
8155 },
8156 })
8157
8158 ret = append(ret, perMessageTest{
8159 messageType: typeCertificate,
8160 test: testCase{
8161 name: "TLS13-ServerCertificate",
8162 config: Config{
8163 MaxVersion: VersionTLS13,
8164 },
8165 },
8166 })
8167
8168 ret = append(ret, perMessageTest{
8169 messageType: typeCertificateVerify,
8170 test: testCase{
8171 name: "TLS13-ServerCertificateVerify",
8172 config: Config{
8173 MaxVersion: VersionTLS13,
8174 },
8175 },
8176 })
8177
8178 ret = append(ret, perMessageTest{
8179 messageType: typeFinished,
8180 test: testCase{
8181 name: "TLS13-ServerFinished",
8182 config: Config{
8183 MaxVersion: VersionTLS13,
8184 },
8185 },
8186 })
8187
8188 ret = append(ret, perMessageTest{
8189 messageType: typeCertificate,
8190 test: testCase{
8191 testType: serverTest,
8192 name: "TLS13-ClientCertificate",
8193 config: Config{
8194 Certificates: []Certificate{rsaCertificate},
8195 MaxVersion: VersionTLS13,
8196 },
8197 flags: []string{"-require-any-client-certificate"},
8198 },
8199 })
8200
8201 ret = append(ret, perMessageTest{
8202 messageType: typeCertificateVerify,
8203 test: testCase{
8204 testType: serverTest,
8205 name: "TLS13-ClientCertificateVerify",
8206 config: Config{
8207 Certificates: []Certificate{rsaCertificate},
8208 MaxVersion: VersionTLS13,
8209 },
8210 flags: []string{"-require-any-client-certificate"},
8211 },
8212 })
8213
8214 ret = append(ret, perMessageTest{
8215 messageType: typeFinished,
8216 test: testCase{
8217 testType: serverTest,
8218 name: "TLS13-ClientFinished",
8219 config: Config{
8220 MaxVersion: VersionTLS13,
8221 },
8222 },
8223 })
8224
8225 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008226}
8227
David Benjamincd2c8062016-09-09 11:28:16 -04008228func addWrongMessageTypeTests() {
8229 for _, t := range makePerMessageTests() {
8230 t.test.name = "WrongMessageType-" + t.test.name
8231 t.test.config.Bugs.SendWrongMessageType = t.messageType
8232 t.test.shouldFail = true
8233 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8234 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008235
David Benjamincd2c8062016-09-09 11:28:16 -04008236 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8237 // In TLS 1.3, a bad ServerHello means the client sends
8238 // an unencrypted alert while the server expects
8239 // encryption, so the alert is not readable by runner.
8240 t.test.expectedLocalError = "local error: bad record MAC"
8241 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008242
David Benjamincd2c8062016-09-09 11:28:16 -04008243 testCases = append(testCases, t.test)
8244 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008245}
8246
David Benjamin639846e2016-09-09 11:41:18 -04008247func addTrailingMessageDataTests() {
8248 for _, t := range makePerMessageTests() {
8249 t.test.name = "TrailingMessageData-" + t.test.name
8250 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8251 t.test.shouldFail = true
8252 t.test.expectedError = ":DECODE_ERROR:"
8253 t.test.expectedLocalError = "remote error: error decoding message"
8254
8255 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8256 // In TLS 1.3, a bad ServerHello means the client sends
8257 // an unencrypted alert while the server expects
8258 // encryption, so the alert is not readable by runner.
8259 t.test.expectedLocalError = "local error: bad record MAC"
8260 }
8261
8262 if t.messageType == typeFinished {
8263 // Bad Finished messages read as the verify data having
8264 // the wrong length.
8265 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8266 t.test.expectedLocalError = "remote error: error decrypting message"
8267 }
8268
8269 testCases = append(testCases, t.test)
8270 }
8271}
8272
Steven Valdez143e8b32016-07-11 13:19:03 -04008273func addTLS13HandshakeTests() {
8274 testCases = append(testCases, testCase{
8275 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008276 name: "NegotiatePSKResumption-TLS13",
8277 config: Config{
8278 MaxVersion: VersionTLS13,
8279 Bugs: ProtocolBugs{
8280 NegotiatePSKResumption: true,
8281 },
8282 },
8283 resumeSession: true,
8284 shouldFail: true,
8285 expectedError: ":UNEXPECTED_EXTENSION:",
8286 })
8287
8288 testCases = append(testCases, testCase{
8289 testType: clientTest,
8290 name: "OmitServerHelloSignatureAlgorithms",
8291 config: Config{
8292 MaxVersion: VersionTLS13,
8293 Bugs: ProtocolBugs{
8294 OmitServerHelloSignatureAlgorithms: true,
8295 },
8296 },
8297 shouldFail: true,
8298 expectedError: ":UNEXPECTED_EXTENSION:",
8299 })
8300
8301 testCases = append(testCases, testCase{
8302 testType: clientTest,
8303 name: "IncludeServerHelloSignatureAlgorithms",
8304 config: Config{
8305 MaxVersion: VersionTLS13,
8306 Bugs: ProtocolBugs{
8307 IncludeServerHelloSignatureAlgorithms: true,
8308 },
8309 },
8310 resumeSession: true,
8311 shouldFail: true,
8312 expectedError: ":UNEXPECTED_EXTENSION:",
8313 })
8314
8315 testCases = append(testCases, testCase{
8316 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008317 name: "MissingKeyShare-Client",
8318 config: Config{
8319 MaxVersion: VersionTLS13,
8320 Bugs: ProtocolBugs{
8321 MissingKeyShare: true,
8322 },
8323 },
8324 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008325 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008326 })
8327
8328 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008329 testType: serverTest,
8330 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008331 config: Config{
8332 MaxVersion: VersionTLS13,
8333 Bugs: ProtocolBugs{
8334 MissingKeyShare: true,
8335 },
8336 },
8337 shouldFail: true,
8338 expectedError: ":MISSING_KEY_SHARE:",
8339 })
8340
8341 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008342 testType: serverTest,
8343 name: "DuplicateKeyShares",
8344 config: Config{
8345 MaxVersion: VersionTLS13,
8346 Bugs: ProtocolBugs{
8347 DuplicateKeyShares: true,
8348 },
8349 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008350 shouldFail: true,
8351 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008352 })
8353
8354 testCases = append(testCases, testCase{
8355 testType: clientTest,
8356 name: "EmptyEncryptedExtensions",
8357 config: Config{
8358 MaxVersion: VersionTLS13,
8359 Bugs: ProtocolBugs{
8360 EmptyEncryptedExtensions: true,
8361 },
8362 },
8363 shouldFail: true,
8364 expectedLocalError: "remote error: error decoding message",
8365 })
8366
8367 testCases = append(testCases, testCase{
8368 testType: clientTest,
8369 name: "EncryptedExtensionsWithKeyShare",
8370 config: Config{
8371 MaxVersion: VersionTLS13,
8372 Bugs: ProtocolBugs{
8373 EncryptedExtensionsWithKeyShare: true,
8374 },
8375 },
8376 shouldFail: true,
8377 expectedLocalError: "remote error: unsupported extension",
8378 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008379
8380 testCases = append(testCases, testCase{
8381 testType: serverTest,
8382 name: "SendHelloRetryRequest",
8383 config: Config{
8384 MaxVersion: VersionTLS13,
8385 // Require a HelloRetryRequest for every curve.
8386 DefaultCurves: []CurveID{},
8387 },
8388 expectedCurveID: CurveX25519,
8389 })
8390
8391 testCases = append(testCases, testCase{
8392 testType: serverTest,
8393 name: "SendHelloRetryRequest-2",
8394 config: Config{
8395 MaxVersion: VersionTLS13,
8396 DefaultCurves: []CurveID{CurveP384},
8397 },
8398 // Although the ClientHello did not predict our preferred curve,
8399 // we always select it whether it is predicted or not.
8400 expectedCurveID: CurveX25519,
8401 })
8402
8403 testCases = append(testCases, testCase{
8404 name: "UnknownCurve-HelloRetryRequest",
8405 config: Config{
8406 MaxVersion: VersionTLS13,
8407 // P-384 requires HelloRetryRequest in BoringSSL.
8408 CurvePreferences: []CurveID{CurveP384},
8409 Bugs: ProtocolBugs{
8410 SendHelloRetryRequestCurve: bogusCurve,
8411 },
8412 },
8413 shouldFail: true,
8414 expectedError: ":WRONG_CURVE:",
8415 })
8416
8417 testCases = append(testCases, testCase{
8418 name: "DisabledCurve-HelloRetryRequest",
8419 config: Config{
8420 MaxVersion: VersionTLS13,
8421 CurvePreferences: []CurveID{CurveP256},
8422 Bugs: ProtocolBugs{
8423 IgnorePeerCurvePreferences: true,
8424 },
8425 },
8426 flags: []string{"-p384-only"},
8427 shouldFail: true,
8428 expectedError: ":WRONG_CURVE:",
8429 })
8430
8431 testCases = append(testCases, testCase{
8432 name: "UnnecessaryHelloRetryRequest",
8433 config: Config{
8434 MaxVersion: VersionTLS13,
8435 Bugs: ProtocolBugs{
8436 UnnecessaryHelloRetryRequest: true,
8437 },
8438 },
8439 shouldFail: true,
8440 expectedError: ":WRONG_CURVE:",
8441 })
8442
8443 testCases = append(testCases, testCase{
8444 name: "SecondHelloRetryRequest",
8445 config: Config{
8446 MaxVersion: VersionTLS13,
8447 // P-384 requires HelloRetryRequest in BoringSSL.
8448 CurvePreferences: []CurveID{CurveP384},
8449 Bugs: ProtocolBugs{
8450 SecondHelloRetryRequest: true,
8451 },
8452 },
8453 shouldFail: true,
8454 expectedError: ":UNEXPECTED_MESSAGE:",
8455 })
8456
8457 testCases = append(testCases, testCase{
8458 testType: serverTest,
8459 name: "SecondClientHelloMissingKeyShare",
8460 config: Config{
8461 MaxVersion: VersionTLS13,
8462 DefaultCurves: []CurveID{},
8463 Bugs: ProtocolBugs{
8464 SecondClientHelloMissingKeyShare: true,
8465 },
8466 },
8467 shouldFail: true,
8468 expectedError: ":MISSING_KEY_SHARE:",
8469 })
8470
8471 testCases = append(testCases, testCase{
8472 testType: serverTest,
8473 name: "SecondClientHelloWrongCurve",
8474 config: Config{
8475 MaxVersion: VersionTLS13,
8476 DefaultCurves: []CurveID{},
8477 Bugs: ProtocolBugs{
8478 MisinterpretHelloRetryRequestCurve: CurveP521,
8479 },
8480 },
8481 shouldFail: true,
8482 expectedError: ":WRONG_CURVE:",
8483 })
8484
8485 testCases = append(testCases, testCase{
8486 name: "HelloRetryRequestVersionMismatch",
8487 config: Config{
8488 MaxVersion: VersionTLS13,
8489 // P-384 requires HelloRetryRequest in BoringSSL.
8490 CurvePreferences: []CurveID{CurveP384},
8491 Bugs: ProtocolBugs{
8492 SendServerHelloVersion: 0x0305,
8493 },
8494 },
8495 shouldFail: true,
8496 expectedError: ":WRONG_VERSION_NUMBER:",
8497 })
8498
8499 testCases = append(testCases, testCase{
8500 name: "HelloRetryRequestCurveMismatch",
8501 config: Config{
8502 MaxVersion: VersionTLS13,
8503 // P-384 requires HelloRetryRequest in BoringSSL.
8504 CurvePreferences: []CurveID{CurveP384},
8505 Bugs: ProtocolBugs{
8506 // Send P-384 (correct) in the HelloRetryRequest.
8507 SendHelloRetryRequestCurve: CurveP384,
8508 // But send P-256 in the ServerHello.
8509 SendCurve: CurveP256,
8510 },
8511 },
8512 shouldFail: true,
8513 expectedError: ":WRONG_CURVE:",
8514 })
8515
8516 // Test the server selecting a curve that requires a HelloRetryRequest
8517 // without sending it.
8518 testCases = append(testCases, testCase{
8519 name: "SkipHelloRetryRequest",
8520 config: Config{
8521 MaxVersion: VersionTLS13,
8522 // P-384 requires HelloRetryRequest in BoringSSL.
8523 CurvePreferences: []CurveID{CurveP384},
8524 Bugs: ProtocolBugs{
8525 SkipHelloRetryRequest: true,
8526 },
8527 },
8528 shouldFail: true,
8529 expectedError: ":WRONG_CURVE:",
8530 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008531
8532 testCases = append(testCases, testCase{
8533 name: "TLS13-RequestContextInHandshake",
8534 config: Config{
8535 MaxVersion: VersionTLS13,
8536 MinVersion: VersionTLS13,
8537 ClientAuth: RequireAnyClientCert,
8538 Bugs: ProtocolBugs{
8539 SendRequestContext: []byte("request context"),
8540 },
8541 },
8542 flags: []string{
8543 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8544 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8545 },
8546 shouldFail: true,
8547 expectedError: ":DECODE_ERROR:",
8548 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008549
8550 testCases = append(testCases, testCase{
8551 testType: serverTest,
8552 name: "TLS13-TrailingKeyShareData",
8553 config: Config{
8554 MaxVersion: VersionTLS13,
8555 Bugs: ProtocolBugs{
8556 TrailingKeyShareData: true,
8557 },
8558 },
8559 shouldFail: true,
8560 expectedError: ":DECODE_ERROR:",
8561 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008562}
8563
David Benjaminf3fbade2016-09-19 13:08:16 -04008564func addPeekTests() {
8565 // Test SSL_peek works, including on empty records.
8566 testCases = append(testCases, testCase{
8567 name: "Peek-Basic",
8568 sendEmptyRecords: 1,
8569 flags: []string{"-peek-then-read"},
8570 })
8571
8572 // Test SSL_peek can drive the initial handshake.
8573 testCases = append(testCases, testCase{
8574 name: "Peek-ImplicitHandshake",
8575 flags: []string{
8576 "-peek-then-read",
8577 "-implicit-handshake",
8578 },
8579 })
8580
8581 // Test SSL_peek can discover and drive a renegotiation.
8582 testCases = append(testCases, testCase{
8583 name: "Peek-Renegotiate",
8584 config: Config{
8585 MaxVersion: VersionTLS12,
8586 },
8587 renegotiate: 1,
8588 flags: []string{
8589 "-peek-then-read",
8590 "-renegotiate-freely",
8591 "-expect-total-renegotiations", "1",
8592 },
8593 })
8594
8595 // Test SSL_peek can discover a close_notify.
8596 testCases = append(testCases, testCase{
8597 name: "Peek-Shutdown",
8598 config: Config{
8599 Bugs: ProtocolBugs{
8600 ExpectCloseNotify: true,
8601 },
8602 },
8603 flags: []string{
8604 "-peek-then-read",
8605 "-check-close-notify",
8606 },
8607 })
8608
8609 // Test SSL_peek can discover an alert.
8610 testCases = append(testCases, testCase{
8611 name: "Peek-Alert",
8612 config: Config{
8613 Bugs: ProtocolBugs{
8614 SendSpuriousAlert: alertRecordOverflow,
8615 },
8616 },
8617 flags: []string{"-peek-then-read"},
8618 shouldFail: true,
8619 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8620 })
8621
8622 // Test SSL_peek can handle KeyUpdate.
8623 testCases = append(testCases, testCase{
8624 name: "Peek-KeyUpdate",
8625 config: Config{
8626 MaxVersion: VersionTLS13,
8627 Bugs: ProtocolBugs{
8628 SendKeyUpdateBeforeEveryAppDataRecord: true,
8629 },
8630 },
8631 flags: []string{"-peek-then-read"},
8632 })
8633}
8634
Adam Langley7c803a62015-06-15 15:35:05 -07008635func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008636 defer wg.Done()
8637
8638 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008639 var err error
8640
8641 if *mallocTest < 0 {
8642 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008643 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008644 } else {
8645 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8646 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008647 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008648 if err != nil {
8649 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8650 }
8651 break
8652 }
8653 }
8654 }
Adam Langley95c29f32014-06-20 12:00:00 -07008655 statusChan <- statusMsg{test: test, err: err}
8656 }
8657}
8658
8659type statusMsg struct {
8660 test *testCase
8661 started bool
8662 err error
8663}
8664
David Benjamin5f237bc2015-02-11 17:14:15 -05008665func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008666 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008667
David Benjamin5f237bc2015-02-11 17:14:15 -05008668 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008669 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008670 if !*pipe {
8671 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008672 var erase string
8673 for i := 0; i < lineLen; i++ {
8674 erase += "\b \b"
8675 }
8676 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008677 }
8678
Adam Langley95c29f32014-06-20 12:00:00 -07008679 if msg.started {
8680 started++
8681 } else {
8682 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008683
8684 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008685 if msg.err == errUnimplemented {
8686 if *pipe {
8687 // Print each test instead of a status line.
8688 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8689 }
8690 unimplemented++
8691 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8692 } else {
8693 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8694 failed++
8695 testOutput.addResult(msg.test.name, "FAIL")
8696 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008697 } else {
8698 if *pipe {
8699 // Print each test instead of a status line.
8700 fmt.Printf("PASSED (%s)\n", msg.test.name)
8701 }
8702 testOutput.addResult(msg.test.name, "PASS")
8703 }
Adam Langley95c29f32014-06-20 12:00:00 -07008704 }
8705
David Benjamin5f237bc2015-02-11 17:14:15 -05008706 if !*pipe {
8707 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008708 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008709 lineLen = len(line)
8710 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008711 }
Adam Langley95c29f32014-06-20 12:00:00 -07008712 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008713
8714 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008715}
8716
8717func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008718 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008719 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008720 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008721
Adam Langley7c803a62015-06-15 15:35:05 -07008722 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008723 addCipherSuiteTests()
8724 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008725 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008726 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008727 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008728 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008729 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008730 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008731 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008732 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008733 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008734 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008735 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008736 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008737 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008738 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008739 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008740 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008741 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008742 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008743 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008744 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04008745 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008746 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008747 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008748 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008749 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008750 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008751 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008752 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008753
8754 var wg sync.WaitGroup
8755
Adam Langley7c803a62015-06-15 15:35:05 -07008756 statusChan := make(chan statusMsg, *numWorkers)
8757 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008758 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008759
EKRf71d7ed2016-08-06 13:25:12 -07008760 if len(*shimConfigFile) != 0 {
8761 encoded, err := ioutil.ReadFile(*shimConfigFile)
8762 if err != nil {
8763 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8764 os.Exit(1)
8765 }
8766
8767 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8768 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8769 os.Exit(1)
8770 }
8771 }
8772
David Benjamin025b3d32014-07-01 19:53:04 -04008773 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008774
Adam Langley7c803a62015-06-15 15:35:05 -07008775 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008776 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008777 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008778 }
8779
David Benjamin270f0a72016-03-17 14:41:36 -04008780 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008781 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008782 matched := true
8783 if len(*testToRun) != 0 {
8784 var err error
8785 matched, err = filepath.Match(*testToRun, testCases[i].name)
8786 if err != nil {
8787 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8788 os.Exit(1)
8789 }
8790 }
8791
EKRf71d7ed2016-08-06 13:25:12 -07008792 if !*includeDisabled {
8793 for pattern := range shimConfig.DisabledTests {
8794 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8795 if err != nil {
8796 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8797 os.Exit(1)
8798 }
8799
8800 if isDisabled {
8801 matched = false
8802 break
8803 }
8804 }
8805 }
8806
David Benjamin17e12922016-07-28 18:04:43 -04008807 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008808 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008809 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008810 }
8811 }
David Benjamin17e12922016-07-28 18:04:43 -04008812
David Benjamin270f0a72016-03-17 14:41:36 -04008813 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008814 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008815 os.Exit(1)
8816 }
Adam Langley95c29f32014-06-20 12:00:00 -07008817
8818 close(testChan)
8819 wg.Wait()
8820 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008821 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008822
8823 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008824
8825 if *jsonOutput != "" {
8826 if err := testOutput.writeTo(*jsonOutput); err != nil {
8827 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8828 }
8829 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008830
EKR842ae6c2016-07-27 09:22:05 +02008831 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8832 os.Exit(1)
8833 }
8834
8835 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008836 os.Exit(1)
8837 }
Adam Langley95c29f32014-06-20 12:00:00 -07008838}