blob: 502e86e3de297b77a1e4f77fb3bbe01b07f253a5 [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 Benjamin397c8e62016-07-08 14:14:36 -07006265 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006266 testCases = append(testCases, testCase{
6267 name: "StrayHelloRequest",
6268 config: Config{
6269 MaxVersion: VersionTLS12,
6270 Bugs: ProtocolBugs{
6271 SendHelloRequestBeforeEveryHandshakeMessage: true,
6272 },
6273 },
6274 })
6275 testCases = append(testCases, testCase{
6276 name: "StrayHelloRequest-Packed",
6277 config: Config{
6278 MaxVersion: VersionTLS12,
6279 Bugs: ProtocolBugs{
6280 PackHandshakeFlight: true,
6281 SendHelloRequestBeforeEveryHandshakeMessage: true,
6282 },
6283 },
6284 })
6285
David Benjamin12d2c482016-07-24 10:56:51 -04006286 // Test renegotiation works if HelloRequest and server Finished come in
6287 // the same record.
6288 testCases = append(testCases, testCase{
6289 name: "Renegotiate-Client-Packed",
6290 config: Config{
6291 MaxVersion: VersionTLS12,
6292 Bugs: ProtocolBugs{
6293 PackHandshakeFlight: true,
6294 PackHelloRequestWithFinished: true,
6295 },
6296 },
6297 renegotiate: 1,
6298 flags: []string{
6299 "-renegotiate-freely",
6300 "-expect-total-renegotiations", "1",
6301 },
6302 })
6303
David Benjamin397c8e62016-07-08 14:14:36 -07006304 // Renegotiation is forbidden in TLS 1.3.
6305 testCases = append(testCases, testCase{
6306 name: "Renegotiate-Client-TLS13",
6307 config: Config{
6308 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006309 Bugs: ProtocolBugs{
6310 SendHelloRequestBeforeEveryAppDataRecord: true,
6311 },
David Benjamin397c8e62016-07-08 14:14:36 -07006312 },
David Benjamin397c8e62016-07-08 14:14:36 -07006313 flags: []string{
6314 "-renegotiate-freely",
6315 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006316 shouldFail: true,
6317 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006318 })
6319
6320 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6321 testCases = append(testCases, testCase{
6322 name: "StrayHelloRequest-TLS13",
6323 config: Config{
6324 MaxVersion: VersionTLS13,
6325 Bugs: ProtocolBugs{
6326 SendHelloRequestBeforeEveryHandshakeMessage: true,
6327 },
6328 },
6329 shouldFail: true,
6330 expectedError: ":UNEXPECTED_MESSAGE:",
6331 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006332}
6333
David Benjamin5e961c12014-11-07 01:48:35 -05006334func addDTLSReplayTests() {
6335 // Test that sequence number replays are detected.
6336 testCases = append(testCases, testCase{
6337 protocol: dtls,
6338 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006339 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006340 replayWrites: true,
6341 })
6342
David Benjamin8e6db492015-07-25 18:29:23 -04006343 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006344 // than the retransmit window.
6345 testCases = append(testCases, testCase{
6346 protocol: dtls,
6347 name: "DTLS-Replay-LargeGaps",
6348 config: Config{
6349 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006350 SequenceNumberMapping: func(in uint64) uint64 {
6351 return in * 127
6352 },
David Benjamin5e961c12014-11-07 01:48:35 -05006353 },
6354 },
David Benjamin8e6db492015-07-25 18:29:23 -04006355 messageCount: 200,
6356 replayWrites: true,
6357 })
6358
6359 // Test the incoming sequence number changing non-monotonically.
6360 testCases = append(testCases, testCase{
6361 protocol: dtls,
6362 name: "DTLS-Replay-NonMonotonic",
6363 config: Config{
6364 Bugs: ProtocolBugs{
6365 SequenceNumberMapping: func(in uint64) uint64 {
6366 return in ^ 31
6367 },
6368 },
6369 },
6370 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006371 replayWrites: true,
6372 })
6373}
6374
Nick Harper60edffd2016-06-21 15:19:24 -07006375var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006376 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006377 id signatureAlgorithm
6378 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006379}{
Nick Harper60edffd2016-06-21 15:19:24 -07006380 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6381 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6382 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6383 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006384 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006385 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6386 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6387 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006388 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6389 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6390 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006391 // Tests for key types prior to TLS 1.2.
6392 {"RSA", 0, testCertRSA},
6393 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006394}
6395
Nick Harper60edffd2016-06-21 15:19:24 -07006396const fakeSigAlg1 signatureAlgorithm = 0x2a01
6397const fakeSigAlg2 signatureAlgorithm = 0xff01
6398
6399func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006400 // Not all ciphers involve a signature. Advertise a list which gives all
6401 // versions a signing cipher.
6402 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006403 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006404 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6405 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6406 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6407 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6408 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6409 }
6410
David Benjaminca3d5452016-07-14 12:51:01 -04006411 var allAlgorithms []signatureAlgorithm
6412 for _, alg := range testSignatureAlgorithms {
6413 if alg.id != 0 {
6414 allAlgorithms = append(allAlgorithms, alg.id)
6415 }
6416 }
6417
Nick Harper60edffd2016-06-21 15:19:24 -07006418 // Make sure each signature algorithm works. Include some fake values in
6419 // the list and ensure they're ignored.
6420 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006421 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006422 if (ver.version < VersionTLS12) != (alg.id == 0) {
6423 continue
6424 }
6425
6426 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6427 // or remove it in C.
6428 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006429 continue
6430 }
Nick Harper60edffd2016-06-21 15:19:24 -07006431
David Benjamin3ef76972016-10-17 17:59:54 -04006432 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006433 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006434 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006435 shouldSignFail = true
6436 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006437 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006438 // RSA-PKCS1 does not exist in TLS 1.3.
6439 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006440 shouldSignFail = true
6441 shouldVerifyFail = true
6442 }
6443
6444 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6445 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6446 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006447 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006448
6449 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006450 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006451 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006452 }
6453 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006454 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006455 }
David Benjamin000800a2014-11-14 01:43:59 -05006456
David Benjamin1fb125c2016-07-08 18:52:12 -07006457 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006458
David Benjamin7a41d372016-07-09 11:21:54 -07006459 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006460 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006461 config: Config{
6462 MaxVersion: ver.version,
6463 ClientAuth: RequireAnyClientCert,
6464 VerifySignatureAlgorithms: []signatureAlgorithm{
6465 fakeSigAlg1,
6466 alg.id,
6467 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006468 },
David Benjamin7a41d372016-07-09 11:21:54 -07006469 },
6470 flags: []string{
6471 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6472 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6473 "-enable-all-curves",
6474 },
David Benjamin3ef76972016-10-17 17:59:54 -04006475 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006476 expectedError: signError,
6477 expectedPeerSignatureAlgorithm: alg.id,
6478 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006479
David Benjamin7a41d372016-07-09 11:21:54 -07006480 testCases = append(testCases, testCase{
6481 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006482 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006483 config: Config{
6484 MaxVersion: ver.version,
6485 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6486 SignSignatureAlgorithms: []signatureAlgorithm{
6487 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006488 },
David Benjamin7a41d372016-07-09 11:21:54 -07006489 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006490 SkipECDSACurveCheck: shouldVerifyFail,
6491 IgnoreSignatureVersionChecks: shouldVerifyFail,
6492 // Some signature algorithms may not be advertised.
6493 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006494 },
David Benjamin7a41d372016-07-09 11:21:54 -07006495 },
6496 flags: []string{
6497 "-require-any-client-certificate",
6498 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6499 "-enable-all-curves",
6500 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006501 // Resume the session to assert the peer signature
6502 // algorithm is reported on both handshakes.
6503 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006504 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006505 expectedError: verifyError,
6506 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006507
6508 testCases = append(testCases, testCase{
6509 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006510 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006511 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006512 MaxVersion: ver.version,
6513 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006514 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006515 fakeSigAlg1,
6516 alg.id,
6517 fakeSigAlg2,
6518 },
6519 },
6520 flags: []string{
6521 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6522 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6523 "-enable-all-curves",
6524 },
David Benjamin3ef76972016-10-17 17:59:54 -04006525 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006526 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006527 expectedPeerSignatureAlgorithm: alg.id,
6528 })
6529
6530 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006531 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006532 config: Config{
6533 MaxVersion: ver.version,
6534 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006535 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006536 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006537 alg.id,
6538 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006539 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006540 SkipECDSACurveCheck: shouldVerifyFail,
6541 IgnoreSignatureVersionChecks: shouldVerifyFail,
6542 // Some signature algorithms may not be advertised.
6543 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006544 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006545 },
6546 flags: []string{
6547 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6548 "-enable-all-curves",
6549 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006550 // Resume the session to assert the peer signature
6551 // algorithm is reported on both handshakes.
6552 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006553 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006554 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006555 })
David Benjamin5208fd42016-07-13 21:43:25 -04006556
David Benjamin3ef76972016-10-17 17:59:54 -04006557 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006558 testCases = append(testCases, testCase{
6559 testType: serverTest,
6560 name: "ClientAuth-InvalidSignature" + suffix,
6561 config: Config{
6562 MaxVersion: ver.version,
6563 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6564 SignSignatureAlgorithms: []signatureAlgorithm{
6565 alg.id,
6566 },
6567 Bugs: ProtocolBugs{
6568 InvalidSignature: true,
6569 },
6570 },
6571 flags: []string{
6572 "-require-any-client-certificate",
6573 "-enable-all-curves",
6574 },
6575 shouldFail: true,
6576 expectedError: ":BAD_SIGNATURE:",
6577 })
6578
6579 testCases = append(testCases, testCase{
6580 name: "ServerAuth-InvalidSignature" + suffix,
6581 config: Config{
6582 MaxVersion: ver.version,
6583 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6584 CipherSuites: signingCiphers,
6585 SignSignatureAlgorithms: []signatureAlgorithm{
6586 alg.id,
6587 },
6588 Bugs: ProtocolBugs{
6589 InvalidSignature: true,
6590 },
6591 },
6592 flags: []string{"-enable-all-curves"},
6593 shouldFail: true,
6594 expectedError: ":BAD_SIGNATURE:",
6595 })
6596 }
David Benjaminca3d5452016-07-14 12:51:01 -04006597
David Benjamin3ef76972016-10-17 17:59:54 -04006598 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006599 testCases = append(testCases, testCase{
6600 name: "ClientAuth-Sign-Negotiate" + suffix,
6601 config: Config{
6602 MaxVersion: ver.version,
6603 ClientAuth: RequireAnyClientCert,
6604 VerifySignatureAlgorithms: allAlgorithms,
6605 },
6606 flags: []string{
6607 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6608 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6609 "-enable-all-curves",
6610 "-signing-prefs", strconv.Itoa(int(alg.id)),
6611 },
6612 expectedPeerSignatureAlgorithm: alg.id,
6613 })
6614
6615 testCases = append(testCases, testCase{
6616 testType: serverTest,
6617 name: "ServerAuth-Sign-Negotiate" + suffix,
6618 config: Config{
6619 MaxVersion: ver.version,
6620 CipherSuites: signingCiphers,
6621 VerifySignatureAlgorithms: allAlgorithms,
6622 },
6623 flags: []string{
6624 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6625 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6626 "-enable-all-curves",
6627 "-signing-prefs", strconv.Itoa(int(alg.id)),
6628 },
6629 expectedPeerSignatureAlgorithm: alg.id,
6630 })
6631 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006632 }
David Benjamin000800a2014-11-14 01:43:59 -05006633 }
6634
Nick Harper60edffd2016-06-21 15:19:24 -07006635 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006636 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006637 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006638 config: Config{
6639 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006640 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006641 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006642 signatureECDSAWithP521AndSHA512,
6643 signatureRSAPKCS1WithSHA384,
6644 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006645 },
6646 },
6647 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006648 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6649 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006650 },
Nick Harper60edffd2016-06-21 15:19:24 -07006651 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006652 })
6653
6654 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006655 name: "ClientAuth-SignatureType-TLS13",
6656 config: Config{
6657 ClientAuth: RequireAnyClientCert,
6658 MaxVersion: VersionTLS13,
6659 VerifySignatureAlgorithms: []signatureAlgorithm{
6660 signatureECDSAWithP521AndSHA512,
6661 signatureRSAPKCS1WithSHA384,
6662 signatureRSAPSSWithSHA384,
6663 signatureECDSAWithSHA1,
6664 },
6665 },
6666 flags: []string{
6667 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6668 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6669 },
6670 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6671 })
6672
6673 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006674 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006675 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006676 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006677 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006678 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006679 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006680 signatureECDSAWithP521AndSHA512,
6681 signatureRSAPKCS1WithSHA384,
6682 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006683 },
6684 },
Nick Harper60edffd2016-06-21 15:19:24 -07006685 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006686 })
6687
Steven Valdez143e8b32016-07-11 13:19:03 -04006688 testCases = append(testCases, testCase{
6689 testType: serverTest,
6690 name: "ServerAuth-SignatureType-TLS13",
6691 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006692 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006693 VerifySignatureAlgorithms: []signatureAlgorithm{
6694 signatureECDSAWithP521AndSHA512,
6695 signatureRSAPKCS1WithSHA384,
6696 signatureRSAPSSWithSHA384,
6697 signatureECDSAWithSHA1,
6698 },
6699 },
6700 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6701 })
6702
David Benjamina95e9f32016-07-08 16:28:04 -07006703 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006704 testCases = append(testCases, testCase{
6705 testType: serverTest,
6706 name: "Verify-ClientAuth-SignatureType",
6707 config: Config{
6708 MaxVersion: VersionTLS12,
6709 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006710 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006711 signatureRSAPKCS1WithSHA256,
6712 },
6713 Bugs: ProtocolBugs{
6714 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6715 },
6716 },
6717 flags: []string{
6718 "-require-any-client-certificate",
6719 },
6720 shouldFail: true,
6721 expectedError: ":WRONG_SIGNATURE_TYPE:",
6722 })
6723
6724 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006725 testType: serverTest,
6726 name: "Verify-ClientAuth-SignatureType-TLS13",
6727 config: Config{
6728 MaxVersion: VersionTLS13,
6729 Certificates: []Certificate{rsaCertificate},
6730 SignSignatureAlgorithms: []signatureAlgorithm{
6731 signatureRSAPSSWithSHA256,
6732 },
6733 Bugs: ProtocolBugs{
6734 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6735 },
6736 },
6737 flags: []string{
6738 "-require-any-client-certificate",
6739 },
6740 shouldFail: true,
6741 expectedError: ":WRONG_SIGNATURE_TYPE:",
6742 })
6743
6744 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006745 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006746 config: Config{
6747 MaxVersion: VersionTLS12,
6748 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006749 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006750 signatureRSAPKCS1WithSHA256,
6751 },
6752 Bugs: ProtocolBugs{
6753 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6754 },
6755 },
6756 shouldFail: true,
6757 expectedError: ":WRONG_SIGNATURE_TYPE:",
6758 })
6759
Steven Valdez143e8b32016-07-11 13:19:03 -04006760 testCases = append(testCases, testCase{
6761 name: "Verify-ServerAuth-SignatureType-TLS13",
6762 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006763 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006764 SignSignatureAlgorithms: []signatureAlgorithm{
6765 signatureRSAPSSWithSHA256,
6766 },
6767 Bugs: ProtocolBugs{
6768 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6769 },
6770 },
6771 shouldFail: true,
6772 expectedError: ":WRONG_SIGNATURE_TYPE:",
6773 })
6774
David Benjamin51dd7d62016-07-08 16:07:01 -07006775 // Test that, if the list is missing, the peer falls back to SHA-1 in
6776 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006777 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006778 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006779 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006780 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006781 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006782 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006783 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006784 },
6785 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006786 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006787 },
6788 },
6789 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006790 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6791 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006792 },
6793 })
6794
6795 testCases = append(testCases, testCase{
6796 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006797 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006798 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006799 MaxVersion: VersionTLS12,
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 },
David Benjaminee32bea2016-08-17 13:36:44 -04006807 flags: []string{
6808 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6809 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6810 },
6811 })
6812
6813 testCases = append(testCases, testCase{
6814 name: "ClientAuth-SHA1-Fallback-ECDSA",
6815 config: Config{
6816 MaxVersion: VersionTLS12,
6817 ClientAuth: RequireAnyClientCert,
6818 VerifySignatureAlgorithms: []signatureAlgorithm{
6819 signatureECDSAWithSHA1,
6820 },
6821 Bugs: ProtocolBugs{
6822 NoSignatureAlgorithms: true,
6823 },
6824 },
6825 flags: []string{
6826 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6827 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6828 },
6829 })
6830
6831 testCases = append(testCases, testCase{
6832 testType: serverTest,
6833 name: "ServerAuth-SHA1-Fallback-ECDSA",
6834 config: Config{
6835 MaxVersion: VersionTLS12,
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 },
David Benjamin000800a2014-11-14 01:43:59 -05006847 })
David Benjamin72dc7832015-03-16 17:49:43 -04006848
David Benjamin51dd7d62016-07-08 16:07:01 -07006849 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006850 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006851 config: Config{
6852 MaxVersion: VersionTLS13,
6853 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006854 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006855 signatureRSAPKCS1WithSHA1,
6856 },
6857 Bugs: ProtocolBugs{
6858 NoSignatureAlgorithms: true,
6859 },
6860 },
6861 flags: []string{
6862 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6863 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6864 },
David Benjamin48901652016-08-01 12:12:47 -04006865 shouldFail: true,
6866 // An empty CertificateRequest signature algorithm list is a
6867 // syntax error in TLS 1.3.
6868 expectedError: ":DECODE_ERROR:",
6869 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006870 })
6871
6872 testCases = append(testCases, testCase{
6873 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006874 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006875 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006876 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006877 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006878 signatureRSAPKCS1WithSHA1,
6879 },
6880 Bugs: ProtocolBugs{
6881 NoSignatureAlgorithms: true,
6882 },
6883 },
6884 shouldFail: true,
6885 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6886 })
6887
David Benjaminb62d2872016-07-18 14:55:02 +02006888 // Test that hash preferences are enforced. BoringSSL does not implement
6889 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006890 testCases = append(testCases, testCase{
6891 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006892 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006893 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006894 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006895 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006896 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006897 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006898 },
6899 Bugs: ProtocolBugs{
6900 IgnorePeerSignatureAlgorithmPreferences: true,
6901 },
6902 },
6903 flags: []string{"-require-any-client-certificate"},
6904 shouldFail: true,
6905 expectedError: ":WRONG_SIGNATURE_TYPE:",
6906 })
6907
6908 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006909 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006911 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006913 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006914 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006915 },
6916 Bugs: ProtocolBugs{
6917 IgnorePeerSignatureAlgorithmPreferences: true,
6918 },
6919 },
6920 shouldFail: true,
6921 expectedError: ":WRONG_SIGNATURE_TYPE:",
6922 })
David Benjaminb62d2872016-07-18 14:55:02 +02006923 testCases = append(testCases, testCase{
6924 testType: serverTest,
6925 name: "ClientAuth-Enforced-TLS13",
6926 config: Config{
6927 MaxVersion: VersionTLS13,
6928 Certificates: []Certificate{rsaCertificate},
6929 SignSignatureAlgorithms: []signatureAlgorithm{
6930 signatureRSAPKCS1WithMD5,
6931 },
6932 Bugs: ProtocolBugs{
6933 IgnorePeerSignatureAlgorithmPreferences: true,
6934 IgnoreSignatureVersionChecks: true,
6935 },
6936 },
6937 flags: []string{"-require-any-client-certificate"},
6938 shouldFail: true,
6939 expectedError: ":WRONG_SIGNATURE_TYPE:",
6940 })
6941
6942 testCases = append(testCases, testCase{
6943 name: "ServerAuth-Enforced-TLS13",
6944 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006945 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006946 SignSignatureAlgorithms: []signatureAlgorithm{
6947 signatureRSAPKCS1WithMD5,
6948 },
6949 Bugs: ProtocolBugs{
6950 IgnorePeerSignatureAlgorithmPreferences: true,
6951 IgnoreSignatureVersionChecks: true,
6952 },
6953 },
6954 shouldFail: true,
6955 expectedError: ":WRONG_SIGNATURE_TYPE:",
6956 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006957
6958 // Test that the agreed upon digest respects the client preferences and
6959 // the server digests.
6960 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006961 name: "NoCommonAlgorithms-Digests",
6962 config: Config{
6963 MaxVersion: VersionTLS12,
6964 ClientAuth: RequireAnyClientCert,
6965 VerifySignatureAlgorithms: []signatureAlgorithm{
6966 signatureRSAPKCS1WithSHA512,
6967 signatureRSAPKCS1WithSHA1,
6968 },
6969 },
6970 flags: []string{
6971 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6972 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6973 "-digest-prefs", "SHA256",
6974 },
6975 shouldFail: true,
6976 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6977 })
6978 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006979 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006980 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006981 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006982 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006983 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006984 signatureRSAPKCS1WithSHA512,
6985 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006986 },
6987 },
6988 flags: []string{
6989 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6990 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006991 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006992 },
David Benjaminca3d5452016-07-14 12:51:01 -04006993 shouldFail: true,
6994 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6995 })
6996 testCases = append(testCases, testCase{
6997 name: "NoCommonAlgorithms-TLS13",
6998 config: Config{
6999 MaxVersion: VersionTLS13,
7000 ClientAuth: RequireAnyClientCert,
7001 VerifySignatureAlgorithms: []signatureAlgorithm{
7002 signatureRSAPSSWithSHA512,
7003 signatureRSAPSSWithSHA384,
7004 },
7005 },
7006 flags: []string{
7007 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7008 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7009 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7010 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007011 shouldFail: true,
7012 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007013 })
7014 testCases = append(testCases, testCase{
7015 name: "Agree-Digest-SHA256",
7016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007017 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007018 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007019 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007020 signatureRSAPKCS1WithSHA1,
7021 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007022 },
7023 },
7024 flags: []string{
7025 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7026 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007027 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007028 },
Nick Harper60edffd2016-06-21 15:19:24 -07007029 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007030 })
7031 testCases = append(testCases, testCase{
7032 name: "Agree-Digest-SHA1",
7033 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007034 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007035 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007036 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007037 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007038 },
7039 },
7040 flags: []string{
7041 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7042 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007043 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007044 },
Nick Harper60edffd2016-06-21 15:19:24 -07007045 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007046 })
7047 testCases = append(testCases, testCase{
7048 name: "Agree-Digest-Default",
7049 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007050 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007051 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007052 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007053 signatureRSAPKCS1WithSHA256,
7054 signatureECDSAWithP256AndSHA256,
7055 signatureRSAPKCS1WithSHA1,
7056 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007057 },
7058 },
7059 flags: []string{
7060 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7061 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7062 },
Nick Harper60edffd2016-06-21 15:19:24 -07007063 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007064 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007065
David Benjaminca3d5452016-07-14 12:51:01 -04007066 // Test that the signing preference list may include extra algorithms
7067 // without negotiation problems.
7068 testCases = append(testCases, testCase{
7069 testType: serverTest,
7070 name: "FilterExtraAlgorithms",
7071 config: Config{
7072 MaxVersion: VersionTLS12,
7073 VerifySignatureAlgorithms: []signatureAlgorithm{
7074 signatureRSAPKCS1WithSHA256,
7075 },
7076 },
7077 flags: []string{
7078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7080 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7081 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7082 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7083 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7084 },
7085 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7086 })
7087
David Benjamin4c3ddf72016-06-29 18:13:53 -04007088 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7089 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007090 testCases = append(testCases, testCase{
7091 name: "CheckLeafCurve",
7092 config: Config{
7093 MaxVersion: VersionTLS12,
7094 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007095 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007096 },
7097 flags: []string{"-p384-only"},
7098 shouldFail: true,
7099 expectedError: ":BAD_ECC_CERT:",
7100 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007101
7102 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7103 testCases = append(testCases, testCase{
7104 name: "CheckLeafCurve-TLS13",
7105 config: Config{
7106 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007107 Certificates: []Certificate{ecdsaP256Certificate},
7108 },
7109 flags: []string{"-p384-only"},
7110 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007111
7112 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7113 testCases = append(testCases, testCase{
7114 name: "ECDSACurveMismatch-Verify-TLS12",
7115 config: Config{
7116 MaxVersion: VersionTLS12,
7117 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7118 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007119 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007120 signatureECDSAWithP384AndSHA384,
7121 },
7122 },
7123 })
7124
7125 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7126 testCases = append(testCases, testCase{
7127 name: "ECDSACurveMismatch-Verify-TLS13",
7128 config: Config{
7129 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007130 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007131 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007132 signatureECDSAWithP384AndSHA384,
7133 },
7134 Bugs: ProtocolBugs{
7135 SkipECDSACurveCheck: true,
7136 },
7137 },
7138 shouldFail: true,
7139 expectedError: ":WRONG_SIGNATURE_TYPE:",
7140 })
7141
7142 // Signature algorithm selection in TLS 1.3 should take the curve into
7143 // account.
7144 testCases = append(testCases, testCase{
7145 testType: serverTest,
7146 name: "ECDSACurveMismatch-Sign-TLS13",
7147 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007148 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007149 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007150 signatureECDSAWithP384AndSHA384,
7151 signatureECDSAWithP256AndSHA256,
7152 },
7153 },
7154 flags: []string{
7155 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7156 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7157 },
7158 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7159 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007160
7161 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7162 // server does not attempt to sign in that case.
7163 testCases = append(testCases, testCase{
7164 testType: serverTest,
7165 name: "RSA-PSS-Large",
7166 config: Config{
7167 MaxVersion: VersionTLS13,
7168 VerifySignatureAlgorithms: []signatureAlgorithm{
7169 signatureRSAPSSWithSHA512,
7170 },
7171 },
7172 flags: []string{
7173 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7174 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7175 },
7176 shouldFail: true,
7177 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7178 })
David Benjamin57e929f2016-08-30 00:30:38 -04007179
7180 // Test that RSA-PSS is enabled by default for TLS 1.2.
7181 testCases = append(testCases, testCase{
7182 testType: clientTest,
7183 name: "RSA-PSS-Default-Verify",
7184 config: Config{
7185 MaxVersion: VersionTLS12,
7186 SignSignatureAlgorithms: []signatureAlgorithm{
7187 signatureRSAPSSWithSHA256,
7188 },
7189 },
7190 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7191 })
7192
7193 testCases = append(testCases, testCase{
7194 testType: serverTest,
7195 name: "RSA-PSS-Default-Sign",
7196 config: Config{
7197 MaxVersion: VersionTLS12,
7198 VerifySignatureAlgorithms: []signatureAlgorithm{
7199 signatureRSAPSSWithSHA256,
7200 },
7201 },
7202 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7203 })
David Benjamin000800a2014-11-14 01:43:59 -05007204}
7205
David Benjamin83f90402015-01-27 01:09:43 -05007206// timeouts is the retransmit schedule for BoringSSL. It doubles and
7207// caps at 60 seconds. On the 13th timeout, it gives up.
7208var timeouts = []time.Duration{
7209 1 * time.Second,
7210 2 * time.Second,
7211 4 * time.Second,
7212 8 * time.Second,
7213 16 * time.Second,
7214 32 * time.Second,
7215 60 * time.Second,
7216 60 * time.Second,
7217 60 * time.Second,
7218 60 * time.Second,
7219 60 * time.Second,
7220 60 * time.Second,
7221 60 * time.Second,
7222}
7223
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007224// shortTimeouts is an alternate set of timeouts which would occur if the
7225// initial timeout duration was set to 250ms.
7226var shortTimeouts = []time.Duration{
7227 250 * time.Millisecond,
7228 500 * time.Millisecond,
7229 1 * time.Second,
7230 2 * time.Second,
7231 4 * time.Second,
7232 8 * time.Second,
7233 16 * time.Second,
7234 32 * time.Second,
7235 60 * time.Second,
7236 60 * time.Second,
7237 60 * time.Second,
7238 60 * time.Second,
7239 60 * time.Second,
7240}
7241
David Benjamin83f90402015-01-27 01:09:43 -05007242func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007243 // These tests work by coordinating some behavior on both the shim and
7244 // the runner.
7245 //
7246 // TimeoutSchedule configures the runner to send a series of timeout
7247 // opcodes to the shim (see packetAdaptor) immediately before reading
7248 // each peer handshake flight N. The timeout opcode both simulates a
7249 // timeout in the shim and acts as a synchronization point to help the
7250 // runner bracket each handshake flight.
7251 //
7252 // We assume the shim does not read from the channel eagerly. It must
7253 // first wait until it has sent flight N and is ready to receive
7254 // handshake flight N+1. At this point, it will process the timeout
7255 // opcode. It must then immediately respond with a timeout ACK and act
7256 // as if the shim was idle for the specified amount of time.
7257 //
7258 // The runner then drops all packets received before the ACK and
7259 // continues waiting for flight N. This ordering results in one attempt
7260 // at sending flight N to be dropped. For the test to complete, the
7261 // shim must send flight N again, testing that the shim implements DTLS
7262 // retransmit on a timeout.
7263
Steven Valdez143e8b32016-07-11 13:19:03 -04007264 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007265 // likely be more epochs to cross and the final message's retransmit may
7266 // be more complex.
7267
David Benjamin585d7a42016-06-02 14:58:00 -04007268 for _, async := range []bool{true, false} {
7269 var tests []testCase
7270
7271 // Test that this is indeed the timeout schedule. Stress all
7272 // four patterns of handshake.
7273 for i := 1; i < len(timeouts); i++ {
7274 number := strconv.Itoa(i)
7275 tests = append(tests, testCase{
7276 protocol: dtls,
7277 name: "DTLS-Retransmit-Client-" + number,
7278 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007279 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007280 Bugs: ProtocolBugs{
7281 TimeoutSchedule: timeouts[:i],
7282 },
7283 },
7284 resumeSession: true,
7285 })
7286 tests = append(tests, testCase{
7287 protocol: dtls,
7288 testType: serverTest,
7289 name: "DTLS-Retransmit-Server-" + number,
7290 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007291 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007292 Bugs: ProtocolBugs{
7293 TimeoutSchedule: timeouts[:i],
7294 },
7295 },
7296 resumeSession: true,
7297 })
7298 }
7299
7300 // Test that exceeding the timeout schedule hits a read
7301 // timeout.
7302 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007303 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007304 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007306 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007307 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007308 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007309 },
7310 },
7311 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007312 shouldFail: true,
7313 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007314 })
David Benjamin585d7a42016-06-02 14:58:00 -04007315
7316 if async {
7317 // Test that timeout handling has a fudge factor, due to API
7318 // problems.
7319 tests = append(tests, testCase{
7320 protocol: dtls,
7321 name: "DTLS-Retransmit-Fudge",
7322 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007323 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007324 Bugs: ProtocolBugs{
7325 TimeoutSchedule: []time.Duration{
7326 timeouts[0] - 10*time.Millisecond,
7327 },
7328 },
7329 },
7330 resumeSession: true,
7331 })
7332 }
7333
7334 // Test that the final Finished retransmitting isn't
7335 // duplicated if the peer badly fragments everything.
7336 tests = append(tests, testCase{
7337 testType: serverTest,
7338 protocol: dtls,
7339 name: "DTLS-Retransmit-Fragmented",
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{timeouts[0]},
7344 MaxHandshakeRecordLength: 2,
7345 },
7346 },
7347 })
7348
7349 // Test the timeout schedule when a shorter initial timeout duration is set.
7350 tests = append(tests, testCase{
7351 protocol: dtls,
7352 name: "DTLS-Retransmit-Short-Client",
7353 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007354 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007355 Bugs: ProtocolBugs{
7356 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7357 },
7358 },
7359 resumeSession: true,
7360 flags: []string{"-initial-timeout-duration-ms", "250"},
7361 })
7362 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007363 protocol: dtls,
7364 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007365 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007366 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007367 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007368 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007369 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007370 },
7371 },
7372 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007373 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007374 })
David Benjamin585d7a42016-06-02 14:58:00 -04007375
7376 for _, test := range tests {
7377 if async {
7378 test.name += "-Async"
7379 test.flags = append(test.flags, "-async")
7380 }
7381
7382 testCases = append(testCases, test)
7383 }
David Benjamin83f90402015-01-27 01:09:43 -05007384 }
David Benjamin83f90402015-01-27 01:09:43 -05007385}
7386
David Benjaminc565ebb2015-04-03 04:06:36 -04007387func addExportKeyingMaterialTests() {
7388 for _, vers := range tlsVersions {
7389 if vers.version == VersionSSL30 {
7390 continue
7391 }
7392 testCases = append(testCases, testCase{
7393 name: "ExportKeyingMaterial-" + vers.name,
7394 config: Config{
7395 MaxVersion: vers.version,
7396 },
7397 exportKeyingMaterial: 1024,
7398 exportLabel: "label",
7399 exportContext: "context",
7400 useExportContext: true,
7401 })
7402 testCases = append(testCases, testCase{
7403 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7404 config: Config{
7405 MaxVersion: vers.version,
7406 },
7407 exportKeyingMaterial: 1024,
7408 })
7409 testCases = append(testCases, testCase{
7410 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7411 config: Config{
7412 MaxVersion: vers.version,
7413 },
7414 exportKeyingMaterial: 1024,
7415 useExportContext: true,
7416 })
7417 testCases = append(testCases, testCase{
7418 name: "ExportKeyingMaterial-Small-" + vers.name,
7419 config: Config{
7420 MaxVersion: vers.version,
7421 },
7422 exportKeyingMaterial: 1,
7423 exportLabel: "label",
7424 exportContext: "context",
7425 useExportContext: true,
7426 })
7427 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007428
David Benjaminc565ebb2015-04-03 04:06:36 -04007429 testCases = append(testCases, testCase{
7430 name: "ExportKeyingMaterial-SSL3",
7431 config: Config{
7432 MaxVersion: VersionSSL30,
7433 },
7434 exportKeyingMaterial: 1024,
7435 exportLabel: "label",
7436 exportContext: "context",
7437 useExportContext: true,
7438 shouldFail: true,
7439 expectedError: "failed to export keying material",
7440 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007441
7442 // Exporters work during a False Start.
7443 testCases = append(testCases, testCase{
7444 name: "ExportKeyingMaterial-FalseStart",
7445 config: Config{
7446 MaxVersion: VersionTLS12,
7447 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7448 NextProtos: []string{"foo"},
7449 Bugs: ProtocolBugs{
7450 ExpectFalseStart: true,
7451 },
7452 },
7453 flags: []string{
7454 "-false-start",
7455 "-advertise-alpn", "\x03foo",
7456 },
7457 shimWritesFirst: true,
7458 exportKeyingMaterial: 1024,
7459 exportLabel: "label",
7460 exportContext: "context",
7461 useExportContext: true,
7462 })
7463
7464 // Exporters do not work in the middle of a renegotiation. Test this by
7465 // triggering the exporter after every SSL_read call and configuring the
7466 // shim to run asynchronously.
7467 testCases = append(testCases, testCase{
7468 name: "ExportKeyingMaterial-Renegotiate",
7469 config: Config{
7470 MaxVersion: VersionTLS12,
7471 },
7472 renegotiate: 1,
7473 flags: []string{
7474 "-async",
7475 "-use-exporter-between-reads",
7476 "-renegotiate-freely",
7477 "-expect-total-renegotiations", "1",
7478 },
7479 shouldFail: true,
7480 expectedError: "failed to export keying material",
7481 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007482}
7483
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007484func addTLSUniqueTests() {
7485 for _, isClient := range []bool{false, true} {
7486 for _, isResumption := range []bool{false, true} {
7487 for _, hasEMS := range []bool{false, true} {
7488 var suffix string
7489 if isResumption {
7490 suffix = "Resume-"
7491 } else {
7492 suffix = "Full-"
7493 }
7494
7495 if hasEMS {
7496 suffix += "EMS-"
7497 } else {
7498 suffix += "NoEMS-"
7499 }
7500
7501 if isClient {
7502 suffix += "Client"
7503 } else {
7504 suffix += "Server"
7505 }
7506
7507 test := testCase{
7508 name: "TLSUnique-" + suffix,
7509 testTLSUnique: true,
7510 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007511 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007512 Bugs: ProtocolBugs{
7513 NoExtendedMasterSecret: !hasEMS,
7514 },
7515 },
7516 }
7517
7518 if isResumption {
7519 test.resumeSession = true
7520 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007521 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007522 Bugs: ProtocolBugs{
7523 NoExtendedMasterSecret: !hasEMS,
7524 },
7525 }
7526 }
7527
7528 if isResumption && !hasEMS {
7529 test.shouldFail = true
7530 test.expectedError = "failed to get tls-unique"
7531 }
7532
7533 testCases = append(testCases, test)
7534 }
7535 }
7536 }
7537}
7538
Adam Langley09505632015-07-30 18:10:13 -07007539func addCustomExtensionTests() {
7540 expectedContents := "custom extension"
7541 emptyString := ""
7542
7543 for _, isClient := range []bool{false, true} {
7544 suffix := "Server"
7545 flag := "-enable-server-custom-extension"
7546 testType := serverTest
7547 if isClient {
7548 suffix = "Client"
7549 flag = "-enable-client-custom-extension"
7550 testType = clientTest
7551 }
7552
7553 testCases = append(testCases, testCase{
7554 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007555 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007557 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007558 Bugs: ProtocolBugs{
7559 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007560 ExpectedCustomExtension: &expectedContents,
7561 },
7562 },
7563 flags: []string{flag},
7564 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007565 testCases = append(testCases, testCase{
7566 testType: testType,
7567 name: "CustomExtensions-" + suffix + "-TLS13",
7568 config: Config{
7569 MaxVersion: VersionTLS13,
7570 Bugs: ProtocolBugs{
7571 CustomExtension: expectedContents,
7572 ExpectedCustomExtension: &expectedContents,
7573 },
7574 },
7575 flags: []string{flag},
7576 })
Adam Langley09505632015-07-30 18:10:13 -07007577
7578 // If the parse callback fails, the handshake should also fail.
7579 testCases = append(testCases, testCase{
7580 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007581 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007583 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007584 Bugs: ProtocolBugs{
7585 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007586 ExpectedCustomExtension: &expectedContents,
7587 },
7588 },
David Benjamin399e7c92015-07-30 23:01:27 -04007589 flags: []string{flag},
7590 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007591 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7592 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007593 testCases = append(testCases, testCase{
7594 testType: testType,
7595 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7596 config: Config{
7597 MaxVersion: VersionTLS13,
7598 Bugs: ProtocolBugs{
7599 CustomExtension: expectedContents + "foo",
7600 ExpectedCustomExtension: &expectedContents,
7601 },
7602 },
7603 flags: []string{flag},
7604 shouldFail: true,
7605 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7606 })
Adam Langley09505632015-07-30 18:10:13 -07007607
7608 // If the add callback fails, the handshake should also fail.
7609 testCases = append(testCases, testCase{
7610 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007611 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007612 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007613 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007614 Bugs: ProtocolBugs{
7615 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007616 ExpectedCustomExtension: &expectedContents,
7617 },
7618 },
David Benjamin399e7c92015-07-30 23:01:27 -04007619 flags: []string{flag, "-custom-extension-fail-add"},
7620 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007621 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7622 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007623 testCases = append(testCases, testCase{
7624 testType: testType,
7625 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7626 config: Config{
7627 MaxVersion: VersionTLS13,
7628 Bugs: ProtocolBugs{
7629 CustomExtension: expectedContents,
7630 ExpectedCustomExtension: &expectedContents,
7631 },
7632 },
7633 flags: []string{flag, "-custom-extension-fail-add"},
7634 shouldFail: true,
7635 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7636 })
Adam Langley09505632015-07-30 18:10:13 -07007637
7638 // If the add callback returns zero, no extension should be
7639 // added.
7640 skipCustomExtension := expectedContents
7641 if isClient {
7642 // For the case where the client skips sending the
7643 // custom extension, the server must not “echo” it.
7644 skipCustomExtension = ""
7645 }
7646 testCases = append(testCases, testCase{
7647 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007648 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007649 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007650 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007651 Bugs: ProtocolBugs{
7652 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007653 ExpectedCustomExtension: &emptyString,
7654 },
7655 },
7656 flags: []string{flag, "-custom-extension-skip"},
7657 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007658 testCases = append(testCases, testCase{
7659 testType: testType,
7660 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7661 config: Config{
7662 MaxVersion: VersionTLS13,
7663 Bugs: ProtocolBugs{
7664 CustomExtension: skipCustomExtension,
7665 ExpectedCustomExtension: &emptyString,
7666 },
7667 },
7668 flags: []string{flag, "-custom-extension-skip"},
7669 })
Adam Langley09505632015-07-30 18:10:13 -07007670 }
7671
7672 // The custom extension add callback should not be called if the client
7673 // doesn't send the extension.
7674 testCases = append(testCases, testCase{
7675 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007676 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007677 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007678 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007679 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007680 ExpectedCustomExtension: &emptyString,
7681 },
7682 },
7683 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7684 })
Adam Langley2deb9842015-08-07 11:15:37 -07007685
Steven Valdez143e8b32016-07-11 13:19:03 -04007686 testCases = append(testCases, testCase{
7687 testType: serverTest,
7688 name: "CustomExtensions-NotCalled-Server-TLS13",
7689 config: Config{
7690 MaxVersion: VersionTLS13,
7691 Bugs: ProtocolBugs{
7692 ExpectedCustomExtension: &emptyString,
7693 },
7694 },
7695 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7696 })
7697
Adam Langley2deb9842015-08-07 11:15:37 -07007698 // Test an unknown extension from the server.
7699 testCases = append(testCases, testCase{
7700 testType: clientTest,
7701 name: "UnknownExtension-Client",
7702 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007703 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007704 Bugs: ProtocolBugs{
7705 CustomExtension: expectedContents,
7706 },
7707 },
David Benjamin0c40a962016-08-01 12:05:50 -04007708 shouldFail: true,
7709 expectedError: ":UNEXPECTED_EXTENSION:",
7710 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007711 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007712 testCases = append(testCases, testCase{
7713 testType: clientTest,
7714 name: "UnknownExtension-Client-TLS13",
7715 config: Config{
7716 MaxVersion: VersionTLS13,
7717 Bugs: ProtocolBugs{
7718 CustomExtension: expectedContents,
7719 },
7720 },
David Benjamin0c40a962016-08-01 12:05:50 -04007721 shouldFail: true,
7722 expectedError: ":UNEXPECTED_EXTENSION:",
7723 expectedLocalError: "remote error: unsupported extension",
7724 })
David Benjamin490469f2016-10-05 22:44:38 -04007725 testCases = append(testCases, testCase{
7726 testType: clientTest,
7727 name: "UnknownUnencryptedExtension-Client-TLS13",
7728 config: Config{
7729 MaxVersion: VersionTLS13,
7730 Bugs: ProtocolBugs{
7731 CustomUnencryptedExtension: expectedContents,
7732 },
7733 },
7734 shouldFail: true,
7735 expectedError: ":UNEXPECTED_EXTENSION:",
7736 // The shim must send an alert, but alerts at this point do not
7737 // get successfully decrypted by the runner.
7738 expectedLocalError: "local error: bad record MAC",
7739 })
7740 testCases = append(testCases, testCase{
7741 testType: clientTest,
7742 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7743 config: Config{
7744 MaxVersion: VersionTLS13,
7745 Bugs: ProtocolBugs{
7746 SendUnencryptedALPN: "foo",
7747 },
7748 },
7749 flags: []string{
7750 "-advertise-alpn", "\x03foo\x03bar",
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 })
David Benjamin0c40a962016-08-01 12:05:50 -04007758
7759 // Test a known but unoffered extension from the server.
7760 testCases = append(testCases, testCase{
7761 testType: clientTest,
7762 name: "UnofferedExtension-Client",
7763 config: Config{
7764 MaxVersion: VersionTLS12,
7765 Bugs: ProtocolBugs{
7766 SendALPN: "alpn",
7767 },
7768 },
7769 shouldFail: true,
7770 expectedError: ":UNEXPECTED_EXTENSION:",
7771 expectedLocalError: "remote error: unsupported extension",
7772 })
7773 testCases = append(testCases, testCase{
7774 testType: clientTest,
7775 name: "UnofferedExtension-Client-TLS13",
7776 config: Config{
7777 MaxVersion: VersionTLS13,
7778 Bugs: ProtocolBugs{
7779 SendALPN: "alpn",
7780 },
7781 },
7782 shouldFail: true,
7783 expectedError: ":UNEXPECTED_EXTENSION:",
7784 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007785 })
Adam Langley09505632015-07-30 18:10:13 -07007786}
7787
David Benjaminb36a3952015-12-01 18:53:13 -05007788func addRSAClientKeyExchangeTests() {
7789 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7790 testCases = append(testCases, testCase{
7791 testType: serverTest,
7792 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7793 config: Config{
7794 // Ensure the ClientHello version and final
7795 // version are different, to detect if the
7796 // server uses the wrong one.
7797 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007798 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007799 Bugs: ProtocolBugs{
7800 BadRSAClientKeyExchange: bad,
7801 },
7802 },
7803 shouldFail: true,
7804 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7805 })
7806 }
David Benjamine63d9d72016-09-19 18:27:34 -04007807
7808 // The server must compare whatever was in ClientHello.version for the
7809 // RSA premaster.
7810 testCases = append(testCases, testCase{
7811 testType: serverTest,
7812 name: "SendClientVersion-RSA",
7813 config: Config{
7814 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7815 Bugs: ProtocolBugs{
7816 SendClientVersion: 0x1234,
7817 },
7818 },
7819 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7820 })
David Benjaminb36a3952015-12-01 18:53:13 -05007821}
7822
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007823var testCurves = []struct {
7824 name string
7825 id CurveID
7826}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007827 {"P-256", CurveP256},
7828 {"P-384", CurveP384},
7829 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007830 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007831}
7832
Steven Valdez5440fe02016-07-18 12:40:30 -04007833const bogusCurve = 0x1234
7834
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007835func addCurveTests() {
7836 for _, curve := range testCurves {
7837 testCases = append(testCases, testCase{
7838 name: "CurveTest-Client-" + curve.name,
7839 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007840 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007841 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7842 CurvePreferences: []CurveID{curve.id},
7843 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007844 flags: []string{
7845 "-enable-all-curves",
7846 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7847 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007848 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007849 })
7850 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007851 name: "CurveTest-Client-" + curve.name + "-TLS13",
7852 config: Config{
7853 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007854 CurvePreferences: []CurveID{curve.id},
7855 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007856 flags: []string{
7857 "-enable-all-curves",
7858 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7859 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007860 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007861 })
7862 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007863 testType: serverTest,
7864 name: "CurveTest-Server-" + curve.name,
7865 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007866 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007867 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7868 CurvePreferences: []CurveID{curve.id},
7869 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007870 flags: []string{
7871 "-enable-all-curves",
7872 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7873 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007874 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007875 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007876 testCases = append(testCases, testCase{
7877 testType: serverTest,
7878 name: "CurveTest-Server-" + curve.name + "-TLS13",
7879 config: Config{
7880 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007881 CurvePreferences: []CurveID{curve.id},
7882 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007883 flags: []string{
7884 "-enable-all-curves",
7885 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7886 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007887 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007888 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007889 }
David Benjamin241ae832016-01-15 03:04:54 -05007890
7891 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007892 testCases = append(testCases, testCase{
7893 testType: serverTest,
7894 name: "UnknownCurve",
7895 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007896 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007897 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7898 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7899 },
7900 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007901
Steven Valdez803c77a2016-09-06 14:13:43 -04007902 // The server must be tolerant to bogus curves.
7903 testCases = append(testCases, testCase{
7904 testType: serverTest,
7905 name: "UnknownCurve-TLS13",
7906 config: Config{
7907 MaxVersion: VersionTLS13,
7908 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7909 },
7910 })
7911
David Benjamin4c3ddf72016-06-29 18:13:53 -04007912 // The server must not consider ECDHE ciphers when there are no
7913 // supported curves.
7914 testCases = append(testCases, testCase{
7915 testType: serverTest,
7916 name: "NoSupportedCurves",
7917 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007918 MaxVersion: VersionTLS12,
7919 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7920 Bugs: ProtocolBugs{
7921 NoSupportedCurves: true,
7922 },
7923 },
7924 shouldFail: true,
7925 expectedError: ":NO_SHARED_CIPHER:",
7926 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007927 testCases = append(testCases, testCase{
7928 testType: serverTest,
7929 name: "NoSupportedCurves-TLS13",
7930 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007931 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007932 Bugs: ProtocolBugs{
7933 NoSupportedCurves: true,
7934 },
7935 },
7936 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007937 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007938 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007939
7940 // The server must fall back to another cipher when there are no
7941 // supported curves.
7942 testCases = append(testCases, testCase{
7943 testType: serverTest,
7944 name: "NoCommonCurves",
7945 config: Config{
7946 MaxVersion: VersionTLS12,
7947 CipherSuites: []uint16{
7948 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7949 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7950 },
7951 CurvePreferences: []CurveID{CurveP224},
7952 },
7953 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7954 })
7955
7956 // The client must reject bogus curves and disabled curves.
7957 testCases = append(testCases, testCase{
7958 name: "BadECDHECurve",
7959 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007960 MaxVersion: VersionTLS12,
7961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7962 Bugs: ProtocolBugs{
7963 SendCurve: bogusCurve,
7964 },
7965 },
7966 shouldFail: true,
7967 expectedError: ":WRONG_CURVE:",
7968 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007969 testCases = append(testCases, testCase{
7970 name: "BadECDHECurve-TLS13",
7971 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007972 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007973 Bugs: ProtocolBugs{
7974 SendCurve: bogusCurve,
7975 },
7976 },
7977 shouldFail: true,
7978 expectedError: ":WRONG_CURVE:",
7979 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007980
7981 testCases = append(testCases, testCase{
7982 name: "UnsupportedCurve",
7983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007984 MaxVersion: VersionTLS12,
7985 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7986 CurvePreferences: []CurveID{CurveP256},
7987 Bugs: ProtocolBugs{
7988 IgnorePeerCurvePreferences: true,
7989 },
7990 },
7991 flags: []string{"-p384-only"},
7992 shouldFail: true,
7993 expectedError: ":WRONG_CURVE:",
7994 })
7995
David Benjamin4f921572016-07-17 14:20:10 +02007996 testCases = append(testCases, testCase{
7997 // TODO(davidben): Add a TLS 1.3 version where
7998 // HelloRetryRequest requests an unsupported curve.
7999 name: "UnsupportedCurve-ServerHello-TLS13",
8000 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008001 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008002 CurvePreferences: []CurveID{CurveP384},
8003 Bugs: ProtocolBugs{
8004 SendCurve: CurveP256,
8005 },
8006 },
8007 flags: []string{"-p384-only"},
8008 shouldFail: true,
8009 expectedError: ":WRONG_CURVE:",
8010 })
8011
David Benjamin4c3ddf72016-06-29 18:13:53 -04008012 // Test invalid curve points.
8013 testCases = append(testCases, testCase{
8014 name: "InvalidECDHPoint-Client",
8015 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008016 MaxVersion: VersionTLS12,
8017 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8018 CurvePreferences: []CurveID{CurveP256},
8019 Bugs: ProtocolBugs{
8020 InvalidECDHPoint: true,
8021 },
8022 },
8023 shouldFail: true,
8024 expectedError: ":INVALID_ENCODING:",
8025 })
8026 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008027 name: "InvalidECDHPoint-Client-TLS13",
8028 config: Config{
8029 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008030 CurvePreferences: []CurveID{CurveP256},
8031 Bugs: ProtocolBugs{
8032 InvalidECDHPoint: true,
8033 },
8034 },
8035 shouldFail: true,
8036 expectedError: ":INVALID_ENCODING:",
8037 })
8038 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008039 testType: serverTest,
8040 name: "InvalidECDHPoint-Server",
8041 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008042 MaxVersion: VersionTLS12,
8043 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8044 CurvePreferences: []CurveID{CurveP256},
8045 Bugs: ProtocolBugs{
8046 InvalidECDHPoint: true,
8047 },
8048 },
8049 shouldFail: true,
8050 expectedError: ":INVALID_ENCODING:",
8051 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008052 testCases = append(testCases, testCase{
8053 testType: serverTest,
8054 name: "InvalidECDHPoint-Server-TLS13",
8055 config: Config{
8056 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008057 CurvePreferences: []CurveID{CurveP256},
8058 Bugs: ProtocolBugs{
8059 InvalidECDHPoint: true,
8060 },
8061 },
8062 shouldFail: true,
8063 expectedError: ":INVALID_ENCODING:",
8064 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008065
8066 // The previous curve ID should be reported on TLS 1.2 resumption.
8067 testCases = append(testCases, testCase{
8068 name: "CurveID-Resume-Client",
8069 config: Config{
8070 MaxVersion: VersionTLS12,
8071 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8072 CurvePreferences: []CurveID{CurveX25519},
8073 },
8074 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8075 resumeSession: true,
8076 })
8077 testCases = append(testCases, testCase{
8078 testType: serverTest,
8079 name: "CurveID-Resume-Server",
8080 config: Config{
8081 MaxVersion: VersionTLS12,
8082 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8083 CurvePreferences: []CurveID{CurveX25519},
8084 },
8085 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8086 resumeSession: true,
8087 })
8088
8089 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8090 // one should be reported.
8091 testCases = append(testCases, testCase{
8092 name: "CurveID-Resume-Client-TLS13",
8093 config: Config{
8094 MaxVersion: VersionTLS13,
8095 CurvePreferences: []CurveID{CurveX25519},
8096 },
8097 resumeConfig: &Config{
8098 MaxVersion: VersionTLS13,
8099 CurvePreferences: []CurveID{CurveP256},
8100 },
8101 flags: []string{
8102 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8103 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8104 },
8105 resumeSession: true,
8106 })
8107 testCases = append(testCases, testCase{
8108 testType: serverTest,
8109 name: "CurveID-Resume-Server-TLS13",
8110 config: Config{
8111 MaxVersion: VersionTLS13,
8112 CurvePreferences: []CurveID{CurveX25519},
8113 },
8114 resumeConfig: &Config{
8115 MaxVersion: VersionTLS13,
8116 CurvePreferences: []CurveID{CurveP256},
8117 },
8118 flags: []string{
8119 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8120 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8121 },
8122 resumeSession: true,
8123 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008124}
8125
David Benjaminc9ae27c2016-06-24 22:56:37 -04008126func addTLS13RecordTests() {
8127 testCases = append(testCases, testCase{
8128 name: "TLS13-RecordPadding",
8129 config: Config{
8130 MaxVersion: VersionTLS13,
8131 MinVersion: VersionTLS13,
8132 Bugs: ProtocolBugs{
8133 RecordPadding: 10,
8134 },
8135 },
8136 })
8137
8138 testCases = append(testCases, testCase{
8139 name: "TLS13-EmptyRecords",
8140 config: Config{
8141 MaxVersion: VersionTLS13,
8142 MinVersion: VersionTLS13,
8143 Bugs: ProtocolBugs{
8144 OmitRecordContents: true,
8145 },
8146 },
8147 shouldFail: true,
8148 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8149 })
8150
8151 testCases = append(testCases, testCase{
8152 name: "TLS13-OnlyPadding",
8153 config: Config{
8154 MaxVersion: VersionTLS13,
8155 MinVersion: VersionTLS13,
8156 Bugs: ProtocolBugs{
8157 OmitRecordContents: true,
8158 RecordPadding: 10,
8159 },
8160 },
8161 shouldFail: true,
8162 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8163 })
8164
8165 testCases = append(testCases, testCase{
8166 name: "TLS13-WrongOuterRecord",
8167 config: Config{
8168 MaxVersion: VersionTLS13,
8169 MinVersion: VersionTLS13,
8170 Bugs: ProtocolBugs{
8171 OuterRecordType: recordTypeHandshake,
8172 },
8173 },
8174 shouldFail: true,
8175 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8176 })
8177}
8178
Steven Valdez5b986082016-09-01 12:29:49 -04008179func addSessionTicketTests() {
8180 testCases = append(testCases, testCase{
8181 // In TLS 1.2 and below, empty NewSessionTicket messages
8182 // mean the server changed its mind on sending a ticket.
8183 name: "SendEmptySessionTicket",
8184 config: Config{
8185 MaxVersion: VersionTLS12,
8186 Bugs: ProtocolBugs{
8187 SendEmptySessionTicket: true,
8188 },
8189 },
8190 flags: []string{"-expect-no-session"},
8191 })
8192
8193 // Test that the server ignores unknown PSK modes.
8194 testCases = append(testCases, testCase{
8195 testType: serverTest,
8196 name: "TLS13-SendUnknownModeSessionTicket-Server",
8197 config: Config{
8198 MaxVersion: VersionTLS13,
8199 Bugs: ProtocolBugs{
8200 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008201 },
8202 },
8203 resumeSession: true,
8204 expectedResumeVersion: VersionTLS13,
8205 })
8206
Steven Valdeza833c352016-11-01 13:39:36 -04008207 // Test that the server does not send session tickets with no matching key exchange mode.
8208 testCases = append(testCases, testCase{
8209 testType: serverTest,
8210 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8211 config: Config{
8212 MaxVersion: VersionTLS13,
8213 Bugs: ProtocolBugs{
8214 SendPSKKeyExchangeModes: []byte{0x1a},
8215 ExpectNoNewSessionTicket: true,
8216 },
8217 },
8218 })
8219
8220 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008221 testCases = append(testCases, testCase{
8222 testType: serverTest,
8223 name: "TLS13-SendBadKEModeSessionTicket-Server",
8224 config: Config{
8225 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008226 },
8227 resumeConfig: &Config{
8228 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008229 Bugs: ProtocolBugs{
8230 SendPSKKeyExchangeModes: []byte{0x1a},
8231 },
8232 },
8233 resumeSession: true,
8234 expectResumeRejected: true,
8235 })
8236
Steven Valdeza833c352016-11-01 13:39:36 -04008237 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008238 testCases = append(testCases, testCase{
8239 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008240 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008241 config: Config{
8242 MaxVersion: VersionTLS13,
8243 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008244 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008245 },
8246 },
Steven Valdeza833c352016-11-01 13:39:36 -04008247 resumeSession: true,
8248 flags: []string{
8249 "-resumption-delay", "10",
8250 },
Steven Valdez5b986082016-09-01 12:29:49 -04008251 })
8252
Steven Valdeza833c352016-11-01 13:39:36 -04008253 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008254 testCases = append(testCases, testCase{
8255 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008256 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008257 config: Config{
8258 MaxVersion: VersionTLS13,
8259 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008260 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008261 },
8262 },
Steven Valdeza833c352016-11-01 13:39:36 -04008263 resumeSession: true,
8264 shouldFail: true,
8265 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008266 })
8267
Steven Valdez5b986082016-09-01 12:29:49 -04008268}
8269
David Benjamin82261be2016-07-07 14:32:50 -07008270func addChangeCipherSpecTests() {
8271 // Test missing ChangeCipherSpecs.
8272 testCases = append(testCases, testCase{
8273 name: "SkipChangeCipherSpec-Client",
8274 config: Config{
8275 MaxVersion: VersionTLS12,
8276 Bugs: ProtocolBugs{
8277 SkipChangeCipherSpec: true,
8278 },
8279 },
8280 shouldFail: true,
8281 expectedError: ":UNEXPECTED_RECORD:",
8282 })
8283 testCases = append(testCases, testCase{
8284 testType: serverTest,
8285 name: "SkipChangeCipherSpec-Server",
8286 config: Config{
8287 MaxVersion: VersionTLS12,
8288 Bugs: ProtocolBugs{
8289 SkipChangeCipherSpec: true,
8290 },
8291 },
8292 shouldFail: true,
8293 expectedError: ":UNEXPECTED_RECORD:",
8294 })
8295 testCases = append(testCases, testCase{
8296 testType: serverTest,
8297 name: "SkipChangeCipherSpec-Server-NPN",
8298 config: Config{
8299 MaxVersion: VersionTLS12,
8300 NextProtos: []string{"bar"},
8301 Bugs: ProtocolBugs{
8302 SkipChangeCipherSpec: true,
8303 },
8304 },
8305 flags: []string{
8306 "-advertise-npn", "\x03foo\x03bar\x03baz",
8307 },
8308 shouldFail: true,
8309 expectedError: ":UNEXPECTED_RECORD:",
8310 })
8311
8312 // Test synchronization between the handshake and ChangeCipherSpec.
8313 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8314 // rejected. Test both with and without handshake packing to handle both
8315 // when the partial post-CCS message is in its own record and when it is
8316 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008317 for _, packed := range []bool{false, true} {
8318 var suffix string
8319 if packed {
8320 suffix = "-Packed"
8321 }
8322
8323 testCases = append(testCases, testCase{
8324 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8325 config: Config{
8326 MaxVersion: VersionTLS12,
8327 Bugs: ProtocolBugs{
8328 FragmentAcrossChangeCipherSpec: true,
8329 PackHandshakeFlight: packed,
8330 },
8331 },
8332 shouldFail: true,
8333 expectedError: ":UNEXPECTED_RECORD:",
8334 })
8335 testCases = append(testCases, testCase{
8336 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8337 config: Config{
8338 MaxVersion: VersionTLS12,
8339 },
8340 resumeSession: true,
8341 resumeConfig: &Config{
8342 MaxVersion: VersionTLS12,
8343 Bugs: ProtocolBugs{
8344 FragmentAcrossChangeCipherSpec: true,
8345 PackHandshakeFlight: packed,
8346 },
8347 },
8348 shouldFail: true,
8349 expectedError: ":UNEXPECTED_RECORD:",
8350 })
8351 testCases = append(testCases, testCase{
8352 testType: serverTest,
8353 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8354 config: Config{
8355 MaxVersion: VersionTLS12,
8356 Bugs: ProtocolBugs{
8357 FragmentAcrossChangeCipherSpec: true,
8358 PackHandshakeFlight: packed,
8359 },
8360 },
8361 shouldFail: true,
8362 expectedError: ":UNEXPECTED_RECORD:",
8363 })
8364 testCases = append(testCases, testCase{
8365 testType: serverTest,
8366 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8367 config: Config{
8368 MaxVersion: VersionTLS12,
8369 },
8370 resumeSession: true,
8371 resumeConfig: &Config{
8372 MaxVersion: VersionTLS12,
8373 Bugs: ProtocolBugs{
8374 FragmentAcrossChangeCipherSpec: true,
8375 PackHandshakeFlight: packed,
8376 },
8377 },
8378 shouldFail: true,
8379 expectedError: ":UNEXPECTED_RECORD:",
8380 })
8381 testCases = append(testCases, testCase{
8382 testType: serverTest,
8383 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8384 config: Config{
8385 MaxVersion: VersionTLS12,
8386 NextProtos: []string{"bar"},
8387 Bugs: ProtocolBugs{
8388 FragmentAcrossChangeCipherSpec: true,
8389 PackHandshakeFlight: packed,
8390 },
8391 },
8392 flags: []string{
8393 "-advertise-npn", "\x03foo\x03bar\x03baz",
8394 },
8395 shouldFail: true,
8396 expectedError: ":UNEXPECTED_RECORD:",
8397 })
8398 }
8399
David Benjamin61672812016-07-14 23:10:43 -04008400 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8401 // messages in the handshake queue. Do this by testing the server
8402 // reading the client Finished, reversing the flight so Finished comes
8403 // first.
8404 testCases = append(testCases, testCase{
8405 protocol: dtls,
8406 testType: serverTest,
8407 name: "SendUnencryptedFinished-DTLS",
8408 config: Config{
8409 MaxVersion: VersionTLS12,
8410 Bugs: ProtocolBugs{
8411 SendUnencryptedFinished: true,
8412 ReverseHandshakeFragments: true,
8413 },
8414 },
8415 shouldFail: true,
8416 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8417 })
8418
Steven Valdez143e8b32016-07-11 13:19:03 -04008419 // Test synchronization between encryption changes and the handshake in
8420 // TLS 1.3, where ChangeCipherSpec is implicit.
8421 testCases = append(testCases, testCase{
8422 name: "PartialEncryptedExtensionsWithServerHello",
8423 config: Config{
8424 MaxVersion: VersionTLS13,
8425 Bugs: ProtocolBugs{
8426 PartialEncryptedExtensionsWithServerHello: true,
8427 },
8428 },
8429 shouldFail: true,
8430 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8431 })
8432 testCases = append(testCases, testCase{
8433 testType: serverTest,
8434 name: "PartialClientFinishedWithClientHello",
8435 config: Config{
8436 MaxVersion: VersionTLS13,
8437 Bugs: ProtocolBugs{
8438 PartialClientFinishedWithClientHello: true,
8439 },
8440 },
8441 shouldFail: true,
8442 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8443 })
8444
David Benjamin82261be2016-07-07 14:32:50 -07008445 // Test that early ChangeCipherSpecs are handled correctly.
8446 testCases = append(testCases, testCase{
8447 testType: serverTest,
8448 name: "EarlyChangeCipherSpec-server-1",
8449 config: Config{
8450 MaxVersion: VersionTLS12,
8451 Bugs: ProtocolBugs{
8452 EarlyChangeCipherSpec: 1,
8453 },
8454 },
8455 shouldFail: true,
8456 expectedError: ":UNEXPECTED_RECORD:",
8457 })
8458 testCases = append(testCases, testCase{
8459 testType: serverTest,
8460 name: "EarlyChangeCipherSpec-server-2",
8461 config: Config{
8462 MaxVersion: VersionTLS12,
8463 Bugs: ProtocolBugs{
8464 EarlyChangeCipherSpec: 2,
8465 },
8466 },
8467 shouldFail: true,
8468 expectedError: ":UNEXPECTED_RECORD:",
8469 })
8470 testCases = append(testCases, testCase{
8471 protocol: dtls,
8472 name: "StrayChangeCipherSpec",
8473 config: Config{
8474 // TODO(davidben): Once DTLS 1.3 exists, test
8475 // that stray ChangeCipherSpec messages are
8476 // rejected.
8477 MaxVersion: VersionTLS12,
8478 Bugs: ProtocolBugs{
8479 StrayChangeCipherSpec: true,
8480 },
8481 },
8482 })
8483
8484 // Test that the contents of ChangeCipherSpec are checked.
8485 testCases = append(testCases, testCase{
8486 name: "BadChangeCipherSpec-1",
8487 config: Config{
8488 MaxVersion: VersionTLS12,
8489 Bugs: ProtocolBugs{
8490 BadChangeCipherSpec: []byte{2},
8491 },
8492 },
8493 shouldFail: true,
8494 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8495 })
8496 testCases = append(testCases, testCase{
8497 name: "BadChangeCipherSpec-2",
8498 config: Config{
8499 MaxVersion: VersionTLS12,
8500 Bugs: ProtocolBugs{
8501 BadChangeCipherSpec: []byte{1, 1},
8502 },
8503 },
8504 shouldFail: true,
8505 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8506 })
8507 testCases = append(testCases, testCase{
8508 protocol: dtls,
8509 name: "BadChangeCipherSpec-DTLS-1",
8510 config: Config{
8511 MaxVersion: VersionTLS12,
8512 Bugs: ProtocolBugs{
8513 BadChangeCipherSpec: []byte{2},
8514 },
8515 },
8516 shouldFail: true,
8517 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8518 })
8519 testCases = append(testCases, testCase{
8520 protocol: dtls,
8521 name: "BadChangeCipherSpec-DTLS-2",
8522 config: Config{
8523 MaxVersion: VersionTLS12,
8524 Bugs: ProtocolBugs{
8525 BadChangeCipherSpec: []byte{1, 1},
8526 },
8527 },
8528 shouldFail: true,
8529 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8530 })
8531}
8532
David Benjamincd2c8062016-09-09 11:28:16 -04008533type perMessageTest struct {
8534 messageType uint8
8535 test testCase
8536}
8537
8538// makePerMessageTests returns a series of test templates which cover each
8539// message in the TLS handshake. These may be used with bugs like
8540// WrongMessageType to fully test a per-message bug.
8541func makePerMessageTests() []perMessageTest {
8542 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008543 for _, protocol := range []protocol{tls, dtls} {
8544 var suffix string
8545 if protocol == dtls {
8546 suffix = "-DTLS"
8547 }
8548
David Benjamincd2c8062016-09-09 11:28:16 -04008549 ret = append(ret, perMessageTest{
8550 messageType: typeClientHello,
8551 test: testCase{
8552 protocol: protocol,
8553 testType: serverTest,
8554 name: "ClientHello" + suffix,
8555 config: Config{
8556 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008557 },
8558 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008559 })
8560
8561 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008562 ret = append(ret, perMessageTest{
8563 messageType: typeHelloVerifyRequest,
8564 test: testCase{
8565 protocol: protocol,
8566 name: "HelloVerifyRequest" + suffix,
8567 config: Config{
8568 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008569 },
8570 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008571 })
8572 }
8573
David Benjamincd2c8062016-09-09 11:28:16 -04008574 ret = append(ret, perMessageTest{
8575 messageType: typeServerHello,
8576 test: testCase{
8577 protocol: protocol,
8578 name: "ServerHello" + suffix,
8579 config: Config{
8580 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008581 },
8582 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008583 })
8584
David Benjamincd2c8062016-09-09 11:28:16 -04008585 ret = append(ret, perMessageTest{
8586 messageType: typeCertificate,
8587 test: testCase{
8588 protocol: protocol,
8589 name: "ServerCertificate" + suffix,
8590 config: Config{
8591 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008592 },
8593 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008594 })
8595
David Benjamincd2c8062016-09-09 11:28:16 -04008596 ret = append(ret, perMessageTest{
8597 messageType: typeCertificateStatus,
8598 test: testCase{
8599 protocol: protocol,
8600 name: "CertificateStatus" + suffix,
8601 config: Config{
8602 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008603 },
David Benjamincd2c8062016-09-09 11:28:16 -04008604 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008605 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008606 })
8607
David Benjamincd2c8062016-09-09 11:28:16 -04008608 ret = append(ret, perMessageTest{
8609 messageType: typeServerKeyExchange,
8610 test: testCase{
8611 protocol: protocol,
8612 name: "ServerKeyExchange" + suffix,
8613 config: Config{
8614 MaxVersion: VersionTLS12,
8615 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008616 },
8617 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008618 })
8619
David Benjamincd2c8062016-09-09 11:28:16 -04008620 ret = append(ret, perMessageTest{
8621 messageType: typeCertificateRequest,
8622 test: testCase{
8623 protocol: protocol,
8624 name: "CertificateRequest" + suffix,
8625 config: Config{
8626 MaxVersion: VersionTLS12,
8627 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008628 },
8629 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008630 })
8631
David Benjamincd2c8062016-09-09 11:28:16 -04008632 ret = append(ret, perMessageTest{
8633 messageType: typeServerHelloDone,
8634 test: testCase{
8635 protocol: protocol,
8636 name: "ServerHelloDone" + suffix,
8637 config: Config{
8638 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008639 },
8640 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008641 })
8642
David Benjamincd2c8062016-09-09 11:28:16 -04008643 ret = append(ret, perMessageTest{
8644 messageType: typeCertificate,
8645 test: testCase{
8646 testType: serverTest,
8647 protocol: protocol,
8648 name: "ClientCertificate" + suffix,
8649 config: Config{
8650 Certificates: []Certificate{rsaCertificate},
8651 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008652 },
David Benjamincd2c8062016-09-09 11:28:16 -04008653 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008654 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008655 })
8656
David Benjamincd2c8062016-09-09 11:28:16 -04008657 ret = append(ret, perMessageTest{
8658 messageType: typeCertificateVerify,
8659 test: testCase{
8660 testType: serverTest,
8661 protocol: protocol,
8662 name: "CertificateVerify" + suffix,
8663 config: Config{
8664 Certificates: []Certificate{rsaCertificate},
8665 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008666 },
David Benjamincd2c8062016-09-09 11:28:16 -04008667 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008668 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008669 })
8670
David Benjamincd2c8062016-09-09 11:28:16 -04008671 ret = append(ret, perMessageTest{
8672 messageType: typeClientKeyExchange,
8673 test: testCase{
8674 testType: serverTest,
8675 protocol: protocol,
8676 name: "ClientKeyExchange" + suffix,
8677 config: Config{
8678 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008679 },
8680 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008681 })
8682
8683 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008684 ret = append(ret, perMessageTest{
8685 messageType: typeNextProtocol,
8686 test: testCase{
8687 testType: serverTest,
8688 protocol: protocol,
8689 name: "NextProtocol" + suffix,
8690 config: Config{
8691 MaxVersion: VersionTLS12,
8692 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008693 },
David Benjamincd2c8062016-09-09 11:28:16 -04008694 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008695 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008696 })
8697
David Benjamincd2c8062016-09-09 11:28:16 -04008698 ret = append(ret, perMessageTest{
8699 messageType: typeChannelID,
8700 test: testCase{
8701 testType: serverTest,
8702 protocol: protocol,
8703 name: "ChannelID" + suffix,
8704 config: Config{
8705 MaxVersion: VersionTLS12,
8706 ChannelID: channelIDKey,
8707 },
8708 flags: []string{
8709 "-expect-channel-id",
8710 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008711 },
8712 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008713 })
8714 }
8715
David Benjamincd2c8062016-09-09 11:28:16 -04008716 ret = append(ret, perMessageTest{
8717 messageType: typeFinished,
8718 test: testCase{
8719 testType: serverTest,
8720 protocol: protocol,
8721 name: "ClientFinished" + suffix,
8722 config: Config{
8723 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008724 },
8725 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008726 })
8727
David Benjamincd2c8062016-09-09 11:28:16 -04008728 ret = append(ret, perMessageTest{
8729 messageType: typeNewSessionTicket,
8730 test: testCase{
8731 protocol: protocol,
8732 name: "NewSessionTicket" + suffix,
8733 config: Config{
8734 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008735 },
8736 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008737 })
8738
David Benjamincd2c8062016-09-09 11:28:16 -04008739 ret = append(ret, perMessageTest{
8740 messageType: typeFinished,
8741 test: testCase{
8742 protocol: protocol,
8743 name: "ServerFinished" + suffix,
8744 config: Config{
8745 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008746 },
8747 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008748 })
8749
8750 }
David Benjamincd2c8062016-09-09 11:28:16 -04008751
8752 ret = append(ret, perMessageTest{
8753 messageType: typeClientHello,
8754 test: testCase{
8755 testType: serverTest,
8756 name: "TLS13-ClientHello",
8757 config: Config{
8758 MaxVersion: VersionTLS13,
8759 },
8760 },
8761 })
8762
8763 ret = append(ret, perMessageTest{
8764 messageType: typeServerHello,
8765 test: testCase{
8766 name: "TLS13-ServerHello",
8767 config: Config{
8768 MaxVersion: VersionTLS13,
8769 },
8770 },
8771 })
8772
8773 ret = append(ret, perMessageTest{
8774 messageType: typeEncryptedExtensions,
8775 test: testCase{
8776 name: "TLS13-EncryptedExtensions",
8777 config: Config{
8778 MaxVersion: VersionTLS13,
8779 },
8780 },
8781 })
8782
8783 ret = append(ret, perMessageTest{
8784 messageType: typeCertificateRequest,
8785 test: testCase{
8786 name: "TLS13-CertificateRequest",
8787 config: Config{
8788 MaxVersion: VersionTLS13,
8789 ClientAuth: RequireAnyClientCert,
8790 },
8791 },
8792 })
8793
8794 ret = append(ret, perMessageTest{
8795 messageType: typeCertificate,
8796 test: testCase{
8797 name: "TLS13-ServerCertificate",
8798 config: Config{
8799 MaxVersion: VersionTLS13,
8800 },
8801 },
8802 })
8803
8804 ret = append(ret, perMessageTest{
8805 messageType: typeCertificateVerify,
8806 test: testCase{
8807 name: "TLS13-ServerCertificateVerify",
8808 config: Config{
8809 MaxVersion: VersionTLS13,
8810 },
8811 },
8812 })
8813
8814 ret = append(ret, perMessageTest{
8815 messageType: typeFinished,
8816 test: testCase{
8817 name: "TLS13-ServerFinished",
8818 config: Config{
8819 MaxVersion: VersionTLS13,
8820 },
8821 },
8822 })
8823
8824 ret = append(ret, perMessageTest{
8825 messageType: typeCertificate,
8826 test: testCase{
8827 testType: serverTest,
8828 name: "TLS13-ClientCertificate",
8829 config: Config{
8830 Certificates: []Certificate{rsaCertificate},
8831 MaxVersion: VersionTLS13,
8832 },
8833 flags: []string{"-require-any-client-certificate"},
8834 },
8835 })
8836
8837 ret = append(ret, perMessageTest{
8838 messageType: typeCertificateVerify,
8839 test: testCase{
8840 testType: serverTest,
8841 name: "TLS13-ClientCertificateVerify",
8842 config: Config{
8843 Certificates: []Certificate{rsaCertificate},
8844 MaxVersion: VersionTLS13,
8845 },
8846 flags: []string{"-require-any-client-certificate"},
8847 },
8848 })
8849
8850 ret = append(ret, perMessageTest{
8851 messageType: typeFinished,
8852 test: testCase{
8853 testType: serverTest,
8854 name: "TLS13-ClientFinished",
8855 config: Config{
8856 MaxVersion: VersionTLS13,
8857 },
8858 },
8859 })
8860
8861 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008862}
8863
David Benjamincd2c8062016-09-09 11:28:16 -04008864func addWrongMessageTypeTests() {
8865 for _, t := range makePerMessageTests() {
8866 t.test.name = "WrongMessageType-" + t.test.name
8867 t.test.config.Bugs.SendWrongMessageType = t.messageType
8868 t.test.shouldFail = true
8869 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8870 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008871
David Benjamincd2c8062016-09-09 11:28:16 -04008872 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8873 // In TLS 1.3, a bad ServerHello means the client sends
8874 // an unencrypted alert while the server expects
8875 // encryption, so the alert is not readable by runner.
8876 t.test.expectedLocalError = "local error: bad record MAC"
8877 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008878
David Benjamincd2c8062016-09-09 11:28:16 -04008879 testCases = append(testCases, t.test)
8880 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008881}
8882
David Benjamin639846e2016-09-09 11:41:18 -04008883func addTrailingMessageDataTests() {
8884 for _, t := range makePerMessageTests() {
8885 t.test.name = "TrailingMessageData-" + t.test.name
8886 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8887 t.test.shouldFail = true
8888 t.test.expectedError = ":DECODE_ERROR:"
8889 t.test.expectedLocalError = "remote error: error decoding message"
8890
8891 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8892 // In TLS 1.3, a bad ServerHello means the client sends
8893 // an unencrypted alert while the server expects
8894 // encryption, so the alert is not readable by runner.
8895 t.test.expectedLocalError = "local error: bad record MAC"
8896 }
8897
8898 if t.messageType == typeFinished {
8899 // Bad Finished messages read as the verify data having
8900 // the wrong length.
8901 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8902 t.test.expectedLocalError = "remote error: error decrypting message"
8903 }
8904
8905 testCases = append(testCases, t.test)
8906 }
8907}
8908
Steven Valdez143e8b32016-07-11 13:19:03 -04008909func addTLS13HandshakeTests() {
8910 testCases = append(testCases, testCase{
8911 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008912 name: "NegotiatePSKResumption-TLS13",
8913 config: Config{
8914 MaxVersion: VersionTLS13,
8915 Bugs: ProtocolBugs{
8916 NegotiatePSKResumption: true,
8917 },
8918 },
8919 resumeSession: true,
8920 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05008921 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04008922 })
8923
8924 testCases = append(testCases, testCase{
8925 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008926 name: "MissingKeyShare-Client",
8927 config: Config{
8928 MaxVersion: VersionTLS13,
8929 Bugs: ProtocolBugs{
8930 MissingKeyShare: true,
8931 },
8932 },
8933 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05008934 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008935 })
8936
8937 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008938 testType: serverTest,
8939 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008940 config: Config{
8941 MaxVersion: VersionTLS13,
8942 Bugs: ProtocolBugs{
8943 MissingKeyShare: true,
8944 },
8945 },
8946 shouldFail: true,
8947 expectedError: ":MISSING_KEY_SHARE:",
8948 })
8949
8950 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008951 testType: serverTest,
8952 name: "DuplicateKeyShares",
8953 config: Config{
8954 MaxVersion: VersionTLS13,
8955 Bugs: ProtocolBugs{
8956 DuplicateKeyShares: true,
8957 },
8958 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008959 shouldFail: true,
8960 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008961 })
8962
8963 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05008964 testType: serverTest,
8965 name: "SkipEarlyData",
8966 config: Config{
8967 MaxVersion: VersionTLS13,
8968 Bugs: ProtocolBugs{
8969 SendEarlyDataLength: 4,
8970 },
8971 },
8972 })
8973
8974 testCases = append(testCases, testCase{
8975 testType: serverTest,
8976 name: "SkipEarlyData-OmitEarlyDataExtension",
8977 config: Config{
8978 MaxVersion: VersionTLS13,
8979 Bugs: ProtocolBugs{
8980 SendEarlyDataLength: 4,
8981 OmitEarlyDataExtension: true,
8982 },
8983 },
8984 shouldFail: true,
8985 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8986 })
8987
8988 testCases = append(testCases, testCase{
8989 testType: serverTest,
8990 name: "SkipEarlyData-TooMuchData",
8991 config: Config{
8992 MaxVersion: VersionTLS13,
8993 Bugs: ProtocolBugs{
8994 SendEarlyDataLength: 16384 + 1,
8995 },
8996 },
8997 shouldFail: true,
8998 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
8999 })
9000
9001 testCases = append(testCases, testCase{
9002 testType: serverTest,
9003 name: "SkipEarlyData-Interleaved",
9004 config: Config{
9005 MaxVersion: VersionTLS13,
9006 Bugs: ProtocolBugs{
9007 SendEarlyDataLength: 4,
9008 InterleaveEarlyData: true,
9009 },
9010 },
9011 shouldFail: true,
9012 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9013 })
9014
9015 testCases = append(testCases, testCase{
9016 testType: serverTest,
9017 name: "SkipEarlyData-EarlyDataInTLS12",
9018 config: Config{
9019 MaxVersion: VersionTLS13,
9020 Bugs: ProtocolBugs{
9021 SendEarlyDataLength: 4,
9022 },
9023 },
9024 shouldFail: true,
9025 expectedError: ":UNEXPECTED_RECORD:",
9026 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9027 })
9028
9029 testCases = append(testCases, testCase{
9030 testType: serverTest,
9031 name: "SkipEarlyData-HRR",
9032 config: Config{
9033 MaxVersion: VersionTLS13,
9034 Bugs: ProtocolBugs{
9035 SendEarlyDataLength: 4,
9036 },
9037 DefaultCurves: []CurveID{},
9038 },
9039 })
9040
9041 testCases = append(testCases, testCase{
9042 testType: serverTest,
9043 name: "SkipEarlyData-HRR-Interleaved",
9044 config: Config{
9045 MaxVersion: VersionTLS13,
9046 Bugs: ProtocolBugs{
9047 SendEarlyDataLength: 4,
9048 InterleaveEarlyData: true,
9049 },
9050 DefaultCurves: []CurveID{},
9051 },
9052 shouldFail: true,
9053 expectedError: ":UNEXPECTED_RECORD:",
9054 })
9055
9056 testCases = append(testCases, testCase{
9057 testType: serverTest,
9058 name: "SkipEarlyData-HRR-TooMuchData",
9059 config: Config{
9060 MaxVersion: VersionTLS13,
9061 Bugs: ProtocolBugs{
9062 SendEarlyDataLength: 16384 + 1,
9063 },
9064 DefaultCurves: []CurveID{},
9065 },
9066 shouldFail: true,
9067 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9068 })
9069
9070 // Test that skipping early data looking for cleartext correctly
9071 // processes an alert record.
9072 testCases = append(testCases, testCase{
9073 testType: serverTest,
9074 name: "SkipEarlyData-HRR-FatalAlert",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 Bugs: ProtocolBugs{
9078 SendEarlyAlert: true,
9079 SendEarlyDataLength: 4,
9080 },
9081 DefaultCurves: []CurveID{},
9082 },
9083 shouldFail: true,
9084 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9085 })
9086
9087 testCases = append(testCases, testCase{
9088 testType: serverTest,
9089 name: "SkipEarlyData-SecondClientHelloEarlyData",
9090 config: Config{
9091 MaxVersion: VersionTLS13,
9092 Bugs: ProtocolBugs{
9093 SendEarlyDataOnSecondClientHello: true,
9094 },
9095 DefaultCurves: []CurveID{},
9096 },
9097 shouldFail: true,
9098 expectedLocalError: "remote error: bad record MAC",
9099 })
9100
9101 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009102 testType: clientTest,
9103 name: "EmptyEncryptedExtensions",
9104 config: Config{
9105 MaxVersion: VersionTLS13,
9106 Bugs: ProtocolBugs{
9107 EmptyEncryptedExtensions: true,
9108 },
9109 },
9110 shouldFail: true,
9111 expectedLocalError: "remote error: error decoding message",
9112 })
9113
9114 testCases = append(testCases, testCase{
9115 testType: clientTest,
9116 name: "EncryptedExtensionsWithKeyShare",
9117 config: Config{
9118 MaxVersion: VersionTLS13,
9119 Bugs: ProtocolBugs{
9120 EncryptedExtensionsWithKeyShare: true,
9121 },
9122 },
9123 shouldFail: true,
9124 expectedLocalError: "remote error: unsupported extension",
9125 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009126
9127 testCases = append(testCases, testCase{
9128 testType: serverTest,
9129 name: "SendHelloRetryRequest",
9130 config: Config{
9131 MaxVersion: VersionTLS13,
9132 // Require a HelloRetryRequest for every curve.
9133 DefaultCurves: []CurveID{},
9134 },
9135 expectedCurveID: CurveX25519,
9136 })
9137
9138 testCases = append(testCases, testCase{
9139 testType: serverTest,
9140 name: "SendHelloRetryRequest-2",
9141 config: Config{
9142 MaxVersion: VersionTLS13,
9143 DefaultCurves: []CurveID{CurveP384},
9144 },
9145 // Although the ClientHello did not predict our preferred curve,
9146 // we always select it whether it is predicted or not.
9147 expectedCurveID: CurveX25519,
9148 })
9149
9150 testCases = append(testCases, testCase{
9151 name: "UnknownCurve-HelloRetryRequest",
9152 config: Config{
9153 MaxVersion: VersionTLS13,
9154 // P-384 requires HelloRetryRequest in BoringSSL.
9155 CurvePreferences: []CurveID{CurveP384},
9156 Bugs: ProtocolBugs{
9157 SendHelloRetryRequestCurve: bogusCurve,
9158 },
9159 },
9160 shouldFail: true,
9161 expectedError: ":WRONG_CURVE:",
9162 })
9163
9164 testCases = append(testCases, testCase{
9165 name: "DisabledCurve-HelloRetryRequest",
9166 config: Config{
9167 MaxVersion: VersionTLS13,
9168 CurvePreferences: []CurveID{CurveP256},
9169 Bugs: ProtocolBugs{
9170 IgnorePeerCurvePreferences: true,
9171 },
9172 },
9173 flags: []string{"-p384-only"},
9174 shouldFail: true,
9175 expectedError: ":WRONG_CURVE:",
9176 })
9177
9178 testCases = append(testCases, testCase{
9179 name: "UnnecessaryHelloRetryRequest",
9180 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009181 MaxVersion: VersionTLS13,
9182 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009183 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009184 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009185 },
9186 },
9187 shouldFail: true,
9188 expectedError: ":WRONG_CURVE:",
9189 })
9190
9191 testCases = append(testCases, testCase{
9192 name: "SecondHelloRetryRequest",
9193 config: Config{
9194 MaxVersion: VersionTLS13,
9195 // P-384 requires HelloRetryRequest in BoringSSL.
9196 CurvePreferences: []CurveID{CurveP384},
9197 Bugs: ProtocolBugs{
9198 SecondHelloRetryRequest: true,
9199 },
9200 },
9201 shouldFail: true,
9202 expectedError: ":UNEXPECTED_MESSAGE:",
9203 })
9204
9205 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009206 name: "HelloRetryRequest-Empty",
9207 config: Config{
9208 MaxVersion: VersionTLS13,
9209 Bugs: ProtocolBugs{
9210 AlwaysSendHelloRetryRequest: true,
9211 },
9212 },
9213 shouldFail: true,
9214 expectedError: ":DECODE_ERROR:",
9215 })
9216
9217 testCases = append(testCases, testCase{
9218 name: "HelloRetryRequest-DuplicateCurve",
9219 config: Config{
9220 MaxVersion: VersionTLS13,
9221 // P-384 requires a HelloRetryRequest against BoringSSL's default
9222 // configuration. Assert this ExpectMissingKeyShare.
9223 CurvePreferences: []CurveID{CurveP384},
9224 Bugs: ProtocolBugs{
9225 ExpectMissingKeyShare: true,
9226 DuplicateHelloRetryRequestExtensions: true,
9227 },
9228 },
9229 shouldFail: true,
9230 expectedError: ":DUPLICATE_EXTENSION:",
9231 expectedLocalError: "remote error: illegal parameter",
9232 })
9233
9234 testCases = append(testCases, testCase{
9235 name: "HelloRetryRequest-Cookie",
9236 config: Config{
9237 MaxVersion: VersionTLS13,
9238 Bugs: ProtocolBugs{
9239 SendHelloRetryRequestCookie: []byte("cookie"),
9240 },
9241 },
9242 })
9243
9244 testCases = append(testCases, testCase{
9245 name: "HelloRetryRequest-DuplicateCookie",
9246 config: Config{
9247 MaxVersion: VersionTLS13,
9248 Bugs: ProtocolBugs{
9249 SendHelloRetryRequestCookie: []byte("cookie"),
9250 DuplicateHelloRetryRequestExtensions: true,
9251 },
9252 },
9253 shouldFail: true,
9254 expectedError: ":DUPLICATE_EXTENSION:",
9255 expectedLocalError: "remote error: illegal parameter",
9256 })
9257
9258 testCases = append(testCases, testCase{
9259 name: "HelloRetryRequest-EmptyCookie",
9260 config: Config{
9261 MaxVersion: VersionTLS13,
9262 Bugs: ProtocolBugs{
9263 SendHelloRetryRequestCookie: []byte{},
9264 },
9265 },
9266 shouldFail: true,
9267 expectedError: ":DECODE_ERROR:",
9268 })
9269
9270 testCases = append(testCases, testCase{
9271 name: "HelloRetryRequest-Cookie-Curve",
9272 config: Config{
9273 MaxVersion: VersionTLS13,
9274 // P-384 requires HelloRetryRequest in BoringSSL.
9275 CurvePreferences: []CurveID{CurveP384},
9276 Bugs: ProtocolBugs{
9277 SendHelloRetryRequestCookie: []byte("cookie"),
9278 ExpectMissingKeyShare: true,
9279 },
9280 },
9281 })
9282
9283 testCases = append(testCases, testCase{
9284 name: "HelloRetryRequest-Unknown",
9285 config: Config{
9286 MaxVersion: VersionTLS13,
9287 Bugs: ProtocolBugs{
9288 CustomHelloRetryRequestExtension: "extension",
9289 },
9290 },
9291 shouldFail: true,
9292 expectedError: ":UNEXPECTED_EXTENSION:",
9293 expectedLocalError: "remote error: unsupported extension",
9294 })
9295
9296 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009297 testType: serverTest,
9298 name: "SecondClientHelloMissingKeyShare",
9299 config: Config{
9300 MaxVersion: VersionTLS13,
9301 DefaultCurves: []CurveID{},
9302 Bugs: ProtocolBugs{
9303 SecondClientHelloMissingKeyShare: true,
9304 },
9305 },
9306 shouldFail: true,
9307 expectedError: ":MISSING_KEY_SHARE:",
9308 })
9309
9310 testCases = append(testCases, testCase{
9311 testType: serverTest,
9312 name: "SecondClientHelloWrongCurve",
9313 config: Config{
9314 MaxVersion: VersionTLS13,
9315 DefaultCurves: []CurveID{},
9316 Bugs: ProtocolBugs{
9317 MisinterpretHelloRetryRequestCurve: CurveP521,
9318 },
9319 },
9320 shouldFail: true,
9321 expectedError: ":WRONG_CURVE:",
9322 })
9323
9324 testCases = append(testCases, testCase{
9325 name: "HelloRetryRequestVersionMismatch",
9326 config: Config{
9327 MaxVersion: VersionTLS13,
9328 // P-384 requires HelloRetryRequest in BoringSSL.
9329 CurvePreferences: []CurveID{CurveP384},
9330 Bugs: ProtocolBugs{
9331 SendServerHelloVersion: 0x0305,
9332 },
9333 },
9334 shouldFail: true,
9335 expectedError: ":WRONG_VERSION_NUMBER:",
9336 })
9337
9338 testCases = append(testCases, testCase{
9339 name: "HelloRetryRequestCurveMismatch",
9340 config: Config{
9341 MaxVersion: VersionTLS13,
9342 // P-384 requires HelloRetryRequest in BoringSSL.
9343 CurvePreferences: []CurveID{CurveP384},
9344 Bugs: ProtocolBugs{
9345 // Send P-384 (correct) in the HelloRetryRequest.
9346 SendHelloRetryRequestCurve: CurveP384,
9347 // But send P-256 in the ServerHello.
9348 SendCurve: CurveP256,
9349 },
9350 },
9351 shouldFail: true,
9352 expectedError: ":WRONG_CURVE:",
9353 })
9354
9355 // Test the server selecting a curve that requires a HelloRetryRequest
9356 // without sending it.
9357 testCases = append(testCases, testCase{
9358 name: "SkipHelloRetryRequest",
9359 config: Config{
9360 MaxVersion: VersionTLS13,
9361 // P-384 requires HelloRetryRequest in BoringSSL.
9362 CurvePreferences: []CurveID{CurveP384},
9363 Bugs: ProtocolBugs{
9364 SkipHelloRetryRequest: true,
9365 },
9366 },
9367 shouldFail: true,
9368 expectedError: ":WRONG_CURVE:",
9369 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009370
9371 testCases = append(testCases, testCase{
9372 name: "TLS13-RequestContextInHandshake",
9373 config: Config{
9374 MaxVersion: VersionTLS13,
9375 MinVersion: VersionTLS13,
9376 ClientAuth: RequireAnyClientCert,
9377 Bugs: ProtocolBugs{
9378 SendRequestContext: []byte("request context"),
9379 },
9380 },
9381 flags: []string{
9382 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9383 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9384 },
9385 shouldFail: true,
9386 expectedError: ":DECODE_ERROR:",
9387 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009388
9389 testCases = append(testCases, testCase{
9390 testType: serverTest,
9391 name: "TLS13-TrailingKeyShareData",
9392 config: Config{
9393 MaxVersion: VersionTLS13,
9394 Bugs: ProtocolBugs{
9395 TrailingKeyShareData: true,
9396 },
9397 },
9398 shouldFail: true,
9399 expectedError: ":DECODE_ERROR:",
9400 })
David Benjamin7f78df42016-10-05 22:33:19 -04009401
9402 testCases = append(testCases, testCase{
9403 name: "TLS13-AlwaysSelectPSKIdentity",
9404 config: Config{
9405 MaxVersion: VersionTLS13,
9406 Bugs: ProtocolBugs{
9407 AlwaysSelectPSKIdentity: true,
9408 },
9409 },
9410 shouldFail: true,
9411 expectedError: ":UNEXPECTED_EXTENSION:",
9412 })
9413
9414 testCases = append(testCases, testCase{
9415 name: "TLS13-InvalidPSKIdentity",
9416 config: Config{
9417 MaxVersion: VersionTLS13,
9418 Bugs: ProtocolBugs{
9419 SelectPSKIdentityOnResume: 1,
9420 },
9421 },
9422 resumeSession: true,
9423 shouldFail: true,
9424 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9425 })
David Benjamin1286bee2016-10-07 15:25:06 -04009426
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009427 testCases = append(testCases, testCase{
9428 testType: serverTest,
9429 name: "TLS13-ExtraPSKIdentity",
9430 config: Config{
9431 MaxVersion: VersionTLS13,
9432 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009433 ExtraPSKIdentity: true,
9434 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009435 },
9436 },
9437 resumeSession: true,
9438 })
9439
David Benjamin1286bee2016-10-07 15:25:06 -04009440 // Test that unknown NewSessionTicket extensions are tolerated.
9441 testCases = append(testCases, testCase{
9442 name: "TLS13-CustomTicketExtension",
9443 config: Config{
9444 MaxVersion: VersionTLS13,
9445 Bugs: ProtocolBugs{
9446 CustomTicketExtension: "1234",
9447 },
9448 },
9449 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009450}
9451
David Benjaminabbbee12016-10-31 19:20:42 -04009452func addTLS13CipherPreferenceTests() {
9453 // Test that client preference is honored if the shim has AES hardware
9454 // and ChaCha20-Poly1305 is preferred otherwise.
9455 testCases = append(testCases, testCase{
9456 testType: serverTest,
9457 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9458 config: Config{
9459 MaxVersion: VersionTLS13,
9460 CipherSuites: []uint16{
9461 TLS_CHACHA20_POLY1305_SHA256,
9462 TLS_AES_128_GCM_SHA256,
9463 },
9464 },
9465 flags: []string{
9466 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9467 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9468 },
9469 })
9470
9471 testCases = append(testCases, testCase{
9472 testType: serverTest,
9473 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9474 config: Config{
9475 MaxVersion: VersionTLS13,
9476 CipherSuites: []uint16{
9477 TLS_AES_128_GCM_SHA256,
9478 TLS_CHACHA20_POLY1305_SHA256,
9479 },
9480 },
9481 flags: []string{
9482 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9483 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9484 },
9485 })
9486
9487 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9488 // whether it has AES hardware.
9489 testCases = append(testCases, testCase{
9490 name: "TLS13-CipherPreference-Client",
9491 config: Config{
9492 MaxVersion: VersionTLS13,
9493 // Use the client cipher order. (This is the default but
9494 // is listed to be explicit.)
9495 PreferServerCipherSuites: false,
9496 },
9497 flags: []string{
9498 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9499 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9500 },
9501 })
9502}
9503
David Benjaminf3fbade2016-09-19 13:08:16 -04009504func addPeekTests() {
9505 // Test SSL_peek works, including on empty records.
9506 testCases = append(testCases, testCase{
9507 name: "Peek-Basic",
9508 sendEmptyRecords: 1,
9509 flags: []string{"-peek-then-read"},
9510 })
9511
9512 // Test SSL_peek can drive the initial handshake.
9513 testCases = append(testCases, testCase{
9514 name: "Peek-ImplicitHandshake",
9515 flags: []string{
9516 "-peek-then-read",
9517 "-implicit-handshake",
9518 },
9519 })
9520
9521 // Test SSL_peek can discover and drive a renegotiation.
9522 testCases = append(testCases, testCase{
9523 name: "Peek-Renegotiate",
9524 config: Config{
9525 MaxVersion: VersionTLS12,
9526 },
9527 renegotiate: 1,
9528 flags: []string{
9529 "-peek-then-read",
9530 "-renegotiate-freely",
9531 "-expect-total-renegotiations", "1",
9532 },
9533 })
9534
9535 // Test SSL_peek can discover a close_notify.
9536 testCases = append(testCases, testCase{
9537 name: "Peek-Shutdown",
9538 config: Config{
9539 Bugs: ProtocolBugs{
9540 ExpectCloseNotify: true,
9541 },
9542 },
9543 flags: []string{
9544 "-peek-then-read",
9545 "-check-close-notify",
9546 },
9547 })
9548
9549 // Test SSL_peek can discover an alert.
9550 testCases = append(testCases, testCase{
9551 name: "Peek-Alert",
9552 config: Config{
9553 Bugs: ProtocolBugs{
9554 SendSpuriousAlert: alertRecordOverflow,
9555 },
9556 },
9557 flags: []string{"-peek-then-read"},
9558 shouldFail: true,
9559 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9560 })
9561
9562 // Test SSL_peek can handle KeyUpdate.
9563 testCases = append(testCases, testCase{
9564 name: "Peek-KeyUpdate",
9565 config: Config{
9566 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009567 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009568 sendKeyUpdates: 1,
9569 keyUpdateRequest: keyUpdateNotRequested,
9570 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009571 })
9572}
9573
David Benjamine6f22212016-11-08 14:28:24 -05009574func addRecordVersionTests() {
9575 for _, ver := range tlsVersions {
9576 // Test that the record version is enforced.
9577 testCases = append(testCases, testCase{
9578 name: "CheckRecordVersion-" + ver.name,
9579 config: Config{
9580 MinVersion: ver.version,
9581 MaxVersion: ver.version,
9582 Bugs: ProtocolBugs{
9583 SendRecordVersion: 0x03ff,
9584 },
9585 },
9586 shouldFail: true,
9587 expectedError: ":WRONG_VERSION_NUMBER:",
9588 })
9589
9590 // Test that the ClientHello may use any record version, for
9591 // compatibility reasons.
9592 testCases = append(testCases, testCase{
9593 testType: serverTest,
9594 name: "LooseInitialRecordVersion-" + ver.name,
9595 config: Config{
9596 MinVersion: ver.version,
9597 MaxVersion: ver.version,
9598 Bugs: ProtocolBugs{
9599 SendInitialRecordVersion: 0x03ff,
9600 },
9601 },
9602 })
9603
9604 // Test that garbage ClientHello record versions are rejected.
9605 testCases = append(testCases, testCase{
9606 testType: serverTest,
9607 name: "GarbageInitialRecordVersion-" + ver.name,
9608 config: Config{
9609 MinVersion: ver.version,
9610 MaxVersion: ver.version,
9611 Bugs: ProtocolBugs{
9612 SendInitialRecordVersion: 0xffff,
9613 },
9614 },
9615 shouldFail: true,
9616 expectedError: ":WRONG_VERSION_NUMBER:",
9617 })
9618 }
9619}
9620
David Benjamin2c516452016-11-15 10:16:54 +09009621func addCertificateTests() {
9622 // Test that a certificate chain with intermediate may be sent and
9623 // received as both client and server.
9624 for _, ver := range tlsVersions {
9625 testCases = append(testCases, testCase{
9626 testType: clientTest,
9627 name: "SendReceiveIntermediate-Client-" + ver.name,
9628 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009629 MinVersion: ver.version,
9630 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009631 Certificates: []Certificate{rsaChainCertificate},
9632 ClientAuth: RequireAnyClientCert,
9633 },
9634 expectPeerCertificate: &rsaChainCertificate,
9635 flags: []string{
9636 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9637 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9638 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9639 },
9640 })
9641
9642 testCases = append(testCases, testCase{
9643 testType: serverTest,
9644 name: "SendReceiveIntermediate-Server-" + ver.name,
9645 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009646 MinVersion: ver.version,
9647 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009648 Certificates: []Certificate{rsaChainCertificate},
9649 },
9650 expectPeerCertificate: &rsaChainCertificate,
9651 flags: []string{
9652 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9653 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9654 "-require-any-client-certificate",
9655 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9656 },
9657 })
9658 }
9659}
9660
David Benjaminbbaf3672016-11-17 10:53:09 +09009661func addRetainOnlySHA256ClientCertTests() {
9662 for _, ver := range tlsVersions {
9663 // Test that enabling
9664 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9665 // actually requesting a client certificate is a no-op.
9666 testCases = append(testCases, testCase{
9667 testType: serverTest,
9668 name: "RetainOnlySHA256-NoCert-" + ver.name,
9669 config: Config{
9670 MinVersion: ver.version,
9671 MaxVersion: ver.version,
9672 },
9673 flags: []string{
9674 "-retain-only-sha256-client-cert-initial",
9675 "-retain-only-sha256-client-cert-resume",
9676 },
9677 resumeSession: true,
9678 })
9679
9680 // Test that when retaining only a SHA-256 certificate is
9681 // enabled, the hash appears as expected.
9682 testCases = append(testCases, testCase{
9683 testType: serverTest,
9684 name: "RetainOnlySHA256-Cert-" + ver.name,
9685 config: Config{
9686 MinVersion: ver.version,
9687 MaxVersion: ver.version,
9688 Certificates: []Certificate{rsaCertificate},
9689 },
9690 flags: []string{
9691 "-verify-peer",
9692 "-retain-only-sha256-client-cert-initial",
9693 "-retain-only-sha256-client-cert-resume",
9694 "-expect-sha256-client-cert-initial",
9695 "-expect-sha256-client-cert-resume",
9696 },
9697 resumeSession: true,
9698 })
9699
9700 // Test that when the config changes from on to off, a
9701 // resumption is rejected because the server now wants the full
9702 // certificate chain.
9703 testCases = append(testCases, testCase{
9704 testType: serverTest,
9705 name: "RetainOnlySHA256-OnOff-" + ver.name,
9706 config: Config{
9707 MinVersion: ver.version,
9708 MaxVersion: ver.version,
9709 Certificates: []Certificate{rsaCertificate},
9710 },
9711 flags: []string{
9712 "-verify-peer",
9713 "-retain-only-sha256-client-cert-initial",
9714 "-expect-sha256-client-cert-initial",
9715 },
9716 resumeSession: true,
9717 expectResumeRejected: true,
9718 })
9719
9720 // Test that when the config changes from off to on, a
9721 // resumption is rejected because the server now wants just the
9722 // hash.
9723 testCases = append(testCases, testCase{
9724 testType: serverTest,
9725 name: "RetainOnlySHA256-OffOn-" + ver.name,
9726 config: Config{
9727 MinVersion: ver.version,
9728 MaxVersion: ver.version,
9729 Certificates: []Certificate{rsaCertificate},
9730 },
9731 flags: []string{
9732 "-verify-peer",
9733 "-retain-only-sha256-client-cert-resume",
9734 "-expect-sha256-client-cert-resume",
9735 },
9736 resumeSession: true,
9737 expectResumeRejected: true,
9738 })
9739 }
9740}
9741
Adam Langleya4b91982016-12-12 12:05:53 -08009742func addECDSAKeyUsageTests() {
9743 p256 := elliptic.P256()
9744 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
9745 if err != nil {
9746 panic(err)
9747 }
9748
9749 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
9750 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
9751 if err != nil {
9752 panic(err)
9753 }
9754
9755 template := x509.Certificate{
9756 SerialNumber: serialNumber,
9757 Subject: pkix.Name{
9758 Organization: []string{"Acme Co"},
9759 },
9760 NotBefore: time.Now(),
9761 NotAfter: time.Now(),
9762
9763 // An ECC certificate with only the keyAgreement key usgae may
9764 // be used with ECDH, but not ECDSA.
9765 KeyUsage: x509.KeyUsageKeyAgreement,
9766 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
9767 BasicConstraintsValid: true,
9768 }
9769
9770 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
9771 if err != nil {
9772 panic(err)
9773 }
9774
9775 cert := Certificate{
9776 Certificate: [][]byte{derBytes},
9777 PrivateKey: priv,
9778 }
9779
9780 for _, ver := range tlsVersions {
9781 if ver.version < VersionTLS12 {
9782 continue
9783 }
9784
9785 testCases = append(testCases, testCase{
9786 testType: clientTest,
9787 name: "ECDSAKeyUsage-" + ver.name,
9788 config: Config{
9789 MinVersion: ver.version,
9790 MaxVersion: ver.version,
9791 Certificates: []Certificate{cert},
9792 },
9793 shouldFail: true,
9794 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
9795 })
9796 }
9797}
9798
David Benjamin6f600d62016-12-21 16:06:54 -05009799func addShortHeaderTests() {
9800 // The short header extension may be negotiated as either client or
9801 // server.
9802 testCases = append(testCases, testCase{
9803 name: "ShortHeader-Client",
9804 config: Config{
9805 MaxVersion: VersionTLS13,
9806 Bugs: ProtocolBugs{
9807 EnableShortHeader: true,
9808 },
9809 },
9810 flags: []string{"-enable-short-header"},
9811 expectShortHeader: true,
9812 })
9813 testCases = append(testCases, testCase{
9814 testType: serverTest,
9815 name: "ShortHeader-Server",
9816 config: Config{
9817 MaxVersion: VersionTLS13,
9818 Bugs: ProtocolBugs{
9819 EnableShortHeader: true,
9820 },
9821 },
9822 flags: []string{"-enable-short-header"},
9823 expectShortHeader: true,
9824 })
9825
9826 // If the peer doesn't support it, it will not be negotiated.
9827 testCases = append(testCases, testCase{
9828 name: "ShortHeader-No-Yes-Client",
9829 config: Config{
9830 MaxVersion: VersionTLS13,
9831 },
9832 flags: []string{"-enable-short-header"},
9833 })
9834 testCases = append(testCases, testCase{
9835 testType: serverTest,
9836 name: "ShortHeader-No-Yes-Server",
9837 config: Config{
9838 MaxVersion: VersionTLS13,
9839 },
9840 flags: []string{"-enable-short-header"},
9841 })
9842
9843 // If we don't support it, it will not be negotiated.
9844 testCases = append(testCases, testCase{
9845 name: "ShortHeader-Yes-No-Client",
9846 config: Config{
9847 MaxVersion: VersionTLS13,
9848 Bugs: ProtocolBugs{
9849 EnableShortHeader: true,
9850 },
9851 },
9852 })
9853 testCases = append(testCases, testCase{
9854 testType: serverTest,
9855 name: "ShortHeader-Yes-No-Server",
9856 config: Config{
9857 MaxVersion: VersionTLS13,
9858 Bugs: ProtocolBugs{
9859 EnableShortHeader: true,
9860 },
9861 },
9862 })
9863
9864 // It will not be negotiated at TLS 1.2.
9865 testCases = append(testCases, testCase{
9866 name: "ShortHeader-TLS12-Client",
9867 config: Config{
9868 MaxVersion: VersionTLS12,
9869 Bugs: ProtocolBugs{
9870 EnableShortHeader: true,
9871 },
9872 },
9873 flags: []string{"-enable-short-header"},
9874 })
9875 testCases = append(testCases, testCase{
9876 testType: serverTest,
9877 name: "ShortHeader-TLS12-Server",
9878 config: Config{
9879 MaxVersion: VersionTLS12,
9880 Bugs: ProtocolBugs{
9881 EnableShortHeader: true,
9882 },
9883 },
9884 flags: []string{"-enable-short-header"},
9885 })
9886
9887 // Servers reject early data and short header sent together.
9888 testCases = append(testCases, testCase{
9889 testType: serverTest,
9890 name: "ShortHeader-EarlyData",
9891 config: Config{
9892 MaxVersion: VersionTLS13,
9893 Bugs: ProtocolBugs{
9894 EnableShortHeader: true,
9895 SendEarlyDataLength: 1,
9896 },
9897 },
9898 flags: []string{"-enable-short-header"},
9899 shouldFail: true,
9900 expectedError: ":UNEXPECTED_EXTENSION:",
9901 })
9902
9903 // Clients reject unsolicited short header extensions.
9904 testCases = append(testCases, testCase{
9905 name: "ShortHeader-Unsolicited",
9906 config: Config{
9907 MaxVersion: VersionTLS13,
9908 Bugs: ProtocolBugs{
9909 AlwaysNegotiateShortHeader: true,
9910 },
9911 },
9912 shouldFail: true,
9913 expectedError: ":UNEXPECTED_EXTENSION:",
9914 })
9915 testCases = append(testCases, testCase{
9916 name: "ShortHeader-Unsolicited-TLS12",
9917 config: Config{
9918 MaxVersion: VersionTLS12,
9919 Bugs: ProtocolBugs{
9920 AlwaysNegotiateShortHeader: true,
9921 },
9922 },
9923 shouldFail: true,
9924 expectedError: ":UNEXPECTED_EXTENSION:",
9925 })
9926
9927 // The high bit must be checked in short headers.
9928 testCases = append(testCases, testCase{
9929 name: "ShortHeader-ClearShortHeaderBit",
9930 config: Config{
9931 Bugs: ProtocolBugs{
9932 EnableShortHeader: true,
9933 ClearShortHeaderBit: true,
9934 },
9935 },
9936 flags: []string{"-enable-short-header"},
9937 shouldFail: true,
9938 expectedError: ":DECODE_ERROR:",
9939 expectedLocalError: "remote error: error decoding message",
9940 })
9941}
9942
Adam Langley7c803a62015-06-15 15:35:05 -07009943func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009944 defer wg.Done()
9945
9946 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009947 var err error
9948
David Benjaminba28dfc2016-11-15 17:47:21 +09009949 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009950 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9951 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009952 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009953 if err != nil {
9954 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9955 }
9956 break
9957 }
9958 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009959 } else if *repeatUntilFailure {
9960 for err == nil {
9961 statusChan <- statusMsg{test: test, started: true}
9962 err = runTest(test, shimPath, -1)
9963 }
9964 } else {
9965 statusChan <- statusMsg{test: test, started: true}
9966 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009967 }
Adam Langley95c29f32014-06-20 12:00:00 -07009968 statusChan <- statusMsg{test: test, err: err}
9969 }
9970}
9971
9972type statusMsg struct {
9973 test *testCase
9974 started bool
9975 err error
9976}
9977
David Benjamin5f237bc2015-02-11 17:14:15 -05009978func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009979 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009980
David Benjamin5f237bc2015-02-11 17:14:15 -05009981 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009982 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009983 if !*pipe {
9984 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009985 var erase string
9986 for i := 0; i < lineLen; i++ {
9987 erase += "\b \b"
9988 }
9989 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009990 }
9991
Adam Langley95c29f32014-06-20 12:00:00 -07009992 if msg.started {
9993 started++
9994 } else {
9995 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009996
9997 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009998 if msg.err == errUnimplemented {
9999 if *pipe {
10000 // Print each test instead of a status line.
10001 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10002 }
10003 unimplemented++
10004 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10005 } else {
10006 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10007 failed++
10008 testOutput.addResult(msg.test.name, "FAIL")
10009 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010010 } else {
10011 if *pipe {
10012 // Print each test instead of a status line.
10013 fmt.Printf("PASSED (%s)\n", msg.test.name)
10014 }
10015 testOutput.addResult(msg.test.name, "PASS")
10016 }
Adam Langley95c29f32014-06-20 12:00:00 -070010017 }
10018
David Benjamin5f237bc2015-02-11 17:14:15 -050010019 if !*pipe {
10020 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010021 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010022 lineLen = len(line)
10023 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010024 }
Adam Langley95c29f32014-06-20 12:00:00 -070010025 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010026
10027 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010028}
10029
10030func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010031 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010032 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010033 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010034
Adam Langley7c803a62015-06-15 15:35:05 -070010035 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010036 addCipherSuiteTests()
10037 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010038 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010039 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010040 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010041 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010042 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010043 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010044 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010045 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010046 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010047 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010048 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010049 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010050 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010051 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010052 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010053 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010054 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010055 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010056 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010057 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010058 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010059 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010060 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010061 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010062 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010063 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010064 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010065 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010066 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010067 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010068 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010069 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010070
10071 var wg sync.WaitGroup
10072
Adam Langley7c803a62015-06-15 15:35:05 -070010073 statusChan := make(chan statusMsg, *numWorkers)
10074 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010075 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010076
EKRf71d7ed2016-08-06 13:25:12 -070010077 if len(*shimConfigFile) != 0 {
10078 encoded, err := ioutil.ReadFile(*shimConfigFile)
10079 if err != nil {
10080 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10081 os.Exit(1)
10082 }
10083
10084 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10085 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10086 os.Exit(1)
10087 }
10088 }
10089
David Benjamin025b3d32014-07-01 19:53:04 -040010090 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010091
Adam Langley7c803a62015-06-15 15:35:05 -070010092 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010093 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010094 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010095 }
10096
David Benjamin270f0a72016-03-17 14:41:36 -040010097 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010098 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010099 matched := true
10100 if len(*testToRun) != 0 {
10101 var err error
10102 matched, err = filepath.Match(*testToRun, testCases[i].name)
10103 if err != nil {
10104 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10105 os.Exit(1)
10106 }
10107 }
10108
EKRf71d7ed2016-08-06 13:25:12 -070010109 if !*includeDisabled {
10110 for pattern := range shimConfig.DisabledTests {
10111 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10112 if err != nil {
10113 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10114 os.Exit(1)
10115 }
10116
10117 if isDisabled {
10118 matched = false
10119 break
10120 }
10121 }
10122 }
10123
David Benjamin17e12922016-07-28 18:04:43 -040010124 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010125 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010126 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010127
10128 // Only run one test if repeating until failure.
10129 if *repeatUntilFailure {
10130 break
10131 }
Adam Langley95c29f32014-06-20 12:00:00 -070010132 }
10133 }
David Benjamin17e12922016-07-28 18:04:43 -040010134
David Benjamin270f0a72016-03-17 14:41:36 -040010135 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010136 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010137 os.Exit(1)
10138 }
Adam Langley95c29f32014-06-20 12:00:00 -070010139
10140 close(testChan)
10141 wg.Wait()
10142 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010143 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010144
10145 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010146
10147 if *jsonOutput != "" {
10148 if err := testOutput.writeTo(*jsonOutput); err != nil {
10149 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10150 }
10151 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010152
EKR842ae6c2016-07-27 09:22:05 +020010153 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10154 os.Exit(1)
10155 }
10156
10157 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010158 os.Exit(1)
10159 }
Adam Langley95c29f32014-06-20 12:00:00 -070010160}