blob: 5c3d914e0d6aabf59f260eeb2fb0030e5896272c [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},
David Benjamine3203922015-12-09 21:21:31 -05001106 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001107 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001108 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001109 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001110 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001111 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001112 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001113 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001114 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
David Benjamin48cae082014-10-27 01:06:24 -04001115 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1116 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001117 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1118 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001119 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001120 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1121 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1122 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001123 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001124}
1125
David Benjamin8b8c0062014-11-23 02:47:52 -05001126func hasComponent(suiteName, component string) bool {
1127 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1128}
1129
David Benjaminf7768e42014-08-31 02:06:47 -04001130func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001131 return hasComponent(suiteName, "GCM") ||
1132 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001133 hasComponent(suiteName, "SHA384") ||
1134 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001135}
1136
Nick Harper1fd39d82016-06-14 18:14:35 -07001137func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001138 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001139}
1140
David Benjamin8b8c0062014-11-23 02:47:52 -05001141func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001142 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001143}
1144
Adam Langleya7997f12015-05-14 17:38:50 -07001145func bigFromHex(hex string) *big.Int {
1146 ret, ok := new(big.Int).SetString(hex, 16)
1147 if !ok {
1148 panic("failed to parse hex number 0x" + hex)
1149 }
1150 return ret
1151}
1152
Adam Langley7c803a62015-06-15 15:35:05 -07001153func addBasicTests() {
1154 basicTests := []testCase{
1155 {
Adam Langley7c803a62015-06-15 15:35:05 -07001156 name: "NoFallbackSCSV",
1157 config: Config{
1158 Bugs: ProtocolBugs{
1159 FailIfNotFallbackSCSV: true,
1160 },
1161 },
1162 shouldFail: true,
1163 expectedLocalError: "no fallback SCSV found",
1164 },
1165 {
1166 name: "SendFallbackSCSV",
1167 config: Config{
1168 Bugs: ProtocolBugs{
1169 FailIfNotFallbackSCSV: true,
1170 },
1171 },
1172 flags: []string{"-fallback-scsv"},
1173 },
1174 {
1175 name: "ClientCertificateTypes",
1176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001177 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001178 ClientAuth: RequestClientCert,
1179 ClientCertificateTypes: []byte{
1180 CertTypeDSSSign,
1181 CertTypeRSASign,
1182 CertTypeECDSASign,
1183 },
1184 },
1185 flags: []string{
1186 "-expect-certificate-types",
1187 base64.StdEncoding.EncodeToString([]byte{
1188 CertTypeDSSSign,
1189 CertTypeRSASign,
1190 CertTypeECDSASign,
1191 }),
1192 },
1193 },
1194 {
Adam Langley7c803a62015-06-15 15:35:05 -07001195 name: "UnauthenticatedECDH",
1196 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001197 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001198 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1199 Bugs: ProtocolBugs{
1200 UnauthenticatedECDH: true,
1201 },
1202 },
1203 shouldFail: true,
1204 expectedError: ":UNEXPECTED_MESSAGE:",
1205 },
1206 {
1207 name: "SkipCertificateStatus",
1208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001209 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001210 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1211 Bugs: ProtocolBugs{
1212 SkipCertificateStatus: true,
1213 },
1214 },
1215 flags: []string{
1216 "-enable-ocsp-stapling",
1217 },
1218 },
1219 {
1220 name: "SkipServerKeyExchange",
1221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001222 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001223 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1224 Bugs: ProtocolBugs{
1225 SkipServerKeyExchange: true,
1226 },
1227 },
1228 shouldFail: true,
1229 expectedError: ":UNEXPECTED_MESSAGE:",
1230 },
1231 {
Adam Langley7c803a62015-06-15 15:35:05 -07001232 testType: serverTest,
1233 name: "Alert",
1234 config: Config{
1235 Bugs: ProtocolBugs{
1236 SendSpuriousAlert: alertRecordOverflow,
1237 },
1238 },
1239 shouldFail: true,
1240 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1241 },
1242 {
1243 protocol: dtls,
1244 testType: serverTest,
1245 name: "Alert-DTLS",
1246 config: Config{
1247 Bugs: ProtocolBugs{
1248 SendSpuriousAlert: alertRecordOverflow,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1253 },
1254 {
1255 testType: serverTest,
1256 name: "FragmentAlert",
1257 config: Config{
1258 Bugs: ProtocolBugs{
1259 FragmentAlert: true,
1260 SendSpuriousAlert: alertRecordOverflow,
1261 },
1262 },
1263 shouldFail: true,
1264 expectedError: ":BAD_ALERT:",
1265 },
1266 {
1267 protocol: dtls,
1268 testType: serverTest,
1269 name: "FragmentAlert-DTLS",
1270 config: Config{
1271 Bugs: ProtocolBugs{
1272 FragmentAlert: true,
1273 SendSpuriousAlert: alertRecordOverflow,
1274 },
1275 },
1276 shouldFail: true,
1277 expectedError: ":BAD_ALERT:",
1278 },
1279 {
1280 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001281 name: "DoubleAlert",
1282 config: Config{
1283 Bugs: ProtocolBugs{
1284 DoubleAlert: true,
1285 SendSpuriousAlert: alertRecordOverflow,
1286 },
1287 },
1288 shouldFail: true,
1289 expectedError: ":BAD_ALERT:",
1290 },
1291 {
1292 protocol: dtls,
1293 testType: serverTest,
1294 name: "DoubleAlert-DTLS",
1295 config: Config{
1296 Bugs: ProtocolBugs{
1297 DoubleAlert: true,
1298 SendSpuriousAlert: alertRecordOverflow,
1299 },
1300 },
1301 shouldFail: true,
1302 expectedError: ":BAD_ALERT:",
1303 },
1304 {
Adam Langley7c803a62015-06-15 15:35:05 -07001305 name: "SkipNewSessionTicket",
1306 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001307 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001308 Bugs: ProtocolBugs{
1309 SkipNewSessionTicket: true,
1310 },
1311 },
1312 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001313 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001314 },
1315 {
1316 testType: serverTest,
1317 name: "FallbackSCSV",
1318 config: Config{
1319 MaxVersion: VersionTLS11,
1320 Bugs: ProtocolBugs{
1321 SendFallbackSCSV: true,
1322 },
1323 },
David Benjamin56cadc32016-12-16 19:54:11 -05001324 shouldFail: true,
1325 expectedError: ":INAPPROPRIATE_FALLBACK:",
1326 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001327 },
1328 {
1329 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001330 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001331 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001332 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001333 Bugs: ProtocolBugs{
1334 SendFallbackSCSV: true,
1335 },
1336 },
1337 },
1338 {
1339 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001340 name: "FallbackSCSV-VersionMatch-TLS12",
1341 config: Config{
1342 MaxVersion: VersionTLS12,
1343 Bugs: ProtocolBugs{
1344 SendFallbackSCSV: true,
1345 },
1346 },
1347 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1348 },
1349 {
1350 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001351 name: "FragmentedClientVersion",
1352 config: Config{
1353 Bugs: ProtocolBugs{
1354 MaxHandshakeRecordLength: 1,
1355 FragmentClientVersion: true,
1356 },
1357 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001358 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001359 },
1360 {
Adam Langley7c803a62015-06-15 15:35:05 -07001361 testType: serverTest,
1362 name: "HttpGET",
1363 sendPrefix: "GET / HTTP/1.0\n",
1364 shouldFail: true,
1365 expectedError: ":HTTP_REQUEST:",
1366 },
1367 {
1368 testType: serverTest,
1369 name: "HttpPOST",
1370 sendPrefix: "POST / HTTP/1.0\n",
1371 shouldFail: true,
1372 expectedError: ":HTTP_REQUEST:",
1373 },
1374 {
1375 testType: serverTest,
1376 name: "HttpHEAD",
1377 sendPrefix: "HEAD / HTTP/1.0\n",
1378 shouldFail: true,
1379 expectedError: ":HTTP_REQUEST:",
1380 },
1381 {
1382 testType: serverTest,
1383 name: "HttpPUT",
1384 sendPrefix: "PUT / HTTP/1.0\n",
1385 shouldFail: true,
1386 expectedError: ":HTTP_REQUEST:",
1387 },
1388 {
1389 testType: serverTest,
1390 name: "HttpCONNECT",
1391 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1392 shouldFail: true,
1393 expectedError: ":HTTPS_PROXY_REQUEST:",
1394 },
1395 {
1396 testType: serverTest,
1397 name: "Garbage",
1398 sendPrefix: "blah",
1399 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001400 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001401 },
1402 {
Adam Langley7c803a62015-06-15 15:35:05 -07001403 name: "RSAEphemeralKey",
1404 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001405 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001406 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1407 Bugs: ProtocolBugs{
1408 RSAEphemeralKey: true,
1409 },
1410 },
1411 shouldFail: true,
1412 expectedError: ":UNEXPECTED_MESSAGE:",
1413 },
1414 {
1415 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001416 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001417 shouldFail: true,
1418 expectedError: ":WRONG_SSL_VERSION:",
1419 },
1420 {
1421 protocol: dtls,
1422 name: "DisableEverything-DTLS",
1423 flags: []string{"-no-tls12", "-no-tls1"},
1424 shouldFail: true,
1425 expectedError: ":WRONG_SSL_VERSION:",
1426 },
1427 {
Adam Langley7c803a62015-06-15 15:35:05 -07001428 protocol: dtls,
1429 testType: serverTest,
1430 name: "MTU",
1431 config: Config{
1432 Bugs: ProtocolBugs{
1433 MaxPacketLength: 256,
1434 },
1435 },
1436 flags: []string{"-mtu", "256"},
1437 },
1438 {
1439 protocol: dtls,
1440 testType: serverTest,
1441 name: "MTUExceeded",
1442 config: Config{
1443 Bugs: ProtocolBugs{
1444 MaxPacketLength: 255,
1445 },
1446 },
1447 flags: []string{"-mtu", "256"},
1448 shouldFail: true,
1449 expectedLocalError: "dtls: exceeded maximum packet length",
1450 },
1451 {
1452 name: "CertMismatchRSA",
1453 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001454 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001455 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001456 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001457 Bugs: ProtocolBugs{
1458 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1459 },
1460 },
1461 shouldFail: true,
1462 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1463 },
1464 {
1465 name: "CertMismatchECDSA",
1466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001467 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001468 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001469 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001470 Bugs: ProtocolBugs{
1471 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1472 },
1473 },
1474 shouldFail: true,
1475 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1476 },
1477 {
1478 name: "EmptyCertificateList",
1479 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001480 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001481 Bugs: ProtocolBugs{
1482 EmptyCertificateList: true,
1483 },
1484 },
1485 shouldFail: true,
1486 expectedError: ":DECODE_ERROR:",
1487 },
1488 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001489 name: "EmptyCertificateList-TLS13",
1490 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001491 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001492 Bugs: ProtocolBugs{
1493 EmptyCertificateList: true,
1494 },
1495 },
1496 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001497 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001498 },
1499 {
Adam Langley7c803a62015-06-15 15:35:05 -07001500 name: "TLSFatalBadPackets",
1501 damageFirstWrite: true,
1502 shouldFail: true,
1503 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1504 },
1505 {
1506 protocol: dtls,
1507 name: "DTLSIgnoreBadPackets",
1508 damageFirstWrite: true,
1509 },
1510 {
1511 protocol: dtls,
1512 name: "DTLSIgnoreBadPackets-Async",
1513 damageFirstWrite: true,
1514 flags: []string{"-async"},
1515 },
1516 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001517 name: "AppDataBeforeHandshake",
1518 config: Config{
1519 Bugs: ProtocolBugs{
1520 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1521 },
1522 },
1523 shouldFail: true,
1524 expectedError: ":UNEXPECTED_RECORD:",
1525 },
1526 {
1527 name: "AppDataBeforeHandshake-Empty",
1528 config: Config{
1529 Bugs: ProtocolBugs{
1530 AppDataBeforeHandshake: []byte{},
1531 },
1532 },
1533 shouldFail: true,
1534 expectedError: ":UNEXPECTED_RECORD:",
1535 },
1536 {
1537 protocol: dtls,
1538 name: "AppDataBeforeHandshake-DTLS",
1539 config: Config{
1540 Bugs: ProtocolBugs{
1541 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1542 },
1543 },
1544 shouldFail: true,
1545 expectedError: ":UNEXPECTED_RECORD:",
1546 },
1547 {
1548 protocol: dtls,
1549 name: "AppDataBeforeHandshake-DTLS-Empty",
1550 config: Config{
1551 Bugs: ProtocolBugs{
1552 AppDataBeforeHandshake: []byte{},
1553 },
1554 },
1555 shouldFail: true,
1556 expectedError: ":UNEXPECTED_RECORD:",
1557 },
1558 {
Adam Langley7c803a62015-06-15 15:35:05 -07001559 name: "AppDataAfterChangeCipherSpec",
1560 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001561 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001562 Bugs: ProtocolBugs{
1563 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1564 },
1565 },
1566 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001567 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001568 },
1569 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001570 name: "AppDataAfterChangeCipherSpec-Empty",
1571 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001572 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001573 Bugs: ProtocolBugs{
1574 AppDataAfterChangeCipherSpec: []byte{},
1575 },
1576 },
1577 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001578 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001579 },
1580 {
Adam Langley7c803a62015-06-15 15:35:05 -07001581 protocol: dtls,
1582 name: "AppDataAfterChangeCipherSpec-DTLS",
1583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001584 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001585 Bugs: ProtocolBugs{
1586 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1587 },
1588 },
1589 // BoringSSL's DTLS implementation will drop the out-of-order
1590 // application data.
1591 },
1592 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001593 protocol: dtls,
1594 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001596 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001597 Bugs: ProtocolBugs{
1598 AppDataAfterChangeCipherSpec: []byte{},
1599 },
1600 },
1601 // BoringSSL's DTLS implementation will drop the out-of-order
1602 // application data.
1603 },
1604 {
Adam Langley7c803a62015-06-15 15:35:05 -07001605 name: "AlertAfterChangeCipherSpec",
1606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001607 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001608 Bugs: ProtocolBugs{
1609 AlertAfterChangeCipherSpec: alertRecordOverflow,
1610 },
1611 },
1612 shouldFail: true,
1613 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1614 },
1615 {
1616 protocol: dtls,
1617 name: "AlertAfterChangeCipherSpec-DTLS",
1618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001619 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001620 Bugs: ProtocolBugs{
1621 AlertAfterChangeCipherSpec: alertRecordOverflow,
1622 },
1623 },
1624 shouldFail: true,
1625 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1626 },
1627 {
1628 protocol: dtls,
1629 name: "ReorderHandshakeFragments-Small-DTLS",
1630 config: Config{
1631 Bugs: ProtocolBugs{
1632 ReorderHandshakeFragments: true,
1633 // Small enough that every handshake message is
1634 // fragmented.
1635 MaxHandshakeRecordLength: 2,
1636 },
1637 },
1638 },
1639 {
1640 protocol: dtls,
1641 name: "ReorderHandshakeFragments-Large-DTLS",
1642 config: Config{
1643 Bugs: ProtocolBugs{
1644 ReorderHandshakeFragments: true,
1645 // Large enough that no handshake message is
1646 // fragmented.
1647 MaxHandshakeRecordLength: 2048,
1648 },
1649 },
1650 },
1651 {
1652 protocol: dtls,
1653 name: "MixCompleteMessageWithFragments-DTLS",
1654 config: Config{
1655 Bugs: ProtocolBugs{
1656 ReorderHandshakeFragments: true,
1657 MixCompleteMessageWithFragments: true,
1658 MaxHandshakeRecordLength: 2,
1659 },
1660 },
1661 },
1662 {
1663 name: "SendInvalidRecordType",
1664 config: Config{
1665 Bugs: ProtocolBugs{
1666 SendInvalidRecordType: true,
1667 },
1668 },
1669 shouldFail: true,
1670 expectedError: ":UNEXPECTED_RECORD:",
1671 },
1672 {
1673 protocol: dtls,
1674 name: "SendInvalidRecordType-DTLS",
1675 config: Config{
1676 Bugs: ProtocolBugs{
1677 SendInvalidRecordType: true,
1678 },
1679 },
1680 shouldFail: true,
1681 expectedError: ":UNEXPECTED_RECORD:",
1682 },
1683 {
1684 name: "FalseStart-SkipServerSecondLeg",
1685 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001686 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001687 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1688 NextProtos: []string{"foo"},
1689 Bugs: ProtocolBugs{
1690 SkipNewSessionTicket: true,
1691 SkipChangeCipherSpec: true,
1692 SkipFinished: true,
1693 ExpectFalseStart: true,
1694 },
1695 },
1696 flags: []string{
1697 "-false-start",
1698 "-handshake-never-done",
1699 "-advertise-alpn", "\x03foo",
1700 },
1701 shimWritesFirst: true,
1702 shouldFail: true,
1703 expectedError: ":UNEXPECTED_RECORD:",
1704 },
1705 {
1706 name: "FalseStart-SkipServerSecondLeg-Implicit",
1707 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001708 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001709 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1710 NextProtos: []string{"foo"},
1711 Bugs: ProtocolBugs{
1712 SkipNewSessionTicket: true,
1713 SkipChangeCipherSpec: true,
1714 SkipFinished: true,
1715 },
1716 },
1717 flags: []string{
1718 "-implicit-handshake",
1719 "-false-start",
1720 "-handshake-never-done",
1721 "-advertise-alpn", "\x03foo",
1722 },
1723 shouldFail: true,
1724 expectedError: ":UNEXPECTED_RECORD:",
1725 },
1726 {
1727 testType: serverTest,
1728 name: "FailEarlyCallback",
1729 flags: []string{"-fail-early-callback"},
1730 shouldFail: true,
1731 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001732 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001733 },
1734 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001735 name: "FailCertCallback-Client-TLS12",
1736 config: Config{
1737 MaxVersion: VersionTLS12,
1738 ClientAuth: RequestClientCert,
1739 },
1740 flags: []string{"-fail-cert-callback"},
1741 shouldFail: true,
1742 expectedError: ":CERT_CB_ERROR:",
1743 expectedLocalError: "remote error: internal error",
1744 },
1745 {
1746 testType: serverTest,
1747 name: "FailCertCallback-Server-TLS12",
1748 config: Config{
1749 MaxVersion: VersionTLS12,
1750 },
1751 flags: []string{"-fail-cert-callback"},
1752 shouldFail: true,
1753 expectedError: ":CERT_CB_ERROR:",
1754 expectedLocalError: "remote error: internal error",
1755 },
1756 {
1757 name: "FailCertCallback-Client-TLS13",
1758 config: Config{
1759 MaxVersion: VersionTLS13,
1760 ClientAuth: RequestClientCert,
1761 },
1762 flags: []string{"-fail-cert-callback"},
1763 shouldFail: true,
1764 expectedError: ":CERT_CB_ERROR:",
1765 expectedLocalError: "remote error: internal error",
1766 },
1767 {
1768 testType: serverTest,
1769 name: "FailCertCallback-Server-TLS13",
1770 config: Config{
1771 MaxVersion: VersionTLS13,
1772 },
1773 flags: []string{"-fail-cert-callback"},
1774 shouldFail: true,
1775 expectedError: ":CERT_CB_ERROR:",
1776 expectedLocalError: "remote error: internal error",
1777 },
1778 {
Adam Langley7c803a62015-06-15 15:35:05 -07001779 protocol: dtls,
1780 name: "FragmentMessageTypeMismatch-DTLS",
1781 config: Config{
1782 Bugs: ProtocolBugs{
1783 MaxHandshakeRecordLength: 2,
1784 FragmentMessageTypeMismatch: true,
1785 },
1786 },
1787 shouldFail: true,
1788 expectedError: ":FRAGMENT_MISMATCH:",
1789 },
1790 {
1791 protocol: dtls,
1792 name: "FragmentMessageLengthMismatch-DTLS",
1793 config: Config{
1794 Bugs: ProtocolBugs{
1795 MaxHandshakeRecordLength: 2,
1796 FragmentMessageLengthMismatch: true,
1797 },
1798 },
1799 shouldFail: true,
1800 expectedError: ":FRAGMENT_MISMATCH:",
1801 },
1802 {
1803 protocol: dtls,
1804 name: "SplitFragments-Header-DTLS",
1805 config: Config{
1806 Bugs: ProtocolBugs{
1807 SplitFragments: 2,
1808 },
1809 },
1810 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001811 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001812 },
1813 {
1814 protocol: dtls,
1815 name: "SplitFragments-Boundary-DTLS",
1816 config: Config{
1817 Bugs: ProtocolBugs{
1818 SplitFragments: dtlsRecordHeaderLen,
1819 },
1820 },
1821 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001822 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001823 },
1824 {
1825 protocol: dtls,
1826 name: "SplitFragments-Body-DTLS",
1827 config: Config{
1828 Bugs: ProtocolBugs{
1829 SplitFragments: dtlsRecordHeaderLen + 1,
1830 },
1831 },
1832 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001833 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001834 },
1835 {
1836 protocol: dtls,
1837 name: "SendEmptyFragments-DTLS",
1838 config: Config{
1839 Bugs: ProtocolBugs{
1840 SendEmptyFragments: true,
1841 },
1842 },
1843 },
1844 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001845 name: "BadFinished-Client",
1846 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001847 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001848 Bugs: ProtocolBugs{
1849 BadFinished: true,
1850 },
1851 },
1852 shouldFail: true,
1853 expectedError: ":DIGEST_CHECK_FAILED:",
1854 },
1855 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001856 name: "BadFinished-Client-TLS13",
1857 config: Config{
1858 MaxVersion: VersionTLS13,
1859 Bugs: ProtocolBugs{
1860 BadFinished: true,
1861 },
1862 },
1863 shouldFail: true,
1864 expectedError: ":DIGEST_CHECK_FAILED:",
1865 },
1866 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001867 testType: serverTest,
1868 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001870 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001871 Bugs: ProtocolBugs{
1872 BadFinished: true,
1873 },
1874 },
1875 shouldFail: true,
1876 expectedError: ":DIGEST_CHECK_FAILED:",
1877 },
1878 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001879 testType: serverTest,
1880 name: "BadFinished-Server-TLS13",
1881 config: Config{
1882 MaxVersion: VersionTLS13,
1883 Bugs: ProtocolBugs{
1884 BadFinished: true,
1885 },
1886 },
1887 shouldFail: true,
1888 expectedError: ":DIGEST_CHECK_FAILED:",
1889 },
1890 {
Adam Langley7c803a62015-06-15 15:35:05 -07001891 name: "FalseStart-BadFinished",
1892 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001893 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001894 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1895 NextProtos: []string{"foo"},
1896 Bugs: ProtocolBugs{
1897 BadFinished: true,
1898 ExpectFalseStart: true,
1899 },
1900 },
1901 flags: []string{
1902 "-false-start",
1903 "-handshake-never-done",
1904 "-advertise-alpn", "\x03foo",
1905 },
1906 shimWritesFirst: true,
1907 shouldFail: true,
1908 expectedError: ":DIGEST_CHECK_FAILED:",
1909 },
1910 {
1911 name: "NoFalseStart-NoALPN",
1912 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001913 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001914 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1915 Bugs: ProtocolBugs{
1916 ExpectFalseStart: true,
1917 AlertBeforeFalseStartTest: alertAccessDenied,
1918 },
1919 },
1920 flags: []string{
1921 "-false-start",
1922 },
1923 shimWritesFirst: true,
1924 shouldFail: true,
1925 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1926 expectedLocalError: "tls: peer did not false start: EOF",
1927 },
1928 {
1929 name: "NoFalseStart-NoAEAD",
1930 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001931 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001932 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1933 NextProtos: []string{"foo"},
1934 Bugs: ProtocolBugs{
1935 ExpectFalseStart: true,
1936 AlertBeforeFalseStartTest: alertAccessDenied,
1937 },
1938 },
1939 flags: []string{
1940 "-false-start",
1941 "-advertise-alpn", "\x03foo",
1942 },
1943 shimWritesFirst: true,
1944 shouldFail: true,
1945 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1946 expectedLocalError: "tls: peer did not false start: EOF",
1947 },
1948 {
1949 name: "NoFalseStart-RSA",
1950 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001951 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001952 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1953 NextProtos: []string{"foo"},
1954 Bugs: ProtocolBugs{
1955 ExpectFalseStart: true,
1956 AlertBeforeFalseStartTest: alertAccessDenied,
1957 },
1958 },
1959 flags: []string{
1960 "-false-start",
1961 "-advertise-alpn", "\x03foo",
1962 },
1963 shimWritesFirst: true,
1964 shouldFail: true,
1965 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1966 expectedLocalError: "tls: peer did not false start: EOF",
1967 },
1968 {
1969 name: "NoFalseStart-DHE_RSA",
1970 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001971 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001972 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1973 NextProtos: []string{"foo"},
1974 Bugs: ProtocolBugs{
1975 ExpectFalseStart: true,
1976 AlertBeforeFalseStartTest: alertAccessDenied,
1977 },
1978 },
1979 flags: []string{
1980 "-false-start",
1981 "-advertise-alpn", "\x03foo",
1982 },
1983 shimWritesFirst: true,
1984 shouldFail: true,
1985 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1986 expectedLocalError: "tls: peer did not false start: EOF",
1987 },
1988 {
Adam Langley7c803a62015-06-15 15:35:05 -07001989 protocol: dtls,
1990 name: "SendSplitAlert-Sync",
1991 config: Config{
1992 Bugs: ProtocolBugs{
1993 SendSplitAlert: true,
1994 },
1995 },
1996 },
1997 {
1998 protocol: dtls,
1999 name: "SendSplitAlert-Async",
2000 config: Config{
2001 Bugs: ProtocolBugs{
2002 SendSplitAlert: true,
2003 },
2004 },
2005 flags: []string{"-async"},
2006 },
2007 {
2008 protocol: dtls,
2009 name: "PackDTLSHandshake",
2010 config: Config{
2011 Bugs: ProtocolBugs{
2012 MaxHandshakeRecordLength: 2,
2013 PackHandshakeFragments: 20,
2014 PackHandshakeRecords: 200,
2015 },
2016 },
2017 },
2018 {
Adam Langley7c803a62015-06-15 15:35:05 -07002019 name: "SendEmptyRecords-Pass",
2020 sendEmptyRecords: 32,
2021 },
2022 {
2023 name: "SendEmptyRecords",
2024 sendEmptyRecords: 33,
2025 shouldFail: true,
2026 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2027 },
2028 {
2029 name: "SendEmptyRecords-Async",
2030 sendEmptyRecords: 33,
2031 flags: []string{"-async"},
2032 shouldFail: true,
2033 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2034 },
2035 {
David Benjamine8e84b92016-08-03 15:39:47 -04002036 name: "SendWarningAlerts-Pass",
2037 config: Config{
2038 MaxVersion: VersionTLS12,
2039 },
Adam Langley7c803a62015-06-15 15:35:05 -07002040 sendWarningAlerts: 4,
2041 },
2042 {
David Benjamine8e84b92016-08-03 15:39:47 -04002043 protocol: dtls,
2044 name: "SendWarningAlerts-DTLS-Pass",
2045 config: Config{
2046 MaxVersion: VersionTLS12,
2047 },
Adam Langley7c803a62015-06-15 15:35:05 -07002048 sendWarningAlerts: 4,
2049 },
2050 {
David Benjamine8e84b92016-08-03 15:39:47 -04002051 name: "SendWarningAlerts-TLS13",
2052 config: Config{
2053 MaxVersion: VersionTLS13,
2054 },
2055 sendWarningAlerts: 4,
2056 shouldFail: true,
2057 expectedError: ":BAD_ALERT:",
2058 expectedLocalError: "remote error: error decoding message",
2059 },
2060 {
2061 name: "SendWarningAlerts",
2062 config: Config{
2063 MaxVersion: VersionTLS12,
2064 },
Adam Langley7c803a62015-06-15 15:35:05 -07002065 sendWarningAlerts: 5,
2066 shouldFail: true,
2067 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2068 },
2069 {
David Benjamine8e84b92016-08-03 15:39:47 -04002070 name: "SendWarningAlerts-Async",
2071 config: Config{
2072 MaxVersion: VersionTLS12,
2073 },
Adam Langley7c803a62015-06-15 15:35:05 -07002074 sendWarningAlerts: 5,
2075 flags: []string{"-async"},
2076 shouldFail: true,
2077 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2078 },
David Benjaminba4594a2015-06-18 18:36:15 -04002079 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002080 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002081 config: Config{
2082 MaxVersion: VersionTLS13,
2083 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002084 sendKeyUpdates: 33,
2085 keyUpdateRequest: keyUpdateNotRequested,
2086 shouldFail: true,
2087 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002088 },
2089 {
David Benjaminba4594a2015-06-18 18:36:15 -04002090 name: "EmptySessionID",
2091 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002092 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002093 SessionTicketsDisabled: true,
2094 },
2095 noSessionCache: true,
2096 flags: []string{"-expect-no-session"},
2097 },
David Benjamin30789da2015-08-29 22:56:45 -04002098 {
2099 name: "Unclean-Shutdown",
2100 config: Config{
2101 Bugs: ProtocolBugs{
2102 NoCloseNotify: true,
2103 ExpectCloseNotify: true,
2104 },
2105 },
2106 shimShutsDown: true,
2107 flags: []string{"-check-close-notify"},
2108 shouldFail: true,
2109 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2110 },
2111 {
2112 name: "Unclean-Shutdown-Ignored",
2113 config: Config{
2114 Bugs: ProtocolBugs{
2115 NoCloseNotify: true,
2116 },
2117 },
2118 shimShutsDown: true,
2119 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002120 {
David Benjaminfa214e42016-05-10 17:03:10 -04002121 name: "Unclean-Shutdown-Alert",
2122 config: Config{
2123 Bugs: ProtocolBugs{
2124 SendAlertOnShutdown: alertDecompressionFailure,
2125 ExpectCloseNotify: true,
2126 },
2127 },
2128 shimShutsDown: true,
2129 flags: []string{"-check-close-notify"},
2130 shouldFail: true,
2131 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2132 },
2133 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002134 name: "LargePlaintext",
2135 config: Config{
2136 Bugs: ProtocolBugs{
2137 SendLargeRecords: true,
2138 },
2139 },
2140 messageLen: maxPlaintext + 1,
2141 shouldFail: true,
2142 expectedError: ":DATA_LENGTH_TOO_LONG:",
2143 },
2144 {
2145 protocol: dtls,
2146 name: "LargePlaintext-DTLS",
2147 config: Config{
2148 Bugs: ProtocolBugs{
2149 SendLargeRecords: true,
2150 },
2151 },
2152 messageLen: maxPlaintext + 1,
2153 shouldFail: true,
2154 expectedError: ":DATA_LENGTH_TOO_LONG:",
2155 },
2156 {
2157 name: "LargeCiphertext",
2158 config: Config{
2159 Bugs: ProtocolBugs{
2160 SendLargeRecords: true,
2161 },
2162 },
2163 messageLen: maxPlaintext * 2,
2164 shouldFail: true,
2165 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2166 },
2167 {
2168 protocol: dtls,
2169 name: "LargeCiphertext-DTLS",
2170 config: Config{
2171 Bugs: ProtocolBugs{
2172 SendLargeRecords: true,
2173 },
2174 },
2175 messageLen: maxPlaintext * 2,
2176 // Unlike the other four cases, DTLS drops records which
2177 // are invalid before authentication, so the connection
2178 // does not fail.
2179 expectMessageDropped: true,
2180 },
David Benjamindd6fed92015-10-23 17:41:12 -04002181 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002182 name: "BadHelloRequest-1",
2183 renegotiate: 1,
2184 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002185 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002186 Bugs: ProtocolBugs{
2187 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2188 },
2189 },
2190 flags: []string{
2191 "-renegotiate-freely",
2192 "-expect-total-renegotiations", "1",
2193 },
2194 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002195 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002196 },
2197 {
2198 name: "BadHelloRequest-2",
2199 renegotiate: 1,
2200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002201 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002202 Bugs: ProtocolBugs{
2203 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2204 },
2205 },
2206 flags: []string{
2207 "-renegotiate-freely",
2208 "-expect-total-renegotiations", "1",
2209 },
2210 shouldFail: true,
2211 expectedError: ":BAD_HELLO_REQUEST:",
2212 },
David Benjaminef1b0092015-11-21 14:05:44 -05002213 {
2214 testType: serverTest,
2215 name: "SupportTicketsWithSessionID",
2216 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002217 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002218 SessionTicketsDisabled: true,
2219 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002220 resumeConfig: &Config{
2221 MaxVersion: VersionTLS12,
2222 },
David Benjaminef1b0092015-11-21 14:05:44 -05002223 resumeSession: true,
2224 },
David Benjamin02edcd02016-07-27 17:40:37 -04002225 {
2226 protocol: dtls,
2227 name: "DTLS-SendExtraFinished",
2228 config: Config{
2229 Bugs: ProtocolBugs{
2230 SendExtraFinished: true,
2231 },
2232 },
2233 shouldFail: true,
2234 expectedError: ":UNEXPECTED_RECORD:",
2235 },
2236 {
2237 protocol: dtls,
2238 name: "DTLS-SendExtraFinished-Reordered",
2239 config: Config{
2240 Bugs: ProtocolBugs{
2241 MaxHandshakeRecordLength: 2,
2242 ReorderHandshakeFragments: true,
2243 SendExtraFinished: true,
2244 },
2245 },
2246 shouldFail: true,
2247 expectedError: ":UNEXPECTED_RECORD:",
2248 },
David Benjamine97fb482016-07-29 09:23:07 -04002249 {
2250 testType: serverTest,
2251 name: "V2ClientHello-EmptyRecordPrefix",
2252 config: Config{
2253 // Choose a cipher suite that does not involve
2254 // elliptic curves, so no extensions are
2255 // involved.
2256 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002257 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002258 Bugs: ProtocolBugs{
2259 SendV2ClientHello: true,
2260 },
2261 },
2262 sendPrefix: string([]byte{
2263 byte(recordTypeHandshake),
2264 3, 1, // version
2265 0, 0, // length
2266 }),
2267 // A no-op empty record may not be sent before V2ClientHello.
2268 shouldFail: true,
2269 expectedError: ":WRONG_VERSION_NUMBER:",
2270 },
2271 {
2272 testType: serverTest,
2273 name: "V2ClientHello-WarningAlertPrefix",
2274 config: Config{
2275 // Choose a cipher suite that does not involve
2276 // elliptic curves, so no extensions are
2277 // involved.
2278 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002279 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002280 Bugs: ProtocolBugs{
2281 SendV2ClientHello: true,
2282 },
2283 },
2284 sendPrefix: string([]byte{
2285 byte(recordTypeAlert),
2286 3, 1, // version
2287 0, 2, // length
2288 alertLevelWarning, byte(alertDecompressionFailure),
2289 }),
2290 // A no-op warning alert may not be sent before V2ClientHello.
2291 shouldFail: true,
2292 expectedError: ":WRONG_VERSION_NUMBER:",
2293 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002294 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002295 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002296 config: Config{
2297 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002298 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002299 sendKeyUpdates: 1,
2300 keyUpdateRequest: keyUpdateNotRequested,
2301 },
2302 {
2303 name: "KeyUpdate-InvalidRequestMode",
2304 config: Config{
2305 MaxVersion: VersionTLS13,
2306 },
2307 sendKeyUpdates: 1,
2308 keyUpdateRequest: 42,
2309 shouldFail: true,
2310 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002311 },
David Benjaminabe94e32016-09-04 14:18:58 -04002312 {
2313 name: "SendSNIWarningAlert",
2314 config: Config{
2315 MaxVersion: VersionTLS12,
2316 Bugs: ProtocolBugs{
2317 SendSNIWarningAlert: true,
2318 },
2319 },
2320 },
David Benjaminc241d792016-09-09 10:34:20 -04002321 {
2322 testType: serverTest,
2323 name: "ExtraCompressionMethods-TLS12",
2324 config: Config{
2325 MaxVersion: VersionTLS12,
2326 Bugs: ProtocolBugs{
2327 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2328 },
2329 },
2330 },
2331 {
2332 testType: serverTest,
2333 name: "ExtraCompressionMethods-TLS13",
2334 config: Config{
2335 MaxVersion: VersionTLS13,
2336 Bugs: ProtocolBugs{
2337 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2338 },
2339 },
2340 shouldFail: true,
2341 expectedError: ":INVALID_COMPRESSION_LIST:",
2342 expectedLocalError: "remote error: illegal parameter",
2343 },
2344 {
2345 testType: serverTest,
2346 name: "NoNullCompression-TLS12",
2347 config: Config{
2348 MaxVersion: VersionTLS12,
2349 Bugs: ProtocolBugs{
2350 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2351 },
2352 },
2353 shouldFail: true,
2354 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2355 expectedLocalError: "remote error: illegal parameter",
2356 },
2357 {
2358 testType: serverTest,
2359 name: "NoNullCompression-TLS13",
2360 config: Config{
2361 MaxVersion: VersionTLS13,
2362 Bugs: ProtocolBugs{
2363 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2364 },
2365 },
2366 shouldFail: true,
2367 expectedError: ":INVALID_COMPRESSION_LIST:",
2368 expectedLocalError: "remote error: illegal parameter",
2369 },
David Benjamin65ac9972016-09-02 21:35:25 -04002370 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002371 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002372 config: Config{
2373 MaxVersion: VersionTLS12,
2374 Bugs: ProtocolBugs{
2375 ExpectGREASE: true,
2376 },
2377 },
2378 flags: []string{"-enable-grease"},
2379 },
2380 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002381 name: "GREASE-Client-TLS13",
2382 config: Config{
2383 MaxVersion: VersionTLS13,
2384 Bugs: ProtocolBugs{
2385 ExpectGREASE: true,
2386 },
2387 },
2388 flags: []string{"-enable-grease"},
2389 },
2390 {
2391 testType: serverTest,
2392 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002393 config: Config{
2394 MaxVersion: VersionTLS13,
2395 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002396 // TLS 1.3 servers are expected to
2397 // always enable GREASE. TLS 1.3 is new,
2398 // so there is no existing ecosystem to
2399 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002400 ExpectGREASE: true,
2401 },
2402 },
David Benjamin65ac9972016-09-02 21:35:25 -04002403 },
Adam Langley7c803a62015-06-15 15:35:05 -07002404 }
Adam Langley7c803a62015-06-15 15:35:05 -07002405 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002406
2407 // Test that very large messages can be received.
2408 cert := rsaCertificate
2409 for i := 0; i < 50; i++ {
2410 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2411 }
2412 testCases = append(testCases, testCase{
2413 name: "LargeMessage",
2414 config: Config{
2415 Certificates: []Certificate{cert},
2416 },
2417 })
2418 testCases = append(testCases, testCase{
2419 protocol: dtls,
2420 name: "LargeMessage-DTLS",
2421 config: Config{
2422 Certificates: []Certificate{cert},
2423 },
2424 })
2425
2426 // They are rejected if the maximum certificate chain length is capped.
2427 testCases = append(testCases, testCase{
2428 name: "LargeMessage-Reject",
2429 config: Config{
2430 Certificates: []Certificate{cert},
2431 },
2432 flags: []string{"-max-cert-list", "16384"},
2433 shouldFail: true,
2434 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2435 })
2436 testCases = append(testCases, testCase{
2437 protocol: dtls,
2438 name: "LargeMessage-Reject-DTLS",
2439 config: Config{
2440 Certificates: []Certificate{cert},
2441 },
2442 flags: []string{"-max-cert-list", "16384"},
2443 shouldFail: true,
2444 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2445 })
Adam Langley7c803a62015-06-15 15:35:05 -07002446}
2447
David Benjaminaa012042016-12-10 13:33:05 -05002448func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2449 const psk = "12345"
2450 const pskIdentity = "luggage combo"
2451
2452 var prefix string
2453 if protocol == dtls {
2454 if !ver.hasDTLS {
2455 return
2456 }
2457 prefix = "D"
2458 }
2459
2460 var cert Certificate
2461 var certFile string
2462 var keyFile string
2463 if hasComponent(suite.name, "ECDSA") {
2464 cert = ecdsaP256Certificate
2465 certFile = ecdsaP256CertificateFile
2466 keyFile = ecdsaP256KeyFile
2467 } else {
2468 cert = rsaCertificate
2469 certFile = rsaCertificateFile
2470 keyFile = rsaKeyFile
2471 }
2472
2473 var flags []string
2474 if hasComponent(suite.name, "PSK") {
2475 flags = append(flags,
2476 "-psk", psk,
2477 "-psk-identity", pskIdentity)
2478 }
2479 if hasComponent(suite.name, "NULL") {
2480 // NULL ciphers must be explicitly enabled.
2481 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2482 }
2483 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2484 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2485 // for now.
2486 flags = append(flags, "-cipher", suite.name)
2487 }
2488
2489 var shouldServerFail, shouldClientFail bool
2490 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2491 // BoringSSL clients accept ECDHE on SSLv3, but
2492 // a BoringSSL server will never select it
2493 // because the extension is missing.
2494 shouldServerFail = true
2495 }
2496 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2497 shouldClientFail = true
2498 shouldServerFail = true
2499 }
2500 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2501 shouldClientFail = true
2502 shouldServerFail = true
2503 }
2504 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2505 shouldClientFail = true
2506 shouldServerFail = true
2507 }
2508 if !isDTLSCipher(suite.name) && protocol == dtls {
2509 shouldClientFail = true
2510 shouldServerFail = true
2511 }
2512
2513 var sendCipherSuite uint16
2514 var expectedServerError, expectedClientError string
2515 serverCipherSuites := []uint16{suite.id}
2516 if shouldServerFail {
2517 expectedServerError = ":NO_SHARED_CIPHER:"
2518 }
2519 if shouldClientFail {
2520 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2521 // Configure the server to select ciphers as normal but
2522 // select an incompatible cipher in ServerHello.
2523 serverCipherSuites = nil
2524 sendCipherSuite = suite.id
2525 }
2526
2527 testCases = append(testCases, testCase{
2528 testType: serverTest,
2529 protocol: protocol,
2530 name: prefix + ver.name + "-" + suite.name + "-server",
2531 config: Config{
2532 MinVersion: ver.version,
2533 MaxVersion: ver.version,
2534 CipherSuites: []uint16{suite.id},
2535 Certificates: []Certificate{cert},
2536 PreSharedKey: []byte(psk),
2537 PreSharedKeyIdentity: pskIdentity,
2538 Bugs: ProtocolBugs{
2539 AdvertiseAllConfiguredCiphers: true,
2540 },
2541 },
2542 certFile: certFile,
2543 keyFile: keyFile,
2544 flags: flags,
2545 resumeSession: true,
2546 shouldFail: shouldServerFail,
2547 expectedError: expectedServerError,
2548 })
2549
2550 testCases = append(testCases, testCase{
2551 testType: clientTest,
2552 protocol: protocol,
2553 name: prefix + ver.name + "-" + suite.name + "-client",
2554 config: Config{
2555 MinVersion: ver.version,
2556 MaxVersion: ver.version,
2557 CipherSuites: serverCipherSuites,
2558 Certificates: []Certificate{cert},
2559 PreSharedKey: []byte(psk),
2560 PreSharedKeyIdentity: pskIdentity,
2561 Bugs: ProtocolBugs{
2562 IgnorePeerCipherPreferences: shouldClientFail,
2563 SendCipherSuite: sendCipherSuite,
2564 },
2565 },
2566 flags: flags,
2567 resumeSession: true,
2568 shouldFail: shouldClientFail,
2569 expectedError: expectedClientError,
2570 })
2571
David Benjamin6f600d62016-12-21 16:06:54 -05002572 if shouldClientFail {
2573 return
2574 }
2575
2576 // Ensure the maximum record size is accepted.
2577 testCases = append(testCases, testCase{
2578 protocol: protocol,
2579 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2580 config: Config{
2581 MinVersion: ver.version,
2582 MaxVersion: ver.version,
2583 CipherSuites: []uint16{suite.id},
2584 Certificates: []Certificate{cert},
2585 PreSharedKey: []byte(psk),
2586 PreSharedKeyIdentity: pskIdentity,
2587 },
2588 flags: flags,
2589 messageLen: maxPlaintext,
2590 })
2591
2592 // Test bad records for all ciphers. Bad records are fatal in TLS
2593 // and ignored in DTLS.
2594 var shouldFail bool
2595 var expectedError string
2596 if protocol == tls {
2597 shouldFail = true
2598 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2599 }
2600
2601 testCases = append(testCases, testCase{
2602 protocol: protocol,
2603 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2604 config: Config{
2605 MinVersion: ver.version,
2606 MaxVersion: ver.version,
2607 CipherSuites: []uint16{suite.id},
2608 Certificates: []Certificate{cert},
2609 PreSharedKey: []byte(psk),
2610 PreSharedKeyIdentity: pskIdentity,
2611 },
2612 flags: flags,
2613 damageFirstWrite: true,
2614 messageLen: maxPlaintext,
2615 shouldFail: shouldFail,
2616 expectedError: expectedError,
2617 })
2618
2619 if ver.version >= VersionTLS13 {
David Benjaminaa012042016-12-10 13:33:05 -05002620 testCases = append(testCases, testCase{
2621 protocol: protocol,
David Benjamin6f600d62016-12-21 16:06:54 -05002622 name: prefix + ver.name + "-" + suite.name + "-ShortHeader",
David Benjaminaa012042016-12-10 13:33:05 -05002623 config: Config{
2624 MinVersion: ver.version,
2625 MaxVersion: ver.version,
2626 CipherSuites: []uint16{suite.id},
2627 Certificates: []Certificate{cert},
2628 PreSharedKey: []byte(psk),
2629 PreSharedKeyIdentity: pskIdentity,
David Benjamin6f600d62016-12-21 16:06:54 -05002630 Bugs: ProtocolBugs{
2631 EnableShortHeader: true,
2632 },
David Benjaminaa012042016-12-10 13:33:05 -05002633 },
David Benjamin6f600d62016-12-21 16:06:54 -05002634 flags: append([]string{"-enable-short-header"}, flags...),
2635 resumeSession: true,
2636 expectShortHeader: true,
David Benjaminaa012042016-12-10 13:33:05 -05002637 })
2638 }
2639}
2640
Adam Langley95c29f32014-06-20 12:00:00 -07002641func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002642 const bogusCipher = 0xfe00
2643
Adam Langley95c29f32014-06-20 12:00:00 -07002644 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002645 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002646 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002647 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002648 }
David Benjamin2c99d282015-09-01 10:23:00 -04002649 }
Adam Langley95c29f32014-06-20 12:00:00 -07002650 }
Adam Langleya7997f12015-05-14 17:38:50 -07002651
2652 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002653 name: "NoSharedCipher",
2654 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002655 MaxVersion: VersionTLS12,
2656 CipherSuites: []uint16{},
2657 },
2658 shouldFail: true,
2659 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2660 })
2661
2662 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002663 name: "NoSharedCipher-TLS13",
2664 config: Config{
2665 MaxVersion: VersionTLS13,
2666 CipherSuites: []uint16{},
2667 },
2668 shouldFail: true,
2669 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2670 })
2671
2672 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002673 name: "UnsupportedCipherSuite",
2674 config: Config{
2675 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002676 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002677 Bugs: ProtocolBugs{
2678 IgnorePeerCipherPreferences: true,
2679 },
2680 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002681 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002682 shouldFail: true,
2683 expectedError: ":WRONG_CIPHER_RETURNED:",
2684 })
2685
2686 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002687 name: "ServerHelloBogusCipher",
2688 config: Config{
2689 MaxVersion: VersionTLS12,
2690 Bugs: ProtocolBugs{
2691 SendCipherSuite: bogusCipher,
2692 },
2693 },
2694 shouldFail: true,
2695 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2696 })
2697 testCases = append(testCases, testCase{
2698 name: "ServerHelloBogusCipher-TLS13",
2699 config: Config{
2700 MaxVersion: VersionTLS13,
2701 Bugs: ProtocolBugs{
2702 SendCipherSuite: bogusCipher,
2703 },
2704 },
2705 shouldFail: true,
2706 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2707 })
2708
2709 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002710 name: "WeakDH",
2711 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002712 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002713 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2714 Bugs: ProtocolBugs{
2715 // This is a 1023-bit prime number, generated
2716 // with:
2717 // openssl gendh 1023 | openssl asn1parse -i
2718 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2719 },
2720 },
2721 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002722 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002723 })
Adam Langleycef75832015-09-03 14:51:12 -07002724
David Benjamincd24a392015-11-11 13:23:05 -08002725 testCases = append(testCases, testCase{
2726 name: "SillyDH",
2727 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002728 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002729 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2730 Bugs: ProtocolBugs{
2731 // This is a 4097-bit prime number, generated
2732 // with:
2733 // openssl gendh 4097 | openssl asn1parse -i
2734 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2735 },
2736 },
2737 shouldFail: true,
2738 expectedError: ":DH_P_TOO_LONG:",
2739 })
2740
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002741 // This test ensures that Diffie-Hellman public values are padded with
2742 // zeros so that they're the same length as the prime. This is to avoid
2743 // hitting a bug in yaSSL.
2744 testCases = append(testCases, testCase{
2745 testType: serverTest,
2746 name: "DHPublicValuePadded",
2747 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002748 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002749 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2750 Bugs: ProtocolBugs{
2751 RequireDHPublicValueLen: (1025 + 7) / 8,
2752 },
2753 },
2754 flags: []string{"-use-sparse-dh-prime"},
2755 })
David Benjamincd24a392015-11-11 13:23:05 -08002756
David Benjamin241ae832016-01-15 03:04:54 -05002757 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002758 testCases = append(testCases, testCase{
2759 testType: serverTest,
2760 name: "UnknownCipher",
2761 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002762 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002763 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002764 Bugs: ProtocolBugs{
2765 AdvertiseAllConfiguredCiphers: true,
2766 },
2767 },
2768 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002769
2770 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002771 testCases = append(testCases, testCase{
2772 testType: serverTest,
2773 name: "UnknownCipher-TLS13",
2774 config: Config{
2775 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002776 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002777 Bugs: ProtocolBugs{
2778 AdvertiseAllConfiguredCiphers: true,
2779 },
David Benjamin241ae832016-01-15 03:04:54 -05002780 },
2781 })
2782
David Benjamin78679342016-09-16 19:42:05 -04002783 // Test empty ECDHE_PSK identity hints work as expected.
2784 testCases = append(testCases, testCase{
2785 name: "EmptyECDHEPSKHint",
2786 config: Config{
2787 MaxVersion: VersionTLS12,
2788 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2789 PreSharedKey: []byte("secret"),
2790 },
2791 flags: []string{"-psk", "secret"},
2792 })
2793
2794 // Test empty PSK identity hints work as expected, even if an explicit
2795 // ServerKeyExchange is sent.
2796 testCases = append(testCases, testCase{
2797 name: "ExplicitEmptyPSKHint",
2798 config: Config{
2799 MaxVersion: VersionTLS12,
2800 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2801 PreSharedKey: []byte("secret"),
2802 Bugs: ProtocolBugs{
2803 AlwaysSendPreSharedKeyIdentityHint: true,
2804 },
2805 },
2806 flags: []string{"-psk", "secret"},
2807 })
Adam Langley95c29f32014-06-20 12:00:00 -07002808}
2809
2810func addBadECDSASignatureTests() {
2811 for badR := BadValue(1); badR < NumBadValues; badR++ {
2812 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002813 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002814 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2815 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002816 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002817 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002818 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002819 Bugs: ProtocolBugs{
2820 BadECDSAR: badR,
2821 BadECDSAS: badS,
2822 },
2823 },
2824 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002825 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002826 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002827 testCases = append(testCases, testCase{
2828 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2829 config: Config{
2830 MaxVersion: VersionTLS13,
2831 Certificates: []Certificate{ecdsaP256Certificate},
2832 Bugs: ProtocolBugs{
2833 BadECDSAR: badR,
2834 BadECDSAS: badS,
2835 },
2836 },
2837 shouldFail: true,
2838 expectedError: ":BAD_SIGNATURE:",
2839 })
Adam Langley95c29f32014-06-20 12:00:00 -07002840 }
2841 }
2842}
2843
Adam Langley80842bd2014-06-20 12:00:00 -07002844func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002845 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002846 name: "MaxCBCPadding",
2847 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002848 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002849 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2850 Bugs: ProtocolBugs{
2851 MaxPadding: true,
2852 },
2853 },
2854 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2855 })
David Benjamin025b3d32014-07-01 19:53:04 -04002856 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002857 name: "BadCBCPadding",
2858 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002859 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002860 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2861 Bugs: ProtocolBugs{
2862 PaddingFirstByteBad: true,
2863 },
2864 },
2865 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002866 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002867 })
2868 // OpenSSL previously had an issue where the first byte of padding in
2869 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002870 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002871 name: "BadCBCPadding255",
2872 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002873 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002874 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2875 Bugs: ProtocolBugs{
2876 MaxPadding: true,
2877 PaddingFirstByteBadIf255: true,
2878 },
2879 },
2880 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2881 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002882 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002883 })
2884}
2885
Kenny Root7fdeaf12014-08-05 15:23:37 -07002886func addCBCSplittingTests() {
2887 testCases = append(testCases, testCase{
2888 name: "CBCRecordSplitting",
2889 config: Config{
2890 MaxVersion: VersionTLS10,
2891 MinVersion: VersionTLS10,
2892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2893 },
David Benjaminac8302a2015-09-01 17:18:15 -04002894 messageLen: -1, // read until EOF
2895 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002896 flags: []string{
2897 "-async",
2898 "-write-different-record-sizes",
2899 "-cbc-record-splitting",
2900 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002901 })
2902 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002903 name: "CBCRecordSplittingPartialWrite",
2904 config: Config{
2905 MaxVersion: VersionTLS10,
2906 MinVersion: VersionTLS10,
2907 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2908 },
2909 messageLen: -1, // read until EOF
2910 flags: []string{
2911 "-async",
2912 "-write-different-record-sizes",
2913 "-cbc-record-splitting",
2914 "-partial-write",
2915 },
2916 })
2917}
2918
David Benjamin636293b2014-07-08 17:59:18 -04002919func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002920 // Add a dummy cert pool to stress certificate authority parsing.
2921 // TODO(davidben): Add tests that those values parse out correctly.
2922 certPool := x509.NewCertPool()
2923 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2924 if err != nil {
2925 panic(err)
2926 }
2927 certPool.AddCert(cert)
2928
David Benjamin636293b2014-07-08 17:59:18 -04002929 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002930 testCases = append(testCases, testCase{
2931 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002932 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002933 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002934 MinVersion: ver.version,
2935 MaxVersion: ver.version,
2936 ClientAuth: RequireAnyClientCert,
2937 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002938 },
2939 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002940 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2941 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002942 },
2943 })
2944 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002945 testType: serverTest,
2946 name: ver.name + "-Server-ClientAuth-RSA",
2947 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002948 MinVersion: ver.version,
2949 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002950 Certificates: []Certificate{rsaCertificate},
2951 },
2952 flags: []string{"-require-any-client-certificate"},
2953 })
David Benjamine098ec22014-08-27 23:13:20 -04002954 if ver.version != VersionSSL30 {
2955 testCases = append(testCases, testCase{
2956 testType: serverTest,
2957 name: ver.name + "-Server-ClientAuth-ECDSA",
2958 config: Config{
2959 MinVersion: ver.version,
2960 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002961 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002962 },
2963 flags: []string{"-require-any-client-certificate"},
2964 })
2965 testCases = append(testCases, testCase{
2966 testType: clientTest,
2967 name: ver.name + "-Client-ClientAuth-ECDSA",
2968 config: Config{
2969 MinVersion: ver.version,
2970 MaxVersion: ver.version,
2971 ClientAuth: RequireAnyClientCert,
2972 ClientCAs: certPool,
2973 },
2974 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002975 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2976 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002977 },
2978 })
2979 }
Adam Langley37646832016-08-01 16:16:46 -07002980
2981 testCases = append(testCases, testCase{
2982 name: "NoClientCertificate-" + ver.name,
2983 config: Config{
2984 MinVersion: ver.version,
2985 MaxVersion: ver.version,
2986 ClientAuth: RequireAnyClientCert,
2987 },
2988 shouldFail: true,
2989 expectedLocalError: "client didn't provide a certificate",
2990 })
2991
2992 testCases = append(testCases, testCase{
2993 // Even if not configured to expect a certificate, OpenSSL will
2994 // return X509_V_OK as the verify_result.
2995 testType: serverTest,
2996 name: "NoClientCertificateRequested-Server-" + ver.name,
2997 config: Config{
2998 MinVersion: ver.version,
2999 MaxVersion: ver.version,
3000 },
3001 flags: []string{
3002 "-expect-verify-result",
3003 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003004 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003005 })
3006
3007 testCases = append(testCases, testCase{
3008 // If a client certificate is not provided, OpenSSL will still
3009 // return X509_V_OK as the verify_result.
3010 testType: serverTest,
3011 name: "NoClientCertificate-Server-" + ver.name,
3012 config: Config{
3013 MinVersion: ver.version,
3014 MaxVersion: ver.version,
3015 },
3016 flags: []string{
3017 "-expect-verify-result",
3018 "-verify-peer",
3019 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003020 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003021 })
3022
David Benjamin1db9e1b2016-10-07 20:51:43 -04003023 certificateRequired := "remote error: certificate required"
3024 if ver.version < VersionTLS13 {
3025 // Prior to TLS 1.3, the generic handshake_failure alert
3026 // was used.
3027 certificateRequired = "remote error: handshake failure"
3028 }
Adam Langley37646832016-08-01 16:16:46 -07003029 testCases = append(testCases, testCase{
3030 testType: serverTest,
3031 name: "RequireAnyClientCertificate-" + ver.name,
3032 config: Config{
3033 MinVersion: ver.version,
3034 MaxVersion: ver.version,
3035 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003036 flags: []string{"-require-any-client-certificate"},
3037 shouldFail: true,
3038 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3039 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003040 })
3041
3042 if ver.version != VersionSSL30 {
3043 testCases = append(testCases, testCase{
3044 testType: serverTest,
3045 name: "SkipClientCertificate-" + ver.name,
3046 config: Config{
3047 MinVersion: ver.version,
3048 MaxVersion: ver.version,
3049 Bugs: ProtocolBugs{
3050 SkipClientCertificate: true,
3051 },
3052 },
3053 // Setting SSL_VERIFY_PEER allows anonymous clients.
3054 flags: []string{"-verify-peer"},
3055 shouldFail: true,
3056 expectedError: ":UNEXPECTED_MESSAGE:",
3057 })
3058 }
David Benjamin636293b2014-07-08 17:59:18 -04003059 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003060
David Benjaminc032dfa2016-05-12 14:54:57 -04003061 // Client auth is only legal in certificate-based ciphers.
3062 testCases = append(testCases, testCase{
3063 testType: clientTest,
3064 name: "ClientAuth-PSK",
3065 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003066 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003067 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3068 PreSharedKey: []byte("secret"),
3069 ClientAuth: RequireAnyClientCert,
3070 },
3071 flags: []string{
3072 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3073 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3074 "-psk", "secret",
3075 },
3076 shouldFail: true,
3077 expectedError: ":UNEXPECTED_MESSAGE:",
3078 })
3079 testCases = append(testCases, testCase{
3080 testType: clientTest,
3081 name: "ClientAuth-ECDHE_PSK",
3082 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003083 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003084 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3085 PreSharedKey: []byte("secret"),
3086 ClientAuth: RequireAnyClientCert,
3087 },
3088 flags: []string{
3089 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3090 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3091 "-psk", "secret",
3092 },
3093 shouldFail: true,
3094 expectedError: ":UNEXPECTED_MESSAGE:",
3095 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003096
3097 // Regression test for a bug where the client CA list, if explicitly
3098 // set to NULL, was mis-encoded.
3099 testCases = append(testCases, testCase{
3100 testType: serverTest,
3101 name: "Null-Client-CA-List",
3102 config: Config{
3103 MaxVersion: VersionTLS12,
3104 Certificates: []Certificate{rsaCertificate},
3105 },
3106 flags: []string{
3107 "-require-any-client-certificate",
3108 "-use-null-client-ca-list",
3109 },
3110 })
David Benjamin636293b2014-07-08 17:59:18 -04003111}
3112
Adam Langley75712922014-10-10 16:23:43 -07003113func addExtendedMasterSecretTests() {
3114 const expectEMSFlag = "-expect-extended-master-secret"
3115
3116 for _, with := range []bool{false, true} {
3117 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003118 if with {
3119 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003120 }
3121
3122 for _, isClient := range []bool{false, true} {
3123 suffix := "-Server"
3124 testType := serverTest
3125 if isClient {
3126 suffix = "-Client"
3127 testType = clientTest
3128 }
3129
3130 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003131 // In TLS 1.3, the extension is irrelevant and
3132 // always reports as enabled.
3133 var flags []string
3134 if with || ver.version >= VersionTLS13 {
3135 flags = []string{expectEMSFlag}
3136 }
3137
Adam Langley75712922014-10-10 16:23:43 -07003138 test := testCase{
3139 testType: testType,
3140 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3141 config: Config{
3142 MinVersion: ver.version,
3143 MaxVersion: ver.version,
3144 Bugs: ProtocolBugs{
3145 NoExtendedMasterSecret: !with,
3146 RequireExtendedMasterSecret: with,
3147 },
3148 },
David Benjamin48cae082014-10-27 01:06:24 -04003149 flags: flags,
3150 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003151 }
3152 if test.shouldFail {
3153 test.expectedLocalError = "extended master secret required but not supported by peer"
3154 }
3155 testCases = append(testCases, test)
3156 }
3157 }
3158 }
3159
Adam Langleyba5934b2015-06-02 10:50:35 -07003160 for _, isClient := range []bool{false, true} {
3161 for _, supportedInFirstConnection := range []bool{false, true} {
3162 for _, supportedInResumeConnection := range []bool{false, true} {
3163 boolToWord := func(b bool) string {
3164 if b {
3165 return "Yes"
3166 }
3167 return "No"
3168 }
3169 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3170 if isClient {
3171 suffix += "Client"
3172 } else {
3173 suffix += "Server"
3174 }
3175
3176 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003177 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003178 Bugs: ProtocolBugs{
3179 RequireExtendedMasterSecret: true,
3180 },
3181 }
3182
3183 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003184 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003185 Bugs: ProtocolBugs{
3186 NoExtendedMasterSecret: true,
3187 },
3188 }
3189
3190 test := testCase{
3191 name: "ExtendedMasterSecret-" + suffix,
3192 resumeSession: true,
3193 }
3194
3195 if !isClient {
3196 test.testType = serverTest
3197 }
3198
3199 if supportedInFirstConnection {
3200 test.config = supportedConfig
3201 } else {
3202 test.config = noSupportConfig
3203 }
3204
3205 if supportedInResumeConnection {
3206 test.resumeConfig = &supportedConfig
3207 } else {
3208 test.resumeConfig = &noSupportConfig
3209 }
3210
3211 switch suffix {
3212 case "YesToYes-Client", "YesToYes-Server":
3213 // When a session is resumed, it should
3214 // still be aware that its master
3215 // secret was generated via EMS and
3216 // thus it's safe to use tls-unique.
3217 test.flags = []string{expectEMSFlag}
3218 case "NoToYes-Server":
3219 // If an original connection did not
3220 // contain EMS, but a resumption
3221 // handshake does, then a server should
3222 // not resume the session.
3223 test.expectResumeRejected = true
3224 case "YesToNo-Server":
3225 // Resuming an EMS session without the
3226 // EMS extension should cause the
3227 // server to abort the connection.
3228 test.shouldFail = true
3229 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3230 case "NoToYes-Client":
3231 // A client should abort a connection
3232 // where the server resumed a non-EMS
3233 // session but echoed the EMS
3234 // extension.
3235 test.shouldFail = true
3236 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3237 case "YesToNo-Client":
3238 // A client should abort a connection
3239 // where the server didn't echo EMS
3240 // when the session used it.
3241 test.shouldFail = true
3242 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3243 }
3244
3245 testCases = append(testCases, test)
3246 }
3247 }
3248 }
David Benjamin163c9562016-08-29 23:14:17 -04003249
3250 // Switching EMS on renegotiation is forbidden.
3251 testCases = append(testCases, testCase{
3252 name: "ExtendedMasterSecret-Renego-NoEMS",
3253 config: Config{
3254 MaxVersion: VersionTLS12,
3255 Bugs: ProtocolBugs{
3256 NoExtendedMasterSecret: true,
3257 NoExtendedMasterSecretOnRenegotiation: true,
3258 },
3259 },
3260 renegotiate: 1,
3261 flags: []string{
3262 "-renegotiate-freely",
3263 "-expect-total-renegotiations", "1",
3264 },
3265 })
3266
3267 testCases = append(testCases, testCase{
3268 name: "ExtendedMasterSecret-Renego-Upgrade",
3269 config: Config{
3270 MaxVersion: VersionTLS12,
3271 Bugs: ProtocolBugs{
3272 NoExtendedMasterSecret: true,
3273 },
3274 },
3275 renegotiate: 1,
3276 flags: []string{
3277 "-renegotiate-freely",
3278 "-expect-total-renegotiations", "1",
3279 },
3280 shouldFail: true,
3281 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3282 })
3283
3284 testCases = append(testCases, testCase{
3285 name: "ExtendedMasterSecret-Renego-Downgrade",
3286 config: Config{
3287 MaxVersion: VersionTLS12,
3288 Bugs: ProtocolBugs{
3289 NoExtendedMasterSecretOnRenegotiation: true,
3290 },
3291 },
3292 renegotiate: 1,
3293 flags: []string{
3294 "-renegotiate-freely",
3295 "-expect-total-renegotiations", "1",
3296 },
3297 shouldFail: true,
3298 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3299 })
Adam Langley75712922014-10-10 16:23:43 -07003300}
3301
David Benjamin582ba042016-07-07 12:33:25 -07003302type stateMachineTestConfig struct {
3303 protocol protocol
3304 async bool
3305 splitHandshake, packHandshakeFlight bool
3306}
3307
David Benjamin43ec06f2014-08-05 02:28:57 -04003308// Adds tests that try to cover the range of the handshake state machine, under
3309// various conditions. Some of these are redundant with other tests, but they
3310// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003311func addAllStateMachineCoverageTests() {
3312 for _, async := range []bool{false, true} {
3313 for _, protocol := range []protocol{tls, dtls} {
3314 addStateMachineCoverageTests(stateMachineTestConfig{
3315 protocol: protocol,
3316 async: async,
3317 })
3318 addStateMachineCoverageTests(stateMachineTestConfig{
3319 protocol: protocol,
3320 async: async,
3321 splitHandshake: true,
3322 })
3323 if protocol == tls {
3324 addStateMachineCoverageTests(stateMachineTestConfig{
3325 protocol: protocol,
3326 async: async,
3327 packHandshakeFlight: true,
3328 })
3329 }
3330 }
3331 }
3332}
3333
3334func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003335 var tests []testCase
3336
3337 // Basic handshake, with resumption. Client and server,
3338 // session ID and session ticket.
3339 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003340 name: "Basic-Client",
3341 config: Config{
3342 MaxVersion: VersionTLS12,
3343 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003344 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003345 // Ensure session tickets are used, not session IDs.
3346 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003347 })
3348 tests = append(tests, testCase{
3349 name: "Basic-Client-RenewTicket",
3350 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003351 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003352 Bugs: ProtocolBugs{
3353 RenewTicketOnResume: true,
3354 },
3355 },
David Benjamin46662482016-08-17 00:51:00 -04003356 flags: []string{"-expect-ticket-renewal"},
3357 resumeSession: true,
3358 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003359 })
3360 tests = append(tests, testCase{
3361 name: "Basic-Client-NoTicket",
3362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003363 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003364 SessionTicketsDisabled: true,
3365 },
3366 resumeSession: true,
3367 })
3368 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003369 name: "Basic-Client-Implicit",
3370 config: Config{
3371 MaxVersion: VersionTLS12,
3372 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003373 flags: []string{"-implicit-handshake"},
3374 resumeSession: true,
3375 })
3376 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003377 testType: serverTest,
3378 name: "Basic-Server",
3379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003380 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003381 Bugs: ProtocolBugs{
3382 RequireSessionTickets: true,
3383 },
3384 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003385 resumeSession: true,
3386 })
3387 tests = append(tests, testCase{
3388 testType: serverTest,
3389 name: "Basic-Server-NoTickets",
3390 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003391 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003392 SessionTicketsDisabled: true,
3393 },
3394 resumeSession: true,
3395 })
3396 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003397 testType: serverTest,
3398 name: "Basic-Server-Implicit",
3399 config: Config{
3400 MaxVersion: VersionTLS12,
3401 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003402 flags: []string{"-implicit-handshake"},
3403 resumeSession: true,
3404 })
3405 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003406 testType: serverTest,
3407 name: "Basic-Server-EarlyCallback",
3408 config: Config{
3409 MaxVersion: VersionTLS12,
3410 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003411 flags: []string{"-use-early-callback"},
3412 resumeSession: true,
3413 })
3414
Steven Valdez143e8b32016-07-11 13:19:03 -04003415 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003416 if config.protocol == tls {
3417 tests = append(tests, testCase{
3418 name: "TLS13-1RTT-Client",
3419 config: Config{
3420 MaxVersion: VersionTLS13,
3421 MinVersion: VersionTLS13,
3422 },
David Benjamin46662482016-08-17 00:51:00 -04003423 resumeSession: true,
3424 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003425 })
3426
3427 tests = append(tests, testCase{
3428 testType: serverTest,
3429 name: "TLS13-1RTT-Server",
3430 config: Config{
3431 MaxVersion: VersionTLS13,
3432 MinVersion: VersionTLS13,
3433 },
David Benjamin46662482016-08-17 00:51:00 -04003434 resumeSession: true,
3435 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003436 })
3437
3438 tests = append(tests, testCase{
3439 name: "TLS13-HelloRetryRequest-Client",
3440 config: Config{
3441 MaxVersion: VersionTLS13,
3442 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003443 // P-384 requires a HelloRetryRequest against BoringSSL's default
3444 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003445 CurvePreferences: []CurveID{CurveP384},
3446 Bugs: ProtocolBugs{
3447 ExpectMissingKeyShare: true,
3448 },
3449 },
3450 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3451 resumeSession: true,
3452 })
3453
3454 tests = append(tests, testCase{
3455 testType: serverTest,
3456 name: "TLS13-HelloRetryRequest-Server",
3457 config: Config{
3458 MaxVersion: VersionTLS13,
3459 MinVersion: VersionTLS13,
3460 // Require a HelloRetryRequest for every curve.
3461 DefaultCurves: []CurveID{},
3462 },
3463 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3464 resumeSession: true,
3465 })
3466 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003467
David Benjamin760b1dd2015-05-15 23:33:48 -04003468 // TLS client auth.
3469 tests = append(tests, testCase{
3470 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003471 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003473 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003474 ClientAuth: RequestClientCert,
3475 },
3476 })
3477 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003478 testType: serverTest,
3479 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003480 config: Config{
3481 MaxVersion: VersionTLS12,
3482 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003483 // Setting SSL_VERIFY_PEER allows anonymous clients.
3484 flags: []string{"-verify-peer"},
3485 })
David Benjamin582ba042016-07-07 12:33:25 -07003486 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003487 tests = append(tests, testCase{
3488 testType: clientTest,
3489 name: "ClientAuth-NoCertificate-Client-SSL3",
3490 config: Config{
3491 MaxVersion: VersionSSL30,
3492 ClientAuth: RequestClientCert,
3493 },
3494 })
3495 tests = append(tests, testCase{
3496 testType: serverTest,
3497 name: "ClientAuth-NoCertificate-Server-SSL3",
3498 config: Config{
3499 MaxVersion: VersionSSL30,
3500 },
3501 // Setting SSL_VERIFY_PEER allows anonymous clients.
3502 flags: []string{"-verify-peer"},
3503 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003504 tests = append(tests, testCase{
3505 testType: clientTest,
3506 name: "ClientAuth-NoCertificate-Client-TLS13",
3507 config: Config{
3508 MaxVersion: VersionTLS13,
3509 ClientAuth: RequestClientCert,
3510 },
3511 })
3512 tests = append(tests, testCase{
3513 testType: serverTest,
3514 name: "ClientAuth-NoCertificate-Server-TLS13",
3515 config: Config{
3516 MaxVersion: VersionTLS13,
3517 },
3518 // Setting SSL_VERIFY_PEER allows anonymous clients.
3519 flags: []string{"-verify-peer"},
3520 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003521 }
3522 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003523 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003524 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003525 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003526 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003527 ClientAuth: RequireAnyClientCert,
3528 },
3529 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003530 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3531 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003532 },
3533 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003534 tests = append(tests, testCase{
3535 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003536 name: "ClientAuth-RSA-Client-TLS13",
3537 config: Config{
3538 MaxVersion: VersionTLS13,
3539 ClientAuth: RequireAnyClientCert,
3540 },
3541 flags: []string{
3542 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3543 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3544 },
3545 })
3546 tests = append(tests, testCase{
3547 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003548 name: "ClientAuth-ECDSA-Client",
3549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003550 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003551 ClientAuth: RequireAnyClientCert,
3552 },
3553 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003554 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3555 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003556 },
3557 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003558 tests = append(tests, testCase{
3559 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003560 name: "ClientAuth-ECDSA-Client-TLS13",
3561 config: Config{
3562 MaxVersion: VersionTLS13,
3563 ClientAuth: RequireAnyClientCert,
3564 },
3565 flags: []string{
3566 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3567 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3568 },
3569 })
3570 tests = append(tests, testCase{
3571 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003572 name: "ClientAuth-NoCertificate-OldCallback",
3573 config: Config{
3574 MaxVersion: VersionTLS12,
3575 ClientAuth: RequestClientCert,
3576 },
3577 flags: []string{"-use-old-client-cert-callback"},
3578 })
3579 tests = append(tests, testCase{
3580 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003581 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3582 config: Config{
3583 MaxVersion: VersionTLS13,
3584 ClientAuth: RequestClientCert,
3585 },
3586 flags: []string{"-use-old-client-cert-callback"},
3587 })
3588 tests = append(tests, testCase{
3589 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003590 name: "ClientAuth-OldCallback",
3591 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003592 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003593 ClientAuth: RequireAnyClientCert,
3594 },
3595 flags: []string{
3596 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3597 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3598 "-use-old-client-cert-callback",
3599 },
3600 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003601 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003602 testType: clientTest,
3603 name: "ClientAuth-OldCallback-TLS13",
3604 config: Config{
3605 MaxVersion: VersionTLS13,
3606 ClientAuth: RequireAnyClientCert,
3607 },
3608 flags: []string{
3609 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3610 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3611 "-use-old-client-cert-callback",
3612 },
3613 })
3614 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003615 testType: serverTest,
3616 name: "ClientAuth-Server",
3617 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003618 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003619 Certificates: []Certificate{rsaCertificate},
3620 },
3621 flags: []string{"-require-any-client-certificate"},
3622 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003623 tests = append(tests, testCase{
3624 testType: serverTest,
3625 name: "ClientAuth-Server-TLS13",
3626 config: Config{
3627 MaxVersion: VersionTLS13,
3628 Certificates: []Certificate{rsaCertificate},
3629 },
3630 flags: []string{"-require-any-client-certificate"},
3631 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003632
David Benjamin4c3ddf72016-06-29 18:13:53 -04003633 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003634 tests = append(tests, testCase{
3635 testType: serverTest,
3636 name: "Basic-Server-RSA",
3637 config: Config{
3638 MaxVersion: VersionTLS12,
3639 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3640 },
3641 flags: []string{
3642 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3643 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3644 },
3645 })
3646 tests = append(tests, testCase{
3647 testType: serverTest,
3648 name: "Basic-Server-ECDHE-RSA",
3649 config: Config{
3650 MaxVersion: VersionTLS12,
3651 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3652 },
3653 flags: []string{
3654 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3655 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3656 },
3657 })
3658 tests = append(tests, testCase{
3659 testType: serverTest,
3660 name: "Basic-Server-ECDHE-ECDSA",
3661 config: Config{
3662 MaxVersion: VersionTLS12,
3663 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3664 },
3665 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003666 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3667 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003668 },
3669 })
3670
David Benjamin760b1dd2015-05-15 23:33:48 -04003671 // No session ticket support; server doesn't send NewSessionTicket.
3672 tests = append(tests, testCase{
3673 name: "SessionTicketsDisabled-Client",
3674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003675 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003676 SessionTicketsDisabled: true,
3677 },
3678 })
3679 tests = append(tests, testCase{
3680 testType: serverTest,
3681 name: "SessionTicketsDisabled-Server",
3682 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003683 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003684 SessionTicketsDisabled: true,
3685 },
3686 })
3687
3688 // Skip ServerKeyExchange in PSK key exchange if there's no
3689 // identity hint.
3690 tests = append(tests, testCase{
3691 name: "EmptyPSKHint-Client",
3692 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003693 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003694 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3695 PreSharedKey: []byte("secret"),
3696 },
3697 flags: []string{"-psk", "secret"},
3698 })
3699 tests = append(tests, testCase{
3700 testType: serverTest,
3701 name: "EmptyPSKHint-Server",
3702 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003703 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003704 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3705 PreSharedKey: []byte("secret"),
3706 },
3707 flags: []string{"-psk", "secret"},
3708 })
3709
David Benjamin4c3ddf72016-06-29 18:13:53 -04003710 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003711 tests = append(tests, testCase{
3712 testType: clientTest,
3713 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003714 config: Config{
3715 MaxVersion: VersionTLS12,
3716 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003717 flags: []string{
3718 "-enable-ocsp-stapling",
3719 "-expect-ocsp-response",
3720 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003721 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003722 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003723 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003724 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003725 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003726 testType: serverTest,
3727 name: "OCSPStapling-Server",
3728 config: Config{
3729 MaxVersion: VersionTLS12,
3730 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003731 expectedOCSPResponse: testOCSPResponse,
3732 flags: []string{
3733 "-ocsp-response",
3734 base64.StdEncoding.EncodeToString(testOCSPResponse),
3735 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003736 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003737 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003738 tests = append(tests, testCase{
3739 testType: clientTest,
3740 name: "OCSPStapling-Client-TLS13",
3741 config: Config{
3742 MaxVersion: VersionTLS13,
3743 },
3744 flags: []string{
3745 "-enable-ocsp-stapling",
3746 "-expect-ocsp-response",
3747 base64.StdEncoding.EncodeToString(testOCSPResponse),
3748 "-verify-peer",
3749 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003750 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003751 })
3752 tests = append(tests, testCase{
3753 testType: serverTest,
3754 name: "OCSPStapling-Server-TLS13",
3755 config: Config{
3756 MaxVersion: VersionTLS13,
3757 },
3758 expectedOCSPResponse: testOCSPResponse,
3759 flags: []string{
3760 "-ocsp-response",
3761 base64.StdEncoding.EncodeToString(testOCSPResponse),
3762 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003763 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003764 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003765
David Benjamin4c3ddf72016-06-29 18:13:53 -04003766 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003767 for _, vers := range tlsVersions {
3768 if config.protocol == dtls && !vers.hasDTLS {
3769 continue
3770 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003771 for _, testType := range []testType{clientTest, serverTest} {
3772 suffix := "-Client"
3773 if testType == serverTest {
3774 suffix = "-Server"
3775 }
3776 suffix += "-" + vers.name
3777
3778 flag := "-verify-peer"
3779 if testType == serverTest {
3780 flag = "-require-any-client-certificate"
3781 }
3782
3783 tests = append(tests, testCase{
3784 testType: testType,
3785 name: "CertificateVerificationSucceed" + suffix,
3786 config: Config{
3787 MaxVersion: vers.version,
3788 Certificates: []Certificate{rsaCertificate},
3789 },
3790 flags: []string{
3791 flag,
3792 "-expect-verify-result",
3793 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003794 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003795 })
3796 tests = append(tests, testCase{
3797 testType: testType,
3798 name: "CertificateVerificationFail" + suffix,
3799 config: Config{
3800 MaxVersion: vers.version,
3801 Certificates: []Certificate{rsaCertificate},
3802 },
3803 flags: []string{
3804 flag,
3805 "-verify-fail",
3806 },
3807 shouldFail: true,
3808 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3809 })
3810 }
3811
3812 // By default, the client is in a soft fail mode where the peer
3813 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003814 tests = append(tests, testCase{
3815 testType: clientTest,
3816 name: "CertificateVerificationSoftFail-" + vers.name,
3817 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003818 MaxVersion: vers.version,
3819 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003820 },
3821 flags: []string{
3822 "-verify-fail",
3823 "-expect-verify-result",
3824 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003825 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003826 })
3827 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003828
David Benjamin1d4f4c02016-07-26 18:03:08 -04003829 tests = append(tests, testCase{
3830 name: "ShimSendAlert",
3831 flags: []string{"-send-alert"},
3832 shimWritesFirst: true,
3833 shouldFail: true,
3834 expectedLocalError: "remote error: decompression failure",
3835 })
3836
David Benjamin582ba042016-07-07 12:33:25 -07003837 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003838 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003839 name: "Renegotiate-Client",
3840 config: Config{
3841 MaxVersion: VersionTLS12,
3842 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003843 renegotiate: 1,
3844 flags: []string{
3845 "-renegotiate-freely",
3846 "-expect-total-renegotiations", "1",
3847 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003848 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003849
David Benjamin47921102016-07-28 11:29:18 -04003850 tests = append(tests, testCase{
3851 name: "SendHalfHelloRequest",
3852 config: Config{
3853 MaxVersion: VersionTLS12,
3854 Bugs: ProtocolBugs{
3855 PackHelloRequestWithFinished: config.packHandshakeFlight,
3856 },
3857 },
3858 sendHalfHelloRequest: true,
3859 flags: []string{"-renegotiate-ignore"},
3860 shouldFail: true,
3861 expectedError: ":UNEXPECTED_RECORD:",
3862 })
3863
David Benjamin760b1dd2015-05-15 23:33:48 -04003864 // NPN on client and server; results in post-handshake message.
3865 tests = append(tests, testCase{
3866 name: "NPN-Client",
3867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003868 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003869 NextProtos: []string{"foo"},
3870 },
3871 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003872 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003873 expectedNextProto: "foo",
3874 expectedNextProtoType: npn,
3875 })
3876 tests = append(tests, testCase{
3877 testType: serverTest,
3878 name: "NPN-Server",
3879 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003880 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 NextProtos: []string{"bar"},
3882 },
3883 flags: []string{
3884 "-advertise-npn", "\x03foo\x03bar\x03baz",
3885 "-expect-next-proto", "bar",
3886 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003887 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003888 expectedNextProto: "bar",
3889 expectedNextProtoType: npn,
3890 })
3891
3892 // TODO(davidben): Add tests for when False Start doesn't trigger.
3893
3894 // Client does False Start and negotiates NPN.
3895 tests = append(tests, testCase{
3896 name: "FalseStart",
3897 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003898 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003899 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3900 NextProtos: []string{"foo"},
3901 Bugs: ProtocolBugs{
3902 ExpectFalseStart: true,
3903 },
3904 },
3905 flags: []string{
3906 "-false-start",
3907 "-select-next-proto", "foo",
3908 },
3909 shimWritesFirst: true,
3910 resumeSession: true,
3911 })
3912
3913 // Client does False Start and negotiates ALPN.
3914 tests = append(tests, testCase{
3915 name: "FalseStart-ALPN",
3916 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003917 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003918 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3919 NextProtos: []string{"foo"},
3920 Bugs: ProtocolBugs{
3921 ExpectFalseStart: true,
3922 },
3923 },
3924 flags: []string{
3925 "-false-start",
3926 "-advertise-alpn", "\x03foo",
3927 },
3928 shimWritesFirst: true,
3929 resumeSession: true,
3930 })
3931
3932 // Client does False Start but doesn't explicitly call
3933 // SSL_connect.
3934 tests = append(tests, testCase{
3935 name: "FalseStart-Implicit",
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 },
3941 flags: []string{
3942 "-implicit-handshake",
3943 "-false-start",
3944 "-advertise-alpn", "\x03foo",
3945 },
3946 })
3947
3948 // False Start without session tickets.
3949 tests = append(tests, testCase{
3950 name: "FalseStart-SessionTicketsDisabled",
3951 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003952 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3954 NextProtos: []string{"foo"},
3955 SessionTicketsDisabled: true,
3956 Bugs: ProtocolBugs{
3957 ExpectFalseStart: true,
3958 },
3959 },
3960 flags: []string{
3961 "-false-start",
3962 "-select-next-proto", "foo",
3963 },
3964 shimWritesFirst: true,
3965 })
3966
3967 // Server parses a V2ClientHello.
3968 tests = append(tests, testCase{
3969 testType: serverTest,
3970 name: "SendV2ClientHello",
3971 config: Config{
3972 // Choose a cipher suite that does not involve
3973 // elliptic curves, so no extensions are
3974 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003975 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003976 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003977 Bugs: ProtocolBugs{
3978 SendV2ClientHello: true,
3979 },
3980 },
3981 })
3982
Nick Harper60a85cb2016-09-23 16:25:11 -07003983 // Test Channel ID
3984 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07003985 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07003986 continue
3987 }
3988 // Client sends a Channel ID.
3989 tests = append(tests, testCase{
3990 name: "ChannelID-Client-" + ver.name,
3991 config: Config{
3992 MaxVersion: ver.version,
3993 RequestChannelID: true,
3994 },
3995 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
3996 resumeSession: true,
3997 expectChannelID: true,
3998 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003999
Nick Harper60a85cb2016-09-23 16:25:11 -07004000 // Server accepts a Channel ID.
4001 tests = append(tests, testCase{
4002 testType: serverTest,
4003 name: "ChannelID-Server-" + ver.name,
4004 config: Config{
4005 MaxVersion: ver.version,
4006 ChannelID: channelIDKey,
4007 },
4008 flags: []string{
4009 "-expect-channel-id",
4010 base64.StdEncoding.EncodeToString(channelIDBytes),
4011 },
4012 resumeSession: true,
4013 expectChannelID: true,
4014 })
4015
4016 tests = append(tests, testCase{
4017 testType: serverTest,
4018 name: "InvalidChannelIDSignature-" + ver.name,
4019 config: Config{
4020 MaxVersion: ver.version,
4021 ChannelID: channelIDKey,
4022 Bugs: ProtocolBugs{
4023 InvalidChannelIDSignature: true,
4024 },
4025 },
4026 flags: []string{"-enable-channel-id"},
4027 shouldFail: true,
4028 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4029 })
4030 }
David Benjamin30789da2015-08-29 22:56:45 -04004031
David Benjaminf8fcdf32016-06-08 15:56:13 -04004032 // Channel ID and NPN at the same time, to ensure their relative
4033 // ordering is correct.
4034 tests = append(tests, testCase{
4035 name: "ChannelID-NPN-Client",
4036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004037 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004038 RequestChannelID: true,
4039 NextProtos: []string{"foo"},
4040 },
4041 flags: []string{
4042 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4043 "-select-next-proto", "foo",
4044 },
4045 resumeSession: true,
4046 expectChannelID: true,
4047 expectedNextProto: "foo",
4048 expectedNextProtoType: npn,
4049 })
4050 tests = append(tests, testCase{
4051 testType: serverTest,
4052 name: "ChannelID-NPN-Server",
4053 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004054 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004055 ChannelID: channelIDKey,
4056 NextProtos: []string{"bar"},
4057 },
4058 flags: []string{
4059 "-expect-channel-id",
4060 base64.StdEncoding.EncodeToString(channelIDBytes),
4061 "-advertise-npn", "\x03foo\x03bar\x03baz",
4062 "-expect-next-proto", "bar",
4063 },
4064 resumeSession: true,
4065 expectChannelID: true,
4066 expectedNextProto: "bar",
4067 expectedNextProtoType: npn,
4068 })
4069
David Benjamin30789da2015-08-29 22:56:45 -04004070 // Bidirectional shutdown with the runner initiating.
4071 tests = append(tests, testCase{
4072 name: "Shutdown-Runner",
4073 config: Config{
4074 Bugs: ProtocolBugs{
4075 ExpectCloseNotify: true,
4076 },
4077 },
4078 flags: []string{"-check-close-notify"},
4079 })
4080
4081 // Bidirectional shutdown with the shim initiating. The runner,
4082 // in the meantime, sends garbage before the close_notify which
4083 // the shim must ignore.
4084 tests = append(tests, testCase{
4085 name: "Shutdown-Shim",
4086 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004087 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004088 Bugs: ProtocolBugs{
4089 ExpectCloseNotify: true,
4090 },
4091 },
4092 shimShutsDown: true,
4093 sendEmptyRecords: 1,
4094 sendWarningAlerts: 1,
4095 flags: []string{"-check-close-notify"},
4096 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004097 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004098 // TODO(davidben): DTLS 1.3 will want a similar thing for
4099 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004100 tests = append(tests, testCase{
4101 name: "SkipHelloVerifyRequest",
4102 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004103 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004104 Bugs: ProtocolBugs{
4105 SkipHelloVerifyRequest: true,
4106 },
4107 },
4108 })
4109 }
4110
David Benjamin760b1dd2015-05-15 23:33:48 -04004111 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004112 test.protocol = config.protocol
4113 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004114 test.name += "-DTLS"
4115 }
David Benjamin582ba042016-07-07 12:33:25 -07004116 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004117 test.name += "-Async"
4118 test.flags = append(test.flags, "-async")
4119 } else {
4120 test.name += "-Sync"
4121 }
David Benjamin582ba042016-07-07 12:33:25 -07004122 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004123 test.name += "-SplitHandshakeRecords"
4124 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004125 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004126 test.config.Bugs.MaxPacketLength = 256
4127 test.flags = append(test.flags, "-mtu", "256")
4128 }
4129 }
David Benjamin582ba042016-07-07 12:33:25 -07004130 if config.packHandshakeFlight {
4131 test.name += "-PackHandshakeFlight"
4132 test.config.Bugs.PackHandshakeFlight = true
4133 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004134 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004135 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004136}
4137
Adam Langley524e7172015-02-20 16:04:00 -08004138func addDDoSCallbackTests() {
4139 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004140 for _, resume := range []bool{false, true} {
4141 suffix := "Resume"
4142 if resume {
4143 suffix = "No" + suffix
4144 }
4145
4146 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004147 testType: serverTest,
4148 name: "Server-DDoS-OK-" + suffix,
4149 config: Config{
4150 MaxVersion: VersionTLS12,
4151 },
Adam Langley524e7172015-02-20 16:04:00 -08004152 flags: []string{"-install-ddos-callback"},
4153 resumeSession: resume,
4154 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004155 testCases = append(testCases, testCase{
4156 testType: serverTest,
4157 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4158 config: Config{
4159 MaxVersion: VersionTLS13,
4160 },
4161 flags: []string{"-install-ddos-callback"},
4162 resumeSession: resume,
4163 })
Adam Langley524e7172015-02-20 16:04:00 -08004164
4165 failFlag := "-fail-ddos-callback"
4166 if resume {
4167 failFlag = "-fail-second-ddos-callback"
4168 }
4169 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004170 testType: serverTest,
4171 name: "Server-DDoS-Reject-" + suffix,
4172 config: Config{
4173 MaxVersion: VersionTLS12,
4174 },
David Benjamin2c66e072016-09-16 15:58:00 -04004175 flags: []string{"-install-ddos-callback", failFlag},
4176 resumeSession: resume,
4177 shouldFail: true,
4178 expectedError: ":CONNECTION_REJECTED:",
4179 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004180 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004181 testCases = append(testCases, testCase{
4182 testType: serverTest,
4183 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4184 config: Config{
4185 MaxVersion: VersionTLS13,
4186 },
David Benjamin2c66e072016-09-16 15:58:00 -04004187 flags: []string{"-install-ddos-callback", failFlag},
4188 resumeSession: resume,
4189 shouldFail: true,
4190 expectedError: ":CONNECTION_REJECTED:",
4191 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004192 })
Adam Langley524e7172015-02-20 16:04:00 -08004193 }
4194}
4195
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004196func addVersionNegotiationTests() {
4197 for i, shimVers := range tlsVersions {
4198 // Assemble flags to disable all newer versions on the shim.
4199 var flags []string
4200 for _, vers := range tlsVersions[i+1:] {
4201 flags = append(flags, vers.flag)
4202 }
4203
Steven Valdezfdd10992016-09-15 16:27:05 -04004204 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004205 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004206 protocols := []protocol{tls}
4207 if runnerVers.hasDTLS && shimVers.hasDTLS {
4208 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004209 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004210 for _, protocol := range protocols {
4211 expectedVersion := shimVers.version
4212 if runnerVers.version < shimVers.version {
4213 expectedVersion = runnerVers.version
4214 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004215
David Benjamin8b8c0062014-11-23 02:47:52 -05004216 suffix := shimVers.name + "-" + runnerVers.name
4217 if protocol == dtls {
4218 suffix += "-DTLS"
4219 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004220
David Benjamin1eb367c2014-12-12 18:17:51 -05004221 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4222
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004223 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004224 clientVers := shimVers.version
4225 if clientVers > VersionTLS10 {
4226 clientVers = VersionTLS10
4227 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004228 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004229 serverVers := expectedVersion
4230 if expectedVersion >= VersionTLS13 {
4231 serverVers = VersionTLS10
4232 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004233 serverVers = versionToWire(serverVers, protocol == dtls)
4234
David Benjamin8b8c0062014-11-23 02:47:52 -05004235 testCases = append(testCases, testCase{
4236 protocol: protocol,
4237 testType: clientTest,
4238 name: "VersionNegotiation-Client-" + suffix,
4239 config: Config{
4240 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004241 Bugs: ProtocolBugs{
4242 ExpectInitialRecordVersion: clientVers,
4243 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004244 },
4245 flags: flags,
4246 expectedVersion: expectedVersion,
4247 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004248 testCases = append(testCases, testCase{
4249 protocol: protocol,
4250 testType: clientTest,
4251 name: "VersionNegotiation-Client2-" + suffix,
4252 config: Config{
4253 MaxVersion: runnerVers.version,
4254 Bugs: ProtocolBugs{
4255 ExpectInitialRecordVersion: clientVers,
4256 },
4257 },
4258 flags: []string{"-max-version", shimVersFlag},
4259 expectedVersion: expectedVersion,
4260 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004261
4262 testCases = append(testCases, testCase{
4263 protocol: protocol,
4264 testType: serverTest,
4265 name: "VersionNegotiation-Server-" + suffix,
4266 config: Config{
4267 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004268 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004269 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004270 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004271 },
4272 flags: flags,
4273 expectedVersion: expectedVersion,
4274 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004275 testCases = append(testCases, testCase{
4276 protocol: protocol,
4277 testType: serverTest,
4278 name: "VersionNegotiation-Server2-" + suffix,
4279 config: Config{
4280 MaxVersion: runnerVers.version,
4281 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004282 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004283 },
4284 },
4285 flags: []string{"-max-version", shimVersFlag},
4286 expectedVersion: expectedVersion,
4287 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004288 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004289 }
4290 }
David Benjamin95c69562016-06-29 18:15:03 -04004291
Steven Valdezfdd10992016-09-15 16:27:05 -04004292 // Test the version extension at all versions.
4293 for _, vers := range tlsVersions {
4294 protocols := []protocol{tls}
4295 if vers.hasDTLS {
4296 protocols = append(protocols, dtls)
4297 }
4298 for _, protocol := range protocols {
4299 suffix := vers.name
4300 if protocol == dtls {
4301 suffix += "-DTLS"
4302 }
4303
4304 wireVersion := versionToWire(vers.version, protocol == dtls)
4305 testCases = append(testCases, testCase{
4306 protocol: protocol,
4307 testType: serverTest,
4308 name: "VersionNegotiationExtension-" + suffix,
4309 config: Config{
4310 Bugs: ProtocolBugs{
4311 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4312 },
4313 },
4314 expectedVersion: vers.version,
4315 })
4316 }
4317
4318 }
4319
4320 // If all versions are unknown, negotiation fails.
4321 testCases = append(testCases, testCase{
4322 testType: serverTest,
4323 name: "NoSupportedVersions",
4324 config: Config{
4325 Bugs: ProtocolBugs{
4326 SendSupportedVersions: []uint16{0x1111},
4327 },
4328 },
4329 shouldFail: true,
4330 expectedError: ":UNSUPPORTED_PROTOCOL:",
4331 })
4332 testCases = append(testCases, testCase{
4333 protocol: dtls,
4334 testType: serverTest,
4335 name: "NoSupportedVersions-DTLS",
4336 config: Config{
4337 Bugs: ProtocolBugs{
4338 SendSupportedVersions: []uint16{0x1111},
4339 },
4340 },
4341 shouldFail: true,
4342 expectedError: ":UNSUPPORTED_PROTOCOL:",
4343 })
4344
4345 testCases = append(testCases, testCase{
4346 testType: serverTest,
4347 name: "ClientHelloVersionTooHigh",
4348 config: Config{
4349 MaxVersion: VersionTLS13,
4350 Bugs: ProtocolBugs{
4351 SendClientVersion: 0x0304,
4352 OmitSupportedVersions: true,
4353 },
4354 },
4355 expectedVersion: VersionTLS12,
4356 })
4357
4358 testCases = append(testCases, testCase{
4359 testType: serverTest,
4360 name: "ConflictingVersionNegotiation",
4361 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004362 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004363 SendClientVersion: VersionTLS12,
4364 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004365 },
4366 },
David Benjaminad75a662016-09-30 15:42:59 -04004367 // The extension takes precedence over the ClientHello version.
4368 expectedVersion: VersionTLS11,
4369 })
4370
4371 testCases = append(testCases, testCase{
4372 testType: serverTest,
4373 name: "ConflictingVersionNegotiation-2",
4374 config: Config{
4375 Bugs: ProtocolBugs{
4376 SendClientVersion: VersionTLS11,
4377 SendSupportedVersions: []uint16{VersionTLS12},
4378 },
4379 },
4380 // The extension takes precedence over the ClientHello version.
4381 expectedVersion: VersionTLS12,
4382 })
4383
4384 testCases = append(testCases, testCase{
4385 testType: serverTest,
4386 name: "RejectFinalTLS13",
4387 config: Config{
4388 Bugs: ProtocolBugs{
4389 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4390 },
4391 },
4392 // We currently implement a draft TLS 1.3 version. Ensure that
4393 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004394 expectedVersion: VersionTLS12,
4395 })
4396
Brian Smithf85d3232016-10-28 10:34:06 -10004397 // Test that the maximum version is selected regardless of the
4398 // client-sent order.
4399 testCases = append(testCases, testCase{
4400 testType: serverTest,
4401 name: "IgnoreClientVersionOrder",
4402 config: Config{
4403 Bugs: ProtocolBugs{
4404 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4405 },
4406 },
4407 expectedVersion: VersionTLS13,
4408 })
4409
David Benjamin95c69562016-06-29 18:15:03 -04004410 // Test for version tolerance.
4411 testCases = append(testCases, testCase{
4412 testType: serverTest,
4413 name: "MinorVersionTolerance",
4414 config: Config{
4415 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004416 SendClientVersion: 0x03ff,
4417 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004418 },
4419 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004420 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004421 })
4422 testCases = append(testCases, testCase{
4423 testType: serverTest,
4424 name: "MajorVersionTolerance",
4425 config: Config{
4426 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004427 SendClientVersion: 0x0400,
4428 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004429 },
4430 },
David Benjaminad75a662016-09-30 15:42:59 -04004431 // TLS 1.3 must be negotiated with the supported_versions
4432 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004433 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004434 })
David Benjaminad75a662016-09-30 15:42:59 -04004435 testCases = append(testCases, testCase{
4436 testType: serverTest,
4437 name: "VersionTolerance-TLS13",
4438 config: Config{
4439 Bugs: ProtocolBugs{
4440 // Although TLS 1.3 does not use
4441 // ClientHello.version, it still tolerates high
4442 // values there.
4443 SendClientVersion: 0x0400,
4444 },
4445 },
4446 expectedVersion: VersionTLS13,
4447 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004448
David Benjamin95c69562016-06-29 18:15:03 -04004449 testCases = append(testCases, testCase{
4450 protocol: dtls,
4451 testType: serverTest,
4452 name: "MinorVersionTolerance-DTLS",
4453 config: Config{
4454 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004455 SendClientVersion: 0xfe00,
4456 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004457 },
4458 },
4459 expectedVersion: VersionTLS12,
4460 })
4461 testCases = append(testCases, testCase{
4462 protocol: dtls,
4463 testType: serverTest,
4464 name: "MajorVersionTolerance-DTLS",
4465 config: Config{
4466 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004467 SendClientVersion: 0xfdff,
4468 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004469 },
4470 },
4471 expectedVersion: VersionTLS12,
4472 })
4473
4474 // Test that versions below 3.0 are rejected.
4475 testCases = append(testCases, testCase{
4476 testType: serverTest,
4477 name: "VersionTooLow",
4478 config: Config{
4479 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004480 SendClientVersion: 0x0200,
4481 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004482 },
4483 },
4484 shouldFail: true,
4485 expectedError: ":UNSUPPORTED_PROTOCOL:",
4486 })
4487 testCases = append(testCases, testCase{
4488 protocol: dtls,
4489 testType: serverTest,
4490 name: "VersionTooLow-DTLS",
4491 config: Config{
4492 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004493 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004494 },
4495 },
4496 shouldFail: true,
4497 expectedError: ":UNSUPPORTED_PROTOCOL:",
4498 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004499
David Benjamin2dc02042016-09-19 19:57:37 -04004500 testCases = append(testCases, testCase{
4501 name: "ServerBogusVersion",
4502 config: Config{
4503 Bugs: ProtocolBugs{
4504 SendServerHelloVersion: 0x1234,
4505 },
4506 },
4507 shouldFail: true,
4508 expectedError: ":UNSUPPORTED_PROTOCOL:",
4509 })
4510
David Benjamin1f61f0d2016-07-10 12:20:35 -04004511 // Test TLS 1.3's downgrade signal.
4512 testCases = append(testCases, testCase{
4513 name: "Downgrade-TLS12-Client",
4514 config: Config{
4515 Bugs: ProtocolBugs{
4516 NegotiateVersion: VersionTLS12,
4517 },
4518 },
David Benjamin592b5322016-09-30 15:15:01 -04004519 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004520 // TODO(davidben): This test should fail once TLS 1.3 is final
4521 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004522 })
4523 testCases = append(testCases, testCase{
4524 testType: serverTest,
4525 name: "Downgrade-TLS12-Server",
4526 config: Config{
4527 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004528 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004529 },
4530 },
David Benjamin592b5322016-09-30 15:15:01 -04004531 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004532 // TODO(davidben): This test should fail once TLS 1.3 is final
4533 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004534 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004535}
4536
David Benjaminaccb4542014-12-12 23:44:33 -05004537func addMinimumVersionTests() {
4538 for i, shimVers := range tlsVersions {
4539 // Assemble flags to disable all older versions on the shim.
4540 var flags []string
4541 for _, vers := range tlsVersions[:i] {
4542 flags = append(flags, vers.flag)
4543 }
4544
4545 for _, runnerVers := range tlsVersions {
4546 protocols := []protocol{tls}
4547 if runnerVers.hasDTLS && shimVers.hasDTLS {
4548 protocols = append(protocols, dtls)
4549 }
4550 for _, protocol := range protocols {
4551 suffix := shimVers.name + "-" + runnerVers.name
4552 if protocol == dtls {
4553 suffix += "-DTLS"
4554 }
4555 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4556
David Benjaminaccb4542014-12-12 23:44:33 -05004557 var expectedVersion uint16
4558 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004559 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004560 if runnerVers.version >= shimVers.version {
4561 expectedVersion = runnerVers.version
4562 } else {
4563 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004564 expectedError = ":UNSUPPORTED_PROTOCOL:"
4565 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004566 }
4567
4568 testCases = append(testCases, testCase{
4569 protocol: protocol,
4570 testType: clientTest,
4571 name: "MinimumVersion-Client-" + suffix,
4572 config: Config{
4573 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004574 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004575 // Ensure the server does not decline to
4576 // select a version (versions extension) or
4577 // cipher (some ciphers depend on versions).
4578 NegotiateVersion: runnerVers.version,
4579 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004580 },
David Benjaminaccb4542014-12-12 23:44:33 -05004581 },
David Benjamin87909c02014-12-13 01:55:01 -05004582 flags: flags,
4583 expectedVersion: expectedVersion,
4584 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004585 expectedError: expectedError,
4586 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004587 })
4588 testCases = append(testCases, testCase{
4589 protocol: protocol,
4590 testType: clientTest,
4591 name: "MinimumVersion-Client2-" + suffix,
4592 config: Config{
4593 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004594 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004595 // Ensure the server does not decline to
4596 // select a version (versions extension) or
4597 // cipher (some ciphers depend on versions).
4598 NegotiateVersion: runnerVers.version,
4599 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004600 },
David Benjaminaccb4542014-12-12 23:44:33 -05004601 },
David Benjamin87909c02014-12-13 01:55:01 -05004602 flags: []string{"-min-version", shimVersFlag},
4603 expectedVersion: expectedVersion,
4604 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004605 expectedError: expectedError,
4606 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004607 })
4608
4609 testCases = append(testCases, testCase{
4610 protocol: protocol,
4611 testType: serverTest,
4612 name: "MinimumVersion-Server-" + suffix,
4613 config: Config{
4614 MaxVersion: runnerVers.version,
4615 },
David Benjamin87909c02014-12-13 01:55:01 -05004616 flags: flags,
4617 expectedVersion: expectedVersion,
4618 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004619 expectedError: expectedError,
4620 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004621 })
4622 testCases = append(testCases, testCase{
4623 protocol: protocol,
4624 testType: serverTest,
4625 name: "MinimumVersion-Server2-" + suffix,
4626 config: Config{
4627 MaxVersion: runnerVers.version,
4628 },
David Benjamin87909c02014-12-13 01:55:01 -05004629 flags: []string{"-min-version", shimVersFlag},
4630 expectedVersion: expectedVersion,
4631 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004632 expectedError: expectedError,
4633 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004634 })
4635 }
4636 }
4637 }
4638}
4639
David Benjamine78bfde2014-09-06 12:45:15 -04004640func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004641 // TODO(davidben): Extensions, where applicable, all move their server
4642 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4643 // tests for both. Also test interaction with 0-RTT when implemented.
4644
David Benjamin97d17d92016-07-14 16:12:00 -04004645 // Repeat extensions tests all versions except SSL 3.0.
4646 for _, ver := range tlsVersions {
4647 if ver.version == VersionSSL30 {
4648 continue
4649 }
4650
David Benjamin97d17d92016-07-14 16:12:00 -04004651 // Test that duplicate extensions are rejected.
4652 testCases = append(testCases, testCase{
4653 testType: clientTest,
4654 name: "DuplicateExtensionClient-" + ver.name,
4655 config: Config{
4656 MaxVersion: ver.version,
4657 Bugs: ProtocolBugs{
4658 DuplicateExtension: true,
4659 },
David Benjamine78bfde2014-09-06 12:45:15 -04004660 },
David Benjamin97d17d92016-07-14 16:12:00 -04004661 shouldFail: true,
4662 expectedLocalError: "remote error: error decoding message",
4663 })
4664 testCases = append(testCases, testCase{
4665 testType: serverTest,
4666 name: "DuplicateExtensionServer-" + ver.name,
4667 config: Config{
4668 MaxVersion: ver.version,
4669 Bugs: ProtocolBugs{
4670 DuplicateExtension: true,
4671 },
David Benjamine78bfde2014-09-06 12:45:15 -04004672 },
David Benjamin97d17d92016-07-14 16:12:00 -04004673 shouldFail: true,
4674 expectedLocalError: "remote error: error decoding message",
4675 })
4676
4677 // Test SNI.
4678 testCases = append(testCases, testCase{
4679 testType: clientTest,
4680 name: "ServerNameExtensionClient-" + ver.name,
4681 config: Config{
4682 MaxVersion: ver.version,
4683 Bugs: ProtocolBugs{
4684 ExpectServerName: "example.com",
4685 },
David Benjamine78bfde2014-09-06 12:45:15 -04004686 },
David Benjamin97d17d92016-07-14 16:12:00 -04004687 flags: []string{"-host-name", "example.com"},
4688 })
4689 testCases = append(testCases, testCase{
4690 testType: clientTest,
4691 name: "ServerNameExtensionClientMismatch-" + ver.name,
4692 config: Config{
4693 MaxVersion: ver.version,
4694 Bugs: ProtocolBugs{
4695 ExpectServerName: "mismatch.com",
4696 },
David Benjamine78bfde2014-09-06 12:45:15 -04004697 },
David Benjamin97d17d92016-07-14 16:12:00 -04004698 flags: []string{"-host-name", "example.com"},
4699 shouldFail: true,
4700 expectedLocalError: "tls: unexpected server name",
4701 })
4702 testCases = append(testCases, testCase{
4703 testType: clientTest,
4704 name: "ServerNameExtensionClientMissing-" + ver.name,
4705 config: Config{
4706 MaxVersion: ver.version,
4707 Bugs: ProtocolBugs{
4708 ExpectServerName: "missing.com",
4709 },
David Benjamine78bfde2014-09-06 12:45:15 -04004710 },
David Benjamin97d17d92016-07-14 16:12:00 -04004711 shouldFail: true,
4712 expectedLocalError: "tls: unexpected server name",
4713 })
4714 testCases = append(testCases, testCase{
4715 testType: serverTest,
4716 name: "ServerNameExtensionServer-" + ver.name,
4717 config: Config{
4718 MaxVersion: ver.version,
4719 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004720 },
David Benjamin97d17d92016-07-14 16:12:00 -04004721 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004722 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004723 })
4724
4725 // Test ALPN.
4726 testCases = append(testCases, testCase{
4727 testType: clientTest,
4728 name: "ALPNClient-" + ver.name,
4729 config: Config{
4730 MaxVersion: ver.version,
4731 NextProtos: []string{"foo"},
4732 },
4733 flags: []string{
4734 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4735 "-expect-alpn", "foo",
4736 },
4737 expectedNextProto: "foo",
4738 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004739 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004740 })
4741 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004742 testType: clientTest,
4743 name: "ALPNClient-Mismatch-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 Bugs: ProtocolBugs{
4747 SendALPN: "baz",
4748 },
4749 },
4750 flags: []string{
4751 "-advertise-alpn", "\x03foo\x03bar",
4752 },
4753 shouldFail: true,
4754 expectedError: ":INVALID_ALPN_PROTOCOL:",
4755 expectedLocalError: "remote error: illegal parameter",
4756 })
4757 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004758 testType: serverTest,
4759 name: "ALPNServer-" + ver.name,
4760 config: Config{
4761 MaxVersion: ver.version,
4762 NextProtos: []string{"foo", "bar", "baz"},
4763 },
4764 flags: []string{
4765 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4766 "-select-alpn", "foo",
4767 },
4768 expectedNextProto: "foo",
4769 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004770 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004771 })
4772 testCases = append(testCases, testCase{
4773 testType: serverTest,
4774 name: "ALPNServer-Decline-" + ver.name,
4775 config: Config{
4776 MaxVersion: ver.version,
4777 NextProtos: []string{"foo", "bar", "baz"},
4778 },
4779 flags: []string{"-decline-alpn"},
4780 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004781 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004782 })
4783
David Benjamin25fe85b2016-08-09 20:00:32 -04004784 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4785 // called once.
4786 testCases = append(testCases, testCase{
4787 testType: serverTest,
4788 name: "ALPNServer-Async-" + ver.name,
4789 config: Config{
4790 MaxVersion: ver.version,
4791 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004792 // Prior to TLS 1.3, exercise the asynchronous session callback.
4793 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004794 },
4795 flags: []string{
4796 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4797 "-select-alpn", "foo",
4798 "-async",
4799 },
4800 expectedNextProto: "foo",
4801 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004802 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004803 })
4804
David Benjamin97d17d92016-07-14 16:12:00 -04004805 var emptyString string
4806 testCases = append(testCases, testCase{
4807 testType: clientTest,
4808 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4809 config: Config{
4810 MaxVersion: ver.version,
4811 NextProtos: []string{""},
4812 Bugs: ProtocolBugs{
4813 // A server returning an empty ALPN protocol
4814 // should be rejected.
4815 ALPNProtocol: &emptyString,
4816 },
4817 },
4818 flags: []string{
4819 "-advertise-alpn", "\x03foo",
4820 },
4821 shouldFail: true,
4822 expectedError: ":PARSE_TLSEXT:",
4823 })
4824 testCases = append(testCases, testCase{
4825 testType: serverTest,
4826 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4827 config: Config{
4828 MaxVersion: ver.version,
4829 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004830 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004831 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004832 },
David Benjamin97d17d92016-07-14 16:12:00 -04004833 flags: []string{
4834 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004835 },
David Benjamin97d17d92016-07-14 16:12:00 -04004836 shouldFail: true,
4837 expectedError: ":PARSE_TLSEXT:",
4838 })
4839
4840 // Test NPN and the interaction with ALPN.
4841 if ver.version < VersionTLS13 {
4842 // Test that the server prefers ALPN over NPN.
4843 testCases = append(testCases, testCase{
4844 testType: serverTest,
4845 name: "ALPNServer-Preferred-" + ver.name,
4846 config: Config{
4847 MaxVersion: ver.version,
4848 NextProtos: []string{"foo", "bar", "baz"},
4849 },
4850 flags: []string{
4851 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4852 "-select-alpn", "foo",
4853 "-advertise-npn", "\x03foo\x03bar\x03baz",
4854 },
4855 expectedNextProto: "foo",
4856 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004857 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004858 })
4859 testCases = append(testCases, testCase{
4860 testType: serverTest,
4861 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4862 config: Config{
4863 MaxVersion: ver.version,
4864 NextProtos: []string{"foo", "bar", "baz"},
4865 Bugs: ProtocolBugs{
4866 SwapNPNAndALPN: true,
4867 },
4868 },
4869 flags: []string{
4870 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4871 "-select-alpn", "foo",
4872 "-advertise-npn", "\x03foo\x03bar\x03baz",
4873 },
4874 expectedNextProto: "foo",
4875 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004876 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004877 })
4878
4879 // Test that negotiating both NPN and ALPN is forbidden.
4880 testCases = append(testCases, testCase{
4881 name: "NegotiateALPNAndNPN-" + ver.name,
4882 config: Config{
4883 MaxVersion: ver.version,
4884 NextProtos: []string{"foo", "bar", "baz"},
4885 Bugs: ProtocolBugs{
4886 NegotiateALPNAndNPN: true,
4887 },
4888 },
4889 flags: []string{
4890 "-advertise-alpn", "\x03foo",
4891 "-select-next-proto", "foo",
4892 },
4893 shouldFail: true,
4894 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4895 })
4896 testCases = append(testCases, testCase{
4897 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4898 config: Config{
4899 MaxVersion: ver.version,
4900 NextProtos: []string{"foo", "bar", "baz"},
4901 Bugs: ProtocolBugs{
4902 NegotiateALPNAndNPN: true,
4903 SwapNPNAndALPN: true,
4904 },
4905 },
4906 flags: []string{
4907 "-advertise-alpn", "\x03foo",
4908 "-select-next-proto", "foo",
4909 },
4910 shouldFail: true,
4911 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4912 })
David Benjamin97d17d92016-07-14 16:12:00 -04004913 }
4914
4915 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004916
4917 // Resume with a corrupt ticket.
4918 testCases = append(testCases, testCase{
4919 testType: serverTest,
4920 name: "CorruptTicket-" + ver.name,
4921 config: Config{
4922 MaxVersion: ver.version,
4923 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004924 FilterTicket: func(in []byte) ([]byte, error) {
4925 in[len(in)-1] ^= 1
4926 return in, nil
4927 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004928 },
4929 },
4930 resumeSession: true,
4931 expectResumeRejected: true,
4932 })
4933 // Test the ticket callback, with and without renewal.
4934 testCases = append(testCases, testCase{
4935 testType: serverTest,
4936 name: "TicketCallback-" + ver.name,
4937 config: Config{
4938 MaxVersion: ver.version,
4939 },
4940 resumeSession: true,
4941 flags: []string{"-use-ticket-callback"},
4942 })
4943 testCases = append(testCases, testCase{
4944 testType: serverTest,
4945 name: "TicketCallback-Renew-" + ver.name,
4946 config: Config{
4947 MaxVersion: ver.version,
4948 Bugs: ProtocolBugs{
4949 ExpectNewTicket: true,
4950 },
4951 },
4952 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4953 resumeSession: true,
4954 })
4955
4956 // Test that the ticket callback is only called once when everything before
4957 // it in the ClientHello is asynchronous. This corrupts the ticket so
4958 // certificate selection callbacks run.
4959 testCases = append(testCases, testCase{
4960 testType: serverTest,
4961 name: "TicketCallback-SingleCall-" + ver.name,
4962 config: Config{
4963 MaxVersion: ver.version,
4964 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004965 FilterTicket: func(in []byte) ([]byte, error) {
4966 in[len(in)-1] ^= 1
4967 return in, nil
4968 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004969 },
4970 },
4971 resumeSession: true,
4972 expectResumeRejected: true,
4973 flags: []string{
4974 "-use-ticket-callback",
4975 "-async",
4976 },
4977 })
4978
4979 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004980 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004981 testCases = append(testCases, testCase{
4982 testType: serverTest,
4983 name: "OversizedSessionId-" + ver.name,
4984 config: Config{
4985 MaxVersion: ver.version,
4986 Bugs: ProtocolBugs{
4987 OversizedSessionId: true,
4988 },
4989 },
4990 resumeSession: true,
4991 shouldFail: true,
4992 expectedError: ":DECODE_ERROR:",
4993 })
4994 }
4995
4996 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4997 // are ignored.
4998 if ver.hasDTLS {
4999 testCases = append(testCases, testCase{
5000 protocol: dtls,
5001 name: "SRTP-Client-" + ver.name,
5002 config: Config{
5003 MaxVersion: ver.version,
5004 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5005 },
5006 flags: []string{
5007 "-srtp-profiles",
5008 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5009 },
5010 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5011 })
5012 testCases = append(testCases, testCase{
5013 protocol: dtls,
5014 testType: serverTest,
5015 name: "SRTP-Server-" + ver.name,
5016 config: Config{
5017 MaxVersion: ver.version,
5018 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5019 },
5020 flags: []string{
5021 "-srtp-profiles",
5022 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5023 },
5024 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5025 })
5026 // Test that the MKI is ignored.
5027 testCases = append(testCases, testCase{
5028 protocol: dtls,
5029 testType: serverTest,
5030 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5031 config: Config{
5032 MaxVersion: ver.version,
5033 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5034 Bugs: ProtocolBugs{
5035 SRTPMasterKeyIdentifer: "bogus",
5036 },
5037 },
5038 flags: []string{
5039 "-srtp-profiles",
5040 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5041 },
5042 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5043 })
5044 // Test that SRTP isn't negotiated on the server if there were
5045 // no matching profiles.
5046 testCases = append(testCases, testCase{
5047 protocol: dtls,
5048 testType: serverTest,
5049 name: "SRTP-Server-NoMatch-" + ver.name,
5050 config: Config{
5051 MaxVersion: ver.version,
5052 SRTPProtectionProfiles: []uint16{100, 101, 102},
5053 },
5054 flags: []string{
5055 "-srtp-profiles",
5056 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5057 },
5058 expectedSRTPProtectionProfile: 0,
5059 })
5060 // Test that the server returning an invalid SRTP profile is
5061 // flagged as an error by the client.
5062 testCases = append(testCases, testCase{
5063 protocol: dtls,
5064 name: "SRTP-Client-NoMatch-" + ver.name,
5065 config: Config{
5066 MaxVersion: ver.version,
5067 Bugs: ProtocolBugs{
5068 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5069 },
5070 },
5071 flags: []string{
5072 "-srtp-profiles",
5073 "SRTP_AES128_CM_SHA1_80",
5074 },
5075 shouldFail: true,
5076 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5077 })
5078 }
5079
5080 // Test SCT list.
5081 testCases = append(testCases, testCase{
5082 name: "SignedCertificateTimestampList-Client-" + ver.name,
5083 testType: clientTest,
5084 config: Config{
5085 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005086 },
David Benjamin97d17d92016-07-14 16:12:00 -04005087 flags: []string{
5088 "-enable-signed-cert-timestamps",
5089 "-expect-signed-cert-timestamps",
5090 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005091 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005092 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005093 })
David Benjamindaa88502016-10-04 16:32:16 -04005094
Adam Langleycfa08c32016-11-17 13:21:27 -08005095 var differentSCTList []byte
5096 differentSCTList = append(differentSCTList, testSCTList...)
5097 differentSCTList[len(differentSCTList)-1] ^= 1
5098
David Benjamindaa88502016-10-04 16:32:16 -04005099 // The SCT extension did not specify that it must only be sent on resumption as it
5100 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005101 testCases = append(testCases, testCase{
5102 name: "SendSCTListOnResume-" + ver.name,
5103 config: Config{
5104 MaxVersion: ver.version,
5105 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005106 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005107 },
David Benjamind98452d2015-06-16 14:16:23 -04005108 },
David Benjamin97d17d92016-07-14 16:12:00 -04005109 flags: []string{
5110 "-enable-signed-cert-timestamps",
5111 "-expect-signed-cert-timestamps",
5112 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005113 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005114 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005115 })
David Benjamindaa88502016-10-04 16:32:16 -04005116
David Benjamin97d17d92016-07-14 16:12:00 -04005117 testCases = append(testCases, testCase{
5118 name: "SignedCertificateTimestampList-Server-" + ver.name,
5119 testType: serverTest,
5120 config: Config{
5121 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005122 },
David Benjamin97d17d92016-07-14 16:12:00 -04005123 flags: []string{
5124 "-signed-cert-timestamps",
5125 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005126 },
David Benjamin97d17d92016-07-14 16:12:00 -04005127 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005128 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005129 })
David Benjamin53210cb2016-11-16 09:01:48 +09005130
Adam Langleycfa08c32016-11-17 13:21:27 -08005131 emptySCTListCert := *testCerts[0].cert
5132 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5133
5134 // Test empty SCT list.
5135 testCases = append(testCases, testCase{
5136 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5137 testType: clientTest,
5138 config: Config{
5139 MaxVersion: ver.version,
5140 Certificates: []Certificate{emptySCTListCert},
5141 },
5142 flags: []string{
5143 "-enable-signed-cert-timestamps",
5144 },
5145 shouldFail: true,
5146 expectedError: ":ERROR_PARSING_EXTENSION:",
5147 })
5148
5149 emptySCTCert := *testCerts[0].cert
5150 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5151
5152 // Test empty SCT in non-empty list.
5153 testCases = append(testCases, testCase{
5154 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5155 testType: clientTest,
5156 config: Config{
5157 MaxVersion: ver.version,
5158 Certificates: []Certificate{emptySCTCert},
5159 },
5160 flags: []string{
5161 "-enable-signed-cert-timestamps",
5162 },
5163 shouldFail: true,
5164 expectedError: ":ERROR_PARSING_EXTENSION:",
5165 })
5166
David Benjamin53210cb2016-11-16 09:01:48 +09005167 // Test that certificate-related extensions are not sent unsolicited.
5168 testCases = append(testCases, testCase{
5169 testType: serverTest,
5170 name: "UnsolicitedCertificateExtensions-" + ver.name,
5171 config: Config{
5172 MaxVersion: ver.version,
5173 Bugs: ProtocolBugs{
5174 NoOCSPStapling: true,
5175 NoSignedCertificateTimestamps: true,
5176 },
5177 },
5178 flags: []string{
5179 "-ocsp-response",
5180 base64.StdEncoding.EncodeToString(testOCSPResponse),
5181 "-signed-cert-timestamps",
5182 base64.StdEncoding.EncodeToString(testSCTList),
5183 },
5184 })
David Benjamin97d17d92016-07-14 16:12:00 -04005185 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005186
Paul Lietar4fac72e2015-09-09 13:44:55 +01005187 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005188 testType: clientTest,
5189 name: "ClientHelloPadding",
5190 config: Config{
5191 Bugs: ProtocolBugs{
5192 RequireClientHelloSize: 512,
5193 },
5194 },
5195 // This hostname just needs to be long enough to push the
5196 // ClientHello into F5's danger zone between 256 and 511 bytes
5197 // long.
5198 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5199 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005200
5201 // Extensions should not function in SSL 3.0.
5202 testCases = append(testCases, testCase{
5203 testType: serverTest,
5204 name: "SSLv3Extensions-NoALPN",
5205 config: Config{
5206 MaxVersion: VersionSSL30,
5207 NextProtos: []string{"foo", "bar", "baz"},
5208 },
5209 flags: []string{
5210 "-select-alpn", "foo",
5211 },
5212 expectNoNextProto: true,
5213 })
5214
5215 // Test session tickets separately as they follow a different codepath.
5216 testCases = append(testCases, testCase{
5217 testType: serverTest,
5218 name: "SSLv3Extensions-NoTickets",
5219 config: Config{
5220 MaxVersion: VersionSSL30,
5221 Bugs: ProtocolBugs{
5222 // Historically, session tickets in SSL 3.0
5223 // failed in different ways depending on whether
5224 // the client supported renegotiation_info.
5225 NoRenegotiationInfo: true,
5226 },
5227 },
5228 resumeSession: true,
5229 })
5230 testCases = append(testCases, testCase{
5231 testType: serverTest,
5232 name: "SSLv3Extensions-NoTickets2",
5233 config: Config{
5234 MaxVersion: VersionSSL30,
5235 },
5236 resumeSession: true,
5237 })
5238
5239 // But SSL 3.0 does send and process renegotiation_info.
5240 testCases = append(testCases, testCase{
5241 testType: serverTest,
5242 name: "SSLv3Extensions-RenegotiationInfo",
5243 config: Config{
5244 MaxVersion: VersionSSL30,
5245 Bugs: ProtocolBugs{
5246 RequireRenegotiationInfo: true,
5247 },
5248 },
5249 })
5250 testCases = append(testCases, testCase{
5251 testType: serverTest,
5252 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5253 config: Config{
5254 MaxVersion: VersionSSL30,
5255 Bugs: ProtocolBugs{
5256 NoRenegotiationInfo: true,
5257 SendRenegotiationSCSV: true,
5258 RequireRenegotiationInfo: true,
5259 },
5260 },
5261 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005262
5263 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5264 // in ServerHello.
5265 testCases = append(testCases, testCase{
5266 name: "NPN-Forbidden-TLS13",
5267 config: Config{
5268 MaxVersion: VersionTLS13,
5269 NextProtos: []string{"foo"},
5270 Bugs: ProtocolBugs{
5271 NegotiateNPNAtAllVersions: true,
5272 },
5273 },
5274 flags: []string{"-select-next-proto", "foo"},
5275 shouldFail: true,
5276 expectedError: ":ERROR_PARSING_EXTENSION:",
5277 })
5278 testCases = append(testCases, testCase{
5279 name: "EMS-Forbidden-TLS13",
5280 config: Config{
5281 MaxVersion: VersionTLS13,
5282 Bugs: ProtocolBugs{
5283 NegotiateEMSAtAllVersions: true,
5284 },
5285 },
5286 shouldFail: true,
5287 expectedError: ":ERROR_PARSING_EXTENSION:",
5288 })
5289 testCases = append(testCases, testCase{
5290 name: "RenegotiationInfo-Forbidden-TLS13",
5291 config: Config{
5292 MaxVersion: VersionTLS13,
5293 Bugs: ProtocolBugs{
5294 NegotiateRenegotiationInfoAtAllVersions: true,
5295 },
5296 },
5297 shouldFail: true,
5298 expectedError: ":ERROR_PARSING_EXTENSION:",
5299 })
5300 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005301 name: "Ticket-Forbidden-TLS13",
5302 config: Config{
5303 MaxVersion: VersionTLS12,
5304 },
5305 resumeConfig: &Config{
5306 MaxVersion: VersionTLS13,
5307 Bugs: ProtocolBugs{
5308 AdvertiseTicketExtension: true,
5309 },
5310 },
5311 resumeSession: true,
5312 shouldFail: true,
5313 expectedError: ":ERROR_PARSING_EXTENSION:",
5314 })
5315
5316 // Test that illegal extensions in TLS 1.3 are declined by the server if
5317 // offered in ClientHello. The runner's server will fail if this occurs,
5318 // so we exercise the offering path. (EMS and Renegotiation Info are
5319 // implicit in every test.)
5320 testCases = append(testCases, testCase{
5321 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005322 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005323 config: Config{
5324 MaxVersion: VersionTLS13,
5325 NextProtos: []string{"bar"},
5326 },
5327 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5328 })
David Benjamin196df5b2016-09-21 16:23:27 -04005329
David Benjamindaa88502016-10-04 16:32:16 -04005330 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5331 // tolerated.
5332 testCases = append(testCases, testCase{
5333 name: "SendOCSPResponseOnResume-TLS12",
5334 config: Config{
5335 MaxVersion: VersionTLS12,
5336 Bugs: ProtocolBugs{
5337 SendOCSPResponseOnResume: []byte("bogus"),
5338 },
5339 },
5340 flags: []string{
5341 "-enable-ocsp-stapling",
5342 "-expect-ocsp-response",
5343 base64.StdEncoding.EncodeToString(testOCSPResponse),
5344 },
5345 resumeSession: true,
5346 })
5347
David Benjamindaa88502016-10-04 16:32:16 -04005348 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005349 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005350 config: Config{
5351 MaxVersion: VersionTLS13,
5352 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005353 SendExtensionOnCertificate: testOCSPExtension,
5354 },
5355 },
5356 shouldFail: true,
5357 expectedError: ":UNEXPECTED_EXTENSION:",
5358 })
5359
5360 testCases = append(testCases, testCase{
5361 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5362 config: Config{
5363 MaxVersion: VersionTLS13,
5364 Bugs: ProtocolBugs{
5365 SendExtensionOnCertificate: testSCTExtension,
5366 },
5367 },
5368 shouldFail: true,
5369 expectedError: ":UNEXPECTED_EXTENSION:",
5370 })
5371
5372 // Test that extensions on client certificates are never accepted.
5373 testCases = append(testCases, testCase{
5374 name: "SendExtensionOnClientCertificate-TLS13",
5375 testType: serverTest,
5376 config: Config{
5377 MaxVersion: VersionTLS13,
5378 Certificates: []Certificate{rsaCertificate},
5379 Bugs: ProtocolBugs{
5380 SendExtensionOnCertificate: testOCSPExtension,
5381 },
5382 },
5383 flags: []string{
5384 "-enable-ocsp-stapling",
5385 "-require-any-client-certificate",
5386 },
5387 shouldFail: true,
5388 expectedError: ":UNEXPECTED_EXTENSION:",
5389 })
5390
5391 testCases = append(testCases, testCase{
5392 name: "SendUnknownExtensionOnCertificate-TLS13",
5393 config: Config{
5394 MaxVersion: VersionTLS13,
5395 Bugs: ProtocolBugs{
5396 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5397 },
5398 },
5399 shouldFail: true,
5400 expectedError: ":UNEXPECTED_EXTENSION:",
5401 })
5402
Adam Langleycfa08c32016-11-17 13:21:27 -08005403 var differentSCTList []byte
5404 differentSCTList = append(differentSCTList, testSCTList...)
5405 differentSCTList[len(differentSCTList)-1] ^= 1
5406
Steven Valdeza833c352016-11-01 13:39:36 -04005407 // Test that extensions on intermediates are allowed but ignored.
5408 testCases = append(testCases, testCase{
5409 name: "IgnoreExtensionsOnIntermediates-TLS13",
5410 config: Config{
5411 MaxVersion: VersionTLS13,
5412 Certificates: []Certificate{rsaChainCertificate},
5413 Bugs: ProtocolBugs{
5414 // Send different values on the intermediate. This tests
5415 // the intermediate's extensions do not override the
5416 // leaf's.
5417 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005418 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005419 },
5420 },
5421 flags: []string{
5422 "-enable-ocsp-stapling",
5423 "-expect-ocsp-response",
5424 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005425 "-enable-signed-cert-timestamps",
5426 "-expect-signed-cert-timestamps",
5427 base64.StdEncoding.EncodeToString(testSCTList),
5428 },
5429 resumeSession: true,
5430 })
5431
5432 // Test that extensions are not sent on intermediates when configured
5433 // only for a leaf.
5434 testCases = append(testCases, testCase{
5435 testType: serverTest,
5436 name: "SendNoExtensionsOnIntermediate-TLS13",
5437 config: Config{
5438 MaxVersion: VersionTLS13,
5439 Bugs: ProtocolBugs{
5440 ExpectNoExtensionsOnIntermediate: true,
5441 },
5442 },
5443 flags: []string{
5444 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5445 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5446 "-ocsp-response",
5447 base64.StdEncoding.EncodeToString(testOCSPResponse),
5448 "-signed-cert-timestamps",
5449 base64.StdEncoding.EncodeToString(testSCTList),
5450 },
5451 })
5452
5453 // Test that extensions are not sent on client certificates.
5454 testCases = append(testCases, testCase{
5455 name: "SendNoClientCertificateExtensions-TLS13",
5456 config: Config{
5457 MaxVersion: VersionTLS13,
5458 ClientAuth: RequireAnyClientCert,
5459 },
5460 flags: []string{
5461 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5462 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5463 "-ocsp-response",
5464 base64.StdEncoding.EncodeToString(testOCSPResponse),
5465 "-signed-cert-timestamps",
5466 base64.StdEncoding.EncodeToString(testSCTList),
5467 },
5468 })
5469
5470 testCases = append(testCases, testCase{
5471 name: "SendDuplicateExtensionsOnCerts-TLS13",
5472 config: Config{
5473 MaxVersion: VersionTLS13,
5474 Bugs: ProtocolBugs{
5475 SendDuplicateCertExtensions: true,
5476 },
5477 },
5478 flags: []string{
5479 "-enable-ocsp-stapling",
5480 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005481 },
5482 resumeSession: true,
5483 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005484 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005485 })
Adam Langley9b885c52016-11-18 14:21:03 -08005486
5487 testCases = append(testCases, testCase{
5488 name: "SignedCertificateTimestampListInvalid-Server",
5489 testType: serverTest,
5490 flags: []string{
5491 "-signed-cert-timestamps",
5492 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5493 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005494 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005495 expectedError: ":INVALID_SCT_LIST:",
5496 })
David Benjamine78bfde2014-09-06 12:45:15 -04005497}
5498
David Benjamin01fe8202014-09-24 15:21:44 -04005499func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005500 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005501 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005502 // SSL 3.0 does not have tickets and TLS 1.3 does not
5503 // have session IDs, so skip their cross-resumption
5504 // tests.
5505 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5506 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5507 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005508 }
5509
David Benjamin8b8c0062014-11-23 02:47:52 -05005510 protocols := []protocol{tls}
5511 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5512 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005513 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005514 for _, protocol := range protocols {
5515 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5516 if protocol == dtls {
5517 suffix += "-DTLS"
5518 }
5519
David Benjaminece3de92015-03-16 18:02:20 -04005520 if sessionVers.version == resumeVers.version {
5521 testCases = append(testCases, testCase{
5522 protocol: protocol,
5523 name: "Resume-Client" + suffix,
5524 resumeSession: true,
5525 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005526 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005527 Bugs: ProtocolBugs{
5528 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5529 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5530 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005531 },
David Benjaminece3de92015-03-16 18:02:20 -04005532 expectedVersion: sessionVers.version,
5533 expectedResumeVersion: resumeVers.version,
5534 })
5535 } else {
David Benjamin405da482016-08-08 17:25:07 -04005536 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5537
5538 // Offering a TLS 1.3 session sends an empty session ID, so
5539 // there is no way to convince a non-lookahead client the
5540 // session was resumed. It will appear to the client that a
5541 // stray ChangeCipherSpec was sent.
5542 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5543 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005544 }
5545
David Benjaminece3de92015-03-16 18:02:20 -04005546 testCases = append(testCases, testCase{
5547 protocol: protocol,
5548 name: "Resume-Client-Mismatch" + suffix,
5549 resumeSession: true,
5550 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005551 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005552 },
David Benjaminece3de92015-03-16 18:02:20 -04005553 expectedVersion: sessionVers.version,
5554 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005555 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005556 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005557 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005558 },
5559 },
5560 expectedResumeVersion: resumeVers.version,
5561 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005562 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005563 })
5564 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005565
5566 testCases = append(testCases, testCase{
5567 protocol: protocol,
5568 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005569 resumeSession: true,
5570 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005571 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005572 },
5573 expectedVersion: sessionVers.version,
5574 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005575 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005576 },
5577 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005578 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005579 expectedResumeVersion: resumeVers.version,
5580 })
5581
David Benjamin8b8c0062014-11-23 02:47:52 -05005582 testCases = append(testCases, testCase{
5583 protocol: protocol,
5584 testType: serverTest,
5585 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005586 resumeSession: true,
5587 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005588 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005589 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005590 expectedVersion: sessionVers.version,
5591 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005592 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005593 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005594 Bugs: ProtocolBugs{
5595 SendBothTickets: true,
5596 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005597 },
5598 expectedResumeVersion: resumeVers.version,
5599 })
5600 }
David Benjamin01fe8202014-09-24 15:21:44 -04005601 }
5602 }
David Benjaminece3de92015-03-16 18:02:20 -04005603
David Benjamin4199b0d2016-11-01 13:58:25 -04005604 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005605 testCases = append(testCases, testCase{
5606 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005607 name: "ShimTicketRewritable",
5608 resumeSession: true,
5609 config: Config{
5610 MaxVersion: VersionTLS12,
5611 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5612 Bugs: ProtocolBugs{
5613 FilterTicket: func(in []byte) ([]byte, error) {
5614 in, err := SetShimTicketVersion(in, VersionTLS12)
5615 if err != nil {
5616 return nil, err
5617 }
5618 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5619 },
5620 },
5621 },
5622 flags: []string{
5623 "-ticket-key",
5624 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5625 },
5626 })
5627
5628 // Resumptions are declined if the version does not match.
5629 testCases = append(testCases, testCase{
5630 testType: serverTest,
5631 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005632 resumeSession: true,
5633 config: Config{
5634 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005635 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005636 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005637 FilterTicket: func(in []byte) ([]byte, error) {
5638 return SetShimTicketVersion(in, VersionTLS13)
5639 },
5640 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005641 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005642 flags: []string{
5643 "-ticket-key",
5644 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5645 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005646 expectResumeRejected: true,
5647 })
5648
5649 testCases = append(testCases, testCase{
5650 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005651 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005652 resumeSession: true,
5653 config: Config{
5654 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005655 Bugs: ProtocolBugs{
5656 FilterTicket: func(in []byte) ([]byte, error) {
5657 return SetShimTicketVersion(in, VersionTLS12)
5658 },
5659 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005660 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005661 flags: []string{
5662 "-ticket-key",
5663 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5664 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005665 expectResumeRejected: true,
5666 })
5667
David Benjamin4199b0d2016-11-01 13:58:25 -04005668 // Resumptions are declined if the cipher is invalid or disabled.
5669 testCases = append(testCases, testCase{
5670 testType: serverTest,
5671 name: "Resume-Server-DeclineBadCipher",
5672 resumeSession: true,
5673 config: Config{
5674 MaxVersion: VersionTLS12,
5675 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005676 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005677 FilterTicket: func(in []byte) ([]byte, error) {
5678 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5679 },
5680 },
5681 },
5682 flags: []string{
5683 "-ticket-key",
5684 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5685 },
5686 expectResumeRejected: true,
5687 })
5688
5689 testCases = append(testCases, testCase{
5690 testType: serverTest,
5691 name: "Resume-Server-DeclineBadCipher-2",
5692 resumeSession: true,
5693 config: Config{
5694 MaxVersion: VersionTLS12,
5695 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005696 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005697 FilterTicket: func(in []byte) ([]byte, error) {
5698 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5699 },
5700 },
5701 },
5702 flags: []string{
5703 "-cipher", "AES128",
5704 "-ticket-key",
5705 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5706 },
5707 expectResumeRejected: true,
5708 })
5709
David Benjaminf01f42a2016-11-16 19:05:33 +09005710 // Sessions are not resumed if they do not use the preferred cipher.
5711 testCases = append(testCases, testCase{
5712 testType: serverTest,
5713 name: "Resume-Server-CipherNotPreferred",
5714 resumeSession: true,
5715 config: Config{
5716 MaxVersion: VersionTLS12,
5717 Bugs: ProtocolBugs{
5718 ExpectNewTicket: true,
5719 FilterTicket: func(in []byte) ([]byte, error) {
5720 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5721 },
5722 },
5723 },
5724 flags: []string{
5725 "-ticket-key",
5726 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5727 },
5728 shouldFail: false,
5729 expectResumeRejected: true,
5730 })
5731
5732 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5733 // PRF hashes match, but BoringSSL will always decline such resumptions.
5734 testCases = append(testCases, testCase{
5735 testType: serverTest,
5736 name: "Resume-Server-CipherNotPreferred-TLS13",
5737 resumeSession: true,
5738 config: Config{
5739 MaxVersion: VersionTLS13,
5740 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5741 Bugs: ProtocolBugs{
5742 FilterTicket: func(in []byte) ([]byte, error) {
5743 // If the client (runner) offers ChaCha20-Poly1305 first, the
5744 // server (shim) always prefers it. Switch it to AES-GCM.
5745 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5746 },
5747 },
5748 },
5749 flags: []string{
5750 "-ticket-key",
5751 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5752 },
5753 shouldFail: false,
5754 expectResumeRejected: true,
5755 })
5756
5757 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005758 testCases = append(testCases, testCase{
5759 testType: serverTest,
5760 name: "Resume-Server-DeclineBadCipher-TLS13",
5761 resumeSession: true,
5762 config: Config{
5763 MaxVersion: VersionTLS13,
5764 Bugs: ProtocolBugs{
5765 FilterTicket: func(in []byte) ([]byte, error) {
5766 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5767 },
5768 },
5769 },
5770 flags: []string{
5771 "-ticket-key",
5772 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5773 },
5774 expectResumeRejected: true,
5775 })
5776
David Benjaminf01f42a2016-11-16 19:05:33 +09005777 // If the client does not offer the cipher from the session, decline to
5778 // resume. Clients are forbidden from doing this, but BoringSSL selects
5779 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005780 testCases = append(testCases, testCase{
5781 testType: serverTest,
5782 name: "Resume-Server-UnofferedCipher",
5783 resumeSession: true,
5784 config: Config{
5785 MaxVersion: VersionTLS12,
5786 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5787 },
5788 resumeConfig: &Config{
5789 MaxVersion: VersionTLS12,
5790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5791 Bugs: ProtocolBugs{
5792 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5793 },
5794 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005795 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005796 })
5797
David Benjaminf01f42a2016-11-16 19:05:33 +09005798 // In TLS 1.3, clients may advertise a cipher list which does not
5799 // include the selected cipher. Test that we tolerate this. Servers may
5800 // resume at another cipher if the PRF matches, but BoringSSL will
5801 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005802 testCases = append(testCases, testCase{
5803 testType: serverTest,
5804 name: "Resume-Server-UnofferedCipher-TLS13",
5805 resumeSession: true,
5806 config: Config{
5807 MaxVersion: VersionTLS13,
5808 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5809 },
5810 resumeConfig: &Config{
5811 MaxVersion: VersionTLS13,
5812 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5813 Bugs: ProtocolBugs{
5814 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5815 },
5816 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005817 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005818 })
5819
David Benjamin4199b0d2016-11-01 13:58:25 -04005820 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005821 testCases = append(testCases, testCase{
5822 name: "Resume-Client-CipherMismatch",
5823 resumeSession: true,
5824 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005825 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005826 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5827 },
5828 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005829 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005830 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5831 Bugs: ProtocolBugs{
5832 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5833 },
5834 },
5835 shouldFail: true,
5836 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5837 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005838
David Benjamine1cc35e2016-11-16 16:25:58 +09005839 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5840 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005841 testCases = append(testCases, testCase{
5842 name: "Resume-Client-CipherMismatch-TLS13",
5843 resumeSession: true,
5844 config: Config{
5845 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005846 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005847 },
5848 resumeConfig: &Config{
5849 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005850 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5851 },
5852 })
5853
5854 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5855 testCases = append(testCases, testCase{
5856 name: "Resume-Client-PRFMismatch-TLS13",
5857 resumeSession: true,
5858 config: Config{
5859 MaxVersion: VersionTLS13,
5860 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5861 },
5862 resumeConfig: &Config{
5863 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005864 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005865 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005866 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005867 },
5868 },
5869 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005870 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005871 })
Steven Valdeza833c352016-11-01 13:39:36 -04005872
5873 testCases = append(testCases, testCase{
5874 testType: serverTest,
5875 name: "Resume-Server-BinderWrongLength",
5876 resumeSession: true,
5877 config: Config{
5878 MaxVersion: VersionTLS13,
5879 Bugs: ProtocolBugs{
5880 SendShortPSKBinder: true,
5881 },
5882 },
5883 shouldFail: true,
5884 expectedLocalError: "remote error: error decrypting message",
5885 expectedError: ":DIGEST_CHECK_FAILED:",
5886 })
5887
5888 testCases = append(testCases, testCase{
5889 testType: serverTest,
5890 name: "Resume-Server-NoPSKBinder",
5891 resumeSession: true,
5892 config: Config{
5893 MaxVersion: VersionTLS13,
5894 Bugs: ProtocolBugs{
5895 SendNoPSKBinder: true,
5896 },
5897 },
5898 shouldFail: true,
5899 expectedLocalError: "remote error: error decoding message",
5900 expectedError: ":DECODE_ERROR:",
5901 })
5902
5903 testCases = append(testCases, testCase{
5904 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005905 name: "Resume-Server-ExtraPSKBinder",
5906 resumeSession: true,
5907 config: Config{
5908 MaxVersion: VersionTLS13,
5909 Bugs: ProtocolBugs{
5910 SendExtraPSKBinder: true,
5911 },
5912 },
5913 shouldFail: true,
5914 expectedLocalError: "remote error: illegal parameter",
5915 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5916 })
5917
5918 testCases = append(testCases, testCase{
5919 testType: serverTest,
5920 name: "Resume-Server-ExtraIdentityNoBinder",
5921 resumeSession: true,
5922 config: Config{
5923 MaxVersion: VersionTLS13,
5924 Bugs: ProtocolBugs{
5925 ExtraPSKIdentity: true,
5926 },
5927 },
5928 shouldFail: true,
5929 expectedLocalError: "remote error: illegal parameter",
5930 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5931 })
5932
5933 testCases = append(testCases, testCase{
5934 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04005935 name: "Resume-Server-InvalidPSKBinder",
5936 resumeSession: true,
5937 config: Config{
5938 MaxVersion: VersionTLS13,
5939 Bugs: ProtocolBugs{
5940 SendInvalidPSKBinder: true,
5941 },
5942 },
5943 shouldFail: true,
5944 expectedLocalError: "remote error: error decrypting message",
5945 expectedError: ":DIGEST_CHECK_FAILED:",
5946 })
5947
5948 testCases = append(testCases, testCase{
5949 testType: serverTest,
5950 name: "Resume-Server-PSKBinderFirstExtension",
5951 resumeSession: true,
5952 config: Config{
5953 MaxVersion: VersionTLS13,
5954 Bugs: ProtocolBugs{
5955 PSKBinderFirst: true,
5956 },
5957 },
5958 shouldFail: true,
5959 expectedLocalError: "remote error: illegal parameter",
5960 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
5961 })
David Benjamin01fe8202014-09-24 15:21:44 -04005962}
5963
Adam Langley2ae77d22014-10-28 17:29:33 -07005964func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005965 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005966 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005967 testType: serverTest,
5968 name: "Renegotiate-Server-Forbidden",
5969 config: Config{
5970 MaxVersion: VersionTLS12,
5971 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005972 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005973 shouldFail: true,
5974 expectedError: ":NO_RENEGOTIATION:",
5975 expectedLocalError: "remote error: no renegotiation",
5976 })
Adam Langley5021b222015-06-12 18:27:58 -07005977 // The server shouldn't echo the renegotiation extension unless
5978 // requested by the client.
5979 testCases = append(testCases, testCase{
5980 testType: serverTest,
5981 name: "Renegotiate-Server-NoExt",
5982 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005983 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005984 Bugs: ProtocolBugs{
5985 NoRenegotiationInfo: true,
5986 RequireRenegotiationInfo: true,
5987 },
5988 },
5989 shouldFail: true,
5990 expectedLocalError: "renegotiation extension missing",
5991 })
5992 // The renegotiation SCSV should be sufficient for the server to echo
5993 // the extension.
5994 testCases = append(testCases, testCase{
5995 testType: serverTest,
5996 name: "Renegotiate-Server-NoExt-SCSV",
5997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005998 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005999 Bugs: ProtocolBugs{
6000 NoRenegotiationInfo: true,
6001 SendRenegotiationSCSV: true,
6002 RequireRenegotiationInfo: true,
6003 },
6004 },
6005 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006006 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006007 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006008 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006009 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006010 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006011 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006012 },
6013 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006014 renegotiate: 1,
6015 flags: []string{
6016 "-renegotiate-freely",
6017 "-expect-total-renegotiations", "1",
6018 },
David Benjamincdea40c2015-03-19 14:09:43 -04006019 })
6020 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006021 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006022 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006023 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006024 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006025 Bugs: ProtocolBugs{
6026 EmptyRenegotiationInfo: true,
6027 },
6028 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006029 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006030 shouldFail: true,
6031 expectedError: ":RENEGOTIATION_MISMATCH:",
6032 })
6033 testCases = append(testCases, testCase{
6034 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006035 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006036 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006037 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006038 Bugs: ProtocolBugs{
6039 BadRenegotiationInfo: true,
6040 },
6041 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006042 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006043 shouldFail: true,
6044 expectedError: ":RENEGOTIATION_MISMATCH:",
6045 })
6046 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006047 name: "Renegotiate-Client-Downgrade",
6048 renegotiate: 1,
6049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006050 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006051 Bugs: ProtocolBugs{
6052 NoRenegotiationInfoAfterInitial: true,
6053 },
6054 },
6055 flags: []string{"-renegotiate-freely"},
6056 shouldFail: true,
6057 expectedError: ":RENEGOTIATION_MISMATCH:",
6058 })
6059 testCases = append(testCases, testCase{
6060 name: "Renegotiate-Client-Upgrade",
6061 renegotiate: 1,
6062 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006063 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006064 Bugs: ProtocolBugs{
6065 NoRenegotiationInfoInInitial: true,
6066 },
6067 },
6068 flags: []string{"-renegotiate-freely"},
6069 shouldFail: true,
6070 expectedError: ":RENEGOTIATION_MISMATCH:",
6071 })
6072 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006073 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006074 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006075 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006076 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006077 Bugs: ProtocolBugs{
6078 NoRenegotiationInfo: true,
6079 },
6080 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006081 flags: []string{
6082 "-renegotiate-freely",
6083 "-expect-total-renegotiations", "1",
6084 },
David Benjamincff0b902015-05-15 23:09:47 -04006085 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006086
6087 // Test that the server may switch ciphers on renegotiation without
6088 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006089 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006090 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006091 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006092 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006093 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006094 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006095 },
6096 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006097 flags: []string{
6098 "-renegotiate-freely",
6099 "-expect-total-renegotiations", "1",
6100 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006101 })
6102 testCases = append(testCases, testCase{
6103 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006104 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006105 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006106 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006107 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6108 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006109 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006110 flags: []string{
6111 "-renegotiate-freely",
6112 "-expect-total-renegotiations", "1",
6113 },
David Benjaminb16346b2015-04-08 19:16:58 -04006114 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006115
6116 // Test that the server may not switch versions on renegotiation.
6117 testCases = append(testCases, testCase{
6118 name: "Renegotiate-Client-SwitchVersion",
6119 config: Config{
6120 MaxVersion: VersionTLS12,
6121 // Pick a cipher which exists at both versions.
6122 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6123 Bugs: ProtocolBugs{
6124 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006125 // Avoid failing early at the record layer.
6126 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006127 },
6128 },
6129 renegotiate: 1,
6130 flags: []string{
6131 "-renegotiate-freely",
6132 "-expect-total-renegotiations", "1",
6133 },
6134 shouldFail: true,
6135 expectedError: ":WRONG_SSL_VERSION:",
6136 })
6137
David Benjaminb16346b2015-04-08 19:16:58 -04006138 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006139 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006140 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006141 config: Config{
6142 MaxVersion: VersionTLS10,
6143 Bugs: ProtocolBugs{
6144 RequireSameRenegoClientVersion: true,
6145 },
6146 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006147 flags: []string{
6148 "-renegotiate-freely",
6149 "-expect-total-renegotiations", "1",
6150 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006151 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006152 testCases = append(testCases, testCase{
6153 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006154 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006155 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006156 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006157 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6158 NextProtos: []string{"foo"},
6159 },
6160 flags: []string{
6161 "-false-start",
6162 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006163 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006164 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006165 },
6166 shimWritesFirst: true,
6167 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006168
6169 // Client-side renegotiation controls.
6170 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006171 name: "Renegotiate-Client-Forbidden-1",
6172 config: Config{
6173 MaxVersion: VersionTLS12,
6174 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006175 renegotiate: 1,
6176 shouldFail: true,
6177 expectedError: ":NO_RENEGOTIATION:",
6178 expectedLocalError: "remote error: no renegotiation",
6179 })
6180 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006181 name: "Renegotiate-Client-Once-1",
6182 config: Config{
6183 MaxVersion: VersionTLS12,
6184 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006185 renegotiate: 1,
6186 flags: []string{
6187 "-renegotiate-once",
6188 "-expect-total-renegotiations", "1",
6189 },
6190 })
6191 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006192 name: "Renegotiate-Client-Freely-1",
6193 config: Config{
6194 MaxVersion: VersionTLS12,
6195 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006196 renegotiate: 1,
6197 flags: []string{
6198 "-renegotiate-freely",
6199 "-expect-total-renegotiations", "1",
6200 },
6201 })
6202 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006203 name: "Renegotiate-Client-Once-2",
6204 config: Config{
6205 MaxVersion: VersionTLS12,
6206 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006207 renegotiate: 2,
6208 flags: []string{"-renegotiate-once"},
6209 shouldFail: true,
6210 expectedError: ":NO_RENEGOTIATION:",
6211 expectedLocalError: "remote error: no renegotiation",
6212 })
6213 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006214 name: "Renegotiate-Client-Freely-2",
6215 config: Config{
6216 MaxVersion: VersionTLS12,
6217 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006218 renegotiate: 2,
6219 flags: []string{
6220 "-renegotiate-freely",
6221 "-expect-total-renegotiations", "2",
6222 },
6223 })
Adam Langley27a0d082015-11-03 13:34:10 -08006224 testCases = append(testCases, testCase{
6225 name: "Renegotiate-Client-NoIgnore",
6226 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006227 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006228 Bugs: ProtocolBugs{
6229 SendHelloRequestBeforeEveryAppDataRecord: true,
6230 },
6231 },
6232 shouldFail: true,
6233 expectedError: ":NO_RENEGOTIATION:",
6234 })
6235 testCases = append(testCases, testCase{
6236 name: "Renegotiate-Client-Ignore",
6237 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006238 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006239 Bugs: ProtocolBugs{
6240 SendHelloRequestBeforeEveryAppDataRecord: true,
6241 },
6242 },
6243 flags: []string{
6244 "-renegotiate-ignore",
6245 "-expect-total-renegotiations", "0",
6246 },
6247 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006248
David Benjamin34941c02016-10-08 11:45:31 -04006249 // Renegotiation is not allowed at SSL 3.0.
6250 testCases = append(testCases, testCase{
6251 name: "Renegotiate-Client-SSL3",
6252 config: Config{
6253 MaxVersion: VersionSSL30,
6254 },
6255 renegotiate: 1,
6256 flags: []string{
6257 "-renegotiate-freely",
6258 "-expect-total-renegotiations", "1",
6259 },
6260 shouldFail: true,
6261 expectedError: ":NO_RENEGOTIATION:",
6262 expectedLocalError: "remote error: no renegotiation",
6263 })
6264
David Benjamina1eaba12017-01-01 23:19:22 -05006265 // Renegotiation is not allowed when there is an unfinished write.
6266 testCases = append(testCases, testCase{
6267 name: "Renegotiate-Client-UnfinishedWrite",
6268 config: Config{
6269 MaxVersion: VersionTLS12,
6270 },
6271 renegotiate: 1,
6272 flags: []string{
6273 "-async",
6274 "-renegotiate-freely",
6275 "-read-with-unfinished-write",
6276 },
6277 shouldFail: true,
6278 expectedError: ":NO_RENEGOTIATION:",
6279 // We do not successfully send the no_renegotiation alert in
6280 // this case. https://crbug.com/boringssl/130
6281 })
6282
David Benjamin397c8e62016-07-08 14:14:36 -07006283 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006284 testCases = append(testCases, testCase{
6285 name: "StrayHelloRequest",
6286 config: Config{
6287 MaxVersion: VersionTLS12,
6288 Bugs: ProtocolBugs{
6289 SendHelloRequestBeforeEveryHandshakeMessage: true,
6290 },
6291 },
6292 })
6293 testCases = append(testCases, testCase{
6294 name: "StrayHelloRequest-Packed",
6295 config: Config{
6296 MaxVersion: VersionTLS12,
6297 Bugs: ProtocolBugs{
6298 PackHandshakeFlight: true,
6299 SendHelloRequestBeforeEveryHandshakeMessage: true,
6300 },
6301 },
6302 })
6303
David Benjamin12d2c482016-07-24 10:56:51 -04006304 // Test renegotiation works if HelloRequest and server Finished come in
6305 // the same record.
6306 testCases = append(testCases, testCase{
6307 name: "Renegotiate-Client-Packed",
6308 config: Config{
6309 MaxVersion: VersionTLS12,
6310 Bugs: ProtocolBugs{
6311 PackHandshakeFlight: true,
6312 PackHelloRequestWithFinished: true,
6313 },
6314 },
6315 renegotiate: 1,
6316 flags: []string{
6317 "-renegotiate-freely",
6318 "-expect-total-renegotiations", "1",
6319 },
6320 })
6321
David Benjamin397c8e62016-07-08 14:14:36 -07006322 // Renegotiation is forbidden in TLS 1.3.
6323 testCases = append(testCases, testCase{
6324 name: "Renegotiate-Client-TLS13",
6325 config: Config{
6326 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006327 Bugs: ProtocolBugs{
6328 SendHelloRequestBeforeEveryAppDataRecord: true,
6329 },
David Benjamin397c8e62016-07-08 14:14:36 -07006330 },
David Benjamin397c8e62016-07-08 14:14:36 -07006331 flags: []string{
6332 "-renegotiate-freely",
6333 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006334 shouldFail: true,
6335 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006336 })
6337
6338 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6339 testCases = append(testCases, testCase{
6340 name: "StrayHelloRequest-TLS13",
6341 config: Config{
6342 MaxVersion: VersionTLS13,
6343 Bugs: ProtocolBugs{
6344 SendHelloRequestBeforeEveryHandshakeMessage: true,
6345 },
6346 },
6347 shouldFail: true,
6348 expectedError: ":UNEXPECTED_MESSAGE:",
6349 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006350}
6351
David Benjamin5e961c12014-11-07 01:48:35 -05006352func addDTLSReplayTests() {
6353 // Test that sequence number replays are detected.
6354 testCases = append(testCases, testCase{
6355 protocol: dtls,
6356 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006357 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006358 replayWrites: true,
6359 })
6360
David Benjamin8e6db492015-07-25 18:29:23 -04006361 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006362 // than the retransmit window.
6363 testCases = append(testCases, testCase{
6364 protocol: dtls,
6365 name: "DTLS-Replay-LargeGaps",
6366 config: Config{
6367 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006368 SequenceNumberMapping: func(in uint64) uint64 {
6369 return in * 127
6370 },
David Benjamin5e961c12014-11-07 01:48:35 -05006371 },
6372 },
David Benjamin8e6db492015-07-25 18:29:23 -04006373 messageCount: 200,
6374 replayWrites: true,
6375 })
6376
6377 // Test the incoming sequence number changing non-monotonically.
6378 testCases = append(testCases, testCase{
6379 protocol: dtls,
6380 name: "DTLS-Replay-NonMonotonic",
6381 config: Config{
6382 Bugs: ProtocolBugs{
6383 SequenceNumberMapping: func(in uint64) uint64 {
6384 return in ^ 31
6385 },
6386 },
6387 },
6388 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006389 replayWrites: true,
6390 })
6391}
6392
Nick Harper60edffd2016-06-21 15:19:24 -07006393var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006394 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006395 id signatureAlgorithm
6396 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006397}{
Nick Harper60edffd2016-06-21 15:19:24 -07006398 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6399 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6400 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6401 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006402 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006403 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6404 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6405 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006406 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6407 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6408 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006409 // Tests for key types prior to TLS 1.2.
6410 {"RSA", 0, testCertRSA},
6411 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006412}
6413
Nick Harper60edffd2016-06-21 15:19:24 -07006414const fakeSigAlg1 signatureAlgorithm = 0x2a01
6415const fakeSigAlg2 signatureAlgorithm = 0xff01
6416
6417func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006418 // Not all ciphers involve a signature. Advertise a list which gives all
6419 // versions a signing cipher.
6420 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006421 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006422 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6423 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6424 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6425 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6426 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6427 }
6428
David Benjaminca3d5452016-07-14 12:51:01 -04006429 var allAlgorithms []signatureAlgorithm
6430 for _, alg := range testSignatureAlgorithms {
6431 if alg.id != 0 {
6432 allAlgorithms = append(allAlgorithms, alg.id)
6433 }
6434 }
6435
Nick Harper60edffd2016-06-21 15:19:24 -07006436 // Make sure each signature algorithm works. Include some fake values in
6437 // the list and ensure they're ignored.
6438 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006439 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006440 if (ver.version < VersionTLS12) != (alg.id == 0) {
6441 continue
6442 }
6443
6444 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6445 // or remove it in C.
6446 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006447 continue
6448 }
Nick Harper60edffd2016-06-21 15:19:24 -07006449
David Benjamin3ef76972016-10-17 17:59:54 -04006450 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006451 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006452 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006453 shouldSignFail = true
6454 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006455 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006456 // RSA-PKCS1 does not exist in TLS 1.3.
6457 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006458 shouldSignFail = true
6459 shouldVerifyFail = true
6460 }
6461
6462 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6463 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6464 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006465 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006466
6467 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006468 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006469 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006470 }
6471 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006472 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006473 }
David Benjamin000800a2014-11-14 01:43:59 -05006474
David Benjamin1fb125c2016-07-08 18:52:12 -07006475 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006476
David Benjamin7a41d372016-07-09 11:21:54 -07006477 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006478 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006479 config: Config{
6480 MaxVersion: ver.version,
6481 ClientAuth: RequireAnyClientCert,
6482 VerifySignatureAlgorithms: []signatureAlgorithm{
6483 fakeSigAlg1,
6484 alg.id,
6485 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006486 },
David Benjamin7a41d372016-07-09 11:21:54 -07006487 },
6488 flags: []string{
6489 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6490 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6491 "-enable-all-curves",
6492 },
David Benjamin3ef76972016-10-17 17:59:54 -04006493 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006494 expectedError: signError,
6495 expectedPeerSignatureAlgorithm: alg.id,
6496 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006497
David Benjamin7a41d372016-07-09 11:21:54 -07006498 testCases = append(testCases, testCase{
6499 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006500 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006501 config: Config{
6502 MaxVersion: ver.version,
6503 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6504 SignSignatureAlgorithms: []signatureAlgorithm{
6505 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006506 },
David Benjamin7a41d372016-07-09 11:21:54 -07006507 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006508 SkipECDSACurveCheck: shouldVerifyFail,
6509 IgnoreSignatureVersionChecks: shouldVerifyFail,
6510 // Some signature algorithms may not be advertised.
6511 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006512 },
David Benjamin7a41d372016-07-09 11:21:54 -07006513 },
6514 flags: []string{
6515 "-require-any-client-certificate",
6516 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6517 "-enable-all-curves",
6518 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006519 // Resume the session to assert the peer signature
6520 // algorithm is reported on both handshakes.
6521 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006522 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006523 expectedError: verifyError,
6524 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006525
6526 testCases = append(testCases, testCase{
6527 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006528 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006529 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006530 MaxVersion: ver.version,
6531 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006532 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006533 fakeSigAlg1,
6534 alg.id,
6535 fakeSigAlg2,
6536 },
6537 },
6538 flags: []string{
6539 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6540 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6541 "-enable-all-curves",
6542 },
David Benjamin3ef76972016-10-17 17:59:54 -04006543 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006544 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006545 expectedPeerSignatureAlgorithm: alg.id,
6546 })
6547
6548 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006549 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006550 config: Config{
6551 MaxVersion: ver.version,
6552 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006553 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006554 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006555 alg.id,
6556 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006557 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006558 SkipECDSACurveCheck: shouldVerifyFail,
6559 IgnoreSignatureVersionChecks: shouldVerifyFail,
6560 // Some signature algorithms may not be advertised.
6561 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006562 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006563 },
6564 flags: []string{
6565 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6566 "-enable-all-curves",
6567 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006568 // Resume the session to assert the peer signature
6569 // algorithm is reported on both handshakes.
6570 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006571 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006572 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006573 })
David Benjamin5208fd42016-07-13 21:43:25 -04006574
David Benjamin3ef76972016-10-17 17:59:54 -04006575 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006576 testCases = append(testCases, testCase{
6577 testType: serverTest,
6578 name: "ClientAuth-InvalidSignature" + suffix,
6579 config: Config{
6580 MaxVersion: ver.version,
6581 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6582 SignSignatureAlgorithms: []signatureAlgorithm{
6583 alg.id,
6584 },
6585 Bugs: ProtocolBugs{
6586 InvalidSignature: true,
6587 },
6588 },
6589 flags: []string{
6590 "-require-any-client-certificate",
6591 "-enable-all-curves",
6592 },
6593 shouldFail: true,
6594 expectedError: ":BAD_SIGNATURE:",
6595 })
6596
6597 testCases = append(testCases, testCase{
6598 name: "ServerAuth-InvalidSignature" + suffix,
6599 config: Config{
6600 MaxVersion: ver.version,
6601 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6602 CipherSuites: signingCiphers,
6603 SignSignatureAlgorithms: []signatureAlgorithm{
6604 alg.id,
6605 },
6606 Bugs: ProtocolBugs{
6607 InvalidSignature: true,
6608 },
6609 },
6610 flags: []string{"-enable-all-curves"},
6611 shouldFail: true,
6612 expectedError: ":BAD_SIGNATURE:",
6613 })
6614 }
David Benjaminca3d5452016-07-14 12:51:01 -04006615
David Benjamin3ef76972016-10-17 17:59:54 -04006616 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006617 testCases = append(testCases, testCase{
6618 name: "ClientAuth-Sign-Negotiate" + suffix,
6619 config: Config{
6620 MaxVersion: ver.version,
6621 ClientAuth: RequireAnyClientCert,
6622 VerifySignatureAlgorithms: allAlgorithms,
6623 },
6624 flags: []string{
6625 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6626 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6627 "-enable-all-curves",
6628 "-signing-prefs", strconv.Itoa(int(alg.id)),
6629 },
6630 expectedPeerSignatureAlgorithm: alg.id,
6631 })
6632
6633 testCases = append(testCases, testCase{
6634 testType: serverTest,
6635 name: "ServerAuth-Sign-Negotiate" + suffix,
6636 config: Config{
6637 MaxVersion: ver.version,
6638 CipherSuites: signingCiphers,
6639 VerifySignatureAlgorithms: allAlgorithms,
6640 },
6641 flags: []string{
6642 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6643 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6644 "-enable-all-curves",
6645 "-signing-prefs", strconv.Itoa(int(alg.id)),
6646 },
6647 expectedPeerSignatureAlgorithm: alg.id,
6648 })
6649 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006650 }
David Benjamin000800a2014-11-14 01:43:59 -05006651 }
6652
Nick Harper60edffd2016-06-21 15:19:24 -07006653 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006654 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006655 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006656 config: Config{
6657 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006658 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006659 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006660 signatureECDSAWithP521AndSHA512,
6661 signatureRSAPKCS1WithSHA384,
6662 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006663 },
6664 },
6665 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006666 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6667 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006668 },
Nick Harper60edffd2016-06-21 15:19:24 -07006669 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006670 })
6671
6672 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006673 name: "ClientAuth-SignatureType-TLS13",
6674 config: Config{
6675 ClientAuth: RequireAnyClientCert,
6676 MaxVersion: VersionTLS13,
6677 VerifySignatureAlgorithms: []signatureAlgorithm{
6678 signatureECDSAWithP521AndSHA512,
6679 signatureRSAPKCS1WithSHA384,
6680 signatureRSAPSSWithSHA384,
6681 signatureECDSAWithSHA1,
6682 },
6683 },
6684 flags: []string{
6685 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6686 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6687 },
6688 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6689 })
6690
6691 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006692 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006693 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006694 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006695 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006696 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006697 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006698 signatureECDSAWithP521AndSHA512,
6699 signatureRSAPKCS1WithSHA384,
6700 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006701 },
6702 },
Nick Harper60edffd2016-06-21 15:19:24 -07006703 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006704 })
6705
Steven Valdez143e8b32016-07-11 13:19:03 -04006706 testCases = append(testCases, testCase{
6707 testType: serverTest,
6708 name: "ServerAuth-SignatureType-TLS13",
6709 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006710 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006711 VerifySignatureAlgorithms: []signatureAlgorithm{
6712 signatureECDSAWithP521AndSHA512,
6713 signatureRSAPKCS1WithSHA384,
6714 signatureRSAPSSWithSHA384,
6715 signatureECDSAWithSHA1,
6716 },
6717 },
6718 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6719 })
6720
David Benjamina95e9f32016-07-08 16:28:04 -07006721 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006722 testCases = append(testCases, testCase{
6723 testType: serverTest,
6724 name: "Verify-ClientAuth-SignatureType",
6725 config: Config{
6726 MaxVersion: VersionTLS12,
6727 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006728 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006729 signatureRSAPKCS1WithSHA256,
6730 },
6731 Bugs: ProtocolBugs{
6732 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6733 },
6734 },
6735 flags: []string{
6736 "-require-any-client-certificate",
6737 },
6738 shouldFail: true,
6739 expectedError: ":WRONG_SIGNATURE_TYPE:",
6740 })
6741
6742 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006743 testType: serverTest,
6744 name: "Verify-ClientAuth-SignatureType-TLS13",
6745 config: Config{
6746 MaxVersion: VersionTLS13,
6747 Certificates: []Certificate{rsaCertificate},
6748 SignSignatureAlgorithms: []signatureAlgorithm{
6749 signatureRSAPSSWithSHA256,
6750 },
6751 Bugs: ProtocolBugs{
6752 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6753 },
6754 },
6755 flags: []string{
6756 "-require-any-client-certificate",
6757 },
6758 shouldFail: true,
6759 expectedError: ":WRONG_SIGNATURE_TYPE:",
6760 })
6761
6762 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006763 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006764 config: Config{
6765 MaxVersion: VersionTLS12,
6766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006767 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006768 signatureRSAPKCS1WithSHA256,
6769 },
6770 Bugs: ProtocolBugs{
6771 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6772 },
6773 },
6774 shouldFail: true,
6775 expectedError: ":WRONG_SIGNATURE_TYPE:",
6776 })
6777
Steven Valdez143e8b32016-07-11 13:19:03 -04006778 testCases = append(testCases, testCase{
6779 name: "Verify-ServerAuth-SignatureType-TLS13",
6780 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006781 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006782 SignSignatureAlgorithms: []signatureAlgorithm{
6783 signatureRSAPSSWithSHA256,
6784 },
6785 Bugs: ProtocolBugs{
6786 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6787 },
6788 },
6789 shouldFail: true,
6790 expectedError: ":WRONG_SIGNATURE_TYPE:",
6791 })
6792
David Benjamin51dd7d62016-07-08 16:07:01 -07006793 // Test that, if the list is missing, the peer falls back to SHA-1 in
6794 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006795 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006796 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006797 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006798 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006799 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006800 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006801 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006802 },
6803 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006804 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006805 },
6806 },
6807 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006808 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6809 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006810 },
6811 })
6812
6813 testCases = append(testCases, testCase{
6814 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006815 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006816 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006817 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006818 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006819 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006820 },
6821 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006822 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006823 },
6824 },
David Benjaminee32bea2016-08-17 13:36:44 -04006825 flags: []string{
6826 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6827 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6828 },
6829 })
6830
6831 testCases = append(testCases, testCase{
6832 name: "ClientAuth-SHA1-Fallback-ECDSA",
6833 config: Config{
6834 MaxVersion: VersionTLS12,
6835 ClientAuth: RequireAnyClientCert,
6836 VerifySignatureAlgorithms: []signatureAlgorithm{
6837 signatureECDSAWithSHA1,
6838 },
6839 Bugs: ProtocolBugs{
6840 NoSignatureAlgorithms: true,
6841 },
6842 },
6843 flags: []string{
6844 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6845 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6846 },
6847 })
6848
6849 testCases = append(testCases, testCase{
6850 testType: serverTest,
6851 name: "ServerAuth-SHA1-Fallback-ECDSA",
6852 config: Config{
6853 MaxVersion: VersionTLS12,
6854 VerifySignatureAlgorithms: []signatureAlgorithm{
6855 signatureECDSAWithSHA1,
6856 },
6857 Bugs: ProtocolBugs{
6858 NoSignatureAlgorithms: true,
6859 },
6860 },
6861 flags: []string{
6862 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6863 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6864 },
David Benjamin000800a2014-11-14 01:43:59 -05006865 })
David Benjamin72dc7832015-03-16 17:49:43 -04006866
David Benjamin51dd7d62016-07-08 16:07:01 -07006867 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006868 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006869 config: Config{
6870 MaxVersion: VersionTLS13,
6871 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006872 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006873 signatureRSAPKCS1WithSHA1,
6874 },
6875 Bugs: ProtocolBugs{
6876 NoSignatureAlgorithms: true,
6877 },
6878 },
6879 flags: []string{
6880 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6881 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6882 },
David Benjamin48901652016-08-01 12:12:47 -04006883 shouldFail: true,
6884 // An empty CertificateRequest signature algorithm list is a
6885 // syntax error in TLS 1.3.
6886 expectedError: ":DECODE_ERROR:",
6887 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006888 })
6889
6890 testCases = append(testCases, testCase{
6891 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006892 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006893 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006894 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006895 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006896 signatureRSAPKCS1WithSHA1,
6897 },
6898 Bugs: ProtocolBugs{
6899 NoSignatureAlgorithms: true,
6900 },
6901 },
6902 shouldFail: true,
6903 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6904 })
6905
David Benjaminb62d2872016-07-18 14:55:02 +02006906 // Test that hash preferences are enforced. BoringSSL does not implement
6907 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006908 testCases = append(testCases, testCase{
6909 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006910 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006911 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006912 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006913 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006914 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006915 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006916 },
6917 Bugs: ProtocolBugs{
6918 IgnorePeerSignatureAlgorithmPreferences: true,
6919 },
6920 },
6921 flags: []string{"-require-any-client-certificate"},
6922 shouldFail: true,
6923 expectedError: ":WRONG_SIGNATURE_TYPE:",
6924 })
6925
6926 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006927 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006929 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006931 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006932 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006933 },
6934 Bugs: ProtocolBugs{
6935 IgnorePeerSignatureAlgorithmPreferences: true,
6936 },
6937 },
6938 shouldFail: true,
6939 expectedError: ":WRONG_SIGNATURE_TYPE:",
6940 })
David Benjaminb62d2872016-07-18 14:55:02 +02006941 testCases = append(testCases, testCase{
6942 testType: serverTest,
6943 name: "ClientAuth-Enforced-TLS13",
6944 config: Config{
6945 MaxVersion: VersionTLS13,
6946 Certificates: []Certificate{rsaCertificate},
6947 SignSignatureAlgorithms: []signatureAlgorithm{
6948 signatureRSAPKCS1WithMD5,
6949 },
6950 Bugs: ProtocolBugs{
6951 IgnorePeerSignatureAlgorithmPreferences: true,
6952 IgnoreSignatureVersionChecks: true,
6953 },
6954 },
6955 flags: []string{"-require-any-client-certificate"},
6956 shouldFail: true,
6957 expectedError: ":WRONG_SIGNATURE_TYPE:",
6958 })
6959
6960 testCases = append(testCases, testCase{
6961 name: "ServerAuth-Enforced-TLS13",
6962 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006963 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006964 SignSignatureAlgorithms: []signatureAlgorithm{
6965 signatureRSAPKCS1WithMD5,
6966 },
6967 Bugs: ProtocolBugs{
6968 IgnorePeerSignatureAlgorithmPreferences: true,
6969 IgnoreSignatureVersionChecks: true,
6970 },
6971 },
6972 shouldFail: true,
6973 expectedError: ":WRONG_SIGNATURE_TYPE:",
6974 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006975
6976 // Test that the agreed upon digest respects the client preferences and
6977 // the server digests.
6978 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006979 name: "NoCommonAlgorithms-Digests",
6980 config: Config{
6981 MaxVersion: VersionTLS12,
6982 ClientAuth: RequireAnyClientCert,
6983 VerifySignatureAlgorithms: []signatureAlgorithm{
6984 signatureRSAPKCS1WithSHA512,
6985 signatureRSAPKCS1WithSHA1,
6986 },
6987 },
6988 flags: []string{
6989 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6990 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6991 "-digest-prefs", "SHA256",
6992 },
6993 shouldFail: true,
6994 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6995 })
6996 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006997 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006998 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006999 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007000 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007001 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007002 signatureRSAPKCS1WithSHA512,
7003 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007004 },
7005 },
7006 flags: []string{
7007 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7008 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007009 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007010 },
David Benjaminca3d5452016-07-14 12:51:01 -04007011 shouldFail: true,
7012 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7013 })
7014 testCases = append(testCases, testCase{
7015 name: "NoCommonAlgorithms-TLS13",
7016 config: Config{
7017 MaxVersion: VersionTLS13,
7018 ClientAuth: RequireAnyClientCert,
7019 VerifySignatureAlgorithms: []signatureAlgorithm{
7020 signatureRSAPSSWithSHA512,
7021 signatureRSAPSSWithSHA384,
7022 },
7023 },
7024 flags: []string{
7025 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7026 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7027 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7028 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007029 shouldFail: true,
7030 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007031 })
7032 testCases = append(testCases, testCase{
7033 name: "Agree-Digest-SHA256",
7034 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007035 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007036 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007037 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007038 signatureRSAPKCS1WithSHA1,
7039 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007040 },
7041 },
7042 flags: []string{
7043 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7044 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007045 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007046 },
Nick Harper60edffd2016-06-21 15:19:24 -07007047 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007048 })
7049 testCases = append(testCases, testCase{
7050 name: "Agree-Digest-SHA1",
7051 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007052 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007053 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007054 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007055 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007056 },
7057 },
7058 flags: []string{
7059 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7060 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007061 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007062 },
Nick Harper60edffd2016-06-21 15:19:24 -07007063 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007064 })
7065 testCases = append(testCases, testCase{
7066 name: "Agree-Digest-Default",
7067 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007068 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007069 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007070 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007071 signatureRSAPKCS1WithSHA256,
7072 signatureECDSAWithP256AndSHA256,
7073 signatureRSAPKCS1WithSHA1,
7074 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007075 },
7076 },
7077 flags: []string{
7078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7080 },
Nick Harper60edffd2016-06-21 15:19:24 -07007081 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007082 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007083
David Benjaminca3d5452016-07-14 12:51:01 -04007084 // Test that the signing preference list may include extra algorithms
7085 // without negotiation problems.
7086 testCases = append(testCases, testCase{
7087 testType: serverTest,
7088 name: "FilterExtraAlgorithms",
7089 config: Config{
7090 MaxVersion: VersionTLS12,
7091 VerifySignatureAlgorithms: []signatureAlgorithm{
7092 signatureRSAPKCS1WithSHA256,
7093 },
7094 },
7095 flags: []string{
7096 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7097 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7098 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7099 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7100 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7101 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7102 },
7103 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7104 })
7105
David Benjamin4c3ddf72016-06-29 18:13:53 -04007106 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7107 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007108 testCases = append(testCases, testCase{
7109 name: "CheckLeafCurve",
7110 config: Config{
7111 MaxVersion: VersionTLS12,
7112 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007113 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007114 },
7115 flags: []string{"-p384-only"},
7116 shouldFail: true,
7117 expectedError: ":BAD_ECC_CERT:",
7118 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007119
7120 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7121 testCases = append(testCases, testCase{
7122 name: "CheckLeafCurve-TLS13",
7123 config: Config{
7124 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007125 Certificates: []Certificate{ecdsaP256Certificate},
7126 },
7127 flags: []string{"-p384-only"},
7128 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007129
7130 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7131 testCases = append(testCases, testCase{
7132 name: "ECDSACurveMismatch-Verify-TLS12",
7133 config: Config{
7134 MaxVersion: VersionTLS12,
7135 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7136 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007137 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007138 signatureECDSAWithP384AndSHA384,
7139 },
7140 },
7141 })
7142
7143 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7144 testCases = append(testCases, testCase{
7145 name: "ECDSACurveMismatch-Verify-TLS13",
7146 config: Config{
7147 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007148 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007149 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007150 signatureECDSAWithP384AndSHA384,
7151 },
7152 Bugs: ProtocolBugs{
7153 SkipECDSACurveCheck: true,
7154 },
7155 },
7156 shouldFail: true,
7157 expectedError: ":WRONG_SIGNATURE_TYPE:",
7158 })
7159
7160 // Signature algorithm selection in TLS 1.3 should take the curve into
7161 // account.
7162 testCases = append(testCases, testCase{
7163 testType: serverTest,
7164 name: "ECDSACurveMismatch-Sign-TLS13",
7165 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007166 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007167 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007168 signatureECDSAWithP384AndSHA384,
7169 signatureECDSAWithP256AndSHA256,
7170 },
7171 },
7172 flags: []string{
7173 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7174 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7175 },
7176 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7177 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007178
7179 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7180 // server does not attempt to sign in that case.
7181 testCases = append(testCases, testCase{
7182 testType: serverTest,
7183 name: "RSA-PSS-Large",
7184 config: Config{
7185 MaxVersion: VersionTLS13,
7186 VerifySignatureAlgorithms: []signatureAlgorithm{
7187 signatureRSAPSSWithSHA512,
7188 },
7189 },
7190 flags: []string{
7191 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7192 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7193 },
7194 shouldFail: true,
7195 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7196 })
David Benjamin57e929f2016-08-30 00:30:38 -04007197
7198 // Test that RSA-PSS is enabled by default for TLS 1.2.
7199 testCases = append(testCases, testCase{
7200 testType: clientTest,
7201 name: "RSA-PSS-Default-Verify",
7202 config: Config{
7203 MaxVersion: VersionTLS12,
7204 SignSignatureAlgorithms: []signatureAlgorithm{
7205 signatureRSAPSSWithSHA256,
7206 },
7207 },
7208 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7209 })
7210
7211 testCases = append(testCases, testCase{
7212 testType: serverTest,
7213 name: "RSA-PSS-Default-Sign",
7214 config: Config{
7215 MaxVersion: VersionTLS12,
7216 VerifySignatureAlgorithms: []signatureAlgorithm{
7217 signatureRSAPSSWithSHA256,
7218 },
7219 },
7220 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7221 })
David Benjamin000800a2014-11-14 01:43:59 -05007222}
7223
David Benjamin83f90402015-01-27 01:09:43 -05007224// timeouts is the retransmit schedule for BoringSSL. It doubles and
7225// caps at 60 seconds. On the 13th timeout, it gives up.
7226var timeouts = []time.Duration{
7227 1 * time.Second,
7228 2 * time.Second,
7229 4 * time.Second,
7230 8 * time.Second,
7231 16 * time.Second,
7232 32 * time.Second,
7233 60 * time.Second,
7234 60 * time.Second,
7235 60 * time.Second,
7236 60 * time.Second,
7237 60 * time.Second,
7238 60 * time.Second,
7239 60 * time.Second,
7240}
7241
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007242// shortTimeouts is an alternate set of timeouts which would occur if the
7243// initial timeout duration was set to 250ms.
7244var shortTimeouts = []time.Duration{
7245 250 * time.Millisecond,
7246 500 * time.Millisecond,
7247 1 * time.Second,
7248 2 * time.Second,
7249 4 * time.Second,
7250 8 * time.Second,
7251 16 * time.Second,
7252 32 * time.Second,
7253 60 * time.Second,
7254 60 * time.Second,
7255 60 * time.Second,
7256 60 * time.Second,
7257 60 * time.Second,
7258}
7259
David Benjamin83f90402015-01-27 01:09:43 -05007260func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007261 // These tests work by coordinating some behavior on both the shim and
7262 // the runner.
7263 //
7264 // TimeoutSchedule configures the runner to send a series of timeout
7265 // opcodes to the shim (see packetAdaptor) immediately before reading
7266 // each peer handshake flight N. The timeout opcode both simulates a
7267 // timeout in the shim and acts as a synchronization point to help the
7268 // runner bracket each handshake flight.
7269 //
7270 // We assume the shim does not read from the channel eagerly. It must
7271 // first wait until it has sent flight N and is ready to receive
7272 // handshake flight N+1. At this point, it will process the timeout
7273 // opcode. It must then immediately respond with a timeout ACK and act
7274 // as if the shim was idle for the specified amount of time.
7275 //
7276 // The runner then drops all packets received before the ACK and
7277 // continues waiting for flight N. This ordering results in one attempt
7278 // at sending flight N to be dropped. For the test to complete, the
7279 // shim must send flight N again, testing that the shim implements DTLS
7280 // retransmit on a timeout.
7281
Steven Valdez143e8b32016-07-11 13:19:03 -04007282 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007283 // likely be more epochs to cross and the final message's retransmit may
7284 // be more complex.
7285
David Benjamin585d7a42016-06-02 14:58:00 -04007286 for _, async := range []bool{true, false} {
7287 var tests []testCase
7288
7289 // Test that this is indeed the timeout schedule. Stress all
7290 // four patterns of handshake.
7291 for i := 1; i < len(timeouts); i++ {
7292 number := strconv.Itoa(i)
7293 tests = append(tests, testCase{
7294 protocol: dtls,
7295 name: "DTLS-Retransmit-Client-" + number,
7296 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007297 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007298 Bugs: ProtocolBugs{
7299 TimeoutSchedule: timeouts[:i],
7300 },
7301 },
7302 resumeSession: true,
7303 })
7304 tests = append(tests, testCase{
7305 protocol: dtls,
7306 testType: serverTest,
7307 name: "DTLS-Retransmit-Server-" + number,
7308 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007309 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007310 Bugs: ProtocolBugs{
7311 TimeoutSchedule: timeouts[:i],
7312 },
7313 },
7314 resumeSession: true,
7315 })
7316 }
7317
7318 // Test that exceeding the timeout schedule hits a read
7319 // timeout.
7320 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007321 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007322 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007324 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007325 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007326 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007327 },
7328 },
7329 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007330 shouldFail: true,
7331 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007332 })
David Benjamin585d7a42016-06-02 14:58:00 -04007333
7334 if async {
7335 // Test that timeout handling has a fudge factor, due to API
7336 // problems.
7337 tests = append(tests, testCase{
7338 protocol: dtls,
7339 name: "DTLS-Retransmit-Fudge",
7340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007341 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007342 Bugs: ProtocolBugs{
7343 TimeoutSchedule: []time.Duration{
7344 timeouts[0] - 10*time.Millisecond,
7345 },
7346 },
7347 },
7348 resumeSession: true,
7349 })
7350 }
7351
7352 // Test that the final Finished retransmitting isn't
7353 // duplicated if the peer badly fragments everything.
7354 tests = append(tests, testCase{
7355 testType: serverTest,
7356 protocol: dtls,
7357 name: "DTLS-Retransmit-Fragmented",
7358 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007359 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007360 Bugs: ProtocolBugs{
7361 TimeoutSchedule: []time.Duration{timeouts[0]},
7362 MaxHandshakeRecordLength: 2,
7363 },
7364 },
7365 })
7366
7367 // Test the timeout schedule when a shorter initial timeout duration is set.
7368 tests = append(tests, testCase{
7369 protocol: dtls,
7370 name: "DTLS-Retransmit-Short-Client",
7371 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007372 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007373 Bugs: ProtocolBugs{
7374 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7375 },
7376 },
7377 resumeSession: true,
7378 flags: []string{"-initial-timeout-duration-ms", "250"},
7379 })
7380 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007381 protocol: dtls,
7382 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007383 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007384 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007385 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007386 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007387 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007388 },
7389 },
7390 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007391 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007392 })
David Benjamin585d7a42016-06-02 14:58:00 -04007393
7394 for _, test := range tests {
7395 if async {
7396 test.name += "-Async"
7397 test.flags = append(test.flags, "-async")
7398 }
7399
7400 testCases = append(testCases, test)
7401 }
David Benjamin83f90402015-01-27 01:09:43 -05007402 }
David Benjamin83f90402015-01-27 01:09:43 -05007403}
7404
David Benjaminc565ebb2015-04-03 04:06:36 -04007405func addExportKeyingMaterialTests() {
7406 for _, vers := range tlsVersions {
7407 if vers.version == VersionSSL30 {
7408 continue
7409 }
7410 testCases = append(testCases, testCase{
7411 name: "ExportKeyingMaterial-" + vers.name,
7412 config: Config{
7413 MaxVersion: vers.version,
7414 },
7415 exportKeyingMaterial: 1024,
7416 exportLabel: "label",
7417 exportContext: "context",
7418 useExportContext: true,
7419 })
7420 testCases = append(testCases, testCase{
7421 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7422 config: Config{
7423 MaxVersion: vers.version,
7424 },
7425 exportKeyingMaterial: 1024,
7426 })
7427 testCases = append(testCases, testCase{
7428 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7429 config: Config{
7430 MaxVersion: vers.version,
7431 },
7432 exportKeyingMaterial: 1024,
7433 useExportContext: true,
7434 })
7435 testCases = append(testCases, testCase{
7436 name: "ExportKeyingMaterial-Small-" + vers.name,
7437 config: Config{
7438 MaxVersion: vers.version,
7439 },
7440 exportKeyingMaterial: 1,
7441 exportLabel: "label",
7442 exportContext: "context",
7443 useExportContext: true,
7444 })
7445 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007446
David Benjaminc565ebb2015-04-03 04:06:36 -04007447 testCases = append(testCases, testCase{
7448 name: "ExportKeyingMaterial-SSL3",
7449 config: Config{
7450 MaxVersion: VersionSSL30,
7451 },
7452 exportKeyingMaterial: 1024,
7453 exportLabel: "label",
7454 exportContext: "context",
7455 useExportContext: true,
7456 shouldFail: true,
7457 expectedError: "failed to export keying material",
7458 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007459
7460 // Exporters work during a False Start.
7461 testCases = append(testCases, testCase{
7462 name: "ExportKeyingMaterial-FalseStart",
7463 config: Config{
7464 MaxVersion: VersionTLS12,
7465 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7466 NextProtos: []string{"foo"},
7467 Bugs: ProtocolBugs{
7468 ExpectFalseStart: true,
7469 },
7470 },
7471 flags: []string{
7472 "-false-start",
7473 "-advertise-alpn", "\x03foo",
7474 },
7475 shimWritesFirst: true,
7476 exportKeyingMaterial: 1024,
7477 exportLabel: "label",
7478 exportContext: "context",
7479 useExportContext: true,
7480 })
7481
7482 // Exporters do not work in the middle of a renegotiation. Test this by
7483 // triggering the exporter after every SSL_read call and configuring the
7484 // shim to run asynchronously.
7485 testCases = append(testCases, testCase{
7486 name: "ExportKeyingMaterial-Renegotiate",
7487 config: Config{
7488 MaxVersion: VersionTLS12,
7489 },
7490 renegotiate: 1,
7491 flags: []string{
7492 "-async",
7493 "-use-exporter-between-reads",
7494 "-renegotiate-freely",
7495 "-expect-total-renegotiations", "1",
7496 },
7497 shouldFail: true,
7498 expectedError: "failed to export keying material",
7499 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007500}
7501
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007502func addTLSUniqueTests() {
7503 for _, isClient := range []bool{false, true} {
7504 for _, isResumption := range []bool{false, true} {
7505 for _, hasEMS := range []bool{false, true} {
7506 var suffix string
7507 if isResumption {
7508 suffix = "Resume-"
7509 } else {
7510 suffix = "Full-"
7511 }
7512
7513 if hasEMS {
7514 suffix += "EMS-"
7515 } else {
7516 suffix += "NoEMS-"
7517 }
7518
7519 if isClient {
7520 suffix += "Client"
7521 } else {
7522 suffix += "Server"
7523 }
7524
7525 test := testCase{
7526 name: "TLSUnique-" + suffix,
7527 testTLSUnique: true,
7528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007529 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007530 Bugs: ProtocolBugs{
7531 NoExtendedMasterSecret: !hasEMS,
7532 },
7533 },
7534 }
7535
7536 if isResumption {
7537 test.resumeSession = true
7538 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007539 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007540 Bugs: ProtocolBugs{
7541 NoExtendedMasterSecret: !hasEMS,
7542 },
7543 }
7544 }
7545
7546 if isResumption && !hasEMS {
7547 test.shouldFail = true
7548 test.expectedError = "failed to get tls-unique"
7549 }
7550
7551 testCases = append(testCases, test)
7552 }
7553 }
7554 }
7555}
7556
Adam Langley09505632015-07-30 18:10:13 -07007557func addCustomExtensionTests() {
7558 expectedContents := "custom extension"
7559 emptyString := ""
7560
7561 for _, isClient := range []bool{false, true} {
7562 suffix := "Server"
7563 flag := "-enable-server-custom-extension"
7564 testType := serverTest
7565 if isClient {
7566 suffix = "Client"
7567 flag = "-enable-client-custom-extension"
7568 testType = clientTest
7569 }
7570
7571 testCases = append(testCases, testCase{
7572 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007573 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007574 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007575 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007576 Bugs: ProtocolBugs{
7577 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007578 ExpectedCustomExtension: &expectedContents,
7579 },
7580 },
7581 flags: []string{flag},
7582 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007583 testCases = append(testCases, testCase{
7584 testType: testType,
7585 name: "CustomExtensions-" + suffix + "-TLS13",
7586 config: Config{
7587 MaxVersion: VersionTLS13,
7588 Bugs: ProtocolBugs{
7589 CustomExtension: expectedContents,
7590 ExpectedCustomExtension: &expectedContents,
7591 },
7592 },
7593 flags: []string{flag},
7594 })
Adam Langley09505632015-07-30 18:10:13 -07007595
7596 // If the parse callback fails, the handshake should also fail.
7597 testCases = append(testCases, testCase{
7598 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007599 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007600 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007601 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007602 Bugs: ProtocolBugs{
7603 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007604 ExpectedCustomExtension: &expectedContents,
7605 },
7606 },
David Benjamin399e7c92015-07-30 23:01:27 -04007607 flags: []string{flag},
7608 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007609 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7610 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007611 testCases = append(testCases, testCase{
7612 testType: testType,
7613 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7614 config: Config{
7615 MaxVersion: VersionTLS13,
7616 Bugs: ProtocolBugs{
7617 CustomExtension: expectedContents + "foo",
7618 ExpectedCustomExtension: &expectedContents,
7619 },
7620 },
7621 flags: []string{flag},
7622 shouldFail: true,
7623 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7624 })
Adam Langley09505632015-07-30 18:10:13 -07007625
7626 // If the add callback fails, the handshake should also fail.
7627 testCases = append(testCases, testCase{
7628 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007629 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007630 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007631 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007632 Bugs: ProtocolBugs{
7633 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007634 ExpectedCustomExtension: &expectedContents,
7635 },
7636 },
David Benjamin399e7c92015-07-30 23:01:27 -04007637 flags: []string{flag, "-custom-extension-fail-add"},
7638 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007639 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7640 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007641 testCases = append(testCases, testCase{
7642 testType: testType,
7643 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7644 config: Config{
7645 MaxVersion: VersionTLS13,
7646 Bugs: ProtocolBugs{
7647 CustomExtension: expectedContents,
7648 ExpectedCustomExtension: &expectedContents,
7649 },
7650 },
7651 flags: []string{flag, "-custom-extension-fail-add"},
7652 shouldFail: true,
7653 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7654 })
Adam Langley09505632015-07-30 18:10:13 -07007655
7656 // If the add callback returns zero, no extension should be
7657 // added.
7658 skipCustomExtension := expectedContents
7659 if isClient {
7660 // For the case where the client skips sending the
7661 // custom extension, the server must not “echo” it.
7662 skipCustomExtension = ""
7663 }
7664 testCases = append(testCases, testCase{
7665 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007666 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007667 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007668 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007669 Bugs: ProtocolBugs{
7670 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007671 ExpectedCustomExtension: &emptyString,
7672 },
7673 },
7674 flags: []string{flag, "-custom-extension-skip"},
7675 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007676 testCases = append(testCases, testCase{
7677 testType: testType,
7678 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7679 config: Config{
7680 MaxVersion: VersionTLS13,
7681 Bugs: ProtocolBugs{
7682 CustomExtension: skipCustomExtension,
7683 ExpectedCustomExtension: &emptyString,
7684 },
7685 },
7686 flags: []string{flag, "-custom-extension-skip"},
7687 })
Adam Langley09505632015-07-30 18:10:13 -07007688 }
7689
7690 // The custom extension add callback should not be called if the client
7691 // doesn't send the extension.
7692 testCases = append(testCases, testCase{
7693 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007694 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007695 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007696 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007697 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007698 ExpectedCustomExtension: &emptyString,
7699 },
7700 },
7701 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7702 })
Adam Langley2deb9842015-08-07 11:15:37 -07007703
Steven Valdez143e8b32016-07-11 13:19:03 -04007704 testCases = append(testCases, testCase{
7705 testType: serverTest,
7706 name: "CustomExtensions-NotCalled-Server-TLS13",
7707 config: Config{
7708 MaxVersion: VersionTLS13,
7709 Bugs: ProtocolBugs{
7710 ExpectedCustomExtension: &emptyString,
7711 },
7712 },
7713 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7714 })
7715
Adam Langley2deb9842015-08-07 11:15:37 -07007716 // Test an unknown extension from the server.
7717 testCases = append(testCases, testCase{
7718 testType: clientTest,
7719 name: "UnknownExtension-Client",
7720 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007721 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007722 Bugs: ProtocolBugs{
7723 CustomExtension: expectedContents,
7724 },
7725 },
David Benjamin0c40a962016-08-01 12:05:50 -04007726 shouldFail: true,
7727 expectedError: ":UNEXPECTED_EXTENSION:",
7728 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007729 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007730 testCases = append(testCases, testCase{
7731 testType: clientTest,
7732 name: "UnknownExtension-Client-TLS13",
7733 config: Config{
7734 MaxVersion: VersionTLS13,
7735 Bugs: ProtocolBugs{
7736 CustomExtension: expectedContents,
7737 },
7738 },
David Benjamin0c40a962016-08-01 12:05:50 -04007739 shouldFail: true,
7740 expectedError: ":UNEXPECTED_EXTENSION:",
7741 expectedLocalError: "remote error: unsupported extension",
7742 })
David Benjamin490469f2016-10-05 22:44:38 -04007743 testCases = append(testCases, testCase{
7744 testType: clientTest,
7745 name: "UnknownUnencryptedExtension-Client-TLS13",
7746 config: Config{
7747 MaxVersion: VersionTLS13,
7748 Bugs: ProtocolBugs{
7749 CustomUnencryptedExtension: expectedContents,
7750 },
7751 },
7752 shouldFail: true,
7753 expectedError: ":UNEXPECTED_EXTENSION:",
7754 // The shim must send an alert, but alerts at this point do not
7755 // get successfully decrypted by the runner.
7756 expectedLocalError: "local error: bad record MAC",
7757 })
7758 testCases = append(testCases, testCase{
7759 testType: clientTest,
7760 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7761 config: Config{
7762 MaxVersion: VersionTLS13,
7763 Bugs: ProtocolBugs{
7764 SendUnencryptedALPN: "foo",
7765 },
7766 },
7767 flags: []string{
7768 "-advertise-alpn", "\x03foo\x03bar",
7769 },
7770 shouldFail: true,
7771 expectedError: ":UNEXPECTED_EXTENSION:",
7772 // The shim must send an alert, but alerts at this point do not
7773 // get successfully decrypted by the runner.
7774 expectedLocalError: "local error: bad record MAC",
7775 })
David Benjamin0c40a962016-08-01 12:05:50 -04007776
7777 // Test a known but unoffered extension from the server.
7778 testCases = append(testCases, testCase{
7779 testType: clientTest,
7780 name: "UnofferedExtension-Client",
7781 config: Config{
7782 MaxVersion: VersionTLS12,
7783 Bugs: ProtocolBugs{
7784 SendALPN: "alpn",
7785 },
7786 },
7787 shouldFail: true,
7788 expectedError: ":UNEXPECTED_EXTENSION:",
7789 expectedLocalError: "remote error: unsupported extension",
7790 })
7791 testCases = append(testCases, testCase{
7792 testType: clientTest,
7793 name: "UnofferedExtension-Client-TLS13",
7794 config: Config{
7795 MaxVersion: VersionTLS13,
7796 Bugs: ProtocolBugs{
7797 SendALPN: "alpn",
7798 },
7799 },
7800 shouldFail: true,
7801 expectedError: ":UNEXPECTED_EXTENSION:",
7802 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007803 })
Adam Langley09505632015-07-30 18:10:13 -07007804}
7805
David Benjaminb36a3952015-12-01 18:53:13 -05007806func addRSAClientKeyExchangeTests() {
7807 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7808 testCases = append(testCases, testCase{
7809 testType: serverTest,
7810 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7811 config: Config{
7812 // Ensure the ClientHello version and final
7813 // version are different, to detect if the
7814 // server uses the wrong one.
7815 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007816 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007817 Bugs: ProtocolBugs{
7818 BadRSAClientKeyExchange: bad,
7819 },
7820 },
7821 shouldFail: true,
7822 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7823 })
7824 }
David Benjamine63d9d72016-09-19 18:27:34 -04007825
7826 // The server must compare whatever was in ClientHello.version for the
7827 // RSA premaster.
7828 testCases = append(testCases, testCase{
7829 testType: serverTest,
7830 name: "SendClientVersion-RSA",
7831 config: Config{
7832 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7833 Bugs: ProtocolBugs{
7834 SendClientVersion: 0x1234,
7835 },
7836 },
7837 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7838 })
David Benjaminb36a3952015-12-01 18:53:13 -05007839}
7840
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007841var testCurves = []struct {
7842 name string
7843 id CurveID
7844}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007845 {"P-256", CurveP256},
7846 {"P-384", CurveP384},
7847 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007848 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007849}
7850
Steven Valdez5440fe02016-07-18 12:40:30 -04007851const bogusCurve = 0x1234
7852
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007853func addCurveTests() {
7854 for _, curve := range testCurves {
7855 testCases = append(testCases, testCase{
7856 name: "CurveTest-Client-" + curve.name,
7857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007858 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007859 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7860 CurvePreferences: []CurveID{curve.id},
7861 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007862 flags: []string{
7863 "-enable-all-curves",
7864 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7865 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007866 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007867 })
7868 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007869 name: "CurveTest-Client-" + curve.name + "-TLS13",
7870 config: Config{
7871 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007872 CurvePreferences: []CurveID{curve.id},
7873 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007874 flags: []string{
7875 "-enable-all-curves",
7876 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7877 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007878 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007879 })
7880 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007881 testType: serverTest,
7882 name: "CurveTest-Server-" + curve.name,
7883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007884 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007885 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7886 CurvePreferences: []CurveID{curve.id},
7887 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007888 flags: []string{
7889 "-enable-all-curves",
7890 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7891 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007892 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007893 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007894 testCases = append(testCases, testCase{
7895 testType: serverTest,
7896 name: "CurveTest-Server-" + curve.name + "-TLS13",
7897 config: Config{
7898 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007899 CurvePreferences: []CurveID{curve.id},
7900 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007901 flags: []string{
7902 "-enable-all-curves",
7903 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7904 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007905 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007906 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007907 }
David Benjamin241ae832016-01-15 03:04:54 -05007908
7909 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007910 testCases = append(testCases, testCase{
7911 testType: serverTest,
7912 name: "UnknownCurve",
7913 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007914 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007915 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7916 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7917 },
7918 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007919
Steven Valdez803c77a2016-09-06 14:13:43 -04007920 // The server must be tolerant to bogus curves.
7921 testCases = append(testCases, testCase{
7922 testType: serverTest,
7923 name: "UnknownCurve-TLS13",
7924 config: Config{
7925 MaxVersion: VersionTLS13,
7926 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7927 },
7928 })
7929
David Benjamin4c3ddf72016-06-29 18:13:53 -04007930 // The server must not consider ECDHE ciphers when there are no
7931 // supported curves.
7932 testCases = append(testCases, testCase{
7933 testType: serverTest,
7934 name: "NoSupportedCurves",
7935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007936 MaxVersion: VersionTLS12,
7937 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7938 Bugs: ProtocolBugs{
7939 NoSupportedCurves: true,
7940 },
7941 },
7942 shouldFail: true,
7943 expectedError: ":NO_SHARED_CIPHER:",
7944 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007945 testCases = append(testCases, testCase{
7946 testType: serverTest,
7947 name: "NoSupportedCurves-TLS13",
7948 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007949 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007950 Bugs: ProtocolBugs{
7951 NoSupportedCurves: true,
7952 },
7953 },
7954 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007955 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007956 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007957
7958 // The server must fall back to another cipher when there are no
7959 // supported curves.
7960 testCases = append(testCases, testCase{
7961 testType: serverTest,
7962 name: "NoCommonCurves",
7963 config: Config{
7964 MaxVersion: VersionTLS12,
7965 CipherSuites: []uint16{
7966 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7967 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7968 },
7969 CurvePreferences: []CurveID{CurveP224},
7970 },
7971 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7972 })
7973
7974 // The client must reject bogus curves and disabled curves.
7975 testCases = append(testCases, testCase{
7976 name: "BadECDHECurve",
7977 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007978 MaxVersion: VersionTLS12,
7979 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7980 Bugs: ProtocolBugs{
7981 SendCurve: bogusCurve,
7982 },
7983 },
7984 shouldFail: true,
7985 expectedError: ":WRONG_CURVE:",
7986 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007987 testCases = append(testCases, testCase{
7988 name: "BadECDHECurve-TLS13",
7989 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007990 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007991 Bugs: ProtocolBugs{
7992 SendCurve: bogusCurve,
7993 },
7994 },
7995 shouldFail: true,
7996 expectedError: ":WRONG_CURVE:",
7997 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007998
7999 testCases = append(testCases, testCase{
8000 name: "UnsupportedCurve",
8001 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008002 MaxVersion: VersionTLS12,
8003 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8004 CurvePreferences: []CurveID{CurveP256},
8005 Bugs: ProtocolBugs{
8006 IgnorePeerCurvePreferences: true,
8007 },
8008 },
8009 flags: []string{"-p384-only"},
8010 shouldFail: true,
8011 expectedError: ":WRONG_CURVE:",
8012 })
8013
David Benjamin4f921572016-07-17 14:20:10 +02008014 testCases = append(testCases, testCase{
8015 // TODO(davidben): Add a TLS 1.3 version where
8016 // HelloRetryRequest requests an unsupported curve.
8017 name: "UnsupportedCurve-ServerHello-TLS13",
8018 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008019 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008020 CurvePreferences: []CurveID{CurveP384},
8021 Bugs: ProtocolBugs{
8022 SendCurve: CurveP256,
8023 },
8024 },
8025 flags: []string{"-p384-only"},
8026 shouldFail: true,
8027 expectedError: ":WRONG_CURVE:",
8028 })
8029
David Benjamin4c3ddf72016-06-29 18:13:53 -04008030 // Test invalid curve points.
8031 testCases = append(testCases, testCase{
8032 name: "InvalidECDHPoint-Client",
8033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008034 MaxVersion: VersionTLS12,
8035 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8036 CurvePreferences: []CurveID{CurveP256},
8037 Bugs: ProtocolBugs{
8038 InvalidECDHPoint: true,
8039 },
8040 },
8041 shouldFail: true,
8042 expectedError: ":INVALID_ENCODING:",
8043 })
8044 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008045 name: "InvalidECDHPoint-Client-TLS13",
8046 config: Config{
8047 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008048 CurvePreferences: []CurveID{CurveP256},
8049 Bugs: ProtocolBugs{
8050 InvalidECDHPoint: true,
8051 },
8052 },
8053 shouldFail: true,
8054 expectedError: ":INVALID_ENCODING:",
8055 })
8056 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008057 testType: serverTest,
8058 name: "InvalidECDHPoint-Server",
8059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008060 MaxVersion: VersionTLS12,
8061 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8062 CurvePreferences: []CurveID{CurveP256},
8063 Bugs: ProtocolBugs{
8064 InvalidECDHPoint: true,
8065 },
8066 },
8067 shouldFail: true,
8068 expectedError: ":INVALID_ENCODING:",
8069 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008070 testCases = append(testCases, testCase{
8071 testType: serverTest,
8072 name: "InvalidECDHPoint-Server-TLS13",
8073 config: Config{
8074 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008075 CurvePreferences: []CurveID{CurveP256},
8076 Bugs: ProtocolBugs{
8077 InvalidECDHPoint: true,
8078 },
8079 },
8080 shouldFail: true,
8081 expectedError: ":INVALID_ENCODING:",
8082 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008083
8084 // The previous curve ID should be reported on TLS 1.2 resumption.
8085 testCases = append(testCases, testCase{
8086 name: "CurveID-Resume-Client",
8087 config: Config{
8088 MaxVersion: VersionTLS12,
8089 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8090 CurvePreferences: []CurveID{CurveX25519},
8091 },
8092 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8093 resumeSession: true,
8094 })
8095 testCases = append(testCases, testCase{
8096 testType: serverTest,
8097 name: "CurveID-Resume-Server",
8098 config: Config{
8099 MaxVersion: VersionTLS12,
8100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8101 CurvePreferences: []CurveID{CurveX25519},
8102 },
8103 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8104 resumeSession: true,
8105 })
8106
8107 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8108 // one should be reported.
8109 testCases = append(testCases, testCase{
8110 name: "CurveID-Resume-Client-TLS13",
8111 config: Config{
8112 MaxVersion: VersionTLS13,
8113 CurvePreferences: []CurveID{CurveX25519},
8114 },
8115 resumeConfig: &Config{
8116 MaxVersion: VersionTLS13,
8117 CurvePreferences: []CurveID{CurveP256},
8118 },
8119 flags: []string{
8120 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8121 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8122 },
8123 resumeSession: true,
8124 })
8125 testCases = append(testCases, testCase{
8126 testType: serverTest,
8127 name: "CurveID-Resume-Server-TLS13",
8128 config: Config{
8129 MaxVersion: VersionTLS13,
8130 CurvePreferences: []CurveID{CurveX25519},
8131 },
8132 resumeConfig: &Config{
8133 MaxVersion: VersionTLS13,
8134 CurvePreferences: []CurveID{CurveP256},
8135 },
8136 flags: []string{
8137 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8138 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8139 },
8140 resumeSession: true,
8141 })
David Benjamina81967b2016-12-22 09:16:57 -05008142
8143 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8144 testCases = append(testCases, testCase{
8145 name: "PointFormat-ServerHello-TLS12",
8146 config: Config{
8147 MaxVersion: VersionTLS12,
8148 Bugs: ProtocolBugs{
8149 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8150 },
8151 },
8152 })
8153 testCases = append(testCases, testCase{
8154 name: "PointFormat-EncryptedExtensions-TLS13",
8155 config: Config{
8156 MaxVersion: VersionTLS13,
8157 Bugs: ProtocolBugs{
8158 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8159 },
8160 },
8161 shouldFail: true,
8162 expectedError: ":ERROR_PARSING_EXTENSION:",
8163 })
8164
8165 // Test that we tolerate unknown point formats, as long as
8166 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8167 // check they are still functional.
8168 testCases = append(testCases, testCase{
8169 name: "PointFormat-Client-Tolerance",
8170 config: Config{
8171 MaxVersion: VersionTLS12,
8172 Bugs: ProtocolBugs{
8173 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8174 },
8175 },
8176 })
8177 testCases = append(testCases, testCase{
8178 testType: serverTest,
8179 name: "PointFormat-Server-Tolerance",
8180 config: Config{
8181 MaxVersion: VersionTLS12,
8182 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8183 Bugs: ProtocolBugs{
8184 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8185 },
8186 },
8187 })
8188
8189 // Test TLS 1.2 does not require the point format extension to be
8190 // present.
8191 testCases = append(testCases, testCase{
8192 name: "PointFormat-Client-Missing",
8193 config: Config{
8194 MaxVersion: VersionTLS12,
8195 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8196 Bugs: ProtocolBugs{
8197 SendSupportedPointFormats: []byte{},
8198 },
8199 },
8200 })
8201 testCases = append(testCases, testCase{
8202 testType: serverTest,
8203 name: "PointFormat-Server-Missing",
8204 config: Config{
8205 MaxVersion: VersionTLS12,
8206 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8207 Bugs: ProtocolBugs{
8208 SendSupportedPointFormats: []byte{},
8209 },
8210 },
8211 })
8212
8213 // If the point format extension is present, uncompressed points must be
8214 // offered. BoringSSL requires this whether or not ECDHE is used.
8215 testCases = append(testCases, testCase{
8216 name: "PointFormat-Client-MissingUncompressed",
8217 config: Config{
8218 MaxVersion: VersionTLS12,
8219 Bugs: ProtocolBugs{
8220 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8221 },
8222 },
8223 shouldFail: true,
8224 expectedError: ":ERROR_PARSING_EXTENSION:",
8225 })
8226 testCases = append(testCases, testCase{
8227 testType: serverTest,
8228 name: "PointFormat-Server-MissingUncompressed",
8229 config: Config{
8230 MaxVersion: VersionTLS12,
8231 Bugs: ProtocolBugs{
8232 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8233 },
8234 },
8235 shouldFail: true,
8236 expectedError: ":ERROR_PARSING_EXTENSION:",
8237 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008238}
8239
David Benjaminc9ae27c2016-06-24 22:56:37 -04008240func addTLS13RecordTests() {
8241 testCases = append(testCases, testCase{
8242 name: "TLS13-RecordPadding",
8243 config: Config{
8244 MaxVersion: VersionTLS13,
8245 MinVersion: VersionTLS13,
8246 Bugs: ProtocolBugs{
8247 RecordPadding: 10,
8248 },
8249 },
8250 })
8251
8252 testCases = append(testCases, testCase{
8253 name: "TLS13-EmptyRecords",
8254 config: Config{
8255 MaxVersion: VersionTLS13,
8256 MinVersion: VersionTLS13,
8257 Bugs: ProtocolBugs{
8258 OmitRecordContents: true,
8259 },
8260 },
8261 shouldFail: true,
8262 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8263 })
8264
8265 testCases = append(testCases, testCase{
8266 name: "TLS13-OnlyPadding",
8267 config: Config{
8268 MaxVersion: VersionTLS13,
8269 MinVersion: VersionTLS13,
8270 Bugs: ProtocolBugs{
8271 OmitRecordContents: true,
8272 RecordPadding: 10,
8273 },
8274 },
8275 shouldFail: true,
8276 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8277 })
8278
8279 testCases = append(testCases, testCase{
8280 name: "TLS13-WrongOuterRecord",
8281 config: Config{
8282 MaxVersion: VersionTLS13,
8283 MinVersion: VersionTLS13,
8284 Bugs: ProtocolBugs{
8285 OuterRecordType: recordTypeHandshake,
8286 },
8287 },
8288 shouldFail: true,
8289 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8290 })
8291}
8292
Steven Valdez5b986082016-09-01 12:29:49 -04008293func addSessionTicketTests() {
8294 testCases = append(testCases, testCase{
8295 // In TLS 1.2 and below, empty NewSessionTicket messages
8296 // mean the server changed its mind on sending a ticket.
8297 name: "SendEmptySessionTicket",
8298 config: Config{
8299 MaxVersion: VersionTLS12,
8300 Bugs: ProtocolBugs{
8301 SendEmptySessionTicket: true,
8302 },
8303 },
8304 flags: []string{"-expect-no-session"},
8305 })
8306
8307 // Test that the server ignores unknown PSK modes.
8308 testCases = append(testCases, testCase{
8309 testType: serverTest,
8310 name: "TLS13-SendUnknownModeSessionTicket-Server",
8311 config: Config{
8312 MaxVersion: VersionTLS13,
8313 Bugs: ProtocolBugs{
8314 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008315 },
8316 },
8317 resumeSession: true,
8318 expectedResumeVersion: VersionTLS13,
8319 })
8320
Steven Valdeza833c352016-11-01 13:39:36 -04008321 // Test that the server does not send session tickets with no matching key exchange mode.
8322 testCases = append(testCases, testCase{
8323 testType: serverTest,
8324 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8325 config: Config{
8326 MaxVersion: VersionTLS13,
8327 Bugs: ProtocolBugs{
8328 SendPSKKeyExchangeModes: []byte{0x1a},
8329 ExpectNoNewSessionTicket: true,
8330 },
8331 },
8332 })
8333
8334 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008335 testCases = append(testCases, testCase{
8336 testType: serverTest,
8337 name: "TLS13-SendBadKEModeSessionTicket-Server",
8338 config: Config{
8339 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008340 },
8341 resumeConfig: &Config{
8342 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008343 Bugs: ProtocolBugs{
8344 SendPSKKeyExchangeModes: []byte{0x1a},
8345 },
8346 },
8347 resumeSession: true,
8348 expectResumeRejected: true,
8349 })
8350
Steven Valdeza833c352016-11-01 13:39:36 -04008351 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008352 testCases = append(testCases, testCase{
8353 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008354 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008355 config: Config{
8356 MaxVersion: VersionTLS13,
8357 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008358 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008359 },
8360 },
Steven Valdeza833c352016-11-01 13:39:36 -04008361 resumeSession: true,
8362 flags: []string{
8363 "-resumption-delay", "10",
8364 },
Steven Valdez5b986082016-09-01 12:29:49 -04008365 })
8366
Steven Valdeza833c352016-11-01 13:39:36 -04008367 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008368 testCases = append(testCases, testCase{
8369 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008370 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008371 config: Config{
8372 MaxVersion: VersionTLS13,
8373 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008374 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008375 },
8376 },
Steven Valdeza833c352016-11-01 13:39:36 -04008377 resumeSession: true,
8378 shouldFail: true,
8379 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008380 })
8381
Steven Valdez08b65f42016-12-07 15:29:45 -05008382 testCases = append(testCases, testCase{
8383 testType: clientTest,
8384 name: "TLS13-SendTicketEarlyDataInfo",
8385 config: Config{
8386 MaxVersion: VersionTLS13,
8387 Bugs: ProtocolBugs{
8388 SendTicketEarlyDataInfo: 16384,
8389 },
8390 },
8391 flags: []string{
8392 "-expect-early-data-info",
8393 },
8394 })
8395
8396 testCases = append(testCases, testCase{
8397 testType: serverTest,
8398 name: "TLS13-ExpectTicketEarlyDataInfo",
8399 config: Config{
8400 MaxVersion: VersionTLS13,
8401 Bugs: ProtocolBugs{
8402 ExpectTicketEarlyDataInfo: true,
8403 },
8404 },
8405 flags: []string{
8406 "-enable-early-data",
8407 },
8408 })
Steven Valdez5b986082016-09-01 12:29:49 -04008409}
8410
David Benjamin82261be2016-07-07 14:32:50 -07008411func addChangeCipherSpecTests() {
8412 // Test missing ChangeCipherSpecs.
8413 testCases = append(testCases, testCase{
8414 name: "SkipChangeCipherSpec-Client",
8415 config: Config{
8416 MaxVersion: VersionTLS12,
8417 Bugs: ProtocolBugs{
8418 SkipChangeCipherSpec: true,
8419 },
8420 },
8421 shouldFail: true,
8422 expectedError: ":UNEXPECTED_RECORD:",
8423 })
8424 testCases = append(testCases, testCase{
8425 testType: serverTest,
8426 name: "SkipChangeCipherSpec-Server",
8427 config: Config{
8428 MaxVersion: VersionTLS12,
8429 Bugs: ProtocolBugs{
8430 SkipChangeCipherSpec: true,
8431 },
8432 },
8433 shouldFail: true,
8434 expectedError: ":UNEXPECTED_RECORD:",
8435 })
8436 testCases = append(testCases, testCase{
8437 testType: serverTest,
8438 name: "SkipChangeCipherSpec-Server-NPN",
8439 config: Config{
8440 MaxVersion: VersionTLS12,
8441 NextProtos: []string{"bar"},
8442 Bugs: ProtocolBugs{
8443 SkipChangeCipherSpec: true,
8444 },
8445 },
8446 flags: []string{
8447 "-advertise-npn", "\x03foo\x03bar\x03baz",
8448 },
8449 shouldFail: true,
8450 expectedError: ":UNEXPECTED_RECORD:",
8451 })
8452
8453 // Test synchronization between the handshake and ChangeCipherSpec.
8454 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8455 // rejected. Test both with and without handshake packing to handle both
8456 // when the partial post-CCS message is in its own record and when it is
8457 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008458 for _, packed := range []bool{false, true} {
8459 var suffix string
8460 if packed {
8461 suffix = "-Packed"
8462 }
8463
8464 testCases = append(testCases, testCase{
8465 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8466 config: Config{
8467 MaxVersion: VersionTLS12,
8468 Bugs: ProtocolBugs{
8469 FragmentAcrossChangeCipherSpec: true,
8470 PackHandshakeFlight: packed,
8471 },
8472 },
8473 shouldFail: true,
8474 expectedError: ":UNEXPECTED_RECORD:",
8475 })
8476 testCases = append(testCases, testCase{
8477 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8478 config: Config{
8479 MaxVersion: VersionTLS12,
8480 },
8481 resumeSession: true,
8482 resumeConfig: &Config{
8483 MaxVersion: VersionTLS12,
8484 Bugs: ProtocolBugs{
8485 FragmentAcrossChangeCipherSpec: true,
8486 PackHandshakeFlight: packed,
8487 },
8488 },
8489 shouldFail: true,
8490 expectedError: ":UNEXPECTED_RECORD:",
8491 })
8492 testCases = append(testCases, testCase{
8493 testType: serverTest,
8494 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8495 config: Config{
8496 MaxVersion: VersionTLS12,
8497 Bugs: ProtocolBugs{
8498 FragmentAcrossChangeCipherSpec: true,
8499 PackHandshakeFlight: packed,
8500 },
8501 },
8502 shouldFail: true,
8503 expectedError: ":UNEXPECTED_RECORD:",
8504 })
8505 testCases = append(testCases, testCase{
8506 testType: serverTest,
8507 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8508 config: Config{
8509 MaxVersion: VersionTLS12,
8510 },
8511 resumeSession: true,
8512 resumeConfig: &Config{
8513 MaxVersion: VersionTLS12,
8514 Bugs: ProtocolBugs{
8515 FragmentAcrossChangeCipherSpec: true,
8516 PackHandshakeFlight: packed,
8517 },
8518 },
8519 shouldFail: true,
8520 expectedError: ":UNEXPECTED_RECORD:",
8521 })
8522 testCases = append(testCases, testCase{
8523 testType: serverTest,
8524 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8525 config: Config{
8526 MaxVersion: VersionTLS12,
8527 NextProtos: []string{"bar"},
8528 Bugs: ProtocolBugs{
8529 FragmentAcrossChangeCipherSpec: true,
8530 PackHandshakeFlight: packed,
8531 },
8532 },
8533 flags: []string{
8534 "-advertise-npn", "\x03foo\x03bar\x03baz",
8535 },
8536 shouldFail: true,
8537 expectedError: ":UNEXPECTED_RECORD:",
8538 })
8539 }
8540
David Benjamin61672812016-07-14 23:10:43 -04008541 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8542 // messages in the handshake queue. Do this by testing the server
8543 // reading the client Finished, reversing the flight so Finished comes
8544 // first.
8545 testCases = append(testCases, testCase{
8546 protocol: dtls,
8547 testType: serverTest,
8548 name: "SendUnencryptedFinished-DTLS",
8549 config: Config{
8550 MaxVersion: VersionTLS12,
8551 Bugs: ProtocolBugs{
8552 SendUnencryptedFinished: true,
8553 ReverseHandshakeFragments: true,
8554 },
8555 },
8556 shouldFail: true,
8557 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8558 })
8559
Steven Valdez143e8b32016-07-11 13:19:03 -04008560 // Test synchronization between encryption changes and the handshake in
8561 // TLS 1.3, where ChangeCipherSpec is implicit.
8562 testCases = append(testCases, testCase{
8563 name: "PartialEncryptedExtensionsWithServerHello",
8564 config: Config{
8565 MaxVersion: VersionTLS13,
8566 Bugs: ProtocolBugs{
8567 PartialEncryptedExtensionsWithServerHello: true,
8568 },
8569 },
8570 shouldFail: true,
8571 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8572 })
8573 testCases = append(testCases, testCase{
8574 testType: serverTest,
8575 name: "PartialClientFinishedWithClientHello",
8576 config: Config{
8577 MaxVersion: VersionTLS13,
8578 Bugs: ProtocolBugs{
8579 PartialClientFinishedWithClientHello: true,
8580 },
8581 },
8582 shouldFail: true,
8583 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8584 })
8585
David Benjamin82261be2016-07-07 14:32:50 -07008586 // Test that early ChangeCipherSpecs are handled correctly.
8587 testCases = append(testCases, testCase{
8588 testType: serverTest,
8589 name: "EarlyChangeCipherSpec-server-1",
8590 config: Config{
8591 MaxVersion: VersionTLS12,
8592 Bugs: ProtocolBugs{
8593 EarlyChangeCipherSpec: 1,
8594 },
8595 },
8596 shouldFail: true,
8597 expectedError: ":UNEXPECTED_RECORD:",
8598 })
8599 testCases = append(testCases, testCase{
8600 testType: serverTest,
8601 name: "EarlyChangeCipherSpec-server-2",
8602 config: Config{
8603 MaxVersion: VersionTLS12,
8604 Bugs: ProtocolBugs{
8605 EarlyChangeCipherSpec: 2,
8606 },
8607 },
8608 shouldFail: true,
8609 expectedError: ":UNEXPECTED_RECORD:",
8610 })
8611 testCases = append(testCases, testCase{
8612 protocol: dtls,
8613 name: "StrayChangeCipherSpec",
8614 config: Config{
8615 // TODO(davidben): Once DTLS 1.3 exists, test
8616 // that stray ChangeCipherSpec messages are
8617 // rejected.
8618 MaxVersion: VersionTLS12,
8619 Bugs: ProtocolBugs{
8620 StrayChangeCipherSpec: true,
8621 },
8622 },
8623 })
8624
8625 // Test that the contents of ChangeCipherSpec are checked.
8626 testCases = append(testCases, testCase{
8627 name: "BadChangeCipherSpec-1",
8628 config: Config{
8629 MaxVersion: VersionTLS12,
8630 Bugs: ProtocolBugs{
8631 BadChangeCipherSpec: []byte{2},
8632 },
8633 },
8634 shouldFail: true,
8635 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8636 })
8637 testCases = append(testCases, testCase{
8638 name: "BadChangeCipherSpec-2",
8639 config: Config{
8640 MaxVersion: VersionTLS12,
8641 Bugs: ProtocolBugs{
8642 BadChangeCipherSpec: []byte{1, 1},
8643 },
8644 },
8645 shouldFail: true,
8646 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8647 })
8648 testCases = append(testCases, testCase{
8649 protocol: dtls,
8650 name: "BadChangeCipherSpec-DTLS-1",
8651 config: Config{
8652 MaxVersion: VersionTLS12,
8653 Bugs: ProtocolBugs{
8654 BadChangeCipherSpec: []byte{2},
8655 },
8656 },
8657 shouldFail: true,
8658 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8659 })
8660 testCases = append(testCases, testCase{
8661 protocol: dtls,
8662 name: "BadChangeCipherSpec-DTLS-2",
8663 config: Config{
8664 MaxVersion: VersionTLS12,
8665 Bugs: ProtocolBugs{
8666 BadChangeCipherSpec: []byte{1, 1},
8667 },
8668 },
8669 shouldFail: true,
8670 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8671 })
8672}
8673
David Benjamincd2c8062016-09-09 11:28:16 -04008674type perMessageTest struct {
8675 messageType uint8
8676 test testCase
8677}
8678
8679// makePerMessageTests returns a series of test templates which cover each
8680// message in the TLS handshake. These may be used with bugs like
8681// WrongMessageType to fully test a per-message bug.
8682func makePerMessageTests() []perMessageTest {
8683 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008684 for _, protocol := range []protocol{tls, dtls} {
8685 var suffix string
8686 if protocol == dtls {
8687 suffix = "-DTLS"
8688 }
8689
David Benjamincd2c8062016-09-09 11:28:16 -04008690 ret = append(ret, perMessageTest{
8691 messageType: typeClientHello,
8692 test: testCase{
8693 protocol: protocol,
8694 testType: serverTest,
8695 name: "ClientHello" + suffix,
8696 config: Config{
8697 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008698 },
8699 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008700 })
8701
8702 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008703 ret = append(ret, perMessageTest{
8704 messageType: typeHelloVerifyRequest,
8705 test: testCase{
8706 protocol: protocol,
8707 name: "HelloVerifyRequest" + suffix,
8708 config: Config{
8709 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008710 },
8711 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008712 })
8713 }
8714
David Benjamincd2c8062016-09-09 11:28:16 -04008715 ret = append(ret, perMessageTest{
8716 messageType: typeServerHello,
8717 test: testCase{
8718 protocol: protocol,
8719 name: "ServerHello" + suffix,
8720 config: Config{
8721 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008722 },
8723 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008724 })
8725
David Benjamincd2c8062016-09-09 11:28:16 -04008726 ret = append(ret, perMessageTest{
8727 messageType: typeCertificate,
8728 test: testCase{
8729 protocol: protocol,
8730 name: "ServerCertificate" + suffix,
8731 config: Config{
8732 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008733 },
8734 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008735 })
8736
David Benjamincd2c8062016-09-09 11:28:16 -04008737 ret = append(ret, perMessageTest{
8738 messageType: typeCertificateStatus,
8739 test: testCase{
8740 protocol: protocol,
8741 name: "CertificateStatus" + suffix,
8742 config: Config{
8743 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008744 },
David Benjamincd2c8062016-09-09 11:28:16 -04008745 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008746 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008747 })
8748
David Benjamincd2c8062016-09-09 11:28:16 -04008749 ret = append(ret, perMessageTest{
8750 messageType: typeServerKeyExchange,
8751 test: testCase{
8752 protocol: protocol,
8753 name: "ServerKeyExchange" + suffix,
8754 config: Config{
8755 MaxVersion: VersionTLS12,
8756 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008757 },
8758 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008759 })
8760
David Benjamincd2c8062016-09-09 11:28:16 -04008761 ret = append(ret, perMessageTest{
8762 messageType: typeCertificateRequest,
8763 test: testCase{
8764 protocol: protocol,
8765 name: "CertificateRequest" + suffix,
8766 config: Config{
8767 MaxVersion: VersionTLS12,
8768 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008769 },
8770 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008771 })
8772
David Benjamincd2c8062016-09-09 11:28:16 -04008773 ret = append(ret, perMessageTest{
8774 messageType: typeServerHelloDone,
8775 test: testCase{
8776 protocol: protocol,
8777 name: "ServerHelloDone" + suffix,
8778 config: Config{
8779 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008780 },
8781 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008782 })
8783
David Benjamincd2c8062016-09-09 11:28:16 -04008784 ret = append(ret, perMessageTest{
8785 messageType: typeCertificate,
8786 test: testCase{
8787 testType: serverTest,
8788 protocol: protocol,
8789 name: "ClientCertificate" + suffix,
8790 config: Config{
8791 Certificates: []Certificate{rsaCertificate},
8792 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008793 },
David Benjamincd2c8062016-09-09 11:28:16 -04008794 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008795 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008796 })
8797
David Benjamincd2c8062016-09-09 11:28:16 -04008798 ret = append(ret, perMessageTest{
8799 messageType: typeCertificateVerify,
8800 test: testCase{
8801 testType: serverTest,
8802 protocol: protocol,
8803 name: "CertificateVerify" + suffix,
8804 config: Config{
8805 Certificates: []Certificate{rsaCertificate},
8806 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008807 },
David Benjamincd2c8062016-09-09 11:28:16 -04008808 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008809 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008810 })
8811
David Benjamincd2c8062016-09-09 11:28:16 -04008812 ret = append(ret, perMessageTest{
8813 messageType: typeClientKeyExchange,
8814 test: testCase{
8815 testType: serverTest,
8816 protocol: protocol,
8817 name: "ClientKeyExchange" + suffix,
8818 config: Config{
8819 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008820 },
8821 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008822 })
8823
8824 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008825 ret = append(ret, perMessageTest{
8826 messageType: typeNextProtocol,
8827 test: testCase{
8828 testType: serverTest,
8829 protocol: protocol,
8830 name: "NextProtocol" + suffix,
8831 config: Config{
8832 MaxVersion: VersionTLS12,
8833 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008834 },
David Benjamincd2c8062016-09-09 11:28:16 -04008835 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008836 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008837 })
8838
David Benjamincd2c8062016-09-09 11:28:16 -04008839 ret = append(ret, perMessageTest{
8840 messageType: typeChannelID,
8841 test: testCase{
8842 testType: serverTest,
8843 protocol: protocol,
8844 name: "ChannelID" + suffix,
8845 config: Config{
8846 MaxVersion: VersionTLS12,
8847 ChannelID: channelIDKey,
8848 },
8849 flags: []string{
8850 "-expect-channel-id",
8851 base64.StdEncoding.EncodeToString(channelIDBytes),
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: typeFinished,
8859 test: testCase{
8860 testType: serverTest,
8861 protocol: protocol,
8862 name: "ClientFinished" + suffix,
8863 config: Config{
8864 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008865 },
8866 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008867 })
8868
David Benjamincd2c8062016-09-09 11:28:16 -04008869 ret = append(ret, perMessageTest{
8870 messageType: typeNewSessionTicket,
8871 test: testCase{
8872 protocol: protocol,
8873 name: "NewSessionTicket" + suffix,
8874 config: Config{
8875 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008876 },
8877 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008878 })
8879
David Benjamincd2c8062016-09-09 11:28:16 -04008880 ret = append(ret, perMessageTest{
8881 messageType: typeFinished,
8882 test: testCase{
8883 protocol: protocol,
8884 name: "ServerFinished" + suffix,
8885 config: Config{
8886 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008887 },
8888 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008889 })
8890
8891 }
David Benjamincd2c8062016-09-09 11:28:16 -04008892
8893 ret = append(ret, perMessageTest{
8894 messageType: typeClientHello,
8895 test: testCase{
8896 testType: serverTest,
8897 name: "TLS13-ClientHello",
8898 config: Config{
8899 MaxVersion: VersionTLS13,
8900 },
8901 },
8902 })
8903
8904 ret = append(ret, perMessageTest{
8905 messageType: typeServerHello,
8906 test: testCase{
8907 name: "TLS13-ServerHello",
8908 config: Config{
8909 MaxVersion: VersionTLS13,
8910 },
8911 },
8912 })
8913
8914 ret = append(ret, perMessageTest{
8915 messageType: typeEncryptedExtensions,
8916 test: testCase{
8917 name: "TLS13-EncryptedExtensions",
8918 config: Config{
8919 MaxVersion: VersionTLS13,
8920 },
8921 },
8922 })
8923
8924 ret = append(ret, perMessageTest{
8925 messageType: typeCertificateRequest,
8926 test: testCase{
8927 name: "TLS13-CertificateRequest",
8928 config: Config{
8929 MaxVersion: VersionTLS13,
8930 ClientAuth: RequireAnyClientCert,
8931 },
8932 },
8933 })
8934
8935 ret = append(ret, perMessageTest{
8936 messageType: typeCertificate,
8937 test: testCase{
8938 name: "TLS13-ServerCertificate",
8939 config: Config{
8940 MaxVersion: VersionTLS13,
8941 },
8942 },
8943 })
8944
8945 ret = append(ret, perMessageTest{
8946 messageType: typeCertificateVerify,
8947 test: testCase{
8948 name: "TLS13-ServerCertificateVerify",
8949 config: Config{
8950 MaxVersion: VersionTLS13,
8951 },
8952 },
8953 })
8954
8955 ret = append(ret, perMessageTest{
8956 messageType: typeFinished,
8957 test: testCase{
8958 name: "TLS13-ServerFinished",
8959 config: Config{
8960 MaxVersion: VersionTLS13,
8961 },
8962 },
8963 })
8964
8965 ret = append(ret, perMessageTest{
8966 messageType: typeCertificate,
8967 test: testCase{
8968 testType: serverTest,
8969 name: "TLS13-ClientCertificate",
8970 config: Config{
8971 Certificates: []Certificate{rsaCertificate},
8972 MaxVersion: VersionTLS13,
8973 },
8974 flags: []string{"-require-any-client-certificate"},
8975 },
8976 })
8977
8978 ret = append(ret, perMessageTest{
8979 messageType: typeCertificateVerify,
8980 test: testCase{
8981 testType: serverTest,
8982 name: "TLS13-ClientCertificateVerify",
8983 config: Config{
8984 Certificates: []Certificate{rsaCertificate},
8985 MaxVersion: VersionTLS13,
8986 },
8987 flags: []string{"-require-any-client-certificate"},
8988 },
8989 })
8990
8991 ret = append(ret, perMessageTest{
8992 messageType: typeFinished,
8993 test: testCase{
8994 testType: serverTest,
8995 name: "TLS13-ClientFinished",
8996 config: Config{
8997 MaxVersion: VersionTLS13,
8998 },
8999 },
9000 })
9001
9002 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009003}
9004
David Benjamincd2c8062016-09-09 11:28:16 -04009005func addWrongMessageTypeTests() {
9006 for _, t := range makePerMessageTests() {
9007 t.test.name = "WrongMessageType-" + t.test.name
9008 t.test.config.Bugs.SendWrongMessageType = t.messageType
9009 t.test.shouldFail = true
9010 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9011 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009012
David Benjamincd2c8062016-09-09 11:28:16 -04009013 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9014 // In TLS 1.3, a bad ServerHello means the client sends
9015 // an unencrypted alert while the server expects
9016 // encryption, so the alert is not readable by runner.
9017 t.test.expectedLocalError = "local error: bad record MAC"
9018 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009019
David Benjamincd2c8062016-09-09 11:28:16 -04009020 testCases = append(testCases, t.test)
9021 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009022}
9023
David Benjamin639846e2016-09-09 11:41:18 -04009024func addTrailingMessageDataTests() {
9025 for _, t := range makePerMessageTests() {
9026 t.test.name = "TrailingMessageData-" + t.test.name
9027 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9028 t.test.shouldFail = true
9029 t.test.expectedError = ":DECODE_ERROR:"
9030 t.test.expectedLocalError = "remote error: error decoding message"
9031
9032 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9033 // In TLS 1.3, a bad ServerHello means the client sends
9034 // an unencrypted alert while the server expects
9035 // encryption, so the alert is not readable by runner.
9036 t.test.expectedLocalError = "local error: bad record MAC"
9037 }
9038
9039 if t.messageType == typeFinished {
9040 // Bad Finished messages read as the verify data having
9041 // the wrong length.
9042 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9043 t.test.expectedLocalError = "remote error: error decrypting message"
9044 }
9045
9046 testCases = append(testCases, t.test)
9047 }
9048}
9049
Steven Valdez143e8b32016-07-11 13:19:03 -04009050func addTLS13HandshakeTests() {
9051 testCases = append(testCases, testCase{
9052 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009053 name: "NegotiatePSKResumption-TLS13",
9054 config: Config{
9055 MaxVersion: VersionTLS13,
9056 Bugs: ProtocolBugs{
9057 NegotiatePSKResumption: true,
9058 },
9059 },
9060 resumeSession: true,
9061 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009062 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009063 })
9064
9065 testCases = append(testCases, testCase{
9066 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009067 name: "MissingKeyShare-Client",
9068 config: Config{
9069 MaxVersion: VersionTLS13,
9070 Bugs: ProtocolBugs{
9071 MissingKeyShare: true,
9072 },
9073 },
9074 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009075 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009076 })
9077
9078 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009079 testType: serverTest,
9080 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009081 config: Config{
9082 MaxVersion: VersionTLS13,
9083 Bugs: ProtocolBugs{
9084 MissingKeyShare: true,
9085 },
9086 },
9087 shouldFail: true,
9088 expectedError: ":MISSING_KEY_SHARE:",
9089 })
9090
9091 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009092 testType: serverTest,
9093 name: "DuplicateKeyShares",
9094 config: Config{
9095 MaxVersion: VersionTLS13,
9096 Bugs: ProtocolBugs{
9097 DuplicateKeyShares: true,
9098 },
9099 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009100 shouldFail: true,
9101 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009102 })
9103
9104 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009105 testType: serverTest,
9106 name: "SkipEarlyData",
9107 config: Config{
9108 MaxVersion: VersionTLS13,
9109 Bugs: ProtocolBugs{
9110 SendEarlyDataLength: 4,
9111 },
9112 },
9113 })
9114
9115 testCases = append(testCases, testCase{
9116 testType: serverTest,
9117 name: "SkipEarlyData-OmitEarlyDataExtension",
9118 config: Config{
9119 MaxVersion: VersionTLS13,
9120 Bugs: ProtocolBugs{
9121 SendEarlyDataLength: 4,
9122 OmitEarlyDataExtension: true,
9123 },
9124 },
9125 shouldFail: true,
9126 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9127 })
9128
9129 testCases = append(testCases, testCase{
9130 testType: serverTest,
9131 name: "SkipEarlyData-TooMuchData",
9132 config: Config{
9133 MaxVersion: VersionTLS13,
9134 Bugs: ProtocolBugs{
9135 SendEarlyDataLength: 16384 + 1,
9136 },
9137 },
9138 shouldFail: true,
9139 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9140 })
9141
9142 testCases = append(testCases, testCase{
9143 testType: serverTest,
9144 name: "SkipEarlyData-Interleaved",
9145 config: Config{
9146 MaxVersion: VersionTLS13,
9147 Bugs: ProtocolBugs{
9148 SendEarlyDataLength: 4,
9149 InterleaveEarlyData: true,
9150 },
9151 },
9152 shouldFail: true,
9153 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9154 })
9155
9156 testCases = append(testCases, testCase{
9157 testType: serverTest,
9158 name: "SkipEarlyData-EarlyDataInTLS12",
9159 config: Config{
9160 MaxVersion: VersionTLS13,
9161 Bugs: ProtocolBugs{
9162 SendEarlyDataLength: 4,
9163 },
9164 },
9165 shouldFail: true,
9166 expectedError: ":UNEXPECTED_RECORD:",
9167 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9168 })
9169
9170 testCases = append(testCases, testCase{
9171 testType: serverTest,
9172 name: "SkipEarlyData-HRR",
9173 config: Config{
9174 MaxVersion: VersionTLS13,
9175 Bugs: ProtocolBugs{
9176 SendEarlyDataLength: 4,
9177 },
9178 DefaultCurves: []CurveID{},
9179 },
9180 })
9181
9182 testCases = append(testCases, testCase{
9183 testType: serverTest,
9184 name: "SkipEarlyData-HRR-Interleaved",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
9187 Bugs: ProtocolBugs{
9188 SendEarlyDataLength: 4,
9189 InterleaveEarlyData: true,
9190 },
9191 DefaultCurves: []CurveID{},
9192 },
9193 shouldFail: true,
9194 expectedError: ":UNEXPECTED_RECORD:",
9195 })
9196
9197 testCases = append(testCases, testCase{
9198 testType: serverTest,
9199 name: "SkipEarlyData-HRR-TooMuchData",
9200 config: Config{
9201 MaxVersion: VersionTLS13,
9202 Bugs: ProtocolBugs{
9203 SendEarlyDataLength: 16384 + 1,
9204 },
9205 DefaultCurves: []CurveID{},
9206 },
9207 shouldFail: true,
9208 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9209 })
9210
9211 // Test that skipping early data looking for cleartext correctly
9212 // processes an alert record.
9213 testCases = append(testCases, testCase{
9214 testType: serverTest,
9215 name: "SkipEarlyData-HRR-FatalAlert",
9216 config: Config{
9217 MaxVersion: VersionTLS13,
9218 Bugs: ProtocolBugs{
9219 SendEarlyAlert: true,
9220 SendEarlyDataLength: 4,
9221 },
9222 DefaultCurves: []CurveID{},
9223 },
9224 shouldFail: true,
9225 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9226 })
9227
9228 testCases = append(testCases, testCase{
9229 testType: serverTest,
9230 name: "SkipEarlyData-SecondClientHelloEarlyData",
9231 config: Config{
9232 MaxVersion: VersionTLS13,
9233 Bugs: ProtocolBugs{
9234 SendEarlyDataOnSecondClientHello: true,
9235 },
9236 DefaultCurves: []CurveID{},
9237 },
9238 shouldFail: true,
9239 expectedLocalError: "remote error: bad record MAC",
9240 })
9241
9242 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009243 testType: clientTest,
9244 name: "EmptyEncryptedExtensions",
9245 config: Config{
9246 MaxVersion: VersionTLS13,
9247 Bugs: ProtocolBugs{
9248 EmptyEncryptedExtensions: true,
9249 },
9250 },
9251 shouldFail: true,
9252 expectedLocalError: "remote error: error decoding message",
9253 })
9254
9255 testCases = append(testCases, testCase{
9256 testType: clientTest,
9257 name: "EncryptedExtensionsWithKeyShare",
9258 config: Config{
9259 MaxVersion: VersionTLS13,
9260 Bugs: ProtocolBugs{
9261 EncryptedExtensionsWithKeyShare: true,
9262 },
9263 },
9264 shouldFail: true,
9265 expectedLocalError: "remote error: unsupported extension",
9266 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009267
9268 testCases = append(testCases, testCase{
9269 testType: serverTest,
9270 name: "SendHelloRetryRequest",
9271 config: Config{
9272 MaxVersion: VersionTLS13,
9273 // Require a HelloRetryRequest for every curve.
9274 DefaultCurves: []CurveID{},
9275 },
9276 expectedCurveID: CurveX25519,
9277 })
9278
9279 testCases = append(testCases, testCase{
9280 testType: serverTest,
9281 name: "SendHelloRetryRequest-2",
9282 config: Config{
9283 MaxVersion: VersionTLS13,
9284 DefaultCurves: []CurveID{CurveP384},
9285 },
9286 // Although the ClientHello did not predict our preferred curve,
9287 // we always select it whether it is predicted or not.
9288 expectedCurveID: CurveX25519,
9289 })
9290
9291 testCases = append(testCases, testCase{
9292 name: "UnknownCurve-HelloRetryRequest",
9293 config: Config{
9294 MaxVersion: VersionTLS13,
9295 // P-384 requires HelloRetryRequest in BoringSSL.
9296 CurvePreferences: []CurveID{CurveP384},
9297 Bugs: ProtocolBugs{
9298 SendHelloRetryRequestCurve: bogusCurve,
9299 },
9300 },
9301 shouldFail: true,
9302 expectedError: ":WRONG_CURVE:",
9303 })
9304
9305 testCases = append(testCases, testCase{
9306 name: "DisabledCurve-HelloRetryRequest",
9307 config: Config{
9308 MaxVersion: VersionTLS13,
9309 CurvePreferences: []CurveID{CurveP256},
9310 Bugs: ProtocolBugs{
9311 IgnorePeerCurvePreferences: true,
9312 },
9313 },
9314 flags: []string{"-p384-only"},
9315 shouldFail: true,
9316 expectedError: ":WRONG_CURVE:",
9317 })
9318
9319 testCases = append(testCases, testCase{
9320 name: "UnnecessaryHelloRetryRequest",
9321 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009322 MaxVersion: VersionTLS13,
9323 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009324 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009325 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009326 },
9327 },
9328 shouldFail: true,
9329 expectedError: ":WRONG_CURVE:",
9330 })
9331
9332 testCases = append(testCases, testCase{
9333 name: "SecondHelloRetryRequest",
9334 config: Config{
9335 MaxVersion: VersionTLS13,
9336 // P-384 requires HelloRetryRequest in BoringSSL.
9337 CurvePreferences: []CurveID{CurveP384},
9338 Bugs: ProtocolBugs{
9339 SecondHelloRetryRequest: true,
9340 },
9341 },
9342 shouldFail: true,
9343 expectedError: ":UNEXPECTED_MESSAGE:",
9344 })
9345
9346 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009347 name: "HelloRetryRequest-Empty",
9348 config: Config{
9349 MaxVersion: VersionTLS13,
9350 Bugs: ProtocolBugs{
9351 AlwaysSendHelloRetryRequest: true,
9352 },
9353 },
9354 shouldFail: true,
9355 expectedError: ":DECODE_ERROR:",
9356 })
9357
9358 testCases = append(testCases, testCase{
9359 name: "HelloRetryRequest-DuplicateCurve",
9360 config: Config{
9361 MaxVersion: VersionTLS13,
9362 // P-384 requires a HelloRetryRequest against BoringSSL's default
9363 // configuration. Assert this ExpectMissingKeyShare.
9364 CurvePreferences: []CurveID{CurveP384},
9365 Bugs: ProtocolBugs{
9366 ExpectMissingKeyShare: true,
9367 DuplicateHelloRetryRequestExtensions: true,
9368 },
9369 },
9370 shouldFail: true,
9371 expectedError: ":DUPLICATE_EXTENSION:",
9372 expectedLocalError: "remote error: illegal parameter",
9373 })
9374
9375 testCases = append(testCases, testCase{
9376 name: "HelloRetryRequest-Cookie",
9377 config: Config{
9378 MaxVersion: VersionTLS13,
9379 Bugs: ProtocolBugs{
9380 SendHelloRetryRequestCookie: []byte("cookie"),
9381 },
9382 },
9383 })
9384
9385 testCases = append(testCases, testCase{
9386 name: "HelloRetryRequest-DuplicateCookie",
9387 config: Config{
9388 MaxVersion: VersionTLS13,
9389 Bugs: ProtocolBugs{
9390 SendHelloRetryRequestCookie: []byte("cookie"),
9391 DuplicateHelloRetryRequestExtensions: true,
9392 },
9393 },
9394 shouldFail: true,
9395 expectedError: ":DUPLICATE_EXTENSION:",
9396 expectedLocalError: "remote error: illegal parameter",
9397 })
9398
9399 testCases = append(testCases, testCase{
9400 name: "HelloRetryRequest-EmptyCookie",
9401 config: Config{
9402 MaxVersion: VersionTLS13,
9403 Bugs: ProtocolBugs{
9404 SendHelloRetryRequestCookie: []byte{},
9405 },
9406 },
9407 shouldFail: true,
9408 expectedError: ":DECODE_ERROR:",
9409 })
9410
9411 testCases = append(testCases, testCase{
9412 name: "HelloRetryRequest-Cookie-Curve",
9413 config: Config{
9414 MaxVersion: VersionTLS13,
9415 // P-384 requires HelloRetryRequest in BoringSSL.
9416 CurvePreferences: []CurveID{CurveP384},
9417 Bugs: ProtocolBugs{
9418 SendHelloRetryRequestCookie: []byte("cookie"),
9419 ExpectMissingKeyShare: true,
9420 },
9421 },
9422 })
9423
9424 testCases = append(testCases, testCase{
9425 name: "HelloRetryRequest-Unknown",
9426 config: Config{
9427 MaxVersion: VersionTLS13,
9428 Bugs: ProtocolBugs{
9429 CustomHelloRetryRequestExtension: "extension",
9430 },
9431 },
9432 shouldFail: true,
9433 expectedError: ":UNEXPECTED_EXTENSION:",
9434 expectedLocalError: "remote error: unsupported extension",
9435 })
9436
9437 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009438 testType: serverTest,
9439 name: "SecondClientHelloMissingKeyShare",
9440 config: Config{
9441 MaxVersion: VersionTLS13,
9442 DefaultCurves: []CurveID{},
9443 Bugs: ProtocolBugs{
9444 SecondClientHelloMissingKeyShare: true,
9445 },
9446 },
9447 shouldFail: true,
9448 expectedError: ":MISSING_KEY_SHARE:",
9449 })
9450
9451 testCases = append(testCases, testCase{
9452 testType: serverTest,
9453 name: "SecondClientHelloWrongCurve",
9454 config: Config{
9455 MaxVersion: VersionTLS13,
9456 DefaultCurves: []CurveID{},
9457 Bugs: ProtocolBugs{
9458 MisinterpretHelloRetryRequestCurve: CurveP521,
9459 },
9460 },
9461 shouldFail: true,
9462 expectedError: ":WRONG_CURVE:",
9463 })
9464
9465 testCases = append(testCases, testCase{
9466 name: "HelloRetryRequestVersionMismatch",
9467 config: Config{
9468 MaxVersion: VersionTLS13,
9469 // P-384 requires HelloRetryRequest in BoringSSL.
9470 CurvePreferences: []CurveID{CurveP384},
9471 Bugs: ProtocolBugs{
9472 SendServerHelloVersion: 0x0305,
9473 },
9474 },
9475 shouldFail: true,
9476 expectedError: ":WRONG_VERSION_NUMBER:",
9477 })
9478
9479 testCases = append(testCases, testCase{
9480 name: "HelloRetryRequestCurveMismatch",
9481 config: Config{
9482 MaxVersion: VersionTLS13,
9483 // P-384 requires HelloRetryRequest in BoringSSL.
9484 CurvePreferences: []CurveID{CurveP384},
9485 Bugs: ProtocolBugs{
9486 // Send P-384 (correct) in the HelloRetryRequest.
9487 SendHelloRetryRequestCurve: CurveP384,
9488 // But send P-256 in the ServerHello.
9489 SendCurve: CurveP256,
9490 },
9491 },
9492 shouldFail: true,
9493 expectedError: ":WRONG_CURVE:",
9494 })
9495
9496 // Test the server selecting a curve that requires a HelloRetryRequest
9497 // without sending it.
9498 testCases = append(testCases, testCase{
9499 name: "SkipHelloRetryRequest",
9500 config: Config{
9501 MaxVersion: VersionTLS13,
9502 // P-384 requires HelloRetryRequest in BoringSSL.
9503 CurvePreferences: []CurveID{CurveP384},
9504 Bugs: ProtocolBugs{
9505 SkipHelloRetryRequest: true,
9506 },
9507 },
9508 shouldFail: true,
9509 expectedError: ":WRONG_CURVE:",
9510 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009511
9512 testCases = append(testCases, testCase{
9513 name: "TLS13-RequestContextInHandshake",
9514 config: Config{
9515 MaxVersion: VersionTLS13,
9516 MinVersion: VersionTLS13,
9517 ClientAuth: RequireAnyClientCert,
9518 Bugs: ProtocolBugs{
9519 SendRequestContext: []byte("request context"),
9520 },
9521 },
9522 flags: []string{
9523 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9524 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9525 },
9526 shouldFail: true,
9527 expectedError: ":DECODE_ERROR:",
9528 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009529
9530 testCases = append(testCases, testCase{
9531 testType: serverTest,
9532 name: "TLS13-TrailingKeyShareData",
9533 config: Config{
9534 MaxVersion: VersionTLS13,
9535 Bugs: ProtocolBugs{
9536 TrailingKeyShareData: true,
9537 },
9538 },
9539 shouldFail: true,
9540 expectedError: ":DECODE_ERROR:",
9541 })
David Benjamin7f78df42016-10-05 22:33:19 -04009542
9543 testCases = append(testCases, testCase{
9544 name: "TLS13-AlwaysSelectPSKIdentity",
9545 config: Config{
9546 MaxVersion: VersionTLS13,
9547 Bugs: ProtocolBugs{
9548 AlwaysSelectPSKIdentity: true,
9549 },
9550 },
9551 shouldFail: true,
9552 expectedError: ":UNEXPECTED_EXTENSION:",
9553 })
9554
9555 testCases = append(testCases, testCase{
9556 name: "TLS13-InvalidPSKIdentity",
9557 config: Config{
9558 MaxVersion: VersionTLS13,
9559 Bugs: ProtocolBugs{
9560 SelectPSKIdentityOnResume: 1,
9561 },
9562 },
9563 resumeSession: true,
9564 shouldFail: true,
9565 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9566 })
David Benjamin1286bee2016-10-07 15:25:06 -04009567
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009568 testCases = append(testCases, testCase{
9569 testType: serverTest,
9570 name: "TLS13-ExtraPSKIdentity",
9571 config: Config{
9572 MaxVersion: VersionTLS13,
9573 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009574 ExtraPSKIdentity: true,
9575 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009576 },
9577 },
9578 resumeSession: true,
9579 })
9580
David Benjamin1286bee2016-10-07 15:25:06 -04009581 // Test that unknown NewSessionTicket extensions are tolerated.
9582 testCases = append(testCases, testCase{
9583 name: "TLS13-CustomTicketExtension",
9584 config: Config{
9585 MaxVersion: VersionTLS13,
9586 Bugs: ProtocolBugs{
9587 CustomTicketExtension: "1234",
9588 },
9589 },
9590 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009591}
9592
David Benjaminabbbee12016-10-31 19:20:42 -04009593func addTLS13CipherPreferenceTests() {
9594 // Test that client preference is honored if the shim has AES hardware
9595 // and ChaCha20-Poly1305 is preferred otherwise.
9596 testCases = append(testCases, testCase{
9597 testType: serverTest,
9598 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9599 config: Config{
9600 MaxVersion: VersionTLS13,
9601 CipherSuites: []uint16{
9602 TLS_CHACHA20_POLY1305_SHA256,
9603 TLS_AES_128_GCM_SHA256,
9604 },
9605 },
9606 flags: []string{
9607 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9608 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9609 },
9610 })
9611
9612 testCases = append(testCases, testCase{
9613 testType: serverTest,
9614 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9615 config: Config{
9616 MaxVersion: VersionTLS13,
9617 CipherSuites: []uint16{
9618 TLS_AES_128_GCM_SHA256,
9619 TLS_CHACHA20_POLY1305_SHA256,
9620 },
9621 },
9622 flags: []string{
9623 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9624 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9625 },
9626 })
9627
9628 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9629 // whether it has AES hardware.
9630 testCases = append(testCases, testCase{
9631 name: "TLS13-CipherPreference-Client",
9632 config: Config{
9633 MaxVersion: VersionTLS13,
9634 // Use the client cipher order. (This is the default but
9635 // is listed to be explicit.)
9636 PreferServerCipherSuites: false,
9637 },
9638 flags: []string{
9639 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9640 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9641 },
9642 })
9643}
9644
David Benjaminf3fbade2016-09-19 13:08:16 -04009645func addPeekTests() {
9646 // Test SSL_peek works, including on empty records.
9647 testCases = append(testCases, testCase{
9648 name: "Peek-Basic",
9649 sendEmptyRecords: 1,
9650 flags: []string{"-peek-then-read"},
9651 })
9652
9653 // Test SSL_peek can drive the initial handshake.
9654 testCases = append(testCases, testCase{
9655 name: "Peek-ImplicitHandshake",
9656 flags: []string{
9657 "-peek-then-read",
9658 "-implicit-handshake",
9659 },
9660 })
9661
9662 // Test SSL_peek can discover and drive a renegotiation.
9663 testCases = append(testCases, testCase{
9664 name: "Peek-Renegotiate",
9665 config: Config{
9666 MaxVersion: VersionTLS12,
9667 },
9668 renegotiate: 1,
9669 flags: []string{
9670 "-peek-then-read",
9671 "-renegotiate-freely",
9672 "-expect-total-renegotiations", "1",
9673 },
9674 })
9675
9676 // Test SSL_peek can discover a close_notify.
9677 testCases = append(testCases, testCase{
9678 name: "Peek-Shutdown",
9679 config: Config{
9680 Bugs: ProtocolBugs{
9681 ExpectCloseNotify: true,
9682 },
9683 },
9684 flags: []string{
9685 "-peek-then-read",
9686 "-check-close-notify",
9687 },
9688 })
9689
9690 // Test SSL_peek can discover an alert.
9691 testCases = append(testCases, testCase{
9692 name: "Peek-Alert",
9693 config: Config{
9694 Bugs: ProtocolBugs{
9695 SendSpuriousAlert: alertRecordOverflow,
9696 },
9697 },
9698 flags: []string{"-peek-then-read"},
9699 shouldFail: true,
9700 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9701 })
9702
9703 // Test SSL_peek can handle KeyUpdate.
9704 testCases = append(testCases, testCase{
9705 name: "Peek-KeyUpdate",
9706 config: Config{
9707 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009708 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009709 sendKeyUpdates: 1,
9710 keyUpdateRequest: keyUpdateNotRequested,
9711 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009712 })
9713}
9714
David Benjamine6f22212016-11-08 14:28:24 -05009715func addRecordVersionTests() {
9716 for _, ver := range tlsVersions {
9717 // Test that the record version is enforced.
9718 testCases = append(testCases, testCase{
9719 name: "CheckRecordVersion-" + ver.name,
9720 config: Config{
9721 MinVersion: ver.version,
9722 MaxVersion: ver.version,
9723 Bugs: ProtocolBugs{
9724 SendRecordVersion: 0x03ff,
9725 },
9726 },
9727 shouldFail: true,
9728 expectedError: ":WRONG_VERSION_NUMBER:",
9729 })
9730
9731 // Test that the ClientHello may use any record version, for
9732 // compatibility reasons.
9733 testCases = append(testCases, testCase{
9734 testType: serverTest,
9735 name: "LooseInitialRecordVersion-" + ver.name,
9736 config: Config{
9737 MinVersion: ver.version,
9738 MaxVersion: ver.version,
9739 Bugs: ProtocolBugs{
9740 SendInitialRecordVersion: 0x03ff,
9741 },
9742 },
9743 })
9744
9745 // Test that garbage ClientHello record versions are rejected.
9746 testCases = append(testCases, testCase{
9747 testType: serverTest,
9748 name: "GarbageInitialRecordVersion-" + ver.name,
9749 config: Config{
9750 MinVersion: ver.version,
9751 MaxVersion: ver.version,
9752 Bugs: ProtocolBugs{
9753 SendInitialRecordVersion: 0xffff,
9754 },
9755 },
9756 shouldFail: true,
9757 expectedError: ":WRONG_VERSION_NUMBER:",
9758 })
9759 }
9760}
9761
David Benjamin2c516452016-11-15 10:16:54 +09009762func addCertificateTests() {
9763 // Test that a certificate chain with intermediate may be sent and
9764 // received as both client and server.
9765 for _, ver := range tlsVersions {
9766 testCases = append(testCases, testCase{
9767 testType: clientTest,
9768 name: "SendReceiveIntermediate-Client-" + ver.name,
9769 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009770 MinVersion: ver.version,
9771 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009772 Certificates: []Certificate{rsaChainCertificate},
9773 ClientAuth: RequireAnyClientCert,
9774 },
9775 expectPeerCertificate: &rsaChainCertificate,
9776 flags: []string{
9777 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9778 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9779 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9780 },
9781 })
9782
9783 testCases = append(testCases, testCase{
9784 testType: serverTest,
9785 name: "SendReceiveIntermediate-Server-" + ver.name,
9786 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009787 MinVersion: ver.version,
9788 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009789 Certificates: []Certificate{rsaChainCertificate},
9790 },
9791 expectPeerCertificate: &rsaChainCertificate,
9792 flags: []string{
9793 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9794 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9795 "-require-any-client-certificate",
9796 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9797 },
9798 })
9799 }
9800}
9801
David Benjaminbbaf3672016-11-17 10:53:09 +09009802func addRetainOnlySHA256ClientCertTests() {
9803 for _, ver := range tlsVersions {
9804 // Test that enabling
9805 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9806 // actually requesting a client certificate is a no-op.
9807 testCases = append(testCases, testCase{
9808 testType: serverTest,
9809 name: "RetainOnlySHA256-NoCert-" + ver.name,
9810 config: Config{
9811 MinVersion: ver.version,
9812 MaxVersion: ver.version,
9813 },
9814 flags: []string{
9815 "-retain-only-sha256-client-cert-initial",
9816 "-retain-only-sha256-client-cert-resume",
9817 },
9818 resumeSession: true,
9819 })
9820
9821 // Test that when retaining only a SHA-256 certificate is
9822 // enabled, the hash appears as expected.
9823 testCases = append(testCases, testCase{
9824 testType: serverTest,
9825 name: "RetainOnlySHA256-Cert-" + ver.name,
9826 config: Config{
9827 MinVersion: ver.version,
9828 MaxVersion: ver.version,
9829 Certificates: []Certificate{rsaCertificate},
9830 },
9831 flags: []string{
9832 "-verify-peer",
9833 "-retain-only-sha256-client-cert-initial",
9834 "-retain-only-sha256-client-cert-resume",
9835 "-expect-sha256-client-cert-initial",
9836 "-expect-sha256-client-cert-resume",
9837 },
9838 resumeSession: true,
9839 })
9840
9841 // Test that when the config changes from on to off, a
9842 // resumption is rejected because the server now wants the full
9843 // certificate chain.
9844 testCases = append(testCases, testCase{
9845 testType: serverTest,
9846 name: "RetainOnlySHA256-OnOff-" + ver.name,
9847 config: Config{
9848 MinVersion: ver.version,
9849 MaxVersion: ver.version,
9850 Certificates: []Certificate{rsaCertificate},
9851 },
9852 flags: []string{
9853 "-verify-peer",
9854 "-retain-only-sha256-client-cert-initial",
9855 "-expect-sha256-client-cert-initial",
9856 },
9857 resumeSession: true,
9858 expectResumeRejected: true,
9859 })
9860
9861 // Test that when the config changes from off to on, a
9862 // resumption is rejected because the server now wants just the
9863 // hash.
9864 testCases = append(testCases, testCase{
9865 testType: serverTest,
9866 name: "RetainOnlySHA256-OffOn-" + ver.name,
9867 config: Config{
9868 MinVersion: ver.version,
9869 MaxVersion: ver.version,
9870 Certificates: []Certificate{rsaCertificate},
9871 },
9872 flags: []string{
9873 "-verify-peer",
9874 "-retain-only-sha256-client-cert-resume",
9875 "-expect-sha256-client-cert-resume",
9876 },
9877 resumeSession: true,
9878 expectResumeRejected: true,
9879 })
9880 }
9881}
9882
Adam Langleya4b91982016-12-12 12:05:53 -08009883func addECDSAKeyUsageTests() {
9884 p256 := elliptic.P256()
9885 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
9886 if err != nil {
9887 panic(err)
9888 }
9889
9890 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
9891 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
9892 if err != nil {
9893 panic(err)
9894 }
9895
9896 template := x509.Certificate{
9897 SerialNumber: serialNumber,
9898 Subject: pkix.Name{
9899 Organization: []string{"Acme Co"},
9900 },
9901 NotBefore: time.Now(),
9902 NotAfter: time.Now(),
9903
9904 // An ECC certificate with only the keyAgreement key usgae may
9905 // be used with ECDH, but not ECDSA.
9906 KeyUsage: x509.KeyUsageKeyAgreement,
9907 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
9908 BasicConstraintsValid: true,
9909 }
9910
9911 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
9912 if err != nil {
9913 panic(err)
9914 }
9915
9916 cert := Certificate{
9917 Certificate: [][]byte{derBytes},
9918 PrivateKey: priv,
9919 }
9920
9921 for _, ver := range tlsVersions {
9922 if ver.version < VersionTLS12 {
9923 continue
9924 }
9925
9926 testCases = append(testCases, testCase{
9927 testType: clientTest,
9928 name: "ECDSAKeyUsage-" + ver.name,
9929 config: Config{
9930 MinVersion: ver.version,
9931 MaxVersion: ver.version,
9932 Certificates: []Certificate{cert},
9933 },
9934 shouldFail: true,
9935 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
9936 })
9937 }
9938}
9939
David Benjamin6f600d62016-12-21 16:06:54 -05009940func addShortHeaderTests() {
9941 // The short header extension may be negotiated as either client or
9942 // server.
9943 testCases = append(testCases, testCase{
9944 name: "ShortHeader-Client",
9945 config: Config{
9946 MaxVersion: VersionTLS13,
9947 Bugs: ProtocolBugs{
9948 EnableShortHeader: true,
9949 },
9950 },
9951 flags: []string{"-enable-short-header"},
9952 expectShortHeader: true,
9953 })
9954 testCases = append(testCases, testCase{
9955 testType: serverTest,
9956 name: "ShortHeader-Server",
9957 config: Config{
9958 MaxVersion: VersionTLS13,
9959 Bugs: ProtocolBugs{
9960 EnableShortHeader: true,
9961 },
9962 },
9963 flags: []string{"-enable-short-header"},
9964 expectShortHeader: true,
9965 })
9966
9967 // If the peer doesn't support it, it will not be negotiated.
9968 testCases = append(testCases, testCase{
9969 name: "ShortHeader-No-Yes-Client",
9970 config: Config{
9971 MaxVersion: VersionTLS13,
9972 },
9973 flags: []string{"-enable-short-header"},
9974 })
9975 testCases = append(testCases, testCase{
9976 testType: serverTest,
9977 name: "ShortHeader-No-Yes-Server",
9978 config: Config{
9979 MaxVersion: VersionTLS13,
9980 },
9981 flags: []string{"-enable-short-header"},
9982 })
9983
9984 // If we don't support it, it will not be negotiated.
9985 testCases = append(testCases, testCase{
9986 name: "ShortHeader-Yes-No-Client",
9987 config: Config{
9988 MaxVersion: VersionTLS13,
9989 Bugs: ProtocolBugs{
9990 EnableShortHeader: true,
9991 },
9992 },
9993 })
9994 testCases = append(testCases, testCase{
9995 testType: serverTest,
9996 name: "ShortHeader-Yes-No-Server",
9997 config: Config{
9998 MaxVersion: VersionTLS13,
9999 Bugs: ProtocolBugs{
10000 EnableShortHeader: true,
10001 },
10002 },
10003 })
10004
10005 // It will not be negotiated at TLS 1.2.
10006 testCases = append(testCases, testCase{
10007 name: "ShortHeader-TLS12-Client",
10008 config: Config{
10009 MaxVersion: VersionTLS12,
10010 Bugs: ProtocolBugs{
10011 EnableShortHeader: true,
10012 },
10013 },
10014 flags: []string{"-enable-short-header"},
10015 })
10016 testCases = append(testCases, testCase{
10017 testType: serverTest,
10018 name: "ShortHeader-TLS12-Server",
10019 config: Config{
10020 MaxVersion: VersionTLS12,
10021 Bugs: ProtocolBugs{
10022 EnableShortHeader: true,
10023 },
10024 },
10025 flags: []string{"-enable-short-header"},
10026 })
10027
10028 // Servers reject early data and short header sent together.
10029 testCases = append(testCases, testCase{
10030 testType: serverTest,
10031 name: "ShortHeader-EarlyData",
10032 config: Config{
10033 MaxVersion: VersionTLS13,
10034 Bugs: ProtocolBugs{
10035 EnableShortHeader: true,
10036 SendEarlyDataLength: 1,
10037 },
10038 },
10039 flags: []string{"-enable-short-header"},
10040 shouldFail: true,
10041 expectedError: ":UNEXPECTED_EXTENSION:",
10042 })
10043
10044 // Clients reject unsolicited short header extensions.
10045 testCases = append(testCases, testCase{
10046 name: "ShortHeader-Unsolicited",
10047 config: Config{
10048 MaxVersion: VersionTLS13,
10049 Bugs: ProtocolBugs{
10050 AlwaysNegotiateShortHeader: true,
10051 },
10052 },
10053 shouldFail: true,
10054 expectedError: ":UNEXPECTED_EXTENSION:",
10055 })
10056 testCases = append(testCases, testCase{
10057 name: "ShortHeader-Unsolicited-TLS12",
10058 config: Config{
10059 MaxVersion: VersionTLS12,
10060 Bugs: ProtocolBugs{
10061 AlwaysNegotiateShortHeader: true,
10062 },
10063 },
10064 shouldFail: true,
10065 expectedError: ":UNEXPECTED_EXTENSION:",
10066 })
10067
10068 // The high bit must be checked in short headers.
10069 testCases = append(testCases, testCase{
10070 name: "ShortHeader-ClearShortHeaderBit",
10071 config: Config{
10072 Bugs: ProtocolBugs{
10073 EnableShortHeader: true,
10074 ClearShortHeaderBit: true,
10075 },
10076 },
10077 flags: []string{"-enable-short-header"},
10078 shouldFail: true,
10079 expectedError: ":DECODE_ERROR:",
10080 expectedLocalError: "remote error: error decoding message",
10081 })
10082}
10083
Adam Langley7c803a62015-06-15 15:35:05 -070010084func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010085 defer wg.Done()
10086
10087 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010088 var err error
10089
David Benjaminba28dfc2016-11-15 17:47:21 +090010090 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010091 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10092 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010093 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010094 if err != nil {
10095 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10096 }
10097 break
10098 }
10099 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010100 } else if *repeatUntilFailure {
10101 for err == nil {
10102 statusChan <- statusMsg{test: test, started: true}
10103 err = runTest(test, shimPath, -1)
10104 }
10105 } else {
10106 statusChan <- statusMsg{test: test, started: true}
10107 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010108 }
Adam Langley95c29f32014-06-20 12:00:00 -070010109 statusChan <- statusMsg{test: test, err: err}
10110 }
10111}
10112
10113type statusMsg struct {
10114 test *testCase
10115 started bool
10116 err error
10117}
10118
David Benjamin5f237bc2015-02-11 17:14:15 -050010119func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010120 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010121
David Benjamin5f237bc2015-02-11 17:14:15 -050010122 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010123 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010124 if !*pipe {
10125 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010126 var erase string
10127 for i := 0; i < lineLen; i++ {
10128 erase += "\b \b"
10129 }
10130 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010131 }
10132
Adam Langley95c29f32014-06-20 12:00:00 -070010133 if msg.started {
10134 started++
10135 } else {
10136 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010137
10138 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010139 if msg.err == errUnimplemented {
10140 if *pipe {
10141 // Print each test instead of a status line.
10142 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10143 }
10144 unimplemented++
10145 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10146 } else {
10147 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10148 failed++
10149 testOutput.addResult(msg.test.name, "FAIL")
10150 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010151 } else {
10152 if *pipe {
10153 // Print each test instead of a status line.
10154 fmt.Printf("PASSED (%s)\n", msg.test.name)
10155 }
10156 testOutput.addResult(msg.test.name, "PASS")
10157 }
Adam Langley95c29f32014-06-20 12:00:00 -070010158 }
10159
David Benjamin5f237bc2015-02-11 17:14:15 -050010160 if !*pipe {
10161 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010162 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010163 lineLen = len(line)
10164 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010165 }
Adam Langley95c29f32014-06-20 12:00:00 -070010166 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010167
10168 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010169}
10170
10171func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010172 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010173 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010174 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010175
Adam Langley7c803a62015-06-15 15:35:05 -070010176 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010177 addCipherSuiteTests()
10178 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010179 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010180 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010181 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010182 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010183 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010184 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010185 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010186 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010187 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010188 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010189 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010190 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010191 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010192 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010193 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010194 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010195 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010196 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010197 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010198 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010199 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010200 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010201 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010202 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010203 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010204 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010205 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010206 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010207 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010208 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010209 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010210 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010211
10212 var wg sync.WaitGroup
10213
Adam Langley7c803a62015-06-15 15:35:05 -070010214 statusChan := make(chan statusMsg, *numWorkers)
10215 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010216 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010217
EKRf71d7ed2016-08-06 13:25:12 -070010218 if len(*shimConfigFile) != 0 {
10219 encoded, err := ioutil.ReadFile(*shimConfigFile)
10220 if err != nil {
10221 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10222 os.Exit(1)
10223 }
10224
10225 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10226 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10227 os.Exit(1)
10228 }
10229 }
10230
David Benjamin025b3d32014-07-01 19:53:04 -040010231 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010232
Adam Langley7c803a62015-06-15 15:35:05 -070010233 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010234 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010235 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010236 }
10237
David Benjamin270f0a72016-03-17 14:41:36 -040010238 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010239 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010240 matched := true
10241 if len(*testToRun) != 0 {
10242 var err error
10243 matched, err = filepath.Match(*testToRun, testCases[i].name)
10244 if err != nil {
10245 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10246 os.Exit(1)
10247 }
10248 }
10249
EKRf71d7ed2016-08-06 13:25:12 -070010250 if !*includeDisabled {
10251 for pattern := range shimConfig.DisabledTests {
10252 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10253 if err != nil {
10254 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10255 os.Exit(1)
10256 }
10257
10258 if isDisabled {
10259 matched = false
10260 break
10261 }
10262 }
10263 }
10264
David Benjamin17e12922016-07-28 18:04:43 -040010265 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010266 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010267 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010268
10269 // Only run one test if repeating until failure.
10270 if *repeatUntilFailure {
10271 break
10272 }
Adam Langley95c29f32014-06-20 12:00:00 -070010273 }
10274 }
David Benjamin17e12922016-07-28 18:04:43 -040010275
David Benjamin270f0a72016-03-17 14:41:36 -040010276 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010277 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010278 os.Exit(1)
10279 }
Adam Langley95c29f32014-06-20 12:00:00 -070010280
10281 close(testChan)
10282 wg.Wait()
10283 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010284 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010285
10286 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010287
10288 if *jsonOutput != "" {
10289 if err := testOutput.writeTo(*jsonOutput); err != nil {
10290 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10291 }
10292 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010293
EKR842ae6c2016-07-27 09:22:05 +020010294 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10295 os.Exit(1)
10296 }
10297
10298 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010299 os.Exit(1)
10300 }
Adam Langley95c29f32014-06-20 12:00:00 -070010301}