blob: 396d5f26f4f9446ce7a0f87012f9699e0e3b902d [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 Benjamin2c516452016-11-15 10:16:54 +090090 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070091 testCertECDSAP256
92 testCertECDSAP384
93 testCertECDSAP521
94)
95
96const (
97 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040098 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +090099 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700100 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
101 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
102 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400103)
104
105const (
David Benjamina08e49d2014-08-24 01:46:07 -0400106 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400107 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900108 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700109 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
110 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
111 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400112 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400113)
114
David Benjamin7944a9f2016-07-12 22:27:01 -0400115var (
116 rsaCertificate Certificate
117 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900118 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400119 ecdsaP256Certificate Certificate
120 ecdsaP384Certificate Certificate
121 ecdsaP521Certificate Certificate
122)
David Benjamin33863262016-07-08 17:20:12 -0700123
124var testCerts = []struct {
125 id testCert
126 certFile, keyFile string
127 cert *Certificate
128}{
129 {
130 id: testCertRSA,
131 certFile: rsaCertificateFile,
132 keyFile: rsaKeyFile,
133 cert: &rsaCertificate,
134 },
135 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400136 id: testCertRSA1024,
137 certFile: rsa1024CertificateFile,
138 keyFile: rsa1024KeyFile,
139 cert: &rsa1024Certificate,
140 },
141 {
David Benjamin2c516452016-11-15 10:16:54 +0900142 id: testCertRSAChain,
143 certFile: rsaChainCertificateFile,
144 keyFile: rsaChainKeyFile,
145 cert: &rsaChainCertificate,
146 },
147 {
David Benjamin33863262016-07-08 17:20:12 -0700148 id: testCertECDSAP256,
149 certFile: ecdsaP256CertificateFile,
150 keyFile: ecdsaP256KeyFile,
151 cert: &ecdsaP256Certificate,
152 },
153 {
154 id: testCertECDSAP384,
155 certFile: ecdsaP384CertificateFile,
156 keyFile: ecdsaP384KeyFile,
157 cert: &ecdsaP384Certificate,
158 },
159 {
160 id: testCertECDSAP521,
161 certFile: ecdsaP521CertificateFile,
162 keyFile: ecdsaP521KeyFile,
163 cert: &ecdsaP521Certificate,
164 },
165}
166
David Benjamina08e49d2014-08-24 01:46:07 -0400167var channelIDKey *ecdsa.PrivateKey
168var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700169
David Benjamin61f95272014-11-25 01:55:35 -0500170var testOCSPResponse = []byte{1, 2, 3, 4}
171var testSCTList = []byte{5, 6, 7, 8}
172
Adam Langley95c29f32014-06-20 12:00:00 -0700173func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700174 for i := range testCerts {
175 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
176 if err != nil {
177 panic(err)
178 }
179 cert.OCSPStaple = testOCSPResponse
180 cert.SignedCertificateTimestampList = testSCTList
181 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700182 }
David Benjamina08e49d2014-08-24 01:46:07 -0400183
Adam Langley7c803a62015-06-15 15:35:05 -0700184 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400185 if err != nil {
186 panic(err)
187 }
188 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
189 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
190 panic("bad key type")
191 }
192 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
193 if err != nil {
194 panic(err)
195 }
196 if channelIDKey.Curve != elliptic.P256() {
197 panic("bad curve")
198 }
199
200 channelIDBytes = make([]byte, 64)
201 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
202 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700203}
204
David Benjamin33863262016-07-08 17:20:12 -0700205func getRunnerCertificate(t testCert) Certificate {
206 for _, cert := range testCerts {
207 if cert.id == t {
208 return *cert.cert
209 }
210 }
211 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700212}
213
David Benjamin33863262016-07-08 17:20:12 -0700214func getShimCertificate(t testCert) string {
215 for _, cert := range testCerts {
216 if cert.id == t {
217 return cert.certFile
218 }
219 }
220 panic("Unknown test certificate")
221}
222
223func getShimKey(t testCert) string {
224 for _, cert := range testCerts {
225 if cert.id == t {
226 return cert.keyFile
227 }
228 }
229 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700230}
231
David Benjamin025b3d32014-07-01 19:53:04 -0400232type testType int
233
234const (
235 clientTest testType = iota
236 serverTest
237)
238
David Benjamin6fd297b2014-08-11 18:43:38 -0400239type protocol int
240
241const (
242 tls protocol = iota
243 dtls
244)
245
David Benjaminfc7b0862014-09-06 13:21:53 -0400246const (
247 alpn = 1
248 npn = 2
249)
250
Adam Langley95c29f32014-06-20 12:00:00 -0700251type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400252 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400253 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700254 name string
255 config Config
256 shouldFail bool
257 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700258 // expectedLocalError, if not empty, contains a substring that must be
259 // found in the local error.
260 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400261 // expectedVersion, if non-zero, specifies the TLS version that must be
262 // negotiated.
263 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400264 // expectedResumeVersion, if non-zero, specifies the TLS version that
265 // must be negotiated on resumption. If zero, expectedVersion is used.
266 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400267 // expectedCipher, if non-zero, specifies the TLS cipher suite that
268 // should be negotiated.
269 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400270 // expectChannelID controls whether the connection should have
271 // negotiated a Channel ID with channelIDKey.
272 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400273 // expectedNextProto controls whether the connection should
274 // negotiate a next protocol via NPN or ALPN.
275 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400276 // expectNoNextProto, if true, means that no next protocol should be
277 // negotiated.
278 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400279 // expectedNextProtoType, if non-zero, is the expected next
280 // protocol negotiation mechanism.
281 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500282 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
283 // should be negotiated. If zero, none should be negotiated.
284 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100285 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
286 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100287 // expectedSCTList, if not nil, is the expected SCT list to be received.
288 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700289 // expectedPeerSignatureAlgorithm, if not zero, is the signature
290 // algorithm that the peer should have used in the handshake.
291 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400292 // expectedCurveID, if not zero, is the curve that the handshake should
293 // have used.
294 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700295 // messageLen is the length, in bytes, of the test message that will be
296 // sent.
297 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400298 // messageCount is the number of test messages that will be sent.
299 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400300 // certFile is the path to the certificate to use for the server.
301 certFile string
302 // keyFile is the path to the private key to use for the server.
303 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400304 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400305 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400306 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400307 // resumeRenewedSession controls whether a third connection should be
308 // tested which attempts to resume the second connection's session.
309 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700310 // expectResumeRejected, if true, specifies that the attempted
311 // resumption must be rejected by the client. This is only valid for a
312 // serverTest.
313 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400314 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500315 // resumption. Unless newSessionsOnResume is set,
316 // SessionTicketKey, ServerSessionCache, and
317 // ClientSessionCache are copied from the initial connection's
318 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400319 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500320 // newSessionsOnResume, if true, will cause resumeConfig to
321 // use a different session resumption context.
322 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400323 // noSessionCache, if true, will cause the server to run without a
324 // session cache.
325 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400326 // sendPrefix sends a prefix on the socket before actually performing a
327 // handshake.
328 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400329 // shimWritesFirst controls whether the shim sends an initial "hello"
330 // message before doing a roundtrip with the runner.
331 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400332 // shimShutsDown, if true, runs a test where the shim shuts down the
333 // connection immediately after the handshake rather than echoing
334 // messages from the runner.
335 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400336 // renegotiate indicates the number of times the connection should be
337 // renegotiated during the exchange.
338 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400339 // sendHalfHelloRequest, if true, causes the server to send half a
340 // HelloRequest when the handshake completes.
341 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700342 // renegotiateCiphers is a list of ciphersuite ids that will be
343 // switched in just before renegotiation.
344 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500345 // replayWrites, if true, configures the underlying transport
346 // to replay every write it makes in DTLS tests.
347 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500348 // damageFirstWrite, if true, configures the underlying transport to
349 // damage the final byte of the first application data write.
350 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400351 // exportKeyingMaterial, if non-zero, configures the test to exchange
352 // keying material and verify they match.
353 exportKeyingMaterial int
354 exportLabel string
355 exportContext string
356 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400357 // flags, if not empty, contains a list of command-line flags that will
358 // be passed to the shim program.
359 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700360 // testTLSUnique, if true, causes the shim to send the tls-unique value
361 // which will be compared against the expected value.
362 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400363 // sendEmptyRecords is the number of consecutive empty records to send
364 // before and after the test message.
365 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400366 // sendWarningAlerts is the number of consecutive warning alerts to send
367 // before and after the test message.
368 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400369 // sendKeyUpdates is the number of consecutive key updates to send
370 // before and after the test message.
371 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400372 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
373 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400374 // expectMessageDropped, if true, means the test message is expected to
375 // be dropped by the client rather than echoed back.
376 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900377 // expectPeerCertificate, if not nil, is the certificate chain the peer
378 // is expected to send.
379 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700380}
381
Adam Langley7c803a62015-06-15 15:35:05 -0700382var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700383
David Benjaminc07afb72016-09-22 10:18:58 -0400384func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500385 if len(data) == 0 {
386 return
387 }
388
389 protocol := "tls"
390 if test.protocol == dtls {
391 protocol = "dtls"
392 }
393
394 side := "client"
395 if test.testType == serverTest {
396 side = "server"
397 }
398
399 dir := path.Join(*transcriptDir, protocol, side)
400 if err := os.MkdirAll(dir, 0755); err != nil {
401 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
402 return
403 }
404
David Benjaminc07afb72016-09-22 10:18:58 -0400405 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500406 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
407 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
408 }
409}
410
David Benjamin3ed59772016-03-08 12:50:21 -0500411// A timeoutConn implements an idle timeout on each Read and Write operation.
412type timeoutConn struct {
413 net.Conn
414 timeout time.Duration
415}
416
417func (t *timeoutConn) Read(b []byte) (int, error) {
418 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
419 return 0, err
420 }
421 return t.Conn.Read(b)
422}
423
424func (t *timeoutConn) Write(b []byte) (int, error) {
425 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
426 return 0, err
427 }
428 return t.Conn.Write(b)
429}
430
David Benjaminc07afb72016-09-22 10:18:58 -0400431func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400432 if !test.noSessionCache {
433 if config.ClientSessionCache == nil {
434 config.ClientSessionCache = NewLRUClientSessionCache(1)
435 }
436 if config.ServerSessionCache == nil {
437 config.ServerSessionCache = NewLRUServerSessionCache(1)
438 }
439 }
440 if test.testType == clientTest {
441 if len(config.Certificates) == 0 {
442 config.Certificates = []Certificate{rsaCertificate}
443 }
444 } else {
445 // Supply a ServerName to ensure a constant session cache key,
446 // rather than falling back to net.Conn.RemoteAddr.
447 if len(config.ServerName) == 0 {
448 config.ServerName = "test"
449 }
450 }
451 if *fuzzer {
452 config.Bugs.NullAllCiphers = true
453 }
David Benjamin01a90572016-09-22 00:11:43 -0400454 if *deterministic {
455 config.Time = func() time.Time { return time.Unix(1234, 1234) }
456 }
David Benjamine54af062016-08-08 19:21:18 -0400457
David Benjamin01784b42016-06-07 18:00:52 -0400458 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500459
David Benjamin6fd297b2014-08-11 18:43:38 -0400460 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500461 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
462 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500463 }
464
David Benjamin9867b7d2016-03-01 23:25:48 -0500465 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500466 local, peer := "client", "server"
467 if test.testType == clientTest {
468 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470 connDebug := &recordingConn{
471 Conn: conn,
472 isDatagram: test.protocol == dtls,
473 local: local,
474 peer: peer,
475 }
476 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500477 if *flagDebug {
478 defer connDebug.WriteTo(os.Stdout)
479 }
480 if len(*transcriptDir) != 0 {
481 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400482 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500483 }()
484 }
David Benjaminebda9b32015-11-02 15:33:18 -0500485
486 if config.Bugs.PacketAdaptor != nil {
487 config.Bugs.PacketAdaptor.debug = connDebug
488 }
489 }
490
491 if test.replayWrites {
492 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400493 }
494
David Benjamin3ed59772016-03-08 12:50:21 -0500495 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500496 if test.damageFirstWrite {
497 connDamage = newDamageAdaptor(conn)
498 conn = connDamage
499 }
500
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.sendPrefix != "" {
502 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
503 return err
504 }
David Benjamin98e882e2014-08-08 13:24:34 -0400505 }
506
David Benjamin1d5c83e2014-07-22 19:20:02 -0400507 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400508 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400509 if test.protocol == dtls {
510 tlsConn = DTLSServer(conn, config)
511 } else {
512 tlsConn = Server(conn, config)
513 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400514 } else {
515 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400516 if test.protocol == dtls {
517 tlsConn = DTLSClient(conn, config)
518 } else {
519 tlsConn = Client(conn, config)
520 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400521 }
David Benjamin30789da2015-08-29 22:56:45 -0400522 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400523
Adam Langley95c29f32014-06-20 12:00:00 -0700524 if err := tlsConn.Handshake(); err != nil {
525 return err
526 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700527
David Benjamin01fe8202014-09-24 15:21:44 -0400528 // TODO(davidben): move all per-connection expectations into a dedicated
529 // expectations struct that can be specified separately for the two
530 // legs.
531 expectedVersion := test.expectedVersion
532 if isResume && test.expectedResumeVersion != 0 {
533 expectedVersion = test.expectedResumeVersion
534 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700535 connState := tlsConn.ConnectionState()
536 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400537 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400538 }
539
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700540 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400541 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
542 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700543 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
544 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
545 }
David Benjamin90da8c82015-04-20 14:57:57 -0400546
David Benjamina08e49d2014-08-24 01:46:07 -0400547 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700548 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400549 if channelID == nil {
550 return fmt.Errorf("no channel ID negotiated")
551 }
552 if channelID.Curve != channelIDKey.Curve ||
553 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
554 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
555 return fmt.Errorf("incorrect channel ID")
556 }
557 }
558
David Benjaminae2888f2014-09-06 12:58:58 -0400559 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700560 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400561 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
562 }
563 }
564
David Benjaminc7ce9772015-10-09 19:32:41 -0400565 if test.expectNoNextProto {
566 if actual := connState.NegotiatedProtocol; actual != "" {
567 return fmt.Errorf("got unexpected next proto %s", actual)
568 }
569 }
570
David Benjaminfc7b0862014-09-06 13:21:53 -0400571 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700572 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400573 return fmt.Errorf("next proto type mismatch")
574 }
575 }
576
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700577 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500578 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
579 }
580
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100581 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300582 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100583 }
584
Paul Lietar4fac72e2015-09-09 13:44:55 +0100585 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
586 return fmt.Errorf("SCT list mismatch")
587 }
588
Nick Harper60edffd2016-06-21 15:19:24 -0700589 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
590 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400591 }
592
Steven Valdez5440fe02016-07-18 12:40:30 -0400593 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
594 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
595 }
596
David Benjamin2c516452016-11-15 10:16:54 +0900597 if test.expectPeerCertificate != nil {
598 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
599 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
600 }
601 for i, cert := range connState.PeerCertificates {
602 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
603 return fmt.Errorf("peer certificate %d did not match", i+1)
604 }
605 }
606 }
607
David Benjaminc565ebb2015-04-03 04:06:36 -0400608 if test.exportKeyingMaterial > 0 {
609 actual := make([]byte, test.exportKeyingMaterial)
610 if _, err := io.ReadFull(tlsConn, actual); err != nil {
611 return err
612 }
613 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
614 if err != nil {
615 return err
616 }
617 if !bytes.Equal(actual, expected) {
618 return fmt.Errorf("keying material mismatch")
619 }
620 }
621
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700622 if test.testTLSUnique {
623 var peersValue [12]byte
624 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
625 return err
626 }
627 expected := tlsConn.ConnectionState().TLSUnique
628 if !bytes.Equal(peersValue[:], expected) {
629 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
630 }
631 }
632
David Benjamine58c4f52014-08-24 03:47:07 -0400633 if test.shimWritesFirst {
634 var buf [5]byte
635 _, err := io.ReadFull(tlsConn, buf[:])
636 if err != nil {
637 return err
638 }
639 if string(buf[:]) != "hello" {
640 return fmt.Errorf("bad initial message")
641 }
642 }
643
Steven Valdez32635b82016-08-16 11:25:03 -0400644 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400645 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400646 return err
647 }
Steven Valdez32635b82016-08-16 11:25:03 -0400648 }
649
David Benjamina8ebe222015-06-06 03:04:39 -0400650 for i := 0; i < test.sendEmptyRecords; i++ {
651 tlsConn.Write(nil)
652 }
653
David Benjamin24f346d2015-06-06 03:28:08 -0400654 for i := 0; i < test.sendWarningAlerts; i++ {
655 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
656 }
657
David Benjamin47921102016-07-28 11:29:18 -0400658 if test.sendHalfHelloRequest {
659 tlsConn.SendHalfHelloRequest()
660 }
661
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400662 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700663 if test.renegotiateCiphers != nil {
664 config.CipherSuites = test.renegotiateCiphers
665 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400666 for i := 0; i < test.renegotiate; i++ {
667 if err := tlsConn.Renegotiate(); err != nil {
668 return err
669 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700670 }
671 } else if test.renegotiateCiphers != nil {
672 panic("renegotiateCiphers without renegotiate")
673 }
674
David Benjamin5fa3eba2015-01-22 16:35:40 -0500675 if test.damageFirstWrite {
676 connDamage.setDamage(true)
677 tlsConn.Write([]byte("DAMAGED WRITE"))
678 connDamage.setDamage(false)
679 }
680
David Benjamin8e6db492015-07-25 18:29:23 -0400681 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700682 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400683 if test.protocol == dtls {
684 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
685 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700686 // Read until EOF.
687 _, err := io.Copy(ioutil.Discard, tlsConn)
688 return err
689 }
David Benjamin4417d052015-04-05 04:17:25 -0400690 if messageLen == 0 {
691 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700692 }
Adam Langley95c29f32014-06-20 12:00:00 -0700693
David Benjamin8e6db492015-07-25 18:29:23 -0400694 messageCount := test.messageCount
695 if messageCount == 0 {
696 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400697 }
698
David Benjamin8e6db492015-07-25 18:29:23 -0400699 for j := 0; j < messageCount; j++ {
700 testMessage := make([]byte, messageLen)
701 for i := range testMessage {
702 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400703 }
David Benjamin8e6db492015-07-25 18:29:23 -0400704 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700705
Steven Valdez32635b82016-08-16 11:25:03 -0400706 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400707 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400708 }
709
David Benjamin8e6db492015-07-25 18:29:23 -0400710 for i := 0; i < test.sendEmptyRecords; i++ {
711 tlsConn.Write(nil)
712 }
713
714 for i := 0; i < test.sendWarningAlerts; i++ {
715 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
716 }
717
David Benjamin4f75aaf2015-09-01 16:53:10 -0400718 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400719 // The shim will not respond.
720 continue
721 }
722
David Benjamin8e6db492015-07-25 18:29:23 -0400723 buf := make([]byte, len(testMessage))
724 if test.protocol == dtls {
725 bufTmp := make([]byte, len(buf)+1)
726 n, err := tlsConn.Read(bufTmp)
727 if err != nil {
728 return err
729 }
730 if n != len(buf) {
731 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
732 }
733 copy(buf, bufTmp)
734 } else {
735 _, err := io.ReadFull(tlsConn, buf)
736 if err != nil {
737 return err
738 }
739 }
740
741 for i, v := range buf {
742 if v != testMessage[i]^0xff {
743 return fmt.Errorf("bad reply contents at byte %d", i)
744 }
Adam Langley95c29f32014-06-20 12:00:00 -0700745 }
746 }
747
748 return nil
749}
750
David Benjamin325b5c32014-07-01 19:40:31 -0400751func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400752 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700753 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400754 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700755 }
David Benjamin325b5c32014-07-01 19:40:31 -0400756 valgrindArgs = append(valgrindArgs, path)
757 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700758
David Benjamin325b5c32014-07-01 19:40:31 -0400759 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700760}
761
David Benjamin325b5c32014-07-01 19:40:31 -0400762func gdbOf(path string, args ...string) *exec.Cmd {
763 xtermArgs := []string{"-e", "gdb", "--args"}
764 xtermArgs = append(xtermArgs, path)
765 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700766
David Benjamin325b5c32014-07-01 19:40:31 -0400767 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700768}
769
David Benjamind16bf342015-12-18 00:53:12 -0500770func lldbOf(path string, args ...string) *exec.Cmd {
771 xtermArgs := []string{"-e", "lldb", "--"}
772 xtermArgs = append(xtermArgs, path)
773 xtermArgs = append(xtermArgs, args...)
774
775 return exec.Command("xterm", xtermArgs...)
776}
777
EKR842ae6c2016-07-27 09:22:05 +0200778var (
779 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
780 errUnimplemented = errors.New("child process does not implement needed flags")
781)
Adam Langley69a01602014-11-17 17:26:55 -0800782
David Benjamin87c8a642015-02-21 01:54:29 -0500783// accept accepts a connection from listener, unless waitChan signals a process
784// exit first.
785func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
786 type connOrError struct {
787 conn net.Conn
788 err error
789 }
790 connChan := make(chan connOrError, 1)
791 go func() {
792 conn, err := listener.Accept()
793 connChan <- connOrError{conn, err}
794 close(connChan)
795 }()
796 select {
797 case result := <-connChan:
798 return result.conn, result.err
799 case childErr := <-waitChan:
800 waitChan <- childErr
801 return nil, fmt.Errorf("child exited early: %s", childErr)
802 }
803}
804
EKRf71d7ed2016-08-06 13:25:12 -0700805func translateExpectedError(errorStr string) string {
806 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
807 return translated
808 }
809
810 if *looseErrors {
811 return ""
812 }
813
814 return errorStr
815}
816
Adam Langley7c803a62015-06-15 15:35:05 -0700817func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400818 // Help debugging panics on the Go side.
819 defer func() {
820 if r := recover(); r != nil {
821 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
822 panic(r)
823 }
824 }()
825
Adam Langley38311732014-10-16 19:04:35 -0700826 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
827 panic("Error expected without shouldFail in " + test.name)
828 }
829
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700830 if test.expectResumeRejected && !test.resumeSession {
831 panic("expectResumeRejected without resumeSession in " + test.name)
832 }
833
David Benjamin87c8a642015-02-21 01:54:29 -0500834 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
835 if err != nil {
836 panic(err)
837 }
838 defer func() {
839 if listener != nil {
840 listener.Close()
841 }
842 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700843
David Benjamin87c8a642015-02-21 01:54:29 -0500844 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400845 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400846 flags = append(flags, "-server")
847
David Benjamin025b3d32014-07-01 19:53:04 -0400848 flags = append(flags, "-key-file")
849 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700850 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400851 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700852 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400853 }
854
855 flags = append(flags, "-cert-file")
856 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700857 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400858 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700859 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400860 }
861 }
David Benjamin5a593af2014-08-11 19:51:50 -0400862
David Benjamin6fd297b2014-08-11 18:43:38 -0400863 if test.protocol == dtls {
864 flags = append(flags, "-dtls")
865 }
866
David Benjamin46662482016-08-17 00:51:00 -0400867 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400868 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400869 resumeCount++
870 if test.resumeRenewedSession {
871 resumeCount++
872 }
873 }
874
875 if resumeCount > 0 {
876 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400877 }
878
David Benjamine58c4f52014-08-24 03:47:07 -0400879 if test.shimWritesFirst {
880 flags = append(flags, "-shim-writes-first")
881 }
882
David Benjamin30789da2015-08-29 22:56:45 -0400883 if test.shimShutsDown {
884 flags = append(flags, "-shim-shuts-down")
885 }
886
David Benjaminc565ebb2015-04-03 04:06:36 -0400887 if test.exportKeyingMaterial > 0 {
888 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
889 flags = append(flags, "-export-label", test.exportLabel)
890 flags = append(flags, "-export-context", test.exportContext)
891 if test.useExportContext {
892 flags = append(flags, "-use-export-context")
893 }
894 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700895 if test.expectResumeRejected {
896 flags = append(flags, "-expect-session-miss")
897 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400898
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700899 if test.testTLSUnique {
900 flags = append(flags, "-tls-unique")
901 }
902
David Benjamin025b3d32014-07-01 19:53:04 -0400903 flags = append(flags, test.flags...)
904
905 var shim *exec.Cmd
906 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700907 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700908 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700909 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500910 } else if *useLLDB {
911 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400912 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700913 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400914 }
David Benjamin025b3d32014-07-01 19:53:04 -0400915 shim.Stdin = os.Stdin
916 var stdoutBuf, stderrBuf bytes.Buffer
917 shim.Stdout = &stdoutBuf
918 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800919 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500920 shim.Env = os.Environ()
921 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800922 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400923 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800924 }
925 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
926 }
David Benjamin025b3d32014-07-01 19:53:04 -0400927
928 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700929 panic(err)
930 }
David Benjamin87c8a642015-02-21 01:54:29 -0500931 waitChan := make(chan error, 1)
932 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700933
934 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700935
David Benjamin7a4aaa42016-09-20 17:58:14 -0400936 if *deterministic {
937 config.Rand = &deterministicRand{}
938 }
939
David Benjamin87c8a642015-02-21 01:54:29 -0500940 conn, err := acceptOrWait(listener, waitChan)
941 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400942 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500943 conn.Close()
944 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500945
David Benjamin46662482016-08-17 00:51:00 -0400946 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400947 var resumeConfig Config
948 if test.resumeConfig != nil {
949 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400950 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500951 resumeConfig.SessionTicketKey = config.SessionTicketKey
952 resumeConfig.ClientSessionCache = config.ClientSessionCache
953 resumeConfig.ServerSessionCache = config.ServerSessionCache
954 }
David Benjamin2e045a92016-06-08 13:09:56 -0400955 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400956 } else {
957 resumeConfig = config
958 }
David Benjamin87c8a642015-02-21 01:54:29 -0500959 var connResume net.Conn
960 connResume, err = acceptOrWait(listener, waitChan)
961 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400962 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500963 connResume.Close()
964 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400965 }
966
David Benjamin87c8a642015-02-21 01:54:29 -0500967 // Close the listener now. This is to avoid hangs should the shim try to
968 // open more connections than expected.
969 listener.Close()
970 listener = nil
971
972 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400973 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800974 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200975 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
976 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800977 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200978 case 89:
979 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400980 case 99:
981 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800982 }
983 }
Adam Langley95c29f32014-06-20 12:00:00 -0700984
David Benjamin9bea3492016-03-02 10:59:16 -0500985 // Account for Windows line endings.
986 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
987 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500988
989 // Separate the errors from the shim and those from tools like
990 // AddressSanitizer.
991 var extraStderr string
992 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
993 stderr = stderrParts[0]
994 extraStderr = stderrParts[1]
995 }
996
Adam Langley95c29f32014-06-20 12:00:00 -0700997 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700998 expectedError := translateExpectedError(test.expectedError)
999 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001000
Adam Langleyac61fa32014-06-23 12:03:11 -07001001 localError := "none"
1002 if err != nil {
1003 localError = err.Error()
1004 }
1005 if len(test.expectedLocalError) != 0 {
1006 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1007 }
Adam Langley95c29f32014-06-20 12:00:00 -07001008
1009 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001010 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001011 if childErr != nil {
1012 childError = childErr.Error()
1013 }
1014
1015 var msg string
1016 switch {
1017 case failed && !test.shouldFail:
1018 msg = "unexpected failure"
1019 case !failed && test.shouldFail:
1020 msg = "unexpected success"
1021 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001022 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001023 default:
1024 panic("internal error")
1025 }
1026
David Benjamin9aafb642016-09-20 19:36:53 -04001027 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 -07001028 }
1029
David Benjamind2ba8892016-09-20 19:41:04 -04001030 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001031 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001032 }
1033
David Benjamind2ba8892016-09-20 19:41:04 -04001034 if *useValgrind && isValgrindError {
1035 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1036 }
1037
Adam Langley95c29f32014-06-20 12:00:00 -07001038 return nil
1039}
1040
1041var tlsVersions = []struct {
1042 name string
1043 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001044 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001045 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001046}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001047 {"SSL3", VersionSSL30, "-no-ssl3", false},
1048 {"TLS1", VersionTLS10, "-no-tls1", true},
1049 {"TLS11", VersionTLS11, "-no-tls11", false},
1050 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001051 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001052}
1053
1054var testCipherSuites = []struct {
1055 name string
1056 id uint16
1057}{
1058 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001059 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001060 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001061 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001062 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001063 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001064 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001065 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1066 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001067 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001068 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1069 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001070 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001071 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1072 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001073 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1074 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001075 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001076 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001077 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001078 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001079 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001080 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001081 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001082 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001083 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001084 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001085 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001086 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001087 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1088 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1089 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1090 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001091 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1092 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001093 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1094 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001095 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001096 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1097 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1098 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001099 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001100}
1101
David Benjamin8b8c0062014-11-23 02:47:52 -05001102func hasComponent(suiteName, component string) bool {
1103 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1104}
1105
David Benjaminf7768e42014-08-31 02:06:47 -04001106func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001107 return hasComponent(suiteName, "GCM") ||
1108 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001109 hasComponent(suiteName, "SHA384") ||
1110 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001111}
1112
Nick Harper1fd39d82016-06-14 18:14:35 -07001113func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001114 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001115}
1116
David Benjamin8b8c0062014-11-23 02:47:52 -05001117func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001118 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001119}
1120
Adam Langleya7997f12015-05-14 17:38:50 -07001121func bigFromHex(hex string) *big.Int {
1122 ret, ok := new(big.Int).SetString(hex, 16)
1123 if !ok {
1124 panic("failed to parse hex number 0x" + hex)
1125 }
1126 return ret
1127}
1128
Adam Langley7c803a62015-06-15 15:35:05 -07001129func addBasicTests() {
1130 basicTests := []testCase{
1131 {
Adam Langley7c803a62015-06-15 15:35:05 -07001132 name: "NoFallbackSCSV",
1133 config: Config{
1134 Bugs: ProtocolBugs{
1135 FailIfNotFallbackSCSV: true,
1136 },
1137 },
1138 shouldFail: true,
1139 expectedLocalError: "no fallback SCSV found",
1140 },
1141 {
1142 name: "SendFallbackSCSV",
1143 config: Config{
1144 Bugs: ProtocolBugs{
1145 FailIfNotFallbackSCSV: true,
1146 },
1147 },
1148 flags: []string{"-fallback-scsv"},
1149 },
1150 {
1151 name: "ClientCertificateTypes",
1152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001153 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001154 ClientAuth: RequestClientCert,
1155 ClientCertificateTypes: []byte{
1156 CertTypeDSSSign,
1157 CertTypeRSASign,
1158 CertTypeECDSASign,
1159 },
1160 },
1161 flags: []string{
1162 "-expect-certificate-types",
1163 base64.StdEncoding.EncodeToString([]byte{
1164 CertTypeDSSSign,
1165 CertTypeRSASign,
1166 CertTypeECDSASign,
1167 }),
1168 },
1169 },
1170 {
Adam Langley7c803a62015-06-15 15:35:05 -07001171 name: "UnauthenticatedECDH",
1172 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001173 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001174 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1175 Bugs: ProtocolBugs{
1176 UnauthenticatedECDH: true,
1177 },
1178 },
1179 shouldFail: true,
1180 expectedError: ":UNEXPECTED_MESSAGE:",
1181 },
1182 {
1183 name: "SkipCertificateStatus",
1184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001185 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001186 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1187 Bugs: ProtocolBugs{
1188 SkipCertificateStatus: true,
1189 },
1190 },
1191 flags: []string{
1192 "-enable-ocsp-stapling",
1193 },
1194 },
1195 {
1196 name: "SkipServerKeyExchange",
1197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001198 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001199 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1200 Bugs: ProtocolBugs{
1201 SkipServerKeyExchange: true,
1202 },
1203 },
1204 shouldFail: true,
1205 expectedError: ":UNEXPECTED_MESSAGE:",
1206 },
1207 {
Adam Langley7c803a62015-06-15 15:35:05 -07001208 testType: serverTest,
1209 name: "Alert",
1210 config: Config{
1211 Bugs: ProtocolBugs{
1212 SendSpuriousAlert: alertRecordOverflow,
1213 },
1214 },
1215 shouldFail: true,
1216 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1217 },
1218 {
1219 protocol: dtls,
1220 testType: serverTest,
1221 name: "Alert-DTLS",
1222 config: Config{
1223 Bugs: ProtocolBugs{
1224 SendSpuriousAlert: alertRecordOverflow,
1225 },
1226 },
1227 shouldFail: true,
1228 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1229 },
1230 {
1231 testType: serverTest,
1232 name: "FragmentAlert",
1233 config: Config{
1234 Bugs: ProtocolBugs{
1235 FragmentAlert: true,
1236 SendSpuriousAlert: alertRecordOverflow,
1237 },
1238 },
1239 shouldFail: true,
1240 expectedError: ":BAD_ALERT:",
1241 },
1242 {
1243 protocol: dtls,
1244 testType: serverTest,
1245 name: "FragmentAlert-DTLS",
1246 config: Config{
1247 Bugs: ProtocolBugs{
1248 FragmentAlert: true,
1249 SendSpuriousAlert: alertRecordOverflow,
1250 },
1251 },
1252 shouldFail: true,
1253 expectedError: ":BAD_ALERT:",
1254 },
1255 {
1256 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001257 name: "DoubleAlert",
1258 config: Config{
1259 Bugs: ProtocolBugs{
1260 DoubleAlert: true,
1261 SendSpuriousAlert: alertRecordOverflow,
1262 },
1263 },
1264 shouldFail: true,
1265 expectedError: ":BAD_ALERT:",
1266 },
1267 {
1268 protocol: dtls,
1269 testType: serverTest,
1270 name: "DoubleAlert-DTLS",
1271 config: Config{
1272 Bugs: ProtocolBugs{
1273 DoubleAlert: true,
1274 SendSpuriousAlert: alertRecordOverflow,
1275 },
1276 },
1277 shouldFail: true,
1278 expectedError: ":BAD_ALERT:",
1279 },
1280 {
Adam Langley7c803a62015-06-15 15:35:05 -07001281 name: "SkipNewSessionTicket",
1282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001283 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001284 Bugs: ProtocolBugs{
1285 SkipNewSessionTicket: true,
1286 },
1287 },
1288 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001289 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001290 },
1291 {
1292 testType: serverTest,
1293 name: "FallbackSCSV",
1294 config: Config{
1295 MaxVersion: VersionTLS11,
1296 Bugs: ProtocolBugs{
1297 SendFallbackSCSV: true,
1298 },
1299 },
1300 shouldFail: true,
1301 expectedError: ":INAPPROPRIATE_FALLBACK:",
1302 },
1303 {
1304 testType: serverTest,
1305 name: "FallbackSCSV-VersionMatch",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 SendFallbackSCSV: true,
1309 },
1310 },
1311 },
1312 {
1313 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001314 name: "FallbackSCSV-VersionMatch-TLS12",
1315 config: Config{
1316 MaxVersion: VersionTLS12,
1317 Bugs: ProtocolBugs{
1318 SendFallbackSCSV: true,
1319 },
1320 },
1321 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1322 },
1323 {
1324 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001325 name: "FragmentedClientVersion",
1326 config: Config{
1327 Bugs: ProtocolBugs{
1328 MaxHandshakeRecordLength: 1,
1329 FragmentClientVersion: true,
1330 },
1331 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001332 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001333 },
1334 {
Adam Langley7c803a62015-06-15 15:35:05 -07001335 testType: serverTest,
1336 name: "HttpGET",
1337 sendPrefix: "GET / HTTP/1.0\n",
1338 shouldFail: true,
1339 expectedError: ":HTTP_REQUEST:",
1340 },
1341 {
1342 testType: serverTest,
1343 name: "HttpPOST",
1344 sendPrefix: "POST / HTTP/1.0\n",
1345 shouldFail: true,
1346 expectedError: ":HTTP_REQUEST:",
1347 },
1348 {
1349 testType: serverTest,
1350 name: "HttpHEAD",
1351 sendPrefix: "HEAD / HTTP/1.0\n",
1352 shouldFail: true,
1353 expectedError: ":HTTP_REQUEST:",
1354 },
1355 {
1356 testType: serverTest,
1357 name: "HttpPUT",
1358 sendPrefix: "PUT / HTTP/1.0\n",
1359 shouldFail: true,
1360 expectedError: ":HTTP_REQUEST:",
1361 },
1362 {
1363 testType: serverTest,
1364 name: "HttpCONNECT",
1365 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1366 shouldFail: true,
1367 expectedError: ":HTTPS_PROXY_REQUEST:",
1368 },
1369 {
1370 testType: serverTest,
1371 name: "Garbage",
1372 sendPrefix: "blah",
1373 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001374 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001375 },
1376 {
Adam Langley7c803a62015-06-15 15:35:05 -07001377 name: "RSAEphemeralKey",
1378 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001379 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001380 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1381 Bugs: ProtocolBugs{
1382 RSAEphemeralKey: true,
1383 },
1384 },
1385 shouldFail: true,
1386 expectedError: ":UNEXPECTED_MESSAGE:",
1387 },
1388 {
1389 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001390 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001391 shouldFail: true,
1392 expectedError: ":WRONG_SSL_VERSION:",
1393 },
1394 {
1395 protocol: dtls,
1396 name: "DisableEverything-DTLS",
1397 flags: []string{"-no-tls12", "-no-tls1"},
1398 shouldFail: true,
1399 expectedError: ":WRONG_SSL_VERSION:",
1400 },
1401 {
Adam Langley7c803a62015-06-15 15:35:05 -07001402 protocol: dtls,
1403 testType: serverTest,
1404 name: "MTU",
1405 config: Config{
1406 Bugs: ProtocolBugs{
1407 MaxPacketLength: 256,
1408 },
1409 },
1410 flags: []string{"-mtu", "256"},
1411 },
1412 {
1413 protocol: dtls,
1414 testType: serverTest,
1415 name: "MTUExceeded",
1416 config: Config{
1417 Bugs: ProtocolBugs{
1418 MaxPacketLength: 255,
1419 },
1420 },
1421 flags: []string{"-mtu", "256"},
1422 shouldFail: true,
1423 expectedLocalError: "dtls: exceeded maximum packet length",
1424 },
1425 {
1426 name: "CertMismatchRSA",
1427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001428 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001429 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001430 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001431 Bugs: ProtocolBugs{
1432 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1433 },
1434 },
1435 shouldFail: true,
1436 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1437 },
1438 {
1439 name: "CertMismatchECDSA",
1440 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001441 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001442 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001443 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001444 Bugs: ProtocolBugs{
1445 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1446 },
1447 },
1448 shouldFail: true,
1449 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1450 },
1451 {
1452 name: "EmptyCertificateList",
1453 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001454 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001455 Bugs: ProtocolBugs{
1456 EmptyCertificateList: true,
1457 },
1458 },
1459 shouldFail: true,
1460 expectedError: ":DECODE_ERROR:",
1461 },
1462 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001463 name: "EmptyCertificateList-TLS13",
1464 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001465 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001466 Bugs: ProtocolBugs{
1467 EmptyCertificateList: true,
1468 },
1469 },
1470 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001471 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001472 },
1473 {
Adam Langley7c803a62015-06-15 15:35:05 -07001474 name: "TLSFatalBadPackets",
1475 damageFirstWrite: true,
1476 shouldFail: true,
1477 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1478 },
1479 {
1480 protocol: dtls,
1481 name: "DTLSIgnoreBadPackets",
1482 damageFirstWrite: true,
1483 },
1484 {
1485 protocol: dtls,
1486 name: "DTLSIgnoreBadPackets-Async",
1487 damageFirstWrite: true,
1488 flags: []string{"-async"},
1489 },
1490 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001491 name: "AppDataBeforeHandshake",
1492 config: Config{
1493 Bugs: ProtocolBugs{
1494 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1495 },
1496 },
1497 shouldFail: true,
1498 expectedError: ":UNEXPECTED_RECORD:",
1499 },
1500 {
1501 name: "AppDataBeforeHandshake-Empty",
1502 config: Config{
1503 Bugs: ProtocolBugs{
1504 AppDataBeforeHandshake: []byte{},
1505 },
1506 },
1507 shouldFail: true,
1508 expectedError: ":UNEXPECTED_RECORD:",
1509 },
1510 {
1511 protocol: dtls,
1512 name: "AppDataBeforeHandshake-DTLS",
1513 config: Config{
1514 Bugs: ProtocolBugs{
1515 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1516 },
1517 },
1518 shouldFail: true,
1519 expectedError: ":UNEXPECTED_RECORD:",
1520 },
1521 {
1522 protocol: dtls,
1523 name: "AppDataBeforeHandshake-DTLS-Empty",
1524 config: Config{
1525 Bugs: ProtocolBugs{
1526 AppDataBeforeHandshake: []byte{},
1527 },
1528 },
1529 shouldFail: true,
1530 expectedError: ":UNEXPECTED_RECORD:",
1531 },
1532 {
Adam Langley7c803a62015-06-15 15:35:05 -07001533 name: "AppDataAfterChangeCipherSpec",
1534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001535 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001536 Bugs: ProtocolBugs{
1537 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1538 },
1539 },
1540 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001541 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001542 },
1543 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001544 name: "AppDataAfterChangeCipherSpec-Empty",
1545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001546 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001547 Bugs: ProtocolBugs{
1548 AppDataAfterChangeCipherSpec: []byte{},
1549 },
1550 },
1551 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001552 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001553 },
1554 {
Adam Langley7c803a62015-06-15 15:35:05 -07001555 protocol: dtls,
1556 name: "AppDataAfterChangeCipherSpec-DTLS",
1557 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001558 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001559 Bugs: ProtocolBugs{
1560 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1561 },
1562 },
1563 // BoringSSL's DTLS implementation will drop the out-of-order
1564 // application data.
1565 },
1566 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001567 protocol: dtls,
1568 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001570 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 Bugs: ProtocolBugs{
1572 AppDataAfterChangeCipherSpec: []byte{},
1573 },
1574 },
1575 // BoringSSL's DTLS implementation will drop the out-of-order
1576 // application data.
1577 },
1578 {
Adam Langley7c803a62015-06-15 15:35:05 -07001579 name: "AlertAfterChangeCipherSpec",
1580 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001581 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001582 Bugs: ProtocolBugs{
1583 AlertAfterChangeCipherSpec: alertRecordOverflow,
1584 },
1585 },
1586 shouldFail: true,
1587 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1588 },
1589 {
1590 protocol: dtls,
1591 name: "AlertAfterChangeCipherSpec-DTLS",
1592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001593 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001594 Bugs: ProtocolBugs{
1595 AlertAfterChangeCipherSpec: alertRecordOverflow,
1596 },
1597 },
1598 shouldFail: true,
1599 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1600 },
1601 {
1602 protocol: dtls,
1603 name: "ReorderHandshakeFragments-Small-DTLS",
1604 config: Config{
1605 Bugs: ProtocolBugs{
1606 ReorderHandshakeFragments: true,
1607 // Small enough that every handshake message is
1608 // fragmented.
1609 MaxHandshakeRecordLength: 2,
1610 },
1611 },
1612 },
1613 {
1614 protocol: dtls,
1615 name: "ReorderHandshakeFragments-Large-DTLS",
1616 config: Config{
1617 Bugs: ProtocolBugs{
1618 ReorderHandshakeFragments: true,
1619 // Large enough that no handshake message is
1620 // fragmented.
1621 MaxHandshakeRecordLength: 2048,
1622 },
1623 },
1624 },
1625 {
1626 protocol: dtls,
1627 name: "MixCompleteMessageWithFragments-DTLS",
1628 config: Config{
1629 Bugs: ProtocolBugs{
1630 ReorderHandshakeFragments: true,
1631 MixCompleteMessageWithFragments: true,
1632 MaxHandshakeRecordLength: 2,
1633 },
1634 },
1635 },
1636 {
1637 name: "SendInvalidRecordType",
1638 config: Config{
1639 Bugs: ProtocolBugs{
1640 SendInvalidRecordType: true,
1641 },
1642 },
1643 shouldFail: true,
1644 expectedError: ":UNEXPECTED_RECORD:",
1645 },
1646 {
1647 protocol: dtls,
1648 name: "SendInvalidRecordType-DTLS",
1649 config: Config{
1650 Bugs: ProtocolBugs{
1651 SendInvalidRecordType: true,
1652 },
1653 },
1654 shouldFail: true,
1655 expectedError: ":UNEXPECTED_RECORD:",
1656 },
1657 {
1658 name: "FalseStart-SkipServerSecondLeg",
1659 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001660 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001661 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1662 NextProtos: []string{"foo"},
1663 Bugs: ProtocolBugs{
1664 SkipNewSessionTicket: true,
1665 SkipChangeCipherSpec: true,
1666 SkipFinished: true,
1667 ExpectFalseStart: true,
1668 },
1669 },
1670 flags: []string{
1671 "-false-start",
1672 "-handshake-never-done",
1673 "-advertise-alpn", "\x03foo",
1674 },
1675 shimWritesFirst: true,
1676 shouldFail: true,
1677 expectedError: ":UNEXPECTED_RECORD:",
1678 },
1679 {
1680 name: "FalseStart-SkipServerSecondLeg-Implicit",
1681 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001682 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001683 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1684 NextProtos: []string{"foo"},
1685 Bugs: ProtocolBugs{
1686 SkipNewSessionTicket: true,
1687 SkipChangeCipherSpec: true,
1688 SkipFinished: true,
1689 },
1690 },
1691 flags: []string{
1692 "-implicit-handshake",
1693 "-false-start",
1694 "-handshake-never-done",
1695 "-advertise-alpn", "\x03foo",
1696 },
1697 shouldFail: true,
1698 expectedError: ":UNEXPECTED_RECORD:",
1699 },
1700 {
1701 testType: serverTest,
1702 name: "FailEarlyCallback",
1703 flags: []string{"-fail-early-callback"},
1704 shouldFail: true,
1705 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001706 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001707 },
1708 {
Adam Langley7c803a62015-06-15 15:35:05 -07001709 protocol: dtls,
1710 name: "FragmentMessageTypeMismatch-DTLS",
1711 config: Config{
1712 Bugs: ProtocolBugs{
1713 MaxHandshakeRecordLength: 2,
1714 FragmentMessageTypeMismatch: true,
1715 },
1716 },
1717 shouldFail: true,
1718 expectedError: ":FRAGMENT_MISMATCH:",
1719 },
1720 {
1721 protocol: dtls,
1722 name: "FragmentMessageLengthMismatch-DTLS",
1723 config: Config{
1724 Bugs: ProtocolBugs{
1725 MaxHandshakeRecordLength: 2,
1726 FragmentMessageLengthMismatch: true,
1727 },
1728 },
1729 shouldFail: true,
1730 expectedError: ":FRAGMENT_MISMATCH:",
1731 },
1732 {
1733 protocol: dtls,
1734 name: "SplitFragments-Header-DTLS",
1735 config: Config{
1736 Bugs: ProtocolBugs{
1737 SplitFragments: 2,
1738 },
1739 },
1740 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001741 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001742 },
1743 {
1744 protocol: dtls,
1745 name: "SplitFragments-Boundary-DTLS",
1746 config: Config{
1747 Bugs: ProtocolBugs{
1748 SplitFragments: dtlsRecordHeaderLen,
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-Body-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 SplitFragments: dtlsRecordHeaderLen + 1,
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: "SendEmptyFragments-DTLS",
1768 config: Config{
1769 Bugs: ProtocolBugs{
1770 SendEmptyFragments: true,
1771 },
1772 },
1773 },
1774 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001775 name: "BadFinished-Client",
1776 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001777 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001778 Bugs: ProtocolBugs{
1779 BadFinished: true,
1780 },
1781 },
1782 shouldFail: true,
1783 expectedError: ":DIGEST_CHECK_FAILED:",
1784 },
1785 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001786 name: "BadFinished-Client-TLS13",
1787 config: Config{
1788 MaxVersion: VersionTLS13,
1789 Bugs: ProtocolBugs{
1790 BadFinished: true,
1791 },
1792 },
1793 shouldFail: true,
1794 expectedError: ":DIGEST_CHECK_FAILED:",
1795 },
1796 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001797 testType: serverTest,
1798 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001799 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001800 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001801 Bugs: ProtocolBugs{
1802 BadFinished: true,
1803 },
1804 },
1805 shouldFail: true,
1806 expectedError: ":DIGEST_CHECK_FAILED:",
1807 },
1808 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001809 testType: serverTest,
1810 name: "BadFinished-Server-TLS13",
1811 config: Config{
1812 MaxVersion: VersionTLS13,
1813 Bugs: ProtocolBugs{
1814 BadFinished: true,
1815 },
1816 },
1817 shouldFail: true,
1818 expectedError: ":DIGEST_CHECK_FAILED:",
1819 },
1820 {
Adam Langley7c803a62015-06-15 15:35:05 -07001821 name: "FalseStart-BadFinished",
1822 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001823 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001824 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1825 NextProtos: []string{"foo"},
1826 Bugs: ProtocolBugs{
1827 BadFinished: true,
1828 ExpectFalseStart: true,
1829 },
1830 },
1831 flags: []string{
1832 "-false-start",
1833 "-handshake-never-done",
1834 "-advertise-alpn", "\x03foo",
1835 },
1836 shimWritesFirst: true,
1837 shouldFail: true,
1838 expectedError: ":DIGEST_CHECK_FAILED:",
1839 },
1840 {
1841 name: "NoFalseStart-NoALPN",
1842 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001843 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001844 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1845 Bugs: ProtocolBugs{
1846 ExpectFalseStart: true,
1847 AlertBeforeFalseStartTest: alertAccessDenied,
1848 },
1849 },
1850 flags: []string{
1851 "-false-start",
1852 },
1853 shimWritesFirst: true,
1854 shouldFail: true,
1855 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1856 expectedLocalError: "tls: peer did not false start: EOF",
1857 },
1858 {
1859 name: "NoFalseStart-NoAEAD",
1860 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001861 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001862 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1863 NextProtos: []string{"foo"},
1864 Bugs: ProtocolBugs{
1865 ExpectFalseStart: true,
1866 AlertBeforeFalseStartTest: alertAccessDenied,
1867 },
1868 },
1869 flags: []string{
1870 "-false-start",
1871 "-advertise-alpn", "\x03foo",
1872 },
1873 shimWritesFirst: true,
1874 shouldFail: true,
1875 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1876 expectedLocalError: "tls: peer did not false start: EOF",
1877 },
1878 {
1879 name: "NoFalseStart-RSA",
1880 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001881 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001882 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1883 NextProtos: []string{"foo"},
1884 Bugs: ProtocolBugs{
1885 ExpectFalseStart: true,
1886 AlertBeforeFalseStartTest: alertAccessDenied,
1887 },
1888 },
1889 flags: []string{
1890 "-false-start",
1891 "-advertise-alpn", "\x03foo",
1892 },
1893 shimWritesFirst: true,
1894 shouldFail: true,
1895 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1896 expectedLocalError: "tls: peer did not false start: EOF",
1897 },
1898 {
1899 name: "NoFalseStart-DHE_RSA",
1900 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001901 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001902 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1903 NextProtos: []string{"foo"},
1904 Bugs: ProtocolBugs{
1905 ExpectFalseStart: true,
1906 AlertBeforeFalseStartTest: alertAccessDenied,
1907 },
1908 },
1909 flags: []string{
1910 "-false-start",
1911 "-advertise-alpn", "\x03foo",
1912 },
1913 shimWritesFirst: true,
1914 shouldFail: true,
1915 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1916 expectedLocalError: "tls: peer did not false start: EOF",
1917 },
1918 {
Adam Langley7c803a62015-06-15 15:35:05 -07001919 protocol: dtls,
1920 name: "SendSplitAlert-Sync",
1921 config: Config{
1922 Bugs: ProtocolBugs{
1923 SendSplitAlert: true,
1924 },
1925 },
1926 },
1927 {
1928 protocol: dtls,
1929 name: "SendSplitAlert-Async",
1930 config: Config{
1931 Bugs: ProtocolBugs{
1932 SendSplitAlert: true,
1933 },
1934 },
1935 flags: []string{"-async"},
1936 },
1937 {
1938 protocol: dtls,
1939 name: "PackDTLSHandshake",
1940 config: Config{
1941 Bugs: ProtocolBugs{
1942 MaxHandshakeRecordLength: 2,
1943 PackHandshakeFragments: 20,
1944 PackHandshakeRecords: 200,
1945 },
1946 },
1947 },
1948 {
Adam Langley7c803a62015-06-15 15:35:05 -07001949 name: "SendEmptyRecords-Pass",
1950 sendEmptyRecords: 32,
1951 },
1952 {
1953 name: "SendEmptyRecords",
1954 sendEmptyRecords: 33,
1955 shouldFail: true,
1956 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1957 },
1958 {
1959 name: "SendEmptyRecords-Async",
1960 sendEmptyRecords: 33,
1961 flags: []string{"-async"},
1962 shouldFail: true,
1963 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1964 },
1965 {
David Benjamine8e84b92016-08-03 15:39:47 -04001966 name: "SendWarningAlerts-Pass",
1967 config: Config{
1968 MaxVersion: VersionTLS12,
1969 },
Adam Langley7c803a62015-06-15 15:35:05 -07001970 sendWarningAlerts: 4,
1971 },
1972 {
David Benjamine8e84b92016-08-03 15:39:47 -04001973 protocol: dtls,
1974 name: "SendWarningAlerts-DTLS-Pass",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 4,
1979 },
1980 {
David Benjamine8e84b92016-08-03 15:39:47 -04001981 name: "SendWarningAlerts-TLS13",
1982 config: Config{
1983 MaxVersion: VersionTLS13,
1984 },
1985 sendWarningAlerts: 4,
1986 shouldFail: true,
1987 expectedError: ":BAD_ALERT:",
1988 expectedLocalError: "remote error: error decoding message",
1989 },
1990 {
1991 name: "SendWarningAlerts",
1992 config: Config{
1993 MaxVersion: VersionTLS12,
1994 },
Adam Langley7c803a62015-06-15 15:35:05 -07001995 sendWarningAlerts: 5,
1996 shouldFail: true,
1997 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1998 },
1999 {
David Benjamine8e84b92016-08-03 15:39:47 -04002000 name: "SendWarningAlerts-Async",
2001 config: Config{
2002 MaxVersion: VersionTLS12,
2003 },
Adam Langley7c803a62015-06-15 15:35:05 -07002004 sendWarningAlerts: 5,
2005 flags: []string{"-async"},
2006 shouldFail: true,
2007 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2008 },
David Benjaminba4594a2015-06-18 18:36:15 -04002009 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002010 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002011 config: Config{
2012 MaxVersion: VersionTLS13,
2013 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002014 sendKeyUpdates: 33,
2015 keyUpdateRequest: keyUpdateNotRequested,
2016 shouldFail: true,
2017 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002018 },
2019 {
David Benjaminba4594a2015-06-18 18:36:15 -04002020 name: "EmptySessionID",
2021 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002022 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002023 SessionTicketsDisabled: true,
2024 },
2025 noSessionCache: true,
2026 flags: []string{"-expect-no-session"},
2027 },
David Benjamin30789da2015-08-29 22:56:45 -04002028 {
2029 name: "Unclean-Shutdown",
2030 config: Config{
2031 Bugs: ProtocolBugs{
2032 NoCloseNotify: true,
2033 ExpectCloseNotify: true,
2034 },
2035 },
2036 shimShutsDown: true,
2037 flags: []string{"-check-close-notify"},
2038 shouldFail: true,
2039 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2040 },
2041 {
2042 name: "Unclean-Shutdown-Ignored",
2043 config: Config{
2044 Bugs: ProtocolBugs{
2045 NoCloseNotify: true,
2046 },
2047 },
2048 shimShutsDown: true,
2049 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002050 {
David Benjaminfa214e42016-05-10 17:03:10 -04002051 name: "Unclean-Shutdown-Alert",
2052 config: Config{
2053 Bugs: ProtocolBugs{
2054 SendAlertOnShutdown: alertDecompressionFailure,
2055 ExpectCloseNotify: true,
2056 },
2057 },
2058 shimShutsDown: true,
2059 flags: []string{"-check-close-notify"},
2060 shouldFail: true,
2061 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2062 },
2063 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002064 name: "LargePlaintext",
2065 config: Config{
2066 Bugs: ProtocolBugs{
2067 SendLargeRecords: true,
2068 },
2069 },
2070 messageLen: maxPlaintext + 1,
2071 shouldFail: true,
2072 expectedError: ":DATA_LENGTH_TOO_LONG:",
2073 },
2074 {
2075 protocol: dtls,
2076 name: "LargePlaintext-DTLS",
2077 config: Config{
2078 Bugs: ProtocolBugs{
2079 SendLargeRecords: true,
2080 },
2081 },
2082 messageLen: maxPlaintext + 1,
2083 shouldFail: true,
2084 expectedError: ":DATA_LENGTH_TOO_LONG:",
2085 },
2086 {
2087 name: "LargeCiphertext",
2088 config: Config{
2089 Bugs: ProtocolBugs{
2090 SendLargeRecords: true,
2091 },
2092 },
2093 messageLen: maxPlaintext * 2,
2094 shouldFail: true,
2095 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2096 },
2097 {
2098 protocol: dtls,
2099 name: "LargeCiphertext-DTLS",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 SendLargeRecords: true,
2103 },
2104 },
2105 messageLen: maxPlaintext * 2,
2106 // Unlike the other four cases, DTLS drops records which
2107 // are invalid before authentication, so the connection
2108 // does not fail.
2109 expectMessageDropped: true,
2110 },
David Benjamindd6fed92015-10-23 17:41:12 -04002111 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002112 name: "BadHelloRequest-1",
2113 renegotiate: 1,
2114 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002115 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002116 Bugs: ProtocolBugs{
2117 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2118 },
2119 },
2120 flags: []string{
2121 "-renegotiate-freely",
2122 "-expect-total-renegotiations", "1",
2123 },
2124 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002125 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002126 },
2127 {
2128 name: "BadHelloRequest-2",
2129 renegotiate: 1,
2130 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002131 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002132 Bugs: ProtocolBugs{
2133 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2134 },
2135 },
2136 flags: []string{
2137 "-renegotiate-freely",
2138 "-expect-total-renegotiations", "1",
2139 },
2140 shouldFail: true,
2141 expectedError: ":BAD_HELLO_REQUEST:",
2142 },
David Benjaminef1b0092015-11-21 14:05:44 -05002143 {
2144 testType: serverTest,
2145 name: "SupportTicketsWithSessionID",
2146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002147 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002148 SessionTicketsDisabled: true,
2149 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002150 resumeConfig: &Config{
2151 MaxVersion: VersionTLS12,
2152 },
David Benjaminef1b0092015-11-21 14:05:44 -05002153 resumeSession: true,
2154 },
David Benjamin02edcd02016-07-27 17:40:37 -04002155 {
2156 protocol: dtls,
2157 name: "DTLS-SendExtraFinished",
2158 config: Config{
2159 Bugs: ProtocolBugs{
2160 SendExtraFinished: true,
2161 },
2162 },
2163 shouldFail: true,
2164 expectedError: ":UNEXPECTED_RECORD:",
2165 },
2166 {
2167 protocol: dtls,
2168 name: "DTLS-SendExtraFinished-Reordered",
2169 config: Config{
2170 Bugs: ProtocolBugs{
2171 MaxHandshakeRecordLength: 2,
2172 ReorderHandshakeFragments: true,
2173 SendExtraFinished: true,
2174 },
2175 },
2176 shouldFail: true,
2177 expectedError: ":UNEXPECTED_RECORD:",
2178 },
David Benjamine97fb482016-07-29 09:23:07 -04002179 {
2180 testType: serverTest,
2181 name: "V2ClientHello-EmptyRecordPrefix",
2182 config: Config{
2183 // Choose a cipher suite that does not involve
2184 // elliptic curves, so no extensions are
2185 // involved.
2186 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002187 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002188 Bugs: ProtocolBugs{
2189 SendV2ClientHello: true,
2190 },
2191 },
2192 sendPrefix: string([]byte{
2193 byte(recordTypeHandshake),
2194 3, 1, // version
2195 0, 0, // length
2196 }),
2197 // A no-op empty record may not be sent before V2ClientHello.
2198 shouldFail: true,
2199 expectedError: ":WRONG_VERSION_NUMBER:",
2200 },
2201 {
2202 testType: serverTest,
2203 name: "V2ClientHello-WarningAlertPrefix",
2204 config: Config{
2205 // Choose a cipher suite that does not involve
2206 // elliptic curves, so no extensions are
2207 // involved.
2208 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002209 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002210 Bugs: ProtocolBugs{
2211 SendV2ClientHello: true,
2212 },
2213 },
2214 sendPrefix: string([]byte{
2215 byte(recordTypeAlert),
2216 3, 1, // version
2217 0, 2, // length
2218 alertLevelWarning, byte(alertDecompressionFailure),
2219 }),
2220 // A no-op warning alert may not be sent before V2ClientHello.
2221 shouldFail: true,
2222 expectedError: ":WRONG_VERSION_NUMBER:",
2223 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002224 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002225 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002226 config: Config{
2227 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002228 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002229 sendKeyUpdates: 1,
2230 keyUpdateRequest: keyUpdateNotRequested,
2231 },
2232 {
2233 name: "KeyUpdate-InvalidRequestMode",
2234 config: Config{
2235 MaxVersion: VersionTLS13,
2236 },
2237 sendKeyUpdates: 1,
2238 keyUpdateRequest: 42,
2239 shouldFail: true,
2240 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002241 },
David Benjaminabe94e32016-09-04 14:18:58 -04002242 {
2243 name: "SendSNIWarningAlert",
2244 config: Config{
2245 MaxVersion: VersionTLS12,
2246 Bugs: ProtocolBugs{
2247 SendSNIWarningAlert: true,
2248 },
2249 },
2250 },
David Benjaminc241d792016-09-09 10:34:20 -04002251 {
2252 testType: serverTest,
2253 name: "ExtraCompressionMethods-TLS12",
2254 config: Config{
2255 MaxVersion: VersionTLS12,
2256 Bugs: ProtocolBugs{
2257 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2258 },
2259 },
2260 },
2261 {
2262 testType: serverTest,
2263 name: "ExtraCompressionMethods-TLS13",
2264 config: Config{
2265 MaxVersion: VersionTLS13,
2266 Bugs: ProtocolBugs{
2267 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2268 },
2269 },
2270 shouldFail: true,
2271 expectedError: ":INVALID_COMPRESSION_LIST:",
2272 expectedLocalError: "remote error: illegal parameter",
2273 },
2274 {
2275 testType: serverTest,
2276 name: "NoNullCompression-TLS12",
2277 config: Config{
2278 MaxVersion: VersionTLS12,
2279 Bugs: ProtocolBugs{
2280 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2281 },
2282 },
2283 shouldFail: true,
2284 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2285 expectedLocalError: "remote error: illegal parameter",
2286 },
2287 {
2288 testType: serverTest,
2289 name: "NoNullCompression-TLS13",
2290 config: Config{
2291 MaxVersion: VersionTLS13,
2292 Bugs: ProtocolBugs{
2293 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2294 },
2295 },
2296 shouldFail: true,
2297 expectedError: ":INVALID_COMPRESSION_LIST:",
2298 expectedLocalError: "remote error: illegal parameter",
2299 },
David Benjamin65ac9972016-09-02 21:35:25 -04002300 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002301 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002302 config: Config{
2303 MaxVersion: VersionTLS12,
2304 Bugs: ProtocolBugs{
2305 ExpectGREASE: true,
2306 },
2307 },
2308 flags: []string{"-enable-grease"},
2309 },
2310 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002311 name: "GREASE-Client-TLS13",
2312 config: Config{
2313 MaxVersion: VersionTLS13,
2314 Bugs: ProtocolBugs{
2315 ExpectGREASE: true,
2316 },
2317 },
2318 flags: []string{"-enable-grease"},
2319 },
2320 {
2321 testType: serverTest,
2322 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002323 config: Config{
2324 MaxVersion: VersionTLS13,
2325 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002326 // TLS 1.3 servers are expected to
2327 // always enable GREASE. TLS 1.3 is new,
2328 // so there is no existing ecosystem to
2329 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002330 ExpectGREASE: true,
2331 },
2332 },
David Benjamin65ac9972016-09-02 21:35:25 -04002333 },
Adam Langley7c803a62015-06-15 15:35:05 -07002334 }
Adam Langley7c803a62015-06-15 15:35:05 -07002335 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002336
2337 // Test that very large messages can be received.
2338 cert := rsaCertificate
2339 for i := 0; i < 50; i++ {
2340 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2341 }
2342 testCases = append(testCases, testCase{
2343 name: "LargeMessage",
2344 config: Config{
2345 Certificates: []Certificate{cert},
2346 },
2347 })
2348 testCases = append(testCases, testCase{
2349 protocol: dtls,
2350 name: "LargeMessage-DTLS",
2351 config: Config{
2352 Certificates: []Certificate{cert},
2353 },
2354 })
2355
2356 // They are rejected if the maximum certificate chain length is capped.
2357 testCases = append(testCases, testCase{
2358 name: "LargeMessage-Reject",
2359 config: Config{
2360 Certificates: []Certificate{cert},
2361 },
2362 flags: []string{"-max-cert-list", "16384"},
2363 shouldFail: true,
2364 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2365 })
2366 testCases = append(testCases, testCase{
2367 protocol: dtls,
2368 name: "LargeMessage-Reject-DTLS",
2369 config: Config{
2370 Certificates: []Certificate{cert},
2371 },
2372 flags: []string{"-max-cert-list", "16384"},
2373 shouldFail: true,
2374 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2375 })
Adam Langley7c803a62015-06-15 15:35:05 -07002376}
2377
Adam Langley95c29f32014-06-20 12:00:00 -07002378func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002379 const bogusCipher = 0xfe00
2380
Adam Langley95c29f32014-06-20 12:00:00 -07002381 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002382 const psk = "12345"
2383 const pskIdentity = "luggage combo"
2384
Adam Langley95c29f32014-06-20 12:00:00 -07002385 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002386 var certFile string
2387 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002388 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002389 cert = ecdsaP256Certificate
2390 certFile = ecdsaP256CertificateFile
2391 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002392 } else {
David Benjamin33863262016-07-08 17:20:12 -07002393 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002394 certFile = rsaCertificateFile
2395 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002396 }
2397
David Benjamin48cae082014-10-27 01:06:24 -04002398 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002399 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002400 flags = append(flags,
2401 "-psk", psk,
2402 "-psk-identity", pskIdentity)
2403 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002404 if hasComponent(suite.name, "NULL") {
2405 // NULL ciphers must be explicitly enabled.
2406 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2407 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002408 if hasComponent(suite.name, "CECPQ1") {
2409 // CECPQ1 ciphers must be explicitly enabled.
2410 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2411 }
David Benjamin881f1962016-08-10 18:29:12 -04002412 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2413 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2414 // for now.
2415 flags = append(flags, "-cipher", suite.name)
2416 }
David Benjamin48cae082014-10-27 01:06:24 -04002417
Adam Langley95c29f32014-06-20 12:00:00 -07002418 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002419 for _, protocol := range []protocol{tls, dtls} {
2420 var prefix string
2421 if protocol == dtls {
2422 if !ver.hasDTLS {
2423 continue
2424 }
2425 prefix = "D"
2426 }
Adam Langley95c29f32014-06-20 12:00:00 -07002427
David Benjamin0407e762016-06-17 16:41:18 -04002428 var shouldServerFail, shouldClientFail bool
2429 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2430 // BoringSSL clients accept ECDHE on SSLv3, but
2431 // a BoringSSL server will never select it
2432 // because the extension is missing.
2433 shouldServerFail = true
2434 }
2435 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2436 shouldClientFail = true
2437 shouldServerFail = true
2438 }
David Benjamin54c217c2016-07-13 12:35:25 -04002439 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002440 shouldClientFail = true
2441 shouldServerFail = true
2442 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002443 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2444 shouldClientFail = true
2445 shouldServerFail = true
2446 }
David Benjamin0407e762016-06-17 16:41:18 -04002447 if !isDTLSCipher(suite.name) && protocol == dtls {
2448 shouldClientFail = true
2449 shouldServerFail = true
2450 }
David Benjamin4298d772015-12-19 00:18:25 -05002451
David Benjamin5ecb88b2016-10-04 17:51:35 -04002452 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002453 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002454 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002455 if shouldServerFail {
2456 expectedServerError = ":NO_SHARED_CIPHER:"
2457 }
2458 if shouldClientFail {
2459 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002460 // Configure the server to select ciphers as normal but
2461 // select an incompatible cipher in ServerHello.
2462 serverCipherSuites = nil
2463 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002464 }
David Benjamin025b3d32014-07-01 19:53:04 -04002465
David Benjamin6fd297b2014-08-11 18:43:38 -04002466 testCases = append(testCases, testCase{
2467 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002468 protocol: protocol,
2469
2470 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002471 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002472 MinVersion: ver.version,
2473 MaxVersion: ver.version,
2474 CipherSuites: []uint16{suite.id},
2475 Certificates: []Certificate{cert},
2476 PreSharedKey: []byte(psk),
2477 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002478 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002479 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002480 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002481 },
2482 certFile: certFile,
2483 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002484 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002485 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002486 shouldFail: shouldServerFail,
2487 expectedError: expectedServerError,
2488 })
2489
2490 testCases = append(testCases, testCase{
2491 testType: clientTest,
2492 protocol: protocol,
2493 name: prefix + ver.name + "-" + suite.name + "-client",
2494 config: Config{
2495 MinVersion: ver.version,
2496 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002497 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002498 Certificates: []Certificate{cert},
2499 PreSharedKey: []byte(psk),
2500 PreSharedKeyIdentity: pskIdentity,
2501 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002502 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002503 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002504 },
2505 },
2506 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002507 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002508 shouldFail: shouldClientFail,
2509 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002510 })
David Benjamin2c99d282015-09-01 10:23:00 -04002511
Nick Harper1fd39d82016-06-14 18:14:35 -07002512 if !shouldClientFail {
2513 // Ensure the maximum record size is accepted.
2514 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002515 protocol: protocol,
2516 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002517 config: Config{
2518 MinVersion: ver.version,
2519 MaxVersion: ver.version,
2520 CipherSuites: []uint16{suite.id},
2521 Certificates: []Certificate{cert},
2522 PreSharedKey: []byte(psk),
2523 PreSharedKeyIdentity: pskIdentity,
2524 },
2525 flags: flags,
2526 messageLen: maxPlaintext,
2527 })
David Benjamin231a4752016-11-10 10:46:00 -05002528
2529 // Test bad records for all ciphers. Bad records are fatal in TLS
2530 // and ignored in DTLS.
2531 var shouldFail bool
2532 var expectedError string
2533 if protocol == tls {
2534 shouldFail = true
2535 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2536 }
2537
2538 testCases = append(testCases, testCase{
2539 protocol: protocol,
2540 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2541 config: Config{
2542 MinVersion: ver.version,
2543 MaxVersion: ver.version,
2544 CipherSuites: []uint16{suite.id},
2545 Certificates: []Certificate{cert},
2546 PreSharedKey: []byte(psk),
2547 PreSharedKeyIdentity: pskIdentity,
2548 },
2549 flags: flags,
2550 damageFirstWrite: true,
2551 messageLen: maxPlaintext,
2552 shouldFail: shouldFail,
2553 expectedError: expectedError,
2554 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002555 }
2556 }
David Benjamin2c99d282015-09-01 10:23:00 -04002557 }
Adam Langley95c29f32014-06-20 12:00:00 -07002558 }
Adam Langleya7997f12015-05-14 17:38:50 -07002559
2560 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002561 name: "NoSharedCipher",
2562 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002563 MaxVersion: VersionTLS12,
2564 CipherSuites: []uint16{},
2565 },
2566 shouldFail: true,
2567 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2568 })
2569
2570 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002571 name: "NoSharedCipher-TLS13",
2572 config: Config{
2573 MaxVersion: VersionTLS13,
2574 CipherSuites: []uint16{},
2575 },
2576 shouldFail: true,
2577 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2578 })
2579
2580 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002581 name: "UnsupportedCipherSuite",
2582 config: Config{
2583 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002584 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002585 Bugs: ProtocolBugs{
2586 IgnorePeerCipherPreferences: true,
2587 },
2588 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002589 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002590 shouldFail: true,
2591 expectedError: ":WRONG_CIPHER_RETURNED:",
2592 })
2593
2594 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002595 name: "ServerHelloBogusCipher",
2596 config: Config{
2597 MaxVersion: VersionTLS12,
2598 Bugs: ProtocolBugs{
2599 SendCipherSuite: bogusCipher,
2600 },
2601 },
2602 shouldFail: true,
2603 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2604 })
2605 testCases = append(testCases, testCase{
2606 name: "ServerHelloBogusCipher-TLS13",
2607 config: Config{
2608 MaxVersion: VersionTLS13,
2609 Bugs: ProtocolBugs{
2610 SendCipherSuite: bogusCipher,
2611 },
2612 },
2613 shouldFail: true,
2614 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2615 })
2616
2617 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002618 name: "WeakDH",
2619 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002620 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002621 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2622 Bugs: ProtocolBugs{
2623 // This is a 1023-bit prime number, generated
2624 // with:
2625 // openssl gendh 1023 | openssl asn1parse -i
2626 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2627 },
2628 },
2629 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002630 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002631 })
Adam Langleycef75832015-09-03 14:51:12 -07002632
David Benjamincd24a392015-11-11 13:23:05 -08002633 testCases = append(testCases, testCase{
2634 name: "SillyDH",
2635 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002636 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002637 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2638 Bugs: ProtocolBugs{
2639 // This is a 4097-bit prime number, generated
2640 // with:
2641 // openssl gendh 4097 | openssl asn1parse -i
2642 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2643 },
2644 },
2645 shouldFail: true,
2646 expectedError: ":DH_P_TOO_LONG:",
2647 })
2648
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002649 // This test ensures that Diffie-Hellman public values are padded with
2650 // zeros so that they're the same length as the prime. This is to avoid
2651 // hitting a bug in yaSSL.
2652 testCases = append(testCases, testCase{
2653 testType: serverTest,
2654 name: "DHPublicValuePadded",
2655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002656 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002657 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2658 Bugs: ProtocolBugs{
2659 RequireDHPublicValueLen: (1025 + 7) / 8,
2660 },
2661 },
2662 flags: []string{"-use-sparse-dh-prime"},
2663 })
David Benjamincd24a392015-11-11 13:23:05 -08002664
David Benjamin241ae832016-01-15 03:04:54 -05002665 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002666 testCases = append(testCases, testCase{
2667 testType: serverTest,
2668 name: "UnknownCipher",
2669 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002670 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002671 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002672 Bugs: ProtocolBugs{
2673 AdvertiseAllConfiguredCiphers: true,
2674 },
2675 },
2676 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002677
2678 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002679 testCases = append(testCases, testCase{
2680 testType: serverTest,
2681 name: "UnknownCipher-TLS13",
2682 config: Config{
2683 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002684 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002685 Bugs: ProtocolBugs{
2686 AdvertiseAllConfiguredCiphers: true,
2687 },
David Benjamin241ae832016-01-15 03:04:54 -05002688 },
2689 })
2690
David Benjamin78679342016-09-16 19:42:05 -04002691 // Test empty ECDHE_PSK identity hints work as expected.
2692 testCases = append(testCases, testCase{
2693 name: "EmptyECDHEPSKHint",
2694 config: Config{
2695 MaxVersion: VersionTLS12,
2696 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2697 PreSharedKey: []byte("secret"),
2698 },
2699 flags: []string{"-psk", "secret"},
2700 })
2701
2702 // Test empty PSK identity hints work as expected, even if an explicit
2703 // ServerKeyExchange is sent.
2704 testCases = append(testCases, testCase{
2705 name: "ExplicitEmptyPSKHint",
2706 config: Config{
2707 MaxVersion: VersionTLS12,
2708 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2709 PreSharedKey: []byte("secret"),
2710 Bugs: ProtocolBugs{
2711 AlwaysSendPreSharedKeyIdentityHint: true,
2712 },
2713 },
2714 flags: []string{"-psk", "secret"},
2715 })
2716
Adam Langleycef75832015-09-03 14:51:12 -07002717 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2718 // 1.1 specific cipher suite settings. A server is setup with the given
2719 // cipher lists and then a connection is made for each member of
2720 // expectations. The cipher suite that the server selects must match
2721 // the specified one.
2722 var versionSpecificCiphersTest = []struct {
2723 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2724 // expectations is a map from TLS version to cipher suite id.
2725 expectations map[uint16]uint16
2726 }{
2727 {
2728 // Test that the null case (where no version-specific ciphers are set)
2729 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002730 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2731 "", // no ciphers specifically for TLS ≥ 1.0
2732 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002733 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002734 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2735 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2736 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2737 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002738 },
2739 },
2740 {
2741 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2742 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002743 "DES-CBC3-SHA:AES128-SHA", // default
2744 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2745 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002746 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002747 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002748 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2749 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2750 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2751 },
2752 },
2753 {
2754 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2755 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002756 "DES-CBC3-SHA:AES128-SHA", // default
2757 "", // no ciphers specifically for TLS ≥ 1.0
2758 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002759 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002760 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2761 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002762 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2763 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2764 },
2765 },
2766 {
2767 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2768 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002769 "DES-CBC3-SHA:AES128-SHA", // default
2770 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2771 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002772 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002773 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002774 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2775 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2776 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2777 },
2778 },
2779 }
2780
2781 for i, test := range versionSpecificCiphersTest {
2782 for version, expectedCipherSuite := range test.expectations {
2783 flags := []string{"-cipher", test.ciphersDefault}
2784 if len(test.ciphersTLS10) > 0 {
2785 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2786 }
2787 if len(test.ciphersTLS11) > 0 {
2788 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2789 }
2790
2791 testCases = append(testCases, testCase{
2792 testType: serverTest,
2793 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2794 config: Config{
2795 MaxVersion: version,
2796 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002797 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 -07002798 },
2799 flags: flags,
2800 expectedCipher: expectedCipherSuite,
2801 })
2802 }
2803 }
Adam Langley95c29f32014-06-20 12:00:00 -07002804}
2805
2806func addBadECDSASignatureTests() {
2807 for badR := BadValue(1); badR < NumBadValues; badR++ {
2808 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002809 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002810 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2811 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002812 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002813 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002814 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002815 Bugs: ProtocolBugs{
2816 BadECDSAR: badR,
2817 BadECDSAS: badS,
2818 },
2819 },
2820 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002821 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002822 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002823 testCases = append(testCases, testCase{
2824 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2825 config: Config{
2826 MaxVersion: VersionTLS13,
2827 Certificates: []Certificate{ecdsaP256Certificate},
2828 Bugs: ProtocolBugs{
2829 BadECDSAR: badR,
2830 BadECDSAS: badS,
2831 },
2832 },
2833 shouldFail: true,
2834 expectedError: ":BAD_SIGNATURE:",
2835 })
Adam Langley95c29f32014-06-20 12:00:00 -07002836 }
2837 }
2838}
2839
Adam Langley80842bd2014-06-20 12:00:00 -07002840func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002841 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002842 name: "MaxCBCPadding",
2843 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002844 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002845 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2846 Bugs: ProtocolBugs{
2847 MaxPadding: true,
2848 },
2849 },
2850 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2851 })
David Benjamin025b3d32014-07-01 19:53:04 -04002852 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002853 name: "BadCBCPadding",
2854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002855 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2857 Bugs: ProtocolBugs{
2858 PaddingFirstByteBad: true,
2859 },
2860 },
2861 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002862 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002863 })
2864 // OpenSSL previously had an issue where the first byte of padding in
2865 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002866 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002867 name: "BadCBCPadding255",
2868 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002869 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2871 Bugs: ProtocolBugs{
2872 MaxPadding: true,
2873 PaddingFirstByteBadIf255: true,
2874 },
2875 },
2876 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2877 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002878 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002879 })
2880}
2881
Kenny Root7fdeaf12014-08-05 15:23:37 -07002882func addCBCSplittingTests() {
2883 testCases = append(testCases, testCase{
2884 name: "CBCRecordSplitting",
2885 config: Config{
2886 MaxVersion: VersionTLS10,
2887 MinVersion: VersionTLS10,
2888 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2889 },
David Benjaminac8302a2015-09-01 17:18:15 -04002890 messageLen: -1, // read until EOF
2891 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002892 flags: []string{
2893 "-async",
2894 "-write-different-record-sizes",
2895 "-cbc-record-splitting",
2896 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002897 })
2898 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002899 name: "CBCRecordSplittingPartialWrite",
2900 config: Config{
2901 MaxVersion: VersionTLS10,
2902 MinVersion: VersionTLS10,
2903 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2904 },
2905 messageLen: -1, // read until EOF
2906 flags: []string{
2907 "-async",
2908 "-write-different-record-sizes",
2909 "-cbc-record-splitting",
2910 "-partial-write",
2911 },
2912 })
2913}
2914
David Benjamin636293b2014-07-08 17:59:18 -04002915func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002916 // Add a dummy cert pool to stress certificate authority parsing.
2917 // TODO(davidben): Add tests that those values parse out correctly.
2918 certPool := x509.NewCertPool()
2919 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2920 if err != nil {
2921 panic(err)
2922 }
2923 certPool.AddCert(cert)
2924
David Benjamin636293b2014-07-08 17:59:18 -04002925 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002926 testCases = append(testCases, testCase{
2927 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002928 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002929 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002930 MinVersion: ver.version,
2931 MaxVersion: ver.version,
2932 ClientAuth: RequireAnyClientCert,
2933 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002934 },
2935 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002936 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2937 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002938 },
2939 })
2940 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002941 testType: serverTest,
2942 name: ver.name + "-Server-ClientAuth-RSA",
2943 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002944 MinVersion: ver.version,
2945 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002946 Certificates: []Certificate{rsaCertificate},
2947 },
2948 flags: []string{"-require-any-client-certificate"},
2949 })
David Benjamine098ec22014-08-27 23:13:20 -04002950 if ver.version != VersionSSL30 {
2951 testCases = append(testCases, testCase{
2952 testType: serverTest,
2953 name: ver.name + "-Server-ClientAuth-ECDSA",
2954 config: Config{
2955 MinVersion: ver.version,
2956 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002957 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002958 },
2959 flags: []string{"-require-any-client-certificate"},
2960 })
2961 testCases = append(testCases, testCase{
2962 testType: clientTest,
2963 name: ver.name + "-Client-ClientAuth-ECDSA",
2964 config: Config{
2965 MinVersion: ver.version,
2966 MaxVersion: ver.version,
2967 ClientAuth: RequireAnyClientCert,
2968 ClientCAs: certPool,
2969 },
2970 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002971 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2972 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002973 },
2974 })
2975 }
Adam Langley37646832016-08-01 16:16:46 -07002976
2977 testCases = append(testCases, testCase{
2978 name: "NoClientCertificate-" + ver.name,
2979 config: Config{
2980 MinVersion: ver.version,
2981 MaxVersion: ver.version,
2982 ClientAuth: RequireAnyClientCert,
2983 },
2984 shouldFail: true,
2985 expectedLocalError: "client didn't provide a certificate",
2986 })
2987
2988 testCases = append(testCases, testCase{
2989 // Even if not configured to expect a certificate, OpenSSL will
2990 // return X509_V_OK as the verify_result.
2991 testType: serverTest,
2992 name: "NoClientCertificateRequested-Server-" + ver.name,
2993 config: Config{
2994 MinVersion: ver.version,
2995 MaxVersion: ver.version,
2996 },
2997 flags: []string{
2998 "-expect-verify-result",
2999 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003000 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003001 })
3002
3003 testCases = append(testCases, testCase{
3004 // If a client certificate is not provided, OpenSSL will still
3005 // return X509_V_OK as the verify_result.
3006 testType: serverTest,
3007 name: "NoClientCertificate-Server-" + ver.name,
3008 config: Config{
3009 MinVersion: ver.version,
3010 MaxVersion: ver.version,
3011 },
3012 flags: []string{
3013 "-expect-verify-result",
3014 "-verify-peer",
3015 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003016 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003017 })
3018
David Benjamin1db9e1b2016-10-07 20:51:43 -04003019 certificateRequired := "remote error: certificate required"
3020 if ver.version < VersionTLS13 {
3021 // Prior to TLS 1.3, the generic handshake_failure alert
3022 // was used.
3023 certificateRequired = "remote error: handshake failure"
3024 }
Adam Langley37646832016-08-01 16:16:46 -07003025 testCases = append(testCases, testCase{
3026 testType: serverTest,
3027 name: "RequireAnyClientCertificate-" + ver.name,
3028 config: Config{
3029 MinVersion: ver.version,
3030 MaxVersion: ver.version,
3031 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003032 flags: []string{"-require-any-client-certificate"},
3033 shouldFail: true,
3034 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3035 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003036 })
3037
3038 if ver.version != VersionSSL30 {
3039 testCases = append(testCases, testCase{
3040 testType: serverTest,
3041 name: "SkipClientCertificate-" + ver.name,
3042 config: Config{
3043 MinVersion: ver.version,
3044 MaxVersion: ver.version,
3045 Bugs: ProtocolBugs{
3046 SkipClientCertificate: true,
3047 },
3048 },
3049 // Setting SSL_VERIFY_PEER allows anonymous clients.
3050 flags: []string{"-verify-peer"},
3051 shouldFail: true,
3052 expectedError: ":UNEXPECTED_MESSAGE:",
3053 })
3054 }
David Benjamin636293b2014-07-08 17:59:18 -04003055 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003056
David Benjaminc032dfa2016-05-12 14:54:57 -04003057 // Client auth is only legal in certificate-based ciphers.
3058 testCases = append(testCases, testCase{
3059 testType: clientTest,
3060 name: "ClientAuth-PSK",
3061 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003062 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003063 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3064 PreSharedKey: []byte("secret"),
3065 ClientAuth: RequireAnyClientCert,
3066 },
3067 flags: []string{
3068 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3069 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3070 "-psk", "secret",
3071 },
3072 shouldFail: true,
3073 expectedError: ":UNEXPECTED_MESSAGE:",
3074 })
3075 testCases = append(testCases, testCase{
3076 testType: clientTest,
3077 name: "ClientAuth-ECDHE_PSK",
3078 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003079 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003080 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3081 PreSharedKey: []byte("secret"),
3082 ClientAuth: RequireAnyClientCert,
3083 },
3084 flags: []string{
3085 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3086 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3087 "-psk", "secret",
3088 },
3089 shouldFail: true,
3090 expectedError: ":UNEXPECTED_MESSAGE:",
3091 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003092
3093 // Regression test for a bug where the client CA list, if explicitly
3094 // set to NULL, was mis-encoded.
3095 testCases = append(testCases, testCase{
3096 testType: serverTest,
3097 name: "Null-Client-CA-List",
3098 config: Config{
3099 MaxVersion: VersionTLS12,
3100 Certificates: []Certificate{rsaCertificate},
3101 },
3102 flags: []string{
3103 "-require-any-client-certificate",
3104 "-use-null-client-ca-list",
3105 },
3106 })
David Benjamin636293b2014-07-08 17:59:18 -04003107}
3108
Adam Langley75712922014-10-10 16:23:43 -07003109func addExtendedMasterSecretTests() {
3110 const expectEMSFlag = "-expect-extended-master-secret"
3111
3112 for _, with := range []bool{false, true} {
3113 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003114 if with {
3115 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003116 }
3117
3118 for _, isClient := range []bool{false, true} {
3119 suffix := "-Server"
3120 testType := serverTest
3121 if isClient {
3122 suffix = "-Client"
3123 testType = clientTest
3124 }
3125
3126 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003127 // In TLS 1.3, the extension is irrelevant and
3128 // always reports as enabled.
3129 var flags []string
3130 if with || ver.version >= VersionTLS13 {
3131 flags = []string{expectEMSFlag}
3132 }
3133
Adam Langley75712922014-10-10 16:23:43 -07003134 test := testCase{
3135 testType: testType,
3136 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3137 config: Config{
3138 MinVersion: ver.version,
3139 MaxVersion: ver.version,
3140 Bugs: ProtocolBugs{
3141 NoExtendedMasterSecret: !with,
3142 RequireExtendedMasterSecret: with,
3143 },
3144 },
David Benjamin48cae082014-10-27 01:06:24 -04003145 flags: flags,
3146 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003147 }
3148 if test.shouldFail {
3149 test.expectedLocalError = "extended master secret required but not supported by peer"
3150 }
3151 testCases = append(testCases, test)
3152 }
3153 }
3154 }
3155
Adam Langleyba5934b2015-06-02 10:50:35 -07003156 for _, isClient := range []bool{false, true} {
3157 for _, supportedInFirstConnection := range []bool{false, true} {
3158 for _, supportedInResumeConnection := range []bool{false, true} {
3159 boolToWord := func(b bool) string {
3160 if b {
3161 return "Yes"
3162 }
3163 return "No"
3164 }
3165 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3166 if isClient {
3167 suffix += "Client"
3168 } else {
3169 suffix += "Server"
3170 }
3171
3172 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003173 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003174 Bugs: ProtocolBugs{
3175 RequireExtendedMasterSecret: true,
3176 },
3177 }
3178
3179 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003180 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003181 Bugs: ProtocolBugs{
3182 NoExtendedMasterSecret: true,
3183 },
3184 }
3185
3186 test := testCase{
3187 name: "ExtendedMasterSecret-" + suffix,
3188 resumeSession: true,
3189 }
3190
3191 if !isClient {
3192 test.testType = serverTest
3193 }
3194
3195 if supportedInFirstConnection {
3196 test.config = supportedConfig
3197 } else {
3198 test.config = noSupportConfig
3199 }
3200
3201 if supportedInResumeConnection {
3202 test.resumeConfig = &supportedConfig
3203 } else {
3204 test.resumeConfig = &noSupportConfig
3205 }
3206
3207 switch suffix {
3208 case "YesToYes-Client", "YesToYes-Server":
3209 // When a session is resumed, it should
3210 // still be aware that its master
3211 // secret was generated via EMS and
3212 // thus it's safe to use tls-unique.
3213 test.flags = []string{expectEMSFlag}
3214 case "NoToYes-Server":
3215 // If an original connection did not
3216 // contain EMS, but a resumption
3217 // handshake does, then a server should
3218 // not resume the session.
3219 test.expectResumeRejected = true
3220 case "YesToNo-Server":
3221 // Resuming an EMS session without the
3222 // EMS extension should cause the
3223 // server to abort the connection.
3224 test.shouldFail = true
3225 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3226 case "NoToYes-Client":
3227 // A client should abort a connection
3228 // where the server resumed a non-EMS
3229 // session but echoed the EMS
3230 // extension.
3231 test.shouldFail = true
3232 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3233 case "YesToNo-Client":
3234 // A client should abort a connection
3235 // where the server didn't echo EMS
3236 // when the session used it.
3237 test.shouldFail = true
3238 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3239 }
3240
3241 testCases = append(testCases, test)
3242 }
3243 }
3244 }
David Benjamin163c9562016-08-29 23:14:17 -04003245
3246 // Switching EMS on renegotiation is forbidden.
3247 testCases = append(testCases, testCase{
3248 name: "ExtendedMasterSecret-Renego-NoEMS",
3249 config: Config{
3250 MaxVersion: VersionTLS12,
3251 Bugs: ProtocolBugs{
3252 NoExtendedMasterSecret: true,
3253 NoExtendedMasterSecretOnRenegotiation: true,
3254 },
3255 },
3256 renegotiate: 1,
3257 flags: []string{
3258 "-renegotiate-freely",
3259 "-expect-total-renegotiations", "1",
3260 },
3261 })
3262
3263 testCases = append(testCases, testCase{
3264 name: "ExtendedMasterSecret-Renego-Upgrade",
3265 config: Config{
3266 MaxVersion: VersionTLS12,
3267 Bugs: ProtocolBugs{
3268 NoExtendedMasterSecret: true,
3269 },
3270 },
3271 renegotiate: 1,
3272 flags: []string{
3273 "-renegotiate-freely",
3274 "-expect-total-renegotiations", "1",
3275 },
3276 shouldFail: true,
3277 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3278 })
3279
3280 testCases = append(testCases, testCase{
3281 name: "ExtendedMasterSecret-Renego-Downgrade",
3282 config: Config{
3283 MaxVersion: VersionTLS12,
3284 Bugs: ProtocolBugs{
3285 NoExtendedMasterSecretOnRenegotiation: true,
3286 },
3287 },
3288 renegotiate: 1,
3289 flags: []string{
3290 "-renegotiate-freely",
3291 "-expect-total-renegotiations", "1",
3292 },
3293 shouldFail: true,
3294 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3295 })
Adam Langley75712922014-10-10 16:23:43 -07003296}
3297
David Benjamin582ba042016-07-07 12:33:25 -07003298type stateMachineTestConfig struct {
3299 protocol protocol
3300 async bool
3301 splitHandshake, packHandshakeFlight bool
3302}
3303
David Benjamin43ec06f2014-08-05 02:28:57 -04003304// Adds tests that try to cover the range of the handshake state machine, under
3305// various conditions. Some of these are redundant with other tests, but they
3306// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003307func addAllStateMachineCoverageTests() {
3308 for _, async := range []bool{false, true} {
3309 for _, protocol := range []protocol{tls, dtls} {
3310 addStateMachineCoverageTests(stateMachineTestConfig{
3311 protocol: protocol,
3312 async: async,
3313 })
3314 addStateMachineCoverageTests(stateMachineTestConfig{
3315 protocol: protocol,
3316 async: async,
3317 splitHandshake: true,
3318 })
3319 if protocol == tls {
3320 addStateMachineCoverageTests(stateMachineTestConfig{
3321 protocol: protocol,
3322 async: async,
3323 packHandshakeFlight: true,
3324 })
3325 }
3326 }
3327 }
3328}
3329
3330func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003331 var tests []testCase
3332
3333 // Basic handshake, with resumption. Client and server,
3334 // session ID and session ticket.
3335 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003336 name: "Basic-Client",
3337 config: Config{
3338 MaxVersion: VersionTLS12,
3339 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003340 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003341 // Ensure session tickets are used, not session IDs.
3342 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003343 })
3344 tests = append(tests, testCase{
3345 name: "Basic-Client-RenewTicket",
3346 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003347 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003348 Bugs: ProtocolBugs{
3349 RenewTicketOnResume: true,
3350 },
3351 },
David Benjamin46662482016-08-17 00:51:00 -04003352 flags: []string{"-expect-ticket-renewal"},
3353 resumeSession: true,
3354 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003355 })
3356 tests = append(tests, testCase{
3357 name: "Basic-Client-NoTicket",
3358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003359 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003360 SessionTicketsDisabled: true,
3361 },
3362 resumeSession: true,
3363 })
3364 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003365 name: "Basic-Client-Implicit",
3366 config: Config{
3367 MaxVersion: VersionTLS12,
3368 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003369 flags: []string{"-implicit-handshake"},
3370 resumeSession: true,
3371 })
3372 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003373 testType: serverTest,
3374 name: "Basic-Server",
3375 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003376 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003377 Bugs: ProtocolBugs{
3378 RequireSessionTickets: true,
3379 },
3380 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 resumeSession: true,
3382 })
3383 tests = append(tests, testCase{
3384 testType: serverTest,
3385 name: "Basic-Server-NoTickets",
3386 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003387 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003388 SessionTicketsDisabled: true,
3389 },
3390 resumeSession: true,
3391 })
3392 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003393 testType: serverTest,
3394 name: "Basic-Server-Implicit",
3395 config: Config{
3396 MaxVersion: VersionTLS12,
3397 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003398 flags: []string{"-implicit-handshake"},
3399 resumeSession: true,
3400 })
3401 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003402 testType: serverTest,
3403 name: "Basic-Server-EarlyCallback",
3404 config: Config{
3405 MaxVersion: VersionTLS12,
3406 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003407 flags: []string{"-use-early-callback"},
3408 resumeSession: true,
3409 })
3410
Steven Valdez143e8b32016-07-11 13:19:03 -04003411 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003412 if config.protocol == tls {
3413 tests = append(tests, testCase{
3414 name: "TLS13-1RTT-Client",
3415 config: Config{
3416 MaxVersion: VersionTLS13,
3417 MinVersion: VersionTLS13,
3418 },
David Benjamin46662482016-08-17 00:51:00 -04003419 resumeSession: true,
3420 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003421 })
3422
3423 tests = append(tests, testCase{
3424 testType: serverTest,
3425 name: "TLS13-1RTT-Server",
3426 config: Config{
3427 MaxVersion: VersionTLS13,
3428 MinVersion: VersionTLS13,
3429 },
David Benjamin46662482016-08-17 00:51:00 -04003430 resumeSession: true,
3431 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003432 })
3433
3434 tests = append(tests, testCase{
3435 name: "TLS13-HelloRetryRequest-Client",
3436 config: Config{
3437 MaxVersion: VersionTLS13,
3438 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003439 // P-384 requires a HelloRetryRequest against BoringSSL's default
3440 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003441 CurvePreferences: []CurveID{CurveP384},
3442 Bugs: ProtocolBugs{
3443 ExpectMissingKeyShare: true,
3444 },
3445 },
3446 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3447 resumeSession: true,
3448 })
3449
3450 tests = append(tests, testCase{
3451 testType: serverTest,
3452 name: "TLS13-HelloRetryRequest-Server",
3453 config: Config{
3454 MaxVersion: VersionTLS13,
3455 MinVersion: VersionTLS13,
3456 // Require a HelloRetryRequest for every curve.
3457 DefaultCurves: []CurveID{},
3458 },
3459 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3460 resumeSession: true,
3461 })
3462 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003463
David Benjamin760b1dd2015-05-15 23:33:48 -04003464 // TLS client auth.
3465 tests = append(tests, testCase{
3466 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003467 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003468 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003469 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003470 ClientAuth: RequestClientCert,
3471 },
3472 })
3473 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003474 testType: serverTest,
3475 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003476 config: Config{
3477 MaxVersion: VersionTLS12,
3478 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003479 // Setting SSL_VERIFY_PEER allows anonymous clients.
3480 flags: []string{"-verify-peer"},
3481 })
David Benjamin582ba042016-07-07 12:33:25 -07003482 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003483 tests = append(tests, testCase{
3484 testType: clientTest,
3485 name: "ClientAuth-NoCertificate-Client-SSL3",
3486 config: Config{
3487 MaxVersion: VersionSSL30,
3488 ClientAuth: RequestClientCert,
3489 },
3490 })
3491 tests = append(tests, testCase{
3492 testType: serverTest,
3493 name: "ClientAuth-NoCertificate-Server-SSL3",
3494 config: Config{
3495 MaxVersion: VersionSSL30,
3496 },
3497 // Setting SSL_VERIFY_PEER allows anonymous clients.
3498 flags: []string{"-verify-peer"},
3499 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003500 tests = append(tests, testCase{
3501 testType: clientTest,
3502 name: "ClientAuth-NoCertificate-Client-TLS13",
3503 config: Config{
3504 MaxVersion: VersionTLS13,
3505 ClientAuth: RequestClientCert,
3506 },
3507 })
3508 tests = append(tests, testCase{
3509 testType: serverTest,
3510 name: "ClientAuth-NoCertificate-Server-TLS13",
3511 config: Config{
3512 MaxVersion: VersionTLS13,
3513 },
3514 // Setting SSL_VERIFY_PEER allows anonymous clients.
3515 flags: []string{"-verify-peer"},
3516 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003517 }
3518 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003519 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003520 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003521 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003522 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003523 ClientAuth: RequireAnyClientCert,
3524 },
3525 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003526 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3527 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003528 },
3529 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003530 tests = append(tests, testCase{
3531 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003532 name: "ClientAuth-RSA-Client-TLS13",
3533 config: Config{
3534 MaxVersion: VersionTLS13,
3535 ClientAuth: RequireAnyClientCert,
3536 },
3537 flags: []string{
3538 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3539 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3540 },
3541 })
3542 tests = append(tests, testCase{
3543 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003544 name: "ClientAuth-ECDSA-Client",
3545 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003546 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003547 ClientAuth: RequireAnyClientCert,
3548 },
3549 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003550 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3551 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003552 },
3553 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003554 tests = append(tests, testCase{
3555 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003556 name: "ClientAuth-ECDSA-Client-TLS13",
3557 config: Config{
3558 MaxVersion: VersionTLS13,
3559 ClientAuth: RequireAnyClientCert,
3560 },
3561 flags: []string{
3562 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3563 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3564 },
3565 })
3566 tests = append(tests, testCase{
3567 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003568 name: "ClientAuth-NoCertificate-OldCallback",
3569 config: Config{
3570 MaxVersion: VersionTLS12,
3571 ClientAuth: RequestClientCert,
3572 },
3573 flags: []string{"-use-old-client-cert-callback"},
3574 })
3575 tests = append(tests, testCase{
3576 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003577 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3578 config: Config{
3579 MaxVersion: VersionTLS13,
3580 ClientAuth: RequestClientCert,
3581 },
3582 flags: []string{"-use-old-client-cert-callback"},
3583 })
3584 tests = append(tests, testCase{
3585 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003586 name: "ClientAuth-OldCallback",
3587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003588 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003589 ClientAuth: RequireAnyClientCert,
3590 },
3591 flags: []string{
3592 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3593 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3594 "-use-old-client-cert-callback",
3595 },
3596 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003597 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003598 testType: clientTest,
3599 name: "ClientAuth-OldCallback-TLS13",
3600 config: Config{
3601 MaxVersion: VersionTLS13,
3602 ClientAuth: RequireAnyClientCert,
3603 },
3604 flags: []string{
3605 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3606 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3607 "-use-old-client-cert-callback",
3608 },
3609 })
3610 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003611 testType: serverTest,
3612 name: "ClientAuth-Server",
3613 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003614 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003615 Certificates: []Certificate{rsaCertificate},
3616 },
3617 flags: []string{"-require-any-client-certificate"},
3618 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003619 tests = append(tests, testCase{
3620 testType: serverTest,
3621 name: "ClientAuth-Server-TLS13",
3622 config: Config{
3623 MaxVersion: VersionTLS13,
3624 Certificates: []Certificate{rsaCertificate},
3625 },
3626 flags: []string{"-require-any-client-certificate"},
3627 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003628
David Benjamin4c3ddf72016-06-29 18:13:53 -04003629 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003630 tests = append(tests, testCase{
3631 testType: serverTest,
3632 name: "Basic-Server-RSA",
3633 config: Config{
3634 MaxVersion: VersionTLS12,
3635 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3636 },
3637 flags: []string{
3638 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3639 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3640 },
3641 })
3642 tests = append(tests, testCase{
3643 testType: serverTest,
3644 name: "Basic-Server-ECDHE-RSA",
3645 config: Config{
3646 MaxVersion: VersionTLS12,
3647 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3648 },
3649 flags: []string{
3650 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3651 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3652 },
3653 })
3654 tests = append(tests, testCase{
3655 testType: serverTest,
3656 name: "Basic-Server-ECDHE-ECDSA",
3657 config: Config{
3658 MaxVersion: VersionTLS12,
3659 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3660 },
3661 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003662 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3663 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003664 },
3665 })
3666
David Benjamin760b1dd2015-05-15 23:33:48 -04003667 // No session ticket support; server doesn't send NewSessionTicket.
3668 tests = append(tests, testCase{
3669 name: "SessionTicketsDisabled-Client",
3670 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003671 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003672 SessionTicketsDisabled: true,
3673 },
3674 })
3675 tests = append(tests, testCase{
3676 testType: serverTest,
3677 name: "SessionTicketsDisabled-Server",
3678 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003679 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003680 SessionTicketsDisabled: true,
3681 },
3682 })
3683
3684 // Skip ServerKeyExchange in PSK key exchange if there's no
3685 // identity hint.
3686 tests = append(tests, testCase{
3687 name: "EmptyPSKHint-Client",
3688 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003689 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003690 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3691 PreSharedKey: []byte("secret"),
3692 },
3693 flags: []string{"-psk", "secret"},
3694 })
3695 tests = append(tests, testCase{
3696 testType: serverTest,
3697 name: "EmptyPSKHint-Server",
3698 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003699 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003700 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3701 PreSharedKey: []byte("secret"),
3702 },
3703 flags: []string{"-psk", "secret"},
3704 })
3705
David Benjamin4c3ddf72016-06-29 18:13:53 -04003706 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003707 tests = append(tests, testCase{
3708 testType: clientTest,
3709 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003710 config: Config{
3711 MaxVersion: VersionTLS12,
3712 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003713 flags: []string{
3714 "-enable-ocsp-stapling",
3715 "-expect-ocsp-response",
3716 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003717 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003718 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003719 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003720 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003721 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003722 testType: serverTest,
3723 name: "OCSPStapling-Server",
3724 config: Config{
3725 MaxVersion: VersionTLS12,
3726 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003727 expectedOCSPResponse: testOCSPResponse,
3728 flags: []string{
3729 "-ocsp-response",
3730 base64.StdEncoding.EncodeToString(testOCSPResponse),
3731 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003732 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003733 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003734 tests = append(tests, testCase{
3735 testType: clientTest,
3736 name: "OCSPStapling-Client-TLS13",
3737 config: Config{
3738 MaxVersion: VersionTLS13,
3739 },
3740 flags: []string{
3741 "-enable-ocsp-stapling",
3742 "-expect-ocsp-response",
3743 base64.StdEncoding.EncodeToString(testOCSPResponse),
3744 "-verify-peer",
3745 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003746 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003747 })
3748 tests = append(tests, testCase{
3749 testType: serverTest,
3750 name: "OCSPStapling-Server-TLS13",
3751 config: Config{
3752 MaxVersion: VersionTLS13,
3753 },
3754 expectedOCSPResponse: testOCSPResponse,
3755 flags: []string{
3756 "-ocsp-response",
3757 base64.StdEncoding.EncodeToString(testOCSPResponse),
3758 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003759 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003760 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003761
David Benjamin4c3ddf72016-06-29 18:13:53 -04003762 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003763 for _, vers := range tlsVersions {
3764 if config.protocol == dtls && !vers.hasDTLS {
3765 continue
3766 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003767 for _, testType := range []testType{clientTest, serverTest} {
3768 suffix := "-Client"
3769 if testType == serverTest {
3770 suffix = "-Server"
3771 }
3772 suffix += "-" + vers.name
3773
3774 flag := "-verify-peer"
3775 if testType == serverTest {
3776 flag = "-require-any-client-certificate"
3777 }
3778
3779 tests = append(tests, testCase{
3780 testType: testType,
3781 name: "CertificateVerificationSucceed" + suffix,
3782 config: Config{
3783 MaxVersion: vers.version,
3784 Certificates: []Certificate{rsaCertificate},
3785 },
3786 flags: []string{
3787 flag,
3788 "-expect-verify-result",
3789 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003790 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003791 })
3792 tests = append(tests, testCase{
3793 testType: testType,
3794 name: "CertificateVerificationFail" + suffix,
3795 config: Config{
3796 MaxVersion: vers.version,
3797 Certificates: []Certificate{rsaCertificate},
3798 },
3799 flags: []string{
3800 flag,
3801 "-verify-fail",
3802 },
3803 shouldFail: true,
3804 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3805 })
3806 }
3807
3808 // By default, the client is in a soft fail mode where the peer
3809 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003810 tests = append(tests, testCase{
3811 testType: clientTest,
3812 name: "CertificateVerificationSoftFail-" + vers.name,
3813 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003814 MaxVersion: vers.version,
3815 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003816 },
3817 flags: []string{
3818 "-verify-fail",
3819 "-expect-verify-result",
3820 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003821 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003822 })
3823 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003824
David Benjamin1d4f4c02016-07-26 18:03:08 -04003825 tests = append(tests, testCase{
3826 name: "ShimSendAlert",
3827 flags: []string{"-send-alert"},
3828 shimWritesFirst: true,
3829 shouldFail: true,
3830 expectedLocalError: "remote error: decompression failure",
3831 })
3832
David Benjamin582ba042016-07-07 12:33:25 -07003833 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003834 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003835 name: "Renegotiate-Client",
3836 config: Config{
3837 MaxVersion: VersionTLS12,
3838 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003839 renegotiate: 1,
3840 flags: []string{
3841 "-renegotiate-freely",
3842 "-expect-total-renegotiations", "1",
3843 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003844 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003845
David Benjamin47921102016-07-28 11:29:18 -04003846 tests = append(tests, testCase{
3847 name: "SendHalfHelloRequest",
3848 config: Config{
3849 MaxVersion: VersionTLS12,
3850 Bugs: ProtocolBugs{
3851 PackHelloRequestWithFinished: config.packHandshakeFlight,
3852 },
3853 },
3854 sendHalfHelloRequest: true,
3855 flags: []string{"-renegotiate-ignore"},
3856 shouldFail: true,
3857 expectedError: ":UNEXPECTED_RECORD:",
3858 })
3859
David Benjamin760b1dd2015-05-15 23:33:48 -04003860 // NPN on client and server; results in post-handshake message.
3861 tests = append(tests, testCase{
3862 name: "NPN-Client",
3863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003864 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003865 NextProtos: []string{"foo"},
3866 },
3867 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003868 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003869 expectedNextProto: "foo",
3870 expectedNextProtoType: npn,
3871 })
3872 tests = append(tests, testCase{
3873 testType: serverTest,
3874 name: "NPN-Server",
3875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003876 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003877 NextProtos: []string{"bar"},
3878 },
3879 flags: []string{
3880 "-advertise-npn", "\x03foo\x03bar\x03baz",
3881 "-expect-next-proto", "bar",
3882 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003883 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003884 expectedNextProto: "bar",
3885 expectedNextProtoType: npn,
3886 })
3887
3888 // TODO(davidben): Add tests for when False Start doesn't trigger.
3889
3890 // Client does False Start and negotiates NPN.
3891 tests = append(tests, testCase{
3892 name: "FalseStart",
3893 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003894 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003895 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3896 NextProtos: []string{"foo"},
3897 Bugs: ProtocolBugs{
3898 ExpectFalseStart: true,
3899 },
3900 },
3901 flags: []string{
3902 "-false-start",
3903 "-select-next-proto", "foo",
3904 },
3905 shimWritesFirst: true,
3906 resumeSession: true,
3907 })
3908
3909 // Client does False Start and negotiates ALPN.
3910 tests = append(tests, testCase{
3911 name: "FalseStart-ALPN",
3912 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003913 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003914 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3915 NextProtos: []string{"foo"},
3916 Bugs: ProtocolBugs{
3917 ExpectFalseStart: true,
3918 },
3919 },
3920 flags: []string{
3921 "-false-start",
3922 "-advertise-alpn", "\x03foo",
3923 },
3924 shimWritesFirst: true,
3925 resumeSession: true,
3926 })
3927
3928 // Client does False Start but doesn't explicitly call
3929 // SSL_connect.
3930 tests = append(tests, testCase{
3931 name: "FalseStart-Implicit",
3932 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003933 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003934 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3935 NextProtos: []string{"foo"},
3936 },
3937 flags: []string{
3938 "-implicit-handshake",
3939 "-false-start",
3940 "-advertise-alpn", "\x03foo",
3941 },
3942 })
3943
3944 // False Start without session tickets.
3945 tests = append(tests, testCase{
3946 name: "FalseStart-SessionTicketsDisabled",
3947 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003948 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3950 NextProtos: []string{"foo"},
3951 SessionTicketsDisabled: true,
3952 Bugs: ProtocolBugs{
3953 ExpectFalseStart: true,
3954 },
3955 },
3956 flags: []string{
3957 "-false-start",
3958 "-select-next-proto", "foo",
3959 },
3960 shimWritesFirst: true,
3961 })
3962
Adam Langleydf759b52016-07-11 15:24:37 -07003963 tests = append(tests, testCase{
3964 name: "FalseStart-CECPQ1",
3965 config: Config{
3966 MaxVersion: VersionTLS12,
3967 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3968 NextProtos: []string{"foo"},
3969 Bugs: ProtocolBugs{
3970 ExpectFalseStart: true,
3971 },
3972 },
3973 flags: []string{
3974 "-false-start",
3975 "-cipher", "DEFAULT:kCECPQ1",
3976 "-select-next-proto", "foo",
3977 },
3978 shimWritesFirst: true,
3979 resumeSession: true,
3980 })
3981
David Benjamin760b1dd2015-05-15 23:33:48 -04003982 // Server parses a V2ClientHello.
3983 tests = append(tests, testCase{
3984 testType: serverTest,
3985 name: "SendV2ClientHello",
3986 config: Config{
3987 // Choose a cipher suite that does not involve
3988 // elliptic curves, so no extensions are
3989 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003990 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003991 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003992 Bugs: ProtocolBugs{
3993 SendV2ClientHello: true,
3994 },
3995 },
3996 })
3997
Nick Harper60a85cb2016-09-23 16:25:11 -07003998 // Test Channel ID
3999 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004000 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004001 continue
4002 }
4003 // Client sends a Channel ID.
4004 tests = append(tests, testCase{
4005 name: "ChannelID-Client-" + ver.name,
4006 config: Config{
4007 MaxVersion: ver.version,
4008 RequestChannelID: true,
4009 },
4010 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4011 resumeSession: true,
4012 expectChannelID: true,
4013 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004014
Nick Harper60a85cb2016-09-23 16:25:11 -07004015 // Server accepts a Channel ID.
4016 tests = append(tests, testCase{
4017 testType: serverTest,
4018 name: "ChannelID-Server-" + ver.name,
4019 config: Config{
4020 MaxVersion: ver.version,
4021 ChannelID: channelIDKey,
4022 },
4023 flags: []string{
4024 "-expect-channel-id",
4025 base64.StdEncoding.EncodeToString(channelIDBytes),
4026 },
4027 resumeSession: true,
4028 expectChannelID: true,
4029 })
4030
4031 tests = append(tests, testCase{
4032 testType: serverTest,
4033 name: "InvalidChannelIDSignature-" + ver.name,
4034 config: Config{
4035 MaxVersion: ver.version,
4036 ChannelID: channelIDKey,
4037 Bugs: ProtocolBugs{
4038 InvalidChannelIDSignature: true,
4039 },
4040 },
4041 flags: []string{"-enable-channel-id"},
4042 shouldFail: true,
4043 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4044 })
4045 }
David Benjamin30789da2015-08-29 22:56:45 -04004046
David Benjaminf8fcdf32016-06-08 15:56:13 -04004047 // Channel ID and NPN at the same time, to ensure their relative
4048 // ordering is correct.
4049 tests = append(tests, testCase{
4050 name: "ChannelID-NPN-Client",
4051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004052 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004053 RequestChannelID: true,
4054 NextProtos: []string{"foo"},
4055 },
4056 flags: []string{
4057 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4058 "-select-next-proto", "foo",
4059 },
4060 resumeSession: true,
4061 expectChannelID: true,
4062 expectedNextProto: "foo",
4063 expectedNextProtoType: npn,
4064 })
4065 tests = append(tests, testCase{
4066 testType: serverTest,
4067 name: "ChannelID-NPN-Server",
4068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004069 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004070 ChannelID: channelIDKey,
4071 NextProtos: []string{"bar"},
4072 },
4073 flags: []string{
4074 "-expect-channel-id",
4075 base64.StdEncoding.EncodeToString(channelIDBytes),
4076 "-advertise-npn", "\x03foo\x03bar\x03baz",
4077 "-expect-next-proto", "bar",
4078 },
4079 resumeSession: true,
4080 expectChannelID: true,
4081 expectedNextProto: "bar",
4082 expectedNextProtoType: npn,
4083 })
4084
David Benjamin30789da2015-08-29 22:56:45 -04004085 // Bidirectional shutdown with the runner initiating.
4086 tests = append(tests, testCase{
4087 name: "Shutdown-Runner",
4088 config: Config{
4089 Bugs: ProtocolBugs{
4090 ExpectCloseNotify: true,
4091 },
4092 },
4093 flags: []string{"-check-close-notify"},
4094 })
4095
4096 // Bidirectional shutdown with the shim initiating. The runner,
4097 // in the meantime, sends garbage before the close_notify which
4098 // the shim must ignore.
4099 tests = append(tests, testCase{
4100 name: "Shutdown-Shim",
4101 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004102 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004103 Bugs: ProtocolBugs{
4104 ExpectCloseNotify: true,
4105 },
4106 },
4107 shimShutsDown: true,
4108 sendEmptyRecords: 1,
4109 sendWarningAlerts: 1,
4110 flags: []string{"-check-close-notify"},
4111 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004112 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004113 // TODO(davidben): DTLS 1.3 will want a similar thing for
4114 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004115 tests = append(tests, testCase{
4116 name: "SkipHelloVerifyRequest",
4117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004118 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004119 Bugs: ProtocolBugs{
4120 SkipHelloVerifyRequest: true,
4121 },
4122 },
4123 })
4124 }
4125
David Benjamin760b1dd2015-05-15 23:33:48 -04004126 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004127 test.protocol = config.protocol
4128 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004129 test.name += "-DTLS"
4130 }
David Benjamin582ba042016-07-07 12:33:25 -07004131 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004132 test.name += "-Async"
4133 test.flags = append(test.flags, "-async")
4134 } else {
4135 test.name += "-Sync"
4136 }
David Benjamin582ba042016-07-07 12:33:25 -07004137 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004138 test.name += "-SplitHandshakeRecords"
4139 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004140 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004141 test.config.Bugs.MaxPacketLength = 256
4142 test.flags = append(test.flags, "-mtu", "256")
4143 }
4144 }
David Benjamin582ba042016-07-07 12:33:25 -07004145 if config.packHandshakeFlight {
4146 test.name += "-PackHandshakeFlight"
4147 test.config.Bugs.PackHandshakeFlight = true
4148 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004149 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004150 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004151}
4152
Adam Langley524e7172015-02-20 16:04:00 -08004153func addDDoSCallbackTests() {
4154 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004155 for _, resume := range []bool{false, true} {
4156 suffix := "Resume"
4157 if resume {
4158 suffix = "No" + suffix
4159 }
4160
4161 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004162 testType: serverTest,
4163 name: "Server-DDoS-OK-" + suffix,
4164 config: Config{
4165 MaxVersion: VersionTLS12,
4166 },
Adam Langley524e7172015-02-20 16:04:00 -08004167 flags: []string{"-install-ddos-callback"},
4168 resumeSession: resume,
4169 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004170 testCases = append(testCases, testCase{
4171 testType: serverTest,
4172 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4173 config: Config{
4174 MaxVersion: VersionTLS13,
4175 },
4176 flags: []string{"-install-ddos-callback"},
4177 resumeSession: resume,
4178 })
Adam Langley524e7172015-02-20 16:04:00 -08004179
4180 failFlag := "-fail-ddos-callback"
4181 if resume {
4182 failFlag = "-fail-second-ddos-callback"
4183 }
4184 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004185 testType: serverTest,
4186 name: "Server-DDoS-Reject-" + suffix,
4187 config: Config{
4188 MaxVersion: VersionTLS12,
4189 },
David Benjamin2c66e072016-09-16 15:58:00 -04004190 flags: []string{"-install-ddos-callback", failFlag},
4191 resumeSession: resume,
4192 shouldFail: true,
4193 expectedError: ":CONNECTION_REJECTED:",
4194 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004195 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004196 testCases = append(testCases, testCase{
4197 testType: serverTest,
4198 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4199 config: Config{
4200 MaxVersion: VersionTLS13,
4201 },
David Benjamin2c66e072016-09-16 15:58:00 -04004202 flags: []string{"-install-ddos-callback", failFlag},
4203 resumeSession: resume,
4204 shouldFail: true,
4205 expectedError: ":CONNECTION_REJECTED:",
4206 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004207 })
Adam Langley524e7172015-02-20 16:04:00 -08004208 }
4209}
4210
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004211func addVersionNegotiationTests() {
4212 for i, shimVers := range tlsVersions {
4213 // Assemble flags to disable all newer versions on the shim.
4214 var flags []string
4215 for _, vers := range tlsVersions[i+1:] {
4216 flags = append(flags, vers.flag)
4217 }
4218
Steven Valdezfdd10992016-09-15 16:27:05 -04004219 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004220 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004221 protocols := []protocol{tls}
4222 if runnerVers.hasDTLS && shimVers.hasDTLS {
4223 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004224 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004225 for _, protocol := range protocols {
4226 expectedVersion := shimVers.version
4227 if runnerVers.version < shimVers.version {
4228 expectedVersion = runnerVers.version
4229 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004230
David Benjamin8b8c0062014-11-23 02:47:52 -05004231 suffix := shimVers.name + "-" + runnerVers.name
4232 if protocol == dtls {
4233 suffix += "-DTLS"
4234 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004235
David Benjamin1eb367c2014-12-12 18:17:51 -05004236 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4237
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004238 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004239 clientVers := shimVers.version
4240 if clientVers > VersionTLS10 {
4241 clientVers = VersionTLS10
4242 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004243 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004244 serverVers := expectedVersion
4245 if expectedVersion >= VersionTLS13 {
4246 serverVers = VersionTLS10
4247 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004248 serverVers = versionToWire(serverVers, protocol == dtls)
4249
David Benjamin8b8c0062014-11-23 02:47:52 -05004250 testCases = append(testCases, testCase{
4251 protocol: protocol,
4252 testType: clientTest,
4253 name: "VersionNegotiation-Client-" + suffix,
4254 config: Config{
4255 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004256 Bugs: ProtocolBugs{
4257 ExpectInitialRecordVersion: clientVers,
4258 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004259 },
4260 flags: flags,
4261 expectedVersion: expectedVersion,
4262 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004263 testCases = append(testCases, testCase{
4264 protocol: protocol,
4265 testType: clientTest,
4266 name: "VersionNegotiation-Client2-" + suffix,
4267 config: Config{
4268 MaxVersion: runnerVers.version,
4269 Bugs: ProtocolBugs{
4270 ExpectInitialRecordVersion: clientVers,
4271 },
4272 },
4273 flags: []string{"-max-version", shimVersFlag},
4274 expectedVersion: expectedVersion,
4275 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004276
4277 testCases = append(testCases, testCase{
4278 protocol: protocol,
4279 testType: serverTest,
4280 name: "VersionNegotiation-Server-" + suffix,
4281 config: Config{
4282 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004283 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004284 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004285 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004286 },
4287 flags: flags,
4288 expectedVersion: expectedVersion,
4289 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004290 testCases = append(testCases, testCase{
4291 protocol: protocol,
4292 testType: serverTest,
4293 name: "VersionNegotiation-Server2-" + suffix,
4294 config: Config{
4295 MaxVersion: runnerVers.version,
4296 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004297 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004298 },
4299 },
4300 flags: []string{"-max-version", shimVersFlag},
4301 expectedVersion: expectedVersion,
4302 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004303 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004304 }
4305 }
David Benjamin95c69562016-06-29 18:15:03 -04004306
Steven Valdezfdd10992016-09-15 16:27:05 -04004307 // Test the version extension at all versions.
4308 for _, vers := range tlsVersions {
4309 protocols := []protocol{tls}
4310 if vers.hasDTLS {
4311 protocols = append(protocols, dtls)
4312 }
4313 for _, protocol := range protocols {
4314 suffix := vers.name
4315 if protocol == dtls {
4316 suffix += "-DTLS"
4317 }
4318
4319 wireVersion := versionToWire(vers.version, protocol == dtls)
4320 testCases = append(testCases, testCase{
4321 protocol: protocol,
4322 testType: serverTest,
4323 name: "VersionNegotiationExtension-" + suffix,
4324 config: Config{
4325 Bugs: ProtocolBugs{
4326 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4327 },
4328 },
4329 expectedVersion: vers.version,
4330 })
4331 }
4332
4333 }
4334
4335 // If all versions are unknown, negotiation fails.
4336 testCases = append(testCases, testCase{
4337 testType: serverTest,
4338 name: "NoSupportedVersions",
4339 config: Config{
4340 Bugs: ProtocolBugs{
4341 SendSupportedVersions: []uint16{0x1111},
4342 },
4343 },
4344 shouldFail: true,
4345 expectedError: ":UNSUPPORTED_PROTOCOL:",
4346 })
4347 testCases = append(testCases, testCase{
4348 protocol: dtls,
4349 testType: serverTest,
4350 name: "NoSupportedVersions-DTLS",
4351 config: Config{
4352 Bugs: ProtocolBugs{
4353 SendSupportedVersions: []uint16{0x1111},
4354 },
4355 },
4356 shouldFail: true,
4357 expectedError: ":UNSUPPORTED_PROTOCOL:",
4358 })
4359
4360 testCases = append(testCases, testCase{
4361 testType: serverTest,
4362 name: "ClientHelloVersionTooHigh",
4363 config: Config{
4364 MaxVersion: VersionTLS13,
4365 Bugs: ProtocolBugs{
4366 SendClientVersion: 0x0304,
4367 OmitSupportedVersions: true,
4368 },
4369 },
4370 expectedVersion: VersionTLS12,
4371 })
4372
4373 testCases = append(testCases, testCase{
4374 testType: serverTest,
4375 name: "ConflictingVersionNegotiation",
4376 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004377 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004378 SendClientVersion: VersionTLS12,
4379 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004380 },
4381 },
David Benjaminad75a662016-09-30 15:42:59 -04004382 // The extension takes precedence over the ClientHello version.
4383 expectedVersion: VersionTLS11,
4384 })
4385
4386 testCases = append(testCases, testCase{
4387 testType: serverTest,
4388 name: "ConflictingVersionNegotiation-2",
4389 config: Config{
4390 Bugs: ProtocolBugs{
4391 SendClientVersion: VersionTLS11,
4392 SendSupportedVersions: []uint16{VersionTLS12},
4393 },
4394 },
4395 // The extension takes precedence over the ClientHello version.
4396 expectedVersion: VersionTLS12,
4397 })
4398
4399 testCases = append(testCases, testCase{
4400 testType: serverTest,
4401 name: "RejectFinalTLS13",
4402 config: Config{
4403 Bugs: ProtocolBugs{
4404 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4405 },
4406 },
4407 // We currently implement a draft TLS 1.3 version. Ensure that
4408 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004409 expectedVersion: VersionTLS12,
4410 })
4411
Brian Smithf85d3232016-10-28 10:34:06 -10004412 // Test that the maximum version is selected regardless of the
4413 // client-sent order.
4414 testCases = append(testCases, testCase{
4415 testType: serverTest,
4416 name: "IgnoreClientVersionOrder",
4417 config: Config{
4418 Bugs: ProtocolBugs{
4419 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4420 },
4421 },
4422 expectedVersion: VersionTLS13,
4423 })
4424
David Benjamin95c69562016-06-29 18:15:03 -04004425 // Test for version tolerance.
4426 testCases = append(testCases, testCase{
4427 testType: serverTest,
4428 name: "MinorVersionTolerance",
4429 config: Config{
4430 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004431 SendClientVersion: 0x03ff,
4432 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004433 },
4434 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004435 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004436 })
4437 testCases = append(testCases, testCase{
4438 testType: serverTest,
4439 name: "MajorVersionTolerance",
4440 config: Config{
4441 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004442 SendClientVersion: 0x0400,
4443 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004444 },
4445 },
David Benjaminad75a662016-09-30 15:42:59 -04004446 // TLS 1.3 must be negotiated with the supported_versions
4447 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004448 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004449 })
David Benjaminad75a662016-09-30 15:42:59 -04004450 testCases = append(testCases, testCase{
4451 testType: serverTest,
4452 name: "VersionTolerance-TLS13",
4453 config: Config{
4454 Bugs: ProtocolBugs{
4455 // Although TLS 1.3 does not use
4456 // ClientHello.version, it still tolerates high
4457 // values there.
4458 SendClientVersion: 0x0400,
4459 },
4460 },
4461 expectedVersion: VersionTLS13,
4462 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004463
David Benjamin95c69562016-06-29 18:15:03 -04004464 testCases = append(testCases, testCase{
4465 protocol: dtls,
4466 testType: serverTest,
4467 name: "MinorVersionTolerance-DTLS",
4468 config: Config{
4469 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004470 SendClientVersion: 0xfe00,
4471 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004472 },
4473 },
4474 expectedVersion: VersionTLS12,
4475 })
4476 testCases = append(testCases, testCase{
4477 protocol: dtls,
4478 testType: serverTest,
4479 name: "MajorVersionTolerance-DTLS",
4480 config: Config{
4481 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004482 SendClientVersion: 0xfdff,
4483 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004484 },
4485 },
4486 expectedVersion: VersionTLS12,
4487 })
4488
4489 // Test that versions below 3.0 are rejected.
4490 testCases = append(testCases, testCase{
4491 testType: serverTest,
4492 name: "VersionTooLow",
4493 config: Config{
4494 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004495 SendClientVersion: 0x0200,
4496 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004497 },
4498 },
4499 shouldFail: true,
4500 expectedError: ":UNSUPPORTED_PROTOCOL:",
4501 })
4502 testCases = append(testCases, testCase{
4503 protocol: dtls,
4504 testType: serverTest,
4505 name: "VersionTooLow-DTLS",
4506 config: Config{
4507 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004508 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004509 },
4510 },
4511 shouldFail: true,
4512 expectedError: ":UNSUPPORTED_PROTOCOL:",
4513 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004514
David Benjamin2dc02042016-09-19 19:57:37 -04004515 testCases = append(testCases, testCase{
4516 name: "ServerBogusVersion",
4517 config: Config{
4518 Bugs: ProtocolBugs{
4519 SendServerHelloVersion: 0x1234,
4520 },
4521 },
4522 shouldFail: true,
4523 expectedError: ":UNSUPPORTED_PROTOCOL:",
4524 })
4525
David Benjamin1f61f0d2016-07-10 12:20:35 -04004526 // Test TLS 1.3's downgrade signal.
4527 testCases = append(testCases, testCase{
4528 name: "Downgrade-TLS12-Client",
4529 config: Config{
4530 Bugs: ProtocolBugs{
4531 NegotiateVersion: VersionTLS12,
4532 },
4533 },
David Benjamin592b5322016-09-30 15:15:01 -04004534 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004535 // TODO(davidben): This test should fail once TLS 1.3 is final
4536 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004537 })
4538 testCases = append(testCases, testCase{
4539 testType: serverTest,
4540 name: "Downgrade-TLS12-Server",
4541 config: Config{
4542 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004543 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004544 },
4545 },
David Benjamin592b5322016-09-30 15:15:01 -04004546 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004547 // TODO(davidben): This test should fail once TLS 1.3 is final
4548 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004549 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004550}
4551
David Benjaminaccb4542014-12-12 23:44:33 -05004552func addMinimumVersionTests() {
4553 for i, shimVers := range tlsVersions {
4554 // Assemble flags to disable all older versions on the shim.
4555 var flags []string
4556 for _, vers := range tlsVersions[:i] {
4557 flags = append(flags, vers.flag)
4558 }
4559
4560 for _, runnerVers := range tlsVersions {
4561 protocols := []protocol{tls}
4562 if runnerVers.hasDTLS && shimVers.hasDTLS {
4563 protocols = append(protocols, dtls)
4564 }
4565 for _, protocol := range protocols {
4566 suffix := shimVers.name + "-" + runnerVers.name
4567 if protocol == dtls {
4568 suffix += "-DTLS"
4569 }
4570 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4571
David Benjaminaccb4542014-12-12 23:44:33 -05004572 var expectedVersion uint16
4573 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004574 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004575 if runnerVers.version >= shimVers.version {
4576 expectedVersion = runnerVers.version
4577 } else {
4578 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004579 expectedError = ":UNSUPPORTED_PROTOCOL:"
4580 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004581 }
4582
4583 testCases = append(testCases, testCase{
4584 protocol: protocol,
4585 testType: clientTest,
4586 name: "MinimumVersion-Client-" + suffix,
4587 config: Config{
4588 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004589 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004590 // Ensure the server does not decline to
4591 // select a version (versions extension) or
4592 // cipher (some ciphers depend on versions).
4593 NegotiateVersion: runnerVers.version,
4594 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004595 },
David Benjaminaccb4542014-12-12 23:44:33 -05004596 },
David Benjamin87909c02014-12-13 01:55:01 -05004597 flags: flags,
4598 expectedVersion: expectedVersion,
4599 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004600 expectedError: expectedError,
4601 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004602 })
4603 testCases = append(testCases, testCase{
4604 protocol: protocol,
4605 testType: clientTest,
4606 name: "MinimumVersion-Client2-" + suffix,
4607 config: Config{
4608 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004609 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004610 // Ensure the server does not decline to
4611 // select a version (versions extension) or
4612 // cipher (some ciphers depend on versions).
4613 NegotiateVersion: runnerVers.version,
4614 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004615 },
David Benjaminaccb4542014-12-12 23:44:33 -05004616 },
David Benjamin87909c02014-12-13 01:55:01 -05004617 flags: []string{"-min-version", shimVersFlag},
4618 expectedVersion: expectedVersion,
4619 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004620 expectedError: expectedError,
4621 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004622 })
4623
4624 testCases = append(testCases, testCase{
4625 protocol: protocol,
4626 testType: serverTest,
4627 name: "MinimumVersion-Server-" + suffix,
4628 config: Config{
4629 MaxVersion: runnerVers.version,
4630 },
David Benjamin87909c02014-12-13 01:55:01 -05004631 flags: flags,
4632 expectedVersion: expectedVersion,
4633 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004634 expectedError: expectedError,
4635 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004636 })
4637 testCases = append(testCases, testCase{
4638 protocol: protocol,
4639 testType: serverTest,
4640 name: "MinimumVersion-Server2-" + suffix,
4641 config: Config{
4642 MaxVersion: runnerVers.version,
4643 },
David Benjamin87909c02014-12-13 01:55:01 -05004644 flags: []string{"-min-version", shimVersFlag},
4645 expectedVersion: expectedVersion,
4646 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004647 expectedError: expectedError,
4648 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004649 })
4650 }
4651 }
4652 }
4653}
4654
David Benjamine78bfde2014-09-06 12:45:15 -04004655func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004656 // TODO(davidben): Extensions, where applicable, all move their server
4657 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4658 // tests for both. Also test interaction with 0-RTT when implemented.
4659
David Benjamin97d17d92016-07-14 16:12:00 -04004660 // Repeat extensions tests all versions except SSL 3.0.
4661 for _, ver := range tlsVersions {
4662 if ver.version == VersionSSL30 {
4663 continue
4664 }
4665
David Benjamin97d17d92016-07-14 16:12:00 -04004666 // Test that duplicate extensions are rejected.
4667 testCases = append(testCases, testCase{
4668 testType: clientTest,
4669 name: "DuplicateExtensionClient-" + ver.name,
4670 config: Config{
4671 MaxVersion: ver.version,
4672 Bugs: ProtocolBugs{
4673 DuplicateExtension: true,
4674 },
David Benjamine78bfde2014-09-06 12:45:15 -04004675 },
David Benjamin97d17d92016-07-14 16:12:00 -04004676 shouldFail: true,
4677 expectedLocalError: "remote error: error decoding message",
4678 })
4679 testCases = append(testCases, testCase{
4680 testType: serverTest,
4681 name: "DuplicateExtensionServer-" + ver.name,
4682 config: Config{
4683 MaxVersion: ver.version,
4684 Bugs: ProtocolBugs{
4685 DuplicateExtension: true,
4686 },
David Benjamine78bfde2014-09-06 12:45:15 -04004687 },
David Benjamin97d17d92016-07-14 16:12:00 -04004688 shouldFail: true,
4689 expectedLocalError: "remote error: error decoding message",
4690 })
4691
4692 // Test SNI.
4693 testCases = append(testCases, testCase{
4694 testType: clientTest,
4695 name: "ServerNameExtensionClient-" + ver.name,
4696 config: Config{
4697 MaxVersion: ver.version,
4698 Bugs: ProtocolBugs{
4699 ExpectServerName: "example.com",
4700 },
David Benjamine78bfde2014-09-06 12:45:15 -04004701 },
David Benjamin97d17d92016-07-14 16:12:00 -04004702 flags: []string{"-host-name", "example.com"},
4703 })
4704 testCases = append(testCases, testCase{
4705 testType: clientTest,
4706 name: "ServerNameExtensionClientMismatch-" + ver.name,
4707 config: Config{
4708 MaxVersion: ver.version,
4709 Bugs: ProtocolBugs{
4710 ExpectServerName: "mismatch.com",
4711 },
David Benjamine78bfde2014-09-06 12:45:15 -04004712 },
David Benjamin97d17d92016-07-14 16:12:00 -04004713 flags: []string{"-host-name", "example.com"},
4714 shouldFail: true,
4715 expectedLocalError: "tls: unexpected server name",
4716 })
4717 testCases = append(testCases, testCase{
4718 testType: clientTest,
4719 name: "ServerNameExtensionClientMissing-" + ver.name,
4720 config: Config{
4721 MaxVersion: ver.version,
4722 Bugs: ProtocolBugs{
4723 ExpectServerName: "missing.com",
4724 },
David Benjamine78bfde2014-09-06 12:45:15 -04004725 },
David Benjamin97d17d92016-07-14 16:12:00 -04004726 shouldFail: true,
4727 expectedLocalError: "tls: unexpected server name",
4728 })
4729 testCases = append(testCases, testCase{
4730 testType: serverTest,
4731 name: "ServerNameExtensionServer-" + ver.name,
4732 config: Config{
4733 MaxVersion: ver.version,
4734 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004735 },
David Benjamin97d17d92016-07-14 16:12:00 -04004736 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004737 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004738 })
4739
4740 // Test ALPN.
4741 testCases = append(testCases, testCase{
4742 testType: clientTest,
4743 name: "ALPNClient-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 NextProtos: []string{"foo"},
4747 },
4748 flags: []string{
4749 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4750 "-expect-alpn", "foo",
4751 },
4752 expectedNextProto: "foo",
4753 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004754 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004755 })
4756 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004757 testType: clientTest,
4758 name: "ALPNClient-Mismatch-" + ver.name,
4759 config: Config{
4760 MaxVersion: ver.version,
4761 Bugs: ProtocolBugs{
4762 SendALPN: "baz",
4763 },
4764 },
4765 flags: []string{
4766 "-advertise-alpn", "\x03foo\x03bar",
4767 },
4768 shouldFail: true,
4769 expectedError: ":INVALID_ALPN_PROTOCOL:",
4770 expectedLocalError: "remote error: illegal parameter",
4771 })
4772 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004773 testType: serverTest,
4774 name: "ALPNServer-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 NextProtos: []string{"foo", "bar", "baz"},
4778 },
4779 flags: []string{
4780 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4781 "-select-alpn", "foo",
4782 },
4783 expectedNextProto: "foo",
4784 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004785 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004786 })
4787 testCases = append(testCases, testCase{
4788 testType: serverTest,
4789 name: "ALPNServer-Decline-" + ver.name,
4790 config: Config{
4791 MaxVersion: ver.version,
4792 NextProtos: []string{"foo", "bar", "baz"},
4793 },
4794 flags: []string{"-decline-alpn"},
4795 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004796 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004797 })
4798
David Benjamin25fe85b2016-08-09 20:00:32 -04004799 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4800 // called once.
4801 testCases = append(testCases, testCase{
4802 testType: serverTest,
4803 name: "ALPNServer-Async-" + ver.name,
4804 config: Config{
4805 MaxVersion: ver.version,
4806 NextProtos: []string{"foo", "bar", "baz"},
4807 },
4808 flags: []string{
4809 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4810 "-select-alpn", "foo",
4811 "-async",
4812 },
4813 expectedNextProto: "foo",
4814 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004815 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004816 })
4817
David Benjamin97d17d92016-07-14 16:12:00 -04004818 var emptyString string
4819 testCases = append(testCases, testCase{
4820 testType: clientTest,
4821 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4822 config: Config{
4823 MaxVersion: ver.version,
4824 NextProtos: []string{""},
4825 Bugs: ProtocolBugs{
4826 // A server returning an empty ALPN protocol
4827 // should be rejected.
4828 ALPNProtocol: &emptyString,
4829 },
4830 },
4831 flags: []string{
4832 "-advertise-alpn", "\x03foo",
4833 },
4834 shouldFail: true,
4835 expectedError: ":PARSE_TLSEXT:",
4836 })
4837 testCases = append(testCases, testCase{
4838 testType: serverTest,
4839 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4840 config: Config{
4841 MaxVersion: ver.version,
4842 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004843 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004844 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004845 },
David Benjamin97d17d92016-07-14 16:12:00 -04004846 flags: []string{
4847 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004848 },
David Benjamin97d17d92016-07-14 16:12:00 -04004849 shouldFail: true,
4850 expectedError: ":PARSE_TLSEXT:",
4851 })
4852
4853 // Test NPN and the interaction with ALPN.
4854 if ver.version < VersionTLS13 {
4855 // Test that the server prefers ALPN over NPN.
4856 testCases = append(testCases, testCase{
4857 testType: serverTest,
4858 name: "ALPNServer-Preferred-" + ver.name,
4859 config: Config{
4860 MaxVersion: ver.version,
4861 NextProtos: []string{"foo", "bar", "baz"},
4862 },
4863 flags: []string{
4864 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4865 "-select-alpn", "foo",
4866 "-advertise-npn", "\x03foo\x03bar\x03baz",
4867 },
4868 expectedNextProto: "foo",
4869 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004870 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004871 })
4872 testCases = append(testCases, testCase{
4873 testType: serverTest,
4874 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4875 config: Config{
4876 MaxVersion: ver.version,
4877 NextProtos: []string{"foo", "bar", "baz"},
4878 Bugs: ProtocolBugs{
4879 SwapNPNAndALPN: true,
4880 },
4881 },
4882 flags: []string{
4883 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4884 "-select-alpn", "foo",
4885 "-advertise-npn", "\x03foo\x03bar\x03baz",
4886 },
4887 expectedNextProto: "foo",
4888 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004889 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004890 })
4891
4892 // Test that negotiating both NPN and ALPN is forbidden.
4893 testCases = append(testCases, testCase{
4894 name: "NegotiateALPNAndNPN-" + ver.name,
4895 config: Config{
4896 MaxVersion: ver.version,
4897 NextProtos: []string{"foo", "bar", "baz"},
4898 Bugs: ProtocolBugs{
4899 NegotiateALPNAndNPN: true,
4900 },
4901 },
4902 flags: []string{
4903 "-advertise-alpn", "\x03foo",
4904 "-select-next-proto", "foo",
4905 },
4906 shouldFail: true,
4907 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4908 })
4909 testCases = append(testCases, testCase{
4910 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4911 config: Config{
4912 MaxVersion: ver.version,
4913 NextProtos: []string{"foo", "bar", "baz"},
4914 Bugs: ProtocolBugs{
4915 NegotiateALPNAndNPN: true,
4916 SwapNPNAndALPN: true,
4917 },
4918 },
4919 flags: []string{
4920 "-advertise-alpn", "\x03foo",
4921 "-select-next-proto", "foo",
4922 },
4923 shouldFail: true,
4924 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4925 })
4926
4927 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4928 testCases = append(testCases, testCase{
4929 name: "DisableNPN-" + ver.name,
4930 config: Config{
4931 MaxVersion: ver.version,
4932 NextProtos: []string{"foo"},
4933 },
4934 flags: []string{
4935 "-select-next-proto", "foo",
4936 "-disable-npn",
4937 },
4938 expectNoNextProto: true,
4939 })
4940 }
4941
4942 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004943
4944 // Resume with a corrupt ticket.
4945 testCases = append(testCases, testCase{
4946 testType: serverTest,
4947 name: "CorruptTicket-" + ver.name,
4948 config: Config{
4949 MaxVersion: ver.version,
4950 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004951 FilterTicket: func(in []byte) ([]byte, error) {
4952 in[len(in)-1] ^= 1
4953 return in, nil
4954 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004955 },
4956 },
4957 resumeSession: true,
4958 expectResumeRejected: true,
4959 })
4960 // Test the ticket callback, with and without renewal.
4961 testCases = append(testCases, testCase{
4962 testType: serverTest,
4963 name: "TicketCallback-" + ver.name,
4964 config: Config{
4965 MaxVersion: ver.version,
4966 },
4967 resumeSession: true,
4968 flags: []string{"-use-ticket-callback"},
4969 })
4970 testCases = append(testCases, testCase{
4971 testType: serverTest,
4972 name: "TicketCallback-Renew-" + ver.name,
4973 config: Config{
4974 MaxVersion: ver.version,
4975 Bugs: ProtocolBugs{
4976 ExpectNewTicket: true,
4977 },
4978 },
4979 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4980 resumeSession: true,
4981 })
4982
4983 // Test that the ticket callback is only called once when everything before
4984 // it in the ClientHello is asynchronous. This corrupts the ticket so
4985 // certificate selection callbacks run.
4986 testCases = append(testCases, testCase{
4987 testType: serverTest,
4988 name: "TicketCallback-SingleCall-" + ver.name,
4989 config: Config{
4990 MaxVersion: ver.version,
4991 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004992 FilterTicket: func(in []byte) ([]byte, error) {
4993 in[len(in)-1] ^= 1
4994 return in, nil
4995 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004996 },
4997 },
4998 resumeSession: true,
4999 expectResumeRejected: true,
5000 flags: []string{
5001 "-use-ticket-callback",
5002 "-async",
5003 },
5004 })
5005
5006 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005007 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005008 testCases = append(testCases, testCase{
5009 testType: serverTest,
5010 name: "OversizedSessionId-" + ver.name,
5011 config: Config{
5012 MaxVersion: ver.version,
5013 Bugs: ProtocolBugs{
5014 OversizedSessionId: true,
5015 },
5016 },
5017 resumeSession: true,
5018 shouldFail: true,
5019 expectedError: ":DECODE_ERROR:",
5020 })
5021 }
5022
5023 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5024 // are ignored.
5025 if ver.hasDTLS {
5026 testCases = append(testCases, testCase{
5027 protocol: dtls,
5028 name: "SRTP-Client-" + ver.name,
5029 config: Config{
5030 MaxVersion: ver.version,
5031 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5032 },
5033 flags: []string{
5034 "-srtp-profiles",
5035 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5036 },
5037 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5038 })
5039 testCases = append(testCases, testCase{
5040 protocol: dtls,
5041 testType: serverTest,
5042 name: "SRTP-Server-" + ver.name,
5043 config: Config{
5044 MaxVersion: ver.version,
5045 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5046 },
5047 flags: []string{
5048 "-srtp-profiles",
5049 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5050 },
5051 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5052 })
5053 // Test that the MKI is ignored.
5054 testCases = append(testCases, testCase{
5055 protocol: dtls,
5056 testType: serverTest,
5057 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5058 config: Config{
5059 MaxVersion: ver.version,
5060 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5061 Bugs: ProtocolBugs{
5062 SRTPMasterKeyIdentifer: "bogus",
5063 },
5064 },
5065 flags: []string{
5066 "-srtp-profiles",
5067 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5068 },
5069 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5070 })
5071 // Test that SRTP isn't negotiated on the server if there were
5072 // no matching profiles.
5073 testCases = append(testCases, testCase{
5074 protocol: dtls,
5075 testType: serverTest,
5076 name: "SRTP-Server-NoMatch-" + ver.name,
5077 config: Config{
5078 MaxVersion: ver.version,
5079 SRTPProtectionProfiles: []uint16{100, 101, 102},
5080 },
5081 flags: []string{
5082 "-srtp-profiles",
5083 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5084 },
5085 expectedSRTPProtectionProfile: 0,
5086 })
5087 // Test that the server returning an invalid SRTP profile is
5088 // flagged as an error by the client.
5089 testCases = append(testCases, testCase{
5090 protocol: dtls,
5091 name: "SRTP-Client-NoMatch-" + ver.name,
5092 config: Config{
5093 MaxVersion: ver.version,
5094 Bugs: ProtocolBugs{
5095 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5096 },
5097 },
5098 flags: []string{
5099 "-srtp-profiles",
5100 "SRTP_AES128_CM_SHA1_80",
5101 },
5102 shouldFail: true,
5103 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5104 })
5105 }
5106
5107 // Test SCT list.
5108 testCases = append(testCases, testCase{
5109 name: "SignedCertificateTimestampList-Client-" + ver.name,
5110 testType: clientTest,
5111 config: Config{
5112 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005113 },
David Benjamin97d17d92016-07-14 16:12:00 -04005114 flags: []string{
5115 "-enable-signed-cert-timestamps",
5116 "-expect-signed-cert-timestamps",
5117 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005118 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005119 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005120 })
David Benjamindaa88502016-10-04 16:32:16 -04005121
5122 // The SCT extension did not specify that it must only be sent on resumption as it
5123 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005124 testCases = append(testCases, testCase{
5125 name: "SendSCTListOnResume-" + ver.name,
5126 config: Config{
5127 MaxVersion: ver.version,
5128 Bugs: ProtocolBugs{
5129 SendSCTListOnResume: []byte("bogus"),
5130 },
David Benjamind98452d2015-06-16 14:16:23 -04005131 },
David Benjamin97d17d92016-07-14 16:12:00 -04005132 flags: []string{
5133 "-enable-signed-cert-timestamps",
5134 "-expect-signed-cert-timestamps",
5135 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005136 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005137 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005138 })
David Benjamindaa88502016-10-04 16:32:16 -04005139
David Benjamin97d17d92016-07-14 16:12:00 -04005140 testCases = append(testCases, testCase{
5141 name: "SignedCertificateTimestampList-Server-" + ver.name,
5142 testType: serverTest,
5143 config: Config{
5144 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005145 },
David Benjamin97d17d92016-07-14 16:12:00 -04005146 flags: []string{
5147 "-signed-cert-timestamps",
5148 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005149 },
David Benjamin97d17d92016-07-14 16:12:00 -04005150 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005151 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005152 })
5153 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005154
Paul Lietar4fac72e2015-09-09 13:44:55 +01005155 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005156 testType: clientTest,
5157 name: "ClientHelloPadding",
5158 config: Config{
5159 Bugs: ProtocolBugs{
5160 RequireClientHelloSize: 512,
5161 },
5162 },
5163 // This hostname just needs to be long enough to push the
5164 // ClientHello into F5's danger zone between 256 and 511 bytes
5165 // long.
5166 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5167 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005168
5169 // Extensions should not function in SSL 3.0.
5170 testCases = append(testCases, testCase{
5171 testType: serverTest,
5172 name: "SSLv3Extensions-NoALPN",
5173 config: Config{
5174 MaxVersion: VersionSSL30,
5175 NextProtos: []string{"foo", "bar", "baz"},
5176 },
5177 flags: []string{
5178 "-select-alpn", "foo",
5179 },
5180 expectNoNextProto: true,
5181 })
5182
5183 // Test session tickets separately as they follow a different codepath.
5184 testCases = append(testCases, testCase{
5185 testType: serverTest,
5186 name: "SSLv3Extensions-NoTickets",
5187 config: Config{
5188 MaxVersion: VersionSSL30,
5189 Bugs: ProtocolBugs{
5190 // Historically, session tickets in SSL 3.0
5191 // failed in different ways depending on whether
5192 // the client supported renegotiation_info.
5193 NoRenegotiationInfo: true,
5194 },
5195 },
5196 resumeSession: true,
5197 })
5198 testCases = append(testCases, testCase{
5199 testType: serverTest,
5200 name: "SSLv3Extensions-NoTickets2",
5201 config: Config{
5202 MaxVersion: VersionSSL30,
5203 },
5204 resumeSession: true,
5205 })
5206
5207 // But SSL 3.0 does send and process renegotiation_info.
5208 testCases = append(testCases, testCase{
5209 testType: serverTest,
5210 name: "SSLv3Extensions-RenegotiationInfo",
5211 config: Config{
5212 MaxVersion: VersionSSL30,
5213 Bugs: ProtocolBugs{
5214 RequireRenegotiationInfo: true,
5215 },
5216 },
5217 })
5218 testCases = append(testCases, testCase{
5219 testType: serverTest,
5220 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5221 config: Config{
5222 MaxVersion: VersionSSL30,
5223 Bugs: ProtocolBugs{
5224 NoRenegotiationInfo: true,
5225 SendRenegotiationSCSV: true,
5226 RequireRenegotiationInfo: true,
5227 },
5228 },
5229 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005230
5231 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5232 // in ServerHello.
5233 testCases = append(testCases, testCase{
5234 name: "NPN-Forbidden-TLS13",
5235 config: Config{
5236 MaxVersion: VersionTLS13,
5237 NextProtos: []string{"foo"},
5238 Bugs: ProtocolBugs{
5239 NegotiateNPNAtAllVersions: true,
5240 },
5241 },
5242 flags: []string{"-select-next-proto", "foo"},
5243 shouldFail: true,
5244 expectedError: ":ERROR_PARSING_EXTENSION:",
5245 })
5246 testCases = append(testCases, testCase{
5247 name: "EMS-Forbidden-TLS13",
5248 config: Config{
5249 MaxVersion: VersionTLS13,
5250 Bugs: ProtocolBugs{
5251 NegotiateEMSAtAllVersions: true,
5252 },
5253 },
5254 shouldFail: true,
5255 expectedError: ":ERROR_PARSING_EXTENSION:",
5256 })
5257 testCases = append(testCases, testCase{
5258 name: "RenegotiationInfo-Forbidden-TLS13",
5259 config: Config{
5260 MaxVersion: VersionTLS13,
5261 Bugs: ProtocolBugs{
5262 NegotiateRenegotiationInfoAtAllVersions: true,
5263 },
5264 },
5265 shouldFail: true,
5266 expectedError: ":ERROR_PARSING_EXTENSION:",
5267 })
5268 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005269 name: "Ticket-Forbidden-TLS13",
5270 config: Config{
5271 MaxVersion: VersionTLS12,
5272 },
5273 resumeConfig: &Config{
5274 MaxVersion: VersionTLS13,
5275 Bugs: ProtocolBugs{
5276 AdvertiseTicketExtension: true,
5277 },
5278 },
5279 resumeSession: true,
5280 shouldFail: true,
5281 expectedError: ":ERROR_PARSING_EXTENSION:",
5282 })
5283
5284 // Test that illegal extensions in TLS 1.3 are declined by the server if
5285 // offered in ClientHello. The runner's server will fail if this occurs,
5286 // so we exercise the offering path. (EMS and Renegotiation Info are
5287 // implicit in every test.)
5288 testCases = append(testCases, testCase{
5289 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005290 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005291 config: Config{
5292 MaxVersion: VersionTLS13,
5293 NextProtos: []string{"bar"},
5294 },
5295 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5296 })
David Benjamin196df5b2016-09-21 16:23:27 -04005297
David Benjamindaa88502016-10-04 16:32:16 -04005298 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5299 // tolerated.
5300 testCases = append(testCases, testCase{
5301 name: "SendOCSPResponseOnResume-TLS12",
5302 config: Config{
5303 MaxVersion: VersionTLS12,
5304 Bugs: ProtocolBugs{
5305 SendOCSPResponseOnResume: []byte("bogus"),
5306 },
5307 },
5308 flags: []string{
5309 "-enable-ocsp-stapling",
5310 "-expect-ocsp-response",
5311 base64.StdEncoding.EncodeToString(testOCSPResponse),
5312 },
5313 resumeSession: true,
5314 })
5315
5316 // Beginning TLS 1.3, enforce this does not happen.
5317 testCases = append(testCases, testCase{
5318 name: "SendOCSPResponseOnResume-TLS13",
5319 config: Config{
5320 MaxVersion: VersionTLS13,
5321 Bugs: ProtocolBugs{
5322 SendOCSPResponseOnResume: []byte("bogus"),
5323 },
5324 },
5325 flags: []string{
5326 "-enable-ocsp-stapling",
5327 "-expect-ocsp-response",
5328 base64.StdEncoding.EncodeToString(testOCSPResponse),
5329 },
5330 resumeSession: true,
5331 shouldFail: true,
5332 expectedError: ":ERROR_PARSING_EXTENSION:",
5333 })
David Benjamine78bfde2014-09-06 12:45:15 -04005334}
5335
David Benjamin01fe8202014-09-24 15:21:44 -04005336func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005337 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005338 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005339 // SSL 3.0 does not have tickets and TLS 1.3 does not
5340 // have session IDs, so skip their cross-resumption
5341 // tests.
5342 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5343 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5344 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005345 }
5346
David Benjamin8b8c0062014-11-23 02:47:52 -05005347 protocols := []protocol{tls}
5348 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5349 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005350 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005351 for _, protocol := range protocols {
5352 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5353 if protocol == dtls {
5354 suffix += "-DTLS"
5355 }
5356
David Benjaminece3de92015-03-16 18:02:20 -04005357 if sessionVers.version == resumeVers.version {
5358 testCases = append(testCases, testCase{
5359 protocol: protocol,
5360 name: "Resume-Client" + suffix,
5361 resumeSession: true,
5362 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005363 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005364 Bugs: ProtocolBugs{
5365 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5366 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5367 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005368 },
David Benjaminece3de92015-03-16 18:02:20 -04005369 expectedVersion: sessionVers.version,
5370 expectedResumeVersion: resumeVers.version,
5371 })
5372 } else {
David Benjamin405da482016-08-08 17:25:07 -04005373 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5374
5375 // Offering a TLS 1.3 session sends an empty session ID, so
5376 // there is no way to convince a non-lookahead client the
5377 // session was resumed. It will appear to the client that a
5378 // stray ChangeCipherSpec was sent.
5379 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5380 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005381 }
5382
David Benjaminece3de92015-03-16 18:02:20 -04005383 testCases = append(testCases, testCase{
5384 protocol: protocol,
5385 name: "Resume-Client-Mismatch" + suffix,
5386 resumeSession: true,
5387 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005388 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005389 },
David Benjaminece3de92015-03-16 18:02:20 -04005390 expectedVersion: sessionVers.version,
5391 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005392 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005393 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005394 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005395 },
5396 },
5397 expectedResumeVersion: resumeVers.version,
5398 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005399 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005400 })
5401 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005402
5403 testCases = append(testCases, testCase{
5404 protocol: protocol,
5405 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005406 resumeSession: true,
5407 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005408 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005409 },
5410 expectedVersion: sessionVers.version,
5411 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005412 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005413 },
5414 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005415 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005416 expectedResumeVersion: resumeVers.version,
5417 })
5418
David Benjamin8b8c0062014-11-23 02:47:52 -05005419 testCases = append(testCases, testCase{
5420 protocol: protocol,
5421 testType: serverTest,
5422 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005423 resumeSession: true,
5424 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005425 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005426 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005427 expectedVersion: sessionVers.version,
5428 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005429 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005430 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005431 Bugs: ProtocolBugs{
5432 SendBothTickets: true,
5433 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005434 },
5435 expectedResumeVersion: resumeVers.version,
5436 })
5437 }
David Benjamin01fe8202014-09-24 15:21:44 -04005438 }
5439 }
David Benjaminece3de92015-03-16 18:02:20 -04005440
David Benjamin4199b0d2016-11-01 13:58:25 -04005441 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005442 testCases = append(testCases, testCase{
5443 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005444 name: "ShimTicketRewritable",
5445 resumeSession: true,
5446 config: Config{
5447 MaxVersion: VersionTLS12,
5448 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5449 Bugs: ProtocolBugs{
5450 FilterTicket: func(in []byte) ([]byte, error) {
5451 in, err := SetShimTicketVersion(in, VersionTLS12)
5452 if err != nil {
5453 return nil, err
5454 }
5455 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5456 },
5457 },
5458 },
5459 flags: []string{
5460 "-ticket-key",
5461 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5462 },
5463 })
5464
5465 // Resumptions are declined if the version does not match.
5466 testCases = append(testCases, testCase{
5467 testType: serverTest,
5468 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005469 resumeSession: true,
5470 config: Config{
5471 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005472 Bugs: ProtocolBugs{
5473 FilterTicket: func(in []byte) ([]byte, error) {
5474 return SetShimTicketVersion(in, VersionTLS13)
5475 },
5476 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005477 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005478 flags: []string{
5479 "-ticket-key",
5480 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5481 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005482 expectResumeRejected: true,
5483 })
5484
5485 testCases = append(testCases, testCase{
5486 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005487 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005488 resumeSession: true,
5489 config: Config{
5490 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005491 Bugs: ProtocolBugs{
5492 FilterTicket: func(in []byte) ([]byte, error) {
5493 return SetShimTicketVersion(in, VersionTLS12)
5494 },
5495 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005496 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005497 flags: []string{
5498 "-ticket-key",
5499 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5500 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005501 expectResumeRejected: true,
5502 })
5503
David Benjamin4199b0d2016-11-01 13:58:25 -04005504 // Resumptions are declined if the cipher is invalid or disabled.
5505 testCases = append(testCases, testCase{
5506 testType: serverTest,
5507 name: "Resume-Server-DeclineBadCipher",
5508 resumeSession: true,
5509 config: Config{
5510 MaxVersion: VersionTLS12,
5511 Bugs: ProtocolBugs{
5512 FilterTicket: func(in []byte) ([]byte, error) {
5513 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5514 },
5515 },
5516 },
5517 flags: []string{
5518 "-ticket-key",
5519 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5520 },
5521 expectResumeRejected: true,
5522 })
5523
5524 testCases = append(testCases, testCase{
5525 testType: serverTest,
5526 name: "Resume-Server-DeclineBadCipher-2",
5527 resumeSession: true,
5528 config: Config{
5529 MaxVersion: VersionTLS12,
5530 Bugs: ProtocolBugs{
5531 FilterTicket: func(in []byte) ([]byte, error) {
5532 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5533 },
5534 },
5535 },
5536 flags: []string{
5537 "-cipher", "AES128",
5538 "-ticket-key",
5539 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5540 },
5541 expectResumeRejected: true,
5542 })
5543
5544 testCases = append(testCases, testCase{
5545 testType: serverTest,
5546 name: "Resume-Server-DeclineBadCipher-TLS13",
5547 resumeSession: true,
5548 config: Config{
5549 MaxVersion: VersionTLS13,
5550 Bugs: ProtocolBugs{
5551 FilterTicket: func(in []byte) ([]byte, error) {
5552 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5553 },
5554 },
5555 },
5556 flags: []string{
5557 "-ticket-key",
5558 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5559 },
5560 expectResumeRejected: true,
5561 })
5562
David Benjamin4199b0d2016-11-01 13:58:25 -04005563 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005564 testCases = append(testCases, testCase{
5565 name: "Resume-Client-CipherMismatch",
5566 resumeSession: true,
5567 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005568 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005569 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5570 },
5571 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005572 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005573 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5574 Bugs: ProtocolBugs{
5575 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5576 },
5577 },
5578 shouldFail: true,
5579 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5580 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005581
5582 testCases = append(testCases, testCase{
5583 name: "Resume-Client-CipherMismatch-TLS13",
5584 resumeSession: true,
5585 config: Config{
5586 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005587 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005588 },
5589 resumeConfig: &Config{
5590 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005591 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005592 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005593 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005594 },
5595 },
5596 shouldFail: true,
5597 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5598 })
David Benjamin01fe8202014-09-24 15:21:44 -04005599}
5600
Adam Langley2ae77d22014-10-28 17:29:33 -07005601func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005602 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005603 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005604 testType: serverTest,
5605 name: "Renegotiate-Server-Forbidden",
5606 config: Config{
5607 MaxVersion: VersionTLS12,
5608 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005609 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005610 shouldFail: true,
5611 expectedError: ":NO_RENEGOTIATION:",
5612 expectedLocalError: "remote error: no renegotiation",
5613 })
Adam Langley5021b222015-06-12 18:27:58 -07005614 // The server shouldn't echo the renegotiation extension unless
5615 // requested by the client.
5616 testCases = append(testCases, testCase{
5617 testType: serverTest,
5618 name: "Renegotiate-Server-NoExt",
5619 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005620 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005621 Bugs: ProtocolBugs{
5622 NoRenegotiationInfo: true,
5623 RequireRenegotiationInfo: true,
5624 },
5625 },
5626 shouldFail: true,
5627 expectedLocalError: "renegotiation extension missing",
5628 })
5629 // The renegotiation SCSV should be sufficient for the server to echo
5630 // the extension.
5631 testCases = append(testCases, testCase{
5632 testType: serverTest,
5633 name: "Renegotiate-Server-NoExt-SCSV",
5634 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005635 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005636 Bugs: ProtocolBugs{
5637 NoRenegotiationInfo: true,
5638 SendRenegotiationSCSV: true,
5639 RequireRenegotiationInfo: true,
5640 },
5641 },
5642 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005643 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005644 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005645 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005646 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005647 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005648 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005649 },
5650 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005651 renegotiate: 1,
5652 flags: []string{
5653 "-renegotiate-freely",
5654 "-expect-total-renegotiations", "1",
5655 },
David Benjamincdea40c2015-03-19 14:09:43 -04005656 })
5657 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005658 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005659 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005661 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005662 Bugs: ProtocolBugs{
5663 EmptyRenegotiationInfo: true,
5664 },
5665 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005666 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005667 shouldFail: true,
5668 expectedError: ":RENEGOTIATION_MISMATCH:",
5669 })
5670 testCases = append(testCases, testCase{
5671 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005672 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005673 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005674 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005675 Bugs: ProtocolBugs{
5676 BadRenegotiationInfo: true,
5677 },
5678 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005679 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005680 shouldFail: true,
5681 expectedError: ":RENEGOTIATION_MISMATCH:",
5682 })
5683 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005684 name: "Renegotiate-Client-Downgrade",
5685 renegotiate: 1,
5686 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005687 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005688 Bugs: ProtocolBugs{
5689 NoRenegotiationInfoAfterInitial: true,
5690 },
5691 },
5692 flags: []string{"-renegotiate-freely"},
5693 shouldFail: true,
5694 expectedError: ":RENEGOTIATION_MISMATCH:",
5695 })
5696 testCases = append(testCases, testCase{
5697 name: "Renegotiate-Client-Upgrade",
5698 renegotiate: 1,
5699 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005700 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005701 Bugs: ProtocolBugs{
5702 NoRenegotiationInfoInInitial: true,
5703 },
5704 },
5705 flags: []string{"-renegotiate-freely"},
5706 shouldFail: true,
5707 expectedError: ":RENEGOTIATION_MISMATCH:",
5708 })
5709 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005710 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005711 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005712 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005713 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005714 Bugs: ProtocolBugs{
5715 NoRenegotiationInfo: true,
5716 },
5717 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005718 flags: []string{
5719 "-renegotiate-freely",
5720 "-expect-total-renegotiations", "1",
5721 },
David Benjamincff0b902015-05-15 23:09:47 -04005722 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005723
5724 // Test that the server may switch ciphers on renegotiation without
5725 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005726 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005727 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005728 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005729 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005730 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005731 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005732 },
5733 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005734 flags: []string{
5735 "-renegotiate-freely",
5736 "-expect-total-renegotiations", "1",
5737 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005738 })
5739 testCases = append(testCases, testCase{
5740 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005741 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005742 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005743 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005744 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5745 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005746 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005747 flags: []string{
5748 "-renegotiate-freely",
5749 "-expect-total-renegotiations", "1",
5750 },
David Benjaminb16346b2015-04-08 19:16:58 -04005751 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005752
5753 // Test that the server may not switch versions on renegotiation.
5754 testCases = append(testCases, testCase{
5755 name: "Renegotiate-Client-SwitchVersion",
5756 config: Config{
5757 MaxVersion: VersionTLS12,
5758 // Pick a cipher which exists at both versions.
5759 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5760 Bugs: ProtocolBugs{
5761 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05005762 // Avoid failing early at the record layer.
5763 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04005764 },
5765 },
5766 renegotiate: 1,
5767 flags: []string{
5768 "-renegotiate-freely",
5769 "-expect-total-renegotiations", "1",
5770 },
5771 shouldFail: true,
5772 expectedError: ":WRONG_SSL_VERSION:",
5773 })
5774
David Benjaminb16346b2015-04-08 19:16:58 -04005775 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005776 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005777 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005778 config: Config{
5779 MaxVersion: VersionTLS10,
5780 Bugs: ProtocolBugs{
5781 RequireSameRenegoClientVersion: true,
5782 },
5783 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005784 flags: []string{
5785 "-renegotiate-freely",
5786 "-expect-total-renegotiations", "1",
5787 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005788 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005789 testCases = append(testCases, testCase{
5790 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005791 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005792 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005793 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005794 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5795 NextProtos: []string{"foo"},
5796 },
5797 flags: []string{
5798 "-false-start",
5799 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005800 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005801 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005802 },
5803 shimWritesFirst: true,
5804 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005805
5806 // Client-side renegotiation controls.
5807 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005808 name: "Renegotiate-Client-Forbidden-1",
5809 config: Config{
5810 MaxVersion: VersionTLS12,
5811 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005812 renegotiate: 1,
5813 shouldFail: true,
5814 expectedError: ":NO_RENEGOTIATION:",
5815 expectedLocalError: "remote error: no renegotiation",
5816 })
5817 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005818 name: "Renegotiate-Client-Once-1",
5819 config: Config{
5820 MaxVersion: VersionTLS12,
5821 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005822 renegotiate: 1,
5823 flags: []string{
5824 "-renegotiate-once",
5825 "-expect-total-renegotiations", "1",
5826 },
5827 })
5828 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005829 name: "Renegotiate-Client-Freely-1",
5830 config: Config{
5831 MaxVersion: VersionTLS12,
5832 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005833 renegotiate: 1,
5834 flags: []string{
5835 "-renegotiate-freely",
5836 "-expect-total-renegotiations", "1",
5837 },
5838 })
5839 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005840 name: "Renegotiate-Client-Once-2",
5841 config: Config{
5842 MaxVersion: VersionTLS12,
5843 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005844 renegotiate: 2,
5845 flags: []string{"-renegotiate-once"},
5846 shouldFail: true,
5847 expectedError: ":NO_RENEGOTIATION:",
5848 expectedLocalError: "remote error: no renegotiation",
5849 })
5850 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005851 name: "Renegotiate-Client-Freely-2",
5852 config: Config{
5853 MaxVersion: VersionTLS12,
5854 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005855 renegotiate: 2,
5856 flags: []string{
5857 "-renegotiate-freely",
5858 "-expect-total-renegotiations", "2",
5859 },
5860 })
Adam Langley27a0d082015-11-03 13:34:10 -08005861 testCases = append(testCases, testCase{
5862 name: "Renegotiate-Client-NoIgnore",
5863 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005864 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005865 Bugs: ProtocolBugs{
5866 SendHelloRequestBeforeEveryAppDataRecord: true,
5867 },
5868 },
5869 shouldFail: true,
5870 expectedError: ":NO_RENEGOTIATION:",
5871 })
5872 testCases = append(testCases, testCase{
5873 name: "Renegotiate-Client-Ignore",
5874 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005875 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005876 Bugs: ProtocolBugs{
5877 SendHelloRequestBeforeEveryAppDataRecord: true,
5878 },
5879 },
5880 flags: []string{
5881 "-renegotiate-ignore",
5882 "-expect-total-renegotiations", "0",
5883 },
5884 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005885
David Benjamin34941c02016-10-08 11:45:31 -04005886 // Renegotiation is not allowed at SSL 3.0.
5887 testCases = append(testCases, testCase{
5888 name: "Renegotiate-Client-SSL3",
5889 config: Config{
5890 MaxVersion: VersionSSL30,
5891 },
5892 renegotiate: 1,
5893 flags: []string{
5894 "-renegotiate-freely",
5895 "-expect-total-renegotiations", "1",
5896 },
5897 shouldFail: true,
5898 expectedError: ":NO_RENEGOTIATION:",
5899 expectedLocalError: "remote error: no renegotiation",
5900 })
5901
David Benjamin397c8e62016-07-08 14:14:36 -07005902 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005903 testCases = append(testCases, testCase{
5904 name: "StrayHelloRequest",
5905 config: Config{
5906 MaxVersion: VersionTLS12,
5907 Bugs: ProtocolBugs{
5908 SendHelloRequestBeforeEveryHandshakeMessage: true,
5909 },
5910 },
5911 })
5912 testCases = append(testCases, testCase{
5913 name: "StrayHelloRequest-Packed",
5914 config: Config{
5915 MaxVersion: VersionTLS12,
5916 Bugs: ProtocolBugs{
5917 PackHandshakeFlight: true,
5918 SendHelloRequestBeforeEveryHandshakeMessage: true,
5919 },
5920 },
5921 })
5922
David Benjamin12d2c482016-07-24 10:56:51 -04005923 // Test renegotiation works if HelloRequest and server Finished come in
5924 // the same record.
5925 testCases = append(testCases, testCase{
5926 name: "Renegotiate-Client-Packed",
5927 config: Config{
5928 MaxVersion: VersionTLS12,
5929 Bugs: ProtocolBugs{
5930 PackHandshakeFlight: true,
5931 PackHelloRequestWithFinished: true,
5932 },
5933 },
5934 renegotiate: 1,
5935 flags: []string{
5936 "-renegotiate-freely",
5937 "-expect-total-renegotiations", "1",
5938 },
5939 })
5940
David Benjamin397c8e62016-07-08 14:14:36 -07005941 // Renegotiation is forbidden in TLS 1.3.
5942 testCases = append(testCases, testCase{
5943 name: "Renegotiate-Client-TLS13",
5944 config: Config{
5945 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005946 Bugs: ProtocolBugs{
5947 SendHelloRequestBeforeEveryAppDataRecord: true,
5948 },
David Benjamin397c8e62016-07-08 14:14:36 -07005949 },
David Benjamin397c8e62016-07-08 14:14:36 -07005950 flags: []string{
5951 "-renegotiate-freely",
5952 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005953 shouldFail: true,
5954 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005955 })
5956
5957 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5958 testCases = append(testCases, testCase{
5959 name: "StrayHelloRequest-TLS13",
5960 config: Config{
5961 MaxVersion: VersionTLS13,
5962 Bugs: ProtocolBugs{
5963 SendHelloRequestBeforeEveryHandshakeMessage: true,
5964 },
5965 },
5966 shouldFail: true,
5967 expectedError: ":UNEXPECTED_MESSAGE:",
5968 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005969}
5970
David Benjamin5e961c12014-11-07 01:48:35 -05005971func addDTLSReplayTests() {
5972 // Test that sequence number replays are detected.
5973 testCases = append(testCases, testCase{
5974 protocol: dtls,
5975 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005976 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005977 replayWrites: true,
5978 })
5979
David Benjamin8e6db492015-07-25 18:29:23 -04005980 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005981 // than the retransmit window.
5982 testCases = append(testCases, testCase{
5983 protocol: dtls,
5984 name: "DTLS-Replay-LargeGaps",
5985 config: Config{
5986 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005987 SequenceNumberMapping: func(in uint64) uint64 {
5988 return in * 127
5989 },
David Benjamin5e961c12014-11-07 01:48:35 -05005990 },
5991 },
David Benjamin8e6db492015-07-25 18:29:23 -04005992 messageCount: 200,
5993 replayWrites: true,
5994 })
5995
5996 // Test the incoming sequence number changing non-monotonically.
5997 testCases = append(testCases, testCase{
5998 protocol: dtls,
5999 name: "DTLS-Replay-NonMonotonic",
6000 config: Config{
6001 Bugs: ProtocolBugs{
6002 SequenceNumberMapping: func(in uint64) uint64 {
6003 return in ^ 31
6004 },
6005 },
6006 },
6007 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006008 replayWrites: true,
6009 })
6010}
6011
Nick Harper60edffd2016-06-21 15:19:24 -07006012var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006013 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006014 id signatureAlgorithm
6015 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006016}{
Nick Harper60edffd2016-06-21 15:19:24 -07006017 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6018 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6019 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6020 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006021 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006022 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6023 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6024 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006025 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6026 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6027 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006028 // Tests for key types prior to TLS 1.2.
6029 {"RSA", 0, testCertRSA},
6030 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006031}
6032
Nick Harper60edffd2016-06-21 15:19:24 -07006033const fakeSigAlg1 signatureAlgorithm = 0x2a01
6034const fakeSigAlg2 signatureAlgorithm = 0xff01
6035
6036func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006037 // Not all ciphers involve a signature. Advertise a list which gives all
6038 // versions a signing cipher.
6039 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006040 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006041 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6042 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6043 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6044 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6045 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6046 }
6047
David Benjaminca3d5452016-07-14 12:51:01 -04006048 var allAlgorithms []signatureAlgorithm
6049 for _, alg := range testSignatureAlgorithms {
6050 if alg.id != 0 {
6051 allAlgorithms = append(allAlgorithms, alg.id)
6052 }
6053 }
6054
Nick Harper60edffd2016-06-21 15:19:24 -07006055 // Make sure each signature algorithm works. Include some fake values in
6056 // the list and ensure they're ignored.
6057 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006058 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006059 if (ver.version < VersionTLS12) != (alg.id == 0) {
6060 continue
6061 }
6062
6063 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6064 // or remove it in C.
6065 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006066 continue
6067 }
Nick Harper60edffd2016-06-21 15:19:24 -07006068
David Benjamin3ef76972016-10-17 17:59:54 -04006069 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006070 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006071 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006072 shouldSignFail = true
6073 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006074 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006075 // RSA-PKCS1 does not exist in TLS 1.3.
6076 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006077 shouldSignFail = true
6078 shouldVerifyFail = true
6079 }
6080
6081 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6082 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6083 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006084 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006085
6086 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006087 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006088 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006089 }
6090 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006091 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006092 }
David Benjamin000800a2014-11-14 01:43:59 -05006093
David Benjamin1fb125c2016-07-08 18:52:12 -07006094 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006095
David Benjamin7a41d372016-07-09 11:21:54 -07006096 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006097 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006098 config: Config{
6099 MaxVersion: ver.version,
6100 ClientAuth: RequireAnyClientCert,
6101 VerifySignatureAlgorithms: []signatureAlgorithm{
6102 fakeSigAlg1,
6103 alg.id,
6104 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006105 },
David Benjamin7a41d372016-07-09 11:21:54 -07006106 },
6107 flags: []string{
6108 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6109 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6110 "-enable-all-curves",
6111 },
David Benjamin3ef76972016-10-17 17:59:54 -04006112 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006113 expectedError: signError,
6114 expectedPeerSignatureAlgorithm: alg.id,
6115 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006116
David Benjamin7a41d372016-07-09 11:21:54 -07006117 testCases = append(testCases, testCase{
6118 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006119 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006120 config: Config{
6121 MaxVersion: ver.version,
6122 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6123 SignSignatureAlgorithms: []signatureAlgorithm{
6124 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006125 },
David Benjamin7a41d372016-07-09 11:21:54 -07006126 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006127 SkipECDSACurveCheck: shouldVerifyFail,
6128 IgnoreSignatureVersionChecks: shouldVerifyFail,
6129 // Some signature algorithms may not be advertised.
6130 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006131 },
David Benjamin7a41d372016-07-09 11:21:54 -07006132 },
6133 flags: []string{
6134 "-require-any-client-certificate",
6135 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6136 "-enable-all-curves",
6137 },
David Benjamin3ef76972016-10-17 17:59:54 -04006138 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006139 expectedError: verifyError,
6140 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006141
6142 testCases = append(testCases, testCase{
6143 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006144 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006145 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006146 MaxVersion: ver.version,
6147 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006148 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006149 fakeSigAlg1,
6150 alg.id,
6151 fakeSigAlg2,
6152 },
6153 },
6154 flags: []string{
6155 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6156 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6157 "-enable-all-curves",
6158 },
David Benjamin3ef76972016-10-17 17:59:54 -04006159 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006160 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006161 expectedPeerSignatureAlgorithm: alg.id,
6162 })
6163
6164 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006165 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006166 config: Config{
6167 MaxVersion: ver.version,
6168 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006169 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006170 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006171 alg.id,
6172 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006173 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006174 SkipECDSACurveCheck: shouldVerifyFail,
6175 IgnoreSignatureVersionChecks: shouldVerifyFail,
6176 // Some signature algorithms may not be advertised.
6177 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006178 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006179 },
6180 flags: []string{
6181 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6182 "-enable-all-curves",
6183 },
David Benjamin3ef76972016-10-17 17:59:54 -04006184 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006185 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006186 })
David Benjamin5208fd42016-07-13 21:43:25 -04006187
David Benjamin3ef76972016-10-17 17:59:54 -04006188 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006189 testCases = append(testCases, testCase{
6190 testType: serverTest,
6191 name: "ClientAuth-InvalidSignature" + suffix,
6192 config: Config{
6193 MaxVersion: ver.version,
6194 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6195 SignSignatureAlgorithms: []signatureAlgorithm{
6196 alg.id,
6197 },
6198 Bugs: ProtocolBugs{
6199 InvalidSignature: true,
6200 },
6201 },
6202 flags: []string{
6203 "-require-any-client-certificate",
6204 "-enable-all-curves",
6205 },
6206 shouldFail: true,
6207 expectedError: ":BAD_SIGNATURE:",
6208 })
6209
6210 testCases = append(testCases, testCase{
6211 name: "ServerAuth-InvalidSignature" + suffix,
6212 config: Config{
6213 MaxVersion: ver.version,
6214 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6215 CipherSuites: signingCiphers,
6216 SignSignatureAlgorithms: []signatureAlgorithm{
6217 alg.id,
6218 },
6219 Bugs: ProtocolBugs{
6220 InvalidSignature: true,
6221 },
6222 },
6223 flags: []string{"-enable-all-curves"},
6224 shouldFail: true,
6225 expectedError: ":BAD_SIGNATURE:",
6226 })
6227 }
David Benjaminca3d5452016-07-14 12:51:01 -04006228
David Benjamin3ef76972016-10-17 17:59:54 -04006229 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006230 testCases = append(testCases, testCase{
6231 name: "ClientAuth-Sign-Negotiate" + suffix,
6232 config: Config{
6233 MaxVersion: ver.version,
6234 ClientAuth: RequireAnyClientCert,
6235 VerifySignatureAlgorithms: allAlgorithms,
6236 },
6237 flags: []string{
6238 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6239 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6240 "-enable-all-curves",
6241 "-signing-prefs", strconv.Itoa(int(alg.id)),
6242 },
6243 expectedPeerSignatureAlgorithm: alg.id,
6244 })
6245
6246 testCases = append(testCases, testCase{
6247 testType: serverTest,
6248 name: "ServerAuth-Sign-Negotiate" + suffix,
6249 config: Config{
6250 MaxVersion: ver.version,
6251 CipherSuites: signingCiphers,
6252 VerifySignatureAlgorithms: allAlgorithms,
6253 },
6254 flags: []string{
6255 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6256 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6257 "-enable-all-curves",
6258 "-signing-prefs", strconv.Itoa(int(alg.id)),
6259 },
6260 expectedPeerSignatureAlgorithm: alg.id,
6261 })
6262 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006263 }
David Benjamin000800a2014-11-14 01:43:59 -05006264 }
6265
Nick Harper60edffd2016-06-21 15:19:24 -07006266 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006267 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006268 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006269 config: Config{
6270 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006271 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006272 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006273 signatureECDSAWithP521AndSHA512,
6274 signatureRSAPKCS1WithSHA384,
6275 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006276 },
6277 },
6278 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006279 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6280 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006281 },
Nick Harper60edffd2016-06-21 15:19:24 -07006282 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006283 })
6284
6285 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006286 name: "ClientAuth-SignatureType-TLS13",
6287 config: Config{
6288 ClientAuth: RequireAnyClientCert,
6289 MaxVersion: VersionTLS13,
6290 VerifySignatureAlgorithms: []signatureAlgorithm{
6291 signatureECDSAWithP521AndSHA512,
6292 signatureRSAPKCS1WithSHA384,
6293 signatureRSAPSSWithSHA384,
6294 signatureECDSAWithSHA1,
6295 },
6296 },
6297 flags: []string{
6298 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6299 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6300 },
6301 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6302 })
6303
6304 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006305 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006306 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006307 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006308 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006309 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006310 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006311 signatureECDSAWithP521AndSHA512,
6312 signatureRSAPKCS1WithSHA384,
6313 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006314 },
6315 },
Nick Harper60edffd2016-06-21 15:19:24 -07006316 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006317 })
6318
Steven Valdez143e8b32016-07-11 13:19:03 -04006319 testCases = append(testCases, testCase{
6320 testType: serverTest,
6321 name: "ServerAuth-SignatureType-TLS13",
6322 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006323 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006324 VerifySignatureAlgorithms: []signatureAlgorithm{
6325 signatureECDSAWithP521AndSHA512,
6326 signatureRSAPKCS1WithSHA384,
6327 signatureRSAPSSWithSHA384,
6328 signatureECDSAWithSHA1,
6329 },
6330 },
6331 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6332 })
6333
David Benjamina95e9f32016-07-08 16:28:04 -07006334 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006335 testCases = append(testCases, testCase{
6336 testType: serverTest,
6337 name: "Verify-ClientAuth-SignatureType",
6338 config: Config{
6339 MaxVersion: VersionTLS12,
6340 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006341 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006342 signatureRSAPKCS1WithSHA256,
6343 },
6344 Bugs: ProtocolBugs{
6345 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6346 },
6347 },
6348 flags: []string{
6349 "-require-any-client-certificate",
6350 },
6351 shouldFail: true,
6352 expectedError: ":WRONG_SIGNATURE_TYPE:",
6353 })
6354
6355 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006356 testType: serverTest,
6357 name: "Verify-ClientAuth-SignatureType-TLS13",
6358 config: Config{
6359 MaxVersion: VersionTLS13,
6360 Certificates: []Certificate{rsaCertificate},
6361 SignSignatureAlgorithms: []signatureAlgorithm{
6362 signatureRSAPSSWithSHA256,
6363 },
6364 Bugs: ProtocolBugs{
6365 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6366 },
6367 },
6368 flags: []string{
6369 "-require-any-client-certificate",
6370 },
6371 shouldFail: true,
6372 expectedError: ":WRONG_SIGNATURE_TYPE:",
6373 })
6374
6375 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006376 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006377 config: Config{
6378 MaxVersion: VersionTLS12,
6379 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006380 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006381 signatureRSAPKCS1WithSHA256,
6382 },
6383 Bugs: ProtocolBugs{
6384 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6385 },
6386 },
6387 shouldFail: true,
6388 expectedError: ":WRONG_SIGNATURE_TYPE:",
6389 })
6390
Steven Valdez143e8b32016-07-11 13:19:03 -04006391 testCases = append(testCases, testCase{
6392 name: "Verify-ServerAuth-SignatureType-TLS13",
6393 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006394 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006395 SignSignatureAlgorithms: []signatureAlgorithm{
6396 signatureRSAPSSWithSHA256,
6397 },
6398 Bugs: ProtocolBugs{
6399 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6400 },
6401 },
6402 shouldFail: true,
6403 expectedError: ":WRONG_SIGNATURE_TYPE:",
6404 })
6405
David Benjamin51dd7d62016-07-08 16:07:01 -07006406 // Test that, if the list is missing, the peer falls back to SHA-1 in
6407 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006408 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006409 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006411 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006412 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006413 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006414 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006415 },
6416 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006417 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006418 },
6419 },
6420 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006421 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6422 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006423 },
6424 })
6425
6426 testCases = append(testCases, testCase{
6427 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006428 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006429 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006430 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006431 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006432 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006433 },
6434 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006435 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006436 },
6437 },
David Benjaminee32bea2016-08-17 13:36:44 -04006438 flags: []string{
6439 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6440 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6441 },
6442 })
6443
6444 testCases = append(testCases, testCase{
6445 name: "ClientAuth-SHA1-Fallback-ECDSA",
6446 config: Config{
6447 MaxVersion: VersionTLS12,
6448 ClientAuth: RequireAnyClientCert,
6449 VerifySignatureAlgorithms: []signatureAlgorithm{
6450 signatureECDSAWithSHA1,
6451 },
6452 Bugs: ProtocolBugs{
6453 NoSignatureAlgorithms: true,
6454 },
6455 },
6456 flags: []string{
6457 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6458 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6459 },
6460 })
6461
6462 testCases = append(testCases, testCase{
6463 testType: serverTest,
6464 name: "ServerAuth-SHA1-Fallback-ECDSA",
6465 config: Config{
6466 MaxVersion: VersionTLS12,
6467 VerifySignatureAlgorithms: []signatureAlgorithm{
6468 signatureECDSAWithSHA1,
6469 },
6470 Bugs: ProtocolBugs{
6471 NoSignatureAlgorithms: true,
6472 },
6473 },
6474 flags: []string{
6475 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6476 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6477 },
David Benjamin000800a2014-11-14 01:43:59 -05006478 })
David Benjamin72dc7832015-03-16 17:49:43 -04006479
David Benjamin51dd7d62016-07-08 16:07:01 -07006480 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006481 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006482 config: Config{
6483 MaxVersion: VersionTLS13,
6484 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006485 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006486 signatureRSAPKCS1WithSHA1,
6487 },
6488 Bugs: ProtocolBugs{
6489 NoSignatureAlgorithms: true,
6490 },
6491 },
6492 flags: []string{
6493 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6494 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6495 },
David Benjamin48901652016-08-01 12:12:47 -04006496 shouldFail: true,
6497 // An empty CertificateRequest signature algorithm list is a
6498 // syntax error in TLS 1.3.
6499 expectedError: ":DECODE_ERROR:",
6500 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006501 })
6502
6503 testCases = append(testCases, testCase{
6504 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006505 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006506 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006507 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006508 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006509 signatureRSAPKCS1WithSHA1,
6510 },
6511 Bugs: ProtocolBugs{
6512 NoSignatureAlgorithms: true,
6513 },
6514 },
6515 shouldFail: true,
6516 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6517 })
6518
David Benjaminb62d2872016-07-18 14:55:02 +02006519 // Test that hash preferences are enforced. BoringSSL does not implement
6520 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006521 testCases = append(testCases, testCase{
6522 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006523 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006524 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006525 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006526 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006527 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006528 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006529 },
6530 Bugs: ProtocolBugs{
6531 IgnorePeerSignatureAlgorithmPreferences: true,
6532 },
6533 },
6534 flags: []string{"-require-any-client-certificate"},
6535 shouldFail: true,
6536 expectedError: ":WRONG_SIGNATURE_TYPE:",
6537 })
6538
6539 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006540 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006541 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006542 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006543 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006544 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006545 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006546 },
6547 Bugs: ProtocolBugs{
6548 IgnorePeerSignatureAlgorithmPreferences: true,
6549 },
6550 },
6551 shouldFail: true,
6552 expectedError: ":WRONG_SIGNATURE_TYPE:",
6553 })
David Benjaminb62d2872016-07-18 14:55:02 +02006554 testCases = append(testCases, testCase{
6555 testType: serverTest,
6556 name: "ClientAuth-Enforced-TLS13",
6557 config: Config{
6558 MaxVersion: VersionTLS13,
6559 Certificates: []Certificate{rsaCertificate},
6560 SignSignatureAlgorithms: []signatureAlgorithm{
6561 signatureRSAPKCS1WithMD5,
6562 },
6563 Bugs: ProtocolBugs{
6564 IgnorePeerSignatureAlgorithmPreferences: true,
6565 IgnoreSignatureVersionChecks: true,
6566 },
6567 },
6568 flags: []string{"-require-any-client-certificate"},
6569 shouldFail: true,
6570 expectedError: ":WRONG_SIGNATURE_TYPE:",
6571 })
6572
6573 testCases = append(testCases, testCase{
6574 name: "ServerAuth-Enforced-TLS13",
6575 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006576 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006577 SignSignatureAlgorithms: []signatureAlgorithm{
6578 signatureRSAPKCS1WithMD5,
6579 },
6580 Bugs: ProtocolBugs{
6581 IgnorePeerSignatureAlgorithmPreferences: true,
6582 IgnoreSignatureVersionChecks: true,
6583 },
6584 },
6585 shouldFail: true,
6586 expectedError: ":WRONG_SIGNATURE_TYPE:",
6587 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006588
6589 // Test that the agreed upon digest respects the client preferences and
6590 // the server digests.
6591 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006592 name: "NoCommonAlgorithms-Digests",
6593 config: Config{
6594 MaxVersion: VersionTLS12,
6595 ClientAuth: RequireAnyClientCert,
6596 VerifySignatureAlgorithms: []signatureAlgorithm{
6597 signatureRSAPKCS1WithSHA512,
6598 signatureRSAPKCS1WithSHA1,
6599 },
6600 },
6601 flags: []string{
6602 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6603 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6604 "-digest-prefs", "SHA256",
6605 },
6606 shouldFail: true,
6607 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6608 })
6609 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006610 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006611 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006612 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006613 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006614 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006615 signatureRSAPKCS1WithSHA512,
6616 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006617 },
6618 },
6619 flags: []string{
6620 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6621 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006622 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006623 },
David Benjaminca3d5452016-07-14 12:51:01 -04006624 shouldFail: true,
6625 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6626 })
6627 testCases = append(testCases, testCase{
6628 name: "NoCommonAlgorithms-TLS13",
6629 config: Config{
6630 MaxVersion: VersionTLS13,
6631 ClientAuth: RequireAnyClientCert,
6632 VerifySignatureAlgorithms: []signatureAlgorithm{
6633 signatureRSAPSSWithSHA512,
6634 signatureRSAPSSWithSHA384,
6635 },
6636 },
6637 flags: []string{
6638 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6639 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6640 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6641 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006642 shouldFail: true,
6643 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006644 })
6645 testCases = append(testCases, testCase{
6646 name: "Agree-Digest-SHA256",
6647 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006648 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006649 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006650 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006651 signatureRSAPKCS1WithSHA1,
6652 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006653 },
6654 },
6655 flags: []string{
6656 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6657 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006658 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006659 },
Nick Harper60edffd2016-06-21 15:19:24 -07006660 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006661 })
6662 testCases = append(testCases, testCase{
6663 name: "Agree-Digest-SHA1",
6664 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006665 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006666 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006667 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006668 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006669 },
6670 },
6671 flags: []string{
6672 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6673 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006674 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006675 },
Nick Harper60edffd2016-06-21 15:19:24 -07006676 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006677 })
6678 testCases = append(testCases, testCase{
6679 name: "Agree-Digest-Default",
6680 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006681 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006682 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006683 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006684 signatureRSAPKCS1WithSHA256,
6685 signatureECDSAWithP256AndSHA256,
6686 signatureRSAPKCS1WithSHA1,
6687 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006688 },
6689 },
6690 flags: []string{
6691 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6692 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6693 },
Nick Harper60edffd2016-06-21 15:19:24 -07006694 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006695 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006696
David Benjaminca3d5452016-07-14 12:51:01 -04006697 // Test that the signing preference list may include extra algorithms
6698 // without negotiation problems.
6699 testCases = append(testCases, testCase{
6700 testType: serverTest,
6701 name: "FilterExtraAlgorithms",
6702 config: Config{
6703 MaxVersion: VersionTLS12,
6704 VerifySignatureAlgorithms: []signatureAlgorithm{
6705 signatureRSAPKCS1WithSHA256,
6706 },
6707 },
6708 flags: []string{
6709 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6710 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6711 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6712 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6713 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6714 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6715 },
6716 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6717 })
6718
David Benjamin4c3ddf72016-06-29 18:13:53 -04006719 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6720 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006721 testCases = append(testCases, testCase{
6722 name: "CheckLeafCurve",
6723 config: Config{
6724 MaxVersion: VersionTLS12,
6725 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006726 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006727 },
6728 flags: []string{"-p384-only"},
6729 shouldFail: true,
6730 expectedError: ":BAD_ECC_CERT:",
6731 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006732
6733 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6734 testCases = append(testCases, testCase{
6735 name: "CheckLeafCurve-TLS13",
6736 config: Config{
6737 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006738 Certificates: []Certificate{ecdsaP256Certificate},
6739 },
6740 flags: []string{"-p384-only"},
6741 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006742
6743 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6744 testCases = append(testCases, testCase{
6745 name: "ECDSACurveMismatch-Verify-TLS12",
6746 config: Config{
6747 MaxVersion: VersionTLS12,
6748 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6749 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006750 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006751 signatureECDSAWithP384AndSHA384,
6752 },
6753 },
6754 })
6755
6756 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6757 testCases = append(testCases, testCase{
6758 name: "ECDSACurveMismatch-Verify-TLS13",
6759 config: Config{
6760 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006761 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006762 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006763 signatureECDSAWithP384AndSHA384,
6764 },
6765 Bugs: ProtocolBugs{
6766 SkipECDSACurveCheck: true,
6767 },
6768 },
6769 shouldFail: true,
6770 expectedError: ":WRONG_SIGNATURE_TYPE:",
6771 })
6772
6773 // Signature algorithm selection in TLS 1.3 should take the curve into
6774 // account.
6775 testCases = append(testCases, testCase{
6776 testType: serverTest,
6777 name: "ECDSACurveMismatch-Sign-TLS13",
6778 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006779 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006780 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006781 signatureECDSAWithP384AndSHA384,
6782 signatureECDSAWithP256AndSHA256,
6783 },
6784 },
6785 flags: []string{
6786 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6787 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6788 },
6789 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6790 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006791
6792 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6793 // server does not attempt to sign in that case.
6794 testCases = append(testCases, testCase{
6795 testType: serverTest,
6796 name: "RSA-PSS-Large",
6797 config: Config{
6798 MaxVersion: VersionTLS13,
6799 VerifySignatureAlgorithms: []signatureAlgorithm{
6800 signatureRSAPSSWithSHA512,
6801 },
6802 },
6803 flags: []string{
6804 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6805 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6806 },
6807 shouldFail: true,
6808 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6809 })
David Benjamin57e929f2016-08-30 00:30:38 -04006810
6811 // Test that RSA-PSS is enabled by default for TLS 1.2.
6812 testCases = append(testCases, testCase{
6813 testType: clientTest,
6814 name: "RSA-PSS-Default-Verify",
6815 config: Config{
6816 MaxVersion: VersionTLS12,
6817 SignSignatureAlgorithms: []signatureAlgorithm{
6818 signatureRSAPSSWithSHA256,
6819 },
6820 },
6821 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6822 })
6823
6824 testCases = append(testCases, testCase{
6825 testType: serverTest,
6826 name: "RSA-PSS-Default-Sign",
6827 config: Config{
6828 MaxVersion: VersionTLS12,
6829 VerifySignatureAlgorithms: []signatureAlgorithm{
6830 signatureRSAPSSWithSHA256,
6831 },
6832 },
6833 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6834 })
David Benjamin000800a2014-11-14 01:43:59 -05006835}
6836
David Benjamin83f90402015-01-27 01:09:43 -05006837// timeouts is the retransmit schedule for BoringSSL. It doubles and
6838// caps at 60 seconds. On the 13th timeout, it gives up.
6839var timeouts = []time.Duration{
6840 1 * time.Second,
6841 2 * time.Second,
6842 4 * time.Second,
6843 8 * time.Second,
6844 16 * time.Second,
6845 32 * time.Second,
6846 60 * time.Second,
6847 60 * time.Second,
6848 60 * time.Second,
6849 60 * time.Second,
6850 60 * time.Second,
6851 60 * time.Second,
6852 60 * time.Second,
6853}
6854
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006855// shortTimeouts is an alternate set of timeouts which would occur if the
6856// initial timeout duration was set to 250ms.
6857var shortTimeouts = []time.Duration{
6858 250 * time.Millisecond,
6859 500 * time.Millisecond,
6860 1 * time.Second,
6861 2 * time.Second,
6862 4 * time.Second,
6863 8 * time.Second,
6864 16 * time.Second,
6865 32 * time.Second,
6866 60 * time.Second,
6867 60 * time.Second,
6868 60 * time.Second,
6869 60 * time.Second,
6870 60 * time.Second,
6871}
6872
David Benjamin83f90402015-01-27 01:09:43 -05006873func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006874 // These tests work by coordinating some behavior on both the shim and
6875 // the runner.
6876 //
6877 // TimeoutSchedule configures the runner to send a series of timeout
6878 // opcodes to the shim (see packetAdaptor) immediately before reading
6879 // each peer handshake flight N. The timeout opcode both simulates a
6880 // timeout in the shim and acts as a synchronization point to help the
6881 // runner bracket each handshake flight.
6882 //
6883 // We assume the shim does not read from the channel eagerly. It must
6884 // first wait until it has sent flight N and is ready to receive
6885 // handshake flight N+1. At this point, it will process the timeout
6886 // opcode. It must then immediately respond with a timeout ACK and act
6887 // as if the shim was idle for the specified amount of time.
6888 //
6889 // The runner then drops all packets received before the ACK and
6890 // continues waiting for flight N. This ordering results in one attempt
6891 // at sending flight N to be dropped. For the test to complete, the
6892 // shim must send flight N again, testing that the shim implements DTLS
6893 // retransmit on a timeout.
6894
Steven Valdez143e8b32016-07-11 13:19:03 -04006895 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006896 // likely be more epochs to cross and the final message's retransmit may
6897 // be more complex.
6898
David Benjamin585d7a42016-06-02 14:58:00 -04006899 for _, async := range []bool{true, false} {
6900 var tests []testCase
6901
6902 // Test that this is indeed the timeout schedule. Stress all
6903 // four patterns of handshake.
6904 for i := 1; i < len(timeouts); i++ {
6905 number := strconv.Itoa(i)
6906 tests = append(tests, testCase{
6907 protocol: dtls,
6908 name: "DTLS-Retransmit-Client-" + number,
6909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006910 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006911 Bugs: ProtocolBugs{
6912 TimeoutSchedule: timeouts[:i],
6913 },
6914 },
6915 resumeSession: true,
6916 })
6917 tests = append(tests, testCase{
6918 protocol: dtls,
6919 testType: serverTest,
6920 name: "DTLS-Retransmit-Server-" + number,
6921 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006922 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006923 Bugs: ProtocolBugs{
6924 TimeoutSchedule: timeouts[:i],
6925 },
6926 },
6927 resumeSession: true,
6928 })
6929 }
6930
6931 // Test that exceeding the timeout schedule hits a read
6932 // timeout.
6933 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006934 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006935 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006937 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006938 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006939 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006940 },
6941 },
6942 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006943 shouldFail: true,
6944 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006945 })
David Benjamin585d7a42016-06-02 14:58:00 -04006946
6947 if async {
6948 // Test that timeout handling has a fudge factor, due to API
6949 // problems.
6950 tests = append(tests, testCase{
6951 protocol: dtls,
6952 name: "DTLS-Retransmit-Fudge",
6953 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006954 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006955 Bugs: ProtocolBugs{
6956 TimeoutSchedule: []time.Duration{
6957 timeouts[0] - 10*time.Millisecond,
6958 },
6959 },
6960 },
6961 resumeSession: true,
6962 })
6963 }
6964
6965 // Test that the final Finished retransmitting isn't
6966 // duplicated if the peer badly fragments everything.
6967 tests = append(tests, testCase{
6968 testType: serverTest,
6969 protocol: dtls,
6970 name: "DTLS-Retransmit-Fragmented",
6971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006972 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006973 Bugs: ProtocolBugs{
6974 TimeoutSchedule: []time.Duration{timeouts[0]},
6975 MaxHandshakeRecordLength: 2,
6976 },
6977 },
6978 })
6979
6980 // Test the timeout schedule when a shorter initial timeout duration is set.
6981 tests = append(tests, testCase{
6982 protocol: dtls,
6983 name: "DTLS-Retransmit-Short-Client",
6984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006985 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006986 Bugs: ProtocolBugs{
6987 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6988 },
6989 },
6990 resumeSession: true,
6991 flags: []string{"-initial-timeout-duration-ms", "250"},
6992 })
6993 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006994 protocol: dtls,
6995 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006996 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006998 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006999 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007000 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007001 },
7002 },
7003 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007004 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007005 })
David Benjamin585d7a42016-06-02 14:58:00 -04007006
7007 for _, test := range tests {
7008 if async {
7009 test.name += "-Async"
7010 test.flags = append(test.flags, "-async")
7011 }
7012
7013 testCases = append(testCases, test)
7014 }
David Benjamin83f90402015-01-27 01:09:43 -05007015 }
David Benjamin83f90402015-01-27 01:09:43 -05007016}
7017
David Benjaminc565ebb2015-04-03 04:06:36 -04007018func addExportKeyingMaterialTests() {
7019 for _, vers := range tlsVersions {
7020 if vers.version == VersionSSL30 {
7021 continue
7022 }
7023 testCases = append(testCases, testCase{
7024 name: "ExportKeyingMaterial-" + vers.name,
7025 config: Config{
7026 MaxVersion: vers.version,
7027 },
7028 exportKeyingMaterial: 1024,
7029 exportLabel: "label",
7030 exportContext: "context",
7031 useExportContext: true,
7032 })
7033 testCases = append(testCases, testCase{
7034 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7035 config: Config{
7036 MaxVersion: vers.version,
7037 },
7038 exportKeyingMaterial: 1024,
7039 })
7040 testCases = append(testCases, testCase{
7041 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7042 config: Config{
7043 MaxVersion: vers.version,
7044 },
7045 exportKeyingMaterial: 1024,
7046 useExportContext: true,
7047 })
7048 testCases = append(testCases, testCase{
7049 name: "ExportKeyingMaterial-Small-" + vers.name,
7050 config: Config{
7051 MaxVersion: vers.version,
7052 },
7053 exportKeyingMaterial: 1,
7054 exportLabel: "label",
7055 exportContext: "context",
7056 useExportContext: true,
7057 })
7058 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007059
David Benjaminc565ebb2015-04-03 04:06:36 -04007060 testCases = append(testCases, testCase{
7061 name: "ExportKeyingMaterial-SSL3",
7062 config: Config{
7063 MaxVersion: VersionSSL30,
7064 },
7065 exportKeyingMaterial: 1024,
7066 exportLabel: "label",
7067 exportContext: "context",
7068 useExportContext: true,
7069 shouldFail: true,
7070 expectedError: "failed to export keying material",
7071 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007072
7073 // Exporters work during a False Start.
7074 testCases = append(testCases, testCase{
7075 name: "ExportKeyingMaterial-FalseStart",
7076 config: Config{
7077 MaxVersion: VersionTLS12,
7078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7079 NextProtos: []string{"foo"},
7080 Bugs: ProtocolBugs{
7081 ExpectFalseStart: true,
7082 },
7083 },
7084 flags: []string{
7085 "-false-start",
7086 "-advertise-alpn", "\x03foo",
7087 },
7088 shimWritesFirst: true,
7089 exportKeyingMaterial: 1024,
7090 exportLabel: "label",
7091 exportContext: "context",
7092 useExportContext: true,
7093 })
7094
7095 // Exporters do not work in the middle of a renegotiation. Test this by
7096 // triggering the exporter after every SSL_read call and configuring the
7097 // shim to run asynchronously.
7098 testCases = append(testCases, testCase{
7099 name: "ExportKeyingMaterial-Renegotiate",
7100 config: Config{
7101 MaxVersion: VersionTLS12,
7102 },
7103 renegotiate: 1,
7104 flags: []string{
7105 "-async",
7106 "-use-exporter-between-reads",
7107 "-renegotiate-freely",
7108 "-expect-total-renegotiations", "1",
7109 },
7110 shouldFail: true,
7111 expectedError: "failed to export keying material",
7112 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007113}
7114
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007115func addTLSUniqueTests() {
7116 for _, isClient := range []bool{false, true} {
7117 for _, isResumption := range []bool{false, true} {
7118 for _, hasEMS := range []bool{false, true} {
7119 var suffix string
7120 if isResumption {
7121 suffix = "Resume-"
7122 } else {
7123 suffix = "Full-"
7124 }
7125
7126 if hasEMS {
7127 suffix += "EMS-"
7128 } else {
7129 suffix += "NoEMS-"
7130 }
7131
7132 if isClient {
7133 suffix += "Client"
7134 } else {
7135 suffix += "Server"
7136 }
7137
7138 test := testCase{
7139 name: "TLSUnique-" + suffix,
7140 testTLSUnique: true,
7141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007142 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007143 Bugs: ProtocolBugs{
7144 NoExtendedMasterSecret: !hasEMS,
7145 },
7146 },
7147 }
7148
7149 if isResumption {
7150 test.resumeSession = true
7151 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007152 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007153 Bugs: ProtocolBugs{
7154 NoExtendedMasterSecret: !hasEMS,
7155 },
7156 }
7157 }
7158
7159 if isResumption && !hasEMS {
7160 test.shouldFail = true
7161 test.expectedError = "failed to get tls-unique"
7162 }
7163
7164 testCases = append(testCases, test)
7165 }
7166 }
7167 }
7168}
7169
Adam Langley09505632015-07-30 18:10:13 -07007170func addCustomExtensionTests() {
7171 expectedContents := "custom extension"
7172 emptyString := ""
7173
7174 for _, isClient := range []bool{false, true} {
7175 suffix := "Server"
7176 flag := "-enable-server-custom-extension"
7177 testType := serverTest
7178 if isClient {
7179 suffix = "Client"
7180 flag = "-enable-client-custom-extension"
7181 testType = clientTest
7182 }
7183
7184 testCases = append(testCases, testCase{
7185 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007186 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007188 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007189 Bugs: ProtocolBugs{
7190 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007191 ExpectedCustomExtension: &expectedContents,
7192 },
7193 },
7194 flags: []string{flag},
7195 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007196 testCases = append(testCases, testCase{
7197 testType: testType,
7198 name: "CustomExtensions-" + suffix + "-TLS13",
7199 config: Config{
7200 MaxVersion: VersionTLS13,
7201 Bugs: ProtocolBugs{
7202 CustomExtension: expectedContents,
7203 ExpectedCustomExtension: &expectedContents,
7204 },
7205 },
7206 flags: []string{flag},
7207 })
Adam Langley09505632015-07-30 18:10:13 -07007208
7209 // If the parse callback fails, the handshake should also fail.
7210 testCases = append(testCases, testCase{
7211 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007212 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007214 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007215 Bugs: ProtocolBugs{
7216 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007217 ExpectedCustomExtension: &expectedContents,
7218 },
7219 },
David Benjamin399e7c92015-07-30 23:01:27 -04007220 flags: []string{flag},
7221 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007222 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7223 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007224 testCases = append(testCases, testCase{
7225 testType: testType,
7226 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7227 config: Config{
7228 MaxVersion: VersionTLS13,
7229 Bugs: ProtocolBugs{
7230 CustomExtension: expectedContents + "foo",
7231 ExpectedCustomExtension: &expectedContents,
7232 },
7233 },
7234 flags: []string{flag},
7235 shouldFail: true,
7236 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7237 })
Adam Langley09505632015-07-30 18:10:13 -07007238
7239 // If the add callback fails, the handshake should also fail.
7240 testCases = append(testCases, testCase{
7241 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007242 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007244 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007245 Bugs: ProtocolBugs{
7246 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007247 ExpectedCustomExtension: &expectedContents,
7248 },
7249 },
David Benjamin399e7c92015-07-30 23:01:27 -04007250 flags: []string{flag, "-custom-extension-fail-add"},
7251 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007252 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7253 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007254 testCases = append(testCases, testCase{
7255 testType: testType,
7256 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7257 config: Config{
7258 MaxVersion: VersionTLS13,
7259 Bugs: ProtocolBugs{
7260 CustomExtension: expectedContents,
7261 ExpectedCustomExtension: &expectedContents,
7262 },
7263 },
7264 flags: []string{flag, "-custom-extension-fail-add"},
7265 shouldFail: true,
7266 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7267 })
Adam Langley09505632015-07-30 18:10:13 -07007268
7269 // If the add callback returns zero, no extension should be
7270 // added.
7271 skipCustomExtension := expectedContents
7272 if isClient {
7273 // For the case where the client skips sending the
7274 // custom extension, the server must not “echo” it.
7275 skipCustomExtension = ""
7276 }
7277 testCases = append(testCases, testCase{
7278 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007279 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007281 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007282 Bugs: ProtocolBugs{
7283 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007284 ExpectedCustomExtension: &emptyString,
7285 },
7286 },
7287 flags: []string{flag, "-custom-extension-skip"},
7288 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007289 testCases = append(testCases, testCase{
7290 testType: testType,
7291 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7292 config: Config{
7293 MaxVersion: VersionTLS13,
7294 Bugs: ProtocolBugs{
7295 CustomExtension: skipCustomExtension,
7296 ExpectedCustomExtension: &emptyString,
7297 },
7298 },
7299 flags: []string{flag, "-custom-extension-skip"},
7300 })
Adam Langley09505632015-07-30 18:10:13 -07007301 }
7302
7303 // The custom extension add callback should not be called if the client
7304 // doesn't send the extension.
7305 testCases = append(testCases, testCase{
7306 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007307 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007308 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007309 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007310 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007311 ExpectedCustomExtension: &emptyString,
7312 },
7313 },
7314 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7315 })
Adam Langley2deb9842015-08-07 11:15:37 -07007316
Steven Valdez143e8b32016-07-11 13:19:03 -04007317 testCases = append(testCases, testCase{
7318 testType: serverTest,
7319 name: "CustomExtensions-NotCalled-Server-TLS13",
7320 config: Config{
7321 MaxVersion: VersionTLS13,
7322 Bugs: ProtocolBugs{
7323 ExpectedCustomExtension: &emptyString,
7324 },
7325 },
7326 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7327 })
7328
Adam Langley2deb9842015-08-07 11:15:37 -07007329 // Test an unknown extension from the server.
7330 testCases = append(testCases, testCase{
7331 testType: clientTest,
7332 name: "UnknownExtension-Client",
7333 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007334 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007335 Bugs: ProtocolBugs{
7336 CustomExtension: expectedContents,
7337 },
7338 },
David Benjamin0c40a962016-08-01 12:05:50 -04007339 shouldFail: true,
7340 expectedError: ":UNEXPECTED_EXTENSION:",
7341 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007342 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007343 testCases = append(testCases, testCase{
7344 testType: clientTest,
7345 name: "UnknownExtension-Client-TLS13",
7346 config: Config{
7347 MaxVersion: VersionTLS13,
7348 Bugs: ProtocolBugs{
7349 CustomExtension: expectedContents,
7350 },
7351 },
David Benjamin0c40a962016-08-01 12:05:50 -04007352 shouldFail: true,
7353 expectedError: ":UNEXPECTED_EXTENSION:",
7354 expectedLocalError: "remote error: unsupported extension",
7355 })
David Benjamin490469f2016-10-05 22:44:38 -04007356 testCases = append(testCases, testCase{
7357 testType: clientTest,
7358 name: "UnknownUnencryptedExtension-Client-TLS13",
7359 config: Config{
7360 MaxVersion: VersionTLS13,
7361 Bugs: ProtocolBugs{
7362 CustomUnencryptedExtension: expectedContents,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":UNEXPECTED_EXTENSION:",
7367 // The shim must send an alert, but alerts at this point do not
7368 // get successfully decrypted by the runner.
7369 expectedLocalError: "local error: bad record MAC",
7370 })
7371 testCases = append(testCases, testCase{
7372 testType: clientTest,
7373 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7374 config: Config{
7375 MaxVersion: VersionTLS13,
7376 Bugs: ProtocolBugs{
7377 SendUnencryptedALPN: "foo",
7378 },
7379 },
7380 flags: []string{
7381 "-advertise-alpn", "\x03foo\x03bar",
7382 },
7383 shouldFail: true,
7384 expectedError: ":UNEXPECTED_EXTENSION:",
7385 // The shim must send an alert, but alerts at this point do not
7386 // get successfully decrypted by the runner.
7387 expectedLocalError: "local error: bad record MAC",
7388 })
David Benjamin0c40a962016-08-01 12:05:50 -04007389
7390 // Test a known but unoffered extension from the server.
7391 testCases = append(testCases, testCase{
7392 testType: clientTest,
7393 name: "UnofferedExtension-Client",
7394 config: Config{
7395 MaxVersion: VersionTLS12,
7396 Bugs: ProtocolBugs{
7397 SendALPN: "alpn",
7398 },
7399 },
7400 shouldFail: true,
7401 expectedError: ":UNEXPECTED_EXTENSION:",
7402 expectedLocalError: "remote error: unsupported extension",
7403 })
7404 testCases = append(testCases, testCase{
7405 testType: clientTest,
7406 name: "UnofferedExtension-Client-TLS13",
7407 config: Config{
7408 MaxVersion: VersionTLS13,
7409 Bugs: ProtocolBugs{
7410 SendALPN: "alpn",
7411 },
7412 },
7413 shouldFail: true,
7414 expectedError: ":UNEXPECTED_EXTENSION:",
7415 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007416 })
Adam Langley09505632015-07-30 18:10:13 -07007417}
7418
David Benjaminb36a3952015-12-01 18:53:13 -05007419func addRSAClientKeyExchangeTests() {
7420 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7421 testCases = append(testCases, testCase{
7422 testType: serverTest,
7423 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7424 config: Config{
7425 // Ensure the ClientHello version and final
7426 // version are different, to detect if the
7427 // server uses the wrong one.
7428 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007429 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007430 Bugs: ProtocolBugs{
7431 BadRSAClientKeyExchange: bad,
7432 },
7433 },
7434 shouldFail: true,
7435 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7436 })
7437 }
David Benjamine63d9d72016-09-19 18:27:34 -04007438
7439 // The server must compare whatever was in ClientHello.version for the
7440 // RSA premaster.
7441 testCases = append(testCases, testCase{
7442 testType: serverTest,
7443 name: "SendClientVersion-RSA",
7444 config: Config{
7445 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7446 Bugs: ProtocolBugs{
7447 SendClientVersion: 0x1234,
7448 },
7449 },
7450 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7451 })
David Benjaminb36a3952015-12-01 18:53:13 -05007452}
7453
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007454var testCurves = []struct {
7455 name string
7456 id CurveID
7457}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007458 {"P-256", CurveP256},
7459 {"P-384", CurveP384},
7460 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007461 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007462}
7463
Steven Valdez5440fe02016-07-18 12:40:30 -04007464const bogusCurve = 0x1234
7465
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007466func addCurveTests() {
7467 for _, curve := range testCurves {
7468 testCases = append(testCases, testCase{
7469 name: "CurveTest-Client-" + curve.name,
7470 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007471 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7473 CurvePreferences: []CurveID{curve.id},
7474 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007475 flags: []string{
7476 "-enable-all-curves",
7477 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7478 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007479 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007480 })
7481 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007482 name: "CurveTest-Client-" + curve.name + "-TLS13",
7483 config: Config{
7484 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007485 CurvePreferences: []CurveID{curve.id},
7486 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007487 flags: []string{
7488 "-enable-all-curves",
7489 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7490 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007491 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007492 })
7493 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007494 testType: serverTest,
7495 name: "CurveTest-Server-" + curve.name,
7496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007497 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007498 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7499 CurvePreferences: []CurveID{curve.id},
7500 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007501 flags: []string{
7502 "-enable-all-curves",
7503 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7504 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007505 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007506 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007507 testCases = append(testCases, testCase{
7508 testType: serverTest,
7509 name: "CurveTest-Server-" + curve.name + "-TLS13",
7510 config: Config{
7511 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007512 CurvePreferences: []CurveID{curve.id},
7513 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007514 flags: []string{
7515 "-enable-all-curves",
7516 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7517 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007518 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007519 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007520 }
David Benjamin241ae832016-01-15 03:04:54 -05007521
7522 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007523 testCases = append(testCases, testCase{
7524 testType: serverTest,
7525 name: "UnknownCurve",
7526 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007527 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007528 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7529 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7530 },
7531 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007532
Steven Valdez803c77a2016-09-06 14:13:43 -04007533 // The server must be tolerant to bogus curves.
7534 testCases = append(testCases, testCase{
7535 testType: serverTest,
7536 name: "UnknownCurve-TLS13",
7537 config: Config{
7538 MaxVersion: VersionTLS13,
7539 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7540 },
7541 })
7542
David Benjamin4c3ddf72016-06-29 18:13:53 -04007543 // The server must not consider ECDHE ciphers when there are no
7544 // supported curves.
7545 testCases = append(testCases, testCase{
7546 testType: serverTest,
7547 name: "NoSupportedCurves",
7548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007549 MaxVersion: VersionTLS12,
7550 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7551 Bugs: ProtocolBugs{
7552 NoSupportedCurves: true,
7553 },
7554 },
7555 shouldFail: true,
7556 expectedError: ":NO_SHARED_CIPHER:",
7557 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007558 testCases = append(testCases, testCase{
7559 testType: serverTest,
7560 name: "NoSupportedCurves-TLS13",
7561 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007562 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007563 Bugs: ProtocolBugs{
7564 NoSupportedCurves: true,
7565 },
7566 },
7567 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007568 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007569 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007570
7571 // The server must fall back to another cipher when there are no
7572 // supported curves.
7573 testCases = append(testCases, testCase{
7574 testType: serverTest,
7575 name: "NoCommonCurves",
7576 config: Config{
7577 MaxVersion: VersionTLS12,
7578 CipherSuites: []uint16{
7579 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7580 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7581 },
7582 CurvePreferences: []CurveID{CurveP224},
7583 },
7584 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7585 })
7586
7587 // The client must reject bogus curves and disabled curves.
7588 testCases = append(testCases, testCase{
7589 name: "BadECDHECurve",
7590 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007591 MaxVersion: VersionTLS12,
7592 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7593 Bugs: ProtocolBugs{
7594 SendCurve: bogusCurve,
7595 },
7596 },
7597 shouldFail: true,
7598 expectedError: ":WRONG_CURVE:",
7599 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007600 testCases = append(testCases, testCase{
7601 name: "BadECDHECurve-TLS13",
7602 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007603 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007604 Bugs: ProtocolBugs{
7605 SendCurve: bogusCurve,
7606 },
7607 },
7608 shouldFail: true,
7609 expectedError: ":WRONG_CURVE:",
7610 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007611
7612 testCases = append(testCases, testCase{
7613 name: "UnsupportedCurve",
7614 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007615 MaxVersion: VersionTLS12,
7616 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7617 CurvePreferences: []CurveID{CurveP256},
7618 Bugs: ProtocolBugs{
7619 IgnorePeerCurvePreferences: true,
7620 },
7621 },
7622 flags: []string{"-p384-only"},
7623 shouldFail: true,
7624 expectedError: ":WRONG_CURVE:",
7625 })
7626
David Benjamin4f921572016-07-17 14:20:10 +02007627 testCases = append(testCases, testCase{
7628 // TODO(davidben): Add a TLS 1.3 version where
7629 // HelloRetryRequest requests an unsupported curve.
7630 name: "UnsupportedCurve-ServerHello-TLS13",
7631 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007632 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007633 CurvePreferences: []CurveID{CurveP384},
7634 Bugs: ProtocolBugs{
7635 SendCurve: CurveP256,
7636 },
7637 },
7638 flags: []string{"-p384-only"},
7639 shouldFail: true,
7640 expectedError: ":WRONG_CURVE:",
7641 })
7642
David Benjamin4c3ddf72016-06-29 18:13:53 -04007643 // Test invalid curve points.
7644 testCases = append(testCases, testCase{
7645 name: "InvalidECDHPoint-Client",
7646 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007647 MaxVersion: VersionTLS12,
7648 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7649 CurvePreferences: []CurveID{CurveP256},
7650 Bugs: ProtocolBugs{
7651 InvalidECDHPoint: true,
7652 },
7653 },
7654 shouldFail: true,
7655 expectedError: ":INVALID_ENCODING:",
7656 })
7657 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007658 name: "InvalidECDHPoint-Client-TLS13",
7659 config: Config{
7660 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007661 CurvePreferences: []CurveID{CurveP256},
7662 Bugs: ProtocolBugs{
7663 InvalidECDHPoint: true,
7664 },
7665 },
7666 shouldFail: true,
7667 expectedError: ":INVALID_ENCODING:",
7668 })
7669 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007670 testType: serverTest,
7671 name: "InvalidECDHPoint-Server",
7672 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007673 MaxVersion: VersionTLS12,
7674 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7675 CurvePreferences: []CurveID{CurveP256},
7676 Bugs: ProtocolBugs{
7677 InvalidECDHPoint: true,
7678 },
7679 },
7680 shouldFail: true,
7681 expectedError: ":INVALID_ENCODING:",
7682 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007683 testCases = append(testCases, testCase{
7684 testType: serverTest,
7685 name: "InvalidECDHPoint-Server-TLS13",
7686 config: Config{
7687 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007688 CurvePreferences: []CurveID{CurveP256},
7689 Bugs: ProtocolBugs{
7690 InvalidECDHPoint: true,
7691 },
7692 },
7693 shouldFail: true,
7694 expectedError: ":INVALID_ENCODING:",
7695 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007696}
7697
Matt Braithwaite54217e42016-06-13 13:03:47 -07007698func addCECPQ1Tests() {
7699 testCases = append(testCases, testCase{
7700 testType: clientTest,
7701 name: "CECPQ1-Client-BadX25519Part",
7702 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007703 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007704 MinVersion: VersionTLS12,
7705 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7706 Bugs: ProtocolBugs{
7707 CECPQ1BadX25519Part: true,
7708 },
7709 },
7710 flags: []string{"-cipher", "kCECPQ1"},
7711 shouldFail: true,
7712 expectedLocalError: "local error: bad record MAC",
7713 })
7714 testCases = append(testCases, testCase{
7715 testType: clientTest,
7716 name: "CECPQ1-Client-BadNewhopePart",
7717 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007718 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007719 MinVersion: VersionTLS12,
7720 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7721 Bugs: ProtocolBugs{
7722 CECPQ1BadNewhopePart: true,
7723 },
7724 },
7725 flags: []string{"-cipher", "kCECPQ1"},
7726 shouldFail: true,
7727 expectedLocalError: "local error: bad record MAC",
7728 })
7729 testCases = append(testCases, testCase{
7730 testType: serverTest,
7731 name: "CECPQ1-Server-BadX25519Part",
7732 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007733 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007734 MinVersion: VersionTLS12,
7735 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7736 Bugs: ProtocolBugs{
7737 CECPQ1BadX25519Part: true,
7738 },
7739 },
7740 flags: []string{"-cipher", "kCECPQ1"},
7741 shouldFail: true,
7742 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7743 })
7744 testCases = append(testCases, testCase{
7745 testType: serverTest,
7746 name: "CECPQ1-Server-BadNewhopePart",
7747 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007748 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007749 MinVersion: VersionTLS12,
7750 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7751 Bugs: ProtocolBugs{
7752 CECPQ1BadNewhopePart: true,
7753 },
7754 },
7755 flags: []string{"-cipher", "kCECPQ1"},
7756 shouldFail: true,
7757 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7758 })
7759}
7760
David Benjamin5c4e8572016-08-19 17:44:53 -04007761func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007762 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007763 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007764 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007765 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007766 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7767 Bugs: ProtocolBugs{
7768 // This is a 1234-bit prime number, generated
7769 // with:
7770 // openssl gendh 1234 | openssl asn1parse -i
7771 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7772 },
7773 },
David Benjamin9e68f192016-06-30 14:55:33 -04007774 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007775 })
7776 testCases = append(testCases, testCase{
7777 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007778 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007779 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007780 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007781 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7782 },
7783 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007784 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007785 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007786}
7787
David Benjaminc9ae27c2016-06-24 22:56:37 -04007788func addTLS13RecordTests() {
7789 testCases = append(testCases, testCase{
7790 name: "TLS13-RecordPadding",
7791 config: Config{
7792 MaxVersion: VersionTLS13,
7793 MinVersion: VersionTLS13,
7794 Bugs: ProtocolBugs{
7795 RecordPadding: 10,
7796 },
7797 },
7798 })
7799
7800 testCases = append(testCases, testCase{
7801 name: "TLS13-EmptyRecords",
7802 config: Config{
7803 MaxVersion: VersionTLS13,
7804 MinVersion: VersionTLS13,
7805 Bugs: ProtocolBugs{
7806 OmitRecordContents: true,
7807 },
7808 },
7809 shouldFail: true,
7810 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7811 })
7812
7813 testCases = append(testCases, testCase{
7814 name: "TLS13-OnlyPadding",
7815 config: Config{
7816 MaxVersion: VersionTLS13,
7817 MinVersion: VersionTLS13,
7818 Bugs: ProtocolBugs{
7819 OmitRecordContents: true,
7820 RecordPadding: 10,
7821 },
7822 },
7823 shouldFail: true,
7824 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7825 })
7826
7827 testCases = append(testCases, testCase{
7828 name: "TLS13-WrongOuterRecord",
7829 config: Config{
7830 MaxVersion: VersionTLS13,
7831 MinVersion: VersionTLS13,
7832 Bugs: ProtocolBugs{
7833 OuterRecordType: recordTypeHandshake,
7834 },
7835 },
7836 shouldFail: true,
7837 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7838 })
7839}
7840
Steven Valdez5b986082016-09-01 12:29:49 -04007841func addSessionTicketTests() {
7842 testCases = append(testCases, testCase{
7843 // In TLS 1.2 and below, empty NewSessionTicket messages
7844 // mean the server changed its mind on sending a ticket.
7845 name: "SendEmptySessionTicket",
7846 config: Config{
7847 MaxVersion: VersionTLS12,
7848 Bugs: ProtocolBugs{
7849 SendEmptySessionTicket: true,
7850 },
7851 },
7852 flags: []string{"-expect-no-session"},
7853 })
7854
7855 // Test that the server ignores unknown PSK modes.
7856 testCases = append(testCases, testCase{
7857 testType: serverTest,
7858 name: "TLS13-SendUnknownModeSessionTicket-Server",
7859 config: Config{
7860 MaxVersion: VersionTLS13,
7861 Bugs: ProtocolBugs{
7862 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7863 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7864 },
7865 },
7866 resumeSession: true,
7867 expectedResumeVersion: VersionTLS13,
7868 })
7869
7870 // Test that the server declines sessions with no matching key exchange mode.
7871 testCases = append(testCases, testCase{
7872 testType: serverTest,
7873 name: "TLS13-SendBadKEModeSessionTicket-Server",
7874 config: Config{
7875 MaxVersion: VersionTLS13,
7876 Bugs: ProtocolBugs{
7877 SendPSKKeyExchangeModes: []byte{0x1a},
7878 },
7879 },
7880 resumeSession: true,
7881 expectResumeRejected: true,
7882 })
7883
7884 // Test that the server declines sessions with no matching auth mode.
7885 testCases = append(testCases, testCase{
7886 testType: serverTest,
7887 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7888 config: Config{
7889 MaxVersion: VersionTLS13,
7890 Bugs: ProtocolBugs{
7891 SendPSKAuthModes: []byte{0x1a},
7892 },
7893 },
7894 resumeSession: true,
7895 expectResumeRejected: true,
7896 })
7897
7898 // Test that the client ignores unknown PSK modes.
7899 testCases = append(testCases, testCase{
7900 testType: clientTest,
7901 name: "TLS13-SendUnknownModeSessionTicket-Client",
7902 config: Config{
7903 MaxVersion: VersionTLS13,
7904 Bugs: ProtocolBugs{
7905 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7906 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7907 },
7908 },
7909 resumeSession: true,
7910 expectedResumeVersion: VersionTLS13,
7911 })
7912
7913 // Test that the client ignores tickets with no matching key exchange mode.
7914 testCases = append(testCases, testCase{
7915 testType: clientTest,
7916 name: "TLS13-SendBadKEModeSessionTicket-Client",
7917 config: Config{
7918 MaxVersion: VersionTLS13,
7919 Bugs: ProtocolBugs{
7920 SendPSKKeyExchangeModes: []byte{0x1a},
7921 },
7922 },
7923 flags: []string{"-expect-no-session"},
7924 })
7925
7926 // Test that the client ignores tickets with no matching auth mode.
7927 testCases = append(testCases, testCase{
7928 testType: clientTest,
7929 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7930 config: Config{
7931 MaxVersion: VersionTLS13,
7932 Bugs: ProtocolBugs{
7933 SendPSKAuthModes: []byte{0x1a},
7934 },
7935 },
7936 flags: []string{"-expect-no-session"},
7937 })
7938}
7939
David Benjamin82261be2016-07-07 14:32:50 -07007940func addChangeCipherSpecTests() {
7941 // Test missing ChangeCipherSpecs.
7942 testCases = append(testCases, testCase{
7943 name: "SkipChangeCipherSpec-Client",
7944 config: Config{
7945 MaxVersion: VersionTLS12,
7946 Bugs: ProtocolBugs{
7947 SkipChangeCipherSpec: true,
7948 },
7949 },
7950 shouldFail: true,
7951 expectedError: ":UNEXPECTED_RECORD:",
7952 })
7953 testCases = append(testCases, testCase{
7954 testType: serverTest,
7955 name: "SkipChangeCipherSpec-Server",
7956 config: Config{
7957 MaxVersion: VersionTLS12,
7958 Bugs: ProtocolBugs{
7959 SkipChangeCipherSpec: true,
7960 },
7961 },
7962 shouldFail: true,
7963 expectedError: ":UNEXPECTED_RECORD:",
7964 })
7965 testCases = append(testCases, testCase{
7966 testType: serverTest,
7967 name: "SkipChangeCipherSpec-Server-NPN",
7968 config: Config{
7969 MaxVersion: VersionTLS12,
7970 NextProtos: []string{"bar"},
7971 Bugs: ProtocolBugs{
7972 SkipChangeCipherSpec: true,
7973 },
7974 },
7975 flags: []string{
7976 "-advertise-npn", "\x03foo\x03bar\x03baz",
7977 },
7978 shouldFail: true,
7979 expectedError: ":UNEXPECTED_RECORD:",
7980 })
7981
7982 // Test synchronization between the handshake and ChangeCipherSpec.
7983 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7984 // rejected. Test both with and without handshake packing to handle both
7985 // when the partial post-CCS message is in its own record and when it is
7986 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007987 for _, packed := range []bool{false, true} {
7988 var suffix string
7989 if packed {
7990 suffix = "-Packed"
7991 }
7992
7993 testCases = append(testCases, testCase{
7994 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7995 config: Config{
7996 MaxVersion: VersionTLS12,
7997 Bugs: ProtocolBugs{
7998 FragmentAcrossChangeCipherSpec: true,
7999 PackHandshakeFlight: packed,
8000 },
8001 },
8002 shouldFail: true,
8003 expectedError: ":UNEXPECTED_RECORD:",
8004 })
8005 testCases = append(testCases, testCase{
8006 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8007 config: Config{
8008 MaxVersion: VersionTLS12,
8009 },
8010 resumeSession: true,
8011 resumeConfig: &Config{
8012 MaxVersion: VersionTLS12,
8013 Bugs: ProtocolBugs{
8014 FragmentAcrossChangeCipherSpec: true,
8015 PackHandshakeFlight: packed,
8016 },
8017 },
8018 shouldFail: true,
8019 expectedError: ":UNEXPECTED_RECORD:",
8020 })
8021 testCases = append(testCases, testCase{
8022 testType: serverTest,
8023 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8024 config: Config{
8025 MaxVersion: VersionTLS12,
8026 Bugs: ProtocolBugs{
8027 FragmentAcrossChangeCipherSpec: true,
8028 PackHandshakeFlight: packed,
8029 },
8030 },
8031 shouldFail: true,
8032 expectedError: ":UNEXPECTED_RECORD:",
8033 })
8034 testCases = append(testCases, testCase{
8035 testType: serverTest,
8036 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8037 config: Config{
8038 MaxVersion: VersionTLS12,
8039 },
8040 resumeSession: true,
8041 resumeConfig: &Config{
8042 MaxVersion: VersionTLS12,
8043 Bugs: ProtocolBugs{
8044 FragmentAcrossChangeCipherSpec: true,
8045 PackHandshakeFlight: packed,
8046 },
8047 },
8048 shouldFail: true,
8049 expectedError: ":UNEXPECTED_RECORD:",
8050 })
8051 testCases = append(testCases, testCase{
8052 testType: serverTest,
8053 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8054 config: Config{
8055 MaxVersion: VersionTLS12,
8056 NextProtos: []string{"bar"},
8057 Bugs: ProtocolBugs{
8058 FragmentAcrossChangeCipherSpec: true,
8059 PackHandshakeFlight: packed,
8060 },
8061 },
8062 flags: []string{
8063 "-advertise-npn", "\x03foo\x03bar\x03baz",
8064 },
8065 shouldFail: true,
8066 expectedError: ":UNEXPECTED_RECORD:",
8067 })
8068 }
8069
David Benjamin61672812016-07-14 23:10:43 -04008070 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8071 // messages in the handshake queue. Do this by testing the server
8072 // reading the client Finished, reversing the flight so Finished comes
8073 // first.
8074 testCases = append(testCases, testCase{
8075 protocol: dtls,
8076 testType: serverTest,
8077 name: "SendUnencryptedFinished-DTLS",
8078 config: Config{
8079 MaxVersion: VersionTLS12,
8080 Bugs: ProtocolBugs{
8081 SendUnencryptedFinished: true,
8082 ReverseHandshakeFragments: true,
8083 },
8084 },
8085 shouldFail: true,
8086 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8087 })
8088
Steven Valdez143e8b32016-07-11 13:19:03 -04008089 // Test synchronization between encryption changes and the handshake in
8090 // TLS 1.3, where ChangeCipherSpec is implicit.
8091 testCases = append(testCases, testCase{
8092 name: "PartialEncryptedExtensionsWithServerHello",
8093 config: Config{
8094 MaxVersion: VersionTLS13,
8095 Bugs: ProtocolBugs{
8096 PartialEncryptedExtensionsWithServerHello: true,
8097 },
8098 },
8099 shouldFail: true,
8100 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8101 })
8102 testCases = append(testCases, testCase{
8103 testType: serverTest,
8104 name: "PartialClientFinishedWithClientHello",
8105 config: Config{
8106 MaxVersion: VersionTLS13,
8107 Bugs: ProtocolBugs{
8108 PartialClientFinishedWithClientHello: true,
8109 },
8110 },
8111 shouldFail: true,
8112 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8113 })
8114
David Benjamin82261be2016-07-07 14:32:50 -07008115 // Test that early ChangeCipherSpecs are handled correctly.
8116 testCases = append(testCases, testCase{
8117 testType: serverTest,
8118 name: "EarlyChangeCipherSpec-server-1",
8119 config: Config{
8120 MaxVersion: VersionTLS12,
8121 Bugs: ProtocolBugs{
8122 EarlyChangeCipherSpec: 1,
8123 },
8124 },
8125 shouldFail: true,
8126 expectedError: ":UNEXPECTED_RECORD:",
8127 })
8128 testCases = append(testCases, testCase{
8129 testType: serverTest,
8130 name: "EarlyChangeCipherSpec-server-2",
8131 config: Config{
8132 MaxVersion: VersionTLS12,
8133 Bugs: ProtocolBugs{
8134 EarlyChangeCipherSpec: 2,
8135 },
8136 },
8137 shouldFail: true,
8138 expectedError: ":UNEXPECTED_RECORD:",
8139 })
8140 testCases = append(testCases, testCase{
8141 protocol: dtls,
8142 name: "StrayChangeCipherSpec",
8143 config: Config{
8144 // TODO(davidben): Once DTLS 1.3 exists, test
8145 // that stray ChangeCipherSpec messages are
8146 // rejected.
8147 MaxVersion: VersionTLS12,
8148 Bugs: ProtocolBugs{
8149 StrayChangeCipherSpec: true,
8150 },
8151 },
8152 })
8153
8154 // Test that the contents of ChangeCipherSpec are checked.
8155 testCases = append(testCases, testCase{
8156 name: "BadChangeCipherSpec-1",
8157 config: Config{
8158 MaxVersion: VersionTLS12,
8159 Bugs: ProtocolBugs{
8160 BadChangeCipherSpec: []byte{2},
8161 },
8162 },
8163 shouldFail: true,
8164 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8165 })
8166 testCases = append(testCases, testCase{
8167 name: "BadChangeCipherSpec-2",
8168 config: Config{
8169 MaxVersion: VersionTLS12,
8170 Bugs: ProtocolBugs{
8171 BadChangeCipherSpec: []byte{1, 1},
8172 },
8173 },
8174 shouldFail: true,
8175 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8176 })
8177 testCases = append(testCases, testCase{
8178 protocol: dtls,
8179 name: "BadChangeCipherSpec-DTLS-1",
8180 config: Config{
8181 MaxVersion: VersionTLS12,
8182 Bugs: ProtocolBugs{
8183 BadChangeCipherSpec: []byte{2},
8184 },
8185 },
8186 shouldFail: true,
8187 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8188 })
8189 testCases = append(testCases, testCase{
8190 protocol: dtls,
8191 name: "BadChangeCipherSpec-DTLS-2",
8192 config: Config{
8193 MaxVersion: VersionTLS12,
8194 Bugs: ProtocolBugs{
8195 BadChangeCipherSpec: []byte{1, 1},
8196 },
8197 },
8198 shouldFail: true,
8199 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8200 })
8201}
8202
David Benjamincd2c8062016-09-09 11:28:16 -04008203type perMessageTest struct {
8204 messageType uint8
8205 test testCase
8206}
8207
8208// makePerMessageTests returns a series of test templates which cover each
8209// message in the TLS handshake. These may be used with bugs like
8210// WrongMessageType to fully test a per-message bug.
8211func makePerMessageTests() []perMessageTest {
8212 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008213 for _, protocol := range []protocol{tls, dtls} {
8214 var suffix string
8215 if protocol == dtls {
8216 suffix = "-DTLS"
8217 }
8218
David Benjamincd2c8062016-09-09 11:28:16 -04008219 ret = append(ret, perMessageTest{
8220 messageType: typeClientHello,
8221 test: testCase{
8222 protocol: protocol,
8223 testType: serverTest,
8224 name: "ClientHello" + suffix,
8225 config: Config{
8226 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008227 },
8228 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008229 })
8230
8231 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008232 ret = append(ret, perMessageTest{
8233 messageType: typeHelloVerifyRequest,
8234 test: testCase{
8235 protocol: protocol,
8236 name: "HelloVerifyRequest" + suffix,
8237 config: Config{
8238 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008239 },
8240 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008241 })
8242 }
8243
David Benjamincd2c8062016-09-09 11:28:16 -04008244 ret = append(ret, perMessageTest{
8245 messageType: typeServerHello,
8246 test: testCase{
8247 protocol: protocol,
8248 name: "ServerHello" + suffix,
8249 config: Config{
8250 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008251 },
8252 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008253 })
8254
David Benjamincd2c8062016-09-09 11:28:16 -04008255 ret = append(ret, perMessageTest{
8256 messageType: typeCertificate,
8257 test: testCase{
8258 protocol: protocol,
8259 name: "ServerCertificate" + suffix,
8260 config: Config{
8261 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008262 },
8263 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008264 })
8265
David Benjamincd2c8062016-09-09 11:28:16 -04008266 ret = append(ret, perMessageTest{
8267 messageType: typeCertificateStatus,
8268 test: testCase{
8269 protocol: protocol,
8270 name: "CertificateStatus" + suffix,
8271 config: Config{
8272 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008273 },
David Benjamincd2c8062016-09-09 11:28:16 -04008274 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008275 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008276 })
8277
David Benjamincd2c8062016-09-09 11:28:16 -04008278 ret = append(ret, perMessageTest{
8279 messageType: typeServerKeyExchange,
8280 test: testCase{
8281 protocol: protocol,
8282 name: "ServerKeyExchange" + suffix,
8283 config: Config{
8284 MaxVersion: VersionTLS12,
8285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008286 },
8287 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008288 })
8289
David Benjamincd2c8062016-09-09 11:28:16 -04008290 ret = append(ret, perMessageTest{
8291 messageType: typeCertificateRequest,
8292 test: testCase{
8293 protocol: protocol,
8294 name: "CertificateRequest" + suffix,
8295 config: Config{
8296 MaxVersion: VersionTLS12,
8297 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008298 },
8299 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008300 })
8301
David Benjamincd2c8062016-09-09 11:28:16 -04008302 ret = append(ret, perMessageTest{
8303 messageType: typeServerHelloDone,
8304 test: testCase{
8305 protocol: protocol,
8306 name: "ServerHelloDone" + suffix,
8307 config: Config{
8308 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008309 },
8310 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008311 })
8312
David Benjamincd2c8062016-09-09 11:28:16 -04008313 ret = append(ret, perMessageTest{
8314 messageType: typeCertificate,
8315 test: testCase{
8316 testType: serverTest,
8317 protocol: protocol,
8318 name: "ClientCertificate" + suffix,
8319 config: Config{
8320 Certificates: []Certificate{rsaCertificate},
8321 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008322 },
David Benjamincd2c8062016-09-09 11:28:16 -04008323 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008324 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008325 })
8326
David Benjamincd2c8062016-09-09 11:28:16 -04008327 ret = append(ret, perMessageTest{
8328 messageType: typeCertificateVerify,
8329 test: testCase{
8330 testType: serverTest,
8331 protocol: protocol,
8332 name: "CertificateVerify" + suffix,
8333 config: Config{
8334 Certificates: []Certificate{rsaCertificate},
8335 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008336 },
David Benjamincd2c8062016-09-09 11:28:16 -04008337 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008338 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008339 })
8340
David Benjamincd2c8062016-09-09 11:28:16 -04008341 ret = append(ret, perMessageTest{
8342 messageType: typeClientKeyExchange,
8343 test: testCase{
8344 testType: serverTest,
8345 protocol: protocol,
8346 name: "ClientKeyExchange" + suffix,
8347 config: Config{
8348 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008349 },
8350 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008351 })
8352
8353 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008354 ret = append(ret, perMessageTest{
8355 messageType: typeNextProtocol,
8356 test: testCase{
8357 testType: serverTest,
8358 protocol: protocol,
8359 name: "NextProtocol" + suffix,
8360 config: Config{
8361 MaxVersion: VersionTLS12,
8362 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008363 },
David Benjamincd2c8062016-09-09 11:28:16 -04008364 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008365 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008366 })
8367
David Benjamincd2c8062016-09-09 11:28:16 -04008368 ret = append(ret, perMessageTest{
8369 messageType: typeChannelID,
8370 test: testCase{
8371 testType: serverTest,
8372 protocol: protocol,
8373 name: "ChannelID" + suffix,
8374 config: Config{
8375 MaxVersion: VersionTLS12,
8376 ChannelID: channelIDKey,
8377 },
8378 flags: []string{
8379 "-expect-channel-id",
8380 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008381 },
8382 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008383 })
8384 }
8385
David Benjamincd2c8062016-09-09 11:28:16 -04008386 ret = append(ret, perMessageTest{
8387 messageType: typeFinished,
8388 test: testCase{
8389 testType: serverTest,
8390 protocol: protocol,
8391 name: "ClientFinished" + suffix,
8392 config: Config{
8393 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008394 },
8395 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008396 })
8397
David Benjamincd2c8062016-09-09 11:28:16 -04008398 ret = append(ret, perMessageTest{
8399 messageType: typeNewSessionTicket,
8400 test: testCase{
8401 protocol: protocol,
8402 name: "NewSessionTicket" + suffix,
8403 config: Config{
8404 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008405 },
8406 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008407 })
8408
David Benjamincd2c8062016-09-09 11:28:16 -04008409 ret = append(ret, perMessageTest{
8410 messageType: typeFinished,
8411 test: testCase{
8412 protocol: protocol,
8413 name: "ServerFinished" + suffix,
8414 config: Config{
8415 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008416 },
8417 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008418 })
8419
8420 }
David Benjamincd2c8062016-09-09 11:28:16 -04008421
8422 ret = append(ret, perMessageTest{
8423 messageType: typeClientHello,
8424 test: testCase{
8425 testType: serverTest,
8426 name: "TLS13-ClientHello",
8427 config: Config{
8428 MaxVersion: VersionTLS13,
8429 },
8430 },
8431 })
8432
8433 ret = append(ret, perMessageTest{
8434 messageType: typeServerHello,
8435 test: testCase{
8436 name: "TLS13-ServerHello",
8437 config: Config{
8438 MaxVersion: VersionTLS13,
8439 },
8440 },
8441 })
8442
8443 ret = append(ret, perMessageTest{
8444 messageType: typeEncryptedExtensions,
8445 test: testCase{
8446 name: "TLS13-EncryptedExtensions",
8447 config: Config{
8448 MaxVersion: VersionTLS13,
8449 },
8450 },
8451 })
8452
8453 ret = append(ret, perMessageTest{
8454 messageType: typeCertificateRequest,
8455 test: testCase{
8456 name: "TLS13-CertificateRequest",
8457 config: Config{
8458 MaxVersion: VersionTLS13,
8459 ClientAuth: RequireAnyClientCert,
8460 },
8461 },
8462 })
8463
8464 ret = append(ret, perMessageTest{
8465 messageType: typeCertificate,
8466 test: testCase{
8467 name: "TLS13-ServerCertificate",
8468 config: Config{
8469 MaxVersion: VersionTLS13,
8470 },
8471 },
8472 })
8473
8474 ret = append(ret, perMessageTest{
8475 messageType: typeCertificateVerify,
8476 test: testCase{
8477 name: "TLS13-ServerCertificateVerify",
8478 config: Config{
8479 MaxVersion: VersionTLS13,
8480 },
8481 },
8482 })
8483
8484 ret = append(ret, perMessageTest{
8485 messageType: typeFinished,
8486 test: testCase{
8487 name: "TLS13-ServerFinished",
8488 config: Config{
8489 MaxVersion: VersionTLS13,
8490 },
8491 },
8492 })
8493
8494 ret = append(ret, perMessageTest{
8495 messageType: typeCertificate,
8496 test: testCase{
8497 testType: serverTest,
8498 name: "TLS13-ClientCertificate",
8499 config: Config{
8500 Certificates: []Certificate{rsaCertificate},
8501 MaxVersion: VersionTLS13,
8502 },
8503 flags: []string{"-require-any-client-certificate"},
8504 },
8505 })
8506
8507 ret = append(ret, perMessageTest{
8508 messageType: typeCertificateVerify,
8509 test: testCase{
8510 testType: serverTest,
8511 name: "TLS13-ClientCertificateVerify",
8512 config: Config{
8513 Certificates: []Certificate{rsaCertificate},
8514 MaxVersion: VersionTLS13,
8515 },
8516 flags: []string{"-require-any-client-certificate"},
8517 },
8518 })
8519
8520 ret = append(ret, perMessageTest{
8521 messageType: typeFinished,
8522 test: testCase{
8523 testType: serverTest,
8524 name: "TLS13-ClientFinished",
8525 config: Config{
8526 MaxVersion: VersionTLS13,
8527 },
8528 },
8529 })
8530
8531 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008532}
8533
David Benjamincd2c8062016-09-09 11:28:16 -04008534func addWrongMessageTypeTests() {
8535 for _, t := range makePerMessageTests() {
8536 t.test.name = "WrongMessageType-" + t.test.name
8537 t.test.config.Bugs.SendWrongMessageType = t.messageType
8538 t.test.shouldFail = true
8539 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8540 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008541
David Benjamincd2c8062016-09-09 11:28:16 -04008542 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8543 // In TLS 1.3, a bad ServerHello means the client sends
8544 // an unencrypted alert while the server expects
8545 // encryption, so the alert is not readable by runner.
8546 t.test.expectedLocalError = "local error: bad record MAC"
8547 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008548
David Benjamincd2c8062016-09-09 11:28:16 -04008549 testCases = append(testCases, t.test)
8550 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008551}
8552
David Benjamin639846e2016-09-09 11:41:18 -04008553func addTrailingMessageDataTests() {
8554 for _, t := range makePerMessageTests() {
8555 t.test.name = "TrailingMessageData-" + t.test.name
8556 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8557 t.test.shouldFail = true
8558 t.test.expectedError = ":DECODE_ERROR:"
8559 t.test.expectedLocalError = "remote error: error decoding message"
8560
8561 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8562 // In TLS 1.3, a bad ServerHello means the client sends
8563 // an unencrypted alert while the server expects
8564 // encryption, so the alert is not readable by runner.
8565 t.test.expectedLocalError = "local error: bad record MAC"
8566 }
8567
8568 if t.messageType == typeFinished {
8569 // Bad Finished messages read as the verify data having
8570 // the wrong length.
8571 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8572 t.test.expectedLocalError = "remote error: error decrypting message"
8573 }
8574
8575 testCases = append(testCases, t.test)
8576 }
8577}
8578
Steven Valdez143e8b32016-07-11 13:19:03 -04008579func addTLS13HandshakeTests() {
8580 testCases = append(testCases, testCase{
8581 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008582 name: "NegotiatePSKResumption-TLS13",
8583 config: Config{
8584 MaxVersion: VersionTLS13,
8585 Bugs: ProtocolBugs{
8586 NegotiatePSKResumption: true,
8587 },
8588 },
8589 resumeSession: true,
8590 shouldFail: true,
8591 expectedError: ":UNEXPECTED_EXTENSION:",
8592 })
8593
8594 testCases = append(testCases, testCase{
8595 testType: clientTest,
8596 name: "OmitServerHelloSignatureAlgorithms",
8597 config: Config{
8598 MaxVersion: VersionTLS13,
8599 Bugs: ProtocolBugs{
8600 OmitServerHelloSignatureAlgorithms: true,
8601 },
8602 },
8603 shouldFail: true,
8604 expectedError: ":UNEXPECTED_EXTENSION:",
8605 })
8606
8607 testCases = append(testCases, testCase{
8608 testType: clientTest,
8609 name: "IncludeServerHelloSignatureAlgorithms",
8610 config: Config{
8611 MaxVersion: VersionTLS13,
8612 Bugs: ProtocolBugs{
8613 IncludeServerHelloSignatureAlgorithms: true,
8614 },
8615 },
8616 resumeSession: true,
8617 shouldFail: true,
8618 expectedError: ":UNEXPECTED_EXTENSION:",
8619 })
8620
8621 testCases = append(testCases, testCase{
8622 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008623 name: "MissingKeyShare-Client",
8624 config: Config{
8625 MaxVersion: VersionTLS13,
8626 Bugs: ProtocolBugs{
8627 MissingKeyShare: true,
8628 },
8629 },
8630 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008631 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008632 })
8633
8634 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008635 testType: serverTest,
8636 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008637 config: Config{
8638 MaxVersion: VersionTLS13,
8639 Bugs: ProtocolBugs{
8640 MissingKeyShare: true,
8641 },
8642 },
8643 shouldFail: true,
8644 expectedError: ":MISSING_KEY_SHARE:",
8645 })
8646
8647 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008648 testType: serverTest,
8649 name: "DuplicateKeyShares",
8650 config: Config{
8651 MaxVersion: VersionTLS13,
8652 Bugs: ProtocolBugs{
8653 DuplicateKeyShares: true,
8654 },
8655 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008656 shouldFail: true,
8657 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008658 })
8659
8660 testCases = append(testCases, testCase{
8661 testType: clientTest,
8662 name: "EmptyEncryptedExtensions",
8663 config: Config{
8664 MaxVersion: VersionTLS13,
8665 Bugs: ProtocolBugs{
8666 EmptyEncryptedExtensions: true,
8667 },
8668 },
8669 shouldFail: true,
8670 expectedLocalError: "remote error: error decoding message",
8671 })
8672
8673 testCases = append(testCases, testCase{
8674 testType: clientTest,
8675 name: "EncryptedExtensionsWithKeyShare",
8676 config: Config{
8677 MaxVersion: VersionTLS13,
8678 Bugs: ProtocolBugs{
8679 EncryptedExtensionsWithKeyShare: true,
8680 },
8681 },
8682 shouldFail: true,
8683 expectedLocalError: "remote error: unsupported extension",
8684 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008685
8686 testCases = append(testCases, testCase{
8687 testType: serverTest,
8688 name: "SendHelloRetryRequest",
8689 config: Config{
8690 MaxVersion: VersionTLS13,
8691 // Require a HelloRetryRequest for every curve.
8692 DefaultCurves: []CurveID{},
8693 },
8694 expectedCurveID: CurveX25519,
8695 })
8696
8697 testCases = append(testCases, testCase{
8698 testType: serverTest,
8699 name: "SendHelloRetryRequest-2",
8700 config: Config{
8701 MaxVersion: VersionTLS13,
8702 DefaultCurves: []CurveID{CurveP384},
8703 },
8704 // Although the ClientHello did not predict our preferred curve,
8705 // we always select it whether it is predicted or not.
8706 expectedCurveID: CurveX25519,
8707 })
8708
8709 testCases = append(testCases, testCase{
8710 name: "UnknownCurve-HelloRetryRequest",
8711 config: Config{
8712 MaxVersion: VersionTLS13,
8713 // P-384 requires HelloRetryRequest in BoringSSL.
8714 CurvePreferences: []CurveID{CurveP384},
8715 Bugs: ProtocolBugs{
8716 SendHelloRetryRequestCurve: bogusCurve,
8717 },
8718 },
8719 shouldFail: true,
8720 expectedError: ":WRONG_CURVE:",
8721 })
8722
8723 testCases = append(testCases, testCase{
8724 name: "DisabledCurve-HelloRetryRequest",
8725 config: Config{
8726 MaxVersion: VersionTLS13,
8727 CurvePreferences: []CurveID{CurveP256},
8728 Bugs: ProtocolBugs{
8729 IgnorePeerCurvePreferences: true,
8730 },
8731 },
8732 flags: []string{"-p384-only"},
8733 shouldFail: true,
8734 expectedError: ":WRONG_CURVE:",
8735 })
8736
8737 testCases = append(testCases, testCase{
8738 name: "UnnecessaryHelloRetryRequest",
8739 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04008740 MaxVersion: VersionTLS13,
8741 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04008742 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04008743 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04008744 },
8745 },
8746 shouldFail: true,
8747 expectedError: ":WRONG_CURVE:",
8748 })
8749
8750 testCases = append(testCases, testCase{
8751 name: "SecondHelloRetryRequest",
8752 config: Config{
8753 MaxVersion: VersionTLS13,
8754 // P-384 requires HelloRetryRequest in BoringSSL.
8755 CurvePreferences: []CurveID{CurveP384},
8756 Bugs: ProtocolBugs{
8757 SecondHelloRetryRequest: true,
8758 },
8759 },
8760 shouldFail: true,
8761 expectedError: ":UNEXPECTED_MESSAGE:",
8762 })
8763
8764 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04008765 name: "HelloRetryRequest-Empty",
8766 config: Config{
8767 MaxVersion: VersionTLS13,
8768 Bugs: ProtocolBugs{
8769 AlwaysSendHelloRetryRequest: true,
8770 },
8771 },
8772 shouldFail: true,
8773 expectedError: ":DECODE_ERROR:",
8774 })
8775
8776 testCases = append(testCases, testCase{
8777 name: "HelloRetryRequest-DuplicateCurve",
8778 config: Config{
8779 MaxVersion: VersionTLS13,
8780 // P-384 requires a HelloRetryRequest against BoringSSL's default
8781 // configuration. Assert this ExpectMissingKeyShare.
8782 CurvePreferences: []CurveID{CurveP384},
8783 Bugs: ProtocolBugs{
8784 ExpectMissingKeyShare: true,
8785 DuplicateHelloRetryRequestExtensions: true,
8786 },
8787 },
8788 shouldFail: true,
8789 expectedError: ":DUPLICATE_EXTENSION:",
8790 expectedLocalError: "remote error: illegal parameter",
8791 })
8792
8793 testCases = append(testCases, testCase{
8794 name: "HelloRetryRequest-Cookie",
8795 config: Config{
8796 MaxVersion: VersionTLS13,
8797 Bugs: ProtocolBugs{
8798 SendHelloRetryRequestCookie: []byte("cookie"),
8799 },
8800 },
8801 })
8802
8803 testCases = append(testCases, testCase{
8804 name: "HelloRetryRequest-DuplicateCookie",
8805 config: Config{
8806 MaxVersion: VersionTLS13,
8807 Bugs: ProtocolBugs{
8808 SendHelloRetryRequestCookie: []byte("cookie"),
8809 DuplicateHelloRetryRequestExtensions: true,
8810 },
8811 },
8812 shouldFail: true,
8813 expectedError: ":DUPLICATE_EXTENSION:",
8814 expectedLocalError: "remote error: illegal parameter",
8815 })
8816
8817 testCases = append(testCases, testCase{
8818 name: "HelloRetryRequest-EmptyCookie",
8819 config: Config{
8820 MaxVersion: VersionTLS13,
8821 Bugs: ProtocolBugs{
8822 SendHelloRetryRequestCookie: []byte{},
8823 },
8824 },
8825 shouldFail: true,
8826 expectedError: ":DECODE_ERROR:",
8827 })
8828
8829 testCases = append(testCases, testCase{
8830 name: "HelloRetryRequest-Cookie-Curve",
8831 config: Config{
8832 MaxVersion: VersionTLS13,
8833 // P-384 requires HelloRetryRequest in BoringSSL.
8834 CurvePreferences: []CurveID{CurveP384},
8835 Bugs: ProtocolBugs{
8836 SendHelloRetryRequestCookie: []byte("cookie"),
8837 ExpectMissingKeyShare: true,
8838 },
8839 },
8840 })
8841
8842 testCases = append(testCases, testCase{
8843 name: "HelloRetryRequest-Unknown",
8844 config: Config{
8845 MaxVersion: VersionTLS13,
8846 Bugs: ProtocolBugs{
8847 CustomHelloRetryRequestExtension: "extension",
8848 },
8849 },
8850 shouldFail: true,
8851 expectedError: ":UNEXPECTED_EXTENSION:",
8852 expectedLocalError: "remote error: unsupported extension",
8853 })
8854
8855 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008856 testType: serverTest,
8857 name: "SecondClientHelloMissingKeyShare",
8858 config: Config{
8859 MaxVersion: VersionTLS13,
8860 DefaultCurves: []CurveID{},
8861 Bugs: ProtocolBugs{
8862 SecondClientHelloMissingKeyShare: true,
8863 },
8864 },
8865 shouldFail: true,
8866 expectedError: ":MISSING_KEY_SHARE:",
8867 })
8868
8869 testCases = append(testCases, testCase{
8870 testType: serverTest,
8871 name: "SecondClientHelloWrongCurve",
8872 config: Config{
8873 MaxVersion: VersionTLS13,
8874 DefaultCurves: []CurveID{},
8875 Bugs: ProtocolBugs{
8876 MisinterpretHelloRetryRequestCurve: CurveP521,
8877 },
8878 },
8879 shouldFail: true,
8880 expectedError: ":WRONG_CURVE:",
8881 })
8882
8883 testCases = append(testCases, testCase{
8884 name: "HelloRetryRequestVersionMismatch",
8885 config: Config{
8886 MaxVersion: VersionTLS13,
8887 // P-384 requires HelloRetryRequest in BoringSSL.
8888 CurvePreferences: []CurveID{CurveP384},
8889 Bugs: ProtocolBugs{
8890 SendServerHelloVersion: 0x0305,
8891 },
8892 },
8893 shouldFail: true,
8894 expectedError: ":WRONG_VERSION_NUMBER:",
8895 })
8896
8897 testCases = append(testCases, testCase{
8898 name: "HelloRetryRequestCurveMismatch",
8899 config: Config{
8900 MaxVersion: VersionTLS13,
8901 // P-384 requires HelloRetryRequest in BoringSSL.
8902 CurvePreferences: []CurveID{CurveP384},
8903 Bugs: ProtocolBugs{
8904 // Send P-384 (correct) in the HelloRetryRequest.
8905 SendHelloRetryRequestCurve: CurveP384,
8906 // But send P-256 in the ServerHello.
8907 SendCurve: CurveP256,
8908 },
8909 },
8910 shouldFail: true,
8911 expectedError: ":WRONG_CURVE:",
8912 })
8913
8914 // Test the server selecting a curve that requires a HelloRetryRequest
8915 // without sending it.
8916 testCases = append(testCases, testCase{
8917 name: "SkipHelloRetryRequest",
8918 config: Config{
8919 MaxVersion: VersionTLS13,
8920 // P-384 requires HelloRetryRequest in BoringSSL.
8921 CurvePreferences: []CurveID{CurveP384},
8922 Bugs: ProtocolBugs{
8923 SkipHelloRetryRequest: true,
8924 },
8925 },
8926 shouldFail: true,
8927 expectedError: ":WRONG_CURVE:",
8928 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008929
8930 testCases = append(testCases, testCase{
8931 name: "TLS13-RequestContextInHandshake",
8932 config: Config{
8933 MaxVersion: VersionTLS13,
8934 MinVersion: VersionTLS13,
8935 ClientAuth: RequireAnyClientCert,
8936 Bugs: ProtocolBugs{
8937 SendRequestContext: []byte("request context"),
8938 },
8939 },
8940 flags: []string{
8941 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8942 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8943 },
8944 shouldFail: true,
8945 expectedError: ":DECODE_ERROR:",
8946 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008947
8948 testCases = append(testCases, testCase{
8949 testType: serverTest,
8950 name: "TLS13-TrailingKeyShareData",
8951 config: Config{
8952 MaxVersion: VersionTLS13,
8953 Bugs: ProtocolBugs{
8954 TrailingKeyShareData: true,
8955 },
8956 },
8957 shouldFail: true,
8958 expectedError: ":DECODE_ERROR:",
8959 })
David Benjamin7f78df42016-10-05 22:33:19 -04008960
8961 testCases = append(testCases, testCase{
8962 name: "TLS13-AlwaysSelectPSKIdentity",
8963 config: Config{
8964 MaxVersion: VersionTLS13,
8965 Bugs: ProtocolBugs{
8966 AlwaysSelectPSKIdentity: true,
8967 },
8968 },
8969 shouldFail: true,
8970 expectedError: ":UNEXPECTED_EXTENSION:",
8971 })
8972
8973 testCases = append(testCases, testCase{
8974 name: "TLS13-InvalidPSKIdentity",
8975 config: Config{
8976 MaxVersion: VersionTLS13,
8977 Bugs: ProtocolBugs{
8978 SelectPSKIdentityOnResume: 1,
8979 },
8980 },
8981 resumeSession: true,
8982 shouldFail: true,
8983 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
8984 })
David Benjamin1286bee2016-10-07 15:25:06 -04008985
Steven Valdezaf3b8a92016-11-01 12:49:22 -04008986 testCases = append(testCases, testCase{
8987 testType: serverTest,
8988 name: "TLS13-ExtraPSKIdentity",
8989 config: Config{
8990 MaxVersion: VersionTLS13,
8991 Bugs: ProtocolBugs{
8992 ExtraPSKIdentity: true,
8993 },
8994 },
8995 resumeSession: true,
8996 })
8997
David Benjamin1286bee2016-10-07 15:25:06 -04008998 // Test that unknown NewSessionTicket extensions are tolerated.
8999 testCases = append(testCases, testCase{
9000 name: "TLS13-CustomTicketExtension",
9001 config: Config{
9002 MaxVersion: VersionTLS13,
9003 Bugs: ProtocolBugs{
9004 CustomTicketExtension: "1234",
9005 },
9006 },
9007 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009008}
9009
David Benjaminabbbee12016-10-31 19:20:42 -04009010func addTLS13CipherPreferenceTests() {
9011 // Test that client preference is honored if the shim has AES hardware
9012 // and ChaCha20-Poly1305 is preferred otherwise.
9013 testCases = append(testCases, testCase{
9014 testType: serverTest,
9015 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9016 config: Config{
9017 MaxVersion: VersionTLS13,
9018 CipherSuites: []uint16{
9019 TLS_CHACHA20_POLY1305_SHA256,
9020 TLS_AES_128_GCM_SHA256,
9021 },
9022 },
9023 flags: []string{
9024 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9025 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9026 },
9027 })
9028
9029 testCases = append(testCases, testCase{
9030 testType: serverTest,
9031 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9032 config: Config{
9033 MaxVersion: VersionTLS13,
9034 CipherSuites: []uint16{
9035 TLS_AES_128_GCM_SHA256,
9036 TLS_CHACHA20_POLY1305_SHA256,
9037 },
9038 },
9039 flags: []string{
9040 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9041 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9042 },
9043 })
9044
9045 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9046 // whether it has AES hardware.
9047 testCases = append(testCases, testCase{
9048 name: "TLS13-CipherPreference-Client",
9049 config: Config{
9050 MaxVersion: VersionTLS13,
9051 // Use the client cipher order. (This is the default but
9052 // is listed to be explicit.)
9053 PreferServerCipherSuites: false,
9054 },
9055 flags: []string{
9056 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9057 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9058 },
9059 })
9060}
9061
David Benjaminf3fbade2016-09-19 13:08:16 -04009062func addPeekTests() {
9063 // Test SSL_peek works, including on empty records.
9064 testCases = append(testCases, testCase{
9065 name: "Peek-Basic",
9066 sendEmptyRecords: 1,
9067 flags: []string{"-peek-then-read"},
9068 })
9069
9070 // Test SSL_peek can drive the initial handshake.
9071 testCases = append(testCases, testCase{
9072 name: "Peek-ImplicitHandshake",
9073 flags: []string{
9074 "-peek-then-read",
9075 "-implicit-handshake",
9076 },
9077 })
9078
9079 // Test SSL_peek can discover and drive a renegotiation.
9080 testCases = append(testCases, testCase{
9081 name: "Peek-Renegotiate",
9082 config: Config{
9083 MaxVersion: VersionTLS12,
9084 },
9085 renegotiate: 1,
9086 flags: []string{
9087 "-peek-then-read",
9088 "-renegotiate-freely",
9089 "-expect-total-renegotiations", "1",
9090 },
9091 })
9092
9093 // Test SSL_peek can discover a close_notify.
9094 testCases = append(testCases, testCase{
9095 name: "Peek-Shutdown",
9096 config: Config{
9097 Bugs: ProtocolBugs{
9098 ExpectCloseNotify: true,
9099 },
9100 },
9101 flags: []string{
9102 "-peek-then-read",
9103 "-check-close-notify",
9104 },
9105 })
9106
9107 // Test SSL_peek can discover an alert.
9108 testCases = append(testCases, testCase{
9109 name: "Peek-Alert",
9110 config: Config{
9111 Bugs: ProtocolBugs{
9112 SendSpuriousAlert: alertRecordOverflow,
9113 },
9114 },
9115 flags: []string{"-peek-then-read"},
9116 shouldFail: true,
9117 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9118 })
9119
9120 // Test SSL_peek can handle KeyUpdate.
9121 testCases = append(testCases, testCase{
9122 name: "Peek-KeyUpdate",
9123 config: Config{
9124 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009125 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009126 sendKeyUpdates: 1,
9127 keyUpdateRequest: keyUpdateNotRequested,
9128 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009129 })
9130}
9131
David Benjamine6f22212016-11-08 14:28:24 -05009132func addRecordVersionTests() {
9133 for _, ver := range tlsVersions {
9134 // Test that the record version is enforced.
9135 testCases = append(testCases, testCase{
9136 name: "CheckRecordVersion-" + ver.name,
9137 config: Config{
9138 MinVersion: ver.version,
9139 MaxVersion: ver.version,
9140 Bugs: ProtocolBugs{
9141 SendRecordVersion: 0x03ff,
9142 },
9143 },
9144 shouldFail: true,
9145 expectedError: ":WRONG_VERSION_NUMBER:",
9146 })
9147
9148 // Test that the ClientHello may use any record version, for
9149 // compatibility reasons.
9150 testCases = append(testCases, testCase{
9151 testType: serverTest,
9152 name: "LooseInitialRecordVersion-" + ver.name,
9153 config: Config{
9154 MinVersion: ver.version,
9155 MaxVersion: ver.version,
9156 Bugs: ProtocolBugs{
9157 SendInitialRecordVersion: 0x03ff,
9158 },
9159 },
9160 })
9161
9162 // Test that garbage ClientHello record versions are rejected.
9163 testCases = append(testCases, testCase{
9164 testType: serverTest,
9165 name: "GarbageInitialRecordVersion-" + ver.name,
9166 config: Config{
9167 MinVersion: ver.version,
9168 MaxVersion: ver.version,
9169 Bugs: ProtocolBugs{
9170 SendInitialRecordVersion: 0xffff,
9171 },
9172 },
9173 shouldFail: true,
9174 expectedError: ":WRONG_VERSION_NUMBER:",
9175 })
9176 }
9177}
9178
David Benjamin2c516452016-11-15 10:16:54 +09009179func addCertificateTests() {
9180 // Test that a certificate chain with intermediate may be sent and
9181 // received as both client and server.
9182 for _, ver := range tlsVersions {
9183 testCases = append(testCases, testCase{
9184 testType: clientTest,
9185 name: "SendReceiveIntermediate-Client-" + ver.name,
9186 config: Config{
9187 Certificates: []Certificate{rsaChainCertificate},
9188 ClientAuth: RequireAnyClientCert,
9189 },
9190 expectPeerCertificate: &rsaChainCertificate,
9191 flags: []string{
9192 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9193 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9194 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9195 },
9196 })
9197
9198 testCases = append(testCases, testCase{
9199 testType: serverTest,
9200 name: "SendReceiveIntermediate-Server-" + ver.name,
9201 config: Config{
9202 Certificates: []Certificate{rsaChainCertificate},
9203 },
9204 expectPeerCertificate: &rsaChainCertificate,
9205 flags: []string{
9206 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9207 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9208 "-require-any-client-certificate",
9209 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9210 },
9211 })
9212 }
9213}
9214
Adam Langley7c803a62015-06-15 15:35:05 -07009215func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009216 defer wg.Done()
9217
9218 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009219 var err error
9220
9221 if *mallocTest < 0 {
9222 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009223 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009224 } else {
9225 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9226 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009227 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009228 if err != nil {
9229 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9230 }
9231 break
9232 }
9233 }
9234 }
Adam Langley95c29f32014-06-20 12:00:00 -07009235 statusChan <- statusMsg{test: test, err: err}
9236 }
9237}
9238
9239type statusMsg struct {
9240 test *testCase
9241 started bool
9242 err error
9243}
9244
David Benjamin5f237bc2015-02-11 17:14:15 -05009245func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009246 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009247
David Benjamin5f237bc2015-02-11 17:14:15 -05009248 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009249 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009250 if !*pipe {
9251 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009252 var erase string
9253 for i := 0; i < lineLen; i++ {
9254 erase += "\b \b"
9255 }
9256 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009257 }
9258
Adam Langley95c29f32014-06-20 12:00:00 -07009259 if msg.started {
9260 started++
9261 } else {
9262 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009263
9264 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009265 if msg.err == errUnimplemented {
9266 if *pipe {
9267 // Print each test instead of a status line.
9268 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9269 }
9270 unimplemented++
9271 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9272 } else {
9273 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9274 failed++
9275 testOutput.addResult(msg.test.name, "FAIL")
9276 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009277 } else {
9278 if *pipe {
9279 // Print each test instead of a status line.
9280 fmt.Printf("PASSED (%s)\n", msg.test.name)
9281 }
9282 testOutput.addResult(msg.test.name, "PASS")
9283 }
Adam Langley95c29f32014-06-20 12:00:00 -07009284 }
9285
David Benjamin5f237bc2015-02-11 17:14:15 -05009286 if !*pipe {
9287 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009288 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009289 lineLen = len(line)
9290 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009291 }
Adam Langley95c29f32014-06-20 12:00:00 -07009292 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009293
9294 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009295}
9296
9297func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009298 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009299 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009300 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009301
Adam Langley7c803a62015-06-15 15:35:05 -07009302 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009303 addCipherSuiteTests()
9304 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009305 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009306 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009307 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009308 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009309 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009310 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009311 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009312 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009313 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009314 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009315 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009316 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009317 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009318 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009319 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009320 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009321 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009322 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009323 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009324 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009325 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009326 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009327 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009328 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009329 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009330 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009331 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009332 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009333 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009334 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009335 addCertificateTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009336
9337 var wg sync.WaitGroup
9338
Adam Langley7c803a62015-06-15 15:35:05 -07009339 statusChan := make(chan statusMsg, *numWorkers)
9340 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009341 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009342
EKRf71d7ed2016-08-06 13:25:12 -07009343 if len(*shimConfigFile) != 0 {
9344 encoded, err := ioutil.ReadFile(*shimConfigFile)
9345 if err != nil {
9346 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9347 os.Exit(1)
9348 }
9349
9350 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9351 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9352 os.Exit(1)
9353 }
9354 }
9355
David Benjamin025b3d32014-07-01 19:53:04 -04009356 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009357
Adam Langley7c803a62015-06-15 15:35:05 -07009358 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009359 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009360 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009361 }
9362
David Benjamin270f0a72016-03-17 14:41:36 -04009363 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009364 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009365 matched := true
9366 if len(*testToRun) != 0 {
9367 var err error
9368 matched, err = filepath.Match(*testToRun, testCases[i].name)
9369 if err != nil {
9370 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9371 os.Exit(1)
9372 }
9373 }
9374
EKRf71d7ed2016-08-06 13:25:12 -07009375 if !*includeDisabled {
9376 for pattern := range shimConfig.DisabledTests {
9377 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9378 if err != nil {
9379 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9380 os.Exit(1)
9381 }
9382
9383 if isDisabled {
9384 matched = false
9385 break
9386 }
9387 }
9388 }
9389
David Benjamin17e12922016-07-28 18:04:43 -04009390 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009391 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009392 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07009393 }
9394 }
David Benjamin17e12922016-07-28 18:04:43 -04009395
David Benjamin270f0a72016-03-17 14:41:36 -04009396 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009397 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009398 os.Exit(1)
9399 }
Adam Langley95c29f32014-06-20 12:00:00 -07009400
9401 close(testChan)
9402 wg.Wait()
9403 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009404 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009405
9406 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009407
9408 if *jsonOutput != "" {
9409 if err := testOutput.writeTo(*jsonOutput); err != nil {
9410 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9411 }
9412 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009413
EKR842ae6c2016-07-27 09:22:05 +02009414 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9415 os.Exit(1)
9416 }
9417
9418 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009419 os.Exit(1)
9420 }
Adam Langley95c29f32014-06-20 12:00:00 -07009421}