blob: 336aa31f0d959ea14bca307b631ebebe32ba256e [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
David Benjamind4c349b2017-02-09 14:07:17 -05005047 // Resume with various lengths of ticket 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,
David Benjamind4c349b2017-02-09 14:07:17 -05005051 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005052 config: Config{
5053 MaxVersion: ver.version,
5054 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005055 EmptyTicketSessionID: true,
5056 },
5057 },
5058 resumeSession: true,
5059 })
5060 testCases = append(testCases, testCase{
5061 testType: serverTest,
5062 name: "TicketSessionIDLength-16-" + ver.name,
5063 config: Config{
5064 MaxVersion: ver.version,
5065 Bugs: ProtocolBugs{
5066 TicketSessionIDLength: 16,
5067 },
5068 },
5069 resumeSession: true,
5070 })
5071 testCases = append(testCases, testCase{
5072 testType: serverTest,
5073 name: "TicketSessionIDLength-32-" + ver.name,
5074 config: Config{
5075 MaxVersion: ver.version,
5076 Bugs: ProtocolBugs{
5077 TicketSessionIDLength: 32,
5078 },
5079 },
5080 resumeSession: true,
5081 })
5082 testCases = append(testCases, testCase{
5083 testType: serverTest,
5084 name: "TicketSessionIDLength-33-" + ver.name,
5085 config: Config{
5086 MaxVersion: ver.version,
5087 Bugs: ProtocolBugs{
5088 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005089 },
5090 },
5091 resumeSession: true,
5092 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005093 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005094 expectedError: ":DECODE_ERROR:",
5095 })
5096 }
5097
5098 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5099 // are ignored.
5100 if ver.hasDTLS {
5101 testCases = append(testCases, testCase{
5102 protocol: dtls,
5103 name: "SRTP-Client-" + ver.name,
5104 config: Config{
5105 MaxVersion: ver.version,
5106 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5107 },
5108 flags: []string{
5109 "-srtp-profiles",
5110 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5111 },
5112 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5113 })
5114 testCases = append(testCases, testCase{
5115 protocol: dtls,
5116 testType: serverTest,
5117 name: "SRTP-Server-" + ver.name,
5118 config: Config{
5119 MaxVersion: ver.version,
5120 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5121 },
5122 flags: []string{
5123 "-srtp-profiles",
5124 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5125 },
5126 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5127 })
5128 // Test that the MKI is ignored.
5129 testCases = append(testCases, testCase{
5130 protocol: dtls,
5131 testType: serverTest,
5132 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5133 config: Config{
5134 MaxVersion: ver.version,
5135 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5136 Bugs: ProtocolBugs{
5137 SRTPMasterKeyIdentifer: "bogus",
5138 },
5139 },
5140 flags: []string{
5141 "-srtp-profiles",
5142 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5143 },
5144 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5145 })
5146 // Test that SRTP isn't negotiated on the server if there were
5147 // no matching profiles.
5148 testCases = append(testCases, testCase{
5149 protocol: dtls,
5150 testType: serverTest,
5151 name: "SRTP-Server-NoMatch-" + ver.name,
5152 config: Config{
5153 MaxVersion: ver.version,
5154 SRTPProtectionProfiles: []uint16{100, 101, 102},
5155 },
5156 flags: []string{
5157 "-srtp-profiles",
5158 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5159 },
5160 expectedSRTPProtectionProfile: 0,
5161 })
5162 // Test that the server returning an invalid SRTP profile is
5163 // flagged as an error by the client.
5164 testCases = append(testCases, testCase{
5165 protocol: dtls,
5166 name: "SRTP-Client-NoMatch-" + ver.name,
5167 config: Config{
5168 MaxVersion: ver.version,
5169 Bugs: ProtocolBugs{
5170 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5171 },
5172 },
5173 flags: []string{
5174 "-srtp-profiles",
5175 "SRTP_AES128_CM_SHA1_80",
5176 },
5177 shouldFail: true,
5178 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5179 })
5180 }
5181
5182 // Test SCT list.
5183 testCases = append(testCases, testCase{
5184 name: "SignedCertificateTimestampList-Client-" + ver.name,
5185 testType: clientTest,
5186 config: Config{
5187 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005188 },
David Benjamin97d17d92016-07-14 16:12:00 -04005189 flags: []string{
5190 "-enable-signed-cert-timestamps",
5191 "-expect-signed-cert-timestamps",
5192 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005193 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005194 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005195 })
David Benjamindaa88502016-10-04 16:32:16 -04005196
Adam Langleycfa08c32016-11-17 13:21:27 -08005197 var differentSCTList []byte
5198 differentSCTList = append(differentSCTList, testSCTList...)
5199 differentSCTList[len(differentSCTList)-1] ^= 1
5200
David Benjamindaa88502016-10-04 16:32:16 -04005201 // The SCT extension did not specify that it must only be sent on resumption as it
5202 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005203 testCases = append(testCases, testCase{
5204 name: "SendSCTListOnResume-" + ver.name,
5205 config: Config{
5206 MaxVersion: ver.version,
5207 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005208 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005209 },
David Benjamind98452d2015-06-16 14:16:23 -04005210 },
David Benjamin97d17d92016-07-14 16:12:00 -04005211 flags: []string{
5212 "-enable-signed-cert-timestamps",
5213 "-expect-signed-cert-timestamps",
5214 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005215 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005216 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005217 })
David Benjamindaa88502016-10-04 16:32:16 -04005218
David Benjamin97d17d92016-07-14 16:12:00 -04005219 testCases = append(testCases, testCase{
5220 name: "SignedCertificateTimestampList-Server-" + ver.name,
5221 testType: serverTest,
5222 config: Config{
5223 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005224 },
David Benjamin97d17d92016-07-14 16:12:00 -04005225 flags: []string{
5226 "-signed-cert-timestamps",
5227 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005228 },
David Benjamin97d17d92016-07-14 16:12:00 -04005229 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005230 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005231 })
David Benjamin53210cb2016-11-16 09:01:48 +09005232
Adam Langleycfa08c32016-11-17 13:21:27 -08005233 emptySCTListCert := *testCerts[0].cert
5234 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5235
5236 // Test empty SCT list.
5237 testCases = append(testCases, testCase{
5238 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5239 testType: clientTest,
5240 config: Config{
5241 MaxVersion: ver.version,
5242 Certificates: []Certificate{emptySCTListCert},
5243 },
5244 flags: []string{
5245 "-enable-signed-cert-timestamps",
5246 },
5247 shouldFail: true,
5248 expectedError: ":ERROR_PARSING_EXTENSION:",
5249 })
5250
5251 emptySCTCert := *testCerts[0].cert
5252 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5253
5254 // Test empty SCT in non-empty list.
5255 testCases = append(testCases, testCase{
5256 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5257 testType: clientTest,
5258 config: Config{
5259 MaxVersion: ver.version,
5260 Certificates: []Certificate{emptySCTCert},
5261 },
5262 flags: []string{
5263 "-enable-signed-cert-timestamps",
5264 },
5265 shouldFail: true,
5266 expectedError: ":ERROR_PARSING_EXTENSION:",
5267 })
5268
David Benjamin53210cb2016-11-16 09:01:48 +09005269 // Test that certificate-related extensions are not sent unsolicited.
5270 testCases = append(testCases, testCase{
5271 testType: serverTest,
5272 name: "UnsolicitedCertificateExtensions-" + ver.name,
5273 config: Config{
5274 MaxVersion: ver.version,
5275 Bugs: ProtocolBugs{
5276 NoOCSPStapling: true,
5277 NoSignedCertificateTimestamps: true,
5278 },
5279 },
5280 flags: []string{
5281 "-ocsp-response",
5282 base64.StdEncoding.EncodeToString(testOCSPResponse),
5283 "-signed-cert-timestamps",
5284 base64.StdEncoding.EncodeToString(testSCTList),
5285 },
5286 })
David Benjamin97d17d92016-07-14 16:12:00 -04005287 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005288
Paul Lietar4fac72e2015-09-09 13:44:55 +01005289 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005290 testType: clientTest,
5291 name: "ClientHelloPadding",
5292 config: Config{
5293 Bugs: ProtocolBugs{
5294 RequireClientHelloSize: 512,
5295 },
5296 },
5297 // This hostname just needs to be long enough to push the
5298 // ClientHello into F5's danger zone between 256 and 511 bytes
5299 // long.
5300 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5301 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005302
5303 // Extensions should not function in SSL 3.0.
5304 testCases = append(testCases, testCase{
5305 testType: serverTest,
5306 name: "SSLv3Extensions-NoALPN",
5307 config: Config{
5308 MaxVersion: VersionSSL30,
5309 NextProtos: []string{"foo", "bar", "baz"},
5310 },
5311 flags: []string{
5312 "-select-alpn", "foo",
5313 },
5314 expectNoNextProto: true,
5315 })
5316
5317 // Test session tickets separately as they follow a different codepath.
5318 testCases = append(testCases, testCase{
5319 testType: serverTest,
5320 name: "SSLv3Extensions-NoTickets",
5321 config: Config{
5322 MaxVersion: VersionSSL30,
5323 Bugs: ProtocolBugs{
5324 // Historically, session tickets in SSL 3.0
5325 // failed in different ways depending on whether
5326 // the client supported renegotiation_info.
5327 NoRenegotiationInfo: true,
5328 },
5329 },
5330 resumeSession: true,
5331 })
5332 testCases = append(testCases, testCase{
5333 testType: serverTest,
5334 name: "SSLv3Extensions-NoTickets2",
5335 config: Config{
5336 MaxVersion: VersionSSL30,
5337 },
5338 resumeSession: true,
5339 })
5340
5341 // But SSL 3.0 does send and process renegotiation_info.
5342 testCases = append(testCases, testCase{
5343 testType: serverTest,
5344 name: "SSLv3Extensions-RenegotiationInfo",
5345 config: Config{
5346 MaxVersion: VersionSSL30,
5347 Bugs: ProtocolBugs{
5348 RequireRenegotiationInfo: true,
5349 },
5350 },
David Benjamind2610042017-01-03 10:49:28 -05005351 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005352 })
5353 testCases = append(testCases, testCase{
5354 testType: serverTest,
5355 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5356 config: Config{
5357 MaxVersion: VersionSSL30,
5358 Bugs: ProtocolBugs{
5359 NoRenegotiationInfo: true,
5360 SendRenegotiationSCSV: true,
5361 RequireRenegotiationInfo: true,
5362 },
5363 },
David Benjamind2610042017-01-03 10:49:28 -05005364 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005365 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005366
5367 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5368 // in ServerHello.
5369 testCases = append(testCases, testCase{
5370 name: "NPN-Forbidden-TLS13",
5371 config: Config{
5372 MaxVersion: VersionTLS13,
5373 NextProtos: []string{"foo"},
5374 Bugs: ProtocolBugs{
5375 NegotiateNPNAtAllVersions: true,
5376 },
5377 },
5378 flags: []string{"-select-next-proto", "foo"},
5379 shouldFail: true,
5380 expectedError: ":ERROR_PARSING_EXTENSION:",
5381 })
5382 testCases = append(testCases, testCase{
5383 name: "EMS-Forbidden-TLS13",
5384 config: Config{
5385 MaxVersion: VersionTLS13,
5386 Bugs: ProtocolBugs{
5387 NegotiateEMSAtAllVersions: true,
5388 },
5389 },
5390 shouldFail: true,
5391 expectedError: ":ERROR_PARSING_EXTENSION:",
5392 })
5393 testCases = append(testCases, testCase{
5394 name: "RenegotiationInfo-Forbidden-TLS13",
5395 config: Config{
5396 MaxVersion: VersionTLS13,
5397 Bugs: ProtocolBugs{
5398 NegotiateRenegotiationInfoAtAllVersions: true,
5399 },
5400 },
5401 shouldFail: true,
5402 expectedError: ":ERROR_PARSING_EXTENSION:",
5403 })
5404 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005405 name: "Ticket-Forbidden-TLS13",
5406 config: Config{
5407 MaxVersion: VersionTLS12,
5408 },
5409 resumeConfig: &Config{
5410 MaxVersion: VersionTLS13,
5411 Bugs: ProtocolBugs{
5412 AdvertiseTicketExtension: true,
5413 },
5414 },
5415 resumeSession: true,
5416 shouldFail: true,
5417 expectedError: ":ERROR_PARSING_EXTENSION:",
5418 })
5419
5420 // Test that illegal extensions in TLS 1.3 are declined by the server if
5421 // offered in ClientHello. The runner's server will fail if this occurs,
5422 // so we exercise the offering path. (EMS and Renegotiation Info are
5423 // implicit in every test.)
5424 testCases = append(testCases, testCase{
5425 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005426 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005427 config: Config{
5428 MaxVersion: VersionTLS13,
5429 NextProtos: []string{"bar"},
5430 },
5431 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5432 })
David Benjamin196df5b2016-09-21 16:23:27 -04005433
David Benjamindaa88502016-10-04 16:32:16 -04005434 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5435 // tolerated.
5436 testCases = append(testCases, testCase{
5437 name: "SendOCSPResponseOnResume-TLS12",
5438 config: Config{
5439 MaxVersion: VersionTLS12,
5440 Bugs: ProtocolBugs{
5441 SendOCSPResponseOnResume: []byte("bogus"),
5442 },
5443 },
5444 flags: []string{
5445 "-enable-ocsp-stapling",
5446 "-expect-ocsp-response",
5447 base64.StdEncoding.EncodeToString(testOCSPResponse),
5448 },
5449 resumeSession: true,
5450 })
5451
David Benjamindaa88502016-10-04 16:32:16 -04005452 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005453 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005454 config: Config{
5455 MaxVersion: VersionTLS13,
5456 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005457 SendExtensionOnCertificate: testOCSPExtension,
5458 },
5459 },
5460 shouldFail: true,
5461 expectedError: ":UNEXPECTED_EXTENSION:",
5462 })
5463
5464 testCases = append(testCases, testCase{
5465 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5466 config: Config{
5467 MaxVersion: VersionTLS13,
5468 Bugs: ProtocolBugs{
5469 SendExtensionOnCertificate: testSCTExtension,
5470 },
5471 },
5472 shouldFail: true,
5473 expectedError: ":UNEXPECTED_EXTENSION:",
5474 })
5475
5476 // Test that extensions on client certificates are never accepted.
5477 testCases = append(testCases, testCase{
5478 name: "SendExtensionOnClientCertificate-TLS13",
5479 testType: serverTest,
5480 config: Config{
5481 MaxVersion: VersionTLS13,
5482 Certificates: []Certificate{rsaCertificate},
5483 Bugs: ProtocolBugs{
5484 SendExtensionOnCertificate: testOCSPExtension,
5485 },
5486 },
5487 flags: []string{
5488 "-enable-ocsp-stapling",
5489 "-require-any-client-certificate",
5490 },
5491 shouldFail: true,
5492 expectedError: ":UNEXPECTED_EXTENSION:",
5493 })
5494
5495 testCases = append(testCases, testCase{
5496 name: "SendUnknownExtensionOnCertificate-TLS13",
5497 config: Config{
5498 MaxVersion: VersionTLS13,
5499 Bugs: ProtocolBugs{
5500 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5501 },
5502 },
5503 shouldFail: true,
5504 expectedError: ":UNEXPECTED_EXTENSION:",
5505 })
5506
Adam Langleycfa08c32016-11-17 13:21:27 -08005507 var differentSCTList []byte
5508 differentSCTList = append(differentSCTList, testSCTList...)
5509 differentSCTList[len(differentSCTList)-1] ^= 1
5510
Steven Valdeza833c352016-11-01 13:39:36 -04005511 // Test that extensions on intermediates are allowed but ignored.
5512 testCases = append(testCases, testCase{
5513 name: "IgnoreExtensionsOnIntermediates-TLS13",
5514 config: Config{
5515 MaxVersion: VersionTLS13,
5516 Certificates: []Certificate{rsaChainCertificate},
5517 Bugs: ProtocolBugs{
5518 // Send different values on the intermediate. This tests
5519 // the intermediate's extensions do not override the
5520 // leaf's.
5521 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005522 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005523 },
5524 },
5525 flags: []string{
5526 "-enable-ocsp-stapling",
5527 "-expect-ocsp-response",
5528 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005529 "-enable-signed-cert-timestamps",
5530 "-expect-signed-cert-timestamps",
5531 base64.StdEncoding.EncodeToString(testSCTList),
5532 },
5533 resumeSession: true,
5534 })
5535
5536 // Test that extensions are not sent on intermediates when configured
5537 // only for a leaf.
5538 testCases = append(testCases, testCase{
5539 testType: serverTest,
5540 name: "SendNoExtensionsOnIntermediate-TLS13",
5541 config: Config{
5542 MaxVersion: VersionTLS13,
5543 Bugs: ProtocolBugs{
5544 ExpectNoExtensionsOnIntermediate: true,
5545 },
5546 },
5547 flags: []string{
5548 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5549 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5550 "-ocsp-response",
5551 base64.StdEncoding.EncodeToString(testOCSPResponse),
5552 "-signed-cert-timestamps",
5553 base64.StdEncoding.EncodeToString(testSCTList),
5554 },
5555 })
5556
5557 // Test that extensions are not sent on client certificates.
5558 testCases = append(testCases, testCase{
5559 name: "SendNoClientCertificateExtensions-TLS13",
5560 config: Config{
5561 MaxVersion: VersionTLS13,
5562 ClientAuth: RequireAnyClientCert,
5563 },
5564 flags: []string{
5565 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5566 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5567 "-ocsp-response",
5568 base64.StdEncoding.EncodeToString(testOCSPResponse),
5569 "-signed-cert-timestamps",
5570 base64.StdEncoding.EncodeToString(testSCTList),
5571 },
5572 })
5573
5574 testCases = append(testCases, testCase{
5575 name: "SendDuplicateExtensionsOnCerts-TLS13",
5576 config: Config{
5577 MaxVersion: VersionTLS13,
5578 Bugs: ProtocolBugs{
5579 SendDuplicateCertExtensions: true,
5580 },
5581 },
5582 flags: []string{
5583 "-enable-ocsp-stapling",
5584 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005585 },
5586 resumeSession: true,
5587 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005588 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005589 })
Adam Langley9b885c52016-11-18 14:21:03 -08005590
5591 testCases = append(testCases, testCase{
5592 name: "SignedCertificateTimestampListInvalid-Server",
5593 testType: serverTest,
5594 flags: []string{
5595 "-signed-cert-timestamps",
5596 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5597 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005598 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005599 expectedError: ":INVALID_SCT_LIST:",
5600 })
David Benjamine78bfde2014-09-06 12:45:15 -04005601}
5602
David Benjamin01fe8202014-09-24 15:21:44 -04005603func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005604 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005605 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005606 // SSL 3.0 does not have tickets and TLS 1.3 does not
5607 // have session IDs, so skip their cross-resumption
5608 // tests.
5609 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5610 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5611 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005612 }
5613
David Benjamin8b8c0062014-11-23 02:47:52 -05005614 protocols := []protocol{tls}
5615 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5616 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005617 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005618 for _, protocol := range protocols {
5619 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5620 if protocol == dtls {
5621 suffix += "-DTLS"
5622 }
5623
David Benjaminece3de92015-03-16 18:02:20 -04005624 if sessionVers.version == resumeVers.version {
5625 testCases = append(testCases, testCase{
5626 protocol: protocol,
5627 name: "Resume-Client" + suffix,
5628 resumeSession: true,
5629 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005630 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005631 Bugs: ProtocolBugs{
5632 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5633 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5634 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005635 },
David Benjaminece3de92015-03-16 18:02:20 -04005636 expectedVersion: sessionVers.version,
5637 expectedResumeVersion: resumeVers.version,
5638 })
5639 } else {
David Benjamin405da482016-08-08 17:25:07 -04005640 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5641
5642 // Offering a TLS 1.3 session sends an empty session ID, so
5643 // there is no way to convince a non-lookahead client the
5644 // session was resumed. It will appear to the client that a
5645 // stray ChangeCipherSpec was sent.
5646 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5647 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005648 }
5649
David Benjaminece3de92015-03-16 18:02:20 -04005650 testCases = append(testCases, testCase{
5651 protocol: protocol,
5652 name: "Resume-Client-Mismatch" + suffix,
5653 resumeSession: true,
5654 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005655 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005656 },
David Benjaminece3de92015-03-16 18:02:20 -04005657 expectedVersion: sessionVers.version,
5658 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005659 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005660 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005661 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005662 },
5663 },
5664 expectedResumeVersion: resumeVers.version,
5665 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005666 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005667 })
5668 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005669
5670 testCases = append(testCases, testCase{
5671 protocol: protocol,
5672 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005673 resumeSession: true,
5674 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005675 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005676 },
5677 expectedVersion: sessionVers.version,
5678 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005679 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005680 },
5681 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005682 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005683 expectedResumeVersion: resumeVers.version,
5684 })
5685
David Benjamin8b8c0062014-11-23 02:47:52 -05005686 testCases = append(testCases, testCase{
5687 protocol: protocol,
5688 testType: serverTest,
5689 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005690 resumeSession: true,
5691 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005692 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005693 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005694 expectedVersion: sessionVers.version,
5695 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005696 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005697 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005698 Bugs: ProtocolBugs{
5699 SendBothTickets: true,
5700 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005701 },
5702 expectedResumeVersion: resumeVers.version,
5703 })
5704 }
David Benjamin01fe8202014-09-24 15:21:44 -04005705 }
5706 }
David Benjaminece3de92015-03-16 18:02:20 -04005707
David Benjamin4199b0d2016-11-01 13:58:25 -04005708 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005709 testCases = append(testCases, testCase{
5710 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005711 name: "ShimTicketRewritable",
5712 resumeSession: true,
5713 config: Config{
5714 MaxVersion: VersionTLS12,
5715 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5716 Bugs: ProtocolBugs{
5717 FilterTicket: func(in []byte) ([]byte, error) {
5718 in, err := SetShimTicketVersion(in, VersionTLS12)
5719 if err != nil {
5720 return nil, err
5721 }
5722 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5723 },
5724 },
5725 },
5726 flags: []string{
5727 "-ticket-key",
5728 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5729 },
5730 })
5731
5732 // Resumptions are declined if the version does not match.
5733 testCases = append(testCases, testCase{
5734 testType: serverTest,
5735 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005736 resumeSession: true,
5737 config: Config{
5738 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005739 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005740 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005741 FilterTicket: func(in []byte) ([]byte, error) {
5742 return SetShimTicketVersion(in, VersionTLS13)
5743 },
5744 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005745 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005746 flags: []string{
5747 "-ticket-key",
5748 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5749 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005750 expectResumeRejected: true,
5751 })
5752
5753 testCases = append(testCases, testCase{
5754 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005755 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005756 resumeSession: true,
5757 config: Config{
5758 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005759 Bugs: ProtocolBugs{
5760 FilterTicket: func(in []byte) ([]byte, error) {
5761 return SetShimTicketVersion(in, VersionTLS12)
5762 },
5763 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005764 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005765 flags: []string{
5766 "-ticket-key",
5767 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5768 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005769 expectResumeRejected: true,
5770 })
5771
David Benjamin4199b0d2016-11-01 13:58:25 -04005772 // Resumptions are declined if the cipher is invalid or disabled.
5773 testCases = append(testCases, testCase{
5774 testType: serverTest,
5775 name: "Resume-Server-DeclineBadCipher",
5776 resumeSession: true,
5777 config: Config{
5778 MaxVersion: VersionTLS12,
5779 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005780 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005781 FilterTicket: func(in []byte) ([]byte, error) {
5782 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5783 },
5784 },
5785 },
5786 flags: []string{
5787 "-ticket-key",
5788 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5789 },
5790 expectResumeRejected: true,
5791 })
5792
5793 testCases = append(testCases, testCase{
5794 testType: serverTest,
5795 name: "Resume-Server-DeclineBadCipher-2",
5796 resumeSession: true,
5797 config: Config{
5798 MaxVersion: VersionTLS12,
5799 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005800 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005801 FilterTicket: func(in []byte) ([]byte, error) {
5802 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5803 },
5804 },
5805 },
5806 flags: []string{
5807 "-cipher", "AES128",
5808 "-ticket-key",
5809 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5810 },
5811 expectResumeRejected: true,
5812 })
5813
David Benjaminf01f42a2016-11-16 19:05:33 +09005814 // Sessions are not resumed if they do not use the preferred cipher.
5815 testCases = append(testCases, testCase{
5816 testType: serverTest,
5817 name: "Resume-Server-CipherNotPreferred",
5818 resumeSession: true,
5819 config: Config{
5820 MaxVersion: VersionTLS12,
5821 Bugs: ProtocolBugs{
5822 ExpectNewTicket: true,
5823 FilterTicket: func(in []byte) ([]byte, error) {
5824 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5825 },
5826 },
5827 },
5828 flags: []string{
5829 "-ticket-key",
5830 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5831 },
5832 shouldFail: false,
5833 expectResumeRejected: true,
5834 })
5835
5836 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5837 // PRF hashes match, but BoringSSL will always decline such resumptions.
5838 testCases = append(testCases, testCase{
5839 testType: serverTest,
5840 name: "Resume-Server-CipherNotPreferred-TLS13",
5841 resumeSession: true,
5842 config: Config{
5843 MaxVersion: VersionTLS13,
5844 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5845 Bugs: ProtocolBugs{
5846 FilterTicket: func(in []byte) ([]byte, error) {
5847 // If the client (runner) offers ChaCha20-Poly1305 first, the
5848 // server (shim) always prefers it. Switch it to AES-GCM.
5849 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5850 },
5851 },
5852 },
5853 flags: []string{
5854 "-ticket-key",
5855 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5856 },
5857 shouldFail: false,
5858 expectResumeRejected: true,
5859 })
5860
5861 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005862 testCases = append(testCases, testCase{
5863 testType: serverTest,
5864 name: "Resume-Server-DeclineBadCipher-TLS13",
5865 resumeSession: true,
5866 config: Config{
5867 MaxVersion: VersionTLS13,
5868 Bugs: ProtocolBugs{
5869 FilterTicket: func(in []byte) ([]byte, error) {
5870 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5871 },
5872 },
5873 },
5874 flags: []string{
5875 "-ticket-key",
5876 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5877 },
5878 expectResumeRejected: true,
5879 })
5880
David Benjaminf01f42a2016-11-16 19:05:33 +09005881 // If the client does not offer the cipher from the session, decline to
5882 // resume. Clients are forbidden from doing this, but BoringSSL selects
5883 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005884 testCases = append(testCases, testCase{
5885 testType: serverTest,
5886 name: "Resume-Server-UnofferedCipher",
5887 resumeSession: true,
5888 config: Config{
5889 MaxVersion: VersionTLS12,
5890 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5891 },
5892 resumeConfig: &Config{
5893 MaxVersion: VersionTLS12,
5894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5895 Bugs: ProtocolBugs{
5896 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5897 },
5898 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005899 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005900 })
5901
David Benjaminf01f42a2016-11-16 19:05:33 +09005902 // In TLS 1.3, clients may advertise a cipher list which does not
5903 // include the selected cipher. Test that we tolerate this. Servers may
5904 // resume at another cipher if the PRF matches, but BoringSSL will
5905 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005906 testCases = append(testCases, testCase{
5907 testType: serverTest,
5908 name: "Resume-Server-UnofferedCipher-TLS13",
5909 resumeSession: true,
5910 config: Config{
5911 MaxVersion: VersionTLS13,
5912 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5913 },
5914 resumeConfig: &Config{
5915 MaxVersion: VersionTLS13,
5916 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5917 Bugs: ProtocolBugs{
5918 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5919 },
5920 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005921 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005922 })
5923
David Benjamin4199b0d2016-11-01 13:58:25 -04005924 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005925 testCases = append(testCases, testCase{
5926 name: "Resume-Client-CipherMismatch",
5927 resumeSession: true,
5928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005929 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005930 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5931 },
5932 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005933 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005934 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5935 Bugs: ProtocolBugs{
5936 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5937 },
5938 },
5939 shouldFail: true,
5940 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5941 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005942
David Benjamine1cc35e2016-11-16 16:25:58 +09005943 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5944 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005945 testCases = append(testCases, testCase{
5946 name: "Resume-Client-CipherMismatch-TLS13",
5947 resumeSession: true,
5948 config: Config{
5949 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005950 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005951 },
5952 resumeConfig: &Config{
5953 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005954 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5955 },
5956 })
5957
5958 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5959 testCases = append(testCases, testCase{
5960 name: "Resume-Client-PRFMismatch-TLS13",
5961 resumeSession: true,
5962 config: Config{
5963 MaxVersion: VersionTLS13,
5964 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5965 },
5966 resumeConfig: &Config{
5967 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005968 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005969 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005970 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005971 },
5972 },
5973 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005974 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005975 })
Steven Valdeza833c352016-11-01 13:39:36 -04005976
5977 testCases = append(testCases, testCase{
5978 testType: serverTest,
5979 name: "Resume-Server-BinderWrongLength",
5980 resumeSession: true,
5981 config: Config{
5982 MaxVersion: VersionTLS13,
5983 Bugs: ProtocolBugs{
5984 SendShortPSKBinder: true,
5985 },
5986 },
5987 shouldFail: true,
5988 expectedLocalError: "remote error: error decrypting message",
5989 expectedError: ":DIGEST_CHECK_FAILED:",
5990 })
5991
5992 testCases = append(testCases, testCase{
5993 testType: serverTest,
5994 name: "Resume-Server-NoPSKBinder",
5995 resumeSession: true,
5996 config: Config{
5997 MaxVersion: VersionTLS13,
5998 Bugs: ProtocolBugs{
5999 SendNoPSKBinder: true,
6000 },
6001 },
6002 shouldFail: true,
6003 expectedLocalError: "remote error: error decoding message",
6004 expectedError: ":DECODE_ERROR:",
6005 })
6006
6007 testCases = append(testCases, testCase{
6008 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006009 name: "Resume-Server-ExtraPSKBinder",
6010 resumeSession: true,
6011 config: Config{
6012 MaxVersion: VersionTLS13,
6013 Bugs: ProtocolBugs{
6014 SendExtraPSKBinder: true,
6015 },
6016 },
6017 shouldFail: true,
6018 expectedLocalError: "remote error: illegal parameter",
6019 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6020 })
6021
6022 testCases = append(testCases, testCase{
6023 testType: serverTest,
6024 name: "Resume-Server-ExtraIdentityNoBinder",
6025 resumeSession: true,
6026 config: Config{
6027 MaxVersion: VersionTLS13,
6028 Bugs: ProtocolBugs{
6029 ExtraPSKIdentity: true,
6030 },
6031 },
6032 shouldFail: true,
6033 expectedLocalError: "remote error: illegal parameter",
6034 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6035 })
6036
6037 testCases = append(testCases, testCase{
6038 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006039 name: "Resume-Server-InvalidPSKBinder",
6040 resumeSession: true,
6041 config: Config{
6042 MaxVersion: VersionTLS13,
6043 Bugs: ProtocolBugs{
6044 SendInvalidPSKBinder: true,
6045 },
6046 },
6047 shouldFail: true,
6048 expectedLocalError: "remote error: error decrypting message",
6049 expectedError: ":DIGEST_CHECK_FAILED:",
6050 })
6051
6052 testCases = append(testCases, testCase{
6053 testType: serverTest,
6054 name: "Resume-Server-PSKBinderFirstExtension",
6055 resumeSession: true,
6056 config: Config{
6057 MaxVersion: VersionTLS13,
6058 Bugs: ProtocolBugs{
6059 PSKBinderFirst: true,
6060 },
6061 },
6062 shouldFail: true,
6063 expectedLocalError: "remote error: illegal parameter",
6064 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6065 })
David Benjamin01fe8202014-09-24 15:21:44 -04006066}
6067
Adam Langley2ae77d22014-10-28 17:29:33 -07006068func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006069 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006070 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006071 testType: serverTest,
6072 name: "Renegotiate-Server-Forbidden",
6073 config: Config{
6074 MaxVersion: VersionTLS12,
6075 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006076 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006077 shouldFail: true,
6078 expectedError: ":NO_RENEGOTIATION:",
6079 expectedLocalError: "remote error: no renegotiation",
6080 })
Adam Langley5021b222015-06-12 18:27:58 -07006081 // The server shouldn't echo the renegotiation extension unless
6082 // requested by the client.
6083 testCases = append(testCases, testCase{
6084 testType: serverTest,
6085 name: "Renegotiate-Server-NoExt",
6086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006087 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006088 Bugs: ProtocolBugs{
6089 NoRenegotiationInfo: true,
6090 RequireRenegotiationInfo: true,
6091 },
6092 },
6093 shouldFail: true,
6094 expectedLocalError: "renegotiation extension missing",
6095 })
6096 // The renegotiation SCSV should be sufficient for the server to echo
6097 // the extension.
6098 testCases = append(testCases, testCase{
6099 testType: serverTest,
6100 name: "Renegotiate-Server-NoExt-SCSV",
6101 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006102 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006103 Bugs: ProtocolBugs{
6104 NoRenegotiationInfo: true,
6105 SendRenegotiationSCSV: true,
6106 RequireRenegotiationInfo: true,
6107 },
6108 },
6109 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006110 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006111 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006113 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006114 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006115 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006116 },
6117 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006118 renegotiate: 1,
6119 flags: []string{
6120 "-renegotiate-freely",
6121 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006122 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006123 },
David Benjamincdea40c2015-03-19 14:09:43 -04006124 })
6125 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006126 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006127 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006128 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006129 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006130 Bugs: ProtocolBugs{
6131 EmptyRenegotiationInfo: true,
6132 },
6133 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006134 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006135 shouldFail: true,
6136 expectedError: ":RENEGOTIATION_MISMATCH:",
6137 })
6138 testCases = append(testCases, testCase{
6139 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006140 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006142 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006143 Bugs: ProtocolBugs{
6144 BadRenegotiationInfo: true,
6145 },
6146 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006147 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006148 shouldFail: true,
6149 expectedError: ":RENEGOTIATION_MISMATCH:",
6150 })
6151 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006152 name: "Renegotiate-Client-Downgrade",
6153 renegotiate: 1,
6154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006155 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006156 Bugs: ProtocolBugs{
6157 NoRenegotiationInfoAfterInitial: true,
6158 },
6159 },
6160 flags: []string{"-renegotiate-freely"},
6161 shouldFail: true,
6162 expectedError: ":RENEGOTIATION_MISMATCH:",
6163 })
6164 testCases = append(testCases, testCase{
6165 name: "Renegotiate-Client-Upgrade",
6166 renegotiate: 1,
6167 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006168 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006169 Bugs: ProtocolBugs{
6170 NoRenegotiationInfoInInitial: true,
6171 },
6172 },
6173 flags: []string{"-renegotiate-freely"},
6174 shouldFail: true,
6175 expectedError: ":RENEGOTIATION_MISMATCH:",
6176 })
6177 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006178 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006179 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006180 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006181 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006182 Bugs: ProtocolBugs{
6183 NoRenegotiationInfo: true,
6184 },
6185 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006186 flags: []string{
6187 "-renegotiate-freely",
6188 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006189 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006190 },
David Benjamincff0b902015-05-15 23:09:47 -04006191 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006192
6193 // Test that the server may switch ciphers on renegotiation without
6194 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006195 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006196 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006197 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006198 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006199 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006200 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006201 },
6202 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006203 flags: []string{
6204 "-renegotiate-freely",
6205 "-expect-total-renegotiations", "1",
6206 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006207 })
6208 testCases = append(testCases, testCase{
6209 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006210 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006211 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006212 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006213 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6214 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006215 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006216 flags: []string{
6217 "-renegotiate-freely",
6218 "-expect-total-renegotiations", "1",
6219 },
David Benjaminb16346b2015-04-08 19:16:58 -04006220 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006221
6222 // Test that the server may not switch versions on renegotiation.
6223 testCases = append(testCases, testCase{
6224 name: "Renegotiate-Client-SwitchVersion",
6225 config: Config{
6226 MaxVersion: VersionTLS12,
6227 // Pick a cipher which exists at both versions.
6228 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6229 Bugs: ProtocolBugs{
6230 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006231 // Avoid failing early at the record layer.
6232 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006233 },
6234 },
6235 renegotiate: 1,
6236 flags: []string{
6237 "-renegotiate-freely",
6238 "-expect-total-renegotiations", "1",
6239 },
6240 shouldFail: true,
6241 expectedError: ":WRONG_SSL_VERSION:",
6242 })
6243
David Benjaminb16346b2015-04-08 19:16:58 -04006244 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006245 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006246 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006247 config: Config{
6248 MaxVersion: VersionTLS10,
6249 Bugs: ProtocolBugs{
6250 RequireSameRenegoClientVersion: true,
6251 },
6252 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006253 flags: []string{
6254 "-renegotiate-freely",
6255 "-expect-total-renegotiations", "1",
6256 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006257 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006258 testCases = append(testCases, testCase{
6259 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006260 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006261 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006262 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006263 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6264 NextProtos: []string{"foo"},
6265 },
6266 flags: []string{
6267 "-false-start",
6268 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006269 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006270 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006271 },
6272 shimWritesFirst: true,
6273 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006274
6275 // Client-side renegotiation controls.
6276 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006277 name: "Renegotiate-Client-Forbidden-1",
6278 config: Config{
6279 MaxVersion: VersionTLS12,
6280 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006281 renegotiate: 1,
6282 shouldFail: true,
6283 expectedError: ":NO_RENEGOTIATION:",
6284 expectedLocalError: "remote error: no renegotiation",
6285 })
6286 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006287 name: "Renegotiate-Client-Once-1",
6288 config: Config{
6289 MaxVersion: VersionTLS12,
6290 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006291 renegotiate: 1,
6292 flags: []string{
6293 "-renegotiate-once",
6294 "-expect-total-renegotiations", "1",
6295 },
6296 })
6297 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006298 name: "Renegotiate-Client-Freely-1",
6299 config: Config{
6300 MaxVersion: VersionTLS12,
6301 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006302 renegotiate: 1,
6303 flags: []string{
6304 "-renegotiate-freely",
6305 "-expect-total-renegotiations", "1",
6306 },
6307 })
6308 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006309 name: "Renegotiate-Client-Once-2",
6310 config: Config{
6311 MaxVersion: VersionTLS12,
6312 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006313 renegotiate: 2,
6314 flags: []string{"-renegotiate-once"},
6315 shouldFail: true,
6316 expectedError: ":NO_RENEGOTIATION:",
6317 expectedLocalError: "remote error: no renegotiation",
6318 })
6319 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006320 name: "Renegotiate-Client-Freely-2",
6321 config: Config{
6322 MaxVersion: VersionTLS12,
6323 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006324 renegotiate: 2,
6325 flags: []string{
6326 "-renegotiate-freely",
6327 "-expect-total-renegotiations", "2",
6328 },
6329 })
Adam Langley27a0d082015-11-03 13:34:10 -08006330 testCases = append(testCases, testCase{
6331 name: "Renegotiate-Client-NoIgnore",
6332 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006333 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006334 Bugs: ProtocolBugs{
6335 SendHelloRequestBeforeEveryAppDataRecord: true,
6336 },
6337 },
6338 shouldFail: true,
6339 expectedError: ":NO_RENEGOTIATION:",
6340 })
6341 testCases = append(testCases, testCase{
6342 name: "Renegotiate-Client-Ignore",
6343 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006344 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006345 Bugs: ProtocolBugs{
6346 SendHelloRequestBeforeEveryAppDataRecord: true,
6347 },
6348 },
6349 flags: []string{
6350 "-renegotiate-ignore",
6351 "-expect-total-renegotiations", "0",
6352 },
6353 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006354
David Benjamin34941c02016-10-08 11:45:31 -04006355 // Renegotiation is not allowed at SSL 3.0.
6356 testCases = append(testCases, testCase{
6357 name: "Renegotiate-Client-SSL3",
6358 config: Config{
6359 MaxVersion: VersionSSL30,
6360 },
6361 renegotiate: 1,
6362 flags: []string{
6363 "-renegotiate-freely",
6364 "-expect-total-renegotiations", "1",
6365 },
6366 shouldFail: true,
6367 expectedError: ":NO_RENEGOTIATION:",
6368 expectedLocalError: "remote error: no renegotiation",
6369 })
6370
David Benjamina1eaba12017-01-01 23:19:22 -05006371 // Renegotiation is not allowed when there is an unfinished write.
6372 testCases = append(testCases, testCase{
6373 name: "Renegotiate-Client-UnfinishedWrite",
6374 config: Config{
6375 MaxVersion: VersionTLS12,
6376 },
6377 renegotiate: 1,
6378 flags: []string{
6379 "-async",
6380 "-renegotiate-freely",
6381 "-read-with-unfinished-write",
6382 },
6383 shouldFail: true,
6384 expectedError: ":NO_RENEGOTIATION:",
6385 // We do not successfully send the no_renegotiation alert in
6386 // this case. https://crbug.com/boringssl/130
6387 })
6388
David Benjamin397c8e62016-07-08 14:14:36 -07006389 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006390 testCases = append(testCases, testCase{
6391 name: "StrayHelloRequest",
6392 config: Config{
6393 MaxVersion: VersionTLS12,
6394 Bugs: ProtocolBugs{
6395 SendHelloRequestBeforeEveryHandshakeMessage: true,
6396 },
6397 },
6398 })
6399 testCases = append(testCases, testCase{
6400 name: "StrayHelloRequest-Packed",
6401 config: Config{
6402 MaxVersion: VersionTLS12,
6403 Bugs: ProtocolBugs{
6404 PackHandshakeFlight: true,
6405 SendHelloRequestBeforeEveryHandshakeMessage: true,
6406 },
6407 },
6408 })
6409
David Benjamin12d2c482016-07-24 10:56:51 -04006410 // Test renegotiation works if HelloRequest and server Finished come in
6411 // the same record.
6412 testCases = append(testCases, testCase{
6413 name: "Renegotiate-Client-Packed",
6414 config: Config{
6415 MaxVersion: VersionTLS12,
6416 Bugs: ProtocolBugs{
6417 PackHandshakeFlight: true,
6418 PackHelloRequestWithFinished: true,
6419 },
6420 },
6421 renegotiate: 1,
6422 flags: []string{
6423 "-renegotiate-freely",
6424 "-expect-total-renegotiations", "1",
6425 },
6426 })
6427
David Benjamin397c8e62016-07-08 14:14:36 -07006428 // Renegotiation is forbidden in TLS 1.3.
6429 testCases = append(testCases, testCase{
6430 name: "Renegotiate-Client-TLS13",
6431 config: Config{
6432 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006433 Bugs: ProtocolBugs{
6434 SendHelloRequestBeforeEveryAppDataRecord: true,
6435 },
David Benjamin397c8e62016-07-08 14:14:36 -07006436 },
David Benjamin397c8e62016-07-08 14:14:36 -07006437 flags: []string{
6438 "-renegotiate-freely",
6439 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006440 shouldFail: true,
6441 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006442 })
6443
6444 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6445 testCases = append(testCases, testCase{
6446 name: "StrayHelloRequest-TLS13",
6447 config: Config{
6448 MaxVersion: VersionTLS13,
6449 Bugs: ProtocolBugs{
6450 SendHelloRequestBeforeEveryHandshakeMessage: true,
6451 },
6452 },
6453 shouldFail: true,
6454 expectedError: ":UNEXPECTED_MESSAGE:",
6455 })
David Benjamind2610042017-01-03 10:49:28 -05006456
6457 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6458 // always reads as supporting it, regardless of whether it was
6459 // negotiated.
6460 testCases = append(testCases, testCase{
6461 name: "AlwaysReportRenegotiationInfo-TLS13",
6462 config: Config{
6463 MaxVersion: VersionTLS13,
6464 Bugs: ProtocolBugs{
6465 NoRenegotiationInfo: true,
6466 },
6467 },
6468 flags: []string{
6469 "-expect-secure-renegotiation",
6470 },
6471 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006472}
6473
David Benjamin5e961c12014-11-07 01:48:35 -05006474func addDTLSReplayTests() {
6475 // Test that sequence number replays are detected.
6476 testCases = append(testCases, testCase{
6477 protocol: dtls,
6478 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006479 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006480 replayWrites: true,
6481 })
6482
David Benjamin8e6db492015-07-25 18:29:23 -04006483 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006484 // than the retransmit window.
6485 testCases = append(testCases, testCase{
6486 protocol: dtls,
6487 name: "DTLS-Replay-LargeGaps",
6488 config: Config{
6489 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006490 SequenceNumberMapping: func(in uint64) uint64 {
6491 return in * 127
6492 },
David Benjamin5e961c12014-11-07 01:48:35 -05006493 },
6494 },
David Benjamin8e6db492015-07-25 18:29:23 -04006495 messageCount: 200,
6496 replayWrites: true,
6497 })
6498
6499 // Test the incoming sequence number changing non-monotonically.
6500 testCases = append(testCases, testCase{
6501 protocol: dtls,
6502 name: "DTLS-Replay-NonMonotonic",
6503 config: Config{
6504 Bugs: ProtocolBugs{
6505 SequenceNumberMapping: func(in uint64) uint64 {
6506 return in ^ 31
6507 },
6508 },
6509 },
6510 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006511 replayWrites: true,
6512 })
6513}
6514
Nick Harper60edffd2016-06-21 15:19:24 -07006515var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006516 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006517 id signatureAlgorithm
6518 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006519}{
Nick Harper60edffd2016-06-21 15:19:24 -07006520 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6521 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6522 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6523 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006524 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006525 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6526 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6527 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006528 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6529 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6530 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006531 // Tests for key types prior to TLS 1.2.
6532 {"RSA", 0, testCertRSA},
6533 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006534}
6535
Nick Harper60edffd2016-06-21 15:19:24 -07006536const fakeSigAlg1 signatureAlgorithm = 0x2a01
6537const fakeSigAlg2 signatureAlgorithm = 0xff01
6538
6539func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006540 // Not all ciphers involve a signature. Advertise a list which gives all
6541 // versions a signing cipher.
6542 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006543 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006544 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6545 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6546 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6547 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6548 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6549 }
6550
David Benjaminca3d5452016-07-14 12:51:01 -04006551 var allAlgorithms []signatureAlgorithm
6552 for _, alg := range testSignatureAlgorithms {
6553 if alg.id != 0 {
6554 allAlgorithms = append(allAlgorithms, alg.id)
6555 }
6556 }
6557
Nick Harper60edffd2016-06-21 15:19:24 -07006558 // Make sure each signature algorithm works. Include some fake values in
6559 // the list and ensure they're ignored.
6560 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006561 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006562 if (ver.version < VersionTLS12) != (alg.id == 0) {
6563 continue
6564 }
6565
6566 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6567 // or remove it in C.
6568 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006569 continue
6570 }
Nick Harper60edffd2016-06-21 15:19:24 -07006571
David Benjamin3ef76972016-10-17 17:59:54 -04006572 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006573 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006574 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006575 shouldSignFail = true
6576 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006577 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006578 // RSA-PKCS1 does not exist in TLS 1.3.
6579 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006580 shouldSignFail = true
6581 shouldVerifyFail = true
6582 }
6583
6584 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6585 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6586 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006587 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006588
6589 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006590 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006591 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006592 }
6593 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006594 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006595 }
David Benjamin000800a2014-11-14 01:43:59 -05006596
David Benjamin1fb125c2016-07-08 18:52:12 -07006597 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006598
David Benjamin7a41d372016-07-09 11:21:54 -07006599 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006600 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006601 config: Config{
6602 MaxVersion: ver.version,
6603 ClientAuth: RequireAnyClientCert,
6604 VerifySignatureAlgorithms: []signatureAlgorithm{
6605 fakeSigAlg1,
6606 alg.id,
6607 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006608 },
David Benjamin7a41d372016-07-09 11:21:54 -07006609 },
6610 flags: []string{
6611 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6612 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6613 "-enable-all-curves",
6614 },
David Benjamin3ef76972016-10-17 17:59:54 -04006615 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006616 expectedError: signError,
6617 expectedPeerSignatureAlgorithm: alg.id,
6618 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006619
David Benjamin7a41d372016-07-09 11:21:54 -07006620 testCases = append(testCases, testCase{
6621 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006622 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006623 config: Config{
6624 MaxVersion: ver.version,
6625 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6626 SignSignatureAlgorithms: []signatureAlgorithm{
6627 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006628 },
David Benjamin7a41d372016-07-09 11:21:54 -07006629 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006630 SkipECDSACurveCheck: shouldVerifyFail,
6631 IgnoreSignatureVersionChecks: shouldVerifyFail,
6632 // Some signature algorithms may not be advertised.
6633 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006634 },
David Benjamin7a41d372016-07-09 11:21:54 -07006635 },
6636 flags: []string{
6637 "-require-any-client-certificate",
6638 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6639 "-enable-all-curves",
6640 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006641 // Resume the session to assert the peer signature
6642 // algorithm is reported on both handshakes.
6643 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006644 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006645 expectedError: verifyError,
6646 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006647
6648 testCases = append(testCases, testCase{
6649 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006650 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006651 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006652 MaxVersion: ver.version,
6653 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006654 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006655 fakeSigAlg1,
6656 alg.id,
6657 fakeSigAlg2,
6658 },
6659 },
6660 flags: []string{
6661 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6662 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6663 "-enable-all-curves",
6664 },
David Benjamin3ef76972016-10-17 17:59:54 -04006665 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006666 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006667 expectedPeerSignatureAlgorithm: alg.id,
6668 })
6669
6670 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006671 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006672 config: Config{
6673 MaxVersion: ver.version,
6674 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006675 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006676 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006677 alg.id,
6678 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006679 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006680 SkipECDSACurveCheck: shouldVerifyFail,
6681 IgnoreSignatureVersionChecks: shouldVerifyFail,
6682 // Some signature algorithms may not be advertised.
6683 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006684 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006685 },
6686 flags: []string{
6687 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6688 "-enable-all-curves",
6689 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006690 // Resume the session to assert the peer signature
6691 // algorithm is reported on both handshakes.
6692 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006693 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006694 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006695 })
David Benjamin5208fd42016-07-13 21:43:25 -04006696
David Benjamin3ef76972016-10-17 17:59:54 -04006697 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006698 testCases = append(testCases, testCase{
6699 testType: serverTest,
6700 name: "ClientAuth-InvalidSignature" + suffix,
6701 config: Config{
6702 MaxVersion: ver.version,
6703 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6704 SignSignatureAlgorithms: []signatureAlgorithm{
6705 alg.id,
6706 },
6707 Bugs: ProtocolBugs{
6708 InvalidSignature: true,
6709 },
6710 },
6711 flags: []string{
6712 "-require-any-client-certificate",
6713 "-enable-all-curves",
6714 },
6715 shouldFail: true,
6716 expectedError: ":BAD_SIGNATURE:",
6717 })
6718
6719 testCases = append(testCases, testCase{
6720 name: "ServerAuth-InvalidSignature" + suffix,
6721 config: Config{
6722 MaxVersion: ver.version,
6723 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6724 CipherSuites: signingCiphers,
6725 SignSignatureAlgorithms: []signatureAlgorithm{
6726 alg.id,
6727 },
6728 Bugs: ProtocolBugs{
6729 InvalidSignature: true,
6730 },
6731 },
6732 flags: []string{"-enable-all-curves"},
6733 shouldFail: true,
6734 expectedError: ":BAD_SIGNATURE:",
6735 })
6736 }
David Benjaminca3d5452016-07-14 12:51:01 -04006737
David Benjamin3ef76972016-10-17 17:59:54 -04006738 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006739 testCases = append(testCases, testCase{
6740 name: "ClientAuth-Sign-Negotiate" + suffix,
6741 config: Config{
6742 MaxVersion: ver.version,
6743 ClientAuth: RequireAnyClientCert,
6744 VerifySignatureAlgorithms: allAlgorithms,
6745 },
6746 flags: []string{
6747 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6748 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6749 "-enable-all-curves",
6750 "-signing-prefs", strconv.Itoa(int(alg.id)),
6751 },
6752 expectedPeerSignatureAlgorithm: alg.id,
6753 })
6754
6755 testCases = append(testCases, testCase{
6756 testType: serverTest,
6757 name: "ServerAuth-Sign-Negotiate" + suffix,
6758 config: Config{
6759 MaxVersion: ver.version,
6760 CipherSuites: signingCiphers,
6761 VerifySignatureAlgorithms: allAlgorithms,
6762 },
6763 flags: []string{
6764 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6765 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6766 "-enable-all-curves",
6767 "-signing-prefs", strconv.Itoa(int(alg.id)),
6768 },
6769 expectedPeerSignatureAlgorithm: alg.id,
6770 })
6771 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006772 }
David Benjamin000800a2014-11-14 01:43:59 -05006773 }
6774
Nick Harper60edffd2016-06-21 15:19:24 -07006775 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006776 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006777 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006778 config: Config{
6779 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006780 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006781 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006782 signatureECDSAWithP521AndSHA512,
6783 signatureRSAPKCS1WithSHA384,
6784 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006785 },
6786 },
6787 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006788 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6789 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006790 },
Nick Harper60edffd2016-06-21 15:19:24 -07006791 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006792 })
6793
6794 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006795 name: "ClientAuth-SignatureType-TLS13",
6796 config: Config{
6797 ClientAuth: RequireAnyClientCert,
6798 MaxVersion: VersionTLS13,
6799 VerifySignatureAlgorithms: []signatureAlgorithm{
6800 signatureECDSAWithP521AndSHA512,
6801 signatureRSAPKCS1WithSHA384,
6802 signatureRSAPSSWithSHA384,
6803 signatureECDSAWithSHA1,
6804 },
6805 },
6806 flags: []string{
6807 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6808 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6809 },
6810 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6811 })
6812
6813 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006814 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006815 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006816 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006817 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006819 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006820 signatureECDSAWithP521AndSHA512,
6821 signatureRSAPKCS1WithSHA384,
6822 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006823 },
6824 },
Nick Harper60edffd2016-06-21 15:19:24 -07006825 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006826 })
6827
Steven Valdez143e8b32016-07-11 13:19:03 -04006828 testCases = append(testCases, testCase{
6829 testType: serverTest,
6830 name: "ServerAuth-SignatureType-TLS13",
6831 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006832 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006833 VerifySignatureAlgorithms: []signatureAlgorithm{
6834 signatureECDSAWithP521AndSHA512,
6835 signatureRSAPKCS1WithSHA384,
6836 signatureRSAPSSWithSHA384,
6837 signatureECDSAWithSHA1,
6838 },
6839 },
6840 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6841 })
6842
David Benjamina95e9f32016-07-08 16:28:04 -07006843 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006844 testCases = append(testCases, testCase{
6845 testType: serverTest,
6846 name: "Verify-ClientAuth-SignatureType",
6847 config: Config{
6848 MaxVersion: VersionTLS12,
6849 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006850 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006851 signatureRSAPKCS1WithSHA256,
6852 },
6853 Bugs: ProtocolBugs{
6854 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6855 },
6856 },
6857 flags: []string{
6858 "-require-any-client-certificate",
6859 },
6860 shouldFail: true,
6861 expectedError: ":WRONG_SIGNATURE_TYPE:",
6862 })
6863
6864 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006865 testType: serverTest,
6866 name: "Verify-ClientAuth-SignatureType-TLS13",
6867 config: Config{
6868 MaxVersion: VersionTLS13,
6869 Certificates: []Certificate{rsaCertificate},
6870 SignSignatureAlgorithms: []signatureAlgorithm{
6871 signatureRSAPSSWithSHA256,
6872 },
6873 Bugs: ProtocolBugs{
6874 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6875 },
6876 },
6877 flags: []string{
6878 "-require-any-client-certificate",
6879 },
6880 shouldFail: true,
6881 expectedError: ":WRONG_SIGNATURE_TYPE:",
6882 })
6883
6884 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006885 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006886 config: Config{
6887 MaxVersion: VersionTLS12,
6888 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006889 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006890 signatureRSAPKCS1WithSHA256,
6891 },
6892 Bugs: ProtocolBugs{
6893 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6894 },
6895 },
6896 shouldFail: true,
6897 expectedError: ":WRONG_SIGNATURE_TYPE:",
6898 })
6899
Steven Valdez143e8b32016-07-11 13:19:03 -04006900 testCases = append(testCases, testCase{
6901 name: "Verify-ServerAuth-SignatureType-TLS13",
6902 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006903 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006904 SignSignatureAlgorithms: []signatureAlgorithm{
6905 signatureRSAPSSWithSHA256,
6906 },
6907 Bugs: ProtocolBugs{
6908 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6909 },
6910 },
6911 shouldFail: true,
6912 expectedError: ":WRONG_SIGNATURE_TYPE:",
6913 })
6914
David Benjamin51dd7d62016-07-08 16:07:01 -07006915 // Test that, if the list is missing, the peer falls back to SHA-1 in
6916 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006917 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006918 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006920 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006921 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006922 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006923 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006924 },
6925 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006926 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006927 },
6928 },
6929 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006930 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6931 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006932 },
6933 })
6934
6935 testCases = append(testCases, testCase{
6936 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006937 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006938 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006939 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006940 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006941 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006942 },
6943 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006944 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006945 },
6946 },
David Benjaminee32bea2016-08-17 13:36:44 -04006947 flags: []string{
6948 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6949 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6950 },
6951 })
6952
6953 testCases = append(testCases, testCase{
6954 name: "ClientAuth-SHA1-Fallback-ECDSA",
6955 config: Config{
6956 MaxVersion: VersionTLS12,
6957 ClientAuth: RequireAnyClientCert,
6958 VerifySignatureAlgorithms: []signatureAlgorithm{
6959 signatureECDSAWithSHA1,
6960 },
6961 Bugs: ProtocolBugs{
6962 NoSignatureAlgorithms: true,
6963 },
6964 },
6965 flags: []string{
6966 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6967 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6968 },
6969 })
6970
6971 testCases = append(testCases, testCase{
6972 testType: serverTest,
6973 name: "ServerAuth-SHA1-Fallback-ECDSA",
6974 config: Config{
6975 MaxVersion: VersionTLS12,
6976 VerifySignatureAlgorithms: []signatureAlgorithm{
6977 signatureECDSAWithSHA1,
6978 },
6979 Bugs: ProtocolBugs{
6980 NoSignatureAlgorithms: true,
6981 },
6982 },
6983 flags: []string{
6984 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6985 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6986 },
David Benjamin000800a2014-11-14 01:43:59 -05006987 })
David Benjamin72dc7832015-03-16 17:49:43 -04006988
David Benjamin51dd7d62016-07-08 16:07:01 -07006989 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006990 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006991 config: Config{
6992 MaxVersion: VersionTLS13,
6993 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006994 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006995 signatureRSAPKCS1WithSHA1,
6996 },
6997 Bugs: ProtocolBugs{
6998 NoSignatureAlgorithms: true,
6999 },
7000 },
7001 flags: []string{
7002 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7003 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7004 },
David Benjamin48901652016-08-01 12:12:47 -04007005 shouldFail: true,
7006 // An empty CertificateRequest signature algorithm list is a
7007 // syntax error in TLS 1.3.
7008 expectedError: ":DECODE_ERROR:",
7009 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007010 })
7011
7012 testCases = append(testCases, testCase{
7013 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007014 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007015 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007016 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007017 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007018 signatureRSAPKCS1WithSHA1,
7019 },
7020 Bugs: ProtocolBugs{
7021 NoSignatureAlgorithms: true,
7022 },
7023 },
7024 shouldFail: true,
7025 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7026 })
7027
David Benjaminb62d2872016-07-18 14:55:02 +02007028 // Test that hash preferences are enforced. BoringSSL does not implement
7029 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007030 testCases = append(testCases, testCase{
7031 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007032 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007034 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007035 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007036 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007037 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007038 },
7039 Bugs: ProtocolBugs{
7040 IgnorePeerSignatureAlgorithmPreferences: 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{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007049 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007050 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007051 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007052 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007053 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007054 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007055 },
7056 Bugs: ProtocolBugs{
7057 IgnorePeerSignatureAlgorithmPreferences: true,
7058 },
7059 },
7060 shouldFail: true,
7061 expectedError: ":WRONG_SIGNATURE_TYPE:",
7062 })
David Benjaminb62d2872016-07-18 14:55:02 +02007063 testCases = append(testCases, testCase{
7064 testType: serverTest,
7065 name: "ClientAuth-Enforced-TLS13",
7066 config: Config{
7067 MaxVersion: VersionTLS13,
7068 Certificates: []Certificate{rsaCertificate},
7069 SignSignatureAlgorithms: []signatureAlgorithm{
7070 signatureRSAPKCS1WithMD5,
7071 },
7072 Bugs: ProtocolBugs{
7073 IgnorePeerSignatureAlgorithmPreferences: true,
7074 IgnoreSignatureVersionChecks: true,
7075 },
7076 },
7077 flags: []string{"-require-any-client-certificate"},
7078 shouldFail: true,
7079 expectedError: ":WRONG_SIGNATURE_TYPE:",
7080 })
7081
7082 testCases = append(testCases, testCase{
7083 name: "ServerAuth-Enforced-TLS13",
7084 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007085 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007086 SignSignatureAlgorithms: []signatureAlgorithm{
7087 signatureRSAPKCS1WithMD5,
7088 },
7089 Bugs: ProtocolBugs{
7090 IgnorePeerSignatureAlgorithmPreferences: true,
7091 IgnoreSignatureVersionChecks: true,
7092 },
7093 },
7094 shouldFail: true,
7095 expectedError: ":WRONG_SIGNATURE_TYPE:",
7096 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007097
7098 // Test that the agreed upon digest respects the client preferences and
7099 // the server digests.
7100 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007101 name: "NoCommonAlgorithms-Digests",
7102 config: Config{
7103 MaxVersion: VersionTLS12,
7104 ClientAuth: RequireAnyClientCert,
7105 VerifySignatureAlgorithms: []signatureAlgorithm{
7106 signatureRSAPKCS1WithSHA512,
7107 signatureRSAPKCS1WithSHA1,
7108 },
7109 },
7110 flags: []string{
7111 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7112 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7113 "-digest-prefs", "SHA256",
7114 },
7115 shouldFail: true,
7116 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7117 })
7118 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007119 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007120 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007121 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007122 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007123 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007124 signatureRSAPKCS1WithSHA512,
7125 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007126 },
7127 },
7128 flags: []string{
7129 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7130 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007131 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007132 },
David Benjaminca3d5452016-07-14 12:51:01 -04007133 shouldFail: true,
7134 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7135 })
7136 testCases = append(testCases, testCase{
7137 name: "NoCommonAlgorithms-TLS13",
7138 config: Config{
7139 MaxVersion: VersionTLS13,
7140 ClientAuth: RequireAnyClientCert,
7141 VerifySignatureAlgorithms: []signatureAlgorithm{
7142 signatureRSAPSSWithSHA512,
7143 signatureRSAPSSWithSHA384,
7144 },
7145 },
7146 flags: []string{
7147 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7148 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7149 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7150 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007151 shouldFail: true,
7152 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007153 })
7154 testCases = append(testCases, testCase{
7155 name: "Agree-Digest-SHA256",
7156 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007157 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007158 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007159 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007160 signatureRSAPKCS1WithSHA1,
7161 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007162 },
7163 },
7164 flags: []string{
7165 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7166 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007167 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007168 },
Nick Harper60edffd2016-06-21 15:19:24 -07007169 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007170 })
7171 testCases = append(testCases, testCase{
7172 name: "Agree-Digest-SHA1",
7173 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007174 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007175 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007176 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007177 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007178 },
7179 },
7180 flags: []string{
7181 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7182 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007183 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007184 },
Nick Harper60edffd2016-06-21 15:19:24 -07007185 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007186 })
7187 testCases = append(testCases, testCase{
7188 name: "Agree-Digest-Default",
7189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007190 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007191 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007192 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007193 signatureRSAPKCS1WithSHA256,
7194 signatureECDSAWithP256AndSHA256,
7195 signatureRSAPKCS1WithSHA1,
7196 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007197 },
7198 },
7199 flags: []string{
7200 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7201 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7202 },
Nick Harper60edffd2016-06-21 15:19:24 -07007203 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007204 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007205
David Benjaminca3d5452016-07-14 12:51:01 -04007206 // Test that the signing preference list may include extra algorithms
7207 // without negotiation problems.
7208 testCases = append(testCases, testCase{
7209 testType: serverTest,
7210 name: "FilterExtraAlgorithms",
7211 config: Config{
7212 MaxVersion: VersionTLS12,
7213 VerifySignatureAlgorithms: []signatureAlgorithm{
7214 signatureRSAPKCS1WithSHA256,
7215 },
7216 },
7217 flags: []string{
7218 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7219 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7220 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7221 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7222 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7223 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7224 },
7225 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7226 })
7227
David Benjamin4c3ddf72016-06-29 18:13:53 -04007228 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7229 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007230 testCases = append(testCases, testCase{
7231 name: "CheckLeafCurve",
7232 config: Config{
7233 MaxVersion: VersionTLS12,
7234 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007235 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007236 },
7237 flags: []string{"-p384-only"},
7238 shouldFail: true,
7239 expectedError: ":BAD_ECC_CERT:",
7240 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007241
7242 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7243 testCases = append(testCases, testCase{
7244 name: "CheckLeafCurve-TLS13",
7245 config: Config{
7246 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007247 Certificates: []Certificate{ecdsaP256Certificate},
7248 },
7249 flags: []string{"-p384-only"},
7250 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007251
7252 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7253 testCases = append(testCases, testCase{
7254 name: "ECDSACurveMismatch-Verify-TLS12",
7255 config: Config{
7256 MaxVersion: VersionTLS12,
7257 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7258 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007259 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007260 signatureECDSAWithP384AndSHA384,
7261 },
7262 },
7263 })
7264
7265 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7266 testCases = append(testCases, testCase{
7267 name: "ECDSACurveMismatch-Verify-TLS13",
7268 config: Config{
7269 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007270 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007271 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007272 signatureECDSAWithP384AndSHA384,
7273 },
7274 Bugs: ProtocolBugs{
7275 SkipECDSACurveCheck: true,
7276 },
7277 },
7278 shouldFail: true,
7279 expectedError: ":WRONG_SIGNATURE_TYPE:",
7280 })
7281
7282 // Signature algorithm selection in TLS 1.3 should take the curve into
7283 // account.
7284 testCases = append(testCases, testCase{
7285 testType: serverTest,
7286 name: "ECDSACurveMismatch-Sign-TLS13",
7287 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007288 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007289 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007290 signatureECDSAWithP384AndSHA384,
7291 signatureECDSAWithP256AndSHA256,
7292 },
7293 },
7294 flags: []string{
7295 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7296 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7297 },
7298 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7299 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007300
7301 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7302 // server does not attempt to sign in that case.
7303 testCases = append(testCases, testCase{
7304 testType: serverTest,
7305 name: "RSA-PSS-Large",
7306 config: Config{
7307 MaxVersion: VersionTLS13,
7308 VerifySignatureAlgorithms: []signatureAlgorithm{
7309 signatureRSAPSSWithSHA512,
7310 },
7311 },
7312 flags: []string{
7313 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7314 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7315 },
7316 shouldFail: true,
7317 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7318 })
David Benjamin57e929f2016-08-30 00:30:38 -04007319
7320 // Test that RSA-PSS is enabled by default for TLS 1.2.
7321 testCases = append(testCases, testCase{
7322 testType: clientTest,
7323 name: "RSA-PSS-Default-Verify",
7324 config: Config{
7325 MaxVersion: VersionTLS12,
7326 SignSignatureAlgorithms: []signatureAlgorithm{
7327 signatureRSAPSSWithSHA256,
7328 },
7329 },
7330 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7331 })
7332
7333 testCases = append(testCases, testCase{
7334 testType: serverTest,
7335 name: "RSA-PSS-Default-Sign",
7336 config: Config{
7337 MaxVersion: VersionTLS12,
7338 VerifySignatureAlgorithms: []signatureAlgorithm{
7339 signatureRSAPSSWithSHA256,
7340 },
7341 },
7342 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7343 })
David Benjamin000800a2014-11-14 01:43:59 -05007344}
7345
David Benjamin83f90402015-01-27 01:09:43 -05007346// timeouts is the retransmit schedule for BoringSSL. It doubles and
7347// caps at 60 seconds. On the 13th timeout, it gives up.
7348var timeouts = []time.Duration{
7349 1 * time.Second,
7350 2 * time.Second,
7351 4 * time.Second,
7352 8 * time.Second,
7353 16 * time.Second,
7354 32 * time.Second,
7355 60 * time.Second,
7356 60 * time.Second,
7357 60 * time.Second,
7358 60 * time.Second,
7359 60 * time.Second,
7360 60 * time.Second,
7361 60 * time.Second,
7362}
7363
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007364// shortTimeouts is an alternate set of timeouts which would occur if the
7365// initial timeout duration was set to 250ms.
7366var shortTimeouts = []time.Duration{
7367 250 * time.Millisecond,
7368 500 * time.Millisecond,
7369 1 * time.Second,
7370 2 * time.Second,
7371 4 * time.Second,
7372 8 * time.Second,
7373 16 * time.Second,
7374 32 * time.Second,
7375 60 * time.Second,
7376 60 * time.Second,
7377 60 * time.Second,
7378 60 * time.Second,
7379 60 * time.Second,
7380}
7381
David Benjamin83f90402015-01-27 01:09:43 -05007382func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007383 // These tests work by coordinating some behavior on both the shim and
7384 // the runner.
7385 //
7386 // TimeoutSchedule configures the runner to send a series of timeout
7387 // opcodes to the shim (see packetAdaptor) immediately before reading
7388 // each peer handshake flight N. The timeout opcode both simulates a
7389 // timeout in the shim and acts as a synchronization point to help the
7390 // runner bracket each handshake flight.
7391 //
7392 // We assume the shim does not read from the channel eagerly. It must
7393 // first wait until it has sent flight N and is ready to receive
7394 // handshake flight N+1. At this point, it will process the timeout
7395 // opcode. It must then immediately respond with a timeout ACK and act
7396 // as if the shim was idle for the specified amount of time.
7397 //
7398 // The runner then drops all packets received before the ACK and
7399 // continues waiting for flight N. This ordering results in one attempt
7400 // at sending flight N to be dropped. For the test to complete, the
7401 // shim must send flight N again, testing that the shim implements DTLS
7402 // retransmit on a timeout.
7403
Steven Valdez143e8b32016-07-11 13:19:03 -04007404 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007405 // likely be more epochs to cross and the final message's retransmit may
7406 // be more complex.
7407
David Benjamin585d7a42016-06-02 14:58:00 -04007408 for _, async := range []bool{true, false} {
7409 var tests []testCase
7410
7411 // Test that this is indeed the timeout schedule. Stress all
7412 // four patterns of handshake.
7413 for i := 1; i < len(timeouts); i++ {
7414 number := strconv.Itoa(i)
7415 tests = append(tests, testCase{
7416 protocol: dtls,
7417 name: "DTLS-Retransmit-Client-" + number,
7418 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007419 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007420 Bugs: ProtocolBugs{
7421 TimeoutSchedule: timeouts[:i],
7422 },
7423 },
7424 resumeSession: true,
7425 })
7426 tests = append(tests, testCase{
7427 protocol: dtls,
7428 testType: serverTest,
7429 name: "DTLS-Retransmit-Server-" + number,
7430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007431 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007432 Bugs: ProtocolBugs{
7433 TimeoutSchedule: timeouts[:i],
7434 },
7435 },
7436 resumeSession: true,
7437 })
7438 }
7439
7440 // Test that exceeding the timeout schedule hits a read
7441 // timeout.
7442 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007443 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007444 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007446 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007447 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007448 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007449 },
7450 },
7451 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007452 shouldFail: true,
7453 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007454 })
David Benjamin585d7a42016-06-02 14:58:00 -04007455
7456 if async {
7457 // Test that timeout handling has a fudge factor, due to API
7458 // problems.
7459 tests = append(tests, testCase{
7460 protocol: dtls,
7461 name: "DTLS-Retransmit-Fudge",
7462 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007463 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007464 Bugs: ProtocolBugs{
7465 TimeoutSchedule: []time.Duration{
7466 timeouts[0] - 10*time.Millisecond,
7467 },
7468 },
7469 },
7470 resumeSession: true,
7471 })
7472 }
7473
7474 // Test that the final Finished retransmitting isn't
7475 // duplicated if the peer badly fragments everything.
7476 tests = append(tests, testCase{
7477 testType: serverTest,
7478 protocol: dtls,
7479 name: "DTLS-Retransmit-Fragmented",
7480 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007481 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007482 Bugs: ProtocolBugs{
7483 TimeoutSchedule: []time.Duration{timeouts[0]},
7484 MaxHandshakeRecordLength: 2,
7485 },
7486 },
7487 })
7488
7489 // Test the timeout schedule when a shorter initial timeout duration is set.
7490 tests = append(tests, testCase{
7491 protocol: dtls,
7492 name: "DTLS-Retransmit-Short-Client",
7493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007494 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007495 Bugs: ProtocolBugs{
7496 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7497 },
7498 },
7499 resumeSession: true,
7500 flags: []string{"-initial-timeout-duration-ms", "250"},
7501 })
7502 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007503 protocol: dtls,
7504 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007505 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007507 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007508 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007509 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007510 },
7511 },
7512 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007513 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007514 })
David Benjamin585d7a42016-06-02 14:58:00 -04007515
7516 for _, test := range tests {
7517 if async {
7518 test.name += "-Async"
7519 test.flags = append(test.flags, "-async")
7520 }
7521
7522 testCases = append(testCases, test)
7523 }
David Benjamin83f90402015-01-27 01:09:43 -05007524 }
David Benjamin83f90402015-01-27 01:09:43 -05007525}
7526
David Benjaminc565ebb2015-04-03 04:06:36 -04007527func addExportKeyingMaterialTests() {
7528 for _, vers := range tlsVersions {
7529 if vers.version == VersionSSL30 {
7530 continue
7531 }
7532 testCases = append(testCases, testCase{
7533 name: "ExportKeyingMaterial-" + vers.name,
7534 config: Config{
7535 MaxVersion: vers.version,
7536 },
7537 exportKeyingMaterial: 1024,
7538 exportLabel: "label",
7539 exportContext: "context",
7540 useExportContext: true,
7541 })
7542 testCases = append(testCases, testCase{
7543 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7544 config: Config{
7545 MaxVersion: vers.version,
7546 },
7547 exportKeyingMaterial: 1024,
7548 })
7549 testCases = append(testCases, testCase{
7550 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7551 config: Config{
7552 MaxVersion: vers.version,
7553 },
7554 exportKeyingMaterial: 1024,
7555 useExportContext: true,
7556 })
7557 testCases = append(testCases, testCase{
7558 name: "ExportKeyingMaterial-Small-" + vers.name,
7559 config: Config{
7560 MaxVersion: vers.version,
7561 },
7562 exportKeyingMaterial: 1,
7563 exportLabel: "label",
7564 exportContext: "context",
7565 useExportContext: true,
7566 })
7567 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007568
David Benjaminc565ebb2015-04-03 04:06:36 -04007569 testCases = append(testCases, testCase{
7570 name: "ExportKeyingMaterial-SSL3",
7571 config: Config{
7572 MaxVersion: VersionSSL30,
7573 },
7574 exportKeyingMaterial: 1024,
7575 exportLabel: "label",
7576 exportContext: "context",
7577 useExportContext: true,
7578 shouldFail: true,
7579 expectedError: "failed to export keying material",
7580 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007581
7582 // Exporters work during a False Start.
7583 testCases = append(testCases, testCase{
7584 name: "ExportKeyingMaterial-FalseStart",
7585 config: Config{
7586 MaxVersion: VersionTLS12,
7587 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7588 NextProtos: []string{"foo"},
7589 Bugs: ProtocolBugs{
7590 ExpectFalseStart: true,
7591 },
7592 },
7593 flags: []string{
7594 "-false-start",
7595 "-advertise-alpn", "\x03foo",
7596 },
7597 shimWritesFirst: true,
7598 exportKeyingMaterial: 1024,
7599 exportLabel: "label",
7600 exportContext: "context",
7601 useExportContext: true,
7602 })
7603
7604 // Exporters do not work in the middle of a renegotiation. Test this by
7605 // triggering the exporter after every SSL_read call and configuring the
7606 // shim to run asynchronously.
7607 testCases = append(testCases, testCase{
7608 name: "ExportKeyingMaterial-Renegotiate",
7609 config: Config{
7610 MaxVersion: VersionTLS12,
7611 },
7612 renegotiate: 1,
7613 flags: []string{
7614 "-async",
7615 "-use-exporter-between-reads",
7616 "-renegotiate-freely",
7617 "-expect-total-renegotiations", "1",
7618 },
7619 shouldFail: true,
7620 expectedError: "failed to export keying material",
7621 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007622}
7623
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007624func addTLSUniqueTests() {
7625 for _, isClient := range []bool{false, true} {
7626 for _, isResumption := range []bool{false, true} {
7627 for _, hasEMS := range []bool{false, true} {
7628 var suffix string
7629 if isResumption {
7630 suffix = "Resume-"
7631 } else {
7632 suffix = "Full-"
7633 }
7634
7635 if hasEMS {
7636 suffix += "EMS-"
7637 } else {
7638 suffix += "NoEMS-"
7639 }
7640
7641 if isClient {
7642 suffix += "Client"
7643 } else {
7644 suffix += "Server"
7645 }
7646
7647 test := testCase{
7648 name: "TLSUnique-" + suffix,
7649 testTLSUnique: true,
7650 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007651 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007652 Bugs: ProtocolBugs{
7653 NoExtendedMasterSecret: !hasEMS,
7654 },
7655 },
7656 }
7657
7658 if isResumption {
7659 test.resumeSession = true
7660 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007661 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007662 Bugs: ProtocolBugs{
7663 NoExtendedMasterSecret: !hasEMS,
7664 },
7665 }
7666 }
7667
7668 if isResumption && !hasEMS {
7669 test.shouldFail = true
7670 test.expectedError = "failed to get tls-unique"
7671 }
7672
7673 testCases = append(testCases, test)
7674 }
7675 }
7676 }
7677}
7678
Adam Langley09505632015-07-30 18:10:13 -07007679func addCustomExtensionTests() {
7680 expectedContents := "custom extension"
7681 emptyString := ""
7682
7683 for _, isClient := range []bool{false, true} {
7684 suffix := "Server"
7685 flag := "-enable-server-custom-extension"
7686 testType := serverTest
7687 if isClient {
7688 suffix = "Client"
7689 flag = "-enable-client-custom-extension"
7690 testType = clientTest
7691 }
7692
7693 testCases = append(testCases, testCase{
7694 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007695 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007696 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007697 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007698 Bugs: ProtocolBugs{
7699 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007700 ExpectedCustomExtension: &expectedContents,
7701 },
7702 },
7703 flags: []string{flag},
7704 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007705 testCases = append(testCases, testCase{
7706 testType: testType,
7707 name: "CustomExtensions-" + suffix + "-TLS13",
7708 config: Config{
7709 MaxVersion: VersionTLS13,
7710 Bugs: ProtocolBugs{
7711 CustomExtension: expectedContents,
7712 ExpectedCustomExtension: &expectedContents,
7713 },
7714 },
7715 flags: []string{flag},
7716 })
Adam Langley09505632015-07-30 18:10:13 -07007717
7718 // If the parse callback fails, the handshake should also fail.
7719 testCases = append(testCases, testCase{
7720 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007721 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007722 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007723 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007724 Bugs: ProtocolBugs{
7725 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007726 ExpectedCustomExtension: &expectedContents,
7727 },
7728 },
David Benjamin399e7c92015-07-30 23:01:27 -04007729 flags: []string{flag},
7730 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007731 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7732 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007733 testCases = append(testCases, testCase{
7734 testType: testType,
7735 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7736 config: Config{
7737 MaxVersion: VersionTLS13,
7738 Bugs: ProtocolBugs{
7739 CustomExtension: expectedContents + "foo",
7740 ExpectedCustomExtension: &expectedContents,
7741 },
7742 },
7743 flags: []string{flag},
7744 shouldFail: true,
7745 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7746 })
Adam Langley09505632015-07-30 18:10:13 -07007747
7748 // If the add callback fails, the handshake should also fail.
7749 testCases = append(testCases, testCase{
7750 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007751 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007753 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007754 Bugs: ProtocolBugs{
7755 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007756 ExpectedCustomExtension: &expectedContents,
7757 },
7758 },
David Benjamin399e7c92015-07-30 23:01:27 -04007759 flags: []string{flag, "-custom-extension-fail-add"},
7760 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007761 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7762 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007763 testCases = append(testCases, testCase{
7764 testType: testType,
7765 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7766 config: Config{
7767 MaxVersion: VersionTLS13,
7768 Bugs: ProtocolBugs{
7769 CustomExtension: expectedContents,
7770 ExpectedCustomExtension: &expectedContents,
7771 },
7772 },
7773 flags: []string{flag, "-custom-extension-fail-add"},
7774 shouldFail: true,
7775 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7776 })
Adam Langley09505632015-07-30 18:10:13 -07007777
7778 // If the add callback returns zero, no extension should be
7779 // added.
7780 skipCustomExtension := expectedContents
7781 if isClient {
7782 // For the case where the client skips sending the
7783 // custom extension, the server must not “echo” it.
7784 skipCustomExtension = ""
7785 }
7786 testCases = append(testCases, testCase{
7787 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007788 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007789 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007790 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007791 Bugs: ProtocolBugs{
7792 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007793 ExpectedCustomExtension: &emptyString,
7794 },
7795 },
7796 flags: []string{flag, "-custom-extension-skip"},
7797 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007798 testCases = append(testCases, testCase{
7799 testType: testType,
7800 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7801 config: Config{
7802 MaxVersion: VersionTLS13,
7803 Bugs: ProtocolBugs{
7804 CustomExtension: skipCustomExtension,
7805 ExpectedCustomExtension: &emptyString,
7806 },
7807 },
7808 flags: []string{flag, "-custom-extension-skip"},
7809 })
Adam Langley09505632015-07-30 18:10:13 -07007810 }
7811
7812 // The custom extension add callback should not be called if the client
7813 // doesn't send the extension.
7814 testCases = append(testCases, testCase{
7815 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007816 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007817 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007818 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007819 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007820 ExpectedCustomExtension: &emptyString,
7821 },
7822 },
7823 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7824 })
Adam Langley2deb9842015-08-07 11:15:37 -07007825
Steven Valdez143e8b32016-07-11 13:19:03 -04007826 testCases = append(testCases, testCase{
7827 testType: serverTest,
7828 name: "CustomExtensions-NotCalled-Server-TLS13",
7829 config: Config{
7830 MaxVersion: VersionTLS13,
7831 Bugs: ProtocolBugs{
7832 ExpectedCustomExtension: &emptyString,
7833 },
7834 },
7835 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7836 })
7837
Adam Langley2deb9842015-08-07 11:15:37 -07007838 // Test an unknown extension from the server.
7839 testCases = append(testCases, testCase{
7840 testType: clientTest,
7841 name: "UnknownExtension-Client",
7842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007843 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007844 Bugs: ProtocolBugs{
7845 CustomExtension: expectedContents,
7846 },
7847 },
David Benjamin0c40a962016-08-01 12:05:50 -04007848 shouldFail: true,
7849 expectedError: ":UNEXPECTED_EXTENSION:",
7850 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007851 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007852 testCases = append(testCases, testCase{
7853 testType: clientTest,
7854 name: "UnknownExtension-Client-TLS13",
7855 config: Config{
7856 MaxVersion: VersionTLS13,
7857 Bugs: ProtocolBugs{
7858 CustomExtension: expectedContents,
7859 },
7860 },
David Benjamin0c40a962016-08-01 12:05:50 -04007861 shouldFail: true,
7862 expectedError: ":UNEXPECTED_EXTENSION:",
7863 expectedLocalError: "remote error: unsupported extension",
7864 })
David Benjamin490469f2016-10-05 22:44:38 -04007865 testCases = append(testCases, testCase{
7866 testType: clientTest,
7867 name: "UnknownUnencryptedExtension-Client-TLS13",
7868 config: Config{
7869 MaxVersion: VersionTLS13,
7870 Bugs: ProtocolBugs{
7871 CustomUnencryptedExtension: expectedContents,
7872 },
7873 },
7874 shouldFail: true,
7875 expectedError: ":UNEXPECTED_EXTENSION:",
7876 // The shim must send an alert, but alerts at this point do not
7877 // get successfully decrypted by the runner.
7878 expectedLocalError: "local error: bad record MAC",
7879 })
7880 testCases = append(testCases, testCase{
7881 testType: clientTest,
7882 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7883 config: Config{
7884 MaxVersion: VersionTLS13,
7885 Bugs: ProtocolBugs{
7886 SendUnencryptedALPN: "foo",
7887 },
7888 },
7889 flags: []string{
7890 "-advertise-alpn", "\x03foo\x03bar",
7891 },
7892 shouldFail: true,
7893 expectedError: ":UNEXPECTED_EXTENSION:",
7894 // The shim must send an alert, but alerts at this point do not
7895 // get successfully decrypted by the runner.
7896 expectedLocalError: "local error: bad record MAC",
7897 })
David Benjamin0c40a962016-08-01 12:05:50 -04007898
7899 // Test a known but unoffered extension from the server.
7900 testCases = append(testCases, testCase{
7901 testType: clientTest,
7902 name: "UnofferedExtension-Client",
7903 config: Config{
7904 MaxVersion: VersionTLS12,
7905 Bugs: ProtocolBugs{
7906 SendALPN: "alpn",
7907 },
7908 },
7909 shouldFail: true,
7910 expectedError: ":UNEXPECTED_EXTENSION:",
7911 expectedLocalError: "remote error: unsupported extension",
7912 })
7913 testCases = append(testCases, testCase{
7914 testType: clientTest,
7915 name: "UnofferedExtension-Client-TLS13",
7916 config: Config{
7917 MaxVersion: VersionTLS13,
7918 Bugs: ProtocolBugs{
7919 SendALPN: "alpn",
7920 },
7921 },
7922 shouldFail: true,
7923 expectedError: ":UNEXPECTED_EXTENSION:",
7924 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007925 })
Adam Langley09505632015-07-30 18:10:13 -07007926}
7927
David Benjaminb36a3952015-12-01 18:53:13 -05007928func addRSAClientKeyExchangeTests() {
7929 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7930 testCases = append(testCases, testCase{
7931 testType: serverTest,
7932 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7933 config: Config{
7934 // Ensure the ClientHello version and final
7935 // version are different, to detect if the
7936 // server uses the wrong one.
7937 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007938 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007939 Bugs: ProtocolBugs{
7940 BadRSAClientKeyExchange: bad,
7941 },
7942 },
7943 shouldFail: true,
7944 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7945 })
7946 }
David Benjamine63d9d72016-09-19 18:27:34 -04007947
7948 // The server must compare whatever was in ClientHello.version for the
7949 // RSA premaster.
7950 testCases = append(testCases, testCase{
7951 testType: serverTest,
7952 name: "SendClientVersion-RSA",
7953 config: Config{
7954 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7955 Bugs: ProtocolBugs{
7956 SendClientVersion: 0x1234,
7957 },
7958 },
7959 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7960 })
David Benjaminb36a3952015-12-01 18:53:13 -05007961}
7962
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007963var testCurves = []struct {
7964 name string
7965 id CurveID
7966}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007967 {"P-256", CurveP256},
7968 {"P-384", CurveP384},
7969 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007970 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007971}
7972
Steven Valdez5440fe02016-07-18 12:40:30 -04007973const bogusCurve = 0x1234
7974
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007975func addCurveTests() {
7976 for _, curve := range testCurves {
7977 testCases = append(testCases, testCase{
7978 name: "CurveTest-Client-" + curve.name,
7979 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007980 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7982 CurvePreferences: []CurveID{curve.id},
7983 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007984 flags: []string{
7985 "-enable-all-curves",
7986 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7987 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007988 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007989 })
7990 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007991 name: "CurveTest-Client-" + curve.name + "-TLS13",
7992 config: Config{
7993 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007994 CurvePreferences: []CurveID{curve.id},
7995 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007996 flags: []string{
7997 "-enable-all-curves",
7998 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7999 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008000 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008001 })
8002 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008003 testType: serverTest,
8004 name: "CurveTest-Server-" + curve.name,
8005 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008006 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008007 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8008 CurvePreferences: []CurveID{curve.id},
8009 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008010 flags: []string{
8011 "-enable-all-curves",
8012 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8013 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008014 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008015 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008016 testCases = append(testCases, testCase{
8017 testType: serverTest,
8018 name: "CurveTest-Server-" + curve.name + "-TLS13",
8019 config: Config{
8020 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008021 CurvePreferences: []CurveID{curve.id},
8022 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008023 flags: []string{
8024 "-enable-all-curves",
8025 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8026 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008027 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008028 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008029 }
David Benjamin241ae832016-01-15 03:04:54 -05008030
8031 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008032 testCases = append(testCases, testCase{
8033 testType: serverTest,
8034 name: "UnknownCurve",
8035 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008036 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008037 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8038 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8039 },
8040 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008041
Steven Valdez803c77a2016-09-06 14:13:43 -04008042 // The server must be tolerant to bogus curves.
8043 testCases = append(testCases, testCase{
8044 testType: serverTest,
8045 name: "UnknownCurve-TLS13",
8046 config: Config{
8047 MaxVersion: VersionTLS13,
8048 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8049 },
8050 })
8051
David Benjamin4c3ddf72016-06-29 18:13:53 -04008052 // The server must not consider ECDHE ciphers when there are no
8053 // supported curves.
8054 testCases = append(testCases, testCase{
8055 testType: serverTest,
8056 name: "NoSupportedCurves",
8057 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008058 MaxVersion: VersionTLS12,
8059 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8060 Bugs: ProtocolBugs{
8061 NoSupportedCurves: true,
8062 },
8063 },
8064 shouldFail: true,
8065 expectedError: ":NO_SHARED_CIPHER:",
8066 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008067 testCases = append(testCases, testCase{
8068 testType: serverTest,
8069 name: "NoSupportedCurves-TLS13",
8070 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008071 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008072 Bugs: ProtocolBugs{
8073 NoSupportedCurves: true,
8074 },
8075 },
8076 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008077 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008078 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008079
8080 // The server must fall back to another cipher when there are no
8081 // supported curves.
8082 testCases = append(testCases, testCase{
8083 testType: serverTest,
8084 name: "NoCommonCurves",
8085 config: Config{
8086 MaxVersion: VersionTLS12,
8087 CipherSuites: []uint16{
8088 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8089 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8090 },
8091 CurvePreferences: []CurveID{CurveP224},
8092 },
8093 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8094 })
8095
8096 // The client must reject bogus curves and disabled curves.
8097 testCases = append(testCases, testCase{
8098 name: "BadECDHECurve",
8099 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008100 MaxVersion: VersionTLS12,
8101 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8102 Bugs: ProtocolBugs{
8103 SendCurve: bogusCurve,
8104 },
8105 },
8106 shouldFail: true,
8107 expectedError: ":WRONG_CURVE:",
8108 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008109 testCases = append(testCases, testCase{
8110 name: "BadECDHECurve-TLS13",
8111 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008112 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008113 Bugs: ProtocolBugs{
8114 SendCurve: bogusCurve,
8115 },
8116 },
8117 shouldFail: true,
8118 expectedError: ":WRONG_CURVE:",
8119 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008120
8121 testCases = append(testCases, testCase{
8122 name: "UnsupportedCurve",
8123 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008124 MaxVersion: VersionTLS12,
8125 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8126 CurvePreferences: []CurveID{CurveP256},
8127 Bugs: ProtocolBugs{
8128 IgnorePeerCurvePreferences: true,
8129 },
8130 },
8131 flags: []string{"-p384-only"},
8132 shouldFail: true,
8133 expectedError: ":WRONG_CURVE:",
8134 })
8135
David Benjamin4f921572016-07-17 14:20:10 +02008136 testCases = append(testCases, testCase{
8137 // TODO(davidben): Add a TLS 1.3 version where
8138 // HelloRetryRequest requests an unsupported curve.
8139 name: "UnsupportedCurve-ServerHello-TLS13",
8140 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008141 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008142 CurvePreferences: []CurveID{CurveP384},
8143 Bugs: ProtocolBugs{
8144 SendCurve: CurveP256,
8145 },
8146 },
8147 flags: []string{"-p384-only"},
8148 shouldFail: true,
8149 expectedError: ":WRONG_CURVE:",
8150 })
8151
David Benjamin4c3ddf72016-06-29 18:13:53 -04008152 // Test invalid curve points.
8153 testCases = append(testCases, testCase{
8154 name: "InvalidECDHPoint-Client",
8155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008156 MaxVersion: VersionTLS12,
8157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8158 CurvePreferences: []CurveID{CurveP256},
8159 Bugs: ProtocolBugs{
8160 InvalidECDHPoint: true,
8161 },
8162 },
8163 shouldFail: true,
8164 expectedError: ":INVALID_ENCODING:",
8165 })
8166 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008167 name: "InvalidECDHPoint-Client-TLS13",
8168 config: Config{
8169 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008170 CurvePreferences: []CurveID{CurveP256},
8171 Bugs: ProtocolBugs{
8172 InvalidECDHPoint: true,
8173 },
8174 },
8175 shouldFail: true,
8176 expectedError: ":INVALID_ENCODING:",
8177 })
8178 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008179 testType: serverTest,
8180 name: "InvalidECDHPoint-Server",
8181 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008182 MaxVersion: VersionTLS12,
8183 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8184 CurvePreferences: []CurveID{CurveP256},
8185 Bugs: ProtocolBugs{
8186 InvalidECDHPoint: true,
8187 },
8188 },
8189 shouldFail: true,
8190 expectedError: ":INVALID_ENCODING:",
8191 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008192 testCases = append(testCases, testCase{
8193 testType: serverTest,
8194 name: "InvalidECDHPoint-Server-TLS13",
8195 config: Config{
8196 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008197 CurvePreferences: []CurveID{CurveP256},
8198 Bugs: ProtocolBugs{
8199 InvalidECDHPoint: true,
8200 },
8201 },
8202 shouldFail: true,
8203 expectedError: ":INVALID_ENCODING:",
8204 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008205
8206 // The previous curve ID should be reported on TLS 1.2 resumption.
8207 testCases = append(testCases, testCase{
8208 name: "CurveID-Resume-Client",
8209 config: Config{
8210 MaxVersion: VersionTLS12,
8211 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8212 CurvePreferences: []CurveID{CurveX25519},
8213 },
8214 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8215 resumeSession: true,
8216 })
8217 testCases = append(testCases, testCase{
8218 testType: serverTest,
8219 name: "CurveID-Resume-Server",
8220 config: Config{
8221 MaxVersion: VersionTLS12,
8222 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8223 CurvePreferences: []CurveID{CurveX25519},
8224 },
8225 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8226 resumeSession: true,
8227 })
8228
8229 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8230 // one should be reported.
8231 testCases = append(testCases, testCase{
8232 name: "CurveID-Resume-Client-TLS13",
8233 config: Config{
8234 MaxVersion: VersionTLS13,
8235 CurvePreferences: []CurveID{CurveX25519},
8236 },
8237 resumeConfig: &Config{
8238 MaxVersion: VersionTLS13,
8239 CurvePreferences: []CurveID{CurveP256},
8240 },
8241 flags: []string{
8242 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8243 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8244 },
8245 resumeSession: true,
8246 })
8247 testCases = append(testCases, testCase{
8248 testType: serverTest,
8249 name: "CurveID-Resume-Server-TLS13",
8250 config: Config{
8251 MaxVersion: VersionTLS13,
8252 CurvePreferences: []CurveID{CurveX25519},
8253 },
8254 resumeConfig: &Config{
8255 MaxVersion: VersionTLS13,
8256 CurvePreferences: []CurveID{CurveP256},
8257 },
8258 flags: []string{
8259 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8260 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8261 },
8262 resumeSession: true,
8263 })
David Benjamina81967b2016-12-22 09:16:57 -05008264
8265 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8266 testCases = append(testCases, testCase{
8267 name: "PointFormat-ServerHello-TLS12",
8268 config: Config{
8269 MaxVersion: VersionTLS12,
8270 Bugs: ProtocolBugs{
8271 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8272 },
8273 },
8274 })
8275 testCases = append(testCases, testCase{
8276 name: "PointFormat-EncryptedExtensions-TLS13",
8277 config: Config{
8278 MaxVersion: VersionTLS13,
8279 Bugs: ProtocolBugs{
8280 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8281 },
8282 },
8283 shouldFail: true,
8284 expectedError: ":ERROR_PARSING_EXTENSION:",
8285 })
8286
8287 // Test that we tolerate unknown point formats, as long as
8288 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8289 // check they are still functional.
8290 testCases = append(testCases, testCase{
8291 name: "PointFormat-Client-Tolerance",
8292 config: Config{
8293 MaxVersion: VersionTLS12,
8294 Bugs: ProtocolBugs{
8295 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8296 },
8297 },
8298 })
8299 testCases = append(testCases, testCase{
8300 testType: serverTest,
8301 name: "PointFormat-Server-Tolerance",
8302 config: Config{
8303 MaxVersion: VersionTLS12,
8304 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8305 Bugs: ProtocolBugs{
8306 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8307 },
8308 },
8309 })
8310
8311 // Test TLS 1.2 does not require the point format extension to be
8312 // present.
8313 testCases = append(testCases, testCase{
8314 name: "PointFormat-Client-Missing",
8315 config: Config{
8316 MaxVersion: VersionTLS12,
8317 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8318 Bugs: ProtocolBugs{
8319 SendSupportedPointFormats: []byte{},
8320 },
8321 },
8322 })
8323 testCases = append(testCases, testCase{
8324 testType: serverTest,
8325 name: "PointFormat-Server-Missing",
8326 config: Config{
8327 MaxVersion: VersionTLS12,
8328 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8329 Bugs: ProtocolBugs{
8330 SendSupportedPointFormats: []byte{},
8331 },
8332 },
8333 })
8334
8335 // If the point format extension is present, uncompressed points must be
8336 // offered. BoringSSL requires this whether or not ECDHE is used.
8337 testCases = append(testCases, testCase{
8338 name: "PointFormat-Client-MissingUncompressed",
8339 config: Config{
8340 MaxVersion: VersionTLS12,
8341 Bugs: ProtocolBugs{
8342 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8343 },
8344 },
8345 shouldFail: true,
8346 expectedError: ":ERROR_PARSING_EXTENSION:",
8347 })
8348 testCases = append(testCases, testCase{
8349 testType: serverTest,
8350 name: "PointFormat-Server-MissingUncompressed",
8351 config: Config{
8352 MaxVersion: VersionTLS12,
8353 Bugs: ProtocolBugs{
8354 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8355 },
8356 },
8357 shouldFail: true,
8358 expectedError: ":ERROR_PARSING_EXTENSION:",
8359 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008360}
8361
David Benjaminc9ae27c2016-06-24 22:56:37 -04008362func addTLS13RecordTests() {
8363 testCases = append(testCases, testCase{
8364 name: "TLS13-RecordPadding",
8365 config: Config{
8366 MaxVersion: VersionTLS13,
8367 MinVersion: VersionTLS13,
8368 Bugs: ProtocolBugs{
8369 RecordPadding: 10,
8370 },
8371 },
8372 })
8373
8374 testCases = append(testCases, testCase{
8375 name: "TLS13-EmptyRecords",
8376 config: Config{
8377 MaxVersion: VersionTLS13,
8378 MinVersion: VersionTLS13,
8379 Bugs: ProtocolBugs{
8380 OmitRecordContents: true,
8381 },
8382 },
8383 shouldFail: true,
8384 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8385 })
8386
8387 testCases = append(testCases, testCase{
8388 name: "TLS13-OnlyPadding",
8389 config: Config{
8390 MaxVersion: VersionTLS13,
8391 MinVersion: VersionTLS13,
8392 Bugs: ProtocolBugs{
8393 OmitRecordContents: true,
8394 RecordPadding: 10,
8395 },
8396 },
8397 shouldFail: true,
8398 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8399 })
8400
8401 testCases = append(testCases, testCase{
8402 name: "TLS13-WrongOuterRecord",
8403 config: Config{
8404 MaxVersion: VersionTLS13,
8405 MinVersion: VersionTLS13,
8406 Bugs: ProtocolBugs{
8407 OuterRecordType: recordTypeHandshake,
8408 },
8409 },
8410 shouldFail: true,
8411 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8412 })
8413}
8414
Steven Valdez5b986082016-09-01 12:29:49 -04008415func addSessionTicketTests() {
8416 testCases = append(testCases, testCase{
8417 // In TLS 1.2 and below, empty NewSessionTicket messages
8418 // mean the server changed its mind on sending a ticket.
8419 name: "SendEmptySessionTicket",
8420 config: Config{
8421 MaxVersion: VersionTLS12,
8422 Bugs: ProtocolBugs{
8423 SendEmptySessionTicket: true,
8424 },
8425 },
8426 flags: []string{"-expect-no-session"},
8427 })
8428
8429 // Test that the server ignores unknown PSK modes.
8430 testCases = append(testCases, testCase{
8431 testType: serverTest,
8432 name: "TLS13-SendUnknownModeSessionTicket-Server",
8433 config: Config{
8434 MaxVersion: VersionTLS13,
8435 Bugs: ProtocolBugs{
8436 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008437 },
8438 },
8439 resumeSession: true,
8440 expectedResumeVersion: VersionTLS13,
8441 })
8442
Steven Valdeza833c352016-11-01 13:39:36 -04008443 // Test that the server does not send session tickets with no matching key exchange mode.
8444 testCases = append(testCases, testCase{
8445 testType: serverTest,
8446 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8447 config: Config{
8448 MaxVersion: VersionTLS13,
8449 Bugs: ProtocolBugs{
8450 SendPSKKeyExchangeModes: []byte{0x1a},
8451 ExpectNoNewSessionTicket: true,
8452 },
8453 },
8454 })
8455
8456 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008457 testCases = append(testCases, testCase{
8458 testType: serverTest,
8459 name: "TLS13-SendBadKEModeSessionTicket-Server",
8460 config: Config{
8461 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008462 },
8463 resumeConfig: &Config{
8464 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008465 Bugs: ProtocolBugs{
8466 SendPSKKeyExchangeModes: []byte{0x1a},
8467 },
8468 },
8469 resumeSession: true,
8470 expectResumeRejected: true,
8471 })
8472
Steven Valdeza833c352016-11-01 13:39:36 -04008473 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008474 testCases = append(testCases, testCase{
8475 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008476 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008477 config: Config{
8478 MaxVersion: VersionTLS13,
8479 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008480 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008481 },
8482 },
Steven Valdeza833c352016-11-01 13:39:36 -04008483 resumeSession: true,
8484 flags: []string{
8485 "-resumption-delay", "10",
8486 },
Steven Valdez5b986082016-09-01 12:29:49 -04008487 })
8488
Steven Valdeza833c352016-11-01 13:39:36 -04008489 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008490 testCases = append(testCases, testCase{
8491 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008492 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008493 config: Config{
8494 MaxVersion: VersionTLS13,
8495 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008496 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008497 },
8498 },
Steven Valdeza833c352016-11-01 13:39:36 -04008499 resumeSession: true,
8500 shouldFail: true,
8501 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008502 })
8503
Steven Valdez08b65f42016-12-07 15:29:45 -05008504 testCases = append(testCases, testCase{
8505 testType: clientTest,
8506 name: "TLS13-SendTicketEarlyDataInfo",
8507 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008508 MaxVersion: VersionTLS13,
8509 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008510 },
8511 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008512 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008513 "-expect-early-data-info",
8514 },
8515 })
8516
David Benjamin9b160662017-01-25 19:53:43 -05008517 // Test that 0-RTT tickets are ignored in clients unless opted in.
8518 testCases = append(testCases, testCase{
8519 testType: clientTest,
8520 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8521 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008522 MaxVersion: VersionTLS13,
8523 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008524 },
8525 })
8526
Steven Valdez08b65f42016-12-07 15:29:45 -05008527 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008528 testType: clientTest,
8529 name: "TLS13-DuplicateTicketEarlyDataInfo",
8530 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008531 MaxVersion: VersionTLS13,
8532 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008533 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008534 DuplicateTicketEarlyDataInfo: true,
8535 },
8536 },
8537 shouldFail: true,
8538 expectedError: ":DUPLICATE_EXTENSION:",
8539 expectedLocalError: "remote error: illegal parameter",
8540 })
8541
8542 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008543 testType: serverTest,
8544 name: "TLS13-ExpectTicketEarlyDataInfo",
8545 config: Config{
8546 MaxVersion: VersionTLS13,
8547 Bugs: ProtocolBugs{
8548 ExpectTicketEarlyDataInfo: true,
8549 },
8550 },
8551 flags: []string{
8552 "-enable-early-data",
8553 },
8554 })
David Benjamin17b30832017-01-28 14:00:32 -05008555
8556 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8557 // is honored.
8558 testCases = append(testCases, testCase{
8559 testType: clientTest,
8560 name: "TLS13-HonorServerSessionTicketLifetime",
8561 config: Config{
8562 MaxVersion: VersionTLS13,
8563 Bugs: ProtocolBugs{
8564 SendTicketLifetime: 20 * time.Second,
8565 },
8566 },
8567 flags: []string{
8568 "-resumption-delay", "19",
8569 },
8570 resumeSession: true,
8571 })
8572 testCases = append(testCases, testCase{
8573 testType: clientTest,
8574 name: "TLS13-HonorServerSessionTicketLifetime-2",
8575 config: Config{
8576 MaxVersion: VersionTLS13,
8577 Bugs: ProtocolBugs{
8578 SendTicketLifetime: 20 * time.Second,
8579 // The client should not offer the expired session.
8580 ExpectNoTLS13PSK: true,
8581 },
8582 },
8583 flags: []string{
8584 "-resumption-delay", "21",
8585 },
David Benjamin023d4192017-02-06 13:49:07 -05008586 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008587 expectResumeRejected: true,
8588 })
Steven Valdez5b986082016-09-01 12:29:49 -04008589}
8590
David Benjamin82261be2016-07-07 14:32:50 -07008591func addChangeCipherSpecTests() {
8592 // Test missing ChangeCipherSpecs.
8593 testCases = append(testCases, testCase{
8594 name: "SkipChangeCipherSpec-Client",
8595 config: Config{
8596 MaxVersion: VersionTLS12,
8597 Bugs: ProtocolBugs{
8598 SkipChangeCipherSpec: true,
8599 },
8600 },
8601 shouldFail: true,
8602 expectedError: ":UNEXPECTED_RECORD:",
8603 })
8604 testCases = append(testCases, testCase{
8605 testType: serverTest,
8606 name: "SkipChangeCipherSpec-Server",
8607 config: Config{
8608 MaxVersion: VersionTLS12,
8609 Bugs: ProtocolBugs{
8610 SkipChangeCipherSpec: true,
8611 },
8612 },
8613 shouldFail: true,
8614 expectedError: ":UNEXPECTED_RECORD:",
8615 })
8616 testCases = append(testCases, testCase{
8617 testType: serverTest,
8618 name: "SkipChangeCipherSpec-Server-NPN",
8619 config: Config{
8620 MaxVersion: VersionTLS12,
8621 NextProtos: []string{"bar"},
8622 Bugs: ProtocolBugs{
8623 SkipChangeCipherSpec: true,
8624 },
8625 },
8626 flags: []string{
8627 "-advertise-npn", "\x03foo\x03bar\x03baz",
8628 },
8629 shouldFail: true,
8630 expectedError: ":UNEXPECTED_RECORD:",
8631 })
8632
8633 // Test synchronization between the handshake and ChangeCipherSpec.
8634 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8635 // rejected. Test both with and without handshake packing to handle both
8636 // when the partial post-CCS message is in its own record and when it is
8637 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008638 for _, packed := range []bool{false, true} {
8639 var suffix string
8640 if packed {
8641 suffix = "-Packed"
8642 }
8643
8644 testCases = append(testCases, testCase{
8645 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8646 config: Config{
8647 MaxVersion: VersionTLS12,
8648 Bugs: ProtocolBugs{
8649 FragmentAcrossChangeCipherSpec: true,
8650 PackHandshakeFlight: packed,
8651 },
8652 },
8653 shouldFail: true,
8654 expectedError: ":UNEXPECTED_RECORD:",
8655 })
8656 testCases = append(testCases, testCase{
8657 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8658 config: Config{
8659 MaxVersion: VersionTLS12,
8660 },
8661 resumeSession: true,
8662 resumeConfig: &Config{
8663 MaxVersion: VersionTLS12,
8664 Bugs: ProtocolBugs{
8665 FragmentAcrossChangeCipherSpec: true,
8666 PackHandshakeFlight: packed,
8667 },
8668 },
8669 shouldFail: true,
8670 expectedError: ":UNEXPECTED_RECORD:",
8671 })
8672 testCases = append(testCases, testCase{
8673 testType: serverTest,
8674 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8675 config: Config{
8676 MaxVersion: VersionTLS12,
8677 Bugs: ProtocolBugs{
8678 FragmentAcrossChangeCipherSpec: true,
8679 PackHandshakeFlight: packed,
8680 },
8681 },
8682 shouldFail: true,
8683 expectedError: ":UNEXPECTED_RECORD:",
8684 })
8685 testCases = append(testCases, testCase{
8686 testType: serverTest,
8687 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8688 config: Config{
8689 MaxVersion: VersionTLS12,
8690 },
8691 resumeSession: true,
8692 resumeConfig: &Config{
8693 MaxVersion: VersionTLS12,
8694 Bugs: ProtocolBugs{
8695 FragmentAcrossChangeCipherSpec: true,
8696 PackHandshakeFlight: packed,
8697 },
8698 },
8699 shouldFail: true,
8700 expectedError: ":UNEXPECTED_RECORD:",
8701 })
8702 testCases = append(testCases, testCase{
8703 testType: serverTest,
8704 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8705 config: Config{
8706 MaxVersion: VersionTLS12,
8707 NextProtos: []string{"bar"},
8708 Bugs: ProtocolBugs{
8709 FragmentAcrossChangeCipherSpec: true,
8710 PackHandshakeFlight: packed,
8711 },
8712 },
8713 flags: []string{
8714 "-advertise-npn", "\x03foo\x03bar\x03baz",
8715 },
8716 shouldFail: true,
8717 expectedError: ":UNEXPECTED_RECORD:",
8718 })
8719 }
8720
David Benjamin61672812016-07-14 23:10:43 -04008721 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8722 // messages in the handshake queue. Do this by testing the server
8723 // reading the client Finished, reversing the flight so Finished comes
8724 // first.
8725 testCases = append(testCases, testCase{
8726 protocol: dtls,
8727 testType: serverTest,
8728 name: "SendUnencryptedFinished-DTLS",
8729 config: Config{
8730 MaxVersion: VersionTLS12,
8731 Bugs: ProtocolBugs{
8732 SendUnencryptedFinished: true,
8733 ReverseHandshakeFragments: true,
8734 },
8735 },
8736 shouldFail: true,
8737 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8738 })
8739
Steven Valdez143e8b32016-07-11 13:19:03 -04008740 // Test synchronization between encryption changes and the handshake in
8741 // TLS 1.3, where ChangeCipherSpec is implicit.
8742 testCases = append(testCases, testCase{
8743 name: "PartialEncryptedExtensionsWithServerHello",
8744 config: Config{
8745 MaxVersion: VersionTLS13,
8746 Bugs: ProtocolBugs{
8747 PartialEncryptedExtensionsWithServerHello: true,
8748 },
8749 },
8750 shouldFail: true,
8751 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8752 })
8753 testCases = append(testCases, testCase{
8754 testType: serverTest,
8755 name: "PartialClientFinishedWithClientHello",
8756 config: Config{
8757 MaxVersion: VersionTLS13,
8758 Bugs: ProtocolBugs{
8759 PartialClientFinishedWithClientHello: true,
8760 },
8761 },
8762 shouldFail: true,
8763 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8764 })
8765
David Benjamin82261be2016-07-07 14:32:50 -07008766 // Test that early ChangeCipherSpecs are handled correctly.
8767 testCases = append(testCases, testCase{
8768 testType: serverTest,
8769 name: "EarlyChangeCipherSpec-server-1",
8770 config: Config{
8771 MaxVersion: VersionTLS12,
8772 Bugs: ProtocolBugs{
8773 EarlyChangeCipherSpec: 1,
8774 },
8775 },
8776 shouldFail: true,
8777 expectedError: ":UNEXPECTED_RECORD:",
8778 })
8779 testCases = append(testCases, testCase{
8780 testType: serverTest,
8781 name: "EarlyChangeCipherSpec-server-2",
8782 config: Config{
8783 MaxVersion: VersionTLS12,
8784 Bugs: ProtocolBugs{
8785 EarlyChangeCipherSpec: 2,
8786 },
8787 },
8788 shouldFail: true,
8789 expectedError: ":UNEXPECTED_RECORD:",
8790 })
8791 testCases = append(testCases, testCase{
8792 protocol: dtls,
8793 name: "StrayChangeCipherSpec",
8794 config: Config{
8795 // TODO(davidben): Once DTLS 1.3 exists, test
8796 // that stray ChangeCipherSpec messages are
8797 // rejected.
8798 MaxVersion: VersionTLS12,
8799 Bugs: ProtocolBugs{
8800 StrayChangeCipherSpec: true,
8801 },
8802 },
8803 })
8804
8805 // Test that the contents of ChangeCipherSpec are checked.
8806 testCases = append(testCases, testCase{
8807 name: "BadChangeCipherSpec-1",
8808 config: Config{
8809 MaxVersion: VersionTLS12,
8810 Bugs: ProtocolBugs{
8811 BadChangeCipherSpec: []byte{2},
8812 },
8813 },
8814 shouldFail: true,
8815 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8816 })
8817 testCases = append(testCases, testCase{
8818 name: "BadChangeCipherSpec-2",
8819 config: Config{
8820 MaxVersion: VersionTLS12,
8821 Bugs: ProtocolBugs{
8822 BadChangeCipherSpec: []byte{1, 1},
8823 },
8824 },
8825 shouldFail: true,
8826 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8827 })
8828 testCases = append(testCases, testCase{
8829 protocol: dtls,
8830 name: "BadChangeCipherSpec-DTLS-1",
8831 config: Config{
8832 MaxVersion: VersionTLS12,
8833 Bugs: ProtocolBugs{
8834 BadChangeCipherSpec: []byte{2},
8835 },
8836 },
8837 shouldFail: true,
8838 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8839 })
8840 testCases = append(testCases, testCase{
8841 protocol: dtls,
8842 name: "BadChangeCipherSpec-DTLS-2",
8843 config: Config{
8844 MaxVersion: VersionTLS12,
8845 Bugs: ProtocolBugs{
8846 BadChangeCipherSpec: []byte{1, 1},
8847 },
8848 },
8849 shouldFail: true,
8850 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8851 })
8852}
8853
David Benjamincd2c8062016-09-09 11:28:16 -04008854type perMessageTest struct {
8855 messageType uint8
8856 test testCase
8857}
8858
8859// makePerMessageTests returns a series of test templates which cover each
8860// message in the TLS handshake. These may be used with bugs like
8861// WrongMessageType to fully test a per-message bug.
8862func makePerMessageTests() []perMessageTest {
8863 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008864 for _, protocol := range []protocol{tls, dtls} {
8865 var suffix string
8866 if protocol == dtls {
8867 suffix = "-DTLS"
8868 }
8869
David Benjamincd2c8062016-09-09 11:28:16 -04008870 ret = append(ret, perMessageTest{
8871 messageType: typeClientHello,
8872 test: testCase{
8873 protocol: protocol,
8874 testType: serverTest,
8875 name: "ClientHello" + suffix,
8876 config: Config{
8877 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008878 },
8879 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008880 })
8881
8882 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008883 ret = append(ret, perMessageTest{
8884 messageType: typeHelloVerifyRequest,
8885 test: testCase{
8886 protocol: protocol,
8887 name: "HelloVerifyRequest" + suffix,
8888 config: Config{
8889 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008890 },
8891 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008892 })
8893 }
8894
David Benjamincd2c8062016-09-09 11:28:16 -04008895 ret = append(ret, perMessageTest{
8896 messageType: typeServerHello,
8897 test: testCase{
8898 protocol: protocol,
8899 name: "ServerHello" + suffix,
8900 config: Config{
8901 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008902 },
8903 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008904 })
8905
David Benjamincd2c8062016-09-09 11:28:16 -04008906 ret = append(ret, perMessageTest{
8907 messageType: typeCertificate,
8908 test: testCase{
8909 protocol: protocol,
8910 name: "ServerCertificate" + suffix,
8911 config: Config{
8912 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008913 },
8914 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008915 })
8916
David Benjamincd2c8062016-09-09 11:28:16 -04008917 ret = append(ret, perMessageTest{
8918 messageType: typeCertificateStatus,
8919 test: testCase{
8920 protocol: protocol,
8921 name: "CertificateStatus" + suffix,
8922 config: Config{
8923 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008924 },
David Benjamincd2c8062016-09-09 11:28:16 -04008925 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008926 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008927 })
8928
David Benjamincd2c8062016-09-09 11:28:16 -04008929 ret = append(ret, perMessageTest{
8930 messageType: typeServerKeyExchange,
8931 test: testCase{
8932 protocol: protocol,
8933 name: "ServerKeyExchange" + suffix,
8934 config: Config{
8935 MaxVersion: VersionTLS12,
8936 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008937 },
8938 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008939 })
8940
David Benjamincd2c8062016-09-09 11:28:16 -04008941 ret = append(ret, perMessageTest{
8942 messageType: typeCertificateRequest,
8943 test: testCase{
8944 protocol: protocol,
8945 name: "CertificateRequest" + suffix,
8946 config: Config{
8947 MaxVersion: VersionTLS12,
8948 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008949 },
8950 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008951 })
8952
David Benjamincd2c8062016-09-09 11:28:16 -04008953 ret = append(ret, perMessageTest{
8954 messageType: typeServerHelloDone,
8955 test: testCase{
8956 protocol: protocol,
8957 name: "ServerHelloDone" + suffix,
8958 config: Config{
8959 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008960 },
8961 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008962 })
8963
David Benjamincd2c8062016-09-09 11:28:16 -04008964 ret = append(ret, perMessageTest{
8965 messageType: typeCertificate,
8966 test: testCase{
8967 testType: serverTest,
8968 protocol: protocol,
8969 name: "ClientCertificate" + suffix,
8970 config: Config{
8971 Certificates: []Certificate{rsaCertificate},
8972 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008973 },
David Benjamincd2c8062016-09-09 11:28:16 -04008974 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008975 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008976 })
8977
David Benjamincd2c8062016-09-09 11:28:16 -04008978 ret = append(ret, perMessageTest{
8979 messageType: typeCertificateVerify,
8980 test: testCase{
8981 testType: serverTest,
8982 protocol: protocol,
8983 name: "CertificateVerify" + suffix,
8984 config: Config{
8985 Certificates: []Certificate{rsaCertificate},
8986 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008987 },
David Benjamincd2c8062016-09-09 11:28:16 -04008988 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008989 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008990 })
8991
David Benjamincd2c8062016-09-09 11:28:16 -04008992 ret = append(ret, perMessageTest{
8993 messageType: typeClientKeyExchange,
8994 test: testCase{
8995 testType: serverTest,
8996 protocol: protocol,
8997 name: "ClientKeyExchange" + suffix,
8998 config: Config{
8999 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009000 },
9001 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009002 })
9003
9004 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009005 ret = append(ret, perMessageTest{
9006 messageType: typeNextProtocol,
9007 test: testCase{
9008 testType: serverTest,
9009 protocol: protocol,
9010 name: "NextProtocol" + suffix,
9011 config: Config{
9012 MaxVersion: VersionTLS12,
9013 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009014 },
David Benjamincd2c8062016-09-09 11:28:16 -04009015 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009016 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009017 })
9018
David Benjamincd2c8062016-09-09 11:28:16 -04009019 ret = append(ret, perMessageTest{
9020 messageType: typeChannelID,
9021 test: testCase{
9022 testType: serverTest,
9023 protocol: protocol,
9024 name: "ChannelID" + suffix,
9025 config: Config{
9026 MaxVersion: VersionTLS12,
9027 ChannelID: channelIDKey,
9028 },
9029 flags: []string{
9030 "-expect-channel-id",
9031 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009032 },
9033 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009034 })
9035 }
9036
David Benjamincd2c8062016-09-09 11:28:16 -04009037 ret = append(ret, perMessageTest{
9038 messageType: typeFinished,
9039 test: testCase{
9040 testType: serverTest,
9041 protocol: protocol,
9042 name: "ClientFinished" + suffix,
9043 config: Config{
9044 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009045 },
9046 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009047 })
9048
David Benjamincd2c8062016-09-09 11:28:16 -04009049 ret = append(ret, perMessageTest{
9050 messageType: typeNewSessionTicket,
9051 test: testCase{
9052 protocol: protocol,
9053 name: "NewSessionTicket" + suffix,
9054 config: Config{
9055 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009056 },
9057 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009058 })
9059
David Benjamincd2c8062016-09-09 11:28:16 -04009060 ret = append(ret, perMessageTest{
9061 messageType: typeFinished,
9062 test: testCase{
9063 protocol: protocol,
9064 name: "ServerFinished" + suffix,
9065 config: Config{
9066 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009067 },
9068 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009069 })
9070
9071 }
David Benjamincd2c8062016-09-09 11:28:16 -04009072
9073 ret = append(ret, perMessageTest{
9074 messageType: typeClientHello,
9075 test: testCase{
9076 testType: serverTest,
9077 name: "TLS13-ClientHello",
9078 config: Config{
9079 MaxVersion: VersionTLS13,
9080 },
9081 },
9082 })
9083
9084 ret = append(ret, perMessageTest{
9085 messageType: typeServerHello,
9086 test: testCase{
9087 name: "TLS13-ServerHello",
9088 config: Config{
9089 MaxVersion: VersionTLS13,
9090 },
9091 },
9092 })
9093
9094 ret = append(ret, perMessageTest{
9095 messageType: typeEncryptedExtensions,
9096 test: testCase{
9097 name: "TLS13-EncryptedExtensions",
9098 config: Config{
9099 MaxVersion: VersionTLS13,
9100 },
9101 },
9102 })
9103
9104 ret = append(ret, perMessageTest{
9105 messageType: typeCertificateRequest,
9106 test: testCase{
9107 name: "TLS13-CertificateRequest",
9108 config: Config{
9109 MaxVersion: VersionTLS13,
9110 ClientAuth: RequireAnyClientCert,
9111 },
9112 },
9113 })
9114
9115 ret = append(ret, perMessageTest{
9116 messageType: typeCertificate,
9117 test: testCase{
9118 name: "TLS13-ServerCertificate",
9119 config: Config{
9120 MaxVersion: VersionTLS13,
9121 },
9122 },
9123 })
9124
9125 ret = append(ret, perMessageTest{
9126 messageType: typeCertificateVerify,
9127 test: testCase{
9128 name: "TLS13-ServerCertificateVerify",
9129 config: Config{
9130 MaxVersion: VersionTLS13,
9131 },
9132 },
9133 })
9134
9135 ret = append(ret, perMessageTest{
9136 messageType: typeFinished,
9137 test: testCase{
9138 name: "TLS13-ServerFinished",
9139 config: Config{
9140 MaxVersion: VersionTLS13,
9141 },
9142 },
9143 })
9144
9145 ret = append(ret, perMessageTest{
9146 messageType: typeCertificate,
9147 test: testCase{
9148 testType: serverTest,
9149 name: "TLS13-ClientCertificate",
9150 config: Config{
9151 Certificates: []Certificate{rsaCertificate},
9152 MaxVersion: VersionTLS13,
9153 },
9154 flags: []string{"-require-any-client-certificate"},
9155 },
9156 })
9157
9158 ret = append(ret, perMessageTest{
9159 messageType: typeCertificateVerify,
9160 test: testCase{
9161 testType: serverTest,
9162 name: "TLS13-ClientCertificateVerify",
9163 config: Config{
9164 Certificates: []Certificate{rsaCertificate},
9165 MaxVersion: VersionTLS13,
9166 },
9167 flags: []string{"-require-any-client-certificate"},
9168 },
9169 })
9170
9171 ret = append(ret, perMessageTest{
9172 messageType: typeFinished,
9173 test: testCase{
9174 testType: serverTest,
9175 name: "TLS13-ClientFinished",
9176 config: Config{
9177 MaxVersion: VersionTLS13,
9178 },
9179 },
9180 })
9181
9182 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009183}
9184
David Benjamincd2c8062016-09-09 11:28:16 -04009185func addWrongMessageTypeTests() {
9186 for _, t := range makePerMessageTests() {
9187 t.test.name = "WrongMessageType-" + t.test.name
9188 t.test.config.Bugs.SendWrongMessageType = t.messageType
9189 t.test.shouldFail = true
9190 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9191 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009192
David Benjamincd2c8062016-09-09 11:28:16 -04009193 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9194 // In TLS 1.3, a bad ServerHello means the client sends
9195 // an unencrypted alert while the server expects
9196 // encryption, so the alert is not readable by runner.
9197 t.test.expectedLocalError = "local error: bad record MAC"
9198 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009199
David Benjamincd2c8062016-09-09 11:28:16 -04009200 testCases = append(testCases, t.test)
9201 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009202}
9203
David Benjamin639846e2016-09-09 11:41:18 -04009204func addTrailingMessageDataTests() {
9205 for _, t := range makePerMessageTests() {
9206 t.test.name = "TrailingMessageData-" + t.test.name
9207 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9208 t.test.shouldFail = true
9209 t.test.expectedError = ":DECODE_ERROR:"
9210 t.test.expectedLocalError = "remote error: error decoding message"
9211
9212 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9213 // In TLS 1.3, a bad ServerHello means the client sends
9214 // an unencrypted alert while the server expects
9215 // encryption, so the alert is not readable by runner.
9216 t.test.expectedLocalError = "local error: bad record MAC"
9217 }
9218
9219 if t.messageType == typeFinished {
9220 // Bad Finished messages read as the verify data having
9221 // the wrong length.
9222 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9223 t.test.expectedLocalError = "remote error: error decrypting message"
9224 }
9225
9226 testCases = append(testCases, t.test)
9227 }
9228}
9229
Steven Valdez143e8b32016-07-11 13:19:03 -04009230func addTLS13HandshakeTests() {
9231 testCases = append(testCases, testCase{
9232 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009233 name: "NegotiatePSKResumption-TLS13",
9234 config: Config{
9235 MaxVersion: VersionTLS13,
9236 Bugs: ProtocolBugs{
9237 NegotiatePSKResumption: true,
9238 },
9239 },
9240 resumeSession: true,
9241 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009242 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009243 })
9244
9245 testCases = append(testCases, testCase{
9246 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009247 name: "MissingKeyShare-Client",
9248 config: Config{
9249 MaxVersion: VersionTLS13,
9250 Bugs: ProtocolBugs{
9251 MissingKeyShare: true,
9252 },
9253 },
9254 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009255 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009256 })
9257
9258 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009259 testType: serverTest,
9260 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009261 config: Config{
9262 MaxVersion: VersionTLS13,
9263 Bugs: ProtocolBugs{
9264 MissingKeyShare: true,
9265 },
9266 },
9267 shouldFail: true,
9268 expectedError: ":MISSING_KEY_SHARE:",
9269 })
9270
9271 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009272 testType: serverTest,
9273 name: "DuplicateKeyShares",
9274 config: Config{
9275 MaxVersion: VersionTLS13,
9276 Bugs: ProtocolBugs{
9277 DuplicateKeyShares: true,
9278 },
9279 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009280 shouldFail: true,
9281 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009282 })
9283
9284 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009285 testType: serverTest,
9286 name: "SkipEarlyData",
9287 config: Config{
9288 MaxVersion: VersionTLS13,
9289 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009290 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009291 },
9292 },
9293 })
9294
9295 testCases = append(testCases, testCase{
9296 testType: serverTest,
9297 name: "SkipEarlyData-OmitEarlyDataExtension",
9298 config: Config{
9299 MaxVersion: VersionTLS13,
9300 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009301 SendFakeEarlyDataLength: 4,
9302 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009303 },
9304 },
9305 shouldFail: true,
9306 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9307 })
9308
9309 testCases = append(testCases, testCase{
9310 testType: serverTest,
9311 name: "SkipEarlyData-TooMuchData",
9312 config: Config{
9313 MaxVersion: VersionTLS13,
9314 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009315 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009316 },
9317 },
9318 shouldFail: true,
9319 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9320 })
9321
9322 testCases = append(testCases, testCase{
9323 testType: serverTest,
9324 name: "SkipEarlyData-Interleaved",
9325 config: Config{
9326 MaxVersion: VersionTLS13,
9327 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009328 SendFakeEarlyDataLength: 4,
9329 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009330 },
9331 },
9332 shouldFail: true,
9333 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9334 })
9335
9336 testCases = append(testCases, testCase{
9337 testType: serverTest,
9338 name: "SkipEarlyData-EarlyDataInTLS12",
9339 config: Config{
9340 MaxVersion: VersionTLS13,
9341 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009342 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009343 },
9344 },
9345 shouldFail: true,
9346 expectedError: ":UNEXPECTED_RECORD:",
9347 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9348 })
9349
9350 testCases = append(testCases, testCase{
9351 testType: serverTest,
9352 name: "SkipEarlyData-HRR",
9353 config: Config{
9354 MaxVersion: VersionTLS13,
9355 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009356 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009357 },
9358 DefaultCurves: []CurveID{},
9359 },
9360 })
9361
9362 testCases = append(testCases, testCase{
9363 testType: serverTest,
9364 name: "SkipEarlyData-HRR-Interleaved",
9365 config: Config{
9366 MaxVersion: VersionTLS13,
9367 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009368 SendFakeEarlyDataLength: 4,
9369 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009370 },
9371 DefaultCurves: []CurveID{},
9372 },
9373 shouldFail: true,
9374 expectedError: ":UNEXPECTED_RECORD:",
9375 })
9376
9377 testCases = append(testCases, testCase{
9378 testType: serverTest,
9379 name: "SkipEarlyData-HRR-TooMuchData",
9380 config: Config{
9381 MaxVersion: VersionTLS13,
9382 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009383 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009384 },
9385 DefaultCurves: []CurveID{},
9386 },
9387 shouldFail: true,
9388 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9389 })
9390
9391 // Test that skipping early data looking for cleartext correctly
9392 // processes an alert record.
9393 testCases = append(testCases, testCase{
9394 testType: serverTest,
9395 name: "SkipEarlyData-HRR-FatalAlert",
9396 config: Config{
9397 MaxVersion: VersionTLS13,
9398 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009399 SendEarlyAlert: true,
9400 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009401 },
9402 DefaultCurves: []CurveID{},
9403 },
9404 shouldFail: true,
9405 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9406 })
9407
9408 testCases = append(testCases, testCase{
9409 testType: serverTest,
9410 name: "SkipEarlyData-SecondClientHelloEarlyData",
9411 config: Config{
9412 MaxVersion: VersionTLS13,
9413 Bugs: ProtocolBugs{
9414 SendEarlyDataOnSecondClientHello: true,
9415 },
9416 DefaultCurves: []CurveID{},
9417 },
9418 shouldFail: true,
9419 expectedLocalError: "remote error: bad record MAC",
9420 })
9421
9422 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009423 testType: clientTest,
9424 name: "EmptyEncryptedExtensions",
9425 config: Config{
9426 MaxVersion: VersionTLS13,
9427 Bugs: ProtocolBugs{
9428 EmptyEncryptedExtensions: true,
9429 },
9430 },
9431 shouldFail: true,
9432 expectedLocalError: "remote error: error decoding message",
9433 })
9434
9435 testCases = append(testCases, testCase{
9436 testType: clientTest,
9437 name: "EncryptedExtensionsWithKeyShare",
9438 config: Config{
9439 MaxVersion: VersionTLS13,
9440 Bugs: ProtocolBugs{
9441 EncryptedExtensionsWithKeyShare: true,
9442 },
9443 },
9444 shouldFail: true,
9445 expectedLocalError: "remote error: unsupported extension",
9446 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009447
9448 testCases = append(testCases, testCase{
9449 testType: serverTest,
9450 name: "SendHelloRetryRequest",
9451 config: Config{
9452 MaxVersion: VersionTLS13,
9453 // Require a HelloRetryRequest for every curve.
9454 DefaultCurves: []CurveID{},
9455 },
9456 expectedCurveID: CurveX25519,
9457 })
9458
9459 testCases = append(testCases, testCase{
9460 testType: serverTest,
9461 name: "SendHelloRetryRequest-2",
9462 config: Config{
9463 MaxVersion: VersionTLS13,
9464 DefaultCurves: []CurveID{CurveP384},
9465 },
9466 // Although the ClientHello did not predict our preferred curve,
9467 // we always select it whether it is predicted or not.
9468 expectedCurveID: CurveX25519,
9469 })
9470
9471 testCases = append(testCases, testCase{
9472 name: "UnknownCurve-HelloRetryRequest",
9473 config: Config{
9474 MaxVersion: VersionTLS13,
9475 // P-384 requires HelloRetryRequest in BoringSSL.
9476 CurvePreferences: []CurveID{CurveP384},
9477 Bugs: ProtocolBugs{
9478 SendHelloRetryRequestCurve: bogusCurve,
9479 },
9480 },
9481 shouldFail: true,
9482 expectedError: ":WRONG_CURVE:",
9483 })
9484
9485 testCases = append(testCases, testCase{
9486 name: "DisabledCurve-HelloRetryRequest",
9487 config: Config{
9488 MaxVersion: VersionTLS13,
9489 CurvePreferences: []CurveID{CurveP256},
9490 Bugs: ProtocolBugs{
9491 IgnorePeerCurvePreferences: true,
9492 },
9493 },
9494 flags: []string{"-p384-only"},
9495 shouldFail: true,
9496 expectedError: ":WRONG_CURVE:",
9497 })
9498
9499 testCases = append(testCases, testCase{
9500 name: "UnnecessaryHelloRetryRequest",
9501 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009502 MaxVersion: VersionTLS13,
9503 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009504 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009505 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009506 },
9507 },
9508 shouldFail: true,
9509 expectedError: ":WRONG_CURVE:",
9510 })
9511
9512 testCases = append(testCases, testCase{
9513 name: "SecondHelloRetryRequest",
9514 config: Config{
9515 MaxVersion: VersionTLS13,
9516 // P-384 requires HelloRetryRequest in BoringSSL.
9517 CurvePreferences: []CurveID{CurveP384},
9518 Bugs: ProtocolBugs{
9519 SecondHelloRetryRequest: true,
9520 },
9521 },
9522 shouldFail: true,
9523 expectedError: ":UNEXPECTED_MESSAGE:",
9524 })
9525
9526 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009527 name: "HelloRetryRequest-Empty",
9528 config: Config{
9529 MaxVersion: VersionTLS13,
9530 Bugs: ProtocolBugs{
9531 AlwaysSendHelloRetryRequest: true,
9532 },
9533 },
9534 shouldFail: true,
9535 expectedError: ":DECODE_ERROR:",
9536 })
9537
9538 testCases = append(testCases, testCase{
9539 name: "HelloRetryRequest-DuplicateCurve",
9540 config: Config{
9541 MaxVersion: VersionTLS13,
9542 // P-384 requires a HelloRetryRequest against BoringSSL's default
9543 // configuration. Assert this ExpectMissingKeyShare.
9544 CurvePreferences: []CurveID{CurveP384},
9545 Bugs: ProtocolBugs{
9546 ExpectMissingKeyShare: true,
9547 DuplicateHelloRetryRequestExtensions: true,
9548 },
9549 },
9550 shouldFail: true,
9551 expectedError: ":DUPLICATE_EXTENSION:",
9552 expectedLocalError: "remote error: illegal parameter",
9553 })
9554
9555 testCases = append(testCases, testCase{
9556 name: "HelloRetryRequest-Cookie",
9557 config: Config{
9558 MaxVersion: VersionTLS13,
9559 Bugs: ProtocolBugs{
9560 SendHelloRetryRequestCookie: []byte("cookie"),
9561 },
9562 },
9563 })
9564
9565 testCases = append(testCases, testCase{
9566 name: "HelloRetryRequest-DuplicateCookie",
9567 config: Config{
9568 MaxVersion: VersionTLS13,
9569 Bugs: ProtocolBugs{
9570 SendHelloRetryRequestCookie: []byte("cookie"),
9571 DuplicateHelloRetryRequestExtensions: true,
9572 },
9573 },
9574 shouldFail: true,
9575 expectedError: ":DUPLICATE_EXTENSION:",
9576 expectedLocalError: "remote error: illegal parameter",
9577 })
9578
9579 testCases = append(testCases, testCase{
9580 name: "HelloRetryRequest-EmptyCookie",
9581 config: Config{
9582 MaxVersion: VersionTLS13,
9583 Bugs: ProtocolBugs{
9584 SendHelloRetryRequestCookie: []byte{},
9585 },
9586 },
9587 shouldFail: true,
9588 expectedError: ":DECODE_ERROR:",
9589 })
9590
9591 testCases = append(testCases, testCase{
9592 name: "HelloRetryRequest-Cookie-Curve",
9593 config: Config{
9594 MaxVersion: VersionTLS13,
9595 // P-384 requires HelloRetryRequest in BoringSSL.
9596 CurvePreferences: []CurveID{CurveP384},
9597 Bugs: ProtocolBugs{
9598 SendHelloRetryRequestCookie: []byte("cookie"),
9599 ExpectMissingKeyShare: true,
9600 },
9601 },
9602 })
9603
9604 testCases = append(testCases, testCase{
9605 name: "HelloRetryRequest-Unknown",
9606 config: Config{
9607 MaxVersion: VersionTLS13,
9608 Bugs: ProtocolBugs{
9609 CustomHelloRetryRequestExtension: "extension",
9610 },
9611 },
9612 shouldFail: true,
9613 expectedError: ":UNEXPECTED_EXTENSION:",
9614 expectedLocalError: "remote error: unsupported extension",
9615 })
9616
9617 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009618 testType: serverTest,
9619 name: "SecondClientHelloMissingKeyShare",
9620 config: Config{
9621 MaxVersion: VersionTLS13,
9622 DefaultCurves: []CurveID{},
9623 Bugs: ProtocolBugs{
9624 SecondClientHelloMissingKeyShare: true,
9625 },
9626 },
9627 shouldFail: true,
9628 expectedError: ":MISSING_KEY_SHARE:",
9629 })
9630
9631 testCases = append(testCases, testCase{
9632 testType: serverTest,
9633 name: "SecondClientHelloWrongCurve",
9634 config: Config{
9635 MaxVersion: VersionTLS13,
9636 DefaultCurves: []CurveID{},
9637 Bugs: ProtocolBugs{
9638 MisinterpretHelloRetryRequestCurve: CurveP521,
9639 },
9640 },
9641 shouldFail: true,
9642 expectedError: ":WRONG_CURVE:",
9643 })
9644
9645 testCases = append(testCases, testCase{
9646 name: "HelloRetryRequestVersionMismatch",
9647 config: Config{
9648 MaxVersion: VersionTLS13,
9649 // P-384 requires HelloRetryRequest in BoringSSL.
9650 CurvePreferences: []CurveID{CurveP384},
9651 Bugs: ProtocolBugs{
9652 SendServerHelloVersion: 0x0305,
9653 },
9654 },
9655 shouldFail: true,
9656 expectedError: ":WRONG_VERSION_NUMBER:",
9657 })
9658
9659 testCases = append(testCases, testCase{
9660 name: "HelloRetryRequestCurveMismatch",
9661 config: Config{
9662 MaxVersion: VersionTLS13,
9663 // P-384 requires HelloRetryRequest in BoringSSL.
9664 CurvePreferences: []CurveID{CurveP384},
9665 Bugs: ProtocolBugs{
9666 // Send P-384 (correct) in the HelloRetryRequest.
9667 SendHelloRetryRequestCurve: CurveP384,
9668 // But send P-256 in the ServerHello.
9669 SendCurve: CurveP256,
9670 },
9671 },
9672 shouldFail: true,
9673 expectedError: ":WRONG_CURVE:",
9674 })
9675
9676 // Test the server selecting a curve that requires a HelloRetryRequest
9677 // without sending it.
9678 testCases = append(testCases, testCase{
9679 name: "SkipHelloRetryRequest",
9680 config: Config{
9681 MaxVersion: VersionTLS13,
9682 // P-384 requires HelloRetryRequest in BoringSSL.
9683 CurvePreferences: []CurveID{CurveP384},
9684 Bugs: ProtocolBugs{
9685 SkipHelloRetryRequest: true,
9686 },
9687 },
9688 shouldFail: true,
9689 expectedError: ":WRONG_CURVE:",
9690 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009691
9692 testCases = append(testCases, testCase{
9693 name: "TLS13-RequestContextInHandshake",
9694 config: Config{
9695 MaxVersion: VersionTLS13,
9696 MinVersion: VersionTLS13,
9697 ClientAuth: RequireAnyClientCert,
9698 Bugs: ProtocolBugs{
9699 SendRequestContext: []byte("request context"),
9700 },
9701 },
9702 flags: []string{
9703 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9704 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9705 },
9706 shouldFail: true,
9707 expectedError: ":DECODE_ERROR:",
9708 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009709
9710 testCases = append(testCases, testCase{
9711 testType: serverTest,
9712 name: "TLS13-TrailingKeyShareData",
9713 config: Config{
9714 MaxVersion: VersionTLS13,
9715 Bugs: ProtocolBugs{
9716 TrailingKeyShareData: true,
9717 },
9718 },
9719 shouldFail: true,
9720 expectedError: ":DECODE_ERROR:",
9721 })
David Benjamin7f78df42016-10-05 22:33:19 -04009722
9723 testCases = append(testCases, testCase{
9724 name: "TLS13-AlwaysSelectPSKIdentity",
9725 config: Config{
9726 MaxVersion: VersionTLS13,
9727 Bugs: ProtocolBugs{
9728 AlwaysSelectPSKIdentity: true,
9729 },
9730 },
9731 shouldFail: true,
9732 expectedError: ":UNEXPECTED_EXTENSION:",
9733 })
9734
9735 testCases = append(testCases, testCase{
9736 name: "TLS13-InvalidPSKIdentity",
9737 config: Config{
9738 MaxVersion: VersionTLS13,
9739 Bugs: ProtocolBugs{
9740 SelectPSKIdentityOnResume: 1,
9741 },
9742 },
9743 resumeSession: true,
9744 shouldFail: true,
9745 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9746 })
David Benjamin1286bee2016-10-07 15:25:06 -04009747
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009748 testCases = append(testCases, testCase{
9749 testType: serverTest,
9750 name: "TLS13-ExtraPSKIdentity",
9751 config: Config{
9752 MaxVersion: VersionTLS13,
9753 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009754 ExtraPSKIdentity: true,
9755 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009756 },
9757 },
9758 resumeSession: true,
9759 })
9760
David Benjamin1286bee2016-10-07 15:25:06 -04009761 // Test that unknown NewSessionTicket extensions are tolerated.
9762 testCases = append(testCases, testCase{
9763 name: "TLS13-CustomTicketExtension",
9764 config: Config{
9765 MaxVersion: VersionTLS13,
9766 Bugs: ProtocolBugs{
9767 CustomTicketExtension: "1234",
9768 },
9769 },
9770 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009771}
9772
David Benjaminabbbee12016-10-31 19:20:42 -04009773func addTLS13CipherPreferenceTests() {
9774 // Test that client preference is honored if the shim has AES hardware
9775 // and ChaCha20-Poly1305 is preferred otherwise.
9776 testCases = append(testCases, testCase{
9777 testType: serverTest,
9778 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9779 config: Config{
9780 MaxVersion: VersionTLS13,
9781 CipherSuites: []uint16{
9782 TLS_CHACHA20_POLY1305_SHA256,
9783 TLS_AES_128_GCM_SHA256,
9784 },
9785 },
9786 flags: []string{
9787 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9788 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9789 },
9790 })
9791
9792 testCases = append(testCases, testCase{
9793 testType: serverTest,
9794 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9795 config: Config{
9796 MaxVersion: VersionTLS13,
9797 CipherSuites: []uint16{
9798 TLS_AES_128_GCM_SHA256,
9799 TLS_CHACHA20_POLY1305_SHA256,
9800 },
9801 },
9802 flags: []string{
9803 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9804 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9805 },
9806 })
9807
9808 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9809 // whether it has AES hardware.
9810 testCases = append(testCases, testCase{
9811 name: "TLS13-CipherPreference-Client",
9812 config: Config{
9813 MaxVersion: VersionTLS13,
9814 // Use the client cipher order. (This is the default but
9815 // is listed to be explicit.)
9816 PreferServerCipherSuites: false,
9817 },
9818 flags: []string{
9819 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9820 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9821 },
9822 })
9823}
9824
David Benjaminf3fbade2016-09-19 13:08:16 -04009825func addPeekTests() {
9826 // Test SSL_peek works, including on empty records.
9827 testCases = append(testCases, testCase{
9828 name: "Peek-Basic",
9829 sendEmptyRecords: 1,
9830 flags: []string{"-peek-then-read"},
9831 })
9832
9833 // Test SSL_peek can drive the initial handshake.
9834 testCases = append(testCases, testCase{
9835 name: "Peek-ImplicitHandshake",
9836 flags: []string{
9837 "-peek-then-read",
9838 "-implicit-handshake",
9839 },
9840 })
9841
9842 // Test SSL_peek can discover and drive a renegotiation.
9843 testCases = append(testCases, testCase{
9844 name: "Peek-Renegotiate",
9845 config: Config{
9846 MaxVersion: VersionTLS12,
9847 },
9848 renegotiate: 1,
9849 flags: []string{
9850 "-peek-then-read",
9851 "-renegotiate-freely",
9852 "-expect-total-renegotiations", "1",
9853 },
9854 })
9855
9856 // Test SSL_peek can discover a close_notify.
9857 testCases = append(testCases, testCase{
9858 name: "Peek-Shutdown",
9859 config: Config{
9860 Bugs: ProtocolBugs{
9861 ExpectCloseNotify: true,
9862 },
9863 },
9864 flags: []string{
9865 "-peek-then-read",
9866 "-check-close-notify",
9867 },
9868 })
9869
9870 // Test SSL_peek can discover an alert.
9871 testCases = append(testCases, testCase{
9872 name: "Peek-Alert",
9873 config: Config{
9874 Bugs: ProtocolBugs{
9875 SendSpuriousAlert: alertRecordOverflow,
9876 },
9877 },
9878 flags: []string{"-peek-then-read"},
9879 shouldFail: true,
9880 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9881 })
9882
9883 // Test SSL_peek can handle KeyUpdate.
9884 testCases = append(testCases, testCase{
9885 name: "Peek-KeyUpdate",
9886 config: Config{
9887 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009888 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009889 sendKeyUpdates: 1,
9890 keyUpdateRequest: keyUpdateNotRequested,
9891 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009892 })
9893}
9894
David Benjamine6f22212016-11-08 14:28:24 -05009895func addRecordVersionTests() {
9896 for _, ver := range tlsVersions {
9897 // Test that the record version is enforced.
9898 testCases = append(testCases, testCase{
9899 name: "CheckRecordVersion-" + ver.name,
9900 config: Config{
9901 MinVersion: ver.version,
9902 MaxVersion: ver.version,
9903 Bugs: ProtocolBugs{
9904 SendRecordVersion: 0x03ff,
9905 },
9906 },
9907 shouldFail: true,
9908 expectedError: ":WRONG_VERSION_NUMBER:",
9909 })
9910
9911 // Test that the ClientHello may use any record version, for
9912 // compatibility reasons.
9913 testCases = append(testCases, testCase{
9914 testType: serverTest,
9915 name: "LooseInitialRecordVersion-" + ver.name,
9916 config: Config{
9917 MinVersion: ver.version,
9918 MaxVersion: ver.version,
9919 Bugs: ProtocolBugs{
9920 SendInitialRecordVersion: 0x03ff,
9921 },
9922 },
9923 })
9924
9925 // Test that garbage ClientHello record versions are rejected.
9926 testCases = append(testCases, testCase{
9927 testType: serverTest,
9928 name: "GarbageInitialRecordVersion-" + ver.name,
9929 config: Config{
9930 MinVersion: ver.version,
9931 MaxVersion: ver.version,
9932 Bugs: ProtocolBugs{
9933 SendInitialRecordVersion: 0xffff,
9934 },
9935 },
9936 shouldFail: true,
9937 expectedError: ":WRONG_VERSION_NUMBER:",
9938 })
9939 }
9940}
9941
David Benjamin2c516452016-11-15 10:16:54 +09009942func addCertificateTests() {
9943 // Test that a certificate chain with intermediate may be sent and
9944 // received as both client and server.
9945 for _, ver := range tlsVersions {
9946 testCases = append(testCases, testCase{
9947 testType: clientTest,
9948 name: "SendReceiveIntermediate-Client-" + ver.name,
9949 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009950 MinVersion: ver.version,
9951 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009952 Certificates: []Certificate{rsaChainCertificate},
9953 ClientAuth: RequireAnyClientCert,
9954 },
9955 expectPeerCertificate: &rsaChainCertificate,
9956 flags: []string{
9957 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9958 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9959 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9960 },
9961 })
9962
9963 testCases = append(testCases, testCase{
9964 testType: serverTest,
9965 name: "SendReceiveIntermediate-Server-" + ver.name,
9966 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009967 MinVersion: ver.version,
9968 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009969 Certificates: []Certificate{rsaChainCertificate},
9970 },
9971 expectPeerCertificate: &rsaChainCertificate,
9972 flags: []string{
9973 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9974 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9975 "-require-any-client-certificate",
9976 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9977 },
9978 })
9979 }
9980}
9981
David Benjaminbbaf3672016-11-17 10:53:09 +09009982func addRetainOnlySHA256ClientCertTests() {
9983 for _, ver := range tlsVersions {
9984 // Test that enabling
9985 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9986 // actually requesting a client certificate is a no-op.
9987 testCases = append(testCases, testCase{
9988 testType: serverTest,
9989 name: "RetainOnlySHA256-NoCert-" + ver.name,
9990 config: Config{
9991 MinVersion: ver.version,
9992 MaxVersion: ver.version,
9993 },
9994 flags: []string{
9995 "-retain-only-sha256-client-cert-initial",
9996 "-retain-only-sha256-client-cert-resume",
9997 },
9998 resumeSession: true,
9999 })
10000
10001 // Test that when retaining only a SHA-256 certificate is
10002 // enabled, the hash appears as expected.
10003 testCases = append(testCases, testCase{
10004 testType: serverTest,
10005 name: "RetainOnlySHA256-Cert-" + ver.name,
10006 config: Config{
10007 MinVersion: ver.version,
10008 MaxVersion: ver.version,
10009 Certificates: []Certificate{rsaCertificate},
10010 },
10011 flags: []string{
10012 "-verify-peer",
10013 "-retain-only-sha256-client-cert-initial",
10014 "-retain-only-sha256-client-cert-resume",
10015 "-expect-sha256-client-cert-initial",
10016 "-expect-sha256-client-cert-resume",
10017 },
10018 resumeSession: true,
10019 })
10020
10021 // Test that when the config changes from on to off, a
10022 // resumption is rejected because the server now wants the full
10023 // certificate chain.
10024 testCases = append(testCases, testCase{
10025 testType: serverTest,
10026 name: "RetainOnlySHA256-OnOff-" + ver.name,
10027 config: Config{
10028 MinVersion: ver.version,
10029 MaxVersion: ver.version,
10030 Certificates: []Certificate{rsaCertificate},
10031 },
10032 flags: []string{
10033 "-verify-peer",
10034 "-retain-only-sha256-client-cert-initial",
10035 "-expect-sha256-client-cert-initial",
10036 },
10037 resumeSession: true,
10038 expectResumeRejected: true,
10039 })
10040
10041 // Test that when the config changes from off to on, a
10042 // resumption is rejected because the server now wants just the
10043 // hash.
10044 testCases = append(testCases, testCase{
10045 testType: serverTest,
10046 name: "RetainOnlySHA256-OffOn-" + ver.name,
10047 config: Config{
10048 MinVersion: ver.version,
10049 MaxVersion: ver.version,
10050 Certificates: []Certificate{rsaCertificate},
10051 },
10052 flags: []string{
10053 "-verify-peer",
10054 "-retain-only-sha256-client-cert-resume",
10055 "-expect-sha256-client-cert-resume",
10056 },
10057 resumeSession: true,
10058 expectResumeRejected: true,
10059 })
10060 }
10061}
10062
Adam Langleya4b91982016-12-12 12:05:53 -080010063func addECDSAKeyUsageTests() {
10064 p256 := elliptic.P256()
10065 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10066 if err != nil {
10067 panic(err)
10068 }
10069
10070 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10071 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10072 if err != nil {
10073 panic(err)
10074 }
10075
10076 template := x509.Certificate{
10077 SerialNumber: serialNumber,
10078 Subject: pkix.Name{
10079 Organization: []string{"Acme Co"},
10080 },
10081 NotBefore: time.Now(),
10082 NotAfter: time.Now(),
10083
10084 // An ECC certificate with only the keyAgreement key usgae may
10085 // be used with ECDH, but not ECDSA.
10086 KeyUsage: x509.KeyUsageKeyAgreement,
10087 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10088 BasicConstraintsValid: true,
10089 }
10090
10091 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10092 if err != nil {
10093 panic(err)
10094 }
10095
10096 cert := Certificate{
10097 Certificate: [][]byte{derBytes},
10098 PrivateKey: priv,
10099 }
10100
10101 for _, ver := range tlsVersions {
10102 if ver.version < VersionTLS12 {
10103 continue
10104 }
10105
10106 testCases = append(testCases, testCase{
10107 testType: clientTest,
10108 name: "ECDSAKeyUsage-" + ver.name,
10109 config: Config{
10110 MinVersion: ver.version,
10111 MaxVersion: ver.version,
10112 Certificates: []Certificate{cert},
10113 },
10114 shouldFail: true,
10115 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10116 })
10117 }
10118}
10119
David Benjamin6f600d62016-12-21 16:06:54 -050010120func addShortHeaderTests() {
10121 // The short header extension may be negotiated as either client or
10122 // server.
10123 testCases = append(testCases, testCase{
10124 name: "ShortHeader-Client",
10125 config: Config{
10126 MaxVersion: VersionTLS13,
10127 Bugs: ProtocolBugs{
10128 EnableShortHeader: true,
10129 },
10130 },
10131 flags: []string{"-enable-short-header"},
10132 expectShortHeader: true,
10133 })
10134 testCases = append(testCases, testCase{
10135 testType: serverTest,
10136 name: "ShortHeader-Server",
10137 config: Config{
10138 MaxVersion: VersionTLS13,
10139 Bugs: ProtocolBugs{
10140 EnableShortHeader: true,
10141 },
10142 },
10143 flags: []string{"-enable-short-header"},
10144 expectShortHeader: true,
10145 })
10146
10147 // If the peer doesn't support it, it will not be negotiated.
10148 testCases = append(testCases, testCase{
10149 name: "ShortHeader-No-Yes-Client",
10150 config: Config{
10151 MaxVersion: VersionTLS13,
10152 },
10153 flags: []string{"-enable-short-header"},
10154 })
10155 testCases = append(testCases, testCase{
10156 testType: serverTest,
10157 name: "ShortHeader-No-Yes-Server",
10158 config: Config{
10159 MaxVersion: VersionTLS13,
10160 },
10161 flags: []string{"-enable-short-header"},
10162 })
10163
10164 // If we don't support it, it will not be negotiated.
10165 testCases = append(testCases, testCase{
10166 name: "ShortHeader-Yes-No-Client",
10167 config: Config{
10168 MaxVersion: VersionTLS13,
10169 Bugs: ProtocolBugs{
10170 EnableShortHeader: true,
10171 },
10172 },
10173 })
10174 testCases = append(testCases, testCase{
10175 testType: serverTest,
10176 name: "ShortHeader-Yes-No-Server",
10177 config: Config{
10178 MaxVersion: VersionTLS13,
10179 Bugs: ProtocolBugs{
10180 EnableShortHeader: true,
10181 },
10182 },
10183 })
10184
10185 // It will not be negotiated at TLS 1.2.
10186 testCases = append(testCases, testCase{
10187 name: "ShortHeader-TLS12-Client",
10188 config: Config{
10189 MaxVersion: VersionTLS12,
10190 Bugs: ProtocolBugs{
10191 EnableShortHeader: true,
10192 },
10193 },
10194 flags: []string{"-enable-short-header"},
10195 })
10196 testCases = append(testCases, testCase{
10197 testType: serverTest,
10198 name: "ShortHeader-TLS12-Server",
10199 config: Config{
10200 MaxVersion: VersionTLS12,
10201 Bugs: ProtocolBugs{
10202 EnableShortHeader: true,
10203 },
10204 },
10205 flags: []string{"-enable-short-header"},
10206 })
10207
10208 // Servers reject early data and short header sent together.
10209 testCases = append(testCases, testCase{
10210 testType: serverTest,
10211 name: "ShortHeader-EarlyData",
10212 config: Config{
10213 MaxVersion: VersionTLS13,
10214 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010215 EnableShortHeader: true,
10216 SendFakeEarlyDataLength: 1,
David Benjamin6f600d62016-12-21 16:06:54 -050010217 },
10218 },
10219 flags: []string{"-enable-short-header"},
10220 shouldFail: true,
10221 expectedError: ":UNEXPECTED_EXTENSION:",
10222 })
10223
10224 // Clients reject unsolicited short header extensions.
10225 testCases = append(testCases, testCase{
10226 name: "ShortHeader-Unsolicited",
10227 config: Config{
10228 MaxVersion: VersionTLS13,
10229 Bugs: ProtocolBugs{
10230 AlwaysNegotiateShortHeader: true,
10231 },
10232 },
10233 shouldFail: true,
10234 expectedError: ":UNEXPECTED_EXTENSION:",
10235 })
10236 testCases = append(testCases, testCase{
10237 name: "ShortHeader-Unsolicited-TLS12",
10238 config: Config{
10239 MaxVersion: VersionTLS12,
10240 Bugs: ProtocolBugs{
10241 AlwaysNegotiateShortHeader: true,
10242 },
10243 },
10244 shouldFail: true,
10245 expectedError: ":UNEXPECTED_EXTENSION:",
10246 })
10247
10248 // The high bit must be checked in short headers.
10249 testCases = append(testCases, testCase{
10250 name: "ShortHeader-ClearShortHeaderBit",
10251 config: Config{
10252 Bugs: ProtocolBugs{
10253 EnableShortHeader: true,
10254 ClearShortHeaderBit: true,
10255 },
10256 },
10257 flags: []string{"-enable-short-header"},
10258 shouldFail: true,
10259 expectedError: ":DECODE_ERROR:",
10260 expectedLocalError: "remote error: error decoding message",
10261 })
10262}
10263
Adam Langley7c803a62015-06-15 15:35:05 -070010264func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010265 defer wg.Done()
10266
10267 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010268 var err error
10269
David Benjaminba28dfc2016-11-15 17:47:21 +090010270 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010271 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10272 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010273 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010274 if err != nil {
10275 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10276 }
10277 break
10278 }
10279 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010280 } else if *repeatUntilFailure {
10281 for err == nil {
10282 statusChan <- statusMsg{test: test, started: true}
10283 err = runTest(test, shimPath, -1)
10284 }
10285 } else {
10286 statusChan <- statusMsg{test: test, started: true}
10287 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010288 }
Adam Langley95c29f32014-06-20 12:00:00 -070010289 statusChan <- statusMsg{test: test, err: err}
10290 }
10291}
10292
10293type statusMsg struct {
10294 test *testCase
10295 started bool
10296 err error
10297}
10298
David Benjamin5f237bc2015-02-11 17:14:15 -050010299func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010300 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010301
David Benjamin5f237bc2015-02-11 17:14:15 -050010302 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010303 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010304 if !*pipe {
10305 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010306 var erase string
10307 for i := 0; i < lineLen; i++ {
10308 erase += "\b \b"
10309 }
10310 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010311 }
10312
Adam Langley95c29f32014-06-20 12:00:00 -070010313 if msg.started {
10314 started++
10315 } else {
10316 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010317
10318 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010319 if msg.err == errUnimplemented {
10320 if *pipe {
10321 // Print each test instead of a status line.
10322 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10323 }
10324 unimplemented++
10325 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10326 } else {
10327 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10328 failed++
10329 testOutput.addResult(msg.test.name, "FAIL")
10330 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010331 } else {
10332 if *pipe {
10333 // Print each test instead of a status line.
10334 fmt.Printf("PASSED (%s)\n", msg.test.name)
10335 }
10336 testOutput.addResult(msg.test.name, "PASS")
10337 }
Adam Langley95c29f32014-06-20 12:00:00 -070010338 }
10339
David Benjamin5f237bc2015-02-11 17:14:15 -050010340 if !*pipe {
10341 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010342 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010343 lineLen = len(line)
10344 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010345 }
Adam Langley95c29f32014-06-20 12:00:00 -070010346 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010347
10348 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010349}
10350
10351func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010352 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010353 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010354 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010355
Adam Langley7c803a62015-06-15 15:35:05 -070010356 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010357 addCipherSuiteTests()
10358 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010359 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010360 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010361 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010362 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010363 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010364 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010365 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010366 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010367 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010368 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010369 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010370 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010371 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010372 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010373 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010374 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010375 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010376 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010377 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010378 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010379 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010380 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010381 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010382 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010383 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010384 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010385 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010386 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010387 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010388 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010389 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010390 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010391
10392 var wg sync.WaitGroup
10393
Adam Langley7c803a62015-06-15 15:35:05 -070010394 statusChan := make(chan statusMsg, *numWorkers)
10395 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010396 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010397
EKRf71d7ed2016-08-06 13:25:12 -070010398 if len(*shimConfigFile) != 0 {
10399 encoded, err := ioutil.ReadFile(*shimConfigFile)
10400 if err != nil {
10401 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10402 os.Exit(1)
10403 }
10404
10405 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10406 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10407 os.Exit(1)
10408 }
10409 }
10410
David Benjamin025b3d32014-07-01 19:53:04 -040010411 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010412
Adam Langley7c803a62015-06-15 15:35:05 -070010413 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010414 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010415 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010416 }
10417
David Benjamin270f0a72016-03-17 14:41:36 -040010418 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010419 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010420 matched := true
10421 if len(*testToRun) != 0 {
10422 var err error
10423 matched, err = filepath.Match(*testToRun, testCases[i].name)
10424 if err != nil {
10425 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10426 os.Exit(1)
10427 }
10428 }
10429
EKRf71d7ed2016-08-06 13:25:12 -070010430 if !*includeDisabled {
10431 for pattern := range shimConfig.DisabledTests {
10432 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10433 if err != nil {
10434 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10435 os.Exit(1)
10436 }
10437
10438 if isDisabled {
10439 matched = false
10440 break
10441 }
10442 }
10443 }
10444
David Benjamin17e12922016-07-28 18:04:43 -040010445 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010446 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010447 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010448
10449 // Only run one test if repeating until failure.
10450 if *repeatUntilFailure {
10451 break
10452 }
Adam Langley95c29f32014-06-20 12:00:00 -070010453 }
10454 }
David Benjamin17e12922016-07-28 18:04:43 -040010455
David Benjamin270f0a72016-03-17 14:41:36 -040010456 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010457 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010458 os.Exit(1)
10459 }
Adam Langley95c29f32014-06-20 12:00:00 -070010460
10461 close(testChan)
10462 wg.Wait()
10463 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010464 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010465
10466 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010467
10468 if *jsonOutput != "" {
10469 if err := testOutput.writeTo(*jsonOutput); err != nil {
10470 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10471 }
10472 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010473
EKR842ae6c2016-07-27 09:22:05 +020010474 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10475 os.Exit(1)
10476 }
10477
10478 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010479 os.Exit(1)
10480 }
Adam Langley95c29f32014-06-20 12:00:00 -070010481}