blob: 496f9a79c163168a04443c64db9635dee8e28fd0 [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"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
Adam Langley2ff79332017-02-28 13:45:39 -080025 "encoding/hex"
EKRf71d7ed2016-08-06 13:25:12 -070026 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040027 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020028 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070029 "flag"
30 "fmt"
31 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070032 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070033 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070034 "net"
35 "os"
36 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040037 "path"
David Benjamin17e12922016-07-28 18:04:43 -040038 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040039 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080040 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070041 "strings"
42 "sync"
43 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050044 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070045)
46
Adam Langley69a01602014-11-17 17:26:55 -080047var (
EKR842ae6c2016-07-27 09:22:05 +020048 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
49 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
50 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
51 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
52 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
53 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.")
54 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
55 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040056 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020057 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
58 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
59 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
60 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
61 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
62 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
63 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
64 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020065 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070066 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
67 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090068 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080069)
Adam Langley95c29f32014-06-20 12:00:00 -070070
EKRf71d7ed2016-08-06 13:25:12 -070071// ShimConfigurations is used with the “json” package and represents a shim
72// config file.
73type ShimConfiguration struct {
74 // DisabledTests maps from a glob-based pattern to a freeform string.
75 // The glob pattern is used to exclude tests from being run and the
76 // freeform string is unparsed but expected to explain why the test is
77 // disabled.
78 DisabledTests map[string]string
79
80 // ErrorMap maps from expected error strings to the correct error
81 // string for the shim in question. For example, it might map
82 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
83 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
84 ErrorMap map[string]string
David Benjamin794cc592017-03-25 22:24:23 -050085
86 // HalfRTTTickets is the number of half-RTT tickets the client should
87 // expect before half-RTT data when testing 0-RTT.
88 HalfRTTTickets int
EKRf71d7ed2016-08-06 13:25:12 -070089}
90
David Benjamin794cc592017-03-25 22:24:23 -050091// Setup shimConfig defaults aligning with BoringSSL.
92var shimConfig ShimConfiguration = ShimConfiguration{
93 HalfRTTTickets: 2,
94}
EKRf71d7ed2016-08-06 13:25:12 -070095
David Benjamin33863262016-07-08 17:20:12 -070096type testCert int
97
David Benjamin025b3d32014-07-01 19:53:04 -040098const (
David Benjamin33863262016-07-08 17:20:12 -070099 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -0400100 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +0900101 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -0800102 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -0700103 testCertECDSAP256
104 testCertECDSAP384
105 testCertECDSAP521
David Benjamin69522112017-03-28 15:38:29 -0500106 testCertEd25519
David Benjamin33863262016-07-08 17:20:12 -0700107)
108
109const (
110 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400111 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900112 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800113 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700114 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
115 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
116 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin69522112017-03-28 15:38:29 -0500117 ed25519CertificateFile = "ed25519_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400118)
119
120const (
David Benjamina08e49d2014-08-24 01:46:07 -0400121 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900123 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800124 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700125 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
126 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
127 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamin69522112017-03-28 15:38:29 -0500128 ed25519KeyFile = "ed25519_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400129 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400130)
131
David Benjamin7944a9f2016-07-12 22:27:01 -0400132var (
133 rsaCertificate Certificate
134 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900135 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800136 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400137 ecdsaP256Certificate Certificate
138 ecdsaP384Certificate Certificate
139 ecdsaP521Certificate Certificate
David Benjamin69522112017-03-28 15:38:29 -0500140 ed25519Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400141)
David Benjamin33863262016-07-08 17:20:12 -0700142
143var testCerts = []struct {
144 id testCert
145 certFile, keyFile string
146 cert *Certificate
147}{
148 {
149 id: testCertRSA,
150 certFile: rsaCertificateFile,
151 keyFile: rsaKeyFile,
152 cert: &rsaCertificate,
153 },
154 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400155 id: testCertRSA1024,
156 certFile: rsa1024CertificateFile,
157 keyFile: rsa1024KeyFile,
158 cert: &rsa1024Certificate,
159 },
160 {
David Benjamin2c516452016-11-15 10:16:54 +0900161 id: testCertRSAChain,
162 certFile: rsaChainCertificateFile,
163 keyFile: rsaChainKeyFile,
164 cert: &rsaChainCertificate,
165 },
166 {
Adam Langley898be922017-02-27 12:37:59 -0800167 id: testCertECDSAP224,
168 certFile: ecdsaP224CertificateFile,
169 keyFile: ecdsaP224KeyFile,
170 cert: &ecdsaP224Certificate,
171 },
172 {
David Benjamin33863262016-07-08 17:20:12 -0700173 id: testCertECDSAP256,
174 certFile: ecdsaP256CertificateFile,
175 keyFile: ecdsaP256KeyFile,
176 cert: &ecdsaP256Certificate,
177 },
178 {
179 id: testCertECDSAP384,
180 certFile: ecdsaP384CertificateFile,
181 keyFile: ecdsaP384KeyFile,
182 cert: &ecdsaP384Certificate,
183 },
184 {
185 id: testCertECDSAP521,
186 certFile: ecdsaP521CertificateFile,
187 keyFile: ecdsaP521KeyFile,
188 cert: &ecdsaP521Certificate,
189 },
David Benjamin69522112017-03-28 15:38:29 -0500190 {
191 id: testCertEd25519,
192 certFile: ed25519CertificateFile,
193 keyFile: ed25519KeyFile,
194 cert: &ed25519Certificate,
195 },
David Benjamin33863262016-07-08 17:20:12 -0700196}
197
David Benjamina08e49d2014-08-24 01:46:07 -0400198var channelIDKey *ecdsa.PrivateKey
199var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700200
David Benjamin61f95272014-11-25 01:55:35 -0500201var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800202var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500203
Steven Valdeza833c352016-11-01 13:39:36 -0400204var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800205var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400206
Adam Langley95c29f32014-06-20 12:00:00 -0700207func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700208 for i := range testCerts {
209 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
210 if err != nil {
211 panic(err)
212 }
213 cert.OCSPStaple = testOCSPResponse
214 cert.SignedCertificateTimestampList = testSCTList
215 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700216 }
David Benjamina08e49d2014-08-24 01:46:07 -0400217
Adam Langley7c803a62015-06-15 15:35:05 -0700218 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400219 if err != nil {
220 panic(err)
221 }
222 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
223 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
224 panic("bad key type")
225 }
226 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
227 if err != nil {
228 panic(err)
229 }
230 if channelIDKey.Curve != elliptic.P256() {
231 panic("bad curve")
232 }
233
234 channelIDBytes = make([]byte, 64)
235 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
236 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700237}
238
David Benjamin33863262016-07-08 17:20:12 -0700239func getRunnerCertificate(t testCert) Certificate {
240 for _, cert := range testCerts {
241 if cert.id == t {
242 return *cert.cert
243 }
244 }
245 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700246}
247
David Benjamin33863262016-07-08 17:20:12 -0700248func getShimCertificate(t testCert) string {
249 for _, cert := range testCerts {
250 if cert.id == t {
251 return cert.certFile
252 }
253 }
254 panic("Unknown test certificate")
255}
256
257func getShimKey(t testCert) string {
258 for _, cert := range testCerts {
259 if cert.id == t {
260 return cert.keyFile
261 }
262 }
263 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700264}
265
Steven Valdezc94998a2017-06-20 10:55:02 -0400266// configVersionToWire maps a protocol version to the default wire version to
267// test at that protocol.
268//
269// TODO(davidben): Rather than mapping these, make tlsVersions contains a list
270// of wire versions and test all of them.
271func configVersionToWire(vers uint16, protocol protocol) uint16 {
272 if protocol == dtls {
273 switch vers {
274 case VersionTLS12:
275 return VersionDTLS12
276 case VersionTLS10:
277 return VersionDTLS10
278 }
279 } else {
280 switch vers {
281 case VersionSSL30, VersionTLS10, VersionTLS11, VersionTLS12:
282 return vers
283 case VersionTLS13:
284 return tls13DraftVersion
285 }
286 }
287
288 panic("unknown version")
289}
290
Adam Langley2ff79332017-02-28 13:45:39 -0800291// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
292func encodeDERValues(values [][]byte) string {
293 var ret string
294 for i, v := range values {
295 if i > 0 {
296 ret += ","
297 }
298 ret += hex.EncodeToString(v)
299 }
300
301 return ret
302}
303
David Benjamin025b3d32014-07-01 19:53:04 -0400304type testType int
305
306const (
307 clientTest testType = iota
308 serverTest
309)
310
David Benjamin6fd297b2014-08-11 18:43:38 -0400311type protocol int
312
313const (
314 tls protocol = iota
315 dtls
316)
317
David Benjaminfc7b0862014-09-06 13:21:53 -0400318const (
319 alpn = 1
320 npn = 2
321)
322
Adam Langley95c29f32014-06-20 12:00:00 -0700323type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400324 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400325 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700326 name string
327 config Config
328 shouldFail bool
329 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700330 // expectedLocalError, if not empty, contains a substring that must be
331 // found in the local error.
332 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400333 // expectedVersion, if non-zero, specifies the TLS version that must be
334 // negotiated.
335 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400336 // expectedResumeVersion, if non-zero, specifies the TLS version that
337 // must be negotiated on resumption. If zero, expectedVersion is used.
338 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400339 // expectedCipher, if non-zero, specifies the TLS cipher suite that
340 // should be negotiated.
341 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400342 // expectChannelID controls whether the connection should have
343 // negotiated a Channel ID with channelIDKey.
344 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400345 // expectedNextProto controls whether the connection should
346 // negotiate a next protocol via NPN or ALPN.
347 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400348 // expectNoNextProto, if true, means that no next protocol should be
349 // negotiated.
350 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400351 // expectedNextProtoType, if non-zero, is the expected next
352 // protocol negotiation mechanism.
353 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500354 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
355 // should be negotiated. If zero, none should be negotiated.
356 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100357 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
358 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100359 // expectedSCTList, if not nil, is the expected SCT list to be received.
360 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700361 // expectedPeerSignatureAlgorithm, if not zero, is the signature
362 // algorithm that the peer should have used in the handshake.
363 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400364 // expectedCurveID, if not zero, is the curve that the handshake should
365 // have used.
366 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700367 // messageLen is the length, in bytes, of the test message that will be
368 // sent.
369 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400370 // messageCount is the number of test messages that will be sent.
371 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400372 // certFile is the path to the certificate to use for the server.
373 certFile string
374 // keyFile is the path to the private key to use for the server.
375 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400376 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400377 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400378 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400379 // resumeRenewedSession controls whether a third connection should be
380 // tested which attempts to resume the second connection's session.
381 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700382 // expectResumeRejected, if true, specifies that the attempted
383 // resumption must be rejected by the client. This is only valid for a
384 // serverTest.
385 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400386 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500387 // resumption. Unless newSessionsOnResume is set,
388 // SessionTicketKey, ServerSessionCache, and
389 // ClientSessionCache are copied from the initial connection's
390 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400391 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500392 // newSessionsOnResume, if true, will cause resumeConfig to
393 // use a different session resumption context.
394 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400395 // noSessionCache, if true, will cause the server to run without a
396 // session cache.
397 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400398 // sendPrefix sends a prefix on the socket before actually performing a
399 // handshake.
400 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400401 // shimWritesFirst controls whether the shim sends an initial "hello"
402 // message before doing a roundtrip with the runner.
403 shimWritesFirst bool
David Benjaminbbba9392017-04-06 12:54:12 -0400404 // readWithUnfinishedWrite behaves like shimWritesFirst, but the shim
405 // does not complete the write until responding to the first runner
406 // message.
407 readWithUnfinishedWrite bool
David Benjamin30789da2015-08-29 22:56:45 -0400408 // shimShutsDown, if true, runs a test where the shim shuts down the
409 // connection immediately after the handshake rather than echoing
410 // messages from the runner.
411 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400412 // renegotiate indicates the number of times the connection should be
413 // renegotiated during the exchange.
414 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400415 // sendHalfHelloRequest, if true, causes the server to send half a
416 // HelloRequest when the handshake completes.
417 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700418 // renegotiateCiphers is a list of ciphersuite ids that will be
419 // switched in just before renegotiation.
420 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500421 // replayWrites, if true, configures the underlying transport
422 // to replay every write it makes in DTLS tests.
423 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500424 // damageFirstWrite, if true, configures the underlying transport to
425 // damage the final byte of the first application data write.
426 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400427 // exportKeyingMaterial, if non-zero, configures the test to exchange
428 // keying material and verify they match.
429 exportKeyingMaterial int
430 exportLabel string
431 exportContext string
432 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400433 // flags, if not empty, contains a list of command-line flags that will
434 // be passed to the shim program.
435 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700436 // testTLSUnique, if true, causes the shim to send the tls-unique value
437 // which will be compared against the expected value.
438 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400439 // sendEmptyRecords is the number of consecutive empty records to send
David Benjamin24e58862017-06-14 18:45:29 -0400440 // before each test message.
David Benjamina8ebe222015-06-06 03:04:39 -0400441 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400442 // sendWarningAlerts is the number of consecutive warning alerts to send
David Benjamin24e58862017-06-14 18:45:29 -0400443 // before each test message.
David Benjamin24f346d2015-06-06 03:28:08 -0400444 sendWarningAlerts int
David Benjamin24e58862017-06-14 18:45:29 -0400445 // sendBogusAlertType, if true, causes a bogus alert of invalid type to
446 // be sent before each test message.
447 sendBogusAlertType bool
Steven Valdez32635b82016-08-16 11:25:03 -0400448 // sendKeyUpdates is the number of consecutive key updates to send
449 // before and after the test message.
450 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400451 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
452 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400453 // expectMessageDropped, if true, means the test message is expected to
454 // be dropped by the client rather than echoed back.
455 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900456 // expectPeerCertificate, if not nil, is the certificate chain the peer
457 // is expected to send.
458 expectPeerCertificate *Certificate
Steven Valdeze831a812017-03-09 14:56:07 -0500459 // shimPrefix is the prefix that the shim will send to the server.
460 shimPrefix string
461 // resumeShimPrefix is the prefix that the shim will send to the server on a
462 // resumption.
463 resumeShimPrefix string
Adam Langley95c29f32014-06-20 12:00:00 -0700464}
465
Adam Langley7c803a62015-06-15 15:35:05 -0700466var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700467
David Benjamin0fde2eb2017-06-30 19:11:22 -0400468func writeTranscript(test *testCase, path string, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500469 if len(data) == 0 {
470 return
471 }
472
David Benjamin0fde2eb2017-06-30 19:11:22 -0400473 settings, err := ioutil.ReadFile(path)
474 if err != nil {
475 fmt.Fprintf(os.Stderr, "Error reading %s: %s.\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500476 return
477 }
478
David Benjamin0fde2eb2017-06-30 19:11:22 -0400479 settings = append(settings, data...)
480 if err := ioutil.WriteFile(path, settings, 0644); err != nil {
481 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", path, err)
David Benjamin9867b7d2016-03-01 23:25:48 -0500482 }
483}
484
David Benjamin3ed59772016-03-08 12:50:21 -0500485// A timeoutConn implements an idle timeout on each Read and Write operation.
486type timeoutConn struct {
487 net.Conn
488 timeout time.Duration
489}
490
491func (t *timeoutConn) Read(b []byte) (int, error) {
492 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
493 return 0, err
494 }
495 return t.Conn.Read(b)
496}
497
498func (t *timeoutConn) Write(b []byte) (int, error) {
499 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
500 return 0, err
501 }
502 return t.Conn.Write(b)
503}
504
David Benjamin0fde2eb2017-06-30 19:11:22 -0400505func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, transcriptPrefix string, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400506 if !test.noSessionCache {
507 if config.ClientSessionCache == nil {
508 config.ClientSessionCache = NewLRUClientSessionCache(1)
509 }
510 if config.ServerSessionCache == nil {
511 config.ServerSessionCache = NewLRUServerSessionCache(1)
512 }
513 }
514 if test.testType == clientTest {
515 if len(config.Certificates) == 0 {
516 config.Certificates = []Certificate{rsaCertificate}
517 }
518 } else {
519 // Supply a ServerName to ensure a constant session cache key,
520 // rather than falling back to net.Conn.RemoteAddr.
521 if len(config.ServerName) == 0 {
522 config.ServerName = "test"
523 }
524 }
525 if *fuzzer {
526 config.Bugs.NullAllCiphers = true
527 }
David Benjamin01a90572016-09-22 00:11:43 -0400528 if *deterministic {
529 config.Time = func() time.Time { return time.Unix(1234, 1234) }
530 }
David Benjamine54af062016-08-08 19:21:18 -0400531
David Benjamin01784b42016-06-07 18:00:52 -0400532 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500533
David Benjamin6fd297b2014-08-11 18:43:38 -0400534 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500535 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
536 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500537 }
538
David Benjamin9867b7d2016-03-01 23:25:48 -0500539 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500540 local, peer := "client", "server"
541 if test.testType == clientTest {
542 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500543 }
David Benjaminebda9b32015-11-02 15:33:18 -0500544 connDebug := &recordingConn{
545 Conn: conn,
546 isDatagram: test.protocol == dtls,
547 local: local,
548 peer: peer,
549 }
550 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500551 if *flagDebug {
552 defer connDebug.WriteTo(os.Stdout)
553 }
David Benjamin0fde2eb2017-06-30 19:11:22 -0400554 if len(transcriptPrefix) != 0 {
David Benjamin9867b7d2016-03-01 23:25:48 -0500555 defer func() {
David Benjamin0fde2eb2017-06-30 19:11:22 -0400556 path := transcriptPrefix + strconv.Itoa(num)
557 writeTranscript(test, path, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500558 }()
559 }
David Benjaminebda9b32015-11-02 15:33:18 -0500560
561 if config.Bugs.PacketAdaptor != nil {
562 config.Bugs.PacketAdaptor.debug = connDebug
563 }
564 }
565
566 if test.replayWrites {
567 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400568 }
569
David Benjamin3ed59772016-03-08 12:50:21 -0500570 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500571 if test.damageFirstWrite {
572 connDamage = newDamageAdaptor(conn)
573 conn = connDamage
574 }
575
David Benjamin6fd297b2014-08-11 18:43:38 -0400576 if test.sendPrefix != "" {
577 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
578 return err
579 }
David Benjamin98e882e2014-08-08 13:24:34 -0400580 }
581
David Benjamin1d5c83e2014-07-22 19:20:02 -0400582 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400583 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400584 if test.protocol == dtls {
585 tlsConn = DTLSServer(conn, config)
586 } else {
587 tlsConn = Server(conn, config)
588 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400589 } else {
590 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400591 if test.protocol == dtls {
592 tlsConn = DTLSClient(conn, config)
593 } else {
594 tlsConn = Client(conn, config)
595 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400596 }
David Benjamin30789da2015-08-29 22:56:45 -0400597 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400598
Adam Langley95c29f32014-06-20 12:00:00 -0700599 if err := tlsConn.Handshake(); err != nil {
600 return err
601 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700602
David Benjamin01fe8202014-09-24 15:21:44 -0400603 // TODO(davidben): move all per-connection expectations into a dedicated
604 // expectations struct that can be specified separately for the two
605 // legs.
606 expectedVersion := test.expectedVersion
607 if isResume && test.expectedResumeVersion != 0 {
608 expectedVersion = test.expectedResumeVersion
609 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700610 connState := tlsConn.ConnectionState()
611 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400612 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400613 }
614
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700615 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400616 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
617 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700618 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
619 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
620 }
David Benjamin90da8c82015-04-20 14:57:57 -0400621
David Benjamina08e49d2014-08-24 01:46:07 -0400622 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700623 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400624 if channelID == nil {
625 return fmt.Errorf("no channel ID negotiated")
626 }
627 if channelID.Curve != channelIDKey.Curve ||
628 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
629 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
630 return fmt.Errorf("incorrect channel ID")
631 }
632 }
633
David Benjaminae2888f2014-09-06 12:58:58 -0400634 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700635 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400636 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
637 }
638 }
639
David Benjaminc7ce9772015-10-09 19:32:41 -0400640 if test.expectNoNextProto {
641 if actual := connState.NegotiatedProtocol; actual != "" {
642 return fmt.Errorf("got unexpected next proto %s", actual)
643 }
644 }
645
David Benjaminfc7b0862014-09-06 13:21:53 -0400646 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700647 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400648 return fmt.Errorf("next proto type mismatch")
649 }
650 }
651
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700652 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500653 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
654 }
655
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100656 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300657 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100658 }
659
Paul Lietar4fac72e2015-09-09 13:44:55 +0100660 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
661 return fmt.Errorf("SCT list mismatch")
662 }
663
Nick Harper60edffd2016-06-21 15:19:24 -0700664 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
665 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400666 }
667
Steven Valdez5440fe02016-07-18 12:40:30 -0400668 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
669 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
670 }
671
David Benjamin2c516452016-11-15 10:16:54 +0900672 if test.expectPeerCertificate != nil {
673 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
674 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
675 }
676 for i, cert := range connState.PeerCertificates {
677 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
678 return fmt.Errorf("peer certificate %d did not match", i+1)
679 }
680 }
681 }
682
David Benjaminc565ebb2015-04-03 04:06:36 -0400683 if test.exportKeyingMaterial > 0 {
684 actual := make([]byte, test.exportKeyingMaterial)
685 if _, err := io.ReadFull(tlsConn, actual); err != nil {
686 return err
687 }
688 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
689 if err != nil {
690 return err
691 }
692 if !bytes.Equal(actual, expected) {
693 return fmt.Errorf("keying material mismatch")
694 }
695 }
696
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700697 if test.testTLSUnique {
698 var peersValue [12]byte
699 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
700 return err
701 }
702 expected := tlsConn.ConnectionState().TLSUnique
703 if !bytes.Equal(peersValue[:], expected) {
704 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
705 }
706 }
707
David Benjamin47921102016-07-28 11:29:18 -0400708 if test.sendHalfHelloRequest {
709 tlsConn.SendHalfHelloRequest()
710 }
711
Steven Valdeze831a812017-03-09 14:56:07 -0500712 shimPrefix := test.shimPrefix
713 if isResume {
714 shimPrefix = test.resumeShimPrefix
715 }
716 if test.shimWritesFirst || test.readWithUnfinishedWrite {
717 shimPrefix = "hello"
718 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400719 if test.renegotiate > 0 {
David Benjaminbbba9392017-04-06 12:54:12 -0400720 // If readWithUnfinishedWrite is set, the shim prefix will be
721 // available later.
Steven Valdeze831a812017-03-09 14:56:07 -0500722 if shimPrefix != "" && !test.readWithUnfinishedWrite {
723 var buf = make([]byte, len(shimPrefix))
724 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400725 if err != nil {
726 return err
727 }
Steven Valdeze831a812017-03-09 14:56:07 -0500728 if string(buf) != shimPrefix {
729 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400730 }
Steven Valdeze831a812017-03-09 14:56:07 -0500731 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400732 }
733
Adam Langleycf2d4f42014-10-28 19:06:14 -0700734 if test.renegotiateCiphers != nil {
735 config.CipherSuites = test.renegotiateCiphers
736 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400737 for i := 0; i < test.renegotiate; i++ {
738 if err := tlsConn.Renegotiate(); err != nil {
739 return err
740 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700741 }
742 } else if test.renegotiateCiphers != nil {
743 panic("renegotiateCiphers without renegotiate")
744 }
745
David Benjamin5fa3eba2015-01-22 16:35:40 -0500746 if test.damageFirstWrite {
747 connDamage.setDamage(true)
748 tlsConn.Write([]byte("DAMAGED WRITE"))
749 connDamage.setDamage(false)
750 }
751
David Benjamin8e6db492015-07-25 18:29:23 -0400752 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700753 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400754 if test.protocol == dtls {
755 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
756 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700757 // Read until EOF.
758 _, err := io.Copy(ioutil.Discard, tlsConn)
759 return err
760 }
David Benjamin4417d052015-04-05 04:17:25 -0400761 if messageLen == 0 {
762 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700763 }
Adam Langley95c29f32014-06-20 12:00:00 -0700764
David Benjamin8e6db492015-07-25 18:29:23 -0400765 messageCount := test.messageCount
766 if messageCount == 0 {
767 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400768 }
769
David Benjamin8e6db492015-07-25 18:29:23 -0400770 for j := 0; j < messageCount; j++ {
Steven Valdez32635b82016-08-16 11:25:03 -0400771 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400772 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400773 }
774
David Benjamin8e6db492015-07-25 18:29:23 -0400775 for i := 0; i < test.sendEmptyRecords; i++ {
776 tlsConn.Write(nil)
777 }
778
779 for i := 0; i < test.sendWarningAlerts; i++ {
780 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
781 }
782
David Benjamin24e58862017-06-14 18:45:29 -0400783 if test.sendBogusAlertType {
784 tlsConn.SendAlert(0x42, alertUnexpectedMessage)
785 }
786
David Benjaminbbba9392017-04-06 12:54:12 -0400787 testMessage := make([]byte, messageLen)
788 for i := range testMessage {
789 testMessage[i] = 0x42 ^ byte(j)
790 }
791 tlsConn.Write(testMessage)
792
793 // Consume the shim prefix if needed.
Steven Valdeze831a812017-03-09 14:56:07 -0500794 if shimPrefix != "" {
795 var buf = make([]byte, len(shimPrefix))
796 _, err := io.ReadFull(tlsConn, buf)
David Benjaminbbba9392017-04-06 12:54:12 -0400797 if err != nil {
798 return err
799 }
Steven Valdeze831a812017-03-09 14:56:07 -0500800 if string(buf) != shimPrefix {
801 return fmt.Errorf("bad initial message %v vs %v", string(buf), shimPrefix)
David Benjaminbbba9392017-04-06 12:54:12 -0400802 }
Steven Valdeze831a812017-03-09 14:56:07 -0500803 shimPrefix = ""
David Benjaminbbba9392017-04-06 12:54:12 -0400804 }
805
David Benjamin4f75aaf2015-09-01 16:53:10 -0400806 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400807 // The shim will not respond.
808 continue
809 }
810
David Benjaminbbba9392017-04-06 12:54:12 -0400811 // Process the KeyUpdate ACK. However many KeyUpdates the runner
812 // sends, the shim should respond only once.
813 if test.sendKeyUpdates > 0 && test.keyUpdateRequest == keyUpdateRequested {
814 if err := tlsConn.ReadKeyUpdateACK(); err != nil {
815 return err
816 }
817 }
818
David Benjamin8e6db492015-07-25 18:29:23 -0400819 buf := make([]byte, len(testMessage))
820 if test.protocol == dtls {
821 bufTmp := make([]byte, len(buf)+1)
822 n, err := tlsConn.Read(bufTmp)
823 if err != nil {
824 return err
825 }
826 if n != len(buf) {
827 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
828 }
829 copy(buf, bufTmp)
830 } else {
831 _, err := io.ReadFull(tlsConn, buf)
832 if err != nil {
833 return err
834 }
835 }
836
837 for i, v := range buf {
838 if v != testMessage[i]^0xff {
839 return fmt.Errorf("bad reply contents at byte %d", i)
840 }
Adam Langley95c29f32014-06-20 12:00:00 -0700841 }
842 }
843
844 return nil
845}
846
David Benjamin325b5c32014-07-01 19:40:31 -0400847func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400848 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700849 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400850 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700851 }
David Benjamin325b5c32014-07-01 19:40:31 -0400852 valgrindArgs = append(valgrindArgs, path)
853 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700854
David Benjamin325b5c32014-07-01 19:40:31 -0400855 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700856}
857
David Benjamin325b5c32014-07-01 19:40:31 -0400858func gdbOf(path string, args ...string) *exec.Cmd {
859 xtermArgs := []string{"-e", "gdb", "--args"}
860 xtermArgs = append(xtermArgs, path)
861 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700862
David Benjamin325b5c32014-07-01 19:40:31 -0400863 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700864}
865
David Benjamind16bf342015-12-18 00:53:12 -0500866func lldbOf(path string, args ...string) *exec.Cmd {
867 xtermArgs := []string{"-e", "lldb", "--"}
868 xtermArgs = append(xtermArgs, path)
869 xtermArgs = append(xtermArgs, args...)
870
871 return exec.Command("xterm", xtermArgs...)
872}
873
EKR842ae6c2016-07-27 09:22:05 +0200874var (
875 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
876 errUnimplemented = errors.New("child process does not implement needed flags")
877)
Adam Langley69a01602014-11-17 17:26:55 -0800878
David Benjamin87c8a642015-02-21 01:54:29 -0500879// accept accepts a connection from listener, unless waitChan signals a process
880// exit first.
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400881func acceptOrWait(listener *net.TCPListener, waitChan chan error) (net.Conn, error) {
David Benjamin87c8a642015-02-21 01:54:29 -0500882 type connOrError struct {
883 conn net.Conn
884 err error
885 }
886 connChan := make(chan connOrError, 1)
887 go func() {
David Benjamin4d1f4ba2017-05-08 15:54:39 -0400888 listener.SetDeadline(time.Now().Add(*idleTimeout))
David Benjamin87c8a642015-02-21 01:54:29 -0500889 conn, err := listener.Accept()
890 connChan <- connOrError{conn, err}
891 close(connChan)
892 }()
893 select {
894 case result := <-connChan:
895 return result.conn, result.err
896 case childErr := <-waitChan:
897 waitChan <- childErr
898 return nil, fmt.Errorf("child exited early: %s", childErr)
899 }
900}
901
EKRf71d7ed2016-08-06 13:25:12 -0700902func translateExpectedError(errorStr string) string {
903 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
904 return translated
905 }
906
907 if *looseErrors {
908 return ""
909 }
910
911 return errorStr
912}
913
Adam Langley7c803a62015-06-15 15:35:05 -0700914func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400915 // Help debugging panics on the Go side.
916 defer func() {
917 if r := recover(); r != nil {
918 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
919 panic(r)
920 }
921 }()
922
Adam Langley38311732014-10-16 19:04:35 -0700923 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
924 panic("Error expected without shouldFail in " + test.name)
925 }
926
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700927 if test.expectResumeRejected && !test.resumeSession {
928 panic("expectResumeRejected without resumeSession in " + test.name)
929 }
930
Adam Langley33b1d4f2016-12-07 15:03:45 -0800931 for _, ver := range tlsVersions {
932 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
933 continue
934 }
935
936 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
937 continue
938 }
939
940 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
941 }
942
Matthew Braithwaite2d04cf02017-05-19 18:13:25 -0700943 listener, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv6loopback})
944 if err != nil {
945 listener, err = net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
946 }
David Benjamin87c8a642015-02-21 01:54:29 -0500947 if err != nil {
948 panic(err)
949 }
950 defer func() {
951 if listener != nil {
952 listener.Close()
953 }
954 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700955
David Benjamin87c8a642015-02-21 01:54:29 -0500956 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400957 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400958 flags = append(flags, "-server")
959
David Benjamin025b3d32014-07-01 19:53:04 -0400960 flags = append(flags, "-key-file")
961 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700962 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400963 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700964 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400965 }
966
967 flags = append(flags, "-cert-file")
968 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700969 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400970 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700971 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400972 }
973 }
David Benjamin5a593af2014-08-11 19:51:50 -0400974
David Benjamin6fd297b2014-08-11 18:43:38 -0400975 if test.protocol == dtls {
976 flags = append(flags, "-dtls")
977 }
978
David Benjamin46662482016-08-17 00:51:00 -0400979 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400980 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400981 resumeCount++
982 if test.resumeRenewedSession {
983 resumeCount++
984 }
985 }
986
987 if resumeCount > 0 {
988 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400989 }
990
David Benjamine58c4f52014-08-24 03:47:07 -0400991 if test.shimWritesFirst {
992 flags = append(flags, "-shim-writes-first")
993 }
994
David Benjaminbbba9392017-04-06 12:54:12 -0400995 if test.readWithUnfinishedWrite {
996 flags = append(flags, "-read-with-unfinished-write")
997 }
998
David Benjamin30789da2015-08-29 22:56:45 -0400999 if test.shimShutsDown {
1000 flags = append(flags, "-shim-shuts-down")
1001 }
1002
David Benjaminc565ebb2015-04-03 04:06:36 -04001003 if test.exportKeyingMaterial > 0 {
1004 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
1005 flags = append(flags, "-export-label", test.exportLabel)
1006 flags = append(flags, "-export-context", test.exportContext)
1007 if test.useExportContext {
1008 flags = append(flags, "-use-export-context")
1009 }
1010 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -07001011 if test.expectResumeRejected {
1012 flags = append(flags, "-expect-session-miss")
1013 }
David Benjaminc565ebb2015-04-03 04:06:36 -04001014
Adam Langleyaf0e32c2015-06-03 09:57:23 -07001015 if test.testTLSUnique {
1016 flags = append(flags, "-tls-unique")
1017 }
1018
David Benjamin0fde2eb2017-06-30 19:11:22 -04001019 var transcriptPrefix string
1020 if len(*transcriptDir) != 0 {
1021 protocol := "tls"
1022 if test.protocol == dtls {
1023 protocol = "dtls"
1024 }
1025
1026 side := "client"
1027 if test.testType == serverTest {
1028 side = "server"
1029 }
1030
1031 dir := filepath.Join(*transcriptDir, protocol, side)
1032 if err := os.MkdirAll(dir, 0755); err != nil {
1033 return err
1034 }
1035 transcriptPrefix = filepath.Join(dir, test.name+"-")
1036 flags = append(flags, "-write-settings", transcriptPrefix)
1037 }
1038
David Benjamin025b3d32014-07-01 19:53:04 -04001039 flags = append(flags, test.flags...)
1040
1041 var shim *exec.Cmd
1042 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -07001043 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -07001044 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -07001045 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -05001046 } else if *useLLDB {
1047 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001048 } else {
Adam Langley7c803a62015-06-15 15:35:05 -07001049 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -04001050 }
David Benjamin025b3d32014-07-01 19:53:04 -04001051 shim.Stdin = os.Stdin
1052 var stdoutBuf, stderrBuf bytes.Buffer
1053 shim.Stdout = &stdoutBuf
1054 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -08001055 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -05001056 shim.Env = os.Environ()
1057 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -08001058 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -04001059 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -08001060 }
1061 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
1062 }
David Benjamin025b3d32014-07-01 19:53:04 -04001063
1064 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -07001065 panic(err)
1066 }
David Benjamin87c8a642015-02-21 01:54:29 -05001067 waitChan := make(chan error, 1)
1068 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -07001069
1070 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -07001071
David Benjamin7a4aaa42016-09-20 17:58:14 -04001072 if *deterministic {
1073 config.Rand = &deterministicRand{}
1074 }
1075
David Benjamin87c8a642015-02-21 01:54:29 -05001076 conn, err := acceptOrWait(listener, waitChan)
1077 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001078 err = doExchange(test, &config, conn, false /* not a resumption */, transcriptPrefix, 0)
David Benjamin87c8a642015-02-21 01:54:29 -05001079 conn.Close()
1080 }
David Benjamin65ea8ff2014-11-23 03:01:00 -05001081
David Benjamin46662482016-08-17 00:51:00 -04001082 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -04001083 var resumeConfig Config
1084 if test.resumeConfig != nil {
1085 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -04001086 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -05001087 resumeConfig.SessionTicketKey = config.SessionTicketKey
1088 resumeConfig.ClientSessionCache = config.ClientSessionCache
1089 resumeConfig.ServerSessionCache = config.ServerSessionCache
1090 }
David Benjamin2e045a92016-06-08 13:09:56 -04001091 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001092 } else {
1093 resumeConfig = config
1094 }
David Benjamin87c8a642015-02-21 01:54:29 -05001095 var connResume net.Conn
1096 connResume, err = acceptOrWait(listener, waitChan)
1097 if err == nil {
David Benjamin0fde2eb2017-06-30 19:11:22 -04001098 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, transcriptPrefix, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001099 connResume.Close()
1100 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001101 }
1102
David Benjamin87c8a642015-02-21 01:54:29 -05001103 // Close the listener now. This is to avoid hangs should the shim try to
1104 // open more connections than expected.
1105 listener.Close()
1106 listener = nil
1107
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001108 var shimKilledLock sync.Mutex
1109 var shimKilled bool
1110 waitTimeout := time.AfterFunc(*idleTimeout, func() {
1111 shimKilledLock.Lock()
1112 shimKilled = true
1113 shimKilledLock.Unlock()
1114 shim.Process.Kill()
1115 })
David Benjamin87c8a642015-02-21 01:54:29 -05001116 childErr := <-waitChan
David Benjamin4d1f4ba2017-05-08 15:54:39 -04001117 waitTimeout.Stop()
1118 shimKilledLock.Lock()
1119 if shimKilled && err == nil {
1120 err = errors.New("timeout waiting for the shim to exit.")
1121 }
1122 shimKilledLock.Unlock()
David Benjamind2ba8892016-09-20 19:41:04 -04001123 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001124 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001125 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1126 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001127 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001128 case 89:
1129 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001130 case 99:
1131 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001132 }
1133 }
Adam Langley95c29f32014-06-20 12:00:00 -07001134
David Benjamin9bea3492016-03-02 10:59:16 -05001135 // Account for Windows line endings.
1136 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1137 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001138
1139 // Separate the errors from the shim and those from tools like
1140 // AddressSanitizer.
1141 var extraStderr string
1142 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1143 stderr = stderrParts[0]
1144 extraStderr = stderrParts[1]
1145 }
1146
Adam Langley95c29f32014-06-20 12:00:00 -07001147 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001148 expectedError := translateExpectedError(test.expectedError)
1149 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001150
Adam Langleyac61fa32014-06-23 12:03:11 -07001151 localError := "none"
1152 if err != nil {
1153 localError = err.Error()
1154 }
1155 if len(test.expectedLocalError) != 0 {
1156 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1157 }
Adam Langley95c29f32014-06-20 12:00:00 -07001158
1159 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001160 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001161 if childErr != nil {
1162 childError = childErr.Error()
1163 }
1164
1165 var msg string
1166 switch {
1167 case failed && !test.shouldFail:
1168 msg = "unexpected failure"
1169 case !failed && test.shouldFail:
1170 msg = "unexpected success"
1171 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001172 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001173 default:
1174 panic("internal error")
1175 }
1176
David Benjamin9aafb642016-09-20 19:36:53 -04001177 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 -07001178 }
1179
David Benjamind2ba8892016-09-20 19:41:04 -04001180 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
Adam Langleyc88f2452017-04-27 14:15:37 -07001181 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001182 }
1183
David Benjamind2ba8892016-09-20 19:41:04 -04001184 if *useValgrind && isValgrindError {
1185 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1186 }
1187
Adam Langley95c29f32014-06-20 12:00:00 -07001188 return nil
1189}
1190
David Benjaminaa012042016-12-10 13:33:05 -05001191type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001192 name string
1193 version uint16
David Benjamin353577c2017-06-29 15:54:58 -04001194 // excludeFlag is the legacy shim flag to disable the version.
1195 excludeFlag string
1196 hasDTLS bool
1197 // shimTLS and shimDTLS are values the shim uses to refer to these
1198 // versions in TLS and DTLS, respectively.
1199 shimTLS, shimDTLS int
1200}
1201
1202func (vers tlsVersion) shimFlag(protocol protocol) string {
1203 if protocol == dtls {
1204 return strconv.Itoa(vers.shimDTLS)
1205 }
1206 return strconv.Itoa(vers.shimTLS)
David Benjaminaa012042016-12-10 13:33:05 -05001207}
1208
1209var tlsVersions = []tlsVersion{
David Benjamin353577c2017-06-29 15:54:58 -04001210 {"SSL3", VersionSSL30, "-no-ssl3", false, VersionSSL30, 0},
1211 {"TLS1", VersionTLS10, "-no-tls1", true, VersionTLS10, VersionDTLS10},
1212 {"TLS11", VersionTLS11, "-no-tls11", false, VersionTLS11, 0},
1213 {"TLS12", VersionTLS12, "-no-tls12", true, VersionTLS12, VersionDTLS12},
1214 {"TLS13", VersionTLS13, "-no-tls13", false, VersionTLS13, 0},
Adam Langley95c29f32014-06-20 12:00:00 -07001215}
1216
David Benjaminaa012042016-12-10 13:33:05 -05001217type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001218 name string
1219 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001220}
1221
1222var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001223 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001224 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001225 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001226 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001227 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001228 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001229 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001230 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1231 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001232 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1233 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001234 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001235 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001236 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001237 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001238 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001239 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001240 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001241 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001242 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001243 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001244 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1245 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001246 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1247 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001248 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001249 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1250 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1251 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001252 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001253}
1254
David Benjamin8b8c0062014-11-23 02:47:52 -05001255func hasComponent(suiteName, component string) bool {
1256 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1257}
1258
David Benjaminf7768e42014-08-31 02:06:47 -04001259func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001260 return hasComponent(suiteName, "GCM") ||
1261 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001262 hasComponent(suiteName, "SHA384") ||
1263 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001264}
1265
Nick Harper1fd39d82016-06-14 18:14:35 -07001266func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001267 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001268}
1269
David Benjamin8b8c0062014-11-23 02:47:52 -05001270func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001271 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001272}
1273
Adam Langleya7997f12015-05-14 17:38:50 -07001274func bigFromHex(hex string) *big.Int {
1275 ret, ok := new(big.Int).SetString(hex, 16)
1276 if !ok {
1277 panic("failed to parse hex number 0x" + hex)
1278 }
1279 return ret
1280}
1281
Adam Langley7c803a62015-06-15 15:35:05 -07001282func addBasicTests() {
1283 basicTests := []testCase{
1284 {
Adam Langley7c803a62015-06-15 15:35:05 -07001285 name: "NoFallbackSCSV",
1286 config: Config{
1287 Bugs: ProtocolBugs{
1288 FailIfNotFallbackSCSV: true,
1289 },
1290 },
1291 shouldFail: true,
1292 expectedLocalError: "no fallback SCSV found",
1293 },
1294 {
1295 name: "SendFallbackSCSV",
1296 config: Config{
1297 Bugs: ProtocolBugs{
1298 FailIfNotFallbackSCSV: true,
1299 },
1300 },
1301 flags: []string{"-fallback-scsv"},
1302 },
1303 {
1304 name: "ClientCertificateTypes",
1305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001306 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 ClientAuth: RequestClientCert,
1308 ClientCertificateTypes: []byte{
1309 CertTypeDSSSign,
1310 CertTypeRSASign,
1311 CertTypeECDSASign,
1312 },
1313 },
1314 flags: []string{
1315 "-expect-certificate-types",
1316 base64.StdEncoding.EncodeToString([]byte{
1317 CertTypeDSSSign,
1318 CertTypeRSASign,
1319 CertTypeECDSASign,
1320 }),
1321 },
1322 },
1323 {
Adam Langley7c803a62015-06-15 15:35:05 -07001324 name: "UnauthenticatedECDH",
1325 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001326 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1328 Bugs: ProtocolBugs{
1329 UnauthenticatedECDH: true,
1330 },
1331 },
1332 shouldFail: true,
1333 expectedError: ":UNEXPECTED_MESSAGE:",
1334 },
1335 {
1336 name: "SkipCertificateStatus",
1337 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001338 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001339 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1340 Bugs: ProtocolBugs{
1341 SkipCertificateStatus: true,
1342 },
1343 },
1344 flags: []string{
1345 "-enable-ocsp-stapling",
1346 },
1347 },
1348 {
1349 name: "SkipServerKeyExchange",
1350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001351 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001352 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1353 Bugs: ProtocolBugs{
1354 SkipServerKeyExchange: true,
1355 },
1356 },
1357 shouldFail: true,
1358 expectedError: ":UNEXPECTED_MESSAGE:",
1359 },
1360 {
Adam Langley7c803a62015-06-15 15:35:05 -07001361 testType: serverTest,
1362 name: "Alert",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 SendSpuriousAlert: alertRecordOverflow,
1366 },
1367 },
1368 shouldFail: true,
1369 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1370 },
1371 {
1372 protocol: dtls,
1373 testType: serverTest,
1374 name: "Alert-DTLS",
1375 config: Config{
1376 Bugs: ProtocolBugs{
1377 SendSpuriousAlert: alertRecordOverflow,
1378 },
1379 },
1380 shouldFail: true,
1381 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1382 },
1383 {
1384 testType: serverTest,
1385 name: "FragmentAlert",
1386 config: Config{
1387 Bugs: ProtocolBugs{
1388 FragmentAlert: true,
1389 SendSpuriousAlert: alertRecordOverflow,
1390 },
1391 },
1392 shouldFail: true,
1393 expectedError: ":BAD_ALERT:",
1394 },
1395 {
1396 protocol: dtls,
1397 testType: serverTest,
1398 name: "FragmentAlert-DTLS",
1399 config: Config{
1400 Bugs: ProtocolBugs{
1401 FragmentAlert: true,
1402 SendSpuriousAlert: alertRecordOverflow,
1403 },
1404 },
1405 shouldFail: true,
1406 expectedError: ":BAD_ALERT:",
1407 },
1408 {
1409 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001410 name: "DoubleAlert",
1411 config: Config{
1412 Bugs: ProtocolBugs{
1413 DoubleAlert: true,
1414 SendSpuriousAlert: alertRecordOverflow,
1415 },
1416 },
1417 shouldFail: true,
1418 expectedError: ":BAD_ALERT:",
1419 },
1420 {
1421 protocol: dtls,
1422 testType: serverTest,
1423 name: "DoubleAlert-DTLS",
1424 config: Config{
1425 Bugs: ProtocolBugs{
1426 DoubleAlert: true,
1427 SendSpuriousAlert: alertRecordOverflow,
1428 },
1429 },
1430 shouldFail: true,
1431 expectedError: ":BAD_ALERT:",
1432 },
1433 {
Adam Langley7c803a62015-06-15 15:35:05 -07001434 name: "SkipNewSessionTicket",
1435 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001436 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001437 Bugs: ProtocolBugs{
1438 SkipNewSessionTicket: true,
1439 },
1440 },
1441 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001442 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001443 },
1444 {
1445 testType: serverTest,
1446 name: "FallbackSCSV",
1447 config: Config{
1448 MaxVersion: VersionTLS11,
1449 Bugs: ProtocolBugs{
1450 SendFallbackSCSV: true,
1451 },
1452 },
David Benjamin56cadc32016-12-16 19:54:11 -05001453 shouldFail: true,
1454 expectedError: ":INAPPROPRIATE_FALLBACK:",
1455 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001456 },
1457 {
1458 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001459 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001460 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001461 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001462 Bugs: ProtocolBugs{
1463 SendFallbackSCSV: true,
1464 },
1465 },
1466 },
1467 {
1468 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001469 name: "FallbackSCSV-VersionMatch-TLS12",
1470 config: Config{
1471 MaxVersion: VersionTLS12,
1472 Bugs: ProtocolBugs{
1473 SendFallbackSCSV: true,
1474 },
1475 },
1476 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1477 },
1478 {
1479 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001480 name: "FragmentedClientVersion",
1481 config: Config{
1482 Bugs: ProtocolBugs{
1483 MaxHandshakeRecordLength: 1,
1484 FragmentClientVersion: true,
1485 },
1486 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001487 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001488 },
1489 {
Adam Langley7c803a62015-06-15 15:35:05 -07001490 testType: serverTest,
1491 name: "HttpGET",
1492 sendPrefix: "GET / HTTP/1.0\n",
1493 shouldFail: true,
1494 expectedError: ":HTTP_REQUEST:",
1495 },
1496 {
1497 testType: serverTest,
1498 name: "HttpPOST",
1499 sendPrefix: "POST / HTTP/1.0\n",
1500 shouldFail: true,
1501 expectedError: ":HTTP_REQUEST:",
1502 },
1503 {
1504 testType: serverTest,
1505 name: "HttpHEAD",
1506 sendPrefix: "HEAD / HTTP/1.0\n",
1507 shouldFail: true,
1508 expectedError: ":HTTP_REQUEST:",
1509 },
1510 {
1511 testType: serverTest,
1512 name: "HttpPUT",
1513 sendPrefix: "PUT / HTTP/1.0\n",
1514 shouldFail: true,
1515 expectedError: ":HTTP_REQUEST:",
1516 },
1517 {
1518 testType: serverTest,
1519 name: "HttpCONNECT",
1520 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1521 shouldFail: true,
1522 expectedError: ":HTTPS_PROXY_REQUEST:",
1523 },
1524 {
1525 testType: serverTest,
1526 name: "Garbage",
1527 sendPrefix: "blah",
1528 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001529 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001530 },
1531 {
Adam Langley7c803a62015-06-15 15:35:05 -07001532 name: "RSAEphemeralKey",
1533 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001534 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001535 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1536 Bugs: ProtocolBugs{
1537 RSAEphemeralKey: true,
1538 },
1539 },
1540 shouldFail: true,
1541 expectedError: ":UNEXPECTED_MESSAGE:",
1542 },
1543 {
1544 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001545 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001546 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001547 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001548 },
1549 {
1550 protocol: dtls,
1551 name: "DisableEverything-DTLS",
1552 flags: []string{"-no-tls12", "-no-tls1"},
1553 shouldFail: true,
David Benjamin3cfeb952017-03-01 16:48:38 -05001554 expectedError: ":NO_SUPPORTED_VERSIONS_ENABLED:",
Adam Langley7c803a62015-06-15 15:35:05 -07001555 },
1556 {
Adam Langley7c803a62015-06-15 15:35:05 -07001557 protocol: dtls,
1558 testType: serverTest,
1559 name: "MTU",
1560 config: Config{
1561 Bugs: ProtocolBugs{
1562 MaxPacketLength: 256,
1563 },
1564 },
1565 flags: []string{"-mtu", "256"},
1566 },
1567 {
1568 protocol: dtls,
1569 testType: serverTest,
1570 name: "MTUExceeded",
1571 config: Config{
1572 Bugs: ProtocolBugs{
1573 MaxPacketLength: 255,
1574 },
1575 },
1576 flags: []string{"-mtu", "256"},
1577 shouldFail: true,
1578 expectedLocalError: "dtls: exceeded maximum packet length",
1579 },
1580 {
Adam Langley7c803a62015-06-15 15:35:05 -07001581 name: "EmptyCertificateList",
1582 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001583 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001584 Bugs: ProtocolBugs{
1585 EmptyCertificateList: true,
1586 },
1587 },
1588 shouldFail: true,
1589 expectedError: ":DECODE_ERROR:",
1590 },
1591 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001592 name: "EmptyCertificateList-TLS13",
1593 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001594 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001595 Bugs: ProtocolBugs{
1596 EmptyCertificateList: true,
1597 },
1598 },
1599 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001600 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001601 },
1602 {
Adam Langley7c803a62015-06-15 15:35:05 -07001603 name: "TLSFatalBadPackets",
1604 damageFirstWrite: true,
1605 shouldFail: true,
1606 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1607 },
1608 {
1609 protocol: dtls,
1610 name: "DTLSIgnoreBadPackets",
1611 damageFirstWrite: true,
1612 },
1613 {
1614 protocol: dtls,
1615 name: "DTLSIgnoreBadPackets-Async",
1616 damageFirstWrite: true,
1617 flags: []string{"-async"},
1618 },
1619 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001620 name: "AppDataBeforeHandshake",
1621 config: Config{
1622 Bugs: ProtocolBugs{
1623 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1624 },
1625 },
1626 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001627 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001628 },
1629 {
1630 name: "AppDataBeforeHandshake-Empty",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 AppDataBeforeHandshake: []byte{},
1634 },
1635 },
1636 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001637 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001638 },
1639 {
1640 protocol: dtls,
1641 name: "AppDataBeforeHandshake-DTLS",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1645 },
1646 },
1647 shouldFail: true,
1648 expectedError: ":UNEXPECTED_RECORD:",
1649 },
1650 {
1651 protocol: dtls,
1652 name: "AppDataBeforeHandshake-DTLS-Empty",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 AppDataBeforeHandshake: []byte{},
1656 },
1657 },
1658 shouldFail: true,
1659 expectedError: ":UNEXPECTED_RECORD:",
1660 },
1661 {
Adam Langley7c803a62015-06-15 15:35:05 -07001662 name: "AppDataAfterChangeCipherSpec",
1663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001664 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001665 Bugs: ProtocolBugs{
1666 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1667 },
1668 },
1669 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001670 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001671 },
1672 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001673 name: "AppDataAfterChangeCipherSpec-Empty",
1674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001675 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001676 Bugs: ProtocolBugs{
1677 AppDataAfterChangeCipherSpec: []byte{},
1678 },
1679 },
1680 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001681 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001682 },
1683 {
Adam Langley7c803a62015-06-15 15:35:05 -07001684 protocol: dtls,
1685 name: "AppDataAfterChangeCipherSpec-DTLS",
1686 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001687 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001688 Bugs: ProtocolBugs{
1689 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1690 },
1691 },
1692 // BoringSSL's DTLS implementation will drop the out-of-order
1693 // application data.
1694 },
1695 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001696 protocol: dtls,
1697 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1698 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001699 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001700 Bugs: ProtocolBugs{
1701 AppDataAfterChangeCipherSpec: []byte{},
1702 },
1703 },
1704 // BoringSSL's DTLS implementation will drop the out-of-order
1705 // application data.
1706 },
1707 {
Adam Langley7c803a62015-06-15 15:35:05 -07001708 name: "AlertAfterChangeCipherSpec",
1709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001710 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001711 Bugs: ProtocolBugs{
1712 AlertAfterChangeCipherSpec: alertRecordOverflow,
1713 },
1714 },
1715 shouldFail: true,
1716 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1717 },
1718 {
1719 protocol: dtls,
1720 name: "AlertAfterChangeCipherSpec-DTLS",
1721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001722 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001723 Bugs: ProtocolBugs{
1724 AlertAfterChangeCipherSpec: alertRecordOverflow,
1725 },
1726 },
1727 shouldFail: true,
1728 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1729 },
1730 {
1731 protocol: dtls,
1732 name: "ReorderHandshakeFragments-Small-DTLS",
1733 config: Config{
1734 Bugs: ProtocolBugs{
1735 ReorderHandshakeFragments: true,
1736 // Small enough that every handshake message is
1737 // fragmented.
1738 MaxHandshakeRecordLength: 2,
1739 },
1740 },
1741 },
1742 {
1743 protocol: dtls,
1744 name: "ReorderHandshakeFragments-Large-DTLS",
1745 config: Config{
1746 Bugs: ProtocolBugs{
1747 ReorderHandshakeFragments: true,
1748 // Large enough that no handshake message is
1749 // fragmented.
1750 MaxHandshakeRecordLength: 2048,
1751 },
1752 },
1753 },
1754 {
1755 protocol: dtls,
1756 name: "MixCompleteMessageWithFragments-DTLS",
1757 config: Config{
1758 Bugs: ProtocolBugs{
1759 ReorderHandshakeFragments: true,
1760 MixCompleteMessageWithFragments: true,
1761 MaxHandshakeRecordLength: 2,
1762 },
1763 },
1764 },
1765 {
1766 name: "SendInvalidRecordType",
1767 config: Config{
1768 Bugs: ProtocolBugs{
1769 SendInvalidRecordType: true,
1770 },
1771 },
1772 shouldFail: true,
1773 expectedError: ":UNEXPECTED_RECORD:",
1774 },
1775 {
1776 protocol: dtls,
1777 name: "SendInvalidRecordType-DTLS",
1778 config: Config{
1779 Bugs: ProtocolBugs{
1780 SendInvalidRecordType: true,
1781 },
1782 },
1783 shouldFail: true,
1784 expectedError: ":UNEXPECTED_RECORD:",
1785 },
1786 {
1787 name: "FalseStart-SkipServerSecondLeg",
1788 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001789 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1791 NextProtos: []string{"foo"},
1792 Bugs: ProtocolBugs{
1793 SkipNewSessionTicket: true,
1794 SkipChangeCipherSpec: true,
1795 SkipFinished: true,
1796 ExpectFalseStart: true,
1797 },
1798 },
1799 flags: []string{
1800 "-false-start",
1801 "-handshake-never-done",
1802 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04001803 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07001804 },
1805 shimWritesFirst: true,
1806 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001807 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001808 },
1809 {
1810 name: "FalseStart-SkipServerSecondLeg-Implicit",
1811 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001812 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1814 NextProtos: []string{"foo"},
1815 Bugs: ProtocolBugs{
1816 SkipNewSessionTicket: true,
1817 SkipChangeCipherSpec: true,
1818 SkipFinished: true,
1819 },
1820 },
1821 flags: []string{
1822 "-implicit-handshake",
1823 "-false-start",
1824 "-handshake-never-done",
1825 "-advertise-alpn", "\x03foo",
1826 },
1827 shouldFail: true,
David Benjamin5aaaa982017-06-22 15:03:18 -04001828 expectedError: ":APPLICATION_DATA_INSTEAD_OF_HANDSHAKE:",
Adam Langley7c803a62015-06-15 15:35:05 -07001829 },
1830 {
1831 testType: serverTest,
1832 name: "FailEarlyCallback",
1833 flags: []string{"-fail-early-callback"},
1834 shouldFail: true,
1835 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001836 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001837 },
1838 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001839 name: "FailCertCallback-Client-TLS12",
1840 config: Config{
1841 MaxVersion: VersionTLS12,
1842 ClientAuth: RequestClientCert,
1843 },
1844 flags: []string{"-fail-cert-callback"},
1845 shouldFail: true,
1846 expectedError: ":CERT_CB_ERROR:",
1847 expectedLocalError: "remote error: internal error",
1848 },
1849 {
1850 testType: serverTest,
1851 name: "FailCertCallback-Server-TLS12",
1852 config: Config{
1853 MaxVersion: VersionTLS12,
1854 },
1855 flags: []string{"-fail-cert-callback"},
1856 shouldFail: true,
1857 expectedError: ":CERT_CB_ERROR:",
1858 expectedLocalError: "remote error: internal error",
1859 },
1860 {
1861 name: "FailCertCallback-Client-TLS13",
1862 config: Config{
1863 MaxVersion: VersionTLS13,
1864 ClientAuth: RequestClientCert,
1865 },
1866 flags: []string{"-fail-cert-callback"},
1867 shouldFail: true,
1868 expectedError: ":CERT_CB_ERROR:",
1869 expectedLocalError: "remote error: internal error",
1870 },
1871 {
1872 testType: serverTest,
1873 name: "FailCertCallback-Server-TLS13",
1874 config: Config{
1875 MaxVersion: VersionTLS13,
1876 },
1877 flags: []string{"-fail-cert-callback"},
1878 shouldFail: true,
1879 expectedError: ":CERT_CB_ERROR:",
1880 expectedLocalError: "remote error: internal error",
1881 },
1882 {
Adam Langley7c803a62015-06-15 15:35:05 -07001883 protocol: dtls,
1884 name: "FragmentMessageTypeMismatch-DTLS",
1885 config: Config{
1886 Bugs: ProtocolBugs{
1887 MaxHandshakeRecordLength: 2,
1888 FragmentMessageTypeMismatch: true,
1889 },
1890 },
1891 shouldFail: true,
1892 expectedError: ":FRAGMENT_MISMATCH:",
1893 },
1894 {
1895 protocol: dtls,
1896 name: "FragmentMessageLengthMismatch-DTLS",
1897 config: Config{
1898 Bugs: ProtocolBugs{
1899 MaxHandshakeRecordLength: 2,
1900 FragmentMessageLengthMismatch: true,
1901 },
1902 },
1903 shouldFail: true,
1904 expectedError: ":FRAGMENT_MISMATCH:",
1905 },
1906 {
1907 protocol: dtls,
1908 name: "SplitFragments-Header-DTLS",
1909 config: Config{
1910 Bugs: ProtocolBugs{
1911 SplitFragments: 2,
1912 },
1913 },
1914 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001915 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001916 },
1917 {
1918 protocol: dtls,
1919 name: "SplitFragments-Boundary-DTLS",
1920 config: Config{
1921 Bugs: ProtocolBugs{
1922 SplitFragments: dtlsRecordHeaderLen,
1923 },
1924 },
1925 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001926 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001927 },
1928 {
1929 protocol: dtls,
1930 name: "SplitFragments-Body-DTLS",
1931 config: Config{
1932 Bugs: ProtocolBugs{
1933 SplitFragments: dtlsRecordHeaderLen + 1,
1934 },
1935 },
1936 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001937 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001938 },
1939 {
1940 protocol: dtls,
1941 name: "SendEmptyFragments-DTLS",
1942 config: Config{
1943 Bugs: ProtocolBugs{
1944 SendEmptyFragments: true,
1945 },
1946 },
1947 },
1948 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001949 name: "BadFinished-Client",
1950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001951 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001952 Bugs: ProtocolBugs{
1953 BadFinished: true,
1954 },
1955 },
1956 shouldFail: true,
1957 expectedError: ":DIGEST_CHECK_FAILED:",
1958 },
1959 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001960 name: "BadFinished-Client-TLS13",
1961 config: Config{
1962 MaxVersion: VersionTLS13,
1963 Bugs: ProtocolBugs{
1964 BadFinished: true,
1965 },
1966 },
1967 shouldFail: true,
1968 expectedError: ":DIGEST_CHECK_FAILED:",
1969 },
1970 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001971 testType: serverTest,
1972 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001973 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001974 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001975 Bugs: ProtocolBugs{
1976 BadFinished: true,
1977 },
1978 },
1979 shouldFail: true,
1980 expectedError: ":DIGEST_CHECK_FAILED:",
1981 },
1982 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001983 testType: serverTest,
1984 name: "BadFinished-Server-TLS13",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 Bugs: ProtocolBugs{
1988 BadFinished: true,
1989 },
1990 },
1991 shouldFail: true,
1992 expectedError: ":DIGEST_CHECK_FAILED:",
1993 },
1994 {
Adam Langley7c803a62015-06-15 15:35:05 -07001995 name: "FalseStart-BadFinished",
1996 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001997 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1999 NextProtos: []string{"foo"},
2000 Bugs: ProtocolBugs{
2001 BadFinished: true,
2002 ExpectFalseStart: true,
2003 },
2004 },
2005 flags: []string{
2006 "-false-start",
2007 "-handshake-never-done",
2008 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04002009 "-expect-alpn", "foo",
Adam Langley7c803a62015-06-15 15:35:05 -07002010 },
2011 shimWritesFirst: true,
2012 shouldFail: true,
2013 expectedError: ":DIGEST_CHECK_FAILED:",
2014 },
2015 {
2016 name: "NoFalseStart-NoALPN",
2017 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002018 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002019 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2020 Bugs: ProtocolBugs{
2021 ExpectFalseStart: true,
2022 AlertBeforeFalseStartTest: alertAccessDenied,
2023 },
2024 },
2025 flags: []string{
2026 "-false-start",
2027 },
2028 shimWritesFirst: true,
2029 shouldFail: true,
2030 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2031 expectedLocalError: "tls: peer did not false start: EOF",
2032 },
2033 {
2034 name: "NoFalseStart-NoAEAD",
2035 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002036 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2038 NextProtos: []string{"foo"},
2039 Bugs: ProtocolBugs{
2040 ExpectFalseStart: true,
2041 AlertBeforeFalseStartTest: alertAccessDenied,
2042 },
2043 },
2044 flags: []string{
2045 "-false-start",
2046 "-advertise-alpn", "\x03foo",
2047 },
2048 shimWritesFirst: true,
2049 shouldFail: true,
2050 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2051 expectedLocalError: "tls: peer did not false start: EOF",
2052 },
2053 {
2054 name: "NoFalseStart-RSA",
2055 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002056 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07002057 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
2058 NextProtos: []string{"foo"},
2059 Bugs: ProtocolBugs{
2060 ExpectFalseStart: true,
2061 AlertBeforeFalseStartTest: alertAccessDenied,
2062 },
2063 },
2064 flags: []string{
2065 "-false-start",
2066 "-advertise-alpn", "\x03foo",
2067 },
2068 shimWritesFirst: true,
2069 shouldFail: true,
2070 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2071 expectedLocalError: "tls: peer did not false start: EOF",
2072 },
2073 {
Adam Langley7c803a62015-06-15 15:35:05 -07002074 protocol: dtls,
2075 name: "SendSplitAlert-Sync",
2076 config: Config{
2077 Bugs: ProtocolBugs{
2078 SendSplitAlert: true,
2079 },
2080 },
2081 },
2082 {
2083 protocol: dtls,
2084 name: "SendSplitAlert-Async",
2085 config: Config{
2086 Bugs: ProtocolBugs{
2087 SendSplitAlert: true,
2088 },
2089 },
2090 flags: []string{"-async"},
2091 },
2092 {
2093 protocol: dtls,
2094 name: "PackDTLSHandshake",
2095 config: Config{
2096 Bugs: ProtocolBugs{
2097 MaxHandshakeRecordLength: 2,
2098 PackHandshakeFragments: 20,
2099 PackHandshakeRecords: 200,
2100 },
2101 },
2102 },
2103 {
Adam Langley7c803a62015-06-15 15:35:05 -07002104 name: "SendEmptyRecords-Pass",
2105 sendEmptyRecords: 32,
2106 },
2107 {
2108 name: "SendEmptyRecords",
2109 sendEmptyRecords: 33,
2110 shouldFail: true,
2111 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2112 },
2113 {
2114 name: "SendEmptyRecords-Async",
2115 sendEmptyRecords: 33,
2116 flags: []string{"-async"},
2117 shouldFail: true,
2118 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2119 },
2120 {
David Benjamine8e84b92016-08-03 15:39:47 -04002121 name: "SendWarningAlerts-Pass",
2122 config: Config{
2123 MaxVersion: VersionTLS12,
2124 },
Adam Langley7c803a62015-06-15 15:35:05 -07002125 sendWarningAlerts: 4,
2126 },
2127 {
David Benjamine8e84b92016-08-03 15:39:47 -04002128 protocol: dtls,
2129 name: "SendWarningAlerts-DTLS-Pass",
2130 config: Config{
2131 MaxVersion: VersionTLS12,
2132 },
Adam Langley7c803a62015-06-15 15:35:05 -07002133 sendWarningAlerts: 4,
2134 },
2135 {
David Benjamine8e84b92016-08-03 15:39:47 -04002136 name: "SendWarningAlerts-TLS13",
2137 config: Config{
2138 MaxVersion: VersionTLS13,
2139 },
2140 sendWarningAlerts: 4,
2141 shouldFail: true,
2142 expectedError: ":BAD_ALERT:",
2143 expectedLocalError: "remote error: error decoding message",
2144 },
2145 {
2146 name: "SendWarningAlerts",
2147 config: Config{
2148 MaxVersion: VersionTLS12,
2149 },
Adam Langley7c803a62015-06-15 15:35:05 -07002150 sendWarningAlerts: 5,
2151 shouldFail: true,
2152 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2153 },
2154 {
David Benjamine8e84b92016-08-03 15:39:47 -04002155 name: "SendWarningAlerts-Async",
2156 config: Config{
2157 MaxVersion: VersionTLS12,
2158 },
Adam Langley7c803a62015-06-15 15:35:05 -07002159 sendWarningAlerts: 5,
2160 flags: []string{"-async"},
2161 shouldFail: true,
2162 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2163 },
David Benjaminba4594a2015-06-18 18:36:15 -04002164 {
David Benjamin24e58862017-06-14 18:45:29 -04002165 name: "SendBogusAlertType",
2166 sendBogusAlertType: true,
2167 shouldFail: true,
2168 expectedError: ":UNKNOWN_ALERT_TYPE:",
2169 expectedLocalError: "remote error: illegal parameter",
2170 },
2171 {
2172 protocol: dtls,
2173 name: "SendBogusAlertType-DTLS",
2174 sendBogusAlertType: true,
2175 shouldFail: true,
2176 expectedError: ":UNKNOWN_ALERT_TYPE:",
2177 expectedLocalError: "remote error: illegal parameter",
2178 },
2179 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002180 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002181 config: Config{
2182 MaxVersion: VersionTLS13,
2183 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002184 sendKeyUpdates: 33,
2185 keyUpdateRequest: keyUpdateNotRequested,
2186 shouldFail: true,
2187 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002188 },
2189 {
David Benjaminba4594a2015-06-18 18:36:15 -04002190 name: "EmptySessionID",
2191 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002192 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002193 SessionTicketsDisabled: true,
2194 },
2195 noSessionCache: true,
2196 flags: []string{"-expect-no-session"},
2197 },
David Benjamin30789da2015-08-29 22:56:45 -04002198 {
2199 name: "Unclean-Shutdown",
2200 config: Config{
2201 Bugs: ProtocolBugs{
2202 NoCloseNotify: true,
2203 ExpectCloseNotify: true,
2204 },
2205 },
2206 shimShutsDown: true,
2207 flags: []string{"-check-close-notify"},
2208 shouldFail: true,
2209 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2210 },
2211 {
2212 name: "Unclean-Shutdown-Ignored",
2213 config: Config{
2214 Bugs: ProtocolBugs{
2215 NoCloseNotify: true,
2216 },
2217 },
2218 shimShutsDown: true,
2219 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002220 {
David Benjaminfa214e42016-05-10 17:03:10 -04002221 name: "Unclean-Shutdown-Alert",
2222 config: Config{
2223 Bugs: ProtocolBugs{
2224 SendAlertOnShutdown: alertDecompressionFailure,
2225 ExpectCloseNotify: true,
2226 },
2227 },
2228 shimShutsDown: true,
2229 flags: []string{"-check-close-notify"},
2230 shouldFail: true,
2231 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2232 },
2233 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002234 name: "LargePlaintext",
2235 config: Config{
2236 Bugs: ProtocolBugs{
2237 SendLargeRecords: true,
2238 },
2239 },
2240 messageLen: maxPlaintext + 1,
2241 shouldFail: true,
2242 expectedError: ":DATA_LENGTH_TOO_LONG:",
2243 },
2244 {
2245 protocol: dtls,
2246 name: "LargePlaintext-DTLS",
2247 config: Config{
2248 Bugs: ProtocolBugs{
2249 SendLargeRecords: true,
2250 },
2251 },
2252 messageLen: maxPlaintext + 1,
2253 shouldFail: true,
2254 expectedError: ":DATA_LENGTH_TOO_LONG:",
2255 },
2256 {
2257 name: "LargeCiphertext",
2258 config: Config{
2259 Bugs: ProtocolBugs{
2260 SendLargeRecords: true,
2261 },
2262 },
2263 messageLen: maxPlaintext * 2,
2264 shouldFail: true,
2265 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2266 },
2267 {
2268 protocol: dtls,
2269 name: "LargeCiphertext-DTLS",
2270 config: Config{
2271 Bugs: ProtocolBugs{
2272 SendLargeRecords: true,
2273 },
2274 },
2275 messageLen: maxPlaintext * 2,
2276 // Unlike the other four cases, DTLS drops records which
2277 // are invalid before authentication, so the connection
2278 // does not fail.
2279 expectMessageDropped: true,
2280 },
David Benjamindd6fed92015-10-23 17:41:12 -04002281 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002282 name: "BadHelloRequest-1",
2283 renegotiate: 1,
2284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002285 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002286 Bugs: ProtocolBugs{
2287 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2288 },
2289 },
2290 flags: []string{
2291 "-renegotiate-freely",
2292 "-expect-total-renegotiations", "1",
2293 },
2294 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002295 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002296 },
2297 {
2298 name: "BadHelloRequest-2",
2299 renegotiate: 1,
2300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002301 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002302 Bugs: ProtocolBugs{
2303 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2304 },
2305 },
2306 flags: []string{
2307 "-renegotiate-freely",
2308 "-expect-total-renegotiations", "1",
2309 },
2310 shouldFail: true,
2311 expectedError: ":BAD_HELLO_REQUEST:",
2312 },
David Benjaminef1b0092015-11-21 14:05:44 -05002313 {
2314 testType: serverTest,
2315 name: "SupportTicketsWithSessionID",
2316 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002317 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002318 SessionTicketsDisabled: true,
2319 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002320 resumeConfig: &Config{
2321 MaxVersion: VersionTLS12,
2322 },
David Benjaminef1b0092015-11-21 14:05:44 -05002323 resumeSession: true,
2324 },
David Benjamin02edcd02016-07-27 17:40:37 -04002325 {
2326 protocol: dtls,
2327 name: "DTLS-SendExtraFinished",
2328 config: Config{
2329 Bugs: ProtocolBugs{
2330 SendExtraFinished: true,
2331 },
2332 },
2333 shouldFail: true,
2334 expectedError: ":UNEXPECTED_RECORD:",
2335 },
2336 {
2337 protocol: dtls,
2338 name: "DTLS-SendExtraFinished-Reordered",
2339 config: Config{
2340 Bugs: ProtocolBugs{
2341 MaxHandshakeRecordLength: 2,
2342 ReorderHandshakeFragments: true,
2343 SendExtraFinished: true,
2344 },
2345 },
2346 shouldFail: true,
2347 expectedError: ":UNEXPECTED_RECORD:",
2348 },
David Benjamine97fb482016-07-29 09:23:07 -04002349 {
2350 testType: serverTest,
2351 name: "V2ClientHello-EmptyRecordPrefix",
2352 config: Config{
2353 // Choose a cipher suite that does not involve
2354 // elliptic curves, so no extensions are
2355 // involved.
2356 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002357 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002358 Bugs: ProtocolBugs{
2359 SendV2ClientHello: true,
2360 },
2361 },
2362 sendPrefix: string([]byte{
2363 byte(recordTypeHandshake),
2364 3, 1, // version
2365 0, 0, // length
2366 }),
2367 // A no-op empty record may not be sent before V2ClientHello.
2368 shouldFail: true,
2369 expectedError: ":WRONG_VERSION_NUMBER:",
2370 },
2371 {
2372 testType: serverTest,
2373 name: "V2ClientHello-WarningAlertPrefix",
2374 config: Config{
2375 // Choose a cipher suite that does not involve
2376 // elliptic curves, so no extensions are
2377 // involved.
2378 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002379 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002380 Bugs: ProtocolBugs{
2381 SendV2ClientHello: true,
2382 },
2383 },
2384 sendPrefix: string([]byte{
2385 byte(recordTypeAlert),
2386 3, 1, // version
2387 0, 2, // length
2388 alertLevelWarning, byte(alertDecompressionFailure),
2389 }),
2390 // A no-op warning alert may not be sent before V2ClientHello.
2391 shouldFail: true,
2392 expectedError: ":WRONG_VERSION_NUMBER:",
2393 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002394 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002395 name: "KeyUpdate-Client",
2396 config: Config{
2397 MaxVersion: VersionTLS13,
2398 },
2399 sendKeyUpdates: 1,
2400 keyUpdateRequest: keyUpdateNotRequested,
2401 },
2402 {
2403 testType: serverTest,
2404 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002405 config: Config{
2406 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002407 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002408 sendKeyUpdates: 1,
2409 keyUpdateRequest: keyUpdateNotRequested,
2410 },
2411 {
2412 name: "KeyUpdate-InvalidRequestMode",
2413 config: Config{
2414 MaxVersion: VersionTLS13,
2415 },
2416 sendKeyUpdates: 1,
2417 keyUpdateRequest: 42,
2418 shouldFail: true,
2419 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002420 },
David Benjaminabe94e32016-09-04 14:18:58 -04002421 {
David Benjaminbbba9392017-04-06 12:54:12 -04002422 // Test that KeyUpdates are acknowledged properly.
2423 name: "KeyUpdate-RequestACK",
2424 config: Config{
2425 MaxVersion: VersionTLS13,
2426 Bugs: ProtocolBugs{
2427 RejectUnsolicitedKeyUpdate: true,
2428 },
2429 },
2430 // Test the shim receiving many KeyUpdates in a row.
2431 sendKeyUpdates: 5,
2432 messageCount: 5,
2433 keyUpdateRequest: keyUpdateRequested,
2434 },
2435 {
2436 // Test that KeyUpdates are acknowledged properly if the
2437 // peer's KeyUpdate is discovered while a write is
2438 // pending.
2439 name: "KeyUpdate-RequestACK-UnfinishedWrite",
2440 config: Config{
2441 MaxVersion: VersionTLS13,
2442 Bugs: ProtocolBugs{
2443 RejectUnsolicitedKeyUpdate: true,
2444 },
2445 },
2446 // Test the shim receiving many KeyUpdates in a row.
2447 sendKeyUpdates: 5,
2448 messageCount: 5,
2449 keyUpdateRequest: keyUpdateRequested,
2450 readWithUnfinishedWrite: true,
2451 flags: []string{"-async"},
2452 },
2453 {
David Benjaminabe94e32016-09-04 14:18:58 -04002454 name: "SendSNIWarningAlert",
2455 config: Config{
2456 MaxVersion: VersionTLS12,
2457 Bugs: ProtocolBugs{
2458 SendSNIWarningAlert: true,
2459 },
2460 },
2461 },
David Benjaminc241d792016-09-09 10:34:20 -04002462 {
2463 testType: serverTest,
2464 name: "ExtraCompressionMethods-TLS12",
2465 config: Config{
2466 MaxVersion: VersionTLS12,
2467 Bugs: ProtocolBugs{
2468 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2469 },
2470 },
2471 },
2472 {
2473 testType: serverTest,
2474 name: "ExtraCompressionMethods-TLS13",
2475 config: Config{
2476 MaxVersion: VersionTLS13,
2477 Bugs: ProtocolBugs{
2478 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2479 },
2480 },
2481 shouldFail: true,
2482 expectedError: ":INVALID_COMPRESSION_LIST:",
2483 expectedLocalError: "remote error: illegal parameter",
2484 },
2485 {
2486 testType: serverTest,
2487 name: "NoNullCompression-TLS12",
2488 config: Config{
2489 MaxVersion: VersionTLS12,
2490 Bugs: ProtocolBugs{
2491 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2492 },
2493 },
2494 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002495 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002496 expectedLocalError: "remote error: illegal parameter",
2497 },
2498 {
2499 testType: serverTest,
2500 name: "NoNullCompression-TLS13",
2501 config: Config{
2502 MaxVersion: VersionTLS13,
2503 Bugs: ProtocolBugs{
2504 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2505 },
2506 },
2507 shouldFail: true,
2508 expectedError: ":INVALID_COMPRESSION_LIST:",
2509 expectedLocalError: "remote error: illegal parameter",
2510 },
David Benjamin413e79e2017-07-01 10:11:53 -04002511 // Test that the client rejects invalid compression methods
2512 // from the server.
2513 {
2514 testType: clientTest,
2515 name: "InvalidCompressionMethod",
2516 config: Config{
2517 MaxVersion: VersionTLS12,
2518 Bugs: ProtocolBugs{
2519 SendCompressionMethod: 1,
2520 },
2521 },
2522 shouldFail: true,
2523 expectedError: ":UNSUPPORTED_COMPRESSION_ALGORITHM:",
2524 expectedLocalError: "remote error: illegal parameter",
2525 },
David Benjamin65ac9972016-09-02 21:35:25 -04002526 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002527 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002528 config: Config{
2529 MaxVersion: VersionTLS12,
2530 Bugs: ProtocolBugs{
2531 ExpectGREASE: true,
2532 },
2533 },
2534 flags: []string{"-enable-grease"},
2535 },
2536 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002537 name: "GREASE-Client-TLS13",
2538 config: Config{
2539 MaxVersion: VersionTLS13,
2540 Bugs: ProtocolBugs{
2541 ExpectGREASE: true,
2542 },
2543 },
2544 flags: []string{"-enable-grease"},
2545 },
2546 {
2547 testType: serverTest,
2548 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002549 config: Config{
2550 MaxVersion: VersionTLS13,
2551 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002552 // TLS 1.3 servers are expected to
2553 // always enable GREASE. TLS 1.3 is new,
2554 // so there is no existing ecosystem to
2555 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002556 ExpectGREASE: true,
2557 },
2558 },
David Benjamin65ac9972016-09-02 21:35:25 -04002559 },
David Benjamine3fbb362017-01-06 16:19:28 -05002560 {
2561 // Test the server so there is a large certificate as
2562 // well as application data.
2563 testType: serverTest,
2564 name: "MaxSendFragment",
2565 config: Config{
2566 Bugs: ProtocolBugs{
2567 MaxReceivePlaintext: 512,
2568 },
2569 },
2570 messageLen: 1024,
2571 flags: []string{
2572 "-max-send-fragment", "512",
2573 "-read-size", "1024",
2574 },
2575 },
2576 {
2577 // Test the server so there is a large certificate as
2578 // well as application data.
2579 testType: serverTest,
2580 name: "MaxSendFragment-TooLarge",
2581 config: Config{
2582 Bugs: ProtocolBugs{
2583 // Ensure that some of the records are
2584 // 512.
2585 MaxReceivePlaintext: 511,
2586 },
2587 },
2588 messageLen: 1024,
2589 flags: []string{
2590 "-max-send-fragment", "512",
2591 "-read-size", "1024",
2592 },
2593 shouldFail: true,
2594 expectedLocalError: "local error: record overflow",
2595 },
Adam Langley7c803a62015-06-15 15:35:05 -07002596 }
Adam Langley7c803a62015-06-15 15:35:05 -07002597 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002598
2599 // Test that very large messages can be received.
2600 cert := rsaCertificate
2601 for i := 0; i < 50; i++ {
2602 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2603 }
2604 testCases = append(testCases, testCase{
2605 name: "LargeMessage",
2606 config: Config{
2607 Certificates: []Certificate{cert},
2608 },
2609 })
2610 testCases = append(testCases, testCase{
2611 protocol: dtls,
2612 name: "LargeMessage-DTLS",
2613 config: Config{
2614 Certificates: []Certificate{cert},
2615 },
2616 })
2617
2618 // They are rejected if the maximum certificate chain length is capped.
2619 testCases = append(testCases, testCase{
2620 name: "LargeMessage-Reject",
2621 config: Config{
2622 Certificates: []Certificate{cert},
2623 },
2624 flags: []string{"-max-cert-list", "16384"},
2625 shouldFail: true,
2626 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2627 })
2628 testCases = append(testCases, testCase{
2629 protocol: dtls,
2630 name: "LargeMessage-Reject-DTLS",
2631 config: Config{
2632 Certificates: []Certificate{cert},
2633 },
2634 flags: []string{"-max-cert-list", "16384"},
2635 shouldFail: true,
2636 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2637 })
Adam Langley7c803a62015-06-15 15:35:05 -07002638}
2639
David Benjaminaa012042016-12-10 13:33:05 -05002640func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2641 const psk = "12345"
2642 const pskIdentity = "luggage combo"
2643
2644 var prefix string
2645 if protocol == dtls {
2646 if !ver.hasDTLS {
2647 return
2648 }
2649 prefix = "D"
2650 }
2651
2652 var cert Certificate
2653 var certFile string
2654 var keyFile string
2655 if hasComponent(suite.name, "ECDSA") {
2656 cert = ecdsaP256Certificate
2657 certFile = ecdsaP256CertificateFile
2658 keyFile = ecdsaP256KeyFile
2659 } else {
2660 cert = rsaCertificate
2661 certFile = rsaCertificateFile
2662 keyFile = rsaKeyFile
2663 }
2664
2665 var flags []string
2666 if hasComponent(suite.name, "PSK") {
2667 flags = append(flags,
2668 "-psk", psk,
2669 "-psk-identity", pskIdentity)
2670 }
2671 if hasComponent(suite.name, "NULL") {
2672 // NULL ciphers must be explicitly enabled.
2673 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2674 }
David Benjaminaa012042016-12-10 13:33:05 -05002675
2676 var shouldServerFail, shouldClientFail bool
2677 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2678 // BoringSSL clients accept ECDHE on SSLv3, but
2679 // a BoringSSL server will never select it
2680 // because the extension is missing.
2681 shouldServerFail = true
2682 }
2683 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2684 shouldClientFail = true
2685 shouldServerFail = true
2686 }
2687 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2688 shouldClientFail = true
2689 shouldServerFail = true
2690 }
2691 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2692 shouldClientFail = true
2693 shouldServerFail = true
2694 }
2695 if !isDTLSCipher(suite.name) && protocol == dtls {
2696 shouldClientFail = true
2697 shouldServerFail = true
2698 }
2699
2700 var sendCipherSuite uint16
2701 var expectedServerError, expectedClientError string
2702 serverCipherSuites := []uint16{suite.id}
2703 if shouldServerFail {
2704 expectedServerError = ":NO_SHARED_CIPHER:"
2705 }
2706 if shouldClientFail {
2707 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2708 // Configure the server to select ciphers as normal but
2709 // select an incompatible cipher in ServerHello.
2710 serverCipherSuites = nil
2711 sendCipherSuite = suite.id
2712 }
2713
David Benjamincdb6fe92017-02-07 16:06:48 -05002714 // For cipher suites and versions where exporters are defined, verify
2715 // that they interoperate.
2716 var exportKeyingMaterial int
2717 if ver.version > VersionSSL30 {
2718 exportKeyingMaterial = 1024
2719 }
2720
David Benjaminaa012042016-12-10 13:33:05 -05002721 testCases = append(testCases, testCase{
2722 testType: serverTest,
2723 protocol: protocol,
2724 name: prefix + ver.name + "-" + suite.name + "-server",
2725 config: Config{
2726 MinVersion: ver.version,
2727 MaxVersion: ver.version,
2728 CipherSuites: []uint16{suite.id},
2729 Certificates: []Certificate{cert},
2730 PreSharedKey: []byte(psk),
2731 PreSharedKeyIdentity: pskIdentity,
2732 Bugs: ProtocolBugs{
2733 AdvertiseAllConfiguredCiphers: true,
2734 },
2735 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002736 certFile: certFile,
2737 keyFile: keyFile,
2738 flags: flags,
2739 resumeSession: true,
2740 shouldFail: shouldServerFail,
2741 expectedError: expectedServerError,
2742 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002743 })
2744
2745 testCases = append(testCases, testCase{
2746 testType: clientTest,
2747 protocol: protocol,
2748 name: prefix + ver.name + "-" + suite.name + "-client",
2749 config: Config{
2750 MinVersion: ver.version,
2751 MaxVersion: ver.version,
2752 CipherSuites: serverCipherSuites,
2753 Certificates: []Certificate{cert},
2754 PreSharedKey: []byte(psk),
2755 PreSharedKeyIdentity: pskIdentity,
2756 Bugs: ProtocolBugs{
2757 IgnorePeerCipherPreferences: shouldClientFail,
2758 SendCipherSuite: sendCipherSuite,
2759 },
2760 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002761 flags: flags,
2762 resumeSession: true,
2763 shouldFail: shouldClientFail,
2764 expectedError: expectedClientError,
2765 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002766 })
2767
David Benjamin6f600d62016-12-21 16:06:54 -05002768 if shouldClientFail {
2769 return
2770 }
2771
2772 // Ensure the maximum record size is accepted.
2773 testCases = append(testCases, testCase{
2774 protocol: protocol,
2775 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2776 config: Config{
2777 MinVersion: ver.version,
2778 MaxVersion: ver.version,
2779 CipherSuites: []uint16{suite.id},
2780 Certificates: []Certificate{cert},
2781 PreSharedKey: []byte(psk),
2782 PreSharedKeyIdentity: pskIdentity,
2783 },
2784 flags: flags,
2785 messageLen: maxPlaintext,
2786 })
2787
2788 // Test bad records for all ciphers. Bad records are fatal in TLS
2789 // and ignored in DTLS.
2790 var shouldFail bool
2791 var expectedError string
2792 if protocol == tls {
2793 shouldFail = true
2794 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2795 }
2796
2797 testCases = append(testCases, testCase{
2798 protocol: protocol,
2799 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2800 config: Config{
2801 MinVersion: ver.version,
2802 MaxVersion: ver.version,
2803 CipherSuites: []uint16{suite.id},
2804 Certificates: []Certificate{cert},
2805 PreSharedKey: []byte(psk),
2806 PreSharedKeyIdentity: pskIdentity,
2807 },
2808 flags: flags,
2809 damageFirstWrite: true,
2810 messageLen: maxPlaintext,
2811 shouldFail: shouldFail,
2812 expectedError: expectedError,
2813 })
David Benjaminaa012042016-12-10 13:33:05 -05002814}
2815
Adam Langley95c29f32014-06-20 12:00:00 -07002816func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002817 const bogusCipher = 0xfe00
2818
Adam Langley95c29f32014-06-20 12:00:00 -07002819 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002820 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002821 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002822 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002823 }
David Benjamin2c99d282015-09-01 10:23:00 -04002824 }
Adam Langley95c29f32014-06-20 12:00:00 -07002825 }
Adam Langleya7997f12015-05-14 17:38:50 -07002826
2827 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002828 name: "NoSharedCipher",
2829 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002830 MaxVersion: VersionTLS12,
2831 CipherSuites: []uint16{},
2832 },
2833 shouldFail: true,
2834 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2835 })
2836
2837 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002838 name: "NoSharedCipher-TLS13",
2839 config: Config{
2840 MaxVersion: VersionTLS13,
2841 CipherSuites: []uint16{},
2842 },
2843 shouldFail: true,
2844 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2845 })
2846
2847 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002848 name: "UnsupportedCipherSuite",
2849 config: Config{
2850 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002851 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002852 Bugs: ProtocolBugs{
2853 IgnorePeerCipherPreferences: true,
2854 },
2855 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002856 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002857 shouldFail: true,
2858 expectedError: ":WRONG_CIPHER_RETURNED:",
2859 })
2860
2861 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002862 name: "ServerHelloBogusCipher",
2863 config: Config{
2864 MaxVersion: VersionTLS12,
2865 Bugs: ProtocolBugs{
2866 SendCipherSuite: bogusCipher,
2867 },
2868 },
2869 shouldFail: true,
2870 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2871 })
2872 testCases = append(testCases, testCase{
2873 name: "ServerHelloBogusCipher-TLS13",
2874 config: Config{
2875 MaxVersion: VersionTLS13,
2876 Bugs: ProtocolBugs{
2877 SendCipherSuite: bogusCipher,
2878 },
2879 },
2880 shouldFail: true,
2881 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2882 })
2883
David Benjamin241ae832016-01-15 03:04:54 -05002884 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002885 testCases = append(testCases, testCase{
2886 testType: serverTest,
2887 name: "UnknownCipher",
2888 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002889 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002890 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002891 Bugs: ProtocolBugs{
2892 AdvertiseAllConfiguredCiphers: true,
2893 },
2894 },
2895 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002896
2897 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002898 testCases = append(testCases, testCase{
2899 testType: serverTest,
2900 name: "UnknownCipher-TLS13",
2901 config: Config{
2902 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002903 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002904 Bugs: ProtocolBugs{
2905 AdvertiseAllConfiguredCiphers: true,
2906 },
David Benjamin241ae832016-01-15 03:04:54 -05002907 },
2908 })
2909
David Benjamin78679342016-09-16 19:42:05 -04002910 // Test empty ECDHE_PSK identity hints work as expected.
2911 testCases = append(testCases, testCase{
2912 name: "EmptyECDHEPSKHint",
2913 config: Config{
2914 MaxVersion: VersionTLS12,
2915 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2916 PreSharedKey: []byte("secret"),
2917 },
2918 flags: []string{"-psk", "secret"},
2919 })
2920
2921 // Test empty PSK identity hints work as expected, even if an explicit
2922 // ServerKeyExchange is sent.
2923 testCases = append(testCases, testCase{
2924 name: "ExplicitEmptyPSKHint",
2925 config: Config{
2926 MaxVersion: VersionTLS12,
2927 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2928 PreSharedKey: []byte("secret"),
2929 Bugs: ProtocolBugs{
2930 AlwaysSendPreSharedKeyIdentityHint: true,
2931 },
2932 },
2933 flags: []string{"-psk", "secret"},
2934 })
David Benjamin69522112017-03-28 15:38:29 -05002935
2936 // Test that clients enforce that the server-sent certificate and cipher
2937 // suite match in TLS 1.2.
2938 testCases = append(testCases, testCase{
2939 name: "CertificateCipherMismatch-RSA",
2940 config: Config{
2941 MaxVersion: VersionTLS12,
2942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
2943 Certificates: []Certificate{rsaCertificate},
2944 Bugs: ProtocolBugs{
2945 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
2946 },
2947 },
2948 shouldFail: true,
2949 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2950 })
2951 testCases = append(testCases, testCase{
2952 name: "CertificateCipherMismatch-ECDSA",
2953 config: Config{
2954 MaxVersion: VersionTLS12,
2955 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2956 Certificates: []Certificate{ecdsaP256Certificate},
2957 Bugs: ProtocolBugs{
2958 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2959 },
2960 },
2961 shouldFail: true,
2962 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2963 })
2964 testCases = append(testCases, testCase{
2965 name: "CertificateCipherMismatch-Ed25519",
2966 config: Config{
2967 MaxVersion: VersionTLS12,
2968 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2969 Certificates: []Certificate{ed25519Certificate},
2970 Bugs: ProtocolBugs{
2971 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
2972 },
2973 },
2974 shouldFail: true,
2975 expectedError: ":WRONG_CERTIFICATE_TYPE:",
2976 })
2977
2978 // Test that servers decline to select a cipher suite which is
2979 // inconsistent with their configured certificate.
2980 testCases = append(testCases, testCase{
2981 testType: serverTest,
2982 name: "ServerCipherFilter-RSA",
2983 config: Config{
2984 MaxVersion: VersionTLS12,
2985 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
2986 },
2987 flags: []string{
2988 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2989 "-key-file", path.Join(*resourceDir, rsaKeyFile),
2990 },
2991 shouldFail: true,
2992 expectedError: ":NO_SHARED_CIPHER:",
2993 })
2994 testCases = append(testCases, testCase{
2995 testType: serverTest,
2996 name: "ServerCipherFilter-ECDSA",
2997 config: Config{
2998 MaxVersion: VersionTLS12,
2999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3000 },
3001 flags: []string{
3002 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3003 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3004 },
3005 shouldFail: true,
3006 expectedError: ":NO_SHARED_CIPHER:",
3007 })
3008 testCases = append(testCases, testCase{
3009 testType: serverTest,
3010 name: "ServerCipherFilter-Ed25519",
3011 config: Config{
3012 MaxVersion: VersionTLS12,
3013 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3014 },
3015 flags: []string{
3016 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
3017 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
3018 },
3019 shouldFail: true,
3020 expectedError: ":NO_SHARED_CIPHER:",
3021 })
David Benjamin364af782017-07-01 10:35:27 -04003022
3023 // Test cipher suite negotiation works as expected. Configure a
3024 // complicated cipher suite configuration.
3025 const negotiationTestCiphers = "" +
3026 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256:" +
3027 "[TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384|TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256|TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA]:" +
3028 "TLS_RSA_WITH_AES_128_GCM_SHA256:" +
3029 "TLS_RSA_WITH_AES_128_CBC_SHA:" +
3030 "[TLS_RSA_WITH_AES_256_GCM_SHA384|TLS_RSA_WITH_AES_256_CBC_SHA]"
3031 negotiationTests := []struct {
3032 ciphers []uint16
3033 expected uint16
3034 }{
3035 // Server preferences are honored, including when
3036 // equipreference groups are involved.
3037 {
3038 []uint16{
3039 TLS_RSA_WITH_AES_256_GCM_SHA384,
3040 TLS_RSA_WITH_AES_128_CBC_SHA,
3041 TLS_RSA_WITH_AES_128_GCM_SHA256,
3042 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3043 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3044 },
3045 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
3046 },
3047 {
3048 []uint16{
3049 TLS_RSA_WITH_AES_256_GCM_SHA384,
3050 TLS_RSA_WITH_AES_128_CBC_SHA,
3051 TLS_RSA_WITH_AES_128_GCM_SHA256,
3052 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3053 },
3054 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3055 },
3056 {
3057 []uint16{
3058 TLS_RSA_WITH_AES_256_GCM_SHA384,
3059 TLS_RSA_WITH_AES_128_CBC_SHA,
3060 TLS_RSA_WITH_AES_128_GCM_SHA256,
3061 },
3062 TLS_RSA_WITH_AES_128_GCM_SHA256,
3063 },
3064 {
3065 []uint16{
3066 TLS_RSA_WITH_AES_256_GCM_SHA384,
3067 TLS_RSA_WITH_AES_128_CBC_SHA,
3068 },
3069 TLS_RSA_WITH_AES_128_CBC_SHA,
3070 },
3071 // Equipreference groups use the client preference.
3072 {
3073 []uint16{
3074 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3075 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3076 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3077 },
3078 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
3079 },
3080 {
3081 []uint16{
3082 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3083 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3084 },
3085 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3086 },
3087 {
3088 []uint16{
3089 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3090 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3091 },
3092 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3093 },
3094 {
3095 []uint16{
3096 TLS_RSA_WITH_AES_256_GCM_SHA384,
3097 TLS_RSA_WITH_AES_256_CBC_SHA,
3098 },
3099 TLS_RSA_WITH_AES_256_GCM_SHA384,
3100 },
3101 {
3102 []uint16{
3103 TLS_RSA_WITH_AES_256_CBC_SHA,
3104 TLS_RSA_WITH_AES_256_GCM_SHA384,
3105 },
3106 TLS_RSA_WITH_AES_256_CBC_SHA,
3107 },
3108 // If there are two equipreference groups, the preferred one
3109 // takes precedence.
3110 {
3111 []uint16{
3112 TLS_RSA_WITH_AES_256_GCM_SHA384,
3113 TLS_RSA_WITH_AES_256_CBC_SHA,
3114 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3115 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256,
3116 },
3117 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
3118 },
3119 }
3120 for i, t := range negotiationTests {
3121 testCases = append(testCases, testCase{
3122 testType: serverTest,
3123 name: "CipherNegotiation-" + strconv.Itoa(i),
3124 config: Config{
3125 MaxVersion: VersionTLS12,
3126 CipherSuites: t.ciphers,
3127 },
3128 flags: []string{"-cipher", negotiationTestCiphers},
3129 expectedCipher: t.expected,
3130 })
3131 }
Adam Langley95c29f32014-06-20 12:00:00 -07003132}
3133
3134func addBadECDSASignatureTests() {
3135 for badR := BadValue(1); badR < NumBadValues; badR++ {
3136 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04003137 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07003138 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
3139 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04003140 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07003141 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07003142 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07003143 Bugs: ProtocolBugs{
3144 BadECDSAR: badR,
3145 BadECDSAS: badS,
3146 },
3147 },
3148 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003149 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07003150 })
Steven Valdez803c77a2016-09-06 14:13:43 -04003151 testCases = append(testCases, testCase{
3152 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
3153 config: Config{
3154 MaxVersion: VersionTLS13,
3155 Certificates: []Certificate{ecdsaP256Certificate},
3156 Bugs: ProtocolBugs{
3157 BadECDSAR: badR,
3158 BadECDSAS: badS,
3159 },
3160 },
3161 shouldFail: true,
3162 expectedError: ":BAD_SIGNATURE:",
3163 })
Adam Langley95c29f32014-06-20 12:00:00 -07003164 }
3165 }
3166}
3167
Adam Langley80842bd2014-06-20 12:00:00 -07003168func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04003169 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003170 name: "MaxCBCPadding",
3171 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003172 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3174 Bugs: ProtocolBugs{
3175 MaxPadding: true,
3176 },
3177 },
3178 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3179 })
David Benjamin025b3d32014-07-01 19:53:04 -04003180 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003181 name: "BadCBCPadding",
3182 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003183 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3185 Bugs: ProtocolBugs{
3186 PaddingFirstByteBad: true,
3187 },
3188 },
3189 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003190 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003191 })
3192 // OpenSSL previously had an issue where the first byte of padding in
3193 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04003194 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07003195 name: "BadCBCPadding255",
3196 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003197 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07003198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3199 Bugs: ProtocolBugs{
3200 MaxPadding: true,
3201 PaddingFirstByteBadIf255: true,
3202 },
3203 },
3204 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
3205 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05003206 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07003207 })
3208}
3209
Kenny Root7fdeaf12014-08-05 15:23:37 -07003210func addCBCSplittingTests() {
3211 testCases = append(testCases, testCase{
3212 name: "CBCRecordSplitting",
3213 config: Config{
3214 MaxVersion: VersionTLS10,
3215 MinVersion: VersionTLS10,
3216 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3217 },
David Benjaminac8302a2015-09-01 17:18:15 -04003218 messageLen: -1, // read until EOF
3219 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07003220 flags: []string{
3221 "-async",
3222 "-write-different-record-sizes",
3223 "-cbc-record-splitting",
3224 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04003225 })
3226 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07003227 name: "CBCRecordSplittingPartialWrite",
3228 config: Config{
3229 MaxVersion: VersionTLS10,
3230 MinVersion: VersionTLS10,
3231 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
3232 },
3233 messageLen: -1, // read until EOF
3234 flags: []string{
3235 "-async",
3236 "-write-different-record-sizes",
3237 "-cbc-record-splitting",
3238 "-partial-write",
3239 },
3240 })
3241}
3242
David Benjamin636293b2014-07-08 17:59:18 -04003243func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04003244 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04003245 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08003246 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
3247 cert, err := x509.ParseCertificate(cert.Certificate[0])
3248 if err != nil {
3249 panic(err)
3250 }
3251 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04003252 }
Adam Langley2ff79332017-02-28 13:45:39 -08003253 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003254
David Benjamin636293b2014-07-08 17:59:18 -04003255 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003256 testCases = append(testCases, testCase{
3257 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003258 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003259 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003260 MinVersion: ver.version,
3261 MaxVersion: ver.version,
3262 ClientAuth: RequireAnyClientCert,
3263 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003264 },
3265 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003266 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3267 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003268 },
3269 })
3270 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003271 testType: serverTest,
3272 name: ver.name + "-Server-ClientAuth-RSA",
3273 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003274 MinVersion: ver.version,
3275 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003276 Certificates: []Certificate{rsaCertificate},
3277 },
3278 flags: []string{"-require-any-client-certificate"},
3279 })
David Benjamine098ec22014-08-27 23:13:20 -04003280 if ver.version != VersionSSL30 {
3281 testCases = append(testCases, testCase{
3282 testType: serverTest,
3283 name: ver.name + "-Server-ClientAuth-ECDSA",
3284 config: Config{
3285 MinVersion: ver.version,
3286 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003287 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003288 },
3289 flags: []string{"-require-any-client-certificate"},
3290 })
3291 testCases = append(testCases, testCase{
3292 testType: clientTest,
3293 name: ver.name + "-Client-ClientAuth-ECDSA",
3294 config: Config{
3295 MinVersion: ver.version,
3296 MaxVersion: ver.version,
3297 ClientAuth: RequireAnyClientCert,
3298 ClientCAs: certPool,
3299 },
3300 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003301 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3302 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003303 },
3304 })
3305 }
Adam Langley37646832016-08-01 16:16:46 -07003306
3307 testCases = append(testCases, testCase{
3308 name: "NoClientCertificate-" + ver.name,
3309 config: Config{
3310 MinVersion: ver.version,
3311 MaxVersion: ver.version,
3312 ClientAuth: RequireAnyClientCert,
3313 },
3314 shouldFail: true,
3315 expectedLocalError: "client didn't provide a certificate",
3316 })
3317
3318 testCases = append(testCases, testCase{
3319 // Even if not configured to expect a certificate, OpenSSL will
3320 // return X509_V_OK as the verify_result.
3321 testType: serverTest,
3322 name: "NoClientCertificateRequested-Server-" + ver.name,
3323 config: Config{
3324 MinVersion: ver.version,
3325 MaxVersion: ver.version,
3326 },
3327 flags: []string{
3328 "-expect-verify-result",
3329 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003330 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003331 })
3332
3333 testCases = append(testCases, testCase{
3334 // If a client certificate is not provided, OpenSSL will still
3335 // return X509_V_OK as the verify_result.
3336 testType: serverTest,
3337 name: "NoClientCertificate-Server-" + ver.name,
3338 config: Config{
3339 MinVersion: ver.version,
3340 MaxVersion: ver.version,
3341 },
3342 flags: []string{
3343 "-expect-verify-result",
3344 "-verify-peer",
3345 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003346 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003347 })
3348
David Benjamin1db9e1b2016-10-07 20:51:43 -04003349 certificateRequired := "remote error: certificate required"
3350 if ver.version < VersionTLS13 {
3351 // Prior to TLS 1.3, the generic handshake_failure alert
3352 // was used.
3353 certificateRequired = "remote error: handshake failure"
3354 }
Adam Langley37646832016-08-01 16:16:46 -07003355 testCases = append(testCases, testCase{
3356 testType: serverTest,
3357 name: "RequireAnyClientCertificate-" + ver.name,
3358 config: Config{
3359 MinVersion: ver.version,
3360 MaxVersion: ver.version,
3361 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003362 flags: []string{"-require-any-client-certificate"},
3363 shouldFail: true,
3364 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3365 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003366 })
3367
3368 if ver.version != VersionSSL30 {
3369 testCases = append(testCases, testCase{
3370 testType: serverTest,
3371 name: "SkipClientCertificate-" + ver.name,
3372 config: Config{
3373 MinVersion: ver.version,
3374 MaxVersion: ver.version,
3375 Bugs: ProtocolBugs{
3376 SkipClientCertificate: true,
3377 },
3378 },
3379 // Setting SSL_VERIFY_PEER allows anonymous clients.
3380 flags: []string{"-verify-peer"},
3381 shouldFail: true,
3382 expectedError: ":UNEXPECTED_MESSAGE:",
3383 })
David Benjaminc3648fa2017-07-01 10:50:56 -04003384
3385 testCases = append(testCases, testCase{
3386 testType: serverTest,
3387 name: "VerifyPeerIfNoOBC-NoChannelID-" + ver.name,
3388 config: Config{
3389 MinVersion: ver.version,
3390 MaxVersion: ver.version,
3391 },
3392 flags: []string{
3393 "-enable-channel-id",
3394 "-verify-peer-if-no-obc",
3395 },
3396 shouldFail: true,
3397 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3398 expectedLocalError: certificateRequired,
3399 })
3400
3401 testCases = append(testCases, testCase{
3402 testType: serverTest,
3403 name: "VerifyPeerIfNoOBC-ChannelID-" + ver.name,
3404 config: Config{
3405 MinVersion: ver.version,
3406 MaxVersion: ver.version,
3407 ChannelID: channelIDKey,
3408 },
3409 expectChannelID: true,
3410 flags: []string{
3411 "-enable-channel-id",
3412 "-verify-peer-if-no-obc",
3413 },
3414 })
Adam Langley37646832016-08-01 16:16:46 -07003415 }
Adam Langley2ff79332017-02-28 13:45:39 -08003416
3417 testCases = append(testCases, testCase{
3418 testType: serverTest,
3419 name: ver.name + "-Server-CertReq-CA-List",
3420 config: Config{
3421 MinVersion: ver.version,
3422 MaxVersion: ver.version,
3423 Certificates: []Certificate{rsaCertificate},
3424 Bugs: ProtocolBugs{
3425 ExpectCertificateReqNames: caNames,
3426 },
3427 },
3428 flags: []string{
3429 "-require-any-client-certificate",
3430 "-use-client-ca-list", encodeDERValues(caNames),
3431 },
3432 })
3433
3434 testCases = append(testCases, testCase{
3435 testType: clientTest,
3436 name: ver.name + "-Client-CertReq-CA-List",
3437 config: Config{
3438 MinVersion: ver.version,
3439 MaxVersion: ver.version,
3440 Certificates: []Certificate{rsaCertificate},
3441 ClientAuth: RequireAnyClientCert,
3442 ClientCAs: certPool,
3443 },
3444 flags: []string{
3445 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3446 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3447 "-expect-client-ca-list", encodeDERValues(caNames),
3448 },
3449 })
David Benjamin636293b2014-07-08 17:59:18 -04003450 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003451
David Benjaminc032dfa2016-05-12 14:54:57 -04003452 // Client auth is only legal in certificate-based ciphers.
3453 testCases = append(testCases, testCase{
3454 testType: clientTest,
3455 name: "ClientAuth-PSK",
3456 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003457 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003458 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3459 PreSharedKey: []byte("secret"),
3460 ClientAuth: RequireAnyClientCert,
3461 },
3462 flags: []string{
3463 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3464 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3465 "-psk", "secret",
3466 },
3467 shouldFail: true,
3468 expectedError: ":UNEXPECTED_MESSAGE:",
3469 })
3470 testCases = append(testCases, testCase{
3471 testType: clientTest,
3472 name: "ClientAuth-ECDHE_PSK",
3473 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003474 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003475 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3476 PreSharedKey: []byte("secret"),
3477 ClientAuth: RequireAnyClientCert,
3478 },
3479 flags: []string{
3480 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3481 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3482 "-psk", "secret",
3483 },
3484 shouldFail: true,
3485 expectedError: ":UNEXPECTED_MESSAGE:",
3486 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003487
3488 // Regression test for a bug where the client CA list, if explicitly
3489 // set to NULL, was mis-encoded.
3490 testCases = append(testCases, testCase{
3491 testType: serverTest,
3492 name: "Null-Client-CA-List",
3493 config: Config{
3494 MaxVersion: VersionTLS12,
3495 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003496 Bugs: ProtocolBugs{
3497 ExpectCertificateReqNames: [][]byte{},
3498 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003499 },
3500 flags: []string{
3501 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003502 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003503 },
3504 })
David Benjamin636293b2014-07-08 17:59:18 -04003505}
3506
Adam Langley75712922014-10-10 16:23:43 -07003507func addExtendedMasterSecretTests() {
3508 const expectEMSFlag = "-expect-extended-master-secret"
3509
3510 for _, with := range []bool{false, true} {
3511 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003512 if with {
3513 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003514 }
3515
3516 for _, isClient := range []bool{false, true} {
3517 suffix := "-Server"
3518 testType := serverTest
3519 if isClient {
3520 suffix = "-Client"
3521 testType = clientTest
3522 }
3523
3524 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003525 // In TLS 1.3, the extension is irrelevant and
3526 // always reports as enabled.
3527 var flags []string
3528 if with || ver.version >= VersionTLS13 {
3529 flags = []string{expectEMSFlag}
3530 }
3531
Adam Langley75712922014-10-10 16:23:43 -07003532 test := testCase{
3533 testType: testType,
3534 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3535 config: Config{
3536 MinVersion: ver.version,
3537 MaxVersion: ver.version,
3538 Bugs: ProtocolBugs{
3539 NoExtendedMasterSecret: !with,
3540 RequireExtendedMasterSecret: with,
3541 },
3542 },
David Benjamin48cae082014-10-27 01:06:24 -04003543 flags: flags,
3544 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003545 }
3546 if test.shouldFail {
3547 test.expectedLocalError = "extended master secret required but not supported by peer"
3548 }
3549 testCases = append(testCases, test)
3550 }
3551 }
3552 }
3553
Adam Langleyba5934b2015-06-02 10:50:35 -07003554 for _, isClient := range []bool{false, true} {
3555 for _, supportedInFirstConnection := range []bool{false, true} {
3556 for _, supportedInResumeConnection := range []bool{false, true} {
3557 boolToWord := func(b bool) string {
3558 if b {
3559 return "Yes"
3560 }
3561 return "No"
3562 }
3563 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3564 if isClient {
3565 suffix += "Client"
3566 } else {
3567 suffix += "Server"
3568 }
3569
3570 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003571 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003572 Bugs: ProtocolBugs{
3573 RequireExtendedMasterSecret: true,
3574 },
3575 }
3576
3577 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003579 Bugs: ProtocolBugs{
3580 NoExtendedMasterSecret: true,
3581 },
3582 }
3583
3584 test := testCase{
3585 name: "ExtendedMasterSecret-" + suffix,
3586 resumeSession: true,
3587 }
3588
3589 if !isClient {
3590 test.testType = serverTest
3591 }
3592
3593 if supportedInFirstConnection {
3594 test.config = supportedConfig
3595 } else {
3596 test.config = noSupportConfig
3597 }
3598
3599 if supportedInResumeConnection {
3600 test.resumeConfig = &supportedConfig
3601 } else {
3602 test.resumeConfig = &noSupportConfig
3603 }
3604
3605 switch suffix {
3606 case "YesToYes-Client", "YesToYes-Server":
3607 // When a session is resumed, it should
3608 // still be aware that its master
3609 // secret was generated via EMS and
3610 // thus it's safe to use tls-unique.
3611 test.flags = []string{expectEMSFlag}
3612 case "NoToYes-Server":
3613 // If an original connection did not
3614 // contain EMS, but a resumption
3615 // handshake does, then a server should
3616 // not resume the session.
3617 test.expectResumeRejected = true
3618 case "YesToNo-Server":
3619 // Resuming an EMS session without the
3620 // EMS extension should cause the
3621 // server to abort the connection.
3622 test.shouldFail = true
3623 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3624 case "NoToYes-Client":
3625 // A client should abort a connection
3626 // where the server resumed a non-EMS
3627 // session but echoed the EMS
3628 // extension.
3629 test.shouldFail = true
3630 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3631 case "YesToNo-Client":
3632 // A client should abort a connection
3633 // where the server didn't echo EMS
3634 // when the session used it.
3635 test.shouldFail = true
3636 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3637 }
3638
3639 testCases = append(testCases, test)
3640 }
3641 }
3642 }
David Benjamin163c9562016-08-29 23:14:17 -04003643
3644 // Switching EMS on renegotiation is forbidden.
3645 testCases = append(testCases, testCase{
3646 name: "ExtendedMasterSecret-Renego-NoEMS",
3647 config: Config{
3648 MaxVersion: VersionTLS12,
3649 Bugs: ProtocolBugs{
3650 NoExtendedMasterSecret: true,
3651 NoExtendedMasterSecretOnRenegotiation: true,
3652 },
3653 },
3654 renegotiate: 1,
3655 flags: []string{
3656 "-renegotiate-freely",
3657 "-expect-total-renegotiations", "1",
3658 },
3659 })
3660
3661 testCases = append(testCases, testCase{
3662 name: "ExtendedMasterSecret-Renego-Upgrade",
3663 config: Config{
3664 MaxVersion: VersionTLS12,
3665 Bugs: ProtocolBugs{
3666 NoExtendedMasterSecret: true,
3667 },
3668 },
3669 renegotiate: 1,
3670 flags: []string{
3671 "-renegotiate-freely",
3672 "-expect-total-renegotiations", "1",
3673 },
3674 shouldFail: true,
3675 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3676 })
3677
3678 testCases = append(testCases, testCase{
3679 name: "ExtendedMasterSecret-Renego-Downgrade",
3680 config: Config{
3681 MaxVersion: VersionTLS12,
3682 Bugs: ProtocolBugs{
3683 NoExtendedMasterSecretOnRenegotiation: true,
3684 },
3685 },
3686 renegotiate: 1,
3687 flags: []string{
3688 "-renegotiate-freely",
3689 "-expect-total-renegotiations", "1",
3690 },
3691 shouldFail: true,
3692 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3693 })
Adam Langley75712922014-10-10 16:23:43 -07003694}
3695
David Benjamin582ba042016-07-07 12:33:25 -07003696type stateMachineTestConfig struct {
David Benjamine3843d42017-03-25 18:00:56 -05003697 protocol protocol
3698 async bool
3699 splitHandshake bool
3700 packHandshakeFlight bool
3701 implicitHandshake bool
David Benjamin582ba042016-07-07 12:33:25 -07003702}
3703
David Benjamin43ec06f2014-08-05 02:28:57 -04003704// Adds tests that try to cover the range of the handshake state machine, under
3705// various conditions. Some of these are redundant with other tests, but they
3706// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003707func addAllStateMachineCoverageTests() {
3708 for _, async := range []bool{false, true} {
3709 for _, protocol := range []protocol{tls, dtls} {
3710 addStateMachineCoverageTests(stateMachineTestConfig{
3711 protocol: protocol,
3712 async: async,
3713 })
3714 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamine3843d42017-03-25 18:00:56 -05003715 protocol: protocol,
3716 async: async,
3717 implicitHandshake: true,
3718 })
3719 addStateMachineCoverageTests(stateMachineTestConfig{
David Benjamin582ba042016-07-07 12:33:25 -07003720 protocol: protocol,
3721 async: async,
3722 splitHandshake: true,
3723 })
3724 if protocol == tls {
3725 addStateMachineCoverageTests(stateMachineTestConfig{
3726 protocol: protocol,
3727 async: async,
3728 packHandshakeFlight: true,
3729 })
3730 }
3731 }
3732 }
3733}
3734
3735func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003736 var tests []testCase
3737
3738 // Basic handshake, with resumption. Client and server,
3739 // session ID and session ticket.
3740 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003741 name: "Basic-Client",
3742 config: Config{
3743 MaxVersion: VersionTLS12,
3744 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003745 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003746 // Ensure session tickets are used, not session IDs.
3747 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003748 })
3749 tests = append(tests, testCase{
3750 name: "Basic-Client-RenewTicket",
3751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003752 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003753 Bugs: ProtocolBugs{
3754 RenewTicketOnResume: true,
3755 },
3756 },
David Benjamin46662482016-08-17 00:51:00 -04003757 flags: []string{"-expect-ticket-renewal"},
3758 resumeSession: true,
3759 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003760 })
3761 tests = append(tests, testCase{
3762 name: "Basic-Client-NoTicket",
3763 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003764 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003765 SessionTicketsDisabled: true,
3766 },
3767 resumeSession: true,
3768 })
3769 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003770 testType: serverTest,
3771 name: "Basic-Server",
3772 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003773 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003774 Bugs: ProtocolBugs{
3775 RequireSessionTickets: true,
3776 },
3777 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003778 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003779 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003780 })
3781 tests = append(tests, testCase{
3782 testType: serverTest,
3783 name: "Basic-Server-NoTickets",
3784 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003785 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 SessionTicketsDisabled: true,
3787 },
3788 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003789 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003790 })
3791 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003792 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003793 name: "Basic-Server-EarlyCallback",
3794 config: Config{
3795 MaxVersion: VersionTLS12,
3796 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003797 flags: []string{"-use-early-callback"},
3798 resumeSession: true,
3799 })
3800
Steven Valdez143e8b32016-07-11 13:19:03 -04003801 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003802 if config.protocol == tls {
3803 tests = append(tests, testCase{
3804 name: "TLS13-1RTT-Client",
3805 config: Config{
3806 MaxVersion: VersionTLS13,
3807 MinVersion: VersionTLS13,
3808 },
David Benjamin46662482016-08-17 00:51:00 -04003809 resumeSession: true,
3810 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003811 })
3812
3813 tests = append(tests, testCase{
3814 testType: serverTest,
3815 name: "TLS13-1RTT-Server",
3816 config: Config{
3817 MaxVersion: VersionTLS13,
3818 MinVersion: VersionTLS13,
3819 },
David Benjamin46662482016-08-17 00:51:00 -04003820 resumeSession: true,
3821 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003822 // TLS 1.3 uses tickets, so the session should not be
3823 // cached statefully.
3824 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003825 })
3826
3827 tests = append(tests, testCase{
3828 name: "TLS13-HelloRetryRequest-Client",
3829 config: Config{
3830 MaxVersion: VersionTLS13,
3831 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003832 // P-384 requires a HelloRetryRequest against BoringSSL's default
3833 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003834 CurvePreferences: []CurveID{CurveP384},
3835 Bugs: ProtocolBugs{
3836 ExpectMissingKeyShare: true,
3837 },
3838 },
3839 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3840 resumeSession: true,
3841 })
3842
3843 tests = append(tests, testCase{
3844 testType: serverTest,
3845 name: "TLS13-HelloRetryRequest-Server",
3846 config: Config{
3847 MaxVersion: VersionTLS13,
3848 MinVersion: VersionTLS13,
3849 // Require a HelloRetryRequest for every curve.
3850 DefaultCurves: []CurveID{},
3851 },
3852 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3853 resumeSession: true,
3854 })
Steven Valdez2d850622017-01-11 11:34:52 -05003855
Steven Valdez2d850622017-01-11 11:34:52 -05003856 tests = append(tests, testCase{
3857 testType: clientTest,
3858 name: "TLS13-EarlyData-Client",
3859 config: Config{
3860 MaxVersion: VersionTLS13,
3861 MinVersion: VersionTLS13,
3862 MaxEarlyDataSize: 16384,
3863 },
Steven Valdeze831a812017-03-09 14:56:07 -05003864 resumeConfig: &Config{
3865 MaxVersion: VersionTLS13,
3866 MinVersion: VersionTLS13,
3867 MaxEarlyDataSize: 16384,
3868 Bugs: ProtocolBugs{
3869 ExpectEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3870 },
3871 },
Steven Valdez2d850622017-01-11 11:34:52 -05003872 resumeSession: true,
3873 flags: []string{
3874 "-enable-early-data",
3875 "-expect-early-data-info",
3876 "-expect-accept-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -05003877 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -05003878 },
3879 })
3880
3881 tests = append(tests, testCase{
Steven Valdeze831a812017-03-09 14:56:07 -05003882 testType: clientTest,
3883 name: "TLS13-EarlyData-TooMuchData-Client",
3884 config: Config{
3885 MaxVersion: VersionTLS13,
3886 MinVersion: VersionTLS13,
3887 MaxEarlyDataSize: 2,
3888 },
3889 resumeConfig: &Config{
3890 MaxVersion: VersionTLS13,
3891 MinVersion: VersionTLS13,
3892 MaxEarlyDataSize: 2,
3893 Bugs: ProtocolBugs{
3894 ExpectEarlyData: [][]byte{{'h', 'e'}},
3895 },
3896 },
3897 resumeShimPrefix: "llo",
3898 resumeSession: true,
3899 flags: []string{
3900 "-enable-early-data",
3901 "-expect-early-data-info",
3902 "-expect-accept-early-data",
3903 "-on-resume-shim-writes-first",
3904 },
3905 })
3906
3907 // Unfinished writes can only be tested when operations are async. EarlyData
3908 // can't be tested as part of an ImplicitHandshake in this case since
3909 // otherwise the early data will be sent as normal data.
3910 if config.async && !config.implicitHandshake {
3911 tests = append(tests, testCase{
3912 testType: clientTest,
3913 name: "TLS13-EarlyData-UnfinishedWrite-Client",
3914 config: Config{
3915 MaxVersion: VersionTLS13,
3916 MinVersion: VersionTLS13,
3917 MaxEarlyDataSize: 16384,
3918 },
3919 resumeConfig: &Config{
3920 MaxVersion: VersionTLS13,
3921 MinVersion: VersionTLS13,
3922 MaxEarlyDataSize: 16384,
3923 Bugs: ProtocolBugs{
3924 ExpectLateEarlyData: [][]byte{{'h', 'e', 'l', 'l', 'o'}},
3925 },
3926 },
3927 resumeSession: true,
3928 flags: []string{
3929 "-enable-early-data",
3930 "-expect-early-data-info",
3931 "-expect-accept-early-data",
3932 "-on-resume-read-with-unfinished-write",
3933 "-on-resume-shim-writes-first",
3934 },
3935 })
3936
3937 // Rejected unfinished writes are discarded (from the
3938 // perspective of the calling application) on 0-RTT
3939 // reject.
3940 tests = append(tests, testCase{
3941 testType: clientTest,
3942 name: "TLS13-EarlyData-RejectUnfinishedWrite-Client",
3943 config: Config{
3944 MaxVersion: VersionTLS13,
3945 MinVersion: VersionTLS13,
3946 MaxEarlyDataSize: 16384,
3947 },
3948 resumeConfig: &Config{
3949 MaxVersion: VersionTLS13,
3950 MinVersion: VersionTLS13,
3951 MaxEarlyDataSize: 16384,
3952 Bugs: ProtocolBugs{
3953 AlwaysRejectEarlyData: true,
3954 },
3955 },
3956 resumeSession: true,
3957 flags: []string{
3958 "-enable-early-data",
3959 "-expect-early-data-info",
3960 "-expect-reject-early-data",
3961 "-on-resume-read-with-unfinished-write",
3962 "-on-resume-shim-writes-first",
3963 },
3964 })
3965 }
3966
3967 tests = append(tests, testCase{
Steven Valdez2d850622017-01-11 11:34:52 -05003968 testType: serverTest,
3969 name: "TLS13-EarlyData-Server",
3970 config: Config{
3971 MaxVersion: VersionTLS13,
3972 MinVersion: VersionTLS13,
3973 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -05003974 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -05003975 ExpectEarlyDataAccepted: true,
Steven Valdez681eb6a2016-12-19 13:19:29 -05003976 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
Steven Valdez2d850622017-01-11 11:34:52 -05003977 },
3978 },
Steven Valdez681eb6a2016-12-19 13:19:29 -05003979 messageCount: 2,
Steven Valdez2d850622017-01-11 11:34:52 -05003980 resumeSession: true,
3981 flags: []string{
3982 "-enable-early-data",
Steven Valdez681eb6a2016-12-19 13:19:29 -05003983 "-expect-accept-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -05003984 },
3985 })
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003986
3987 tests = append(tests, testCase{
3988 testType: serverTest,
3989 name: "TLS13-MaxEarlyData-Server",
3990 config: Config{
3991 MaxVersion: VersionTLS13,
3992 MinVersion: VersionTLS13,
3993 Bugs: ProtocolBugs{
David Benjamin29975892017-04-27 23:47:21 -04003994 SendEarlyData: [][]byte{bytes.Repeat([]byte{1}, 14336+1)},
Alessandro Ghedinide254b42017-04-17 19:12:33 +01003995 ExpectEarlyDataAccepted: true,
3996 },
3997 },
3998 messageCount: 2,
3999 resumeSession: true,
4000 flags: []string{
4001 "-enable-early-data",
4002 "-expect-accept-early-data",
4003 },
4004 shouldFail: true,
4005 expectedError: ":TOO_MUCH_READ_EARLY_DATA:",
4006 })
David Benjamine73c7f42016-08-17 00:29:33 -04004007 }
Steven Valdez143e8b32016-07-11 13:19:03 -04004008
David Benjamin760b1dd2015-05-15 23:33:48 -04004009 // TLS client auth.
4010 tests = append(tests, testCase{
4011 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004012 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05004013 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004014 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004015 ClientAuth: RequestClientCert,
4016 },
4017 })
4018 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004019 testType: serverTest,
4020 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004021 config: Config{
4022 MaxVersion: VersionTLS12,
4023 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004024 // Setting SSL_VERIFY_PEER allows anonymous clients.
4025 flags: []string{"-verify-peer"},
4026 })
David Benjamin582ba042016-07-07 12:33:25 -07004027 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004028 tests = append(tests, testCase{
4029 testType: clientTest,
4030 name: "ClientAuth-NoCertificate-Client-SSL3",
4031 config: Config{
4032 MaxVersion: VersionSSL30,
4033 ClientAuth: RequestClientCert,
4034 },
4035 })
4036 tests = append(tests, testCase{
4037 testType: serverTest,
4038 name: "ClientAuth-NoCertificate-Server-SSL3",
4039 config: Config{
4040 MaxVersion: VersionSSL30,
4041 },
4042 // Setting SSL_VERIFY_PEER allows anonymous clients.
4043 flags: []string{"-verify-peer"},
4044 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004045 tests = append(tests, testCase{
4046 testType: clientTest,
4047 name: "ClientAuth-NoCertificate-Client-TLS13",
4048 config: Config{
4049 MaxVersion: VersionTLS13,
4050 ClientAuth: RequestClientCert,
4051 },
4052 })
4053 tests = append(tests, testCase{
4054 testType: serverTest,
4055 name: "ClientAuth-NoCertificate-Server-TLS13",
4056 config: Config{
4057 MaxVersion: VersionTLS13,
4058 },
4059 // Setting SSL_VERIFY_PEER allows anonymous clients.
4060 flags: []string{"-verify-peer"},
4061 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05004062 }
4063 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05004064 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004065 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04004066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004067 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004068 ClientAuth: RequireAnyClientCert,
4069 },
4070 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07004071 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4072 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04004073 },
4074 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004075 tests = append(tests, testCase{
4076 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004077 name: "ClientAuth-RSA-Client-TLS13",
4078 config: Config{
4079 MaxVersion: VersionTLS13,
4080 ClientAuth: RequireAnyClientCert,
4081 },
4082 flags: []string{
4083 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4084 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4085 },
4086 })
4087 tests = append(tests, testCase{
4088 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004089 name: "ClientAuth-ECDSA-Client",
4090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004091 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004092 ClientAuth: RequireAnyClientCert,
4093 },
4094 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004095 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4096 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07004097 },
4098 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05004099 tests = append(tests, testCase{
4100 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004101 name: "ClientAuth-ECDSA-Client-TLS13",
4102 config: Config{
4103 MaxVersion: VersionTLS13,
4104 ClientAuth: RequireAnyClientCert,
4105 },
4106 flags: []string{
4107 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4108 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
4109 },
4110 })
4111 tests = append(tests, testCase{
4112 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04004113 name: "ClientAuth-NoCertificate-OldCallback",
4114 config: Config{
4115 MaxVersion: VersionTLS12,
4116 ClientAuth: RequestClientCert,
4117 },
4118 flags: []string{"-use-old-client-cert-callback"},
4119 })
4120 tests = append(tests, testCase{
4121 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04004122 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
4123 config: Config{
4124 MaxVersion: VersionTLS13,
4125 ClientAuth: RequestClientCert,
4126 },
4127 flags: []string{"-use-old-client-cert-callback"},
4128 })
4129 tests = append(tests, testCase{
4130 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004131 name: "ClientAuth-OldCallback",
4132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004133 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05004134 ClientAuth: RequireAnyClientCert,
4135 },
4136 flags: []string{
4137 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4138 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4139 "-use-old-client-cert-callback",
4140 },
4141 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004142 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04004143 testType: clientTest,
4144 name: "ClientAuth-OldCallback-TLS13",
4145 config: Config{
4146 MaxVersion: VersionTLS13,
4147 ClientAuth: RequireAnyClientCert,
4148 },
4149 flags: []string{
4150 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4151 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4152 "-use-old-client-cert-callback",
4153 },
4154 })
4155 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04004156 testType: serverTest,
4157 name: "ClientAuth-Server",
4158 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004159 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004160 Certificates: []Certificate{rsaCertificate},
4161 },
4162 flags: []string{"-require-any-client-certificate"},
4163 })
Steven Valdez143e8b32016-07-11 13:19:03 -04004164 tests = append(tests, testCase{
4165 testType: serverTest,
4166 name: "ClientAuth-Server-TLS13",
4167 config: Config{
4168 MaxVersion: VersionTLS13,
4169 Certificates: []Certificate{rsaCertificate},
4170 },
4171 flags: []string{"-require-any-client-certificate"},
4172 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004173
David Benjamin4c3ddf72016-06-29 18:13:53 -04004174 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04004175 tests = append(tests, testCase{
4176 testType: serverTest,
4177 name: "Basic-Server-RSA",
4178 config: Config{
4179 MaxVersion: VersionTLS12,
4180 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
4181 },
4182 flags: []string{
4183 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4184 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4185 },
4186 })
4187 tests = append(tests, testCase{
4188 testType: serverTest,
4189 name: "Basic-Server-ECDHE-RSA",
4190 config: Config{
4191 MaxVersion: VersionTLS12,
4192 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4193 },
4194 flags: []string{
4195 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
4196 "-key-file", path.Join(*resourceDir, rsaKeyFile),
4197 },
4198 })
4199 tests = append(tests, testCase{
4200 testType: serverTest,
4201 name: "Basic-Server-ECDHE-ECDSA",
4202 config: Config{
4203 MaxVersion: VersionTLS12,
4204 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4205 },
4206 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07004207 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
4208 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04004209 },
4210 })
David Benjamin69522112017-03-28 15:38:29 -05004211 tests = append(tests, testCase{
4212 testType: serverTest,
4213 name: "Basic-Server-Ed25519",
4214 config: Config{
4215 MaxVersion: VersionTLS12,
4216 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
4217 },
4218 flags: []string{
4219 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
4220 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
4221 "-enable-ed25519",
4222 },
4223 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004224
David Benjamin760b1dd2015-05-15 23:33:48 -04004225 // No session ticket support; server doesn't send NewSessionTicket.
4226 tests = append(tests, testCase{
4227 name: "SessionTicketsDisabled-Client",
4228 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004229 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004230 SessionTicketsDisabled: true,
4231 },
4232 })
4233 tests = append(tests, testCase{
4234 testType: serverTest,
4235 name: "SessionTicketsDisabled-Server",
4236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004237 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004238 SessionTicketsDisabled: true,
4239 },
4240 })
4241
4242 // Skip ServerKeyExchange in PSK key exchange if there's no
4243 // identity hint.
4244 tests = append(tests, testCase{
4245 name: "EmptyPSKHint-Client",
4246 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004247 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004248 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4249 PreSharedKey: []byte("secret"),
4250 },
4251 flags: []string{"-psk", "secret"},
4252 })
4253 tests = append(tests, testCase{
4254 testType: serverTest,
4255 name: "EmptyPSKHint-Server",
4256 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004257 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004258 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
4259 PreSharedKey: []byte("secret"),
4260 },
4261 flags: []string{"-psk", "secret"},
4262 })
4263
David Benjamin4c3ddf72016-06-29 18:13:53 -04004264 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004265 tests = append(tests, testCase{
4266 testType: clientTest,
4267 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04004268 config: Config{
4269 MaxVersion: VersionTLS12,
4270 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004271 flags: []string{
4272 "-enable-ocsp-stapling",
4273 "-expect-ocsp-response",
4274 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01004275 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004276 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004277 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004278 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004279 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004280 testType: serverTest,
4281 name: "OCSPStapling-Server",
4282 config: Config{
4283 MaxVersion: VersionTLS12,
4284 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004285 expectedOCSPResponse: testOCSPResponse,
4286 flags: []string{
4287 "-ocsp-response",
4288 base64.StdEncoding.EncodeToString(testOCSPResponse),
4289 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01004290 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004291 })
David Benjamin942f4ed2016-07-16 19:03:49 +03004292 tests = append(tests, testCase{
4293 testType: clientTest,
4294 name: "OCSPStapling-Client-TLS13",
4295 config: Config{
4296 MaxVersion: VersionTLS13,
4297 },
4298 flags: []string{
4299 "-enable-ocsp-stapling",
4300 "-expect-ocsp-response",
4301 base64.StdEncoding.EncodeToString(testOCSPResponse),
4302 "-verify-peer",
4303 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004304 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004305 })
4306 tests = append(tests, testCase{
4307 testType: serverTest,
4308 name: "OCSPStapling-Server-TLS13",
4309 config: Config{
4310 MaxVersion: VersionTLS13,
4311 },
4312 expectedOCSPResponse: testOCSPResponse,
4313 flags: []string{
4314 "-ocsp-response",
4315 base64.StdEncoding.EncodeToString(testOCSPResponse),
4316 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004317 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03004318 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01004319
David Benjamin4c3ddf72016-06-29 18:13:53 -04004320 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04004321 for _, vers := range tlsVersions {
4322 if config.protocol == dtls && !vers.hasDTLS {
4323 continue
4324 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04004325 for _, testType := range []testType{clientTest, serverTest} {
4326 suffix := "-Client"
4327 if testType == serverTest {
4328 suffix = "-Server"
4329 }
4330 suffix += "-" + vers.name
4331
4332 flag := "-verify-peer"
4333 if testType == serverTest {
4334 flag = "-require-any-client-certificate"
4335 }
4336
4337 tests = append(tests, testCase{
4338 testType: testType,
4339 name: "CertificateVerificationSucceed" + suffix,
4340 config: Config{
4341 MaxVersion: vers.version,
4342 Certificates: []Certificate{rsaCertificate},
4343 },
4344 flags: []string{
4345 flag,
4346 "-expect-verify-result",
4347 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004348 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04004349 })
4350 tests = append(tests, testCase{
4351 testType: testType,
4352 name: "CertificateVerificationFail" + suffix,
4353 config: Config{
4354 MaxVersion: vers.version,
4355 Certificates: []Certificate{rsaCertificate},
4356 },
4357 flags: []string{
4358 flag,
4359 "-verify-fail",
4360 },
4361 shouldFail: true,
4362 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
4363 })
4364 }
4365
4366 // By default, the client is in a soft fail mode where the peer
4367 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04004368 tests = append(tests, testCase{
4369 testType: clientTest,
4370 name: "CertificateVerificationSoftFail-" + vers.name,
4371 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04004372 MaxVersion: vers.version,
4373 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04004374 },
4375 flags: []string{
4376 "-verify-fail",
4377 "-expect-verify-result",
4378 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004379 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04004380 })
4381 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01004382
David Benjamin1d4f4c02016-07-26 18:03:08 -04004383 tests = append(tests, testCase{
4384 name: "ShimSendAlert",
4385 flags: []string{"-send-alert"},
4386 shimWritesFirst: true,
4387 shouldFail: true,
4388 expectedLocalError: "remote error: decompression failure",
4389 })
4390
David Benjamin582ba042016-07-07 12:33:25 -07004391 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04004392 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004393 name: "Renegotiate-Client",
4394 config: Config{
4395 MaxVersion: VersionTLS12,
4396 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04004397 renegotiate: 1,
4398 flags: []string{
4399 "-renegotiate-freely",
4400 "-expect-total-renegotiations", "1",
4401 },
David Benjamin760b1dd2015-05-15 23:33:48 -04004402 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04004403
David Benjamin47921102016-07-28 11:29:18 -04004404 tests = append(tests, testCase{
4405 name: "SendHalfHelloRequest",
4406 config: Config{
4407 MaxVersion: VersionTLS12,
4408 Bugs: ProtocolBugs{
4409 PackHelloRequestWithFinished: config.packHandshakeFlight,
4410 },
4411 },
4412 sendHalfHelloRequest: true,
4413 flags: []string{"-renegotiate-ignore"},
4414 shouldFail: true,
4415 expectedError: ":UNEXPECTED_RECORD:",
4416 })
4417
David Benjamin760b1dd2015-05-15 23:33:48 -04004418 // NPN on client and server; results in post-handshake message.
4419 tests = append(tests, testCase{
4420 name: "NPN-Client",
4421 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004422 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004423 NextProtos: []string{"foo"},
4424 },
4425 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04004426 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004427 expectedNextProto: "foo",
4428 expectedNextProtoType: npn,
4429 })
4430 tests = append(tests, testCase{
4431 testType: serverTest,
4432 name: "NPN-Server",
4433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004434 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004435 NextProtos: []string{"bar"},
4436 },
4437 flags: []string{
4438 "-advertise-npn", "\x03foo\x03bar\x03baz",
4439 "-expect-next-proto", "bar",
4440 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004441 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004442 expectedNextProto: "bar",
4443 expectedNextProtoType: npn,
4444 })
4445
4446 // TODO(davidben): Add tests for when False Start doesn't trigger.
4447
4448 // Client does False Start and negotiates NPN.
4449 tests = append(tests, testCase{
4450 name: "FalseStart",
4451 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004452 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004453 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4454 NextProtos: []string{"foo"},
4455 Bugs: ProtocolBugs{
4456 ExpectFalseStart: true,
4457 },
4458 },
4459 flags: []string{
4460 "-false-start",
4461 "-select-next-proto", "foo",
4462 },
4463 shimWritesFirst: true,
4464 resumeSession: true,
4465 })
4466
4467 // Client does False Start and negotiates ALPN.
4468 tests = append(tests, testCase{
4469 name: "FalseStart-ALPN",
4470 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004471 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004472 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4473 NextProtos: []string{"foo"},
4474 Bugs: ProtocolBugs{
4475 ExpectFalseStart: true,
4476 },
4477 },
4478 flags: []string{
4479 "-false-start",
4480 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04004481 "-expect-alpn", "foo",
David Benjamin760b1dd2015-05-15 23:33:48 -04004482 },
4483 shimWritesFirst: true,
4484 resumeSession: true,
4485 })
4486
David Benjamin760b1dd2015-05-15 23:33:48 -04004487 // False Start without session tickets.
4488 tests = append(tests, testCase{
4489 name: "FalseStart-SessionTicketsDisabled",
4490 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004491 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004492 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4493 NextProtos: []string{"foo"},
4494 SessionTicketsDisabled: true,
4495 Bugs: ProtocolBugs{
4496 ExpectFalseStart: true,
4497 },
4498 },
4499 flags: []string{
4500 "-false-start",
4501 "-select-next-proto", "foo",
4502 },
4503 shimWritesFirst: true,
4504 })
4505
4506 // Server parses a V2ClientHello.
4507 tests = append(tests, testCase{
4508 testType: serverTest,
4509 name: "SendV2ClientHello",
4510 config: Config{
4511 // Choose a cipher suite that does not involve
4512 // elliptic curves, so no extensions are
4513 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004514 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004515 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004516 Bugs: ProtocolBugs{
4517 SendV2ClientHello: true,
4518 },
4519 },
4520 })
4521
Nick Harper60a85cb2016-09-23 16:25:11 -07004522 // Test Channel ID
4523 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004524 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004525 continue
4526 }
4527 // Client sends a Channel ID.
4528 tests = append(tests, testCase{
4529 name: "ChannelID-Client-" + ver.name,
4530 config: Config{
4531 MaxVersion: ver.version,
4532 RequestChannelID: true,
4533 },
4534 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4535 resumeSession: true,
4536 expectChannelID: true,
4537 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004538
Nick Harper60a85cb2016-09-23 16:25:11 -07004539 // Server accepts a Channel ID.
4540 tests = append(tests, testCase{
4541 testType: serverTest,
4542 name: "ChannelID-Server-" + ver.name,
4543 config: Config{
4544 MaxVersion: ver.version,
4545 ChannelID: channelIDKey,
4546 },
4547 flags: []string{
4548 "-expect-channel-id",
4549 base64.StdEncoding.EncodeToString(channelIDBytes),
4550 },
4551 resumeSession: true,
4552 expectChannelID: true,
4553 })
4554
4555 tests = append(tests, testCase{
4556 testType: serverTest,
4557 name: "InvalidChannelIDSignature-" + ver.name,
4558 config: Config{
4559 MaxVersion: ver.version,
4560 ChannelID: channelIDKey,
4561 Bugs: ProtocolBugs{
4562 InvalidChannelIDSignature: true,
4563 },
4564 },
4565 flags: []string{"-enable-channel-id"},
4566 shouldFail: true,
4567 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4568 })
4569 }
David Benjamin30789da2015-08-29 22:56:45 -04004570
David Benjaminf8fcdf32016-06-08 15:56:13 -04004571 // Channel ID and NPN at the same time, to ensure their relative
4572 // ordering is correct.
4573 tests = append(tests, testCase{
4574 name: "ChannelID-NPN-Client",
4575 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004576 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004577 RequestChannelID: true,
4578 NextProtos: []string{"foo"},
4579 },
4580 flags: []string{
4581 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4582 "-select-next-proto", "foo",
4583 },
4584 resumeSession: true,
4585 expectChannelID: true,
4586 expectedNextProto: "foo",
4587 expectedNextProtoType: npn,
4588 })
4589 tests = append(tests, testCase{
4590 testType: serverTest,
4591 name: "ChannelID-NPN-Server",
4592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004593 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004594 ChannelID: channelIDKey,
4595 NextProtos: []string{"bar"},
4596 },
4597 flags: []string{
4598 "-expect-channel-id",
4599 base64.StdEncoding.EncodeToString(channelIDBytes),
4600 "-advertise-npn", "\x03foo\x03bar\x03baz",
4601 "-expect-next-proto", "bar",
4602 },
4603 resumeSession: true,
4604 expectChannelID: true,
4605 expectedNextProto: "bar",
4606 expectedNextProtoType: npn,
4607 })
4608
David Benjamin30789da2015-08-29 22:56:45 -04004609 // Bidirectional shutdown with the runner initiating.
4610 tests = append(tests, testCase{
4611 name: "Shutdown-Runner",
4612 config: Config{
4613 Bugs: ProtocolBugs{
4614 ExpectCloseNotify: true,
4615 },
4616 },
4617 flags: []string{"-check-close-notify"},
4618 })
4619
David Benjamine3843d42017-03-25 18:00:56 -05004620 if !config.implicitHandshake {
4621 // Bidirectional shutdown with the shim initiating. The runner,
4622 // in the meantime, sends garbage before the close_notify which
4623 // the shim must ignore. This test is disabled under implicit
4624 // handshake tests because the shim never reads or writes.
4625 tests = append(tests, testCase{
4626 name: "Shutdown-Shim",
4627 config: Config{
4628 MaxVersion: VersionTLS12,
4629 Bugs: ProtocolBugs{
4630 ExpectCloseNotify: true,
4631 },
David Benjamin30789da2015-08-29 22:56:45 -04004632 },
David Benjamine3843d42017-03-25 18:00:56 -05004633 shimShutsDown: true,
4634 sendEmptyRecords: 1,
4635 sendWarningAlerts: 1,
4636 flags: []string{"-check-close-notify"},
4637 })
4638 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004639 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004640 // TODO(davidben): DTLS 1.3 will want a similar thing for
4641 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004642 tests = append(tests, testCase{
4643 name: "SkipHelloVerifyRequest",
4644 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004645 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004646 Bugs: ProtocolBugs{
4647 SkipHelloVerifyRequest: true,
4648 },
4649 },
4650 })
4651 }
4652
David Benjamin760b1dd2015-05-15 23:33:48 -04004653 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004654 test.protocol = config.protocol
4655 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004656 test.name += "-DTLS"
4657 }
David Benjamin582ba042016-07-07 12:33:25 -07004658 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004659 test.name += "-Async"
4660 test.flags = append(test.flags, "-async")
4661 } else {
4662 test.name += "-Sync"
4663 }
David Benjamin582ba042016-07-07 12:33:25 -07004664 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004665 test.name += "-SplitHandshakeRecords"
4666 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004667 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004668 test.config.Bugs.MaxPacketLength = 256
4669 test.flags = append(test.flags, "-mtu", "256")
4670 }
4671 }
David Benjamin582ba042016-07-07 12:33:25 -07004672 if config.packHandshakeFlight {
4673 test.name += "-PackHandshakeFlight"
4674 test.config.Bugs.PackHandshakeFlight = true
4675 }
David Benjamine3843d42017-03-25 18:00:56 -05004676 if config.implicitHandshake {
4677 test.name += "-ImplicitHandshake"
4678 test.flags = append(test.flags, "-implicit-handshake")
4679 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004680 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004681 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004682}
4683
Adam Langley524e7172015-02-20 16:04:00 -08004684func addDDoSCallbackTests() {
4685 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004686 for _, resume := range []bool{false, true} {
4687 suffix := "Resume"
4688 if resume {
4689 suffix = "No" + suffix
4690 }
4691
4692 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004693 testType: serverTest,
4694 name: "Server-DDoS-OK-" + suffix,
4695 config: Config{
4696 MaxVersion: VersionTLS12,
4697 },
Adam Langley524e7172015-02-20 16:04:00 -08004698 flags: []string{"-install-ddos-callback"},
4699 resumeSession: resume,
4700 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004701 testCases = append(testCases, testCase{
4702 testType: serverTest,
4703 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4704 config: Config{
4705 MaxVersion: VersionTLS13,
4706 },
4707 flags: []string{"-install-ddos-callback"},
4708 resumeSession: resume,
4709 })
Adam Langley524e7172015-02-20 16:04:00 -08004710
4711 failFlag := "-fail-ddos-callback"
4712 if resume {
4713 failFlag = "-fail-second-ddos-callback"
4714 }
4715 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004716 testType: serverTest,
4717 name: "Server-DDoS-Reject-" + suffix,
4718 config: Config{
4719 MaxVersion: VersionTLS12,
4720 },
David Benjamin2c66e072016-09-16 15:58:00 -04004721 flags: []string{"-install-ddos-callback", failFlag},
4722 resumeSession: resume,
4723 shouldFail: true,
4724 expectedError: ":CONNECTION_REJECTED:",
4725 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004726 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004727 testCases = append(testCases, testCase{
4728 testType: serverTest,
4729 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4730 config: Config{
4731 MaxVersion: VersionTLS13,
4732 },
David Benjamin2c66e072016-09-16 15:58:00 -04004733 flags: []string{"-install-ddos-callback", failFlag},
4734 resumeSession: resume,
4735 shouldFail: true,
4736 expectedError: ":CONNECTION_REJECTED:",
4737 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004738 })
Adam Langley524e7172015-02-20 16:04:00 -08004739 }
4740}
4741
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004742func addVersionNegotiationTests() {
4743 for i, shimVers := range tlsVersions {
4744 // Assemble flags to disable all newer versions on the shim.
4745 var flags []string
4746 for _, vers := range tlsVersions[i+1:] {
David Benjamin353577c2017-06-29 15:54:58 -04004747 flags = append(flags, vers.excludeFlag)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004748 }
4749
Steven Valdezfdd10992016-09-15 16:27:05 -04004750 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004751 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004752 protocols := []protocol{tls}
4753 if runnerVers.hasDTLS && shimVers.hasDTLS {
4754 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004755 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004756 for _, protocol := range protocols {
4757 expectedVersion := shimVers.version
4758 if runnerVers.version < shimVers.version {
4759 expectedVersion = runnerVers.version
4760 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004761
David Benjamin8b8c0062014-11-23 02:47:52 -05004762 suffix := shimVers.name + "-" + runnerVers.name
4763 if protocol == dtls {
4764 suffix += "-DTLS"
4765 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004766
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004767 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004768 clientVers := shimVers.version
4769 if clientVers > VersionTLS10 {
4770 clientVers = VersionTLS10
4771 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004772 clientVers = configVersionToWire(clientVers, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07004773 serverVers := expectedVersion
4774 if expectedVersion >= VersionTLS13 {
4775 serverVers = VersionTLS10
4776 }
Steven Valdezc94998a2017-06-20 10:55:02 -04004777 serverVers = configVersionToWire(serverVers, protocol)
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004778
David Benjamin8b8c0062014-11-23 02:47:52 -05004779 testCases = append(testCases, testCase{
4780 protocol: protocol,
4781 testType: clientTest,
4782 name: "VersionNegotiation-Client-" + suffix,
4783 config: Config{
4784 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004785 Bugs: ProtocolBugs{
4786 ExpectInitialRecordVersion: clientVers,
4787 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004788 },
4789 flags: flags,
4790 expectedVersion: expectedVersion,
4791 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004792 testCases = append(testCases, testCase{
4793 protocol: protocol,
4794 testType: clientTest,
4795 name: "VersionNegotiation-Client2-" + suffix,
4796 config: Config{
4797 MaxVersion: runnerVers.version,
4798 Bugs: ProtocolBugs{
4799 ExpectInitialRecordVersion: clientVers,
4800 },
4801 },
David Benjamin353577c2017-06-29 15:54:58 -04004802 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004803 expectedVersion: expectedVersion,
4804 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004805
4806 testCases = append(testCases, testCase{
4807 protocol: protocol,
4808 testType: serverTest,
4809 name: "VersionNegotiation-Server-" + suffix,
4810 config: Config{
4811 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004812 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004813 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004814 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004815 },
4816 flags: flags,
4817 expectedVersion: expectedVersion,
4818 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004819 testCases = append(testCases, testCase{
4820 protocol: protocol,
4821 testType: serverTest,
4822 name: "VersionNegotiation-Server2-" + suffix,
4823 config: Config{
4824 MaxVersion: runnerVers.version,
4825 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004826 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004827 },
4828 },
David Benjamin353577c2017-06-29 15:54:58 -04004829 flags: []string{"-max-version", shimVers.shimFlag(protocol)},
David Benjamin1eb367c2014-12-12 18:17:51 -05004830 expectedVersion: expectedVersion,
4831 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004832 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004833 }
4834 }
David Benjamin95c69562016-06-29 18:15:03 -04004835
Steven Valdezfdd10992016-09-15 16:27:05 -04004836 // Test the version extension at all versions.
4837 for _, vers := range tlsVersions {
4838 protocols := []protocol{tls}
4839 if vers.hasDTLS {
4840 protocols = append(protocols, dtls)
4841 }
4842 for _, protocol := range protocols {
4843 suffix := vers.name
4844 if protocol == dtls {
4845 suffix += "-DTLS"
4846 }
4847
Steven Valdezc94998a2017-06-20 10:55:02 -04004848 wireVersion := configVersionToWire(vers.version, protocol)
Steven Valdezfdd10992016-09-15 16:27:05 -04004849 testCases = append(testCases, testCase{
4850 protocol: protocol,
4851 testType: serverTest,
4852 name: "VersionNegotiationExtension-" + suffix,
4853 config: Config{
4854 Bugs: ProtocolBugs{
4855 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4856 },
4857 },
4858 expectedVersion: vers.version,
4859 })
4860 }
4861
4862 }
4863
4864 // If all versions are unknown, negotiation fails.
4865 testCases = append(testCases, testCase{
4866 testType: serverTest,
4867 name: "NoSupportedVersions",
4868 config: Config{
4869 Bugs: ProtocolBugs{
4870 SendSupportedVersions: []uint16{0x1111},
4871 },
4872 },
4873 shouldFail: true,
4874 expectedError: ":UNSUPPORTED_PROTOCOL:",
4875 })
4876 testCases = append(testCases, testCase{
4877 protocol: dtls,
4878 testType: serverTest,
4879 name: "NoSupportedVersions-DTLS",
4880 config: Config{
4881 Bugs: ProtocolBugs{
4882 SendSupportedVersions: []uint16{0x1111},
4883 },
4884 },
4885 shouldFail: true,
4886 expectedError: ":UNSUPPORTED_PROTOCOL:",
4887 })
4888
4889 testCases = append(testCases, testCase{
4890 testType: serverTest,
4891 name: "ClientHelloVersionTooHigh",
4892 config: Config{
4893 MaxVersion: VersionTLS13,
4894 Bugs: ProtocolBugs{
4895 SendClientVersion: 0x0304,
4896 OmitSupportedVersions: true,
4897 },
4898 },
4899 expectedVersion: VersionTLS12,
4900 })
4901
4902 testCases = append(testCases, testCase{
4903 testType: serverTest,
4904 name: "ConflictingVersionNegotiation",
4905 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004906 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004907 SendClientVersion: VersionTLS12,
4908 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004909 },
4910 },
David Benjaminad75a662016-09-30 15:42:59 -04004911 // The extension takes precedence over the ClientHello version.
4912 expectedVersion: VersionTLS11,
4913 })
4914
4915 testCases = append(testCases, testCase{
4916 testType: serverTest,
4917 name: "ConflictingVersionNegotiation-2",
4918 config: Config{
4919 Bugs: ProtocolBugs{
4920 SendClientVersion: VersionTLS11,
4921 SendSupportedVersions: []uint16{VersionTLS12},
4922 },
4923 },
4924 // The extension takes precedence over the ClientHello version.
4925 expectedVersion: VersionTLS12,
4926 })
4927
4928 testCases = append(testCases, testCase{
4929 testType: serverTest,
4930 name: "RejectFinalTLS13",
4931 config: Config{
4932 Bugs: ProtocolBugs{
4933 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4934 },
4935 },
4936 // We currently implement a draft TLS 1.3 version. Ensure that
4937 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004938 expectedVersion: VersionTLS12,
4939 })
4940
Brian Smithf85d3232016-10-28 10:34:06 -10004941 // Test that the maximum version is selected regardless of the
4942 // client-sent order.
4943 testCases = append(testCases, testCase{
4944 testType: serverTest,
4945 name: "IgnoreClientVersionOrder",
4946 config: Config{
4947 Bugs: ProtocolBugs{
4948 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4949 },
4950 },
4951 expectedVersion: VersionTLS13,
4952 })
4953
David Benjamin95c69562016-06-29 18:15:03 -04004954 // Test for version tolerance.
4955 testCases = append(testCases, testCase{
4956 testType: serverTest,
4957 name: "MinorVersionTolerance",
4958 config: Config{
4959 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004960 SendClientVersion: 0x03ff,
4961 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004962 },
4963 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004964 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004965 })
4966 testCases = append(testCases, testCase{
4967 testType: serverTest,
4968 name: "MajorVersionTolerance",
4969 config: Config{
4970 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004971 SendClientVersion: 0x0400,
4972 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004973 },
4974 },
David Benjaminad75a662016-09-30 15:42:59 -04004975 // TLS 1.3 must be negotiated with the supported_versions
4976 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004977 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004978 })
David Benjaminad75a662016-09-30 15:42:59 -04004979 testCases = append(testCases, testCase{
4980 testType: serverTest,
4981 name: "VersionTolerance-TLS13",
4982 config: Config{
4983 Bugs: ProtocolBugs{
4984 // Although TLS 1.3 does not use
4985 // ClientHello.version, it still tolerates high
4986 // values there.
4987 SendClientVersion: 0x0400,
4988 },
4989 },
4990 expectedVersion: VersionTLS13,
4991 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004992
David Benjamin95c69562016-06-29 18:15:03 -04004993 testCases = append(testCases, testCase{
4994 protocol: dtls,
4995 testType: serverTest,
4996 name: "MinorVersionTolerance-DTLS",
4997 config: Config{
4998 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004999 SendClientVersion: 0xfe00,
5000 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005001 },
5002 },
5003 expectedVersion: VersionTLS12,
5004 })
5005 testCases = append(testCases, testCase{
5006 protocol: dtls,
5007 testType: serverTest,
5008 name: "MajorVersionTolerance-DTLS",
5009 config: Config{
5010 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005011 SendClientVersion: 0xfdff,
5012 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005013 },
5014 },
5015 expectedVersion: VersionTLS12,
5016 })
5017
5018 // Test that versions below 3.0 are rejected.
5019 testCases = append(testCases, testCase{
5020 testType: serverTest,
5021 name: "VersionTooLow",
5022 config: Config{
5023 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04005024 SendClientVersion: 0x0200,
5025 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04005026 },
5027 },
5028 shouldFail: true,
5029 expectedError: ":UNSUPPORTED_PROTOCOL:",
5030 })
5031 testCases = append(testCases, testCase{
5032 protocol: dtls,
5033 testType: serverTest,
5034 name: "VersionTooLow-DTLS",
5035 config: Config{
5036 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04005037 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04005038 },
5039 },
5040 shouldFail: true,
5041 expectedError: ":UNSUPPORTED_PROTOCOL:",
5042 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04005043
David Benjamin2dc02042016-09-19 19:57:37 -04005044 testCases = append(testCases, testCase{
5045 name: "ServerBogusVersion",
5046 config: Config{
5047 Bugs: ProtocolBugs{
5048 SendServerHelloVersion: 0x1234,
5049 },
5050 },
5051 shouldFail: true,
5052 expectedError: ":UNSUPPORTED_PROTOCOL:",
5053 })
5054
David Benjamin1f61f0d2016-07-10 12:20:35 -04005055 // Test TLS 1.3's downgrade signal.
5056 testCases = append(testCases, testCase{
5057 name: "Downgrade-TLS12-Client",
5058 config: Config{
5059 Bugs: ProtocolBugs{
5060 NegotiateVersion: VersionTLS12,
5061 },
5062 },
David Benjamin592b5322016-09-30 15:15:01 -04005063 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005064 // TODO(davidben): This test should fail once TLS 1.3 is final
5065 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005066 })
5067 testCases = append(testCases, testCase{
5068 testType: serverTest,
5069 name: "Downgrade-TLS12-Server",
5070 config: Config{
5071 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04005072 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04005073 },
5074 },
David Benjamin592b5322016-09-30 15:15:01 -04005075 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04005076 // TODO(davidben): This test should fail once TLS 1.3 is final
5077 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04005078 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04005079}
5080
David Benjaminaccb4542014-12-12 23:44:33 -05005081func addMinimumVersionTests() {
5082 for i, shimVers := range tlsVersions {
5083 // Assemble flags to disable all older versions on the shim.
5084 var flags []string
5085 for _, vers := range tlsVersions[:i] {
David Benjamin353577c2017-06-29 15:54:58 -04005086 flags = append(flags, vers.excludeFlag)
David Benjaminaccb4542014-12-12 23:44:33 -05005087 }
5088
5089 for _, runnerVers := range tlsVersions {
5090 protocols := []protocol{tls}
5091 if runnerVers.hasDTLS && shimVers.hasDTLS {
5092 protocols = append(protocols, dtls)
5093 }
5094 for _, protocol := range protocols {
5095 suffix := shimVers.name + "-" + runnerVers.name
5096 if protocol == dtls {
5097 suffix += "-DTLS"
5098 }
David Benjaminaccb4542014-12-12 23:44:33 -05005099
David Benjaminaccb4542014-12-12 23:44:33 -05005100 var expectedVersion uint16
5101 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04005102 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05005103 if runnerVers.version >= shimVers.version {
5104 expectedVersion = runnerVers.version
5105 } else {
5106 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04005107 expectedError = ":UNSUPPORTED_PROTOCOL:"
5108 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05005109 }
5110
5111 testCases = append(testCases, testCase{
5112 protocol: protocol,
5113 testType: clientTest,
5114 name: "MinimumVersion-Client-" + suffix,
5115 config: Config{
5116 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005117 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005118 // Ensure the server does not decline to
5119 // select a version (versions extension) or
5120 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005121 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005122 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005123 },
David Benjaminaccb4542014-12-12 23:44:33 -05005124 },
David Benjamin87909c02014-12-13 01:55:01 -05005125 flags: flags,
5126 expectedVersion: expectedVersion,
5127 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005128 expectedError: expectedError,
5129 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005130 })
5131 testCases = append(testCases, testCase{
5132 protocol: protocol,
5133 testType: clientTest,
5134 name: "MinimumVersion-Client2-" + suffix,
5135 config: Config{
5136 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04005137 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04005138 // Ensure the server does not decline to
5139 // select a version (versions extension) or
5140 // cipher (some ciphers depend on versions).
Steven Valdezc94998a2017-06-20 10:55:02 -04005141 NegotiateVersion: configVersionToWire(runnerVers.version, protocol),
David Benjamin6dbde982016-10-03 19:11:14 -04005142 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04005143 },
David Benjaminaccb4542014-12-12 23:44:33 -05005144 },
David Benjamin353577c2017-06-29 15:54:58 -04005145 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005146 expectedVersion: expectedVersion,
5147 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005148 expectedError: expectedError,
5149 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005150 })
5151
5152 testCases = append(testCases, testCase{
5153 protocol: protocol,
5154 testType: serverTest,
5155 name: "MinimumVersion-Server-" + suffix,
5156 config: Config{
5157 MaxVersion: runnerVers.version,
5158 },
David Benjamin87909c02014-12-13 01:55:01 -05005159 flags: flags,
5160 expectedVersion: expectedVersion,
5161 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005162 expectedError: expectedError,
5163 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005164 })
5165 testCases = append(testCases, testCase{
5166 protocol: protocol,
5167 testType: serverTest,
5168 name: "MinimumVersion-Server2-" + suffix,
5169 config: Config{
5170 MaxVersion: runnerVers.version,
5171 },
David Benjamin353577c2017-06-29 15:54:58 -04005172 flags: []string{"-min-version", shimVers.shimFlag(protocol)},
David Benjamin87909c02014-12-13 01:55:01 -05005173 expectedVersion: expectedVersion,
5174 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04005175 expectedError: expectedError,
5176 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05005177 })
5178 }
5179 }
5180 }
5181}
5182
David Benjamine78bfde2014-09-06 12:45:15 -04005183func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04005184 // TODO(davidben): Extensions, where applicable, all move their server
5185 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
5186 // tests for both. Also test interaction with 0-RTT when implemented.
5187
David Benjamin97d17d92016-07-14 16:12:00 -04005188 // Repeat extensions tests all versions except SSL 3.0.
5189 for _, ver := range tlsVersions {
5190 if ver.version == VersionSSL30 {
5191 continue
5192 }
5193
David Benjamin97d17d92016-07-14 16:12:00 -04005194 // Test that duplicate extensions are rejected.
5195 testCases = append(testCases, testCase{
5196 testType: clientTest,
5197 name: "DuplicateExtensionClient-" + ver.name,
5198 config: Config{
5199 MaxVersion: ver.version,
5200 Bugs: ProtocolBugs{
5201 DuplicateExtension: true,
5202 },
David Benjamine78bfde2014-09-06 12:45:15 -04005203 },
David Benjamin97d17d92016-07-14 16:12:00 -04005204 shouldFail: true,
5205 expectedLocalError: "remote error: error decoding message",
5206 })
5207 testCases = append(testCases, testCase{
5208 testType: serverTest,
5209 name: "DuplicateExtensionServer-" + ver.name,
5210 config: Config{
5211 MaxVersion: ver.version,
5212 Bugs: ProtocolBugs{
5213 DuplicateExtension: true,
5214 },
David Benjamine78bfde2014-09-06 12:45:15 -04005215 },
David Benjamin97d17d92016-07-14 16:12:00 -04005216 shouldFail: true,
5217 expectedLocalError: "remote error: error decoding message",
5218 })
5219
5220 // Test SNI.
5221 testCases = append(testCases, testCase{
5222 testType: clientTest,
5223 name: "ServerNameExtensionClient-" + ver.name,
5224 config: Config{
5225 MaxVersion: ver.version,
5226 Bugs: ProtocolBugs{
5227 ExpectServerName: "example.com",
5228 },
David Benjamine78bfde2014-09-06 12:45:15 -04005229 },
David Benjamin97d17d92016-07-14 16:12:00 -04005230 flags: []string{"-host-name", "example.com"},
5231 })
5232 testCases = append(testCases, testCase{
5233 testType: clientTest,
5234 name: "ServerNameExtensionClientMismatch-" + ver.name,
5235 config: Config{
5236 MaxVersion: ver.version,
5237 Bugs: ProtocolBugs{
5238 ExpectServerName: "mismatch.com",
5239 },
David Benjamine78bfde2014-09-06 12:45:15 -04005240 },
David Benjamin97d17d92016-07-14 16:12:00 -04005241 flags: []string{"-host-name", "example.com"},
5242 shouldFail: true,
5243 expectedLocalError: "tls: unexpected server name",
5244 })
5245 testCases = append(testCases, testCase{
5246 testType: clientTest,
5247 name: "ServerNameExtensionClientMissing-" + ver.name,
5248 config: Config{
5249 MaxVersion: ver.version,
5250 Bugs: ProtocolBugs{
5251 ExpectServerName: "missing.com",
5252 },
David Benjamine78bfde2014-09-06 12:45:15 -04005253 },
David Benjamin97d17d92016-07-14 16:12:00 -04005254 shouldFail: true,
5255 expectedLocalError: "tls: unexpected server name",
5256 })
5257 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05005258 testType: clientTest,
5259 name: "TolerateServerNameAck-" + ver.name,
5260 config: Config{
5261 MaxVersion: ver.version,
5262 Bugs: ProtocolBugs{
5263 SendServerNameAck: true,
5264 },
5265 },
5266 flags: []string{"-host-name", "example.com"},
5267 resumeSession: true,
5268 })
5269 testCases = append(testCases, testCase{
5270 testType: clientTest,
5271 name: "UnsolicitedServerNameAck-" + ver.name,
5272 config: Config{
5273 MaxVersion: ver.version,
5274 Bugs: ProtocolBugs{
5275 SendServerNameAck: true,
5276 },
5277 },
5278 shouldFail: true,
5279 expectedError: ":UNEXPECTED_EXTENSION:",
5280 expectedLocalError: "remote error: unsupported extension",
5281 })
5282 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005283 testType: serverTest,
5284 name: "ServerNameExtensionServer-" + ver.name,
5285 config: Config{
5286 MaxVersion: ver.version,
5287 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04005288 },
David Benjamin97d17d92016-07-14 16:12:00 -04005289 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005290 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005291 })
5292
5293 // Test ALPN.
5294 testCases = append(testCases, testCase{
5295 testType: clientTest,
5296 name: "ALPNClient-" + ver.name,
5297 config: Config{
5298 MaxVersion: ver.version,
5299 NextProtos: []string{"foo"},
5300 },
5301 flags: []string{
5302 "-advertise-alpn", "\x03foo\x03bar\x03baz",
5303 "-expect-alpn", "foo",
5304 },
5305 expectedNextProto: "foo",
5306 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005307 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005308 })
5309 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04005310 testType: clientTest,
David Benjaminc8ff30c2017-04-04 13:52:36 -04005311 name: "ALPNClient-RejectUnknown-" + ver.name,
David Benjamin3e517572016-08-11 11:52:23 -04005312 config: Config{
5313 MaxVersion: ver.version,
5314 Bugs: ProtocolBugs{
5315 SendALPN: "baz",
5316 },
5317 },
5318 flags: []string{
5319 "-advertise-alpn", "\x03foo\x03bar",
5320 },
5321 shouldFail: true,
5322 expectedError: ":INVALID_ALPN_PROTOCOL:",
5323 expectedLocalError: "remote error: illegal parameter",
5324 })
5325 testCases = append(testCases, testCase{
David Benjaminc8ff30c2017-04-04 13:52:36 -04005326 testType: clientTest,
5327 name: "ALPNClient-AllowUnknown-" + ver.name,
5328 config: Config{
5329 MaxVersion: ver.version,
5330 Bugs: ProtocolBugs{
5331 SendALPN: "baz",
5332 },
5333 },
5334 flags: []string{
5335 "-advertise-alpn", "\x03foo\x03bar",
5336 "-allow-unknown-alpn-protos",
Steven Valdez873ebc92017-05-09 12:12:58 -04005337 "-expect-alpn", "baz",
David Benjaminc8ff30c2017-04-04 13:52:36 -04005338 },
5339 })
5340 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04005341 testType: serverTest,
5342 name: "ALPNServer-" + ver.name,
5343 config: Config{
5344 MaxVersion: ver.version,
5345 NextProtos: []string{"foo", "bar", "baz"},
5346 },
5347 flags: []string{
5348 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5349 "-select-alpn", "foo",
5350 },
5351 expectedNextProto: "foo",
5352 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005353 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005354 })
5355 testCases = append(testCases, testCase{
5356 testType: serverTest,
5357 name: "ALPNServer-Decline-" + ver.name,
5358 config: Config{
5359 MaxVersion: ver.version,
5360 NextProtos: []string{"foo", "bar", "baz"},
5361 },
5362 flags: []string{"-decline-alpn"},
5363 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005364 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005365 })
5366
David Benjamin25fe85b2016-08-09 20:00:32 -04005367 // Test ALPN in async mode as well to ensure that extensions callbacks are only
5368 // called once.
5369 testCases = append(testCases, testCase{
5370 testType: serverTest,
5371 name: "ALPNServer-Async-" + ver.name,
5372 config: Config{
5373 MaxVersion: ver.version,
5374 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09005375 // Prior to TLS 1.3, exercise the asynchronous session callback.
5376 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04005377 },
5378 flags: []string{
5379 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5380 "-select-alpn", "foo",
5381 "-async",
5382 },
5383 expectedNextProto: "foo",
5384 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005385 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04005386 })
5387
David Benjamin97d17d92016-07-14 16:12:00 -04005388 var emptyString string
5389 testCases = append(testCases, testCase{
5390 testType: clientTest,
5391 name: "ALPNClient-EmptyProtocolName-" + ver.name,
5392 config: Config{
5393 MaxVersion: ver.version,
5394 NextProtos: []string{""},
5395 Bugs: ProtocolBugs{
5396 // A server returning an empty ALPN protocol
5397 // should be rejected.
5398 ALPNProtocol: &emptyString,
5399 },
5400 },
5401 flags: []string{
5402 "-advertise-alpn", "\x03foo",
5403 },
5404 shouldFail: true,
5405 expectedError: ":PARSE_TLSEXT:",
5406 })
5407 testCases = append(testCases, testCase{
5408 testType: serverTest,
5409 name: "ALPNServer-EmptyProtocolName-" + ver.name,
5410 config: Config{
5411 MaxVersion: ver.version,
5412 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07005413 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04005414 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07005415 },
David Benjamin97d17d92016-07-14 16:12:00 -04005416 flags: []string{
5417 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04005418 },
David Benjamin97d17d92016-07-14 16:12:00 -04005419 shouldFail: true,
5420 expectedError: ":PARSE_TLSEXT:",
5421 })
5422
5423 // Test NPN and the interaction with ALPN.
5424 if ver.version < VersionTLS13 {
5425 // Test that the server prefers ALPN over NPN.
5426 testCases = append(testCases, testCase{
5427 testType: serverTest,
5428 name: "ALPNServer-Preferred-" + ver.name,
5429 config: Config{
5430 MaxVersion: ver.version,
5431 NextProtos: []string{"foo", "bar", "baz"},
5432 },
5433 flags: []string{
5434 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5435 "-select-alpn", "foo",
5436 "-advertise-npn", "\x03foo\x03bar\x03baz",
5437 },
5438 expectedNextProto: "foo",
5439 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005440 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005441 })
5442 testCases = append(testCases, testCase{
5443 testType: serverTest,
5444 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5445 config: Config{
5446 MaxVersion: ver.version,
5447 NextProtos: []string{"foo", "bar", "baz"},
5448 Bugs: ProtocolBugs{
5449 SwapNPNAndALPN: true,
5450 },
5451 },
5452 flags: []string{
5453 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5454 "-select-alpn", "foo",
5455 "-advertise-npn", "\x03foo\x03bar\x03baz",
5456 },
5457 expectedNextProto: "foo",
5458 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005459 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005460 })
5461
5462 // Test that negotiating both NPN and ALPN is forbidden.
5463 testCases = append(testCases, testCase{
5464 name: "NegotiateALPNAndNPN-" + ver.name,
5465 config: Config{
5466 MaxVersion: ver.version,
5467 NextProtos: []string{"foo", "bar", "baz"},
5468 Bugs: ProtocolBugs{
5469 NegotiateALPNAndNPN: true,
5470 },
5471 },
5472 flags: []string{
5473 "-advertise-alpn", "\x03foo",
5474 "-select-next-proto", "foo",
5475 },
5476 shouldFail: true,
5477 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5478 })
5479 testCases = append(testCases, testCase{
5480 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5481 config: Config{
5482 MaxVersion: ver.version,
5483 NextProtos: []string{"foo", "bar", "baz"},
5484 Bugs: ProtocolBugs{
5485 NegotiateALPNAndNPN: true,
5486 SwapNPNAndALPN: true,
5487 },
5488 },
5489 flags: []string{
5490 "-advertise-alpn", "\x03foo",
5491 "-select-next-proto", "foo",
5492 },
5493 shouldFail: true,
5494 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5495 })
David Benjamin97d17d92016-07-14 16:12:00 -04005496 }
5497
5498 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005499
5500 // Resume with a corrupt ticket.
5501 testCases = append(testCases, testCase{
5502 testType: serverTest,
5503 name: "CorruptTicket-" + ver.name,
5504 config: Config{
5505 MaxVersion: ver.version,
5506 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005507 FilterTicket: func(in []byte) ([]byte, error) {
5508 in[len(in)-1] ^= 1
5509 return in, nil
5510 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005511 },
5512 },
5513 resumeSession: true,
5514 expectResumeRejected: true,
5515 })
5516 // Test the ticket callback, with and without renewal.
5517 testCases = append(testCases, testCase{
5518 testType: serverTest,
5519 name: "TicketCallback-" + ver.name,
5520 config: Config{
5521 MaxVersion: ver.version,
5522 },
5523 resumeSession: true,
5524 flags: []string{"-use-ticket-callback"},
5525 })
5526 testCases = append(testCases, testCase{
5527 testType: serverTest,
5528 name: "TicketCallback-Renew-" + ver.name,
5529 config: Config{
5530 MaxVersion: ver.version,
5531 Bugs: ProtocolBugs{
5532 ExpectNewTicket: true,
5533 },
5534 },
5535 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5536 resumeSession: true,
5537 })
5538
5539 // Test that the ticket callback is only called once when everything before
5540 // it in the ClientHello is asynchronous. This corrupts the ticket so
5541 // certificate selection callbacks run.
5542 testCases = append(testCases, testCase{
5543 testType: serverTest,
5544 name: "TicketCallback-SingleCall-" + ver.name,
5545 config: Config{
5546 MaxVersion: ver.version,
5547 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005548 FilterTicket: func(in []byte) ([]byte, error) {
5549 in[len(in)-1] ^= 1
5550 return in, nil
5551 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005552 },
5553 },
5554 resumeSession: true,
5555 expectResumeRejected: true,
5556 flags: []string{
5557 "-use-ticket-callback",
5558 "-async",
5559 },
5560 })
5561
David Benjamind4c349b2017-02-09 14:07:17 -05005562 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005563 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005564 testCases = append(testCases, testCase{
5565 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005566 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005567 config: Config{
5568 MaxVersion: ver.version,
5569 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005570 EmptyTicketSessionID: true,
5571 },
5572 },
5573 resumeSession: true,
5574 })
5575 testCases = append(testCases, testCase{
5576 testType: serverTest,
5577 name: "TicketSessionIDLength-16-" + ver.name,
5578 config: Config{
5579 MaxVersion: ver.version,
5580 Bugs: ProtocolBugs{
5581 TicketSessionIDLength: 16,
5582 },
5583 },
5584 resumeSession: true,
5585 })
5586 testCases = append(testCases, testCase{
5587 testType: serverTest,
5588 name: "TicketSessionIDLength-32-" + ver.name,
5589 config: Config{
5590 MaxVersion: ver.version,
5591 Bugs: ProtocolBugs{
5592 TicketSessionIDLength: 32,
5593 },
5594 },
5595 resumeSession: true,
5596 })
5597 testCases = append(testCases, testCase{
5598 testType: serverTest,
5599 name: "TicketSessionIDLength-33-" + ver.name,
5600 config: Config{
5601 MaxVersion: ver.version,
5602 Bugs: ProtocolBugs{
5603 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005604 },
5605 },
5606 resumeSession: true,
5607 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005608 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005609 expectedError: ":DECODE_ERROR:",
5610 })
5611 }
5612
5613 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5614 // are ignored.
5615 if ver.hasDTLS {
5616 testCases = append(testCases, testCase{
5617 protocol: dtls,
5618 name: "SRTP-Client-" + ver.name,
5619 config: Config{
5620 MaxVersion: ver.version,
5621 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5622 },
5623 flags: []string{
5624 "-srtp-profiles",
5625 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5626 },
5627 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5628 })
5629 testCases = append(testCases, testCase{
5630 protocol: dtls,
5631 testType: serverTest,
5632 name: "SRTP-Server-" + ver.name,
5633 config: Config{
5634 MaxVersion: ver.version,
5635 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5636 },
5637 flags: []string{
5638 "-srtp-profiles",
5639 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5640 },
5641 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5642 })
5643 // Test that the MKI is ignored.
5644 testCases = append(testCases, testCase{
5645 protocol: dtls,
5646 testType: serverTest,
5647 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5648 config: Config{
5649 MaxVersion: ver.version,
5650 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5651 Bugs: ProtocolBugs{
5652 SRTPMasterKeyIdentifer: "bogus",
5653 },
5654 },
5655 flags: []string{
5656 "-srtp-profiles",
5657 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5658 },
5659 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5660 })
5661 // Test that SRTP isn't negotiated on the server if there were
5662 // no matching profiles.
5663 testCases = append(testCases, testCase{
5664 protocol: dtls,
5665 testType: serverTest,
5666 name: "SRTP-Server-NoMatch-" + ver.name,
5667 config: Config{
5668 MaxVersion: ver.version,
5669 SRTPProtectionProfiles: []uint16{100, 101, 102},
5670 },
5671 flags: []string{
5672 "-srtp-profiles",
5673 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5674 },
5675 expectedSRTPProtectionProfile: 0,
5676 })
5677 // Test that the server returning an invalid SRTP profile is
5678 // flagged as an error by the client.
5679 testCases = append(testCases, testCase{
5680 protocol: dtls,
5681 name: "SRTP-Client-NoMatch-" + ver.name,
5682 config: Config{
5683 MaxVersion: ver.version,
5684 Bugs: ProtocolBugs{
5685 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5686 },
5687 },
5688 flags: []string{
5689 "-srtp-profiles",
5690 "SRTP_AES128_CM_SHA1_80",
5691 },
5692 shouldFail: true,
5693 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5694 })
5695 }
5696
5697 // Test SCT list.
5698 testCases = append(testCases, testCase{
5699 name: "SignedCertificateTimestampList-Client-" + ver.name,
5700 testType: clientTest,
5701 config: Config{
5702 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005703 },
David Benjamin97d17d92016-07-14 16:12:00 -04005704 flags: []string{
5705 "-enable-signed-cert-timestamps",
5706 "-expect-signed-cert-timestamps",
5707 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005708 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005709 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005710 })
David Benjamindaa88502016-10-04 16:32:16 -04005711
Adam Langleycfa08c32016-11-17 13:21:27 -08005712 var differentSCTList []byte
5713 differentSCTList = append(differentSCTList, testSCTList...)
5714 differentSCTList[len(differentSCTList)-1] ^= 1
5715
David Benjamindaa88502016-10-04 16:32:16 -04005716 // The SCT extension did not specify that it must only be sent on resumption as it
5717 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005718 testCases = append(testCases, testCase{
5719 name: "SendSCTListOnResume-" + ver.name,
5720 config: Config{
5721 MaxVersion: ver.version,
5722 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005723 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005724 },
David Benjamind98452d2015-06-16 14:16:23 -04005725 },
David Benjamin97d17d92016-07-14 16:12:00 -04005726 flags: []string{
5727 "-enable-signed-cert-timestamps",
5728 "-expect-signed-cert-timestamps",
5729 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005730 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005731 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005732 })
David Benjamindaa88502016-10-04 16:32:16 -04005733
David Benjamin97d17d92016-07-14 16:12:00 -04005734 testCases = append(testCases, testCase{
5735 name: "SignedCertificateTimestampList-Server-" + ver.name,
5736 testType: serverTest,
5737 config: Config{
5738 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005739 },
David Benjamin97d17d92016-07-14 16:12:00 -04005740 flags: []string{
5741 "-signed-cert-timestamps",
5742 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005743 },
David Benjamin97d17d92016-07-14 16:12:00 -04005744 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005745 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005746 })
David Benjamin53210cb2016-11-16 09:01:48 +09005747
Adam Langleycfa08c32016-11-17 13:21:27 -08005748 emptySCTListCert := *testCerts[0].cert
5749 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5750
5751 // Test empty SCT list.
5752 testCases = append(testCases, testCase{
5753 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5754 testType: clientTest,
5755 config: Config{
5756 MaxVersion: ver.version,
5757 Certificates: []Certificate{emptySCTListCert},
5758 },
5759 flags: []string{
5760 "-enable-signed-cert-timestamps",
5761 },
5762 shouldFail: true,
5763 expectedError: ":ERROR_PARSING_EXTENSION:",
5764 })
5765
5766 emptySCTCert := *testCerts[0].cert
5767 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5768
5769 // Test empty SCT in non-empty list.
5770 testCases = append(testCases, testCase{
5771 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5772 testType: clientTest,
5773 config: Config{
5774 MaxVersion: ver.version,
5775 Certificates: []Certificate{emptySCTCert},
5776 },
5777 flags: []string{
5778 "-enable-signed-cert-timestamps",
5779 },
5780 shouldFail: true,
5781 expectedError: ":ERROR_PARSING_EXTENSION:",
5782 })
5783
David Benjamin53210cb2016-11-16 09:01:48 +09005784 // Test that certificate-related extensions are not sent unsolicited.
5785 testCases = append(testCases, testCase{
5786 testType: serverTest,
5787 name: "UnsolicitedCertificateExtensions-" + ver.name,
5788 config: Config{
5789 MaxVersion: ver.version,
5790 Bugs: ProtocolBugs{
5791 NoOCSPStapling: true,
5792 NoSignedCertificateTimestamps: true,
5793 },
5794 },
5795 flags: []string{
5796 "-ocsp-response",
5797 base64.StdEncoding.EncodeToString(testOCSPResponse),
5798 "-signed-cert-timestamps",
5799 base64.StdEncoding.EncodeToString(testSCTList),
5800 },
5801 })
David Benjamin97d17d92016-07-14 16:12:00 -04005802 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005803
Paul Lietar4fac72e2015-09-09 13:44:55 +01005804 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005805 testType: clientTest,
5806 name: "ClientHelloPadding",
5807 config: Config{
5808 Bugs: ProtocolBugs{
5809 RequireClientHelloSize: 512,
5810 },
5811 },
5812 // This hostname just needs to be long enough to push the
5813 // ClientHello into F5's danger zone between 256 and 511 bytes
5814 // long.
5815 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5816 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005817
5818 // Extensions should not function in SSL 3.0.
5819 testCases = append(testCases, testCase{
5820 testType: serverTest,
5821 name: "SSLv3Extensions-NoALPN",
5822 config: Config{
5823 MaxVersion: VersionSSL30,
5824 NextProtos: []string{"foo", "bar", "baz"},
5825 },
5826 flags: []string{
5827 "-select-alpn", "foo",
5828 },
5829 expectNoNextProto: true,
5830 })
5831
5832 // Test session tickets separately as they follow a different codepath.
5833 testCases = append(testCases, testCase{
5834 testType: serverTest,
5835 name: "SSLv3Extensions-NoTickets",
5836 config: Config{
5837 MaxVersion: VersionSSL30,
5838 Bugs: ProtocolBugs{
5839 // Historically, session tickets in SSL 3.0
5840 // failed in different ways depending on whether
5841 // the client supported renegotiation_info.
5842 NoRenegotiationInfo: true,
5843 },
5844 },
5845 resumeSession: true,
5846 })
5847 testCases = append(testCases, testCase{
5848 testType: serverTest,
5849 name: "SSLv3Extensions-NoTickets2",
5850 config: Config{
5851 MaxVersion: VersionSSL30,
5852 },
5853 resumeSession: true,
5854 })
5855
5856 // But SSL 3.0 does send and process renegotiation_info.
5857 testCases = append(testCases, testCase{
5858 testType: serverTest,
5859 name: "SSLv3Extensions-RenegotiationInfo",
5860 config: Config{
5861 MaxVersion: VersionSSL30,
5862 Bugs: ProtocolBugs{
5863 RequireRenegotiationInfo: true,
5864 },
5865 },
David Benjamind2610042017-01-03 10:49:28 -05005866 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005867 })
5868 testCases = append(testCases, testCase{
5869 testType: serverTest,
5870 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5871 config: Config{
5872 MaxVersion: VersionSSL30,
5873 Bugs: ProtocolBugs{
5874 NoRenegotiationInfo: true,
5875 SendRenegotiationSCSV: true,
5876 RequireRenegotiationInfo: true,
5877 },
5878 },
David Benjamind2610042017-01-03 10:49:28 -05005879 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005880 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005881
5882 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5883 // in ServerHello.
5884 testCases = append(testCases, testCase{
5885 name: "NPN-Forbidden-TLS13",
5886 config: Config{
5887 MaxVersion: VersionTLS13,
5888 NextProtos: []string{"foo"},
5889 Bugs: ProtocolBugs{
5890 NegotiateNPNAtAllVersions: true,
5891 },
5892 },
5893 flags: []string{"-select-next-proto", "foo"},
5894 shouldFail: true,
5895 expectedError: ":ERROR_PARSING_EXTENSION:",
5896 })
5897 testCases = append(testCases, testCase{
5898 name: "EMS-Forbidden-TLS13",
5899 config: Config{
5900 MaxVersion: VersionTLS13,
5901 Bugs: ProtocolBugs{
5902 NegotiateEMSAtAllVersions: true,
5903 },
5904 },
5905 shouldFail: true,
5906 expectedError: ":ERROR_PARSING_EXTENSION:",
5907 })
5908 testCases = append(testCases, testCase{
5909 name: "RenegotiationInfo-Forbidden-TLS13",
5910 config: Config{
5911 MaxVersion: VersionTLS13,
5912 Bugs: ProtocolBugs{
5913 NegotiateRenegotiationInfoAtAllVersions: true,
5914 },
5915 },
5916 shouldFail: true,
5917 expectedError: ":ERROR_PARSING_EXTENSION:",
5918 })
5919 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005920 name: "Ticket-Forbidden-TLS13",
5921 config: Config{
5922 MaxVersion: VersionTLS12,
5923 },
5924 resumeConfig: &Config{
5925 MaxVersion: VersionTLS13,
5926 Bugs: ProtocolBugs{
5927 AdvertiseTicketExtension: true,
5928 },
5929 },
5930 resumeSession: true,
5931 shouldFail: true,
5932 expectedError: ":ERROR_PARSING_EXTENSION:",
5933 })
5934
5935 // Test that illegal extensions in TLS 1.3 are declined by the server if
5936 // offered in ClientHello. The runner's server will fail if this occurs,
5937 // so we exercise the offering path. (EMS and Renegotiation Info are
5938 // implicit in every test.)
5939 testCases = append(testCases, testCase{
5940 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005941 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005942 config: Config{
5943 MaxVersion: VersionTLS13,
5944 NextProtos: []string{"bar"},
5945 },
5946 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5947 })
David Benjamin196df5b2016-09-21 16:23:27 -04005948
David Benjamindaa88502016-10-04 16:32:16 -04005949 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5950 // tolerated.
5951 testCases = append(testCases, testCase{
5952 name: "SendOCSPResponseOnResume-TLS12",
5953 config: Config{
5954 MaxVersion: VersionTLS12,
5955 Bugs: ProtocolBugs{
5956 SendOCSPResponseOnResume: []byte("bogus"),
5957 },
5958 },
5959 flags: []string{
5960 "-enable-ocsp-stapling",
5961 "-expect-ocsp-response",
5962 base64.StdEncoding.EncodeToString(testOCSPResponse),
5963 },
5964 resumeSession: true,
5965 })
5966
David Benjamindaa88502016-10-04 16:32:16 -04005967 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005968 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005969 config: Config{
5970 MaxVersion: VersionTLS13,
5971 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005972 SendExtensionOnCertificate: testOCSPExtension,
5973 },
5974 },
5975 shouldFail: true,
5976 expectedError: ":UNEXPECTED_EXTENSION:",
5977 })
5978
5979 testCases = append(testCases, testCase{
5980 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5981 config: Config{
5982 MaxVersion: VersionTLS13,
5983 Bugs: ProtocolBugs{
5984 SendExtensionOnCertificate: testSCTExtension,
5985 },
5986 },
5987 shouldFail: true,
5988 expectedError: ":UNEXPECTED_EXTENSION:",
5989 })
5990
5991 // Test that extensions on client certificates are never accepted.
5992 testCases = append(testCases, testCase{
5993 name: "SendExtensionOnClientCertificate-TLS13",
5994 testType: serverTest,
5995 config: Config{
5996 MaxVersion: VersionTLS13,
5997 Certificates: []Certificate{rsaCertificate},
5998 Bugs: ProtocolBugs{
5999 SendExtensionOnCertificate: testOCSPExtension,
6000 },
6001 },
6002 flags: []string{
6003 "-enable-ocsp-stapling",
6004 "-require-any-client-certificate",
6005 },
6006 shouldFail: true,
6007 expectedError: ":UNEXPECTED_EXTENSION:",
6008 })
6009
6010 testCases = append(testCases, testCase{
6011 name: "SendUnknownExtensionOnCertificate-TLS13",
6012 config: Config{
6013 MaxVersion: VersionTLS13,
6014 Bugs: ProtocolBugs{
6015 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
6016 },
6017 },
6018 shouldFail: true,
6019 expectedError: ":UNEXPECTED_EXTENSION:",
6020 })
6021
Adam Langleycfa08c32016-11-17 13:21:27 -08006022 var differentSCTList []byte
6023 differentSCTList = append(differentSCTList, testSCTList...)
6024 differentSCTList[len(differentSCTList)-1] ^= 1
6025
Steven Valdeza833c352016-11-01 13:39:36 -04006026 // Test that extensions on intermediates are allowed but ignored.
6027 testCases = append(testCases, testCase{
6028 name: "IgnoreExtensionsOnIntermediates-TLS13",
6029 config: Config{
6030 MaxVersion: VersionTLS13,
6031 Certificates: []Certificate{rsaChainCertificate},
6032 Bugs: ProtocolBugs{
6033 // Send different values on the intermediate. This tests
6034 // the intermediate's extensions do not override the
6035 // leaf's.
6036 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08006037 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04006038 },
6039 },
6040 flags: []string{
6041 "-enable-ocsp-stapling",
6042 "-expect-ocsp-response",
6043 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04006044 "-enable-signed-cert-timestamps",
6045 "-expect-signed-cert-timestamps",
6046 base64.StdEncoding.EncodeToString(testSCTList),
6047 },
6048 resumeSession: true,
6049 })
6050
6051 // Test that extensions are not sent on intermediates when configured
6052 // only for a leaf.
6053 testCases = append(testCases, testCase{
6054 testType: serverTest,
6055 name: "SendNoExtensionsOnIntermediate-TLS13",
6056 config: Config{
6057 MaxVersion: VersionTLS13,
6058 Bugs: ProtocolBugs{
6059 ExpectNoExtensionsOnIntermediate: true,
6060 },
6061 },
6062 flags: []string{
6063 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
6064 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
6065 "-ocsp-response",
6066 base64.StdEncoding.EncodeToString(testOCSPResponse),
6067 "-signed-cert-timestamps",
6068 base64.StdEncoding.EncodeToString(testSCTList),
6069 },
6070 })
6071
6072 // Test that extensions are not sent on client certificates.
6073 testCases = append(testCases, testCase{
6074 name: "SendNoClientCertificateExtensions-TLS13",
6075 config: Config{
6076 MaxVersion: VersionTLS13,
6077 ClientAuth: RequireAnyClientCert,
6078 },
6079 flags: []string{
6080 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6081 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6082 "-ocsp-response",
6083 base64.StdEncoding.EncodeToString(testOCSPResponse),
6084 "-signed-cert-timestamps",
6085 base64.StdEncoding.EncodeToString(testSCTList),
6086 },
6087 })
6088
6089 testCases = append(testCases, testCase{
6090 name: "SendDuplicateExtensionsOnCerts-TLS13",
6091 config: Config{
6092 MaxVersion: VersionTLS13,
6093 Bugs: ProtocolBugs{
6094 SendDuplicateCertExtensions: true,
6095 },
6096 },
6097 flags: []string{
6098 "-enable-ocsp-stapling",
6099 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04006100 },
6101 resumeSession: true,
6102 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04006103 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04006104 })
Adam Langley9b885c52016-11-18 14:21:03 -08006105
6106 testCases = append(testCases, testCase{
6107 name: "SignedCertificateTimestampListInvalid-Server",
6108 testType: serverTest,
6109 flags: []string{
6110 "-signed-cert-timestamps",
6111 base64.StdEncoding.EncodeToString([]byte{0, 0}),
6112 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05006113 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08006114 expectedError: ":INVALID_SCT_LIST:",
6115 })
David Benjamine78bfde2014-09-06 12:45:15 -04006116}
6117
David Benjamin01fe8202014-09-24 15:21:44 -04006118func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04006119 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04006120 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04006121 // SSL 3.0 does not have tickets and TLS 1.3 does not
6122 // have session IDs, so skip their cross-resumption
6123 // tests.
6124 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
6125 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
6126 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07006127 }
6128
David Benjamin8b8c0062014-11-23 02:47:52 -05006129 protocols := []protocol{tls}
6130 if sessionVers.hasDTLS && resumeVers.hasDTLS {
6131 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05006132 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006133 for _, protocol := range protocols {
6134 suffix := "-" + sessionVers.name + "-" + resumeVers.name
6135 if protocol == dtls {
6136 suffix += "-DTLS"
6137 }
6138
David Benjaminece3de92015-03-16 18:02:20 -04006139 if sessionVers.version == resumeVers.version {
6140 testCases = append(testCases, testCase{
6141 protocol: protocol,
6142 name: "Resume-Client" + suffix,
6143 resumeSession: true,
6144 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006145 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006146 Bugs: ProtocolBugs{
6147 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
6148 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
6149 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006150 },
David Benjaminece3de92015-03-16 18:02:20 -04006151 expectedVersion: sessionVers.version,
6152 expectedResumeVersion: resumeVers.version,
6153 })
6154 } else {
David Benjamin405da482016-08-08 17:25:07 -04006155 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
6156
6157 // Offering a TLS 1.3 session sends an empty session ID, so
6158 // there is no way to convince a non-lookahead client the
6159 // session was resumed. It will appear to the client that a
6160 // stray ChangeCipherSpec was sent.
6161 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
6162 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04006163 }
6164
David Benjaminece3de92015-03-16 18:02:20 -04006165 testCases = append(testCases, testCase{
6166 protocol: protocol,
6167 name: "Resume-Client-Mismatch" + suffix,
6168 resumeSession: true,
6169 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006170 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006171 },
David Benjaminece3de92015-03-16 18:02:20 -04006172 expectedVersion: sessionVers.version,
6173 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006174 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04006175 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04006176 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04006177 },
6178 },
6179 expectedResumeVersion: resumeVers.version,
6180 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006181 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04006182 })
6183 }
David Benjamin8b8c0062014-11-23 02:47:52 -05006184
6185 testCases = append(testCases, testCase{
6186 protocol: protocol,
6187 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006188 resumeSession: true,
6189 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006190 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006191 },
6192 expectedVersion: sessionVers.version,
6193 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006194 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006195 },
6196 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006197 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05006198 expectedResumeVersion: resumeVers.version,
6199 })
6200
David Benjamin8b8c0062014-11-23 02:47:52 -05006201 testCases = append(testCases, testCase{
6202 protocol: protocol,
6203 testType: serverTest,
6204 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05006205 resumeSession: true,
6206 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006207 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006208 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07006209 expectedVersion: sessionVers.version,
6210 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05006211 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006212 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04006213 Bugs: ProtocolBugs{
6214 SendBothTickets: true,
6215 },
David Benjamin8b8c0062014-11-23 02:47:52 -05006216 },
6217 expectedResumeVersion: resumeVers.version,
6218 })
6219 }
David Benjamin01fe8202014-09-24 15:21:44 -04006220 }
6221 }
David Benjaminece3de92015-03-16 18:02:20 -04006222
David Benjamin4199b0d2016-11-01 13:58:25 -04006223 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006224 testCases = append(testCases, testCase{
6225 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006226 name: "ShimTicketRewritable",
6227 resumeSession: true,
6228 config: Config{
6229 MaxVersion: VersionTLS12,
6230 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6231 Bugs: ProtocolBugs{
6232 FilterTicket: func(in []byte) ([]byte, error) {
6233 in, err := SetShimTicketVersion(in, VersionTLS12)
6234 if err != nil {
6235 return nil, err
6236 }
6237 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6238 },
6239 },
6240 },
6241 flags: []string{
6242 "-ticket-key",
6243 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6244 },
6245 })
6246
6247 // Resumptions are declined if the version does not match.
6248 testCases = append(testCases, testCase{
6249 testType: serverTest,
6250 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006251 resumeSession: true,
6252 config: Config{
6253 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04006254 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006255 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006256 FilterTicket: func(in []byte) ([]byte, error) {
6257 return SetShimTicketVersion(in, VersionTLS13)
6258 },
6259 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006260 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006261 flags: []string{
6262 "-ticket-key",
6263 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6264 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006265 expectResumeRejected: true,
6266 })
6267
6268 testCases = append(testCases, testCase{
6269 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04006270 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006271 resumeSession: true,
6272 config: Config{
6273 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04006274 Bugs: ProtocolBugs{
6275 FilterTicket: func(in []byte) ([]byte, error) {
6276 return SetShimTicketVersion(in, VersionTLS12)
6277 },
6278 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006279 },
David Benjamin4199b0d2016-11-01 13:58:25 -04006280 flags: []string{
6281 "-ticket-key",
6282 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6283 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04006284 expectResumeRejected: true,
6285 })
6286
David Benjamin4199b0d2016-11-01 13:58:25 -04006287 // Resumptions are declined if the cipher is invalid or disabled.
6288 testCases = append(testCases, testCase{
6289 testType: serverTest,
6290 name: "Resume-Server-DeclineBadCipher",
6291 resumeSession: true,
6292 config: Config{
6293 MaxVersion: VersionTLS12,
6294 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006295 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006296 FilterTicket: func(in []byte) ([]byte, error) {
6297 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6298 },
6299 },
6300 },
6301 flags: []string{
6302 "-ticket-key",
6303 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6304 },
6305 expectResumeRejected: true,
6306 })
6307
6308 testCases = append(testCases, testCase{
6309 testType: serverTest,
6310 name: "Resume-Server-DeclineBadCipher-2",
6311 resumeSession: true,
6312 config: Config{
6313 MaxVersion: VersionTLS12,
6314 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09006315 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04006316 FilterTicket: func(in []byte) ([]byte, error) {
6317 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
6318 },
6319 },
6320 },
6321 flags: []string{
6322 "-cipher", "AES128",
6323 "-ticket-key",
6324 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6325 },
6326 expectResumeRejected: true,
6327 })
6328
David Benjaminf01f42a2016-11-16 19:05:33 +09006329 // Sessions are not resumed if they do not use the preferred cipher.
6330 testCases = append(testCases, testCase{
6331 testType: serverTest,
6332 name: "Resume-Server-CipherNotPreferred",
6333 resumeSession: true,
6334 config: Config{
6335 MaxVersion: VersionTLS12,
6336 Bugs: ProtocolBugs{
6337 ExpectNewTicket: true,
6338 FilterTicket: func(in []byte) ([]byte, error) {
6339 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
6340 },
6341 },
6342 },
6343 flags: []string{
6344 "-ticket-key",
6345 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6346 },
6347 shouldFail: false,
6348 expectResumeRejected: true,
6349 })
6350
6351 // TLS 1.3 allows sessions to be resumed at a different cipher if their
6352 // PRF hashes match, but BoringSSL will always decline such resumptions.
6353 testCases = append(testCases, testCase{
6354 testType: serverTest,
6355 name: "Resume-Server-CipherNotPreferred-TLS13",
6356 resumeSession: true,
6357 config: Config{
6358 MaxVersion: VersionTLS13,
6359 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
6360 Bugs: ProtocolBugs{
6361 FilterTicket: func(in []byte) ([]byte, error) {
6362 // If the client (runner) offers ChaCha20-Poly1305 first, the
6363 // server (shim) always prefers it. Switch it to AES-GCM.
6364 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
6365 },
6366 },
6367 },
6368 flags: []string{
6369 "-ticket-key",
6370 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6371 },
6372 shouldFail: false,
6373 expectResumeRejected: true,
6374 })
6375
6376 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04006377 testCases = append(testCases, testCase{
6378 testType: serverTest,
6379 name: "Resume-Server-DeclineBadCipher-TLS13",
6380 resumeSession: true,
6381 config: Config{
6382 MaxVersion: VersionTLS13,
6383 Bugs: ProtocolBugs{
6384 FilterTicket: func(in []byte) ([]byte, error) {
6385 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
6386 },
6387 },
6388 },
6389 flags: []string{
6390 "-ticket-key",
6391 base64.StdEncoding.EncodeToString(TestShimTicketKey),
6392 },
6393 expectResumeRejected: true,
6394 })
6395
David Benjaminf01f42a2016-11-16 19:05:33 +09006396 // If the client does not offer the cipher from the session, decline to
6397 // resume. Clients are forbidden from doing this, but BoringSSL selects
6398 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09006399 testCases = append(testCases, testCase{
6400 testType: serverTest,
6401 name: "Resume-Server-UnofferedCipher",
6402 resumeSession: true,
6403 config: Config{
6404 MaxVersion: VersionTLS12,
6405 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6406 },
6407 resumeConfig: &Config{
6408 MaxVersion: VersionTLS12,
6409 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
6410 Bugs: ProtocolBugs{
6411 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6412 },
6413 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006414 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006415 })
6416
David Benjaminf01f42a2016-11-16 19:05:33 +09006417 // In TLS 1.3, clients may advertise a cipher list which does not
6418 // include the selected cipher. Test that we tolerate this. Servers may
Steven Valdez2d850622017-01-11 11:34:52 -05006419 // resume at another cipher if the PRF matches and are not doing 0-RTT, but
6420 // BoringSSL will always decline.
David Benjamin75f99142016-11-12 12:36:06 +09006421 testCases = append(testCases, testCase{
6422 testType: serverTest,
6423 name: "Resume-Server-UnofferedCipher-TLS13",
6424 resumeSession: true,
6425 config: Config{
6426 MaxVersion: VersionTLS13,
6427 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6428 },
6429 resumeConfig: &Config{
6430 MaxVersion: VersionTLS13,
6431 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6432 Bugs: ProtocolBugs{
6433 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6434 },
6435 },
David Benjaminf01f42a2016-11-16 19:05:33 +09006436 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09006437 })
6438
David Benjamin4199b0d2016-11-01 13:58:25 -04006439 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04006440 testCases = append(testCases, testCase{
6441 name: "Resume-Client-CipherMismatch",
6442 resumeSession: true,
6443 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006444 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006445 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6446 },
6447 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006448 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006449 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6450 Bugs: ProtocolBugs{
6451 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6452 },
6453 },
6454 shouldFail: true,
6455 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6456 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006457
David Benjamine1cc35e2016-11-16 16:25:58 +09006458 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6459 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006460 testCases = append(testCases, testCase{
6461 name: "Resume-Client-CipherMismatch-TLS13",
6462 resumeSession: true,
6463 config: Config{
6464 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006465 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006466 },
6467 resumeConfig: &Config{
6468 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006469 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6470 },
6471 })
6472
6473 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6474 testCases = append(testCases, testCase{
6475 name: "Resume-Client-PRFMismatch-TLS13",
6476 resumeSession: true,
6477 config: Config{
6478 MaxVersion: VersionTLS13,
6479 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6480 },
6481 resumeConfig: &Config{
6482 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006483 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006484 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006485 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006486 },
6487 },
6488 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006489 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006490 })
Steven Valdeza833c352016-11-01 13:39:36 -04006491
6492 testCases = append(testCases, testCase{
6493 testType: serverTest,
6494 name: "Resume-Server-BinderWrongLength",
6495 resumeSession: true,
6496 config: Config{
6497 MaxVersion: VersionTLS13,
6498 Bugs: ProtocolBugs{
6499 SendShortPSKBinder: true,
6500 },
6501 },
6502 shouldFail: true,
6503 expectedLocalError: "remote error: error decrypting message",
6504 expectedError: ":DIGEST_CHECK_FAILED:",
6505 })
6506
6507 testCases = append(testCases, testCase{
6508 testType: serverTest,
6509 name: "Resume-Server-NoPSKBinder",
6510 resumeSession: true,
6511 config: Config{
6512 MaxVersion: VersionTLS13,
6513 Bugs: ProtocolBugs{
6514 SendNoPSKBinder: true,
6515 },
6516 },
6517 shouldFail: true,
6518 expectedLocalError: "remote error: error decoding message",
6519 expectedError: ":DECODE_ERROR:",
6520 })
6521
6522 testCases = append(testCases, testCase{
6523 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006524 name: "Resume-Server-ExtraPSKBinder",
6525 resumeSession: true,
6526 config: Config{
6527 MaxVersion: VersionTLS13,
6528 Bugs: ProtocolBugs{
6529 SendExtraPSKBinder: true,
6530 },
6531 },
6532 shouldFail: true,
6533 expectedLocalError: "remote error: illegal parameter",
6534 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6535 })
6536
6537 testCases = append(testCases, testCase{
6538 testType: serverTest,
6539 name: "Resume-Server-ExtraIdentityNoBinder",
6540 resumeSession: true,
6541 config: Config{
6542 MaxVersion: VersionTLS13,
6543 Bugs: ProtocolBugs{
6544 ExtraPSKIdentity: true,
6545 },
6546 },
6547 shouldFail: true,
6548 expectedLocalError: "remote error: illegal parameter",
6549 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6550 })
6551
6552 testCases = append(testCases, testCase{
6553 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006554 name: "Resume-Server-InvalidPSKBinder",
6555 resumeSession: true,
6556 config: Config{
6557 MaxVersion: VersionTLS13,
6558 Bugs: ProtocolBugs{
6559 SendInvalidPSKBinder: true,
6560 },
6561 },
6562 shouldFail: true,
6563 expectedLocalError: "remote error: error decrypting message",
6564 expectedError: ":DIGEST_CHECK_FAILED:",
6565 })
6566
6567 testCases = append(testCases, testCase{
6568 testType: serverTest,
6569 name: "Resume-Server-PSKBinderFirstExtension",
6570 resumeSession: true,
6571 config: Config{
6572 MaxVersion: VersionTLS13,
6573 Bugs: ProtocolBugs{
6574 PSKBinderFirst: true,
6575 },
6576 },
6577 shouldFail: true,
6578 expectedLocalError: "remote error: illegal parameter",
6579 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6580 })
David Benjamin01fe8202014-09-24 15:21:44 -04006581}
6582
Adam Langley2ae77d22014-10-28 17:29:33 -07006583func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006584 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006585 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006586 testType: serverTest,
6587 name: "Renegotiate-Server-Forbidden",
6588 config: Config{
6589 MaxVersion: VersionTLS12,
6590 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006591 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006592 shouldFail: true,
6593 expectedError: ":NO_RENEGOTIATION:",
6594 expectedLocalError: "remote error: no renegotiation",
6595 })
Adam Langley5021b222015-06-12 18:27:58 -07006596 // The server shouldn't echo the renegotiation extension unless
6597 // requested by the client.
6598 testCases = append(testCases, testCase{
6599 testType: serverTest,
6600 name: "Renegotiate-Server-NoExt",
6601 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006602 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006603 Bugs: ProtocolBugs{
6604 NoRenegotiationInfo: true,
6605 RequireRenegotiationInfo: true,
6606 },
6607 },
6608 shouldFail: true,
6609 expectedLocalError: "renegotiation extension missing",
6610 })
6611 // The renegotiation SCSV should be sufficient for the server to echo
6612 // the extension.
6613 testCases = append(testCases, testCase{
6614 testType: serverTest,
6615 name: "Renegotiate-Server-NoExt-SCSV",
6616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006617 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006618 Bugs: ProtocolBugs{
6619 NoRenegotiationInfo: true,
6620 SendRenegotiationSCSV: true,
6621 RequireRenegotiationInfo: true,
6622 },
6623 },
6624 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006625 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006626 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006627 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006628 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006629 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006630 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006631 },
6632 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006633 renegotiate: 1,
6634 flags: []string{
6635 "-renegotiate-freely",
6636 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006637 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006638 },
David Benjamincdea40c2015-03-19 14:09:43 -04006639 })
6640 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006641 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006642 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006644 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006645 Bugs: ProtocolBugs{
6646 EmptyRenegotiationInfo: true,
6647 },
6648 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006649 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006650 shouldFail: true,
6651 expectedError: ":RENEGOTIATION_MISMATCH:",
6652 })
6653 testCases = append(testCases, testCase{
6654 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006655 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006656 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006657 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006658 Bugs: ProtocolBugs{
6659 BadRenegotiationInfo: true,
6660 },
6661 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006662 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006663 shouldFail: true,
6664 expectedError: ":RENEGOTIATION_MISMATCH:",
6665 })
6666 testCases = append(testCases, testCase{
David Benjamin9343b0b2017-07-01 00:31:27 -04006667 name: "Renegotiate-Client-BadExt2",
6668 renegotiate: 1,
6669 config: Config{
6670 MaxVersion: VersionTLS12,
6671 Bugs: ProtocolBugs{
6672 BadRenegotiationInfoEnd: true,
6673 },
6674 },
6675 flags: []string{"-renegotiate-freely"},
6676 shouldFail: true,
6677 expectedError: ":RENEGOTIATION_MISMATCH:",
6678 })
6679 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006680 name: "Renegotiate-Client-Downgrade",
6681 renegotiate: 1,
6682 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006683 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006684 Bugs: ProtocolBugs{
6685 NoRenegotiationInfoAfterInitial: true,
6686 },
6687 },
6688 flags: []string{"-renegotiate-freely"},
6689 shouldFail: true,
6690 expectedError: ":RENEGOTIATION_MISMATCH:",
6691 })
6692 testCases = append(testCases, testCase{
6693 name: "Renegotiate-Client-Upgrade",
6694 renegotiate: 1,
6695 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006696 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006697 Bugs: ProtocolBugs{
6698 NoRenegotiationInfoInInitial: true,
6699 },
6700 },
6701 flags: []string{"-renegotiate-freely"},
6702 shouldFail: true,
6703 expectedError: ":RENEGOTIATION_MISMATCH:",
6704 })
6705 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006706 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006707 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006708 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006709 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006710 Bugs: ProtocolBugs{
6711 NoRenegotiationInfo: true,
6712 },
6713 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006714 flags: []string{
6715 "-renegotiate-freely",
6716 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006717 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006718 },
David Benjamincff0b902015-05-15 23:09:47 -04006719 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006720
6721 // Test that the server may switch ciphers on renegotiation without
6722 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006723 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006724 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006725 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006726 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006727 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006728 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006729 },
6730 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006731 flags: []string{
6732 "-renegotiate-freely",
6733 "-expect-total-renegotiations", "1",
6734 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006735 })
6736 testCases = append(testCases, testCase{
6737 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006738 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006739 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006740 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006741 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6742 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006743 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006744 flags: []string{
6745 "-renegotiate-freely",
6746 "-expect-total-renegotiations", "1",
6747 },
David Benjaminb16346b2015-04-08 19:16:58 -04006748 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006749
6750 // Test that the server may not switch versions on renegotiation.
6751 testCases = append(testCases, testCase{
6752 name: "Renegotiate-Client-SwitchVersion",
6753 config: Config{
6754 MaxVersion: VersionTLS12,
6755 // Pick a cipher which exists at both versions.
6756 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6757 Bugs: ProtocolBugs{
6758 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006759 // Avoid failing early at the record layer.
6760 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006761 },
6762 },
6763 renegotiate: 1,
6764 flags: []string{
6765 "-renegotiate-freely",
6766 "-expect-total-renegotiations", "1",
6767 },
6768 shouldFail: true,
6769 expectedError: ":WRONG_SSL_VERSION:",
6770 })
6771
David Benjaminb16346b2015-04-08 19:16:58 -04006772 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006773 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006774 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006775 config: Config{
6776 MaxVersion: VersionTLS10,
6777 Bugs: ProtocolBugs{
6778 RequireSameRenegoClientVersion: true,
6779 },
6780 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006781 flags: []string{
6782 "-renegotiate-freely",
6783 "-expect-total-renegotiations", "1",
6784 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006785 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006786 testCases = append(testCases, testCase{
6787 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006788 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006789 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006790 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006791 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6792 NextProtos: []string{"foo"},
6793 },
6794 flags: []string{
6795 "-false-start",
6796 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006797 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006798 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006799 },
6800 shimWritesFirst: true,
6801 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006802
6803 // Client-side renegotiation controls.
6804 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006805 name: "Renegotiate-Client-Forbidden-1",
6806 config: Config{
6807 MaxVersion: VersionTLS12,
6808 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006809 renegotiate: 1,
6810 shouldFail: true,
6811 expectedError: ":NO_RENEGOTIATION:",
6812 expectedLocalError: "remote error: no renegotiation",
6813 })
6814 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006815 name: "Renegotiate-Client-Once-1",
6816 config: Config{
6817 MaxVersion: VersionTLS12,
6818 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006819 renegotiate: 1,
6820 flags: []string{
6821 "-renegotiate-once",
6822 "-expect-total-renegotiations", "1",
6823 },
6824 })
6825 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006826 name: "Renegotiate-Client-Freely-1",
6827 config: Config{
6828 MaxVersion: VersionTLS12,
6829 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006830 renegotiate: 1,
6831 flags: []string{
6832 "-renegotiate-freely",
6833 "-expect-total-renegotiations", "1",
6834 },
6835 })
6836 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006837 name: "Renegotiate-Client-Once-2",
6838 config: Config{
6839 MaxVersion: VersionTLS12,
6840 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006841 renegotiate: 2,
6842 flags: []string{"-renegotiate-once"},
6843 shouldFail: true,
6844 expectedError: ":NO_RENEGOTIATION:",
6845 expectedLocalError: "remote error: no renegotiation",
6846 })
6847 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006848 name: "Renegotiate-Client-Freely-2",
6849 config: Config{
6850 MaxVersion: VersionTLS12,
6851 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006852 renegotiate: 2,
6853 flags: []string{
6854 "-renegotiate-freely",
6855 "-expect-total-renegotiations", "2",
6856 },
6857 })
Adam Langley27a0d082015-11-03 13:34:10 -08006858 testCases = append(testCases, testCase{
6859 name: "Renegotiate-Client-NoIgnore",
6860 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006861 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006862 Bugs: ProtocolBugs{
6863 SendHelloRequestBeforeEveryAppDataRecord: true,
6864 },
6865 },
6866 shouldFail: true,
6867 expectedError: ":NO_RENEGOTIATION:",
6868 })
6869 testCases = append(testCases, testCase{
6870 name: "Renegotiate-Client-Ignore",
6871 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006872 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006873 Bugs: ProtocolBugs{
6874 SendHelloRequestBeforeEveryAppDataRecord: true,
6875 },
6876 },
6877 flags: []string{
6878 "-renegotiate-ignore",
6879 "-expect-total-renegotiations", "0",
6880 },
6881 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006882
David Benjamin34941c02016-10-08 11:45:31 -04006883 // Renegotiation is not allowed at SSL 3.0.
6884 testCases = append(testCases, testCase{
6885 name: "Renegotiate-Client-SSL3",
6886 config: Config{
6887 MaxVersion: VersionSSL30,
6888 },
6889 renegotiate: 1,
6890 flags: []string{
6891 "-renegotiate-freely",
6892 "-expect-total-renegotiations", "1",
6893 },
6894 shouldFail: true,
6895 expectedError: ":NO_RENEGOTIATION:",
6896 expectedLocalError: "remote error: no renegotiation",
6897 })
6898
David Benjamina1eaba12017-01-01 23:19:22 -05006899 // Renegotiation is not allowed when there is an unfinished write.
6900 testCases = append(testCases, testCase{
6901 name: "Renegotiate-Client-UnfinishedWrite",
6902 config: Config{
6903 MaxVersion: VersionTLS12,
6904 },
David Benjaminbbba9392017-04-06 12:54:12 -04006905 renegotiate: 1,
6906 readWithUnfinishedWrite: true,
David Benjamina1eaba12017-01-01 23:19:22 -05006907 flags: []string{
6908 "-async",
6909 "-renegotiate-freely",
David Benjamina1eaba12017-01-01 23:19:22 -05006910 },
6911 shouldFail: true,
6912 expectedError: ":NO_RENEGOTIATION:",
6913 // We do not successfully send the no_renegotiation alert in
6914 // this case. https://crbug.com/boringssl/130
6915 })
6916
David Benjamin07ab5d42017-02-09 20:11:41 -05006917 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006918 testCases = append(testCases, testCase{
6919 name: "StrayHelloRequest",
6920 config: Config{
6921 MaxVersion: VersionTLS12,
6922 Bugs: ProtocolBugs{
6923 SendHelloRequestBeforeEveryHandshakeMessage: true,
6924 },
6925 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006926 shouldFail: true,
6927 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006928 })
6929 testCases = append(testCases, testCase{
6930 name: "StrayHelloRequest-Packed",
6931 config: Config{
6932 MaxVersion: VersionTLS12,
6933 Bugs: ProtocolBugs{
6934 PackHandshakeFlight: true,
6935 SendHelloRequestBeforeEveryHandshakeMessage: true,
6936 },
6937 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006938 shouldFail: true,
6939 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006940 })
6941
David Benjamin12d2c482016-07-24 10:56:51 -04006942 // Test renegotiation works if HelloRequest and server Finished come in
6943 // the same record.
6944 testCases = append(testCases, testCase{
6945 name: "Renegotiate-Client-Packed",
6946 config: Config{
6947 MaxVersion: VersionTLS12,
6948 Bugs: ProtocolBugs{
6949 PackHandshakeFlight: true,
6950 PackHelloRequestWithFinished: true,
6951 },
6952 },
6953 renegotiate: 1,
6954 flags: []string{
6955 "-renegotiate-freely",
6956 "-expect-total-renegotiations", "1",
6957 },
6958 })
6959
David Benjamin397c8e62016-07-08 14:14:36 -07006960 // Renegotiation is forbidden in TLS 1.3.
6961 testCases = append(testCases, testCase{
6962 name: "Renegotiate-Client-TLS13",
6963 config: Config{
6964 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006965 Bugs: ProtocolBugs{
6966 SendHelloRequestBeforeEveryAppDataRecord: true,
6967 },
David Benjamin397c8e62016-07-08 14:14:36 -07006968 },
David Benjamin397c8e62016-07-08 14:14:36 -07006969 flags: []string{
6970 "-renegotiate-freely",
6971 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006972 shouldFail: true,
6973 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006974 })
6975
6976 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6977 testCases = append(testCases, testCase{
6978 name: "StrayHelloRequest-TLS13",
6979 config: Config{
6980 MaxVersion: VersionTLS13,
6981 Bugs: ProtocolBugs{
6982 SendHelloRequestBeforeEveryHandshakeMessage: true,
6983 },
6984 },
6985 shouldFail: true,
6986 expectedError: ":UNEXPECTED_MESSAGE:",
6987 })
David Benjamind2610042017-01-03 10:49:28 -05006988
6989 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6990 // always reads as supporting it, regardless of whether it was
6991 // negotiated.
6992 testCases = append(testCases, testCase{
6993 name: "AlwaysReportRenegotiationInfo-TLS13",
6994 config: Config{
6995 MaxVersion: VersionTLS13,
6996 Bugs: ProtocolBugs{
6997 NoRenegotiationInfo: true,
6998 },
6999 },
7000 flags: []string{
7001 "-expect-secure-renegotiation",
7002 },
7003 })
David Benjamina58baaf2017-02-28 20:54:28 -05007004
7005 // Certificates may not change on renegotiation.
7006 testCases = append(testCases, testCase{
7007 name: "Renegotiation-CertificateChange",
7008 config: Config{
7009 MaxVersion: VersionTLS12,
7010 Certificates: []Certificate{rsaCertificate},
7011 Bugs: ProtocolBugs{
7012 RenegotiationCertificate: &rsaChainCertificate,
7013 },
7014 },
7015 renegotiate: 1,
7016 flags: []string{"-renegotiate-freely"},
7017 shouldFail: true,
7018 expectedError: ":SERVER_CERT_CHANGED:",
7019 })
7020 testCases = append(testCases, testCase{
7021 name: "Renegotiation-CertificateChange-2",
7022 config: Config{
7023 MaxVersion: VersionTLS12,
7024 Certificates: []Certificate{rsaCertificate},
7025 Bugs: ProtocolBugs{
7026 RenegotiationCertificate: &rsa1024Certificate,
7027 },
7028 },
7029 renegotiate: 1,
7030 flags: []string{"-renegotiate-freely"},
7031 shouldFail: true,
7032 expectedError: ":SERVER_CERT_CHANGED:",
7033 })
David Benjaminbbf42462017-03-14 21:27:10 -04007034
7035 // We do not negotiate ALPN after the initial handshake. This is
7036 // error-prone and only risks bugs in consumers.
7037 testCases = append(testCases, testCase{
7038 testType: clientTest,
7039 name: "Renegotiation-ForbidALPN",
7040 config: Config{
7041 MaxVersion: VersionTLS12,
7042 Bugs: ProtocolBugs{
7043 // Forcibly negotiate ALPN on both initial and
7044 // renegotiation handshakes. The test stack will
7045 // internally check the client does not offer
7046 // it.
7047 SendALPN: "foo",
7048 },
7049 },
7050 flags: []string{
7051 "-advertise-alpn", "\x03foo\x03bar\x03baz",
7052 "-expect-alpn", "foo",
7053 "-renegotiate-freely",
7054 },
7055 renegotiate: 1,
7056 shouldFail: true,
7057 expectedError: ":UNEXPECTED_EXTENSION:",
7058 })
Adam Langley2ae77d22014-10-28 17:29:33 -07007059}
7060
David Benjamin5e961c12014-11-07 01:48:35 -05007061func addDTLSReplayTests() {
7062 // Test that sequence number replays are detected.
7063 testCases = append(testCases, testCase{
7064 protocol: dtls,
7065 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04007066 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007067 replayWrites: true,
7068 })
7069
David Benjamin8e6db492015-07-25 18:29:23 -04007070 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05007071 // than the retransmit window.
7072 testCases = append(testCases, testCase{
7073 protocol: dtls,
7074 name: "DTLS-Replay-LargeGaps",
7075 config: Config{
7076 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04007077 SequenceNumberMapping: func(in uint64) uint64 {
7078 return in * 127
7079 },
David Benjamin5e961c12014-11-07 01:48:35 -05007080 },
7081 },
David Benjamin8e6db492015-07-25 18:29:23 -04007082 messageCount: 200,
7083 replayWrites: true,
7084 })
7085
7086 // Test the incoming sequence number changing non-monotonically.
7087 testCases = append(testCases, testCase{
7088 protocol: dtls,
7089 name: "DTLS-Replay-NonMonotonic",
7090 config: Config{
7091 Bugs: ProtocolBugs{
7092 SequenceNumberMapping: func(in uint64) uint64 {
7093 return in ^ 31
7094 },
7095 },
7096 },
7097 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05007098 replayWrites: true,
7099 })
7100}
7101
Nick Harper60edffd2016-06-21 15:19:24 -07007102var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05007103 name string
Nick Harper60edffd2016-06-21 15:19:24 -07007104 id signatureAlgorithm
7105 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05007106}{
Nick Harper60edffd2016-06-21 15:19:24 -07007107 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
7108 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
7109 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
7110 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07007111 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
Adam Langley764ab982017-03-10 18:01:30 -08007112 // The “P256” in the following line is not a mistake. In TLS 1.2 the
7113 // hash function doesn't have to match the curve and so the same
7114 // signature algorithm works with P-224.
7115 {"ECDSA-P224-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP224},
David Benjamin33863262016-07-08 17:20:12 -07007116 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
7117 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
7118 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007119 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
7120 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
7121 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin69522112017-03-28 15:38:29 -05007122 {"Ed25519", signatureEd25519, testCertEd25519},
David Benjamin5208fd42016-07-13 21:43:25 -04007123 // Tests for key types prior to TLS 1.2.
7124 {"RSA", 0, testCertRSA},
7125 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05007126}
7127
Nick Harper60edffd2016-06-21 15:19:24 -07007128const fakeSigAlg1 signatureAlgorithm = 0x2a01
7129const fakeSigAlg2 signatureAlgorithm = 0xff01
7130
7131func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04007132 // Not all ciphers involve a signature. Advertise a list which gives all
7133 // versions a signing cipher.
7134 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04007135 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04007136 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
7137 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7138 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
7139 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007140 }
David Benjamin5208fd42016-07-13 21:43:25 -04007141
David Benjaminca3d5452016-07-14 12:51:01 -04007142 var allAlgorithms []signatureAlgorithm
7143 for _, alg := range testSignatureAlgorithms {
7144 if alg.id != 0 {
7145 allAlgorithms = append(allAlgorithms, alg.id)
7146 }
7147 }
7148
Nick Harper60edffd2016-06-21 15:19:24 -07007149 // Make sure each signature algorithm works. Include some fake values in
7150 // the list and ensure they're ignored.
7151 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07007152 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04007153 if (ver.version < VersionTLS12) != (alg.id == 0) {
7154 continue
7155 }
7156
7157 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
7158 // or remove it in C.
7159 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07007160 continue
7161 }
Nick Harper60edffd2016-06-21 15:19:24 -07007162
David Benjamin3ef76972016-10-17 17:59:54 -04007163 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07007164 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007165 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04007166 shouldSignFail = true
7167 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007168 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04007169 // RSA-PKCS1 does not exist in TLS 1.3.
Adam Langley764ab982017-03-10 18:01:30 -08007170 if ver.version >= VersionTLS13 && hasComponent(alg.name, "PKCS1") {
7171 shouldSignFail = true
7172 shouldVerifyFail = true
7173 }
7174 // SHA-224 has been removed from TLS 1.3 and, in 1.3,
7175 // the curve has to match the hash size.
7176 if ver.version >= VersionTLS13 && alg.cert == testCertECDSAP224 {
David Benjamin3ef76972016-10-17 17:59:54 -04007177 shouldSignFail = true
7178 shouldVerifyFail = true
7179 }
7180
7181 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
7182 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
7183 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04007184 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007185
7186 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04007187 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007188 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04007189 }
7190 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007191 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07007192 }
David Benjamin000800a2014-11-14 01:43:59 -05007193
David Benjamin1fb125c2016-07-08 18:52:12 -07007194 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05007195
David Benjamin7a41d372016-07-09 11:21:54 -07007196 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007197 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007198 config: Config{
7199 MaxVersion: ver.version,
7200 ClientAuth: RequireAnyClientCert,
7201 VerifySignatureAlgorithms: []signatureAlgorithm{
7202 fakeSigAlg1,
7203 alg.id,
7204 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07007205 },
David Benjamin7a41d372016-07-09 11:21:54 -07007206 },
7207 flags: []string{
7208 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7209 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7210 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007211 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007212 },
David Benjamin3ef76972016-10-17 17:59:54 -04007213 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007214 expectedError: signError,
7215 expectedPeerSignatureAlgorithm: alg.id,
7216 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007217
David Benjamin7a41d372016-07-09 11:21:54 -07007218 testCases = append(testCases, testCase{
7219 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007220 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07007221 config: Config{
7222 MaxVersion: ver.version,
7223 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7224 SignSignatureAlgorithms: []signatureAlgorithm{
7225 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007226 },
David Benjamin7a41d372016-07-09 11:21:54 -07007227 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007228 SkipECDSACurveCheck: shouldVerifyFail,
7229 IgnoreSignatureVersionChecks: shouldVerifyFail,
7230 // Some signature algorithms may not be advertised.
7231 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007232 },
David Benjamin7a41d372016-07-09 11:21:54 -07007233 },
7234 flags: []string{
7235 "-require-any-client-certificate",
7236 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7237 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007238 "-enable-ed25519",
David Benjamin7a41d372016-07-09 11:21:54 -07007239 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007240 // Resume the session to assert the peer signature
7241 // algorithm is reported on both handshakes.
7242 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007243 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07007244 expectedError: verifyError,
7245 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007246
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007247 // No signing cipher for SSL 3.0.
David Benjamin96bc12a2017-04-14 16:48:08 -04007248 if ver.version > VersionSSL30 {
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007249 testCases = append(testCases, testCase{
7250 testType: serverTest,
7251 name: "ServerAuth-Sign" + suffix,
7252 config: Config{
7253 MaxVersion: ver.version,
7254 CipherSuites: signingCiphers,
7255 VerifySignatureAlgorithms: []signatureAlgorithm{
7256 fakeSigAlg1,
7257 alg.id,
7258 fakeSigAlg2,
7259 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007260 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007261 flags: []string{
7262 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7263 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7264 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007265 "-enable-ed25519",
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07007266 },
7267 shouldFail: shouldSignFail,
7268 expectedError: signError,
7269 expectedPeerSignatureAlgorithm: alg.id,
7270 })
7271 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007272
7273 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007274 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07007275 config: Config{
7276 MaxVersion: ver.version,
7277 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04007278 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07007279 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007280 alg.id,
7281 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007282 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04007283 SkipECDSACurveCheck: shouldVerifyFail,
7284 IgnoreSignatureVersionChecks: shouldVerifyFail,
7285 // Some signature algorithms may not be advertised.
7286 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007287 },
David Benjamin1fb125c2016-07-08 18:52:12 -07007288 },
7289 flags: []string{
7290 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
7291 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007292 "-enable-ed25519",
David Benjamin1fb125c2016-07-08 18:52:12 -07007293 },
David Benjaminf1050fd2016-12-13 20:05:36 -05007294 // Resume the session to assert the peer signature
7295 // algorithm is reported on both handshakes.
7296 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04007297 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04007298 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07007299 })
David Benjamin5208fd42016-07-13 21:43:25 -04007300
David Benjamin3ef76972016-10-17 17:59:54 -04007301 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04007302 testCases = append(testCases, testCase{
7303 testType: serverTest,
7304 name: "ClientAuth-InvalidSignature" + suffix,
7305 config: Config{
7306 MaxVersion: ver.version,
7307 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7308 SignSignatureAlgorithms: []signatureAlgorithm{
7309 alg.id,
7310 },
7311 Bugs: ProtocolBugs{
7312 InvalidSignature: true,
7313 },
7314 },
7315 flags: []string{
7316 "-require-any-client-certificate",
7317 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007318 "-enable-ed25519",
David Benjamin5208fd42016-07-13 21:43:25 -04007319 },
7320 shouldFail: true,
7321 expectedError: ":BAD_SIGNATURE:",
7322 })
7323
7324 testCases = append(testCases, testCase{
7325 name: "ServerAuth-InvalidSignature" + suffix,
7326 config: Config{
7327 MaxVersion: ver.version,
7328 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
7329 CipherSuites: signingCiphers,
7330 SignSignatureAlgorithms: []signatureAlgorithm{
7331 alg.id,
7332 },
7333 Bugs: ProtocolBugs{
7334 InvalidSignature: true,
7335 },
7336 },
David Benjamin69522112017-03-28 15:38:29 -05007337 flags: []string{
7338 "-enable-all-curves",
7339 "-enable-ed25519",
7340 },
David Benjamin5208fd42016-07-13 21:43:25 -04007341 shouldFail: true,
7342 expectedError: ":BAD_SIGNATURE:",
7343 })
7344 }
David Benjaminca3d5452016-07-14 12:51:01 -04007345
David Benjamin3ef76972016-10-17 17:59:54 -04007346 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04007347 testCases = append(testCases, testCase{
7348 name: "ClientAuth-Sign-Negotiate" + suffix,
7349 config: Config{
7350 MaxVersion: ver.version,
7351 ClientAuth: RequireAnyClientCert,
7352 VerifySignatureAlgorithms: allAlgorithms,
7353 },
7354 flags: []string{
7355 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7356 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7357 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007358 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007359 "-signing-prefs", strconv.Itoa(int(alg.id)),
7360 },
7361 expectedPeerSignatureAlgorithm: alg.id,
7362 })
7363
7364 testCases = append(testCases, testCase{
7365 testType: serverTest,
7366 name: "ServerAuth-Sign-Negotiate" + suffix,
7367 config: Config{
7368 MaxVersion: ver.version,
7369 CipherSuites: signingCiphers,
7370 VerifySignatureAlgorithms: allAlgorithms,
7371 },
7372 flags: []string{
7373 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
7374 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
7375 "-enable-all-curves",
David Benjamin69522112017-03-28 15:38:29 -05007376 "-enable-ed25519",
David Benjaminca3d5452016-07-14 12:51:01 -04007377 "-signing-prefs", strconv.Itoa(int(alg.id)),
7378 },
7379 expectedPeerSignatureAlgorithm: alg.id,
7380 })
7381 }
David Benjamin1fb125c2016-07-08 18:52:12 -07007382 }
David Benjamin000800a2014-11-14 01:43:59 -05007383 }
7384
Nick Harper60edffd2016-06-21 15:19:24 -07007385 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05007386 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007387 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007388 config: Config{
7389 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04007390 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007391 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007392 signatureECDSAWithP521AndSHA512,
7393 signatureRSAPKCS1WithSHA384,
7394 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007395 },
7396 },
7397 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007398 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7399 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007400 },
Nick Harper60edffd2016-06-21 15:19:24 -07007401 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007402 })
7403
7404 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007405 name: "ClientAuth-SignatureType-TLS13",
7406 config: Config{
7407 ClientAuth: RequireAnyClientCert,
7408 MaxVersion: VersionTLS13,
7409 VerifySignatureAlgorithms: []signatureAlgorithm{
7410 signatureECDSAWithP521AndSHA512,
7411 signatureRSAPKCS1WithSHA384,
7412 signatureRSAPSSWithSHA384,
7413 signatureECDSAWithSHA1,
7414 },
7415 },
7416 flags: []string{
7417 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7418 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7419 },
7420 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7421 })
7422
7423 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05007424 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007425 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05007426 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007427 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007428 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007429 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007430 signatureECDSAWithP521AndSHA512,
7431 signatureRSAPKCS1WithSHA384,
7432 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007433 },
7434 },
Nick Harper60edffd2016-06-21 15:19:24 -07007435 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05007436 })
7437
Steven Valdez143e8b32016-07-11 13:19:03 -04007438 testCases = append(testCases, testCase{
7439 testType: serverTest,
7440 name: "ServerAuth-SignatureType-TLS13",
7441 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007442 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007443 VerifySignatureAlgorithms: []signatureAlgorithm{
7444 signatureECDSAWithP521AndSHA512,
7445 signatureRSAPKCS1WithSHA384,
7446 signatureRSAPSSWithSHA384,
7447 signatureECDSAWithSHA1,
7448 },
7449 },
7450 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
7451 })
7452
David Benjamina95e9f32016-07-08 16:28:04 -07007453 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07007454 testCases = append(testCases, testCase{
7455 testType: serverTest,
7456 name: "Verify-ClientAuth-SignatureType",
7457 config: Config{
7458 MaxVersion: VersionTLS12,
7459 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007460 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007461 signatureRSAPKCS1WithSHA256,
7462 },
7463 Bugs: ProtocolBugs{
7464 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7465 },
7466 },
7467 flags: []string{
7468 "-require-any-client-certificate",
7469 },
7470 shouldFail: true,
7471 expectedError: ":WRONG_SIGNATURE_TYPE:",
7472 })
7473
7474 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007475 testType: serverTest,
7476 name: "Verify-ClientAuth-SignatureType-TLS13",
7477 config: Config{
7478 MaxVersion: VersionTLS13,
7479 Certificates: []Certificate{rsaCertificate},
7480 SignSignatureAlgorithms: []signatureAlgorithm{
7481 signatureRSAPSSWithSHA256,
7482 },
7483 Bugs: ProtocolBugs{
7484 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7485 },
7486 },
7487 flags: []string{
7488 "-require-any-client-certificate",
7489 },
7490 shouldFail: true,
7491 expectedError: ":WRONG_SIGNATURE_TYPE:",
7492 })
7493
7494 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007495 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07007496 config: Config{
7497 MaxVersion: VersionTLS12,
7498 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007499 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07007500 signatureRSAPKCS1WithSHA256,
7501 },
7502 Bugs: ProtocolBugs{
7503 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7504 },
7505 },
7506 shouldFail: true,
7507 expectedError: ":WRONG_SIGNATURE_TYPE:",
7508 })
7509
Steven Valdez143e8b32016-07-11 13:19:03 -04007510 testCases = append(testCases, testCase{
7511 name: "Verify-ServerAuth-SignatureType-TLS13",
7512 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007513 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007514 SignSignatureAlgorithms: []signatureAlgorithm{
7515 signatureRSAPSSWithSHA256,
7516 },
7517 Bugs: ProtocolBugs{
7518 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7519 },
7520 },
7521 shouldFail: true,
7522 expectedError: ":WRONG_SIGNATURE_TYPE:",
7523 })
7524
David Benjamin51dd7d62016-07-08 16:07:01 -07007525 // Test that, if the list is missing, the peer falls back to SHA-1 in
7526 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007527 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007528 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007530 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007531 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007532 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007533 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007534 },
7535 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007536 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007537 },
7538 },
7539 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007540 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7541 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007542 },
7543 })
7544
7545 testCases = append(testCases, testCase{
7546 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007547 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007548 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007549 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007550 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007551 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007552 },
7553 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007554 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007555 },
7556 },
David Benjaminee32bea2016-08-17 13:36:44 -04007557 flags: []string{
7558 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7559 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7560 },
7561 })
7562
7563 testCases = append(testCases, testCase{
7564 name: "ClientAuth-SHA1-Fallback-ECDSA",
7565 config: Config{
7566 MaxVersion: VersionTLS12,
7567 ClientAuth: RequireAnyClientCert,
7568 VerifySignatureAlgorithms: []signatureAlgorithm{
7569 signatureECDSAWithSHA1,
7570 },
7571 Bugs: ProtocolBugs{
7572 NoSignatureAlgorithms: true,
7573 },
7574 },
7575 flags: []string{
7576 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7577 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7578 },
7579 })
7580
7581 testCases = append(testCases, testCase{
7582 testType: serverTest,
7583 name: "ServerAuth-SHA1-Fallback-ECDSA",
7584 config: Config{
7585 MaxVersion: VersionTLS12,
7586 VerifySignatureAlgorithms: []signatureAlgorithm{
7587 signatureECDSAWithSHA1,
7588 },
7589 Bugs: ProtocolBugs{
7590 NoSignatureAlgorithms: true,
7591 },
7592 },
7593 flags: []string{
7594 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7595 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7596 },
David Benjamin000800a2014-11-14 01:43:59 -05007597 })
David Benjamin72dc7832015-03-16 17:49:43 -04007598
David Benjamin51dd7d62016-07-08 16:07:01 -07007599 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007600 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007601 config: Config{
7602 MaxVersion: VersionTLS13,
7603 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007604 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007605 signatureRSAPKCS1WithSHA1,
7606 },
7607 Bugs: ProtocolBugs{
7608 NoSignatureAlgorithms: true,
7609 },
7610 },
7611 flags: []string{
7612 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7613 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7614 },
David Benjamin48901652016-08-01 12:12:47 -04007615 shouldFail: true,
7616 // An empty CertificateRequest signature algorithm list is a
7617 // syntax error in TLS 1.3.
7618 expectedError: ":DECODE_ERROR:",
7619 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007620 })
7621
7622 testCases = append(testCases, testCase{
7623 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007624 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007625 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007626 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007627 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007628 signatureRSAPKCS1WithSHA1,
7629 },
7630 Bugs: ProtocolBugs{
7631 NoSignatureAlgorithms: true,
7632 },
7633 },
7634 shouldFail: true,
7635 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7636 })
7637
David Benjaminb62d2872016-07-18 14:55:02 +02007638 // Test that hash preferences are enforced. BoringSSL does not implement
7639 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007640 testCases = append(testCases, testCase{
7641 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007642 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007644 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007645 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007646 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007647 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007648 },
7649 Bugs: ProtocolBugs{
7650 IgnorePeerSignatureAlgorithmPreferences: true,
7651 },
7652 },
7653 flags: []string{"-require-any-client-certificate"},
7654 shouldFail: true,
7655 expectedError: ":WRONG_SIGNATURE_TYPE:",
7656 })
7657
7658 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007659 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007661 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007662 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007663 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007664 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007665 },
7666 Bugs: ProtocolBugs{
7667 IgnorePeerSignatureAlgorithmPreferences: true,
7668 },
7669 },
7670 shouldFail: true,
7671 expectedError: ":WRONG_SIGNATURE_TYPE:",
7672 })
David Benjaminb62d2872016-07-18 14:55:02 +02007673 testCases = append(testCases, testCase{
7674 testType: serverTest,
7675 name: "ClientAuth-Enforced-TLS13",
7676 config: Config{
7677 MaxVersion: VersionTLS13,
7678 Certificates: []Certificate{rsaCertificate},
7679 SignSignatureAlgorithms: []signatureAlgorithm{
7680 signatureRSAPKCS1WithMD5,
7681 },
7682 Bugs: ProtocolBugs{
7683 IgnorePeerSignatureAlgorithmPreferences: true,
7684 IgnoreSignatureVersionChecks: true,
7685 },
7686 },
7687 flags: []string{"-require-any-client-certificate"},
7688 shouldFail: true,
7689 expectedError: ":WRONG_SIGNATURE_TYPE:",
7690 })
7691
7692 testCases = append(testCases, testCase{
7693 name: "ServerAuth-Enforced-TLS13",
7694 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007695 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007696 SignSignatureAlgorithms: []signatureAlgorithm{
7697 signatureRSAPKCS1WithMD5,
7698 },
7699 Bugs: ProtocolBugs{
7700 IgnorePeerSignatureAlgorithmPreferences: true,
7701 IgnoreSignatureVersionChecks: true,
7702 },
7703 },
7704 shouldFail: true,
7705 expectedError: ":WRONG_SIGNATURE_TYPE:",
7706 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007707
7708 // Test that the agreed upon digest respects the client preferences and
7709 // the server digests.
7710 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007711 name: "NoCommonAlgorithms-Digests",
7712 config: Config{
7713 MaxVersion: VersionTLS12,
7714 ClientAuth: RequireAnyClientCert,
7715 VerifySignatureAlgorithms: []signatureAlgorithm{
7716 signatureRSAPKCS1WithSHA512,
7717 signatureRSAPKCS1WithSHA1,
7718 },
7719 },
7720 flags: []string{
7721 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7722 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7723 "-digest-prefs", "SHA256",
7724 },
7725 shouldFail: true,
7726 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7727 })
7728 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007729 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007730 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007731 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007732 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007733 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007734 signatureRSAPKCS1WithSHA512,
7735 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007736 },
7737 },
7738 flags: []string{
7739 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7740 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007741 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007742 },
David Benjaminca3d5452016-07-14 12:51:01 -04007743 shouldFail: true,
7744 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7745 })
7746 testCases = append(testCases, testCase{
7747 name: "NoCommonAlgorithms-TLS13",
7748 config: Config{
7749 MaxVersion: VersionTLS13,
7750 ClientAuth: RequireAnyClientCert,
7751 VerifySignatureAlgorithms: []signatureAlgorithm{
7752 signatureRSAPSSWithSHA512,
7753 signatureRSAPSSWithSHA384,
7754 },
7755 },
7756 flags: []string{
7757 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7758 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7759 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7760 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007761 shouldFail: true,
7762 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007763 })
7764 testCases = append(testCases, testCase{
7765 name: "Agree-Digest-SHA256",
7766 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007767 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007768 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007769 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007770 signatureRSAPKCS1WithSHA1,
7771 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007772 },
7773 },
7774 flags: []string{
7775 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7776 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007777 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007778 },
Nick Harper60edffd2016-06-21 15:19:24 -07007779 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007780 })
7781 testCases = append(testCases, testCase{
7782 name: "Agree-Digest-SHA1",
7783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007784 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007785 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007786 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007787 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007788 },
7789 },
7790 flags: []string{
7791 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7792 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007793 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007794 },
Nick Harper60edffd2016-06-21 15:19:24 -07007795 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007796 })
7797 testCases = append(testCases, testCase{
7798 name: "Agree-Digest-Default",
7799 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007800 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007801 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007802 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007803 signatureRSAPKCS1WithSHA256,
7804 signatureECDSAWithP256AndSHA256,
7805 signatureRSAPKCS1WithSHA1,
7806 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007807 },
7808 },
7809 flags: []string{
7810 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7811 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7812 },
Nick Harper60edffd2016-06-21 15:19:24 -07007813 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007814 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007815
David Benjaminca3d5452016-07-14 12:51:01 -04007816 // Test that the signing preference list may include extra algorithms
7817 // without negotiation problems.
7818 testCases = append(testCases, testCase{
7819 testType: serverTest,
7820 name: "FilterExtraAlgorithms",
7821 config: Config{
7822 MaxVersion: VersionTLS12,
7823 VerifySignatureAlgorithms: []signatureAlgorithm{
7824 signatureRSAPKCS1WithSHA256,
7825 },
7826 },
7827 flags: []string{
7828 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7829 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7830 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7831 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7832 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7833 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7834 },
7835 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7836 })
7837
David Benjamin4c3ddf72016-06-29 18:13:53 -04007838 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7839 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007840 testCases = append(testCases, testCase{
7841 name: "CheckLeafCurve",
7842 config: Config{
7843 MaxVersion: VersionTLS12,
7844 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007845 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007846 },
7847 flags: []string{"-p384-only"},
7848 shouldFail: true,
7849 expectedError: ":BAD_ECC_CERT:",
7850 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007851
7852 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7853 testCases = append(testCases, testCase{
7854 name: "CheckLeafCurve-TLS13",
7855 config: Config{
7856 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007857 Certificates: []Certificate{ecdsaP256Certificate},
7858 },
7859 flags: []string{"-p384-only"},
7860 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007861
7862 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7863 testCases = append(testCases, testCase{
7864 name: "ECDSACurveMismatch-Verify-TLS12",
7865 config: Config{
7866 MaxVersion: VersionTLS12,
7867 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7868 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007869 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007870 signatureECDSAWithP384AndSHA384,
7871 },
7872 },
7873 })
7874
7875 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7876 testCases = append(testCases, testCase{
7877 name: "ECDSACurveMismatch-Verify-TLS13",
7878 config: Config{
7879 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007880 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007881 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007882 signatureECDSAWithP384AndSHA384,
7883 },
7884 Bugs: ProtocolBugs{
7885 SkipECDSACurveCheck: true,
7886 },
7887 },
7888 shouldFail: true,
7889 expectedError: ":WRONG_SIGNATURE_TYPE:",
7890 })
7891
7892 // Signature algorithm selection in TLS 1.3 should take the curve into
7893 // account.
7894 testCases = append(testCases, testCase{
7895 testType: serverTest,
7896 name: "ECDSACurveMismatch-Sign-TLS13",
7897 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007898 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007899 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007900 signatureECDSAWithP384AndSHA384,
7901 signatureECDSAWithP256AndSHA256,
7902 },
7903 },
7904 flags: []string{
7905 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7906 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7907 },
7908 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7909 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007910
7911 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7912 // server does not attempt to sign in that case.
7913 testCases = append(testCases, testCase{
7914 testType: serverTest,
7915 name: "RSA-PSS-Large",
7916 config: Config{
7917 MaxVersion: VersionTLS13,
7918 VerifySignatureAlgorithms: []signatureAlgorithm{
7919 signatureRSAPSSWithSHA512,
7920 },
7921 },
7922 flags: []string{
7923 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7924 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7925 },
7926 shouldFail: true,
7927 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7928 })
David Benjamin57e929f2016-08-30 00:30:38 -04007929
7930 // Test that RSA-PSS is enabled by default for TLS 1.2.
7931 testCases = append(testCases, testCase{
7932 testType: clientTest,
7933 name: "RSA-PSS-Default-Verify",
7934 config: Config{
7935 MaxVersion: VersionTLS12,
7936 SignSignatureAlgorithms: []signatureAlgorithm{
7937 signatureRSAPSSWithSHA256,
7938 },
7939 },
7940 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7941 })
7942
7943 testCases = append(testCases, testCase{
7944 testType: serverTest,
7945 name: "RSA-PSS-Default-Sign",
7946 config: Config{
7947 MaxVersion: VersionTLS12,
7948 VerifySignatureAlgorithms: []signatureAlgorithm{
7949 signatureRSAPSSWithSHA256,
7950 },
7951 },
7952 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7953 })
David Benjamin69522112017-03-28 15:38:29 -05007954
7955 // TLS 1.1 and below has no way to advertise support for or negotiate
7956 // Ed25519's signature algorithm.
7957 testCases = append(testCases, testCase{
7958 testType: clientTest,
7959 name: "NoEd25519-TLS11-ServerAuth-Verify",
7960 config: Config{
7961 MaxVersion: VersionTLS11,
7962 Certificates: []Certificate{ed25519Certificate},
7963 Bugs: ProtocolBugs{
7964 // Sign with Ed25519 even though it is TLS 1.1.
7965 UseLegacySigningAlgorithm: signatureEd25519,
7966 },
7967 },
7968 flags: []string{"-enable-ed25519"},
7969 shouldFail: true,
7970 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
7971 })
7972 testCases = append(testCases, testCase{
7973 testType: serverTest,
7974 name: "NoEd25519-TLS11-ServerAuth-Sign",
7975 config: Config{
7976 MaxVersion: VersionTLS11,
7977 },
7978 flags: []string{
7979 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
7980 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
7981 },
7982 shouldFail: true,
7983 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7984 })
7985 testCases = append(testCases, testCase{
7986 testType: serverTest,
7987 name: "NoEd25519-TLS11-ClientAuth-Verify",
7988 config: Config{
7989 MaxVersion: VersionTLS11,
7990 Certificates: []Certificate{ed25519Certificate},
7991 Bugs: ProtocolBugs{
7992 // Sign with Ed25519 even though it is TLS 1.1.
7993 UseLegacySigningAlgorithm: signatureEd25519,
7994 },
7995 },
7996 flags: []string{
7997 "-enable-ed25519",
7998 "-require-any-client-certificate",
7999 },
8000 shouldFail: true,
8001 expectedError: ":PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE:",
8002 })
8003 testCases = append(testCases, testCase{
8004 testType: clientTest,
8005 name: "NoEd25519-TLS11-ClientAuth-Sign",
8006 config: Config{
8007 MaxVersion: VersionTLS11,
8008 ClientAuth: RequireAnyClientCert,
8009 },
8010 flags: []string{
8011 "-cert-file", path.Join(*resourceDir, ed25519CertificateFile),
8012 "-key-file", path.Join(*resourceDir, ed25519KeyFile),
8013 },
8014 shouldFail: true,
8015 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
8016 })
8017
8018 // Test Ed25519 is not advertised by default.
8019 testCases = append(testCases, testCase{
8020 testType: clientTest,
8021 name: "Ed25519DefaultDisable-NoAdvertise",
8022 config: Config{
8023 Certificates: []Certificate{ed25519Certificate},
8024 },
8025 shouldFail: true,
8026 expectedLocalError: "tls: no common signature algorithms",
8027 })
8028
8029 // Test Ed25519, when disabled, is not accepted if the peer ignores our
8030 // preferences.
8031 testCases = append(testCases, testCase{
8032 testType: clientTest,
8033 name: "Ed25519DefaultDisable-NoAccept",
8034 config: Config{
8035 Certificates: []Certificate{ed25519Certificate},
8036 Bugs: ProtocolBugs{
8037 IgnorePeerSignatureAlgorithmPreferences: true,
8038 },
8039 },
8040 shouldFail: true,
8041 expectedLocalError: "remote error: illegal parameter",
8042 expectedError: ":WRONG_SIGNATURE_TYPE:",
8043 })
David Benjamin71c21b42017-04-14 17:05:40 -04008044
8045 // Test that configuring verify preferences changes what the client
8046 // advertises.
8047 testCases = append(testCases, testCase{
8048 name: "VerifyPreferences-Advertised",
8049 config: Config{
8050 Certificates: []Certificate{rsaCertificate},
8051 SignSignatureAlgorithms: []signatureAlgorithm{
8052 signatureRSAPSSWithSHA256,
8053 signatureRSAPSSWithSHA384,
8054 signatureRSAPSSWithSHA512,
8055 },
8056 },
8057 flags: []string{
8058 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8059 "-expect-peer-signature-algorithm", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8060 },
8061 })
8062
8063 // Test that the client advertises a set which the runner can find
8064 // nothing in common with.
8065 testCases = append(testCases, testCase{
8066 name: "VerifyPreferences-NoCommonAlgorithms",
8067 config: Config{
8068 Certificates: []Certificate{rsaCertificate},
8069 SignSignatureAlgorithms: []signatureAlgorithm{
8070 signatureRSAPSSWithSHA256,
8071 signatureRSAPSSWithSHA512,
8072 },
8073 },
8074 flags: []string{
8075 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8076 },
8077 shouldFail: true,
8078 expectedLocalError: "tls: no common signature algorithms",
8079 })
8080
8081 // Test that the client enforces its preferences when configured.
8082 testCases = append(testCases, testCase{
8083 name: "VerifyPreferences-Enforced",
8084 config: Config{
8085 Certificates: []Certificate{rsaCertificate},
8086 SignSignatureAlgorithms: []signatureAlgorithm{
8087 signatureRSAPSSWithSHA256,
8088 signatureRSAPSSWithSHA512,
8089 },
8090 Bugs: ProtocolBugs{
8091 IgnorePeerSignatureAlgorithmPreferences: true,
8092 },
8093 },
8094 flags: []string{
8095 "-verify-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA384)),
8096 },
8097 shouldFail: true,
8098 expectedLocalError: "remote error: illegal parameter",
8099 expectedError: ":WRONG_SIGNATURE_TYPE:",
8100 })
8101
8102 // Test that explicitly configuring Ed25519 is as good as changing the
8103 // boolean toggle.
8104 testCases = append(testCases, testCase{
8105 name: "VerifyPreferences-Ed25519",
8106 config: Config{
8107 Certificates: []Certificate{ed25519Certificate},
8108 },
8109 flags: []string{
8110 "-verify-prefs", strconv.Itoa(int(signatureEd25519)),
8111 },
8112 })
David Benjamin000800a2014-11-14 01:43:59 -05008113}
8114
David Benjamin83f90402015-01-27 01:09:43 -05008115// timeouts is the retransmit schedule for BoringSSL. It doubles and
8116// caps at 60 seconds. On the 13th timeout, it gives up.
8117var timeouts = []time.Duration{
8118 1 * time.Second,
8119 2 * time.Second,
8120 4 * time.Second,
8121 8 * time.Second,
8122 16 * time.Second,
8123 32 * time.Second,
8124 60 * time.Second,
8125 60 * time.Second,
8126 60 * time.Second,
8127 60 * time.Second,
8128 60 * time.Second,
8129 60 * time.Second,
8130 60 * time.Second,
8131}
8132
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07008133// shortTimeouts is an alternate set of timeouts which would occur if the
8134// initial timeout duration was set to 250ms.
8135var shortTimeouts = []time.Duration{
8136 250 * time.Millisecond,
8137 500 * time.Millisecond,
8138 1 * time.Second,
8139 2 * time.Second,
8140 4 * time.Second,
8141 8 * time.Second,
8142 16 * time.Second,
8143 32 * time.Second,
8144 60 * time.Second,
8145 60 * time.Second,
8146 60 * time.Second,
8147 60 * time.Second,
8148 60 * time.Second,
8149}
8150
David Benjamin83f90402015-01-27 01:09:43 -05008151func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04008152 // These tests work by coordinating some behavior on both the shim and
8153 // the runner.
8154 //
8155 // TimeoutSchedule configures the runner to send a series of timeout
8156 // opcodes to the shim (see packetAdaptor) immediately before reading
8157 // each peer handshake flight N. The timeout opcode both simulates a
8158 // timeout in the shim and acts as a synchronization point to help the
8159 // runner bracket each handshake flight.
8160 //
8161 // We assume the shim does not read from the channel eagerly. It must
8162 // first wait until it has sent flight N and is ready to receive
8163 // handshake flight N+1. At this point, it will process the timeout
8164 // opcode. It must then immediately respond with a timeout ACK and act
8165 // as if the shim was idle for the specified amount of time.
8166 //
8167 // The runner then drops all packets received before the ACK and
8168 // continues waiting for flight N. This ordering results in one attempt
8169 // at sending flight N to be dropped. For the test to complete, the
8170 // shim must send flight N again, testing that the shim implements DTLS
8171 // retransmit on a timeout.
8172
Steven Valdez143e8b32016-07-11 13:19:03 -04008173 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04008174 // likely be more epochs to cross and the final message's retransmit may
8175 // be more complex.
8176
David Benjamin11c82892017-02-23 20:40:31 -05008177 // Test that this is indeed the timeout schedule. Stress all
8178 // four patterns of handshake.
8179 for i := 1; i < len(timeouts); i++ {
8180 number := strconv.Itoa(i)
8181 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008182 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05008183 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008185 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008186 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008187 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008188 },
8189 },
8190 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008191 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008192 })
David Benjamin11c82892017-02-23 20:40:31 -05008193 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05008194 protocol: dtls,
8195 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05008196 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05008197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008198 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05008199 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05008200 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05008201 },
8202 },
8203 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05008204 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05008205 })
8206 }
David Benjamin11c82892017-02-23 20:40:31 -05008207
8208 // Test that exceeding the timeout schedule hits a read
8209 // timeout.
8210 testCases = append(testCases, testCase{
8211 protocol: dtls,
8212 name: "DTLS-Retransmit-Timeout",
8213 config: Config{
8214 MaxVersion: VersionTLS12,
8215 Bugs: ProtocolBugs{
8216 TimeoutSchedule: timeouts,
8217 },
8218 },
8219 resumeSession: true,
8220 flags: []string{"-async"},
8221 shouldFail: true,
8222 expectedError: ":READ_TIMEOUT_EXPIRED:",
8223 })
8224
8225 // Test that timeout handling has a fudge factor, due to API
8226 // problems.
8227 testCases = append(testCases, testCase{
8228 protocol: dtls,
8229 name: "DTLS-Retransmit-Fudge",
8230 config: Config{
8231 MaxVersion: VersionTLS12,
8232 Bugs: ProtocolBugs{
8233 TimeoutSchedule: []time.Duration{
8234 timeouts[0] - 10*time.Millisecond,
8235 },
8236 },
8237 },
8238 resumeSession: true,
8239 flags: []string{"-async"},
8240 })
8241
8242 // Test that the final Finished retransmitting isn't
8243 // duplicated if the peer badly fragments everything.
8244 testCases = append(testCases, testCase{
8245 testType: serverTest,
8246 protocol: dtls,
8247 name: "DTLS-Retransmit-Fragmented",
8248 config: Config{
8249 MaxVersion: VersionTLS12,
8250 Bugs: ProtocolBugs{
8251 TimeoutSchedule: []time.Duration{timeouts[0]},
8252 MaxHandshakeRecordLength: 2,
8253 },
8254 },
8255 flags: []string{"-async"},
8256 })
8257
8258 // Test the timeout schedule when a shorter initial timeout duration is set.
8259 testCases = append(testCases, testCase{
8260 protocol: dtls,
8261 name: "DTLS-Retransmit-Short-Client",
8262 config: Config{
8263 MaxVersion: VersionTLS12,
8264 Bugs: ProtocolBugs{
8265 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8266 },
8267 },
8268 resumeSession: true,
8269 flags: []string{
8270 "-async",
8271 "-initial-timeout-duration-ms", "250",
8272 },
8273 })
8274 testCases = append(testCases, testCase{
8275 protocol: dtls,
8276 testType: serverTest,
8277 name: "DTLS-Retransmit-Short-Server",
8278 config: Config{
8279 MaxVersion: VersionTLS12,
8280 Bugs: ProtocolBugs{
8281 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
8282 },
8283 },
8284 resumeSession: true,
8285 flags: []string{
8286 "-async",
8287 "-initial-timeout-duration-ms", "250",
8288 },
8289 })
David Benjamin83f90402015-01-27 01:09:43 -05008290}
8291
David Benjaminc565ebb2015-04-03 04:06:36 -04008292func addExportKeyingMaterialTests() {
8293 for _, vers := range tlsVersions {
8294 if vers.version == VersionSSL30 {
8295 continue
8296 }
8297 testCases = append(testCases, testCase{
8298 name: "ExportKeyingMaterial-" + vers.name,
8299 config: Config{
8300 MaxVersion: vers.version,
8301 },
8302 exportKeyingMaterial: 1024,
8303 exportLabel: "label",
8304 exportContext: "context",
8305 useExportContext: true,
8306 })
8307 testCases = append(testCases, testCase{
8308 name: "ExportKeyingMaterial-NoContext-" + vers.name,
8309 config: Config{
8310 MaxVersion: vers.version,
8311 },
8312 exportKeyingMaterial: 1024,
8313 })
8314 testCases = append(testCases, testCase{
8315 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
8316 config: Config{
8317 MaxVersion: vers.version,
8318 },
8319 exportKeyingMaterial: 1024,
8320 useExportContext: true,
8321 })
8322 testCases = append(testCases, testCase{
8323 name: "ExportKeyingMaterial-Small-" + vers.name,
8324 config: Config{
8325 MaxVersion: vers.version,
8326 },
8327 exportKeyingMaterial: 1,
8328 exportLabel: "label",
8329 exportContext: "context",
8330 useExportContext: true,
8331 })
8332 }
David Benjamin7bb1d292016-11-01 19:45:06 -04008333
David Benjaminc565ebb2015-04-03 04:06:36 -04008334 testCases = append(testCases, testCase{
8335 name: "ExportKeyingMaterial-SSL3",
8336 config: Config{
8337 MaxVersion: VersionSSL30,
8338 },
8339 exportKeyingMaterial: 1024,
8340 exportLabel: "label",
8341 exportContext: "context",
8342 useExportContext: true,
8343 shouldFail: true,
8344 expectedError: "failed to export keying material",
8345 })
David Benjamin7bb1d292016-11-01 19:45:06 -04008346
8347 // Exporters work during a False Start.
8348 testCases = append(testCases, testCase{
8349 name: "ExportKeyingMaterial-FalseStart",
8350 config: Config{
8351 MaxVersion: VersionTLS12,
8352 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8353 NextProtos: []string{"foo"},
8354 Bugs: ProtocolBugs{
8355 ExpectFalseStart: true,
8356 },
8357 },
8358 flags: []string{
8359 "-false-start",
8360 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -04008361 "-expect-alpn", "foo",
David Benjamin7bb1d292016-11-01 19:45:06 -04008362 },
8363 shimWritesFirst: true,
8364 exportKeyingMaterial: 1024,
8365 exportLabel: "label",
8366 exportContext: "context",
8367 useExportContext: true,
8368 })
8369
8370 // Exporters do not work in the middle of a renegotiation. Test this by
8371 // triggering the exporter after every SSL_read call and configuring the
8372 // shim to run asynchronously.
8373 testCases = append(testCases, testCase{
8374 name: "ExportKeyingMaterial-Renegotiate",
8375 config: Config{
8376 MaxVersion: VersionTLS12,
8377 },
8378 renegotiate: 1,
8379 flags: []string{
8380 "-async",
8381 "-use-exporter-between-reads",
8382 "-renegotiate-freely",
8383 "-expect-total-renegotiations", "1",
8384 },
8385 shouldFail: true,
8386 expectedError: "failed to export keying material",
8387 })
David Benjaminc565ebb2015-04-03 04:06:36 -04008388}
8389
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008390func addTLSUniqueTests() {
8391 for _, isClient := range []bool{false, true} {
8392 for _, isResumption := range []bool{false, true} {
8393 for _, hasEMS := range []bool{false, true} {
8394 var suffix string
8395 if isResumption {
8396 suffix = "Resume-"
8397 } else {
8398 suffix = "Full-"
8399 }
8400
8401 if hasEMS {
8402 suffix += "EMS-"
8403 } else {
8404 suffix += "NoEMS-"
8405 }
8406
8407 if isClient {
8408 suffix += "Client"
8409 } else {
8410 suffix += "Server"
8411 }
8412
8413 test := testCase{
8414 name: "TLSUnique-" + suffix,
8415 testTLSUnique: true,
8416 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008417 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008418 Bugs: ProtocolBugs{
8419 NoExtendedMasterSecret: !hasEMS,
8420 },
8421 },
8422 }
8423
8424 if isResumption {
8425 test.resumeSession = true
8426 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008427 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008428 Bugs: ProtocolBugs{
8429 NoExtendedMasterSecret: !hasEMS,
8430 },
8431 }
8432 }
8433
8434 if isResumption && !hasEMS {
8435 test.shouldFail = true
8436 test.expectedError = "failed to get tls-unique"
8437 }
8438
8439 testCases = append(testCases, test)
8440 }
8441 }
8442 }
8443}
8444
Adam Langley09505632015-07-30 18:10:13 -07008445func addCustomExtensionTests() {
8446 expectedContents := "custom extension"
8447 emptyString := ""
8448
8449 for _, isClient := range []bool{false, true} {
8450 suffix := "Server"
8451 flag := "-enable-server-custom-extension"
8452 testType := serverTest
8453 if isClient {
8454 suffix = "Client"
8455 flag = "-enable-client-custom-extension"
8456 testType = clientTest
8457 }
8458
8459 testCases = append(testCases, testCase{
8460 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008461 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008463 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008464 Bugs: ProtocolBugs{
8465 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008466 ExpectedCustomExtension: &expectedContents,
8467 },
8468 },
8469 flags: []string{flag},
8470 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008471 testCases = append(testCases, testCase{
8472 testType: testType,
8473 name: "CustomExtensions-" + suffix + "-TLS13",
8474 config: Config{
8475 MaxVersion: VersionTLS13,
8476 Bugs: ProtocolBugs{
8477 CustomExtension: expectedContents,
8478 ExpectedCustomExtension: &expectedContents,
8479 },
8480 },
8481 flags: []string{flag},
8482 })
Adam Langley09505632015-07-30 18:10:13 -07008483
Steven Valdez2a070722017-03-25 20:54:16 -05008484 // 0-RTT is not currently supported with Custom Extensions.
8485 testCases = append(testCases, testCase{
8486 testType: testType,
8487 name: "CustomExtensions-" + suffix + "-EarlyData",
8488 config: Config{
8489 MaxVersion: VersionTLS13,
8490 Bugs: ProtocolBugs{
8491 CustomExtension: expectedContents,
8492 ExpectedCustomExtension: &expectedContents,
8493 },
8494 },
8495 shouldFail: true,
8496 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8497 flags: []string{flag, "-enable-early-data"},
8498 })
8499
Adam Langley09505632015-07-30 18:10:13 -07008500 // If the parse callback fails, the handshake should also fail.
8501 testCases = append(testCases, testCase{
8502 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008503 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008504 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008505 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008506 Bugs: ProtocolBugs{
8507 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07008508 ExpectedCustomExtension: &expectedContents,
8509 },
8510 },
David Benjamin399e7c92015-07-30 23:01:27 -04008511 flags: []string{flag},
8512 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008513 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8514 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008515 testCases = append(testCases, testCase{
8516 testType: testType,
8517 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
8518 config: Config{
8519 MaxVersion: VersionTLS13,
8520 Bugs: ProtocolBugs{
8521 CustomExtension: expectedContents + "foo",
8522 ExpectedCustomExtension: &expectedContents,
8523 },
8524 },
8525 flags: []string{flag},
8526 shouldFail: true,
8527 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8528 })
Adam Langley09505632015-07-30 18:10:13 -07008529
8530 // If the add callback fails, the handshake should also fail.
8531 testCases = append(testCases, testCase{
8532 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008533 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008534 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008535 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008536 Bugs: ProtocolBugs{
8537 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07008538 ExpectedCustomExtension: &expectedContents,
8539 },
8540 },
David Benjamin399e7c92015-07-30 23:01:27 -04008541 flags: []string{flag, "-custom-extension-fail-add"},
8542 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07008543 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8544 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008545 testCases = append(testCases, testCase{
8546 testType: testType,
8547 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
8548 config: Config{
8549 MaxVersion: VersionTLS13,
8550 Bugs: ProtocolBugs{
8551 CustomExtension: expectedContents,
8552 ExpectedCustomExtension: &expectedContents,
8553 },
8554 },
8555 flags: []string{flag, "-custom-extension-fail-add"},
8556 shouldFail: true,
8557 expectedError: ":CUSTOM_EXTENSION_ERROR:",
8558 })
Adam Langley09505632015-07-30 18:10:13 -07008559
8560 // If the add callback returns zero, no extension should be
8561 // added.
8562 skipCustomExtension := expectedContents
8563 if isClient {
8564 // For the case where the client skips sending the
8565 // custom extension, the server must not “echo” it.
8566 skipCustomExtension = ""
8567 }
8568 testCases = append(testCases, testCase{
8569 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04008570 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07008571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008572 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008573 Bugs: ProtocolBugs{
8574 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07008575 ExpectedCustomExtension: &emptyString,
8576 },
8577 },
8578 flags: []string{flag, "-custom-extension-skip"},
8579 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008580 testCases = append(testCases, testCase{
8581 testType: testType,
8582 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
8583 config: Config{
8584 MaxVersion: VersionTLS13,
8585 Bugs: ProtocolBugs{
8586 CustomExtension: skipCustomExtension,
8587 ExpectedCustomExtension: &emptyString,
8588 },
8589 },
8590 flags: []string{flag, "-custom-extension-skip"},
8591 })
Adam Langley09505632015-07-30 18:10:13 -07008592 }
8593
8594 // The custom extension add callback should not be called if the client
8595 // doesn't send the extension.
8596 testCases = append(testCases, testCase{
8597 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04008598 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07008599 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008600 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04008601 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07008602 ExpectedCustomExtension: &emptyString,
8603 },
8604 },
8605 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8606 })
Adam Langley2deb9842015-08-07 11:15:37 -07008607
Steven Valdez143e8b32016-07-11 13:19:03 -04008608 testCases = append(testCases, testCase{
8609 testType: serverTest,
8610 name: "CustomExtensions-NotCalled-Server-TLS13",
8611 config: Config{
8612 MaxVersion: VersionTLS13,
8613 Bugs: ProtocolBugs{
8614 ExpectedCustomExtension: &emptyString,
8615 },
8616 },
8617 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
8618 })
8619
Adam Langley2deb9842015-08-07 11:15:37 -07008620 // Test an unknown extension from the server.
8621 testCases = append(testCases, testCase{
8622 testType: clientTest,
8623 name: "UnknownExtension-Client",
8624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008625 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07008626 Bugs: ProtocolBugs{
8627 CustomExtension: expectedContents,
8628 },
8629 },
David Benjamin0c40a962016-08-01 12:05:50 -04008630 shouldFail: true,
8631 expectedError: ":UNEXPECTED_EXTENSION:",
8632 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07008633 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008634 testCases = append(testCases, testCase{
8635 testType: clientTest,
8636 name: "UnknownExtension-Client-TLS13",
8637 config: Config{
8638 MaxVersion: VersionTLS13,
8639 Bugs: ProtocolBugs{
8640 CustomExtension: expectedContents,
8641 },
8642 },
David Benjamin0c40a962016-08-01 12:05:50 -04008643 shouldFail: true,
8644 expectedError: ":UNEXPECTED_EXTENSION:",
8645 expectedLocalError: "remote error: unsupported extension",
8646 })
David Benjamin490469f2016-10-05 22:44:38 -04008647 testCases = append(testCases, testCase{
8648 testType: clientTest,
8649 name: "UnknownUnencryptedExtension-Client-TLS13",
8650 config: Config{
8651 MaxVersion: VersionTLS13,
8652 Bugs: ProtocolBugs{
8653 CustomUnencryptedExtension: expectedContents,
8654 },
8655 },
8656 shouldFail: true,
8657 expectedError: ":UNEXPECTED_EXTENSION:",
8658 // The shim must send an alert, but alerts at this point do not
8659 // get successfully decrypted by the runner.
8660 expectedLocalError: "local error: bad record MAC",
8661 })
8662 testCases = append(testCases, testCase{
8663 testType: clientTest,
8664 name: "UnexpectedUnencryptedExtension-Client-TLS13",
8665 config: Config{
8666 MaxVersion: VersionTLS13,
8667 Bugs: ProtocolBugs{
8668 SendUnencryptedALPN: "foo",
8669 },
8670 },
8671 flags: []string{
8672 "-advertise-alpn", "\x03foo\x03bar",
8673 },
8674 shouldFail: true,
8675 expectedError: ":UNEXPECTED_EXTENSION:",
8676 // The shim must send an alert, but alerts at this point do not
8677 // get successfully decrypted by the runner.
8678 expectedLocalError: "local error: bad record MAC",
8679 })
David Benjamin0c40a962016-08-01 12:05:50 -04008680
8681 // Test a known but unoffered extension from the server.
8682 testCases = append(testCases, testCase{
8683 testType: clientTest,
8684 name: "UnofferedExtension-Client",
8685 config: Config{
8686 MaxVersion: VersionTLS12,
8687 Bugs: ProtocolBugs{
8688 SendALPN: "alpn",
8689 },
8690 },
8691 shouldFail: true,
8692 expectedError: ":UNEXPECTED_EXTENSION:",
8693 expectedLocalError: "remote error: unsupported extension",
8694 })
8695 testCases = append(testCases, testCase{
8696 testType: clientTest,
8697 name: "UnofferedExtension-Client-TLS13",
8698 config: Config{
8699 MaxVersion: VersionTLS13,
8700 Bugs: ProtocolBugs{
8701 SendALPN: "alpn",
8702 },
8703 },
8704 shouldFail: true,
8705 expectedError: ":UNEXPECTED_EXTENSION:",
8706 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008707 })
Adam Langley09505632015-07-30 18:10:13 -07008708}
8709
David Benjaminb36a3952015-12-01 18:53:13 -05008710func addRSAClientKeyExchangeTests() {
8711 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8712 testCases = append(testCases, testCase{
8713 testType: serverTest,
8714 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8715 config: Config{
8716 // Ensure the ClientHello version and final
8717 // version are different, to detect if the
8718 // server uses the wrong one.
8719 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008720 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008721 Bugs: ProtocolBugs{
8722 BadRSAClientKeyExchange: bad,
8723 },
8724 },
8725 shouldFail: true,
8726 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8727 })
8728 }
David Benjamine63d9d72016-09-19 18:27:34 -04008729
8730 // The server must compare whatever was in ClientHello.version for the
8731 // RSA premaster.
8732 testCases = append(testCases, testCase{
8733 testType: serverTest,
8734 name: "SendClientVersion-RSA",
8735 config: Config{
8736 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8737 Bugs: ProtocolBugs{
8738 SendClientVersion: 0x1234,
8739 },
8740 },
8741 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8742 })
David Benjaminb36a3952015-12-01 18:53:13 -05008743}
8744
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008745var testCurves = []struct {
8746 name string
8747 id CurveID
8748}{
Adam Langley764ab982017-03-10 18:01:30 -08008749 {"P-224", CurveP224},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008750 {"P-256", CurveP256},
8751 {"P-384", CurveP384},
8752 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008753 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008754}
8755
Steven Valdez5440fe02016-07-18 12:40:30 -04008756const bogusCurve = 0x1234
8757
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008758func addCurveTests() {
8759 for _, curve := range testCurves {
8760 testCases = append(testCases, testCase{
8761 name: "CurveTest-Client-" + curve.name,
8762 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008763 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008764 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8765 CurvePreferences: []CurveID{curve.id},
8766 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008767 flags: []string{
8768 "-enable-all-curves",
8769 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8770 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008771 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008772 })
8773 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008774 name: "CurveTest-Client-" + curve.name + "-TLS13",
8775 config: Config{
8776 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008777 CurvePreferences: []CurveID{curve.id},
8778 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008779 flags: []string{
8780 "-enable-all-curves",
8781 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8782 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008783 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008784 })
8785 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008786 testType: serverTest,
8787 name: "CurveTest-Server-" + curve.name,
8788 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008789 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8791 CurvePreferences: []CurveID{curve.id},
8792 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008793 flags: []string{
8794 "-enable-all-curves",
8795 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8796 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008797 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008798 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008799 testCases = append(testCases, testCase{
8800 testType: serverTest,
8801 name: "CurveTest-Server-" + curve.name + "-TLS13",
8802 config: Config{
8803 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008804 CurvePreferences: []CurveID{curve.id},
8805 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008806 flags: []string{
8807 "-enable-all-curves",
8808 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8809 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008810 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008811 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008812 }
David Benjamin241ae832016-01-15 03:04:54 -05008813
8814 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008815 testCases = append(testCases, testCase{
8816 testType: serverTest,
8817 name: "UnknownCurve",
8818 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008819 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008820 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8821 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8822 },
8823 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008824
Steven Valdez803c77a2016-09-06 14:13:43 -04008825 // The server must be tolerant to bogus curves.
8826 testCases = append(testCases, testCase{
8827 testType: serverTest,
8828 name: "UnknownCurve-TLS13",
8829 config: Config{
8830 MaxVersion: VersionTLS13,
8831 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8832 },
8833 })
8834
David Benjamin4c3ddf72016-06-29 18:13:53 -04008835 // The server must not consider ECDHE ciphers when there are no
8836 // supported curves.
8837 testCases = append(testCases, testCase{
8838 testType: serverTest,
8839 name: "NoSupportedCurves",
8840 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008841 MaxVersion: VersionTLS12,
8842 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8843 Bugs: ProtocolBugs{
8844 NoSupportedCurves: true,
8845 },
8846 },
8847 shouldFail: true,
8848 expectedError: ":NO_SHARED_CIPHER:",
8849 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008850 testCases = append(testCases, testCase{
8851 testType: serverTest,
8852 name: "NoSupportedCurves-TLS13",
8853 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008854 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008855 Bugs: ProtocolBugs{
8856 NoSupportedCurves: true,
8857 },
8858 },
8859 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008860 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008861 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008862
8863 // The server must fall back to another cipher when there are no
8864 // supported curves.
8865 testCases = append(testCases, testCase{
8866 testType: serverTest,
8867 name: "NoCommonCurves",
8868 config: Config{
8869 MaxVersion: VersionTLS12,
8870 CipherSuites: []uint16{
8871 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008872 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008873 },
8874 CurvePreferences: []CurveID{CurveP224},
8875 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008876 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008877 })
8878
8879 // The client must reject bogus curves and disabled curves.
8880 testCases = append(testCases, testCase{
8881 name: "BadECDHECurve",
8882 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008883 MaxVersion: VersionTLS12,
8884 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8885 Bugs: ProtocolBugs{
8886 SendCurve: bogusCurve,
8887 },
8888 },
8889 shouldFail: true,
8890 expectedError: ":WRONG_CURVE:",
8891 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008892 testCases = append(testCases, testCase{
8893 name: "BadECDHECurve-TLS13",
8894 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008895 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008896 Bugs: ProtocolBugs{
8897 SendCurve: bogusCurve,
8898 },
8899 },
8900 shouldFail: true,
8901 expectedError: ":WRONG_CURVE:",
8902 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008903
8904 testCases = append(testCases, testCase{
8905 name: "UnsupportedCurve",
8906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008907 MaxVersion: VersionTLS12,
8908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8909 CurvePreferences: []CurveID{CurveP256},
8910 Bugs: ProtocolBugs{
8911 IgnorePeerCurvePreferences: true,
8912 },
8913 },
8914 flags: []string{"-p384-only"},
8915 shouldFail: true,
8916 expectedError: ":WRONG_CURVE:",
8917 })
8918
David Benjamin4f921572016-07-17 14:20:10 +02008919 testCases = append(testCases, testCase{
8920 // TODO(davidben): Add a TLS 1.3 version where
8921 // HelloRetryRequest requests an unsupported curve.
8922 name: "UnsupportedCurve-ServerHello-TLS13",
8923 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008924 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008925 CurvePreferences: []CurveID{CurveP384},
8926 Bugs: ProtocolBugs{
8927 SendCurve: CurveP256,
8928 },
8929 },
8930 flags: []string{"-p384-only"},
8931 shouldFail: true,
8932 expectedError: ":WRONG_CURVE:",
8933 })
8934
David Benjamin4c3ddf72016-06-29 18:13:53 -04008935 // Test invalid curve points.
8936 testCases = append(testCases, testCase{
8937 name: "InvalidECDHPoint-Client",
8938 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008939 MaxVersion: VersionTLS12,
8940 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8941 CurvePreferences: []CurveID{CurveP256},
8942 Bugs: ProtocolBugs{
8943 InvalidECDHPoint: true,
8944 },
8945 },
8946 shouldFail: true,
8947 expectedError: ":INVALID_ENCODING:",
8948 })
8949 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008950 name: "InvalidECDHPoint-Client-TLS13",
8951 config: Config{
8952 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008953 CurvePreferences: []CurveID{CurveP256},
8954 Bugs: ProtocolBugs{
8955 InvalidECDHPoint: true,
8956 },
8957 },
8958 shouldFail: true,
8959 expectedError: ":INVALID_ENCODING:",
8960 })
8961 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008962 testType: serverTest,
8963 name: "InvalidECDHPoint-Server",
8964 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008965 MaxVersion: VersionTLS12,
8966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8967 CurvePreferences: []CurveID{CurveP256},
8968 Bugs: ProtocolBugs{
8969 InvalidECDHPoint: true,
8970 },
8971 },
8972 shouldFail: true,
8973 expectedError: ":INVALID_ENCODING:",
8974 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008975 testCases = append(testCases, testCase{
8976 testType: serverTest,
8977 name: "InvalidECDHPoint-Server-TLS13",
8978 config: Config{
8979 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008980 CurvePreferences: []CurveID{CurveP256},
8981 Bugs: ProtocolBugs{
8982 InvalidECDHPoint: true,
8983 },
8984 },
8985 shouldFail: true,
8986 expectedError: ":INVALID_ENCODING:",
8987 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008988
8989 // The previous curve ID should be reported on TLS 1.2 resumption.
8990 testCases = append(testCases, testCase{
8991 name: "CurveID-Resume-Client",
8992 config: Config{
8993 MaxVersion: VersionTLS12,
8994 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8995 CurvePreferences: []CurveID{CurveX25519},
8996 },
8997 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8998 resumeSession: true,
8999 })
9000 testCases = append(testCases, testCase{
9001 testType: serverTest,
9002 name: "CurveID-Resume-Server",
9003 config: Config{
9004 MaxVersion: VersionTLS12,
9005 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
9006 CurvePreferences: []CurveID{CurveX25519},
9007 },
9008 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
9009 resumeSession: true,
9010 })
9011
9012 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
9013 // one should be reported.
9014 testCases = append(testCases, testCase{
9015 name: "CurveID-Resume-Client-TLS13",
9016 config: Config{
9017 MaxVersion: VersionTLS13,
9018 CurvePreferences: []CurveID{CurveX25519},
9019 },
9020 resumeConfig: &Config{
9021 MaxVersion: VersionTLS13,
9022 CurvePreferences: []CurveID{CurveP256},
9023 },
9024 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009025 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9026 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009027 },
9028 resumeSession: true,
9029 })
9030 testCases = append(testCases, testCase{
9031 testType: serverTest,
9032 name: "CurveID-Resume-Server-TLS13",
9033 config: Config{
9034 MaxVersion: VersionTLS13,
9035 CurvePreferences: []CurveID{CurveX25519},
9036 },
9037 resumeConfig: &Config{
9038 MaxVersion: VersionTLS13,
9039 CurvePreferences: []CurveID{CurveP256},
9040 },
9041 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -04009042 "-on-initial-expect-curve-id", strconv.Itoa(int(CurveX25519)),
9043 "-on-resume-expect-curve-id", strconv.Itoa(int(CurveP256)),
David Benjamin8a55ce42016-12-11 03:03:42 -05009044 },
9045 resumeSession: true,
9046 })
David Benjamina81967b2016-12-22 09:16:57 -05009047
9048 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
9049 testCases = append(testCases, testCase{
9050 name: "PointFormat-ServerHello-TLS12",
9051 config: Config{
9052 MaxVersion: VersionTLS12,
9053 Bugs: ProtocolBugs{
9054 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9055 },
9056 },
9057 })
9058 testCases = append(testCases, testCase{
9059 name: "PointFormat-EncryptedExtensions-TLS13",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 Bugs: ProtocolBugs{
9063 SendSupportedPointFormats: []byte{pointFormatUncompressed},
9064 },
9065 },
9066 shouldFail: true,
9067 expectedError: ":ERROR_PARSING_EXTENSION:",
9068 })
9069
9070 // Test that we tolerate unknown point formats, as long as
9071 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
9072 // check they are still functional.
9073 testCases = append(testCases, testCase{
9074 name: "PointFormat-Client-Tolerance",
9075 config: Config{
9076 MaxVersion: VersionTLS12,
9077 Bugs: ProtocolBugs{
9078 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9079 },
9080 },
9081 })
9082 testCases = append(testCases, testCase{
9083 testType: serverTest,
9084 name: "PointFormat-Server-Tolerance",
9085 config: Config{
9086 MaxVersion: VersionTLS12,
9087 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9088 Bugs: ProtocolBugs{
9089 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
9090 },
9091 },
9092 })
9093
9094 // Test TLS 1.2 does not require the point format extension to be
9095 // present.
9096 testCases = append(testCases, testCase{
9097 name: "PointFormat-Client-Missing",
9098 config: Config{
9099 MaxVersion: VersionTLS12,
9100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9101 Bugs: ProtocolBugs{
9102 SendSupportedPointFormats: []byte{},
9103 },
9104 },
9105 })
9106 testCases = append(testCases, testCase{
9107 testType: serverTest,
9108 name: "PointFormat-Server-Missing",
9109 config: Config{
9110 MaxVersion: VersionTLS12,
9111 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
9112 Bugs: ProtocolBugs{
9113 SendSupportedPointFormats: []byte{},
9114 },
9115 },
9116 })
9117
9118 // If the point format extension is present, uncompressed points must be
9119 // offered. BoringSSL requires this whether or not ECDHE is used.
9120 testCases = append(testCases, testCase{
9121 name: "PointFormat-Client-MissingUncompressed",
9122 config: Config{
9123 MaxVersion: VersionTLS12,
9124 Bugs: ProtocolBugs{
9125 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9126 },
9127 },
9128 shouldFail: true,
9129 expectedError: ":ERROR_PARSING_EXTENSION:",
9130 })
9131 testCases = append(testCases, testCase{
9132 testType: serverTest,
9133 name: "PointFormat-Server-MissingUncompressed",
9134 config: Config{
9135 MaxVersion: VersionTLS12,
9136 Bugs: ProtocolBugs{
9137 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
9138 },
9139 },
9140 shouldFail: true,
9141 expectedError: ":ERROR_PARSING_EXTENSION:",
9142 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009143}
9144
David Benjaminc9ae27c2016-06-24 22:56:37 -04009145func addTLS13RecordTests() {
9146 testCases = append(testCases, testCase{
9147 name: "TLS13-RecordPadding",
9148 config: Config{
9149 MaxVersion: VersionTLS13,
9150 MinVersion: VersionTLS13,
9151 Bugs: ProtocolBugs{
9152 RecordPadding: 10,
9153 },
9154 },
9155 })
9156
9157 testCases = append(testCases, testCase{
9158 name: "TLS13-EmptyRecords",
9159 config: Config{
9160 MaxVersion: VersionTLS13,
9161 MinVersion: VersionTLS13,
9162 Bugs: ProtocolBugs{
9163 OmitRecordContents: true,
9164 },
9165 },
9166 shouldFail: true,
9167 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9168 })
9169
9170 testCases = append(testCases, testCase{
9171 name: "TLS13-OnlyPadding",
9172 config: Config{
9173 MaxVersion: VersionTLS13,
9174 MinVersion: VersionTLS13,
9175 Bugs: ProtocolBugs{
9176 OmitRecordContents: true,
9177 RecordPadding: 10,
9178 },
9179 },
9180 shouldFail: true,
9181 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9182 })
9183
9184 testCases = append(testCases, testCase{
9185 name: "TLS13-WrongOuterRecord",
9186 config: Config{
9187 MaxVersion: VersionTLS13,
9188 MinVersion: VersionTLS13,
9189 Bugs: ProtocolBugs{
9190 OuterRecordType: recordTypeHandshake,
9191 },
9192 },
9193 shouldFail: true,
9194 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
9195 })
9196}
9197
Steven Valdez5b986082016-09-01 12:29:49 -04009198func addSessionTicketTests() {
9199 testCases = append(testCases, testCase{
9200 // In TLS 1.2 and below, empty NewSessionTicket messages
9201 // mean the server changed its mind on sending a ticket.
9202 name: "SendEmptySessionTicket",
9203 config: Config{
9204 MaxVersion: VersionTLS12,
9205 Bugs: ProtocolBugs{
9206 SendEmptySessionTicket: true,
9207 },
9208 },
9209 flags: []string{"-expect-no-session"},
9210 })
9211
9212 // Test that the server ignores unknown PSK modes.
9213 testCases = append(testCases, testCase{
9214 testType: serverTest,
9215 name: "TLS13-SendUnknownModeSessionTicket-Server",
9216 config: Config{
9217 MaxVersion: VersionTLS13,
9218 Bugs: ProtocolBugs{
9219 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04009220 },
9221 },
9222 resumeSession: true,
9223 expectedResumeVersion: VersionTLS13,
9224 })
9225
Steven Valdeza833c352016-11-01 13:39:36 -04009226 // Test that the server does not send session tickets with no matching key exchange mode.
9227 testCases = append(testCases, testCase{
9228 testType: serverTest,
9229 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
9230 config: Config{
9231 MaxVersion: VersionTLS13,
9232 Bugs: ProtocolBugs{
9233 SendPSKKeyExchangeModes: []byte{0x1a},
9234 ExpectNoNewSessionTicket: true,
9235 },
9236 },
9237 })
9238
9239 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04009240 testCases = append(testCases, testCase{
9241 testType: serverTest,
9242 name: "TLS13-SendBadKEModeSessionTicket-Server",
9243 config: Config{
9244 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04009245 },
9246 resumeConfig: &Config{
9247 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04009248 Bugs: ProtocolBugs{
9249 SendPSKKeyExchangeModes: []byte{0x1a},
9250 },
9251 },
9252 resumeSession: true,
9253 expectResumeRejected: true,
9254 })
9255
Steven Valdeza833c352016-11-01 13:39:36 -04009256 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04009257 testCases = append(testCases, testCase{
9258 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009259 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009260 config: Config{
9261 MaxVersion: VersionTLS13,
9262 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009263 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009264 },
9265 },
Steven Valdeza833c352016-11-01 13:39:36 -04009266 resumeSession: true,
9267 flags: []string{
9268 "-resumption-delay", "10",
9269 },
Steven Valdez5b986082016-09-01 12:29:49 -04009270 })
9271
Steven Valdeza833c352016-11-01 13:39:36 -04009272 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04009273 testCases = append(testCases, testCase{
9274 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04009275 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04009276 config: Config{
9277 MaxVersion: VersionTLS13,
9278 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04009279 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04009280 },
9281 },
Steven Valdeza833c352016-11-01 13:39:36 -04009282 resumeSession: true,
9283 shouldFail: true,
9284 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04009285 })
9286
David Benjamin35ac5b72017-03-03 15:05:56 -05009287 // Test that the server's ticket age skew reporting works.
9288 testCases = append(testCases, testCase{
9289 testType: serverTest,
9290 name: "TLS13-TicketAgeSkew-Forward",
9291 config: Config{
9292 MaxVersion: VersionTLS13,
9293 Bugs: ProtocolBugs{
9294 SendTicketAge: 15 * time.Second,
9295 },
9296 },
David Benjamin065d7332017-03-26 10:51:43 -05009297 resumeSession: true,
9298 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009299 flags: []string{
9300 "-resumption-delay", "10",
9301 "-expect-ticket-age-skew", "5",
9302 },
9303 })
9304 testCases = append(testCases, testCase{
9305 testType: serverTest,
9306 name: "TLS13-TicketAgeSkew-Backward",
9307 config: Config{
9308 MaxVersion: VersionTLS13,
9309 Bugs: ProtocolBugs{
9310 SendTicketAge: 5 * time.Second,
9311 },
9312 },
David Benjamin065d7332017-03-26 10:51:43 -05009313 resumeSession: true,
9314 resumeRenewedSession: true,
David Benjamin35ac5b72017-03-03 15:05:56 -05009315 flags: []string{
9316 "-resumption-delay", "10",
9317 "-expect-ticket-age-skew", "-5",
9318 },
9319 })
9320
Steven Valdez08b65f42016-12-07 15:29:45 -05009321 testCases = append(testCases, testCase{
9322 testType: clientTest,
9323 name: "TLS13-SendTicketEarlyDataInfo",
9324 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009325 MaxVersion: VersionTLS13,
9326 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05009327 },
9328 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05009329 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05009330 "-expect-early-data-info",
9331 },
9332 })
9333
David Benjamin9b160662017-01-25 19:53:43 -05009334 // Test that 0-RTT tickets are ignored in clients unless opted in.
9335 testCases = append(testCases, testCase{
9336 testType: clientTest,
9337 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
9338 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009339 MaxVersion: VersionTLS13,
9340 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05009341 },
9342 })
9343
Steven Valdez08b65f42016-12-07 15:29:45 -05009344 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05009345 testType: clientTest,
9346 name: "TLS13-DuplicateTicketEarlyDataInfo",
9347 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08009348 MaxVersion: VersionTLS13,
9349 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05009350 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05009351 DuplicateTicketEarlyDataInfo: true,
9352 },
9353 },
9354 shouldFail: true,
9355 expectedError: ":DUPLICATE_EXTENSION:",
9356 expectedLocalError: "remote error: illegal parameter",
9357 })
9358
9359 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05009360 testType: serverTest,
9361 name: "TLS13-ExpectTicketEarlyDataInfo",
9362 config: Config{
9363 MaxVersion: VersionTLS13,
9364 Bugs: ProtocolBugs{
9365 ExpectTicketEarlyDataInfo: true,
9366 },
9367 },
9368 flags: []string{
9369 "-enable-early-data",
9370 },
9371 })
David Benjamin17b30832017-01-28 14:00:32 -05009372
9373 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
9374 // is honored.
9375 testCases = append(testCases, testCase{
9376 testType: clientTest,
9377 name: "TLS13-HonorServerSessionTicketLifetime",
9378 config: Config{
9379 MaxVersion: VersionTLS13,
9380 Bugs: ProtocolBugs{
9381 SendTicketLifetime: 20 * time.Second,
9382 },
9383 },
9384 flags: []string{
9385 "-resumption-delay", "19",
9386 },
9387 resumeSession: true,
9388 })
9389 testCases = append(testCases, testCase{
9390 testType: clientTest,
9391 name: "TLS13-HonorServerSessionTicketLifetime-2",
9392 config: Config{
9393 MaxVersion: VersionTLS13,
9394 Bugs: ProtocolBugs{
9395 SendTicketLifetime: 20 * time.Second,
9396 // The client should not offer the expired session.
9397 ExpectNoTLS13PSK: true,
9398 },
9399 },
9400 flags: []string{
9401 "-resumption-delay", "21",
9402 },
David Benjamin023d4192017-02-06 13:49:07 -05009403 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05009404 expectResumeRejected: true,
9405 })
Steven Valdez5b986082016-09-01 12:29:49 -04009406}
9407
David Benjamin82261be2016-07-07 14:32:50 -07009408func addChangeCipherSpecTests() {
9409 // Test missing ChangeCipherSpecs.
9410 testCases = append(testCases, testCase{
9411 name: "SkipChangeCipherSpec-Client",
9412 config: Config{
9413 MaxVersion: VersionTLS12,
9414 Bugs: ProtocolBugs{
9415 SkipChangeCipherSpec: true,
9416 },
9417 },
9418 shouldFail: true,
9419 expectedError: ":UNEXPECTED_RECORD:",
9420 })
9421 testCases = append(testCases, testCase{
9422 testType: serverTest,
9423 name: "SkipChangeCipherSpec-Server",
9424 config: Config{
9425 MaxVersion: VersionTLS12,
9426 Bugs: ProtocolBugs{
9427 SkipChangeCipherSpec: true,
9428 },
9429 },
9430 shouldFail: true,
9431 expectedError: ":UNEXPECTED_RECORD:",
9432 })
9433 testCases = append(testCases, testCase{
9434 testType: serverTest,
9435 name: "SkipChangeCipherSpec-Server-NPN",
9436 config: Config{
9437 MaxVersion: VersionTLS12,
9438 NextProtos: []string{"bar"},
9439 Bugs: ProtocolBugs{
9440 SkipChangeCipherSpec: true,
9441 },
9442 },
9443 flags: []string{
9444 "-advertise-npn", "\x03foo\x03bar\x03baz",
9445 },
9446 shouldFail: true,
9447 expectedError: ":UNEXPECTED_RECORD:",
9448 })
9449
9450 // Test synchronization between the handshake and ChangeCipherSpec.
9451 // Partial post-CCS handshake messages before ChangeCipherSpec should be
9452 // rejected. Test both with and without handshake packing to handle both
9453 // when the partial post-CCS message is in its own record and when it is
9454 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07009455 for _, packed := range []bool{false, true} {
9456 var suffix string
9457 if packed {
9458 suffix = "-Packed"
9459 }
9460
9461 testCases = append(testCases, testCase{
9462 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
9463 config: Config{
9464 MaxVersion: VersionTLS12,
9465 Bugs: ProtocolBugs{
9466 FragmentAcrossChangeCipherSpec: true,
9467 PackHandshakeFlight: packed,
9468 },
9469 },
9470 shouldFail: true,
9471 expectedError: ":UNEXPECTED_RECORD:",
9472 })
9473 testCases = append(testCases, testCase{
9474 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
9475 config: Config{
9476 MaxVersion: VersionTLS12,
9477 },
9478 resumeSession: true,
9479 resumeConfig: &Config{
9480 MaxVersion: VersionTLS12,
9481 Bugs: ProtocolBugs{
9482 FragmentAcrossChangeCipherSpec: true,
9483 PackHandshakeFlight: packed,
9484 },
9485 },
9486 shouldFail: true,
9487 expectedError: ":UNEXPECTED_RECORD:",
9488 })
9489 testCases = append(testCases, testCase{
9490 testType: serverTest,
9491 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
9492 config: Config{
9493 MaxVersion: VersionTLS12,
9494 Bugs: ProtocolBugs{
9495 FragmentAcrossChangeCipherSpec: true,
9496 PackHandshakeFlight: packed,
9497 },
9498 },
9499 shouldFail: true,
9500 expectedError: ":UNEXPECTED_RECORD:",
9501 })
9502 testCases = append(testCases, testCase{
9503 testType: serverTest,
9504 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
9505 config: Config{
9506 MaxVersion: VersionTLS12,
9507 },
9508 resumeSession: true,
9509 resumeConfig: &Config{
9510 MaxVersion: VersionTLS12,
9511 Bugs: ProtocolBugs{
9512 FragmentAcrossChangeCipherSpec: true,
9513 PackHandshakeFlight: packed,
9514 },
9515 },
9516 shouldFail: true,
9517 expectedError: ":UNEXPECTED_RECORD:",
9518 })
9519 testCases = append(testCases, testCase{
9520 testType: serverTest,
9521 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
9522 config: Config{
9523 MaxVersion: VersionTLS12,
9524 NextProtos: []string{"bar"},
9525 Bugs: ProtocolBugs{
9526 FragmentAcrossChangeCipherSpec: true,
9527 PackHandshakeFlight: packed,
9528 },
9529 },
9530 flags: []string{
9531 "-advertise-npn", "\x03foo\x03bar\x03baz",
9532 },
9533 shouldFail: true,
9534 expectedError: ":UNEXPECTED_RECORD:",
9535 })
9536 }
9537
David Benjamin61672812016-07-14 23:10:43 -04009538 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
9539 // messages in the handshake queue. Do this by testing the server
9540 // reading the client Finished, reversing the flight so Finished comes
9541 // first.
9542 testCases = append(testCases, testCase{
9543 protocol: dtls,
9544 testType: serverTest,
9545 name: "SendUnencryptedFinished-DTLS",
9546 config: Config{
9547 MaxVersion: VersionTLS12,
9548 Bugs: ProtocolBugs{
9549 SendUnencryptedFinished: true,
9550 ReverseHandshakeFragments: true,
9551 },
9552 },
9553 shouldFail: true,
9554 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9555 })
9556
Steven Valdez143e8b32016-07-11 13:19:03 -04009557 // Test synchronization between encryption changes and the handshake in
9558 // TLS 1.3, where ChangeCipherSpec is implicit.
9559 testCases = append(testCases, testCase{
9560 name: "PartialEncryptedExtensionsWithServerHello",
9561 config: Config{
9562 MaxVersion: VersionTLS13,
9563 Bugs: ProtocolBugs{
9564 PartialEncryptedExtensionsWithServerHello: true,
9565 },
9566 },
9567 shouldFail: true,
9568 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9569 })
9570 testCases = append(testCases, testCase{
9571 testType: serverTest,
9572 name: "PartialClientFinishedWithClientHello",
9573 config: Config{
9574 MaxVersion: VersionTLS13,
9575 Bugs: ProtocolBugs{
9576 PartialClientFinishedWithClientHello: true,
9577 },
9578 },
9579 shouldFail: true,
9580 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
9581 })
9582
David Benjamin82261be2016-07-07 14:32:50 -07009583 // Test that early ChangeCipherSpecs are handled correctly.
9584 testCases = append(testCases, testCase{
9585 testType: serverTest,
9586 name: "EarlyChangeCipherSpec-server-1",
9587 config: Config{
9588 MaxVersion: VersionTLS12,
9589 Bugs: ProtocolBugs{
9590 EarlyChangeCipherSpec: 1,
9591 },
9592 },
9593 shouldFail: true,
9594 expectedError: ":UNEXPECTED_RECORD:",
9595 })
9596 testCases = append(testCases, testCase{
9597 testType: serverTest,
9598 name: "EarlyChangeCipherSpec-server-2",
9599 config: Config{
9600 MaxVersion: VersionTLS12,
9601 Bugs: ProtocolBugs{
9602 EarlyChangeCipherSpec: 2,
9603 },
9604 },
9605 shouldFail: true,
9606 expectedError: ":UNEXPECTED_RECORD:",
9607 })
9608 testCases = append(testCases, testCase{
9609 protocol: dtls,
9610 name: "StrayChangeCipherSpec",
9611 config: Config{
9612 // TODO(davidben): Once DTLS 1.3 exists, test
9613 // that stray ChangeCipherSpec messages are
9614 // rejected.
9615 MaxVersion: VersionTLS12,
9616 Bugs: ProtocolBugs{
9617 StrayChangeCipherSpec: true,
9618 },
9619 },
9620 })
9621
9622 // Test that the contents of ChangeCipherSpec are checked.
9623 testCases = append(testCases, testCase{
9624 name: "BadChangeCipherSpec-1",
9625 config: Config{
9626 MaxVersion: VersionTLS12,
9627 Bugs: ProtocolBugs{
9628 BadChangeCipherSpec: []byte{2},
9629 },
9630 },
9631 shouldFail: true,
9632 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9633 })
9634 testCases = append(testCases, testCase{
9635 name: "BadChangeCipherSpec-2",
9636 config: Config{
9637 MaxVersion: VersionTLS12,
9638 Bugs: ProtocolBugs{
9639 BadChangeCipherSpec: []byte{1, 1},
9640 },
9641 },
9642 shouldFail: true,
9643 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9644 })
9645 testCases = append(testCases, testCase{
9646 protocol: dtls,
9647 name: "BadChangeCipherSpec-DTLS-1",
9648 config: Config{
9649 MaxVersion: VersionTLS12,
9650 Bugs: ProtocolBugs{
9651 BadChangeCipherSpec: []byte{2},
9652 },
9653 },
9654 shouldFail: true,
9655 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9656 })
9657 testCases = append(testCases, testCase{
9658 protocol: dtls,
9659 name: "BadChangeCipherSpec-DTLS-2",
9660 config: Config{
9661 MaxVersion: VersionTLS12,
9662 Bugs: ProtocolBugs{
9663 BadChangeCipherSpec: []byte{1, 1},
9664 },
9665 },
9666 shouldFail: true,
9667 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
9668 })
9669}
9670
David Benjamincd2c8062016-09-09 11:28:16 -04009671type perMessageTest struct {
9672 messageType uint8
9673 test testCase
9674}
9675
9676// makePerMessageTests returns a series of test templates which cover each
9677// message in the TLS handshake. These may be used with bugs like
9678// WrongMessageType to fully test a per-message bug.
9679func makePerMessageTests() []perMessageTest {
9680 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009681 for _, protocol := range []protocol{tls, dtls} {
9682 var suffix string
9683 if protocol == dtls {
9684 suffix = "-DTLS"
9685 }
9686
David Benjamincd2c8062016-09-09 11:28:16 -04009687 ret = append(ret, perMessageTest{
9688 messageType: typeClientHello,
9689 test: testCase{
9690 protocol: protocol,
9691 testType: serverTest,
9692 name: "ClientHello" + suffix,
9693 config: Config{
9694 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009695 },
9696 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009697 })
9698
9699 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009700 ret = append(ret, perMessageTest{
9701 messageType: typeHelloVerifyRequest,
9702 test: testCase{
9703 protocol: protocol,
9704 name: "HelloVerifyRequest" + suffix,
9705 config: Config{
9706 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009707 },
9708 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009709 })
9710 }
9711
David Benjamincd2c8062016-09-09 11:28:16 -04009712 ret = append(ret, perMessageTest{
9713 messageType: typeServerHello,
9714 test: testCase{
9715 protocol: protocol,
9716 name: "ServerHello" + suffix,
9717 config: Config{
9718 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009719 },
9720 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009721 })
9722
David Benjamincd2c8062016-09-09 11:28:16 -04009723 ret = append(ret, perMessageTest{
9724 messageType: typeCertificate,
9725 test: testCase{
9726 protocol: protocol,
9727 name: "ServerCertificate" + suffix,
9728 config: Config{
9729 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009730 },
9731 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009732 })
9733
David Benjamincd2c8062016-09-09 11:28:16 -04009734 ret = append(ret, perMessageTest{
9735 messageType: typeCertificateStatus,
9736 test: testCase{
9737 protocol: protocol,
9738 name: "CertificateStatus" + suffix,
9739 config: Config{
9740 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009741 },
David Benjamincd2c8062016-09-09 11:28:16 -04009742 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009743 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009744 })
9745
David Benjamincd2c8062016-09-09 11:28:16 -04009746 ret = append(ret, perMessageTest{
9747 messageType: typeServerKeyExchange,
9748 test: testCase{
9749 protocol: protocol,
9750 name: "ServerKeyExchange" + suffix,
9751 config: Config{
9752 MaxVersion: VersionTLS12,
9753 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009754 },
9755 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009756 })
9757
David Benjamincd2c8062016-09-09 11:28:16 -04009758 ret = append(ret, perMessageTest{
9759 messageType: typeCertificateRequest,
9760 test: testCase{
9761 protocol: protocol,
9762 name: "CertificateRequest" + suffix,
9763 config: Config{
9764 MaxVersion: VersionTLS12,
9765 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009766 },
9767 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009768 })
9769
David Benjamincd2c8062016-09-09 11:28:16 -04009770 ret = append(ret, perMessageTest{
9771 messageType: typeServerHelloDone,
9772 test: testCase{
9773 protocol: protocol,
9774 name: "ServerHelloDone" + suffix,
9775 config: Config{
9776 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009777 },
9778 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009779 })
9780
David Benjamincd2c8062016-09-09 11:28:16 -04009781 ret = append(ret, perMessageTest{
9782 messageType: typeCertificate,
9783 test: testCase{
9784 testType: serverTest,
9785 protocol: protocol,
9786 name: "ClientCertificate" + suffix,
9787 config: Config{
9788 Certificates: []Certificate{rsaCertificate},
9789 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009790 },
David Benjamincd2c8062016-09-09 11:28:16 -04009791 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009792 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009793 })
9794
David Benjamincd2c8062016-09-09 11:28:16 -04009795 ret = append(ret, perMessageTest{
9796 messageType: typeCertificateVerify,
9797 test: testCase{
9798 testType: serverTest,
9799 protocol: protocol,
9800 name: "CertificateVerify" + suffix,
9801 config: Config{
9802 Certificates: []Certificate{rsaCertificate},
9803 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009804 },
David Benjamincd2c8062016-09-09 11:28:16 -04009805 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009806 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009807 })
9808
David Benjamincd2c8062016-09-09 11:28:16 -04009809 ret = append(ret, perMessageTest{
9810 messageType: typeClientKeyExchange,
9811 test: testCase{
9812 testType: serverTest,
9813 protocol: protocol,
9814 name: "ClientKeyExchange" + suffix,
9815 config: Config{
9816 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009817 },
9818 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009819 })
9820
9821 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009822 ret = append(ret, perMessageTest{
9823 messageType: typeNextProtocol,
9824 test: testCase{
9825 testType: serverTest,
9826 protocol: protocol,
9827 name: "NextProtocol" + suffix,
9828 config: Config{
9829 MaxVersion: VersionTLS12,
9830 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009831 },
David Benjamincd2c8062016-09-09 11:28:16 -04009832 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009833 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009834 })
9835
David Benjamincd2c8062016-09-09 11:28:16 -04009836 ret = append(ret, perMessageTest{
9837 messageType: typeChannelID,
9838 test: testCase{
9839 testType: serverTest,
9840 protocol: protocol,
9841 name: "ChannelID" + suffix,
9842 config: Config{
9843 MaxVersion: VersionTLS12,
9844 ChannelID: channelIDKey,
9845 },
9846 flags: []string{
9847 "-expect-channel-id",
9848 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009849 },
9850 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009851 })
9852 }
9853
David Benjamincd2c8062016-09-09 11:28:16 -04009854 ret = append(ret, perMessageTest{
9855 messageType: typeFinished,
9856 test: testCase{
9857 testType: serverTest,
9858 protocol: protocol,
9859 name: "ClientFinished" + suffix,
9860 config: Config{
9861 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009862 },
9863 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009864 })
9865
David Benjamincd2c8062016-09-09 11:28:16 -04009866 ret = append(ret, perMessageTest{
9867 messageType: typeNewSessionTicket,
9868 test: testCase{
9869 protocol: protocol,
9870 name: "NewSessionTicket" + suffix,
9871 config: Config{
9872 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009873 },
9874 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009875 })
9876
David Benjamincd2c8062016-09-09 11:28:16 -04009877 ret = append(ret, perMessageTest{
9878 messageType: typeFinished,
9879 test: testCase{
9880 protocol: protocol,
9881 name: "ServerFinished" + suffix,
9882 config: Config{
9883 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009884 },
9885 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009886 })
9887
9888 }
David Benjamincd2c8062016-09-09 11:28:16 -04009889
9890 ret = append(ret, perMessageTest{
9891 messageType: typeClientHello,
9892 test: testCase{
9893 testType: serverTest,
9894 name: "TLS13-ClientHello",
9895 config: Config{
9896 MaxVersion: VersionTLS13,
9897 },
9898 },
9899 })
9900
9901 ret = append(ret, perMessageTest{
9902 messageType: typeServerHello,
9903 test: testCase{
9904 name: "TLS13-ServerHello",
9905 config: Config{
9906 MaxVersion: VersionTLS13,
9907 },
9908 },
9909 })
9910
9911 ret = append(ret, perMessageTest{
9912 messageType: typeEncryptedExtensions,
9913 test: testCase{
9914 name: "TLS13-EncryptedExtensions",
9915 config: Config{
9916 MaxVersion: VersionTLS13,
9917 },
9918 },
9919 })
9920
9921 ret = append(ret, perMessageTest{
9922 messageType: typeCertificateRequest,
9923 test: testCase{
9924 name: "TLS13-CertificateRequest",
9925 config: Config{
9926 MaxVersion: VersionTLS13,
9927 ClientAuth: RequireAnyClientCert,
9928 },
9929 },
9930 })
9931
9932 ret = append(ret, perMessageTest{
9933 messageType: typeCertificate,
9934 test: testCase{
9935 name: "TLS13-ServerCertificate",
9936 config: Config{
9937 MaxVersion: VersionTLS13,
9938 },
9939 },
9940 })
9941
9942 ret = append(ret, perMessageTest{
9943 messageType: typeCertificateVerify,
9944 test: testCase{
9945 name: "TLS13-ServerCertificateVerify",
9946 config: Config{
9947 MaxVersion: VersionTLS13,
9948 },
9949 },
9950 })
9951
9952 ret = append(ret, perMessageTest{
9953 messageType: typeFinished,
9954 test: testCase{
9955 name: "TLS13-ServerFinished",
9956 config: Config{
9957 MaxVersion: VersionTLS13,
9958 },
9959 },
9960 })
9961
9962 ret = append(ret, perMessageTest{
9963 messageType: typeCertificate,
9964 test: testCase{
9965 testType: serverTest,
9966 name: "TLS13-ClientCertificate",
9967 config: Config{
9968 Certificates: []Certificate{rsaCertificate},
9969 MaxVersion: VersionTLS13,
9970 },
9971 flags: []string{"-require-any-client-certificate"},
9972 },
9973 })
9974
9975 ret = append(ret, perMessageTest{
9976 messageType: typeCertificateVerify,
9977 test: testCase{
9978 testType: serverTest,
9979 name: "TLS13-ClientCertificateVerify",
9980 config: Config{
9981 Certificates: []Certificate{rsaCertificate},
9982 MaxVersion: VersionTLS13,
9983 },
9984 flags: []string{"-require-any-client-certificate"},
9985 },
9986 })
9987
9988 ret = append(ret, perMessageTest{
9989 messageType: typeFinished,
9990 test: testCase{
9991 testType: serverTest,
9992 name: "TLS13-ClientFinished",
9993 config: Config{
9994 MaxVersion: VersionTLS13,
9995 },
9996 },
9997 })
9998
9999 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -040010000}
10001
David Benjamincd2c8062016-09-09 11:28:16 -040010002func addWrongMessageTypeTests() {
10003 for _, t := range makePerMessageTests() {
10004 t.test.name = "WrongMessageType-" + t.test.name
10005 t.test.config.Bugs.SendWrongMessageType = t.messageType
10006 t.test.shouldFail = true
10007 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
10008 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -040010009
David Benjamincd2c8062016-09-09 11:28:16 -040010010 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10011 // In TLS 1.3, a bad ServerHello means the client sends
10012 // an unencrypted alert while the server expects
10013 // encryption, so the alert is not readable by runner.
10014 t.test.expectedLocalError = "local error: bad record MAC"
10015 }
Steven Valdez143e8b32016-07-11 13:19:03 -040010016
David Benjamincd2c8062016-09-09 11:28:16 -040010017 testCases = append(testCases, t.test)
10018 }
David Benjaminebacdee2017-04-08 11:00:45 -040010019
10020 // The processing order for TLS 1.3 version negotiation is such that one
10021 // may accidentally accept a HelloRetryRequest in lieu of ServerHello in
10022 // TLS 1.2. Test that we do not do this.
10023 testCases = append(testCases, testCase{
10024 name: "SendServerHelloAsHelloRetryRequest",
10025 config: Config{
10026 MaxVersion: VersionTLS12,
10027 Bugs: ProtocolBugs{
10028 SendServerHelloAsHelloRetryRequest: true,
10029 },
10030 },
10031 shouldFail: true,
10032 expectedError: ":UNEXPECTED_MESSAGE:",
10033 expectedLocalError: "remote error: unexpected message",
10034 })
Steven Valdez143e8b32016-07-11 13:19:03 -040010035}
10036
David Benjamin639846e2016-09-09 11:41:18 -040010037func addTrailingMessageDataTests() {
10038 for _, t := range makePerMessageTests() {
10039 t.test.name = "TrailingMessageData-" + t.test.name
10040 t.test.config.Bugs.SendTrailingMessageData = t.messageType
10041 t.test.shouldFail = true
10042 t.test.expectedError = ":DECODE_ERROR:"
10043 t.test.expectedLocalError = "remote error: error decoding message"
10044
10045 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
10046 // In TLS 1.3, a bad ServerHello means the client sends
10047 // an unencrypted alert while the server expects
10048 // encryption, so the alert is not readable by runner.
10049 t.test.expectedLocalError = "local error: bad record MAC"
10050 }
10051
10052 if t.messageType == typeFinished {
10053 // Bad Finished messages read as the verify data having
10054 // the wrong length.
10055 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
10056 t.test.expectedLocalError = "remote error: error decrypting message"
10057 }
10058
10059 testCases = append(testCases, t.test)
10060 }
10061}
10062
Steven Valdez143e8b32016-07-11 13:19:03 -040010063func addTLS13HandshakeTests() {
10064 testCases = append(testCases, testCase{
10065 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -040010066 name: "NegotiatePSKResumption-TLS13",
10067 config: Config{
10068 MaxVersion: VersionTLS13,
10069 Bugs: ProtocolBugs{
10070 NegotiatePSKResumption: true,
10071 },
10072 },
10073 resumeSession: true,
10074 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010075 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -040010076 })
10077
10078 testCases = append(testCases, testCase{
10079 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -040010080 name: "MissingKeyShare-Client",
10081 config: Config{
10082 MaxVersion: VersionTLS13,
10083 Bugs: ProtocolBugs{
10084 MissingKeyShare: true,
10085 },
10086 },
10087 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -050010088 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010089 })
10090
10091 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010092 testType: serverTest,
10093 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -040010094 config: Config{
10095 MaxVersion: VersionTLS13,
10096 Bugs: ProtocolBugs{
10097 MissingKeyShare: true,
10098 },
10099 },
10100 shouldFail: true,
10101 expectedError: ":MISSING_KEY_SHARE:",
10102 })
10103
10104 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010105 testType: serverTest,
10106 name: "DuplicateKeyShares",
10107 config: Config{
10108 MaxVersion: VersionTLS13,
10109 Bugs: ProtocolBugs{
10110 DuplicateKeyShares: true,
10111 },
10112 },
David Benjamin7e1f9842016-09-20 19:24:40 -040010113 shouldFail: true,
10114 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -040010115 })
10116
10117 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010118 testType: serverTest,
10119 name: "SkipEarlyData",
10120 config: Config{
10121 MaxVersion: VersionTLS13,
10122 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010123 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010124 },
10125 },
10126 })
10127
10128 testCases = append(testCases, testCase{
10129 testType: serverTest,
10130 name: "SkipEarlyData-OmitEarlyDataExtension",
10131 config: Config{
10132 MaxVersion: VersionTLS13,
10133 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010134 SendFakeEarlyDataLength: 4,
10135 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010136 },
10137 },
10138 shouldFail: true,
10139 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10140 })
10141
10142 testCases = append(testCases, testCase{
10143 testType: serverTest,
10144 name: "SkipEarlyData-TooMuchData",
10145 config: Config{
10146 MaxVersion: VersionTLS13,
10147 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010148 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010149 },
10150 },
10151 shouldFail: true,
10152 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10153 })
10154
10155 testCases = append(testCases, testCase{
10156 testType: serverTest,
10157 name: "SkipEarlyData-Interleaved",
10158 config: Config{
10159 MaxVersion: VersionTLS13,
10160 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010161 SendFakeEarlyDataLength: 4,
10162 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010163 },
10164 },
10165 shouldFail: true,
10166 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
10167 })
10168
10169 testCases = append(testCases, testCase{
10170 testType: serverTest,
10171 name: "SkipEarlyData-EarlyDataInTLS12",
10172 config: Config{
10173 MaxVersion: VersionTLS13,
10174 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010175 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010176 },
10177 },
10178 shouldFail: true,
10179 expectedError: ":UNEXPECTED_RECORD:",
10180 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
10181 })
10182
10183 testCases = append(testCases, testCase{
10184 testType: serverTest,
10185 name: "SkipEarlyData-HRR",
10186 config: Config{
10187 MaxVersion: VersionTLS13,
10188 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010189 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010190 },
10191 DefaultCurves: []CurveID{},
10192 },
10193 })
10194
10195 testCases = append(testCases, testCase{
10196 testType: serverTest,
10197 name: "SkipEarlyData-HRR-Interleaved",
10198 config: Config{
10199 MaxVersion: VersionTLS13,
10200 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010201 SendFakeEarlyDataLength: 4,
10202 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010203 },
10204 DefaultCurves: []CurveID{},
10205 },
10206 shouldFail: true,
10207 expectedError: ":UNEXPECTED_RECORD:",
10208 })
10209
10210 testCases = append(testCases, testCase{
10211 testType: serverTest,
10212 name: "SkipEarlyData-HRR-TooMuchData",
10213 config: Config{
10214 MaxVersion: VersionTLS13,
10215 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010216 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010217 },
10218 DefaultCurves: []CurveID{},
10219 },
10220 shouldFail: true,
10221 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
10222 })
10223
10224 // Test that skipping early data looking for cleartext correctly
10225 // processes an alert record.
10226 testCases = append(testCases, testCase{
10227 testType: serverTest,
10228 name: "SkipEarlyData-HRR-FatalAlert",
10229 config: Config{
10230 MaxVersion: VersionTLS13,
10231 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010232 SendEarlyAlert: true,
10233 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -050010234 },
10235 DefaultCurves: []CurveID{},
10236 },
10237 shouldFail: true,
10238 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
10239 })
10240
10241 testCases = append(testCases, testCase{
10242 testType: serverTest,
10243 name: "SkipEarlyData-SecondClientHelloEarlyData",
10244 config: Config{
10245 MaxVersion: VersionTLS13,
10246 Bugs: ProtocolBugs{
10247 SendEarlyDataOnSecondClientHello: true,
10248 },
10249 DefaultCurves: []CurveID{},
10250 },
10251 shouldFail: true,
10252 expectedLocalError: "remote error: bad record MAC",
10253 })
10254
10255 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -040010256 testType: clientTest,
10257 name: "EmptyEncryptedExtensions",
10258 config: Config{
10259 MaxVersion: VersionTLS13,
10260 Bugs: ProtocolBugs{
10261 EmptyEncryptedExtensions: true,
10262 },
10263 },
10264 shouldFail: true,
10265 expectedLocalError: "remote error: error decoding message",
10266 })
10267
10268 testCases = append(testCases, testCase{
10269 testType: clientTest,
10270 name: "EncryptedExtensionsWithKeyShare",
10271 config: Config{
10272 MaxVersion: VersionTLS13,
10273 Bugs: ProtocolBugs{
10274 EncryptedExtensionsWithKeyShare: true,
10275 },
10276 },
10277 shouldFail: true,
10278 expectedLocalError: "remote error: unsupported extension",
10279 })
Steven Valdez5440fe02016-07-18 12:40:30 -040010280
10281 testCases = append(testCases, testCase{
10282 testType: serverTest,
10283 name: "SendHelloRetryRequest",
10284 config: Config{
10285 MaxVersion: VersionTLS13,
10286 // Require a HelloRetryRequest for every curve.
10287 DefaultCurves: []CurveID{},
10288 },
10289 expectedCurveID: CurveX25519,
10290 })
10291
10292 testCases = append(testCases, testCase{
10293 testType: serverTest,
10294 name: "SendHelloRetryRequest-2",
10295 config: Config{
10296 MaxVersion: VersionTLS13,
10297 DefaultCurves: []CurveID{CurveP384},
10298 },
10299 // Although the ClientHello did not predict our preferred curve,
10300 // we always select it whether it is predicted or not.
10301 expectedCurveID: CurveX25519,
10302 })
10303
10304 testCases = append(testCases, testCase{
10305 name: "UnknownCurve-HelloRetryRequest",
10306 config: Config{
10307 MaxVersion: VersionTLS13,
10308 // P-384 requires HelloRetryRequest in BoringSSL.
10309 CurvePreferences: []CurveID{CurveP384},
10310 Bugs: ProtocolBugs{
10311 SendHelloRetryRequestCurve: bogusCurve,
10312 },
10313 },
10314 shouldFail: true,
10315 expectedError: ":WRONG_CURVE:",
10316 })
10317
10318 testCases = append(testCases, testCase{
10319 name: "DisabledCurve-HelloRetryRequest",
10320 config: Config{
10321 MaxVersion: VersionTLS13,
10322 CurvePreferences: []CurveID{CurveP256},
10323 Bugs: ProtocolBugs{
10324 IgnorePeerCurvePreferences: true,
10325 },
10326 },
10327 flags: []string{"-p384-only"},
10328 shouldFail: true,
10329 expectedError: ":WRONG_CURVE:",
10330 })
10331
10332 testCases = append(testCases, testCase{
10333 name: "UnnecessaryHelloRetryRequest",
10334 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -040010335 MaxVersion: VersionTLS13,
10336 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -040010337 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -040010338 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -040010339 },
10340 },
10341 shouldFail: true,
10342 expectedError: ":WRONG_CURVE:",
10343 })
10344
10345 testCases = append(testCases, testCase{
10346 name: "SecondHelloRetryRequest",
10347 config: Config{
10348 MaxVersion: VersionTLS13,
10349 // P-384 requires HelloRetryRequest in BoringSSL.
10350 CurvePreferences: []CurveID{CurveP384},
10351 Bugs: ProtocolBugs{
10352 SecondHelloRetryRequest: true,
10353 },
10354 },
10355 shouldFail: true,
10356 expectedError: ":UNEXPECTED_MESSAGE:",
10357 })
10358
10359 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -040010360 name: "HelloRetryRequest-Empty",
10361 config: Config{
10362 MaxVersion: VersionTLS13,
10363 Bugs: ProtocolBugs{
10364 AlwaysSendHelloRetryRequest: true,
10365 },
10366 },
10367 shouldFail: true,
10368 expectedError: ":DECODE_ERROR:",
10369 })
10370
10371 testCases = append(testCases, testCase{
10372 name: "HelloRetryRequest-DuplicateCurve",
10373 config: Config{
10374 MaxVersion: VersionTLS13,
10375 // P-384 requires a HelloRetryRequest against BoringSSL's default
10376 // configuration. Assert this ExpectMissingKeyShare.
10377 CurvePreferences: []CurveID{CurveP384},
10378 Bugs: ProtocolBugs{
10379 ExpectMissingKeyShare: true,
10380 DuplicateHelloRetryRequestExtensions: true,
10381 },
10382 },
10383 shouldFail: true,
10384 expectedError: ":DUPLICATE_EXTENSION:",
10385 expectedLocalError: "remote error: illegal parameter",
10386 })
10387
10388 testCases = append(testCases, testCase{
10389 name: "HelloRetryRequest-Cookie",
10390 config: Config{
10391 MaxVersion: VersionTLS13,
10392 Bugs: ProtocolBugs{
10393 SendHelloRetryRequestCookie: []byte("cookie"),
10394 },
10395 },
10396 })
10397
10398 testCases = append(testCases, testCase{
10399 name: "HelloRetryRequest-DuplicateCookie",
10400 config: Config{
10401 MaxVersion: VersionTLS13,
10402 Bugs: ProtocolBugs{
10403 SendHelloRetryRequestCookie: []byte("cookie"),
10404 DuplicateHelloRetryRequestExtensions: true,
10405 },
10406 },
10407 shouldFail: true,
10408 expectedError: ":DUPLICATE_EXTENSION:",
10409 expectedLocalError: "remote error: illegal parameter",
10410 })
10411
10412 testCases = append(testCases, testCase{
10413 name: "HelloRetryRequest-EmptyCookie",
10414 config: Config{
10415 MaxVersion: VersionTLS13,
10416 Bugs: ProtocolBugs{
10417 SendHelloRetryRequestCookie: []byte{},
10418 },
10419 },
10420 shouldFail: true,
10421 expectedError: ":DECODE_ERROR:",
10422 })
10423
10424 testCases = append(testCases, testCase{
10425 name: "HelloRetryRequest-Cookie-Curve",
10426 config: Config{
10427 MaxVersion: VersionTLS13,
10428 // P-384 requires HelloRetryRequest in BoringSSL.
10429 CurvePreferences: []CurveID{CurveP384},
10430 Bugs: ProtocolBugs{
10431 SendHelloRetryRequestCookie: []byte("cookie"),
10432 ExpectMissingKeyShare: true,
10433 },
10434 },
10435 })
10436
10437 testCases = append(testCases, testCase{
10438 name: "HelloRetryRequest-Unknown",
10439 config: Config{
10440 MaxVersion: VersionTLS13,
10441 Bugs: ProtocolBugs{
10442 CustomHelloRetryRequestExtension: "extension",
10443 },
10444 },
10445 shouldFail: true,
10446 expectedError: ":UNEXPECTED_EXTENSION:",
10447 expectedLocalError: "remote error: unsupported extension",
10448 })
10449
10450 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -040010451 testType: serverTest,
10452 name: "SecondClientHelloMissingKeyShare",
10453 config: Config{
10454 MaxVersion: VersionTLS13,
10455 DefaultCurves: []CurveID{},
10456 Bugs: ProtocolBugs{
10457 SecondClientHelloMissingKeyShare: true,
10458 },
10459 },
10460 shouldFail: true,
10461 expectedError: ":MISSING_KEY_SHARE:",
10462 })
10463
10464 testCases = append(testCases, testCase{
10465 testType: serverTest,
10466 name: "SecondClientHelloWrongCurve",
10467 config: Config{
10468 MaxVersion: VersionTLS13,
10469 DefaultCurves: []CurveID{},
10470 Bugs: ProtocolBugs{
10471 MisinterpretHelloRetryRequestCurve: CurveP521,
10472 },
10473 },
10474 shouldFail: true,
10475 expectedError: ":WRONG_CURVE:",
10476 })
10477
10478 testCases = append(testCases, testCase{
10479 name: "HelloRetryRequestVersionMismatch",
10480 config: Config{
10481 MaxVersion: VersionTLS13,
10482 // P-384 requires HelloRetryRequest in BoringSSL.
10483 CurvePreferences: []CurveID{CurveP384},
10484 Bugs: ProtocolBugs{
10485 SendServerHelloVersion: 0x0305,
10486 },
10487 },
10488 shouldFail: true,
10489 expectedError: ":WRONG_VERSION_NUMBER:",
10490 })
10491
10492 testCases = append(testCases, testCase{
10493 name: "HelloRetryRequestCurveMismatch",
10494 config: Config{
10495 MaxVersion: VersionTLS13,
10496 // P-384 requires HelloRetryRequest in BoringSSL.
10497 CurvePreferences: []CurveID{CurveP384},
10498 Bugs: ProtocolBugs{
10499 // Send P-384 (correct) in the HelloRetryRequest.
10500 SendHelloRetryRequestCurve: CurveP384,
10501 // But send P-256 in the ServerHello.
10502 SendCurve: CurveP256,
10503 },
10504 },
10505 shouldFail: true,
10506 expectedError: ":WRONG_CURVE:",
10507 })
10508
10509 // Test the server selecting a curve that requires a HelloRetryRequest
10510 // without sending it.
10511 testCases = append(testCases, testCase{
10512 name: "SkipHelloRetryRequest",
10513 config: Config{
10514 MaxVersion: VersionTLS13,
10515 // P-384 requires HelloRetryRequest in BoringSSL.
10516 CurvePreferences: []CurveID{CurveP384},
10517 Bugs: ProtocolBugs{
10518 SkipHelloRetryRequest: true,
10519 },
10520 },
10521 shouldFail: true,
10522 expectedError: ":WRONG_CURVE:",
10523 })
David Benjamin8a8349b2016-08-18 02:32:23 -040010524
10525 testCases = append(testCases, testCase{
10526 name: "TLS13-RequestContextInHandshake",
10527 config: Config{
10528 MaxVersion: VersionTLS13,
10529 MinVersion: VersionTLS13,
10530 ClientAuth: RequireAnyClientCert,
10531 Bugs: ProtocolBugs{
10532 SendRequestContext: []byte("request context"),
10533 },
10534 },
10535 flags: []string{
10536 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10537 "-key-file", path.Join(*resourceDir, rsaKeyFile),
10538 },
10539 shouldFail: true,
10540 expectedError: ":DECODE_ERROR:",
10541 })
David Benjamin7e1f9842016-09-20 19:24:40 -040010542
10543 testCases = append(testCases, testCase{
10544 testType: serverTest,
10545 name: "TLS13-TrailingKeyShareData",
10546 config: Config{
10547 MaxVersion: VersionTLS13,
10548 Bugs: ProtocolBugs{
10549 TrailingKeyShareData: true,
10550 },
10551 },
10552 shouldFail: true,
10553 expectedError: ":DECODE_ERROR:",
10554 })
David Benjamin7f78df42016-10-05 22:33:19 -040010555
10556 testCases = append(testCases, testCase{
10557 name: "TLS13-AlwaysSelectPSKIdentity",
10558 config: Config{
10559 MaxVersion: VersionTLS13,
10560 Bugs: ProtocolBugs{
10561 AlwaysSelectPSKIdentity: true,
10562 },
10563 },
10564 shouldFail: true,
10565 expectedError: ":UNEXPECTED_EXTENSION:",
10566 })
10567
10568 testCases = append(testCases, testCase{
10569 name: "TLS13-InvalidPSKIdentity",
10570 config: Config{
10571 MaxVersion: VersionTLS13,
10572 Bugs: ProtocolBugs{
10573 SelectPSKIdentityOnResume: 1,
10574 },
10575 },
10576 resumeSession: true,
10577 shouldFail: true,
10578 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
10579 })
David Benjamin1286bee2016-10-07 15:25:06 -040010580
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010581 testCases = append(testCases, testCase{
10582 testType: serverTest,
10583 name: "TLS13-ExtraPSKIdentity",
10584 config: Config{
10585 MaxVersion: VersionTLS13,
10586 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -050010587 ExtraPSKIdentity: true,
10588 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -040010589 },
10590 },
10591 resumeSession: true,
10592 })
10593
David Benjamin1286bee2016-10-07 15:25:06 -040010594 // Test that unknown NewSessionTicket extensions are tolerated.
10595 testCases = append(testCases, testCase{
10596 name: "TLS13-CustomTicketExtension",
10597 config: Config{
10598 MaxVersion: VersionTLS13,
10599 Bugs: ProtocolBugs{
10600 CustomTicketExtension: "1234",
10601 },
10602 },
10603 })
Steven Valdez2d850622017-01-11 11:34:52 -050010604
Steven Valdez2d850622017-01-11 11:34:52 -050010605 testCases = append(testCases, testCase{
10606 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010607 name: "TLS13-EarlyData-Reject-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010608 config: Config{
10609 MaxVersion: VersionTLS13,
10610 MaxEarlyDataSize: 16384,
10611 },
10612 resumeConfig: &Config{
10613 MaxVersion: VersionTLS13,
10614 MaxEarlyDataSize: 16384,
10615 Bugs: ProtocolBugs{
10616 AlwaysRejectEarlyData: true,
10617 },
10618 },
10619 resumeSession: true,
10620 flags: []string{
10621 "-enable-early-data",
10622 "-expect-early-data-info",
10623 "-expect-reject-early-data",
Steven Valdeze831a812017-03-09 14:56:07 -050010624 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010625 },
10626 })
10627
10628 testCases = append(testCases, testCase{
10629 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010630 name: "TLS13-EarlyData-RejectTicket-Client",
10631 config: Config{
10632 MaxVersion: VersionTLS13,
10633 MaxEarlyDataSize: 16384,
10634 Certificates: []Certificate{rsaCertificate},
10635 },
10636 resumeConfig: &Config{
10637 MaxVersion: VersionTLS13,
10638 MaxEarlyDataSize: 16384,
10639 Certificates: []Certificate{ecdsaP256Certificate},
10640 SessionTicketsDisabled: true,
10641 },
10642 resumeSession: true,
10643 expectResumeRejected: true,
10644 flags: []string{
10645 "-enable-early-data",
10646 "-expect-early-data-info",
10647 "-expect-reject-early-data",
10648 "-on-resume-shim-writes-first",
10649 "-on-initial-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10650 "-on-resume-expect-peer-cert-file", path.Join(*resourceDir, rsaCertificateFile),
10651 "-on-retry-expect-peer-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
10652 // Session tickets are disabled, so the runner will not send a ticket.
10653 "-on-retry-expect-no-session",
10654 },
10655 })
10656
10657 testCases = append(testCases, testCase{
10658 testType: clientTest,
10659 name: "TLS13-EarlyData-HRR-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010660 config: Config{
10661 MaxVersion: VersionTLS13,
10662 MaxEarlyDataSize: 16384,
10663 },
10664 resumeConfig: &Config{
10665 MaxVersion: VersionTLS13,
10666 MaxEarlyDataSize: 16384,
10667 Bugs: ProtocolBugs{
10668 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10669 },
10670 },
10671 resumeSession: true,
10672 flags: []string{
10673 "-enable-early-data",
10674 "-expect-early-data-info",
10675 "-expect-reject-early-data",
10676 },
10677 })
10678
10679 // The client must check the server does not send the early_data
10680 // extension while rejecting the session.
10681 testCases = append(testCases, testCase{
10682 testType: clientTest,
10683 name: "TLS13-EarlyDataWithoutResume-Client",
10684 config: Config{
10685 MaxVersion: VersionTLS13,
10686 MaxEarlyDataSize: 16384,
10687 },
10688 resumeConfig: &Config{
10689 MaxVersion: VersionTLS13,
10690 SessionTicketsDisabled: true,
10691 Bugs: ProtocolBugs{
10692 SendEarlyDataExtension: true,
10693 },
10694 },
10695 resumeSession: true,
10696 flags: []string{
10697 "-enable-early-data",
10698 "-expect-early-data-info",
10699 },
10700 shouldFail: true,
10701 expectedError: ":UNEXPECTED_EXTENSION:",
10702 })
10703
10704 // The client must fail with a dedicated error code if the server
10705 // responds with TLS 1.2 when offering 0-RTT.
10706 testCases = append(testCases, testCase{
10707 testType: clientTest,
10708 name: "TLS13-EarlyDataVersionDowngrade-Client",
10709 config: Config{
10710 MaxVersion: VersionTLS13,
10711 MaxEarlyDataSize: 16384,
10712 },
10713 resumeConfig: &Config{
10714 MaxVersion: VersionTLS12,
10715 },
10716 resumeSession: true,
10717 flags: []string{
10718 "-enable-early-data",
10719 "-expect-early-data-info",
10720 },
10721 shouldFail: true,
10722 expectedError: ":WRONG_VERSION_ON_EARLY_DATA:",
10723 })
10724
10725 // Test that the client rejects an (unsolicited) early_data extension if
10726 // the server sent an HRR.
10727 testCases = append(testCases, testCase{
10728 testType: clientTest,
10729 name: "TLS13-ServerAcceptsEarlyDataOnHRR-Client",
10730 config: Config{
10731 MaxVersion: VersionTLS13,
10732 MaxEarlyDataSize: 16384,
10733 },
10734 resumeConfig: &Config{
10735 MaxVersion: VersionTLS13,
10736 MaxEarlyDataSize: 16384,
10737 Bugs: ProtocolBugs{
10738 SendHelloRetryRequestCookie: []byte{1, 2, 3, 4},
10739 SendEarlyDataExtension: true,
10740 },
10741 },
10742 resumeSession: true,
10743 flags: []string{
10744 "-enable-early-data",
10745 "-expect-early-data-info",
Steven Valdeze831a812017-03-09 14:56:07 -050010746 "-expect-reject-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010747 },
10748 shouldFail: true,
10749 expectedError: ":UNEXPECTED_EXTENSION:",
10750 })
10751
10752 fooString := "foo"
10753 barString := "bar"
10754
10755 // Test that the client reports the correct ALPN after a 0-RTT reject
10756 // that changed it.
10757 testCases = append(testCases, testCase{
10758 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010759 name: "TLS13-EarlyData-ALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010760 config: Config{
10761 MaxVersion: VersionTLS13,
10762 MaxEarlyDataSize: 16384,
10763 Bugs: ProtocolBugs{
10764 ALPNProtocol: &fooString,
10765 },
10766 },
10767 resumeConfig: &Config{
10768 MaxVersion: VersionTLS13,
10769 MaxEarlyDataSize: 16384,
10770 Bugs: ProtocolBugs{
10771 ALPNProtocol: &barString,
10772 },
10773 },
10774 resumeSession: true,
10775 flags: []string{
10776 "-advertise-alpn", "\x03foo\x03bar",
10777 "-enable-early-data",
10778 "-expect-early-data-info",
10779 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010780 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010781 "-on-resume-expect-alpn", "foo",
10782 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010783 },
10784 })
10785
10786 // Test that the client reports the correct ALPN after a 0-RTT reject if
10787 // ALPN was omitted from the first connection.
10788 testCases = append(testCases, testCase{
10789 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010790 name: "TLS13-EarlyData-ALPNOmitted1-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010791 config: Config{
10792 MaxVersion: VersionTLS13,
10793 MaxEarlyDataSize: 16384,
10794 },
10795 resumeConfig: &Config{
10796 MaxVersion: VersionTLS13,
10797 MaxEarlyDataSize: 16384,
10798 NextProtos: []string{"foo"},
10799 },
10800 resumeSession: true,
10801 flags: []string{
10802 "-advertise-alpn", "\x03foo\x03bar",
10803 "-enable-early-data",
10804 "-expect-early-data-info",
10805 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010806 "-on-initial-expect-alpn", "",
Steven Valdeze831a812017-03-09 14:56:07 -050010807 "-on-resume-expect-alpn", "",
10808 "-on-retry-expect-alpn", "foo",
10809 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010810 },
10811 })
10812
10813 // Test that the client reports the correct ALPN after a 0-RTT reject if
10814 // ALPN was omitted from the second connection.
10815 testCases = append(testCases, testCase{
10816 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010817 name: "TLS13-EarlyData-ALPNOmitted2-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010818 config: Config{
10819 MaxVersion: VersionTLS13,
10820 MaxEarlyDataSize: 16384,
10821 NextProtos: []string{"foo"},
10822 },
10823 resumeConfig: &Config{
10824 MaxVersion: VersionTLS13,
10825 MaxEarlyDataSize: 16384,
10826 },
10827 resumeSession: true,
10828 flags: []string{
10829 "-advertise-alpn", "\x03foo\x03bar",
10830 "-enable-early-data",
10831 "-expect-early-data-info",
10832 "-expect-reject-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010833 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010834 "-on-resume-expect-alpn", "foo",
10835 "-on-retry-expect-alpn", "",
10836 "-on-resume-shim-writes-first",
Steven Valdez2d850622017-01-11 11:34:52 -050010837 },
10838 })
10839
10840 // Test that the client enforces ALPN match on 0-RTT accept.
10841 testCases = append(testCases, testCase{
10842 testType: clientTest,
Steven Valdeze831a812017-03-09 14:56:07 -050010843 name: "TLS13-EarlyData-BadALPNMismatch-Client",
Steven Valdez2d850622017-01-11 11:34:52 -050010844 config: Config{
10845 MaxVersion: VersionTLS13,
10846 MaxEarlyDataSize: 16384,
10847 Bugs: ProtocolBugs{
10848 ALPNProtocol: &fooString,
10849 },
10850 },
10851 resumeConfig: &Config{
10852 MaxVersion: VersionTLS13,
10853 MaxEarlyDataSize: 16384,
10854 Bugs: ProtocolBugs{
10855 AlwaysAcceptEarlyData: true,
10856 ALPNProtocol: &barString,
10857 },
10858 },
10859 resumeSession: true,
10860 flags: []string{
10861 "-advertise-alpn", "\x03foo\x03bar",
10862 "-enable-early-data",
10863 "-expect-early-data-info",
Steven Valdez873ebc92017-05-09 12:12:58 -040010864 "-on-initial-expect-alpn", "foo",
Steven Valdeze831a812017-03-09 14:56:07 -050010865 "-on-resume-expect-alpn", "foo",
10866 "-on-retry-expect-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010867 },
10868 shouldFail: true,
10869 expectedError: ":ALPN_MISMATCH_ON_EARLY_DATA:",
10870 })
10871
10872 // Test that the server correctly rejects 0-RTT when the previous
10873 // session did not allow early data on resumption.
10874 testCases = append(testCases, testCase{
10875 testType: serverTest,
10876 name: "TLS13-EarlyData-NonZeroRTTSession-Server",
10877 config: Config{
10878 MaxVersion: VersionTLS13,
10879 },
10880 resumeConfig: &Config{
10881 MaxVersion: VersionTLS13,
10882 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010883 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010884 ExpectEarlyDataAccepted: false,
10885 },
10886 },
10887 resumeSession: true,
10888 flags: []string{
Steven Valdez873ebc92017-05-09 12:12:58 -040010889 "-on-resume-enable-early-data",
Steven Valdez2d850622017-01-11 11:34:52 -050010890 "-expect-reject-early-data",
10891 },
10892 })
10893
10894 // Test that we reject early data where ALPN is omitted from the first
10895 // connection.
10896 testCases = append(testCases, testCase{
10897 testType: serverTest,
10898 name: "TLS13-EarlyData-ALPNOmitted1-Server",
10899 config: Config{
10900 MaxVersion: VersionTLS13,
10901 NextProtos: []string{},
10902 },
10903 resumeConfig: &Config{
10904 MaxVersion: VersionTLS13,
10905 NextProtos: []string{"foo"},
10906 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010907 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010908 ExpectEarlyDataAccepted: false,
10909 },
10910 },
10911 resumeSession: true,
10912 flags: []string{
10913 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010914 "-on-initial-select-alpn", "",
10915 "-on-resume-select-alpn", "foo",
Steven Valdez2d850622017-01-11 11:34:52 -050010916 },
10917 })
10918
10919 // Test that we reject early data where ALPN is omitted from the second
10920 // connection.
10921 testCases = append(testCases, testCase{
10922 testType: serverTest,
10923 name: "TLS13-EarlyData-ALPNOmitted2-Server",
10924 config: Config{
10925 MaxVersion: VersionTLS13,
10926 NextProtos: []string{"foo"},
10927 },
10928 resumeConfig: &Config{
10929 MaxVersion: VersionTLS13,
10930 NextProtos: []string{},
10931 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010932 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010933 ExpectEarlyDataAccepted: false,
10934 },
10935 },
10936 resumeSession: true,
10937 flags: []string{
10938 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010939 "-on-initial-select-alpn", "foo",
10940 "-on-resume-select-alpn", "",
Steven Valdez2d850622017-01-11 11:34:52 -050010941 },
10942 })
10943
10944 // Test that we reject early data with mismatched ALPN.
10945 testCases = append(testCases, testCase{
10946 testType: serverTest,
10947 name: "TLS13-EarlyData-ALPNMismatch-Server",
10948 config: Config{
10949 MaxVersion: VersionTLS13,
10950 NextProtos: []string{"foo"},
10951 },
10952 resumeConfig: &Config{
10953 MaxVersion: VersionTLS13,
10954 NextProtos: []string{"bar"},
10955 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050010956 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2d850622017-01-11 11:34:52 -050010957 ExpectEarlyDataAccepted: false,
10958 },
10959 },
10960 resumeSession: true,
10961 flags: []string{
10962 "-enable-early-data",
Steven Valdez873ebc92017-05-09 12:12:58 -040010963 "-on-initial-select-alpn", "foo",
10964 "-on-resume-select-alpn", "bar",
Steven Valdez2d850622017-01-11 11:34:52 -050010965 },
10966 })
10967
David Benjamin6bb507b2017-03-29 16:35:57 -050010968 // Test that the client offering 0-RTT and Channel ID forbids the server
10969 // from accepting both.
Steven Valdez2a070722017-03-25 20:54:16 -050010970 testCases = append(testCases, testCase{
10971 testType: clientTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050010972 name: "TLS13-EarlyDataChannelID-AcceptBoth-Client",
Steven Valdez2a070722017-03-25 20:54:16 -050010973 config: Config{
10974 MaxVersion: VersionTLS13,
10975 MaxEarlyDataSize: 16384,
10976 RequestChannelID: true,
10977 },
10978 resumeSession: true,
10979 expectChannelID: true,
10980 shouldFail: true,
10981 expectedError: ":CHANNEL_ID_ON_EARLY_DATA:",
10982 flags: []string{
10983 "-enable-early-data",
10984 "-expect-early-data-info",
10985 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
10986 },
10987 })
10988
David Benjamin6bb507b2017-03-29 16:35:57 -050010989 // Test that the client offering Channel ID and 0-RTT allows the server
10990 // to decline 0-RTT.
10991 testCases = append(testCases, testCase{
10992 testType: clientTest,
10993 name: "TLS13-EarlyDataChannelID-AcceptChannelID-Client",
10994 config: Config{
10995 MaxVersion: VersionTLS13,
10996 MaxEarlyDataSize: 16384,
10997 RequestChannelID: true,
10998 Bugs: ProtocolBugs{
10999 AlwaysRejectEarlyData: true,
11000 },
11001 },
11002 resumeSession: true,
11003 expectChannelID: true,
11004 flags: []string{
11005 "-enable-early-data",
11006 "-expect-early-data-info",
11007 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11008 "-expect-reject-early-data",
11009 },
11010 })
11011
11012 // Test that the client offering Channel ID and 0-RTT allows the server
11013 // to decline Channel ID.
11014 testCases = append(testCases, testCase{
11015 testType: clientTest,
11016 name: "TLS13-EarlyDataChannelID-AcceptEarlyData-Client",
11017 config: Config{
11018 MaxVersion: VersionTLS13,
11019 MaxEarlyDataSize: 16384,
11020 },
11021 resumeSession: true,
11022 flags: []string{
11023 "-enable-early-data",
11024 "-expect-early-data-info",
11025 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
11026 "-expect-accept-early-data",
11027 },
11028 })
11029
11030 // Test that the server supporting Channel ID and 0-RTT declines 0-RTT
11031 // if it would negotiate Channel ID.
Steven Valdez2a070722017-03-25 20:54:16 -050011032 testCases = append(testCases, testCase{
11033 testType: serverTest,
David Benjamin6bb507b2017-03-29 16:35:57 -050011034 name: "TLS13-EarlyDataChannelID-OfferBoth-Server",
Steven Valdez2a070722017-03-25 20:54:16 -050011035 config: Config{
11036 MaxVersion: VersionTLS13,
11037 ChannelID: channelIDKey,
11038 Bugs: ProtocolBugs{
David Benjamin6bb507b2017-03-29 16:35:57 -050011039 SendEarlyData: [][]byte{{1, 2, 3, 4}},
Steven Valdez2a070722017-03-25 20:54:16 -050011040 ExpectEarlyDataAccepted: false,
11041 },
11042 },
11043 resumeSession: true,
11044 expectChannelID: true,
11045 flags: []string{
11046 "-enable-early-data",
11047 "-expect-reject-early-data",
11048 "-expect-channel-id",
11049 base64.StdEncoding.EncodeToString(channelIDBytes),
11050 },
11051 })
11052
David Benjamin6bb507b2017-03-29 16:35:57 -050011053 // Test that the server supporting Channel ID and 0-RTT accepts 0-RTT
11054 // if not offered Channel ID.
11055 testCases = append(testCases, testCase{
11056 testType: serverTest,
11057 name: "TLS13-EarlyDataChannelID-OfferEarlyData-Server",
11058 config: Config{
11059 MaxVersion: VersionTLS13,
11060 Bugs: ProtocolBugs{
11061 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11062 ExpectEarlyDataAccepted: true,
11063 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11064 },
11065 },
11066 resumeSession: true,
11067 expectChannelID: false,
11068 flags: []string{
11069 "-enable-early-data",
11070 "-expect-accept-early-data",
11071 "-enable-channel-id",
11072 },
11073 })
11074
David Benjamin32c89272017-03-26 13:54:21 -050011075 // Test that the server rejects 0-RTT streams without end_of_early_data.
11076 // The subsequent records should fail to decrypt.
11077 testCases = append(testCases, testCase{
11078 testType: serverTest,
11079 name: "TLS13-EarlyData-SkipEndOfEarlyData",
11080 config: Config{
11081 MaxVersion: VersionTLS13,
11082 Bugs: ProtocolBugs{
Steven Valdez681eb6a2016-12-19 13:19:29 -050011083 SendEarlyData: [][]byte{{1, 2, 3, 4}},
David Benjamin32c89272017-03-26 13:54:21 -050011084 ExpectEarlyDataAccepted: true,
11085 SkipEndOfEarlyData: true,
11086 },
11087 },
11088 resumeSession: true,
11089 flags: []string{"-enable-early-data"},
11090 shouldFail: true,
11091 expectedLocalError: "remote error: bad record MAC",
11092 expectedError: ":BAD_DECRYPT:",
11093 })
Steven Valdez681eb6a2016-12-19 13:19:29 -050011094
11095 testCases = append(testCases, testCase{
11096 testType: serverTest,
11097 name: "TLS13-EarlyData-UnexpectedHandshake-Server",
11098 config: Config{
11099 MaxVersion: VersionTLS13,
11100 },
11101 resumeConfig: &Config{
11102 MaxVersion: VersionTLS13,
11103 Bugs: ProtocolBugs{
11104 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11105 SendStrayEarlyHandshake: true,
11106 ExpectEarlyDataAccepted: true},
11107 },
11108 resumeSession: true,
11109 shouldFail: true,
11110 expectedError: ":UNEXPECTED_RECORD:",
11111 expectedLocalError: "remote error: unexpected message",
11112 flags: []string{
11113 "-enable-early-data",
11114 },
11115 })
Steven Valdez143e8b32016-07-11 13:19:03 -040011116}
11117
David Benjaminabbbee12016-10-31 19:20:42 -040011118func addTLS13CipherPreferenceTests() {
11119 // Test that client preference is honored if the shim has AES hardware
11120 // and ChaCha20-Poly1305 is preferred otherwise.
11121 testCases = append(testCases, testCase{
11122 testType: serverTest,
11123 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
11124 config: Config{
11125 MaxVersion: VersionTLS13,
11126 CipherSuites: []uint16{
11127 TLS_CHACHA20_POLY1305_SHA256,
11128 TLS_AES_128_GCM_SHA256,
11129 },
11130 },
11131 flags: []string{
11132 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11133 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11134 },
11135 })
11136
11137 testCases = append(testCases, testCase{
11138 testType: serverTest,
11139 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
11140 config: Config{
11141 MaxVersion: VersionTLS13,
11142 CipherSuites: []uint16{
11143 TLS_AES_128_GCM_SHA256,
11144 TLS_CHACHA20_POLY1305_SHA256,
11145 },
11146 },
11147 flags: []string{
11148 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11149 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11150 },
11151 })
11152
11153 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
11154 // whether it has AES hardware.
11155 testCases = append(testCases, testCase{
11156 name: "TLS13-CipherPreference-Client",
11157 config: Config{
11158 MaxVersion: VersionTLS13,
11159 // Use the client cipher order. (This is the default but
11160 // is listed to be explicit.)
11161 PreferServerCipherSuites: false,
11162 },
11163 flags: []string{
11164 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
11165 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
11166 },
11167 })
11168}
11169
David Benjaminf3fbade2016-09-19 13:08:16 -040011170func addPeekTests() {
11171 // Test SSL_peek works, including on empty records.
11172 testCases = append(testCases, testCase{
11173 name: "Peek-Basic",
11174 sendEmptyRecords: 1,
11175 flags: []string{"-peek-then-read"},
11176 })
11177
11178 // Test SSL_peek can drive the initial handshake.
11179 testCases = append(testCases, testCase{
11180 name: "Peek-ImplicitHandshake",
11181 flags: []string{
11182 "-peek-then-read",
11183 "-implicit-handshake",
11184 },
11185 })
11186
11187 // Test SSL_peek can discover and drive a renegotiation.
11188 testCases = append(testCases, testCase{
11189 name: "Peek-Renegotiate",
11190 config: Config{
11191 MaxVersion: VersionTLS12,
11192 },
11193 renegotiate: 1,
11194 flags: []string{
11195 "-peek-then-read",
11196 "-renegotiate-freely",
11197 "-expect-total-renegotiations", "1",
11198 },
11199 })
11200
11201 // Test SSL_peek can discover a close_notify.
11202 testCases = append(testCases, testCase{
11203 name: "Peek-Shutdown",
11204 config: Config{
11205 Bugs: ProtocolBugs{
11206 ExpectCloseNotify: true,
11207 },
11208 },
11209 flags: []string{
11210 "-peek-then-read",
11211 "-check-close-notify",
11212 },
11213 })
11214
11215 // Test SSL_peek can discover an alert.
11216 testCases = append(testCases, testCase{
11217 name: "Peek-Alert",
11218 config: Config{
11219 Bugs: ProtocolBugs{
11220 SendSpuriousAlert: alertRecordOverflow,
11221 },
11222 },
11223 flags: []string{"-peek-then-read"},
11224 shouldFail: true,
11225 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
11226 })
11227
11228 // Test SSL_peek can handle KeyUpdate.
11229 testCases = append(testCases, testCase{
11230 name: "Peek-KeyUpdate",
11231 config: Config{
11232 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040011233 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040011234 sendKeyUpdates: 1,
11235 keyUpdateRequest: keyUpdateNotRequested,
11236 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040011237 })
11238}
11239
David Benjamine6f22212016-11-08 14:28:24 -050011240func addRecordVersionTests() {
11241 for _, ver := range tlsVersions {
11242 // Test that the record version is enforced.
11243 testCases = append(testCases, testCase{
11244 name: "CheckRecordVersion-" + ver.name,
11245 config: Config{
11246 MinVersion: ver.version,
11247 MaxVersion: ver.version,
11248 Bugs: ProtocolBugs{
11249 SendRecordVersion: 0x03ff,
11250 },
11251 },
11252 shouldFail: true,
11253 expectedError: ":WRONG_VERSION_NUMBER:",
11254 })
11255
11256 // Test that the ClientHello may use any record version, for
11257 // compatibility reasons.
11258 testCases = append(testCases, testCase{
11259 testType: serverTest,
11260 name: "LooseInitialRecordVersion-" + ver.name,
11261 config: Config{
11262 MinVersion: ver.version,
11263 MaxVersion: ver.version,
11264 Bugs: ProtocolBugs{
11265 SendInitialRecordVersion: 0x03ff,
11266 },
11267 },
11268 })
11269
11270 // Test that garbage ClientHello record versions are rejected.
11271 testCases = append(testCases, testCase{
11272 testType: serverTest,
11273 name: "GarbageInitialRecordVersion-" + ver.name,
11274 config: Config{
11275 MinVersion: ver.version,
11276 MaxVersion: ver.version,
11277 Bugs: ProtocolBugs{
11278 SendInitialRecordVersion: 0xffff,
11279 },
11280 },
11281 shouldFail: true,
11282 expectedError: ":WRONG_VERSION_NUMBER:",
11283 })
11284 }
11285}
11286
David Benjamin2c516452016-11-15 10:16:54 +090011287func addCertificateTests() {
11288 // Test that a certificate chain with intermediate may be sent and
11289 // received as both client and server.
11290 for _, ver := range tlsVersions {
11291 testCases = append(testCases, testCase{
11292 testType: clientTest,
11293 name: "SendReceiveIntermediate-Client-" + ver.name,
11294 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011295 MinVersion: ver.version,
11296 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011297 Certificates: []Certificate{rsaChainCertificate},
11298 ClientAuth: RequireAnyClientCert,
11299 },
11300 expectPeerCertificate: &rsaChainCertificate,
11301 flags: []string{
11302 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11303 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11304 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11305 },
11306 })
11307
11308 testCases = append(testCases, testCase{
11309 testType: serverTest,
11310 name: "SendReceiveIntermediate-Server-" + ver.name,
11311 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080011312 MinVersion: ver.version,
11313 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090011314 Certificates: []Certificate{rsaChainCertificate},
11315 },
11316 expectPeerCertificate: &rsaChainCertificate,
11317 flags: []string{
11318 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11319 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
11320 "-require-any-client-certificate",
11321 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
11322 },
11323 })
11324 }
11325}
11326
David Benjaminbbaf3672016-11-17 10:53:09 +090011327func addRetainOnlySHA256ClientCertTests() {
11328 for _, ver := range tlsVersions {
11329 // Test that enabling
11330 // SSL_CTX_set_retain_only_sha256_of_client_certs without
11331 // actually requesting a client certificate is a no-op.
11332 testCases = append(testCases, testCase{
11333 testType: serverTest,
11334 name: "RetainOnlySHA256-NoCert-" + ver.name,
11335 config: Config{
11336 MinVersion: ver.version,
11337 MaxVersion: ver.version,
11338 },
11339 flags: []string{
11340 "-retain-only-sha256-client-cert-initial",
11341 "-retain-only-sha256-client-cert-resume",
11342 },
11343 resumeSession: true,
11344 })
11345
11346 // Test that when retaining only a SHA-256 certificate is
11347 // enabled, the hash appears as expected.
11348 testCases = append(testCases, testCase{
11349 testType: serverTest,
11350 name: "RetainOnlySHA256-Cert-" + ver.name,
11351 config: Config{
11352 MinVersion: ver.version,
11353 MaxVersion: ver.version,
11354 Certificates: []Certificate{rsaCertificate},
11355 },
11356 flags: []string{
11357 "-verify-peer",
11358 "-retain-only-sha256-client-cert-initial",
11359 "-retain-only-sha256-client-cert-resume",
11360 "-expect-sha256-client-cert-initial",
11361 "-expect-sha256-client-cert-resume",
11362 },
11363 resumeSession: true,
11364 })
11365
11366 // Test that when the config changes from on to off, a
11367 // resumption is rejected because the server now wants the full
11368 // certificate chain.
11369 testCases = append(testCases, testCase{
11370 testType: serverTest,
11371 name: "RetainOnlySHA256-OnOff-" + ver.name,
11372 config: Config{
11373 MinVersion: ver.version,
11374 MaxVersion: ver.version,
11375 Certificates: []Certificate{rsaCertificate},
11376 },
11377 flags: []string{
11378 "-verify-peer",
11379 "-retain-only-sha256-client-cert-initial",
11380 "-expect-sha256-client-cert-initial",
11381 },
11382 resumeSession: true,
11383 expectResumeRejected: true,
11384 })
11385
11386 // Test that when the config changes from off to on, a
11387 // resumption is rejected because the server now wants just the
11388 // hash.
11389 testCases = append(testCases, testCase{
11390 testType: serverTest,
11391 name: "RetainOnlySHA256-OffOn-" + ver.name,
11392 config: Config{
11393 MinVersion: ver.version,
11394 MaxVersion: ver.version,
11395 Certificates: []Certificate{rsaCertificate},
11396 },
11397 flags: []string{
11398 "-verify-peer",
11399 "-retain-only-sha256-client-cert-resume",
11400 "-expect-sha256-client-cert-resume",
11401 },
11402 resumeSession: true,
11403 expectResumeRejected: true,
11404 })
11405 }
11406}
11407
Adam Langleya4b91982016-12-12 12:05:53 -080011408func addECDSAKeyUsageTests() {
11409 p256 := elliptic.P256()
11410 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
11411 if err != nil {
11412 panic(err)
11413 }
11414
11415 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
11416 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
11417 if err != nil {
11418 panic(err)
11419 }
11420
11421 template := x509.Certificate{
11422 SerialNumber: serialNumber,
11423 Subject: pkix.Name{
11424 Organization: []string{"Acme Co"},
11425 },
11426 NotBefore: time.Now(),
11427 NotAfter: time.Now(),
11428
11429 // An ECC certificate with only the keyAgreement key usgae may
11430 // be used with ECDH, but not ECDSA.
11431 KeyUsage: x509.KeyUsageKeyAgreement,
11432 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
11433 BasicConstraintsValid: true,
11434 }
11435
11436 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
11437 if err != nil {
11438 panic(err)
11439 }
11440
11441 cert := Certificate{
11442 Certificate: [][]byte{derBytes},
11443 PrivateKey: priv,
11444 }
11445
11446 for _, ver := range tlsVersions {
11447 if ver.version < VersionTLS12 {
11448 continue
11449 }
11450
11451 testCases = append(testCases, testCase{
11452 testType: clientTest,
11453 name: "ECDSAKeyUsage-" + ver.name,
11454 config: Config{
11455 MinVersion: ver.version,
11456 MaxVersion: ver.version,
11457 Certificates: []Certificate{cert},
11458 },
11459 shouldFail: true,
11460 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
11461 })
11462 }
11463}
11464
David Benjamin8c26d752017-03-26 15:13:51 -050011465func addExtraHandshakeTests() {
11466 // An extra SSL_do_handshake is normally a no-op. These tests use -async
11467 // to ensure there is no transport I/O.
11468 testCases = append(testCases, testCase{
11469 testType: clientTest,
11470 name: "ExtraHandshake-Client-TLS12",
11471 config: Config{
11472 MinVersion: VersionTLS12,
11473 MaxVersion: VersionTLS12,
11474 },
11475 flags: []string{
11476 "-async",
11477 "-no-op-extra-handshake",
11478 },
11479 })
11480 testCases = append(testCases, testCase{
11481 testType: serverTest,
11482 name: "ExtraHandshake-Server-TLS12",
11483 config: Config{
11484 MinVersion: VersionTLS12,
11485 MaxVersion: VersionTLS12,
11486 },
11487 flags: []string{
11488 "-async",
11489 "-no-op-extra-handshake",
11490 },
11491 })
11492 testCases = append(testCases, testCase{
11493 testType: clientTest,
11494 name: "ExtraHandshake-Client-TLS13",
11495 config: Config{
11496 MinVersion: VersionTLS13,
11497 MaxVersion: VersionTLS13,
11498 },
11499 flags: []string{
11500 "-async",
11501 "-no-op-extra-handshake",
11502 },
11503 })
11504 testCases = append(testCases, testCase{
11505 testType: serverTest,
11506 name: "ExtraHandshake-Server-TLS13",
11507 config: Config{
11508 MinVersion: VersionTLS13,
11509 MaxVersion: VersionTLS13,
11510 },
11511 flags: []string{
11512 "-async",
11513 "-no-op-extra-handshake",
11514 },
11515 })
11516
11517 // An extra SSL_do_handshake is a no-op in server 0-RTT.
11518 testCases = append(testCases, testCase{
11519 testType: serverTest,
11520 name: "ExtraHandshake-Server-EarlyData-TLS13",
11521 config: Config{
11522 MaxVersion: VersionTLS13,
11523 MinVersion: VersionTLS13,
11524 Bugs: ProtocolBugs{
11525 SendEarlyData: [][]byte{{1, 2, 3, 4}},
11526 ExpectEarlyDataAccepted: true,
11527 ExpectHalfRTTData: [][]byte{{254, 253, 252, 251}},
11528 },
11529 },
11530 messageCount: 2,
11531 resumeSession: true,
11532 flags: []string{
11533 "-async",
11534 "-enable-early-data",
11535 "-expect-accept-early-data",
11536 "-no-op-extra-handshake",
11537 },
11538 })
11539
11540 // An extra SSL_do_handshake drives the handshake to completion in False
11541 // Start. We test this by handshaking twice and asserting the False
11542 // Start does not appear to happen. See AlertBeforeFalseStartTest for
11543 // how the test works.
11544 testCases = append(testCases, testCase{
11545 testType: clientTest,
11546 name: "ExtraHandshake-FalseStart",
11547 config: Config{
11548 MaxVersion: VersionTLS12,
11549 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
11550 NextProtos: []string{"foo"},
11551 Bugs: ProtocolBugs{
11552 ExpectFalseStart: true,
11553 AlertBeforeFalseStartTest: alertAccessDenied,
11554 },
11555 },
11556 flags: []string{
11557 "-handshake-twice",
11558 "-false-start",
11559 "-advertise-alpn", "\x03foo",
Steven Valdez873ebc92017-05-09 12:12:58 -040011560 "-expect-alpn", "foo",
David Benjamin8c26d752017-03-26 15:13:51 -050011561 },
11562 shimWritesFirst: true,
11563 shouldFail: true,
11564 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
11565 expectedLocalError: "tls: peer did not false start: EOF",
11566 })
11567}
11568
Adam Langley7c803a62015-06-15 15:35:05 -070011569func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070011570 defer wg.Done()
11571
11572 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080011573 var err error
11574
David Benjaminba28dfc2016-11-15 17:47:21 +090011575 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080011576 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
11577 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070011578 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080011579 if err != nil {
11580 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
11581 }
11582 break
11583 }
11584 }
David Benjaminba28dfc2016-11-15 17:47:21 +090011585 } else if *repeatUntilFailure {
11586 for err == nil {
11587 statusChan <- statusMsg{test: test, started: true}
11588 err = runTest(test, shimPath, -1)
11589 }
11590 } else {
11591 statusChan <- statusMsg{test: test, started: true}
11592 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080011593 }
Adam Langley95c29f32014-06-20 12:00:00 -070011594 statusChan <- statusMsg{test: test, err: err}
11595 }
11596}
11597
11598type statusMsg struct {
11599 test *testCase
11600 started bool
11601 err error
11602}
11603
David Benjamin5f237bc2015-02-11 17:14:15 -050011604func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020011605 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070011606
David Benjamin5f237bc2015-02-11 17:14:15 -050011607 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070011608 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050011609 if !*pipe {
11610 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050011611 var erase string
11612 for i := 0; i < lineLen; i++ {
11613 erase += "\b \b"
11614 }
11615 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050011616 }
11617
Adam Langley95c29f32014-06-20 12:00:00 -070011618 if msg.started {
11619 started++
11620 } else {
11621 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050011622
11623 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020011624 if msg.err == errUnimplemented {
11625 if *pipe {
11626 // Print each test instead of a status line.
11627 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
11628 }
11629 unimplemented++
11630 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
11631 } else {
11632 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
11633 failed++
11634 testOutput.addResult(msg.test.name, "FAIL")
11635 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011636 } else {
11637 if *pipe {
11638 // Print each test instead of a status line.
11639 fmt.Printf("PASSED (%s)\n", msg.test.name)
11640 }
11641 testOutput.addResult(msg.test.name, "PASS")
11642 }
Adam Langley95c29f32014-06-20 12:00:00 -070011643 }
11644
David Benjamin5f237bc2015-02-11 17:14:15 -050011645 if !*pipe {
11646 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020011647 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050011648 lineLen = len(line)
11649 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070011650 }
Adam Langley95c29f32014-06-20 12:00:00 -070011651 }
David Benjamin5f237bc2015-02-11 17:14:15 -050011652
11653 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070011654}
11655
11656func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070011657 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070011658 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070011659 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070011660
Adam Langley7c803a62015-06-15 15:35:05 -070011661 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011662 addCipherSuiteTests()
11663 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070011664 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070011665 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040011666 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080011667 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040011668 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050011669 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040011670 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040011671 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070011672 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070011673 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050011674 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070011675 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050011676 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040011677 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070011678 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070011679 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050011680 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050011681 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040011682 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040011683 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070011684 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070011685 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040011686 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040011687 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040011688 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040011689 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040011690 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050011691 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090011692 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090011693 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080011694 addECDSAKeyUsageTests()
David Benjamin8c26d752017-03-26 15:13:51 -050011695 addExtraHandshakeTests()
Adam Langley95c29f32014-06-20 12:00:00 -070011696
11697 var wg sync.WaitGroup
11698
Adam Langley7c803a62015-06-15 15:35:05 -070011699 statusChan := make(chan statusMsg, *numWorkers)
11700 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050011701 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070011702
EKRf71d7ed2016-08-06 13:25:12 -070011703 if len(*shimConfigFile) != 0 {
11704 encoded, err := ioutil.ReadFile(*shimConfigFile)
11705 if err != nil {
11706 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
11707 os.Exit(1)
11708 }
11709
11710 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
11711 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
11712 os.Exit(1)
11713 }
11714 }
11715
David Benjamin025b3d32014-07-01 19:53:04 -040011716 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070011717
Adam Langley7c803a62015-06-15 15:35:05 -070011718 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070011719 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070011720 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070011721 }
11722
David Benjamin270f0a72016-03-17 14:41:36 -040011723 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040011724 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040011725 matched := true
11726 if len(*testToRun) != 0 {
11727 var err error
11728 matched, err = filepath.Match(*testToRun, testCases[i].name)
11729 if err != nil {
11730 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
11731 os.Exit(1)
11732 }
11733 }
11734
EKRf71d7ed2016-08-06 13:25:12 -070011735 if !*includeDisabled {
11736 for pattern := range shimConfig.DisabledTests {
11737 isDisabled, err := filepath.Match(pattern, testCases[i].name)
11738 if err != nil {
11739 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
11740 os.Exit(1)
11741 }
11742
11743 if isDisabled {
11744 matched = false
11745 break
11746 }
11747 }
11748 }
11749
David Benjamin17e12922016-07-28 18:04:43 -040011750 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040011751 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040011752 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090011753
11754 // Only run one test if repeating until failure.
11755 if *repeatUntilFailure {
11756 break
11757 }
Adam Langley95c29f32014-06-20 12:00:00 -070011758 }
11759 }
David Benjamin17e12922016-07-28 18:04:43 -040011760
David Benjamin270f0a72016-03-17 14:41:36 -040011761 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070011762 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040011763 os.Exit(1)
11764 }
Adam Langley95c29f32014-06-20 12:00:00 -070011765
11766 close(testChan)
11767 wg.Wait()
11768 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050011769 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070011770
11771 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050011772
11773 if *jsonOutput != "" {
11774 if err := testOutput.writeTo(*jsonOutput); err != nil {
11775 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
11776 }
11777 }
David Benjamin2ab7a862015-04-04 17:02:18 -040011778
EKR842ae6c2016-07-27 09:22:05 +020011779 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
11780 os.Exit(1)
11781 }
11782
11783 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040011784 os.Exit(1)
11785 }
Adam Langley95c29f32014-06-20 12:00:00 -070011786}