blob: ba337d204838aee3c8a673ada7f716d046236c12 [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 Benjamin9867b7d2016-03-01 23:25:48 -0500369func writeTranscript(test *testCase, isResume bool, data []byte) {
370 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
390 name := test.name
391 if isResume {
392 name += "-Resume"
393 } else {
394 name += "-Normal"
395 }
396
397 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
398 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
399 }
400}
401
David Benjamin3ed59772016-03-08 12:50:21 -0500402// A timeoutConn implements an idle timeout on each Read and Write operation.
403type timeoutConn struct {
404 net.Conn
405 timeout time.Duration
406}
407
408func (t *timeoutConn) Read(b []byte) (int, error) {
409 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
410 return 0, err
411 }
412 return t.Conn.Read(b)
413}
414
415func (t *timeoutConn) Write(b []byte) (int, error) {
416 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
417 return 0, err
418 }
419 return t.Conn.Write(b)
420}
421
David Benjamin8e6db492015-07-25 18:29:23 -0400422func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool) error {
David Benjamine54af062016-08-08 19:21:18 -0400423 if !test.noSessionCache {
424 if config.ClientSessionCache == nil {
425 config.ClientSessionCache = NewLRUClientSessionCache(1)
426 }
427 if config.ServerSessionCache == nil {
428 config.ServerSessionCache = NewLRUServerSessionCache(1)
429 }
430 }
431 if test.testType == clientTest {
432 if len(config.Certificates) == 0 {
433 config.Certificates = []Certificate{rsaCertificate}
434 }
435 } else {
436 // Supply a ServerName to ensure a constant session cache key,
437 // rather than falling back to net.Conn.RemoteAddr.
438 if len(config.ServerName) == 0 {
439 config.ServerName = "test"
440 }
441 }
442 if *fuzzer {
443 config.Bugs.NullAllCiphers = true
444 }
David Benjamine54af062016-08-08 19:21:18 -0400445
David Benjamin01784b42016-06-07 18:00:52 -0400446 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500447
David Benjamin6fd297b2014-08-11 18:43:38 -0400448 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500449 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
450 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500451 }
452
David Benjamin9867b7d2016-03-01 23:25:48 -0500453 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500454 local, peer := "client", "server"
455 if test.testType == clientTest {
456 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500457 }
David Benjaminebda9b32015-11-02 15:33:18 -0500458 connDebug := &recordingConn{
459 Conn: conn,
460 isDatagram: test.protocol == dtls,
461 local: local,
462 peer: peer,
463 }
464 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500465 if *flagDebug {
466 defer connDebug.WriteTo(os.Stdout)
467 }
468 if len(*transcriptDir) != 0 {
469 defer func() {
470 writeTranscript(test, isResume, connDebug.Transcript())
471 }()
472 }
David Benjaminebda9b32015-11-02 15:33:18 -0500473
474 if config.Bugs.PacketAdaptor != nil {
475 config.Bugs.PacketAdaptor.debug = connDebug
476 }
477 }
478
479 if test.replayWrites {
480 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400481 }
482
David Benjamin3ed59772016-03-08 12:50:21 -0500483 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500484 if test.damageFirstWrite {
485 connDamage = newDamageAdaptor(conn)
486 conn = connDamage
487 }
488
David Benjamin6fd297b2014-08-11 18:43:38 -0400489 if test.sendPrefix != "" {
490 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
491 return err
492 }
David Benjamin98e882e2014-08-08 13:24:34 -0400493 }
494
David Benjamin1d5c83e2014-07-22 19:20:02 -0400495 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400496 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400497 if test.protocol == dtls {
498 tlsConn = DTLSServer(conn, config)
499 } else {
500 tlsConn = Server(conn, config)
501 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400502 } else {
503 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400504 if test.protocol == dtls {
505 tlsConn = DTLSClient(conn, config)
506 } else {
507 tlsConn = Client(conn, config)
508 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400509 }
David Benjamin30789da2015-08-29 22:56:45 -0400510 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400511
Adam Langley95c29f32014-06-20 12:00:00 -0700512 if err := tlsConn.Handshake(); err != nil {
513 return err
514 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700515
David Benjamin01fe8202014-09-24 15:21:44 -0400516 // TODO(davidben): move all per-connection expectations into a dedicated
517 // expectations struct that can be specified separately for the two
518 // legs.
519 expectedVersion := test.expectedVersion
520 if isResume && test.expectedResumeVersion != 0 {
521 expectedVersion = test.expectedResumeVersion
522 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700523 connState := tlsConn.ConnectionState()
524 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400525 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400526 }
527
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400529 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
530 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700531 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
532 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
533 }
David Benjamin90da8c82015-04-20 14:57:57 -0400534
David Benjamina08e49d2014-08-24 01:46:07 -0400535 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700536 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400537 if channelID == nil {
538 return fmt.Errorf("no channel ID negotiated")
539 }
540 if channelID.Curve != channelIDKey.Curve ||
541 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
542 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
543 return fmt.Errorf("incorrect channel ID")
544 }
545 }
546
David Benjaminae2888f2014-09-06 12:58:58 -0400547 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700548 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400549 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
550 }
551 }
552
David Benjaminc7ce9772015-10-09 19:32:41 -0400553 if test.expectNoNextProto {
554 if actual := connState.NegotiatedProtocol; actual != "" {
555 return fmt.Errorf("got unexpected next proto %s", actual)
556 }
557 }
558
David Benjaminfc7b0862014-09-06 13:21:53 -0400559 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700560 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400561 return fmt.Errorf("next proto type mismatch")
562 }
563 }
564
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700565 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500566 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
567 }
568
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100569 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300570 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100571 }
572
Paul Lietar4fac72e2015-09-09 13:44:55 +0100573 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
574 return fmt.Errorf("SCT list mismatch")
575 }
576
Nick Harper60edffd2016-06-21 15:19:24 -0700577 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
578 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400579 }
580
Steven Valdez5440fe02016-07-18 12:40:30 -0400581 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
582 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
583 }
584
David Benjaminc565ebb2015-04-03 04:06:36 -0400585 if test.exportKeyingMaterial > 0 {
586 actual := make([]byte, test.exportKeyingMaterial)
587 if _, err := io.ReadFull(tlsConn, actual); err != nil {
588 return err
589 }
590 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
591 if err != nil {
592 return err
593 }
594 if !bytes.Equal(actual, expected) {
595 return fmt.Errorf("keying material mismatch")
596 }
597 }
598
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700599 if test.testTLSUnique {
600 var peersValue [12]byte
601 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
602 return err
603 }
604 expected := tlsConn.ConnectionState().TLSUnique
605 if !bytes.Equal(peersValue[:], expected) {
606 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
607 }
608 }
609
David Benjamine58c4f52014-08-24 03:47:07 -0400610 if test.shimWritesFirst {
611 var buf [5]byte
612 _, err := io.ReadFull(tlsConn, buf[:])
613 if err != nil {
614 return err
615 }
616 if string(buf[:]) != "hello" {
617 return fmt.Errorf("bad initial message")
618 }
619 }
620
Steven Valdez32635b82016-08-16 11:25:03 -0400621 for i := 0; i < test.sendKeyUpdates; i++ {
622 tlsConn.SendKeyUpdate()
623 }
624
David Benjamina8ebe222015-06-06 03:04:39 -0400625 for i := 0; i < test.sendEmptyRecords; i++ {
626 tlsConn.Write(nil)
627 }
628
David Benjamin24f346d2015-06-06 03:28:08 -0400629 for i := 0; i < test.sendWarningAlerts; i++ {
630 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
631 }
632
David Benjamin47921102016-07-28 11:29:18 -0400633 if test.sendHalfHelloRequest {
634 tlsConn.SendHalfHelloRequest()
635 }
636
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400637 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700638 if test.renegotiateCiphers != nil {
639 config.CipherSuites = test.renegotiateCiphers
640 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400641 for i := 0; i < test.renegotiate; i++ {
642 if err := tlsConn.Renegotiate(); err != nil {
643 return err
644 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700645 }
646 } else if test.renegotiateCiphers != nil {
647 panic("renegotiateCiphers without renegotiate")
648 }
649
David Benjamin5fa3eba2015-01-22 16:35:40 -0500650 if test.damageFirstWrite {
651 connDamage.setDamage(true)
652 tlsConn.Write([]byte("DAMAGED WRITE"))
653 connDamage.setDamage(false)
654 }
655
David Benjamin8e6db492015-07-25 18:29:23 -0400656 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700657 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400658 if test.protocol == dtls {
659 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
660 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700661 // Read until EOF.
662 _, err := io.Copy(ioutil.Discard, tlsConn)
663 return err
664 }
David Benjamin4417d052015-04-05 04:17:25 -0400665 if messageLen == 0 {
666 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700667 }
Adam Langley95c29f32014-06-20 12:00:00 -0700668
David Benjamin8e6db492015-07-25 18:29:23 -0400669 messageCount := test.messageCount
670 if messageCount == 0 {
671 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400672 }
673
David Benjamin8e6db492015-07-25 18:29:23 -0400674 for j := 0; j < messageCount; j++ {
675 testMessage := make([]byte, messageLen)
676 for i := range testMessage {
677 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400678 }
David Benjamin8e6db492015-07-25 18:29:23 -0400679 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700680
Steven Valdez32635b82016-08-16 11:25:03 -0400681 for i := 0; i < test.sendKeyUpdates; i++ {
682 tlsConn.SendKeyUpdate()
683 }
684
David Benjamin8e6db492015-07-25 18:29:23 -0400685 for i := 0; i < test.sendEmptyRecords; i++ {
686 tlsConn.Write(nil)
687 }
688
689 for i := 0; i < test.sendWarningAlerts; i++ {
690 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
691 }
692
David Benjamin4f75aaf2015-09-01 16:53:10 -0400693 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400694 // The shim will not respond.
695 continue
696 }
697
David Benjamin8e6db492015-07-25 18:29:23 -0400698 buf := make([]byte, len(testMessage))
699 if test.protocol == dtls {
700 bufTmp := make([]byte, len(buf)+1)
701 n, err := tlsConn.Read(bufTmp)
702 if err != nil {
703 return err
704 }
705 if n != len(buf) {
706 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
707 }
708 copy(buf, bufTmp)
709 } else {
710 _, err := io.ReadFull(tlsConn, buf)
711 if err != nil {
712 return err
713 }
714 }
715
716 for i, v := range buf {
717 if v != testMessage[i]^0xff {
718 return fmt.Errorf("bad reply contents at byte %d", i)
719 }
Adam Langley95c29f32014-06-20 12:00:00 -0700720 }
721 }
722
723 return nil
724}
725
David Benjamin325b5c32014-07-01 19:40:31 -0400726func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400727 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700728 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400729 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700730 }
David Benjamin325b5c32014-07-01 19:40:31 -0400731 valgrindArgs = append(valgrindArgs, path)
732 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700733
David Benjamin325b5c32014-07-01 19:40:31 -0400734 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700735}
736
David Benjamin325b5c32014-07-01 19:40:31 -0400737func gdbOf(path string, args ...string) *exec.Cmd {
738 xtermArgs := []string{"-e", "gdb", "--args"}
739 xtermArgs = append(xtermArgs, path)
740 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700741
David Benjamin325b5c32014-07-01 19:40:31 -0400742 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700743}
744
David Benjamind16bf342015-12-18 00:53:12 -0500745func lldbOf(path string, args ...string) *exec.Cmd {
746 xtermArgs := []string{"-e", "lldb", "--"}
747 xtermArgs = append(xtermArgs, path)
748 xtermArgs = append(xtermArgs, args...)
749
750 return exec.Command("xterm", xtermArgs...)
751}
752
EKR842ae6c2016-07-27 09:22:05 +0200753var (
754 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
755 errUnimplemented = errors.New("child process does not implement needed flags")
756)
Adam Langley69a01602014-11-17 17:26:55 -0800757
David Benjamin87c8a642015-02-21 01:54:29 -0500758// accept accepts a connection from listener, unless waitChan signals a process
759// exit first.
760func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
761 type connOrError struct {
762 conn net.Conn
763 err error
764 }
765 connChan := make(chan connOrError, 1)
766 go func() {
767 conn, err := listener.Accept()
768 connChan <- connOrError{conn, err}
769 close(connChan)
770 }()
771 select {
772 case result := <-connChan:
773 return result.conn, result.err
774 case childErr := <-waitChan:
775 waitChan <- childErr
776 return nil, fmt.Errorf("child exited early: %s", childErr)
777 }
778}
779
EKRf71d7ed2016-08-06 13:25:12 -0700780func translateExpectedError(errorStr string) string {
781 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
782 return translated
783 }
784
785 if *looseErrors {
786 return ""
787 }
788
789 return errorStr
790}
791
Adam Langley7c803a62015-06-15 15:35:05 -0700792func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Adam Langley38311732014-10-16 19:04:35 -0700793 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
794 panic("Error expected without shouldFail in " + test.name)
795 }
796
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700797 if test.expectResumeRejected && !test.resumeSession {
798 panic("expectResumeRejected without resumeSession in " + test.name)
799 }
800
David Benjamin87c8a642015-02-21 01:54:29 -0500801 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
802 if err != nil {
803 panic(err)
804 }
805 defer func() {
806 if listener != nil {
807 listener.Close()
808 }
809 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700810
David Benjamin87c8a642015-02-21 01:54:29 -0500811 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400812 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400813 flags = append(flags, "-server")
814
David Benjamin025b3d32014-07-01 19:53:04 -0400815 flags = append(flags, "-key-file")
816 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700817 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400818 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700819 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400820 }
821
822 flags = append(flags, "-cert-file")
823 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828 }
David Benjamin5a593af2014-08-11 19:51:50 -0400829
David Benjamin6fd297b2014-08-11 18:43:38 -0400830 if test.protocol == dtls {
831 flags = append(flags, "-dtls")
832 }
833
David Benjamin46662482016-08-17 00:51:00 -0400834 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400835 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400836 resumeCount++
837 if test.resumeRenewedSession {
838 resumeCount++
839 }
840 }
841
842 if resumeCount > 0 {
843 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400844 }
845
David Benjamine58c4f52014-08-24 03:47:07 -0400846 if test.shimWritesFirst {
847 flags = append(flags, "-shim-writes-first")
848 }
849
David Benjamin30789da2015-08-29 22:56:45 -0400850 if test.shimShutsDown {
851 flags = append(flags, "-shim-shuts-down")
852 }
853
David Benjaminc565ebb2015-04-03 04:06:36 -0400854 if test.exportKeyingMaterial > 0 {
855 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
856 flags = append(flags, "-export-label", test.exportLabel)
857 flags = append(flags, "-export-context", test.exportContext)
858 if test.useExportContext {
859 flags = append(flags, "-use-export-context")
860 }
861 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700862 if test.expectResumeRejected {
863 flags = append(flags, "-expect-session-miss")
864 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400865
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700866 if test.testTLSUnique {
867 flags = append(flags, "-tls-unique")
868 }
869
David Benjamin025b3d32014-07-01 19:53:04 -0400870 flags = append(flags, test.flags...)
871
872 var shim *exec.Cmd
873 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700874 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700875 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700876 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500877 } else if *useLLDB {
878 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400879 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700880 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400881 }
David Benjamin025b3d32014-07-01 19:53:04 -0400882 shim.Stdin = os.Stdin
883 var stdoutBuf, stderrBuf bytes.Buffer
884 shim.Stdout = &stdoutBuf
885 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800886 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500887 shim.Env = os.Environ()
888 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800889 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400890 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800891 }
892 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
893 }
David Benjamin025b3d32014-07-01 19:53:04 -0400894
895 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700896 panic(err)
897 }
David Benjamin87c8a642015-02-21 01:54:29 -0500898 waitChan := make(chan error, 1)
899 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700900
901 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700902
David Benjamin7a4aaa42016-09-20 17:58:14 -0400903 if *deterministic {
904 config.Rand = &deterministicRand{}
905 }
906
David Benjamin87c8a642015-02-21 01:54:29 -0500907 conn, err := acceptOrWait(listener, waitChan)
908 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400909 err = doExchange(test, &config, conn, false /* not a resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500910 conn.Close()
911 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500912
David Benjamin46662482016-08-17 00:51:00 -0400913 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400914 var resumeConfig Config
915 if test.resumeConfig != nil {
916 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400917 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500918 resumeConfig.SessionTicketKey = config.SessionTicketKey
919 resumeConfig.ClientSessionCache = config.ClientSessionCache
920 resumeConfig.ServerSessionCache = config.ServerSessionCache
921 }
David Benjamin2e045a92016-06-08 13:09:56 -0400922 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400923 } else {
924 resumeConfig = config
925 }
David Benjamin87c8a642015-02-21 01:54:29 -0500926 var connResume net.Conn
927 connResume, err = acceptOrWait(listener, waitChan)
928 if err == nil {
David Benjamin8e6db492015-07-25 18:29:23 -0400929 err = doExchange(test, &resumeConfig, connResume, true /* resumption */)
David Benjamin87c8a642015-02-21 01:54:29 -0500930 connResume.Close()
931 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400932 }
933
David Benjamin87c8a642015-02-21 01:54:29 -0500934 // Close the listener now. This is to avoid hangs should the shim try to
935 // open more connections than expected.
936 listener.Close()
937 listener = nil
938
939 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400940 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800941 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200942 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
943 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800944 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200945 case 89:
946 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400947 case 99:
948 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800949 }
950 }
Adam Langley95c29f32014-06-20 12:00:00 -0700951
David Benjamin9bea3492016-03-02 10:59:16 -0500952 // Account for Windows line endings.
953 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
954 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500955
956 // Separate the errors from the shim and those from tools like
957 // AddressSanitizer.
958 var extraStderr string
959 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
960 stderr = stderrParts[0]
961 extraStderr = stderrParts[1]
962 }
963
Adam Langley95c29f32014-06-20 12:00:00 -0700964 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700965 expectedError := translateExpectedError(test.expectedError)
966 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200967
Adam Langleyac61fa32014-06-23 12:03:11 -0700968 localError := "none"
969 if err != nil {
970 localError = err.Error()
971 }
972 if len(test.expectedLocalError) != 0 {
973 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
974 }
Adam Langley95c29f32014-06-20 12:00:00 -0700975
976 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700977 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700978 if childErr != nil {
979 childError = childErr.Error()
980 }
981
982 var msg string
983 switch {
984 case failed && !test.shouldFail:
985 msg = "unexpected failure"
986 case !failed && test.shouldFail:
987 msg = "unexpected success"
988 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700989 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700990 default:
991 panic("internal error")
992 }
993
David Benjamin9aafb642016-09-20 19:36:53 -0400994 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 -0700995 }
996
David Benjamind2ba8892016-09-20 19:41:04 -0400997 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -0500998 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -0700999 }
1000
David Benjamind2ba8892016-09-20 19:41:04 -04001001 if *useValgrind && isValgrindError {
1002 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1003 }
1004
Adam Langley95c29f32014-06-20 12:00:00 -07001005 return nil
1006}
1007
1008var tlsVersions = []struct {
1009 name string
1010 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001011 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001012 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001013}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001014 {"SSL3", VersionSSL30, "-no-ssl3", false},
1015 {"TLS1", VersionTLS10, "-no-tls1", true},
1016 {"TLS11", VersionTLS11, "-no-tls11", false},
1017 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001018 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001019}
1020
1021var testCipherSuites = []struct {
1022 name string
1023 id uint16
1024}{
1025 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001026 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001027 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001028 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001029 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001030 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001031 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001032 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1033 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001034 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001035 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1036 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001037 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001038 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1039 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001040 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1041 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001042 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001043 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001044 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001045 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001046 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001047 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001048 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001049 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001050 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001051 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001052 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001053 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001054 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1055 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1056 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1057 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001058 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1059 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001060 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1061 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001062 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez3084e7b2016-06-02 12:07:20 -04001063 {"ECDHE-PSK-AES128-GCM-SHA256", TLS_ECDHE_PSK_WITH_AES_128_GCM_SHA256},
1064 {"ECDHE-PSK-AES256-GCM-SHA384", TLS_ECDHE_PSK_WITH_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001065 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001066}
1067
David Benjamin8b8c0062014-11-23 02:47:52 -05001068func hasComponent(suiteName, component string) bool {
1069 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1070}
1071
David Benjaminf7768e42014-08-31 02:06:47 -04001072func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001073 return hasComponent(suiteName, "GCM") ||
1074 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001075 hasComponent(suiteName, "SHA384") ||
1076 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001077}
1078
Nick Harper1fd39d82016-06-14 18:14:35 -07001079func isTLS13Suite(suiteName string) bool {
David Benjamin54c217c2016-07-13 12:35:25 -04001080 // Only AEADs.
1081 if !hasComponent(suiteName, "GCM") && !hasComponent(suiteName, "POLY1305") {
1082 return false
1083 }
1084 // No old CHACHA20_POLY1305.
1085 if hasComponent(suiteName, "CHACHA20-POLY1305-OLD") {
1086 return false
1087 }
1088 // Must have ECDHE.
1089 // TODO(davidben,svaldez): Add pure PSK support.
1090 if !hasComponent(suiteName, "ECDHE") {
1091 return false
1092 }
1093 // TODO(davidben,svaldez): Add PSK support.
1094 if hasComponent(suiteName, "PSK") {
1095 return false
1096 }
1097 return true
Nick Harper1fd39d82016-06-14 18:14:35 -07001098}
1099
David Benjamin8b8c0062014-11-23 02:47:52 -05001100func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001101 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001102}
1103
Adam Langleya7997f12015-05-14 17:38:50 -07001104func bigFromHex(hex string) *big.Int {
1105 ret, ok := new(big.Int).SetString(hex, 16)
1106 if !ok {
1107 panic("failed to parse hex number 0x" + hex)
1108 }
1109 return ret
1110}
1111
Adam Langley7c803a62015-06-15 15:35:05 -07001112func addBasicTests() {
1113 basicTests := []testCase{
1114 {
Adam Langley7c803a62015-06-15 15:35:05 -07001115 name: "NoFallbackSCSV",
1116 config: Config{
1117 Bugs: ProtocolBugs{
1118 FailIfNotFallbackSCSV: true,
1119 },
1120 },
1121 shouldFail: true,
1122 expectedLocalError: "no fallback SCSV found",
1123 },
1124 {
1125 name: "SendFallbackSCSV",
1126 config: Config{
1127 Bugs: ProtocolBugs{
1128 FailIfNotFallbackSCSV: true,
1129 },
1130 },
1131 flags: []string{"-fallback-scsv"},
1132 },
1133 {
1134 name: "ClientCertificateTypes",
1135 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001136 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001137 ClientAuth: RequestClientCert,
1138 ClientCertificateTypes: []byte{
1139 CertTypeDSSSign,
1140 CertTypeRSASign,
1141 CertTypeECDSASign,
1142 },
1143 },
1144 flags: []string{
1145 "-expect-certificate-types",
1146 base64.StdEncoding.EncodeToString([]byte{
1147 CertTypeDSSSign,
1148 CertTypeRSASign,
1149 CertTypeECDSASign,
1150 }),
1151 },
1152 },
1153 {
Adam Langley7c803a62015-06-15 15:35:05 -07001154 name: "UnauthenticatedECDH",
1155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001156 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1158 Bugs: ProtocolBugs{
1159 UnauthenticatedECDH: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedError: ":UNEXPECTED_MESSAGE:",
1164 },
1165 {
1166 name: "SkipCertificateStatus",
1167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001168 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1170 Bugs: ProtocolBugs{
1171 SkipCertificateStatus: true,
1172 },
1173 },
1174 flags: []string{
1175 "-enable-ocsp-stapling",
1176 },
1177 },
1178 {
1179 name: "SkipServerKeyExchange",
1180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001181 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001182 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1183 Bugs: ProtocolBugs{
1184 SkipServerKeyExchange: true,
1185 },
1186 },
1187 shouldFail: true,
1188 expectedError: ":UNEXPECTED_MESSAGE:",
1189 },
1190 {
Adam Langley7c803a62015-06-15 15:35:05 -07001191 testType: serverTest,
1192 name: "Alert",
1193 config: Config{
1194 Bugs: ProtocolBugs{
1195 SendSpuriousAlert: alertRecordOverflow,
1196 },
1197 },
1198 shouldFail: true,
1199 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1200 },
1201 {
1202 protocol: dtls,
1203 testType: serverTest,
1204 name: "Alert-DTLS",
1205 config: Config{
1206 Bugs: ProtocolBugs{
1207 SendSpuriousAlert: alertRecordOverflow,
1208 },
1209 },
1210 shouldFail: true,
1211 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1212 },
1213 {
1214 testType: serverTest,
1215 name: "FragmentAlert",
1216 config: Config{
1217 Bugs: ProtocolBugs{
1218 FragmentAlert: true,
1219 SendSpuriousAlert: alertRecordOverflow,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":BAD_ALERT:",
1224 },
1225 {
1226 protocol: dtls,
1227 testType: serverTest,
1228 name: "FragmentAlert-DTLS",
1229 config: Config{
1230 Bugs: ProtocolBugs{
1231 FragmentAlert: true,
1232 SendSpuriousAlert: alertRecordOverflow,
1233 },
1234 },
1235 shouldFail: true,
1236 expectedError: ":BAD_ALERT:",
1237 },
1238 {
1239 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001240 name: "DoubleAlert",
1241 config: Config{
1242 Bugs: ProtocolBugs{
1243 DoubleAlert: true,
1244 SendSpuriousAlert: alertRecordOverflow,
1245 },
1246 },
1247 shouldFail: true,
1248 expectedError: ":BAD_ALERT:",
1249 },
1250 {
1251 protocol: dtls,
1252 testType: serverTest,
1253 name: "DoubleAlert-DTLS",
1254 config: Config{
1255 Bugs: ProtocolBugs{
1256 DoubleAlert: true,
1257 SendSpuriousAlert: alertRecordOverflow,
1258 },
1259 },
1260 shouldFail: true,
1261 expectedError: ":BAD_ALERT:",
1262 },
1263 {
Adam Langley7c803a62015-06-15 15:35:05 -07001264 name: "SkipNewSessionTicket",
1265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001266 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001267 Bugs: ProtocolBugs{
1268 SkipNewSessionTicket: true,
1269 },
1270 },
1271 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001272 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001273 },
1274 {
1275 testType: serverTest,
1276 name: "FallbackSCSV",
1277 config: Config{
1278 MaxVersion: VersionTLS11,
1279 Bugs: ProtocolBugs{
1280 SendFallbackSCSV: true,
1281 },
1282 },
1283 shouldFail: true,
1284 expectedError: ":INAPPROPRIATE_FALLBACK:",
1285 },
1286 {
1287 testType: serverTest,
1288 name: "FallbackSCSV-VersionMatch",
1289 config: Config{
1290 Bugs: ProtocolBugs{
1291 SendFallbackSCSV: true,
1292 },
1293 },
1294 },
1295 {
1296 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001297 name: "FallbackSCSV-VersionMatch-TLS12",
1298 config: Config{
1299 MaxVersion: VersionTLS12,
1300 Bugs: ProtocolBugs{
1301 SendFallbackSCSV: true,
1302 },
1303 },
1304 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1305 },
1306 {
1307 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001308 name: "FragmentedClientVersion",
1309 config: Config{
1310 Bugs: ProtocolBugs{
1311 MaxHandshakeRecordLength: 1,
1312 FragmentClientVersion: true,
1313 },
1314 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001315 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001316 },
1317 {
Adam Langley7c803a62015-06-15 15:35:05 -07001318 testType: serverTest,
1319 name: "HttpGET",
1320 sendPrefix: "GET / HTTP/1.0\n",
1321 shouldFail: true,
1322 expectedError: ":HTTP_REQUEST:",
1323 },
1324 {
1325 testType: serverTest,
1326 name: "HttpPOST",
1327 sendPrefix: "POST / HTTP/1.0\n",
1328 shouldFail: true,
1329 expectedError: ":HTTP_REQUEST:",
1330 },
1331 {
1332 testType: serverTest,
1333 name: "HttpHEAD",
1334 sendPrefix: "HEAD / HTTP/1.0\n",
1335 shouldFail: true,
1336 expectedError: ":HTTP_REQUEST:",
1337 },
1338 {
1339 testType: serverTest,
1340 name: "HttpPUT",
1341 sendPrefix: "PUT / HTTP/1.0\n",
1342 shouldFail: true,
1343 expectedError: ":HTTP_REQUEST:",
1344 },
1345 {
1346 testType: serverTest,
1347 name: "HttpCONNECT",
1348 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1349 shouldFail: true,
1350 expectedError: ":HTTPS_PROXY_REQUEST:",
1351 },
1352 {
1353 testType: serverTest,
1354 name: "Garbage",
1355 sendPrefix: "blah",
1356 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001357 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001358 },
1359 {
Adam Langley7c803a62015-06-15 15:35:05 -07001360 name: "RSAEphemeralKey",
1361 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001362 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001363 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1364 Bugs: ProtocolBugs{
1365 RSAEphemeralKey: true,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":UNEXPECTED_MESSAGE:",
1370 },
1371 {
1372 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001373 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001374 shouldFail: true,
1375 expectedError: ":WRONG_SSL_VERSION:",
1376 },
1377 {
1378 protocol: dtls,
1379 name: "DisableEverything-DTLS",
1380 flags: []string{"-no-tls12", "-no-tls1"},
1381 shouldFail: true,
1382 expectedError: ":WRONG_SSL_VERSION:",
1383 },
1384 {
Adam Langley7c803a62015-06-15 15:35:05 -07001385 protocol: dtls,
1386 testType: serverTest,
1387 name: "MTU",
1388 config: Config{
1389 Bugs: ProtocolBugs{
1390 MaxPacketLength: 256,
1391 },
1392 },
1393 flags: []string{"-mtu", "256"},
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "MTUExceeded",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 MaxPacketLength: 255,
1402 },
1403 },
1404 flags: []string{"-mtu", "256"},
1405 shouldFail: true,
1406 expectedLocalError: "dtls: exceeded maximum packet length",
1407 },
1408 {
1409 name: "CertMismatchRSA",
1410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001411 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001412 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001413 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001414 Bugs: ProtocolBugs{
1415 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1416 },
1417 },
1418 shouldFail: true,
1419 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1420 },
1421 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001422 name: "CertMismatchRSA-TLS13",
1423 config: Config{
1424 MaxVersion: VersionTLS13,
1425 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1426 Certificates: []Certificate{ecdsaP256Certificate},
1427 Bugs: ProtocolBugs{
1428 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1429 },
1430 },
1431 shouldFail: true,
1432 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1433 },
1434 {
Adam Langley7c803a62015-06-15 15:35:05 -07001435 name: "CertMismatchECDSA",
1436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001437 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001438 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001439 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001440 Bugs: ProtocolBugs{
1441 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1442 },
1443 },
1444 shouldFail: true,
1445 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1446 },
1447 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001448 name: "CertMismatchECDSA-TLS13",
1449 config: Config{
1450 MaxVersion: VersionTLS13,
1451 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1452 Certificates: []Certificate{rsaCertificate},
1453 Bugs: ProtocolBugs{
1454 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1455 },
1456 },
1457 shouldFail: true,
1458 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1459 },
1460 {
Adam Langley7c803a62015-06-15 15:35:05 -07001461 name: "EmptyCertificateList",
1462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001463 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001464 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1465 Bugs: ProtocolBugs{
1466 EmptyCertificateList: true,
1467 },
1468 },
1469 shouldFail: true,
1470 expectedError: ":DECODE_ERROR:",
1471 },
1472 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001473 name: "EmptyCertificateList-TLS13",
1474 config: Config{
1475 MaxVersion: VersionTLS13,
1476 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1477 Bugs: ProtocolBugs{
1478 EmptyCertificateList: true,
1479 },
1480 },
1481 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001482 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001483 },
1484 {
Adam Langley7c803a62015-06-15 15:35:05 -07001485 name: "TLSFatalBadPackets",
1486 damageFirstWrite: true,
1487 shouldFail: true,
1488 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1489 },
1490 {
1491 protocol: dtls,
1492 name: "DTLSIgnoreBadPackets",
1493 damageFirstWrite: true,
1494 },
1495 {
1496 protocol: dtls,
1497 name: "DTLSIgnoreBadPackets-Async",
1498 damageFirstWrite: true,
1499 flags: []string{"-async"},
1500 },
1501 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001502 name: "AppDataBeforeHandshake",
1503 config: Config{
1504 Bugs: ProtocolBugs{
1505 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1506 },
1507 },
1508 shouldFail: true,
1509 expectedError: ":UNEXPECTED_RECORD:",
1510 },
1511 {
1512 name: "AppDataBeforeHandshake-Empty",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 AppDataBeforeHandshake: []byte{},
1516 },
1517 },
1518 shouldFail: true,
1519 expectedError: ":UNEXPECTED_RECORD:",
1520 },
1521 {
1522 protocol: dtls,
1523 name: "AppDataBeforeHandshake-DTLS",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_RECORD:",
1531 },
1532 {
1533 protocol: dtls,
1534 name: "AppDataBeforeHandshake-DTLS-Empty",
1535 config: Config{
1536 Bugs: ProtocolBugs{
1537 AppDataBeforeHandshake: []byte{},
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_RECORD:",
1542 },
1543 {
Adam Langley7c803a62015-06-15 15:35:05 -07001544 name: "AppDataAfterChangeCipherSpec",
1545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001546 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001547 Bugs: ProtocolBugs{
1548 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1549 },
1550 },
1551 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001552 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001553 },
1554 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001555 name: "AppDataAfterChangeCipherSpec-Empty",
1556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001557 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001558 Bugs: ProtocolBugs{
1559 AppDataAfterChangeCipherSpec: []byte{},
1560 },
1561 },
1562 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001563 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001564 },
1565 {
Adam Langley7c803a62015-06-15 15:35:05 -07001566 protocol: dtls,
1567 name: "AppDataAfterChangeCipherSpec-DTLS",
1568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001569 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001570 Bugs: ProtocolBugs{
1571 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1572 },
1573 },
1574 // BoringSSL's DTLS implementation will drop the out-of-order
1575 // application data.
1576 },
1577 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001578 protocol: dtls,
1579 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001581 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001582 Bugs: ProtocolBugs{
1583 AppDataAfterChangeCipherSpec: []byte{},
1584 },
1585 },
1586 // BoringSSL's DTLS implementation will drop the out-of-order
1587 // application data.
1588 },
1589 {
Adam Langley7c803a62015-06-15 15:35:05 -07001590 name: "AlertAfterChangeCipherSpec",
1591 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001592 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001593 Bugs: ProtocolBugs{
1594 AlertAfterChangeCipherSpec: alertRecordOverflow,
1595 },
1596 },
1597 shouldFail: true,
1598 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1599 },
1600 {
1601 protocol: dtls,
1602 name: "AlertAfterChangeCipherSpec-DTLS",
1603 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001604 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001605 Bugs: ProtocolBugs{
1606 AlertAfterChangeCipherSpec: alertRecordOverflow,
1607 },
1608 },
1609 shouldFail: true,
1610 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1611 },
1612 {
1613 protocol: dtls,
1614 name: "ReorderHandshakeFragments-Small-DTLS",
1615 config: Config{
1616 Bugs: ProtocolBugs{
1617 ReorderHandshakeFragments: true,
1618 // Small enough that every handshake message is
1619 // fragmented.
1620 MaxHandshakeRecordLength: 2,
1621 },
1622 },
1623 },
1624 {
1625 protocol: dtls,
1626 name: "ReorderHandshakeFragments-Large-DTLS",
1627 config: Config{
1628 Bugs: ProtocolBugs{
1629 ReorderHandshakeFragments: true,
1630 // Large enough that no handshake message is
1631 // fragmented.
1632 MaxHandshakeRecordLength: 2048,
1633 },
1634 },
1635 },
1636 {
1637 protocol: dtls,
1638 name: "MixCompleteMessageWithFragments-DTLS",
1639 config: Config{
1640 Bugs: ProtocolBugs{
1641 ReorderHandshakeFragments: true,
1642 MixCompleteMessageWithFragments: true,
1643 MaxHandshakeRecordLength: 2,
1644 },
1645 },
1646 },
1647 {
1648 name: "SendInvalidRecordType",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SendInvalidRecordType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_RECORD:",
1656 },
1657 {
1658 protocol: dtls,
1659 name: "SendInvalidRecordType-DTLS",
1660 config: Config{
1661 Bugs: ProtocolBugs{
1662 SendInvalidRecordType: true,
1663 },
1664 },
1665 shouldFail: true,
1666 expectedError: ":UNEXPECTED_RECORD:",
1667 },
1668 {
1669 name: "FalseStart-SkipServerSecondLeg",
1670 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001671 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1673 NextProtos: []string{"foo"},
1674 Bugs: ProtocolBugs{
1675 SkipNewSessionTicket: true,
1676 SkipChangeCipherSpec: true,
1677 SkipFinished: true,
1678 ExpectFalseStart: true,
1679 },
1680 },
1681 flags: []string{
1682 "-false-start",
1683 "-handshake-never-done",
1684 "-advertise-alpn", "\x03foo",
1685 },
1686 shimWritesFirst: true,
1687 shouldFail: true,
1688 expectedError: ":UNEXPECTED_RECORD:",
1689 },
1690 {
1691 name: "FalseStart-SkipServerSecondLeg-Implicit",
1692 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001693 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1695 NextProtos: []string{"foo"},
1696 Bugs: ProtocolBugs{
1697 SkipNewSessionTicket: true,
1698 SkipChangeCipherSpec: true,
1699 SkipFinished: true,
1700 },
1701 },
1702 flags: []string{
1703 "-implicit-handshake",
1704 "-false-start",
1705 "-handshake-never-done",
1706 "-advertise-alpn", "\x03foo",
1707 },
1708 shouldFail: true,
1709 expectedError: ":UNEXPECTED_RECORD:",
1710 },
1711 {
1712 testType: serverTest,
1713 name: "FailEarlyCallback",
1714 flags: []string{"-fail-early-callback"},
1715 shouldFail: true,
1716 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001717 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001718 },
1719 {
Adam Langley7c803a62015-06-15 15:35:05 -07001720 protocol: dtls,
1721 name: "FragmentMessageTypeMismatch-DTLS",
1722 config: Config{
1723 Bugs: ProtocolBugs{
1724 MaxHandshakeRecordLength: 2,
1725 FragmentMessageTypeMismatch: true,
1726 },
1727 },
1728 shouldFail: true,
1729 expectedError: ":FRAGMENT_MISMATCH:",
1730 },
1731 {
1732 protocol: dtls,
1733 name: "FragmentMessageLengthMismatch-DTLS",
1734 config: Config{
1735 Bugs: ProtocolBugs{
1736 MaxHandshakeRecordLength: 2,
1737 FragmentMessageLengthMismatch: true,
1738 },
1739 },
1740 shouldFail: true,
1741 expectedError: ":FRAGMENT_MISMATCH:",
1742 },
1743 {
1744 protocol: dtls,
1745 name: "SplitFragments-Header-DTLS",
1746 config: Config{
1747 Bugs: ProtocolBugs{
1748 SplitFragments: 2,
1749 },
1750 },
1751 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001752 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001753 },
1754 {
1755 protocol: dtls,
1756 name: "SplitFragments-Boundary-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 SplitFragments: dtlsRecordHeaderLen,
1760 },
1761 },
1762 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001763 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001764 },
1765 {
1766 protocol: dtls,
1767 name: "SplitFragments-Body-DTLS",
1768 config: Config{
1769 Bugs: ProtocolBugs{
1770 SplitFragments: dtlsRecordHeaderLen + 1,
1771 },
1772 },
1773 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001774 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001775 },
1776 {
1777 protocol: dtls,
1778 name: "SendEmptyFragments-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 SendEmptyFragments: true,
1782 },
1783 },
1784 },
1785 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001786 name: "BadFinished-Client",
1787 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001788 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001789 Bugs: ProtocolBugs{
1790 BadFinished: true,
1791 },
1792 },
1793 shouldFail: true,
1794 expectedError: ":DIGEST_CHECK_FAILED:",
1795 },
1796 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001797 name: "BadFinished-Client-TLS13",
1798 config: Config{
1799 MaxVersion: VersionTLS13,
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 },
1803 },
1804 shouldFail: true,
1805 expectedError: ":DIGEST_CHECK_FAILED:",
1806 },
1807 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001808 testType: serverTest,
1809 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001811 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001812 Bugs: ProtocolBugs{
1813 BadFinished: true,
1814 },
1815 },
1816 shouldFail: true,
1817 expectedError: ":DIGEST_CHECK_FAILED:",
1818 },
1819 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001820 testType: serverTest,
1821 name: "BadFinished-Server-TLS13",
1822 config: Config{
1823 MaxVersion: VersionTLS13,
1824 Bugs: ProtocolBugs{
1825 BadFinished: true,
1826 },
1827 },
1828 shouldFail: true,
1829 expectedError: ":DIGEST_CHECK_FAILED:",
1830 },
1831 {
Adam Langley7c803a62015-06-15 15:35:05 -07001832 name: "FalseStart-BadFinished",
1833 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001834 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1836 NextProtos: []string{"foo"},
1837 Bugs: ProtocolBugs{
1838 BadFinished: true,
1839 ExpectFalseStart: true,
1840 },
1841 },
1842 flags: []string{
1843 "-false-start",
1844 "-handshake-never-done",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":DIGEST_CHECK_FAILED:",
1850 },
1851 {
1852 name: "NoFalseStart-NoALPN",
1853 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001854 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001855 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1856 Bugs: ProtocolBugs{
1857 ExpectFalseStart: true,
1858 AlertBeforeFalseStartTest: alertAccessDenied,
1859 },
1860 },
1861 flags: []string{
1862 "-false-start",
1863 },
1864 shimWritesFirst: true,
1865 shouldFail: true,
1866 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1867 expectedLocalError: "tls: peer did not false start: EOF",
1868 },
1869 {
1870 name: "NoFalseStart-NoAEAD",
1871 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001872 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001873 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1874 NextProtos: []string{"foo"},
1875 Bugs: ProtocolBugs{
1876 ExpectFalseStart: true,
1877 AlertBeforeFalseStartTest: alertAccessDenied,
1878 },
1879 },
1880 flags: []string{
1881 "-false-start",
1882 "-advertise-alpn", "\x03foo",
1883 },
1884 shimWritesFirst: true,
1885 shouldFail: true,
1886 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1887 expectedLocalError: "tls: peer did not false start: EOF",
1888 },
1889 {
1890 name: "NoFalseStart-RSA",
1891 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001892 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001893 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1894 NextProtos: []string{"foo"},
1895 Bugs: ProtocolBugs{
1896 ExpectFalseStart: true,
1897 AlertBeforeFalseStartTest: alertAccessDenied,
1898 },
1899 },
1900 flags: []string{
1901 "-false-start",
1902 "-advertise-alpn", "\x03foo",
1903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
1906 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1907 expectedLocalError: "tls: peer did not false start: EOF",
1908 },
1909 {
1910 name: "NoFalseStart-DHE_RSA",
1911 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001912 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001913 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1914 NextProtos: []string{"foo"},
1915 Bugs: ProtocolBugs{
1916 ExpectFalseStart: true,
1917 AlertBeforeFalseStartTest: alertAccessDenied,
1918 },
1919 },
1920 flags: []string{
1921 "-false-start",
1922 "-advertise-alpn", "\x03foo",
1923 },
1924 shimWritesFirst: true,
1925 shouldFail: true,
1926 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1927 expectedLocalError: "tls: peer did not false start: EOF",
1928 },
1929 {
Adam Langley7c803a62015-06-15 15:35:05 -07001930 protocol: dtls,
1931 name: "SendSplitAlert-Sync",
1932 config: Config{
1933 Bugs: ProtocolBugs{
1934 SendSplitAlert: true,
1935 },
1936 },
1937 },
1938 {
1939 protocol: dtls,
1940 name: "SendSplitAlert-Async",
1941 config: Config{
1942 Bugs: ProtocolBugs{
1943 SendSplitAlert: true,
1944 },
1945 },
1946 flags: []string{"-async"},
1947 },
1948 {
1949 protocol: dtls,
1950 name: "PackDTLSHandshake",
1951 config: Config{
1952 Bugs: ProtocolBugs{
1953 MaxHandshakeRecordLength: 2,
1954 PackHandshakeFragments: 20,
1955 PackHandshakeRecords: 200,
1956 },
1957 },
1958 },
1959 {
Adam Langley7c803a62015-06-15 15:35:05 -07001960 name: "SendEmptyRecords-Pass",
1961 sendEmptyRecords: 32,
1962 },
1963 {
1964 name: "SendEmptyRecords",
1965 sendEmptyRecords: 33,
1966 shouldFail: true,
1967 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1968 },
1969 {
1970 name: "SendEmptyRecords-Async",
1971 sendEmptyRecords: 33,
1972 flags: []string{"-async"},
1973 shouldFail: true,
1974 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1975 },
1976 {
David Benjamine8e84b92016-08-03 15:39:47 -04001977 name: "SendWarningAlerts-Pass",
1978 config: Config{
1979 MaxVersion: VersionTLS12,
1980 },
Adam Langley7c803a62015-06-15 15:35:05 -07001981 sendWarningAlerts: 4,
1982 },
1983 {
David Benjamine8e84b92016-08-03 15:39:47 -04001984 protocol: dtls,
1985 name: "SendWarningAlerts-DTLS-Pass",
1986 config: Config{
1987 MaxVersion: VersionTLS12,
1988 },
Adam Langley7c803a62015-06-15 15:35:05 -07001989 sendWarningAlerts: 4,
1990 },
1991 {
David Benjamine8e84b92016-08-03 15:39:47 -04001992 name: "SendWarningAlerts-TLS13",
1993 config: Config{
1994 MaxVersion: VersionTLS13,
1995 },
1996 sendWarningAlerts: 4,
1997 shouldFail: true,
1998 expectedError: ":BAD_ALERT:",
1999 expectedLocalError: "remote error: error decoding message",
2000 },
2001 {
2002 name: "SendWarningAlerts",
2003 config: Config{
2004 MaxVersion: VersionTLS12,
2005 },
Adam Langley7c803a62015-06-15 15:35:05 -07002006 sendWarningAlerts: 5,
2007 shouldFail: true,
2008 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2009 },
2010 {
David Benjamine8e84b92016-08-03 15:39:47 -04002011 name: "SendWarningAlerts-Async",
2012 config: Config{
2013 MaxVersion: VersionTLS12,
2014 },
Adam Langley7c803a62015-06-15 15:35:05 -07002015 sendWarningAlerts: 5,
2016 flags: []string{"-async"},
2017 shouldFail: true,
2018 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2019 },
David Benjaminba4594a2015-06-18 18:36:15 -04002020 {
Steven Valdez32635b82016-08-16 11:25:03 -04002021 name: "SendKeyUpdates",
2022 config: Config{
2023 MaxVersion: VersionTLS13,
2024 },
2025 sendKeyUpdates: 33,
2026 shouldFail: true,
2027 expectedError: ":TOO_MANY_KEY_UPDATES:",
2028 },
2029 {
David Benjaminba4594a2015-06-18 18:36:15 -04002030 name: "EmptySessionID",
2031 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002032 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002033 SessionTicketsDisabled: true,
2034 },
2035 noSessionCache: true,
2036 flags: []string{"-expect-no-session"},
2037 },
David Benjamin30789da2015-08-29 22:56:45 -04002038 {
2039 name: "Unclean-Shutdown",
2040 config: Config{
2041 Bugs: ProtocolBugs{
2042 NoCloseNotify: true,
2043 ExpectCloseNotify: true,
2044 },
2045 },
2046 shimShutsDown: true,
2047 flags: []string{"-check-close-notify"},
2048 shouldFail: true,
2049 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2050 },
2051 {
2052 name: "Unclean-Shutdown-Ignored",
2053 config: Config{
2054 Bugs: ProtocolBugs{
2055 NoCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002060 {
David Benjaminfa214e42016-05-10 17:03:10 -04002061 name: "Unclean-Shutdown-Alert",
2062 config: Config{
2063 Bugs: ProtocolBugs{
2064 SendAlertOnShutdown: alertDecompressionFailure,
2065 ExpectCloseNotify: true,
2066 },
2067 },
2068 shimShutsDown: true,
2069 flags: []string{"-check-close-notify"},
2070 shouldFail: true,
2071 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2072 },
2073 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002074 name: "LargePlaintext",
2075 config: Config{
2076 Bugs: ProtocolBugs{
2077 SendLargeRecords: true,
2078 },
2079 },
2080 messageLen: maxPlaintext + 1,
2081 shouldFail: true,
2082 expectedError: ":DATA_LENGTH_TOO_LONG:",
2083 },
2084 {
2085 protocol: dtls,
2086 name: "LargePlaintext-DTLS",
2087 config: Config{
2088 Bugs: ProtocolBugs{
2089 SendLargeRecords: true,
2090 },
2091 },
2092 messageLen: maxPlaintext + 1,
2093 shouldFail: true,
2094 expectedError: ":DATA_LENGTH_TOO_LONG:",
2095 },
2096 {
2097 name: "LargeCiphertext",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 SendLargeRecords: true,
2101 },
2102 },
2103 messageLen: maxPlaintext * 2,
2104 shouldFail: true,
2105 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2106 },
2107 {
2108 protocol: dtls,
2109 name: "LargeCiphertext-DTLS",
2110 config: Config{
2111 Bugs: ProtocolBugs{
2112 SendLargeRecords: true,
2113 },
2114 },
2115 messageLen: maxPlaintext * 2,
2116 // Unlike the other four cases, DTLS drops records which
2117 // are invalid before authentication, so the connection
2118 // does not fail.
2119 expectMessageDropped: true,
2120 },
David Benjamindd6fed92015-10-23 17:41:12 -04002121 {
David Benjamin4c3ddf72016-06-29 18:13:53 -04002122 // In TLS 1.2 and below, empty NewSessionTicket messages
2123 // mean the server changed its mind on sending a ticket.
David Benjamindd6fed92015-10-23 17:41:12 -04002124 name: "SendEmptySessionTicket",
2125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002126 MaxVersion: VersionTLS12,
David Benjamindd6fed92015-10-23 17:41:12 -04002127 Bugs: ProtocolBugs{
2128 SendEmptySessionTicket: true,
2129 FailIfSessionOffered: true,
2130 },
2131 },
David Benjamin46662482016-08-17 00:51:00 -04002132 flags: []string{"-expect-no-session"},
David Benjamindd6fed92015-10-23 17:41:12 -04002133 },
David Benjamin99fdfb92015-11-02 12:11:35 -05002134 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002135 name: "BadHelloRequest-1",
2136 renegotiate: 1,
2137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002138 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002139 Bugs: ProtocolBugs{
2140 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2141 },
2142 },
2143 flags: []string{
2144 "-renegotiate-freely",
2145 "-expect-total-renegotiations", "1",
2146 },
2147 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002148 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002149 },
2150 {
2151 name: "BadHelloRequest-2",
2152 renegotiate: 1,
2153 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002154 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002155 Bugs: ProtocolBugs{
2156 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2157 },
2158 },
2159 flags: []string{
2160 "-renegotiate-freely",
2161 "-expect-total-renegotiations", "1",
2162 },
2163 shouldFail: true,
2164 expectedError: ":BAD_HELLO_REQUEST:",
2165 },
David Benjaminef1b0092015-11-21 14:05:44 -05002166 {
2167 testType: serverTest,
2168 name: "SupportTicketsWithSessionID",
2169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002170 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002171 SessionTicketsDisabled: true,
2172 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002173 resumeConfig: &Config{
2174 MaxVersion: VersionTLS12,
2175 },
David Benjaminef1b0092015-11-21 14:05:44 -05002176 resumeSession: true,
2177 },
David Benjamin02edcd02016-07-27 17:40:37 -04002178 {
2179 protocol: dtls,
2180 name: "DTLS-SendExtraFinished",
2181 config: Config{
2182 Bugs: ProtocolBugs{
2183 SendExtraFinished: true,
2184 },
2185 },
2186 shouldFail: true,
2187 expectedError: ":UNEXPECTED_RECORD:",
2188 },
2189 {
2190 protocol: dtls,
2191 name: "DTLS-SendExtraFinished-Reordered",
2192 config: Config{
2193 Bugs: ProtocolBugs{
2194 MaxHandshakeRecordLength: 2,
2195 ReorderHandshakeFragments: true,
2196 SendExtraFinished: true,
2197 },
2198 },
2199 shouldFail: true,
2200 expectedError: ":UNEXPECTED_RECORD:",
2201 },
David Benjamine97fb482016-07-29 09:23:07 -04002202 {
2203 testType: serverTest,
2204 name: "V2ClientHello-EmptyRecordPrefix",
2205 config: Config{
2206 // Choose a cipher suite that does not involve
2207 // elliptic curves, so no extensions are
2208 // involved.
2209 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002210 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002211 Bugs: ProtocolBugs{
2212 SendV2ClientHello: true,
2213 },
2214 },
2215 sendPrefix: string([]byte{
2216 byte(recordTypeHandshake),
2217 3, 1, // version
2218 0, 0, // length
2219 }),
2220 // A no-op empty record may not be sent before V2ClientHello.
2221 shouldFail: true,
2222 expectedError: ":WRONG_VERSION_NUMBER:",
2223 },
2224 {
2225 testType: serverTest,
2226 name: "V2ClientHello-WarningAlertPrefix",
2227 config: Config{
2228 // Choose a cipher suite that does not involve
2229 // elliptic curves, so no extensions are
2230 // involved.
2231 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002232 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002233 Bugs: ProtocolBugs{
2234 SendV2ClientHello: true,
2235 },
2236 },
2237 sendPrefix: string([]byte{
2238 byte(recordTypeAlert),
2239 3, 1, // version
2240 0, 2, // length
2241 alertLevelWarning, byte(alertDecompressionFailure),
2242 }),
2243 // A no-op warning alert may not be sent before V2ClientHello.
2244 shouldFail: true,
2245 expectedError: ":WRONG_VERSION_NUMBER:",
2246 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002247 {
2248 testType: clientTest,
2249 name: "KeyUpdate",
2250 config: Config{
2251 MaxVersion: VersionTLS13,
2252 Bugs: ProtocolBugs{
2253 SendKeyUpdateBeforeEveryAppDataRecord: true,
2254 },
2255 },
2256 },
David Benjaminabe94e32016-09-04 14:18:58 -04002257 {
2258 name: "SendSNIWarningAlert",
2259 config: Config{
2260 MaxVersion: VersionTLS12,
2261 Bugs: ProtocolBugs{
2262 SendSNIWarningAlert: true,
2263 },
2264 },
2265 },
David Benjaminc241d792016-09-09 10:34:20 -04002266 {
2267 testType: serverTest,
2268 name: "ExtraCompressionMethods-TLS12",
2269 config: Config{
2270 MaxVersion: VersionTLS12,
2271 Bugs: ProtocolBugs{
2272 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2273 },
2274 },
2275 },
2276 {
2277 testType: serverTest,
2278 name: "ExtraCompressionMethods-TLS13",
2279 config: Config{
2280 MaxVersion: VersionTLS13,
2281 Bugs: ProtocolBugs{
2282 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2283 },
2284 },
2285 shouldFail: true,
2286 expectedError: ":INVALID_COMPRESSION_LIST:",
2287 expectedLocalError: "remote error: illegal parameter",
2288 },
2289 {
2290 testType: serverTest,
2291 name: "NoNullCompression-TLS12",
2292 config: Config{
2293 MaxVersion: VersionTLS12,
2294 Bugs: ProtocolBugs{
2295 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2296 },
2297 },
2298 shouldFail: true,
2299 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2300 expectedLocalError: "remote error: illegal parameter",
2301 },
2302 {
2303 testType: serverTest,
2304 name: "NoNullCompression-TLS13",
2305 config: Config{
2306 MaxVersion: VersionTLS13,
2307 Bugs: ProtocolBugs{
2308 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2309 },
2310 },
2311 shouldFail: true,
2312 expectedError: ":INVALID_COMPRESSION_LIST:",
2313 expectedLocalError: "remote error: illegal parameter",
2314 },
Adam Langley7c803a62015-06-15 15:35:05 -07002315 }
Adam Langley7c803a62015-06-15 15:35:05 -07002316 testCases = append(testCases, basicTests...)
2317}
2318
Adam Langley95c29f32014-06-20 12:00:00 -07002319func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002320 const bogusCipher = 0xfe00
2321
Adam Langley95c29f32014-06-20 12:00:00 -07002322 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002323 const psk = "12345"
2324 const pskIdentity = "luggage combo"
2325
Adam Langley95c29f32014-06-20 12:00:00 -07002326 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002327 var certFile string
2328 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002329 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002330 cert = ecdsaP256Certificate
2331 certFile = ecdsaP256CertificateFile
2332 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002333 } else {
David Benjamin33863262016-07-08 17:20:12 -07002334 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002335 certFile = rsaCertificateFile
2336 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002337 }
2338
David Benjamin48cae082014-10-27 01:06:24 -04002339 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002340 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002341 flags = append(flags,
2342 "-psk", psk,
2343 "-psk-identity", pskIdentity)
2344 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002345 if hasComponent(suite.name, "NULL") {
2346 // NULL ciphers must be explicitly enabled.
2347 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2348 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002349 if hasComponent(suite.name, "CECPQ1") {
2350 // CECPQ1 ciphers must be explicitly enabled.
2351 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2352 }
David Benjamin881f1962016-08-10 18:29:12 -04002353 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2354 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2355 // for now.
2356 flags = append(flags, "-cipher", suite.name)
2357 }
David Benjamin48cae082014-10-27 01:06:24 -04002358
Adam Langley95c29f32014-06-20 12:00:00 -07002359 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002360 for _, protocol := range []protocol{tls, dtls} {
2361 var prefix string
2362 if protocol == dtls {
2363 if !ver.hasDTLS {
2364 continue
2365 }
2366 prefix = "D"
2367 }
Adam Langley95c29f32014-06-20 12:00:00 -07002368
David Benjamin0407e762016-06-17 16:41:18 -04002369 var shouldServerFail, shouldClientFail bool
2370 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2371 // BoringSSL clients accept ECDHE on SSLv3, but
2372 // a BoringSSL server will never select it
2373 // because the extension is missing.
2374 shouldServerFail = true
2375 }
2376 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2377 shouldClientFail = true
2378 shouldServerFail = true
2379 }
David Benjamin54c217c2016-07-13 12:35:25 -04002380 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002381 shouldClientFail = true
2382 shouldServerFail = true
2383 }
David Benjamin0407e762016-06-17 16:41:18 -04002384 if !isDTLSCipher(suite.name) && protocol == dtls {
2385 shouldClientFail = true
2386 shouldServerFail = true
2387 }
David Benjamin4298d772015-12-19 00:18:25 -05002388
David Benjamin0407e762016-06-17 16:41:18 -04002389 var expectedServerError, expectedClientError string
2390 if shouldServerFail {
2391 expectedServerError = ":NO_SHARED_CIPHER:"
2392 }
2393 if shouldClientFail {
2394 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2395 }
David Benjamin025b3d32014-07-01 19:53:04 -04002396
David Benjamin6fd297b2014-08-11 18:43:38 -04002397 testCases = append(testCases, testCase{
2398 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002399 protocol: protocol,
2400
2401 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002402 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002403 MinVersion: ver.version,
2404 MaxVersion: ver.version,
2405 CipherSuites: []uint16{suite.id},
2406 Certificates: []Certificate{cert},
2407 PreSharedKey: []byte(psk),
2408 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002409 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002410 EnableAllCiphers: shouldServerFail,
2411 IgnorePeerCipherPreferences: shouldServerFail,
David Benjamin0407e762016-06-17 16:41:18 -04002412 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002413 },
2414 certFile: certFile,
2415 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002416 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002417 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002418 shouldFail: shouldServerFail,
2419 expectedError: expectedServerError,
2420 })
2421
2422 testCases = append(testCases, testCase{
2423 testType: clientTest,
2424 protocol: protocol,
2425 name: prefix + ver.name + "-" + suite.name + "-client",
2426 config: Config{
2427 MinVersion: ver.version,
2428 MaxVersion: ver.version,
2429 CipherSuites: []uint16{suite.id},
2430 Certificates: []Certificate{cert},
2431 PreSharedKey: []byte(psk),
2432 PreSharedKeyIdentity: pskIdentity,
2433 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002434 EnableAllCiphers: shouldClientFail,
2435 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin0407e762016-06-17 16:41:18 -04002436 },
2437 },
2438 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002439 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002440 shouldFail: shouldClientFail,
2441 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002442 })
David Benjamin2c99d282015-09-01 10:23:00 -04002443
Nick Harper1fd39d82016-06-14 18:14:35 -07002444 if !shouldClientFail {
2445 // Ensure the maximum record size is accepted.
2446 testCases = append(testCases, testCase{
2447 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2448 config: Config{
2449 MinVersion: ver.version,
2450 MaxVersion: ver.version,
2451 CipherSuites: []uint16{suite.id},
2452 Certificates: []Certificate{cert},
2453 PreSharedKey: []byte(psk),
2454 PreSharedKeyIdentity: pskIdentity,
2455 },
2456 flags: flags,
2457 messageLen: maxPlaintext,
2458 })
2459 }
2460 }
David Benjamin2c99d282015-09-01 10:23:00 -04002461 }
Adam Langley95c29f32014-06-20 12:00:00 -07002462 }
Adam Langleya7997f12015-05-14 17:38:50 -07002463
2464 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002465 name: "NoSharedCipher",
2466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002467 MaxVersion: VersionTLS12,
2468 CipherSuites: []uint16{},
2469 },
2470 shouldFail: true,
2471 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2472 })
2473
2474 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002475 name: "NoSharedCipher-TLS13",
2476 config: Config{
2477 MaxVersion: VersionTLS13,
2478 CipherSuites: []uint16{},
2479 },
2480 shouldFail: true,
2481 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2482 })
2483
2484 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002485 name: "UnsupportedCipherSuite",
2486 config: Config{
2487 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002488 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002489 Bugs: ProtocolBugs{
2490 IgnorePeerCipherPreferences: true,
2491 },
2492 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002493 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002494 shouldFail: true,
2495 expectedError: ":WRONG_CIPHER_RETURNED:",
2496 })
2497
2498 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002499 name: "ServerHelloBogusCipher",
2500 config: Config{
2501 MaxVersion: VersionTLS12,
2502 Bugs: ProtocolBugs{
2503 SendCipherSuite: bogusCipher,
2504 },
2505 },
2506 shouldFail: true,
2507 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2508 })
2509 testCases = append(testCases, testCase{
2510 name: "ServerHelloBogusCipher-TLS13",
2511 config: Config{
2512 MaxVersion: VersionTLS13,
2513 Bugs: ProtocolBugs{
2514 SendCipherSuite: bogusCipher,
2515 },
2516 },
2517 shouldFail: true,
2518 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2519 })
2520
2521 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002522 name: "WeakDH",
2523 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002524 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002525 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2526 Bugs: ProtocolBugs{
2527 // This is a 1023-bit prime number, generated
2528 // with:
2529 // openssl gendh 1023 | openssl asn1parse -i
2530 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2531 },
2532 },
2533 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002534 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002535 })
Adam Langleycef75832015-09-03 14:51:12 -07002536
David Benjamincd24a392015-11-11 13:23:05 -08002537 testCases = append(testCases, testCase{
2538 name: "SillyDH",
2539 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002540 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002541 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2542 Bugs: ProtocolBugs{
2543 // This is a 4097-bit prime number, generated
2544 // with:
2545 // openssl gendh 4097 | openssl asn1parse -i
2546 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2547 },
2548 },
2549 shouldFail: true,
2550 expectedError: ":DH_P_TOO_LONG:",
2551 })
2552
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002553 // This test ensures that Diffie-Hellman public values are padded with
2554 // zeros so that they're the same length as the prime. This is to avoid
2555 // hitting a bug in yaSSL.
2556 testCases = append(testCases, testCase{
2557 testType: serverTest,
2558 name: "DHPublicValuePadded",
2559 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002560 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002561 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2562 Bugs: ProtocolBugs{
2563 RequireDHPublicValueLen: (1025 + 7) / 8,
2564 },
2565 },
2566 flags: []string{"-use-sparse-dh-prime"},
2567 })
David Benjamincd24a392015-11-11 13:23:05 -08002568
David Benjamin241ae832016-01-15 03:04:54 -05002569 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002570 testCases = append(testCases, testCase{
2571 testType: serverTest,
2572 name: "UnknownCipher",
2573 config: Config{
2574 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2575 },
2576 })
2577
David Benjamin78679342016-09-16 19:42:05 -04002578 // Test empty ECDHE_PSK identity hints work as expected.
2579 testCases = append(testCases, testCase{
2580 name: "EmptyECDHEPSKHint",
2581 config: Config{
2582 MaxVersion: VersionTLS12,
2583 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2584 PreSharedKey: []byte("secret"),
2585 },
2586 flags: []string{"-psk", "secret"},
2587 })
2588
2589 // Test empty PSK identity hints work as expected, even if an explicit
2590 // ServerKeyExchange is sent.
2591 testCases = append(testCases, testCase{
2592 name: "ExplicitEmptyPSKHint",
2593 config: Config{
2594 MaxVersion: VersionTLS12,
2595 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2596 PreSharedKey: []byte("secret"),
2597 Bugs: ProtocolBugs{
2598 AlwaysSendPreSharedKeyIdentityHint: true,
2599 },
2600 },
2601 flags: []string{"-psk", "secret"},
2602 })
2603
Adam Langleycef75832015-09-03 14:51:12 -07002604 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2605 // 1.1 specific cipher suite settings. A server is setup with the given
2606 // cipher lists and then a connection is made for each member of
2607 // expectations. The cipher suite that the server selects must match
2608 // the specified one.
2609 var versionSpecificCiphersTest = []struct {
2610 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2611 // expectations is a map from TLS version to cipher suite id.
2612 expectations map[uint16]uint16
2613 }{
2614 {
2615 // Test that the null case (where no version-specific ciphers are set)
2616 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002617 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2618 "", // no ciphers specifically for TLS ≥ 1.0
2619 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002620 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002621 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2622 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2623 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2624 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002625 },
2626 },
2627 {
2628 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2629 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002630 "DES-CBC3-SHA:AES128-SHA", // default
2631 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2632 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002633 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002634 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002635 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2636 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2637 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2638 },
2639 },
2640 {
2641 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2642 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002643 "DES-CBC3-SHA:AES128-SHA", // default
2644 "", // no ciphers specifically for TLS ≥ 1.0
2645 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002646 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002647 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2648 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002649 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2650 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2651 },
2652 },
2653 {
2654 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2655 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002656 "DES-CBC3-SHA:AES128-SHA", // default
2657 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2658 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002659 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002660 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002661 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2662 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2663 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2664 },
2665 },
2666 }
2667
2668 for i, test := range versionSpecificCiphersTest {
2669 for version, expectedCipherSuite := range test.expectations {
2670 flags := []string{"-cipher", test.ciphersDefault}
2671 if len(test.ciphersTLS10) > 0 {
2672 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2673 }
2674 if len(test.ciphersTLS11) > 0 {
2675 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2676 }
2677
2678 testCases = append(testCases, testCase{
2679 testType: serverTest,
2680 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2681 config: Config{
2682 MaxVersion: version,
2683 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002684 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 -07002685 },
2686 flags: flags,
2687 expectedCipher: expectedCipherSuite,
2688 })
2689 }
2690 }
Adam Langley95c29f32014-06-20 12:00:00 -07002691}
2692
2693func addBadECDSASignatureTests() {
2694 for badR := BadValue(1); badR < NumBadValues; badR++ {
2695 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002696 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002697 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2698 config: Config{
2699 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002700 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002701 Bugs: ProtocolBugs{
2702 BadECDSAR: badR,
2703 BadECDSAS: badS,
2704 },
2705 },
2706 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002707 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002708 })
2709 }
2710 }
2711}
2712
Adam Langley80842bd2014-06-20 12:00:00 -07002713func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002714 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002715 name: "MaxCBCPadding",
2716 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002717 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002718 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2719 Bugs: ProtocolBugs{
2720 MaxPadding: true,
2721 },
2722 },
2723 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2724 })
David Benjamin025b3d32014-07-01 19:53:04 -04002725 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002726 name: "BadCBCPadding",
2727 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002728 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002729 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2730 Bugs: ProtocolBugs{
2731 PaddingFirstByteBad: true,
2732 },
2733 },
2734 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002735 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002736 })
2737 // OpenSSL previously had an issue where the first byte of padding in
2738 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002739 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002740 name: "BadCBCPadding255",
2741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002742 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002743 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2744 Bugs: ProtocolBugs{
2745 MaxPadding: true,
2746 PaddingFirstByteBadIf255: true,
2747 },
2748 },
2749 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2750 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002751 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002752 })
2753}
2754
Kenny Root7fdeaf12014-08-05 15:23:37 -07002755func addCBCSplittingTests() {
2756 testCases = append(testCases, testCase{
2757 name: "CBCRecordSplitting",
2758 config: Config{
2759 MaxVersion: VersionTLS10,
2760 MinVersion: VersionTLS10,
2761 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2762 },
David Benjaminac8302a2015-09-01 17:18:15 -04002763 messageLen: -1, // read until EOF
2764 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002765 flags: []string{
2766 "-async",
2767 "-write-different-record-sizes",
2768 "-cbc-record-splitting",
2769 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002770 })
2771 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002772 name: "CBCRecordSplittingPartialWrite",
2773 config: Config{
2774 MaxVersion: VersionTLS10,
2775 MinVersion: VersionTLS10,
2776 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2777 },
2778 messageLen: -1, // read until EOF
2779 flags: []string{
2780 "-async",
2781 "-write-different-record-sizes",
2782 "-cbc-record-splitting",
2783 "-partial-write",
2784 },
2785 })
2786}
2787
David Benjamin636293b2014-07-08 17:59:18 -04002788func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002789 // Add a dummy cert pool to stress certificate authority parsing.
2790 // TODO(davidben): Add tests that those values parse out correctly.
2791 certPool := x509.NewCertPool()
2792 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2793 if err != nil {
2794 panic(err)
2795 }
2796 certPool.AddCert(cert)
2797
David Benjamin636293b2014-07-08 17:59:18 -04002798 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002799 testCases = append(testCases, testCase{
2800 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002801 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002802 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002803 MinVersion: ver.version,
2804 MaxVersion: ver.version,
2805 ClientAuth: RequireAnyClientCert,
2806 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002807 },
2808 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002809 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2810 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002811 },
2812 })
2813 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002814 testType: serverTest,
2815 name: ver.name + "-Server-ClientAuth-RSA",
2816 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002817 MinVersion: ver.version,
2818 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002819 Certificates: []Certificate{rsaCertificate},
2820 },
2821 flags: []string{"-require-any-client-certificate"},
2822 })
David Benjamine098ec22014-08-27 23:13:20 -04002823 if ver.version != VersionSSL30 {
2824 testCases = append(testCases, testCase{
2825 testType: serverTest,
2826 name: ver.name + "-Server-ClientAuth-ECDSA",
2827 config: Config{
2828 MinVersion: ver.version,
2829 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002830 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002831 },
2832 flags: []string{"-require-any-client-certificate"},
2833 })
2834 testCases = append(testCases, testCase{
2835 testType: clientTest,
2836 name: ver.name + "-Client-ClientAuth-ECDSA",
2837 config: Config{
2838 MinVersion: ver.version,
2839 MaxVersion: ver.version,
2840 ClientAuth: RequireAnyClientCert,
2841 ClientCAs: certPool,
2842 },
2843 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002844 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2845 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002846 },
2847 })
2848 }
Adam Langley37646832016-08-01 16:16:46 -07002849
2850 testCases = append(testCases, testCase{
2851 name: "NoClientCertificate-" + ver.name,
2852 config: Config{
2853 MinVersion: ver.version,
2854 MaxVersion: ver.version,
2855 ClientAuth: RequireAnyClientCert,
2856 },
2857 shouldFail: true,
2858 expectedLocalError: "client didn't provide a certificate",
2859 })
2860
2861 testCases = append(testCases, testCase{
2862 // Even if not configured to expect a certificate, OpenSSL will
2863 // return X509_V_OK as the verify_result.
2864 testType: serverTest,
2865 name: "NoClientCertificateRequested-Server-" + ver.name,
2866 config: Config{
2867 MinVersion: ver.version,
2868 MaxVersion: ver.version,
2869 },
2870 flags: []string{
2871 "-expect-verify-result",
2872 },
2873 // TODO(davidben): Switch this to true when TLS 1.3
2874 // supports session resumption.
2875 resumeSession: ver.version < VersionTLS13,
2876 })
2877
2878 testCases = append(testCases, testCase{
2879 // If a client certificate is not provided, OpenSSL will still
2880 // return X509_V_OK as the verify_result.
2881 testType: serverTest,
2882 name: "NoClientCertificate-Server-" + ver.name,
2883 config: Config{
2884 MinVersion: ver.version,
2885 MaxVersion: ver.version,
2886 },
2887 flags: []string{
2888 "-expect-verify-result",
2889 "-verify-peer",
2890 },
2891 // TODO(davidben): Switch this to true when TLS 1.3
2892 // supports session resumption.
2893 resumeSession: ver.version < VersionTLS13,
2894 })
2895
2896 testCases = append(testCases, testCase{
2897 testType: serverTest,
2898 name: "RequireAnyClientCertificate-" + ver.name,
2899 config: Config{
2900 MinVersion: ver.version,
2901 MaxVersion: ver.version,
2902 },
2903 flags: []string{"-require-any-client-certificate"},
2904 shouldFail: true,
2905 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2906 })
2907
2908 if ver.version != VersionSSL30 {
2909 testCases = append(testCases, testCase{
2910 testType: serverTest,
2911 name: "SkipClientCertificate-" + ver.name,
2912 config: Config{
2913 MinVersion: ver.version,
2914 MaxVersion: ver.version,
2915 Bugs: ProtocolBugs{
2916 SkipClientCertificate: true,
2917 },
2918 },
2919 // Setting SSL_VERIFY_PEER allows anonymous clients.
2920 flags: []string{"-verify-peer"},
2921 shouldFail: true,
2922 expectedError: ":UNEXPECTED_MESSAGE:",
2923 })
2924 }
David Benjamin636293b2014-07-08 17:59:18 -04002925 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002926
David Benjaminc032dfa2016-05-12 14:54:57 -04002927 // Client auth is only legal in certificate-based ciphers.
2928 testCases = append(testCases, testCase{
2929 testType: clientTest,
2930 name: "ClientAuth-PSK",
2931 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002932 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002933 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2934 PreSharedKey: []byte("secret"),
2935 ClientAuth: RequireAnyClientCert,
2936 },
2937 flags: []string{
2938 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2939 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2940 "-psk", "secret",
2941 },
2942 shouldFail: true,
2943 expectedError: ":UNEXPECTED_MESSAGE:",
2944 })
2945 testCases = append(testCases, testCase{
2946 testType: clientTest,
2947 name: "ClientAuth-ECDHE_PSK",
2948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002949 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002950 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2951 PreSharedKey: []byte("secret"),
2952 ClientAuth: RequireAnyClientCert,
2953 },
2954 flags: []string{
2955 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2956 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2957 "-psk", "secret",
2958 },
2959 shouldFail: true,
2960 expectedError: ":UNEXPECTED_MESSAGE:",
2961 })
David Benjamin2f8935d2016-07-13 19:47:39 -04002962
2963 // Regression test for a bug where the client CA list, if explicitly
2964 // set to NULL, was mis-encoded.
2965 testCases = append(testCases, testCase{
2966 testType: serverTest,
2967 name: "Null-Client-CA-List",
2968 config: Config{
2969 MaxVersion: VersionTLS12,
2970 Certificates: []Certificate{rsaCertificate},
2971 },
2972 flags: []string{
2973 "-require-any-client-certificate",
2974 "-use-null-client-ca-list",
2975 },
2976 })
David Benjamin636293b2014-07-08 17:59:18 -04002977}
2978
Adam Langley75712922014-10-10 16:23:43 -07002979func addExtendedMasterSecretTests() {
2980 const expectEMSFlag = "-expect-extended-master-secret"
2981
2982 for _, with := range []bool{false, true} {
2983 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07002984 if with {
2985 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07002986 }
2987
2988 for _, isClient := range []bool{false, true} {
2989 suffix := "-Server"
2990 testType := serverTest
2991 if isClient {
2992 suffix = "-Client"
2993 testType = clientTest
2994 }
2995
2996 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04002997 // In TLS 1.3, the extension is irrelevant and
2998 // always reports as enabled.
2999 var flags []string
3000 if with || ver.version >= VersionTLS13 {
3001 flags = []string{expectEMSFlag}
3002 }
3003
Adam Langley75712922014-10-10 16:23:43 -07003004 test := testCase{
3005 testType: testType,
3006 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3007 config: Config{
3008 MinVersion: ver.version,
3009 MaxVersion: ver.version,
3010 Bugs: ProtocolBugs{
3011 NoExtendedMasterSecret: !with,
3012 RequireExtendedMasterSecret: with,
3013 },
3014 },
David Benjamin48cae082014-10-27 01:06:24 -04003015 flags: flags,
3016 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003017 }
3018 if test.shouldFail {
3019 test.expectedLocalError = "extended master secret required but not supported by peer"
3020 }
3021 testCases = append(testCases, test)
3022 }
3023 }
3024 }
3025
Adam Langleyba5934b2015-06-02 10:50:35 -07003026 for _, isClient := range []bool{false, true} {
3027 for _, supportedInFirstConnection := range []bool{false, true} {
3028 for _, supportedInResumeConnection := range []bool{false, true} {
3029 boolToWord := func(b bool) string {
3030 if b {
3031 return "Yes"
3032 }
3033 return "No"
3034 }
3035 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3036 if isClient {
3037 suffix += "Client"
3038 } else {
3039 suffix += "Server"
3040 }
3041
3042 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003043 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003044 Bugs: ProtocolBugs{
3045 RequireExtendedMasterSecret: true,
3046 },
3047 }
3048
3049 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003050 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003051 Bugs: ProtocolBugs{
3052 NoExtendedMasterSecret: true,
3053 },
3054 }
3055
3056 test := testCase{
3057 name: "ExtendedMasterSecret-" + suffix,
3058 resumeSession: true,
3059 }
3060
3061 if !isClient {
3062 test.testType = serverTest
3063 }
3064
3065 if supportedInFirstConnection {
3066 test.config = supportedConfig
3067 } else {
3068 test.config = noSupportConfig
3069 }
3070
3071 if supportedInResumeConnection {
3072 test.resumeConfig = &supportedConfig
3073 } else {
3074 test.resumeConfig = &noSupportConfig
3075 }
3076
3077 switch suffix {
3078 case "YesToYes-Client", "YesToYes-Server":
3079 // When a session is resumed, it should
3080 // still be aware that its master
3081 // secret was generated via EMS and
3082 // thus it's safe to use tls-unique.
3083 test.flags = []string{expectEMSFlag}
3084 case "NoToYes-Server":
3085 // If an original connection did not
3086 // contain EMS, but a resumption
3087 // handshake does, then a server should
3088 // not resume the session.
3089 test.expectResumeRejected = true
3090 case "YesToNo-Server":
3091 // Resuming an EMS session without the
3092 // EMS extension should cause the
3093 // server to abort the connection.
3094 test.shouldFail = true
3095 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3096 case "NoToYes-Client":
3097 // A client should abort a connection
3098 // where the server resumed a non-EMS
3099 // session but echoed the EMS
3100 // extension.
3101 test.shouldFail = true
3102 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3103 case "YesToNo-Client":
3104 // A client should abort a connection
3105 // where the server didn't echo EMS
3106 // when the session used it.
3107 test.shouldFail = true
3108 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3109 }
3110
3111 testCases = append(testCases, test)
3112 }
3113 }
3114 }
David Benjamin163c9562016-08-29 23:14:17 -04003115
3116 // Switching EMS on renegotiation is forbidden.
3117 testCases = append(testCases, testCase{
3118 name: "ExtendedMasterSecret-Renego-NoEMS",
3119 config: Config{
3120 MaxVersion: VersionTLS12,
3121 Bugs: ProtocolBugs{
3122 NoExtendedMasterSecret: true,
3123 NoExtendedMasterSecretOnRenegotiation: true,
3124 },
3125 },
3126 renegotiate: 1,
3127 flags: []string{
3128 "-renegotiate-freely",
3129 "-expect-total-renegotiations", "1",
3130 },
3131 })
3132
3133 testCases = append(testCases, testCase{
3134 name: "ExtendedMasterSecret-Renego-Upgrade",
3135 config: Config{
3136 MaxVersion: VersionTLS12,
3137 Bugs: ProtocolBugs{
3138 NoExtendedMasterSecret: true,
3139 },
3140 },
3141 renegotiate: 1,
3142 flags: []string{
3143 "-renegotiate-freely",
3144 "-expect-total-renegotiations", "1",
3145 },
3146 shouldFail: true,
3147 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 name: "ExtendedMasterSecret-Renego-Downgrade",
3152 config: Config{
3153 MaxVersion: VersionTLS12,
3154 Bugs: ProtocolBugs{
3155 NoExtendedMasterSecretOnRenegotiation: true,
3156 },
3157 },
3158 renegotiate: 1,
3159 flags: []string{
3160 "-renegotiate-freely",
3161 "-expect-total-renegotiations", "1",
3162 },
3163 shouldFail: true,
3164 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3165 })
Adam Langley75712922014-10-10 16:23:43 -07003166}
3167
David Benjamin582ba042016-07-07 12:33:25 -07003168type stateMachineTestConfig struct {
3169 protocol protocol
3170 async bool
3171 splitHandshake, packHandshakeFlight bool
3172}
3173
David Benjamin43ec06f2014-08-05 02:28:57 -04003174// Adds tests that try to cover the range of the handshake state machine, under
3175// various conditions. Some of these are redundant with other tests, but they
3176// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003177func addAllStateMachineCoverageTests() {
3178 for _, async := range []bool{false, true} {
3179 for _, protocol := range []protocol{tls, dtls} {
3180 addStateMachineCoverageTests(stateMachineTestConfig{
3181 protocol: protocol,
3182 async: async,
3183 })
3184 addStateMachineCoverageTests(stateMachineTestConfig{
3185 protocol: protocol,
3186 async: async,
3187 splitHandshake: true,
3188 })
3189 if protocol == tls {
3190 addStateMachineCoverageTests(stateMachineTestConfig{
3191 protocol: protocol,
3192 async: async,
3193 packHandshakeFlight: true,
3194 })
3195 }
3196 }
3197 }
3198}
3199
3200func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003201 var tests []testCase
3202
3203 // Basic handshake, with resumption. Client and server,
3204 // session ID and session ticket.
3205 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003206 name: "Basic-Client",
3207 config: Config{
3208 MaxVersion: VersionTLS12,
3209 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003210 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003211 // Ensure session tickets are used, not session IDs.
3212 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003213 })
3214 tests = append(tests, testCase{
3215 name: "Basic-Client-RenewTicket",
3216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003217 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003218 Bugs: ProtocolBugs{
3219 RenewTicketOnResume: true,
3220 },
3221 },
David Benjamin46662482016-08-17 00:51:00 -04003222 flags: []string{"-expect-ticket-renewal"},
3223 resumeSession: true,
3224 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003225 })
3226 tests = append(tests, testCase{
3227 name: "Basic-Client-NoTicket",
3228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003229 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003230 SessionTicketsDisabled: true,
3231 },
3232 resumeSession: true,
3233 })
3234 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003235 name: "Basic-Client-Implicit",
3236 config: Config{
3237 MaxVersion: VersionTLS12,
3238 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003239 flags: []string{"-implicit-handshake"},
3240 resumeSession: true,
3241 })
3242 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003243 testType: serverTest,
3244 name: "Basic-Server",
3245 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003246 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003247 Bugs: ProtocolBugs{
3248 RequireSessionTickets: true,
3249 },
3250 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003251 resumeSession: true,
3252 })
3253 tests = append(tests, testCase{
3254 testType: serverTest,
3255 name: "Basic-Server-NoTickets",
3256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003257 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003258 SessionTicketsDisabled: true,
3259 },
3260 resumeSession: true,
3261 })
3262 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003263 testType: serverTest,
3264 name: "Basic-Server-Implicit",
3265 config: Config{
3266 MaxVersion: VersionTLS12,
3267 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003268 flags: []string{"-implicit-handshake"},
3269 resumeSession: true,
3270 })
3271 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003272 testType: serverTest,
3273 name: "Basic-Server-EarlyCallback",
3274 config: Config{
3275 MaxVersion: VersionTLS12,
3276 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 flags: []string{"-use-early-callback"},
3278 resumeSession: true,
3279 })
3280
Steven Valdez143e8b32016-07-11 13:19:03 -04003281 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003282 if config.protocol == tls {
3283 tests = append(tests, testCase{
3284 name: "TLS13-1RTT-Client",
3285 config: Config{
3286 MaxVersion: VersionTLS13,
3287 MinVersion: VersionTLS13,
3288 },
David Benjamin46662482016-08-17 00:51:00 -04003289 resumeSession: true,
3290 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003291 })
3292
3293 tests = append(tests, testCase{
3294 testType: serverTest,
3295 name: "TLS13-1RTT-Server",
3296 config: Config{
3297 MaxVersion: VersionTLS13,
3298 MinVersion: VersionTLS13,
3299 },
David Benjamin46662482016-08-17 00:51:00 -04003300 resumeSession: true,
3301 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003302 })
3303
3304 tests = append(tests, testCase{
3305 name: "TLS13-HelloRetryRequest-Client",
3306 config: Config{
3307 MaxVersion: VersionTLS13,
3308 MinVersion: VersionTLS13,
3309 // P-384 requires a HelloRetryRequest against
3310 // BoringSSL's default configuration. Assert
3311 // that we do indeed test this with
3312 // ExpectMissingKeyShare.
3313 CurvePreferences: []CurveID{CurveP384},
3314 Bugs: ProtocolBugs{
3315 ExpectMissingKeyShare: true,
3316 },
3317 },
3318 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3319 resumeSession: true,
3320 })
3321
3322 tests = append(tests, testCase{
3323 testType: serverTest,
3324 name: "TLS13-HelloRetryRequest-Server",
3325 config: Config{
3326 MaxVersion: VersionTLS13,
3327 MinVersion: VersionTLS13,
3328 // Require a HelloRetryRequest for every curve.
3329 DefaultCurves: []CurveID{},
3330 },
3331 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3332 resumeSession: true,
3333 })
3334 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003335
David Benjamin760b1dd2015-05-15 23:33:48 -04003336 // TLS client auth.
3337 tests = append(tests, testCase{
3338 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003339 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003341 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003342 ClientAuth: RequestClientCert,
3343 },
3344 })
3345 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003346 testType: serverTest,
3347 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003348 config: Config{
3349 MaxVersion: VersionTLS12,
3350 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003351 // Setting SSL_VERIFY_PEER allows anonymous clients.
3352 flags: []string{"-verify-peer"},
3353 })
David Benjamin582ba042016-07-07 12:33:25 -07003354 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003355 tests = append(tests, testCase{
3356 testType: clientTest,
3357 name: "ClientAuth-NoCertificate-Client-SSL3",
3358 config: Config{
3359 MaxVersion: VersionSSL30,
3360 ClientAuth: RequestClientCert,
3361 },
3362 })
3363 tests = append(tests, testCase{
3364 testType: serverTest,
3365 name: "ClientAuth-NoCertificate-Server-SSL3",
3366 config: Config{
3367 MaxVersion: VersionSSL30,
3368 },
3369 // Setting SSL_VERIFY_PEER allows anonymous clients.
3370 flags: []string{"-verify-peer"},
3371 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003372 tests = append(tests, testCase{
3373 testType: clientTest,
3374 name: "ClientAuth-NoCertificate-Client-TLS13",
3375 config: Config{
3376 MaxVersion: VersionTLS13,
3377 ClientAuth: RequestClientCert,
3378 },
3379 })
3380 tests = append(tests, testCase{
3381 testType: serverTest,
3382 name: "ClientAuth-NoCertificate-Server-TLS13",
3383 config: Config{
3384 MaxVersion: VersionTLS13,
3385 },
3386 // Setting SSL_VERIFY_PEER allows anonymous clients.
3387 flags: []string{"-verify-peer"},
3388 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003389 }
3390 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003391 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003392 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003394 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 ClientAuth: RequireAnyClientCert,
3396 },
3397 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 },
3401 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003402 tests = append(tests, testCase{
3403 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003404 name: "ClientAuth-RSA-Client-TLS13",
3405 config: Config{
3406 MaxVersion: VersionTLS13,
3407 ClientAuth: RequireAnyClientCert,
3408 },
3409 flags: []string{
3410 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3411 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3412 },
3413 })
3414 tests = append(tests, testCase{
3415 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003416 name: "ClientAuth-ECDSA-Client",
3417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003418 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003419 ClientAuth: RequireAnyClientCert,
3420 },
3421 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003422 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3423 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003424 },
3425 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003426 tests = append(tests, testCase{
3427 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003428 name: "ClientAuth-ECDSA-Client-TLS13",
3429 config: Config{
3430 MaxVersion: VersionTLS13,
3431 ClientAuth: RequireAnyClientCert,
3432 },
3433 flags: []string{
3434 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3435 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3436 },
3437 })
3438 tests = append(tests, testCase{
3439 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440 name: "ClientAuth-NoCertificate-OldCallback",
3441 config: Config{
3442 MaxVersion: VersionTLS12,
3443 ClientAuth: RequestClientCert,
3444 },
3445 flags: []string{"-use-old-client-cert-callback"},
3446 })
3447 tests = append(tests, testCase{
3448 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003449 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3450 config: Config{
3451 MaxVersion: VersionTLS13,
3452 ClientAuth: RequestClientCert,
3453 },
3454 flags: []string{"-use-old-client-cert-callback"},
3455 })
3456 tests = append(tests, testCase{
3457 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003458 name: "ClientAuth-OldCallback",
3459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003460 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003461 ClientAuth: RequireAnyClientCert,
3462 },
3463 flags: []string{
3464 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3465 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3466 "-use-old-client-cert-callback",
3467 },
3468 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003469 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003470 testType: clientTest,
3471 name: "ClientAuth-OldCallback-TLS13",
3472 config: Config{
3473 MaxVersion: VersionTLS13,
3474 ClientAuth: RequireAnyClientCert,
3475 },
3476 flags: []string{
3477 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3478 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3479 "-use-old-client-cert-callback",
3480 },
3481 })
3482 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003483 testType: serverTest,
3484 name: "ClientAuth-Server",
3485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003486 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003487 Certificates: []Certificate{rsaCertificate},
3488 },
3489 flags: []string{"-require-any-client-certificate"},
3490 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003491 tests = append(tests, testCase{
3492 testType: serverTest,
3493 name: "ClientAuth-Server-TLS13",
3494 config: Config{
3495 MaxVersion: VersionTLS13,
3496 Certificates: []Certificate{rsaCertificate},
3497 },
3498 flags: []string{"-require-any-client-certificate"},
3499 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003500
David Benjamin4c3ddf72016-06-29 18:13:53 -04003501 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003502 tests = append(tests, testCase{
3503 testType: serverTest,
3504 name: "Basic-Server-RSA",
3505 config: Config{
3506 MaxVersion: VersionTLS12,
3507 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3508 },
3509 flags: []string{
3510 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3511 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3512 },
3513 })
3514 tests = append(tests, testCase{
3515 testType: serverTest,
3516 name: "Basic-Server-ECDHE-RSA",
3517 config: Config{
3518 MaxVersion: VersionTLS12,
3519 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3520 },
3521 flags: []string{
3522 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3523 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3524 },
3525 })
3526 tests = append(tests, testCase{
3527 testType: serverTest,
3528 name: "Basic-Server-ECDHE-ECDSA",
3529 config: Config{
3530 MaxVersion: VersionTLS12,
3531 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3532 },
3533 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003534 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3535 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003536 },
3537 })
3538
David Benjamin760b1dd2015-05-15 23:33:48 -04003539 // No session ticket support; server doesn't send NewSessionTicket.
3540 tests = append(tests, testCase{
3541 name: "SessionTicketsDisabled-Client",
3542 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003543 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003544 SessionTicketsDisabled: true,
3545 },
3546 })
3547 tests = append(tests, testCase{
3548 testType: serverTest,
3549 name: "SessionTicketsDisabled-Server",
3550 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003551 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003552 SessionTicketsDisabled: true,
3553 },
3554 })
3555
3556 // Skip ServerKeyExchange in PSK key exchange if there's no
3557 // identity hint.
3558 tests = append(tests, testCase{
3559 name: "EmptyPSKHint-Client",
3560 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003561 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003562 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3563 PreSharedKey: []byte("secret"),
3564 },
3565 flags: []string{"-psk", "secret"},
3566 })
3567 tests = append(tests, testCase{
3568 testType: serverTest,
3569 name: "EmptyPSKHint-Server",
3570 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003571 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003572 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3573 PreSharedKey: []byte("secret"),
3574 },
3575 flags: []string{"-psk", "secret"},
3576 })
3577
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003579 tests = append(tests, testCase{
3580 testType: clientTest,
3581 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003582 config: Config{
3583 MaxVersion: VersionTLS12,
3584 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003585 flags: []string{
3586 "-enable-ocsp-stapling",
3587 "-expect-ocsp-response",
3588 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003589 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003590 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003591 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003592 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003593 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003594 testType: serverTest,
3595 name: "OCSPStapling-Server",
3596 config: Config{
3597 MaxVersion: VersionTLS12,
3598 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003599 expectedOCSPResponse: testOCSPResponse,
3600 flags: []string{
3601 "-ocsp-response",
3602 base64.StdEncoding.EncodeToString(testOCSPResponse),
3603 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003604 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003605 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003606 tests = append(tests, testCase{
3607 testType: clientTest,
3608 name: "OCSPStapling-Client-TLS13",
3609 config: Config{
3610 MaxVersion: VersionTLS13,
3611 },
3612 flags: []string{
3613 "-enable-ocsp-stapling",
3614 "-expect-ocsp-response",
3615 base64.StdEncoding.EncodeToString(testOCSPResponse),
3616 "-verify-peer",
3617 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003618 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003619 })
3620 tests = append(tests, testCase{
3621 testType: serverTest,
3622 name: "OCSPStapling-Server-TLS13",
3623 config: Config{
3624 MaxVersion: VersionTLS13,
3625 },
3626 expectedOCSPResponse: testOCSPResponse,
3627 flags: []string{
3628 "-ocsp-response",
3629 base64.StdEncoding.EncodeToString(testOCSPResponse),
3630 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003631 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003632 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003633
David Benjamin4c3ddf72016-06-29 18:13:53 -04003634 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003635 for _, vers := range tlsVersions {
3636 if config.protocol == dtls && !vers.hasDTLS {
3637 continue
3638 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003639 for _, testType := range []testType{clientTest, serverTest} {
3640 suffix := "-Client"
3641 if testType == serverTest {
3642 suffix = "-Server"
3643 }
3644 suffix += "-" + vers.name
3645
3646 flag := "-verify-peer"
3647 if testType == serverTest {
3648 flag = "-require-any-client-certificate"
3649 }
3650
3651 tests = append(tests, testCase{
3652 testType: testType,
3653 name: "CertificateVerificationSucceed" + suffix,
3654 config: Config{
3655 MaxVersion: vers.version,
3656 Certificates: []Certificate{rsaCertificate},
3657 },
3658 flags: []string{
3659 flag,
3660 "-expect-verify-result",
3661 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003662 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003663 })
3664 tests = append(tests, testCase{
3665 testType: testType,
3666 name: "CertificateVerificationFail" + suffix,
3667 config: Config{
3668 MaxVersion: vers.version,
3669 Certificates: []Certificate{rsaCertificate},
3670 },
3671 flags: []string{
3672 flag,
3673 "-verify-fail",
3674 },
3675 shouldFail: true,
3676 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3677 })
3678 }
3679
3680 // By default, the client is in a soft fail mode where the peer
3681 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003682 tests = append(tests, testCase{
3683 testType: clientTest,
3684 name: "CertificateVerificationSoftFail-" + vers.name,
3685 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003686 MaxVersion: vers.version,
3687 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003688 },
3689 flags: []string{
3690 "-verify-fail",
3691 "-expect-verify-result",
3692 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003693 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003694 })
3695 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003696
David Benjamin1d4f4c02016-07-26 18:03:08 -04003697 tests = append(tests, testCase{
3698 name: "ShimSendAlert",
3699 flags: []string{"-send-alert"},
3700 shimWritesFirst: true,
3701 shouldFail: true,
3702 expectedLocalError: "remote error: decompression failure",
3703 })
3704
David Benjamin582ba042016-07-07 12:33:25 -07003705 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003706 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003707 name: "Renegotiate-Client",
3708 config: Config{
3709 MaxVersion: VersionTLS12,
3710 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003711 renegotiate: 1,
3712 flags: []string{
3713 "-renegotiate-freely",
3714 "-expect-total-renegotiations", "1",
3715 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003716 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717
David Benjamin47921102016-07-28 11:29:18 -04003718 tests = append(tests, testCase{
3719 name: "SendHalfHelloRequest",
3720 config: Config{
3721 MaxVersion: VersionTLS12,
3722 Bugs: ProtocolBugs{
3723 PackHelloRequestWithFinished: config.packHandshakeFlight,
3724 },
3725 },
3726 sendHalfHelloRequest: true,
3727 flags: []string{"-renegotiate-ignore"},
3728 shouldFail: true,
3729 expectedError: ":UNEXPECTED_RECORD:",
3730 })
3731
David Benjamin760b1dd2015-05-15 23:33:48 -04003732 // NPN on client and server; results in post-handshake message.
3733 tests = append(tests, testCase{
3734 name: "NPN-Client",
3735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 NextProtos: []string{"foo"},
3738 },
3739 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003740 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003741 expectedNextProto: "foo",
3742 expectedNextProtoType: npn,
3743 })
3744 tests = append(tests, testCase{
3745 testType: serverTest,
3746 name: "NPN-Server",
3747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003748 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003749 NextProtos: []string{"bar"},
3750 },
3751 flags: []string{
3752 "-advertise-npn", "\x03foo\x03bar\x03baz",
3753 "-expect-next-proto", "bar",
3754 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003755 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003756 expectedNextProto: "bar",
3757 expectedNextProtoType: npn,
3758 })
3759
3760 // TODO(davidben): Add tests for when False Start doesn't trigger.
3761
3762 // Client does False Start and negotiates NPN.
3763 tests = append(tests, testCase{
3764 name: "FalseStart",
3765 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003766 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003767 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3768 NextProtos: []string{"foo"},
3769 Bugs: ProtocolBugs{
3770 ExpectFalseStart: true,
3771 },
3772 },
3773 flags: []string{
3774 "-false-start",
3775 "-select-next-proto", "foo",
3776 },
3777 shimWritesFirst: true,
3778 resumeSession: true,
3779 })
3780
3781 // Client does False Start and negotiates ALPN.
3782 tests = append(tests, testCase{
3783 name: "FalseStart-ALPN",
3784 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003785 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3787 NextProtos: []string{"foo"},
3788 Bugs: ProtocolBugs{
3789 ExpectFalseStart: true,
3790 },
3791 },
3792 flags: []string{
3793 "-false-start",
3794 "-advertise-alpn", "\x03foo",
3795 },
3796 shimWritesFirst: true,
3797 resumeSession: true,
3798 })
3799
3800 // Client does False Start but doesn't explicitly call
3801 // SSL_connect.
3802 tests = append(tests, testCase{
3803 name: "FalseStart-Implicit",
3804 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003805 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003806 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3807 NextProtos: []string{"foo"},
3808 },
3809 flags: []string{
3810 "-implicit-handshake",
3811 "-false-start",
3812 "-advertise-alpn", "\x03foo",
3813 },
3814 })
3815
3816 // False Start without session tickets.
3817 tests = append(tests, testCase{
3818 name: "FalseStart-SessionTicketsDisabled",
3819 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003820 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003821 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3822 NextProtos: []string{"foo"},
3823 SessionTicketsDisabled: true,
3824 Bugs: ProtocolBugs{
3825 ExpectFalseStart: true,
3826 },
3827 },
3828 flags: []string{
3829 "-false-start",
3830 "-select-next-proto", "foo",
3831 },
3832 shimWritesFirst: true,
3833 })
3834
Adam Langleydf759b52016-07-11 15:24:37 -07003835 tests = append(tests, testCase{
3836 name: "FalseStart-CECPQ1",
3837 config: Config{
3838 MaxVersion: VersionTLS12,
3839 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3840 NextProtos: []string{"foo"},
3841 Bugs: ProtocolBugs{
3842 ExpectFalseStart: true,
3843 },
3844 },
3845 flags: []string{
3846 "-false-start",
3847 "-cipher", "DEFAULT:kCECPQ1",
3848 "-select-next-proto", "foo",
3849 },
3850 shimWritesFirst: true,
3851 resumeSession: true,
3852 })
3853
David Benjamin760b1dd2015-05-15 23:33:48 -04003854 // Server parses a V2ClientHello.
3855 tests = append(tests, testCase{
3856 testType: serverTest,
3857 name: "SendV2ClientHello",
3858 config: Config{
3859 // Choose a cipher suite that does not involve
3860 // elliptic curves, so no extensions are
3861 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003862 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003863 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003864 Bugs: ProtocolBugs{
3865 SendV2ClientHello: true,
3866 },
3867 },
3868 })
3869
3870 // Client sends a Channel ID.
3871 tests = append(tests, testCase{
3872 name: "ChannelID-Client",
3873 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003874 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003875 RequestChannelID: true,
3876 },
Adam Langley7c803a62015-06-15 15:35:05 -07003877 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003878 resumeSession: true,
3879 expectChannelID: true,
3880 })
3881
3882 // Server accepts a Channel ID.
3883 tests = append(tests, testCase{
3884 testType: serverTest,
3885 name: "ChannelID-Server",
3886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003887 MaxVersion: VersionTLS12,
3888 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003889 },
3890 flags: []string{
3891 "-expect-channel-id",
3892 base64.StdEncoding.EncodeToString(channelIDBytes),
3893 },
3894 resumeSession: true,
3895 expectChannelID: true,
3896 })
David Benjamin30789da2015-08-29 22:56:45 -04003897
David Benjaminf8fcdf32016-06-08 15:56:13 -04003898 // Channel ID and NPN at the same time, to ensure their relative
3899 // ordering is correct.
3900 tests = append(tests, testCase{
3901 name: "ChannelID-NPN-Client",
3902 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003903 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003904 RequestChannelID: true,
3905 NextProtos: []string{"foo"},
3906 },
3907 flags: []string{
3908 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3909 "-select-next-proto", "foo",
3910 },
3911 resumeSession: true,
3912 expectChannelID: true,
3913 expectedNextProto: "foo",
3914 expectedNextProtoType: npn,
3915 })
3916 tests = append(tests, testCase{
3917 testType: serverTest,
3918 name: "ChannelID-NPN-Server",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003921 ChannelID: channelIDKey,
3922 NextProtos: []string{"bar"},
3923 },
3924 flags: []string{
3925 "-expect-channel-id",
3926 base64.StdEncoding.EncodeToString(channelIDBytes),
3927 "-advertise-npn", "\x03foo\x03bar\x03baz",
3928 "-expect-next-proto", "bar",
3929 },
3930 resumeSession: true,
3931 expectChannelID: true,
3932 expectedNextProto: "bar",
3933 expectedNextProtoType: npn,
3934 })
3935
David Benjamin30789da2015-08-29 22:56:45 -04003936 // Bidirectional shutdown with the runner initiating.
3937 tests = append(tests, testCase{
3938 name: "Shutdown-Runner",
3939 config: Config{
3940 Bugs: ProtocolBugs{
3941 ExpectCloseNotify: true,
3942 },
3943 },
3944 flags: []string{"-check-close-notify"},
3945 })
3946
3947 // Bidirectional shutdown with the shim initiating. The runner,
3948 // in the meantime, sends garbage before the close_notify which
3949 // the shim must ignore.
3950 tests = append(tests, testCase{
3951 name: "Shutdown-Shim",
3952 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04003953 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04003954 Bugs: ProtocolBugs{
3955 ExpectCloseNotify: true,
3956 },
3957 },
3958 shimShutsDown: true,
3959 sendEmptyRecords: 1,
3960 sendWarningAlerts: 1,
3961 flags: []string{"-check-close-notify"},
3962 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964 // TODO(davidben): DTLS 1.3 will want a similar thing for
3965 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04003966 tests = append(tests, testCase{
3967 name: "SkipHelloVerifyRequest",
3968 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 Bugs: ProtocolBugs{
3971 SkipHelloVerifyRequest: true,
3972 },
3973 },
3974 })
3975 }
3976
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07003978 test.protocol = config.protocol
3979 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003980 test.name += "-DTLS"
3981 }
David Benjamin582ba042016-07-07 12:33:25 -07003982 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05003983 test.name += "-Async"
3984 test.flags = append(test.flags, "-async")
3985 } else {
3986 test.name += "-Sync"
3987 }
David Benjamin582ba042016-07-07 12:33:25 -07003988 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05003989 test.name += "-SplitHandshakeRecords"
3990 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07003991 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05003992 test.config.Bugs.MaxPacketLength = 256
3993 test.flags = append(test.flags, "-mtu", "256")
3994 }
3995 }
David Benjamin582ba042016-07-07 12:33:25 -07003996 if config.packHandshakeFlight {
3997 test.name += "-PackHandshakeFlight"
3998 test.config.Bugs.PackHandshakeFlight = true
3999 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004000 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004001 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004002}
4003
Adam Langley524e7172015-02-20 16:04:00 -08004004func addDDoSCallbackTests() {
4005 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004006 for _, resume := range []bool{false, true} {
4007 suffix := "Resume"
4008 if resume {
4009 suffix = "No" + suffix
4010 }
4011
4012 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004013 testType: serverTest,
4014 name: "Server-DDoS-OK-" + suffix,
4015 config: Config{
4016 MaxVersion: VersionTLS12,
4017 },
Adam Langley524e7172015-02-20 16:04:00 -08004018 flags: []string{"-install-ddos-callback"},
4019 resumeSession: resume,
4020 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004021 testCases = append(testCases, testCase{
4022 testType: serverTest,
4023 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4024 config: Config{
4025 MaxVersion: VersionTLS13,
4026 },
4027 flags: []string{"-install-ddos-callback"},
4028 resumeSession: resume,
4029 })
Adam Langley524e7172015-02-20 16:04:00 -08004030
4031 failFlag := "-fail-ddos-callback"
4032 if resume {
4033 failFlag = "-fail-second-ddos-callback"
4034 }
4035 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004036 testType: serverTest,
4037 name: "Server-DDoS-Reject-" + suffix,
4038 config: Config{
4039 MaxVersion: VersionTLS12,
4040 },
David Benjamin2c66e072016-09-16 15:58:00 -04004041 flags: []string{"-install-ddos-callback", failFlag},
4042 resumeSession: resume,
4043 shouldFail: true,
4044 expectedError: ":CONNECTION_REJECTED:",
4045 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004046 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004047 testCases = append(testCases, testCase{
4048 testType: serverTest,
4049 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4050 config: Config{
4051 MaxVersion: VersionTLS13,
4052 },
David Benjamin2c66e072016-09-16 15:58:00 -04004053 flags: []string{"-install-ddos-callback", failFlag},
4054 resumeSession: resume,
4055 shouldFail: true,
4056 expectedError: ":CONNECTION_REJECTED:",
4057 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004058 })
Adam Langley524e7172015-02-20 16:04:00 -08004059 }
4060}
4061
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004062func addVersionNegotiationTests() {
4063 for i, shimVers := range tlsVersions {
4064 // Assemble flags to disable all newer versions on the shim.
4065 var flags []string
4066 for _, vers := range tlsVersions[i+1:] {
4067 flags = append(flags, vers.flag)
4068 }
4069
4070 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004071 protocols := []protocol{tls}
4072 if runnerVers.hasDTLS && shimVers.hasDTLS {
4073 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004074 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004075 for _, protocol := range protocols {
4076 expectedVersion := shimVers.version
4077 if runnerVers.version < shimVers.version {
4078 expectedVersion = runnerVers.version
4079 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004080
David Benjamin8b8c0062014-11-23 02:47:52 -05004081 suffix := shimVers.name + "-" + runnerVers.name
4082 if protocol == dtls {
4083 suffix += "-DTLS"
4084 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004085
David Benjamin1eb367c2014-12-12 18:17:51 -05004086 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4087
David Benjamin1e29a6b2014-12-10 02:27:24 -05004088 clientVers := shimVers.version
4089 if clientVers > VersionTLS10 {
4090 clientVers = VersionTLS10
4091 }
Nick Harper1fd39d82016-06-14 18:14:35 -07004092 serverVers := expectedVersion
4093 if expectedVersion >= VersionTLS13 {
4094 serverVers = VersionTLS10
4095 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004096 testCases = append(testCases, testCase{
4097 protocol: protocol,
4098 testType: clientTest,
4099 name: "VersionNegotiation-Client-" + suffix,
4100 config: Config{
4101 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004102 Bugs: ProtocolBugs{
4103 ExpectInitialRecordVersion: clientVers,
4104 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004105 },
4106 flags: flags,
4107 expectedVersion: expectedVersion,
4108 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004109 testCases = append(testCases, testCase{
4110 protocol: protocol,
4111 testType: clientTest,
4112 name: "VersionNegotiation-Client2-" + suffix,
4113 config: Config{
4114 MaxVersion: runnerVers.version,
4115 Bugs: ProtocolBugs{
4116 ExpectInitialRecordVersion: clientVers,
4117 },
4118 },
4119 flags: []string{"-max-version", shimVersFlag},
4120 expectedVersion: expectedVersion,
4121 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004122
4123 testCases = append(testCases, testCase{
4124 protocol: protocol,
4125 testType: serverTest,
4126 name: "VersionNegotiation-Server-" + suffix,
4127 config: Config{
4128 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004129 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004130 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004131 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004132 },
4133 flags: flags,
4134 expectedVersion: expectedVersion,
4135 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004136 testCases = append(testCases, testCase{
4137 protocol: protocol,
4138 testType: serverTest,
4139 name: "VersionNegotiation-Server2-" + suffix,
4140 config: Config{
4141 MaxVersion: runnerVers.version,
4142 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004143 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004144 },
4145 },
4146 flags: []string{"-max-version", shimVersFlag},
4147 expectedVersion: expectedVersion,
4148 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004149 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004150 }
4151 }
David Benjamin95c69562016-06-29 18:15:03 -04004152
4153 // Test for version tolerance.
4154 testCases = append(testCases, testCase{
4155 testType: serverTest,
4156 name: "MinorVersionTolerance",
4157 config: Config{
4158 Bugs: ProtocolBugs{
4159 SendClientVersion: 0x03ff,
4160 },
4161 },
4162 expectedVersion: VersionTLS13,
4163 })
4164 testCases = append(testCases, testCase{
4165 testType: serverTest,
4166 name: "MajorVersionTolerance",
4167 config: Config{
4168 Bugs: ProtocolBugs{
4169 SendClientVersion: 0x0400,
4170 },
4171 },
4172 expectedVersion: VersionTLS13,
4173 })
4174 testCases = append(testCases, testCase{
4175 protocol: dtls,
4176 testType: serverTest,
4177 name: "MinorVersionTolerance-DTLS",
4178 config: Config{
4179 Bugs: ProtocolBugs{
4180 SendClientVersion: 0x03ff,
4181 },
4182 },
4183 expectedVersion: VersionTLS12,
4184 })
4185 testCases = append(testCases, testCase{
4186 protocol: dtls,
4187 testType: serverTest,
4188 name: "MajorVersionTolerance-DTLS",
4189 config: Config{
4190 Bugs: ProtocolBugs{
4191 SendClientVersion: 0x0400,
4192 },
4193 },
4194 expectedVersion: VersionTLS12,
4195 })
4196
4197 // Test that versions below 3.0 are rejected.
4198 testCases = append(testCases, testCase{
4199 testType: serverTest,
4200 name: "VersionTooLow",
4201 config: Config{
4202 Bugs: ProtocolBugs{
4203 SendClientVersion: 0x0200,
4204 },
4205 },
4206 shouldFail: true,
4207 expectedError: ":UNSUPPORTED_PROTOCOL:",
4208 })
4209 testCases = append(testCases, testCase{
4210 protocol: dtls,
4211 testType: serverTest,
4212 name: "VersionTooLow-DTLS",
4213 config: Config{
4214 Bugs: ProtocolBugs{
4215 // 0x0201 is the lowest version expressable in
4216 // DTLS.
4217 SendClientVersion: 0x0201,
4218 },
4219 },
4220 shouldFail: true,
4221 expectedError: ":UNSUPPORTED_PROTOCOL:",
4222 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004223
David Benjamin2dc02042016-09-19 19:57:37 -04004224 testCases = append(testCases, testCase{
4225 name: "ServerBogusVersion",
4226 config: Config{
4227 Bugs: ProtocolBugs{
4228 SendServerHelloVersion: 0x1234,
4229 },
4230 },
4231 shouldFail: true,
4232 expectedError: ":UNSUPPORTED_PROTOCOL:",
4233 })
4234
David Benjamin1f61f0d2016-07-10 12:20:35 -04004235 // Test TLS 1.3's downgrade signal.
4236 testCases = append(testCases, testCase{
4237 name: "Downgrade-TLS12-Client",
4238 config: Config{
4239 Bugs: ProtocolBugs{
4240 NegotiateVersion: VersionTLS12,
4241 },
4242 },
David Benjamin55108632016-08-11 22:01:18 -04004243 // TODO(davidben): This test should fail once TLS 1.3 is final
4244 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004245 })
4246 testCases = append(testCases, testCase{
4247 testType: serverTest,
4248 name: "Downgrade-TLS12-Server",
4249 config: Config{
4250 Bugs: ProtocolBugs{
4251 SendClientVersion: VersionTLS12,
4252 },
4253 },
David Benjamin55108632016-08-11 22:01:18 -04004254 // TODO(davidben): This test should fail once TLS 1.3 is final
4255 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004256 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004257}
4258
David Benjaminaccb4542014-12-12 23:44:33 -05004259func addMinimumVersionTests() {
4260 for i, shimVers := range tlsVersions {
4261 // Assemble flags to disable all older versions on the shim.
4262 var flags []string
4263 for _, vers := range tlsVersions[:i] {
4264 flags = append(flags, vers.flag)
4265 }
4266
4267 for _, runnerVers := range tlsVersions {
4268 protocols := []protocol{tls}
4269 if runnerVers.hasDTLS && shimVers.hasDTLS {
4270 protocols = append(protocols, dtls)
4271 }
4272 for _, protocol := range protocols {
4273 suffix := shimVers.name + "-" + runnerVers.name
4274 if protocol == dtls {
4275 suffix += "-DTLS"
4276 }
4277 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4278
David Benjaminaccb4542014-12-12 23:44:33 -05004279 var expectedVersion uint16
4280 var shouldFail bool
David Benjamin929d4ee2016-06-24 23:55:58 -04004281 var expectedClientError, expectedServerError string
4282 var expectedClientLocalError, expectedServerLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004283 if runnerVers.version >= shimVers.version {
4284 expectedVersion = runnerVers.version
4285 } else {
4286 shouldFail = true
David Benjamin929d4ee2016-06-24 23:55:58 -04004287 expectedServerError = ":UNSUPPORTED_PROTOCOL:"
4288 expectedServerLocalError = "remote error: protocol version not supported"
4289 if shimVers.version >= VersionTLS13 && runnerVers.version <= VersionTLS11 {
4290 // If the client's minimum version is TLS 1.3 and the runner's
4291 // maximum is below TLS 1.2, the runner will fail to select a
4292 // cipher before the shim rejects the selected version.
4293 expectedClientError = ":SSLV3_ALERT_HANDSHAKE_FAILURE:"
4294 expectedClientLocalError = "tls: no cipher suite supported by both client and server"
4295 } else {
4296 expectedClientError = expectedServerError
4297 expectedClientLocalError = expectedServerLocalError
4298 }
David Benjaminaccb4542014-12-12 23:44:33 -05004299 }
4300
4301 testCases = append(testCases, testCase{
4302 protocol: protocol,
4303 testType: clientTest,
4304 name: "MinimumVersion-Client-" + suffix,
4305 config: Config{
4306 MaxVersion: runnerVers.version,
4307 },
David Benjamin87909c02014-12-13 01:55:01 -05004308 flags: flags,
4309 expectedVersion: expectedVersion,
4310 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004311 expectedError: expectedClientError,
4312 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004313 })
4314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: clientTest,
4317 name: "MinimumVersion-Client2-" + suffix,
4318 config: Config{
4319 MaxVersion: runnerVers.version,
4320 },
David Benjamin87909c02014-12-13 01:55:01 -05004321 flags: []string{"-min-version", shimVersFlag},
4322 expectedVersion: expectedVersion,
4323 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004324 expectedError: expectedClientError,
4325 expectedLocalError: expectedClientLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004326 })
4327
4328 testCases = append(testCases, testCase{
4329 protocol: protocol,
4330 testType: serverTest,
4331 name: "MinimumVersion-Server-" + suffix,
4332 config: Config{
4333 MaxVersion: runnerVers.version,
4334 },
David Benjamin87909c02014-12-13 01:55:01 -05004335 flags: flags,
4336 expectedVersion: expectedVersion,
4337 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004338 expectedError: expectedServerError,
4339 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004340 })
4341 testCases = append(testCases, testCase{
4342 protocol: protocol,
4343 testType: serverTest,
4344 name: "MinimumVersion-Server2-" + suffix,
4345 config: Config{
4346 MaxVersion: runnerVers.version,
4347 },
David Benjamin87909c02014-12-13 01:55:01 -05004348 flags: []string{"-min-version", shimVersFlag},
4349 expectedVersion: expectedVersion,
4350 shouldFail: shouldFail,
David Benjamin929d4ee2016-06-24 23:55:58 -04004351 expectedError: expectedServerError,
4352 expectedLocalError: expectedServerLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004353 })
4354 }
4355 }
4356 }
4357}
4358
David Benjamine78bfde2014-09-06 12:45:15 -04004359func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004360 // TODO(davidben): Extensions, where applicable, all move their server
4361 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4362 // tests for both. Also test interaction with 0-RTT when implemented.
4363
David Benjamin97d17d92016-07-14 16:12:00 -04004364 // Repeat extensions tests all versions except SSL 3.0.
4365 for _, ver := range tlsVersions {
4366 if ver.version == VersionSSL30 {
4367 continue
4368 }
4369
David Benjamin97d17d92016-07-14 16:12:00 -04004370 // Test that duplicate extensions are rejected.
4371 testCases = append(testCases, testCase{
4372 testType: clientTest,
4373 name: "DuplicateExtensionClient-" + ver.name,
4374 config: Config{
4375 MaxVersion: ver.version,
4376 Bugs: ProtocolBugs{
4377 DuplicateExtension: true,
4378 },
David Benjamine78bfde2014-09-06 12:45:15 -04004379 },
David Benjamin97d17d92016-07-14 16:12:00 -04004380 shouldFail: true,
4381 expectedLocalError: "remote error: error decoding message",
4382 })
4383 testCases = append(testCases, testCase{
4384 testType: serverTest,
4385 name: "DuplicateExtensionServer-" + ver.name,
4386 config: Config{
4387 MaxVersion: ver.version,
4388 Bugs: ProtocolBugs{
4389 DuplicateExtension: true,
4390 },
David Benjamine78bfde2014-09-06 12:45:15 -04004391 },
David Benjamin97d17d92016-07-14 16:12:00 -04004392 shouldFail: true,
4393 expectedLocalError: "remote error: error decoding message",
4394 })
4395
4396 // Test SNI.
4397 testCases = append(testCases, testCase{
4398 testType: clientTest,
4399 name: "ServerNameExtensionClient-" + ver.name,
4400 config: Config{
4401 MaxVersion: ver.version,
4402 Bugs: ProtocolBugs{
4403 ExpectServerName: "example.com",
4404 },
David Benjamine78bfde2014-09-06 12:45:15 -04004405 },
David Benjamin97d17d92016-07-14 16:12:00 -04004406 flags: []string{"-host-name", "example.com"},
4407 })
4408 testCases = append(testCases, testCase{
4409 testType: clientTest,
4410 name: "ServerNameExtensionClientMismatch-" + ver.name,
4411 config: Config{
4412 MaxVersion: ver.version,
4413 Bugs: ProtocolBugs{
4414 ExpectServerName: "mismatch.com",
4415 },
David Benjamine78bfde2014-09-06 12:45:15 -04004416 },
David Benjamin97d17d92016-07-14 16:12:00 -04004417 flags: []string{"-host-name", "example.com"},
4418 shouldFail: true,
4419 expectedLocalError: "tls: unexpected server name",
4420 })
4421 testCases = append(testCases, testCase{
4422 testType: clientTest,
4423 name: "ServerNameExtensionClientMissing-" + ver.name,
4424 config: Config{
4425 MaxVersion: ver.version,
4426 Bugs: ProtocolBugs{
4427 ExpectServerName: "missing.com",
4428 },
David Benjamine78bfde2014-09-06 12:45:15 -04004429 },
David Benjamin97d17d92016-07-14 16:12:00 -04004430 shouldFail: true,
4431 expectedLocalError: "tls: unexpected server name",
4432 })
4433 testCases = append(testCases, testCase{
4434 testType: serverTest,
4435 name: "ServerNameExtensionServer-" + ver.name,
4436 config: Config{
4437 MaxVersion: ver.version,
4438 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004439 },
David Benjamin97d17d92016-07-14 16:12:00 -04004440 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004441 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004442 })
4443
4444 // Test ALPN.
4445 testCases = append(testCases, testCase{
4446 testType: clientTest,
4447 name: "ALPNClient-" + ver.name,
4448 config: Config{
4449 MaxVersion: ver.version,
4450 NextProtos: []string{"foo"},
4451 },
4452 flags: []string{
4453 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4454 "-expect-alpn", "foo",
4455 },
4456 expectedNextProto: "foo",
4457 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004458 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004459 })
4460 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004461 testType: clientTest,
4462 name: "ALPNClient-Mismatch-" + ver.name,
4463 config: Config{
4464 MaxVersion: ver.version,
4465 Bugs: ProtocolBugs{
4466 SendALPN: "baz",
4467 },
4468 },
4469 flags: []string{
4470 "-advertise-alpn", "\x03foo\x03bar",
4471 },
4472 shouldFail: true,
4473 expectedError: ":INVALID_ALPN_PROTOCOL:",
4474 expectedLocalError: "remote error: illegal parameter",
4475 })
4476 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004477 testType: serverTest,
4478 name: "ALPNServer-" + ver.name,
4479 config: Config{
4480 MaxVersion: ver.version,
4481 NextProtos: []string{"foo", "bar", "baz"},
4482 },
4483 flags: []string{
4484 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4485 "-select-alpn", "foo",
4486 },
4487 expectedNextProto: "foo",
4488 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004489 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004490 })
4491 testCases = append(testCases, testCase{
4492 testType: serverTest,
4493 name: "ALPNServer-Decline-" + ver.name,
4494 config: Config{
4495 MaxVersion: ver.version,
4496 NextProtos: []string{"foo", "bar", "baz"},
4497 },
4498 flags: []string{"-decline-alpn"},
4499 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004500 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004501 })
4502
David Benjamin25fe85b2016-08-09 20:00:32 -04004503 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4504 // called once.
4505 testCases = append(testCases, testCase{
4506 testType: serverTest,
4507 name: "ALPNServer-Async-" + ver.name,
4508 config: Config{
4509 MaxVersion: ver.version,
4510 NextProtos: []string{"foo", "bar", "baz"},
4511 },
4512 flags: []string{
4513 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4514 "-select-alpn", "foo",
4515 "-async",
4516 },
4517 expectedNextProto: "foo",
4518 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004519 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004520 })
4521
David Benjamin97d17d92016-07-14 16:12:00 -04004522 var emptyString string
4523 testCases = append(testCases, testCase{
4524 testType: clientTest,
4525 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4526 config: Config{
4527 MaxVersion: ver.version,
4528 NextProtos: []string{""},
4529 Bugs: ProtocolBugs{
4530 // A server returning an empty ALPN protocol
4531 // should be rejected.
4532 ALPNProtocol: &emptyString,
4533 },
4534 },
4535 flags: []string{
4536 "-advertise-alpn", "\x03foo",
4537 },
4538 shouldFail: true,
4539 expectedError: ":PARSE_TLSEXT:",
4540 })
4541 testCases = append(testCases, testCase{
4542 testType: serverTest,
4543 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4544 config: Config{
4545 MaxVersion: ver.version,
4546 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004547 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004548 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004549 },
David Benjamin97d17d92016-07-14 16:12:00 -04004550 flags: []string{
4551 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004552 },
David Benjamin97d17d92016-07-14 16:12:00 -04004553 shouldFail: true,
4554 expectedError: ":PARSE_TLSEXT:",
4555 })
4556
4557 // Test NPN and the interaction with ALPN.
4558 if ver.version < VersionTLS13 {
4559 // Test that the server prefers ALPN over NPN.
4560 testCases = append(testCases, testCase{
4561 testType: serverTest,
4562 name: "ALPNServer-Preferred-" + ver.name,
4563 config: Config{
4564 MaxVersion: ver.version,
4565 NextProtos: []string{"foo", "bar", "baz"},
4566 },
4567 flags: []string{
4568 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4569 "-select-alpn", "foo",
4570 "-advertise-npn", "\x03foo\x03bar\x03baz",
4571 },
4572 expectedNextProto: "foo",
4573 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004574 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004575 })
4576 testCases = append(testCases, testCase{
4577 testType: serverTest,
4578 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4579 config: Config{
4580 MaxVersion: ver.version,
4581 NextProtos: []string{"foo", "bar", "baz"},
4582 Bugs: ProtocolBugs{
4583 SwapNPNAndALPN: true,
4584 },
4585 },
4586 flags: []string{
4587 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4588 "-select-alpn", "foo",
4589 "-advertise-npn", "\x03foo\x03bar\x03baz",
4590 },
4591 expectedNextProto: "foo",
4592 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004593 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004594 })
4595
4596 // Test that negotiating both NPN and ALPN is forbidden.
4597 testCases = append(testCases, testCase{
4598 name: "NegotiateALPNAndNPN-" + ver.name,
4599 config: Config{
4600 MaxVersion: ver.version,
4601 NextProtos: []string{"foo", "bar", "baz"},
4602 Bugs: ProtocolBugs{
4603 NegotiateALPNAndNPN: true,
4604 },
4605 },
4606 flags: []string{
4607 "-advertise-alpn", "\x03foo",
4608 "-select-next-proto", "foo",
4609 },
4610 shouldFail: true,
4611 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4612 })
4613 testCases = append(testCases, testCase{
4614 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4615 config: Config{
4616 MaxVersion: ver.version,
4617 NextProtos: []string{"foo", "bar", "baz"},
4618 Bugs: ProtocolBugs{
4619 NegotiateALPNAndNPN: true,
4620 SwapNPNAndALPN: true,
4621 },
4622 },
4623 flags: []string{
4624 "-advertise-alpn", "\x03foo",
4625 "-select-next-proto", "foo",
4626 },
4627 shouldFail: true,
4628 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4629 })
4630
4631 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4632 testCases = append(testCases, testCase{
4633 name: "DisableNPN-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 NextProtos: []string{"foo"},
4637 },
4638 flags: []string{
4639 "-select-next-proto", "foo",
4640 "-disable-npn",
4641 },
4642 expectNoNextProto: true,
4643 })
4644 }
4645
4646 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004647
4648 // Resume with a corrupt ticket.
4649 testCases = append(testCases, testCase{
4650 testType: serverTest,
4651 name: "CorruptTicket-" + ver.name,
4652 config: Config{
4653 MaxVersion: ver.version,
4654 Bugs: ProtocolBugs{
4655 CorruptTicket: true,
4656 },
4657 },
4658 resumeSession: true,
4659 expectResumeRejected: true,
4660 })
4661 // Test the ticket callback, with and without renewal.
4662 testCases = append(testCases, testCase{
4663 testType: serverTest,
4664 name: "TicketCallback-" + ver.name,
4665 config: Config{
4666 MaxVersion: ver.version,
4667 },
4668 resumeSession: true,
4669 flags: []string{"-use-ticket-callback"},
4670 })
4671 testCases = append(testCases, testCase{
4672 testType: serverTest,
4673 name: "TicketCallback-Renew-" + ver.name,
4674 config: Config{
4675 MaxVersion: ver.version,
4676 Bugs: ProtocolBugs{
4677 ExpectNewTicket: true,
4678 },
4679 },
4680 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4681 resumeSession: true,
4682 })
4683
4684 // Test that the ticket callback is only called once when everything before
4685 // it in the ClientHello is asynchronous. This corrupts the ticket so
4686 // certificate selection callbacks run.
4687 testCases = append(testCases, testCase{
4688 testType: serverTest,
4689 name: "TicketCallback-SingleCall-" + ver.name,
4690 config: Config{
4691 MaxVersion: ver.version,
4692 Bugs: ProtocolBugs{
4693 CorruptTicket: true,
4694 },
4695 },
4696 resumeSession: true,
4697 expectResumeRejected: true,
4698 flags: []string{
4699 "-use-ticket-callback",
4700 "-async",
4701 },
4702 })
4703
4704 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004705 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004706 testCases = append(testCases, testCase{
4707 testType: serverTest,
4708 name: "OversizedSessionId-" + ver.name,
4709 config: Config{
4710 MaxVersion: ver.version,
4711 Bugs: ProtocolBugs{
4712 OversizedSessionId: true,
4713 },
4714 },
4715 resumeSession: true,
4716 shouldFail: true,
4717 expectedError: ":DECODE_ERROR:",
4718 })
4719 }
4720
4721 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4722 // are ignored.
4723 if ver.hasDTLS {
4724 testCases = append(testCases, testCase{
4725 protocol: dtls,
4726 name: "SRTP-Client-" + ver.name,
4727 config: Config{
4728 MaxVersion: ver.version,
4729 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4730 },
4731 flags: []string{
4732 "-srtp-profiles",
4733 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4734 },
4735 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4736 })
4737 testCases = append(testCases, testCase{
4738 protocol: dtls,
4739 testType: serverTest,
4740 name: "SRTP-Server-" + ver.name,
4741 config: Config{
4742 MaxVersion: ver.version,
4743 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4744 },
4745 flags: []string{
4746 "-srtp-profiles",
4747 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4748 },
4749 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4750 })
4751 // Test that the MKI is ignored.
4752 testCases = append(testCases, testCase{
4753 protocol: dtls,
4754 testType: serverTest,
4755 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4759 Bugs: ProtocolBugs{
4760 SRTPMasterKeyIdentifer: "bogus",
4761 },
4762 },
4763 flags: []string{
4764 "-srtp-profiles",
4765 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4766 },
4767 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4768 })
4769 // Test that SRTP isn't negotiated on the server if there were
4770 // no matching profiles.
4771 testCases = append(testCases, testCase{
4772 protocol: dtls,
4773 testType: serverTest,
4774 name: "SRTP-Server-NoMatch-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 SRTPProtectionProfiles: []uint16{100, 101, 102},
4778 },
4779 flags: []string{
4780 "-srtp-profiles",
4781 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4782 },
4783 expectedSRTPProtectionProfile: 0,
4784 })
4785 // Test that the server returning an invalid SRTP profile is
4786 // flagged as an error by the client.
4787 testCases = append(testCases, testCase{
4788 protocol: dtls,
4789 name: "SRTP-Client-NoMatch-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 Bugs: ProtocolBugs{
4793 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4794 },
4795 },
4796 flags: []string{
4797 "-srtp-profiles",
4798 "SRTP_AES128_CM_SHA1_80",
4799 },
4800 shouldFail: true,
4801 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
4802 })
4803 }
4804
4805 // Test SCT list.
4806 testCases = append(testCases, testCase{
4807 name: "SignedCertificateTimestampList-Client-" + ver.name,
4808 testType: clientTest,
4809 config: Config{
4810 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04004811 },
David Benjamin97d17d92016-07-14 16:12:00 -04004812 flags: []string{
4813 "-enable-signed-cert-timestamps",
4814 "-expect-signed-cert-timestamps",
4815 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004816 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004817 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004818 })
4819 testCases = append(testCases, testCase{
4820 name: "SendSCTListOnResume-" + ver.name,
4821 config: Config{
4822 MaxVersion: ver.version,
4823 Bugs: ProtocolBugs{
4824 SendSCTListOnResume: []byte("bogus"),
4825 },
David Benjamind98452d2015-06-16 14:16:23 -04004826 },
David Benjamin97d17d92016-07-14 16:12:00 -04004827 flags: []string{
4828 "-enable-signed-cert-timestamps",
4829 "-expect-signed-cert-timestamps",
4830 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07004831 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004832 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004833 })
4834 testCases = append(testCases, testCase{
4835 name: "SignedCertificateTimestampList-Server-" + ver.name,
4836 testType: serverTest,
4837 config: Config{
4838 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05004839 },
David Benjamin97d17d92016-07-14 16:12:00 -04004840 flags: []string{
4841 "-signed-cert-timestamps",
4842 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05004843 },
David Benjamin97d17d92016-07-14 16:12:00 -04004844 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004845 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004846 })
4847 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04004848
Paul Lietar4fac72e2015-09-09 13:44:55 +01004849 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07004850 testType: clientTest,
4851 name: "ClientHelloPadding",
4852 config: Config{
4853 Bugs: ProtocolBugs{
4854 RequireClientHelloSize: 512,
4855 },
4856 },
4857 // This hostname just needs to be long enough to push the
4858 // ClientHello into F5's danger zone between 256 and 511 bytes
4859 // long.
4860 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
4861 })
David Benjaminc7ce9772015-10-09 19:32:41 -04004862
4863 // Extensions should not function in SSL 3.0.
4864 testCases = append(testCases, testCase{
4865 testType: serverTest,
4866 name: "SSLv3Extensions-NoALPN",
4867 config: Config{
4868 MaxVersion: VersionSSL30,
4869 NextProtos: []string{"foo", "bar", "baz"},
4870 },
4871 flags: []string{
4872 "-select-alpn", "foo",
4873 },
4874 expectNoNextProto: true,
4875 })
4876
4877 // Test session tickets separately as they follow a different codepath.
4878 testCases = append(testCases, testCase{
4879 testType: serverTest,
4880 name: "SSLv3Extensions-NoTickets",
4881 config: Config{
4882 MaxVersion: VersionSSL30,
4883 Bugs: ProtocolBugs{
4884 // Historically, session tickets in SSL 3.0
4885 // failed in different ways depending on whether
4886 // the client supported renegotiation_info.
4887 NoRenegotiationInfo: true,
4888 },
4889 },
4890 resumeSession: true,
4891 })
4892 testCases = append(testCases, testCase{
4893 testType: serverTest,
4894 name: "SSLv3Extensions-NoTickets2",
4895 config: Config{
4896 MaxVersion: VersionSSL30,
4897 },
4898 resumeSession: true,
4899 })
4900
4901 // But SSL 3.0 does send and process renegotiation_info.
4902 testCases = append(testCases, testCase{
4903 testType: serverTest,
4904 name: "SSLv3Extensions-RenegotiationInfo",
4905 config: Config{
4906 MaxVersion: VersionSSL30,
4907 Bugs: ProtocolBugs{
4908 RequireRenegotiationInfo: true,
4909 },
4910 },
4911 })
4912 testCases = append(testCases, testCase{
4913 testType: serverTest,
4914 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
4915 config: Config{
4916 MaxVersion: VersionSSL30,
4917 Bugs: ProtocolBugs{
4918 NoRenegotiationInfo: true,
4919 SendRenegotiationSCSV: true,
4920 RequireRenegotiationInfo: true,
4921 },
4922 },
4923 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004924
4925 // Test that illegal extensions in TLS 1.3 are rejected by the client if
4926 // in ServerHello.
4927 testCases = append(testCases, testCase{
4928 name: "NPN-Forbidden-TLS13",
4929 config: Config{
4930 MaxVersion: VersionTLS13,
4931 NextProtos: []string{"foo"},
4932 Bugs: ProtocolBugs{
4933 NegotiateNPNAtAllVersions: true,
4934 },
4935 },
4936 flags: []string{"-select-next-proto", "foo"},
4937 shouldFail: true,
4938 expectedError: ":ERROR_PARSING_EXTENSION:",
4939 })
4940 testCases = append(testCases, testCase{
4941 name: "EMS-Forbidden-TLS13",
4942 config: Config{
4943 MaxVersion: VersionTLS13,
4944 Bugs: ProtocolBugs{
4945 NegotiateEMSAtAllVersions: true,
4946 },
4947 },
4948 shouldFail: true,
4949 expectedError: ":ERROR_PARSING_EXTENSION:",
4950 })
4951 testCases = append(testCases, testCase{
4952 name: "RenegotiationInfo-Forbidden-TLS13",
4953 config: Config{
4954 MaxVersion: VersionTLS13,
4955 Bugs: ProtocolBugs{
4956 NegotiateRenegotiationInfoAtAllVersions: true,
4957 },
4958 },
4959 shouldFail: true,
4960 expectedError: ":ERROR_PARSING_EXTENSION:",
4961 })
4962 testCases = append(testCases, testCase{
4963 name: "ChannelID-Forbidden-TLS13",
4964 config: Config{
4965 MaxVersion: VersionTLS13,
4966 RequestChannelID: true,
4967 Bugs: ProtocolBugs{
4968 NegotiateChannelIDAtAllVersions: true,
4969 },
4970 },
4971 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4972 shouldFail: true,
4973 expectedError: ":ERROR_PARSING_EXTENSION:",
4974 })
4975 testCases = append(testCases, testCase{
4976 name: "Ticket-Forbidden-TLS13",
4977 config: Config{
4978 MaxVersion: VersionTLS12,
4979 },
4980 resumeConfig: &Config{
4981 MaxVersion: VersionTLS13,
4982 Bugs: ProtocolBugs{
4983 AdvertiseTicketExtension: true,
4984 },
4985 },
4986 resumeSession: true,
4987 shouldFail: true,
4988 expectedError: ":ERROR_PARSING_EXTENSION:",
4989 })
4990
4991 // Test that illegal extensions in TLS 1.3 are declined by the server if
4992 // offered in ClientHello. The runner's server will fail if this occurs,
4993 // so we exercise the offering path. (EMS and Renegotiation Info are
4994 // implicit in every test.)
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "ChannelID-Declined-TLS13",
4998 config: Config{
4999 MaxVersion: VersionTLS13,
5000 ChannelID: channelIDKey,
5001 },
5002 flags: []string{"-enable-channel-id"},
5003 })
5004 testCases = append(testCases, testCase{
5005 testType: serverTest,
5006 name: "NPN-Server",
5007 config: Config{
5008 MaxVersion: VersionTLS13,
5009 NextProtos: []string{"bar"},
5010 },
5011 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5012 })
David Benjamin196df5b2016-09-21 16:23:27 -04005013
5014 testCases = append(testCases, testCase{
5015 testType: serverTest,
5016 name: "InvalidChannelIDSignature",
5017 config: Config{
5018 MaxVersion: VersionTLS12,
5019 ChannelID: channelIDKey,
5020 Bugs: ProtocolBugs{
5021 InvalidChannelIDSignature: true,
5022 },
5023 },
5024 flags: []string{"-enable-channel-id"},
5025 shouldFail: true,
5026 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5027 expectedLocalError: "remote error: error decrypting message",
5028 })
David Benjamine78bfde2014-09-06 12:45:15 -04005029}
5030
David Benjamin01fe8202014-09-24 15:21:44 -04005031func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005032 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005033 for _, resumeVers := range tlsVersions {
Nick Harper1fd39d82016-06-14 18:14:35 -07005034 cipher := TLS_RSA_WITH_AES_128_CBC_SHA
5035 if sessionVers.version >= VersionTLS13 || resumeVers.version >= VersionTLS13 {
5036 // TLS 1.3 only shares ciphers with TLS 1.2, so
5037 // we skip certain combinations and use a
5038 // different cipher to test with.
5039 cipher = TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
5040 if sessionVers.version < VersionTLS12 || resumeVers.version < VersionTLS12 {
5041 continue
5042 }
5043 }
5044
David Benjamin8b8c0062014-11-23 02:47:52 -05005045 protocols := []protocol{tls}
5046 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5047 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005048 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005049 for _, protocol := range protocols {
5050 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5051 if protocol == dtls {
5052 suffix += "-DTLS"
5053 }
5054
David Benjaminece3de92015-03-16 18:02:20 -04005055 if sessionVers.version == resumeVers.version {
5056 testCases = append(testCases, testCase{
5057 protocol: protocol,
5058 name: "Resume-Client" + suffix,
5059 resumeSession: true,
5060 config: Config{
5061 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005062 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005063 Bugs: ProtocolBugs{
5064 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5065 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5066 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005067 },
David Benjaminece3de92015-03-16 18:02:20 -04005068 expectedVersion: sessionVers.version,
5069 expectedResumeVersion: resumeVers.version,
5070 })
5071 } else {
David Benjamin405da482016-08-08 17:25:07 -04005072 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5073
5074 // Offering a TLS 1.3 session sends an empty session ID, so
5075 // there is no way to convince a non-lookahead client the
5076 // session was resumed. It will appear to the client that a
5077 // stray ChangeCipherSpec was sent.
5078 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5079 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005080 }
5081
David Benjaminece3de92015-03-16 18:02:20 -04005082 testCases = append(testCases, testCase{
5083 protocol: protocol,
5084 name: "Resume-Client-Mismatch" + suffix,
5085 resumeSession: true,
5086 config: Config{
5087 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005088 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005089 },
David Benjaminece3de92015-03-16 18:02:20 -04005090 expectedVersion: sessionVers.version,
5091 resumeConfig: &Config{
5092 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005093 CipherSuites: []uint16{cipher},
David Benjaminece3de92015-03-16 18:02:20 -04005094 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005095 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005096 },
5097 },
5098 expectedResumeVersion: resumeVers.version,
5099 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005100 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005101 })
5102 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005103
5104 testCases = append(testCases, testCase{
5105 protocol: protocol,
5106 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005107 resumeSession: true,
5108 config: Config{
5109 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005110 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005111 },
5112 expectedVersion: sessionVers.version,
5113 resumeConfig: &Config{
5114 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005115 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005116 },
5117 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005118 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005119 expectedResumeVersion: resumeVers.version,
5120 })
5121
David Benjamin8b8c0062014-11-23 02:47:52 -05005122 testCases = append(testCases, testCase{
5123 protocol: protocol,
5124 testType: serverTest,
5125 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005126 resumeSession: true,
5127 config: Config{
5128 MaxVersion: sessionVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005129 CipherSuites: []uint16{cipher},
David Benjamin8b8c0062014-11-23 02:47:52 -05005130 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005131 expectedVersion: sessionVers.version,
5132 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005133 resumeConfig: &Config{
5134 MaxVersion: resumeVers.version,
Nick Harper1fd39d82016-06-14 18:14:35 -07005135 CipherSuites: []uint16{cipher},
David Benjamin405da482016-08-08 17:25:07 -04005136 Bugs: ProtocolBugs{
5137 SendBothTickets: true,
5138 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005139 },
5140 expectedResumeVersion: resumeVers.version,
5141 })
5142 }
David Benjamin01fe8202014-09-24 15:21:44 -04005143 }
5144 }
David Benjaminece3de92015-03-16 18:02:20 -04005145
5146 testCases = append(testCases, testCase{
5147 name: "Resume-Client-CipherMismatch",
5148 resumeSession: true,
5149 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005150 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005151 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5152 },
5153 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005154 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005155 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5156 Bugs: ProtocolBugs{
5157 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5158 },
5159 },
5160 shouldFail: true,
5161 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5162 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005163
5164 testCases = append(testCases, testCase{
5165 name: "Resume-Client-CipherMismatch-TLS13",
5166 resumeSession: true,
5167 config: Config{
5168 MaxVersion: VersionTLS13,
5169 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5170 },
5171 resumeConfig: &Config{
5172 MaxVersion: VersionTLS13,
5173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5174 Bugs: ProtocolBugs{
5175 SendCipherSuite: TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA,
5176 },
5177 },
5178 shouldFail: true,
5179 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5180 })
David Benjamin01fe8202014-09-24 15:21:44 -04005181}
5182
Adam Langley2ae77d22014-10-28 17:29:33 -07005183func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005184 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005185 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005186 testType: serverTest,
5187 name: "Renegotiate-Server-Forbidden",
5188 config: Config{
5189 MaxVersion: VersionTLS12,
5190 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005191 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005192 shouldFail: true,
5193 expectedError: ":NO_RENEGOTIATION:",
5194 expectedLocalError: "remote error: no renegotiation",
5195 })
Adam Langley5021b222015-06-12 18:27:58 -07005196 // The server shouldn't echo the renegotiation extension unless
5197 // requested by the client.
5198 testCases = append(testCases, testCase{
5199 testType: serverTest,
5200 name: "Renegotiate-Server-NoExt",
5201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005202 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005203 Bugs: ProtocolBugs{
5204 NoRenegotiationInfo: true,
5205 RequireRenegotiationInfo: true,
5206 },
5207 },
5208 shouldFail: true,
5209 expectedLocalError: "renegotiation extension missing",
5210 })
5211 // The renegotiation SCSV should be sufficient for the server to echo
5212 // the extension.
5213 testCases = append(testCases, testCase{
5214 testType: serverTest,
5215 name: "Renegotiate-Server-NoExt-SCSV",
5216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005217 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005218 Bugs: ProtocolBugs{
5219 NoRenegotiationInfo: true,
5220 SendRenegotiationSCSV: true,
5221 RequireRenegotiationInfo: true,
5222 },
5223 },
5224 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005225 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005226 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005227 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005228 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005229 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005230 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005231 },
5232 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005233 renegotiate: 1,
5234 flags: []string{
5235 "-renegotiate-freely",
5236 "-expect-total-renegotiations", "1",
5237 },
David Benjamincdea40c2015-03-19 14:09:43 -04005238 })
5239 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005240 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005241 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005242 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005243 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005244 Bugs: ProtocolBugs{
5245 EmptyRenegotiationInfo: true,
5246 },
5247 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005248 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005249 shouldFail: true,
5250 expectedError: ":RENEGOTIATION_MISMATCH:",
5251 })
5252 testCases = append(testCases, testCase{
5253 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005254 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005255 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005256 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005257 Bugs: ProtocolBugs{
5258 BadRenegotiationInfo: true,
5259 },
5260 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005261 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005262 shouldFail: true,
5263 expectedError: ":RENEGOTIATION_MISMATCH:",
5264 })
5265 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005266 name: "Renegotiate-Client-Downgrade",
5267 renegotiate: 1,
5268 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005269 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005270 Bugs: ProtocolBugs{
5271 NoRenegotiationInfoAfterInitial: true,
5272 },
5273 },
5274 flags: []string{"-renegotiate-freely"},
5275 shouldFail: true,
5276 expectedError: ":RENEGOTIATION_MISMATCH:",
5277 })
5278 testCases = append(testCases, testCase{
5279 name: "Renegotiate-Client-Upgrade",
5280 renegotiate: 1,
5281 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005282 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005283 Bugs: ProtocolBugs{
5284 NoRenegotiationInfoInInitial: true,
5285 },
5286 },
5287 flags: []string{"-renegotiate-freely"},
5288 shouldFail: true,
5289 expectedError: ":RENEGOTIATION_MISMATCH:",
5290 })
5291 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005292 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005293 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005295 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005296 Bugs: ProtocolBugs{
5297 NoRenegotiationInfo: true,
5298 },
5299 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005300 flags: []string{
5301 "-renegotiate-freely",
5302 "-expect-total-renegotiations", "1",
5303 },
David Benjamincff0b902015-05-15 23:09:47 -04005304 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005305
5306 // Test that the server may switch ciphers on renegotiation without
5307 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005308 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005309 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005310 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005311 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005312 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005313 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005314 },
5315 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005316 flags: []string{
5317 "-renegotiate-freely",
5318 "-expect-total-renegotiations", "1",
5319 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005320 })
5321 testCases = append(testCases, testCase{
5322 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005323 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005324 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005325 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005326 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5327 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005328 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005329 flags: []string{
5330 "-renegotiate-freely",
5331 "-expect-total-renegotiations", "1",
5332 },
David Benjaminb16346b2015-04-08 19:16:58 -04005333 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005334
5335 // Test that the server may not switch versions on renegotiation.
5336 testCases = append(testCases, testCase{
5337 name: "Renegotiate-Client-SwitchVersion",
5338 config: Config{
5339 MaxVersion: VersionTLS12,
5340 // Pick a cipher which exists at both versions.
5341 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5342 Bugs: ProtocolBugs{
5343 NegotiateVersionOnRenego: VersionTLS11,
5344 },
5345 },
5346 renegotiate: 1,
5347 flags: []string{
5348 "-renegotiate-freely",
5349 "-expect-total-renegotiations", "1",
5350 },
5351 shouldFail: true,
5352 expectedError: ":WRONG_SSL_VERSION:",
5353 })
5354
David Benjaminb16346b2015-04-08 19:16:58 -04005355 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005356 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005357 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005358 config: Config{
5359 MaxVersion: VersionTLS10,
5360 Bugs: ProtocolBugs{
5361 RequireSameRenegoClientVersion: true,
5362 },
5363 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005364 flags: []string{
5365 "-renegotiate-freely",
5366 "-expect-total-renegotiations", "1",
5367 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005368 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005369 testCases = append(testCases, testCase{
5370 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005371 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005372 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005373 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005374 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5375 NextProtos: []string{"foo"},
5376 },
5377 flags: []string{
5378 "-false-start",
5379 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005380 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005381 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005382 },
5383 shimWritesFirst: true,
5384 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005385
5386 // Client-side renegotiation controls.
5387 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005388 name: "Renegotiate-Client-Forbidden-1",
5389 config: Config{
5390 MaxVersion: VersionTLS12,
5391 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005392 renegotiate: 1,
5393 shouldFail: true,
5394 expectedError: ":NO_RENEGOTIATION:",
5395 expectedLocalError: "remote error: no renegotiation",
5396 })
5397 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005398 name: "Renegotiate-Client-Once-1",
5399 config: Config{
5400 MaxVersion: VersionTLS12,
5401 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005402 renegotiate: 1,
5403 flags: []string{
5404 "-renegotiate-once",
5405 "-expect-total-renegotiations", "1",
5406 },
5407 })
5408 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005409 name: "Renegotiate-Client-Freely-1",
5410 config: Config{
5411 MaxVersion: VersionTLS12,
5412 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005413 renegotiate: 1,
5414 flags: []string{
5415 "-renegotiate-freely",
5416 "-expect-total-renegotiations", "1",
5417 },
5418 })
5419 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005420 name: "Renegotiate-Client-Once-2",
5421 config: Config{
5422 MaxVersion: VersionTLS12,
5423 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005424 renegotiate: 2,
5425 flags: []string{"-renegotiate-once"},
5426 shouldFail: true,
5427 expectedError: ":NO_RENEGOTIATION:",
5428 expectedLocalError: "remote error: no renegotiation",
5429 })
5430 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005431 name: "Renegotiate-Client-Freely-2",
5432 config: Config{
5433 MaxVersion: VersionTLS12,
5434 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005435 renegotiate: 2,
5436 flags: []string{
5437 "-renegotiate-freely",
5438 "-expect-total-renegotiations", "2",
5439 },
5440 })
Adam Langley27a0d082015-11-03 13:34:10 -08005441 testCases = append(testCases, testCase{
5442 name: "Renegotiate-Client-NoIgnore",
5443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005444 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005445 Bugs: ProtocolBugs{
5446 SendHelloRequestBeforeEveryAppDataRecord: true,
5447 },
5448 },
5449 shouldFail: true,
5450 expectedError: ":NO_RENEGOTIATION:",
5451 })
5452 testCases = append(testCases, testCase{
5453 name: "Renegotiate-Client-Ignore",
5454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005455 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005456 Bugs: ProtocolBugs{
5457 SendHelloRequestBeforeEveryAppDataRecord: true,
5458 },
5459 },
5460 flags: []string{
5461 "-renegotiate-ignore",
5462 "-expect-total-renegotiations", "0",
5463 },
5464 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005465
David Benjamin397c8e62016-07-08 14:14:36 -07005466 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005467 testCases = append(testCases, testCase{
5468 name: "StrayHelloRequest",
5469 config: Config{
5470 MaxVersion: VersionTLS12,
5471 Bugs: ProtocolBugs{
5472 SendHelloRequestBeforeEveryHandshakeMessage: true,
5473 },
5474 },
5475 })
5476 testCases = append(testCases, testCase{
5477 name: "StrayHelloRequest-Packed",
5478 config: Config{
5479 MaxVersion: VersionTLS12,
5480 Bugs: ProtocolBugs{
5481 PackHandshakeFlight: true,
5482 SendHelloRequestBeforeEveryHandshakeMessage: true,
5483 },
5484 },
5485 })
5486
David Benjamin12d2c482016-07-24 10:56:51 -04005487 // Test renegotiation works if HelloRequest and server Finished come in
5488 // the same record.
5489 testCases = append(testCases, testCase{
5490 name: "Renegotiate-Client-Packed",
5491 config: Config{
5492 MaxVersion: VersionTLS12,
5493 Bugs: ProtocolBugs{
5494 PackHandshakeFlight: true,
5495 PackHelloRequestWithFinished: true,
5496 },
5497 },
5498 renegotiate: 1,
5499 flags: []string{
5500 "-renegotiate-freely",
5501 "-expect-total-renegotiations", "1",
5502 },
5503 })
5504
David Benjamin397c8e62016-07-08 14:14:36 -07005505 // Renegotiation is forbidden in TLS 1.3.
5506 testCases = append(testCases, testCase{
5507 name: "Renegotiate-Client-TLS13",
5508 config: Config{
5509 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005510 Bugs: ProtocolBugs{
5511 SendHelloRequestBeforeEveryAppDataRecord: true,
5512 },
David Benjamin397c8e62016-07-08 14:14:36 -07005513 },
David Benjamin397c8e62016-07-08 14:14:36 -07005514 flags: []string{
5515 "-renegotiate-freely",
5516 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005517 shouldFail: true,
5518 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005519 })
5520
5521 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5522 testCases = append(testCases, testCase{
5523 name: "StrayHelloRequest-TLS13",
5524 config: Config{
5525 MaxVersion: VersionTLS13,
5526 Bugs: ProtocolBugs{
5527 SendHelloRequestBeforeEveryHandshakeMessage: true,
5528 },
5529 },
5530 shouldFail: true,
5531 expectedError: ":UNEXPECTED_MESSAGE:",
5532 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005533}
5534
David Benjamin5e961c12014-11-07 01:48:35 -05005535func addDTLSReplayTests() {
5536 // Test that sequence number replays are detected.
5537 testCases = append(testCases, testCase{
5538 protocol: dtls,
5539 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005540 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005541 replayWrites: true,
5542 })
5543
David Benjamin8e6db492015-07-25 18:29:23 -04005544 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005545 // than the retransmit window.
5546 testCases = append(testCases, testCase{
5547 protocol: dtls,
5548 name: "DTLS-Replay-LargeGaps",
5549 config: Config{
5550 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005551 SequenceNumberMapping: func(in uint64) uint64 {
5552 return in * 127
5553 },
David Benjamin5e961c12014-11-07 01:48:35 -05005554 },
5555 },
David Benjamin8e6db492015-07-25 18:29:23 -04005556 messageCount: 200,
5557 replayWrites: true,
5558 })
5559
5560 // Test the incoming sequence number changing non-monotonically.
5561 testCases = append(testCases, testCase{
5562 protocol: dtls,
5563 name: "DTLS-Replay-NonMonotonic",
5564 config: Config{
5565 Bugs: ProtocolBugs{
5566 SequenceNumberMapping: func(in uint64) uint64 {
5567 return in ^ 31
5568 },
5569 },
5570 },
5571 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005572 replayWrites: true,
5573 })
5574}
5575
Nick Harper60edffd2016-06-21 15:19:24 -07005576var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005577 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005578 id signatureAlgorithm
5579 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005580}{
Nick Harper60edffd2016-06-21 15:19:24 -07005581 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5582 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5583 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5584 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005585 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005586 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5587 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5588 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005589 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5590 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5591 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005592 // Tests for key types prior to TLS 1.2.
5593 {"RSA", 0, testCertRSA},
5594 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005595}
5596
Nick Harper60edffd2016-06-21 15:19:24 -07005597const fakeSigAlg1 signatureAlgorithm = 0x2a01
5598const fakeSigAlg2 signatureAlgorithm = 0xff01
5599
5600func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005601 // Not all ciphers involve a signature. Advertise a list which gives all
5602 // versions a signing cipher.
5603 signingCiphers := []uint16{
5604 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5605 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5606 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5607 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5608 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5609 }
5610
David Benjaminca3d5452016-07-14 12:51:01 -04005611 var allAlgorithms []signatureAlgorithm
5612 for _, alg := range testSignatureAlgorithms {
5613 if alg.id != 0 {
5614 allAlgorithms = append(allAlgorithms, alg.id)
5615 }
5616 }
5617
Nick Harper60edffd2016-06-21 15:19:24 -07005618 // Make sure each signature algorithm works. Include some fake values in
5619 // the list and ensure they're ignored.
5620 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005621 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005622 if (ver.version < VersionTLS12) != (alg.id == 0) {
5623 continue
5624 }
5625
5626 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5627 // or remove it in C.
5628 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005629 continue
5630 }
Nick Harper60edffd2016-06-21 15:19:24 -07005631
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005632 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005633 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005634 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5635 shouldFail = true
5636 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005637 // RSA-PKCS1 does not exist in TLS 1.3.
5638 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5639 shouldFail = true
5640 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005641
5642 var signError, verifyError string
5643 if shouldFail {
5644 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5645 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005646 }
David Benjamin000800a2014-11-14 01:43:59 -05005647
David Benjamin1fb125c2016-07-08 18:52:12 -07005648 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005649
David Benjamin7a41d372016-07-09 11:21:54 -07005650 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005651 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005652 config: Config{
5653 MaxVersion: ver.version,
5654 ClientAuth: RequireAnyClientCert,
5655 VerifySignatureAlgorithms: []signatureAlgorithm{
5656 fakeSigAlg1,
5657 alg.id,
5658 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005659 },
David Benjamin7a41d372016-07-09 11:21:54 -07005660 },
5661 flags: []string{
5662 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5663 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5664 "-enable-all-curves",
5665 },
5666 shouldFail: shouldFail,
5667 expectedError: signError,
5668 expectedPeerSignatureAlgorithm: alg.id,
5669 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005670
David Benjamin7a41d372016-07-09 11:21:54 -07005671 testCases = append(testCases, testCase{
5672 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005673 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005674 config: Config{
5675 MaxVersion: ver.version,
5676 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5677 SignSignatureAlgorithms: []signatureAlgorithm{
5678 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005679 },
David Benjamin7a41d372016-07-09 11:21:54 -07005680 Bugs: ProtocolBugs{
5681 SkipECDSACurveCheck: shouldFail,
5682 IgnoreSignatureVersionChecks: shouldFail,
5683 // The client won't advertise 1.3-only algorithms after
5684 // version negotiation.
5685 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005686 },
David Benjamin7a41d372016-07-09 11:21:54 -07005687 },
5688 flags: []string{
5689 "-require-any-client-certificate",
5690 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5691 "-enable-all-curves",
5692 },
5693 shouldFail: shouldFail,
5694 expectedError: verifyError,
5695 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005696
5697 testCases = append(testCases, testCase{
5698 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005699 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005700 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005701 MaxVersion: ver.version,
5702 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005703 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005704 fakeSigAlg1,
5705 alg.id,
5706 fakeSigAlg2,
5707 },
5708 },
5709 flags: []string{
5710 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5711 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5712 "-enable-all-curves",
5713 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005714 shouldFail: shouldFail,
5715 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005716 expectedPeerSignatureAlgorithm: alg.id,
5717 })
5718
5719 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005720 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005721 config: Config{
5722 MaxVersion: ver.version,
5723 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005724 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005725 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005726 alg.id,
5727 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005728 Bugs: ProtocolBugs{
5729 SkipECDSACurveCheck: shouldFail,
5730 IgnoreSignatureVersionChecks: shouldFail,
5731 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005732 },
5733 flags: []string{
5734 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5735 "-enable-all-curves",
5736 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005737 shouldFail: shouldFail,
5738 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005739 })
David Benjamin5208fd42016-07-13 21:43:25 -04005740
5741 if !shouldFail {
5742 testCases = append(testCases, testCase{
5743 testType: serverTest,
5744 name: "ClientAuth-InvalidSignature" + suffix,
5745 config: Config{
5746 MaxVersion: ver.version,
5747 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5748 SignSignatureAlgorithms: []signatureAlgorithm{
5749 alg.id,
5750 },
5751 Bugs: ProtocolBugs{
5752 InvalidSignature: true,
5753 },
5754 },
5755 flags: []string{
5756 "-require-any-client-certificate",
5757 "-enable-all-curves",
5758 },
5759 shouldFail: true,
5760 expectedError: ":BAD_SIGNATURE:",
5761 })
5762
5763 testCases = append(testCases, testCase{
5764 name: "ServerAuth-InvalidSignature" + suffix,
5765 config: Config{
5766 MaxVersion: ver.version,
5767 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5768 CipherSuites: signingCiphers,
5769 SignSignatureAlgorithms: []signatureAlgorithm{
5770 alg.id,
5771 },
5772 Bugs: ProtocolBugs{
5773 InvalidSignature: true,
5774 },
5775 },
5776 flags: []string{"-enable-all-curves"},
5777 shouldFail: true,
5778 expectedError: ":BAD_SIGNATURE:",
5779 })
5780 }
David Benjaminca3d5452016-07-14 12:51:01 -04005781
5782 if ver.version >= VersionTLS12 && !shouldFail {
5783 testCases = append(testCases, testCase{
5784 name: "ClientAuth-Sign-Negotiate" + suffix,
5785 config: Config{
5786 MaxVersion: ver.version,
5787 ClientAuth: RequireAnyClientCert,
5788 VerifySignatureAlgorithms: allAlgorithms,
5789 },
5790 flags: []string{
5791 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5792 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5793 "-enable-all-curves",
5794 "-signing-prefs", strconv.Itoa(int(alg.id)),
5795 },
5796 expectedPeerSignatureAlgorithm: alg.id,
5797 })
5798
5799 testCases = append(testCases, testCase{
5800 testType: serverTest,
5801 name: "ServerAuth-Sign-Negotiate" + suffix,
5802 config: Config{
5803 MaxVersion: ver.version,
5804 CipherSuites: signingCiphers,
5805 VerifySignatureAlgorithms: allAlgorithms,
5806 },
5807 flags: []string{
5808 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5809 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5810 "-enable-all-curves",
5811 "-signing-prefs", strconv.Itoa(int(alg.id)),
5812 },
5813 expectedPeerSignatureAlgorithm: alg.id,
5814 })
5815 }
David Benjamin1fb125c2016-07-08 18:52:12 -07005816 }
David Benjamin000800a2014-11-14 01:43:59 -05005817 }
5818
Nick Harper60edffd2016-06-21 15:19:24 -07005819 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05005820 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005821 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005822 config: Config{
5823 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04005824 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005825 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005826 signatureECDSAWithP521AndSHA512,
5827 signatureRSAPKCS1WithSHA384,
5828 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005829 },
5830 },
5831 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005832 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5833 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005834 },
Nick Harper60edffd2016-06-21 15:19:24 -07005835 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005836 })
5837
5838 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005839 name: "ClientAuth-SignatureType-TLS13",
5840 config: Config{
5841 ClientAuth: RequireAnyClientCert,
5842 MaxVersion: VersionTLS13,
5843 VerifySignatureAlgorithms: []signatureAlgorithm{
5844 signatureECDSAWithP521AndSHA512,
5845 signatureRSAPKCS1WithSHA384,
5846 signatureRSAPSSWithSHA384,
5847 signatureECDSAWithSHA1,
5848 },
5849 },
5850 flags: []string{
5851 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5852 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5853 },
5854 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5855 })
5856
5857 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05005858 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005859 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05005860 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005861 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005862 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005863 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005864 signatureECDSAWithP521AndSHA512,
5865 signatureRSAPKCS1WithSHA384,
5866 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005867 },
5868 },
Nick Harper60edffd2016-06-21 15:19:24 -07005869 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05005870 })
5871
Steven Valdez143e8b32016-07-11 13:19:03 -04005872 testCases = append(testCases, testCase{
5873 testType: serverTest,
5874 name: "ServerAuth-SignatureType-TLS13",
5875 config: Config{
5876 MaxVersion: VersionTLS13,
5877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5878 VerifySignatureAlgorithms: []signatureAlgorithm{
5879 signatureECDSAWithP521AndSHA512,
5880 signatureRSAPKCS1WithSHA384,
5881 signatureRSAPSSWithSHA384,
5882 signatureECDSAWithSHA1,
5883 },
5884 },
5885 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
5886 })
5887
David Benjamina95e9f32016-07-08 16:28:04 -07005888 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07005889 testCases = append(testCases, testCase{
5890 testType: serverTest,
5891 name: "Verify-ClientAuth-SignatureType",
5892 config: Config{
5893 MaxVersion: VersionTLS12,
5894 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07005895 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005896 signatureRSAPKCS1WithSHA256,
5897 },
5898 Bugs: ProtocolBugs{
5899 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5900 },
5901 },
5902 flags: []string{
5903 "-require-any-client-certificate",
5904 },
5905 shouldFail: true,
5906 expectedError: ":WRONG_SIGNATURE_TYPE:",
5907 })
5908
5909 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005910 testType: serverTest,
5911 name: "Verify-ClientAuth-SignatureType-TLS13",
5912 config: Config{
5913 MaxVersion: VersionTLS13,
5914 Certificates: []Certificate{rsaCertificate},
5915 SignSignatureAlgorithms: []signatureAlgorithm{
5916 signatureRSAPSSWithSHA256,
5917 },
5918 Bugs: ProtocolBugs{
5919 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5920 },
5921 },
5922 flags: []string{
5923 "-require-any-client-certificate",
5924 },
5925 shouldFail: true,
5926 expectedError: ":WRONG_SIGNATURE_TYPE:",
5927 })
5928
5929 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005930 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07005931 config: Config{
5932 MaxVersion: VersionTLS12,
5933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07005934 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07005935 signatureRSAPKCS1WithSHA256,
5936 },
5937 Bugs: ProtocolBugs{
5938 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5939 },
5940 },
5941 shouldFail: true,
5942 expectedError: ":WRONG_SIGNATURE_TYPE:",
5943 })
5944
Steven Valdez143e8b32016-07-11 13:19:03 -04005945 testCases = append(testCases, testCase{
5946 name: "Verify-ServerAuth-SignatureType-TLS13",
5947 config: Config{
5948 MaxVersion: VersionTLS13,
5949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5950 SignSignatureAlgorithms: []signatureAlgorithm{
5951 signatureRSAPSSWithSHA256,
5952 },
5953 Bugs: ProtocolBugs{
5954 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
5955 },
5956 },
5957 shouldFail: true,
5958 expectedError: ":WRONG_SIGNATURE_TYPE:",
5959 })
5960
David Benjamin51dd7d62016-07-08 16:07:01 -07005961 // Test that, if the list is missing, the peer falls back to SHA-1 in
5962 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05005963 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04005964 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005966 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05005967 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07005968 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005969 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005970 },
5971 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005972 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005973 },
5974 },
5975 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07005976 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5977 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05005978 },
5979 })
5980
5981 testCases = append(testCases, testCase{
5982 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04005983 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05005984 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04005985 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07005986 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07005987 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05005988 },
5989 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07005990 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05005991 },
5992 },
David Benjaminee32bea2016-08-17 13:36:44 -04005993 flags: []string{
5994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5996 },
5997 })
5998
5999 testCases = append(testCases, testCase{
6000 name: "ClientAuth-SHA1-Fallback-ECDSA",
6001 config: Config{
6002 MaxVersion: VersionTLS12,
6003 ClientAuth: RequireAnyClientCert,
6004 VerifySignatureAlgorithms: []signatureAlgorithm{
6005 signatureECDSAWithSHA1,
6006 },
6007 Bugs: ProtocolBugs{
6008 NoSignatureAlgorithms: true,
6009 },
6010 },
6011 flags: []string{
6012 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6013 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6014 },
6015 })
6016
6017 testCases = append(testCases, testCase{
6018 testType: serverTest,
6019 name: "ServerAuth-SHA1-Fallback-ECDSA",
6020 config: Config{
6021 MaxVersion: VersionTLS12,
6022 VerifySignatureAlgorithms: []signatureAlgorithm{
6023 signatureECDSAWithSHA1,
6024 },
6025 Bugs: ProtocolBugs{
6026 NoSignatureAlgorithms: true,
6027 },
6028 },
6029 flags: []string{
6030 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6031 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6032 },
David Benjamin000800a2014-11-14 01:43:59 -05006033 })
David Benjamin72dc7832015-03-16 17:49:43 -04006034
David Benjamin51dd7d62016-07-08 16:07:01 -07006035 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006036 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006037 config: Config{
6038 MaxVersion: VersionTLS13,
6039 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006040 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006041 signatureRSAPKCS1WithSHA1,
6042 },
6043 Bugs: ProtocolBugs{
6044 NoSignatureAlgorithms: true,
6045 },
6046 },
6047 flags: []string{
6048 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6049 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6050 },
David Benjamin48901652016-08-01 12:12:47 -04006051 shouldFail: true,
6052 // An empty CertificateRequest signature algorithm list is a
6053 // syntax error in TLS 1.3.
6054 expectedError: ":DECODE_ERROR:",
6055 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006056 })
6057
6058 testCases = append(testCases, testCase{
6059 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006060 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006061 config: Config{
6062 MaxVersion: VersionTLS13,
6063 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006064 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006065 signatureRSAPKCS1WithSHA1,
6066 },
6067 Bugs: ProtocolBugs{
6068 NoSignatureAlgorithms: true,
6069 },
6070 },
6071 shouldFail: true,
6072 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6073 })
6074
David Benjaminb62d2872016-07-18 14:55:02 +02006075 // Test that hash preferences are enforced. BoringSSL does not implement
6076 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006077 testCases = append(testCases, testCase{
6078 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006079 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006081 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006082 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006083 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006084 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006085 },
6086 Bugs: ProtocolBugs{
6087 IgnorePeerSignatureAlgorithmPreferences: true,
6088 },
6089 },
6090 flags: []string{"-require-any-client-certificate"},
6091 shouldFail: true,
6092 expectedError: ":WRONG_SIGNATURE_TYPE:",
6093 })
6094
6095 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006096 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006098 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006099 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006100 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006101 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006102 },
6103 Bugs: ProtocolBugs{
6104 IgnorePeerSignatureAlgorithmPreferences: true,
6105 },
6106 },
6107 shouldFail: true,
6108 expectedError: ":WRONG_SIGNATURE_TYPE:",
6109 })
David Benjaminb62d2872016-07-18 14:55:02 +02006110 testCases = append(testCases, testCase{
6111 testType: serverTest,
6112 name: "ClientAuth-Enforced-TLS13",
6113 config: Config{
6114 MaxVersion: VersionTLS13,
6115 Certificates: []Certificate{rsaCertificate},
6116 SignSignatureAlgorithms: []signatureAlgorithm{
6117 signatureRSAPKCS1WithMD5,
6118 },
6119 Bugs: ProtocolBugs{
6120 IgnorePeerSignatureAlgorithmPreferences: true,
6121 IgnoreSignatureVersionChecks: true,
6122 },
6123 },
6124 flags: []string{"-require-any-client-certificate"},
6125 shouldFail: true,
6126 expectedError: ":WRONG_SIGNATURE_TYPE:",
6127 })
6128
6129 testCases = append(testCases, testCase{
6130 name: "ServerAuth-Enforced-TLS13",
6131 config: Config{
6132 MaxVersion: VersionTLS13,
6133 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6134 SignSignatureAlgorithms: []signatureAlgorithm{
6135 signatureRSAPKCS1WithMD5,
6136 },
6137 Bugs: ProtocolBugs{
6138 IgnorePeerSignatureAlgorithmPreferences: true,
6139 IgnoreSignatureVersionChecks: true,
6140 },
6141 },
6142 shouldFail: true,
6143 expectedError: ":WRONG_SIGNATURE_TYPE:",
6144 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006145
6146 // Test that the agreed upon digest respects the client preferences and
6147 // the server digests.
6148 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006149 name: "NoCommonAlgorithms-Digests",
6150 config: Config{
6151 MaxVersion: VersionTLS12,
6152 ClientAuth: RequireAnyClientCert,
6153 VerifySignatureAlgorithms: []signatureAlgorithm{
6154 signatureRSAPKCS1WithSHA512,
6155 signatureRSAPKCS1WithSHA1,
6156 },
6157 },
6158 flags: []string{
6159 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6160 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6161 "-digest-prefs", "SHA256",
6162 },
6163 shouldFail: true,
6164 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6165 })
6166 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006167 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006169 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006170 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006171 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006172 signatureRSAPKCS1WithSHA512,
6173 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006174 },
6175 },
6176 flags: []string{
6177 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6178 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006179 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006180 },
David Benjaminca3d5452016-07-14 12:51:01 -04006181 shouldFail: true,
6182 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6183 })
6184 testCases = append(testCases, testCase{
6185 name: "NoCommonAlgorithms-TLS13",
6186 config: Config{
6187 MaxVersion: VersionTLS13,
6188 ClientAuth: RequireAnyClientCert,
6189 VerifySignatureAlgorithms: []signatureAlgorithm{
6190 signatureRSAPSSWithSHA512,
6191 signatureRSAPSSWithSHA384,
6192 },
6193 },
6194 flags: []string{
6195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6197 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6198 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006199 shouldFail: true,
6200 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006201 })
6202 testCases = append(testCases, testCase{
6203 name: "Agree-Digest-SHA256",
6204 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006205 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006206 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006207 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006208 signatureRSAPKCS1WithSHA1,
6209 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006210 },
6211 },
6212 flags: []string{
6213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006215 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006216 },
Nick Harper60edffd2016-06-21 15:19:24 -07006217 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006218 })
6219 testCases = append(testCases, testCase{
6220 name: "Agree-Digest-SHA1",
6221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006222 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006223 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006224 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006225 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006226 },
6227 },
6228 flags: []string{
6229 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6230 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006231 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006232 },
Nick Harper60edffd2016-06-21 15:19:24 -07006233 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006234 })
6235 testCases = append(testCases, testCase{
6236 name: "Agree-Digest-Default",
6237 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006238 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006239 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006240 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006241 signatureRSAPKCS1WithSHA256,
6242 signatureECDSAWithP256AndSHA256,
6243 signatureRSAPKCS1WithSHA1,
6244 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006245 },
6246 },
6247 flags: []string{
6248 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6249 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6250 },
Nick Harper60edffd2016-06-21 15:19:24 -07006251 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006252 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006253
David Benjaminca3d5452016-07-14 12:51:01 -04006254 // Test that the signing preference list may include extra algorithms
6255 // without negotiation problems.
6256 testCases = append(testCases, testCase{
6257 testType: serverTest,
6258 name: "FilterExtraAlgorithms",
6259 config: Config{
6260 MaxVersion: VersionTLS12,
6261 VerifySignatureAlgorithms: []signatureAlgorithm{
6262 signatureRSAPKCS1WithSHA256,
6263 },
6264 },
6265 flags: []string{
6266 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6267 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6268 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6269 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6270 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6271 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6272 },
6273 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6274 })
6275
David Benjamin4c3ddf72016-06-29 18:13:53 -04006276 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6277 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006278 testCases = append(testCases, testCase{
6279 name: "CheckLeafCurve",
6280 config: Config{
6281 MaxVersion: VersionTLS12,
6282 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006283 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006284 },
6285 flags: []string{"-p384-only"},
6286 shouldFail: true,
6287 expectedError: ":BAD_ECC_CERT:",
6288 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006289
6290 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6291 testCases = append(testCases, testCase{
6292 name: "CheckLeafCurve-TLS13",
6293 config: Config{
6294 MaxVersion: VersionTLS13,
6295 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6296 Certificates: []Certificate{ecdsaP256Certificate},
6297 },
6298 flags: []string{"-p384-only"},
6299 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006300
6301 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6302 testCases = append(testCases, testCase{
6303 name: "ECDSACurveMismatch-Verify-TLS12",
6304 config: Config{
6305 MaxVersion: VersionTLS12,
6306 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6307 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006308 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006309 signatureECDSAWithP384AndSHA384,
6310 },
6311 },
6312 })
6313
6314 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6315 testCases = append(testCases, testCase{
6316 name: "ECDSACurveMismatch-Verify-TLS13",
6317 config: Config{
6318 MaxVersion: VersionTLS13,
6319 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6320 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006321 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006322 signatureECDSAWithP384AndSHA384,
6323 },
6324 Bugs: ProtocolBugs{
6325 SkipECDSACurveCheck: true,
6326 },
6327 },
6328 shouldFail: true,
6329 expectedError: ":WRONG_SIGNATURE_TYPE:",
6330 })
6331
6332 // Signature algorithm selection in TLS 1.3 should take the curve into
6333 // account.
6334 testCases = append(testCases, testCase{
6335 testType: serverTest,
6336 name: "ECDSACurveMismatch-Sign-TLS13",
6337 config: Config{
6338 MaxVersion: VersionTLS13,
6339 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006340 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006341 signatureECDSAWithP384AndSHA384,
6342 signatureECDSAWithP256AndSHA256,
6343 },
6344 },
6345 flags: []string{
6346 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6347 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6348 },
6349 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6350 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006351
6352 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6353 // server does not attempt to sign in that case.
6354 testCases = append(testCases, testCase{
6355 testType: serverTest,
6356 name: "RSA-PSS-Large",
6357 config: Config{
6358 MaxVersion: VersionTLS13,
6359 VerifySignatureAlgorithms: []signatureAlgorithm{
6360 signatureRSAPSSWithSHA512,
6361 },
6362 },
6363 flags: []string{
6364 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6365 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6366 },
6367 shouldFail: true,
6368 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6369 })
David Benjamin57e929f2016-08-30 00:30:38 -04006370
6371 // Test that RSA-PSS is enabled by default for TLS 1.2.
6372 testCases = append(testCases, testCase{
6373 testType: clientTest,
6374 name: "RSA-PSS-Default-Verify",
6375 config: Config{
6376 MaxVersion: VersionTLS12,
6377 SignSignatureAlgorithms: []signatureAlgorithm{
6378 signatureRSAPSSWithSHA256,
6379 },
6380 },
6381 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6382 })
6383
6384 testCases = append(testCases, testCase{
6385 testType: serverTest,
6386 name: "RSA-PSS-Default-Sign",
6387 config: Config{
6388 MaxVersion: VersionTLS12,
6389 VerifySignatureAlgorithms: []signatureAlgorithm{
6390 signatureRSAPSSWithSHA256,
6391 },
6392 },
6393 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6394 })
David Benjamin000800a2014-11-14 01:43:59 -05006395}
6396
David Benjamin83f90402015-01-27 01:09:43 -05006397// timeouts is the retransmit schedule for BoringSSL. It doubles and
6398// caps at 60 seconds. On the 13th timeout, it gives up.
6399var timeouts = []time.Duration{
6400 1 * time.Second,
6401 2 * time.Second,
6402 4 * time.Second,
6403 8 * time.Second,
6404 16 * time.Second,
6405 32 * time.Second,
6406 60 * time.Second,
6407 60 * time.Second,
6408 60 * time.Second,
6409 60 * time.Second,
6410 60 * time.Second,
6411 60 * time.Second,
6412 60 * time.Second,
6413}
6414
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006415// shortTimeouts is an alternate set of timeouts which would occur if the
6416// initial timeout duration was set to 250ms.
6417var shortTimeouts = []time.Duration{
6418 250 * time.Millisecond,
6419 500 * time.Millisecond,
6420 1 * time.Second,
6421 2 * time.Second,
6422 4 * time.Second,
6423 8 * time.Second,
6424 16 * time.Second,
6425 32 * time.Second,
6426 60 * time.Second,
6427 60 * time.Second,
6428 60 * time.Second,
6429 60 * time.Second,
6430 60 * time.Second,
6431}
6432
David Benjamin83f90402015-01-27 01:09:43 -05006433func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006434 // These tests work by coordinating some behavior on both the shim and
6435 // the runner.
6436 //
6437 // TimeoutSchedule configures the runner to send a series of timeout
6438 // opcodes to the shim (see packetAdaptor) immediately before reading
6439 // each peer handshake flight N. The timeout opcode both simulates a
6440 // timeout in the shim and acts as a synchronization point to help the
6441 // runner bracket each handshake flight.
6442 //
6443 // We assume the shim does not read from the channel eagerly. It must
6444 // first wait until it has sent flight N and is ready to receive
6445 // handshake flight N+1. At this point, it will process the timeout
6446 // opcode. It must then immediately respond with a timeout ACK and act
6447 // as if the shim was idle for the specified amount of time.
6448 //
6449 // The runner then drops all packets received before the ACK and
6450 // continues waiting for flight N. This ordering results in one attempt
6451 // at sending flight N to be dropped. For the test to complete, the
6452 // shim must send flight N again, testing that the shim implements DTLS
6453 // retransmit on a timeout.
6454
Steven Valdez143e8b32016-07-11 13:19:03 -04006455 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006456 // likely be more epochs to cross and the final message's retransmit may
6457 // be more complex.
6458
David Benjamin585d7a42016-06-02 14:58:00 -04006459 for _, async := range []bool{true, false} {
6460 var tests []testCase
6461
6462 // Test that this is indeed the timeout schedule. Stress all
6463 // four patterns of handshake.
6464 for i := 1; i < len(timeouts); i++ {
6465 number := strconv.Itoa(i)
6466 tests = append(tests, testCase{
6467 protocol: dtls,
6468 name: "DTLS-Retransmit-Client-" + number,
6469 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006470 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006471 Bugs: ProtocolBugs{
6472 TimeoutSchedule: timeouts[:i],
6473 },
6474 },
6475 resumeSession: true,
6476 })
6477 tests = append(tests, testCase{
6478 protocol: dtls,
6479 testType: serverTest,
6480 name: "DTLS-Retransmit-Server-" + number,
6481 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006482 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006483 Bugs: ProtocolBugs{
6484 TimeoutSchedule: timeouts[:i],
6485 },
6486 },
6487 resumeSession: true,
6488 })
6489 }
6490
6491 // Test that exceeding the timeout schedule hits a read
6492 // timeout.
6493 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006494 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006495 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006497 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006498 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006499 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006500 },
6501 },
6502 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006503 shouldFail: true,
6504 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006505 })
David Benjamin585d7a42016-06-02 14:58:00 -04006506
6507 if async {
6508 // Test that timeout handling has a fudge factor, due to API
6509 // problems.
6510 tests = append(tests, testCase{
6511 protocol: dtls,
6512 name: "DTLS-Retransmit-Fudge",
6513 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006514 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006515 Bugs: ProtocolBugs{
6516 TimeoutSchedule: []time.Duration{
6517 timeouts[0] - 10*time.Millisecond,
6518 },
6519 },
6520 },
6521 resumeSession: true,
6522 })
6523 }
6524
6525 // Test that the final Finished retransmitting isn't
6526 // duplicated if the peer badly fragments everything.
6527 tests = append(tests, testCase{
6528 testType: serverTest,
6529 protocol: dtls,
6530 name: "DTLS-Retransmit-Fragmented",
6531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006532 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006533 Bugs: ProtocolBugs{
6534 TimeoutSchedule: []time.Duration{timeouts[0]},
6535 MaxHandshakeRecordLength: 2,
6536 },
6537 },
6538 })
6539
6540 // Test the timeout schedule when a shorter initial timeout duration is set.
6541 tests = append(tests, testCase{
6542 protocol: dtls,
6543 name: "DTLS-Retransmit-Short-Client",
6544 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006545 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006546 Bugs: ProtocolBugs{
6547 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6548 },
6549 },
6550 resumeSession: true,
6551 flags: []string{"-initial-timeout-duration-ms", "250"},
6552 })
6553 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006554 protocol: dtls,
6555 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006556 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006557 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006558 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006559 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006560 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006561 },
6562 },
6563 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006564 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006565 })
David Benjamin585d7a42016-06-02 14:58:00 -04006566
6567 for _, test := range tests {
6568 if async {
6569 test.name += "-Async"
6570 test.flags = append(test.flags, "-async")
6571 }
6572
6573 testCases = append(testCases, test)
6574 }
David Benjamin83f90402015-01-27 01:09:43 -05006575 }
David Benjamin83f90402015-01-27 01:09:43 -05006576}
6577
David Benjaminc565ebb2015-04-03 04:06:36 -04006578func addExportKeyingMaterialTests() {
6579 for _, vers := range tlsVersions {
6580 if vers.version == VersionSSL30 {
6581 continue
6582 }
6583 testCases = append(testCases, testCase{
6584 name: "ExportKeyingMaterial-" + vers.name,
6585 config: Config{
6586 MaxVersion: vers.version,
6587 },
6588 exportKeyingMaterial: 1024,
6589 exportLabel: "label",
6590 exportContext: "context",
6591 useExportContext: true,
6592 })
6593 testCases = append(testCases, testCase{
6594 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6595 config: Config{
6596 MaxVersion: vers.version,
6597 },
6598 exportKeyingMaterial: 1024,
6599 })
6600 testCases = append(testCases, testCase{
6601 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6602 config: Config{
6603 MaxVersion: vers.version,
6604 },
6605 exportKeyingMaterial: 1024,
6606 useExportContext: true,
6607 })
6608 testCases = append(testCases, testCase{
6609 name: "ExportKeyingMaterial-Small-" + vers.name,
6610 config: Config{
6611 MaxVersion: vers.version,
6612 },
6613 exportKeyingMaterial: 1,
6614 exportLabel: "label",
6615 exportContext: "context",
6616 useExportContext: true,
6617 })
6618 }
6619 testCases = append(testCases, testCase{
6620 name: "ExportKeyingMaterial-SSL3",
6621 config: Config{
6622 MaxVersion: VersionSSL30,
6623 },
6624 exportKeyingMaterial: 1024,
6625 exportLabel: "label",
6626 exportContext: "context",
6627 useExportContext: true,
6628 shouldFail: true,
6629 expectedError: "failed to export keying material",
6630 })
6631}
6632
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006633func addTLSUniqueTests() {
6634 for _, isClient := range []bool{false, true} {
6635 for _, isResumption := range []bool{false, true} {
6636 for _, hasEMS := range []bool{false, true} {
6637 var suffix string
6638 if isResumption {
6639 suffix = "Resume-"
6640 } else {
6641 suffix = "Full-"
6642 }
6643
6644 if hasEMS {
6645 suffix += "EMS-"
6646 } else {
6647 suffix += "NoEMS-"
6648 }
6649
6650 if isClient {
6651 suffix += "Client"
6652 } else {
6653 suffix += "Server"
6654 }
6655
6656 test := testCase{
6657 name: "TLSUnique-" + suffix,
6658 testTLSUnique: true,
6659 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006660 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006661 Bugs: ProtocolBugs{
6662 NoExtendedMasterSecret: !hasEMS,
6663 },
6664 },
6665 }
6666
6667 if isResumption {
6668 test.resumeSession = true
6669 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006670 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006671 Bugs: ProtocolBugs{
6672 NoExtendedMasterSecret: !hasEMS,
6673 },
6674 }
6675 }
6676
6677 if isResumption && !hasEMS {
6678 test.shouldFail = true
6679 test.expectedError = "failed to get tls-unique"
6680 }
6681
6682 testCases = append(testCases, test)
6683 }
6684 }
6685 }
6686}
6687
Adam Langley09505632015-07-30 18:10:13 -07006688func addCustomExtensionTests() {
6689 expectedContents := "custom extension"
6690 emptyString := ""
6691
6692 for _, isClient := range []bool{false, true} {
6693 suffix := "Server"
6694 flag := "-enable-server-custom-extension"
6695 testType := serverTest
6696 if isClient {
6697 suffix = "Client"
6698 flag = "-enable-client-custom-extension"
6699 testType = clientTest
6700 }
6701
6702 testCases = append(testCases, testCase{
6703 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006704 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006706 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006707 Bugs: ProtocolBugs{
6708 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006709 ExpectedCustomExtension: &expectedContents,
6710 },
6711 },
6712 flags: []string{flag},
6713 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006714 testCases = append(testCases, testCase{
6715 testType: testType,
6716 name: "CustomExtensions-" + suffix + "-TLS13",
6717 config: Config{
6718 MaxVersion: VersionTLS13,
6719 Bugs: ProtocolBugs{
6720 CustomExtension: expectedContents,
6721 ExpectedCustomExtension: &expectedContents,
6722 },
6723 },
6724 flags: []string{flag},
6725 })
Adam Langley09505632015-07-30 18:10:13 -07006726
6727 // If the parse callback fails, the handshake should also fail.
6728 testCases = append(testCases, testCase{
6729 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006730 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006731 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006732 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006733 Bugs: ProtocolBugs{
6734 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006735 ExpectedCustomExtension: &expectedContents,
6736 },
6737 },
David Benjamin399e7c92015-07-30 23:01:27 -04006738 flags: []string{flag},
6739 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006740 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6741 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006742 testCases = append(testCases, testCase{
6743 testType: testType,
6744 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6745 config: Config{
6746 MaxVersion: VersionTLS13,
6747 Bugs: ProtocolBugs{
6748 CustomExtension: expectedContents + "foo",
6749 ExpectedCustomExtension: &expectedContents,
6750 },
6751 },
6752 flags: []string{flag},
6753 shouldFail: true,
6754 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6755 })
Adam Langley09505632015-07-30 18:10:13 -07006756
6757 // If the add callback fails, the handshake should also fail.
6758 testCases = append(testCases, testCase{
6759 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006760 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006761 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006762 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006763 Bugs: ProtocolBugs{
6764 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006765 ExpectedCustomExtension: &expectedContents,
6766 },
6767 },
David Benjamin399e7c92015-07-30 23:01:27 -04006768 flags: []string{flag, "-custom-extension-fail-add"},
6769 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006770 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6771 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006772 testCases = append(testCases, testCase{
6773 testType: testType,
6774 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
6775 config: Config{
6776 MaxVersion: VersionTLS13,
6777 Bugs: ProtocolBugs{
6778 CustomExtension: expectedContents,
6779 ExpectedCustomExtension: &expectedContents,
6780 },
6781 },
6782 flags: []string{flag, "-custom-extension-fail-add"},
6783 shouldFail: true,
6784 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6785 })
Adam Langley09505632015-07-30 18:10:13 -07006786
6787 // If the add callback returns zero, no extension should be
6788 // added.
6789 skipCustomExtension := expectedContents
6790 if isClient {
6791 // For the case where the client skips sending the
6792 // custom extension, the server must not “echo” it.
6793 skipCustomExtension = ""
6794 }
6795 testCases = append(testCases, testCase{
6796 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006797 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006799 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006800 Bugs: ProtocolBugs{
6801 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07006802 ExpectedCustomExtension: &emptyString,
6803 },
6804 },
6805 flags: []string{flag, "-custom-extension-skip"},
6806 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006807 testCases = append(testCases, testCase{
6808 testType: testType,
6809 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
6810 config: Config{
6811 MaxVersion: VersionTLS13,
6812 Bugs: ProtocolBugs{
6813 CustomExtension: skipCustomExtension,
6814 ExpectedCustomExtension: &emptyString,
6815 },
6816 },
6817 flags: []string{flag, "-custom-extension-skip"},
6818 })
Adam Langley09505632015-07-30 18:10:13 -07006819 }
6820
6821 // The custom extension add callback should not be called if the client
6822 // doesn't send the extension.
6823 testCases = append(testCases, testCase{
6824 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04006825 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07006826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006827 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006828 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07006829 ExpectedCustomExtension: &emptyString,
6830 },
6831 },
6832 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6833 })
Adam Langley2deb9842015-08-07 11:15:37 -07006834
Steven Valdez143e8b32016-07-11 13:19:03 -04006835 testCases = append(testCases, testCase{
6836 testType: serverTest,
6837 name: "CustomExtensions-NotCalled-Server-TLS13",
6838 config: Config{
6839 MaxVersion: VersionTLS13,
6840 Bugs: ProtocolBugs{
6841 ExpectedCustomExtension: &emptyString,
6842 },
6843 },
6844 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
6845 })
6846
Adam Langley2deb9842015-08-07 11:15:37 -07006847 // Test an unknown extension from the server.
6848 testCases = append(testCases, testCase{
6849 testType: clientTest,
6850 name: "UnknownExtension-Client",
6851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006852 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07006853 Bugs: ProtocolBugs{
6854 CustomExtension: expectedContents,
6855 },
6856 },
David Benjamin0c40a962016-08-01 12:05:50 -04006857 shouldFail: true,
6858 expectedError: ":UNEXPECTED_EXTENSION:",
6859 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07006860 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006861 testCases = append(testCases, testCase{
6862 testType: clientTest,
6863 name: "UnknownExtension-Client-TLS13",
6864 config: Config{
6865 MaxVersion: VersionTLS13,
6866 Bugs: ProtocolBugs{
6867 CustomExtension: expectedContents,
6868 },
6869 },
David Benjamin0c40a962016-08-01 12:05:50 -04006870 shouldFail: true,
6871 expectedError: ":UNEXPECTED_EXTENSION:",
6872 expectedLocalError: "remote error: unsupported extension",
6873 })
6874
6875 // Test a known but unoffered extension from the server.
6876 testCases = append(testCases, testCase{
6877 testType: clientTest,
6878 name: "UnofferedExtension-Client",
6879 config: Config{
6880 MaxVersion: VersionTLS12,
6881 Bugs: ProtocolBugs{
6882 SendALPN: "alpn",
6883 },
6884 },
6885 shouldFail: true,
6886 expectedError: ":UNEXPECTED_EXTENSION:",
6887 expectedLocalError: "remote error: unsupported extension",
6888 })
6889 testCases = append(testCases, testCase{
6890 testType: clientTest,
6891 name: "UnofferedExtension-Client-TLS13",
6892 config: Config{
6893 MaxVersion: VersionTLS13,
6894 Bugs: ProtocolBugs{
6895 SendALPN: "alpn",
6896 },
6897 },
6898 shouldFail: true,
6899 expectedError: ":UNEXPECTED_EXTENSION:",
6900 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04006901 })
Adam Langley09505632015-07-30 18:10:13 -07006902}
6903
David Benjaminb36a3952015-12-01 18:53:13 -05006904func addRSAClientKeyExchangeTests() {
6905 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
6906 testCases = append(testCases, testCase{
6907 testType: serverTest,
6908 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
6909 config: Config{
6910 // Ensure the ClientHello version and final
6911 // version are different, to detect if the
6912 // server uses the wrong one.
6913 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006914 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05006915 Bugs: ProtocolBugs{
6916 BadRSAClientKeyExchange: bad,
6917 },
6918 },
6919 shouldFail: true,
6920 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
6921 })
6922 }
David Benjamine63d9d72016-09-19 18:27:34 -04006923
6924 // The server must compare whatever was in ClientHello.version for the
6925 // RSA premaster.
6926 testCases = append(testCases, testCase{
6927 testType: serverTest,
6928 name: "SendClientVersion-RSA",
6929 config: Config{
6930 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6931 Bugs: ProtocolBugs{
6932 SendClientVersion: 0x1234,
6933 },
6934 },
6935 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6936 })
David Benjaminb36a3952015-12-01 18:53:13 -05006937}
6938
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006939var testCurves = []struct {
6940 name string
6941 id CurveID
6942}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006943 {"P-256", CurveP256},
6944 {"P-384", CurveP384},
6945 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05006946 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006947}
6948
Steven Valdez5440fe02016-07-18 12:40:30 -04006949const bogusCurve = 0x1234
6950
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006951func addCurveTests() {
6952 for _, curve := range testCurves {
6953 testCases = append(testCases, testCase{
6954 name: "CurveTest-Client-" + curve.name,
6955 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006956 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006957 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6958 CurvePreferences: []CurveID{curve.id},
6959 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006960 flags: []string{
6961 "-enable-all-curves",
6962 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6963 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006964 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006965 })
6966 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006967 name: "CurveTest-Client-" + curve.name + "-TLS13",
6968 config: Config{
6969 MaxVersion: VersionTLS13,
6970 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6971 CurvePreferences: []CurveID{curve.id},
6972 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006973 flags: []string{
6974 "-enable-all-curves",
6975 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6976 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006977 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04006978 })
6979 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006980 testType: serverTest,
6981 name: "CurveTest-Server-" + curve.name,
6982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006983 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006984 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6985 CurvePreferences: []CurveID{curve.id},
6986 },
David Benjamin5c4e8572016-08-19 17:44:53 -04006987 flags: []string{
6988 "-enable-all-curves",
6989 "-expect-curve-id", strconv.Itoa(int(curve.id)),
6990 },
Steven Valdez5440fe02016-07-18 12:40:30 -04006991 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05006992 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006993 testCases = append(testCases, testCase{
6994 testType: serverTest,
6995 name: "CurveTest-Server-" + curve.name + "-TLS13",
6996 config: Config{
6997 MaxVersion: VersionTLS13,
6998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6999 CurvePreferences: []CurveID{curve.id},
7000 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007001 flags: []string{
7002 "-enable-all-curves",
7003 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7004 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007005 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007006 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007007 }
David Benjamin241ae832016-01-15 03:04:54 -05007008
7009 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007010 testCases = append(testCases, testCase{
7011 testType: serverTest,
7012 name: "UnknownCurve",
7013 config: Config{
7014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7015 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7016 },
7017 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007018
7019 // The server must not consider ECDHE ciphers when there are no
7020 // supported curves.
7021 testCases = append(testCases, testCase{
7022 testType: serverTest,
7023 name: "NoSupportedCurves",
7024 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007025 MaxVersion: VersionTLS12,
7026 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7027 Bugs: ProtocolBugs{
7028 NoSupportedCurves: true,
7029 },
7030 },
7031 shouldFail: true,
7032 expectedError: ":NO_SHARED_CIPHER:",
7033 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007034 testCases = append(testCases, testCase{
7035 testType: serverTest,
7036 name: "NoSupportedCurves-TLS13",
7037 config: Config{
7038 MaxVersion: VersionTLS13,
7039 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7040 Bugs: ProtocolBugs{
7041 NoSupportedCurves: true,
7042 },
7043 },
7044 shouldFail: true,
7045 expectedError: ":NO_SHARED_CIPHER:",
7046 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007047
7048 // The server must fall back to another cipher when there are no
7049 // supported curves.
7050 testCases = append(testCases, testCase{
7051 testType: serverTest,
7052 name: "NoCommonCurves",
7053 config: Config{
7054 MaxVersion: VersionTLS12,
7055 CipherSuites: []uint16{
7056 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7057 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7058 },
7059 CurvePreferences: []CurveID{CurveP224},
7060 },
7061 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7062 })
7063
7064 // The client must reject bogus curves and disabled curves.
7065 testCases = append(testCases, testCase{
7066 name: "BadECDHECurve",
7067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007068 MaxVersion: VersionTLS12,
7069 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7070 Bugs: ProtocolBugs{
7071 SendCurve: bogusCurve,
7072 },
7073 },
7074 shouldFail: true,
7075 expectedError: ":WRONG_CURVE:",
7076 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007077 testCases = append(testCases, testCase{
7078 name: "BadECDHECurve-TLS13",
7079 config: Config{
7080 MaxVersion: VersionTLS13,
7081 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7082 Bugs: ProtocolBugs{
7083 SendCurve: bogusCurve,
7084 },
7085 },
7086 shouldFail: true,
7087 expectedError: ":WRONG_CURVE:",
7088 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007089
7090 testCases = append(testCases, testCase{
7091 name: "UnsupportedCurve",
7092 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007093 MaxVersion: VersionTLS12,
7094 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7095 CurvePreferences: []CurveID{CurveP256},
7096 Bugs: ProtocolBugs{
7097 IgnorePeerCurvePreferences: true,
7098 },
7099 },
7100 flags: []string{"-p384-only"},
7101 shouldFail: true,
7102 expectedError: ":WRONG_CURVE:",
7103 })
7104
David Benjamin4f921572016-07-17 14:20:10 +02007105 testCases = append(testCases, testCase{
7106 // TODO(davidben): Add a TLS 1.3 version where
7107 // HelloRetryRequest requests an unsupported curve.
7108 name: "UnsupportedCurve-ServerHello-TLS13",
7109 config: Config{
7110 MaxVersion: VersionTLS12,
7111 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7112 CurvePreferences: []CurveID{CurveP384},
7113 Bugs: ProtocolBugs{
7114 SendCurve: CurveP256,
7115 },
7116 },
7117 flags: []string{"-p384-only"},
7118 shouldFail: true,
7119 expectedError: ":WRONG_CURVE:",
7120 })
7121
David Benjamin4c3ddf72016-06-29 18:13:53 -04007122 // Test invalid curve points.
7123 testCases = append(testCases, testCase{
7124 name: "InvalidECDHPoint-Client",
7125 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007126 MaxVersion: VersionTLS12,
7127 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7128 CurvePreferences: []CurveID{CurveP256},
7129 Bugs: ProtocolBugs{
7130 InvalidECDHPoint: true,
7131 },
7132 },
7133 shouldFail: true,
7134 expectedError: ":INVALID_ENCODING:",
7135 })
7136 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007137 name: "InvalidECDHPoint-Client-TLS13",
7138 config: Config{
7139 MaxVersion: VersionTLS13,
7140 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7141 CurvePreferences: []CurveID{CurveP256},
7142 Bugs: ProtocolBugs{
7143 InvalidECDHPoint: true,
7144 },
7145 },
7146 shouldFail: true,
7147 expectedError: ":INVALID_ENCODING:",
7148 })
7149 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007150 testType: serverTest,
7151 name: "InvalidECDHPoint-Server",
7152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007153 MaxVersion: VersionTLS12,
7154 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7155 CurvePreferences: []CurveID{CurveP256},
7156 Bugs: ProtocolBugs{
7157 InvalidECDHPoint: true,
7158 },
7159 },
7160 shouldFail: true,
7161 expectedError: ":INVALID_ENCODING:",
7162 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007163 testCases = append(testCases, testCase{
7164 testType: serverTest,
7165 name: "InvalidECDHPoint-Server-TLS13",
7166 config: Config{
7167 MaxVersion: VersionTLS13,
7168 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7169 CurvePreferences: []CurveID{CurveP256},
7170 Bugs: ProtocolBugs{
7171 InvalidECDHPoint: true,
7172 },
7173 },
7174 shouldFail: true,
7175 expectedError: ":INVALID_ENCODING:",
7176 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007177}
7178
Matt Braithwaite54217e42016-06-13 13:03:47 -07007179func addCECPQ1Tests() {
7180 testCases = append(testCases, testCase{
7181 testType: clientTest,
7182 name: "CECPQ1-Client-BadX25519Part",
7183 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007184 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007185 MinVersion: VersionTLS12,
7186 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7187 Bugs: ProtocolBugs{
7188 CECPQ1BadX25519Part: true,
7189 },
7190 },
7191 flags: []string{"-cipher", "kCECPQ1"},
7192 shouldFail: true,
7193 expectedLocalError: "local error: bad record MAC",
7194 })
7195 testCases = append(testCases, testCase{
7196 testType: clientTest,
7197 name: "CECPQ1-Client-BadNewhopePart",
7198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007199 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007200 MinVersion: VersionTLS12,
7201 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7202 Bugs: ProtocolBugs{
7203 CECPQ1BadNewhopePart: true,
7204 },
7205 },
7206 flags: []string{"-cipher", "kCECPQ1"},
7207 shouldFail: true,
7208 expectedLocalError: "local error: bad record MAC",
7209 })
7210 testCases = append(testCases, testCase{
7211 testType: serverTest,
7212 name: "CECPQ1-Server-BadX25519Part",
7213 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007214 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007215 MinVersion: VersionTLS12,
7216 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7217 Bugs: ProtocolBugs{
7218 CECPQ1BadX25519Part: true,
7219 },
7220 },
7221 flags: []string{"-cipher", "kCECPQ1"},
7222 shouldFail: true,
7223 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7224 })
7225 testCases = append(testCases, testCase{
7226 testType: serverTest,
7227 name: "CECPQ1-Server-BadNewhopePart",
7228 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007229 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007230 MinVersion: VersionTLS12,
7231 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7232 Bugs: ProtocolBugs{
7233 CECPQ1BadNewhopePart: true,
7234 },
7235 },
7236 flags: []string{"-cipher", "kCECPQ1"},
7237 shouldFail: true,
7238 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7239 })
7240}
7241
David Benjamin5c4e8572016-08-19 17:44:53 -04007242func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007243 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007244 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007245 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007246 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007247 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7248 Bugs: ProtocolBugs{
7249 // This is a 1234-bit prime number, generated
7250 // with:
7251 // openssl gendh 1234 | openssl asn1parse -i
7252 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7253 },
7254 },
David Benjamin9e68f192016-06-30 14:55:33 -04007255 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007256 })
7257 testCases = append(testCases, testCase{
7258 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007259 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007260 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007261 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007262 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7263 },
7264 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007265 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007266 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007267}
7268
David Benjaminc9ae27c2016-06-24 22:56:37 -04007269func addTLS13RecordTests() {
7270 testCases = append(testCases, testCase{
7271 name: "TLS13-RecordPadding",
7272 config: Config{
7273 MaxVersion: VersionTLS13,
7274 MinVersion: VersionTLS13,
7275 Bugs: ProtocolBugs{
7276 RecordPadding: 10,
7277 },
7278 },
7279 })
7280
7281 testCases = append(testCases, testCase{
7282 name: "TLS13-EmptyRecords",
7283 config: Config{
7284 MaxVersion: VersionTLS13,
7285 MinVersion: VersionTLS13,
7286 Bugs: ProtocolBugs{
7287 OmitRecordContents: true,
7288 },
7289 },
7290 shouldFail: true,
7291 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7292 })
7293
7294 testCases = append(testCases, testCase{
7295 name: "TLS13-OnlyPadding",
7296 config: Config{
7297 MaxVersion: VersionTLS13,
7298 MinVersion: VersionTLS13,
7299 Bugs: ProtocolBugs{
7300 OmitRecordContents: true,
7301 RecordPadding: 10,
7302 },
7303 },
7304 shouldFail: true,
7305 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7306 })
7307
7308 testCases = append(testCases, testCase{
7309 name: "TLS13-WrongOuterRecord",
7310 config: Config{
7311 MaxVersion: VersionTLS13,
7312 MinVersion: VersionTLS13,
7313 Bugs: ProtocolBugs{
7314 OuterRecordType: recordTypeHandshake,
7315 },
7316 },
7317 shouldFail: true,
7318 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7319 })
7320}
7321
David Benjamin82261be2016-07-07 14:32:50 -07007322func addChangeCipherSpecTests() {
7323 // Test missing ChangeCipherSpecs.
7324 testCases = append(testCases, testCase{
7325 name: "SkipChangeCipherSpec-Client",
7326 config: Config{
7327 MaxVersion: VersionTLS12,
7328 Bugs: ProtocolBugs{
7329 SkipChangeCipherSpec: true,
7330 },
7331 },
7332 shouldFail: true,
7333 expectedError: ":UNEXPECTED_RECORD:",
7334 })
7335 testCases = append(testCases, testCase{
7336 testType: serverTest,
7337 name: "SkipChangeCipherSpec-Server",
7338 config: Config{
7339 MaxVersion: VersionTLS12,
7340 Bugs: ProtocolBugs{
7341 SkipChangeCipherSpec: true,
7342 },
7343 },
7344 shouldFail: true,
7345 expectedError: ":UNEXPECTED_RECORD:",
7346 })
7347 testCases = append(testCases, testCase{
7348 testType: serverTest,
7349 name: "SkipChangeCipherSpec-Server-NPN",
7350 config: Config{
7351 MaxVersion: VersionTLS12,
7352 NextProtos: []string{"bar"},
7353 Bugs: ProtocolBugs{
7354 SkipChangeCipherSpec: true,
7355 },
7356 },
7357 flags: []string{
7358 "-advertise-npn", "\x03foo\x03bar\x03baz",
7359 },
7360 shouldFail: true,
7361 expectedError: ":UNEXPECTED_RECORD:",
7362 })
7363
7364 // Test synchronization between the handshake and ChangeCipherSpec.
7365 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7366 // rejected. Test both with and without handshake packing to handle both
7367 // when the partial post-CCS message is in its own record and when it is
7368 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007369 for _, packed := range []bool{false, true} {
7370 var suffix string
7371 if packed {
7372 suffix = "-Packed"
7373 }
7374
7375 testCases = append(testCases, testCase{
7376 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7377 config: Config{
7378 MaxVersion: VersionTLS12,
7379 Bugs: ProtocolBugs{
7380 FragmentAcrossChangeCipherSpec: true,
7381 PackHandshakeFlight: packed,
7382 },
7383 },
7384 shouldFail: true,
7385 expectedError: ":UNEXPECTED_RECORD:",
7386 })
7387 testCases = append(testCases, testCase{
7388 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7389 config: Config{
7390 MaxVersion: VersionTLS12,
7391 },
7392 resumeSession: true,
7393 resumeConfig: &Config{
7394 MaxVersion: VersionTLS12,
7395 Bugs: ProtocolBugs{
7396 FragmentAcrossChangeCipherSpec: true,
7397 PackHandshakeFlight: packed,
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":UNEXPECTED_RECORD:",
7402 })
7403 testCases = append(testCases, testCase{
7404 testType: serverTest,
7405 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7406 config: Config{
7407 MaxVersion: VersionTLS12,
7408 Bugs: ProtocolBugs{
7409 FragmentAcrossChangeCipherSpec: true,
7410 PackHandshakeFlight: packed,
7411 },
7412 },
7413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_RECORD:",
7415 })
7416 testCases = append(testCases, testCase{
7417 testType: serverTest,
7418 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7419 config: Config{
7420 MaxVersion: VersionTLS12,
7421 },
7422 resumeSession: true,
7423 resumeConfig: &Config{
7424 MaxVersion: VersionTLS12,
7425 Bugs: ProtocolBugs{
7426 FragmentAcrossChangeCipherSpec: true,
7427 PackHandshakeFlight: packed,
7428 },
7429 },
7430 shouldFail: true,
7431 expectedError: ":UNEXPECTED_RECORD:",
7432 })
7433 testCases = append(testCases, testCase{
7434 testType: serverTest,
7435 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7436 config: Config{
7437 MaxVersion: VersionTLS12,
7438 NextProtos: []string{"bar"},
7439 Bugs: ProtocolBugs{
7440 FragmentAcrossChangeCipherSpec: true,
7441 PackHandshakeFlight: packed,
7442 },
7443 },
7444 flags: []string{
7445 "-advertise-npn", "\x03foo\x03bar\x03baz",
7446 },
7447 shouldFail: true,
7448 expectedError: ":UNEXPECTED_RECORD:",
7449 })
7450 }
7451
David Benjamin61672812016-07-14 23:10:43 -04007452 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7453 // messages in the handshake queue. Do this by testing the server
7454 // reading the client Finished, reversing the flight so Finished comes
7455 // first.
7456 testCases = append(testCases, testCase{
7457 protocol: dtls,
7458 testType: serverTest,
7459 name: "SendUnencryptedFinished-DTLS",
7460 config: Config{
7461 MaxVersion: VersionTLS12,
7462 Bugs: ProtocolBugs{
7463 SendUnencryptedFinished: true,
7464 ReverseHandshakeFragments: true,
7465 },
7466 },
7467 shouldFail: true,
7468 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7469 })
7470
Steven Valdez143e8b32016-07-11 13:19:03 -04007471 // Test synchronization between encryption changes and the handshake in
7472 // TLS 1.3, where ChangeCipherSpec is implicit.
7473 testCases = append(testCases, testCase{
7474 name: "PartialEncryptedExtensionsWithServerHello",
7475 config: Config{
7476 MaxVersion: VersionTLS13,
7477 Bugs: ProtocolBugs{
7478 PartialEncryptedExtensionsWithServerHello: true,
7479 },
7480 },
7481 shouldFail: true,
7482 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7483 })
7484 testCases = append(testCases, testCase{
7485 testType: serverTest,
7486 name: "PartialClientFinishedWithClientHello",
7487 config: Config{
7488 MaxVersion: VersionTLS13,
7489 Bugs: ProtocolBugs{
7490 PartialClientFinishedWithClientHello: true,
7491 },
7492 },
7493 shouldFail: true,
7494 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7495 })
7496
David Benjamin82261be2016-07-07 14:32:50 -07007497 // Test that early ChangeCipherSpecs are handled correctly.
7498 testCases = append(testCases, testCase{
7499 testType: serverTest,
7500 name: "EarlyChangeCipherSpec-server-1",
7501 config: Config{
7502 MaxVersion: VersionTLS12,
7503 Bugs: ProtocolBugs{
7504 EarlyChangeCipherSpec: 1,
7505 },
7506 },
7507 shouldFail: true,
7508 expectedError: ":UNEXPECTED_RECORD:",
7509 })
7510 testCases = append(testCases, testCase{
7511 testType: serverTest,
7512 name: "EarlyChangeCipherSpec-server-2",
7513 config: Config{
7514 MaxVersion: VersionTLS12,
7515 Bugs: ProtocolBugs{
7516 EarlyChangeCipherSpec: 2,
7517 },
7518 },
7519 shouldFail: true,
7520 expectedError: ":UNEXPECTED_RECORD:",
7521 })
7522 testCases = append(testCases, testCase{
7523 protocol: dtls,
7524 name: "StrayChangeCipherSpec",
7525 config: Config{
7526 // TODO(davidben): Once DTLS 1.3 exists, test
7527 // that stray ChangeCipherSpec messages are
7528 // rejected.
7529 MaxVersion: VersionTLS12,
7530 Bugs: ProtocolBugs{
7531 StrayChangeCipherSpec: true,
7532 },
7533 },
7534 })
7535
7536 // Test that the contents of ChangeCipherSpec are checked.
7537 testCases = append(testCases, testCase{
7538 name: "BadChangeCipherSpec-1",
7539 config: Config{
7540 MaxVersion: VersionTLS12,
7541 Bugs: ProtocolBugs{
7542 BadChangeCipherSpec: []byte{2},
7543 },
7544 },
7545 shouldFail: true,
7546 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7547 })
7548 testCases = append(testCases, testCase{
7549 name: "BadChangeCipherSpec-2",
7550 config: Config{
7551 MaxVersion: VersionTLS12,
7552 Bugs: ProtocolBugs{
7553 BadChangeCipherSpec: []byte{1, 1},
7554 },
7555 },
7556 shouldFail: true,
7557 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7558 })
7559 testCases = append(testCases, testCase{
7560 protocol: dtls,
7561 name: "BadChangeCipherSpec-DTLS-1",
7562 config: Config{
7563 MaxVersion: VersionTLS12,
7564 Bugs: ProtocolBugs{
7565 BadChangeCipherSpec: []byte{2},
7566 },
7567 },
7568 shouldFail: true,
7569 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7570 })
7571 testCases = append(testCases, testCase{
7572 protocol: dtls,
7573 name: "BadChangeCipherSpec-DTLS-2",
7574 config: Config{
7575 MaxVersion: VersionTLS12,
7576 Bugs: ProtocolBugs{
7577 BadChangeCipherSpec: []byte{1, 1},
7578 },
7579 },
7580 shouldFail: true,
7581 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7582 })
7583}
7584
David Benjamincd2c8062016-09-09 11:28:16 -04007585type perMessageTest struct {
7586 messageType uint8
7587 test testCase
7588}
7589
7590// makePerMessageTests returns a series of test templates which cover each
7591// message in the TLS handshake. These may be used with bugs like
7592// WrongMessageType to fully test a per-message bug.
7593func makePerMessageTests() []perMessageTest {
7594 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007595 for _, protocol := range []protocol{tls, dtls} {
7596 var suffix string
7597 if protocol == dtls {
7598 suffix = "-DTLS"
7599 }
7600
David Benjamincd2c8062016-09-09 11:28:16 -04007601 ret = append(ret, perMessageTest{
7602 messageType: typeClientHello,
7603 test: testCase{
7604 protocol: protocol,
7605 testType: serverTest,
7606 name: "ClientHello" + suffix,
7607 config: Config{
7608 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007609 },
7610 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007611 })
7612
7613 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007614 ret = append(ret, perMessageTest{
7615 messageType: typeHelloVerifyRequest,
7616 test: testCase{
7617 protocol: protocol,
7618 name: "HelloVerifyRequest" + suffix,
7619 config: Config{
7620 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007621 },
7622 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007623 })
7624 }
7625
David Benjamincd2c8062016-09-09 11:28:16 -04007626 ret = append(ret, perMessageTest{
7627 messageType: typeServerHello,
7628 test: testCase{
7629 protocol: protocol,
7630 name: "ServerHello" + suffix,
7631 config: Config{
7632 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007633 },
7634 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007635 })
7636
David Benjamincd2c8062016-09-09 11:28:16 -04007637 ret = append(ret, perMessageTest{
7638 messageType: typeCertificate,
7639 test: testCase{
7640 protocol: protocol,
7641 name: "ServerCertificate" + suffix,
7642 config: Config{
7643 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007644 },
7645 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007646 })
7647
David Benjamincd2c8062016-09-09 11:28:16 -04007648 ret = append(ret, perMessageTest{
7649 messageType: typeCertificateStatus,
7650 test: testCase{
7651 protocol: protocol,
7652 name: "CertificateStatus" + suffix,
7653 config: Config{
7654 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007655 },
David Benjamincd2c8062016-09-09 11:28:16 -04007656 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007657 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007658 })
7659
David Benjamincd2c8062016-09-09 11:28:16 -04007660 ret = append(ret, perMessageTest{
7661 messageType: typeServerKeyExchange,
7662 test: testCase{
7663 protocol: protocol,
7664 name: "ServerKeyExchange" + suffix,
7665 config: Config{
7666 MaxVersion: VersionTLS12,
7667 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007668 },
7669 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007670 })
7671
David Benjamincd2c8062016-09-09 11:28:16 -04007672 ret = append(ret, perMessageTest{
7673 messageType: typeCertificateRequest,
7674 test: testCase{
7675 protocol: protocol,
7676 name: "CertificateRequest" + suffix,
7677 config: Config{
7678 MaxVersion: VersionTLS12,
7679 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007680 },
7681 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007682 })
7683
David Benjamincd2c8062016-09-09 11:28:16 -04007684 ret = append(ret, perMessageTest{
7685 messageType: typeServerHelloDone,
7686 test: testCase{
7687 protocol: protocol,
7688 name: "ServerHelloDone" + suffix,
7689 config: Config{
7690 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007691 },
7692 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007693 })
7694
David Benjamincd2c8062016-09-09 11:28:16 -04007695 ret = append(ret, perMessageTest{
7696 messageType: typeCertificate,
7697 test: testCase{
7698 testType: serverTest,
7699 protocol: protocol,
7700 name: "ClientCertificate" + suffix,
7701 config: Config{
7702 Certificates: []Certificate{rsaCertificate},
7703 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007704 },
David Benjamincd2c8062016-09-09 11:28:16 -04007705 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007706 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007707 })
7708
David Benjamincd2c8062016-09-09 11:28:16 -04007709 ret = append(ret, perMessageTest{
7710 messageType: typeCertificateVerify,
7711 test: testCase{
7712 testType: serverTest,
7713 protocol: protocol,
7714 name: "CertificateVerify" + suffix,
7715 config: Config{
7716 Certificates: []Certificate{rsaCertificate},
7717 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007718 },
David Benjamincd2c8062016-09-09 11:28:16 -04007719 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007720 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007721 })
7722
David Benjamincd2c8062016-09-09 11:28:16 -04007723 ret = append(ret, perMessageTest{
7724 messageType: typeClientKeyExchange,
7725 test: testCase{
7726 testType: serverTest,
7727 protocol: protocol,
7728 name: "ClientKeyExchange" + suffix,
7729 config: Config{
7730 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007731 },
7732 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007733 })
7734
7735 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007736 ret = append(ret, perMessageTest{
7737 messageType: typeNextProtocol,
7738 test: testCase{
7739 testType: serverTest,
7740 protocol: protocol,
7741 name: "NextProtocol" + suffix,
7742 config: Config{
7743 MaxVersion: VersionTLS12,
7744 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007745 },
David Benjamincd2c8062016-09-09 11:28:16 -04007746 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04007747 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007748 })
7749
David Benjamincd2c8062016-09-09 11:28:16 -04007750 ret = append(ret, perMessageTest{
7751 messageType: typeChannelID,
7752 test: testCase{
7753 testType: serverTest,
7754 protocol: protocol,
7755 name: "ChannelID" + suffix,
7756 config: Config{
7757 MaxVersion: VersionTLS12,
7758 ChannelID: channelIDKey,
7759 },
7760 flags: []string{
7761 "-expect-channel-id",
7762 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04007763 },
7764 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007765 })
7766 }
7767
David Benjamincd2c8062016-09-09 11:28:16 -04007768 ret = append(ret, perMessageTest{
7769 messageType: typeFinished,
7770 test: testCase{
7771 testType: serverTest,
7772 protocol: protocol,
7773 name: "ClientFinished" + suffix,
7774 config: Config{
7775 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007776 },
7777 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007778 })
7779
David Benjamincd2c8062016-09-09 11:28:16 -04007780 ret = append(ret, perMessageTest{
7781 messageType: typeNewSessionTicket,
7782 test: testCase{
7783 protocol: protocol,
7784 name: "NewSessionTicket" + suffix,
7785 config: Config{
7786 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007787 },
7788 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007789 })
7790
David Benjamincd2c8062016-09-09 11:28:16 -04007791 ret = append(ret, perMessageTest{
7792 messageType: typeFinished,
7793 test: testCase{
7794 protocol: protocol,
7795 name: "ServerFinished" + suffix,
7796 config: Config{
7797 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007798 },
7799 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007800 })
7801
7802 }
David Benjamincd2c8062016-09-09 11:28:16 -04007803
7804 ret = append(ret, perMessageTest{
7805 messageType: typeClientHello,
7806 test: testCase{
7807 testType: serverTest,
7808 name: "TLS13-ClientHello",
7809 config: Config{
7810 MaxVersion: VersionTLS13,
7811 },
7812 },
7813 })
7814
7815 ret = append(ret, perMessageTest{
7816 messageType: typeServerHello,
7817 test: testCase{
7818 name: "TLS13-ServerHello",
7819 config: Config{
7820 MaxVersion: VersionTLS13,
7821 },
7822 },
7823 })
7824
7825 ret = append(ret, perMessageTest{
7826 messageType: typeEncryptedExtensions,
7827 test: testCase{
7828 name: "TLS13-EncryptedExtensions",
7829 config: Config{
7830 MaxVersion: VersionTLS13,
7831 },
7832 },
7833 })
7834
7835 ret = append(ret, perMessageTest{
7836 messageType: typeCertificateRequest,
7837 test: testCase{
7838 name: "TLS13-CertificateRequest",
7839 config: Config{
7840 MaxVersion: VersionTLS13,
7841 ClientAuth: RequireAnyClientCert,
7842 },
7843 },
7844 })
7845
7846 ret = append(ret, perMessageTest{
7847 messageType: typeCertificate,
7848 test: testCase{
7849 name: "TLS13-ServerCertificate",
7850 config: Config{
7851 MaxVersion: VersionTLS13,
7852 },
7853 },
7854 })
7855
7856 ret = append(ret, perMessageTest{
7857 messageType: typeCertificateVerify,
7858 test: testCase{
7859 name: "TLS13-ServerCertificateVerify",
7860 config: Config{
7861 MaxVersion: VersionTLS13,
7862 },
7863 },
7864 })
7865
7866 ret = append(ret, perMessageTest{
7867 messageType: typeFinished,
7868 test: testCase{
7869 name: "TLS13-ServerFinished",
7870 config: Config{
7871 MaxVersion: VersionTLS13,
7872 },
7873 },
7874 })
7875
7876 ret = append(ret, perMessageTest{
7877 messageType: typeCertificate,
7878 test: testCase{
7879 testType: serverTest,
7880 name: "TLS13-ClientCertificate",
7881 config: Config{
7882 Certificates: []Certificate{rsaCertificate},
7883 MaxVersion: VersionTLS13,
7884 },
7885 flags: []string{"-require-any-client-certificate"},
7886 },
7887 })
7888
7889 ret = append(ret, perMessageTest{
7890 messageType: typeCertificateVerify,
7891 test: testCase{
7892 testType: serverTest,
7893 name: "TLS13-ClientCertificateVerify",
7894 config: Config{
7895 Certificates: []Certificate{rsaCertificate},
7896 MaxVersion: VersionTLS13,
7897 },
7898 flags: []string{"-require-any-client-certificate"},
7899 },
7900 })
7901
7902 ret = append(ret, perMessageTest{
7903 messageType: typeFinished,
7904 test: testCase{
7905 testType: serverTest,
7906 name: "TLS13-ClientFinished",
7907 config: Config{
7908 MaxVersion: VersionTLS13,
7909 },
7910 },
7911 })
7912
7913 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04007914}
7915
David Benjamincd2c8062016-09-09 11:28:16 -04007916func addWrongMessageTypeTests() {
7917 for _, t := range makePerMessageTests() {
7918 t.test.name = "WrongMessageType-" + t.test.name
7919 t.test.config.Bugs.SendWrongMessageType = t.messageType
7920 t.test.shouldFail = true
7921 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
7922 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04007923
David Benjamincd2c8062016-09-09 11:28:16 -04007924 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7925 // In TLS 1.3, a bad ServerHello means the client sends
7926 // an unencrypted alert while the server expects
7927 // encryption, so the alert is not readable by runner.
7928 t.test.expectedLocalError = "local error: bad record MAC"
7929 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007930
David Benjamincd2c8062016-09-09 11:28:16 -04007931 testCases = append(testCases, t.test)
7932 }
Steven Valdez143e8b32016-07-11 13:19:03 -04007933}
7934
David Benjamin639846e2016-09-09 11:41:18 -04007935func addTrailingMessageDataTests() {
7936 for _, t := range makePerMessageTests() {
7937 t.test.name = "TrailingMessageData-" + t.test.name
7938 t.test.config.Bugs.SendTrailingMessageData = t.messageType
7939 t.test.shouldFail = true
7940 t.test.expectedError = ":DECODE_ERROR:"
7941 t.test.expectedLocalError = "remote error: error decoding message"
7942
7943 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
7944 // In TLS 1.3, a bad ServerHello means the client sends
7945 // an unencrypted alert while the server expects
7946 // encryption, so the alert is not readable by runner.
7947 t.test.expectedLocalError = "local error: bad record MAC"
7948 }
7949
7950 if t.messageType == typeFinished {
7951 // Bad Finished messages read as the verify data having
7952 // the wrong length.
7953 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
7954 t.test.expectedLocalError = "remote error: error decrypting message"
7955 }
7956
7957 testCases = append(testCases, t.test)
7958 }
7959}
7960
Steven Valdez143e8b32016-07-11 13:19:03 -04007961func addTLS13HandshakeTests() {
7962 testCases = append(testCases, testCase{
7963 testType: clientTest,
7964 name: "MissingKeyShare-Client",
7965 config: Config{
7966 MaxVersion: VersionTLS13,
7967 Bugs: ProtocolBugs{
7968 MissingKeyShare: true,
7969 },
7970 },
7971 shouldFail: true,
7972 expectedError: ":MISSING_KEY_SHARE:",
7973 })
7974
7975 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04007976 testType: serverTest,
7977 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04007978 config: Config{
7979 MaxVersion: VersionTLS13,
7980 Bugs: ProtocolBugs{
7981 MissingKeyShare: true,
7982 },
7983 },
7984 shouldFail: true,
7985 expectedError: ":MISSING_KEY_SHARE:",
7986 })
7987
7988 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007989 testType: serverTest,
7990 name: "DuplicateKeyShares",
7991 config: Config{
7992 MaxVersion: VersionTLS13,
7993 Bugs: ProtocolBugs{
7994 DuplicateKeyShares: true,
7995 },
7996 },
David Benjamin7e1f9842016-09-20 19:24:40 -04007997 shouldFail: true,
7998 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007999 })
8000
8001 testCases = append(testCases, testCase{
8002 testType: clientTest,
8003 name: "EmptyEncryptedExtensions",
8004 config: Config{
8005 MaxVersion: VersionTLS13,
8006 Bugs: ProtocolBugs{
8007 EmptyEncryptedExtensions: true,
8008 },
8009 },
8010 shouldFail: true,
8011 expectedLocalError: "remote error: error decoding message",
8012 })
8013
8014 testCases = append(testCases, testCase{
8015 testType: clientTest,
8016 name: "EncryptedExtensionsWithKeyShare",
8017 config: Config{
8018 MaxVersion: VersionTLS13,
8019 Bugs: ProtocolBugs{
8020 EncryptedExtensionsWithKeyShare: true,
8021 },
8022 },
8023 shouldFail: true,
8024 expectedLocalError: "remote error: unsupported extension",
8025 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008026
8027 testCases = append(testCases, testCase{
8028 testType: serverTest,
8029 name: "SendHelloRetryRequest",
8030 config: Config{
8031 MaxVersion: VersionTLS13,
8032 // Require a HelloRetryRequest for every curve.
8033 DefaultCurves: []CurveID{},
8034 },
8035 expectedCurveID: CurveX25519,
8036 })
8037
8038 testCases = append(testCases, testCase{
8039 testType: serverTest,
8040 name: "SendHelloRetryRequest-2",
8041 config: Config{
8042 MaxVersion: VersionTLS13,
8043 DefaultCurves: []CurveID{CurveP384},
8044 },
8045 // Although the ClientHello did not predict our preferred curve,
8046 // we always select it whether it is predicted or not.
8047 expectedCurveID: CurveX25519,
8048 })
8049
8050 testCases = append(testCases, testCase{
8051 name: "UnknownCurve-HelloRetryRequest",
8052 config: Config{
8053 MaxVersion: VersionTLS13,
8054 // P-384 requires HelloRetryRequest in BoringSSL.
8055 CurvePreferences: []CurveID{CurveP384},
8056 Bugs: ProtocolBugs{
8057 SendHelloRetryRequestCurve: bogusCurve,
8058 },
8059 },
8060 shouldFail: true,
8061 expectedError: ":WRONG_CURVE:",
8062 })
8063
8064 testCases = append(testCases, testCase{
8065 name: "DisabledCurve-HelloRetryRequest",
8066 config: Config{
8067 MaxVersion: VersionTLS13,
8068 CurvePreferences: []CurveID{CurveP256},
8069 Bugs: ProtocolBugs{
8070 IgnorePeerCurvePreferences: true,
8071 },
8072 },
8073 flags: []string{"-p384-only"},
8074 shouldFail: true,
8075 expectedError: ":WRONG_CURVE:",
8076 })
8077
8078 testCases = append(testCases, testCase{
8079 name: "UnnecessaryHelloRetryRequest",
8080 config: Config{
8081 MaxVersion: VersionTLS13,
8082 Bugs: ProtocolBugs{
8083 UnnecessaryHelloRetryRequest: true,
8084 },
8085 },
8086 shouldFail: true,
8087 expectedError: ":WRONG_CURVE:",
8088 })
8089
8090 testCases = append(testCases, testCase{
8091 name: "SecondHelloRetryRequest",
8092 config: Config{
8093 MaxVersion: VersionTLS13,
8094 // P-384 requires HelloRetryRequest in BoringSSL.
8095 CurvePreferences: []CurveID{CurveP384},
8096 Bugs: ProtocolBugs{
8097 SecondHelloRetryRequest: true,
8098 },
8099 },
8100 shouldFail: true,
8101 expectedError: ":UNEXPECTED_MESSAGE:",
8102 })
8103
8104 testCases = append(testCases, testCase{
8105 testType: serverTest,
8106 name: "SecondClientHelloMissingKeyShare",
8107 config: Config{
8108 MaxVersion: VersionTLS13,
8109 DefaultCurves: []CurveID{},
8110 Bugs: ProtocolBugs{
8111 SecondClientHelloMissingKeyShare: true,
8112 },
8113 },
8114 shouldFail: true,
8115 expectedError: ":MISSING_KEY_SHARE:",
8116 })
8117
8118 testCases = append(testCases, testCase{
8119 testType: serverTest,
8120 name: "SecondClientHelloWrongCurve",
8121 config: Config{
8122 MaxVersion: VersionTLS13,
8123 DefaultCurves: []CurveID{},
8124 Bugs: ProtocolBugs{
8125 MisinterpretHelloRetryRequestCurve: CurveP521,
8126 },
8127 },
8128 shouldFail: true,
8129 expectedError: ":WRONG_CURVE:",
8130 })
8131
8132 testCases = append(testCases, testCase{
8133 name: "HelloRetryRequestVersionMismatch",
8134 config: Config{
8135 MaxVersion: VersionTLS13,
8136 // P-384 requires HelloRetryRequest in BoringSSL.
8137 CurvePreferences: []CurveID{CurveP384},
8138 Bugs: ProtocolBugs{
8139 SendServerHelloVersion: 0x0305,
8140 },
8141 },
8142 shouldFail: true,
8143 expectedError: ":WRONG_VERSION_NUMBER:",
8144 })
8145
8146 testCases = append(testCases, testCase{
8147 name: "HelloRetryRequestCurveMismatch",
8148 config: Config{
8149 MaxVersion: VersionTLS13,
8150 // P-384 requires HelloRetryRequest in BoringSSL.
8151 CurvePreferences: []CurveID{CurveP384},
8152 Bugs: ProtocolBugs{
8153 // Send P-384 (correct) in the HelloRetryRequest.
8154 SendHelloRetryRequestCurve: CurveP384,
8155 // But send P-256 in the ServerHello.
8156 SendCurve: CurveP256,
8157 },
8158 },
8159 shouldFail: true,
8160 expectedError: ":WRONG_CURVE:",
8161 })
8162
8163 // Test the server selecting a curve that requires a HelloRetryRequest
8164 // without sending it.
8165 testCases = append(testCases, testCase{
8166 name: "SkipHelloRetryRequest",
8167 config: Config{
8168 MaxVersion: VersionTLS13,
8169 // P-384 requires HelloRetryRequest in BoringSSL.
8170 CurvePreferences: []CurveID{CurveP384},
8171 Bugs: ProtocolBugs{
8172 SkipHelloRetryRequest: true,
8173 },
8174 },
8175 shouldFail: true,
8176 expectedError: ":WRONG_CURVE:",
8177 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008178
8179 testCases = append(testCases, testCase{
8180 name: "TLS13-RequestContextInHandshake",
8181 config: Config{
8182 MaxVersion: VersionTLS13,
8183 MinVersion: VersionTLS13,
8184 ClientAuth: RequireAnyClientCert,
8185 Bugs: ProtocolBugs{
8186 SendRequestContext: []byte("request context"),
8187 },
8188 },
8189 flags: []string{
8190 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8191 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8192 },
8193 shouldFail: true,
8194 expectedError: ":DECODE_ERROR:",
8195 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008196
8197 testCases = append(testCases, testCase{
8198 testType: serverTest,
8199 name: "TLS13-TrailingKeyShareData",
8200 config: Config{
8201 MaxVersion: VersionTLS13,
8202 Bugs: ProtocolBugs{
8203 TrailingKeyShareData: true,
8204 },
8205 },
8206 shouldFail: true,
8207 expectedError: ":DECODE_ERROR:",
8208 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008209}
8210
David Benjaminf3fbade2016-09-19 13:08:16 -04008211func addPeekTests() {
8212 // Test SSL_peek works, including on empty records.
8213 testCases = append(testCases, testCase{
8214 name: "Peek-Basic",
8215 sendEmptyRecords: 1,
8216 flags: []string{"-peek-then-read"},
8217 })
8218
8219 // Test SSL_peek can drive the initial handshake.
8220 testCases = append(testCases, testCase{
8221 name: "Peek-ImplicitHandshake",
8222 flags: []string{
8223 "-peek-then-read",
8224 "-implicit-handshake",
8225 },
8226 })
8227
8228 // Test SSL_peek can discover and drive a renegotiation.
8229 testCases = append(testCases, testCase{
8230 name: "Peek-Renegotiate",
8231 config: Config{
8232 MaxVersion: VersionTLS12,
8233 },
8234 renegotiate: 1,
8235 flags: []string{
8236 "-peek-then-read",
8237 "-renegotiate-freely",
8238 "-expect-total-renegotiations", "1",
8239 },
8240 })
8241
8242 // Test SSL_peek can discover a close_notify.
8243 testCases = append(testCases, testCase{
8244 name: "Peek-Shutdown",
8245 config: Config{
8246 Bugs: ProtocolBugs{
8247 ExpectCloseNotify: true,
8248 },
8249 },
8250 flags: []string{
8251 "-peek-then-read",
8252 "-check-close-notify",
8253 },
8254 })
8255
8256 // Test SSL_peek can discover an alert.
8257 testCases = append(testCases, testCase{
8258 name: "Peek-Alert",
8259 config: Config{
8260 Bugs: ProtocolBugs{
8261 SendSpuriousAlert: alertRecordOverflow,
8262 },
8263 },
8264 flags: []string{"-peek-then-read"},
8265 shouldFail: true,
8266 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8267 })
8268
8269 // Test SSL_peek can handle KeyUpdate.
8270 testCases = append(testCases, testCase{
8271 name: "Peek-KeyUpdate",
8272 config: Config{
8273 MaxVersion: VersionTLS13,
8274 Bugs: ProtocolBugs{
8275 SendKeyUpdateBeforeEveryAppDataRecord: true,
8276 },
8277 },
8278 flags: []string{"-peek-then-read"},
8279 })
8280}
8281
Adam Langley7c803a62015-06-15 15:35:05 -07008282func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008283 defer wg.Done()
8284
8285 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008286 var err error
8287
8288 if *mallocTest < 0 {
8289 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008290 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008291 } else {
8292 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8293 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008294 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008295 if err != nil {
8296 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8297 }
8298 break
8299 }
8300 }
8301 }
Adam Langley95c29f32014-06-20 12:00:00 -07008302 statusChan <- statusMsg{test: test, err: err}
8303 }
8304}
8305
8306type statusMsg struct {
8307 test *testCase
8308 started bool
8309 err error
8310}
8311
David Benjamin5f237bc2015-02-11 17:14:15 -05008312func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008313 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008314
David Benjamin5f237bc2015-02-11 17:14:15 -05008315 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008316 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008317 if !*pipe {
8318 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008319 var erase string
8320 for i := 0; i < lineLen; i++ {
8321 erase += "\b \b"
8322 }
8323 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008324 }
8325
Adam Langley95c29f32014-06-20 12:00:00 -07008326 if msg.started {
8327 started++
8328 } else {
8329 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008330
8331 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008332 if msg.err == errUnimplemented {
8333 if *pipe {
8334 // Print each test instead of a status line.
8335 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8336 }
8337 unimplemented++
8338 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8339 } else {
8340 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8341 failed++
8342 testOutput.addResult(msg.test.name, "FAIL")
8343 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008344 } else {
8345 if *pipe {
8346 // Print each test instead of a status line.
8347 fmt.Printf("PASSED (%s)\n", msg.test.name)
8348 }
8349 testOutput.addResult(msg.test.name, "PASS")
8350 }
Adam Langley95c29f32014-06-20 12:00:00 -07008351 }
8352
David Benjamin5f237bc2015-02-11 17:14:15 -05008353 if !*pipe {
8354 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008355 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008356 lineLen = len(line)
8357 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008358 }
Adam Langley95c29f32014-06-20 12:00:00 -07008359 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008360
8361 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008362}
8363
8364func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008365 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008366 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008367 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008368
Adam Langley7c803a62015-06-15 15:35:05 -07008369 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008370 addCipherSuiteTests()
8371 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008372 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008373 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008374 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008375 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008376 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008377 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008378 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008379 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008380 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008381 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008382 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008383 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008384 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008385 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008386 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008387 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008388 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008389 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008390 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008391 addDHEGroupSizeTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008392 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008393 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008394 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008395 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008396 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008397 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008398 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008399
8400 var wg sync.WaitGroup
8401
Adam Langley7c803a62015-06-15 15:35:05 -07008402 statusChan := make(chan statusMsg, *numWorkers)
8403 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008404 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008405
EKRf71d7ed2016-08-06 13:25:12 -07008406 if len(*shimConfigFile) != 0 {
8407 encoded, err := ioutil.ReadFile(*shimConfigFile)
8408 if err != nil {
8409 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8410 os.Exit(1)
8411 }
8412
8413 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8414 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8415 os.Exit(1)
8416 }
8417 }
8418
David Benjamin025b3d32014-07-01 19:53:04 -04008419 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008420
Adam Langley7c803a62015-06-15 15:35:05 -07008421 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008422 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008423 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008424 }
8425
David Benjamin270f0a72016-03-17 14:41:36 -04008426 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008427 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008428 matched := true
8429 if len(*testToRun) != 0 {
8430 var err error
8431 matched, err = filepath.Match(*testToRun, testCases[i].name)
8432 if err != nil {
8433 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8434 os.Exit(1)
8435 }
8436 }
8437
EKRf71d7ed2016-08-06 13:25:12 -07008438 if !*includeDisabled {
8439 for pattern := range shimConfig.DisabledTests {
8440 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8441 if err != nil {
8442 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8443 os.Exit(1)
8444 }
8445
8446 if isDisabled {
8447 matched = false
8448 break
8449 }
8450 }
8451 }
8452
David Benjamin17e12922016-07-28 18:04:43 -04008453 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008454 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008455 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008456 }
8457 }
David Benjamin17e12922016-07-28 18:04:43 -04008458
David Benjamin270f0a72016-03-17 14:41:36 -04008459 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008460 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008461 os.Exit(1)
8462 }
Adam Langley95c29f32014-06-20 12:00:00 -07008463
8464 close(testChan)
8465 wg.Wait()
8466 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008467 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008468
8469 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008470
8471 if *jsonOutput != "" {
8472 if err := testOutput.writeTo(*jsonOutput); err != nil {
8473 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8474 }
8475 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008476
EKR842ae6c2016-07-27 09:22:05 +02008477 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8478 os.Exit(1)
8479 }
8480
8481 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008482 os.Exit(1)
8483 }
Adam Langley95c29f32014-06-20 12:00:00 -07008484}