blob: 5630b479bbe1307b72c83361fcda515d30dadc48 [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 {
Adam Langley38311732014-10-16 19:04:35 -0700792 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
793 panic("Error expected without shouldFail in " + test.name)
794 }
795
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700796 if test.expectResumeRejected && !test.resumeSession {
797 panic("expectResumeRejected without resumeSession in " + test.name)
798 }
799
David Benjamin87c8a642015-02-21 01:54:29 -0500800 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
801 if err != nil {
802 panic(err)
803 }
804 defer func() {
805 if listener != nil {
806 listener.Close()
807 }
808 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700809
David Benjamin87c8a642015-02-21 01:54:29 -0500810 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400811 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400812 flags = append(flags, "-server")
813
David Benjamin025b3d32014-07-01 19:53:04 -0400814 flags = append(flags, "-key-file")
815 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700816 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400817 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700818 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400819 }
820
821 flags = append(flags, "-cert-file")
822 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700823 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400824 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700825 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400826 }
827 }
David Benjamin5a593af2014-08-11 19:51:50 -0400828
David Benjamin6fd297b2014-08-11 18:43:38 -0400829 if test.protocol == dtls {
830 flags = append(flags, "-dtls")
831 }
832
David Benjamin46662482016-08-17 00:51:00 -0400833 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400834 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400835 resumeCount++
836 if test.resumeRenewedSession {
837 resumeCount++
838 }
839 }
840
841 if resumeCount > 0 {
842 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400843 }
844
David Benjamine58c4f52014-08-24 03:47:07 -0400845 if test.shimWritesFirst {
846 flags = append(flags, "-shim-writes-first")
847 }
848
David Benjamin30789da2015-08-29 22:56:45 -0400849 if test.shimShutsDown {
850 flags = append(flags, "-shim-shuts-down")
851 }
852
David Benjaminc565ebb2015-04-03 04:06:36 -0400853 if test.exportKeyingMaterial > 0 {
854 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
855 flags = append(flags, "-export-label", test.exportLabel)
856 flags = append(flags, "-export-context", test.exportContext)
857 if test.useExportContext {
858 flags = append(flags, "-use-export-context")
859 }
860 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700861 if test.expectResumeRejected {
862 flags = append(flags, "-expect-session-miss")
863 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400864
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700865 if test.testTLSUnique {
866 flags = append(flags, "-tls-unique")
867 }
868
David Benjamin025b3d32014-07-01 19:53:04 -0400869 flags = append(flags, test.flags...)
870
871 var shim *exec.Cmd
872 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700873 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700874 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700875 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500876 } else if *useLLDB {
877 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400878 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700879 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400880 }
David Benjamin025b3d32014-07-01 19:53:04 -0400881 shim.Stdin = os.Stdin
882 var stdoutBuf, stderrBuf bytes.Buffer
883 shim.Stdout = &stdoutBuf
884 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800885 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500886 shim.Env = os.Environ()
887 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800888 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400889 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800890 }
891 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
892 }
David Benjamin025b3d32014-07-01 19:53:04 -0400893
894 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700895 panic(err)
896 }
David Benjamin87c8a642015-02-21 01:54:29 -0500897 waitChan := make(chan error, 1)
898 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700899
900 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700901
David Benjamin7a4aaa42016-09-20 17:58:14 -0400902 if *deterministic {
903 config.Rand = &deterministicRand{}
904 }
905
David Benjamin87c8a642015-02-21 01:54:29 -0500906 conn, err := acceptOrWait(listener, waitChan)
907 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400908 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500909 conn.Close()
910 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500911
David Benjamin46662482016-08-17 00:51:00 -0400912 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400913 var resumeConfig Config
914 if test.resumeConfig != nil {
915 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400916 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500917 resumeConfig.SessionTicketKey = config.SessionTicketKey
918 resumeConfig.ClientSessionCache = config.ClientSessionCache
919 resumeConfig.ServerSessionCache = config.ServerSessionCache
920 }
David Benjamin2e045a92016-06-08 13:09:56 -0400921 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400922 } else {
923 resumeConfig = config
924 }
David Benjamin87c8a642015-02-21 01:54:29 -0500925 var connResume net.Conn
926 connResume, err = acceptOrWait(listener, waitChan)
927 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400928 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500929 connResume.Close()
930 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400931 }
932
David Benjamin87c8a642015-02-21 01:54:29 -0500933 // Close the listener now. This is to avoid hangs should the shim try to
934 // open more connections than expected.
935 listener.Close()
936 listener = nil
937
938 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400939 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800940 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200941 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
942 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800943 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200944 case 89:
945 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400946 case 99:
947 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800948 }
949 }
Adam Langley95c29f32014-06-20 12:00:00 -0700950
David Benjamin9bea3492016-03-02 10:59:16 -0500951 // Account for Windows line endings.
952 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
953 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500954
955 // Separate the errors from the shim and those from tools like
956 // AddressSanitizer.
957 var extraStderr string
958 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
959 stderr = stderrParts[0]
960 extraStderr = stderrParts[1]
961 }
962
Adam Langley95c29f32014-06-20 12:00:00 -0700963 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700964 expectedError := translateExpectedError(test.expectedError)
965 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200966
Adam Langleyac61fa32014-06-23 12:03:11 -0700967 localError := "none"
968 if err != nil {
969 localError = err.Error()
970 }
971 if len(test.expectedLocalError) != 0 {
972 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
973 }
Adam Langley95c29f32014-06-20 12:00:00 -0700974
975 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700976 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700977 if childErr != nil {
978 childError = childErr.Error()
979 }
980
981 var msg string
982 switch {
983 case failed && !test.shouldFail:
984 msg = "unexpected failure"
985 case !failed && test.shouldFail:
986 msg = "unexpected success"
987 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700988 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700989 default:
990 panic("internal error")
991 }
992
David Benjamin9aafb642016-09-20 19:36:53 -0400993 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 -0700994 }
995
David Benjamind2ba8892016-09-20 19:41:04 -0400996 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500997 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700998 }
999
David Benjamind2ba8892016-09-20 19:41:04 -04001000 if *useValgrind && isValgrindError {
1001 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1002 }
1003
Adam Langley95c29f32014-06-20 12:00:00 -07001004 return nil
1005}
1006
1007var tlsVersions = []struct {
1008 name string
1009 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001010 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001011 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001012}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001013 {"SSL3", VersionSSL30, "-no-ssl3", false},
1014 {"TLS1", VersionTLS10, "-no-tls1", true},
1015 {"TLS11", VersionTLS11, "-no-tls11", false},
1016 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001017 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001018}
1019
1020var testCipherSuites = []struct {
1021 name string
1022 id uint16
1023}{
1024 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001025 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001026 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001027 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001028 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001029 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001030 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001031 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1032 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001033 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001034 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1035 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001036 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001037 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1038 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001039 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1040 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001041 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001042 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001043 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001044 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001045 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001046 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001047 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001048 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001049 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001050 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001051 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001052 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001053 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1054 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1055 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1056 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001057 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1058 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001059 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1060 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001061 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001062 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1063 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001064 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001065}
1066
David Benjamin8b8c0062014-11-23 02:47:52 -05001067func hasComponent(suiteName, component string) bool {
1068 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1069}
1070
David Benjaminf7768e42014-08-31 02:06:47 -04001071func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001072 return hasComponent(suiteName, "GCM") ||
1073 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001074 hasComponent(suiteName, "SHA384") ||
1075 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001076}
1077
Nick Harper1fd39d82016-06-14 18:14:35 -07001078func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001079 // Only AEADs.
1080 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1081 return false
1082 }
1083 // No old CHACHA20_POLY1305.
1084 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1085 return false
1086 }
1087 // Must have ECDHE.
1088 // TODO(davidben,svaldez): Add pure PSK support.
1089 if !hasComponent(suiteName, "ECDHE") {
1090 return false
1091 }
1092 // TODO(davidben,svaldez): Add PSK support.
1093 if hasComponent(suiteName, "PSK") {
1094 return false
1095 }
1096 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001097}
1098
David Benjamin8b8c0062014-11-23 02:47:52 -05001099func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001100 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001101}
1102
Adam Langleya7997f12015-05-14 17:38:50 -07001103func bigFromHex(hex string) *big.Int {
1104 ret, ok := new(big.Int).SetString(hex, 16)
1105 if !ok {
1106 panic("failed to parse hex number 0x" + hex)
1107 }
1108 return ret
1109}
1110
Adam Langley7c803a62015-06-15 15:35:05 -07001111func addBasicTests() {
1112 basicTests := []testCase{
1113 {
Adam Langley7c803a62015-06-15 15:35:05 -07001114 name: "NoFallbackSCSV",
1115 config: Config{
1116 Bugs: ProtocolBugs{
1117 FailIfNotFallbackSCSV: true,
1118 },
1119 },
1120 shouldFail: true,
1121 expectedLocalError: "no fallback SCSV found",
1122 },
1123 {
1124 name: "SendFallbackSCSV",
1125 config: Config{
1126 Bugs: ProtocolBugs{
1127 FailIfNotFallbackSCSV: true,
1128 },
1129 },
1130 flags: []string{"-fallback-scsv"},
1131 },
1132 {
1133 name: "ClientCertificateTypes",
1134 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001135 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001136 ClientAuth: RequestClientCert,
1137 ClientCertificateTypes: []byte{
1138 CertTypeDSSSign,
1139 CertTypeRSASign,
1140 CertTypeECDSASign,
1141 },
1142 },
1143 flags: []string{
1144 "-expect-certificate-types",
1145 base64.StdEncoding.EncodeToString([]byte{
1146 CertTypeDSSSign,
1147 CertTypeRSASign,
1148 CertTypeECDSASign,
1149 }),
1150 },
1151 },
1152 {
Adam Langley7c803a62015-06-15 15:35:05 -07001153 name: "UnauthenticatedECDH",
1154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001155 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001156 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1157 Bugs: ProtocolBugs{
1158 UnauthenticatedECDH: true,
1159 },
1160 },
1161 shouldFail: true,
1162 expectedError: ":UNEXPECTED_MESSAGE:",
1163 },
1164 {
1165 name: "SkipCertificateStatus",
1166 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001167 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001168 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1169 Bugs: ProtocolBugs{
1170 SkipCertificateStatus: true,
1171 },
1172 },
1173 flags: []string{
1174 "-enable-ocsp-stapling",
1175 },
1176 },
1177 {
1178 name: "SkipServerKeyExchange",
1179 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001180 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001181 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1182 Bugs: ProtocolBugs{
1183 SkipServerKeyExchange: true,
1184 },
1185 },
1186 shouldFail: true,
1187 expectedError: ":UNEXPECTED_MESSAGE:",
1188 },
1189 {
Adam Langley7c803a62015-06-15 15:35:05 -07001190 testType: serverTest,
1191 name: "Alert",
1192 config: Config{
1193 Bugs: ProtocolBugs{
1194 SendSpuriousAlert: alertRecordOverflow,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1199 },
1200 {
1201 protocol: dtls,
1202 testType: serverTest,
1203 name: "Alert-DTLS",
1204 config: Config{
1205 Bugs: ProtocolBugs{
1206 SendSpuriousAlert: alertRecordOverflow,
1207 },
1208 },
1209 shouldFail: true,
1210 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1211 },
1212 {
1213 testType: serverTest,
1214 name: "FragmentAlert",
1215 config: Config{
1216 Bugs: ProtocolBugs{
1217 FragmentAlert: true,
1218 SendSpuriousAlert: alertRecordOverflow,
1219 },
1220 },
1221 shouldFail: true,
1222 expectedError: ":BAD_ALERT:",
1223 },
1224 {
1225 protocol: dtls,
1226 testType: serverTest,
1227 name: "FragmentAlert-DTLS",
1228 config: Config{
1229 Bugs: ProtocolBugs{
1230 FragmentAlert: true,
1231 SendSpuriousAlert: alertRecordOverflow,
1232 },
1233 },
1234 shouldFail: true,
1235 expectedError: ":BAD_ALERT:",
1236 },
1237 {
1238 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001239 name: "DoubleAlert",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 DoubleAlert: true,
1243 SendSpuriousAlert: alertRecordOverflow,
1244 },
1245 },
1246 shouldFail: true,
1247 expectedError: ":BAD_ALERT:",
1248 },
1249 {
1250 protocol: dtls,
1251 testType: serverTest,
1252 name: "DoubleAlert-DTLS",
1253 config: Config{
1254 Bugs: ProtocolBugs{
1255 DoubleAlert: true,
1256 SendSpuriousAlert: alertRecordOverflow,
1257 },
1258 },
1259 shouldFail: true,
1260 expectedError: ":BAD_ALERT:",
1261 },
1262 {
Adam Langley7c803a62015-06-15 15:35:05 -07001263 name: "SkipNewSessionTicket",
1264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001265 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001266 Bugs: ProtocolBugs{
1267 SkipNewSessionTicket: true,
1268 },
1269 },
1270 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001271 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001272 },
1273 {
1274 testType: serverTest,
1275 name: "FallbackSCSV",
1276 config: Config{
1277 MaxVersion: VersionTLS11,
1278 Bugs: ProtocolBugs{
1279 SendFallbackSCSV: true,
1280 },
1281 },
1282 shouldFail: true,
1283 expectedError: ":INAPPROPRIATE_FALLBACK:",
1284 },
1285 {
1286 testType: serverTest,
1287 name: "FallbackSCSV-VersionMatch",
1288 config: Config{
1289 Bugs: ProtocolBugs{
1290 SendFallbackSCSV: true,
1291 },
1292 },
1293 },
1294 {
1295 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001296 name: "FallbackSCSV-VersionMatch-TLS12",
1297 config: Config{
1298 MaxVersion: VersionTLS12,
1299 Bugs: ProtocolBugs{
1300 SendFallbackSCSV: true,
1301 },
1302 },
1303 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1304 },
1305 {
1306 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 name: "FragmentedClientVersion",
1308 config: Config{
1309 Bugs: ProtocolBugs{
1310 MaxHandshakeRecordLength: 1,
1311 FragmentClientVersion: true,
1312 },
1313 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001314 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001315 },
1316 {
Adam Langley7c803a62015-06-15 15:35:05 -07001317 testType: serverTest,
1318 name: "HttpGET",
1319 sendPrefix: "GET / HTTP/1.0\n",
1320 shouldFail: true,
1321 expectedError: ":HTTP_REQUEST:",
1322 },
1323 {
1324 testType: serverTest,
1325 name: "HttpPOST",
1326 sendPrefix: "POST / HTTP/1.0\n",
1327 shouldFail: true,
1328 expectedError: ":HTTP_REQUEST:",
1329 },
1330 {
1331 testType: serverTest,
1332 name: "HttpHEAD",
1333 sendPrefix: "HEAD / HTTP/1.0\n",
1334 shouldFail: true,
1335 expectedError: ":HTTP_REQUEST:",
1336 },
1337 {
1338 testType: serverTest,
1339 name: "HttpPUT",
1340 sendPrefix: "PUT / HTTP/1.0\n",
1341 shouldFail: true,
1342 expectedError: ":HTTP_REQUEST:",
1343 },
1344 {
1345 testType: serverTest,
1346 name: "HttpCONNECT",
1347 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1348 shouldFail: true,
1349 expectedError: ":HTTPS_PROXY_REQUEST:",
1350 },
1351 {
1352 testType: serverTest,
1353 name: "Garbage",
1354 sendPrefix: "blah",
1355 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001356 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001357 },
1358 {
Adam Langley7c803a62015-06-15 15:35:05 -07001359 name: "RSAEphemeralKey",
1360 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001361 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001362 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1363 Bugs: ProtocolBugs{
1364 RSAEphemeralKey: true,
1365 },
1366 },
1367 shouldFail: true,
1368 expectedError: ":UNEXPECTED_MESSAGE:",
1369 },
1370 {
1371 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001372 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001373 shouldFail: true,
1374 expectedError: ":WRONG_SSL_VERSION:",
1375 },
1376 {
1377 protocol: dtls,
1378 name: "DisableEverything-DTLS",
1379 flags: []string{"-no-tls12", "-no-tls1"},
1380 shouldFail: true,
1381 expectedError: ":WRONG_SSL_VERSION:",
1382 },
1383 {
Adam Langley7c803a62015-06-15 15:35:05 -07001384 protocol: dtls,
1385 testType: serverTest,
1386 name: "MTU",
1387 config: Config{
1388 Bugs: ProtocolBugs{
1389 MaxPacketLength: 256,
1390 },
1391 },
1392 flags: []string{"-mtu", "256"},
1393 },
1394 {
1395 protocol: dtls,
1396 testType: serverTest,
1397 name: "MTUExceeded",
1398 config: Config{
1399 Bugs: ProtocolBugs{
1400 MaxPacketLength: 255,
1401 },
1402 },
1403 flags: []string{"-mtu", "256"},
1404 shouldFail: true,
1405 expectedLocalError: "dtls: exceeded maximum packet length",
1406 },
1407 {
1408 name: "CertMismatchRSA",
1409 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001410 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001411 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001412 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001413 Bugs: ProtocolBugs{
1414 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1419 },
1420 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001421 name: "CertMismatchRSA-TLS13",
1422 config: Config{
1423 MaxVersion: VersionTLS13,
1424 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1425 Certificates: []Certificate{ecdsaP256Certificate},
1426 Bugs: ProtocolBugs{
1427 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1428 },
1429 },
1430 shouldFail: true,
1431 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1432 },
1433 {
Adam Langley7c803a62015-06-15 15:35:05 -07001434 name: "CertMismatchECDSA",
1435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001436 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001437 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001438 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001439 Bugs: ProtocolBugs{
1440 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1441 },
1442 },
1443 shouldFail: true,
1444 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1445 },
1446 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001447 name: "CertMismatchECDSA-TLS13",
1448 config: Config{
1449 MaxVersion: VersionTLS13,
1450 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1451 Certificates: []Certificate{rsaCertificate},
1452 Bugs: ProtocolBugs{
1453 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1454 },
1455 },
1456 shouldFail: true,
1457 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1458 },
1459 {
Adam Langley7c803a62015-06-15 15:35:05 -07001460 name: "EmptyCertificateList",
1461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001462 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001463 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1464 Bugs: ProtocolBugs{
1465 EmptyCertificateList: true,
1466 },
1467 },
1468 shouldFail: true,
1469 expectedError: ":DECODE_ERROR:",
1470 },
1471 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001472 name: "EmptyCertificateList-TLS13",
1473 config: Config{
1474 MaxVersion: VersionTLS13,
1475 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1476 Bugs: ProtocolBugs{
1477 EmptyCertificateList: true,
1478 },
1479 },
1480 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001481 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001482 },
1483 {
Adam Langley7c803a62015-06-15 15:35:05 -07001484 name: "TLSFatalBadPackets",
1485 damageFirstWrite: true,
1486 shouldFail: true,
1487 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1488 },
1489 {
1490 protocol: dtls,
1491 name: "DTLSIgnoreBadPackets",
1492 damageFirstWrite: true,
1493 },
1494 {
1495 protocol: dtls,
1496 name: "DTLSIgnoreBadPackets-Async",
1497 damageFirstWrite: true,
1498 flags: []string{"-async"},
1499 },
1500 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001501 name: "AppDataBeforeHandshake",
1502 config: Config{
1503 Bugs: ProtocolBugs{
1504 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1505 },
1506 },
1507 shouldFail: true,
1508 expectedError: ":UNEXPECTED_RECORD:",
1509 },
1510 {
1511 name: "AppDataBeforeHandshake-Empty",
1512 config: Config{
1513 Bugs: ProtocolBugs{
1514 AppDataBeforeHandshake: []byte{},
1515 },
1516 },
1517 shouldFail: true,
1518 expectedError: ":UNEXPECTED_RECORD:",
1519 },
1520 {
1521 protocol: dtls,
1522 name: "AppDataBeforeHandshake-DTLS",
1523 config: Config{
1524 Bugs: ProtocolBugs{
1525 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1526 },
1527 },
1528 shouldFail: true,
1529 expectedError: ":UNEXPECTED_RECORD:",
1530 },
1531 {
1532 protocol: dtls,
1533 name: "AppDataBeforeHandshake-DTLS-Empty",
1534 config: Config{
1535 Bugs: ProtocolBugs{
1536 AppDataBeforeHandshake: []byte{},
1537 },
1538 },
1539 shouldFail: true,
1540 expectedError: ":UNEXPECTED_RECORD:",
1541 },
1542 {
Adam Langley7c803a62015-06-15 15:35:05 -07001543 name: "AppDataAfterChangeCipherSpec",
1544 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001545 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001546 Bugs: ProtocolBugs{
1547 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1548 },
1549 },
1550 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001551 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001552 },
1553 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001554 name: "AppDataAfterChangeCipherSpec-Empty",
1555 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001556 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001557 Bugs: ProtocolBugs{
1558 AppDataAfterChangeCipherSpec: []byte{},
1559 },
1560 },
1561 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001562 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001563 },
1564 {
Adam Langley7c803a62015-06-15 15:35:05 -07001565 protocol: dtls,
1566 name: "AppDataAfterChangeCipherSpec-DTLS",
1567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001568 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001569 Bugs: ProtocolBugs{
1570 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1571 },
1572 },
1573 // BoringSSL's DTLS implementation will drop the out-of-order
1574 // application data.
1575 },
1576 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001577 protocol: dtls,
1578 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1579 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001580 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001581 Bugs: ProtocolBugs{
1582 AppDataAfterChangeCipherSpec: []byte{},
1583 },
1584 },
1585 // BoringSSL's DTLS implementation will drop the out-of-order
1586 // application data.
1587 },
1588 {
Adam Langley7c803a62015-06-15 15:35:05 -07001589 name: "AlertAfterChangeCipherSpec",
1590 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001591 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001592 Bugs: ProtocolBugs{
1593 AlertAfterChangeCipherSpec: alertRecordOverflow,
1594 },
1595 },
1596 shouldFail: true,
1597 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1598 },
1599 {
1600 protocol: dtls,
1601 name: "AlertAfterChangeCipherSpec-DTLS",
1602 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001603 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001604 Bugs: ProtocolBugs{
1605 AlertAfterChangeCipherSpec: alertRecordOverflow,
1606 },
1607 },
1608 shouldFail: true,
1609 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1610 },
1611 {
1612 protocol: dtls,
1613 name: "ReorderHandshakeFragments-Small-DTLS",
1614 config: Config{
1615 Bugs: ProtocolBugs{
1616 ReorderHandshakeFragments: true,
1617 // Small enough that every handshake message is
1618 // fragmented.
1619 MaxHandshakeRecordLength: 2,
1620 },
1621 },
1622 },
1623 {
1624 protocol: dtls,
1625 name: "ReorderHandshakeFragments-Large-DTLS",
1626 config: Config{
1627 Bugs: ProtocolBugs{
1628 ReorderHandshakeFragments: true,
1629 // Large enough that no handshake message is
1630 // fragmented.
1631 MaxHandshakeRecordLength: 2048,
1632 },
1633 },
1634 },
1635 {
1636 protocol: dtls,
1637 name: "MixCompleteMessageWithFragments-DTLS",
1638 config: Config{
1639 Bugs: ProtocolBugs{
1640 ReorderHandshakeFragments: true,
1641 MixCompleteMessageWithFragments: true,
1642 MaxHandshakeRecordLength: 2,
1643 },
1644 },
1645 },
1646 {
1647 name: "SendInvalidRecordType",
1648 config: Config{
1649 Bugs: ProtocolBugs{
1650 SendInvalidRecordType: true,
1651 },
1652 },
1653 shouldFail: true,
1654 expectedError: ":UNEXPECTED_RECORD:",
1655 },
1656 {
1657 protocol: dtls,
1658 name: "SendInvalidRecordType-DTLS",
1659 config: Config{
1660 Bugs: ProtocolBugs{
1661 SendInvalidRecordType: true,
1662 },
1663 },
1664 shouldFail: true,
1665 expectedError: ":UNEXPECTED_RECORD:",
1666 },
1667 {
1668 name: "FalseStart-SkipServerSecondLeg",
1669 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001670 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001671 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1672 NextProtos: []string{"foo"},
1673 Bugs: ProtocolBugs{
1674 SkipNewSessionTicket: true,
1675 SkipChangeCipherSpec: true,
1676 SkipFinished: true,
1677 ExpectFalseStart: true,
1678 },
1679 },
1680 flags: []string{
1681 "-false-start",
1682 "-handshake-never-done",
1683 "-advertise-alpn", "\x03foo",
1684 },
1685 shimWritesFirst: true,
1686 shouldFail: true,
1687 expectedError: ":UNEXPECTED_RECORD:",
1688 },
1689 {
1690 name: "FalseStart-SkipServerSecondLeg-Implicit",
1691 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001692 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001693 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1694 NextProtos: []string{"foo"},
1695 Bugs: ProtocolBugs{
1696 SkipNewSessionTicket: true,
1697 SkipChangeCipherSpec: true,
1698 SkipFinished: true,
1699 },
1700 },
1701 flags: []string{
1702 "-implicit-handshake",
1703 "-false-start",
1704 "-handshake-never-done",
1705 "-advertise-alpn", "\x03foo",
1706 },
1707 shouldFail: true,
1708 expectedError: ":UNEXPECTED_RECORD:",
1709 },
1710 {
1711 testType: serverTest,
1712 name: "FailEarlyCallback",
1713 flags: []string{"-fail-early-callback"},
1714 shouldFail: true,
1715 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001716 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001717 },
1718 {
Adam Langley7c803a62015-06-15 15:35:05 -07001719 protocol: dtls,
1720 name: "FragmentMessageTypeMismatch-DTLS",
1721 config: Config{
1722 Bugs: ProtocolBugs{
1723 MaxHandshakeRecordLength: 2,
1724 FragmentMessageTypeMismatch: true,
1725 },
1726 },
1727 shouldFail: true,
1728 expectedError: ":FRAGMENT_MISMATCH:",
1729 },
1730 {
1731 protocol: dtls,
1732 name: "FragmentMessageLengthMismatch-DTLS",
1733 config: Config{
1734 Bugs: ProtocolBugs{
1735 MaxHandshakeRecordLength: 2,
1736 FragmentMessageLengthMismatch: true,
1737 },
1738 },
1739 shouldFail: true,
1740 expectedError: ":FRAGMENT_MISMATCH:",
1741 },
1742 {
1743 protocol: dtls,
1744 name: "SplitFragments-Header-DTLS",
1745 config: Config{
1746 Bugs: ProtocolBugs{
1747 SplitFragments: 2,
1748 },
1749 },
1750 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001751 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001752 },
1753 {
1754 protocol: dtls,
1755 name: "SplitFragments-Boundary-DTLS",
1756 config: Config{
1757 Bugs: ProtocolBugs{
1758 SplitFragments: dtlsRecordHeaderLen,
1759 },
1760 },
1761 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001762 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001763 },
1764 {
1765 protocol: dtls,
1766 name: "SplitFragments-Body-DTLS",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 SplitFragments: dtlsRecordHeaderLen + 1,
1770 },
1771 },
1772 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001773 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001774 },
1775 {
1776 protocol: dtls,
1777 name: "SendEmptyFragments-DTLS",
1778 config: Config{
1779 Bugs: ProtocolBugs{
1780 SendEmptyFragments: true,
1781 },
1782 },
1783 },
1784 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001785 name: "BadFinished-Client",
1786 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001787 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001788 Bugs: ProtocolBugs{
1789 BadFinished: true,
1790 },
1791 },
1792 shouldFail: true,
1793 expectedError: ":DIGEST_CHECK_FAILED:",
1794 },
1795 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001796 name: "BadFinished-Client-TLS13",
1797 config: Config{
1798 MaxVersion: VersionTLS13,
1799 Bugs: ProtocolBugs{
1800 BadFinished: true,
1801 },
1802 },
1803 shouldFail: true,
1804 expectedError: ":DIGEST_CHECK_FAILED:",
1805 },
1806 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001807 testType: serverTest,
1808 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001809 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001810 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001811 Bugs: ProtocolBugs{
1812 BadFinished: true,
1813 },
1814 },
1815 shouldFail: true,
1816 expectedError: ":DIGEST_CHECK_FAILED:",
1817 },
1818 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001819 testType: serverTest,
1820 name: "BadFinished-Server-TLS13",
1821 config: Config{
1822 MaxVersion: VersionTLS13,
1823 Bugs: ProtocolBugs{
1824 BadFinished: true,
1825 },
1826 },
1827 shouldFail: true,
1828 expectedError: ":DIGEST_CHECK_FAILED:",
1829 },
1830 {
Adam Langley7c803a62015-06-15 15:35:05 -07001831 name: "FalseStart-BadFinished",
1832 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001833 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001834 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1835 NextProtos: []string{"foo"},
1836 Bugs: ProtocolBugs{
1837 BadFinished: true,
1838 ExpectFalseStart: true,
1839 },
1840 },
1841 flags: []string{
1842 "-false-start",
1843 "-handshake-never-done",
1844 "-advertise-alpn", "\x03foo",
1845 },
1846 shimWritesFirst: true,
1847 shouldFail: true,
1848 expectedError: ":DIGEST_CHECK_FAILED:",
1849 },
1850 {
1851 name: "NoFalseStart-NoALPN",
1852 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001853 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001854 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1855 Bugs: ProtocolBugs{
1856 ExpectFalseStart: true,
1857 AlertBeforeFalseStartTest: alertAccessDenied,
1858 },
1859 },
1860 flags: []string{
1861 "-false-start",
1862 },
1863 shimWritesFirst: true,
1864 shouldFail: true,
1865 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1866 expectedLocalError: "tls: peer did not false start: EOF",
1867 },
1868 {
1869 name: "NoFalseStart-NoAEAD",
1870 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001871 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001872 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1873 NextProtos: []string{"foo"},
1874 Bugs: ProtocolBugs{
1875 ExpectFalseStart: true,
1876 AlertBeforeFalseStartTest: alertAccessDenied,
1877 },
1878 },
1879 flags: []string{
1880 "-false-start",
1881 "-advertise-alpn", "\x03foo",
1882 },
1883 shimWritesFirst: true,
1884 shouldFail: true,
1885 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1886 expectedLocalError: "tls: peer did not false start: EOF",
1887 },
1888 {
1889 name: "NoFalseStart-RSA",
1890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001891 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001892 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1893 NextProtos: []string{"foo"},
1894 Bugs: ProtocolBugs{
1895 ExpectFalseStart: true,
1896 AlertBeforeFalseStartTest: alertAccessDenied,
1897 },
1898 },
1899 flags: []string{
1900 "-false-start",
1901 "-advertise-alpn", "\x03foo",
1902 },
1903 shimWritesFirst: true,
1904 shouldFail: true,
1905 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1906 expectedLocalError: "tls: peer did not false start: EOF",
1907 },
1908 {
1909 name: "NoFalseStart-DHE_RSA",
1910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001911 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001912 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1913 NextProtos: []string{"foo"},
1914 Bugs: ProtocolBugs{
1915 ExpectFalseStart: true,
1916 AlertBeforeFalseStartTest: alertAccessDenied,
1917 },
1918 },
1919 flags: []string{
1920 "-false-start",
1921 "-advertise-alpn", "\x03foo",
1922 },
1923 shimWritesFirst: true,
1924 shouldFail: true,
1925 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1926 expectedLocalError: "tls: peer did not false start: EOF",
1927 },
1928 {
Adam Langley7c803a62015-06-15 15:35:05 -07001929 protocol: dtls,
1930 name: "SendSplitAlert-Sync",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SendSplitAlert: true,
1934 },
1935 },
1936 },
1937 {
1938 protocol: dtls,
1939 name: "SendSplitAlert-Async",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 SendSplitAlert: true,
1943 },
1944 },
1945 flags: []string{"-async"},
1946 },
1947 {
1948 protocol: dtls,
1949 name: "PackDTLSHandshake",
1950 config: Config{
1951 Bugs: ProtocolBugs{
1952 MaxHandshakeRecordLength: 2,
1953 PackHandshakeFragments: 20,
1954 PackHandshakeRecords: 200,
1955 },
1956 },
1957 },
1958 {
Adam Langley7c803a62015-06-15 15:35:05 -07001959 name: "SendEmptyRecords-Pass",
1960 sendEmptyRecords: 32,
1961 },
1962 {
1963 name: "SendEmptyRecords",
1964 sendEmptyRecords: 33,
1965 shouldFail: true,
1966 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1967 },
1968 {
1969 name: "SendEmptyRecords-Async",
1970 sendEmptyRecords: 33,
1971 flags: []string{"-async"},
1972 shouldFail: true,
1973 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1974 },
1975 {
David Benjamine8e84b92016-08-03 15:39:47 -04001976 name: "SendWarningAlerts-Pass",
1977 config: Config{
1978 MaxVersion: VersionTLS12,
1979 },
Adam Langley7c803a62015-06-15 15:35:05 -07001980 sendWarningAlerts: 4,
1981 },
1982 {
David Benjamine8e84b92016-08-03 15:39:47 -04001983 protocol: dtls,
1984 name: "SendWarningAlerts-DTLS-Pass",
1985 config: Config{
1986 MaxVersion: VersionTLS12,
1987 },
Adam Langley7c803a62015-06-15 15:35:05 -07001988 sendWarningAlerts: 4,
1989 },
1990 {
David Benjamine8e84b92016-08-03 15:39:47 -04001991 name: "SendWarningAlerts-TLS13",
1992 config: Config{
1993 MaxVersion: VersionTLS13,
1994 },
1995 sendWarningAlerts: 4,
1996 shouldFail: true,
1997 expectedError: ":BAD_ALERT:",
1998 expectedLocalError: "remote error: error decoding message",
1999 },
2000 {
2001 name: "SendWarningAlerts",
2002 config: Config{
2003 MaxVersion: VersionTLS12,
2004 },
Adam Langley7c803a62015-06-15 15:35:05 -07002005 sendWarningAlerts: 5,
2006 shouldFail: true,
2007 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2008 },
2009 {
David Benjamine8e84b92016-08-03 15:39:47 -04002010 name: "SendWarningAlerts-Async",
2011 config: Config{
2012 MaxVersion: VersionTLS12,
2013 },
Adam Langley7c803a62015-06-15 15:35:05 -07002014 sendWarningAlerts: 5,
2015 flags: []string{"-async"},
2016 shouldFail: true,
2017 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2018 },
David Benjaminba4594a2015-06-18 18:36:15 -04002019 {
Steven Valdez32635b82016-08-16 11:25:03 -04002020 name: "SendKeyUpdates",
2021 config: Config{
2022 MaxVersion: VersionTLS13,
2023 },
2024 sendKeyUpdates: 33,
2025 shouldFail: true,
2026 expectedError: ":TOO_MANY_KEY_UPDATES:",
2027 },
2028 {
David Benjaminba4594a2015-06-18 18:36:15 -04002029 name: "EmptySessionID",
2030 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002031 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002032 SessionTicketsDisabled: true,
2033 },
2034 noSessionCache: true,
2035 flags: []string{"-expect-no-session"},
2036 },
David Benjamin30789da2015-08-29 22:56:45 -04002037 {
2038 name: "Unclean-Shutdown",
2039 config: Config{
2040 Bugs: ProtocolBugs{
2041 NoCloseNotify: true,
2042 ExpectCloseNotify: true,
2043 },
2044 },
2045 shimShutsDown: true,
2046 flags: []string{"-check-close-notify"},
2047 shouldFail: true,
2048 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2049 },
2050 {
2051 name: "Unclean-Shutdown-Ignored",
2052 config: Config{
2053 Bugs: ProtocolBugs{
2054 NoCloseNotify: true,
2055 },
2056 },
2057 shimShutsDown: true,
2058 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002059 {
David Benjaminfa214e42016-05-10 17:03:10 -04002060 name: "Unclean-Shutdown-Alert",
2061 config: Config{
2062 Bugs: ProtocolBugs{
2063 SendAlertOnShutdown: alertDecompressionFailure,
2064 ExpectCloseNotify: true,
2065 },
2066 },
2067 shimShutsDown: true,
2068 flags: []string{"-check-close-notify"},
2069 shouldFail: true,
2070 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2071 },
2072 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002073 name: "LargePlaintext",
2074 config: Config{
2075 Bugs: ProtocolBugs{
2076 SendLargeRecords: true,
2077 },
2078 },
2079 messageLen: maxPlaintext + 1,
2080 shouldFail: true,
2081 expectedError: ":DATA_LENGTH_TOO_LONG:",
2082 },
2083 {
2084 protocol: dtls,
2085 name: "LargePlaintext-DTLS",
2086 config: Config{
2087 Bugs: ProtocolBugs{
2088 SendLargeRecords: true,
2089 },
2090 },
2091 messageLen: maxPlaintext + 1,
2092 shouldFail: true,
2093 expectedError: ":DATA_LENGTH_TOO_LONG:",
2094 },
2095 {
2096 name: "LargeCiphertext",
2097 config: Config{
2098 Bugs: ProtocolBugs{
2099 SendLargeRecords: true,
2100 },
2101 },
2102 messageLen: maxPlaintext * 2,
2103 shouldFail: true,
2104 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2105 },
2106 {
2107 protocol: dtls,
2108 name: "LargeCiphertext-DTLS",
2109 config: Config{
2110 Bugs: ProtocolBugs{
2111 SendLargeRecords: true,
2112 },
2113 },
2114 messageLen: maxPlaintext * 2,
2115 // Unlike the other four cases, DTLS drops records which
2116 // are invalid before authentication, so the connection
2117 // does not fail.
2118 expectMessageDropped: true,
2119 },
David Benjamindd6fed92015-10-23 17:41:12 -04002120 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002121 // In TLS 1.2 and below, empty NewSessionTicket messages
2122 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002123 name: "SendEmptySessionTicket",
2124 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002125 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002126 Bugs: ProtocolBugs{
2127 SendEmptySessionTicket: true,
2128 FailIfSessionOffered: true,
2129 },
2130 },
David Benjamin46662482016-08-17 00:51:00 -04002131 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002132 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002133 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002134 name: "BadHelloRequest-1",
2135 renegotiate: 1,
2136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002137 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002138 Bugs: ProtocolBugs{
2139 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2140 },
2141 },
2142 flags: []string{
2143 "-renegotiate-freely",
2144 "-expect-total-renegotiations", "1",
2145 },
2146 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002147 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002148 },
2149 {
2150 name: "BadHelloRequest-2",
2151 renegotiate: 1,
2152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002153 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002154 Bugs: ProtocolBugs{
2155 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2156 },
2157 },
2158 flags: []string{
2159 "-renegotiate-freely",
2160 "-expect-total-renegotiations", "1",
2161 },
2162 shouldFail: true,
2163 expectedError: ":BAD_HELLO_REQUEST:",
2164 },
David Benjaminef1b0092015-11-21 14:05:44 -05002165 {
2166 testType: serverTest,
2167 name: "SupportTicketsWithSessionID",
2168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002169 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002170 SessionTicketsDisabled: true,
2171 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002172 resumeConfig: &Config{
2173 MaxVersion: VersionTLS12,
2174 },
David Benjaminef1b0092015-11-21 14:05:44 -05002175 resumeSession: true,
2176 },
David Benjamin02edcd02016-07-27 17:40:37 -04002177 {
2178 protocol: dtls,
2179 name: "DTLS-SendExtraFinished",
2180 config: Config{
2181 Bugs: ProtocolBugs{
2182 SendExtraFinished: true,
2183 },
2184 },
2185 shouldFail: true,
2186 expectedError: ":UNEXPECTED_RECORD:",
2187 },
2188 {
2189 protocol: dtls,
2190 name: "DTLS-SendExtraFinished-Reordered",
2191 config: Config{
2192 Bugs: ProtocolBugs{
2193 MaxHandshakeRecordLength: 2,
2194 ReorderHandshakeFragments: true,
2195 SendExtraFinished: true,
2196 },
2197 },
2198 shouldFail: true,
2199 expectedError: ":UNEXPECTED_RECORD:",
2200 },
David Benjamine97fb482016-07-29 09:23:07 -04002201 {
2202 testType: serverTest,
2203 name: "V2ClientHello-EmptyRecordPrefix",
2204 config: Config{
2205 // Choose a cipher suite that does not involve
2206 // elliptic curves, so no extensions are
2207 // involved.
2208 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002209 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002210 Bugs: ProtocolBugs{
2211 SendV2ClientHello: true,
2212 },
2213 },
2214 sendPrefix: string([]byte{
2215 byte(recordTypeHandshake),
2216 3, 1, // version
2217 0, 0, // length
2218 }),
2219 // A no-op empty record may not be sent before V2ClientHello.
2220 shouldFail: true,
2221 expectedError: ":WRONG_VERSION_NUMBER:",
2222 },
2223 {
2224 testType: serverTest,
2225 name: "V2ClientHello-WarningAlertPrefix",
2226 config: Config{
2227 // Choose a cipher suite that does not involve
2228 // elliptic curves, so no extensions are
2229 // involved.
2230 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002231 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002232 Bugs: ProtocolBugs{
2233 SendV2ClientHello: true,
2234 },
2235 },
2236 sendPrefix: string([]byte{
2237 byte(recordTypeAlert),
2238 3, 1, // version
2239 0, 2, // length
2240 alertLevelWarning, byte(alertDecompressionFailure),
2241 }),
2242 // A no-op warning alert may not be sent before V2ClientHello.
2243 shouldFail: true,
2244 expectedError: ":WRONG_VERSION_NUMBER:",
2245 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002246 {
2247 testType: clientTest,
2248 name: "KeyUpdate",
2249 config: Config{
2250 MaxVersion: VersionTLS13,
2251 Bugs: ProtocolBugs{
2252 SendKeyUpdateBeforeEveryAppDataRecord: true,
2253 },
2254 },
2255 },
David Benjaminabe94e32016-09-04 14:18:58 -04002256 {
2257 name: "SendSNIWarningAlert",
2258 config: Config{
2259 MaxVersion: VersionTLS12,
2260 Bugs: ProtocolBugs{
2261 SendSNIWarningAlert: true,
2262 },
2263 },
2264 },
David Benjaminc241d792016-09-09 10:34:20 -04002265 {
2266 testType: serverTest,
2267 name: "ExtraCompressionMethods-TLS12",
2268 config: Config{
2269 MaxVersion: VersionTLS12,
2270 Bugs: ProtocolBugs{
2271 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2272 },
2273 },
2274 },
2275 {
2276 testType: serverTest,
2277 name: "ExtraCompressionMethods-TLS13",
2278 config: Config{
2279 MaxVersion: VersionTLS13,
2280 Bugs: ProtocolBugs{
2281 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2282 },
2283 },
2284 shouldFail: true,
2285 expectedError: ":INVALID_COMPRESSION_LIST:",
2286 expectedLocalError: "remote error: illegal parameter",
2287 },
2288 {
2289 testType: serverTest,
2290 name: "NoNullCompression-TLS12",
2291 config: Config{
2292 MaxVersion: VersionTLS12,
2293 Bugs: ProtocolBugs{
2294 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2295 },
2296 },
2297 shouldFail: true,
2298 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2299 expectedLocalError: "remote error: illegal parameter",
2300 },
2301 {
2302 testType: serverTest,
2303 name: "NoNullCompression-TLS13",
2304 config: Config{
2305 MaxVersion: VersionTLS13,
2306 Bugs: ProtocolBugs{
2307 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2308 },
2309 },
2310 shouldFail: true,
2311 expectedError: ":INVALID_COMPRESSION_LIST:",
2312 expectedLocalError: "remote error: illegal parameter",
2313 },
David Benjamin65ac9972016-09-02 21:35:25 -04002314 {
2315 name: "GREASE-TLS12",
2316 config: Config{
2317 MaxVersion: VersionTLS12,
2318 Bugs: ProtocolBugs{
2319 ExpectGREASE: true,
2320 },
2321 },
2322 flags: []string{"-enable-grease"},
2323 },
2324 {
2325 name: "GREASE-TLS13",
2326 config: Config{
2327 MaxVersion: VersionTLS13,
2328 Bugs: ProtocolBugs{
2329 ExpectGREASE: true,
2330 },
2331 },
2332 flags: []string{"-enable-grease"},
2333 },
Adam Langley7c803a62015-06-15 15:35:05 -07002334 }
Adam Langley7c803a62015-06-15 15:35:05 -07002335 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002336
2337 // Test that very large messages can be received.
2338 cert := rsaCertificate
2339 for i := 0; i < 50; i++ {
2340 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2341 }
2342 testCases = append(testCases, testCase{
2343 name: "LargeMessage",
2344 config: Config{
2345 Certificates: []Certificate{cert},
2346 },
2347 })
2348 testCases = append(testCases, testCase{
2349 protocol: dtls,
2350 name: "LargeMessage-DTLS",
2351 config: Config{
2352 Certificates: []Certificate{cert},
2353 },
2354 })
2355
2356 // They are rejected if the maximum certificate chain length is capped.
2357 testCases = append(testCases, testCase{
2358 name: "LargeMessage-Reject",
2359 config: Config{
2360 Certificates: []Certificate{cert},
2361 },
2362 flags: []string{"-max-cert-list", "16384"},
2363 shouldFail: true,
2364 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2365 })
2366 testCases = append(testCases, testCase{
2367 protocol: dtls,
2368 name: "LargeMessage-Reject-DTLS",
2369 config: Config{
2370 Certificates: []Certificate{cert},
2371 },
2372 flags: []string{"-max-cert-list", "16384"},
2373 shouldFail: true,
2374 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2375 })
Adam Langley7c803a62015-06-15 15:35:05 -07002376}
2377
Adam Langley95c29f32014-06-20 12:00:00 -07002378func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002379 const bogusCipher = 0xfe00
2380
Adam Langley95c29f32014-06-20 12:00:00 -07002381 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002382 const psk = "12345"
2383 const pskIdentity = "luggage combo"
2384
Adam Langley95c29f32014-06-20 12:00:00 -07002385 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002386 var certFile string
2387 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002388 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002389 cert = ecdsaP256Certificate
2390 certFile = ecdsaP256CertificateFile
2391 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002392 } else {
David Benjamin33863262016-07-08 17:20:12 -07002393 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002394 certFile = rsaCertificateFile
2395 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002396 }
2397
David Benjamin48cae082014-10-27 01:06:24 -04002398 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002399 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002400 flags = append(flags,
2401 "-psk", psk,
2402 "-psk-identity", pskIdentity)
2403 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002404 if hasComponent(suite.name, "NULL") {
2405 // NULL ciphers must be explicitly enabled.
2406 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2407 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002408 if hasComponent(suite.name, "CECPQ1") {
2409 // CECPQ1 ciphers must be explicitly enabled.
2410 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2411 }
David Benjamin881f1962016-08-10 18:29:12 -04002412 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2413 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2414 // for now.
2415 flags = append(flags, "-cipher", suite.name)
2416 }
David Benjamin48cae082014-10-27 01:06:24 -04002417
Adam Langley95c29f32014-06-20 12:00:00 -07002418 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002419 for _, protocol := range []protocol{tls, dtls} {
2420 var prefix string
2421 if protocol == dtls {
2422 if !ver.hasDTLS {
2423 continue
2424 }
2425 prefix = "D"
2426 }
Adam Langley95c29f32014-06-20 12:00:00 -07002427
David Benjamin0407e762016-06-17 16:41:18 -04002428 var shouldServerFail, shouldClientFail bool
2429 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2430 // BoringSSL clients accept ECDHE on SSLv3, but
2431 // a BoringSSL server will never select it
2432 // because the extension is missing.
2433 shouldServerFail = true
2434 }
2435 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2436 shouldClientFail = true
2437 shouldServerFail = true
2438 }
David Benjamin54c217c2016-07-13 12:35:25 -04002439 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002440 shouldClientFail = true
2441 shouldServerFail = true
2442 }
David Benjamin0407e762016-06-17 16:41:18 -04002443 if !isDTLSCipher(suite.name) && protocol == dtls {
2444 shouldClientFail = true
2445 shouldServerFail = true
2446 }
David Benjamin4298d772015-12-19 00:18:25 -05002447
David Benjamin0407e762016-06-17 16:41:18 -04002448 var expectedServerError, expectedClientError string
2449 if shouldServerFail {
2450 expectedServerError = ":NO_SHARED_CIPHER:"
2451 }
2452 if shouldClientFail {
2453 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2454 }
David Benjamin025b3d32014-07-01 19:53:04 -04002455
David Benjamin6fd297b2014-08-11 18:43:38 -04002456 testCases = append(testCases, testCase{
2457 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002458 protocol: protocol,
2459
2460 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002461 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002462 MinVersion: ver.version,
2463 MaxVersion: ver.version,
2464 CipherSuites: []uint16{suite.id},
2465 Certificates: []Certificate{cert},
2466 PreSharedKey: []byte(psk),
2467 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002468 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002469 EnableAllCiphers: shouldServerFail,
2470 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002471 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002472 },
2473 certFile: certFile,
2474 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002475 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002476 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002477 shouldFail: shouldServerFail,
2478 expectedError: expectedServerError,
2479 })
2480
2481 testCases = append(testCases, testCase{
2482 testType: clientTest,
2483 protocol: protocol,
2484 name: prefix + ver.name + "-" + suite.name + "-client",
2485 config: Config{
2486 MinVersion: ver.version,
2487 MaxVersion: ver.version,
2488 CipherSuites: []uint16{suite.id},
2489 Certificates: []Certificate{cert},
2490 PreSharedKey: []byte(psk),
2491 PreSharedKeyIdentity: pskIdentity,
2492 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002493 EnableAllCiphers: shouldClientFail,
2494 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002495 },
2496 },
2497 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002498 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002499 shouldFail: shouldClientFail,
2500 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002501 })
David Benjamin2c99d282015-09-01 10:23:00 -04002502
Nick Harper1fd39d82016-06-14 18:14:35 -07002503 if !shouldClientFail {
2504 // Ensure the maximum record size is accepted.
2505 testCases = append(testCases, testCase{
2506 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2507 config: Config{
2508 MinVersion: ver.version,
2509 MaxVersion: ver.version,
2510 CipherSuites: []uint16{suite.id},
2511 Certificates: []Certificate{cert},
2512 PreSharedKey: []byte(psk),
2513 PreSharedKeyIdentity: pskIdentity,
2514 },
2515 flags: flags,
2516 messageLen: maxPlaintext,
2517 })
2518 }
2519 }
David Benjamin2c99d282015-09-01 10:23:00 -04002520 }
Adam Langley95c29f32014-06-20 12:00:00 -07002521 }
Adam Langleya7997f12015-05-14 17:38:50 -07002522
2523 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002524 name: "NoSharedCipher",
2525 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002526 MaxVersion: VersionTLS12,
2527 CipherSuites: []uint16{},
2528 },
2529 shouldFail: true,
2530 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2531 })
2532
2533 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002534 name: "NoSharedCipher-TLS13",
2535 config: Config{
2536 MaxVersion: VersionTLS13,
2537 CipherSuites: []uint16{},
2538 },
2539 shouldFail: true,
2540 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2541 })
2542
2543 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002544 name: "UnsupportedCipherSuite",
2545 config: Config{
2546 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002547 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002548 Bugs: ProtocolBugs{
2549 IgnorePeerCipherPreferences: true,
2550 },
2551 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002552 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002553 shouldFail: true,
2554 expectedError: ":WRONG_CIPHER_RETURNED:",
2555 })
2556
2557 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002558 name: "ServerHelloBogusCipher",
2559 config: Config{
2560 MaxVersion: VersionTLS12,
2561 Bugs: ProtocolBugs{
2562 SendCipherSuite: bogusCipher,
2563 },
2564 },
2565 shouldFail: true,
2566 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2567 })
2568 testCases = append(testCases, testCase{
2569 name: "ServerHelloBogusCipher-TLS13",
2570 config: Config{
2571 MaxVersion: VersionTLS13,
2572 Bugs: ProtocolBugs{
2573 SendCipherSuite: bogusCipher,
2574 },
2575 },
2576 shouldFail: true,
2577 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2578 })
2579
2580 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002581 name: "WeakDH",
2582 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002583 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002584 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2585 Bugs: ProtocolBugs{
2586 // This is a 1023-bit prime number, generated
2587 // with:
2588 // openssl gendh 1023 | openssl asn1parse -i
2589 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2590 },
2591 },
2592 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002593 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002594 })
Adam Langleycef75832015-09-03 14:51:12 -07002595
David Benjamincd24a392015-11-11 13:23:05 -08002596 testCases = append(testCases, testCase{
2597 name: "SillyDH",
2598 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002599 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002600 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2601 Bugs: ProtocolBugs{
2602 // This is a 4097-bit prime number, generated
2603 // with:
2604 // openssl gendh 4097 | openssl asn1parse -i
2605 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2606 },
2607 },
2608 shouldFail: true,
2609 expectedError: ":DH_P_TOO_LONG:",
2610 })
2611
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002612 // This test ensures that Diffie-Hellman public values are padded with
2613 // zeros so that they're the same length as the prime. This is to avoid
2614 // hitting a bug in yaSSL.
2615 testCases = append(testCases, testCase{
2616 testType: serverTest,
2617 name: "DHPublicValuePadded",
2618 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002619 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002620 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2621 Bugs: ProtocolBugs{
2622 RequireDHPublicValueLen: (1025 + 7) / 8,
2623 },
2624 },
2625 flags: []string{"-use-sparse-dh-prime"},
2626 })
David Benjamincd24a392015-11-11 13:23:05 -08002627
David Benjamin241ae832016-01-15 03:04:54 -05002628 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002629 testCases = append(testCases, testCase{
2630 testType: serverTest,
2631 name: "UnknownCipher",
2632 config: Config{
2633 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2634 },
2635 })
2636
David Benjamin78679342016-09-16 19:42:05 -04002637 // Test empty ECDHE_PSK identity hints work as expected.
2638 testCases = append(testCases, testCase{
2639 name: "EmptyECDHEPSKHint",
2640 config: Config{
2641 MaxVersion: VersionTLS12,
2642 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2643 PreSharedKey: []byte("secret"),
2644 },
2645 flags: []string{"-psk", "secret"},
2646 })
2647
2648 // Test empty PSK identity hints work as expected, even if an explicit
2649 // ServerKeyExchange is sent.
2650 testCases = append(testCases, testCase{
2651 name: "ExplicitEmptyPSKHint",
2652 config: Config{
2653 MaxVersion: VersionTLS12,
2654 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2655 PreSharedKey: []byte("secret"),
2656 Bugs: ProtocolBugs{
2657 AlwaysSendPreSharedKeyIdentityHint: true,
2658 },
2659 },
2660 flags: []string{"-psk", "secret"},
2661 })
2662
Adam Langleycef75832015-09-03 14:51:12 -07002663 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2664 // 1.1 specific cipher suite settings. A server is setup with the given
2665 // cipher lists and then a connection is made for each member of
2666 // expectations. The cipher suite that the server selects must match
2667 // the specified one.
2668 var versionSpecificCiphersTest = []struct {
2669 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2670 // expectations is a map from TLS version to cipher suite id.
2671 expectations map[uint16]uint16
2672 }{
2673 {
2674 // Test that the null case (where no version-specific ciphers are set)
2675 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002676 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2677 "", // no ciphers specifically for TLS ≥ 1.0
2678 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002679 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002680 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2681 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2682 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2683 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002684 },
2685 },
2686 {
2687 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2688 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002689 "DES-CBC3-SHA:AES128-SHA", // default
2690 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2691 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002692 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002693 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002694 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2695 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2696 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2697 },
2698 },
2699 {
2700 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2701 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002702 "DES-CBC3-SHA:AES128-SHA", // default
2703 "", // no ciphers specifically for TLS ≥ 1.0
2704 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002705 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002706 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2707 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002708 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2709 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2710 },
2711 },
2712 {
2713 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2714 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002715 "DES-CBC3-SHA:AES128-SHA", // default
2716 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2717 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002718 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002719 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002720 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2721 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2722 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2723 },
2724 },
2725 }
2726
2727 for i, test := range versionSpecificCiphersTest {
2728 for version, expectedCipherSuite := range test.expectations {
2729 flags := []string{"-cipher", test.ciphersDefault}
2730 if len(test.ciphersTLS10) > 0 {
2731 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2732 }
2733 if len(test.ciphersTLS11) > 0 {
2734 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2735 }
2736
2737 testCases = append(testCases, testCase{
2738 testType: serverTest,
2739 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2740 config: Config{
2741 MaxVersion: version,
2742 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002743 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 -07002744 },
2745 flags: flags,
2746 expectedCipher: expectedCipherSuite,
2747 })
2748 }
2749 }
Adam Langley95c29f32014-06-20 12:00:00 -07002750}
2751
2752func addBadECDSASignatureTests() {
2753 for badR := BadValue(1); badR < NumBadValues; badR++ {
2754 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002755 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002756 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2757 config: Config{
2758 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002759 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002760 Bugs: ProtocolBugs{
2761 BadECDSAR: badR,
2762 BadECDSAS: badS,
2763 },
2764 },
2765 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002766 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002767 })
2768 }
2769 }
2770}
2771
Adam Langley80842bd2014-06-20 12:00:00 -07002772func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002773 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002774 name: "MaxCBCPadding",
2775 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002776 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002777 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2778 Bugs: ProtocolBugs{
2779 MaxPadding: true,
2780 },
2781 },
2782 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2783 })
David Benjamin025b3d32014-07-01 19:53:04 -04002784 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002785 name: "BadCBCPadding",
2786 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002787 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002788 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2789 Bugs: ProtocolBugs{
2790 PaddingFirstByteBad: true,
2791 },
2792 },
2793 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002794 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002795 })
2796 // OpenSSL previously had an issue where the first byte of padding in
2797 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002798 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002799 name: "BadCBCPadding255",
2800 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002801 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002802 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2803 Bugs: ProtocolBugs{
2804 MaxPadding: true,
2805 PaddingFirstByteBadIf255: true,
2806 },
2807 },
2808 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2809 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002810 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002811 })
2812}
2813
Kenny Root7fdeaf12014-08-05 15:23:37 -07002814func addCBCSplittingTests() {
2815 testCases = append(testCases, testCase{
2816 name: "CBCRecordSplitting",
2817 config: Config{
2818 MaxVersion: VersionTLS10,
2819 MinVersion: VersionTLS10,
2820 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2821 },
David Benjaminac8302a2015-09-01 17:18:15 -04002822 messageLen: -1, // read until EOF
2823 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002824 flags: []string{
2825 "-async",
2826 "-write-different-record-sizes",
2827 "-cbc-record-splitting",
2828 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002829 })
2830 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002831 name: "CBCRecordSplittingPartialWrite",
2832 config: Config{
2833 MaxVersion: VersionTLS10,
2834 MinVersion: VersionTLS10,
2835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2836 },
2837 messageLen: -1, // read until EOF
2838 flags: []string{
2839 "-async",
2840 "-write-different-record-sizes",
2841 "-cbc-record-splitting",
2842 "-partial-write",
2843 },
2844 })
2845}
2846
David Benjamin636293b2014-07-08 17:59:18 -04002847func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002848 // Add a dummy cert pool to stress certificate authority parsing.
2849 // TODO(davidben): Add tests that those values parse out correctly.
2850 certPool := x509.NewCertPool()
2851 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2852 if err != nil {
2853 panic(err)
2854 }
2855 certPool.AddCert(cert)
2856
David Benjamin636293b2014-07-08 17:59:18 -04002857 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002858 testCases = append(testCases, testCase{
2859 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002860 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002861 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002862 MinVersion: ver.version,
2863 MaxVersion: ver.version,
2864 ClientAuth: RequireAnyClientCert,
2865 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002866 },
2867 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002868 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2869 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002870 },
2871 })
2872 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002873 testType: serverTest,
2874 name: ver.name + "-Server-ClientAuth-RSA",
2875 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002876 MinVersion: ver.version,
2877 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002878 Certificates: []Certificate{rsaCertificate},
2879 },
2880 flags: []string{"-require-any-client-certificate"},
2881 })
David Benjamine098ec22014-08-27 23:13:20 -04002882 if ver.version != VersionSSL30 {
2883 testCases = append(testCases, testCase{
2884 testType: serverTest,
2885 name: ver.name + "-Server-ClientAuth-ECDSA",
2886 config: Config{
2887 MinVersion: ver.version,
2888 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002889 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002890 },
2891 flags: []string{"-require-any-client-certificate"},
2892 })
2893 testCases = append(testCases, testCase{
2894 testType: clientTest,
2895 name: ver.name + "-Client-ClientAuth-ECDSA",
2896 config: Config{
2897 MinVersion: ver.version,
2898 MaxVersion: ver.version,
2899 ClientAuth: RequireAnyClientCert,
2900 ClientCAs: certPool,
2901 },
2902 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002903 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2904 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002905 },
2906 })
2907 }
Adam Langley37646832016-08-01 16:16:46 -07002908
2909 testCases = append(testCases, testCase{
2910 name: "NoClientCertificate-" + ver.name,
2911 config: Config{
2912 MinVersion: ver.version,
2913 MaxVersion: ver.version,
2914 ClientAuth: RequireAnyClientCert,
2915 },
2916 shouldFail: true,
2917 expectedLocalError: "client didn't provide a certificate",
2918 })
2919
2920 testCases = append(testCases, testCase{
2921 // Even if not configured to expect a certificate, OpenSSL will
2922 // return X509_V_OK as the verify_result.
2923 testType: serverTest,
2924 name: "NoClientCertificateRequested-Server-" + ver.name,
2925 config: Config{
2926 MinVersion: ver.version,
2927 MaxVersion: ver.version,
2928 },
2929 flags: []string{
2930 "-expect-verify-result",
2931 },
2932 // TODO(davidben): Switch this to true when TLS 1.3
2933 // supports session resumption.
2934 resumeSession: ver.version < VersionTLS13,
2935 })
2936
2937 testCases = append(testCases, testCase{
2938 // If a client certificate is not provided, OpenSSL will still
2939 // return X509_V_OK as the verify_result.
2940 testType: serverTest,
2941 name: "NoClientCertificate-Server-" + ver.name,
2942 config: Config{
2943 MinVersion: ver.version,
2944 MaxVersion: ver.version,
2945 },
2946 flags: []string{
2947 "-expect-verify-result",
2948 "-verify-peer",
2949 },
2950 // TODO(davidben): Switch this to true when TLS 1.3
2951 // supports session resumption.
2952 resumeSession: ver.version < VersionTLS13,
2953 })
2954
2955 testCases = append(testCases, testCase{
2956 testType: serverTest,
2957 name: "RequireAnyClientCertificate-" + ver.name,
2958 config: Config{
2959 MinVersion: ver.version,
2960 MaxVersion: ver.version,
2961 },
2962 flags: []string{"-require-any-client-certificate"},
2963 shouldFail: true,
2964 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2965 })
2966
2967 if ver.version != VersionSSL30 {
2968 testCases = append(testCases, testCase{
2969 testType: serverTest,
2970 name: "SkipClientCertificate-" + ver.name,
2971 config: Config{
2972 MinVersion: ver.version,
2973 MaxVersion: ver.version,
2974 Bugs: ProtocolBugs{
2975 SkipClientCertificate: true,
2976 },
2977 },
2978 // Setting SSL_VERIFY_PEER allows anonymous clients.
2979 flags: []string{"-verify-peer"},
2980 shouldFail: true,
2981 expectedError: ":UNEXPECTED_MESSAGE:",
2982 })
2983 }
David Benjamin636293b2014-07-08 17:59:18 -04002984 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002985
David Benjaminc032dfa2016-05-12 14:54:57 -04002986 // Client auth is only legal in certificate-based ciphers.
2987 testCases = append(testCases, testCase{
2988 testType: clientTest,
2989 name: "ClientAuth-PSK",
2990 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002991 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002992 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2993 PreSharedKey: []byte("secret"),
2994 ClientAuth: RequireAnyClientCert,
2995 },
2996 flags: []string{
2997 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2998 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2999 "-psk", "secret",
3000 },
3001 shouldFail: true,
3002 expectedError: ":UNEXPECTED_MESSAGE:",
3003 })
3004 testCases = append(testCases, testCase{
3005 testType: clientTest,
3006 name: "ClientAuth-ECDHE_PSK",
3007 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003008 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003009 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3010 PreSharedKey: []byte("secret"),
3011 ClientAuth: RequireAnyClientCert,
3012 },
3013 flags: []string{
3014 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3015 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3016 "-psk", "secret",
3017 },
3018 shouldFail: true,
3019 expectedError: ":UNEXPECTED_MESSAGE:",
3020 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003021
3022 // Regression test for a bug where the client CA list, if explicitly
3023 // set to NULL, was mis-encoded.
3024 testCases = append(testCases, testCase{
3025 testType: serverTest,
3026 name: "Null-Client-CA-List",
3027 config: Config{
3028 MaxVersion: VersionTLS12,
3029 Certificates: []Certificate{rsaCertificate},
3030 },
3031 flags: []string{
3032 "-require-any-client-certificate",
3033 "-use-null-client-ca-list",
3034 },
3035 })
David Benjamin636293b2014-07-08 17:59:18 -04003036}
3037
Adam Langley75712922014-10-10 16:23:43 -07003038func addExtendedMasterSecretTests() {
3039 const expectEMSFlag = "-expect-extended-master-secret"
3040
3041 for _, with := range []bool{false, true} {
3042 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003043 if with {
3044 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003045 }
3046
3047 for _, isClient := range []bool{false, true} {
3048 suffix := "-Server"
3049 testType := serverTest
3050 if isClient {
3051 suffix = "-Client"
3052 testType = clientTest
3053 }
3054
3055 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003056 // In TLS 1.3, the extension is irrelevant and
3057 // always reports as enabled.
3058 var flags []string
3059 if with || ver.version >= VersionTLS13 {
3060 flags = []string{expectEMSFlag}
3061 }
3062
Adam Langley75712922014-10-10 16:23:43 -07003063 test := testCase{
3064 testType: testType,
3065 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3066 config: Config{
3067 MinVersion: ver.version,
3068 MaxVersion: ver.version,
3069 Bugs: ProtocolBugs{
3070 NoExtendedMasterSecret: !with,
3071 RequireExtendedMasterSecret: with,
3072 },
3073 },
David Benjamin48cae082014-10-27 01:06:24 -04003074 flags: flags,
3075 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003076 }
3077 if test.shouldFail {
3078 test.expectedLocalError = "extended master secret required but not supported by peer"
3079 }
3080 testCases = append(testCases, test)
3081 }
3082 }
3083 }
3084
Adam Langleyba5934b2015-06-02 10:50:35 -07003085 for _, isClient := range []bool{false, true} {
3086 for _, supportedInFirstConnection := range []bool{false, true} {
3087 for _, supportedInResumeConnection := range []bool{false, true} {
3088 boolToWord := func(b bool) string {
3089 if b {
3090 return "Yes"
3091 }
3092 return "No"
3093 }
3094 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3095 if isClient {
3096 suffix += "Client"
3097 } else {
3098 suffix += "Server"
3099 }
3100
3101 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003102 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003103 Bugs: ProtocolBugs{
3104 RequireExtendedMasterSecret: true,
3105 },
3106 }
3107
3108 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003109 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003110 Bugs: ProtocolBugs{
3111 NoExtendedMasterSecret: true,
3112 },
3113 }
3114
3115 test := testCase{
3116 name: "ExtendedMasterSecret-" + suffix,
3117 resumeSession: true,
3118 }
3119
3120 if !isClient {
3121 test.testType = serverTest
3122 }
3123
3124 if supportedInFirstConnection {
3125 test.config = supportedConfig
3126 } else {
3127 test.config = noSupportConfig
3128 }
3129
3130 if supportedInResumeConnection {
3131 test.resumeConfig = &supportedConfig
3132 } else {
3133 test.resumeConfig = &noSupportConfig
3134 }
3135
3136 switch suffix {
3137 case "YesToYes-Client", "YesToYes-Server":
3138 // When a session is resumed, it should
3139 // still be aware that its master
3140 // secret was generated via EMS and
3141 // thus it's safe to use tls-unique.
3142 test.flags = []string{expectEMSFlag}
3143 case "NoToYes-Server":
3144 // If an original connection did not
3145 // contain EMS, but a resumption
3146 // handshake does, then a server should
3147 // not resume the session.
3148 test.expectResumeRejected = true
3149 case "YesToNo-Server":
3150 // Resuming an EMS session without the
3151 // EMS extension should cause the
3152 // server to abort the connection.
3153 test.shouldFail = true
3154 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3155 case "NoToYes-Client":
3156 // A client should abort a connection
3157 // where the server resumed a non-EMS
3158 // session but echoed the EMS
3159 // extension.
3160 test.shouldFail = true
3161 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3162 case "YesToNo-Client":
3163 // A client should abort a connection
3164 // where the server didn't echo EMS
3165 // when the session used it.
3166 test.shouldFail = true
3167 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3168 }
3169
3170 testCases = append(testCases, test)
3171 }
3172 }
3173 }
David Benjamin163c9562016-08-29 23:14:17 -04003174
3175 // Switching EMS on renegotiation is forbidden.
3176 testCases = append(testCases, testCase{
3177 name: "ExtendedMasterSecret-Renego-NoEMS",
3178 config: Config{
3179 MaxVersion: VersionTLS12,
3180 Bugs: ProtocolBugs{
3181 NoExtendedMasterSecret: true,
3182 NoExtendedMasterSecretOnRenegotiation: true,
3183 },
3184 },
3185 renegotiate: 1,
3186 flags: []string{
3187 "-renegotiate-freely",
3188 "-expect-total-renegotiations", "1",
3189 },
3190 })
3191
3192 testCases = append(testCases, testCase{
3193 name: "ExtendedMasterSecret-Renego-Upgrade",
3194 config: Config{
3195 MaxVersion: VersionTLS12,
3196 Bugs: ProtocolBugs{
3197 NoExtendedMasterSecret: true,
3198 },
3199 },
3200 renegotiate: 1,
3201 flags: []string{
3202 "-renegotiate-freely",
3203 "-expect-total-renegotiations", "1",
3204 },
3205 shouldFail: true,
3206 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3207 })
3208
3209 testCases = append(testCases, testCase{
3210 name: "ExtendedMasterSecret-Renego-Downgrade",
3211 config: Config{
3212 MaxVersion: VersionTLS12,
3213 Bugs: ProtocolBugs{
3214 NoExtendedMasterSecretOnRenegotiation: true,
3215 },
3216 },
3217 renegotiate: 1,
3218 flags: []string{
3219 "-renegotiate-freely",
3220 "-expect-total-renegotiations", "1",
3221 },
3222 shouldFail: true,
3223 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3224 })
Adam Langley75712922014-10-10 16:23:43 -07003225}
3226
David Benjamin582ba042016-07-07 12:33:25 -07003227type stateMachineTestConfig struct {
3228 protocol protocol
3229 async bool
3230 splitHandshake, packHandshakeFlight bool
3231}
3232
David Benjamin43ec06f2014-08-05 02:28:57 -04003233// Adds tests that try to cover the range of the handshake state machine, under
3234// various conditions. Some of these are redundant with other tests, but they
3235// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003236func addAllStateMachineCoverageTests() {
3237 for _, async := range []bool{false, true} {
3238 for _, protocol := range []protocol{tls, dtls} {
3239 addStateMachineCoverageTests(stateMachineTestConfig{
3240 protocol: protocol,
3241 async: async,
3242 })
3243 addStateMachineCoverageTests(stateMachineTestConfig{
3244 protocol: protocol,
3245 async: async,
3246 splitHandshake: true,
3247 })
3248 if protocol == tls {
3249 addStateMachineCoverageTests(stateMachineTestConfig{
3250 protocol: protocol,
3251 async: async,
3252 packHandshakeFlight: true,
3253 })
3254 }
3255 }
3256 }
3257}
3258
3259func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003260 var tests []testCase
3261
3262 // Basic handshake, with resumption. Client and server,
3263 // session ID and session ticket.
3264 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003265 name: "Basic-Client",
3266 config: Config{
3267 MaxVersion: VersionTLS12,
3268 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003269 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003270 // Ensure session tickets are used, not session IDs.
3271 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003272 })
3273 tests = append(tests, testCase{
3274 name: "Basic-Client-RenewTicket",
3275 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003276 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 Bugs: ProtocolBugs{
3278 RenewTicketOnResume: true,
3279 },
3280 },
David Benjamin46662482016-08-17 00:51:00 -04003281 flags: []string{"-expect-ticket-renewal"},
3282 resumeSession: true,
3283 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003284 })
3285 tests = append(tests, testCase{
3286 name: "Basic-Client-NoTicket",
3287 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003288 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003289 SessionTicketsDisabled: true,
3290 },
3291 resumeSession: true,
3292 })
3293 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003294 name: "Basic-Client-Implicit",
3295 config: Config{
3296 MaxVersion: VersionTLS12,
3297 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003298 flags: []string{"-implicit-handshake"},
3299 resumeSession: true,
3300 })
3301 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003302 testType: serverTest,
3303 name: "Basic-Server",
3304 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003305 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003306 Bugs: ProtocolBugs{
3307 RequireSessionTickets: true,
3308 },
3309 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003310 resumeSession: true,
3311 })
3312 tests = append(tests, testCase{
3313 testType: serverTest,
3314 name: "Basic-Server-NoTickets",
3315 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003316 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003317 SessionTicketsDisabled: true,
3318 },
3319 resumeSession: true,
3320 })
3321 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003322 testType: serverTest,
3323 name: "Basic-Server-Implicit",
3324 config: Config{
3325 MaxVersion: VersionTLS12,
3326 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003327 flags: []string{"-implicit-handshake"},
3328 resumeSession: true,
3329 })
3330 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003331 testType: serverTest,
3332 name: "Basic-Server-EarlyCallback",
3333 config: Config{
3334 MaxVersion: VersionTLS12,
3335 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 flags: []string{"-use-early-callback"},
3337 resumeSession: true,
3338 })
3339
Steven Valdez143e8b32016-07-11 13:19:03 -04003340 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003341 if config.protocol == tls {
3342 tests = append(tests, testCase{
3343 name: "TLS13-1RTT-Client",
3344 config: Config{
3345 MaxVersion: VersionTLS13,
3346 MinVersion: VersionTLS13,
3347 },
David Benjamin46662482016-08-17 00:51:00 -04003348 resumeSession: true,
3349 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003350 })
3351
3352 tests = append(tests, testCase{
3353 testType: serverTest,
3354 name: "TLS13-1RTT-Server",
3355 config: Config{
3356 MaxVersion: VersionTLS13,
3357 MinVersion: VersionTLS13,
3358 },
David Benjamin46662482016-08-17 00:51:00 -04003359 resumeSession: true,
3360 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003361 })
3362
3363 tests = append(tests, testCase{
3364 name: "TLS13-HelloRetryRequest-Client",
3365 config: Config{
3366 MaxVersion: VersionTLS13,
3367 MinVersion: VersionTLS13,
3368 // P-384 requires a HelloRetryRequest against
3369 // BoringSSL's default configuration. Assert
3370 // that we do indeed test this with
3371 // ExpectMissingKeyShare.
3372 CurvePreferences: []CurveID{CurveP384},
3373 Bugs: ProtocolBugs{
3374 ExpectMissingKeyShare: true,
3375 },
3376 },
3377 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3378 resumeSession: true,
3379 })
3380
3381 tests = append(tests, testCase{
3382 testType: serverTest,
3383 name: "TLS13-HelloRetryRequest-Server",
3384 config: Config{
3385 MaxVersion: VersionTLS13,
3386 MinVersion: VersionTLS13,
3387 // Require a HelloRetryRequest for every curve.
3388 DefaultCurves: []CurveID{},
3389 },
3390 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3391 resumeSession: true,
3392 })
3393 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003394
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 // TLS client auth.
3396 tests = append(tests, testCase{
3397 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003398 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003399 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003400 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003401 ClientAuth: RequestClientCert,
3402 },
3403 })
3404 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003405 testType: serverTest,
3406 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003407 config: Config{
3408 MaxVersion: VersionTLS12,
3409 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003410 // Setting SSL_VERIFY_PEER allows anonymous clients.
3411 flags: []string{"-verify-peer"},
3412 })
David Benjamin582ba042016-07-07 12:33:25 -07003413 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003414 tests = append(tests, testCase{
3415 testType: clientTest,
3416 name: "ClientAuth-NoCertificate-Client-SSL3",
3417 config: Config{
3418 MaxVersion: VersionSSL30,
3419 ClientAuth: RequestClientCert,
3420 },
3421 })
3422 tests = append(tests, testCase{
3423 testType: serverTest,
3424 name: "ClientAuth-NoCertificate-Server-SSL3",
3425 config: Config{
3426 MaxVersion: VersionSSL30,
3427 },
3428 // Setting SSL_VERIFY_PEER allows anonymous clients.
3429 flags: []string{"-verify-peer"},
3430 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003431 tests = append(tests, testCase{
3432 testType: clientTest,
3433 name: "ClientAuth-NoCertificate-Client-TLS13",
3434 config: Config{
3435 MaxVersion: VersionTLS13,
3436 ClientAuth: RequestClientCert,
3437 },
3438 })
3439 tests = append(tests, testCase{
3440 testType: serverTest,
3441 name: "ClientAuth-NoCertificate-Server-TLS13",
3442 config: Config{
3443 MaxVersion: VersionTLS13,
3444 },
3445 // Setting SSL_VERIFY_PEER allows anonymous clients.
3446 flags: []string{"-verify-peer"},
3447 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003448 }
3449 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003450 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003451 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003452 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003453 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003454 ClientAuth: RequireAnyClientCert,
3455 },
3456 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003457 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3458 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003459 },
3460 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003461 tests = append(tests, testCase{
3462 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003463 name: "ClientAuth-RSA-Client-TLS13",
3464 config: Config{
3465 MaxVersion: VersionTLS13,
3466 ClientAuth: RequireAnyClientCert,
3467 },
3468 flags: []string{
3469 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3470 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3471 },
3472 })
3473 tests = append(tests, testCase{
3474 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003475 name: "ClientAuth-ECDSA-Client",
3476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003477 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003478 ClientAuth: RequireAnyClientCert,
3479 },
3480 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003481 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3482 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003483 },
3484 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003485 tests = append(tests, testCase{
3486 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003487 name: "ClientAuth-ECDSA-Client-TLS13",
3488 config: Config{
3489 MaxVersion: VersionTLS13,
3490 ClientAuth: RequireAnyClientCert,
3491 },
3492 flags: []string{
3493 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3494 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3495 },
3496 })
3497 tests = append(tests, testCase{
3498 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003499 name: "ClientAuth-NoCertificate-OldCallback",
3500 config: Config{
3501 MaxVersion: VersionTLS12,
3502 ClientAuth: RequestClientCert,
3503 },
3504 flags: []string{"-use-old-client-cert-callback"},
3505 })
3506 tests = append(tests, testCase{
3507 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003508 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3509 config: Config{
3510 MaxVersion: VersionTLS13,
3511 ClientAuth: RequestClientCert,
3512 },
3513 flags: []string{"-use-old-client-cert-callback"},
3514 })
3515 tests = append(tests, testCase{
3516 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003517 name: "ClientAuth-OldCallback",
3518 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003519 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003520 ClientAuth: RequireAnyClientCert,
3521 },
3522 flags: []string{
3523 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3524 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3525 "-use-old-client-cert-callback",
3526 },
3527 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003528 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003529 testType: clientTest,
3530 name: "ClientAuth-OldCallback-TLS13",
3531 config: Config{
3532 MaxVersion: VersionTLS13,
3533 ClientAuth: RequireAnyClientCert,
3534 },
3535 flags: []string{
3536 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3537 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3538 "-use-old-client-cert-callback",
3539 },
3540 })
3541 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003542 testType: serverTest,
3543 name: "ClientAuth-Server",
3544 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003545 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003546 Certificates: []Certificate{rsaCertificate},
3547 },
3548 flags: []string{"-require-any-client-certificate"},
3549 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003550 tests = append(tests, testCase{
3551 testType: serverTest,
3552 name: "ClientAuth-Server-TLS13",
3553 config: Config{
3554 MaxVersion: VersionTLS13,
3555 Certificates: []Certificate{rsaCertificate},
3556 },
3557 flags: []string{"-require-any-client-certificate"},
3558 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003559
David Benjamin4c3ddf72016-06-29 18:13:53 -04003560 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003561 tests = append(tests, testCase{
3562 testType: serverTest,
3563 name: "Basic-Server-RSA",
3564 config: Config{
3565 MaxVersion: VersionTLS12,
3566 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3567 },
3568 flags: []string{
3569 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3570 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3571 },
3572 })
3573 tests = append(tests, testCase{
3574 testType: serverTest,
3575 name: "Basic-Server-ECDHE-RSA",
3576 config: Config{
3577 MaxVersion: VersionTLS12,
3578 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3579 },
3580 flags: []string{
3581 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3582 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3583 },
3584 })
3585 tests = append(tests, testCase{
3586 testType: serverTest,
3587 name: "Basic-Server-ECDHE-ECDSA",
3588 config: Config{
3589 MaxVersion: VersionTLS12,
3590 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3591 },
3592 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003593 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3594 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 },
3596 })
3597
David Benjamin760b1dd2015-05-15 23:33:48 -04003598 // No session ticket support; server doesn't send NewSessionTicket.
3599 tests = append(tests, testCase{
3600 name: "SessionTicketsDisabled-Client",
3601 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003602 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003603 SessionTicketsDisabled: true,
3604 },
3605 })
3606 tests = append(tests, testCase{
3607 testType: serverTest,
3608 name: "SessionTicketsDisabled-Server",
3609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003610 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003611 SessionTicketsDisabled: true,
3612 },
3613 })
3614
3615 // Skip ServerKeyExchange in PSK key exchange if there's no
3616 // identity hint.
3617 tests = append(tests, testCase{
3618 name: "EmptyPSKHint-Client",
3619 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003620 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003621 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3622 PreSharedKey: []byte("secret"),
3623 },
3624 flags: []string{"-psk", "secret"},
3625 })
3626 tests = append(tests, testCase{
3627 testType: serverTest,
3628 name: "EmptyPSKHint-Server",
3629 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003630 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003631 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3632 PreSharedKey: []byte("secret"),
3633 },
3634 flags: []string{"-psk", "secret"},
3635 })
3636
David Benjamin4c3ddf72016-06-29 18:13:53 -04003637 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003638 tests = append(tests, testCase{
3639 testType: clientTest,
3640 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003641 config: Config{
3642 MaxVersion: VersionTLS12,
3643 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003644 flags: []string{
3645 "-enable-ocsp-stapling",
3646 "-expect-ocsp-response",
3647 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003648 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003649 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003650 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003651 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003652 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003653 testType: serverTest,
3654 name: "OCSPStapling-Server",
3655 config: Config{
3656 MaxVersion: VersionTLS12,
3657 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003658 expectedOCSPResponse: testOCSPResponse,
3659 flags: []string{
3660 "-ocsp-response",
3661 base64.StdEncoding.EncodeToString(testOCSPResponse),
3662 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003663 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003664 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003665 tests = append(tests, testCase{
3666 testType: clientTest,
3667 name: "OCSPStapling-Client-TLS13",
3668 config: Config{
3669 MaxVersion: VersionTLS13,
3670 },
3671 flags: []string{
3672 "-enable-ocsp-stapling",
3673 "-expect-ocsp-response",
3674 base64.StdEncoding.EncodeToString(testOCSPResponse),
3675 "-verify-peer",
3676 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003677 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003678 })
3679 tests = append(tests, testCase{
3680 testType: serverTest,
3681 name: "OCSPStapling-Server-TLS13",
3682 config: Config{
3683 MaxVersion: VersionTLS13,
3684 },
3685 expectedOCSPResponse: testOCSPResponse,
3686 flags: []string{
3687 "-ocsp-response",
3688 base64.StdEncoding.EncodeToString(testOCSPResponse),
3689 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003690 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003691 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003692
David Benjamin4c3ddf72016-06-29 18:13:53 -04003693 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003694 for _, vers := range tlsVersions {
3695 if config.protocol == dtls && !vers.hasDTLS {
3696 continue
3697 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003698 for _, testType := range []testType{clientTest, serverTest} {
3699 suffix := "-Client"
3700 if testType == serverTest {
3701 suffix = "-Server"
3702 }
3703 suffix += "-" + vers.name
3704
3705 flag := "-verify-peer"
3706 if testType == serverTest {
3707 flag = "-require-any-client-certificate"
3708 }
3709
3710 tests = append(tests, testCase{
3711 testType: testType,
3712 name: "CertificateVerificationSucceed" + suffix,
3713 config: Config{
3714 MaxVersion: vers.version,
3715 Certificates: []Certificate{rsaCertificate},
3716 },
3717 flags: []string{
3718 flag,
3719 "-expect-verify-result",
3720 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003721 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003722 })
3723 tests = append(tests, testCase{
3724 testType: testType,
3725 name: "CertificateVerificationFail" + suffix,
3726 config: Config{
3727 MaxVersion: vers.version,
3728 Certificates: []Certificate{rsaCertificate},
3729 },
3730 flags: []string{
3731 flag,
3732 "-verify-fail",
3733 },
3734 shouldFail: true,
3735 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3736 })
3737 }
3738
3739 // By default, the client is in a soft fail mode where the peer
3740 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003741 tests = append(tests, testCase{
3742 testType: clientTest,
3743 name: "CertificateVerificationSoftFail-" + vers.name,
3744 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003745 MaxVersion: vers.version,
3746 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003747 },
3748 flags: []string{
3749 "-verify-fail",
3750 "-expect-verify-result",
3751 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003752 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003753 })
3754 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003755
David Benjamin1d4f4c02016-07-26 18:03:08 -04003756 tests = append(tests, testCase{
3757 name: "ShimSendAlert",
3758 flags: []string{"-send-alert"},
3759 shimWritesFirst: true,
3760 shouldFail: true,
3761 expectedLocalError: "remote error: decompression failure",
3762 })
3763
David Benjamin582ba042016-07-07 12:33:25 -07003764 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003765 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003766 name: "Renegotiate-Client",
3767 config: Config{
3768 MaxVersion: VersionTLS12,
3769 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003770 renegotiate: 1,
3771 flags: []string{
3772 "-renegotiate-freely",
3773 "-expect-total-renegotiations", "1",
3774 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003775 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003776
David Benjamin47921102016-07-28 11:29:18 -04003777 tests = append(tests, testCase{
3778 name: "SendHalfHelloRequest",
3779 config: Config{
3780 MaxVersion: VersionTLS12,
3781 Bugs: ProtocolBugs{
3782 PackHelloRequestWithFinished: config.packHandshakeFlight,
3783 },
3784 },
3785 sendHalfHelloRequest: true,
3786 flags: []string{"-renegotiate-ignore"},
3787 shouldFail: true,
3788 expectedError: ":UNEXPECTED_RECORD:",
3789 })
3790
David Benjamin760b1dd2015-05-15 23:33:48 -04003791 // NPN on client and server; results in post-handshake message.
3792 tests = append(tests, testCase{
3793 name: "NPN-Client",
3794 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003795 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003796 NextProtos: []string{"foo"},
3797 },
3798 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003799 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003800 expectedNextProto: "foo",
3801 expectedNextProtoType: npn,
3802 })
3803 tests = append(tests, testCase{
3804 testType: serverTest,
3805 name: "NPN-Server",
3806 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003807 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003808 NextProtos: []string{"bar"},
3809 },
3810 flags: []string{
3811 "-advertise-npn", "\x03foo\x03bar\x03baz",
3812 "-expect-next-proto", "bar",
3813 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003814 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003815 expectedNextProto: "bar",
3816 expectedNextProtoType: npn,
3817 })
3818
3819 // TODO(davidben): Add tests for when False Start doesn't trigger.
3820
3821 // Client does False Start and negotiates NPN.
3822 tests = append(tests, testCase{
3823 name: "FalseStart",
3824 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003825 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003826 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3827 NextProtos: []string{"foo"},
3828 Bugs: ProtocolBugs{
3829 ExpectFalseStart: true,
3830 },
3831 },
3832 flags: []string{
3833 "-false-start",
3834 "-select-next-proto", "foo",
3835 },
3836 shimWritesFirst: true,
3837 resumeSession: true,
3838 })
3839
3840 // Client does False Start and negotiates ALPN.
3841 tests = append(tests, testCase{
3842 name: "FalseStart-ALPN",
3843 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003844 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3846 NextProtos: []string{"foo"},
3847 Bugs: ProtocolBugs{
3848 ExpectFalseStart: true,
3849 },
3850 },
3851 flags: []string{
3852 "-false-start",
3853 "-advertise-alpn", "\x03foo",
3854 },
3855 shimWritesFirst: true,
3856 resumeSession: true,
3857 })
3858
3859 // Client does False Start but doesn't explicitly call
3860 // SSL_connect.
3861 tests = append(tests, testCase{
3862 name: "FalseStart-Implicit",
3863 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003864 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003865 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3866 NextProtos: []string{"foo"},
3867 },
3868 flags: []string{
3869 "-implicit-handshake",
3870 "-false-start",
3871 "-advertise-alpn", "\x03foo",
3872 },
3873 })
3874
3875 // False Start without session tickets.
3876 tests = append(tests, testCase{
3877 name: "FalseStart-SessionTicketsDisabled",
3878 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003879 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003880 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3881 NextProtos: []string{"foo"},
3882 SessionTicketsDisabled: true,
3883 Bugs: ProtocolBugs{
3884 ExpectFalseStart: true,
3885 },
3886 },
3887 flags: []string{
3888 "-false-start",
3889 "-select-next-proto", "foo",
3890 },
3891 shimWritesFirst: true,
3892 })
3893
Adam Langleydf759b52016-07-11 15:24:37 -07003894 tests = append(tests, testCase{
3895 name: "FalseStart-CECPQ1",
3896 config: Config{
3897 MaxVersion: VersionTLS12,
3898 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3899 NextProtos: []string{"foo"},
3900 Bugs: ProtocolBugs{
3901 ExpectFalseStart: true,
3902 },
3903 },
3904 flags: []string{
3905 "-false-start",
3906 "-cipher", "DEFAULT:kCECPQ1",
3907 "-select-next-proto", "foo",
3908 },
3909 shimWritesFirst: true,
3910 resumeSession: true,
3911 })
3912
David Benjamin760b1dd2015-05-15 23:33:48 -04003913 // Server parses a V2ClientHello.
3914 tests = append(tests, testCase{
3915 testType: serverTest,
3916 name: "SendV2ClientHello",
3917 config: Config{
3918 // Choose a cipher suite that does not involve
3919 // elliptic curves, so no extensions are
3920 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003921 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003922 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003923 Bugs: ProtocolBugs{
3924 SendV2ClientHello: true,
3925 },
3926 },
3927 })
3928
3929 // Client sends a Channel ID.
3930 tests = append(tests, testCase{
3931 name: "ChannelID-Client",
3932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003933 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003934 RequestChannelID: true,
3935 },
Adam Langley7c803a62015-06-15 15:35:05 -07003936 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003937 resumeSession: true,
3938 expectChannelID: true,
3939 })
3940
3941 // Server accepts a Channel ID.
3942 tests = append(tests, testCase{
3943 testType: serverTest,
3944 name: "ChannelID-Server",
3945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003946 MaxVersion: VersionTLS12,
3947 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003948 },
3949 flags: []string{
3950 "-expect-channel-id",
3951 base64.StdEncoding.EncodeToString(channelIDBytes),
3952 },
3953 resumeSession: true,
3954 expectChannelID: true,
3955 })
David Benjamin30789da2015-08-29 22:56:45 -04003956
David Benjaminf8fcdf32016-06-08 15:56:13 -04003957 // Channel ID and NPN at the same time, to ensure their relative
3958 // ordering is correct.
3959 tests = append(tests, testCase{
3960 name: "ChannelID-NPN-Client",
3961 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003962 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003963 RequestChannelID: true,
3964 NextProtos: []string{"foo"},
3965 },
3966 flags: []string{
3967 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3968 "-select-next-proto", "foo",
3969 },
3970 resumeSession: true,
3971 expectChannelID: true,
3972 expectedNextProto: "foo",
3973 expectedNextProtoType: npn,
3974 })
3975 tests = append(tests, testCase{
3976 testType: serverTest,
3977 name: "ChannelID-NPN-Server",
3978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003980 ChannelID: channelIDKey,
3981 NextProtos: []string{"bar"},
3982 },
3983 flags: []string{
3984 "-expect-channel-id",
3985 base64.StdEncoding.EncodeToString(channelIDBytes),
3986 "-advertise-npn", "\x03foo\x03bar\x03baz",
3987 "-expect-next-proto", "bar",
3988 },
3989 resumeSession: true,
3990 expectChannelID: true,
3991 expectedNextProto: "bar",
3992 expectedNextProtoType: npn,
3993 })
3994
David Benjamin30789da2015-08-29 22:56:45 -04003995 // Bidirectional shutdown with the runner initiating.
3996 tests = append(tests, testCase{
3997 name: "Shutdown-Runner",
3998 config: Config{
3999 Bugs: ProtocolBugs{
4000 ExpectCloseNotify: true,
4001 },
4002 },
4003 flags: []string{"-check-close-notify"},
4004 })
4005
4006 // Bidirectional shutdown with the shim initiating. The runner,
4007 // in the meantime, sends garbage before the close_notify which
4008 // the shim must ignore.
4009 tests = append(tests, testCase{
4010 name: "Shutdown-Shim",
4011 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004012 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004013 Bugs: ProtocolBugs{
4014 ExpectCloseNotify: true,
4015 },
4016 },
4017 shimShutsDown: true,
4018 sendEmptyRecords: 1,
4019 sendWarningAlerts: 1,
4020 flags: []string{"-check-close-notify"},
4021 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004022 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004023 // TODO(davidben): DTLS 1.3 will want a similar thing for
4024 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004025 tests = append(tests, testCase{
4026 name: "SkipHelloVerifyRequest",
4027 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004028 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004029 Bugs: ProtocolBugs{
4030 SkipHelloVerifyRequest: true,
4031 },
4032 },
4033 })
4034 }
4035
David Benjamin760b1dd2015-05-15 23:33:48 -04004036 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004037 test.protocol = config.protocol
4038 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004039 test.name += "-DTLS"
4040 }
David Benjamin582ba042016-07-07 12:33:25 -07004041 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004042 test.name += "-Async"
4043 test.flags = append(test.flags, "-async")
4044 } else {
4045 test.name += "-Sync"
4046 }
David Benjamin582ba042016-07-07 12:33:25 -07004047 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004048 test.name += "-SplitHandshakeRecords"
4049 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004050 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004051 test.config.Bugs.MaxPacketLength = 256
4052 test.flags = append(test.flags, "-mtu", "256")
4053 }
4054 }
David Benjamin582ba042016-07-07 12:33:25 -07004055 if config.packHandshakeFlight {
4056 test.name += "-PackHandshakeFlight"
4057 test.config.Bugs.PackHandshakeFlight = true
4058 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004059 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004060 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004061}
4062
Adam Langley524e7172015-02-20 16:04:00 -08004063func addDDoSCallbackTests() {
4064 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004065 for _, resume := range []bool{false, true} {
4066 suffix := "Resume"
4067 if resume {
4068 suffix = "No" + suffix
4069 }
4070
4071 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004072 testType: serverTest,
4073 name: "Server-DDoS-OK-" + suffix,
4074 config: Config{
4075 MaxVersion: VersionTLS12,
4076 },
Adam Langley524e7172015-02-20 16:04:00 -08004077 flags: []string{"-install-ddos-callback"},
4078 resumeSession: resume,
4079 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004080 testCases = append(testCases, testCase{
4081 testType: serverTest,
4082 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4083 config: Config{
4084 MaxVersion: VersionTLS13,
4085 },
4086 flags: []string{"-install-ddos-callback"},
4087 resumeSession: resume,
4088 })
Adam Langley524e7172015-02-20 16:04:00 -08004089
4090 failFlag := "-fail-ddos-callback"
4091 if resume {
4092 failFlag = "-fail-second-ddos-callback"
4093 }
4094 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004095 testType: serverTest,
4096 name: "Server-DDoS-Reject-" + suffix,
4097 config: Config{
4098 MaxVersion: VersionTLS12,
4099 },
David Benjamin2c66e072016-09-16 15:58:00 -04004100 flags: []string{"-install-ddos-callback", failFlag},
4101 resumeSession: resume,
4102 shouldFail: true,
4103 expectedError: ":CONNECTION_REJECTED:",
4104 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004105 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004106 testCases = append(testCases, testCase{
4107 testType: serverTest,
4108 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4109 config: Config{
4110 MaxVersion: VersionTLS13,
4111 },
David Benjamin2c66e072016-09-16 15:58:00 -04004112 flags: []string{"-install-ddos-callback", failFlag},
4113 resumeSession: resume,
4114 shouldFail: true,
4115 expectedError: ":CONNECTION_REJECTED:",
4116 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004117 })
Adam Langley524e7172015-02-20 16:04:00 -08004118 }
4119}
4120
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004121func addVersionNegotiationTests() {
4122 for i, shimVers := range tlsVersions {
4123 // Assemble flags to disable all newer versions on the shim.
4124 var flags []string
4125 for _, vers := range tlsVersions[i+1:] {
4126 flags = append(flags, vers.flag)
4127 }
4128
Steven Valdezfdd10992016-09-15 16:27:05 -04004129 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004130 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004131 protocols := []protocol{tls}
4132 if runnerVers.hasDTLS && shimVers.hasDTLS {
4133 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004134 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004135 for _, protocol := range protocols {
4136 expectedVersion := shimVers.version
4137 if runnerVers.version < shimVers.version {
4138 expectedVersion = runnerVers.version
4139 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004140
David Benjamin8b8c0062014-11-23 02:47:52 -05004141 suffix := shimVers.name + "-" + runnerVers.name
4142 if protocol == dtls {
4143 suffix += "-DTLS"
4144 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004145
David Benjamin1eb367c2014-12-12 18:17:51 -05004146 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4147
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004148 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004149 clientVers := shimVers.version
4150 if clientVers > VersionTLS10 {
4151 clientVers = VersionTLS10
4152 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004153 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004154 serverVers := expectedVersion
4155 if expectedVersion >= VersionTLS13 {
4156 serverVers = VersionTLS10
4157 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004158 serverVers = versionToWire(serverVers, protocol == dtls)
4159
David Benjamin8b8c0062014-11-23 02:47:52 -05004160 testCases = append(testCases, testCase{
4161 protocol: protocol,
4162 testType: clientTest,
4163 name: "VersionNegotiation-Client-" + suffix,
4164 config: Config{
4165 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004166 Bugs: ProtocolBugs{
4167 ExpectInitialRecordVersion: clientVers,
4168 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004169 },
4170 flags: flags,
4171 expectedVersion: expectedVersion,
4172 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004173 testCases = append(testCases, testCase{
4174 protocol: protocol,
4175 testType: clientTest,
4176 name: "VersionNegotiation-Client2-" + suffix,
4177 config: Config{
4178 MaxVersion: runnerVers.version,
4179 Bugs: ProtocolBugs{
4180 ExpectInitialRecordVersion: clientVers,
4181 },
4182 },
4183 flags: []string{"-max-version", shimVersFlag},
4184 expectedVersion: expectedVersion,
4185 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004186
4187 testCases = append(testCases, testCase{
4188 protocol: protocol,
4189 testType: serverTest,
4190 name: "VersionNegotiation-Server-" + suffix,
4191 config: Config{
4192 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004193 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004194 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004195 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004196 },
4197 flags: flags,
4198 expectedVersion: expectedVersion,
4199 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004200 testCases = append(testCases, testCase{
4201 protocol: protocol,
4202 testType: serverTest,
4203 name: "VersionNegotiation-Server2-" + suffix,
4204 config: Config{
4205 MaxVersion: runnerVers.version,
4206 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004207 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004208 },
4209 },
4210 flags: []string{"-max-version", shimVersFlag},
4211 expectedVersion: expectedVersion,
4212 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004213 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004214 }
4215 }
David Benjamin95c69562016-06-29 18:15:03 -04004216
Steven Valdezfdd10992016-09-15 16:27:05 -04004217 // Test the version extension at all versions.
4218 for _, vers := range tlsVersions {
4219 protocols := []protocol{tls}
4220 if vers.hasDTLS {
4221 protocols = append(protocols, dtls)
4222 }
4223 for _, protocol := range protocols {
4224 suffix := vers.name
4225 if protocol == dtls {
4226 suffix += "-DTLS"
4227 }
4228
4229 wireVersion := versionToWire(vers.version, protocol == dtls)
4230 testCases = append(testCases, testCase{
4231 protocol: protocol,
4232 testType: serverTest,
4233 name: "VersionNegotiationExtension-" + suffix,
4234 config: Config{
4235 Bugs: ProtocolBugs{
4236 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4237 },
4238 },
4239 expectedVersion: vers.version,
4240 })
4241 }
4242
4243 }
4244
4245 // If all versions are unknown, negotiation fails.
4246 testCases = append(testCases, testCase{
4247 testType: serverTest,
4248 name: "NoSupportedVersions",
4249 config: Config{
4250 Bugs: ProtocolBugs{
4251 SendSupportedVersions: []uint16{0x1111},
4252 },
4253 },
4254 shouldFail: true,
4255 expectedError: ":UNSUPPORTED_PROTOCOL:",
4256 })
4257 testCases = append(testCases, testCase{
4258 protocol: dtls,
4259 testType: serverTest,
4260 name: "NoSupportedVersions-DTLS",
4261 config: Config{
4262 Bugs: ProtocolBugs{
4263 SendSupportedVersions: []uint16{0x1111},
4264 },
4265 },
4266 shouldFail: true,
4267 expectedError: ":UNSUPPORTED_PROTOCOL:",
4268 })
4269
4270 testCases = append(testCases, testCase{
4271 testType: serverTest,
4272 name: "ClientHelloVersionTooHigh",
4273 config: Config{
4274 MaxVersion: VersionTLS13,
4275 Bugs: ProtocolBugs{
4276 SendClientVersion: 0x0304,
4277 OmitSupportedVersions: true,
4278 },
4279 },
4280 expectedVersion: VersionTLS12,
4281 })
4282
4283 testCases = append(testCases, testCase{
4284 testType: serverTest,
4285 name: "ConflictingVersionNegotiation",
4286 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004287 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004288 SendClientVersion: VersionTLS12,
4289 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004290 },
4291 },
David Benjaminad75a662016-09-30 15:42:59 -04004292 // The extension takes precedence over the ClientHello version.
4293 expectedVersion: VersionTLS11,
4294 })
4295
4296 testCases = append(testCases, testCase{
4297 testType: serverTest,
4298 name: "ConflictingVersionNegotiation-2",
4299 config: Config{
4300 Bugs: ProtocolBugs{
4301 SendClientVersion: VersionTLS11,
4302 SendSupportedVersions: []uint16{VersionTLS12},
4303 },
4304 },
4305 // The extension takes precedence over the ClientHello version.
4306 expectedVersion: VersionTLS12,
4307 })
4308
4309 testCases = append(testCases, testCase{
4310 testType: serverTest,
4311 name: "RejectFinalTLS13",
4312 config: Config{
4313 Bugs: ProtocolBugs{
4314 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4315 },
4316 },
4317 // We currently implement a draft TLS 1.3 version. Ensure that
4318 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004319 expectedVersion: VersionTLS12,
4320 })
4321
David Benjamin95c69562016-06-29 18:15:03 -04004322 // Test for version tolerance.
4323 testCases = append(testCases, testCase{
4324 testType: serverTest,
4325 name: "MinorVersionTolerance",
4326 config: Config{
4327 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004328 SendClientVersion: 0x03ff,
4329 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004330 },
4331 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004332 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004333 })
4334 testCases = append(testCases, testCase{
4335 testType: serverTest,
4336 name: "MajorVersionTolerance",
4337 config: Config{
4338 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004339 SendClientVersion: 0x0400,
4340 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004341 },
4342 },
David Benjaminad75a662016-09-30 15:42:59 -04004343 // TLS 1.3 must be negotiated with the supported_versions
4344 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004345 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004346 })
David Benjaminad75a662016-09-30 15:42:59 -04004347 testCases = append(testCases, testCase{
4348 testType: serverTest,
4349 name: "VersionTolerance-TLS13",
4350 config: Config{
4351 Bugs: ProtocolBugs{
4352 // Although TLS 1.3 does not use
4353 // ClientHello.version, it still tolerates high
4354 // values there.
4355 SendClientVersion: 0x0400,
4356 },
4357 },
4358 expectedVersion: VersionTLS13,
4359 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004360
David Benjamin95c69562016-06-29 18:15:03 -04004361 testCases = append(testCases, testCase{
4362 protocol: dtls,
4363 testType: serverTest,
4364 name: "MinorVersionTolerance-DTLS",
4365 config: Config{
4366 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004367 SendClientVersion: 0xfe00,
4368 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004369 },
4370 },
4371 expectedVersion: VersionTLS12,
4372 })
4373 testCases = append(testCases, testCase{
4374 protocol: dtls,
4375 testType: serverTest,
4376 name: "MajorVersionTolerance-DTLS",
4377 config: Config{
4378 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004379 SendClientVersion: 0xfdff,
4380 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004381 },
4382 },
4383 expectedVersion: VersionTLS12,
4384 })
4385
4386 // Test that versions below 3.0 are rejected.
4387 testCases = append(testCases, testCase{
4388 testType: serverTest,
4389 name: "VersionTooLow",
4390 config: Config{
4391 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004392 SendClientVersion: 0x0200,
4393 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004394 },
4395 },
4396 shouldFail: true,
4397 expectedError: ":UNSUPPORTED_PROTOCOL:",
4398 })
4399 testCases = append(testCases, testCase{
4400 protocol: dtls,
4401 testType: serverTest,
4402 name: "VersionTooLow-DTLS",
4403 config: Config{
4404 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004405 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004406 },
4407 },
4408 shouldFail: true,
4409 expectedError: ":UNSUPPORTED_PROTOCOL:",
4410 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004411
David Benjamin2dc02042016-09-19 19:57:37 -04004412 testCases = append(testCases, testCase{
4413 name: "ServerBogusVersion",
4414 config: Config{
4415 Bugs: ProtocolBugs{
4416 SendServerHelloVersion: 0x1234,
4417 },
4418 },
4419 shouldFail: true,
4420 expectedError: ":UNSUPPORTED_PROTOCOL:",
4421 })
4422
David Benjamin1f61f0d2016-07-10 12:20:35 -04004423 // Test TLS 1.3's downgrade signal.
4424 testCases = append(testCases, testCase{
4425 name: "Downgrade-TLS12-Client",
4426 config: Config{
4427 Bugs: ProtocolBugs{
4428 NegotiateVersion: VersionTLS12,
4429 },
4430 },
David Benjamin592b5322016-09-30 15:15:01 -04004431 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004432 // TODO(davidben): This test should fail once TLS 1.3 is final
4433 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004434 })
4435 testCases = append(testCases, testCase{
4436 testType: serverTest,
4437 name: "Downgrade-TLS12-Server",
4438 config: Config{
4439 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004440 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004441 },
4442 },
David Benjamin592b5322016-09-30 15:15:01 -04004443 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004444 // TODO(davidben): This test should fail once TLS 1.3 is final
4445 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004446 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004447}
4448
David Benjaminaccb4542014-12-12 23:44:33 -05004449func addMinimumVersionTests() {
4450 for i, shimVers := range tlsVersions {
4451 // Assemble flags to disable all older versions on the shim.
4452 var flags []string
4453 for _, vers := range tlsVersions[:i] {
4454 flags = append(flags, vers.flag)
4455 }
4456
4457 for _, runnerVers := range tlsVersions {
4458 protocols := []protocol{tls}
4459 if runnerVers.hasDTLS && shimVers.hasDTLS {
4460 protocols = append(protocols, dtls)
4461 }
4462 for _, protocol := range protocols {
4463 suffix := shimVers.name + "-" + runnerVers.name
4464 if protocol == dtls {
4465 suffix += "-DTLS"
4466 }
4467 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4468
David Benjaminaccb4542014-12-12 23:44:33 -05004469 var expectedVersion uint16
4470 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004471 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004472 if runnerVers.version >= shimVers.version {
4473 expectedVersion = runnerVers.version
4474 } else {
4475 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004476 expectedError = ":UNSUPPORTED_PROTOCOL:"
4477 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004478 }
4479
4480 testCases = append(testCases, testCase{
4481 protocol: protocol,
4482 testType: clientTest,
4483 name: "MinimumVersion-Client-" + suffix,
4484 config: Config{
4485 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004486 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004487 // Ensure the server does not decline to
4488 // select a version (versions extension) or
4489 // cipher (some ciphers depend on versions).
4490 NegotiateVersion: runnerVers.version,
4491 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004492 },
David Benjaminaccb4542014-12-12 23:44:33 -05004493 },
David Benjamin87909c02014-12-13 01:55:01 -05004494 flags: flags,
4495 expectedVersion: expectedVersion,
4496 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004497 expectedError: expectedError,
4498 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004499 })
4500 testCases = append(testCases, testCase{
4501 protocol: protocol,
4502 testType: clientTest,
4503 name: "MinimumVersion-Client2-" + suffix,
4504 config: Config{
4505 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004506 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004507 // Ensure the server does not decline to
4508 // select a version (versions extension) or
4509 // cipher (some ciphers depend on versions).
4510 NegotiateVersion: runnerVers.version,
4511 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004512 },
David Benjaminaccb4542014-12-12 23:44:33 -05004513 },
David Benjamin87909c02014-12-13 01:55:01 -05004514 flags: []string{"-min-version", shimVersFlag},
4515 expectedVersion: expectedVersion,
4516 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004517 expectedError: expectedError,
4518 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004519 })
4520
4521 testCases = append(testCases, testCase{
4522 protocol: protocol,
4523 testType: serverTest,
4524 name: "MinimumVersion-Server-" + suffix,
4525 config: Config{
4526 MaxVersion: runnerVers.version,
4527 },
David Benjamin87909c02014-12-13 01:55:01 -05004528 flags: flags,
4529 expectedVersion: expectedVersion,
4530 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004531 expectedError: expectedError,
4532 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004533 })
4534 testCases = append(testCases, testCase{
4535 protocol: protocol,
4536 testType: serverTest,
4537 name: "MinimumVersion-Server2-" + suffix,
4538 config: Config{
4539 MaxVersion: runnerVers.version,
4540 },
David Benjamin87909c02014-12-13 01:55:01 -05004541 flags: []string{"-min-version", shimVersFlag},
4542 expectedVersion: expectedVersion,
4543 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004544 expectedError: expectedError,
4545 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004546 })
4547 }
4548 }
4549 }
4550}
4551
David Benjamine78bfde2014-09-06 12:45:15 -04004552func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004553 // TODO(davidben): Extensions, where applicable, all move their server
4554 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4555 // tests for both. Also test interaction with 0-RTT when implemented.
4556
David Benjamin97d17d92016-07-14 16:12:00 -04004557 // Repeat extensions tests all versions except SSL 3.0.
4558 for _, ver := range tlsVersions {
4559 if ver.version == VersionSSL30 {
4560 continue
4561 }
4562
David Benjamin97d17d92016-07-14 16:12:00 -04004563 // Test that duplicate extensions are rejected.
4564 testCases = append(testCases, testCase{
4565 testType: clientTest,
4566 name: "DuplicateExtensionClient-" + ver.name,
4567 config: Config{
4568 MaxVersion: ver.version,
4569 Bugs: ProtocolBugs{
4570 DuplicateExtension: true,
4571 },
David Benjamine78bfde2014-09-06 12:45:15 -04004572 },
David Benjamin97d17d92016-07-14 16:12:00 -04004573 shouldFail: true,
4574 expectedLocalError: "remote error: error decoding message",
4575 })
4576 testCases = append(testCases, testCase{
4577 testType: serverTest,
4578 name: "DuplicateExtensionServer-" + ver.name,
4579 config: Config{
4580 MaxVersion: ver.version,
4581 Bugs: ProtocolBugs{
4582 DuplicateExtension: true,
4583 },
David Benjamine78bfde2014-09-06 12:45:15 -04004584 },
David Benjamin97d17d92016-07-14 16:12:00 -04004585 shouldFail: true,
4586 expectedLocalError: "remote error: error decoding message",
4587 })
4588
4589 // Test SNI.
4590 testCases = append(testCases, testCase{
4591 testType: clientTest,
4592 name: "ServerNameExtensionClient-" + ver.name,
4593 config: Config{
4594 MaxVersion: ver.version,
4595 Bugs: ProtocolBugs{
4596 ExpectServerName: "example.com",
4597 },
David Benjamine78bfde2014-09-06 12:45:15 -04004598 },
David Benjamin97d17d92016-07-14 16:12:00 -04004599 flags: []string{"-host-name", "example.com"},
4600 })
4601 testCases = append(testCases, testCase{
4602 testType: clientTest,
4603 name: "ServerNameExtensionClientMismatch-" + ver.name,
4604 config: Config{
4605 MaxVersion: ver.version,
4606 Bugs: ProtocolBugs{
4607 ExpectServerName: "mismatch.com",
4608 },
David Benjamine78bfde2014-09-06 12:45:15 -04004609 },
David Benjamin97d17d92016-07-14 16:12:00 -04004610 flags: []string{"-host-name", "example.com"},
4611 shouldFail: true,
4612 expectedLocalError: "tls: unexpected server name",
4613 })
4614 testCases = append(testCases, testCase{
4615 testType: clientTest,
4616 name: "ServerNameExtensionClientMissing-" + ver.name,
4617 config: Config{
4618 MaxVersion: ver.version,
4619 Bugs: ProtocolBugs{
4620 ExpectServerName: "missing.com",
4621 },
David Benjamine78bfde2014-09-06 12:45:15 -04004622 },
David Benjamin97d17d92016-07-14 16:12:00 -04004623 shouldFail: true,
4624 expectedLocalError: "tls: unexpected server name",
4625 })
4626 testCases = append(testCases, testCase{
4627 testType: serverTest,
4628 name: "ServerNameExtensionServer-" + ver.name,
4629 config: Config{
4630 MaxVersion: ver.version,
4631 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004632 },
David Benjamin97d17d92016-07-14 16:12:00 -04004633 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004634 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004635 })
4636
4637 // Test ALPN.
4638 testCases = append(testCases, testCase{
4639 testType: clientTest,
4640 name: "ALPNClient-" + ver.name,
4641 config: Config{
4642 MaxVersion: ver.version,
4643 NextProtos: []string{"foo"},
4644 },
4645 flags: []string{
4646 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4647 "-expect-alpn", "foo",
4648 },
4649 expectedNextProto: "foo",
4650 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004651 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004652 })
4653 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004654 testType: clientTest,
4655 name: "ALPNClient-Mismatch-" + ver.name,
4656 config: Config{
4657 MaxVersion: ver.version,
4658 Bugs: ProtocolBugs{
4659 SendALPN: "baz",
4660 },
4661 },
4662 flags: []string{
4663 "-advertise-alpn", "\x03foo\x03bar",
4664 },
4665 shouldFail: true,
4666 expectedError: ":INVALID_ALPN_PROTOCOL:",
4667 expectedLocalError: "remote error: illegal parameter",
4668 })
4669 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004670 testType: serverTest,
4671 name: "ALPNServer-" + ver.name,
4672 config: Config{
4673 MaxVersion: ver.version,
4674 NextProtos: []string{"foo", "bar", "baz"},
4675 },
4676 flags: []string{
4677 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4678 "-select-alpn", "foo",
4679 },
4680 expectedNextProto: "foo",
4681 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004682 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004683 })
4684 testCases = append(testCases, testCase{
4685 testType: serverTest,
4686 name: "ALPNServer-Decline-" + ver.name,
4687 config: Config{
4688 MaxVersion: ver.version,
4689 NextProtos: []string{"foo", "bar", "baz"},
4690 },
4691 flags: []string{"-decline-alpn"},
4692 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004693 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004694 })
4695
David Benjamin25fe85b2016-08-09 20:00:32 -04004696 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4697 // called once.
4698 testCases = append(testCases, testCase{
4699 testType: serverTest,
4700 name: "ALPNServer-Async-" + ver.name,
4701 config: Config{
4702 MaxVersion: ver.version,
4703 NextProtos: []string{"foo", "bar", "baz"},
4704 },
4705 flags: []string{
4706 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4707 "-select-alpn", "foo",
4708 "-async",
4709 },
4710 expectedNextProto: "foo",
4711 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004712 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004713 })
4714
David Benjamin97d17d92016-07-14 16:12:00 -04004715 var emptyString string
4716 testCases = append(testCases, testCase{
4717 testType: clientTest,
4718 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4719 config: Config{
4720 MaxVersion: ver.version,
4721 NextProtos: []string{""},
4722 Bugs: ProtocolBugs{
4723 // A server returning an empty ALPN protocol
4724 // should be rejected.
4725 ALPNProtocol: &emptyString,
4726 },
4727 },
4728 flags: []string{
4729 "-advertise-alpn", "\x03foo",
4730 },
4731 shouldFail: true,
4732 expectedError: ":PARSE_TLSEXT:",
4733 })
4734 testCases = append(testCases, testCase{
4735 testType: serverTest,
4736 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4737 config: Config{
4738 MaxVersion: ver.version,
4739 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004740 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004741 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004742 },
David Benjamin97d17d92016-07-14 16:12:00 -04004743 flags: []string{
4744 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004745 },
David Benjamin97d17d92016-07-14 16:12:00 -04004746 shouldFail: true,
4747 expectedError: ":PARSE_TLSEXT:",
4748 })
4749
4750 // Test NPN and the interaction with ALPN.
4751 if ver.version < VersionTLS13 {
4752 // Test that the server prefers ALPN over NPN.
4753 testCases = append(testCases, testCase{
4754 testType: serverTest,
4755 name: "ALPNServer-Preferred-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 NextProtos: []string{"foo", "bar", "baz"},
4759 },
4760 flags: []string{
4761 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4762 "-select-alpn", "foo",
4763 "-advertise-npn", "\x03foo\x03bar\x03baz",
4764 },
4765 expectedNextProto: "foo",
4766 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004767 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004768 })
4769 testCases = append(testCases, testCase{
4770 testType: serverTest,
4771 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 NextProtos: []string{"foo", "bar", "baz"},
4775 Bugs: ProtocolBugs{
4776 SwapNPNAndALPN: true,
4777 },
4778 },
4779 flags: []string{
4780 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4781 "-select-alpn", "foo",
4782 "-advertise-npn", "\x03foo\x03bar\x03baz",
4783 },
4784 expectedNextProto: "foo",
4785 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004786 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004787 })
4788
4789 // Test that negotiating both NPN and ALPN is forbidden.
4790 testCases = append(testCases, testCase{
4791 name: "NegotiateALPNAndNPN-" + ver.name,
4792 config: Config{
4793 MaxVersion: ver.version,
4794 NextProtos: []string{"foo", "bar", "baz"},
4795 Bugs: ProtocolBugs{
4796 NegotiateALPNAndNPN: true,
4797 },
4798 },
4799 flags: []string{
4800 "-advertise-alpn", "\x03foo",
4801 "-select-next-proto", "foo",
4802 },
4803 shouldFail: true,
4804 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4805 })
4806 testCases = append(testCases, testCase{
4807 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4808 config: Config{
4809 MaxVersion: ver.version,
4810 NextProtos: []string{"foo", "bar", "baz"},
4811 Bugs: ProtocolBugs{
4812 NegotiateALPNAndNPN: true,
4813 SwapNPNAndALPN: true,
4814 },
4815 },
4816 flags: []string{
4817 "-advertise-alpn", "\x03foo",
4818 "-select-next-proto", "foo",
4819 },
4820 shouldFail: true,
4821 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4822 })
4823
4824 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4825 testCases = append(testCases, testCase{
4826 name: "DisableNPN-" + ver.name,
4827 config: Config{
4828 MaxVersion: ver.version,
4829 NextProtos: []string{"foo"},
4830 },
4831 flags: []string{
4832 "-select-next-proto", "foo",
4833 "-disable-npn",
4834 },
4835 expectNoNextProto: true,
4836 })
4837 }
4838
4839 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004840
4841 // Resume with a corrupt ticket.
4842 testCases = append(testCases, testCase{
4843 testType: serverTest,
4844 name: "CorruptTicket-" + ver.name,
4845 config: Config{
4846 MaxVersion: ver.version,
4847 Bugs: ProtocolBugs{
4848 CorruptTicket: true,
4849 },
4850 },
4851 resumeSession: true,
4852 expectResumeRejected: true,
4853 })
4854 // Test the ticket callback, with and without renewal.
4855 testCases = append(testCases, testCase{
4856 testType: serverTest,
4857 name: "TicketCallback-" + ver.name,
4858 config: Config{
4859 MaxVersion: ver.version,
4860 },
4861 resumeSession: true,
4862 flags: []string{"-use-ticket-callback"},
4863 })
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "TicketCallback-Renew-" + ver.name,
4867 config: Config{
4868 MaxVersion: ver.version,
4869 Bugs: ProtocolBugs{
4870 ExpectNewTicket: true,
4871 },
4872 },
4873 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4874 resumeSession: true,
4875 })
4876
4877 // Test that the ticket callback is only called once when everything before
4878 // it in the ClientHello is asynchronous. This corrupts the ticket so
4879 // certificate selection callbacks run.
4880 testCases = append(testCases, testCase{
4881 testType: serverTest,
4882 name: "TicketCallback-SingleCall-" + ver.name,
4883 config: Config{
4884 MaxVersion: ver.version,
4885 Bugs: ProtocolBugs{
4886 CorruptTicket: true,
4887 },
4888 },
4889 resumeSession: true,
4890 expectResumeRejected: true,
4891 flags: []string{
4892 "-use-ticket-callback",
4893 "-async",
4894 },
4895 })
4896
4897 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004898 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004899 testCases = append(testCases, testCase{
4900 testType: serverTest,
4901 name: "OversizedSessionId-" + ver.name,
4902 config: Config{
4903 MaxVersion: ver.version,
4904 Bugs: ProtocolBugs{
4905 OversizedSessionId: true,
4906 },
4907 },
4908 resumeSession: true,
4909 shouldFail: true,
4910 expectedError: ":DECODE_ERROR:",
4911 })
4912 }
4913
4914 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4915 // are ignored.
4916 if ver.hasDTLS {
4917 testCases = append(testCases, testCase{
4918 protocol: dtls,
4919 name: "SRTP-Client-" + ver.name,
4920 config: Config{
4921 MaxVersion: ver.version,
4922 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4923 },
4924 flags: []string{
4925 "-srtp-profiles",
4926 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4927 },
4928 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4929 })
4930 testCases = append(testCases, testCase{
4931 protocol: dtls,
4932 testType: serverTest,
4933 name: "SRTP-Server-" + ver.name,
4934 config: Config{
4935 MaxVersion: ver.version,
4936 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4937 },
4938 flags: []string{
4939 "-srtp-profiles",
4940 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4941 },
4942 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4943 })
4944 // Test that the MKI is ignored.
4945 testCases = append(testCases, testCase{
4946 protocol: dtls,
4947 testType: serverTest,
4948 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4949 config: Config{
4950 MaxVersion: ver.version,
4951 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4952 Bugs: ProtocolBugs{
4953 SRTPMasterKeyIdentifer: "bogus",
4954 },
4955 },
4956 flags: []string{
4957 "-srtp-profiles",
4958 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4959 },
4960 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4961 })
4962 // Test that SRTP isn't negotiated on the server if there were
4963 // no matching profiles.
4964 testCases = append(testCases, testCase{
4965 protocol: dtls,
4966 testType: serverTest,
4967 name: "SRTP-Server-NoMatch-" + ver.name,
4968 config: Config{
4969 MaxVersion: ver.version,
4970 SRTPProtectionProfiles: []uint16{100, 101, 102},
4971 },
4972 flags: []string{
4973 "-srtp-profiles",
4974 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4975 },
4976 expectedSRTPProtectionProfile: 0,
4977 })
4978 // Test that the server returning an invalid SRTP profile is
4979 // flagged as an error by the client.
4980 testCases = append(testCases, testCase{
4981 protocol: dtls,
4982 name: "SRTP-Client-NoMatch-" + ver.name,
4983 config: Config{
4984 MaxVersion: ver.version,
4985 Bugs: ProtocolBugs{
4986 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4987 },
4988 },
4989 flags: []string{
4990 "-srtp-profiles",
4991 "SRTP_AES128_CM_SHA1_80",
4992 },
4993 shouldFail: true,
4994 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4995 })
4996 }
4997
4998 // Test SCT list.
4999 testCases = append(testCases, testCase{
5000 name: "SignedCertificateTimestampList-Client-" + ver.name,
5001 testType: clientTest,
5002 config: Config{
5003 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005004 },
David Benjamin97d17d92016-07-14 16:12:00 -04005005 flags: []string{
5006 "-enable-signed-cert-timestamps",
5007 "-expect-signed-cert-timestamps",
5008 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005009 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005010 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005011 })
David Benjamindaa88502016-10-04 16:32:16 -04005012
5013 // The SCT extension did not specify that it must only be sent on resumption as it
5014 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005015 testCases = append(testCases, testCase{
5016 name: "SendSCTListOnResume-" + ver.name,
5017 config: Config{
5018 MaxVersion: ver.version,
5019 Bugs: ProtocolBugs{
5020 SendSCTListOnResume: []byte("bogus"),
5021 },
David Benjamind98452d2015-06-16 14:16:23 -04005022 },
David Benjamin97d17d92016-07-14 16:12:00 -04005023 flags: []string{
5024 "-enable-signed-cert-timestamps",
5025 "-expect-signed-cert-timestamps",
5026 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005027 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005028 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005029 })
David Benjamindaa88502016-10-04 16:32:16 -04005030
David Benjamin97d17d92016-07-14 16:12:00 -04005031 testCases = append(testCases, testCase{
5032 name: "SignedCertificateTimestampList-Server-" + ver.name,
5033 testType: serverTest,
5034 config: Config{
5035 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005036 },
David Benjamin97d17d92016-07-14 16:12:00 -04005037 flags: []string{
5038 "-signed-cert-timestamps",
5039 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005040 },
David Benjamin97d17d92016-07-14 16:12:00 -04005041 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005042 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005043 })
5044 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005045
Paul Lietar4fac72e2015-09-09 13:44:55 +01005046 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005047 testType: clientTest,
5048 name: "ClientHelloPadding",
5049 config: Config{
5050 Bugs: ProtocolBugs{
5051 RequireClientHelloSize: 512,
5052 },
5053 },
5054 // This hostname just needs to be long enough to push the
5055 // ClientHello into F5's danger zone between 256 and 511 bytes
5056 // long.
5057 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5058 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005059
5060 // Extensions should not function in SSL 3.0.
5061 testCases = append(testCases, testCase{
5062 testType: serverTest,
5063 name: "SSLv3Extensions-NoALPN",
5064 config: Config{
5065 MaxVersion: VersionSSL30,
5066 NextProtos: []string{"foo", "bar", "baz"},
5067 },
5068 flags: []string{
5069 "-select-alpn", "foo",
5070 },
5071 expectNoNextProto: true,
5072 })
5073
5074 // Test session tickets separately as they follow a different codepath.
5075 testCases = append(testCases, testCase{
5076 testType: serverTest,
5077 name: "SSLv3Extensions-NoTickets",
5078 config: Config{
5079 MaxVersion: VersionSSL30,
5080 Bugs: ProtocolBugs{
5081 // Historically, session tickets in SSL 3.0
5082 // failed in different ways depending on whether
5083 // the client supported renegotiation_info.
5084 NoRenegotiationInfo: true,
5085 },
5086 },
5087 resumeSession: true,
5088 })
5089 testCases = append(testCases, testCase{
5090 testType: serverTest,
5091 name: "SSLv3Extensions-NoTickets2",
5092 config: Config{
5093 MaxVersion: VersionSSL30,
5094 },
5095 resumeSession: true,
5096 })
5097
5098 // But SSL 3.0 does send and process renegotiation_info.
5099 testCases = append(testCases, testCase{
5100 testType: serverTest,
5101 name: "SSLv3Extensions-RenegotiationInfo",
5102 config: Config{
5103 MaxVersion: VersionSSL30,
5104 Bugs: ProtocolBugs{
5105 RequireRenegotiationInfo: true,
5106 },
5107 },
5108 })
5109 testCases = append(testCases, testCase{
5110 testType: serverTest,
5111 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5112 config: Config{
5113 MaxVersion: VersionSSL30,
5114 Bugs: ProtocolBugs{
5115 NoRenegotiationInfo: true,
5116 SendRenegotiationSCSV: true,
5117 RequireRenegotiationInfo: true,
5118 },
5119 },
5120 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005121
5122 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5123 // in ServerHello.
5124 testCases = append(testCases, testCase{
5125 name: "NPN-Forbidden-TLS13",
5126 config: Config{
5127 MaxVersion: VersionTLS13,
5128 NextProtos: []string{"foo"},
5129 Bugs: ProtocolBugs{
5130 NegotiateNPNAtAllVersions: true,
5131 },
5132 },
5133 flags: []string{"-select-next-proto", "foo"},
5134 shouldFail: true,
5135 expectedError: ":ERROR_PARSING_EXTENSION:",
5136 })
5137 testCases = append(testCases, testCase{
5138 name: "EMS-Forbidden-TLS13",
5139 config: Config{
5140 MaxVersion: VersionTLS13,
5141 Bugs: ProtocolBugs{
5142 NegotiateEMSAtAllVersions: true,
5143 },
5144 },
5145 shouldFail: true,
5146 expectedError: ":ERROR_PARSING_EXTENSION:",
5147 })
5148 testCases = append(testCases, testCase{
5149 name: "RenegotiationInfo-Forbidden-TLS13",
5150 config: Config{
5151 MaxVersion: VersionTLS13,
5152 Bugs: ProtocolBugs{
5153 NegotiateRenegotiationInfoAtAllVersions: true,
5154 },
5155 },
5156 shouldFail: true,
5157 expectedError: ":ERROR_PARSING_EXTENSION:",
5158 })
5159 testCases = append(testCases, testCase{
5160 name: "ChannelID-Forbidden-TLS13",
5161 config: Config{
5162 MaxVersion: VersionTLS13,
5163 RequestChannelID: true,
5164 Bugs: ProtocolBugs{
5165 NegotiateChannelIDAtAllVersions: true,
5166 },
5167 },
5168 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5169 shouldFail: true,
5170 expectedError: ":ERROR_PARSING_EXTENSION:",
5171 })
5172 testCases = append(testCases, testCase{
5173 name: "Ticket-Forbidden-TLS13",
5174 config: Config{
5175 MaxVersion: VersionTLS12,
5176 },
5177 resumeConfig: &Config{
5178 MaxVersion: VersionTLS13,
5179 Bugs: ProtocolBugs{
5180 AdvertiseTicketExtension: true,
5181 },
5182 },
5183 resumeSession: true,
5184 shouldFail: true,
5185 expectedError: ":ERROR_PARSING_EXTENSION:",
5186 })
5187
5188 // Test that illegal extensions in TLS 1.3 are declined by the server if
5189 // offered in ClientHello. The runner's server will fail if this occurs,
5190 // so we exercise the offering path. (EMS and Renegotiation Info are
5191 // implicit in every test.)
5192 testCases = append(testCases, testCase{
5193 testType: serverTest,
5194 name: "ChannelID-Declined-TLS13",
5195 config: Config{
5196 MaxVersion: VersionTLS13,
5197 ChannelID: channelIDKey,
5198 },
5199 flags: []string{"-enable-channel-id"},
5200 })
5201 testCases = append(testCases, testCase{
5202 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005203 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005204 config: Config{
5205 MaxVersion: VersionTLS13,
5206 NextProtos: []string{"bar"},
5207 },
5208 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5209 })
David Benjamin196df5b2016-09-21 16:23:27 -04005210
5211 testCases = append(testCases, testCase{
5212 testType: serverTest,
5213 name: "InvalidChannelIDSignature",
5214 config: Config{
5215 MaxVersion: VersionTLS12,
5216 ChannelID: channelIDKey,
5217 Bugs: ProtocolBugs{
5218 InvalidChannelIDSignature: true,
5219 },
5220 },
5221 flags: []string{"-enable-channel-id"},
5222 shouldFail: true,
5223 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5224 expectedLocalError: "remote error: error decrypting message",
5225 })
David Benjamindaa88502016-10-04 16:32:16 -04005226
5227 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5228 // tolerated.
5229 testCases = append(testCases, testCase{
5230 name: "SendOCSPResponseOnResume-TLS12",
5231 config: Config{
5232 MaxVersion: VersionTLS12,
5233 Bugs: ProtocolBugs{
5234 SendOCSPResponseOnResume: []byte("bogus"),
5235 },
5236 },
5237 flags: []string{
5238 "-enable-ocsp-stapling",
5239 "-expect-ocsp-response",
5240 base64.StdEncoding.EncodeToString(testOCSPResponse),
5241 },
5242 resumeSession: true,
5243 })
5244
5245 // Beginning TLS 1.3, enforce this does not happen.
5246 testCases = append(testCases, testCase{
5247 name: "SendOCSPResponseOnResume-TLS13",
5248 config: Config{
5249 MaxVersion: VersionTLS13,
5250 Bugs: ProtocolBugs{
5251 SendOCSPResponseOnResume: []byte("bogus"),
5252 },
5253 },
5254 flags: []string{
5255 "-enable-ocsp-stapling",
5256 "-expect-ocsp-response",
5257 base64.StdEncoding.EncodeToString(testOCSPResponse),
5258 },
5259 resumeSession: true,
5260 shouldFail: true,
5261 expectedError: ":ERROR_PARSING_EXTENSION:",
5262 })
David Benjamine78bfde2014-09-06 12:45:15 -04005263}
5264
David Benjamin01fe8202014-09-24 15:21:44 -04005265func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005266 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005267 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005268 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5269 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5270 // TLS 1.3 only shares ciphers with TLS 1.2, so
5271 // we skip certain combinations and use a
5272 // different cipher to test with.
5273 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5274 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5275 continue
5276 }
5277 }
5278
David Benjamin8b8c0062014-11-23 02:47:52 -05005279 protocols := []protocol{tls}
5280 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5281 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005282 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005283 for _, protocol := range protocols {
5284 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5285 if protocol == dtls {
5286 suffix += "-DTLS"
5287 }
5288
David Benjaminece3de92015-03-16 18:02:20 -04005289 if sessionVers.version == resumeVers.version {
5290 testCases = append(testCases, testCase{
5291 protocol: protocol,
5292 name: "Resume-Client" + suffix,
5293 resumeSession: true,
5294 config: Config{
5295 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005296 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005297 Bugs: ProtocolBugs{
5298 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5299 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5300 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005301 },
David Benjaminece3de92015-03-16 18:02:20 -04005302 expectedVersion: sessionVers.version,
5303 expectedResumeVersion: resumeVers.version,
5304 })
5305 } else {
David Benjamin405da482016-08-08 17:25:07 -04005306 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5307
5308 // Offering a TLS 1.3 session sends an empty session ID, so
5309 // there is no way to convince a non-lookahead client the
5310 // session was resumed. It will appear to the client that a
5311 // stray ChangeCipherSpec was sent.
5312 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5313 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005314 }
5315
David Benjaminece3de92015-03-16 18:02:20 -04005316 testCases = append(testCases, testCase{
5317 protocol: protocol,
5318 name: "Resume-Client-Mismatch" + suffix,
5319 resumeSession: true,
5320 config: Config{
5321 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005322 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005323 },
David Benjaminece3de92015-03-16 18:02:20 -04005324 expectedVersion: sessionVers.version,
5325 resumeConfig: &Config{
5326 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005327 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005328 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005329 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005330 },
5331 },
5332 expectedResumeVersion: resumeVers.version,
5333 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005334 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005335 })
5336 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005337
5338 testCases = append(testCases, testCase{
5339 protocol: protocol,
5340 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005341 resumeSession: true,
5342 config: Config{
5343 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005344 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005345 },
5346 expectedVersion: sessionVers.version,
5347 resumeConfig: &Config{
5348 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005349 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005350 },
5351 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005352 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005353 expectedResumeVersion: resumeVers.version,
5354 })
5355
David Benjamin8b8c0062014-11-23 02:47:52 -05005356 testCases = append(testCases, testCase{
5357 protocol: protocol,
5358 testType: serverTest,
5359 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005360 resumeSession: true,
5361 config: Config{
5362 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005363 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005364 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005365 expectedVersion: sessionVers.version,
5366 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005367 resumeConfig: &Config{
5368 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005369 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005370 Bugs: ProtocolBugs{
5371 SendBothTickets: true,
5372 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005373 },
5374 expectedResumeVersion: resumeVers.version,
5375 })
5376 }
David Benjamin01fe8202014-09-24 15:21:44 -04005377 }
5378 }
David Benjaminece3de92015-03-16 18:02:20 -04005379
5380 testCases = append(testCases, testCase{
5381 name: "Resume-Client-CipherMismatch",
5382 resumeSession: true,
5383 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005384 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005385 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5386 },
5387 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005388 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005389 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5390 Bugs: ProtocolBugs{
5391 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5392 },
5393 },
5394 shouldFail: true,
5395 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5396 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005397
5398 testCases = append(testCases, testCase{
5399 name: "Resume-Client-CipherMismatch-TLS13",
5400 resumeSession: true,
5401 config: Config{
5402 MaxVersion: VersionTLS13,
5403 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5404 },
5405 resumeConfig: &Config{
5406 MaxVersion: VersionTLS13,
5407 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5408 Bugs: ProtocolBugs{
5409 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5410 },
5411 },
5412 shouldFail: true,
5413 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5414 })
David Benjamin01fe8202014-09-24 15:21:44 -04005415}
5416
Adam Langley2ae77d22014-10-28 17:29:33 -07005417func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005418 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005419 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005420 testType: serverTest,
5421 name: "Renegotiate-Server-Forbidden",
5422 config: Config{
5423 MaxVersion: VersionTLS12,
5424 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005425 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005426 shouldFail: true,
5427 expectedError: ":NO_RENEGOTIATION:",
5428 expectedLocalError: "remote error: no renegotiation",
5429 })
Adam Langley5021b222015-06-12 18:27:58 -07005430 // The server shouldn't echo the renegotiation extension unless
5431 // requested by the client.
5432 testCases = append(testCases, testCase{
5433 testType: serverTest,
5434 name: "Renegotiate-Server-NoExt",
5435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005436 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005437 Bugs: ProtocolBugs{
5438 NoRenegotiationInfo: true,
5439 RequireRenegotiationInfo: true,
5440 },
5441 },
5442 shouldFail: true,
5443 expectedLocalError: "renegotiation extension missing",
5444 })
5445 // The renegotiation SCSV should be sufficient for the server to echo
5446 // the extension.
5447 testCases = append(testCases, testCase{
5448 testType: serverTest,
5449 name: "Renegotiate-Server-NoExt-SCSV",
5450 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005451 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005452 Bugs: ProtocolBugs{
5453 NoRenegotiationInfo: true,
5454 SendRenegotiationSCSV: true,
5455 RequireRenegotiationInfo: true,
5456 },
5457 },
5458 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005459 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005460 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005462 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005463 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005464 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005465 },
5466 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005467 renegotiate: 1,
5468 flags: []string{
5469 "-renegotiate-freely",
5470 "-expect-total-renegotiations", "1",
5471 },
David Benjamincdea40c2015-03-19 14:09:43 -04005472 })
5473 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005474 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005475 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005476 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005477 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005478 Bugs: ProtocolBugs{
5479 EmptyRenegotiationInfo: true,
5480 },
5481 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005482 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005483 shouldFail: true,
5484 expectedError: ":RENEGOTIATION_MISMATCH:",
5485 })
5486 testCases = append(testCases, testCase{
5487 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005488 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005489 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005490 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005491 Bugs: ProtocolBugs{
5492 BadRenegotiationInfo: true,
5493 },
5494 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005495 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005496 shouldFail: true,
5497 expectedError: ":RENEGOTIATION_MISMATCH:",
5498 })
5499 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005500 name: "Renegotiate-Client-Downgrade",
5501 renegotiate: 1,
5502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005503 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005504 Bugs: ProtocolBugs{
5505 NoRenegotiationInfoAfterInitial: true,
5506 },
5507 },
5508 flags: []string{"-renegotiate-freely"},
5509 shouldFail: true,
5510 expectedError: ":RENEGOTIATION_MISMATCH:",
5511 })
5512 testCases = append(testCases, testCase{
5513 name: "Renegotiate-Client-Upgrade",
5514 renegotiate: 1,
5515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005516 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005517 Bugs: ProtocolBugs{
5518 NoRenegotiationInfoInInitial: true,
5519 },
5520 },
5521 flags: []string{"-renegotiate-freely"},
5522 shouldFail: true,
5523 expectedError: ":RENEGOTIATION_MISMATCH:",
5524 })
5525 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005526 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005527 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005529 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005530 Bugs: ProtocolBugs{
5531 NoRenegotiationInfo: true,
5532 },
5533 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005534 flags: []string{
5535 "-renegotiate-freely",
5536 "-expect-total-renegotiations", "1",
5537 },
David Benjamincff0b902015-05-15 23:09:47 -04005538 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005539
5540 // Test that the server may switch ciphers on renegotiation without
5541 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005542 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005543 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005544 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005545 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005546 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005547 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005548 },
5549 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005550 flags: []string{
5551 "-renegotiate-freely",
5552 "-expect-total-renegotiations", "1",
5553 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005554 })
5555 testCases = append(testCases, testCase{
5556 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005557 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005558 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005559 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005560 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5561 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005562 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005563 flags: []string{
5564 "-renegotiate-freely",
5565 "-expect-total-renegotiations", "1",
5566 },
David Benjaminb16346b2015-04-08 19:16:58 -04005567 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005568
5569 // Test that the server may not switch versions on renegotiation.
5570 testCases = append(testCases, testCase{
5571 name: "Renegotiate-Client-SwitchVersion",
5572 config: Config{
5573 MaxVersion: VersionTLS12,
5574 // Pick a cipher which exists at both versions.
5575 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5576 Bugs: ProtocolBugs{
5577 NegotiateVersionOnRenego: VersionTLS11,
5578 },
5579 },
5580 renegotiate: 1,
5581 flags: []string{
5582 "-renegotiate-freely",
5583 "-expect-total-renegotiations", "1",
5584 },
5585 shouldFail: true,
5586 expectedError: ":WRONG_SSL_VERSION:",
5587 })
5588
David Benjaminb16346b2015-04-08 19:16:58 -04005589 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005590 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005591 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005592 config: Config{
5593 MaxVersion: VersionTLS10,
5594 Bugs: ProtocolBugs{
5595 RequireSameRenegoClientVersion: true,
5596 },
5597 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005598 flags: []string{
5599 "-renegotiate-freely",
5600 "-expect-total-renegotiations", "1",
5601 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005602 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005603 testCases = append(testCases, testCase{
5604 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005605 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005606 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005607 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005608 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5609 NextProtos: []string{"foo"},
5610 },
5611 flags: []string{
5612 "-false-start",
5613 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005614 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005615 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005616 },
5617 shimWritesFirst: true,
5618 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005619
5620 // Client-side renegotiation controls.
5621 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005622 name: "Renegotiate-Client-Forbidden-1",
5623 config: Config{
5624 MaxVersion: VersionTLS12,
5625 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005626 renegotiate: 1,
5627 shouldFail: true,
5628 expectedError: ":NO_RENEGOTIATION:",
5629 expectedLocalError: "remote error: no renegotiation",
5630 })
5631 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005632 name: "Renegotiate-Client-Once-1",
5633 config: Config{
5634 MaxVersion: VersionTLS12,
5635 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005636 renegotiate: 1,
5637 flags: []string{
5638 "-renegotiate-once",
5639 "-expect-total-renegotiations", "1",
5640 },
5641 })
5642 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005643 name: "Renegotiate-Client-Freely-1",
5644 config: Config{
5645 MaxVersion: VersionTLS12,
5646 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005647 renegotiate: 1,
5648 flags: []string{
5649 "-renegotiate-freely",
5650 "-expect-total-renegotiations", "1",
5651 },
5652 })
5653 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005654 name: "Renegotiate-Client-Once-2",
5655 config: Config{
5656 MaxVersion: VersionTLS12,
5657 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005658 renegotiate: 2,
5659 flags: []string{"-renegotiate-once"},
5660 shouldFail: true,
5661 expectedError: ":NO_RENEGOTIATION:",
5662 expectedLocalError: "remote error: no renegotiation",
5663 })
5664 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005665 name: "Renegotiate-Client-Freely-2",
5666 config: Config{
5667 MaxVersion: VersionTLS12,
5668 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005669 renegotiate: 2,
5670 flags: []string{
5671 "-renegotiate-freely",
5672 "-expect-total-renegotiations", "2",
5673 },
5674 })
Adam Langley27a0d082015-11-03 13:34:10 -08005675 testCases = append(testCases, testCase{
5676 name: "Renegotiate-Client-NoIgnore",
5677 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005678 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005679 Bugs: ProtocolBugs{
5680 SendHelloRequestBeforeEveryAppDataRecord: true,
5681 },
5682 },
5683 shouldFail: true,
5684 expectedError: ":NO_RENEGOTIATION:",
5685 })
5686 testCases = append(testCases, testCase{
5687 name: "Renegotiate-Client-Ignore",
5688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005689 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005690 Bugs: ProtocolBugs{
5691 SendHelloRequestBeforeEveryAppDataRecord: true,
5692 },
5693 },
5694 flags: []string{
5695 "-renegotiate-ignore",
5696 "-expect-total-renegotiations", "0",
5697 },
5698 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005699
David Benjamin397c8e62016-07-08 14:14:36 -07005700 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005701 testCases = append(testCases, testCase{
5702 name: "StrayHelloRequest",
5703 config: Config{
5704 MaxVersion: VersionTLS12,
5705 Bugs: ProtocolBugs{
5706 SendHelloRequestBeforeEveryHandshakeMessage: true,
5707 },
5708 },
5709 })
5710 testCases = append(testCases, testCase{
5711 name: "StrayHelloRequest-Packed",
5712 config: Config{
5713 MaxVersion: VersionTLS12,
5714 Bugs: ProtocolBugs{
5715 PackHandshakeFlight: true,
5716 SendHelloRequestBeforeEveryHandshakeMessage: true,
5717 },
5718 },
5719 })
5720
David Benjamin12d2c482016-07-24 10:56:51 -04005721 // Test renegotiation works if HelloRequest and server Finished come in
5722 // the same record.
5723 testCases = append(testCases, testCase{
5724 name: "Renegotiate-Client-Packed",
5725 config: Config{
5726 MaxVersion: VersionTLS12,
5727 Bugs: ProtocolBugs{
5728 PackHandshakeFlight: true,
5729 PackHelloRequestWithFinished: true,
5730 },
5731 },
5732 renegotiate: 1,
5733 flags: []string{
5734 "-renegotiate-freely",
5735 "-expect-total-renegotiations", "1",
5736 },
5737 })
5738
David Benjamin397c8e62016-07-08 14:14:36 -07005739 // Renegotiation is forbidden in TLS 1.3.
5740 testCases = append(testCases, testCase{
5741 name: "Renegotiate-Client-TLS13",
5742 config: Config{
5743 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005744 Bugs: ProtocolBugs{
5745 SendHelloRequestBeforeEveryAppDataRecord: true,
5746 },
David Benjamin397c8e62016-07-08 14:14:36 -07005747 },
David Benjamin397c8e62016-07-08 14:14:36 -07005748 flags: []string{
5749 "-renegotiate-freely",
5750 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005751 shouldFail: true,
5752 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005753 })
5754
5755 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5756 testCases = append(testCases, testCase{
5757 name: "StrayHelloRequest-TLS13",
5758 config: Config{
5759 MaxVersion: VersionTLS13,
5760 Bugs: ProtocolBugs{
5761 SendHelloRequestBeforeEveryHandshakeMessage: true,
5762 },
5763 },
5764 shouldFail: true,
5765 expectedError: ":UNEXPECTED_MESSAGE:",
5766 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005767}
5768
David Benjamin5e961c12014-11-07 01:48:35 -05005769func addDTLSReplayTests() {
5770 // Test that sequence number replays are detected.
5771 testCases = append(testCases, testCase{
5772 protocol: dtls,
5773 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005774 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005775 replayWrites: true,
5776 })
5777
David Benjamin8e6db492015-07-25 18:29:23 -04005778 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005779 // than the retransmit window.
5780 testCases = append(testCases, testCase{
5781 protocol: dtls,
5782 name: "DTLS-Replay-LargeGaps",
5783 config: Config{
5784 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005785 SequenceNumberMapping: func(in uint64) uint64 {
5786 return in * 127
5787 },
David Benjamin5e961c12014-11-07 01:48:35 -05005788 },
5789 },
David Benjamin8e6db492015-07-25 18:29:23 -04005790 messageCount: 200,
5791 replayWrites: true,
5792 })
5793
5794 // Test the incoming sequence number changing non-monotonically.
5795 testCases = append(testCases, testCase{
5796 protocol: dtls,
5797 name: "DTLS-Replay-NonMonotonic",
5798 config: Config{
5799 Bugs: ProtocolBugs{
5800 SequenceNumberMapping: func(in uint64) uint64 {
5801 return in ^ 31
5802 },
5803 },
5804 },
5805 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005806 replayWrites: true,
5807 })
5808}
5809
Nick Harper60edffd2016-06-21 15:19:24 -07005810var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005811 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005812 id signatureAlgorithm
5813 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005814}{
Nick Harper60edffd2016-06-21 15:19:24 -07005815 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5816 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5817 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5818 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005819 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005820 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5821 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5822 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005823 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5824 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5825 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005826 // Tests for key types prior to TLS 1.2.
5827 {"RSA", 0, testCertRSA},
5828 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005829}
5830
Nick Harper60edffd2016-06-21 15:19:24 -07005831const fakeSigAlg1 signatureAlgorithm = 0x2a01
5832const fakeSigAlg2 signatureAlgorithm = 0xff01
5833
5834func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005835 // Not all ciphers involve a signature. Advertise a list which gives all
5836 // versions a signing cipher.
5837 signingCiphers := []uint16{
5838 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5839 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5840 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5841 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5842 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5843 }
5844
David Benjaminca3d5452016-07-14 12:51:01 -04005845 var allAlgorithms []signatureAlgorithm
5846 for _, alg := range testSignatureAlgorithms {
5847 if alg.id != 0 {
5848 allAlgorithms = append(allAlgorithms, alg.id)
5849 }
5850 }
5851
Nick Harper60edffd2016-06-21 15:19:24 -07005852 // Make sure each signature algorithm works. Include some fake values in
5853 // the list and ensure they're ignored.
5854 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005855 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005856 if (ver.version < VersionTLS12) != (alg.id == 0) {
5857 continue
5858 }
5859
5860 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5861 // or remove it in C.
5862 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005863 continue
5864 }
Nick Harper60edffd2016-06-21 15:19:24 -07005865
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005866 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005867 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005868 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5869 shouldFail = true
5870 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005871 // RSA-PKCS1 does not exist in TLS 1.3.
5872 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5873 shouldFail = true
5874 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005875
5876 var signError, verifyError string
5877 if shouldFail {
5878 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5879 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005880 }
David Benjamin000800a2014-11-14 01:43:59 -05005881
David Benjamin1fb125c2016-07-08 18:52:12 -07005882 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005883
David Benjamin7a41d372016-07-09 11:21:54 -07005884 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005885 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005886 config: Config{
5887 MaxVersion: ver.version,
5888 ClientAuth: RequireAnyClientCert,
5889 VerifySignatureAlgorithms: []signatureAlgorithm{
5890 fakeSigAlg1,
5891 alg.id,
5892 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005893 },
David Benjamin7a41d372016-07-09 11:21:54 -07005894 },
5895 flags: []string{
5896 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5897 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5898 "-enable-all-curves",
5899 },
5900 shouldFail: shouldFail,
5901 expectedError: signError,
5902 expectedPeerSignatureAlgorithm: alg.id,
5903 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005904
David Benjamin7a41d372016-07-09 11:21:54 -07005905 testCases = append(testCases, testCase{
5906 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005907 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005908 config: Config{
5909 MaxVersion: ver.version,
5910 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5911 SignSignatureAlgorithms: []signatureAlgorithm{
5912 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005913 },
David Benjamin7a41d372016-07-09 11:21:54 -07005914 Bugs: ProtocolBugs{
5915 SkipECDSACurveCheck: shouldFail,
5916 IgnoreSignatureVersionChecks: shouldFail,
5917 // The client won't advertise 1.3-only algorithms after
5918 // version negotiation.
5919 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005920 },
David Benjamin7a41d372016-07-09 11:21:54 -07005921 },
5922 flags: []string{
5923 "-require-any-client-certificate",
5924 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5925 "-enable-all-curves",
5926 },
5927 shouldFail: shouldFail,
5928 expectedError: verifyError,
5929 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005930
5931 testCases = append(testCases, testCase{
5932 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005933 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005934 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005935 MaxVersion: ver.version,
5936 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005937 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005938 fakeSigAlg1,
5939 alg.id,
5940 fakeSigAlg2,
5941 },
5942 },
5943 flags: []string{
5944 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5945 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5946 "-enable-all-curves",
5947 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005948 shouldFail: shouldFail,
5949 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005950 expectedPeerSignatureAlgorithm: alg.id,
5951 })
5952
5953 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005954 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005955 config: Config{
5956 MaxVersion: ver.version,
5957 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005958 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005959 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005960 alg.id,
5961 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005962 Bugs: ProtocolBugs{
5963 SkipECDSACurveCheck: shouldFail,
5964 IgnoreSignatureVersionChecks: shouldFail,
5965 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005966 },
5967 flags: []string{
5968 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5969 "-enable-all-curves",
5970 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005971 shouldFail: shouldFail,
5972 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005973 })
David Benjamin5208fd42016-07-13 21:43:25 -04005974
5975 if !shouldFail {
5976 testCases = append(testCases, testCase{
5977 testType: serverTest,
5978 name: "ClientAuth-InvalidSignature" + suffix,
5979 config: Config{
5980 MaxVersion: ver.version,
5981 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5982 SignSignatureAlgorithms: []signatureAlgorithm{
5983 alg.id,
5984 },
5985 Bugs: ProtocolBugs{
5986 InvalidSignature: true,
5987 },
5988 },
5989 flags: []string{
5990 "-require-any-client-certificate",
5991 "-enable-all-curves",
5992 },
5993 shouldFail: true,
5994 expectedError: ":BAD_SIGNATURE:",
5995 })
5996
5997 testCases = append(testCases, testCase{
5998 name: "ServerAuth-InvalidSignature" + suffix,
5999 config: Config{
6000 MaxVersion: ver.version,
6001 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6002 CipherSuites: signingCiphers,
6003 SignSignatureAlgorithms: []signatureAlgorithm{
6004 alg.id,
6005 },
6006 Bugs: ProtocolBugs{
6007 InvalidSignature: true,
6008 },
6009 },
6010 flags: []string{"-enable-all-curves"},
6011 shouldFail: true,
6012 expectedError: ":BAD_SIGNATURE:",
6013 })
6014 }
David Benjaminca3d5452016-07-14 12:51:01 -04006015
6016 if ver.version >= VersionTLS12 && !shouldFail {
6017 testCases = append(testCases, testCase{
6018 name: "ClientAuth-Sign-Negotiate" + suffix,
6019 config: Config{
6020 MaxVersion: ver.version,
6021 ClientAuth: RequireAnyClientCert,
6022 VerifySignatureAlgorithms: allAlgorithms,
6023 },
6024 flags: []string{
6025 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6026 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6027 "-enable-all-curves",
6028 "-signing-prefs", strconv.Itoa(int(alg.id)),
6029 },
6030 expectedPeerSignatureAlgorithm: alg.id,
6031 })
6032
6033 testCases = append(testCases, testCase{
6034 testType: serverTest,
6035 name: "ServerAuth-Sign-Negotiate" + suffix,
6036 config: Config{
6037 MaxVersion: ver.version,
6038 CipherSuites: signingCiphers,
6039 VerifySignatureAlgorithms: allAlgorithms,
6040 },
6041 flags: []string{
6042 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6043 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6044 "-enable-all-curves",
6045 "-signing-prefs", strconv.Itoa(int(alg.id)),
6046 },
6047 expectedPeerSignatureAlgorithm: alg.id,
6048 })
6049 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006050 }
David Benjamin000800a2014-11-14 01:43:59 -05006051 }
6052
Nick Harper60edffd2016-06-21 15:19:24 -07006053 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006054 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006055 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006056 config: Config{
6057 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006058 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006059 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006060 signatureECDSAWithP521AndSHA512,
6061 signatureRSAPKCS1WithSHA384,
6062 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006063 },
6064 },
6065 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006066 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6067 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006068 },
Nick Harper60edffd2016-06-21 15:19:24 -07006069 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006070 })
6071
6072 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006073 name: "ClientAuth-SignatureType-TLS13",
6074 config: Config{
6075 ClientAuth: RequireAnyClientCert,
6076 MaxVersion: VersionTLS13,
6077 VerifySignatureAlgorithms: []signatureAlgorithm{
6078 signatureECDSAWithP521AndSHA512,
6079 signatureRSAPKCS1WithSHA384,
6080 signatureRSAPSSWithSHA384,
6081 signatureECDSAWithSHA1,
6082 },
6083 },
6084 flags: []string{
6085 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6086 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6087 },
6088 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6089 })
6090
6091 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006092 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006093 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006095 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006096 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006097 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006098 signatureECDSAWithP521AndSHA512,
6099 signatureRSAPKCS1WithSHA384,
6100 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006101 },
6102 },
Nick Harper60edffd2016-06-21 15:19:24 -07006103 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006104 })
6105
Steven Valdez143e8b32016-07-11 13:19:03 -04006106 testCases = append(testCases, testCase{
6107 testType: serverTest,
6108 name: "ServerAuth-SignatureType-TLS13",
6109 config: Config{
6110 MaxVersion: VersionTLS13,
6111 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6112 VerifySignatureAlgorithms: []signatureAlgorithm{
6113 signatureECDSAWithP521AndSHA512,
6114 signatureRSAPKCS1WithSHA384,
6115 signatureRSAPSSWithSHA384,
6116 signatureECDSAWithSHA1,
6117 },
6118 },
6119 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6120 })
6121
David Benjamina95e9f32016-07-08 16:28:04 -07006122 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006123 testCases = append(testCases, testCase{
6124 testType: serverTest,
6125 name: "Verify-ClientAuth-SignatureType",
6126 config: Config{
6127 MaxVersion: VersionTLS12,
6128 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006129 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006130 signatureRSAPKCS1WithSHA256,
6131 },
6132 Bugs: ProtocolBugs{
6133 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6134 },
6135 },
6136 flags: []string{
6137 "-require-any-client-certificate",
6138 },
6139 shouldFail: true,
6140 expectedError: ":WRONG_SIGNATURE_TYPE:",
6141 })
6142
6143 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006144 testType: serverTest,
6145 name: "Verify-ClientAuth-SignatureType-TLS13",
6146 config: Config{
6147 MaxVersion: VersionTLS13,
6148 Certificates: []Certificate{rsaCertificate},
6149 SignSignatureAlgorithms: []signatureAlgorithm{
6150 signatureRSAPSSWithSHA256,
6151 },
6152 Bugs: ProtocolBugs{
6153 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6154 },
6155 },
6156 flags: []string{
6157 "-require-any-client-certificate",
6158 },
6159 shouldFail: true,
6160 expectedError: ":WRONG_SIGNATURE_TYPE:",
6161 })
6162
6163 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006164 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006165 config: Config{
6166 MaxVersion: VersionTLS12,
6167 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006168 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006169 signatureRSAPKCS1WithSHA256,
6170 },
6171 Bugs: ProtocolBugs{
6172 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6173 },
6174 },
6175 shouldFail: true,
6176 expectedError: ":WRONG_SIGNATURE_TYPE:",
6177 })
6178
Steven Valdez143e8b32016-07-11 13:19:03 -04006179 testCases = append(testCases, testCase{
6180 name: "Verify-ServerAuth-SignatureType-TLS13",
6181 config: Config{
6182 MaxVersion: VersionTLS13,
6183 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6184 SignSignatureAlgorithms: []signatureAlgorithm{
6185 signatureRSAPSSWithSHA256,
6186 },
6187 Bugs: ProtocolBugs{
6188 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6189 },
6190 },
6191 shouldFail: true,
6192 expectedError: ":WRONG_SIGNATURE_TYPE:",
6193 })
6194
David Benjamin51dd7d62016-07-08 16:07:01 -07006195 // Test that, if the list is missing, the peer falls back to SHA-1 in
6196 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006197 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006198 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006199 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006200 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006201 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006202 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006203 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006204 },
6205 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006206 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006207 },
6208 },
6209 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006210 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6211 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006212 },
6213 })
6214
6215 testCases = append(testCases, testCase{
6216 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006217 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006218 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006219 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006220 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006221 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006222 },
6223 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006224 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006225 },
6226 },
David Benjaminee32bea2016-08-17 13:36:44 -04006227 flags: []string{
6228 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6229 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6230 },
6231 })
6232
6233 testCases = append(testCases, testCase{
6234 name: "ClientAuth-SHA1-Fallback-ECDSA",
6235 config: Config{
6236 MaxVersion: VersionTLS12,
6237 ClientAuth: RequireAnyClientCert,
6238 VerifySignatureAlgorithms: []signatureAlgorithm{
6239 signatureECDSAWithSHA1,
6240 },
6241 Bugs: ProtocolBugs{
6242 NoSignatureAlgorithms: true,
6243 },
6244 },
6245 flags: []string{
6246 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6247 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6248 },
6249 })
6250
6251 testCases = append(testCases, testCase{
6252 testType: serverTest,
6253 name: "ServerAuth-SHA1-Fallback-ECDSA",
6254 config: Config{
6255 MaxVersion: VersionTLS12,
6256 VerifySignatureAlgorithms: []signatureAlgorithm{
6257 signatureECDSAWithSHA1,
6258 },
6259 Bugs: ProtocolBugs{
6260 NoSignatureAlgorithms: true,
6261 },
6262 },
6263 flags: []string{
6264 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6265 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6266 },
David Benjamin000800a2014-11-14 01:43:59 -05006267 })
David Benjamin72dc7832015-03-16 17:49:43 -04006268
David Benjamin51dd7d62016-07-08 16:07:01 -07006269 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006270 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006271 config: Config{
6272 MaxVersion: VersionTLS13,
6273 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006274 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006275 signatureRSAPKCS1WithSHA1,
6276 },
6277 Bugs: ProtocolBugs{
6278 NoSignatureAlgorithms: true,
6279 },
6280 },
6281 flags: []string{
6282 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6283 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6284 },
David Benjamin48901652016-08-01 12:12:47 -04006285 shouldFail: true,
6286 // An empty CertificateRequest signature algorithm list is a
6287 // syntax error in TLS 1.3.
6288 expectedError: ":DECODE_ERROR:",
6289 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006290 })
6291
6292 testCases = append(testCases, testCase{
6293 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006294 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006295 config: Config{
6296 MaxVersion: VersionTLS13,
6297 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006298 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006299 signatureRSAPKCS1WithSHA1,
6300 },
6301 Bugs: ProtocolBugs{
6302 NoSignatureAlgorithms: true,
6303 },
6304 },
6305 shouldFail: true,
6306 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6307 })
6308
David Benjaminb62d2872016-07-18 14:55:02 +02006309 // Test that hash preferences are enforced. BoringSSL does not implement
6310 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006311 testCases = append(testCases, testCase{
6312 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006313 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006314 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006315 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006316 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006317 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006318 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006319 },
6320 Bugs: ProtocolBugs{
6321 IgnorePeerSignatureAlgorithmPreferences: true,
6322 },
6323 },
6324 flags: []string{"-require-any-client-certificate"},
6325 shouldFail: true,
6326 expectedError: ":WRONG_SIGNATURE_TYPE:",
6327 })
6328
6329 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006330 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006331 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006332 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006333 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006334 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006335 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006336 },
6337 Bugs: ProtocolBugs{
6338 IgnorePeerSignatureAlgorithmPreferences: true,
6339 },
6340 },
6341 shouldFail: true,
6342 expectedError: ":WRONG_SIGNATURE_TYPE:",
6343 })
David Benjaminb62d2872016-07-18 14:55:02 +02006344 testCases = append(testCases, testCase{
6345 testType: serverTest,
6346 name: "ClientAuth-Enforced-TLS13",
6347 config: Config{
6348 MaxVersion: VersionTLS13,
6349 Certificates: []Certificate{rsaCertificate},
6350 SignSignatureAlgorithms: []signatureAlgorithm{
6351 signatureRSAPKCS1WithMD5,
6352 },
6353 Bugs: ProtocolBugs{
6354 IgnorePeerSignatureAlgorithmPreferences: true,
6355 IgnoreSignatureVersionChecks: true,
6356 },
6357 },
6358 flags: []string{"-require-any-client-certificate"},
6359 shouldFail: true,
6360 expectedError: ":WRONG_SIGNATURE_TYPE:",
6361 })
6362
6363 testCases = append(testCases, testCase{
6364 name: "ServerAuth-Enforced-TLS13",
6365 config: Config{
6366 MaxVersion: VersionTLS13,
6367 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6368 SignSignatureAlgorithms: []signatureAlgorithm{
6369 signatureRSAPKCS1WithMD5,
6370 },
6371 Bugs: ProtocolBugs{
6372 IgnorePeerSignatureAlgorithmPreferences: true,
6373 IgnoreSignatureVersionChecks: true,
6374 },
6375 },
6376 shouldFail: true,
6377 expectedError: ":WRONG_SIGNATURE_TYPE:",
6378 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006379
6380 // Test that the agreed upon digest respects the client preferences and
6381 // the server digests.
6382 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006383 name: "NoCommonAlgorithms-Digests",
6384 config: Config{
6385 MaxVersion: VersionTLS12,
6386 ClientAuth: RequireAnyClientCert,
6387 VerifySignatureAlgorithms: []signatureAlgorithm{
6388 signatureRSAPKCS1WithSHA512,
6389 signatureRSAPKCS1WithSHA1,
6390 },
6391 },
6392 flags: []string{
6393 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6394 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6395 "-digest-prefs", "SHA256",
6396 },
6397 shouldFail: true,
6398 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6399 })
6400 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006401 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006402 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006403 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006404 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006405 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006406 signatureRSAPKCS1WithSHA512,
6407 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006408 },
6409 },
6410 flags: []string{
6411 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6412 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006413 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006414 },
David Benjaminca3d5452016-07-14 12:51:01 -04006415 shouldFail: true,
6416 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6417 })
6418 testCases = append(testCases, testCase{
6419 name: "NoCommonAlgorithms-TLS13",
6420 config: Config{
6421 MaxVersion: VersionTLS13,
6422 ClientAuth: RequireAnyClientCert,
6423 VerifySignatureAlgorithms: []signatureAlgorithm{
6424 signatureRSAPSSWithSHA512,
6425 signatureRSAPSSWithSHA384,
6426 },
6427 },
6428 flags: []string{
6429 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6430 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6431 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6432 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006433 shouldFail: true,
6434 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006435 })
6436 testCases = append(testCases, testCase{
6437 name: "Agree-Digest-SHA256",
6438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006439 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006440 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006441 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006442 signatureRSAPKCS1WithSHA1,
6443 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006444 },
6445 },
6446 flags: []string{
6447 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6448 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006449 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006450 },
Nick Harper60edffd2016-06-21 15:19:24 -07006451 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006452 })
6453 testCases = append(testCases, testCase{
6454 name: "Agree-Digest-SHA1",
6455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006456 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006457 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006458 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006459 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006460 },
6461 },
6462 flags: []string{
6463 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6464 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006465 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006466 },
Nick Harper60edffd2016-06-21 15:19:24 -07006467 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006468 })
6469 testCases = append(testCases, testCase{
6470 name: "Agree-Digest-Default",
6471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006472 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006473 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006474 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006475 signatureRSAPKCS1WithSHA256,
6476 signatureECDSAWithP256AndSHA256,
6477 signatureRSAPKCS1WithSHA1,
6478 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006479 },
6480 },
6481 flags: []string{
6482 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6483 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6484 },
Nick Harper60edffd2016-06-21 15:19:24 -07006485 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006486 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006487
David Benjaminca3d5452016-07-14 12:51:01 -04006488 // Test that the signing preference list may include extra algorithms
6489 // without negotiation problems.
6490 testCases = append(testCases, testCase{
6491 testType: serverTest,
6492 name: "FilterExtraAlgorithms",
6493 config: Config{
6494 MaxVersion: VersionTLS12,
6495 VerifySignatureAlgorithms: []signatureAlgorithm{
6496 signatureRSAPKCS1WithSHA256,
6497 },
6498 },
6499 flags: []string{
6500 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6501 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6502 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6503 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6504 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6505 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6506 },
6507 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6508 })
6509
David Benjamin4c3ddf72016-06-29 18:13:53 -04006510 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6511 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006512 testCases = append(testCases, testCase{
6513 name: "CheckLeafCurve",
6514 config: Config{
6515 MaxVersion: VersionTLS12,
6516 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006517 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006518 },
6519 flags: []string{"-p384-only"},
6520 shouldFail: true,
6521 expectedError: ":BAD_ECC_CERT:",
6522 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006523
6524 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6525 testCases = append(testCases, testCase{
6526 name: "CheckLeafCurve-TLS13",
6527 config: Config{
6528 MaxVersion: VersionTLS13,
6529 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6530 Certificates: []Certificate{ecdsaP256Certificate},
6531 },
6532 flags: []string{"-p384-only"},
6533 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006534
6535 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6536 testCases = append(testCases, testCase{
6537 name: "ECDSACurveMismatch-Verify-TLS12",
6538 config: Config{
6539 MaxVersion: VersionTLS12,
6540 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6541 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006542 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006543 signatureECDSAWithP384AndSHA384,
6544 },
6545 },
6546 })
6547
6548 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6549 testCases = append(testCases, testCase{
6550 name: "ECDSACurveMismatch-Verify-TLS13",
6551 config: Config{
6552 MaxVersion: VersionTLS13,
6553 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6554 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006555 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006556 signatureECDSAWithP384AndSHA384,
6557 },
6558 Bugs: ProtocolBugs{
6559 SkipECDSACurveCheck: true,
6560 },
6561 },
6562 shouldFail: true,
6563 expectedError: ":WRONG_SIGNATURE_TYPE:",
6564 })
6565
6566 // Signature algorithm selection in TLS 1.3 should take the curve into
6567 // account.
6568 testCases = append(testCases, testCase{
6569 testType: serverTest,
6570 name: "ECDSACurveMismatch-Sign-TLS13",
6571 config: Config{
6572 MaxVersion: VersionTLS13,
6573 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006574 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006575 signatureECDSAWithP384AndSHA384,
6576 signatureECDSAWithP256AndSHA256,
6577 },
6578 },
6579 flags: []string{
6580 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6581 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6582 },
6583 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6584 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006585
6586 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6587 // server does not attempt to sign in that case.
6588 testCases = append(testCases, testCase{
6589 testType: serverTest,
6590 name: "RSA-PSS-Large",
6591 config: Config{
6592 MaxVersion: VersionTLS13,
6593 VerifySignatureAlgorithms: []signatureAlgorithm{
6594 signatureRSAPSSWithSHA512,
6595 },
6596 },
6597 flags: []string{
6598 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6599 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6600 },
6601 shouldFail: true,
6602 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6603 })
David Benjamin57e929f2016-08-30 00:30:38 -04006604
6605 // Test that RSA-PSS is enabled by default for TLS 1.2.
6606 testCases = append(testCases, testCase{
6607 testType: clientTest,
6608 name: "RSA-PSS-Default-Verify",
6609 config: Config{
6610 MaxVersion: VersionTLS12,
6611 SignSignatureAlgorithms: []signatureAlgorithm{
6612 signatureRSAPSSWithSHA256,
6613 },
6614 },
6615 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6616 })
6617
6618 testCases = append(testCases, testCase{
6619 testType: serverTest,
6620 name: "RSA-PSS-Default-Sign",
6621 config: Config{
6622 MaxVersion: VersionTLS12,
6623 VerifySignatureAlgorithms: []signatureAlgorithm{
6624 signatureRSAPSSWithSHA256,
6625 },
6626 },
6627 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6628 })
David Benjamin000800a2014-11-14 01:43:59 -05006629}
6630
David Benjamin83f90402015-01-27 01:09:43 -05006631// timeouts is the retransmit schedule for BoringSSL. It doubles and
6632// caps at 60 seconds. On the 13th timeout, it gives up.
6633var timeouts = []time.Duration{
6634 1 * time.Second,
6635 2 * time.Second,
6636 4 * time.Second,
6637 8 * time.Second,
6638 16 * time.Second,
6639 32 * time.Second,
6640 60 * time.Second,
6641 60 * time.Second,
6642 60 * time.Second,
6643 60 * time.Second,
6644 60 * time.Second,
6645 60 * time.Second,
6646 60 * time.Second,
6647}
6648
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006649// shortTimeouts is an alternate set of timeouts which would occur if the
6650// initial timeout duration was set to 250ms.
6651var shortTimeouts = []time.Duration{
6652 250 * time.Millisecond,
6653 500 * time.Millisecond,
6654 1 * time.Second,
6655 2 * time.Second,
6656 4 * time.Second,
6657 8 * time.Second,
6658 16 * time.Second,
6659 32 * time.Second,
6660 60 * time.Second,
6661 60 * time.Second,
6662 60 * time.Second,
6663 60 * time.Second,
6664 60 * time.Second,
6665}
6666
David Benjamin83f90402015-01-27 01:09:43 -05006667func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006668 // These tests work by coordinating some behavior on both the shim and
6669 // the runner.
6670 //
6671 // TimeoutSchedule configures the runner to send a series of timeout
6672 // opcodes to the shim (see packetAdaptor) immediately before reading
6673 // each peer handshake flight N. The timeout opcode both simulates a
6674 // timeout in the shim and acts as a synchronization point to help the
6675 // runner bracket each handshake flight.
6676 //
6677 // We assume the shim does not read from the channel eagerly. It must
6678 // first wait until it has sent flight N and is ready to receive
6679 // handshake flight N+1. At this point, it will process the timeout
6680 // opcode. It must then immediately respond with a timeout ACK and act
6681 // as if the shim was idle for the specified amount of time.
6682 //
6683 // The runner then drops all packets received before the ACK and
6684 // continues waiting for flight N. This ordering results in one attempt
6685 // at sending flight N to be dropped. For the test to complete, the
6686 // shim must send flight N again, testing that the shim implements DTLS
6687 // retransmit on a timeout.
6688
Steven Valdez143e8b32016-07-11 13:19:03 -04006689 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006690 // likely be more epochs to cross and the final message's retransmit may
6691 // be more complex.
6692
David Benjamin585d7a42016-06-02 14:58:00 -04006693 for _, async := range []bool{true, false} {
6694 var tests []testCase
6695
6696 // Test that this is indeed the timeout schedule. Stress all
6697 // four patterns of handshake.
6698 for i := 1; i < len(timeouts); i++ {
6699 number := strconv.Itoa(i)
6700 tests = append(tests, testCase{
6701 protocol: dtls,
6702 name: "DTLS-Retransmit-Client-" + number,
6703 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006704 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006705 Bugs: ProtocolBugs{
6706 TimeoutSchedule: timeouts[:i],
6707 },
6708 },
6709 resumeSession: true,
6710 })
6711 tests = append(tests, testCase{
6712 protocol: dtls,
6713 testType: serverTest,
6714 name: "DTLS-Retransmit-Server-" + number,
6715 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006716 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006717 Bugs: ProtocolBugs{
6718 TimeoutSchedule: timeouts[:i],
6719 },
6720 },
6721 resumeSession: true,
6722 })
6723 }
6724
6725 // Test that exceeding the timeout schedule hits a read
6726 // timeout.
6727 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006728 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006729 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006731 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006732 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006733 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006734 },
6735 },
6736 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006737 shouldFail: true,
6738 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006739 })
David Benjamin585d7a42016-06-02 14:58:00 -04006740
6741 if async {
6742 // Test that timeout handling has a fudge factor, due to API
6743 // problems.
6744 tests = append(tests, testCase{
6745 protocol: dtls,
6746 name: "DTLS-Retransmit-Fudge",
6747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006748 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006749 Bugs: ProtocolBugs{
6750 TimeoutSchedule: []time.Duration{
6751 timeouts[0] - 10*time.Millisecond,
6752 },
6753 },
6754 },
6755 resumeSession: true,
6756 })
6757 }
6758
6759 // Test that the final Finished retransmitting isn't
6760 // duplicated if the peer badly fragments everything.
6761 tests = append(tests, testCase{
6762 testType: serverTest,
6763 protocol: dtls,
6764 name: "DTLS-Retransmit-Fragmented",
6765 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006766 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006767 Bugs: ProtocolBugs{
6768 TimeoutSchedule: []time.Duration{timeouts[0]},
6769 MaxHandshakeRecordLength: 2,
6770 },
6771 },
6772 })
6773
6774 // Test the timeout schedule when a shorter initial timeout duration is set.
6775 tests = append(tests, testCase{
6776 protocol: dtls,
6777 name: "DTLS-Retransmit-Short-Client",
6778 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006779 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006780 Bugs: ProtocolBugs{
6781 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6782 },
6783 },
6784 resumeSession: true,
6785 flags: []string{"-initial-timeout-duration-ms", "250"},
6786 })
6787 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006788 protocol: dtls,
6789 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006790 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006791 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006792 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006793 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006794 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006795 },
6796 },
6797 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006798 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006799 })
David Benjamin585d7a42016-06-02 14:58:00 -04006800
6801 for _, test := range tests {
6802 if async {
6803 test.name += "-Async"
6804 test.flags = append(test.flags, "-async")
6805 }
6806
6807 testCases = append(testCases, test)
6808 }
David Benjamin83f90402015-01-27 01:09:43 -05006809 }
David Benjamin83f90402015-01-27 01:09:43 -05006810}
6811
David Benjaminc565ebb2015-04-03 04:06:36 -04006812func addExportKeyingMaterialTests() {
6813 for _, vers := range tlsVersions {
6814 if vers.version == VersionSSL30 {
6815 continue
6816 }
6817 testCases = append(testCases, testCase{
6818 name: "ExportKeyingMaterial-" + vers.name,
6819 config: Config{
6820 MaxVersion: vers.version,
6821 },
6822 exportKeyingMaterial: 1024,
6823 exportLabel: "label",
6824 exportContext: "context",
6825 useExportContext: true,
6826 })
6827 testCases = append(testCases, testCase{
6828 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6829 config: Config{
6830 MaxVersion: vers.version,
6831 },
6832 exportKeyingMaterial: 1024,
6833 })
6834 testCases = append(testCases, testCase{
6835 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6836 config: Config{
6837 MaxVersion: vers.version,
6838 },
6839 exportKeyingMaterial: 1024,
6840 useExportContext: true,
6841 })
6842 testCases = append(testCases, testCase{
6843 name: "ExportKeyingMaterial-Small-" + vers.name,
6844 config: Config{
6845 MaxVersion: vers.version,
6846 },
6847 exportKeyingMaterial: 1,
6848 exportLabel: "label",
6849 exportContext: "context",
6850 useExportContext: true,
6851 })
6852 }
6853 testCases = append(testCases, testCase{
6854 name: "ExportKeyingMaterial-SSL3",
6855 config: Config{
6856 MaxVersion: VersionSSL30,
6857 },
6858 exportKeyingMaterial: 1024,
6859 exportLabel: "label",
6860 exportContext: "context",
6861 useExportContext: true,
6862 shouldFail: true,
6863 expectedError: "failed to export keying material",
6864 })
6865}
6866
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006867func addTLSUniqueTests() {
6868 for _, isClient := range []bool{false, true} {
6869 for _, isResumption := range []bool{false, true} {
6870 for _, hasEMS := range []bool{false, true} {
6871 var suffix string
6872 if isResumption {
6873 suffix = "Resume-"
6874 } else {
6875 suffix = "Full-"
6876 }
6877
6878 if hasEMS {
6879 suffix += "EMS-"
6880 } else {
6881 suffix += "NoEMS-"
6882 }
6883
6884 if isClient {
6885 suffix += "Client"
6886 } else {
6887 suffix += "Server"
6888 }
6889
6890 test := testCase{
6891 name: "TLSUnique-" + suffix,
6892 testTLSUnique: true,
6893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006894 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006895 Bugs: ProtocolBugs{
6896 NoExtendedMasterSecret: !hasEMS,
6897 },
6898 },
6899 }
6900
6901 if isResumption {
6902 test.resumeSession = true
6903 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006904 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006905 Bugs: ProtocolBugs{
6906 NoExtendedMasterSecret: !hasEMS,
6907 },
6908 }
6909 }
6910
6911 if isResumption && !hasEMS {
6912 test.shouldFail = true
6913 test.expectedError = "failed to get tls-unique"
6914 }
6915
6916 testCases = append(testCases, test)
6917 }
6918 }
6919 }
6920}
6921
Adam Langley09505632015-07-30 18:10:13 -07006922func addCustomExtensionTests() {
6923 expectedContents := "custom extension"
6924 emptyString := ""
6925
6926 for _, isClient := range []bool{false, true} {
6927 suffix := "Server"
6928 flag := "-enable-server-custom-extension"
6929 testType := serverTest
6930 if isClient {
6931 suffix = "Client"
6932 flag = "-enable-client-custom-extension"
6933 testType = clientTest
6934 }
6935
6936 testCases = append(testCases, testCase{
6937 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006938 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006940 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006941 Bugs: ProtocolBugs{
6942 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006943 ExpectedCustomExtension: &expectedContents,
6944 },
6945 },
6946 flags: []string{flag},
6947 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006948 testCases = append(testCases, testCase{
6949 testType: testType,
6950 name: "CustomExtensions-" + suffix + "-TLS13",
6951 config: Config{
6952 MaxVersion: VersionTLS13,
6953 Bugs: ProtocolBugs{
6954 CustomExtension: expectedContents,
6955 ExpectedCustomExtension: &expectedContents,
6956 },
6957 },
6958 flags: []string{flag},
6959 })
Adam Langley09505632015-07-30 18:10:13 -07006960
6961 // If the parse callback fails, the handshake should also fail.
6962 testCases = append(testCases, testCase{
6963 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006964 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006966 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006967 Bugs: ProtocolBugs{
6968 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006969 ExpectedCustomExtension: &expectedContents,
6970 },
6971 },
David Benjamin399e7c92015-07-30 23:01:27 -04006972 flags: []string{flag},
6973 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006974 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6975 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006976 testCases = append(testCases, testCase{
6977 testType: testType,
6978 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6979 config: Config{
6980 MaxVersion: VersionTLS13,
6981 Bugs: ProtocolBugs{
6982 CustomExtension: expectedContents + "foo",
6983 ExpectedCustomExtension: &expectedContents,
6984 },
6985 },
6986 flags: []string{flag},
6987 shouldFail: true,
6988 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6989 })
Adam Langley09505632015-07-30 18:10:13 -07006990
6991 // If the add callback fails, the handshake should also fail.
6992 testCases = append(testCases, testCase{
6993 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006994 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006995 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006996 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006997 Bugs: ProtocolBugs{
6998 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006999 ExpectedCustomExtension: &expectedContents,
7000 },
7001 },
David Benjamin399e7c92015-07-30 23:01:27 -04007002 flags: []string{flag, "-custom-extension-fail-add"},
7003 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007004 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7005 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007006 testCases = append(testCases, testCase{
7007 testType: testType,
7008 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7009 config: Config{
7010 MaxVersion: VersionTLS13,
7011 Bugs: ProtocolBugs{
7012 CustomExtension: expectedContents,
7013 ExpectedCustomExtension: &expectedContents,
7014 },
7015 },
7016 flags: []string{flag, "-custom-extension-fail-add"},
7017 shouldFail: true,
7018 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7019 })
Adam Langley09505632015-07-30 18:10:13 -07007020
7021 // If the add callback returns zero, no extension should be
7022 // added.
7023 skipCustomExtension := expectedContents
7024 if isClient {
7025 // For the case where the client skips sending the
7026 // custom extension, the server must not “echo” it.
7027 skipCustomExtension = ""
7028 }
7029 testCases = append(testCases, testCase{
7030 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007031 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007032 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007033 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007034 Bugs: ProtocolBugs{
7035 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007036 ExpectedCustomExtension: &emptyString,
7037 },
7038 },
7039 flags: []string{flag, "-custom-extension-skip"},
7040 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007041 testCases = append(testCases, testCase{
7042 testType: testType,
7043 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7044 config: Config{
7045 MaxVersion: VersionTLS13,
7046 Bugs: ProtocolBugs{
7047 CustomExtension: skipCustomExtension,
7048 ExpectedCustomExtension: &emptyString,
7049 },
7050 },
7051 flags: []string{flag, "-custom-extension-skip"},
7052 })
Adam Langley09505632015-07-30 18:10:13 -07007053 }
7054
7055 // The custom extension add callback should not be called if the client
7056 // doesn't send the extension.
7057 testCases = append(testCases, testCase{
7058 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007059 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007060 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007061 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007062 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007063 ExpectedCustomExtension: &emptyString,
7064 },
7065 },
7066 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7067 })
Adam Langley2deb9842015-08-07 11:15:37 -07007068
Steven Valdez143e8b32016-07-11 13:19:03 -04007069 testCases = append(testCases, testCase{
7070 testType: serverTest,
7071 name: "CustomExtensions-NotCalled-Server-TLS13",
7072 config: Config{
7073 MaxVersion: VersionTLS13,
7074 Bugs: ProtocolBugs{
7075 ExpectedCustomExtension: &emptyString,
7076 },
7077 },
7078 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7079 })
7080
Adam Langley2deb9842015-08-07 11:15:37 -07007081 // Test an unknown extension from the server.
7082 testCases = append(testCases, testCase{
7083 testType: clientTest,
7084 name: "UnknownExtension-Client",
7085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007086 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007087 Bugs: ProtocolBugs{
7088 CustomExtension: expectedContents,
7089 },
7090 },
David Benjamin0c40a962016-08-01 12:05:50 -04007091 shouldFail: true,
7092 expectedError: ":UNEXPECTED_EXTENSION:",
7093 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007094 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007095 testCases = append(testCases, testCase{
7096 testType: clientTest,
7097 name: "UnknownExtension-Client-TLS13",
7098 config: Config{
7099 MaxVersion: VersionTLS13,
7100 Bugs: ProtocolBugs{
7101 CustomExtension: expectedContents,
7102 },
7103 },
David Benjamin0c40a962016-08-01 12:05:50 -04007104 shouldFail: true,
7105 expectedError: ":UNEXPECTED_EXTENSION:",
7106 expectedLocalError: "remote error: unsupported extension",
7107 })
7108
7109 // Test a known but unoffered extension from the server.
7110 testCases = append(testCases, testCase{
7111 testType: clientTest,
7112 name: "UnofferedExtension-Client",
7113 config: Config{
7114 MaxVersion: VersionTLS12,
7115 Bugs: ProtocolBugs{
7116 SendALPN: "alpn",
7117 },
7118 },
7119 shouldFail: true,
7120 expectedError: ":UNEXPECTED_EXTENSION:",
7121 expectedLocalError: "remote error: unsupported extension",
7122 })
7123 testCases = append(testCases, testCase{
7124 testType: clientTest,
7125 name: "UnofferedExtension-Client-TLS13",
7126 config: Config{
7127 MaxVersion: VersionTLS13,
7128 Bugs: ProtocolBugs{
7129 SendALPN: "alpn",
7130 },
7131 },
7132 shouldFail: true,
7133 expectedError: ":UNEXPECTED_EXTENSION:",
7134 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007135 })
Adam Langley09505632015-07-30 18:10:13 -07007136}
7137
David Benjaminb36a3952015-12-01 18:53:13 -05007138func addRSAClientKeyExchangeTests() {
7139 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7140 testCases = append(testCases, testCase{
7141 testType: serverTest,
7142 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7143 config: Config{
7144 // Ensure the ClientHello version and final
7145 // version are different, to detect if the
7146 // server uses the wrong one.
7147 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007148 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007149 Bugs: ProtocolBugs{
7150 BadRSAClientKeyExchange: bad,
7151 },
7152 },
7153 shouldFail: true,
7154 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7155 })
7156 }
David Benjamine63d9d72016-09-19 18:27:34 -04007157
7158 // The server must compare whatever was in ClientHello.version for the
7159 // RSA premaster.
7160 testCases = append(testCases, testCase{
7161 testType: serverTest,
7162 name: "SendClientVersion-RSA",
7163 config: Config{
7164 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7165 Bugs: ProtocolBugs{
7166 SendClientVersion: 0x1234,
7167 },
7168 },
7169 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7170 })
David Benjaminb36a3952015-12-01 18:53:13 -05007171}
7172
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007173var testCurves = []struct {
7174 name string
7175 id CurveID
7176}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007177 {"P-256", CurveP256},
7178 {"P-384", CurveP384},
7179 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007180 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007181}
7182
Steven Valdez5440fe02016-07-18 12:40:30 -04007183const bogusCurve = 0x1234
7184
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007185func addCurveTests() {
7186 for _, curve := range testCurves {
7187 testCases = append(testCases, testCase{
7188 name: "CurveTest-Client-" + curve.name,
7189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007190 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007191 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7192 CurvePreferences: []CurveID{curve.id},
7193 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007194 flags: []string{
7195 "-enable-all-curves",
7196 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7197 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007198 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007199 })
7200 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007201 name: "CurveTest-Client-" + curve.name + "-TLS13",
7202 config: Config{
7203 MaxVersion: VersionTLS13,
7204 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7205 CurvePreferences: []CurveID{curve.id},
7206 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007207 flags: []string{
7208 "-enable-all-curves",
7209 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7210 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007211 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007212 })
7213 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007214 testType: serverTest,
7215 name: "CurveTest-Server-" + curve.name,
7216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007217 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007218 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7219 CurvePreferences: []CurveID{curve.id},
7220 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007221 flags: []string{
7222 "-enable-all-curves",
7223 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7224 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007225 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007226 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007227 testCases = append(testCases, testCase{
7228 testType: serverTest,
7229 name: "CurveTest-Server-" + curve.name + "-TLS13",
7230 config: Config{
7231 MaxVersion: VersionTLS13,
7232 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7233 CurvePreferences: []CurveID{curve.id},
7234 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007235 flags: []string{
7236 "-enable-all-curves",
7237 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7238 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007239 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007240 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007241 }
David Benjamin241ae832016-01-15 03:04:54 -05007242
7243 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007244 testCases = append(testCases, testCase{
7245 testType: serverTest,
7246 name: "UnknownCurve",
7247 config: Config{
7248 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7249 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7250 },
7251 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007252
7253 // The server must not consider ECDHE ciphers when there are no
7254 // supported curves.
7255 testCases = append(testCases, testCase{
7256 testType: serverTest,
7257 name: "NoSupportedCurves",
7258 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007259 MaxVersion: VersionTLS12,
7260 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7261 Bugs: ProtocolBugs{
7262 NoSupportedCurves: true,
7263 },
7264 },
7265 shouldFail: true,
7266 expectedError: ":NO_SHARED_CIPHER:",
7267 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007268 testCases = append(testCases, testCase{
7269 testType: serverTest,
7270 name: "NoSupportedCurves-TLS13",
7271 config: Config{
7272 MaxVersion: VersionTLS13,
7273 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7274 Bugs: ProtocolBugs{
7275 NoSupportedCurves: true,
7276 },
7277 },
7278 shouldFail: true,
7279 expectedError: ":NO_SHARED_CIPHER:",
7280 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007281
7282 // The server must fall back to another cipher when there are no
7283 // supported curves.
7284 testCases = append(testCases, testCase{
7285 testType: serverTest,
7286 name: "NoCommonCurves",
7287 config: Config{
7288 MaxVersion: VersionTLS12,
7289 CipherSuites: []uint16{
7290 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7291 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7292 },
7293 CurvePreferences: []CurveID{CurveP224},
7294 },
7295 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7296 })
7297
7298 // The client must reject bogus curves and disabled curves.
7299 testCases = append(testCases, testCase{
7300 name: "BadECDHECurve",
7301 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007302 MaxVersion: VersionTLS12,
7303 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7304 Bugs: ProtocolBugs{
7305 SendCurve: bogusCurve,
7306 },
7307 },
7308 shouldFail: true,
7309 expectedError: ":WRONG_CURVE:",
7310 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007311 testCases = append(testCases, testCase{
7312 name: "BadECDHECurve-TLS13",
7313 config: Config{
7314 MaxVersion: VersionTLS13,
7315 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7316 Bugs: ProtocolBugs{
7317 SendCurve: bogusCurve,
7318 },
7319 },
7320 shouldFail: true,
7321 expectedError: ":WRONG_CURVE:",
7322 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007323
7324 testCases = append(testCases, testCase{
7325 name: "UnsupportedCurve",
7326 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007327 MaxVersion: VersionTLS12,
7328 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7329 CurvePreferences: []CurveID{CurveP256},
7330 Bugs: ProtocolBugs{
7331 IgnorePeerCurvePreferences: true,
7332 },
7333 },
7334 flags: []string{"-p384-only"},
7335 shouldFail: true,
7336 expectedError: ":WRONG_CURVE:",
7337 })
7338
David Benjamin4f921572016-07-17 14:20:10 +02007339 testCases = append(testCases, testCase{
7340 // TODO(davidben): Add a TLS 1.3 version where
7341 // HelloRetryRequest requests an unsupported curve.
7342 name: "UnsupportedCurve-ServerHello-TLS13",
7343 config: Config{
7344 MaxVersion: VersionTLS12,
7345 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7346 CurvePreferences: []CurveID{CurveP384},
7347 Bugs: ProtocolBugs{
7348 SendCurve: CurveP256,
7349 },
7350 },
7351 flags: []string{"-p384-only"},
7352 shouldFail: true,
7353 expectedError: ":WRONG_CURVE:",
7354 })
7355
David Benjamin4c3ddf72016-06-29 18:13:53 -04007356 // Test invalid curve points.
7357 testCases = append(testCases, testCase{
7358 name: "InvalidECDHPoint-Client",
7359 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007360 MaxVersion: VersionTLS12,
7361 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7362 CurvePreferences: []CurveID{CurveP256},
7363 Bugs: ProtocolBugs{
7364 InvalidECDHPoint: true,
7365 },
7366 },
7367 shouldFail: true,
7368 expectedError: ":INVALID_ENCODING:",
7369 })
7370 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007371 name: "InvalidECDHPoint-Client-TLS13",
7372 config: Config{
7373 MaxVersion: VersionTLS13,
7374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7375 CurvePreferences: []CurveID{CurveP256},
7376 Bugs: ProtocolBugs{
7377 InvalidECDHPoint: true,
7378 },
7379 },
7380 shouldFail: true,
7381 expectedError: ":INVALID_ENCODING:",
7382 })
7383 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007384 testType: serverTest,
7385 name: "InvalidECDHPoint-Server",
7386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007387 MaxVersion: VersionTLS12,
7388 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7389 CurvePreferences: []CurveID{CurveP256},
7390 Bugs: ProtocolBugs{
7391 InvalidECDHPoint: true,
7392 },
7393 },
7394 shouldFail: true,
7395 expectedError: ":INVALID_ENCODING:",
7396 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007397 testCases = append(testCases, testCase{
7398 testType: serverTest,
7399 name: "InvalidECDHPoint-Server-TLS13",
7400 config: Config{
7401 MaxVersion: VersionTLS13,
7402 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7403 CurvePreferences: []CurveID{CurveP256},
7404 Bugs: ProtocolBugs{
7405 InvalidECDHPoint: true,
7406 },
7407 },
7408 shouldFail: true,
7409 expectedError: ":INVALID_ENCODING:",
7410 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007411}
7412
Matt Braithwaite54217e42016-06-13 13:03:47 -07007413func addCECPQ1Tests() {
7414 testCases = append(testCases, testCase{
7415 testType: clientTest,
7416 name: "CECPQ1-Client-BadX25519Part",
7417 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007418 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007419 MinVersion: VersionTLS12,
7420 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7421 Bugs: ProtocolBugs{
7422 CECPQ1BadX25519Part: true,
7423 },
7424 },
7425 flags: []string{"-cipher", "kCECPQ1"},
7426 shouldFail: true,
7427 expectedLocalError: "local error: bad record MAC",
7428 })
7429 testCases = append(testCases, testCase{
7430 testType: clientTest,
7431 name: "CECPQ1-Client-BadNewhopePart",
7432 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007433 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007434 MinVersion: VersionTLS12,
7435 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7436 Bugs: ProtocolBugs{
7437 CECPQ1BadNewhopePart: true,
7438 },
7439 },
7440 flags: []string{"-cipher", "kCECPQ1"},
7441 shouldFail: true,
7442 expectedLocalError: "local error: bad record MAC",
7443 })
7444 testCases = append(testCases, testCase{
7445 testType: serverTest,
7446 name: "CECPQ1-Server-BadX25519Part",
7447 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007448 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007449 MinVersion: VersionTLS12,
7450 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7451 Bugs: ProtocolBugs{
7452 CECPQ1BadX25519Part: true,
7453 },
7454 },
7455 flags: []string{"-cipher", "kCECPQ1"},
7456 shouldFail: true,
7457 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7458 })
7459 testCases = append(testCases, testCase{
7460 testType: serverTest,
7461 name: "CECPQ1-Server-BadNewhopePart",
7462 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007463 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007464 MinVersion: VersionTLS12,
7465 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7466 Bugs: ProtocolBugs{
7467 CECPQ1BadNewhopePart: true,
7468 },
7469 },
7470 flags: []string{"-cipher", "kCECPQ1"},
7471 shouldFail: true,
7472 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7473 })
7474}
7475
David Benjamin5c4e8572016-08-19 17:44:53 -04007476func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007477 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007478 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007479 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007480 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007481 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7482 Bugs: ProtocolBugs{
7483 // This is a 1234-bit prime number, generated
7484 // with:
7485 // openssl gendh 1234 | openssl asn1parse -i
7486 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7487 },
7488 },
David Benjamin9e68f192016-06-30 14:55:33 -04007489 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007490 })
7491 testCases = append(testCases, testCase{
7492 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007493 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007494 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007495 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007496 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7497 },
7498 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007499 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007500 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007501}
7502
David Benjaminc9ae27c2016-06-24 22:56:37 -04007503func addTLS13RecordTests() {
7504 testCases = append(testCases, testCase{
7505 name: "TLS13-RecordPadding",
7506 config: Config{
7507 MaxVersion: VersionTLS13,
7508 MinVersion: VersionTLS13,
7509 Bugs: ProtocolBugs{
7510 RecordPadding: 10,
7511 },
7512 },
7513 })
7514
7515 testCases = append(testCases, testCase{
7516 name: "TLS13-EmptyRecords",
7517 config: Config{
7518 MaxVersion: VersionTLS13,
7519 MinVersion: VersionTLS13,
7520 Bugs: ProtocolBugs{
7521 OmitRecordContents: true,
7522 },
7523 },
7524 shouldFail: true,
7525 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7526 })
7527
7528 testCases = append(testCases, testCase{
7529 name: "TLS13-OnlyPadding",
7530 config: Config{
7531 MaxVersion: VersionTLS13,
7532 MinVersion: VersionTLS13,
7533 Bugs: ProtocolBugs{
7534 OmitRecordContents: true,
7535 RecordPadding: 10,
7536 },
7537 },
7538 shouldFail: true,
7539 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7540 })
7541
7542 testCases = append(testCases, testCase{
7543 name: "TLS13-WrongOuterRecord",
7544 config: Config{
7545 MaxVersion: VersionTLS13,
7546 MinVersion: VersionTLS13,
7547 Bugs: ProtocolBugs{
7548 OuterRecordType: recordTypeHandshake,
7549 },
7550 },
7551 shouldFail: true,
7552 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7553 })
7554}
7555
David Benjamin82261be2016-07-07 14:32:50 -07007556func addChangeCipherSpecTests() {
7557 // Test missing ChangeCipherSpecs.
7558 testCases = append(testCases, testCase{
7559 name: "SkipChangeCipherSpec-Client",
7560 config: Config{
7561 MaxVersion: VersionTLS12,
7562 Bugs: ProtocolBugs{
7563 SkipChangeCipherSpec: true,
7564 },
7565 },
7566 shouldFail: true,
7567 expectedError: ":UNEXPECTED_RECORD:",
7568 })
7569 testCases = append(testCases, testCase{
7570 testType: serverTest,
7571 name: "SkipChangeCipherSpec-Server",
7572 config: Config{
7573 MaxVersion: VersionTLS12,
7574 Bugs: ProtocolBugs{
7575 SkipChangeCipherSpec: true,
7576 },
7577 },
7578 shouldFail: true,
7579 expectedError: ":UNEXPECTED_RECORD:",
7580 })
7581 testCases = append(testCases, testCase{
7582 testType: serverTest,
7583 name: "SkipChangeCipherSpec-Server-NPN",
7584 config: Config{
7585 MaxVersion: VersionTLS12,
7586 NextProtos: []string{"bar"},
7587 Bugs: ProtocolBugs{
7588 SkipChangeCipherSpec: true,
7589 },
7590 },
7591 flags: []string{
7592 "-advertise-npn", "\x03foo\x03bar\x03baz",
7593 },
7594 shouldFail: true,
7595 expectedError: ":UNEXPECTED_RECORD:",
7596 })
7597
7598 // Test synchronization between the handshake and ChangeCipherSpec.
7599 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7600 // rejected. Test both with and without handshake packing to handle both
7601 // when the partial post-CCS message is in its own record and when it is
7602 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007603 for _, packed := range []bool{false, true} {
7604 var suffix string
7605 if packed {
7606 suffix = "-Packed"
7607 }
7608
7609 testCases = append(testCases, testCase{
7610 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7611 config: Config{
7612 MaxVersion: VersionTLS12,
7613 Bugs: ProtocolBugs{
7614 FragmentAcrossChangeCipherSpec: true,
7615 PackHandshakeFlight: packed,
7616 },
7617 },
7618 shouldFail: true,
7619 expectedError: ":UNEXPECTED_RECORD:",
7620 })
7621 testCases = append(testCases, testCase{
7622 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7623 config: Config{
7624 MaxVersion: VersionTLS12,
7625 },
7626 resumeSession: true,
7627 resumeConfig: &Config{
7628 MaxVersion: VersionTLS12,
7629 Bugs: ProtocolBugs{
7630 FragmentAcrossChangeCipherSpec: true,
7631 PackHandshakeFlight: packed,
7632 },
7633 },
7634 shouldFail: true,
7635 expectedError: ":UNEXPECTED_RECORD:",
7636 })
7637 testCases = append(testCases, testCase{
7638 testType: serverTest,
7639 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7640 config: Config{
7641 MaxVersion: VersionTLS12,
7642 Bugs: ProtocolBugs{
7643 FragmentAcrossChangeCipherSpec: true,
7644 PackHandshakeFlight: packed,
7645 },
7646 },
7647 shouldFail: true,
7648 expectedError: ":UNEXPECTED_RECORD:",
7649 })
7650 testCases = append(testCases, testCase{
7651 testType: serverTest,
7652 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7653 config: Config{
7654 MaxVersion: VersionTLS12,
7655 },
7656 resumeSession: true,
7657 resumeConfig: &Config{
7658 MaxVersion: VersionTLS12,
7659 Bugs: ProtocolBugs{
7660 FragmentAcrossChangeCipherSpec: true,
7661 PackHandshakeFlight: packed,
7662 },
7663 },
7664 shouldFail: true,
7665 expectedError: ":UNEXPECTED_RECORD:",
7666 })
7667 testCases = append(testCases, testCase{
7668 testType: serverTest,
7669 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7670 config: Config{
7671 MaxVersion: VersionTLS12,
7672 NextProtos: []string{"bar"},
7673 Bugs: ProtocolBugs{
7674 FragmentAcrossChangeCipherSpec: true,
7675 PackHandshakeFlight: packed,
7676 },
7677 },
7678 flags: []string{
7679 "-advertise-npn", "\x03foo\x03bar\x03baz",
7680 },
7681 shouldFail: true,
7682 expectedError: ":UNEXPECTED_RECORD:",
7683 })
7684 }
7685
David Benjamin61672812016-07-14 23:10:43 -04007686 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7687 // messages in the handshake queue. Do this by testing the server
7688 // reading the client Finished, reversing the flight so Finished comes
7689 // first.
7690 testCases = append(testCases, testCase{
7691 protocol: dtls,
7692 testType: serverTest,
7693 name: "SendUnencryptedFinished-DTLS",
7694 config: Config{
7695 MaxVersion: VersionTLS12,
7696 Bugs: ProtocolBugs{
7697 SendUnencryptedFinished: true,
7698 ReverseHandshakeFragments: true,
7699 },
7700 },
7701 shouldFail: true,
7702 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7703 })
7704
Steven Valdez143e8b32016-07-11 13:19:03 -04007705 // Test synchronization between encryption changes and the handshake in
7706 // TLS 1.3, where ChangeCipherSpec is implicit.
7707 testCases = append(testCases, testCase{
7708 name: "PartialEncryptedExtensionsWithServerHello",
7709 config: Config{
7710 MaxVersion: VersionTLS13,
7711 Bugs: ProtocolBugs{
7712 PartialEncryptedExtensionsWithServerHello: true,
7713 },
7714 },
7715 shouldFail: true,
7716 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7717 })
7718 testCases = append(testCases, testCase{
7719 testType: serverTest,
7720 name: "PartialClientFinishedWithClientHello",
7721 config: Config{
7722 MaxVersion: VersionTLS13,
7723 Bugs: ProtocolBugs{
7724 PartialClientFinishedWithClientHello: true,
7725 },
7726 },
7727 shouldFail: true,
7728 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7729 })
7730
David Benjamin82261be2016-07-07 14:32:50 -07007731 // Test that early ChangeCipherSpecs are handled correctly.
7732 testCases = append(testCases, testCase{
7733 testType: serverTest,
7734 name: "EarlyChangeCipherSpec-server-1",
7735 config: Config{
7736 MaxVersion: VersionTLS12,
7737 Bugs: ProtocolBugs{
7738 EarlyChangeCipherSpec: 1,
7739 },
7740 },
7741 shouldFail: true,
7742 expectedError: ":UNEXPECTED_RECORD:",
7743 })
7744 testCases = append(testCases, testCase{
7745 testType: serverTest,
7746 name: "EarlyChangeCipherSpec-server-2",
7747 config: Config{
7748 MaxVersion: VersionTLS12,
7749 Bugs: ProtocolBugs{
7750 EarlyChangeCipherSpec: 2,
7751 },
7752 },
7753 shouldFail: true,
7754 expectedError: ":UNEXPECTED_RECORD:",
7755 })
7756 testCases = append(testCases, testCase{
7757 protocol: dtls,
7758 name: "StrayChangeCipherSpec",
7759 config: Config{
7760 // TODO(davidben): Once DTLS 1.3 exists, test
7761 // that stray ChangeCipherSpec messages are
7762 // rejected.
7763 MaxVersion: VersionTLS12,
7764 Bugs: ProtocolBugs{
7765 StrayChangeCipherSpec: true,
7766 },
7767 },
7768 })
7769
7770 // Test that the contents of ChangeCipherSpec are checked.
7771 testCases = append(testCases, testCase{
7772 name: "BadChangeCipherSpec-1",
7773 config: Config{
7774 MaxVersion: VersionTLS12,
7775 Bugs: ProtocolBugs{
7776 BadChangeCipherSpec: []byte{2},
7777 },
7778 },
7779 shouldFail: true,
7780 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7781 })
7782 testCases = append(testCases, testCase{
7783 name: "BadChangeCipherSpec-2",
7784 config: Config{
7785 MaxVersion: VersionTLS12,
7786 Bugs: ProtocolBugs{
7787 BadChangeCipherSpec: []byte{1, 1},
7788 },
7789 },
7790 shouldFail: true,
7791 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7792 })
7793 testCases = append(testCases, testCase{
7794 protocol: dtls,
7795 name: "BadChangeCipherSpec-DTLS-1",
7796 config: Config{
7797 MaxVersion: VersionTLS12,
7798 Bugs: ProtocolBugs{
7799 BadChangeCipherSpec: []byte{2},
7800 },
7801 },
7802 shouldFail: true,
7803 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7804 })
7805 testCases = append(testCases, testCase{
7806 protocol: dtls,
7807 name: "BadChangeCipherSpec-DTLS-2",
7808 config: Config{
7809 MaxVersion: VersionTLS12,
7810 Bugs: ProtocolBugs{
7811 BadChangeCipherSpec: []byte{1, 1},
7812 },
7813 },
7814 shouldFail: true,
7815 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7816 })
7817}
7818
David Benjamincd2c8062016-09-09 11:28:16 -04007819type perMessageTest struct {
7820 messageType uint8
7821 test testCase
7822}
7823
7824// makePerMessageTests returns a series of test templates which cover each
7825// message in the TLS handshake. These may be used with bugs like
7826// WrongMessageType to fully test a per-message bug.
7827func makePerMessageTests() []perMessageTest {
7828 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007829 for _, protocol := range []protocol{tls, dtls} {
7830 var suffix string
7831 if protocol == dtls {
7832 suffix = "-DTLS"
7833 }
7834
David Benjamincd2c8062016-09-09 11:28:16 -04007835 ret = append(ret, perMessageTest{
7836 messageType: typeClientHello,
7837 test: testCase{
7838 protocol: protocol,
7839 testType: serverTest,
7840 name: "ClientHello" + suffix,
7841 config: Config{
7842 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007843 },
7844 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007845 })
7846
7847 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007848 ret = append(ret, perMessageTest{
7849 messageType: typeHelloVerifyRequest,
7850 test: testCase{
7851 protocol: protocol,
7852 name: "HelloVerifyRequest" + suffix,
7853 config: Config{
7854 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007855 },
7856 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007857 })
7858 }
7859
David Benjamincd2c8062016-09-09 11:28:16 -04007860 ret = append(ret, perMessageTest{
7861 messageType: typeServerHello,
7862 test: testCase{
7863 protocol: protocol,
7864 name: "ServerHello" + suffix,
7865 config: Config{
7866 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007867 },
7868 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007869 })
7870
David Benjamincd2c8062016-09-09 11:28:16 -04007871 ret = append(ret, perMessageTest{
7872 messageType: typeCertificate,
7873 test: testCase{
7874 protocol: protocol,
7875 name: "ServerCertificate" + suffix,
7876 config: Config{
7877 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007878 },
7879 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007880 })
7881
David Benjamincd2c8062016-09-09 11:28:16 -04007882 ret = append(ret, perMessageTest{
7883 messageType: typeCertificateStatus,
7884 test: testCase{
7885 protocol: protocol,
7886 name: "CertificateStatus" + suffix,
7887 config: Config{
7888 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007889 },
David Benjamincd2c8062016-09-09 11:28:16 -04007890 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007891 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007892 })
7893
David Benjamincd2c8062016-09-09 11:28:16 -04007894 ret = append(ret, perMessageTest{
7895 messageType: typeServerKeyExchange,
7896 test: testCase{
7897 protocol: protocol,
7898 name: "ServerKeyExchange" + suffix,
7899 config: Config{
7900 MaxVersion: VersionTLS12,
7901 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007902 },
7903 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007904 })
7905
David Benjamincd2c8062016-09-09 11:28:16 -04007906 ret = append(ret, perMessageTest{
7907 messageType: typeCertificateRequest,
7908 test: testCase{
7909 protocol: protocol,
7910 name: "CertificateRequest" + suffix,
7911 config: Config{
7912 MaxVersion: VersionTLS12,
7913 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007914 },
7915 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007916 })
7917
David Benjamincd2c8062016-09-09 11:28:16 -04007918 ret = append(ret, perMessageTest{
7919 messageType: typeServerHelloDone,
7920 test: testCase{
7921 protocol: protocol,
7922 name: "ServerHelloDone" + suffix,
7923 config: Config{
7924 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007925 },
7926 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007927 })
7928
David Benjamincd2c8062016-09-09 11:28:16 -04007929 ret = append(ret, perMessageTest{
7930 messageType: typeCertificate,
7931 test: testCase{
7932 testType: serverTest,
7933 protocol: protocol,
7934 name: "ClientCertificate" + suffix,
7935 config: Config{
7936 Certificates: []Certificate{rsaCertificate},
7937 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007938 },
David Benjamincd2c8062016-09-09 11:28:16 -04007939 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007940 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007941 })
7942
David Benjamincd2c8062016-09-09 11:28:16 -04007943 ret = append(ret, perMessageTest{
7944 messageType: typeCertificateVerify,
7945 test: testCase{
7946 testType: serverTest,
7947 protocol: protocol,
7948 name: "CertificateVerify" + suffix,
7949 config: Config{
7950 Certificates: []Certificate{rsaCertificate},
7951 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007952 },
David Benjamincd2c8062016-09-09 11:28:16 -04007953 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007954 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007955 })
7956
David Benjamincd2c8062016-09-09 11:28:16 -04007957 ret = append(ret, perMessageTest{
7958 messageType: typeClientKeyExchange,
7959 test: testCase{
7960 testType: serverTest,
7961 protocol: protocol,
7962 name: "ClientKeyExchange" + suffix,
7963 config: Config{
7964 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007965 },
7966 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007967 })
7968
7969 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007970 ret = append(ret, perMessageTest{
7971 messageType: typeNextProtocol,
7972 test: testCase{
7973 testType: serverTest,
7974 protocol: protocol,
7975 name: "NextProtocol" + suffix,
7976 config: Config{
7977 MaxVersion: VersionTLS12,
7978 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007979 },
David Benjamincd2c8062016-09-09 11:28:16 -04007980 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007981 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007982 })
7983
David Benjamincd2c8062016-09-09 11:28:16 -04007984 ret = append(ret, perMessageTest{
7985 messageType: typeChannelID,
7986 test: testCase{
7987 testType: serverTest,
7988 protocol: protocol,
7989 name: "ChannelID" + suffix,
7990 config: Config{
7991 MaxVersion: VersionTLS12,
7992 ChannelID: channelIDKey,
7993 },
7994 flags: []string{
7995 "-expect-channel-id",
7996 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007997 },
7998 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007999 })
8000 }
8001
David Benjamincd2c8062016-09-09 11:28:16 -04008002 ret = append(ret, perMessageTest{
8003 messageType: typeFinished,
8004 test: testCase{
8005 testType: serverTest,
8006 protocol: protocol,
8007 name: "ClientFinished" + suffix,
8008 config: Config{
8009 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008010 },
8011 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008012 })
8013
David Benjamincd2c8062016-09-09 11:28:16 -04008014 ret = append(ret, perMessageTest{
8015 messageType: typeNewSessionTicket,
8016 test: testCase{
8017 protocol: protocol,
8018 name: "NewSessionTicket" + suffix,
8019 config: Config{
8020 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008021 },
8022 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008023 })
8024
David Benjamincd2c8062016-09-09 11:28:16 -04008025 ret = append(ret, perMessageTest{
8026 messageType: typeFinished,
8027 test: testCase{
8028 protocol: protocol,
8029 name: "ServerFinished" + suffix,
8030 config: Config{
8031 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008032 },
8033 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008034 })
8035
8036 }
David Benjamincd2c8062016-09-09 11:28:16 -04008037
8038 ret = append(ret, perMessageTest{
8039 messageType: typeClientHello,
8040 test: testCase{
8041 testType: serverTest,
8042 name: "TLS13-ClientHello",
8043 config: Config{
8044 MaxVersion: VersionTLS13,
8045 },
8046 },
8047 })
8048
8049 ret = append(ret, perMessageTest{
8050 messageType: typeServerHello,
8051 test: testCase{
8052 name: "TLS13-ServerHello",
8053 config: Config{
8054 MaxVersion: VersionTLS13,
8055 },
8056 },
8057 })
8058
8059 ret = append(ret, perMessageTest{
8060 messageType: typeEncryptedExtensions,
8061 test: testCase{
8062 name: "TLS13-EncryptedExtensions",
8063 config: Config{
8064 MaxVersion: VersionTLS13,
8065 },
8066 },
8067 })
8068
8069 ret = append(ret, perMessageTest{
8070 messageType: typeCertificateRequest,
8071 test: testCase{
8072 name: "TLS13-CertificateRequest",
8073 config: Config{
8074 MaxVersion: VersionTLS13,
8075 ClientAuth: RequireAnyClientCert,
8076 },
8077 },
8078 })
8079
8080 ret = append(ret, perMessageTest{
8081 messageType: typeCertificate,
8082 test: testCase{
8083 name: "TLS13-ServerCertificate",
8084 config: Config{
8085 MaxVersion: VersionTLS13,
8086 },
8087 },
8088 })
8089
8090 ret = append(ret, perMessageTest{
8091 messageType: typeCertificateVerify,
8092 test: testCase{
8093 name: "TLS13-ServerCertificateVerify",
8094 config: Config{
8095 MaxVersion: VersionTLS13,
8096 },
8097 },
8098 })
8099
8100 ret = append(ret, perMessageTest{
8101 messageType: typeFinished,
8102 test: testCase{
8103 name: "TLS13-ServerFinished",
8104 config: Config{
8105 MaxVersion: VersionTLS13,
8106 },
8107 },
8108 })
8109
8110 ret = append(ret, perMessageTest{
8111 messageType: typeCertificate,
8112 test: testCase{
8113 testType: serverTest,
8114 name: "TLS13-ClientCertificate",
8115 config: Config{
8116 Certificates: []Certificate{rsaCertificate},
8117 MaxVersion: VersionTLS13,
8118 },
8119 flags: []string{"-require-any-client-certificate"},
8120 },
8121 })
8122
8123 ret = append(ret, perMessageTest{
8124 messageType: typeCertificateVerify,
8125 test: testCase{
8126 testType: serverTest,
8127 name: "TLS13-ClientCertificateVerify",
8128 config: Config{
8129 Certificates: []Certificate{rsaCertificate},
8130 MaxVersion: VersionTLS13,
8131 },
8132 flags: []string{"-require-any-client-certificate"},
8133 },
8134 })
8135
8136 ret = append(ret, perMessageTest{
8137 messageType: typeFinished,
8138 test: testCase{
8139 testType: serverTest,
8140 name: "TLS13-ClientFinished",
8141 config: Config{
8142 MaxVersion: VersionTLS13,
8143 },
8144 },
8145 })
8146
8147 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008148}
8149
David Benjamincd2c8062016-09-09 11:28:16 -04008150func addWrongMessageTypeTests() {
8151 for _, t := range makePerMessageTests() {
8152 t.test.name = "WrongMessageType-" + t.test.name
8153 t.test.config.Bugs.SendWrongMessageType = t.messageType
8154 t.test.shouldFail = true
8155 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8156 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008157
David Benjamincd2c8062016-09-09 11:28:16 -04008158 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8159 // In TLS 1.3, a bad ServerHello means the client sends
8160 // an unencrypted alert while the server expects
8161 // encryption, so the alert is not readable by runner.
8162 t.test.expectedLocalError = "local error: bad record MAC"
8163 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008164
David Benjamincd2c8062016-09-09 11:28:16 -04008165 testCases = append(testCases, t.test)
8166 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008167}
8168
David Benjamin639846e2016-09-09 11:41:18 -04008169func addTrailingMessageDataTests() {
8170 for _, t := range makePerMessageTests() {
8171 t.test.name = "TrailingMessageData-" + t.test.name
8172 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8173 t.test.shouldFail = true
8174 t.test.expectedError = ":DECODE_ERROR:"
8175 t.test.expectedLocalError = "remote error: error decoding message"
8176
8177 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8178 // In TLS 1.3, a bad ServerHello means the client sends
8179 // an unencrypted alert while the server expects
8180 // encryption, so the alert is not readable by runner.
8181 t.test.expectedLocalError = "local error: bad record MAC"
8182 }
8183
8184 if t.messageType == typeFinished {
8185 // Bad Finished messages read as the verify data having
8186 // the wrong length.
8187 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8188 t.test.expectedLocalError = "remote error: error decrypting message"
8189 }
8190
8191 testCases = append(testCases, t.test)
8192 }
8193}
8194
Steven Valdez143e8b32016-07-11 13:19:03 -04008195func addTLS13HandshakeTests() {
8196 testCases = append(testCases, testCase{
8197 testType: clientTest,
8198 name: "MissingKeyShare-Client",
8199 config: Config{
8200 MaxVersion: VersionTLS13,
8201 Bugs: ProtocolBugs{
8202 MissingKeyShare: true,
8203 },
8204 },
8205 shouldFail: true,
8206 expectedError: ":MISSING_KEY_SHARE:",
8207 })
8208
8209 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008210 testType: serverTest,
8211 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008212 config: Config{
8213 MaxVersion: VersionTLS13,
8214 Bugs: ProtocolBugs{
8215 MissingKeyShare: true,
8216 },
8217 },
8218 shouldFail: true,
8219 expectedError: ":MISSING_KEY_SHARE:",
8220 })
8221
8222 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008223 testType: serverTest,
8224 name: "DuplicateKeyShares",
8225 config: Config{
8226 MaxVersion: VersionTLS13,
8227 Bugs: ProtocolBugs{
8228 DuplicateKeyShares: true,
8229 },
8230 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008231 shouldFail: true,
8232 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008233 })
8234
8235 testCases = append(testCases, testCase{
8236 testType: clientTest,
8237 name: "EmptyEncryptedExtensions",
8238 config: Config{
8239 MaxVersion: VersionTLS13,
8240 Bugs: ProtocolBugs{
8241 EmptyEncryptedExtensions: true,
8242 },
8243 },
8244 shouldFail: true,
8245 expectedLocalError: "remote error: error decoding message",
8246 })
8247
8248 testCases = append(testCases, testCase{
8249 testType: clientTest,
8250 name: "EncryptedExtensionsWithKeyShare",
8251 config: Config{
8252 MaxVersion: VersionTLS13,
8253 Bugs: ProtocolBugs{
8254 EncryptedExtensionsWithKeyShare: true,
8255 },
8256 },
8257 shouldFail: true,
8258 expectedLocalError: "remote error: unsupported extension",
8259 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008260
8261 testCases = append(testCases, testCase{
8262 testType: serverTest,
8263 name: "SendHelloRetryRequest",
8264 config: Config{
8265 MaxVersion: VersionTLS13,
8266 // Require a HelloRetryRequest for every curve.
8267 DefaultCurves: []CurveID{},
8268 },
8269 expectedCurveID: CurveX25519,
8270 })
8271
8272 testCases = append(testCases, testCase{
8273 testType: serverTest,
8274 name: "SendHelloRetryRequest-2",
8275 config: Config{
8276 MaxVersion: VersionTLS13,
8277 DefaultCurves: []CurveID{CurveP384},
8278 },
8279 // Although the ClientHello did not predict our preferred curve,
8280 // we always select it whether it is predicted or not.
8281 expectedCurveID: CurveX25519,
8282 })
8283
8284 testCases = append(testCases, testCase{
8285 name: "UnknownCurve-HelloRetryRequest",
8286 config: Config{
8287 MaxVersion: VersionTLS13,
8288 // P-384 requires HelloRetryRequest in BoringSSL.
8289 CurvePreferences: []CurveID{CurveP384},
8290 Bugs: ProtocolBugs{
8291 SendHelloRetryRequestCurve: bogusCurve,
8292 },
8293 },
8294 shouldFail: true,
8295 expectedError: ":WRONG_CURVE:",
8296 })
8297
8298 testCases = append(testCases, testCase{
8299 name: "DisabledCurve-HelloRetryRequest",
8300 config: Config{
8301 MaxVersion: VersionTLS13,
8302 CurvePreferences: []CurveID{CurveP256},
8303 Bugs: ProtocolBugs{
8304 IgnorePeerCurvePreferences: true,
8305 },
8306 },
8307 flags: []string{"-p384-only"},
8308 shouldFail: true,
8309 expectedError: ":WRONG_CURVE:",
8310 })
8311
8312 testCases = append(testCases, testCase{
8313 name: "UnnecessaryHelloRetryRequest",
8314 config: Config{
8315 MaxVersion: VersionTLS13,
8316 Bugs: ProtocolBugs{
8317 UnnecessaryHelloRetryRequest: true,
8318 },
8319 },
8320 shouldFail: true,
8321 expectedError: ":WRONG_CURVE:",
8322 })
8323
8324 testCases = append(testCases, testCase{
8325 name: "SecondHelloRetryRequest",
8326 config: Config{
8327 MaxVersion: VersionTLS13,
8328 // P-384 requires HelloRetryRequest in BoringSSL.
8329 CurvePreferences: []CurveID{CurveP384},
8330 Bugs: ProtocolBugs{
8331 SecondHelloRetryRequest: true,
8332 },
8333 },
8334 shouldFail: true,
8335 expectedError: ":UNEXPECTED_MESSAGE:",
8336 })
8337
8338 testCases = append(testCases, testCase{
8339 testType: serverTest,
8340 name: "SecondClientHelloMissingKeyShare",
8341 config: Config{
8342 MaxVersion: VersionTLS13,
8343 DefaultCurves: []CurveID{},
8344 Bugs: ProtocolBugs{
8345 SecondClientHelloMissingKeyShare: true,
8346 },
8347 },
8348 shouldFail: true,
8349 expectedError: ":MISSING_KEY_SHARE:",
8350 })
8351
8352 testCases = append(testCases, testCase{
8353 testType: serverTest,
8354 name: "SecondClientHelloWrongCurve",
8355 config: Config{
8356 MaxVersion: VersionTLS13,
8357 DefaultCurves: []CurveID{},
8358 Bugs: ProtocolBugs{
8359 MisinterpretHelloRetryRequestCurve: CurveP521,
8360 },
8361 },
8362 shouldFail: true,
8363 expectedError: ":WRONG_CURVE:",
8364 })
8365
8366 testCases = append(testCases, testCase{
8367 name: "HelloRetryRequestVersionMismatch",
8368 config: Config{
8369 MaxVersion: VersionTLS13,
8370 // P-384 requires HelloRetryRequest in BoringSSL.
8371 CurvePreferences: []CurveID{CurveP384},
8372 Bugs: ProtocolBugs{
8373 SendServerHelloVersion: 0x0305,
8374 },
8375 },
8376 shouldFail: true,
8377 expectedError: ":WRONG_VERSION_NUMBER:",
8378 })
8379
8380 testCases = append(testCases, testCase{
8381 name: "HelloRetryRequestCurveMismatch",
8382 config: Config{
8383 MaxVersion: VersionTLS13,
8384 // P-384 requires HelloRetryRequest in BoringSSL.
8385 CurvePreferences: []CurveID{CurveP384},
8386 Bugs: ProtocolBugs{
8387 // Send P-384 (correct) in the HelloRetryRequest.
8388 SendHelloRetryRequestCurve: CurveP384,
8389 // But send P-256 in the ServerHello.
8390 SendCurve: CurveP256,
8391 },
8392 },
8393 shouldFail: true,
8394 expectedError: ":WRONG_CURVE:",
8395 })
8396
8397 // Test the server selecting a curve that requires a HelloRetryRequest
8398 // without sending it.
8399 testCases = append(testCases, testCase{
8400 name: "SkipHelloRetryRequest",
8401 config: Config{
8402 MaxVersion: VersionTLS13,
8403 // P-384 requires HelloRetryRequest in BoringSSL.
8404 CurvePreferences: []CurveID{CurveP384},
8405 Bugs: ProtocolBugs{
8406 SkipHelloRetryRequest: true,
8407 },
8408 },
8409 shouldFail: true,
8410 expectedError: ":WRONG_CURVE:",
8411 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008412
8413 testCases = append(testCases, testCase{
8414 name: "TLS13-RequestContextInHandshake",
8415 config: Config{
8416 MaxVersion: VersionTLS13,
8417 MinVersion: VersionTLS13,
8418 ClientAuth: RequireAnyClientCert,
8419 Bugs: ProtocolBugs{
8420 SendRequestContext: []byte("request context"),
8421 },
8422 },
8423 flags: []string{
8424 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8425 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8426 },
8427 shouldFail: true,
8428 expectedError: ":DECODE_ERROR:",
8429 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008430
8431 testCases = append(testCases, testCase{
8432 testType: serverTest,
8433 name: "TLS13-TrailingKeyShareData",
8434 config: Config{
8435 MaxVersion: VersionTLS13,
8436 Bugs: ProtocolBugs{
8437 TrailingKeyShareData: true,
8438 },
8439 },
8440 shouldFail: true,
8441 expectedError: ":DECODE_ERROR:",
8442 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008443}
8444
David Benjaminf3fbade2016-09-19 13:08:16 -04008445func addPeekTests() {
8446 // Test SSL_peek works, including on empty records.
8447 testCases = append(testCases, testCase{
8448 name: "Peek-Basic",
8449 sendEmptyRecords: 1,
8450 flags: []string{"-peek-then-read"},
8451 })
8452
8453 // Test SSL_peek can drive the initial handshake.
8454 testCases = append(testCases, testCase{
8455 name: "Peek-ImplicitHandshake",
8456 flags: []string{
8457 "-peek-then-read",
8458 "-implicit-handshake",
8459 },
8460 })
8461
8462 // Test SSL_peek can discover and drive a renegotiation.
8463 testCases = append(testCases, testCase{
8464 name: "Peek-Renegotiate",
8465 config: Config{
8466 MaxVersion: VersionTLS12,
8467 },
8468 renegotiate: 1,
8469 flags: []string{
8470 "-peek-then-read",
8471 "-renegotiate-freely",
8472 "-expect-total-renegotiations", "1",
8473 },
8474 })
8475
8476 // Test SSL_peek can discover a close_notify.
8477 testCases = append(testCases, testCase{
8478 name: "Peek-Shutdown",
8479 config: Config{
8480 Bugs: ProtocolBugs{
8481 ExpectCloseNotify: true,
8482 },
8483 },
8484 flags: []string{
8485 "-peek-then-read",
8486 "-check-close-notify",
8487 },
8488 })
8489
8490 // Test SSL_peek can discover an alert.
8491 testCases = append(testCases, testCase{
8492 name: "Peek-Alert",
8493 config: Config{
8494 Bugs: ProtocolBugs{
8495 SendSpuriousAlert: alertRecordOverflow,
8496 },
8497 },
8498 flags: []string{"-peek-then-read"},
8499 shouldFail: true,
8500 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8501 })
8502
8503 // Test SSL_peek can handle KeyUpdate.
8504 testCases = append(testCases, testCase{
8505 name: "Peek-KeyUpdate",
8506 config: Config{
8507 MaxVersion: VersionTLS13,
8508 Bugs: ProtocolBugs{
8509 SendKeyUpdateBeforeEveryAppDataRecord: true,
8510 },
8511 },
8512 flags: []string{"-peek-then-read"},
8513 })
8514}
8515
Adam Langley7c803a62015-06-15 15:35:05 -07008516func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008517 defer wg.Done()
8518
8519 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008520 var err error
8521
8522 if *mallocTest < 0 {
8523 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008524 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008525 } else {
8526 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8527 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008528 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008529 if err != nil {
8530 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8531 }
8532 break
8533 }
8534 }
8535 }
Adam Langley95c29f32014-06-20 12:00:00 -07008536 statusChan <- statusMsg{test: test, err: err}
8537 }
8538}
8539
8540type statusMsg struct {
8541 test *testCase
8542 started bool
8543 err error
8544}
8545
David Benjamin5f237bc2015-02-11 17:14:15 -05008546func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008547 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008548
David Benjamin5f237bc2015-02-11 17:14:15 -05008549 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008550 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008551 if !*pipe {
8552 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008553 var erase string
8554 for i := 0; i < lineLen; i++ {
8555 erase += "\b \b"
8556 }
8557 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008558 }
8559
Adam Langley95c29f32014-06-20 12:00:00 -07008560 if msg.started {
8561 started++
8562 } else {
8563 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008564
8565 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008566 if msg.err == errUnimplemented {
8567 if *pipe {
8568 // Print each test instead of a status line.
8569 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8570 }
8571 unimplemented++
8572 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8573 } else {
8574 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8575 failed++
8576 testOutput.addResult(msg.test.name, "FAIL")
8577 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008578 } else {
8579 if *pipe {
8580 // Print each test instead of a status line.
8581 fmt.Printf("PASSED (%s)\n", msg.test.name)
8582 }
8583 testOutput.addResult(msg.test.name, "PASS")
8584 }
Adam Langley95c29f32014-06-20 12:00:00 -07008585 }
8586
David Benjamin5f237bc2015-02-11 17:14:15 -05008587 if !*pipe {
8588 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008589 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008590 lineLen = len(line)
8591 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008592 }
Adam Langley95c29f32014-06-20 12:00:00 -07008593 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008594
8595 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008596}
8597
8598func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008599 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008600 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008601 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008602
Adam Langley7c803a62015-06-15 15:35:05 -07008603 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008604 addCipherSuiteTests()
8605 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008606 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008607 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008608 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008609 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008610 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008611 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008612 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008613 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008614 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008615 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008616 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008617 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008618 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008619 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008620 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008621 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008622 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008623 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008624 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008625 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008626 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008627 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008628 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008629 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008630 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008631 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008632 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008633
8634 var wg sync.WaitGroup
8635
Adam Langley7c803a62015-06-15 15:35:05 -07008636 statusChan := make(chan statusMsg, *numWorkers)
8637 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008638 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008639
EKRf71d7ed2016-08-06 13:25:12 -07008640 if len(*shimConfigFile) != 0 {
8641 encoded, err := ioutil.ReadFile(*shimConfigFile)
8642 if err != nil {
8643 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8644 os.Exit(1)
8645 }
8646
8647 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8648 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8649 os.Exit(1)
8650 }
8651 }
8652
David Benjamin025b3d32014-07-01 19:53:04 -04008653 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008654
Adam Langley7c803a62015-06-15 15:35:05 -07008655 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008656 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008657 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008658 }
8659
David Benjamin270f0a72016-03-17 14:41:36 -04008660 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008661 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008662 matched := true
8663 if len(*testToRun) != 0 {
8664 var err error
8665 matched, err = filepath.Match(*testToRun, testCases[i].name)
8666 if err != nil {
8667 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8668 os.Exit(1)
8669 }
8670 }
8671
EKRf71d7ed2016-08-06 13:25:12 -07008672 if !*includeDisabled {
8673 for pattern := range shimConfig.DisabledTests {
8674 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8675 if err != nil {
8676 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8677 os.Exit(1)
8678 }
8679
8680 if isDisabled {
8681 matched = false
8682 break
8683 }
8684 }
8685 }
8686
David Benjamin17e12922016-07-28 18:04:43 -04008687 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008688 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008689 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008690 }
8691 }
David Benjamin17e12922016-07-28 18:04:43 -04008692
David Benjamin270f0a72016-03-17 14:41:36 -04008693 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008694 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008695 os.Exit(1)
8696 }
Adam Langley95c29f32014-06-20 12:00:00 -07008697
8698 close(testChan)
8699 wg.Wait()
8700 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008701 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008702
8703 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008704
8705 if *jsonOutput != "" {
8706 if err := testOutput.writeTo(*jsonOutput); err != nil {
8707 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8708 }
8709 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008710
EKR842ae6c2016-07-27 09:22:05 +02008711 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8712 os.Exit(1)
8713 }
8714
8715 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008716 os.Exit(1)
8717 }
Adam Langley95c29f32014-06-20 12:00:00 -07008718}