blob: 76fd13a6656e89be60be69b30e34383b004e77b7 [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 }
2517 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2518 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2519 // for now.
2520 flags = append(flags, "-cipher", suite.name)
2521 }
2522
2523 var shouldServerFail, shouldClientFail bool
2524 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2525 // BoringSSL clients accept ECDHE on SSLv3, but
2526 // a BoringSSL server will never select it
2527 // because the extension is missing.
2528 shouldServerFail = true
2529 }
2530 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2531 shouldClientFail = true
2532 shouldServerFail = true
2533 }
2534 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2535 shouldClientFail = true
2536 shouldServerFail = true
2537 }
2538 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2539 shouldClientFail = true
2540 shouldServerFail = true
2541 }
2542 if !isDTLSCipher(suite.name) && protocol == dtls {
2543 shouldClientFail = true
2544 shouldServerFail = true
2545 }
2546
2547 var sendCipherSuite uint16
2548 var expectedServerError, expectedClientError string
2549 serverCipherSuites := []uint16{suite.id}
2550 if shouldServerFail {
2551 expectedServerError = ":NO_SHARED_CIPHER:"
2552 }
2553 if shouldClientFail {
2554 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2555 // Configure the server to select ciphers as normal but
2556 // select an incompatible cipher in ServerHello.
2557 serverCipherSuites = nil
2558 sendCipherSuite = suite.id
2559 }
2560
2561 testCases = append(testCases, testCase{
2562 testType: serverTest,
2563 protocol: protocol,
2564 name: prefix + ver.name + "-" + suite.name + "-server",
2565 config: Config{
2566 MinVersion: ver.version,
2567 MaxVersion: ver.version,
2568 CipherSuites: []uint16{suite.id},
2569 Certificates: []Certificate{cert},
2570 PreSharedKey: []byte(psk),
2571 PreSharedKeyIdentity: pskIdentity,
2572 Bugs: ProtocolBugs{
2573 AdvertiseAllConfiguredCiphers: true,
2574 },
2575 },
2576 certFile: certFile,
2577 keyFile: keyFile,
2578 flags: flags,
2579 resumeSession: true,
2580 shouldFail: shouldServerFail,
2581 expectedError: expectedServerError,
2582 })
2583
2584 testCases = append(testCases, testCase{
2585 testType: clientTest,
2586 protocol: protocol,
2587 name: prefix + ver.name + "-" + suite.name + "-client",
2588 config: Config{
2589 MinVersion: ver.version,
2590 MaxVersion: ver.version,
2591 CipherSuites: serverCipherSuites,
2592 Certificates: []Certificate{cert},
2593 PreSharedKey: []byte(psk),
2594 PreSharedKeyIdentity: pskIdentity,
2595 Bugs: ProtocolBugs{
2596 IgnorePeerCipherPreferences: shouldClientFail,
2597 SendCipherSuite: sendCipherSuite,
2598 },
2599 },
2600 flags: flags,
2601 resumeSession: true,
2602 shouldFail: shouldClientFail,
2603 expectedError: expectedClientError,
2604 })
2605
David Benjamin6f600d62016-12-21 16:06:54 -05002606 if shouldClientFail {
2607 return
2608 }
2609
2610 // Ensure the maximum record size is accepted.
2611 testCases = append(testCases, testCase{
2612 protocol: protocol,
2613 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2614 config: Config{
2615 MinVersion: ver.version,
2616 MaxVersion: ver.version,
2617 CipherSuites: []uint16{suite.id},
2618 Certificates: []Certificate{cert},
2619 PreSharedKey: []byte(psk),
2620 PreSharedKeyIdentity: pskIdentity,
2621 },
2622 flags: flags,
2623 messageLen: maxPlaintext,
2624 })
2625
2626 // Test bad records for all ciphers. Bad records are fatal in TLS
2627 // and ignored in DTLS.
2628 var shouldFail bool
2629 var expectedError string
2630 if protocol == tls {
2631 shouldFail = true
2632 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2633 }
2634
2635 testCases = append(testCases, testCase{
2636 protocol: protocol,
2637 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2638 config: Config{
2639 MinVersion: ver.version,
2640 MaxVersion: ver.version,
2641 CipherSuites: []uint16{suite.id},
2642 Certificates: []Certificate{cert},
2643 PreSharedKey: []byte(psk),
2644 PreSharedKeyIdentity: pskIdentity,
2645 },
2646 flags: flags,
2647 damageFirstWrite: true,
2648 messageLen: maxPlaintext,
2649 shouldFail: shouldFail,
2650 expectedError: expectedError,
2651 })
2652
2653 if ver.version >= VersionTLS13 {
David Benjaminaa012042016-12-10 13:33:05 -05002654 testCases = append(testCases, testCase{
2655 protocol: protocol,
David Benjamin6f600d62016-12-21 16:06:54 -05002656 name: prefix + ver.name + "-" + suite.name + "-ShortHeader",
David Benjaminaa012042016-12-10 13:33:05 -05002657 config: Config{
2658 MinVersion: ver.version,
2659 MaxVersion: ver.version,
2660 CipherSuites: []uint16{suite.id},
2661 Certificates: []Certificate{cert},
2662 PreSharedKey: []byte(psk),
2663 PreSharedKeyIdentity: pskIdentity,
David Benjamin6f600d62016-12-21 16:06:54 -05002664 Bugs: ProtocolBugs{
2665 EnableShortHeader: true,
2666 },
David Benjaminaa012042016-12-10 13:33:05 -05002667 },
David Benjamin6f600d62016-12-21 16:06:54 -05002668 flags: append([]string{"-enable-short-header"}, flags...),
2669 resumeSession: true,
2670 expectShortHeader: true,
David Benjaminaa012042016-12-10 13:33:05 -05002671 })
2672 }
2673}
2674
Adam Langley95c29f32014-06-20 12:00:00 -07002675func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002676 const bogusCipher = 0xfe00
2677
Adam Langley95c29f32014-06-20 12:00:00 -07002678 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002679 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002680 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002681 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002682 }
David Benjamin2c99d282015-09-01 10:23:00 -04002683 }
Adam Langley95c29f32014-06-20 12:00:00 -07002684 }
Adam Langleya7997f12015-05-14 17:38:50 -07002685
2686 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002687 name: "NoSharedCipher",
2688 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002689 MaxVersion: VersionTLS12,
2690 CipherSuites: []uint16{},
2691 },
2692 shouldFail: true,
2693 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2694 })
2695
2696 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002697 name: "NoSharedCipher-TLS13",
2698 config: Config{
2699 MaxVersion: VersionTLS13,
2700 CipherSuites: []uint16{},
2701 },
2702 shouldFail: true,
2703 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2704 })
2705
2706 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002707 name: "UnsupportedCipherSuite",
2708 config: Config{
2709 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002710 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002711 Bugs: ProtocolBugs{
2712 IgnorePeerCipherPreferences: true,
2713 },
2714 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002715 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002716 shouldFail: true,
2717 expectedError: ":WRONG_CIPHER_RETURNED:",
2718 })
2719
2720 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002721 name: "ServerHelloBogusCipher",
2722 config: Config{
2723 MaxVersion: VersionTLS12,
2724 Bugs: ProtocolBugs{
2725 SendCipherSuite: bogusCipher,
2726 },
2727 },
2728 shouldFail: true,
2729 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2730 })
2731 testCases = append(testCases, testCase{
2732 name: "ServerHelloBogusCipher-TLS13",
2733 config: Config{
2734 MaxVersion: VersionTLS13,
2735 Bugs: ProtocolBugs{
2736 SendCipherSuite: bogusCipher,
2737 },
2738 },
2739 shouldFail: true,
2740 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2741 })
2742
2743 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002744 name: "WeakDH",
2745 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002746 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002747 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2748 Bugs: ProtocolBugs{
2749 // This is a 1023-bit prime number, generated
2750 // with:
2751 // openssl gendh 1023 | openssl asn1parse -i
2752 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2753 },
2754 },
2755 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002756 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002757 })
Adam Langleycef75832015-09-03 14:51:12 -07002758
David Benjamincd24a392015-11-11 13:23:05 -08002759 testCases = append(testCases, testCase{
2760 name: "SillyDH",
2761 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002762 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002763 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2764 Bugs: ProtocolBugs{
2765 // This is a 4097-bit prime number, generated
2766 // with:
2767 // openssl gendh 4097 | openssl asn1parse -i
2768 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2769 },
2770 },
2771 shouldFail: true,
2772 expectedError: ":DH_P_TOO_LONG:",
2773 })
2774
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002775 // This test ensures that Diffie-Hellman public values are padded with
2776 // zeros so that they're the same length as the prime. This is to avoid
2777 // hitting a bug in yaSSL.
2778 testCases = append(testCases, testCase{
2779 testType: serverTest,
2780 name: "DHPublicValuePadded",
2781 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002782 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002783 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2784 Bugs: ProtocolBugs{
2785 RequireDHPublicValueLen: (1025 + 7) / 8,
2786 },
2787 },
2788 flags: []string{"-use-sparse-dh-prime"},
2789 })
David Benjamincd24a392015-11-11 13:23:05 -08002790
David Benjamin241ae832016-01-15 03:04:54 -05002791 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002792 testCases = append(testCases, testCase{
2793 testType: serverTest,
2794 name: "UnknownCipher",
2795 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002796 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002797 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002798 Bugs: ProtocolBugs{
2799 AdvertiseAllConfiguredCiphers: true,
2800 },
2801 },
2802 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002803
2804 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002805 testCases = append(testCases, testCase{
2806 testType: serverTest,
2807 name: "UnknownCipher-TLS13",
2808 config: Config{
2809 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002810 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002811 Bugs: ProtocolBugs{
2812 AdvertiseAllConfiguredCiphers: true,
2813 },
David Benjamin241ae832016-01-15 03:04:54 -05002814 },
2815 })
2816
David Benjamin78679342016-09-16 19:42:05 -04002817 // Test empty ECDHE_PSK identity hints work as expected.
2818 testCases = append(testCases, testCase{
2819 name: "EmptyECDHEPSKHint",
2820 config: Config{
2821 MaxVersion: VersionTLS12,
2822 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2823 PreSharedKey: []byte("secret"),
2824 },
2825 flags: []string{"-psk", "secret"},
2826 })
2827
2828 // Test empty PSK identity hints work as expected, even if an explicit
2829 // ServerKeyExchange is sent.
2830 testCases = append(testCases, testCase{
2831 name: "ExplicitEmptyPSKHint",
2832 config: Config{
2833 MaxVersion: VersionTLS12,
2834 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2835 PreSharedKey: []byte("secret"),
2836 Bugs: ProtocolBugs{
2837 AlwaysSendPreSharedKeyIdentityHint: true,
2838 },
2839 },
2840 flags: []string{"-psk", "secret"},
2841 })
Adam Langley95c29f32014-06-20 12:00:00 -07002842}
2843
2844func addBadECDSASignatureTests() {
2845 for badR := BadValue(1); badR < NumBadValues; badR++ {
2846 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002847 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002848 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2849 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002850 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002851 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002852 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002853 Bugs: ProtocolBugs{
2854 BadECDSAR: badR,
2855 BadECDSAS: badS,
2856 },
2857 },
2858 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002859 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002860 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002861 testCases = append(testCases, testCase{
2862 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2863 config: Config{
2864 MaxVersion: VersionTLS13,
2865 Certificates: []Certificate{ecdsaP256Certificate},
2866 Bugs: ProtocolBugs{
2867 BadECDSAR: badR,
2868 BadECDSAS: badS,
2869 },
2870 },
2871 shouldFail: true,
2872 expectedError: ":BAD_SIGNATURE:",
2873 })
Adam Langley95c29f32014-06-20 12:00:00 -07002874 }
2875 }
2876}
2877
Adam Langley80842bd2014-06-20 12:00:00 -07002878func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002879 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002880 name: "MaxCBCPadding",
2881 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002882 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002883 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2884 Bugs: ProtocolBugs{
2885 MaxPadding: true,
2886 },
2887 },
2888 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2889 })
David Benjamin025b3d32014-07-01 19:53:04 -04002890 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002891 name: "BadCBCPadding",
2892 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002893 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2895 Bugs: ProtocolBugs{
2896 PaddingFirstByteBad: true,
2897 },
2898 },
2899 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002900 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002901 })
2902 // OpenSSL previously had an issue where the first byte of padding in
2903 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002904 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002905 name: "BadCBCPadding255",
2906 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002907 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002908 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2909 Bugs: ProtocolBugs{
2910 MaxPadding: true,
2911 PaddingFirstByteBadIf255: true,
2912 },
2913 },
2914 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2915 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002916 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002917 })
2918}
2919
Kenny Root7fdeaf12014-08-05 15:23:37 -07002920func addCBCSplittingTests() {
2921 testCases = append(testCases, testCase{
2922 name: "CBCRecordSplitting",
2923 config: Config{
2924 MaxVersion: VersionTLS10,
2925 MinVersion: VersionTLS10,
2926 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2927 },
David Benjaminac8302a2015-09-01 17:18:15 -04002928 messageLen: -1, // read until EOF
2929 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002930 flags: []string{
2931 "-async",
2932 "-write-different-record-sizes",
2933 "-cbc-record-splitting",
2934 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002935 })
2936 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002937 name: "CBCRecordSplittingPartialWrite",
2938 config: Config{
2939 MaxVersion: VersionTLS10,
2940 MinVersion: VersionTLS10,
2941 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2942 },
2943 messageLen: -1, // read until EOF
2944 flags: []string{
2945 "-async",
2946 "-write-different-record-sizes",
2947 "-cbc-record-splitting",
2948 "-partial-write",
2949 },
2950 })
2951}
2952
David Benjamin636293b2014-07-08 17:59:18 -04002953func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002954 // Add a dummy cert pool to stress certificate authority parsing.
2955 // TODO(davidben): Add tests that those values parse out correctly.
2956 certPool := x509.NewCertPool()
2957 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2958 if err != nil {
2959 panic(err)
2960 }
2961 certPool.AddCert(cert)
2962
David Benjamin636293b2014-07-08 17:59:18 -04002963 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002964 testCases = append(testCases, testCase{
2965 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002966 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002967 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002968 MinVersion: ver.version,
2969 MaxVersion: ver.version,
2970 ClientAuth: RequireAnyClientCert,
2971 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002972 },
2973 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002974 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2975 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002976 },
2977 })
2978 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002979 testType: serverTest,
2980 name: ver.name + "-Server-ClientAuth-RSA",
2981 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002982 MinVersion: ver.version,
2983 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002984 Certificates: []Certificate{rsaCertificate},
2985 },
2986 flags: []string{"-require-any-client-certificate"},
2987 })
David Benjamine098ec22014-08-27 23:13:20 -04002988 if ver.version != VersionSSL30 {
2989 testCases = append(testCases, testCase{
2990 testType: serverTest,
2991 name: ver.name + "-Server-ClientAuth-ECDSA",
2992 config: Config{
2993 MinVersion: ver.version,
2994 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002995 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002996 },
2997 flags: []string{"-require-any-client-certificate"},
2998 })
2999 testCases = append(testCases, testCase{
3000 testType: clientTest,
3001 name: ver.name + "-Client-ClientAuth-ECDSA",
3002 config: Config{
3003 MinVersion: ver.version,
3004 MaxVersion: ver.version,
3005 ClientAuth: RequireAnyClientCert,
3006 ClientCAs: certPool,
3007 },
3008 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003009 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3010 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003011 },
3012 })
3013 }
Adam Langley37646832016-08-01 16:16:46 -07003014
3015 testCases = append(testCases, testCase{
3016 name: "NoClientCertificate-" + ver.name,
3017 config: Config{
3018 MinVersion: ver.version,
3019 MaxVersion: ver.version,
3020 ClientAuth: RequireAnyClientCert,
3021 },
3022 shouldFail: true,
3023 expectedLocalError: "client didn't provide a certificate",
3024 })
3025
3026 testCases = append(testCases, testCase{
3027 // Even if not configured to expect a certificate, OpenSSL will
3028 // return X509_V_OK as the verify_result.
3029 testType: serverTest,
3030 name: "NoClientCertificateRequested-Server-" + ver.name,
3031 config: Config{
3032 MinVersion: ver.version,
3033 MaxVersion: ver.version,
3034 },
3035 flags: []string{
3036 "-expect-verify-result",
3037 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003038 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003039 })
3040
3041 testCases = append(testCases, testCase{
3042 // If a client certificate is not provided, OpenSSL will still
3043 // return X509_V_OK as the verify_result.
3044 testType: serverTest,
3045 name: "NoClientCertificate-Server-" + ver.name,
3046 config: Config{
3047 MinVersion: ver.version,
3048 MaxVersion: ver.version,
3049 },
3050 flags: []string{
3051 "-expect-verify-result",
3052 "-verify-peer",
3053 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003054 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003055 })
3056
David Benjamin1db9e1b2016-10-07 20:51:43 -04003057 certificateRequired := "remote error: certificate required"
3058 if ver.version < VersionTLS13 {
3059 // Prior to TLS 1.3, the generic handshake_failure alert
3060 // was used.
3061 certificateRequired = "remote error: handshake failure"
3062 }
Adam Langley37646832016-08-01 16:16:46 -07003063 testCases = append(testCases, testCase{
3064 testType: serverTest,
3065 name: "RequireAnyClientCertificate-" + ver.name,
3066 config: Config{
3067 MinVersion: ver.version,
3068 MaxVersion: ver.version,
3069 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003070 flags: []string{"-require-any-client-certificate"},
3071 shouldFail: true,
3072 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3073 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003074 })
3075
3076 if ver.version != VersionSSL30 {
3077 testCases = append(testCases, testCase{
3078 testType: serverTest,
3079 name: "SkipClientCertificate-" + ver.name,
3080 config: Config{
3081 MinVersion: ver.version,
3082 MaxVersion: ver.version,
3083 Bugs: ProtocolBugs{
3084 SkipClientCertificate: true,
3085 },
3086 },
3087 // Setting SSL_VERIFY_PEER allows anonymous clients.
3088 flags: []string{"-verify-peer"},
3089 shouldFail: true,
3090 expectedError: ":UNEXPECTED_MESSAGE:",
3091 })
3092 }
David Benjamin636293b2014-07-08 17:59:18 -04003093 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003094
David Benjaminc032dfa2016-05-12 14:54:57 -04003095 // Client auth is only legal in certificate-based ciphers.
3096 testCases = append(testCases, testCase{
3097 testType: clientTest,
3098 name: "ClientAuth-PSK",
3099 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003100 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003101 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3102 PreSharedKey: []byte("secret"),
3103 ClientAuth: RequireAnyClientCert,
3104 },
3105 flags: []string{
3106 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3107 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3108 "-psk", "secret",
3109 },
3110 shouldFail: true,
3111 expectedError: ":UNEXPECTED_MESSAGE:",
3112 })
3113 testCases = append(testCases, testCase{
3114 testType: clientTest,
3115 name: "ClientAuth-ECDHE_PSK",
3116 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003117 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003118 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3119 PreSharedKey: []byte("secret"),
3120 ClientAuth: RequireAnyClientCert,
3121 },
3122 flags: []string{
3123 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3124 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3125 "-psk", "secret",
3126 },
3127 shouldFail: true,
3128 expectedError: ":UNEXPECTED_MESSAGE:",
3129 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003130
3131 // Regression test for a bug where the client CA list, if explicitly
3132 // set to NULL, was mis-encoded.
3133 testCases = append(testCases, testCase{
3134 testType: serverTest,
3135 name: "Null-Client-CA-List",
3136 config: Config{
3137 MaxVersion: VersionTLS12,
3138 Certificates: []Certificate{rsaCertificate},
3139 },
3140 flags: []string{
3141 "-require-any-client-certificate",
3142 "-use-null-client-ca-list",
3143 },
3144 })
David Benjamin636293b2014-07-08 17:59:18 -04003145}
3146
Adam Langley75712922014-10-10 16:23:43 -07003147func addExtendedMasterSecretTests() {
3148 const expectEMSFlag = "-expect-extended-master-secret"
3149
3150 for _, with := range []bool{false, true} {
3151 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003152 if with {
3153 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003154 }
3155
3156 for _, isClient := range []bool{false, true} {
3157 suffix := "-Server"
3158 testType := serverTest
3159 if isClient {
3160 suffix = "-Client"
3161 testType = clientTest
3162 }
3163
3164 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003165 // In TLS 1.3, the extension is irrelevant and
3166 // always reports as enabled.
3167 var flags []string
3168 if with || ver.version >= VersionTLS13 {
3169 flags = []string{expectEMSFlag}
3170 }
3171
Adam Langley75712922014-10-10 16:23:43 -07003172 test := testCase{
3173 testType: testType,
3174 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3175 config: Config{
3176 MinVersion: ver.version,
3177 MaxVersion: ver.version,
3178 Bugs: ProtocolBugs{
3179 NoExtendedMasterSecret: !with,
3180 RequireExtendedMasterSecret: with,
3181 },
3182 },
David Benjamin48cae082014-10-27 01:06:24 -04003183 flags: flags,
3184 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003185 }
3186 if test.shouldFail {
3187 test.expectedLocalError = "extended master secret required but not supported by peer"
3188 }
3189 testCases = append(testCases, test)
3190 }
3191 }
3192 }
3193
Adam Langleyba5934b2015-06-02 10:50:35 -07003194 for _, isClient := range []bool{false, true} {
3195 for _, supportedInFirstConnection := range []bool{false, true} {
3196 for _, supportedInResumeConnection := range []bool{false, true} {
3197 boolToWord := func(b bool) string {
3198 if b {
3199 return "Yes"
3200 }
3201 return "No"
3202 }
3203 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3204 if isClient {
3205 suffix += "Client"
3206 } else {
3207 suffix += "Server"
3208 }
3209
3210 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003211 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003212 Bugs: ProtocolBugs{
3213 RequireExtendedMasterSecret: true,
3214 },
3215 }
3216
3217 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003218 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003219 Bugs: ProtocolBugs{
3220 NoExtendedMasterSecret: true,
3221 },
3222 }
3223
3224 test := testCase{
3225 name: "ExtendedMasterSecret-" + suffix,
3226 resumeSession: true,
3227 }
3228
3229 if !isClient {
3230 test.testType = serverTest
3231 }
3232
3233 if supportedInFirstConnection {
3234 test.config = supportedConfig
3235 } else {
3236 test.config = noSupportConfig
3237 }
3238
3239 if supportedInResumeConnection {
3240 test.resumeConfig = &supportedConfig
3241 } else {
3242 test.resumeConfig = &noSupportConfig
3243 }
3244
3245 switch suffix {
3246 case "YesToYes-Client", "YesToYes-Server":
3247 // When a session is resumed, it should
3248 // still be aware that its master
3249 // secret was generated via EMS and
3250 // thus it's safe to use tls-unique.
3251 test.flags = []string{expectEMSFlag}
3252 case "NoToYes-Server":
3253 // If an original connection did not
3254 // contain EMS, but a resumption
3255 // handshake does, then a server should
3256 // not resume the session.
3257 test.expectResumeRejected = true
3258 case "YesToNo-Server":
3259 // Resuming an EMS session without the
3260 // EMS extension should cause the
3261 // server to abort the connection.
3262 test.shouldFail = true
3263 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3264 case "NoToYes-Client":
3265 // A client should abort a connection
3266 // where the server resumed a non-EMS
3267 // session but echoed the EMS
3268 // extension.
3269 test.shouldFail = true
3270 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3271 case "YesToNo-Client":
3272 // A client should abort a connection
3273 // where the server didn't echo EMS
3274 // when the session used it.
3275 test.shouldFail = true
3276 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3277 }
3278
3279 testCases = append(testCases, test)
3280 }
3281 }
3282 }
David Benjamin163c9562016-08-29 23:14:17 -04003283
3284 // Switching EMS on renegotiation is forbidden.
3285 testCases = append(testCases, testCase{
3286 name: "ExtendedMasterSecret-Renego-NoEMS",
3287 config: Config{
3288 MaxVersion: VersionTLS12,
3289 Bugs: ProtocolBugs{
3290 NoExtendedMasterSecret: true,
3291 NoExtendedMasterSecretOnRenegotiation: true,
3292 },
3293 },
3294 renegotiate: 1,
3295 flags: []string{
3296 "-renegotiate-freely",
3297 "-expect-total-renegotiations", "1",
3298 },
3299 })
3300
3301 testCases = append(testCases, testCase{
3302 name: "ExtendedMasterSecret-Renego-Upgrade",
3303 config: Config{
3304 MaxVersion: VersionTLS12,
3305 Bugs: ProtocolBugs{
3306 NoExtendedMasterSecret: true,
3307 },
3308 },
3309 renegotiate: 1,
3310 flags: []string{
3311 "-renegotiate-freely",
3312 "-expect-total-renegotiations", "1",
3313 },
3314 shouldFail: true,
3315 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3316 })
3317
3318 testCases = append(testCases, testCase{
3319 name: "ExtendedMasterSecret-Renego-Downgrade",
3320 config: Config{
3321 MaxVersion: VersionTLS12,
3322 Bugs: ProtocolBugs{
3323 NoExtendedMasterSecretOnRenegotiation: true,
3324 },
3325 },
3326 renegotiate: 1,
3327 flags: []string{
3328 "-renegotiate-freely",
3329 "-expect-total-renegotiations", "1",
3330 },
3331 shouldFail: true,
3332 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3333 })
Adam Langley75712922014-10-10 16:23:43 -07003334}
3335
David Benjamin582ba042016-07-07 12:33:25 -07003336type stateMachineTestConfig struct {
3337 protocol protocol
3338 async bool
3339 splitHandshake, packHandshakeFlight bool
3340}
3341
David Benjamin43ec06f2014-08-05 02:28:57 -04003342// Adds tests that try to cover the range of the handshake state machine, under
3343// various conditions. Some of these are redundant with other tests, but they
3344// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003345func addAllStateMachineCoverageTests() {
3346 for _, async := range []bool{false, true} {
3347 for _, protocol := range []protocol{tls, dtls} {
3348 addStateMachineCoverageTests(stateMachineTestConfig{
3349 protocol: protocol,
3350 async: async,
3351 })
3352 addStateMachineCoverageTests(stateMachineTestConfig{
3353 protocol: protocol,
3354 async: async,
3355 splitHandshake: true,
3356 })
3357 if protocol == tls {
3358 addStateMachineCoverageTests(stateMachineTestConfig{
3359 protocol: protocol,
3360 async: async,
3361 packHandshakeFlight: true,
3362 })
3363 }
3364 }
3365 }
3366}
3367
3368func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003369 var tests []testCase
3370
3371 // Basic handshake, with resumption. Client and server,
3372 // session ID and session ticket.
3373 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003374 name: "Basic-Client",
3375 config: Config{
3376 MaxVersion: VersionTLS12,
3377 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003378 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003379 // Ensure session tickets are used, not session IDs.
3380 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003381 })
3382 tests = append(tests, testCase{
3383 name: "Basic-Client-RenewTicket",
3384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003385 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003386 Bugs: ProtocolBugs{
3387 RenewTicketOnResume: true,
3388 },
3389 },
David Benjamin46662482016-08-17 00:51:00 -04003390 flags: []string{"-expect-ticket-renewal"},
3391 resumeSession: true,
3392 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003393 })
3394 tests = append(tests, testCase{
3395 name: "Basic-Client-NoTicket",
3396 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003397 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003398 SessionTicketsDisabled: true,
3399 },
3400 resumeSession: true,
3401 })
3402 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003403 name: "Basic-Client-Implicit",
3404 config: Config{
3405 MaxVersion: VersionTLS12,
3406 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003407 flags: []string{"-implicit-handshake"},
3408 resumeSession: true,
3409 })
3410 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003411 testType: serverTest,
3412 name: "Basic-Server",
3413 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003414 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003415 Bugs: ProtocolBugs{
3416 RequireSessionTickets: true,
3417 },
3418 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003419 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003420 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003421 })
3422 tests = append(tests, testCase{
3423 testType: serverTest,
3424 name: "Basic-Server-NoTickets",
3425 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003426 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003427 SessionTicketsDisabled: true,
3428 },
3429 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003430 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003431 })
3432 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003433 testType: serverTest,
3434 name: "Basic-Server-Implicit",
3435 config: Config{
3436 MaxVersion: VersionTLS12,
3437 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003438 flags: []string{"-implicit-handshake"},
3439 resumeSession: true,
3440 })
3441 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003442 testType: serverTest,
3443 name: "Basic-Server-EarlyCallback",
3444 config: Config{
3445 MaxVersion: VersionTLS12,
3446 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003447 flags: []string{"-use-early-callback"},
3448 resumeSession: true,
3449 })
3450
Steven Valdez143e8b32016-07-11 13:19:03 -04003451 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003452 if config.protocol == tls {
3453 tests = append(tests, testCase{
3454 name: "TLS13-1RTT-Client",
3455 config: Config{
3456 MaxVersion: VersionTLS13,
3457 MinVersion: VersionTLS13,
3458 },
David Benjamin46662482016-08-17 00:51:00 -04003459 resumeSession: true,
3460 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003461 })
3462
3463 tests = append(tests, testCase{
3464 testType: serverTest,
3465 name: "TLS13-1RTT-Server",
3466 config: Config{
3467 MaxVersion: VersionTLS13,
3468 MinVersion: VersionTLS13,
3469 },
David Benjamin46662482016-08-17 00:51:00 -04003470 resumeSession: true,
3471 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003472 // TLS 1.3 uses tickets, so the session should not be
3473 // cached statefully.
3474 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003475 })
3476
3477 tests = append(tests, testCase{
3478 name: "TLS13-HelloRetryRequest-Client",
3479 config: Config{
3480 MaxVersion: VersionTLS13,
3481 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003482 // P-384 requires a HelloRetryRequest against BoringSSL's default
3483 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003484 CurvePreferences: []CurveID{CurveP384},
3485 Bugs: ProtocolBugs{
3486 ExpectMissingKeyShare: true,
3487 },
3488 },
3489 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3490 resumeSession: true,
3491 })
3492
3493 tests = append(tests, testCase{
3494 testType: serverTest,
3495 name: "TLS13-HelloRetryRequest-Server",
3496 config: Config{
3497 MaxVersion: VersionTLS13,
3498 MinVersion: VersionTLS13,
3499 // Require a HelloRetryRequest for every curve.
3500 DefaultCurves: []CurveID{},
3501 },
3502 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3503 resumeSession: true,
3504 })
3505 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003506
David Benjamin760b1dd2015-05-15 23:33:48 -04003507 // TLS client auth.
3508 tests = append(tests, testCase{
3509 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003510 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003511 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003512 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003513 ClientAuth: RequestClientCert,
3514 },
3515 })
3516 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003517 testType: serverTest,
3518 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003519 config: Config{
3520 MaxVersion: VersionTLS12,
3521 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003522 // Setting SSL_VERIFY_PEER allows anonymous clients.
3523 flags: []string{"-verify-peer"},
3524 })
David Benjamin582ba042016-07-07 12:33:25 -07003525 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003526 tests = append(tests, testCase{
3527 testType: clientTest,
3528 name: "ClientAuth-NoCertificate-Client-SSL3",
3529 config: Config{
3530 MaxVersion: VersionSSL30,
3531 ClientAuth: RequestClientCert,
3532 },
3533 })
3534 tests = append(tests, testCase{
3535 testType: serverTest,
3536 name: "ClientAuth-NoCertificate-Server-SSL3",
3537 config: Config{
3538 MaxVersion: VersionSSL30,
3539 },
3540 // Setting SSL_VERIFY_PEER allows anonymous clients.
3541 flags: []string{"-verify-peer"},
3542 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003543 tests = append(tests, testCase{
3544 testType: clientTest,
3545 name: "ClientAuth-NoCertificate-Client-TLS13",
3546 config: Config{
3547 MaxVersion: VersionTLS13,
3548 ClientAuth: RequestClientCert,
3549 },
3550 })
3551 tests = append(tests, testCase{
3552 testType: serverTest,
3553 name: "ClientAuth-NoCertificate-Server-TLS13",
3554 config: Config{
3555 MaxVersion: VersionTLS13,
3556 },
3557 // Setting SSL_VERIFY_PEER allows anonymous clients.
3558 flags: []string{"-verify-peer"},
3559 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003560 }
3561 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003562 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003563 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003564 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003565 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003566 ClientAuth: RequireAnyClientCert,
3567 },
3568 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003569 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3570 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003571 },
3572 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003573 tests = append(tests, testCase{
3574 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003575 name: "ClientAuth-RSA-Client-TLS13",
3576 config: Config{
3577 MaxVersion: VersionTLS13,
3578 ClientAuth: RequireAnyClientCert,
3579 },
3580 flags: []string{
3581 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3582 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3583 },
3584 })
3585 tests = append(tests, testCase{
3586 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003587 name: "ClientAuth-ECDSA-Client",
3588 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003589 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003590 ClientAuth: RequireAnyClientCert,
3591 },
3592 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003593 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3594 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003595 },
3596 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003597 tests = append(tests, testCase{
3598 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003599 name: "ClientAuth-ECDSA-Client-TLS13",
3600 config: Config{
3601 MaxVersion: VersionTLS13,
3602 ClientAuth: RequireAnyClientCert,
3603 },
3604 flags: []string{
3605 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3606 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3607 },
3608 })
3609 tests = append(tests, testCase{
3610 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003611 name: "ClientAuth-NoCertificate-OldCallback",
3612 config: Config{
3613 MaxVersion: VersionTLS12,
3614 ClientAuth: RequestClientCert,
3615 },
3616 flags: []string{"-use-old-client-cert-callback"},
3617 })
3618 tests = append(tests, testCase{
3619 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003620 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3621 config: Config{
3622 MaxVersion: VersionTLS13,
3623 ClientAuth: RequestClientCert,
3624 },
3625 flags: []string{"-use-old-client-cert-callback"},
3626 })
3627 tests = append(tests, testCase{
3628 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003629 name: "ClientAuth-OldCallback",
3630 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003631 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003632 ClientAuth: RequireAnyClientCert,
3633 },
3634 flags: []string{
3635 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3636 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3637 "-use-old-client-cert-callback",
3638 },
3639 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003640 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003641 testType: clientTest,
3642 name: "ClientAuth-OldCallback-TLS13",
3643 config: Config{
3644 MaxVersion: VersionTLS13,
3645 ClientAuth: RequireAnyClientCert,
3646 },
3647 flags: []string{
3648 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3649 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3650 "-use-old-client-cert-callback",
3651 },
3652 })
3653 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003654 testType: serverTest,
3655 name: "ClientAuth-Server",
3656 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003657 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003658 Certificates: []Certificate{rsaCertificate},
3659 },
3660 flags: []string{"-require-any-client-certificate"},
3661 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003662 tests = append(tests, testCase{
3663 testType: serverTest,
3664 name: "ClientAuth-Server-TLS13",
3665 config: Config{
3666 MaxVersion: VersionTLS13,
3667 Certificates: []Certificate{rsaCertificate},
3668 },
3669 flags: []string{"-require-any-client-certificate"},
3670 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003671
David Benjamin4c3ddf72016-06-29 18:13:53 -04003672 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003673 tests = append(tests, testCase{
3674 testType: serverTest,
3675 name: "Basic-Server-RSA",
3676 config: Config{
3677 MaxVersion: VersionTLS12,
3678 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3679 },
3680 flags: []string{
3681 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3682 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3683 },
3684 })
3685 tests = append(tests, testCase{
3686 testType: serverTest,
3687 name: "Basic-Server-ECDHE-RSA",
3688 config: Config{
3689 MaxVersion: VersionTLS12,
3690 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3691 },
3692 flags: []string{
3693 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3694 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3695 },
3696 })
3697 tests = append(tests, testCase{
3698 testType: serverTest,
3699 name: "Basic-Server-ECDHE-ECDSA",
3700 config: Config{
3701 MaxVersion: VersionTLS12,
3702 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3703 },
3704 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003705 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3706 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003707 },
3708 })
3709
David Benjamin760b1dd2015-05-15 23:33:48 -04003710 // No session ticket support; server doesn't send NewSessionTicket.
3711 tests = append(tests, testCase{
3712 name: "SessionTicketsDisabled-Client",
3713 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003714 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003715 SessionTicketsDisabled: true,
3716 },
3717 })
3718 tests = append(tests, testCase{
3719 testType: serverTest,
3720 name: "SessionTicketsDisabled-Server",
3721 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003722 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003723 SessionTicketsDisabled: true,
3724 },
3725 })
3726
3727 // Skip ServerKeyExchange in PSK key exchange if there's no
3728 // identity hint.
3729 tests = append(tests, testCase{
3730 name: "EmptyPSKHint-Client",
3731 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003732 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003733 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3734 PreSharedKey: []byte("secret"),
3735 },
3736 flags: []string{"-psk", "secret"},
3737 })
3738 tests = append(tests, testCase{
3739 testType: serverTest,
3740 name: "EmptyPSKHint-Server",
3741 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003742 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003743 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3744 PreSharedKey: []byte("secret"),
3745 },
3746 flags: []string{"-psk", "secret"},
3747 })
3748
David Benjamin4c3ddf72016-06-29 18:13:53 -04003749 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003750 tests = append(tests, testCase{
3751 testType: clientTest,
3752 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 config: Config{
3754 MaxVersion: VersionTLS12,
3755 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003756 flags: []string{
3757 "-enable-ocsp-stapling",
3758 "-expect-ocsp-response",
3759 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003760 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003761 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003762 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003763 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003764 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003765 testType: serverTest,
3766 name: "OCSPStapling-Server",
3767 config: Config{
3768 MaxVersion: VersionTLS12,
3769 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003770 expectedOCSPResponse: testOCSPResponse,
3771 flags: []string{
3772 "-ocsp-response",
3773 base64.StdEncoding.EncodeToString(testOCSPResponse),
3774 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003775 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003776 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003777 tests = append(tests, testCase{
3778 testType: clientTest,
3779 name: "OCSPStapling-Client-TLS13",
3780 config: Config{
3781 MaxVersion: VersionTLS13,
3782 },
3783 flags: []string{
3784 "-enable-ocsp-stapling",
3785 "-expect-ocsp-response",
3786 base64.StdEncoding.EncodeToString(testOCSPResponse),
3787 "-verify-peer",
3788 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003789 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003790 })
3791 tests = append(tests, testCase{
3792 testType: serverTest,
3793 name: "OCSPStapling-Server-TLS13",
3794 config: Config{
3795 MaxVersion: VersionTLS13,
3796 },
3797 expectedOCSPResponse: testOCSPResponse,
3798 flags: []string{
3799 "-ocsp-response",
3800 base64.StdEncoding.EncodeToString(testOCSPResponse),
3801 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003802 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003803 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003804
David Benjamin4c3ddf72016-06-29 18:13:53 -04003805 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003806 for _, vers := range tlsVersions {
3807 if config.protocol == dtls && !vers.hasDTLS {
3808 continue
3809 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003810 for _, testType := range []testType{clientTest, serverTest} {
3811 suffix := "-Client"
3812 if testType == serverTest {
3813 suffix = "-Server"
3814 }
3815 suffix += "-" + vers.name
3816
3817 flag := "-verify-peer"
3818 if testType == serverTest {
3819 flag = "-require-any-client-certificate"
3820 }
3821
3822 tests = append(tests, testCase{
3823 testType: testType,
3824 name: "CertificateVerificationSucceed" + suffix,
3825 config: Config{
3826 MaxVersion: vers.version,
3827 Certificates: []Certificate{rsaCertificate},
3828 },
3829 flags: []string{
3830 flag,
3831 "-expect-verify-result",
3832 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003833 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003834 })
3835 tests = append(tests, testCase{
3836 testType: testType,
3837 name: "CertificateVerificationFail" + suffix,
3838 config: Config{
3839 MaxVersion: vers.version,
3840 Certificates: []Certificate{rsaCertificate},
3841 },
3842 flags: []string{
3843 flag,
3844 "-verify-fail",
3845 },
3846 shouldFail: true,
3847 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3848 })
3849 }
3850
3851 // By default, the client is in a soft fail mode where the peer
3852 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003853 tests = append(tests, testCase{
3854 testType: clientTest,
3855 name: "CertificateVerificationSoftFail-" + vers.name,
3856 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003857 MaxVersion: vers.version,
3858 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003859 },
3860 flags: []string{
3861 "-verify-fail",
3862 "-expect-verify-result",
3863 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003864 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003865 })
3866 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003867
David Benjamin1d4f4c02016-07-26 18:03:08 -04003868 tests = append(tests, testCase{
3869 name: "ShimSendAlert",
3870 flags: []string{"-send-alert"},
3871 shimWritesFirst: true,
3872 shouldFail: true,
3873 expectedLocalError: "remote error: decompression failure",
3874 })
3875
David Benjamin582ba042016-07-07 12:33:25 -07003876 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003877 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003878 name: "Renegotiate-Client",
3879 config: Config{
3880 MaxVersion: VersionTLS12,
3881 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003882 renegotiate: 1,
3883 flags: []string{
3884 "-renegotiate-freely",
3885 "-expect-total-renegotiations", "1",
3886 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003887 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003888
David Benjamin47921102016-07-28 11:29:18 -04003889 tests = append(tests, testCase{
3890 name: "SendHalfHelloRequest",
3891 config: Config{
3892 MaxVersion: VersionTLS12,
3893 Bugs: ProtocolBugs{
3894 PackHelloRequestWithFinished: config.packHandshakeFlight,
3895 },
3896 },
3897 sendHalfHelloRequest: true,
3898 flags: []string{"-renegotiate-ignore"},
3899 shouldFail: true,
3900 expectedError: ":UNEXPECTED_RECORD:",
3901 })
3902
David Benjamin760b1dd2015-05-15 23:33:48 -04003903 // NPN on client and server; results in post-handshake message.
3904 tests = append(tests, testCase{
3905 name: "NPN-Client",
3906 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003907 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003908 NextProtos: []string{"foo"},
3909 },
3910 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003911 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003912 expectedNextProto: "foo",
3913 expectedNextProtoType: npn,
3914 })
3915 tests = append(tests, testCase{
3916 testType: serverTest,
3917 name: "NPN-Server",
3918 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003919 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003920 NextProtos: []string{"bar"},
3921 },
3922 flags: []string{
3923 "-advertise-npn", "\x03foo\x03bar\x03baz",
3924 "-expect-next-proto", "bar",
3925 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003926 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003927 expectedNextProto: "bar",
3928 expectedNextProtoType: npn,
3929 })
3930
3931 // TODO(davidben): Add tests for when False Start doesn't trigger.
3932
3933 // Client does False Start and negotiates NPN.
3934 tests = append(tests, testCase{
3935 name: "FalseStart",
3936 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003937 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003938 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3939 NextProtos: []string{"foo"},
3940 Bugs: ProtocolBugs{
3941 ExpectFalseStart: true,
3942 },
3943 },
3944 flags: []string{
3945 "-false-start",
3946 "-select-next-proto", "foo",
3947 },
3948 shimWritesFirst: true,
3949 resumeSession: true,
3950 })
3951
3952 // Client does False Start and negotiates ALPN.
3953 tests = append(tests, testCase{
3954 name: "FalseStart-ALPN",
3955 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003956 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003957 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3958 NextProtos: []string{"foo"},
3959 Bugs: ProtocolBugs{
3960 ExpectFalseStart: true,
3961 },
3962 },
3963 flags: []string{
3964 "-false-start",
3965 "-advertise-alpn", "\x03foo",
3966 },
3967 shimWritesFirst: true,
3968 resumeSession: true,
3969 })
3970
3971 // Client does False Start but doesn't explicitly call
3972 // SSL_connect.
3973 tests = append(tests, testCase{
3974 name: "FalseStart-Implicit",
3975 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003976 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3978 NextProtos: []string{"foo"},
3979 },
3980 flags: []string{
3981 "-implicit-handshake",
3982 "-false-start",
3983 "-advertise-alpn", "\x03foo",
3984 },
3985 })
3986
3987 // False Start without session tickets.
3988 tests = append(tests, testCase{
3989 name: "FalseStart-SessionTicketsDisabled",
3990 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003991 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003992 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3993 NextProtos: []string{"foo"},
3994 SessionTicketsDisabled: true,
3995 Bugs: ProtocolBugs{
3996 ExpectFalseStart: true,
3997 },
3998 },
3999 flags: []string{
4000 "-false-start",
4001 "-select-next-proto", "foo",
4002 },
4003 shimWritesFirst: true,
4004 })
4005
4006 // Server parses a V2ClientHello.
4007 tests = append(tests, testCase{
4008 testType: serverTest,
4009 name: "SendV2ClientHello",
4010 config: Config{
4011 // Choose a cipher suite that does not involve
4012 // elliptic curves, so no extensions are
4013 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004014 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004015 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004016 Bugs: ProtocolBugs{
4017 SendV2ClientHello: true,
4018 },
4019 },
4020 })
4021
Nick Harper60a85cb2016-09-23 16:25:11 -07004022 // Test Channel ID
4023 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004024 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004025 continue
4026 }
4027 // Client sends a Channel ID.
4028 tests = append(tests, testCase{
4029 name: "ChannelID-Client-" + ver.name,
4030 config: Config{
4031 MaxVersion: ver.version,
4032 RequestChannelID: true,
4033 },
4034 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4035 resumeSession: true,
4036 expectChannelID: true,
4037 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004038
Nick Harper60a85cb2016-09-23 16:25:11 -07004039 // Server accepts a Channel ID.
4040 tests = append(tests, testCase{
4041 testType: serverTest,
4042 name: "ChannelID-Server-" + ver.name,
4043 config: Config{
4044 MaxVersion: ver.version,
4045 ChannelID: channelIDKey,
4046 },
4047 flags: []string{
4048 "-expect-channel-id",
4049 base64.StdEncoding.EncodeToString(channelIDBytes),
4050 },
4051 resumeSession: true,
4052 expectChannelID: true,
4053 })
4054
4055 tests = append(tests, testCase{
4056 testType: serverTest,
4057 name: "InvalidChannelIDSignature-" + ver.name,
4058 config: Config{
4059 MaxVersion: ver.version,
4060 ChannelID: channelIDKey,
4061 Bugs: ProtocolBugs{
4062 InvalidChannelIDSignature: true,
4063 },
4064 },
4065 flags: []string{"-enable-channel-id"},
4066 shouldFail: true,
4067 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4068 })
4069 }
David Benjamin30789da2015-08-29 22:56:45 -04004070
David Benjaminf8fcdf32016-06-08 15:56:13 -04004071 // Channel ID and NPN at the same time, to ensure their relative
4072 // ordering is correct.
4073 tests = append(tests, testCase{
4074 name: "ChannelID-NPN-Client",
4075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004076 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004077 RequestChannelID: true,
4078 NextProtos: []string{"foo"},
4079 },
4080 flags: []string{
4081 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4082 "-select-next-proto", "foo",
4083 },
4084 resumeSession: true,
4085 expectChannelID: true,
4086 expectedNextProto: "foo",
4087 expectedNextProtoType: npn,
4088 })
4089 tests = append(tests, testCase{
4090 testType: serverTest,
4091 name: "ChannelID-NPN-Server",
4092 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004093 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004094 ChannelID: channelIDKey,
4095 NextProtos: []string{"bar"},
4096 },
4097 flags: []string{
4098 "-expect-channel-id",
4099 base64.StdEncoding.EncodeToString(channelIDBytes),
4100 "-advertise-npn", "\x03foo\x03bar\x03baz",
4101 "-expect-next-proto", "bar",
4102 },
4103 resumeSession: true,
4104 expectChannelID: true,
4105 expectedNextProto: "bar",
4106 expectedNextProtoType: npn,
4107 })
4108
David Benjamin30789da2015-08-29 22:56:45 -04004109 // Bidirectional shutdown with the runner initiating.
4110 tests = append(tests, testCase{
4111 name: "Shutdown-Runner",
4112 config: Config{
4113 Bugs: ProtocolBugs{
4114 ExpectCloseNotify: true,
4115 },
4116 },
4117 flags: []string{"-check-close-notify"},
4118 })
4119
4120 // Bidirectional shutdown with the shim initiating. The runner,
4121 // in the meantime, sends garbage before the close_notify which
4122 // the shim must ignore.
4123 tests = append(tests, testCase{
4124 name: "Shutdown-Shim",
4125 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004126 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004127 Bugs: ProtocolBugs{
4128 ExpectCloseNotify: true,
4129 },
4130 },
4131 shimShutsDown: true,
4132 sendEmptyRecords: 1,
4133 sendWarningAlerts: 1,
4134 flags: []string{"-check-close-notify"},
4135 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004136 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004137 // TODO(davidben): DTLS 1.3 will want a similar thing for
4138 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004139 tests = append(tests, testCase{
4140 name: "SkipHelloVerifyRequest",
4141 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004142 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004143 Bugs: ProtocolBugs{
4144 SkipHelloVerifyRequest: true,
4145 },
4146 },
4147 })
4148 }
4149
David Benjamin760b1dd2015-05-15 23:33:48 -04004150 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004151 test.protocol = config.protocol
4152 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004153 test.name += "-DTLS"
4154 }
David Benjamin582ba042016-07-07 12:33:25 -07004155 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004156 test.name += "-Async"
4157 test.flags = append(test.flags, "-async")
4158 } else {
4159 test.name += "-Sync"
4160 }
David Benjamin582ba042016-07-07 12:33:25 -07004161 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004162 test.name += "-SplitHandshakeRecords"
4163 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004164 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004165 test.config.Bugs.MaxPacketLength = 256
4166 test.flags = append(test.flags, "-mtu", "256")
4167 }
4168 }
David Benjamin582ba042016-07-07 12:33:25 -07004169 if config.packHandshakeFlight {
4170 test.name += "-PackHandshakeFlight"
4171 test.config.Bugs.PackHandshakeFlight = true
4172 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004173 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004174 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004175}
4176
Adam Langley524e7172015-02-20 16:04:00 -08004177func addDDoSCallbackTests() {
4178 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004179 for _, resume := range []bool{false, true} {
4180 suffix := "Resume"
4181 if resume {
4182 suffix = "No" + suffix
4183 }
4184
4185 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004186 testType: serverTest,
4187 name: "Server-DDoS-OK-" + suffix,
4188 config: Config{
4189 MaxVersion: VersionTLS12,
4190 },
Adam Langley524e7172015-02-20 16:04:00 -08004191 flags: []string{"-install-ddos-callback"},
4192 resumeSession: resume,
4193 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004194 testCases = append(testCases, testCase{
4195 testType: serverTest,
4196 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4197 config: Config{
4198 MaxVersion: VersionTLS13,
4199 },
4200 flags: []string{"-install-ddos-callback"},
4201 resumeSession: resume,
4202 })
Adam Langley524e7172015-02-20 16:04:00 -08004203
4204 failFlag := "-fail-ddos-callback"
4205 if resume {
4206 failFlag = "-fail-second-ddos-callback"
4207 }
4208 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004209 testType: serverTest,
4210 name: "Server-DDoS-Reject-" + suffix,
4211 config: Config{
4212 MaxVersion: VersionTLS12,
4213 },
David Benjamin2c66e072016-09-16 15:58:00 -04004214 flags: []string{"-install-ddos-callback", failFlag},
4215 resumeSession: resume,
4216 shouldFail: true,
4217 expectedError: ":CONNECTION_REJECTED:",
4218 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004219 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004220 testCases = append(testCases, testCase{
4221 testType: serverTest,
4222 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4223 config: Config{
4224 MaxVersion: VersionTLS13,
4225 },
David Benjamin2c66e072016-09-16 15:58:00 -04004226 flags: []string{"-install-ddos-callback", failFlag},
4227 resumeSession: resume,
4228 shouldFail: true,
4229 expectedError: ":CONNECTION_REJECTED:",
4230 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004231 })
Adam Langley524e7172015-02-20 16:04:00 -08004232 }
4233}
4234
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004235func addVersionNegotiationTests() {
4236 for i, shimVers := range tlsVersions {
4237 // Assemble flags to disable all newer versions on the shim.
4238 var flags []string
4239 for _, vers := range tlsVersions[i+1:] {
4240 flags = append(flags, vers.flag)
4241 }
4242
Steven Valdezfdd10992016-09-15 16:27:05 -04004243 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004244 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004245 protocols := []protocol{tls}
4246 if runnerVers.hasDTLS && shimVers.hasDTLS {
4247 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004248 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004249 for _, protocol := range protocols {
4250 expectedVersion := shimVers.version
4251 if runnerVers.version < shimVers.version {
4252 expectedVersion = runnerVers.version
4253 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004254
David Benjamin8b8c0062014-11-23 02:47:52 -05004255 suffix := shimVers.name + "-" + runnerVers.name
4256 if protocol == dtls {
4257 suffix += "-DTLS"
4258 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004259
David Benjamin1eb367c2014-12-12 18:17:51 -05004260 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4261
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004262 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004263 clientVers := shimVers.version
4264 if clientVers > VersionTLS10 {
4265 clientVers = VersionTLS10
4266 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004267 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004268 serverVers := expectedVersion
4269 if expectedVersion >= VersionTLS13 {
4270 serverVers = VersionTLS10
4271 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004272 serverVers = versionToWire(serverVers, protocol == dtls)
4273
David Benjamin8b8c0062014-11-23 02:47:52 -05004274 testCases = append(testCases, testCase{
4275 protocol: protocol,
4276 testType: clientTest,
4277 name: "VersionNegotiation-Client-" + suffix,
4278 config: Config{
4279 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004280 Bugs: ProtocolBugs{
4281 ExpectInitialRecordVersion: clientVers,
4282 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004283 },
4284 flags: flags,
4285 expectedVersion: expectedVersion,
4286 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004287 testCases = append(testCases, testCase{
4288 protocol: protocol,
4289 testType: clientTest,
4290 name: "VersionNegotiation-Client2-" + suffix,
4291 config: Config{
4292 MaxVersion: runnerVers.version,
4293 Bugs: ProtocolBugs{
4294 ExpectInitialRecordVersion: clientVers,
4295 },
4296 },
4297 flags: []string{"-max-version", shimVersFlag},
4298 expectedVersion: expectedVersion,
4299 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004300
4301 testCases = append(testCases, testCase{
4302 protocol: protocol,
4303 testType: serverTest,
4304 name: "VersionNegotiation-Server-" + suffix,
4305 config: Config{
4306 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004307 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004308 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004309 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004310 },
4311 flags: flags,
4312 expectedVersion: expectedVersion,
4313 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: serverTest,
4317 name: "VersionNegotiation-Server2-" + suffix,
4318 config: Config{
4319 MaxVersion: runnerVers.version,
4320 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004321 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004322 },
4323 },
4324 flags: []string{"-max-version", shimVersFlag},
4325 expectedVersion: expectedVersion,
4326 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004327 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004328 }
4329 }
David Benjamin95c69562016-06-29 18:15:03 -04004330
Steven Valdezfdd10992016-09-15 16:27:05 -04004331 // Test the version extension at all versions.
4332 for _, vers := range tlsVersions {
4333 protocols := []protocol{tls}
4334 if vers.hasDTLS {
4335 protocols = append(protocols, dtls)
4336 }
4337 for _, protocol := range protocols {
4338 suffix := vers.name
4339 if protocol == dtls {
4340 suffix += "-DTLS"
4341 }
4342
4343 wireVersion := versionToWire(vers.version, protocol == dtls)
4344 testCases = append(testCases, testCase{
4345 protocol: protocol,
4346 testType: serverTest,
4347 name: "VersionNegotiationExtension-" + suffix,
4348 config: Config{
4349 Bugs: ProtocolBugs{
4350 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4351 },
4352 },
4353 expectedVersion: vers.version,
4354 })
4355 }
4356
4357 }
4358
4359 // If all versions are unknown, negotiation fails.
4360 testCases = append(testCases, testCase{
4361 testType: serverTest,
4362 name: "NoSupportedVersions",
4363 config: Config{
4364 Bugs: ProtocolBugs{
4365 SendSupportedVersions: []uint16{0x1111},
4366 },
4367 },
4368 shouldFail: true,
4369 expectedError: ":UNSUPPORTED_PROTOCOL:",
4370 })
4371 testCases = append(testCases, testCase{
4372 protocol: dtls,
4373 testType: serverTest,
4374 name: "NoSupportedVersions-DTLS",
4375 config: Config{
4376 Bugs: ProtocolBugs{
4377 SendSupportedVersions: []uint16{0x1111},
4378 },
4379 },
4380 shouldFail: true,
4381 expectedError: ":UNSUPPORTED_PROTOCOL:",
4382 })
4383
4384 testCases = append(testCases, testCase{
4385 testType: serverTest,
4386 name: "ClientHelloVersionTooHigh",
4387 config: Config{
4388 MaxVersion: VersionTLS13,
4389 Bugs: ProtocolBugs{
4390 SendClientVersion: 0x0304,
4391 OmitSupportedVersions: true,
4392 },
4393 },
4394 expectedVersion: VersionTLS12,
4395 })
4396
4397 testCases = append(testCases, testCase{
4398 testType: serverTest,
4399 name: "ConflictingVersionNegotiation",
4400 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004401 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004402 SendClientVersion: VersionTLS12,
4403 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004404 },
4405 },
David Benjaminad75a662016-09-30 15:42:59 -04004406 // The extension takes precedence over the ClientHello version.
4407 expectedVersion: VersionTLS11,
4408 })
4409
4410 testCases = append(testCases, testCase{
4411 testType: serverTest,
4412 name: "ConflictingVersionNegotiation-2",
4413 config: Config{
4414 Bugs: ProtocolBugs{
4415 SendClientVersion: VersionTLS11,
4416 SendSupportedVersions: []uint16{VersionTLS12},
4417 },
4418 },
4419 // The extension takes precedence over the ClientHello version.
4420 expectedVersion: VersionTLS12,
4421 })
4422
4423 testCases = append(testCases, testCase{
4424 testType: serverTest,
4425 name: "RejectFinalTLS13",
4426 config: Config{
4427 Bugs: ProtocolBugs{
4428 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4429 },
4430 },
4431 // We currently implement a draft TLS 1.3 version. Ensure that
4432 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004433 expectedVersion: VersionTLS12,
4434 })
4435
Brian Smithf85d3232016-10-28 10:34:06 -10004436 // Test that the maximum version is selected regardless of the
4437 // client-sent order.
4438 testCases = append(testCases, testCase{
4439 testType: serverTest,
4440 name: "IgnoreClientVersionOrder",
4441 config: Config{
4442 Bugs: ProtocolBugs{
4443 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4444 },
4445 },
4446 expectedVersion: VersionTLS13,
4447 })
4448
David Benjamin95c69562016-06-29 18:15:03 -04004449 // Test for version tolerance.
4450 testCases = append(testCases, testCase{
4451 testType: serverTest,
4452 name: "MinorVersionTolerance",
4453 config: Config{
4454 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004455 SendClientVersion: 0x03ff,
4456 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004457 },
4458 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004459 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004460 })
4461 testCases = append(testCases, testCase{
4462 testType: serverTest,
4463 name: "MajorVersionTolerance",
4464 config: Config{
4465 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004466 SendClientVersion: 0x0400,
4467 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004468 },
4469 },
David Benjaminad75a662016-09-30 15:42:59 -04004470 // TLS 1.3 must be negotiated with the supported_versions
4471 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004472 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004473 })
David Benjaminad75a662016-09-30 15:42:59 -04004474 testCases = append(testCases, testCase{
4475 testType: serverTest,
4476 name: "VersionTolerance-TLS13",
4477 config: Config{
4478 Bugs: ProtocolBugs{
4479 // Although TLS 1.3 does not use
4480 // ClientHello.version, it still tolerates high
4481 // values there.
4482 SendClientVersion: 0x0400,
4483 },
4484 },
4485 expectedVersion: VersionTLS13,
4486 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004487
David Benjamin95c69562016-06-29 18:15:03 -04004488 testCases = append(testCases, testCase{
4489 protocol: dtls,
4490 testType: serverTest,
4491 name: "MinorVersionTolerance-DTLS",
4492 config: Config{
4493 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004494 SendClientVersion: 0xfe00,
4495 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004496 },
4497 },
4498 expectedVersion: VersionTLS12,
4499 })
4500 testCases = append(testCases, testCase{
4501 protocol: dtls,
4502 testType: serverTest,
4503 name: "MajorVersionTolerance-DTLS",
4504 config: Config{
4505 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004506 SendClientVersion: 0xfdff,
4507 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004508 },
4509 },
4510 expectedVersion: VersionTLS12,
4511 })
4512
4513 // Test that versions below 3.0 are rejected.
4514 testCases = append(testCases, testCase{
4515 testType: serverTest,
4516 name: "VersionTooLow",
4517 config: Config{
4518 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004519 SendClientVersion: 0x0200,
4520 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004521 },
4522 },
4523 shouldFail: true,
4524 expectedError: ":UNSUPPORTED_PROTOCOL:",
4525 })
4526 testCases = append(testCases, testCase{
4527 protocol: dtls,
4528 testType: serverTest,
4529 name: "VersionTooLow-DTLS",
4530 config: Config{
4531 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004532 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004533 },
4534 },
4535 shouldFail: true,
4536 expectedError: ":UNSUPPORTED_PROTOCOL:",
4537 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004538
David Benjamin2dc02042016-09-19 19:57:37 -04004539 testCases = append(testCases, testCase{
4540 name: "ServerBogusVersion",
4541 config: Config{
4542 Bugs: ProtocolBugs{
4543 SendServerHelloVersion: 0x1234,
4544 },
4545 },
4546 shouldFail: true,
4547 expectedError: ":UNSUPPORTED_PROTOCOL:",
4548 })
4549
David Benjamin1f61f0d2016-07-10 12:20:35 -04004550 // Test TLS 1.3's downgrade signal.
4551 testCases = append(testCases, testCase{
4552 name: "Downgrade-TLS12-Client",
4553 config: Config{
4554 Bugs: ProtocolBugs{
4555 NegotiateVersion: VersionTLS12,
4556 },
4557 },
David Benjamin592b5322016-09-30 15:15:01 -04004558 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004559 // TODO(davidben): This test should fail once TLS 1.3 is final
4560 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004561 })
4562 testCases = append(testCases, testCase{
4563 testType: serverTest,
4564 name: "Downgrade-TLS12-Server",
4565 config: Config{
4566 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004567 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004568 },
4569 },
David Benjamin592b5322016-09-30 15:15:01 -04004570 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004571 // TODO(davidben): This test should fail once TLS 1.3 is final
4572 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004573 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004574}
4575
David Benjaminaccb4542014-12-12 23:44:33 -05004576func addMinimumVersionTests() {
4577 for i, shimVers := range tlsVersions {
4578 // Assemble flags to disable all older versions on the shim.
4579 var flags []string
4580 for _, vers := range tlsVersions[:i] {
4581 flags = append(flags, vers.flag)
4582 }
4583
4584 for _, runnerVers := range tlsVersions {
4585 protocols := []protocol{tls}
4586 if runnerVers.hasDTLS && shimVers.hasDTLS {
4587 protocols = append(protocols, dtls)
4588 }
4589 for _, protocol := range protocols {
4590 suffix := shimVers.name + "-" + runnerVers.name
4591 if protocol == dtls {
4592 suffix += "-DTLS"
4593 }
4594 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4595
David Benjaminaccb4542014-12-12 23:44:33 -05004596 var expectedVersion uint16
4597 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004598 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004599 if runnerVers.version >= shimVers.version {
4600 expectedVersion = runnerVers.version
4601 } else {
4602 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004603 expectedError = ":UNSUPPORTED_PROTOCOL:"
4604 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004605 }
4606
4607 testCases = append(testCases, testCase{
4608 protocol: protocol,
4609 testType: clientTest,
4610 name: "MinimumVersion-Client-" + suffix,
4611 config: Config{
4612 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004613 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004614 // Ensure the server does not decline to
4615 // select a version (versions extension) or
4616 // cipher (some ciphers depend on versions).
4617 NegotiateVersion: runnerVers.version,
4618 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004619 },
David Benjaminaccb4542014-12-12 23:44:33 -05004620 },
David Benjamin87909c02014-12-13 01:55:01 -05004621 flags: flags,
4622 expectedVersion: expectedVersion,
4623 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004624 expectedError: expectedError,
4625 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004626 })
4627 testCases = append(testCases, testCase{
4628 protocol: protocol,
4629 testType: clientTest,
4630 name: "MinimumVersion-Client2-" + suffix,
4631 config: Config{
4632 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004633 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004634 // Ensure the server does not decline to
4635 // select a version (versions extension) or
4636 // cipher (some ciphers depend on versions).
4637 NegotiateVersion: runnerVers.version,
4638 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004639 },
David Benjaminaccb4542014-12-12 23:44:33 -05004640 },
David Benjamin87909c02014-12-13 01:55:01 -05004641 flags: []string{"-min-version", shimVersFlag},
4642 expectedVersion: expectedVersion,
4643 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004644 expectedError: expectedError,
4645 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004646 })
4647
4648 testCases = append(testCases, testCase{
4649 protocol: protocol,
4650 testType: serverTest,
4651 name: "MinimumVersion-Server-" + suffix,
4652 config: Config{
4653 MaxVersion: runnerVers.version,
4654 },
David Benjamin87909c02014-12-13 01:55:01 -05004655 flags: flags,
4656 expectedVersion: expectedVersion,
4657 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004658 expectedError: expectedError,
4659 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004660 })
4661 testCases = append(testCases, testCase{
4662 protocol: protocol,
4663 testType: serverTest,
4664 name: "MinimumVersion-Server2-" + suffix,
4665 config: Config{
4666 MaxVersion: runnerVers.version,
4667 },
David Benjamin87909c02014-12-13 01:55:01 -05004668 flags: []string{"-min-version", shimVersFlag},
4669 expectedVersion: expectedVersion,
4670 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004671 expectedError: expectedError,
4672 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004673 })
4674 }
4675 }
4676 }
4677}
4678
David Benjamine78bfde2014-09-06 12:45:15 -04004679func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004680 // TODO(davidben): Extensions, where applicable, all move their server
4681 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4682 // tests for both. Also test interaction with 0-RTT when implemented.
4683
David Benjamin97d17d92016-07-14 16:12:00 -04004684 // Repeat extensions tests all versions except SSL 3.0.
4685 for _, ver := range tlsVersions {
4686 if ver.version == VersionSSL30 {
4687 continue
4688 }
4689
David Benjamin97d17d92016-07-14 16:12:00 -04004690 // Test that duplicate extensions are rejected.
4691 testCases = append(testCases, testCase{
4692 testType: clientTest,
4693 name: "DuplicateExtensionClient-" + ver.name,
4694 config: Config{
4695 MaxVersion: ver.version,
4696 Bugs: ProtocolBugs{
4697 DuplicateExtension: true,
4698 },
David Benjamine78bfde2014-09-06 12:45:15 -04004699 },
David Benjamin97d17d92016-07-14 16:12:00 -04004700 shouldFail: true,
4701 expectedLocalError: "remote error: error decoding message",
4702 })
4703 testCases = append(testCases, testCase{
4704 testType: serverTest,
4705 name: "DuplicateExtensionServer-" + ver.name,
4706 config: Config{
4707 MaxVersion: ver.version,
4708 Bugs: ProtocolBugs{
4709 DuplicateExtension: true,
4710 },
David Benjamine78bfde2014-09-06 12:45:15 -04004711 },
David Benjamin97d17d92016-07-14 16:12:00 -04004712 shouldFail: true,
4713 expectedLocalError: "remote error: error decoding message",
4714 })
4715
4716 // Test SNI.
4717 testCases = append(testCases, testCase{
4718 testType: clientTest,
4719 name: "ServerNameExtensionClient-" + ver.name,
4720 config: Config{
4721 MaxVersion: ver.version,
4722 Bugs: ProtocolBugs{
4723 ExpectServerName: "example.com",
4724 },
David Benjamine78bfde2014-09-06 12:45:15 -04004725 },
David Benjamin97d17d92016-07-14 16:12:00 -04004726 flags: []string{"-host-name", "example.com"},
4727 })
4728 testCases = append(testCases, testCase{
4729 testType: clientTest,
4730 name: "ServerNameExtensionClientMismatch-" + ver.name,
4731 config: Config{
4732 MaxVersion: ver.version,
4733 Bugs: ProtocolBugs{
4734 ExpectServerName: "mismatch.com",
4735 },
David Benjamine78bfde2014-09-06 12:45:15 -04004736 },
David Benjamin97d17d92016-07-14 16:12:00 -04004737 flags: []string{"-host-name", "example.com"},
4738 shouldFail: true,
4739 expectedLocalError: "tls: unexpected server name",
4740 })
4741 testCases = append(testCases, testCase{
4742 testType: clientTest,
4743 name: "ServerNameExtensionClientMissing-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 Bugs: ProtocolBugs{
4747 ExpectServerName: "missing.com",
4748 },
David Benjamine78bfde2014-09-06 12:45:15 -04004749 },
David Benjamin97d17d92016-07-14 16:12:00 -04004750 shouldFail: true,
4751 expectedLocalError: "tls: unexpected server name",
4752 })
4753 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05004754 testType: clientTest,
4755 name: "TolerateServerNameAck-" + ver.name,
4756 config: Config{
4757 MaxVersion: ver.version,
4758 Bugs: ProtocolBugs{
4759 SendServerNameAck: true,
4760 },
4761 },
4762 flags: []string{"-host-name", "example.com"},
4763 resumeSession: true,
4764 })
4765 testCases = append(testCases, testCase{
4766 testType: clientTest,
4767 name: "UnsolicitedServerNameAck-" + ver.name,
4768 config: Config{
4769 MaxVersion: ver.version,
4770 Bugs: ProtocolBugs{
4771 SendServerNameAck: true,
4772 },
4773 },
4774 shouldFail: true,
4775 expectedError: ":UNEXPECTED_EXTENSION:",
4776 expectedLocalError: "remote error: unsupported extension",
4777 })
4778 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004779 testType: serverTest,
4780 name: "ServerNameExtensionServer-" + ver.name,
4781 config: Config{
4782 MaxVersion: ver.version,
4783 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004784 },
David Benjamin97d17d92016-07-14 16:12:00 -04004785 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004786 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004787 })
4788
4789 // Test ALPN.
4790 testCases = append(testCases, testCase{
4791 testType: clientTest,
4792 name: "ALPNClient-" + ver.name,
4793 config: Config{
4794 MaxVersion: ver.version,
4795 NextProtos: []string{"foo"},
4796 },
4797 flags: []string{
4798 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4799 "-expect-alpn", "foo",
4800 },
4801 expectedNextProto: "foo",
4802 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004803 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004804 })
4805 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004806 testType: clientTest,
4807 name: "ALPNClient-Mismatch-" + ver.name,
4808 config: Config{
4809 MaxVersion: ver.version,
4810 Bugs: ProtocolBugs{
4811 SendALPN: "baz",
4812 },
4813 },
4814 flags: []string{
4815 "-advertise-alpn", "\x03foo\x03bar",
4816 },
4817 shouldFail: true,
4818 expectedError: ":INVALID_ALPN_PROTOCOL:",
4819 expectedLocalError: "remote error: illegal parameter",
4820 })
4821 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004822 testType: serverTest,
4823 name: "ALPNServer-" + ver.name,
4824 config: Config{
4825 MaxVersion: ver.version,
4826 NextProtos: []string{"foo", "bar", "baz"},
4827 },
4828 flags: []string{
4829 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4830 "-select-alpn", "foo",
4831 },
4832 expectedNextProto: "foo",
4833 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004834 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004835 })
4836 testCases = append(testCases, testCase{
4837 testType: serverTest,
4838 name: "ALPNServer-Decline-" + ver.name,
4839 config: Config{
4840 MaxVersion: ver.version,
4841 NextProtos: []string{"foo", "bar", "baz"},
4842 },
4843 flags: []string{"-decline-alpn"},
4844 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004845 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004846 })
4847
David Benjamin25fe85b2016-08-09 20:00:32 -04004848 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4849 // called once.
4850 testCases = append(testCases, testCase{
4851 testType: serverTest,
4852 name: "ALPNServer-Async-" + ver.name,
4853 config: Config{
4854 MaxVersion: ver.version,
4855 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004856 // Prior to TLS 1.3, exercise the asynchronous session callback.
4857 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004858 },
4859 flags: []string{
4860 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4861 "-select-alpn", "foo",
4862 "-async",
4863 },
4864 expectedNextProto: "foo",
4865 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004866 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004867 })
4868
David Benjamin97d17d92016-07-14 16:12:00 -04004869 var emptyString string
4870 testCases = append(testCases, testCase{
4871 testType: clientTest,
4872 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4873 config: Config{
4874 MaxVersion: ver.version,
4875 NextProtos: []string{""},
4876 Bugs: ProtocolBugs{
4877 // A server returning an empty ALPN protocol
4878 // should be rejected.
4879 ALPNProtocol: &emptyString,
4880 },
4881 },
4882 flags: []string{
4883 "-advertise-alpn", "\x03foo",
4884 },
4885 shouldFail: true,
4886 expectedError: ":PARSE_TLSEXT:",
4887 })
4888 testCases = append(testCases, testCase{
4889 testType: serverTest,
4890 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4891 config: Config{
4892 MaxVersion: ver.version,
4893 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004894 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004895 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004896 },
David Benjamin97d17d92016-07-14 16:12:00 -04004897 flags: []string{
4898 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004899 },
David Benjamin97d17d92016-07-14 16:12:00 -04004900 shouldFail: true,
4901 expectedError: ":PARSE_TLSEXT:",
4902 })
4903
4904 // Test NPN and the interaction with ALPN.
4905 if ver.version < VersionTLS13 {
4906 // Test that the server prefers ALPN over NPN.
4907 testCases = append(testCases, testCase{
4908 testType: serverTest,
4909 name: "ALPNServer-Preferred-" + ver.name,
4910 config: Config{
4911 MaxVersion: ver.version,
4912 NextProtos: []string{"foo", "bar", "baz"},
4913 },
4914 flags: []string{
4915 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4916 "-select-alpn", "foo",
4917 "-advertise-npn", "\x03foo\x03bar\x03baz",
4918 },
4919 expectedNextProto: "foo",
4920 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004921 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004922 })
4923 testCases = append(testCases, testCase{
4924 testType: serverTest,
4925 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4926 config: Config{
4927 MaxVersion: ver.version,
4928 NextProtos: []string{"foo", "bar", "baz"},
4929 Bugs: ProtocolBugs{
4930 SwapNPNAndALPN: true,
4931 },
4932 },
4933 flags: []string{
4934 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4935 "-select-alpn", "foo",
4936 "-advertise-npn", "\x03foo\x03bar\x03baz",
4937 },
4938 expectedNextProto: "foo",
4939 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004940 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004941 })
4942
4943 // Test that negotiating both NPN and ALPN is forbidden.
4944 testCases = append(testCases, testCase{
4945 name: "NegotiateALPNAndNPN-" + ver.name,
4946 config: Config{
4947 MaxVersion: ver.version,
4948 NextProtos: []string{"foo", "bar", "baz"},
4949 Bugs: ProtocolBugs{
4950 NegotiateALPNAndNPN: true,
4951 },
4952 },
4953 flags: []string{
4954 "-advertise-alpn", "\x03foo",
4955 "-select-next-proto", "foo",
4956 },
4957 shouldFail: true,
4958 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4959 })
4960 testCases = append(testCases, testCase{
4961 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4962 config: Config{
4963 MaxVersion: ver.version,
4964 NextProtos: []string{"foo", "bar", "baz"},
4965 Bugs: ProtocolBugs{
4966 NegotiateALPNAndNPN: true,
4967 SwapNPNAndALPN: true,
4968 },
4969 },
4970 flags: []string{
4971 "-advertise-alpn", "\x03foo",
4972 "-select-next-proto", "foo",
4973 },
4974 shouldFail: true,
4975 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4976 })
David Benjamin97d17d92016-07-14 16:12:00 -04004977 }
4978
4979 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004980
4981 // Resume with a corrupt ticket.
4982 testCases = append(testCases, testCase{
4983 testType: serverTest,
4984 name: "CorruptTicket-" + ver.name,
4985 config: Config{
4986 MaxVersion: ver.version,
4987 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004988 FilterTicket: func(in []byte) ([]byte, error) {
4989 in[len(in)-1] ^= 1
4990 return in, nil
4991 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004992 },
4993 },
4994 resumeSession: true,
4995 expectResumeRejected: true,
4996 })
4997 // Test the ticket callback, with and without renewal.
4998 testCases = append(testCases, testCase{
4999 testType: serverTest,
5000 name: "TicketCallback-" + ver.name,
5001 config: Config{
5002 MaxVersion: ver.version,
5003 },
5004 resumeSession: true,
5005 flags: []string{"-use-ticket-callback"},
5006 })
5007 testCases = append(testCases, testCase{
5008 testType: serverTest,
5009 name: "TicketCallback-Renew-" + ver.name,
5010 config: Config{
5011 MaxVersion: ver.version,
5012 Bugs: ProtocolBugs{
5013 ExpectNewTicket: true,
5014 },
5015 },
5016 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5017 resumeSession: true,
5018 })
5019
5020 // Test that the ticket callback is only called once when everything before
5021 // it in the ClientHello is asynchronous. This corrupts the ticket so
5022 // certificate selection callbacks run.
5023 testCases = append(testCases, testCase{
5024 testType: serverTest,
5025 name: "TicketCallback-SingleCall-" + ver.name,
5026 config: Config{
5027 MaxVersion: ver.version,
5028 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005029 FilterTicket: func(in []byte) ([]byte, error) {
5030 in[len(in)-1] ^= 1
5031 return in, nil
5032 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005033 },
5034 },
5035 resumeSession: true,
5036 expectResumeRejected: true,
5037 flags: []string{
5038 "-use-ticket-callback",
5039 "-async",
5040 },
5041 })
5042
5043 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005044 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005045 testCases = append(testCases, testCase{
5046 testType: serverTest,
5047 name: "OversizedSessionId-" + ver.name,
5048 config: Config{
5049 MaxVersion: ver.version,
5050 Bugs: ProtocolBugs{
5051 OversizedSessionId: true,
5052 },
5053 },
5054 resumeSession: true,
5055 shouldFail: true,
5056 expectedError: ":DECODE_ERROR:",
5057 })
5058 }
5059
5060 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5061 // are ignored.
5062 if ver.hasDTLS {
5063 testCases = append(testCases, testCase{
5064 protocol: dtls,
5065 name: "SRTP-Client-" + ver.name,
5066 config: Config{
5067 MaxVersion: ver.version,
5068 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5069 },
5070 flags: []string{
5071 "-srtp-profiles",
5072 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5073 },
5074 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5075 })
5076 testCases = append(testCases, testCase{
5077 protocol: dtls,
5078 testType: serverTest,
5079 name: "SRTP-Server-" + ver.name,
5080 config: Config{
5081 MaxVersion: ver.version,
5082 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5083 },
5084 flags: []string{
5085 "-srtp-profiles",
5086 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5087 },
5088 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5089 })
5090 // Test that the MKI is ignored.
5091 testCases = append(testCases, testCase{
5092 protocol: dtls,
5093 testType: serverTest,
5094 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5095 config: Config{
5096 MaxVersion: ver.version,
5097 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5098 Bugs: ProtocolBugs{
5099 SRTPMasterKeyIdentifer: "bogus",
5100 },
5101 },
5102 flags: []string{
5103 "-srtp-profiles",
5104 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5105 },
5106 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5107 })
5108 // Test that SRTP isn't negotiated on the server if there were
5109 // no matching profiles.
5110 testCases = append(testCases, testCase{
5111 protocol: dtls,
5112 testType: serverTest,
5113 name: "SRTP-Server-NoMatch-" + ver.name,
5114 config: Config{
5115 MaxVersion: ver.version,
5116 SRTPProtectionProfiles: []uint16{100, 101, 102},
5117 },
5118 flags: []string{
5119 "-srtp-profiles",
5120 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5121 },
5122 expectedSRTPProtectionProfile: 0,
5123 })
5124 // Test that the server returning an invalid SRTP profile is
5125 // flagged as an error by the client.
5126 testCases = append(testCases, testCase{
5127 protocol: dtls,
5128 name: "SRTP-Client-NoMatch-" + ver.name,
5129 config: Config{
5130 MaxVersion: ver.version,
5131 Bugs: ProtocolBugs{
5132 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5133 },
5134 },
5135 flags: []string{
5136 "-srtp-profiles",
5137 "SRTP_AES128_CM_SHA1_80",
5138 },
5139 shouldFail: true,
5140 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5141 })
5142 }
5143
5144 // Test SCT list.
5145 testCases = append(testCases, testCase{
5146 name: "SignedCertificateTimestampList-Client-" + ver.name,
5147 testType: clientTest,
5148 config: Config{
5149 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005150 },
David Benjamin97d17d92016-07-14 16:12:00 -04005151 flags: []string{
5152 "-enable-signed-cert-timestamps",
5153 "-expect-signed-cert-timestamps",
5154 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005155 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005156 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005157 })
David Benjamindaa88502016-10-04 16:32:16 -04005158
Adam Langleycfa08c32016-11-17 13:21:27 -08005159 var differentSCTList []byte
5160 differentSCTList = append(differentSCTList, testSCTList...)
5161 differentSCTList[len(differentSCTList)-1] ^= 1
5162
David Benjamindaa88502016-10-04 16:32:16 -04005163 // The SCT extension did not specify that it must only be sent on resumption as it
5164 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005165 testCases = append(testCases, testCase{
5166 name: "SendSCTListOnResume-" + ver.name,
5167 config: Config{
5168 MaxVersion: ver.version,
5169 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005170 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005171 },
David Benjamind98452d2015-06-16 14:16:23 -04005172 },
David Benjamin97d17d92016-07-14 16:12:00 -04005173 flags: []string{
5174 "-enable-signed-cert-timestamps",
5175 "-expect-signed-cert-timestamps",
5176 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005177 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005178 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005179 })
David Benjamindaa88502016-10-04 16:32:16 -04005180
David Benjamin97d17d92016-07-14 16:12:00 -04005181 testCases = append(testCases, testCase{
5182 name: "SignedCertificateTimestampList-Server-" + ver.name,
5183 testType: serverTest,
5184 config: Config{
5185 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005186 },
David Benjamin97d17d92016-07-14 16:12:00 -04005187 flags: []string{
5188 "-signed-cert-timestamps",
5189 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005190 },
David Benjamin97d17d92016-07-14 16:12:00 -04005191 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005192 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005193 })
David Benjamin53210cb2016-11-16 09:01:48 +09005194
Adam Langleycfa08c32016-11-17 13:21:27 -08005195 emptySCTListCert := *testCerts[0].cert
5196 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5197
5198 // Test empty SCT list.
5199 testCases = append(testCases, testCase{
5200 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5201 testType: clientTest,
5202 config: Config{
5203 MaxVersion: ver.version,
5204 Certificates: []Certificate{emptySCTListCert},
5205 },
5206 flags: []string{
5207 "-enable-signed-cert-timestamps",
5208 },
5209 shouldFail: true,
5210 expectedError: ":ERROR_PARSING_EXTENSION:",
5211 })
5212
5213 emptySCTCert := *testCerts[0].cert
5214 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5215
5216 // Test empty SCT in non-empty list.
5217 testCases = append(testCases, testCase{
5218 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5219 testType: clientTest,
5220 config: Config{
5221 MaxVersion: ver.version,
5222 Certificates: []Certificate{emptySCTCert},
5223 },
5224 flags: []string{
5225 "-enable-signed-cert-timestamps",
5226 },
5227 shouldFail: true,
5228 expectedError: ":ERROR_PARSING_EXTENSION:",
5229 })
5230
David Benjamin53210cb2016-11-16 09:01:48 +09005231 // Test that certificate-related extensions are not sent unsolicited.
5232 testCases = append(testCases, testCase{
5233 testType: serverTest,
5234 name: "UnsolicitedCertificateExtensions-" + ver.name,
5235 config: Config{
5236 MaxVersion: ver.version,
5237 Bugs: ProtocolBugs{
5238 NoOCSPStapling: true,
5239 NoSignedCertificateTimestamps: true,
5240 },
5241 },
5242 flags: []string{
5243 "-ocsp-response",
5244 base64.StdEncoding.EncodeToString(testOCSPResponse),
5245 "-signed-cert-timestamps",
5246 base64.StdEncoding.EncodeToString(testSCTList),
5247 },
5248 })
David Benjamin97d17d92016-07-14 16:12:00 -04005249 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005250
Paul Lietar4fac72e2015-09-09 13:44:55 +01005251 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005252 testType: clientTest,
5253 name: "ClientHelloPadding",
5254 config: Config{
5255 Bugs: ProtocolBugs{
5256 RequireClientHelloSize: 512,
5257 },
5258 },
5259 // This hostname just needs to be long enough to push the
5260 // ClientHello into F5's danger zone between 256 and 511 bytes
5261 // long.
5262 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5263 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005264
5265 // Extensions should not function in SSL 3.0.
5266 testCases = append(testCases, testCase{
5267 testType: serverTest,
5268 name: "SSLv3Extensions-NoALPN",
5269 config: Config{
5270 MaxVersion: VersionSSL30,
5271 NextProtos: []string{"foo", "bar", "baz"},
5272 },
5273 flags: []string{
5274 "-select-alpn", "foo",
5275 },
5276 expectNoNextProto: true,
5277 })
5278
5279 // Test session tickets separately as they follow a different codepath.
5280 testCases = append(testCases, testCase{
5281 testType: serverTest,
5282 name: "SSLv3Extensions-NoTickets",
5283 config: Config{
5284 MaxVersion: VersionSSL30,
5285 Bugs: ProtocolBugs{
5286 // Historically, session tickets in SSL 3.0
5287 // failed in different ways depending on whether
5288 // the client supported renegotiation_info.
5289 NoRenegotiationInfo: true,
5290 },
5291 },
5292 resumeSession: true,
5293 })
5294 testCases = append(testCases, testCase{
5295 testType: serverTest,
5296 name: "SSLv3Extensions-NoTickets2",
5297 config: Config{
5298 MaxVersion: VersionSSL30,
5299 },
5300 resumeSession: true,
5301 })
5302
5303 // But SSL 3.0 does send and process renegotiation_info.
5304 testCases = append(testCases, testCase{
5305 testType: serverTest,
5306 name: "SSLv3Extensions-RenegotiationInfo",
5307 config: Config{
5308 MaxVersion: VersionSSL30,
5309 Bugs: ProtocolBugs{
5310 RequireRenegotiationInfo: true,
5311 },
5312 },
David Benjamind2610042017-01-03 10:49:28 -05005313 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005314 })
5315 testCases = append(testCases, testCase{
5316 testType: serverTest,
5317 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5318 config: Config{
5319 MaxVersion: VersionSSL30,
5320 Bugs: ProtocolBugs{
5321 NoRenegotiationInfo: true,
5322 SendRenegotiationSCSV: true,
5323 RequireRenegotiationInfo: true,
5324 },
5325 },
David Benjamind2610042017-01-03 10:49:28 -05005326 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005327 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005328
5329 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5330 // in ServerHello.
5331 testCases = append(testCases, testCase{
5332 name: "NPN-Forbidden-TLS13",
5333 config: Config{
5334 MaxVersion: VersionTLS13,
5335 NextProtos: []string{"foo"},
5336 Bugs: ProtocolBugs{
5337 NegotiateNPNAtAllVersions: true,
5338 },
5339 },
5340 flags: []string{"-select-next-proto", "foo"},
5341 shouldFail: true,
5342 expectedError: ":ERROR_PARSING_EXTENSION:",
5343 })
5344 testCases = append(testCases, testCase{
5345 name: "EMS-Forbidden-TLS13",
5346 config: Config{
5347 MaxVersion: VersionTLS13,
5348 Bugs: ProtocolBugs{
5349 NegotiateEMSAtAllVersions: true,
5350 },
5351 },
5352 shouldFail: true,
5353 expectedError: ":ERROR_PARSING_EXTENSION:",
5354 })
5355 testCases = append(testCases, testCase{
5356 name: "RenegotiationInfo-Forbidden-TLS13",
5357 config: Config{
5358 MaxVersion: VersionTLS13,
5359 Bugs: ProtocolBugs{
5360 NegotiateRenegotiationInfoAtAllVersions: true,
5361 },
5362 },
5363 shouldFail: true,
5364 expectedError: ":ERROR_PARSING_EXTENSION:",
5365 })
5366 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005367 name: "Ticket-Forbidden-TLS13",
5368 config: Config{
5369 MaxVersion: VersionTLS12,
5370 },
5371 resumeConfig: &Config{
5372 MaxVersion: VersionTLS13,
5373 Bugs: ProtocolBugs{
5374 AdvertiseTicketExtension: true,
5375 },
5376 },
5377 resumeSession: true,
5378 shouldFail: true,
5379 expectedError: ":ERROR_PARSING_EXTENSION:",
5380 })
5381
5382 // Test that illegal extensions in TLS 1.3 are declined by the server if
5383 // offered in ClientHello. The runner's server will fail if this occurs,
5384 // so we exercise the offering path. (EMS and Renegotiation Info are
5385 // implicit in every test.)
5386 testCases = append(testCases, testCase{
5387 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005388 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005389 config: Config{
5390 MaxVersion: VersionTLS13,
5391 NextProtos: []string{"bar"},
5392 },
5393 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5394 })
David Benjamin196df5b2016-09-21 16:23:27 -04005395
David Benjamindaa88502016-10-04 16:32:16 -04005396 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5397 // tolerated.
5398 testCases = append(testCases, testCase{
5399 name: "SendOCSPResponseOnResume-TLS12",
5400 config: Config{
5401 MaxVersion: VersionTLS12,
5402 Bugs: ProtocolBugs{
5403 SendOCSPResponseOnResume: []byte("bogus"),
5404 },
5405 },
5406 flags: []string{
5407 "-enable-ocsp-stapling",
5408 "-expect-ocsp-response",
5409 base64.StdEncoding.EncodeToString(testOCSPResponse),
5410 },
5411 resumeSession: true,
5412 })
5413
David Benjamindaa88502016-10-04 16:32:16 -04005414 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005415 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005416 config: Config{
5417 MaxVersion: VersionTLS13,
5418 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005419 SendExtensionOnCertificate: testOCSPExtension,
5420 },
5421 },
5422 shouldFail: true,
5423 expectedError: ":UNEXPECTED_EXTENSION:",
5424 })
5425
5426 testCases = append(testCases, testCase{
5427 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5428 config: Config{
5429 MaxVersion: VersionTLS13,
5430 Bugs: ProtocolBugs{
5431 SendExtensionOnCertificate: testSCTExtension,
5432 },
5433 },
5434 shouldFail: true,
5435 expectedError: ":UNEXPECTED_EXTENSION:",
5436 })
5437
5438 // Test that extensions on client certificates are never accepted.
5439 testCases = append(testCases, testCase{
5440 name: "SendExtensionOnClientCertificate-TLS13",
5441 testType: serverTest,
5442 config: Config{
5443 MaxVersion: VersionTLS13,
5444 Certificates: []Certificate{rsaCertificate},
5445 Bugs: ProtocolBugs{
5446 SendExtensionOnCertificate: testOCSPExtension,
5447 },
5448 },
5449 flags: []string{
5450 "-enable-ocsp-stapling",
5451 "-require-any-client-certificate",
5452 },
5453 shouldFail: true,
5454 expectedError: ":UNEXPECTED_EXTENSION:",
5455 })
5456
5457 testCases = append(testCases, testCase{
5458 name: "SendUnknownExtensionOnCertificate-TLS13",
5459 config: Config{
5460 MaxVersion: VersionTLS13,
5461 Bugs: ProtocolBugs{
5462 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5463 },
5464 },
5465 shouldFail: true,
5466 expectedError: ":UNEXPECTED_EXTENSION:",
5467 })
5468
Adam Langleycfa08c32016-11-17 13:21:27 -08005469 var differentSCTList []byte
5470 differentSCTList = append(differentSCTList, testSCTList...)
5471 differentSCTList[len(differentSCTList)-1] ^= 1
5472
Steven Valdeza833c352016-11-01 13:39:36 -04005473 // Test that extensions on intermediates are allowed but ignored.
5474 testCases = append(testCases, testCase{
5475 name: "IgnoreExtensionsOnIntermediates-TLS13",
5476 config: Config{
5477 MaxVersion: VersionTLS13,
5478 Certificates: []Certificate{rsaChainCertificate},
5479 Bugs: ProtocolBugs{
5480 // Send different values on the intermediate. This tests
5481 // the intermediate's extensions do not override the
5482 // leaf's.
5483 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005484 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005485 },
5486 },
5487 flags: []string{
5488 "-enable-ocsp-stapling",
5489 "-expect-ocsp-response",
5490 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005491 "-enable-signed-cert-timestamps",
5492 "-expect-signed-cert-timestamps",
5493 base64.StdEncoding.EncodeToString(testSCTList),
5494 },
5495 resumeSession: true,
5496 })
5497
5498 // Test that extensions are not sent on intermediates when configured
5499 // only for a leaf.
5500 testCases = append(testCases, testCase{
5501 testType: serverTest,
5502 name: "SendNoExtensionsOnIntermediate-TLS13",
5503 config: Config{
5504 MaxVersion: VersionTLS13,
5505 Bugs: ProtocolBugs{
5506 ExpectNoExtensionsOnIntermediate: true,
5507 },
5508 },
5509 flags: []string{
5510 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5511 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5512 "-ocsp-response",
5513 base64.StdEncoding.EncodeToString(testOCSPResponse),
5514 "-signed-cert-timestamps",
5515 base64.StdEncoding.EncodeToString(testSCTList),
5516 },
5517 })
5518
5519 // Test that extensions are not sent on client certificates.
5520 testCases = append(testCases, testCase{
5521 name: "SendNoClientCertificateExtensions-TLS13",
5522 config: Config{
5523 MaxVersion: VersionTLS13,
5524 ClientAuth: RequireAnyClientCert,
5525 },
5526 flags: []string{
5527 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5528 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5529 "-ocsp-response",
5530 base64.StdEncoding.EncodeToString(testOCSPResponse),
5531 "-signed-cert-timestamps",
5532 base64.StdEncoding.EncodeToString(testSCTList),
5533 },
5534 })
5535
5536 testCases = append(testCases, testCase{
5537 name: "SendDuplicateExtensionsOnCerts-TLS13",
5538 config: Config{
5539 MaxVersion: VersionTLS13,
5540 Bugs: ProtocolBugs{
5541 SendDuplicateCertExtensions: true,
5542 },
5543 },
5544 flags: []string{
5545 "-enable-ocsp-stapling",
5546 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005547 },
5548 resumeSession: true,
5549 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005550 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005551 })
Adam Langley9b885c52016-11-18 14:21:03 -08005552
5553 testCases = append(testCases, testCase{
5554 name: "SignedCertificateTimestampListInvalid-Server",
5555 testType: serverTest,
5556 flags: []string{
5557 "-signed-cert-timestamps",
5558 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5559 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005560 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005561 expectedError: ":INVALID_SCT_LIST:",
5562 })
David Benjamine78bfde2014-09-06 12:45:15 -04005563}
5564
David Benjamin01fe8202014-09-24 15:21:44 -04005565func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005566 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005567 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005568 // SSL 3.0 does not have tickets and TLS 1.3 does not
5569 // have session IDs, so skip their cross-resumption
5570 // tests.
5571 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5572 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5573 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005574 }
5575
David Benjamin8b8c0062014-11-23 02:47:52 -05005576 protocols := []protocol{tls}
5577 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5578 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005579 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005580 for _, protocol := range protocols {
5581 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5582 if protocol == dtls {
5583 suffix += "-DTLS"
5584 }
5585
David Benjaminece3de92015-03-16 18:02:20 -04005586 if sessionVers.version == resumeVers.version {
5587 testCases = append(testCases, testCase{
5588 protocol: protocol,
5589 name: "Resume-Client" + suffix,
5590 resumeSession: true,
5591 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005592 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005593 Bugs: ProtocolBugs{
5594 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5595 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5596 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005597 },
David Benjaminece3de92015-03-16 18:02:20 -04005598 expectedVersion: sessionVers.version,
5599 expectedResumeVersion: resumeVers.version,
5600 })
5601 } else {
David Benjamin405da482016-08-08 17:25:07 -04005602 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5603
5604 // Offering a TLS 1.3 session sends an empty session ID, so
5605 // there is no way to convince a non-lookahead client the
5606 // session was resumed. It will appear to the client that a
5607 // stray ChangeCipherSpec was sent.
5608 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5609 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005610 }
5611
David Benjaminece3de92015-03-16 18:02:20 -04005612 testCases = append(testCases, testCase{
5613 protocol: protocol,
5614 name: "Resume-Client-Mismatch" + suffix,
5615 resumeSession: true,
5616 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005617 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005618 },
David Benjaminece3de92015-03-16 18:02:20 -04005619 expectedVersion: sessionVers.version,
5620 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005621 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005622 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005623 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005624 },
5625 },
5626 expectedResumeVersion: resumeVers.version,
5627 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005628 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005629 })
5630 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005631
5632 testCases = append(testCases, testCase{
5633 protocol: protocol,
5634 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005635 resumeSession: true,
5636 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005637 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005638 },
5639 expectedVersion: sessionVers.version,
5640 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005641 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005642 },
5643 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005644 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005645 expectedResumeVersion: resumeVers.version,
5646 })
5647
David Benjamin8b8c0062014-11-23 02:47:52 -05005648 testCases = append(testCases, testCase{
5649 protocol: protocol,
5650 testType: serverTest,
5651 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005652 resumeSession: true,
5653 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005654 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005655 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005656 expectedVersion: sessionVers.version,
5657 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005658 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005659 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005660 Bugs: ProtocolBugs{
5661 SendBothTickets: true,
5662 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005663 },
5664 expectedResumeVersion: resumeVers.version,
5665 })
5666 }
David Benjamin01fe8202014-09-24 15:21:44 -04005667 }
5668 }
David Benjaminece3de92015-03-16 18:02:20 -04005669
David Benjamin4199b0d2016-11-01 13:58:25 -04005670 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005671 testCases = append(testCases, testCase{
5672 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005673 name: "ShimTicketRewritable",
5674 resumeSession: true,
5675 config: Config{
5676 MaxVersion: VersionTLS12,
5677 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5678 Bugs: ProtocolBugs{
5679 FilterTicket: func(in []byte) ([]byte, error) {
5680 in, err := SetShimTicketVersion(in, VersionTLS12)
5681 if err != nil {
5682 return nil, err
5683 }
5684 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5685 },
5686 },
5687 },
5688 flags: []string{
5689 "-ticket-key",
5690 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5691 },
5692 })
5693
5694 // Resumptions are declined if the version does not match.
5695 testCases = append(testCases, testCase{
5696 testType: serverTest,
5697 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005698 resumeSession: true,
5699 config: Config{
5700 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005701 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005702 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005703 FilterTicket: func(in []byte) ([]byte, error) {
5704 return SetShimTicketVersion(in, VersionTLS13)
5705 },
5706 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005707 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005708 flags: []string{
5709 "-ticket-key",
5710 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5711 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005712 expectResumeRejected: true,
5713 })
5714
5715 testCases = append(testCases, testCase{
5716 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005717 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005718 resumeSession: true,
5719 config: Config{
5720 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005721 Bugs: ProtocolBugs{
5722 FilterTicket: func(in []byte) ([]byte, error) {
5723 return SetShimTicketVersion(in, VersionTLS12)
5724 },
5725 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005726 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005727 flags: []string{
5728 "-ticket-key",
5729 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5730 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005731 expectResumeRejected: true,
5732 })
5733
David Benjamin4199b0d2016-11-01 13:58:25 -04005734 // Resumptions are declined if the cipher is invalid or disabled.
5735 testCases = append(testCases, testCase{
5736 testType: serverTest,
5737 name: "Resume-Server-DeclineBadCipher",
5738 resumeSession: true,
5739 config: Config{
5740 MaxVersion: VersionTLS12,
5741 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005742 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005743 FilterTicket: func(in []byte) ([]byte, error) {
5744 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5745 },
5746 },
5747 },
5748 flags: []string{
5749 "-ticket-key",
5750 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5751 },
5752 expectResumeRejected: true,
5753 })
5754
5755 testCases = append(testCases, testCase{
5756 testType: serverTest,
5757 name: "Resume-Server-DeclineBadCipher-2",
5758 resumeSession: true,
5759 config: Config{
5760 MaxVersion: VersionTLS12,
5761 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005762 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005763 FilterTicket: func(in []byte) ([]byte, error) {
5764 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5765 },
5766 },
5767 },
5768 flags: []string{
5769 "-cipher", "AES128",
5770 "-ticket-key",
5771 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5772 },
5773 expectResumeRejected: true,
5774 })
5775
David Benjaminf01f42a2016-11-16 19:05:33 +09005776 // Sessions are not resumed if they do not use the preferred cipher.
5777 testCases = append(testCases, testCase{
5778 testType: serverTest,
5779 name: "Resume-Server-CipherNotPreferred",
5780 resumeSession: true,
5781 config: Config{
5782 MaxVersion: VersionTLS12,
5783 Bugs: ProtocolBugs{
5784 ExpectNewTicket: true,
5785 FilterTicket: func(in []byte) ([]byte, error) {
5786 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5787 },
5788 },
5789 },
5790 flags: []string{
5791 "-ticket-key",
5792 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5793 },
5794 shouldFail: false,
5795 expectResumeRejected: true,
5796 })
5797
5798 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5799 // PRF hashes match, but BoringSSL will always decline such resumptions.
5800 testCases = append(testCases, testCase{
5801 testType: serverTest,
5802 name: "Resume-Server-CipherNotPreferred-TLS13",
5803 resumeSession: true,
5804 config: Config{
5805 MaxVersion: VersionTLS13,
5806 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5807 Bugs: ProtocolBugs{
5808 FilterTicket: func(in []byte) ([]byte, error) {
5809 // If the client (runner) offers ChaCha20-Poly1305 first, the
5810 // server (shim) always prefers it. Switch it to AES-GCM.
5811 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5812 },
5813 },
5814 },
5815 flags: []string{
5816 "-ticket-key",
5817 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5818 },
5819 shouldFail: false,
5820 expectResumeRejected: true,
5821 })
5822
5823 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005824 testCases = append(testCases, testCase{
5825 testType: serverTest,
5826 name: "Resume-Server-DeclineBadCipher-TLS13",
5827 resumeSession: true,
5828 config: Config{
5829 MaxVersion: VersionTLS13,
5830 Bugs: ProtocolBugs{
5831 FilterTicket: func(in []byte) ([]byte, error) {
5832 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5833 },
5834 },
5835 },
5836 flags: []string{
5837 "-ticket-key",
5838 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5839 },
5840 expectResumeRejected: true,
5841 })
5842
David Benjaminf01f42a2016-11-16 19:05:33 +09005843 // If the client does not offer the cipher from the session, decline to
5844 // resume. Clients are forbidden from doing this, but BoringSSL selects
5845 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005846 testCases = append(testCases, testCase{
5847 testType: serverTest,
5848 name: "Resume-Server-UnofferedCipher",
5849 resumeSession: true,
5850 config: Config{
5851 MaxVersion: VersionTLS12,
5852 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5853 },
5854 resumeConfig: &Config{
5855 MaxVersion: VersionTLS12,
5856 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5857 Bugs: ProtocolBugs{
5858 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5859 },
5860 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005861 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005862 })
5863
David Benjaminf01f42a2016-11-16 19:05:33 +09005864 // In TLS 1.3, clients may advertise a cipher list which does not
5865 // include the selected cipher. Test that we tolerate this. Servers may
5866 // resume at another cipher if the PRF matches, but BoringSSL will
5867 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005868 testCases = append(testCases, testCase{
5869 testType: serverTest,
5870 name: "Resume-Server-UnofferedCipher-TLS13",
5871 resumeSession: true,
5872 config: Config{
5873 MaxVersion: VersionTLS13,
5874 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5875 },
5876 resumeConfig: &Config{
5877 MaxVersion: VersionTLS13,
5878 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5879 Bugs: ProtocolBugs{
5880 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5881 },
5882 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005883 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005884 })
5885
David Benjamin4199b0d2016-11-01 13:58:25 -04005886 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005887 testCases = append(testCases, testCase{
5888 name: "Resume-Client-CipherMismatch",
5889 resumeSession: true,
5890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005891 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005892 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5893 },
5894 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005895 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005896 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5897 Bugs: ProtocolBugs{
5898 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5899 },
5900 },
5901 shouldFail: true,
5902 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5903 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005904
David Benjamine1cc35e2016-11-16 16:25:58 +09005905 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5906 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005907 testCases = append(testCases, testCase{
5908 name: "Resume-Client-CipherMismatch-TLS13",
5909 resumeSession: true,
5910 config: Config{
5911 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005912 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005913 },
5914 resumeConfig: &Config{
5915 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005916 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5917 },
5918 })
5919
5920 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5921 testCases = append(testCases, testCase{
5922 name: "Resume-Client-PRFMismatch-TLS13",
5923 resumeSession: true,
5924 config: Config{
5925 MaxVersion: VersionTLS13,
5926 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5927 },
5928 resumeConfig: &Config{
5929 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005930 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005931 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005932 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005933 },
5934 },
5935 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005936 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005937 })
Steven Valdeza833c352016-11-01 13:39:36 -04005938
5939 testCases = append(testCases, testCase{
5940 testType: serverTest,
5941 name: "Resume-Server-BinderWrongLength",
5942 resumeSession: true,
5943 config: Config{
5944 MaxVersion: VersionTLS13,
5945 Bugs: ProtocolBugs{
5946 SendShortPSKBinder: true,
5947 },
5948 },
5949 shouldFail: true,
5950 expectedLocalError: "remote error: error decrypting message",
5951 expectedError: ":DIGEST_CHECK_FAILED:",
5952 })
5953
5954 testCases = append(testCases, testCase{
5955 testType: serverTest,
5956 name: "Resume-Server-NoPSKBinder",
5957 resumeSession: true,
5958 config: Config{
5959 MaxVersion: VersionTLS13,
5960 Bugs: ProtocolBugs{
5961 SendNoPSKBinder: true,
5962 },
5963 },
5964 shouldFail: true,
5965 expectedLocalError: "remote error: error decoding message",
5966 expectedError: ":DECODE_ERROR:",
5967 })
5968
5969 testCases = append(testCases, testCase{
5970 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005971 name: "Resume-Server-ExtraPSKBinder",
5972 resumeSession: true,
5973 config: Config{
5974 MaxVersion: VersionTLS13,
5975 Bugs: ProtocolBugs{
5976 SendExtraPSKBinder: true,
5977 },
5978 },
5979 shouldFail: true,
5980 expectedLocalError: "remote error: illegal parameter",
5981 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5982 })
5983
5984 testCases = append(testCases, testCase{
5985 testType: serverTest,
5986 name: "Resume-Server-ExtraIdentityNoBinder",
5987 resumeSession: true,
5988 config: Config{
5989 MaxVersion: VersionTLS13,
5990 Bugs: ProtocolBugs{
5991 ExtraPSKIdentity: true,
5992 },
5993 },
5994 shouldFail: true,
5995 expectedLocalError: "remote error: illegal parameter",
5996 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5997 })
5998
5999 testCases = append(testCases, testCase{
6000 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006001 name: "Resume-Server-InvalidPSKBinder",
6002 resumeSession: true,
6003 config: Config{
6004 MaxVersion: VersionTLS13,
6005 Bugs: ProtocolBugs{
6006 SendInvalidPSKBinder: true,
6007 },
6008 },
6009 shouldFail: true,
6010 expectedLocalError: "remote error: error decrypting message",
6011 expectedError: ":DIGEST_CHECK_FAILED:",
6012 })
6013
6014 testCases = append(testCases, testCase{
6015 testType: serverTest,
6016 name: "Resume-Server-PSKBinderFirstExtension",
6017 resumeSession: true,
6018 config: Config{
6019 MaxVersion: VersionTLS13,
6020 Bugs: ProtocolBugs{
6021 PSKBinderFirst: true,
6022 },
6023 },
6024 shouldFail: true,
6025 expectedLocalError: "remote error: illegal parameter",
6026 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6027 })
David Benjamin01fe8202014-09-24 15:21:44 -04006028}
6029
Adam Langley2ae77d22014-10-28 17:29:33 -07006030func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006031 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006032 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006033 testType: serverTest,
6034 name: "Renegotiate-Server-Forbidden",
6035 config: Config{
6036 MaxVersion: VersionTLS12,
6037 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006038 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006039 shouldFail: true,
6040 expectedError: ":NO_RENEGOTIATION:",
6041 expectedLocalError: "remote error: no renegotiation",
6042 })
Adam Langley5021b222015-06-12 18:27:58 -07006043 // The server shouldn't echo the renegotiation extension unless
6044 // requested by the client.
6045 testCases = append(testCases, testCase{
6046 testType: serverTest,
6047 name: "Renegotiate-Server-NoExt",
6048 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006049 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006050 Bugs: ProtocolBugs{
6051 NoRenegotiationInfo: true,
6052 RequireRenegotiationInfo: true,
6053 },
6054 },
6055 shouldFail: true,
6056 expectedLocalError: "renegotiation extension missing",
6057 })
6058 // The renegotiation SCSV should be sufficient for the server to echo
6059 // the extension.
6060 testCases = append(testCases, testCase{
6061 testType: serverTest,
6062 name: "Renegotiate-Server-NoExt-SCSV",
6063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006064 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006065 Bugs: ProtocolBugs{
6066 NoRenegotiationInfo: true,
6067 SendRenegotiationSCSV: true,
6068 RequireRenegotiationInfo: true,
6069 },
6070 },
6071 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006072 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006073 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006074 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006075 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006076 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006077 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006078 },
6079 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006080 renegotiate: 1,
6081 flags: []string{
6082 "-renegotiate-freely",
6083 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006084 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006085 },
David Benjamincdea40c2015-03-19 14:09:43 -04006086 })
6087 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006088 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006089 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006091 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006092 Bugs: ProtocolBugs{
6093 EmptyRenegotiationInfo: true,
6094 },
6095 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006096 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006097 shouldFail: true,
6098 expectedError: ":RENEGOTIATION_MISMATCH:",
6099 })
6100 testCases = append(testCases, testCase{
6101 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006102 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006104 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006105 Bugs: ProtocolBugs{
6106 BadRenegotiationInfo: true,
6107 },
6108 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006109 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006110 shouldFail: true,
6111 expectedError: ":RENEGOTIATION_MISMATCH:",
6112 })
6113 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006114 name: "Renegotiate-Client-Downgrade",
6115 renegotiate: 1,
6116 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006117 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006118 Bugs: ProtocolBugs{
6119 NoRenegotiationInfoAfterInitial: true,
6120 },
6121 },
6122 flags: []string{"-renegotiate-freely"},
6123 shouldFail: true,
6124 expectedError: ":RENEGOTIATION_MISMATCH:",
6125 })
6126 testCases = append(testCases, testCase{
6127 name: "Renegotiate-Client-Upgrade",
6128 renegotiate: 1,
6129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006130 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006131 Bugs: ProtocolBugs{
6132 NoRenegotiationInfoInInitial: true,
6133 },
6134 },
6135 flags: []string{"-renegotiate-freely"},
6136 shouldFail: true,
6137 expectedError: ":RENEGOTIATION_MISMATCH:",
6138 })
6139 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006140 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006141 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006142 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006143 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006144 Bugs: ProtocolBugs{
6145 NoRenegotiationInfo: true,
6146 },
6147 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006148 flags: []string{
6149 "-renegotiate-freely",
6150 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006151 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006152 },
David Benjamincff0b902015-05-15 23:09:47 -04006153 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006154
6155 // Test that the server may switch ciphers on renegotiation without
6156 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006157 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006158 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006159 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006160 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006161 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006162 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006163 },
6164 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006165 flags: []string{
6166 "-renegotiate-freely",
6167 "-expect-total-renegotiations", "1",
6168 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006169 })
6170 testCases = append(testCases, testCase{
6171 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006172 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006173 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006174 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006175 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6176 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006177 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006178 flags: []string{
6179 "-renegotiate-freely",
6180 "-expect-total-renegotiations", "1",
6181 },
David Benjaminb16346b2015-04-08 19:16:58 -04006182 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006183
6184 // Test that the server may not switch versions on renegotiation.
6185 testCases = append(testCases, testCase{
6186 name: "Renegotiate-Client-SwitchVersion",
6187 config: Config{
6188 MaxVersion: VersionTLS12,
6189 // Pick a cipher which exists at both versions.
6190 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6191 Bugs: ProtocolBugs{
6192 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006193 // Avoid failing early at the record layer.
6194 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006195 },
6196 },
6197 renegotiate: 1,
6198 flags: []string{
6199 "-renegotiate-freely",
6200 "-expect-total-renegotiations", "1",
6201 },
6202 shouldFail: true,
6203 expectedError: ":WRONG_SSL_VERSION:",
6204 })
6205
David Benjaminb16346b2015-04-08 19:16:58 -04006206 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006207 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006208 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006209 config: Config{
6210 MaxVersion: VersionTLS10,
6211 Bugs: ProtocolBugs{
6212 RequireSameRenegoClientVersion: true,
6213 },
6214 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006215 flags: []string{
6216 "-renegotiate-freely",
6217 "-expect-total-renegotiations", "1",
6218 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006219 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006220 testCases = append(testCases, testCase{
6221 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006222 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006223 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006224 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006225 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6226 NextProtos: []string{"foo"},
6227 },
6228 flags: []string{
6229 "-false-start",
6230 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006231 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006232 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006233 },
6234 shimWritesFirst: true,
6235 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006236
6237 // Client-side renegotiation controls.
6238 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006239 name: "Renegotiate-Client-Forbidden-1",
6240 config: Config{
6241 MaxVersion: VersionTLS12,
6242 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006243 renegotiate: 1,
6244 shouldFail: true,
6245 expectedError: ":NO_RENEGOTIATION:",
6246 expectedLocalError: "remote error: no renegotiation",
6247 })
6248 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006249 name: "Renegotiate-Client-Once-1",
6250 config: Config{
6251 MaxVersion: VersionTLS12,
6252 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006253 renegotiate: 1,
6254 flags: []string{
6255 "-renegotiate-once",
6256 "-expect-total-renegotiations", "1",
6257 },
6258 })
6259 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006260 name: "Renegotiate-Client-Freely-1",
6261 config: Config{
6262 MaxVersion: VersionTLS12,
6263 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006264 renegotiate: 1,
6265 flags: []string{
6266 "-renegotiate-freely",
6267 "-expect-total-renegotiations", "1",
6268 },
6269 })
6270 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006271 name: "Renegotiate-Client-Once-2",
6272 config: Config{
6273 MaxVersion: VersionTLS12,
6274 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006275 renegotiate: 2,
6276 flags: []string{"-renegotiate-once"},
6277 shouldFail: true,
6278 expectedError: ":NO_RENEGOTIATION:",
6279 expectedLocalError: "remote error: no renegotiation",
6280 })
6281 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006282 name: "Renegotiate-Client-Freely-2",
6283 config: Config{
6284 MaxVersion: VersionTLS12,
6285 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006286 renegotiate: 2,
6287 flags: []string{
6288 "-renegotiate-freely",
6289 "-expect-total-renegotiations", "2",
6290 },
6291 })
Adam Langley27a0d082015-11-03 13:34:10 -08006292 testCases = append(testCases, testCase{
6293 name: "Renegotiate-Client-NoIgnore",
6294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006295 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006296 Bugs: ProtocolBugs{
6297 SendHelloRequestBeforeEveryAppDataRecord: true,
6298 },
6299 },
6300 shouldFail: true,
6301 expectedError: ":NO_RENEGOTIATION:",
6302 })
6303 testCases = append(testCases, testCase{
6304 name: "Renegotiate-Client-Ignore",
6305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006306 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006307 Bugs: ProtocolBugs{
6308 SendHelloRequestBeforeEveryAppDataRecord: true,
6309 },
6310 },
6311 flags: []string{
6312 "-renegotiate-ignore",
6313 "-expect-total-renegotiations", "0",
6314 },
6315 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006316
David Benjamin34941c02016-10-08 11:45:31 -04006317 // Renegotiation is not allowed at SSL 3.0.
6318 testCases = append(testCases, testCase{
6319 name: "Renegotiate-Client-SSL3",
6320 config: Config{
6321 MaxVersion: VersionSSL30,
6322 },
6323 renegotiate: 1,
6324 flags: []string{
6325 "-renegotiate-freely",
6326 "-expect-total-renegotiations", "1",
6327 },
6328 shouldFail: true,
6329 expectedError: ":NO_RENEGOTIATION:",
6330 expectedLocalError: "remote error: no renegotiation",
6331 })
6332
David Benjamina1eaba12017-01-01 23:19:22 -05006333 // Renegotiation is not allowed when there is an unfinished write.
6334 testCases = append(testCases, testCase{
6335 name: "Renegotiate-Client-UnfinishedWrite",
6336 config: Config{
6337 MaxVersion: VersionTLS12,
6338 },
6339 renegotiate: 1,
6340 flags: []string{
6341 "-async",
6342 "-renegotiate-freely",
6343 "-read-with-unfinished-write",
6344 },
6345 shouldFail: true,
6346 expectedError: ":NO_RENEGOTIATION:",
6347 // We do not successfully send the no_renegotiation alert in
6348 // this case. https://crbug.com/boringssl/130
6349 })
6350
David Benjamin397c8e62016-07-08 14:14:36 -07006351 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006352 testCases = append(testCases, testCase{
6353 name: "StrayHelloRequest",
6354 config: Config{
6355 MaxVersion: VersionTLS12,
6356 Bugs: ProtocolBugs{
6357 SendHelloRequestBeforeEveryHandshakeMessage: true,
6358 },
6359 },
6360 })
6361 testCases = append(testCases, testCase{
6362 name: "StrayHelloRequest-Packed",
6363 config: Config{
6364 MaxVersion: VersionTLS12,
6365 Bugs: ProtocolBugs{
6366 PackHandshakeFlight: true,
6367 SendHelloRequestBeforeEveryHandshakeMessage: true,
6368 },
6369 },
6370 })
6371
David Benjamin12d2c482016-07-24 10:56:51 -04006372 // Test renegotiation works if HelloRequest and server Finished come in
6373 // the same record.
6374 testCases = append(testCases, testCase{
6375 name: "Renegotiate-Client-Packed",
6376 config: Config{
6377 MaxVersion: VersionTLS12,
6378 Bugs: ProtocolBugs{
6379 PackHandshakeFlight: true,
6380 PackHelloRequestWithFinished: true,
6381 },
6382 },
6383 renegotiate: 1,
6384 flags: []string{
6385 "-renegotiate-freely",
6386 "-expect-total-renegotiations", "1",
6387 },
6388 })
6389
David Benjamin397c8e62016-07-08 14:14:36 -07006390 // Renegotiation is forbidden in TLS 1.3.
6391 testCases = append(testCases, testCase{
6392 name: "Renegotiate-Client-TLS13",
6393 config: Config{
6394 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006395 Bugs: ProtocolBugs{
6396 SendHelloRequestBeforeEveryAppDataRecord: true,
6397 },
David Benjamin397c8e62016-07-08 14:14:36 -07006398 },
David Benjamin397c8e62016-07-08 14:14:36 -07006399 flags: []string{
6400 "-renegotiate-freely",
6401 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006402 shouldFail: true,
6403 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006404 })
6405
6406 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6407 testCases = append(testCases, testCase{
6408 name: "StrayHelloRequest-TLS13",
6409 config: Config{
6410 MaxVersion: VersionTLS13,
6411 Bugs: ProtocolBugs{
6412 SendHelloRequestBeforeEveryHandshakeMessage: true,
6413 },
6414 },
6415 shouldFail: true,
6416 expectedError: ":UNEXPECTED_MESSAGE:",
6417 })
David Benjamind2610042017-01-03 10:49:28 -05006418
6419 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6420 // always reads as supporting it, regardless of whether it was
6421 // negotiated.
6422 testCases = append(testCases, testCase{
6423 name: "AlwaysReportRenegotiationInfo-TLS13",
6424 config: Config{
6425 MaxVersion: VersionTLS13,
6426 Bugs: ProtocolBugs{
6427 NoRenegotiationInfo: true,
6428 },
6429 },
6430 flags: []string{
6431 "-expect-secure-renegotiation",
6432 },
6433 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006434}
6435
David Benjamin5e961c12014-11-07 01:48:35 -05006436func addDTLSReplayTests() {
6437 // Test that sequence number replays are detected.
6438 testCases = append(testCases, testCase{
6439 protocol: dtls,
6440 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006441 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006442 replayWrites: true,
6443 })
6444
David Benjamin8e6db492015-07-25 18:29:23 -04006445 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006446 // than the retransmit window.
6447 testCases = append(testCases, testCase{
6448 protocol: dtls,
6449 name: "DTLS-Replay-LargeGaps",
6450 config: Config{
6451 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006452 SequenceNumberMapping: func(in uint64) uint64 {
6453 return in * 127
6454 },
David Benjamin5e961c12014-11-07 01:48:35 -05006455 },
6456 },
David Benjamin8e6db492015-07-25 18:29:23 -04006457 messageCount: 200,
6458 replayWrites: true,
6459 })
6460
6461 // Test the incoming sequence number changing non-monotonically.
6462 testCases = append(testCases, testCase{
6463 protocol: dtls,
6464 name: "DTLS-Replay-NonMonotonic",
6465 config: Config{
6466 Bugs: ProtocolBugs{
6467 SequenceNumberMapping: func(in uint64) uint64 {
6468 return in ^ 31
6469 },
6470 },
6471 },
6472 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006473 replayWrites: true,
6474 })
6475}
6476
Nick Harper60edffd2016-06-21 15:19:24 -07006477var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006478 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006479 id signatureAlgorithm
6480 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006481}{
Nick Harper60edffd2016-06-21 15:19:24 -07006482 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6483 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6484 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6485 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006486 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006487 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6488 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6489 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006490 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6491 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6492 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006493 // Tests for key types prior to TLS 1.2.
6494 {"RSA", 0, testCertRSA},
6495 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006496}
6497
Nick Harper60edffd2016-06-21 15:19:24 -07006498const fakeSigAlg1 signatureAlgorithm = 0x2a01
6499const fakeSigAlg2 signatureAlgorithm = 0xff01
6500
6501func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006502 // Not all ciphers involve a signature. Advertise a list which gives all
6503 // versions a signing cipher.
6504 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006505 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006506 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6507 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6508 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6509 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6510 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6511 }
6512
David Benjaminca3d5452016-07-14 12:51:01 -04006513 var allAlgorithms []signatureAlgorithm
6514 for _, alg := range testSignatureAlgorithms {
6515 if alg.id != 0 {
6516 allAlgorithms = append(allAlgorithms, alg.id)
6517 }
6518 }
6519
Nick Harper60edffd2016-06-21 15:19:24 -07006520 // Make sure each signature algorithm works. Include some fake values in
6521 // the list and ensure they're ignored.
6522 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006523 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006524 if (ver.version < VersionTLS12) != (alg.id == 0) {
6525 continue
6526 }
6527
6528 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6529 // or remove it in C.
6530 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006531 continue
6532 }
Nick Harper60edffd2016-06-21 15:19:24 -07006533
David Benjamin3ef76972016-10-17 17:59:54 -04006534 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006535 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006536 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006537 shouldSignFail = true
6538 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006539 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006540 // RSA-PKCS1 does not exist in TLS 1.3.
6541 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006542 shouldSignFail = true
6543 shouldVerifyFail = true
6544 }
6545
6546 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6547 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6548 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006549 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006550
6551 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006552 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006553 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006554 }
6555 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006556 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006557 }
David Benjamin000800a2014-11-14 01:43:59 -05006558
David Benjamin1fb125c2016-07-08 18:52:12 -07006559 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006560
David Benjamin7a41d372016-07-09 11:21:54 -07006561 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006562 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006563 config: Config{
6564 MaxVersion: ver.version,
6565 ClientAuth: RequireAnyClientCert,
6566 VerifySignatureAlgorithms: []signatureAlgorithm{
6567 fakeSigAlg1,
6568 alg.id,
6569 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006570 },
David Benjamin7a41d372016-07-09 11:21:54 -07006571 },
6572 flags: []string{
6573 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6574 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6575 "-enable-all-curves",
6576 },
David Benjamin3ef76972016-10-17 17:59:54 -04006577 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006578 expectedError: signError,
6579 expectedPeerSignatureAlgorithm: alg.id,
6580 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006581
David Benjamin7a41d372016-07-09 11:21:54 -07006582 testCases = append(testCases, testCase{
6583 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006584 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006585 config: Config{
6586 MaxVersion: ver.version,
6587 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6588 SignSignatureAlgorithms: []signatureAlgorithm{
6589 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006590 },
David Benjamin7a41d372016-07-09 11:21:54 -07006591 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006592 SkipECDSACurveCheck: shouldVerifyFail,
6593 IgnoreSignatureVersionChecks: shouldVerifyFail,
6594 // Some signature algorithms may not be advertised.
6595 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006596 },
David Benjamin7a41d372016-07-09 11:21:54 -07006597 },
6598 flags: []string{
6599 "-require-any-client-certificate",
6600 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6601 "-enable-all-curves",
6602 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006603 // Resume the session to assert the peer signature
6604 // algorithm is reported on both handshakes.
6605 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006606 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006607 expectedError: verifyError,
6608 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006609
6610 testCases = append(testCases, testCase{
6611 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006612 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006613 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006614 MaxVersion: ver.version,
6615 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006616 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006617 fakeSigAlg1,
6618 alg.id,
6619 fakeSigAlg2,
6620 },
6621 },
6622 flags: []string{
6623 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6624 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6625 "-enable-all-curves",
6626 },
David Benjamin3ef76972016-10-17 17:59:54 -04006627 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006628 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006629 expectedPeerSignatureAlgorithm: alg.id,
6630 })
6631
6632 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006633 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006634 config: Config{
6635 MaxVersion: ver.version,
6636 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006637 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006638 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006639 alg.id,
6640 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006641 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006642 SkipECDSACurveCheck: shouldVerifyFail,
6643 IgnoreSignatureVersionChecks: shouldVerifyFail,
6644 // Some signature algorithms may not be advertised.
6645 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006646 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006647 },
6648 flags: []string{
6649 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6650 "-enable-all-curves",
6651 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006652 // Resume the session to assert the peer signature
6653 // algorithm is reported on both handshakes.
6654 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006655 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006656 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006657 })
David Benjamin5208fd42016-07-13 21:43:25 -04006658
David Benjamin3ef76972016-10-17 17:59:54 -04006659 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006660 testCases = append(testCases, testCase{
6661 testType: serverTest,
6662 name: "ClientAuth-InvalidSignature" + suffix,
6663 config: Config{
6664 MaxVersion: ver.version,
6665 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6666 SignSignatureAlgorithms: []signatureAlgorithm{
6667 alg.id,
6668 },
6669 Bugs: ProtocolBugs{
6670 InvalidSignature: true,
6671 },
6672 },
6673 flags: []string{
6674 "-require-any-client-certificate",
6675 "-enable-all-curves",
6676 },
6677 shouldFail: true,
6678 expectedError: ":BAD_SIGNATURE:",
6679 })
6680
6681 testCases = append(testCases, testCase{
6682 name: "ServerAuth-InvalidSignature" + suffix,
6683 config: Config{
6684 MaxVersion: ver.version,
6685 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6686 CipherSuites: signingCiphers,
6687 SignSignatureAlgorithms: []signatureAlgorithm{
6688 alg.id,
6689 },
6690 Bugs: ProtocolBugs{
6691 InvalidSignature: true,
6692 },
6693 },
6694 flags: []string{"-enable-all-curves"},
6695 shouldFail: true,
6696 expectedError: ":BAD_SIGNATURE:",
6697 })
6698 }
David Benjaminca3d5452016-07-14 12:51:01 -04006699
David Benjamin3ef76972016-10-17 17:59:54 -04006700 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006701 testCases = append(testCases, testCase{
6702 name: "ClientAuth-Sign-Negotiate" + suffix,
6703 config: Config{
6704 MaxVersion: ver.version,
6705 ClientAuth: RequireAnyClientCert,
6706 VerifySignatureAlgorithms: allAlgorithms,
6707 },
6708 flags: []string{
6709 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6710 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6711 "-enable-all-curves",
6712 "-signing-prefs", strconv.Itoa(int(alg.id)),
6713 },
6714 expectedPeerSignatureAlgorithm: alg.id,
6715 })
6716
6717 testCases = append(testCases, testCase{
6718 testType: serverTest,
6719 name: "ServerAuth-Sign-Negotiate" + suffix,
6720 config: Config{
6721 MaxVersion: ver.version,
6722 CipherSuites: signingCiphers,
6723 VerifySignatureAlgorithms: allAlgorithms,
6724 },
6725 flags: []string{
6726 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6727 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6728 "-enable-all-curves",
6729 "-signing-prefs", strconv.Itoa(int(alg.id)),
6730 },
6731 expectedPeerSignatureAlgorithm: alg.id,
6732 })
6733 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006734 }
David Benjamin000800a2014-11-14 01:43:59 -05006735 }
6736
Nick Harper60edffd2016-06-21 15:19:24 -07006737 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006738 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006739 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006740 config: Config{
6741 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006742 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006743 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006744 signatureECDSAWithP521AndSHA512,
6745 signatureRSAPKCS1WithSHA384,
6746 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006747 },
6748 },
6749 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006750 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6751 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006752 },
Nick Harper60edffd2016-06-21 15:19:24 -07006753 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006754 })
6755
6756 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006757 name: "ClientAuth-SignatureType-TLS13",
6758 config: Config{
6759 ClientAuth: RequireAnyClientCert,
6760 MaxVersion: VersionTLS13,
6761 VerifySignatureAlgorithms: []signatureAlgorithm{
6762 signatureECDSAWithP521AndSHA512,
6763 signatureRSAPKCS1WithSHA384,
6764 signatureRSAPSSWithSHA384,
6765 signatureECDSAWithSHA1,
6766 },
6767 },
6768 flags: []string{
6769 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6770 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6771 },
6772 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6773 })
6774
6775 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006776 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006777 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006778 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006779 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006780 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
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 },
Nick Harper60edffd2016-06-21 15:19:24 -07006787 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006788 })
6789
Steven Valdez143e8b32016-07-11 13:19:03 -04006790 testCases = append(testCases, testCase{
6791 testType: serverTest,
6792 name: "ServerAuth-SignatureType-TLS13",
6793 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006794 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006795 VerifySignatureAlgorithms: []signatureAlgorithm{
6796 signatureECDSAWithP521AndSHA512,
6797 signatureRSAPKCS1WithSHA384,
6798 signatureRSAPSSWithSHA384,
6799 signatureECDSAWithSHA1,
6800 },
6801 },
6802 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6803 })
6804
David Benjamina95e9f32016-07-08 16:28:04 -07006805 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006806 testCases = append(testCases, testCase{
6807 testType: serverTest,
6808 name: "Verify-ClientAuth-SignatureType",
6809 config: Config{
6810 MaxVersion: VersionTLS12,
6811 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006812 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006813 signatureRSAPKCS1WithSHA256,
6814 },
6815 Bugs: ProtocolBugs{
6816 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6817 },
6818 },
6819 flags: []string{
6820 "-require-any-client-certificate",
6821 },
6822 shouldFail: true,
6823 expectedError: ":WRONG_SIGNATURE_TYPE:",
6824 })
6825
6826 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006827 testType: serverTest,
6828 name: "Verify-ClientAuth-SignatureType-TLS13",
6829 config: Config{
6830 MaxVersion: VersionTLS13,
6831 Certificates: []Certificate{rsaCertificate},
6832 SignSignatureAlgorithms: []signatureAlgorithm{
6833 signatureRSAPSSWithSHA256,
6834 },
6835 Bugs: ProtocolBugs{
6836 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6837 },
6838 },
6839 flags: []string{
6840 "-require-any-client-certificate",
6841 },
6842 shouldFail: true,
6843 expectedError: ":WRONG_SIGNATURE_TYPE:",
6844 })
6845
6846 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006847 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006848 config: Config{
6849 MaxVersion: VersionTLS12,
6850 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006851 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006852 signatureRSAPKCS1WithSHA256,
6853 },
6854 Bugs: ProtocolBugs{
6855 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6856 },
6857 },
6858 shouldFail: true,
6859 expectedError: ":WRONG_SIGNATURE_TYPE:",
6860 })
6861
Steven Valdez143e8b32016-07-11 13:19:03 -04006862 testCases = append(testCases, testCase{
6863 name: "Verify-ServerAuth-SignatureType-TLS13",
6864 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006865 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006866 SignSignatureAlgorithms: []signatureAlgorithm{
6867 signatureRSAPSSWithSHA256,
6868 },
6869 Bugs: ProtocolBugs{
6870 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6871 },
6872 },
6873 shouldFail: true,
6874 expectedError: ":WRONG_SIGNATURE_TYPE:",
6875 })
6876
David Benjamin51dd7d62016-07-08 16:07:01 -07006877 // Test that, if the list is missing, the peer falls back to SHA-1 in
6878 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006879 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006880 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006881 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006882 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006883 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006884 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006885 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006886 },
6887 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006888 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006889 },
6890 },
6891 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006892 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6893 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006894 },
6895 })
6896
6897 testCases = append(testCases, testCase{
6898 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006899 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006900 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006901 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006902 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006903 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006904 },
6905 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006906 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006907 },
6908 },
David Benjaminee32bea2016-08-17 13:36:44 -04006909 flags: []string{
6910 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6911 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6912 },
6913 })
6914
6915 testCases = append(testCases, testCase{
6916 name: "ClientAuth-SHA1-Fallback-ECDSA",
6917 config: Config{
6918 MaxVersion: VersionTLS12,
6919 ClientAuth: RequireAnyClientCert,
6920 VerifySignatureAlgorithms: []signatureAlgorithm{
6921 signatureECDSAWithSHA1,
6922 },
6923 Bugs: ProtocolBugs{
6924 NoSignatureAlgorithms: true,
6925 },
6926 },
6927 flags: []string{
6928 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6929 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6930 },
6931 })
6932
6933 testCases = append(testCases, testCase{
6934 testType: serverTest,
6935 name: "ServerAuth-SHA1-Fallback-ECDSA",
6936 config: Config{
6937 MaxVersion: VersionTLS12,
6938 VerifySignatureAlgorithms: []signatureAlgorithm{
6939 signatureECDSAWithSHA1,
6940 },
6941 Bugs: ProtocolBugs{
6942 NoSignatureAlgorithms: true,
6943 },
6944 },
6945 flags: []string{
6946 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6947 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6948 },
David Benjamin000800a2014-11-14 01:43:59 -05006949 })
David Benjamin72dc7832015-03-16 17:49:43 -04006950
David Benjamin51dd7d62016-07-08 16:07:01 -07006951 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006952 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006953 config: Config{
6954 MaxVersion: VersionTLS13,
6955 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006956 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006957 signatureRSAPKCS1WithSHA1,
6958 },
6959 Bugs: ProtocolBugs{
6960 NoSignatureAlgorithms: true,
6961 },
6962 },
6963 flags: []string{
6964 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6965 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6966 },
David Benjamin48901652016-08-01 12:12:47 -04006967 shouldFail: true,
6968 // An empty CertificateRequest signature algorithm list is a
6969 // syntax error in TLS 1.3.
6970 expectedError: ":DECODE_ERROR:",
6971 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006972 })
6973
6974 testCases = append(testCases, testCase{
6975 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006976 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006977 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006978 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006979 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006980 signatureRSAPKCS1WithSHA1,
6981 },
6982 Bugs: ProtocolBugs{
6983 NoSignatureAlgorithms: true,
6984 },
6985 },
6986 shouldFail: true,
6987 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6988 })
6989
David Benjaminb62d2872016-07-18 14:55:02 +02006990 // Test that hash preferences are enforced. BoringSSL does not implement
6991 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006992 testCases = append(testCases, testCase{
6993 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006994 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006995 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006996 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006997 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006998 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006999 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007000 },
7001 Bugs: ProtocolBugs{
7002 IgnorePeerSignatureAlgorithmPreferences: true,
7003 },
7004 },
7005 flags: []string{"-require-any-client-certificate"},
7006 shouldFail: true,
7007 expectedError: ":WRONG_SIGNATURE_TYPE:",
7008 })
7009
7010 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007011 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007012 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007013 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007014 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007015 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007016 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007017 },
7018 Bugs: ProtocolBugs{
7019 IgnorePeerSignatureAlgorithmPreferences: true,
7020 },
7021 },
7022 shouldFail: true,
7023 expectedError: ":WRONG_SIGNATURE_TYPE:",
7024 })
David Benjaminb62d2872016-07-18 14:55:02 +02007025 testCases = append(testCases, testCase{
7026 testType: serverTest,
7027 name: "ClientAuth-Enforced-TLS13",
7028 config: Config{
7029 MaxVersion: VersionTLS13,
7030 Certificates: []Certificate{rsaCertificate},
7031 SignSignatureAlgorithms: []signatureAlgorithm{
7032 signatureRSAPKCS1WithMD5,
7033 },
7034 Bugs: ProtocolBugs{
7035 IgnorePeerSignatureAlgorithmPreferences: true,
7036 IgnoreSignatureVersionChecks: true,
7037 },
7038 },
7039 flags: []string{"-require-any-client-certificate"},
7040 shouldFail: true,
7041 expectedError: ":WRONG_SIGNATURE_TYPE:",
7042 })
7043
7044 testCases = append(testCases, testCase{
7045 name: "ServerAuth-Enforced-TLS13",
7046 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007047 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007048 SignSignatureAlgorithms: []signatureAlgorithm{
7049 signatureRSAPKCS1WithMD5,
7050 },
7051 Bugs: ProtocolBugs{
7052 IgnorePeerSignatureAlgorithmPreferences: true,
7053 IgnoreSignatureVersionChecks: true,
7054 },
7055 },
7056 shouldFail: true,
7057 expectedError: ":WRONG_SIGNATURE_TYPE:",
7058 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007059
7060 // Test that the agreed upon digest respects the client preferences and
7061 // the server digests.
7062 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007063 name: "NoCommonAlgorithms-Digests",
7064 config: Config{
7065 MaxVersion: VersionTLS12,
7066 ClientAuth: RequireAnyClientCert,
7067 VerifySignatureAlgorithms: []signatureAlgorithm{
7068 signatureRSAPKCS1WithSHA512,
7069 signatureRSAPKCS1WithSHA1,
7070 },
7071 },
7072 flags: []string{
7073 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7074 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7075 "-digest-prefs", "SHA256",
7076 },
7077 shouldFail: true,
7078 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7079 })
7080 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007081 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007082 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007083 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007084 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007085 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007086 signatureRSAPKCS1WithSHA512,
7087 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007088 },
7089 },
7090 flags: []string{
7091 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7092 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007093 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007094 },
David Benjaminca3d5452016-07-14 12:51:01 -04007095 shouldFail: true,
7096 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7097 })
7098 testCases = append(testCases, testCase{
7099 name: "NoCommonAlgorithms-TLS13",
7100 config: Config{
7101 MaxVersion: VersionTLS13,
7102 ClientAuth: RequireAnyClientCert,
7103 VerifySignatureAlgorithms: []signatureAlgorithm{
7104 signatureRSAPSSWithSHA512,
7105 signatureRSAPSSWithSHA384,
7106 },
7107 },
7108 flags: []string{
7109 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7110 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7111 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7112 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007113 shouldFail: true,
7114 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007115 })
7116 testCases = append(testCases, testCase{
7117 name: "Agree-Digest-SHA256",
7118 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007119 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007120 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007121 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007122 signatureRSAPKCS1WithSHA1,
7123 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007124 },
7125 },
7126 flags: []string{
7127 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7128 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007129 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007130 },
Nick Harper60edffd2016-06-21 15:19:24 -07007131 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007132 })
7133 testCases = append(testCases, testCase{
7134 name: "Agree-Digest-SHA1",
7135 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007136 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007137 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007138 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007139 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007140 },
7141 },
7142 flags: []string{
7143 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7144 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007145 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007146 },
Nick Harper60edffd2016-06-21 15:19:24 -07007147 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007148 })
7149 testCases = append(testCases, testCase{
7150 name: "Agree-Digest-Default",
7151 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007152 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007153 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007154 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007155 signatureRSAPKCS1WithSHA256,
7156 signatureECDSAWithP256AndSHA256,
7157 signatureRSAPKCS1WithSHA1,
7158 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007159 },
7160 },
7161 flags: []string{
7162 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7163 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7164 },
Nick Harper60edffd2016-06-21 15:19:24 -07007165 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007166 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007167
David Benjaminca3d5452016-07-14 12:51:01 -04007168 // Test that the signing preference list may include extra algorithms
7169 // without negotiation problems.
7170 testCases = append(testCases, testCase{
7171 testType: serverTest,
7172 name: "FilterExtraAlgorithms",
7173 config: Config{
7174 MaxVersion: VersionTLS12,
7175 VerifySignatureAlgorithms: []signatureAlgorithm{
7176 signatureRSAPKCS1WithSHA256,
7177 },
7178 },
7179 flags: []string{
7180 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7181 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7182 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7183 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7184 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7185 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7186 },
7187 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7188 })
7189
David Benjamin4c3ddf72016-06-29 18:13:53 -04007190 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7191 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007192 testCases = append(testCases, testCase{
7193 name: "CheckLeafCurve",
7194 config: Config{
7195 MaxVersion: VersionTLS12,
7196 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007197 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007198 },
7199 flags: []string{"-p384-only"},
7200 shouldFail: true,
7201 expectedError: ":BAD_ECC_CERT:",
7202 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007203
7204 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7205 testCases = append(testCases, testCase{
7206 name: "CheckLeafCurve-TLS13",
7207 config: Config{
7208 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007209 Certificates: []Certificate{ecdsaP256Certificate},
7210 },
7211 flags: []string{"-p384-only"},
7212 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007213
7214 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7215 testCases = append(testCases, testCase{
7216 name: "ECDSACurveMismatch-Verify-TLS12",
7217 config: Config{
7218 MaxVersion: VersionTLS12,
7219 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7220 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007221 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007222 signatureECDSAWithP384AndSHA384,
7223 },
7224 },
7225 })
7226
7227 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7228 testCases = append(testCases, testCase{
7229 name: "ECDSACurveMismatch-Verify-TLS13",
7230 config: Config{
7231 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007232 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007233 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007234 signatureECDSAWithP384AndSHA384,
7235 },
7236 Bugs: ProtocolBugs{
7237 SkipECDSACurveCheck: true,
7238 },
7239 },
7240 shouldFail: true,
7241 expectedError: ":WRONG_SIGNATURE_TYPE:",
7242 })
7243
7244 // Signature algorithm selection in TLS 1.3 should take the curve into
7245 // account.
7246 testCases = append(testCases, testCase{
7247 testType: serverTest,
7248 name: "ECDSACurveMismatch-Sign-TLS13",
7249 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007250 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007251 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007252 signatureECDSAWithP384AndSHA384,
7253 signatureECDSAWithP256AndSHA256,
7254 },
7255 },
7256 flags: []string{
7257 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7258 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7259 },
7260 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7261 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007262
7263 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7264 // server does not attempt to sign in that case.
7265 testCases = append(testCases, testCase{
7266 testType: serverTest,
7267 name: "RSA-PSS-Large",
7268 config: Config{
7269 MaxVersion: VersionTLS13,
7270 VerifySignatureAlgorithms: []signatureAlgorithm{
7271 signatureRSAPSSWithSHA512,
7272 },
7273 },
7274 flags: []string{
7275 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7276 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7277 },
7278 shouldFail: true,
7279 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7280 })
David Benjamin57e929f2016-08-30 00:30:38 -04007281
7282 // Test that RSA-PSS is enabled by default for TLS 1.2.
7283 testCases = append(testCases, testCase{
7284 testType: clientTest,
7285 name: "RSA-PSS-Default-Verify",
7286 config: Config{
7287 MaxVersion: VersionTLS12,
7288 SignSignatureAlgorithms: []signatureAlgorithm{
7289 signatureRSAPSSWithSHA256,
7290 },
7291 },
7292 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7293 })
7294
7295 testCases = append(testCases, testCase{
7296 testType: serverTest,
7297 name: "RSA-PSS-Default-Sign",
7298 config: Config{
7299 MaxVersion: VersionTLS12,
7300 VerifySignatureAlgorithms: []signatureAlgorithm{
7301 signatureRSAPSSWithSHA256,
7302 },
7303 },
7304 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7305 })
David Benjamin000800a2014-11-14 01:43:59 -05007306}
7307
David Benjamin83f90402015-01-27 01:09:43 -05007308// timeouts is the retransmit schedule for BoringSSL. It doubles and
7309// caps at 60 seconds. On the 13th timeout, it gives up.
7310var timeouts = []time.Duration{
7311 1 * time.Second,
7312 2 * time.Second,
7313 4 * time.Second,
7314 8 * time.Second,
7315 16 * time.Second,
7316 32 * time.Second,
7317 60 * time.Second,
7318 60 * time.Second,
7319 60 * time.Second,
7320 60 * time.Second,
7321 60 * time.Second,
7322 60 * time.Second,
7323 60 * time.Second,
7324}
7325
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007326// shortTimeouts is an alternate set of timeouts which would occur if the
7327// initial timeout duration was set to 250ms.
7328var shortTimeouts = []time.Duration{
7329 250 * time.Millisecond,
7330 500 * time.Millisecond,
7331 1 * time.Second,
7332 2 * time.Second,
7333 4 * time.Second,
7334 8 * time.Second,
7335 16 * time.Second,
7336 32 * time.Second,
7337 60 * time.Second,
7338 60 * time.Second,
7339 60 * time.Second,
7340 60 * time.Second,
7341 60 * time.Second,
7342}
7343
David Benjamin83f90402015-01-27 01:09:43 -05007344func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007345 // These tests work by coordinating some behavior on both the shim and
7346 // the runner.
7347 //
7348 // TimeoutSchedule configures the runner to send a series of timeout
7349 // opcodes to the shim (see packetAdaptor) immediately before reading
7350 // each peer handshake flight N. The timeout opcode both simulates a
7351 // timeout in the shim and acts as a synchronization point to help the
7352 // runner bracket each handshake flight.
7353 //
7354 // We assume the shim does not read from the channel eagerly. It must
7355 // first wait until it has sent flight N and is ready to receive
7356 // handshake flight N+1. At this point, it will process the timeout
7357 // opcode. It must then immediately respond with a timeout ACK and act
7358 // as if the shim was idle for the specified amount of time.
7359 //
7360 // The runner then drops all packets received before the ACK and
7361 // continues waiting for flight N. This ordering results in one attempt
7362 // at sending flight N to be dropped. For the test to complete, the
7363 // shim must send flight N again, testing that the shim implements DTLS
7364 // retransmit on a timeout.
7365
Steven Valdez143e8b32016-07-11 13:19:03 -04007366 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007367 // likely be more epochs to cross and the final message's retransmit may
7368 // be more complex.
7369
David Benjamin585d7a42016-06-02 14:58:00 -04007370 for _, async := range []bool{true, false} {
7371 var tests []testCase
7372
7373 // Test that this is indeed the timeout schedule. Stress all
7374 // four patterns of handshake.
7375 for i := 1; i < len(timeouts); i++ {
7376 number := strconv.Itoa(i)
7377 tests = append(tests, testCase{
7378 protocol: dtls,
7379 name: "DTLS-Retransmit-Client-" + number,
7380 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007381 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007382 Bugs: ProtocolBugs{
7383 TimeoutSchedule: timeouts[:i],
7384 },
7385 },
7386 resumeSession: true,
7387 })
7388 tests = append(tests, testCase{
7389 protocol: dtls,
7390 testType: serverTest,
7391 name: "DTLS-Retransmit-Server-" + number,
7392 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007393 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007394 Bugs: ProtocolBugs{
7395 TimeoutSchedule: timeouts[:i],
7396 },
7397 },
7398 resumeSession: true,
7399 })
7400 }
7401
7402 // Test that exceeding the timeout schedule hits a read
7403 // timeout.
7404 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007405 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007406 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007408 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007409 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007410 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007411 },
7412 },
7413 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007414 shouldFail: true,
7415 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007416 })
David Benjamin585d7a42016-06-02 14:58:00 -04007417
7418 if async {
7419 // Test that timeout handling has a fudge factor, due to API
7420 // problems.
7421 tests = append(tests, testCase{
7422 protocol: dtls,
7423 name: "DTLS-Retransmit-Fudge",
7424 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007425 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007426 Bugs: ProtocolBugs{
7427 TimeoutSchedule: []time.Duration{
7428 timeouts[0] - 10*time.Millisecond,
7429 },
7430 },
7431 },
7432 resumeSession: true,
7433 })
7434 }
7435
7436 // Test that the final Finished retransmitting isn't
7437 // duplicated if the peer badly fragments everything.
7438 tests = append(tests, testCase{
7439 testType: serverTest,
7440 protocol: dtls,
7441 name: "DTLS-Retransmit-Fragmented",
7442 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007443 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007444 Bugs: ProtocolBugs{
7445 TimeoutSchedule: []time.Duration{timeouts[0]},
7446 MaxHandshakeRecordLength: 2,
7447 },
7448 },
7449 })
7450
7451 // Test the timeout schedule when a shorter initial timeout duration is set.
7452 tests = append(tests, testCase{
7453 protocol: dtls,
7454 name: "DTLS-Retransmit-Short-Client",
7455 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007456 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007457 Bugs: ProtocolBugs{
7458 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7459 },
7460 },
7461 resumeSession: true,
7462 flags: []string{"-initial-timeout-duration-ms", "250"},
7463 })
7464 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007465 protocol: dtls,
7466 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007467 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007468 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007469 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007470 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007471 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007472 },
7473 },
7474 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007475 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007476 })
David Benjamin585d7a42016-06-02 14:58:00 -04007477
7478 for _, test := range tests {
7479 if async {
7480 test.name += "-Async"
7481 test.flags = append(test.flags, "-async")
7482 }
7483
7484 testCases = append(testCases, test)
7485 }
David Benjamin83f90402015-01-27 01:09:43 -05007486 }
David Benjamin83f90402015-01-27 01:09:43 -05007487}
7488
David Benjaminc565ebb2015-04-03 04:06:36 -04007489func addExportKeyingMaterialTests() {
7490 for _, vers := range tlsVersions {
7491 if vers.version == VersionSSL30 {
7492 continue
7493 }
7494 testCases = append(testCases, testCase{
7495 name: "ExportKeyingMaterial-" + vers.name,
7496 config: Config{
7497 MaxVersion: vers.version,
7498 },
7499 exportKeyingMaterial: 1024,
7500 exportLabel: "label",
7501 exportContext: "context",
7502 useExportContext: true,
7503 })
7504 testCases = append(testCases, testCase{
7505 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7506 config: Config{
7507 MaxVersion: vers.version,
7508 },
7509 exportKeyingMaterial: 1024,
7510 })
7511 testCases = append(testCases, testCase{
7512 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7513 config: Config{
7514 MaxVersion: vers.version,
7515 },
7516 exportKeyingMaterial: 1024,
7517 useExportContext: true,
7518 })
7519 testCases = append(testCases, testCase{
7520 name: "ExportKeyingMaterial-Small-" + vers.name,
7521 config: Config{
7522 MaxVersion: vers.version,
7523 },
7524 exportKeyingMaterial: 1,
7525 exportLabel: "label",
7526 exportContext: "context",
7527 useExportContext: true,
7528 })
7529 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007530
David Benjaminc565ebb2015-04-03 04:06:36 -04007531 testCases = append(testCases, testCase{
7532 name: "ExportKeyingMaterial-SSL3",
7533 config: Config{
7534 MaxVersion: VersionSSL30,
7535 },
7536 exportKeyingMaterial: 1024,
7537 exportLabel: "label",
7538 exportContext: "context",
7539 useExportContext: true,
7540 shouldFail: true,
7541 expectedError: "failed to export keying material",
7542 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007543
7544 // Exporters work during a False Start.
7545 testCases = append(testCases, testCase{
7546 name: "ExportKeyingMaterial-FalseStart",
7547 config: Config{
7548 MaxVersion: VersionTLS12,
7549 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7550 NextProtos: []string{"foo"},
7551 Bugs: ProtocolBugs{
7552 ExpectFalseStart: true,
7553 },
7554 },
7555 flags: []string{
7556 "-false-start",
7557 "-advertise-alpn", "\x03foo",
7558 },
7559 shimWritesFirst: true,
7560 exportKeyingMaterial: 1024,
7561 exportLabel: "label",
7562 exportContext: "context",
7563 useExportContext: true,
7564 })
7565
7566 // Exporters do not work in the middle of a renegotiation. Test this by
7567 // triggering the exporter after every SSL_read call and configuring the
7568 // shim to run asynchronously.
7569 testCases = append(testCases, testCase{
7570 name: "ExportKeyingMaterial-Renegotiate",
7571 config: Config{
7572 MaxVersion: VersionTLS12,
7573 },
7574 renegotiate: 1,
7575 flags: []string{
7576 "-async",
7577 "-use-exporter-between-reads",
7578 "-renegotiate-freely",
7579 "-expect-total-renegotiations", "1",
7580 },
7581 shouldFail: true,
7582 expectedError: "failed to export keying material",
7583 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007584}
7585
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007586func addTLSUniqueTests() {
7587 for _, isClient := range []bool{false, true} {
7588 for _, isResumption := range []bool{false, true} {
7589 for _, hasEMS := range []bool{false, true} {
7590 var suffix string
7591 if isResumption {
7592 suffix = "Resume-"
7593 } else {
7594 suffix = "Full-"
7595 }
7596
7597 if hasEMS {
7598 suffix += "EMS-"
7599 } else {
7600 suffix += "NoEMS-"
7601 }
7602
7603 if isClient {
7604 suffix += "Client"
7605 } else {
7606 suffix += "Server"
7607 }
7608
7609 test := testCase{
7610 name: "TLSUnique-" + suffix,
7611 testTLSUnique: true,
7612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007613 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007614 Bugs: ProtocolBugs{
7615 NoExtendedMasterSecret: !hasEMS,
7616 },
7617 },
7618 }
7619
7620 if isResumption {
7621 test.resumeSession = true
7622 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007623 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007624 Bugs: ProtocolBugs{
7625 NoExtendedMasterSecret: !hasEMS,
7626 },
7627 }
7628 }
7629
7630 if isResumption && !hasEMS {
7631 test.shouldFail = true
7632 test.expectedError = "failed to get tls-unique"
7633 }
7634
7635 testCases = append(testCases, test)
7636 }
7637 }
7638 }
7639}
7640
Adam Langley09505632015-07-30 18:10:13 -07007641func addCustomExtensionTests() {
7642 expectedContents := "custom extension"
7643 emptyString := ""
7644
7645 for _, isClient := range []bool{false, true} {
7646 suffix := "Server"
7647 flag := "-enable-server-custom-extension"
7648 testType := serverTest
7649 if isClient {
7650 suffix = "Client"
7651 flag = "-enable-client-custom-extension"
7652 testType = clientTest
7653 }
7654
7655 testCases = append(testCases, testCase{
7656 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007657 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007658 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007659 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007660 Bugs: ProtocolBugs{
7661 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007662 ExpectedCustomExtension: &expectedContents,
7663 },
7664 },
7665 flags: []string{flag},
7666 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007667 testCases = append(testCases, testCase{
7668 testType: testType,
7669 name: "CustomExtensions-" + suffix + "-TLS13",
7670 config: Config{
7671 MaxVersion: VersionTLS13,
7672 Bugs: ProtocolBugs{
7673 CustomExtension: expectedContents,
7674 ExpectedCustomExtension: &expectedContents,
7675 },
7676 },
7677 flags: []string{flag},
7678 })
Adam Langley09505632015-07-30 18:10:13 -07007679
7680 // If the parse callback fails, the handshake should also fail.
7681 testCases = append(testCases, testCase{
7682 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007683 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007684 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007685 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007686 Bugs: ProtocolBugs{
7687 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007688 ExpectedCustomExtension: &expectedContents,
7689 },
7690 },
David Benjamin399e7c92015-07-30 23:01:27 -04007691 flags: []string{flag},
7692 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007693 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7694 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007695 testCases = append(testCases, testCase{
7696 testType: testType,
7697 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7698 config: Config{
7699 MaxVersion: VersionTLS13,
7700 Bugs: ProtocolBugs{
7701 CustomExtension: expectedContents + "foo",
7702 ExpectedCustomExtension: &expectedContents,
7703 },
7704 },
7705 flags: []string{flag},
7706 shouldFail: true,
7707 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7708 })
Adam Langley09505632015-07-30 18:10:13 -07007709
7710 // If the add callback fails, the handshake should also fail.
7711 testCases = append(testCases, testCase{
7712 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007713 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007714 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007715 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007716 Bugs: ProtocolBugs{
7717 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007718 ExpectedCustomExtension: &expectedContents,
7719 },
7720 },
David Benjamin399e7c92015-07-30 23:01:27 -04007721 flags: []string{flag, "-custom-extension-fail-add"},
7722 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007723 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7724 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007725 testCases = append(testCases, testCase{
7726 testType: testType,
7727 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7728 config: Config{
7729 MaxVersion: VersionTLS13,
7730 Bugs: ProtocolBugs{
7731 CustomExtension: expectedContents,
7732 ExpectedCustomExtension: &expectedContents,
7733 },
7734 },
7735 flags: []string{flag, "-custom-extension-fail-add"},
7736 shouldFail: true,
7737 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7738 })
Adam Langley09505632015-07-30 18:10:13 -07007739
7740 // If the add callback returns zero, no extension should be
7741 // added.
7742 skipCustomExtension := expectedContents
7743 if isClient {
7744 // For the case where the client skips sending the
7745 // custom extension, the server must not “echo” it.
7746 skipCustomExtension = ""
7747 }
7748 testCases = append(testCases, testCase{
7749 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007750 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007751 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007752 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007753 Bugs: ProtocolBugs{
7754 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007755 ExpectedCustomExtension: &emptyString,
7756 },
7757 },
7758 flags: []string{flag, "-custom-extension-skip"},
7759 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007760 testCases = append(testCases, testCase{
7761 testType: testType,
7762 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7763 config: Config{
7764 MaxVersion: VersionTLS13,
7765 Bugs: ProtocolBugs{
7766 CustomExtension: skipCustomExtension,
7767 ExpectedCustomExtension: &emptyString,
7768 },
7769 },
7770 flags: []string{flag, "-custom-extension-skip"},
7771 })
Adam Langley09505632015-07-30 18:10:13 -07007772 }
7773
7774 // The custom extension add callback should not be called if the client
7775 // doesn't send the extension.
7776 testCases = append(testCases, testCase{
7777 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007778 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007780 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007781 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007782 ExpectedCustomExtension: &emptyString,
7783 },
7784 },
7785 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7786 })
Adam Langley2deb9842015-08-07 11:15:37 -07007787
Steven Valdez143e8b32016-07-11 13:19:03 -04007788 testCases = append(testCases, testCase{
7789 testType: serverTest,
7790 name: "CustomExtensions-NotCalled-Server-TLS13",
7791 config: Config{
7792 MaxVersion: VersionTLS13,
7793 Bugs: ProtocolBugs{
7794 ExpectedCustomExtension: &emptyString,
7795 },
7796 },
7797 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7798 })
7799
Adam Langley2deb9842015-08-07 11:15:37 -07007800 // Test an unknown extension from the server.
7801 testCases = append(testCases, testCase{
7802 testType: clientTest,
7803 name: "UnknownExtension-Client",
7804 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007805 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007806 Bugs: ProtocolBugs{
7807 CustomExtension: expectedContents,
7808 },
7809 },
David Benjamin0c40a962016-08-01 12:05:50 -04007810 shouldFail: true,
7811 expectedError: ":UNEXPECTED_EXTENSION:",
7812 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007813 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007814 testCases = append(testCases, testCase{
7815 testType: clientTest,
7816 name: "UnknownExtension-Client-TLS13",
7817 config: Config{
7818 MaxVersion: VersionTLS13,
7819 Bugs: ProtocolBugs{
7820 CustomExtension: expectedContents,
7821 },
7822 },
David Benjamin0c40a962016-08-01 12:05:50 -04007823 shouldFail: true,
7824 expectedError: ":UNEXPECTED_EXTENSION:",
7825 expectedLocalError: "remote error: unsupported extension",
7826 })
David Benjamin490469f2016-10-05 22:44:38 -04007827 testCases = append(testCases, testCase{
7828 testType: clientTest,
7829 name: "UnknownUnencryptedExtension-Client-TLS13",
7830 config: Config{
7831 MaxVersion: VersionTLS13,
7832 Bugs: ProtocolBugs{
7833 CustomUnencryptedExtension: expectedContents,
7834 },
7835 },
7836 shouldFail: true,
7837 expectedError: ":UNEXPECTED_EXTENSION:",
7838 // The shim must send an alert, but alerts at this point do not
7839 // get successfully decrypted by the runner.
7840 expectedLocalError: "local error: bad record MAC",
7841 })
7842 testCases = append(testCases, testCase{
7843 testType: clientTest,
7844 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7845 config: Config{
7846 MaxVersion: VersionTLS13,
7847 Bugs: ProtocolBugs{
7848 SendUnencryptedALPN: "foo",
7849 },
7850 },
7851 flags: []string{
7852 "-advertise-alpn", "\x03foo\x03bar",
7853 },
7854 shouldFail: true,
7855 expectedError: ":UNEXPECTED_EXTENSION:",
7856 // The shim must send an alert, but alerts at this point do not
7857 // get successfully decrypted by the runner.
7858 expectedLocalError: "local error: bad record MAC",
7859 })
David Benjamin0c40a962016-08-01 12:05:50 -04007860
7861 // Test a known but unoffered extension from the server.
7862 testCases = append(testCases, testCase{
7863 testType: clientTest,
7864 name: "UnofferedExtension-Client",
7865 config: Config{
7866 MaxVersion: VersionTLS12,
7867 Bugs: ProtocolBugs{
7868 SendALPN: "alpn",
7869 },
7870 },
7871 shouldFail: true,
7872 expectedError: ":UNEXPECTED_EXTENSION:",
7873 expectedLocalError: "remote error: unsupported extension",
7874 })
7875 testCases = append(testCases, testCase{
7876 testType: clientTest,
7877 name: "UnofferedExtension-Client-TLS13",
7878 config: Config{
7879 MaxVersion: VersionTLS13,
7880 Bugs: ProtocolBugs{
7881 SendALPN: "alpn",
7882 },
7883 },
7884 shouldFail: true,
7885 expectedError: ":UNEXPECTED_EXTENSION:",
7886 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007887 })
Adam Langley09505632015-07-30 18:10:13 -07007888}
7889
David Benjaminb36a3952015-12-01 18:53:13 -05007890func addRSAClientKeyExchangeTests() {
7891 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7892 testCases = append(testCases, testCase{
7893 testType: serverTest,
7894 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7895 config: Config{
7896 // Ensure the ClientHello version and final
7897 // version are different, to detect if the
7898 // server uses the wrong one.
7899 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007900 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007901 Bugs: ProtocolBugs{
7902 BadRSAClientKeyExchange: bad,
7903 },
7904 },
7905 shouldFail: true,
7906 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7907 })
7908 }
David Benjamine63d9d72016-09-19 18:27:34 -04007909
7910 // The server must compare whatever was in ClientHello.version for the
7911 // RSA premaster.
7912 testCases = append(testCases, testCase{
7913 testType: serverTest,
7914 name: "SendClientVersion-RSA",
7915 config: Config{
7916 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7917 Bugs: ProtocolBugs{
7918 SendClientVersion: 0x1234,
7919 },
7920 },
7921 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7922 })
David Benjaminb36a3952015-12-01 18:53:13 -05007923}
7924
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007925var testCurves = []struct {
7926 name string
7927 id CurveID
7928}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007929 {"P-256", CurveP256},
7930 {"P-384", CurveP384},
7931 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007932 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007933}
7934
Steven Valdez5440fe02016-07-18 12:40:30 -04007935const bogusCurve = 0x1234
7936
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007937func addCurveTests() {
7938 for _, curve := range testCurves {
7939 testCases = append(testCases, testCase{
7940 name: "CurveTest-Client-" + curve.name,
7941 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007942 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007943 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7944 CurvePreferences: []CurveID{curve.id},
7945 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007946 flags: []string{
7947 "-enable-all-curves",
7948 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7949 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007950 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007951 })
7952 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007953 name: "CurveTest-Client-" + curve.name + "-TLS13",
7954 config: Config{
7955 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007956 CurvePreferences: []CurveID{curve.id},
7957 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007958 flags: []string{
7959 "-enable-all-curves",
7960 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7961 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007962 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007963 })
7964 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007965 testType: serverTest,
7966 name: "CurveTest-Server-" + curve.name,
7967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007968 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007969 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7970 CurvePreferences: []CurveID{curve.id},
7971 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007972 flags: []string{
7973 "-enable-all-curves",
7974 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7975 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007976 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007977 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007978 testCases = append(testCases, testCase{
7979 testType: serverTest,
7980 name: "CurveTest-Server-" + curve.name + "-TLS13",
7981 config: Config{
7982 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007983 CurvePreferences: []CurveID{curve.id},
7984 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007985 flags: []string{
7986 "-enable-all-curves",
7987 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7988 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007989 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007990 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007991 }
David Benjamin241ae832016-01-15 03:04:54 -05007992
7993 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007994 testCases = append(testCases, testCase{
7995 testType: serverTest,
7996 name: "UnknownCurve",
7997 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007998 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007999 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8000 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8001 },
8002 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008003
Steven Valdez803c77a2016-09-06 14:13:43 -04008004 // The server must be tolerant to bogus curves.
8005 testCases = append(testCases, testCase{
8006 testType: serverTest,
8007 name: "UnknownCurve-TLS13",
8008 config: Config{
8009 MaxVersion: VersionTLS13,
8010 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8011 },
8012 })
8013
David Benjamin4c3ddf72016-06-29 18:13:53 -04008014 // The server must not consider ECDHE ciphers when there are no
8015 // supported curves.
8016 testCases = append(testCases, testCase{
8017 testType: serverTest,
8018 name: "NoSupportedCurves",
8019 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008020 MaxVersion: VersionTLS12,
8021 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8022 Bugs: ProtocolBugs{
8023 NoSupportedCurves: true,
8024 },
8025 },
8026 shouldFail: true,
8027 expectedError: ":NO_SHARED_CIPHER:",
8028 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008029 testCases = append(testCases, testCase{
8030 testType: serverTest,
8031 name: "NoSupportedCurves-TLS13",
8032 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008033 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008034 Bugs: ProtocolBugs{
8035 NoSupportedCurves: true,
8036 },
8037 },
8038 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008039 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008040 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008041
8042 // The server must fall back to another cipher when there are no
8043 // supported curves.
8044 testCases = append(testCases, testCase{
8045 testType: serverTest,
8046 name: "NoCommonCurves",
8047 config: Config{
8048 MaxVersion: VersionTLS12,
8049 CipherSuites: []uint16{
8050 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8051 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8052 },
8053 CurvePreferences: []CurveID{CurveP224},
8054 },
8055 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8056 })
8057
8058 // The client must reject bogus curves and disabled curves.
8059 testCases = append(testCases, testCase{
8060 name: "BadECDHECurve",
8061 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008062 MaxVersion: VersionTLS12,
8063 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8064 Bugs: ProtocolBugs{
8065 SendCurve: bogusCurve,
8066 },
8067 },
8068 shouldFail: true,
8069 expectedError: ":WRONG_CURVE:",
8070 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008071 testCases = append(testCases, testCase{
8072 name: "BadECDHECurve-TLS13",
8073 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008074 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008075 Bugs: ProtocolBugs{
8076 SendCurve: bogusCurve,
8077 },
8078 },
8079 shouldFail: true,
8080 expectedError: ":WRONG_CURVE:",
8081 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008082
8083 testCases = append(testCases, testCase{
8084 name: "UnsupportedCurve",
8085 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008086 MaxVersion: VersionTLS12,
8087 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8088 CurvePreferences: []CurveID{CurveP256},
8089 Bugs: ProtocolBugs{
8090 IgnorePeerCurvePreferences: true,
8091 },
8092 },
8093 flags: []string{"-p384-only"},
8094 shouldFail: true,
8095 expectedError: ":WRONG_CURVE:",
8096 })
8097
David Benjamin4f921572016-07-17 14:20:10 +02008098 testCases = append(testCases, testCase{
8099 // TODO(davidben): Add a TLS 1.3 version where
8100 // HelloRetryRequest requests an unsupported curve.
8101 name: "UnsupportedCurve-ServerHello-TLS13",
8102 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008103 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008104 CurvePreferences: []CurveID{CurveP384},
8105 Bugs: ProtocolBugs{
8106 SendCurve: CurveP256,
8107 },
8108 },
8109 flags: []string{"-p384-only"},
8110 shouldFail: true,
8111 expectedError: ":WRONG_CURVE:",
8112 })
8113
David Benjamin4c3ddf72016-06-29 18:13:53 -04008114 // Test invalid curve points.
8115 testCases = append(testCases, testCase{
8116 name: "InvalidECDHPoint-Client",
8117 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008118 MaxVersion: VersionTLS12,
8119 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8120 CurvePreferences: []CurveID{CurveP256},
8121 Bugs: ProtocolBugs{
8122 InvalidECDHPoint: true,
8123 },
8124 },
8125 shouldFail: true,
8126 expectedError: ":INVALID_ENCODING:",
8127 })
8128 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008129 name: "InvalidECDHPoint-Client-TLS13",
8130 config: Config{
8131 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008132 CurvePreferences: []CurveID{CurveP256},
8133 Bugs: ProtocolBugs{
8134 InvalidECDHPoint: true,
8135 },
8136 },
8137 shouldFail: true,
8138 expectedError: ":INVALID_ENCODING:",
8139 })
8140 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008141 testType: serverTest,
8142 name: "InvalidECDHPoint-Server",
8143 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008144 MaxVersion: VersionTLS12,
8145 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8146 CurvePreferences: []CurveID{CurveP256},
8147 Bugs: ProtocolBugs{
8148 InvalidECDHPoint: true,
8149 },
8150 },
8151 shouldFail: true,
8152 expectedError: ":INVALID_ENCODING:",
8153 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008154 testCases = append(testCases, testCase{
8155 testType: serverTest,
8156 name: "InvalidECDHPoint-Server-TLS13",
8157 config: Config{
8158 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008159 CurvePreferences: []CurveID{CurveP256},
8160 Bugs: ProtocolBugs{
8161 InvalidECDHPoint: true,
8162 },
8163 },
8164 shouldFail: true,
8165 expectedError: ":INVALID_ENCODING:",
8166 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008167
8168 // The previous curve ID should be reported on TLS 1.2 resumption.
8169 testCases = append(testCases, testCase{
8170 name: "CurveID-Resume-Client",
8171 config: Config{
8172 MaxVersion: VersionTLS12,
8173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8174 CurvePreferences: []CurveID{CurveX25519},
8175 },
8176 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8177 resumeSession: true,
8178 })
8179 testCases = append(testCases, testCase{
8180 testType: serverTest,
8181 name: "CurveID-Resume-Server",
8182 config: Config{
8183 MaxVersion: VersionTLS12,
8184 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8185 CurvePreferences: []CurveID{CurveX25519},
8186 },
8187 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8188 resumeSession: true,
8189 })
8190
8191 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8192 // one should be reported.
8193 testCases = append(testCases, testCase{
8194 name: "CurveID-Resume-Client-TLS13",
8195 config: Config{
8196 MaxVersion: VersionTLS13,
8197 CurvePreferences: []CurveID{CurveX25519},
8198 },
8199 resumeConfig: &Config{
8200 MaxVersion: VersionTLS13,
8201 CurvePreferences: []CurveID{CurveP256},
8202 },
8203 flags: []string{
8204 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8205 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8206 },
8207 resumeSession: true,
8208 })
8209 testCases = append(testCases, testCase{
8210 testType: serverTest,
8211 name: "CurveID-Resume-Server-TLS13",
8212 config: Config{
8213 MaxVersion: VersionTLS13,
8214 CurvePreferences: []CurveID{CurveX25519},
8215 },
8216 resumeConfig: &Config{
8217 MaxVersion: VersionTLS13,
8218 CurvePreferences: []CurveID{CurveP256},
8219 },
8220 flags: []string{
8221 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8222 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8223 },
8224 resumeSession: true,
8225 })
David Benjamina81967b2016-12-22 09:16:57 -05008226
8227 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8228 testCases = append(testCases, testCase{
8229 name: "PointFormat-ServerHello-TLS12",
8230 config: Config{
8231 MaxVersion: VersionTLS12,
8232 Bugs: ProtocolBugs{
8233 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8234 },
8235 },
8236 })
8237 testCases = append(testCases, testCase{
8238 name: "PointFormat-EncryptedExtensions-TLS13",
8239 config: Config{
8240 MaxVersion: VersionTLS13,
8241 Bugs: ProtocolBugs{
8242 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8243 },
8244 },
8245 shouldFail: true,
8246 expectedError: ":ERROR_PARSING_EXTENSION:",
8247 })
8248
8249 // Test that we tolerate unknown point formats, as long as
8250 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8251 // check they are still functional.
8252 testCases = append(testCases, testCase{
8253 name: "PointFormat-Client-Tolerance",
8254 config: Config{
8255 MaxVersion: VersionTLS12,
8256 Bugs: ProtocolBugs{
8257 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8258 },
8259 },
8260 })
8261 testCases = append(testCases, testCase{
8262 testType: serverTest,
8263 name: "PointFormat-Server-Tolerance",
8264 config: Config{
8265 MaxVersion: VersionTLS12,
8266 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8267 Bugs: ProtocolBugs{
8268 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8269 },
8270 },
8271 })
8272
8273 // Test TLS 1.2 does not require the point format extension to be
8274 // present.
8275 testCases = append(testCases, testCase{
8276 name: "PointFormat-Client-Missing",
8277 config: Config{
8278 MaxVersion: VersionTLS12,
8279 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8280 Bugs: ProtocolBugs{
8281 SendSupportedPointFormats: []byte{},
8282 },
8283 },
8284 })
8285 testCases = append(testCases, testCase{
8286 testType: serverTest,
8287 name: "PointFormat-Server-Missing",
8288 config: Config{
8289 MaxVersion: VersionTLS12,
8290 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8291 Bugs: ProtocolBugs{
8292 SendSupportedPointFormats: []byte{},
8293 },
8294 },
8295 })
8296
8297 // If the point format extension is present, uncompressed points must be
8298 // offered. BoringSSL requires this whether or not ECDHE is used.
8299 testCases = append(testCases, testCase{
8300 name: "PointFormat-Client-MissingUncompressed",
8301 config: Config{
8302 MaxVersion: VersionTLS12,
8303 Bugs: ProtocolBugs{
8304 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8305 },
8306 },
8307 shouldFail: true,
8308 expectedError: ":ERROR_PARSING_EXTENSION:",
8309 })
8310 testCases = append(testCases, testCase{
8311 testType: serverTest,
8312 name: "PointFormat-Server-MissingUncompressed",
8313 config: Config{
8314 MaxVersion: VersionTLS12,
8315 Bugs: ProtocolBugs{
8316 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8317 },
8318 },
8319 shouldFail: true,
8320 expectedError: ":ERROR_PARSING_EXTENSION:",
8321 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008322}
8323
David Benjaminc9ae27c2016-06-24 22:56:37 -04008324func addTLS13RecordTests() {
8325 testCases = append(testCases, testCase{
8326 name: "TLS13-RecordPadding",
8327 config: Config{
8328 MaxVersion: VersionTLS13,
8329 MinVersion: VersionTLS13,
8330 Bugs: ProtocolBugs{
8331 RecordPadding: 10,
8332 },
8333 },
8334 })
8335
8336 testCases = append(testCases, testCase{
8337 name: "TLS13-EmptyRecords",
8338 config: Config{
8339 MaxVersion: VersionTLS13,
8340 MinVersion: VersionTLS13,
8341 Bugs: ProtocolBugs{
8342 OmitRecordContents: true,
8343 },
8344 },
8345 shouldFail: true,
8346 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8347 })
8348
8349 testCases = append(testCases, testCase{
8350 name: "TLS13-OnlyPadding",
8351 config: Config{
8352 MaxVersion: VersionTLS13,
8353 MinVersion: VersionTLS13,
8354 Bugs: ProtocolBugs{
8355 OmitRecordContents: true,
8356 RecordPadding: 10,
8357 },
8358 },
8359 shouldFail: true,
8360 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8361 })
8362
8363 testCases = append(testCases, testCase{
8364 name: "TLS13-WrongOuterRecord",
8365 config: Config{
8366 MaxVersion: VersionTLS13,
8367 MinVersion: VersionTLS13,
8368 Bugs: ProtocolBugs{
8369 OuterRecordType: recordTypeHandshake,
8370 },
8371 },
8372 shouldFail: true,
8373 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8374 })
8375}
8376
Steven Valdez5b986082016-09-01 12:29:49 -04008377func addSessionTicketTests() {
8378 testCases = append(testCases, testCase{
8379 // In TLS 1.2 and below, empty NewSessionTicket messages
8380 // mean the server changed its mind on sending a ticket.
8381 name: "SendEmptySessionTicket",
8382 config: Config{
8383 MaxVersion: VersionTLS12,
8384 Bugs: ProtocolBugs{
8385 SendEmptySessionTicket: true,
8386 },
8387 },
8388 flags: []string{"-expect-no-session"},
8389 })
8390
8391 // Test that the server ignores unknown PSK modes.
8392 testCases = append(testCases, testCase{
8393 testType: serverTest,
8394 name: "TLS13-SendUnknownModeSessionTicket-Server",
8395 config: Config{
8396 MaxVersion: VersionTLS13,
8397 Bugs: ProtocolBugs{
8398 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008399 },
8400 },
8401 resumeSession: true,
8402 expectedResumeVersion: VersionTLS13,
8403 })
8404
Steven Valdeza833c352016-11-01 13:39:36 -04008405 // Test that the server does not send session tickets with no matching key exchange mode.
8406 testCases = append(testCases, testCase{
8407 testType: serverTest,
8408 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8409 config: Config{
8410 MaxVersion: VersionTLS13,
8411 Bugs: ProtocolBugs{
8412 SendPSKKeyExchangeModes: []byte{0x1a},
8413 ExpectNoNewSessionTicket: true,
8414 },
8415 },
8416 })
8417
8418 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008419 testCases = append(testCases, testCase{
8420 testType: serverTest,
8421 name: "TLS13-SendBadKEModeSessionTicket-Server",
8422 config: Config{
8423 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008424 },
8425 resumeConfig: &Config{
8426 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008427 Bugs: ProtocolBugs{
8428 SendPSKKeyExchangeModes: []byte{0x1a},
8429 },
8430 },
8431 resumeSession: true,
8432 expectResumeRejected: true,
8433 })
8434
Steven Valdeza833c352016-11-01 13:39:36 -04008435 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008436 testCases = append(testCases, testCase{
8437 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008438 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008439 config: Config{
8440 MaxVersion: VersionTLS13,
8441 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008442 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008443 },
8444 },
Steven Valdeza833c352016-11-01 13:39:36 -04008445 resumeSession: true,
8446 flags: []string{
8447 "-resumption-delay", "10",
8448 },
Steven Valdez5b986082016-09-01 12:29:49 -04008449 })
8450
Steven Valdeza833c352016-11-01 13:39:36 -04008451 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008452 testCases = append(testCases, testCase{
8453 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008454 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008455 config: Config{
8456 MaxVersion: VersionTLS13,
8457 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008458 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008459 },
8460 },
Steven Valdeza833c352016-11-01 13:39:36 -04008461 resumeSession: true,
8462 shouldFail: true,
8463 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008464 })
8465
Steven Valdez08b65f42016-12-07 15:29:45 -05008466 testCases = append(testCases, testCase{
8467 testType: clientTest,
8468 name: "TLS13-SendTicketEarlyDataInfo",
8469 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008470 MaxVersion: VersionTLS13,
8471 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008472 },
8473 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008474 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008475 "-expect-early-data-info",
8476 },
8477 })
8478
David Benjamin9b160662017-01-25 19:53:43 -05008479 // Test that 0-RTT tickets are ignored in clients unless opted in.
8480 testCases = append(testCases, testCase{
8481 testType: clientTest,
8482 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8483 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008484 MaxVersion: VersionTLS13,
8485 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008486 },
8487 })
8488
Steven Valdez08b65f42016-12-07 15:29:45 -05008489 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008490 testType: clientTest,
8491 name: "TLS13-DuplicateTicketEarlyDataInfo",
8492 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008493 MaxVersion: VersionTLS13,
8494 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008495 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008496 DuplicateTicketEarlyDataInfo: true,
8497 },
8498 },
8499 shouldFail: true,
8500 expectedError: ":DUPLICATE_EXTENSION:",
8501 expectedLocalError: "remote error: illegal parameter",
8502 })
8503
8504 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008505 testType: serverTest,
8506 name: "TLS13-ExpectTicketEarlyDataInfo",
8507 config: Config{
8508 MaxVersion: VersionTLS13,
8509 Bugs: ProtocolBugs{
8510 ExpectTicketEarlyDataInfo: true,
8511 },
8512 },
8513 flags: []string{
8514 "-enable-early-data",
8515 },
8516 })
David Benjamin17b30832017-01-28 14:00:32 -05008517
8518 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8519 // is honored.
8520 testCases = append(testCases, testCase{
8521 testType: clientTest,
8522 name: "TLS13-HonorServerSessionTicketLifetime",
8523 config: Config{
8524 MaxVersion: VersionTLS13,
8525 Bugs: ProtocolBugs{
8526 SendTicketLifetime: 20 * time.Second,
8527 },
8528 },
8529 flags: []string{
8530 "-resumption-delay", "19",
8531 },
8532 resumeSession: true,
8533 })
8534 testCases = append(testCases, testCase{
8535 testType: clientTest,
8536 name: "TLS13-HonorServerSessionTicketLifetime-2",
8537 config: Config{
8538 MaxVersion: VersionTLS13,
8539 Bugs: ProtocolBugs{
8540 SendTicketLifetime: 20 * time.Second,
8541 // The client should not offer the expired session.
8542 ExpectNoTLS13PSK: true,
8543 },
8544 },
8545 flags: []string{
8546 "-resumption-delay", "21",
8547 },
David Benjamin023d4192017-02-06 13:49:07 -05008548 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008549 expectResumeRejected: true,
8550 })
Steven Valdez5b986082016-09-01 12:29:49 -04008551}
8552
David Benjamin82261be2016-07-07 14:32:50 -07008553func addChangeCipherSpecTests() {
8554 // Test missing ChangeCipherSpecs.
8555 testCases = append(testCases, testCase{
8556 name: "SkipChangeCipherSpec-Client",
8557 config: Config{
8558 MaxVersion: VersionTLS12,
8559 Bugs: ProtocolBugs{
8560 SkipChangeCipherSpec: true,
8561 },
8562 },
8563 shouldFail: true,
8564 expectedError: ":UNEXPECTED_RECORD:",
8565 })
8566 testCases = append(testCases, testCase{
8567 testType: serverTest,
8568 name: "SkipChangeCipherSpec-Server",
8569 config: Config{
8570 MaxVersion: VersionTLS12,
8571 Bugs: ProtocolBugs{
8572 SkipChangeCipherSpec: true,
8573 },
8574 },
8575 shouldFail: true,
8576 expectedError: ":UNEXPECTED_RECORD:",
8577 })
8578 testCases = append(testCases, testCase{
8579 testType: serverTest,
8580 name: "SkipChangeCipherSpec-Server-NPN",
8581 config: Config{
8582 MaxVersion: VersionTLS12,
8583 NextProtos: []string{"bar"},
8584 Bugs: ProtocolBugs{
8585 SkipChangeCipherSpec: true,
8586 },
8587 },
8588 flags: []string{
8589 "-advertise-npn", "\x03foo\x03bar\x03baz",
8590 },
8591 shouldFail: true,
8592 expectedError: ":UNEXPECTED_RECORD:",
8593 })
8594
8595 // Test synchronization between the handshake and ChangeCipherSpec.
8596 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8597 // rejected. Test both with and without handshake packing to handle both
8598 // when the partial post-CCS message is in its own record and when it is
8599 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008600 for _, packed := range []bool{false, true} {
8601 var suffix string
8602 if packed {
8603 suffix = "-Packed"
8604 }
8605
8606 testCases = append(testCases, testCase{
8607 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8608 config: Config{
8609 MaxVersion: VersionTLS12,
8610 Bugs: ProtocolBugs{
8611 FragmentAcrossChangeCipherSpec: true,
8612 PackHandshakeFlight: packed,
8613 },
8614 },
8615 shouldFail: true,
8616 expectedError: ":UNEXPECTED_RECORD:",
8617 })
8618 testCases = append(testCases, testCase{
8619 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8620 config: Config{
8621 MaxVersion: VersionTLS12,
8622 },
8623 resumeSession: true,
8624 resumeConfig: &Config{
8625 MaxVersion: VersionTLS12,
8626 Bugs: ProtocolBugs{
8627 FragmentAcrossChangeCipherSpec: true,
8628 PackHandshakeFlight: packed,
8629 },
8630 },
8631 shouldFail: true,
8632 expectedError: ":UNEXPECTED_RECORD:",
8633 })
8634 testCases = append(testCases, testCase{
8635 testType: serverTest,
8636 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8637 config: Config{
8638 MaxVersion: VersionTLS12,
8639 Bugs: ProtocolBugs{
8640 FragmentAcrossChangeCipherSpec: true,
8641 PackHandshakeFlight: packed,
8642 },
8643 },
8644 shouldFail: true,
8645 expectedError: ":UNEXPECTED_RECORD:",
8646 })
8647 testCases = append(testCases, testCase{
8648 testType: serverTest,
8649 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8650 config: Config{
8651 MaxVersion: VersionTLS12,
8652 },
8653 resumeSession: true,
8654 resumeConfig: &Config{
8655 MaxVersion: VersionTLS12,
8656 Bugs: ProtocolBugs{
8657 FragmentAcrossChangeCipherSpec: true,
8658 PackHandshakeFlight: packed,
8659 },
8660 },
8661 shouldFail: true,
8662 expectedError: ":UNEXPECTED_RECORD:",
8663 })
8664 testCases = append(testCases, testCase{
8665 testType: serverTest,
8666 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8667 config: Config{
8668 MaxVersion: VersionTLS12,
8669 NextProtos: []string{"bar"},
8670 Bugs: ProtocolBugs{
8671 FragmentAcrossChangeCipherSpec: true,
8672 PackHandshakeFlight: packed,
8673 },
8674 },
8675 flags: []string{
8676 "-advertise-npn", "\x03foo\x03bar\x03baz",
8677 },
8678 shouldFail: true,
8679 expectedError: ":UNEXPECTED_RECORD:",
8680 })
8681 }
8682
David Benjamin61672812016-07-14 23:10:43 -04008683 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8684 // messages in the handshake queue. Do this by testing the server
8685 // reading the client Finished, reversing the flight so Finished comes
8686 // first.
8687 testCases = append(testCases, testCase{
8688 protocol: dtls,
8689 testType: serverTest,
8690 name: "SendUnencryptedFinished-DTLS",
8691 config: Config{
8692 MaxVersion: VersionTLS12,
8693 Bugs: ProtocolBugs{
8694 SendUnencryptedFinished: true,
8695 ReverseHandshakeFragments: true,
8696 },
8697 },
8698 shouldFail: true,
8699 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8700 })
8701
Steven Valdez143e8b32016-07-11 13:19:03 -04008702 // Test synchronization between encryption changes and the handshake in
8703 // TLS 1.3, where ChangeCipherSpec is implicit.
8704 testCases = append(testCases, testCase{
8705 name: "PartialEncryptedExtensionsWithServerHello",
8706 config: Config{
8707 MaxVersion: VersionTLS13,
8708 Bugs: ProtocolBugs{
8709 PartialEncryptedExtensionsWithServerHello: true,
8710 },
8711 },
8712 shouldFail: true,
8713 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8714 })
8715 testCases = append(testCases, testCase{
8716 testType: serverTest,
8717 name: "PartialClientFinishedWithClientHello",
8718 config: Config{
8719 MaxVersion: VersionTLS13,
8720 Bugs: ProtocolBugs{
8721 PartialClientFinishedWithClientHello: true,
8722 },
8723 },
8724 shouldFail: true,
8725 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8726 })
8727
David Benjamin82261be2016-07-07 14:32:50 -07008728 // Test that early ChangeCipherSpecs are handled correctly.
8729 testCases = append(testCases, testCase{
8730 testType: serverTest,
8731 name: "EarlyChangeCipherSpec-server-1",
8732 config: Config{
8733 MaxVersion: VersionTLS12,
8734 Bugs: ProtocolBugs{
8735 EarlyChangeCipherSpec: 1,
8736 },
8737 },
8738 shouldFail: true,
8739 expectedError: ":UNEXPECTED_RECORD:",
8740 })
8741 testCases = append(testCases, testCase{
8742 testType: serverTest,
8743 name: "EarlyChangeCipherSpec-server-2",
8744 config: Config{
8745 MaxVersion: VersionTLS12,
8746 Bugs: ProtocolBugs{
8747 EarlyChangeCipherSpec: 2,
8748 },
8749 },
8750 shouldFail: true,
8751 expectedError: ":UNEXPECTED_RECORD:",
8752 })
8753 testCases = append(testCases, testCase{
8754 protocol: dtls,
8755 name: "StrayChangeCipherSpec",
8756 config: Config{
8757 // TODO(davidben): Once DTLS 1.3 exists, test
8758 // that stray ChangeCipherSpec messages are
8759 // rejected.
8760 MaxVersion: VersionTLS12,
8761 Bugs: ProtocolBugs{
8762 StrayChangeCipherSpec: true,
8763 },
8764 },
8765 })
8766
8767 // Test that the contents of ChangeCipherSpec are checked.
8768 testCases = append(testCases, testCase{
8769 name: "BadChangeCipherSpec-1",
8770 config: Config{
8771 MaxVersion: VersionTLS12,
8772 Bugs: ProtocolBugs{
8773 BadChangeCipherSpec: []byte{2},
8774 },
8775 },
8776 shouldFail: true,
8777 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8778 })
8779 testCases = append(testCases, testCase{
8780 name: "BadChangeCipherSpec-2",
8781 config: Config{
8782 MaxVersion: VersionTLS12,
8783 Bugs: ProtocolBugs{
8784 BadChangeCipherSpec: []byte{1, 1},
8785 },
8786 },
8787 shouldFail: true,
8788 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8789 })
8790 testCases = append(testCases, testCase{
8791 protocol: dtls,
8792 name: "BadChangeCipherSpec-DTLS-1",
8793 config: Config{
8794 MaxVersion: VersionTLS12,
8795 Bugs: ProtocolBugs{
8796 BadChangeCipherSpec: []byte{2},
8797 },
8798 },
8799 shouldFail: true,
8800 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8801 })
8802 testCases = append(testCases, testCase{
8803 protocol: dtls,
8804 name: "BadChangeCipherSpec-DTLS-2",
8805 config: Config{
8806 MaxVersion: VersionTLS12,
8807 Bugs: ProtocolBugs{
8808 BadChangeCipherSpec: []byte{1, 1},
8809 },
8810 },
8811 shouldFail: true,
8812 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8813 })
8814}
8815
David Benjamincd2c8062016-09-09 11:28:16 -04008816type perMessageTest struct {
8817 messageType uint8
8818 test testCase
8819}
8820
8821// makePerMessageTests returns a series of test templates which cover each
8822// message in the TLS handshake. These may be used with bugs like
8823// WrongMessageType to fully test a per-message bug.
8824func makePerMessageTests() []perMessageTest {
8825 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008826 for _, protocol := range []protocol{tls, dtls} {
8827 var suffix string
8828 if protocol == dtls {
8829 suffix = "-DTLS"
8830 }
8831
David Benjamincd2c8062016-09-09 11:28:16 -04008832 ret = append(ret, perMessageTest{
8833 messageType: typeClientHello,
8834 test: testCase{
8835 protocol: protocol,
8836 testType: serverTest,
8837 name: "ClientHello" + suffix,
8838 config: Config{
8839 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008840 },
8841 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008842 })
8843
8844 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008845 ret = append(ret, perMessageTest{
8846 messageType: typeHelloVerifyRequest,
8847 test: testCase{
8848 protocol: protocol,
8849 name: "HelloVerifyRequest" + suffix,
8850 config: Config{
8851 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008852 },
8853 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008854 })
8855 }
8856
David Benjamincd2c8062016-09-09 11:28:16 -04008857 ret = append(ret, perMessageTest{
8858 messageType: typeServerHello,
8859 test: testCase{
8860 protocol: protocol,
8861 name: "ServerHello" + suffix,
8862 config: Config{
8863 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008864 },
8865 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008866 })
8867
David Benjamincd2c8062016-09-09 11:28:16 -04008868 ret = append(ret, perMessageTest{
8869 messageType: typeCertificate,
8870 test: testCase{
8871 protocol: protocol,
8872 name: "ServerCertificate" + suffix,
8873 config: Config{
8874 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008875 },
8876 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008877 })
8878
David Benjamincd2c8062016-09-09 11:28:16 -04008879 ret = append(ret, perMessageTest{
8880 messageType: typeCertificateStatus,
8881 test: testCase{
8882 protocol: protocol,
8883 name: "CertificateStatus" + suffix,
8884 config: Config{
8885 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008886 },
David Benjamincd2c8062016-09-09 11:28:16 -04008887 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008888 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008889 })
8890
David Benjamincd2c8062016-09-09 11:28:16 -04008891 ret = append(ret, perMessageTest{
8892 messageType: typeServerKeyExchange,
8893 test: testCase{
8894 protocol: protocol,
8895 name: "ServerKeyExchange" + suffix,
8896 config: Config{
8897 MaxVersion: VersionTLS12,
8898 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008899 },
8900 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008901 })
8902
David Benjamincd2c8062016-09-09 11:28:16 -04008903 ret = append(ret, perMessageTest{
8904 messageType: typeCertificateRequest,
8905 test: testCase{
8906 protocol: protocol,
8907 name: "CertificateRequest" + suffix,
8908 config: Config{
8909 MaxVersion: VersionTLS12,
8910 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008911 },
8912 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008913 })
8914
David Benjamincd2c8062016-09-09 11:28:16 -04008915 ret = append(ret, perMessageTest{
8916 messageType: typeServerHelloDone,
8917 test: testCase{
8918 protocol: protocol,
8919 name: "ServerHelloDone" + suffix,
8920 config: Config{
8921 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008922 },
8923 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008924 })
8925
David Benjamincd2c8062016-09-09 11:28:16 -04008926 ret = append(ret, perMessageTest{
8927 messageType: typeCertificate,
8928 test: testCase{
8929 testType: serverTest,
8930 protocol: protocol,
8931 name: "ClientCertificate" + suffix,
8932 config: Config{
8933 Certificates: []Certificate{rsaCertificate},
8934 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008935 },
David Benjamincd2c8062016-09-09 11:28:16 -04008936 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008937 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008938 })
8939
David Benjamincd2c8062016-09-09 11:28:16 -04008940 ret = append(ret, perMessageTest{
8941 messageType: typeCertificateVerify,
8942 test: testCase{
8943 testType: serverTest,
8944 protocol: protocol,
8945 name: "CertificateVerify" + suffix,
8946 config: Config{
8947 Certificates: []Certificate{rsaCertificate},
8948 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008949 },
David Benjamincd2c8062016-09-09 11:28:16 -04008950 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008951 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008952 })
8953
David Benjamincd2c8062016-09-09 11:28:16 -04008954 ret = append(ret, perMessageTest{
8955 messageType: typeClientKeyExchange,
8956 test: testCase{
8957 testType: serverTest,
8958 protocol: protocol,
8959 name: "ClientKeyExchange" + suffix,
8960 config: Config{
8961 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008962 },
8963 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008964 })
8965
8966 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008967 ret = append(ret, perMessageTest{
8968 messageType: typeNextProtocol,
8969 test: testCase{
8970 testType: serverTest,
8971 protocol: protocol,
8972 name: "NextProtocol" + suffix,
8973 config: Config{
8974 MaxVersion: VersionTLS12,
8975 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008976 },
David Benjamincd2c8062016-09-09 11:28:16 -04008977 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008978 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008979 })
8980
David Benjamincd2c8062016-09-09 11:28:16 -04008981 ret = append(ret, perMessageTest{
8982 messageType: typeChannelID,
8983 test: testCase{
8984 testType: serverTest,
8985 protocol: protocol,
8986 name: "ChannelID" + suffix,
8987 config: Config{
8988 MaxVersion: VersionTLS12,
8989 ChannelID: channelIDKey,
8990 },
8991 flags: []string{
8992 "-expect-channel-id",
8993 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008994 },
8995 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008996 })
8997 }
8998
David Benjamincd2c8062016-09-09 11:28:16 -04008999 ret = append(ret, perMessageTest{
9000 messageType: typeFinished,
9001 test: testCase{
9002 testType: serverTest,
9003 protocol: protocol,
9004 name: "ClientFinished" + suffix,
9005 config: Config{
9006 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009007 },
9008 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009009 })
9010
David Benjamincd2c8062016-09-09 11:28:16 -04009011 ret = append(ret, perMessageTest{
9012 messageType: typeNewSessionTicket,
9013 test: testCase{
9014 protocol: protocol,
9015 name: "NewSessionTicket" + suffix,
9016 config: Config{
9017 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009018 },
9019 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009020 })
9021
David Benjamincd2c8062016-09-09 11:28:16 -04009022 ret = append(ret, perMessageTest{
9023 messageType: typeFinished,
9024 test: testCase{
9025 protocol: protocol,
9026 name: "ServerFinished" + suffix,
9027 config: Config{
9028 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009029 },
9030 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009031 })
9032
9033 }
David Benjamincd2c8062016-09-09 11:28:16 -04009034
9035 ret = append(ret, perMessageTest{
9036 messageType: typeClientHello,
9037 test: testCase{
9038 testType: serverTest,
9039 name: "TLS13-ClientHello",
9040 config: Config{
9041 MaxVersion: VersionTLS13,
9042 },
9043 },
9044 })
9045
9046 ret = append(ret, perMessageTest{
9047 messageType: typeServerHello,
9048 test: testCase{
9049 name: "TLS13-ServerHello",
9050 config: Config{
9051 MaxVersion: VersionTLS13,
9052 },
9053 },
9054 })
9055
9056 ret = append(ret, perMessageTest{
9057 messageType: typeEncryptedExtensions,
9058 test: testCase{
9059 name: "TLS13-EncryptedExtensions",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 },
9063 },
9064 })
9065
9066 ret = append(ret, perMessageTest{
9067 messageType: typeCertificateRequest,
9068 test: testCase{
9069 name: "TLS13-CertificateRequest",
9070 config: Config{
9071 MaxVersion: VersionTLS13,
9072 ClientAuth: RequireAnyClientCert,
9073 },
9074 },
9075 })
9076
9077 ret = append(ret, perMessageTest{
9078 messageType: typeCertificate,
9079 test: testCase{
9080 name: "TLS13-ServerCertificate",
9081 config: Config{
9082 MaxVersion: VersionTLS13,
9083 },
9084 },
9085 })
9086
9087 ret = append(ret, perMessageTest{
9088 messageType: typeCertificateVerify,
9089 test: testCase{
9090 name: "TLS13-ServerCertificateVerify",
9091 config: Config{
9092 MaxVersion: VersionTLS13,
9093 },
9094 },
9095 })
9096
9097 ret = append(ret, perMessageTest{
9098 messageType: typeFinished,
9099 test: testCase{
9100 name: "TLS13-ServerFinished",
9101 config: Config{
9102 MaxVersion: VersionTLS13,
9103 },
9104 },
9105 })
9106
9107 ret = append(ret, perMessageTest{
9108 messageType: typeCertificate,
9109 test: testCase{
9110 testType: serverTest,
9111 name: "TLS13-ClientCertificate",
9112 config: Config{
9113 Certificates: []Certificate{rsaCertificate},
9114 MaxVersion: VersionTLS13,
9115 },
9116 flags: []string{"-require-any-client-certificate"},
9117 },
9118 })
9119
9120 ret = append(ret, perMessageTest{
9121 messageType: typeCertificateVerify,
9122 test: testCase{
9123 testType: serverTest,
9124 name: "TLS13-ClientCertificateVerify",
9125 config: Config{
9126 Certificates: []Certificate{rsaCertificate},
9127 MaxVersion: VersionTLS13,
9128 },
9129 flags: []string{"-require-any-client-certificate"},
9130 },
9131 })
9132
9133 ret = append(ret, perMessageTest{
9134 messageType: typeFinished,
9135 test: testCase{
9136 testType: serverTest,
9137 name: "TLS13-ClientFinished",
9138 config: Config{
9139 MaxVersion: VersionTLS13,
9140 },
9141 },
9142 })
9143
9144 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009145}
9146
David Benjamincd2c8062016-09-09 11:28:16 -04009147func addWrongMessageTypeTests() {
9148 for _, t := range makePerMessageTests() {
9149 t.test.name = "WrongMessageType-" + t.test.name
9150 t.test.config.Bugs.SendWrongMessageType = t.messageType
9151 t.test.shouldFail = true
9152 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9153 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009154
David Benjamincd2c8062016-09-09 11:28:16 -04009155 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9156 // In TLS 1.3, a bad ServerHello means the client sends
9157 // an unencrypted alert while the server expects
9158 // encryption, so the alert is not readable by runner.
9159 t.test.expectedLocalError = "local error: bad record MAC"
9160 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009161
David Benjamincd2c8062016-09-09 11:28:16 -04009162 testCases = append(testCases, t.test)
9163 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009164}
9165
David Benjamin639846e2016-09-09 11:41:18 -04009166func addTrailingMessageDataTests() {
9167 for _, t := range makePerMessageTests() {
9168 t.test.name = "TrailingMessageData-" + t.test.name
9169 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9170 t.test.shouldFail = true
9171 t.test.expectedError = ":DECODE_ERROR:"
9172 t.test.expectedLocalError = "remote error: error decoding message"
9173
9174 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9175 // In TLS 1.3, a bad ServerHello means the client sends
9176 // an unencrypted alert while the server expects
9177 // encryption, so the alert is not readable by runner.
9178 t.test.expectedLocalError = "local error: bad record MAC"
9179 }
9180
9181 if t.messageType == typeFinished {
9182 // Bad Finished messages read as the verify data having
9183 // the wrong length.
9184 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9185 t.test.expectedLocalError = "remote error: error decrypting message"
9186 }
9187
9188 testCases = append(testCases, t.test)
9189 }
9190}
9191
Steven Valdez143e8b32016-07-11 13:19:03 -04009192func addTLS13HandshakeTests() {
9193 testCases = append(testCases, testCase{
9194 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009195 name: "NegotiatePSKResumption-TLS13",
9196 config: Config{
9197 MaxVersion: VersionTLS13,
9198 Bugs: ProtocolBugs{
9199 NegotiatePSKResumption: true,
9200 },
9201 },
9202 resumeSession: true,
9203 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009204 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009205 })
9206
9207 testCases = append(testCases, testCase{
9208 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009209 name: "MissingKeyShare-Client",
9210 config: Config{
9211 MaxVersion: VersionTLS13,
9212 Bugs: ProtocolBugs{
9213 MissingKeyShare: true,
9214 },
9215 },
9216 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009217 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009218 })
9219
9220 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009221 testType: serverTest,
9222 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009223 config: Config{
9224 MaxVersion: VersionTLS13,
9225 Bugs: ProtocolBugs{
9226 MissingKeyShare: true,
9227 },
9228 },
9229 shouldFail: true,
9230 expectedError: ":MISSING_KEY_SHARE:",
9231 })
9232
9233 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009234 testType: serverTest,
9235 name: "DuplicateKeyShares",
9236 config: Config{
9237 MaxVersion: VersionTLS13,
9238 Bugs: ProtocolBugs{
9239 DuplicateKeyShares: true,
9240 },
9241 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009242 shouldFail: true,
9243 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009244 })
9245
9246 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009247 testType: serverTest,
9248 name: "SkipEarlyData",
9249 config: Config{
9250 MaxVersion: VersionTLS13,
9251 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009252 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009253 },
9254 },
9255 })
9256
9257 testCases = append(testCases, testCase{
9258 testType: serverTest,
9259 name: "SkipEarlyData-OmitEarlyDataExtension",
9260 config: Config{
9261 MaxVersion: VersionTLS13,
9262 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009263 SendFakeEarlyDataLength: 4,
9264 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009265 },
9266 },
9267 shouldFail: true,
9268 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9269 })
9270
9271 testCases = append(testCases, testCase{
9272 testType: serverTest,
9273 name: "SkipEarlyData-TooMuchData",
9274 config: Config{
9275 MaxVersion: VersionTLS13,
9276 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009277 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009278 },
9279 },
9280 shouldFail: true,
9281 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9282 })
9283
9284 testCases = append(testCases, testCase{
9285 testType: serverTest,
9286 name: "SkipEarlyData-Interleaved",
9287 config: Config{
9288 MaxVersion: VersionTLS13,
9289 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009290 SendFakeEarlyDataLength: 4,
9291 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009292 },
9293 },
9294 shouldFail: true,
9295 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9296 })
9297
9298 testCases = append(testCases, testCase{
9299 testType: serverTest,
9300 name: "SkipEarlyData-EarlyDataInTLS12",
9301 config: Config{
9302 MaxVersion: VersionTLS13,
9303 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009304 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009305 },
9306 },
9307 shouldFail: true,
9308 expectedError: ":UNEXPECTED_RECORD:",
9309 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9310 })
9311
9312 testCases = append(testCases, testCase{
9313 testType: serverTest,
9314 name: "SkipEarlyData-HRR",
9315 config: Config{
9316 MaxVersion: VersionTLS13,
9317 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009318 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009319 },
9320 DefaultCurves: []CurveID{},
9321 },
9322 })
9323
9324 testCases = append(testCases, testCase{
9325 testType: serverTest,
9326 name: "SkipEarlyData-HRR-Interleaved",
9327 config: Config{
9328 MaxVersion: VersionTLS13,
9329 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009330 SendFakeEarlyDataLength: 4,
9331 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009332 },
9333 DefaultCurves: []CurveID{},
9334 },
9335 shouldFail: true,
9336 expectedError: ":UNEXPECTED_RECORD:",
9337 })
9338
9339 testCases = append(testCases, testCase{
9340 testType: serverTest,
9341 name: "SkipEarlyData-HRR-TooMuchData",
9342 config: Config{
9343 MaxVersion: VersionTLS13,
9344 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009345 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009346 },
9347 DefaultCurves: []CurveID{},
9348 },
9349 shouldFail: true,
9350 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9351 })
9352
9353 // Test that skipping early data looking for cleartext correctly
9354 // processes an alert record.
9355 testCases = append(testCases, testCase{
9356 testType: serverTest,
9357 name: "SkipEarlyData-HRR-FatalAlert",
9358 config: Config{
9359 MaxVersion: VersionTLS13,
9360 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009361 SendEarlyAlert: true,
9362 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009363 },
9364 DefaultCurves: []CurveID{},
9365 },
9366 shouldFail: true,
9367 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9368 })
9369
9370 testCases = append(testCases, testCase{
9371 testType: serverTest,
9372 name: "SkipEarlyData-SecondClientHelloEarlyData",
9373 config: Config{
9374 MaxVersion: VersionTLS13,
9375 Bugs: ProtocolBugs{
9376 SendEarlyDataOnSecondClientHello: true,
9377 },
9378 DefaultCurves: []CurveID{},
9379 },
9380 shouldFail: true,
9381 expectedLocalError: "remote error: bad record MAC",
9382 })
9383
9384 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009385 testType: clientTest,
9386 name: "EmptyEncryptedExtensions",
9387 config: Config{
9388 MaxVersion: VersionTLS13,
9389 Bugs: ProtocolBugs{
9390 EmptyEncryptedExtensions: true,
9391 },
9392 },
9393 shouldFail: true,
9394 expectedLocalError: "remote error: error decoding message",
9395 })
9396
9397 testCases = append(testCases, testCase{
9398 testType: clientTest,
9399 name: "EncryptedExtensionsWithKeyShare",
9400 config: Config{
9401 MaxVersion: VersionTLS13,
9402 Bugs: ProtocolBugs{
9403 EncryptedExtensionsWithKeyShare: true,
9404 },
9405 },
9406 shouldFail: true,
9407 expectedLocalError: "remote error: unsupported extension",
9408 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009409
9410 testCases = append(testCases, testCase{
9411 testType: serverTest,
9412 name: "SendHelloRetryRequest",
9413 config: Config{
9414 MaxVersion: VersionTLS13,
9415 // Require a HelloRetryRequest for every curve.
9416 DefaultCurves: []CurveID{},
9417 },
9418 expectedCurveID: CurveX25519,
9419 })
9420
9421 testCases = append(testCases, testCase{
9422 testType: serverTest,
9423 name: "SendHelloRetryRequest-2",
9424 config: Config{
9425 MaxVersion: VersionTLS13,
9426 DefaultCurves: []CurveID{CurveP384},
9427 },
9428 // Although the ClientHello did not predict our preferred curve,
9429 // we always select it whether it is predicted or not.
9430 expectedCurveID: CurveX25519,
9431 })
9432
9433 testCases = append(testCases, testCase{
9434 name: "UnknownCurve-HelloRetryRequest",
9435 config: Config{
9436 MaxVersion: VersionTLS13,
9437 // P-384 requires HelloRetryRequest in BoringSSL.
9438 CurvePreferences: []CurveID{CurveP384},
9439 Bugs: ProtocolBugs{
9440 SendHelloRetryRequestCurve: bogusCurve,
9441 },
9442 },
9443 shouldFail: true,
9444 expectedError: ":WRONG_CURVE:",
9445 })
9446
9447 testCases = append(testCases, testCase{
9448 name: "DisabledCurve-HelloRetryRequest",
9449 config: Config{
9450 MaxVersion: VersionTLS13,
9451 CurvePreferences: []CurveID{CurveP256},
9452 Bugs: ProtocolBugs{
9453 IgnorePeerCurvePreferences: true,
9454 },
9455 },
9456 flags: []string{"-p384-only"},
9457 shouldFail: true,
9458 expectedError: ":WRONG_CURVE:",
9459 })
9460
9461 testCases = append(testCases, testCase{
9462 name: "UnnecessaryHelloRetryRequest",
9463 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009464 MaxVersion: VersionTLS13,
9465 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009466 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009467 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009468 },
9469 },
9470 shouldFail: true,
9471 expectedError: ":WRONG_CURVE:",
9472 })
9473
9474 testCases = append(testCases, testCase{
9475 name: "SecondHelloRetryRequest",
9476 config: Config{
9477 MaxVersion: VersionTLS13,
9478 // P-384 requires HelloRetryRequest in BoringSSL.
9479 CurvePreferences: []CurveID{CurveP384},
9480 Bugs: ProtocolBugs{
9481 SecondHelloRetryRequest: true,
9482 },
9483 },
9484 shouldFail: true,
9485 expectedError: ":UNEXPECTED_MESSAGE:",
9486 })
9487
9488 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009489 name: "HelloRetryRequest-Empty",
9490 config: Config{
9491 MaxVersion: VersionTLS13,
9492 Bugs: ProtocolBugs{
9493 AlwaysSendHelloRetryRequest: true,
9494 },
9495 },
9496 shouldFail: true,
9497 expectedError: ":DECODE_ERROR:",
9498 })
9499
9500 testCases = append(testCases, testCase{
9501 name: "HelloRetryRequest-DuplicateCurve",
9502 config: Config{
9503 MaxVersion: VersionTLS13,
9504 // P-384 requires a HelloRetryRequest against BoringSSL's default
9505 // configuration. Assert this ExpectMissingKeyShare.
9506 CurvePreferences: []CurveID{CurveP384},
9507 Bugs: ProtocolBugs{
9508 ExpectMissingKeyShare: true,
9509 DuplicateHelloRetryRequestExtensions: true,
9510 },
9511 },
9512 shouldFail: true,
9513 expectedError: ":DUPLICATE_EXTENSION:",
9514 expectedLocalError: "remote error: illegal parameter",
9515 })
9516
9517 testCases = append(testCases, testCase{
9518 name: "HelloRetryRequest-Cookie",
9519 config: Config{
9520 MaxVersion: VersionTLS13,
9521 Bugs: ProtocolBugs{
9522 SendHelloRetryRequestCookie: []byte("cookie"),
9523 },
9524 },
9525 })
9526
9527 testCases = append(testCases, testCase{
9528 name: "HelloRetryRequest-DuplicateCookie",
9529 config: Config{
9530 MaxVersion: VersionTLS13,
9531 Bugs: ProtocolBugs{
9532 SendHelloRetryRequestCookie: []byte("cookie"),
9533 DuplicateHelloRetryRequestExtensions: true,
9534 },
9535 },
9536 shouldFail: true,
9537 expectedError: ":DUPLICATE_EXTENSION:",
9538 expectedLocalError: "remote error: illegal parameter",
9539 })
9540
9541 testCases = append(testCases, testCase{
9542 name: "HelloRetryRequest-EmptyCookie",
9543 config: Config{
9544 MaxVersion: VersionTLS13,
9545 Bugs: ProtocolBugs{
9546 SendHelloRetryRequestCookie: []byte{},
9547 },
9548 },
9549 shouldFail: true,
9550 expectedError: ":DECODE_ERROR:",
9551 })
9552
9553 testCases = append(testCases, testCase{
9554 name: "HelloRetryRequest-Cookie-Curve",
9555 config: Config{
9556 MaxVersion: VersionTLS13,
9557 // P-384 requires HelloRetryRequest in BoringSSL.
9558 CurvePreferences: []CurveID{CurveP384},
9559 Bugs: ProtocolBugs{
9560 SendHelloRetryRequestCookie: []byte("cookie"),
9561 ExpectMissingKeyShare: true,
9562 },
9563 },
9564 })
9565
9566 testCases = append(testCases, testCase{
9567 name: "HelloRetryRequest-Unknown",
9568 config: Config{
9569 MaxVersion: VersionTLS13,
9570 Bugs: ProtocolBugs{
9571 CustomHelloRetryRequestExtension: "extension",
9572 },
9573 },
9574 shouldFail: true,
9575 expectedError: ":UNEXPECTED_EXTENSION:",
9576 expectedLocalError: "remote error: unsupported extension",
9577 })
9578
9579 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009580 testType: serverTest,
9581 name: "SecondClientHelloMissingKeyShare",
9582 config: Config{
9583 MaxVersion: VersionTLS13,
9584 DefaultCurves: []CurveID{},
9585 Bugs: ProtocolBugs{
9586 SecondClientHelloMissingKeyShare: true,
9587 },
9588 },
9589 shouldFail: true,
9590 expectedError: ":MISSING_KEY_SHARE:",
9591 })
9592
9593 testCases = append(testCases, testCase{
9594 testType: serverTest,
9595 name: "SecondClientHelloWrongCurve",
9596 config: Config{
9597 MaxVersion: VersionTLS13,
9598 DefaultCurves: []CurveID{},
9599 Bugs: ProtocolBugs{
9600 MisinterpretHelloRetryRequestCurve: CurveP521,
9601 },
9602 },
9603 shouldFail: true,
9604 expectedError: ":WRONG_CURVE:",
9605 })
9606
9607 testCases = append(testCases, testCase{
9608 name: "HelloRetryRequestVersionMismatch",
9609 config: Config{
9610 MaxVersion: VersionTLS13,
9611 // P-384 requires HelloRetryRequest in BoringSSL.
9612 CurvePreferences: []CurveID{CurveP384},
9613 Bugs: ProtocolBugs{
9614 SendServerHelloVersion: 0x0305,
9615 },
9616 },
9617 shouldFail: true,
9618 expectedError: ":WRONG_VERSION_NUMBER:",
9619 })
9620
9621 testCases = append(testCases, testCase{
9622 name: "HelloRetryRequestCurveMismatch",
9623 config: Config{
9624 MaxVersion: VersionTLS13,
9625 // P-384 requires HelloRetryRequest in BoringSSL.
9626 CurvePreferences: []CurveID{CurveP384},
9627 Bugs: ProtocolBugs{
9628 // Send P-384 (correct) in the HelloRetryRequest.
9629 SendHelloRetryRequestCurve: CurveP384,
9630 // But send P-256 in the ServerHello.
9631 SendCurve: CurveP256,
9632 },
9633 },
9634 shouldFail: true,
9635 expectedError: ":WRONG_CURVE:",
9636 })
9637
9638 // Test the server selecting a curve that requires a HelloRetryRequest
9639 // without sending it.
9640 testCases = append(testCases, testCase{
9641 name: "SkipHelloRetryRequest",
9642 config: Config{
9643 MaxVersion: VersionTLS13,
9644 // P-384 requires HelloRetryRequest in BoringSSL.
9645 CurvePreferences: []CurveID{CurveP384},
9646 Bugs: ProtocolBugs{
9647 SkipHelloRetryRequest: true,
9648 },
9649 },
9650 shouldFail: true,
9651 expectedError: ":WRONG_CURVE:",
9652 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009653
9654 testCases = append(testCases, testCase{
9655 name: "TLS13-RequestContextInHandshake",
9656 config: Config{
9657 MaxVersion: VersionTLS13,
9658 MinVersion: VersionTLS13,
9659 ClientAuth: RequireAnyClientCert,
9660 Bugs: ProtocolBugs{
9661 SendRequestContext: []byte("request context"),
9662 },
9663 },
9664 flags: []string{
9665 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9666 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9667 },
9668 shouldFail: true,
9669 expectedError: ":DECODE_ERROR:",
9670 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009671
9672 testCases = append(testCases, testCase{
9673 testType: serverTest,
9674 name: "TLS13-TrailingKeyShareData",
9675 config: Config{
9676 MaxVersion: VersionTLS13,
9677 Bugs: ProtocolBugs{
9678 TrailingKeyShareData: true,
9679 },
9680 },
9681 shouldFail: true,
9682 expectedError: ":DECODE_ERROR:",
9683 })
David Benjamin7f78df42016-10-05 22:33:19 -04009684
9685 testCases = append(testCases, testCase{
9686 name: "TLS13-AlwaysSelectPSKIdentity",
9687 config: Config{
9688 MaxVersion: VersionTLS13,
9689 Bugs: ProtocolBugs{
9690 AlwaysSelectPSKIdentity: true,
9691 },
9692 },
9693 shouldFail: true,
9694 expectedError: ":UNEXPECTED_EXTENSION:",
9695 })
9696
9697 testCases = append(testCases, testCase{
9698 name: "TLS13-InvalidPSKIdentity",
9699 config: Config{
9700 MaxVersion: VersionTLS13,
9701 Bugs: ProtocolBugs{
9702 SelectPSKIdentityOnResume: 1,
9703 },
9704 },
9705 resumeSession: true,
9706 shouldFail: true,
9707 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9708 })
David Benjamin1286bee2016-10-07 15:25:06 -04009709
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009710 testCases = append(testCases, testCase{
9711 testType: serverTest,
9712 name: "TLS13-ExtraPSKIdentity",
9713 config: Config{
9714 MaxVersion: VersionTLS13,
9715 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009716 ExtraPSKIdentity: true,
9717 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009718 },
9719 },
9720 resumeSession: true,
9721 })
9722
David Benjamin1286bee2016-10-07 15:25:06 -04009723 // Test that unknown NewSessionTicket extensions are tolerated.
9724 testCases = append(testCases, testCase{
9725 name: "TLS13-CustomTicketExtension",
9726 config: Config{
9727 MaxVersion: VersionTLS13,
9728 Bugs: ProtocolBugs{
9729 CustomTicketExtension: "1234",
9730 },
9731 },
9732 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009733}
9734
David Benjaminabbbee12016-10-31 19:20:42 -04009735func addTLS13CipherPreferenceTests() {
9736 // Test that client preference is honored if the shim has AES hardware
9737 // and ChaCha20-Poly1305 is preferred otherwise.
9738 testCases = append(testCases, testCase{
9739 testType: serverTest,
9740 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9741 config: Config{
9742 MaxVersion: VersionTLS13,
9743 CipherSuites: []uint16{
9744 TLS_CHACHA20_POLY1305_SHA256,
9745 TLS_AES_128_GCM_SHA256,
9746 },
9747 },
9748 flags: []string{
9749 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9750 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9751 },
9752 })
9753
9754 testCases = append(testCases, testCase{
9755 testType: serverTest,
9756 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9757 config: Config{
9758 MaxVersion: VersionTLS13,
9759 CipherSuites: []uint16{
9760 TLS_AES_128_GCM_SHA256,
9761 TLS_CHACHA20_POLY1305_SHA256,
9762 },
9763 },
9764 flags: []string{
9765 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9766 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9767 },
9768 })
9769
9770 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9771 // whether it has AES hardware.
9772 testCases = append(testCases, testCase{
9773 name: "TLS13-CipherPreference-Client",
9774 config: Config{
9775 MaxVersion: VersionTLS13,
9776 // Use the client cipher order. (This is the default but
9777 // is listed to be explicit.)
9778 PreferServerCipherSuites: false,
9779 },
9780 flags: []string{
9781 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9782 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9783 },
9784 })
9785}
9786
David Benjaminf3fbade2016-09-19 13:08:16 -04009787func addPeekTests() {
9788 // Test SSL_peek works, including on empty records.
9789 testCases = append(testCases, testCase{
9790 name: "Peek-Basic",
9791 sendEmptyRecords: 1,
9792 flags: []string{"-peek-then-read"},
9793 })
9794
9795 // Test SSL_peek can drive the initial handshake.
9796 testCases = append(testCases, testCase{
9797 name: "Peek-ImplicitHandshake",
9798 flags: []string{
9799 "-peek-then-read",
9800 "-implicit-handshake",
9801 },
9802 })
9803
9804 // Test SSL_peek can discover and drive a renegotiation.
9805 testCases = append(testCases, testCase{
9806 name: "Peek-Renegotiate",
9807 config: Config{
9808 MaxVersion: VersionTLS12,
9809 },
9810 renegotiate: 1,
9811 flags: []string{
9812 "-peek-then-read",
9813 "-renegotiate-freely",
9814 "-expect-total-renegotiations", "1",
9815 },
9816 })
9817
9818 // Test SSL_peek can discover a close_notify.
9819 testCases = append(testCases, testCase{
9820 name: "Peek-Shutdown",
9821 config: Config{
9822 Bugs: ProtocolBugs{
9823 ExpectCloseNotify: true,
9824 },
9825 },
9826 flags: []string{
9827 "-peek-then-read",
9828 "-check-close-notify",
9829 },
9830 })
9831
9832 // Test SSL_peek can discover an alert.
9833 testCases = append(testCases, testCase{
9834 name: "Peek-Alert",
9835 config: Config{
9836 Bugs: ProtocolBugs{
9837 SendSpuriousAlert: alertRecordOverflow,
9838 },
9839 },
9840 flags: []string{"-peek-then-read"},
9841 shouldFail: true,
9842 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9843 })
9844
9845 // Test SSL_peek can handle KeyUpdate.
9846 testCases = append(testCases, testCase{
9847 name: "Peek-KeyUpdate",
9848 config: Config{
9849 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009850 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009851 sendKeyUpdates: 1,
9852 keyUpdateRequest: keyUpdateNotRequested,
9853 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009854 })
9855}
9856
David Benjamine6f22212016-11-08 14:28:24 -05009857func addRecordVersionTests() {
9858 for _, ver := range tlsVersions {
9859 // Test that the record version is enforced.
9860 testCases = append(testCases, testCase{
9861 name: "CheckRecordVersion-" + ver.name,
9862 config: Config{
9863 MinVersion: ver.version,
9864 MaxVersion: ver.version,
9865 Bugs: ProtocolBugs{
9866 SendRecordVersion: 0x03ff,
9867 },
9868 },
9869 shouldFail: true,
9870 expectedError: ":WRONG_VERSION_NUMBER:",
9871 })
9872
9873 // Test that the ClientHello may use any record version, for
9874 // compatibility reasons.
9875 testCases = append(testCases, testCase{
9876 testType: serverTest,
9877 name: "LooseInitialRecordVersion-" + ver.name,
9878 config: Config{
9879 MinVersion: ver.version,
9880 MaxVersion: ver.version,
9881 Bugs: ProtocolBugs{
9882 SendInitialRecordVersion: 0x03ff,
9883 },
9884 },
9885 })
9886
9887 // Test that garbage ClientHello record versions are rejected.
9888 testCases = append(testCases, testCase{
9889 testType: serverTest,
9890 name: "GarbageInitialRecordVersion-" + ver.name,
9891 config: Config{
9892 MinVersion: ver.version,
9893 MaxVersion: ver.version,
9894 Bugs: ProtocolBugs{
9895 SendInitialRecordVersion: 0xffff,
9896 },
9897 },
9898 shouldFail: true,
9899 expectedError: ":WRONG_VERSION_NUMBER:",
9900 })
9901 }
9902}
9903
David Benjamin2c516452016-11-15 10:16:54 +09009904func addCertificateTests() {
9905 // Test that a certificate chain with intermediate may be sent and
9906 // received as both client and server.
9907 for _, ver := range tlsVersions {
9908 testCases = append(testCases, testCase{
9909 testType: clientTest,
9910 name: "SendReceiveIntermediate-Client-" + ver.name,
9911 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009912 MinVersion: ver.version,
9913 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009914 Certificates: []Certificate{rsaChainCertificate},
9915 ClientAuth: RequireAnyClientCert,
9916 },
9917 expectPeerCertificate: &rsaChainCertificate,
9918 flags: []string{
9919 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9920 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9921 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9922 },
9923 })
9924
9925 testCases = append(testCases, testCase{
9926 testType: serverTest,
9927 name: "SendReceiveIntermediate-Server-" + ver.name,
9928 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009929 MinVersion: ver.version,
9930 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009931 Certificates: []Certificate{rsaChainCertificate},
9932 },
9933 expectPeerCertificate: &rsaChainCertificate,
9934 flags: []string{
9935 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9936 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9937 "-require-any-client-certificate",
9938 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9939 },
9940 })
9941 }
9942}
9943
David Benjaminbbaf3672016-11-17 10:53:09 +09009944func addRetainOnlySHA256ClientCertTests() {
9945 for _, ver := range tlsVersions {
9946 // Test that enabling
9947 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9948 // actually requesting a client certificate is a no-op.
9949 testCases = append(testCases, testCase{
9950 testType: serverTest,
9951 name: "RetainOnlySHA256-NoCert-" + ver.name,
9952 config: Config{
9953 MinVersion: ver.version,
9954 MaxVersion: ver.version,
9955 },
9956 flags: []string{
9957 "-retain-only-sha256-client-cert-initial",
9958 "-retain-only-sha256-client-cert-resume",
9959 },
9960 resumeSession: true,
9961 })
9962
9963 // Test that when retaining only a SHA-256 certificate is
9964 // enabled, the hash appears as expected.
9965 testCases = append(testCases, testCase{
9966 testType: serverTest,
9967 name: "RetainOnlySHA256-Cert-" + ver.name,
9968 config: Config{
9969 MinVersion: ver.version,
9970 MaxVersion: ver.version,
9971 Certificates: []Certificate{rsaCertificate},
9972 },
9973 flags: []string{
9974 "-verify-peer",
9975 "-retain-only-sha256-client-cert-initial",
9976 "-retain-only-sha256-client-cert-resume",
9977 "-expect-sha256-client-cert-initial",
9978 "-expect-sha256-client-cert-resume",
9979 },
9980 resumeSession: true,
9981 })
9982
9983 // Test that when the config changes from on to off, a
9984 // resumption is rejected because the server now wants the full
9985 // certificate chain.
9986 testCases = append(testCases, testCase{
9987 testType: serverTest,
9988 name: "RetainOnlySHA256-OnOff-" + ver.name,
9989 config: Config{
9990 MinVersion: ver.version,
9991 MaxVersion: ver.version,
9992 Certificates: []Certificate{rsaCertificate},
9993 },
9994 flags: []string{
9995 "-verify-peer",
9996 "-retain-only-sha256-client-cert-initial",
9997 "-expect-sha256-client-cert-initial",
9998 },
9999 resumeSession: true,
10000 expectResumeRejected: true,
10001 })
10002
10003 // Test that when the config changes from off to on, a
10004 // resumption is rejected because the server now wants just the
10005 // hash.
10006 testCases = append(testCases, testCase{
10007 testType: serverTest,
10008 name: "RetainOnlySHA256-OffOn-" + ver.name,
10009 config: Config{
10010 MinVersion: ver.version,
10011 MaxVersion: ver.version,
10012 Certificates: []Certificate{rsaCertificate},
10013 },
10014 flags: []string{
10015 "-verify-peer",
10016 "-retain-only-sha256-client-cert-resume",
10017 "-expect-sha256-client-cert-resume",
10018 },
10019 resumeSession: true,
10020 expectResumeRejected: true,
10021 })
10022 }
10023}
10024
Adam Langleya4b91982016-12-12 12:05:53 -080010025func addECDSAKeyUsageTests() {
10026 p256 := elliptic.P256()
10027 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10028 if err != nil {
10029 panic(err)
10030 }
10031
10032 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10033 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10034 if err != nil {
10035 panic(err)
10036 }
10037
10038 template := x509.Certificate{
10039 SerialNumber: serialNumber,
10040 Subject: pkix.Name{
10041 Organization: []string{"Acme Co"},
10042 },
10043 NotBefore: time.Now(),
10044 NotAfter: time.Now(),
10045
10046 // An ECC certificate with only the keyAgreement key usgae may
10047 // be used with ECDH, but not ECDSA.
10048 KeyUsage: x509.KeyUsageKeyAgreement,
10049 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10050 BasicConstraintsValid: true,
10051 }
10052
10053 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10054 if err != nil {
10055 panic(err)
10056 }
10057
10058 cert := Certificate{
10059 Certificate: [][]byte{derBytes},
10060 PrivateKey: priv,
10061 }
10062
10063 for _, ver := range tlsVersions {
10064 if ver.version < VersionTLS12 {
10065 continue
10066 }
10067
10068 testCases = append(testCases, testCase{
10069 testType: clientTest,
10070 name: "ECDSAKeyUsage-" + ver.name,
10071 config: Config{
10072 MinVersion: ver.version,
10073 MaxVersion: ver.version,
10074 Certificates: []Certificate{cert},
10075 },
10076 shouldFail: true,
10077 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10078 })
10079 }
10080}
10081
David Benjamin6f600d62016-12-21 16:06:54 -050010082func addShortHeaderTests() {
10083 // The short header extension may be negotiated as either client or
10084 // server.
10085 testCases = append(testCases, testCase{
10086 name: "ShortHeader-Client",
10087 config: Config{
10088 MaxVersion: VersionTLS13,
10089 Bugs: ProtocolBugs{
10090 EnableShortHeader: true,
10091 },
10092 },
10093 flags: []string{"-enable-short-header"},
10094 expectShortHeader: true,
10095 })
10096 testCases = append(testCases, testCase{
10097 testType: serverTest,
10098 name: "ShortHeader-Server",
10099 config: Config{
10100 MaxVersion: VersionTLS13,
10101 Bugs: ProtocolBugs{
10102 EnableShortHeader: true,
10103 },
10104 },
10105 flags: []string{"-enable-short-header"},
10106 expectShortHeader: true,
10107 })
10108
10109 // If the peer doesn't support it, it will not be negotiated.
10110 testCases = append(testCases, testCase{
10111 name: "ShortHeader-No-Yes-Client",
10112 config: Config{
10113 MaxVersion: VersionTLS13,
10114 },
10115 flags: []string{"-enable-short-header"},
10116 })
10117 testCases = append(testCases, testCase{
10118 testType: serverTest,
10119 name: "ShortHeader-No-Yes-Server",
10120 config: Config{
10121 MaxVersion: VersionTLS13,
10122 },
10123 flags: []string{"-enable-short-header"},
10124 })
10125
10126 // If we don't support it, it will not be negotiated.
10127 testCases = append(testCases, testCase{
10128 name: "ShortHeader-Yes-No-Client",
10129 config: Config{
10130 MaxVersion: VersionTLS13,
10131 Bugs: ProtocolBugs{
10132 EnableShortHeader: true,
10133 },
10134 },
10135 })
10136 testCases = append(testCases, testCase{
10137 testType: serverTest,
10138 name: "ShortHeader-Yes-No-Server",
10139 config: Config{
10140 MaxVersion: VersionTLS13,
10141 Bugs: ProtocolBugs{
10142 EnableShortHeader: true,
10143 },
10144 },
10145 })
10146
10147 // It will not be negotiated at TLS 1.2.
10148 testCases = append(testCases, testCase{
10149 name: "ShortHeader-TLS12-Client",
10150 config: Config{
10151 MaxVersion: VersionTLS12,
10152 Bugs: ProtocolBugs{
10153 EnableShortHeader: true,
10154 },
10155 },
10156 flags: []string{"-enable-short-header"},
10157 })
10158 testCases = append(testCases, testCase{
10159 testType: serverTest,
10160 name: "ShortHeader-TLS12-Server",
10161 config: Config{
10162 MaxVersion: VersionTLS12,
10163 Bugs: ProtocolBugs{
10164 EnableShortHeader: true,
10165 },
10166 },
10167 flags: []string{"-enable-short-header"},
10168 })
10169
10170 // Servers reject early data and short header sent together.
10171 testCases = append(testCases, testCase{
10172 testType: serverTest,
10173 name: "ShortHeader-EarlyData",
10174 config: Config{
10175 MaxVersion: VersionTLS13,
10176 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010177 EnableShortHeader: true,
10178 SendFakeEarlyDataLength: 1,
David Benjamin6f600d62016-12-21 16:06:54 -050010179 },
10180 },
10181 flags: []string{"-enable-short-header"},
10182 shouldFail: true,
10183 expectedError: ":UNEXPECTED_EXTENSION:",
10184 })
10185
10186 // Clients reject unsolicited short header extensions.
10187 testCases = append(testCases, testCase{
10188 name: "ShortHeader-Unsolicited",
10189 config: Config{
10190 MaxVersion: VersionTLS13,
10191 Bugs: ProtocolBugs{
10192 AlwaysNegotiateShortHeader: true,
10193 },
10194 },
10195 shouldFail: true,
10196 expectedError: ":UNEXPECTED_EXTENSION:",
10197 })
10198 testCases = append(testCases, testCase{
10199 name: "ShortHeader-Unsolicited-TLS12",
10200 config: Config{
10201 MaxVersion: VersionTLS12,
10202 Bugs: ProtocolBugs{
10203 AlwaysNegotiateShortHeader: true,
10204 },
10205 },
10206 shouldFail: true,
10207 expectedError: ":UNEXPECTED_EXTENSION:",
10208 })
10209
10210 // The high bit must be checked in short headers.
10211 testCases = append(testCases, testCase{
10212 name: "ShortHeader-ClearShortHeaderBit",
10213 config: Config{
10214 Bugs: ProtocolBugs{
10215 EnableShortHeader: true,
10216 ClearShortHeaderBit: true,
10217 },
10218 },
10219 flags: []string{"-enable-short-header"},
10220 shouldFail: true,
10221 expectedError: ":DECODE_ERROR:",
10222 expectedLocalError: "remote error: error decoding message",
10223 })
10224}
10225
Adam Langley7c803a62015-06-15 15:35:05 -070010226func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010227 defer wg.Done()
10228
10229 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010230 var err error
10231
David Benjaminba28dfc2016-11-15 17:47:21 +090010232 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010233 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10234 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010235 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010236 if err != nil {
10237 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10238 }
10239 break
10240 }
10241 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010242 } else if *repeatUntilFailure {
10243 for err == nil {
10244 statusChan <- statusMsg{test: test, started: true}
10245 err = runTest(test, shimPath, -1)
10246 }
10247 } else {
10248 statusChan <- statusMsg{test: test, started: true}
10249 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010250 }
Adam Langley95c29f32014-06-20 12:00:00 -070010251 statusChan <- statusMsg{test: test, err: err}
10252 }
10253}
10254
10255type statusMsg struct {
10256 test *testCase
10257 started bool
10258 err error
10259}
10260
David Benjamin5f237bc2015-02-11 17:14:15 -050010261func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010262 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010263
David Benjamin5f237bc2015-02-11 17:14:15 -050010264 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010265 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010266 if !*pipe {
10267 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010268 var erase string
10269 for i := 0; i < lineLen; i++ {
10270 erase += "\b \b"
10271 }
10272 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010273 }
10274
Adam Langley95c29f32014-06-20 12:00:00 -070010275 if msg.started {
10276 started++
10277 } else {
10278 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010279
10280 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010281 if msg.err == errUnimplemented {
10282 if *pipe {
10283 // Print each test instead of a status line.
10284 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10285 }
10286 unimplemented++
10287 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10288 } else {
10289 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10290 failed++
10291 testOutput.addResult(msg.test.name, "FAIL")
10292 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010293 } else {
10294 if *pipe {
10295 // Print each test instead of a status line.
10296 fmt.Printf("PASSED (%s)\n", msg.test.name)
10297 }
10298 testOutput.addResult(msg.test.name, "PASS")
10299 }
Adam Langley95c29f32014-06-20 12:00:00 -070010300 }
10301
David Benjamin5f237bc2015-02-11 17:14:15 -050010302 if !*pipe {
10303 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010304 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010305 lineLen = len(line)
10306 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010307 }
Adam Langley95c29f32014-06-20 12:00:00 -070010308 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010309
10310 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010311}
10312
10313func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010314 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010315 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010316 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010317
Adam Langley7c803a62015-06-15 15:35:05 -070010318 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010319 addCipherSuiteTests()
10320 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010321 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010322 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010323 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010324 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010325 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010326 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010327 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010328 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010329 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010330 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010331 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010332 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010333 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010334 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010335 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010336 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010337 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010338 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010339 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010340 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010341 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010342 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010343 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010344 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010345 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010346 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010347 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010348 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010349 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010350 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010351 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010352 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010353
10354 var wg sync.WaitGroup
10355
Adam Langley7c803a62015-06-15 15:35:05 -070010356 statusChan := make(chan statusMsg, *numWorkers)
10357 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010358 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010359
EKRf71d7ed2016-08-06 13:25:12 -070010360 if len(*shimConfigFile) != 0 {
10361 encoded, err := ioutil.ReadFile(*shimConfigFile)
10362 if err != nil {
10363 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10364 os.Exit(1)
10365 }
10366
10367 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10368 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10369 os.Exit(1)
10370 }
10371 }
10372
David Benjamin025b3d32014-07-01 19:53:04 -040010373 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010374
Adam Langley7c803a62015-06-15 15:35:05 -070010375 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010376 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010377 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010378 }
10379
David Benjamin270f0a72016-03-17 14:41:36 -040010380 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010381 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010382 matched := true
10383 if len(*testToRun) != 0 {
10384 var err error
10385 matched, err = filepath.Match(*testToRun, testCases[i].name)
10386 if err != nil {
10387 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10388 os.Exit(1)
10389 }
10390 }
10391
EKRf71d7ed2016-08-06 13:25:12 -070010392 if !*includeDisabled {
10393 for pattern := range shimConfig.DisabledTests {
10394 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10395 if err != nil {
10396 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10397 os.Exit(1)
10398 }
10399
10400 if isDisabled {
10401 matched = false
10402 break
10403 }
10404 }
10405 }
10406
David Benjamin17e12922016-07-28 18:04:43 -040010407 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010408 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010409 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010410
10411 // Only run one test if repeating until failure.
10412 if *repeatUntilFailure {
10413 break
10414 }
Adam Langley95c29f32014-06-20 12:00:00 -070010415 }
10416 }
David Benjamin17e12922016-07-28 18:04:43 -040010417
David Benjamin270f0a72016-03-17 14:41:36 -040010418 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010419 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010420 os.Exit(1)
10421 }
Adam Langley95c29f32014-06-20 12:00:00 -070010422
10423 close(testChan)
10424 wg.Wait()
10425 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010426 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010427
10428 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010429
10430 if *jsonOutput != "" {
10431 if err := testOutput.writeTo(*jsonOutput); err != nil {
10432 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10433 }
10434 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010435
EKR842ae6c2016-07-27 09:22:05 +020010436 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10437 os.Exit(1)
10438 }
10439
10440 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010441 os.Exit(1)
10442 }
Adam Langley95c29f32014-06-20 12:00:00 -070010443}