blob: 563d4b24b1f91d7625b689e86236d02203a22366 [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.")
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -070068 includeDHE = flag.Bool("include-dhe", false, "If true, test DHE ciphersuites.")
David Benjaminba28dfc2016-11-15 17:47:21 +090069 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 -080070)
Adam Langley95c29f32014-06-20 12:00:00 -070071
EKRf71d7ed2016-08-06 13:25:12 -070072// ShimConfigurations is used with the “json” package and represents a shim
73// config file.
74type ShimConfiguration struct {
75 // DisabledTests maps from a glob-based pattern to a freeform string.
76 // The glob pattern is used to exclude tests from being run and the
77 // freeform string is unparsed but expected to explain why the test is
78 // disabled.
79 DisabledTests map[string]string
80
81 // ErrorMap maps from expected error strings to the correct error
82 // string for the shim in question. For example, it might map
83 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
84 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
85 ErrorMap map[string]string
86}
87
88var shimConfig ShimConfiguration
89
David Benjamin33863262016-07-08 17:20:12 -070090type testCert int
91
David Benjamin025b3d32014-07-01 19:53:04 -040092const (
David Benjamin33863262016-07-08 17:20:12 -070093 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040094 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090095 testCertRSAChain
Adam Langley898be922017-02-27 12:37:59 -080096 testCertECDSAP224
David Benjamin33863262016-07-08 17:20:12 -070097 testCertECDSAP256
98 testCertECDSAP384
99 testCertECDSAP521
100)
101
102const (
103 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400104 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900105 rsaChainCertificateFile = "rsa_chain_cert.pem"
Adam Langley898be922017-02-27 12:37:59 -0800106 ecdsaP224CertificateFile = "ecdsa_p224_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700107 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
108 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
109 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
112const (
David Benjamina08e49d2014-08-24 01:46:07 -0400113 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400114 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900115 rsaChainKeyFile = "rsa_chain_key.pem"
Adam Langley898be922017-02-27 12:37:59 -0800116 ecdsaP224KeyFile = "ecdsa_p224_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700117 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
118 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
119 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400120 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400121)
122
David Benjamin7944a9f2016-07-12 22:27:01 -0400123var (
124 rsaCertificate Certificate
125 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900126 rsaChainCertificate Certificate
Adam Langley898be922017-02-27 12:37:59 -0800127 ecdsaP224Certificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400128 ecdsaP256Certificate Certificate
129 ecdsaP384Certificate Certificate
130 ecdsaP521Certificate Certificate
131)
David Benjamin33863262016-07-08 17:20:12 -0700132
133var testCerts = []struct {
134 id testCert
135 certFile, keyFile string
136 cert *Certificate
137}{
138 {
139 id: testCertRSA,
140 certFile: rsaCertificateFile,
141 keyFile: rsaKeyFile,
142 cert: &rsaCertificate,
143 },
144 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400145 id: testCertRSA1024,
146 certFile: rsa1024CertificateFile,
147 keyFile: rsa1024KeyFile,
148 cert: &rsa1024Certificate,
149 },
150 {
David Benjamin2c516452016-11-15 10:16:54 +0900151 id: testCertRSAChain,
152 certFile: rsaChainCertificateFile,
153 keyFile: rsaChainKeyFile,
154 cert: &rsaChainCertificate,
155 },
156 {
Adam Langley898be922017-02-27 12:37:59 -0800157 id: testCertECDSAP224,
158 certFile: ecdsaP224CertificateFile,
159 keyFile: ecdsaP224KeyFile,
160 cert: &ecdsaP224Certificate,
161 },
162 {
David Benjamin33863262016-07-08 17:20:12 -0700163 id: testCertECDSAP256,
164 certFile: ecdsaP256CertificateFile,
165 keyFile: ecdsaP256KeyFile,
166 cert: &ecdsaP256Certificate,
167 },
168 {
169 id: testCertECDSAP384,
170 certFile: ecdsaP384CertificateFile,
171 keyFile: ecdsaP384KeyFile,
172 cert: &ecdsaP384Certificate,
173 },
174 {
175 id: testCertECDSAP521,
176 certFile: ecdsaP521CertificateFile,
177 keyFile: ecdsaP521KeyFile,
178 cert: &ecdsaP521Certificate,
179 },
180}
181
David Benjamina08e49d2014-08-24 01:46:07 -0400182var channelIDKey *ecdsa.PrivateKey
183var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700184
David Benjamin61f95272014-11-25 01:55:35 -0500185var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800186var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500187
Steven Valdeza833c352016-11-01 13:39:36 -0400188var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800189var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400190
Adam Langley95c29f32014-06-20 12:00:00 -0700191func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700192 for i := range testCerts {
193 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
194 if err != nil {
195 panic(err)
196 }
197 cert.OCSPStaple = testOCSPResponse
198 cert.SignedCertificateTimestampList = testSCTList
199 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700200 }
David Benjamina08e49d2014-08-24 01:46:07 -0400201
Adam Langley7c803a62015-06-15 15:35:05 -0700202 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400203 if err != nil {
204 panic(err)
205 }
206 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
207 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
208 panic("bad key type")
209 }
210 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
211 if err != nil {
212 panic(err)
213 }
214 if channelIDKey.Curve != elliptic.P256() {
215 panic("bad curve")
216 }
217
218 channelIDBytes = make([]byte, 64)
219 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
220 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700221}
222
David Benjamin33863262016-07-08 17:20:12 -0700223func getRunnerCertificate(t testCert) Certificate {
224 for _, cert := range testCerts {
225 if cert.id == t {
226 return *cert.cert
227 }
228 }
229 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700230}
231
David Benjamin33863262016-07-08 17:20:12 -0700232func getShimCertificate(t testCert) string {
233 for _, cert := range testCerts {
234 if cert.id == t {
235 return cert.certFile
236 }
237 }
238 panic("Unknown test certificate")
239}
240
241func getShimKey(t testCert) string {
242 for _, cert := range testCerts {
243 if cert.id == t {
244 return cert.keyFile
245 }
246 }
247 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700248}
249
Adam Langley2ff79332017-02-28 13:45:39 -0800250// encodeDERValues encodes a series of bytestrings in comma-separated-hex form.
251func encodeDERValues(values [][]byte) string {
252 var ret string
253 for i, v := range values {
254 if i > 0 {
255 ret += ","
256 }
257 ret += hex.EncodeToString(v)
258 }
259
260 return ret
261}
262
David Benjamin025b3d32014-07-01 19:53:04 -0400263type testType int
264
265const (
266 clientTest testType = iota
267 serverTest
268)
269
David Benjamin6fd297b2014-08-11 18:43:38 -0400270type protocol int
271
272const (
273 tls protocol = iota
274 dtls
275)
276
David Benjaminfc7b0862014-09-06 13:21:53 -0400277const (
278 alpn = 1
279 npn = 2
280)
281
Adam Langley95c29f32014-06-20 12:00:00 -0700282type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400283 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400284 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700285 name string
286 config Config
287 shouldFail bool
288 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700289 // expectedLocalError, if not empty, contains a substring that must be
290 // found in the local error.
291 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400292 // expectedVersion, if non-zero, specifies the TLS version that must be
293 // negotiated.
294 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // expectedResumeVersion, if non-zero, specifies the TLS version that
296 // must be negotiated on resumption. If zero, expectedVersion is used.
297 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400298 // expectedCipher, if non-zero, specifies the TLS cipher suite that
299 // should be negotiated.
300 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400301 // expectChannelID controls whether the connection should have
302 // negotiated a Channel ID with channelIDKey.
303 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400304 // expectedNextProto controls whether the connection should
305 // negotiate a next protocol via NPN or ALPN.
306 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400307 // expectNoNextProto, if true, means that no next protocol should be
308 // negotiated.
309 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400310 // expectedNextProtoType, if non-zero, is the expected next
311 // protocol negotiation mechanism.
312 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500313 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
314 // should be negotiated. If zero, none should be negotiated.
315 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100316 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
317 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100318 // expectedSCTList, if not nil, is the expected SCT list to be received.
319 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700320 // expectedPeerSignatureAlgorithm, if not zero, is the signature
321 // algorithm that the peer should have used in the handshake.
322 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400323 // expectedCurveID, if not zero, is the curve that the handshake should
324 // have used.
325 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700326 // messageLen is the length, in bytes, of the test message that will be
327 // sent.
328 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400329 // messageCount is the number of test messages that will be sent.
330 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400331 // certFile is the path to the certificate to use for the server.
332 certFile string
333 // keyFile is the path to the private key to use for the server.
334 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400335 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400336 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400337 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400338 // resumeRenewedSession controls whether a third connection should be
339 // tested which attempts to resume the second connection's session.
340 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700341 // expectResumeRejected, if true, specifies that the attempted
342 // resumption must be rejected by the client. This is only valid for a
343 // serverTest.
344 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400345 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500346 // resumption. Unless newSessionsOnResume is set,
347 // SessionTicketKey, ServerSessionCache, and
348 // ClientSessionCache are copied from the initial connection's
349 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400350 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500351 // newSessionsOnResume, if true, will cause resumeConfig to
352 // use a different session resumption context.
353 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400354 // noSessionCache, if true, will cause the server to run without a
355 // session cache.
356 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400357 // sendPrefix sends a prefix on the socket before actually performing a
358 // handshake.
359 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400360 // shimWritesFirst controls whether the shim sends an initial "hello"
361 // message before doing a roundtrip with the runner.
362 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400363 // shimShutsDown, if true, runs a test where the shim shuts down the
364 // connection immediately after the handshake rather than echoing
365 // messages from the runner.
366 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400367 // renegotiate indicates the number of times the connection should be
368 // renegotiated during the exchange.
369 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400370 // sendHalfHelloRequest, if true, causes the server to send half a
371 // HelloRequest when the handshake completes.
372 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700373 // renegotiateCiphers is a list of ciphersuite ids that will be
374 // switched in just before renegotiation.
375 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500376 // replayWrites, if true, configures the underlying transport
377 // to replay every write it makes in DTLS tests.
378 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500379 // damageFirstWrite, if true, configures the underlying transport to
380 // damage the final byte of the first application data write.
381 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400382 // exportKeyingMaterial, if non-zero, configures the test to exchange
383 // keying material and verify they match.
384 exportKeyingMaterial int
385 exportLabel string
386 exportContext string
387 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400388 // flags, if not empty, contains a list of command-line flags that will
389 // be passed to the shim program.
390 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700391 // testTLSUnique, if true, causes the shim to send the tls-unique value
392 // which will be compared against the expected value.
393 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400394 // sendEmptyRecords is the number of consecutive empty records to send
395 // before and after the test message.
396 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400397 // sendWarningAlerts is the number of consecutive warning alerts to send
398 // before and after the test message.
399 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400400 // sendKeyUpdates is the number of consecutive key updates to send
401 // before and after the test message.
402 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400403 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
404 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400405 // expectMessageDropped, if true, means the test message is expected to
406 // be dropped by the client rather than echoed back.
407 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900408 // expectPeerCertificate, if not nil, is the certificate chain the peer
409 // is expected to send.
410 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700411}
412
Adam Langley7c803a62015-06-15 15:35:05 -0700413var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700414
David Benjaminc07afb72016-09-22 10:18:58 -0400415func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500416 if len(data) == 0 {
417 return
418 }
419
420 protocol := "tls"
421 if test.protocol == dtls {
422 protocol = "dtls"
423 }
424
425 side := "client"
426 if test.testType == serverTest {
427 side = "server"
428 }
429
430 dir := path.Join(*transcriptDir, protocol, side)
431 if err := os.MkdirAll(dir, 0755); err != nil {
432 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
433 return
434 }
435
David Benjaminc07afb72016-09-22 10:18:58 -0400436 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500437 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
438 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
439 }
440}
441
David Benjamin3ed59772016-03-08 12:50:21 -0500442// A timeoutConn implements an idle timeout on each Read and Write operation.
443type timeoutConn struct {
444 net.Conn
445 timeout time.Duration
446}
447
448func (t *timeoutConn) Read(b []byte) (int, error) {
449 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
450 return 0, err
451 }
452 return t.Conn.Read(b)
453}
454
455func (t *timeoutConn) Write(b []byte) (int, error) {
456 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
457 return 0, err
458 }
459 return t.Conn.Write(b)
460}
461
David Benjaminc07afb72016-09-22 10:18:58 -0400462func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400463 if !test.noSessionCache {
464 if config.ClientSessionCache == nil {
465 config.ClientSessionCache = NewLRUClientSessionCache(1)
466 }
467 if config.ServerSessionCache == nil {
468 config.ServerSessionCache = NewLRUServerSessionCache(1)
469 }
470 }
471 if test.testType == clientTest {
472 if len(config.Certificates) == 0 {
473 config.Certificates = []Certificate{rsaCertificate}
474 }
475 } else {
476 // Supply a ServerName to ensure a constant session cache key,
477 // rather than falling back to net.Conn.RemoteAddr.
478 if len(config.ServerName) == 0 {
479 config.ServerName = "test"
480 }
481 }
482 if *fuzzer {
483 config.Bugs.NullAllCiphers = true
484 }
David Benjamin01a90572016-09-22 00:11:43 -0400485 if *deterministic {
486 config.Time = func() time.Time { return time.Unix(1234, 1234) }
487 }
David Benjamine54af062016-08-08 19:21:18 -0400488
David Benjamin01784b42016-06-07 18:00:52 -0400489 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500490
David Benjamin6fd297b2014-08-11 18:43:38 -0400491 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500492 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
493 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500494 }
495
David Benjamin9867b7d2016-03-01 23:25:48 -0500496 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500497 local, peer := "client", "server"
498 if test.testType == clientTest {
499 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500500 }
David Benjaminebda9b32015-11-02 15:33:18 -0500501 connDebug := &recordingConn{
502 Conn: conn,
503 isDatagram: test.protocol == dtls,
504 local: local,
505 peer: peer,
506 }
507 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500508 if *flagDebug {
509 defer connDebug.WriteTo(os.Stdout)
510 }
511 if len(*transcriptDir) != 0 {
512 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400513 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500514 }()
515 }
David Benjaminebda9b32015-11-02 15:33:18 -0500516
517 if config.Bugs.PacketAdaptor != nil {
518 config.Bugs.PacketAdaptor.debug = connDebug
519 }
520 }
521
522 if test.replayWrites {
523 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400524 }
525
David Benjamin3ed59772016-03-08 12:50:21 -0500526 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500527 if test.damageFirstWrite {
528 connDamage = newDamageAdaptor(conn)
529 conn = connDamage
530 }
531
David Benjamin6fd297b2014-08-11 18:43:38 -0400532 if test.sendPrefix != "" {
533 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
534 return err
535 }
David Benjamin98e882e2014-08-08 13:24:34 -0400536 }
537
David Benjamin1d5c83e2014-07-22 19:20:02 -0400538 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400539 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400540 if test.protocol == dtls {
541 tlsConn = DTLSServer(conn, config)
542 } else {
543 tlsConn = Server(conn, config)
544 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400545 } else {
546 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400547 if test.protocol == dtls {
548 tlsConn = DTLSClient(conn, config)
549 } else {
550 tlsConn = Client(conn, config)
551 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400552 }
David Benjamin30789da2015-08-29 22:56:45 -0400553 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400554
Adam Langley95c29f32014-06-20 12:00:00 -0700555 if err := tlsConn.Handshake(); err != nil {
556 return err
557 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700558
David Benjamin01fe8202014-09-24 15:21:44 -0400559 // TODO(davidben): move all per-connection expectations into a dedicated
560 // expectations struct that can be specified separately for the two
561 // legs.
562 expectedVersion := test.expectedVersion
563 if isResume && test.expectedResumeVersion != 0 {
564 expectedVersion = test.expectedResumeVersion
565 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700566 connState := tlsConn.ConnectionState()
567 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400568 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400569 }
570
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700571 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400572 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
573 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700574 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
575 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
576 }
David Benjamin90da8c82015-04-20 14:57:57 -0400577
David Benjamina08e49d2014-08-24 01:46:07 -0400578 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700579 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400580 if channelID == nil {
581 return fmt.Errorf("no channel ID negotiated")
582 }
583 if channelID.Curve != channelIDKey.Curve ||
584 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
585 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
586 return fmt.Errorf("incorrect channel ID")
587 }
588 }
589
David Benjaminae2888f2014-09-06 12:58:58 -0400590 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700591 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400592 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
593 }
594 }
595
David Benjaminc7ce9772015-10-09 19:32:41 -0400596 if test.expectNoNextProto {
597 if actual := connState.NegotiatedProtocol; actual != "" {
598 return fmt.Errorf("got unexpected next proto %s", actual)
599 }
600 }
601
David Benjaminfc7b0862014-09-06 13:21:53 -0400602 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700603 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400604 return fmt.Errorf("next proto type mismatch")
605 }
606 }
607
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700608 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500609 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
610 }
611
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100612 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300613 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100614 }
615
Paul Lietar4fac72e2015-09-09 13:44:55 +0100616 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
617 return fmt.Errorf("SCT list mismatch")
618 }
619
Nick Harper60edffd2016-06-21 15:19:24 -0700620 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
621 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400622 }
623
Steven Valdez5440fe02016-07-18 12:40:30 -0400624 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
625 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
626 }
627
David Benjamin2c516452016-11-15 10:16:54 +0900628 if test.expectPeerCertificate != nil {
629 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
630 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
631 }
632 for i, cert := range connState.PeerCertificates {
633 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
634 return fmt.Errorf("peer certificate %d did not match", i+1)
635 }
636 }
637 }
638
David Benjaminc565ebb2015-04-03 04:06:36 -0400639 if test.exportKeyingMaterial > 0 {
640 actual := make([]byte, test.exportKeyingMaterial)
641 if _, err := io.ReadFull(tlsConn, actual); err != nil {
642 return err
643 }
644 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
645 if err != nil {
646 return err
647 }
648 if !bytes.Equal(actual, expected) {
649 return fmt.Errorf("keying material mismatch")
650 }
651 }
652
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700653 if test.testTLSUnique {
654 var peersValue [12]byte
655 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
656 return err
657 }
658 expected := tlsConn.ConnectionState().TLSUnique
659 if !bytes.Equal(peersValue[:], expected) {
660 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
661 }
662 }
663
David Benjamine58c4f52014-08-24 03:47:07 -0400664 if test.shimWritesFirst {
665 var buf [5]byte
666 _, err := io.ReadFull(tlsConn, buf[:])
667 if err != nil {
668 return err
669 }
670 if string(buf[:]) != "hello" {
671 return fmt.Errorf("bad initial message")
672 }
673 }
674
Steven Valdez32635b82016-08-16 11:25:03 -0400675 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400676 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400677 return err
678 }
Steven Valdez32635b82016-08-16 11:25:03 -0400679 }
680
David Benjamina8ebe222015-06-06 03:04:39 -0400681 for i := 0; i < test.sendEmptyRecords; i++ {
682 tlsConn.Write(nil)
683 }
684
David Benjamin24f346d2015-06-06 03:28:08 -0400685 for i := 0; i < test.sendWarningAlerts; i++ {
686 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
687 }
688
David Benjamin47921102016-07-28 11:29:18 -0400689 if test.sendHalfHelloRequest {
690 tlsConn.SendHalfHelloRequest()
691 }
692
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400693 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700694 if test.renegotiateCiphers != nil {
695 config.CipherSuites = test.renegotiateCiphers
696 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400697 for i := 0; i < test.renegotiate; i++ {
698 if err := tlsConn.Renegotiate(); err != nil {
699 return err
700 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700701 }
702 } else if test.renegotiateCiphers != nil {
703 panic("renegotiateCiphers without renegotiate")
704 }
705
David Benjamin5fa3eba2015-01-22 16:35:40 -0500706 if test.damageFirstWrite {
707 connDamage.setDamage(true)
708 tlsConn.Write([]byte("DAMAGED WRITE"))
709 connDamage.setDamage(false)
710 }
711
David Benjamin8e6db492015-07-25 18:29:23 -0400712 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700713 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400714 if test.protocol == dtls {
715 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
716 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700717 // Read until EOF.
718 _, err := io.Copy(ioutil.Discard, tlsConn)
719 return err
720 }
David Benjamin4417d052015-04-05 04:17:25 -0400721 if messageLen == 0 {
722 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700723 }
Adam Langley95c29f32014-06-20 12:00:00 -0700724
David Benjamin8e6db492015-07-25 18:29:23 -0400725 messageCount := test.messageCount
726 if messageCount == 0 {
727 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400728 }
729
David Benjamin8e6db492015-07-25 18:29:23 -0400730 for j := 0; j < messageCount; j++ {
731 testMessage := make([]byte, messageLen)
732 for i := range testMessage {
733 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400734 }
David Benjamin8e6db492015-07-25 18:29:23 -0400735 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700736
Steven Valdez32635b82016-08-16 11:25:03 -0400737 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400738 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400739 }
740
David Benjamin8e6db492015-07-25 18:29:23 -0400741 for i := 0; i < test.sendEmptyRecords; i++ {
742 tlsConn.Write(nil)
743 }
744
745 for i := 0; i < test.sendWarningAlerts; i++ {
746 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
747 }
748
David Benjamin4f75aaf2015-09-01 16:53:10 -0400749 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400750 // The shim will not respond.
751 continue
752 }
753
David Benjamin8e6db492015-07-25 18:29:23 -0400754 buf := make([]byte, len(testMessage))
755 if test.protocol == dtls {
756 bufTmp := make([]byte, len(buf)+1)
757 n, err := tlsConn.Read(bufTmp)
758 if err != nil {
759 return err
760 }
761 if n != len(buf) {
762 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
763 }
764 copy(buf, bufTmp)
765 } else {
766 _, err := io.ReadFull(tlsConn, buf)
767 if err != nil {
768 return err
769 }
770 }
771
772 for i, v := range buf {
773 if v != testMessage[i]^0xff {
774 return fmt.Errorf("bad reply contents at byte %d", i)
775 }
Adam Langley95c29f32014-06-20 12:00:00 -0700776 }
777 }
778
779 return nil
780}
781
David Benjamin325b5c32014-07-01 19:40:31 -0400782func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400783 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700784 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400785 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700786 }
David Benjamin325b5c32014-07-01 19:40:31 -0400787 valgrindArgs = append(valgrindArgs, path)
788 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700789
David Benjamin325b5c32014-07-01 19:40:31 -0400790 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700791}
792
David Benjamin325b5c32014-07-01 19:40:31 -0400793func gdbOf(path string, args ...string) *exec.Cmd {
794 xtermArgs := []string{"-e", "gdb", "--args"}
795 xtermArgs = append(xtermArgs, path)
796 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700797
David Benjamin325b5c32014-07-01 19:40:31 -0400798 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700799}
800
David Benjamind16bf342015-12-18 00:53:12 -0500801func lldbOf(path string, args ...string) *exec.Cmd {
802 xtermArgs := []string{"-e", "lldb", "--"}
803 xtermArgs = append(xtermArgs, path)
804 xtermArgs = append(xtermArgs, args...)
805
806 return exec.Command("xterm", xtermArgs...)
807}
808
EKR842ae6c2016-07-27 09:22:05 +0200809var (
810 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
811 errUnimplemented = errors.New("child process does not implement needed flags")
812)
Adam Langley69a01602014-11-17 17:26:55 -0800813
David Benjamin87c8a642015-02-21 01:54:29 -0500814// accept accepts a connection from listener, unless waitChan signals a process
815// exit first.
816func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
817 type connOrError struct {
818 conn net.Conn
819 err error
820 }
821 connChan := make(chan connOrError, 1)
822 go func() {
823 conn, err := listener.Accept()
824 connChan <- connOrError{conn, err}
825 close(connChan)
826 }()
827 select {
828 case result := <-connChan:
829 return result.conn, result.err
830 case childErr := <-waitChan:
831 waitChan <- childErr
832 return nil, fmt.Errorf("child exited early: %s", childErr)
833 }
834}
835
EKRf71d7ed2016-08-06 13:25:12 -0700836func translateExpectedError(errorStr string) string {
837 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
838 return translated
839 }
840
841 if *looseErrors {
842 return ""
843 }
844
845 return errorStr
846}
847
Adam Langley7c803a62015-06-15 15:35:05 -0700848func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400849 // Help debugging panics on the Go side.
850 defer func() {
851 if r := recover(); r != nil {
852 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
853 panic(r)
854 }
855 }()
856
Adam Langley38311732014-10-16 19:04:35 -0700857 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
858 panic("Error expected without shouldFail in " + test.name)
859 }
860
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700861 if test.expectResumeRejected && !test.resumeSession {
862 panic("expectResumeRejected without resumeSession in " + test.name)
863 }
864
Adam Langley33b1d4f2016-12-07 15:03:45 -0800865 for _, ver := range tlsVersions {
866 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
867 continue
868 }
869
870 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
871 continue
872 }
873
874 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))
875 }
876
David Benjamin87c8a642015-02-21 01:54:29 -0500877 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
878 if err != nil {
879 panic(err)
880 }
881 defer func() {
882 if listener != nil {
883 listener.Close()
884 }
885 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700886
David Benjamin87c8a642015-02-21 01:54:29 -0500887 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400888 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400889 flags = append(flags, "-server")
890
David Benjamin025b3d32014-07-01 19:53:04 -0400891 flags = append(flags, "-key-file")
892 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700893 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400894 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700895 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400896 }
897
898 flags = append(flags, "-cert-file")
899 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700900 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400901 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700902 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400903 }
904 }
David Benjamin5a593af2014-08-11 19:51:50 -0400905
David Benjamin6fd297b2014-08-11 18:43:38 -0400906 if test.protocol == dtls {
907 flags = append(flags, "-dtls")
908 }
909
David Benjamin46662482016-08-17 00:51:00 -0400910 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400911 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400912 resumeCount++
913 if test.resumeRenewedSession {
914 resumeCount++
915 }
916 }
917
918 if resumeCount > 0 {
919 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400920 }
921
David Benjamine58c4f52014-08-24 03:47:07 -0400922 if test.shimWritesFirst {
923 flags = append(flags, "-shim-writes-first")
924 }
925
David Benjamin30789da2015-08-29 22:56:45 -0400926 if test.shimShutsDown {
927 flags = append(flags, "-shim-shuts-down")
928 }
929
David Benjaminc565ebb2015-04-03 04:06:36 -0400930 if test.exportKeyingMaterial > 0 {
931 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
932 flags = append(flags, "-export-label", test.exportLabel)
933 flags = append(flags, "-export-context", test.exportContext)
934 if test.useExportContext {
935 flags = append(flags, "-use-export-context")
936 }
937 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700938 if test.expectResumeRejected {
939 flags = append(flags, "-expect-session-miss")
940 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400941
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700942 if test.testTLSUnique {
943 flags = append(flags, "-tls-unique")
944 }
945
David Benjamin025b3d32014-07-01 19:53:04 -0400946 flags = append(flags, test.flags...)
947
948 var shim *exec.Cmd
949 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700950 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700951 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700952 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500953 } else if *useLLDB {
954 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400955 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700956 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400957 }
David Benjamin025b3d32014-07-01 19:53:04 -0400958 shim.Stdin = os.Stdin
959 var stdoutBuf, stderrBuf bytes.Buffer
960 shim.Stdout = &stdoutBuf
961 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800962 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500963 shim.Env = os.Environ()
964 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800965 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400966 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800967 }
968 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
969 }
David Benjamin025b3d32014-07-01 19:53:04 -0400970
971 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700972 panic(err)
973 }
David Benjamin87c8a642015-02-21 01:54:29 -0500974 waitChan := make(chan error, 1)
975 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700976
977 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700978
David Benjamin7a4aaa42016-09-20 17:58:14 -0400979 if *deterministic {
980 config.Rand = &deterministicRand{}
981 }
982
David Benjamin87c8a642015-02-21 01:54:29 -0500983 conn, err := acceptOrWait(listener, waitChan)
984 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400985 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500986 conn.Close()
987 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500988
David Benjamin46662482016-08-17 00:51:00 -0400989 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400990 var resumeConfig Config
991 if test.resumeConfig != nil {
992 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400993 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500994 resumeConfig.SessionTicketKey = config.SessionTicketKey
995 resumeConfig.ClientSessionCache = config.ClientSessionCache
996 resumeConfig.ServerSessionCache = config.ServerSessionCache
997 }
David Benjamin2e045a92016-06-08 13:09:56 -0400998 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400999 } else {
1000 resumeConfig = config
1001 }
David Benjamin87c8a642015-02-21 01:54:29 -05001002 var connResume net.Conn
1003 connResume, err = acceptOrWait(listener, waitChan)
1004 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -04001005 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -05001006 connResume.Close()
1007 }
David Benjamin1d5c83e2014-07-22 19:20:02 -04001008 }
1009
David Benjamin87c8a642015-02-21 01:54:29 -05001010 // Close the listener now. This is to avoid hangs should the shim try to
1011 // open more connections than expected.
1012 listener.Close()
1013 listener = nil
1014
1015 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -04001016 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -08001017 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +02001018 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1019 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001020 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001021 case 89:
1022 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001023 case 99:
1024 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001025 }
1026 }
Adam Langley95c29f32014-06-20 12:00:00 -07001027
David Benjamin9bea3492016-03-02 10:59:16 -05001028 // Account for Windows line endings.
1029 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1030 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001031
1032 // Separate the errors from the shim and those from tools like
1033 // AddressSanitizer.
1034 var extraStderr string
1035 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1036 stderr = stderrParts[0]
1037 extraStderr = stderrParts[1]
1038 }
1039
Adam Langley95c29f32014-06-20 12:00:00 -07001040 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001041 expectedError := translateExpectedError(test.expectedError)
1042 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001043
Adam Langleyac61fa32014-06-23 12:03:11 -07001044 localError := "none"
1045 if err != nil {
1046 localError = err.Error()
1047 }
1048 if len(test.expectedLocalError) != 0 {
1049 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1050 }
Adam Langley95c29f32014-06-20 12:00:00 -07001051
1052 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001053 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001054 if childErr != nil {
1055 childError = childErr.Error()
1056 }
1057
1058 var msg string
1059 switch {
1060 case failed && !test.shouldFail:
1061 msg = "unexpected failure"
1062 case !failed && test.shouldFail:
1063 msg = "unexpected success"
1064 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001065 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001066 default:
1067 panic("internal error")
1068 }
1069
David Benjamin9aafb642016-09-20 19:36:53 -04001070 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 -07001071 }
1072
David Benjamind2ba8892016-09-20 19:41:04 -04001073 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001074 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001075 }
1076
David Benjamind2ba8892016-09-20 19:41:04 -04001077 if *useValgrind && isValgrindError {
1078 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1079 }
1080
Adam Langley95c29f32014-06-20 12:00:00 -07001081 return nil
1082}
1083
David Benjaminaa012042016-12-10 13:33:05 -05001084type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001085 name string
1086 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001087 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001088 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001089}
1090
1091var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001092 {"SSL3", VersionSSL30, "-no-ssl3", false},
1093 {"TLS1", VersionTLS10, "-no-tls1", true},
1094 {"TLS11", VersionTLS11, "-no-tls11", false},
1095 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001096 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001097}
1098
David Benjaminaa012042016-12-10 13:33:05 -05001099type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001100 name string
1101 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001102}
1103
1104var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001105 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001106 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001107 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001108 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001109 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001110 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001111 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001112 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1113 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001114 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1115 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001116 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001117 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001118 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001119 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001120 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001121 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001122 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001123 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001124 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001125 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001126 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1127 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001128 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1129 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001130 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001131 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1132 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1133 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001134 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001135}
1136
David Benjamin8b8c0062014-11-23 02:47:52 -05001137func hasComponent(suiteName, component string) bool {
1138 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1139}
1140
David Benjaminf7768e42014-08-31 02:06:47 -04001141func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001142 return hasComponent(suiteName, "GCM") ||
1143 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001144 hasComponent(suiteName, "SHA384") ||
1145 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001146}
1147
Nick Harper1fd39d82016-06-14 18:14:35 -07001148func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001149 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001150}
1151
David Benjamin8b8c0062014-11-23 02:47:52 -05001152func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001153 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001154}
1155
Adam Langleya7997f12015-05-14 17:38:50 -07001156func bigFromHex(hex string) *big.Int {
1157 ret, ok := new(big.Int).SetString(hex, 16)
1158 if !ok {
1159 panic("failed to parse hex number 0x" + hex)
1160 }
1161 return ret
1162}
1163
Adam Langley7c803a62015-06-15 15:35:05 -07001164func addBasicTests() {
1165 basicTests := []testCase{
1166 {
Adam Langley7c803a62015-06-15 15:35:05 -07001167 name: "NoFallbackSCSV",
1168 config: Config{
1169 Bugs: ProtocolBugs{
1170 FailIfNotFallbackSCSV: true,
1171 },
1172 },
1173 shouldFail: true,
1174 expectedLocalError: "no fallback SCSV found",
1175 },
1176 {
1177 name: "SendFallbackSCSV",
1178 config: Config{
1179 Bugs: ProtocolBugs{
1180 FailIfNotFallbackSCSV: true,
1181 },
1182 },
1183 flags: []string{"-fallback-scsv"},
1184 },
1185 {
1186 name: "ClientCertificateTypes",
1187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001188 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001189 ClientAuth: RequestClientCert,
1190 ClientCertificateTypes: []byte{
1191 CertTypeDSSSign,
1192 CertTypeRSASign,
1193 CertTypeECDSASign,
1194 },
1195 },
1196 flags: []string{
1197 "-expect-certificate-types",
1198 base64.StdEncoding.EncodeToString([]byte{
1199 CertTypeDSSSign,
1200 CertTypeRSASign,
1201 CertTypeECDSASign,
1202 }),
1203 },
1204 },
1205 {
Adam Langley7c803a62015-06-15 15:35:05 -07001206 name: "UnauthenticatedECDH",
1207 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001208 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001209 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1210 Bugs: ProtocolBugs{
1211 UnauthenticatedECDH: true,
1212 },
1213 },
1214 shouldFail: true,
1215 expectedError: ":UNEXPECTED_MESSAGE:",
1216 },
1217 {
1218 name: "SkipCertificateStatus",
1219 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001220 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001221 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1222 Bugs: ProtocolBugs{
1223 SkipCertificateStatus: true,
1224 },
1225 },
1226 flags: []string{
1227 "-enable-ocsp-stapling",
1228 },
1229 },
1230 {
1231 name: "SkipServerKeyExchange",
1232 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001233 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001234 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1235 Bugs: ProtocolBugs{
1236 SkipServerKeyExchange: true,
1237 },
1238 },
1239 shouldFail: true,
1240 expectedError: ":UNEXPECTED_MESSAGE:",
1241 },
1242 {
Adam Langley7c803a62015-06-15 15:35:05 -07001243 testType: serverTest,
1244 name: "Alert",
1245 config: Config{
1246 Bugs: ProtocolBugs{
1247 SendSpuriousAlert: alertRecordOverflow,
1248 },
1249 },
1250 shouldFail: true,
1251 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1252 },
1253 {
1254 protocol: dtls,
1255 testType: serverTest,
1256 name: "Alert-DTLS",
1257 config: Config{
1258 Bugs: ProtocolBugs{
1259 SendSpuriousAlert: alertRecordOverflow,
1260 },
1261 },
1262 shouldFail: true,
1263 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1264 },
1265 {
1266 testType: serverTest,
1267 name: "FragmentAlert",
1268 config: Config{
1269 Bugs: ProtocolBugs{
1270 FragmentAlert: true,
1271 SendSpuriousAlert: alertRecordOverflow,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":BAD_ALERT:",
1276 },
1277 {
1278 protocol: dtls,
1279 testType: serverTest,
1280 name: "FragmentAlert-DTLS",
1281 config: Config{
1282 Bugs: ProtocolBugs{
1283 FragmentAlert: true,
1284 SendSpuriousAlert: alertRecordOverflow,
1285 },
1286 },
1287 shouldFail: true,
1288 expectedError: ":BAD_ALERT:",
1289 },
1290 {
1291 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001292 name: "DoubleAlert",
1293 config: Config{
1294 Bugs: ProtocolBugs{
1295 DoubleAlert: true,
1296 SendSpuriousAlert: alertRecordOverflow,
1297 },
1298 },
1299 shouldFail: true,
1300 expectedError: ":BAD_ALERT:",
1301 },
1302 {
1303 protocol: dtls,
1304 testType: serverTest,
1305 name: "DoubleAlert-DTLS",
1306 config: Config{
1307 Bugs: ProtocolBugs{
1308 DoubleAlert: true,
1309 SendSpuriousAlert: alertRecordOverflow,
1310 },
1311 },
1312 shouldFail: true,
1313 expectedError: ":BAD_ALERT:",
1314 },
1315 {
Adam Langley7c803a62015-06-15 15:35:05 -07001316 name: "SkipNewSessionTicket",
1317 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001318 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001319 Bugs: ProtocolBugs{
1320 SkipNewSessionTicket: true,
1321 },
1322 },
1323 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001324 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001325 },
1326 {
1327 testType: serverTest,
1328 name: "FallbackSCSV",
1329 config: Config{
1330 MaxVersion: VersionTLS11,
1331 Bugs: ProtocolBugs{
1332 SendFallbackSCSV: true,
1333 },
1334 },
David Benjamin56cadc32016-12-16 19:54:11 -05001335 shouldFail: true,
1336 expectedError: ":INAPPROPRIATE_FALLBACK:",
1337 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001338 },
1339 {
1340 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001341 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001342 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001343 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001344 Bugs: ProtocolBugs{
1345 SendFallbackSCSV: true,
1346 },
1347 },
1348 },
1349 {
1350 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001351 name: "FallbackSCSV-VersionMatch-TLS12",
1352 config: Config{
1353 MaxVersion: VersionTLS12,
1354 Bugs: ProtocolBugs{
1355 SendFallbackSCSV: true,
1356 },
1357 },
1358 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1359 },
1360 {
1361 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001362 name: "FragmentedClientVersion",
1363 config: Config{
1364 Bugs: ProtocolBugs{
1365 MaxHandshakeRecordLength: 1,
1366 FragmentClientVersion: true,
1367 },
1368 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001369 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001370 },
1371 {
Adam Langley7c803a62015-06-15 15:35:05 -07001372 testType: serverTest,
1373 name: "HttpGET",
1374 sendPrefix: "GET / HTTP/1.0\n",
1375 shouldFail: true,
1376 expectedError: ":HTTP_REQUEST:",
1377 },
1378 {
1379 testType: serverTest,
1380 name: "HttpPOST",
1381 sendPrefix: "POST / HTTP/1.0\n",
1382 shouldFail: true,
1383 expectedError: ":HTTP_REQUEST:",
1384 },
1385 {
1386 testType: serverTest,
1387 name: "HttpHEAD",
1388 sendPrefix: "HEAD / HTTP/1.0\n",
1389 shouldFail: true,
1390 expectedError: ":HTTP_REQUEST:",
1391 },
1392 {
1393 testType: serverTest,
1394 name: "HttpPUT",
1395 sendPrefix: "PUT / HTTP/1.0\n",
1396 shouldFail: true,
1397 expectedError: ":HTTP_REQUEST:",
1398 },
1399 {
1400 testType: serverTest,
1401 name: "HttpCONNECT",
1402 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1403 shouldFail: true,
1404 expectedError: ":HTTPS_PROXY_REQUEST:",
1405 },
1406 {
1407 testType: serverTest,
1408 name: "Garbage",
1409 sendPrefix: "blah",
1410 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001411 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001412 },
1413 {
Adam Langley7c803a62015-06-15 15:35:05 -07001414 name: "RSAEphemeralKey",
1415 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001416 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001417 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1418 Bugs: ProtocolBugs{
1419 RSAEphemeralKey: true,
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":UNEXPECTED_MESSAGE:",
1424 },
1425 {
1426 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001427 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001428 shouldFail: true,
1429 expectedError: ":WRONG_SSL_VERSION:",
1430 },
1431 {
1432 protocol: dtls,
1433 name: "DisableEverything-DTLS",
1434 flags: []string{"-no-tls12", "-no-tls1"},
1435 shouldFail: true,
1436 expectedError: ":WRONG_SSL_VERSION:",
1437 },
1438 {
Adam Langley7c803a62015-06-15 15:35:05 -07001439 protocol: dtls,
1440 testType: serverTest,
1441 name: "MTU",
1442 config: Config{
1443 Bugs: ProtocolBugs{
1444 MaxPacketLength: 256,
1445 },
1446 },
1447 flags: []string{"-mtu", "256"},
1448 },
1449 {
1450 protocol: dtls,
1451 testType: serverTest,
1452 name: "MTUExceeded",
1453 config: Config{
1454 Bugs: ProtocolBugs{
1455 MaxPacketLength: 255,
1456 },
1457 },
1458 flags: []string{"-mtu", "256"},
1459 shouldFail: true,
1460 expectedLocalError: "dtls: exceeded maximum packet length",
1461 },
1462 {
1463 name: "CertMismatchRSA",
1464 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001465 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001466 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001467 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001468 Bugs: ProtocolBugs{
1469 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1470 },
1471 },
1472 shouldFail: true,
1473 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1474 },
1475 {
1476 name: "CertMismatchECDSA",
1477 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001478 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001479 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001480 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001481 Bugs: ProtocolBugs{
1482 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1483 },
1484 },
1485 shouldFail: true,
1486 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1487 },
1488 {
1489 name: "EmptyCertificateList",
1490 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001491 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001492 Bugs: ProtocolBugs{
1493 EmptyCertificateList: true,
1494 },
1495 },
1496 shouldFail: true,
1497 expectedError: ":DECODE_ERROR:",
1498 },
1499 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001500 name: "EmptyCertificateList-TLS13",
1501 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001502 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001503 Bugs: ProtocolBugs{
1504 EmptyCertificateList: true,
1505 },
1506 },
1507 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001508 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001509 },
1510 {
Adam Langley7c803a62015-06-15 15:35:05 -07001511 name: "TLSFatalBadPackets",
1512 damageFirstWrite: true,
1513 shouldFail: true,
1514 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1515 },
1516 {
1517 protocol: dtls,
1518 name: "DTLSIgnoreBadPackets",
1519 damageFirstWrite: true,
1520 },
1521 {
1522 protocol: dtls,
1523 name: "DTLSIgnoreBadPackets-Async",
1524 damageFirstWrite: true,
1525 flags: []string{"-async"},
1526 },
1527 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001528 name: "AppDataBeforeHandshake",
1529 config: Config{
1530 Bugs: ProtocolBugs{
1531 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1532 },
1533 },
1534 shouldFail: true,
1535 expectedError: ":UNEXPECTED_RECORD:",
1536 },
1537 {
1538 name: "AppDataBeforeHandshake-Empty",
1539 config: Config{
1540 Bugs: ProtocolBugs{
1541 AppDataBeforeHandshake: []byte{},
1542 },
1543 },
1544 shouldFail: true,
1545 expectedError: ":UNEXPECTED_RECORD:",
1546 },
1547 {
1548 protocol: dtls,
1549 name: "AppDataBeforeHandshake-DTLS",
1550 config: Config{
1551 Bugs: ProtocolBugs{
1552 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1553 },
1554 },
1555 shouldFail: true,
1556 expectedError: ":UNEXPECTED_RECORD:",
1557 },
1558 {
1559 protocol: dtls,
1560 name: "AppDataBeforeHandshake-DTLS-Empty",
1561 config: Config{
1562 Bugs: ProtocolBugs{
1563 AppDataBeforeHandshake: []byte{},
1564 },
1565 },
1566 shouldFail: true,
1567 expectedError: ":UNEXPECTED_RECORD:",
1568 },
1569 {
Adam Langley7c803a62015-06-15 15:35:05 -07001570 name: "AppDataAfterChangeCipherSpec",
1571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001572 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001573 Bugs: ProtocolBugs{
1574 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1575 },
1576 },
1577 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001578 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001579 },
1580 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001581 name: "AppDataAfterChangeCipherSpec-Empty",
1582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001583 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001584 Bugs: ProtocolBugs{
1585 AppDataAfterChangeCipherSpec: []byte{},
1586 },
1587 },
1588 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001589 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001590 },
1591 {
Adam Langley7c803a62015-06-15 15:35:05 -07001592 protocol: dtls,
1593 name: "AppDataAfterChangeCipherSpec-DTLS",
1594 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001595 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001596 Bugs: ProtocolBugs{
1597 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1598 },
1599 },
1600 // BoringSSL's DTLS implementation will drop the out-of-order
1601 // application data.
1602 },
1603 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001604 protocol: dtls,
1605 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001607 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001608 Bugs: ProtocolBugs{
1609 AppDataAfterChangeCipherSpec: []byte{},
1610 },
1611 },
1612 // BoringSSL's DTLS implementation will drop the out-of-order
1613 // application data.
1614 },
1615 {
Adam Langley7c803a62015-06-15 15:35:05 -07001616 name: "AlertAfterChangeCipherSpec",
1617 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001618 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001619 Bugs: ProtocolBugs{
1620 AlertAfterChangeCipherSpec: alertRecordOverflow,
1621 },
1622 },
1623 shouldFail: true,
1624 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1625 },
1626 {
1627 protocol: dtls,
1628 name: "AlertAfterChangeCipherSpec-DTLS",
1629 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001630 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001631 Bugs: ProtocolBugs{
1632 AlertAfterChangeCipherSpec: alertRecordOverflow,
1633 },
1634 },
1635 shouldFail: true,
1636 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1637 },
1638 {
1639 protocol: dtls,
1640 name: "ReorderHandshakeFragments-Small-DTLS",
1641 config: Config{
1642 Bugs: ProtocolBugs{
1643 ReorderHandshakeFragments: true,
1644 // Small enough that every handshake message is
1645 // fragmented.
1646 MaxHandshakeRecordLength: 2,
1647 },
1648 },
1649 },
1650 {
1651 protocol: dtls,
1652 name: "ReorderHandshakeFragments-Large-DTLS",
1653 config: Config{
1654 Bugs: ProtocolBugs{
1655 ReorderHandshakeFragments: true,
1656 // Large enough that no handshake message is
1657 // fragmented.
1658 MaxHandshakeRecordLength: 2048,
1659 },
1660 },
1661 },
1662 {
1663 protocol: dtls,
1664 name: "MixCompleteMessageWithFragments-DTLS",
1665 config: Config{
1666 Bugs: ProtocolBugs{
1667 ReorderHandshakeFragments: true,
1668 MixCompleteMessageWithFragments: true,
1669 MaxHandshakeRecordLength: 2,
1670 },
1671 },
1672 },
1673 {
1674 name: "SendInvalidRecordType",
1675 config: Config{
1676 Bugs: ProtocolBugs{
1677 SendInvalidRecordType: true,
1678 },
1679 },
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 protocol: dtls,
1685 name: "SendInvalidRecordType-DTLS",
1686 config: Config{
1687 Bugs: ProtocolBugs{
1688 SendInvalidRecordType: true,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":UNEXPECTED_RECORD:",
1693 },
1694 {
1695 name: "FalseStart-SkipServerSecondLeg",
1696 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001697 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001698 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1699 NextProtos: []string{"foo"},
1700 Bugs: ProtocolBugs{
1701 SkipNewSessionTicket: true,
1702 SkipChangeCipherSpec: true,
1703 SkipFinished: true,
1704 ExpectFalseStart: true,
1705 },
1706 },
1707 flags: []string{
1708 "-false-start",
1709 "-handshake-never-done",
1710 "-advertise-alpn", "\x03foo",
1711 },
1712 shimWritesFirst: true,
1713 shouldFail: true,
1714 expectedError: ":UNEXPECTED_RECORD:",
1715 },
1716 {
1717 name: "FalseStart-SkipServerSecondLeg-Implicit",
1718 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001719 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001720 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1721 NextProtos: []string{"foo"},
1722 Bugs: ProtocolBugs{
1723 SkipNewSessionTicket: true,
1724 SkipChangeCipherSpec: true,
1725 SkipFinished: true,
1726 },
1727 },
1728 flags: []string{
1729 "-implicit-handshake",
1730 "-false-start",
1731 "-handshake-never-done",
1732 "-advertise-alpn", "\x03foo",
1733 },
1734 shouldFail: true,
1735 expectedError: ":UNEXPECTED_RECORD:",
1736 },
1737 {
1738 testType: serverTest,
1739 name: "FailEarlyCallback",
1740 flags: []string{"-fail-early-callback"},
1741 shouldFail: true,
1742 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001743 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001744 },
1745 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001746 name: "FailCertCallback-Client-TLS12",
1747 config: Config{
1748 MaxVersion: VersionTLS12,
1749 ClientAuth: RequestClientCert,
1750 },
1751 flags: []string{"-fail-cert-callback"},
1752 shouldFail: true,
1753 expectedError: ":CERT_CB_ERROR:",
1754 expectedLocalError: "remote error: internal error",
1755 },
1756 {
1757 testType: serverTest,
1758 name: "FailCertCallback-Server-TLS12",
1759 config: Config{
1760 MaxVersion: VersionTLS12,
1761 },
1762 flags: []string{"-fail-cert-callback"},
1763 shouldFail: true,
1764 expectedError: ":CERT_CB_ERROR:",
1765 expectedLocalError: "remote error: internal error",
1766 },
1767 {
1768 name: "FailCertCallback-Client-TLS13",
1769 config: Config{
1770 MaxVersion: VersionTLS13,
1771 ClientAuth: RequestClientCert,
1772 },
1773 flags: []string{"-fail-cert-callback"},
1774 shouldFail: true,
1775 expectedError: ":CERT_CB_ERROR:",
1776 expectedLocalError: "remote error: internal error",
1777 },
1778 {
1779 testType: serverTest,
1780 name: "FailCertCallback-Server-TLS13",
1781 config: Config{
1782 MaxVersion: VersionTLS13,
1783 },
1784 flags: []string{"-fail-cert-callback"},
1785 shouldFail: true,
1786 expectedError: ":CERT_CB_ERROR:",
1787 expectedLocalError: "remote error: internal error",
1788 },
1789 {
Adam Langley7c803a62015-06-15 15:35:05 -07001790 protocol: dtls,
1791 name: "FragmentMessageTypeMismatch-DTLS",
1792 config: Config{
1793 Bugs: ProtocolBugs{
1794 MaxHandshakeRecordLength: 2,
1795 FragmentMessageTypeMismatch: true,
1796 },
1797 },
1798 shouldFail: true,
1799 expectedError: ":FRAGMENT_MISMATCH:",
1800 },
1801 {
1802 protocol: dtls,
1803 name: "FragmentMessageLengthMismatch-DTLS",
1804 config: Config{
1805 Bugs: ProtocolBugs{
1806 MaxHandshakeRecordLength: 2,
1807 FragmentMessageLengthMismatch: true,
1808 },
1809 },
1810 shouldFail: true,
1811 expectedError: ":FRAGMENT_MISMATCH:",
1812 },
1813 {
1814 protocol: dtls,
1815 name: "SplitFragments-Header-DTLS",
1816 config: Config{
1817 Bugs: ProtocolBugs{
1818 SplitFragments: 2,
1819 },
1820 },
1821 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001822 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001823 },
1824 {
1825 protocol: dtls,
1826 name: "SplitFragments-Boundary-DTLS",
1827 config: Config{
1828 Bugs: ProtocolBugs{
1829 SplitFragments: dtlsRecordHeaderLen,
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-Body-DTLS",
1838 config: Config{
1839 Bugs: ProtocolBugs{
1840 SplitFragments: dtlsRecordHeaderLen + 1,
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: "SendEmptyFragments-DTLS",
1849 config: Config{
1850 Bugs: ProtocolBugs{
1851 SendEmptyFragments: true,
1852 },
1853 },
1854 },
1855 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001856 name: "BadFinished-Client",
1857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001858 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001859 Bugs: ProtocolBugs{
1860 BadFinished: true,
1861 },
1862 },
1863 shouldFail: true,
1864 expectedError: ":DIGEST_CHECK_FAILED:",
1865 },
1866 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001867 name: "BadFinished-Client-TLS13",
1868 config: Config{
1869 MaxVersion: VersionTLS13,
1870 Bugs: ProtocolBugs{
1871 BadFinished: true,
1872 },
1873 },
1874 shouldFail: true,
1875 expectedError: ":DIGEST_CHECK_FAILED:",
1876 },
1877 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001878 testType: serverTest,
1879 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001880 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001881 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001882 Bugs: ProtocolBugs{
1883 BadFinished: true,
1884 },
1885 },
1886 shouldFail: true,
1887 expectedError: ":DIGEST_CHECK_FAILED:",
1888 },
1889 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001890 testType: serverTest,
1891 name: "BadFinished-Server-TLS13",
1892 config: Config{
1893 MaxVersion: VersionTLS13,
1894 Bugs: ProtocolBugs{
1895 BadFinished: true,
1896 },
1897 },
1898 shouldFail: true,
1899 expectedError: ":DIGEST_CHECK_FAILED:",
1900 },
1901 {
Adam Langley7c803a62015-06-15 15:35:05 -07001902 name: "FalseStart-BadFinished",
1903 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001904 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001905 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1906 NextProtos: []string{"foo"},
1907 Bugs: ProtocolBugs{
1908 BadFinished: true,
1909 ExpectFalseStart: true,
1910 },
1911 },
1912 flags: []string{
1913 "-false-start",
1914 "-handshake-never-done",
1915 "-advertise-alpn", "\x03foo",
1916 },
1917 shimWritesFirst: true,
1918 shouldFail: true,
1919 expectedError: ":DIGEST_CHECK_FAILED:",
1920 },
1921 {
1922 name: "NoFalseStart-NoALPN",
1923 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001924 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001925 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1926 Bugs: ProtocolBugs{
1927 ExpectFalseStart: true,
1928 AlertBeforeFalseStartTest: alertAccessDenied,
1929 },
1930 },
1931 flags: []string{
1932 "-false-start",
1933 },
1934 shimWritesFirst: true,
1935 shouldFail: true,
1936 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1937 expectedLocalError: "tls: peer did not false start: EOF",
1938 },
1939 {
1940 name: "NoFalseStart-NoAEAD",
1941 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001942 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1944 NextProtos: []string{"foo"},
1945 Bugs: ProtocolBugs{
1946 ExpectFalseStart: true,
1947 AlertBeforeFalseStartTest: alertAccessDenied,
1948 },
1949 },
1950 flags: []string{
1951 "-false-start",
1952 "-advertise-alpn", "\x03foo",
1953 },
1954 shimWritesFirst: true,
1955 shouldFail: true,
1956 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1957 expectedLocalError: "tls: peer did not false start: EOF",
1958 },
1959 {
1960 name: "NoFalseStart-RSA",
1961 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001962 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001963 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1964 NextProtos: []string{"foo"},
1965 Bugs: ProtocolBugs{
1966 ExpectFalseStart: true,
1967 AlertBeforeFalseStartTest: alertAccessDenied,
1968 },
1969 },
1970 flags: []string{
1971 "-false-start",
1972 "-advertise-alpn", "\x03foo",
1973 },
1974 shimWritesFirst: true,
1975 shouldFail: true,
1976 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1977 expectedLocalError: "tls: peer did not false start: EOF",
1978 },
1979 {
Adam Langley7c803a62015-06-15 15:35:05 -07001980 protocol: dtls,
1981 name: "SendSplitAlert-Sync",
1982 config: Config{
1983 Bugs: ProtocolBugs{
1984 SendSplitAlert: true,
1985 },
1986 },
1987 },
1988 {
1989 protocol: dtls,
1990 name: "SendSplitAlert-Async",
1991 config: Config{
1992 Bugs: ProtocolBugs{
1993 SendSplitAlert: true,
1994 },
1995 },
1996 flags: []string{"-async"},
1997 },
1998 {
1999 protocol: dtls,
2000 name: "PackDTLSHandshake",
2001 config: Config{
2002 Bugs: ProtocolBugs{
2003 MaxHandshakeRecordLength: 2,
2004 PackHandshakeFragments: 20,
2005 PackHandshakeRecords: 200,
2006 },
2007 },
2008 },
2009 {
Adam Langley7c803a62015-06-15 15:35:05 -07002010 name: "SendEmptyRecords-Pass",
2011 sendEmptyRecords: 32,
2012 },
2013 {
2014 name: "SendEmptyRecords",
2015 sendEmptyRecords: 33,
2016 shouldFail: true,
2017 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2018 },
2019 {
2020 name: "SendEmptyRecords-Async",
2021 sendEmptyRecords: 33,
2022 flags: []string{"-async"},
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2025 },
2026 {
David Benjamine8e84b92016-08-03 15:39:47 -04002027 name: "SendWarningAlerts-Pass",
2028 config: Config{
2029 MaxVersion: VersionTLS12,
2030 },
Adam Langley7c803a62015-06-15 15:35:05 -07002031 sendWarningAlerts: 4,
2032 },
2033 {
David Benjamine8e84b92016-08-03 15:39:47 -04002034 protocol: dtls,
2035 name: "SendWarningAlerts-DTLS-Pass",
2036 config: Config{
2037 MaxVersion: VersionTLS12,
2038 },
Adam Langley7c803a62015-06-15 15:35:05 -07002039 sendWarningAlerts: 4,
2040 },
2041 {
David Benjamine8e84b92016-08-03 15:39:47 -04002042 name: "SendWarningAlerts-TLS13",
2043 config: Config{
2044 MaxVersion: VersionTLS13,
2045 },
2046 sendWarningAlerts: 4,
2047 shouldFail: true,
2048 expectedError: ":BAD_ALERT:",
2049 expectedLocalError: "remote error: error decoding message",
2050 },
2051 {
2052 name: "SendWarningAlerts",
2053 config: Config{
2054 MaxVersion: VersionTLS12,
2055 },
Adam Langley7c803a62015-06-15 15:35:05 -07002056 sendWarningAlerts: 5,
2057 shouldFail: true,
2058 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2059 },
2060 {
David Benjamine8e84b92016-08-03 15:39:47 -04002061 name: "SendWarningAlerts-Async",
2062 config: Config{
2063 MaxVersion: VersionTLS12,
2064 },
Adam Langley7c803a62015-06-15 15:35:05 -07002065 sendWarningAlerts: 5,
2066 flags: []string{"-async"},
2067 shouldFail: true,
2068 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2069 },
David Benjaminba4594a2015-06-18 18:36:15 -04002070 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002071 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002072 config: Config{
2073 MaxVersion: VersionTLS13,
2074 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002075 sendKeyUpdates: 33,
2076 keyUpdateRequest: keyUpdateNotRequested,
2077 shouldFail: true,
2078 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002079 },
2080 {
David Benjaminba4594a2015-06-18 18:36:15 -04002081 name: "EmptySessionID",
2082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002083 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002084 SessionTicketsDisabled: true,
2085 },
2086 noSessionCache: true,
2087 flags: []string{"-expect-no-session"},
2088 },
David Benjamin30789da2015-08-29 22:56:45 -04002089 {
2090 name: "Unclean-Shutdown",
2091 config: Config{
2092 Bugs: ProtocolBugs{
2093 NoCloseNotify: true,
2094 ExpectCloseNotify: true,
2095 },
2096 },
2097 shimShutsDown: true,
2098 flags: []string{"-check-close-notify"},
2099 shouldFail: true,
2100 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2101 },
2102 {
2103 name: "Unclean-Shutdown-Ignored",
2104 config: Config{
2105 Bugs: ProtocolBugs{
2106 NoCloseNotify: true,
2107 },
2108 },
2109 shimShutsDown: true,
2110 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002111 {
David Benjaminfa214e42016-05-10 17:03:10 -04002112 name: "Unclean-Shutdown-Alert",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 SendAlertOnShutdown: alertDecompressionFailure,
2116 ExpectCloseNotify: true,
2117 },
2118 },
2119 shimShutsDown: true,
2120 flags: []string{"-check-close-notify"},
2121 shouldFail: true,
2122 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2123 },
2124 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002125 name: "LargePlaintext",
2126 config: Config{
2127 Bugs: ProtocolBugs{
2128 SendLargeRecords: true,
2129 },
2130 },
2131 messageLen: maxPlaintext + 1,
2132 shouldFail: true,
2133 expectedError: ":DATA_LENGTH_TOO_LONG:",
2134 },
2135 {
2136 protocol: dtls,
2137 name: "LargePlaintext-DTLS",
2138 config: Config{
2139 Bugs: ProtocolBugs{
2140 SendLargeRecords: true,
2141 },
2142 },
2143 messageLen: maxPlaintext + 1,
2144 shouldFail: true,
2145 expectedError: ":DATA_LENGTH_TOO_LONG:",
2146 },
2147 {
2148 name: "LargeCiphertext",
2149 config: Config{
2150 Bugs: ProtocolBugs{
2151 SendLargeRecords: true,
2152 },
2153 },
2154 messageLen: maxPlaintext * 2,
2155 shouldFail: true,
2156 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2157 },
2158 {
2159 protocol: dtls,
2160 name: "LargeCiphertext-DTLS",
2161 config: Config{
2162 Bugs: ProtocolBugs{
2163 SendLargeRecords: true,
2164 },
2165 },
2166 messageLen: maxPlaintext * 2,
2167 // Unlike the other four cases, DTLS drops records which
2168 // are invalid before authentication, so the connection
2169 // does not fail.
2170 expectMessageDropped: true,
2171 },
David Benjamindd6fed92015-10-23 17:41:12 -04002172 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002173 name: "BadHelloRequest-1",
2174 renegotiate: 1,
2175 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002176 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002177 Bugs: ProtocolBugs{
2178 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2179 },
2180 },
2181 flags: []string{
2182 "-renegotiate-freely",
2183 "-expect-total-renegotiations", "1",
2184 },
2185 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002186 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002187 },
2188 {
2189 name: "BadHelloRequest-2",
2190 renegotiate: 1,
2191 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002192 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002193 Bugs: ProtocolBugs{
2194 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2195 },
2196 },
2197 flags: []string{
2198 "-renegotiate-freely",
2199 "-expect-total-renegotiations", "1",
2200 },
2201 shouldFail: true,
2202 expectedError: ":BAD_HELLO_REQUEST:",
2203 },
David Benjaminef1b0092015-11-21 14:05:44 -05002204 {
2205 testType: serverTest,
2206 name: "SupportTicketsWithSessionID",
2207 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002208 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002209 SessionTicketsDisabled: true,
2210 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002211 resumeConfig: &Config{
2212 MaxVersion: VersionTLS12,
2213 },
David Benjaminef1b0092015-11-21 14:05:44 -05002214 resumeSession: true,
2215 },
David Benjamin02edcd02016-07-27 17:40:37 -04002216 {
2217 protocol: dtls,
2218 name: "DTLS-SendExtraFinished",
2219 config: Config{
2220 Bugs: ProtocolBugs{
2221 SendExtraFinished: true,
2222 },
2223 },
2224 shouldFail: true,
2225 expectedError: ":UNEXPECTED_RECORD:",
2226 },
2227 {
2228 protocol: dtls,
2229 name: "DTLS-SendExtraFinished-Reordered",
2230 config: Config{
2231 Bugs: ProtocolBugs{
2232 MaxHandshakeRecordLength: 2,
2233 ReorderHandshakeFragments: true,
2234 SendExtraFinished: true,
2235 },
2236 },
2237 shouldFail: true,
2238 expectedError: ":UNEXPECTED_RECORD:",
2239 },
David Benjamine97fb482016-07-29 09:23:07 -04002240 {
2241 testType: serverTest,
2242 name: "V2ClientHello-EmptyRecordPrefix",
2243 config: Config{
2244 // Choose a cipher suite that does not involve
2245 // elliptic curves, so no extensions are
2246 // involved.
2247 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002248 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002249 Bugs: ProtocolBugs{
2250 SendV2ClientHello: true,
2251 },
2252 },
2253 sendPrefix: string([]byte{
2254 byte(recordTypeHandshake),
2255 3, 1, // version
2256 0, 0, // length
2257 }),
2258 // A no-op empty record may not be sent before V2ClientHello.
2259 shouldFail: true,
2260 expectedError: ":WRONG_VERSION_NUMBER:",
2261 },
2262 {
2263 testType: serverTest,
2264 name: "V2ClientHello-WarningAlertPrefix",
2265 config: Config{
2266 // Choose a cipher suite that does not involve
2267 // elliptic curves, so no extensions are
2268 // involved.
2269 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002270 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002271 Bugs: ProtocolBugs{
2272 SendV2ClientHello: true,
2273 },
2274 },
2275 sendPrefix: string([]byte{
2276 byte(recordTypeAlert),
2277 3, 1, // version
2278 0, 2, // length
2279 alertLevelWarning, byte(alertDecompressionFailure),
2280 }),
2281 // A no-op warning alert may not be sent before V2ClientHello.
2282 shouldFail: true,
2283 expectedError: ":WRONG_VERSION_NUMBER:",
2284 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002285 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002286 name: "KeyUpdate-Client",
2287 config: Config{
2288 MaxVersion: VersionTLS13,
2289 },
2290 sendKeyUpdates: 1,
2291 keyUpdateRequest: keyUpdateNotRequested,
2292 },
2293 {
2294 testType: serverTest,
2295 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002296 config: Config{
2297 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002298 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002299 sendKeyUpdates: 1,
2300 keyUpdateRequest: keyUpdateNotRequested,
2301 },
2302 {
2303 name: "KeyUpdate-InvalidRequestMode",
2304 config: Config{
2305 MaxVersion: VersionTLS13,
2306 },
2307 sendKeyUpdates: 1,
2308 keyUpdateRequest: 42,
2309 shouldFail: true,
2310 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002311 },
David Benjaminabe94e32016-09-04 14:18:58 -04002312 {
2313 name: "SendSNIWarningAlert",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 SendSNIWarningAlert: true,
2318 },
2319 },
2320 },
David Benjaminc241d792016-09-09 10:34:20 -04002321 {
2322 testType: serverTest,
2323 name: "ExtraCompressionMethods-TLS12",
2324 config: Config{
2325 MaxVersion: VersionTLS12,
2326 Bugs: ProtocolBugs{
2327 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2328 },
2329 },
2330 },
2331 {
2332 testType: serverTest,
2333 name: "ExtraCompressionMethods-TLS13",
2334 config: Config{
2335 MaxVersion: VersionTLS13,
2336 Bugs: ProtocolBugs{
2337 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2338 },
2339 },
2340 shouldFail: true,
2341 expectedError: ":INVALID_COMPRESSION_LIST:",
2342 expectedLocalError: "remote error: illegal parameter",
2343 },
2344 {
2345 testType: serverTest,
2346 name: "NoNullCompression-TLS12",
2347 config: Config{
2348 MaxVersion: VersionTLS12,
2349 Bugs: ProtocolBugs{
2350 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2351 },
2352 },
2353 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002354 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002355 expectedLocalError: "remote error: illegal parameter",
2356 },
2357 {
2358 testType: serverTest,
2359 name: "NoNullCompression-TLS13",
2360 config: Config{
2361 MaxVersion: VersionTLS13,
2362 Bugs: ProtocolBugs{
2363 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2364 },
2365 },
2366 shouldFail: true,
2367 expectedError: ":INVALID_COMPRESSION_LIST:",
2368 expectedLocalError: "remote error: illegal parameter",
2369 },
David Benjamin65ac9972016-09-02 21:35:25 -04002370 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002371 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002372 config: Config{
2373 MaxVersion: VersionTLS12,
2374 Bugs: ProtocolBugs{
2375 ExpectGREASE: true,
2376 },
2377 },
2378 flags: []string{"-enable-grease"},
2379 },
2380 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002381 name: "GREASE-Client-TLS13",
2382 config: Config{
2383 MaxVersion: VersionTLS13,
2384 Bugs: ProtocolBugs{
2385 ExpectGREASE: true,
2386 },
2387 },
2388 flags: []string{"-enable-grease"},
2389 },
2390 {
2391 testType: serverTest,
2392 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002393 config: Config{
2394 MaxVersion: VersionTLS13,
2395 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002396 // TLS 1.3 servers are expected to
2397 // always enable GREASE. TLS 1.3 is new,
2398 // so there is no existing ecosystem to
2399 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002400 ExpectGREASE: true,
2401 },
2402 },
David Benjamin65ac9972016-09-02 21:35:25 -04002403 },
David Benjamine3fbb362017-01-06 16:19:28 -05002404 {
2405 // Test the server so there is a large certificate as
2406 // well as application data.
2407 testType: serverTest,
2408 name: "MaxSendFragment",
2409 config: Config{
2410 Bugs: ProtocolBugs{
2411 MaxReceivePlaintext: 512,
2412 },
2413 },
2414 messageLen: 1024,
2415 flags: []string{
2416 "-max-send-fragment", "512",
2417 "-read-size", "1024",
2418 },
2419 },
2420 {
2421 // Test the server so there is a large certificate as
2422 // well as application data.
2423 testType: serverTest,
2424 name: "MaxSendFragment-TooLarge",
2425 config: Config{
2426 Bugs: ProtocolBugs{
2427 // Ensure that some of the records are
2428 // 512.
2429 MaxReceivePlaintext: 511,
2430 },
2431 },
2432 messageLen: 1024,
2433 flags: []string{
2434 "-max-send-fragment", "512",
2435 "-read-size", "1024",
2436 },
2437 shouldFail: true,
2438 expectedLocalError: "local error: record overflow",
2439 },
Adam Langley7c803a62015-06-15 15:35:05 -07002440 }
Adam Langley7c803a62015-06-15 15:35:05 -07002441 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002442
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002443 if *includeDHE {
2444 testCases = append(testCases, testCase{
2445 name: "NoFalseStart-DHE_RSA",
2446 config: Config{
2447 MaxVersion: VersionTLS12,
2448 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2449 NextProtos: []string{"foo"},
2450 Bugs: ProtocolBugs{
2451 ExpectFalseStart: true,
2452 AlertBeforeFalseStartTest: alertAccessDenied,
2453 },
2454 },
2455 flags: []string{
2456 "-false-start",
2457 "-advertise-alpn", "\x03foo",
2458 },
2459 shimWritesFirst: true,
2460 shouldFail: true,
2461 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
2462 expectedLocalError: "tls: peer did not false start: EOF",
2463 })
2464 }
2465
David Benjamina252b342016-09-26 19:57:53 -04002466 // Test that very large messages can be received.
2467 cert := rsaCertificate
2468 for i := 0; i < 50; i++ {
2469 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2470 }
2471 testCases = append(testCases, testCase{
2472 name: "LargeMessage",
2473 config: Config{
2474 Certificates: []Certificate{cert},
2475 },
2476 })
2477 testCases = append(testCases, testCase{
2478 protocol: dtls,
2479 name: "LargeMessage-DTLS",
2480 config: Config{
2481 Certificates: []Certificate{cert},
2482 },
2483 })
2484
2485 // They are rejected if the maximum certificate chain length is capped.
2486 testCases = append(testCases, testCase{
2487 name: "LargeMessage-Reject",
2488 config: Config{
2489 Certificates: []Certificate{cert},
2490 },
2491 flags: []string{"-max-cert-list", "16384"},
2492 shouldFail: true,
2493 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2494 })
2495 testCases = append(testCases, testCase{
2496 protocol: dtls,
2497 name: "LargeMessage-Reject-DTLS",
2498 config: Config{
2499 Certificates: []Certificate{cert},
2500 },
2501 flags: []string{"-max-cert-list", "16384"},
2502 shouldFail: true,
2503 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2504 })
Adam Langley7c803a62015-06-15 15:35:05 -07002505}
2506
David Benjaminaa012042016-12-10 13:33:05 -05002507func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2508 const psk = "12345"
2509 const pskIdentity = "luggage combo"
2510
2511 var prefix string
2512 if protocol == dtls {
2513 if !ver.hasDTLS {
2514 return
2515 }
2516 prefix = "D"
2517 }
2518
2519 var cert Certificate
2520 var certFile string
2521 var keyFile string
2522 if hasComponent(suite.name, "ECDSA") {
2523 cert = ecdsaP256Certificate
2524 certFile = ecdsaP256CertificateFile
2525 keyFile = ecdsaP256KeyFile
2526 } else {
2527 cert = rsaCertificate
2528 certFile = rsaCertificateFile
2529 keyFile = rsaKeyFile
2530 }
2531
2532 var flags []string
2533 if hasComponent(suite.name, "PSK") {
2534 flags = append(flags,
2535 "-psk", psk,
2536 "-psk-identity", pskIdentity)
2537 }
2538 if hasComponent(suite.name, "NULL") {
2539 // NULL ciphers must be explicitly enabled.
2540 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2541 }
David Benjaminaa012042016-12-10 13:33:05 -05002542
2543 var shouldServerFail, shouldClientFail bool
2544 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2545 // BoringSSL clients accept ECDHE on SSLv3, but
2546 // a BoringSSL server will never select it
2547 // because the extension is missing.
2548 shouldServerFail = true
2549 }
2550 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2551 shouldClientFail = true
2552 shouldServerFail = true
2553 }
2554 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2555 shouldClientFail = true
2556 shouldServerFail = true
2557 }
2558 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2559 shouldClientFail = true
2560 shouldServerFail = true
2561 }
2562 if !isDTLSCipher(suite.name) && protocol == dtls {
2563 shouldClientFail = true
2564 shouldServerFail = true
2565 }
2566
2567 var sendCipherSuite uint16
2568 var expectedServerError, expectedClientError string
2569 serverCipherSuites := []uint16{suite.id}
2570 if shouldServerFail {
2571 expectedServerError = ":NO_SHARED_CIPHER:"
2572 }
2573 if shouldClientFail {
2574 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2575 // Configure the server to select ciphers as normal but
2576 // select an incompatible cipher in ServerHello.
2577 serverCipherSuites = nil
2578 sendCipherSuite = suite.id
2579 }
2580
David Benjamincdb6fe92017-02-07 16:06:48 -05002581 // For cipher suites and versions where exporters are defined, verify
2582 // that they interoperate.
2583 var exportKeyingMaterial int
2584 if ver.version > VersionSSL30 {
2585 exportKeyingMaterial = 1024
2586 }
2587
David Benjaminaa012042016-12-10 13:33:05 -05002588 testCases = append(testCases, testCase{
2589 testType: serverTest,
2590 protocol: protocol,
2591 name: prefix + ver.name + "-" + suite.name + "-server",
2592 config: Config{
2593 MinVersion: ver.version,
2594 MaxVersion: ver.version,
2595 CipherSuites: []uint16{suite.id},
2596 Certificates: []Certificate{cert},
2597 PreSharedKey: []byte(psk),
2598 PreSharedKeyIdentity: pskIdentity,
2599 Bugs: ProtocolBugs{
2600 AdvertiseAllConfiguredCiphers: true,
2601 },
2602 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002603 certFile: certFile,
2604 keyFile: keyFile,
2605 flags: flags,
2606 resumeSession: true,
2607 shouldFail: shouldServerFail,
2608 expectedError: expectedServerError,
2609 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002610 })
2611
2612 testCases = append(testCases, testCase{
2613 testType: clientTest,
2614 protocol: protocol,
2615 name: prefix + ver.name + "-" + suite.name + "-client",
2616 config: Config{
2617 MinVersion: ver.version,
2618 MaxVersion: ver.version,
2619 CipherSuites: serverCipherSuites,
2620 Certificates: []Certificate{cert},
2621 PreSharedKey: []byte(psk),
2622 PreSharedKeyIdentity: pskIdentity,
2623 Bugs: ProtocolBugs{
2624 IgnorePeerCipherPreferences: shouldClientFail,
2625 SendCipherSuite: sendCipherSuite,
2626 },
2627 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002628 flags: flags,
2629 resumeSession: true,
2630 shouldFail: shouldClientFail,
2631 expectedError: expectedClientError,
2632 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002633 })
2634
David Benjamin6f600d62016-12-21 16:06:54 -05002635 if shouldClientFail {
2636 return
2637 }
2638
2639 // Ensure the maximum record size is accepted.
2640 testCases = append(testCases, testCase{
2641 protocol: protocol,
2642 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2643 config: Config{
2644 MinVersion: ver.version,
2645 MaxVersion: ver.version,
2646 CipherSuites: []uint16{suite.id},
2647 Certificates: []Certificate{cert},
2648 PreSharedKey: []byte(psk),
2649 PreSharedKeyIdentity: pskIdentity,
2650 },
2651 flags: flags,
2652 messageLen: maxPlaintext,
2653 })
2654
2655 // Test bad records for all ciphers. Bad records are fatal in TLS
2656 // and ignored in DTLS.
2657 var shouldFail bool
2658 var expectedError string
2659 if protocol == tls {
2660 shouldFail = true
2661 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2662 }
2663
2664 testCases = append(testCases, testCase{
2665 protocol: protocol,
2666 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2667 config: Config{
2668 MinVersion: ver.version,
2669 MaxVersion: ver.version,
2670 CipherSuites: []uint16{suite.id},
2671 Certificates: []Certificate{cert},
2672 PreSharedKey: []byte(psk),
2673 PreSharedKeyIdentity: pskIdentity,
2674 },
2675 flags: flags,
2676 damageFirstWrite: true,
2677 messageLen: maxPlaintext,
2678 shouldFail: shouldFail,
2679 expectedError: expectedError,
2680 })
David Benjaminaa012042016-12-10 13:33:05 -05002681}
2682
Adam Langley95c29f32014-06-20 12:00:00 -07002683func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002684 const bogusCipher = 0xfe00
2685
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002686 if *includeDHE {
2687 testCipherSuites = append(testCipherSuites, []testCipherSuite{
2688 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2689 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
2690 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
2691 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
2692 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
2693 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
2694 }...)
2695 }
2696
Adam Langley95c29f32014-06-20 12:00:00 -07002697 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002698 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002699 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002700 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002701 }
David Benjamin2c99d282015-09-01 10:23:00 -04002702 }
Adam Langley95c29f32014-06-20 12:00:00 -07002703 }
Adam Langleya7997f12015-05-14 17:38:50 -07002704
2705 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002706 name: "NoSharedCipher",
2707 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002708 MaxVersion: VersionTLS12,
2709 CipherSuites: []uint16{},
2710 },
2711 shouldFail: true,
2712 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2713 })
2714
2715 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002716 name: "NoSharedCipher-TLS13",
2717 config: Config{
2718 MaxVersion: VersionTLS13,
2719 CipherSuites: []uint16{},
2720 },
2721 shouldFail: true,
2722 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2723 })
2724
2725 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002726 name: "UnsupportedCipherSuite",
2727 config: Config{
2728 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002729 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002730 Bugs: ProtocolBugs{
2731 IgnorePeerCipherPreferences: true,
2732 },
2733 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002734 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002735 shouldFail: true,
2736 expectedError: ":WRONG_CIPHER_RETURNED:",
2737 })
2738
2739 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002740 name: "ServerHelloBogusCipher",
2741 config: Config{
2742 MaxVersion: VersionTLS12,
2743 Bugs: ProtocolBugs{
2744 SendCipherSuite: bogusCipher,
2745 },
2746 },
2747 shouldFail: true,
2748 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2749 })
2750 testCases = append(testCases, testCase{
2751 name: "ServerHelloBogusCipher-TLS13",
2752 config: Config{
2753 MaxVersion: VersionTLS13,
2754 Bugs: ProtocolBugs{
2755 SendCipherSuite: bogusCipher,
2756 },
2757 },
2758 shouldFail: true,
2759 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2760 })
2761
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002762 if *includeDHE {
2763 testCases = append(testCases, testCase{
2764 name: "WeakDH",
2765 config: Config{
2766 MaxVersion: VersionTLS12,
2767 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2768 Bugs: ProtocolBugs{
2769 // This is a 1023-bit prime number, generated
2770 // with:
2771 // openssl gendh 1023 | openssl asn1parse -i
2772 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2773 },
Adam Langleya7997f12015-05-14 17:38:50 -07002774 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002775 shouldFail: true,
2776 expectedError: ":BAD_DH_P_LENGTH:",
2777 })
Adam Langleycef75832015-09-03 14:51:12 -07002778
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002779 testCases = append(testCases, testCase{
2780 name: "SillyDH",
2781 config: Config{
2782 MaxVersion: VersionTLS12,
2783 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2784 Bugs: ProtocolBugs{
2785 // This is a 4097-bit prime number, generated
2786 // with:
2787 // openssl gendh 4097 | openssl asn1parse -i
2788 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2789 },
David Benjamincd24a392015-11-11 13:23:05 -08002790 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002791 shouldFail: true,
2792 expectedError: ":DH_P_TOO_LONG:",
2793 })
David Benjamincd24a392015-11-11 13:23:05 -08002794
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002795 // This test ensures that Diffie-Hellman public values are padded with
2796 // zeros so that they're the same length as the prime. This is to avoid
2797 // hitting a bug in yaSSL.
2798 testCases = append(testCases, testCase{
2799 testType: serverTest,
2800 name: "DHPublicValuePadded",
2801 config: Config{
2802 MaxVersion: VersionTLS12,
2803 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2804 Bugs: ProtocolBugs{
2805 RequireDHPublicValueLen: (1025 + 7) / 8,
2806 },
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002807 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07002808 flags: []string{"-use-sparse-dh-prime"},
2809 })
2810 }
David Benjamincd24a392015-11-11 13:23:05 -08002811
David Benjamin241ae832016-01-15 03:04:54 -05002812 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002813 testCases = append(testCases, testCase{
2814 testType: serverTest,
2815 name: "UnknownCipher",
2816 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002817 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002818 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002819 Bugs: ProtocolBugs{
2820 AdvertiseAllConfiguredCiphers: true,
2821 },
2822 },
2823 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002824
2825 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002826 testCases = append(testCases, testCase{
2827 testType: serverTest,
2828 name: "UnknownCipher-TLS13",
2829 config: Config{
2830 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002831 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002832 Bugs: ProtocolBugs{
2833 AdvertiseAllConfiguredCiphers: true,
2834 },
David Benjamin241ae832016-01-15 03:04:54 -05002835 },
2836 })
2837
David Benjamin78679342016-09-16 19:42:05 -04002838 // Test empty ECDHE_PSK identity hints work as expected.
2839 testCases = append(testCases, testCase{
2840 name: "EmptyECDHEPSKHint",
2841 config: Config{
2842 MaxVersion: VersionTLS12,
2843 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2844 PreSharedKey: []byte("secret"),
2845 },
2846 flags: []string{"-psk", "secret"},
2847 })
2848
2849 // Test empty PSK identity hints work as expected, even if an explicit
2850 // ServerKeyExchange is sent.
2851 testCases = append(testCases, testCase{
2852 name: "ExplicitEmptyPSKHint",
2853 config: Config{
2854 MaxVersion: VersionTLS12,
2855 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2856 PreSharedKey: []byte("secret"),
2857 Bugs: ProtocolBugs{
2858 AlwaysSendPreSharedKeyIdentityHint: true,
2859 },
2860 },
2861 flags: []string{"-psk", "secret"},
2862 })
Adam Langley95c29f32014-06-20 12:00:00 -07002863}
2864
2865func addBadECDSASignatureTests() {
2866 for badR := BadValue(1); badR < NumBadValues; badR++ {
2867 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002868 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002869 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2870 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002871 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002872 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002873 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002874 Bugs: ProtocolBugs{
2875 BadECDSAR: badR,
2876 BadECDSAS: badS,
2877 },
2878 },
2879 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002880 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002881 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002882 testCases = append(testCases, testCase{
2883 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2884 config: Config{
2885 MaxVersion: VersionTLS13,
2886 Certificates: []Certificate{ecdsaP256Certificate},
2887 Bugs: ProtocolBugs{
2888 BadECDSAR: badR,
2889 BadECDSAS: badS,
2890 },
2891 },
2892 shouldFail: true,
2893 expectedError: ":BAD_SIGNATURE:",
2894 })
Adam Langley95c29f32014-06-20 12:00:00 -07002895 }
2896 }
2897}
2898
Adam Langley80842bd2014-06-20 12:00:00 -07002899func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002900 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002901 name: "MaxCBCPadding",
2902 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002903 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002904 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2905 Bugs: ProtocolBugs{
2906 MaxPadding: true,
2907 },
2908 },
2909 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2910 })
David Benjamin025b3d32014-07-01 19:53:04 -04002911 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002912 name: "BadCBCPadding",
2913 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002914 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2916 Bugs: ProtocolBugs{
2917 PaddingFirstByteBad: true,
2918 },
2919 },
2920 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002921 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002922 })
2923 // OpenSSL previously had an issue where the first byte of padding in
2924 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002925 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002926 name: "BadCBCPadding255",
2927 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002928 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002929 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2930 Bugs: ProtocolBugs{
2931 MaxPadding: true,
2932 PaddingFirstByteBadIf255: true,
2933 },
2934 },
2935 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
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}
2940
Kenny Root7fdeaf12014-08-05 15:23:37 -07002941func addCBCSplittingTests() {
2942 testCases = append(testCases, testCase{
2943 name: "CBCRecordSplitting",
2944 config: Config{
2945 MaxVersion: VersionTLS10,
2946 MinVersion: VersionTLS10,
2947 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2948 },
David Benjaminac8302a2015-09-01 17:18:15 -04002949 messageLen: -1, // read until EOF
2950 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002951 flags: []string{
2952 "-async",
2953 "-write-different-record-sizes",
2954 "-cbc-record-splitting",
2955 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002956 })
2957 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002958 name: "CBCRecordSplittingPartialWrite",
2959 config: Config{
2960 MaxVersion: VersionTLS10,
2961 MinVersion: VersionTLS10,
2962 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2963 },
2964 messageLen: -1, // read until EOF
2965 flags: []string{
2966 "-async",
2967 "-write-different-record-sizes",
2968 "-cbc-record-splitting",
2969 "-partial-write",
2970 },
2971 })
2972}
2973
David Benjamin636293b2014-07-08 17:59:18 -04002974func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002975 // Add a dummy cert pool to stress certificate authority parsing.
David Benjamin407a10c2014-07-16 12:58:59 -04002976 certPool := x509.NewCertPool()
Adam Langley2ff79332017-02-28 13:45:39 -08002977 for _, cert := range []Certificate{rsaCertificate, rsa1024Certificate} {
2978 cert, err := x509.ParseCertificate(cert.Certificate[0])
2979 if err != nil {
2980 panic(err)
2981 }
2982 certPool.AddCert(cert)
David Benjamin407a10c2014-07-16 12:58:59 -04002983 }
Adam Langley2ff79332017-02-28 13:45:39 -08002984 caNames := certPool.Subjects()
David Benjamin407a10c2014-07-16 12:58:59 -04002985
David Benjamin636293b2014-07-08 17:59:18 -04002986 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002987 testCases = append(testCases, testCase{
2988 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002989 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002990 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002991 MinVersion: ver.version,
2992 MaxVersion: ver.version,
2993 ClientAuth: RequireAnyClientCert,
2994 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002995 },
2996 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002997 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2998 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002999 },
3000 })
3001 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003002 testType: serverTest,
3003 name: ver.name + "-Server-ClientAuth-RSA",
3004 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003005 MinVersion: ver.version,
3006 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003007 Certificates: []Certificate{rsaCertificate},
3008 },
3009 flags: []string{"-require-any-client-certificate"},
3010 })
David Benjamine098ec22014-08-27 23:13:20 -04003011 if ver.version != VersionSSL30 {
3012 testCases = append(testCases, testCase{
3013 testType: serverTest,
3014 name: ver.name + "-Server-ClientAuth-ECDSA",
3015 config: Config{
3016 MinVersion: ver.version,
3017 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003018 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003019 },
3020 flags: []string{"-require-any-client-certificate"},
3021 })
3022 testCases = append(testCases, testCase{
3023 testType: clientTest,
3024 name: ver.name + "-Client-ClientAuth-ECDSA",
3025 config: Config{
3026 MinVersion: ver.version,
3027 MaxVersion: ver.version,
3028 ClientAuth: RequireAnyClientCert,
3029 ClientCAs: certPool,
3030 },
3031 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003032 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3033 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003034 },
3035 })
3036 }
Adam Langley37646832016-08-01 16:16:46 -07003037
3038 testCases = append(testCases, testCase{
3039 name: "NoClientCertificate-" + ver.name,
3040 config: Config{
3041 MinVersion: ver.version,
3042 MaxVersion: ver.version,
3043 ClientAuth: RequireAnyClientCert,
3044 },
3045 shouldFail: true,
3046 expectedLocalError: "client didn't provide a certificate",
3047 })
3048
3049 testCases = append(testCases, testCase{
3050 // Even if not configured to expect a certificate, OpenSSL will
3051 // return X509_V_OK as the verify_result.
3052 testType: serverTest,
3053 name: "NoClientCertificateRequested-Server-" + ver.name,
3054 config: Config{
3055 MinVersion: ver.version,
3056 MaxVersion: ver.version,
3057 },
3058 flags: []string{
3059 "-expect-verify-result",
3060 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003061 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003062 })
3063
3064 testCases = append(testCases, testCase{
3065 // If a client certificate is not provided, OpenSSL will still
3066 // return X509_V_OK as the verify_result.
3067 testType: serverTest,
3068 name: "NoClientCertificate-Server-" + ver.name,
3069 config: Config{
3070 MinVersion: ver.version,
3071 MaxVersion: ver.version,
3072 },
3073 flags: []string{
3074 "-expect-verify-result",
3075 "-verify-peer",
3076 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003077 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003078 })
3079
David Benjamin1db9e1b2016-10-07 20:51:43 -04003080 certificateRequired := "remote error: certificate required"
3081 if ver.version < VersionTLS13 {
3082 // Prior to TLS 1.3, the generic handshake_failure alert
3083 // was used.
3084 certificateRequired = "remote error: handshake failure"
3085 }
Adam Langley37646832016-08-01 16:16:46 -07003086 testCases = append(testCases, testCase{
3087 testType: serverTest,
3088 name: "RequireAnyClientCertificate-" + ver.name,
3089 config: Config{
3090 MinVersion: ver.version,
3091 MaxVersion: ver.version,
3092 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003093 flags: []string{"-require-any-client-certificate"},
3094 shouldFail: true,
3095 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3096 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003097 })
3098
3099 if ver.version != VersionSSL30 {
3100 testCases = append(testCases, testCase{
3101 testType: serverTest,
3102 name: "SkipClientCertificate-" + ver.name,
3103 config: Config{
3104 MinVersion: ver.version,
3105 MaxVersion: ver.version,
3106 Bugs: ProtocolBugs{
3107 SkipClientCertificate: true,
3108 },
3109 },
3110 // Setting SSL_VERIFY_PEER allows anonymous clients.
3111 flags: []string{"-verify-peer"},
3112 shouldFail: true,
3113 expectedError: ":UNEXPECTED_MESSAGE:",
3114 })
3115 }
Adam Langley2ff79332017-02-28 13:45:39 -08003116
3117 testCases = append(testCases, testCase{
3118 testType: serverTest,
3119 name: ver.name + "-Server-CertReq-CA-List",
3120 config: Config{
3121 MinVersion: ver.version,
3122 MaxVersion: ver.version,
3123 Certificates: []Certificate{rsaCertificate},
3124 Bugs: ProtocolBugs{
3125 ExpectCertificateReqNames: caNames,
3126 },
3127 },
3128 flags: []string{
3129 "-require-any-client-certificate",
3130 "-use-client-ca-list", encodeDERValues(caNames),
3131 },
3132 })
3133
3134 testCases = append(testCases, testCase{
3135 testType: clientTest,
3136 name: ver.name + "-Client-CertReq-CA-List",
3137 config: Config{
3138 MinVersion: ver.version,
3139 MaxVersion: ver.version,
3140 Certificates: []Certificate{rsaCertificate},
3141 ClientAuth: RequireAnyClientCert,
3142 ClientCAs: certPool,
3143 },
3144 flags: []string{
3145 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3146 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3147 "-expect-client-ca-list", encodeDERValues(caNames),
3148 },
3149 })
David Benjamin636293b2014-07-08 17:59:18 -04003150 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003151
David Benjaminc032dfa2016-05-12 14:54:57 -04003152 // Client auth is only legal in certificate-based ciphers.
3153 testCases = append(testCases, testCase{
3154 testType: clientTest,
3155 name: "ClientAuth-PSK",
3156 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003157 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003158 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3159 PreSharedKey: []byte("secret"),
3160 ClientAuth: RequireAnyClientCert,
3161 },
3162 flags: []string{
3163 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3164 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3165 "-psk", "secret",
3166 },
3167 shouldFail: true,
3168 expectedError: ":UNEXPECTED_MESSAGE:",
3169 })
3170 testCases = append(testCases, testCase{
3171 testType: clientTest,
3172 name: "ClientAuth-ECDHE_PSK",
3173 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003174 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003175 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3176 PreSharedKey: []byte("secret"),
3177 ClientAuth: RequireAnyClientCert,
3178 },
3179 flags: []string{
3180 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3181 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3182 "-psk", "secret",
3183 },
3184 shouldFail: true,
3185 expectedError: ":UNEXPECTED_MESSAGE:",
3186 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003187
3188 // Regression test for a bug where the client CA list, if explicitly
3189 // set to NULL, was mis-encoded.
3190 testCases = append(testCases, testCase{
3191 testType: serverTest,
3192 name: "Null-Client-CA-List",
3193 config: Config{
3194 MaxVersion: VersionTLS12,
3195 Certificates: []Certificate{rsaCertificate},
Adam Langley2ff79332017-02-28 13:45:39 -08003196 Bugs: ProtocolBugs{
3197 ExpectCertificateReqNames: [][]byte{},
3198 },
David Benjamin2f8935d2016-07-13 19:47:39 -04003199 },
3200 flags: []string{
3201 "-require-any-client-certificate",
Adam Langley2ff79332017-02-28 13:45:39 -08003202 "-use-client-ca-list", "<NULL>",
David Benjamin2f8935d2016-07-13 19:47:39 -04003203 },
3204 })
David Benjamin636293b2014-07-08 17:59:18 -04003205}
3206
Adam Langley75712922014-10-10 16:23:43 -07003207func addExtendedMasterSecretTests() {
3208 const expectEMSFlag = "-expect-extended-master-secret"
3209
3210 for _, with := range []bool{false, true} {
3211 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003212 if with {
3213 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003214 }
3215
3216 for _, isClient := range []bool{false, true} {
3217 suffix := "-Server"
3218 testType := serverTest
3219 if isClient {
3220 suffix = "-Client"
3221 testType = clientTest
3222 }
3223
3224 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003225 // In TLS 1.3, the extension is irrelevant and
3226 // always reports as enabled.
3227 var flags []string
3228 if with || ver.version >= VersionTLS13 {
3229 flags = []string{expectEMSFlag}
3230 }
3231
Adam Langley75712922014-10-10 16:23:43 -07003232 test := testCase{
3233 testType: testType,
3234 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3235 config: Config{
3236 MinVersion: ver.version,
3237 MaxVersion: ver.version,
3238 Bugs: ProtocolBugs{
3239 NoExtendedMasterSecret: !with,
3240 RequireExtendedMasterSecret: with,
3241 },
3242 },
David Benjamin48cae082014-10-27 01:06:24 -04003243 flags: flags,
3244 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003245 }
3246 if test.shouldFail {
3247 test.expectedLocalError = "extended master secret required but not supported by peer"
3248 }
3249 testCases = append(testCases, test)
3250 }
3251 }
3252 }
3253
Adam Langleyba5934b2015-06-02 10:50:35 -07003254 for _, isClient := range []bool{false, true} {
3255 for _, supportedInFirstConnection := range []bool{false, true} {
3256 for _, supportedInResumeConnection := range []bool{false, true} {
3257 boolToWord := func(b bool) string {
3258 if b {
3259 return "Yes"
3260 }
3261 return "No"
3262 }
3263 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3264 if isClient {
3265 suffix += "Client"
3266 } else {
3267 suffix += "Server"
3268 }
3269
3270 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003271 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003272 Bugs: ProtocolBugs{
3273 RequireExtendedMasterSecret: true,
3274 },
3275 }
3276
3277 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003278 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003279 Bugs: ProtocolBugs{
3280 NoExtendedMasterSecret: true,
3281 },
3282 }
3283
3284 test := testCase{
3285 name: "ExtendedMasterSecret-" + suffix,
3286 resumeSession: true,
3287 }
3288
3289 if !isClient {
3290 test.testType = serverTest
3291 }
3292
3293 if supportedInFirstConnection {
3294 test.config = supportedConfig
3295 } else {
3296 test.config = noSupportConfig
3297 }
3298
3299 if supportedInResumeConnection {
3300 test.resumeConfig = &supportedConfig
3301 } else {
3302 test.resumeConfig = &noSupportConfig
3303 }
3304
3305 switch suffix {
3306 case "YesToYes-Client", "YesToYes-Server":
3307 // When a session is resumed, it should
3308 // still be aware that its master
3309 // secret was generated via EMS and
3310 // thus it's safe to use tls-unique.
3311 test.flags = []string{expectEMSFlag}
3312 case "NoToYes-Server":
3313 // If an original connection did not
3314 // contain EMS, but a resumption
3315 // handshake does, then a server should
3316 // not resume the session.
3317 test.expectResumeRejected = true
3318 case "YesToNo-Server":
3319 // Resuming an EMS session without the
3320 // EMS extension should cause the
3321 // server to abort the connection.
3322 test.shouldFail = true
3323 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3324 case "NoToYes-Client":
3325 // A client should abort a connection
3326 // where the server resumed a non-EMS
3327 // session but echoed the EMS
3328 // extension.
3329 test.shouldFail = true
3330 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3331 case "YesToNo-Client":
3332 // A client should abort a connection
3333 // where the server didn't echo EMS
3334 // when the session used it.
3335 test.shouldFail = true
3336 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3337 }
3338
3339 testCases = append(testCases, test)
3340 }
3341 }
3342 }
David Benjamin163c9562016-08-29 23:14:17 -04003343
3344 // Switching EMS on renegotiation is forbidden.
3345 testCases = append(testCases, testCase{
3346 name: "ExtendedMasterSecret-Renego-NoEMS",
3347 config: Config{
3348 MaxVersion: VersionTLS12,
3349 Bugs: ProtocolBugs{
3350 NoExtendedMasterSecret: true,
3351 NoExtendedMasterSecretOnRenegotiation: true,
3352 },
3353 },
3354 renegotiate: 1,
3355 flags: []string{
3356 "-renegotiate-freely",
3357 "-expect-total-renegotiations", "1",
3358 },
3359 })
3360
3361 testCases = append(testCases, testCase{
3362 name: "ExtendedMasterSecret-Renego-Upgrade",
3363 config: Config{
3364 MaxVersion: VersionTLS12,
3365 Bugs: ProtocolBugs{
3366 NoExtendedMasterSecret: true,
3367 },
3368 },
3369 renegotiate: 1,
3370 flags: []string{
3371 "-renegotiate-freely",
3372 "-expect-total-renegotiations", "1",
3373 },
3374 shouldFail: true,
3375 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3376 })
3377
3378 testCases = append(testCases, testCase{
3379 name: "ExtendedMasterSecret-Renego-Downgrade",
3380 config: Config{
3381 MaxVersion: VersionTLS12,
3382 Bugs: ProtocolBugs{
3383 NoExtendedMasterSecretOnRenegotiation: true,
3384 },
3385 },
3386 renegotiate: 1,
3387 flags: []string{
3388 "-renegotiate-freely",
3389 "-expect-total-renegotiations", "1",
3390 },
3391 shouldFail: true,
3392 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3393 })
Adam Langley75712922014-10-10 16:23:43 -07003394}
3395
David Benjamin582ba042016-07-07 12:33:25 -07003396type stateMachineTestConfig struct {
3397 protocol protocol
3398 async bool
3399 splitHandshake, packHandshakeFlight bool
3400}
3401
David Benjamin43ec06f2014-08-05 02:28:57 -04003402// Adds tests that try to cover the range of the handshake state machine, under
3403// various conditions. Some of these are redundant with other tests, but they
3404// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003405func addAllStateMachineCoverageTests() {
3406 for _, async := range []bool{false, true} {
3407 for _, protocol := range []protocol{tls, dtls} {
3408 addStateMachineCoverageTests(stateMachineTestConfig{
3409 protocol: protocol,
3410 async: async,
3411 })
3412 addStateMachineCoverageTests(stateMachineTestConfig{
3413 protocol: protocol,
3414 async: async,
3415 splitHandshake: true,
3416 })
3417 if protocol == tls {
3418 addStateMachineCoverageTests(stateMachineTestConfig{
3419 protocol: protocol,
3420 async: async,
3421 packHandshakeFlight: true,
3422 })
3423 }
3424 }
3425 }
3426}
3427
3428func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003429 var tests []testCase
3430
3431 // Basic handshake, with resumption. Client and server,
3432 // session ID and session ticket.
3433 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003434 name: "Basic-Client",
3435 config: Config{
3436 MaxVersion: VersionTLS12,
3437 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003438 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003439 // Ensure session tickets are used, not session IDs.
3440 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003441 })
3442 tests = append(tests, testCase{
3443 name: "Basic-Client-RenewTicket",
3444 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003445 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003446 Bugs: ProtocolBugs{
3447 RenewTicketOnResume: true,
3448 },
3449 },
David Benjamin46662482016-08-17 00:51:00 -04003450 flags: []string{"-expect-ticket-renewal"},
3451 resumeSession: true,
3452 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003453 })
3454 tests = append(tests, testCase{
3455 name: "Basic-Client-NoTicket",
3456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003457 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003458 SessionTicketsDisabled: true,
3459 },
3460 resumeSession: true,
3461 })
3462 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003463 name: "Basic-Client-Implicit",
3464 config: Config{
3465 MaxVersion: VersionTLS12,
3466 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003467 flags: []string{"-implicit-handshake"},
3468 resumeSession: true,
3469 })
3470 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003471 testType: serverTest,
3472 name: "Basic-Server",
3473 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003474 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003475 Bugs: ProtocolBugs{
3476 RequireSessionTickets: true,
3477 },
3478 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003479 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003480 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003481 })
3482 tests = append(tests, testCase{
3483 testType: serverTest,
3484 name: "Basic-Server-NoTickets",
3485 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003486 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003487 SessionTicketsDisabled: true,
3488 },
3489 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003490 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003491 })
3492 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003493 testType: serverTest,
3494 name: "Basic-Server-Implicit",
3495 config: Config{
3496 MaxVersion: VersionTLS12,
3497 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003498 flags: []string{"-implicit-handshake"},
3499 resumeSession: true,
3500 })
3501 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003502 testType: serverTest,
3503 name: "Basic-Server-EarlyCallback",
3504 config: Config{
3505 MaxVersion: VersionTLS12,
3506 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003507 flags: []string{"-use-early-callback"},
3508 resumeSession: true,
3509 })
3510
Steven Valdez143e8b32016-07-11 13:19:03 -04003511 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003512 if config.protocol == tls {
3513 tests = append(tests, testCase{
3514 name: "TLS13-1RTT-Client",
3515 config: Config{
3516 MaxVersion: VersionTLS13,
3517 MinVersion: VersionTLS13,
3518 },
David Benjamin46662482016-08-17 00:51:00 -04003519 resumeSession: true,
3520 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003521 })
3522
3523 tests = append(tests, testCase{
3524 testType: serverTest,
3525 name: "TLS13-1RTT-Server",
3526 config: Config{
3527 MaxVersion: VersionTLS13,
3528 MinVersion: VersionTLS13,
3529 },
David Benjamin46662482016-08-17 00:51:00 -04003530 resumeSession: true,
3531 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003532 // TLS 1.3 uses tickets, so the session should not be
3533 // cached statefully.
3534 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003535 })
3536
3537 tests = append(tests, testCase{
3538 name: "TLS13-HelloRetryRequest-Client",
3539 config: Config{
3540 MaxVersion: VersionTLS13,
3541 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003542 // P-384 requires a HelloRetryRequest against BoringSSL's default
3543 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003544 CurvePreferences: []CurveID{CurveP384},
3545 Bugs: ProtocolBugs{
3546 ExpectMissingKeyShare: true,
3547 },
3548 },
3549 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3550 resumeSession: true,
3551 })
3552
3553 tests = append(tests, testCase{
3554 testType: serverTest,
3555 name: "TLS13-HelloRetryRequest-Server",
3556 config: Config{
3557 MaxVersion: VersionTLS13,
3558 MinVersion: VersionTLS13,
3559 // Require a HelloRetryRequest for every curve.
3560 DefaultCurves: []CurveID{},
3561 },
3562 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3563 resumeSession: true,
3564 })
3565 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003566
David Benjamin760b1dd2015-05-15 23:33:48 -04003567 // TLS client auth.
3568 tests = append(tests, testCase{
3569 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003570 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003572 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003573 ClientAuth: RequestClientCert,
3574 },
3575 })
3576 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003577 testType: serverTest,
3578 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003579 config: Config{
3580 MaxVersion: VersionTLS12,
3581 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003582 // Setting SSL_VERIFY_PEER allows anonymous clients.
3583 flags: []string{"-verify-peer"},
3584 })
David Benjamin582ba042016-07-07 12:33:25 -07003585 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003586 tests = append(tests, testCase{
3587 testType: clientTest,
3588 name: "ClientAuth-NoCertificate-Client-SSL3",
3589 config: Config{
3590 MaxVersion: VersionSSL30,
3591 ClientAuth: RequestClientCert,
3592 },
3593 })
3594 tests = append(tests, testCase{
3595 testType: serverTest,
3596 name: "ClientAuth-NoCertificate-Server-SSL3",
3597 config: Config{
3598 MaxVersion: VersionSSL30,
3599 },
3600 // Setting SSL_VERIFY_PEER allows anonymous clients.
3601 flags: []string{"-verify-peer"},
3602 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003603 tests = append(tests, testCase{
3604 testType: clientTest,
3605 name: "ClientAuth-NoCertificate-Client-TLS13",
3606 config: Config{
3607 MaxVersion: VersionTLS13,
3608 ClientAuth: RequestClientCert,
3609 },
3610 })
3611 tests = append(tests, testCase{
3612 testType: serverTest,
3613 name: "ClientAuth-NoCertificate-Server-TLS13",
3614 config: Config{
3615 MaxVersion: VersionTLS13,
3616 },
3617 // Setting SSL_VERIFY_PEER allows anonymous clients.
3618 flags: []string{"-verify-peer"},
3619 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003620 }
3621 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003622 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003623 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003624 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003625 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003626 ClientAuth: RequireAnyClientCert,
3627 },
3628 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003629 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3630 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003631 },
3632 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003633 tests = append(tests, testCase{
3634 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003635 name: "ClientAuth-RSA-Client-TLS13",
3636 config: Config{
3637 MaxVersion: VersionTLS13,
3638 ClientAuth: RequireAnyClientCert,
3639 },
3640 flags: []string{
3641 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3642 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3643 },
3644 })
3645 tests = append(tests, testCase{
3646 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003647 name: "ClientAuth-ECDSA-Client",
3648 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003649 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003650 ClientAuth: RequireAnyClientCert,
3651 },
3652 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003653 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3654 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003655 },
3656 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003657 tests = append(tests, testCase{
3658 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003659 name: "ClientAuth-ECDSA-Client-TLS13",
3660 config: Config{
3661 MaxVersion: VersionTLS13,
3662 ClientAuth: RequireAnyClientCert,
3663 },
3664 flags: []string{
3665 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3666 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3667 },
3668 })
3669 tests = append(tests, testCase{
3670 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003671 name: "ClientAuth-NoCertificate-OldCallback",
3672 config: Config{
3673 MaxVersion: VersionTLS12,
3674 ClientAuth: RequestClientCert,
3675 },
3676 flags: []string{"-use-old-client-cert-callback"},
3677 })
3678 tests = append(tests, testCase{
3679 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003680 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3681 config: Config{
3682 MaxVersion: VersionTLS13,
3683 ClientAuth: RequestClientCert,
3684 },
3685 flags: []string{"-use-old-client-cert-callback"},
3686 })
3687 tests = append(tests, testCase{
3688 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003689 name: "ClientAuth-OldCallback",
3690 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003691 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003692 ClientAuth: RequireAnyClientCert,
3693 },
3694 flags: []string{
3695 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3696 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3697 "-use-old-client-cert-callback",
3698 },
3699 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003700 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003701 testType: clientTest,
3702 name: "ClientAuth-OldCallback-TLS13",
3703 config: Config{
3704 MaxVersion: VersionTLS13,
3705 ClientAuth: RequireAnyClientCert,
3706 },
3707 flags: []string{
3708 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3709 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3710 "-use-old-client-cert-callback",
3711 },
3712 })
3713 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003714 testType: serverTest,
3715 name: "ClientAuth-Server",
3716 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003717 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003718 Certificates: []Certificate{rsaCertificate},
3719 },
3720 flags: []string{"-require-any-client-certificate"},
3721 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003722 tests = append(tests, testCase{
3723 testType: serverTest,
3724 name: "ClientAuth-Server-TLS13",
3725 config: Config{
3726 MaxVersion: VersionTLS13,
3727 Certificates: []Certificate{rsaCertificate},
3728 },
3729 flags: []string{"-require-any-client-certificate"},
3730 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003731
David Benjamin4c3ddf72016-06-29 18:13:53 -04003732 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003733 tests = append(tests, testCase{
3734 testType: serverTest,
3735 name: "Basic-Server-RSA",
3736 config: Config{
3737 MaxVersion: VersionTLS12,
3738 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3739 },
3740 flags: []string{
3741 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3742 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3743 },
3744 })
3745 tests = append(tests, testCase{
3746 testType: serverTest,
3747 name: "Basic-Server-ECDHE-RSA",
3748 config: Config{
3749 MaxVersion: VersionTLS12,
3750 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3751 },
3752 flags: []string{
3753 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3754 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3755 },
3756 })
3757 tests = append(tests, testCase{
3758 testType: serverTest,
3759 name: "Basic-Server-ECDHE-ECDSA",
3760 config: Config{
3761 MaxVersion: VersionTLS12,
3762 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3763 },
3764 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003765 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3766 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003767 },
3768 })
3769
David Benjamin760b1dd2015-05-15 23:33:48 -04003770 // No session ticket support; server doesn't send NewSessionTicket.
3771 tests = append(tests, testCase{
3772 name: "SessionTicketsDisabled-Client",
3773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003774 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003775 SessionTicketsDisabled: true,
3776 },
3777 })
3778 tests = append(tests, testCase{
3779 testType: serverTest,
3780 name: "SessionTicketsDisabled-Server",
3781 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003782 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003783 SessionTicketsDisabled: true,
3784 },
3785 })
3786
3787 // Skip ServerKeyExchange in PSK key exchange if there's no
3788 // identity hint.
3789 tests = append(tests, testCase{
3790 name: "EmptyPSKHint-Client",
3791 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003792 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003793 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3794 PreSharedKey: []byte("secret"),
3795 },
3796 flags: []string{"-psk", "secret"},
3797 })
3798 tests = append(tests, testCase{
3799 testType: serverTest,
3800 name: "EmptyPSKHint-Server",
3801 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003802 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003803 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3804 PreSharedKey: []byte("secret"),
3805 },
3806 flags: []string{"-psk", "secret"},
3807 })
3808
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003810 tests = append(tests, testCase{
3811 testType: clientTest,
3812 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003813 config: Config{
3814 MaxVersion: VersionTLS12,
3815 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003816 flags: []string{
3817 "-enable-ocsp-stapling",
3818 "-expect-ocsp-response",
3819 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003820 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003821 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003822 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003823 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003824 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003825 testType: serverTest,
3826 name: "OCSPStapling-Server",
3827 config: Config{
3828 MaxVersion: VersionTLS12,
3829 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003830 expectedOCSPResponse: testOCSPResponse,
3831 flags: []string{
3832 "-ocsp-response",
3833 base64.StdEncoding.EncodeToString(testOCSPResponse),
3834 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003835 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003836 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003837 tests = append(tests, testCase{
3838 testType: clientTest,
3839 name: "OCSPStapling-Client-TLS13",
3840 config: Config{
3841 MaxVersion: VersionTLS13,
3842 },
3843 flags: []string{
3844 "-enable-ocsp-stapling",
3845 "-expect-ocsp-response",
3846 base64.StdEncoding.EncodeToString(testOCSPResponse),
3847 "-verify-peer",
3848 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003849 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003850 })
3851 tests = append(tests, testCase{
3852 testType: serverTest,
3853 name: "OCSPStapling-Server-TLS13",
3854 config: Config{
3855 MaxVersion: VersionTLS13,
3856 },
3857 expectedOCSPResponse: testOCSPResponse,
3858 flags: []string{
3859 "-ocsp-response",
3860 base64.StdEncoding.EncodeToString(testOCSPResponse),
3861 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003862 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003863 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003864
David Benjamin4c3ddf72016-06-29 18:13:53 -04003865 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003866 for _, vers := range tlsVersions {
3867 if config.protocol == dtls && !vers.hasDTLS {
3868 continue
3869 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003870 for _, testType := range []testType{clientTest, serverTest} {
3871 suffix := "-Client"
3872 if testType == serverTest {
3873 suffix = "-Server"
3874 }
3875 suffix += "-" + vers.name
3876
3877 flag := "-verify-peer"
3878 if testType == serverTest {
3879 flag = "-require-any-client-certificate"
3880 }
3881
3882 tests = append(tests, testCase{
3883 testType: testType,
3884 name: "CertificateVerificationSucceed" + suffix,
3885 config: Config{
3886 MaxVersion: vers.version,
3887 Certificates: []Certificate{rsaCertificate},
3888 },
3889 flags: []string{
3890 flag,
3891 "-expect-verify-result",
3892 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003893 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003894 })
3895 tests = append(tests, testCase{
3896 testType: testType,
3897 name: "CertificateVerificationFail" + suffix,
3898 config: Config{
3899 MaxVersion: vers.version,
3900 Certificates: []Certificate{rsaCertificate},
3901 },
3902 flags: []string{
3903 flag,
3904 "-verify-fail",
3905 },
3906 shouldFail: true,
3907 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3908 })
3909 }
3910
3911 // By default, the client is in a soft fail mode where the peer
3912 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003913 tests = append(tests, testCase{
3914 testType: clientTest,
3915 name: "CertificateVerificationSoftFail-" + vers.name,
3916 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003917 MaxVersion: vers.version,
3918 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003919 },
3920 flags: []string{
3921 "-verify-fail",
3922 "-expect-verify-result",
3923 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003924 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003925 })
3926 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003927
David Benjamin1d4f4c02016-07-26 18:03:08 -04003928 tests = append(tests, testCase{
3929 name: "ShimSendAlert",
3930 flags: []string{"-send-alert"},
3931 shimWritesFirst: true,
3932 shouldFail: true,
3933 expectedLocalError: "remote error: decompression failure",
3934 })
3935
David Benjamin582ba042016-07-07 12:33:25 -07003936 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003937 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003938 name: "Renegotiate-Client",
3939 config: Config{
3940 MaxVersion: VersionTLS12,
3941 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003942 renegotiate: 1,
3943 flags: []string{
3944 "-renegotiate-freely",
3945 "-expect-total-renegotiations", "1",
3946 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003947 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003948
David Benjamin47921102016-07-28 11:29:18 -04003949 tests = append(tests, testCase{
3950 name: "SendHalfHelloRequest",
3951 config: Config{
3952 MaxVersion: VersionTLS12,
3953 Bugs: ProtocolBugs{
3954 PackHelloRequestWithFinished: config.packHandshakeFlight,
3955 },
3956 },
3957 sendHalfHelloRequest: true,
3958 flags: []string{"-renegotiate-ignore"},
3959 shouldFail: true,
3960 expectedError: ":UNEXPECTED_RECORD:",
3961 })
3962
David Benjamin760b1dd2015-05-15 23:33:48 -04003963 // NPN on client and server; results in post-handshake message.
3964 tests = append(tests, testCase{
3965 name: "NPN-Client",
3966 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003967 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003968 NextProtos: []string{"foo"},
3969 },
3970 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003971 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003972 expectedNextProto: "foo",
3973 expectedNextProtoType: npn,
3974 })
3975 tests = append(tests, testCase{
3976 testType: serverTest,
3977 name: "NPN-Server",
3978 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003979 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003980 NextProtos: []string{"bar"},
3981 },
3982 flags: []string{
3983 "-advertise-npn", "\x03foo\x03bar\x03baz",
3984 "-expect-next-proto", "bar",
3985 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003986 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003987 expectedNextProto: "bar",
3988 expectedNextProtoType: npn,
3989 })
3990
3991 // TODO(davidben): Add tests for when False Start doesn't trigger.
3992
3993 // Client does False Start and negotiates NPN.
3994 tests = append(tests, testCase{
3995 name: "FalseStart",
3996 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003997 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003998 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3999 NextProtos: []string{"foo"},
4000 Bugs: ProtocolBugs{
4001 ExpectFalseStart: true,
4002 },
4003 },
4004 flags: []string{
4005 "-false-start",
4006 "-select-next-proto", "foo",
4007 },
4008 shimWritesFirst: true,
4009 resumeSession: true,
4010 })
4011
4012 // Client does False Start and negotiates ALPN.
4013 tests = append(tests, testCase{
4014 name: "FalseStart-ALPN",
4015 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004016 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004017 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4018 NextProtos: []string{"foo"},
4019 Bugs: ProtocolBugs{
4020 ExpectFalseStart: true,
4021 },
4022 },
4023 flags: []string{
4024 "-false-start",
4025 "-advertise-alpn", "\x03foo",
4026 },
4027 shimWritesFirst: true,
4028 resumeSession: true,
4029 })
4030
4031 // Client does False Start but doesn't explicitly call
4032 // SSL_connect.
4033 tests = append(tests, testCase{
4034 name: "FalseStart-Implicit",
4035 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004036 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4038 NextProtos: []string{"foo"},
4039 },
4040 flags: []string{
4041 "-implicit-handshake",
4042 "-false-start",
4043 "-advertise-alpn", "\x03foo",
4044 },
4045 })
4046
4047 // False Start without session tickets.
4048 tests = append(tests, testCase{
4049 name: "FalseStart-SessionTicketsDisabled",
4050 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004051 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004052 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4053 NextProtos: []string{"foo"},
4054 SessionTicketsDisabled: true,
4055 Bugs: ProtocolBugs{
4056 ExpectFalseStart: true,
4057 },
4058 },
4059 flags: []string{
4060 "-false-start",
4061 "-select-next-proto", "foo",
4062 },
4063 shimWritesFirst: true,
4064 })
4065
4066 // Server parses a V2ClientHello.
4067 tests = append(tests, testCase{
4068 testType: serverTest,
4069 name: "SendV2ClientHello",
4070 config: Config{
4071 // Choose a cipher suite that does not involve
4072 // elliptic curves, so no extensions are
4073 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004074 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004075 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004076 Bugs: ProtocolBugs{
4077 SendV2ClientHello: true,
4078 },
4079 },
4080 })
4081
Nick Harper60a85cb2016-09-23 16:25:11 -07004082 // Test Channel ID
4083 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004084 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004085 continue
4086 }
4087 // Client sends a Channel ID.
4088 tests = append(tests, testCase{
4089 name: "ChannelID-Client-" + ver.name,
4090 config: Config{
4091 MaxVersion: ver.version,
4092 RequestChannelID: true,
4093 },
4094 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4095 resumeSession: true,
4096 expectChannelID: true,
4097 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004098
Nick Harper60a85cb2016-09-23 16:25:11 -07004099 // Server accepts a Channel ID.
4100 tests = append(tests, testCase{
4101 testType: serverTest,
4102 name: "ChannelID-Server-" + ver.name,
4103 config: Config{
4104 MaxVersion: ver.version,
4105 ChannelID: channelIDKey,
4106 },
4107 flags: []string{
4108 "-expect-channel-id",
4109 base64.StdEncoding.EncodeToString(channelIDBytes),
4110 },
4111 resumeSession: true,
4112 expectChannelID: true,
4113 })
4114
4115 tests = append(tests, testCase{
4116 testType: serverTest,
4117 name: "InvalidChannelIDSignature-" + ver.name,
4118 config: Config{
4119 MaxVersion: ver.version,
4120 ChannelID: channelIDKey,
4121 Bugs: ProtocolBugs{
4122 InvalidChannelIDSignature: true,
4123 },
4124 },
4125 flags: []string{"-enable-channel-id"},
4126 shouldFail: true,
4127 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4128 })
4129 }
David Benjamin30789da2015-08-29 22:56:45 -04004130
David Benjaminf8fcdf32016-06-08 15:56:13 -04004131 // Channel ID and NPN at the same time, to ensure their relative
4132 // ordering is correct.
4133 tests = append(tests, testCase{
4134 name: "ChannelID-NPN-Client",
4135 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004136 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004137 RequestChannelID: true,
4138 NextProtos: []string{"foo"},
4139 },
4140 flags: []string{
4141 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4142 "-select-next-proto", "foo",
4143 },
4144 resumeSession: true,
4145 expectChannelID: true,
4146 expectedNextProto: "foo",
4147 expectedNextProtoType: npn,
4148 })
4149 tests = append(tests, testCase{
4150 testType: serverTest,
4151 name: "ChannelID-NPN-Server",
4152 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004153 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004154 ChannelID: channelIDKey,
4155 NextProtos: []string{"bar"},
4156 },
4157 flags: []string{
4158 "-expect-channel-id",
4159 base64.StdEncoding.EncodeToString(channelIDBytes),
4160 "-advertise-npn", "\x03foo\x03bar\x03baz",
4161 "-expect-next-proto", "bar",
4162 },
4163 resumeSession: true,
4164 expectChannelID: true,
4165 expectedNextProto: "bar",
4166 expectedNextProtoType: npn,
4167 })
4168
David Benjamin30789da2015-08-29 22:56:45 -04004169 // Bidirectional shutdown with the runner initiating.
4170 tests = append(tests, testCase{
4171 name: "Shutdown-Runner",
4172 config: Config{
4173 Bugs: ProtocolBugs{
4174 ExpectCloseNotify: true,
4175 },
4176 },
4177 flags: []string{"-check-close-notify"},
4178 })
4179
4180 // Bidirectional shutdown with the shim initiating. The runner,
4181 // in the meantime, sends garbage before the close_notify which
4182 // the shim must ignore.
4183 tests = append(tests, testCase{
4184 name: "Shutdown-Shim",
4185 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004186 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004187 Bugs: ProtocolBugs{
4188 ExpectCloseNotify: true,
4189 },
4190 },
4191 shimShutsDown: true,
4192 sendEmptyRecords: 1,
4193 sendWarningAlerts: 1,
4194 flags: []string{"-check-close-notify"},
4195 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004196 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004197 // TODO(davidben): DTLS 1.3 will want a similar thing for
4198 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004199 tests = append(tests, testCase{
4200 name: "SkipHelloVerifyRequest",
4201 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004202 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004203 Bugs: ProtocolBugs{
4204 SkipHelloVerifyRequest: true,
4205 },
4206 },
4207 })
4208 }
4209
David Benjamin760b1dd2015-05-15 23:33:48 -04004210 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004211 test.protocol = config.protocol
4212 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004213 test.name += "-DTLS"
4214 }
David Benjamin582ba042016-07-07 12:33:25 -07004215 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004216 test.name += "-Async"
4217 test.flags = append(test.flags, "-async")
4218 } else {
4219 test.name += "-Sync"
4220 }
David Benjamin582ba042016-07-07 12:33:25 -07004221 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004222 test.name += "-SplitHandshakeRecords"
4223 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004224 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004225 test.config.Bugs.MaxPacketLength = 256
4226 test.flags = append(test.flags, "-mtu", "256")
4227 }
4228 }
David Benjamin582ba042016-07-07 12:33:25 -07004229 if config.packHandshakeFlight {
4230 test.name += "-PackHandshakeFlight"
4231 test.config.Bugs.PackHandshakeFlight = true
4232 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004233 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004234 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004235}
4236
Adam Langley524e7172015-02-20 16:04:00 -08004237func addDDoSCallbackTests() {
4238 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004239 for _, resume := range []bool{false, true} {
4240 suffix := "Resume"
4241 if resume {
4242 suffix = "No" + suffix
4243 }
4244
4245 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004246 testType: serverTest,
4247 name: "Server-DDoS-OK-" + suffix,
4248 config: Config{
4249 MaxVersion: VersionTLS12,
4250 },
Adam Langley524e7172015-02-20 16:04:00 -08004251 flags: []string{"-install-ddos-callback"},
4252 resumeSession: resume,
4253 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004254 testCases = append(testCases, testCase{
4255 testType: serverTest,
4256 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4257 config: Config{
4258 MaxVersion: VersionTLS13,
4259 },
4260 flags: []string{"-install-ddos-callback"},
4261 resumeSession: resume,
4262 })
Adam Langley524e7172015-02-20 16:04:00 -08004263
4264 failFlag := "-fail-ddos-callback"
4265 if resume {
4266 failFlag = "-fail-second-ddos-callback"
4267 }
4268 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004269 testType: serverTest,
4270 name: "Server-DDoS-Reject-" + suffix,
4271 config: Config{
4272 MaxVersion: VersionTLS12,
4273 },
David Benjamin2c66e072016-09-16 15:58:00 -04004274 flags: []string{"-install-ddos-callback", failFlag},
4275 resumeSession: resume,
4276 shouldFail: true,
4277 expectedError: ":CONNECTION_REJECTED:",
4278 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004279 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004280 testCases = append(testCases, testCase{
4281 testType: serverTest,
4282 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4283 config: Config{
4284 MaxVersion: VersionTLS13,
4285 },
David Benjamin2c66e072016-09-16 15:58:00 -04004286 flags: []string{"-install-ddos-callback", failFlag},
4287 resumeSession: resume,
4288 shouldFail: true,
4289 expectedError: ":CONNECTION_REJECTED:",
4290 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004291 })
Adam Langley524e7172015-02-20 16:04:00 -08004292 }
4293}
4294
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004295func addVersionNegotiationTests() {
4296 for i, shimVers := range tlsVersions {
4297 // Assemble flags to disable all newer versions on the shim.
4298 var flags []string
4299 for _, vers := range tlsVersions[i+1:] {
4300 flags = append(flags, vers.flag)
4301 }
4302
Steven Valdezfdd10992016-09-15 16:27:05 -04004303 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004304 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004305 protocols := []protocol{tls}
4306 if runnerVers.hasDTLS && shimVers.hasDTLS {
4307 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004308 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004309 for _, protocol := range protocols {
4310 expectedVersion := shimVers.version
4311 if runnerVers.version < shimVers.version {
4312 expectedVersion = runnerVers.version
4313 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004314
David Benjamin8b8c0062014-11-23 02:47:52 -05004315 suffix := shimVers.name + "-" + runnerVers.name
4316 if protocol == dtls {
4317 suffix += "-DTLS"
4318 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004319
David Benjamin1eb367c2014-12-12 18:17:51 -05004320 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4321
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004322 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004323 clientVers := shimVers.version
4324 if clientVers > VersionTLS10 {
4325 clientVers = VersionTLS10
4326 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004327 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004328 serverVers := expectedVersion
4329 if expectedVersion >= VersionTLS13 {
4330 serverVers = VersionTLS10
4331 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004332 serverVers = versionToWire(serverVers, protocol == dtls)
4333
David Benjamin8b8c0062014-11-23 02:47:52 -05004334 testCases = append(testCases, testCase{
4335 protocol: protocol,
4336 testType: clientTest,
4337 name: "VersionNegotiation-Client-" + suffix,
4338 config: Config{
4339 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004340 Bugs: ProtocolBugs{
4341 ExpectInitialRecordVersion: clientVers,
4342 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004343 },
4344 flags: flags,
4345 expectedVersion: expectedVersion,
4346 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004347 testCases = append(testCases, testCase{
4348 protocol: protocol,
4349 testType: clientTest,
4350 name: "VersionNegotiation-Client2-" + suffix,
4351 config: Config{
4352 MaxVersion: runnerVers.version,
4353 Bugs: ProtocolBugs{
4354 ExpectInitialRecordVersion: clientVers,
4355 },
4356 },
4357 flags: []string{"-max-version", shimVersFlag},
4358 expectedVersion: expectedVersion,
4359 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004360
4361 testCases = append(testCases, testCase{
4362 protocol: protocol,
4363 testType: serverTest,
4364 name: "VersionNegotiation-Server-" + suffix,
4365 config: Config{
4366 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004367 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004368 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004369 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004370 },
4371 flags: flags,
4372 expectedVersion: expectedVersion,
4373 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004374 testCases = append(testCases, testCase{
4375 protocol: protocol,
4376 testType: serverTest,
4377 name: "VersionNegotiation-Server2-" + suffix,
4378 config: Config{
4379 MaxVersion: runnerVers.version,
4380 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004381 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004382 },
4383 },
4384 flags: []string{"-max-version", shimVersFlag},
4385 expectedVersion: expectedVersion,
4386 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004387 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004388 }
4389 }
David Benjamin95c69562016-06-29 18:15:03 -04004390
Steven Valdezfdd10992016-09-15 16:27:05 -04004391 // Test the version extension at all versions.
4392 for _, vers := range tlsVersions {
4393 protocols := []protocol{tls}
4394 if vers.hasDTLS {
4395 protocols = append(protocols, dtls)
4396 }
4397 for _, protocol := range protocols {
4398 suffix := vers.name
4399 if protocol == dtls {
4400 suffix += "-DTLS"
4401 }
4402
4403 wireVersion := versionToWire(vers.version, protocol == dtls)
4404 testCases = append(testCases, testCase{
4405 protocol: protocol,
4406 testType: serverTest,
4407 name: "VersionNegotiationExtension-" + suffix,
4408 config: Config{
4409 Bugs: ProtocolBugs{
4410 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4411 },
4412 },
4413 expectedVersion: vers.version,
4414 })
4415 }
4416
4417 }
4418
4419 // If all versions are unknown, negotiation fails.
4420 testCases = append(testCases, testCase{
4421 testType: serverTest,
4422 name: "NoSupportedVersions",
4423 config: Config{
4424 Bugs: ProtocolBugs{
4425 SendSupportedVersions: []uint16{0x1111},
4426 },
4427 },
4428 shouldFail: true,
4429 expectedError: ":UNSUPPORTED_PROTOCOL:",
4430 })
4431 testCases = append(testCases, testCase{
4432 protocol: dtls,
4433 testType: serverTest,
4434 name: "NoSupportedVersions-DTLS",
4435 config: Config{
4436 Bugs: ProtocolBugs{
4437 SendSupportedVersions: []uint16{0x1111},
4438 },
4439 },
4440 shouldFail: true,
4441 expectedError: ":UNSUPPORTED_PROTOCOL:",
4442 })
4443
4444 testCases = append(testCases, testCase{
4445 testType: serverTest,
4446 name: "ClientHelloVersionTooHigh",
4447 config: Config{
4448 MaxVersion: VersionTLS13,
4449 Bugs: ProtocolBugs{
4450 SendClientVersion: 0x0304,
4451 OmitSupportedVersions: true,
4452 },
4453 },
4454 expectedVersion: VersionTLS12,
4455 })
4456
4457 testCases = append(testCases, testCase{
4458 testType: serverTest,
4459 name: "ConflictingVersionNegotiation",
4460 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004461 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004462 SendClientVersion: VersionTLS12,
4463 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004464 },
4465 },
David Benjaminad75a662016-09-30 15:42:59 -04004466 // The extension takes precedence over the ClientHello version.
4467 expectedVersion: VersionTLS11,
4468 })
4469
4470 testCases = append(testCases, testCase{
4471 testType: serverTest,
4472 name: "ConflictingVersionNegotiation-2",
4473 config: Config{
4474 Bugs: ProtocolBugs{
4475 SendClientVersion: VersionTLS11,
4476 SendSupportedVersions: []uint16{VersionTLS12},
4477 },
4478 },
4479 // The extension takes precedence over the ClientHello version.
4480 expectedVersion: VersionTLS12,
4481 })
4482
4483 testCases = append(testCases, testCase{
4484 testType: serverTest,
4485 name: "RejectFinalTLS13",
4486 config: Config{
4487 Bugs: ProtocolBugs{
4488 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4489 },
4490 },
4491 // We currently implement a draft TLS 1.3 version. Ensure that
4492 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004493 expectedVersion: VersionTLS12,
4494 })
4495
Brian Smithf85d3232016-10-28 10:34:06 -10004496 // Test that the maximum version is selected regardless of the
4497 // client-sent order.
4498 testCases = append(testCases, testCase{
4499 testType: serverTest,
4500 name: "IgnoreClientVersionOrder",
4501 config: Config{
4502 Bugs: ProtocolBugs{
4503 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4504 },
4505 },
4506 expectedVersion: VersionTLS13,
4507 })
4508
David Benjamin95c69562016-06-29 18:15:03 -04004509 // Test for version tolerance.
4510 testCases = append(testCases, testCase{
4511 testType: serverTest,
4512 name: "MinorVersionTolerance",
4513 config: Config{
4514 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004515 SendClientVersion: 0x03ff,
4516 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004517 },
4518 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004519 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004520 })
4521 testCases = append(testCases, testCase{
4522 testType: serverTest,
4523 name: "MajorVersionTolerance",
4524 config: Config{
4525 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004526 SendClientVersion: 0x0400,
4527 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004528 },
4529 },
David Benjaminad75a662016-09-30 15:42:59 -04004530 // TLS 1.3 must be negotiated with the supported_versions
4531 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004532 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004533 })
David Benjaminad75a662016-09-30 15:42:59 -04004534 testCases = append(testCases, testCase{
4535 testType: serverTest,
4536 name: "VersionTolerance-TLS13",
4537 config: Config{
4538 Bugs: ProtocolBugs{
4539 // Although TLS 1.3 does not use
4540 // ClientHello.version, it still tolerates high
4541 // values there.
4542 SendClientVersion: 0x0400,
4543 },
4544 },
4545 expectedVersion: VersionTLS13,
4546 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004547
David Benjamin95c69562016-06-29 18:15:03 -04004548 testCases = append(testCases, testCase{
4549 protocol: dtls,
4550 testType: serverTest,
4551 name: "MinorVersionTolerance-DTLS",
4552 config: Config{
4553 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004554 SendClientVersion: 0xfe00,
4555 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004556 },
4557 },
4558 expectedVersion: VersionTLS12,
4559 })
4560 testCases = append(testCases, testCase{
4561 protocol: dtls,
4562 testType: serverTest,
4563 name: "MajorVersionTolerance-DTLS",
4564 config: Config{
4565 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004566 SendClientVersion: 0xfdff,
4567 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004568 },
4569 },
4570 expectedVersion: VersionTLS12,
4571 })
4572
4573 // Test that versions below 3.0 are rejected.
4574 testCases = append(testCases, testCase{
4575 testType: serverTest,
4576 name: "VersionTooLow",
4577 config: Config{
4578 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004579 SendClientVersion: 0x0200,
4580 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004581 },
4582 },
4583 shouldFail: true,
4584 expectedError: ":UNSUPPORTED_PROTOCOL:",
4585 })
4586 testCases = append(testCases, testCase{
4587 protocol: dtls,
4588 testType: serverTest,
4589 name: "VersionTooLow-DTLS",
4590 config: Config{
4591 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004592 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004593 },
4594 },
4595 shouldFail: true,
4596 expectedError: ":UNSUPPORTED_PROTOCOL:",
4597 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004598
David Benjamin2dc02042016-09-19 19:57:37 -04004599 testCases = append(testCases, testCase{
4600 name: "ServerBogusVersion",
4601 config: Config{
4602 Bugs: ProtocolBugs{
4603 SendServerHelloVersion: 0x1234,
4604 },
4605 },
4606 shouldFail: true,
4607 expectedError: ":UNSUPPORTED_PROTOCOL:",
4608 })
4609
David Benjamin1f61f0d2016-07-10 12:20:35 -04004610 // Test TLS 1.3's downgrade signal.
4611 testCases = append(testCases, testCase{
4612 name: "Downgrade-TLS12-Client",
4613 config: Config{
4614 Bugs: ProtocolBugs{
4615 NegotiateVersion: VersionTLS12,
4616 },
4617 },
David Benjamin592b5322016-09-30 15:15:01 -04004618 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004619 // TODO(davidben): This test should fail once TLS 1.3 is final
4620 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004621 })
4622 testCases = append(testCases, testCase{
4623 testType: serverTest,
4624 name: "Downgrade-TLS12-Server",
4625 config: Config{
4626 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004627 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004628 },
4629 },
David Benjamin592b5322016-09-30 15:15:01 -04004630 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004631 // TODO(davidben): This test should fail once TLS 1.3 is final
4632 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004633 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004634}
4635
David Benjaminaccb4542014-12-12 23:44:33 -05004636func addMinimumVersionTests() {
4637 for i, shimVers := range tlsVersions {
4638 // Assemble flags to disable all older versions on the shim.
4639 var flags []string
4640 for _, vers := range tlsVersions[:i] {
4641 flags = append(flags, vers.flag)
4642 }
4643
4644 for _, runnerVers := range tlsVersions {
4645 protocols := []protocol{tls}
4646 if runnerVers.hasDTLS && shimVers.hasDTLS {
4647 protocols = append(protocols, dtls)
4648 }
4649 for _, protocol := range protocols {
4650 suffix := shimVers.name + "-" + runnerVers.name
4651 if protocol == dtls {
4652 suffix += "-DTLS"
4653 }
4654 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4655
David Benjaminaccb4542014-12-12 23:44:33 -05004656 var expectedVersion uint16
4657 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004658 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004659 if runnerVers.version >= shimVers.version {
4660 expectedVersion = runnerVers.version
4661 } else {
4662 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004663 expectedError = ":UNSUPPORTED_PROTOCOL:"
4664 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004665 }
4666
4667 testCases = append(testCases, testCase{
4668 protocol: protocol,
4669 testType: clientTest,
4670 name: "MinimumVersion-Client-" + suffix,
4671 config: Config{
4672 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004673 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004674 // Ensure the server does not decline to
4675 // select a version (versions extension) or
4676 // cipher (some ciphers depend on versions).
4677 NegotiateVersion: runnerVers.version,
4678 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004679 },
David Benjaminaccb4542014-12-12 23:44:33 -05004680 },
David Benjamin87909c02014-12-13 01:55:01 -05004681 flags: flags,
4682 expectedVersion: expectedVersion,
4683 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004684 expectedError: expectedError,
4685 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004686 })
4687 testCases = append(testCases, testCase{
4688 protocol: protocol,
4689 testType: clientTest,
4690 name: "MinimumVersion-Client2-" + suffix,
4691 config: Config{
4692 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004693 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004694 // Ensure the server does not decline to
4695 // select a version (versions extension) or
4696 // cipher (some ciphers depend on versions).
4697 NegotiateVersion: runnerVers.version,
4698 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004699 },
David Benjaminaccb4542014-12-12 23:44:33 -05004700 },
David Benjamin87909c02014-12-13 01:55:01 -05004701 flags: []string{"-min-version", shimVersFlag},
4702 expectedVersion: expectedVersion,
4703 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004704 expectedError: expectedError,
4705 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004706 })
4707
4708 testCases = append(testCases, testCase{
4709 protocol: protocol,
4710 testType: serverTest,
4711 name: "MinimumVersion-Server-" + suffix,
4712 config: Config{
4713 MaxVersion: runnerVers.version,
4714 },
David Benjamin87909c02014-12-13 01:55:01 -05004715 flags: flags,
4716 expectedVersion: expectedVersion,
4717 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004718 expectedError: expectedError,
4719 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004720 })
4721 testCases = append(testCases, testCase{
4722 protocol: protocol,
4723 testType: serverTest,
4724 name: "MinimumVersion-Server2-" + suffix,
4725 config: Config{
4726 MaxVersion: runnerVers.version,
4727 },
David Benjamin87909c02014-12-13 01:55:01 -05004728 flags: []string{"-min-version", shimVersFlag},
4729 expectedVersion: expectedVersion,
4730 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004731 expectedError: expectedError,
4732 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004733 })
4734 }
4735 }
4736 }
4737}
4738
David Benjamine78bfde2014-09-06 12:45:15 -04004739func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004740 // TODO(davidben): Extensions, where applicable, all move their server
4741 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4742 // tests for both. Also test interaction with 0-RTT when implemented.
4743
David Benjamin97d17d92016-07-14 16:12:00 -04004744 // Repeat extensions tests all versions except SSL 3.0.
4745 for _, ver := range tlsVersions {
4746 if ver.version == VersionSSL30 {
4747 continue
4748 }
4749
David Benjamin97d17d92016-07-14 16:12:00 -04004750 // Test that duplicate extensions are rejected.
4751 testCases = append(testCases, testCase{
4752 testType: clientTest,
4753 name: "DuplicateExtensionClient-" + ver.name,
4754 config: Config{
4755 MaxVersion: ver.version,
4756 Bugs: ProtocolBugs{
4757 DuplicateExtension: true,
4758 },
David Benjamine78bfde2014-09-06 12:45:15 -04004759 },
David Benjamin97d17d92016-07-14 16:12:00 -04004760 shouldFail: true,
4761 expectedLocalError: "remote error: error decoding message",
4762 })
4763 testCases = append(testCases, testCase{
4764 testType: serverTest,
4765 name: "DuplicateExtensionServer-" + ver.name,
4766 config: Config{
4767 MaxVersion: ver.version,
4768 Bugs: ProtocolBugs{
4769 DuplicateExtension: true,
4770 },
David Benjamine78bfde2014-09-06 12:45:15 -04004771 },
David Benjamin97d17d92016-07-14 16:12:00 -04004772 shouldFail: true,
4773 expectedLocalError: "remote error: error decoding message",
4774 })
4775
4776 // Test SNI.
4777 testCases = append(testCases, testCase{
4778 testType: clientTest,
4779 name: "ServerNameExtensionClient-" + ver.name,
4780 config: Config{
4781 MaxVersion: ver.version,
4782 Bugs: ProtocolBugs{
4783 ExpectServerName: "example.com",
4784 },
David Benjamine78bfde2014-09-06 12:45:15 -04004785 },
David Benjamin97d17d92016-07-14 16:12:00 -04004786 flags: []string{"-host-name", "example.com"},
4787 })
4788 testCases = append(testCases, testCase{
4789 testType: clientTest,
4790 name: "ServerNameExtensionClientMismatch-" + ver.name,
4791 config: Config{
4792 MaxVersion: ver.version,
4793 Bugs: ProtocolBugs{
4794 ExpectServerName: "mismatch.com",
4795 },
David Benjamine78bfde2014-09-06 12:45:15 -04004796 },
David Benjamin97d17d92016-07-14 16:12:00 -04004797 flags: []string{"-host-name", "example.com"},
4798 shouldFail: true,
4799 expectedLocalError: "tls: unexpected server name",
4800 })
4801 testCases = append(testCases, testCase{
4802 testType: clientTest,
4803 name: "ServerNameExtensionClientMissing-" + ver.name,
4804 config: Config{
4805 MaxVersion: ver.version,
4806 Bugs: ProtocolBugs{
4807 ExpectServerName: "missing.com",
4808 },
David Benjamine78bfde2014-09-06 12:45:15 -04004809 },
David Benjamin97d17d92016-07-14 16:12:00 -04004810 shouldFail: true,
4811 expectedLocalError: "tls: unexpected server name",
4812 })
4813 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05004814 testType: clientTest,
4815 name: "TolerateServerNameAck-" + ver.name,
4816 config: Config{
4817 MaxVersion: ver.version,
4818 Bugs: ProtocolBugs{
4819 SendServerNameAck: true,
4820 },
4821 },
4822 flags: []string{"-host-name", "example.com"},
4823 resumeSession: true,
4824 })
4825 testCases = append(testCases, testCase{
4826 testType: clientTest,
4827 name: "UnsolicitedServerNameAck-" + ver.name,
4828 config: Config{
4829 MaxVersion: ver.version,
4830 Bugs: ProtocolBugs{
4831 SendServerNameAck: true,
4832 },
4833 },
4834 shouldFail: true,
4835 expectedError: ":UNEXPECTED_EXTENSION:",
4836 expectedLocalError: "remote error: unsupported extension",
4837 })
4838 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004839 testType: serverTest,
4840 name: "ServerNameExtensionServer-" + ver.name,
4841 config: Config{
4842 MaxVersion: ver.version,
4843 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004844 },
David Benjamin97d17d92016-07-14 16:12:00 -04004845 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004846 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004847 })
4848
4849 // Test ALPN.
4850 testCases = append(testCases, testCase{
4851 testType: clientTest,
4852 name: "ALPNClient-" + ver.name,
4853 config: Config{
4854 MaxVersion: ver.version,
4855 NextProtos: []string{"foo"},
4856 },
4857 flags: []string{
4858 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4859 "-expect-alpn", "foo",
4860 },
4861 expectedNextProto: "foo",
4862 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004863 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004864 })
4865 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004866 testType: clientTest,
4867 name: "ALPNClient-Mismatch-" + ver.name,
4868 config: Config{
4869 MaxVersion: ver.version,
4870 Bugs: ProtocolBugs{
4871 SendALPN: "baz",
4872 },
4873 },
4874 flags: []string{
4875 "-advertise-alpn", "\x03foo\x03bar",
4876 },
4877 shouldFail: true,
4878 expectedError: ":INVALID_ALPN_PROTOCOL:",
4879 expectedLocalError: "remote error: illegal parameter",
4880 })
4881 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004882 testType: serverTest,
4883 name: "ALPNServer-" + ver.name,
4884 config: Config{
4885 MaxVersion: ver.version,
4886 NextProtos: []string{"foo", "bar", "baz"},
4887 },
4888 flags: []string{
4889 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4890 "-select-alpn", "foo",
4891 },
4892 expectedNextProto: "foo",
4893 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004894 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004895 })
4896 testCases = append(testCases, testCase{
4897 testType: serverTest,
4898 name: "ALPNServer-Decline-" + ver.name,
4899 config: Config{
4900 MaxVersion: ver.version,
4901 NextProtos: []string{"foo", "bar", "baz"},
4902 },
4903 flags: []string{"-decline-alpn"},
4904 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004905 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004906 })
4907
David Benjamin25fe85b2016-08-09 20:00:32 -04004908 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4909 // called once.
4910 testCases = append(testCases, testCase{
4911 testType: serverTest,
4912 name: "ALPNServer-Async-" + ver.name,
4913 config: Config{
4914 MaxVersion: ver.version,
4915 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004916 // Prior to TLS 1.3, exercise the asynchronous session callback.
4917 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004918 },
4919 flags: []string{
4920 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4921 "-select-alpn", "foo",
4922 "-async",
4923 },
4924 expectedNextProto: "foo",
4925 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004926 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004927 })
4928
David Benjamin97d17d92016-07-14 16:12:00 -04004929 var emptyString string
4930 testCases = append(testCases, testCase{
4931 testType: clientTest,
4932 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4933 config: Config{
4934 MaxVersion: ver.version,
4935 NextProtos: []string{""},
4936 Bugs: ProtocolBugs{
4937 // A server returning an empty ALPN protocol
4938 // should be rejected.
4939 ALPNProtocol: &emptyString,
4940 },
4941 },
4942 flags: []string{
4943 "-advertise-alpn", "\x03foo",
4944 },
4945 shouldFail: true,
4946 expectedError: ":PARSE_TLSEXT:",
4947 })
4948 testCases = append(testCases, testCase{
4949 testType: serverTest,
4950 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4951 config: Config{
4952 MaxVersion: ver.version,
4953 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004954 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004955 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004956 },
David Benjamin97d17d92016-07-14 16:12:00 -04004957 flags: []string{
4958 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004959 },
David Benjamin97d17d92016-07-14 16:12:00 -04004960 shouldFail: true,
4961 expectedError: ":PARSE_TLSEXT:",
4962 })
4963
4964 // Test NPN and the interaction with ALPN.
4965 if ver.version < VersionTLS13 {
4966 // Test that the server prefers ALPN over NPN.
4967 testCases = append(testCases, testCase{
4968 testType: serverTest,
4969 name: "ALPNServer-Preferred-" + ver.name,
4970 config: Config{
4971 MaxVersion: ver.version,
4972 NextProtos: []string{"foo", "bar", "baz"},
4973 },
4974 flags: []string{
4975 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4976 "-select-alpn", "foo",
4977 "-advertise-npn", "\x03foo\x03bar\x03baz",
4978 },
4979 expectedNextProto: "foo",
4980 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004981 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004982 })
4983 testCases = append(testCases, testCase{
4984 testType: serverTest,
4985 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4986 config: Config{
4987 MaxVersion: ver.version,
4988 NextProtos: []string{"foo", "bar", "baz"},
4989 Bugs: ProtocolBugs{
4990 SwapNPNAndALPN: true,
4991 },
4992 },
4993 flags: []string{
4994 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4995 "-select-alpn", "foo",
4996 "-advertise-npn", "\x03foo\x03bar\x03baz",
4997 },
4998 expectedNextProto: "foo",
4999 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005000 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005001 })
5002
5003 // Test that negotiating both NPN and ALPN is forbidden.
5004 testCases = append(testCases, testCase{
5005 name: "NegotiateALPNAndNPN-" + ver.name,
5006 config: Config{
5007 MaxVersion: ver.version,
5008 NextProtos: []string{"foo", "bar", "baz"},
5009 Bugs: ProtocolBugs{
5010 NegotiateALPNAndNPN: true,
5011 },
5012 },
5013 flags: []string{
5014 "-advertise-alpn", "\x03foo",
5015 "-select-next-proto", "foo",
5016 },
5017 shouldFail: true,
5018 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5019 })
5020 testCases = append(testCases, testCase{
5021 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
5022 config: Config{
5023 MaxVersion: ver.version,
5024 NextProtos: []string{"foo", "bar", "baz"},
5025 Bugs: ProtocolBugs{
5026 NegotiateALPNAndNPN: true,
5027 SwapNPNAndALPN: true,
5028 },
5029 },
5030 flags: []string{
5031 "-advertise-alpn", "\x03foo",
5032 "-select-next-proto", "foo",
5033 },
5034 shouldFail: true,
5035 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
5036 })
David Benjamin97d17d92016-07-14 16:12:00 -04005037 }
5038
5039 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005040
5041 // Resume with a corrupt ticket.
5042 testCases = append(testCases, testCase{
5043 testType: serverTest,
5044 name: "CorruptTicket-" + ver.name,
5045 config: Config{
5046 MaxVersion: ver.version,
5047 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005048 FilterTicket: func(in []byte) ([]byte, error) {
5049 in[len(in)-1] ^= 1
5050 return in, nil
5051 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005052 },
5053 },
5054 resumeSession: true,
5055 expectResumeRejected: true,
5056 })
5057 // Test the ticket callback, with and without renewal.
5058 testCases = append(testCases, testCase{
5059 testType: serverTest,
5060 name: "TicketCallback-" + ver.name,
5061 config: Config{
5062 MaxVersion: ver.version,
5063 },
5064 resumeSession: true,
5065 flags: []string{"-use-ticket-callback"},
5066 })
5067 testCases = append(testCases, testCase{
5068 testType: serverTest,
5069 name: "TicketCallback-Renew-" + ver.name,
5070 config: Config{
5071 MaxVersion: ver.version,
5072 Bugs: ProtocolBugs{
5073 ExpectNewTicket: true,
5074 },
5075 },
5076 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5077 resumeSession: true,
5078 })
5079
5080 // Test that the ticket callback is only called once when everything before
5081 // it in the ClientHello is asynchronous. This corrupts the ticket so
5082 // certificate selection callbacks run.
5083 testCases = append(testCases, testCase{
5084 testType: serverTest,
5085 name: "TicketCallback-SingleCall-" + ver.name,
5086 config: Config{
5087 MaxVersion: ver.version,
5088 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005089 FilterTicket: func(in []byte) ([]byte, error) {
5090 in[len(in)-1] ^= 1
5091 return in, nil
5092 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005093 },
5094 },
5095 resumeSession: true,
5096 expectResumeRejected: true,
5097 flags: []string{
5098 "-use-ticket-callback",
5099 "-async",
5100 },
5101 })
5102
David Benjamind4c349b2017-02-09 14:07:17 -05005103 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005104 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005105 testCases = append(testCases, testCase{
5106 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005107 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005108 config: Config{
5109 MaxVersion: ver.version,
5110 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005111 EmptyTicketSessionID: true,
5112 },
5113 },
5114 resumeSession: true,
5115 })
5116 testCases = append(testCases, testCase{
5117 testType: serverTest,
5118 name: "TicketSessionIDLength-16-" + ver.name,
5119 config: Config{
5120 MaxVersion: ver.version,
5121 Bugs: ProtocolBugs{
5122 TicketSessionIDLength: 16,
5123 },
5124 },
5125 resumeSession: true,
5126 })
5127 testCases = append(testCases, testCase{
5128 testType: serverTest,
5129 name: "TicketSessionIDLength-32-" + ver.name,
5130 config: Config{
5131 MaxVersion: ver.version,
5132 Bugs: ProtocolBugs{
5133 TicketSessionIDLength: 32,
5134 },
5135 },
5136 resumeSession: true,
5137 })
5138 testCases = append(testCases, testCase{
5139 testType: serverTest,
5140 name: "TicketSessionIDLength-33-" + ver.name,
5141 config: Config{
5142 MaxVersion: ver.version,
5143 Bugs: ProtocolBugs{
5144 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005145 },
5146 },
5147 resumeSession: true,
5148 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005149 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005150 expectedError: ":DECODE_ERROR:",
5151 })
5152 }
5153
5154 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5155 // are ignored.
5156 if ver.hasDTLS {
5157 testCases = append(testCases, testCase{
5158 protocol: dtls,
5159 name: "SRTP-Client-" + ver.name,
5160 config: Config{
5161 MaxVersion: ver.version,
5162 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5163 },
5164 flags: []string{
5165 "-srtp-profiles",
5166 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5167 },
5168 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5169 })
5170 testCases = append(testCases, testCase{
5171 protocol: dtls,
5172 testType: serverTest,
5173 name: "SRTP-Server-" + ver.name,
5174 config: Config{
5175 MaxVersion: ver.version,
5176 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5177 },
5178 flags: []string{
5179 "-srtp-profiles",
5180 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5181 },
5182 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5183 })
5184 // Test that the MKI is ignored.
5185 testCases = append(testCases, testCase{
5186 protocol: dtls,
5187 testType: serverTest,
5188 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5189 config: Config{
5190 MaxVersion: ver.version,
5191 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5192 Bugs: ProtocolBugs{
5193 SRTPMasterKeyIdentifer: "bogus",
5194 },
5195 },
5196 flags: []string{
5197 "-srtp-profiles",
5198 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5199 },
5200 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5201 })
5202 // Test that SRTP isn't negotiated on the server if there were
5203 // no matching profiles.
5204 testCases = append(testCases, testCase{
5205 protocol: dtls,
5206 testType: serverTest,
5207 name: "SRTP-Server-NoMatch-" + ver.name,
5208 config: Config{
5209 MaxVersion: ver.version,
5210 SRTPProtectionProfiles: []uint16{100, 101, 102},
5211 },
5212 flags: []string{
5213 "-srtp-profiles",
5214 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5215 },
5216 expectedSRTPProtectionProfile: 0,
5217 })
5218 // Test that the server returning an invalid SRTP profile is
5219 // flagged as an error by the client.
5220 testCases = append(testCases, testCase{
5221 protocol: dtls,
5222 name: "SRTP-Client-NoMatch-" + ver.name,
5223 config: Config{
5224 MaxVersion: ver.version,
5225 Bugs: ProtocolBugs{
5226 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5227 },
5228 },
5229 flags: []string{
5230 "-srtp-profiles",
5231 "SRTP_AES128_CM_SHA1_80",
5232 },
5233 shouldFail: true,
5234 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5235 })
5236 }
5237
5238 // Test SCT list.
5239 testCases = append(testCases, testCase{
5240 name: "SignedCertificateTimestampList-Client-" + ver.name,
5241 testType: clientTest,
5242 config: Config{
5243 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005244 },
David Benjamin97d17d92016-07-14 16:12:00 -04005245 flags: []string{
5246 "-enable-signed-cert-timestamps",
5247 "-expect-signed-cert-timestamps",
5248 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005249 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005250 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005251 })
David Benjamindaa88502016-10-04 16:32:16 -04005252
Adam Langleycfa08c32016-11-17 13:21:27 -08005253 var differentSCTList []byte
5254 differentSCTList = append(differentSCTList, testSCTList...)
5255 differentSCTList[len(differentSCTList)-1] ^= 1
5256
David Benjamindaa88502016-10-04 16:32:16 -04005257 // The SCT extension did not specify that it must only be sent on resumption as it
5258 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005259 testCases = append(testCases, testCase{
5260 name: "SendSCTListOnResume-" + ver.name,
5261 config: Config{
5262 MaxVersion: ver.version,
5263 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005264 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005265 },
David Benjamind98452d2015-06-16 14:16:23 -04005266 },
David Benjamin97d17d92016-07-14 16:12:00 -04005267 flags: []string{
5268 "-enable-signed-cert-timestamps",
5269 "-expect-signed-cert-timestamps",
5270 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005271 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005272 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005273 })
David Benjamindaa88502016-10-04 16:32:16 -04005274
David Benjamin97d17d92016-07-14 16:12:00 -04005275 testCases = append(testCases, testCase{
5276 name: "SignedCertificateTimestampList-Server-" + ver.name,
5277 testType: serverTest,
5278 config: Config{
5279 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005280 },
David Benjamin97d17d92016-07-14 16:12:00 -04005281 flags: []string{
5282 "-signed-cert-timestamps",
5283 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005284 },
David Benjamin97d17d92016-07-14 16:12:00 -04005285 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005286 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005287 })
David Benjamin53210cb2016-11-16 09:01:48 +09005288
Adam Langleycfa08c32016-11-17 13:21:27 -08005289 emptySCTListCert := *testCerts[0].cert
5290 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5291
5292 // Test empty SCT list.
5293 testCases = append(testCases, testCase{
5294 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5295 testType: clientTest,
5296 config: Config{
5297 MaxVersion: ver.version,
5298 Certificates: []Certificate{emptySCTListCert},
5299 },
5300 flags: []string{
5301 "-enable-signed-cert-timestamps",
5302 },
5303 shouldFail: true,
5304 expectedError: ":ERROR_PARSING_EXTENSION:",
5305 })
5306
5307 emptySCTCert := *testCerts[0].cert
5308 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5309
5310 // Test empty SCT in non-empty list.
5311 testCases = append(testCases, testCase{
5312 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5313 testType: clientTest,
5314 config: Config{
5315 MaxVersion: ver.version,
5316 Certificates: []Certificate{emptySCTCert},
5317 },
5318 flags: []string{
5319 "-enable-signed-cert-timestamps",
5320 },
5321 shouldFail: true,
5322 expectedError: ":ERROR_PARSING_EXTENSION:",
5323 })
5324
David Benjamin53210cb2016-11-16 09:01:48 +09005325 // Test that certificate-related extensions are not sent unsolicited.
5326 testCases = append(testCases, testCase{
5327 testType: serverTest,
5328 name: "UnsolicitedCertificateExtensions-" + ver.name,
5329 config: Config{
5330 MaxVersion: ver.version,
5331 Bugs: ProtocolBugs{
5332 NoOCSPStapling: true,
5333 NoSignedCertificateTimestamps: true,
5334 },
5335 },
5336 flags: []string{
5337 "-ocsp-response",
5338 base64.StdEncoding.EncodeToString(testOCSPResponse),
5339 "-signed-cert-timestamps",
5340 base64.StdEncoding.EncodeToString(testSCTList),
5341 },
5342 })
David Benjamin97d17d92016-07-14 16:12:00 -04005343 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005344
Paul Lietar4fac72e2015-09-09 13:44:55 +01005345 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005346 testType: clientTest,
5347 name: "ClientHelloPadding",
5348 config: Config{
5349 Bugs: ProtocolBugs{
5350 RequireClientHelloSize: 512,
5351 },
5352 },
5353 // This hostname just needs to be long enough to push the
5354 // ClientHello into F5's danger zone between 256 and 511 bytes
5355 // long.
5356 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5357 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005358
5359 // Extensions should not function in SSL 3.0.
5360 testCases = append(testCases, testCase{
5361 testType: serverTest,
5362 name: "SSLv3Extensions-NoALPN",
5363 config: Config{
5364 MaxVersion: VersionSSL30,
5365 NextProtos: []string{"foo", "bar", "baz"},
5366 },
5367 flags: []string{
5368 "-select-alpn", "foo",
5369 },
5370 expectNoNextProto: true,
5371 })
5372
5373 // Test session tickets separately as they follow a different codepath.
5374 testCases = append(testCases, testCase{
5375 testType: serverTest,
5376 name: "SSLv3Extensions-NoTickets",
5377 config: Config{
5378 MaxVersion: VersionSSL30,
5379 Bugs: ProtocolBugs{
5380 // Historically, session tickets in SSL 3.0
5381 // failed in different ways depending on whether
5382 // the client supported renegotiation_info.
5383 NoRenegotiationInfo: true,
5384 },
5385 },
5386 resumeSession: true,
5387 })
5388 testCases = append(testCases, testCase{
5389 testType: serverTest,
5390 name: "SSLv3Extensions-NoTickets2",
5391 config: Config{
5392 MaxVersion: VersionSSL30,
5393 },
5394 resumeSession: true,
5395 })
5396
5397 // But SSL 3.0 does send and process renegotiation_info.
5398 testCases = append(testCases, testCase{
5399 testType: serverTest,
5400 name: "SSLv3Extensions-RenegotiationInfo",
5401 config: Config{
5402 MaxVersion: VersionSSL30,
5403 Bugs: ProtocolBugs{
5404 RequireRenegotiationInfo: true,
5405 },
5406 },
David Benjamind2610042017-01-03 10:49:28 -05005407 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005408 })
5409 testCases = append(testCases, testCase{
5410 testType: serverTest,
5411 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5412 config: Config{
5413 MaxVersion: VersionSSL30,
5414 Bugs: ProtocolBugs{
5415 NoRenegotiationInfo: true,
5416 SendRenegotiationSCSV: true,
5417 RequireRenegotiationInfo: true,
5418 },
5419 },
David Benjamind2610042017-01-03 10:49:28 -05005420 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005421 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005422
5423 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5424 // in ServerHello.
5425 testCases = append(testCases, testCase{
5426 name: "NPN-Forbidden-TLS13",
5427 config: Config{
5428 MaxVersion: VersionTLS13,
5429 NextProtos: []string{"foo"},
5430 Bugs: ProtocolBugs{
5431 NegotiateNPNAtAllVersions: true,
5432 },
5433 },
5434 flags: []string{"-select-next-proto", "foo"},
5435 shouldFail: true,
5436 expectedError: ":ERROR_PARSING_EXTENSION:",
5437 })
5438 testCases = append(testCases, testCase{
5439 name: "EMS-Forbidden-TLS13",
5440 config: Config{
5441 MaxVersion: VersionTLS13,
5442 Bugs: ProtocolBugs{
5443 NegotiateEMSAtAllVersions: true,
5444 },
5445 },
5446 shouldFail: true,
5447 expectedError: ":ERROR_PARSING_EXTENSION:",
5448 })
5449 testCases = append(testCases, testCase{
5450 name: "RenegotiationInfo-Forbidden-TLS13",
5451 config: Config{
5452 MaxVersion: VersionTLS13,
5453 Bugs: ProtocolBugs{
5454 NegotiateRenegotiationInfoAtAllVersions: true,
5455 },
5456 },
5457 shouldFail: true,
5458 expectedError: ":ERROR_PARSING_EXTENSION:",
5459 })
5460 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005461 name: "Ticket-Forbidden-TLS13",
5462 config: Config{
5463 MaxVersion: VersionTLS12,
5464 },
5465 resumeConfig: &Config{
5466 MaxVersion: VersionTLS13,
5467 Bugs: ProtocolBugs{
5468 AdvertiseTicketExtension: true,
5469 },
5470 },
5471 resumeSession: true,
5472 shouldFail: true,
5473 expectedError: ":ERROR_PARSING_EXTENSION:",
5474 })
5475
5476 // Test that illegal extensions in TLS 1.3 are declined by the server if
5477 // offered in ClientHello. The runner's server will fail if this occurs,
5478 // so we exercise the offering path. (EMS and Renegotiation Info are
5479 // implicit in every test.)
5480 testCases = append(testCases, testCase{
5481 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005482 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005483 config: Config{
5484 MaxVersion: VersionTLS13,
5485 NextProtos: []string{"bar"},
5486 },
5487 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5488 })
David Benjamin196df5b2016-09-21 16:23:27 -04005489
David Benjamindaa88502016-10-04 16:32:16 -04005490 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5491 // tolerated.
5492 testCases = append(testCases, testCase{
5493 name: "SendOCSPResponseOnResume-TLS12",
5494 config: Config{
5495 MaxVersion: VersionTLS12,
5496 Bugs: ProtocolBugs{
5497 SendOCSPResponseOnResume: []byte("bogus"),
5498 },
5499 },
5500 flags: []string{
5501 "-enable-ocsp-stapling",
5502 "-expect-ocsp-response",
5503 base64.StdEncoding.EncodeToString(testOCSPResponse),
5504 },
5505 resumeSession: true,
5506 })
5507
David Benjamindaa88502016-10-04 16:32:16 -04005508 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005509 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005510 config: Config{
5511 MaxVersion: VersionTLS13,
5512 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005513 SendExtensionOnCertificate: testOCSPExtension,
5514 },
5515 },
5516 shouldFail: true,
5517 expectedError: ":UNEXPECTED_EXTENSION:",
5518 })
5519
5520 testCases = append(testCases, testCase{
5521 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5522 config: Config{
5523 MaxVersion: VersionTLS13,
5524 Bugs: ProtocolBugs{
5525 SendExtensionOnCertificate: testSCTExtension,
5526 },
5527 },
5528 shouldFail: true,
5529 expectedError: ":UNEXPECTED_EXTENSION:",
5530 })
5531
5532 // Test that extensions on client certificates are never accepted.
5533 testCases = append(testCases, testCase{
5534 name: "SendExtensionOnClientCertificate-TLS13",
5535 testType: serverTest,
5536 config: Config{
5537 MaxVersion: VersionTLS13,
5538 Certificates: []Certificate{rsaCertificate},
5539 Bugs: ProtocolBugs{
5540 SendExtensionOnCertificate: testOCSPExtension,
5541 },
5542 },
5543 flags: []string{
5544 "-enable-ocsp-stapling",
5545 "-require-any-client-certificate",
5546 },
5547 shouldFail: true,
5548 expectedError: ":UNEXPECTED_EXTENSION:",
5549 })
5550
5551 testCases = append(testCases, testCase{
5552 name: "SendUnknownExtensionOnCertificate-TLS13",
5553 config: Config{
5554 MaxVersion: VersionTLS13,
5555 Bugs: ProtocolBugs{
5556 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5557 },
5558 },
5559 shouldFail: true,
5560 expectedError: ":UNEXPECTED_EXTENSION:",
5561 })
5562
Adam Langleycfa08c32016-11-17 13:21:27 -08005563 var differentSCTList []byte
5564 differentSCTList = append(differentSCTList, testSCTList...)
5565 differentSCTList[len(differentSCTList)-1] ^= 1
5566
Steven Valdeza833c352016-11-01 13:39:36 -04005567 // Test that extensions on intermediates are allowed but ignored.
5568 testCases = append(testCases, testCase{
5569 name: "IgnoreExtensionsOnIntermediates-TLS13",
5570 config: Config{
5571 MaxVersion: VersionTLS13,
5572 Certificates: []Certificate{rsaChainCertificate},
5573 Bugs: ProtocolBugs{
5574 // Send different values on the intermediate. This tests
5575 // the intermediate's extensions do not override the
5576 // leaf's.
5577 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005578 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005579 },
5580 },
5581 flags: []string{
5582 "-enable-ocsp-stapling",
5583 "-expect-ocsp-response",
5584 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005585 "-enable-signed-cert-timestamps",
5586 "-expect-signed-cert-timestamps",
5587 base64.StdEncoding.EncodeToString(testSCTList),
5588 },
5589 resumeSession: true,
5590 })
5591
5592 // Test that extensions are not sent on intermediates when configured
5593 // only for a leaf.
5594 testCases = append(testCases, testCase{
5595 testType: serverTest,
5596 name: "SendNoExtensionsOnIntermediate-TLS13",
5597 config: Config{
5598 MaxVersion: VersionTLS13,
5599 Bugs: ProtocolBugs{
5600 ExpectNoExtensionsOnIntermediate: true,
5601 },
5602 },
5603 flags: []string{
5604 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5605 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5606 "-ocsp-response",
5607 base64.StdEncoding.EncodeToString(testOCSPResponse),
5608 "-signed-cert-timestamps",
5609 base64.StdEncoding.EncodeToString(testSCTList),
5610 },
5611 })
5612
5613 // Test that extensions are not sent on client certificates.
5614 testCases = append(testCases, testCase{
5615 name: "SendNoClientCertificateExtensions-TLS13",
5616 config: Config{
5617 MaxVersion: VersionTLS13,
5618 ClientAuth: RequireAnyClientCert,
5619 },
5620 flags: []string{
5621 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5622 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5623 "-ocsp-response",
5624 base64.StdEncoding.EncodeToString(testOCSPResponse),
5625 "-signed-cert-timestamps",
5626 base64.StdEncoding.EncodeToString(testSCTList),
5627 },
5628 })
5629
5630 testCases = append(testCases, testCase{
5631 name: "SendDuplicateExtensionsOnCerts-TLS13",
5632 config: Config{
5633 MaxVersion: VersionTLS13,
5634 Bugs: ProtocolBugs{
5635 SendDuplicateCertExtensions: true,
5636 },
5637 },
5638 flags: []string{
5639 "-enable-ocsp-stapling",
5640 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005641 },
5642 resumeSession: true,
5643 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005644 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005645 })
Adam Langley9b885c52016-11-18 14:21:03 -08005646
5647 testCases = append(testCases, testCase{
5648 name: "SignedCertificateTimestampListInvalid-Server",
5649 testType: serverTest,
5650 flags: []string{
5651 "-signed-cert-timestamps",
5652 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5653 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005654 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005655 expectedError: ":INVALID_SCT_LIST:",
5656 })
David Benjamine78bfde2014-09-06 12:45:15 -04005657}
5658
David Benjamin01fe8202014-09-24 15:21:44 -04005659func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005660 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005661 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005662 // SSL 3.0 does not have tickets and TLS 1.3 does not
5663 // have session IDs, so skip their cross-resumption
5664 // tests.
5665 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5666 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5667 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005668 }
5669
David Benjamin8b8c0062014-11-23 02:47:52 -05005670 protocols := []protocol{tls}
5671 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5672 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005673 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005674 for _, protocol := range protocols {
5675 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5676 if protocol == dtls {
5677 suffix += "-DTLS"
5678 }
5679
David Benjaminece3de92015-03-16 18:02:20 -04005680 if sessionVers.version == resumeVers.version {
5681 testCases = append(testCases, testCase{
5682 protocol: protocol,
5683 name: "Resume-Client" + suffix,
5684 resumeSession: true,
5685 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005686 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005687 Bugs: ProtocolBugs{
5688 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5689 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5690 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005691 },
David Benjaminece3de92015-03-16 18:02:20 -04005692 expectedVersion: sessionVers.version,
5693 expectedResumeVersion: resumeVers.version,
5694 })
5695 } else {
David Benjamin405da482016-08-08 17:25:07 -04005696 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5697
5698 // Offering a TLS 1.3 session sends an empty session ID, so
5699 // there is no way to convince a non-lookahead client the
5700 // session was resumed. It will appear to the client that a
5701 // stray ChangeCipherSpec was sent.
5702 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5703 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005704 }
5705
David Benjaminece3de92015-03-16 18:02:20 -04005706 testCases = append(testCases, testCase{
5707 protocol: protocol,
5708 name: "Resume-Client-Mismatch" + suffix,
5709 resumeSession: true,
5710 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005711 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005712 },
David Benjaminece3de92015-03-16 18:02:20 -04005713 expectedVersion: sessionVers.version,
5714 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005715 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005716 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005717 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005718 },
5719 },
5720 expectedResumeVersion: resumeVers.version,
5721 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005722 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005723 })
5724 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005725
5726 testCases = append(testCases, testCase{
5727 protocol: protocol,
5728 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005729 resumeSession: true,
5730 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005731 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005732 },
5733 expectedVersion: sessionVers.version,
5734 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005735 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005736 },
5737 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005738 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005739 expectedResumeVersion: resumeVers.version,
5740 })
5741
David Benjamin8b8c0062014-11-23 02:47:52 -05005742 testCases = append(testCases, testCase{
5743 protocol: protocol,
5744 testType: serverTest,
5745 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005746 resumeSession: true,
5747 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005748 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005749 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005750 expectedVersion: sessionVers.version,
5751 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005752 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005753 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005754 Bugs: ProtocolBugs{
5755 SendBothTickets: true,
5756 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005757 },
5758 expectedResumeVersion: resumeVers.version,
5759 })
5760 }
David Benjamin01fe8202014-09-24 15:21:44 -04005761 }
5762 }
David Benjaminece3de92015-03-16 18:02:20 -04005763
David Benjamin4199b0d2016-11-01 13:58:25 -04005764 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005765 testCases = append(testCases, testCase{
5766 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005767 name: "ShimTicketRewritable",
5768 resumeSession: true,
5769 config: Config{
5770 MaxVersion: VersionTLS12,
5771 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5772 Bugs: ProtocolBugs{
5773 FilterTicket: func(in []byte) ([]byte, error) {
5774 in, err := SetShimTicketVersion(in, VersionTLS12)
5775 if err != nil {
5776 return nil, err
5777 }
5778 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5779 },
5780 },
5781 },
5782 flags: []string{
5783 "-ticket-key",
5784 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5785 },
5786 })
5787
5788 // Resumptions are declined if the version does not match.
5789 testCases = append(testCases, testCase{
5790 testType: serverTest,
5791 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005792 resumeSession: true,
5793 config: Config{
5794 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005795 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005796 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005797 FilterTicket: func(in []byte) ([]byte, error) {
5798 return SetShimTicketVersion(in, VersionTLS13)
5799 },
5800 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005801 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005802 flags: []string{
5803 "-ticket-key",
5804 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5805 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005806 expectResumeRejected: true,
5807 })
5808
5809 testCases = append(testCases, testCase{
5810 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005811 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005812 resumeSession: true,
5813 config: Config{
5814 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005815 Bugs: ProtocolBugs{
5816 FilterTicket: func(in []byte) ([]byte, error) {
5817 return SetShimTicketVersion(in, VersionTLS12)
5818 },
5819 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005820 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005821 flags: []string{
5822 "-ticket-key",
5823 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5824 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005825 expectResumeRejected: true,
5826 })
5827
David Benjamin4199b0d2016-11-01 13:58:25 -04005828 // Resumptions are declined if the cipher is invalid or disabled.
5829 testCases = append(testCases, testCase{
5830 testType: serverTest,
5831 name: "Resume-Server-DeclineBadCipher",
5832 resumeSession: true,
5833 config: Config{
5834 MaxVersion: VersionTLS12,
5835 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005836 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005837 FilterTicket: func(in []byte) ([]byte, error) {
5838 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5839 },
5840 },
5841 },
5842 flags: []string{
5843 "-ticket-key",
5844 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5845 },
5846 expectResumeRejected: true,
5847 })
5848
5849 testCases = append(testCases, testCase{
5850 testType: serverTest,
5851 name: "Resume-Server-DeclineBadCipher-2",
5852 resumeSession: true,
5853 config: Config{
5854 MaxVersion: VersionTLS12,
5855 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005856 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005857 FilterTicket: func(in []byte) ([]byte, error) {
5858 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5859 },
5860 },
5861 },
5862 flags: []string{
5863 "-cipher", "AES128",
5864 "-ticket-key",
5865 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5866 },
5867 expectResumeRejected: true,
5868 })
5869
David Benjaminf01f42a2016-11-16 19:05:33 +09005870 // Sessions are not resumed if they do not use the preferred cipher.
5871 testCases = append(testCases, testCase{
5872 testType: serverTest,
5873 name: "Resume-Server-CipherNotPreferred",
5874 resumeSession: true,
5875 config: Config{
5876 MaxVersion: VersionTLS12,
5877 Bugs: ProtocolBugs{
5878 ExpectNewTicket: true,
5879 FilterTicket: func(in []byte) ([]byte, error) {
5880 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5881 },
5882 },
5883 },
5884 flags: []string{
5885 "-ticket-key",
5886 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5887 },
5888 shouldFail: false,
5889 expectResumeRejected: true,
5890 })
5891
5892 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5893 // PRF hashes match, but BoringSSL will always decline such resumptions.
5894 testCases = append(testCases, testCase{
5895 testType: serverTest,
5896 name: "Resume-Server-CipherNotPreferred-TLS13",
5897 resumeSession: true,
5898 config: Config{
5899 MaxVersion: VersionTLS13,
5900 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5901 Bugs: ProtocolBugs{
5902 FilterTicket: func(in []byte) ([]byte, error) {
5903 // If the client (runner) offers ChaCha20-Poly1305 first, the
5904 // server (shim) always prefers it. Switch it to AES-GCM.
5905 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5906 },
5907 },
5908 },
5909 flags: []string{
5910 "-ticket-key",
5911 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5912 },
5913 shouldFail: false,
5914 expectResumeRejected: true,
5915 })
5916
5917 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005918 testCases = append(testCases, testCase{
5919 testType: serverTest,
5920 name: "Resume-Server-DeclineBadCipher-TLS13",
5921 resumeSession: true,
5922 config: Config{
5923 MaxVersion: VersionTLS13,
5924 Bugs: ProtocolBugs{
5925 FilterTicket: func(in []byte) ([]byte, error) {
5926 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5927 },
5928 },
5929 },
5930 flags: []string{
5931 "-ticket-key",
5932 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5933 },
5934 expectResumeRejected: true,
5935 })
5936
David Benjaminf01f42a2016-11-16 19:05:33 +09005937 // If the client does not offer the cipher from the session, decline to
5938 // resume. Clients are forbidden from doing this, but BoringSSL selects
5939 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005940 testCases = append(testCases, testCase{
5941 testType: serverTest,
5942 name: "Resume-Server-UnofferedCipher",
5943 resumeSession: true,
5944 config: Config{
5945 MaxVersion: VersionTLS12,
5946 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5947 },
5948 resumeConfig: &Config{
5949 MaxVersion: VersionTLS12,
5950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5951 Bugs: ProtocolBugs{
5952 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5953 },
5954 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005955 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005956 })
5957
David Benjaminf01f42a2016-11-16 19:05:33 +09005958 // In TLS 1.3, clients may advertise a cipher list which does not
5959 // include the selected cipher. Test that we tolerate this. Servers may
5960 // resume at another cipher if the PRF matches, but BoringSSL will
5961 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005962 testCases = append(testCases, testCase{
5963 testType: serverTest,
5964 name: "Resume-Server-UnofferedCipher-TLS13",
5965 resumeSession: true,
5966 config: Config{
5967 MaxVersion: VersionTLS13,
5968 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5969 },
5970 resumeConfig: &Config{
5971 MaxVersion: VersionTLS13,
5972 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5973 Bugs: ProtocolBugs{
5974 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5975 },
5976 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005977 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005978 })
5979
David Benjamin4199b0d2016-11-01 13:58:25 -04005980 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005981 testCases = append(testCases, testCase{
5982 name: "Resume-Client-CipherMismatch",
5983 resumeSession: true,
5984 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005985 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005986 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5987 },
5988 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005989 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005990 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5991 Bugs: ProtocolBugs{
5992 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5993 },
5994 },
5995 shouldFail: true,
5996 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5997 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005998
David Benjamine1cc35e2016-11-16 16:25:58 +09005999 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
6000 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04006001 testCases = append(testCases, testCase{
6002 name: "Resume-Client-CipherMismatch-TLS13",
6003 resumeSession: true,
6004 config: Config{
6005 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006006 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006007 },
6008 resumeConfig: &Config{
6009 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09006010 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
6011 },
6012 })
6013
6014 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
6015 testCases = append(testCases, testCase{
6016 name: "Resume-Client-PRFMismatch-TLS13",
6017 resumeSession: true,
6018 config: Config{
6019 MaxVersion: VersionTLS13,
6020 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
6021 },
6022 resumeConfig: &Config{
6023 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04006024 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04006025 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04006026 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04006027 },
6028 },
6029 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09006030 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04006031 })
Steven Valdeza833c352016-11-01 13:39:36 -04006032
6033 testCases = append(testCases, testCase{
6034 testType: serverTest,
6035 name: "Resume-Server-BinderWrongLength",
6036 resumeSession: true,
6037 config: Config{
6038 MaxVersion: VersionTLS13,
6039 Bugs: ProtocolBugs{
6040 SendShortPSKBinder: true,
6041 },
6042 },
6043 shouldFail: true,
6044 expectedLocalError: "remote error: error decrypting message",
6045 expectedError: ":DIGEST_CHECK_FAILED:",
6046 })
6047
6048 testCases = append(testCases, testCase{
6049 testType: serverTest,
6050 name: "Resume-Server-NoPSKBinder",
6051 resumeSession: true,
6052 config: Config{
6053 MaxVersion: VersionTLS13,
6054 Bugs: ProtocolBugs{
6055 SendNoPSKBinder: true,
6056 },
6057 },
6058 shouldFail: true,
6059 expectedLocalError: "remote error: error decoding message",
6060 expectedError: ":DECODE_ERROR:",
6061 })
6062
6063 testCases = append(testCases, testCase{
6064 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006065 name: "Resume-Server-ExtraPSKBinder",
6066 resumeSession: true,
6067 config: Config{
6068 MaxVersion: VersionTLS13,
6069 Bugs: ProtocolBugs{
6070 SendExtraPSKBinder: true,
6071 },
6072 },
6073 shouldFail: true,
6074 expectedLocalError: "remote error: illegal parameter",
6075 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6076 })
6077
6078 testCases = append(testCases, testCase{
6079 testType: serverTest,
6080 name: "Resume-Server-ExtraIdentityNoBinder",
6081 resumeSession: true,
6082 config: Config{
6083 MaxVersion: VersionTLS13,
6084 Bugs: ProtocolBugs{
6085 ExtraPSKIdentity: true,
6086 },
6087 },
6088 shouldFail: true,
6089 expectedLocalError: "remote error: illegal parameter",
6090 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6091 })
6092
6093 testCases = append(testCases, testCase{
6094 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006095 name: "Resume-Server-InvalidPSKBinder",
6096 resumeSession: true,
6097 config: Config{
6098 MaxVersion: VersionTLS13,
6099 Bugs: ProtocolBugs{
6100 SendInvalidPSKBinder: true,
6101 },
6102 },
6103 shouldFail: true,
6104 expectedLocalError: "remote error: error decrypting message",
6105 expectedError: ":DIGEST_CHECK_FAILED:",
6106 })
6107
6108 testCases = append(testCases, testCase{
6109 testType: serverTest,
6110 name: "Resume-Server-PSKBinderFirstExtension",
6111 resumeSession: true,
6112 config: Config{
6113 MaxVersion: VersionTLS13,
6114 Bugs: ProtocolBugs{
6115 PSKBinderFirst: true,
6116 },
6117 },
6118 shouldFail: true,
6119 expectedLocalError: "remote error: illegal parameter",
6120 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6121 })
David Benjamin01fe8202014-09-24 15:21:44 -04006122}
6123
Adam Langley2ae77d22014-10-28 17:29:33 -07006124func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006125 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006126 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006127 testType: serverTest,
6128 name: "Renegotiate-Server-Forbidden",
6129 config: Config{
6130 MaxVersion: VersionTLS12,
6131 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006132 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006133 shouldFail: true,
6134 expectedError: ":NO_RENEGOTIATION:",
6135 expectedLocalError: "remote error: no renegotiation",
6136 })
Adam Langley5021b222015-06-12 18:27:58 -07006137 // The server shouldn't echo the renegotiation extension unless
6138 // requested by the client.
6139 testCases = append(testCases, testCase{
6140 testType: serverTest,
6141 name: "Renegotiate-Server-NoExt",
6142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006143 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006144 Bugs: ProtocolBugs{
6145 NoRenegotiationInfo: true,
6146 RequireRenegotiationInfo: true,
6147 },
6148 },
6149 shouldFail: true,
6150 expectedLocalError: "renegotiation extension missing",
6151 })
6152 // The renegotiation SCSV should be sufficient for the server to echo
6153 // the extension.
6154 testCases = append(testCases, testCase{
6155 testType: serverTest,
6156 name: "Renegotiate-Server-NoExt-SCSV",
6157 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006158 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006159 Bugs: ProtocolBugs{
6160 NoRenegotiationInfo: true,
6161 SendRenegotiationSCSV: true,
6162 RequireRenegotiationInfo: true,
6163 },
6164 },
6165 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006166 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006167 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006169 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006170 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006171 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006172 },
6173 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006174 renegotiate: 1,
6175 flags: []string{
6176 "-renegotiate-freely",
6177 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006178 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006179 },
David Benjamincdea40c2015-03-19 14:09:43 -04006180 })
6181 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006182 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006183 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006185 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006186 Bugs: ProtocolBugs{
6187 EmptyRenegotiationInfo: true,
6188 },
6189 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006190 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006191 shouldFail: true,
6192 expectedError: ":RENEGOTIATION_MISMATCH:",
6193 })
6194 testCases = append(testCases, testCase{
6195 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006196 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006197 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006198 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006199 Bugs: ProtocolBugs{
6200 BadRenegotiationInfo: true,
6201 },
6202 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006203 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006204 shouldFail: true,
6205 expectedError: ":RENEGOTIATION_MISMATCH:",
6206 })
6207 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006208 name: "Renegotiate-Client-Downgrade",
6209 renegotiate: 1,
6210 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006211 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006212 Bugs: ProtocolBugs{
6213 NoRenegotiationInfoAfterInitial: true,
6214 },
6215 },
6216 flags: []string{"-renegotiate-freely"},
6217 shouldFail: true,
6218 expectedError: ":RENEGOTIATION_MISMATCH:",
6219 })
6220 testCases = append(testCases, testCase{
6221 name: "Renegotiate-Client-Upgrade",
6222 renegotiate: 1,
6223 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006224 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006225 Bugs: ProtocolBugs{
6226 NoRenegotiationInfoInInitial: true,
6227 },
6228 },
6229 flags: []string{"-renegotiate-freely"},
6230 shouldFail: true,
6231 expectedError: ":RENEGOTIATION_MISMATCH:",
6232 })
6233 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006234 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006235 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006236 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006237 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006238 Bugs: ProtocolBugs{
6239 NoRenegotiationInfo: true,
6240 },
6241 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006242 flags: []string{
6243 "-renegotiate-freely",
6244 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006245 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006246 },
David Benjamincff0b902015-05-15 23:09:47 -04006247 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006248
6249 // Test that the server may switch ciphers on renegotiation without
6250 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006251 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006252 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006253 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006254 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006255 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006256 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006257 },
6258 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006259 flags: []string{
6260 "-renegotiate-freely",
6261 "-expect-total-renegotiations", "1",
6262 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006263 })
6264 testCases = append(testCases, testCase{
6265 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006266 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006267 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006268 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006269 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6270 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006271 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006272 flags: []string{
6273 "-renegotiate-freely",
6274 "-expect-total-renegotiations", "1",
6275 },
David Benjaminb16346b2015-04-08 19:16:58 -04006276 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006277
6278 // Test that the server may not switch versions on renegotiation.
6279 testCases = append(testCases, testCase{
6280 name: "Renegotiate-Client-SwitchVersion",
6281 config: Config{
6282 MaxVersion: VersionTLS12,
6283 // Pick a cipher which exists at both versions.
6284 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6285 Bugs: ProtocolBugs{
6286 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006287 // Avoid failing early at the record layer.
6288 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006289 },
6290 },
6291 renegotiate: 1,
6292 flags: []string{
6293 "-renegotiate-freely",
6294 "-expect-total-renegotiations", "1",
6295 },
6296 shouldFail: true,
6297 expectedError: ":WRONG_SSL_VERSION:",
6298 })
6299
David Benjaminb16346b2015-04-08 19:16:58 -04006300 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006301 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006302 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006303 config: Config{
6304 MaxVersion: VersionTLS10,
6305 Bugs: ProtocolBugs{
6306 RequireSameRenegoClientVersion: true,
6307 },
6308 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006309 flags: []string{
6310 "-renegotiate-freely",
6311 "-expect-total-renegotiations", "1",
6312 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006313 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006314 testCases = append(testCases, testCase{
6315 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006316 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006317 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006318 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006319 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6320 NextProtos: []string{"foo"},
6321 },
6322 flags: []string{
6323 "-false-start",
6324 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006325 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006326 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006327 },
6328 shimWritesFirst: true,
6329 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006330
6331 // Client-side renegotiation controls.
6332 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006333 name: "Renegotiate-Client-Forbidden-1",
6334 config: Config{
6335 MaxVersion: VersionTLS12,
6336 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006337 renegotiate: 1,
6338 shouldFail: true,
6339 expectedError: ":NO_RENEGOTIATION:",
6340 expectedLocalError: "remote error: no renegotiation",
6341 })
6342 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006343 name: "Renegotiate-Client-Once-1",
6344 config: Config{
6345 MaxVersion: VersionTLS12,
6346 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006347 renegotiate: 1,
6348 flags: []string{
6349 "-renegotiate-once",
6350 "-expect-total-renegotiations", "1",
6351 },
6352 })
6353 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006354 name: "Renegotiate-Client-Freely-1",
6355 config: Config{
6356 MaxVersion: VersionTLS12,
6357 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006358 renegotiate: 1,
6359 flags: []string{
6360 "-renegotiate-freely",
6361 "-expect-total-renegotiations", "1",
6362 },
6363 })
6364 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006365 name: "Renegotiate-Client-Once-2",
6366 config: Config{
6367 MaxVersion: VersionTLS12,
6368 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006369 renegotiate: 2,
6370 flags: []string{"-renegotiate-once"},
6371 shouldFail: true,
6372 expectedError: ":NO_RENEGOTIATION:",
6373 expectedLocalError: "remote error: no renegotiation",
6374 })
6375 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006376 name: "Renegotiate-Client-Freely-2",
6377 config: Config{
6378 MaxVersion: VersionTLS12,
6379 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006380 renegotiate: 2,
6381 flags: []string{
6382 "-renegotiate-freely",
6383 "-expect-total-renegotiations", "2",
6384 },
6385 })
Adam Langley27a0d082015-11-03 13:34:10 -08006386 testCases = append(testCases, testCase{
6387 name: "Renegotiate-Client-NoIgnore",
6388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006389 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006390 Bugs: ProtocolBugs{
6391 SendHelloRequestBeforeEveryAppDataRecord: true,
6392 },
6393 },
6394 shouldFail: true,
6395 expectedError: ":NO_RENEGOTIATION:",
6396 })
6397 testCases = append(testCases, testCase{
6398 name: "Renegotiate-Client-Ignore",
6399 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006400 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006401 Bugs: ProtocolBugs{
6402 SendHelloRequestBeforeEveryAppDataRecord: true,
6403 },
6404 },
6405 flags: []string{
6406 "-renegotiate-ignore",
6407 "-expect-total-renegotiations", "0",
6408 },
6409 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006410
David Benjamin34941c02016-10-08 11:45:31 -04006411 // Renegotiation is not allowed at SSL 3.0.
6412 testCases = append(testCases, testCase{
6413 name: "Renegotiate-Client-SSL3",
6414 config: Config{
6415 MaxVersion: VersionSSL30,
6416 },
6417 renegotiate: 1,
6418 flags: []string{
6419 "-renegotiate-freely",
6420 "-expect-total-renegotiations", "1",
6421 },
6422 shouldFail: true,
6423 expectedError: ":NO_RENEGOTIATION:",
6424 expectedLocalError: "remote error: no renegotiation",
6425 })
6426
David Benjamina1eaba12017-01-01 23:19:22 -05006427 // Renegotiation is not allowed when there is an unfinished write.
6428 testCases = append(testCases, testCase{
6429 name: "Renegotiate-Client-UnfinishedWrite",
6430 config: Config{
6431 MaxVersion: VersionTLS12,
6432 },
6433 renegotiate: 1,
6434 flags: []string{
6435 "-async",
6436 "-renegotiate-freely",
6437 "-read-with-unfinished-write",
6438 },
6439 shouldFail: true,
6440 expectedError: ":NO_RENEGOTIATION:",
6441 // We do not successfully send the no_renegotiation alert in
6442 // this case. https://crbug.com/boringssl/130
6443 })
6444
David Benjamin07ab5d42017-02-09 20:11:41 -05006445 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006446 testCases = append(testCases, testCase{
6447 name: "StrayHelloRequest",
6448 config: Config{
6449 MaxVersion: VersionTLS12,
6450 Bugs: ProtocolBugs{
6451 SendHelloRequestBeforeEveryHandshakeMessage: true,
6452 },
6453 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006454 shouldFail: true,
6455 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006456 })
6457 testCases = append(testCases, testCase{
6458 name: "StrayHelloRequest-Packed",
6459 config: Config{
6460 MaxVersion: VersionTLS12,
6461 Bugs: ProtocolBugs{
6462 PackHandshakeFlight: true,
6463 SendHelloRequestBeforeEveryHandshakeMessage: true,
6464 },
6465 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006466 shouldFail: true,
6467 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006468 })
6469
David Benjamin12d2c482016-07-24 10:56:51 -04006470 // Test renegotiation works if HelloRequest and server Finished come in
6471 // the same record.
6472 testCases = append(testCases, testCase{
6473 name: "Renegotiate-Client-Packed",
6474 config: Config{
6475 MaxVersion: VersionTLS12,
6476 Bugs: ProtocolBugs{
6477 PackHandshakeFlight: true,
6478 PackHelloRequestWithFinished: true,
6479 },
6480 },
6481 renegotiate: 1,
6482 flags: []string{
6483 "-renegotiate-freely",
6484 "-expect-total-renegotiations", "1",
6485 },
6486 })
6487
David Benjamin397c8e62016-07-08 14:14:36 -07006488 // Renegotiation is forbidden in TLS 1.3.
6489 testCases = append(testCases, testCase{
6490 name: "Renegotiate-Client-TLS13",
6491 config: Config{
6492 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006493 Bugs: ProtocolBugs{
6494 SendHelloRequestBeforeEveryAppDataRecord: true,
6495 },
David Benjamin397c8e62016-07-08 14:14:36 -07006496 },
David Benjamin397c8e62016-07-08 14:14:36 -07006497 flags: []string{
6498 "-renegotiate-freely",
6499 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006500 shouldFail: true,
6501 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006502 })
6503
6504 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6505 testCases = append(testCases, testCase{
6506 name: "StrayHelloRequest-TLS13",
6507 config: Config{
6508 MaxVersion: VersionTLS13,
6509 Bugs: ProtocolBugs{
6510 SendHelloRequestBeforeEveryHandshakeMessage: true,
6511 },
6512 },
6513 shouldFail: true,
6514 expectedError: ":UNEXPECTED_MESSAGE:",
6515 })
David Benjamind2610042017-01-03 10:49:28 -05006516
6517 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6518 // always reads as supporting it, regardless of whether it was
6519 // negotiated.
6520 testCases = append(testCases, testCase{
6521 name: "AlwaysReportRenegotiationInfo-TLS13",
6522 config: Config{
6523 MaxVersion: VersionTLS13,
6524 Bugs: ProtocolBugs{
6525 NoRenegotiationInfo: true,
6526 },
6527 },
6528 flags: []string{
6529 "-expect-secure-renegotiation",
6530 },
6531 })
David Benjamina58baaf2017-02-28 20:54:28 -05006532
6533 // Certificates may not change on renegotiation.
6534 testCases = append(testCases, testCase{
6535 name: "Renegotiation-CertificateChange",
6536 config: Config{
6537 MaxVersion: VersionTLS12,
6538 Certificates: []Certificate{rsaCertificate},
6539 Bugs: ProtocolBugs{
6540 RenegotiationCertificate: &rsaChainCertificate,
6541 },
6542 },
6543 renegotiate: 1,
6544 flags: []string{"-renegotiate-freely"},
6545 shouldFail: true,
6546 expectedError: ":SERVER_CERT_CHANGED:",
6547 })
6548 testCases = append(testCases, testCase{
6549 name: "Renegotiation-CertificateChange-2",
6550 config: Config{
6551 MaxVersion: VersionTLS12,
6552 Certificates: []Certificate{rsaCertificate},
6553 Bugs: ProtocolBugs{
6554 RenegotiationCertificate: &rsa1024Certificate,
6555 },
6556 },
6557 renegotiate: 1,
6558 flags: []string{"-renegotiate-freely"},
6559 shouldFail: true,
6560 expectedError: ":SERVER_CERT_CHANGED:",
6561 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006562}
6563
David Benjamin5e961c12014-11-07 01:48:35 -05006564func addDTLSReplayTests() {
6565 // Test that sequence number replays are detected.
6566 testCases = append(testCases, testCase{
6567 protocol: dtls,
6568 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006569 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006570 replayWrites: true,
6571 })
6572
David Benjamin8e6db492015-07-25 18:29:23 -04006573 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006574 // than the retransmit window.
6575 testCases = append(testCases, testCase{
6576 protocol: dtls,
6577 name: "DTLS-Replay-LargeGaps",
6578 config: Config{
6579 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006580 SequenceNumberMapping: func(in uint64) uint64 {
6581 return in * 127
6582 },
David Benjamin5e961c12014-11-07 01:48:35 -05006583 },
6584 },
David Benjamin8e6db492015-07-25 18:29:23 -04006585 messageCount: 200,
6586 replayWrites: true,
6587 })
6588
6589 // Test the incoming sequence number changing non-monotonically.
6590 testCases = append(testCases, testCase{
6591 protocol: dtls,
6592 name: "DTLS-Replay-NonMonotonic",
6593 config: Config{
6594 Bugs: ProtocolBugs{
6595 SequenceNumberMapping: func(in uint64) uint64 {
6596 return in ^ 31
6597 },
6598 },
6599 },
6600 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006601 replayWrites: true,
6602 })
6603}
6604
Nick Harper60edffd2016-06-21 15:19:24 -07006605var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006606 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006607 id signatureAlgorithm
6608 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006609}{
Nick Harper60edffd2016-06-21 15:19:24 -07006610 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6611 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6612 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6613 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006614 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006615 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6616 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6617 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006618 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6619 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6620 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006621 // Tests for key types prior to TLS 1.2.
6622 {"RSA", 0, testCertRSA},
6623 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006624}
6625
Nick Harper60edffd2016-06-21 15:19:24 -07006626const fakeSigAlg1 signatureAlgorithm = 0x2a01
6627const fakeSigAlg2 signatureAlgorithm = 0xff01
6628
6629func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006630 // Not all ciphers involve a signature. Advertise a list which gives all
6631 // versions a signing cipher.
6632 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006633 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006634 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6635 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6636 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6637 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006638 }
6639 if *includeDHE {
6640 signingCiphers = append(signingCiphers, TLS_DHE_RSA_WITH_AES_128_CBC_SHA)
David Benjamin5208fd42016-07-13 21:43:25 -04006641 }
6642
David Benjaminca3d5452016-07-14 12:51:01 -04006643 var allAlgorithms []signatureAlgorithm
6644 for _, alg := range testSignatureAlgorithms {
6645 if alg.id != 0 {
6646 allAlgorithms = append(allAlgorithms, alg.id)
6647 }
6648 }
6649
Nick Harper60edffd2016-06-21 15:19:24 -07006650 // Make sure each signature algorithm works. Include some fake values in
6651 // the list and ensure they're ignored.
6652 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006653 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006654 if (ver.version < VersionTLS12) != (alg.id == 0) {
6655 continue
6656 }
6657
6658 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6659 // or remove it in C.
6660 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006661 continue
6662 }
Nick Harper60edffd2016-06-21 15:19:24 -07006663
David Benjamin3ef76972016-10-17 17:59:54 -04006664 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006665 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006666 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006667 shouldSignFail = true
6668 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006669 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006670 // RSA-PKCS1 does not exist in TLS 1.3.
6671 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006672 shouldSignFail = true
6673 shouldVerifyFail = true
6674 }
6675
6676 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6677 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6678 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006679 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006680
6681 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006682 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006683 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006684 }
6685 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006686 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006687 }
David Benjamin000800a2014-11-14 01:43:59 -05006688
David Benjamin1fb125c2016-07-08 18:52:12 -07006689 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006690
David Benjamin7a41d372016-07-09 11:21:54 -07006691 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006692 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006693 config: Config{
6694 MaxVersion: ver.version,
6695 ClientAuth: RequireAnyClientCert,
6696 VerifySignatureAlgorithms: []signatureAlgorithm{
6697 fakeSigAlg1,
6698 alg.id,
6699 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006700 },
David Benjamin7a41d372016-07-09 11:21:54 -07006701 },
6702 flags: []string{
6703 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6704 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6705 "-enable-all-curves",
6706 },
David Benjamin3ef76972016-10-17 17:59:54 -04006707 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006708 expectedError: signError,
6709 expectedPeerSignatureAlgorithm: alg.id,
6710 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006711
David Benjamin7a41d372016-07-09 11:21:54 -07006712 testCases = append(testCases, testCase{
6713 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006714 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006715 config: Config{
6716 MaxVersion: ver.version,
6717 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6718 SignSignatureAlgorithms: []signatureAlgorithm{
6719 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006720 },
David Benjamin7a41d372016-07-09 11:21:54 -07006721 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006722 SkipECDSACurveCheck: shouldVerifyFail,
6723 IgnoreSignatureVersionChecks: shouldVerifyFail,
6724 // Some signature algorithms may not be advertised.
6725 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006726 },
David Benjamin7a41d372016-07-09 11:21:54 -07006727 },
6728 flags: []string{
6729 "-require-any-client-certificate",
6730 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6731 "-enable-all-curves",
6732 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006733 // Resume the session to assert the peer signature
6734 // algorithm is reported on both handshakes.
6735 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006736 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006737 expectedError: verifyError,
6738 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006739
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006740 // No signing cipher for SSL 3.0.
6741 if *includeDHE || ver.version > VersionSSL30 {
6742 testCases = append(testCases, testCase{
6743 testType: serverTest,
6744 name: "ServerAuth-Sign" + suffix,
6745 config: Config{
6746 MaxVersion: ver.version,
6747 CipherSuites: signingCiphers,
6748 VerifySignatureAlgorithms: []signatureAlgorithm{
6749 fakeSigAlg1,
6750 alg.id,
6751 fakeSigAlg2,
6752 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006753 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07006754 flags: []string{
6755 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6756 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6757 "-enable-all-curves",
6758 },
6759 shouldFail: shouldSignFail,
6760 expectedError: signError,
6761 expectedPeerSignatureAlgorithm: alg.id,
6762 })
6763 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006764
6765 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006766 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006767 config: Config{
6768 MaxVersion: ver.version,
6769 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006770 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006771 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006772 alg.id,
6773 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006774 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006775 SkipECDSACurveCheck: shouldVerifyFail,
6776 IgnoreSignatureVersionChecks: shouldVerifyFail,
6777 // Some signature algorithms may not be advertised.
6778 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006779 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006780 },
6781 flags: []string{
6782 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6783 "-enable-all-curves",
6784 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006785 // Resume the session to assert the peer signature
6786 // algorithm is reported on both handshakes.
6787 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006788 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006789 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006790 })
David Benjamin5208fd42016-07-13 21:43:25 -04006791
David Benjamin3ef76972016-10-17 17:59:54 -04006792 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006793 testCases = append(testCases, testCase{
6794 testType: serverTest,
6795 name: "ClientAuth-InvalidSignature" + suffix,
6796 config: Config{
6797 MaxVersion: ver.version,
6798 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6799 SignSignatureAlgorithms: []signatureAlgorithm{
6800 alg.id,
6801 },
6802 Bugs: ProtocolBugs{
6803 InvalidSignature: true,
6804 },
6805 },
6806 flags: []string{
6807 "-require-any-client-certificate",
6808 "-enable-all-curves",
6809 },
6810 shouldFail: true,
6811 expectedError: ":BAD_SIGNATURE:",
6812 })
6813
6814 testCases = append(testCases, testCase{
6815 name: "ServerAuth-InvalidSignature" + suffix,
6816 config: Config{
6817 MaxVersion: ver.version,
6818 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6819 CipherSuites: signingCiphers,
6820 SignSignatureAlgorithms: []signatureAlgorithm{
6821 alg.id,
6822 },
6823 Bugs: ProtocolBugs{
6824 InvalidSignature: true,
6825 },
6826 },
6827 flags: []string{"-enable-all-curves"},
6828 shouldFail: true,
6829 expectedError: ":BAD_SIGNATURE:",
6830 })
6831 }
David Benjaminca3d5452016-07-14 12:51:01 -04006832
David Benjamin3ef76972016-10-17 17:59:54 -04006833 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006834 testCases = append(testCases, testCase{
6835 name: "ClientAuth-Sign-Negotiate" + suffix,
6836 config: Config{
6837 MaxVersion: ver.version,
6838 ClientAuth: RequireAnyClientCert,
6839 VerifySignatureAlgorithms: allAlgorithms,
6840 },
6841 flags: []string{
6842 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6843 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6844 "-enable-all-curves",
6845 "-signing-prefs", strconv.Itoa(int(alg.id)),
6846 },
6847 expectedPeerSignatureAlgorithm: alg.id,
6848 })
6849
6850 testCases = append(testCases, testCase{
6851 testType: serverTest,
6852 name: "ServerAuth-Sign-Negotiate" + suffix,
6853 config: Config{
6854 MaxVersion: ver.version,
6855 CipherSuites: signingCiphers,
6856 VerifySignatureAlgorithms: allAlgorithms,
6857 },
6858 flags: []string{
6859 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6860 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6861 "-enable-all-curves",
6862 "-signing-prefs", strconv.Itoa(int(alg.id)),
6863 },
6864 expectedPeerSignatureAlgorithm: alg.id,
6865 })
6866 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006867 }
David Benjamin000800a2014-11-14 01:43:59 -05006868 }
6869
Nick Harper60edffd2016-06-21 15:19:24 -07006870 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006871 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006872 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006873 config: Config{
6874 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006875 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006876 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006877 signatureECDSAWithP521AndSHA512,
6878 signatureRSAPKCS1WithSHA384,
6879 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006880 },
6881 },
6882 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006883 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6884 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006885 },
Nick Harper60edffd2016-06-21 15:19:24 -07006886 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006887 })
6888
6889 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006890 name: "ClientAuth-SignatureType-TLS13",
6891 config: Config{
6892 ClientAuth: RequireAnyClientCert,
6893 MaxVersion: VersionTLS13,
6894 VerifySignatureAlgorithms: []signatureAlgorithm{
6895 signatureECDSAWithP521AndSHA512,
6896 signatureRSAPKCS1WithSHA384,
6897 signatureRSAPSSWithSHA384,
6898 signatureECDSAWithSHA1,
6899 },
6900 },
6901 flags: []string{
6902 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6903 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6904 },
6905 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6906 })
6907
6908 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006909 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006910 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006912 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006913 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006914 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006915 signatureECDSAWithP521AndSHA512,
6916 signatureRSAPKCS1WithSHA384,
6917 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006918 },
6919 },
Nick Harper60edffd2016-06-21 15:19:24 -07006920 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006921 })
6922
Steven Valdez143e8b32016-07-11 13:19:03 -04006923 testCases = append(testCases, testCase{
6924 testType: serverTest,
6925 name: "ServerAuth-SignatureType-TLS13",
6926 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006927 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006928 VerifySignatureAlgorithms: []signatureAlgorithm{
6929 signatureECDSAWithP521AndSHA512,
6930 signatureRSAPKCS1WithSHA384,
6931 signatureRSAPSSWithSHA384,
6932 signatureECDSAWithSHA1,
6933 },
6934 },
6935 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6936 })
6937
David Benjamina95e9f32016-07-08 16:28:04 -07006938 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006939 testCases = append(testCases, testCase{
6940 testType: serverTest,
6941 name: "Verify-ClientAuth-SignatureType",
6942 config: Config{
6943 MaxVersion: VersionTLS12,
6944 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006945 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006946 signatureRSAPKCS1WithSHA256,
6947 },
6948 Bugs: ProtocolBugs{
6949 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6950 },
6951 },
6952 flags: []string{
6953 "-require-any-client-certificate",
6954 },
6955 shouldFail: true,
6956 expectedError: ":WRONG_SIGNATURE_TYPE:",
6957 })
6958
6959 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006960 testType: serverTest,
6961 name: "Verify-ClientAuth-SignatureType-TLS13",
6962 config: Config{
6963 MaxVersion: VersionTLS13,
6964 Certificates: []Certificate{rsaCertificate},
6965 SignSignatureAlgorithms: []signatureAlgorithm{
6966 signatureRSAPSSWithSHA256,
6967 },
6968 Bugs: ProtocolBugs{
6969 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6970 },
6971 },
6972 flags: []string{
6973 "-require-any-client-certificate",
6974 },
6975 shouldFail: true,
6976 expectedError: ":WRONG_SIGNATURE_TYPE:",
6977 })
6978
6979 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006980 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006981 config: Config{
6982 MaxVersion: VersionTLS12,
6983 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006984 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006985 signatureRSAPKCS1WithSHA256,
6986 },
6987 Bugs: ProtocolBugs{
6988 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6989 },
6990 },
6991 shouldFail: true,
6992 expectedError: ":WRONG_SIGNATURE_TYPE:",
6993 })
6994
Steven Valdez143e8b32016-07-11 13:19:03 -04006995 testCases = append(testCases, testCase{
6996 name: "Verify-ServerAuth-SignatureType-TLS13",
6997 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006998 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006999 SignSignatureAlgorithms: []signatureAlgorithm{
7000 signatureRSAPSSWithSHA256,
7001 },
7002 Bugs: ProtocolBugs{
7003 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7004 },
7005 },
7006 shouldFail: true,
7007 expectedError: ":WRONG_SIGNATURE_TYPE:",
7008 })
7009
David Benjamin51dd7d62016-07-08 16:07:01 -07007010 // Test that, if the list is missing, the peer falls back to SHA-1 in
7011 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05007012 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04007013 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007015 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05007016 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007017 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007018 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007019 },
7020 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007021 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007022 },
7023 },
7024 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07007025 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7026 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05007027 },
7028 })
7029
7030 testCases = append(testCases, testCase{
7031 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04007032 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05007033 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04007034 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07007035 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007036 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05007037 },
7038 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07007039 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05007040 },
7041 },
David Benjaminee32bea2016-08-17 13:36:44 -04007042 flags: []string{
7043 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7044 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7045 },
7046 })
7047
7048 testCases = append(testCases, testCase{
7049 name: "ClientAuth-SHA1-Fallback-ECDSA",
7050 config: Config{
7051 MaxVersion: VersionTLS12,
7052 ClientAuth: RequireAnyClientCert,
7053 VerifySignatureAlgorithms: []signatureAlgorithm{
7054 signatureECDSAWithSHA1,
7055 },
7056 Bugs: ProtocolBugs{
7057 NoSignatureAlgorithms: true,
7058 },
7059 },
7060 flags: []string{
7061 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7062 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7063 },
7064 })
7065
7066 testCases = append(testCases, testCase{
7067 testType: serverTest,
7068 name: "ServerAuth-SHA1-Fallback-ECDSA",
7069 config: Config{
7070 MaxVersion: VersionTLS12,
7071 VerifySignatureAlgorithms: []signatureAlgorithm{
7072 signatureECDSAWithSHA1,
7073 },
7074 Bugs: ProtocolBugs{
7075 NoSignatureAlgorithms: true,
7076 },
7077 },
7078 flags: []string{
7079 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7080 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7081 },
David Benjamin000800a2014-11-14 01:43:59 -05007082 })
David Benjamin72dc7832015-03-16 17:49:43 -04007083
David Benjamin51dd7d62016-07-08 16:07:01 -07007084 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007085 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007086 config: Config{
7087 MaxVersion: VersionTLS13,
7088 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007089 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007090 signatureRSAPKCS1WithSHA1,
7091 },
7092 Bugs: ProtocolBugs{
7093 NoSignatureAlgorithms: true,
7094 },
7095 },
7096 flags: []string{
7097 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7098 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7099 },
David Benjamin48901652016-08-01 12:12:47 -04007100 shouldFail: true,
7101 // An empty CertificateRequest signature algorithm list is a
7102 // syntax error in TLS 1.3.
7103 expectedError: ":DECODE_ERROR:",
7104 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007105 })
7106
7107 testCases = append(testCases, testCase{
7108 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007109 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007110 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007111 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007112 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007113 signatureRSAPKCS1WithSHA1,
7114 },
7115 Bugs: ProtocolBugs{
7116 NoSignatureAlgorithms: true,
7117 },
7118 },
7119 shouldFail: true,
7120 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7121 })
7122
David Benjaminb62d2872016-07-18 14:55:02 +02007123 // Test that hash preferences are enforced. BoringSSL does not implement
7124 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007125 testCases = append(testCases, testCase{
7126 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007127 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007129 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007130 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007131 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007132 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007133 },
7134 Bugs: ProtocolBugs{
7135 IgnorePeerSignatureAlgorithmPreferences: true,
7136 },
7137 },
7138 flags: []string{"-require-any-client-certificate"},
7139 shouldFail: true,
7140 expectedError: ":WRONG_SIGNATURE_TYPE:",
7141 })
7142
7143 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007144 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007145 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007146 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007147 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007148 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007149 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007150 },
7151 Bugs: ProtocolBugs{
7152 IgnorePeerSignatureAlgorithmPreferences: true,
7153 },
7154 },
7155 shouldFail: true,
7156 expectedError: ":WRONG_SIGNATURE_TYPE:",
7157 })
David Benjaminb62d2872016-07-18 14:55:02 +02007158 testCases = append(testCases, testCase{
7159 testType: serverTest,
7160 name: "ClientAuth-Enforced-TLS13",
7161 config: Config{
7162 MaxVersion: VersionTLS13,
7163 Certificates: []Certificate{rsaCertificate},
7164 SignSignatureAlgorithms: []signatureAlgorithm{
7165 signatureRSAPKCS1WithMD5,
7166 },
7167 Bugs: ProtocolBugs{
7168 IgnorePeerSignatureAlgorithmPreferences: true,
7169 IgnoreSignatureVersionChecks: true,
7170 },
7171 },
7172 flags: []string{"-require-any-client-certificate"},
7173 shouldFail: true,
7174 expectedError: ":WRONG_SIGNATURE_TYPE:",
7175 })
7176
7177 testCases = append(testCases, testCase{
7178 name: "ServerAuth-Enforced-TLS13",
7179 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007180 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007181 SignSignatureAlgorithms: []signatureAlgorithm{
7182 signatureRSAPKCS1WithMD5,
7183 },
7184 Bugs: ProtocolBugs{
7185 IgnorePeerSignatureAlgorithmPreferences: true,
7186 IgnoreSignatureVersionChecks: true,
7187 },
7188 },
7189 shouldFail: true,
7190 expectedError: ":WRONG_SIGNATURE_TYPE:",
7191 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007192
7193 // Test that the agreed upon digest respects the client preferences and
7194 // the server digests.
7195 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007196 name: "NoCommonAlgorithms-Digests",
7197 config: Config{
7198 MaxVersion: VersionTLS12,
7199 ClientAuth: RequireAnyClientCert,
7200 VerifySignatureAlgorithms: []signatureAlgorithm{
7201 signatureRSAPKCS1WithSHA512,
7202 signatureRSAPKCS1WithSHA1,
7203 },
7204 },
7205 flags: []string{
7206 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7207 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7208 "-digest-prefs", "SHA256",
7209 },
7210 shouldFail: true,
7211 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7212 })
7213 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007214 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007216 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007217 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007218 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007219 signatureRSAPKCS1WithSHA512,
7220 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007221 },
7222 },
7223 flags: []string{
7224 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7225 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007226 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007227 },
David Benjaminca3d5452016-07-14 12:51:01 -04007228 shouldFail: true,
7229 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7230 })
7231 testCases = append(testCases, testCase{
7232 name: "NoCommonAlgorithms-TLS13",
7233 config: Config{
7234 MaxVersion: VersionTLS13,
7235 ClientAuth: RequireAnyClientCert,
7236 VerifySignatureAlgorithms: []signatureAlgorithm{
7237 signatureRSAPSSWithSHA512,
7238 signatureRSAPSSWithSHA384,
7239 },
7240 },
7241 flags: []string{
7242 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7243 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7244 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7245 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007246 shouldFail: true,
7247 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007248 })
7249 testCases = append(testCases, testCase{
7250 name: "Agree-Digest-SHA256",
7251 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007252 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007253 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007254 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007255 signatureRSAPKCS1WithSHA1,
7256 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007257 },
7258 },
7259 flags: []string{
7260 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7261 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007262 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007263 },
Nick Harper60edffd2016-06-21 15:19:24 -07007264 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007265 })
7266 testCases = append(testCases, testCase{
7267 name: "Agree-Digest-SHA1",
7268 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007269 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007270 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007271 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007272 signatureRSAPKCS1WithSHA1,
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),
David Benjaminca3d5452016-07-14 12:51:01 -04007278 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007279 },
Nick Harper60edffd2016-06-21 15:19:24 -07007280 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007281 })
7282 testCases = append(testCases, testCase{
7283 name: "Agree-Digest-Default",
7284 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007285 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007286 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007287 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007288 signatureRSAPKCS1WithSHA256,
7289 signatureECDSAWithP256AndSHA256,
7290 signatureRSAPKCS1WithSHA1,
7291 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007292 },
7293 },
7294 flags: []string{
7295 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7296 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7297 },
Nick Harper60edffd2016-06-21 15:19:24 -07007298 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007299 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007300
David Benjaminca3d5452016-07-14 12:51:01 -04007301 // Test that the signing preference list may include extra algorithms
7302 // without negotiation problems.
7303 testCases = append(testCases, testCase{
7304 testType: serverTest,
7305 name: "FilterExtraAlgorithms",
7306 config: Config{
7307 MaxVersion: VersionTLS12,
7308 VerifySignatureAlgorithms: []signatureAlgorithm{
7309 signatureRSAPKCS1WithSHA256,
7310 },
7311 },
7312 flags: []string{
7313 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7314 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7315 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7316 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7317 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7318 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7319 },
7320 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7321 })
7322
David Benjamin4c3ddf72016-06-29 18:13:53 -04007323 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7324 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007325 testCases = append(testCases, testCase{
7326 name: "CheckLeafCurve",
7327 config: Config{
7328 MaxVersion: VersionTLS12,
7329 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007330 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007331 },
7332 flags: []string{"-p384-only"},
7333 shouldFail: true,
7334 expectedError: ":BAD_ECC_CERT:",
7335 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007336
7337 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7338 testCases = append(testCases, testCase{
7339 name: "CheckLeafCurve-TLS13",
7340 config: Config{
7341 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007342 Certificates: []Certificate{ecdsaP256Certificate},
7343 },
7344 flags: []string{"-p384-only"},
7345 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007346
7347 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7348 testCases = append(testCases, testCase{
7349 name: "ECDSACurveMismatch-Verify-TLS12",
7350 config: Config{
7351 MaxVersion: VersionTLS12,
7352 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7353 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007354 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007355 signatureECDSAWithP384AndSHA384,
7356 },
7357 },
7358 })
7359
7360 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7361 testCases = append(testCases, testCase{
7362 name: "ECDSACurveMismatch-Verify-TLS13",
7363 config: Config{
7364 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007365 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007366 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007367 signatureECDSAWithP384AndSHA384,
7368 },
7369 Bugs: ProtocolBugs{
7370 SkipECDSACurveCheck: true,
7371 },
7372 },
7373 shouldFail: true,
7374 expectedError: ":WRONG_SIGNATURE_TYPE:",
7375 })
7376
7377 // Signature algorithm selection in TLS 1.3 should take the curve into
7378 // account.
7379 testCases = append(testCases, testCase{
7380 testType: serverTest,
7381 name: "ECDSACurveMismatch-Sign-TLS13",
7382 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007383 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007384 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007385 signatureECDSAWithP384AndSHA384,
7386 signatureECDSAWithP256AndSHA256,
7387 },
7388 },
7389 flags: []string{
7390 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7391 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7392 },
7393 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7394 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007395
7396 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7397 // server does not attempt to sign in that case.
7398 testCases = append(testCases, testCase{
7399 testType: serverTest,
7400 name: "RSA-PSS-Large",
7401 config: Config{
7402 MaxVersion: VersionTLS13,
7403 VerifySignatureAlgorithms: []signatureAlgorithm{
7404 signatureRSAPSSWithSHA512,
7405 },
7406 },
7407 flags: []string{
7408 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7409 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7410 },
7411 shouldFail: true,
7412 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7413 })
David Benjamin57e929f2016-08-30 00:30:38 -04007414
7415 // Test that RSA-PSS is enabled by default for TLS 1.2.
7416 testCases = append(testCases, testCase{
7417 testType: clientTest,
7418 name: "RSA-PSS-Default-Verify",
7419 config: Config{
7420 MaxVersion: VersionTLS12,
7421 SignSignatureAlgorithms: []signatureAlgorithm{
7422 signatureRSAPSSWithSHA256,
7423 },
7424 },
7425 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7426 })
7427
7428 testCases = append(testCases, testCase{
7429 testType: serverTest,
7430 name: "RSA-PSS-Default-Sign",
7431 config: Config{
7432 MaxVersion: VersionTLS12,
7433 VerifySignatureAlgorithms: []signatureAlgorithm{
7434 signatureRSAPSSWithSHA256,
7435 },
7436 },
7437 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7438 })
Adam Langley898be922017-02-27 12:37:59 -08007439
7440 // A server certificate with a P-224 key will only work up to TLS 1.2
7441 // and we only test it with BoringSSL acting as a server because that's
7442 // all Alphabet requires with it.
7443 testCases = append(testCases, testCase{
7444 testType: serverTest,
7445 name: "P224-Server",
7446 config: Config{
7447 VerifySignatureAlgorithms: []signatureAlgorithm{
7448 // TLS 1.2 does not require that the curve
7449 // match the hash, thus P-256 with SHA-256 is
7450 // the same signature algorithm value as P-224
7451 // with SHA-256.
7452 signatureECDSAWithP256AndSHA256,
7453 },
7454 // P-256 must be offered as well because ECDHE requires
7455 // it.
7456 CurvePreferences: []CurveID{CurveP224, CurveP256},
7457 },
7458 flags: []string{
7459 "-max-version", strconv.Itoa(VersionTLS12),
7460 "-cert-file", path.Join(*resourceDir, ecdsaP224CertificateFile),
7461 "-key-file", path.Join(*resourceDir, ecdsaP224KeyFile),
7462 },
7463 })
David Benjamin000800a2014-11-14 01:43:59 -05007464}
7465
David Benjamin83f90402015-01-27 01:09:43 -05007466// timeouts is the retransmit schedule for BoringSSL. It doubles and
7467// caps at 60 seconds. On the 13th timeout, it gives up.
7468var timeouts = []time.Duration{
7469 1 * time.Second,
7470 2 * time.Second,
7471 4 * time.Second,
7472 8 * time.Second,
7473 16 * time.Second,
7474 32 * time.Second,
7475 60 * time.Second,
7476 60 * time.Second,
7477 60 * time.Second,
7478 60 * time.Second,
7479 60 * time.Second,
7480 60 * time.Second,
7481 60 * time.Second,
7482}
7483
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007484// shortTimeouts is an alternate set of timeouts which would occur if the
7485// initial timeout duration was set to 250ms.
7486var shortTimeouts = []time.Duration{
7487 250 * time.Millisecond,
7488 500 * time.Millisecond,
7489 1 * time.Second,
7490 2 * time.Second,
7491 4 * time.Second,
7492 8 * time.Second,
7493 16 * time.Second,
7494 32 * time.Second,
7495 60 * time.Second,
7496 60 * time.Second,
7497 60 * time.Second,
7498 60 * time.Second,
7499 60 * time.Second,
7500}
7501
David Benjamin83f90402015-01-27 01:09:43 -05007502func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007503 // These tests work by coordinating some behavior on both the shim and
7504 // the runner.
7505 //
7506 // TimeoutSchedule configures the runner to send a series of timeout
7507 // opcodes to the shim (see packetAdaptor) immediately before reading
7508 // each peer handshake flight N. The timeout opcode both simulates a
7509 // timeout in the shim and acts as a synchronization point to help the
7510 // runner bracket each handshake flight.
7511 //
7512 // We assume the shim does not read from the channel eagerly. It must
7513 // first wait until it has sent flight N and is ready to receive
7514 // handshake flight N+1. At this point, it will process the timeout
7515 // opcode. It must then immediately respond with a timeout ACK and act
7516 // as if the shim was idle for the specified amount of time.
7517 //
7518 // The runner then drops all packets received before the ACK and
7519 // continues waiting for flight N. This ordering results in one attempt
7520 // at sending flight N to be dropped. For the test to complete, the
7521 // shim must send flight N again, testing that the shim implements DTLS
7522 // retransmit on a timeout.
7523
Steven Valdez143e8b32016-07-11 13:19:03 -04007524 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007525 // likely be more epochs to cross and the final message's retransmit may
7526 // be more complex.
7527
David Benjamin11c82892017-02-23 20:40:31 -05007528 // Test that this is indeed the timeout schedule. Stress all
7529 // four patterns of handshake.
7530 for i := 1; i < len(timeouts); i++ {
7531 number := strconv.Itoa(i)
7532 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007533 protocol: dtls,
David Benjamin11c82892017-02-23 20:40:31 -05007534 name: "DTLS-Retransmit-Client-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007535 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007536 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007537 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007538 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007539 },
7540 },
7541 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007542 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007543 })
David Benjamin11c82892017-02-23 20:40:31 -05007544 testCases = append(testCases, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007545 protocol: dtls,
7546 testType: serverTest,
David Benjamin11c82892017-02-23 20:40:31 -05007547 name: "DTLS-Retransmit-Server-" + number,
David Benjamin83f90402015-01-27 01:09:43 -05007548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007549 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007550 Bugs: ProtocolBugs{
David Benjamin11c82892017-02-23 20:40:31 -05007551 TimeoutSchedule: timeouts[:i],
David Benjamin83f90402015-01-27 01:09:43 -05007552 },
7553 },
7554 resumeSession: true,
David Benjamin11c82892017-02-23 20:40:31 -05007555 flags: []string{"-async"},
David Benjamin83f90402015-01-27 01:09:43 -05007556 })
7557 }
David Benjamin11c82892017-02-23 20:40:31 -05007558
7559 // Test that exceeding the timeout schedule hits a read
7560 // timeout.
7561 testCases = append(testCases, testCase{
7562 protocol: dtls,
7563 name: "DTLS-Retransmit-Timeout",
7564 config: Config{
7565 MaxVersion: VersionTLS12,
7566 Bugs: ProtocolBugs{
7567 TimeoutSchedule: timeouts,
7568 },
7569 },
7570 resumeSession: true,
7571 flags: []string{"-async"},
7572 shouldFail: true,
7573 expectedError: ":READ_TIMEOUT_EXPIRED:",
7574 })
7575
7576 // Test that timeout handling has a fudge factor, due to API
7577 // problems.
7578 testCases = append(testCases, testCase{
7579 protocol: dtls,
7580 name: "DTLS-Retransmit-Fudge",
7581 config: Config{
7582 MaxVersion: VersionTLS12,
7583 Bugs: ProtocolBugs{
7584 TimeoutSchedule: []time.Duration{
7585 timeouts[0] - 10*time.Millisecond,
7586 },
7587 },
7588 },
7589 resumeSession: true,
7590 flags: []string{"-async"},
7591 })
7592
7593 // Test that the final Finished retransmitting isn't
7594 // duplicated if the peer badly fragments everything.
7595 testCases = append(testCases, testCase{
7596 testType: serverTest,
7597 protocol: dtls,
7598 name: "DTLS-Retransmit-Fragmented",
7599 config: Config{
7600 MaxVersion: VersionTLS12,
7601 Bugs: ProtocolBugs{
7602 TimeoutSchedule: []time.Duration{timeouts[0]},
7603 MaxHandshakeRecordLength: 2,
7604 },
7605 },
7606 flags: []string{"-async"},
7607 })
7608
7609 // Test the timeout schedule when a shorter initial timeout duration is set.
7610 testCases = append(testCases, testCase{
7611 protocol: dtls,
7612 name: "DTLS-Retransmit-Short-Client",
7613 config: Config{
7614 MaxVersion: VersionTLS12,
7615 Bugs: ProtocolBugs{
7616 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7617 },
7618 },
7619 resumeSession: true,
7620 flags: []string{
7621 "-async",
7622 "-initial-timeout-duration-ms", "250",
7623 },
7624 })
7625 testCases = append(testCases, testCase{
7626 protocol: dtls,
7627 testType: serverTest,
7628 name: "DTLS-Retransmit-Short-Server",
7629 config: Config{
7630 MaxVersion: VersionTLS12,
7631 Bugs: ProtocolBugs{
7632 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7633 },
7634 },
7635 resumeSession: true,
7636 flags: []string{
7637 "-async",
7638 "-initial-timeout-duration-ms", "250",
7639 },
7640 })
David Benjamin83f90402015-01-27 01:09:43 -05007641}
7642
David Benjaminc565ebb2015-04-03 04:06:36 -04007643func addExportKeyingMaterialTests() {
7644 for _, vers := range tlsVersions {
7645 if vers.version == VersionSSL30 {
7646 continue
7647 }
7648 testCases = append(testCases, testCase{
7649 name: "ExportKeyingMaterial-" + vers.name,
7650 config: Config{
7651 MaxVersion: vers.version,
7652 },
7653 exportKeyingMaterial: 1024,
7654 exportLabel: "label",
7655 exportContext: "context",
7656 useExportContext: true,
7657 })
7658 testCases = append(testCases, testCase{
7659 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7660 config: Config{
7661 MaxVersion: vers.version,
7662 },
7663 exportKeyingMaterial: 1024,
7664 })
7665 testCases = append(testCases, testCase{
7666 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7667 config: Config{
7668 MaxVersion: vers.version,
7669 },
7670 exportKeyingMaterial: 1024,
7671 useExportContext: true,
7672 })
7673 testCases = append(testCases, testCase{
7674 name: "ExportKeyingMaterial-Small-" + vers.name,
7675 config: Config{
7676 MaxVersion: vers.version,
7677 },
7678 exportKeyingMaterial: 1,
7679 exportLabel: "label",
7680 exportContext: "context",
7681 useExportContext: true,
7682 })
7683 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007684
David Benjaminc565ebb2015-04-03 04:06:36 -04007685 testCases = append(testCases, testCase{
7686 name: "ExportKeyingMaterial-SSL3",
7687 config: Config{
7688 MaxVersion: VersionSSL30,
7689 },
7690 exportKeyingMaterial: 1024,
7691 exportLabel: "label",
7692 exportContext: "context",
7693 useExportContext: true,
7694 shouldFail: true,
7695 expectedError: "failed to export keying material",
7696 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007697
7698 // Exporters work during a False Start.
7699 testCases = append(testCases, testCase{
7700 name: "ExportKeyingMaterial-FalseStart",
7701 config: Config{
7702 MaxVersion: VersionTLS12,
7703 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7704 NextProtos: []string{"foo"},
7705 Bugs: ProtocolBugs{
7706 ExpectFalseStart: true,
7707 },
7708 },
7709 flags: []string{
7710 "-false-start",
7711 "-advertise-alpn", "\x03foo",
7712 },
7713 shimWritesFirst: true,
7714 exportKeyingMaterial: 1024,
7715 exportLabel: "label",
7716 exportContext: "context",
7717 useExportContext: true,
7718 })
7719
7720 // Exporters do not work in the middle of a renegotiation. Test this by
7721 // triggering the exporter after every SSL_read call and configuring the
7722 // shim to run asynchronously.
7723 testCases = append(testCases, testCase{
7724 name: "ExportKeyingMaterial-Renegotiate",
7725 config: Config{
7726 MaxVersion: VersionTLS12,
7727 },
7728 renegotiate: 1,
7729 flags: []string{
7730 "-async",
7731 "-use-exporter-between-reads",
7732 "-renegotiate-freely",
7733 "-expect-total-renegotiations", "1",
7734 },
7735 shouldFail: true,
7736 expectedError: "failed to export keying material",
7737 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007738}
7739
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007740func addTLSUniqueTests() {
7741 for _, isClient := range []bool{false, true} {
7742 for _, isResumption := range []bool{false, true} {
7743 for _, hasEMS := range []bool{false, true} {
7744 var suffix string
7745 if isResumption {
7746 suffix = "Resume-"
7747 } else {
7748 suffix = "Full-"
7749 }
7750
7751 if hasEMS {
7752 suffix += "EMS-"
7753 } else {
7754 suffix += "NoEMS-"
7755 }
7756
7757 if isClient {
7758 suffix += "Client"
7759 } else {
7760 suffix += "Server"
7761 }
7762
7763 test := testCase{
7764 name: "TLSUnique-" + suffix,
7765 testTLSUnique: true,
7766 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007767 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007768 Bugs: ProtocolBugs{
7769 NoExtendedMasterSecret: !hasEMS,
7770 },
7771 },
7772 }
7773
7774 if isResumption {
7775 test.resumeSession = true
7776 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007777 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007778 Bugs: ProtocolBugs{
7779 NoExtendedMasterSecret: !hasEMS,
7780 },
7781 }
7782 }
7783
7784 if isResumption && !hasEMS {
7785 test.shouldFail = true
7786 test.expectedError = "failed to get tls-unique"
7787 }
7788
7789 testCases = append(testCases, test)
7790 }
7791 }
7792 }
7793}
7794
Adam Langley09505632015-07-30 18:10:13 -07007795func addCustomExtensionTests() {
7796 expectedContents := "custom extension"
7797 emptyString := ""
7798
7799 for _, isClient := range []bool{false, true} {
7800 suffix := "Server"
7801 flag := "-enable-server-custom-extension"
7802 testType := serverTest
7803 if isClient {
7804 suffix = "Client"
7805 flag = "-enable-client-custom-extension"
7806 testType = clientTest
7807 }
7808
7809 testCases = append(testCases, testCase{
7810 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007811 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007812 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007813 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007814 Bugs: ProtocolBugs{
7815 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007816 ExpectedCustomExtension: &expectedContents,
7817 },
7818 },
7819 flags: []string{flag},
7820 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007821 testCases = append(testCases, testCase{
7822 testType: testType,
7823 name: "CustomExtensions-" + suffix + "-TLS13",
7824 config: Config{
7825 MaxVersion: VersionTLS13,
7826 Bugs: ProtocolBugs{
7827 CustomExtension: expectedContents,
7828 ExpectedCustomExtension: &expectedContents,
7829 },
7830 },
7831 flags: []string{flag},
7832 })
Adam Langley09505632015-07-30 18:10:13 -07007833
7834 // If the parse callback fails, the handshake should also fail.
7835 testCases = append(testCases, testCase{
7836 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007837 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007838 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007839 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007840 Bugs: ProtocolBugs{
7841 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007842 ExpectedCustomExtension: &expectedContents,
7843 },
7844 },
David Benjamin399e7c92015-07-30 23:01:27 -04007845 flags: []string{flag},
7846 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007847 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7848 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007849 testCases = append(testCases, testCase{
7850 testType: testType,
7851 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7852 config: Config{
7853 MaxVersion: VersionTLS13,
7854 Bugs: ProtocolBugs{
7855 CustomExtension: expectedContents + "foo",
7856 ExpectedCustomExtension: &expectedContents,
7857 },
7858 },
7859 flags: []string{flag},
7860 shouldFail: true,
7861 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7862 })
Adam Langley09505632015-07-30 18:10:13 -07007863
7864 // If the add callback fails, the handshake should also fail.
7865 testCases = append(testCases, testCase{
7866 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007867 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007869 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007870 Bugs: ProtocolBugs{
7871 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007872 ExpectedCustomExtension: &expectedContents,
7873 },
7874 },
David Benjamin399e7c92015-07-30 23:01:27 -04007875 flags: []string{flag, "-custom-extension-fail-add"},
7876 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007877 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7878 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007879 testCases = append(testCases, testCase{
7880 testType: testType,
7881 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7882 config: Config{
7883 MaxVersion: VersionTLS13,
7884 Bugs: ProtocolBugs{
7885 CustomExtension: expectedContents,
7886 ExpectedCustomExtension: &expectedContents,
7887 },
7888 },
7889 flags: []string{flag, "-custom-extension-fail-add"},
7890 shouldFail: true,
7891 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7892 })
Adam Langley09505632015-07-30 18:10:13 -07007893
7894 // If the add callback returns zero, no extension should be
7895 // added.
7896 skipCustomExtension := expectedContents
7897 if isClient {
7898 // For the case where the client skips sending the
7899 // custom extension, the server must not “echo” it.
7900 skipCustomExtension = ""
7901 }
7902 testCases = append(testCases, testCase{
7903 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007904 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007905 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007906 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007907 Bugs: ProtocolBugs{
7908 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007909 ExpectedCustomExtension: &emptyString,
7910 },
7911 },
7912 flags: []string{flag, "-custom-extension-skip"},
7913 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007914 testCases = append(testCases, testCase{
7915 testType: testType,
7916 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7917 config: Config{
7918 MaxVersion: VersionTLS13,
7919 Bugs: ProtocolBugs{
7920 CustomExtension: skipCustomExtension,
7921 ExpectedCustomExtension: &emptyString,
7922 },
7923 },
7924 flags: []string{flag, "-custom-extension-skip"},
7925 })
Adam Langley09505632015-07-30 18:10:13 -07007926 }
7927
7928 // The custom extension add callback should not be called if the client
7929 // doesn't send the extension.
7930 testCases = append(testCases, testCase{
7931 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007932 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007933 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007934 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007935 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007936 ExpectedCustomExtension: &emptyString,
7937 },
7938 },
7939 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7940 })
Adam Langley2deb9842015-08-07 11:15:37 -07007941
Steven Valdez143e8b32016-07-11 13:19:03 -04007942 testCases = append(testCases, testCase{
7943 testType: serverTest,
7944 name: "CustomExtensions-NotCalled-Server-TLS13",
7945 config: Config{
7946 MaxVersion: VersionTLS13,
7947 Bugs: ProtocolBugs{
7948 ExpectedCustomExtension: &emptyString,
7949 },
7950 },
7951 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7952 })
7953
Adam Langley2deb9842015-08-07 11:15:37 -07007954 // Test an unknown extension from the server.
7955 testCases = append(testCases, testCase{
7956 testType: clientTest,
7957 name: "UnknownExtension-Client",
7958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007959 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007960 Bugs: ProtocolBugs{
7961 CustomExtension: expectedContents,
7962 },
7963 },
David Benjamin0c40a962016-08-01 12:05:50 -04007964 shouldFail: true,
7965 expectedError: ":UNEXPECTED_EXTENSION:",
7966 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007967 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007968 testCases = append(testCases, testCase{
7969 testType: clientTest,
7970 name: "UnknownExtension-Client-TLS13",
7971 config: Config{
7972 MaxVersion: VersionTLS13,
7973 Bugs: ProtocolBugs{
7974 CustomExtension: expectedContents,
7975 },
7976 },
David Benjamin0c40a962016-08-01 12:05:50 -04007977 shouldFail: true,
7978 expectedError: ":UNEXPECTED_EXTENSION:",
7979 expectedLocalError: "remote error: unsupported extension",
7980 })
David Benjamin490469f2016-10-05 22:44:38 -04007981 testCases = append(testCases, testCase{
7982 testType: clientTest,
7983 name: "UnknownUnencryptedExtension-Client-TLS13",
7984 config: Config{
7985 MaxVersion: VersionTLS13,
7986 Bugs: ProtocolBugs{
7987 CustomUnencryptedExtension: expectedContents,
7988 },
7989 },
7990 shouldFail: true,
7991 expectedError: ":UNEXPECTED_EXTENSION:",
7992 // The shim must send an alert, but alerts at this point do not
7993 // get successfully decrypted by the runner.
7994 expectedLocalError: "local error: bad record MAC",
7995 })
7996 testCases = append(testCases, testCase{
7997 testType: clientTest,
7998 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7999 config: Config{
8000 MaxVersion: VersionTLS13,
8001 Bugs: ProtocolBugs{
8002 SendUnencryptedALPN: "foo",
8003 },
8004 },
8005 flags: []string{
8006 "-advertise-alpn", "\x03foo\x03bar",
8007 },
8008 shouldFail: true,
8009 expectedError: ":UNEXPECTED_EXTENSION:",
8010 // The shim must send an alert, but alerts at this point do not
8011 // get successfully decrypted by the runner.
8012 expectedLocalError: "local error: bad record MAC",
8013 })
David Benjamin0c40a962016-08-01 12:05:50 -04008014
8015 // Test a known but unoffered extension from the server.
8016 testCases = append(testCases, testCase{
8017 testType: clientTest,
8018 name: "UnofferedExtension-Client",
8019 config: Config{
8020 MaxVersion: VersionTLS12,
8021 Bugs: ProtocolBugs{
8022 SendALPN: "alpn",
8023 },
8024 },
8025 shouldFail: true,
8026 expectedError: ":UNEXPECTED_EXTENSION:",
8027 expectedLocalError: "remote error: unsupported extension",
8028 })
8029 testCases = append(testCases, testCase{
8030 testType: clientTest,
8031 name: "UnofferedExtension-Client-TLS13",
8032 config: Config{
8033 MaxVersion: VersionTLS13,
8034 Bugs: ProtocolBugs{
8035 SendALPN: "alpn",
8036 },
8037 },
8038 shouldFail: true,
8039 expectedError: ":UNEXPECTED_EXTENSION:",
8040 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04008041 })
Adam Langley09505632015-07-30 18:10:13 -07008042}
8043
David Benjaminb36a3952015-12-01 18:53:13 -05008044func addRSAClientKeyExchangeTests() {
8045 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
8046 testCases = append(testCases, testCase{
8047 testType: serverTest,
8048 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
8049 config: Config{
8050 // Ensure the ClientHello version and final
8051 // version are different, to detect if the
8052 // server uses the wrong one.
8053 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07008054 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05008055 Bugs: ProtocolBugs{
8056 BadRSAClientKeyExchange: bad,
8057 },
8058 },
8059 shouldFail: true,
8060 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8061 })
8062 }
David Benjamine63d9d72016-09-19 18:27:34 -04008063
8064 // The server must compare whatever was in ClientHello.version for the
8065 // RSA premaster.
8066 testCases = append(testCases, testCase{
8067 testType: serverTest,
8068 name: "SendClientVersion-RSA",
8069 config: Config{
8070 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
8071 Bugs: ProtocolBugs{
8072 SendClientVersion: 0x1234,
8073 },
8074 },
8075 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
8076 })
David Benjaminb36a3952015-12-01 18:53:13 -05008077}
8078
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008079var testCurves = []struct {
8080 name string
8081 id CurveID
8082}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008083 {"P-256", CurveP256},
8084 {"P-384", CurveP384},
8085 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05008086 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008087}
8088
Steven Valdez5440fe02016-07-18 12:40:30 -04008089const bogusCurve = 0x1234
8090
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008091func addCurveTests() {
8092 for _, curve := range testCurves {
8093 testCases = append(testCases, testCase{
8094 name: "CurveTest-Client-" + curve.name,
8095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008096 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008097 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8098 CurvePreferences: []CurveID{curve.id},
8099 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008100 flags: []string{
8101 "-enable-all-curves",
8102 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8103 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008104 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008105 })
8106 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008107 name: "CurveTest-Client-" + curve.name + "-TLS13",
8108 config: Config{
8109 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008110 CurvePreferences: []CurveID{curve.id},
8111 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008112 flags: []string{
8113 "-enable-all-curves",
8114 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8115 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008116 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008117 })
8118 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008119 testType: serverTest,
8120 name: "CurveTest-Server-" + curve.name,
8121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008122 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008123 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8124 CurvePreferences: []CurveID{curve.id},
8125 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008126 flags: []string{
8127 "-enable-all-curves",
8128 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8129 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008130 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008131 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008132 testCases = append(testCases, testCase{
8133 testType: serverTest,
8134 name: "CurveTest-Server-" + curve.name + "-TLS13",
8135 config: Config{
8136 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008137 CurvePreferences: []CurveID{curve.id},
8138 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008139 flags: []string{
8140 "-enable-all-curves",
8141 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8142 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008143 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008144 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008145 }
David Benjamin241ae832016-01-15 03:04:54 -05008146
8147 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008148 testCases = append(testCases, testCase{
8149 testType: serverTest,
8150 name: "UnknownCurve",
8151 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008152 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008153 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8154 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8155 },
8156 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008157
Steven Valdez803c77a2016-09-06 14:13:43 -04008158 // The server must be tolerant to bogus curves.
8159 testCases = append(testCases, testCase{
8160 testType: serverTest,
8161 name: "UnknownCurve-TLS13",
8162 config: Config{
8163 MaxVersion: VersionTLS13,
8164 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8165 },
8166 })
8167
David Benjamin4c3ddf72016-06-29 18:13:53 -04008168 // The server must not consider ECDHE ciphers when there are no
8169 // supported curves.
8170 testCases = append(testCases, testCase{
8171 testType: serverTest,
8172 name: "NoSupportedCurves",
8173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008174 MaxVersion: VersionTLS12,
8175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8176 Bugs: ProtocolBugs{
8177 NoSupportedCurves: true,
8178 },
8179 },
8180 shouldFail: true,
8181 expectedError: ":NO_SHARED_CIPHER:",
8182 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008183 testCases = append(testCases, testCase{
8184 testType: serverTest,
8185 name: "NoSupportedCurves-TLS13",
8186 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008187 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008188 Bugs: ProtocolBugs{
8189 NoSupportedCurves: true,
8190 },
8191 },
8192 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008193 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008194 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008195
8196 // The server must fall back to another cipher when there are no
8197 // supported curves.
8198 testCases = append(testCases, testCase{
8199 testType: serverTest,
8200 name: "NoCommonCurves",
8201 config: Config{
8202 MaxVersion: VersionTLS12,
8203 CipherSuites: []uint16{
8204 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008205 TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008206 },
8207 CurvePreferences: []CurveID{CurveP224},
8208 },
Matthew Braithwaitecedc6f12017-03-15 19:20:23 -07008209 expectedCipher: TLS_RSA_WITH_AES_128_GCM_SHA256,
David Benjamin4c3ddf72016-06-29 18:13:53 -04008210 })
8211
8212 // The client must reject bogus curves and disabled curves.
8213 testCases = append(testCases, testCase{
8214 name: "BadECDHECurve",
8215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008216 MaxVersion: VersionTLS12,
8217 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8218 Bugs: ProtocolBugs{
8219 SendCurve: bogusCurve,
8220 },
8221 },
8222 shouldFail: true,
8223 expectedError: ":WRONG_CURVE:",
8224 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008225 testCases = append(testCases, testCase{
8226 name: "BadECDHECurve-TLS13",
8227 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008228 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008229 Bugs: ProtocolBugs{
8230 SendCurve: bogusCurve,
8231 },
8232 },
8233 shouldFail: true,
8234 expectedError: ":WRONG_CURVE:",
8235 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008236
8237 testCases = append(testCases, testCase{
8238 name: "UnsupportedCurve",
8239 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008240 MaxVersion: VersionTLS12,
8241 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8242 CurvePreferences: []CurveID{CurveP256},
8243 Bugs: ProtocolBugs{
8244 IgnorePeerCurvePreferences: true,
8245 },
8246 },
8247 flags: []string{"-p384-only"},
8248 shouldFail: true,
8249 expectedError: ":WRONG_CURVE:",
8250 })
8251
David Benjamin4f921572016-07-17 14:20:10 +02008252 testCases = append(testCases, testCase{
8253 // TODO(davidben): Add a TLS 1.3 version where
8254 // HelloRetryRequest requests an unsupported curve.
8255 name: "UnsupportedCurve-ServerHello-TLS13",
8256 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008257 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008258 CurvePreferences: []CurveID{CurveP384},
8259 Bugs: ProtocolBugs{
8260 SendCurve: CurveP256,
8261 },
8262 },
8263 flags: []string{"-p384-only"},
8264 shouldFail: true,
8265 expectedError: ":WRONG_CURVE:",
8266 })
8267
David Benjamin4c3ddf72016-06-29 18:13:53 -04008268 // Test invalid curve points.
8269 testCases = append(testCases, testCase{
8270 name: "InvalidECDHPoint-Client",
8271 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008272 MaxVersion: VersionTLS12,
8273 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8274 CurvePreferences: []CurveID{CurveP256},
8275 Bugs: ProtocolBugs{
8276 InvalidECDHPoint: true,
8277 },
8278 },
8279 shouldFail: true,
8280 expectedError: ":INVALID_ENCODING:",
8281 })
8282 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008283 name: "InvalidECDHPoint-Client-TLS13",
8284 config: Config{
8285 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008286 CurvePreferences: []CurveID{CurveP256},
8287 Bugs: ProtocolBugs{
8288 InvalidECDHPoint: true,
8289 },
8290 },
8291 shouldFail: true,
8292 expectedError: ":INVALID_ENCODING:",
8293 })
8294 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008295 testType: serverTest,
8296 name: "InvalidECDHPoint-Server",
8297 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008298 MaxVersion: VersionTLS12,
8299 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8300 CurvePreferences: []CurveID{CurveP256},
8301 Bugs: ProtocolBugs{
8302 InvalidECDHPoint: true,
8303 },
8304 },
8305 shouldFail: true,
8306 expectedError: ":INVALID_ENCODING:",
8307 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008308 testCases = append(testCases, testCase{
8309 testType: serverTest,
8310 name: "InvalidECDHPoint-Server-TLS13",
8311 config: Config{
8312 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008313 CurvePreferences: []CurveID{CurveP256},
8314 Bugs: ProtocolBugs{
8315 InvalidECDHPoint: true,
8316 },
8317 },
8318 shouldFail: true,
8319 expectedError: ":INVALID_ENCODING:",
8320 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008321
8322 // The previous curve ID should be reported on TLS 1.2 resumption.
8323 testCases = append(testCases, testCase{
8324 name: "CurveID-Resume-Client",
8325 config: Config{
8326 MaxVersion: VersionTLS12,
8327 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8328 CurvePreferences: []CurveID{CurveX25519},
8329 },
8330 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8331 resumeSession: true,
8332 })
8333 testCases = append(testCases, testCase{
8334 testType: serverTest,
8335 name: "CurveID-Resume-Server",
8336 config: Config{
8337 MaxVersion: VersionTLS12,
8338 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8339 CurvePreferences: []CurveID{CurveX25519},
8340 },
8341 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8342 resumeSession: true,
8343 })
8344
8345 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8346 // one should be reported.
8347 testCases = append(testCases, testCase{
8348 name: "CurveID-Resume-Client-TLS13",
8349 config: Config{
8350 MaxVersion: VersionTLS13,
8351 CurvePreferences: []CurveID{CurveX25519},
8352 },
8353 resumeConfig: &Config{
8354 MaxVersion: VersionTLS13,
8355 CurvePreferences: []CurveID{CurveP256},
8356 },
8357 flags: []string{
8358 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8359 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8360 },
8361 resumeSession: true,
8362 })
8363 testCases = append(testCases, testCase{
8364 testType: serverTest,
8365 name: "CurveID-Resume-Server-TLS13",
8366 config: Config{
8367 MaxVersion: VersionTLS13,
8368 CurvePreferences: []CurveID{CurveX25519},
8369 },
8370 resumeConfig: &Config{
8371 MaxVersion: VersionTLS13,
8372 CurvePreferences: []CurveID{CurveP256},
8373 },
8374 flags: []string{
8375 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8376 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8377 },
8378 resumeSession: true,
8379 })
David Benjamina81967b2016-12-22 09:16:57 -05008380
8381 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8382 testCases = append(testCases, testCase{
8383 name: "PointFormat-ServerHello-TLS12",
8384 config: Config{
8385 MaxVersion: VersionTLS12,
8386 Bugs: ProtocolBugs{
8387 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8388 },
8389 },
8390 })
8391 testCases = append(testCases, testCase{
8392 name: "PointFormat-EncryptedExtensions-TLS13",
8393 config: Config{
8394 MaxVersion: VersionTLS13,
8395 Bugs: ProtocolBugs{
8396 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8397 },
8398 },
8399 shouldFail: true,
8400 expectedError: ":ERROR_PARSING_EXTENSION:",
8401 })
8402
8403 // Test that we tolerate unknown point formats, as long as
8404 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8405 // check they are still functional.
8406 testCases = append(testCases, testCase{
8407 name: "PointFormat-Client-Tolerance",
8408 config: Config{
8409 MaxVersion: VersionTLS12,
8410 Bugs: ProtocolBugs{
8411 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8412 },
8413 },
8414 })
8415 testCases = append(testCases, testCase{
8416 testType: serverTest,
8417 name: "PointFormat-Server-Tolerance",
8418 config: Config{
8419 MaxVersion: VersionTLS12,
8420 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8421 Bugs: ProtocolBugs{
8422 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8423 },
8424 },
8425 })
8426
8427 // Test TLS 1.2 does not require the point format extension to be
8428 // present.
8429 testCases = append(testCases, testCase{
8430 name: "PointFormat-Client-Missing",
8431 config: Config{
8432 MaxVersion: VersionTLS12,
8433 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8434 Bugs: ProtocolBugs{
8435 SendSupportedPointFormats: []byte{},
8436 },
8437 },
8438 })
8439 testCases = append(testCases, testCase{
8440 testType: serverTest,
8441 name: "PointFormat-Server-Missing",
8442 config: Config{
8443 MaxVersion: VersionTLS12,
8444 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8445 Bugs: ProtocolBugs{
8446 SendSupportedPointFormats: []byte{},
8447 },
8448 },
8449 })
8450
8451 // If the point format extension is present, uncompressed points must be
8452 // offered. BoringSSL requires this whether or not ECDHE is used.
8453 testCases = append(testCases, testCase{
8454 name: "PointFormat-Client-MissingUncompressed",
8455 config: Config{
8456 MaxVersion: VersionTLS12,
8457 Bugs: ProtocolBugs{
8458 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8459 },
8460 },
8461 shouldFail: true,
8462 expectedError: ":ERROR_PARSING_EXTENSION:",
8463 })
8464 testCases = append(testCases, testCase{
8465 testType: serverTest,
8466 name: "PointFormat-Server-MissingUncompressed",
8467 config: Config{
8468 MaxVersion: VersionTLS12,
8469 Bugs: ProtocolBugs{
8470 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8471 },
8472 },
8473 shouldFail: true,
8474 expectedError: ":ERROR_PARSING_EXTENSION:",
8475 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008476}
8477
David Benjaminc9ae27c2016-06-24 22:56:37 -04008478func addTLS13RecordTests() {
8479 testCases = append(testCases, testCase{
8480 name: "TLS13-RecordPadding",
8481 config: Config{
8482 MaxVersion: VersionTLS13,
8483 MinVersion: VersionTLS13,
8484 Bugs: ProtocolBugs{
8485 RecordPadding: 10,
8486 },
8487 },
8488 })
8489
8490 testCases = append(testCases, testCase{
8491 name: "TLS13-EmptyRecords",
8492 config: Config{
8493 MaxVersion: VersionTLS13,
8494 MinVersion: VersionTLS13,
8495 Bugs: ProtocolBugs{
8496 OmitRecordContents: true,
8497 },
8498 },
8499 shouldFail: true,
8500 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8501 })
8502
8503 testCases = append(testCases, testCase{
8504 name: "TLS13-OnlyPadding",
8505 config: Config{
8506 MaxVersion: VersionTLS13,
8507 MinVersion: VersionTLS13,
8508 Bugs: ProtocolBugs{
8509 OmitRecordContents: true,
8510 RecordPadding: 10,
8511 },
8512 },
8513 shouldFail: true,
8514 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8515 })
8516
8517 testCases = append(testCases, testCase{
8518 name: "TLS13-WrongOuterRecord",
8519 config: Config{
8520 MaxVersion: VersionTLS13,
8521 MinVersion: VersionTLS13,
8522 Bugs: ProtocolBugs{
8523 OuterRecordType: recordTypeHandshake,
8524 },
8525 },
8526 shouldFail: true,
8527 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8528 })
8529}
8530
Steven Valdez5b986082016-09-01 12:29:49 -04008531func addSessionTicketTests() {
8532 testCases = append(testCases, testCase{
8533 // In TLS 1.2 and below, empty NewSessionTicket messages
8534 // mean the server changed its mind on sending a ticket.
8535 name: "SendEmptySessionTicket",
8536 config: Config{
8537 MaxVersion: VersionTLS12,
8538 Bugs: ProtocolBugs{
8539 SendEmptySessionTicket: true,
8540 },
8541 },
8542 flags: []string{"-expect-no-session"},
8543 })
8544
8545 // Test that the server ignores unknown PSK modes.
8546 testCases = append(testCases, testCase{
8547 testType: serverTest,
8548 name: "TLS13-SendUnknownModeSessionTicket-Server",
8549 config: Config{
8550 MaxVersion: VersionTLS13,
8551 Bugs: ProtocolBugs{
8552 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008553 },
8554 },
8555 resumeSession: true,
8556 expectedResumeVersion: VersionTLS13,
8557 })
8558
Steven Valdeza833c352016-11-01 13:39:36 -04008559 // Test that the server does not send session tickets with no matching key exchange mode.
8560 testCases = append(testCases, testCase{
8561 testType: serverTest,
8562 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8563 config: Config{
8564 MaxVersion: VersionTLS13,
8565 Bugs: ProtocolBugs{
8566 SendPSKKeyExchangeModes: []byte{0x1a},
8567 ExpectNoNewSessionTicket: true,
8568 },
8569 },
8570 })
8571
8572 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008573 testCases = append(testCases, testCase{
8574 testType: serverTest,
8575 name: "TLS13-SendBadKEModeSessionTicket-Server",
8576 config: Config{
8577 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008578 },
8579 resumeConfig: &Config{
8580 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008581 Bugs: ProtocolBugs{
8582 SendPSKKeyExchangeModes: []byte{0x1a},
8583 },
8584 },
8585 resumeSession: true,
8586 expectResumeRejected: true,
8587 })
8588
Steven Valdeza833c352016-11-01 13:39:36 -04008589 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008590 testCases = append(testCases, testCase{
8591 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008592 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008593 config: Config{
8594 MaxVersion: VersionTLS13,
8595 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008596 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008597 },
8598 },
Steven Valdeza833c352016-11-01 13:39:36 -04008599 resumeSession: true,
8600 flags: []string{
8601 "-resumption-delay", "10",
8602 },
Steven Valdez5b986082016-09-01 12:29:49 -04008603 })
8604
Steven Valdeza833c352016-11-01 13:39:36 -04008605 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008606 testCases = append(testCases, testCase{
8607 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008608 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008609 config: Config{
8610 MaxVersion: VersionTLS13,
8611 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008612 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008613 },
8614 },
Steven Valdeza833c352016-11-01 13:39:36 -04008615 resumeSession: true,
8616 shouldFail: true,
8617 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008618 })
8619
David Benjamin35ac5b72017-03-03 15:05:56 -05008620 // Test that the server's ticket age skew reporting works.
8621 testCases = append(testCases, testCase{
8622 testType: serverTest,
8623 name: "TLS13-TicketAgeSkew-Forward",
8624 config: Config{
8625 MaxVersion: VersionTLS13,
8626 Bugs: ProtocolBugs{
8627 SendTicketAge: 15 * time.Second,
8628 },
8629 },
8630 resumeSession: true,
8631 flags: []string{
8632 "-resumption-delay", "10",
8633 "-expect-ticket-age-skew", "5",
8634 },
8635 })
8636 testCases = append(testCases, testCase{
8637 testType: serverTest,
8638 name: "TLS13-TicketAgeSkew-Backward",
8639 config: Config{
8640 MaxVersion: VersionTLS13,
8641 Bugs: ProtocolBugs{
8642 SendTicketAge: 5 * time.Second,
8643 },
8644 },
8645 resumeSession: true,
8646 flags: []string{
8647 "-resumption-delay", "10",
8648 "-expect-ticket-age-skew", "-5",
8649 },
8650 })
8651
Steven Valdez08b65f42016-12-07 15:29:45 -05008652 testCases = append(testCases, testCase{
8653 testType: clientTest,
8654 name: "TLS13-SendTicketEarlyDataInfo",
8655 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008656 MaxVersion: VersionTLS13,
8657 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008658 },
8659 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008660 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008661 "-expect-early-data-info",
8662 },
8663 })
8664
David Benjamin9b160662017-01-25 19:53:43 -05008665 // Test that 0-RTT tickets are ignored in clients unless opted in.
8666 testCases = append(testCases, testCase{
8667 testType: clientTest,
8668 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8669 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008670 MaxVersion: VersionTLS13,
8671 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008672 },
8673 })
8674
Steven Valdez08b65f42016-12-07 15:29:45 -05008675 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008676 testType: clientTest,
8677 name: "TLS13-DuplicateTicketEarlyDataInfo",
8678 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008679 MaxVersion: VersionTLS13,
8680 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008681 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008682 DuplicateTicketEarlyDataInfo: true,
8683 },
8684 },
8685 shouldFail: true,
8686 expectedError: ":DUPLICATE_EXTENSION:",
8687 expectedLocalError: "remote error: illegal parameter",
8688 })
8689
8690 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008691 testType: serverTest,
8692 name: "TLS13-ExpectTicketEarlyDataInfo",
8693 config: Config{
8694 MaxVersion: VersionTLS13,
8695 Bugs: ProtocolBugs{
8696 ExpectTicketEarlyDataInfo: true,
8697 },
8698 },
8699 flags: []string{
8700 "-enable-early-data",
8701 },
8702 })
David Benjamin17b30832017-01-28 14:00:32 -05008703
8704 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8705 // is honored.
8706 testCases = append(testCases, testCase{
8707 testType: clientTest,
8708 name: "TLS13-HonorServerSessionTicketLifetime",
8709 config: Config{
8710 MaxVersion: VersionTLS13,
8711 Bugs: ProtocolBugs{
8712 SendTicketLifetime: 20 * time.Second,
8713 },
8714 },
8715 flags: []string{
8716 "-resumption-delay", "19",
8717 },
8718 resumeSession: true,
8719 })
8720 testCases = append(testCases, testCase{
8721 testType: clientTest,
8722 name: "TLS13-HonorServerSessionTicketLifetime-2",
8723 config: Config{
8724 MaxVersion: VersionTLS13,
8725 Bugs: ProtocolBugs{
8726 SendTicketLifetime: 20 * time.Second,
8727 // The client should not offer the expired session.
8728 ExpectNoTLS13PSK: true,
8729 },
8730 },
8731 flags: []string{
8732 "-resumption-delay", "21",
8733 },
David Benjamin023d4192017-02-06 13:49:07 -05008734 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008735 expectResumeRejected: true,
8736 })
Steven Valdez5b986082016-09-01 12:29:49 -04008737}
8738
David Benjamin82261be2016-07-07 14:32:50 -07008739func addChangeCipherSpecTests() {
8740 // Test missing ChangeCipherSpecs.
8741 testCases = append(testCases, testCase{
8742 name: "SkipChangeCipherSpec-Client",
8743 config: Config{
8744 MaxVersion: VersionTLS12,
8745 Bugs: ProtocolBugs{
8746 SkipChangeCipherSpec: true,
8747 },
8748 },
8749 shouldFail: true,
8750 expectedError: ":UNEXPECTED_RECORD:",
8751 })
8752 testCases = append(testCases, testCase{
8753 testType: serverTest,
8754 name: "SkipChangeCipherSpec-Server",
8755 config: Config{
8756 MaxVersion: VersionTLS12,
8757 Bugs: ProtocolBugs{
8758 SkipChangeCipherSpec: true,
8759 },
8760 },
8761 shouldFail: true,
8762 expectedError: ":UNEXPECTED_RECORD:",
8763 })
8764 testCases = append(testCases, testCase{
8765 testType: serverTest,
8766 name: "SkipChangeCipherSpec-Server-NPN",
8767 config: Config{
8768 MaxVersion: VersionTLS12,
8769 NextProtos: []string{"bar"},
8770 Bugs: ProtocolBugs{
8771 SkipChangeCipherSpec: true,
8772 },
8773 },
8774 flags: []string{
8775 "-advertise-npn", "\x03foo\x03bar\x03baz",
8776 },
8777 shouldFail: true,
8778 expectedError: ":UNEXPECTED_RECORD:",
8779 })
8780
8781 // Test synchronization between the handshake and ChangeCipherSpec.
8782 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8783 // rejected. Test both with and without handshake packing to handle both
8784 // when the partial post-CCS message is in its own record and when it is
8785 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008786 for _, packed := range []bool{false, true} {
8787 var suffix string
8788 if packed {
8789 suffix = "-Packed"
8790 }
8791
8792 testCases = append(testCases, testCase{
8793 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8794 config: Config{
8795 MaxVersion: VersionTLS12,
8796 Bugs: ProtocolBugs{
8797 FragmentAcrossChangeCipherSpec: true,
8798 PackHandshakeFlight: packed,
8799 },
8800 },
8801 shouldFail: true,
8802 expectedError: ":UNEXPECTED_RECORD:",
8803 })
8804 testCases = append(testCases, testCase{
8805 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8806 config: Config{
8807 MaxVersion: VersionTLS12,
8808 },
8809 resumeSession: true,
8810 resumeConfig: &Config{
8811 MaxVersion: VersionTLS12,
8812 Bugs: ProtocolBugs{
8813 FragmentAcrossChangeCipherSpec: true,
8814 PackHandshakeFlight: packed,
8815 },
8816 },
8817 shouldFail: true,
8818 expectedError: ":UNEXPECTED_RECORD:",
8819 })
8820 testCases = append(testCases, testCase{
8821 testType: serverTest,
8822 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8823 config: Config{
8824 MaxVersion: VersionTLS12,
8825 Bugs: ProtocolBugs{
8826 FragmentAcrossChangeCipherSpec: true,
8827 PackHandshakeFlight: packed,
8828 },
8829 },
8830 shouldFail: true,
8831 expectedError: ":UNEXPECTED_RECORD:",
8832 })
8833 testCases = append(testCases, testCase{
8834 testType: serverTest,
8835 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8836 config: Config{
8837 MaxVersion: VersionTLS12,
8838 },
8839 resumeSession: true,
8840 resumeConfig: &Config{
8841 MaxVersion: VersionTLS12,
8842 Bugs: ProtocolBugs{
8843 FragmentAcrossChangeCipherSpec: true,
8844 PackHandshakeFlight: packed,
8845 },
8846 },
8847 shouldFail: true,
8848 expectedError: ":UNEXPECTED_RECORD:",
8849 })
8850 testCases = append(testCases, testCase{
8851 testType: serverTest,
8852 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8853 config: Config{
8854 MaxVersion: VersionTLS12,
8855 NextProtos: []string{"bar"},
8856 Bugs: ProtocolBugs{
8857 FragmentAcrossChangeCipherSpec: true,
8858 PackHandshakeFlight: packed,
8859 },
8860 },
8861 flags: []string{
8862 "-advertise-npn", "\x03foo\x03bar\x03baz",
8863 },
8864 shouldFail: true,
8865 expectedError: ":UNEXPECTED_RECORD:",
8866 })
8867 }
8868
David Benjamin61672812016-07-14 23:10:43 -04008869 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8870 // messages in the handshake queue. Do this by testing the server
8871 // reading the client Finished, reversing the flight so Finished comes
8872 // first.
8873 testCases = append(testCases, testCase{
8874 protocol: dtls,
8875 testType: serverTest,
8876 name: "SendUnencryptedFinished-DTLS",
8877 config: Config{
8878 MaxVersion: VersionTLS12,
8879 Bugs: ProtocolBugs{
8880 SendUnencryptedFinished: true,
8881 ReverseHandshakeFragments: true,
8882 },
8883 },
8884 shouldFail: true,
8885 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8886 })
8887
Steven Valdez143e8b32016-07-11 13:19:03 -04008888 // Test synchronization between encryption changes and the handshake in
8889 // TLS 1.3, where ChangeCipherSpec is implicit.
8890 testCases = append(testCases, testCase{
8891 name: "PartialEncryptedExtensionsWithServerHello",
8892 config: Config{
8893 MaxVersion: VersionTLS13,
8894 Bugs: ProtocolBugs{
8895 PartialEncryptedExtensionsWithServerHello: true,
8896 },
8897 },
8898 shouldFail: true,
8899 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8900 })
8901 testCases = append(testCases, testCase{
8902 testType: serverTest,
8903 name: "PartialClientFinishedWithClientHello",
8904 config: Config{
8905 MaxVersion: VersionTLS13,
8906 Bugs: ProtocolBugs{
8907 PartialClientFinishedWithClientHello: true,
8908 },
8909 },
8910 shouldFail: true,
8911 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8912 })
8913
David Benjamin82261be2016-07-07 14:32:50 -07008914 // Test that early ChangeCipherSpecs are handled correctly.
8915 testCases = append(testCases, testCase{
8916 testType: serverTest,
8917 name: "EarlyChangeCipherSpec-server-1",
8918 config: Config{
8919 MaxVersion: VersionTLS12,
8920 Bugs: ProtocolBugs{
8921 EarlyChangeCipherSpec: 1,
8922 },
8923 },
8924 shouldFail: true,
8925 expectedError: ":UNEXPECTED_RECORD:",
8926 })
8927 testCases = append(testCases, testCase{
8928 testType: serverTest,
8929 name: "EarlyChangeCipherSpec-server-2",
8930 config: Config{
8931 MaxVersion: VersionTLS12,
8932 Bugs: ProtocolBugs{
8933 EarlyChangeCipherSpec: 2,
8934 },
8935 },
8936 shouldFail: true,
8937 expectedError: ":UNEXPECTED_RECORD:",
8938 })
8939 testCases = append(testCases, testCase{
8940 protocol: dtls,
8941 name: "StrayChangeCipherSpec",
8942 config: Config{
8943 // TODO(davidben): Once DTLS 1.3 exists, test
8944 // that stray ChangeCipherSpec messages are
8945 // rejected.
8946 MaxVersion: VersionTLS12,
8947 Bugs: ProtocolBugs{
8948 StrayChangeCipherSpec: true,
8949 },
8950 },
8951 })
8952
8953 // Test that the contents of ChangeCipherSpec are checked.
8954 testCases = append(testCases, testCase{
8955 name: "BadChangeCipherSpec-1",
8956 config: Config{
8957 MaxVersion: VersionTLS12,
8958 Bugs: ProtocolBugs{
8959 BadChangeCipherSpec: []byte{2},
8960 },
8961 },
8962 shouldFail: true,
8963 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8964 })
8965 testCases = append(testCases, testCase{
8966 name: "BadChangeCipherSpec-2",
8967 config: Config{
8968 MaxVersion: VersionTLS12,
8969 Bugs: ProtocolBugs{
8970 BadChangeCipherSpec: []byte{1, 1},
8971 },
8972 },
8973 shouldFail: true,
8974 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8975 })
8976 testCases = append(testCases, testCase{
8977 protocol: dtls,
8978 name: "BadChangeCipherSpec-DTLS-1",
8979 config: Config{
8980 MaxVersion: VersionTLS12,
8981 Bugs: ProtocolBugs{
8982 BadChangeCipherSpec: []byte{2},
8983 },
8984 },
8985 shouldFail: true,
8986 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8987 })
8988 testCases = append(testCases, testCase{
8989 protocol: dtls,
8990 name: "BadChangeCipherSpec-DTLS-2",
8991 config: Config{
8992 MaxVersion: VersionTLS12,
8993 Bugs: ProtocolBugs{
8994 BadChangeCipherSpec: []byte{1, 1},
8995 },
8996 },
8997 shouldFail: true,
8998 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8999 })
9000}
9001
David Benjamincd2c8062016-09-09 11:28:16 -04009002type perMessageTest struct {
9003 messageType uint8
9004 test testCase
9005}
9006
9007// makePerMessageTests returns a series of test templates which cover each
9008// message in the TLS handshake. These may be used with bugs like
9009// WrongMessageType to fully test a per-message bug.
9010func makePerMessageTests() []perMessageTest {
9011 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04009012 for _, protocol := range []protocol{tls, dtls} {
9013 var suffix string
9014 if protocol == dtls {
9015 suffix = "-DTLS"
9016 }
9017
David Benjamincd2c8062016-09-09 11:28:16 -04009018 ret = append(ret, perMessageTest{
9019 messageType: typeClientHello,
9020 test: testCase{
9021 protocol: protocol,
9022 testType: serverTest,
9023 name: "ClientHello" + suffix,
9024 config: Config{
9025 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009026 },
9027 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009028 })
9029
9030 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009031 ret = append(ret, perMessageTest{
9032 messageType: typeHelloVerifyRequest,
9033 test: testCase{
9034 protocol: protocol,
9035 name: "HelloVerifyRequest" + suffix,
9036 config: Config{
9037 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009038 },
9039 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009040 })
9041 }
9042
David Benjamincd2c8062016-09-09 11:28:16 -04009043 ret = append(ret, perMessageTest{
9044 messageType: typeServerHello,
9045 test: testCase{
9046 protocol: protocol,
9047 name: "ServerHello" + suffix,
9048 config: Config{
9049 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009050 },
9051 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009052 })
9053
David Benjamincd2c8062016-09-09 11:28:16 -04009054 ret = append(ret, perMessageTest{
9055 messageType: typeCertificate,
9056 test: testCase{
9057 protocol: protocol,
9058 name: "ServerCertificate" + suffix,
9059 config: Config{
9060 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009061 },
9062 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009063 })
9064
David Benjamincd2c8062016-09-09 11:28:16 -04009065 ret = append(ret, perMessageTest{
9066 messageType: typeCertificateStatus,
9067 test: testCase{
9068 protocol: protocol,
9069 name: "CertificateStatus" + suffix,
9070 config: Config{
9071 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009072 },
David Benjamincd2c8062016-09-09 11:28:16 -04009073 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009074 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009075 })
9076
David Benjamincd2c8062016-09-09 11:28:16 -04009077 ret = append(ret, perMessageTest{
9078 messageType: typeServerKeyExchange,
9079 test: testCase{
9080 protocol: protocol,
9081 name: "ServerKeyExchange" + suffix,
9082 config: Config{
9083 MaxVersion: VersionTLS12,
9084 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009085 },
9086 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009087 })
9088
David Benjamincd2c8062016-09-09 11:28:16 -04009089 ret = append(ret, perMessageTest{
9090 messageType: typeCertificateRequest,
9091 test: testCase{
9092 protocol: protocol,
9093 name: "CertificateRequest" + suffix,
9094 config: Config{
9095 MaxVersion: VersionTLS12,
9096 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009097 },
9098 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009099 })
9100
David Benjamincd2c8062016-09-09 11:28:16 -04009101 ret = append(ret, perMessageTest{
9102 messageType: typeServerHelloDone,
9103 test: testCase{
9104 protocol: protocol,
9105 name: "ServerHelloDone" + suffix,
9106 config: Config{
9107 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009108 },
9109 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009110 })
9111
David Benjamincd2c8062016-09-09 11:28:16 -04009112 ret = append(ret, perMessageTest{
9113 messageType: typeCertificate,
9114 test: testCase{
9115 testType: serverTest,
9116 protocol: protocol,
9117 name: "ClientCertificate" + suffix,
9118 config: Config{
9119 Certificates: []Certificate{rsaCertificate},
9120 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009121 },
David Benjamincd2c8062016-09-09 11:28:16 -04009122 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009123 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009124 })
9125
David Benjamincd2c8062016-09-09 11:28:16 -04009126 ret = append(ret, perMessageTest{
9127 messageType: typeCertificateVerify,
9128 test: testCase{
9129 testType: serverTest,
9130 protocol: protocol,
9131 name: "CertificateVerify" + suffix,
9132 config: Config{
9133 Certificates: []Certificate{rsaCertificate},
9134 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009135 },
David Benjamincd2c8062016-09-09 11:28:16 -04009136 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009137 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009138 })
9139
David Benjamincd2c8062016-09-09 11:28:16 -04009140 ret = append(ret, perMessageTest{
9141 messageType: typeClientKeyExchange,
9142 test: testCase{
9143 testType: serverTest,
9144 protocol: protocol,
9145 name: "ClientKeyExchange" + suffix,
9146 config: Config{
9147 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009148 },
9149 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009150 })
9151
9152 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009153 ret = append(ret, perMessageTest{
9154 messageType: typeNextProtocol,
9155 test: testCase{
9156 testType: serverTest,
9157 protocol: protocol,
9158 name: "NextProtocol" + suffix,
9159 config: Config{
9160 MaxVersion: VersionTLS12,
9161 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009162 },
David Benjamincd2c8062016-09-09 11:28:16 -04009163 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009164 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009165 })
9166
David Benjamincd2c8062016-09-09 11:28:16 -04009167 ret = append(ret, perMessageTest{
9168 messageType: typeChannelID,
9169 test: testCase{
9170 testType: serverTest,
9171 protocol: protocol,
9172 name: "ChannelID" + suffix,
9173 config: Config{
9174 MaxVersion: VersionTLS12,
9175 ChannelID: channelIDKey,
9176 },
9177 flags: []string{
9178 "-expect-channel-id",
9179 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009180 },
9181 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009182 })
9183 }
9184
David Benjamincd2c8062016-09-09 11:28:16 -04009185 ret = append(ret, perMessageTest{
9186 messageType: typeFinished,
9187 test: testCase{
9188 testType: serverTest,
9189 protocol: protocol,
9190 name: "ClientFinished" + suffix,
9191 config: Config{
9192 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009193 },
9194 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009195 })
9196
David Benjamincd2c8062016-09-09 11:28:16 -04009197 ret = append(ret, perMessageTest{
9198 messageType: typeNewSessionTicket,
9199 test: testCase{
9200 protocol: protocol,
9201 name: "NewSessionTicket" + suffix,
9202 config: Config{
9203 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009204 },
9205 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009206 })
9207
David Benjamincd2c8062016-09-09 11:28:16 -04009208 ret = append(ret, perMessageTest{
9209 messageType: typeFinished,
9210 test: testCase{
9211 protocol: protocol,
9212 name: "ServerFinished" + suffix,
9213 config: Config{
9214 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009215 },
9216 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009217 })
9218
9219 }
David Benjamincd2c8062016-09-09 11:28:16 -04009220
9221 ret = append(ret, perMessageTest{
9222 messageType: typeClientHello,
9223 test: testCase{
9224 testType: serverTest,
9225 name: "TLS13-ClientHello",
9226 config: Config{
9227 MaxVersion: VersionTLS13,
9228 },
9229 },
9230 })
9231
9232 ret = append(ret, perMessageTest{
9233 messageType: typeServerHello,
9234 test: testCase{
9235 name: "TLS13-ServerHello",
9236 config: Config{
9237 MaxVersion: VersionTLS13,
9238 },
9239 },
9240 })
9241
9242 ret = append(ret, perMessageTest{
9243 messageType: typeEncryptedExtensions,
9244 test: testCase{
9245 name: "TLS13-EncryptedExtensions",
9246 config: Config{
9247 MaxVersion: VersionTLS13,
9248 },
9249 },
9250 })
9251
9252 ret = append(ret, perMessageTest{
9253 messageType: typeCertificateRequest,
9254 test: testCase{
9255 name: "TLS13-CertificateRequest",
9256 config: Config{
9257 MaxVersion: VersionTLS13,
9258 ClientAuth: RequireAnyClientCert,
9259 },
9260 },
9261 })
9262
9263 ret = append(ret, perMessageTest{
9264 messageType: typeCertificate,
9265 test: testCase{
9266 name: "TLS13-ServerCertificate",
9267 config: Config{
9268 MaxVersion: VersionTLS13,
9269 },
9270 },
9271 })
9272
9273 ret = append(ret, perMessageTest{
9274 messageType: typeCertificateVerify,
9275 test: testCase{
9276 name: "TLS13-ServerCertificateVerify",
9277 config: Config{
9278 MaxVersion: VersionTLS13,
9279 },
9280 },
9281 })
9282
9283 ret = append(ret, perMessageTest{
9284 messageType: typeFinished,
9285 test: testCase{
9286 name: "TLS13-ServerFinished",
9287 config: Config{
9288 MaxVersion: VersionTLS13,
9289 },
9290 },
9291 })
9292
9293 ret = append(ret, perMessageTest{
9294 messageType: typeCertificate,
9295 test: testCase{
9296 testType: serverTest,
9297 name: "TLS13-ClientCertificate",
9298 config: Config{
9299 Certificates: []Certificate{rsaCertificate},
9300 MaxVersion: VersionTLS13,
9301 },
9302 flags: []string{"-require-any-client-certificate"},
9303 },
9304 })
9305
9306 ret = append(ret, perMessageTest{
9307 messageType: typeCertificateVerify,
9308 test: testCase{
9309 testType: serverTest,
9310 name: "TLS13-ClientCertificateVerify",
9311 config: Config{
9312 Certificates: []Certificate{rsaCertificate},
9313 MaxVersion: VersionTLS13,
9314 },
9315 flags: []string{"-require-any-client-certificate"},
9316 },
9317 })
9318
9319 ret = append(ret, perMessageTest{
9320 messageType: typeFinished,
9321 test: testCase{
9322 testType: serverTest,
9323 name: "TLS13-ClientFinished",
9324 config: Config{
9325 MaxVersion: VersionTLS13,
9326 },
9327 },
9328 })
9329
9330 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009331}
9332
David Benjamincd2c8062016-09-09 11:28:16 -04009333func addWrongMessageTypeTests() {
9334 for _, t := range makePerMessageTests() {
9335 t.test.name = "WrongMessageType-" + t.test.name
9336 t.test.config.Bugs.SendWrongMessageType = t.messageType
9337 t.test.shouldFail = true
9338 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9339 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009340
David Benjamincd2c8062016-09-09 11:28:16 -04009341 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9342 // In TLS 1.3, a bad ServerHello means the client sends
9343 // an unencrypted alert while the server expects
9344 // encryption, so the alert is not readable by runner.
9345 t.test.expectedLocalError = "local error: bad record MAC"
9346 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009347
David Benjamincd2c8062016-09-09 11:28:16 -04009348 testCases = append(testCases, t.test)
9349 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009350}
9351
David Benjamin639846e2016-09-09 11:41:18 -04009352func addTrailingMessageDataTests() {
9353 for _, t := range makePerMessageTests() {
9354 t.test.name = "TrailingMessageData-" + t.test.name
9355 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9356 t.test.shouldFail = true
9357 t.test.expectedError = ":DECODE_ERROR:"
9358 t.test.expectedLocalError = "remote error: error decoding message"
9359
9360 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9361 // In TLS 1.3, a bad ServerHello means the client sends
9362 // an unencrypted alert while the server expects
9363 // encryption, so the alert is not readable by runner.
9364 t.test.expectedLocalError = "local error: bad record MAC"
9365 }
9366
9367 if t.messageType == typeFinished {
9368 // Bad Finished messages read as the verify data having
9369 // the wrong length.
9370 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9371 t.test.expectedLocalError = "remote error: error decrypting message"
9372 }
9373
9374 testCases = append(testCases, t.test)
9375 }
9376}
9377
Steven Valdez143e8b32016-07-11 13:19:03 -04009378func addTLS13HandshakeTests() {
9379 testCases = append(testCases, testCase{
9380 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009381 name: "NegotiatePSKResumption-TLS13",
9382 config: Config{
9383 MaxVersion: VersionTLS13,
9384 Bugs: ProtocolBugs{
9385 NegotiatePSKResumption: true,
9386 },
9387 },
9388 resumeSession: true,
9389 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009390 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009391 })
9392
9393 testCases = append(testCases, testCase{
9394 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009395 name: "MissingKeyShare-Client",
9396 config: Config{
9397 MaxVersion: VersionTLS13,
9398 Bugs: ProtocolBugs{
9399 MissingKeyShare: true,
9400 },
9401 },
9402 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009403 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009404 })
9405
9406 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009407 testType: serverTest,
9408 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009409 config: Config{
9410 MaxVersion: VersionTLS13,
9411 Bugs: ProtocolBugs{
9412 MissingKeyShare: true,
9413 },
9414 },
9415 shouldFail: true,
9416 expectedError: ":MISSING_KEY_SHARE:",
9417 })
9418
9419 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009420 testType: serverTest,
9421 name: "DuplicateKeyShares",
9422 config: Config{
9423 MaxVersion: VersionTLS13,
9424 Bugs: ProtocolBugs{
9425 DuplicateKeyShares: true,
9426 },
9427 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009428 shouldFail: true,
9429 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009430 })
9431
9432 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009433 testType: serverTest,
9434 name: "SkipEarlyData",
9435 config: Config{
9436 MaxVersion: VersionTLS13,
9437 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009438 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009439 },
9440 },
9441 })
9442
9443 testCases = append(testCases, testCase{
9444 testType: serverTest,
9445 name: "SkipEarlyData-OmitEarlyDataExtension",
9446 config: Config{
9447 MaxVersion: VersionTLS13,
9448 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009449 SendFakeEarlyDataLength: 4,
9450 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009451 },
9452 },
9453 shouldFail: true,
9454 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9455 })
9456
9457 testCases = append(testCases, testCase{
9458 testType: serverTest,
9459 name: "SkipEarlyData-TooMuchData",
9460 config: Config{
9461 MaxVersion: VersionTLS13,
9462 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009463 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009464 },
9465 },
9466 shouldFail: true,
9467 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9468 })
9469
9470 testCases = append(testCases, testCase{
9471 testType: serverTest,
9472 name: "SkipEarlyData-Interleaved",
9473 config: Config{
9474 MaxVersion: VersionTLS13,
9475 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009476 SendFakeEarlyDataLength: 4,
9477 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009478 },
9479 },
9480 shouldFail: true,
9481 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9482 })
9483
9484 testCases = append(testCases, testCase{
9485 testType: serverTest,
9486 name: "SkipEarlyData-EarlyDataInTLS12",
9487 config: Config{
9488 MaxVersion: VersionTLS13,
9489 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009490 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009491 },
9492 },
9493 shouldFail: true,
9494 expectedError: ":UNEXPECTED_RECORD:",
9495 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9496 })
9497
9498 testCases = append(testCases, testCase{
9499 testType: serverTest,
9500 name: "SkipEarlyData-HRR",
9501 config: Config{
9502 MaxVersion: VersionTLS13,
9503 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009504 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009505 },
9506 DefaultCurves: []CurveID{},
9507 },
9508 })
9509
9510 testCases = append(testCases, testCase{
9511 testType: serverTest,
9512 name: "SkipEarlyData-HRR-Interleaved",
9513 config: Config{
9514 MaxVersion: VersionTLS13,
9515 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009516 SendFakeEarlyDataLength: 4,
9517 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009518 },
9519 DefaultCurves: []CurveID{},
9520 },
9521 shouldFail: true,
9522 expectedError: ":UNEXPECTED_RECORD:",
9523 })
9524
9525 testCases = append(testCases, testCase{
9526 testType: serverTest,
9527 name: "SkipEarlyData-HRR-TooMuchData",
9528 config: Config{
9529 MaxVersion: VersionTLS13,
9530 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009531 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009532 },
9533 DefaultCurves: []CurveID{},
9534 },
9535 shouldFail: true,
9536 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9537 })
9538
9539 // Test that skipping early data looking for cleartext correctly
9540 // processes an alert record.
9541 testCases = append(testCases, testCase{
9542 testType: serverTest,
9543 name: "SkipEarlyData-HRR-FatalAlert",
9544 config: Config{
9545 MaxVersion: VersionTLS13,
9546 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009547 SendEarlyAlert: true,
9548 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009549 },
9550 DefaultCurves: []CurveID{},
9551 },
9552 shouldFail: true,
9553 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9554 })
9555
9556 testCases = append(testCases, testCase{
9557 testType: serverTest,
9558 name: "SkipEarlyData-SecondClientHelloEarlyData",
9559 config: Config{
9560 MaxVersion: VersionTLS13,
9561 Bugs: ProtocolBugs{
9562 SendEarlyDataOnSecondClientHello: true,
9563 },
9564 DefaultCurves: []CurveID{},
9565 },
9566 shouldFail: true,
9567 expectedLocalError: "remote error: bad record MAC",
9568 })
9569
9570 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009571 testType: clientTest,
9572 name: "EmptyEncryptedExtensions",
9573 config: Config{
9574 MaxVersion: VersionTLS13,
9575 Bugs: ProtocolBugs{
9576 EmptyEncryptedExtensions: true,
9577 },
9578 },
9579 shouldFail: true,
9580 expectedLocalError: "remote error: error decoding message",
9581 })
9582
9583 testCases = append(testCases, testCase{
9584 testType: clientTest,
9585 name: "EncryptedExtensionsWithKeyShare",
9586 config: Config{
9587 MaxVersion: VersionTLS13,
9588 Bugs: ProtocolBugs{
9589 EncryptedExtensionsWithKeyShare: true,
9590 },
9591 },
9592 shouldFail: true,
9593 expectedLocalError: "remote error: unsupported extension",
9594 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009595
9596 testCases = append(testCases, testCase{
9597 testType: serverTest,
9598 name: "SendHelloRetryRequest",
9599 config: Config{
9600 MaxVersion: VersionTLS13,
9601 // Require a HelloRetryRequest for every curve.
9602 DefaultCurves: []CurveID{},
9603 },
9604 expectedCurveID: CurveX25519,
9605 })
9606
9607 testCases = append(testCases, testCase{
9608 testType: serverTest,
9609 name: "SendHelloRetryRequest-2",
9610 config: Config{
9611 MaxVersion: VersionTLS13,
9612 DefaultCurves: []CurveID{CurveP384},
9613 },
9614 // Although the ClientHello did not predict our preferred curve,
9615 // we always select it whether it is predicted or not.
9616 expectedCurveID: CurveX25519,
9617 })
9618
9619 testCases = append(testCases, testCase{
9620 name: "UnknownCurve-HelloRetryRequest",
9621 config: Config{
9622 MaxVersion: VersionTLS13,
9623 // P-384 requires HelloRetryRequest in BoringSSL.
9624 CurvePreferences: []CurveID{CurveP384},
9625 Bugs: ProtocolBugs{
9626 SendHelloRetryRequestCurve: bogusCurve,
9627 },
9628 },
9629 shouldFail: true,
9630 expectedError: ":WRONG_CURVE:",
9631 })
9632
9633 testCases = append(testCases, testCase{
9634 name: "DisabledCurve-HelloRetryRequest",
9635 config: Config{
9636 MaxVersion: VersionTLS13,
9637 CurvePreferences: []CurveID{CurveP256},
9638 Bugs: ProtocolBugs{
9639 IgnorePeerCurvePreferences: true,
9640 },
9641 },
9642 flags: []string{"-p384-only"},
9643 shouldFail: true,
9644 expectedError: ":WRONG_CURVE:",
9645 })
9646
9647 testCases = append(testCases, testCase{
9648 name: "UnnecessaryHelloRetryRequest",
9649 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009650 MaxVersion: VersionTLS13,
9651 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009652 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009653 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009654 },
9655 },
9656 shouldFail: true,
9657 expectedError: ":WRONG_CURVE:",
9658 })
9659
9660 testCases = append(testCases, testCase{
9661 name: "SecondHelloRetryRequest",
9662 config: Config{
9663 MaxVersion: VersionTLS13,
9664 // P-384 requires HelloRetryRequest in BoringSSL.
9665 CurvePreferences: []CurveID{CurveP384},
9666 Bugs: ProtocolBugs{
9667 SecondHelloRetryRequest: true,
9668 },
9669 },
9670 shouldFail: true,
9671 expectedError: ":UNEXPECTED_MESSAGE:",
9672 })
9673
9674 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009675 name: "HelloRetryRequest-Empty",
9676 config: Config{
9677 MaxVersion: VersionTLS13,
9678 Bugs: ProtocolBugs{
9679 AlwaysSendHelloRetryRequest: true,
9680 },
9681 },
9682 shouldFail: true,
9683 expectedError: ":DECODE_ERROR:",
9684 })
9685
9686 testCases = append(testCases, testCase{
9687 name: "HelloRetryRequest-DuplicateCurve",
9688 config: Config{
9689 MaxVersion: VersionTLS13,
9690 // P-384 requires a HelloRetryRequest against BoringSSL's default
9691 // configuration. Assert this ExpectMissingKeyShare.
9692 CurvePreferences: []CurveID{CurveP384},
9693 Bugs: ProtocolBugs{
9694 ExpectMissingKeyShare: true,
9695 DuplicateHelloRetryRequestExtensions: true,
9696 },
9697 },
9698 shouldFail: true,
9699 expectedError: ":DUPLICATE_EXTENSION:",
9700 expectedLocalError: "remote error: illegal parameter",
9701 })
9702
9703 testCases = append(testCases, testCase{
9704 name: "HelloRetryRequest-Cookie",
9705 config: Config{
9706 MaxVersion: VersionTLS13,
9707 Bugs: ProtocolBugs{
9708 SendHelloRetryRequestCookie: []byte("cookie"),
9709 },
9710 },
9711 })
9712
9713 testCases = append(testCases, testCase{
9714 name: "HelloRetryRequest-DuplicateCookie",
9715 config: Config{
9716 MaxVersion: VersionTLS13,
9717 Bugs: ProtocolBugs{
9718 SendHelloRetryRequestCookie: []byte("cookie"),
9719 DuplicateHelloRetryRequestExtensions: true,
9720 },
9721 },
9722 shouldFail: true,
9723 expectedError: ":DUPLICATE_EXTENSION:",
9724 expectedLocalError: "remote error: illegal parameter",
9725 })
9726
9727 testCases = append(testCases, testCase{
9728 name: "HelloRetryRequest-EmptyCookie",
9729 config: Config{
9730 MaxVersion: VersionTLS13,
9731 Bugs: ProtocolBugs{
9732 SendHelloRetryRequestCookie: []byte{},
9733 },
9734 },
9735 shouldFail: true,
9736 expectedError: ":DECODE_ERROR:",
9737 })
9738
9739 testCases = append(testCases, testCase{
9740 name: "HelloRetryRequest-Cookie-Curve",
9741 config: Config{
9742 MaxVersion: VersionTLS13,
9743 // P-384 requires HelloRetryRequest in BoringSSL.
9744 CurvePreferences: []CurveID{CurveP384},
9745 Bugs: ProtocolBugs{
9746 SendHelloRetryRequestCookie: []byte("cookie"),
9747 ExpectMissingKeyShare: true,
9748 },
9749 },
9750 })
9751
9752 testCases = append(testCases, testCase{
9753 name: "HelloRetryRequest-Unknown",
9754 config: Config{
9755 MaxVersion: VersionTLS13,
9756 Bugs: ProtocolBugs{
9757 CustomHelloRetryRequestExtension: "extension",
9758 },
9759 },
9760 shouldFail: true,
9761 expectedError: ":UNEXPECTED_EXTENSION:",
9762 expectedLocalError: "remote error: unsupported extension",
9763 })
9764
9765 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009766 testType: serverTest,
9767 name: "SecondClientHelloMissingKeyShare",
9768 config: Config{
9769 MaxVersion: VersionTLS13,
9770 DefaultCurves: []CurveID{},
9771 Bugs: ProtocolBugs{
9772 SecondClientHelloMissingKeyShare: true,
9773 },
9774 },
9775 shouldFail: true,
9776 expectedError: ":MISSING_KEY_SHARE:",
9777 })
9778
9779 testCases = append(testCases, testCase{
9780 testType: serverTest,
9781 name: "SecondClientHelloWrongCurve",
9782 config: Config{
9783 MaxVersion: VersionTLS13,
9784 DefaultCurves: []CurveID{},
9785 Bugs: ProtocolBugs{
9786 MisinterpretHelloRetryRequestCurve: CurveP521,
9787 },
9788 },
9789 shouldFail: true,
9790 expectedError: ":WRONG_CURVE:",
9791 })
9792
9793 testCases = append(testCases, testCase{
9794 name: "HelloRetryRequestVersionMismatch",
9795 config: Config{
9796 MaxVersion: VersionTLS13,
9797 // P-384 requires HelloRetryRequest in BoringSSL.
9798 CurvePreferences: []CurveID{CurveP384},
9799 Bugs: ProtocolBugs{
9800 SendServerHelloVersion: 0x0305,
9801 },
9802 },
9803 shouldFail: true,
9804 expectedError: ":WRONG_VERSION_NUMBER:",
9805 })
9806
9807 testCases = append(testCases, testCase{
9808 name: "HelloRetryRequestCurveMismatch",
9809 config: Config{
9810 MaxVersion: VersionTLS13,
9811 // P-384 requires HelloRetryRequest in BoringSSL.
9812 CurvePreferences: []CurveID{CurveP384},
9813 Bugs: ProtocolBugs{
9814 // Send P-384 (correct) in the HelloRetryRequest.
9815 SendHelloRetryRequestCurve: CurveP384,
9816 // But send P-256 in the ServerHello.
9817 SendCurve: CurveP256,
9818 },
9819 },
9820 shouldFail: true,
9821 expectedError: ":WRONG_CURVE:",
9822 })
9823
9824 // Test the server selecting a curve that requires a HelloRetryRequest
9825 // without sending it.
9826 testCases = append(testCases, testCase{
9827 name: "SkipHelloRetryRequest",
9828 config: Config{
9829 MaxVersion: VersionTLS13,
9830 // P-384 requires HelloRetryRequest in BoringSSL.
9831 CurvePreferences: []CurveID{CurveP384},
9832 Bugs: ProtocolBugs{
9833 SkipHelloRetryRequest: true,
9834 },
9835 },
9836 shouldFail: true,
9837 expectedError: ":WRONG_CURVE:",
9838 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009839
9840 testCases = append(testCases, testCase{
9841 name: "TLS13-RequestContextInHandshake",
9842 config: Config{
9843 MaxVersion: VersionTLS13,
9844 MinVersion: VersionTLS13,
9845 ClientAuth: RequireAnyClientCert,
9846 Bugs: ProtocolBugs{
9847 SendRequestContext: []byte("request context"),
9848 },
9849 },
9850 flags: []string{
9851 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9852 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9853 },
9854 shouldFail: true,
9855 expectedError: ":DECODE_ERROR:",
9856 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009857
9858 testCases = append(testCases, testCase{
9859 testType: serverTest,
9860 name: "TLS13-TrailingKeyShareData",
9861 config: Config{
9862 MaxVersion: VersionTLS13,
9863 Bugs: ProtocolBugs{
9864 TrailingKeyShareData: true,
9865 },
9866 },
9867 shouldFail: true,
9868 expectedError: ":DECODE_ERROR:",
9869 })
David Benjamin7f78df42016-10-05 22:33:19 -04009870
9871 testCases = append(testCases, testCase{
9872 name: "TLS13-AlwaysSelectPSKIdentity",
9873 config: Config{
9874 MaxVersion: VersionTLS13,
9875 Bugs: ProtocolBugs{
9876 AlwaysSelectPSKIdentity: true,
9877 },
9878 },
9879 shouldFail: true,
9880 expectedError: ":UNEXPECTED_EXTENSION:",
9881 })
9882
9883 testCases = append(testCases, testCase{
9884 name: "TLS13-InvalidPSKIdentity",
9885 config: Config{
9886 MaxVersion: VersionTLS13,
9887 Bugs: ProtocolBugs{
9888 SelectPSKIdentityOnResume: 1,
9889 },
9890 },
9891 resumeSession: true,
9892 shouldFail: true,
9893 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9894 })
David Benjamin1286bee2016-10-07 15:25:06 -04009895
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009896 testCases = append(testCases, testCase{
9897 testType: serverTest,
9898 name: "TLS13-ExtraPSKIdentity",
9899 config: Config{
9900 MaxVersion: VersionTLS13,
9901 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009902 ExtraPSKIdentity: true,
9903 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009904 },
9905 },
9906 resumeSession: true,
9907 })
9908
David Benjamin1286bee2016-10-07 15:25:06 -04009909 // Test that unknown NewSessionTicket extensions are tolerated.
9910 testCases = append(testCases, testCase{
9911 name: "TLS13-CustomTicketExtension",
9912 config: Config{
9913 MaxVersion: VersionTLS13,
9914 Bugs: ProtocolBugs{
9915 CustomTicketExtension: "1234",
9916 },
9917 },
9918 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009919}
9920
David Benjaminabbbee12016-10-31 19:20:42 -04009921func addTLS13CipherPreferenceTests() {
9922 // Test that client preference is honored if the shim has AES hardware
9923 // and ChaCha20-Poly1305 is preferred otherwise.
9924 testCases = append(testCases, testCase{
9925 testType: serverTest,
9926 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9927 config: Config{
9928 MaxVersion: VersionTLS13,
9929 CipherSuites: []uint16{
9930 TLS_CHACHA20_POLY1305_SHA256,
9931 TLS_AES_128_GCM_SHA256,
9932 },
9933 },
9934 flags: []string{
9935 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9936 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9937 },
9938 })
9939
9940 testCases = append(testCases, testCase{
9941 testType: serverTest,
9942 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9943 config: Config{
9944 MaxVersion: VersionTLS13,
9945 CipherSuites: []uint16{
9946 TLS_AES_128_GCM_SHA256,
9947 TLS_CHACHA20_POLY1305_SHA256,
9948 },
9949 },
9950 flags: []string{
9951 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9952 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9953 },
9954 })
9955
9956 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9957 // whether it has AES hardware.
9958 testCases = append(testCases, testCase{
9959 name: "TLS13-CipherPreference-Client",
9960 config: Config{
9961 MaxVersion: VersionTLS13,
9962 // Use the client cipher order. (This is the default but
9963 // is listed to be explicit.)
9964 PreferServerCipherSuites: false,
9965 },
9966 flags: []string{
9967 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9968 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9969 },
9970 })
9971}
9972
David Benjaminf3fbade2016-09-19 13:08:16 -04009973func addPeekTests() {
9974 // Test SSL_peek works, including on empty records.
9975 testCases = append(testCases, testCase{
9976 name: "Peek-Basic",
9977 sendEmptyRecords: 1,
9978 flags: []string{"-peek-then-read"},
9979 })
9980
9981 // Test SSL_peek can drive the initial handshake.
9982 testCases = append(testCases, testCase{
9983 name: "Peek-ImplicitHandshake",
9984 flags: []string{
9985 "-peek-then-read",
9986 "-implicit-handshake",
9987 },
9988 })
9989
9990 // Test SSL_peek can discover and drive a renegotiation.
9991 testCases = append(testCases, testCase{
9992 name: "Peek-Renegotiate",
9993 config: Config{
9994 MaxVersion: VersionTLS12,
9995 },
9996 renegotiate: 1,
9997 flags: []string{
9998 "-peek-then-read",
9999 "-renegotiate-freely",
10000 "-expect-total-renegotiations", "1",
10001 },
10002 })
10003
10004 // Test SSL_peek can discover a close_notify.
10005 testCases = append(testCases, testCase{
10006 name: "Peek-Shutdown",
10007 config: Config{
10008 Bugs: ProtocolBugs{
10009 ExpectCloseNotify: true,
10010 },
10011 },
10012 flags: []string{
10013 "-peek-then-read",
10014 "-check-close-notify",
10015 },
10016 })
10017
10018 // Test SSL_peek can discover an alert.
10019 testCases = append(testCases, testCase{
10020 name: "Peek-Alert",
10021 config: Config{
10022 Bugs: ProtocolBugs{
10023 SendSpuriousAlert: alertRecordOverflow,
10024 },
10025 },
10026 flags: []string{"-peek-then-read"},
10027 shouldFail: true,
10028 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
10029 })
10030
10031 // Test SSL_peek can handle KeyUpdate.
10032 testCases = append(testCases, testCase{
10033 name: "Peek-KeyUpdate",
10034 config: Config{
10035 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -040010036 },
Steven Valdezc4aa7272016-10-03 12:25:56 -040010037 sendKeyUpdates: 1,
10038 keyUpdateRequest: keyUpdateNotRequested,
10039 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -040010040 })
10041}
10042
David Benjamine6f22212016-11-08 14:28:24 -050010043func addRecordVersionTests() {
10044 for _, ver := range tlsVersions {
10045 // Test that the record version is enforced.
10046 testCases = append(testCases, testCase{
10047 name: "CheckRecordVersion-" + ver.name,
10048 config: Config{
10049 MinVersion: ver.version,
10050 MaxVersion: ver.version,
10051 Bugs: ProtocolBugs{
10052 SendRecordVersion: 0x03ff,
10053 },
10054 },
10055 shouldFail: true,
10056 expectedError: ":WRONG_VERSION_NUMBER:",
10057 })
10058
10059 // Test that the ClientHello may use any record version, for
10060 // compatibility reasons.
10061 testCases = append(testCases, testCase{
10062 testType: serverTest,
10063 name: "LooseInitialRecordVersion-" + ver.name,
10064 config: Config{
10065 MinVersion: ver.version,
10066 MaxVersion: ver.version,
10067 Bugs: ProtocolBugs{
10068 SendInitialRecordVersion: 0x03ff,
10069 },
10070 },
10071 })
10072
10073 // Test that garbage ClientHello record versions are rejected.
10074 testCases = append(testCases, testCase{
10075 testType: serverTest,
10076 name: "GarbageInitialRecordVersion-" + ver.name,
10077 config: Config{
10078 MinVersion: ver.version,
10079 MaxVersion: ver.version,
10080 Bugs: ProtocolBugs{
10081 SendInitialRecordVersion: 0xffff,
10082 },
10083 },
10084 shouldFail: true,
10085 expectedError: ":WRONG_VERSION_NUMBER:",
10086 })
10087 }
10088}
10089
David Benjamin2c516452016-11-15 10:16:54 +090010090func addCertificateTests() {
10091 // Test that a certificate chain with intermediate may be sent and
10092 // received as both client and server.
10093 for _, ver := range tlsVersions {
10094 testCases = append(testCases, testCase{
10095 testType: clientTest,
10096 name: "SendReceiveIntermediate-Client-" + ver.name,
10097 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080010098 MinVersion: ver.version,
10099 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090010100 Certificates: []Certificate{rsaChainCertificate},
10101 ClientAuth: RequireAnyClientCert,
10102 },
10103 expectPeerCertificate: &rsaChainCertificate,
10104 flags: []string{
10105 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10106 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
10107 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10108 },
10109 })
10110
10111 testCases = append(testCases, testCase{
10112 testType: serverTest,
10113 name: "SendReceiveIntermediate-Server-" + ver.name,
10114 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -080010115 MinVersion: ver.version,
10116 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +090010117 Certificates: []Certificate{rsaChainCertificate},
10118 },
10119 expectPeerCertificate: &rsaChainCertificate,
10120 flags: []string{
10121 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10122 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
10123 "-require-any-client-certificate",
10124 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
10125 },
10126 })
10127 }
10128}
10129
David Benjaminbbaf3672016-11-17 10:53:09 +090010130func addRetainOnlySHA256ClientCertTests() {
10131 for _, ver := range tlsVersions {
10132 // Test that enabling
10133 // SSL_CTX_set_retain_only_sha256_of_client_certs without
10134 // actually requesting a client certificate is a no-op.
10135 testCases = append(testCases, testCase{
10136 testType: serverTest,
10137 name: "RetainOnlySHA256-NoCert-" + ver.name,
10138 config: Config{
10139 MinVersion: ver.version,
10140 MaxVersion: ver.version,
10141 },
10142 flags: []string{
10143 "-retain-only-sha256-client-cert-initial",
10144 "-retain-only-sha256-client-cert-resume",
10145 },
10146 resumeSession: true,
10147 })
10148
10149 // Test that when retaining only a SHA-256 certificate is
10150 // enabled, the hash appears as expected.
10151 testCases = append(testCases, testCase{
10152 testType: serverTest,
10153 name: "RetainOnlySHA256-Cert-" + ver.name,
10154 config: Config{
10155 MinVersion: ver.version,
10156 MaxVersion: ver.version,
10157 Certificates: []Certificate{rsaCertificate},
10158 },
10159 flags: []string{
10160 "-verify-peer",
10161 "-retain-only-sha256-client-cert-initial",
10162 "-retain-only-sha256-client-cert-resume",
10163 "-expect-sha256-client-cert-initial",
10164 "-expect-sha256-client-cert-resume",
10165 },
10166 resumeSession: true,
10167 })
10168
10169 // Test that when the config changes from on to off, a
10170 // resumption is rejected because the server now wants the full
10171 // certificate chain.
10172 testCases = append(testCases, testCase{
10173 testType: serverTest,
10174 name: "RetainOnlySHA256-OnOff-" + ver.name,
10175 config: Config{
10176 MinVersion: ver.version,
10177 MaxVersion: ver.version,
10178 Certificates: []Certificate{rsaCertificate},
10179 },
10180 flags: []string{
10181 "-verify-peer",
10182 "-retain-only-sha256-client-cert-initial",
10183 "-expect-sha256-client-cert-initial",
10184 },
10185 resumeSession: true,
10186 expectResumeRejected: true,
10187 })
10188
10189 // Test that when the config changes from off to on, a
10190 // resumption is rejected because the server now wants just the
10191 // hash.
10192 testCases = append(testCases, testCase{
10193 testType: serverTest,
10194 name: "RetainOnlySHA256-OffOn-" + ver.name,
10195 config: Config{
10196 MinVersion: ver.version,
10197 MaxVersion: ver.version,
10198 Certificates: []Certificate{rsaCertificate},
10199 },
10200 flags: []string{
10201 "-verify-peer",
10202 "-retain-only-sha256-client-cert-resume",
10203 "-expect-sha256-client-cert-resume",
10204 },
10205 resumeSession: true,
10206 expectResumeRejected: true,
10207 })
10208 }
10209}
10210
Adam Langleya4b91982016-12-12 12:05:53 -080010211func addECDSAKeyUsageTests() {
10212 p256 := elliptic.P256()
10213 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10214 if err != nil {
10215 panic(err)
10216 }
10217
10218 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10219 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10220 if err != nil {
10221 panic(err)
10222 }
10223
10224 template := x509.Certificate{
10225 SerialNumber: serialNumber,
10226 Subject: pkix.Name{
10227 Organization: []string{"Acme Co"},
10228 },
10229 NotBefore: time.Now(),
10230 NotAfter: time.Now(),
10231
10232 // An ECC certificate with only the keyAgreement key usgae may
10233 // be used with ECDH, but not ECDSA.
10234 KeyUsage: x509.KeyUsageKeyAgreement,
10235 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10236 BasicConstraintsValid: true,
10237 }
10238
10239 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10240 if err != nil {
10241 panic(err)
10242 }
10243
10244 cert := Certificate{
10245 Certificate: [][]byte{derBytes},
10246 PrivateKey: priv,
10247 }
10248
10249 for _, ver := range tlsVersions {
10250 if ver.version < VersionTLS12 {
10251 continue
10252 }
10253
10254 testCases = append(testCases, testCase{
10255 testType: clientTest,
10256 name: "ECDSAKeyUsage-" + ver.name,
10257 config: Config{
10258 MinVersion: ver.version,
10259 MaxVersion: ver.version,
10260 Certificates: []Certificate{cert},
10261 },
10262 shouldFail: true,
10263 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10264 })
10265 }
10266}
10267
Adam Langley7c803a62015-06-15 15:35:05 -070010268func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010269 defer wg.Done()
10270
10271 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010272 var err error
10273
David Benjaminba28dfc2016-11-15 17:47:21 +090010274 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010275 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10276 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010277 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010278 if err != nil {
10279 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10280 }
10281 break
10282 }
10283 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010284 } else if *repeatUntilFailure {
10285 for err == nil {
10286 statusChan <- statusMsg{test: test, started: true}
10287 err = runTest(test, shimPath, -1)
10288 }
10289 } else {
10290 statusChan <- statusMsg{test: test, started: true}
10291 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010292 }
Adam Langley95c29f32014-06-20 12:00:00 -070010293 statusChan <- statusMsg{test: test, err: err}
10294 }
10295}
10296
10297type statusMsg struct {
10298 test *testCase
10299 started bool
10300 err error
10301}
10302
David Benjamin5f237bc2015-02-11 17:14:15 -050010303func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010304 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010305
David Benjamin5f237bc2015-02-11 17:14:15 -050010306 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010307 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010308 if !*pipe {
10309 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010310 var erase string
10311 for i := 0; i < lineLen; i++ {
10312 erase += "\b \b"
10313 }
10314 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010315 }
10316
Adam Langley95c29f32014-06-20 12:00:00 -070010317 if msg.started {
10318 started++
10319 } else {
10320 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010321
10322 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010323 if msg.err == errUnimplemented {
10324 if *pipe {
10325 // Print each test instead of a status line.
10326 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10327 }
10328 unimplemented++
10329 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10330 } else {
10331 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10332 failed++
10333 testOutput.addResult(msg.test.name, "FAIL")
10334 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010335 } else {
10336 if *pipe {
10337 // Print each test instead of a status line.
10338 fmt.Printf("PASSED (%s)\n", msg.test.name)
10339 }
10340 testOutput.addResult(msg.test.name, "PASS")
10341 }
Adam Langley95c29f32014-06-20 12:00:00 -070010342 }
10343
David Benjamin5f237bc2015-02-11 17:14:15 -050010344 if !*pipe {
10345 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010346 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010347 lineLen = len(line)
10348 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010349 }
Adam Langley95c29f32014-06-20 12:00:00 -070010350 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010351
10352 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010353}
10354
10355func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010356 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010357 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010358 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010359
Adam Langley7c803a62015-06-15 15:35:05 -070010360 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010361 addCipherSuiteTests()
10362 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010363 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010364 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010365 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010366 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010367 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010368 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010369 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010370 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010371 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010372 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010373 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010374 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010375 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010376 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010377 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010378 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010379 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010380 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010381 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010382 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010383 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010384 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010385 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010386 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010387 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010388 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010389 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010390 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010391 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010392 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010393 addECDSAKeyUsageTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010394
10395 var wg sync.WaitGroup
10396
Adam Langley7c803a62015-06-15 15:35:05 -070010397 statusChan := make(chan statusMsg, *numWorkers)
10398 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010399 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010400
EKRf71d7ed2016-08-06 13:25:12 -070010401 if len(*shimConfigFile) != 0 {
10402 encoded, err := ioutil.ReadFile(*shimConfigFile)
10403 if err != nil {
10404 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10405 os.Exit(1)
10406 }
10407
10408 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10409 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10410 os.Exit(1)
10411 }
10412 }
10413
David Benjamin025b3d32014-07-01 19:53:04 -040010414 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010415
Adam Langley7c803a62015-06-15 15:35:05 -070010416 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010417 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010418 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010419 }
10420
David Benjamin270f0a72016-03-17 14:41:36 -040010421 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010422 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010423 matched := true
10424 if len(*testToRun) != 0 {
10425 var err error
10426 matched, err = filepath.Match(*testToRun, testCases[i].name)
10427 if err != nil {
10428 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10429 os.Exit(1)
10430 }
10431 }
10432
EKRf71d7ed2016-08-06 13:25:12 -070010433 if !*includeDisabled {
10434 for pattern := range shimConfig.DisabledTests {
10435 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10436 if err != nil {
10437 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10438 os.Exit(1)
10439 }
10440
10441 if isDisabled {
10442 matched = false
10443 break
10444 }
10445 }
10446 }
10447
David Benjamin17e12922016-07-28 18:04:43 -040010448 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010449 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010450 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010451
10452 // Only run one test if repeating until failure.
10453 if *repeatUntilFailure {
10454 break
10455 }
Adam Langley95c29f32014-06-20 12:00:00 -070010456 }
10457 }
David Benjamin17e12922016-07-28 18:04:43 -040010458
David Benjamin270f0a72016-03-17 14:41:36 -040010459 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010460 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010461 os.Exit(1)
10462 }
Adam Langley95c29f32014-06-20 12:00:00 -070010463
10464 close(testChan)
10465 wg.Wait()
10466 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010467 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010468
10469 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010470
10471 if *jsonOutput != "" {
10472 if err := testOutput.writeTo(*jsonOutput); err != nil {
10473 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10474 }
10475 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010476
EKR842ae6c2016-07-27 09:22:05 +020010477 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10478 os.Exit(1)
10479 }
10480
10481 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010482 os.Exit(1)
10483 }
Adam Langley95c29f32014-06-20 12:00:00 -070010484}