blob: dd18ce8a4a22dc7b900612b4f870cdf03fc74ec2 [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"
EKRf71d7ed2016-08-06 13:25:12 -070025 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040026 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020027 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070028 "flag"
29 "fmt"
30 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070031 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070032 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070033 "net"
34 "os"
35 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040036 "path"
David Benjamin17e12922016-07-28 18:04:43 -040037 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040038 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080039 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070040 "strings"
41 "sync"
42 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050043 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070044)
45
Adam Langley69a01602014-11-17 17:26:55 -080046var (
EKR842ae6c2016-07-27 09:22:05 +020047 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
48 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
49 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
50 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
51 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
52 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.")
53 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
54 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040055 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020056 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
57 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
58 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
59 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
60 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
61 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
62 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
63 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020064 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070065 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
66 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090067 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 -080068)
Adam Langley95c29f32014-06-20 12:00:00 -070069
EKRf71d7ed2016-08-06 13:25:12 -070070// ShimConfigurations is used with the “json” package and represents a shim
71// config file.
72type ShimConfiguration struct {
73 // DisabledTests maps from a glob-based pattern to a freeform string.
74 // The glob pattern is used to exclude tests from being run and the
75 // freeform string is unparsed but expected to explain why the test is
76 // disabled.
77 DisabledTests map[string]string
78
79 // ErrorMap maps from expected error strings to the correct error
80 // string for the shim in question. For example, it might map
81 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
82 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
83 ErrorMap map[string]string
84}
85
86var shimConfig ShimConfiguration
87
David Benjamin33863262016-07-08 17:20:12 -070088type testCert int
89
David Benjamin025b3d32014-07-01 19:53:04 -040090const (
David Benjamin33863262016-07-08 17:20:12 -070091 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040092 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090093 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070094 testCertECDSAP256
95 testCertECDSAP384
96 testCertECDSAP521
97)
98
99const (
100 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400101 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900102 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700103 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
104 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
105 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400106)
107
108const (
David Benjamina08e49d2014-08-24 01:46:07 -0400109 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400110 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900111 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700112 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
113 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
114 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400115 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400116)
117
David Benjamin7944a9f2016-07-12 22:27:01 -0400118var (
119 rsaCertificate Certificate
120 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900121 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 ecdsaP256Certificate Certificate
123 ecdsaP384Certificate Certificate
124 ecdsaP521Certificate Certificate
125)
David Benjamin33863262016-07-08 17:20:12 -0700126
127var testCerts = []struct {
128 id testCert
129 certFile, keyFile string
130 cert *Certificate
131}{
132 {
133 id: testCertRSA,
134 certFile: rsaCertificateFile,
135 keyFile: rsaKeyFile,
136 cert: &rsaCertificate,
137 },
138 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400139 id: testCertRSA1024,
140 certFile: rsa1024CertificateFile,
141 keyFile: rsa1024KeyFile,
142 cert: &rsa1024Certificate,
143 },
144 {
David Benjamin2c516452016-11-15 10:16:54 +0900145 id: testCertRSAChain,
146 certFile: rsaChainCertificateFile,
147 keyFile: rsaChainKeyFile,
148 cert: &rsaChainCertificate,
149 },
150 {
David Benjamin33863262016-07-08 17:20:12 -0700151 id: testCertECDSAP256,
152 certFile: ecdsaP256CertificateFile,
153 keyFile: ecdsaP256KeyFile,
154 cert: &ecdsaP256Certificate,
155 },
156 {
157 id: testCertECDSAP384,
158 certFile: ecdsaP384CertificateFile,
159 keyFile: ecdsaP384KeyFile,
160 cert: &ecdsaP384Certificate,
161 },
162 {
163 id: testCertECDSAP521,
164 certFile: ecdsaP521CertificateFile,
165 keyFile: ecdsaP521KeyFile,
166 cert: &ecdsaP521Certificate,
167 },
168}
169
David Benjamina08e49d2014-08-24 01:46:07 -0400170var channelIDKey *ecdsa.PrivateKey
171var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700172
David Benjamin61f95272014-11-25 01:55:35 -0500173var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800174var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500175
Steven Valdeza833c352016-11-01 13:39:36 -0400176var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800177var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400178
Adam Langley95c29f32014-06-20 12:00:00 -0700179func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700180 for i := range testCerts {
181 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
182 if err != nil {
183 panic(err)
184 }
185 cert.OCSPStaple = testOCSPResponse
186 cert.SignedCertificateTimestampList = testSCTList
187 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700188 }
David Benjamina08e49d2014-08-24 01:46:07 -0400189
Adam Langley7c803a62015-06-15 15:35:05 -0700190 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400191 if err != nil {
192 panic(err)
193 }
194 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
195 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
196 panic("bad key type")
197 }
198 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
199 if err != nil {
200 panic(err)
201 }
202 if channelIDKey.Curve != elliptic.P256() {
203 panic("bad curve")
204 }
205
206 channelIDBytes = make([]byte, 64)
207 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
208 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700209}
210
David Benjamin33863262016-07-08 17:20:12 -0700211func getRunnerCertificate(t testCert) Certificate {
212 for _, cert := range testCerts {
213 if cert.id == t {
214 return *cert.cert
215 }
216 }
217 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700218}
219
David Benjamin33863262016-07-08 17:20:12 -0700220func getShimCertificate(t testCert) string {
221 for _, cert := range testCerts {
222 if cert.id == t {
223 return cert.certFile
224 }
225 }
226 panic("Unknown test certificate")
227}
228
229func getShimKey(t testCert) string {
230 for _, cert := range testCerts {
231 if cert.id == t {
232 return cert.keyFile
233 }
234 }
235 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700236}
237
David Benjamin025b3d32014-07-01 19:53:04 -0400238type testType int
239
240const (
241 clientTest testType = iota
242 serverTest
243)
244
David Benjamin6fd297b2014-08-11 18:43:38 -0400245type protocol int
246
247const (
248 tls protocol = iota
249 dtls
250)
251
David Benjaminfc7b0862014-09-06 13:21:53 -0400252const (
253 alpn = 1
254 npn = 2
255)
256
Adam Langley95c29f32014-06-20 12:00:00 -0700257type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400258 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400259 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700260 name string
261 config Config
262 shouldFail bool
263 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700264 // expectedLocalError, if not empty, contains a substring that must be
265 // found in the local error.
266 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400267 // expectedVersion, if non-zero, specifies the TLS version that must be
268 // negotiated.
269 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400270 // expectedResumeVersion, if non-zero, specifies the TLS version that
271 // must be negotiated on resumption. If zero, expectedVersion is used.
272 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400273 // expectedCipher, if non-zero, specifies the TLS cipher suite that
274 // should be negotiated.
275 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400276 // expectChannelID controls whether the connection should have
277 // negotiated a Channel ID with channelIDKey.
278 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400279 // expectedNextProto controls whether the connection should
280 // negotiate a next protocol via NPN or ALPN.
281 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400282 // expectNoNextProto, if true, means that no next protocol should be
283 // negotiated.
284 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400285 // expectedNextProtoType, if non-zero, is the expected next
286 // protocol negotiation mechanism.
287 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500288 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
289 // should be negotiated. If zero, none should be negotiated.
290 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100291 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
292 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100293 // expectedSCTList, if not nil, is the expected SCT list to be received.
294 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700295 // expectedPeerSignatureAlgorithm, if not zero, is the signature
296 // algorithm that the peer should have used in the handshake.
297 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400298 // expectedCurveID, if not zero, is the curve that the handshake should
299 // have used.
300 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700301 // messageLen is the length, in bytes, of the test message that will be
302 // sent.
303 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400304 // messageCount is the number of test messages that will be sent.
305 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400306 // certFile is the path to the certificate to use for the server.
307 certFile string
308 // keyFile is the path to the private key to use for the server.
309 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400310 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400311 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400312 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400313 // resumeRenewedSession controls whether a third connection should be
314 // tested which attempts to resume the second connection's session.
315 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700316 // expectResumeRejected, if true, specifies that the attempted
317 // resumption must be rejected by the client. This is only valid for a
318 // serverTest.
319 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400320 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500321 // resumption. Unless newSessionsOnResume is set,
322 // SessionTicketKey, ServerSessionCache, and
323 // ClientSessionCache are copied from the initial connection's
324 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400325 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500326 // newSessionsOnResume, if true, will cause resumeConfig to
327 // use a different session resumption context.
328 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400329 // noSessionCache, if true, will cause the server to run without a
330 // session cache.
331 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400332 // sendPrefix sends a prefix on the socket before actually performing a
333 // handshake.
334 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400335 // shimWritesFirst controls whether the shim sends an initial "hello"
336 // message before doing a roundtrip with the runner.
337 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400338 // shimShutsDown, if true, runs a test where the shim shuts down the
339 // connection immediately after the handshake rather than echoing
340 // messages from the runner.
341 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400342 // renegotiate indicates the number of times the connection should be
343 // renegotiated during the exchange.
344 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400345 // sendHalfHelloRequest, if true, causes the server to send half a
346 // HelloRequest when the handshake completes.
347 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700348 // renegotiateCiphers is a list of ciphersuite ids that will be
349 // switched in just before renegotiation.
350 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500351 // replayWrites, if true, configures the underlying transport
352 // to replay every write it makes in DTLS tests.
353 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500354 // damageFirstWrite, if true, configures the underlying transport to
355 // damage the final byte of the first application data write.
356 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400357 // exportKeyingMaterial, if non-zero, configures the test to exchange
358 // keying material and verify they match.
359 exportKeyingMaterial int
360 exportLabel string
361 exportContext string
362 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400363 // flags, if not empty, contains a list of command-line flags that will
364 // be passed to the shim program.
365 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700366 // testTLSUnique, if true, causes the shim to send the tls-unique value
367 // which will be compared against the expected value.
368 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400369 // sendEmptyRecords is the number of consecutive empty records to send
370 // before and after the test message.
371 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400372 // sendWarningAlerts is the number of consecutive warning alerts to send
373 // before and after the test message.
374 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400375 // sendKeyUpdates is the number of consecutive key updates to send
376 // before and after the test message.
377 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400378 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
379 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400380 // expectMessageDropped, if true, means the test message is expected to
381 // be dropped by the client rather than echoed back.
382 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900383 // expectPeerCertificate, if not nil, is the certificate chain the peer
384 // is expected to send.
385 expectPeerCertificate *Certificate
David Benjamin6f600d62016-12-21 16:06:54 -0500386 // expectShortHeader is whether the short header extension should be negotiated.
387 expectShortHeader bool
Adam Langley95c29f32014-06-20 12:00:00 -0700388}
389
Adam Langley7c803a62015-06-15 15:35:05 -0700390var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700391
David Benjaminc07afb72016-09-22 10:18:58 -0400392func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500393 if len(data) == 0 {
394 return
395 }
396
397 protocol := "tls"
398 if test.protocol == dtls {
399 protocol = "dtls"
400 }
401
402 side := "client"
403 if test.testType == serverTest {
404 side = "server"
405 }
406
407 dir := path.Join(*transcriptDir, protocol, side)
408 if err := os.MkdirAll(dir, 0755); err != nil {
409 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
410 return
411 }
412
David Benjaminc07afb72016-09-22 10:18:58 -0400413 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500414 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
415 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
416 }
417}
418
David Benjamin3ed59772016-03-08 12:50:21 -0500419// A timeoutConn implements an idle timeout on each Read and Write operation.
420type timeoutConn struct {
421 net.Conn
422 timeout time.Duration
423}
424
425func (t *timeoutConn) Read(b []byte) (int, error) {
426 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
427 return 0, err
428 }
429 return t.Conn.Read(b)
430}
431
432func (t *timeoutConn) Write(b []byte) (int, error) {
433 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
434 return 0, err
435 }
436 return t.Conn.Write(b)
437}
438
David Benjaminc07afb72016-09-22 10:18:58 -0400439func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400440 if !test.noSessionCache {
441 if config.ClientSessionCache == nil {
442 config.ClientSessionCache = NewLRUClientSessionCache(1)
443 }
444 if config.ServerSessionCache == nil {
445 config.ServerSessionCache = NewLRUServerSessionCache(1)
446 }
447 }
448 if test.testType == clientTest {
449 if len(config.Certificates) == 0 {
450 config.Certificates = []Certificate{rsaCertificate}
451 }
452 } else {
453 // Supply a ServerName to ensure a constant session cache key,
454 // rather than falling back to net.Conn.RemoteAddr.
455 if len(config.ServerName) == 0 {
456 config.ServerName = "test"
457 }
458 }
459 if *fuzzer {
460 config.Bugs.NullAllCiphers = true
461 }
David Benjamin01a90572016-09-22 00:11:43 -0400462 if *deterministic {
463 config.Time = func() time.Time { return time.Unix(1234, 1234) }
464 }
David Benjamine54af062016-08-08 19:21:18 -0400465
David Benjamin01784b42016-06-07 18:00:52 -0400466 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500467
David Benjamin6fd297b2014-08-11 18:43:38 -0400468 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500469 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
470 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500471 }
472
David Benjamin9867b7d2016-03-01 23:25:48 -0500473 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500474 local, peer := "client", "server"
475 if test.testType == clientTest {
476 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500477 }
David Benjaminebda9b32015-11-02 15:33:18 -0500478 connDebug := &recordingConn{
479 Conn: conn,
480 isDatagram: test.protocol == dtls,
481 local: local,
482 peer: peer,
483 }
484 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500485 if *flagDebug {
486 defer connDebug.WriteTo(os.Stdout)
487 }
488 if len(*transcriptDir) != 0 {
489 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400490 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500491 }()
492 }
David Benjaminebda9b32015-11-02 15:33:18 -0500493
494 if config.Bugs.PacketAdaptor != nil {
495 config.Bugs.PacketAdaptor.debug = connDebug
496 }
497 }
498
499 if test.replayWrites {
500 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 }
502
David Benjamin3ed59772016-03-08 12:50:21 -0500503 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500504 if test.damageFirstWrite {
505 connDamage = newDamageAdaptor(conn)
506 conn = connDamage
507 }
508
David Benjamin6fd297b2014-08-11 18:43:38 -0400509 if test.sendPrefix != "" {
510 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
511 return err
512 }
David Benjamin98e882e2014-08-08 13:24:34 -0400513 }
514
David Benjamin1d5c83e2014-07-22 19:20:02 -0400515 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400516 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400517 if test.protocol == dtls {
518 tlsConn = DTLSServer(conn, config)
519 } else {
520 tlsConn = Server(conn, config)
521 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400522 } else {
523 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400524 if test.protocol == dtls {
525 tlsConn = DTLSClient(conn, config)
526 } else {
527 tlsConn = Client(conn, config)
528 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400529 }
David Benjamin30789da2015-08-29 22:56:45 -0400530 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400531
Adam Langley95c29f32014-06-20 12:00:00 -0700532 if err := tlsConn.Handshake(); err != nil {
533 return err
534 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700535
David Benjamin01fe8202014-09-24 15:21:44 -0400536 // TODO(davidben): move all per-connection expectations into a dedicated
537 // expectations struct that can be specified separately for the two
538 // legs.
539 expectedVersion := test.expectedVersion
540 if isResume && test.expectedResumeVersion != 0 {
541 expectedVersion = test.expectedResumeVersion
542 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700543 connState := tlsConn.ConnectionState()
544 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400545 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400546 }
547
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700548 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400549 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
550 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700551 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
552 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
553 }
David Benjamin90da8c82015-04-20 14:57:57 -0400554
David Benjamina08e49d2014-08-24 01:46:07 -0400555 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700556 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400557 if channelID == nil {
558 return fmt.Errorf("no channel ID negotiated")
559 }
560 if channelID.Curve != channelIDKey.Curve ||
561 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
562 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
563 return fmt.Errorf("incorrect channel ID")
564 }
565 }
566
David Benjaminae2888f2014-09-06 12:58:58 -0400567 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700568 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400569 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
570 }
571 }
572
David Benjaminc7ce9772015-10-09 19:32:41 -0400573 if test.expectNoNextProto {
574 if actual := connState.NegotiatedProtocol; actual != "" {
575 return fmt.Errorf("got unexpected next proto %s", actual)
576 }
577 }
578
David Benjaminfc7b0862014-09-06 13:21:53 -0400579 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700580 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400581 return fmt.Errorf("next proto type mismatch")
582 }
583 }
584
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700585 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500586 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
587 }
588
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100589 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300590 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100591 }
592
Paul Lietar4fac72e2015-09-09 13:44:55 +0100593 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
594 return fmt.Errorf("SCT list mismatch")
595 }
596
Nick Harper60edffd2016-06-21 15:19:24 -0700597 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
598 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400599 }
600
Steven Valdez5440fe02016-07-18 12:40:30 -0400601 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
602 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
603 }
604
David Benjamin2c516452016-11-15 10:16:54 +0900605 if test.expectPeerCertificate != nil {
606 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
607 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
608 }
609 for i, cert := range connState.PeerCertificates {
610 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
611 return fmt.Errorf("peer certificate %d did not match", i+1)
612 }
613 }
614 }
615
David Benjamin6f600d62016-12-21 16:06:54 -0500616 if test.expectShortHeader != connState.ShortHeader {
617 return fmt.Errorf("ShortHeader is %t, but we expected the opposite", connState.ShortHeader)
618 }
619
David Benjaminc565ebb2015-04-03 04:06:36 -0400620 if test.exportKeyingMaterial > 0 {
621 actual := make([]byte, test.exportKeyingMaterial)
622 if _, err := io.ReadFull(tlsConn, actual); err != nil {
623 return err
624 }
625 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
626 if err != nil {
627 return err
628 }
629 if !bytes.Equal(actual, expected) {
630 return fmt.Errorf("keying material mismatch")
631 }
632 }
633
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700634 if test.testTLSUnique {
635 var peersValue [12]byte
636 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
637 return err
638 }
639 expected := tlsConn.ConnectionState().TLSUnique
640 if !bytes.Equal(peersValue[:], expected) {
641 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
642 }
643 }
644
David Benjamine58c4f52014-08-24 03:47:07 -0400645 if test.shimWritesFirst {
646 var buf [5]byte
647 _, err := io.ReadFull(tlsConn, buf[:])
648 if err != nil {
649 return err
650 }
651 if string(buf[:]) != "hello" {
652 return fmt.Errorf("bad initial message")
653 }
654 }
655
Steven Valdez32635b82016-08-16 11:25:03 -0400656 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400657 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400658 return err
659 }
Steven Valdez32635b82016-08-16 11:25:03 -0400660 }
661
David Benjamina8ebe222015-06-06 03:04:39 -0400662 for i := 0; i < test.sendEmptyRecords; i++ {
663 tlsConn.Write(nil)
664 }
665
David Benjamin24f346d2015-06-06 03:28:08 -0400666 for i := 0; i < test.sendWarningAlerts; i++ {
667 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
668 }
669
David Benjamin47921102016-07-28 11:29:18 -0400670 if test.sendHalfHelloRequest {
671 tlsConn.SendHalfHelloRequest()
672 }
673
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400674 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700675 if test.renegotiateCiphers != nil {
676 config.CipherSuites = test.renegotiateCiphers
677 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400678 for i := 0; i < test.renegotiate; i++ {
679 if err := tlsConn.Renegotiate(); err != nil {
680 return err
681 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700682 }
683 } else if test.renegotiateCiphers != nil {
684 panic("renegotiateCiphers without renegotiate")
685 }
686
David Benjamin5fa3eba2015-01-22 16:35:40 -0500687 if test.damageFirstWrite {
688 connDamage.setDamage(true)
689 tlsConn.Write([]byte("DAMAGED WRITE"))
690 connDamage.setDamage(false)
691 }
692
David Benjamin8e6db492015-07-25 18:29:23 -0400693 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700694 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400695 if test.protocol == dtls {
696 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
697 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700698 // Read until EOF.
699 _, err := io.Copy(ioutil.Discard, tlsConn)
700 return err
701 }
David Benjamin4417d052015-04-05 04:17:25 -0400702 if messageLen == 0 {
703 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700704 }
Adam Langley95c29f32014-06-20 12:00:00 -0700705
David Benjamin8e6db492015-07-25 18:29:23 -0400706 messageCount := test.messageCount
707 if messageCount == 0 {
708 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400709 }
710
David Benjamin8e6db492015-07-25 18:29:23 -0400711 for j := 0; j < messageCount; j++ {
712 testMessage := make([]byte, messageLen)
713 for i := range testMessage {
714 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400715 }
David Benjamin8e6db492015-07-25 18:29:23 -0400716 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700717
Steven Valdez32635b82016-08-16 11:25:03 -0400718 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400719 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400720 }
721
David Benjamin8e6db492015-07-25 18:29:23 -0400722 for i := 0; i < test.sendEmptyRecords; i++ {
723 tlsConn.Write(nil)
724 }
725
726 for i := 0; i < test.sendWarningAlerts; i++ {
727 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
728 }
729
David Benjamin4f75aaf2015-09-01 16:53:10 -0400730 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400731 // The shim will not respond.
732 continue
733 }
734
David Benjamin8e6db492015-07-25 18:29:23 -0400735 buf := make([]byte, len(testMessage))
736 if test.protocol == dtls {
737 bufTmp := make([]byte, len(buf)+1)
738 n, err := tlsConn.Read(bufTmp)
739 if err != nil {
740 return err
741 }
742 if n != len(buf) {
743 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
744 }
745 copy(buf, bufTmp)
746 } else {
747 _, err := io.ReadFull(tlsConn, buf)
748 if err != nil {
749 return err
750 }
751 }
752
753 for i, v := range buf {
754 if v != testMessage[i]^0xff {
755 return fmt.Errorf("bad reply contents at byte %d", i)
756 }
Adam Langley95c29f32014-06-20 12:00:00 -0700757 }
758 }
759
760 return nil
761}
762
David Benjamin325b5c32014-07-01 19:40:31 -0400763func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400764 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700765 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400766 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700767 }
David Benjamin325b5c32014-07-01 19:40:31 -0400768 valgrindArgs = append(valgrindArgs, path)
769 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700770
David Benjamin325b5c32014-07-01 19:40:31 -0400771 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772}
773
David Benjamin325b5c32014-07-01 19:40:31 -0400774func gdbOf(path string, args ...string) *exec.Cmd {
775 xtermArgs := []string{"-e", "gdb", "--args"}
776 xtermArgs = append(xtermArgs, path)
777 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700778
David Benjamin325b5c32014-07-01 19:40:31 -0400779 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700780}
781
David Benjamind16bf342015-12-18 00:53:12 -0500782func lldbOf(path string, args ...string) *exec.Cmd {
783 xtermArgs := []string{"-e", "lldb", "--"}
784 xtermArgs = append(xtermArgs, path)
785 xtermArgs = append(xtermArgs, args...)
786
787 return exec.Command("xterm", xtermArgs...)
788}
789
EKR842ae6c2016-07-27 09:22:05 +0200790var (
791 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
792 errUnimplemented = errors.New("child process does not implement needed flags")
793)
Adam Langley69a01602014-11-17 17:26:55 -0800794
David Benjamin87c8a642015-02-21 01:54:29 -0500795// accept accepts a connection from listener, unless waitChan signals a process
796// exit first.
797func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
798 type connOrError struct {
799 conn net.Conn
800 err error
801 }
802 connChan := make(chan connOrError, 1)
803 go func() {
804 conn, err := listener.Accept()
805 connChan <- connOrError{conn, err}
806 close(connChan)
807 }()
808 select {
809 case result := <-connChan:
810 return result.conn, result.err
811 case childErr := <-waitChan:
812 waitChan <- childErr
813 return nil, fmt.Errorf("child exited early: %s", childErr)
814 }
815}
816
EKRf71d7ed2016-08-06 13:25:12 -0700817func translateExpectedError(errorStr string) string {
818 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
819 return translated
820 }
821
822 if *looseErrors {
823 return ""
824 }
825
826 return errorStr
827}
828
Adam Langley7c803a62015-06-15 15:35:05 -0700829func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400830 // Help debugging panics on the Go side.
831 defer func() {
832 if r := recover(); r != nil {
833 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
834 panic(r)
835 }
836 }()
837
Adam Langley38311732014-10-16 19:04:35 -0700838 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
839 panic("Error expected without shouldFail in " + test.name)
840 }
841
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700842 if test.expectResumeRejected && !test.resumeSession {
843 panic("expectResumeRejected without resumeSession in " + test.name)
844 }
845
Adam Langley33b1d4f2016-12-07 15:03:45 -0800846 for _, ver := range tlsVersions {
847 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
848 continue
849 }
850
851 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
852 continue
853 }
854
855 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))
856 }
857
David Benjamin87c8a642015-02-21 01:54:29 -0500858 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
859 if err != nil {
860 panic(err)
861 }
862 defer func() {
863 if listener != nil {
864 listener.Close()
865 }
866 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700867
David Benjamin87c8a642015-02-21 01:54:29 -0500868 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400869 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400870 flags = append(flags, "-server")
871
David Benjamin025b3d32014-07-01 19:53:04 -0400872 flags = append(flags, "-key-file")
873 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700874 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400875 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700876 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400877 }
878
879 flags = append(flags, "-cert-file")
880 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700881 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400882 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400884 }
885 }
David Benjamin5a593af2014-08-11 19:51:50 -0400886
David Benjamin6fd297b2014-08-11 18:43:38 -0400887 if test.protocol == dtls {
888 flags = append(flags, "-dtls")
889 }
890
David Benjamin46662482016-08-17 00:51:00 -0400891 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400892 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400893 resumeCount++
894 if test.resumeRenewedSession {
895 resumeCount++
896 }
897 }
898
899 if resumeCount > 0 {
900 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400901 }
902
David Benjamine58c4f52014-08-24 03:47:07 -0400903 if test.shimWritesFirst {
904 flags = append(flags, "-shim-writes-first")
905 }
906
David Benjamin30789da2015-08-29 22:56:45 -0400907 if test.shimShutsDown {
908 flags = append(flags, "-shim-shuts-down")
909 }
910
David Benjaminc565ebb2015-04-03 04:06:36 -0400911 if test.exportKeyingMaterial > 0 {
912 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
913 flags = append(flags, "-export-label", test.exportLabel)
914 flags = append(flags, "-export-context", test.exportContext)
915 if test.useExportContext {
916 flags = append(flags, "-use-export-context")
917 }
918 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700919 if test.expectResumeRejected {
920 flags = append(flags, "-expect-session-miss")
921 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400922
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700923 if test.testTLSUnique {
924 flags = append(flags, "-tls-unique")
925 }
926
David Benjamin025b3d32014-07-01 19:53:04 -0400927 flags = append(flags, test.flags...)
928
929 var shim *exec.Cmd
930 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700931 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700932 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700933 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500934 } else if *useLLDB {
935 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400936 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700937 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400938 }
David Benjamin025b3d32014-07-01 19:53:04 -0400939 shim.Stdin = os.Stdin
940 var stdoutBuf, stderrBuf bytes.Buffer
941 shim.Stdout = &stdoutBuf
942 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800943 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500944 shim.Env = os.Environ()
945 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800946 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400947 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800948 }
949 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
950 }
David Benjamin025b3d32014-07-01 19:53:04 -0400951
952 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700953 panic(err)
954 }
David Benjamin87c8a642015-02-21 01:54:29 -0500955 waitChan := make(chan error, 1)
956 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700957
958 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700959
David Benjamin7a4aaa42016-09-20 17:58:14 -0400960 if *deterministic {
961 config.Rand = &deterministicRand{}
962 }
963
David Benjamin87c8a642015-02-21 01:54:29 -0500964 conn, err := acceptOrWait(listener, waitChan)
965 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400966 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500967 conn.Close()
968 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500969
David Benjamin46662482016-08-17 00:51:00 -0400970 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400971 var resumeConfig Config
972 if test.resumeConfig != nil {
973 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400974 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500975 resumeConfig.SessionTicketKey = config.SessionTicketKey
976 resumeConfig.ClientSessionCache = config.ClientSessionCache
977 resumeConfig.ServerSessionCache = config.ServerSessionCache
978 }
David Benjamin2e045a92016-06-08 13:09:56 -0400979 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400980 } else {
981 resumeConfig = config
982 }
David Benjamin87c8a642015-02-21 01:54:29 -0500983 var connResume net.Conn
984 connResume, err = acceptOrWait(listener, waitChan)
985 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400986 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500987 connResume.Close()
988 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400989 }
990
David Benjamin87c8a642015-02-21 01:54:29 -0500991 // Close the listener now. This is to avoid hangs should the shim try to
992 // open more connections than expected.
993 listener.Close()
994 listener = nil
995
996 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400997 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800998 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200999 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1000 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001001 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001002 case 89:
1003 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001004 case 99:
1005 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001006 }
1007 }
Adam Langley95c29f32014-06-20 12:00:00 -07001008
David Benjamin9bea3492016-03-02 10:59:16 -05001009 // Account for Windows line endings.
1010 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1011 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001012
1013 // Separate the errors from the shim and those from tools like
1014 // AddressSanitizer.
1015 var extraStderr string
1016 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1017 stderr = stderrParts[0]
1018 extraStderr = stderrParts[1]
1019 }
1020
Adam Langley95c29f32014-06-20 12:00:00 -07001021 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001022 expectedError := translateExpectedError(test.expectedError)
1023 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001024
Adam Langleyac61fa32014-06-23 12:03:11 -07001025 localError := "none"
1026 if err != nil {
1027 localError = err.Error()
1028 }
1029 if len(test.expectedLocalError) != 0 {
1030 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1031 }
Adam Langley95c29f32014-06-20 12:00:00 -07001032
1033 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001034 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001035 if childErr != nil {
1036 childError = childErr.Error()
1037 }
1038
1039 var msg string
1040 switch {
1041 case failed && !test.shouldFail:
1042 msg = "unexpected failure"
1043 case !failed && test.shouldFail:
1044 msg = "unexpected success"
1045 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001046 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001047 default:
1048 panic("internal error")
1049 }
1050
David Benjamin9aafb642016-09-20 19:36:53 -04001051 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 -07001052 }
1053
David Benjamind2ba8892016-09-20 19:41:04 -04001054 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001055 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001056 }
1057
David Benjamind2ba8892016-09-20 19:41:04 -04001058 if *useValgrind && isValgrindError {
1059 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1060 }
1061
Adam Langley95c29f32014-06-20 12:00:00 -07001062 return nil
1063}
1064
David Benjaminaa012042016-12-10 13:33:05 -05001065type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001066 name string
1067 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001068 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001069 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001070}
1071
1072var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001073 {"SSL3", VersionSSL30, "-no-ssl3", false},
1074 {"TLS1", VersionTLS10, "-no-tls1", true},
1075 {"TLS11", VersionTLS11, "-no-tls11", false},
1076 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001077 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001078}
1079
David Benjaminaa012042016-12-10 13:33:05 -05001080type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001081 name string
1082 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001083}
1084
1085var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001086 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001087 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001088 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001089 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001090 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001091 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001092 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001093 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1094 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001095 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001096 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1097 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001098 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001099 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1100 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001101 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1102 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001103 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001104 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001105 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001106 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001107 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001108 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001109 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001110 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001111 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001112 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001113 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1114 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001115 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1116 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001117 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001118 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1119 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1120 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001121 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001122}
1123
David Benjamin8b8c0062014-11-23 02:47:52 -05001124func hasComponent(suiteName, component string) bool {
1125 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1126}
1127
David Benjaminf7768e42014-08-31 02:06:47 -04001128func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001129 return hasComponent(suiteName, "GCM") ||
1130 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001131 hasComponent(suiteName, "SHA384") ||
1132 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001133}
1134
Nick Harper1fd39d82016-06-14 18:14:35 -07001135func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001136 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001137}
1138
David Benjamin8b8c0062014-11-23 02:47:52 -05001139func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001140 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001141}
1142
Adam Langleya7997f12015-05-14 17:38:50 -07001143func bigFromHex(hex string) *big.Int {
1144 ret, ok := new(big.Int).SetString(hex, 16)
1145 if !ok {
1146 panic("failed to parse hex number 0x" + hex)
1147 }
1148 return ret
1149}
1150
Adam Langley7c803a62015-06-15 15:35:05 -07001151func addBasicTests() {
1152 basicTests := []testCase{
1153 {
Adam Langley7c803a62015-06-15 15:35:05 -07001154 name: "NoFallbackSCSV",
1155 config: Config{
1156 Bugs: ProtocolBugs{
1157 FailIfNotFallbackSCSV: true,
1158 },
1159 },
1160 shouldFail: true,
1161 expectedLocalError: "no fallback SCSV found",
1162 },
1163 {
1164 name: "SendFallbackSCSV",
1165 config: Config{
1166 Bugs: ProtocolBugs{
1167 FailIfNotFallbackSCSV: true,
1168 },
1169 },
1170 flags: []string{"-fallback-scsv"},
1171 },
1172 {
1173 name: "ClientCertificateTypes",
1174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001175 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001176 ClientAuth: RequestClientCert,
1177 ClientCertificateTypes: []byte{
1178 CertTypeDSSSign,
1179 CertTypeRSASign,
1180 CertTypeECDSASign,
1181 },
1182 },
1183 flags: []string{
1184 "-expect-certificate-types",
1185 base64.StdEncoding.EncodeToString([]byte{
1186 CertTypeDSSSign,
1187 CertTypeRSASign,
1188 CertTypeECDSASign,
1189 }),
1190 },
1191 },
1192 {
Adam Langley7c803a62015-06-15 15:35:05 -07001193 name: "UnauthenticatedECDH",
1194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001195 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1197 Bugs: ProtocolBugs{
1198 UnauthenticatedECDH: true,
1199 },
1200 },
1201 shouldFail: true,
1202 expectedError: ":UNEXPECTED_MESSAGE:",
1203 },
1204 {
1205 name: "SkipCertificateStatus",
1206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001207 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001208 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1209 Bugs: ProtocolBugs{
1210 SkipCertificateStatus: true,
1211 },
1212 },
1213 flags: []string{
1214 "-enable-ocsp-stapling",
1215 },
1216 },
1217 {
1218 name: "SkipServerKeyExchange",
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 SkipServerKeyExchange: true,
1224 },
1225 },
1226 shouldFail: true,
1227 expectedError: ":UNEXPECTED_MESSAGE:",
1228 },
1229 {
Adam Langley7c803a62015-06-15 15:35:05 -07001230 testType: serverTest,
1231 name: "Alert",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 SendSpuriousAlert: alertRecordOverflow,
1235 },
1236 },
1237 shouldFail: true,
1238 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1239 },
1240 {
1241 protocol: dtls,
1242 testType: serverTest,
1243 name: "Alert-DTLS",
1244 config: Config{
1245 Bugs: ProtocolBugs{
1246 SendSpuriousAlert: alertRecordOverflow,
1247 },
1248 },
1249 shouldFail: true,
1250 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1251 },
1252 {
1253 testType: serverTest,
1254 name: "FragmentAlert",
1255 config: Config{
1256 Bugs: ProtocolBugs{
1257 FragmentAlert: true,
1258 SendSpuriousAlert: alertRecordOverflow,
1259 },
1260 },
1261 shouldFail: true,
1262 expectedError: ":BAD_ALERT:",
1263 },
1264 {
1265 protocol: dtls,
1266 testType: serverTest,
1267 name: "FragmentAlert-DTLS",
1268 config: Config{
1269 Bugs: ProtocolBugs{
1270 FragmentAlert: true,
1271 SendSpuriousAlert: alertRecordOverflow,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":BAD_ALERT:",
1276 },
1277 {
1278 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001279 name: "DoubleAlert",
1280 config: Config{
1281 Bugs: ProtocolBugs{
1282 DoubleAlert: true,
1283 SendSpuriousAlert: alertRecordOverflow,
1284 },
1285 },
1286 shouldFail: true,
1287 expectedError: ":BAD_ALERT:",
1288 },
1289 {
1290 protocol: dtls,
1291 testType: serverTest,
1292 name: "DoubleAlert-DTLS",
1293 config: Config{
1294 Bugs: ProtocolBugs{
1295 DoubleAlert: true,
1296 SendSpuriousAlert: alertRecordOverflow,
1297 },
1298 },
1299 shouldFail: true,
1300 expectedError: ":BAD_ALERT:",
1301 },
1302 {
Adam Langley7c803a62015-06-15 15:35:05 -07001303 name: "SkipNewSessionTicket",
1304 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001305 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001306 Bugs: ProtocolBugs{
1307 SkipNewSessionTicket: true,
1308 },
1309 },
1310 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001311 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001312 },
1313 {
1314 testType: serverTest,
1315 name: "FallbackSCSV",
1316 config: Config{
1317 MaxVersion: VersionTLS11,
1318 Bugs: ProtocolBugs{
1319 SendFallbackSCSV: true,
1320 },
1321 },
David Benjamin56cadc32016-12-16 19:54:11 -05001322 shouldFail: true,
1323 expectedError: ":INAPPROPRIATE_FALLBACK:",
1324 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001325 },
1326 {
1327 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001328 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001329 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001330 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001331 Bugs: ProtocolBugs{
1332 SendFallbackSCSV: true,
1333 },
1334 },
1335 },
1336 {
1337 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001338 name: "FallbackSCSV-VersionMatch-TLS12",
1339 config: Config{
1340 MaxVersion: VersionTLS12,
1341 Bugs: ProtocolBugs{
1342 SendFallbackSCSV: true,
1343 },
1344 },
1345 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1346 },
1347 {
1348 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001349 name: "FragmentedClientVersion",
1350 config: Config{
1351 Bugs: ProtocolBugs{
1352 MaxHandshakeRecordLength: 1,
1353 FragmentClientVersion: true,
1354 },
1355 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001356 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001357 },
1358 {
Adam Langley7c803a62015-06-15 15:35:05 -07001359 testType: serverTest,
1360 name: "HttpGET",
1361 sendPrefix: "GET / HTTP/1.0\n",
1362 shouldFail: true,
1363 expectedError: ":HTTP_REQUEST:",
1364 },
1365 {
1366 testType: serverTest,
1367 name: "HttpPOST",
1368 sendPrefix: "POST / HTTP/1.0\n",
1369 shouldFail: true,
1370 expectedError: ":HTTP_REQUEST:",
1371 },
1372 {
1373 testType: serverTest,
1374 name: "HttpHEAD",
1375 sendPrefix: "HEAD / HTTP/1.0\n",
1376 shouldFail: true,
1377 expectedError: ":HTTP_REQUEST:",
1378 },
1379 {
1380 testType: serverTest,
1381 name: "HttpPUT",
1382 sendPrefix: "PUT / HTTP/1.0\n",
1383 shouldFail: true,
1384 expectedError: ":HTTP_REQUEST:",
1385 },
1386 {
1387 testType: serverTest,
1388 name: "HttpCONNECT",
1389 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1390 shouldFail: true,
1391 expectedError: ":HTTPS_PROXY_REQUEST:",
1392 },
1393 {
1394 testType: serverTest,
1395 name: "Garbage",
1396 sendPrefix: "blah",
1397 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001398 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001399 },
1400 {
Adam Langley7c803a62015-06-15 15:35:05 -07001401 name: "RSAEphemeralKey",
1402 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001403 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001404 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1405 Bugs: ProtocolBugs{
1406 RSAEphemeralKey: true,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedError: ":UNEXPECTED_MESSAGE:",
1411 },
1412 {
1413 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001414 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001415 shouldFail: true,
1416 expectedError: ":WRONG_SSL_VERSION:",
1417 },
1418 {
1419 protocol: dtls,
1420 name: "DisableEverything-DTLS",
1421 flags: []string{"-no-tls12", "-no-tls1"},
1422 shouldFail: true,
1423 expectedError: ":WRONG_SSL_VERSION:",
1424 },
1425 {
Adam Langley7c803a62015-06-15 15:35:05 -07001426 protocol: dtls,
1427 testType: serverTest,
1428 name: "MTU",
1429 config: Config{
1430 Bugs: ProtocolBugs{
1431 MaxPacketLength: 256,
1432 },
1433 },
1434 flags: []string{"-mtu", "256"},
1435 },
1436 {
1437 protocol: dtls,
1438 testType: serverTest,
1439 name: "MTUExceeded",
1440 config: Config{
1441 Bugs: ProtocolBugs{
1442 MaxPacketLength: 255,
1443 },
1444 },
1445 flags: []string{"-mtu", "256"},
1446 shouldFail: true,
1447 expectedLocalError: "dtls: exceeded maximum packet length",
1448 },
1449 {
1450 name: "CertMismatchRSA",
1451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001452 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001453 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001454 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001455 Bugs: ProtocolBugs{
1456 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1457 },
1458 },
1459 shouldFail: true,
1460 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1461 },
1462 {
1463 name: "CertMismatchECDSA",
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_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001467 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001468 Bugs: ProtocolBugs{
1469 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1470 },
1471 },
1472 shouldFail: true,
1473 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1474 },
1475 {
1476 name: "EmptyCertificateList",
1477 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001478 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001479 Bugs: ProtocolBugs{
1480 EmptyCertificateList: true,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":DECODE_ERROR:",
1485 },
1486 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001487 name: "EmptyCertificateList-TLS13",
1488 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001489 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001490 Bugs: ProtocolBugs{
1491 EmptyCertificateList: true,
1492 },
1493 },
1494 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001495 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001496 },
1497 {
Adam Langley7c803a62015-06-15 15:35:05 -07001498 name: "TLSFatalBadPackets",
1499 damageFirstWrite: true,
1500 shouldFail: true,
1501 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1502 },
1503 {
1504 protocol: dtls,
1505 name: "DTLSIgnoreBadPackets",
1506 damageFirstWrite: true,
1507 },
1508 {
1509 protocol: dtls,
1510 name: "DTLSIgnoreBadPackets-Async",
1511 damageFirstWrite: true,
1512 flags: []string{"-async"},
1513 },
1514 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001515 name: "AppDataBeforeHandshake",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":UNEXPECTED_RECORD:",
1523 },
1524 {
1525 name: "AppDataBeforeHandshake-Empty",
1526 config: Config{
1527 Bugs: ProtocolBugs{
1528 AppDataBeforeHandshake: []byte{},
1529 },
1530 },
1531 shouldFail: true,
1532 expectedError: ":UNEXPECTED_RECORD:",
1533 },
1534 {
1535 protocol: dtls,
1536 name: "AppDataBeforeHandshake-DTLS",
1537 config: Config{
1538 Bugs: ProtocolBugs{
1539 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1540 },
1541 },
1542 shouldFail: true,
1543 expectedError: ":UNEXPECTED_RECORD:",
1544 },
1545 {
1546 protocol: dtls,
1547 name: "AppDataBeforeHandshake-DTLS-Empty",
1548 config: Config{
1549 Bugs: ProtocolBugs{
1550 AppDataBeforeHandshake: []byte{},
1551 },
1552 },
1553 shouldFail: true,
1554 expectedError: ":UNEXPECTED_RECORD:",
1555 },
1556 {
Adam Langley7c803a62015-06-15 15:35:05 -07001557 name: "AppDataAfterChangeCipherSpec",
1558 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001559 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001560 Bugs: ProtocolBugs{
1561 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1562 },
1563 },
1564 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001565 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001566 },
1567 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001568 name: "AppDataAfterChangeCipherSpec-Empty",
1569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001570 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 Bugs: ProtocolBugs{
1572 AppDataAfterChangeCipherSpec: []byte{},
1573 },
1574 },
1575 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001576 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001577 },
1578 {
Adam Langley7c803a62015-06-15 15:35:05 -07001579 protocol: dtls,
1580 name: "AppDataAfterChangeCipherSpec-DTLS",
1581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001582 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001583 Bugs: ProtocolBugs{
1584 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1585 },
1586 },
1587 // BoringSSL's DTLS implementation will drop the out-of-order
1588 // application data.
1589 },
1590 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001591 protocol: dtls,
1592 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001594 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001595 Bugs: ProtocolBugs{
1596 AppDataAfterChangeCipherSpec: []byte{},
1597 },
1598 },
1599 // BoringSSL's DTLS implementation will drop the out-of-order
1600 // application data.
1601 },
1602 {
Adam Langley7c803a62015-06-15 15:35:05 -07001603 name: "AlertAfterChangeCipherSpec",
1604 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001605 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001606 Bugs: ProtocolBugs{
1607 AlertAfterChangeCipherSpec: alertRecordOverflow,
1608 },
1609 },
1610 shouldFail: true,
1611 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1612 },
1613 {
1614 protocol: dtls,
1615 name: "AlertAfterChangeCipherSpec-DTLS",
1616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001617 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001618 Bugs: ProtocolBugs{
1619 AlertAfterChangeCipherSpec: alertRecordOverflow,
1620 },
1621 },
1622 shouldFail: true,
1623 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1624 },
1625 {
1626 protocol: dtls,
1627 name: "ReorderHandshakeFragments-Small-DTLS",
1628 config: Config{
1629 Bugs: ProtocolBugs{
1630 ReorderHandshakeFragments: true,
1631 // Small enough that every handshake message is
1632 // fragmented.
1633 MaxHandshakeRecordLength: 2,
1634 },
1635 },
1636 },
1637 {
1638 protocol: dtls,
1639 name: "ReorderHandshakeFragments-Large-DTLS",
1640 config: Config{
1641 Bugs: ProtocolBugs{
1642 ReorderHandshakeFragments: true,
1643 // Large enough that no handshake message is
1644 // fragmented.
1645 MaxHandshakeRecordLength: 2048,
1646 },
1647 },
1648 },
1649 {
1650 protocol: dtls,
1651 name: "MixCompleteMessageWithFragments-DTLS",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 ReorderHandshakeFragments: true,
1655 MixCompleteMessageWithFragments: true,
1656 MaxHandshakeRecordLength: 2,
1657 },
1658 },
1659 },
1660 {
1661 name: "SendInvalidRecordType",
1662 config: Config{
1663 Bugs: ProtocolBugs{
1664 SendInvalidRecordType: true,
1665 },
1666 },
1667 shouldFail: true,
1668 expectedError: ":UNEXPECTED_RECORD:",
1669 },
1670 {
1671 protocol: dtls,
1672 name: "SendInvalidRecordType-DTLS",
1673 config: Config{
1674 Bugs: ProtocolBugs{
1675 SendInvalidRecordType: true,
1676 },
1677 },
1678 shouldFail: true,
1679 expectedError: ":UNEXPECTED_RECORD:",
1680 },
1681 {
1682 name: "FalseStart-SkipServerSecondLeg",
1683 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001684 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001685 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1686 NextProtos: []string{"foo"},
1687 Bugs: ProtocolBugs{
1688 SkipNewSessionTicket: true,
1689 SkipChangeCipherSpec: true,
1690 SkipFinished: true,
1691 ExpectFalseStart: true,
1692 },
1693 },
1694 flags: []string{
1695 "-false-start",
1696 "-handshake-never-done",
1697 "-advertise-alpn", "\x03foo",
1698 },
1699 shimWritesFirst: true,
1700 shouldFail: true,
1701 expectedError: ":UNEXPECTED_RECORD:",
1702 },
1703 {
1704 name: "FalseStart-SkipServerSecondLeg-Implicit",
1705 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001706 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001707 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1708 NextProtos: []string{"foo"},
1709 Bugs: ProtocolBugs{
1710 SkipNewSessionTicket: true,
1711 SkipChangeCipherSpec: true,
1712 SkipFinished: true,
1713 },
1714 },
1715 flags: []string{
1716 "-implicit-handshake",
1717 "-false-start",
1718 "-handshake-never-done",
1719 "-advertise-alpn", "\x03foo",
1720 },
1721 shouldFail: true,
1722 expectedError: ":UNEXPECTED_RECORD:",
1723 },
1724 {
1725 testType: serverTest,
1726 name: "FailEarlyCallback",
1727 flags: []string{"-fail-early-callback"},
1728 shouldFail: true,
1729 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001730 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001731 },
1732 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001733 name: "FailCertCallback-Client-TLS12",
1734 config: Config{
1735 MaxVersion: VersionTLS12,
1736 ClientAuth: RequestClientCert,
1737 },
1738 flags: []string{"-fail-cert-callback"},
1739 shouldFail: true,
1740 expectedError: ":CERT_CB_ERROR:",
1741 expectedLocalError: "remote error: internal error",
1742 },
1743 {
1744 testType: serverTest,
1745 name: "FailCertCallback-Server-TLS12",
1746 config: Config{
1747 MaxVersion: VersionTLS12,
1748 },
1749 flags: []string{"-fail-cert-callback"},
1750 shouldFail: true,
1751 expectedError: ":CERT_CB_ERROR:",
1752 expectedLocalError: "remote error: internal error",
1753 },
1754 {
1755 name: "FailCertCallback-Client-TLS13",
1756 config: Config{
1757 MaxVersion: VersionTLS13,
1758 ClientAuth: RequestClientCert,
1759 },
1760 flags: []string{"-fail-cert-callback"},
1761 shouldFail: true,
1762 expectedError: ":CERT_CB_ERROR:",
1763 expectedLocalError: "remote error: internal error",
1764 },
1765 {
1766 testType: serverTest,
1767 name: "FailCertCallback-Server-TLS13",
1768 config: Config{
1769 MaxVersion: VersionTLS13,
1770 },
1771 flags: []string{"-fail-cert-callback"},
1772 shouldFail: true,
1773 expectedError: ":CERT_CB_ERROR:",
1774 expectedLocalError: "remote error: internal error",
1775 },
1776 {
Adam Langley7c803a62015-06-15 15:35:05 -07001777 protocol: dtls,
1778 name: "FragmentMessageTypeMismatch-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 MaxHandshakeRecordLength: 2,
1782 FragmentMessageTypeMismatch: true,
1783 },
1784 },
1785 shouldFail: true,
1786 expectedError: ":FRAGMENT_MISMATCH:",
1787 },
1788 {
1789 protocol: dtls,
1790 name: "FragmentMessageLengthMismatch-DTLS",
1791 config: Config{
1792 Bugs: ProtocolBugs{
1793 MaxHandshakeRecordLength: 2,
1794 FragmentMessageLengthMismatch: true,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":FRAGMENT_MISMATCH:",
1799 },
1800 {
1801 protocol: dtls,
1802 name: "SplitFragments-Header-DTLS",
1803 config: Config{
1804 Bugs: ProtocolBugs{
1805 SplitFragments: 2,
1806 },
1807 },
1808 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001809 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 },
1811 {
1812 protocol: dtls,
1813 name: "SplitFragments-Boundary-DTLS",
1814 config: Config{
1815 Bugs: ProtocolBugs{
1816 SplitFragments: dtlsRecordHeaderLen,
1817 },
1818 },
1819 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001820 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001821 },
1822 {
1823 protocol: dtls,
1824 name: "SplitFragments-Body-DTLS",
1825 config: Config{
1826 Bugs: ProtocolBugs{
1827 SplitFragments: dtlsRecordHeaderLen + 1,
1828 },
1829 },
1830 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001831 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001832 },
1833 {
1834 protocol: dtls,
1835 name: "SendEmptyFragments-DTLS",
1836 config: Config{
1837 Bugs: ProtocolBugs{
1838 SendEmptyFragments: true,
1839 },
1840 },
1841 },
1842 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001843 name: "BadFinished-Client",
1844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001845 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001846 Bugs: ProtocolBugs{
1847 BadFinished: true,
1848 },
1849 },
1850 shouldFail: true,
1851 expectedError: ":DIGEST_CHECK_FAILED:",
1852 },
1853 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001854 name: "BadFinished-Client-TLS13",
1855 config: Config{
1856 MaxVersion: VersionTLS13,
1857 Bugs: ProtocolBugs{
1858 BadFinished: true,
1859 },
1860 },
1861 shouldFail: true,
1862 expectedError: ":DIGEST_CHECK_FAILED:",
1863 },
1864 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001865 testType: serverTest,
1866 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001868 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001869 Bugs: ProtocolBugs{
1870 BadFinished: true,
1871 },
1872 },
1873 shouldFail: true,
1874 expectedError: ":DIGEST_CHECK_FAILED:",
1875 },
1876 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001877 testType: serverTest,
1878 name: "BadFinished-Server-TLS13",
1879 config: Config{
1880 MaxVersion: VersionTLS13,
1881 Bugs: ProtocolBugs{
1882 BadFinished: true,
1883 },
1884 },
1885 shouldFail: true,
1886 expectedError: ":DIGEST_CHECK_FAILED:",
1887 },
1888 {
Adam Langley7c803a62015-06-15 15:35:05 -07001889 name: "FalseStart-BadFinished",
1890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001891 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1893 NextProtos: []string{"foo"},
1894 Bugs: ProtocolBugs{
1895 BadFinished: true,
1896 ExpectFalseStart: true,
1897 },
1898 },
1899 flags: []string{
1900 "-false-start",
1901 "-handshake-never-done",
1902 "-advertise-alpn", "\x03foo",
1903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
1906 expectedError: ":DIGEST_CHECK_FAILED:",
1907 },
1908 {
1909 name: "NoFalseStart-NoALPN",
1910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001911 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1913 Bugs: ProtocolBugs{
1914 ExpectFalseStart: true,
1915 AlertBeforeFalseStartTest: alertAccessDenied,
1916 },
1917 },
1918 flags: []string{
1919 "-false-start",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
1927 name: "NoFalseStart-NoAEAD",
1928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001929 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1931 NextProtos: []string{"foo"},
1932 Bugs: ProtocolBugs{
1933 ExpectFalseStart: true,
1934 AlertBeforeFalseStartTest: alertAccessDenied,
1935 },
1936 },
1937 flags: []string{
1938 "-false-start",
1939 "-advertise-alpn", "\x03foo",
1940 },
1941 shimWritesFirst: true,
1942 shouldFail: true,
1943 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1944 expectedLocalError: "tls: peer did not false start: EOF",
1945 },
1946 {
1947 name: "NoFalseStart-RSA",
1948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001949 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001950 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1951 NextProtos: []string{"foo"},
1952 Bugs: ProtocolBugs{
1953 ExpectFalseStart: true,
1954 AlertBeforeFalseStartTest: alertAccessDenied,
1955 },
1956 },
1957 flags: []string{
1958 "-false-start",
1959 "-advertise-alpn", "\x03foo",
1960 },
1961 shimWritesFirst: true,
1962 shouldFail: true,
1963 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1964 expectedLocalError: "tls: peer did not false start: EOF",
1965 },
1966 {
1967 name: "NoFalseStart-DHE_RSA",
1968 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001969 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001970 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1971 NextProtos: []string{"foo"},
1972 Bugs: ProtocolBugs{
1973 ExpectFalseStart: true,
1974 AlertBeforeFalseStartTest: alertAccessDenied,
1975 },
1976 },
1977 flags: []string{
1978 "-false-start",
1979 "-advertise-alpn", "\x03foo",
1980 },
1981 shimWritesFirst: true,
1982 shouldFail: true,
1983 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1984 expectedLocalError: "tls: peer did not false start: EOF",
1985 },
1986 {
Adam Langley7c803a62015-06-15 15:35:05 -07001987 protocol: dtls,
1988 name: "SendSplitAlert-Sync",
1989 config: Config{
1990 Bugs: ProtocolBugs{
1991 SendSplitAlert: true,
1992 },
1993 },
1994 },
1995 {
1996 protocol: dtls,
1997 name: "SendSplitAlert-Async",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendSplitAlert: true,
2001 },
2002 },
2003 flags: []string{"-async"},
2004 },
2005 {
2006 protocol: dtls,
2007 name: "PackDTLSHandshake",
2008 config: Config{
2009 Bugs: ProtocolBugs{
2010 MaxHandshakeRecordLength: 2,
2011 PackHandshakeFragments: 20,
2012 PackHandshakeRecords: 200,
2013 },
2014 },
2015 },
2016 {
Adam Langley7c803a62015-06-15 15:35:05 -07002017 name: "SendEmptyRecords-Pass",
2018 sendEmptyRecords: 32,
2019 },
2020 {
2021 name: "SendEmptyRecords",
2022 sendEmptyRecords: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2025 },
2026 {
2027 name: "SendEmptyRecords-Async",
2028 sendEmptyRecords: 33,
2029 flags: []string{"-async"},
2030 shouldFail: true,
2031 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2032 },
2033 {
David Benjamine8e84b92016-08-03 15:39:47 -04002034 name: "SendWarningAlerts-Pass",
2035 config: Config{
2036 MaxVersion: VersionTLS12,
2037 },
Adam Langley7c803a62015-06-15 15:35:05 -07002038 sendWarningAlerts: 4,
2039 },
2040 {
David Benjamine8e84b92016-08-03 15:39:47 -04002041 protocol: dtls,
2042 name: "SendWarningAlerts-DTLS-Pass",
2043 config: Config{
2044 MaxVersion: VersionTLS12,
2045 },
Adam Langley7c803a62015-06-15 15:35:05 -07002046 sendWarningAlerts: 4,
2047 },
2048 {
David Benjamine8e84b92016-08-03 15:39:47 -04002049 name: "SendWarningAlerts-TLS13",
2050 config: Config{
2051 MaxVersion: VersionTLS13,
2052 },
2053 sendWarningAlerts: 4,
2054 shouldFail: true,
2055 expectedError: ":BAD_ALERT:",
2056 expectedLocalError: "remote error: error decoding message",
2057 },
2058 {
2059 name: "SendWarningAlerts",
2060 config: Config{
2061 MaxVersion: VersionTLS12,
2062 },
Adam Langley7c803a62015-06-15 15:35:05 -07002063 sendWarningAlerts: 5,
2064 shouldFail: true,
2065 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2066 },
2067 {
David Benjamine8e84b92016-08-03 15:39:47 -04002068 name: "SendWarningAlerts-Async",
2069 config: Config{
2070 MaxVersion: VersionTLS12,
2071 },
Adam Langley7c803a62015-06-15 15:35:05 -07002072 sendWarningAlerts: 5,
2073 flags: []string{"-async"},
2074 shouldFail: true,
2075 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2076 },
David Benjaminba4594a2015-06-18 18:36:15 -04002077 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002078 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002079 config: Config{
2080 MaxVersion: VersionTLS13,
2081 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002082 sendKeyUpdates: 33,
2083 keyUpdateRequest: keyUpdateNotRequested,
2084 shouldFail: true,
2085 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002086 },
2087 {
David Benjaminba4594a2015-06-18 18:36:15 -04002088 name: "EmptySessionID",
2089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002090 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002091 SessionTicketsDisabled: true,
2092 },
2093 noSessionCache: true,
2094 flags: []string{"-expect-no-session"},
2095 },
David Benjamin30789da2015-08-29 22:56:45 -04002096 {
2097 name: "Unclean-Shutdown",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 NoCloseNotify: true,
2101 ExpectCloseNotify: true,
2102 },
2103 },
2104 shimShutsDown: true,
2105 flags: []string{"-check-close-notify"},
2106 shouldFail: true,
2107 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2108 },
2109 {
2110 name: "Unclean-Shutdown-Ignored",
2111 config: Config{
2112 Bugs: ProtocolBugs{
2113 NoCloseNotify: true,
2114 },
2115 },
2116 shimShutsDown: true,
2117 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002118 {
David Benjaminfa214e42016-05-10 17:03:10 -04002119 name: "Unclean-Shutdown-Alert",
2120 config: Config{
2121 Bugs: ProtocolBugs{
2122 SendAlertOnShutdown: alertDecompressionFailure,
2123 ExpectCloseNotify: true,
2124 },
2125 },
2126 shimShutsDown: true,
2127 flags: []string{"-check-close-notify"},
2128 shouldFail: true,
2129 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2130 },
2131 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002132 name: "LargePlaintext",
2133 config: Config{
2134 Bugs: ProtocolBugs{
2135 SendLargeRecords: true,
2136 },
2137 },
2138 messageLen: maxPlaintext + 1,
2139 shouldFail: true,
2140 expectedError: ":DATA_LENGTH_TOO_LONG:",
2141 },
2142 {
2143 protocol: dtls,
2144 name: "LargePlaintext-DTLS",
2145 config: Config{
2146 Bugs: ProtocolBugs{
2147 SendLargeRecords: true,
2148 },
2149 },
2150 messageLen: maxPlaintext + 1,
2151 shouldFail: true,
2152 expectedError: ":DATA_LENGTH_TOO_LONG:",
2153 },
2154 {
2155 name: "LargeCiphertext",
2156 config: Config{
2157 Bugs: ProtocolBugs{
2158 SendLargeRecords: true,
2159 },
2160 },
2161 messageLen: maxPlaintext * 2,
2162 shouldFail: true,
2163 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2164 },
2165 {
2166 protocol: dtls,
2167 name: "LargeCiphertext-DTLS",
2168 config: Config{
2169 Bugs: ProtocolBugs{
2170 SendLargeRecords: true,
2171 },
2172 },
2173 messageLen: maxPlaintext * 2,
2174 // Unlike the other four cases, DTLS drops records which
2175 // are invalid before authentication, so the connection
2176 // does not fail.
2177 expectMessageDropped: true,
2178 },
David Benjamindd6fed92015-10-23 17:41:12 -04002179 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002180 name: "BadHelloRequest-1",
2181 renegotiate: 1,
2182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002183 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002184 Bugs: ProtocolBugs{
2185 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2186 },
2187 },
2188 flags: []string{
2189 "-renegotiate-freely",
2190 "-expect-total-renegotiations", "1",
2191 },
2192 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002193 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002194 },
2195 {
2196 name: "BadHelloRequest-2",
2197 renegotiate: 1,
2198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002199 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002200 Bugs: ProtocolBugs{
2201 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2202 },
2203 },
2204 flags: []string{
2205 "-renegotiate-freely",
2206 "-expect-total-renegotiations", "1",
2207 },
2208 shouldFail: true,
2209 expectedError: ":BAD_HELLO_REQUEST:",
2210 },
David Benjaminef1b0092015-11-21 14:05:44 -05002211 {
2212 testType: serverTest,
2213 name: "SupportTicketsWithSessionID",
2214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002215 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002216 SessionTicketsDisabled: true,
2217 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002218 resumeConfig: &Config{
2219 MaxVersion: VersionTLS12,
2220 },
David Benjaminef1b0092015-11-21 14:05:44 -05002221 resumeSession: true,
2222 },
David Benjamin02edcd02016-07-27 17:40:37 -04002223 {
2224 protocol: dtls,
2225 name: "DTLS-SendExtraFinished",
2226 config: Config{
2227 Bugs: ProtocolBugs{
2228 SendExtraFinished: true,
2229 },
2230 },
2231 shouldFail: true,
2232 expectedError: ":UNEXPECTED_RECORD:",
2233 },
2234 {
2235 protocol: dtls,
2236 name: "DTLS-SendExtraFinished-Reordered",
2237 config: Config{
2238 Bugs: ProtocolBugs{
2239 MaxHandshakeRecordLength: 2,
2240 ReorderHandshakeFragments: true,
2241 SendExtraFinished: true,
2242 },
2243 },
2244 shouldFail: true,
2245 expectedError: ":UNEXPECTED_RECORD:",
2246 },
David Benjamine97fb482016-07-29 09:23:07 -04002247 {
2248 testType: serverTest,
2249 name: "V2ClientHello-EmptyRecordPrefix",
2250 config: Config{
2251 // Choose a cipher suite that does not involve
2252 // elliptic curves, so no extensions are
2253 // involved.
2254 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002255 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002256 Bugs: ProtocolBugs{
2257 SendV2ClientHello: true,
2258 },
2259 },
2260 sendPrefix: string([]byte{
2261 byte(recordTypeHandshake),
2262 3, 1, // version
2263 0, 0, // length
2264 }),
2265 // A no-op empty record may not be sent before V2ClientHello.
2266 shouldFail: true,
2267 expectedError: ":WRONG_VERSION_NUMBER:",
2268 },
2269 {
2270 testType: serverTest,
2271 name: "V2ClientHello-WarningAlertPrefix",
2272 config: Config{
2273 // Choose a cipher suite that does not involve
2274 // elliptic curves, so no extensions are
2275 // involved.
2276 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002277 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002278 Bugs: ProtocolBugs{
2279 SendV2ClientHello: true,
2280 },
2281 },
2282 sendPrefix: string([]byte{
2283 byte(recordTypeAlert),
2284 3, 1, // version
2285 0, 2, // length
2286 alertLevelWarning, byte(alertDecompressionFailure),
2287 }),
2288 // A no-op warning alert may not be sent before V2ClientHello.
2289 shouldFail: true,
2290 expectedError: ":WRONG_VERSION_NUMBER:",
2291 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002292 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002293 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002294 config: Config{
2295 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002296 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002297 sendKeyUpdates: 1,
2298 keyUpdateRequest: keyUpdateNotRequested,
2299 },
2300 {
2301 name: "KeyUpdate-InvalidRequestMode",
2302 config: Config{
2303 MaxVersion: VersionTLS13,
2304 },
2305 sendKeyUpdates: 1,
2306 keyUpdateRequest: 42,
2307 shouldFail: true,
2308 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002309 },
David Benjaminabe94e32016-09-04 14:18:58 -04002310 {
2311 name: "SendSNIWarningAlert",
2312 config: Config{
2313 MaxVersion: VersionTLS12,
2314 Bugs: ProtocolBugs{
2315 SendSNIWarningAlert: true,
2316 },
2317 },
2318 },
David Benjaminc241d792016-09-09 10:34:20 -04002319 {
2320 testType: serverTest,
2321 name: "ExtraCompressionMethods-TLS12",
2322 config: Config{
2323 MaxVersion: VersionTLS12,
2324 Bugs: ProtocolBugs{
2325 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2326 },
2327 },
2328 },
2329 {
2330 testType: serverTest,
2331 name: "ExtraCompressionMethods-TLS13",
2332 config: Config{
2333 MaxVersion: VersionTLS13,
2334 Bugs: ProtocolBugs{
2335 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2336 },
2337 },
2338 shouldFail: true,
2339 expectedError: ":INVALID_COMPRESSION_LIST:",
2340 expectedLocalError: "remote error: illegal parameter",
2341 },
2342 {
2343 testType: serverTest,
2344 name: "NoNullCompression-TLS12",
2345 config: Config{
2346 MaxVersion: VersionTLS12,
2347 Bugs: ProtocolBugs{
2348 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2349 },
2350 },
2351 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002352 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002353 expectedLocalError: "remote error: illegal parameter",
2354 },
2355 {
2356 testType: serverTest,
2357 name: "NoNullCompression-TLS13",
2358 config: Config{
2359 MaxVersion: VersionTLS13,
2360 Bugs: ProtocolBugs{
2361 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2362 },
2363 },
2364 shouldFail: true,
2365 expectedError: ":INVALID_COMPRESSION_LIST:",
2366 expectedLocalError: "remote error: illegal parameter",
2367 },
David Benjamin65ac9972016-09-02 21:35:25 -04002368 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002369 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002370 config: Config{
2371 MaxVersion: VersionTLS12,
2372 Bugs: ProtocolBugs{
2373 ExpectGREASE: true,
2374 },
2375 },
2376 flags: []string{"-enable-grease"},
2377 },
2378 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002379 name: "GREASE-Client-TLS13",
2380 config: Config{
2381 MaxVersion: VersionTLS13,
2382 Bugs: ProtocolBugs{
2383 ExpectGREASE: true,
2384 },
2385 },
2386 flags: []string{"-enable-grease"},
2387 },
2388 {
2389 testType: serverTest,
2390 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002391 config: Config{
2392 MaxVersion: VersionTLS13,
2393 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002394 // TLS 1.3 servers are expected to
2395 // always enable GREASE. TLS 1.3 is new,
2396 // so there is no existing ecosystem to
2397 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002398 ExpectGREASE: true,
2399 },
2400 },
David Benjamin65ac9972016-09-02 21:35:25 -04002401 },
David Benjamine3fbb362017-01-06 16:19:28 -05002402 {
2403 // Test the server so there is a large certificate as
2404 // well as application data.
2405 testType: serverTest,
2406 name: "MaxSendFragment",
2407 config: Config{
2408 Bugs: ProtocolBugs{
2409 MaxReceivePlaintext: 512,
2410 },
2411 },
2412 messageLen: 1024,
2413 flags: []string{
2414 "-max-send-fragment", "512",
2415 "-read-size", "1024",
2416 },
2417 },
2418 {
2419 // Test the server so there is a large certificate as
2420 // well as application data.
2421 testType: serverTest,
2422 name: "MaxSendFragment-TooLarge",
2423 config: Config{
2424 Bugs: ProtocolBugs{
2425 // Ensure that some of the records are
2426 // 512.
2427 MaxReceivePlaintext: 511,
2428 },
2429 },
2430 messageLen: 1024,
2431 flags: []string{
2432 "-max-send-fragment", "512",
2433 "-read-size", "1024",
2434 },
2435 shouldFail: true,
2436 expectedLocalError: "local error: record overflow",
2437 },
Adam Langley7c803a62015-06-15 15:35:05 -07002438 }
Adam Langley7c803a62015-06-15 15:35:05 -07002439 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002440
2441 // Test that very large messages can be received.
2442 cert := rsaCertificate
2443 for i := 0; i < 50; i++ {
2444 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2445 }
2446 testCases = append(testCases, testCase{
2447 name: "LargeMessage",
2448 config: Config{
2449 Certificates: []Certificate{cert},
2450 },
2451 })
2452 testCases = append(testCases, testCase{
2453 protocol: dtls,
2454 name: "LargeMessage-DTLS",
2455 config: Config{
2456 Certificates: []Certificate{cert},
2457 },
2458 })
2459
2460 // They are rejected if the maximum certificate chain length is capped.
2461 testCases = append(testCases, testCase{
2462 name: "LargeMessage-Reject",
2463 config: Config{
2464 Certificates: []Certificate{cert},
2465 },
2466 flags: []string{"-max-cert-list", "16384"},
2467 shouldFail: true,
2468 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2469 })
2470 testCases = append(testCases, testCase{
2471 protocol: dtls,
2472 name: "LargeMessage-Reject-DTLS",
2473 config: Config{
2474 Certificates: []Certificate{cert},
2475 },
2476 flags: []string{"-max-cert-list", "16384"},
2477 shouldFail: true,
2478 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2479 })
Adam Langley7c803a62015-06-15 15:35:05 -07002480}
2481
David Benjaminaa012042016-12-10 13:33:05 -05002482func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2483 const psk = "12345"
2484 const pskIdentity = "luggage combo"
2485
2486 var prefix string
2487 if protocol == dtls {
2488 if !ver.hasDTLS {
2489 return
2490 }
2491 prefix = "D"
2492 }
2493
2494 var cert Certificate
2495 var certFile string
2496 var keyFile string
2497 if hasComponent(suite.name, "ECDSA") {
2498 cert = ecdsaP256Certificate
2499 certFile = ecdsaP256CertificateFile
2500 keyFile = ecdsaP256KeyFile
2501 } else {
2502 cert = rsaCertificate
2503 certFile = rsaCertificateFile
2504 keyFile = rsaKeyFile
2505 }
2506
2507 var flags []string
2508 if hasComponent(suite.name, "PSK") {
2509 flags = append(flags,
2510 "-psk", psk,
2511 "-psk-identity", pskIdentity)
2512 }
2513 if hasComponent(suite.name, "NULL") {
2514 // NULL ciphers must be explicitly enabled.
2515 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2516 }
David Benjaminaa012042016-12-10 13:33:05 -05002517
2518 var shouldServerFail, shouldClientFail bool
2519 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2520 // BoringSSL clients accept ECDHE on SSLv3, but
2521 // a BoringSSL server will never select it
2522 // because the extension is missing.
2523 shouldServerFail = true
2524 }
2525 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2526 shouldClientFail = true
2527 shouldServerFail = true
2528 }
2529 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2530 shouldClientFail = true
2531 shouldServerFail = true
2532 }
2533 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2534 shouldClientFail = true
2535 shouldServerFail = true
2536 }
2537 if !isDTLSCipher(suite.name) && protocol == dtls {
2538 shouldClientFail = true
2539 shouldServerFail = true
2540 }
2541
2542 var sendCipherSuite uint16
2543 var expectedServerError, expectedClientError string
2544 serverCipherSuites := []uint16{suite.id}
2545 if shouldServerFail {
2546 expectedServerError = ":NO_SHARED_CIPHER:"
2547 }
2548 if shouldClientFail {
2549 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2550 // Configure the server to select ciphers as normal but
2551 // select an incompatible cipher in ServerHello.
2552 serverCipherSuites = nil
2553 sendCipherSuite = suite.id
2554 }
2555
David Benjamincdb6fe92017-02-07 16:06:48 -05002556 // For cipher suites and versions where exporters are defined, verify
2557 // that they interoperate.
2558 var exportKeyingMaterial int
2559 if ver.version > VersionSSL30 {
2560 exportKeyingMaterial = 1024
2561 }
2562
David Benjaminaa012042016-12-10 13:33:05 -05002563 testCases = append(testCases, testCase{
2564 testType: serverTest,
2565 protocol: protocol,
2566 name: prefix + ver.name + "-" + suite.name + "-server",
2567 config: Config{
2568 MinVersion: ver.version,
2569 MaxVersion: ver.version,
2570 CipherSuites: []uint16{suite.id},
2571 Certificates: []Certificate{cert},
2572 PreSharedKey: []byte(psk),
2573 PreSharedKeyIdentity: pskIdentity,
2574 Bugs: ProtocolBugs{
2575 AdvertiseAllConfiguredCiphers: true,
2576 },
2577 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002578 certFile: certFile,
2579 keyFile: keyFile,
2580 flags: flags,
2581 resumeSession: true,
2582 shouldFail: shouldServerFail,
2583 expectedError: expectedServerError,
2584 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002585 })
2586
2587 testCases = append(testCases, testCase{
2588 testType: clientTest,
2589 protocol: protocol,
2590 name: prefix + ver.name + "-" + suite.name + "-client",
2591 config: Config{
2592 MinVersion: ver.version,
2593 MaxVersion: ver.version,
2594 CipherSuites: serverCipherSuites,
2595 Certificates: []Certificate{cert},
2596 PreSharedKey: []byte(psk),
2597 PreSharedKeyIdentity: pskIdentity,
2598 Bugs: ProtocolBugs{
2599 IgnorePeerCipherPreferences: shouldClientFail,
2600 SendCipherSuite: sendCipherSuite,
2601 },
2602 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002603 flags: flags,
2604 resumeSession: true,
2605 shouldFail: shouldClientFail,
2606 expectedError: expectedClientError,
2607 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002608 })
2609
David Benjamin6f600d62016-12-21 16:06:54 -05002610 if shouldClientFail {
2611 return
2612 }
2613
2614 // Ensure the maximum record size is accepted.
2615 testCases = append(testCases, testCase{
2616 protocol: protocol,
2617 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2618 config: Config{
2619 MinVersion: ver.version,
2620 MaxVersion: ver.version,
2621 CipherSuites: []uint16{suite.id},
2622 Certificates: []Certificate{cert},
2623 PreSharedKey: []byte(psk),
2624 PreSharedKeyIdentity: pskIdentity,
2625 },
2626 flags: flags,
2627 messageLen: maxPlaintext,
2628 })
2629
2630 // Test bad records for all ciphers. Bad records are fatal in TLS
2631 // and ignored in DTLS.
2632 var shouldFail bool
2633 var expectedError string
2634 if protocol == tls {
2635 shouldFail = true
2636 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2637 }
2638
2639 testCases = append(testCases, testCase{
2640 protocol: protocol,
2641 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2642 config: Config{
2643 MinVersion: ver.version,
2644 MaxVersion: ver.version,
2645 CipherSuites: []uint16{suite.id},
2646 Certificates: []Certificate{cert},
2647 PreSharedKey: []byte(psk),
2648 PreSharedKeyIdentity: pskIdentity,
2649 },
2650 flags: flags,
2651 damageFirstWrite: true,
2652 messageLen: maxPlaintext,
2653 shouldFail: shouldFail,
2654 expectedError: expectedError,
2655 })
2656
2657 if ver.version >= VersionTLS13 {
David Benjaminaa012042016-12-10 13:33:05 -05002658 testCases = append(testCases, testCase{
2659 protocol: protocol,
David Benjamin6f600d62016-12-21 16:06:54 -05002660 name: prefix + ver.name + "-" + suite.name + "-ShortHeader",
David Benjaminaa012042016-12-10 13:33:05 -05002661 config: Config{
2662 MinVersion: ver.version,
2663 MaxVersion: ver.version,
2664 CipherSuites: []uint16{suite.id},
2665 Certificates: []Certificate{cert},
2666 PreSharedKey: []byte(psk),
2667 PreSharedKeyIdentity: pskIdentity,
David Benjamin6f600d62016-12-21 16:06:54 -05002668 Bugs: ProtocolBugs{
2669 EnableShortHeader: true,
2670 },
David Benjaminaa012042016-12-10 13:33:05 -05002671 },
David Benjamin6f600d62016-12-21 16:06:54 -05002672 flags: append([]string{"-enable-short-header"}, flags...),
2673 resumeSession: true,
2674 expectShortHeader: true,
David Benjaminaa012042016-12-10 13:33:05 -05002675 })
2676 }
2677}
2678
Adam Langley95c29f32014-06-20 12:00:00 -07002679func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002680 const bogusCipher = 0xfe00
2681
Adam Langley95c29f32014-06-20 12:00:00 -07002682 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002683 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002684 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002685 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002686 }
David Benjamin2c99d282015-09-01 10:23:00 -04002687 }
Adam Langley95c29f32014-06-20 12:00:00 -07002688 }
Adam Langleya7997f12015-05-14 17:38:50 -07002689
2690 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002691 name: "NoSharedCipher",
2692 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002693 MaxVersion: VersionTLS12,
2694 CipherSuites: []uint16{},
2695 },
2696 shouldFail: true,
2697 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2698 })
2699
2700 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002701 name: "NoSharedCipher-TLS13",
2702 config: Config{
2703 MaxVersion: VersionTLS13,
2704 CipherSuites: []uint16{},
2705 },
2706 shouldFail: true,
2707 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2708 })
2709
2710 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002711 name: "UnsupportedCipherSuite",
2712 config: Config{
2713 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002714 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002715 Bugs: ProtocolBugs{
2716 IgnorePeerCipherPreferences: true,
2717 },
2718 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002719 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002720 shouldFail: true,
2721 expectedError: ":WRONG_CIPHER_RETURNED:",
2722 })
2723
2724 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002725 name: "ServerHelloBogusCipher",
2726 config: Config{
2727 MaxVersion: VersionTLS12,
2728 Bugs: ProtocolBugs{
2729 SendCipherSuite: bogusCipher,
2730 },
2731 },
2732 shouldFail: true,
2733 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2734 })
2735 testCases = append(testCases, testCase{
2736 name: "ServerHelloBogusCipher-TLS13",
2737 config: Config{
2738 MaxVersion: VersionTLS13,
2739 Bugs: ProtocolBugs{
2740 SendCipherSuite: bogusCipher,
2741 },
2742 },
2743 shouldFail: true,
2744 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2745 })
2746
2747 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002748 name: "WeakDH",
2749 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002750 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002751 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2752 Bugs: ProtocolBugs{
2753 // This is a 1023-bit prime number, generated
2754 // with:
2755 // openssl gendh 1023 | openssl asn1parse -i
2756 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2757 },
2758 },
2759 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002760 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002761 })
Adam Langleycef75832015-09-03 14:51:12 -07002762
David Benjamincd24a392015-11-11 13:23:05 -08002763 testCases = append(testCases, testCase{
2764 name: "SillyDH",
2765 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002766 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002767 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2768 Bugs: ProtocolBugs{
2769 // This is a 4097-bit prime number, generated
2770 // with:
2771 // openssl gendh 4097 | openssl asn1parse -i
2772 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2773 },
2774 },
2775 shouldFail: true,
2776 expectedError: ":DH_P_TOO_LONG:",
2777 })
2778
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002779 // This test ensures that Diffie-Hellman public values are padded with
2780 // zeros so that they're the same length as the prime. This is to avoid
2781 // hitting a bug in yaSSL.
2782 testCases = append(testCases, testCase{
2783 testType: serverTest,
2784 name: "DHPublicValuePadded",
2785 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002786 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002787 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2788 Bugs: ProtocolBugs{
2789 RequireDHPublicValueLen: (1025 + 7) / 8,
2790 },
2791 },
2792 flags: []string{"-use-sparse-dh-prime"},
2793 })
David Benjamincd24a392015-11-11 13:23:05 -08002794
David Benjamin241ae832016-01-15 03:04:54 -05002795 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002796 testCases = append(testCases, testCase{
2797 testType: serverTest,
2798 name: "UnknownCipher",
2799 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002800 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002801 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002802 Bugs: ProtocolBugs{
2803 AdvertiseAllConfiguredCiphers: true,
2804 },
2805 },
2806 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002807
2808 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002809 testCases = append(testCases, testCase{
2810 testType: serverTest,
2811 name: "UnknownCipher-TLS13",
2812 config: Config{
2813 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002814 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002815 Bugs: ProtocolBugs{
2816 AdvertiseAllConfiguredCiphers: true,
2817 },
David Benjamin241ae832016-01-15 03:04:54 -05002818 },
2819 })
2820
David Benjamin78679342016-09-16 19:42:05 -04002821 // Test empty ECDHE_PSK identity hints work as expected.
2822 testCases = append(testCases, testCase{
2823 name: "EmptyECDHEPSKHint",
2824 config: Config{
2825 MaxVersion: VersionTLS12,
2826 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2827 PreSharedKey: []byte("secret"),
2828 },
2829 flags: []string{"-psk", "secret"},
2830 })
2831
2832 // Test empty PSK identity hints work as expected, even if an explicit
2833 // ServerKeyExchange is sent.
2834 testCases = append(testCases, testCase{
2835 name: "ExplicitEmptyPSKHint",
2836 config: Config{
2837 MaxVersion: VersionTLS12,
2838 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2839 PreSharedKey: []byte("secret"),
2840 Bugs: ProtocolBugs{
2841 AlwaysSendPreSharedKeyIdentityHint: true,
2842 },
2843 },
2844 flags: []string{"-psk", "secret"},
2845 })
Adam Langley95c29f32014-06-20 12:00:00 -07002846}
2847
2848func addBadECDSASignatureTests() {
2849 for badR := BadValue(1); badR < NumBadValues; badR++ {
2850 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002851 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002852 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2853 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002854 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002855 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002856 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002857 Bugs: ProtocolBugs{
2858 BadECDSAR: badR,
2859 BadECDSAS: badS,
2860 },
2861 },
2862 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002863 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002864 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002865 testCases = append(testCases, testCase{
2866 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2867 config: Config{
2868 MaxVersion: VersionTLS13,
2869 Certificates: []Certificate{ecdsaP256Certificate},
2870 Bugs: ProtocolBugs{
2871 BadECDSAR: badR,
2872 BadECDSAS: badS,
2873 },
2874 },
2875 shouldFail: true,
2876 expectedError: ":BAD_SIGNATURE:",
2877 })
Adam Langley95c29f32014-06-20 12:00:00 -07002878 }
2879 }
2880}
2881
Adam Langley80842bd2014-06-20 12:00:00 -07002882func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002883 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002884 name: "MaxCBCPadding",
2885 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002886 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002887 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2888 Bugs: ProtocolBugs{
2889 MaxPadding: true,
2890 },
2891 },
2892 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2893 })
David Benjamin025b3d32014-07-01 19:53:04 -04002894 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002895 name: "BadCBCPadding",
2896 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002897 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002898 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2899 Bugs: ProtocolBugs{
2900 PaddingFirstByteBad: true,
2901 },
2902 },
2903 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002904 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002905 })
2906 // OpenSSL previously had an issue where the first byte of padding in
2907 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002908 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002909 name: "BadCBCPadding255",
2910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002911 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2913 Bugs: ProtocolBugs{
2914 MaxPadding: true,
2915 PaddingFirstByteBadIf255: true,
2916 },
2917 },
2918 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2919 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002920 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002921 })
2922}
2923
Kenny Root7fdeaf12014-08-05 15:23:37 -07002924func addCBCSplittingTests() {
2925 testCases = append(testCases, testCase{
2926 name: "CBCRecordSplitting",
2927 config: Config{
2928 MaxVersion: VersionTLS10,
2929 MinVersion: VersionTLS10,
2930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2931 },
David Benjaminac8302a2015-09-01 17:18:15 -04002932 messageLen: -1, // read until EOF
2933 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002934 flags: []string{
2935 "-async",
2936 "-write-different-record-sizes",
2937 "-cbc-record-splitting",
2938 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002939 })
2940 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002941 name: "CBCRecordSplittingPartialWrite",
2942 config: Config{
2943 MaxVersion: VersionTLS10,
2944 MinVersion: VersionTLS10,
2945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2946 },
2947 messageLen: -1, // read until EOF
2948 flags: []string{
2949 "-async",
2950 "-write-different-record-sizes",
2951 "-cbc-record-splitting",
2952 "-partial-write",
2953 },
2954 })
2955}
2956
David Benjamin636293b2014-07-08 17:59:18 -04002957func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002958 // Add a dummy cert pool to stress certificate authority parsing.
2959 // TODO(davidben): Add tests that those values parse out correctly.
2960 certPool := x509.NewCertPool()
2961 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2962 if err != nil {
2963 panic(err)
2964 }
2965 certPool.AddCert(cert)
2966
David Benjamin636293b2014-07-08 17:59:18 -04002967 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002968 testCases = append(testCases, testCase{
2969 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002970 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002971 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002972 MinVersion: ver.version,
2973 MaxVersion: ver.version,
2974 ClientAuth: RequireAnyClientCert,
2975 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002976 },
2977 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002978 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2979 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002980 },
2981 })
2982 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002983 testType: serverTest,
2984 name: ver.name + "-Server-ClientAuth-RSA",
2985 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002986 MinVersion: ver.version,
2987 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002988 Certificates: []Certificate{rsaCertificate},
2989 },
2990 flags: []string{"-require-any-client-certificate"},
2991 })
David Benjamine098ec22014-08-27 23:13:20 -04002992 if ver.version != VersionSSL30 {
2993 testCases = append(testCases, testCase{
2994 testType: serverTest,
2995 name: ver.name + "-Server-ClientAuth-ECDSA",
2996 config: Config{
2997 MinVersion: ver.version,
2998 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002999 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003000 },
3001 flags: []string{"-require-any-client-certificate"},
3002 })
3003 testCases = append(testCases, testCase{
3004 testType: clientTest,
3005 name: ver.name + "-Client-ClientAuth-ECDSA",
3006 config: Config{
3007 MinVersion: ver.version,
3008 MaxVersion: ver.version,
3009 ClientAuth: RequireAnyClientCert,
3010 ClientCAs: certPool,
3011 },
3012 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003013 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3014 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003015 },
3016 })
3017 }
Adam Langley37646832016-08-01 16:16:46 -07003018
3019 testCases = append(testCases, testCase{
3020 name: "NoClientCertificate-" + ver.name,
3021 config: Config{
3022 MinVersion: ver.version,
3023 MaxVersion: ver.version,
3024 ClientAuth: RequireAnyClientCert,
3025 },
3026 shouldFail: true,
3027 expectedLocalError: "client didn't provide a certificate",
3028 })
3029
3030 testCases = append(testCases, testCase{
3031 // Even if not configured to expect a certificate, OpenSSL will
3032 // return X509_V_OK as the verify_result.
3033 testType: serverTest,
3034 name: "NoClientCertificateRequested-Server-" + ver.name,
3035 config: Config{
3036 MinVersion: ver.version,
3037 MaxVersion: ver.version,
3038 },
3039 flags: []string{
3040 "-expect-verify-result",
3041 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003042 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003043 })
3044
3045 testCases = append(testCases, testCase{
3046 // If a client certificate is not provided, OpenSSL will still
3047 // return X509_V_OK as the verify_result.
3048 testType: serverTest,
3049 name: "NoClientCertificate-Server-" + ver.name,
3050 config: Config{
3051 MinVersion: ver.version,
3052 MaxVersion: ver.version,
3053 },
3054 flags: []string{
3055 "-expect-verify-result",
3056 "-verify-peer",
3057 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003058 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003059 })
3060
David Benjamin1db9e1b2016-10-07 20:51:43 -04003061 certificateRequired := "remote error: certificate required"
3062 if ver.version < VersionTLS13 {
3063 // Prior to TLS 1.3, the generic handshake_failure alert
3064 // was used.
3065 certificateRequired = "remote error: handshake failure"
3066 }
Adam Langley37646832016-08-01 16:16:46 -07003067 testCases = append(testCases, testCase{
3068 testType: serverTest,
3069 name: "RequireAnyClientCertificate-" + ver.name,
3070 config: Config{
3071 MinVersion: ver.version,
3072 MaxVersion: ver.version,
3073 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003074 flags: []string{"-require-any-client-certificate"},
3075 shouldFail: true,
3076 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3077 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003078 })
3079
3080 if ver.version != VersionSSL30 {
3081 testCases = append(testCases, testCase{
3082 testType: serverTest,
3083 name: "SkipClientCertificate-" + ver.name,
3084 config: Config{
3085 MinVersion: ver.version,
3086 MaxVersion: ver.version,
3087 Bugs: ProtocolBugs{
3088 SkipClientCertificate: true,
3089 },
3090 },
3091 // Setting SSL_VERIFY_PEER allows anonymous clients.
3092 flags: []string{"-verify-peer"},
3093 shouldFail: true,
3094 expectedError: ":UNEXPECTED_MESSAGE:",
3095 })
3096 }
David Benjamin636293b2014-07-08 17:59:18 -04003097 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003098
David Benjaminc032dfa2016-05-12 14:54:57 -04003099 // Client auth is only legal in certificate-based ciphers.
3100 testCases = append(testCases, testCase{
3101 testType: clientTest,
3102 name: "ClientAuth-PSK",
3103 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003104 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003105 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3106 PreSharedKey: []byte("secret"),
3107 ClientAuth: RequireAnyClientCert,
3108 },
3109 flags: []string{
3110 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3111 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3112 "-psk", "secret",
3113 },
3114 shouldFail: true,
3115 expectedError: ":UNEXPECTED_MESSAGE:",
3116 })
3117 testCases = append(testCases, testCase{
3118 testType: clientTest,
3119 name: "ClientAuth-ECDHE_PSK",
3120 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003121 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003122 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3123 PreSharedKey: []byte("secret"),
3124 ClientAuth: RequireAnyClientCert,
3125 },
3126 flags: []string{
3127 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3128 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3129 "-psk", "secret",
3130 },
3131 shouldFail: true,
3132 expectedError: ":UNEXPECTED_MESSAGE:",
3133 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003134
3135 // Regression test for a bug where the client CA list, if explicitly
3136 // set to NULL, was mis-encoded.
3137 testCases = append(testCases, testCase{
3138 testType: serverTest,
3139 name: "Null-Client-CA-List",
3140 config: Config{
3141 MaxVersion: VersionTLS12,
3142 Certificates: []Certificate{rsaCertificate},
3143 },
3144 flags: []string{
3145 "-require-any-client-certificate",
3146 "-use-null-client-ca-list",
3147 },
3148 })
David Benjamin636293b2014-07-08 17:59:18 -04003149}
3150
Adam Langley75712922014-10-10 16:23:43 -07003151func addExtendedMasterSecretTests() {
3152 const expectEMSFlag = "-expect-extended-master-secret"
3153
3154 for _, with := range []bool{false, true} {
3155 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003156 if with {
3157 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003158 }
3159
3160 for _, isClient := range []bool{false, true} {
3161 suffix := "-Server"
3162 testType := serverTest
3163 if isClient {
3164 suffix = "-Client"
3165 testType = clientTest
3166 }
3167
3168 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003169 // In TLS 1.3, the extension is irrelevant and
3170 // always reports as enabled.
3171 var flags []string
3172 if with || ver.version >= VersionTLS13 {
3173 flags = []string{expectEMSFlag}
3174 }
3175
Adam Langley75712922014-10-10 16:23:43 -07003176 test := testCase{
3177 testType: testType,
3178 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3179 config: Config{
3180 MinVersion: ver.version,
3181 MaxVersion: ver.version,
3182 Bugs: ProtocolBugs{
3183 NoExtendedMasterSecret: !with,
3184 RequireExtendedMasterSecret: with,
3185 },
3186 },
David Benjamin48cae082014-10-27 01:06:24 -04003187 flags: flags,
3188 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003189 }
3190 if test.shouldFail {
3191 test.expectedLocalError = "extended master secret required but not supported by peer"
3192 }
3193 testCases = append(testCases, test)
3194 }
3195 }
3196 }
3197
Adam Langleyba5934b2015-06-02 10:50:35 -07003198 for _, isClient := range []bool{false, true} {
3199 for _, supportedInFirstConnection := range []bool{false, true} {
3200 for _, supportedInResumeConnection := range []bool{false, true} {
3201 boolToWord := func(b bool) string {
3202 if b {
3203 return "Yes"
3204 }
3205 return "No"
3206 }
3207 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3208 if isClient {
3209 suffix += "Client"
3210 } else {
3211 suffix += "Server"
3212 }
3213
3214 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003215 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003216 Bugs: ProtocolBugs{
3217 RequireExtendedMasterSecret: true,
3218 },
3219 }
3220
3221 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003222 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003223 Bugs: ProtocolBugs{
3224 NoExtendedMasterSecret: true,
3225 },
3226 }
3227
3228 test := testCase{
3229 name: "ExtendedMasterSecret-" + suffix,
3230 resumeSession: true,
3231 }
3232
3233 if !isClient {
3234 test.testType = serverTest
3235 }
3236
3237 if supportedInFirstConnection {
3238 test.config = supportedConfig
3239 } else {
3240 test.config = noSupportConfig
3241 }
3242
3243 if supportedInResumeConnection {
3244 test.resumeConfig = &supportedConfig
3245 } else {
3246 test.resumeConfig = &noSupportConfig
3247 }
3248
3249 switch suffix {
3250 case "YesToYes-Client", "YesToYes-Server":
3251 // When a session is resumed, it should
3252 // still be aware that its master
3253 // secret was generated via EMS and
3254 // thus it's safe to use tls-unique.
3255 test.flags = []string{expectEMSFlag}
3256 case "NoToYes-Server":
3257 // If an original connection did not
3258 // contain EMS, but a resumption
3259 // handshake does, then a server should
3260 // not resume the session.
3261 test.expectResumeRejected = true
3262 case "YesToNo-Server":
3263 // Resuming an EMS session without the
3264 // EMS extension should cause the
3265 // server to abort the connection.
3266 test.shouldFail = true
3267 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3268 case "NoToYes-Client":
3269 // A client should abort a connection
3270 // where the server resumed a non-EMS
3271 // session but echoed the EMS
3272 // extension.
3273 test.shouldFail = true
3274 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3275 case "YesToNo-Client":
3276 // A client should abort a connection
3277 // where the server didn't echo EMS
3278 // when the session used it.
3279 test.shouldFail = true
3280 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3281 }
3282
3283 testCases = append(testCases, test)
3284 }
3285 }
3286 }
David Benjamin163c9562016-08-29 23:14:17 -04003287
3288 // Switching EMS on renegotiation is forbidden.
3289 testCases = append(testCases, testCase{
3290 name: "ExtendedMasterSecret-Renego-NoEMS",
3291 config: Config{
3292 MaxVersion: VersionTLS12,
3293 Bugs: ProtocolBugs{
3294 NoExtendedMasterSecret: true,
3295 NoExtendedMasterSecretOnRenegotiation: true,
3296 },
3297 },
3298 renegotiate: 1,
3299 flags: []string{
3300 "-renegotiate-freely",
3301 "-expect-total-renegotiations", "1",
3302 },
3303 })
3304
3305 testCases = append(testCases, testCase{
3306 name: "ExtendedMasterSecret-Renego-Upgrade",
3307 config: Config{
3308 MaxVersion: VersionTLS12,
3309 Bugs: ProtocolBugs{
3310 NoExtendedMasterSecret: true,
3311 },
3312 },
3313 renegotiate: 1,
3314 flags: []string{
3315 "-renegotiate-freely",
3316 "-expect-total-renegotiations", "1",
3317 },
3318 shouldFail: true,
3319 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3320 })
3321
3322 testCases = append(testCases, testCase{
3323 name: "ExtendedMasterSecret-Renego-Downgrade",
3324 config: Config{
3325 MaxVersion: VersionTLS12,
3326 Bugs: ProtocolBugs{
3327 NoExtendedMasterSecretOnRenegotiation: true,
3328 },
3329 },
3330 renegotiate: 1,
3331 flags: []string{
3332 "-renegotiate-freely",
3333 "-expect-total-renegotiations", "1",
3334 },
3335 shouldFail: true,
3336 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3337 })
Adam Langley75712922014-10-10 16:23:43 -07003338}
3339
David Benjamin582ba042016-07-07 12:33:25 -07003340type stateMachineTestConfig struct {
3341 protocol protocol
3342 async bool
3343 splitHandshake, packHandshakeFlight bool
3344}
3345
David Benjamin43ec06f2014-08-05 02:28:57 -04003346// Adds tests that try to cover the range of the handshake state machine, under
3347// various conditions. Some of these are redundant with other tests, but they
3348// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003349func addAllStateMachineCoverageTests() {
3350 for _, async := range []bool{false, true} {
3351 for _, protocol := range []protocol{tls, dtls} {
3352 addStateMachineCoverageTests(stateMachineTestConfig{
3353 protocol: protocol,
3354 async: async,
3355 })
3356 addStateMachineCoverageTests(stateMachineTestConfig{
3357 protocol: protocol,
3358 async: async,
3359 splitHandshake: true,
3360 })
3361 if protocol == tls {
3362 addStateMachineCoverageTests(stateMachineTestConfig{
3363 protocol: protocol,
3364 async: async,
3365 packHandshakeFlight: true,
3366 })
3367 }
3368 }
3369 }
3370}
3371
3372func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003373 var tests []testCase
3374
3375 // Basic handshake, with resumption. Client and server,
3376 // session ID and session ticket.
3377 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003378 name: "Basic-Client",
3379 config: Config{
3380 MaxVersion: VersionTLS12,
3381 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003382 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003383 // Ensure session tickets are used, not session IDs.
3384 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003385 })
3386 tests = append(tests, testCase{
3387 name: "Basic-Client-RenewTicket",
3388 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003389 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003390 Bugs: ProtocolBugs{
3391 RenewTicketOnResume: true,
3392 },
3393 },
David Benjamin46662482016-08-17 00:51:00 -04003394 flags: []string{"-expect-ticket-renewal"},
3395 resumeSession: true,
3396 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003397 })
3398 tests = append(tests, testCase{
3399 name: "Basic-Client-NoTicket",
3400 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003401 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003402 SessionTicketsDisabled: true,
3403 },
3404 resumeSession: true,
3405 })
3406 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003407 name: "Basic-Client-Implicit",
3408 config: Config{
3409 MaxVersion: VersionTLS12,
3410 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003411 flags: []string{"-implicit-handshake"},
3412 resumeSession: true,
3413 })
3414 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003415 testType: serverTest,
3416 name: "Basic-Server",
3417 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003418 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003419 Bugs: ProtocolBugs{
3420 RequireSessionTickets: true,
3421 },
3422 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003423 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003424 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003425 })
3426 tests = append(tests, testCase{
3427 testType: serverTest,
3428 name: "Basic-Server-NoTickets",
3429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003430 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003431 SessionTicketsDisabled: true,
3432 },
3433 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003434 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003435 })
3436 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003437 testType: serverTest,
3438 name: "Basic-Server-Implicit",
3439 config: Config{
3440 MaxVersion: VersionTLS12,
3441 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003442 flags: []string{"-implicit-handshake"},
3443 resumeSession: true,
3444 })
3445 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003446 testType: serverTest,
3447 name: "Basic-Server-EarlyCallback",
3448 config: Config{
3449 MaxVersion: VersionTLS12,
3450 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003451 flags: []string{"-use-early-callback"},
3452 resumeSession: true,
3453 })
3454
Steven Valdez143e8b32016-07-11 13:19:03 -04003455 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003456 if config.protocol == tls {
3457 tests = append(tests, testCase{
3458 name: "TLS13-1RTT-Client",
3459 config: Config{
3460 MaxVersion: VersionTLS13,
3461 MinVersion: VersionTLS13,
3462 },
David Benjamin46662482016-08-17 00:51:00 -04003463 resumeSession: true,
3464 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003465 })
3466
3467 tests = append(tests, testCase{
3468 testType: serverTest,
3469 name: "TLS13-1RTT-Server",
3470 config: Config{
3471 MaxVersion: VersionTLS13,
3472 MinVersion: VersionTLS13,
3473 },
David Benjamin46662482016-08-17 00:51:00 -04003474 resumeSession: true,
3475 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003476 // TLS 1.3 uses tickets, so the session should not be
3477 // cached statefully.
3478 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003479 })
3480
3481 tests = append(tests, testCase{
3482 name: "TLS13-HelloRetryRequest-Client",
3483 config: Config{
3484 MaxVersion: VersionTLS13,
3485 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003486 // P-384 requires a HelloRetryRequest against BoringSSL's default
3487 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003488 CurvePreferences: []CurveID{CurveP384},
3489 Bugs: ProtocolBugs{
3490 ExpectMissingKeyShare: true,
3491 },
3492 },
3493 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3494 resumeSession: true,
3495 })
3496
3497 tests = append(tests, testCase{
3498 testType: serverTest,
3499 name: "TLS13-HelloRetryRequest-Server",
3500 config: Config{
3501 MaxVersion: VersionTLS13,
3502 MinVersion: VersionTLS13,
3503 // Require a HelloRetryRequest for every curve.
3504 DefaultCurves: []CurveID{},
3505 },
3506 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3507 resumeSession: true,
3508 })
3509 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003510
David Benjamin760b1dd2015-05-15 23:33:48 -04003511 // TLS client auth.
3512 tests = append(tests, testCase{
3513 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003514 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003516 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003517 ClientAuth: RequestClientCert,
3518 },
3519 })
3520 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003521 testType: serverTest,
3522 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003523 config: Config{
3524 MaxVersion: VersionTLS12,
3525 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003526 // Setting SSL_VERIFY_PEER allows anonymous clients.
3527 flags: []string{"-verify-peer"},
3528 })
David Benjamin582ba042016-07-07 12:33:25 -07003529 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003530 tests = append(tests, testCase{
3531 testType: clientTest,
3532 name: "ClientAuth-NoCertificate-Client-SSL3",
3533 config: Config{
3534 MaxVersion: VersionSSL30,
3535 ClientAuth: RequestClientCert,
3536 },
3537 })
3538 tests = append(tests, testCase{
3539 testType: serverTest,
3540 name: "ClientAuth-NoCertificate-Server-SSL3",
3541 config: Config{
3542 MaxVersion: VersionSSL30,
3543 },
3544 // Setting SSL_VERIFY_PEER allows anonymous clients.
3545 flags: []string{"-verify-peer"},
3546 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003547 tests = append(tests, testCase{
3548 testType: clientTest,
3549 name: "ClientAuth-NoCertificate-Client-TLS13",
3550 config: Config{
3551 MaxVersion: VersionTLS13,
3552 ClientAuth: RequestClientCert,
3553 },
3554 })
3555 tests = append(tests, testCase{
3556 testType: serverTest,
3557 name: "ClientAuth-NoCertificate-Server-TLS13",
3558 config: Config{
3559 MaxVersion: VersionTLS13,
3560 },
3561 // Setting SSL_VERIFY_PEER allows anonymous clients.
3562 flags: []string{"-verify-peer"},
3563 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003564 }
3565 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003566 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003567 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003569 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003570 ClientAuth: RequireAnyClientCert,
3571 },
3572 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003573 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3574 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003575 },
3576 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003577 tests = append(tests, testCase{
3578 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003579 name: "ClientAuth-RSA-Client-TLS13",
3580 config: Config{
3581 MaxVersion: VersionTLS13,
3582 ClientAuth: RequireAnyClientCert,
3583 },
3584 flags: []string{
3585 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3586 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3587 },
3588 })
3589 tests = append(tests, testCase{
3590 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003591 name: "ClientAuth-ECDSA-Client",
3592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003593 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003594 ClientAuth: RequireAnyClientCert,
3595 },
3596 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003597 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3598 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003599 },
3600 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003601 tests = append(tests, testCase{
3602 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003603 name: "ClientAuth-ECDSA-Client-TLS13",
3604 config: Config{
3605 MaxVersion: VersionTLS13,
3606 ClientAuth: RequireAnyClientCert,
3607 },
3608 flags: []string{
3609 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3610 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3611 },
3612 })
3613 tests = append(tests, testCase{
3614 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003615 name: "ClientAuth-NoCertificate-OldCallback",
3616 config: Config{
3617 MaxVersion: VersionTLS12,
3618 ClientAuth: RequestClientCert,
3619 },
3620 flags: []string{"-use-old-client-cert-callback"},
3621 })
3622 tests = append(tests, testCase{
3623 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003624 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3625 config: Config{
3626 MaxVersion: VersionTLS13,
3627 ClientAuth: RequestClientCert,
3628 },
3629 flags: []string{"-use-old-client-cert-callback"},
3630 })
3631 tests = append(tests, testCase{
3632 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003633 name: "ClientAuth-OldCallback",
3634 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003635 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003636 ClientAuth: RequireAnyClientCert,
3637 },
3638 flags: []string{
3639 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3640 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3641 "-use-old-client-cert-callback",
3642 },
3643 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003644 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003645 testType: clientTest,
3646 name: "ClientAuth-OldCallback-TLS13",
3647 config: Config{
3648 MaxVersion: VersionTLS13,
3649 ClientAuth: RequireAnyClientCert,
3650 },
3651 flags: []string{
3652 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3653 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3654 "-use-old-client-cert-callback",
3655 },
3656 })
3657 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003658 testType: serverTest,
3659 name: "ClientAuth-Server",
3660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003661 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003662 Certificates: []Certificate{rsaCertificate},
3663 },
3664 flags: []string{"-require-any-client-certificate"},
3665 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003666 tests = append(tests, testCase{
3667 testType: serverTest,
3668 name: "ClientAuth-Server-TLS13",
3669 config: Config{
3670 MaxVersion: VersionTLS13,
3671 Certificates: []Certificate{rsaCertificate},
3672 },
3673 flags: []string{"-require-any-client-certificate"},
3674 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003675
David Benjamin4c3ddf72016-06-29 18:13:53 -04003676 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003677 tests = append(tests, testCase{
3678 testType: serverTest,
3679 name: "Basic-Server-RSA",
3680 config: Config{
3681 MaxVersion: VersionTLS12,
3682 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3683 },
3684 flags: []string{
3685 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3686 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3687 },
3688 })
3689 tests = append(tests, testCase{
3690 testType: serverTest,
3691 name: "Basic-Server-ECDHE-RSA",
3692 config: Config{
3693 MaxVersion: VersionTLS12,
3694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3695 },
3696 flags: []string{
3697 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3698 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3699 },
3700 })
3701 tests = append(tests, testCase{
3702 testType: serverTest,
3703 name: "Basic-Server-ECDHE-ECDSA",
3704 config: Config{
3705 MaxVersion: VersionTLS12,
3706 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3707 },
3708 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003709 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3710 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003711 },
3712 })
3713
David Benjamin760b1dd2015-05-15 23:33:48 -04003714 // No session ticket support; server doesn't send NewSessionTicket.
3715 tests = append(tests, testCase{
3716 name: "SessionTicketsDisabled-Client",
3717 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003718 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003719 SessionTicketsDisabled: true,
3720 },
3721 })
3722 tests = append(tests, testCase{
3723 testType: serverTest,
3724 name: "SessionTicketsDisabled-Server",
3725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003726 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003727 SessionTicketsDisabled: true,
3728 },
3729 })
3730
3731 // Skip ServerKeyExchange in PSK key exchange if there's no
3732 // identity hint.
3733 tests = append(tests, testCase{
3734 name: "EmptyPSKHint-Client",
3735 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3738 PreSharedKey: []byte("secret"),
3739 },
3740 flags: []string{"-psk", "secret"},
3741 })
3742 tests = append(tests, testCase{
3743 testType: serverTest,
3744 name: "EmptyPSKHint-Server",
3745 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003746 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003747 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3748 PreSharedKey: []byte("secret"),
3749 },
3750 flags: []string{"-psk", "secret"},
3751 })
3752
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003754 tests = append(tests, testCase{
3755 testType: clientTest,
3756 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003757 config: Config{
3758 MaxVersion: VersionTLS12,
3759 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003760 flags: []string{
3761 "-enable-ocsp-stapling",
3762 "-expect-ocsp-response",
3763 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003764 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003765 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003766 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003767 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003768 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003769 testType: serverTest,
3770 name: "OCSPStapling-Server",
3771 config: Config{
3772 MaxVersion: VersionTLS12,
3773 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003774 expectedOCSPResponse: testOCSPResponse,
3775 flags: []string{
3776 "-ocsp-response",
3777 base64.StdEncoding.EncodeToString(testOCSPResponse),
3778 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003779 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003780 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003781 tests = append(tests, testCase{
3782 testType: clientTest,
3783 name: "OCSPStapling-Client-TLS13",
3784 config: Config{
3785 MaxVersion: VersionTLS13,
3786 },
3787 flags: []string{
3788 "-enable-ocsp-stapling",
3789 "-expect-ocsp-response",
3790 base64.StdEncoding.EncodeToString(testOCSPResponse),
3791 "-verify-peer",
3792 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003793 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003794 })
3795 tests = append(tests, testCase{
3796 testType: serverTest,
3797 name: "OCSPStapling-Server-TLS13",
3798 config: Config{
3799 MaxVersion: VersionTLS13,
3800 },
3801 expectedOCSPResponse: testOCSPResponse,
3802 flags: []string{
3803 "-ocsp-response",
3804 base64.StdEncoding.EncodeToString(testOCSPResponse),
3805 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003806 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003807 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003808
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003810 for _, vers := range tlsVersions {
3811 if config.protocol == dtls && !vers.hasDTLS {
3812 continue
3813 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003814 for _, testType := range []testType{clientTest, serverTest} {
3815 suffix := "-Client"
3816 if testType == serverTest {
3817 suffix = "-Server"
3818 }
3819 suffix += "-" + vers.name
3820
3821 flag := "-verify-peer"
3822 if testType == serverTest {
3823 flag = "-require-any-client-certificate"
3824 }
3825
3826 tests = append(tests, testCase{
3827 testType: testType,
3828 name: "CertificateVerificationSucceed" + suffix,
3829 config: Config{
3830 MaxVersion: vers.version,
3831 Certificates: []Certificate{rsaCertificate},
3832 },
3833 flags: []string{
3834 flag,
3835 "-expect-verify-result",
3836 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003837 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003838 })
3839 tests = append(tests, testCase{
3840 testType: testType,
3841 name: "CertificateVerificationFail" + suffix,
3842 config: Config{
3843 MaxVersion: vers.version,
3844 Certificates: []Certificate{rsaCertificate},
3845 },
3846 flags: []string{
3847 flag,
3848 "-verify-fail",
3849 },
3850 shouldFail: true,
3851 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3852 })
3853 }
3854
3855 // By default, the client is in a soft fail mode where the peer
3856 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003857 tests = append(tests, testCase{
3858 testType: clientTest,
3859 name: "CertificateVerificationSoftFail-" + vers.name,
3860 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003861 MaxVersion: vers.version,
3862 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003863 },
3864 flags: []string{
3865 "-verify-fail",
3866 "-expect-verify-result",
3867 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003868 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003869 })
3870 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003871
David Benjamin1d4f4c02016-07-26 18:03:08 -04003872 tests = append(tests, testCase{
3873 name: "ShimSendAlert",
3874 flags: []string{"-send-alert"},
3875 shimWritesFirst: true,
3876 shouldFail: true,
3877 expectedLocalError: "remote error: decompression failure",
3878 })
3879
David Benjamin582ba042016-07-07 12:33:25 -07003880 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003882 name: "Renegotiate-Client",
3883 config: Config{
3884 MaxVersion: VersionTLS12,
3885 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003886 renegotiate: 1,
3887 flags: []string{
3888 "-renegotiate-freely",
3889 "-expect-total-renegotiations", "1",
3890 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003891 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003892
David Benjamin47921102016-07-28 11:29:18 -04003893 tests = append(tests, testCase{
3894 name: "SendHalfHelloRequest",
3895 config: Config{
3896 MaxVersion: VersionTLS12,
3897 Bugs: ProtocolBugs{
3898 PackHelloRequestWithFinished: config.packHandshakeFlight,
3899 },
3900 },
3901 sendHalfHelloRequest: true,
3902 flags: []string{"-renegotiate-ignore"},
3903 shouldFail: true,
3904 expectedError: ":UNEXPECTED_RECORD:",
3905 })
3906
David Benjamin760b1dd2015-05-15 23:33:48 -04003907 // NPN on client and server; results in post-handshake message.
3908 tests = append(tests, testCase{
3909 name: "NPN-Client",
3910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003911 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003912 NextProtos: []string{"foo"},
3913 },
3914 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003915 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003916 expectedNextProto: "foo",
3917 expectedNextProtoType: npn,
3918 })
3919 tests = append(tests, testCase{
3920 testType: serverTest,
3921 name: "NPN-Server",
3922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003923 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003924 NextProtos: []string{"bar"},
3925 },
3926 flags: []string{
3927 "-advertise-npn", "\x03foo\x03bar\x03baz",
3928 "-expect-next-proto", "bar",
3929 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003930 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003931 expectedNextProto: "bar",
3932 expectedNextProtoType: npn,
3933 })
3934
3935 // TODO(davidben): Add tests for when False Start doesn't trigger.
3936
3937 // Client does False Start and negotiates NPN.
3938 tests = append(tests, testCase{
3939 name: "FalseStart",
3940 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003941 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3943 NextProtos: []string{"foo"},
3944 Bugs: ProtocolBugs{
3945 ExpectFalseStart: true,
3946 },
3947 },
3948 flags: []string{
3949 "-false-start",
3950 "-select-next-proto", "foo",
3951 },
3952 shimWritesFirst: true,
3953 resumeSession: true,
3954 })
3955
3956 // Client does False Start and negotiates ALPN.
3957 tests = append(tests, testCase{
3958 name: "FalseStart-ALPN",
3959 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003960 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3962 NextProtos: []string{"foo"},
3963 Bugs: ProtocolBugs{
3964 ExpectFalseStart: true,
3965 },
3966 },
3967 flags: []string{
3968 "-false-start",
3969 "-advertise-alpn", "\x03foo",
3970 },
3971 shimWritesFirst: true,
3972 resumeSession: true,
3973 })
3974
3975 // Client does False Start but doesn't explicitly call
3976 // SSL_connect.
3977 tests = append(tests, testCase{
3978 name: "FalseStart-Implicit",
3979 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003980 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3982 NextProtos: []string{"foo"},
3983 },
3984 flags: []string{
3985 "-implicit-handshake",
3986 "-false-start",
3987 "-advertise-alpn", "\x03foo",
3988 },
3989 })
3990
3991 // False Start without session tickets.
3992 tests = append(tests, testCase{
3993 name: "FalseStart-SessionTicketsDisabled",
3994 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003995 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003996 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3997 NextProtos: []string{"foo"},
3998 SessionTicketsDisabled: true,
3999 Bugs: ProtocolBugs{
4000 ExpectFalseStart: true,
4001 },
4002 },
4003 flags: []string{
4004 "-false-start",
4005 "-select-next-proto", "foo",
4006 },
4007 shimWritesFirst: true,
4008 })
4009
4010 // Server parses a V2ClientHello.
4011 tests = append(tests, testCase{
4012 testType: serverTest,
4013 name: "SendV2ClientHello",
4014 config: Config{
4015 // Choose a cipher suite that does not involve
4016 // elliptic curves, so no extensions are
4017 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004018 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004019 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004020 Bugs: ProtocolBugs{
4021 SendV2ClientHello: true,
4022 },
4023 },
4024 })
4025
Nick Harper60a85cb2016-09-23 16:25:11 -07004026 // Test Channel ID
4027 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004028 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004029 continue
4030 }
4031 // Client sends a Channel ID.
4032 tests = append(tests, testCase{
4033 name: "ChannelID-Client-" + ver.name,
4034 config: Config{
4035 MaxVersion: ver.version,
4036 RequestChannelID: true,
4037 },
4038 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4039 resumeSession: true,
4040 expectChannelID: true,
4041 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004042
Nick Harper60a85cb2016-09-23 16:25:11 -07004043 // Server accepts a Channel ID.
4044 tests = append(tests, testCase{
4045 testType: serverTest,
4046 name: "ChannelID-Server-" + ver.name,
4047 config: Config{
4048 MaxVersion: ver.version,
4049 ChannelID: channelIDKey,
4050 },
4051 flags: []string{
4052 "-expect-channel-id",
4053 base64.StdEncoding.EncodeToString(channelIDBytes),
4054 },
4055 resumeSession: true,
4056 expectChannelID: true,
4057 })
4058
4059 tests = append(tests, testCase{
4060 testType: serverTest,
4061 name: "InvalidChannelIDSignature-" + ver.name,
4062 config: Config{
4063 MaxVersion: ver.version,
4064 ChannelID: channelIDKey,
4065 Bugs: ProtocolBugs{
4066 InvalidChannelIDSignature: true,
4067 },
4068 },
4069 flags: []string{"-enable-channel-id"},
4070 shouldFail: true,
4071 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4072 })
4073 }
David Benjamin30789da2015-08-29 22:56:45 -04004074
David Benjaminf8fcdf32016-06-08 15:56:13 -04004075 // Channel ID and NPN at the same time, to ensure their relative
4076 // ordering is correct.
4077 tests = append(tests, testCase{
4078 name: "ChannelID-NPN-Client",
4079 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004080 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004081 RequestChannelID: true,
4082 NextProtos: []string{"foo"},
4083 },
4084 flags: []string{
4085 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4086 "-select-next-proto", "foo",
4087 },
4088 resumeSession: true,
4089 expectChannelID: true,
4090 expectedNextProto: "foo",
4091 expectedNextProtoType: npn,
4092 })
4093 tests = append(tests, testCase{
4094 testType: serverTest,
4095 name: "ChannelID-NPN-Server",
4096 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004097 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004098 ChannelID: channelIDKey,
4099 NextProtos: []string{"bar"},
4100 },
4101 flags: []string{
4102 "-expect-channel-id",
4103 base64.StdEncoding.EncodeToString(channelIDBytes),
4104 "-advertise-npn", "\x03foo\x03bar\x03baz",
4105 "-expect-next-proto", "bar",
4106 },
4107 resumeSession: true,
4108 expectChannelID: true,
4109 expectedNextProto: "bar",
4110 expectedNextProtoType: npn,
4111 })
4112
David Benjamin30789da2015-08-29 22:56:45 -04004113 // Bidirectional shutdown with the runner initiating.
4114 tests = append(tests, testCase{
4115 name: "Shutdown-Runner",
4116 config: Config{
4117 Bugs: ProtocolBugs{
4118 ExpectCloseNotify: true,
4119 },
4120 },
4121 flags: []string{"-check-close-notify"},
4122 })
4123
4124 // Bidirectional shutdown with the shim initiating. The runner,
4125 // in the meantime, sends garbage before the close_notify which
4126 // the shim must ignore.
4127 tests = append(tests, testCase{
4128 name: "Shutdown-Shim",
4129 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004130 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004131 Bugs: ProtocolBugs{
4132 ExpectCloseNotify: true,
4133 },
4134 },
4135 shimShutsDown: true,
4136 sendEmptyRecords: 1,
4137 sendWarningAlerts: 1,
4138 flags: []string{"-check-close-notify"},
4139 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004140 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004141 // TODO(davidben): DTLS 1.3 will want a similar thing for
4142 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004143 tests = append(tests, testCase{
4144 name: "SkipHelloVerifyRequest",
4145 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004146 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004147 Bugs: ProtocolBugs{
4148 SkipHelloVerifyRequest: true,
4149 },
4150 },
4151 })
4152 }
4153
David Benjamin760b1dd2015-05-15 23:33:48 -04004154 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004155 test.protocol = config.protocol
4156 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004157 test.name += "-DTLS"
4158 }
David Benjamin582ba042016-07-07 12:33:25 -07004159 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004160 test.name += "-Async"
4161 test.flags = append(test.flags, "-async")
4162 } else {
4163 test.name += "-Sync"
4164 }
David Benjamin582ba042016-07-07 12:33:25 -07004165 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004166 test.name += "-SplitHandshakeRecords"
4167 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004168 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004169 test.config.Bugs.MaxPacketLength = 256
4170 test.flags = append(test.flags, "-mtu", "256")
4171 }
4172 }
David Benjamin582ba042016-07-07 12:33:25 -07004173 if config.packHandshakeFlight {
4174 test.name += "-PackHandshakeFlight"
4175 test.config.Bugs.PackHandshakeFlight = true
4176 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004177 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004178 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004179}
4180
Adam Langley524e7172015-02-20 16:04:00 -08004181func addDDoSCallbackTests() {
4182 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004183 for _, resume := range []bool{false, true} {
4184 suffix := "Resume"
4185 if resume {
4186 suffix = "No" + suffix
4187 }
4188
4189 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004190 testType: serverTest,
4191 name: "Server-DDoS-OK-" + suffix,
4192 config: Config{
4193 MaxVersion: VersionTLS12,
4194 },
Adam Langley524e7172015-02-20 16:04:00 -08004195 flags: []string{"-install-ddos-callback"},
4196 resumeSession: resume,
4197 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004198 testCases = append(testCases, testCase{
4199 testType: serverTest,
4200 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4201 config: Config{
4202 MaxVersion: VersionTLS13,
4203 },
4204 flags: []string{"-install-ddos-callback"},
4205 resumeSession: resume,
4206 })
Adam Langley524e7172015-02-20 16:04:00 -08004207
4208 failFlag := "-fail-ddos-callback"
4209 if resume {
4210 failFlag = "-fail-second-ddos-callback"
4211 }
4212 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004213 testType: serverTest,
4214 name: "Server-DDoS-Reject-" + suffix,
4215 config: Config{
4216 MaxVersion: VersionTLS12,
4217 },
David Benjamin2c66e072016-09-16 15:58:00 -04004218 flags: []string{"-install-ddos-callback", failFlag},
4219 resumeSession: resume,
4220 shouldFail: true,
4221 expectedError: ":CONNECTION_REJECTED:",
4222 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004223 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004224 testCases = append(testCases, testCase{
4225 testType: serverTest,
4226 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4227 config: Config{
4228 MaxVersion: VersionTLS13,
4229 },
David Benjamin2c66e072016-09-16 15:58:00 -04004230 flags: []string{"-install-ddos-callback", failFlag},
4231 resumeSession: resume,
4232 shouldFail: true,
4233 expectedError: ":CONNECTION_REJECTED:",
4234 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004235 })
Adam Langley524e7172015-02-20 16:04:00 -08004236 }
4237}
4238
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004239func addVersionNegotiationTests() {
4240 for i, shimVers := range tlsVersions {
4241 // Assemble flags to disable all newer versions on the shim.
4242 var flags []string
4243 for _, vers := range tlsVersions[i+1:] {
4244 flags = append(flags, vers.flag)
4245 }
4246
Steven Valdezfdd10992016-09-15 16:27:05 -04004247 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004248 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004249 protocols := []protocol{tls}
4250 if runnerVers.hasDTLS && shimVers.hasDTLS {
4251 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004252 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004253 for _, protocol := range protocols {
4254 expectedVersion := shimVers.version
4255 if runnerVers.version < shimVers.version {
4256 expectedVersion = runnerVers.version
4257 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004258
David Benjamin8b8c0062014-11-23 02:47:52 -05004259 suffix := shimVers.name + "-" + runnerVers.name
4260 if protocol == dtls {
4261 suffix += "-DTLS"
4262 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004263
David Benjamin1eb367c2014-12-12 18:17:51 -05004264 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4265
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004266 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004267 clientVers := shimVers.version
4268 if clientVers > VersionTLS10 {
4269 clientVers = VersionTLS10
4270 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004271 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004272 serverVers := expectedVersion
4273 if expectedVersion >= VersionTLS13 {
4274 serverVers = VersionTLS10
4275 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004276 serverVers = versionToWire(serverVers, protocol == dtls)
4277
David Benjamin8b8c0062014-11-23 02:47:52 -05004278 testCases = append(testCases, testCase{
4279 protocol: protocol,
4280 testType: clientTest,
4281 name: "VersionNegotiation-Client-" + suffix,
4282 config: Config{
4283 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004284 Bugs: ProtocolBugs{
4285 ExpectInitialRecordVersion: clientVers,
4286 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004287 },
4288 flags: flags,
4289 expectedVersion: expectedVersion,
4290 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004291 testCases = append(testCases, testCase{
4292 protocol: protocol,
4293 testType: clientTest,
4294 name: "VersionNegotiation-Client2-" + suffix,
4295 config: Config{
4296 MaxVersion: runnerVers.version,
4297 Bugs: ProtocolBugs{
4298 ExpectInitialRecordVersion: clientVers,
4299 },
4300 },
4301 flags: []string{"-max-version", shimVersFlag},
4302 expectedVersion: expectedVersion,
4303 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004304
4305 testCases = append(testCases, testCase{
4306 protocol: protocol,
4307 testType: serverTest,
4308 name: "VersionNegotiation-Server-" + suffix,
4309 config: Config{
4310 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004311 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004312 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004313 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004314 },
4315 flags: flags,
4316 expectedVersion: expectedVersion,
4317 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004318 testCases = append(testCases, testCase{
4319 protocol: protocol,
4320 testType: serverTest,
4321 name: "VersionNegotiation-Server2-" + suffix,
4322 config: Config{
4323 MaxVersion: runnerVers.version,
4324 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004325 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004326 },
4327 },
4328 flags: []string{"-max-version", shimVersFlag},
4329 expectedVersion: expectedVersion,
4330 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004331 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004332 }
4333 }
David Benjamin95c69562016-06-29 18:15:03 -04004334
Steven Valdezfdd10992016-09-15 16:27:05 -04004335 // Test the version extension at all versions.
4336 for _, vers := range tlsVersions {
4337 protocols := []protocol{tls}
4338 if vers.hasDTLS {
4339 protocols = append(protocols, dtls)
4340 }
4341 for _, protocol := range protocols {
4342 suffix := vers.name
4343 if protocol == dtls {
4344 suffix += "-DTLS"
4345 }
4346
4347 wireVersion := versionToWire(vers.version, protocol == dtls)
4348 testCases = append(testCases, testCase{
4349 protocol: protocol,
4350 testType: serverTest,
4351 name: "VersionNegotiationExtension-" + suffix,
4352 config: Config{
4353 Bugs: ProtocolBugs{
4354 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4355 },
4356 },
4357 expectedVersion: vers.version,
4358 })
4359 }
4360
4361 }
4362
4363 // If all versions are unknown, negotiation fails.
4364 testCases = append(testCases, testCase{
4365 testType: serverTest,
4366 name: "NoSupportedVersions",
4367 config: Config{
4368 Bugs: ProtocolBugs{
4369 SendSupportedVersions: []uint16{0x1111},
4370 },
4371 },
4372 shouldFail: true,
4373 expectedError: ":UNSUPPORTED_PROTOCOL:",
4374 })
4375 testCases = append(testCases, testCase{
4376 protocol: dtls,
4377 testType: serverTest,
4378 name: "NoSupportedVersions-DTLS",
4379 config: Config{
4380 Bugs: ProtocolBugs{
4381 SendSupportedVersions: []uint16{0x1111},
4382 },
4383 },
4384 shouldFail: true,
4385 expectedError: ":UNSUPPORTED_PROTOCOL:",
4386 })
4387
4388 testCases = append(testCases, testCase{
4389 testType: serverTest,
4390 name: "ClientHelloVersionTooHigh",
4391 config: Config{
4392 MaxVersion: VersionTLS13,
4393 Bugs: ProtocolBugs{
4394 SendClientVersion: 0x0304,
4395 OmitSupportedVersions: true,
4396 },
4397 },
4398 expectedVersion: VersionTLS12,
4399 })
4400
4401 testCases = append(testCases, testCase{
4402 testType: serverTest,
4403 name: "ConflictingVersionNegotiation",
4404 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004405 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004406 SendClientVersion: VersionTLS12,
4407 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004408 },
4409 },
David Benjaminad75a662016-09-30 15:42:59 -04004410 // The extension takes precedence over the ClientHello version.
4411 expectedVersion: VersionTLS11,
4412 })
4413
4414 testCases = append(testCases, testCase{
4415 testType: serverTest,
4416 name: "ConflictingVersionNegotiation-2",
4417 config: Config{
4418 Bugs: ProtocolBugs{
4419 SendClientVersion: VersionTLS11,
4420 SendSupportedVersions: []uint16{VersionTLS12},
4421 },
4422 },
4423 // The extension takes precedence over the ClientHello version.
4424 expectedVersion: VersionTLS12,
4425 })
4426
4427 testCases = append(testCases, testCase{
4428 testType: serverTest,
4429 name: "RejectFinalTLS13",
4430 config: Config{
4431 Bugs: ProtocolBugs{
4432 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4433 },
4434 },
4435 // We currently implement a draft TLS 1.3 version. Ensure that
4436 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004437 expectedVersion: VersionTLS12,
4438 })
4439
Brian Smithf85d3232016-10-28 10:34:06 -10004440 // Test that the maximum version is selected regardless of the
4441 // client-sent order.
4442 testCases = append(testCases, testCase{
4443 testType: serverTest,
4444 name: "IgnoreClientVersionOrder",
4445 config: Config{
4446 Bugs: ProtocolBugs{
4447 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4448 },
4449 },
4450 expectedVersion: VersionTLS13,
4451 })
4452
David Benjamin95c69562016-06-29 18:15:03 -04004453 // Test for version tolerance.
4454 testCases = append(testCases, testCase{
4455 testType: serverTest,
4456 name: "MinorVersionTolerance",
4457 config: Config{
4458 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004459 SendClientVersion: 0x03ff,
4460 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004461 },
4462 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004463 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004464 })
4465 testCases = append(testCases, testCase{
4466 testType: serverTest,
4467 name: "MajorVersionTolerance",
4468 config: Config{
4469 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004470 SendClientVersion: 0x0400,
4471 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004472 },
4473 },
David Benjaminad75a662016-09-30 15:42:59 -04004474 // TLS 1.3 must be negotiated with the supported_versions
4475 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004476 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004477 })
David Benjaminad75a662016-09-30 15:42:59 -04004478 testCases = append(testCases, testCase{
4479 testType: serverTest,
4480 name: "VersionTolerance-TLS13",
4481 config: Config{
4482 Bugs: ProtocolBugs{
4483 // Although TLS 1.3 does not use
4484 // ClientHello.version, it still tolerates high
4485 // values there.
4486 SendClientVersion: 0x0400,
4487 },
4488 },
4489 expectedVersion: VersionTLS13,
4490 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004491
David Benjamin95c69562016-06-29 18:15:03 -04004492 testCases = append(testCases, testCase{
4493 protocol: dtls,
4494 testType: serverTest,
4495 name: "MinorVersionTolerance-DTLS",
4496 config: Config{
4497 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004498 SendClientVersion: 0xfe00,
4499 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004500 },
4501 },
4502 expectedVersion: VersionTLS12,
4503 })
4504 testCases = append(testCases, testCase{
4505 protocol: dtls,
4506 testType: serverTest,
4507 name: "MajorVersionTolerance-DTLS",
4508 config: Config{
4509 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004510 SendClientVersion: 0xfdff,
4511 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004512 },
4513 },
4514 expectedVersion: VersionTLS12,
4515 })
4516
4517 // Test that versions below 3.0 are rejected.
4518 testCases = append(testCases, testCase{
4519 testType: serverTest,
4520 name: "VersionTooLow",
4521 config: Config{
4522 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004523 SendClientVersion: 0x0200,
4524 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004525 },
4526 },
4527 shouldFail: true,
4528 expectedError: ":UNSUPPORTED_PROTOCOL:",
4529 })
4530 testCases = append(testCases, testCase{
4531 protocol: dtls,
4532 testType: serverTest,
4533 name: "VersionTooLow-DTLS",
4534 config: Config{
4535 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004536 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004537 },
4538 },
4539 shouldFail: true,
4540 expectedError: ":UNSUPPORTED_PROTOCOL:",
4541 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004542
David Benjamin2dc02042016-09-19 19:57:37 -04004543 testCases = append(testCases, testCase{
4544 name: "ServerBogusVersion",
4545 config: Config{
4546 Bugs: ProtocolBugs{
4547 SendServerHelloVersion: 0x1234,
4548 },
4549 },
4550 shouldFail: true,
4551 expectedError: ":UNSUPPORTED_PROTOCOL:",
4552 })
4553
David Benjamin1f61f0d2016-07-10 12:20:35 -04004554 // Test TLS 1.3's downgrade signal.
4555 testCases = append(testCases, testCase{
4556 name: "Downgrade-TLS12-Client",
4557 config: Config{
4558 Bugs: ProtocolBugs{
4559 NegotiateVersion: VersionTLS12,
4560 },
4561 },
David Benjamin592b5322016-09-30 15:15:01 -04004562 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004563 // TODO(davidben): This test should fail once TLS 1.3 is final
4564 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004565 })
4566 testCases = append(testCases, testCase{
4567 testType: serverTest,
4568 name: "Downgrade-TLS12-Server",
4569 config: Config{
4570 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004571 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004572 },
4573 },
David Benjamin592b5322016-09-30 15:15:01 -04004574 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004575 // TODO(davidben): This test should fail once TLS 1.3 is final
4576 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004577 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004578}
4579
David Benjaminaccb4542014-12-12 23:44:33 -05004580func addMinimumVersionTests() {
4581 for i, shimVers := range tlsVersions {
4582 // Assemble flags to disable all older versions on the shim.
4583 var flags []string
4584 for _, vers := range tlsVersions[:i] {
4585 flags = append(flags, vers.flag)
4586 }
4587
4588 for _, runnerVers := range tlsVersions {
4589 protocols := []protocol{tls}
4590 if runnerVers.hasDTLS && shimVers.hasDTLS {
4591 protocols = append(protocols, dtls)
4592 }
4593 for _, protocol := range protocols {
4594 suffix := shimVers.name + "-" + runnerVers.name
4595 if protocol == dtls {
4596 suffix += "-DTLS"
4597 }
4598 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4599
David Benjaminaccb4542014-12-12 23:44:33 -05004600 var expectedVersion uint16
4601 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004602 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004603 if runnerVers.version >= shimVers.version {
4604 expectedVersion = runnerVers.version
4605 } else {
4606 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004607 expectedError = ":UNSUPPORTED_PROTOCOL:"
4608 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004609 }
4610
4611 testCases = append(testCases, testCase{
4612 protocol: protocol,
4613 testType: clientTest,
4614 name: "MinimumVersion-Client-" + suffix,
4615 config: Config{
4616 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004617 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004618 // Ensure the server does not decline to
4619 // select a version (versions extension) or
4620 // cipher (some ciphers depend on versions).
4621 NegotiateVersion: runnerVers.version,
4622 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004623 },
David Benjaminaccb4542014-12-12 23:44:33 -05004624 },
David Benjamin87909c02014-12-13 01:55:01 -05004625 flags: flags,
4626 expectedVersion: expectedVersion,
4627 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004628 expectedError: expectedError,
4629 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004630 })
4631 testCases = append(testCases, testCase{
4632 protocol: protocol,
4633 testType: clientTest,
4634 name: "MinimumVersion-Client2-" + suffix,
4635 config: Config{
4636 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004637 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004638 // Ensure the server does not decline to
4639 // select a version (versions extension) or
4640 // cipher (some ciphers depend on versions).
4641 NegotiateVersion: runnerVers.version,
4642 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004643 },
David Benjaminaccb4542014-12-12 23:44:33 -05004644 },
David Benjamin87909c02014-12-13 01:55:01 -05004645 flags: []string{"-min-version", shimVersFlag},
4646 expectedVersion: expectedVersion,
4647 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004648 expectedError: expectedError,
4649 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004650 })
4651
4652 testCases = append(testCases, testCase{
4653 protocol: protocol,
4654 testType: serverTest,
4655 name: "MinimumVersion-Server-" + suffix,
4656 config: Config{
4657 MaxVersion: runnerVers.version,
4658 },
David Benjamin87909c02014-12-13 01:55:01 -05004659 flags: flags,
4660 expectedVersion: expectedVersion,
4661 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004662 expectedError: expectedError,
4663 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004664 })
4665 testCases = append(testCases, testCase{
4666 protocol: protocol,
4667 testType: serverTest,
4668 name: "MinimumVersion-Server2-" + suffix,
4669 config: Config{
4670 MaxVersion: runnerVers.version,
4671 },
David Benjamin87909c02014-12-13 01:55:01 -05004672 flags: []string{"-min-version", shimVersFlag},
4673 expectedVersion: expectedVersion,
4674 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004675 expectedError: expectedError,
4676 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004677 })
4678 }
4679 }
4680 }
4681}
4682
David Benjamine78bfde2014-09-06 12:45:15 -04004683func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004684 // TODO(davidben): Extensions, where applicable, all move their server
4685 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4686 // tests for both. Also test interaction with 0-RTT when implemented.
4687
David Benjamin97d17d92016-07-14 16:12:00 -04004688 // Repeat extensions tests all versions except SSL 3.0.
4689 for _, ver := range tlsVersions {
4690 if ver.version == VersionSSL30 {
4691 continue
4692 }
4693
David Benjamin97d17d92016-07-14 16:12:00 -04004694 // Test that duplicate extensions are rejected.
4695 testCases = append(testCases, testCase{
4696 testType: clientTest,
4697 name: "DuplicateExtensionClient-" + ver.name,
4698 config: Config{
4699 MaxVersion: ver.version,
4700 Bugs: ProtocolBugs{
4701 DuplicateExtension: true,
4702 },
David Benjamine78bfde2014-09-06 12:45:15 -04004703 },
David Benjamin97d17d92016-07-14 16:12:00 -04004704 shouldFail: true,
4705 expectedLocalError: "remote error: error decoding message",
4706 })
4707 testCases = append(testCases, testCase{
4708 testType: serverTest,
4709 name: "DuplicateExtensionServer-" + ver.name,
4710 config: Config{
4711 MaxVersion: ver.version,
4712 Bugs: ProtocolBugs{
4713 DuplicateExtension: true,
4714 },
David Benjamine78bfde2014-09-06 12:45:15 -04004715 },
David Benjamin97d17d92016-07-14 16:12:00 -04004716 shouldFail: true,
4717 expectedLocalError: "remote error: error decoding message",
4718 })
4719
4720 // Test SNI.
4721 testCases = append(testCases, testCase{
4722 testType: clientTest,
4723 name: "ServerNameExtensionClient-" + ver.name,
4724 config: Config{
4725 MaxVersion: ver.version,
4726 Bugs: ProtocolBugs{
4727 ExpectServerName: "example.com",
4728 },
David Benjamine78bfde2014-09-06 12:45:15 -04004729 },
David Benjamin97d17d92016-07-14 16:12:00 -04004730 flags: []string{"-host-name", "example.com"},
4731 })
4732 testCases = append(testCases, testCase{
4733 testType: clientTest,
4734 name: "ServerNameExtensionClientMismatch-" + ver.name,
4735 config: Config{
4736 MaxVersion: ver.version,
4737 Bugs: ProtocolBugs{
4738 ExpectServerName: "mismatch.com",
4739 },
David Benjamine78bfde2014-09-06 12:45:15 -04004740 },
David Benjamin97d17d92016-07-14 16:12:00 -04004741 flags: []string{"-host-name", "example.com"},
4742 shouldFail: true,
4743 expectedLocalError: "tls: unexpected server name",
4744 })
4745 testCases = append(testCases, testCase{
4746 testType: clientTest,
4747 name: "ServerNameExtensionClientMissing-" + ver.name,
4748 config: Config{
4749 MaxVersion: ver.version,
4750 Bugs: ProtocolBugs{
4751 ExpectServerName: "missing.com",
4752 },
David Benjamine78bfde2014-09-06 12:45:15 -04004753 },
David Benjamin97d17d92016-07-14 16:12:00 -04004754 shouldFail: true,
4755 expectedLocalError: "tls: unexpected server name",
4756 })
4757 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05004758 testType: clientTest,
4759 name: "TolerateServerNameAck-" + ver.name,
4760 config: Config{
4761 MaxVersion: ver.version,
4762 Bugs: ProtocolBugs{
4763 SendServerNameAck: true,
4764 },
4765 },
4766 flags: []string{"-host-name", "example.com"},
4767 resumeSession: true,
4768 })
4769 testCases = append(testCases, testCase{
4770 testType: clientTest,
4771 name: "UnsolicitedServerNameAck-" + ver.name,
4772 config: Config{
4773 MaxVersion: ver.version,
4774 Bugs: ProtocolBugs{
4775 SendServerNameAck: true,
4776 },
4777 },
4778 shouldFail: true,
4779 expectedError: ":UNEXPECTED_EXTENSION:",
4780 expectedLocalError: "remote error: unsupported extension",
4781 })
4782 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004783 testType: serverTest,
4784 name: "ServerNameExtensionServer-" + ver.name,
4785 config: Config{
4786 MaxVersion: ver.version,
4787 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004788 },
David Benjamin97d17d92016-07-14 16:12:00 -04004789 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004790 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004791 })
4792
4793 // Test ALPN.
4794 testCases = append(testCases, testCase{
4795 testType: clientTest,
4796 name: "ALPNClient-" + ver.name,
4797 config: Config{
4798 MaxVersion: ver.version,
4799 NextProtos: []string{"foo"},
4800 },
4801 flags: []string{
4802 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4803 "-expect-alpn", "foo",
4804 },
4805 expectedNextProto: "foo",
4806 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004807 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004808 })
4809 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004810 testType: clientTest,
4811 name: "ALPNClient-Mismatch-" + ver.name,
4812 config: Config{
4813 MaxVersion: ver.version,
4814 Bugs: ProtocolBugs{
4815 SendALPN: "baz",
4816 },
4817 },
4818 flags: []string{
4819 "-advertise-alpn", "\x03foo\x03bar",
4820 },
4821 shouldFail: true,
4822 expectedError: ":INVALID_ALPN_PROTOCOL:",
4823 expectedLocalError: "remote error: illegal parameter",
4824 })
4825 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004826 testType: serverTest,
4827 name: "ALPNServer-" + ver.name,
4828 config: Config{
4829 MaxVersion: ver.version,
4830 NextProtos: []string{"foo", "bar", "baz"},
4831 },
4832 flags: []string{
4833 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4834 "-select-alpn", "foo",
4835 },
4836 expectedNextProto: "foo",
4837 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004838 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004839 })
4840 testCases = append(testCases, testCase{
4841 testType: serverTest,
4842 name: "ALPNServer-Decline-" + ver.name,
4843 config: Config{
4844 MaxVersion: ver.version,
4845 NextProtos: []string{"foo", "bar", "baz"},
4846 },
4847 flags: []string{"-decline-alpn"},
4848 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004849 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004850 })
4851
David Benjamin25fe85b2016-08-09 20:00:32 -04004852 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4853 // called once.
4854 testCases = append(testCases, testCase{
4855 testType: serverTest,
4856 name: "ALPNServer-Async-" + ver.name,
4857 config: Config{
4858 MaxVersion: ver.version,
4859 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004860 // Prior to TLS 1.3, exercise the asynchronous session callback.
4861 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004862 },
4863 flags: []string{
4864 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4865 "-select-alpn", "foo",
4866 "-async",
4867 },
4868 expectedNextProto: "foo",
4869 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004870 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004871 })
4872
David Benjamin97d17d92016-07-14 16:12:00 -04004873 var emptyString string
4874 testCases = append(testCases, testCase{
4875 testType: clientTest,
4876 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4877 config: Config{
4878 MaxVersion: ver.version,
4879 NextProtos: []string{""},
4880 Bugs: ProtocolBugs{
4881 // A server returning an empty ALPN protocol
4882 // should be rejected.
4883 ALPNProtocol: &emptyString,
4884 },
4885 },
4886 flags: []string{
4887 "-advertise-alpn", "\x03foo",
4888 },
4889 shouldFail: true,
4890 expectedError: ":PARSE_TLSEXT:",
4891 })
4892 testCases = append(testCases, testCase{
4893 testType: serverTest,
4894 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4895 config: Config{
4896 MaxVersion: ver.version,
4897 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004898 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004899 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004900 },
David Benjamin97d17d92016-07-14 16:12:00 -04004901 flags: []string{
4902 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004903 },
David Benjamin97d17d92016-07-14 16:12:00 -04004904 shouldFail: true,
4905 expectedError: ":PARSE_TLSEXT:",
4906 })
4907
4908 // Test NPN and the interaction with ALPN.
4909 if ver.version < VersionTLS13 {
4910 // Test that the server prefers ALPN over NPN.
4911 testCases = append(testCases, testCase{
4912 testType: serverTest,
4913 name: "ALPNServer-Preferred-" + ver.name,
4914 config: Config{
4915 MaxVersion: ver.version,
4916 NextProtos: []string{"foo", "bar", "baz"},
4917 },
4918 flags: []string{
4919 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4920 "-select-alpn", "foo",
4921 "-advertise-npn", "\x03foo\x03bar\x03baz",
4922 },
4923 expectedNextProto: "foo",
4924 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004925 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004926 })
4927 testCases = append(testCases, testCase{
4928 testType: serverTest,
4929 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4930 config: Config{
4931 MaxVersion: ver.version,
4932 NextProtos: []string{"foo", "bar", "baz"},
4933 Bugs: ProtocolBugs{
4934 SwapNPNAndALPN: true,
4935 },
4936 },
4937 flags: []string{
4938 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4939 "-select-alpn", "foo",
4940 "-advertise-npn", "\x03foo\x03bar\x03baz",
4941 },
4942 expectedNextProto: "foo",
4943 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004944 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004945 })
4946
4947 // Test that negotiating both NPN and ALPN is forbidden.
4948 testCases = append(testCases, testCase{
4949 name: "NegotiateALPNAndNPN-" + ver.name,
4950 config: Config{
4951 MaxVersion: ver.version,
4952 NextProtos: []string{"foo", "bar", "baz"},
4953 Bugs: ProtocolBugs{
4954 NegotiateALPNAndNPN: true,
4955 },
4956 },
4957 flags: []string{
4958 "-advertise-alpn", "\x03foo",
4959 "-select-next-proto", "foo",
4960 },
4961 shouldFail: true,
4962 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4963 })
4964 testCases = append(testCases, testCase{
4965 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4966 config: Config{
4967 MaxVersion: ver.version,
4968 NextProtos: []string{"foo", "bar", "baz"},
4969 Bugs: ProtocolBugs{
4970 NegotiateALPNAndNPN: true,
4971 SwapNPNAndALPN: true,
4972 },
4973 },
4974 flags: []string{
4975 "-advertise-alpn", "\x03foo",
4976 "-select-next-proto", "foo",
4977 },
4978 shouldFail: true,
4979 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4980 })
David Benjamin97d17d92016-07-14 16:12:00 -04004981 }
4982
4983 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004984
4985 // Resume with a corrupt ticket.
4986 testCases = append(testCases, testCase{
4987 testType: serverTest,
4988 name: "CorruptTicket-" + ver.name,
4989 config: Config{
4990 MaxVersion: ver.version,
4991 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004992 FilterTicket: func(in []byte) ([]byte, error) {
4993 in[len(in)-1] ^= 1
4994 return in, nil
4995 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004996 },
4997 },
4998 resumeSession: true,
4999 expectResumeRejected: true,
5000 })
5001 // Test the ticket callback, with and without renewal.
5002 testCases = append(testCases, testCase{
5003 testType: serverTest,
5004 name: "TicketCallback-" + ver.name,
5005 config: Config{
5006 MaxVersion: ver.version,
5007 },
5008 resumeSession: true,
5009 flags: []string{"-use-ticket-callback"},
5010 })
5011 testCases = append(testCases, testCase{
5012 testType: serverTest,
5013 name: "TicketCallback-Renew-" + ver.name,
5014 config: Config{
5015 MaxVersion: ver.version,
5016 Bugs: ProtocolBugs{
5017 ExpectNewTicket: true,
5018 },
5019 },
5020 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5021 resumeSession: true,
5022 })
5023
5024 // Test that the ticket callback is only called once when everything before
5025 // it in the ClientHello is asynchronous. This corrupts the ticket so
5026 // certificate selection callbacks run.
5027 testCases = append(testCases, testCase{
5028 testType: serverTest,
5029 name: "TicketCallback-SingleCall-" + ver.name,
5030 config: Config{
5031 MaxVersion: ver.version,
5032 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005033 FilterTicket: func(in []byte) ([]byte, error) {
5034 in[len(in)-1] ^= 1
5035 return in, nil
5036 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005037 },
5038 },
5039 resumeSession: true,
5040 expectResumeRejected: true,
5041 flags: []string{
5042 "-use-ticket-callback",
5043 "-async",
5044 },
5045 })
5046
5047 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005048 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005049 testCases = append(testCases, testCase{
5050 testType: serverTest,
5051 name: "OversizedSessionId-" + ver.name,
5052 config: Config{
5053 MaxVersion: ver.version,
5054 Bugs: ProtocolBugs{
5055 OversizedSessionId: true,
5056 },
5057 },
5058 resumeSession: true,
5059 shouldFail: true,
5060 expectedError: ":DECODE_ERROR:",
5061 })
5062 }
5063
5064 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5065 // are ignored.
5066 if ver.hasDTLS {
5067 testCases = append(testCases, testCase{
5068 protocol: dtls,
5069 name: "SRTP-Client-" + ver.name,
5070 config: Config{
5071 MaxVersion: ver.version,
5072 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5073 },
5074 flags: []string{
5075 "-srtp-profiles",
5076 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5077 },
5078 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5079 })
5080 testCases = append(testCases, testCase{
5081 protocol: dtls,
5082 testType: serverTest,
5083 name: "SRTP-Server-" + ver.name,
5084 config: Config{
5085 MaxVersion: ver.version,
5086 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5087 },
5088 flags: []string{
5089 "-srtp-profiles",
5090 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5091 },
5092 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5093 })
5094 // Test that the MKI is ignored.
5095 testCases = append(testCases, testCase{
5096 protocol: dtls,
5097 testType: serverTest,
5098 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5099 config: Config{
5100 MaxVersion: ver.version,
5101 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5102 Bugs: ProtocolBugs{
5103 SRTPMasterKeyIdentifer: "bogus",
5104 },
5105 },
5106 flags: []string{
5107 "-srtp-profiles",
5108 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5109 },
5110 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5111 })
5112 // Test that SRTP isn't negotiated on the server if there were
5113 // no matching profiles.
5114 testCases = append(testCases, testCase{
5115 protocol: dtls,
5116 testType: serverTest,
5117 name: "SRTP-Server-NoMatch-" + ver.name,
5118 config: Config{
5119 MaxVersion: ver.version,
5120 SRTPProtectionProfiles: []uint16{100, 101, 102},
5121 },
5122 flags: []string{
5123 "-srtp-profiles",
5124 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5125 },
5126 expectedSRTPProtectionProfile: 0,
5127 })
5128 // Test that the server returning an invalid SRTP profile is
5129 // flagged as an error by the client.
5130 testCases = append(testCases, testCase{
5131 protocol: dtls,
5132 name: "SRTP-Client-NoMatch-" + ver.name,
5133 config: Config{
5134 MaxVersion: ver.version,
5135 Bugs: ProtocolBugs{
5136 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5137 },
5138 },
5139 flags: []string{
5140 "-srtp-profiles",
5141 "SRTP_AES128_CM_SHA1_80",
5142 },
5143 shouldFail: true,
5144 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5145 })
5146 }
5147
5148 // Test SCT list.
5149 testCases = append(testCases, testCase{
5150 name: "SignedCertificateTimestampList-Client-" + ver.name,
5151 testType: clientTest,
5152 config: Config{
5153 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005154 },
David Benjamin97d17d92016-07-14 16:12:00 -04005155 flags: []string{
5156 "-enable-signed-cert-timestamps",
5157 "-expect-signed-cert-timestamps",
5158 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005159 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005160 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005161 })
David Benjamindaa88502016-10-04 16:32:16 -04005162
Adam Langleycfa08c32016-11-17 13:21:27 -08005163 var differentSCTList []byte
5164 differentSCTList = append(differentSCTList, testSCTList...)
5165 differentSCTList[len(differentSCTList)-1] ^= 1
5166
David Benjamindaa88502016-10-04 16:32:16 -04005167 // The SCT extension did not specify that it must only be sent on resumption as it
5168 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005169 testCases = append(testCases, testCase{
5170 name: "SendSCTListOnResume-" + ver.name,
5171 config: Config{
5172 MaxVersion: ver.version,
5173 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005174 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005175 },
David Benjamind98452d2015-06-16 14:16:23 -04005176 },
David Benjamin97d17d92016-07-14 16:12:00 -04005177 flags: []string{
5178 "-enable-signed-cert-timestamps",
5179 "-expect-signed-cert-timestamps",
5180 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005181 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005182 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005183 })
David Benjamindaa88502016-10-04 16:32:16 -04005184
David Benjamin97d17d92016-07-14 16:12:00 -04005185 testCases = append(testCases, testCase{
5186 name: "SignedCertificateTimestampList-Server-" + ver.name,
5187 testType: serverTest,
5188 config: Config{
5189 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005190 },
David Benjamin97d17d92016-07-14 16:12:00 -04005191 flags: []string{
5192 "-signed-cert-timestamps",
5193 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005194 },
David Benjamin97d17d92016-07-14 16:12:00 -04005195 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005196 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005197 })
David Benjamin53210cb2016-11-16 09:01:48 +09005198
Adam Langleycfa08c32016-11-17 13:21:27 -08005199 emptySCTListCert := *testCerts[0].cert
5200 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5201
5202 // Test empty SCT list.
5203 testCases = append(testCases, testCase{
5204 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5205 testType: clientTest,
5206 config: Config{
5207 MaxVersion: ver.version,
5208 Certificates: []Certificate{emptySCTListCert},
5209 },
5210 flags: []string{
5211 "-enable-signed-cert-timestamps",
5212 },
5213 shouldFail: true,
5214 expectedError: ":ERROR_PARSING_EXTENSION:",
5215 })
5216
5217 emptySCTCert := *testCerts[0].cert
5218 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5219
5220 // Test empty SCT in non-empty list.
5221 testCases = append(testCases, testCase{
5222 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5223 testType: clientTest,
5224 config: Config{
5225 MaxVersion: ver.version,
5226 Certificates: []Certificate{emptySCTCert},
5227 },
5228 flags: []string{
5229 "-enable-signed-cert-timestamps",
5230 },
5231 shouldFail: true,
5232 expectedError: ":ERROR_PARSING_EXTENSION:",
5233 })
5234
David Benjamin53210cb2016-11-16 09:01:48 +09005235 // Test that certificate-related extensions are not sent unsolicited.
5236 testCases = append(testCases, testCase{
5237 testType: serverTest,
5238 name: "UnsolicitedCertificateExtensions-" + ver.name,
5239 config: Config{
5240 MaxVersion: ver.version,
5241 Bugs: ProtocolBugs{
5242 NoOCSPStapling: true,
5243 NoSignedCertificateTimestamps: true,
5244 },
5245 },
5246 flags: []string{
5247 "-ocsp-response",
5248 base64.StdEncoding.EncodeToString(testOCSPResponse),
5249 "-signed-cert-timestamps",
5250 base64.StdEncoding.EncodeToString(testSCTList),
5251 },
5252 })
David Benjamin97d17d92016-07-14 16:12:00 -04005253 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005254
Paul Lietar4fac72e2015-09-09 13:44:55 +01005255 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005256 testType: clientTest,
5257 name: "ClientHelloPadding",
5258 config: Config{
5259 Bugs: ProtocolBugs{
5260 RequireClientHelloSize: 512,
5261 },
5262 },
5263 // This hostname just needs to be long enough to push the
5264 // ClientHello into F5's danger zone between 256 and 511 bytes
5265 // long.
5266 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5267 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005268
5269 // Extensions should not function in SSL 3.0.
5270 testCases = append(testCases, testCase{
5271 testType: serverTest,
5272 name: "SSLv3Extensions-NoALPN",
5273 config: Config{
5274 MaxVersion: VersionSSL30,
5275 NextProtos: []string{"foo", "bar", "baz"},
5276 },
5277 flags: []string{
5278 "-select-alpn", "foo",
5279 },
5280 expectNoNextProto: true,
5281 })
5282
5283 // Test session tickets separately as they follow a different codepath.
5284 testCases = append(testCases, testCase{
5285 testType: serverTest,
5286 name: "SSLv3Extensions-NoTickets",
5287 config: Config{
5288 MaxVersion: VersionSSL30,
5289 Bugs: ProtocolBugs{
5290 // Historically, session tickets in SSL 3.0
5291 // failed in different ways depending on whether
5292 // the client supported renegotiation_info.
5293 NoRenegotiationInfo: true,
5294 },
5295 },
5296 resumeSession: true,
5297 })
5298 testCases = append(testCases, testCase{
5299 testType: serverTest,
5300 name: "SSLv3Extensions-NoTickets2",
5301 config: Config{
5302 MaxVersion: VersionSSL30,
5303 },
5304 resumeSession: true,
5305 })
5306
5307 // But SSL 3.0 does send and process renegotiation_info.
5308 testCases = append(testCases, testCase{
5309 testType: serverTest,
5310 name: "SSLv3Extensions-RenegotiationInfo",
5311 config: Config{
5312 MaxVersion: VersionSSL30,
5313 Bugs: ProtocolBugs{
5314 RequireRenegotiationInfo: true,
5315 },
5316 },
David Benjamind2610042017-01-03 10:49:28 -05005317 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005318 })
5319 testCases = append(testCases, testCase{
5320 testType: serverTest,
5321 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5322 config: Config{
5323 MaxVersion: VersionSSL30,
5324 Bugs: ProtocolBugs{
5325 NoRenegotiationInfo: true,
5326 SendRenegotiationSCSV: true,
5327 RequireRenegotiationInfo: true,
5328 },
5329 },
David Benjamind2610042017-01-03 10:49:28 -05005330 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005331 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005332
5333 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5334 // in ServerHello.
5335 testCases = append(testCases, testCase{
5336 name: "NPN-Forbidden-TLS13",
5337 config: Config{
5338 MaxVersion: VersionTLS13,
5339 NextProtos: []string{"foo"},
5340 Bugs: ProtocolBugs{
5341 NegotiateNPNAtAllVersions: true,
5342 },
5343 },
5344 flags: []string{"-select-next-proto", "foo"},
5345 shouldFail: true,
5346 expectedError: ":ERROR_PARSING_EXTENSION:",
5347 })
5348 testCases = append(testCases, testCase{
5349 name: "EMS-Forbidden-TLS13",
5350 config: Config{
5351 MaxVersion: VersionTLS13,
5352 Bugs: ProtocolBugs{
5353 NegotiateEMSAtAllVersions: true,
5354 },
5355 },
5356 shouldFail: true,
5357 expectedError: ":ERROR_PARSING_EXTENSION:",
5358 })
5359 testCases = append(testCases, testCase{
5360 name: "RenegotiationInfo-Forbidden-TLS13",
5361 config: Config{
5362 MaxVersion: VersionTLS13,
5363 Bugs: ProtocolBugs{
5364 NegotiateRenegotiationInfoAtAllVersions: true,
5365 },
5366 },
5367 shouldFail: true,
5368 expectedError: ":ERROR_PARSING_EXTENSION:",
5369 })
5370 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005371 name: "Ticket-Forbidden-TLS13",
5372 config: Config{
5373 MaxVersion: VersionTLS12,
5374 },
5375 resumeConfig: &Config{
5376 MaxVersion: VersionTLS13,
5377 Bugs: ProtocolBugs{
5378 AdvertiseTicketExtension: true,
5379 },
5380 },
5381 resumeSession: true,
5382 shouldFail: true,
5383 expectedError: ":ERROR_PARSING_EXTENSION:",
5384 })
5385
5386 // Test that illegal extensions in TLS 1.3 are declined by the server if
5387 // offered in ClientHello. The runner's server will fail if this occurs,
5388 // so we exercise the offering path. (EMS and Renegotiation Info are
5389 // implicit in every test.)
5390 testCases = append(testCases, testCase{
5391 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005392 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005393 config: Config{
5394 MaxVersion: VersionTLS13,
5395 NextProtos: []string{"bar"},
5396 },
5397 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5398 })
David Benjamin196df5b2016-09-21 16:23:27 -04005399
David Benjamindaa88502016-10-04 16:32:16 -04005400 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5401 // tolerated.
5402 testCases = append(testCases, testCase{
5403 name: "SendOCSPResponseOnResume-TLS12",
5404 config: Config{
5405 MaxVersion: VersionTLS12,
5406 Bugs: ProtocolBugs{
5407 SendOCSPResponseOnResume: []byte("bogus"),
5408 },
5409 },
5410 flags: []string{
5411 "-enable-ocsp-stapling",
5412 "-expect-ocsp-response",
5413 base64.StdEncoding.EncodeToString(testOCSPResponse),
5414 },
5415 resumeSession: true,
5416 })
5417
David Benjamindaa88502016-10-04 16:32:16 -04005418 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005419 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005420 config: Config{
5421 MaxVersion: VersionTLS13,
5422 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005423 SendExtensionOnCertificate: testOCSPExtension,
5424 },
5425 },
5426 shouldFail: true,
5427 expectedError: ":UNEXPECTED_EXTENSION:",
5428 })
5429
5430 testCases = append(testCases, testCase{
5431 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5432 config: Config{
5433 MaxVersion: VersionTLS13,
5434 Bugs: ProtocolBugs{
5435 SendExtensionOnCertificate: testSCTExtension,
5436 },
5437 },
5438 shouldFail: true,
5439 expectedError: ":UNEXPECTED_EXTENSION:",
5440 })
5441
5442 // Test that extensions on client certificates are never accepted.
5443 testCases = append(testCases, testCase{
5444 name: "SendExtensionOnClientCertificate-TLS13",
5445 testType: serverTest,
5446 config: Config{
5447 MaxVersion: VersionTLS13,
5448 Certificates: []Certificate{rsaCertificate},
5449 Bugs: ProtocolBugs{
5450 SendExtensionOnCertificate: testOCSPExtension,
5451 },
5452 },
5453 flags: []string{
5454 "-enable-ocsp-stapling",
5455 "-require-any-client-certificate",
5456 },
5457 shouldFail: true,
5458 expectedError: ":UNEXPECTED_EXTENSION:",
5459 })
5460
5461 testCases = append(testCases, testCase{
5462 name: "SendUnknownExtensionOnCertificate-TLS13",
5463 config: Config{
5464 MaxVersion: VersionTLS13,
5465 Bugs: ProtocolBugs{
5466 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5467 },
5468 },
5469 shouldFail: true,
5470 expectedError: ":UNEXPECTED_EXTENSION:",
5471 })
5472
Adam Langleycfa08c32016-11-17 13:21:27 -08005473 var differentSCTList []byte
5474 differentSCTList = append(differentSCTList, testSCTList...)
5475 differentSCTList[len(differentSCTList)-1] ^= 1
5476
Steven Valdeza833c352016-11-01 13:39:36 -04005477 // Test that extensions on intermediates are allowed but ignored.
5478 testCases = append(testCases, testCase{
5479 name: "IgnoreExtensionsOnIntermediates-TLS13",
5480 config: Config{
5481 MaxVersion: VersionTLS13,
5482 Certificates: []Certificate{rsaChainCertificate},
5483 Bugs: ProtocolBugs{
5484 // Send different values on the intermediate. This tests
5485 // the intermediate's extensions do not override the
5486 // leaf's.
5487 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005488 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005489 },
5490 },
5491 flags: []string{
5492 "-enable-ocsp-stapling",
5493 "-expect-ocsp-response",
5494 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005495 "-enable-signed-cert-timestamps",
5496 "-expect-signed-cert-timestamps",
5497 base64.StdEncoding.EncodeToString(testSCTList),
5498 },
5499 resumeSession: true,
5500 })
5501
5502 // Test that extensions are not sent on intermediates when configured
5503 // only for a leaf.
5504 testCases = append(testCases, testCase{
5505 testType: serverTest,
5506 name: "SendNoExtensionsOnIntermediate-TLS13",
5507 config: Config{
5508 MaxVersion: VersionTLS13,
5509 Bugs: ProtocolBugs{
5510 ExpectNoExtensionsOnIntermediate: true,
5511 },
5512 },
5513 flags: []string{
5514 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5515 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5516 "-ocsp-response",
5517 base64.StdEncoding.EncodeToString(testOCSPResponse),
5518 "-signed-cert-timestamps",
5519 base64.StdEncoding.EncodeToString(testSCTList),
5520 },
5521 })
5522
5523 // Test that extensions are not sent on client certificates.
5524 testCases = append(testCases, testCase{
5525 name: "SendNoClientCertificateExtensions-TLS13",
5526 config: Config{
5527 MaxVersion: VersionTLS13,
5528 ClientAuth: RequireAnyClientCert,
5529 },
5530 flags: []string{
5531 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5532 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5533 "-ocsp-response",
5534 base64.StdEncoding.EncodeToString(testOCSPResponse),
5535 "-signed-cert-timestamps",
5536 base64.StdEncoding.EncodeToString(testSCTList),
5537 },
5538 })
5539
5540 testCases = append(testCases, testCase{
5541 name: "SendDuplicateExtensionsOnCerts-TLS13",
5542 config: Config{
5543 MaxVersion: VersionTLS13,
5544 Bugs: ProtocolBugs{
5545 SendDuplicateCertExtensions: true,
5546 },
5547 },
5548 flags: []string{
5549 "-enable-ocsp-stapling",
5550 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005551 },
5552 resumeSession: true,
5553 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005554 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005555 })
Adam Langley9b885c52016-11-18 14:21:03 -08005556
5557 testCases = append(testCases, testCase{
5558 name: "SignedCertificateTimestampListInvalid-Server",
5559 testType: serverTest,
5560 flags: []string{
5561 "-signed-cert-timestamps",
5562 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5563 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005564 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005565 expectedError: ":INVALID_SCT_LIST:",
5566 })
David Benjamine78bfde2014-09-06 12:45:15 -04005567}
5568
David Benjamin01fe8202014-09-24 15:21:44 -04005569func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005570 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005571 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005572 // SSL 3.0 does not have tickets and TLS 1.3 does not
5573 // have session IDs, so skip their cross-resumption
5574 // tests.
5575 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5576 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5577 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005578 }
5579
David Benjamin8b8c0062014-11-23 02:47:52 -05005580 protocols := []protocol{tls}
5581 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5582 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005583 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005584 for _, protocol := range protocols {
5585 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5586 if protocol == dtls {
5587 suffix += "-DTLS"
5588 }
5589
David Benjaminece3de92015-03-16 18:02:20 -04005590 if sessionVers.version == resumeVers.version {
5591 testCases = append(testCases, testCase{
5592 protocol: protocol,
5593 name: "Resume-Client" + suffix,
5594 resumeSession: true,
5595 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005596 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005597 Bugs: ProtocolBugs{
5598 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5599 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5600 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005601 },
David Benjaminece3de92015-03-16 18:02:20 -04005602 expectedVersion: sessionVers.version,
5603 expectedResumeVersion: resumeVers.version,
5604 })
5605 } else {
David Benjamin405da482016-08-08 17:25:07 -04005606 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5607
5608 // Offering a TLS 1.3 session sends an empty session ID, so
5609 // there is no way to convince a non-lookahead client the
5610 // session was resumed. It will appear to the client that a
5611 // stray ChangeCipherSpec was sent.
5612 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5613 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005614 }
5615
David Benjaminece3de92015-03-16 18:02:20 -04005616 testCases = append(testCases, testCase{
5617 protocol: protocol,
5618 name: "Resume-Client-Mismatch" + suffix,
5619 resumeSession: true,
5620 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005621 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005622 },
David Benjaminece3de92015-03-16 18:02:20 -04005623 expectedVersion: sessionVers.version,
5624 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005625 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005626 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005627 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005628 },
5629 },
5630 expectedResumeVersion: resumeVers.version,
5631 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005632 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005633 })
5634 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005635
5636 testCases = append(testCases, testCase{
5637 protocol: protocol,
5638 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005639 resumeSession: true,
5640 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005641 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005642 },
5643 expectedVersion: sessionVers.version,
5644 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005645 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005646 },
5647 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005648 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005649 expectedResumeVersion: resumeVers.version,
5650 })
5651
David Benjamin8b8c0062014-11-23 02:47:52 -05005652 testCases = append(testCases, testCase{
5653 protocol: protocol,
5654 testType: serverTest,
5655 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005656 resumeSession: true,
5657 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005658 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005659 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005660 expectedVersion: sessionVers.version,
5661 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005662 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005663 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005664 Bugs: ProtocolBugs{
5665 SendBothTickets: true,
5666 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005667 },
5668 expectedResumeVersion: resumeVers.version,
5669 })
5670 }
David Benjamin01fe8202014-09-24 15:21:44 -04005671 }
5672 }
David Benjaminece3de92015-03-16 18:02:20 -04005673
David Benjamin4199b0d2016-11-01 13:58:25 -04005674 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005675 testCases = append(testCases, testCase{
5676 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005677 name: "ShimTicketRewritable",
5678 resumeSession: true,
5679 config: Config{
5680 MaxVersion: VersionTLS12,
5681 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5682 Bugs: ProtocolBugs{
5683 FilterTicket: func(in []byte) ([]byte, error) {
5684 in, err := SetShimTicketVersion(in, VersionTLS12)
5685 if err != nil {
5686 return nil, err
5687 }
5688 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5689 },
5690 },
5691 },
5692 flags: []string{
5693 "-ticket-key",
5694 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5695 },
5696 })
5697
5698 // Resumptions are declined if the version does not match.
5699 testCases = append(testCases, testCase{
5700 testType: serverTest,
5701 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005702 resumeSession: true,
5703 config: Config{
5704 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005705 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005706 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005707 FilterTicket: func(in []byte) ([]byte, error) {
5708 return SetShimTicketVersion(in, VersionTLS13)
5709 },
5710 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005711 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005712 flags: []string{
5713 "-ticket-key",
5714 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5715 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005716 expectResumeRejected: true,
5717 })
5718
5719 testCases = append(testCases, testCase{
5720 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005721 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005722 resumeSession: true,
5723 config: Config{
5724 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005725 Bugs: ProtocolBugs{
5726 FilterTicket: func(in []byte) ([]byte, error) {
5727 return SetShimTicketVersion(in, VersionTLS12)
5728 },
5729 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005730 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005731 flags: []string{
5732 "-ticket-key",
5733 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5734 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005735 expectResumeRejected: true,
5736 })
5737
David Benjamin4199b0d2016-11-01 13:58:25 -04005738 // Resumptions are declined if the cipher is invalid or disabled.
5739 testCases = append(testCases, testCase{
5740 testType: serverTest,
5741 name: "Resume-Server-DeclineBadCipher",
5742 resumeSession: true,
5743 config: Config{
5744 MaxVersion: VersionTLS12,
5745 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005746 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005747 FilterTicket: func(in []byte) ([]byte, error) {
5748 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5749 },
5750 },
5751 },
5752 flags: []string{
5753 "-ticket-key",
5754 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5755 },
5756 expectResumeRejected: true,
5757 })
5758
5759 testCases = append(testCases, testCase{
5760 testType: serverTest,
5761 name: "Resume-Server-DeclineBadCipher-2",
5762 resumeSession: true,
5763 config: Config{
5764 MaxVersion: VersionTLS12,
5765 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005766 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005767 FilterTicket: func(in []byte) ([]byte, error) {
5768 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5769 },
5770 },
5771 },
5772 flags: []string{
5773 "-cipher", "AES128",
5774 "-ticket-key",
5775 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5776 },
5777 expectResumeRejected: true,
5778 })
5779
David Benjaminf01f42a2016-11-16 19:05:33 +09005780 // Sessions are not resumed if they do not use the preferred cipher.
5781 testCases = append(testCases, testCase{
5782 testType: serverTest,
5783 name: "Resume-Server-CipherNotPreferred",
5784 resumeSession: true,
5785 config: Config{
5786 MaxVersion: VersionTLS12,
5787 Bugs: ProtocolBugs{
5788 ExpectNewTicket: true,
5789 FilterTicket: func(in []byte) ([]byte, error) {
5790 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5791 },
5792 },
5793 },
5794 flags: []string{
5795 "-ticket-key",
5796 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5797 },
5798 shouldFail: false,
5799 expectResumeRejected: true,
5800 })
5801
5802 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5803 // PRF hashes match, but BoringSSL will always decline such resumptions.
5804 testCases = append(testCases, testCase{
5805 testType: serverTest,
5806 name: "Resume-Server-CipherNotPreferred-TLS13",
5807 resumeSession: true,
5808 config: Config{
5809 MaxVersion: VersionTLS13,
5810 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5811 Bugs: ProtocolBugs{
5812 FilterTicket: func(in []byte) ([]byte, error) {
5813 // If the client (runner) offers ChaCha20-Poly1305 first, the
5814 // server (shim) always prefers it. Switch it to AES-GCM.
5815 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5816 },
5817 },
5818 },
5819 flags: []string{
5820 "-ticket-key",
5821 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5822 },
5823 shouldFail: false,
5824 expectResumeRejected: true,
5825 })
5826
5827 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005828 testCases = append(testCases, testCase{
5829 testType: serverTest,
5830 name: "Resume-Server-DeclineBadCipher-TLS13",
5831 resumeSession: true,
5832 config: Config{
5833 MaxVersion: VersionTLS13,
5834 Bugs: ProtocolBugs{
5835 FilterTicket: func(in []byte) ([]byte, error) {
5836 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5837 },
5838 },
5839 },
5840 flags: []string{
5841 "-ticket-key",
5842 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5843 },
5844 expectResumeRejected: true,
5845 })
5846
David Benjaminf01f42a2016-11-16 19:05:33 +09005847 // If the client does not offer the cipher from the session, decline to
5848 // resume. Clients are forbidden from doing this, but BoringSSL selects
5849 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005850 testCases = append(testCases, testCase{
5851 testType: serverTest,
5852 name: "Resume-Server-UnofferedCipher",
5853 resumeSession: true,
5854 config: Config{
5855 MaxVersion: VersionTLS12,
5856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5857 },
5858 resumeConfig: &Config{
5859 MaxVersion: VersionTLS12,
5860 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5861 Bugs: ProtocolBugs{
5862 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5863 },
5864 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005865 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005866 })
5867
David Benjaminf01f42a2016-11-16 19:05:33 +09005868 // In TLS 1.3, clients may advertise a cipher list which does not
5869 // include the selected cipher. Test that we tolerate this. Servers may
5870 // resume at another cipher if the PRF matches, but BoringSSL will
5871 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005872 testCases = append(testCases, testCase{
5873 testType: serverTest,
5874 name: "Resume-Server-UnofferedCipher-TLS13",
5875 resumeSession: true,
5876 config: Config{
5877 MaxVersion: VersionTLS13,
5878 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5879 },
5880 resumeConfig: &Config{
5881 MaxVersion: VersionTLS13,
5882 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5883 Bugs: ProtocolBugs{
5884 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5885 },
5886 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005887 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005888 })
5889
David Benjamin4199b0d2016-11-01 13:58:25 -04005890 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005891 testCases = append(testCases, testCase{
5892 name: "Resume-Client-CipherMismatch",
5893 resumeSession: true,
5894 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005895 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005896 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5897 },
5898 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005899 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005900 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5901 Bugs: ProtocolBugs{
5902 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5903 },
5904 },
5905 shouldFail: true,
5906 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5907 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005908
David Benjamine1cc35e2016-11-16 16:25:58 +09005909 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5910 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005911 testCases = append(testCases, testCase{
5912 name: "Resume-Client-CipherMismatch-TLS13",
5913 resumeSession: true,
5914 config: Config{
5915 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005916 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005917 },
5918 resumeConfig: &Config{
5919 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005920 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5921 },
5922 })
5923
5924 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5925 testCases = append(testCases, testCase{
5926 name: "Resume-Client-PRFMismatch-TLS13",
5927 resumeSession: true,
5928 config: Config{
5929 MaxVersion: VersionTLS13,
5930 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5931 },
5932 resumeConfig: &Config{
5933 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005934 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005935 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005936 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005937 },
5938 },
5939 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005940 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005941 })
Steven Valdeza833c352016-11-01 13:39:36 -04005942
5943 testCases = append(testCases, testCase{
5944 testType: serverTest,
5945 name: "Resume-Server-BinderWrongLength",
5946 resumeSession: true,
5947 config: Config{
5948 MaxVersion: VersionTLS13,
5949 Bugs: ProtocolBugs{
5950 SendShortPSKBinder: true,
5951 },
5952 },
5953 shouldFail: true,
5954 expectedLocalError: "remote error: error decrypting message",
5955 expectedError: ":DIGEST_CHECK_FAILED:",
5956 })
5957
5958 testCases = append(testCases, testCase{
5959 testType: serverTest,
5960 name: "Resume-Server-NoPSKBinder",
5961 resumeSession: true,
5962 config: Config{
5963 MaxVersion: VersionTLS13,
5964 Bugs: ProtocolBugs{
5965 SendNoPSKBinder: true,
5966 },
5967 },
5968 shouldFail: true,
5969 expectedLocalError: "remote error: error decoding message",
5970 expectedError: ":DECODE_ERROR:",
5971 })
5972
5973 testCases = append(testCases, testCase{
5974 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005975 name: "Resume-Server-ExtraPSKBinder",
5976 resumeSession: true,
5977 config: Config{
5978 MaxVersion: VersionTLS13,
5979 Bugs: ProtocolBugs{
5980 SendExtraPSKBinder: true,
5981 },
5982 },
5983 shouldFail: true,
5984 expectedLocalError: "remote error: illegal parameter",
5985 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5986 })
5987
5988 testCases = append(testCases, testCase{
5989 testType: serverTest,
5990 name: "Resume-Server-ExtraIdentityNoBinder",
5991 resumeSession: true,
5992 config: Config{
5993 MaxVersion: VersionTLS13,
5994 Bugs: ProtocolBugs{
5995 ExtraPSKIdentity: true,
5996 },
5997 },
5998 shouldFail: true,
5999 expectedLocalError: "remote error: illegal parameter",
6000 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6001 })
6002
6003 testCases = append(testCases, testCase{
6004 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006005 name: "Resume-Server-InvalidPSKBinder",
6006 resumeSession: true,
6007 config: Config{
6008 MaxVersion: VersionTLS13,
6009 Bugs: ProtocolBugs{
6010 SendInvalidPSKBinder: true,
6011 },
6012 },
6013 shouldFail: true,
6014 expectedLocalError: "remote error: error decrypting message",
6015 expectedError: ":DIGEST_CHECK_FAILED:",
6016 })
6017
6018 testCases = append(testCases, testCase{
6019 testType: serverTest,
6020 name: "Resume-Server-PSKBinderFirstExtension",
6021 resumeSession: true,
6022 config: Config{
6023 MaxVersion: VersionTLS13,
6024 Bugs: ProtocolBugs{
6025 PSKBinderFirst: true,
6026 },
6027 },
6028 shouldFail: true,
6029 expectedLocalError: "remote error: illegal parameter",
6030 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6031 })
David Benjamin01fe8202014-09-24 15:21:44 -04006032}
6033
Adam Langley2ae77d22014-10-28 17:29:33 -07006034func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006035 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006036 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006037 testType: serverTest,
6038 name: "Renegotiate-Server-Forbidden",
6039 config: Config{
6040 MaxVersion: VersionTLS12,
6041 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006042 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006043 shouldFail: true,
6044 expectedError: ":NO_RENEGOTIATION:",
6045 expectedLocalError: "remote error: no renegotiation",
6046 })
Adam Langley5021b222015-06-12 18:27:58 -07006047 // The server shouldn't echo the renegotiation extension unless
6048 // requested by the client.
6049 testCases = append(testCases, testCase{
6050 testType: serverTest,
6051 name: "Renegotiate-Server-NoExt",
6052 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006053 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006054 Bugs: ProtocolBugs{
6055 NoRenegotiationInfo: true,
6056 RequireRenegotiationInfo: true,
6057 },
6058 },
6059 shouldFail: true,
6060 expectedLocalError: "renegotiation extension missing",
6061 })
6062 // The renegotiation SCSV should be sufficient for the server to echo
6063 // the extension.
6064 testCases = append(testCases, testCase{
6065 testType: serverTest,
6066 name: "Renegotiate-Server-NoExt-SCSV",
6067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006068 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006069 Bugs: ProtocolBugs{
6070 NoRenegotiationInfo: true,
6071 SendRenegotiationSCSV: true,
6072 RequireRenegotiationInfo: true,
6073 },
6074 },
6075 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006076 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006077 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006078 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006079 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006080 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006081 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006082 },
6083 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006084 renegotiate: 1,
6085 flags: []string{
6086 "-renegotiate-freely",
6087 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006088 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006089 },
David Benjamincdea40c2015-03-19 14:09:43 -04006090 })
6091 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006092 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006093 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006094 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006095 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006096 Bugs: ProtocolBugs{
6097 EmptyRenegotiationInfo: true,
6098 },
6099 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006100 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006101 shouldFail: true,
6102 expectedError: ":RENEGOTIATION_MISMATCH:",
6103 })
6104 testCases = append(testCases, testCase{
6105 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006106 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006107 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006108 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006109 Bugs: ProtocolBugs{
6110 BadRenegotiationInfo: true,
6111 },
6112 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006113 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006114 shouldFail: true,
6115 expectedError: ":RENEGOTIATION_MISMATCH:",
6116 })
6117 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006118 name: "Renegotiate-Client-Downgrade",
6119 renegotiate: 1,
6120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006121 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006122 Bugs: ProtocolBugs{
6123 NoRenegotiationInfoAfterInitial: true,
6124 },
6125 },
6126 flags: []string{"-renegotiate-freely"},
6127 shouldFail: true,
6128 expectedError: ":RENEGOTIATION_MISMATCH:",
6129 })
6130 testCases = append(testCases, testCase{
6131 name: "Renegotiate-Client-Upgrade",
6132 renegotiate: 1,
6133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006134 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006135 Bugs: ProtocolBugs{
6136 NoRenegotiationInfoInInitial: true,
6137 },
6138 },
6139 flags: []string{"-renegotiate-freely"},
6140 shouldFail: true,
6141 expectedError: ":RENEGOTIATION_MISMATCH:",
6142 })
6143 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006144 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006145 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006147 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006148 Bugs: ProtocolBugs{
6149 NoRenegotiationInfo: true,
6150 },
6151 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006152 flags: []string{
6153 "-renegotiate-freely",
6154 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006155 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006156 },
David Benjamincff0b902015-05-15 23:09:47 -04006157 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006158
6159 // Test that the server may switch ciphers on renegotiation without
6160 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006161 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006162 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006163 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006164 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006165 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006166 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006167 },
6168 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006169 flags: []string{
6170 "-renegotiate-freely",
6171 "-expect-total-renegotiations", "1",
6172 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006173 })
6174 testCases = append(testCases, testCase{
6175 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006176 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006177 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006178 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006179 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6180 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006181 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006182 flags: []string{
6183 "-renegotiate-freely",
6184 "-expect-total-renegotiations", "1",
6185 },
David Benjaminb16346b2015-04-08 19:16:58 -04006186 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006187
6188 // Test that the server may not switch versions on renegotiation.
6189 testCases = append(testCases, testCase{
6190 name: "Renegotiate-Client-SwitchVersion",
6191 config: Config{
6192 MaxVersion: VersionTLS12,
6193 // Pick a cipher which exists at both versions.
6194 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6195 Bugs: ProtocolBugs{
6196 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006197 // Avoid failing early at the record layer.
6198 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006199 },
6200 },
6201 renegotiate: 1,
6202 flags: []string{
6203 "-renegotiate-freely",
6204 "-expect-total-renegotiations", "1",
6205 },
6206 shouldFail: true,
6207 expectedError: ":WRONG_SSL_VERSION:",
6208 })
6209
David Benjaminb16346b2015-04-08 19:16:58 -04006210 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006211 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006212 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006213 config: Config{
6214 MaxVersion: VersionTLS10,
6215 Bugs: ProtocolBugs{
6216 RequireSameRenegoClientVersion: true,
6217 },
6218 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006219 flags: []string{
6220 "-renegotiate-freely",
6221 "-expect-total-renegotiations", "1",
6222 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006223 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006224 testCases = append(testCases, testCase{
6225 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006226 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006227 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006228 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006229 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6230 NextProtos: []string{"foo"},
6231 },
6232 flags: []string{
6233 "-false-start",
6234 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006235 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006236 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006237 },
6238 shimWritesFirst: true,
6239 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006240
6241 // Client-side renegotiation controls.
6242 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006243 name: "Renegotiate-Client-Forbidden-1",
6244 config: Config{
6245 MaxVersion: VersionTLS12,
6246 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006247 renegotiate: 1,
6248 shouldFail: true,
6249 expectedError: ":NO_RENEGOTIATION:",
6250 expectedLocalError: "remote error: no renegotiation",
6251 })
6252 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006253 name: "Renegotiate-Client-Once-1",
6254 config: Config{
6255 MaxVersion: VersionTLS12,
6256 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006257 renegotiate: 1,
6258 flags: []string{
6259 "-renegotiate-once",
6260 "-expect-total-renegotiations", "1",
6261 },
6262 })
6263 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006264 name: "Renegotiate-Client-Freely-1",
6265 config: Config{
6266 MaxVersion: VersionTLS12,
6267 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006268 renegotiate: 1,
6269 flags: []string{
6270 "-renegotiate-freely",
6271 "-expect-total-renegotiations", "1",
6272 },
6273 })
6274 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006275 name: "Renegotiate-Client-Once-2",
6276 config: Config{
6277 MaxVersion: VersionTLS12,
6278 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006279 renegotiate: 2,
6280 flags: []string{"-renegotiate-once"},
6281 shouldFail: true,
6282 expectedError: ":NO_RENEGOTIATION:",
6283 expectedLocalError: "remote error: no renegotiation",
6284 })
6285 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006286 name: "Renegotiate-Client-Freely-2",
6287 config: Config{
6288 MaxVersion: VersionTLS12,
6289 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006290 renegotiate: 2,
6291 flags: []string{
6292 "-renegotiate-freely",
6293 "-expect-total-renegotiations", "2",
6294 },
6295 })
Adam Langley27a0d082015-11-03 13:34:10 -08006296 testCases = append(testCases, testCase{
6297 name: "Renegotiate-Client-NoIgnore",
6298 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006299 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006300 Bugs: ProtocolBugs{
6301 SendHelloRequestBeforeEveryAppDataRecord: true,
6302 },
6303 },
6304 shouldFail: true,
6305 expectedError: ":NO_RENEGOTIATION:",
6306 })
6307 testCases = append(testCases, testCase{
6308 name: "Renegotiate-Client-Ignore",
6309 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006310 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006311 Bugs: ProtocolBugs{
6312 SendHelloRequestBeforeEveryAppDataRecord: true,
6313 },
6314 },
6315 flags: []string{
6316 "-renegotiate-ignore",
6317 "-expect-total-renegotiations", "0",
6318 },
6319 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006320
David Benjamin34941c02016-10-08 11:45:31 -04006321 // Renegotiation is not allowed at SSL 3.0.
6322 testCases = append(testCases, testCase{
6323 name: "Renegotiate-Client-SSL3",
6324 config: Config{
6325 MaxVersion: VersionSSL30,
6326 },
6327 renegotiate: 1,
6328 flags: []string{
6329 "-renegotiate-freely",
6330 "-expect-total-renegotiations", "1",
6331 },
6332 shouldFail: true,
6333 expectedError: ":NO_RENEGOTIATION:",
6334 expectedLocalError: "remote error: no renegotiation",
6335 })
6336
David Benjamina1eaba12017-01-01 23:19:22 -05006337 // Renegotiation is not allowed when there is an unfinished write.
6338 testCases = append(testCases, testCase{
6339 name: "Renegotiate-Client-UnfinishedWrite",
6340 config: Config{
6341 MaxVersion: VersionTLS12,
6342 },
6343 renegotiate: 1,
6344 flags: []string{
6345 "-async",
6346 "-renegotiate-freely",
6347 "-read-with-unfinished-write",
6348 },
6349 shouldFail: true,
6350 expectedError: ":NO_RENEGOTIATION:",
6351 // We do not successfully send the no_renegotiation alert in
6352 // this case. https://crbug.com/boringssl/130
6353 })
6354
David Benjamin397c8e62016-07-08 14:14:36 -07006355 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006356 testCases = append(testCases, testCase{
6357 name: "StrayHelloRequest",
6358 config: Config{
6359 MaxVersion: VersionTLS12,
6360 Bugs: ProtocolBugs{
6361 SendHelloRequestBeforeEveryHandshakeMessage: true,
6362 },
6363 },
6364 })
6365 testCases = append(testCases, testCase{
6366 name: "StrayHelloRequest-Packed",
6367 config: Config{
6368 MaxVersion: VersionTLS12,
6369 Bugs: ProtocolBugs{
6370 PackHandshakeFlight: true,
6371 SendHelloRequestBeforeEveryHandshakeMessage: true,
6372 },
6373 },
6374 })
6375
David Benjamin12d2c482016-07-24 10:56:51 -04006376 // Test renegotiation works if HelloRequest and server Finished come in
6377 // the same record.
6378 testCases = append(testCases, testCase{
6379 name: "Renegotiate-Client-Packed",
6380 config: Config{
6381 MaxVersion: VersionTLS12,
6382 Bugs: ProtocolBugs{
6383 PackHandshakeFlight: true,
6384 PackHelloRequestWithFinished: true,
6385 },
6386 },
6387 renegotiate: 1,
6388 flags: []string{
6389 "-renegotiate-freely",
6390 "-expect-total-renegotiations", "1",
6391 },
6392 })
6393
David Benjamin397c8e62016-07-08 14:14:36 -07006394 // Renegotiation is forbidden in TLS 1.3.
6395 testCases = append(testCases, testCase{
6396 name: "Renegotiate-Client-TLS13",
6397 config: Config{
6398 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006399 Bugs: ProtocolBugs{
6400 SendHelloRequestBeforeEveryAppDataRecord: true,
6401 },
David Benjamin397c8e62016-07-08 14:14:36 -07006402 },
David Benjamin397c8e62016-07-08 14:14:36 -07006403 flags: []string{
6404 "-renegotiate-freely",
6405 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006406 shouldFail: true,
6407 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006408 })
6409
6410 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6411 testCases = append(testCases, testCase{
6412 name: "StrayHelloRequest-TLS13",
6413 config: Config{
6414 MaxVersion: VersionTLS13,
6415 Bugs: ProtocolBugs{
6416 SendHelloRequestBeforeEveryHandshakeMessage: true,
6417 },
6418 },
6419 shouldFail: true,
6420 expectedError: ":UNEXPECTED_MESSAGE:",
6421 })
David Benjamind2610042017-01-03 10:49:28 -05006422
6423 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6424 // always reads as supporting it, regardless of whether it was
6425 // negotiated.
6426 testCases = append(testCases, testCase{
6427 name: "AlwaysReportRenegotiationInfo-TLS13",
6428 config: Config{
6429 MaxVersion: VersionTLS13,
6430 Bugs: ProtocolBugs{
6431 NoRenegotiationInfo: true,
6432 },
6433 },
6434 flags: []string{
6435 "-expect-secure-renegotiation",
6436 },
6437 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006438}
6439
David Benjamin5e961c12014-11-07 01:48:35 -05006440func addDTLSReplayTests() {
6441 // Test that sequence number replays are detected.
6442 testCases = append(testCases, testCase{
6443 protocol: dtls,
6444 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006445 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006446 replayWrites: true,
6447 })
6448
David Benjamin8e6db492015-07-25 18:29:23 -04006449 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006450 // than the retransmit window.
6451 testCases = append(testCases, testCase{
6452 protocol: dtls,
6453 name: "DTLS-Replay-LargeGaps",
6454 config: Config{
6455 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006456 SequenceNumberMapping: func(in uint64) uint64 {
6457 return in * 127
6458 },
David Benjamin5e961c12014-11-07 01:48:35 -05006459 },
6460 },
David Benjamin8e6db492015-07-25 18:29:23 -04006461 messageCount: 200,
6462 replayWrites: true,
6463 })
6464
6465 // Test the incoming sequence number changing non-monotonically.
6466 testCases = append(testCases, testCase{
6467 protocol: dtls,
6468 name: "DTLS-Replay-NonMonotonic",
6469 config: Config{
6470 Bugs: ProtocolBugs{
6471 SequenceNumberMapping: func(in uint64) uint64 {
6472 return in ^ 31
6473 },
6474 },
6475 },
6476 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006477 replayWrites: true,
6478 })
6479}
6480
Nick Harper60edffd2016-06-21 15:19:24 -07006481var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006482 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006483 id signatureAlgorithm
6484 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006485}{
Nick Harper60edffd2016-06-21 15:19:24 -07006486 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6487 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6488 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6489 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006490 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006491 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6492 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6493 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006494 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6495 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6496 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006497 // Tests for key types prior to TLS 1.2.
6498 {"RSA", 0, testCertRSA},
6499 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006500}
6501
Nick Harper60edffd2016-06-21 15:19:24 -07006502const fakeSigAlg1 signatureAlgorithm = 0x2a01
6503const fakeSigAlg2 signatureAlgorithm = 0xff01
6504
6505func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006506 // Not all ciphers involve a signature. Advertise a list which gives all
6507 // versions a signing cipher.
6508 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006509 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006510 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6511 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6512 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6513 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6514 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6515 }
6516
David Benjaminca3d5452016-07-14 12:51:01 -04006517 var allAlgorithms []signatureAlgorithm
6518 for _, alg := range testSignatureAlgorithms {
6519 if alg.id != 0 {
6520 allAlgorithms = append(allAlgorithms, alg.id)
6521 }
6522 }
6523
Nick Harper60edffd2016-06-21 15:19:24 -07006524 // Make sure each signature algorithm works. Include some fake values in
6525 // the list and ensure they're ignored.
6526 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006527 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006528 if (ver.version < VersionTLS12) != (alg.id == 0) {
6529 continue
6530 }
6531
6532 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6533 // or remove it in C.
6534 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006535 continue
6536 }
Nick Harper60edffd2016-06-21 15:19:24 -07006537
David Benjamin3ef76972016-10-17 17:59:54 -04006538 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006539 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006540 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006541 shouldSignFail = true
6542 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006543 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006544 // RSA-PKCS1 does not exist in TLS 1.3.
6545 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006546 shouldSignFail = true
6547 shouldVerifyFail = true
6548 }
6549
6550 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6551 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6552 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006553 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006554
6555 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006556 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006557 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006558 }
6559 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006560 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006561 }
David Benjamin000800a2014-11-14 01:43:59 -05006562
David Benjamin1fb125c2016-07-08 18:52:12 -07006563 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006564
David Benjamin7a41d372016-07-09 11:21:54 -07006565 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006566 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006567 config: Config{
6568 MaxVersion: ver.version,
6569 ClientAuth: RequireAnyClientCert,
6570 VerifySignatureAlgorithms: []signatureAlgorithm{
6571 fakeSigAlg1,
6572 alg.id,
6573 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006574 },
David Benjamin7a41d372016-07-09 11:21:54 -07006575 },
6576 flags: []string{
6577 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6578 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6579 "-enable-all-curves",
6580 },
David Benjamin3ef76972016-10-17 17:59:54 -04006581 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006582 expectedError: signError,
6583 expectedPeerSignatureAlgorithm: alg.id,
6584 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006585
David Benjamin7a41d372016-07-09 11:21:54 -07006586 testCases = append(testCases, testCase{
6587 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006588 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006589 config: Config{
6590 MaxVersion: ver.version,
6591 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6592 SignSignatureAlgorithms: []signatureAlgorithm{
6593 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006594 },
David Benjamin7a41d372016-07-09 11:21:54 -07006595 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006596 SkipECDSACurveCheck: shouldVerifyFail,
6597 IgnoreSignatureVersionChecks: shouldVerifyFail,
6598 // Some signature algorithms may not be advertised.
6599 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006600 },
David Benjamin7a41d372016-07-09 11:21:54 -07006601 },
6602 flags: []string{
6603 "-require-any-client-certificate",
6604 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6605 "-enable-all-curves",
6606 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006607 // Resume the session to assert the peer signature
6608 // algorithm is reported on both handshakes.
6609 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006610 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006611 expectedError: verifyError,
6612 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006613
6614 testCases = append(testCases, testCase{
6615 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006616 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006617 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006618 MaxVersion: ver.version,
6619 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006620 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006621 fakeSigAlg1,
6622 alg.id,
6623 fakeSigAlg2,
6624 },
6625 },
6626 flags: []string{
6627 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6628 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6629 "-enable-all-curves",
6630 },
David Benjamin3ef76972016-10-17 17:59:54 -04006631 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006632 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006633 expectedPeerSignatureAlgorithm: alg.id,
6634 })
6635
6636 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006637 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006638 config: Config{
6639 MaxVersion: ver.version,
6640 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006641 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006642 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006643 alg.id,
6644 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006645 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006646 SkipECDSACurveCheck: shouldVerifyFail,
6647 IgnoreSignatureVersionChecks: shouldVerifyFail,
6648 // Some signature algorithms may not be advertised.
6649 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006650 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006651 },
6652 flags: []string{
6653 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6654 "-enable-all-curves",
6655 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006656 // Resume the session to assert the peer signature
6657 // algorithm is reported on both handshakes.
6658 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006659 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006660 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006661 })
David Benjamin5208fd42016-07-13 21:43:25 -04006662
David Benjamin3ef76972016-10-17 17:59:54 -04006663 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006664 testCases = append(testCases, testCase{
6665 testType: serverTest,
6666 name: "ClientAuth-InvalidSignature" + suffix,
6667 config: Config{
6668 MaxVersion: ver.version,
6669 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6670 SignSignatureAlgorithms: []signatureAlgorithm{
6671 alg.id,
6672 },
6673 Bugs: ProtocolBugs{
6674 InvalidSignature: true,
6675 },
6676 },
6677 flags: []string{
6678 "-require-any-client-certificate",
6679 "-enable-all-curves",
6680 },
6681 shouldFail: true,
6682 expectedError: ":BAD_SIGNATURE:",
6683 })
6684
6685 testCases = append(testCases, testCase{
6686 name: "ServerAuth-InvalidSignature" + suffix,
6687 config: Config{
6688 MaxVersion: ver.version,
6689 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6690 CipherSuites: signingCiphers,
6691 SignSignatureAlgorithms: []signatureAlgorithm{
6692 alg.id,
6693 },
6694 Bugs: ProtocolBugs{
6695 InvalidSignature: true,
6696 },
6697 },
6698 flags: []string{"-enable-all-curves"},
6699 shouldFail: true,
6700 expectedError: ":BAD_SIGNATURE:",
6701 })
6702 }
David Benjaminca3d5452016-07-14 12:51:01 -04006703
David Benjamin3ef76972016-10-17 17:59:54 -04006704 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006705 testCases = append(testCases, testCase{
6706 name: "ClientAuth-Sign-Negotiate" + suffix,
6707 config: Config{
6708 MaxVersion: ver.version,
6709 ClientAuth: RequireAnyClientCert,
6710 VerifySignatureAlgorithms: allAlgorithms,
6711 },
6712 flags: []string{
6713 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6714 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6715 "-enable-all-curves",
6716 "-signing-prefs", strconv.Itoa(int(alg.id)),
6717 },
6718 expectedPeerSignatureAlgorithm: alg.id,
6719 })
6720
6721 testCases = append(testCases, testCase{
6722 testType: serverTest,
6723 name: "ServerAuth-Sign-Negotiate" + suffix,
6724 config: Config{
6725 MaxVersion: ver.version,
6726 CipherSuites: signingCiphers,
6727 VerifySignatureAlgorithms: allAlgorithms,
6728 },
6729 flags: []string{
6730 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6731 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6732 "-enable-all-curves",
6733 "-signing-prefs", strconv.Itoa(int(alg.id)),
6734 },
6735 expectedPeerSignatureAlgorithm: alg.id,
6736 })
6737 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006738 }
David Benjamin000800a2014-11-14 01:43:59 -05006739 }
6740
Nick Harper60edffd2016-06-21 15:19:24 -07006741 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006742 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006743 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006744 config: Config{
6745 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006746 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006747 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006748 signatureECDSAWithP521AndSHA512,
6749 signatureRSAPKCS1WithSHA384,
6750 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006751 },
6752 },
6753 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006754 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6755 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006756 },
Nick Harper60edffd2016-06-21 15:19:24 -07006757 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006758 })
6759
6760 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006761 name: "ClientAuth-SignatureType-TLS13",
6762 config: Config{
6763 ClientAuth: RequireAnyClientCert,
6764 MaxVersion: VersionTLS13,
6765 VerifySignatureAlgorithms: []signatureAlgorithm{
6766 signatureECDSAWithP521AndSHA512,
6767 signatureRSAPKCS1WithSHA384,
6768 signatureRSAPSSWithSHA384,
6769 signatureECDSAWithSHA1,
6770 },
6771 },
6772 flags: []string{
6773 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6774 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6775 },
6776 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6777 })
6778
6779 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006780 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006781 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006782 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006783 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006784 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006785 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006786 signatureECDSAWithP521AndSHA512,
6787 signatureRSAPKCS1WithSHA384,
6788 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006789 },
6790 },
Nick Harper60edffd2016-06-21 15:19:24 -07006791 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006792 })
6793
Steven Valdez143e8b32016-07-11 13:19:03 -04006794 testCases = append(testCases, testCase{
6795 testType: serverTest,
6796 name: "ServerAuth-SignatureType-TLS13",
6797 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006798 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006799 VerifySignatureAlgorithms: []signatureAlgorithm{
6800 signatureECDSAWithP521AndSHA512,
6801 signatureRSAPKCS1WithSHA384,
6802 signatureRSAPSSWithSHA384,
6803 signatureECDSAWithSHA1,
6804 },
6805 },
6806 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6807 })
6808
David Benjamina95e9f32016-07-08 16:28:04 -07006809 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006810 testCases = append(testCases, testCase{
6811 testType: serverTest,
6812 name: "Verify-ClientAuth-SignatureType",
6813 config: Config{
6814 MaxVersion: VersionTLS12,
6815 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006816 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006817 signatureRSAPKCS1WithSHA256,
6818 },
6819 Bugs: ProtocolBugs{
6820 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6821 },
6822 },
6823 flags: []string{
6824 "-require-any-client-certificate",
6825 },
6826 shouldFail: true,
6827 expectedError: ":WRONG_SIGNATURE_TYPE:",
6828 })
6829
6830 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006831 testType: serverTest,
6832 name: "Verify-ClientAuth-SignatureType-TLS13",
6833 config: Config{
6834 MaxVersion: VersionTLS13,
6835 Certificates: []Certificate{rsaCertificate},
6836 SignSignatureAlgorithms: []signatureAlgorithm{
6837 signatureRSAPSSWithSHA256,
6838 },
6839 Bugs: ProtocolBugs{
6840 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6841 },
6842 },
6843 flags: []string{
6844 "-require-any-client-certificate",
6845 },
6846 shouldFail: true,
6847 expectedError: ":WRONG_SIGNATURE_TYPE:",
6848 })
6849
6850 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006851 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006852 config: Config{
6853 MaxVersion: VersionTLS12,
6854 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006855 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006856 signatureRSAPKCS1WithSHA256,
6857 },
6858 Bugs: ProtocolBugs{
6859 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6860 },
6861 },
6862 shouldFail: true,
6863 expectedError: ":WRONG_SIGNATURE_TYPE:",
6864 })
6865
Steven Valdez143e8b32016-07-11 13:19:03 -04006866 testCases = append(testCases, testCase{
6867 name: "Verify-ServerAuth-SignatureType-TLS13",
6868 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006869 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006870 SignSignatureAlgorithms: []signatureAlgorithm{
6871 signatureRSAPSSWithSHA256,
6872 },
6873 Bugs: ProtocolBugs{
6874 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6875 },
6876 },
6877 shouldFail: true,
6878 expectedError: ":WRONG_SIGNATURE_TYPE:",
6879 })
6880
David Benjamin51dd7d62016-07-08 16:07:01 -07006881 // Test that, if the list is missing, the peer falls back to SHA-1 in
6882 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006883 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006884 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006885 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006886 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006887 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006888 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006889 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006890 },
6891 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006892 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006893 },
6894 },
6895 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006896 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6897 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006898 },
6899 })
6900
6901 testCases = append(testCases, testCase{
6902 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006903 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006904 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006905 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006906 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006907 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006908 },
6909 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006910 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006911 },
6912 },
David Benjaminee32bea2016-08-17 13:36:44 -04006913 flags: []string{
6914 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6915 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6916 },
6917 })
6918
6919 testCases = append(testCases, testCase{
6920 name: "ClientAuth-SHA1-Fallback-ECDSA",
6921 config: Config{
6922 MaxVersion: VersionTLS12,
6923 ClientAuth: RequireAnyClientCert,
6924 VerifySignatureAlgorithms: []signatureAlgorithm{
6925 signatureECDSAWithSHA1,
6926 },
6927 Bugs: ProtocolBugs{
6928 NoSignatureAlgorithms: true,
6929 },
6930 },
6931 flags: []string{
6932 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6933 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6934 },
6935 })
6936
6937 testCases = append(testCases, testCase{
6938 testType: serverTest,
6939 name: "ServerAuth-SHA1-Fallback-ECDSA",
6940 config: Config{
6941 MaxVersion: VersionTLS12,
6942 VerifySignatureAlgorithms: []signatureAlgorithm{
6943 signatureECDSAWithSHA1,
6944 },
6945 Bugs: ProtocolBugs{
6946 NoSignatureAlgorithms: true,
6947 },
6948 },
6949 flags: []string{
6950 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6951 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6952 },
David Benjamin000800a2014-11-14 01:43:59 -05006953 })
David Benjamin72dc7832015-03-16 17:49:43 -04006954
David Benjamin51dd7d62016-07-08 16:07:01 -07006955 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006956 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006957 config: Config{
6958 MaxVersion: VersionTLS13,
6959 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006960 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006961 signatureRSAPKCS1WithSHA1,
6962 },
6963 Bugs: ProtocolBugs{
6964 NoSignatureAlgorithms: true,
6965 },
6966 },
6967 flags: []string{
6968 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6969 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6970 },
David Benjamin48901652016-08-01 12:12:47 -04006971 shouldFail: true,
6972 // An empty CertificateRequest signature algorithm list is a
6973 // syntax error in TLS 1.3.
6974 expectedError: ":DECODE_ERROR:",
6975 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006976 })
6977
6978 testCases = append(testCases, testCase{
6979 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006980 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006981 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006982 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006983 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006984 signatureRSAPKCS1WithSHA1,
6985 },
6986 Bugs: ProtocolBugs{
6987 NoSignatureAlgorithms: true,
6988 },
6989 },
6990 shouldFail: true,
6991 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6992 })
6993
David Benjaminb62d2872016-07-18 14:55:02 +02006994 // Test that hash preferences are enforced. BoringSSL does not implement
6995 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006996 testCases = append(testCases, testCase{
6997 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006998 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006999 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007000 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007001 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007002 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007003 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007004 },
7005 Bugs: ProtocolBugs{
7006 IgnorePeerSignatureAlgorithmPreferences: true,
7007 },
7008 },
7009 flags: []string{"-require-any-client-certificate"},
7010 shouldFail: true,
7011 expectedError: ":WRONG_SIGNATURE_TYPE:",
7012 })
7013
7014 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007015 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007017 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007018 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007019 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007020 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007021 },
7022 Bugs: ProtocolBugs{
7023 IgnorePeerSignatureAlgorithmPreferences: true,
7024 },
7025 },
7026 shouldFail: true,
7027 expectedError: ":WRONG_SIGNATURE_TYPE:",
7028 })
David Benjaminb62d2872016-07-18 14:55:02 +02007029 testCases = append(testCases, testCase{
7030 testType: serverTest,
7031 name: "ClientAuth-Enforced-TLS13",
7032 config: Config{
7033 MaxVersion: VersionTLS13,
7034 Certificates: []Certificate{rsaCertificate},
7035 SignSignatureAlgorithms: []signatureAlgorithm{
7036 signatureRSAPKCS1WithMD5,
7037 },
7038 Bugs: ProtocolBugs{
7039 IgnorePeerSignatureAlgorithmPreferences: true,
7040 IgnoreSignatureVersionChecks: true,
7041 },
7042 },
7043 flags: []string{"-require-any-client-certificate"},
7044 shouldFail: true,
7045 expectedError: ":WRONG_SIGNATURE_TYPE:",
7046 })
7047
7048 testCases = append(testCases, testCase{
7049 name: "ServerAuth-Enforced-TLS13",
7050 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007051 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007052 SignSignatureAlgorithms: []signatureAlgorithm{
7053 signatureRSAPKCS1WithMD5,
7054 },
7055 Bugs: ProtocolBugs{
7056 IgnorePeerSignatureAlgorithmPreferences: true,
7057 IgnoreSignatureVersionChecks: true,
7058 },
7059 },
7060 shouldFail: true,
7061 expectedError: ":WRONG_SIGNATURE_TYPE:",
7062 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007063
7064 // Test that the agreed upon digest respects the client preferences and
7065 // the server digests.
7066 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007067 name: "NoCommonAlgorithms-Digests",
7068 config: Config{
7069 MaxVersion: VersionTLS12,
7070 ClientAuth: RequireAnyClientCert,
7071 VerifySignatureAlgorithms: []signatureAlgorithm{
7072 signatureRSAPKCS1WithSHA512,
7073 signatureRSAPKCS1WithSHA1,
7074 },
7075 },
7076 flags: []string{
7077 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7078 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7079 "-digest-prefs", "SHA256",
7080 },
7081 shouldFail: true,
7082 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7083 })
7084 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007085 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007087 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007088 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007089 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007090 signatureRSAPKCS1WithSHA512,
7091 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007092 },
7093 },
7094 flags: []string{
7095 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7096 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007097 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007098 },
David Benjaminca3d5452016-07-14 12:51:01 -04007099 shouldFail: true,
7100 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7101 })
7102 testCases = append(testCases, testCase{
7103 name: "NoCommonAlgorithms-TLS13",
7104 config: Config{
7105 MaxVersion: VersionTLS13,
7106 ClientAuth: RequireAnyClientCert,
7107 VerifySignatureAlgorithms: []signatureAlgorithm{
7108 signatureRSAPSSWithSHA512,
7109 signatureRSAPSSWithSHA384,
7110 },
7111 },
7112 flags: []string{
7113 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7114 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7115 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7116 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007117 shouldFail: true,
7118 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007119 })
7120 testCases = append(testCases, testCase{
7121 name: "Agree-Digest-SHA256",
7122 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007123 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007124 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007125 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007126 signatureRSAPKCS1WithSHA1,
7127 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007128 },
7129 },
7130 flags: []string{
7131 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7132 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007133 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007134 },
Nick Harper60edffd2016-06-21 15:19:24 -07007135 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007136 })
7137 testCases = append(testCases, testCase{
7138 name: "Agree-Digest-SHA1",
7139 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007140 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007141 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007142 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007143 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007144 },
7145 },
7146 flags: []string{
7147 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7148 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007149 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007150 },
Nick Harper60edffd2016-06-21 15:19:24 -07007151 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007152 })
7153 testCases = append(testCases, testCase{
7154 name: "Agree-Digest-Default",
7155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007156 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007157 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007158 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007159 signatureRSAPKCS1WithSHA256,
7160 signatureECDSAWithP256AndSHA256,
7161 signatureRSAPKCS1WithSHA1,
7162 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007163 },
7164 },
7165 flags: []string{
7166 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7167 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7168 },
Nick Harper60edffd2016-06-21 15:19:24 -07007169 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007170 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007171
David Benjaminca3d5452016-07-14 12:51:01 -04007172 // Test that the signing preference list may include extra algorithms
7173 // without negotiation problems.
7174 testCases = append(testCases, testCase{
7175 testType: serverTest,
7176 name: "FilterExtraAlgorithms",
7177 config: Config{
7178 MaxVersion: VersionTLS12,
7179 VerifySignatureAlgorithms: []signatureAlgorithm{
7180 signatureRSAPKCS1WithSHA256,
7181 },
7182 },
7183 flags: []string{
7184 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7185 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7186 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7187 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7188 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7189 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7190 },
7191 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7192 })
7193
David Benjamin4c3ddf72016-06-29 18:13:53 -04007194 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7195 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007196 testCases = append(testCases, testCase{
7197 name: "CheckLeafCurve",
7198 config: Config{
7199 MaxVersion: VersionTLS12,
7200 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007201 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007202 },
7203 flags: []string{"-p384-only"},
7204 shouldFail: true,
7205 expectedError: ":BAD_ECC_CERT:",
7206 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007207
7208 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7209 testCases = append(testCases, testCase{
7210 name: "CheckLeafCurve-TLS13",
7211 config: Config{
7212 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007213 Certificates: []Certificate{ecdsaP256Certificate},
7214 },
7215 flags: []string{"-p384-only"},
7216 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007217
7218 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7219 testCases = append(testCases, testCase{
7220 name: "ECDSACurveMismatch-Verify-TLS12",
7221 config: Config{
7222 MaxVersion: VersionTLS12,
7223 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7224 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007225 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007226 signatureECDSAWithP384AndSHA384,
7227 },
7228 },
7229 })
7230
7231 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7232 testCases = append(testCases, testCase{
7233 name: "ECDSACurveMismatch-Verify-TLS13",
7234 config: Config{
7235 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007236 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007237 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007238 signatureECDSAWithP384AndSHA384,
7239 },
7240 Bugs: ProtocolBugs{
7241 SkipECDSACurveCheck: true,
7242 },
7243 },
7244 shouldFail: true,
7245 expectedError: ":WRONG_SIGNATURE_TYPE:",
7246 })
7247
7248 // Signature algorithm selection in TLS 1.3 should take the curve into
7249 // account.
7250 testCases = append(testCases, testCase{
7251 testType: serverTest,
7252 name: "ECDSACurveMismatch-Sign-TLS13",
7253 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007254 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007255 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007256 signatureECDSAWithP384AndSHA384,
7257 signatureECDSAWithP256AndSHA256,
7258 },
7259 },
7260 flags: []string{
7261 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7262 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7263 },
7264 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7265 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007266
7267 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7268 // server does not attempt to sign in that case.
7269 testCases = append(testCases, testCase{
7270 testType: serverTest,
7271 name: "RSA-PSS-Large",
7272 config: Config{
7273 MaxVersion: VersionTLS13,
7274 VerifySignatureAlgorithms: []signatureAlgorithm{
7275 signatureRSAPSSWithSHA512,
7276 },
7277 },
7278 flags: []string{
7279 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7280 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7281 },
7282 shouldFail: true,
7283 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7284 })
David Benjamin57e929f2016-08-30 00:30:38 -04007285
7286 // Test that RSA-PSS is enabled by default for TLS 1.2.
7287 testCases = append(testCases, testCase{
7288 testType: clientTest,
7289 name: "RSA-PSS-Default-Verify",
7290 config: Config{
7291 MaxVersion: VersionTLS12,
7292 SignSignatureAlgorithms: []signatureAlgorithm{
7293 signatureRSAPSSWithSHA256,
7294 },
7295 },
7296 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7297 })
7298
7299 testCases = append(testCases, testCase{
7300 testType: serverTest,
7301 name: "RSA-PSS-Default-Sign",
7302 config: Config{
7303 MaxVersion: VersionTLS12,
7304 VerifySignatureAlgorithms: []signatureAlgorithm{
7305 signatureRSAPSSWithSHA256,
7306 },
7307 },
7308 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7309 })
David Benjamin000800a2014-11-14 01:43:59 -05007310}
7311
David Benjamin83f90402015-01-27 01:09:43 -05007312// timeouts is the retransmit schedule for BoringSSL. It doubles and
7313// caps at 60 seconds. On the 13th timeout, it gives up.
7314var timeouts = []time.Duration{
7315 1 * time.Second,
7316 2 * time.Second,
7317 4 * time.Second,
7318 8 * time.Second,
7319 16 * time.Second,
7320 32 * time.Second,
7321 60 * time.Second,
7322 60 * time.Second,
7323 60 * time.Second,
7324 60 * time.Second,
7325 60 * time.Second,
7326 60 * time.Second,
7327 60 * time.Second,
7328}
7329
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007330// shortTimeouts is an alternate set of timeouts which would occur if the
7331// initial timeout duration was set to 250ms.
7332var shortTimeouts = []time.Duration{
7333 250 * time.Millisecond,
7334 500 * time.Millisecond,
7335 1 * time.Second,
7336 2 * time.Second,
7337 4 * time.Second,
7338 8 * time.Second,
7339 16 * time.Second,
7340 32 * time.Second,
7341 60 * time.Second,
7342 60 * time.Second,
7343 60 * time.Second,
7344 60 * time.Second,
7345 60 * time.Second,
7346}
7347
David Benjamin83f90402015-01-27 01:09:43 -05007348func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007349 // These tests work by coordinating some behavior on both the shim and
7350 // the runner.
7351 //
7352 // TimeoutSchedule configures the runner to send a series of timeout
7353 // opcodes to the shim (see packetAdaptor) immediately before reading
7354 // each peer handshake flight N. The timeout opcode both simulates a
7355 // timeout in the shim and acts as a synchronization point to help the
7356 // runner bracket each handshake flight.
7357 //
7358 // We assume the shim does not read from the channel eagerly. It must
7359 // first wait until it has sent flight N and is ready to receive
7360 // handshake flight N+1. At this point, it will process the timeout
7361 // opcode. It must then immediately respond with a timeout ACK and act
7362 // as if the shim was idle for the specified amount of time.
7363 //
7364 // The runner then drops all packets received before the ACK and
7365 // continues waiting for flight N. This ordering results in one attempt
7366 // at sending flight N to be dropped. For the test to complete, the
7367 // shim must send flight N again, testing that the shim implements DTLS
7368 // retransmit on a timeout.
7369
Steven Valdez143e8b32016-07-11 13:19:03 -04007370 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007371 // likely be more epochs to cross and the final message's retransmit may
7372 // be more complex.
7373
David Benjamin585d7a42016-06-02 14:58:00 -04007374 for _, async := range []bool{true, false} {
7375 var tests []testCase
7376
7377 // Test that this is indeed the timeout schedule. Stress all
7378 // four patterns of handshake.
7379 for i := 1; i < len(timeouts); i++ {
7380 number := strconv.Itoa(i)
7381 tests = append(tests, testCase{
7382 protocol: dtls,
7383 name: "DTLS-Retransmit-Client-" + number,
7384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007385 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007386 Bugs: ProtocolBugs{
7387 TimeoutSchedule: timeouts[:i],
7388 },
7389 },
7390 resumeSession: true,
7391 })
7392 tests = append(tests, testCase{
7393 protocol: dtls,
7394 testType: serverTest,
7395 name: "DTLS-Retransmit-Server-" + number,
7396 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007397 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007398 Bugs: ProtocolBugs{
7399 TimeoutSchedule: timeouts[:i],
7400 },
7401 },
7402 resumeSession: true,
7403 })
7404 }
7405
7406 // Test that exceeding the timeout schedule hits a read
7407 // timeout.
7408 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007409 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007410 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007411 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007412 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007413 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007414 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007415 },
7416 },
7417 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007418 shouldFail: true,
7419 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007420 })
David Benjamin585d7a42016-06-02 14:58:00 -04007421
7422 if async {
7423 // Test that timeout handling has a fudge factor, due to API
7424 // problems.
7425 tests = append(tests, testCase{
7426 protocol: dtls,
7427 name: "DTLS-Retransmit-Fudge",
7428 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007429 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007430 Bugs: ProtocolBugs{
7431 TimeoutSchedule: []time.Duration{
7432 timeouts[0] - 10*time.Millisecond,
7433 },
7434 },
7435 },
7436 resumeSession: true,
7437 })
7438 }
7439
7440 // Test that the final Finished retransmitting isn't
7441 // duplicated if the peer badly fragments everything.
7442 tests = append(tests, testCase{
7443 testType: serverTest,
7444 protocol: dtls,
7445 name: "DTLS-Retransmit-Fragmented",
7446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007447 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007448 Bugs: ProtocolBugs{
7449 TimeoutSchedule: []time.Duration{timeouts[0]},
7450 MaxHandshakeRecordLength: 2,
7451 },
7452 },
7453 })
7454
7455 // Test the timeout schedule when a shorter initial timeout duration is set.
7456 tests = append(tests, testCase{
7457 protocol: dtls,
7458 name: "DTLS-Retransmit-Short-Client",
7459 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007460 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007461 Bugs: ProtocolBugs{
7462 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7463 },
7464 },
7465 resumeSession: true,
7466 flags: []string{"-initial-timeout-duration-ms", "250"},
7467 })
7468 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007469 protocol: dtls,
7470 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007471 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007473 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007474 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007475 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007476 },
7477 },
7478 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007479 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007480 })
David Benjamin585d7a42016-06-02 14:58:00 -04007481
7482 for _, test := range tests {
7483 if async {
7484 test.name += "-Async"
7485 test.flags = append(test.flags, "-async")
7486 }
7487
7488 testCases = append(testCases, test)
7489 }
David Benjamin83f90402015-01-27 01:09:43 -05007490 }
David Benjamin83f90402015-01-27 01:09:43 -05007491}
7492
David Benjaminc565ebb2015-04-03 04:06:36 -04007493func addExportKeyingMaterialTests() {
7494 for _, vers := range tlsVersions {
7495 if vers.version == VersionSSL30 {
7496 continue
7497 }
7498 testCases = append(testCases, testCase{
7499 name: "ExportKeyingMaterial-" + vers.name,
7500 config: Config{
7501 MaxVersion: vers.version,
7502 },
7503 exportKeyingMaterial: 1024,
7504 exportLabel: "label",
7505 exportContext: "context",
7506 useExportContext: true,
7507 })
7508 testCases = append(testCases, testCase{
7509 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7510 config: Config{
7511 MaxVersion: vers.version,
7512 },
7513 exportKeyingMaterial: 1024,
7514 })
7515 testCases = append(testCases, testCase{
7516 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7517 config: Config{
7518 MaxVersion: vers.version,
7519 },
7520 exportKeyingMaterial: 1024,
7521 useExportContext: true,
7522 })
7523 testCases = append(testCases, testCase{
7524 name: "ExportKeyingMaterial-Small-" + vers.name,
7525 config: Config{
7526 MaxVersion: vers.version,
7527 },
7528 exportKeyingMaterial: 1,
7529 exportLabel: "label",
7530 exportContext: "context",
7531 useExportContext: true,
7532 })
7533 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007534
David Benjaminc565ebb2015-04-03 04:06:36 -04007535 testCases = append(testCases, testCase{
7536 name: "ExportKeyingMaterial-SSL3",
7537 config: Config{
7538 MaxVersion: VersionSSL30,
7539 },
7540 exportKeyingMaterial: 1024,
7541 exportLabel: "label",
7542 exportContext: "context",
7543 useExportContext: true,
7544 shouldFail: true,
7545 expectedError: "failed to export keying material",
7546 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007547
7548 // Exporters work during a False Start.
7549 testCases = append(testCases, testCase{
7550 name: "ExportKeyingMaterial-FalseStart",
7551 config: Config{
7552 MaxVersion: VersionTLS12,
7553 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7554 NextProtos: []string{"foo"},
7555 Bugs: ProtocolBugs{
7556 ExpectFalseStart: true,
7557 },
7558 },
7559 flags: []string{
7560 "-false-start",
7561 "-advertise-alpn", "\x03foo",
7562 },
7563 shimWritesFirst: true,
7564 exportKeyingMaterial: 1024,
7565 exportLabel: "label",
7566 exportContext: "context",
7567 useExportContext: true,
7568 })
7569
7570 // Exporters do not work in the middle of a renegotiation. Test this by
7571 // triggering the exporter after every SSL_read call and configuring the
7572 // shim to run asynchronously.
7573 testCases = append(testCases, testCase{
7574 name: "ExportKeyingMaterial-Renegotiate",
7575 config: Config{
7576 MaxVersion: VersionTLS12,
7577 },
7578 renegotiate: 1,
7579 flags: []string{
7580 "-async",
7581 "-use-exporter-between-reads",
7582 "-renegotiate-freely",
7583 "-expect-total-renegotiations", "1",
7584 },
7585 shouldFail: true,
7586 expectedError: "failed to export keying material",
7587 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007588}
7589
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007590func addTLSUniqueTests() {
7591 for _, isClient := range []bool{false, true} {
7592 for _, isResumption := range []bool{false, true} {
7593 for _, hasEMS := range []bool{false, true} {
7594 var suffix string
7595 if isResumption {
7596 suffix = "Resume-"
7597 } else {
7598 suffix = "Full-"
7599 }
7600
7601 if hasEMS {
7602 suffix += "EMS-"
7603 } else {
7604 suffix += "NoEMS-"
7605 }
7606
7607 if isClient {
7608 suffix += "Client"
7609 } else {
7610 suffix += "Server"
7611 }
7612
7613 test := testCase{
7614 name: "TLSUnique-" + suffix,
7615 testTLSUnique: true,
7616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007617 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007618 Bugs: ProtocolBugs{
7619 NoExtendedMasterSecret: !hasEMS,
7620 },
7621 },
7622 }
7623
7624 if isResumption {
7625 test.resumeSession = true
7626 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007627 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007628 Bugs: ProtocolBugs{
7629 NoExtendedMasterSecret: !hasEMS,
7630 },
7631 }
7632 }
7633
7634 if isResumption && !hasEMS {
7635 test.shouldFail = true
7636 test.expectedError = "failed to get tls-unique"
7637 }
7638
7639 testCases = append(testCases, test)
7640 }
7641 }
7642 }
7643}
7644
Adam Langley09505632015-07-30 18:10:13 -07007645func addCustomExtensionTests() {
7646 expectedContents := "custom extension"
7647 emptyString := ""
7648
7649 for _, isClient := range []bool{false, true} {
7650 suffix := "Server"
7651 flag := "-enable-server-custom-extension"
7652 testType := serverTest
7653 if isClient {
7654 suffix = "Client"
7655 flag = "-enable-client-custom-extension"
7656 testType = clientTest
7657 }
7658
7659 testCases = append(testCases, testCase{
7660 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007661 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007662 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007663 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007664 Bugs: ProtocolBugs{
7665 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007666 ExpectedCustomExtension: &expectedContents,
7667 },
7668 },
7669 flags: []string{flag},
7670 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007671 testCases = append(testCases, testCase{
7672 testType: testType,
7673 name: "CustomExtensions-" + suffix + "-TLS13",
7674 config: Config{
7675 MaxVersion: VersionTLS13,
7676 Bugs: ProtocolBugs{
7677 CustomExtension: expectedContents,
7678 ExpectedCustomExtension: &expectedContents,
7679 },
7680 },
7681 flags: []string{flag},
7682 })
Adam Langley09505632015-07-30 18:10:13 -07007683
7684 // If the parse callback fails, the handshake should also fail.
7685 testCases = append(testCases, testCase{
7686 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007687 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007689 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007690 Bugs: ProtocolBugs{
7691 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007692 ExpectedCustomExtension: &expectedContents,
7693 },
7694 },
David Benjamin399e7c92015-07-30 23:01:27 -04007695 flags: []string{flag},
7696 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007697 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7698 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007699 testCases = append(testCases, testCase{
7700 testType: testType,
7701 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7702 config: Config{
7703 MaxVersion: VersionTLS13,
7704 Bugs: ProtocolBugs{
7705 CustomExtension: expectedContents + "foo",
7706 ExpectedCustomExtension: &expectedContents,
7707 },
7708 },
7709 flags: []string{flag},
7710 shouldFail: true,
7711 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7712 })
Adam Langley09505632015-07-30 18:10:13 -07007713
7714 // If the add callback fails, the handshake should also fail.
7715 testCases = append(testCases, testCase{
7716 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007717 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007718 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007719 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007720 Bugs: ProtocolBugs{
7721 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007722 ExpectedCustomExtension: &expectedContents,
7723 },
7724 },
David Benjamin399e7c92015-07-30 23:01:27 -04007725 flags: []string{flag, "-custom-extension-fail-add"},
7726 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007727 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7728 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007729 testCases = append(testCases, testCase{
7730 testType: testType,
7731 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7732 config: Config{
7733 MaxVersion: VersionTLS13,
7734 Bugs: ProtocolBugs{
7735 CustomExtension: expectedContents,
7736 ExpectedCustomExtension: &expectedContents,
7737 },
7738 },
7739 flags: []string{flag, "-custom-extension-fail-add"},
7740 shouldFail: true,
7741 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7742 })
Adam Langley09505632015-07-30 18:10:13 -07007743
7744 // If the add callback returns zero, no extension should be
7745 // added.
7746 skipCustomExtension := expectedContents
7747 if isClient {
7748 // For the case where the client skips sending the
7749 // custom extension, the server must not “echo” it.
7750 skipCustomExtension = ""
7751 }
7752 testCases = append(testCases, testCase{
7753 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007754 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007755 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007756 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007757 Bugs: ProtocolBugs{
7758 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007759 ExpectedCustomExtension: &emptyString,
7760 },
7761 },
7762 flags: []string{flag, "-custom-extension-skip"},
7763 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007764 testCases = append(testCases, testCase{
7765 testType: testType,
7766 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7767 config: Config{
7768 MaxVersion: VersionTLS13,
7769 Bugs: ProtocolBugs{
7770 CustomExtension: skipCustomExtension,
7771 ExpectedCustomExtension: &emptyString,
7772 },
7773 },
7774 flags: []string{flag, "-custom-extension-skip"},
7775 })
Adam Langley09505632015-07-30 18:10:13 -07007776 }
7777
7778 // The custom extension add callback should not be called if the client
7779 // doesn't send the extension.
7780 testCases = append(testCases, testCase{
7781 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007782 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007784 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007785 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007786 ExpectedCustomExtension: &emptyString,
7787 },
7788 },
7789 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7790 })
Adam Langley2deb9842015-08-07 11:15:37 -07007791
Steven Valdez143e8b32016-07-11 13:19:03 -04007792 testCases = append(testCases, testCase{
7793 testType: serverTest,
7794 name: "CustomExtensions-NotCalled-Server-TLS13",
7795 config: Config{
7796 MaxVersion: VersionTLS13,
7797 Bugs: ProtocolBugs{
7798 ExpectedCustomExtension: &emptyString,
7799 },
7800 },
7801 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7802 })
7803
Adam Langley2deb9842015-08-07 11:15:37 -07007804 // Test an unknown extension from the server.
7805 testCases = append(testCases, testCase{
7806 testType: clientTest,
7807 name: "UnknownExtension-Client",
7808 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007809 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007810 Bugs: ProtocolBugs{
7811 CustomExtension: expectedContents,
7812 },
7813 },
David Benjamin0c40a962016-08-01 12:05:50 -04007814 shouldFail: true,
7815 expectedError: ":UNEXPECTED_EXTENSION:",
7816 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007817 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007818 testCases = append(testCases, testCase{
7819 testType: clientTest,
7820 name: "UnknownExtension-Client-TLS13",
7821 config: Config{
7822 MaxVersion: VersionTLS13,
7823 Bugs: ProtocolBugs{
7824 CustomExtension: expectedContents,
7825 },
7826 },
David Benjamin0c40a962016-08-01 12:05:50 -04007827 shouldFail: true,
7828 expectedError: ":UNEXPECTED_EXTENSION:",
7829 expectedLocalError: "remote error: unsupported extension",
7830 })
David Benjamin490469f2016-10-05 22:44:38 -04007831 testCases = append(testCases, testCase{
7832 testType: clientTest,
7833 name: "UnknownUnencryptedExtension-Client-TLS13",
7834 config: Config{
7835 MaxVersion: VersionTLS13,
7836 Bugs: ProtocolBugs{
7837 CustomUnencryptedExtension: expectedContents,
7838 },
7839 },
7840 shouldFail: true,
7841 expectedError: ":UNEXPECTED_EXTENSION:",
7842 // The shim must send an alert, but alerts at this point do not
7843 // get successfully decrypted by the runner.
7844 expectedLocalError: "local error: bad record MAC",
7845 })
7846 testCases = append(testCases, testCase{
7847 testType: clientTest,
7848 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7849 config: Config{
7850 MaxVersion: VersionTLS13,
7851 Bugs: ProtocolBugs{
7852 SendUnencryptedALPN: "foo",
7853 },
7854 },
7855 flags: []string{
7856 "-advertise-alpn", "\x03foo\x03bar",
7857 },
7858 shouldFail: true,
7859 expectedError: ":UNEXPECTED_EXTENSION:",
7860 // The shim must send an alert, but alerts at this point do not
7861 // get successfully decrypted by the runner.
7862 expectedLocalError: "local error: bad record MAC",
7863 })
David Benjamin0c40a962016-08-01 12:05:50 -04007864
7865 // Test a known but unoffered extension from the server.
7866 testCases = append(testCases, testCase{
7867 testType: clientTest,
7868 name: "UnofferedExtension-Client",
7869 config: Config{
7870 MaxVersion: VersionTLS12,
7871 Bugs: ProtocolBugs{
7872 SendALPN: "alpn",
7873 },
7874 },
7875 shouldFail: true,
7876 expectedError: ":UNEXPECTED_EXTENSION:",
7877 expectedLocalError: "remote error: unsupported extension",
7878 })
7879 testCases = append(testCases, testCase{
7880 testType: clientTest,
7881 name: "UnofferedExtension-Client-TLS13",
7882 config: Config{
7883 MaxVersion: VersionTLS13,
7884 Bugs: ProtocolBugs{
7885 SendALPN: "alpn",
7886 },
7887 },
7888 shouldFail: true,
7889 expectedError: ":UNEXPECTED_EXTENSION:",
7890 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007891 })
Adam Langley09505632015-07-30 18:10:13 -07007892}
7893
David Benjaminb36a3952015-12-01 18:53:13 -05007894func addRSAClientKeyExchangeTests() {
7895 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7896 testCases = append(testCases, testCase{
7897 testType: serverTest,
7898 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7899 config: Config{
7900 // Ensure the ClientHello version and final
7901 // version are different, to detect if the
7902 // server uses the wrong one.
7903 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007904 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007905 Bugs: ProtocolBugs{
7906 BadRSAClientKeyExchange: bad,
7907 },
7908 },
7909 shouldFail: true,
7910 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7911 })
7912 }
David Benjamine63d9d72016-09-19 18:27:34 -04007913
7914 // The server must compare whatever was in ClientHello.version for the
7915 // RSA premaster.
7916 testCases = append(testCases, testCase{
7917 testType: serverTest,
7918 name: "SendClientVersion-RSA",
7919 config: Config{
7920 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7921 Bugs: ProtocolBugs{
7922 SendClientVersion: 0x1234,
7923 },
7924 },
7925 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7926 })
David Benjaminb36a3952015-12-01 18:53:13 -05007927}
7928
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007929var testCurves = []struct {
7930 name string
7931 id CurveID
7932}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007933 {"P-256", CurveP256},
7934 {"P-384", CurveP384},
7935 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007936 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007937}
7938
Steven Valdez5440fe02016-07-18 12:40:30 -04007939const bogusCurve = 0x1234
7940
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007941func addCurveTests() {
7942 for _, curve := range testCurves {
7943 testCases = append(testCases, testCase{
7944 name: "CurveTest-Client-" + curve.name,
7945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007946 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007947 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7948 CurvePreferences: []CurveID{curve.id},
7949 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007950 flags: []string{
7951 "-enable-all-curves",
7952 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7953 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007954 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007955 })
7956 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007957 name: "CurveTest-Client-" + curve.name + "-TLS13",
7958 config: Config{
7959 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007960 CurvePreferences: []CurveID{curve.id},
7961 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007962 flags: []string{
7963 "-enable-all-curves",
7964 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7965 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007966 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007967 })
7968 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007969 testType: serverTest,
7970 name: "CurveTest-Server-" + curve.name,
7971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007972 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007973 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7974 CurvePreferences: []CurveID{curve.id},
7975 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007976 flags: []string{
7977 "-enable-all-curves",
7978 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7979 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007980 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007981 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007982 testCases = append(testCases, testCase{
7983 testType: serverTest,
7984 name: "CurveTest-Server-" + curve.name + "-TLS13",
7985 config: Config{
7986 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007987 CurvePreferences: []CurveID{curve.id},
7988 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007989 flags: []string{
7990 "-enable-all-curves",
7991 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7992 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007993 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007994 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007995 }
David Benjamin241ae832016-01-15 03:04:54 -05007996
7997 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007998 testCases = append(testCases, testCase{
7999 testType: serverTest,
8000 name: "UnknownCurve",
8001 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008002 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8004 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8005 },
8006 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008007
Steven Valdez803c77a2016-09-06 14:13:43 -04008008 // The server must be tolerant to bogus curves.
8009 testCases = append(testCases, testCase{
8010 testType: serverTest,
8011 name: "UnknownCurve-TLS13",
8012 config: Config{
8013 MaxVersion: VersionTLS13,
8014 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8015 },
8016 })
8017
David Benjamin4c3ddf72016-06-29 18:13:53 -04008018 // The server must not consider ECDHE ciphers when there are no
8019 // supported curves.
8020 testCases = append(testCases, testCase{
8021 testType: serverTest,
8022 name: "NoSupportedCurves",
8023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008024 MaxVersion: VersionTLS12,
8025 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8026 Bugs: ProtocolBugs{
8027 NoSupportedCurves: true,
8028 },
8029 },
8030 shouldFail: true,
8031 expectedError: ":NO_SHARED_CIPHER:",
8032 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008033 testCases = append(testCases, testCase{
8034 testType: serverTest,
8035 name: "NoSupportedCurves-TLS13",
8036 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008037 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008038 Bugs: ProtocolBugs{
8039 NoSupportedCurves: true,
8040 },
8041 },
8042 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008043 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008044 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008045
8046 // The server must fall back to another cipher when there are no
8047 // supported curves.
8048 testCases = append(testCases, testCase{
8049 testType: serverTest,
8050 name: "NoCommonCurves",
8051 config: Config{
8052 MaxVersion: VersionTLS12,
8053 CipherSuites: []uint16{
8054 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8055 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8056 },
8057 CurvePreferences: []CurveID{CurveP224},
8058 },
8059 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8060 })
8061
8062 // The client must reject bogus curves and disabled curves.
8063 testCases = append(testCases, testCase{
8064 name: "BadECDHECurve",
8065 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008066 MaxVersion: VersionTLS12,
8067 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8068 Bugs: ProtocolBugs{
8069 SendCurve: bogusCurve,
8070 },
8071 },
8072 shouldFail: true,
8073 expectedError: ":WRONG_CURVE:",
8074 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008075 testCases = append(testCases, testCase{
8076 name: "BadECDHECurve-TLS13",
8077 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008078 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008079 Bugs: ProtocolBugs{
8080 SendCurve: bogusCurve,
8081 },
8082 },
8083 shouldFail: true,
8084 expectedError: ":WRONG_CURVE:",
8085 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008086
8087 testCases = append(testCases, testCase{
8088 name: "UnsupportedCurve",
8089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008090 MaxVersion: VersionTLS12,
8091 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8092 CurvePreferences: []CurveID{CurveP256},
8093 Bugs: ProtocolBugs{
8094 IgnorePeerCurvePreferences: true,
8095 },
8096 },
8097 flags: []string{"-p384-only"},
8098 shouldFail: true,
8099 expectedError: ":WRONG_CURVE:",
8100 })
8101
David Benjamin4f921572016-07-17 14:20:10 +02008102 testCases = append(testCases, testCase{
8103 // TODO(davidben): Add a TLS 1.3 version where
8104 // HelloRetryRequest requests an unsupported curve.
8105 name: "UnsupportedCurve-ServerHello-TLS13",
8106 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008107 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008108 CurvePreferences: []CurveID{CurveP384},
8109 Bugs: ProtocolBugs{
8110 SendCurve: CurveP256,
8111 },
8112 },
8113 flags: []string{"-p384-only"},
8114 shouldFail: true,
8115 expectedError: ":WRONG_CURVE:",
8116 })
8117
David Benjamin4c3ddf72016-06-29 18:13:53 -04008118 // Test invalid curve points.
8119 testCases = append(testCases, testCase{
8120 name: "InvalidECDHPoint-Client",
8121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008122 MaxVersion: VersionTLS12,
8123 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8124 CurvePreferences: []CurveID{CurveP256},
8125 Bugs: ProtocolBugs{
8126 InvalidECDHPoint: true,
8127 },
8128 },
8129 shouldFail: true,
8130 expectedError: ":INVALID_ENCODING:",
8131 })
8132 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008133 name: "InvalidECDHPoint-Client-TLS13",
8134 config: Config{
8135 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008136 CurvePreferences: []CurveID{CurveP256},
8137 Bugs: ProtocolBugs{
8138 InvalidECDHPoint: true,
8139 },
8140 },
8141 shouldFail: true,
8142 expectedError: ":INVALID_ENCODING:",
8143 })
8144 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008145 testType: serverTest,
8146 name: "InvalidECDHPoint-Server",
8147 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008148 MaxVersion: VersionTLS12,
8149 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8150 CurvePreferences: []CurveID{CurveP256},
8151 Bugs: ProtocolBugs{
8152 InvalidECDHPoint: true,
8153 },
8154 },
8155 shouldFail: true,
8156 expectedError: ":INVALID_ENCODING:",
8157 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008158 testCases = append(testCases, testCase{
8159 testType: serverTest,
8160 name: "InvalidECDHPoint-Server-TLS13",
8161 config: Config{
8162 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008163 CurvePreferences: []CurveID{CurveP256},
8164 Bugs: ProtocolBugs{
8165 InvalidECDHPoint: true,
8166 },
8167 },
8168 shouldFail: true,
8169 expectedError: ":INVALID_ENCODING:",
8170 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008171
8172 // The previous curve ID should be reported on TLS 1.2 resumption.
8173 testCases = append(testCases, testCase{
8174 name: "CurveID-Resume-Client",
8175 config: Config{
8176 MaxVersion: VersionTLS12,
8177 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8178 CurvePreferences: []CurveID{CurveX25519},
8179 },
8180 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8181 resumeSession: true,
8182 })
8183 testCases = append(testCases, testCase{
8184 testType: serverTest,
8185 name: "CurveID-Resume-Server",
8186 config: Config{
8187 MaxVersion: VersionTLS12,
8188 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8189 CurvePreferences: []CurveID{CurveX25519},
8190 },
8191 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8192 resumeSession: true,
8193 })
8194
8195 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8196 // one should be reported.
8197 testCases = append(testCases, testCase{
8198 name: "CurveID-Resume-Client-TLS13",
8199 config: Config{
8200 MaxVersion: VersionTLS13,
8201 CurvePreferences: []CurveID{CurveX25519},
8202 },
8203 resumeConfig: &Config{
8204 MaxVersion: VersionTLS13,
8205 CurvePreferences: []CurveID{CurveP256},
8206 },
8207 flags: []string{
8208 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8209 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8210 },
8211 resumeSession: true,
8212 })
8213 testCases = append(testCases, testCase{
8214 testType: serverTest,
8215 name: "CurveID-Resume-Server-TLS13",
8216 config: Config{
8217 MaxVersion: VersionTLS13,
8218 CurvePreferences: []CurveID{CurveX25519},
8219 },
8220 resumeConfig: &Config{
8221 MaxVersion: VersionTLS13,
8222 CurvePreferences: []CurveID{CurveP256},
8223 },
8224 flags: []string{
8225 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8226 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8227 },
8228 resumeSession: true,
8229 })
David Benjamina81967b2016-12-22 09:16:57 -05008230
8231 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8232 testCases = append(testCases, testCase{
8233 name: "PointFormat-ServerHello-TLS12",
8234 config: Config{
8235 MaxVersion: VersionTLS12,
8236 Bugs: ProtocolBugs{
8237 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8238 },
8239 },
8240 })
8241 testCases = append(testCases, testCase{
8242 name: "PointFormat-EncryptedExtensions-TLS13",
8243 config: Config{
8244 MaxVersion: VersionTLS13,
8245 Bugs: ProtocolBugs{
8246 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8247 },
8248 },
8249 shouldFail: true,
8250 expectedError: ":ERROR_PARSING_EXTENSION:",
8251 })
8252
8253 // Test that we tolerate unknown point formats, as long as
8254 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8255 // check they are still functional.
8256 testCases = append(testCases, testCase{
8257 name: "PointFormat-Client-Tolerance",
8258 config: Config{
8259 MaxVersion: VersionTLS12,
8260 Bugs: ProtocolBugs{
8261 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8262 },
8263 },
8264 })
8265 testCases = append(testCases, testCase{
8266 testType: serverTest,
8267 name: "PointFormat-Server-Tolerance",
8268 config: Config{
8269 MaxVersion: VersionTLS12,
8270 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8271 Bugs: ProtocolBugs{
8272 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8273 },
8274 },
8275 })
8276
8277 // Test TLS 1.2 does not require the point format extension to be
8278 // present.
8279 testCases = append(testCases, testCase{
8280 name: "PointFormat-Client-Missing",
8281 config: Config{
8282 MaxVersion: VersionTLS12,
8283 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8284 Bugs: ProtocolBugs{
8285 SendSupportedPointFormats: []byte{},
8286 },
8287 },
8288 })
8289 testCases = append(testCases, testCase{
8290 testType: serverTest,
8291 name: "PointFormat-Server-Missing",
8292 config: Config{
8293 MaxVersion: VersionTLS12,
8294 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8295 Bugs: ProtocolBugs{
8296 SendSupportedPointFormats: []byte{},
8297 },
8298 },
8299 })
8300
8301 // If the point format extension is present, uncompressed points must be
8302 // offered. BoringSSL requires this whether or not ECDHE is used.
8303 testCases = append(testCases, testCase{
8304 name: "PointFormat-Client-MissingUncompressed",
8305 config: Config{
8306 MaxVersion: VersionTLS12,
8307 Bugs: ProtocolBugs{
8308 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8309 },
8310 },
8311 shouldFail: true,
8312 expectedError: ":ERROR_PARSING_EXTENSION:",
8313 })
8314 testCases = append(testCases, testCase{
8315 testType: serverTest,
8316 name: "PointFormat-Server-MissingUncompressed",
8317 config: Config{
8318 MaxVersion: VersionTLS12,
8319 Bugs: ProtocolBugs{
8320 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8321 },
8322 },
8323 shouldFail: true,
8324 expectedError: ":ERROR_PARSING_EXTENSION:",
8325 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008326}
8327
David Benjaminc9ae27c2016-06-24 22:56:37 -04008328func addTLS13RecordTests() {
8329 testCases = append(testCases, testCase{
8330 name: "TLS13-RecordPadding",
8331 config: Config{
8332 MaxVersion: VersionTLS13,
8333 MinVersion: VersionTLS13,
8334 Bugs: ProtocolBugs{
8335 RecordPadding: 10,
8336 },
8337 },
8338 })
8339
8340 testCases = append(testCases, testCase{
8341 name: "TLS13-EmptyRecords",
8342 config: Config{
8343 MaxVersion: VersionTLS13,
8344 MinVersion: VersionTLS13,
8345 Bugs: ProtocolBugs{
8346 OmitRecordContents: true,
8347 },
8348 },
8349 shouldFail: true,
8350 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8351 })
8352
8353 testCases = append(testCases, testCase{
8354 name: "TLS13-OnlyPadding",
8355 config: Config{
8356 MaxVersion: VersionTLS13,
8357 MinVersion: VersionTLS13,
8358 Bugs: ProtocolBugs{
8359 OmitRecordContents: true,
8360 RecordPadding: 10,
8361 },
8362 },
8363 shouldFail: true,
8364 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8365 })
8366
8367 testCases = append(testCases, testCase{
8368 name: "TLS13-WrongOuterRecord",
8369 config: Config{
8370 MaxVersion: VersionTLS13,
8371 MinVersion: VersionTLS13,
8372 Bugs: ProtocolBugs{
8373 OuterRecordType: recordTypeHandshake,
8374 },
8375 },
8376 shouldFail: true,
8377 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8378 })
8379}
8380
Steven Valdez5b986082016-09-01 12:29:49 -04008381func addSessionTicketTests() {
8382 testCases = append(testCases, testCase{
8383 // In TLS 1.2 and below, empty NewSessionTicket messages
8384 // mean the server changed its mind on sending a ticket.
8385 name: "SendEmptySessionTicket",
8386 config: Config{
8387 MaxVersion: VersionTLS12,
8388 Bugs: ProtocolBugs{
8389 SendEmptySessionTicket: true,
8390 },
8391 },
8392 flags: []string{"-expect-no-session"},
8393 })
8394
8395 // Test that the server ignores unknown PSK modes.
8396 testCases = append(testCases, testCase{
8397 testType: serverTest,
8398 name: "TLS13-SendUnknownModeSessionTicket-Server",
8399 config: Config{
8400 MaxVersion: VersionTLS13,
8401 Bugs: ProtocolBugs{
8402 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008403 },
8404 },
8405 resumeSession: true,
8406 expectedResumeVersion: VersionTLS13,
8407 })
8408
Steven Valdeza833c352016-11-01 13:39:36 -04008409 // Test that the server does not send session tickets with no matching key exchange mode.
8410 testCases = append(testCases, testCase{
8411 testType: serverTest,
8412 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8413 config: Config{
8414 MaxVersion: VersionTLS13,
8415 Bugs: ProtocolBugs{
8416 SendPSKKeyExchangeModes: []byte{0x1a},
8417 ExpectNoNewSessionTicket: true,
8418 },
8419 },
8420 })
8421
8422 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008423 testCases = append(testCases, testCase{
8424 testType: serverTest,
8425 name: "TLS13-SendBadKEModeSessionTicket-Server",
8426 config: Config{
8427 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008428 },
8429 resumeConfig: &Config{
8430 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008431 Bugs: ProtocolBugs{
8432 SendPSKKeyExchangeModes: []byte{0x1a},
8433 },
8434 },
8435 resumeSession: true,
8436 expectResumeRejected: true,
8437 })
8438
Steven Valdeza833c352016-11-01 13:39:36 -04008439 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008440 testCases = append(testCases, testCase{
8441 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008442 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008443 config: Config{
8444 MaxVersion: VersionTLS13,
8445 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008446 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008447 },
8448 },
Steven Valdeza833c352016-11-01 13:39:36 -04008449 resumeSession: true,
8450 flags: []string{
8451 "-resumption-delay", "10",
8452 },
Steven Valdez5b986082016-09-01 12:29:49 -04008453 })
8454
Steven Valdeza833c352016-11-01 13:39:36 -04008455 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008456 testCases = append(testCases, testCase{
8457 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008458 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008459 config: Config{
8460 MaxVersion: VersionTLS13,
8461 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008462 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008463 },
8464 },
Steven Valdeza833c352016-11-01 13:39:36 -04008465 resumeSession: true,
8466 shouldFail: true,
8467 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008468 })
8469
Steven Valdez08b65f42016-12-07 15:29:45 -05008470 testCases = append(testCases, testCase{
8471 testType: clientTest,
8472 name: "TLS13-SendTicketEarlyDataInfo",
8473 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008474 MaxVersion: VersionTLS13,
8475 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008476 },
8477 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008478 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008479 "-expect-early-data-info",
8480 },
8481 })
8482
David Benjamin9b160662017-01-25 19:53:43 -05008483 // Test that 0-RTT tickets are ignored in clients unless opted in.
8484 testCases = append(testCases, testCase{
8485 testType: clientTest,
8486 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8487 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008488 MaxVersion: VersionTLS13,
8489 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008490 },
8491 })
8492
Steven Valdez08b65f42016-12-07 15:29:45 -05008493 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008494 testType: clientTest,
8495 name: "TLS13-DuplicateTicketEarlyDataInfo",
8496 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008497 MaxVersion: VersionTLS13,
8498 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008499 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008500 DuplicateTicketEarlyDataInfo: true,
8501 },
8502 },
8503 shouldFail: true,
8504 expectedError: ":DUPLICATE_EXTENSION:",
8505 expectedLocalError: "remote error: illegal parameter",
8506 })
8507
8508 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008509 testType: serverTest,
8510 name: "TLS13-ExpectTicketEarlyDataInfo",
8511 config: Config{
8512 MaxVersion: VersionTLS13,
8513 Bugs: ProtocolBugs{
8514 ExpectTicketEarlyDataInfo: true,
8515 },
8516 },
8517 flags: []string{
8518 "-enable-early-data",
8519 },
8520 })
David Benjamin17b30832017-01-28 14:00:32 -05008521
8522 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8523 // is honored.
8524 testCases = append(testCases, testCase{
8525 testType: clientTest,
8526 name: "TLS13-HonorServerSessionTicketLifetime",
8527 config: Config{
8528 MaxVersion: VersionTLS13,
8529 Bugs: ProtocolBugs{
8530 SendTicketLifetime: 20 * time.Second,
8531 },
8532 },
8533 flags: []string{
8534 "-resumption-delay", "19",
8535 },
8536 resumeSession: true,
8537 })
8538 testCases = append(testCases, testCase{
8539 testType: clientTest,
8540 name: "TLS13-HonorServerSessionTicketLifetime-2",
8541 config: Config{
8542 MaxVersion: VersionTLS13,
8543 Bugs: ProtocolBugs{
8544 SendTicketLifetime: 20 * time.Second,
8545 // The client should not offer the expired session.
8546 ExpectNoTLS13PSK: true,
8547 },
8548 },
8549 flags: []string{
8550 "-resumption-delay", "21",
8551 },
David Benjamin023d4192017-02-06 13:49:07 -05008552 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008553 expectResumeRejected: true,
8554 })
Steven Valdez5b986082016-09-01 12:29:49 -04008555}
8556
David Benjamin82261be2016-07-07 14:32:50 -07008557func addChangeCipherSpecTests() {
8558 // Test missing ChangeCipherSpecs.
8559 testCases = append(testCases, testCase{
8560 name: "SkipChangeCipherSpec-Client",
8561 config: Config{
8562 MaxVersion: VersionTLS12,
8563 Bugs: ProtocolBugs{
8564 SkipChangeCipherSpec: true,
8565 },
8566 },
8567 shouldFail: true,
8568 expectedError: ":UNEXPECTED_RECORD:",
8569 })
8570 testCases = append(testCases, testCase{
8571 testType: serverTest,
8572 name: "SkipChangeCipherSpec-Server",
8573 config: Config{
8574 MaxVersion: VersionTLS12,
8575 Bugs: ProtocolBugs{
8576 SkipChangeCipherSpec: true,
8577 },
8578 },
8579 shouldFail: true,
8580 expectedError: ":UNEXPECTED_RECORD:",
8581 })
8582 testCases = append(testCases, testCase{
8583 testType: serverTest,
8584 name: "SkipChangeCipherSpec-Server-NPN",
8585 config: Config{
8586 MaxVersion: VersionTLS12,
8587 NextProtos: []string{"bar"},
8588 Bugs: ProtocolBugs{
8589 SkipChangeCipherSpec: true,
8590 },
8591 },
8592 flags: []string{
8593 "-advertise-npn", "\x03foo\x03bar\x03baz",
8594 },
8595 shouldFail: true,
8596 expectedError: ":UNEXPECTED_RECORD:",
8597 })
8598
8599 // Test synchronization between the handshake and ChangeCipherSpec.
8600 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8601 // rejected. Test both with and without handshake packing to handle both
8602 // when the partial post-CCS message is in its own record and when it is
8603 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008604 for _, packed := range []bool{false, true} {
8605 var suffix string
8606 if packed {
8607 suffix = "-Packed"
8608 }
8609
8610 testCases = append(testCases, testCase{
8611 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8612 config: Config{
8613 MaxVersion: VersionTLS12,
8614 Bugs: ProtocolBugs{
8615 FragmentAcrossChangeCipherSpec: true,
8616 PackHandshakeFlight: packed,
8617 },
8618 },
8619 shouldFail: true,
8620 expectedError: ":UNEXPECTED_RECORD:",
8621 })
8622 testCases = append(testCases, testCase{
8623 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8624 config: Config{
8625 MaxVersion: VersionTLS12,
8626 },
8627 resumeSession: true,
8628 resumeConfig: &Config{
8629 MaxVersion: VersionTLS12,
8630 Bugs: ProtocolBugs{
8631 FragmentAcrossChangeCipherSpec: true,
8632 PackHandshakeFlight: packed,
8633 },
8634 },
8635 shouldFail: true,
8636 expectedError: ":UNEXPECTED_RECORD:",
8637 })
8638 testCases = append(testCases, testCase{
8639 testType: serverTest,
8640 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8641 config: Config{
8642 MaxVersion: VersionTLS12,
8643 Bugs: ProtocolBugs{
8644 FragmentAcrossChangeCipherSpec: true,
8645 PackHandshakeFlight: packed,
8646 },
8647 },
8648 shouldFail: true,
8649 expectedError: ":UNEXPECTED_RECORD:",
8650 })
8651 testCases = append(testCases, testCase{
8652 testType: serverTest,
8653 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8654 config: Config{
8655 MaxVersion: VersionTLS12,
8656 },
8657 resumeSession: true,
8658 resumeConfig: &Config{
8659 MaxVersion: VersionTLS12,
8660 Bugs: ProtocolBugs{
8661 FragmentAcrossChangeCipherSpec: true,
8662 PackHandshakeFlight: packed,
8663 },
8664 },
8665 shouldFail: true,
8666 expectedError: ":UNEXPECTED_RECORD:",
8667 })
8668 testCases = append(testCases, testCase{
8669 testType: serverTest,
8670 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8671 config: Config{
8672 MaxVersion: VersionTLS12,
8673 NextProtos: []string{"bar"},
8674 Bugs: ProtocolBugs{
8675 FragmentAcrossChangeCipherSpec: true,
8676 PackHandshakeFlight: packed,
8677 },
8678 },
8679 flags: []string{
8680 "-advertise-npn", "\x03foo\x03bar\x03baz",
8681 },
8682 shouldFail: true,
8683 expectedError: ":UNEXPECTED_RECORD:",
8684 })
8685 }
8686
David Benjamin61672812016-07-14 23:10:43 -04008687 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8688 // messages in the handshake queue. Do this by testing the server
8689 // reading the client Finished, reversing the flight so Finished comes
8690 // first.
8691 testCases = append(testCases, testCase{
8692 protocol: dtls,
8693 testType: serverTest,
8694 name: "SendUnencryptedFinished-DTLS",
8695 config: Config{
8696 MaxVersion: VersionTLS12,
8697 Bugs: ProtocolBugs{
8698 SendUnencryptedFinished: true,
8699 ReverseHandshakeFragments: true,
8700 },
8701 },
8702 shouldFail: true,
8703 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8704 })
8705
Steven Valdez143e8b32016-07-11 13:19:03 -04008706 // Test synchronization between encryption changes and the handshake in
8707 // TLS 1.3, where ChangeCipherSpec is implicit.
8708 testCases = append(testCases, testCase{
8709 name: "PartialEncryptedExtensionsWithServerHello",
8710 config: Config{
8711 MaxVersion: VersionTLS13,
8712 Bugs: ProtocolBugs{
8713 PartialEncryptedExtensionsWithServerHello: true,
8714 },
8715 },
8716 shouldFail: true,
8717 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8718 })
8719 testCases = append(testCases, testCase{
8720 testType: serverTest,
8721 name: "PartialClientFinishedWithClientHello",
8722 config: Config{
8723 MaxVersion: VersionTLS13,
8724 Bugs: ProtocolBugs{
8725 PartialClientFinishedWithClientHello: true,
8726 },
8727 },
8728 shouldFail: true,
8729 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8730 })
8731
David Benjamin82261be2016-07-07 14:32:50 -07008732 // Test that early ChangeCipherSpecs are handled correctly.
8733 testCases = append(testCases, testCase{
8734 testType: serverTest,
8735 name: "EarlyChangeCipherSpec-server-1",
8736 config: Config{
8737 MaxVersion: VersionTLS12,
8738 Bugs: ProtocolBugs{
8739 EarlyChangeCipherSpec: 1,
8740 },
8741 },
8742 shouldFail: true,
8743 expectedError: ":UNEXPECTED_RECORD:",
8744 })
8745 testCases = append(testCases, testCase{
8746 testType: serverTest,
8747 name: "EarlyChangeCipherSpec-server-2",
8748 config: Config{
8749 MaxVersion: VersionTLS12,
8750 Bugs: ProtocolBugs{
8751 EarlyChangeCipherSpec: 2,
8752 },
8753 },
8754 shouldFail: true,
8755 expectedError: ":UNEXPECTED_RECORD:",
8756 })
8757 testCases = append(testCases, testCase{
8758 protocol: dtls,
8759 name: "StrayChangeCipherSpec",
8760 config: Config{
8761 // TODO(davidben): Once DTLS 1.3 exists, test
8762 // that stray ChangeCipherSpec messages are
8763 // rejected.
8764 MaxVersion: VersionTLS12,
8765 Bugs: ProtocolBugs{
8766 StrayChangeCipherSpec: true,
8767 },
8768 },
8769 })
8770
8771 // Test that the contents of ChangeCipherSpec are checked.
8772 testCases = append(testCases, testCase{
8773 name: "BadChangeCipherSpec-1",
8774 config: Config{
8775 MaxVersion: VersionTLS12,
8776 Bugs: ProtocolBugs{
8777 BadChangeCipherSpec: []byte{2},
8778 },
8779 },
8780 shouldFail: true,
8781 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8782 })
8783 testCases = append(testCases, testCase{
8784 name: "BadChangeCipherSpec-2",
8785 config: Config{
8786 MaxVersion: VersionTLS12,
8787 Bugs: ProtocolBugs{
8788 BadChangeCipherSpec: []byte{1, 1},
8789 },
8790 },
8791 shouldFail: true,
8792 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8793 })
8794 testCases = append(testCases, testCase{
8795 protocol: dtls,
8796 name: "BadChangeCipherSpec-DTLS-1",
8797 config: Config{
8798 MaxVersion: VersionTLS12,
8799 Bugs: ProtocolBugs{
8800 BadChangeCipherSpec: []byte{2},
8801 },
8802 },
8803 shouldFail: true,
8804 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8805 })
8806 testCases = append(testCases, testCase{
8807 protocol: dtls,
8808 name: "BadChangeCipherSpec-DTLS-2",
8809 config: Config{
8810 MaxVersion: VersionTLS12,
8811 Bugs: ProtocolBugs{
8812 BadChangeCipherSpec: []byte{1, 1},
8813 },
8814 },
8815 shouldFail: true,
8816 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8817 })
8818}
8819
David Benjamincd2c8062016-09-09 11:28:16 -04008820type perMessageTest struct {
8821 messageType uint8
8822 test testCase
8823}
8824
8825// makePerMessageTests returns a series of test templates which cover each
8826// message in the TLS handshake. These may be used with bugs like
8827// WrongMessageType to fully test a per-message bug.
8828func makePerMessageTests() []perMessageTest {
8829 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008830 for _, protocol := range []protocol{tls, dtls} {
8831 var suffix string
8832 if protocol == dtls {
8833 suffix = "-DTLS"
8834 }
8835
David Benjamincd2c8062016-09-09 11:28:16 -04008836 ret = append(ret, perMessageTest{
8837 messageType: typeClientHello,
8838 test: testCase{
8839 protocol: protocol,
8840 testType: serverTest,
8841 name: "ClientHello" + suffix,
8842 config: Config{
8843 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008844 },
8845 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008846 })
8847
8848 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008849 ret = append(ret, perMessageTest{
8850 messageType: typeHelloVerifyRequest,
8851 test: testCase{
8852 protocol: protocol,
8853 name: "HelloVerifyRequest" + suffix,
8854 config: Config{
8855 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008856 },
8857 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008858 })
8859 }
8860
David Benjamincd2c8062016-09-09 11:28:16 -04008861 ret = append(ret, perMessageTest{
8862 messageType: typeServerHello,
8863 test: testCase{
8864 protocol: protocol,
8865 name: "ServerHello" + suffix,
8866 config: Config{
8867 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008868 },
8869 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008870 })
8871
David Benjamincd2c8062016-09-09 11:28:16 -04008872 ret = append(ret, perMessageTest{
8873 messageType: typeCertificate,
8874 test: testCase{
8875 protocol: protocol,
8876 name: "ServerCertificate" + suffix,
8877 config: Config{
8878 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008879 },
8880 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008881 })
8882
David Benjamincd2c8062016-09-09 11:28:16 -04008883 ret = append(ret, perMessageTest{
8884 messageType: typeCertificateStatus,
8885 test: testCase{
8886 protocol: protocol,
8887 name: "CertificateStatus" + suffix,
8888 config: Config{
8889 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008890 },
David Benjamincd2c8062016-09-09 11:28:16 -04008891 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008892 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008893 })
8894
David Benjamincd2c8062016-09-09 11:28:16 -04008895 ret = append(ret, perMessageTest{
8896 messageType: typeServerKeyExchange,
8897 test: testCase{
8898 protocol: protocol,
8899 name: "ServerKeyExchange" + suffix,
8900 config: Config{
8901 MaxVersion: VersionTLS12,
8902 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008903 },
8904 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008905 })
8906
David Benjamincd2c8062016-09-09 11:28:16 -04008907 ret = append(ret, perMessageTest{
8908 messageType: typeCertificateRequest,
8909 test: testCase{
8910 protocol: protocol,
8911 name: "CertificateRequest" + suffix,
8912 config: Config{
8913 MaxVersion: VersionTLS12,
8914 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008915 },
8916 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008917 })
8918
David Benjamincd2c8062016-09-09 11:28:16 -04008919 ret = append(ret, perMessageTest{
8920 messageType: typeServerHelloDone,
8921 test: testCase{
8922 protocol: protocol,
8923 name: "ServerHelloDone" + suffix,
8924 config: Config{
8925 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008926 },
8927 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008928 })
8929
David Benjamincd2c8062016-09-09 11:28:16 -04008930 ret = append(ret, perMessageTest{
8931 messageType: typeCertificate,
8932 test: testCase{
8933 testType: serverTest,
8934 protocol: protocol,
8935 name: "ClientCertificate" + suffix,
8936 config: Config{
8937 Certificates: []Certificate{rsaCertificate},
8938 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008939 },
David Benjamincd2c8062016-09-09 11:28:16 -04008940 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008941 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008942 })
8943
David Benjamincd2c8062016-09-09 11:28:16 -04008944 ret = append(ret, perMessageTest{
8945 messageType: typeCertificateVerify,
8946 test: testCase{
8947 testType: serverTest,
8948 protocol: protocol,
8949 name: "CertificateVerify" + suffix,
8950 config: Config{
8951 Certificates: []Certificate{rsaCertificate},
8952 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008953 },
David Benjamincd2c8062016-09-09 11:28:16 -04008954 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008955 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008956 })
8957
David Benjamincd2c8062016-09-09 11:28:16 -04008958 ret = append(ret, perMessageTest{
8959 messageType: typeClientKeyExchange,
8960 test: testCase{
8961 testType: serverTest,
8962 protocol: protocol,
8963 name: "ClientKeyExchange" + suffix,
8964 config: Config{
8965 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008966 },
8967 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008968 })
8969
8970 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008971 ret = append(ret, perMessageTest{
8972 messageType: typeNextProtocol,
8973 test: testCase{
8974 testType: serverTest,
8975 protocol: protocol,
8976 name: "NextProtocol" + suffix,
8977 config: Config{
8978 MaxVersion: VersionTLS12,
8979 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008980 },
David Benjamincd2c8062016-09-09 11:28:16 -04008981 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008982 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008983 })
8984
David Benjamincd2c8062016-09-09 11:28:16 -04008985 ret = append(ret, perMessageTest{
8986 messageType: typeChannelID,
8987 test: testCase{
8988 testType: serverTest,
8989 protocol: protocol,
8990 name: "ChannelID" + suffix,
8991 config: Config{
8992 MaxVersion: VersionTLS12,
8993 ChannelID: channelIDKey,
8994 },
8995 flags: []string{
8996 "-expect-channel-id",
8997 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008998 },
8999 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009000 })
9001 }
9002
David Benjamincd2c8062016-09-09 11:28:16 -04009003 ret = append(ret, perMessageTest{
9004 messageType: typeFinished,
9005 test: testCase{
9006 testType: serverTest,
9007 protocol: protocol,
9008 name: "ClientFinished" + suffix,
9009 config: Config{
9010 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009011 },
9012 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009013 })
9014
David Benjamincd2c8062016-09-09 11:28:16 -04009015 ret = append(ret, perMessageTest{
9016 messageType: typeNewSessionTicket,
9017 test: testCase{
9018 protocol: protocol,
9019 name: "NewSessionTicket" + suffix,
9020 config: Config{
9021 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009022 },
9023 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009024 })
9025
David Benjamincd2c8062016-09-09 11:28:16 -04009026 ret = append(ret, perMessageTest{
9027 messageType: typeFinished,
9028 test: testCase{
9029 protocol: protocol,
9030 name: "ServerFinished" + suffix,
9031 config: Config{
9032 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009033 },
9034 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009035 })
9036
9037 }
David Benjamincd2c8062016-09-09 11:28:16 -04009038
9039 ret = append(ret, perMessageTest{
9040 messageType: typeClientHello,
9041 test: testCase{
9042 testType: serverTest,
9043 name: "TLS13-ClientHello",
9044 config: Config{
9045 MaxVersion: VersionTLS13,
9046 },
9047 },
9048 })
9049
9050 ret = append(ret, perMessageTest{
9051 messageType: typeServerHello,
9052 test: testCase{
9053 name: "TLS13-ServerHello",
9054 config: Config{
9055 MaxVersion: VersionTLS13,
9056 },
9057 },
9058 })
9059
9060 ret = append(ret, perMessageTest{
9061 messageType: typeEncryptedExtensions,
9062 test: testCase{
9063 name: "TLS13-EncryptedExtensions",
9064 config: Config{
9065 MaxVersion: VersionTLS13,
9066 },
9067 },
9068 })
9069
9070 ret = append(ret, perMessageTest{
9071 messageType: typeCertificateRequest,
9072 test: testCase{
9073 name: "TLS13-CertificateRequest",
9074 config: Config{
9075 MaxVersion: VersionTLS13,
9076 ClientAuth: RequireAnyClientCert,
9077 },
9078 },
9079 })
9080
9081 ret = append(ret, perMessageTest{
9082 messageType: typeCertificate,
9083 test: testCase{
9084 name: "TLS13-ServerCertificate",
9085 config: Config{
9086 MaxVersion: VersionTLS13,
9087 },
9088 },
9089 })
9090
9091 ret = append(ret, perMessageTest{
9092 messageType: typeCertificateVerify,
9093 test: testCase{
9094 name: "TLS13-ServerCertificateVerify",
9095 config: Config{
9096 MaxVersion: VersionTLS13,
9097 },
9098 },
9099 })
9100
9101 ret = append(ret, perMessageTest{
9102 messageType: typeFinished,
9103 test: testCase{
9104 name: "TLS13-ServerFinished",
9105 config: Config{
9106 MaxVersion: VersionTLS13,
9107 },
9108 },
9109 })
9110
9111 ret = append(ret, perMessageTest{
9112 messageType: typeCertificate,
9113 test: testCase{
9114 testType: serverTest,
9115 name: "TLS13-ClientCertificate",
9116 config: Config{
9117 Certificates: []Certificate{rsaCertificate},
9118 MaxVersion: VersionTLS13,
9119 },
9120 flags: []string{"-require-any-client-certificate"},
9121 },
9122 })
9123
9124 ret = append(ret, perMessageTest{
9125 messageType: typeCertificateVerify,
9126 test: testCase{
9127 testType: serverTest,
9128 name: "TLS13-ClientCertificateVerify",
9129 config: Config{
9130 Certificates: []Certificate{rsaCertificate},
9131 MaxVersion: VersionTLS13,
9132 },
9133 flags: []string{"-require-any-client-certificate"},
9134 },
9135 })
9136
9137 ret = append(ret, perMessageTest{
9138 messageType: typeFinished,
9139 test: testCase{
9140 testType: serverTest,
9141 name: "TLS13-ClientFinished",
9142 config: Config{
9143 MaxVersion: VersionTLS13,
9144 },
9145 },
9146 })
9147
9148 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009149}
9150
David Benjamincd2c8062016-09-09 11:28:16 -04009151func addWrongMessageTypeTests() {
9152 for _, t := range makePerMessageTests() {
9153 t.test.name = "WrongMessageType-" + t.test.name
9154 t.test.config.Bugs.SendWrongMessageType = t.messageType
9155 t.test.shouldFail = true
9156 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9157 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009158
David Benjamincd2c8062016-09-09 11:28:16 -04009159 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9160 // In TLS 1.3, a bad ServerHello means the client sends
9161 // an unencrypted alert while the server expects
9162 // encryption, so the alert is not readable by runner.
9163 t.test.expectedLocalError = "local error: bad record MAC"
9164 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009165
David Benjamincd2c8062016-09-09 11:28:16 -04009166 testCases = append(testCases, t.test)
9167 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009168}
9169
David Benjamin639846e2016-09-09 11:41:18 -04009170func addTrailingMessageDataTests() {
9171 for _, t := range makePerMessageTests() {
9172 t.test.name = "TrailingMessageData-" + t.test.name
9173 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9174 t.test.shouldFail = true
9175 t.test.expectedError = ":DECODE_ERROR:"
9176 t.test.expectedLocalError = "remote error: error decoding message"
9177
9178 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9179 // In TLS 1.3, a bad ServerHello means the client sends
9180 // an unencrypted alert while the server expects
9181 // encryption, so the alert is not readable by runner.
9182 t.test.expectedLocalError = "local error: bad record MAC"
9183 }
9184
9185 if t.messageType == typeFinished {
9186 // Bad Finished messages read as the verify data having
9187 // the wrong length.
9188 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9189 t.test.expectedLocalError = "remote error: error decrypting message"
9190 }
9191
9192 testCases = append(testCases, t.test)
9193 }
9194}
9195
Steven Valdez143e8b32016-07-11 13:19:03 -04009196func addTLS13HandshakeTests() {
9197 testCases = append(testCases, testCase{
9198 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009199 name: "NegotiatePSKResumption-TLS13",
9200 config: Config{
9201 MaxVersion: VersionTLS13,
9202 Bugs: ProtocolBugs{
9203 NegotiatePSKResumption: true,
9204 },
9205 },
9206 resumeSession: true,
9207 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009208 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009209 })
9210
9211 testCases = append(testCases, testCase{
9212 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009213 name: "MissingKeyShare-Client",
9214 config: Config{
9215 MaxVersion: VersionTLS13,
9216 Bugs: ProtocolBugs{
9217 MissingKeyShare: true,
9218 },
9219 },
9220 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009221 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009222 })
9223
9224 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009225 testType: serverTest,
9226 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009227 config: Config{
9228 MaxVersion: VersionTLS13,
9229 Bugs: ProtocolBugs{
9230 MissingKeyShare: true,
9231 },
9232 },
9233 shouldFail: true,
9234 expectedError: ":MISSING_KEY_SHARE:",
9235 })
9236
9237 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009238 testType: serverTest,
9239 name: "DuplicateKeyShares",
9240 config: Config{
9241 MaxVersion: VersionTLS13,
9242 Bugs: ProtocolBugs{
9243 DuplicateKeyShares: true,
9244 },
9245 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009246 shouldFail: true,
9247 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009248 })
9249
9250 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009251 testType: serverTest,
9252 name: "SkipEarlyData",
9253 config: Config{
9254 MaxVersion: VersionTLS13,
9255 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009256 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009257 },
9258 },
9259 })
9260
9261 testCases = append(testCases, testCase{
9262 testType: serverTest,
9263 name: "SkipEarlyData-OmitEarlyDataExtension",
9264 config: Config{
9265 MaxVersion: VersionTLS13,
9266 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009267 SendFakeEarlyDataLength: 4,
9268 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009269 },
9270 },
9271 shouldFail: true,
9272 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9273 })
9274
9275 testCases = append(testCases, testCase{
9276 testType: serverTest,
9277 name: "SkipEarlyData-TooMuchData",
9278 config: Config{
9279 MaxVersion: VersionTLS13,
9280 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009281 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009282 },
9283 },
9284 shouldFail: true,
9285 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9286 })
9287
9288 testCases = append(testCases, testCase{
9289 testType: serverTest,
9290 name: "SkipEarlyData-Interleaved",
9291 config: Config{
9292 MaxVersion: VersionTLS13,
9293 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009294 SendFakeEarlyDataLength: 4,
9295 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009296 },
9297 },
9298 shouldFail: true,
9299 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9300 })
9301
9302 testCases = append(testCases, testCase{
9303 testType: serverTest,
9304 name: "SkipEarlyData-EarlyDataInTLS12",
9305 config: Config{
9306 MaxVersion: VersionTLS13,
9307 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009308 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009309 },
9310 },
9311 shouldFail: true,
9312 expectedError: ":UNEXPECTED_RECORD:",
9313 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9314 })
9315
9316 testCases = append(testCases, testCase{
9317 testType: serverTest,
9318 name: "SkipEarlyData-HRR",
9319 config: Config{
9320 MaxVersion: VersionTLS13,
9321 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009322 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009323 },
9324 DefaultCurves: []CurveID{},
9325 },
9326 })
9327
9328 testCases = append(testCases, testCase{
9329 testType: serverTest,
9330 name: "SkipEarlyData-HRR-Interleaved",
9331 config: Config{
9332 MaxVersion: VersionTLS13,
9333 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009334 SendFakeEarlyDataLength: 4,
9335 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009336 },
9337 DefaultCurves: []CurveID{},
9338 },
9339 shouldFail: true,
9340 expectedError: ":UNEXPECTED_RECORD:",
9341 })
9342
9343 testCases = append(testCases, testCase{
9344 testType: serverTest,
9345 name: "SkipEarlyData-HRR-TooMuchData",
9346 config: Config{
9347 MaxVersion: VersionTLS13,
9348 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009349 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009350 },
9351 DefaultCurves: []CurveID{},
9352 },
9353 shouldFail: true,
9354 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9355 })
9356
9357 // Test that skipping early data looking for cleartext correctly
9358 // processes an alert record.
9359 testCases = append(testCases, testCase{
9360 testType: serverTest,
9361 name: "SkipEarlyData-HRR-FatalAlert",
9362 config: Config{
9363 MaxVersion: VersionTLS13,
9364 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009365 SendEarlyAlert: true,
9366 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009367 },
9368 DefaultCurves: []CurveID{},
9369 },
9370 shouldFail: true,
9371 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9372 })
9373
9374 testCases = append(testCases, testCase{
9375 testType: serverTest,
9376 name: "SkipEarlyData-SecondClientHelloEarlyData",
9377 config: Config{
9378 MaxVersion: VersionTLS13,
9379 Bugs: ProtocolBugs{
9380 SendEarlyDataOnSecondClientHello: true,
9381 },
9382 DefaultCurves: []CurveID{},
9383 },
9384 shouldFail: true,
9385 expectedLocalError: "remote error: bad record MAC",
9386 })
9387
9388 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009389 testType: clientTest,
9390 name: "EmptyEncryptedExtensions",
9391 config: Config{
9392 MaxVersion: VersionTLS13,
9393 Bugs: ProtocolBugs{
9394 EmptyEncryptedExtensions: true,
9395 },
9396 },
9397 shouldFail: true,
9398 expectedLocalError: "remote error: error decoding message",
9399 })
9400
9401 testCases = append(testCases, testCase{
9402 testType: clientTest,
9403 name: "EncryptedExtensionsWithKeyShare",
9404 config: Config{
9405 MaxVersion: VersionTLS13,
9406 Bugs: ProtocolBugs{
9407 EncryptedExtensionsWithKeyShare: true,
9408 },
9409 },
9410 shouldFail: true,
9411 expectedLocalError: "remote error: unsupported extension",
9412 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009413
9414 testCases = append(testCases, testCase{
9415 testType: serverTest,
9416 name: "SendHelloRetryRequest",
9417 config: Config{
9418 MaxVersion: VersionTLS13,
9419 // Require a HelloRetryRequest for every curve.
9420 DefaultCurves: []CurveID{},
9421 },
9422 expectedCurveID: CurveX25519,
9423 })
9424
9425 testCases = append(testCases, testCase{
9426 testType: serverTest,
9427 name: "SendHelloRetryRequest-2",
9428 config: Config{
9429 MaxVersion: VersionTLS13,
9430 DefaultCurves: []CurveID{CurveP384},
9431 },
9432 // Although the ClientHello did not predict our preferred curve,
9433 // we always select it whether it is predicted or not.
9434 expectedCurveID: CurveX25519,
9435 })
9436
9437 testCases = append(testCases, testCase{
9438 name: "UnknownCurve-HelloRetryRequest",
9439 config: Config{
9440 MaxVersion: VersionTLS13,
9441 // P-384 requires HelloRetryRequest in BoringSSL.
9442 CurvePreferences: []CurveID{CurveP384},
9443 Bugs: ProtocolBugs{
9444 SendHelloRetryRequestCurve: bogusCurve,
9445 },
9446 },
9447 shouldFail: true,
9448 expectedError: ":WRONG_CURVE:",
9449 })
9450
9451 testCases = append(testCases, testCase{
9452 name: "DisabledCurve-HelloRetryRequest",
9453 config: Config{
9454 MaxVersion: VersionTLS13,
9455 CurvePreferences: []CurveID{CurveP256},
9456 Bugs: ProtocolBugs{
9457 IgnorePeerCurvePreferences: true,
9458 },
9459 },
9460 flags: []string{"-p384-only"},
9461 shouldFail: true,
9462 expectedError: ":WRONG_CURVE:",
9463 })
9464
9465 testCases = append(testCases, testCase{
9466 name: "UnnecessaryHelloRetryRequest",
9467 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009468 MaxVersion: VersionTLS13,
9469 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009470 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009471 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009472 },
9473 },
9474 shouldFail: true,
9475 expectedError: ":WRONG_CURVE:",
9476 })
9477
9478 testCases = append(testCases, testCase{
9479 name: "SecondHelloRetryRequest",
9480 config: Config{
9481 MaxVersion: VersionTLS13,
9482 // P-384 requires HelloRetryRequest in BoringSSL.
9483 CurvePreferences: []CurveID{CurveP384},
9484 Bugs: ProtocolBugs{
9485 SecondHelloRetryRequest: true,
9486 },
9487 },
9488 shouldFail: true,
9489 expectedError: ":UNEXPECTED_MESSAGE:",
9490 })
9491
9492 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009493 name: "HelloRetryRequest-Empty",
9494 config: Config{
9495 MaxVersion: VersionTLS13,
9496 Bugs: ProtocolBugs{
9497 AlwaysSendHelloRetryRequest: true,
9498 },
9499 },
9500 shouldFail: true,
9501 expectedError: ":DECODE_ERROR:",
9502 })
9503
9504 testCases = append(testCases, testCase{
9505 name: "HelloRetryRequest-DuplicateCurve",
9506 config: Config{
9507 MaxVersion: VersionTLS13,
9508 // P-384 requires a HelloRetryRequest against BoringSSL's default
9509 // configuration. Assert this ExpectMissingKeyShare.
9510 CurvePreferences: []CurveID{CurveP384},
9511 Bugs: ProtocolBugs{
9512 ExpectMissingKeyShare: true,
9513 DuplicateHelloRetryRequestExtensions: true,
9514 },
9515 },
9516 shouldFail: true,
9517 expectedError: ":DUPLICATE_EXTENSION:",
9518 expectedLocalError: "remote error: illegal parameter",
9519 })
9520
9521 testCases = append(testCases, testCase{
9522 name: "HelloRetryRequest-Cookie",
9523 config: Config{
9524 MaxVersion: VersionTLS13,
9525 Bugs: ProtocolBugs{
9526 SendHelloRetryRequestCookie: []byte("cookie"),
9527 },
9528 },
9529 })
9530
9531 testCases = append(testCases, testCase{
9532 name: "HelloRetryRequest-DuplicateCookie",
9533 config: Config{
9534 MaxVersion: VersionTLS13,
9535 Bugs: ProtocolBugs{
9536 SendHelloRetryRequestCookie: []byte("cookie"),
9537 DuplicateHelloRetryRequestExtensions: true,
9538 },
9539 },
9540 shouldFail: true,
9541 expectedError: ":DUPLICATE_EXTENSION:",
9542 expectedLocalError: "remote error: illegal parameter",
9543 })
9544
9545 testCases = append(testCases, testCase{
9546 name: "HelloRetryRequest-EmptyCookie",
9547 config: Config{
9548 MaxVersion: VersionTLS13,
9549 Bugs: ProtocolBugs{
9550 SendHelloRetryRequestCookie: []byte{},
9551 },
9552 },
9553 shouldFail: true,
9554 expectedError: ":DECODE_ERROR:",
9555 })
9556
9557 testCases = append(testCases, testCase{
9558 name: "HelloRetryRequest-Cookie-Curve",
9559 config: Config{
9560 MaxVersion: VersionTLS13,
9561 // P-384 requires HelloRetryRequest in BoringSSL.
9562 CurvePreferences: []CurveID{CurveP384},
9563 Bugs: ProtocolBugs{
9564 SendHelloRetryRequestCookie: []byte("cookie"),
9565 ExpectMissingKeyShare: true,
9566 },
9567 },
9568 })
9569
9570 testCases = append(testCases, testCase{
9571 name: "HelloRetryRequest-Unknown",
9572 config: Config{
9573 MaxVersion: VersionTLS13,
9574 Bugs: ProtocolBugs{
9575 CustomHelloRetryRequestExtension: "extension",
9576 },
9577 },
9578 shouldFail: true,
9579 expectedError: ":UNEXPECTED_EXTENSION:",
9580 expectedLocalError: "remote error: unsupported extension",
9581 })
9582
9583 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009584 testType: serverTest,
9585 name: "SecondClientHelloMissingKeyShare",
9586 config: Config{
9587 MaxVersion: VersionTLS13,
9588 DefaultCurves: []CurveID{},
9589 Bugs: ProtocolBugs{
9590 SecondClientHelloMissingKeyShare: true,
9591 },
9592 },
9593 shouldFail: true,
9594 expectedError: ":MISSING_KEY_SHARE:",
9595 })
9596
9597 testCases = append(testCases, testCase{
9598 testType: serverTest,
9599 name: "SecondClientHelloWrongCurve",
9600 config: Config{
9601 MaxVersion: VersionTLS13,
9602 DefaultCurves: []CurveID{},
9603 Bugs: ProtocolBugs{
9604 MisinterpretHelloRetryRequestCurve: CurveP521,
9605 },
9606 },
9607 shouldFail: true,
9608 expectedError: ":WRONG_CURVE:",
9609 })
9610
9611 testCases = append(testCases, testCase{
9612 name: "HelloRetryRequestVersionMismatch",
9613 config: Config{
9614 MaxVersion: VersionTLS13,
9615 // P-384 requires HelloRetryRequest in BoringSSL.
9616 CurvePreferences: []CurveID{CurveP384},
9617 Bugs: ProtocolBugs{
9618 SendServerHelloVersion: 0x0305,
9619 },
9620 },
9621 shouldFail: true,
9622 expectedError: ":WRONG_VERSION_NUMBER:",
9623 })
9624
9625 testCases = append(testCases, testCase{
9626 name: "HelloRetryRequestCurveMismatch",
9627 config: Config{
9628 MaxVersion: VersionTLS13,
9629 // P-384 requires HelloRetryRequest in BoringSSL.
9630 CurvePreferences: []CurveID{CurveP384},
9631 Bugs: ProtocolBugs{
9632 // Send P-384 (correct) in the HelloRetryRequest.
9633 SendHelloRetryRequestCurve: CurveP384,
9634 // But send P-256 in the ServerHello.
9635 SendCurve: CurveP256,
9636 },
9637 },
9638 shouldFail: true,
9639 expectedError: ":WRONG_CURVE:",
9640 })
9641
9642 // Test the server selecting a curve that requires a HelloRetryRequest
9643 // without sending it.
9644 testCases = append(testCases, testCase{
9645 name: "SkipHelloRetryRequest",
9646 config: Config{
9647 MaxVersion: VersionTLS13,
9648 // P-384 requires HelloRetryRequest in BoringSSL.
9649 CurvePreferences: []CurveID{CurveP384},
9650 Bugs: ProtocolBugs{
9651 SkipHelloRetryRequest: true,
9652 },
9653 },
9654 shouldFail: true,
9655 expectedError: ":WRONG_CURVE:",
9656 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009657
9658 testCases = append(testCases, testCase{
9659 name: "TLS13-RequestContextInHandshake",
9660 config: Config{
9661 MaxVersion: VersionTLS13,
9662 MinVersion: VersionTLS13,
9663 ClientAuth: RequireAnyClientCert,
9664 Bugs: ProtocolBugs{
9665 SendRequestContext: []byte("request context"),
9666 },
9667 },
9668 flags: []string{
9669 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9670 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9671 },
9672 shouldFail: true,
9673 expectedError: ":DECODE_ERROR:",
9674 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009675
9676 testCases = append(testCases, testCase{
9677 testType: serverTest,
9678 name: "TLS13-TrailingKeyShareData",
9679 config: Config{
9680 MaxVersion: VersionTLS13,
9681 Bugs: ProtocolBugs{
9682 TrailingKeyShareData: true,
9683 },
9684 },
9685 shouldFail: true,
9686 expectedError: ":DECODE_ERROR:",
9687 })
David Benjamin7f78df42016-10-05 22:33:19 -04009688
9689 testCases = append(testCases, testCase{
9690 name: "TLS13-AlwaysSelectPSKIdentity",
9691 config: Config{
9692 MaxVersion: VersionTLS13,
9693 Bugs: ProtocolBugs{
9694 AlwaysSelectPSKIdentity: true,
9695 },
9696 },
9697 shouldFail: true,
9698 expectedError: ":UNEXPECTED_EXTENSION:",
9699 })
9700
9701 testCases = append(testCases, testCase{
9702 name: "TLS13-InvalidPSKIdentity",
9703 config: Config{
9704 MaxVersion: VersionTLS13,
9705 Bugs: ProtocolBugs{
9706 SelectPSKIdentityOnResume: 1,
9707 },
9708 },
9709 resumeSession: true,
9710 shouldFail: true,
9711 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9712 })
David Benjamin1286bee2016-10-07 15:25:06 -04009713
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009714 testCases = append(testCases, testCase{
9715 testType: serverTest,
9716 name: "TLS13-ExtraPSKIdentity",
9717 config: Config{
9718 MaxVersion: VersionTLS13,
9719 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009720 ExtraPSKIdentity: true,
9721 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009722 },
9723 },
9724 resumeSession: true,
9725 })
9726
David Benjamin1286bee2016-10-07 15:25:06 -04009727 // Test that unknown NewSessionTicket extensions are tolerated.
9728 testCases = append(testCases, testCase{
9729 name: "TLS13-CustomTicketExtension",
9730 config: Config{
9731 MaxVersion: VersionTLS13,
9732 Bugs: ProtocolBugs{
9733 CustomTicketExtension: "1234",
9734 },
9735 },
9736 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009737}
9738
David Benjaminabbbee12016-10-31 19:20:42 -04009739func addTLS13CipherPreferenceTests() {
9740 // Test that client preference is honored if the shim has AES hardware
9741 // and ChaCha20-Poly1305 is preferred otherwise.
9742 testCases = append(testCases, testCase{
9743 testType: serverTest,
9744 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9745 config: Config{
9746 MaxVersion: VersionTLS13,
9747 CipherSuites: []uint16{
9748 TLS_CHACHA20_POLY1305_SHA256,
9749 TLS_AES_128_GCM_SHA256,
9750 },
9751 },
9752 flags: []string{
9753 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9754 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9755 },
9756 })
9757
9758 testCases = append(testCases, testCase{
9759 testType: serverTest,
9760 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9761 config: Config{
9762 MaxVersion: VersionTLS13,
9763 CipherSuites: []uint16{
9764 TLS_AES_128_GCM_SHA256,
9765 TLS_CHACHA20_POLY1305_SHA256,
9766 },
9767 },
9768 flags: []string{
9769 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9770 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9771 },
9772 })
9773
9774 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9775 // whether it has AES hardware.
9776 testCases = append(testCases, testCase{
9777 name: "TLS13-CipherPreference-Client",
9778 config: Config{
9779 MaxVersion: VersionTLS13,
9780 // Use the client cipher order. (This is the default but
9781 // is listed to be explicit.)
9782 PreferServerCipherSuites: false,
9783 },
9784 flags: []string{
9785 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9786 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9787 },
9788 })
9789}
9790
David Benjaminf3fbade2016-09-19 13:08:16 -04009791func addPeekTests() {
9792 // Test SSL_peek works, including on empty records.
9793 testCases = append(testCases, testCase{
9794 name: "Peek-Basic",
9795 sendEmptyRecords: 1,
9796 flags: []string{"-peek-then-read"},
9797 })
9798
9799 // Test SSL_peek can drive the initial handshake.
9800 testCases = append(testCases, testCase{
9801 name: "Peek-ImplicitHandshake",
9802 flags: []string{
9803 "-peek-then-read",
9804 "-implicit-handshake",
9805 },
9806 })
9807
9808 // Test SSL_peek can discover and drive a renegotiation.
9809 testCases = append(testCases, testCase{
9810 name: "Peek-Renegotiate",
9811 config: Config{
9812 MaxVersion: VersionTLS12,
9813 },
9814 renegotiate: 1,
9815 flags: []string{
9816 "-peek-then-read",
9817 "-renegotiate-freely",
9818 "-expect-total-renegotiations", "1",
9819 },
9820 })
9821
9822 // Test SSL_peek can discover a close_notify.
9823 testCases = append(testCases, testCase{
9824 name: "Peek-Shutdown",
9825 config: Config{
9826 Bugs: ProtocolBugs{
9827 ExpectCloseNotify: true,
9828 },
9829 },
9830 flags: []string{
9831 "-peek-then-read",
9832 "-check-close-notify",
9833 },
9834 })
9835
9836 // Test SSL_peek can discover an alert.
9837 testCases = append(testCases, testCase{
9838 name: "Peek-Alert",
9839 config: Config{
9840 Bugs: ProtocolBugs{
9841 SendSpuriousAlert: alertRecordOverflow,
9842 },
9843 },
9844 flags: []string{"-peek-then-read"},
9845 shouldFail: true,
9846 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9847 })
9848
9849 // Test SSL_peek can handle KeyUpdate.
9850 testCases = append(testCases, testCase{
9851 name: "Peek-KeyUpdate",
9852 config: Config{
9853 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009854 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009855 sendKeyUpdates: 1,
9856 keyUpdateRequest: keyUpdateNotRequested,
9857 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009858 })
9859}
9860
David Benjamine6f22212016-11-08 14:28:24 -05009861func addRecordVersionTests() {
9862 for _, ver := range tlsVersions {
9863 // Test that the record version is enforced.
9864 testCases = append(testCases, testCase{
9865 name: "CheckRecordVersion-" + ver.name,
9866 config: Config{
9867 MinVersion: ver.version,
9868 MaxVersion: ver.version,
9869 Bugs: ProtocolBugs{
9870 SendRecordVersion: 0x03ff,
9871 },
9872 },
9873 shouldFail: true,
9874 expectedError: ":WRONG_VERSION_NUMBER:",
9875 })
9876
9877 // Test that the ClientHello may use any record version, for
9878 // compatibility reasons.
9879 testCases = append(testCases, testCase{
9880 testType: serverTest,
9881 name: "LooseInitialRecordVersion-" + ver.name,
9882 config: Config{
9883 MinVersion: ver.version,
9884 MaxVersion: ver.version,
9885 Bugs: ProtocolBugs{
9886 SendInitialRecordVersion: 0x03ff,
9887 },
9888 },
9889 })
9890
9891 // Test that garbage ClientHello record versions are rejected.
9892 testCases = append(testCases, testCase{
9893 testType: serverTest,
9894 name: "GarbageInitialRecordVersion-" + ver.name,
9895 config: Config{
9896 MinVersion: ver.version,
9897 MaxVersion: ver.version,
9898 Bugs: ProtocolBugs{
9899 SendInitialRecordVersion: 0xffff,
9900 },
9901 },
9902 shouldFail: true,
9903 expectedError: ":WRONG_VERSION_NUMBER:",
9904 })
9905 }
9906}
9907
David Benjamin2c516452016-11-15 10:16:54 +09009908func addCertificateTests() {
9909 // Test that a certificate chain with intermediate may be sent and
9910 // received as both client and server.
9911 for _, ver := range tlsVersions {
9912 testCases = append(testCases, testCase{
9913 testType: clientTest,
9914 name: "SendReceiveIntermediate-Client-" + ver.name,
9915 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009916 MinVersion: ver.version,
9917 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009918 Certificates: []Certificate{rsaChainCertificate},
9919 ClientAuth: RequireAnyClientCert,
9920 },
9921 expectPeerCertificate: &rsaChainCertificate,
9922 flags: []string{
9923 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9924 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9925 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9926 },
9927 })
9928
9929 testCases = append(testCases, testCase{
9930 testType: serverTest,
9931 name: "SendReceiveIntermediate-Server-" + ver.name,
9932 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009933 MinVersion: ver.version,
9934 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009935 Certificates: []Certificate{rsaChainCertificate},
9936 },
9937 expectPeerCertificate: &rsaChainCertificate,
9938 flags: []string{
9939 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9940 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9941 "-require-any-client-certificate",
9942 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9943 },
9944 })
9945 }
9946}
9947
David Benjaminbbaf3672016-11-17 10:53:09 +09009948func addRetainOnlySHA256ClientCertTests() {
9949 for _, ver := range tlsVersions {
9950 // Test that enabling
9951 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9952 // actually requesting a client certificate is a no-op.
9953 testCases = append(testCases, testCase{
9954 testType: serverTest,
9955 name: "RetainOnlySHA256-NoCert-" + ver.name,
9956 config: Config{
9957 MinVersion: ver.version,
9958 MaxVersion: ver.version,
9959 },
9960 flags: []string{
9961 "-retain-only-sha256-client-cert-initial",
9962 "-retain-only-sha256-client-cert-resume",
9963 },
9964 resumeSession: true,
9965 })
9966
9967 // Test that when retaining only a SHA-256 certificate is
9968 // enabled, the hash appears as expected.
9969 testCases = append(testCases, testCase{
9970 testType: serverTest,
9971 name: "RetainOnlySHA256-Cert-" + ver.name,
9972 config: Config{
9973 MinVersion: ver.version,
9974 MaxVersion: ver.version,
9975 Certificates: []Certificate{rsaCertificate},
9976 },
9977 flags: []string{
9978 "-verify-peer",
9979 "-retain-only-sha256-client-cert-initial",
9980 "-retain-only-sha256-client-cert-resume",
9981 "-expect-sha256-client-cert-initial",
9982 "-expect-sha256-client-cert-resume",
9983 },
9984 resumeSession: true,
9985 })
9986
9987 // Test that when the config changes from on to off, a
9988 // resumption is rejected because the server now wants the full
9989 // certificate chain.
9990 testCases = append(testCases, testCase{
9991 testType: serverTest,
9992 name: "RetainOnlySHA256-OnOff-" + ver.name,
9993 config: Config{
9994 MinVersion: ver.version,
9995 MaxVersion: ver.version,
9996 Certificates: []Certificate{rsaCertificate},
9997 },
9998 flags: []string{
9999 "-verify-peer",
10000 "-retain-only-sha256-client-cert-initial",
10001 "-expect-sha256-client-cert-initial",
10002 },
10003 resumeSession: true,
10004 expectResumeRejected: true,
10005 })
10006
10007 // Test that when the config changes from off to on, a
10008 // resumption is rejected because the server now wants just the
10009 // hash.
10010 testCases = append(testCases, testCase{
10011 testType: serverTest,
10012 name: "RetainOnlySHA256-OffOn-" + ver.name,
10013 config: Config{
10014 MinVersion: ver.version,
10015 MaxVersion: ver.version,
10016 Certificates: []Certificate{rsaCertificate},
10017 },
10018 flags: []string{
10019 "-verify-peer",
10020 "-retain-only-sha256-client-cert-resume",
10021 "-expect-sha256-client-cert-resume",
10022 },
10023 resumeSession: true,
10024 expectResumeRejected: true,
10025 })
10026 }
10027}
10028
Adam Langleya4b91982016-12-12 12:05:53 -080010029func addECDSAKeyUsageTests() {
10030 p256 := elliptic.P256()
10031 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10032 if err != nil {
10033 panic(err)
10034 }
10035
10036 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10037 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10038 if err != nil {
10039 panic(err)
10040 }
10041
10042 template := x509.Certificate{
10043 SerialNumber: serialNumber,
10044 Subject: pkix.Name{
10045 Organization: []string{"Acme Co"},
10046 },
10047 NotBefore: time.Now(),
10048 NotAfter: time.Now(),
10049
10050 // An ECC certificate with only the keyAgreement key usgae may
10051 // be used with ECDH, but not ECDSA.
10052 KeyUsage: x509.KeyUsageKeyAgreement,
10053 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10054 BasicConstraintsValid: true,
10055 }
10056
10057 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10058 if err != nil {
10059 panic(err)
10060 }
10061
10062 cert := Certificate{
10063 Certificate: [][]byte{derBytes},
10064 PrivateKey: priv,
10065 }
10066
10067 for _, ver := range tlsVersions {
10068 if ver.version < VersionTLS12 {
10069 continue
10070 }
10071
10072 testCases = append(testCases, testCase{
10073 testType: clientTest,
10074 name: "ECDSAKeyUsage-" + ver.name,
10075 config: Config{
10076 MinVersion: ver.version,
10077 MaxVersion: ver.version,
10078 Certificates: []Certificate{cert},
10079 },
10080 shouldFail: true,
10081 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10082 })
10083 }
10084}
10085
David Benjamin6f600d62016-12-21 16:06:54 -050010086func addShortHeaderTests() {
10087 // The short header extension may be negotiated as either client or
10088 // server.
10089 testCases = append(testCases, testCase{
10090 name: "ShortHeader-Client",
10091 config: Config{
10092 MaxVersion: VersionTLS13,
10093 Bugs: ProtocolBugs{
10094 EnableShortHeader: true,
10095 },
10096 },
10097 flags: []string{"-enable-short-header"},
10098 expectShortHeader: true,
10099 })
10100 testCases = append(testCases, testCase{
10101 testType: serverTest,
10102 name: "ShortHeader-Server",
10103 config: Config{
10104 MaxVersion: VersionTLS13,
10105 Bugs: ProtocolBugs{
10106 EnableShortHeader: true,
10107 },
10108 },
10109 flags: []string{"-enable-short-header"},
10110 expectShortHeader: true,
10111 })
10112
10113 // If the peer doesn't support it, it will not be negotiated.
10114 testCases = append(testCases, testCase{
10115 name: "ShortHeader-No-Yes-Client",
10116 config: Config{
10117 MaxVersion: VersionTLS13,
10118 },
10119 flags: []string{"-enable-short-header"},
10120 })
10121 testCases = append(testCases, testCase{
10122 testType: serverTest,
10123 name: "ShortHeader-No-Yes-Server",
10124 config: Config{
10125 MaxVersion: VersionTLS13,
10126 },
10127 flags: []string{"-enable-short-header"},
10128 })
10129
10130 // If we don't support it, it will not be negotiated.
10131 testCases = append(testCases, testCase{
10132 name: "ShortHeader-Yes-No-Client",
10133 config: Config{
10134 MaxVersion: VersionTLS13,
10135 Bugs: ProtocolBugs{
10136 EnableShortHeader: true,
10137 },
10138 },
10139 })
10140 testCases = append(testCases, testCase{
10141 testType: serverTest,
10142 name: "ShortHeader-Yes-No-Server",
10143 config: Config{
10144 MaxVersion: VersionTLS13,
10145 Bugs: ProtocolBugs{
10146 EnableShortHeader: true,
10147 },
10148 },
10149 })
10150
10151 // It will not be negotiated at TLS 1.2.
10152 testCases = append(testCases, testCase{
10153 name: "ShortHeader-TLS12-Client",
10154 config: Config{
10155 MaxVersion: VersionTLS12,
10156 Bugs: ProtocolBugs{
10157 EnableShortHeader: true,
10158 },
10159 },
10160 flags: []string{"-enable-short-header"},
10161 })
10162 testCases = append(testCases, testCase{
10163 testType: serverTest,
10164 name: "ShortHeader-TLS12-Server",
10165 config: Config{
10166 MaxVersion: VersionTLS12,
10167 Bugs: ProtocolBugs{
10168 EnableShortHeader: true,
10169 },
10170 },
10171 flags: []string{"-enable-short-header"},
10172 })
10173
10174 // Servers reject early data and short header sent together.
10175 testCases = append(testCases, testCase{
10176 testType: serverTest,
10177 name: "ShortHeader-EarlyData",
10178 config: Config{
10179 MaxVersion: VersionTLS13,
10180 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010181 EnableShortHeader: true,
10182 SendFakeEarlyDataLength: 1,
David Benjamin6f600d62016-12-21 16:06:54 -050010183 },
10184 },
10185 flags: []string{"-enable-short-header"},
10186 shouldFail: true,
10187 expectedError: ":UNEXPECTED_EXTENSION:",
10188 })
10189
10190 // Clients reject unsolicited short header extensions.
10191 testCases = append(testCases, testCase{
10192 name: "ShortHeader-Unsolicited",
10193 config: Config{
10194 MaxVersion: VersionTLS13,
10195 Bugs: ProtocolBugs{
10196 AlwaysNegotiateShortHeader: true,
10197 },
10198 },
10199 shouldFail: true,
10200 expectedError: ":UNEXPECTED_EXTENSION:",
10201 })
10202 testCases = append(testCases, testCase{
10203 name: "ShortHeader-Unsolicited-TLS12",
10204 config: Config{
10205 MaxVersion: VersionTLS12,
10206 Bugs: ProtocolBugs{
10207 AlwaysNegotiateShortHeader: true,
10208 },
10209 },
10210 shouldFail: true,
10211 expectedError: ":UNEXPECTED_EXTENSION:",
10212 })
10213
10214 // The high bit must be checked in short headers.
10215 testCases = append(testCases, testCase{
10216 name: "ShortHeader-ClearShortHeaderBit",
10217 config: Config{
10218 Bugs: ProtocolBugs{
10219 EnableShortHeader: true,
10220 ClearShortHeaderBit: true,
10221 },
10222 },
10223 flags: []string{"-enable-short-header"},
10224 shouldFail: true,
10225 expectedError: ":DECODE_ERROR:",
10226 expectedLocalError: "remote error: error decoding message",
10227 })
10228}
10229
Adam Langley7c803a62015-06-15 15:35:05 -070010230func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010231 defer wg.Done()
10232
10233 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010234 var err error
10235
David Benjaminba28dfc2016-11-15 17:47:21 +090010236 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010237 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10238 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010239 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010240 if err != nil {
10241 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10242 }
10243 break
10244 }
10245 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010246 } else if *repeatUntilFailure {
10247 for err == nil {
10248 statusChan <- statusMsg{test: test, started: true}
10249 err = runTest(test, shimPath, -1)
10250 }
10251 } else {
10252 statusChan <- statusMsg{test: test, started: true}
10253 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010254 }
Adam Langley95c29f32014-06-20 12:00:00 -070010255 statusChan <- statusMsg{test: test, err: err}
10256 }
10257}
10258
10259type statusMsg struct {
10260 test *testCase
10261 started bool
10262 err error
10263}
10264
David Benjamin5f237bc2015-02-11 17:14:15 -050010265func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010266 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010267
David Benjamin5f237bc2015-02-11 17:14:15 -050010268 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010269 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010270 if !*pipe {
10271 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010272 var erase string
10273 for i := 0; i < lineLen; i++ {
10274 erase += "\b \b"
10275 }
10276 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010277 }
10278
Adam Langley95c29f32014-06-20 12:00:00 -070010279 if msg.started {
10280 started++
10281 } else {
10282 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010283
10284 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010285 if msg.err == errUnimplemented {
10286 if *pipe {
10287 // Print each test instead of a status line.
10288 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10289 }
10290 unimplemented++
10291 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10292 } else {
10293 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10294 failed++
10295 testOutput.addResult(msg.test.name, "FAIL")
10296 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010297 } else {
10298 if *pipe {
10299 // Print each test instead of a status line.
10300 fmt.Printf("PASSED (%s)\n", msg.test.name)
10301 }
10302 testOutput.addResult(msg.test.name, "PASS")
10303 }
Adam Langley95c29f32014-06-20 12:00:00 -070010304 }
10305
David Benjamin5f237bc2015-02-11 17:14:15 -050010306 if !*pipe {
10307 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010308 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010309 lineLen = len(line)
10310 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010311 }
Adam Langley95c29f32014-06-20 12:00:00 -070010312 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010313
10314 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010315}
10316
10317func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010318 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010319 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010320 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010321
Adam Langley7c803a62015-06-15 15:35:05 -070010322 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010323 addCipherSuiteTests()
10324 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010325 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010326 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010327 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010328 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010329 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010330 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010331 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010332 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010333 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010334 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010335 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010336 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010337 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010338 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010339 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010340 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010341 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010342 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010343 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010344 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010345 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010346 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010347 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010348 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010349 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010350 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010351 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010352 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010353 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010354 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010355 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010356 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010357
10358 var wg sync.WaitGroup
10359
Adam Langley7c803a62015-06-15 15:35:05 -070010360 statusChan := make(chan statusMsg, *numWorkers)
10361 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010362 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010363
EKRf71d7ed2016-08-06 13:25:12 -070010364 if len(*shimConfigFile) != 0 {
10365 encoded, err := ioutil.ReadFile(*shimConfigFile)
10366 if err != nil {
10367 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10368 os.Exit(1)
10369 }
10370
10371 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10372 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10373 os.Exit(1)
10374 }
10375 }
10376
David Benjamin025b3d32014-07-01 19:53:04 -040010377 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010378
Adam Langley7c803a62015-06-15 15:35:05 -070010379 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010380 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010381 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010382 }
10383
David Benjamin270f0a72016-03-17 14:41:36 -040010384 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010385 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010386 matched := true
10387 if len(*testToRun) != 0 {
10388 var err error
10389 matched, err = filepath.Match(*testToRun, testCases[i].name)
10390 if err != nil {
10391 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10392 os.Exit(1)
10393 }
10394 }
10395
EKRf71d7ed2016-08-06 13:25:12 -070010396 if !*includeDisabled {
10397 for pattern := range shimConfig.DisabledTests {
10398 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10399 if err != nil {
10400 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10401 os.Exit(1)
10402 }
10403
10404 if isDisabled {
10405 matched = false
10406 break
10407 }
10408 }
10409 }
10410
David Benjamin17e12922016-07-28 18:04:43 -040010411 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010412 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010413 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010414
10415 // Only run one test if repeating until failure.
10416 if *repeatUntilFailure {
10417 break
10418 }
Adam Langley95c29f32014-06-20 12:00:00 -070010419 }
10420 }
David Benjamin17e12922016-07-28 18:04:43 -040010421
David Benjamin270f0a72016-03-17 14:41:36 -040010422 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010423 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010424 os.Exit(1)
10425 }
Adam Langley95c29f32014-06-20 12:00:00 -070010426
10427 close(testChan)
10428 wg.Wait()
10429 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010430 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010431
10432 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010433
10434 if *jsonOutput != "" {
10435 if err := testOutput.writeTo(*jsonOutput); err != nil {
10436 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10437 }
10438 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010439
EKR842ae6c2016-07-27 09:22:05 +020010440 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10441 os.Exit(1)
10442 }
10443
10444 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010445 os.Exit(1)
10446 }
Adam Langley95c29f32014-06-20 12:00:00 -070010447}