blob: d6db050b9aaae298fef873a7f051935ebe5a800a [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
85}
86
87var shimConfig ShimConfiguration
88
David Benjamin33863262016-07-08 17:20:12 -070089type testCert int
90
David Benjamin025b3d32014-07-01 19:53:04 -040091const (
David Benjamin33863262016-07-08 17:20:12 -070092 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040093 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090094 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -080095 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -070096 testCertECDSAP256
97 testCertECDSAP384
98 testCertECDSAP521
99)
100
101const (
102 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400103 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900104 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800105 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
107 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
108 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400109)
110
111const (
David Benjamina08e49d2014-08-24 01:46:07 -0400112 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400113 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900114 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800115 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700116 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
117 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
118 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400119 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400120)
121
David Benjamin7944a9f2016-07-12 22:27:01 -0400122var (
123 rsaCertificate Certificate
124 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900125 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800126 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400127 ecdsaP256Certificate Certificate
128 ecdsaP384Certificate Certificate
129 ecdsaP521Certificate Certificate
130)
David Benjamin33863262016-07-08 17:20:12 -0700131
132var testCerts = []struct {
133 id testCert
134 certFile, keyFile string
135 cert *Certificate
136}{
137 {
138 id: testCertRSA,
139 certFile: rsaCertificateFile,
140 keyFile: rsaKeyFile,
141 cert: &rsaCertificate,
142 },
143 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400144 id: testCertRSA1024,
145 certFile: rsa1024CertificateFile,
146 keyFile: rsa1024KeyFile,
147 cert: &rsa1024Certificate,
148 },
149 {
David Benjamin2c516452016-11-15 10:16:54 +0900150 id: testCertRSAChain,
151 certFile: rsaChainCertificateFile,
152 keyFile: rsaChainKeyFile,
153 cert: &rsaChainCertificate,
154 },
155 {
Adam Langley898be922017-02-27 12:37:59 -0800156 id: testCertECDSAP224,
157 certFile: ecdsaP224CertificateFile,
158 keyFile: ecdsaP224KeyFile,
159 cert: &ecdsaP224Certificate,
160 },
161 {
David Benjamin33863262016-07-08 17:20:12 -0700162 id: testCertECDSAP256,
163 certFile: ecdsaP256CertificateFile,
164 keyFile: ecdsaP256KeyFile,
165 cert: &ecdsaP256Certificate,
166 },
167 {
168 id: testCertECDSAP384,
169 certFile: ecdsaP384CertificateFile,
170 keyFile: ecdsaP384KeyFile,
171 cert: &ecdsaP384Certificate,
172 },
173 {
174 id: testCertECDSAP521,
175 certFile: ecdsaP521CertificateFile,
176 keyFile: ecdsaP521KeyFile,
177 cert: &ecdsaP521Certificate,
178 },
179}
180
David Benjamina08e49d2014-08-24 01:46:07 -0400181var channelIDKey *ecdsa.PrivateKey
182var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700183
David Benjamin61f95272014-11-25 01:55:35 -0500184var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800185var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500186
Steven Valdeza833c352016-11-01 13:39:36 -0400187var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800188var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400189
Adam Langley95c29f32014-06-20 12:00:00 -0700190func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700191 for i := range testCerts {
192 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
193 if err != nil {
194 panic(err)
195 }
196 cert.OCSPStaple = testOCSPResponse
197 cert.SignedCertificateTimestampList = testSCTList
198 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700199 }
David Benjamina08e49d2014-08-24 01:46:07 -0400200
Adam Langley7c803a62015-06-15 15:35:05 -0700201 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400202 if err != nil {
203 panic(err)
204 }
205 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
206 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
207 panic("bad key type")
208 }
209 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
210 if err != nil {
211 panic(err)
212 }
213 if channelIDKey.Curve != elliptic.P256() {
214 panic("bad curve")
215 }
216
217 channelIDBytes = make([]byte, 64)
218 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
219 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin33863262016-07-08 17:20:12 -0700222func getRunnerCertificate(t testCert) Certificate {
223 for _, cert := range testCerts {
224 if cert.id == t {
225 return *cert.cert
226 }
227 }
228 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700229}
230
David Benjamin33863262016-07-08 17:20:12 -0700231func getShimCertificate(t testCert) string {
232 for _, cert := range testCerts {
233 if cert.id == t {
234 return cert.certFile
235 }
236 }
237 panic("Unknown test certificate")
238}
239
240func getShimKey(t testCert) string {
241 for _, cert := range testCerts {
242 if cert.id == t {
243 return cert.keyFile
244 }
245 }
246 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700247}
248
Adam Langley2ff79332017-02-28 13:45:39 -0800249// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
250func encodeDERValues(values [][]byte) string {
251 var ret string
252 for i, v := range values {
253 if i > 0 {
254 ret += ","
255 }
256 ret += hex.EncodeToString(v)
257 }
258
259 return ret
260}
261
David Benjamin025b3d32014-07-01 19:53:04 -0400262type testType int
263
264const (
265 clientTest testType = iota
266 serverTest
267)
268
David Benjamin6fd297b2014-08-11 18:43:38 -0400269type protocol int
270
271const (
272 tls protocol = iota
273 dtls
274)
275
David Benjaminfc7b0862014-09-06 13:21:53 -0400276const (
277 alpn = 1
278 npn = 2
279)
280
Adam Langley95c29f32014-06-20 12:00:00 -0700281type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400282 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400283 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700284 name string
285 config Config
286 shouldFail bool
287 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700288 // expectedLocalError, if not empty, contains a substring that must be
289 // found in the local error.
290 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400291 // expectedVersion, if non-zero, specifies the TLS version that must be
292 // negotiated.
293 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400294 // expectedResumeVersion, if non-zero, specifies the TLS version that
295 // must be negotiated on resumption. If zero, expectedVersion is used.
296 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400297 // expectedCipher, if non-zero, specifies the TLS cipher suite that
298 // should be negotiated.
299 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400300 // expectChannelID controls whether the connection should have
301 // negotiated a Channel ID with channelIDKey.
302 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400303 // expectedNextProto controls whether the connection should
304 // negotiate a next protocol via NPN or ALPN.
305 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400306 // expectNoNextProto, if true, means that no next protocol should be
307 // negotiated.
308 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400309 // expectedNextProtoType, if non-zero, is the expected next
310 // protocol negotiation mechanism.
311 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500312 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
313 // should be negotiated. If zero, none should be negotiated.
314 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100315 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
316 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100317 // expectedSCTList, if not nil, is the expected SCT list to be received.
318 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700319 // expectedPeerSignatureAlgorithm, if not zero, is the signature
320 // algorithm that the peer should have used in the handshake.
321 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400322 // expectedCurveID, if not zero, is the curve that the handshake should
323 // have used.
324 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700325 // messageLen is the length, in bytes, of the test message that will be
326 // sent.
327 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400328 // messageCount is the number of test messages that will be sent.
329 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400330 // certFile is the path to the certificate to use for the server.
331 certFile string
332 // keyFile is the path to the private key to use for the server.
333 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400334 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400335 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400336 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400337 // resumeRenewedSession controls whether a third connection should be
338 // tested which attempts to resume the second connection's session.
339 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700340 // expectResumeRejected, if true, specifies that the attempted
341 // resumption must be rejected by the client. This is only valid for a
342 // serverTest.
343 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400344 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500345 // resumption. Unless newSessionsOnResume is set,
346 // SessionTicketKey, ServerSessionCache, and
347 // ClientSessionCache are copied from the initial connection's
348 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400349 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500350 // newSessionsOnResume, if true, will cause resumeConfig to
351 // use a different session resumption context.
352 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400353 // noSessionCache, if true, will cause the server to run without a
354 // session cache.
355 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400356 // sendPrefix sends a prefix on the socket before actually performing a
357 // handshake.
358 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400359 // shimWritesFirst controls whether the shim sends an initial "hello"
360 // message before doing a roundtrip with the runner.
361 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400362 // shimShutsDown, if true, runs a test where the shim shuts down the
363 // connection immediately after the handshake rather than echoing
364 // messages from the runner.
365 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400366 // renegotiate indicates the number of times the connection should be
367 // renegotiated during the exchange.
368 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400369 // sendHalfHelloRequest, if true, causes the server to send half a
370 // HelloRequest when the handshake completes.
371 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700372 // renegotiateCiphers is a list of ciphersuite ids that will be
373 // switched in just before renegotiation.
374 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500375 // replayWrites, if true, configures the underlying transport
376 // to replay every write it makes in DTLS tests.
377 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500378 // damageFirstWrite, if true, configures the underlying transport to
379 // damage the final byte of the first application data write.
380 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400381 // exportKeyingMaterial, if non-zero, configures the test to exchange
382 // keying material and verify they match.
383 exportKeyingMaterial int
384 exportLabel string
385 exportContext string
386 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400387 // flags, if not empty, contains a list of command-line flags that will
388 // be passed to the shim program.
389 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700390 // testTLSUnique, if true, causes the shim to send the tls-unique value
391 // which will be compared against the expected value.
392 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400393 // sendEmptyRecords is the number of consecutive empty records to send
394 // before and after the test message.
395 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400396 // sendWarningAlerts is the number of consecutive warning alerts to send
397 // before and after the test message.
398 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400399 // sendKeyUpdates is the number of consecutive key updates to send
400 // before and after the test message.
401 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400402 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
403 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400404 // expectMessageDropped, if true, means the test message is expected to
405 // be dropped by the client rather than echoed back.
406 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900407 // expectPeerCertificate, if not nil, is the certificate chain the peer
408 // is expected to send.
409 expectPeerCertificate *Certificate
David Benjamin6f600d62016-12-21 16:06:54 -0500410 // expectShortHeader is whether the short header extension should be negotiated.
411 expectShortHeader bool
Adam Langley95c29f32014-06-20 12:00:00 -0700412}
413
Adam Langley7c803a62015-06-15 15:35:05 -0700414var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700415
David Benjaminc07afb72016-09-22 10:18:58 -0400416func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500417 if len(data) == 0 {
418 return
419 }
420
421 protocol := "tls"
422 if test.protocol == dtls {
423 protocol = "dtls"
424 }
425
426 side := "client"
427 if test.testType == serverTest {
428 side = "server"
429 }
430
431 dir := path.Join(*transcriptDir, protocol, side)
432 if err := os.MkdirAll(dir, 0755); err != nil {
433 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
434 return
435 }
436
David Benjaminc07afb72016-09-22 10:18:58 -0400437 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500438 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
439 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
440 }
441}
442
David Benjamin3ed59772016-03-08 12:50:21 -0500443// A timeoutConn implements an idle timeout on each Read and Write operation.
444type timeoutConn struct {
445 net.Conn
446 timeout time.Duration
447}
448
449func (t *timeoutConn) Read(b []byte) (int, error) {
450 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
451 return 0, err
452 }
453 return t.Conn.Read(b)
454}
455
456func (t *timeoutConn) Write(b []byte) (int, error) {
457 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
458 return 0, err
459 }
460 return t.Conn.Write(b)
461}
462
David Benjaminc07afb72016-09-22 10:18:58 -0400463func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400464 if !test.noSessionCache {
465 if config.ClientSessionCache == nil {
466 config.ClientSessionCache = NewLRUClientSessionCache(1)
467 }
468 if config.ServerSessionCache == nil {
469 config.ServerSessionCache = NewLRUServerSessionCache(1)
470 }
471 }
472 if test.testType == clientTest {
473 if len(config.Certificates) == 0 {
474 config.Certificates = []Certificate{rsaCertificate}
475 }
476 } else {
477 // Supply a ServerName to ensure a constant session cache key,
478 // rather than falling back to net.Conn.RemoteAddr.
479 if len(config.ServerName) == 0 {
480 config.ServerName = "test"
481 }
482 }
483 if *fuzzer {
484 config.Bugs.NullAllCiphers = true
485 }
David Benjamin01a90572016-09-22 00:11:43 -0400486 if *deterministic {
487 config.Time = func() time.Time { return time.Unix(1234, 1234) }
488 }
David Benjamine54af062016-08-08 19:21:18 -0400489
David Benjamin01784b42016-06-07 18:00:52 -0400490 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500491
David Benjamin6fd297b2014-08-11 18:43:38 -0400492 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500493 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
494 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500495 }
496
David Benjamin9867b7d2016-03-01 23:25:48 -0500497 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500498 local, peer := "client", "server"
499 if test.testType == clientTest {
500 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500501 }
David Benjaminebda9b32015-11-02 15:33:18 -0500502 connDebug := &recordingConn{
503 Conn: conn,
504 isDatagram: test.protocol == dtls,
505 local: local,
506 peer: peer,
507 }
508 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500509 if *flagDebug {
510 defer connDebug.WriteTo(os.Stdout)
511 }
512 if len(*transcriptDir) != 0 {
513 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400514 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500515 }()
516 }
David Benjaminebda9b32015-11-02 15:33:18 -0500517
518 if config.Bugs.PacketAdaptor != nil {
519 config.Bugs.PacketAdaptor.debug = connDebug
520 }
521 }
522
523 if test.replayWrites {
524 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400525 }
526
David Benjamin3ed59772016-03-08 12:50:21 -0500527 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500528 if test.damageFirstWrite {
529 connDamage = newDamageAdaptor(conn)
530 conn = connDamage
531 }
532
David Benjamin6fd297b2014-08-11 18:43:38 -0400533 if test.sendPrefix != "" {
534 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
535 return err
536 }
David Benjamin98e882e2014-08-08 13:24:34 -0400537 }
538
David Benjamin1d5c83e2014-07-22 19:20:02 -0400539 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400540 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400541 if test.protocol == dtls {
542 tlsConn = DTLSServer(conn, config)
543 } else {
544 tlsConn = Server(conn, config)
545 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400546 } else {
547 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400548 if test.protocol == dtls {
549 tlsConn = DTLSClient(conn, config)
550 } else {
551 tlsConn = Client(conn, config)
552 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400553 }
David Benjamin30789da2015-08-29 22:56:45 -0400554 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400555
Adam Langley95c29f32014-06-20 12:00:00 -0700556 if err := tlsConn.Handshake(); err != nil {
557 return err
558 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700559
David Benjamin01fe8202014-09-24 15:21:44 -0400560 // TODO(davidben): move all per-connection expectations into a dedicated
561 // expectations struct that can be specified separately for the two
562 // legs.
563 expectedVersion := test.expectedVersion
564 if isResume && test.expectedResumeVersion != 0 {
565 expectedVersion = test.expectedResumeVersion
566 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700567 connState := tlsConn.ConnectionState()
568 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400569 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400570 }
571
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700572 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400573 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
574 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700575 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
576 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
577 }
David Benjamin90da8c82015-04-20 14:57:57 -0400578
David Benjamina08e49d2014-08-24 01:46:07 -0400579 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700580 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400581 if channelID == nil {
582 return fmt.Errorf("no channel ID negotiated")
583 }
584 if channelID.Curve != channelIDKey.Curve ||
585 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
586 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
587 return fmt.Errorf("incorrect channel ID")
588 }
589 }
590
David Benjaminae2888f2014-09-06 12:58:58 -0400591 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700592 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400593 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
594 }
595 }
596
David Benjaminc7ce9772015-10-09 19:32:41 -0400597 if test.expectNoNextProto {
598 if actual := connState.NegotiatedProtocol; actual != "" {
599 return fmt.Errorf("got unexpected next proto %s", actual)
600 }
601 }
602
David Benjaminfc7b0862014-09-06 13:21:53 -0400603 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700604 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400605 return fmt.Errorf("next proto type mismatch")
606 }
607 }
608
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700609 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500610 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
611 }
612
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100613 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300614 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100615 }
616
Paul Lietar4fac72e2015-09-09 13:44:55 +0100617 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
618 return fmt.Errorf("SCT list mismatch")
619 }
620
Nick Harper60edffd2016-06-21 15:19:24 -0700621 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
622 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400623 }
624
Steven Valdez5440fe02016-07-18 12:40:30 -0400625 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
626 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
627 }
628
David Benjamin2c516452016-11-15 10:16:54 +0900629 if test.expectPeerCertificate != nil {
630 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
631 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
632 }
633 for i, cert := range connState.PeerCertificates {
634 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
635 return fmt.Errorf("peer certificate %d did not match", i+1)
636 }
637 }
638 }
639
David Benjamin6f600d62016-12-21 16:06:54 -0500640 if test.expectShortHeader != connState.ShortHeader {
641 return fmt.Errorf("ShortHeader is %t, but we expected the opposite", connState.ShortHeader)
642 }
643
David Benjaminc565ebb2015-04-03 04:06:36 -0400644 if test.exportKeyingMaterial > 0 {
645 actual := make([]byte, test.exportKeyingMaterial)
646 if _, err := io.ReadFull(tlsConn, actual); err != nil {
647 return err
648 }
649 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
650 if err != nil {
651 return err
652 }
653 if !bytes.Equal(actual, expected) {
654 return fmt.Errorf("keying material mismatch")
655 }
656 }
657
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700658 if test.testTLSUnique {
659 var peersValue [12]byte
660 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
661 return err
662 }
663 expected := tlsConn.ConnectionState().TLSUnique
664 if !bytes.Equal(peersValue[:], expected) {
665 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
666 }
667 }
668
David Benjamine58c4f52014-08-24 03:47:07 -0400669 if test.shimWritesFirst {
670 var buf [5]byte
671 _, err := io.ReadFull(tlsConn, buf[:])
672 if err != nil {
673 return err
674 }
675 if string(buf[:]) != "hello" {
676 return fmt.Errorf("bad initial message")
677 }
678 }
679
Steven Valdez32635b82016-08-16 11:25:03 -0400680 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400681 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400682 return err
683 }
Steven Valdez32635b82016-08-16 11:25:03 -0400684 }
685
David Benjamina8ebe222015-06-06 03:04:39 -0400686 for i := 0; i < test.sendEmptyRecords; i++ {
687 tlsConn.Write(nil)
688 }
689
David Benjamin24f346d2015-06-06 03:28:08 -0400690 for i := 0; i < test.sendWarningAlerts; i++ {
691 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
692 }
693
David Benjamin47921102016-07-28 11:29:18 -0400694 if test.sendHalfHelloRequest {
695 tlsConn.SendHalfHelloRequest()
696 }
697
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400698 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700699 if test.renegotiateCiphers != nil {
700 config.CipherSuites = test.renegotiateCiphers
701 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400702 for i := 0; i < test.renegotiate; i++ {
703 if err := tlsConn.Renegotiate(); err != nil {
704 return err
705 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700706 }
707 } else if test.renegotiateCiphers != nil {
708 panic("renegotiateCiphers without renegotiate")
709 }
710
David Benjamin5fa3eba2015-01-22 16:35:40 -0500711 if test.damageFirstWrite {
712 connDamage.setDamage(true)
713 tlsConn.Write([]byte("DAMAGED WRITE"))
714 connDamage.setDamage(false)
715 }
716
David Benjamin8e6db492015-07-25 18:29:23 -0400717 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700718 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400719 if test.protocol == dtls {
720 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
721 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700722 // Read until EOF.
723 _, err := io.Copy(ioutil.Discard, tlsConn)
724 return err
725 }
David Benjamin4417d052015-04-05 04:17:25 -0400726 if messageLen == 0 {
727 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700728 }
Adam Langley95c29f32014-06-20 12:00:00 -0700729
David Benjamin8e6db492015-07-25 18:29:23 -0400730 messageCount := test.messageCount
731 if messageCount == 0 {
732 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400733 }
734
David Benjamin8e6db492015-07-25 18:29:23 -0400735 for j := 0; j < messageCount; j++ {
736 testMessage := make([]byte, messageLen)
737 for i := range testMessage {
738 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400739 }
David Benjamin8e6db492015-07-25 18:29:23 -0400740 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700741
Steven Valdez32635b82016-08-16 11:25:03 -0400742 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400743 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400744 }
745
David Benjamin8e6db492015-07-25 18:29:23 -0400746 for i := 0; i < test.sendEmptyRecords; i++ {
747 tlsConn.Write(nil)
748 }
749
750 for i := 0; i < test.sendWarningAlerts; i++ {
751 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
752 }
753
David Benjamin4f75aaf2015-09-01 16:53:10 -0400754 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400755 // The shim will not respond.
756 continue
757 }
758
David Benjamin8e6db492015-07-25 18:29:23 -0400759 buf := make([]byte, len(testMessage))
760 if test.protocol == dtls {
761 bufTmp := make([]byte, len(buf)+1)
762 n, err := tlsConn.Read(bufTmp)
763 if err != nil {
764 return err
765 }
766 if n != len(buf) {
767 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
768 }
769 copy(buf, bufTmp)
770 } else {
771 _, err := io.ReadFull(tlsConn, buf)
772 if err != nil {
773 return err
774 }
775 }
776
777 for i, v := range buf {
778 if v != testMessage[i]^0xff {
779 return fmt.Errorf("bad reply contents at byte %d", i)
780 }
Adam Langley95c29f32014-06-20 12:00:00 -0700781 }
782 }
783
784 return nil
785}
786
David Benjamin325b5c32014-07-01 19:40:31 -0400787func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400788 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700789 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400790 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700791 }
David Benjamin325b5c32014-07-01 19:40:31 -0400792 valgrindArgs = append(valgrindArgs, path)
793 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700794
David Benjamin325b5c32014-07-01 19:40:31 -0400795 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700796}
797
David Benjamin325b5c32014-07-01 19:40:31 -0400798func gdbOf(path string, args ...string) *exec.Cmd {
799 xtermArgs := []string{"-e", "gdb", "--args"}
800 xtermArgs = append(xtermArgs, path)
801 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700802
David Benjamin325b5c32014-07-01 19:40:31 -0400803 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700804}
805
David Benjamind16bf342015-12-18 00:53:12 -0500806func lldbOf(path string, args ...string) *exec.Cmd {
807 xtermArgs := []string{"-e", "lldb", "--"}
808 xtermArgs = append(xtermArgs, path)
809 xtermArgs = append(xtermArgs, args...)
810
811 return exec.Command("xterm", xtermArgs...)
812}
813
EKR842ae6c2016-07-27 09:22:05 +0200814var (
815 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
816 errUnimplemented = errors.New("child process does not implement needed flags")
817)
Adam Langley69a01602014-11-17 17:26:55 -0800818
David Benjamin87c8a642015-02-21 01:54:29 -0500819// accept accepts a connection from listener, unless waitChan signals a process
820// exit first.
821func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
822 type connOrError struct {
823 conn net.Conn
824 err error
825 }
826 connChan := make(chan connOrError, 1)
827 go func() {
828 conn, err := listener.Accept()
829 connChan <- connOrError{conn, err}
830 close(connChan)
831 }()
832 select {
833 case result := <-connChan:
834 return result.conn, result.err
835 case childErr := <-waitChan:
836 waitChan <- childErr
837 return nil, fmt.Errorf("child exited early: %s", childErr)
838 }
839}
840
EKRf71d7ed2016-08-06 13:25:12 -0700841func translateExpectedError(errorStr string) string {
842 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
843 return translated
844 }
845
846 if *looseErrors {
847 return ""
848 }
849
850 return errorStr
851}
852
Adam Langley7c803a62015-06-15 15:35:05 -0700853func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400854 // Help debugging panics on the Go side.
855 defer func() {
856 if r := recover(); r != nil {
857 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
858 panic(r)
859 }
860 }()
861
Adam Langley38311732014-10-16 19:04:35 -0700862 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
863 panic("Error expected without shouldFail in " + test.name)
864 }
865
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700866 if test.expectResumeRejected && !test.resumeSession {
867 panic("expectResumeRejected without resumeSession in " + test.name)
868 }
869
Adam Langley33b1d4f2016-12-07 15:03:45 -0800870 for _, ver := range tlsVersions {
871 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
872 continue
873 }
874
875 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
876 continue
877 }
878
879 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))
880 }
881
David Benjamin87c8a642015-02-21 01:54:29 -0500882 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
883 if err != nil {
884 panic(err)
885 }
886 defer func() {
887 if listener != nil {
888 listener.Close()
889 }
890 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700891
David Benjamin87c8a642015-02-21 01:54:29 -0500892 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400893 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400894 flags = append(flags, "-server")
895
David Benjamin025b3d32014-07-01 19:53:04 -0400896 flags = append(flags, "-key-file")
897 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700898 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400899 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700900 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400901 }
902
903 flags = append(flags, "-cert-file")
904 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700905 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400906 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700907 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400908 }
909 }
David Benjamin5a593af2014-08-11 19:51:50 -0400910
David Benjamin6fd297b2014-08-11 18:43:38 -0400911 if test.protocol == dtls {
912 flags = append(flags, "-dtls")
913 }
914
David Benjamin46662482016-08-17 00:51:00 -0400915 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400916 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400917 resumeCount++
918 if test.resumeRenewedSession {
919 resumeCount++
920 }
921 }
922
923 if resumeCount > 0 {
924 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400925 }
926
David Benjamine58c4f52014-08-24 03:47:07 -0400927 if test.shimWritesFirst {
928 flags = append(flags, "-shim-writes-first")
929 }
930
David Benjamin30789da2015-08-29 22:56:45 -0400931 if test.shimShutsDown {
932 flags = append(flags, "-shim-shuts-down")
933 }
934
David Benjaminc565ebb2015-04-03 04:06:36 -0400935 if test.exportKeyingMaterial > 0 {
936 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
937 flags = append(flags, "-export-label", test.exportLabel)
938 flags = append(flags, "-export-context", test.exportContext)
939 if test.useExportContext {
940 flags = append(flags, "-use-export-context")
941 }
942 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700943 if test.expectResumeRejected {
944 flags = append(flags, "-expect-session-miss")
945 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400946
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700947 if test.testTLSUnique {
948 flags = append(flags, "-tls-unique")
949 }
950
David Benjamin025b3d32014-07-01 19:53:04 -0400951 flags = append(flags, test.flags...)
952
953 var shim *exec.Cmd
954 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700955 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700956 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700957 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500958 } else if *useLLDB {
959 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400960 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700961 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400962 }
David Benjamin025b3d32014-07-01 19:53:04 -0400963 shim.Stdin = os.Stdin
964 var stdoutBuf, stderrBuf bytes.Buffer
965 shim.Stdout = &stdoutBuf
966 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800967 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500968 shim.Env = os.Environ()
969 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800970 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400971 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800972 }
973 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
974 }
David Benjamin025b3d32014-07-01 19:53:04 -0400975
976 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700977 panic(err)
978 }
David Benjamin87c8a642015-02-21 01:54:29 -0500979 waitChan := make(chan error, 1)
980 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700981
982 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700983
David Benjamin7a4aaa42016-09-20 17:58:14 -0400984 if *deterministic {
985 config.Rand = &deterministicRand{}
986 }
987
David Benjamin87c8a642015-02-21 01:54:29 -0500988 conn, err := acceptOrWait(listener, waitChan)
989 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400990 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500991 conn.Close()
992 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500993
David Benjamin46662482016-08-17 00:51:00 -0400994 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400995 var resumeConfig Config
996 if test.resumeConfig != nil {
997 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400998 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500999 resumeConfig.SessionTicketKey = config.SessionTicketKey
1000 resumeConfig.ClientSessionCache = config.ClientSessionCache
1001 resumeConfig.ServerSessionCache = config.ServerSessionCache
1002 }
David Benjamin2e045a92016-06-08 13:09:56 -04001003 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -04001004 } else {
1005 resumeConfig = config
1006 }
David Benjamin87c8a642015-02-21 01:54:29 -05001007 var connResume net.Conn
1008 connResume, err = acceptOrWait(listener, waitChan)
1009 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001010 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001011 connResume.Close()
1012 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001013 }
1014
David Benjamin87c8a642015-02-21 01:54:29 -05001015 // Close the listener now. This is to avoid hangs should the shim try to
1016 // open more connections than expected.
1017 listener.Close()
1018 listener = nil
1019
1020 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -04001021 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001022 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001023 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1024 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001025 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001026 case 89:
1027 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001028 case 99:
1029 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001030 }
1031 }
Adam Langley95c29f32014-06-20 12:00:00 -07001032
David Benjamin9bea3492016-03-02 10:59:16 -05001033 // Account for Windows line endings.
1034 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1035 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001036
1037 // Separate the errors from the shim and those from tools like
1038 // AddressSanitizer.
1039 var extraStderr string
1040 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1041 stderr = stderrParts[0]
1042 extraStderr = stderrParts[1]
1043 }
1044
Adam Langley95c29f32014-06-20 12:00:00 -07001045 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001046 expectedError := translateExpectedError(test.expectedError)
1047 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001048
Adam Langleyac61fa32014-06-23 12:03:11 -07001049 localError := "none"
1050 if err != nil {
1051 localError = err.Error()
1052 }
1053 if len(test.expectedLocalError) != 0 {
1054 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1055 }
Adam Langley95c29f32014-06-20 12:00:00 -07001056
1057 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001058 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001059 if childErr != nil {
1060 childError = childErr.Error()
1061 }
1062
1063 var msg string
1064 switch {
1065 case failed && !test.shouldFail:
1066 msg = "unexpected failure"
1067 case !failed && test.shouldFail:
1068 msg = "unexpected success"
1069 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001070 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001071 default:
1072 panic("internal error")
1073 }
1074
David Benjamin9aafb642016-09-20 19:36:53 -04001075 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 -07001076 }
1077
David Benjamind2ba8892016-09-20 19:41:04 -04001078 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001079 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001080 }
1081
David Benjamind2ba8892016-09-20 19:41:04 -04001082 if *useValgrind && isValgrindError {
1083 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1084 }
1085
Adam Langley95c29f32014-06-20 12:00:00 -07001086 return nil
1087}
1088
David Benjaminaa012042016-12-10 13:33:05 -05001089type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001090 name string
1091 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001092 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001093 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001094}
1095
1096var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001097 {"SSL3", VersionSSL30, "-no-ssl3", false},
1098 {"TLS1", VersionTLS10, "-no-tls1", true},
1099 {"TLS11", VersionTLS11, "-no-tls11", false},
1100 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001101 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001102}
1103
David Benjaminaa012042016-12-10 13:33:05 -05001104type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001105 name string
1106 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001107}
1108
1109var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001110 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001111 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001112 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001113 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001114 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001115 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001116 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001117 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1118 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001119 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001120 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1121 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001122 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001123 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1124 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001125 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1126 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001127 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001128 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001129 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001130 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001131 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001132 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001133 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001134 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001135 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001136 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001137 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1138 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001139 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1140 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001141 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001142 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1143 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1144 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001145 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001146}
1147
David Benjamin8b8c0062014-11-23 02:47:52 -05001148func hasComponent(suiteName, component string) bool {
1149 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1150}
1151
David Benjaminf7768e42014-08-31 02:06:47 -04001152func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001153 return hasComponent(suiteName, "GCM") ||
1154 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001155 hasComponent(suiteName, "SHA384") ||
1156 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001157}
1158
Nick Harper1fd39d82016-06-14 18:14:35 -07001159func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001160 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001161}
1162
David Benjamin8b8c0062014-11-23 02:47:52 -05001163func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001164 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001165}
1166
Adam Langleya7997f12015-05-14 17:38:50 -07001167func bigFromHex(hex string) *big.Int {
1168 ret, ok := new(big.Int).SetString(hex, 16)
1169 if !ok {
1170 panic("failed to parse hex number 0x" + hex)
1171 }
1172 return ret
1173}
1174
Adam Langley7c803a62015-06-15 15:35:05 -07001175func addBasicTests() {
1176 basicTests := []testCase{
1177 {
Adam Langley7c803a62015-06-15 15:35:05 -07001178 name: "NoFallbackSCSV",
1179 config: Config{
1180 Bugs: ProtocolBugs{
1181 FailIfNotFallbackSCSV: true,
1182 },
1183 },
1184 shouldFail: true,
1185 expectedLocalError: "no fallback SCSV found",
1186 },
1187 {
1188 name: "SendFallbackSCSV",
1189 config: Config{
1190 Bugs: ProtocolBugs{
1191 FailIfNotFallbackSCSV: true,
1192 },
1193 },
1194 flags: []string{"-fallback-scsv"},
1195 },
1196 {
1197 name: "ClientCertificateTypes",
1198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001199 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001200 ClientAuth: RequestClientCert,
1201 ClientCertificateTypes: []byte{
1202 CertTypeDSSSign,
1203 CertTypeRSASign,
1204 CertTypeECDSASign,
1205 },
1206 },
1207 flags: []string{
1208 "-expect-certificate-types",
1209 base64.StdEncoding.EncodeToString([]byte{
1210 CertTypeDSSSign,
1211 CertTypeRSASign,
1212 CertTypeECDSASign,
1213 }),
1214 },
1215 },
1216 {
Adam Langley7c803a62015-06-15 15:35:05 -07001217 name: "UnauthenticatedECDH",
1218 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001219 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1221 Bugs: ProtocolBugs{
1222 UnauthenticatedECDH: true,
1223 },
1224 },
1225 shouldFail: true,
1226 expectedError: ":UNEXPECTED_MESSAGE:",
1227 },
1228 {
1229 name: "SkipCertificateStatus",
1230 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001231 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001232 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1233 Bugs: ProtocolBugs{
1234 SkipCertificateStatus: true,
1235 },
1236 },
1237 flags: []string{
1238 "-enable-ocsp-stapling",
1239 },
1240 },
1241 {
1242 name: "SkipServerKeyExchange",
1243 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001244 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001245 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1246 Bugs: ProtocolBugs{
1247 SkipServerKeyExchange: true,
1248 },
1249 },
1250 shouldFail: true,
1251 expectedError: ":UNEXPECTED_MESSAGE:",
1252 },
1253 {
Adam Langley7c803a62015-06-15 15:35:05 -07001254 testType: serverTest,
1255 name: "Alert",
1256 config: Config{
1257 Bugs: ProtocolBugs{
1258 SendSpuriousAlert: alertRecordOverflow,
1259 },
1260 },
1261 shouldFail: true,
1262 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1263 },
1264 {
1265 protocol: dtls,
1266 testType: serverTest,
1267 name: "Alert-DTLS",
1268 config: Config{
1269 Bugs: ProtocolBugs{
1270 SendSpuriousAlert: alertRecordOverflow,
1271 },
1272 },
1273 shouldFail: true,
1274 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1275 },
1276 {
1277 testType: serverTest,
1278 name: "FragmentAlert",
1279 config: Config{
1280 Bugs: ProtocolBugs{
1281 FragmentAlert: true,
1282 SendSpuriousAlert: alertRecordOverflow,
1283 },
1284 },
1285 shouldFail: true,
1286 expectedError: ":BAD_ALERT:",
1287 },
1288 {
1289 protocol: dtls,
1290 testType: serverTest,
1291 name: "FragmentAlert-DTLS",
1292 config: Config{
1293 Bugs: ProtocolBugs{
1294 FragmentAlert: true,
1295 SendSpuriousAlert: alertRecordOverflow,
1296 },
1297 },
1298 shouldFail: true,
1299 expectedError: ":BAD_ALERT:",
1300 },
1301 {
1302 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001303 name: "DoubleAlert",
1304 config: Config{
1305 Bugs: ProtocolBugs{
1306 DoubleAlert: true,
1307 SendSpuriousAlert: alertRecordOverflow,
1308 },
1309 },
1310 shouldFail: true,
1311 expectedError: ":BAD_ALERT:",
1312 },
1313 {
1314 protocol: dtls,
1315 testType: serverTest,
1316 name: "DoubleAlert-DTLS",
1317 config: Config{
1318 Bugs: ProtocolBugs{
1319 DoubleAlert: true,
1320 SendSpuriousAlert: alertRecordOverflow,
1321 },
1322 },
1323 shouldFail: true,
1324 expectedError: ":BAD_ALERT:",
1325 },
1326 {
Adam Langley7c803a62015-06-15 15:35:05 -07001327 name: "SkipNewSessionTicket",
1328 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001329 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001330 Bugs: ProtocolBugs{
1331 SkipNewSessionTicket: true,
1332 },
1333 },
1334 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001335 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001336 },
1337 {
1338 testType: serverTest,
1339 name: "FallbackSCSV",
1340 config: Config{
1341 MaxVersion: VersionTLS11,
1342 Bugs: ProtocolBugs{
1343 SendFallbackSCSV: true,
1344 },
1345 },
David Benjamin56cadc32016-12-16 19:54:11 -05001346 shouldFail: true,
1347 expectedError: ":INAPPROPRIATE_FALLBACK:",
1348 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001349 },
1350 {
1351 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001352 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001353 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001354 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001355 Bugs: ProtocolBugs{
1356 SendFallbackSCSV: true,
1357 },
1358 },
1359 },
1360 {
1361 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001362 name: "FallbackSCSV-VersionMatch-TLS12",
1363 config: Config{
1364 MaxVersion: VersionTLS12,
1365 Bugs: ProtocolBugs{
1366 SendFallbackSCSV: true,
1367 },
1368 },
1369 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1370 },
1371 {
1372 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001373 name: "FragmentedClientVersion",
1374 config: Config{
1375 Bugs: ProtocolBugs{
1376 MaxHandshakeRecordLength: 1,
1377 FragmentClientVersion: true,
1378 },
1379 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001380 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001381 },
1382 {
Adam Langley7c803a62015-06-15 15:35:05 -07001383 testType: serverTest,
1384 name: "HttpGET",
1385 sendPrefix: "GET / HTTP/1.0\n",
1386 shouldFail: true,
1387 expectedError: ":HTTP_REQUEST:",
1388 },
1389 {
1390 testType: serverTest,
1391 name: "HttpPOST",
1392 sendPrefix: "POST / HTTP/1.0\n",
1393 shouldFail: true,
1394 expectedError: ":HTTP_REQUEST:",
1395 },
1396 {
1397 testType: serverTest,
1398 name: "HttpHEAD",
1399 sendPrefix: "HEAD / HTTP/1.0\n",
1400 shouldFail: true,
1401 expectedError: ":HTTP_REQUEST:",
1402 },
1403 {
1404 testType: serverTest,
1405 name: "HttpPUT",
1406 sendPrefix: "PUT / HTTP/1.0\n",
1407 shouldFail: true,
1408 expectedError: ":HTTP_REQUEST:",
1409 },
1410 {
1411 testType: serverTest,
1412 name: "HttpCONNECT",
1413 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1414 shouldFail: true,
1415 expectedError: ":HTTPS_PROXY_REQUEST:",
1416 },
1417 {
1418 testType: serverTest,
1419 name: "Garbage",
1420 sendPrefix: "blah",
1421 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001422 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001423 },
1424 {
Adam Langley7c803a62015-06-15 15:35:05 -07001425 name: "RSAEphemeralKey",
1426 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001427 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001428 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1429 Bugs: ProtocolBugs{
1430 RSAEphemeralKey: true,
1431 },
1432 },
1433 shouldFail: true,
1434 expectedError: ":UNEXPECTED_MESSAGE:",
1435 },
1436 {
1437 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001438 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001439 shouldFail: true,
1440 expectedError: ":WRONG_SSL_VERSION:",
1441 },
1442 {
1443 protocol: dtls,
1444 name: "DisableEverything-DTLS",
1445 flags: []string{"-no-tls12", "-no-tls1"},
1446 shouldFail: true,
1447 expectedError: ":WRONG_SSL_VERSION:",
1448 },
1449 {
Adam Langley7c803a62015-06-15 15:35:05 -07001450 protocol: dtls,
1451 testType: serverTest,
1452 name: "MTU",
1453 config: Config{
1454 Bugs: ProtocolBugs{
1455 MaxPacketLength: 256,
1456 },
1457 },
1458 flags: []string{"-mtu", "256"},
1459 },
1460 {
1461 protocol: dtls,
1462 testType: serverTest,
1463 name: "MTUExceeded",
1464 config: Config{
1465 Bugs: ProtocolBugs{
1466 MaxPacketLength: 255,
1467 },
1468 },
1469 flags: []string{"-mtu", "256"},
1470 shouldFail: true,
1471 expectedLocalError: "dtls: exceeded maximum packet length",
1472 },
1473 {
1474 name: "CertMismatchRSA",
1475 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001476 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001477 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001478 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001479 Bugs: ProtocolBugs{
1480 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1485 },
1486 {
1487 name: "CertMismatchECDSA",
1488 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001489 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001490 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001491 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001492 Bugs: ProtocolBugs{
1493 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1494 },
1495 },
1496 shouldFail: true,
1497 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1498 },
1499 {
1500 name: "EmptyCertificateList",
1501 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001502 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001503 Bugs: ProtocolBugs{
1504 EmptyCertificateList: true,
1505 },
1506 },
1507 shouldFail: true,
1508 expectedError: ":DECODE_ERROR:",
1509 },
1510 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001511 name: "EmptyCertificateList-TLS13",
1512 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001513 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001514 Bugs: ProtocolBugs{
1515 EmptyCertificateList: true,
1516 },
1517 },
1518 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001519 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001520 },
1521 {
Adam Langley7c803a62015-06-15 15:35:05 -07001522 name: "TLSFatalBadPackets",
1523 damageFirstWrite: true,
1524 shouldFail: true,
1525 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1526 },
1527 {
1528 protocol: dtls,
1529 name: "DTLSIgnoreBadPackets",
1530 damageFirstWrite: true,
1531 },
1532 {
1533 protocol: dtls,
1534 name: "DTLSIgnoreBadPackets-Async",
1535 damageFirstWrite: true,
1536 flags: []string{"-async"},
1537 },
1538 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001539 name: "AppDataBeforeHandshake",
1540 config: Config{
1541 Bugs: ProtocolBugs{
1542 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1543 },
1544 },
1545 shouldFail: true,
1546 expectedError: ":UNEXPECTED_RECORD:",
1547 },
1548 {
1549 name: "AppDataBeforeHandshake-Empty",
1550 config: Config{
1551 Bugs: ProtocolBugs{
1552 AppDataBeforeHandshake: []byte{},
1553 },
1554 },
1555 shouldFail: true,
1556 expectedError: ":UNEXPECTED_RECORD:",
1557 },
1558 {
1559 protocol: dtls,
1560 name: "AppDataBeforeHandshake-DTLS",
1561 config: Config{
1562 Bugs: ProtocolBugs{
1563 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1564 },
1565 },
1566 shouldFail: true,
1567 expectedError: ":UNEXPECTED_RECORD:",
1568 },
1569 {
1570 protocol: dtls,
1571 name: "AppDataBeforeHandshake-DTLS-Empty",
1572 config: Config{
1573 Bugs: ProtocolBugs{
1574 AppDataBeforeHandshake: []byte{},
1575 },
1576 },
1577 shouldFail: true,
1578 expectedError: ":UNEXPECTED_RECORD:",
1579 },
1580 {
Adam Langley7c803a62015-06-15 15:35:05 -07001581 name: "AppDataAfterChangeCipherSpec",
1582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001583 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001584 Bugs: ProtocolBugs{
1585 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1586 },
1587 },
1588 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001589 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001590 },
1591 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001592 name: "AppDataAfterChangeCipherSpec-Empty",
1593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001594 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001595 Bugs: ProtocolBugs{
1596 AppDataAfterChangeCipherSpec: []byte{},
1597 },
1598 },
1599 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001600 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001601 },
1602 {
Adam Langley7c803a62015-06-15 15:35:05 -07001603 protocol: dtls,
1604 name: "AppDataAfterChangeCipherSpec-DTLS",
1605 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001606 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001607 Bugs: ProtocolBugs{
1608 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1609 },
1610 },
1611 // BoringSSL's DTLS implementation will drop the out-of-order
1612 // application data.
1613 },
1614 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001615 protocol: dtls,
1616 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1617 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001618 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001619 Bugs: ProtocolBugs{
1620 AppDataAfterChangeCipherSpec: []byte{},
1621 },
1622 },
1623 // BoringSSL's DTLS implementation will drop the out-of-order
1624 // application data.
1625 },
1626 {
Adam Langley7c803a62015-06-15 15:35:05 -07001627 name: "AlertAfterChangeCipherSpec",
1628 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001629 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001630 Bugs: ProtocolBugs{
1631 AlertAfterChangeCipherSpec: alertRecordOverflow,
1632 },
1633 },
1634 shouldFail: true,
1635 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1636 },
1637 {
1638 protocol: dtls,
1639 name: "AlertAfterChangeCipherSpec-DTLS",
1640 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001641 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001642 Bugs: ProtocolBugs{
1643 AlertAfterChangeCipherSpec: alertRecordOverflow,
1644 },
1645 },
1646 shouldFail: true,
1647 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1648 },
1649 {
1650 protocol: dtls,
1651 name: "ReorderHandshakeFragments-Small-DTLS",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 ReorderHandshakeFragments: true,
1655 // Small enough that every handshake message is
1656 // fragmented.
1657 MaxHandshakeRecordLength: 2,
1658 },
1659 },
1660 },
1661 {
1662 protocol: dtls,
1663 name: "ReorderHandshakeFragments-Large-DTLS",
1664 config: Config{
1665 Bugs: ProtocolBugs{
1666 ReorderHandshakeFragments: true,
1667 // Large enough that no handshake message is
1668 // fragmented.
1669 MaxHandshakeRecordLength: 2048,
1670 },
1671 },
1672 },
1673 {
1674 protocol: dtls,
1675 name: "MixCompleteMessageWithFragments-DTLS",
1676 config: Config{
1677 Bugs: ProtocolBugs{
1678 ReorderHandshakeFragments: true,
1679 MixCompleteMessageWithFragments: true,
1680 MaxHandshakeRecordLength: 2,
1681 },
1682 },
1683 },
1684 {
1685 name: "SendInvalidRecordType",
1686 config: Config{
1687 Bugs: ProtocolBugs{
1688 SendInvalidRecordType: true,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":UNEXPECTED_RECORD:",
1693 },
1694 {
1695 protocol: dtls,
1696 name: "SendInvalidRecordType-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 SendInvalidRecordType: true,
1700 },
1701 },
1702 shouldFail: true,
1703 expectedError: ":UNEXPECTED_RECORD:",
1704 },
1705 {
1706 name: "FalseStart-SkipServerSecondLeg",
1707 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001708 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001709 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1710 NextProtos: []string{"foo"},
1711 Bugs: ProtocolBugs{
1712 SkipNewSessionTicket: true,
1713 SkipChangeCipherSpec: true,
1714 SkipFinished: true,
1715 ExpectFalseStart: true,
1716 },
1717 },
1718 flags: []string{
1719 "-false-start",
1720 "-handshake-never-done",
1721 "-advertise-alpn", "\x03foo",
1722 },
1723 shimWritesFirst: true,
1724 shouldFail: true,
1725 expectedError: ":UNEXPECTED_RECORD:",
1726 },
1727 {
1728 name: "FalseStart-SkipServerSecondLeg-Implicit",
1729 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001730 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001731 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1732 NextProtos: []string{"foo"},
1733 Bugs: ProtocolBugs{
1734 SkipNewSessionTicket: true,
1735 SkipChangeCipherSpec: true,
1736 SkipFinished: true,
1737 },
1738 },
1739 flags: []string{
1740 "-implicit-handshake",
1741 "-false-start",
1742 "-handshake-never-done",
1743 "-advertise-alpn", "\x03foo",
1744 },
1745 shouldFail: true,
1746 expectedError: ":UNEXPECTED_RECORD:",
1747 },
1748 {
1749 testType: serverTest,
1750 name: "FailEarlyCallback",
1751 flags: []string{"-fail-early-callback"},
1752 shouldFail: true,
1753 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001754 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001755 },
1756 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001757 name: "FailCertCallback-Client-TLS12",
1758 config: Config{
1759 MaxVersion: VersionTLS12,
1760 ClientAuth: RequestClientCert,
1761 },
1762 flags: []string{"-fail-cert-callback"},
1763 shouldFail: true,
1764 expectedError: ":CERT_CB_ERROR:",
1765 expectedLocalError: "remote error: internal error",
1766 },
1767 {
1768 testType: serverTest,
1769 name: "FailCertCallback-Server-TLS12",
1770 config: Config{
1771 MaxVersion: VersionTLS12,
1772 },
1773 flags: []string{"-fail-cert-callback"},
1774 shouldFail: true,
1775 expectedError: ":CERT_CB_ERROR:",
1776 expectedLocalError: "remote error: internal error",
1777 },
1778 {
1779 name: "FailCertCallback-Client-TLS13",
1780 config: Config{
1781 MaxVersion: VersionTLS13,
1782 ClientAuth: RequestClientCert,
1783 },
1784 flags: []string{"-fail-cert-callback"},
1785 shouldFail: true,
1786 expectedError: ":CERT_CB_ERROR:",
1787 expectedLocalError: "remote error: internal error",
1788 },
1789 {
1790 testType: serverTest,
1791 name: "FailCertCallback-Server-TLS13",
1792 config: Config{
1793 MaxVersion: VersionTLS13,
1794 },
1795 flags: []string{"-fail-cert-callback"},
1796 shouldFail: true,
1797 expectedError: ":CERT_CB_ERROR:",
1798 expectedLocalError: "remote error: internal error",
1799 },
1800 {
Adam Langley7c803a62015-06-15 15:35:05 -07001801 protocol: dtls,
1802 name: "FragmentMessageTypeMismatch-DTLS",
1803 config: Config{
1804 Bugs: ProtocolBugs{
1805 MaxHandshakeRecordLength: 2,
1806 FragmentMessageTypeMismatch: true,
1807 },
1808 },
1809 shouldFail: true,
1810 expectedError: ":FRAGMENT_MISMATCH:",
1811 },
1812 {
1813 protocol: dtls,
1814 name: "FragmentMessageLengthMismatch-DTLS",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 MaxHandshakeRecordLength: 2,
1818 FragmentMessageLengthMismatch: true,
1819 },
1820 },
1821 shouldFail: true,
1822 expectedError: ":FRAGMENT_MISMATCH:",
1823 },
1824 {
1825 protocol: dtls,
1826 name: "SplitFragments-Header-DTLS",
1827 config: Config{
1828 Bugs: ProtocolBugs{
1829 SplitFragments: 2,
1830 },
1831 },
1832 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001833 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001834 },
1835 {
1836 protocol: dtls,
1837 name: "SplitFragments-Boundary-DTLS",
1838 config: Config{
1839 Bugs: ProtocolBugs{
1840 SplitFragments: dtlsRecordHeaderLen,
1841 },
1842 },
1843 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001844 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001845 },
1846 {
1847 protocol: dtls,
1848 name: "SplitFragments-Body-DTLS",
1849 config: Config{
1850 Bugs: ProtocolBugs{
1851 SplitFragments: dtlsRecordHeaderLen + 1,
1852 },
1853 },
1854 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001855 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001856 },
1857 {
1858 protocol: dtls,
1859 name: "SendEmptyFragments-DTLS",
1860 config: Config{
1861 Bugs: ProtocolBugs{
1862 SendEmptyFragments: true,
1863 },
1864 },
1865 },
1866 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001867 name: "BadFinished-Client",
1868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001869 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001870 Bugs: ProtocolBugs{
1871 BadFinished: true,
1872 },
1873 },
1874 shouldFail: true,
1875 expectedError: ":DIGEST_CHECK_FAILED:",
1876 },
1877 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001878 name: "BadFinished-Client-TLS13",
1879 config: Config{
1880 MaxVersion: VersionTLS13,
1881 Bugs: ProtocolBugs{
1882 BadFinished: true,
1883 },
1884 },
1885 shouldFail: true,
1886 expectedError: ":DIGEST_CHECK_FAILED:",
1887 },
1888 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001889 testType: serverTest,
1890 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001891 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001892 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001893 Bugs: ProtocolBugs{
1894 BadFinished: true,
1895 },
1896 },
1897 shouldFail: true,
1898 expectedError: ":DIGEST_CHECK_FAILED:",
1899 },
1900 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001901 testType: serverTest,
1902 name: "BadFinished-Server-TLS13",
1903 config: Config{
1904 MaxVersion: VersionTLS13,
1905 Bugs: ProtocolBugs{
1906 BadFinished: true,
1907 },
1908 },
1909 shouldFail: true,
1910 expectedError: ":DIGEST_CHECK_FAILED:",
1911 },
1912 {
Adam Langley7c803a62015-06-15 15:35:05 -07001913 name: "FalseStart-BadFinished",
1914 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001915 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001916 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1917 NextProtos: []string{"foo"},
1918 Bugs: ProtocolBugs{
1919 BadFinished: true,
1920 ExpectFalseStart: true,
1921 },
1922 },
1923 flags: []string{
1924 "-false-start",
1925 "-handshake-never-done",
1926 "-advertise-alpn", "\x03foo",
1927 },
1928 shimWritesFirst: true,
1929 shouldFail: true,
1930 expectedError: ":DIGEST_CHECK_FAILED:",
1931 },
1932 {
1933 name: "NoFalseStart-NoALPN",
1934 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001935 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1937 Bugs: ProtocolBugs{
1938 ExpectFalseStart: true,
1939 AlertBeforeFalseStartTest: alertAccessDenied,
1940 },
1941 },
1942 flags: []string{
1943 "-false-start",
1944 },
1945 shimWritesFirst: true,
1946 shouldFail: true,
1947 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1948 expectedLocalError: "tls: peer did not false start: EOF",
1949 },
1950 {
1951 name: "NoFalseStart-NoAEAD",
1952 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001953 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1955 NextProtos: []string{"foo"},
1956 Bugs: ProtocolBugs{
1957 ExpectFalseStart: true,
1958 AlertBeforeFalseStartTest: alertAccessDenied,
1959 },
1960 },
1961 flags: []string{
1962 "-false-start",
1963 "-advertise-alpn", "\x03foo",
1964 },
1965 shimWritesFirst: true,
1966 shouldFail: true,
1967 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1968 expectedLocalError: "tls: peer did not false start: EOF",
1969 },
1970 {
1971 name: "NoFalseStart-RSA",
1972 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001973 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001974 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1975 NextProtos: []string{"foo"},
1976 Bugs: ProtocolBugs{
1977 ExpectFalseStart: true,
1978 AlertBeforeFalseStartTest: alertAccessDenied,
1979 },
1980 },
1981 flags: []string{
1982 "-false-start",
1983 "-advertise-alpn", "\x03foo",
1984 },
1985 shimWritesFirst: true,
1986 shouldFail: true,
1987 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1988 expectedLocalError: "tls: peer did not false start: EOF",
1989 },
1990 {
1991 name: "NoFalseStart-DHE_RSA",
1992 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001993 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001994 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1995 NextProtos: []string{"foo"},
1996 Bugs: ProtocolBugs{
1997 ExpectFalseStart: true,
1998 AlertBeforeFalseStartTest: alertAccessDenied,
1999 },
2000 },
2001 flags: []string{
2002 "-false-start",
2003 "-advertise-alpn", "\x03foo",
2004 },
2005 shimWritesFirst: true,
2006 shouldFail: true,
2007 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2008 expectedLocalError: "tls: peer did not false start: EOF",
2009 },
2010 {
Adam Langley7c803a62015-06-15 15:35:05 -07002011 protocol: dtls,
2012 name: "SendSplitAlert-Sync",
2013 config: Config{
2014 Bugs: ProtocolBugs{
2015 SendSplitAlert: true,
2016 },
2017 },
2018 },
2019 {
2020 protocol: dtls,
2021 name: "SendSplitAlert-Async",
2022 config: Config{
2023 Bugs: ProtocolBugs{
2024 SendSplitAlert: true,
2025 },
2026 },
2027 flags: []string{"-async"},
2028 },
2029 {
2030 protocol: dtls,
2031 name: "PackDTLSHandshake",
2032 config: Config{
2033 Bugs: ProtocolBugs{
2034 MaxHandshakeRecordLength: 2,
2035 PackHandshakeFragments: 20,
2036 PackHandshakeRecords: 200,
2037 },
2038 },
2039 },
2040 {
Adam Langley7c803a62015-06-15 15:35:05 -07002041 name: "SendEmptyRecords-Pass",
2042 sendEmptyRecords: 32,
2043 },
2044 {
2045 name: "SendEmptyRecords",
2046 sendEmptyRecords: 33,
2047 shouldFail: true,
2048 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2049 },
2050 {
2051 name: "SendEmptyRecords-Async",
2052 sendEmptyRecords: 33,
2053 flags: []string{"-async"},
2054 shouldFail: true,
2055 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2056 },
2057 {
David Benjamine8e84b92016-08-03 15:39:47 -04002058 name: "SendWarningAlerts-Pass",
2059 config: Config{
2060 MaxVersion: VersionTLS12,
2061 },
Adam Langley7c803a62015-06-15 15:35:05 -07002062 sendWarningAlerts: 4,
2063 },
2064 {
David Benjamine8e84b92016-08-03 15:39:47 -04002065 protocol: dtls,
2066 name: "SendWarningAlerts-DTLS-Pass",
2067 config: Config{
2068 MaxVersion: VersionTLS12,
2069 },
Adam Langley7c803a62015-06-15 15:35:05 -07002070 sendWarningAlerts: 4,
2071 },
2072 {
David Benjamine8e84b92016-08-03 15:39:47 -04002073 name: "SendWarningAlerts-TLS13",
2074 config: Config{
2075 MaxVersion: VersionTLS13,
2076 },
2077 sendWarningAlerts: 4,
2078 shouldFail: true,
2079 expectedError: ":BAD_ALERT:",
2080 expectedLocalError: "remote error: error decoding message",
2081 },
2082 {
2083 name: "SendWarningAlerts",
2084 config: Config{
2085 MaxVersion: VersionTLS12,
2086 },
Adam Langley7c803a62015-06-15 15:35:05 -07002087 sendWarningAlerts: 5,
2088 shouldFail: true,
2089 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2090 },
2091 {
David Benjamine8e84b92016-08-03 15:39:47 -04002092 name: "SendWarningAlerts-Async",
2093 config: Config{
2094 MaxVersion: VersionTLS12,
2095 },
Adam Langley7c803a62015-06-15 15:35:05 -07002096 sendWarningAlerts: 5,
2097 flags: []string{"-async"},
2098 shouldFail: true,
2099 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2100 },
David Benjaminba4594a2015-06-18 18:36:15 -04002101 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002102 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002103 config: Config{
2104 MaxVersion: VersionTLS13,
2105 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002106 sendKeyUpdates: 33,
2107 keyUpdateRequest: keyUpdateNotRequested,
2108 shouldFail: true,
2109 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002110 },
2111 {
David Benjaminba4594a2015-06-18 18:36:15 -04002112 name: "EmptySessionID",
2113 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002114 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002115 SessionTicketsDisabled: true,
2116 },
2117 noSessionCache: true,
2118 flags: []string{"-expect-no-session"},
2119 },
David Benjamin30789da2015-08-29 22:56:45 -04002120 {
2121 name: "Unclean-Shutdown",
2122 config: Config{
2123 Bugs: ProtocolBugs{
2124 NoCloseNotify: true,
2125 ExpectCloseNotify: true,
2126 },
2127 },
2128 shimShutsDown: true,
2129 flags: []string{"-check-close-notify"},
2130 shouldFail: true,
2131 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2132 },
2133 {
2134 name: "Unclean-Shutdown-Ignored",
2135 config: Config{
2136 Bugs: ProtocolBugs{
2137 NoCloseNotify: true,
2138 },
2139 },
2140 shimShutsDown: true,
2141 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002142 {
David Benjaminfa214e42016-05-10 17:03:10 -04002143 name: "Unclean-Shutdown-Alert",
2144 config: Config{
2145 Bugs: ProtocolBugs{
2146 SendAlertOnShutdown: alertDecompressionFailure,
2147 ExpectCloseNotify: true,
2148 },
2149 },
2150 shimShutsDown: true,
2151 flags: []string{"-check-close-notify"},
2152 shouldFail: true,
2153 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2154 },
2155 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002156 name: "LargePlaintext",
2157 config: Config{
2158 Bugs: ProtocolBugs{
2159 SendLargeRecords: true,
2160 },
2161 },
2162 messageLen: maxPlaintext + 1,
2163 shouldFail: true,
2164 expectedError: ":DATA_LENGTH_TOO_LONG:",
2165 },
2166 {
2167 protocol: dtls,
2168 name: "LargePlaintext-DTLS",
2169 config: Config{
2170 Bugs: ProtocolBugs{
2171 SendLargeRecords: true,
2172 },
2173 },
2174 messageLen: maxPlaintext + 1,
2175 shouldFail: true,
2176 expectedError: ":DATA_LENGTH_TOO_LONG:",
2177 },
2178 {
2179 name: "LargeCiphertext",
2180 config: Config{
2181 Bugs: ProtocolBugs{
2182 SendLargeRecords: true,
2183 },
2184 },
2185 messageLen: maxPlaintext * 2,
2186 shouldFail: true,
2187 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2188 },
2189 {
2190 protocol: dtls,
2191 name: "LargeCiphertext-DTLS",
2192 config: Config{
2193 Bugs: ProtocolBugs{
2194 SendLargeRecords: true,
2195 },
2196 },
2197 messageLen: maxPlaintext * 2,
2198 // Unlike the other four cases, DTLS drops records which
2199 // are invalid before authentication, so the connection
2200 // does not fail.
2201 expectMessageDropped: true,
2202 },
David Benjamindd6fed92015-10-23 17:41:12 -04002203 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002204 name: "BadHelloRequest-1",
2205 renegotiate: 1,
2206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002207 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002208 Bugs: ProtocolBugs{
2209 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2210 },
2211 },
2212 flags: []string{
2213 "-renegotiate-freely",
2214 "-expect-total-renegotiations", "1",
2215 },
2216 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002217 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002218 },
2219 {
2220 name: "BadHelloRequest-2",
2221 renegotiate: 1,
2222 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002223 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002224 Bugs: ProtocolBugs{
2225 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2226 },
2227 },
2228 flags: []string{
2229 "-renegotiate-freely",
2230 "-expect-total-renegotiations", "1",
2231 },
2232 shouldFail: true,
2233 expectedError: ":BAD_HELLO_REQUEST:",
2234 },
David Benjaminef1b0092015-11-21 14:05:44 -05002235 {
2236 testType: serverTest,
2237 name: "SupportTicketsWithSessionID",
2238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002239 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002240 SessionTicketsDisabled: true,
2241 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002242 resumeConfig: &Config{
2243 MaxVersion: VersionTLS12,
2244 },
David Benjaminef1b0092015-11-21 14:05:44 -05002245 resumeSession: true,
2246 },
David Benjamin02edcd02016-07-27 17:40:37 -04002247 {
2248 protocol: dtls,
2249 name: "DTLS-SendExtraFinished",
2250 config: Config{
2251 Bugs: ProtocolBugs{
2252 SendExtraFinished: true,
2253 },
2254 },
2255 shouldFail: true,
2256 expectedError: ":UNEXPECTED_RECORD:",
2257 },
2258 {
2259 protocol: dtls,
2260 name: "DTLS-SendExtraFinished-Reordered",
2261 config: Config{
2262 Bugs: ProtocolBugs{
2263 MaxHandshakeRecordLength: 2,
2264 ReorderHandshakeFragments: true,
2265 SendExtraFinished: true,
2266 },
2267 },
2268 shouldFail: true,
2269 expectedError: ":UNEXPECTED_RECORD:",
2270 },
David Benjamine97fb482016-07-29 09:23:07 -04002271 {
2272 testType: serverTest,
2273 name: "V2ClientHello-EmptyRecordPrefix",
2274 config: Config{
2275 // Choose a cipher suite that does not involve
2276 // elliptic curves, so no extensions are
2277 // involved.
2278 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002279 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002280 Bugs: ProtocolBugs{
2281 SendV2ClientHello: true,
2282 },
2283 },
2284 sendPrefix: string([]byte{
2285 byte(recordTypeHandshake),
2286 3, 1, // version
2287 0, 0, // length
2288 }),
2289 // A no-op empty record may not be sent before V2ClientHello.
2290 shouldFail: true,
2291 expectedError: ":WRONG_VERSION_NUMBER:",
2292 },
2293 {
2294 testType: serverTest,
2295 name: "V2ClientHello-WarningAlertPrefix",
2296 config: Config{
2297 // Choose a cipher suite that does not involve
2298 // elliptic curves, so no extensions are
2299 // involved.
2300 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002301 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002302 Bugs: ProtocolBugs{
2303 SendV2ClientHello: true,
2304 },
2305 },
2306 sendPrefix: string([]byte{
2307 byte(recordTypeAlert),
2308 3, 1, // version
2309 0, 2, // length
2310 alertLevelWarning, byte(alertDecompressionFailure),
2311 }),
2312 // A no-op warning alert may not be sent before V2ClientHello.
2313 shouldFail: true,
2314 expectedError: ":WRONG_VERSION_NUMBER:",
2315 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002316 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002317 name: "KeyUpdate-Client",
2318 config: Config{
2319 MaxVersion: VersionTLS13,
2320 },
2321 sendKeyUpdates: 1,
2322 keyUpdateRequest: keyUpdateNotRequested,
2323 },
2324 {
2325 testType: serverTest,
2326 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002327 config: Config{
2328 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002329 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002330 sendKeyUpdates: 1,
2331 keyUpdateRequest: keyUpdateNotRequested,
2332 },
2333 {
2334 name: "KeyUpdate-InvalidRequestMode",
2335 config: Config{
2336 MaxVersion: VersionTLS13,
2337 },
2338 sendKeyUpdates: 1,
2339 keyUpdateRequest: 42,
2340 shouldFail: true,
2341 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002342 },
David Benjaminabe94e32016-09-04 14:18:58 -04002343 {
2344 name: "SendSNIWarningAlert",
2345 config: Config{
2346 MaxVersion: VersionTLS12,
2347 Bugs: ProtocolBugs{
2348 SendSNIWarningAlert: true,
2349 },
2350 },
2351 },
David Benjaminc241d792016-09-09 10:34:20 -04002352 {
2353 testType: serverTest,
2354 name: "ExtraCompressionMethods-TLS12",
2355 config: Config{
2356 MaxVersion: VersionTLS12,
2357 Bugs: ProtocolBugs{
2358 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2359 },
2360 },
2361 },
2362 {
2363 testType: serverTest,
2364 name: "ExtraCompressionMethods-TLS13",
2365 config: Config{
2366 MaxVersion: VersionTLS13,
2367 Bugs: ProtocolBugs{
2368 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2369 },
2370 },
2371 shouldFail: true,
2372 expectedError: ":INVALID_COMPRESSION_LIST:",
2373 expectedLocalError: "remote error: illegal parameter",
2374 },
2375 {
2376 testType: serverTest,
2377 name: "NoNullCompression-TLS12",
2378 config: Config{
2379 MaxVersion: VersionTLS12,
2380 Bugs: ProtocolBugs{
2381 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2382 },
2383 },
2384 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002385 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002386 expectedLocalError: "remote error: illegal parameter",
2387 },
2388 {
2389 testType: serverTest,
2390 name: "NoNullCompression-TLS13",
2391 config: Config{
2392 MaxVersion: VersionTLS13,
2393 Bugs: ProtocolBugs{
2394 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2395 },
2396 },
2397 shouldFail: true,
2398 expectedError: ":INVALID_COMPRESSION_LIST:",
2399 expectedLocalError: "remote error: illegal parameter",
2400 },
David Benjamin65ac9972016-09-02 21:35:25 -04002401 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002402 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002403 config: Config{
2404 MaxVersion: VersionTLS12,
2405 Bugs: ProtocolBugs{
2406 ExpectGREASE: true,
2407 },
2408 },
2409 flags: []string{"-enable-grease"},
2410 },
2411 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002412 name: "GREASE-Client-TLS13",
2413 config: Config{
2414 MaxVersion: VersionTLS13,
2415 Bugs: ProtocolBugs{
2416 ExpectGREASE: true,
2417 },
2418 },
2419 flags: []string{"-enable-grease"},
2420 },
2421 {
2422 testType: serverTest,
2423 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002424 config: Config{
2425 MaxVersion: VersionTLS13,
2426 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002427 // TLS 1.3 servers are expected to
2428 // always enable GREASE. TLS 1.3 is new,
2429 // so there is no existing ecosystem to
2430 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002431 ExpectGREASE: true,
2432 },
2433 },
David Benjamin65ac9972016-09-02 21:35:25 -04002434 },
David Benjamine3fbb362017-01-06 16:19:28 -05002435 {
2436 // Test the server so there is a large certificate as
2437 // well as application data.
2438 testType: serverTest,
2439 name: "MaxSendFragment",
2440 config: Config{
2441 Bugs: ProtocolBugs{
2442 MaxReceivePlaintext: 512,
2443 },
2444 },
2445 messageLen: 1024,
2446 flags: []string{
2447 "-max-send-fragment", "512",
2448 "-read-size", "1024",
2449 },
2450 },
2451 {
2452 // Test the server so there is a large certificate as
2453 // well as application data.
2454 testType: serverTest,
2455 name: "MaxSendFragment-TooLarge",
2456 config: Config{
2457 Bugs: ProtocolBugs{
2458 // Ensure that some of the records are
2459 // 512.
2460 MaxReceivePlaintext: 511,
2461 },
2462 },
2463 messageLen: 1024,
2464 flags: []string{
2465 "-max-send-fragment", "512",
2466 "-read-size", "1024",
2467 },
2468 shouldFail: true,
2469 expectedLocalError: "local error: record overflow",
2470 },
Adam Langley7c803a62015-06-15 15:35:05 -07002471 }
Adam Langley7c803a62015-06-15 15:35:05 -07002472 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002473
2474 // Test that very large messages can be received.
2475 cert := rsaCertificate
2476 for i := 0; i < 50; i++ {
2477 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2478 }
2479 testCases = append(testCases, testCase{
2480 name: "LargeMessage",
2481 config: Config{
2482 Certificates: []Certificate{cert},
2483 },
2484 })
2485 testCases = append(testCases, testCase{
2486 protocol: dtls,
2487 name: "LargeMessage-DTLS",
2488 config: Config{
2489 Certificates: []Certificate{cert},
2490 },
2491 })
2492
2493 // They are rejected if the maximum certificate chain length is capped.
2494 testCases = append(testCases, testCase{
2495 name: "LargeMessage-Reject",
2496 config: Config{
2497 Certificates: []Certificate{cert},
2498 },
2499 flags: []string{"-max-cert-list", "16384"},
2500 shouldFail: true,
2501 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2502 })
2503 testCases = append(testCases, testCase{
2504 protocol: dtls,
2505 name: "LargeMessage-Reject-DTLS",
2506 config: Config{
2507 Certificates: []Certificate{cert},
2508 },
2509 flags: []string{"-max-cert-list", "16384"},
2510 shouldFail: true,
2511 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2512 })
Adam Langley7c803a62015-06-15 15:35:05 -07002513}
2514
David Benjaminaa012042016-12-10 13:33:05 -05002515func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2516 const psk = "12345"
2517 const pskIdentity = "luggage combo"
2518
2519 var prefix string
2520 if protocol == dtls {
2521 if !ver.hasDTLS {
2522 return
2523 }
2524 prefix = "D"
2525 }
2526
2527 var cert Certificate
2528 var certFile string
2529 var keyFile string
2530 if hasComponent(suite.name, "ECDSA") {
2531 cert = ecdsaP256Certificate
2532 certFile = ecdsaP256CertificateFile
2533 keyFile = ecdsaP256KeyFile
2534 } else {
2535 cert = rsaCertificate
2536 certFile = rsaCertificateFile
2537 keyFile = rsaKeyFile
2538 }
2539
2540 var flags []string
2541 if hasComponent(suite.name, "PSK") {
2542 flags = append(flags,
2543 "-psk", psk,
2544 "-psk-identity", pskIdentity)
2545 }
2546 if hasComponent(suite.name, "NULL") {
2547 // NULL ciphers must be explicitly enabled.
2548 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2549 }
David Benjaminaa012042016-12-10 13:33:05 -05002550
2551 var shouldServerFail, shouldClientFail bool
2552 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2553 // BoringSSL clients accept ECDHE on SSLv3, but
2554 // a BoringSSL server will never select it
2555 // because the extension is missing.
2556 shouldServerFail = true
2557 }
2558 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2559 shouldClientFail = true
2560 shouldServerFail = true
2561 }
2562 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2563 shouldClientFail = true
2564 shouldServerFail = true
2565 }
2566 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2567 shouldClientFail = true
2568 shouldServerFail = true
2569 }
2570 if !isDTLSCipher(suite.name) && protocol == dtls {
2571 shouldClientFail = true
2572 shouldServerFail = true
2573 }
2574
2575 var sendCipherSuite uint16
2576 var expectedServerError, expectedClientError string
2577 serverCipherSuites := []uint16{suite.id}
2578 if shouldServerFail {
2579 expectedServerError = ":NO_SHARED_CIPHER:"
2580 }
2581 if shouldClientFail {
2582 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2583 // Configure the server to select ciphers as normal but
2584 // select an incompatible cipher in ServerHello.
2585 serverCipherSuites = nil
2586 sendCipherSuite = suite.id
2587 }
2588
David Benjamincdb6fe92017-02-07 16:06:48 -05002589 // For cipher suites and versions where exporters are defined, verify
2590 // that they interoperate.
2591 var exportKeyingMaterial int
2592 if ver.version > VersionSSL30 {
2593 exportKeyingMaterial = 1024
2594 }
2595
David Benjaminaa012042016-12-10 13:33:05 -05002596 testCases = append(testCases, testCase{
2597 testType: serverTest,
2598 protocol: protocol,
2599 name: prefix + ver.name + "-" + suite.name + "-server",
2600 config: Config{
2601 MinVersion: ver.version,
2602 MaxVersion: ver.version,
2603 CipherSuites: []uint16{suite.id},
2604 Certificates: []Certificate{cert},
2605 PreSharedKey: []byte(psk),
2606 PreSharedKeyIdentity: pskIdentity,
2607 Bugs: ProtocolBugs{
2608 AdvertiseAllConfiguredCiphers: true,
2609 },
2610 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002611 certFile: certFile,
2612 keyFile: keyFile,
2613 flags: flags,
2614 resumeSession: true,
2615 shouldFail: shouldServerFail,
2616 expectedError: expectedServerError,
2617 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002618 })
2619
2620 testCases = append(testCases, testCase{
2621 testType: clientTest,
2622 protocol: protocol,
2623 name: prefix + ver.name + "-" + suite.name + "-client",
2624 config: Config{
2625 MinVersion: ver.version,
2626 MaxVersion: ver.version,
2627 CipherSuites: serverCipherSuites,
2628 Certificates: []Certificate{cert},
2629 PreSharedKey: []byte(psk),
2630 PreSharedKeyIdentity: pskIdentity,
2631 Bugs: ProtocolBugs{
2632 IgnorePeerCipherPreferences: shouldClientFail,
2633 SendCipherSuite: sendCipherSuite,
2634 },
2635 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002636 flags: flags,
2637 resumeSession: true,
2638 shouldFail: shouldClientFail,
2639 expectedError: expectedClientError,
2640 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002641 })
2642
David Benjamin6f600d62016-12-21 16:06:54 -05002643 if shouldClientFail {
2644 return
2645 }
2646
2647 // Ensure the maximum record size is accepted.
2648 testCases = append(testCases, testCase{
2649 protocol: protocol,
2650 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2651 config: Config{
2652 MinVersion: ver.version,
2653 MaxVersion: ver.version,
2654 CipherSuites: []uint16{suite.id},
2655 Certificates: []Certificate{cert},
2656 PreSharedKey: []byte(psk),
2657 PreSharedKeyIdentity: pskIdentity,
2658 },
2659 flags: flags,
2660 messageLen: maxPlaintext,
2661 })
2662
2663 // Test bad records for all ciphers. Bad records are fatal in TLS
2664 // and ignored in DTLS.
2665 var shouldFail bool
2666 var expectedError string
2667 if protocol == tls {
2668 shouldFail = true
2669 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2670 }
2671
2672 testCases = append(testCases, testCase{
2673 protocol: protocol,
2674 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2675 config: Config{
2676 MinVersion: ver.version,
2677 MaxVersion: ver.version,
2678 CipherSuites: []uint16{suite.id},
2679 Certificates: []Certificate{cert},
2680 PreSharedKey: []byte(psk),
2681 PreSharedKeyIdentity: pskIdentity,
2682 },
2683 flags: flags,
2684 damageFirstWrite: true,
2685 messageLen: maxPlaintext,
2686 shouldFail: shouldFail,
2687 expectedError: expectedError,
2688 })
2689
2690 if ver.version >= VersionTLS13 {
David Benjaminaa012042016-12-10 13:33:05 -05002691 testCases = append(testCases, testCase{
2692 protocol: protocol,
David Benjamin6f600d62016-12-21 16:06:54 -05002693 name: prefix + ver.name + "-" + suite.name + "-ShortHeader",
David Benjaminaa012042016-12-10 13:33:05 -05002694 config: Config{
2695 MinVersion: ver.version,
2696 MaxVersion: ver.version,
2697 CipherSuites: []uint16{suite.id},
2698 Certificates: []Certificate{cert},
2699 PreSharedKey: []byte(psk),
2700 PreSharedKeyIdentity: pskIdentity,
David Benjamin6f600d62016-12-21 16:06:54 -05002701 Bugs: ProtocolBugs{
2702 EnableShortHeader: true,
2703 },
David Benjaminaa012042016-12-10 13:33:05 -05002704 },
David Benjamin6f600d62016-12-21 16:06:54 -05002705 flags: append([]string{"-enable-short-header"}, flags...),
2706 resumeSession: true,
2707 expectShortHeader: true,
David Benjaminaa012042016-12-10 13:33:05 -05002708 })
2709 }
2710}
2711
Adam Langley95c29f32014-06-20 12:00:00 -07002712func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002713 const bogusCipher = 0xfe00
2714
Adam Langley95c29f32014-06-20 12:00:00 -07002715 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002716 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002717 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002718 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002719 }
David Benjamin2c99d282015-09-01 10:23:00 -04002720 }
Adam Langley95c29f32014-06-20 12:00:00 -07002721 }
Adam Langleya7997f12015-05-14 17:38:50 -07002722
2723 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002724 name: "NoSharedCipher",
2725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002726 MaxVersion: VersionTLS12,
2727 CipherSuites: []uint16{},
2728 },
2729 shouldFail: true,
2730 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2731 })
2732
2733 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002734 name: "NoSharedCipher-TLS13",
2735 config: Config{
2736 MaxVersion: VersionTLS13,
2737 CipherSuites: []uint16{},
2738 },
2739 shouldFail: true,
2740 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2741 })
2742
2743 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002744 name: "UnsupportedCipherSuite",
2745 config: Config{
2746 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002747 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002748 Bugs: ProtocolBugs{
2749 IgnorePeerCipherPreferences: true,
2750 },
2751 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002752 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002753 shouldFail: true,
2754 expectedError: ":WRONG_CIPHER_RETURNED:",
2755 })
2756
2757 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002758 name: "ServerHelloBogusCipher",
2759 config: Config{
2760 MaxVersion: VersionTLS12,
2761 Bugs: ProtocolBugs{
2762 SendCipherSuite: bogusCipher,
2763 },
2764 },
2765 shouldFail: true,
2766 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2767 })
2768 testCases = append(testCases, testCase{
2769 name: "ServerHelloBogusCipher-TLS13",
2770 config: Config{
2771 MaxVersion: VersionTLS13,
2772 Bugs: ProtocolBugs{
2773 SendCipherSuite: bogusCipher,
2774 },
2775 },
2776 shouldFail: true,
2777 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2778 })
2779
2780 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002781 name: "WeakDH",
2782 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002783 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002784 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2785 Bugs: ProtocolBugs{
2786 // This is a 1023-bit prime number, generated
2787 // with:
2788 // openssl gendh 1023 | openssl asn1parse -i
2789 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2790 },
2791 },
2792 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002793 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002794 })
Adam Langleycef75832015-09-03 14:51:12 -07002795
David Benjamincd24a392015-11-11 13:23:05 -08002796 testCases = append(testCases, testCase{
2797 name: "SillyDH",
2798 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002799 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002800 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2801 Bugs: ProtocolBugs{
2802 // This is a 4097-bit prime number, generated
2803 // with:
2804 // openssl gendh 4097 | openssl asn1parse -i
2805 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2806 },
2807 },
2808 shouldFail: true,
2809 expectedError: ":DH_P_TOO_LONG:",
2810 })
2811
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002812 // This test ensures that Diffie-Hellman public values are padded with
2813 // zeros so that they're the same length as the prime. This is to avoid
2814 // hitting a bug in yaSSL.
2815 testCases = append(testCases, testCase{
2816 testType: serverTest,
2817 name: "DHPublicValuePadded",
2818 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002819 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002820 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2821 Bugs: ProtocolBugs{
2822 RequireDHPublicValueLen: (1025 + 7) / 8,
2823 },
2824 },
2825 flags: []string{"-use-sparse-dh-prime"},
2826 })
David Benjamincd24a392015-11-11 13:23:05 -08002827
David Benjamin241ae832016-01-15 03:04:54 -05002828 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002829 testCases = append(testCases, testCase{
2830 testType: serverTest,
2831 name: "UnknownCipher",
2832 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002833 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002834 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002835 Bugs: ProtocolBugs{
2836 AdvertiseAllConfiguredCiphers: true,
2837 },
2838 },
2839 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002840
2841 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002842 testCases = append(testCases, testCase{
2843 testType: serverTest,
2844 name: "UnknownCipher-TLS13",
2845 config: Config{
2846 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002847 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002848 Bugs: ProtocolBugs{
2849 AdvertiseAllConfiguredCiphers: true,
2850 },
David Benjamin241ae832016-01-15 03:04:54 -05002851 },
2852 })
2853
David Benjamin78679342016-09-16 19:42:05 -04002854 // Test empty ECDHE_PSK identity hints work as expected.
2855 testCases = append(testCases, testCase{
2856 name: "EmptyECDHEPSKHint",
2857 config: Config{
2858 MaxVersion: VersionTLS12,
2859 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2860 PreSharedKey: []byte("secret"),
2861 },
2862 flags: []string{"-psk", "secret"},
2863 })
2864
2865 // Test empty PSK identity hints work as expected, even if an explicit
2866 // ServerKeyExchange is sent.
2867 testCases = append(testCases, testCase{
2868 name: "ExplicitEmptyPSKHint",
2869 config: Config{
2870 MaxVersion: VersionTLS12,
2871 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2872 PreSharedKey: []byte("secret"),
2873 Bugs: ProtocolBugs{
2874 AlwaysSendPreSharedKeyIdentityHint: true,
2875 },
2876 },
2877 flags: []string{"-psk", "secret"},
2878 })
Adam Langley95c29f32014-06-20 12:00:00 -07002879}
2880
2881func addBadECDSASignatureTests() {
2882 for badR := BadValue(1); badR < NumBadValues; badR++ {
2883 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002884 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002885 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2886 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002887 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002888 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002889 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002890 Bugs: ProtocolBugs{
2891 BadECDSAR: badR,
2892 BadECDSAS: badS,
2893 },
2894 },
2895 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002896 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002897 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002898 testCases = append(testCases, testCase{
2899 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2900 config: Config{
2901 MaxVersion: VersionTLS13,
2902 Certificates: []Certificate{ecdsaP256Certificate},
2903 Bugs: ProtocolBugs{
2904 BadECDSAR: badR,
2905 BadECDSAS: badS,
2906 },
2907 },
2908 shouldFail: true,
2909 expectedError: ":BAD_SIGNATURE:",
2910 })
Adam Langley95c29f32014-06-20 12:00:00 -07002911 }
2912 }
2913}
2914
Adam Langley80842bd2014-06-20 12:00:00 -07002915func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002916 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002917 name: "MaxCBCPadding",
2918 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002919 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002920 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2921 Bugs: ProtocolBugs{
2922 MaxPadding: true,
2923 },
2924 },
2925 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2926 })
David Benjamin025b3d32014-07-01 19:53:04 -04002927 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002928 name: "BadCBCPadding",
2929 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002930 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2932 Bugs: ProtocolBugs{
2933 PaddingFirstByteBad: true,
2934 },
2935 },
2936 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002937 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002938 })
2939 // OpenSSL previously had an issue where the first byte of padding in
2940 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002941 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002942 name: "BadCBCPadding255",
2943 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002944 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2946 Bugs: ProtocolBugs{
2947 MaxPadding: true,
2948 PaddingFirstByteBadIf255: true,
2949 },
2950 },
2951 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2952 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002953 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002954 })
2955}
2956
Kenny Root7fdeaf12014-08-05 15:23:37 -07002957func addCBCSplittingTests() {
2958 testCases = append(testCases, testCase{
2959 name: "CBCRecordSplitting",
2960 config: Config{
2961 MaxVersion: VersionTLS10,
2962 MinVersion: VersionTLS10,
2963 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2964 },
David Benjaminac8302a2015-09-01 17:18:15 -04002965 messageLen: -1, // read until EOF
2966 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002967 flags: []string{
2968 "-async",
2969 "-write-different-record-sizes",
2970 "-cbc-record-splitting",
2971 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002972 })
2973 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002974 name: "CBCRecordSplittingPartialWrite",
2975 config: Config{
2976 MaxVersion: VersionTLS10,
2977 MinVersion: VersionTLS10,
2978 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2979 },
2980 messageLen: -1, // read until EOF
2981 flags: []string{
2982 "-async",
2983 "-write-different-record-sizes",
2984 "-cbc-record-splitting",
2985 "-partial-write",
2986 },
2987 })
2988}
2989
David Benjamin636293b2014-07-08 17:59:18 -04002990func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002991 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04002992 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08002993 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
2994 cert, err := x509.ParseCertificate(cert.Certificate[0])
2995 if err != nil {
2996 panic(err)
2997 }
2998 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04002999 }
Adam Langley2ff79332017-02-28 13:45:39 -08003000 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04003001
David Benjamin636293b2014-07-08 17:59:18 -04003002 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04003003 testCases = append(testCases, testCase{
3004 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04003005 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04003006 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003007 MinVersion: ver.version,
3008 MaxVersion: ver.version,
3009 ClientAuth: RequireAnyClientCert,
3010 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04003011 },
3012 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003013 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3014 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04003015 },
3016 })
3017 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003018 testType: serverTest,
3019 name: ver.name + "-Server-ClientAuth-RSA",
3020 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003021 MinVersion: ver.version,
3022 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003023 Certificates: []Certificate{rsaCertificate},
3024 },
3025 flags: []string{"-require-any-client-certificate"},
3026 })
David Benjamine098ec22014-08-27 23:13:20 -04003027 if ver.version != VersionSSL30 {
3028 testCases = append(testCases, testCase{
3029 testType: serverTest,
3030 name: ver.name + "-Server-ClientAuth-ECDSA",
3031 config: Config{
3032 MinVersion: ver.version,
3033 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003034 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003035 },
3036 flags: []string{"-require-any-client-certificate"},
3037 })
3038 testCases = append(testCases, testCase{
3039 testType: clientTest,
3040 name: ver.name + "-Client-ClientAuth-ECDSA",
3041 config: Config{
3042 MinVersion: ver.version,
3043 MaxVersion: ver.version,
3044 ClientAuth: RequireAnyClientCert,
3045 ClientCAs: certPool,
3046 },
3047 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003048 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3049 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003050 },
3051 })
3052 }
Adam Langley37646832016-08-01 16:16:46 -07003053
3054 testCases = append(testCases, testCase{
3055 name: "NoClientCertificate-" + ver.name,
3056 config: Config{
3057 MinVersion: ver.version,
3058 MaxVersion: ver.version,
3059 ClientAuth: RequireAnyClientCert,
3060 },
3061 shouldFail: true,
3062 expectedLocalError: "client didn't provide a certificate",
3063 })
3064
3065 testCases = append(testCases, testCase{
3066 // Even if not configured to expect a certificate, OpenSSL will
3067 // return X509_V_OK as the verify_result.
3068 testType: serverTest,
3069 name: "NoClientCertificateRequested-Server-" + ver.name,
3070 config: Config{
3071 MinVersion: ver.version,
3072 MaxVersion: ver.version,
3073 },
3074 flags: []string{
3075 "-expect-verify-result",
3076 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003077 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003078 })
3079
3080 testCases = append(testCases, testCase{
3081 // If a client certificate is not provided, OpenSSL will still
3082 // return X509_V_OK as the verify_result.
3083 testType: serverTest,
3084 name: "NoClientCertificate-Server-" + ver.name,
3085 config: Config{
3086 MinVersion: ver.version,
3087 MaxVersion: ver.version,
3088 },
3089 flags: []string{
3090 "-expect-verify-result",
3091 "-verify-peer",
3092 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003093 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003094 })
3095
David Benjamin1db9e1b2016-10-07 20:51:43 -04003096 certificateRequired := "remote error: certificate required"
3097 if ver.version < VersionTLS13 {
3098 // Prior to TLS 1.3, the generic handshake_failure alert
3099 // was used.
3100 certificateRequired = "remote error: handshake failure"
3101 }
Adam Langley37646832016-08-01 16:16:46 -07003102 testCases = append(testCases, testCase{
3103 testType: serverTest,
3104 name: "RequireAnyClientCertificate-" + ver.name,
3105 config: Config{
3106 MinVersion: ver.version,
3107 MaxVersion: ver.version,
3108 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003109 flags: []string{"-require-any-client-certificate"},
3110 shouldFail: true,
3111 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3112 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003113 })
3114
3115 if ver.version != VersionSSL30 {
3116 testCases = append(testCases, testCase{
3117 testType: serverTest,
3118 name: "SkipClientCertificate-" + ver.name,
3119 config: Config{
3120 MinVersion: ver.version,
3121 MaxVersion: ver.version,
3122 Bugs: ProtocolBugs{
3123 SkipClientCertificate: true,
3124 },
3125 },
3126 // Setting SSL_VERIFY_PEER allows anonymous clients.
3127 flags: []string{"-verify-peer"},
3128 shouldFail: true,
3129 expectedError: ":UNEXPECTED_MESSAGE:",
3130 })
3131 }
Adam Langley2ff79332017-02-28 13:45:39 -08003132
3133 testCases = append(testCases, testCase{
3134 testType: serverTest,
3135 name: ver.name + "-Server-CertReq-CA-List",
3136 config: Config{
3137 MinVersion: ver.version,
3138 MaxVersion: ver.version,
3139 Certificates: []Certificate{rsaCertificate},
3140 Bugs: ProtocolBugs{
3141 ExpectCertificateReqNames: caNames,
3142 },
3143 },
3144 flags: []string{
3145 "-require-any-client-certificate",
3146 "-use-client-ca-list", encodeDERValues(caNames),
3147 },
3148 })
3149
3150 testCases = append(testCases, testCase{
3151 testType: clientTest,
3152 name: ver.name + "-Client-CertReq-CA-List",
3153 config: Config{
3154 MinVersion: ver.version,
3155 MaxVersion: ver.version,
3156 Certificates: []Certificate{rsaCertificate},
3157 ClientAuth: RequireAnyClientCert,
3158 ClientCAs: certPool,
3159 },
3160 flags: []string{
3161 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3162 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3163 "-expect-client-ca-list", encodeDERValues(caNames),
3164 },
3165 })
David Benjamin636293b2014-07-08 17:59:18 -04003166 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003167
David Benjaminc032dfa2016-05-12 14:54:57 -04003168 // Client auth is only legal in certificate-based ciphers.
3169 testCases = append(testCases, testCase{
3170 testType: clientTest,
3171 name: "ClientAuth-PSK",
3172 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003173 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003174 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3175 PreSharedKey: []byte("secret"),
3176 ClientAuth: RequireAnyClientCert,
3177 },
3178 flags: []string{
3179 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3180 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3181 "-psk", "secret",
3182 },
3183 shouldFail: true,
3184 expectedError: ":UNEXPECTED_MESSAGE:",
3185 })
3186 testCases = append(testCases, testCase{
3187 testType: clientTest,
3188 name: "ClientAuth-ECDHE_PSK",
3189 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003190 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003191 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3192 PreSharedKey: []byte("secret"),
3193 ClientAuth: RequireAnyClientCert,
3194 },
3195 flags: []string{
3196 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3197 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3198 "-psk", "secret",
3199 },
3200 shouldFail: true,
3201 expectedError: ":UNEXPECTED_MESSAGE:",
3202 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003203
3204 // Regression test for a bug where the client CA list, if explicitly
3205 // set to NULL, was mis-encoded.
3206 testCases = append(testCases, testCase{
3207 testType: serverTest,
3208 name: "Null-Client-CA-List",
3209 config: Config{
3210 MaxVersion: VersionTLS12,
3211 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003212 Bugs: ProtocolBugs{
3213 ExpectCertificateReqNames: [][]byte{},
3214 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003215 },
3216 flags: []string{
3217 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003218 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003219 },
3220 })
David Benjamin636293b2014-07-08 17:59:18 -04003221}
3222
Adam Langley75712922014-10-10 16:23:43 -07003223func addExtendedMasterSecretTests() {
3224 const expectEMSFlag = "-expect-extended-master-secret"
3225
3226 for _, with := range []bool{false, true} {
3227 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003228 if with {
3229 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003230 }
3231
3232 for _, isClient := range []bool{false, true} {
3233 suffix := "-Server"
3234 testType := serverTest
3235 if isClient {
3236 suffix = "-Client"
3237 testType = clientTest
3238 }
3239
3240 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003241 // In TLS 1.3, the extension is irrelevant and
3242 // always reports as enabled.
3243 var flags []string
3244 if with || ver.version >= VersionTLS13 {
3245 flags = []string{expectEMSFlag}
3246 }
3247
Adam Langley75712922014-10-10 16:23:43 -07003248 test := testCase{
3249 testType: testType,
3250 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3251 config: Config{
3252 MinVersion: ver.version,
3253 MaxVersion: ver.version,
3254 Bugs: ProtocolBugs{
3255 NoExtendedMasterSecret: !with,
3256 RequireExtendedMasterSecret: with,
3257 },
3258 },
David Benjamin48cae082014-10-27 01:06:24 -04003259 flags: flags,
3260 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003261 }
3262 if test.shouldFail {
3263 test.expectedLocalError = "extended master secret required but not supported by peer"
3264 }
3265 testCases = append(testCases, test)
3266 }
3267 }
3268 }
3269
Adam Langleyba5934b2015-06-02 10:50:35 -07003270 for _, isClient := range []bool{false, true} {
3271 for _, supportedInFirstConnection := range []bool{false, true} {
3272 for _, supportedInResumeConnection := range []bool{false, true} {
3273 boolToWord := func(b bool) string {
3274 if b {
3275 return "Yes"
3276 }
3277 return "No"
3278 }
3279 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3280 if isClient {
3281 suffix += "Client"
3282 } else {
3283 suffix += "Server"
3284 }
3285
3286 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003287 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003288 Bugs: ProtocolBugs{
3289 RequireExtendedMasterSecret: true,
3290 },
3291 }
3292
3293 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003294 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003295 Bugs: ProtocolBugs{
3296 NoExtendedMasterSecret: true,
3297 },
3298 }
3299
3300 test := testCase{
3301 name: "ExtendedMasterSecret-" + suffix,
3302 resumeSession: true,
3303 }
3304
3305 if !isClient {
3306 test.testType = serverTest
3307 }
3308
3309 if supportedInFirstConnection {
3310 test.config = supportedConfig
3311 } else {
3312 test.config = noSupportConfig
3313 }
3314
3315 if supportedInResumeConnection {
3316 test.resumeConfig = &supportedConfig
3317 } else {
3318 test.resumeConfig = &noSupportConfig
3319 }
3320
3321 switch suffix {
3322 case "YesToYes-Client", "YesToYes-Server":
3323 // When a session is resumed, it should
3324 // still be aware that its master
3325 // secret was generated via EMS and
3326 // thus it's safe to use tls-unique.
3327 test.flags = []string{expectEMSFlag}
3328 case "NoToYes-Server":
3329 // If an original connection did not
3330 // contain EMS, but a resumption
3331 // handshake does, then a server should
3332 // not resume the session.
3333 test.expectResumeRejected = true
3334 case "YesToNo-Server":
3335 // Resuming an EMS session without the
3336 // EMS extension should cause the
3337 // server to abort the connection.
3338 test.shouldFail = true
3339 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3340 case "NoToYes-Client":
3341 // A client should abort a connection
3342 // where the server resumed a non-EMS
3343 // session but echoed the EMS
3344 // extension.
3345 test.shouldFail = true
3346 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3347 case "YesToNo-Client":
3348 // A client should abort a connection
3349 // where the server didn't echo EMS
3350 // when the session used it.
3351 test.shouldFail = true
3352 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3353 }
3354
3355 testCases = append(testCases, test)
3356 }
3357 }
3358 }
David Benjamin163c9562016-08-29 23:14:17 -04003359
3360 // Switching EMS on renegotiation is forbidden.
3361 testCases = append(testCases, testCase{
3362 name: "ExtendedMasterSecret-Renego-NoEMS",
3363 config: Config{
3364 MaxVersion: VersionTLS12,
3365 Bugs: ProtocolBugs{
3366 NoExtendedMasterSecret: true,
3367 NoExtendedMasterSecretOnRenegotiation: true,
3368 },
3369 },
3370 renegotiate: 1,
3371 flags: []string{
3372 "-renegotiate-freely",
3373 "-expect-total-renegotiations", "1",
3374 },
3375 })
3376
3377 testCases = append(testCases, testCase{
3378 name: "ExtendedMasterSecret-Renego-Upgrade",
3379 config: Config{
3380 MaxVersion: VersionTLS12,
3381 Bugs: ProtocolBugs{
3382 NoExtendedMasterSecret: true,
3383 },
3384 },
3385 renegotiate: 1,
3386 flags: []string{
3387 "-renegotiate-freely",
3388 "-expect-total-renegotiations", "1",
3389 },
3390 shouldFail: true,
3391 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3392 })
3393
3394 testCases = append(testCases, testCase{
3395 name: "ExtendedMasterSecret-Renego-Downgrade",
3396 config: Config{
3397 MaxVersion: VersionTLS12,
3398 Bugs: ProtocolBugs{
3399 NoExtendedMasterSecretOnRenegotiation: true,
3400 },
3401 },
3402 renegotiate: 1,
3403 flags: []string{
3404 "-renegotiate-freely",
3405 "-expect-total-renegotiations", "1",
3406 },
3407 shouldFail: true,
3408 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3409 })
Adam Langley75712922014-10-10 16:23:43 -07003410}
3411
David Benjamin582ba042016-07-07 12:33:25 -07003412type stateMachineTestConfig struct {
3413 protocol protocol
3414 async bool
3415 splitHandshake, packHandshakeFlight bool
3416}
3417
David Benjamin43ec06f2014-08-05 02:28:57 -04003418// Adds tests that try to cover the range of the handshake state machine, under
3419// various conditions. Some of these are redundant with other tests, but they
3420// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003421func addAllStateMachineCoverageTests() {
3422 for _, async := range []bool{false, true} {
3423 for _, protocol := range []protocol{tls, dtls} {
3424 addStateMachineCoverageTests(stateMachineTestConfig{
3425 protocol: protocol,
3426 async: async,
3427 })
3428 addStateMachineCoverageTests(stateMachineTestConfig{
3429 protocol: protocol,
3430 async: async,
3431 splitHandshake: true,
3432 })
3433 if protocol == tls {
3434 addStateMachineCoverageTests(stateMachineTestConfig{
3435 protocol: protocol,
3436 async: async,
3437 packHandshakeFlight: true,
3438 })
3439 }
3440 }
3441 }
3442}
3443
3444func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003445 var tests []testCase
3446
3447 // Basic handshake, with resumption. Client and server,
3448 // session ID and session ticket.
3449 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003450 name: "Basic-Client",
3451 config: Config{
3452 MaxVersion: VersionTLS12,
3453 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003454 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003455 // Ensure session tickets are used, not session IDs.
3456 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003457 })
3458 tests = append(tests, testCase{
3459 name: "Basic-Client-RenewTicket",
3460 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003461 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003462 Bugs: ProtocolBugs{
3463 RenewTicketOnResume: true,
3464 },
3465 },
David Benjamin46662482016-08-17 00:51:00 -04003466 flags: []string{"-expect-ticket-renewal"},
3467 resumeSession: true,
3468 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003469 })
3470 tests = append(tests, testCase{
3471 name: "Basic-Client-NoTicket",
3472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003473 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003474 SessionTicketsDisabled: true,
3475 },
3476 resumeSession: true,
3477 })
3478 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003479 name: "Basic-Client-Implicit",
3480 config: Config{
3481 MaxVersion: VersionTLS12,
3482 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003483 flags: []string{"-implicit-handshake"},
3484 resumeSession: true,
3485 })
3486 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003487 testType: serverTest,
3488 name: "Basic-Server",
3489 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003490 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003491 Bugs: ProtocolBugs{
3492 RequireSessionTickets: true,
3493 },
3494 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003495 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003496 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003497 })
3498 tests = append(tests, testCase{
3499 testType: serverTest,
3500 name: "Basic-Server-NoTickets",
3501 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003502 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003503 SessionTicketsDisabled: true,
3504 },
3505 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003506 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003507 })
3508 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003509 testType: serverTest,
3510 name: "Basic-Server-Implicit",
3511 config: Config{
3512 MaxVersion: VersionTLS12,
3513 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003514 flags: []string{"-implicit-handshake"},
3515 resumeSession: true,
3516 })
3517 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003518 testType: serverTest,
3519 name: "Basic-Server-EarlyCallback",
3520 config: Config{
3521 MaxVersion: VersionTLS12,
3522 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003523 flags: []string{"-use-early-callback"},
3524 resumeSession: true,
3525 })
3526
Steven Valdez143e8b32016-07-11 13:19:03 -04003527 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003528 if config.protocol == tls {
3529 tests = append(tests, testCase{
3530 name: "TLS13-1RTT-Client",
3531 config: Config{
3532 MaxVersion: VersionTLS13,
3533 MinVersion: VersionTLS13,
3534 },
David Benjamin46662482016-08-17 00:51:00 -04003535 resumeSession: true,
3536 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003537 })
3538
3539 tests = append(tests, testCase{
3540 testType: serverTest,
3541 name: "TLS13-1RTT-Server",
3542 config: Config{
3543 MaxVersion: VersionTLS13,
3544 MinVersion: VersionTLS13,
3545 },
David Benjamin46662482016-08-17 00:51:00 -04003546 resumeSession: true,
3547 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003548 // TLS 1.3 uses tickets, so the session should not be
3549 // cached statefully.
3550 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003551 })
3552
3553 tests = append(tests, testCase{
3554 name: "TLS13-HelloRetryRequest-Client",
3555 config: Config{
3556 MaxVersion: VersionTLS13,
3557 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003558 // P-384 requires a HelloRetryRequest against BoringSSL's default
3559 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003560 CurvePreferences: []CurveID{CurveP384},
3561 Bugs: ProtocolBugs{
3562 ExpectMissingKeyShare: true,
3563 },
3564 },
3565 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3566 resumeSession: true,
3567 })
3568
3569 tests = append(tests, testCase{
3570 testType: serverTest,
3571 name: "TLS13-HelloRetryRequest-Server",
3572 config: Config{
3573 MaxVersion: VersionTLS13,
3574 MinVersion: VersionTLS13,
3575 // Require a HelloRetryRequest for every curve.
3576 DefaultCurves: []CurveID{},
3577 },
3578 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3579 resumeSession: true,
3580 })
3581 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003582
David Benjamin760b1dd2015-05-15 23:33:48 -04003583 // TLS client auth.
3584 tests = append(tests, testCase{
3585 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003586 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003588 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003589 ClientAuth: RequestClientCert,
3590 },
3591 })
3592 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003593 testType: serverTest,
3594 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003595 config: Config{
3596 MaxVersion: VersionTLS12,
3597 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003598 // Setting SSL_VERIFY_PEER allows anonymous clients.
3599 flags: []string{"-verify-peer"},
3600 })
David Benjamin582ba042016-07-07 12:33:25 -07003601 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003602 tests = append(tests, testCase{
3603 testType: clientTest,
3604 name: "ClientAuth-NoCertificate-Client-SSL3",
3605 config: Config{
3606 MaxVersion: VersionSSL30,
3607 ClientAuth: RequestClientCert,
3608 },
3609 })
3610 tests = append(tests, testCase{
3611 testType: serverTest,
3612 name: "ClientAuth-NoCertificate-Server-SSL3",
3613 config: Config{
3614 MaxVersion: VersionSSL30,
3615 },
3616 // Setting SSL_VERIFY_PEER allows anonymous clients.
3617 flags: []string{"-verify-peer"},
3618 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003619 tests = append(tests, testCase{
3620 testType: clientTest,
3621 name: "ClientAuth-NoCertificate-Client-TLS13",
3622 config: Config{
3623 MaxVersion: VersionTLS13,
3624 ClientAuth: RequestClientCert,
3625 },
3626 })
3627 tests = append(tests, testCase{
3628 testType: serverTest,
3629 name: "ClientAuth-NoCertificate-Server-TLS13",
3630 config: Config{
3631 MaxVersion: VersionTLS13,
3632 },
3633 // Setting SSL_VERIFY_PEER allows anonymous clients.
3634 flags: []string{"-verify-peer"},
3635 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003636 }
3637 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003638 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003639 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003640 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003641 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003642 ClientAuth: RequireAnyClientCert,
3643 },
3644 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003645 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3646 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003647 },
3648 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003649 tests = append(tests, testCase{
3650 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003651 name: "ClientAuth-RSA-Client-TLS13",
3652 config: Config{
3653 MaxVersion: VersionTLS13,
3654 ClientAuth: RequireAnyClientCert,
3655 },
3656 flags: []string{
3657 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3658 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3659 },
3660 })
3661 tests = append(tests, testCase{
3662 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003663 name: "ClientAuth-ECDSA-Client",
3664 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003665 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003666 ClientAuth: RequireAnyClientCert,
3667 },
3668 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003669 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3670 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003671 },
3672 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003673 tests = append(tests, testCase{
3674 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003675 name: "ClientAuth-ECDSA-Client-TLS13",
3676 config: Config{
3677 MaxVersion: VersionTLS13,
3678 ClientAuth: RequireAnyClientCert,
3679 },
3680 flags: []string{
3681 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3682 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3683 },
3684 })
3685 tests = append(tests, testCase{
3686 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003687 name: "ClientAuth-NoCertificate-OldCallback",
3688 config: Config{
3689 MaxVersion: VersionTLS12,
3690 ClientAuth: RequestClientCert,
3691 },
3692 flags: []string{"-use-old-client-cert-callback"},
3693 })
3694 tests = append(tests, testCase{
3695 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003696 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3697 config: Config{
3698 MaxVersion: VersionTLS13,
3699 ClientAuth: RequestClientCert,
3700 },
3701 flags: []string{"-use-old-client-cert-callback"},
3702 })
3703 tests = append(tests, testCase{
3704 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003705 name: "ClientAuth-OldCallback",
3706 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003707 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003708 ClientAuth: RequireAnyClientCert,
3709 },
3710 flags: []string{
3711 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3712 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3713 "-use-old-client-cert-callback",
3714 },
3715 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003716 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003717 testType: clientTest,
3718 name: "ClientAuth-OldCallback-TLS13",
3719 config: Config{
3720 MaxVersion: VersionTLS13,
3721 ClientAuth: RequireAnyClientCert,
3722 },
3723 flags: []string{
3724 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3725 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3726 "-use-old-client-cert-callback",
3727 },
3728 })
3729 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003730 testType: serverTest,
3731 name: "ClientAuth-Server",
3732 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003733 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003734 Certificates: []Certificate{rsaCertificate},
3735 },
3736 flags: []string{"-require-any-client-certificate"},
3737 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003738 tests = append(tests, testCase{
3739 testType: serverTest,
3740 name: "ClientAuth-Server-TLS13",
3741 config: Config{
3742 MaxVersion: VersionTLS13,
3743 Certificates: []Certificate{rsaCertificate},
3744 },
3745 flags: []string{"-require-any-client-certificate"},
3746 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003747
David Benjamin4c3ddf72016-06-29 18:13:53 -04003748 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003749 tests = append(tests, testCase{
3750 testType: serverTest,
3751 name: "Basic-Server-RSA",
3752 config: Config{
3753 MaxVersion: VersionTLS12,
3754 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3755 },
3756 flags: []string{
3757 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3758 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3759 },
3760 })
3761 tests = append(tests, testCase{
3762 testType: serverTest,
3763 name: "Basic-Server-ECDHE-RSA",
3764 config: Config{
3765 MaxVersion: VersionTLS12,
3766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3767 },
3768 flags: []string{
3769 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3770 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3771 },
3772 })
3773 tests = append(tests, testCase{
3774 testType: serverTest,
3775 name: "Basic-Server-ECDHE-ECDSA",
3776 config: Config{
3777 MaxVersion: VersionTLS12,
3778 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3779 },
3780 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003781 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3782 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 },
3784 })
3785
David Benjamin760b1dd2015-05-15 23:33:48 -04003786 // No session ticket support; server doesn't send NewSessionTicket.
3787 tests = append(tests, testCase{
3788 name: "SessionTicketsDisabled-Client",
3789 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003790 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003791 SessionTicketsDisabled: true,
3792 },
3793 })
3794 tests = append(tests, testCase{
3795 testType: serverTest,
3796 name: "SessionTicketsDisabled-Server",
3797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003798 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003799 SessionTicketsDisabled: true,
3800 },
3801 })
3802
3803 // Skip ServerKeyExchange in PSK key exchange if there's no
3804 // identity hint.
3805 tests = append(tests, testCase{
3806 name: "EmptyPSKHint-Client",
3807 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003808 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003809 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3810 PreSharedKey: []byte("secret"),
3811 },
3812 flags: []string{"-psk", "secret"},
3813 })
3814 tests = append(tests, testCase{
3815 testType: serverTest,
3816 name: "EmptyPSKHint-Server",
3817 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003818 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003819 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3820 PreSharedKey: []byte("secret"),
3821 },
3822 flags: []string{"-psk", "secret"},
3823 })
3824
David Benjamin4c3ddf72016-06-29 18:13:53 -04003825 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003826 tests = append(tests, testCase{
3827 testType: clientTest,
3828 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003829 config: Config{
3830 MaxVersion: VersionTLS12,
3831 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003832 flags: []string{
3833 "-enable-ocsp-stapling",
3834 "-expect-ocsp-response",
3835 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003836 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003837 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003838 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003839 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003840 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003841 testType: serverTest,
3842 name: "OCSPStapling-Server",
3843 config: Config{
3844 MaxVersion: VersionTLS12,
3845 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003846 expectedOCSPResponse: testOCSPResponse,
3847 flags: []string{
3848 "-ocsp-response",
3849 base64.StdEncoding.EncodeToString(testOCSPResponse),
3850 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003851 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003852 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003853 tests = append(tests, testCase{
3854 testType: clientTest,
3855 name: "OCSPStapling-Client-TLS13",
3856 config: Config{
3857 MaxVersion: VersionTLS13,
3858 },
3859 flags: []string{
3860 "-enable-ocsp-stapling",
3861 "-expect-ocsp-response",
3862 base64.StdEncoding.EncodeToString(testOCSPResponse),
3863 "-verify-peer",
3864 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003865 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003866 })
3867 tests = append(tests, testCase{
3868 testType: serverTest,
3869 name: "OCSPStapling-Server-TLS13",
3870 config: Config{
3871 MaxVersion: VersionTLS13,
3872 },
3873 expectedOCSPResponse: testOCSPResponse,
3874 flags: []string{
3875 "-ocsp-response",
3876 base64.StdEncoding.EncodeToString(testOCSPResponse),
3877 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003878 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003879 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003880
David Benjamin4c3ddf72016-06-29 18:13:53 -04003881 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003882 for _, vers := range tlsVersions {
3883 if config.protocol == dtls && !vers.hasDTLS {
3884 continue
3885 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003886 for _, testType := range []testType{clientTest, serverTest} {
3887 suffix := "-Client"
3888 if testType == serverTest {
3889 suffix = "-Server"
3890 }
3891 suffix += "-" + vers.name
3892
3893 flag := "-verify-peer"
3894 if testType == serverTest {
3895 flag = "-require-any-client-certificate"
3896 }
3897
3898 tests = append(tests, testCase{
3899 testType: testType,
3900 name: "CertificateVerificationSucceed" + suffix,
3901 config: Config{
3902 MaxVersion: vers.version,
3903 Certificates: []Certificate{rsaCertificate},
3904 },
3905 flags: []string{
3906 flag,
3907 "-expect-verify-result",
3908 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003909 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003910 })
3911 tests = append(tests, testCase{
3912 testType: testType,
3913 name: "CertificateVerificationFail" + suffix,
3914 config: Config{
3915 MaxVersion: vers.version,
3916 Certificates: []Certificate{rsaCertificate},
3917 },
3918 flags: []string{
3919 flag,
3920 "-verify-fail",
3921 },
3922 shouldFail: true,
3923 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3924 })
3925 }
3926
3927 // By default, the client is in a soft fail mode where the peer
3928 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003929 tests = append(tests, testCase{
3930 testType: clientTest,
3931 name: "CertificateVerificationSoftFail-" + vers.name,
3932 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003933 MaxVersion: vers.version,
3934 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003935 },
3936 flags: []string{
3937 "-verify-fail",
3938 "-expect-verify-result",
3939 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003940 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003941 })
3942 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003943
David Benjamin1d4f4c02016-07-26 18:03:08 -04003944 tests = append(tests, testCase{
3945 name: "ShimSendAlert",
3946 flags: []string{"-send-alert"},
3947 shimWritesFirst: true,
3948 shouldFail: true,
3949 expectedLocalError: "remote error: decompression failure",
3950 })
3951
David Benjamin582ba042016-07-07 12:33:25 -07003952 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003954 name: "Renegotiate-Client",
3955 config: Config{
3956 MaxVersion: VersionTLS12,
3957 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003958 renegotiate: 1,
3959 flags: []string{
3960 "-renegotiate-freely",
3961 "-expect-total-renegotiations", "1",
3962 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003964
David Benjamin47921102016-07-28 11:29:18 -04003965 tests = append(tests, testCase{
3966 name: "SendHalfHelloRequest",
3967 config: Config{
3968 MaxVersion: VersionTLS12,
3969 Bugs: ProtocolBugs{
3970 PackHelloRequestWithFinished: config.packHandshakeFlight,
3971 },
3972 },
3973 sendHalfHelloRequest: true,
3974 flags: []string{"-renegotiate-ignore"},
3975 shouldFail: true,
3976 expectedError: ":UNEXPECTED_RECORD:",
3977 })
3978
David Benjamin760b1dd2015-05-15 23:33:48 -04003979 // NPN on client and server; results in post-handshake message.
3980 tests = append(tests, testCase{
3981 name: "NPN-Client",
3982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003983 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003984 NextProtos: []string{"foo"},
3985 },
3986 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003987 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003988 expectedNextProto: "foo",
3989 expectedNextProtoType: npn,
3990 })
3991 tests = append(tests, testCase{
3992 testType: serverTest,
3993 name: "NPN-Server",
3994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003995 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003996 NextProtos: []string{"bar"},
3997 },
3998 flags: []string{
3999 "-advertise-npn", "\x03foo\x03bar\x03baz",
4000 "-expect-next-proto", "bar",
4001 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04004002 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04004003 expectedNextProto: "bar",
4004 expectedNextProtoType: npn,
4005 })
4006
4007 // TODO(davidben): Add tests for when False Start doesn't trigger.
4008
4009 // Client does False Start and negotiates NPN.
4010 tests = append(tests, testCase{
4011 name: "FalseStart",
4012 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004013 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4015 NextProtos: []string{"foo"},
4016 Bugs: ProtocolBugs{
4017 ExpectFalseStart: true,
4018 },
4019 },
4020 flags: []string{
4021 "-false-start",
4022 "-select-next-proto", "foo",
4023 },
4024 shimWritesFirst: true,
4025 resumeSession: true,
4026 })
4027
4028 // Client does False Start and negotiates ALPN.
4029 tests = append(tests, testCase{
4030 name: "FalseStart-ALPN",
4031 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004032 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004033 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4034 NextProtos: []string{"foo"},
4035 Bugs: ProtocolBugs{
4036 ExpectFalseStart: true,
4037 },
4038 },
4039 flags: []string{
4040 "-false-start",
4041 "-advertise-alpn", "\x03foo",
4042 },
4043 shimWritesFirst: true,
4044 resumeSession: true,
4045 })
4046
4047 // Client does False Start but doesn't explicitly call
4048 // SSL_connect.
4049 tests = append(tests, testCase{
4050 name: "FalseStart-Implicit",
4051 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004052 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004053 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4054 NextProtos: []string{"foo"},
4055 },
4056 flags: []string{
4057 "-implicit-handshake",
4058 "-false-start",
4059 "-advertise-alpn", "\x03foo",
4060 },
4061 })
4062
4063 // False Start without session tickets.
4064 tests = append(tests, testCase{
4065 name: "FalseStart-SessionTicketsDisabled",
4066 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004067 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4069 NextProtos: []string{"foo"},
4070 SessionTicketsDisabled: true,
4071 Bugs: ProtocolBugs{
4072 ExpectFalseStart: true,
4073 },
4074 },
4075 flags: []string{
4076 "-false-start",
4077 "-select-next-proto", "foo",
4078 },
4079 shimWritesFirst: true,
4080 })
4081
4082 // Server parses a V2ClientHello.
4083 tests = append(tests, testCase{
4084 testType: serverTest,
4085 name: "SendV2ClientHello",
4086 config: Config{
4087 // Choose a cipher suite that does not involve
4088 // elliptic curves, so no extensions are
4089 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004090 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004091 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004092 Bugs: ProtocolBugs{
4093 SendV2ClientHello: true,
4094 },
4095 },
4096 })
4097
Nick Harper60a85cb2016-09-23 16:25:11 -07004098 // Test Channel ID
4099 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004100 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004101 continue
4102 }
4103 // Client sends a Channel ID.
4104 tests = append(tests, testCase{
4105 name: "ChannelID-Client-" + ver.name,
4106 config: Config{
4107 MaxVersion: ver.version,
4108 RequestChannelID: true,
4109 },
4110 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4111 resumeSession: true,
4112 expectChannelID: true,
4113 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004114
Nick Harper60a85cb2016-09-23 16:25:11 -07004115 // Server accepts a Channel ID.
4116 tests = append(tests, testCase{
4117 testType: serverTest,
4118 name: "ChannelID-Server-" + ver.name,
4119 config: Config{
4120 MaxVersion: ver.version,
4121 ChannelID: channelIDKey,
4122 },
4123 flags: []string{
4124 "-expect-channel-id",
4125 base64.StdEncoding.EncodeToString(channelIDBytes),
4126 },
4127 resumeSession: true,
4128 expectChannelID: true,
4129 })
4130
4131 tests = append(tests, testCase{
4132 testType: serverTest,
4133 name: "InvalidChannelIDSignature-" + ver.name,
4134 config: Config{
4135 MaxVersion: ver.version,
4136 ChannelID: channelIDKey,
4137 Bugs: ProtocolBugs{
4138 InvalidChannelIDSignature: true,
4139 },
4140 },
4141 flags: []string{"-enable-channel-id"},
4142 shouldFail: true,
4143 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4144 })
4145 }
David Benjamin30789da2015-08-29 22:56:45 -04004146
David Benjaminf8fcdf32016-06-08 15:56:13 -04004147 // Channel ID and NPN at the same time, to ensure their relative
4148 // ordering is correct.
4149 tests = append(tests, testCase{
4150 name: "ChannelID-NPN-Client",
4151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004152 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004153 RequestChannelID: true,
4154 NextProtos: []string{"foo"},
4155 },
4156 flags: []string{
4157 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4158 "-select-next-proto", "foo",
4159 },
4160 resumeSession: true,
4161 expectChannelID: true,
4162 expectedNextProto: "foo",
4163 expectedNextProtoType: npn,
4164 })
4165 tests = append(tests, testCase{
4166 testType: serverTest,
4167 name: "ChannelID-NPN-Server",
4168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004169 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004170 ChannelID: channelIDKey,
4171 NextProtos: []string{"bar"},
4172 },
4173 flags: []string{
4174 "-expect-channel-id",
4175 base64.StdEncoding.EncodeToString(channelIDBytes),
4176 "-advertise-npn", "\x03foo\x03bar\x03baz",
4177 "-expect-next-proto", "bar",
4178 },
4179 resumeSession: true,
4180 expectChannelID: true,
4181 expectedNextProto: "bar",
4182 expectedNextProtoType: npn,
4183 })
4184
David Benjamin30789da2015-08-29 22:56:45 -04004185 // Bidirectional shutdown with the runner initiating.
4186 tests = append(tests, testCase{
4187 name: "Shutdown-Runner",
4188 config: Config{
4189 Bugs: ProtocolBugs{
4190 ExpectCloseNotify: true,
4191 },
4192 },
4193 flags: []string{"-check-close-notify"},
4194 })
4195
4196 // Bidirectional shutdown with the shim initiating. The runner,
4197 // in the meantime, sends garbage before the close_notify which
4198 // the shim must ignore.
4199 tests = append(tests, testCase{
4200 name: "Shutdown-Shim",
4201 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004202 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004203 Bugs: ProtocolBugs{
4204 ExpectCloseNotify: true,
4205 },
4206 },
4207 shimShutsDown: true,
4208 sendEmptyRecords: 1,
4209 sendWarningAlerts: 1,
4210 flags: []string{"-check-close-notify"},
4211 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004212 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004213 // TODO(davidben): DTLS 1.3 will want a similar thing for
4214 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004215 tests = append(tests, testCase{
4216 name: "SkipHelloVerifyRequest",
4217 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004218 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004219 Bugs: ProtocolBugs{
4220 SkipHelloVerifyRequest: true,
4221 },
4222 },
4223 })
4224 }
4225
David Benjamin760b1dd2015-05-15 23:33:48 -04004226 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004227 test.protocol = config.protocol
4228 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004229 test.name += "-DTLS"
4230 }
David Benjamin582ba042016-07-07 12:33:25 -07004231 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004232 test.name += "-Async"
4233 test.flags = append(test.flags, "-async")
4234 } else {
4235 test.name += "-Sync"
4236 }
David Benjamin582ba042016-07-07 12:33:25 -07004237 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004238 test.name += "-SplitHandshakeRecords"
4239 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004240 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004241 test.config.Bugs.MaxPacketLength = 256
4242 test.flags = append(test.flags, "-mtu", "256")
4243 }
4244 }
David Benjamin582ba042016-07-07 12:33:25 -07004245 if config.packHandshakeFlight {
4246 test.name += "-PackHandshakeFlight"
4247 test.config.Bugs.PackHandshakeFlight = true
4248 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004249 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004250 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004251}
4252
Adam Langley524e7172015-02-20 16:04:00 -08004253func addDDoSCallbackTests() {
4254 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004255 for _, resume := range []bool{false, true} {
4256 suffix := "Resume"
4257 if resume {
4258 suffix = "No" + suffix
4259 }
4260
4261 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004262 testType: serverTest,
4263 name: "Server-DDoS-OK-" + suffix,
4264 config: Config{
4265 MaxVersion: VersionTLS12,
4266 },
Adam Langley524e7172015-02-20 16:04:00 -08004267 flags: []string{"-install-ddos-callback"},
4268 resumeSession: resume,
4269 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004270 testCases = append(testCases, testCase{
4271 testType: serverTest,
4272 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4273 config: Config{
4274 MaxVersion: VersionTLS13,
4275 },
4276 flags: []string{"-install-ddos-callback"},
4277 resumeSession: resume,
4278 })
Adam Langley524e7172015-02-20 16:04:00 -08004279
4280 failFlag := "-fail-ddos-callback"
4281 if resume {
4282 failFlag = "-fail-second-ddos-callback"
4283 }
4284 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004285 testType: serverTest,
4286 name: "Server-DDoS-Reject-" + suffix,
4287 config: Config{
4288 MaxVersion: VersionTLS12,
4289 },
David Benjamin2c66e072016-09-16 15:58:00 -04004290 flags: []string{"-install-ddos-callback", failFlag},
4291 resumeSession: resume,
4292 shouldFail: true,
4293 expectedError: ":CONNECTION_REJECTED:",
4294 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004295 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004296 testCases = append(testCases, testCase{
4297 testType: serverTest,
4298 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4299 config: Config{
4300 MaxVersion: VersionTLS13,
4301 },
David Benjamin2c66e072016-09-16 15:58:00 -04004302 flags: []string{"-install-ddos-callback", failFlag},
4303 resumeSession: resume,
4304 shouldFail: true,
4305 expectedError: ":CONNECTION_REJECTED:",
4306 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004307 })
Adam Langley524e7172015-02-20 16:04:00 -08004308 }
4309}
4310
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004311func addVersionNegotiationTests() {
4312 for i, shimVers := range tlsVersions {
4313 // Assemble flags to disable all newer versions on the shim.
4314 var flags []string
4315 for _, vers := range tlsVersions[i+1:] {
4316 flags = append(flags, vers.flag)
4317 }
4318
Steven Valdezfdd10992016-09-15 16:27:05 -04004319 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004320 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004321 protocols := []protocol{tls}
4322 if runnerVers.hasDTLS && shimVers.hasDTLS {
4323 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004324 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004325 for _, protocol := range protocols {
4326 expectedVersion := shimVers.version
4327 if runnerVers.version < shimVers.version {
4328 expectedVersion = runnerVers.version
4329 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004330
David Benjamin8b8c0062014-11-23 02:47:52 -05004331 suffix := shimVers.name + "-" + runnerVers.name
4332 if protocol == dtls {
4333 suffix += "-DTLS"
4334 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004335
David Benjamin1eb367c2014-12-12 18:17:51 -05004336 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4337
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004338 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004339 clientVers := shimVers.version
4340 if clientVers > VersionTLS10 {
4341 clientVers = VersionTLS10
4342 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004343 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004344 serverVers := expectedVersion
4345 if expectedVersion >= VersionTLS13 {
4346 serverVers = VersionTLS10
4347 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004348 serverVers = versionToWire(serverVers, protocol == dtls)
4349
David Benjamin8b8c0062014-11-23 02:47:52 -05004350 testCases = append(testCases, testCase{
4351 protocol: protocol,
4352 testType: clientTest,
4353 name: "VersionNegotiation-Client-" + suffix,
4354 config: Config{
4355 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004356 Bugs: ProtocolBugs{
4357 ExpectInitialRecordVersion: clientVers,
4358 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004359 },
4360 flags: flags,
4361 expectedVersion: expectedVersion,
4362 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004363 testCases = append(testCases, testCase{
4364 protocol: protocol,
4365 testType: clientTest,
4366 name: "VersionNegotiation-Client2-" + suffix,
4367 config: Config{
4368 MaxVersion: runnerVers.version,
4369 Bugs: ProtocolBugs{
4370 ExpectInitialRecordVersion: clientVers,
4371 },
4372 },
4373 flags: []string{"-max-version", shimVersFlag},
4374 expectedVersion: expectedVersion,
4375 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004376
4377 testCases = append(testCases, testCase{
4378 protocol: protocol,
4379 testType: serverTest,
4380 name: "VersionNegotiation-Server-" + suffix,
4381 config: Config{
4382 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004383 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004384 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004385 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004386 },
4387 flags: flags,
4388 expectedVersion: expectedVersion,
4389 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004390 testCases = append(testCases, testCase{
4391 protocol: protocol,
4392 testType: serverTest,
4393 name: "VersionNegotiation-Server2-" + suffix,
4394 config: Config{
4395 MaxVersion: runnerVers.version,
4396 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004397 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004398 },
4399 },
4400 flags: []string{"-max-version", shimVersFlag},
4401 expectedVersion: expectedVersion,
4402 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004403 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004404 }
4405 }
David Benjamin95c69562016-06-29 18:15:03 -04004406
Steven Valdezfdd10992016-09-15 16:27:05 -04004407 // Test the version extension at all versions.
4408 for _, vers := range tlsVersions {
4409 protocols := []protocol{tls}
4410 if vers.hasDTLS {
4411 protocols = append(protocols, dtls)
4412 }
4413 for _, protocol := range protocols {
4414 suffix := vers.name
4415 if protocol == dtls {
4416 suffix += "-DTLS"
4417 }
4418
4419 wireVersion := versionToWire(vers.version, protocol == dtls)
4420 testCases = append(testCases, testCase{
4421 protocol: protocol,
4422 testType: serverTest,
4423 name: "VersionNegotiationExtension-" + suffix,
4424 config: Config{
4425 Bugs: ProtocolBugs{
4426 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4427 },
4428 },
4429 expectedVersion: vers.version,
4430 })
4431 }
4432
4433 }
4434
4435 // If all versions are unknown, negotiation fails.
4436 testCases = append(testCases, testCase{
4437 testType: serverTest,
4438 name: "NoSupportedVersions",
4439 config: Config{
4440 Bugs: ProtocolBugs{
4441 SendSupportedVersions: []uint16{0x1111},
4442 },
4443 },
4444 shouldFail: true,
4445 expectedError: ":UNSUPPORTED_PROTOCOL:",
4446 })
4447 testCases = append(testCases, testCase{
4448 protocol: dtls,
4449 testType: serverTest,
4450 name: "NoSupportedVersions-DTLS",
4451 config: Config{
4452 Bugs: ProtocolBugs{
4453 SendSupportedVersions: []uint16{0x1111},
4454 },
4455 },
4456 shouldFail: true,
4457 expectedError: ":UNSUPPORTED_PROTOCOL:",
4458 })
4459
4460 testCases = append(testCases, testCase{
4461 testType: serverTest,
4462 name: "ClientHelloVersionTooHigh",
4463 config: Config{
4464 MaxVersion: VersionTLS13,
4465 Bugs: ProtocolBugs{
4466 SendClientVersion: 0x0304,
4467 OmitSupportedVersions: true,
4468 },
4469 },
4470 expectedVersion: VersionTLS12,
4471 })
4472
4473 testCases = append(testCases, testCase{
4474 testType: serverTest,
4475 name: "ConflictingVersionNegotiation",
4476 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004477 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004478 SendClientVersion: VersionTLS12,
4479 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004480 },
4481 },
David Benjaminad75a662016-09-30 15:42:59 -04004482 // The extension takes precedence over the ClientHello version.
4483 expectedVersion: VersionTLS11,
4484 })
4485
4486 testCases = append(testCases, testCase{
4487 testType: serverTest,
4488 name: "ConflictingVersionNegotiation-2",
4489 config: Config{
4490 Bugs: ProtocolBugs{
4491 SendClientVersion: VersionTLS11,
4492 SendSupportedVersions: []uint16{VersionTLS12},
4493 },
4494 },
4495 // The extension takes precedence over the ClientHello version.
4496 expectedVersion: VersionTLS12,
4497 })
4498
4499 testCases = append(testCases, testCase{
4500 testType: serverTest,
4501 name: "RejectFinalTLS13",
4502 config: Config{
4503 Bugs: ProtocolBugs{
4504 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4505 },
4506 },
4507 // We currently implement a draft TLS 1.3 version. Ensure that
4508 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004509 expectedVersion: VersionTLS12,
4510 })
4511
Brian Smithf85d3232016-10-28 10:34:06 -10004512 // Test that the maximum version is selected regardless of the
4513 // client-sent order.
4514 testCases = append(testCases, testCase{
4515 testType: serverTest,
4516 name: "IgnoreClientVersionOrder",
4517 config: Config{
4518 Bugs: ProtocolBugs{
4519 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4520 },
4521 },
4522 expectedVersion: VersionTLS13,
4523 })
4524
David Benjamin95c69562016-06-29 18:15:03 -04004525 // Test for version tolerance.
4526 testCases = append(testCases, testCase{
4527 testType: serverTest,
4528 name: "MinorVersionTolerance",
4529 config: Config{
4530 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004531 SendClientVersion: 0x03ff,
4532 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004533 },
4534 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004535 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004536 })
4537 testCases = append(testCases, testCase{
4538 testType: serverTest,
4539 name: "MajorVersionTolerance",
4540 config: Config{
4541 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004542 SendClientVersion: 0x0400,
4543 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004544 },
4545 },
David Benjaminad75a662016-09-30 15:42:59 -04004546 // TLS 1.3 must be negotiated with the supported_versions
4547 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004548 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004549 })
David Benjaminad75a662016-09-30 15:42:59 -04004550 testCases = append(testCases, testCase{
4551 testType: serverTest,
4552 name: "VersionTolerance-TLS13",
4553 config: Config{
4554 Bugs: ProtocolBugs{
4555 // Although TLS 1.3 does not use
4556 // ClientHello.version, it still tolerates high
4557 // values there.
4558 SendClientVersion: 0x0400,
4559 },
4560 },
4561 expectedVersion: VersionTLS13,
4562 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004563
David Benjamin95c69562016-06-29 18:15:03 -04004564 testCases = append(testCases, testCase{
4565 protocol: dtls,
4566 testType: serverTest,
4567 name: "MinorVersionTolerance-DTLS",
4568 config: Config{
4569 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004570 SendClientVersion: 0xfe00,
4571 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004572 },
4573 },
4574 expectedVersion: VersionTLS12,
4575 })
4576 testCases = append(testCases, testCase{
4577 protocol: dtls,
4578 testType: serverTest,
4579 name: "MajorVersionTolerance-DTLS",
4580 config: Config{
4581 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004582 SendClientVersion: 0xfdff,
4583 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004584 },
4585 },
4586 expectedVersion: VersionTLS12,
4587 })
4588
4589 // Test that versions below 3.0 are rejected.
4590 testCases = append(testCases, testCase{
4591 testType: serverTest,
4592 name: "VersionTooLow",
4593 config: Config{
4594 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004595 SendClientVersion: 0x0200,
4596 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004597 },
4598 },
4599 shouldFail: true,
4600 expectedError: ":UNSUPPORTED_PROTOCOL:",
4601 })
4602 testCases = append(testCases, testCase{
4603 protocol: dtls,
4604 testType: serverTest,
4605 name: "VersionTooLow-DTLS",
4606 config: Config{
4607 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004608 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004609 },
4610 },
4611 shouldFail: true,
4612 expectedError: ":UNSUPPORTED_PROTOCOL:",
4613 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004614
David Benjamin2dc02042016-09-19 19:57:37 -04004615 testCases = append(testCases, testCase{
4616 name: "ServerBogusVersion",
4617 config: Config{
4618 Bugs: ProtocolBugs{
4619 SendServerHelloVersion: 0x1234,
4620 },
4621 },
4622 shouldFail: true,
4623 expectedError: ":UNSUPPORTED_PROTOCOL:",
4624 })
4625
David Benjamin1f61f0d2016-07-10 12:20:35 -04004626 // Test TLS 1.3's downgrade signal.
4627 testCases = append(testCases, testCase{
4628 name: "Downgrade-TLS12-Client",
4629 config: Config{
4630 Bugs: ProtocolBugs{
4631 NegotiateVersion: VersionTLS12,
4632 },
4633 },
David Benjamin592b5322016-09-30 15:15:01 -04004634 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004635 // TODO(davidben): This test should fail once TLS 1.3 is final
4636 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004637 })
4638 testCases = append(testCases, testCase{
4639 testType: serverTest,
4640 name: "Downgrade-TLS12-Server",
4641 config: Config{
4642 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004643 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004644 },
4645 },
David Benjamin592b5322016-09-30 15:15:01 -04004646 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004647 // TODO(davidben): This test should fail once TLS 1.3 is final
4648 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004649 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004650}
4651
David Benjaminaccb4542014-12-12 23:44:33 -05004652func addMinimumVersionTests() {
4653 for i, shimVers := range tlsVersions {
4654 // Assemble flags to disable all older versions on the shim.
4655 var flags []string
4656 for _, vers := range tlsVersions[:i] {
4657 flags = append(flags, vers.flag)
4658 }
4659
4660 for _, runnerVers := range tlsVersions {
4661 protocols := []protocol{tls}
4662 if runnerVers.hasDTLS && shimVers.hasDTLS {
4663 protocols = append(protocols, dtls)
4664 }
4665 for _, protocol := range protocols {
4666 suffix := shimVers.name + "-" + runnerVers.name
4667 if protocol == dtls {
4668 suffix += "-DTLS"
4669 }
4670 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4671
David Benjaminaccb4542014-12-12 23:44:33 -05004672 var expectedVersion uint16
4673 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004674 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004675 if runnerVers.version >= shimVers.version {
4676 expectedVersion = runnerVers.version
4677 } else {
4678 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004679 expectedError = ":UNSUPPORTED_PROTOCOL:"
4680 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004681 }
4682
4683 testCases = append(testCases, testCase{
4684 protocol: protocol,
4685 testType: clientTest,
4686 name: "MinimumVersion-Client-" + suffix,
4687 config: Config{
4688 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004689 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004690 // Ensure the server does not decline to
4691 // select a version (versions extension) or
4692 // cipher (some ciphers depend on versions).
4693 NegotiateVersion: runnerVers.version,
4694 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004695 },
David Benjaminaccb4542014-12-12 23:44:33 -05004696 },
David Benjamin87909c02014-12-13 01:55:01 -05004697 flags: flags,
4698 expectedVersion: expectedVersion,
4699 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004700 expectedError: expectedError,
4701 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004702 })
4703 testCases = append(testCases, testCase{
4704 protocol: protocol,
4705 testType: clientTest,
4706 name: "MinimumVersion-Client2-" + suffix,
4707 config: Config{
4708 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004709 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004710 // Ensure the server does not decline to
4711 // select a version (versions extension) or
4712 // cipher (some ciphers depend on versions).
4713 NegotiateVersion: runnerVers.version,
4714 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004715 },
David Benjaminaccb4542014-12-12 23:44:33 -05004716 },
David Benjamin87909c02014-12-13 01:55:01 -05004717 flags: []string{"-min-version", shimVersFlag},
4718 expectedVersion: expectedVersion,
4719 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004720 expectedError: expectedError,
4721 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004722 })
4723
4724 testCases = append(testCases, testCase{
4725 protocol: protocol,
4726 testType: serverTest,
4727 name: "MinimumVersion-Server-" + suffix,
4728 config: Config{
4729 MaxVersion: runnerVers.version,
4730 },
David Benjamin87909c02014-12-13 01:55:01 -05004731 flags: flags,
4732 expectedVersion: expectedVersion,
4733 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004734 expectedError: expectedError,
4735 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004736 })
4737 testCases = append(testCases, testCase{
4738 protocol: protocol,
4739 testType: serverTest,
4740 name: "MinimumVersion-Server2-" + suffix,
4741 config: Config{
4742 MaxVersion: runnerVers.version,
4743 },
David Benjamin87909c02014-12-13 01:55:01 -05004744 flags: []string{"-min-version", shimVersFlag},
4745 expectedVersion: expectedVersion,
4746 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004747 expectedError: expectedError,
4748 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004749 })
4750 }
4751 }
4752 }
4753}
4754
David Benjamine78bfde2014-09-06 12:45:15 -04004755func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004756 // TODO(davidben): Extensions, where applicable, all move their server
4757 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4758 // tests for both. Also test interaction with 0-RTT when implemented.
4759
David Benjamin97d17d92016-07-14 16:12:00 -04004760 // Repeat extensions tests all versions except SSL 3.0.
4761 for _, ver := range tlsVersions {
4762 if ver.version == VersionSSL30 {
4763 continue
4764 }
4765
David Benjamin97d17d92016-07-14 16:12:00 -04004766 // Test that duplicate extensions are rejected.
4767 testCases = append(testCases, testCase{
4768 testType: clientTest,
4769 name: "DuplicateExtensionClient-" + ver.name,
4770 config: Config{
4771 MaxVersion: ver.version,
4772 Bugs: ProtocolBugs{
4773 DuplicateExtension: true,
4774 },
David Benjamine78bfde2014-09-06 12:45:15 -04004775 },
David Benjamin97d17d92016-07-14 16:12:00 -04004776 shouldFail: true,
4777 expectedLocalError: "remote error: error decoding message",
4778 })
4779 testCases = append(testCases, testCase{
4780 testType: serverTest,
4781 name: "DuplicateExtensionServer-" + ver.name,
4782 config: Config{
4783 MaxVersion: ver.version,
4784 Bugs: ProtocolBugs{
4785 DuplicateExtension: true,
4786 },
David Benjamine78bfde2014-09-06 12:45:15 -04004787 },
David Benjamin97d17d92016-07-14 16:12:00 -04004788 shouldFail: true,
4789 expectedLocalError: "remote error: error decoding message",
4790 })
4791
4792 // Test SNI.
4793 testCases = append(testCases, testCase{
4794 testType: clientTest,
4795 name: "ServerNameExtensionClient-" + ver.name,
4796 config: Config{
4797 MaxVersion: ver.version,
4798 Bugs: ProtocolBugs{
4799 ExpectServerName: "example.com",
4800 },
David Benjamine78bfde2014-09-06 12:45:15 -04004801 },
David Benjamin97d17d92016-07-14 16:12:00 -04004802 flags: []string{"-host-name", "example.com"},
4803 })
4804 testCases = append(testCases, testCase{
4805 testType: clientTest,
4806 name: "ServerNameExtensionClientMismatch-" + ver.name,
4807 config: Config{
4808 MaxVersion: ver.version,
4809 Bugs: ProtocolBugs{
4810 ExpectServerName: "mismatch.com",
4811 },
David Benjamine78bfde2014-09-06 12:45:15 -04004812 },
David Benjamin97d17d92016-07-14 16:12:00 -04004813 flags: []string{"-host-name", "example.com"},
4814 shouldFail: true,
4815 expectedLocalError: "tls: unexpected server name",
4816 })
4817 testCases = append(testCases, testCase{
4818 testType: clientTest,
4819 name: "ServerNameExtensionClientMissing-" + ver.name,
4820 config: Config{
4821 MaxVersion: ver.version,
4822 Bugs: ProtocolBugs{
4823 ExpectServerName: "missing.com",
4824 },
David Benjamine78bfde2014-09-06 12:45:15 -04004825 },
David Benjamin97d17d92016-07-14 16:12:00 -04004826 shouldFail: true,
4827 expectedLocalError: "tls: unexpected server name",
4828 })
4829 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05004830 testType: clientTest,
4831 name: "TolerateServerNameAck-" + ver.name,
4832 config: Config{
4833 MaxVersion: ver.version,
4834 Bugs: ProtocolBugs{
4835 SendServerNameAck: true,
4836 },
4837 },
4838 flags: []string{"-host-name", "example.com"},
4839 resumeSession: true,
4840 })
4841 testCases = append(testCases, testCase{
4842 testType: clientTest,
4843 name: "UnsolicitedServerNameAck-" + ver.name,
4844 config: Config{
4845 MaxVersion: ver.version,
4846 Bugs: ProtocolBugs{
4847 SendServerNameAck: true,
4848 },
4849 },
4850 shouldFail: true,
4851 expectedError: ":UNEXPECTED_EXTENSION:",
4852 expectedLocalError: "remote error: unsupported extension",
4853 })
4854 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004855 testType: serverTest,
4856 name: "ServerNameExtensionServer-" + ver.name,
4857 config: Config{
4858 MaxVersion: ver.version,
4859 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004860 },
David Benjamin97d17d92016-07-14 16:12:00 -04004861 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004862 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004863 })
4864
4865 // Test ALPN.
4866 testCases = append(testCases, testCase{
4867 testType: clientTest,
4868 name: "ALPNClient-" + ver.name,
4869 config: Config{
4870 MaxVersion: ver.version,
4871 NextProtos: []string{"foo"},
4872 },
4873 flags: []string{
4874 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4875 "-expect-alpn", "foo",
4876 },
4877 expectedNextProto: "foo",
4878 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004879 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004880 })
4881 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004882 testType: clientTest,
4883 name: "ALPNClient-Mismatch-" + ver.name,
4884 config: Config{
4885 MaxVersion: ver.version,
4886 Bugs: ProtocolBugs{
4887 SendALPN: "baz",
4888 },
4889 },
4890 flags: []string{
4891 "-advertise-alpn", "\x03foo\x03bar",
4892 },
4893 shouldFail: true,
4894 expectedError: ":INVALID_ALPN_PROTOCOL:",
4895 expectedLocalError: "remote error: illegal parameter",
4896 })
4897 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004898 testType: serverTest,
4899 name: "ALPNServer-" + ver.name,
4900 config: Config{
4901 MaxVersion: ver.version,
4902 NextProtos: []string{"foo", "bar", "baz"},
4903 },
4904 flags: []string{
4905 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4906 "-select-alpn", "foo",
4907 },
4908 expectedNextProto: "foo",
4909 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004910 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004911 })
4912 testCases = append(testCases, testCase{
4913 testType: serverTest,
4914 name: "ALPNServer-Decline-" + ver.name,
4915 config: Config{
4916 MaxVersion: ver.version,
4917 NextProtos: []string{"foo", "bar", "baz"},
4918 },
4919 flags: []string{"-decline-alpn"},
4920 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004921 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004922 })
4923
David Benjamin25fe85b2016-08-09 20:00:32 -04004924 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4925 // called once.
4926 testCases = append(testCases, testCase{
4927 testType: serverTest,
4928 name: "ALPNServer-Async-" + ver.name,
4929 config: Config{
4930 MaxVersion: ver.version,
4931 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004932 // Prior to TLS 1.3, exercise the asynchronous session callback.
4933 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004934 },
4935 flags: []string{
4936 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4937 "-select-alpn", "foo",
4938 "-async",
4939 },
4940 expectedNextProto: "foo",
4941 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004942 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004943 })
4944
David Benjamin97d17d92016-07-14 16:12:00 -04004945 var emptyString string
4946 testCases = append(testCases, testCase{
4947 testType: clientTest,
4948 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4949 config: Config{
4950 MaxVersion: ver.version,
4951 NextProtos: []string{""},
4952 Bugs: ProtocolBugs{
4953 // A server returning an empty ALPN protocol
4954 // should be rejected.
4955 ALPNProtocol: &emptyString,
4956 },
4957 },
4958 flags: []string{
4959 "-advertise-alpn", "\x03foo",
4960 },
4961 shouldFail: true,
4962 expectedError: ":PARSE_TLSEXT:",
4963 })
4964 testCases = append(testCases, testCase{
4965 testType: serverTest,
4966 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4967 config: Config{
4968 MaxVersion: ver.version,
4969 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004970 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004971 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004972 },
David Benjamin97d17d92016-07-14 16:12:00 -04004973 flags: []string{
4974 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004975 },
David Benjamin97d17d92016-07-14 16:12:00 -04004976 shouldFail: true,
4977 expectedError: ":PARSE_TLSEXT:",
4978 })
4979
4980 // Test NPN and the interaction with ALPN.
4981 if ver.version < VersionTLS13 {
4982 // Test that the server prefers ALPN over NPN.
4983 testCases = append(testCases, testCase{
4984 testType: serverTest,
4985 name: "ALPNServer-Preferred-" + ver.name,
4986 config: Config{
4987 MaxVersion: ver.version,
4988 NextProtos: []string{"foo", "bar", "baz"},
4989 },
4990 flags: []string{
4991 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4992 "-select-alpn", "foo",
4993 "-advertise-npn", "\x03foo\x03bar\x03baz",
4994 },
4995 expectedNextProto: "foo",
4996 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004997 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004998 })
4999 testCases = append(testCases, testCase{
5000 testType: serverTest,
5001 name: "ALPNServer-Preferred-Swapped-" + ver.name,
5002 config: Config{
5003 MaxVersion: ver.version,
5004 NextProtos: []string{"foo", "bar", "baz"},
5005 Bugs: ProtocolBugs{
5006 SwapNPNAndALPN: true,
5007 },
5008 },
5009 flags: []string{
5010 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
5011 "-select-alpn", "foo",
5012 "-advertise-npn", "\x03foo\x03bar\x03baz",
5013 },
5014 expectedNextProto: "foo",
5015 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005016 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005017 })
5018
5019 // Test that negotiating both NPN and ALPN is forbidden.
5020 testCases = append(testCases, testCase{
5021 name: "NegotiateALPNAndNPN-" + ver.name,
5022 config: Config{
5023 MaxVersion: ver.version,
5024 NextProtos: []string{"foo", "bar", "baz"},
5025 Bugs: ProtocolBugs{
5026 NegotiateALPNAndNPN: true,
5027 },
5028 },
5029 flags: []string{
5030 "-advertise-alpn", "\x03foo",
5031 "-select-next-proto", "foo",
5032 },
5033 shouldFail: true,
5034 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5035 })
5036 testCases = append(testCases, testCase{
5037 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5038 config: Config{
5039 MaxVersion: ver.version,
5040 NextProtos: []string{"foo", "bar", "baz"},
5041 Bugs: ProtocolBugs{
5042 NegotiateALPNAndNPN: true,
5043 SwapNPNAndALPN: true,
5044 },
5045 },
5046 flags: []string{
5047 "-advertise-alpn", "\x03foo",
5048 "-select-next-proto", "foo",
5049 },
5050 shouldFail: true,
5051 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5052 })
David Benjamin97d17d92016-07-14 16:12:00 -04005053 }
5054
5055 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005056
5057 // Resume with a corrupt ticket.
5058 testCases = append(testCases, testCase{
5059 testType: serverTest,
5060 name: "CorruptTicket-" + ver.name,
5061 config: Config{
5062 MaxVersion: ver.version,
5063 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005064 FilterTicket: func(in []byte) ([]byte, error) {
5065 in[len(in)-1] ^= 1
5066 return in, nil
5067 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005068 },
5069 },
5070 resumeSession: true,
5071 expectResumeRejected: true,
5072 })
5073 // Test the ticket callback, with and without renewal.
5074 testCases = append(testCases, testCase{
5075 testType: serverTest,
5076 name: "TicketCallback-" + ver.name,
5077 config: Config{
5078 MaxVersion: ver.version,
5079 },
5080 resumeSession: true,
5081 flags: []string{"-use-ticket-callback"},
5082 })
5083 testCases = append(testCases, testCase{
5084 testType: serverTest,
5085 name: "TicketCallback-Renew-" + ver.name,
5086 config: Config{
5087 MaxVersion: ver.version,
5088 Bugs: ProtocolBugs{
5089 ExpectNewTicket: true,
5090 },
5091 },
5092 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5093 resumeSession: true,
5094 })
5095
5096 // Test that the ticket callback is only called once when everything before
5097 // it in the ClientHello is asynchronous. This corrupts the ticket so
5098 // certificate selection callbacks run.
5099 testCases = append(testCases, testCase{
5100 testType: serverTest,
5101 name: "TicketCallback-SingleCall-" + ver.name,
5102 config: Config{
5103 MaxVersion: ver.version,
5104 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005105 FilterTicket: func(in []byte) ([]byte, error) {
5106 in[len(in)-1] ^= 1
5107 return in, nil
5108 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005109 },
5110 },
5111 resumeSession: true,
5112 expectResumeRejected: true,
5113 flags: []string{
5114 "-use-ticket-callback",
5115 "-async",
5116 },
5117 })
5118
David Benjamind4c349b2017-02-09 14:07:17 -05005119 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005120 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005121 testCases = append(testCases, testCase{
5122 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005123 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005124 config: Config{
5125 MaxVersion: ver.version,
5126 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005127 EmptyTicketSessionID: true,
5128 },
5129 },
5130 resumeSession: true,
5131 })
5132 testCases = append(testCases, testCase{
5133 testType: serverTest,
5134 name: "TicketSessionIDLength-16-" + ver.name,
5135 config: Config{
5136 MaxVersion: ver.version,
5137 Bugs: ProtocolBugs{
5138 TicketSessionIDLength: 16,
5139 },
5140 },
5141 resumeSession: true,
5142 })
5143 testCases = append(testCases, testCase{
5144 testType: serverTest,
5145 name: "TicketSessionIDLength-32-" + ver.name,
5146 config: Config{
5147 MaxVersion: ver.version,
5148 Bugs: ProtocolBugs{
5149 TicketSessionIDLength: 32,
5150 },
5151 },
5152 resumeSession: true,
5153 })
5154 testCases = append(testCases, testCase{
5155 testType: serverTest,
5156 name: "TicketSessionIDLength-33-" + ver.name,
5157 config: Config{
5158 MaxVersion: ver.version,
5159 Bugs: ProtocolBugs{
5160 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005161 },
5162 },
5163 resumeSession: true,
5164 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005165 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005166 expectedError: ":DECODE_ERROR:",
5167 })
5168 }
5169
5170 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5171 // are ignored.
5172 if ver.hasDTLS {
5173 testCases = append(testCases, testCase{
5174 protocol: dtls,
5175 name: "SRTP-Client-" + ver.name,
5176 config: Config{
5177 MaxVersion: ver.version,
5178 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5179 },
5180 flags: []string{
5181 "-srtp-profiles",
5182 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5183 },
5184 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5185 })
5186 testCases = append(testCases, testCase{
5187 protocol: dtls,
5188 testType: serverTest,
5189 name: "SRTP-Server-" + ver.name,
5190 config: Config{
5191 MaxVersion: ver.version,
5192 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5193 },
5194 flags: []string{
5195 "-srtp-profiles",
5196 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5197 },
5198 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5199 })
5200 // Test that the MKI is ignored.
5201 testCases = append(testCases, testCase{
5202 protocol: dtls,
5203 testType: serverTest,
5204 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5205 config: Config{
5206 MaxVersion: ver.version,
5207 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5208 Bugs: ProtocolBugs{
5209 SRTPMasterKeyIdentifer: "bogus",
5210 },
5211 },
5212 flags: []string{
5213 "-srtp-profiles",
5214 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5215 },
5216 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5217 })
5218 // Test that SRTP isn't negotiated on the server if there were
5219 // no matching profiles.
5220 testCases = append(testCases, testCase{
5221 protocol: dtls,
5222 testType: serverTest,
5223 name: "SRTP-Server-NoMatch-" + ver.name,
5224 config: Config{
5225 MaxVersion: ver.version,
5226 SRTPProtectionProfiles: []uint16{100, 101, 102},
5227 },
5228 flags: []string{
5229 "-srtp-profiles",
5230 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5231 },
5232 expectedSRTPProtectionProfile: 0,
5233 })
5234 // Test that the server returning an invalid SRTP profile is
5235 // flagged as an error by the client.
5236 testCases = append(testCases, testCase{
5237 protocol: dtls,
5238 name: "SRTP-Client-NoMatch-" + ver.name,
5239 config: Config{
5240 MaxVersion: ver.version,
5241 Bugs: ProtocolBugs{
5242 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5243 },
5244 },
5245 flags: []string{
5246 "-srtp-profiles",
5247 "SRTP_AES128_CM_SHA1_80",
5248 },
5249 shouldFail: true,
5250 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5251 })
5252 }
5253
5254 // Test SCT list.
5255 testCases = append(testCases, testCase{
5256 name: "SignedCertificateTimestampList-Client-" + ver.name,
5257 testType: clientTest,
5258 config: Config{
5259 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005260 },
David Benjamin97d17d92016-07-14 16:12:00 -04005261 flags: []string{
5262 "-enable-signed-cert-timestamps",
5263 "-expect-signed-cert-timestamps",
5264 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005265 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005266 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005267 })
David Benjamindaa88502016-10-04 16:32:16 -04005268
Adam Langleycfa08c32016-11-17 13:21:27 -08005269 var differentSCTList []byte
5270 differentSCTList = append(differentSCTList, testSCTList...)
5271 differentSCTList[len(differentSCTList)-1] ^= 1
5272
David Benjamindaa88502016-10-04 16:32:16 -04005273 // The SCT extension did not specify that it must only be sent on resumption as it
5274 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005275 testCases = append(testCases, testCase{
5276 name: "SendSCTListOnResume-" + ver.name,
5277 config: Config{
5278 MaxVersion: ver.version,
5279 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005280 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005281 },
David Benjamind98452d2015-06-16 14:16:23 -04005282 },
David Benjamin97d17d92016-07-14 16:12:00 -04005283 flags: []string{
5284 "-enable-signed-cert-timestamps",
5285 "-expect-signed-cert-timestamps",
5286 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005287 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005288 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005289 })
David Benjamindaa88502016-10-04 16:32:16 -04005290
David Benjamin97d17d92016-07-14 16:12:00 -04005291 testCases = append(testCases, testCase{
5292 name: "SignedCertificateTimestampList-Server-" + ver.name,
5293 testType: serverTest,
5294 config: Config{
5295 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005296 },
David Benjamin97d17d92016-07-14 16:12:00 -04005297 flags: []string{
5298 "-signed-cert-timestamps",
5299 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005300 },
David Benjamin97d17d92016-07-14 16:12:00 -04005301 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005302 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005303 })
David Benjamin53210cb2016-11-16 09:01:48 +09005304
Adam Langleycfa08c32016-11-17 13:21:27 -08005305 emptySCTListCert := *testCerts[0].cert
5306 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5307
5308 // Test empty SCT list.
5309 testCases = append(testCases, testCase{
5310 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5311 testType: clientTest,
5312 config: Config{
5313 MaxVersion: ver.version,
5314 Certificates: []Certificate{emptySCTListCert},
5315 },
5316 flags: []string{
5317 "-enable-signed-cert-timestamps",
5318 },
5319 shouldFail: true,
5320 expectedError: ":ERROR_PARSING_EXTENSION:",
5321 })
5322
5323 emptySCTCert := *testCerts[0].cert
5324 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5325
5326 // Test empty SCT in non-empty list.
5327 testCases = append(testCases, testCase{
5328 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5329 testType: clientTest,
5330 config: Config{
5331 MaxVersion: ver.version,
5332 Certificates: []Certificate{emptySCTCert},
5333 },
5334 flags: []string{
5335 "-enable-signed-cert-timestamps",
5336 },
5337 shouldFail: true,
5338 expectedError: ":ERROR_PARSING_EXTENSION:",
5339 })
5340
David Benjamin53210cb2016-11-16 09:01:48 +09005341 // Test that certificate-related extensions are not sent unsolicited.
5342 testCases = append(testCases, testCase{
5343 testType: serverTest,
5344 name: "UnsolicitedCertificateExtensions-" + ver.name,
5345 config: Config{
5346 MaxVersion: ver.version,
5347 Bugs: ProtocolBugs{
5348 NoOCSPStapling: true,
5349 NoSignedCertificateTimestamps: true,
5350 },
5351 },
5352 flags: []string{
5353 "-ocsp-response",
5354 base64.StdEncoding.EncodeToString(testOCSPResponse),
5355 "-signed-cert-timestamps",
5356 base64.StdEncoding.EncodeToString(testSCTList),
5357 },
5358 })
David Benjamin97d17d92016-07-14 16:12:00 -04005359 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005360
Paul Lietar4fac72e2015-09-09 13:44:55 +01005361 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005362 testType: clientTest,
5363 name: "ClientHelloPadding",
5364 config: Config{
5365 Bugs: ProtocolBugs{
5366 RequireClientHelloSize: 512,
5367 },
5368 },
5369 // This hostname just needs to be long enough to push the
5370 // ClientHello into F5's danger zone between 256 and 511 bytes
5371 // long.
5372 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5373 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005374
5375 // Extensions should not function in SSL 3.0.
5376 testCases = append(testCases, testCase{
5377 testType: serverTest,
5378 name: "SSLv3Extensions-NoALPN",
5379 config: Config{
5380 MaxVersion: VersionSSL30,
5381 NextProtos: []string{"foo", "bar", "baz"},
5382 },
5383 flags: []string{
5384 "-select-alpn", "foo",
5385 },
5386 expectNoNextProto: true,
5387 })
5388
5389 // Test session tickets separately as they follow a different codepath.
5390 testCases = append(testCases, testCase{
5391 testType: serverTest,
5392 name: "SSLv3Extensions-NoTickets",
5393 config: Config{
5394 MaxVersion: VersionSSL30,
5395 Bugs: ProtocolBugs{
5396 // Historically, session tickets in SSL 3.0
5397 // failed in different ways depending on whether
5398 // the client supported renegotiation_info.
5399 NoRenegotiationInfo: true,
5400 },
5401 },
5402 resumeSession: true,
5403 })
5404 testCases = append(testCases, testCase{
5405 testType: serverTest,
5406 name: "SSLv3Extensions-NoTickets2",
5407 config: Config{
5408 MaxVersion: VersionSSL30,
5409 },
5410 resumeSession: true,
5411 })
5412
5413 // But SSL 3.0 does send and process renegotiation_info.
5414 testCases = append(testCases, testCase{
5415 testType: serverTest,
5416 name: "SSLv3Extensions-RenegotiationInfo",
5417 config: Config{
5418 MaxVersion: VersionSSL30,
5419 Bugs: ProtocolBugs{
5420 RequireRenegotiationInfo: true,
5421 },
5422 },
David Benjamind2610042017-01-03 10:49:28 -05005423 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005424 })
5425 testCases = append(testCases, testCase{
5426 testType: serverTest,
5427 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5428 config: Config{
5429 MaxVersion: VersionSSL30,
5430 Bugs: ProtocolBugs{
5431 NoRenegotiationInfo: true,
5432 SendRenegotiationSCSV: true,
5433 RequireRenegotiationInfo: true,
5434 },
5435 },
David Benjamind2610042017-01-03 10:49:28 -05005436 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005437 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005438
5439 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5440 // in ServerHello.
5441 testCases = append(testCases, testCase{
5442 name: "NPN-Forbidden-TLS13",
5443 config: Config{
5444 MaxVersion: VersionTLS13,
5445 NextProtos: []string{"foo"},
5446 Bugs: ProtocolBugs{
5447 NegotiateNPNAtAllVersions: true,
5448 },
5449 },
5450 flags: []string{"-select-next-proto", "foo"},
5451 shouldFail: true,
5452 expectedError: ":ERROR_PARSING_EXTENSION:",
5453 })
5454 testCases = append(testCases, testCase{
5455 name: "EMS-Forbidden-TLS13",
5456 config: Config{
5457 MaxVersion: VersionTLS13,
5458 Bugs: ProtocolBugs{
5459 NegotiateEMSAtAllVersions: true,
5460 },
5461 },
5462 shouldFail: true,
5463 expectedError: ":ERROR_PARSING_EXTENSION:",
5464 })
5465 testCases = append(testCases, testCase{
5466 name: "RenegotiationInfo-Forbidden-TLS13",
5467 config: Config{
5468 MaxVersion: VersionTLS13,
5469 Bugs: ProtocolBugs{
5470 NegotiateRenegotiationInfoAtAllVersions: true,
5471 },
5472 },
5473 shouldFail: true,
5474 expectedError: ":ERROR_PARSING_EXTENSION:",
5475 })
5476 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005477 name: "Ticket-Forbidden-TLS13",
5478 config: Config{
5479 MaxVersion: VersionTLS12,
5480 },
5481 resumeConfig: &Config{
5482 MaxVersion: VersionTLS13,
5483 Bugs: ProtocolBugs{
5484 AdvertiseTicketExtension: true,
5485 },
5486 },
5487 resumeSession: true,
5488 shouldFail: true,
5489 expectedError: ":ERROR_PARSING_EXTENSION:",
5490 })
5491
5492 // Test that illegal extensions in TLS 1.3 are declined by the server if
5493 // offered in ClientHello. The runner's server will fail if this occurs,
5494 // so we exercise the offering path. (EMS and Renegotiation Info are
5495 // implicit in every test.)
5496 testCases = append(testCases, testCase{
5497 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005498 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005499 config: Config{
5500 MaxVersion: VersionTLS13,
5501 NextProtos: []string{"bar"},
5502 },
5503 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5504 })
David Benjamin196df5b2016-09-21 16:23:27 -04005505
David Benjamindaa88502016-10-04 16:32:16 -04005506 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5507 // tolerated.
5508 testCases = append(testCases, testCase{
5509 name: "SendOCSPResponseOnResume-TLS12",
5510 config: Config{
5511 MaxVersion: VersionTLS12,
5512 Bugs: ProtocolBugs{
5513 SendOCSPResponseOnResume: []byte("bogus"),
5514 },
5515 },
5516 flags: []string{
5517 "-enable-ocsp-stapling",
5518 "-expect-ocsp-response",
5519 base64.StdEncoding.EncodeToString(testOCSPResponse),
5520 },
5521 resumeSession: true,
5522 })
5523
David Benjamindaa88502016-10-04 16:32:16 -04005524 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005525 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005526 config: Config{
5527 MaxVersion: VersionTLS13,
5528 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005529 SendExtensionOnCertificate: testOCSPExtension,
5530 },
5531 },
5532 shouldFail: true,
5533 expectedError: ":UNEXPECTED_EXTENSION:",
5534 })
5535
5536 testCases = append(testCases, testCase{
5537 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5538 config: Config{
5539 MaxVersion: VersionTLS13,
5540 Bugs: ProtocolBugs{
5541 SendExtensionOnCertificate: testSCTExtension,
5542 },
5543 },
5544 shouldFail: true,
5545 expectedError: ":UNEXPECTED_EXTENSION:",
5546 })
5547
5548 // Test that extensions on client certificates are never accepted.
5549 testCases = append(testCases, testCase{
5550 name: "SendExtensionOnClientCertificate-TLS13",
5551 testType: serverTest,
5552 config: Config{
5553 MaxVersion: VersionTLS13,
5554 Certificates: []Certificate{rsaCertificate},
5555 Bugs: ProtocolBugs{
5556 SendExtensionOnCertificate: testOCSPExtension,
5557 },
5558 },
5559 flags: []string{
5560 "-enable-ocsp-stapling",
5561 "-require-any-client-certificate",
5562 },
5563 shouldFail: true,
5564 expectedError: ":UNEXPECTED_EXTENSION:",
5565 })
5566
5567 testCases = append(testCases, testCase{
5568 name: "SendUnknownExtensionOnCertificate-TLS13",
5569 config: Config{
5570 MaxVersion: VersionTLS13,
5571 Bugs: ProtocolBugs{
5572 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5573 },
5574 },
5575 shouldFail: true,
5576 expectedError: ":UNEXPECTED_EXTENSION:",
5577 })
5578
Adam Langleycfa08c32016-11-17 13:21:27 -08005579 var differentSCTList []byte
5580 differentSCTList = append(differentSCTList, testSCTList...)
5581 differentSCTList[len(differentSCTList)-1] ^= 1
5582
Steven Valdeza833c352016-11-01 13:39:36 -04005583 // Test that extensions on intermediates are allowed but ignored.
5584 testCases = append(testCases, testCase{
5585 name: "IgnoreExtensionsOnIntermediates-TLS13",
5586 config: Config{
5587 MaxVersion: VersionTLS13,
5588 Certificates: []Certificate{rsaChainCertificate},
5589 Bugs: ProtocolBugs{
5590 // Send different values on the intermediate. This tests
5591 // the intermediate's extensions do not override the
5592 // leaf's.
5593 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005594 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005595 },
5596 },
5597 flags: []string{
5598 "-enable-ocsp-stapling",
5599 "-expect-ocsp-response",
5600 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005601 "-enable-signed-cert-timestamps",
5602 "-expect-signed-cert-timestamps",
5603 base64.StdEncoding.EncodeToString(testSCTList),
5604 },
5605 resumeSession: true,
5606 })
5607
5608 // Test that extensions are not sent on intermediates when configured
5609 // only for a leaf.
5610 testCases = append(testCases, testCase{
5611 testType: serverTest,
5612 name: "SendNoExtensionsOnIntermediate-TLS13",
5613 config: Config{
5614 MaxVersion: VersionTLS13,
5615 Bugs: ProtocolBugs{
5616 ExpectNoExtensionsOnIntermediate: true,
5617 },
5618 },
5619 flags: []string{
5620 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5621 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5622 "-ocsp-response",
5623 base64.StdEncoding.EncodeToString(testOCSPResponse),
5624 "-signed-cert-timestamps",
5625 base64.StdEncoding.EncodeToString(testSCTList),
5626 },
5627 })
5628
5629 // Test that extensions are not sent on client certificates.
5630 testCases = append(testCases, testCase{
5631 name: "SendNoClientCertificateExtensions-TLS13",
5632 config: Config{
5633 MaxVersion: VersionTLS13,
5634 ClientAuth: RequireAnyClientCert,
5635 },
5636 flags: []string{
5637 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5638 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5639 "-ocsp-response",
5640 base64.StdEncoding.EncodeToString(testOCSPResponse),
5641 "-signed-cert-timestamps",
5642 base64.StdEncoding.EncodeToString(testSCTList),
5643 },
5644 })
5645
5646 testCases = append(testCases, testCase{
5647 name: "SendDuplicateExtensionsOnCerts-TLS13",
5648 config: Config{
5649 MaxVersion: VersionTLS13,
5650 Bugs: ProtocolBugs{
5651 SendDuplicateCertExtensions: true,
5652 },
5653 },
5654 flags: []string{
5655 "-enable-ocsp-stapling",
5656 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005657 },
5658 resumeSession: true,
5659 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005660 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005661 })
Adam Langley9b885c52016-11-18 14:21:03 -08005662
5663 testCases = append(testCases, testCase{
5664 name: "SignedCertificateTimestampListInvalid-Server",
5665 testType: serverTest,
5666 flags: []string{
5667 "-signed-cert-timestamps",
5668 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5669 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005670 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005671 expectedError: ":INVALID_SCT_LIST:",
5672 })
David Benjamine78bfde2014-09-06 12:45:15 -04005673}
5674
David Benjamin01fe8202014-09-24 15:21:44 -04005675func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005676 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005677 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005678 // SSL 3.0 does not have tickets and TLS 1.3 does not
5679 // have session IDs, so skip their cross-resumption
5680 // tests.
5681 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5682 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5683 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005684 }
5685
David Benjamin8b8c0062014-11-23 02:47:52 -05005686 protocols := []protocol{tls}
5687 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5688 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005689 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005690 for _, protocol := range protocols {
5691 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5692 if protocol == dtls {
5693 suffix += "-DTLS"
5694 }
5695
David Benjaminece3de92015-03-16 18:02:20 -04005696 if sessionVers.version == resumeVers.version {
5697 testCases = append(testCases, testCase{
5698 protocol: protocol,
5699 name: "Resume-Client" + suffix,
5700 resumeSession: true,
5701 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005702 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005703 Bugs: ProtocolBugs{
5704 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5705 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5706 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005707 },
David Benjaminece3de92015-03-16 18:02:20 -04005708 expectedVersion: sessionVers.version,
5709 expectedResumeVersion: resumeVers.version,
5710 })
5711 } else {
David Benjamin405da482016-08-08 17:25:07 -04005712 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5713
5714 // Offering a TLS 1.3 session sends an empty session ID, so
5715 // there is no way to convince a non-lookahead client the
5716 // session was resumed. It will appear to the client that a
5717 // stray ChangeCipherSpec was sent.
5718 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5719 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005720 }
5721
David Benjaminece3de92015-03-16 18:02:20 -04005722 testCases = append(testCases, testCase{
5723 protocol: protocol,
5724 name: "Resume-Client-Mismatch" + suffix,
5725 resumeSession: true,
5726 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005727 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005728 },
David Benjaminece3de92015-03-16 18:02:20 -04005729 expectedVersion: sessionVers.version,
5730 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005731 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005732 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005733 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005734 },
5735 },
5736 expectedResumeVersion: resumeVers.version,
5737 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005738 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005739 })
5740 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005741
5742 testCases = append(testCases, testCase{
5743 protocol: protocol,
5744 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005745 resumeSession: true,
5746 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005747 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005748 },
5749 expectedVersion: sessionVers.version,
5750 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005751 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005752 },
5753 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005754 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005755 expectedResumeVersion: resumeVers.version,
5756 })
5757
David Benjamin8b8c0062014-11-23 02:47:52 -05005758 testCases = append(testCases, testCase{
5759 protocol: protocol,
5760 testType: serverTest,
5761 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005762 resumeSession: true,
5763 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005764 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005765 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005766 expectedVersion: sessionVers.version,
5767 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005768 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005769 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005770 Bugs: ProtocolBugs{
5771 SendBothTickets: true,
5772 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005773 },
5774 expectedResumeVersion: resumeVers.version,
5775 })
5776 }
David Benjamin01fe8202014-09-24 15:21:44 -04005777 }
5778 }
David Benjaminece3de92015-03-16 18:02:20 -04005779
David Benjamin4199b0d2016-11-01 13:58:25 -04005780 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005781 testCases = append(testCases, testCase{
5782 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005783 name: "ShimTicketRewritable",
5784 resumeSession: true,
5785 config: Config{
5786 MaxVersion: VersionTLS12,
5787 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5788 Bugs: ProtocolBugs{
5789 FilterTicket: func(in []byte) ([]byte, error) {
5790 in, err := SetShimTicketVersion(in, VersionTLS12)
5791 if err != nil {
5792 return nil, err
5793 }
5794 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5795 },
5796 },
5797 },
5798 flags: []string{
5799 "-ticket-key",
5800 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5801 },
5802 })
5803
5804 // Resumptions are declined if the version does not match.
5805 testCases = append(testCases, testCase{
5806 testType: serverTest,
5807 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005808 resumeSession: true,
5809 config: Config{
5810 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005811 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005812 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005813 FilterTicket: func(in []byte) ([]byte, error) {
5814 return SetShimTicketVersion(in, VersionTLS13)
5815 },
5816 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005817 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005818 flags: []string{
5819 "-ticket-key",
5820 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5821 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005822 expectResumeRejected: true,
5823 })
5824
5825 testCases = append(testCases, testCase{
5826 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005827 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005828 resumeSession: true,
5829 config: Config{
5830 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005831 Bugs: ProtocolBugs{
5832 FilterTicket: func(in []byte) ([]byte, error) {
5833 return SetShimTicketVersion(in, VersionTLS12)
5834 },
5835 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005836 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005837 flags: []string{
5838 "-ticket-key",
5839 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5840 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005841 expectResumeRejected: true,
5842 })
5843
David Benjamin4199b0d2016-11-01 13:58:25 -04005844 // Resumptions are declined if the cipher is invalid or disabled.
5845 testCases = append(testCases, testCase{
5846 testType: serverTest,
5847 name: "Resume-Server-DeclineBadCipher",
5848 resumeSession: true,
5849 config: Config{
5850 MaxVersion: VersionTLS12,
5851 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005852 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005853 FilterTicket: func(in []byte) ([]byte, error) {
5854 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5855 },
5856 },
5857 },
5858 flags: []string{
5859 "-ticket-key",
5860 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5861 },
5862 expectResumeRejected: true,
5863 })
5864
5865 testCases = append(testCases, testCase{
5866 testType: serverTest,
5867 name: "Resume-Server-DeclineBadCipher-2",
5868 resumeSession: true,
5869 config: Config{
5870 MaxVersion: VersionTLS12,
5871 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005872 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005873 FilterTicket: func(in []byte) ([]byte, error) {
5874 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5875 },
5876 },
5877 },
5878 flags: []string{
5879 "-cipher", "AES128",
5880 "-ticket-key",
5881 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5882 },
5883 expectResumeRejected: true,
5884 })
5885
David Benjaminf01f42a2016-11-16 19:05:33 +09005886 // Sessions are not resumed if they do not use the preferred cipher.
5887 testCases = append(testCases, testCase{
5888 testType: serverTest,
5889 name: "Resume-Server-CipherNotPreferred",
5890 resumeSession: true,
5891 config: Config{
5892 MaxVersion: VersionTLS12,
5893 Bugs: ProtocolBugs{
5894 ExpectNewTicket: true,
5895 FilterTicket: func(in []byte) ([]byte, error) {
5896 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5897 },
5898 },
5899 },
5900 flags: []string{
5901 "-ticket-key",
5902 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5903 },
5904 shouldFail: false,
5905 expectResumeRejected: true,
5906 })
5907
5908 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5909 // PRF hashes match, but BoringSSL will always decline such resumptions.
5910 testCases = append(testCases, testCase{
5911 testType: serverTest,
5912 name: "Resume-Server-CipherNotPreferred-TLS13",
5913 resumeSession: true,
5914 config: Config{
5915 MaxVersion: VersionTLS13,
5916 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5917 Bugs: ProtocolBugs{
5918 FilterTicket: func(in []byte) ([]byte, error) {
5919 // If the client (runner) offers ChaCha20-Poly1305 first, the
5920 // server (shim) always prefers it. Switch it to AES-GCM.
5921 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5922 },
5923 },
5924 },
5925 flags: []string{
5926 "-ticket-key",
5927 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5928 },
5929 shouldFail: false,
5930 expectResumeRejected: true,
5931 })
5932
5933 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005934 testCases = append(testCases, testCase{
5935 testType: serverTest,
5936 name: "Resume-Server-DeclineBadCipher-TLS13",
5937 resumeSession: true,
5938 config: Config{
5939 MaxVersion: VersionTLS13,
5940 Bugs: ProtocolBugs{
5941 FilterTicket: func(in []byte) ([]byte, error) {
5942 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5943 },
5944 },
5945 },
5946 flags: []string{
5947 "-ticket-key",
5948 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5949 },
5950 expectResumeRejected: true,
5951 })
5952
David Benjaminf01f42a2016-11-16 19:05:33 +09005953 // If the client does not offer the cipher from the session, decline to
5954 // resume. Clients are forbidden from doing this, but BoringSSL selects
5955 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005956 testCases = append(testCases, testCase{
5957 testType: serverTest,
5958 name: "Resume-Server-UnofferedCipher",
5959 resumeSession: true,
5960 config: Config{
5961 MaxVersion: VersionTLS12,
5962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5963 },
5964 resumeConfig: &Config{
5965 MaxVersion: VersionTLS12,
5966 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5967 Bugs: ProtocolBugs{
5968 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5969 },
5970 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005971 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005972 })
5973
David Benjaminf01f42a2016-11-16 19:05:33 +09005974 // In TLS 1.3, clients may advertise a cipher list which does not
5975 // include the selected cipher. Test that we tolerate this. Servers may
5976 // resume at another cipher if the PRF matches, but BoringSSL will
5977 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005978 testCases = append(testCases, testCase{
5979 testType: serverTest,
5980 name: "Resume-Server-UnofferedCipher-TLS13",
5981 resumeSession: true,
5982 config: Config{
5983 MaxVersion: VersionTLS13,
5984 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5985 },
5986 resumeConfig: &Config{
5987 MaxVersion: VersionTLS13,
5988 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5989 Bugs: ProtocolBugs{
5990 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5991 },
5992 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005993 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005994 })
5995
David Benjamin4199b0d2016-11-01 13:58:25 -04005996 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005997 testCases = append(testCases, testCase{
5998 name: "Resume-Client-CipherMismatch",
5999 resumeSession: true,
6000 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006001 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006002 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6003 },
6004 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006005 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04006006 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
6007 Bugs: ProtocolBugs{
6008 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
6009 },
6010 },
6011 shouldFail: true,
6012 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
6013 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04006014
David Benjamine1cc35e2016-11-16 16:25:58 +09006015 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6016 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006017 testCases = append(testCases, testCase{
6018 name: "Resume-Client-CipherMismatch-TLS13",
6019 resumeSession: true,
6020 config: Config{
6021 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006022 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006023 },
6024 resumeConfig: &Config{
6025 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006026 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6027 },
6028 })
6029
6030 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6031 testCases = append(testCases, testCase{
6032 name: "Resume-Client-PRFMismatch-TLS13",
6033 resumeSession: true,
6034 config: Config{
6035 MaxVersion: VersionTLS13,
6036 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6037 },
6038 resumeConfig: &Config{
6039 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006040 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006041 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006042 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006043 },
6044 },
6045 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006046 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006047 })
Steven Valdeza833c352016-11-01 13:39:36 -04006048
6049 testCases = append(testCases, testCase{
6050 testType: serverTest,
6051 name: "Resume-Server-BinderWrongLength",
6052 resumeSession: true,
6053 config: Config{
6054 MaxVersion: VersionTLS13,
6055 Bugs: ProtocolBugs{
6056 SendShortPSKBinder: true,
6057 },
6058 },
6059 shouldFail: true,
6060 expectedLocalError: "remote error: error decrypting message",
6061 expectedError: ":DIGEST_CHECK_FAILED:",
6062 })
6063
6064 testCases = append(testCases, testCase{
6065 testType: serverTest,
6066 name: "Resume-Server-NoPSKBinder",
6067 resumeSession: true,
6068 config: Config{
6069 MaxVersion: VersionTLS13,
6070 Bugs: ProtocolBugs{
6071 SendNoPSKBinder: true,
6072 },
6073 },
6074 shouldFail: true,
6075 expectedLocalError: "remote error: error decoding message",
6076 expectedError: ":DECODE_ERROR:",
6077 })
6078
6079 testCases = append(testCases, testCase{
6080 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006081 name: "Resume-Server-ExtraPSKBinder",
6082 resumeSession: true,
6083 config: Config{
6084 MaxVersion: VersionTLS13,
6085 Bugs: ProtocolBugs{
6086 SendExtraPSKBinder: true,
6087 },
6088 },
6089 shouldFail: true,
6090 expectedLocalError: "remote error: illegal parameter",
6091 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6092 })
6093
6094 testCases = append(testCases, testCase{
6095 testType: serverTest,
6096 name: "Resume-Server-ExtraIdentityNoBinder",
6097 resumeSession: true,
6098 config: Config{
6099 MaxVersion: VersionTLS13,
6100 Bugs: ProtocolBugs{
6101 ExtraPSKIdentity: true,
6102 },
6103 },
6104 shouldFail: true,
6105 expectedLocalError: "remote error: illegal parameter",
6106 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6107 })
6108
6109 testCases = append(testCases, testCase{
6110 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006111 name: "Resume-Server-InvalidPSKBinder",
6112 resumeSession: true,
6113 config: Config{
6114 MaxVersion: VersionTLS13,
6115 Bugs: ProtocolBugs{
6116 SendInvalidPSKBinder: true,
6117 },
6118 },
6119 shouldFail: true,
6120 expectedLocalError: "remote error: error decrypting message",
6121 expectedError: ":DIGEST_CHECK_FAILED:",
6122 })
6123
6124 testCases = append(testCases, testCase{
6125 testType: serverTest,
6126 name: "Resume-Server-PSKBinderFirstExtension",
6127 resumeSession: true,
6128 config: Config{
6129 MaxVersion: VersionTLS13,
6130 Bugs: ProtocolBugs{
6131 PSKBinderFirst: true,
6132 },
6133 },
6134 shouldFail: true,
6135 expectedLocalError: "remote error: illegal parameter",
6136 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6137 })
David Benjamin01fe8202014-09-24 15:21:44 -04006138}
6139
Adam Langley2ae77d22014-10-28 17:29:33 -07006140func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006141 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006142 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006143 testType: serverTest,
6144 name: "Renegotiate-Server-Forbidden",
6145 config: Config{
6146 MaxVersion: VersionTLS12,
6147 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006148 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006149 shouldFail: true,
6150 expectedError: ":NO_RENEGOTIATION:",
6151 expectedLocalError: "remote error: no renegotiation",
6152 })
Adam Langley5021b222015-06-12 18:27:58 -07006153 // The server shouldn't echo the renegotiation extension unless
6154 // requested by the client.
6155 testCases = append(testCases, testCase{
6156 testType: serverTest,
6157 name: "Renegotiate-Server-NoExt",
6158 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006159 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006160 Bugs: ProtocolBugs{
6161 NoRenegotiationInfo: true,
6162 RequireRenegotiationInfo: true,
6163 },
6164 },
6165 shouldFail: true,
6166 expectedLocalError: "renegotiation extension missing",
6167 })
6168 // The renegotiation SCSV should be sufficient for the server to echo
6169 // the extension.
6170 testCases = append(testCases, testCase{
6171 testType: serverTest,
6172 name: "Renegotiate-Server-NoExt-SCSV",
6173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006174 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006175 Bugs: ProtocolBugs{
6176 NoRenegotiationInfo: true,
6177 SendRenegotiationSCSV: true,
6178 RequireRenegotiationInfo: true,
6179 },
6180 },
6181 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006182 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006183 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006185 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006186 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006187 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006188 },
6189 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006190 renegotiate: 1,
6191 flags: []string{
6192 "-renegotiate-freely",
6193 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006194 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006195 },
David Benjamincdea40c2015-03-19 14:09:43 -04006196 })
6197 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006198 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006199 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006201 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006202 Bugs: ProtocolBugs{
6203 EmptyRenegotiationInfo: true,
6204 },
6205 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006206 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006207 shouldFail: true,
6208 expectedError: ":RENEGOTIATION_MISMATCH:",
6209 })
6210 testCases = append(testCases, testCase{
6211 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006212 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006213 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006214 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006215 Bugs: ProtocolBugs{
6216 BadRenegotiationInfo: true,
6217 },
6218 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006219 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006220 shouldFail: true,
6221 expectedError: ":RENEGOTIATION_MISMATCH:",
6222 })
6223 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006224 name: "Renegotiate-Client-Downgrade",
6225 renegotiate: 1,
6226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006227 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006228 Bugs: ProtocolBugs{
6229 NoRenegotiationInfoAfterInitial: true,
6230 },
6231 },
6232 flags: []string{"-renegotiate-freely"},
6233 shouldFail: true,
6234 expectedError: ":RENEGOTIATION_MISMATCH:",
6235 })
6236 testCases = append(testCases, testCase{
6237 name: "Renegotiate-Client-Upgrade",
6238 renegotiate: 1,
6239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006240 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006241 Bugs: ProtocolBugs{
6242 NoRenegotiationInfoInInitial: true,
6243 },
6244 },
6245 flags: []string{"-renegotiate-freely"},
6246 shouldFail: true,
6247 expectedError: ":RENEGOTIATION_MISMATCH:",
6248 })
6249 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006250 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006251 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006253 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006254 Bugs: ProtocolBugs{
6255 NoRenegotiationInfo: true,
6256 },
6257 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006258 flags: []string{
6259 "-renegotiate-freely",
6260 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006261 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006262 },
David Benjamincff0b902015-05-15 23:09:47 -04006263 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006264
6265 // Test that the server may switch ciphers on renegotiation without
6266 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006267 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006268 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006269 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006270 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006271 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006272 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006273 },
6274 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006275 flags: []string{
6276 "-renegotiate-freely",
6277 "-expect-total-renegotiations", "1",
6278 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006279 })
6280 testCases = append(testCases, testCase{
6281 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006282 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006283 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006284 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6286 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006287 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006288 flags: []string{
6289 "-renegotiate-freely",
6290 "-expect-total-renegotiations", "1",
6291 },
David Benjaminb16346b2015-04-08 19:16:58 -04006292 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006293
6294 // Test that the server may not switch versions on renegotiation.
6295 testCases = append(testCases, testCase{
6296 name: "Renegotiate-Client-SwitchVersion",
6297 config: Config{
6298 MaxVersion: VersionTLS12,
6299 // Pick a cipher which exists at both versions.
6300 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6301 Bugs: ProtocolBugs{
6302 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006303 // Avoid failing early at the record layer.
6304 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006305 },
6306 },
6307 renegotiate: 1,
6308 flags: []string{
6309 "-renegotiate-freely",
6310 "-expect-total-renegotiations", "1",
6311 },
6312 shouldFail: true,
6313 expectedError: ":WRONG_SSL_VERSION:",
6314 })
6315
David Benjaminb16346b2015-04-08 19:16:58 -04006316 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006317 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006318 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006319 config: Config{
6320 MaxVersion: VersionTLS10,
6321 Bugs: ProtocolBugs{
6322 RequireSameRenegoClientVersion: true,
6323 },
6324 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006325 flags: []string{
6326 "-renegotiate-freely",
6327 "-expect-total-renegotiations", "1",
6328 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006329 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006330 testCases = append(testCases, testCase{
6331 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006332 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006333 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006334 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006335 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6336 NextProtos: []string{"foo"},
6337 },
6338 flags: []string{
6339 "-false-start",
6340 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006341 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006342 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006343 },
6344 shimWritesFirst: true,
6345 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006346
6347 // Client-side renegotiation controls.
6348 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006349 name: "Renegotiate-Client-Forbidden-1",
6350 config: Config{
6351 MaxVersion: VersionTLS12,
6352 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006353 renegotiate: 1,
6354 shouldFail: true,
6355 expectedError: ":NO_RENEGOTIATION:",
6356 expectedLocalError: "remote error: no renegotiation",
6357 })
6358 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006359 name: "Renegotiate-Client-Once-1",
6360 config: Config{
6361 MaxVersion: VersionTLS12,
6362 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006363 renegotiate: 1,
6364 flags: []string{
6365 "-renegotiate-once",
6366 "-expect-total-renegotiations", "1",
6367 },
6368 })
6369 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006370 name: "Renegotiate-Client-Freely-1",
6371 config: Config{
6372 MaxVersion: VersionTLS12,
6373 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006374 renegotiate: 1,
6375 flags: []string{
6376 "-renegotiate-freely",
6377 "-expect-total-renegotiations", "1",
6378 },
6379 })
6380 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006381 name: "Renegotiate-Client-Once-2",
6382 config: Config{
6383 MaxVersion: VersionTLS12,
6384 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006385 renegotiate: 2,
6386 flags: []string{"-renegotiate-once"},
6387 shouldFail: true,
6388 expectedError: ":NO_RENEGOTIATION:",
6389 expectedLocalError: "remote error: no renegotiation",
6390 })
6391 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006392 name: "Renegotiate-Client-Freely-2",
6393 config: Config{
6394 MaxVersion: VersionTLS12,
6395 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006396 renegotiate: 2,
6397 flags: []string{
6398 "-renegotiate-freely",
6399 "-expect-total-renegotiations", "2",
6400 },
6401 })
Adam Langley27a0d082015-11-03 13:34:10 -08006402 testCases = append(testCases, testCase{
6403 name: "Renegotiate-Client-NoIgnore",
6404 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006405 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006406 Bugs: ProtocolBugs{
6407 SendHelloRequestBeforeEveryAppDataRecord: true,
6408 },
6409 },
6410 shouldFail: true,
6411 expectedError: ":NO_RENEGOTIATION:",
6412 })
6413 testCases = append(testCases, testCase{
6414 name: "Renegotiate-Client-Ignore",
6415 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006416 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006417 Bugs: ProtocolBugs{
6418 SendHelloRequestBeforeEveryAppDataRecord: true,
6419 },
6420 },
6421 flags: []string{
6422 "-renegotiate-ignore",
6423 "-expect-total-renegotiations", "0",
6424 },
6425 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006426
David Benjamin34941c02016-10-08 11:45:31 -04006427 // Renegotiation is not allowed at SSL 3.0.
6428 testCases = append(testCases, testCase{
6429 name: "Renegotiate-Client-SSL3",
6430 config: Config{
6431 MaxVersion: VersionSSL30,
6432 },
6433 renegotiate: 1,
6434 flags: []string{
6435 "-renegotiate-freely",
6436 "-expect-total-renegotiations", "1",
6437 },
6438 shouldFail: true,
6439 expectedError: ":NO_RENEGOTIATION:",
6440 expectedLocalError: "remote error: no renegotiation",
6441 })
6442
David Benjamina1eaba12017-01-01 23:19:22 -05006443 // Renegotiation is not allowed when there is an unfinished write.
6444 testCases = append(testCases, testCase{
6445 name: "Renegotiate-Client-UnfinishedWrite",
6446 config: Config{
6447 MaxVersion: VersionTLS12,
6448 },
6449 renegotiate: 1,
6450 flags: []string{
6451 "-async",
6452 "-renegotiate-freely",
6453 "-read-with-unfinished-write",
6454 },
6455 shouldFail: true,
6456 expectedError: ":NO_RENEGOTIATION:",
6457 // We do not successfully send the no_renegotiation alert in
6458 // this case. https://crbug.com/boringssl/130
6459 })
6460
David Benjamin07ab5d42017-02-09 20:11:41 -05006461 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006462 testCases = append(testCases, testCase{
6463 name: "StrayHelloRequest",
6464 config: Config{
6465 MaxVersion: VersionTLS12,
6466 Bugs: ProtocolBugs{
6467 SendHelloRequestBeforeEveryHandshakeMessage: true,
6468 },
6469 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006470 shouldFail: true,
6471 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006472 })
6473 testCases = append(testCases, testCase{
6474 name: "StrayHelloRequest-Packed",
6475 config: Config{
6476 MaxVersion: VersionTLS12,
6477 Bugs: ProtocolBugs{
6478 PackHandshakeFlight: true,
6479 SendHelloRequestBeforeEveryHandshakeMessage: true,
6480 },
6481 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006482 shouldFail: true,
6483 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006484 })
6485
David Benjamin12d2c482016-07-24 10:56:51 -04006486 // Test renegotiation works if HelloRequest and server Finished come in
6487 // the same record.
6488 testCases = append(testCases, testCase{
6489 name: "Renegotiate-Client-Packed",
6490 config: Config{
6491 MaxVersion: VersionTLS12,
6492 Bugs: ProtocolBugs{
6493 PackHandshakeFlight: true,
6494 PackHelloRequestWithFinished: true,
6495 },
6496 },
6497 renegotiate: 1,
6498 flags: []string{
6499 "-renegotiate-freely",
6500 "-expect-total-renegotiations", "1",
6501 },
6502 })
6503
David Benjamin397c8e62016-07-08 14:14:36 -07006504 // Renegotiation is forbidden in TLS 1.3.
6505 testCases = append(testCases, testCase{
6506 name: "Renegotiate-Client-TLS13",
6507 config: Config{
6508 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006509 Bugs: ProtocolBugs{
6510 SendHelloRequestBeforeEveryAppDataRecord: true,
6511 },
David Benjamin397c8e62016-07-08 14:14:36 -07006512 },
David Benjamin397c8e62016-07-08 14:14:36 -07006513 flags: []string{
6514 "-renegotiate-freely",
6515 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006516 shouldFail: true,
6517 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006518 })
6519
6520 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6521 testCases = append(testCases, testCase{
6522 name: "StrayHelloRequest-TLS13",
6523 config: Config{
6524 MaxVersion: VersionTLS13,
6525 Bugs: ProtocolBugs{
6526 SendHelloRequestBeforeEveryHandshakeMessage: true,
6527 },
6528 },
6529 shouldFail: true,
6530 expectedError: ":UNEXPECTED_MESSAGE:",
6531 })
David Benjamind2610042017-01-03 10:49:28 -05006532
6533 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6534 // always reads as supporting it, regardless of whether it was
6535 // negotiated.
6536 testCases = append(testCases, testCase{
6537 name: "AlwaysReportRenegotiationInfo-TLS13",
6538 config: Config{
6539 MaxVersion: VersionTLS13,
6540 Bugs: ProtocolBugs{
6541 NoRenegotiationInfo: true,
6542 },
6543 },
6544 flags: []string{
6545 "-expect-secure-renegotiation",
6546 },
6547 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006548}
6549
David Benjamin5e961c12014-11-07 01:48:35 -05006550func addDTLSReplayTests() {
6551 // Test that sequence number replays are detected.
6552 testCases = append(testCases, testCase{
6553 protocol: dtls,
6554 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006555 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006556 replayWrites: true,
6557 })
6558
David Benjamin8e6db492015-07-25 18:29:23 -04006559 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006560 // than the retransmit window.
6561 testCases = append(testCases, testCase{
6562 protocol: dtls,
6563 name: "DTLS-Replay-LargeGaps",
6564 config: Config{
6565 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006566 SequenceNumberMapping: func(in uint64) uint64 {
6567 return in * 127
6568 },
David Benjamin5e961c12014-11-07 01:48:35 -05006569 },
6570 },
David Benjamin8e6db492015-07-25 18:29:23 -04006571 messageCount: 200,
6572 replayWrites: true,
6573 })
6574
6575 // Test the incoming sequence number changing non-monotonically.
6576 testCases = append(testCases, testCase{
6577 protocol: dtls,
6578 name: "DTLS-Replay-NonMonotonic",
6579 config: Config{
6580 Bugs: ProtocolBugs{
6581 SequenceNumberMapping: func(in uint64) uint64 {
6582 return in ^ 31
6583 },
6584 },
6585 },
6586 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006587 replayWrites: true,
6588 })
6589}
6590
Nick Harper60edffd2016-06-21 15:19:24 -07006591var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006592 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006593 id signatureAlgorithm
6594 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006595}{
Nick Harper60edffd2016-06-21 15:19:24 -07006596 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6597 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6598 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6599 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006600 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006601 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6602 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6603 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006604 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6605 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6606 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006607 // Tests for key types prior to TLS 1.2.
6608 {"RSA", 0, testCertRSA},
6609 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006610}
6611
Nick Harper60edffd2016-06-21 15:19:24 -07006612const fakeSigAlg1 signatureAlgorithm = 0x2a01
6613const fakeSigAlg2 signatureAlgorithm = 0xff01
6614
6615func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006616 // Not all ciphers involve a signature. Advertise a list which gives all
6617 // versions a signing cipher.
6618 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006619 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006620 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6621 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6622 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6623 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6624 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6625 }
6626
David Benjaminca3d5452016-07-14 12:51:01 -04006627 var allAlgorithms []signatureAlgorithm
6628 for _, alg := range testSignatureAlgorithms {
6629 if alg.id != 0 {
6630 allAlgorithms = append(allAlgorithms, alg.id)
6631 }
6632 }
6633
Nick Harper60edffd2016-06-21 15:19:24 -07006634 // Make sure each signature algorithm works. Include some fake values in
6635 // the list and ensure they're ignored.
6636 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006637 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006638 if (ver.version < VersionTLS12) != (alg.id == 0) {
6639 continue
6640 }
6641
6642 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6643 // or remove it in C.
6644 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006645 continue
6646 }
Nick Harper60edffd2016-06-21 15:19:24 -07006647
David Benjamin3ef76972016-10-17 17:59:54 -04006648 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006649 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006650 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006651 shouldSignFail = true
6652 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006653 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006654 // RSA-PKCS1 does not exist in TLS 1.3.
6655 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006656 shouldSignFail = true
6657 shouldVerifyFail = true
6658 }
6659
6660 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6661 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6662 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006663 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006664
6665 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006666 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006667 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006668 }
6669 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006670 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006671 }
David Benjamin000800a2014-11-14 01:43:59 -05006672
David Benjamin1fb125c2016-07-08 18:52:12 -07006673 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006674
David Benjamin7a41d372016-07-09 11:21:54 -07006675 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006676 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006677 config: Config{
6678 MaxVersion: ver.version,
6679 ClientAuth: RequireAnyClientCert,
6680 VerifySignatureAlgorithms: []signatureAlgorithm{
6681 fakeSigAlg1,
6682 alg.id,
6683 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006684 },
David Benjamin7a41d372016-07-09 11:21:54 -07006685 },
6686 flags: []string{
6687 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6688 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6689 "-enable-all-curves",
6690 },
David Benjamin3ef76972016-10-17 17:59:54 -04006691 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006692 expectedError: signError,
6693 expectedPeerSignatureAlgorithm: alg.id,
6694 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006695
David Benjamin7a41d372016-07-09 11:21:54 -07006696 testCases = append(testCases, testCase{
6697 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006698 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006699 config: Config{
6700 MaxVersion: ver.version,
6701 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6702 SignSignatureAlgorithms: []signatureAlgorithm{
6703 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006704 },
David Benjamin7a41d372016-07-09 11:21:54 -07006705 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006706 SkipECDSACurveCheck: shouldVerifyFail,
6707 IgnoreSignatureVersionChecks: shouldVerifyFail,
6708 // Some signature algorithms may not be advertised.
6709 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006710 },
David Benjamin7a41d372016-07-09 11:21:54 -07006711 },
6712 flags: []string{
6713 "-require-any-client-certificate",
6714 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6715 "-enable-all-curves",
6716 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006717 // Resume the session to assert the peer signature
6718 // algorithm is reported on both handshakes.
6719 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006720 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006721 expectedError: verifyError,
6722 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006723
6724 testCases = append(testCases, testCase{
6725 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006726 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006727 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006728 MaxVersion: ver.version,
6729 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006730 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006731 fakeSigAlg1,
6732 alg.id,
6733 fakeSigAlg2,
6734 },
6735 },
6736 flags: []string{
6737 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6738 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6739 "-enable-all-curves",
6740 },
David Benjamin3ef76972016-10-17 17:59:54 -04006741 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006742 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006743 expectedPeerSignatureAlgorithm: alg.id,
6744 })
6745
6746 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006747 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006748 config: Config{
6749 MaxVersion: ver.version,
6750 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006751 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006752 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006753 alg.id,
6754 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006755 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006756 SkipECDSACurveCheck: shouldVerifyFail,
6757 IgnoreSignatureVersionChecks: shouldVerifyFail,
6758 // Some signature algorithms may not be advertised.
6759 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006760 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006761 },
6762 flags: []string{
6763 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6764 "-enable-all-curves",
6765 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006766 // Resume the session to assert the peer signature
6767 // algorithm is reported on both handshakes.
6768 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006769 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006770 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006771 })
David Benjamin5208fd42016-07-13 21:43:25 -04006772
David Benjamin3ef76972016-10-17 17:59:54 -04006773 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006774 testCases = append(testCases, testCase{
6775 testType: serverTest,
6776 name: "ClientAuth-InvalidSignature" + suffix,
6777 config: Config{
6778 MaxVersion: ver.version,
6779 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6780 SignSignatureAlgorithms: []signatureAlgorithm{
6781 alg.id,
6782 },
6783 Bugs: ProtocolBugs{
6784 InvalidSignature: true,
6785 },
6786 },
6787 flags: []string{
6788 "-require-any-client-certificate",
6789 "-enable-all-curves",
6790 },
6791 shouldFail: true,
6792 expectedError: ":BAD_SIGNATURE:",
6793 })
6794
6795 testCases = append(testCases, testCase{
6796 name: "ServerAuth-InvalidSignature" + suffix,
6797 config: Config{
6798 MaxVersion: ver.version,
6799 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6800 CipherSuites: signingCiphers,
6801 SignSignatureAlgorithms: []signatureAlgorithm{
6802 alg.id,
6803 },
6804 Bugs: ProtocolBugs{
6805 InvalidSignature: true,
6806 },
6807 },
6808 flags: []string{"-enable-all-curves"},
6809 shouldFail: true,
6810 expectedError: ":BAD_SIGNATURE:",
6811 })
6812 }
David Benjaminca3d5452016-07-14 12:51:01 -04006813
David Benjamin3ef76972016-10-17 17:59:54 -04006814 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006815 testCases = append(testCases, testCase{
6816 name: "ClientAuth-Sign-Negotiate" + suffix,
6817 config: Config{
6818 MaxVersion: ver.version,
6819 ClientAuth: RequireAnyClientCert,
6820 VerifySignatureAlgorithms: allAlgorithms,
6821 },
6822 flags: []string{
6823 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6824 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6825 "-enable-all-curves",
6826 "-signing-prefs", strconv.Itoa(int(alg.id)),
6827 },
6828 expectedPeerSignatureAlgorithm: alg.id,
6829 })
6830
6831 testCases = append(testCases, testCase{
6832 testType: serverTest,
6833 name: "ServerAuth-Sign-Negotiate" + suffix,
6834 config: Config{
6835 MaxVersion: ver.version,
6836 CipherSuites: signingCiphers,
6837 VerifySignatureAlgorithms: allAlgorithms,
6838 },
6839 flags: []string{
6840 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6841 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6842 "-enable-all-curves",
6843 "-signing-prefs", strconv.Itoa(int(alg.id)),
6844 },
6845 expectedPeerSignatureAlgorithm: alg.id,
6846 })
6847 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006848 }
David Benjamin000800a2014-11-14 01:43:59 -05006849 }
6850
Nick Harper60edffd2016-06-21 15:19:24 -07006851 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006852 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006853 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006854 config: Config{
6855 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006856 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006857 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006858 signatureECDSAWithP521AndSHA512,
6859 signatureRSAPKCS1WithSHA384,
6860 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006861 },
6862 },
6863 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006864 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6865 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006866 },
Nick Harper60edffd2016-06-21 15:19:24 -07006867 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006868 })
6869
6870 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006871 name: "ClientAuth-SignatureType-TLS13",
6872 config: Config{
6873 ClientAuth: RequireAnyClientCert,
6874 MaxVersion: VersionTLS13,
6875 VerifySignatureAlgorithms: []signatureAlgorithm{
6876 signatureECDSAWithP521AndSHA512,
6877 signatureRSAPKCS1WithSHA384,
6878 signatureRSAPSSWithSHA384,
6879 signatureECDSAWithSHA1,
6880 },
6881 },
6882 flags: []string{
6883 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6884 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6885 },
6886 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6887 })
6888
6889 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006890 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006891 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006892 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006893 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006895 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006896 signatureECDSAWithP521AndSHA512,
6897 signatureRSAPKCS1WithSHA384,
6898 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006899 },
6900 },
Nick Harper60edffd2016-06-21 15:19:24 -07006901 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006902 })
6903
Steven Valdez143e8b32016-07-11 13:19:03 -04006904 testCases = append(testCases, testCase{
6905 testType: serverTest,
6906 name: "ServerAuth-SignatureType-TLS13",
6907 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006908 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006909 VerifySignatureAlgorithms: []signatureAlgorithm{
6910 signatureECDSAWithP521AndSHA512,
6911 signatureRSAPKCS1WithSHA384,
6912 signatureRSAPSSWithSHA384,
6913 signatureECDSAWithSHA1,
6914 },
6915 },
6916 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6917 })
6918
David Benjamina95e9f32016-07-08 16:28:04 -07006919 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006920 testCases = append(testCases, testCase{
6921 testType: serverTest,
6922 name: "Verify-ClientAuth-SignatureType",
6923 config: Config{
6924 MaxVersion: VersionTLS12,
6925 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006926 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006927 signatureRSAPKCS1WithSHA256,
6928 },
6929 Bugs: ProtocolBugs{
6930 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6931 },
6932 },
6933 flags: []string{
6934 "-require-any-client-certificate",
6935 },
6936 shouldFail: true,
6937 expectedError: ":WRONG_SIGNATURE_TYPE:",
6938 })
6939
6940 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006941 testType: serverTest,
6942 name: "Verify-ClientAuth-SignatureType-TLS13",
6943 config: Config{
6944 MaxVersion: VersionTLS13,
6945 Certificates: []Certificate{rsaCertificate},
6946 SignSignatureAlgorithms: []signatureAlgorithm{
6947 signatureRSAPSSWithSHA256,
6948 },
6949 Bugs: ProtocolBugs{
6950 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6951 },
6952 },
6953 flags: []string{
6954 "-require-any-client-certificate",
6955 },
6956 shouldFail: true,
6957 expectedError: ":WRONG_SIGNATURE_TYPE:",
6958 })
6959
6960 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006961 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006962 config: Config{
6963 MaxVersion: VersionTLS12,
6964 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006965 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006966 signatureRSAPKCS1WithSHA256,
6967 },
6968 Bugs: ProtocolBugs{
6969 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6970 },
6971 },
6972 shouldFail: true,
6973 expectedError: ":WRONG_SIGNATURE_TYPE:",
6974 })
6975
Steven Valdez143e8b32016-07-11 13:19:03 -04006976 testCases = append(testCases, testCase{
6977 name: "Verify-ServerAuth-SignatureType-TLS13",
6978 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006979 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006980 SignSignatureAlgorithms: []signatureAlgorithm{
6981 signatureRSAPSSWithSHA256,
6982 },
6983 Bugs: ProtocolBugs{
6984 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6985 },
6986 },
6987 shouldFail: true,
6988 expectedError: ":WRONG_SIGNATURE_TYPE:",
6989 })
6990
David Benjamin51dd7d62016-07-08 16:07:01 -07006991 // Test that, if the list is missing, the peer falls back to SHA-1 in
6992 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006993 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006994 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006995 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006996 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006997 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006998 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006999 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007000 },
7001 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007002 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007003 },
7004 },
7005 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007006 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7007 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007008 },
7009 })
7010
7011 testCases = append(testCases, testCase{
7012 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007013 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007014 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007015 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007016 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007017 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007018 },
7019 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007020 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007021 },
7022 },
David Benjaminee32bea2016-08-17 13:36:44 -04007023 flags: []string{
7024 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7025 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7026 },
7027 })
7028
7029 testCases = append(testCases, testCase{
7030 name: "ClientAuth-SHA1-Fallback-ECDSA",
7031 config: Config{
7032 MaxVersion: VersionTLS12,
7033 ClientAuth: RequireAnyClientCert,
7034 VerifySignatureAlgorithms: []signatureAlgorithm{
7035 signatureECDSAWithSHA1,
7036 },
7037 Bugs: ProtocolBugs{
7038 NoSignatureAlgorithms: true,
7039 },
7040 },
7041 flags: []string{
7042 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7043 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7044 },
7045 })
7046
7047 testCases = append(testCases, testCase{
7048 testType: serverTest,
7049 name: "ServerAuth-SHA1-Fallback-ECDSA",
7050 config: Config{
7051 MaxVersion: VersionTLS12,
7052 VerifySignatureAlgorithms: []signatureAlgorithm{
7053 signatureECDSAWithSHA1,
7054 },
7055 Bugs: ProtocolBugs{
7056 NoSignatureAlgorithms: true,
7057 },
7058 },
7059 flags: []string{
7060 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7061 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7062 },
David Benjamin000800a2014-11-14 01:43:59 -05007063 })
David Benjamin72dc7832015-03-16 17:49:43 -04007064
David Benjamin51dd7d62016-07-08 16:07:01 -07007065 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007066 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007067 config: Config{
7068 MaxVersion: VersionTLS13,
7069 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007070 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007071 signatureRSAPKCS1WithSHA1,
7072 },
7073 Bugs: ProtocolBugs{
7074 NoSignatureAlgorithms: true,
7075 },
7076 },
7077 flags: []string{
7078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7080 },
David Benjamin48901652016-08-01 12:12:47 -04007081 shouldFail: true,
7082 // An empty CertificateRequest signature algorithm list is a
7083 // syntax error in TLS 1.3.
7084 expectedError: ":DECODE_ERROR:",
7085 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007086 })
7087
7088 testCases = append(testCases, testCase{
7089 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007090 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007091 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007092 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007093 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007094 signatureRSAPKCS1WithSHA1,
7095 },
7096 Bugs: ProtocolBugs{
7097 NoSignatureAlgorithms: true,
7098 },
7099 },
7100 shouldFail: true,
7101 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7102 })
7103
David Benjaminb62d2872016-07-18 14:55:02 +02007104 // Test that hash preferences are enforced. BoringSSL does not implement
7105 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007106 testCases = append(testCases, testCase{
7107 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007108 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007109 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007110 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007111 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007112 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007113 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007114 },
7115 Bugs: ProtocolBugs{
7116 IgnorePeerSignatureAlgorithmPreferences: true,
7117 },
7118 },
7119 flags: []string{"-require-any-client-certificate"},
7120 shouldFail: true,
7121 expectedError: ":WRONG_SIGNATURE_TYPE:",
7122 })
7123
7124 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007125 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007127 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007128 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007129 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007130 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007131 },
7132 Bugs: ProtocolBugs{
7133 IgnorePeerSignatureAlgorithmPreferences: true,
7134 },
7135 },
7136 shouldFail: true,
7137 expectedError: ":WRONG_SIGNATURE_TYPE:",
7138 })
David Benjaminb62d2872016-07-18 14:55:02 +02007139 testCases = append(testCases, testCase{
7140 testType: serverTest,
7141 name: "ClientAuth-Enforced-TLS13",
7142 config: Config{
7143 MaxVersion: VersionTLS13,
7144 Certificates: []Certificate{rsaCertificate},
7145 SignSignatureAlgorithms: []signatureAlgorithm{
7146 signatureRSAPKCS1WithMD5,
7147 },
7148 Bugs: ProtocolBugs{
7149 IgnorePeerSignatureAlgorithmPreferences: true,
7150 IgnoreSignatureVersionChecks: true,
7151 },
7152 },
7153 flags: []string{"-require-any-client-certificate"},
7154 shouldFail: true,
7155 expectedError: ":WRONG_SIGNATURE_TYPE:",
7156 })
7157
7158 testCases = append(testCases, testCase{
7159 name: "ServerAuth-Enforced-TLS13",
7160 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007161 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007162 SignSignatureAlgorithms: []signatureAlgorithm{
7163 signatureRSAPKCS1WithMD5,
7164 },
7165 Bugs: ProtocolBugs{
7166 IgnorePeerSignatureAlgorithmPreferences: true,
7167 IgnoreSignatureVersionChecks: true,
7168 },
7169 },
7170 shouldFail: true,
7171 expectedError: ":WRONG_SIGNATURE_TYPE:",
7172 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007173
7174 // Test that the agreed upon digest respects the client preferences and
7175 // the server digests.
7176 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007177 name: "NoCommonAlgorithms-Digests",
7178 config: Config{
7179 MaxVersion: VersionTLS12,
7180 ClientAuth: RequireAnyClientCert,
7181 VerifySignatureAlgorithms: []signatureAlgorithm{
7182 signatureRSAPKCS1WithSHA512,
7183 signatureRSAPKCS1WithSHA1,
7184 },
7185 },
7186 flags: []string{
7187 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7188 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7189 "-digest-prefs", "SHA256",
7190 },
7191 shouldFail: true,
7192 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7193 })
7194 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007195 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007197 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007198 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007199 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007200 signatureRSAPKCS1WithSHA512,
7201 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007202 },
7203 },
7204 flags: []string{
7205 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7206 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007207 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007208 },
David Benjaminca3d5452016-07-14 12:51:01 -04007209 shouldFail: true,
7210 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7211 })
7212 testCases = append(testCases, testCase{
7213 name: "NoCommonAlgorithms-TLS13",
7214 config: Config{
7215 MaxVersion: VersionTLS13,
7216 ClientAuth: RequireAnyClientCert,
7217 VerifySignatureAlgorithms: []signatureAlgorithm{
7218 signatureRSAPSSWithSHA512,
7219 signatureRSAPSSWithSHA384,
7220 },
7221 },
7222 flags: []string{
7223 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7224 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7225 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7226 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007227 shouldFail: true,
7228 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007229 })
7230 testCases = append(testCases, testCase{
7231 name: "Agree-Digest-SHA256",
7232 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007233 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007234 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007235 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007236 signatureRSAPKCS1WithSHA1,
7237 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007238 },
7239 },
7240 flags: []string{
7241 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7242 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007243 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007244 },
Nick Harper60edffd2016-06-21 15:19:24 -07007245 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007246 })
7247 testCases = append(testCases, testCase{
7248 name: "Agree-Digest-SHA1",
7249 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007250 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007251 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007252 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007253 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007254 },
7255 },
7256 flags: []string{
7257 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7258 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007259 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007260 },
Nick Harper60edffd2016-06-21 15:19:24 -07007261 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007262 })
7263 testCases = append(testCases, testCase{
7264 name: "Agree-Digest-Default",
7265 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007266 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007267 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007268 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007269 signatureRSAPKCS1WithSHA256,
7270 signatureECDSAWithP256AndSHA256,
7271 signatureRSAPKCS1WithSHA1,
7272 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007273 },
7274 },
7275 flags: []string{
7276 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7277 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7278 },
Nick Harper60edffd2016-06-21 15:19:24 -07007279 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007280 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007281
David Benjaminca3d5452016-07-14 12:51:01 -04007282 // Test that the signing preference list may include extra algorithms
7283 // without negotiation problems.
7284 testCases = append(testCases, testCase{
7285 testType: serverTest,
7286 name: "FilterExtraAlgorithms",
7287 config: Config{
7288 MaxVersion: VersionTLS12,
7289 VerifySignatureAlgorithms: []signatureAlgorithm{
7290 signatureRSAPKCS1WithSHA256,
7291 },
7292 },
7293 flags: []string{
7294 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7295 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7296 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7297 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7298 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7299 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7300 },
7301 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7302 })
7303
David Benjamin4c3ddf72016-06-29 18:13:53 -04007304 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7305 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007306 testCases = append(testCases, testCase{
7307 name: "CheckLeafCurve",
7308 config: Config{
7309 MaxVersion: VersionTLS12,
7310 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007311 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007312 },
7313 flags: []string{"-p384-only"},
7314 shouldFail: true,
7315 expectedError: ":BAD_ECC_CERT:",
7316 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007317
7318 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7319 testCases = append(testCases, testCase{
7320 name: "CheckLeafCurve-TLS13",
7321 config: Config{
7322 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007323 Certificates: []Certificate{ecdsaP256Certificate},
7324 },
7325 flags: []string{"-p384-only"},
7326 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007327
7328 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7329 testCases = append(testCases, testCase{
7330 name: "ECDSACurveMismatch-Verify-TLS12",
7331 config: Config{
7332 MaxVersion: VersionTLS12,
7333 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7334 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007335 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007336 signatureECDSAWithP384AndSHA384,
7337 },
7338 },
7339 })
7340
7341 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7342 testCases = append(testCases, testCase{
7343 name: "ECDSACurveMismatch-Verify-TLS13",
7344 config: Config{
7345 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007346 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007347 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007348 signatureECDSAWithP384AndSHA384,
7349 },
7350 Bugs: ProtocolBugs{
7351 SkipECDSACurveCheck: true,
7352 },
7353 },
7354 shouldFail: true,
7355 expectedError: ":WRONG_SIGNATURE_TYPE:",
7356 })
7357
7358 // Signature algorithm selection in TLS 1.3 should take the curve into
7359 // account.
7360 testCases = append(testCases, testCase{
7361 testType: serverTest,
7362 name: "ECDSACurveMismatch-Sign-TLS13",
7363 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007364 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007365 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007366 signatureECDSAWithP384AndSHA384,
7367 signatureECDSAWithP256AndSHA256,
7368 },
7369 },
7370 flags: []string{
7371 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7372 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7373 },
7374 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7375 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007376
7377 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7378 // server does not attempt to sign in that case.
7379 testCases = append(testCases, testCase{
7380 testType: serverTest,
7381 name: "RSA-PSS-Large",
7382 config: Config{
7383 MaxVersion: VersionTLS13,
7384 VerifySignatureAlgorithms: []signatureAlgorithm{
7385 signatureRSAPSSWithSHA512,
7386 },
7387 },
7388 flags: []string{
7389 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7390 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7391 },
7392 shouldFail: true,
7393 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7394 })
David Benjamin57e929f2016-08-30 00:30:38 -04007395
7396 // Test that RSA-PSS is enabled by default for TLS 1.2.
7397 testCases = append(testCases, testCase{
7398 testType: clientTest,
7399 name: "RSA-PSS-Default-Verify",
7400 config: Config{
7401 MaxVersion: VersionTLS12,
7402 SignSignatureAlgorithms: []signatureAlgorithm{
7403 signatureRSAPSSWithSHA256,
7404 },
7405 },
7406 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7407 })
7408
7409 testCases = append(testCases, testCase{
7410 testType: serverTest,
7411 name: "RSA-PSS-Default-Sign",
7412 config: Config{
7413 MaxVersion: VersionTLS12,
7414 VerifySignatureAlgorithms: []signatureAlgorithm{
7415 signatureRSAPSSWithSHA256,
7416 },
7417 },
7418 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7419 })
Adam Langley898be922017-02-27 12:37:59 -08007420
7421 // A server certificate with a P-224 key will only work up to TLS 1.2
7422 // and we only test it with BoringSSL acting as a server because that's
7423 // all Alphabet requires with it.
7424 testCases = append(testCases, testCase{
7425 testType: serverTest,
7426 name: "P224-Server",
7427 config: Config{
7428 VerifySignatureAlgorithms: []signatureAlgorithm{
7429 // TLS 1.2 does not require that the curve
7430 // match the hash, thus P-256 with SHA-256 is
7431 // the same signature algorithm value as P-224
7432 // with SHA-256.
7433 signatureECDSAWithP256AndSHA256,
7434 },
7435 // P-256 must be offered as well because ECDHE requires
7436 // it.
7437 CurvePreferences: []CurveID{CurveP224, CurveP256},
7438 },
7439 flags: []string{
7440 "-max-version", strconv.Itoa(VersionTLS12),
7441 "-cert-file", path.Join(*resourceDir, ecdsaP224CertificateFile),
7442 "-key-file", path.Join(*resourceDir, ecdsaP224KeyFile),
7443 },
7444 })
David Benjamin000800a2014-11-14 01:43:59 -05007445}
7446
David Benjamin83f90402015-01-27 01:09:43 -05007447// timeouts is the retransmit schedule for BoringSSL. It doubles and
7448// caps at 60 seconds. On the 13th timeout, it gives up.
7449var timeouts = []time.Duration{
7450 1 * time.Second,
7451 2 * time.Second,
7452 4 * time.Second,
7453 8 * time.Second,
7454 16 * time.Second,
7455 32 * time.Second,
7456 60 * time.Second,
7457 60 * time.Second,
7458 60 * time.Second,
7459 60 * time.Second,
7460 60 * time.Second,
7461 60 * time.Second,
7462 60 * time.Second,
7463}
7464
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007465// shortTimeouts is an alternate set of timeouts which would occur if the
7466// initial timeout duration was set to 250ms.
7467var shortTimeouts = []time.Duration{
7468 250 * time.Millisecond,
7469 500 * time.Millisecond,
7470 1 * time.Second,
7471 2 * time.Second,
7472 4 * time.Second,
7473 8 * time.Second,
7474 16 * time.Second,
7475 32 * time.Second,
7476 60 * time.Second,
7477 60 * time.Second,
7478 60 * time.Second,
7479 60 * time.Second,
7480 60 * time.Second,
7481}
7482
David Benjamin83f90402015-01-27 01:09:43 -05007483func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007484 // These tests work by coordinating some behavior on both the shim and
7485 // the runner.
7486 //
7487 // TimeoutSchedule configures the runner to send a series of timeout
7488 // opcodes to the shim (see packetAdaptor) immediately before reading
7489 // each peer handshake flight N. The timeout opcode both simulates a
7490 // timeout in the shim and acts as a synchronization point to help the
7491 // runner bracket each handshake flight.
7492 //
7493 // We assume the shim does not read from the channel eagerly. It must
7494 // first wait until it has sent flight N and is ready to receive
7495 // handshake flight N+1. At this point, it will process the timeout
7496 // opcode. It must then immediately respond with a timeout ACK and act
7497 // as if the shim was idle for the specified amount of time.
7498 //
7499 // The runner then drops all packets received before the ACK and
7500 // continues waiting for flight N. This ordering results in one attempt
7501 // at sending flight N to be dropped. For the test to complete, the
7502 // shim must send flight N again, testing that the shim implements DTLS
7503 // retransmit on a timeout.
7504
Steven Valdez143e8b32016-07-11 13:19:03 -04007505 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007506 // likely be more epochs to cross and the final message's retransmit may
7507 // be more complex.
7508
David Benjamin11c82892017-02-23 20:40:31 -05007509 // Test that this is indeed the timeout schedule. Stress all
7510 // four patterns of handshake.
7511 for i := 1; i < len(timeouts); i++ {
7512 number := strconv.Itoa(i)
7513 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007514 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05007515 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007516 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007517 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007518 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007519 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007520 },
7521 },
7522 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007523 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007524 })
David Benjamin11c82892017-02-23 20:40:31 -05007525 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007526 protocol: dtls,
7527 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05007528 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007530 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007531 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007532 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007533 },
7534 },
7535 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007536 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007537 })
7538 }
David Benjamin11c82892017-02-23 20:40:31 -05007539
7540 // Test that exceeding the timeout schedule hits a read
7541 // timeout.
7542 testCases = append(testCases, testCase{
7543 protocol: dtls,
7544 name: "DTLS-Retransmit-Timeout",
7545 config: Config{
7546 MaxVersion: VersionTLS12,
7547 Bugs: ProtocolBugs{
7548 TimeoutSchedule: timeouts,
7549 },
7550 },
7551 resumeSession: true,
7552 flags: []string{"-async"},
7553 shouldFail: true,
7554 expectedError: ":READ_TIMEOUT_EXPIRED:",
7555 })
7556
7557 // Test that timeout handling has a fudge factor, due to API
7558 // problems.
7559 testCases = append(testCases, testCase{
7560 protocol: dtls,
7561 name: "DTLS-Retransmit-Fudge",
7562 config: Config{
7563 MaxVersion: VersionTLS12,
7564 Bugs: ProtocolBugs{
7565 TimeoutSchedule: []time.Duration{
7566 timeouts[0] - 10*time.Millisecond,
7567 },
7568 },
7569 },
7570 resumeSession: true,
7571 flags: []string{"-async"},
7572 })
7573
7574 // Test that the final Finished retransmitting isn't
7575 // duplicated if the peer badly fragments everything.
7576 testCases = append(testCases, testCase{
7577 testType: serverTest,
7578 protocol: dtls,
7579 name: "DTLS-Retransmit-Fragmented",
7580 config: Config{
7581 MaxVersion: VersionTLS12,
7582 Bugs: ProtocolBugs{
7583 TimeoutSchedule: []time.Duration{timeouts[0]},
7584 MaxHandshakeRecordLength: 2,
7585 },
7586 },
7587 flags: []string{"-async"},
7588 })
7589
7590 // Test the timeout schedule when a shorter initial timeout duration is set.
7591 testCases = append(testCases, testCase{
7592 protocol: dtls,
7593 name: "DTLS-Retransmit-Short-Client",
7594 config: Config{
7595 MaxVersion: VersionTLS12,
7596 Bugs: ProtocolBugs{
7597 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7598 },
7599 },
7600 resumeSession: true,
7601 flags: []string{
7602 "-async",
7603 "-initial-timeout-duration-ms", "250",
7604 },
7605 })
7606 testCases = append(testCases, testCase{
7607 protocol: dtls,
7608 testType: serverTest,
7609 name: "DTLS-Retransmit-Short-Server",
7610 config: Config{
7611 MaxVersion: VersionTLS12,
7612 Bugs: ProtocolBugs{
7613 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7614 },
7615 },
7616 resumeSession: true,
7617 flags: []string{
7618 "-async",
7619 "-initial-timeout-duration-ms", "250",
7620 },
7621 })
David Benjamin83f90402015-01-27 01:09:43 -05007622}
7623
David Benjaminc565ebb2015-04-03 04:06:36 -04007624func addExportKeyingMaterialTests() {
7625 for _, vers := range tlsVersions {
7626 if vers.version == VersionSSL30 {
7627 continue
7628 }
7629 testCases = append(testCases, testCase{
7630 name: "ExportKeyingMaterial-" + vers.name,
7631 config: Config{
7632 MaxVersion: vers.version,
7633 },
7634 exportKeyingMaterial: 1024,
7635 exportLabel: "label",
7636 exportContext: "context",
7637 useExportContext: true,
7638 })
7639 testCases = append(testCases, testCase{
7640 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7641 config: Config{
7642 MaxVersion: vers.version,
7643 },
7644 exportKeyingMaterial: 1024,
7645 })
7646 testCases = append(testCases, testCase{
7647 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7648 config: Config{
7649 MaxVersion: vers.version,
7650 },
7651 exportKeyingMaterial: 1024,
7652 useExportContext: true,
7653 })
7654 testCases = append(testCases, testCase{
7655 name: "ExportKeyingMaterial-Small-" + vers.name,
7656 config: Config{
7657 MaxVersion: vers.version,
7658 },
7659 exportKeyingMaterial: 1,
7660 exportLabel: "label",
7661 exportContext: "context",
7662 useExportContext: true,
7663 })
7664 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007665
David Benjaminc565ebb2015-04-03 04:06:36 -04007666 testCases = append(testCases, testCase{
7667 name: "ExportKeyingMaterial-SSL3",
7668 config: Config{
7669 MaxVersion: VersionSSL30,
7670 },
7671 exportKeyingMaterial: 1024,
7672 exportLabel: "label",
7673 exportContext: "context",
7674 useExportContext: true,
7675 shouldFail: true,
7676 expectedError: "failed to export keying material",
7677 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007678
7679 // Exporters work during a False Start.
7680 testCases = append(testCases, testCase{
7681 name: "ExportKeyingMaterial-FalseStart",
7682 config: Config{
7683 MaxVersion: VersionTLS12,
7684 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7685 NextProtos: []string{"foo"},
7686 Bugs: ProtocolBugs{
7687 ExpectFalseStart: true,
7688 },
7689 },
7690 flags: []string{
7691 "-false-start",
7692 "-advertise-alpn", "\x03foo",
7693 },
7694 shimWritesFirst: true,
7695 exportKeyingMaterial: 1024,
7696 exportLabel: "label",
7697 exportContext: "context",
7698 useExportContext: true,
7699 })
7700
7701 // Exporters do not work in the middle of a renegotiation. Test this by
7702 // triggering the exporter after every SSL_read call and configuring the
7703 // shim to run asynchronously.
7704 testCases = append(testCases, testCase{
7705 name: "ExportKeyingMaterial-Renegotiate",
7706 config: Config{
7707 MaxVersion: VersionTLS12,
7708 },
7709 renegotiate: 1,
7710 flags: []string{
7711 "-async",
7712 "-use-exporter-between-reads",
7713 "-renegotiate-freely",
7714 "-expect-total-renegotiations", "1",
7715 },
7716 shouldFail: true,
7717 expectedError: "failed to export keying material",
7718 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007719}
7720
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007721func addTLSUniqueTests() {
7722 for _, isClient := range []bool{false, true} {
7723 for _, isResumption := range []bool{false, true} {
7724 for _, hasEMS := range []bool{false, true} {
7725 var suffix string
7726 if isResumption {
7727 suffix = "Resume-"
7728 } else {
7729 suffix = "Full-"
7730 }
7731
7732 if hasEMS {
7733 suffix += "EMS-"
7734 } else {
7735 suffix += "NoEMS-"
7736 }
7737
7738 if isClient {
7739 suffix += "Client"
7740 } else {
7741 suffix += "Server"
7742 }
7743
7744 test := testCase{
7745 name: "TLSUnique-" + suffix,
7746 testTLSUnique: true,
7747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007748 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007749 Bugs: ProtocolBugs{
7750 NoExtendedMasterSecret: !hasEMS,
7751 },
7752 },
7753 }
7754
7755 if isResumption {
7756 test.resumeSession = true
7757 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007758 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007759 Bugs: ProtocolBugs{
7760 NoExtendedMasterSecret: !hasEMS,
7761 },
7762 }
7763 }
7764
7765 if isResumption && !hasEMS {
7766 test.shouldFail = true
7767 test.expectedError = "failed to get tls-unique"
7768 }
7769
7770 testCases = append(testCases, test)
7771 }
7772 }
7773 }
7774}
7775
Adam Langley09505632015-07-30 18:10:13 -07007776func addCustomExtensionTests() {
7777 expectedContents := "custom extension"
7778 emptyString := ""
7779
7780 for _, isClient := range []bool{false, true} {
7781 suffix := "Server"
7782 flag := "-enable-server-custom-extension"
7783 testType := serverTest
7784 if isClient {
7785 suffix = "Client"
7786 flag = "-enable-client-custom-extension"
7787 testType = clientTest
7788 }
7789
7790 testCases = append(testCases, testCase{
7791 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007792 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007793 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007794 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007795 Bugs: ProtocolBugs{
7796 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007797 ExpectedCustomExtension: &expectedContents,
7798 },
7799 },
7800 flags: []string{flag},
7801 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007802 testCases = append(testCases, testCase{
7803 testType: testType,
7804 name: "CustomExtensions-" + suffix + "-TLS13",
7805 config: Config{
7806 MaxVersion: VersionTLS13,
7807 Bugs: ProtocolBugs{
7808 CustomExtension: expectedContents,
7809 ExpectedCustomExtension: &expectedContents,
7810 },
7811 },
7812 flags: []string{flag},
7813 })
Adam Langley09505632015-07-30 18:10:13 -07007814
7815 // If the parse callback fails, the handshake should also fail.
7816 testCases = append(testCases, testCase{
7817 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007818 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007819 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007820 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007821 Bugs: ProtocolBugs{
7822 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007823 ExpectedCustomExtension: &expectedContents,
7824 },
7825 },
David Benjamin399e7c92015-07-30 23:01:27 -04007826 flags: []string{flag},
7827 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007828 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7829 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007830 testCases = append(testCases, testCase{
7831 testType: testType,
7832 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7833 config: Config{
7834 MaxVersion: VersionTLS13,
7835 Bugs: ProtocolBugs{
7836 CustomExtension: expectedContents + "foo",
7837 ExpectedCustomExtension: &expectedContents,
7838 },
7839 },
7840 flags: []string{flag},
7841 shouldFail: true,
7842 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7843 })
Adam Langley09505632015-07-30 18:10:13 -07007844
7845 // If the add callback fails, the handshake should also fail.
7846 testCases = append(testCases, testCase{
7847 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007848 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007849 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007850 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007851 Bugs: ProtocolBugs{
7852 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007853 ExpectedCustomExtension: &expectedContents,
7854 },
7855 },
David Benjamin399e7c92015-07-30 23:01:27 -04007856 flags: []string{flag, "-custom-extension-fail-add"},
7857 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007858 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7859 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007860 testCases = append(testCases, testCase{
7861 testType: testType,
7862 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7863 config: Config{
7864 MaxVersion: VersionTLS13,
7865 Bugs: ProtocolBugs{
7866 CustomExtension: expectedContents,
7867 ExpectedCustomExtension: &expectedContents,
7868 },
7869 },
7870 flags: []string{flag, "-custom-extension-fail-add"},
7871 shouldFail: true,
7872 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7873 })
Adam Langley09505632015-07-30 18:10:13 -07007874
7875 // If the add callback returns zero, no extension should be
7876 // added.
7877 skipCustomExtension := expectedContents
7878 if isClient {
7879 // For the case where the client skips sending the
7880 // custom extension, the server must not “echo” it.
7881 skipCustomExtension = ""
7882 }
7883 testCases = append(testCases, testCase{
7884 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007885 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007886 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007887 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007888 Bugs: ProtocolBugs{
7889 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007890 ExpectedCustomExtension: &emptyString,
7891 },
7892 },
7893 flags: []string{flag, "-custom-extension-skip"},
7894 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007895 testCases = append(testCases, testCase{
7896 testType: testType,
7897 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7898 config: Config{
7899 MaxVersion: VersionTLS13,
7900 Bugs: ProtocolBugs{
7901 CustomExtension: skipCustomExtension,
7902 ExpectedCustomExtension: &emptyString,
7903 },
7904 },
7905 flags: []string{flag, "-custom-extension-skip"},
7906 })
Adam Langley09505632015-07-30 18:10:13 -07007907 }
7908
7909 // The custom extension add callback should not be called if the client
7910 // doesn't send the extension.
7911 testCases = append(testCases, testCase{
7912 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007913 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007914 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007915 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007916 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007917 ExpectedCustomExtension: &emptyString,
7918 },
7919 },
7920 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7921 })
Adam Langley2deb9842015-08-07 11:15:37 -07007922
Steven Valdez143e8b32016-07-11 13:19:03 -04007923 testCases = append(testCases, testCase{
7924 testType: serverTest,
7925 name: "CustomExtensions-NotCalled-Server-TLS13",
7926 config: Config{
7927 MaxVersion: VersionTLS13,
7928 Bugs: ProtocolBugs{
7929 ExpectedCustomExtension: &emptyString,
7930 },
7931 },
7932 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7933 })
7934
Adam Langley2deb9842015-08-07 11:15:37 -07007935 // Test an unknown extension from the server.
7936 testCases = append(testCases, testCase{
7937 testType: clientTest,
7938 name: "UnknownExtension-Client",
7939 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007940 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007941 Bugs: ProtocolBugs{
7942 CustomExtension: expectedContents,
7943 },
7944 },
David Benjamin0c40a962016-08-01 12:05:50 -04007945 shouldFail: true,
7946 expectedError: ":UNEXPECTED_EXTENSION:",
7947 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007948 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007949 testCases = append(testCases, testCase{
7950 testType: clientTest,
7951 name: "UnknownExtension-Client-TLS13",
7952 config: Config{
7953 MaxVersion: VersionTLS13,
7954 Bugs: ProtocolBugs{
7955 CustomExtension: expectedContents,
7956 },
7957 },
David Benjamin0c40a962016-08-01 12:05:50 -04007958 shouldFail: true,
7959 expectedError: ":UNEXPECTED_EXTENSION:",
7960 expectedLocalError: "remote error: unsupported extension",
7961 })
David Benjamin490469f2016-10-05 22:44:38 -04007962 testCases = append(testCases, testCase{
7963 testType: clientTest,
7964 name: "UnknownUnencryptedExtension-Client-TLS13",
7965 config: Config{
7966 MaxVersion: VersionTLS13,
7967 Bugs: ProtocolBugs{
7968 CustomUnencryptedExtension: expectedContents,
7969 },
7970 },
7971 shouldFail: true,
7972 expectedError: ":UNEXPECTED_EXTENSION:",
7973 // The shim must send an alert, but alerts at this point do not
7974 // get successfully decrypted by the runner.
7975 expectedLocalError: "local error: bad record MAC",
7976 })
7977 testCases = append(testCases, testCase{
7978 testType: clientTest,
7979 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7980 config: Config{
7981 MaxVersion: VersionTLS13,
7982 Bugs: ProtocolBugs{
7983 SendUnencryptedALPN: "foo",
7984 },
7985 },
7986 flags: []string{
7987 "-advertise-alpn", "\x03foo\x03bar",
7988 },
7989 shouldFail: true,
7990 expectedError: ":UNEXPECTED_EXTENSION:",
7991 // The shim must send an alert, but alerts at this point do not
7992 // get successfully decrypted by the runner.
7993 expectedLocalError: "local error: bad record MAC",
7994 })
David Benjamin0c40a962016-08-01 12:05:50 -04007995
7996 // Test a known but unoffered extension from the server.
7997 testCases = append(testCases, testCase{
7998 testType: clientTest,
7999 name: "UnofferedExtension-Client",
8000 config: Config{
8001 MaxVersion: VersionTLS12,
8002 Bugs: ProtocolBugs{
8003 SendALPN: "alpn",
8004 },
8005 },
8006 shouldFail: true,
8007 expectedError: ":UNEXPECTED_EXTENSION:",
8008 expectedLocalError: "remote error: unsupported extension",
8009 })
8010 testCases = append(testCases, testCase{
8011 testType: clientTest,
8012 name: "UnofferedExtension-Client-TLS13",
8013 config: Config{
8014 MaxVersion: VersionTLS13,
8015 Bugs: ProtocolBugs{
8016 SendALPN: "alpn",
8017 },
8018 },
8019 shouldFail: true,
8020 expectedError: ":UNEXPECTED_EXTENSION:",
8021 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008022 })
Adam Langley09505632015-07-30 18:10:13 -07008023}
8024
David Benjaminb36a3952015-12-01 18:53:13 -05008025func addRSAClientKeyExchangeTests() {
8026 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8027 testCases = append(testCases, testCase{
8028 testType: serverTest,
8029 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8030 config: Config{
8031 // Ensure the ClientHello version and final
8032 // version are different, to detect if the
8033 // server uses the wrong one.
8034 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008035 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008036 Bugs: ProtocolBugs{
8037 BadRSAClientKeyExchange: bad,
8038 },
8039 },
8040 shouldFail: true,
8041 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8042 })
8043 }
David Benjamine63d9d72016-09-19 18:27:34 -04008044
8045 // The server must compare whatever was in ClientHello.version for the
8046 // RSA premaster.
8047 testCases = append(testCases, testCase{
8048 testType: serverTest,
8049 name: "SendClientVersion-RSA",
8050 config: Config{
8051 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8052 Bugs: ProtocolBugs{
8053 SendClientVersion: 0x1234,
8054 },
8055 },
8056 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8057 })
David Benjaminb36a3952015-12-01 18:53:13 -05008058}
8059
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008060var testCurves = []struct {
8061 name string
8062 id CurveID
8063}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008064 {"P-256", CurveP256},
8065 {"P-384", CurveP384},
8066 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008067 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008068}
8069
Steven Valdez5440fe02016-07-18 12:40:30 -04008070const bogusCurve = 0x1234
8071
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008072func addCurveTests() {
8073 for _, curve := range testCurves {
8074 testCases = append(testCases, testCase{
8075 name: "CurveTest-Client-" + curve.name,
8076 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008077 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008078 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8079 CurvePreferences: []CurveID{curve.id},
8080 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008081 flags: []string{
8082 "-enable-all-curves",
8083 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8084 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008085 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008086 })
8087 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008088 name: "CurveTest-Client-" + curve.name + "-TLS13",
8089 config: Config{
8090 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008091 CurvePreferences: []CurveID{curve.id},
8092 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008093 flags: []string{
8094 "-enable-all-curves",
8095 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8096 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008097 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008098 })
8099 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008100 testType: serverTest,
8101 name: "CurveTest-Server-" + curve.name,
8102 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008103 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008104 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8105 CurvePreferences: []CurveID{curve.id},
8106 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008107 flags: []string{
8108 "-enable-all-curves",
8109 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8110 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008111 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008112 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008113 testCases = append(testCases, testCase{
8114 testType: serverTest,
8115 name: "CurveTest-Server-" + curve.name + "-TLS13",
8116 config: Config{
8117 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008118 CurvePreferences: []CurveID{curve.id},
8119 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008120 flags: []string{
8121 "-enable-all-curves",
8122 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8123 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008124 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008125 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008126 }
David Benjamin241ae832016-01-15 03:04:54 -05008127
8128 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008129 testCases = append(testCases, testCase{
8130 testType: serverTest,
8131 name: "UnknownCurve",
8132 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008133 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008134 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8135 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8136 },
8137 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008138
Steven Valdez803c77a2016-09-06 14:13:43 -04008139 // The server must be tolerant to bogus curves.
8140 testCases = append(testCases, testCase{
8141 testType: serverTest,
8142 name: "UnknownCurve-TLS13",
8143 config: Config{
8144 MaxVersion: VersionTLS13,
8145 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8146 },
8147 })
8148
David Benjamin4c3ddf72016-06-29 18:13:53 -04008149 // The server must not consider ECDHE ciphers when there are no
8150 // supported curves.
8151 testCases = append(testCases, testCase{
8152 testType: serverTest,
8153 name: "NoSupportedCurves",
8154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008155 MaxVersion: VersionTLS12,
8156 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8157 Bugs: ProtocolBugs{
8158 NoSupportedCurves: true,
8159 },
8160 },
8161 shouldFail: true,
8162 expectedError: ":NO_SHARED_CIPHER:",
8163 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008164 testCases = append(testCases, testCase{
8165 testType: serverTest,
8166 name: "NoSupportedCurves-TLS13",
8167 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008168 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008169 Bugs: ProtocolBugs{
8170 NoSupportedCurves: true,
8171 },
8172 },
8173 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008174 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008175 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008176
8177 // The server must fall back to another cipher when there are no
8178 // supported curves.
8179 testCases = append(testCases, testCase{
8180 testType: serverTest,
8181 name: "NoCommonCurves",
8182 config: Config{
8183 MaxVersion: VersionTLS12,
8184 CipherSuites: []uint16{
8185 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8186 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8187 },
8188 CurvePreferences: []CurveID{CurveP224},
8189 },
8190 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8191 })
8192
8193 // The client must reject bogus curves and disabled curves.
8194 testCases = append(testCases, testCase{
8195 name: "BadECDHECurve",
8196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008197 MaxVersion: VersionTLS12,
8198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8199 Bugs: ProtocolBugs{
8200 SendCurve: bogusCurve,
8201 },
8202 },
8203 shouldFail: true,
8204 expectedError: ":WRONG_CURVE:",
8205 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008206 testCases = append(testCases, testCase{
8207 name: "BadECDHECurve-TLS13",
8208 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008209 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008210 Bugs: ProtocolBugs{
8211 SendCurve: bogusCurve,
8212 },
8213 },
8214 shouldFail: true,
8215 expectedError: ":WRONG_CURVE:",
8216 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008217
8218 testCases = append(testCases, testCase{
8219 name: "UnsupportedCurve",
8220 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008221 MaxVersion: VersionTLS12,
8222 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8223 CurvePreferences: []CurveID{CurveP256},
8224 Bugs: ProtocolBugs{
8225 IgnorePeerCurvePreferences: true,
8226 },
8227 },
8228 flags: []string{"-p384-only"},
8229 shouldFail: true,
8230 expectedError: ":WRONG_CURVE:",
8231 })
8232
David Benjamin4f921572016-07-17 14:20:10 +02008233 testCases = append(testCases, testCase{
8234 // TODO(davidben): Add a TLS 1.3 version where
8235 // HelloRetryRequest requests an unsupported curve.
8236 name: "UnsupportedCurve-ServerHello-TLS13",
8237 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008238 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008239 CurvePreferences: []CurveID{CurveP384},
8240 Bugs: ProtocolBugs{
8241 SendCurve: CurveP256,
8242 },
8243 },
8244 flags: []string{"-p384-only"},
8245 shouldFail: true,
8246 expectedError: ":WRONG_CURVE:",
8247 })
8248
David Benjamin4c3ddf72016-06-29 18:13:53 -04008249 // Test invalid curve points.
8250 testCases = append(testCases, testCase{
8251 name: "InvalidECDHPoint-Client",
8252 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008253 MaxVersion: VersionTLS12,
8254 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8255 CurvePreferences: []CurveID{CurveP256},
8256 Bugs: ProtocolBugs{
8257 InvalidECDHPoint: true,
8258 },
8259 },
8260 shouldFail: true,
8261 expectedError: ":INVALID_ENCODING:",
8262 })
8263 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008264 name: "InvalidECDHPoint-Client-TLS13",
8265 config: Config{
8266 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008267 CurvePreferences: []CurveID{CurveP256},
8268 Bugs: ProtocolBugs{
8269 InvalidECDHPoint: true,
8270 },
8271 },
8272 shouldFail: true,
8273 expectedError: ":INVALID_ENCODING:",
8274 })
8275 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008276 testType: serverTest,
8277 name: "InvalidECDHPoint-Server",
8278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008279 MaxVersion: VersionTLS12,
8280 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8281 CurvePreferences: []CurveID{CurveP256},
8282 Bugs: ProtocolBugs{
8283 InvalidECDHPoint: true,
8284 },
8285 },
8286 shouldFail: true,
8287 expectedError: ":INVALID_ENCODING:",
8288 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008289 testCases = append(testCases, testCase{
8290 testType: serverTest,
8291 name: "InvalidECDHPoint-Server-TLS13",
8292 config: Config{
8293 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008294 CurvePreferences: []CurveID{CurveP256},
8295 Bugs: ProtocolBugs{
8296 InvalidECDHPoint: true,
8297 },
8298 },
8299 shouldFail: true,
8300 expectedError: ":INVALID_ENCODING:",
8301 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008302
8303 // The previous curve ID should be reported on TLS 1.2 resumption.
8304 testCases = append(testCases, testCase{
8305 name: "CurveID-Resume-Client",
8306 config: Config{
8307 MaxVersion: VersionTLS12,
8308 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8309 CurvePreferences: []CurveID{CurveX25519},
8310 },
8311 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8312 resumeSession: true,
8313 })
8314 testCases = append(testCases, testCase{
8315 testType: serverTest,
8316 name: "CurveID-Resume-Server",
8317 config: Config{
8318 MaxVersion: VersionTLS12,
8319 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8320 CurvePreferences: []CurveID{CurveX25519},
8321 },
8322 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8323 resumeSession: true,
8324 })
8325
8326 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8327 // one should be reported.
8328 testCases = append(testCases, testCase{
8329 name: "CurveID-Resume-Client-TLS13",
8330 config: Config{
8331 MaxVersion: VersionTLS13,
8332 CurvePreferences: []CurveID{CurveX25519},
8333 },
8334 resumeConfig: &Config{
8335 MaxVersion: VersionTLS13,
8336 CurvePreferences: []CurveID{CurveP256},
8337 },
8338 flags: []string{
8339 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8340 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8341 },
8342 resumeSession: true,
8343 })
8344 testCases = append(testCases, testCase{
8345 testType: serverTest,
8346 name: "CurveID-Resume-Server-TLS13",
8347 config: Config{
8348 MaxVersion: VersionTLS13,
8349 CurvePreferences: []CurveID{CurveX25519},
8350 },
8351 resumeConfig: &Config{
8352 MaxVersion: VersionTLS13,
8353 CurvePreferences: []CurveID{CurveP256},
8354 },
8355 flags: []string{
8356 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8357 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8358 },
8359 resumeSession: true,
8360 })
David Benjamina81967b2016-12-22 09:16:57 -05008361
8362 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8363 testCases = append(testCases, testCase{
8364 name: "PointFormat-ServerHello-TLS12",
8365 config: Config{
8366 MaxVersion: VersionTLS12,
8367 Bugs: ProtocolBugs{
8368 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8369 },
8370 },
8371 })
8372 testCases = append(testCases, testCase{
8373 name: "PointFormat-EncryptedExtensions-TLS13",
8374 config: Config{
8375 MaxVersion: VersionTLS13,
8376 Bugs: ProtocolBugs{
8377 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8378 },
8379 },
8380 shouldFail: true,
8381 expectedError: ":ERROR_PARSING_EXTENSION:",
8382 })
8383
8384 // Test that we tolerate unknown point formats, as long as
8385 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8386 // check they are still functional.
8387 testCases = append(testCases, testCase{
8388 name: "PointFormat-Client-Tolerance",
8389 config: Config{
8390 MaxVersion: VersionTLS12,
8391 Bugs: ProtocolBugs{
8392 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8393 },
8394 },
8395 })
8396 testCases = append(testCases, testCase{
8397 testType: serverTest,
8398 name: "PointFormat-Server-Tolerance",
8399 config: Config{
8400 MaxVersion: VersionTLS12,
8401 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8402 Bugs: ProtocolBugs{
8403 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8404 },
8405 },
8406 })
8407
8408 // Test TLS 1.2 does not require the point format extension to be
8409 // present.
8410 testCases = append(testCases, testCase{
8411 name: "PointFormat-Client-Missing",
8412 config: Config{
8413 MaxVersion: VersionTLS12,
8414 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8415 Bugs: ProtocolBugs{
8416 SendSupportedPointFormats: []byte{},
8417 },
8418 },
8419 })
8420 testCases = append(testCases, testCase{
8421 testType: serverTest,
8422 name: "PointFormat-Server-Missing",
8423 config: Config{
8424 MaxVersion: VersionTLS12,
8425 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8426 Bugs: ProtocolBugs{
8427 SendSupportedPointFormats: []byte{},
8428 },
8429 },
8430 })
8431
8432 // If the point format extension is present, uncompressed points must be
8433 // offered. BoringSSL requires this whether or not ECDHE is used.
8434 testCases = append(testCases, testCase{
8435 name: "PointFormat-Client-MissingUncompressed",
8436 config: Config{
8437 MaxVersion: VersionTLS12,
8438 Bugs: ProtocolBugs{
8439 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8440 },
8441 },
8442 shouldFail: true,
8443 expectedError: ":ERROR_PARSING_EXTENSION:",
8444 })
8445 testCases = append(testCases, testCase{
8446 testType: serverTest,
8447 name: "PointFormat-Server-MissingUncompressed",
8448 config: Config{
8449 MaxVersion: VersionTLS12,
8450 Bugs: ProtocolBugs{
8451 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8452 },
8453 },
8454 shouldFail: true,
8455 expectedError: ":ERROR_PARSING_EXTENSION:",
8456 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008457}
8458
David Benjaminc9ae27c2016-06-24 22:56:37 -04008459func addTLS13RecordTests() {
8460 testCases = append(testCases, testCase{
8461 name: "TLS13-RecordPadding",
8462 config: Config{
8463 MaxVersion: VersionTLS13,
8464 MinVersion: VersionTLS13,
8465 Bugs: ProtocolBugs{
8466 RecordPadding: 10,
8467 },
8468 },
8469 })
8470
8471 testCases = append(testCases, testCase{
8472 name: "TLS13-EmptyRecords",
8473 config: Config{
8474 MaxVersion: VersionTLS13,
8475 MinVersion: VersionTLS13,
8476 Bugs: ProtocolBugs{
8477 OmitRecordContents: true,
8478 },
8479 },
8480 shouldFail: true,
8481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8482 })
8483
8484 testCases = append(testCases, testCase{
8485 name: "TLS13-OnlyPadding",
8486 config: Config{
8487 MaxVersion: VersionTLS13,
8488 MinVersion: VersionTLS13,
8489 Bugs: ProtocolBugs{
8490 OmitRecordContents: true,
8491 RecordPadding: 10,
8492 },
8493 },
8494 shouldFail: true,
8495 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8496 })
8497
8498 testCases = append(testCases, testCase{
8499 name: "TLS13-WrongOuterRecord",
8500 config: Config{
8501 MaxVersion: VersionTLS13,
8502 MinVersion: VersionTLS13,
8503 Bugs: ProtocolBugs{
8504 OuterRecordType: recordTypeHandshake,
8505 },
8506 },
8507 shouldFail: true,
8508 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8509 })
8510}
8511
Steven Valdez5b986082016-09-01 12:29:49 -04008512func addSessionTicketTests() {
8513 testCases = append(testCases, testCase{
8514 // In TLS 1.2 and below, empty NewSessionTicket messages
8515 // mean the server changed its mind on sending a ticket.
8516 name: "SendEmptySessionTicket",
8517 config: Config{
8518 MaxVersion: VersionTLS12,
8519 Bugs: ProtocolBugs{
8520 SendEmptySessionTicket: true,
8521 },
8522 },
8523 flags: []string{"-expect-no-session"},
8524 })
8525
8526 // Test that the server ignores unknown PSK modes.
8527 testCases = append(testCases, testCase{
8528 testType: serverTest,
8529 name: "TLS13-SendUnknownModeSessionTicket-Server",
8530 config: Config{
8531 MaxVersion: VersionTLS13,
8532 Bugs: ProtocolBugs{
8533 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008534 },
8535 },
8536 resumeSession: true,
8537 expectedResumeVersion: VersionTLS13,
8538 })
8539
Steven Valdeza833c352016-11-01 13:39:36 -04008540 // Test that the server does not send session tickets with no matching key exchange mode.
8541 testCases = append(testCases, testCase{
8542 testType: serverTest,
8543 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8544 config: Config{
8545 MaxVersion: VersionTLS13,
8546 Bugs: ProtocolBugs{
8547 SendPSKKeyExchangeModes: []byte{0x1a},
8548 ExpectNoNewSessionTicket: true,
8549 },
8550 },
8551 })
8552
8553 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008554 testCases = append(testCases, testCase{
8555 testType: serverTest,
8556 name: "TLS13-SendBadKEModeSessionTicket-Server",
8557 config: Config{
8558 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008559 },
8560 resumeConfig: &Config{
8561 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008562 Bugs: ProtocolBugs{
8563 SendPSKKeyExchangeModes: []byte{0x1a},
8564 },
8565 },
8566 resumeSession: true,
8567 expectResumeRejected: true,
8568 })
8569
Steven Valdeza833c352016-11-01 13:39:36 -04008570 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008571 testCases = append(testCases, testCase{
8572 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008573 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008574 config: Config{
8575 MaxVersion: VersionTLS13,
8576 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008577 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008578 },
8579 },
Steven Valdeza833c352016-11-01 13:39:36 -04008580 resumeSession: true,
8581 flags: []string{
8582 "-resumption-delay", "10",
8583 },
Steven Valdez5b986082016-09-01 12:29:49 -04008584 })
8585
Steven Valdeza833c352016-11-01 13:39:36 -04008586 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008587 testCases = append(testCases, testCase{
8588 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008589 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008590 config: Config{
8591 MaxVersion: VersionTLS13,
8592 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008593 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008594 },
8595 },
Steven Valdeza833c352016-11-01 13:39:36 -04008596 resumeSession: true,
8597 shouldFail: true,
8598 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008599 })
8600
Steven Valdez08b65f42016-12-07 15:29:45 -05008601 testCases = append(testCases, testCase{
8602 testType: clientTest,
8603 name: "TLS13-SendTicketEarlyDataInfo",
8604 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008605 MaxVersion: VersionTLS13,
8606 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008607 },
8608 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008609 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008610 "-expect-early-data-info",
8611 },
8612 })
8613
David Benjamin9b160662017-01-25 19:53:43 -05008614 // Test that 0-RTT tickets are ignored in clients unless opted in.
8615 testCases = append(testCases, testCase{
8616 testType: clientTest,
8617 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8618 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008619 MaxVersion: VersionTLS13,
8620 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008621 },
8622 })
8623
Steven Valdez08b65f42016-12-07 15:29:45 -05008624 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008625 testType: clientTest,
8626 name: "TLS13-DuplicateTicketEarlyDataInfo",
8627 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008628 MaxVersion: VersionTLS13,
8629 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008630 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008631 DuplicateTicketEarlyDataInfo: true,
8632 },
8633 },
8634 shouldFail: true,
8635 expectedError: ":DUPLICATE_EXTENSION:",
8636 expectedLocalError: "remote error: illegal parameter",
8637 })
8638
8639 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008640 testType: serverTest,
8641 name: "TLS13-ExpectTicketEarlyDataInfo",
8642 config: Config{
8643 MaxVersion: VersionTLS13,
8644 Bugs: ProtocolBugs{
8645 ExpectTicketEarlyDataInfo: true,
8646 },
8647 },
8648 flags: []string{
8649 "-enable-early-data",
8650 },
8651 })
David Benjamin17b30832017-01-28 14:00:32 -05008652
8653 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8654 // is honored.
8655 testCases = append(testCases, testCase{
8656 testType: clientTest,
8657 name: "TLS13-HonorServerSessionTicketLifetime",
8658 config: Config{
8659 MaxVersion: VersionTLS13,
8660 Bugs: ProtocolBugs{
8661 SendTicketLifetime: 20 * time.Second,
8662 },
8663 },
8664 flags: []string{
8665 "-resumption-delay", "19",
8666 },
8667 resumeSession: true,
8668 })
8669 testCases = append(testCases, testCase{
8670 testType: clientTest,
8671 name: "TLS13-HonorServerSessionTicketLifetime-2",
8672 config: Config{
8673 MaxVersion: VersionTLS13,
8674 Bugs: ProtocolBugs{
8675 SendTicketLifetime: 20 * time.Second,
8676 // The client should not offer the expired session.
8677 ExpectNoTLS13PSK: true,
8678 },
8679 },
8680 flags: []string{
8681 "-resumption-delay", "21",
8682 },
David Benjamin023d4192017-02-06 13:49:07 -05008683 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008684 expectResumeRejected: true,
8685 })
Steven Valdez5b986082016-09-01 12:29:49 -04008686}
8687
David Benjamin82261be2016-07-07 14:32:50 -07008688func addChangeCipherSpecTests() {
8689 // Test missing ChangeCipherSpecs.
8690 testCases = append(testCases, testCase{
8691 name: "SkipChangeCipherSpec-Client",
8692 config: Config{
8693 MaxVersion: VersionTLS12,
8694 Bugs: ProtocolBugs{
8695 SkipChangeCipherSpec: true,
8696 },
8697 },
8698 shouldFail: true,
8699 expectedError: ":UNEXPECTED_RECORD:",
8700 })
8701 testCases = append(testCases, testCase{
8702 testType: serverTest,
8703 name: "SkipChangeCipherSpec-Server",
8704 config: Config{
8705 MaxVersion: VersionTLS12,
8706 Bugs: ProtocolBugs{
8707 SkipChangeCipherSpec: true,
8708 },
8709 },
8710 shouldFail: true,
8711 expectedError: ":UNEXPECTED_RECORD:",
8712 })
8713 testCases = append(testCases, testCase{
8714 testType: serverTest,
8715 name: "SkipChangeCipherSpec-Server-NPN",
8716 config: Config{
8717 MaxVersion: VersionTLS12,
8718 NextProtos: []string{"bar"},
8719 Bugs: ProtocolBugs{
8720 SkipChangeCipherSpec: true,
8721 },
8722 },
8723 flags: []string{
8724 "-advertise-npn", "\x03foo\x03bar\x03baz",
8725 },
8726 shouldFail: true,
8727 expectedError: ":UNEXPECTED_RECORD:",
8728 })
8729
8730 // Test synchronization between the handshake and ChangeCipherSpec.
8731 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8732 // rejected. Test both with and without handshake packing to handle both
8733 // when the partial post-CCS message is in its own record and when it is
8734 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008735 for _, packed := range []bool{false, true} {
8736 var suffix string
8737 if packed {
8738 suffix = "-Packed"
8739 }
8740
8741 testCases = append(testCases, testCase{
8742 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8743 config: Config{
8744 MaxVersion: VersionTLS12,
8745 Bugs: ProtocolBugs{
8746 FragmentAcrossChangeCipherSpec: true,
8747 PackHandshakeFlight: packed,
8748 },
8749 },
8750 shouldFail: true,
8751 expectedError: ":UNEXPECTED_RECORD:",
8752 })
8753 testCases = append(testCases, testCase{
8754 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8755 config: Config{
8756 MaxVersion: VersionTLS12,
8757 },
8758 resumeSession: true,
8759 resumeConfig: &Config{
8760 MaxVersion: VersionTLS12,
8761 Bugs: ProtocolBugs{
8762 FragmentAcrossChangeCipherSpec: true,
8763 PackHandshakeFlight: packed,
8764 },
8765 },
8766 shouldFail: true,
8767 expectedError: ":UNEXPECTED_RECORD:",
8768 })
8769 testCases = append(testCases, testCase{
8770 testType: serverTest,
8771 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8772 config: Config{
8773 MaxVersion: VersionTLS12,
8774 Bugs: ProtocolBugs{
8775 FragmentAcrossChangeCipherSpec: true,
8776 PackHandshakeFlight: packed,
8777 },
8778 },
8779 shouldFail: true,
8780 expectedError: ":UNEXPECTED_RECORD:",
8781 })
8782 testCases = append(testCases, testCase{
8783 testType: serverTest,
8784 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8785 config: Config{
8786 MaxVersion: VersionTLS12,
8787 },
8788 resumeSession: true,
8789 resumeConfig: &Config{
8790 MaxVersion: VersionTLS12,
8791 Bugs: ProtocolBugs{
8792 FragmentAcrossChangeCipherSpec: true,
8793 PackHandshakeFlight: packed,
8794 },
8795 },
8796 shouldFail: true,
8797 expectedError: ":UNEXPECTED_RECORD:",
8798 })
8799 testCases = append(testCases, testCase{
8800 testType: serverTest,
8801 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8802 config: Config{
8803 MaxVersion: VersionTLS12,
8804 NextProtos: []string{"bar"},
8805 Bugs: ProtocolBugs{
8806 FragmentAcrossChangeCipherSpec: true,
8807 PackHandshakeFlight: packed,
8808 },
8809 },
8810 flags: []string{
8811 "-advertise-npn", "\x03foo\x03bar\x03baz",
8812 },
8813 shouldFail: true,
8814 expectedError: ":UNEXPECTED_RECORD:",
8815 })
8816 }
8817
David Benjamin61672812016-07-14 23:10:43 -04008818 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8819 // messages in the handshake queue. Do this by testing the server
8820 // reading the client Finished, reversing the flight so Finished comes
8821 // first.
8822 testCases = append(testCases, testCase{
8823 protocol: dtls,
8824 testType: serverTest,
8825 name: "SendUnencryptedFinished-DTLS",
8826 config: Config{
8827 MaxVersion: VersionTLS12,
8828 Bugs: ProtocolBugs{
8829 SendUnencryptedFinished: true,
8830 ReverseHandshakeFragments: true,
8831 },
8832 },
8833 shouldFail: true,
8834 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8835 })
8836
Steven Valdez143e8b32016-07-11 13:19:03 -04008837 // Test synchronization between encryption changes and the handshake in
8838 // TLS 1.3, where ChangeCipherSpec is implicit.
8839 testCases = append(testCases, testCase{
8840 name: "PartialEncryptedExtensionsWithServerHello",
8841 config: Config{
8842 MaxVersion: VersionTLS13,
8843 Bugs: ProtocolBugs{
8844 PartialEncryptedExtensionsWithServerHello: true,
8845 },
8846 },
8847 shouldFail: true,
8848 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8849 })
8850 testCases = append(testCases, testCase{
8851 testType: serverTest,
8852 name: "PartialClientFinishedWithClientHello",
8853 config: Config{
8854 MaxVersion: VersionTLS13,
8855 Bugs: ProtocolBugs{
8856 PartialClientFinishedWithClientHello: true,
8857 },
8858 },
8859 shouldFail: true,
8860 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8861 })
8862
David Benjamin82261be2016-07-07 14:32:50 -07008863 // Test that early ChangeCipherSpecs are handled correctly.
8864 testCases = append(testCases, testCase{
8865 testType: serverTest,
8866 name: "EarlyChangeCipherSpec-server-1",
8867 config: Config{
8868 MaxVersion: VersionTLS12,
8869 Bugs: ProtocolBugs{
8870 EarlyChangeCipherSpec: 1,
8871 },
8872 },
8873 shouldFail: true,
8874 expectedError: ":UNEXPECTED_RECORD:",
8875 })
8876 testCases = append(testCases, testCase{
8877 testType: serverTest,
8878 name: "EarlyChangeCipherSpec-server-2",
8879 config: Config{
8880 MaxVersion: VersionTLS12,
8881 Bugs: ProtocolBugs{
8882 EarlyChangeCipherSpec: 2,
8883 },
8884 },
8885 shouldFail: true,
8886 expectedError: ":UNEXPECTED_RECORD:",
8887 })
8888 testCases = append(testCases, testCase{
8889 protocol: dtls,
8890 name: "StrayChangeCipherSpec",
8891 config: Config{
8892 // TODO(davidben): Once DTLS 1.3 exists, test
8893 // that stray ChangeCipherSpec messages are
8894 // rejected.
8895 MaxVersion: VersionTLS12,
8896 Bugs: ProtocolBugs{
8897 StrayChangeCipherSpec: true,
8898 },
8899 },
8900 })
8901
8902 // Test that the contents of ChangeCipherSpec are checked.
8903 testCases = append(testCases, testCase{
8904 name: "BadChangeCipherSpec-1",
8905 config: Config{
8906 MaxVersion: VersionTLS12,
8907 Bugs: ProtocolBugs{
8908 BadChangeCipherSpec: []byte{2},
8909 },
8910 },
8911 shouldFail: true,
8912 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8913 })
8914 testCases = append(testCases, testCase{
8915 name: "BadChangeCipherSpec-2",
8916 config: Config{
8917 MaxVersion: VersionTLS12,
8918 Bugs: ProtocolBugs{
8919 BadChangeCipherSpec: []byte{1, 1},
8920 },
8921 },
8922 shouldFail: true,
8923 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8924 })
8925 testCases = append(testCases, testCase{
8926 protocol: dtls,
8927 name: "BadChangeCipherSpec-DTLS-1",
8928 config: Config{
8929 MaxVersion: VersionTLS12,
8930 Bugs: ProtocolBugs{
8931 BadChangeCipherSpec: []byte{2},
8932 },
8933 },
8934 shouldFail: true,
8935 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8936 })
8937 testCases = append(testCases, testCase{
8938 protocol: dtls,
8939 name: "BadChangeCipherSpec-DTLS-2",
8940 config: Config{
8941 MaxVersion: VersionTLS12,
8942 Bugs: ProtocolBugs{
8943 BadChangeCipherSpec: []byte{1, 1},
8944 },
8945 },
8946 shouldFail: true,
8947 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8948 })
8949}
8950
David Benjamincd2c8062016-09-09 11:28:16 -04008951type perMessageTest struct {
8952 messageType uint8
8953 test testCase
8954}
8955
8956// makePerMessageTests returns a series of test templates which cover each
8957// message in the TLS handshake. These may be used with bugs like
8958// WrongMessageType to fully test a per-message bug.
8959func makePerMessageTests() []perMessageTest {
8960 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008961 for _, protocol := range []protocol{tls, dtls} {
8962 var suffix string
8963 if protocol == dtls {
8964 suffix = "-DTLS"
8965 }
8966
David Benjamincd2c8062016-09-09 11:28:16 -04008967 ret = append(ret, perMessageTest{
8968 messageType: typeClientHello,
8969 test: testCase{
8970 protocol: protocol,
8971 testType: serverTest,
8972 name: "ClientHello" + suffix,
8973 config: Config{
8974 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008975 },
8976 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008977 })
8978
8979 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008980 ret = append(ret, perMessageTest{
8981 messageType: typeHelloVerifyRequest,
8982 test: testCase{
8983 protocol: protocol,
8984 name: "HelloVerifyRequest" + suffix,
8985 config: Config{
8986 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008987 },
8988 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008989 })
8990 }
8991
David Benjamincd2c8062016-09-09 11:28:16 -04008992 ret = append(ret, perMessageTest{
8993 messageType: typeServerHello,
8994 test: testCase{
8995 protocol: protocol,
8996 name: "ServerHello" + suffix,
8997 config: Config{
8998 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008999 },
9000 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009001 })
9002
David Benjamincd2c8062016-09-09 11:28:16 -04009003 ret = append(ret, perMessageTest{
9004 messageType: typeCertificate,
9005 test: testCase{
9006 protocol: protocol,
9007 name: "ServerCertificate" + suffix,
9008 config: Config{
9009 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009010 },
9011 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009012 })
9013
David Benjamincd2c8062016-09-09 11:28:16 -04009014 ret = append(ret, perMessageTest{
9015 messageType: typeCertificateStatus,
9016 test: testCase{
9017 protocol: protocol,
9018 name: "CertificateStatus" + suffix,
9019 config: Config{
9020 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009021 },
David Benjamincd2c8062016-09-09 11:28:16 -04009022 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009023 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009024 })
9025
David Benjamincd2c8062016-09-09 11:28:16 -04009026 ret = append(ret, perMessageTest{
9027 messageType: typeServerKeyExchange,
9028 test: testCase{
9029 protocol: protocol,
9030 name: "ServerKeyExchange" + suffix,
9031 config: Config{
9032 MaxVersion: VersionTLS12,
9033 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009034 },
9035 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009036 })
9037
David Benjamincd2c8062016-09-09 11:28:16 -04009038 ret = append(ret, perMessageTest{
9039 messageType: typeCertificateRequest,
9040 test: testCase{
9041 protocol: protocol,
9042 name: "CertificateRequest" + suffix,
9043 config: Config{
9044 MaxVersion: VersionTLS12,
9045 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009046 },
9047 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009048 })
9049
David Benjamincd2c8062016-09-09 11:28:16 -04009050 ret = append(ret, perMessageTest{
9051 messageType: typeServerHelloDone,
9052 test: testCase{
9053 protocol: protocol,
9054 name: "ServerHelloDone" + suffix,
9055 config: Config{
9056 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009057 },
9058 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009059 })
9060
David Benjamincd2c8062016-09-09 11:28:16 -04009061 ret = append(ret, perMessageTest{
9062 messageType: typeCertificate,
9063 test: testCase{
9064 testType: serverTest,
9065 protocol: protocol,
9066 name: "ClientCertificate" + suffix,
9067 config: Config{
9068 Certificates: []Certificate{rsaCertificate},
9069 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009070 },
David Benjamincd2c8062016-09-09 11:28:16 -04009071 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009072 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009073 })
9074
David Benjamincd2c8062016-09-09 11:28:16 -04009075 ret = append(ret, perMessageTest{
9076 messageType: typeCertificateVerify,
9077 test: testCase{
9078 testType: serverTest,
9079 protocol: protocol,
9080 name: "CertificateVerify" + suffix,
9081 config: Config{
9082 Certificates: []Certificate{rsaCertificate},
9083 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009084 },
David Benjamincd2c8062016-09-09 11:28:16 -04009085 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009086 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009087 })
9088
David Benjamincd2c8062016-09-09 11:28:16 -04009089 ret = append(ret, perMessageTest{
9090 messageType: typeClientKeyExchange,
9091 test: testCase{
9092 testType: serverTest,
9093 protocol: protocol,
9094 name: "ClientKeyExchange" + suffix,
9095 config: Config{
9096 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009097 },
9098 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009099 })
9100
9101 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009102 ret = append(ret, perMessageTest{
9103 messageType: typeNextProtocol,
9104 test: testCase{
9105 testType: serverTest,
9106 protocol: protocol,
9107 name: "NextProtocol" + suffix,
9108 config: Config{
9109 MaxVersion: VersionTLS12,
9110 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009111 },
David Benjamincd2c8062016-09-09 11:28:16 -04009112 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009113 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009114 })
9115
David Benjamincd2c8062016-09-09 11:28:16 -04009116 ret = append(ret, perMessageTest{
9117 messageType: typeChannelID,
9118 test: testCase{
9119 testType: serverTest,
9120 protocol: protocol,
9121 name: "ChannelID" + suffix,
9122 config: Config{
9123 MaxVersion: VersionTLS12,
9124 ChannelID: channelIDKey,
9125 },
9126 flags: []string{
9127 "-expect-channel-id",
9128 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009129 },
9130 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009131 })
9132 }
9133
David Benjamincd2c8062016-09-09 11:28:16 -04009134 ret = append(ret, perMessageTest{
9135 messageType: typeFinished,
9136 test: testCase{
9137 testType: serverTest,
9138 protocol: protocol,
9139 name: "ClientFinished" + suffix,
9140 config: Config{
9141 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009142 },
9143 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009144 })
9145
David Benjamincd2c8062016-09-09 11:28:16 -04009146 ret = append(ret, perMessageTest{
9147 messageType: typeNewSessionTicket,
9148 test: testCase{
9149 protocol: protocol,
9150 name: "NewSessionTicket" + suffix,
9151 config: Config{
9152 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009153 },
9154 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009155 })
9156
David Benjamincd2c8062016-09-09 11:28:16 -04009157 ret = append(ret, perMessageTest{
9158 messageType: typeFinished,
9159 test: testCase{
9160 protocol: protocol,
9161 name: "ServerFinished" + suffix,
9162 config: Config{
9163 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009164 },
9165 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009166 })
9167
9168 }
David Benjamincd2c8062016-09-09 11:28:16 -04009169
9170 ret = append(ret, perMessageTest{
9171 messageType: typeClientHello,
9172 test: testCase{
9173 testType: serverTest,
9174 name: "TLS13-ClientHello",
9175 config: Config{
9176 MaxVersion: VersionTLS13,
9177 },
9178 },
9179 })
9180
9181 ret = append(ret, perMessageTest{
9182 messageType: typeServerHello,
9183 test: testCase{
9184 name: "TLS13-ServerHello",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
9187 },
9188 },
9189 })
9190
9191 ret = append(ret, perMessageTest{
9192 messageType: typeEncryptedExtensions,
9193 test: testCase{
9194 name: "TLS13-EncryptedExtensions",
9195 config: Config{
9196 MaxVersion: VersionTLS13,
9197 },
9198 },
9199 })
9200
9201 ret = append(ret, perMessageTest{
9202 messageType: typeCertificateRequest,
9203 test: testCase{
9204 name: "TLS13-CertificateRequest",
9205 config: Config{
9206 MaxVersion: VersionTLS13,
9207 ClientAuth: RequireAnyClientCert,
9208 },
9209 },
9210 })
9211
9212 ret = append(ret, perMessageTest{
9213 messageType: typeCertificate,
9214 test: testCase{
9215 name: "TLS13-ServerCertificate",
9216 config: Config{
9217 MaxVersion: VersionTLS13,
9218 },
9219 },
9220 })
9221
9222 ret = append(ret, perMessageTest{
9223 messageType: typeCertificateVerify,
9224 test: testCase{
9225 name: "TLS13-ServerCertificateVerify",
9226 config: Config{
9227 MaxVersion: VersionTLS13,
9228 },
9229 },
9230 })
9231
9232 ret = append(ret, perMessageTest{
9233 messageType: typeFinished,
9234 test: testCase{
9235 name: "TLS13-ServerFinished",
9236 config: Config{
9237 MaxVersion: VersionTLS13,
9238 },
9239 },
9240 })
9241
9242 ret = append(ret, perMessageTest{
9243 messageType: typeCertificate,
9244 test: testCase{
9245 testType: serverTest,
9246 name: "TLS13-ClientCertificate",
9247 config: Config{
9248 Certificates: []Certificate{rsaCertificate},
9249 MaxVersion: VersionTLS13,
9250 },
9251 flags: []string{"-require-any-client-certificate"},
9252 },
9253 })
9254
9255 ret = append(ret, perMessageTest{
9256 messageType: typeCertificateVerify,
9257 test: testCase{
9258 testType: serverTest,
9259 name: "TLS13-ClientCertificateVerify",
9260 config: Config{
9261 Certificates: []Certificate{rsaCertificate},
9262 MaxVersion: VersionTLS13,
9263 },
9264 flags: []string{"-require-any-client-certificate"},
9265 },
9266 })
9267
9268 ret = append(ret, perMessageTest{
9269 messageType: typeFinished,
9270 test: testCase{
9271 testType: serverTest,
9272 name: "TLS13-ClientFinished",
9273 config: Config{
9274 MaxVersion: VersionTLS13,
9275 },
9276 },
9277 })
9278
9279 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009280}
9281
David Benjamincd2c8062016-09-09 11:28:16 -04009282func addWrongMessageTypeTests() {
9283 for _, t := range makePerMessageTests() {
9284 t.test.name = "WrongMessageType-" + t.test.name
9285 t.test.config.Bugs.SendWrongMessageType = t.messageType
9286 t.test.shouldFail = true
9287 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9288 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009289
David Benjamincd2c8062016-09-09 11:28:16 -04009290 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9291 // In TLS 1.3, a bad ServerHello means the client sends
9292 // an unencrypted alert while the server expects
9293 // encryption, so the alert is not readable by runner.
9294 t.test.expectedLocalError = "local error: bad record MAC"
9295 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009296
David Benjamincd2c8062016-09-09 11:28:16 -04009297 testCases = append(testCases, t.test)
9298 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009299}
9300
David Benjamin639846e2016-09-09 11:41:18 -04009301func addTrailingMessageDataTests() {
9302 for _, t := range makePerMessageTests() {
9303 t.test.name = "TrailingMessageData-" + t.test.name
9304 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9305 t.test.shouldFail = true
9306 t.test.expectedError = ":DECODE_ERROR:"
9307 t.test.expectedLocalError = "remote error: error decoding message"
9308
9309 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9310 // In TLS 1.3, a bad ServerHello means the client sends
9311 // an unencrypted alert while the server expects
9312 // encryption, so the alert is not readable by runner.
9313 t.test.expectedLocalError = "local error: bad record MAC"
9314 }
9315
9316 if t.messageType == typeFinished {
9317 // Bad Finished messages read as the verify data having
9318 // the wrong length.
9319 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9320 t.test.expectedLocalError = "remote error: error decrypting message"
9321 }
9322
9323 testCases = append(testCases, t.test)
9324 }
9325}
9326
Steven Valdez143e8b32016-07-11 13:19:03 -04009327func addTLS13HandshakeTests() {
9328 testCases = append(testCases, testCase{
9329 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009330 name: "NegotiatePSKResumption-TLS13",
9331 config: Config{
9332 MaxVersion: VersionTLS13,
9333 Bugs: ProtocolBugs{
9334 NegotiatePSKResumption: true,
9335 },
9336 },
9337 resumeSession: true,
9338 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009339 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009340 })
9341
9342 testCases = append(testCases, testCase{
9343 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009344 name: "MissingKeyShare-Client",
9345 config: Config{
9346 MaxVersion: VersionTLS13,
9347 Bugs: ProtocolBugs{
9348 MissingKeyShare: true,
9349 },
9350 },
9351 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009352 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009353 })
9354
9355 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009356 testType: serverTest,
9357 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009358 config: Config{
9359 MaxVersion: VersionTLS13,
9360 Bugs: ProtocolBugs{
9361 MissingKeyShare: true,
9362 },
9363 },
9364 shouldFail: true,
9365 expectedError: ":MISSING_KEY_SHARE:",
9366 })
9367
9368 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009369 testType: serverTest,
9370 name: "DuplicateKeyShares",
9371 config: Config{
9372 MaxVersion: VersionTLS13,
9373 Bugs: ProtocolBugs{
9374 DuplicateKeyShares: true,
9375 },
9376 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009377 shouldFail: true,
9378 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009379 })
9380
9381 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009382 testType: serverTest,
9383 name: "SkipEarlyData",
9384 config: Config{
9385 MaxVersion: VersionTLS13,
9386 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009387 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009388 },
9389 },
9390 })
9391
9392 testCases = append(testCases, testCase{
9393 testType: serverTest,
9394 name: "SkipEarlyData-OmitEarlyDataExtension",
9395 config: Config{
9396 MaxVersion: VersionTLS13,
9397 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009398 SendFakeEarlyDataLength: 4,
9399 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009400 },
9401 },
9402 shouldFail: true,
9403 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9404 })
9405
9406 testCases = append(testCases, testCase{
9407 testType: serverTest,
9408 name: "SkipEarlyData-TooMuchData",
9409 config: Config{
9410 MaxVersion: VersionTLS13,
9411 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009412 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009413 },
9414 },
9415 shouldFail: true,
9416 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9417 })
9418
9419 testCases = append(testCases, testCase{
9420 testType: serverTest,
9421 name: "SkipEarlyData-Interleaved",
9422 config: Config{
9423 MaxVersion: VersionTLS13,
9424 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009425 SendFakeEarlyDataLength: 4,
9426 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009427 },
9428 },
9429 shouldFail: true,
9430 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9431 })
9432
9433 testCases = append(testCases, testCase{
9434 testType: serverTest,
9435 name: "SkipEarlyData-EarlyDataInTLS12",
9436 config: Config{
9437 MaxVersion: VersionTLS13,
9438 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009439 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009440 },
9441 },
9442 shouldFail: true,
9443 expectedError: ":UNEXPECTED_RECORD:",
9444 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9445 })
9446
9447 testCases = append(testCases, testCase{
9448 testType: serverTest,
9449 name: "SkipEarlyData-HRR",
9450 config: Config{
9451 MaxVersion: VersionTLS13,
9452 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009453 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009454 },
9455 DefaultCurves: []CurveID{},
9456 },
9457 })
9458
9459 testCases = append(testCases, testCase{
9460 testType: serverTest,
9461 name: "SkipEarlyData-HRR-Interleaved",
9462 config: Config{
9463 MaxVersion: VersionTLS13,
9464 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009465 SendFakeEarlyDataLength: 4,
9466 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009467 },
9468 DefaultCurves: []CurveID{},
9469 },
9470 shouldFail: true,
9471 expectedError: ":UNEXPECTED_RECORD:",
9472 })
9473
9474 testCases = append(testCases, testCase{
9475 testType: serverTest,
9476 name: "SkipEarlyData-HRR-TooMuchData",
9477 config: Config{
9478 MaxVersion: VersionTLS13,
9479 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009480 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009481 },
9482 DefaultCurves: []CurveID{},
9483 },
9484 shouldFail: true,
9485 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9486 })
9487
9488 // Test that skipping early data looking for cleartext correctly
9489 // processes an alert record.
9490 testCases = append(testCases, testCase{
9491 testType: serverTest,
9492 name: "SkipEarlyData-HRR-FatalAlert",
9493 config: Config{
9494 MaxVersion: VersionTLS13,
9495 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009496 SendEarlyAlert: true,
9497 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009498 },
9499 DefaultCurves: []CurveID{},
9500 },
9501 shouldFail: true,
9502 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9503 })
9504
9505 testCases = append(testCases, testCase{
9506 testType: serverTest,
9507 name: "SkipEarlyData-SecondClientHelloEarlyData",
9508 config: Config{
9509 MaxVersion: VersionTLS13,
9510 Bugs: ProtocolBugs{
9511 SendEarlyDataOnSecondClientHello: true,
9512 },
9513 DefaultCurves: []CurveID{},
9514 },
9515 shouldFail: true,
9516 expectedLocalError: "remote error: bad record MAC",
9517 })
9518
9519 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009520 testType: clientTest,
9521 name: "EmptyEncryptedExtensions",
9522 config: Config{
9523 MaxVersion: VersionTLS13,
9524 Bugs: ProtocolBugs{
9525 EmptyEncryptedExtensions: true,
9526 },
9527 },
9528 shouldFail: true,
9529 expectedLocalError: "remote error: error decoding message",
9530 })
9531
9532 testCases = append(testCases, testCase{
9533 testType: clientTest,
9534 name: "EncryptedExtensionsWithKeyShare",
9535 config: Config{
9536 MaxVersion: VersionTLS13,
9537 Bugs: ProtocolBugs{
9538 EncryptedExtensionsWithKeyShare: true,
9539 },
9540 },
9541 shouldFail: true,
9542 expectedLocalError: "remote error: unsupported extension",
9543 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009544
9545 testCases = append(testCases, testCase{
9546 testType: serverTest,
9547 name: "SendHelloRetryRequest",
9548 config: Config{
9549 MaxVersion: VersionTLS13,
9550 // Require a HelloRetryRequest for every curve.
9551 DefaultCurves: []CurveID{},
9552 },
9553 expectedCurveID: CurveX25519,
9554 })
9555
9556 testCases = append(testCases, testCase{
9557 testType: serverTest,
9558 name: "SendHelloRetryRequest-2",
9559 config: Config{
9560 MaxVersion: VersionTLS13,
9561 DefaultCurves: []CurveID{CurveP384},
9562 },
9563 // Although the ClientHello did not predict our preferred curve,
9564 // we always select it whether it is predicted or not.
9565 expectedCurveID: CurveX25519,
9566 })
9567
9568 testCases = append(testCases, testCase{
9569 name: "UnknownCurve-HelloRetryRequest",
9570 config: Config{
9571 MaxVersion: VersionTLS13,
9572 // P-384 requires HelloRetryRequest in BoringSSL.
9573 CurvePreferences: []CurveID{CurveP384},
9574 Bugs: ProtocolBugs{
9575 SendHelloRetryRequestCurve: bogusCurve,
9576 },
9577 },
9578 shouldFail: true,
9579 expectedError: ":WRONG_CURVE:",
9580 })
9581
9582 testCases = append(testCases, testCase{
9583 name: "DisabledCurve-HelloRetryRequest",
9584 config: Config{
9585 MaxVersion: VersionTLS13,
9586 CurvePreferences: []CurveID{CurveP256},
9587 Bugs: ProtocolBugs{
9588 IgnorePeerCurvePreferences: true,
9589 },
9590 },
9591 flags: []string{"-p384-only"},
9592 shouldFail: true,
9593 expectedError: ":WRONG_CURVE:",
9594 })
9595
9596 testCases = append(testCases, testCase{
9597 name: "UnnecessaryHelloRetryRequest",
9598 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009599 MaxVersion: VersionTLS13,
9600 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009601 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009602 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009603 },
9604 },
9605 shouldFail: true,
9606 expectedError: ":WRONG_CURVE:",
9607 })
9608
9609 testCases = append(testCases, testCase{
9610 name: "SecondHelloRetryRequest",
9611 config: Config{
9612 MaxVersion: VersionTLS13,
9613 // P-384 requires HelloRetryRequest in BoringSSL.
9614 CurvePreferences: []CurveID{CurveP384},
9615 Bugs: ProtocolBugs{
9616 SecondHelloRetryRequest: true,
9617 },
9618 },
9619 shouldFail: true,
9620 expectedError: ":UNEXPECTED_MESSAGE:",
9621 })
9622
9623 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009624 name: "HelloRetryRequest-Empty",
9625 config: Config{
9626 MaxVersion: VersionTLS13,
9627 Bugs: ProtocolBugs{
9628 AlwaysSendHelloRetryRequest: true,
9629 },
9630 },
9631 shouldFail: true,
9632 expectedError: ":DECODE_ERROR:",
9633 })
9634
9635 testCases = append(testCases, testCase{
9636 name: "HelloRetryRequest-DuplicateCurve",
9637 config: Config{
9638 MaxVersion: VersionTLS13,
9639 // P-384 requires a HelloRetryRequest against BoringSSL's default
9640 // configuration. Assert this ExpectMissingKeyShare.
9641 CurvePreferences: []CurveID{CurveP384},
9642 Bugs: ProtocolBugs{
9643 ExpectMissingKeyShare: true,
9644 DuplicateHelloRetryRequestExtensions: true,
9645 },
9646 },
9647 shouldFail: true,
9648 expectedError: ":DUPLICATE_EXTENSION:",
9649 expectedLocalError: "remote error: illegal parameter",
9650 })
9651
9652 testCases = append(testCases, testCase{
9653 name: "HelloRetryRequest-Cookie",
9654 config: Config{
9655 MaxVersion: VersionTLS13,
9656 Bugs: ProtocolBugs{
9657 SendHelloRetryRequestCookie: []byte("cookie"),
9658 },
9659 },
9660 })
9661
9662 testCases = append(testCases, testCase{
9663 name: "HelloRetryRequest-DuplicateCookie",
9664 config: Config{
9665 MaxVersion: VersionTLS13,
9666 Bugs: ProtocolBugs{
9667 SendHelloRetryRequestCookie: []byte("cookie"),
9668 DuplicateHelloRetryRequestExtensions: true,
9669 },
9670 },
9671 shouldFail: true,
9672 expectedError: ":DUPLICATE_EXTENSION:",
9673 expectedLocalError: "remote error: illegal parameter",
9674 })
9675
9676 testCases = append(testCases, testCase{
9677 name: "HelloRetryRequest-EmptyCookie",
9678 config: Config{
9679 MaxVersion: VersionTLS13,
9680 Bugs: ProtocolBugs{
9681 SendHelloRetryRequestCookie: []byte{},
9682 },
9683 },
9684 shouldFail: true,
9685 expectedError: ":DECODE_ERROR:",
9686 })
9687
9688 testCases = append(testCases, testCase{
9689 name: "HelloRetryRequest-Cookie-Curve",
9690 config: Config{
9691 MaxVersion: VersionTLS13,
9692 // P-384 requires HelloRetryRequest in BoringSSL.
9693 CurvePreferences: []CurveID{CurveP384},
9694 Bugs: ProtocolBugs{
9695 SendHelloRetryRequestCookie: []byte("cookie"),
9696 ExpectMissingKeyShare: true,
9697 },
9698 },
9699 })
9700
9701 testCases = append(testCases, testCase{
9702 name: "HelloRetryRequest-Unknown",
9703 config: Config{
9704 MaxVersion: VersionTLS13,
9705 Bugs: ProtocolBugs{
9706 CustomHelloRetryRequestExtension: "extension",
9707 },
9708 },
9709 shouldFail: true,
9710 expectedError: ":UNEXPECTED_EXTENSION:",
9711 expectedLocalError: "remote error: unsupported extension",
9712 })
9713
9714 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009715 testType: serverTest,
9716 name: "SecondClientHelloMissingKeyShare",
9717 config: Config{
9718 MaxVersion: VersionTLS13,
9719 DefaultCurves: []CurveID{},
9720 Bugs: ProtocolBugs{
9721 SecondClientHelloMissingKeyShare: true,
9722 },
9723 },
9724 shouldFail: true,
9725 expectedError: ":MISSING_KEY_SHARE:",
9726 })
9727
9728 testCases = append(testCases, testCase{
9729 testType: serverTest,
9730 name: "SecondClientHelloWrongCurve",
9731 config: Config{
9732 MaxVersion: VersionTLS13,
9733 DefaultCurves: []CurveID{},
9734 Bugs: ProtocolBugs{
9735 MisinterpretHelloRetryRequestCurve: CurveP521,
9736 },
9737 },
9738 shouldFail: true,
9739 expectedError: ":WRONG_CURVE:",
9740 })
9741
9742 testCases = append(testCases, testCase{
9743 name: "HelloRetryRequestVersionMismatch",
9744 config: Config{
9745 MaxVersion: VersionTLS13,
9746 // P-384 requires HelloRetryRequest in BoringSSL.
9747 CurvePreferences: []CurveID{CurveP384},
9748 Bugs: ProtocolBugs{
9749 SendServerHelloVersion: 0x0305,
9750 },
9751 },
9752 shouldFail: true,
9753 expectedError: ":WRONG_VERSION_NUMBER:",
9754 })
9755
9756 testCases = append(testCases, testCase{
9757 name: "HelloRetryRequestCurveMismatch",
9758 config: Config{
9759 MaxVersion: VersionTLS13,
9760 // P-384 requires HelloRetryRequest in BoringSSL.
9761 CurvePreferences: []CurveID{CurveP384},
9762 Bugs: ProtocolBugs{
9763 // Send P-384 (correct) in the HelloRetryRequest.
9764 SendHelloRetryRequestCurve: CurveP384,
9765 // But send P-256 in the ServerHello.
9766 SendCurve: CurveP256,
9767 },
9768 },
9769 shouldFail: true,
9770 expectedError: ":WRONG_CURVE:",
9771 })
9772
9773 // Test the server selecting a curve that requires a HelloRetryRequest
9774 // without sending it.
9775 testCases = append(testCases, testCase{
9776 name: "SkipHelloRetryRequest",
9777 config: Config{
9778 MaxVersion: VersionTLS13,
9779 // P-384 requires HelloRetryRequest in BoringSSL.
9780 CurvePreferences: []CurveID{CurveP384},
9781 Bugs: ProtocolBugs{
9782 SkipHelloRetryRequest: true,
9783 },
9784 },
9785 shouldFail: true,
9786 expectedError: ":WRONG_CURVE:",
9787 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009788
9789 testCases = append(testCases, testCase{
9790 name: "TLS13-RequestContextInHandshake",
9791 config: Config{
9792 MaxVersion: VersionTLS13,
9793 MinVersion: VersionTLS13,
9794 ClientAuth: RequireAnyClientCert,
9795 Bugs: ProtocolBugs{
9796 SendRequestContext: []byte("request context"),
9797 },
9798 },
9799 flags: []string{
9800 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9801 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9802 },
9803 shouldFail: true,
9804 expectedError: ":DECODE_ERROR:",
9805 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009806
9807 testCases = append(testCases, testCase{
9808 testType: serverTest,
9809 name: "TLS13-TrailingKeyShareData",
9810 config: Config{
9811 MaxVersion: VersionTLS13,
9812 Bugs: ProtocolBugs{
9813 TrailingKeyShareData: true,
9814 },
9815 },
9816 shouldFail: true,
9817 expectedError: ":DECODE_ERROR:",
9818 })
David Benjamin7f78df42016-10-05 22:33:19 -04009819
9820 testCases = append(testCases, testCase{
9821 name: "TLS13-AlwaysSelectPSKIdentity",
9822 config: Config{
9823 MaxVersion: VersionTLS13,
9824 Bugs: ProtocolBugs{
9825 AlwaysSelectPSKIdentity: true,
9826 },
9827 },
9828 shouldFail: true,
9829 expectedError: ":UNEXPECTED_EXTENSION:",
9830 })
9831
9832 testCases = append(testCases, testCase{
9833 name: "TLS13-InvalidPSKIdentity",
9834 config: Config{
9835 MaxVersion: VersionTLS13,
9836 Bugs: ProtocolBugs{
9837 SelectPSKIdentityOnResume: 1,
9838 },
9839 },
9840 resumeSession: true,
9841 shouldFail: true,
9842 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9843 })
David Benjamin1286bee2016-10-07 15:25:06 -04009844
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009845 testCases = append(testCases, testCase{
9846 testType: serverTest,
9847 name: "TLS13-ExtraPSKIdentity",
9848 config: Config{
9849 MaxVersion: VersionTLS13,
9850 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009851 ExtraPSKIdentity: true,
9852 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009853 },
9854 },
9855 resumeSession: true,
9856 })
9857
David Benjamin1286bee2016-10-07 15:25:06 -04009858 // Test that unknown NewSessionTicket extensions are tolerated.
9859 testCases = append(testCases, testCase{
9860 name: "TLS13-CustomTicketExtension",
9861 config: Config{
9862 MaxVersion: VersionTLS13,
9863 Bugs: ProtocolBugs{
9864 CustomTicketExtension: "1234",
9865 },
9866 },
9867 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009868}
9869
David Benjaminabbbee12016-10-31 19:20:42 -04009870func addTLS13CipherPreferenceTests() {
9871 // Test that client preference is honored if the shim has AES hardware
9872 // and ChaCha20-Poly1305 is preferred otherwise.
9873 testCases = append(testCases, testCase{
9874 testType: serverTest,
9875 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9876 config: Config{
9877 MaxVersion: VersionTLS13,
9878 CipherSuites: []uint16{
9879 TLS_CHACHA20_POLY1305_SHA256,
9880 TLS_AES_128_GCM_SHA256,
9881 },
9882 },
9883 flags: []string{
9884 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9885 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9886 },
9887 })
9888
9889 testCases = append(testCases, testCase{
9890 testType: serverTest,
9891 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9892 config: Config{
9893 MaxVersion: VersionTLS13,
9894 CipherSuites: []uint16{
9895 TLS_AES_128_GCM_SHA256,
9896 TLS_CHACHA20_POLY1305_SHA256,
9897 },
9898 },
9899 flags: []string{
9900 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9901 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9902 },
9903 })
9904
9905 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9906 // whether it has AES hardware.
9907 testCases = append(testCases, testCase{
9908 name: "TLS13-CipherPreference-Client",
9909 config: Config{
9910 MaxVersion: VersionTLS13,
9911 // Use the client cipher order. (This is the default but
9912 // is listed to be explicit.)
9913 PreferServerCipherSuites: false,
9914 },
9915 flags: []string{
9916 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9917 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9918 },
9919 })
9920}
9921
David Benjaminf3fbade2016-09-19 13:08:16 -04009922func addPeekTests() {
9923 // Test SSL_peek works, including on empty records.
9924 testCases = append(testCases, testCase{
9925 name: "Peek-Basic",
9926 sendEmptyRecords: 1,
9927 flags: []string{"-peek-then-read"},
9928 })
9929
9930 // Test SSL_peek can drive the initial handshake.
9931 testCases = append(testCases, testCase{
9932 name: "Peek-ImplicitHandshake",
9933 flags: []string{
9934 "-peek-then-read",
9935 "-implicit-handshake",
9936 },
9937 })
9938
9939 // Test SSL_peek can discover and drive a renegotiation.
9940 testCases = append(testCases, testCase{
9941 name: "Peek-Renegotiate",
9942 config: Config{
9943 MaxVersion: VersionTLS12,
9944 },
9945 renegotiate: 1,
9946 flags: []string{
9947 "-peek-then-read",
9948 "-renegotiate-freely",
9949 "-expect-total-renegotiations", "1",
9950 },
9951 })
9952
9953 // Test SSL_peek can discover a close_notify.
9954 testCases = append(testCases, testCase{
9955 name: "Peek-Shutdown",
9956 config: Config{
9957 Bugs: ProtocolBugs{
9958 ExpectCloseNotify: true,
9959 },
9960 },
9961 flags: []string{
9962 "-peek-then-read",
9963 "-check-close-notify",
9964 },
9965 })
9966
9967 // Test SSL_peek can discover an alert.
9968 testCases = append(testCases, testCase{
9969 name: "Peek-Alert",
9970 config: Config{
9971 Bugs: ProtocolBugs{
9972 SendSpuriousAlert: alertRecordOverflow,
9973 },
9974 },
9975 flags: []string{"-peek-then-read"},
9976 shouldFail: true,
9977 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9978 })
9979
9980 // Test SSL_peek can handle KeyUpdate.
9981 testCases = append(testCases, testCase{
9982 name: "Peek-KeyUpdate",
9983 config: Config{
9984 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009985 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009986 sendKeyUpdates: 1,
9987 keyUpdateRequest: keyUpdateNotRequested,
9988 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009989 })
9990}
9991
David Benjamine6f22212016-11-08 14:28:24 -05009992func addRecordVersionTests() {
9993 for _, ver := range tlsVersions {
9994 // Test that the record version is enforced.
9995 testCases = append(testCases, testCase{
9996 name: "CheckRecordVersion-" + ver.name,
9997 config: Config{
9998 MinVersion: ver.version,
9999 MaxVersion: ver.version,
10000 Bugs: ProtocolBugs{
10001 SendRecordVersion: 0x03ff,
10002 },
10003 },
10004 shouldFail: true,
10005 expectedError: ":WRONG_VERSION_NUMBER:",
10006 })
10007
10008 // Test that the ClientHello may use any record version, for
10009 // compatibility reasons.
10010 testCases = append(testCases, testCase{
10011 testType: serverTest,
10012 name: "LooseInitialRecordVersion-" + ver.name,
10013 config: Config{
10014 MinVersion: ver.version,
10015 MaxVersion: ver.version,
10016 Bugs: ProtocolBugs{
10017 SendInitialRecordVersion: 0x03ff,
10018 },
10019 },
10020 })
10021
10022 // Test that garbage ClientHello record versions are rejected.
10023 testCases = append(testCases, testCase{
10024 testType: serverTest,
10025 name: "GarbageInitialRecordVersion-" + ver.name,
10026 config: Config{
10027 MinVersion: ver.version,
10028 MaxVersion: ver.version,
10029 Bugs: ProtocolBugs{
10030 SendInitialRecordVersion: 0xffff,
10031 },
10032 },
10033 shouldFail: true,
10034 expectedError: ":WRONG_VERSION_NUMBER:",
10035 })
10036 }
10037}
10038
David Benjamin2c516452016-11-15 10:16:54 +090010039func addCertificateTests() {
10040 // Test that a certificate chain with intermediate may be sent and
10041 // received as both client and server.
10042 for _, ver := range tlsVersions {
10043 testCases = append(testCases, testCase{
10044 testType: clientTest,
10045 name: "SendReceiveIntermediate-Client-" + ver.name,
10046 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080010047 MinVersion: ver.version,
10048 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090010049 Certificates: []Certificate{rsaChainCertificate},
10050 ClientAuth: RequireAnyClientCert,
10051 },
10052 expectPeerCertificate: &rsaChainCertificate,
10053 flags: []string{
10054 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10055 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
10056 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10057 },
10058 })
10059
10060 testCases = append(testCases, testCase{
10061 testType: serverTest,
10062 name: "SendReceiveIntermediate-Server-" + ver.name,
10063 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080010064 MinVersion: ver.version,
10065 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090010066 Certificates: []Certificate{rsaChainCertificate},
10067 },
10068 expectPeerCertificate: &rsaChainCertificate,
10069 flags: []string{
10070 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10071 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
10072 "-require-any-client-certificate",
10073 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10074 },
10075 })
10076 }
10077}
10078
David Benjaminbbaf3672016-11-17 10:53:09 +090010079func addRetainOnlySHA256ClientCertTests() {
10080 for _, ver := range tlsVersions {
10081 // Test that enabling
10082 // SSL_CTX_set_retain_only_sha256_of_client_certs without
10083 // actually requesting a client certificate is a no-op.
10084 testCases = append(testCases, testCase{
10085 testType: serverTest,
10086 name: "RetainOnlySHA256-NoCert-" + ver.name,
10087 config: Config{
10088 MinVersion: ver.version,
10089 MaxVersion: ver.version,
10090 },
10091 flags: []string{
10092 "-retain-only-sha256-client-cert-initial",
10093 "-retain-only-sha256-client-cert-resume",
10094 },
10095 resumeSession: true,
10096 })
10097
10098 // Test that when retaining only a SHA-256 certificate is
10099 // enabled, the hash appears as expected.
10100 testCases = append(testCases, testCase{
10101 testType: serverTest,
10102 name: "RetainOnlySHA256-Cert-" + ver.name,
10103 config: Config{
10104 MinVersion: ver.version,
10105 MaxVersion: ver.version,
10106 Certificates: []Certificate{rsaCertificate},
10107 },
10108 flags: []string{
10109 "-verify-peer",
10110 "-retain-only-sha256-client-cert-initial",
10111 "-retain-only-sha256-client-cert-resume",
10112 "-expect-sha256-client-cert-initial",
10113 "-expect-sha256-client-cert-resume",
10114 },
10115 resumeSession: true,
10116 })
10117
10118 // Test that when the config changes from on to off, a
10119 // resumption is rejected because the server now wants the full
10120 // certificate chain.
10121 testCases = append(testCases, testCase{
10122 testType: serverTest,
10123 name: "RetainOnlySHA256-OnOff-" + ver.name,
10124 config: Config{
10125 MinVersion: ver.version,
10126 MaxVersion: ver.version,
10127 Certificates: []Certificate{rsaCertificate},
10128 },
10129 flags: []string{
10130 "-verify-peer",
10131 "-retain-only-sha256-client-cert-initial",
10132 "-expect-sha256-client-cert-initial",
10133 },
10134 resumeSession: true,
10135 expectResumeRejected: true,
10136 })
10137
10138 // Test that when the config changes from off to on, a
10139 // resumption is rejected because the server now wants just the
10140 // hash.
10141 testCases = append(testCases, testCase{
10142 testType: serverTest,
10143 name: "RetainOnlySHA256-OffOn-" + ver.name,
10144 config: Config{
10145 MinVersion: ver.version,
10146 MaxVersion: ver.version,
10147 Certificates: []Certificate{rsaCertificate},
10148 },
10149 flags: []string{
10150 "-verify-peer",
10151 "-retain-only-sha256-client-cert-resume",
10152 "-expect-sha256-client-cert-resume",
10153 },
10154 resumeSession: true,
10155 expectResumeRejected: true,
10156 })
10157 }
10158}
10159
Adam Langleya4b91982016-12-12 12:05:53 -080010160func addECDSAKeyUsageTests() {
10161 p256 := elliptic.P256()
10162 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10163 if err != nil {
10164 panic(err)
10165 }
10166
10167 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10168 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10169 if err != nil {
10170 panic(err)
10171 }
10172
10173 template := x509.Certificate{
10174 SerialNumber: serialNumber,
10175 Subject: pkix.Name{
10176 Organization: []string{"Acme Co"},
10177 },
10178 NotBefore: time.Now(),
10179 NotAfter: time.Now(),
10180
10181 // An ECC certificate with only the keyAgreement key usgae may
10182 // be used with ECDH, but not ECDSA.
10183 KeyUsage: x509.KeyUsageKeyAgreement,
10184 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10185 BasicConstraintsValid: true,
10186 }
10187
10188 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10189 if err != nil {
10190 panic(err)
10191 }
10192
10193 cert := Certificate{
10194 Certificate: [][]byte{derBytes},
10195 PrivateKey: priv,
10196 }
10197
10198 for _, ver := range tlsVersions {
10199 if ver.version < VersionTLS12 {
10200 continue
10201 }
10202
10203 testCases = append(testCases, testCase{
10204 testType: clientTest,
10205 name: "ECDSAKeyUsage-" + ver.name,
10206 config: Config{
10207 MinVersion: ver.version,
10208 MaxVersion: ver.version,
10209 Certificates: []Certificate{cert},
10210 },
10211 shouldFail: true,
10212 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10213 })
10214 }
10215}
10216
David Benjamin6f600d62016-12-21 16:06:54 -050010217func addShortHeaderTests() {
10218 // The short header extension may be negotiated as either client or
10219 // server.
10220 testCases = append(testCases, testCase{
10221 name: "ShortHeader-Client",
10222 config: Config{
10223 MaxVersion: VersionTLS13,
10224 Bugs: ProtocolBugs{
10225 EnableShortHeader: true,
10226 },
10227 },
10228 flags: []string{"-enable-short-header"},
10229 expectShortHeader: true,
10230 })
10231 testCases = append(testCases, testCase{
10232 testType: serverTest,
10233 name: "ShortHeader-Server",
10234 config: Config{
10235 MaxVersion: VersionTLS13,
10236 Bugs: ProtocolBugs{
10237 EnableShortHeader: true,
10238 },
10239 },
10240 flags: []string{"-enable-short-header"},
10241 expectShortHeader: true,
10242 })
10243
10244 // If the peer doesn't support it, it will not be negotiated.
10245 testCases = append(testCases, testCase{
10246 name: "ShortHeader-No-Yes-Client",
10247 config: Config{
10248 MaxVersion: VersionTLS13,
10249 },
10250 flags: []string{"-enable-short-header"},
10251 })
10252 testCases = append(testCases, testCase{
10253 testType: serverTest,
10254 name: "ShortHeader-No-Yes-Server",
10255 config: Config{
10256 MaxVersion: VersionTLS13,
10257 },
10258 flags: []string{"-enable-short-header"},
10259 })
10260
10261 // If we don't support it, it will not be negotiated.
10262 testCases = append(testCases, testCase{
10263 name: "ShortHeader-Yes-No-Client",
10264 config: Config{
10265 MaxVersion: VersionTLS13,
10266 Bugs: ProtocolBugs{
10267 EnableShortHeader: true,
10268 },
10269 },
10270 })
10271 testCases = append(testCases, testCase{
10272 testType: serverTest,
10273 name: "ShortHeader-Yes-No-Server",
10274 config: Config{
10275 MaxVersion: VersionTLS13,
10276 Bugs: ProtocolBugs{
10277 EnableShortHeader: true,
10278 },
10279 },
10280 })
10281
10282 // It will not be negotiated at TLS 1.2.
10283 testCases = append(testCases, testCase{
10284 name: "ShortHeader-TLS12-Client",
10285 config: Config{
10286 MaxVersion: VersionTLS12,
10287 Bugs: ProtocolBugs{
10288 EnableShortHeader: true,
10289 },
10290 },
10291 flags: []string{"-enable-short-header"},
10292 })
10293 testCases = append(testCases, testCase{
10294 testType: serverTest,
10295 name: "ShortHeader-TLS12-Server",
10296 config: Config{
10297 MaxVersion: VersionTLS12,
10298 Bugs: ProtocolBugs{
10299 EnableShortHeader: true,
10300 },
10301 },
10302 flags: []string{"-enable-short-header"},
10303 })
10304
10305 // Servers reject early data and short header sent together.
10306 testCases = append(testCases, testCase{
10307 testType: serverTest,
10308 name: "ShortHeader-EarlyData",
10309 config: Config{
10310 MaxVersion: VersionTLS13,
10311 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010312 EnableShortHeader: true,
10313 SendFakeEarlyDataLength: 1,
David Benjamin6f600d62016-12-21 16:06:54 -050010314 },
10315 },
10316 flags: []string{"-enable-short-header"},
10317 shouldFail: true,
10318 expectedError: ":UNEXPECTED_EXTENSION:",
10319 })
10320
10321 // Clients reject unsolicited short header extensions.
10322 testCases = append(testCases, testCase{
10323 name: "ShortHeader-Unsolicited",
10324 config: Config{
10325 MaxVersion: VersionTLS13,
10326 Bugs: ProtocolBugs{
10327 AlwaysNegotiateShortHeader: true,
10328 },
10329 },
10330 shouldFail: true,
10331 expectedError: ":UNEXPECTED_EXTENSION:",
10332 })
10333 testCases = append(testCases, testCase{
10334 name: "ShortHeader-Unsolicited-TLS12",
10335 config: Config{
10336 MaxVersion: VersionTLS12,
10337 Bugs: ProtocolBugs{
10338 AlwaysNegotiateShortHeader: true,
10339 },
10340 },
10341 shouldFail: true,
10342 expectedError: ":UNEXPECTED_EXTENSION:",
10343 })
10344
10345 // The high bit must be checked in short headers.
10346 testCases = append(testCases, testCase{
10347 name: "ShortHeader-ClearShortHeaderBit",
10348 config: Config{
10349 Bugs: ProtocolBugs{
10350 EnableShortHeader: true,
10351 ClearShortHeaderBit: true,
10352 },
10353 },
10354 flags: []string{"-enable-short-header"},
10355 shouldFail: true,
10356 expectedError: ":DECODE_ERROR:",
10357 expectedLocalError: "remote error: error decoding message",
10358 })
10359}
10360
Adam Langley7c803a62015-06-15 15:35:05 -070010361func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010362 defer wg.Done()
10363
10364 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010365 var err error
10366
David Benjaminba28dfc2016-11-15 17:47:21 +090010367 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010368 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10369 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010370 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010371 if err != nil {
10372 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10373 }
10374 break
10375 }
10376 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010377 } else if *repeatUntilFailure {
10378 for err == nil {
10379 statusChan <- statusMsg{test: test, started: true}
10380 err = runTest(test, shimPath, -1)
10381 }
10382 } else {
10383 statusChan <- statusMsg{test: test, started: true}
10384 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010385 }
Adam Langley95c29f32014-06-20 12:00:00 -070010386 statusChan <- statusMsg{test: test, err: err}
10387 }
10388}
10389
10390type statusMsg struct {
10391 test *testCase
10392 started bool
10393 err error
10394}
10395
David Benjamin5f237bc2015-02-11 17:14:15 -050010396func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010397 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010398
David Benjamin5f237bc2015-02-11 17:14:15 -050010399 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010400 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010401 if !*pipe {
10402 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010403 var erase string
10404 for i := 0; i < lineLen; i++ {
10405 erase += "\b \b"
10406 }
10407 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010408 }
10409
Adam Langley95c29f32014-06-20 12:00:00 -070010410 if msg.started {
10411 started++
10412 } else {
10413 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010414
10415 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010416 if msg.err == errUnimplemented {
10417 if *pipe {
10418 // Print each test instead of a status line.
10419 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10420 }
10421 unimplemented++
10422 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10423 } else {
10424 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10425 failed++
10426 testOutput.addResult(msg.test.name, "FAIL")
10427 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010428 } else {
10429 if *pipe {
10430 // Print each test instead of a status line.
10431 fmt.Printf("PASSED (%s)\n", msg.test.name)
10432 }
10433 testOutput.addResult(msg.test.name, "PASS")
10434 }
Adam Langley95c29f32014-06-20 12:00:00 -070010435 }
10436
David Benjamin5f237bc2015-02-11 17:14:15 -050010437 if !*pipe {
10438 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010439 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010440 lineLen = len(line)
10441 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010442 }
Adam Langley95c29f32014-06-20 12:00:00 -070010443 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010444
10445 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010446}
10447
10448func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010449 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010450 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010451 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010452
Adam Langley7c803a62015-06-15 15:35:05 -070010453 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010454 addCipherSuiteTests()
10455 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010456 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010457 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010458 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010459 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010460 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010461 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010462 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010463 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010464 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010465 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010466 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010467 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010468 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010469 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010470 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010471 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010472 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010473 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010474 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010475 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010476 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010477 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010478 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010479 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010480 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010481 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010482 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010483 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010484 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010485 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010486 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010487 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010488
10489 var wg sync.WaitGroup
10490
Adam Langley7c803a62015-06-15 15:35:05 -070010491 statusChan := make(chan statusMsg, *numWorkers)
10492 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010493 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010494
EKRf71d7ed2016-08-06 13:25:12 -070010495 if len(*shimConfigFile) != 0 {
10496 encoded, err := ioutil.ReadFile(*shimConfigFile)
10497 if err != nil {
10498 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10499 os.Exit(1)
10500 }
10501
10502 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10503 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10504 os.Exit(1)
10505 }
10506 }
10507
David Benjamin025b3d32014-07-01 19:53:04 -040010508 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010509
Adam Langley7c803a62015-06-15 15:35:05 -070010510 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010511 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010512 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010513 }
10514
David Benjamin270f0a72016-03-17 14:41:36 -040010515 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010516 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010517 matched := true
10518 if len(*testToRun) != 0 {
10519 var err error
10520 matched, err = filepath.Match(*testToRun, testCases[i].name)
10521 if err != nil {
10522 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10523 os.Exit(1)
10524 }
10525 }
10526
EKRf71d7ed2016-08-06 13:25:12 -070010527 if !*includeDisabled {
10528 for pattern := range shimConfig.DisabledTests {
10529 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10530 if err != nil {
10531 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10532 os.Exit(1)
10533 }
10534
10535 if isDisabled {
10536 matched = false
10537 break
10538 }
10539 }
10540 }
10541
David Benjamin17e12922016-07-28 18:04:43 -040010542 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010543 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010544 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010545
10546 // Only run one test if repeating until failure.
10547 if *repeatUntilFailure {
10548 break
10549 }
Adam Langley95c29f32014-06-20 12:00:00 -070010550 }
10551 }
David Benjamin17e12922016-07-28 18:04:43 -040010552
David Benjamin270f0a72016-03-17 14:41:36 -040010553 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010554 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010555 os.Exit(1)
10556 }
Adam Langley95c29f32014-06-20 12:00:00 -070010557
10558 close(testChan)
10559 wg.Wait()
10560 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010561 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010562
10563 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010564
10565 if *jsonOutput != "" {
10566 if err := testOutput.writeTo(*jsonOutput); err != nil {
10567 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10568 }
10569 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010570
EKR842ae6c2016-07-27 09:22:05 +020010571 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10572 os.Exit(1)
10573 }
10574
10575 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010576 os.Exit(1)
10577 }
Adam Langley95c29f32014-06-20 12:00:00 -070010578}