blob: f536cebef2e3563102c26adf9607c91e0a71a45d [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 Benjaminef5dfd22015-12-06 13:17:07 -05002121 name: "BadHelloRequest-1",
2122 renegotiate: 1,
2123 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002124 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002125 Bugs: ProtocolBugs{
2126 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2127 },
2128 },
2129 flags: []string{
2130 "-renegotiate-freely",
2131 "-expect-total-renegotiations", "1",
2132 },
2133 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002134 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002135 },
2136 {
2137 name: "BadHelloRequest-2",
2138 renegotiate: 1,
2139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002140 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002141 Bugs: ProtocolBugs{
2142 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2143 },
2144 },
2145 flags: []string{
2146 "-renegotiate-freely",
2147 "-expect-total-renegotiations", "1",
2148 },
2149 shouldFail: true,
2150 expectedError: ":BAD_HELLO_REQUEST:",
2151 },
David Benjaminef1b0092015-11-21 14:05:44 -05002152 {
2153 testType: serverTest,
2154 name: "SupportTicketsWithSessionID",
2155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002156 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002157 SessionTicketsDisabled: true,
2158 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002159 resumeConfig: &Config{
2160 MaxVersion: VersionTLS12,
2161 },
David Benjaminef1b0092015-11-21 14:05:44 -05002162 resumeSession: true,
2163 },
David Benjamin02edcd02016-07-27 17:40:37 -04002164 {
2165 protocol: dtls,
2166 name: "DTLS-SendExtraFinished",
2167 config: Config{
2168 Bugs: ProtocolBugs{
2169 SendExtraFinished: true,
2170 },
2171 },
2172 shouldFail: true,
2173 expectedError: ":UNEXPECTED_RECORD:",
2174 },
2175 {
2176 protocol: dtls,
2177 name: "DTLS-SendExtraFinished-Reordered",
2178 config: Config{
2179 Bugs: ProtocolBugs{
2180 MaxHandshakeRecordLength: 2,
2181 ReorderHandshakeFragments: true,
2182 SendExtraFinished: true,
2183 },
2184 },
2185 shouldFail: true,
2186 expectedError: ":UNEXPECTED_RECORD:",
2187 },
David Benjamine97fb482016-07-29 09:23:07 -04002188 {
2189 testType: serverTest,
2190 name: "V2ClientHello-EmptyRecordPrefix",
2191 config: Config{
2192 // Choose a cipher suite that does not involve
2193 // elliptic curves, so no extensions are
2194 // involved.
2195 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002196 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002197 Bugs: ProtocolBugs{
2198 SendV2ClientHello: true,
2199 },
2200 },
2201 sendPrefix: string([]byte{
2202 byte(recordTypeHandshake),
2203 3, 1, // version
2204 0, 0, // length
2205 }),
2206 // A no-op empty record may not be sent before V2ClientHello.
2207 shouldFail: true,
2208 expectedError: ":WRONG_VERSION_NUMBER:",
2209 },
2210 {
2211 testType: serverTest,
2212 name: "V2ClientHello-WarningAlertPrefix",
2213 config: Config{
2214 // Choose a cipher suite that does not involve
2215 // elliptic curves, so no extensions are
2216 // involved.
2217 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002218 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002219 Bugs: ProtocolBugs{
2220 SendV2ClientHello: true,
2221 },
2222 },
2223 sendPrefix: string([]byte{
2224 byte(recordTypeAlert),
2225 3, 1, // version
2226 0, 2, // length
2227 alertLevelWarning, byte(alertDecompressionFailure),
2228 }),
2229 // A no-op warning alert may not be sent before V2ClientHello.
2230 shouldFail: true,
2231 expectedError: ":WRONG_VERSION_NUMBER:",
2232 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002233 {
2234 testType: clientTest,
2235 name: "KeyUpdate",
2236 config: Config{
2237 MaxVersion: VersionTLS13,
2238 Bugs: ProtocolBugs{
2239 SendKeyUpdateBeforeEveryAppDataRecord: true,
2240 },
2241 },
2242 },
David Benjaminabe94e32016-09-04 14:18:58 -04002243 {
2244 name: "SendSNIWarningAlert",
2245 config: Config{
2246 MaxVersion: VersionTLS12,
2247 Bugs: ProtocolBugs{
2248 SendSNIWarningAlert: true,
2249 },
2250 },
2251 },
David Benjaminc241d792016-09-09 10:34:20 -04002252 {
2253 testType: serverTest,
2254 name: "ExtraCompressionMethods-TLS12",
2255 config: Config{
2256 MaxVersion: VersionTLS12,
2257 Bugs: ProtocolBugs{
2258 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2259 },
2260 },
2261 },
2262 {
2263 testType: serverTest,
2264 name: "ExtraCompressionMethods-TLS13",
2265 config: Config{
2266 MaxVersion: VersionTLS13,
2267 Bugs: ProtocolBugs{
2268 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2269 },
2270 },
2271 shouldFail: true,
2272 expectedError: ":INVALID_COMPRESSION_LIST:",
2273 expectedLocalError: "remote error: illegal parameter",
2274 },
2275 {
2276 testType: serverTest,
2277 name: "NoNullCompression-TLS12",
2278 config: Config{
2279 MaxVersion: VersionTLS12,
2280 Bugs: ProtocolBugs{
2281 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2282 },
2283 },
2284 shouldFail: true,
2285 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2286 expectedLocalError: "remote error: illegal parameter",
2287 },
2288 {
2289 testType: serverTest,
2290 name: "NoNullCompression-TLS13",
2291 config: Config{
2292 MaxVersion: VersionTLS13,
2293 Bugs: ProtocolBugs{
2294 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2295 },
2296 },
2297 shouldFail: true,
2298 expectedError: ":INVALID_COMPRESSION_LIST:",
2299 expectedLocalError: "remote error: illegal parameter",
2300 },
David Benjamin65ac9972016-09-02 21:35:25 -04002301 {
2302 name: "GREASE-TLS12",
2303 config: Config{
2304 MaxVersion: VersionTLS12,
2305 Bugs: ProtocolBugs{
2306 ExpectGREASE: true,
2307 },
2308 },
2309 flags: []string{"-enable-grease"},
2310 },
2311 {
2312 name: "GREASE-TLS13",
2313 config: Config{
2314 MaxVersion: VersionTLS13,
2315 Bugs: ProtocolBugs{
2316 ExpectGREASE: true,
2317 },
2318 },
2319 flags: []string{"-enable-grease"},
2320 },
Adam Langley7c803a62015-06-15 15:35:05 -07002321 }
Adam Langley7c803a62015-06-15 15:35:05 -07002322 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002323
2324 // Test that very large messages can be received.
2325 cert := rsaCertificate
2326 for i := 0; i < 50; i++ {
2327 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2328 }
2329 testCases = append(testCases, testCase{
2330 name: "LargeMessage",
2331 config: Config{
2332 Certificates: []Certificate{cert},
2333 },
2334 })
2335 testCases = append(testCases, testCase{
2336 protocol: dtls,
2337 name: "LargeMessage-DTLS",
2338 config: Config{
2339 Certificates: []Certificate{cert},
2340 },
2341 })
2342
2343 // They are rejected if the maximum certificate chain length is capped.
2344 testCases = append(testCases, testCase{
2345 name: "LargeMessage-Reject",
2346 config: Config{
2347 Certificates: []Certificate{cert},
2348 },
2349 flags: []string{"-max-cert-list", "16384"},
2350 shouldFail: true,
2351 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2352 })
2353 testCases = append(testCases, testCase{
2354 protocol: dtls,
2355 name: "LargeMessage-Reject-DTLS",
2356 config: Config{
2357 Certificates: []Certificate{cert},
2358 },
2359 flags: []string{"-max-cert-list", "16384"},
2360 shouldFail: true,
2361 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2362 })
Adam Langley7c803a62015-06-15 15:35:05 -07002363}
2364
Adam Langley95c29f32014-06-20 12:00:00 -07002365func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002366 const bogusCipher = 0xfe00
2367
Adam Langley95c29f32014-06-20 12:00:00 -07002368 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002369 const psk = "12345"
2370 const pskIdentity = "luggage combo"
2371
Adam Langley95c29f32014-06-20 12:00:00 -07002372 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002373 var certFile string
2374 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002375 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002376 cert = ecdsaP256Certificate
2377 certFile = ecdsaP256CertificateFile
2378 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002379 } else {
David Benjamin33863262016-07-08 17:20:12 -07002380 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002381 certFile = rsaCertificateFile
2382 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002383 }
2384
David Benjamin48cae082014-10-27 01:06:24 -04002385 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002386 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002387 flags = append(flags,
2388 "-psk", psk,
2389 "-psk-identity", pskIdentity)
2390 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002391 if hasComponent(suite.name, "NULL") {
2392 // NULL ciphers must be explicitly enabled.
2393 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2394 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002395 if hasComponent(suite.name, "CECPQ1") {
2396 // CECPQ1 ciphers must be explicitly enabled.
2397 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2398 }
David Benjamin881f1962016-08-10 18:29:12 -04002399 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2400 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2401 // for now.
2402 flags = append(flags, "-cipher", suite.name)
2403 }
David Benjamin48cae082014-10-27 01:06:24 -04002404
Adam Langley95c29f32014-06-20 12:00:00 -07002405 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002406 for _, protocol := range []protocol{tls, dtls} {
2407 var prefix string
2408 if protocol == dtls {
2409 if !ver.hasDTLS {
2410 continue
2411 }
2412 prefix = "D"
2413 }
Adam Langley95c29f32014-06-20 12:00:00 -07002414
David Benjamin0407e762016-06-17 16:41:18 -04002415 var shouldServerFail, shouldClientFail bool
2416 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2417 // BoringSSL clients accept ECDHE on SSLv3, but
2418 // a BoringSSL server will never select it
2419 // because the extension is missing.
2420 shouldServerFail = true
2421 }
2422 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2423 shouldClientFail = true
2424 shouldServerFail = true
2425 }
David Benjamin54c217c2016-07-13 12:35:25 -04002426 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002427 shouldClientFail = true
2428 shouldServerFail = true
2429 }
David Benjamin0407e762016-06-17 16:41:18 -04002430 if !isDTLSCipher(suite.name) && protocol == dtls {
2431 shouldClientFail = true
2432 shouldServerFail = true
2433 }
David Benjamin4298d772015-12-19 00:18:25 -05002434
David Benjamin5ecb88b2016-10-04 17:51:35 -04002435 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002436 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002437 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002438 if shouldServerFail {
2439 expectedServerError = ":NO_SHARED_CIPHER:"
2440 }
2441 if shouldClientFail {
2442 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002443 // Configure the server to select ciphers as normal but
2444 // select an incompatible cipher in ServerHello.
2445 serverCipherSuites = nil
2446 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002447 }
David Benjamin025b3d32014-07-01 19:53:04 -04002448
David Benjamin6fd297b2014-08-11 18:43:38 -04002449 testCases = append(testCases, testCase{
2450 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002451 protocol: protocol,
2452
2453 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002454 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002455 MinVersion: ver.version,
2456 MaxVersion: ver.version,
2457 CipherSuites: []uint16{suite.id},
2458 Certificates: []Certificate{cert},
2459 PreSharedKey: []byte(psk),
2460 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002461 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002462 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002463 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002464 },
2465 certFile: certFile,
2466 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002467 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002468 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002469 shouldFail: shouldServerFail,
2470 expectedError: expectedServerError,
2471 })
2472
2473 testCases = append(testCases, testCase{
2474 testType: clientTest,
2475 protocol: protocol,
2476 name: prefix + ver.name + "-" + suite.name + "-client",
2477 config: Config{
2478 MinVersion: ver.version,
2479 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002480 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002481 Certificates: []Certificate{cert},
2482 PreSharedKey: []byte(psk),
2483 PreSharedKeyIdentity: pskIdentity,
2484 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002485 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002486 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002487 },
2488 },
2489 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002490 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002491 shouldFail: shouldClientFail,
2492 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002493 })
David Benjamin2c99d282015-09-01 10:23:00 -04002494
Nick Harper1fd39d82016-06-14 18:14:35 -07002495 if !shouldClientFail {
2496 // Ensure the maximum record size is accepted.
2497 testCases = append(testCases, testCase{
2498 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2499 config: Config{
2500 MinVersion: ver.version,
2501 MaxVersion: ver.version,
2502 CipherSuites: []uint16{suite.id},
2503 Certificates: []Certificate{cert},
2504 PreSharedKey: []byte(psk),
2505 PreSharedKeyIdentity: pskIdentity,
2506 },
2507 flags: flags,
2508 messageLen: maxPlaintext,
2509 })
2510 }
2511 }
David Benjamin2c99d282015-09-01 10:23:00 -04002512 }
Adam Langley95c29f32014-06-20 12:00:00 -07002513 }
Adam Langleya7997f12015-05-14 17:38:50 -07002514
2515 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002516 name: "NoSharedCipher",
2517 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002518 MaxVersion: VersionTLS12,
2519 CipherSuites: []uint16{},
2520 },
2521 shouldFail: true,
2522 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2523 })
2524
2525 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002526 name: "NoSharedCipher-TLS13",
2527 config: Config{
2528 MaxVersion: VersionTLS13,
2529 CipherSuites: []uint16{},
2530 },
2531 shouldFail: true,
2532 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2533 })
2534
2535 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002536 name: "UnsupportedCipherSuite",
2537 config: Config{
2538 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002539 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002540 Bugs: ProtocolBugs{
2541 IgnorePeerCipherPreferences: true,
2542 },
2543 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002544 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002545 shouldFail: true,
2546 expectedError: ":WRONG_CIPHER_RETURNED:",
2547 })
2548
2549 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002550 name: "ServerHelloBogusCipher",
2551 config: Config{
2552 MaxVersion: VersionTLS12,
2553 Bugs: ProtocolBugs{
2554 SendCipherSuite: bogusCipher,
2555 },
2556 },
2557 shouldFail: true,
2558 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2559 })
2560 testCases = append(testCases, testCase{
2561 name: "ServerHelloBogusCipher-TLS13",
2562 config: Config{
2563 MaxVersion: VersionTLS13,
2564 Bugs: ProtocolBugs{
2565 SendCipherSuite: bogusCipher,
2566 },
2567 },
2568 shouldFail: true,
2569 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2570 })
2571
2572 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002573 name: "WeakDH",
2574 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002575 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002576 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2577 Bugs: ProtocolBugs{
2578 // This is a 1023-bit prime number, generated
2579 // with:
2580 // openssl gendh 1023 | openssl asn1parse -i
2581 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2582 },
2583 },
2584 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002585 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002586 })
Adam Langleycef75832015-09-03 14:51:12 -07002587
David Benjamincd24a392015-11-11 13:23:05 -08002588 testCases = append(testCases, testCase{
2589 name: "SillyDH",
2590 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002591 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002592 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2593 Bugs: ProtocolBugs{
2594 // This is a 4097-bit prime number, generated
2595 // with:
2596 // openssl gendh 4097 | openssl asn1parse -i
2597 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2598 },
2599 },
2600 shouldFail: true,
2601 expectedError: ":DH_P_TOO_LONG:",
2602 })
2603
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002604 // This test ensures that Diffie-Hellman public values are padded with
2605 // zeros so that they're the same length as the prime. This is to avoid
2606 // hitting a bug in yaSSL.
2607 testCases = append(testCases, testCase{
2608 testType: serverTest,
2609 name: "DHPublicValuePadded",
2610 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002611 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002612 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2613 Bugs: ProtocolBugs{
2614 RequireDHPublicValueLen: (1025 + 7) / 8,
2615 },
2616 },
2617 flags: []string{"-use-sparse-dh-prime"},
2618 })
David Benjamincd24a392015-11-11 13:23:05 -08002619
David Benjamin241ae832016-01-15 03:04:54 -05002620 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002621 testCases = append(testCases, testCase{
2622 testType: serverTest,
2623 name: "UnknownCipher",
2624 config: Config{
2625 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002626 Bugs: ProtocolBugs{
2627 AdvertiseAllConfiguredCiphers: true,
2628 },
2629 },
2630 })
2631 testCases = append(testCases, testCase{
2632 testType: serverTest,
2633 name: "UnknownCipher-TLS13",
2634 config: Config{
2635 MaxVersion: VersionTLS13,
2636 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2637 Bugs: ProtocolBugs{
2638 AdvertiseAllConfiguredCiphers: true,
2639 },
David Benjamin241ae832016-01-15 03:04:54 -05002640 },
2641 })
2642
David Benjamin78679342016-09-16 19:42:05 -04002643 // Test empty ECDHE_PSK identity hints work as expected.
2644 testCases = append(testCases, testCase{
2645 name: "EmptyECDHEPSKHint",
2646 config: Config{
2647 MaxVersion: VersionTLS12,
2648 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2649 PreSharedKey: []byte("secret"),
2650 },
2651 flags: []string{"-psk", "secret"},
2652 })
2653
2654 // Test empty PSK identity hints work as expected, even if an explicit
2655 // ServerKeyExchange is sent.
2656 testCases = append(testCases, testCase{
2657 name: "ExplicitEmptyPSKHint",
2658 config: Config{
2659 MaxVersion: VersionTLS12,
2660 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2661 PreSharedKey: []byte("secret"),
2662 Bugs: ProtocolBugs{
2663 AlwaysSendPreSharedKeyIdentityHint: true,
2664 },
2665 },
2666 flags: []string{"-psk", "secret"},
2667 })
2668
Adam Langleycef75832015-09-03 14:51:12 -07002669 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2670 // 1.1 specific cipher suite settings. A server is setup with the given
2671 // cipher lists and then a connection is made for each member of
2672 // expectations. The cipher suite that the server selects must match
2673 // the specified one.
2674 var versionSpecificCiphersTest = []struct {
2675 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2676 // expectations is a map from TLS version to cipher suite id.
2677 expectations map[uint16]uint16
2678 }{
2679 {
2680 // Test that the null case (where no version-specific ciphers are set)
2681 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002682 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2683 "", // no ciphers specifically for TLS ≥ 1.0
2684 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002685 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002686 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2687 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2688 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2689 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002690 },
2691 },
2692 {
2693 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2694 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002695 "DES-CBC3-SHA:AES128-SHA", // default
2696 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2697 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002698 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002699 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002700 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2701 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2702 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2703 },
2704 },
2705 {
2706 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2707 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002708 "DES-CBC3-SHA:AES128-SHA", // default
2709 "", // no ciphers specifically for TLS ≥ 1.0
2710 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002711 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002712 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2713 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002714 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2715 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2716 },
2717 },
2718 {
2719 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2720 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002721 "DES-CBC3-SHA:AES128-SHA", // default
2722 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2723 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002724 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002725 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002726 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2727 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2728 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2729 },
2730 },
2731 }
2732
2733 for i, test := range versionSpecificCiphersTest {
2734 for version, expectedCipherSuite := range test.expectations {
2735 flags := []string{"-cipher", test.ciphersDefault}
2736 if len(test.ciphersTLS10) > 0 {
2737 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2738 }
2739 if len(test.ciphersTLS11) > 0 {
2740 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2741 }
2742
2743 testCases = append(testCases, testCase{
2744 testType: serverTest,
2745 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2746 config: Config{
2747 MaxVersion: version,
2748 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002749 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 -07002750 },
2751 flags: flags,
2752 expectedCipher: expectedCipherSuite,
2753 })
2754 }
2755 }
Adam Langley95c29f32014-06-20 12:00:00 -07002756}
2757
2758func addBadECDSASignatureTests() {
2759 for badR := BadValue(1); badR < NumBadValues; badR++ {
2760 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002761 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002762 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2763 config: Config{
2764 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002765 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002766 Bugs: ProtocolBugs{
2767 BadECDSAR: badR,
2768 BadECDSAS: badS,
2769 },
2770 },
2771 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002772 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002773 })
2774 }
2775 }
2776}
2777
Adam Langley80842bd2014-06-20 12:00:00 -07002778func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002779 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002780 name: "MaxCBCPadding",
2781 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002782 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2784 Bugs: ProtocolBugs{
2785 MaxPadding: true,
2786 },
2787 },
2788 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2789 })
David Benjamin025b3d32014-07-01 19:53:04 -04002790 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002791 name: "BadCBCPadding",
2792 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002793 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2795 Bugs: ProtocolBugs{
2796 PaddingFirstByteBad: true,
2797 },
2798 },
2799 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002800 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002801 })
2802 // OpenSSL previously had an issue where the first byte of padding in
2803 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002804 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002805 name: "BadCBCPadding255",
2806 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002807 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002808 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2809 Bugs: ProtocolBugs{
2810 MaxPadding: true,
2811 PaddingFirstByteBadIf255: true,
2812 },
2813 },
2814 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2815 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002816 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002817 })
2818}
2819
Kenny Root7fdeaf12014-08-05 15:23:37 -07002820func addCBCSplittingTests() {
2821 testCases = append(testCases, testCase{
2822 name: "CBCRecordSplitting",
2823 config: Config{
2824 MaxVersion: VersionTLS10,
2825 MinVersion: VersionTLS10,
2826 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2827 },
David Benjaminac8302a2015-09-01 17:18:15 -04002828 messageLen: -1, // read until EOF
2829 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002830 flags: []string{
2831 "-async",
2832 "-write-different-record-sizes",
2833 "-cbc-record-splitting",
2834 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002835 })
2836 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002837 name: "CBCRecordSplittingPartialWrite",
2838 config: Config{
2839 MaxVersion: VersionTLS10,
2840 MinVersion: VersionTLS10,
2841 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2842 },
2843 messageLen: -1, // read until EOF
2844 flags: []string{
2845 "-async",
2846 "-write-different-record-sizes",
2847 "-cbc-record-splitting",
2848 "-partial-write",
2849 },
2850 })
2851}
2852
David Benjamin636293b2014-07-08 17:59:18 -04002853func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002854 // Add a dummy cert pool to stress certificate authority parsing.
2855 // TODO(davidben): Add tests that those values parse out correctly.
2856 certPool := x509.NewCertPool()
2857 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2858 if err != nil {
2859 panic(err)
2860 }
2861 certPool.AddCert(cert)
2862
David Benjamin636293b2014-07-08 17:59:18 -04002863 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002864 testCases = append(testCases, testCase{
2865 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002866 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002867 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002868 MinVersion: ver.version,
2869 MaxVersion: ver.version,
2870 ClientAuth: RequireAnyClientCert,
2871 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002872 },
2873 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002874 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2875 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002876 },
2877 })
2878 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002879 testType: serverTest,
2880 name: ver.name + "-Server-ClientAuth-RSA",
2881 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002882 MinVersion: ver.version,
2883 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002884 Certificates: []Certificate{rsaCertificate},
2885 },
2886 flags: []string{"-require-any-client-certificate"},
2887 })
David Benjamine098ec22014-08-27 23:13:20 -04002888 if ver.version != VersionSSL30 {
2889 testCases = append(testCases, testCase{
2890 testType: serverTest,
2891 name: ver.name + "-Server-ClientAuth-ECDSA",
2892 config: Config{
2893 MinVersion: ver.version,
2894 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002895 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002896 },
2897 flags: []string{"-require-any-client-certificate"},
2898 })
2899 testCases = append(testCases, testCase{
2900 testType: clientTest,
2901 name: ver.name + "-Client-ClientAuth-ECDSA",
2902 config: Config{
2903 MinVersion: ver.version,
2904 MaxVersion: ver.version,
2905 ClientAuth: RequireAnyClientCert,
2906 ClientCAs: certPool,
2907 },
2908 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002909 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2910 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002911 },
2912 })
2913 }
Adam Langley37646832016-08-01 16:16:46 -07002914
2915 testCases = append(testCases, testCase{
2916 name: "NoClientCertificate-" + ver.name,
2917 config: Config{
2918 MinVersion: ver.version,
2919 MaxVersion: ver.version,
2920 ClientAuth: RequireAnyClientCert,
2921 },
2922 shouldFail: true,
2923 expectedLocalError: "client didn't provide a certificate",
2924 })
2925
2926 testCases = append(testCases, testCase{
2927 // Even if not configured to expect a certificate, OpenSSL will
2928 // return X509_V_OK as the verify_result.
2929 testType: serverTest,
2930 name: "NoClientCertificateRequested-Server-" + ver.name,
2931 config: Config{
2932 MinVersion: ver.version,
2933 MaxVersion: ver.version,
2934 },
2935 flags: []string{
2936 "-expect-verify-result",
2937 },
2938 // TODO(davidben): Switch this to true when TLS 1.3
2939 // supports session resumption.
2940 resumeSession: ver.version < VersionTLS13,
2941 })
2942
2943 testCases = append(testCases, testCase{
2944 // If a client certificate is not provided, OpenSSL will still
2945 // return X509_V_OK as the verify_result.
2946 testType: serverTest,
2947 name: "NoClientCertificate-Server-" + ver.name,
2948 config: Config{
2949 MinVersion: ver.version,
2950 MaxVersion: ver.version,
2951 },
2952 flags: []string{
2953 "-expect-verify-result",
2954 "-verify-peer",
2955 },
2956 // TODO(davidben): Switch this to true when TLS 1.3
2957 // supports session resumption.
2958 resumeSession: ver.version < VersionTLS13,
2959 })
2960
2961 testCases = append(testCases, testCase{
2962 testType: serverTest,
2963 name: "RequireAnyClientCertificate-" + ver.name,
2964 config: Config{
2965 MinVersion: ver.version,
2966 MaxVersion: ver.version,
2967 },
2968 flags: []string{"-require-any-client-certificate"},
2969 shouldFail: true,
2970 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2971 })
2972
2973 if ver.version != VersionSSL30 {
2974 testCases = append(testCases, testCase{
2975 testType: serverTest,
2976 name: "SkipClientCertificate-" + ver.name,
2977 config: Config{
2978 MinVersion: ver.version,
2979 MaxVersion: ver.version,
2980 Bugs: ProtocolBugs{
2981 SkipClientCertificate: true,
2982 },
2983 },
2984 // Setting SSL_VERIFY_PEER allows anonymous clients.
2985 flags: []string{"-verify-peer"},
2986 shouldFail: true,
2987 expectedError: ":UNEXPECTED_MESSAGE:",
2988 })
2989 }
David Benjamin636293b2014-07-08 17:59:18 -04002990 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002991
David Benjaminc032dfa2016-05-12 14:54:57 -04002992 // Client auth is only legal in certificate-based ciphers.
2993 testCases = append(testCases, testCase{
2994 testType: clientTest,
2995 name: "ClientAuth-PSK",
2996 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002997 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002998 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2999 PreSharedKey: []byte("secret"),
3000 ClientAuth: RequireAnyClientCert,
3001 },
3002 flags: []string{
3003 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3004 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3005 "-psk", "secret",
3006 },
3007 shouldFail: true,
3008 expectedError: ":UNEXPECTED_MESSAGE:",
3009 })
3010 testCases = append(testCases, testCase{
3011 testType: clientTest,
3012 name: "ClientAuth-ECDHE_PSK",
3013 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003014 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003015 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3016 PreSharedKey: []byte("secret"),
3017 ClientAuth: RequireAnyClientCert,
3018 },
3019 flags: []string{
3020 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3021 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3022 "-psk", "secret",
3023 },
3024 shouldFail: true,
3025 expectedError: ":UNEXPECTED_MESSAGE:",
3026 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003027
3028 // Regression test for a bug where the client CA list, if explicitly
3029 // set to NULL, was mis-encoded.
3030 testCases = append(testCases, testCase{
3031 testType: serverTest,
3032 name: "Null-Client-CA-List",
3033 config: Config{
3034 MaxVersion: VersionTLS12,
3035 Certificates: []Certificate{rsaCertificate},
3036 },
3037 flags: []string{
3038 "-require-any-client-certificate",
3039 "-use-null-client-ca-list",
3040 },
3041 })
David Benjamin636293b2014-07-08 17:59:18 -04003042}
3043
Adam Langley75712922014-10-10 16:23:43 -07003044func addExtendedMasterSecretTests() {
3045 const expectEMSFlag = "-expect-extended-master-secret"
3046
3047 for _, with := range []bool{false, true} {
3048 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003049 if with {
3050 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003051 }
3052
3053 for _, isClient := range []bool{false, true} {
3054 suffix := "-Server"
3055 testType := serverTest
3056 if isClient {
3057 suffix = "-Client"
3058 testType = clientTest
3059 }
3060
3061 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003062 // In TLS 1.3, the extension is irrelevant and
3063 // always reports as enabled.
3064 var flags []string
3065 if with || ver.version >= VersionTLS13 {
3066 flags = []string{expectEMSFlag}
3067 }
3068
Adam Langley75712922014-10-10 16:23:43 -07003069 test := testCase{
3070 testType: testType,
3071 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3072 config: Config{
3073 MinVersion: ver.version,
3074 MaxVersion: ver.version,
3075 Bugs: ProtocolBugs{
3076 NoExtendedMasterSecret: !with,
3077 RequireExtendedMasterSecret: with,
3078 },
3079 },
David Benjamin48cae082014-10-27 01:06:24 -04003080 flags: flags,
3081 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003082 }
3083 if test.shouldFail {
3084 test.expectedLocalError = "extended master secret required but not supported by peer"
3085 }
3086 testCases = append(testCases, test)
3087 }
3088 }
3089 }
3090
Adam Langleyba5934b2015-06-02 10:50:35 -07003091 for _, isClient := range []bool{false, true} {
3092 for _, supportedInFirstConnection := range []bool{false, true} {
3093 for _, supportedInResumeConnection := range []bool{false, true} {
3094 boolToWord := func(b bool) string {
3095 if b {
3096 return "Yes"
3097 }
3098 return "No"
3099 }
3100 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3101 if isClient {
3102 suffix += "Client"
3103 } else {
3104 suffix += "Server"
3105 }
3106
3107 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003108 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003109 Bugs: ProtocolBugs{
3110 RequireExtendedMasterSecret: true,
3111 },
3112 }
3113
3114 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003115 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003116 Bugs: ProtocolBugs{
3117 NoExtendedMasterSecret: true,
3118 },
3119 }
3120
3121 test := testCase{
3122 name: "ExtendedMasterSecret-" + suffix,
3123 resumeSession: true,
3124 }
3125
3126 if !isClient {
3127 test.testType = serverTest
3128 }
3129
3130 if supportedInFirstConnection {
3131 test.config = supportedConfig
3132 } else {
3133 test.config = noSupportConfig
3134 }
3135
3136 if supportedInResumeConnection {
3137 test.resumeConfig = &supportedConfig
3138 } else {
3139 test.resumeConfig = &noSupportConfig
3140 }
3141
3142 switch suffix {
3143 case "YesToYes-Client", "YesToYes-Server":
3144 // When a session is resumed, it should
3145 // still be aware that its master
3146 // secret was generated via EMS and
3147 // thus it's safe to use tls-unique.
3148 test.flags = []string{expectEMSFlag}
3149 case "NoToYes-Server":
3150 // If an original connection did not
3151 // contain EMS, but a resumption
3152 // handshake does, then a server should
3153 // not resume the session.
3154 test.expectResumeRejected = true
3155 case "YesToNo-Server":
3156 // Resuming an EMS session without the
3157 // EMS extension should cause the
3158 // server to abort the connection.
3159 test.shouldFail = true
3160 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3161 case "NoToYes-Client":
3162 // A client should abort a connection
3163 // where the server resumed a non-EMS
3164 // session but echoed the EMS
3165 // extension.
3166 test.shouldFail = true
3167 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3168 case "YesToNo-Client":
3169 // A client should abort a connection
3170 // where the server didn't echo EMS
3171 // when the session used it.
3172 test.shouldFail = true
3173 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3174 }
3175
3176 testCases = append(testCases, test)
3177 }
3178 }
3179 }
David Benjamin163c9562016-08-29 23:14:17 -04003180
3181 // Switching EMS on renegotiation is forbidden.
3182 testCases = append(testCases, testCase{
3183 name: "ExtendedMasterSecret-Renego-NoEMS",
3184 config: Config{
3185 MaxVersion: VersionTLS12,
3186 Bugs: ProtocolBugs{
3187 NoExtendedMasterSecret: true,
3188 NoExtendedMasterSecretOnRenegotiation: true,
3189 },
3190 },
3191 renegotiate: 1,
3192 flags: []string{
3193 "-renegotiate-freely",
3194 "-expect-total-renegotiations", "1",
3195 },
3196 })
3197
3198 testCases = append(testCases, testCase{
3199 name: "ExtendedMasterSecret-Renego-Upgrade",
3200 config: Config{
3201 MaxVersion: VersionTLS12,
3202 Bugs: ProtocolBugs{
3203 NoExtendedMasterSecret: true,
3204 },
3205 },
3206 renegotiate: 1,
3207 flags: []string{
3208 "-renegotiate-freely",
3209 "-expect-total-renegotiations", "1",
3210 },
3211 shouldFail: true,
3212 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3213 })
3214
3215 testCases = append(testCases, testCase{
3216 name: "ExtendedMasterSecret-Renego-Downgrade",
3217 config: Config{
3218 MaxVersion: VersionTLS12,
3219 Bugs: ProtocolBugs{
3220 NoExtendedMasterSecretOnRenegotiation: true,
3221 },
3222 },
3223 renegotiate: 1,
3224 flags: []string{
3225 "-renegotiate-freely",
3226 "-expect-total-renegotiations", "1",
3227 },
3228 shouldFail: true,
3229 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3230 })
Adam Langley75712922014-10-10 16:23:43 -07003231}
3232
David Benjamin582ba042016-07-07 12:33:25 -07003233type stateMachineTestConfig struct {
3234 protocol protocol
3235 async bool
3236 splitHandshake, packHandshakeFlight bool
3237}
3238
David Benjamin43ec06f2014-08-05 02:28:57 -04003239// Adds tests that try to cover the range of the handshake state machine, under
3240// various conditions. Some of these are redundant with other tests, but they
3241// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003242func addAllStateMachineCoverageTests() {
3243 for _, async := range []bool{false, true} {
3244 for _, protocol := range []protocol{tls, dtls} {
3245 addStateMachineCoverageTests(stateMachineTestConfig{
3246 protocol: protocol,
3247 async: async,
3248 })
3249 addStateMachineCoverageTests(stateMachineTestConfig{
3250 protocol: protocol,
3251 async: async,
3252 splitHandshake: true,
3253 })
3254 if protocol == tls {
3255 addStateMachineCoverageTests(stateMachineTestConfig{
3256 protocol: protocol,
3257 async: async,
3258 packHandshakeFlight: true,
3259 })
3260 }
3261 }
3262 }
3263}
3264
3265func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003266 var tests []testCase
3267
3268 // Basic handshake, with resumption. Client and server,
3269 // session ID and session ticket.
3270 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003271 name: "Basic-Client",
3272 config: Config{
3273 MaxVersion: VersionTLS12,
3274 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003275 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003276 // Ensure session tickets are used, not session IDs.
3277 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003278 })
3279 tests = append(tests, testCase{
3280 name: "Basic-Client-RenewTicket",
3281 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003282 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003283 Bugs: ProtocolBugs{
3284 RenewTicketOnResume: true,
3285 },
3286 },
David Benjamin46662482016-08-17 00:51:00 -04003287 flags: []string{"-expect-ticket-renewal"},
3288 resumeSession: true,
3289 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003290 })
3291 tests = append(tests, testCase{
3292 name: "Basic-Client-NoTicket",
3293 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003294 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003295 SessionTicketsDisabled: true,
3296 },
3297 resumeSession: true,
3298 })
3299 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003300 name: "Basic-Client-Implicit",
3301 config: Config{
3302 MaxVersion: VersionTLS12,
3303 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003304 flags: []string{"-implicit-handshake"},
3305 resumeSession: true,
3306 })
3307 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003308 testType: serverTest,
3309 name: "Basic-Server",
3310 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003311 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003312 Bugs: ProtocolBugs{
3313 RequireSessionTickets: true,
3314 },
3315 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003316 resumeSession: true,
3317 })
3318 tests = append(tests, testCase{
3319 testType: serverTest,
3320 name: "Basic-Server-NoTickets",
3321 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003322 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003323 SessionTicketsDisabled: true,
3324 },
3325 resumeSession: true,
3326 })
3327 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003328 testType: serverTest,
3329 name: "Basic-Server-Implicit",
3330 config: Config{
3331 MaxVersion: VersionTLS12,
3332 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003333 flags: []string{"-implicit-handshake"},
3334 resumeSession: true,
3335 })
3336 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003337 testType: serverTest,
3338 name: "Basic-Server-EarlyCallback",
3339 config: Config{
3340 MaxVersion: VersionTLS12,
3341 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003342 flags: []string{"-use-early-callback"},
3343 resumeSession: true,
3344 })
3345
Steven Valdez143e8b32016-07-11 13:19:03 -04003346 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003347 if config.protocol == tls {
3348 tests = append(tests, testCase{
3349 name: "TLS13-1RTT-Client",
3350 config: Config{
3351 MaxVersion: VersionTLS13,
3352 MinVersion: VersionTLS13,
3353 },
David Benjamin46662482016-08-17 00:51:00 -04003354 resumeSession: true,
3355 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003356 })
3357
3358 tests = append(tests, testCase{
3359 testType: serverTest,
3360 name: "TLS13-1RTT-Server",
3361 config: Config{
3362 MaxVersion: VersionTLS13,
3363 MinVersion: VersionTLS13,
3364 },
David Benjamin46662482016-08-17 00:51:00 -04003365 resumeSession: true,
3366 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003367 })
3368
3369 tests = append(tests, testCase{
3370 name: "TLS13-HelloRetryRequest-Client",
3371 config: Config{
3372 MaxVersion: VersionTLS13,
3373 MinVersion: VersionTLS13,
3374 // P-384 requires a HelloRetryRequest against
3375 // BoringSSL's default configuration. Assert
3376 // that we do indeed test this with
3377 // ExpectMissingKeyShare.
3378 CurvePreferences: []CurveID{CurveP384},
3379 Bugs: ProtocolBugs{
3380 ExpectMissingKeyShare: true,
3381 },
3382 },
3383 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3384 resumeSession: true,
3385 })
3386
3387 tests = append(tests, testCase{
3388 testType: serverTest,
3389 name: "TLS13-HelloRetryRequest-Server",
3390 config: Config{
3391 MaxVersion: VersionTLS13,
3392 MinVersion: VersionTLS13,
3393 // Require a HelloRetryRequest for every curve.
3394 DefaultCurves: []CurveID{},
3395 },
3396 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3397 resumeSession: true,
3398 })
3399 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003400
David Benjamin760b1dd2015-05-15 23:33:48 -04003401 // TLS client auth.
3402 tests = append(tests, testCase{
3403 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003404 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003406 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003407 ClientAuth: RequestClientCert,
3408 },
3409 })
3410 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003411 testType: serverTest,
3412 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003413 config: Config{
3414 MaxVersion: VersionTLS12,
3415 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003416 // Setting SSL_VERIFY_PEER allows anonymous clients.
3417 flags: []string{"-verify-peer"},
3418 })
David Benjamin582ba042016-07-07 12:33:25 -07003419 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003420 tests = append(tests, testCase{
3421 testType: clientTest,
3422 name: "ClientAuth-NoCertificate-Client-SSL3",
3423 config: Config{
3424 MaxVersion: VersionSSL30,
3425 ClientAuth: RequestClientCert,
3426 },
3427 })
3428 tests = append(tests, testCase{
3429 testType: serverTest,
3430 name: "ClientAuth-NoCertificate-Server-SSL3",
3431 config: Config{
3432 MaxVersion: VersionSSL30,
3433 },
3434 // Setting SSL_VERIFY_PEER allows anonymous clients.
3435 flags: []string{"-verify-peer"},
3436 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003437 tests = append(tests, testCase{
3438 testType: clientTest,
3439 name: "ClientAuth-NoCertificate-Client-TLS13",
3440 config: Config{
3441 MaxVersion: VersionTLS13,
3442 ClientAuth: RequestClientCert,
3443 },
3444 })
3445 tests = append(tests, testCase{
3446 testType: serverTest,
3447 name: "ClientAuth-NoCertificate-Server-TLS13",
3448 config: Config{
3449 MaxVersion: VersionTLS13,
3450 },
3451 // Setting SSL_VERIFY_PEER allows anonymous clients.
3452 flags: []string{"-verify-peer"},
3453 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003454 }
3455 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003456 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003457 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003459 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003460 ClientAuth: RequireAnyClientCert,
3461 },
3462 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003463 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3464 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003465 },
3466 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003467 tests = append(tests, testCase{
3468 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003469 name: "ClientAuth-RSA-Client-TLS13",
3470 config: Config{
3471 MaxVersion: VersionTLS13,
3472 ClientAuth: RequireAnyClientCert,
3473 },
3474 flags: []string{
3475 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3476 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3477 },
3478 })
3479 tests = append(tests, testCase{
3480 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003481 name: "ClientAuth-ECDSA-Client",
3482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003483 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003484 ClientAuth: RequireAnyClientCert,
3485 },
3486 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003487 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3488 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003489 },
3490 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003491 tests = append(tests, testCase{
3492 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003493 name: "ClientAuth-ECDSA-Client-TLS13",
3494 config: Config{
3495 MaxVersion: VersionTLS13,
3496 ClientAuth: RequireAnyClientCert,
3497 },
3498 flags: []string{
3499 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3500 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3501 },
3502 })
3503 tests = append(tests, testCase{
3504 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003505 name: "ClientAuth-NoCertificate-OldCallback",
3506 config: Config{
3507 MaxVersion: VersionTLS12,
3508 ClientAuth: RequestClientCert,
3509 },
3510 flags: []string{"-use-old-client-cert-callback"},
3511 })
3512 tests = append(tests, testCase{
3513 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003514 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3515 config: Config{
3516 MaxVersion: VersionTLS13,
3517 ClientAuth: RequestClientCert,
3518 },
3519 flags: []string{"-use-old-client-cert-callback"},
3520 })
3521 tests = append(tests, testCase{
3522 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003523 name: "ClientAuth-OldCallback",
3524 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003525 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003526 ClientAuth: RequireAnyClientCert,
3527 },
3528 flags: []string{
3529 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3530 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3531 "-use-old-client-cert-callback",
3532 },
3533 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003534 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003535 testType: clientTest,
3536 name: "ClientAuth-OldCallback-TLS13",
3537 config: Config{
3538 MaxVersion: VersionTLS13,
3539 ClientAuth: RequireAnyClientCert,
3540 },
3541 flags: []string{
3542 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3543 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3544 "-use-old-client-cert-callback",
3545 },
3546 })
3547 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003548 testType: serverTest,
3549 name: "ClientAuth-Server",
3550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003551 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003552 Certificates: []Certificate{rsaCertificate},
3553 },
3554 flags: []string{"-require-any-client-certificate"},
3555 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003556 tests = append(tests, testCase{
3557 testType: serverTest,
3558 name: "ClientAuth-Server-TLS13",
3559 config: Config{
3560 MaxVersion: VersionTLS13,
3561 Certificates: []Certificate{rsaCertificate},
3562 },
3563 flags: []string{"-require-any-client-certificate"},
3564 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003565
David Benjamin4c3ddf72016-06-29 18:13:53 -04003566 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003567 tests = append(tests, testCase{
3568 testType: serverTest,
3569 name: "Basic-Server-RSA",
3570 config: Config{
3571 MaxVersion: VersionTLS12,
3572 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3573 },
3574 flags: []string{
3575 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3576 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3577 },
3578 })
3579 tests = append(tests, testCase{
3580 testType: serverTest,
3581 name: "Basic-Server-ECDHE-RSA",
3582 config: Config{
3583 MaxVersion: VersionTLS12,
3584 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3585 },
3586 flags: []string{
3587 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3588 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3589 },
3590 })
3591 tests = append(tests, testCase{
3592 testType: serverTest,
3593 name: "Basic-Server-ECDHE-ECDSA",
3594 config: Config{
3595 MaxVersion: VersionTLS12,
3596 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3597 },
3598 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003599 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3600 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003601 },
3602 })
3603
David Benjamin760b1dd2015-05-15 23:33:48 -04003604 // No session ticket support; server doesn't send NewSessionTicket.
3605 tests = append(tests, testCase{
3606 name: "SessionTicketsDisabled-Client",
3607 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003608 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003609 SessionTicketsDisabled: true,
3610 },
3611 })
3612 tests = append(tests, testCase{
3613 testType: serverTest,
3614 name: "SessionTicketsDisabled-Server",
3615 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003616 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003617 SessionTicketsDisabled: true,
3618 },
3619 })
3620
3621 // Skip ServerKeyExchange in PSK key exchange if there's no
3622 // identity hint.
3623 tests = append(tests, testCase{
3624 name: "EmptyPSKHint-Client",
3625 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003626 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003627 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3628 PreSharedKey: []byte("secret"),
3629 },
3630 flags: []string{"-psk", "secret"},
3631 })
3632 tests = append(tests, testCase{
3633 testType: serverTest,
3634 name: "EmptyPSKHint-Server",
3635 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003636 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003637 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3638 PreSharedKey: []byte("secret"),
3639 },
3640 flags: []string{"-psk", "secret"},
3641 })
3642
David Benjamin4c3ddf72016-06-29 18:13:53 -04003643 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003644 tests = append(tests, testCase{
3645 testType: clientTest,
3646 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003647 config: Config{
3648 MaxVersion: VersionTLS12,
3649 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003650 flags: []string{
3651 "-enable-ocsp-stapling",
3652 "-expect-ocsp-response",
3653 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003654 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003655 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003656 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003657 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003658 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003659 testType: serverTest,
3660 name: "OCSPStapling-Server",
3661 config: Config{
3662 MaxVersion: VersionTLS12,
3663 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003664 expectedOCSPResponse: testOCSPResponse,
3665 flags: []string{
3666 "-ocsp-response",
3667 base64.StdEncoding.EncodeToString(testOCSPResponse),
3668 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003669 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003670 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003671 tests = append(tests, testCase{
3672 testType: clientTest,
3673 name: "OCSPStapling-Client-TLS13",
3674 config: Config{
3675 MaxVersion: VersionTLS13,
3676 },
3677 flags: []string{
3678 "-enable-ocsp-stapling",
3679 "-expect-ocsp-response",
3680 base64.StdEncoding.EncodeToString(testOCSPResponse),
3681 "-verify-peer",
3682 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003683 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003684 })
3685 tests = append(tests, testCase{
3686 testType: serverTest,
3687 name: "OCSPStapling-Server-TLS13",
3688 config: Config{
3689 MaxVersion: VersionTLS13,
3690 },
3691 expectedOCSPResponse: testOCSPResponse,
3692 flags: []string{
3693 "-ocsp-response",
3694 base64.StdEncoding.EncodeToString(testOCSPResponse),
3695 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003696 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003697 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003698
David Benjamin4c3ddf72016-06-29 18:13:53 -04003699 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003700 for _, vers := range tlsVersions {
3701 if config.protocol == dtls && !vers.hasDTLS {
3702 continue
3703 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003704 for _, testType := range []testType{clientTest, serverTest} {
3705 suffix := "-Client"
3706 if testType == serverTest {
3707 suffix = "-Server"
3708 }
3709 suffix += "-" + vers.name
3710
3711 flag := "-verify-peer"
3712 if testType == serverTest {
3713 flag = "-require-any-client-certificate"
3714 }
3715
3716 tests = append(tests, testCase{
3717 testType: testType,
3718 name: "CertificateVerificationSucceed" + suffix,
3719 config: Config{
3720 MaxVersion: vers.version,
3721 Certificates: []Certificate{rsaCertificate},
3722 },
3723 flags: []string{
3724 flag,
3725 "-expect-verify-result",
3726 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003727 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003728 })
3729 tests = append(tests, testCase{
3730 testType: testType,
3731 name: "CertificateVerificationFail" + suffix,
3732 config: Config{
3733 MaxVersion: vers.version,
3734 Certificates: []Certificate{rsaCertificate},
3735 },
3736 flags: []string{
3737 flag,
3738 "-verify-fail",
3739 },
3740 shouldFail: true,
3741 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3742 })
3743 }
3744
3745 // By default, the client is in a soft fail mode where the peer
3746 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003747 tests = append(tests, testCase{
3748 testType: clientTest,
3749 name: "CertificateVerificationSoftFail-" + vers.name,
3750 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003751 MaxVersion: vers.version,
3752 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003753 },
3754 flags: []string{
3755 "-verify-fail",
3756 "-expect-verify-result",
3757 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003758 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003759 })
3760 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003761
David Benjamin1d4f4c02016-07-26 18:03:08 -04003762 tests = append(tests, testCase{
3763 name: "ShimSendAlert",
3764 flags: []string{"-send-alert"},
3765 shimWritesFirst: true,
3766 shouldFail: true,
3767 expectedLocalError: "remote error: decompression failure",
3768 })
3769
David Benjamin582ba042016-07-07 12:33:25 -07003770 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003771 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003772 name: "Renegotiate-Client",
3773 config: Config{
3774 MaxVersion: VersionTLS12,
3775 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003776 renegotiate: 1,
3777 flags: []string{
3778 "-renegotiate-freely",
3779 "-expect-total-renegotiations", "1",
3780 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003781 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003782
David Benjamin47921102016-07-28 11:29:18 -04003783 tests = append(tests, testCase{
3784 name: "SendHalfHelloRequest",
3785 config: Config{
3786 MaxVersion: VersionTLS12,
3787 Bugs: ProtocolBugs{
3788 PackHelloRequestWithFinished: config.packHandshakeFlight,
3789 },
3790 },
3791 sendHalfHelloRequest: true,
3792 flags: []string{"-renegotiate-ignore"},
3793 shouldFail: true,
3794 expectedError: ":UNEXPECTED_RECORD:",
3795 })
3796
David Benjamin760b1dd2015-05-15 23:33:48 -04003797 // NPN on client and server; results in post-handshake message.
3798 tests = append(tests, testCase{
3799 name: "NPN-Client",
3800 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003801 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003802 NextProtos: []string{"foo"},
3803 },
3804 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003805 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 expectedNextProto: "foo",
3807 expectedNextProtoType: npn,
3808 })
3809 tests = append(tests, testCase{
3810 testType: serverTest,
3811 name: "NPN-Server",
3812 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003813 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003814 NextProtos: []string{"bar"},
3815 },
3816 flags: []string{
3817 "-advertise-npn", "\x03foo\x03bar\x03baz",
3818 "-expect-next-proto", "bar",
3819 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003820 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003821 expectedNextProto: "bar",
3822 expectedNextProtoType: npn,
3823 })
3824
3825 // TODO(davidben): Add tests for when False Start doesn't trigger.
3826
3827 // Client does False Start and negotiates NPN.
3828 tests = append(tests, testCase{
3829 name: "FalseStart",
3830 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003831 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003832 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3833 NextProtos: []string{"foo"},
3834 Bugs: ProtocolBugs{
3835 ExpectFalseStart: true,
3836 },
3837 },
3838 flags: []string{
3839 "-false-start",
3840 "-select-next-proto", "foo",
3841 },
3842 shimWritesFirst: true,
3843 resumeSession: true,
3844 })
3845
3846 // Client does False Start and negotiates ALPN.
3847 tests = append(tests, testCase{
3848 name: "FalseStart-ALPN",
3849 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003850 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003851 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3852 NextProtos: []string{"foo"},
3853 Bugs: ProtocolBugs{
3854 ExpectFalseStart: true,
3855 },
3856 },
3857 flags: []string{
3858 "-false-start",
3859 "-advertise-alpn", "\x03foo",
3860 },
3861 shimWritesFirst: true,
3862 resumeSession: true,
3863 })
3864
3865 // Client does False Start but doesn't explicitly call
3866 // SSL_connect.
3867 tests = append(tests, testCase{
3868 name: "FalseStart-Implicit",
3869 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003870 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3872 NextProtos: []string{"foo"},
3873 },
3874 flags: []string{
3875 "-implicit-handshake",
3876 "-false-start",
3877 "-advertise-alpn", "\x03foo",
3878 },
3879 })
3880
3881 // False Start without session tickets.
3882 tests = append(tests, testCase{
3883 name: "FalseStart-SessionTicketsDisabled",
3884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003885 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3887 NextProtos: []string{"foo"},
3888 SessionTicketsDisabled: true,
3889 Bugs: ProtocolBugs{
3890 ExpectFalseStart: true,
3891 },
3892 },
3893 flags: []string{
3894 "-false-start",
3895 "-select-next-proto", "foo",
3896 },
3897 shimWritesFirst: true,
3898 })
3899
Adam Langleydf759b52016-07-11 15:24:37 -07003900 tests = append(tests, testCase{
3901 name: "FalseStart-CECPQ1",
3902 config: Config{
3903 MaxVersion: VersionTLS12,
3904 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3905 NextProtos: []string{"foo"},
3906 Bugs: ProtocolBugs{
3907 ExpectFalseStart: true,
3908 },
3909 },
3910 flags: []string{
3911 "-false-start",
3912 "-cipher", "DEFAULT:kCECPQ1",
3913 "-select-next-proto", "foo",
3914 },
3915 shimWritesFirst: true,
3916 resumeSession: true,
3917 })
3918
David Benjamin760b1dd2015-05-15 23:33:48 -04003919 // Server parses a V2ClientHello.
3920 tests = append(tests, testCase{
3921 testType: serverTest,
3922 name: "SendV2ClientHello",
3923 config: Config{
3924 // Choose a cipher suite that does not involve
3925 // elliptic curves, so no extensions are
3926 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003927 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003928 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003929 Bugs: ProtocolBugs{
3930 SendV2ClientHello: true,
3931 },
3932 },
3933 })
3934
3935 // Client sends a Channel ID.
3936 tests = append(tests, testCase{
3937 name: "ChannelID-Client",
3938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003939 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003940 RequestChannelID: true,
3941 },
Adam Langley7c803a62015-06-15 15:35:05 -07003942 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003943 resumeSession: true,
3944 expectChannelID: true,
3945 })
3946
3947 // Server accepts a Channel ID.
3948 tests = append(tests, testCase{
3949 testType: serverTest,
3950 name: "ChannelID-Server",
3951 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003952 MaxVersion: VersionTLS12,
3953 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003954 },
3955 flags: []string{
3956 "-expect-channel-id",
3957 base64.StdEncoding.EncodeToString(channelIDBytes),
3958 },
3959 resumeSession: true,
3960 expectChannelID: true,
3961 })
David Benjamin30789da2015-08-29 22:56:45 -04003962
David Benjaminf8fcdf32016-06-08 15:56:13 -04003963 // Channel ID and NPN at the same time, to ensure their relative
3964 // ordering is correct.
3965 tests = append(tests, testCase{
3966 name: "ChannelID-NPN-Client",
3967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003968 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003969 RequestChannelID: true,
3970 NextProtos: []string{"foo"},
3971 },
3972 flags: []string{
3973 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3974 "-select-next-proto", "foo",
3975 },
3976 resumeSession: true,
3977 expectChannelID: true,
3978 expectedNextProto: "foo",
3979 expectedNextProtoType: npn,
3980 })
3981 tests = append(tests, testCase{
3982 testType: serverTest,
3983 name: "ChannelID-NPN-Server",
3984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003985 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003986 ChannelID: channelIDKey,
3987 NextProtos: []string{"bar"},
3988 },
3989 flags: []string{
3990 "-expect-channel-id",
3991 base64.StdEncoding.EncodeToString(channelIDBytes),
3992 "-advertise-npn", "\x03foo\x03bar\x03baz",
3993 "-expect-next-proto", "bar",
3994 },
3995 resumeSession: true,
3996 expectChannelID: true,
3997 expectedNextProto: "bar",
3998 expectedNextProtoType: npn,
3999 })
4000
David Benjamin30789da2015-08-29 22:56:45 -04004001 // Bidirectional shutdown with the runner initiating.
4002 tests = append(tests, testCase{
4003 name: "Shutdown-Runner",
4004 config: Config{
4005 Bugs: ProtocolBugs{
4006 ExpectCloseNotify: true,
4007 },
4008 },
4009 flags: []string{"-check-close-notify"},
4010 })
4011
4012 // Bidirectional shutdown with the shim initiating. The runner,
4013 // in the meantime, sends garbage before the close_notify which
4014 // the shim must ignore.
4015 tests = append(tests, testCase{
4016 name: "Shutdown-Shim",
4017 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004018 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004019 Bugs: ProtocolBugs{
4020 ExpectCloseNotify: true,
4021 },
4022 },
4023 shimShutsDown: true,
4024 sendEmptyRecords: 1,
4025 sendWarningAlerts: 1,
4026 flags: []string{"-check-close-notify"},
4027 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004028 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004029 // TODO(davidben): DTLS 1.3 will want a similar thing for
4030 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004031 tests = append(tests, testCase{
4032 name: "SkipHelloVerifyRequest",
4033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004034 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004035 Bugs: ProtocolBugs{
4036 SkipHelloVerifyRequest: true,
4037 },
4038 },
4039 })
4040 }
4041
David Benjamin760b1dd2015-05-15 23:33:48 -04004042 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004043 test.protocol = config.protocol
4044 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004045 test.name += "-DTLS"
4046 }
David Benjamin582ba042016-07-07 12:33:25 -07004047 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004048 test.name += "-Async"
4049 test.flags = append(test.flags, "-async")
4050 } else {
4051 test.name += "-Sync"
4052 }
David Benjamin582ba042016-07-07 12:33:25 -07004053 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004054 test.name += "-SplitHandshakeRecords"
4055 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004056 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004057 test.config.Bugs.MaxPacketLength = 256
4058 test.flags = append(test.flags, "-mtu", "256")
4059 }
4060 }
David Benjamin582ba042016-07-07 12:33:25 -07004061 if config.packHandshakeFlight {
4062 test.name += "-PackHandshakeFlight"
4063 test.config.Bugs.PackHandshakeFlight = true
4064 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004065 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004066 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004067}
4068
Adam Langley524e7172015-02-20 16:04:00 -08004069func addDDoSCallbackTests() {
4070 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004071 for _, resume := range []bool{false, true} {
4072 suffix := "Resume"
4073 if resume {
4074 suffix = "No" + suffix
4075 }
4076
4077 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004078 testType: serverTest,
4079 name: "Server-DDoS-OK-" + suffix,
4080 config: Config{
4081 MaxVersion: VersionTLS12,
4082 },
Adam Langley524e7172015-02-20 16:04:00 -08004083 flags: []string{"-install-ddos-callback"},
4084 resumeSession: resume,
4085 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004086 testCases = append(testCases, testCase{
4087 testType: serverTest,
4088 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4089 config: Config{
4090 MaxVersion: VersionTLS13,
4091 },
4092 flags: []string{"-install-ddos-callback"},
4093 resumeSession: resume,
4094 })
Adam Langley524e7172015-02-20 16:04:00 -08004095
4096 failFlag := "-fail-ddos-callback"
4097 if resume {
4098 failFlag = "-fail-second-ddos-callback"
4099 }
4100 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004101 testType: serverTest,
4102 name: "Server-DDoS-Reject-" + suffix,
4103 config: Config{
4104 MaxVersion: VersionTLS12,
4105 },
David Benjamin2c66e072016-09-16 15:58:00 -04004106 flags: []string{"-install-ddos-callback", failFlag},
4107 resumeSession: resume,
4108 shouldFail: true,
4109 expectedError: ":CONNECTION_REJECTED:",
4110 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004111 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004112 testCases = append(testCases, testCase{
4113 testType: serverTest,
4114 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4115 config: Config{
4116 MaxVersion: VersionTLS13,
4117 },
David Benjamin2c66e072016-09-16 15:58:00 -04004118 flags: []string{"-install-ddos-callback", failFlag},
4119 resumeSession: resume,
4120 shouldFail: true,
4121 expectedError: ":CONNECTION_REJECTED:",
4122 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004123 })
Adam Langley524e7172015-02-20 16:04:00 -08004124 }
4125}
4126
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004127func addVersionNegotiationTests() {
4128 for i, shimVers := range tlsVersions {
4129 // Assemble flags to disable all newer versions on the shim.
4130 var flags []string
4131 for _, vers := range tlsVersions[i+1:] {
4132 flags = append(flags, vers.flag)
4133 }
4134
Steven Valdezfdd10992016-09-15 16:27:05 -04004135 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004136 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004137 protocols := []protocol{tls}
4138 if runnerVers.hasDTLS && shimVers.hasDTLS {
4139 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004140 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004141 for _, protocol := range protocols {
4142 expectedVersion := shimVers.version
4143 if runnerVers.version < shimVers.version {
4144 expectedVersion = runnerVers.version
4145 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004146
David Benjamin8b8c0062014-11-23 02:47:52 -05004147 suffix := shimVers.name + "-" + runnerVers.name
4148 if protocol == dtls {
4149 suffix += "-DTLS"
4150 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004151
David Benjamin1eb367c2014-12-12 18:17:51 -05004152 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4153
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004154 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004155 clientVers := shimVers.version
4156 if clientVers > VersionTLS10 {
4157 clientVers = VersionTLS10
4158 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004159 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004160 serverVers := expectedVersion
4161 if expectedVersion >= VersionTLS13 {
4162 serverVers = VersionTLS10
4163 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004164 serverVers = versionToWire(serverVers, protocol == dtls)
4165
David Benjamin8b8c0062014-11-23 02:47:52 -05004166 testCases = append(testCases, testCase{
4167 protocol: protocol,
4168 testType: clientTest,
4169 name: "VersionNegotiation-Client-" + suffix,
4170 config: Config{
4171 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004172 Bugs: ProtocolBugs{
4173 ExpectInitialRecordVersion: clientVers,
4174 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004175 },
4176 flags: flags,
4177 expectedVersion: expectedVersion,
4178 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004179 testCases = append(testCases, testCase{
4180 protocol: protocol,
4181 testType: clientTest,
4182 name: "VersionNegotiation-Client2-" + suffix,
4183 config: Config{
4184 MaxVersion: runnerVers.version,
4185 Bugs: ProtocolBugs{
4186 ExpectInitialRecordVersion: clientVers,
4187 },
4188 },
4189 flags: []string{"-max-version", shimVersFlag},
4190 expectedVersion: expectedVersion,
4191 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004192
4193 testCases = append(testCases, testCase{
4194 protocol: protocol,
4195 testType: serverTest,
4196 name: "VersionNegotiation-Server-" + suffix,
4197 config: Config{
4198 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004199 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004200 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004201 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004202 },
4203 flags: flags,
4204 expectedVersion: expectedVersion,
4205 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004206 testCases = append(testCases, testCase{
4207 protocol: protocol,
4208 testType: serverTest,
4209 name: "VersionNegotiation-Server2-" + suffix,
4210 config: Config{
4211 MaxVersion: runnerVers.version,
4212 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004213 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004214 },
4215 },
4216 flags: []string{"-max-version", shimVersFlag},
4217 expectedVersion: expectedVersion,
4218 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004219 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004220 }
4221 }
David Benjamin95c69562016-06-29 18:15:03 -04004222
Steven Valdezfdd10992016-09-15 16:27:05 -04004223 // Test the version extension at all versions.
4224 for _, vers := range tlsVersions {
4225 protocols := []protocol{tls}
4226 if vers.hasDTLS {
4227 protocols = append(protocols, dtls)
4228 }
4229 for _, protocol := range protocols {
4230 suffix := vers.name
4231 if protocol == dtls {
4232 suffix += "-DTLS"
4233 }
4234
4235 wireVersion := versionToWire(vers.version, protocol == dtls)
4236 testCases = append(testCases, testCase{
4237 protocol: protocol,
4238 testType: serverTest,
4239 name: "VersionNegotiationExtension-" + suffix,
4240 config: Config{
4241 Bugs: ProtocolBugs{
4242 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4243 },
4244 },
4245 expectedVersion: vers.version,
4246 })
4247 }
4248
4249 }
4250
4251 // If all versions are unknown, negotiation fails.
4252 testCases = append(testCases, testCase{
4253 testType: serverTest,
4254 name: "NoSupportedVersions",
4255 config: Config{
4256 Bugs: ProtocolBugs{
4257 SendSupportedVersions: []uint16{0x1111},
4258 },
4259 },
4260 shouldFail: true,
4261 expectedError: ":UNSUPPORTED_PROTOCOL:",
4262 })
4263 testCases = append(testCases, testCase{
4264 protocol: dtls,
4265 testType: serverTest,
4266 name: "NoSupportedVersions-DTLS",
4267 config: Config{
4268 Bugs: ProtocolBugs{
4269 SendSupportedVersions: []uint16{0x1111},
4270 },
4271 },
4272 shouldFail: true,
4273 expectedError: ":UNSUPPORTED_PROTOCOL:",
4274 })
4275
4276 testCases = append(testCases, testCase{
4277 testType: serverTest,
4278 name: "ClientHelloVersionTooHigh",
4279 config: Config{
4280 MaxVersion: VersionTLS13,
4281 Bugs: ProtocolBugs{
4282 SendClientVersion: 0x0304,
4283 OmitSupportedVersions: true,
4284 },
4285 },
4286 expectedVersion: VersionTLS12,
4287 })
4288
4289 testCases = append(testCases, testCase{
4290 testType: serverTest,
4291 name: "ConflictingVersionNegotiation",
4292 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004293 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004294 SendClientVersion: VersionTLS12,
4295 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004296 },
4297 },
David Benjaminad75a662016-09-30 15:42:59 -04004298 // The extension takes precedence over the ClientHello version.
4299 expectedVersion: VersionTLS11,
4300 })
4301
4302 testCases = append(testCases, testCase{
4303 testType: serverTest,
4304 name: "ConflictingVersionNegotiation-2",
4305 config: Config{
4306 Bugs: ProtocolBugs{
4307 SendClientVersion: VersionTLS11,
4308 SendSupportedVersions: []uint16{VersionTLS12},
4309 },
4310 },
4311 // The extension takes precedence over the ClientHello version.
4312 expectedVersion: VersionTLS12,
4313 })
4314
4315 testCases = append(testCases, testCase{
4316 testType: serverTest,
4317 name: "RejectFinalTLS13",
4318 config: Config{
4319 Bugs: ProtocolBugs{
4320 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4321 },
4322 },
4323 // We currently implement a draft TLS 1.3 version. Ensure that
4324 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004325 expectedVersion: VersionTLS12,
4326 })
4327
David Benjamin95c69562016-06-29 18:15:03 -04004328 // Test for version tolerance.
4329 testCases = append(testCases, testCase{
4330 testType: serverTest,
4331 name: "MinorVersionTolerance",
4332 config: Config{
4333 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004334 SendClientVersion: 0x03ff,
4335 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004336 },
4337 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004338 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004339 })
4340 testCases = append(testCases, testCase{
4341 testType: serverTest,
4342 name: "MajorVersionTolerance",
4343 config: Config{
4344 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004345 SendClientVersion: 0x0400,
4346 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004347 },
4348 },
David Benjaminad75a662016-09-30 15:42:59 -04004349 // TLS 1.3 must be negotiated with the supported_versions
4350 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004351 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004352 })
David Benjaminad75a662016-09-30 15:42:59 -04004353 testCases = append(testCases, testCase{
4354 testType: serverTest,
4355 name: "VersionTolerance-TLS13",
4356 config: Config{
4357 Bugs: ProtocolBugs{
4358 // Although TLS 1.3 does not use
4359 // ClientHello.version, it still tolerates high
4360 // values there.
4361 SendClientVersion: 0x0400,
4362 },
4363 },
4364 expectedVersion: VersionTLS13,
4365 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004366
David Benjamin95c69562016-06-29 18:15:03 -04004367 testCases = append(testCases, testCase{
4368 protocol: dtls,
4369 testType: serverTest,
4370 name: "MinorVersionTolerance-DTLS",
4371 config: Config{
4372 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004373 SendClientVersion: 0xfe00,
4374 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004375 },
4376 },
4377 expectedVersion: VersionTLS12,
4378 })
4379 testCases = append(testCases, testCase{
4380 protocol: dtls,
4381 testType: serverTest,
4382 name: "MajorVersionTolerance-DTLS",
4383 config: Config{
4384 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004385 SendClientVersion: 0xfdff,
4386 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004387 },
4388 },
4389 expectedVersion: VersionTLS12,
4390 })
4391
4392 // Test that versions below 3.0 are rejected.
4393 testCases = append(testCases, testCase{
4394 testType: serverTest,
4395 name: "VersionTooLow",
4396 config: Config{
4397 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004398 SendClientVersion: 0x0200,
4399 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004400 },
4401 },
4402 shouldFail: true,
4403 expectedError: ":UNSUPPORTED_PROTOCOL:",
4404 })
4405 testCases = append(testCases, testCase{
4406 protocol: dtls,
4407 testType: serverTest,
4408 name: "VersionTooLow-DTLS",
4409 config: Config{
4410 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004411 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004412 },
4413 },
4414 shouldFail: true,
4415 expectedError: ":UNSUPPORTED_PROTOCOL:",
4416 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004417
David Benjamin2dc02042016-09-19 19:57:37 -04004418 testCases = append(testCases, testCase{
4419 name: "ServerBogusVersion",
4420 config: Config{
4421 Bugs: ProtocolBugs{
4422 SendServerHelloVersion: 0x1234,
4423 },
4424 },
4425 shouldFail: true,
4426 expectedError: ":UNSUPPORTED_PROTOCOL:",
4427 })
4428
David Benjamin1f61f0d2016-07-10 12:20:35 -04004429 // Test TLS 1.3's downgrade signal.
4430 testCases = append(testCases, testCase{
4431 name: "Downgrade-TLS12-Client",
4432 config: Config{
4433 Bugs: ProtocolBugs{
4434 NegotiateVersion: VersionTLS12,
4435 },
4436 },
David Benjamin592b5322016-09-30 15:15:01 -04004437 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004438 // TODO(davidben): This test should fail once TLS 1.3 is final
4439 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004440 })
4441 testCases = append(testCases, testCase{
4442 testType: serverTest,
4443 name: "Downgrade-TLS12-Server",
4444 config: Config{
4445 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004446 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004447 },
4448 },
David Benjamin592b5322016-09-30 15:15:01 -04004449 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004450 // TODO(davidben): This test should fail once TLS 1.3 is final
4451 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004452 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004453}
4454
David Benjaminaccb4542014-12-12 23:44:33 -05004455func addMinimumVersionTests() {
4456 for i, shimVers := range tlsVersions {
4457 // Assemble flags to disable all older versions on the shim.
4458 var flags []string
4459 for _, vers := range tlsVersions[:i] {
4460 flags = append(flags, vers.flag)
4461 }
4462
4463 for _, runnerVers := range tlsVersions {
4464 protocols := []protocol{tls}
4465 if runnerVers.hasDTLS && shimVers.hasDTLS {
4466 protocols = append(protocols, dtls)
4467 }
4468 for _, protocol := range protocols {
4469 suffix := shimVers.name + "-" + runnerVers.name
4470 if protocol == dtls {
4471 suffix += "-DTLS"
4472 }
4473 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4474
David Benjaminaccb4542014-12-12 23:44:33 -05004475 var expectedVersion uint16
4476 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004477 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004478 if runnerVers.version >= shimVers.version {
4479 expectedVersion = runnerVers.version
4480 } else {
4481 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004482 expectedError = ":UNSUPPORTED_PROTOCOL:"
4483 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004484 }
4485
4486 testCases = append(testCases, testCase{
4487 protocol: protocol,
4488 testType: clientTest,
4489 name: "MinimumVersion-Client-" + suffix,
4490 config: Config{
4491 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004492 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004493 // Ensure the server does not decline to
4494 // select a version (versions extension) or
4495 // cipher (some ciphers depend on versions).
4496 NegotiateVersion: runnerVers.version,
4497 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004498 },
David Benjaminaccb4542014-12-12 23:44:33 -05004499 },
David Benjamin87909c02014-12-13 01:55:01 -05004500 flags: flags,
4501 expectedVersion: expectedVersion,
4502 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004503 expectedError: expectedError,
4504 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004505 })
4506 testCases = append(testCases, testCase{
4507 protocol: protocol,
4508 testType: clientTest,
4509 name: "MinimumVersion-Client2-" + suffix,
4510 config: Config{
4511 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004512 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004513 // Ensure the server does not decline to
4514 // select a version (versions extension) or
4515 // cipher (some ciphers depend on versions).
4516 NegotiateVersion: runnerVers.version,
4517 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004518 },
David Benjaminaccb4542014-12-12 23:44:33 -05004519 },
David Benjamin87909c02014-12-13 01:55:01 -05004520 flags: []string{"-min-version", shimVersFlag},
4521 expectedVersion: expectedVersion,
4522 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004523 expectedError: expectedError,
4524 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004525 })
4526
4527 testCases = append(testCases, testCase{
4528 protocol: protocol,
4529 testType: serverTest,
4530 name: "MinimumVersion-Server-" + suffix,
4531 config: Config{
4532 MaxVersion: runnerVers.version,
4533 },
David Benjamin87909c02014-12-13 01:55:01 -05004534 flags: flags,
4535 expectedVersion: expectedVersion,
4536 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004537 expectedError: expectedError,
4538 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004539 })
4540 testCases = append(testCases, testCase{
4541 protocol: protocol,
4542 testType: serverTest,
4543 name: "MinimumVersion-Server2-" + suffix,
4544 config: Config{
4545 MaxVersion: runnerVers.version,
4546 },
David Benjamin87909c02014-12-13 01:55:01 -05004547 flags: []string{"-min-version", shimVersFlag},
4548 expectedVersion: expectedVersion,
4549 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004550 expectedError: expectedError,
4551 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004552 })
4553 }
4554 }
4555 }
4556}
4557
David Benjamine78bfde2014-09-06 12:45:15 -04004558func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004559 // TODO(davidben): Extensions, where applicable, all move their server
4560 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4561 // tests for both. Also test interaction with 0-RTT when implemented.
4562
David Benjamin97d17d92016-07-14 16:12:00 -04004563 // Repeat extensions tests all versions except SSL 3.0.
4564 for _, ver := range tlsVersions {
4565 if ver.version == VersionSSL30 {
4566 continue
4567 }
4568
David Benjamin97d17d92016-07-14 16:12:00 -04004569 // Test that duplicate extensions are rejected.
4570 testCases = append(testCases, testCase{
4571 testType: clientTest,
4572 name: "DuplicateExtensionClient-" + ver.name,
4573 config: Config{
4574 MaxVersion: ver.version,
4575 Bugs: ProtocolBugs{
4576 DuplicateExtension: true,
4577 },
David Benjamine78bfde2014-09-06 12:45:15 -04004578 },
David Benjamin97d17d92016-07-14 16:12:00 -04004579 shouldFail: true,
4580 expectedLocalError: "remote error: error decoding message",
4581 })
4582 testCases = append(testCases, testCase{
4583 testType: serverTest,
4584 name: "DuplicateExtensionServer-" + ver.name,
4585 config: Config{
4586 MaxVersion: ver.version,
4587 Bugs: ProtocolBugs{
4588 DuplicateExtension: true,
4589 },
David Benjamine78bfde2014-09-06 12:45:15 -04004590 },
David Benjamin97d17d92016-07-14 16:12:00 -04004591 shouldFail: true,
4592 expectedLocalError: "remote error: error decoding message",
4593 })
4594
4595 // Test SNI.
4596 testCases = append(testCases, testCase{
4597 testType: clientTest,
4598 name: "ServerNameExtensionClient-" + ver.name,
4599 config: Config{
4600 MaxVersion: ver.version,
4601 Bugs: ProtocolBugs{
4602 ExpectServerName: "example.com",
4603 },
David Benjamine78bfde2014-09-06 12:45:15 -04004604 },
David Benjamin97d17d92016-07-14 16:12:00 -04004605 flags: []string{"-host-name", "example.com"},
4606 })
4607 testCases = append(testCases, testCase{
4608 testType: clientTest,
4609 name: "ServerNameExtensionClientMismatch-" + ver.name,
4610 config: Config{
4611 MaxVersion: ver.version,
4612 Bugs: ProtocolBugs{
4613 ExpectServerName: "mismatch.com",
4614 },
David Benjamine78bfde2014-09-06 12:45:15 -04004615 },
David Benjamin97d17d92016-07-14 16:12:00 -04004616 flags: []string{"-host-name", "example.com"},
4617 shouldFail: true,
4618 expectedLocalError: "tls: unexpected server name",
4619 })
4620 testCases = append(testCases, testCase{
4621 testType: clientTest,
4622 name: "ServerNameExtensionClientMissing-" + ver.name,
4623 config: Config{
4624 MaxVersion: ver.version,
4625 Bugs: ProtocolBugs{
4626 ExpectServerName: "missing.com",
4627 },
David Benjamine78bfde2014-09-06 12:45:15 -04004628 },
David Benjamin97d17d92016-07-14 16:12:00 -04004629 shouldFail: true,
4630 expectedLocalError: "tls: unexpected server name",
4631 })
4632 testCases = append(testCases, testCase{
4633 testType: serverTest,
4634 name: "ServerNameExtensionServer-" + ver.name,
4635 config: Config{
4636 MaxVersion: ver.version,
4637 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004638 },
David Benjamin97d17d92016-07-14 16:12:00 -04004639 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004640 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004641 })
4642
4643 // Test ALPN.
4644 testCases = append(testCases, testCase{
4645 testType: clientTest,
4646 name: "ALPNClient-" + ver.name,
4647 config: Config{
4648 MaxVersion: ver.version,
4649 NextProtos: []string{"foo"},
4650 },
4651 flags: []string{
4652 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4653 "-expect-alpn", "foo",
4654 },
4655 expectedNextProto: "foo",
4656 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004657 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004658 })
4659 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004660 testType: clientTest,
4661 name: "ALPNClient-Mismatch-" + ver.name,
4662 config: Config{
4663 MaxVersion: ver.version,
4664 Bugs: ProtocolBugs{
4665 SendALPN: "baz",
4666 },
4667 },
4668 flags: []string{
4669 "-advertise-alpn", "\x03foo\x03bar",
4670 },
4671 shouldFail: true,
4672 expectedError: ":INVALID_ALPN_PROTOCOL:",
4673 expectedLocalError: "remote error: illegal parameter",
4674 })
4675 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004676 testType: serverTest,
4677 name: "ALPNServer-" + ver.name,
4678 config: Config{
4679 MaxVersion: ver.version,
4680 NextProtos: []string{"foo", "bar", "baz"},
4681 },
4682 flags: []string{
4683 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4684 "-select-alpn", "foo",
4685 },
4686 expectedNextProto: "foo",
4687 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004688 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004689 })
4690 testCases = append(testCases, testCase{
4691 testType: serverTest,
4692 name: "ALPNServer-Decline-" + ver.name,
4693 config: Config{
4694 MaxVersion: ver.version,
4695 NextProtos: []string{"foo", "bar", "baz"},
4696 },
4697 flags: []string{"-decline-alpn"},
4698 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004699 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004700 })
4701
David Benjamin25fe85b2016-08-09 20:00:32 -04004702 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4703 // called once.
4704 testCases = append(testCases, testCase{
4705 testType: serverTest,
4706 name: "ALPNServer-Async-" + ver.name,
4707 config: Config{
4708 MaxVersion: ver.version,
4709 NextProtos: []string{"foo", "bar", "baz"},
4710 },
4711 flags: []string{
4712 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4713 "-select-alpn", "foo",
4714 "-async",
4715 },
4716 expectedNextProto: "foo",
4717 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004718 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004719 })
4720
David Benjamin97d17d92016-07-14 16:12:00 -04004721 var emptyString string
4722 testCases = append(testCases, testCase{
4723 testType: clientTest,
4724 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4725 config: Config{
4726 MaxVersion: ver.version,
4727 NextProtos: []string{""},
4728 Bugs: ProtocolBugs{
4729 // A server returning an empty ALPN protocol
4730 // should be rejected.
4731 ALPNProtocol: &emptyString,
4732 },
4733 },
4734 flags: []string{
4735 "-advertise-alpn", "\x03foo",
4736 },
4737 shouldFail: true,
4738 expectedError: ":PARSE_TLSEXT:",
4739 })
4740 testCases = append(testCases, testCase{
4741 testType: serverTest,
4742 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4743 config: Config{
4744 MaxVersion: ver.version,
4745 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004746 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004747 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004748 },
David Benjamin97d17d92016-07-14 16:12:00 -04004749 flags: []string{
4750 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004751 },
David Benjamin97d17d92016-07-14 16:12:00 -04004752 shouldFail: true,
4753 expectedError: ":PARSE_TLSEXT:",
4754 })
4755
4756 // Test NPN and the interaction with ALPN.
4757 if ver.version < VersionTLS13 {
4758 // Test that the server prefers ALPN over NPN.
4759 testCases = append(testCases, testCase{
4760 testType: serverTest,
4761 name: "ALPNServer-Preferred-" + ver.name,
4762 config: Config{
4763 MaxVersion: ver.version,
4764 NextProtos: []string{"foo", "bar", "baz"},
4765 },
4766 flags: []string{
4767 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4768 "-select-alpn", "foo",
4769 "-advertise-npn", "\x03foo\x03bar\x03baz",
4770 },
4771 expectedNextProto: "foo",
4772 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004773 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004774 })
4775 testCases = append(testCases, testCase{
4776 testType: serverTest,
4777 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4778 config: Config{
4779 MaxVersion: ver.version,
4780 NextProtos: []string{"foo", "bar", "baz"},
4781 Bugs: ProtocolBugs{
4782 SwapNPNAndALPN: true,
4783 },
4784 },
4785 flags: []string{
4786 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4787 "-select-alpn", "foo",
4788 "-advertise-npn", "\x03foo\x03bar\x03baz",
4789 },
4790 expectedNextProto: "foo",
4791 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004792 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004793 })
4794
4795 // Test that negotiating both NPN and ALPN is forbidden.
4796 testCases = append(testCases, testCase{
4797 name: "NegotiateALPNAndNPN-" + ver.name,
4798 config: Config{
4799 MaxVersion: ver.version,
4800 NextProtos: []string{"foo", "bar", "baz"},
4801 Bugs: ProtocolBugs{
4802 NegotiateALPNAndNPN: true,
4803 },
4804 },
4805 flags: []string{
4806 "-advertise-alpn", "\x03foo",
4807 "-select-next-proto", "foo",
4808 },
4809 shouldFail: true,
4810 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4811 })
4812 testCases = append(testCases, testCase{
4813 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4814 config: Config{
4815 MaxVersion: ver.version,
4816 NextProtos: []string{"foo", "bar", "baz"},
4817 Bugs: ProtocolBugs{
4818 NegotiateALPNAndNPN: true,
4819 SwapNPNAndALPN: true,
4820 },
4821 },
4822 flags: []string{
4823 "-advertise-alpn", "\x03foo",
4824 "-select-next-proto", "foo",
4825 },
4826 shouldFail: true,
4827 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4828 })
4829
4830 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4831 testCases = append(testCases, testCase{
4832 name: "DisableNPN-" + ver.name,
4833 config: Config{
4834 MaxVersion: ver.version,
4835 NextProtos: []string{"foo"},
4836 },
4837 flags: []string{
4838 "-select-next-proto", "foo",
4839 "-disable-npn",
4840 },
4841 expectNoNextProto: true,
4842 })
4843 }
4844
4845 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004846
4847 // Resume with a corrupt ticket.
4848 testCases = append(testCases, testCase{
4849 testType: serverTest,
4850 name: "CorruptTicket-" + ver.name,
4851 config: Config{
4852 MaxVersion: ver.version,
4853 Bugs: ProtocolBugs{
4854 CorruptTicket: true,
4855 },
4856 },
4857 resumeSession: true,
4858 expectResumeRejected: true,
4859 })
4860 // Test the ticket callback, with and without renewal.
4861 testCases = append(testCases, testCase{
4862 testType: serverTest,
4863 name: "TicketCallback-" + ver.name,
4864 config: Config{
4865 MaxVersion: ver.version,
4866 },
4867 resumeSession: true,
4868 flags: []string{"-use-ticket-callback"},
4869 })
4870 testCases = append(testCases, testCase{
4871 testType: serverTest,
4872 name: "TicketCallback-Renew-" + ver.name,
4873 config: Config{
4874 MaxVersion: ver.version,
4875 Bugs: ProtocolBugs{
4876 ExpectNewTicket: true,
4877 },
4878 },
4879 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4880 resumeSession: true,
4881 })
4882
4883 // Test that the ticket callback is only called once when everything before
4884 // it in the ClientHello is asynchronous. This corrupts the ticket so
4885 // certificate selection callbacks run.
4886 testCases = append(testCases, testCase{
4887 testType: serverTest,
4888 name: "TicketCallback-SingleCall-" + ver.name,
4889 config: Config{
4890 MaxVersion: ver.version,
4891 Bugs: ProtocolBugs{
4892 CorruptTicket: true,
4893 },
4894 },
4895 resumeSession: true,
4896 expectResumeRejected: true,
4897 flags: []string{
4898 "-use-ticket-callback",
4899 "-async",
4900 },
4901 })
4902
4903 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004904 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004905 testCases = append(testCases, testCase{
4906 testType: serverTest,
4907 name: "OversizedSessionId-" + ver.name,
4908 config: Config{
4909 MaxVersion: ver.version,
4910 Bugs: ProtocolBugs{
4911 OversizedSessionId: true,
4912 },
4913 },
4914 resumeSession: true,
4915 shouldFail: true,
4916 expectedError: ":DECODE_ERROR:",
4917 })
4918 }
4919
4920 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4921 // are ignored.
4922 if ver.hasDTLS {
4923 testCases = append(testCases, testCase{
4924 protocol: dtls,
4925 name: "SRTP-Client-" + ver.name,
4926 config: Config{
4927 MaxVersion: ver.version,
4928 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4929 },
4930 flags: []string{
4931 "-srtp-profiles",
4932 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4933 },
4934 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4935 })
4936 testCases = append(testCases, testCase{
4937 protocol: dtls,
4938 testType: serverTest,
4939 name: "SRTP-Server-" + ver.name,
4940 config: Config{
4941 MaxVersion: ver.version,
4942 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4943 },
4944 flags: []string{
4945 "-srtp-profiles",
4946 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4947 },
4948 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4949 })
4950 // Test that the MKI is ignored.
4951 testCases = append(testCases, testCase{
4952 protocol: dtls,
4953 testType: serverTest,
4954 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4955 config: Config{
4956 MaxVersion: ver.version,
4957 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4958 Bugs: ProtocolBugs{
4959 SRTPMasterKeyIdentifer: "bogus",
4960 },
4961 },
4962 flags: []string{
4963 "-srtp-profiles",
4964 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4965 },
4966 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4967 })
4968 // Test that SRTP isn't negotiated on the server if there were
4969 // no matching profiles.
4970 testCases = append(testCases, testCase{
4971 protocol: dtls,
4972 testType: serverTest,
4973 name: "SRTP-Server-NoMatch-" + ver.name,
4974 config: Config{
4975 MaxVersion: ver.version,
4976 SRTPProtectionProfiles: []uint16{100, 101, 102},
4977 },
4978 flags: []string{
4979 "-srtp-profiles",
4980 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4981 },
4982 expectedSRTPProtectionProfile: 0,
4983 })
4984 // Test that the server returning an invalid SRTP profile is
4985 // flagged as an error by the client.
4986 testCases = append(testCases, testCase{
4987 protocol: dtls,
4988 name: "SRTP-Client-NoMatch-" + ver.name,
4989 config: Config{
4990 MaxVersion: ver.version,
4991 Bugs: ProtocolBugs{
4992 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4993 },
4994 },
4995 flags: []string{
4996 "-srtp-profiles",
4997 "SRTP_AES128_CM_SHA1_80",
4998 },
4999 shouldFail: true,
5000 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5001 })
5002 }
5003
5004 // Test SCT list.
5005 testCases = append(testCases, testCase{
5006 name: "SignedCertificateTimestampList-Client-" + ver.name,
5007 testType: clientTest,
5008 config: Config{
5009 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005010 },
David Benjamin97d17d92016-07-14 16:12:00 -04005011 flags: []string{
5012 "-enable-signed-cert-timestamps",
5013 "-expect-signed-cert-timestamps",
5014 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005015 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005016 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005017 })
David Benjamindaa88502016-10-04 16:32:16 -04005018
5019 // The SCT extension did not specify that it must only be sent on resumption as it
5020 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005021 testCases = append(testCases, testCase{
5022 name: "SendSCTListOnResume-" + ver.name,
5023 config: Config{
5024 MaxVersion: ver.version,
5025 Bugs: ProtocolBugs{
5026 SendSCTListOnResume: []byte("bogus"),
5027 },
David Benjamind98452d2015-06-16 14:16:23 -04005028 },
David Benjamin97d17d92016-07-14 16:12:00 -04005029 flags: []string{
5030 "-enable-signed-cert-timestamps",
5031 "-expect-signed-cert-timestamps",
5032 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005033 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005034 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005035 })
David Benjamindaa88502016-10-04 16:32:16 -04005036
David Benjamin97d17d92016-07-14 16:12:00 -04005037 testCases = append(testCases, testCase{
5038 name: "SignedCertificateTimestampList-Server-" + ver.name,
5039 testType: serverTest,
5040 config: Config{
5041 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005042 },
David Benjamin97d17d92016-07-14 16:12:00 -04005043 flags: []string{
5044 "-signed-cert-timestamps",
5045 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005046 },
David Benjamin97d17d92016-07-14 16:12:00 -04005047 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005048 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005049 })
5050 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005051
Paul Lietar4fac72e2015-09-09 13:44:55 +01005052 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005053 testType: clientTest,
5054 name: "ClientHelloPadding",
5055 config: Config{
5056 Bugs: ProtocolBugs{
5057 RequireClientHelloSize: 512,
5058 },
5059 },
5060 // This hostname just needs to be long enough to push the
5061 // ClientHello into F5's danger zone between 256 and 511 bytes
5062 // long.
5063 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5064 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005065
5066 // Extensions should not function in SSL 3.0.
5067 testCases = append(testCases, testCase{
5068 testType: serverTest,
5069 name: "SSLv3Extensions-NoALPN",
5070 config: Config{
5071 MaxVersion: VersionSSL30,
5072 NextProtos: []string{"foo", "bar", "baz"},
5073 },
5074 flags: []string{
5075 "-select-alpn", "foo",
5076 },
5077 expectNoNextProto: true,
5078 })
5079
5080 // Test session tickets separately as they follow a different codepath.
5081 testCases = append(testCases, testCase{
5082 testType: serverTest,
5083 name: "SSLv3Extensions-NoTickets",
5084 config: Config{
5085 MaxVersion: VersionSSL30,
5086 Bugs: ProtocolBugs{
5087 // Historically, session tickets in SSL 3.0
5088 // failed in different ways depending on whether
5089 // the client supported renegotiation_info.
5090 NoRenegotiationInfo: true,
5091 },
5092 },
5093 resumeSession: true,
5094 })
5095 testCases = append(testCases, testCase{
5096 testType: serverTest,
5097 name: "SSLv3Extensions-NoTickets2",
5098 config: Config{
5099 MaxVersion: VersionSSL30,
5100 },
5101 resumeSession: true,
5102 })
5103
5104 // But SSL 3.0 does send and process renegotiation_info.
5105 testCases = append(testCases, testCase{
5106 testType: serverTest,
5107 name: "SSLv3Extensions-RenegotiationInfo",
5108 config: Config{
5109 MaxVersion: VersionSSL30,
5110 Bugs: ProtocolBugs{
5111 RequireRenegotiationInfo: true,
5112 },
5113 },
5114 })
5115 testCases = append(testCases, testCase{
5116 testType: serverTest,
5117 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5118 config: Config{
5119 MaxVersion: VersionSSL30,
5120 Bugs: ProtocolBugs{
5121 NoRenegotiationInfo: true,
5122 SendRenegotiationSCSV: true,
5123 RequireRenegotiationInfo: true,
5124 },
5125 },
5126 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005127
5128 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5129 // in ServerHello.
5130 testCases = append(testCases, testCase{
5131 name: "NPN-Forbidden-TLS13",
5132 config: Config{
5133 MaxVersion: VersionTLS13,
5134 NextProtos: []string{"foo"},
5135 Bugs: ProtocolBugs{
5136 NegotiateNPNAtAllVersions: true,
5137 },
5138 },
5139 flags: []string{"-select-next-proto", "foo"},
5140 shouldFail: true,
5141 expectedError: ":ERROR_PARSING_EXTENSION:",
5142 })
5143 testCases = append(testCases, testCase{
5144 name: "EMS-Forbidden-TLS13",
5145 config: Config{
5146 MaxVersion: VersionTLS13,
5147 Bugs: ProtocolBugs{
5148 NegotiateEMSAtAllVersions: true,
5149 },
5150 },
5151 shouldFail: true,
5152 expectedError: ":ERROR_PARSING_EXTENSION:",
5153 })
5154 testCases = append(testCases, testCase{
5155 name: "RenegotiationInfo-Forbidden-TLS13",
5156 config: Config{
5157 MaxVersion: VersionTLS13,
5158 Bugs: ProtocolBugs{
5159 NegotiateRenegotiationInfoAtAllVersions: true,
5160 },
5161 },
5162 shouldFail: true,
5163 expectedError: ":ERROR_PARSING_EXTENSION:",
5164 })
5165 testCases = append(testCases, testCase{
5166 name: "ChannelID-Forbidden-TLS13",
5167 config: Config{
5168 MaxVersion: VersionTLS13,
5169 RequestChannelID: true,
5170 Bugs: ProtocolBugs{
5171 NegotiateChannelIDAtAllVersions: true,
5172 },
5173 },
5174 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5175 shouldFail: true,
5176 expectedError: ":ERROR_PARSING_EXTENSION:",
5177 })
5178 testCases = append(testCases, testCase{
5179 name: "Ticket-Forbidden-TLS13",
5180 config: Config{
5181 MaxVersion: VersionTLS12,
5182 },
5183 resumeConfig: &Config{
5184 MaxVersion: VersionTLS13,
5185 Bugs: ProtocolBugs{
5186 AdvertiseTicketExtension: true,
5187 },
5188 },
5189 resumeSession: true,
5190 shouldFail: true,
5191 expectedError: ":ERROR_PARSING_EXTENSION:",
5192 })
5193
5194 // Test that illegal extensions in TLS 1.3 are declined by the server if
5195 // offered in ClientHello. The runner's server will fail if this occurs,
5196 // so we exercise the offering path. (EMS and Renegotiation Info are
5197 // implicit in every test.)
5198 testCases = append(testCases, testCase{
5199 testType: serverTest,
5200 name: "ChannelID-Declined-TLS13",
5201 config: Config{
5202 MaxVersion: VersionTLS13,
5203 ChannelID: channelIDKey,
5204 },
5205 flags: []string{"-enable-channel-id"},
5206 })
5207 testCases = append(testCases, testCase{
5208 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005209 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005210 config: Config{
5211 MaxVersion: VersionTLS13,
5212 NextProtos: []string{"bar"},
5213 },
5214 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5215 })
David Benjamin196df5b2016-09-21 16:23:27 -04005216
5217 testCases = append(testCases, testCase{
5218 testType: serverTest,
5219 name: "InvalidChannelIDSignature",
5220 config: Config{
5221 MaxVersion: VersionTLS12,
5222 ChannelID: channelIDKey,
5223 Bugs: ProtocolBugs{
5224 InvalidChannelIDSignature: true,
5225 },
5226 },
5227 flags: []string{"-enable-channel-id"},
5228 shouldFail: true,
5229 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5230 expectedLocalError: "remote error: error decrypting message",
5231 })
David Benjamindaa88502016-10-04 16:32:16 -04005232
5233 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5234 // tolerated.
5235 testCases = append(testCases, testCase{
5236 name: "SendOCSPResponseOnResume-TLS12",
5237 config: Config{
5238 MaxVersion: VersionTLS12,
5239 Bugs: ProtocolBugs{
5240 SendOCSPResponseOnResume: []byte("bogus"),
5241 },
5242 },
5243 flags: []string{
5244 "-enable-ocsp-stapling",
5245 "-expect-ocsp-response",
5246 base64.StdEncoding.EncodeToString(testOCSPResponse),
5247 },
5248 resumeSession: true,
5249 })
5250
5251 // Beginning TLS 1.3, enforce this does not happen.
5252 testCases = append(testCases, testCase{
5253 name: "SendOCSPResponseOnResume-TLS13",
5254 config: Config{
5255 MaxVersion: VersionTLS13,
5256 Bugs: ProtocolBugs{
5257 SendOCSPResponseOnResume: []byte("bogus"),
5258 },
5259 },
5260 flags: []string{
5261 "-enable-ocsp-stapling",
5262 "-expect-ocsp-response",
5263 base64.StdEncoding.EncodeToString(testOCSPResponse),
5264 },
5265 resumeSession: true,
5266 shouldFail: true,
5267 expectedError: ":ERROR_PARSING_EXTENSION:",
5268 })
David Benjamine78bfde2014-09-06 12:45:15 -04005269}
5270
David Benjamin01fe8202014-09-24 15:21:44 -04005271func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005272 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005273 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005274 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5275 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5276 // TLS 1.3 only shares ciphers with TLS 1.2, so
5277 // we skip certain combinations and use a
5278 // different cipher to test with.
5279 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5280 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5281 continue
5282 }
5283 }
5284
David Benjamin8b8c0062014-11-23 02:47:52 -05005285 protocols := []protocol{tls}
5286 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5287 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005288 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005289 for _, protocol := range protocols {
5290 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5291 if protocol == dtls {
5292 suffix += "-DTLS"
5293 }
5294
David Benjaminece3de92015-03-16 18:02:20 -04005295 if sessionVers.version == resumeVers.version {
5296 testCases = append(testCases, testCase{
5297 protocol: protocol,
5298 name: "Resume-Client" + suffix,
5299 resumeSession: true,
5300 config: Config{
5301 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005302 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005303 Bugs: ProtocolBugs{
5304 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5305 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5306 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005307 },
David Benjaminece3de92015-03-16 18:02:20 -04005308 expectedVersion: sessionVers.version,
5309 expectedResumeVersion: resumeVers.version,
5310 })
5311 } else {
David Benjamin405da482016-08-08 17:25:07 -04005312 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5313
5314 // Offering a TLS 1.3 session sends an empty session ID, so
5315 // there is no way to convince a non-lookahead client the
5316 // session was resumed. It will appear to the client that a
5317 // stray ChangeCipherSpec was sent.
5318 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5319 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005320 }
5321
David Benjaminece3de92015-03-16 18:02:20 -04005322 testCases = append(testCases, testCase{
5323 protocol: protocol,
5324 name: "Resume-Client-Mismatch" + suffix,
5325 resumeSession: true,
5326 config: Config{
5327 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005328 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005329 },
David Benjaminece3de92015-03-16 18:02:20 -04005330 expectedVersion: sessionVers.version,
5331 resumeConfig: &Config{
5332 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005333 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005334 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005335 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005336 },
5337 },
5338 expectedResumeVersion: resumeVers.version,
5339 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005340 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005341 })
5342 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005343
5344 testCases = append(testCases, testCase{
5345 protocol: protocol,
5346 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005347 resumeSession: true,
5348 config: Config{
5349 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005350 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005351 },
5352 expectedVersion: sessionVers.version,
5353 resumeConfig: &Config{
5354 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005355 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005356 },
5357 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005358 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005359 expectedResumeVersion: resumeVers.version,
5360 })
5361
David Benjamin8b8c0062014-11-23 02:47:52 -05005362 testCases = append(testCases, testCase{
5363 protocol: protocol,
5364 testType: serverTest,
5365 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005366 resumeSession: true,
5367 config: Config{
5368 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005369 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005370 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005371 expectedVersion: sessionVers.version,
5372 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005373 resumeConfig: &Config{
5374 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005375 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005376 Bugs: ProtocolBugs{
5377 SendBothTickets: true,
5378 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005379 },
5380 expectedResumeVersion: resumeVers.version,
5381 })
5382 }
David Benjamin01fe8202014-09-24 15:21:44 -04005383 }
5384 }
David Benjaminece3de92015-03-16 18:02:20 -04005385
5386 testCases = append(testCases, testCase{
5387 name: "Resume-Client-CipherMismatch",
5388 resumeSession: true,
5389 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005390 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005391 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5392 },
5393 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005394 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005395 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5396 Bugs: ProtocolBugs{
5397 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5398 },
5399 },
5400 shouldFail: true,
5401 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5402 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005403
5404 testCases = append(testCases, testCase{
5405 name: "Resume-Client-CipherMismatch-TLS13",
5406 resumeSession: true,
5407 config: Config{
5408 MaxVersion: VersionTLS13,
5409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5410 },
5411 resumeConfig: &Config{
5412 MaxVersion: VersionTLS13,
5413 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5414 Bugs: ProtocolBugs{
5415 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5416 },
5417 },
5418 shouldFail: true,
5419 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5420 })
David Benjamin01fe8202014-09-24 15:21:44 -04005421}
5422
Adam Langley2ae77d22014-10-28 17:29:33 -07005423func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005424 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005425 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005426 testType: serverTest,
5427 name: "Renegotiate-Server-Forbidden",
5428 config: Config{
5429 MaxVersion: VersionTLS12,
5430 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005431 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005432 shouldFail: true,
5433 expectedError: ":NO_RENEGOTIATION:",
5434 expectedLocalError: "remote error: no renegotiation",
5435 })
Adam Langley5021b222015-06-12 18:27:58 -07005436 // The server shouldn't echo the renegotiation extension unless
5437 // requested by the client.
5438 testCases = append(testCases, testCase{
5439 testType: serverTest,
5440 name: "Renegotiate-Server-NoExt",
5441 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005442 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005443 Bugs: ProtocolBugs{
5444 NoRenegotiationInfo: true,
5445 RequireRenegotiationInfo: true,
5446 },
5447 },
5448 shouldFail: true,
5449 expectedLocalError: "renegotiation extension missing",
5450 })
5451 // The renegotiation SCSV should be sufficient for the server to echo
5452 // the extension.
5453 testCases = append(testCases, testCase{
5454 testType: serverTest,
5455 name: "Renegotiate-Server-NoExt-SCSV",
5456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005457 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005458 Bugs: ProtocolBugs{
5459 NoRenegotiationInfo: true,
5460 SendRenegotiationSCSV: true,
5461 RequireRenegotiationInfo: true,
5462 },
5463 },
5464 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005465 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005466 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005467 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005468 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005469 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005470 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005471 },
5472 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005473 renegotiate: 1,
5474 flags: []string{
5475 "-renegotiate-freely",
5476 "-expect-total-renegotiations", "1",
5477 },
David Benjamincdea40c2015-03-19 14:09:43 -04005478 })
5479 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005480 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005481 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005482 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005483 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005484 Bugs: ProtocolBugs{
5485 EmptyRenegotiationInfo: true,
5486 },
5487 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005488 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005489 shouldFail: true,
5490 expectedError: ":RENEGOTIATION_MISMATCH:",
5491 })
5492 testCases = append(testCases, testCase{
5493 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005494 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005495 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005496 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005497 Bugs: ProtocolBugs{
5498 BadRenegotiationInfo: true,
5499 },
5500 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005501 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005502 shouldFail: true,
5503 expectedError: ":RENEGOTIATION_MISMATCH:",
5504 })
5505 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005506 name: "Renegotiate-Client-Downgrade",
5507 renegotiate: 1,
5508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005509 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005510 Bugs: ProtocolBugs{
5511 NoRenegotiationInfoAfterInitial: true,
5512 },
5513 },
5514 flags: []string{"-renegotiate-freely"},
5515 shouldFail: true,
5516 expectedError: ":RENEGOTIATION_MISMATCH:",
5517 })
5518 testCases = append(testCases, testCase{
5519 name: "Renegotiate-Client-Upgrade",
5520 renegotiate: 1,
5521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005522 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005523 Bugs: ProtocolBugs{
5524 NoRenegotiationInfoInInitial: true,
5525 },
5526 },
5527 flags: []string{"-renegotiate-freely"},
5528 shouldFail: true,
5529 expectedError: ":RENEGOTIATION_MISMATCH:",
5530 })
5531 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005532 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005533 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005535 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005536 Bugs: ProtocolBugs{
5537 NoRenegotiationInfo: true,
5538 },
5539 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005540 flags: []string{
5541 "-renegotiate-freely",
5542 "-expect-total-renegotiations", "1",
5543 },
David Benjamincff0b902015-05-15 23:09:47 -04005544 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005545
5546 // Test that the server may switch ciphers on renegotiation without
5547 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005548 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005549 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005550 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005551 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005552 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005553 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005554 },
5555 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005556 flags: []string{
5557 "-renegotiate-freely",
5558 "-expect-total-renegotiations", "1",
5559 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005560 })
5561 testCases = append(testCases, testCase{
5562 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005563 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005564 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005565 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005566 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5567 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005568 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005569 flags: []string{
5570 "-renegotiate-freely",
5571 "-expect-total-renegotiations", "1",
5572 },
David Benjaminb16346b2015-04-08 19:16:58 -04005573 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005574
5575 // Test that the server may not switch versions on renegotiation.
5576 testCases = append(testCases, testCase{
5577 name: "Renegotiate-Client-SwitchVersion",
5578 config: Config{
5579 MaxVersion: VersionTLS12,
5580 // Pick a cipher which exists at both versions.
5581 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5582 Bugs: ProtocolBugs{
5583 NegotiateVersionOnRenego: VersionTLS11,
5584 },
5585 },
5586 renegotiate: 1,
5587 flags: []string{
5588 "-renegotiate-freely",
5589 "-expect-total-renegotiations", "1",
5590 },
5591 shouldFail: true,
5592 expectedError: ":WRONG_SSL_VERSION:",
5593 })
5594
David Benjaminb16346b2015-04-08 19:16:58 -04005595 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005596 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005597 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005598 config: Config{
5599 MaxVersion: VersionTLS10,
5600 Bugs: ProtocolBugs{
5601 RequireSameRenegoClientVersion: true,
5602 },
5603 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005604 flags: []string{
5605 "-renegotiate-freely",
5606 "-expect-total-renegotiations", "1",
5607 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005608 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005609 testCases = append(testCases, testCase{
5610 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005611 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005612 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005613 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005614 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5615 NextProtos: []string{"foo"},
5616 },
5617 flags: []string{
5618 "-false-start",
5619 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005620 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005621 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005622 },
5623 shimWritesFirst: true,
5624 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005625
5626 // Client-side renegotiation controls.
5627 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005628 name: "Renegotiate-Client-Forbidden-1",
5629 config: Config{
5630 MaxVersion: VersionTLS12,
5631 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005632 renegotiate: 1,
5633 shouldFail: true,
5634 expectedError: ":NO_RENEGOTIATION:",
5635 expectedLocalError: "remote error: no renegotiation",
5636 })
5637 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005638 name: "Renegotiate-Client-Once-1",
5639 config: Config{
5640 MaxVersion: VersionTLS12,
5641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005642 renegotiate: 1,
5643 flags: []string{
5644 "-renegotiate-once",
5645 "-expect-total-renegotiations", "1",
5646 },
5647 })
5648 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005649 name: "Renegotiate-Client-Freely-1",
5650 config: Config{
5651 MaxVersion: VersionTLS12,
5652 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005653 renegotiate: 1,
5654 flags: []string{
5655 "-renegotiate-freely",
5656 "-expect-total-renegotiations", "1",
5657 },
5658 })
5659 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005660 name: "Renegotiate-Client-Once-2",
5661 config: Config{
5662 MaxVersion: VersionTLS12,
5663 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005664 renegotiate: 2,
5665 flags: []string{"-renegotiate-once"},
5666 shouldFail: true,
5667 expectedError: ":NO_RENEGOTIATION:",
5668 expectedLocalError: "remote error: no renegotiation",
5669 })
5670 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005671 name: "Renegotiate-Client-Freely-2",
5672 config: Config{
5673 MaxVersion: VersionTLS12,
5674 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005675 renegotiate: 2,
5676 flags: []string{
5677 "-renegotiate-freely",
5678 "-expect-total-renegotiations", "2",
5679 },
5680 })
Adam Langley27a0d082015-11-03 13:34:10 -08005681 testCases = append(testCases, testCase{
5682 name: "Renegotiate-Client-NoIgnore",
5683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005684 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005685 Bugs: ProtocolBugs{
5686 SendHelloRequestBeforeEveryAppDataRecord: true,
5687 },
5688 },
5689 shouldFail: true,
5690 expectedError: ":NO_RENEGOTIATION:",
5691 })
5692 testCases = append(testCases, testCase{
5693 name: "Renegotiate-Client-Ignore",
5694 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005695 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005696 Bugs: ProtocolBugs{
5697 SendHelloRequestBeforeEveryAppDataRecord: true,
5698 },
5699 },
5700 flags: []string{
5701 "-renegotiate-ignore",
5702 "-expect-total-renegotiations", "0",
5703 },
5704 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005705
David Benjamin397c8e62016-07-08 14:14:36 -07005706 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005707 testCases = append(testCases, testCase{
5708 name: "StrayHelloRequest",
5709 config: Config{
5710 MaxVersion: VersionTLS12,
5711 Bugs: ProtocolBugs{
5712 SendHelloRequestBeforeEveryHandshakeMessage: true,
5713 },
5714 },
5715 })
5716 testCases = append(testCases, testCase{
5717 name: "StrayHelloRequest-Packed",
5718 config: Config{
5719 MaxVersion: VersionTLS12,
5720 Bugs: ProtocolBugs{
5721 PackHandshakeFlight: true,
5722 SendHelloRequestBeforeEveryHandshakeMessage: true,
5723 },
5724 },
5725 })
5726
David Benjamin12d2c482016-07-24 10:56:51 -04005727 // Test renegotiation works if HelloRequest and server Finished come in
5728 // the same record.
5729 testCases = append(testCases, testCase{
5730 name: "Renegotiate-Client-Packed",
5731 config: Config{
5732 MaxVersion: VersionTLS12,
5733 Bugs: ProtocolBugs{
5734 PackHandshakeFlight: true,
5735 PackHelloRequestWithFinished: true,
5736 },
5737 },
5738 renegotiate: 1,
5739 flags: []string{
5740 "-renegotiate-freely",
5741 "-expect-total-renegotiations", "1",
5742 },
5743 })
5744
David Benjamin397c8e62016-07-08 14:14:36 -07005745 // Renegotiation is forbidden in TLS 1.3.
5746 testCases = append(testCases, testCase{
5747 name: "Renegotiate-Client-TLS13",
5748 config: Config{
5749 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005750 Bugs: ProtocolBugs{
5751 SendHelloRequestBeforeEveryAppDataRecord: true,
5752 },
David Benjamin397c8e62016-07-08 14:14:36 -07005753 },
David Benjamin397c8e62016-07-08 14:14:36 -07005754 flags: []string{
5755 "-renegotiate-freely",
5756 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005757 shouldFail: true,
5758 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005759 })
5760
5761 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5762 testCases = append(testCases, testCase{
5763 name: "StrayHelloRequest-TLS13",
5764 config: Config{
5765 MaxVersion: VersionTLS13,
5766 Bugs: ProtocolBugs{
5767 SendHelloRequestBeforeEveryHandshakeMessage: true,
5768 },
5769 },
5770 shouldFail: true,
5771 expectedError: ":UNEXPECTED_MESSAGE:",
5772 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005773}
5774
David Benjamin5e961c12014-11-07 01:48:35 -05005775func addDTLSReplayTests() {
5776 // Test that sequence number replays are detected.
5777 testCases = append(testCases, testCase{
5778 protocol: dtls,
5779 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005780 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005781 replayWrites: true,
5782 })
5783
David Benjamin8e6db492015-07-25 18:29:23 -04005784 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005785 // than the retransmit window.
5786 testCases = append(testCases, testCase{
5787 protocol: dtls,
5788 name: "DTLS-Replay-LargeGaps",
5789 config: Config{
5790 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005791 SequenceNumberMapping: func(in uint64) uint64 {
5792 return in * 127
5793 },
David Benjamin5e961c12014-11-07 01:48:35 -05005794 },
5795 },
David Benjamin8e6db492015-07-25 18:29:23 -04005796 messageCount: 200,
5797 replayWrites: true,
5798 })
5799
5800 // Test the incoming sequence number changing non-monotonically.
5801 testCases = append(testCases, testCase{
5802 protocol: dtls,
5803 name: "DTLS-Replay-NonMonotonic",
5804 config: Config{
5805 Bugs: ProtocolBugs{
5806 SequenceNumberMapping: func(in uint64) uint64 {
5807 return in ^ 31
5808 },
5809 },
5810 },
5811 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005812 replayWrites: true,
5813 })
5814}
5815
Nick Harper60edffd2016-06-21 15:19:24 -07005816var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005817 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005818 id signatureAlgorithm
5819 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005820}{
Nick Harper60edffd2016-06-21 15:19:24 -07005821 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5822 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5823 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5824 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005825 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005826 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5827 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5828 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005829 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5830 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5831 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005832 // Tests for key types prior to TLS 1.2.
5833 {"RSA", 0, testCertRSA},
5834 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005835}
5836
Nick Harper60edffd2016-06-21 15:19:24 -07005837const fakeSigAlg1 signatureAlgorithm = 0x2a01
5838const fakeSigAlg2 signatureAlgorithm = 0xff01
5839
5840func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005841 // Not all ciphers involve a signature. Advertise a list which gives all
5842 // versions a signing cipher.
5843 signingCiphers := []uint16{
5844 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5845 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5846 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5847 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5848 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5849 }
5850
David Benjaminca3d5452016-07-14 12:51:01 -04005851 var allAlgorithms []signatureAlgorithm
5852 for _, alg := range testSignatureAlgorithms {
5853 if alg.id != 0 {
5854 allAlgorithms = append(allAlgorithms, alg.id)
5855 }
5856 }
5857
Nick Harper60edffd2016-06-21 15:19:24 -07005858 // Make sure each signature algorithm works. Include some fake values in
5859 // the list and ensure they're ignored.
5860 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005861 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005862 if (ver.version < VersionTLS12) != (alg.id == 0) {
5863 continue
5864 }
5865
5866 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5867 // or remove it in C.
5868 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005869 continue
5870 }
Nick Harper60edffd2016-06-21 15:19:24 -07005871
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005872 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005873 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005874 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5875 shouldFail = true
5876 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005877 // RSA-PKCS1 does not exist in TLS 1.3.
5878 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5879 shouldFail = true
5880 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005881
5882 var signError, verifyError string
5883 if shouldFail {
5884 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5885 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005886 }
David Benjamin000800a2014-11-14 01:43:59 -05005887
David Benjamin1fb125c2016-07-08 18:52:12 -07005888 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005889
David Benjamin7a41d372016-07-09 11:21:54 -07005890 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005891 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005892 config: Config{
5893 MaxVersion: ver.version,
5894 ClientAuth: RequireAnyClientCert,
5895 VerifySignatureAlgorithms: []signatureAlgorithm{
5896 fakeSigAlg1,
5897 alg.id,
5898 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005899 },
David Benjamin7a41d372016-07-09 11:21:54 -07005900 },
5901 flags: []string{
5902 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5903 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5904 "-enable-all-curves",
5905 },
5906 shouldFail: shouldFail,
5907 expectedError: signError,
5908 expectedPeerSignatureAlgorithm: alg.id,
5909 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005910
David Benjamin7a41d372016-07-09 11:21:54 -07005911 testCases = append(testCases, testCase{
5912 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005913 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005914 config: Config{
5915 MaxVersion: ver.version,
5916 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5917 SignSignatureAlgorithms: []signatureAlgorithm{
5918 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005919 },
David Benjamin7a41d372016-07-09 11:21:54 -07005920 Bugs: ProtocolBugs{
5921 SkipECDSACurveCheck: shouldFail,
5922 IgnoreSignatureVersionChecks: shouldFail,
5923 // The client won't advertise 1.3-only algorithms after
5924 // version negotiation.
5925 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005926 },
David Benjamin7a41d372016-07-09 11:21:54 -07005927 },
5928 flags: []string{
5929 "-require-any-client-certificate",
5930 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5931 "-enable-all-curves",
5932 },
5933 shouldFail: shouldFail,
5934 expectedError: verifyError,
5935 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005936
5937 testCases = append(testCases, testCase{
5938 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005939 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005940 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005941 MaxVersion: ver.version,
5942 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005943 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005944 fakeSigAlg1,
5945 alg.id,
5946 fakeSigAlg2,
5947 },
5948 },
5949 flags: []string{
5950 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5951 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5952 "-enable-all-curves",
5953 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005954 shouldFail: shouldFail,
5955 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005956 expectedPeerSignatureAlgorithm: alg.id,
5957 })
5958
5959 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005960 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005961 config: Config{
5962 MaxVersion: ver.version,
5963 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005964 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005965 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005966 alg.id,
5967 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005968 Bugs: ProtocolBugs{
5969 SkipECDSACurveCheck: shouldFail,
5970 IgnoreSignatureVersionChecks: shouldFail,
5971 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005972 },
5973 flags: []string{
5974 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5975 "-enable-all-curves",
5976 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005977 shouldFail: shouldFail,
5978 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005979 })
David Benjamin5208fd42016-07-13 21:43:25 -04005980
5981 if !shouldFail {
5982 testCases = append(testCases, testCase{
5983 testType: serverTest,
5984 name: "ClientAuth-InvalidSignature" + suffix,
5985 config: Config{
5986 MaxVersion: ver.version,
5987 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5988 SignSignatureAlgorithms: []signatureAlgorithm{
5989 alg.id,
5990 },
5991 Bugs: ProtocolBugs{
5992 InvalidSignature: true,
5993 },
5994 },
5995 flags: []string{
5996 "-require-any-client-certificate",
5997 "-enable-all-curves",
5998 },
5999 shouldFail: true,
6000 expectedError: ":BAD_SIGNATURE:",
6001 })
6002
6003 testCases = append(testCases, testCase{
6004 name: "ServerAuth-InvalidSignature" + suffix,
6005 config: Config{
6006 MaxVersion: ver.version,
6007 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6008 CipherSuites: signingCiphers,
6009 SignSignatureAlgorithms: []signatureAlgorithm{
6010 alg.id,
6011 },
6012 Bugs: ProtocolBugs{
6013 InvalidSignature: true,
6014 },
6015 },
6016 flags: []string{"-enable-all-curves"},
6017 shouldFail: true,
6018 expectedError: ":BAD_SIGNATURE:",
6019 })
6020 }
David Benjaminca3d5452016-07-14 12:51:01 -04006021
6022 if ver.version >= VersionTLS12 && !shouldFail {
6023 testCases = append(testCases, testCase{
6024 name: "ClientAuth-Sign-Negotiate" + suffix,
6025 config: Config{
6026 MaxVersion: ver.version,
6027 ClientAuth: RequireAnyClientCert,
6028 VerifySignatureAlgorithms: allAlgorithms,
6029 },
6030 flags: []string{
6031 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6032 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6033 "-enable-all-curves",
6034 "-signing-prefs", strconv.Itoa(int(alg.id)),
6035 },
6036 expectedPeerSignatureAlgorithm: alg.id,
6037 })
6038
6039 testCases = append(testCases, testCase{
6040 testType: serverTest,
6041 name: "ServerAuth-Sign-Negotiate" + suffix,
6042 config: Config{
6043 MaxVersion: ver.version,
6044 CipherSuites: signingCiphers,
6045 VerifySignatureAlgorithms: allAlgorithms,
6046 },
6047 flags: []string{
6048 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6049 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6050 "-enable-all-curves",
6051 "-signing-prefs", strconv.Itoa(int(alg.id)),
6052 },
6053 expectedPeerSignatureAlgorithm: alg.id,
6054 })
6055 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006056 }
David Benjamin000800a2014-11-14 01:43:59 -05006057 }
6058
Nick Harper60edffd2016-06-21 15:19:24 -07006059 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006060 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006061 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006062 config: Config{
6063 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006064 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006065 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006066 signatureECDSAWithP521AndSHA512,
6067 signatureRSAPKCS1WithSHA384,
6068 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006069 },
6070 },
6071 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006072 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6073 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006074 },
Nick Harper60edffd2016-06-21 15:19:24 -07006075 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006076 })
6077
6078 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006079 name: "ClientAuth-SignatureType-TLS13",
6080 config: Config{
6081 ClientAuth: RequireAnyClientCert,
6082 MaxVersion: VersionTLS13,
6083 VerifySignatureAlgorithms: []signatureAlgorithm{
6084 signatureECDSAWithP521AndSHA512,
6085 signatureRSAPKCS1WithSHA384,
6086 signatureRSAPSSWithSHA384,
6087 signatureECDSAWithSHA1,
6088 },
6089 },
6090 flags: []string{
6091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6093 },
6094 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6095 })
6096
6097 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006098 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006099 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006100 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006101 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006102 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006103 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006104 signatureECDSAWithP521AndSHA512,
6105 signatureRSAPKCS1WithSHA384,
6106 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006107 },
6108 },
Nick Harper60edffd2016-06-21 15:19:24 -07006109 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006110 })
6111
Steven Valdez143e8b32016-07-11 13:19:03 -04006112 testCases = append(testCases, testCase{
6113 testType: serverTest,
6114 name: "ServerAuth-SignatureType-TLS13",
6115 config: Config{
6116 MaxVersion: VersionTLS13,
6117 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6118 VerifySignatureAlgorithms: []signatureAlgorithm{
6119 signatureECDSAWithP521AndSHA512,
6120 signatureRSAPKCS1WithSHA384,
6121 signatureRSAPSSWithSHA384,
6122 signatureECDSAWithSHA1,
6123 },
6124 },
6125 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6126 })
6127
David Benjamina95e9f32016-07-08 16:28:04 -07006128 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006129 testCases = append(testCases, testCase{
6130 testType: serverTest,
6131 name: "Verify-ClientAuth-SignatureType",
6132 config: Config{
6133 MaxVersion: VersionTLS12,
6134 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006135 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006136 signatureRSAPKCS1WithSHA256,
6137 },
6138 Bugs: ProtocolBugs{
6139 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6140 },
6141 },
6142 flags: []string{
6143 "-require-any-client-certificate",
6144 },
6145 shouldFail: true,
6146 expectedError: ":WRONG_SIGNATURE_TYPE:",
6147 })
6148
6149 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006150 testType: serverTest,
6151 name: "Verify-ClientAuth-SignatureType-TLS13",
6152 config: Config{
6153 MaxVersion: VersionTLS13,
6154 Certificates: []Certificate{rsaCertificate},
6155 SignSignatureAlgorithms: []signatureAlgorithm{
6156 signatureRSAPSSWithSHA256,
6157 },
6158 Bugs: ProtocolBugs{
6159 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6160 },
6161 },
6162 flags: []string{
6163 "-require-any-client-certificate",
6164 },
6165 shouldFail: true,
6166 expectedError: ":WRONG_SIGNATURE_TYPE:",
6167 })
6168
6169 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006170 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006171 config: Config{
6172 MaxVersion: VersionTLS12,
6173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006174 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006175 signatureRSAPKCS1WithSHA256,
6176 },
6177 Bugs: ProtocolBugs{
6178 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6179 },
6180 },
6181 shouldFail: true,
6182 expectedError: ":WRONG_SIGNATURE_TYPE:",
6183 })
6184
Steven Valdez143e8b32016-07-11 13:19:03 -04006185 testCases = append(testCases, testCase{
6186 name: "Verify-ServerAuth-SignatureType-TLS13",
6187 config: Config{
6188 MaxVersion: VersionTLS13,
6189 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6190 SignSignatureAlgorithms: []signatureAlgorithm{
6191 signatureRSAPSSWithSHA256,
6192 },
6193 Bugs: ProtocolBugs{
6194 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6195 },
6196 },
6197 shouldFail: true,
6198 expectedError: ":WRONG_SIGNATURE_TYPE:",
6199 })
6200
David Benjamin51dd7d62016-07-08 16:07:01 -07006201 // Test that, if the list is missing, the peer falls back to SHA-1 in
6202 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006203 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006204 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006205 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006206 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006207 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006208 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006209 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006210 },
6211 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006212 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006213 },
6214 },
6215 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006216 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6217 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006218 },
6219 })
6220
6221 testCases = append(testCases, testCase{
6222 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006223 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006224 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006225 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006226 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006227 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006228 },
6229 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006230 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006231 },
6232 },
David Benjaminee32bea2016-08-17 13:36:44 -04006233 flags: []string{
6234 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6235 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6236 },
6237 })
6238
6239 testCases = append(testCases, testCase{
6240 name: "ClientAuth-SHA1-Fallback-ECDSA",
6241 config: Config{
6242 MaxVersion: VersionTLS12,
6243 ClientAuth: RequireAnyClientCert,
6244 VerifySignatureAlgorithms: []signatureAlgorithm{
6245 signatureECDSAWithSHA1,
6246 },
6247 Bugs: ProtocolBugs{
6248 NoSignatureAlgorithms: true,
6249 },
6250 },
6251 flags: []string{
6252 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6253 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6254 },
6255 })
6256
6257 testCases = append(testCases, testCase{
6258 testType: serverTest,
6259 name: "ServerAuth-SHA1-Fallback-ECDSA",
6260 config: Config{
6261 MaxVersion: VersionTLS12,
6262 VerifySignatureAlgorithms: []signatureAlgorithm{
6263 signatureECDSAWithSHA1,
6264 },
6265 Bugs: ProtocolBugs{
6266 NoSignatureAlgorithms: true,
6267 },
6268 },
6269 flags: []string{
6270 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6271 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6272 },
David Benjamin000800a2014-11-14 01:43:59 -05006273 })
David Benjamin72dc7832015-03-16 17:49:43 -04006274
David Benjamin51dd7d62016-07-08 16:07:01 -07006275 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006276 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006277 config: Config{
6278 MaxVersion: VersionTLS13,
6279 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006280 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006281 signatureRSAPKCS1WithSHA1,
6282 },
6283 Bugs: ProtocolBugs{
6284 NoSignatureAlgorithms: true,
6285 },
6286 },
6287 flags: []string{
6288 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6289 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6290 },
David Benjamin48901652016-08-01 12:12:47 -04006291 shouldFail: true,
6292 // An empty CertificateRequest signature algorithm list is a
6293 // syntax error in TLS 1.3.
6294 expectedError: ":DECODE_ERROR:",
6295 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006296 })
6297
6298 testCases = append(testCases, testCase{
6299 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006300 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006301 config: Config{
6302 MaxVersion: VersionTLS13,
6303 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006304 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006305 signatureRSAPKCS1WithSHA1,
6306 },
6307 Bugs: ProtocolBugs{
6308 NoSignatureAlgorithms: true,
6309 },
6310 },
6311 shouldFail: true,
6312 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6313 })
6314
David Benjaminb62d2872016-07-18 14:55:02 +02006315 // Test that hash preferences are enforced. BoringSSL does not implement
6316 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006317 testCases = append(testCases, testCase{
6318 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006319 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006321 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006322 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006323 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006324 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006325 },
6326 Bugs: ProtocolBugs{
6327 IgnorePeerSignatureAlgorithmPreferences: true,
6328 },
6329 },
6330 flags: []string{"-require-any-client-certificate"},
6331 shouldFail: true,
6332 expectedError: ":WRONG_SIGNATURE_TYPE:",
6333 })
6334
6335 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006336 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006338 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006340 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006341 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006342 },
6343 Bugs: ProtocolBugs{
6344 IgnorePeerSignatureAlgorithmPreferences: true,
6345 },
6346 },
6347 shouldFail: true,
6348 expectedError: ":WRONG_SIGNATURE_TYPE:",
6349 })
David Benjaminb62d2872016-07-18 14:55:02 +02006350 testCases = append(testCases, testCase{
6351 testType: serverTest,
6352 name: "ClientAuth-Enforced-TLS13",
6353 config: Config{
6354 MaxVersion: VersionTLS13,
6355 Certificates: []Certificate{rsaCertificate},
6356 SignSignatureAlgorithms: []signatureAlgorithm{
6357 signatureRSAPKCS1WithMD5,
6358 },
6359 Bugs: ProtocolBugs{
6360 IgnorePeerSignatureAlgorithmPreferences: true,
6361 IgnoreSignatureVersionChecks: true,
6362 },
6363 },
6364 flags: []string{"-require-any-client-certificate"},
6365 shouldFail: true,
6366 expectedError: ":WRONG_SIGNATURE_TYPE:",
6367 })
6368
6369 testCases = append(testCases, testCase{
6370 name: "ServerAuth-Enforced-TLS13",
6371 config: Config{
6372 MaxVersion: VersionTLS13,
6373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6374 SignSignatureAlgorithms: []signatureAlgorithm{
6375 signatureRSAPKCS1WithMD5,
6376 },
6377 Bugs: ProtocolBugs{
6378 IgnorePeerSignatureAlgorithmPreferences: true,
6379 IgnoreSignatureVersionChecks: true,
6380 },
6381 },
6382 shouldFail: true,
6383 expectedError: ":WRONG_SIGNATURE_TYPE:",
6384 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006385
6386 // Test that the agreed upon digest respects the client preferences and
6387 // the server digests.
6388 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006389 name: "NoCommonAlgorithms-Digests",
6390 config: Config{
6391 MaxVersion: VersionTLS12,
6392 ClientAuth: RequireAnyClientCert,
6393 VerifySignatureAlgorithms: []signatureAlgorithm{
6394 signatureRSAPKCS1WithSHA512,
6395 signatureRSAPKCS1WithSHA1,
6396 },
6397 },
6398 flags: []string{
6399 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6400 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6401 "-digest-prefs", "SHA256",
6402 },
6403 shouldFail: true,
6404 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6405 })
6406 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006407 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006408 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006409 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006410 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006411 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006412 signatureRSAPKCS1WithSHA512,
6413 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006414 },
6415 },
6416 flags: []string{
6417 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6418 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006419 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006420 },
David Benjaminca3d5452016-07-14 12:51:01 -04006421 shouldFail: true,
6422 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6423 })
6424 testCases = append(testCases, testCase{
6425 name: "NoCommonAlgorithms-TLS13",
6426 config: Config{
6427 MaxVersion: VersionTLS13,
6428 ClientAuth: RequireAnyClientCert,
6429 VerifySignatureAlgorithms: []signatureAlgorithm{
6430 signatureRSAPSSWithSHA512,
6431 signatureRSAPSSWithSHA384,
6432 },
6433 },
6434 flags: []string{
6435 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6436 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6437 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6438 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006439 shouldFail: true,
6440 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006441 })
6442 testCases = append(testCases, testCase{
6443 name: "Agree-Digest-SHA256",
6444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006445 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006446 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006447 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006448 signatureRSAPKCS1WithSHA1,
6449 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006450 },
6451 },
6452 flags: []string{
6453 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6454 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006455 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006456 },
Nick Harper60edffd2016-06-21 15:19:24 -07006457 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006458 })
6459 testCases = append(testCases, testCase{
6460 name: "Agree-Digest-SHA1",
6461 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006462 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006463 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006464 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006465 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006466 },
6467 },
6468 flags: []string{
6469 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6470 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006471 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006472 },
Nick Harper60edffd2016-06-21 15:19:24 -07006473 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006474 })
6475 testCases = append(testCases, testCase{
6476 name: "Agree-Digest-Default",
6477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006478 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006479 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006480 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006481 signatureRSAPKCS1WithSHA256,
6482 signatureECDSAWithP256AndSHA256,
6483 signatureRSAPKCS1WithSHA1,
6484 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006485 },
6486 },
6487 flags: []string{
6488 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6489 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6490 },
Nick Harper60edffd2016-06-21 15:19:24 -07006491 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006492 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006493
David Benjaminca3d5452016-07-14 12:51:01 -04006494 // Test that the signing preference list may include extra algorithms
6495 // without negotiation problems.
6496 testCases = append(testCases, testCase{
6497 testType: serverTest,
6498 name: "FilterExtraAlgorithms",
6499 config: Config{
6500 MaxVersion: VersionTLS12,
6501 VerifySignatureAlgorithms: []signatureAlgorithm{
6502 signatureRSAPKCS1WithSHA256,
6503 },
6504 },
6505 flags: []string{
6506 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6507 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6508 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6509 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6510 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6511 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6512 },
6513 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6514 })
6515
David Benjamin4c3ddf72016-06-29 18:13:53 -04006516 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6517 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006518 testCases = append(testCases, testCase{
6519 name: "CheckLeafCurve",
6520 config: Config{
6521 MaxVersion: VersionTLS12,
6522 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006523 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006524 },
6525 flags: []string{"-p384-only"},
6526 shouldFail: true,
6527 expectedError: ":BAD_ECC_CERT:",
6528 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006529
6530 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6531 testCases = append(testCases, testCase{
6532 name: "CheckLeafCurve-TLS13",
6533 config: Config{
6534 MaxVersion: VersionTLS13,
6535 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6536 Certificates: []Certificate{ecdsaP256Certificate},
6537 },
6538 flags: []string{"-p384-only"},
6539 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006540
6541 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6542 testCases = append(testCases, testCase{
6543 name: "ECDSACurveMismatch-Verify-TLS12",
6544 config: Config{
6545 MaxVersion: VersionTLS12,
6546 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6547 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006548 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006549 signatureECDSAWithP384AndSHA384,
6550 },
6551 },
6552 })
6553
6554 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6555 testCases = append(testCases, testCase{
6556 name: "ECDSACurveMismatch-Verify-TLS13",
6557 config: Config{
6558 MaxVersion: VersionTLS13,
6559 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6560 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006561 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006562 signatureECDSAWithP384AndSHA384,
6563 },
6564 Bugs: ProtocolBugs{
6565 SkipECDSACurveCheck: true,
6566 },
6567 },
6568 shouldFail: true,
6569 expectedError: ":WRONG_SIGNATURE_TYPE:",
6570 })
6571
6572 // Signature algorithm selection in TLS 1.3 should take the curve into
6573 // account.
6574 testCases = append(testCases, testCase{
6575 testType: serverTest,
6576 name: "ECDSACurveMismatch-Sign-TLS13",
6577 config: Config{
6578 MaxVersion: VersionTLS13,
6579 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006580 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006581 signatureECDSAWithP384AndSHA384,
6582 signatureECDSAWithP256AndSHA256,
6583 },
6584 },
6585 flags: []string{
6586 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6587 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6588 },
6589 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6590 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006591
6592 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6593 // server does not attempt to sign in that case.
6594 testCases = append(testCases, testCase{
6595 testType: serverTest,
6596 name: "RSA-PSS-Large",
6597 config: Config{
6598 MaxVersion: VersionTLS13,
6599 VerifySignatureAlgorithms: []signatureAlgorithm{
6600 signatureRSAPSSWithSHA512,
6601 },
6602 },
6603 flags: []string{
6604 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6605 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6606 },
6607 shouldFail: true,
6608 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6609 })
David Benjamin57e929f2016-08-30 00:30:38 -04006610
6611 // Test that RSA-PSS is enabled by default for TLS 1.2.
6612 testCases = append(testCases, testCase{
6613 testType: clientTest,
6614 name: "RSA-PSS-Default-Verify",
6615 config: Config{
6616 MaxVersion: VersionTLS12,
6617 SignSignatureAlgorithms: []signatureAlgorithm{
6618 signatureRSAPSSWithSHA256,
6619 },
6620 },
6621 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6622 })
6623
6624 testCases = append(testCases, testCase{
6625 testType: serverTest,
6626 name: "RSA-PSS-Default-Sign",
6627 config: Config{
6628 MaxVersion: VersionTLS12,
6629 VerifySignatureAlgorithms: []signatureAlgorithm{
6630 signatureRSAPSSWithSHA256,
6631 },
6632 },
6633 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6634 })
David Benjamin000800a2014-11-14 01:43:59 -05006635}
6636
David Benjamin83f90402015-01-27 01:09:43 -05006637// timeouts is the retransmit schedule for BoringSSL. It doubles and
6638// caps at 60 seconds. On the 13th timeout, it gives up.
6639var timeouts = []time.Duration{
6640 1 * time.Second,
6641 2 * time.Second,
6642 4 * time.Second,
6643 8 * time.Second,
6644 16 * time.Second,
6645 32 * time.Second,
6646 60 * time.Second,
6647 60 * time.Second,
6648 60 * time.Second,
6649 60 * time.Second,
6650 60 * time.Second,
6651 60 * time.Second,
6652 60 * time.Second,
6653}
6654
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006655// shortTimeouts is an alternate set of timeouts which would occur if the
6656// initial timeout duration was set to 250ms.
6657var shortTimeouts = []time.Duration{
6658 250 * time.Millisecond,
6659 500 * time.Millisecond,
6660 1 * time.Second,
6661 2 * time.Second,
6662 4 * time.Second,
6663 8 * time.Second,
6664 16 * time.Second,
6665 32 * time.Second,
6666 60 * time.Second,
6667 60 * time.Second,
6668 60 * time.Second,
6669 60 * time.Second,
6670 60 * time.Second,
6671}
6672
David Benjamin83f90402015-01-27 01:09:43 -05006673func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006674 // These tests work by coordinating some behavior on both the shim and
6675 // the runner.
6676 //
6677 // TimeoutSchedule configures the runner to send a series of timeout
6678 // opcodes to the shim (see packetAdaptor) immediately before reading
6679 // each peer handshake flight N. The timeout opcode both simulates a
6680 // timeout in the shim and acts as a synchronization point to help the
6681 // runner bracket each handshake flight.
6682 //
6683 // We assume the shim does not read from the channel eagerly. It must
6684 // first wait until it has sent flight N and is ready to receive
6685 // handshake flight N+1. At this point, it will process the timeout
6686 // opcode. It must then immediately respond with a timeout ACK and act
6687 // as if the shim was idle for the specified amount of time.
6688 //
6689 // The runner then drops all packets received before the ACK and
6690 // continues waiting for flight N. This ordering results in one attempt
6691 // at sending flight N to be dropped. For the test to complete, the
6692 // shim must send flight N again, testing that the shim implements DTLS
6693 // retransmit on a timeout.
6694
Steven Valdez143e8b32016-07-11 13:19:03 -04006695 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006696 // likely be more epochs to cross and the final message's retransmit may
6697 // be more complex.
6698
David Benjamin585d7a42016-06-02 14:58:00 -04006699 for _, async := range []bool{true, false} {
6700 var tests []testCase
6701
6702 // Test that this is indeed the timeout schedule. Stress all
6703 // four patterns of handshake.
6704 for i := 1; i < len(timeouts); i++ {
6705 number := strconv.Itoa(i)
6706 tests = append(tests, testCase{
6707 protocol: dtls,
6708 name: "DTLS-Retransmit-Client-" + number,
6709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006710 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006711 Bugs: ProtocolBugs{
6712 TimeoutSchedule: timeouts[:i],
6713 },
6714 },
6715 resumeSession: true,
6716 })
6717 tests = append(tests, testCase{
6718 protocol: dtls,
6719 testType: serverTest,
6720 name: "DTLS-Retransmit-Server-" + number,
6721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006722 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006723 Bugs: ProtocolBugs{
6724 TimeoutSchedule: timeouts[:i],
6725 },
6726 },
6727 resumeSession: true,
6728 })
6729 }
6730
6731 // Test that exceeding the timeout schedule hits a read
6732 // timeout.
6733 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006734 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006735 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006736 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006737 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006738 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006739 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006740 },
6741 },
6742 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006743 shouldFail: true,
6744 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006745 })
David Benjamin585d7a42016-06-02 14:58:00 -04006746
6747 if async {
6748 // Test that timeout handling has a fudge factor, due to API
6749 // problems.
6750 tests = append(tests, testCase{
6751 protocol: dtls,
6752 name: "DTLS-Retransmit-Fudge",
6753 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006754 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006755 Bugs: ProtocolBugs{
6756 TimeoutSchedule: []time.Duration{
6757 timeouts[0] - 10*time.Millisecond,
6758 },
6759 },
6760 },
6761 resumeSession: true,
6762 })
6763 }
6764
6765 // Test that the final Finished retransmitting isn't
6766 // duplicated if the peer badly fragments everything.
6767 tests = append(tests, testCase{
6768 testType: serverTest,
6769 protocol: dtls,
6770 name: "DTLS-Retransmit-Fragmented",
6771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006772 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006773 Bugs: ProtocolBugs{
6774 TimeoutSchedule: []time.Duration{timeouts[0]},
6775 MaxHandshakeRecordLength: 2,
6776 },
6777 },
6778 })
6779
6780 // Test the timeout schedule when a shorter initial timeout duration is set.
6781 tests = append(tests, testCase{
6782 protocol: dtls,
6783 name: "DTLS-Retransmit-Short-Client",
6784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006785 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006786 Bugs: ProtocolBugs{
6787 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6788 },
6789 },
6790 resumeSession: true,
6791 flags: []string{"-initial-timeout-duration-ms", "250"},
6792 })
6793 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006794 protocol: dtls,
6795 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006796 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006798 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006799 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006800 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006801 },
6802 },
6803 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006804 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006805 })
David Benjamin585d7a42016-06-02 14:58:00 -04006806
6807 for _, test := range tests {
6808 if async {
6809 test.name += "-Async"
6810 test.flags = append(test.flags, "-async")
6811 }
6812
6813 testCases = append(testCases, test)
6814 }
David Benjamin83f90402015-01-27 01:09:43 -05006815 }
David Benjamin83f90402015-01-27 01:09:43 -05006816}
6817
David Benjaminc565ebb2015-04-03 04:06:36 -04006818func addExportKeyingMaterialTests() {
6819 for _, vers := range tlsVersions {
6820 if vers.version == VersionSSL30 {
6821 continue
6822 }
6823 testCases = append(testCases, testCase{
6824 name: "ExportKeyingMaterial-" + vers.name,
6825 config: Config{
6826 MaxVersion: vers.version,
6827 },
6828 exportKeyingMaterial: 1024,
6829 exportLabel: "label",
6830 exportContext: "context",
6831 useExportContext: true,
6832 })
6833 testCases = append(testCases, testCase{
6834 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6835 config: Config{
6836 MaxVersion: vers.version,
6837 },
6838 exportKeyingMaterial: 1024,
6839 })
6840 testCases = append(testCases, testCase{
6841 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6842 config: Config{
6843 MaxVersion: vers.version,
6844 },
6845 exportKeyingMaterial: 1024,
6846 useExportContext: true,
6847 })
6848 testCases = append(testCases, testCase{
6849 name: "ExportKeyingMaterial-Small-" + vers.name,
6850 config: Config{
6851 MaxVersion: vers.version,
6852 },
6853 exportKeyingMaterial: 1,
6854 exportLabel: "label",
6855 exportContext: "context",
6856 useExportContext: true,
6857 })
6858 }
6859 testCases = append(testCases, testCase{
6860 name: "ExportKeyingMaterial-SSL3",
6861 config: Config{
6862 MaxVersion: VersionSSL30,
6863 },
6864 exportKeyingMaterial: 1024,
6865 exportLabel: "label",
6866 exportContext: "context",
6867 useExportContext: true,
6868 shouldFail: true,
6869 expectedError: "failed to export keying material",
6870 })
6871}
6872
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006873func addTLSUniqueTests() {
6874 for _, isClient := range []bool{false, true} {
6875 for _, isResumption := range []bool{false, true} {
6876 for _, hasEMS := range []bool{false, true} {
6877 var suffix string
6878 if isResumption {
6879 suffix = "Resume-"
6880 } else {
6881 suffix = "Full-"
6882 }
6883
6884 if hasEMS {
6885 suffix += "EMS-"
6886 } else {
6887 suffix += "NoEMS-"
6888 }
6889
6890 if isClient {
6891 suffix += "Client"
6892 } else {
6893 suffix += "Server"
6894 }
6895
6896 test := testCase{
6897 name: "TLSUnique-" + suffix,
6898 testTLSUnique: true,
6899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006900 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006901 Bugs: ProtocolBugs{
6902 NoExtendedMasterSecret: !hasEMS,
6903 },
6904 },
6905 }
6906
6907 if isResumption {
6908 test.resumeSession = true
6909 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006910 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006911 Bugs: ProtocolBugs{
6912 NoExtendedMasterSecret: !hasEMS,
6913 },
6914 }
6915 }
6916
6917 if isResumption && !hasEMS {
6918 test.shouldFail = true
6919 test.expectedError = "failed to get tls-unique"
6920 }
6921
6922 testCases = append(testCases, test)
6923 }
6924 }
6925 }
6926}
6927
Adam Langley09505632015-07-30 18:10:13 -07006928func addCustomExtensionTests() {
6929 expectedContents := "custom extension"
6930 emptyString := ""
6931
6932 for _, isClient := range []bool{false, true} {
6933 suffix := "Server"
6934 flag := "-enable-server-custom-extension"
6935 testType := serverTest
6936 if isClient {
6937 suffix = "Client"
6938 flag = "-enable-client-custom-extension"
6939 testType = clientTest
6940 }
6941
6942 testCases = append(testCases, testCase{
6943 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006944 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006946 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006947 Bugs: ProtocolBugs{
6948 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006949 ExpectedCustomExtension: &expectedContents,
6950 },
6951 },
6952 flags: []string{flag},
6953 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006954 testCases = append(testCases, testCase{
6955 testType: testType,
6956 name: "CustomExtensions-" + suffix + "-TLS13",
6957 config: Config{
6958 MaxVersion: VersionTLS13,
6959 Bugs: ProtocolBugs{
6960 CustomExtension: expectedContents,
6961 ExpectedCustomExtension: &expectedContents,
6962 },
6963 },
6964 flags: []string{flag},
6965 })
Adam Langley09505632015-07-30 18:10:13 -07006966
6967 // If the parse callback fails, the handshake should also fail.
6968 testCases = append(testCases, testCase{
6969 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006970 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006972 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006973 Bugs: ProtocolBugs{
6974 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006975 ExpectedCustomExtension: &expectedContents,
6976 },
6977 },
David Benjamin399e7c92015-07-30 23:01:27 -04006978 flags: []string{flag},
6979 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006980 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6981 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006982 testCases = append(testCases, testCase{
6983 testType: testType,
6984 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6985 config: Config{
6986 MaxVersion: VersionTLS13,
6987 Bugs: ProtocolBugs{
6988 CustomExtension: expectedContents + "foo",
6989 ExpectedCustomExtension: &expectedContents,
6990 },
6991 },
6992 flags: []string{flag},
6993 shouldFail: true,
6994 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6995 })
Adam Langley09505632015-07-30 18:10:13 -07006996
6997 // If the add callback fails, the handshake should also fail.
6998 testCases = append(testCases, testCase{
6999 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007000 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007002 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007003 Bugs: ProtocolBugs{
7004 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007005 ExpectedCustomExtension: &expectedContents,
7006 },
7007 },
David Benjamin399e7c92015-07-30 23:01:27 -04007008 flags: []string{flag, "-custom-extension-fail-add"},
7009 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007010 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7011 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007012 testCases = append(testCases, testCase{
7013 testType: testType,
7014 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7015 config: Config{
7016 MaxVersion: VersionTLS13,
7017 Bugs: ProtocolBugs{
7018 CustomExtension: expectedContents,
7019 ExpectedCustomExtension: &expectedContents,
7020 },
7021 },
7022 flags: []string{flag, "-custom-extension-fail-add"},
7023 shouldFail: true,
7024 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7025 })
Adam Langley09505632015-07-30 18:10:13 -07007026
7027 // If the add callback returns zero, no extension should be
7028 // added.
7029 skipCustomExtension := expectedContents
7030 if isClient {
7031 // For the case where the client skips sending the
7032 // custom extension, the server must not “echo” it.
7033 skipCustomExtension = ""
7034 }
7035 testCases = append(testCases, testCase{
7036 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007037 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007038 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007039 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007040 Bugs: ProtocolBugs{
7041 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007042 ExpectedCustomExtension: &emptyString,
7043 },
7044 },
7045 flags: []string{flag, "-custom-extension-skip"},
7046 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007047 testCases = append(testCases, testCase{
7048 testType: testType,
7049 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7050 config: Config{
7051 MaxVersion: VersionTLS13,
7052 Bugs: ProtocolBugs{
7053 CustomExtension: skipCustomExtension,
7054 ExpectedCustomExtension: &emptyString,
7055 },
7056 },
7057 flags: []string{flag, "-custom-extension-skip"},
7058 })
Adam Langley09505632015-07-30 18:10:13 -07007059 }
7060
7061 // The custom extension add callback should not be called if the client
7062 // doesn't send the extension.
7063 testCases = append(testCases, testCase{
7064 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007065 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007067 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007068 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007069 ExpectedCustomExtension: &emptyString,
7070 },
7071 },
7072 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7073 })
Adam Langley2deb9842015-08-07 11:15:37 -07007074
Steven Valdez143e8b32016-07-11 13:19:03 -04007075 testCases = append(testCases, testCase{
7076 testType: serverTest,
7077 name: "CustomExtensions-NotCalled-Server-TLS13",
7078 config: Config{
7079 MaxVersion: VersionTLS13,
7080 Bugs: ProtocolBugs{
7081 ExpectedCustomExtension: &emptyString,
7082 },
7083 },
7084 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7085 })
7086
Adam Langley2deb9842015-08-07 11:15:37 -07007087 // Test an unknown extension from the server.
7088 testCases = append(testCases, testCase{
7089 testType: clientTest,
7090 name: "UnknownExtension-Client",
7091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007092 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007093 Bugs: ProtocolBugs{
7094 CustomExtension: expectedContents,
7095 },
7096 },
David Benjamin0c40a962016-08-01 12:05:50 -04007097 shouldFail: true,
7098 expectedError: ":UNEXPECTED_EXTENSION:",
7099 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007100 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007101 testCases = append(testCases, testCase{
7102 testType: clientTest,
7103 name: "UnknownExtension-Client-TLS13",
7104 config: Config{
7105 MaxVersion: VersionTLS13,
7106 Bugs: ProtocolBugs{
7107 CustomExtension: expectedContents,
7108 },
7109 },
David Benjamin0c40a962016-08-01 12:05:50 -04007110 shouldFail: true,
7111 expectedError: ":UNEXPECTED_EXTENSION:",
7112 expectedLocalError: "remote error: unsupported extension",
7113 })
7114
7115 // Test a known but unoffered extension from the server.
7116 testCases = append(testCases, testCase{
7117 testType: clientTest,
7118 name: "UnofferedExtension-Client",
7119 config: Config{
7120 MaxVersion: VersionTLS12,
7121 Bugs: ProtocolBugs{
7122 SendALPN: "alpn",
7123 },
7124 },
7125 shouldFail: true,
7126 expectedError: ":UNEXPECTED_EXTENSION:",
7127 expectedLocalError: "remote error: unsupported extension",
7128 })
7129 testCases = append(testCases, testCase{
7130 testType: clientTest,
7131 name: "UnofferedExtension-Client-TLS13",
7132 config: Config{
7133 MaxVersion: VersionTLS13,
7134 Bugs: ProtocolBugs{
7135 SendALPN: "alpn",
7136 },
7137 },
7138 shouldFail: true,
7139 expectedError: ":UNEXPECTED_EXTENSION:",
7140 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007141 })
Adam Langley09505632015-07-30 18:10:13 -07007142}
7143
David Benjaminb36a3952015-12-01 18:53:13 -05007144func addRSAClientKeyExchangeTests() {
7145 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7146 testCases = append(testCases, testCase{
7147 testType: serverTest,
7148 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7149 config: Config{
7150 // Ensure the ClientHello version and final
7151 // version are different, to detect if the
7152 // server uses the wrong one.
7153 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007154 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007155 Bugs: ProtocolBugs{
7156 BadRSAClientKeyExchange: bad,
7157 },
7158 },
7159 shouldFail: true,
7160 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7161 })
7162 }
David Benjamine63d9d72016-09-19 18:27:34 -04007163
7164 // The server must compare whatever was in ClientHello.version for the
7165 // RSA premaster.
7166 testCases = append(testCases, testCase{
7167 testType: serverTest,
7168 name: "SendClientVersion-RSA",
7169 config: Config{
7170 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7171 Bugs: ProtocolBugs{
7172 SendClientVersion: 0x1234,
7173 },
7174 },
7175 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7176 })
David Benjaminb36a3952015-12-01 18:53:13 -05007177}
7178
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007179var testCurves = []struct {
7180 name string
7181 id CurveID
7182}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007183 {"P-256", CurveP256},
7184 {"P-384", CurveP384},
7185 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007186 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007187}
7188
Steven Valdez5440fe02016-07-18 12:40:30 -04007189const bogusCurve = 0x1234
7190
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007191func addCurveTests() {
7192 for _, curve := range testCurves {
7193 testCases = append(testCases, testCase{
7194 name: "CurveTest-Client-" + curve.name,
7195 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007197 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7198 CurvePreferences: []CurveID{curve.id},
7199 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007200 flags: []string{
7201 "-enable-all-curves",
7202 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7203 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007204 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007205 })
7206 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007207 name: "CurveTest-Client-" + curve.name + "-TLS13",
7208 config: Config{
7209 MaxVersion: VersionTLS13,
7210 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7211 CurvePreferences: []CurveID{curve.id},
7212 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007213 flags: []string{
7214 "-enable-all-curves",
7215 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7216 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007217 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007218 })
7219 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007220 testType: serverTest,
7221 name: "CurveTest-Server-" + curve.name,
7222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007223 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007224 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7225 CurvePreferences: []CurveID{curve.id},
7226 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007227 flags: []string{
7228 "-enable-all-curves",
7229 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7230 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007231 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007232 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007233 testCases = append(testCases, testCase{
7234 testType: serverTest,
7235 name: "CurveTest-Server-" + curve.name + "-TLS13",
7236 config: Config{
7237 MaxVersion: VersionTLS13,
7238 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7239 CurvePreferences: []CurveID{curve.id},
7240 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007241 flags: []string{
7242 "-enable-all-curves",
7243 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7244 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007245 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007246 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007247 }
David Benjamin241ae832016-01-15 03:04:54 -05007248
7249 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007250 testCases = append(testCases, testCase{
7251 testType: serverTest,
7252 name: "UnknownCurve",
7253 config: Config{
7254 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7255 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7256 },
7257 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007258
7259 // The server must not consider ECDHE ciphers when there are no
7260 // supported curves.
7261 testCases = append(testCases, testCase{
7262 testType: serverTest,
7263 name: "NoSupportedCurves",
7264 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007265 MaxVersion: VersionTLS12,
7266 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7267 Bugs: ProtocolBugs{
7268 NoSupportedCurves: true,
7269 },
7270 },
7271 shouldFail: true,
7272 expectedError: ":NO_SHARED_CIPHER:",
7273 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007274 testCases = append(testCases, testCase{
7275 testType: serverTest,
7276 name: "NoSupportedCurves-TLS13",
7277 config: Config{
7278 MaxVersion: VersionTLS13,
7279 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7280 Bugs: ProtocolBugs{
7281 NoSupportedCurves: true,
7282 },
7283 },
7284 shouldFail: true,
7285 expectedError: ":NO_SHARED_CIPHER:",
7286 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007287
7288 // The server must fall back to another cipher when there are no
7289 // supported curves.
7290 testCases = append(testCases, testCase{
7291 testType: serverTest,
7292 name: "NoCommonCurves",
7293 config: Config{
7294 MaxVersion: VersionTLS12,
7295 CipherSuites: []uint16{
7296 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7297 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7298 },
7299 CurvePreferences: []CurveID{CurveP224},
7300 },
7301 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7302 })
7303
7304 // The client must reject bogus curves and disabled curves.
7305 testCases = append(testCases, testCase{
7306 name: "BadECDHECurve",
7307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007308 MaxVersion: VersionTLS12,
7309 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7310 Bugs: ProtocolBugs{
7311 SendCurve: bogusCurve,
7312 },
7313 },
7314 shouldFail: true,
7315 expectedError: ":WRONG_CURVE:",
7316 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007317 testCases = append(testCases, testCase{
7318 name: "BadECDHECurve-TLS13",
7319 config: Config{
7320 MaxVersion: VersionTLS13,
7321 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7322 Bugs: ProtocolBugs{
7323 SendCurve: bogusCurve,
7324 },
7325 },
7326 shouldFail: true,
7327 expectedError: ":WRONG_CURVE:",
7328 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007329
7330 testCases = append(testCases, testCase{
7331 name: "UnsupportedCurve",
7332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007333 MaxVersion: VersionTLS12,
7334 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7335 CurvePreferences: []CurveID{CurveP256},
7336 Bugs: ProtocolBugs{
7337 IgnorePeerCurvePreferences: true,
7338 },
7339 },
7340 flags: []string{"-p384-only"},
7341 shouldFail: true,
7342 expectedError: ":WRONG_CURVE:",
7343 })
7344
David Benjamin4f921572016-07-17 14:20:10 +02007345 testCases = append(testCases, testCase{
7346 // TODO(davidben): Add a TLS 1.3 version where
7347 // HelloRetryRequest requests an unsupported curve.
7348 name: "UnsupportedCurve-ServerHello-TLS13",
7349 config: Config{
7350 MaxVersion: VersionTLS12,
7351 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7352 CurvePreferences: []CurveID{CurveP384},
7353 Bugs: ProtocolBugs{
7354 SendCurve: CurveP256,
7355 },
7356 },
7357 flags: []string{"-p384-only"},
7358 shouldFail: true,
7359 expectedError: ":WRONG_CURVE:",
7360 })
7361
David Benjamin4c3ddf72016-06-29 18:13:53 -04007362 // Test invalid curve points.
7363 testCases = append(testCases, testCase{
7364 name: "InvalidECDHPoint-Client",
7365 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007366 MaxVersion: VersionTLS12,
7367 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7368 CurvePreferences: []CurveID{CurveP256},
7369 Bugs: ProtocolBugs{
7370 InvalidECDHPoint: true,
7371 },
7372 },
7373 shouldFail: true,
7374 expectedError: ":INVALID_ENCODING:",
7375 })
7376 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007377 name: "InvalidECDHPoint-Client-TLS13",
7378 config: Config{
7379 MaxVersion: VersionTLS13,
7380 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7381 CurvePreferences: []CurveID{CurveP256},
7382 Bugs: ProtocolBugs{
7383 InvalidECDHPoint: true,
7384 },
7385 },
7386 shouldFail: true,
7387 expectedError: ":INVALID_ENCODING:",
7388 })
7389 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007390 testType: serverTest,
7391 name: "InvalidECDHPoint-Server",
7392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007393 MaxVersion: VersionTLS12,
7394 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7395 CurvePreferences: []CurveID{CurveP256},
7396 Bugs: ProtocolBugs{
7397 InvalidECDHPoint: true,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":INVALID_ENCODING:",
7402 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007403 testCases = append(testCases, testCase{
7404 testType: serverTest,
7405 name: "InvalidECDHPoint-Server-TLS13",
7406 config: Config{
7407 MaxVersion: VersionTLS13,
7408 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7409 CurvePreferences: []CurveID{CurveP256},
7410 Bugs: ProtocolBugs{
7411 InvalidECDHPoint: true,
7412 },
7413 },
7414 shouldFail: true,
7415 expectedError: ":INVALID_ENCODING:",
7416 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007417}
7418
Matt Braithwaite54217e42016-06-13 13:03:47 -07007419func addCECPQ1Tests() {
7420 testCases = append(testCases, testCase{
7421 testType: clientTest,
7422 name: "CECPQ1-Client-BadX25519Part",
7423 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007424 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007425 MinVersion: VersionTLS12,
7426 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7427 Bugs: ProtocolBugs{
7428 CECPQ1BadX25519Part: true,
7429 },
7430 },
7431 flags: []string{"-cipher", "kCECPQ1"},
7432 shouldFail: true,
7433 expectedLocalError: "local error: bad record MAC",
7434 })
7435 testCases = append(testCases, testCase{
7436 testType: clientTest,
7437 name: "CECPQ1-Client-BadNewhopePart",
7438 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007439 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007440 MinVersion: VersionTLS12,
7441 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7442 Bugs: ProtocolBugs{
7443 CECPQ1BadNewhopePart: true,
7444 },
7445 },
7446 flags: []string{"-cipher", "kCECPQ1"},
7447 shouldFail: true,
7448 expectedLocalError: "local error: bad record MAC",
7449 })
7450 testCases = append(testCases, testCase{
7451 testType: serverTest,
7452 name: "CECPQ1-Server-BadX25519Part",
7453 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007454 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007455 MinVersion: VersionTLS12,
7456 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7457 Bugs: ProtocolBugs{
7458 CECPQ1BadX25519Part: true,
7459 },
7460 },
7461 flags: []string{"-cipher", "kCECPQ1"},
7462 shouldFail: true,
7463 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7464 })
7465 testCases = append(testCases, testCase{
7466 testType: serverTest,
7467 name: "CECPQ1-Server-BadNewhopePart",
7468 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007469 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007470 MinVersion: VersionTLS12,
7471 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7472 Bugs: ProtocolBugs{
7473 CECPQ1BadNewhopePart: true,
7474 },
7475 },
7476 flags: []string{"-cipher", "kCECPQ1"},
7477 shouldFail: true,
7478 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7479 })
7480}
7481
David Benjamin5c4e8572016-08-19 17:44:53 -04007482func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007483 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007484 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007485 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007486 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007487 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7488 Bugs: ProtocolBugs{
7489 // This is a 1234-bit prime number, generated
7490 // with:
7491 // openssl gendh 1234 | openssl asn1parse -i
7492 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7493 },
7494 },
David Benjamin9e68f192016-06-30 14:55:33 -04007495 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007496 })
7497 testCases = append(testCases, testCase{
7498 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007499 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007500 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007501 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007502 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7503 },
7504 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007505 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007506 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007507}
7508
David Benjaminc9ae27c2016-06-24 22:56:37 -04007509func addTLS13RecordTests() {
7510 testCases = append(testCases, testCase{
7511 name: "TLS13-RecordPadding",
7512 config: Config{
7513 MaxVersion: VersionTLS13,
7514 MinVersion: VersionTLS13,
7515 Bugs: ProtocolBugs{
7516 RecordPadding: 10,
7517 },
7518 },
7519 })
7520
7521 testCases = append(testCases, testCase{
7522 name: "TLS13-EmptyRecords",
7523 config: Config{
7524 MaxVersion: VersionTLS13,
7525 MinVersion: VersionTLS13,
7526 Bugs: ProtocolBugs{
7527 OmitRecordContents: true,
7528 },
7529 },
7530 shouldFail: true,
7531 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7532 })
7533
7534 testCases = append(testCases, testCase{
7535 name: "TLS13-OnlyPadding",
7536 config: Config{
7537 MaxVersion: VersionTLS13,
7538 MinVersion: VersionTLS13,
7539 Bugs: ProtocolBugs{
7540 OmitRecordContents: true,
7541 RecordPadding: 10,
7542 },
7543 },
7544 shouldFail: true,
7545 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7546 })
7547
7548 testCases = append(testCases, testCase{
7549 name: "TLS13-WrongOuterRecord",
7550 config: Config{
7551 MaxVersion: VersionTLS13,
7552 MinVersion: VersionTLS13,
7553 Bugs: ProtocolBugs{
7554 OuterRecordType: recordTypeHandshake,
7555 },
7556 },
7557 shouldFail: true,
7558 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7559 })
7560}
7561
Steven Valdez5b986082016-09-01 12:29:49 -04007562func addSessionTicketTests() {
7563 testCases = append(testCases, testCase{
7564 // In TLS 1.2 and below, empty NewSessionTicket messages
7565 // mean the server changed its mind on sending a ticket.
7566 name: "SendEmptySessionTicket",
7567 config: Config{
7568 MaxVersion: VersionTLS12,
7569 Bugs: ProtocolBugs{
7570 SendEmptySessionTicket: true,
7571 },
7572 },
7573 flags: []string{"-expect-no-session"},
7574 })
7575
7576 // Test that the server ignores unknown PSK modes.
7577 testCases = append(testCases, testCase{
7578 testType: serverTest,
7579 name: "TLS13-SendUnknownModeSessionTicket-Server",
7580 config: Config{
7581 MaxVersion: VersionTLS13,
7582 Bugs: ProtocolBugs{
7583 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7584 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7585 },
7586 },
7587 resumeSession: true,
7588 expectedResumeVersion: VersionTLS13,
7589 })
7590
7591 // Test that the server declines sessions with no matching key exchange mode.
7592 testCases = append(testCases, testCase{
7593 testType: serverTest,
7594 name: "TLS13-SendBadKEModeSessionTicket-Server",
7595 config: Config{
7596 MaxVersion: VersionTLS13,
7597 Bugs: ProtocolBugs{
7598 SendPSKKeyExchangeModes: []byte{0x1a},
7599 },
7600 },
7601 resumeSession: true,
7602 expectResumeRejected: true,
7603 })
7604
7605 // Test that the server declines sessions with no matching auth mode.
7606 testCases = append(testCases, testCase{
7607 testType: serverTest,
7608 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7609 config: Config{
7610 MaxVersion: VersionTLS13,
7611 Bugs: ProtocolBugs{
7612 SendPSKAuthModes: []byte{0x1a},
7613 },
7614 },
7615 resumeSession: true,
7616 expectResumeRejected: true,
7617 })
7618
7619 // Test that the client ignores unknown PSK modes.
7620 testCases = append(testCases, testCase{
7621 testType: clientTest,
7622 name: "TLS13-SendUnknownModeSessionTicket-Client",
7623 config: Config{
7624 MaxVersion: VersionTLS13,
7625 Bugs: ProtocolBugs{
7626 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7627 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7628 },
7629 },
7630 resumeSession: true,
7631 expectedResumeVersion: VersionTLS13,
7632 })
7633
7634 // Test that the client ignores tickets with no matching key exchange mode.
7635 testCases = append(testCases, testCase{
7636 testType: clientTest,
7637 name: "TLS13-SendBadKEModeSessionTicket-Client",
7638 config: Config{
7639 MaxVersion: VersionTLS13,
7640 Bugs: ProtocolBugs{
7641 SendPSKKeyExchangeModes: []byte{0x1a},
7642 },
7643 },
7644 flags: []string{"-expect-no-session"},
7645 })
7646
7647 // Test that the client ignores tickets with no matching auth mode.
7648 testCases = append(testCases, testCase{
7649 testType: clientTest,
7650 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7651 config: Config{
7652 MaxVersion: VersionTLS13,
7653 Bugs: ProtocolBugs{
7654 SendPSKAuthModes: []byte{0x1a},
7655 },
7656 },
7657 flags: []string{"-expect-no-session"},
7658 })
7659}
7660
David Benjamin82261be2016-07-07 14:32:50 -07007661func addChangeCipherSpecTests() {
7662 // Test missing ChangeCipherSpecs.
7663 testCases = append(testCases, testCase{
7664 name: "SkipChangeCipherSpec-Client",
7665 config: Config{
7666 MaxVersion: VersionTLS12,
7667 Bugs: ProtocolBugs{
7668 SkipChangeCipherSpec: true,
7669 },
7670 },
7671 shouldFail: true,
7672 expectedError: ":UNEXPECTED_RECORD:",
7673 })
7674 testCases = append(testCases, testCase{
7675 testType: serverTest,
7676 name: "SkipChangeCipherSpec-Server",
7677 config: Config{
7678 MaxVersion: VersionTLS12,
7679 Bugs: ProtocolBugs{
7680 SkipChangeCipherSpec: true,
7681 },
7682 },
7683 shouldFail: true,
7684 expectedError: ":UNEXPECTED_RECORD:",
7685 })
7686 testCases = append(testCases, testCase{
7687 testType: serverTest,
7688 name: "SkipChangeCipherSpec-Server-NPN",
7689 config: Config{
7690 MaxVersion: VersionTLS12,
7691 NextProtos: []string{"bar"},
7692 Bugs: ProtocolBugs{
7693 SkipChangeCipherSpec: true,
7694 },
7695 },
7696 flags: []string{
7697 "-advertise-npn", "\x03foo\x03bar\x03baz",
7698 },
7699 shouldFail: true,
7700 expectedError: ":UNEXPECTED_RECORD:",
7701 })
7702
7703 // Test synchronization between the handshake and ChangeCipherSpec.
7704 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7705 // rejected. Test both with and without handshake packing to handle both
7706 // when the partial post-CCS message is in its own record and when it is
7707 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007708 for _, packed := range []bool{false, true} {
7709 var suffix string
7710 if packed {
7711 suffix = "-Packed"
7712 }
7713
7714 testCases = append(testCases, testCase{
7715 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7716 config: Config{
7717 MaxVersion: VersionTLS12,
7718 Bugs: ProtocolBugs{
7719 FragmentAcrossChangeCipherSpec: true,
7720 PackHandshakeFlight: packed,
7721 },
7722 },
7723 shouldFail: true,
7724 expectedError: ":UNEXPECTED_RECORD:",
7725 })
7726 testCases = append(testCases, testCase{
7727 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7728 config: Config{
7729 MaxVersion: VersionTLS12,
7730 },
7731 resumeSession: true,
7732 resumeConfig: &Config{
7733 MaxVersion: VersionTLS12,
7734 Bugs: ProtocolBugs{
7735 FragmentAcrossChangeCipherSpec: true,
7736 PackHandshakeFlight: packed,
7737 },
7738 },
7739 shouldFail: true,
7740 expectedError: ":UNEXPECTED_RECORD:",
7741 })
7742 testCases = append(testCases, testCase{
7743 testType: serverTest,
7744 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7745 config: Config{
7746 MaxVersion: VersionTLS12,
7747 Bugs: ProtocolBugs{
7748 FragmentAcrossChangeCipherSpec: true,
7749 PackHandshakeFlight: packed,
7750 },
7751 },
7752 shouldFail: true,
7753 expectedError: ":UNEXPECTED_RECORD:",
7754 })
7755 testCases = append(testCases, testCase{
7756 testType: serverTest,
7757 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7758 config: Config{
7759 MaxVersion: VersionTLS12,
7760 },
7761 resumeSession: true,
7762 resumeConfig: &Config{
7763 MaxVersion: VersionTLS12,
7764 Bugs: ProtocolBugs{
7765 FragmentAcrossChangeCipherSpec: true,
7766 PackHandshakeFlight: packed,
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":UNEXPECTED_RECORD:",
7771 })
7772 testCases = append(testCases, testCase{
7773 testType: serverTest,
7774 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7775 config: Config{
7776 MaxVersion: VersionTLS12,
7777 NextProtos: []string{"bar"},
7778 Bugs: ProtocolBugs{
7779 FragmentAcrossChangeCipherSpec: true,
7780 PackHandshakeFlight: packed,
7781 },
7782 },
7783 flags: []string{
7784 "-advertise-npn", "\x03foo\x03bar\x03baz",
7785 },
7786 shouldFail: true,
7787 expectedError: ":UNEXPECTED_RECORD:",
7788 })
7789 }
7790
David Benjamin61672812016-07-14 23:10:43 -04007791 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7792 // messages in the handshake queue. Do this by testing the server
7793 // reading the client Finished, reversing the flight so Finished comes
7794 // first.
7795 testCases = append(testCases, testCase{
7796 protocol: dtls,
7797 testType: serverTest,
7798 name: "SendUnencryptedFinished-DTLS",
7799 config: Config{
7800 MaxVersion: VersionTLS12,
7801 Bugs: ProtocolBugs{
7802 SendUnencryptedFinished: true,
7803 ReverseHandshakeFragments: true,
7804 },
7805 },
7806 shouldFail: true,
7807 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7808 })
7809
Steven Valdez143e8b32016-07-11 13:19:03 -04007810 // Test synchronization between encryption changes and the handshake in
7811 // TLS 1.3, where ChangeCipherSpec is implicit.
7812 testCases = append(testCases, testCase{
7813 name: "PartialEncryptedExtensionsWithServerHello",
7814 config: Config{
7815 MaxVersion: VersionTLS13,
7816 Bugs: ProtocolBugs{
7817 PartialEncryptedExtensionsWithServerHello: true,
7818 },
7819 },
7820 shouldFail: true,
7821 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7822 })
7823 testCases = append(testCases, testCase{
7824 testType: serverTest,
7825 name: "PartialClientFinishedWithClientHello",
7826 config: Config{
7827 MaxVersion: VersionTLS13,
7828 Bugs: ProtocolBugs{
7829 PartialClientFinishedWithClientHello: true,
7830 },
7831 },
7832 shouldFail: true,
7833 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7834 })
7835
David Benjamin82261be2016-07-07 14:32:50 -07007836 // Test that early ChangeCipherSpecs are handled correctly.
7837 testCases = append(testCases, testCase{
7838 testType: serverTest,
7839 name: "EarlyChangeCipherSpec-server-1",
7840 config: Config{
7841 MaxVersion: VersionTLS12,
7842 Bugs: ProtocolBugs{
7843 EarlyChangeCipherSpec: 1,
7844 },
7845 },
7846 shouldFail: true,
7847 expectedError: ":UNEXPECTED_RECORD:",
7848 })
7849 testCases = append(testCases, testCase{
7850 testType: serverTest,
7851 name: "EarlyChangeCipherSpec-server-2",
7852 config: Config{
7853 MaxVersion: VersionTLS12,
7854 Bugs: ProtocolBugs{
7855 EarlyChangeCipherSpec: 2,
7856 },
7857 },
7858 shouldFail: true,
7859 expectedError: ":UNEXPECTED_RECORD:",
7860 })
7861 testCases = append(testCases, testCase{
7862 protocol: dtls,
7863 name: "StrayChangeCipherSpec",
7864 config: Config{
7865 // TODO(davidben): Once DTLS 1.3 exists, test
7866 // that stray ChangeCipherSpec messages are
7867 // rejected.
7868 MaxVersion: VersionTLS12,
7869 Bugs: ProtocolBugs{
7870 StrayChangeCipherSpec: true,
7871 },
7872 },
7873 })
7874
7875 // Test that the contents of ChangeCipherSpec are checked.
7876 testCases = append(testCases, testCase{
7877 name: "BadChangeCipherSpec-1",
7878 config: Config{
7879 MaxVersion: VersionTLS12,
7880 Bugs: ProtocolBugs{
7881 BadChangeCipherSpec: []byte{2},
7882 },
7883 },
7884 shouldFail: true,
7885 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7886 })
7887 testCases = append(testCases, testCase{
7888 name: "BadChangeCipherSpec-2",
7889 config: Config{
7890 MaxVersion: VersionTLS12,
7891 Bugs: ProtocolBugs{
7892 BadChangeCipherSpec: []byte{1, 1},
7893 },
7894 },
7895 shouldFail: true,
7896 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7897 })
7898 testCases = append(testCases, testCase{
7899 protocol: dtls,
7900 name: "BadChangeCipherSpec-DTLS-1",
7901 config: Config{
7902 MaxVersion: VersionTLS12,
7903 Bugs: ProtocolBugs{
7904 BadChangeCipherSpec: []byte{2},
7905 },
7906 },
7907 shouldFail: true,
7908 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7909 })
7910 testCases = append(testCases, testCase{
7911 protocol: dtls,
7912 name: "BadChangeCipherSpec-DTLS-2",
7913 config: Config{
7914 MaxVersion: VersionTLS12,
7915 Bugs: ProtocolBugs{
7916 BadChangeCipherSpec: []byte{1, 1},
7917 },
7918 },
7919 shouldFail: true,
7920 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7921 })
7922}
7923
David Benjamincd2c8062016-09-09 11:28:16 -04007924type perMessageTest struct {
7925 messageType uint8
7926 test testCase
7927}
7928
7929// makePerMessageTests returns a series of test templates which cover each
7930// message in the TLS handshake. These may be used with bugs like
7931// WrongMessageType to fully test a per-message bug.
7932func makePerMessageTests() []perMessageTest {
7933 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007934 for _, protocol := range []protocol{tls, dtls} {
7935 var suffix string
7936 if protocol == dtls {
7937 suffix = "-DTLS"
7938 }
7939
David Benjamincd2c8062016-09-09 11:28:16 -04007940 ret = append(ret, perMessageTest{
7941 messageType: typeClientHello,
7942 test: testCase{
7943 protocol: protocol,
7944 testType: serverTest,
7945 name: "ClientHello" + suffix,
7946 config: Config{
7947 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007948 },
7949 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007950 })
7951
7952 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007953 ret = append(ret, perMessageTest{
7954 messageType: typeHelloVerifyRequest,
7955 test: testCase{
7956 protocol: protocol,
7957 name: "HelloVerifyRequest" + suffix,
7958 config: Config{
7959 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007960 },
7961 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007962 })
7963 }
7964
David Benjamincd2c8062016-09-09 11:28:16 -04007965 ret = append(ret, perMessageTest{
7966 messageType: typeServerHello,
7967 test: testCase{
7968 protocol: protocol,
7969 name: "ServerHello" + suffix,
7970 config: Config{
7971 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007972 },
7973 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007974 })
7975
David Benjamincd2c8062016-09-09 11:28:16 -04007976 ret = append(ret, perMessageTest{
7977 messageType: typeCertificate,
7978 test: testCase{
7979 protocol: protocol,
7980 name: "ServerCertificate" + suffix,
7981 config: Config{
7982 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007983 },
7984 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007985 })
7986
David Benjamincd2c8062016-09-09 11:28:16 -04007987 ret = append(ret, perMessageTest{
7988 messageType: typeCertificateStatus,
7989 test: testCase{
7990 protocol: protocol,
7991 name: "CertificateStatus" + suffix,
7992 config: Config{
7993 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007994 },
David Benjamincd2c8062016-09-09 11:28:16 -04007995 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007996 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007997 })
7998
David Benjamincd2c8062016-09-09 11:28:16 -04007999 ret = append(ret, perMessageTest{
8000 messageType: typeServerKeyExchange,
8001 test: testCase{
8002 protocol: protocol,
8003 name: "ServerKeyExchange" + suffix,
8004 config: Config{
8005 MaxVersion: VersionTLS12,
8006 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008007 },
8008 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008009 })
8010
David Benjamincd2c8062016-09-09 11:28:16 -04008011 ret = append(ret, perMessageTest{
8012 messageType: typeCertificateRequest,
8013 test: testCase{
8014 protocol: protocol,
8015 name: "CertificateRequest" + suffix,
8016 config: Config{
8017 MaxVersion: VersionTLS12,
8018 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008019 },
8020 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008021 })
8022
David Benjamincd2c8062016-09-09 11:28:16 -04008023 ret = append(ret, perMessageTest{
8024 messageType: typeServerHelloDone,
8025 test: testCase{
8026 protocol: protocol,
8027 name: "ServerHelloDone" + suffix,
8028 config: Config{
8029 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008030 },
8031 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008032 })
8033
David Benjamincd2c8062016-09-09 11:28:16 -04008034 ret = append(ret, perMessageTest{
8035 messageType: typeCertificate,
8036 test: testCase{
8037 testType: serverTest,
8038 protocol: protocol,
8039 name: "ClientCertificate" + suffix,
8040 config: Config{
8041 Certificates: []Certificate{rsaCertificate},
8042 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008043 },
David Benjamincd2c8062016-09-09 11:28:16 -04008044 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008045 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008046 })
8047
David Benjamincd2c8062016-09-09 11:28:16 -04008048 ret = append(ret, perMessageTest{
8049 messageType: typeCertificateVerify,
8050 test: testCase{
8051 testType: serverTest,
8052 protocol: protocol,
8053 name: "CertificateVerify" + suffix,
8054 config: Config{
8055 Certificates: []Certificate{rsaCertificate},
8056 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008057 },
David Benjamincd2c8062016-09-09 11:28:16 -04008058 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008059 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008060 })
8061
David Benjamincd2c8062016-09-09 11:28:16 -04008062 ret = append(ret, perMessageTest{
8063 messageType: typeClientKeyExchange,
8064 test: testCase{
8065 testType: serverTest,
8066 protocol: protocol,
8067 name: "ClientKeyExchange" + suffix,
8068 config: Config{
8069 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008070 },
8071 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008072 })
8073
8074 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008075 ret = append(ret, perMessageTest{
8076 messageType: typeNextProtocol,
8077 test: testCase{
8078 testType: serverTest,
8079 protocol: protocol,
8080 name: "NextProtocol" + suffix,
8081 config: Config{
8082 MaxVersion: VersionTLS12,
8083 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008084 },
David Benjamincd2c8062016-09-09 11:28:16 -04008085 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008086 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008087 })
8088
David Benjamincd2c8062016-09-09 11:28:16 -04008089 ret = append(ret, perMessageTest{
8090 messageType: typeChannelID,
8091 test: testCase{
8092 testType: serverTest,
8093 protocol: protocol,
8094 name: "ChannelID" + suffix,
8095 config: Config{
8096 MaxVersion: VersionTLS12,
8097 ChannelID: channelIDKey,
8098 },
8099 flags: []string{
8100 "-expect-channel-id",
8101 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008102 },
8103 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008104 })
8105 }
8106
David Benjamincd2c8062016-09-09 11:28:16 -04008107 ret = append(ret, perMessageTest{
8108 messageType: typeFinished,
8109 test: testCase{
8110 testType: serverTest,
8111 protocol: protocol,
8112 name: "ClientFinished" + suffix,
8113 config: Config{
8114 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008115 },
8116 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008117 })
8118
David Benjamincd2c8062016-09-09 11:28:16 -04008119 ret = append(ret, perMessageTest{
8120 messageType: typeNewSessionTicket,
8121 test: testCase{
8122 protocol: protocol,
8123 name: "NewSessionTicket" + suffix,
8124 config: Config{
8125 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008126 },
8127 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008128 })
8129
David Benjamincd2c8062016-09-09 11:28:16 -04008130 ret = append(ret, perMessageTest{
8131 messageType: typeFinished,
8132 test: testCase{
8133 protocol: protocol,
8134 name: "ServerFinished" + suffix,
8135 config: Config{
8136 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008137 },
8138 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008139 })
8140
8141 }
David Benjamincd2c8062016-09-09 11:28:16 -04008142
8143 ret = append(ret, perMessageTest{
8144 messageType: typeClientHello,
8145 test: testCase{
8146 testType: serverTest,
8147 name: "TLS13-ClientHello",
8148 config: Config{
8149 MaxVersion: VersionTLS13,
8150 },
8151 },
8152 })
8153
8154 ret = append(ret, perMessageTest{
8155 messageType: typeServerHello,
8156 test: testCase{
8157 name: "TLS13-ServerHello",
8158 config: Config{
8159 MaxVersion: VersionTLS13,
8160 },
8161 },
8162 })
8163
8164 ret = append(ret, perMessageTest{
8165 messageType: typeEncryptedExtensions,
8166 test: testCase{
8167 name: "TLS13-EncryptedExtensions",
8168 config: Config{
8169 MaxVersion: VersionTLS13,
8170 },
8171 },
8172 })
8173
8174 ret = append(ret, perMessageTest{
8175 messageType: typeCertificateRequest,
8176 test: testCase{
8177 name: "TLS13-CertificateRequest",
8178 config: Config{
8179 MaxVersion: VersionTLS13,
8180 ClientAuth: RequireAnyClientCert,
8181 },
8182 },
8183 })
8184
8185 ret = append(ret, perMessageTest{
8186 messageType: typeCertificate,
8187 test: testCase{
8188 name: "TLS13-ServerCertificate",
8189 config: Config{
8190 MaxVersion: VersionTLS13,
8191 },
8192 },
8193 })
8194
8195 ret = append(ret, perMessageTest{
8196 messageType: typeCertificateVerify,
8197 test: testCase{
8198 name: "TLS13-ServerCertificateVerify",
8199 config: Config{
8200 MaxVersion: VersionTLS13,
8201 },
8202 },
8203 })
8204
8205 ret = append(ret, perMessageTest{
8206 messageType: typeFinished,
8207 test: testCase{
8208 name: "TLS13-ServerFinished",
8209 config: Config{
8210 MaxVersion: VersionTLS13,
8211 },
8212 },
8213 })
8214
8215 ret = append(ret, perMessageTest{
8216 messageType: typeCertificate,
8217 test: testCase{
8218 testType: serverTest,
8219 name: "TLS13-ClientCertificate",
8220 config: Config{
8221 Certificates: []Certificate{rsaCertificate},
8222 MaxVersion: VersionTLS13,
8223 },
8224 flags: []string{"-require-any-client-certificate"},
8225 },
8226 })
8227
8228 ret = append(ret, perMessageTest{
8229 messageType: typeCertificateVerify,
8230 test: testCase{
8231 testType: serverTest,
8232 name: "TLS13-ClientCertificateVerify",
8233 config: Config{
8234 Certificates: []Certificate{rsaCertificate},
8235 MaxVersion: VersionTLS13,
8236 },
8237 flags: []string{"-require-any-client-certificate"},
8238 },
8239 })
8240
8241 ret = append(ret, perMessageTest{
8242 messageType: typeFinished,
8243 test: testCase{
8244 testType: serverTest,
8245 name: "TLS13-ClientFinished",
8246 config: Config{
8247 MaxVersion: VersionTLS13,
8248 },
8249 },
8250 })
8251
8252 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008253}
8254
David Benjamincd2c8062016-09-09 11:28:16 -04008255func addWrongMessageTypeTests() {
8256 for _, t := range makePerMessageTests() {
8257 t.test.name = "WrongMessageType-" + t.test.name
8258 t.test.config.Bugs.SendWrongMessageType = t.messageType
8259 t.test.shouldFail = true
8260 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8261 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008262
David Benjamincd2c8062016-09-09 11:28:16 -04008263 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8264 // In TLS 1.3, a bad ServerHello means the client sends
8265 // an unencrypted alert while the server expects
8266 // encryption, so the alert is not readable by runner.
8267 t.test.expectedLocalError = "local error: bad record MAC"
8268 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008269
David Benjamincd2c8062016-09-09 11:28:16 -04008270 testCases = append(testCases, t.test)
8271 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008272}
8273
David Benjamin639846e2016-09-09 11:41:18 -04008274func addTrailingMessageDataTests() {
8275 for _, t := range makePerMessageTests() {
8276 t.test.name = "TrailingMessageData-" + t.test.name
8277 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8278 t.test.shouldFail = true
8279 t.test.expectedError = ":DECODE_ERROR:"
8280 t.test.expectedLocalError = "remote error: error decoding message"
8281
8282 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8283 // In TLS 1.3, a bad ServerHello means the client sends
8284 // an unencrypted alert while the server expects
8285 // encryption, so the alert is not readable by runner.
8286 t.test.expectedLocalError = "local error: bad record MAC"
8287 }
8288
8289 if t.messageType == typeFinished {
8290 // Bad Finished messages read as the verify data having
8291 // the wrong length.
8292 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8293 t.test.expectedLocalError = "remote error: error decrypting message"
8294 }
8295
8296 testCases = append(testCases, t.test)
8297 }
8298}
8299
Steven Valdez143e8b32016-07-11 13:19:03 -04008300func addTLS13HandshakeTests() {
8301 testCases = append(testCases, testCase{
8302 testType: clientTest,
8303 name: "MissingKeyShare-Client",
8304 config: Config{
8305 MaxVersion: VersionTLS13,
8306 Bugs: ProtocolBugs{
8307 MissingKeyShare: true,
8308 },
8309 },
8310 shouldFail: true,
8311 expectedError: ":MISSING_KEY_SHARE:",
8312 })
8313
8314 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008315 testType: serverTest,
8316 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008317 config: Config{
8318 MaxVersion: VersionTLS13,
8319 Bugs: ProtocolBugs{
8320 MissingKeyShare: true,
8321 },
8322 },
8323 shouldFail: true,
8324 expectedError: ":MISSING_KEY_SHARE:",
8325 })
8326
8327 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008328 testType: serverTest,
8329 name: "DuplicateKeyShares",
8330 config: Config{
8331 MaxVersion: VersionTLS13,
8332 Bugs: ProtocolBugs{
8333 DuplicateKeyShares: true,
8334 },
8335 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008336 shouldFail: true,
8337 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008338 })
8339
8340 testCases = append(testCases, testCase{
8341 testType: clientTest,
8342 name: "EmptyEncryptedExtensions",
8343 config: Config{
8344 MaxVersion: VersionTLS13,
8345 Bugs: ProtocolBugs{
8346 EmptyEncryptedExtensions: true,
8347 },
8348 },
8349 shouldFail: true,
8350 expectedLocalError: "remote error: error decoding message",
8351 })
8352
8353 testCases = append(testCases, testCase{
8354 testType: clientTest,
8355 name: "EncryptedExtensionsWithKeyShare",
8356 config: Config{
8357 MaxVersion: VersionTLS13,
8358 Bugs: ProtocolBugs{
8359 EncryptedExtensionsWithKeyShare: true,
8360 },
8361 },
8362 shouldFail: true,
8363 expectedLocalError: "remote error: unsupported extension",
8364 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008365
8366 testCases = append(testCases, testCase{
8367 testType: serverTest,
8368 name: "SendHelloRetryRequest",
8369 config: Config{
8370 MaxVersion: VersionTLS13,
8371 // Require a HelloRetryRequest for every curve.
8372 DefaultCurves: []CurveID{},
8373 },
8374 expectedCurveID: CurveX25519,
8375 })
8376
8377 testCases = append(testCases, testCase{
8378 testType: serverTest,
8379 name: "SendHelloRetryRequest-2",
8380 config: Config{
8381 MaxVersion: VersionTLS13,
8382 DefaultCurves: []CurveID{CurveP384},
8383 },
8384 // Although the ClientHello did not predict our preferred curve,
8385 // we always select it whether it is predicted or not.
8386 expectedCurveID: CurveX25519,
8387 })
8388
8389 testCases = append(testCases, testCase{
8390 name: "UnknownCurve-HelloRetryRequest",
8391 config: Config{
8392 MaxVersion: VersionTLS13,
8393 // P-384 requires HelloRetryRequest in BoringSSL.
8394 CurvePreferences: []CurveID{CurveP384},
8395 Bugs: ProtocolBugs{
8396 SendHelloRetryRequestCurve: bogusCurve,
8397 },
8398 },
8399 shouldFail: true,
8400 expectedError: ":WRONG_CURVE:",
8401 })
8402
8403 testCases = append(testCases, testCase{
8404 name: "DisabledCurve-HelloRetryRequest",
8405 config: Config{
8406 MaxVersion: VersionTLS13,
8407 CurvePreferences: []CurveID{CurveP256},
8408 Bugs: ProtocolBugs{
8409 IgnorePeerCurvePreferences: true,
8410 },
8411 },
8412 flags: []string{"-p384-only"},
8413 shouldFail: true,
8414 expectedError: ":WRONG_CURVE:",
8415 })
8416
8417 testCases = append(testCases, testCase{
8418 name: "UnnecessaryHelloRetryRequest",
8419 config: Config{
8420 MaxVersion: VersionTLS13,
8421 Bugs: ProtocolBugs{
8422 UnnecessaryHelloRetryRequest: true,
8423 },
8424 },
8425 shouldFail: true,
8426 expectedError: ":WRONG_CURVE:",
8427 })
8428
8429 testCases = append(testCases, testCase{
8430 name: "SecondHelloRetryRequest",
8431 config: Config{
8432 MaxVersion: VersionTLS13,
8433 // P-384 requires HelloRetryRequest in BoringSSL.
8434 CurvePreferences: []CurveID{CurveP384},
8435 Bugs: ProtocolBugs{
8436 SecondHelloRetryRequest: true,
8437 },
8438 },
8439 shouldFail: true,
8440 expectedError: ":UNEXPECTED_MESSAGE:",
8441 })
8442
8443 testCases = append(testCases, testCase{
8444 testType: serverTest,
8445 name: "SecondClientHelloMissingKeyShare",
8446 config: Config{
8447 MaxVersion: VersionTLS13,
8448 DefaultCurves: []CurveID{},
8449 Bugs: ProtocolBugs{
8450 SecondClientHelloMissingKeyShare: true,
8451 },
8452 },
8453 shouldFail: true,
8454 expectedError: ":MISSING_KEY_SHARE:",
8455 })
8456
8457 testCases = append(testCases, testCase{
8458 testType: serverTest,
8459 name: "SecondClientHelloWrongCurve",
8460 config: Config{
8461 MaxVersion: VersionTLS13,
8462 DefaultCurves: []CurveID{},
8463 Bugs: ProtocolBugs{
8464 MisinterpretHelloRetryRequestCurve: CurveP521,
8465 },
8466 },
8467 shouldFail: true,
8468 expectedError: ":WRONG_CURVE:",
8469 })
8470
8471 testCases = append(testCases, testCase{
8472 name: "HelloRetryRequestVersionMismatch",
8473 config: Config{
8474 MaxVersion: VersionTLS13,
8475 // P-384 requires HelloRetryRequest in BoringSSL.
8476 CurvePreferences: []CurveID{CurveP384},
8477 Bugs: ProtocolBugs{
8478 SendServerHelloVersion: 0x0305,
8479 },
8480 },
8481 shouldFail: true,
8482 expectedError: ":WRONG_VERSION_NUMBER:",
8483 })
8484
8485 testCases = append(testCases, testCase{
8486 name: "HelloRetryRequestCurveMismatch",
8487 config: Config{
8488 MaxVersion: VersionTLS13,
8489 // P-384 requires HelloRetryRequest in BoringSSL.
8490 CurvePreferences: []CurveID{CurveP384},
8491 Bugs: ProtocolBugs{
8492 // Send P-384 (correct) in the HelloRetryRequest.
8493 SendHelloRetryRequestCurve: CurveP384,
8494 // But send P-256 in the ServerHello.
8495 SendCurve: CurveP256,
8496 },
8497 },
8498 shouldFail: true,
8499 expectedError: ":WRONG_CURVE:",
8500 })
8501
8502 // Test the server selecting a curve that requires a HelloRetryRequest
8503 // without sending it.
8504 testCases = append(testCases, testCase{
8505 name: "SkipHelloRetryRequest",
8506 config: Config{
8507 MaxVersion: VersionTLS13,
8508 // P-384 requires HelloRetryRequest in BoringSSL.
8509 CurvePreferences: []CurveID{CurveP384},
8510 Bugs: ProtocolBugs{
8511 SkipHelloRetryRequest: true,
8512 },
8513 },
8514 shouldFail: true,
8515 expectedError: ":WRONG_CURVE:",
8516 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008517
8518 testCases = append(testCases, testCase{
8519 name: "TLS13-RequestContextInHandshake",
8520 config: Config{
8521 MaxVersion: VersionTLS13,
8522 MinVersion: VersionTLS13,
8523 ClientAuth: RequireAnyClientCert,
8524 Bugs: ProtocolBugs{
8525 SendRequestContext: []byte("request context"),
8526 },
8527 },
8528 flags: []string{
8529 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8530 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8531 },
8532 shouldFail: true,
8533 expectedError: ":DECODE_ERROR:",
8534 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008535
8536 testCases = append(testCases, testCase{
8537 testType: serverTest,
8538 name: "TLS13-TrailingKeyShareData",
8539 config: Config{
8540 MaxVersion: VersionTLS13,
8541 Bugs: ProtocolBugs{
8542 TrailingKeyShareData: true,
8543 },
8544 },
8545 shouldFail: true,
8546 expectedError: ":DECODE_ERROR:",
8547 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008548}
8549
David Benjaminf3fbade2016-09-19 13:08:16 -04008550func addPeekTests() {
8551 // Test SSL_peek works, including on empty records.
8552 testCases = append(testCases, testCase{
8553 name: "Peek-Basic",
8554 sendEmptyRecords: 1,
8555 flags: []string{"-peek-then-read"},
8556 })
8557
8558 // Test SSL_peek can drive the initial handshake.
8559 testCases = append(testCases, testCase{
8560 name: "Peek-ImplicitHandshake",
8561 flags: []string{
8562 "-peek-then-read",
8563 "-implicit-handshake",
8564 },
8565 })
8566
8567 // Test SSL_peek can discover and drive a renegotiation.
8568 testCases = append(testCases, testCase{
8569 name: "Peek-Renegotiate",
8570 config: Config{
8571 MaxVersion: VersionTLS12,
8572 },
8573 renegotiate: 1,
8574 flags: []string{
8575 "-peek-then-read",
8576 "-renegotiate-freely",
8577 "-expect-total-renegotiations", "1",
8578 },
8579 })
8580
8581 // Test SSL_peek can discover a close_notify.
8582 testCases = append(testCases, testCase{
8583 name: "Peek-Shutdown",
8584 config: Config{
8585 Bugs: ProtocolBugs{
8586 ExpectCloseNotify: true,
8587 },
8588 },
8589 flags: []string{
8590 "-peek-then-read",
8591 "-check-close-notify",
8592 },
8593 })
8594
8595 // Test SSL_peek can discover an alert.
8596 testCases = append(testCases, testCase{
8597 name: "Peek-Alert",
8598 config: Config{
8599 Bugs: ProtocolBugs{
8600 SendSpuriousAlert: alertRecordOverflow,
8601 },
8602 },
8603 flags: []string{"-peek-then-read"},
8604 shouldFail: true,
8605 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8606 })
8607
8608 // Test SSL_peek can handle KeyUpdate.
8609 testCases = append(testCases, testCase{
8610 name: "Peek-KeyUpdate",
8611 config: Config{
8612 MaxVersion: VersionTLS13,
8613 Bugs: ProtocolBugs{
8614 SendKeyUpdateBeforeEveryAppDataRecord: true,
8615 },
8616 },
8617 flags: []string{"-peek-then-read"},
8618 })
8619}
8620
Adam Langley7c803a62015-06-15 15:35:05 -07008621func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008622 defer wg.Done()
8623
8624 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008625 var err error
8626
8627 if *mallocTest < 0 {
8628 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008629 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008630 } else {
8631 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8632 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008633 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008634 if err != nil {
8635 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8636 }
8637 break
8638 }
8639 }
8640 }
Adam Langley95c29f32014-06-20 12:00:00 -07008641 statusChan <- statusMsg{test: test, err: err}
8642 }
8643}
8644
8645type statusMsg struct {
8646 test *testCase
8647 started bool
8648 err error
8649}
8650
David Benjamin5f237bc2015-02-11 17:14:15 -05008651func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008652 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008653
David Benjamin5f237bc2015-02-11 17:14:15 -05008654 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008655 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008656 if !*pipe {
8657 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008658 var erase string
8659 for i := 0; i < lineLen; i++ {
8660 erase += "\b \b"
8661 }
8662 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008663 }
8664
Adam Langley95c29f32014-06-20 12:00:00 -07008665 if msg.started {
8666 started++
8667 } else {
8668 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008669
8670 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008671 if msg.err == errUnimplemented {
8672 if *pipe {
8673 // Print each test instead of a status line.
8674 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8675 }
8676 unimplemented++
8677 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8678 } else {
8679 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8680 failed++
8681 testOutput.addResult(msg.test.name, "FAIL")
8682 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008683 } else {
8684 if *pipe {
8685 // Print each test instead of a status line.
8686 fmt.Printf("PASSED (%s)\n", msg.test.name)
8687 }
8688 testOutput.addResult(msg.test.name, "PASS")
8689 }
Adam Langley95c29f32014-06-20 12:00:00 -07008690 }
8691
David Benjamin5f237bc2015-02-11 17:14:15 -05008692 if !*pipe {
8693 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008694 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008695 lineLen = len(line)
8696 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008697 }
Adam Langley95c29f32014-06-20 12:00:00 -07008698 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008699
8700 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008701}
8702
8703func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008704 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008705 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008706 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008707
Adam Langley7c803a62015-06-15 15:35:05 -07008708 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008709 addCipherSuiteTests()
8710 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008711 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008712 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008713 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008714 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008715 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008716 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008717 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008718 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008719 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008720 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008721 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008722 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008723 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008724 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008725 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008726 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008727 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008728 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008729 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008730 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04008731 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008732 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008733 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008734 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008735 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008736 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008737 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008738 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008739
8740 var wg sync.WaitGroup
8741
Adam Langley7c803a62015-06-15 15:35:05 -07008742 statusChan := make(chan statusMsg, *numWorkers)
8743 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008744 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008745
EKRf71d7ed2016-08-06 13:25:12 -07008746 if len(*shimConfigFile) != 0 {
8747 encoded, err := ioutil.ReadFile(*shimConfigFile)
8748 if err != nil {
8749 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8750 os.Exit(1)
8751 }
8752
8753 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8754 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8755 os.Exit(1)
8756 }
8757 }
8758
David Benjamin025b3d32014-07-01 19:53:04 -04008759 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008760
Adam Langley7c803a62015-06-15 15:35:05 -07008761 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008762 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008763 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008764 }
8765
David Benjamin270f0a72016-03-17 14:41:36 -04008766 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008767 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008768 matched := true
8769 if len(*testToRun) != 0 {
8770 var err error
8771 matched, err = filepath.Match(*testToRun, testCases[i].name)
8772 if err != nil {
8773 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8774 os.Exit(1)
8775 }
8776 }
8777
EKRf71d7ed2016-08-06 13:25:12 -07008778 if !*includeDisabled {
8779 for pattern := range shimConfig.DisabledTests {
8780 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8781 if err != nil {
8782 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8783 os.Exit(1)
8784 }
8785
8786 if isDisabled {
8787 matched = false
8788 break
8789 }
8790 }
8791 }
8792
David Benjamin17e12922016-07-28 18:04:43 -04008793 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008794 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008795 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008796 }
8797 }
David Benjamin17e12922016-07-28 18:04:43 -04008798
David Benjamin270f0a72016-03-17 14:41:36 -04008799 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008800 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008801 os.Exit(1)
8802 }
Adam Langley95c29f32014-06-20 12:00:00 -07008803
8804 close(testChan)
8805 wg.Wait()
8806 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008807 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008808
8809 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008810
8811 if *jsonOutput != "" {
8812 if err := testOutput.writeTo(*jsonOutput); err != nil {
8813 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8814 }
8815 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008816
EKR842ae6c2016-07-27 09:22:05 +02008817 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8818 os.Exit(1)
8819 }
8820
8821 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008822 os.Exit(1)
8823 }
Adam Langley95c29f32014-06-20 12:00:00 -07008824}