blob: fc66cf697dbeaa1fbc4809526c4084e729664b28 [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
Adam Langley95c29f32014-06-20 12:00:00 -0700386}
387
Adam Langley7c803a62015-06-15 15:35:05 -0700388var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700389
David Benjaminc07afb72016-09-22 10:18:58 -0400390func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 if len(data) == 0 {
392 return
393 }
394
395 protocol := "tls"
396 if test.protocol == dtls {
397 protocol = "dtls"
398 }
399
400 side := "client"
401 if test.testType == serverTest {
402 side = "server"
403 }
404
405 dir := path.Join(*transcriptDir, protocol, side)
406 if err := os.MkdirAll(dir, 0755); err != nil {
407 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
408 return
409 }
410
David Benjaminc07afb72016-09-22 10:18:58 -0400411 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500412 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
413 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
414 }
415}
416
David Benjamin3ed59772016-03-08 12:50:21 -0500417// A timeoutConn implements an idle timeout on each Read and Write operation.
418type timeoutConn struct {
419 net.Conn
420 timeout time.Duration
421}
422
423func (t *timeoutConn) Read(b []byte) (int, error) {
424 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
425 return 0, err
426 }
427 return t.Conn.Read(b)
428}
429
430func (t *timeoutConn) Write(b []byte) (int, error) {
431 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
432 return 0, err
433 }
434 return t.Conn.Write(b)
435}
436
David Benjaminc07afb72016-09-22 10:18:58 -0400437func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400438 if !test.noSessionCache {
439 if config.ClientSessionCache == nil {
440 config.ClientSessionCache = NewLRUClientSessionCache(1)
441 }
442 if config.ServerSessionCache == nil {
443 config.ServerSessionCache = NewLRUServerSessionCache(1)
444 }
445 }
446 if test.testType == clientTest {
447 if len(config.Certificates) == 0 {
448 config.Certificates = []Certificate{rsaCertificate}
449 }
450 } else {
451 // Supply a ServerName to ensure a constant session cache key,
452 // rather than falling back to net.Conn.RemoteAddr.
453 if len(config.ServerName) == 0 {
454 config.ServerName = "test"
455 }
456 }
457 if *fuzzer {
458 config.Bugs.NullAllCiphers = true
459 }
David Benjamin01a90572016-09-22 00:11:43 -0400460 if *deterministic {
461 config.Time = func() time.Time { return time.Unix(1234, 1234) }
462 }
David Benjamine54af062016-08-08 19:21:18 -0400463
David Benjamin01784b42016-06-07 18:00:52 -0400464 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500465
David Benjamin6fd297b2014-08-11 18:43:38 -0400466 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500467 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
468 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500469 }
470
David Benjamin9867b7d2016-03-01 23:25:48 -0500471 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500472 local, peer := "client", "server"
473 if test.testType == clientTest {
474 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500475 }
David Benjaminebda9b32015-11-02 15:33:18 -0500476 connDebug := &recordingConn{
477 Conn: conn,
478 isDatagram: test.protocol == dtls,
479 local: local,
480 peer: peer,
481 }
482 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500483 if *flagDebug {
484 defer connDebug.WriteTo(os.Stdout)
485 }
486 if len(*transcriptDir) != 0 {
487 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400488 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500489 }()
490 }
David Benjaminebda9b32015-11-02 15:33:18 -0500491
492 if config.Bugs.PacketAdaptor != nil {
493 config.Bugs.PacketAdaptor.debug = connDebug
494 }
495 }
496
497 if test.replayWrites {
498 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400499 }
500
David Benjamin3ed59772016-03-08 12:50:21 -0500501 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500502 if test.damageFirstWrite {
503 connDamage = newDamageAdaptor(conn)
504 conn = connDamage
505 }
506
David Benjamin6fd297b2014-08-11 18:43:38 -0400507 if test.sendPrefix != "" {
508 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
509 return err
510 }
David Benjamin98e882e2014-08-08 13:24:34 -0400511 }
512
David Benjamin1d5c83e2014-07-22 19:20:02 -0400513 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400514 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400515 if test.protocol == dtls {
516 tlsConn = DTLSServer(conn, config)
517 } else {
518 tlsConn = Server(conn, config)
519 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400520 } else {
521 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400522 if test.protocol == dtls {
523 tlsConn = DTLSClient(conn, config)
524 } else {
525 tlsConn = Client(conn, config)
526 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400527 }
David Benjamin30789da2015-08-29 22:56:45 -0400528 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400529
Adam Langley95c29f32014-06-20 12:00:00 -0700530 if err := tlsConn.Handshake(); err != nil {
531 return err
532 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700533
David Benjamin01fe8202014-09-24 15:21:44 -0400534 // TODO(davidben): move all per-connection expectations into a dedicated
535 // expectations struct that can be specified separately for the two
536 // legs.
537 expectedVersion := test.expectedVersion
538 if isResume && test.expectedResumeVersion != 0 {
539 expectedVersion = test.expectedResumeVersion
540 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700541 connState := tlsConn.ConnectionState()
542 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400543 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400544 }
545
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700546 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400547 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
548 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700549 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
550 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
551 }
David Benjamin90da8c82015-04-20 14:57:57 -0400552
David Benjamina08e49d2014-08-24 01:46:07 -0400553 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700554 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400555 if channelID == nil {
556 return fmt.Errorf("no channel ID negotiated")
557 }
558 if channelID.Curve != channelIDKey.Curve ||
559 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
560 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
561 return fmt.Errorf("incorrect channel ID")
562 }
563 }
564
David Benjaminae2888f2014-09-06 12:58:58 -0400565 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700566 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400567 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
568 }
569 }
570
David Benjaminc7ce9772015-10-09 19:32:41 -0400571 if test.expectNoNextProto {
572 if actual := connState.NegotiatedProtocol; actual != "" {
573 return fmt.Errorf("got unexpected next proto %s", actual)
574 }
575 }
576
David Benjaminfc7b0862014-09-06 13:21:53 -0400577 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700578 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400579 return fmt.Errorf("next proto type mismatch")
580 }
581 }
582
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700583 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500584 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
585 }
586
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100587 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300588 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100589 }
590
Paul Lietar4fac72e2015-09-09 13:44:55 +0100591 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
592 return fmt.Errorf("SCT list mismatch")
593 }
594
Nick Harper60edffd2016-06-21 15:19:24 -0700595 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
596 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400597 }
598
Steven Valdez5440fe02016-07-18 12:40:30 -0400599 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
600 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
601 }
602
David Benjamin2c516452016-11-15 10:16:54 +0900603 if test.expectPeerCertificate != nil {
604 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
605 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
606 }
607 for i, cert := range connState.PeerCertificates {
608 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
609 return fmt.Errorf("peer certificate %d did not match", i+1)
610 }
611 }
612 }
613
David Benjaminc565ebb2015-04-03 04:06:36 -0400614 if test.exportKeyingMaterial > 0 {
615 actual := make([]byte, test.exportKeyingMaterial)
616 if _, err := io.ReadFull(tlsConn, actual); err != nil {
617 return err
618 }
619 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
620 if err != nil {
621 return err
622 }
623 if !bytes.Equal(actual, expected) {
624 return fmt.Errorf("keying material mismatch")
625 }
626 }
627
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700628 if test.testTLSUnique {
629 var peersValue [12]byte
630 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
631 return err
632 }
633 expected := tlsConn.ConnectionState().TLSUnique
634 if !bytes.Equal(peersValue[:], expected) {
635 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
636 }
637 }
638
David Benjamine58c4f52014-08-24 03:47:07 -0400639 if test.shimWritesFirst {
640 var buf [5]byte
641 _, err := io.ReadFull(tlsConn, buf[:])
642 if err != nil {
643 return err
644 }
645 if string(buf[:]) != "hello" {
646 return fmt.Errorf("bad initial message")
647 }
648 }
649
Steven Valdez32635b82016-08-16 11:25:03 -0400650 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400651 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400652 return err
653 }
Steven Valdez32635b82016-08-16 11:25:03 -0400654 }
655
David Benjamina8ebe222015-06-06 03:04:39 -0400656 for i := 0; i < test.sendEmptyRecords; i++ {
657 tlsConn.Write(nil)
658 }
659
David Benjamin24f346d2015-06-06 03:28:08 -0400660 for i := 0; i < test.sendWarningAlerts; i++ {
661 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
662 }
663
David Benjamin47921102016-07-28 11:29:18 -0400664 if test.sendHalfHelloRequest {
665 tlsConn.SendHalfHelloRequest()
666 }
667
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400668 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700669 if test.renegotiateCiphers != nil {
670 config.CipherSuites = test.renegotiateCiphers
671 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400672 for i := 0; i < test.renegotiate; i++ {
673 if err := tlsConn.Renegotiate(); err != nil {
674 return err
675 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700676 }
677 } else if test.renegotiateCiphers != nil {
678 panic("renegotiateCiphers without renegotiate")
679 }
680
David Benjamin5fa3eba2015-01-22 16:35:40 -0500681 if test.damageFirstWrite {
682 connDamage.setDamage(true)
683 tlsConn.Write([]byte("DAMAGED WRITE"))
684 connDamage.setDamage(false)
685 }
686
David Benjamin8e6db492015-07-25 18:29:23 -0400687 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700688 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400689 if test.protocol == dtls {
690 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
691 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700692 // Read until EOF.
693 _, err := io.Copy(ioutil.Discard, tlsConn)
694 return err
695 }
David Benjamin4417d052015-04-05 04:17:25 -0400696 if messageLen == 0 {
697 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700698 }
Adam Langley95c29f32014-06-20 12:00:00 -0700699
David Benjamin8e6db492015-07-25 18:29:23 -0400700 messageCount := test.messageCount
701 if messageCount == 0 {
702 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400703 }
704
David Benjamin8e6db492015-07-25 18:29:23 -0400705 for j := 0; j < messageCount; j++ {
706 testMessage := make([]byte, messageLen)
707 for i := range testMessage {
708 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400709 }
David Benjamin8e6db492015-07-25 18:29:23 -0400710 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700711
Steven Valdez32635b82016-08-16 11:25:03 -0400712 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400713 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400714 }
715
David Benjamin8e6db492015-07-25 18:29:23 -0400716 for i := 0; i < test.sendEmptyRecords; i++ {
717 tlsConn.Write(nil)
718 }
719
720 for i := 0; i < test.sendWarningAlerts; i++ {
721 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
722 }
723
David Benjamin4f75aaf2015-09-01 16:53:10 -0400724 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400725 // The shim will not respond.
726 continue
727 }
728
David Benjamin8e6db492015-07-25 18:29:23 -0400729 buf := make([]byte, len(testMessage))
730 if test.protocol == dtls {
731 bufTmp := make([]byte, len(buf)+1)
732 n, err := tlsConn.Read(bufTmp)
733 if err != nil {
734 return err
735 }
736 if n != len(buf) {
737 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
738 }
739 copy(buf, bufTmp)
740 } else {
741 _, err := io.ReadFull(tlsConn, buf)
742 if err != nil {
743 return err
744 }
745 }
746
747 for i, v := range buf {
748 if v != testMessage[i]^0xff {
749 return fmt.Errorf("bad reply contents at byte %d", i)
750 }
Adam Langley95c29f32014-06-20 12:00:00 -0700751 }
752 }
753
754 return nil
755}
756
David Benjamin325b5c32014-07-01 19:40:31 -0400757func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400758 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700759 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400760 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700761 }
David Benjamin325b5c32014-07-01 19:40:31 -0400762 valgrindArgs = append(valgrindArgs, path)
763 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700764
David Benjamin325b5c32014-07-01 19:40:31 -0400765 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700766}
767
David Benjamin325b5c32014-07-01 19:40:31 -0400768func gdbOf(path string, args ...string) *exec.Cmd {
769 xtermArgs := []string{"-e", "gdb", "--args"}
770 xtermArgs = append(xtermArgs, path)
771 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772
David Benjamin325b5c32014-07-01 19:40:31 -0400773 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700774}
775
David Benjamind16bf342015-12-18 00:53:12 -0500776func lldbOf(path string, args ...string) *exec.Cmd {
777 xtermArgs := []string{"-e", "lldb", "--"}
778 xtermArgs = append(xtermArgs, path)
779 xtermArgs = append(xtermArgs, args...)
780
781 return exec.Command("xterm", xtermArgs...)
782}
783
EKR842ae6c2016-07-27 09:22:05 +0200784var (
785 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
786 errUnimplemented = errors.New("child process does not implement needed flags")
787)
Adam Langley69a01602014-11-17 17:26:55 -0800788
David Benjamin87c8a642015-02-21 01:54:29 -0500789// accept accepts a connection from listener, unless waitChan signals a process
790// exit first.
791func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
792 type connOrError struct {
793 conn net.Conn
794 err error
795 }
796 connChan := make(chan connOrError, 1)
797 go func() {
798 conn, err := listener.Accept()
799 connChan <- connOrError{conn, err}
800 close(connChan)
801 }()
802 select {
803 case result := <-connChan:
804 return result.conn, result.err
805 case childErr := <-waitChan:
806 waitChan <- childErr
807 return nil, fmt.Errorf("child exited early: %s", childErr)
808 }
809}
810
EKRf71d7ed2016-08-06 13:25:12 -0700811func translateExpectedError(errorStr string) string {
812 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
813 return translated
814 }
815
816 if *looseErrors {
817 return ""
818 }
819
820 return errorStr
821}
822
Adam Langley7c803a62015-06-15 15:35:05 -0700823func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400824 // Help debugging panics on the Go side.
825 defer func() {
826 if r := recover(); r != nil {
827 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
828 panic(r)
829 }
830 }()
831
Adam Langley38311732014-10-16 19:04:35 -0700832 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
833 panic("Error expected without shouldFail in " + test.name)
834 }
835
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700836 if test.expectResumeRejected && !test.resumeSession {
837 panic("expectResumeRejected without resumeSession in " + test.name)
838 }
839
Adam Langley33b1d4f2016-12-07 15:03:45 -0800840 for _, ver := range tlsVersions {
841 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
842 continue
843 }
844
845 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
846 continue
847 }
848
849 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))
850 }
851
David Benjamin87c8a642015-02-21 01:54:29 -0500852 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
853 if err != nil {
854 panic(err)
855 }
856 defer func() {
857 if listener != nil {
858 listener.Close()
859 }
860 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700861
David Benjamin87c8a642015-02-21 01:54:29 -0500862 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400863 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400864 flags = append(flags, "-server")
865
David Benjamin025b3d32014-07-01 19:53:04 -0400866 flags = append(flags, "-key-file")
867 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700868 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400869 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700870 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400871 }
872
873 flags = append(flags, "-cert-file")
874 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700875 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400876 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700877 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400878 }
879 }
David Benjamin5a593af2014-08-11 19:51:50 -0400880
David Benjamin6fd297b2014-08-11 18:43:38 -0400881 if test.protocol == dtls {
882 flags = append(flags, "-dtls")
883 }
884
David Benjamin46662482016-08-17 00:51:00 -0400885 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400886 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400887 resumeCount++
888 if test.resumeRenewedSession {
889 resumeCount++
890 }
891 }
892
893 if resumeCount > 0 {
894 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400895 }
896
David Benjamine58c4f52014-08-24 03:47:07 -0400897 if test.shimWritesFirst {
898 flags = append(flags, "-shim-writes-first")
899 }
900
David Benjamin30789da2015-08-29 22:56:45 -0400901 if test.shimShutsDown {
902 flags = append(flags, "-shim-shuts-down")
903 }
904
David Benjaminc565ebb2015-04-03 04:06:36 -0400905 if test.exportKeyingMaterial > 0 {
906 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
907 flags = append(flags, "-export-label", test.exportLabel)
908 flags = append(flags, "-export-context", test.exportContext)
909 if test.useExportContext {
910 flags = append(flags, "-use-export-context")
911 }
912 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700913 if test.expectResumeRejected {
914 flags = append(flags, "-expect-session-miss")
915 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400916
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700917 if test.testTLSUnique {
918 flags = append(flags, "-tls-unique")
919 }
920
David Benjamin025b3d32014-07-01 19:53:04 -0400921 flags = append(flags, test.flags...)
922
923 var shim *exec.Cmd
924 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700925 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700926 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700927 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500928 } else if *useLLDB {
929 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400930 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700931 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400932 }
David Benjamin025b3d32014-07-01 19:53:04 -0400933 shim.Stdin = os.Stdin
934 var stdoutBuf, stderrBuf bytes.Buffer
935 shim.Stdout = &stdoutBuf
936 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800937 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500938 shim.Env = os.Environ()
939 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800940 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400941 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800942 }
943 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
944 }
David Benjamin025b3d32014-07-01 19:53:04 -0400945
946 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700947 panic(err)
948 }
David Benjamin87c8a642015-02-21 01:54:29 -0500949 waitChan := make(chan error, 1)
950 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700951
952 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700953
David Benjamin7a4aaa42016-09-20 17:58:14 -0400954 if *deterministic {
955 config.Rand = &deterministicRand{}
956 }
957
David Benjamin87c8a642015-02-21 01:54:29 -0500958 conn, err := acceptOrWait(listener, waitChan)
959 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400960 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500961 conn.Close()
962 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500963
David Benjamin46662482016-08-17 00:51:00 -0400964 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400965 var resumeConfig Config
966 if test.resumeConfig != nil {
967 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400968 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500969 resumeConfig.SessionTicketKey = config.SessionTicketKey
970 resumeConfig.ClientSessionCache = config.ClientSessionCache
971 resumeConfig.ServerSessionCache = config.ServerSessionCache
972 }
David Benjamin2e045a92016-06-08 13:09:56 -0400973 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400974 } else {
975 resumeConfig = config
976 }
David Benjamin87c8a642015-02-21 01:54:29 -0500977 var connResume net.Conn
978 connResume, err = acceptOrWait(listener, waitChan)
979 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400980 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500981 connResume.Close()
982 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400983 }
984
David Benjamin87c8a642015-02-21 01:54:29 -0500985 // Close the listener now. This is to avoid hangs should the shim try to
986 // open more connections than expected.
987 listener.Close()
988 listener = nil
989
990 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400991 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800992 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200993 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
994 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800995 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200996 case 89:
997 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400998 case 99:
999 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001000 }
1001 }
Adam Langley95c29f32014-06-20 12:00:00 -07001002
David Benjamin9bea3492016-03-02 10:59:16 -05001003 // Account for Windows line endings.
1004 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1005 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001006
1007 // Separate the errors from the shim and those from tools like
1008 // AddressSanitizer.
1009 var extraStderr string
1010 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1011 stderr = stderrParts[0]
1012 extraStderr = stderrParts[1]
1013 }
1014
Adam Langley95c29f32014-06-20 12:00:00 -07001015 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001016 expectedError := translateExpectedError(test.expectedError)
1017 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001018
Adam Langleyac61fa32014-06-23 12:03:11 -07001019 localError := "none"
1020 if err != nil {
1021 localError = err.Error()
1022 }
1023 if len(test.expectedLocalError) != 0 {
1024 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1025 }
Adam Langley95c29f32014-06-20 12:00:00 -07001026
1027 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001028 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001029 if childErr != nil {
1030 childError = childErr.Error()
1031 }
1032
1033 var msg string
1034 switch {
1035 case failed && !test.shouldFail:
1036 msg = "unexpected failure"
1037 case !failed && test.shouldFail:
1038 msg = "unexpected success"
1039 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001040 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001041 default:
1042 panic("internal error")
1043 }
1044
David Benjamin9aafb642016-09-20 19:36:53 -04001045 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 -07001046 }
1047
David Benjamind2ba8892016-09-20 19:41:04 -04001048 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001049 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001050 }
1051
David Benjamind2ba8892016-09-20 19:41:04 -04001052 if *useValgrind && isValgrindError {
1053 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1054 }
1055
Adam Langley95c29f32014-06-20 12:00:00 -07001056 return nil
1057}
1058
David Benjaminaa012042016-12-10 13:33:05 -05001059type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001060 name string
1061 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001062 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001063 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001064}
1065
1066var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001067 {"SSL3", VersionSSL30, "-no-ssl3", false},
1068 {"TLS1", VersionTLS10, "-no-tls1", true},
1069 {"TLS11", VersionTLS11, "-no-tls11", false},
1070 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001071 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001072}
1073
David Benjaminaa012042016-12-10 13:33:05 -05001074type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001075 name string
1076 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001077}
1078
1079var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001080 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001081 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001082 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001083 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001084 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001085 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001086 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001087 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1088 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001089 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001090 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1091 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001092 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001093 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1094 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001095 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1096 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001097 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001098 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001099 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001100 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001101 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001102 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001103 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001104 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001105 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001106 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001107 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001108 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
David Benjamin48cae082014-10-27 01:06:24 -04001109 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1110 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001111 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1112 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001113 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001114 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1115 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1116 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001117 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001118}
1119
David Benjamin8b8c0062014-11-23 02:47:52 -05001120func hasComponent(suiteName, component string) bool {
1121 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1122}
1123
David Benjaminf7768e42014-08-31 02:06:47 -04001124func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001125 return hasComponent(suiteName, "GCM") ||
1126 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001127 hasComponent(suiteName, "SHA384") ||
1128 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001129}
1130
Nick Harper1fd39d82016-06-14 18:14:35 -07001131func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001132 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001133}
1134
David Benjamin8b8c0062014-11-23 02:47:52 -05001135func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001136 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001137}
1138
Adam Langleya7997f12015-05-14 17:38:50 -07001139func bigFromHex(hex string) *big.Int {
1140 ret, ok := new(big.Int).SetString(hex, 16)
1141 if !ok {
1142 panic("failed to parse hex number 0x" + hex)
1143 }
1144 return ret
1145}
1146
Adam Langley7c803a62015-06-15 15:35:05 -07001147func addBasicTests() {
1148 basicTests := []testCase{
1149 {
Adam Langley7c803a62015-06-15 15:35:05 -07001150 name: "NoFallbackSCSV",
1151 config: Config{
1152 Bugs: ProtocolBugs{
1153 FailIfNotFallbackSCSV: true,
1154 },
1155 },
1156 shouldFail: true,
1157 expectedLocalError: "no fallback SCSV found",
1158 },
1159 {
1160 name: "SendFallbackSCSV",
1161 config: Config{
1162 Bugs: ProtocolBugs{
1163 FailIfNotFallbackSCSV: true,
1164 },
1165 },
1166 flags: []string{"-fallback-scsv"},
1167 },
1168 {
1169 name: "ClientCertificateTypes",
1170 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001171 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001172 ClientAuth: RequestClientCert,
1173 ClientCertificateTypes: []byte{
1174 CertTypeDSSSign,
1175 CertTypeRSASign,
1176 CertTypeECDSASign,
1177 },
1178 },
1179 flags: []string{
1180 "-expect-certificate-types",
1181 base64.StdEncoding.EncodeToString([]byte{
1182 CertTypeDSSSign,
1183 CertTypeRSASign,
1184 CertTypeECDSASign,
1185 }),
1186 },
1187 },
1188 {
Adam Langley7c803a62015-06-15 15:35:05 -07001189 name: "UnauthenticatedECDH",
1190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001191 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001192 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1193 Bugs: ProtocolBugs{
1194 UnauthenticatedECDH: true,
1195 },
1196 },
1197 shouldFail: true,
1198 expectedError: ":UNEXPECTED_MESSAGE:",
1199 },
1200 {
1201 name: "SkipCertificateStatus",
1202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001203 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001204 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1205 Bugs: ProtocolBugs{
1206 SkipCertificateStatus: true,
1207 },
1208 },
1209 flags: []string{
1210 "-enable-ocsp-stapling",
1211 },
1212 },
1213 {
1214 name: "SkipServerKeyExchange",
1215 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001216 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001217 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1218 Bugs: ProtocolBugs{
1219 SkipServerKeyExchange: true,
1220 },
1221 },
1222 shouldFail: true,
1223 expectedError: ":UNEXPECTED_MESSAGE:",
1224 },
1225 {
Adam Langley7c803a62015-06-15 15:35:05 -07001226 testType: serverTest,
1227 name: "Alert",
1228 config: Config{
1229 Bugs: ProtocolBugs{
1230 SendSpuriousAlert: alertRecordOverflow,
1231 },
1232 },
1233 shouldFail: true,
1234 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1235 },
1236 {
1237 protocol: dtls,
1238 testType: serverTest,
1239 name: "Alert-DTLS",
1240 config: Config{
1241 Bugs: ProtocolBugs{
1242 SendSpuriousAlert: alertRecordOverflow,
1243 },
1244 },
1245 shouldFail: true,
1246 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1247 },
1248 {
1249 testType: serverTest,
1250 name: "FragmentAlert",
1251 config: Config{
1252 Bugs: ProtocolBugs{
1253 FragmentAlert: true,
1254 SendSpuriousAlert: alertRecordOverflow,
1255 },
1256 },
1257 shouldFail: true,
1258 expectedError: ":BAD_ALERT:",
1259 },
1260 {
1261 protocol: dtls,
1262 testType: serverTest,
1263 name: "FragmentAlert-DTLS",
1264 config: Config{
1265 Bugs: ProtocolBugs{
1266 FragmentAlert: true,
1267 SendSpuriousAlert: alertRecordOverflow,
1268 },
1269 },
1270 shouldFail: true,
1271 expectedError: ":BAD_ALERT:",
1272 },
1273 {
1274 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001275 name: "DoubleAlert",
1276 config: Config{
1277 Bugs: ProtocolBugs{
1278 DoubleAlert: true,
1279 SendSpuriousAlert: alertRecordOverflow,
1280 },
1281 },
1282 shouldFail: true,
1283 expectedError: ":BAD_ALERT:",
1284 },
1285 {
1286 protocol: dtls,
1287 testType: serverTest,
1288 name: "DoubleAlert-DTLS",
1289 config: Config{
1290 Bugs: ProtocolBugs{
1291 DoubleAlert: true,
1292 SendSpuriousAlert: alertRecordOverflow,
1293 },
1294 },
1295 shouldFail: true,
1296 expectedError: ":BAD_ALERT:",
1297 },
1298 {
Adam Langley7c803a62015-06-15 15:35:05 -07001299 name: "SkipNewSessionTicket",
1300 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001301 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001302 Bugs: ProtocolBugs{
1303 SkipNewSessionTicket: true,
1304 },
1305 },
1306 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001307 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001308 },
1309 {
1310 testType: serverTest,
1311 name: "FallbackSCSV",
1312 config: Config{
1313 MaxVersion: VersionTLS11,
1314 Bugs: ProtocolBugs{
1315 SendFallbackSCSV: true,
1316 },
1317 },
1318 shouldFail: true,
1319 expectedError: ":INAPPROPRIATE_FALLBACK:",
1320 },
1321 {
1322 testType: serverTest,
1323 name: "FallbackSCSV-VersionMatch",
1324 config: Config{
1325 Bugs: ProtocolBugs{
1326 SendFallbackSCSV: true,
1327 },
1328 },
1329 },
1330 {
1331 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001332 name: "FallbackSCSV-VersionMatch-TLS12",
1333 config: Config{
1334 MaxVersion: VersionTLS12,
1335 Bugs: ProtocolBugs{
1336 SendFallbackSCSV: true,
1337 },
1338 },
1339 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1340 },
1341 {
1342 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001343 name: "FragmentedClientVersion",
1344 config: Config{
1345 Bugs: ProtocolBugs{
1346 MaxHandshakeRecordLength: 1,
1347 FragmentClientVersion: true,
1348 },
1349 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001350 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001351 },
1352 {
Adam Langley7c803a62015-06-15 15:35:05 -07001353 testType: serverTest,
1354 name: "HttpGET",
1355 sendPrefix: "GET / HTTP/1.0\n",
1356 shouldFail: true,
1357 expectedError: ":HTTP_REQUEST:",
1358 },
1359 {
1360 testType: serverTest,
1361 name: "HttpPOST",
1362 sendPrefix: "POST / HTTP/1.0\n",
1363 shouldFail: true,
1364 expectedError: ":HTTP_REQUEST:",
1365 },
1366 {
1367 testType: serverTest,
1368 name: "HttpHEAD",
1369 sendPrefix: "HEAD / HTTP/1.0\n",
1370 shouldFail: true,
1371 expectedError: ":HTTP_REQUEST:",
1372 },
1373 {
1374 testType: serverTest,
1375 name: "HttpPUT",
1376 sendPrefix: "PUT / HTTP/1.0\n",
1377 shouldFail: true,
1378 expectedError: ":HTTP_REQUEST:",
1379 },
1380 {
1381 testType: serverTest,
1382 name: "HttpCONNECT",
1383 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1384 shouldFail: true,
1385 expectedError: ":HTTPS_PROXY_REQUEST:",
1386 },
1387 {
1388 testType: serverTest,
1389 name: "Garbage",
1390 sendPrefix: "blah",
1391 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001392 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001393 },
1394 {
Adam Langley7c803a62015-06-15 15:35:05 -07001395 name: "RSAEphemeralKey",
1396 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001397 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001398 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1399 Bugs: ProtocolBugs{
1400 RSAEphemeralKey: true,
1401 },
1402 },
1403 shouldFail: true,
1404 expectedError: ":UNEXPECTED_MESSAGE:",
1405 },
1406 {
1407 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001408 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001409 shouldFail: true,
1410 expectedError: ":WRONG_SSL_VERSION:",
1411 },
1412 {
1413 protocol: dtls,
1414 name: "DisableEverything-DTLS",
1415 flags: []string{"-no-tls12", "-no-tls1"},
1416 shouldFail: true,
1417 expectedError: ":WRONG_SSL_VERSION:",
1418 },
1419 {
Adam Langley7c803a62015-06-15 15:35:05 -07001420 protocol: dtls,
1421 testType: serverTest,
1422 name: "MTU",
1423 config: Config{
1424 Bugs: ProtocolBugs{
1425 MaxPacketLength: 256,
1426 },
1427 },
1428 flags: []string{"-mtu", "256"},
1429 },
1430 {
1431 protocol: dtls,
1432 testType: serverTest,
1433 name: "MTUExceeded",
1434 config: Config{
1435 Bugs: ProtocolBugs{
1436 MaxPacketLength: 255,
1437 },
1438 },
1439 flags: []string{"-mtu", "256"},
1440 shouldFail: true,
1441 expectedLocalError: "dtls: exceeded maximum packet length",
1442 },
1443 {
1444 name: "CertMismatchRSA",
1445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001446 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001447 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001448 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001449 Bugs: ProtocolBugs{
1450 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1451 },
1452 },
1453 shouldFail: true,
1454 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1455 },
1456 {
1457 name: "CertMismatchECDSA",
1458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001459 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001460 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001461 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001462 Bugs: ProtocolBugs{
1463 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1464 },
1465 },
1466 shouldFail: true,
1467 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1468 },
1469 {
1470 name: "EmptyCertificateList",
1471 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001472 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001473 Bugs: ProtocolBugs{
1474 EmptyCertificateList: true,
1475 },
1476 },
1477 shouldFail: true,
1478 expectedError: ":DECODE_ERROR:",
1479 },
1480 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001481 name: "EmptyCertificateList-TLS13",
1482 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001483 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001484 Bugs: ProtocolBugs{
1485 EmptyCertificateList: true,
1486 },
1487 },
1488 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001489 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001490 },
1491 {
Adam Langley7c803a62015-06-15 15:35:05 -07001492 name: "TLSFatalBadPackets",
1493 damageFirstWrite: true,
1494 shouldFail: true,
1495 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1496 },
1497 {
1498 protocol: dtls,
1499 name: "DTLSIgnoreBadPackets",
1500 damageFirstWrite: true,
1501 },
1502 {
1503 protocol: dtls,
1504 name: "DTLSIgnoreBadPackets-Async",
1505 damageFirstWrite: true,
1506 flags: []string{"-async"},
1507 },
1508 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001509 name: "AppDataBeforeHandshake",
1510 config: Config{
1511 Bugs: ProtocolBugs{
1512 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1513 },
1514 },
1515 shouldFail: true,
1516 expectedError: ":UNEXPECTED_RECORD:",
1517 },
1518 {
1519 name: "AppDataBeforeHandshake-Empty",
1520 config: Config{
1521 Bugs: ProtocolBugs{
1522 AppDataBeforeHandshake: []byte{},
1523 },
1524 },
1525 shouldFail: true,
1526 expectedError: ":UNEXPECTED_RECORD:",
1527 },
1528 {
1529 protocol: dtls,
1530 name: "AppDataBeforeHandshake-DTLS",
1531 config: Config{
1532 Bugs: ProtocolBugs{
1533 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1534 },
1535 },
1536 shouldFail: true,
1537 expectedError: ":UNEXPECTED_RECORD:",
1538 },
1539 {
1540 protocol: dtls,
1541 name: "AppDataBeforeHandshake-DTLS-Empty",
1542 config: Config{
1543 Bugs: ProtocolBugs{
1544 AppDataBeforeHandshake: []byte{},
1545 },
1546 },
1547 shouldFail: true,
1548 expectedError: ":UNEXPECTED_RECORD:",
1549 },
1550 {
Adam Langley7c803a62015-06-15 15:35:05 -07001551 name: "AppDataAfterChangeCipherSpec",
1552 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001553 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001554 Bugs: ProtocolBugs{
1555 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1556 },
1557 },
1558 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001559 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001560 },
1561 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001562 name: "AppDataAfterChangeCipherSpec-Empty",
1563 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001564 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001565 Bugs: ProtocolBugs{
1566 AppDataAfterChangeCipherSpec: []byte{},
1567 },
1568 },
1569 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001570 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 },
1572 {
Adam Langley7c803a62015-06-15 15:35:05 -07001573 protocol: dtls,
1574 name: "AppDataAfterChangeCipherSpec-DTLS",
1575 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001576 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001577 Bugs: ProtocolBugs{
1578 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1579 },
1580 },
1581 // BoringSSL's DTLS implementation will drop the out-of-order
1582 // application data.
1583 },
1584 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001585 protocol: dtls,
1586 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1587 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001588 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001589 Bugs: ProtocolBugs{
1590 AppDataAfterChangeCipherSpec: []byte{},
1591 },
1592 },
1593 // BoringSSL's DTLS implementation will drop the out-of-order
1594 // application data.
1595 },
1596 {
Adam Langley7c803a62015-06-15 15:35:05 -07001597 name: "AlertAfterChangeCipherSpec",
1598 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001599 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001600 Bugs: ProtocolBugs{
1601 AlertAfterChangeCipherSpec: alertRecordOverflow,
1602 },
1603 },
1604 shouldFail: true,
1605 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1606 },
1607 {
1608 protocol: dtls,
1609 name: "AlertAfterChangeCipherSpec-DTLS",
1610 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001611 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001612 Bugs: ProtocolBugs{
1613 AlertAfterChangeCipherSpec: alertRecordOverflow,
1614 },
1615 },
1616 shouldFail: true,
1617 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1618 },
1619 {
1620 protocol: dtls,
1621 name: "ReorderHandshakeFragments-Small-DTLS",
1622 config: Config{
1623 Bugs: ProtocolBugs{
1624 ReorderHandshakeFragments: true,
1625 // Small enough that every handshake message is
1626 // fragmented.
1627 MaxHandshakeRecordLength: 2,
1628 },
1629 },
1630 },
1631 {
1632 protocol: dtls,
1633 name: "ReorderHandshakeFragments-Large-DTLS",
1634 config: Config{
1635 Bugs: ProtocolBugs{
1636 ReorderHandshakeFragments: true,
1637 // Large enough that no handshake message is
1638 // fragmented.
1639 MaxHandshakeRecordLength: 2048,
1640 },
1641 },
1642 },
1643 {
1644 protocol: dtls,
1645 name: "MixCompleteMessageWithFragments-DTLS",
1646 config: Config{
1647 Bugs: ProtocolBugs{
1648 ReorderHandshakeFragments: true,
1649 MixCompleteMessageWithFragments: true,
1650 MaxHandshakeRecordLength: 2,
1651 },
1652 },
1653 },
1654 {
1655 name: "SendInvalidRecordType",
1656 config: Config{
1657 Bugs: ProtocolBugs{
1658 SendInvalidRecordType: true,
1659 },
1660 },
1661 shouldFail: true,
1662 expectedError: ":UNEXPECTED_RECORD:",
1663 },
1664 {
1665 protocol: dtls,
1666 name: "SendInvalidRecordType-DTLS",
1667 config: Config{
1668 Bugs: ProtocolBugs{
1669 SendInvalidRecordType: true,
1670 },
1671 },
1672 shouldFail: true,
1673 expectedError: ":UNEXPECTED_RECORD:",
1674 },
1675 {
1676 name: "FalseStart-SkipServerSecondLeg",
1677 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001678 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001679 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1680 NextProtos: []string{"foo"},
1681 Bugs: ProtocolBugs{
1682 SkipNewSessionTicket: true,
1683 SkipChangeCipherSpec: true,
1684 SkipFinished: true,
1685 ExpectFalseStart: true,
1686 },
1687 },
1688 flags: []string{
1689 "-false-start",
1690 "-handshake-never-done",
1691 "-advertise-alpn", "\x03foo",
1692 },
1693 shimWritesFirst: true,
1694 shouldFail: true,
1695 expectedError: ":UNEXPECTED_RECORD:",
1696 },
1697 {
1698 name: "FalseStart-SkipServerSecondLeg-Implicit",
1699 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001700 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001701 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1702 NextProtos: []string{"foo"},
1703 Bugs: ProtocolBugs{
1704 SkipNewSessionTicket: true,
1705 SkipChangeCipherSpec: true,
1706 SkipFinished: true,
1707 },
1708 },
1709 flags: []string{
1710 "-implicit-handshake",
1711 "-false-start",
1712 "-handshake-never-done",
1713 "-advertise-alpn", "\x03foo",
1714 },
1715 shouldFail: true,
1716 expectedError: ":UNEXPECTED_RECORD:",
1717 },
1718 {
1719 testType: serverTest,
1720 name: "FailEarlyCallback",
1721 flags: []string{"-fail-early-callback"},
1722 shouldFail: true,
1723 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001724 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001725 },
1726 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001727 name: "FailCertCallback-Client-TLS12",
1728 config: Config{
1729 MaxVersion: VersionTLS12,
1730 ClientAuth: RequestClientCert,
1731 },
1732 flags: []string{"-fail-cert-callback"},
1733 shouldFail: true,
1734 expectedError: ":CERT_CB_ERROR:",
1735 expectedLocalError: "remote error: internal error",
1736 },
1737 {
1738 testType: serverTest,
1739 name: "FailCertCallback-Server-TLS12",
1740 config: Config{
1741 MaxVersion: VersionTLS12,
1742 },
1743 flags: []string{"-fail-cert-callback"},
1744 shouldFail: true,
1745 expectedError: ":CERT_CB_ERROR:",
1746 expectedLocalError: "remote error: internal error",
1747 },
1748 {
1749 name: "FailCertCallback-Client-TLS13",
1750 config: Config{
1751 MaxVersion: VersionTLS13,
1752 ClientAuth: RequestClientCert,
1753 },
1754 flags: []string{"-fail-cert-callback"},
1755 shouldFail: true,
1756 expectedError: ":CERT_CB_ERROR:",
1757 expectedLocalError: "remote error: internal error",
1758 },
1759 {
1760 testType: serverTest,
1761 name: "FailCertCallback-Server-TLS13",
1762 config: Config{
1763 MaxVersion: VersionTLS13,
1764 },
1765 flags: []string{"-fail-cert-callback"},
1766 shouldFail: true,
1767 expectedError: ":CERT_CB_ERROR:",
1768 expectedLocalError: "remote error: internal error",
1769 },
1770 {
Adam Langley7c803a62015-06-15 15:35:05 -07001771 protocol: dtls,
1772 name: "FragmentMessageTypeMismatch-DTLS",
1773 config: Config{
1774 Bugs: ProtocolBugs{
1775 MaxHandshakeRecordLength: 2,
1776 FragmentMessageTypeMismatch: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":FRAGMENT_MISMATCH:",
1781 },
1782 {
1783 protocol: dtls,
1784 name: "FragmentMessageLengthMismatch-DTLS",
1785 config: Config{
1786 Bugs: ProtocolBugs{
1787 MaxHandshakeRecordLength: 2,
1788 FragmentMessageLengthMismatch: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":FRAGMENT_MISMATCH:",
1793 },
1794 {
1795 protocol: dtls,
1796 name: "SplitFragments-Header-DTLS",
1797 config: Config{
1798 Bugs: ProtocolBugs{
1799 SplitFragments: 2,
1800 },
1801 },
1802 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001803 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001804 },
1805 {
1806 protocol: dtls,
1807 name: "SplitFragments-Boundary-DTLS",
1808 config: Config{
1809 Bugs: ProtocolBugs{
1810 SplitFragments: dtlsRecordHeaderLen,
1811 },
1812 },
1813 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001814 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001815 },
1816 {
1817 protocol: dtls,
1818 name: "SplitFragments-Body-DTLS",
1819 config: Config{
1820 Bugs: ProtocolBugs{
1821 SplitFragments: dtlsRecordHeaderLen + 1,
1822 },
1823 },
1824 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001825 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001826 },
1827 {
1828 protocol: dtls,
1829 name: "SendEmptyFragments-DTLS",
1830 config: Config{
1831 Bugs: ProtocolBugs{
1832 SendEmptyFragments: true,
1833 },
1834 },
1835 },
1836 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001837 name: "BadFinished-Client",
1838 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001839 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001840 Bugs: ProtocolBugs{
1841 BadFinished: true,
1842 },
1843 },
1844 shouldFail: true,
1845 expectedError: ":DIGEST_CHECK_FAILED:",
1846 },
1847 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001848 name: "BadFinished-Client-TLS13",
1849 config: Config{
1850 MaxVersion: VersionTLS13,
1851 Bugs: ProtocolBugs{
1852 BadFinished: true,
1853 },
1854 },
1855 shouldFail: true,
1856 expectedError: ":DIGEST_CHECK_FAILED:",
1857 },
1858 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001859 testType: serverTest,
1860 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001861 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001862 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001863 Bugs: ProtocolBugs{
1864 BadFinished: true,
1865 },
1866 },
1867 shouldFail: true,
1868 expectedError: ":DIGEST_CHECK_FAILED:",
1869 },
1870 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001871 testType: serverTest,
1872 name: "BadFinished-Server-TLS13",
1873 config: Config{
1874 MaxVersion: VersionTLS13,
1875 Bugs: ProtocolBugs{
1876 BadFinished: true,
1877 },
1878 },
1879 shouldFail: true,
1880 expectedError: ":DIGEST_CHECK_FAILED:",
1881 },
1882 {
Adam Langley7c803a62015-06-15 15:35:05 -07001883 name: "FalseStart-BadFinished",
1884 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001885 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001886 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1887 NextProtos: []string{"foo"},
1888 Bugs: ProtocolBugs{
1889 BadFinished: true,
1890 ExpectFalseStart: true,
1891 },
1892 },
1893 flags: []string{
1894 "-false-start",
1895 "-handshake-never-done",
1896 "-advertise-alpn", "\x03foo",
1897 },
1898 shimWritesFirst: true,
1899 shouldFail: true,
1900 expectedError: ":DIGEST_CHECK_FAILED:",
1901 },
1902 {
1903 name: "NoFalseStart-NoALPN",
1904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001905 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001906 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1907 Bugs: ProtocolBugs{
1908 ExpectFalseStart: true,
1909 AlertBeforeFalseStartTest: alertAccessDenied,
1910 },
1911 },
1912 flags: []string{
1913 "-false-start",
1914 },
1915 shimWritesFirst: true,
1916 shouldFail: true,
1917 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1918 expectedLocalError: "tls: peer did not false start: EOF",
1919 },
1920 {
1921 name: "NoFalseStart-NoAEAD",
1922 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001923 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001924 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1925 NextProtos: []string{"foo"},
1926 Bugs: ProtocolBugs{
1927 ExpectFalseStart: true,
1928 AlertBeforeFalseStartTest: alertAccessDenied,
1929 },
1930 },
1931 flags: []string{
1932 "-false-start",
1933 "-advertise-alpn", "\x03foo",
1934 },
1935 shimWritesFirst: true,
1936 shouldFail: true,
1937 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1938 expectedLocalError: "tls: peer did not false start: EOF",
1939 },
1940 {
1941 name: "NoFalseStart-RSA",
1942 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001943 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001944 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1945 NextProtos: []string{"foo"},
1946 Bugs: ProtocolBugs{
1947 ExpectFalseStart: true,
1948 AlertBeforeFalseStartTest: alertAccessDenied,
1949 },
1950 },
1951 flags: []string{
1952 "-false-start",
1953 "-advertise-alpn", "\x03foo",
1954 },
1955 shimWritesFirst: true,
1956 shouldFail: true,
1957 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1958 expectedLocalError: "tls: peer did not false start: EOF",
1959 },
1960 {
1961 name: "NoFalseStart-DHE_RSA",
1962 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001963 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001964 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1965 NextProtos: []string{"foo"},
1966 Bugs: ProtocolBugs{
1967 ExpectFalseStart: true,
1968 AlertBeforeFalseStartTest: alertAccessDenied,
1969 },
1970 },
1971 flags: []string{
1972 "-false-start",
1973 "-advertise-alpn", "\x03foo",
1974 },
1975 shimWritesFirst: true,
1976 shouldFail: true,
1977 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1978 expectedLocalError: "tls: peer did not false start: EOF",
1979 },
1980 {
Adam Langley7c803a62015-06-15 15:35:05 -07001981 protocol: dtls,
1982 name: "SendSplitAlert-Sync",
1983 config: Config{
1984 Bugs: ProtocolBugs{
1985 SendSplitAlert: true,
1986 },
1987 },
1988 },
1989 {
1990 protocol: dtls,
1991 name: "SendSplitAlert-Async",
1992 config: Config{
1993 Bugs: ProtocolBugs{
1994 SendSplitAlert: true,
1995 },
1996 },
1997 flags: []string{"-async"},
1998 },
1999 {
2000 protocol: dtls,
2001 name: "PackDTLSHandshake",
2002 config: Config{
2003 Bugs: ProtocolBugs{
2004 MaxHandshakeRecordLength: 2,
2005 PackHandshakeFragments: 20,
2006 PackHandshakeRecords: 200,
2007 },
2008 },
2009 },
2010 {
Adam Langley7c803a62015-06-15 15:35:05 -07002011 name: "SendEmptyRecords-Pass",
2012 sendEmptyRecords: 32,
2013 },
2014 {
2015 name: "SendEmptyRecords",
2016 sendEmptyRecords: 33,
2017 shouldFail: true,
2018 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2019 },
2020 {
2021 name: "SendEmptyRecords-Async",
2022 sendEmptyRecords: 33,
2023 flags: []string{"-async"},
2024 shouldFail: true,
2025 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2026 },
2027 {
David Benjamine8e84b92016-08-03 15:39:47 -04002028 name: "SendWarningAlerts-Pass",
2029 config: Config{
2030 MaxVersion: VersionTLS12,
2031 },
Adam Langley7c803a62015-06-15 15:35:05 -07002032 sendWarningAlerts: 4,
2033 },
2034 {
David Benjamine8e84b92016-08-03 15:39:47 -04002035 protocol: dtls,
2036 name: "SendWarningAlerts-DTLS-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 name: "SendWarningAlerts-TLS13",
2044 config: Config{
2045 MaxVersion: VersionTLS13,
2046 },
2047 sendWarningAlerts: 4,
2048 shouldFail: true,
2049 expectedError: ":BAD_ALERT:",
2050 expectedLocalError: "remote error: error decoding message",
2051 },
2052 {
2053 name: "SendWarningAlerts",
2054 config: Config{
2055 MaxVersion: VersionTLS12,
2056 },
Adam Langley7c803a62015-06-15 15:35:05 -07002057 sendWarningAlerts: 5,
2058 shouldFail: true,
2059 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2060 },
2061 {
David Benjamine8e84b92016-08-03 15:39:47 -04002062 name: "SendWarningAlerts-Async",
2063 config: Config{
2064 MaxVersion: VersionTLS12,
2065 },
Adam Langley7c803a62015-06-15 15:35:05 -07002066 sendWarningAlerts: 5,
2067 flags: []string{"-async"},
2068 shouldFail: true,
2069 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2070 },
David Benjaminba4594a2015-06-18 18:36:15 -04002071 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002072 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002073 config: Config{
2074 MaxVersion: VersionTLS13,
2075 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002076 sendKeyUpdates: 33,
2077 keyUpdateRequest: keyUpdateNotRequested,
2078 shouldFail: true,
2079 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002080 },
2081 {
David Benjaminba4594a2015-06-18 18:36:15 -04002082 name: "EmptySessionID",
2083 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002084 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002085 SessionTicketsDisabled: true,
2086 },
2087 noSessionCache: true,
2088 flags: []string{"-expect-no-session"},
2089 },
David Benjamin30789da2015-08-29 22:56:45 -04002090 {
2091 name: "Unclean-Shutdown",
2092 config: Config{
2093 Bugs: ProtocolBugs{
2094 NoCloseNotify: true,
2095 ExpectCloseNotify: true,
2096 },
2097 },
2098 shimShutsDown: true,
2099 flags: []string{"-check-close-notify"},
2100 shouldFail: true,
2101 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2102 },
2103 {
2104 name: "Unclean-Shutdown-Ignored",
2105 config: Config{
2106 Bugs: ProtocolBugs{
2107 NoCloseNotify: true,
2108 },
2109 },
2110 shimShutsDown: true,
2111 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002112 {
David Benjaminfa214e42016-05-10 17:03:10 -04002113 name: "Unclean-Shutdown-Alert",
2114 config: Config{
2115 Bugs: ProtocolBugs{
2116 SendAlertOnShutdown: alertDecompressionFailure,
2117 ExpectCloseNotify: true,
2118 },
2119 },
2120 shimShutsDown: true,
2121 flags: []string{"-check-close-notify"},
2122 shouldFail: true,
2123 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2124 },
2125 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002126 name: "LargePlaintext",
2127 config: Config{
2128 Bugs: ProtocolBugs{
2129 SendLargeRecords: true,
2130 },
2131 },
2132 messageLen: maxPlaintext + 1,
2133 shouldFail: true,
2134 expectedError: ":DATA_LENGTH_TOO_LONG:",
2135 },
2136 {
2137 protocol: dtls,
2138 name: "LargePlaintext-DTLS",
2139 config: Config{
2140 Bugs: ProtocolBugs{
2141 SendLargeRecords: true,
2142 },
2143 },
2144 messageLen: maxPlaintext + 1,
2145 shouldFail: true,
2146 expectedError: ":DATA_LENGTH_TOO_LONG:",
2147 },
2148 {
2149 name: "LargeCiphertext",
2150 config: Config{
2151 Bugs: ProtocolBugs{
2152 SendLargeRecords: true,
2153 },
2154 },
2155 messageLen: maxPlaintext * 2,
2156 shouldFail: true,
2157 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2158 },
2159 {
2160 protocol: dtls,
2161 name: "LargeCiphertext-DTLS",
2162 config: Config{
2163 Bugs: ProtocolBugs{
2164 SendLargeRecords: true,
2165 },
2166 },
2167 messageLen: maxPlaintext * 2,
2168 // Unlike the other four cases, DTLS drops records which
2169 // are invalid before authentication, so the connection
2170 // does not fail.
2171 expectMessageDropped: true,
2172 },
David Benjamindd6fed92015-10-23 17:41:12 -04002173 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002174 name: "BadHelloRequest-1",
2175 renegotiate: 1,
2176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002177 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002178 Bugs: ProtocolBugs{
2179 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2180 },
2181 },
2182 flags: []string{
2183 "-renegotiate-freely",
2184 "-expect-total-renegotiations", "1",
2185 },
2186 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002187 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002188 },
2189 {
2190 name: "BadHelloRequest-2",
2191 renegotiate: 1,
2192 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002193 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002194 Bugs: ProtocolBugs{
2195 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2196 },
2197 },
2198 flags: []string{
2199 "-renegotiate-freely",
2200 "-expect-total-renegotiations", "1",
2201 },
2202 shouldFail: true,
2203 expectedError: ":BAD_HELLO_REQUEST:",
2204 },
David Benjaminef1b0092015-11-21 14:05:44 -05002205 {
2206 testType: serverTest,
2207 name: "SupportTicketsWithSessionID",
2208 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002209 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002210 SessionTicketsDisabled: true,
2211 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002212 resumeConfig: &Config{
2213 MaxVersion: VersionTLS12,
2214 },
David Benjaminef1b0092015-11-21 14:05:44 -05002215 resumeSession: true,
2216 },
David Benjamin02edcd02016-07-27 17:40:37 -04002217 {
2218 protocol: dtls,
2219 name: "DTLS-SendExtraFinished",
2220 config: Config{
2221 Bugs: ProtocolBugs{
2222 SendExtraFinished: true,
2223 },
2224 },
2225 shouldFail: true,
2226 expectedError: ":UNEXPECTED_RECORD:",
2227 },
2228 {
2229 protocol: dtls,
2230 name: "DTLS-SendExtraFinished-Reordered",
2231 config: Config{
2232 Bugs: ProtocolBugs{
2233 MaxHandshakeRecordLength: 2,
2234 ReorderHandshakeFragments: true,
2235 SendExtraFinished: true,
2236 },
2237 },
2238 shouldFail: true,
2239 expectedError: ":UNEXPECTED_RECORD:",
2240 },
David Benjamine97fb482016-07-29 09:23:07 -04002241 {
2242 testType: serverTest,
2243 name: "V2ClientHello-EmptyRecordPrefix",
2244 config: Config{
2245 // Choose a cipher suite that does not involve
2246 // elliptic curves, so no extensions are
2247 // involved.
2248 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002249 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002250 Bugs: ProtocolBugs{
2251 SendV2ClientHello: true,
2252 },
2253 },
2254 sendPrefix: string([]byte{
2255 byte(recordTypeHandshake),
2256 3, 1, // version
2257 0, 0, // length
2258 }),
2259 // A no-op empty record may not be sent before V2ClientHello.
2260 shouldFail: true,
2261 expectedError: ":WRONG_VERSION_NUMBER:",
2262 },
2263 {
2264 testType: serverTest,
2265 name: "V2ClientHello-WarningAlertPrefix",
2266 config: Config{
2267 // Choose a cipher suite that does not involve
2268 // elliptic curves, so no extensions are
2269 // involved.
2270 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002271 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002272 Bugs: ProtocolBugs{
2273 SendV2ClientHello: true,
2274 },
2275 },
2276 sendPrefix: string([]byte{
2277 byte(recordTypeAlert),
2278 3, 1, // version
2279 0, 2, // length
2280 alertLevelWarning, byte(alertDecompressionFailure),
2281 }),
2282 // A no-op warning alert may not be sent before V2ClientHello.
2283 shouldFail: true,
2284 expectedError: ":WRONG_VERSION_NUMBER:",
2285 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002286 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002287 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002288 config: Config{
2289 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002290 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002291 sendKeyUpdates: 1,
2292 keyUpdateRequest: keyUpdateNotRequested,
2293 },
2294 {
2295 name: "KeyUpdate-InvalidRequestMode",
2296 config: Config{
2297 MaxVersion: VersionTLS13,
2298 },
2299 sendKeyUpdates: 1,
2300 keyUpdateRequest: 42,
2301 shouldFail: true,
2302 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002303 },
David Benjaminabe94e32016-09-04 14:18:58 -04002304 {
2305 name: "SendSNIWarningAlert",
2306 config: Config{
2307 MaxVersion: VersionTLS12,
2308 Bugs: ProtocolBugs{
2309 SendSNIWarningAlert: true,
2310 },
2311 },
2312 },
David Benjaminc241d792016-09-09 10:34:20 -04002313 {
2314 testType: serverTest,
2315 name: "ExtraCompressionMethods-TLS12",
2316 config: Config{
2317 MaxVersion: VersionTLS12,
2318 Bugs: ProtocolBugs{
2319 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2320 },
2321 },
2322 },
2323 {
2324 testType: serverTest,
2325 name: "ExtraCompressionMethods-TLS13",
2326 config: Config{
2327 MaxVersion: VersionTLS13,
2328 Bugs: ProtocolBugs{
2329 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2330 },
2331 },
2332 shouldFail: true,
2333 expectedError: ":INVALID_COMPRESSION_LIST:",
2334 expectedLocalError: "remote error: illegal parameter",
2335 },
2336 {
2337 testType: serverTest,
2338 name: "NoNullCompression-TLS12",
2339 config: Config{
2340 MaxVersion: VersionTLS12,
2341 Bugs: ProtocolBugs{
2342 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2343 },
2344 },
2345 shouldFail: true,
2346 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2347 expectedLocalError: "remote error: illegal parameter",
2348 },
2349 {
2350 testType: serverTest,
2351 name: "NoNullCompression-TLS13",
2352 config: Config{
2353 MaxVersion: VersionTLS13,
2354 Bugs: ProtocolBugs{
2355 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2356 },
2357 },
2358 shouldFail: true,
2359 expectedError: ":INVALID_COMPRESSION_LIST:",
2360 expectedLocalError: "remote error: illegal parameter",
2361 },
David Benjamin65ac9972016-09-02 21:35:25 -04002362 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002363 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002364 config: Config{
2365 MaxVersion: VersionTLS12,
2366 Bugs: ProtocolBugs{
2367 ExpectGREASE: true,
2368 },
2369 },
2370 flags: []string{"-enable-grease"},
2371 },
2372 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002373 name: "GREASE-Client-TLS13",
2374 config: Config{
2375 MaxVersion: VersionTLS13,
2376 Bugs: ProtocolBugs{
2377 ExpectGREASE: true,
2378 },
2379 },
2380 flags: []string{"-enable-grease"},
2381 },
2382 {
2383 testType: serverTest,
2384 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002385 config: Config{
2386 MaxVersion: VersionTLS13,
2387 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002388 // TLS 1.3 servers are expected to
2389 // always enable GREASE. TLS 1.3 is new,
2390 // so there is no existing ecosystem to
2391 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002392 ExpectGREASE: true,
2393 },
2394 },
David Benjamin65ac9972016-09-02 21:35:25 -04002395 },
Adam Langley7c803a62015-06-15 15:35:05 -07002396 }
Adam Langley7c803a62015-06-15 15:35:05 -07002397 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002398
2399 // Test that very large messages can be received.
2400 cert := rsaCertificate
2401 for i := 0; i < 50; i++ {
2402 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2403 }
2404 testCases = append(testCases, testCase{
2405 name: "LargeMessage",
2406 config: Config{
2407 Certificates: []Certificate{cert},
2408 },
2409 })
2410 testCases = append(testCases, testCase{
2411 protocol: dtls,
2412 name: "LargeMessage-DTLS",
2413 config: Config{
2414 Certificates: []Certificate{cert},
2415 },
2416 })
2417
2418 // They are rejected if the maximum certificate chain length is capped.
2419 testCases = append(testCases, testCase{
2420 name: "LargeMessage-Reject",
2421 config: Config{
2422 Certificates: []Certificate{cert},
2423 },
2424 flags: []string{"-max-cert-list", "16384"},
2425 shouldFail: true,
2426 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2427 })
2428 testCases = append(testCases, testCase{
2429 protocol: dtls,
2430 name: "LargeMessage-Reject-DTLS",
2431 config: Config{
2432 Certificates: []Certificate{cert},
2433 },
2434 flags: []string{"-max-cert-list", "16384"},
2435 shouldFail: true,
2436 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2437 })
Adam Langley7c803a62015-06-15 15:35:05 -07002438}
2439
David Benjaminaa012042016-12-10 13:33:05 -05002440func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2441 const psk = "12345"
2442 const pskIdentity = "luggage combo"
2443
2444 var prefix string
2445 if protocol == dtls {
2446 if !ver.hasDTLS {
2447 return
2448 }
2449 prefix = "D"
2450 }
2451
2452 var cert Certificate
2453 var certFile string
2454 var keyFile string
2455 if hasComponent(suite.name, "ECDSA") {
2456 cert = ecdsaP256Certificate
2457 certFile = ecdsaP256CertificateFile
2458 keyFile = ecdsaP256KeyFile
2459 } else {
2460 cert = rsaCertificate
2461 certFile = rsaCertificateFile
2462 keyFile = rsaKeyFile
2463 }
2464
2465 var flags []string
2466 if hasComponent(suite.name, "PSK") {
2467 flags = append(flags,
2468 "-psk", psk,
2469 "-psk-identity", pskIdentity)
2470 }
2471 if hasComponent(suite.name, "NULL") {
2472 // NULL ciphers must be explicitly enabled.
2473 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2474 }
2475 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2476 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2477 // for now.
2478 flags = append(flags, "-cipher", suite.name)
2479 }
2480
2481 var shouldServerFail, shouldClientFail bool
2482 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2483 // BoringSSL clients accept ECDHE on SSLv3, but
2484 // a BoringSSL server will never select it
2485 // because the extension is missing.
2486 shouldServerFail = true
2487 }
2488 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2489 shouldClientFail = true
2490 shouldServerFail = true
2491 }
2492 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2493 shouldClientFail = true
2494 shouldServerFail = true
2495 }
2496 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2497 shouldClientFail = true
2498 shouldServerFail = true
2499 }
2500 if !isDTLSCipher(suite.name) && protocol == dtls {
2501 shouldClientFail = true
2502 shouldServerFail = true
2503 }
2504
2505 var sendCipherSuite uint16
2506 var expectedServerError, expectedClientError string
2507 serverCipherSuites := []uint16{suite.id}
2508 if shouldServerFail {
2509 expectedServerError = ":NO_SHARED_CIPHER:"
2510 }
2511 if shouldClientFail {
2512 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2513 // Configure the server to select ciphers as normal but
2514 // select an incompatible cipher in ServerHello.
2515 serverCipherSuites = nil
2516 sendCipherSuite = suite.id
2517 }
2518
2519 testCases = append(testCases, testCase{
2520 testType: serverTest,
2521 protocol: protocol,
2522 name: prefix + ver.name + "-" + suite.name + "-server",
2523 config: Config{
2524 MinVersion: ver.version,
2525 MaxVersion: ver.version,
2526 CipherSuites: []uint16{suite.id},
2527 Certificates: []Certificate{cert},
2528 PreSharedKey: []byte(psk),
2529 PreSharedKeyIdentity: pskIdentity,
2530 Bugs: ProtocolBugs{
2531 AdvertiseAllConfiguredCiphers: true,
2532 },
2533 },
2534 certFile: certFile,
2535 keyFile: keyFile,
2536 flags: flags,
2537 resumeSession: true,
2538 shouldFail: shouldServerFail,
2539 expectedError: expectedServerError,
2540 })
2541
2542 testCases = append(testCases, testCase{
2543 testType: clientTest,
2544 protocol: protocol,
2545 name: prefix + ver.name + "-" + suite.name + "-client",
2546 config: Config{
2547 MinVersion: ver.version,
2548 MaxVersion: ver.version,
2549 CipherSuites: serverCipherSuites,
2550 Certificates: []Certificate{cert},
2551 PreSharedKey: []byte(psk),
2552 PreSharedKeyIdentity: pskIdentity,
2553 Bugs: ProtocolBugs{
2554 IgnorePeerCipherPreferences: shouldClientFail,
2555 SendCipherSuite: sendCipherSuite,
2556 },
2557 },
2558 flags: flags,
2559 resumeSession: true,
2560 shouldFail: shouldClientFail,
2561 expectedError: expectedClientError,
2562 })
2563
2564 if !shouldClientFail {
2565 // Ensure the maximum record size is accepted.
2566 testCases = append(testCases, testCase{
2567 protocol: protocol,
2568 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2569 config: Config{
2570 MinVersion: ver.version,
2571 MaxVersion: ver.version,
2572 CipherSuites: []uint16{suite.id},
2573 Certificates: []Certificate{cert},
2574 PreSharedKey: []byte(psk),
2575 PreSharedKeyIdentity: pskIdentity,
2576 },
2577 flags: flags,
2578 messageLen: maxPlaintext,
2579 })
2580
2581 // Test bad records for all ciphers. Bad records are fatal in TLS
2582 // and ignored in DTLS.
2583 var shouldFail bool
2584 var expectedError string
2585 if protocol == tls {
2586 shouldFail = true
2587 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2588 }
2589
2590 testCases = append(testCases, testCase{
2591 protocol: protocol,
2592 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2593 config: Config{
2594 MinVersion: ver.version,
2595 MaxVersion: ver.version,
2596 CipherSuites: []uint16{suite.id},
2597 Certificates: []Certificate{cert},
2598 PreSharedKey: []byte(psk),
2599 PreSharedKeyIdentity: pskIdentity,
2600 },
2601 flags: flags,
2602 damageFirstWrite: true,
2603 messageLen: maxPlaintext,
2604 shouldFail: shouldFail,
2605 expectedError: expectedError,
2606 })
2607 }
2608}
2609
Adam Langley95c29f32014-06-20 12:00:00 -07002610func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002611 const bogusCipher = 0xfe00
2612
Adam Langley95c29f32014-06-20 12:00:00 -07002613 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002614 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002615 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002616 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002617 }
David Benjamin2c99d282015-09-01 10:23:00 -04002618 }
Adam Langley95c29f32014-06-20 12:00:00 -07002619 }
Adam Langleya7997f12015-05-14 17:38:50 -07002620
2621 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002622 name: "NoSharedCipher",
2623 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002624 MaxVersion: VersionTLS12,
2625 CipherSuites: []uint16{},
2626 },
2627 shouldFail: true,
2628 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2629 })
2630
2631 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002632 name: "NoSharedCipher-TLS13",
2633 config: Config{
2634 MaxVersion: VersionTLS13,
2635 CipherSuites: []uint16{},
2636 },
2637 shouldFail: true,
2638 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2639 })
2640
2641 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002642 name: "UnsupportedCipherSuite",
2643 config: Config{
2644 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002645 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002646 Bugs: ProtocolBugs{
2647 IgnorePeerCipherPreferences: true,
2648 },
2649 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002650 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002651 shouldFail: true,
2652 expectedError: ":WRONG_CIPHER_RETURNED:",
2653 })
2654
2655 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002656 name: "ServerHelloBogusCipher",
2657 config: Config{
2658 MaxVersion: VersionTLS12,
2659 Bugs: ProtocolBugs{
2660 SendCipherSuite: bogusCipher,
2661 },
2662 },
2663 shouldFail: true,
2664 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2665 })
2666 testCases = append(testCases, testCase{
2667 name: "ServerHelloBogusCipher-TLS13",
2668 config: Config{
2669 MaxVersion: VersionTLS13,
2670 Bugs: ProtocolBugs{
2671 SendCipherSuite: bogusCipher,
2672 },
2673 },
2674 shouldFail: true,
2675 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2676 })
2677
2678 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002679 name: "WeakDH",
2680 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002681 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002682 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2683 Bugs: ProtocolBugs{
2684 // This is a 1023-bit prime number, generated
2685 // with:
2686 // openssl gendh 1023 | openssl asn1parse -i
2687 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2688 },
2689 },
2690 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002691 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002692 })
Adam Langleycef75832015-09-03 14:51:12 -07002693
David Benjamincd24a392015-11-11 13:23:05 -08002694 testCases = append(testCases, testCase{
2695 name: "SillyDH",
2696 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002697 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002698 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2699 Bugs: ProtocolBugs{
2700 // This is a 4097-bit prime number, generated
2701 // with:
2702 // openssl gendh 4097 | openssl asn1parse -i
2703 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2704 },
2705 },
2706 shouldFail: true,
2707 expectedError: ":DH_P_TOO_LONG:",
2708 })
2709
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002710 // This test ensures that Diffie-Hellman public values are padded with
2711 // zeros so that they're the same length as the prime. This is to avoid
2712 // hitting a bug in yaSSL.
2713 testCases = append(testCases, testCase{
2714 testType: serverTest,
2715 name: "DHPublicValuePadded",
2716 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002717 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002718 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2719 Bugs: ProtocolBugs{
2720 RequireDHPublicValueLen: (1025 + 7) / 8,
2721 },
2722 },
2723 flags: []string{"-use-sparse-dh-prime"},
2724 })
David Benjamincd24a392015-11-11 13:23:05 -08002725
David Benjamin241ae832016-01-15 03:04:54 -05002726 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002727 testCases = append(testCases, testCase{
2728 testType: serverTest,
2729 name: "UnknownCipher",
2730 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002731 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002732 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002733 Bugs: ProtocolBugs{
2734 AdvertiseAllConfiguredCiphers: true,
2735 },
2736 },
2737 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002738
2739 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002740 testCases = append(testCases, testCase{
2741 testType: serverTest,
2742 name: "UnknownCipher-TLS13",
2743 config: Config{
2744 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002745 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002746 Bugs: ProtocolBugs{
2747 AdvertiseAllConfiguredCiphers: true,
2748 },
David Benjamin241ae832016-01-15 03:04:54 -05002749 },
2750 })
2751
David Benjamin78679342016-09-16 19:42:05 -04002752 // Test empty ECDHE_PSK identity hints work as expected.
2753 testCases = append(testCases, testCase{
2754 name: "EmptyECDHEPSKHint",
2755 config: Config{
2756 MaxVersion: VersionTLS12,
2757 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2758 PreSharedKey: []byte("secret"),
2759 },
2760 flags: []string{"-psk", "secret"},
2761 })
2762
2763 // Test empty PSK identity hints work as expected, even if an explicit
2764 // ServerKeyExchange is sent.
2765 testCases = append(testCases, testCase{
2766 name: "ExplicitEmptyPSKHint",
2767 config: Config{
2768 MaxVersion: VersionTLS12,
2769 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2770 PreSharedKey: []byte("secret"),
2771 Bugs: ProtocolBugs{
2772 AlwaysSendPreSharedKeyIdentityHint: true,
2773 },
2774 },
2775 flags: []string{"-psk", "secret"},
2776 })
2777
Adam Langleycef75832015-09-03 14:51:12 -07002778 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2779 // 1.1 specific cipher suite settings. A server is setup with the given
2780 // cipher lists and then a connection is made for each member of
2781 // expectations. The cipher suite that the server selects must match
2782 // the specified one.
2783 var versionSpecificCiphersTest = []struct {
2784 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2785 // expectations is a map from TLS version to cipher suite id.
2786 expectations map[uint16]uint16
2787 }{
2788 {
2789 // Test that the null case (where no version-specific ciphers are set)
2790 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002791 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2792 "", // no ciphers specifically for TLS ≥ 1.0
2793 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002794 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002795 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2796 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2797 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2798 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002799 },
2800 },
2801 {
2802 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2803 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002804 "DES-CBC3-SHA:AES128-SHA", // default
2805 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2806 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002807 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002808 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002809 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2810 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2811 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2812 },
2813 },
2814 {
2815 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2816 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002817 "DES-CBC3-SHA:AES128-SHA", // default
2818 "", // no ciphers specifically for TLS ≥ 1.0
2819 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002820 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002821 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2822 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002823 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2824 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2825 },
2826 },
2827 {
2828 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2829 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002830 "DES-CBC3-SHA:AES128-SHA", // default
2831 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2832 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002833 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002834 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002835 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2836 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2837 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2838 },
2839 },
2840 }
2841
2842 for i, test := range versionSpecificCiphersTest {
2843 for version, expectedCipherSuite := range test.expectations {
2844 flags := []string{"-cipher", test.ciphersDefault}
2845 if len(test.ciphersTLS10) > 0 {
2846 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2847 }
2848 if len(test.ciphersTLS11) > 0 {
2849 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2850 }
2851
2852 testCases = append(testCases, testCase{
2853 testType: serverTest,
2854 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2855 config: Config{
2856 MaxVersion: version,
2857 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002858 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002859 },
2860 flags: flags,
2861 expectedCipher: expectedCipherSuite,
2862 })
2863 }
2864 }
Adam Langley95c29f32014-06-20 12:00:00 -07002865}
2866
2867func addBadECDSASignatureTests() {
2868 for badR := BadValue(1); badR < NumBadValues; badR++ {
2869 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002870 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002871 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2872 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002873 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002874 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002875 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002876 Bugs: ProtocolBugs{
2877 BadECDSAR: badR,
2878 BadECDSAS: badS,
2879 },
2880 },
2881 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002882 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002883 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002884 testCases = append(testCases, testCase{
2885 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2886 config: Config{
2887 MaxVersion: VersionTLS13,
2888 Certificates: []Certificate{ecdsaP256Certificate},
2889 Bugs: ProtocolBugs{
2890 BadECDSAR: badR,
2891 BadECDSAS: badS,
2892 },
2893 },
2894 shouldFail: true,
2895 expectedError: ":BAD_SIGNATURE:",
2896 })
Adam Langley95c29f32014-06-20 12:00:00 -07002897 }
2898 }
2899}
2900
Adam Langley80842bd2014-06-20 12:00:00 -07002901func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002902 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002903 name: "MaxCBCPadding",
2904 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002905 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002906 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2907 Bugs: ProtocolBugs{
2908 MaxPadding: true,
2909 },
2910 },
2911 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2912 })
David Benjamin025b3d32014-07-01 19:53:04 -04002913 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002914 name: "BadCBCPadding",
2915 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002916 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2918 Bugs: ProtocolBugs{
2919 PaddingFirstByteBad: true,
2920 },
2921 },
2922 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002923 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002924 })
2925 // OpenSSL previously had an issue where the first byte of padding in
2926 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002927 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002928 name: "BadCBCPadding255",
2929 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002930 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002931 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2932 Bugs: ProtocolBugs{
2933 MaxPadding: true,
2934 PaddingFirstByteBadIf255: true,
2935 },
2936 },
2937 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2938 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002939 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002940 })
2941}
2942
Kenny Root7fdeaf12014-08-05 15:23:37 -07002943func addCBCSplittingTests() {
2944 testCases = append(testCases, testCase{
2945 name: "CBCRecordSplitting",
2946 config: Config{
2947 MaxVersion: VersionTLS10,
2948 MinVersion: VersionTLS10,
2949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2950 },
David Benjaminac8302a2015-09-01 17:18:15 -04002951 messageLen: -1, // read until EOF
2952 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002953 flags: []string{
2954 "-async",
2955 "-write-different-record-sizes",
2956 "-cbc-record-splitting",
2957 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002958 })
2959 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002960 name: "CBCRecordSplittingPartialWrite",
2961 config: Config{
2962 MaxVersion: VersionTLS10,
2963 MinVersion: VersionTLS10,
2964 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2965 },
2966 messageLen: -1, // read until EOF
2967 flags: []string{
2968 "-async",
2969 "-write-different-record-sizes",
2970 "-cbc-record-splitting",
2971 "-partial-write",
2972 },
2973 })
2974}
2975
David Benjamin636293b2014-07-08 17:59:18 -04002976func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002977 // Add a dummy cert pool to stress certificate authority parsing.
2978 // TODO(davidben): Add tests that those values parse out correctly.
2979 certPool := x509.NewCertPool()
2980 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2981 if err != nil {
2982 panic(err)
2983 }
2984 certPool.AddCert(cert)
2985
David Benjamin636293b2014-07-08 17:59:18 -04002986 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002987 testCases = append(testCases, testCase{
2988 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002989 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002990 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002991 MinVersion: ver.version,
2992 MaxVersion: ver.version,
2993 ClientAuth: RequireAnyClientCert,
2994 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002995 },
2996 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002997 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2998 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002999 },
3000 })
3001 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04003002 testType: serverTest,
3003 name: ver.name + "-Server-ClientAuth-RSA",
3004 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04003005 MinVersion: ver.version,
3006 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04003007 Certificates: []Certificate{rsaCertificate},
3008 },
3009 flags: []string{"-require-any-client-certificate"},
3010 })
David Benjamine098ec22014-08-27 23:13:20 -04003011 if ver.version != VersionSSL30 {
3012 testCases = append(testCases, testCase{
3013 testType: serverTest,
3014 name: ver.name + "-Server-ClientAuth-ECDSA",
3015 config: Config{
3016 MinVersion: ver.version,
3017 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003018 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003019 },
3020 flags: []string{"-require-any-client-certificate"},
3021 })
3022 testCases = append(testCases, testCase{
3023 testType: clientTest,
3024 name: ver.name + "-Client-ClientAuth-ECDSA",
3025 config: Config{
3026 MinVersion: ver.version,
3027 MaxVersion: ver.version,
3028 ClientAuth: RequireAnyClientCert,
3029 ClientCAs: certPool,
3030 },
3031 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003032 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3033 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003034 },
3035 })
3036 }
Adam Langley37646832016-08-01 16:16:46 -07003037
3038 testCases = append(testCases, testCase{
3039 name: "NoClientCertificate-" + ver.name,
3040 config: Config{
3041 MinVersion: ver.version,
3042 MaxVersion: ver.version,
3043 ClientAuth: RequireAnyClientCert,
3044 },
3045 shouldFail: true,
3046 expectedLocalError: "client didn't provide a certificate",
3047 })
3048
3049 testCases = append(testCases, testCase{
3050 // Even if not configured to expect a certificate, OpenSSL will
3051 // return X509_V_OK as the verify_result.
3052 testType: serverTest,
3053 name: "NoClientCertificateRequested-Server-" + ver.name,
3054 config: Config{
3055 MinVersion: ver.version,
3056 MaxVersion: ver.version,
3057 },
3058 flags: []string{
3059 "-expect-verify-result",
3060 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003061 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003062 })
3063
3064 testCases = append(testCases, testCase{
3065 // If a client certificate is not provided, OpenSSL will still
3066 // return X509_V_OK as the verify_result.
3067 testType: serverTest,
3068 name: "NoClientCertificate-Server-" + ver.name,
3069 config: Config{
3070 MinVersion: ver.version,
3071 MaxVersion: ver.version,
3072 },
3073 flags: []string{
3074 "-expect-verify-result",
3075 "-verify-peer",
3076 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003077 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003078 })
3079
David Benjamin1db9e1b2016-10-07 20:51:43 -04003080 certificateRequired := "remote error: certificate required"
3081 if ver.version < VersionTLS13 {
3082 // Prior to TLS 1.3, the generic handshake_failure alert
3083 // was used.
3084 certificateRequired = "remote error: handshake failure"
3085 }
Adam Langley37646832016-08-01 16:16:46 -07003086 testCases = append(testCases, testCase{
3087 testType: serverTest,
3088 name: "RequireAnyClientCertificate-" + ver.name,
3089 config: Config{
3090 MinVersion: ver.version,
3091 MaxVersion: ver.version,
3092 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003093 flags: []string{"-require-any-client-certificate"},
3094 shouldFail: true,
3095 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3096 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003097 })
3098
3099 if ver.version != VersionSSL30 {
3100 testCases = append(testCases, testCase{
3101 testType: serverTest,
3102 name: "SkipClientCertificate-" + ver.name,
3103 config: Config{
3104 MinVersion: ver.version,
3105 MaxVersion: ver.version,
3106 Bugs: ProtocolBugs{
3107 SkipClientCertificate: true,
3108 },
3109 },
3110 // Setting SSL_VERIFY_PEER allows anonymous clients.
3111 flags: []string{"-verify-peer"},
3112 shouldFail: true,
3113 expectedError: ":UNEXPECTED_MESSAGE:",
3114 })
3115 }
David Benjamin636293b2014-07-08 17:59:18 -04003116 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003117
David Benjaminc032dfa2016-05-12 14:54:57 -04003118 // Client auth is only legal in certificate-based ciphers.
3119 testCases = append(testCases, testCase{
3120 testType: clientTest,
3121 name: "ClientAuth-PSK",
3122 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003123 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003124 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3125 PreSharedKey: []byte("secret"),
3126 ClientAuth: RequireAnyClientCert,
3127 },
3128 flags: []string{
3129 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3130 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3131 "-psk", "secret",
3132 },
3133 shouldFail: true,
3134 expectedError: ":UNEXPECTED_MESSAGE:",
3135 })
3136 testCases = append(testCases, testCase{
3137 testType: clientTest,
3138 name: "ClientAuth-ECDHE_PSK",
3139 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003140 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003141 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3142 PreSharedKey: []byte("secret"),
3143 ClientAuth: RequireAnyClientCert,
3144 },
3145 flags: []string{
3146 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3147 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3148 "-psk", "secret",
3149 },
3150 shouldFail: true,
3151 expectedError: ":UNEXPECTED_MESSAGE:",
3152 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003153
3154 // Regression test for a bug where the client CA list, if explicitly
3155 // set to NULL, was mis-encoded.
3156 testCases = append(testCases, testCase{
3157 testType: serverTest,
3158 name: "Null-Client-CA-List",
3159 config: Config{
3160 MaxVersion: VersionTLS12,
3161 Certificates: []Certificate{rsaCertificate},
3162 },
3163 flags: []string{
3164 "-require-any-client-certificate",
3165 "-use-null-client-ca-list",
3166 },
3167 })
David Benjamin636293b2014-07-08 17:59:18 -04003168}
3169
Adam Langley75712922014-10-10 16:23:43 -07003170func addExtendedMasterSecretTests() {
3171 const expectEMSFlag = "-expect-extended-master-secret"
3172
3173 for _, with := range []bool{false, true} {
3174 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003175 if with {
3176 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003177 }
3178
3179 for _, isClient := range []bool{false, true} {
3180 suffix := "-Server"
3181 testType := serverTest
3182 if isClient {
3183 suffix = "-Client"
3184 testType = clientTest
3185 }
3186
3187 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003188 // In TLS 1.3, the extension is irrelevant and
3189 // always reports as enabled.
3190 var flags []string
3191 if with || ver.version >= VersionTLS13 {
3192 flags = []string{expectEMSFlag}
3193 }
3194
Adam Langley75712922014-10-10 16:23:43 -07003195 test := testCase{
3196 testType: testType,
3197 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3198 config: Config{
3199 MinVersion: ver.version,
3200 MaxVersion: ver.version,
3201 Bugs: ProtocolBugs{
3202 NoExtendedMasterSecret: !with,
3203 RequireExtendedMasterSecret: with,
3204 },
3205 },
David Benjamin48cae082014-10-27 01:06:24 -04003206 flags: flags,
3207 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003208 }
3209 if test.shouldFail {
3210 test.expectedLocalError = "extended master secret required but not supported by peer"
3211 }
3212 testCases = append(testCases, test)
3213 }
3214 }
3215 }
3216
Adam Langleyba5934b2015-06-02 10:50:35 -07003217 for _, isClient := range []bool{false, true} {
3218 for _, supportedInFirstConnection := range []bool{false, true} {
3219 for _, supportedInResumeConnection := range []bool{false, true} {
3220 boolToWord := func(b bool) string {
3221 if b {
3222 return "Yes"
3223 }
3224 return "No"
3225 }
3226 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3227 if isClient {
3228 suffix += "Client"
3229 } else {
3230 suffix += "Server"
3231 }
3232
3233 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003234 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003235 Bugs: ProtocolBugs{
3236 RequireExtendedMasterSecret: true,
3237 },
3238 }
3239
3240 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003241 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003242 Bugs: ProtocolBugs{
3243 NoExtendedMasterSecret: true,
3244 },
3245 }
3246
3247 test := testCase{
3248 name: "ExtendedMasterSecret-" + suffix,
3249 resumeSession: true,
3250 }
3251
3252 if !isClient {
3253 test.testType = serverTest
3254 }
3255
3256 if supportedInFirstConnection {
3257 test.config = supportedConfig
3258 } else {
3259 test.config = noSupportConfig
3260 }
3261
3262 if supportedInResumeConnection {
3263 test.resumeConfig = &supportedConfig
3264 } else {
3265 test.resumeConfig = &noSupportConfig
3266 }
3267
3268 switch suffix {
3269 case "YesToYes-Client", "YesToYes-Server":
3270 // When a session is resumed, it should
3271 // still be aware that its master
3272 // secret was generated via EMS and
3273 // thus it's safe to use tls-unique.
3274 test.flags = []string{expectEMSFlag}
3275 case "NoToYes-Server":
3276 // If an original connection did not
3277 // contain EMS, but a resumption
3278 // handshake does, then a server should
3279 // not resume the session.
3280 test.expectResumeRejected = true
3281 case "YesToNo-Server":
3282 // Resuming an EMS session without the
3283 // EMS extension should cause the
3284 // server to abort the connection.
3285 test.shouldFail = true
3286 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3287 case "NoToYes-Client":
3288 // A client should abort a connection
3289 // where the server resumed a non-EMS
3290 // session but echoed the EMS
3291 // extension.
3292 test.shouldFail = true
3293 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3294 case "YesToNo-Client":
3295 // A client should abort a connection
3296 // where the server didn't echo EMS
3297 // when the session used it.
3298 test.shouldFail = true
3299 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3300 }
3301
3302 testCases = append(testCases, test)
3303 }
3304 }
3305 }
David Benjamin163c9562016-08-29 23:14:17 -04003306
3307 // Switching EMS on renegotiation is forbidden.
3308 testCases = append(testCases, testCase{
3309 name: "ExtendedMasterSecret-Renego-NoEMS",
3310 config: Config{
3311 MaxVersion: VersionTLS12,
3312 Bugs: ProtocolBugs{
3313 NoExtendedMasterSecret: true,
3314 NoExtendedMasterSecretOnRenegotiation: true,
3315 },
3316 },
3317 renegotiate: 1,
3318 flags: []string{
3319 "-renegotiate-freely",
3320 "-expect-total-renegotiations", "1",
3321 },
3322 })
3323
3324 testCases = append(testCases, testCase{
3325 name: "ExtendedMasterSecret-Renego-Upgrade",
3326 config: Config{
3327 MaxVersion: VersionTLS12,
3328 Bugs: ProtocolBugs{
3329 NoExtendedMasterSecret: true,
3330 },
3331 },
3332 renegotiate: 1,
3333 flags: []string{
3334 "-renegotiate-freely",
3335 "-expect-total-renegotiations", "1",
3336 },
3337 shouldFail: true,
3338 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3339 })
3340
3341 testCases = append(testCases, testCase{
3342 name: "ExtendedMasterSecret-Renego-Downgrade",
3343 config: Config{
3344 MaxVersion: VersionTLS12,
3345 Bugs: ProtocolBugs{
3346 NoExtendedMasterSecretOnRenegotiation: true,
3347 },
3348 },
3349 renegotiate: 1,
3350 flags: []string{
3351 "-renegotiate-freely",
3352 "-expect-total-renegotiations", "1",
3353 },
3354 shouldFail: true,
3355 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3356 })
Adam Langley75712922014-10-10 16:23:43 -07003357}
3358
David Benjamin582ba042016-07-07 12:33:25 -07003359type stateMachineTestConfig struct {
3360 protocol protocol
3361 async bool
3362 splitHandshake, packHandshakeFlight bool
3363}
3364
David Benjamin43ec06f2014-08-05 02:28:57 -04003365// Adds tests that try to cover the range of the handshake state machine, under
3366// various conditions. Some of these are redundant with other tests, but they
3367// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003368func addAllStateMachineCoverageTests() {
3369 for _, async := range []bool{false, true} {
3370 for _, protocol := range []protocol{tls, dtls} {
3371 addStateMachineCoverageTests(stateMachineTestConfig{
3372 protocol: protocol,
3373 async: async,
3374 })
3375 addStateMachineCoverageTests(stateMachineTestConfig{
3376 protocol: protocol,
3377 async: async,
3378 splitHandshake: true,
3379 })
3380 if protocol == tls {
3381 addStateMachineCoverageTests(stateMachineTestConfig{
3382 protocol: protocol,
3383 async: async,
3384 packHandshakeFlight: true,
3385 })
3386 }
3387 }
3388 }
3389}
3390
3391func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003392 var tests []testCase
3393
3394 // Basic handshake, with resumption. Client and server,
3395 // session ID and session ticket.
3396 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003397 name: "Basic-Client",
3398 config: Config{
3399 MaxVersion: VersionTLS12,
3400 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003401 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003402 // Ensure session tickets are used, not session IDs.
3403 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003404 })
3405 tests = append(tests, testCase{
3406 name: "Basic-Client-RenewTicket",
3407 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003408 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003409 Bugs: ProtocolBugs{
3410 RenewTicketOnResume: true,
3411 },
3412 },
David Benjamin46662482016-08-17 00:51:00 -04003413 flags: []string{"-expect-ticket-renewal"},
3414 resumeSession: true,
3415 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003416 })
3417 tests = append(tests, testCase{
3418 name: "Basic-Client-NoTicket",
3419 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003420 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003421 SessionTicketsDisabled: true,
3422 },
3423 resumeSession: true,
3424 })
3425 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003426 name: "Basic-Client-Implicit",
3427 config: Config{
3428 MaxVersion: VersionTLS12,
3429 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003430 flags: []string{"-implicit-handshake"},
3431 resumeSession: true,
3432 })
3433 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003434 testType: serverTest,
3435 name: "Basic-Server",
3436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003437 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003438 Bugs: ProtocolBugs{
3439 RequireSessionTickets: true,
3440 },
3441 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003442 resumeSession: true,
3443 })
3444 tests = append(tests, testCase{
3445 testType: serverTest,
3446 name: "Basic-Server-NoTickets",
3447 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003448 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003449 SessionTicketsDisabled: true,
3450 },
3451 resumeSession: true,
3452 })
3453 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003454 testType: serverTest,
3455 name: "Basic-Server-Implicit",
3456 config: Config{
3457 MaxVersion: VersionTLS12,
3458 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003459 flags: []string{"-implicit-handshake"},
3460 resumeSession: true,
3461 })
3462 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003463 testType: serverTest,
3464 name: "Basic-Server-EarlyCallback",
3465 config: Config{
3466 MaxVersion: VersionTLS12,
3467 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003468 flags: []string{"-use-early-callback"},
3469 resumeSession: true,
3470 })
3471
Steven Valdez143e8b32016-07-11 13:19:03 -04003472 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003473 if config.protocol == tls {
3474 tests = append(tests, testCase{
3475 name: "TLS13-1RTT-Client",
3476 config: Config{
3477 MaxVersion: VersionTLS13,
3478 MinVersion: VersionTLS13,
3479 },
David Benjamin46662482016-08-17 00:51:00 -04003480 resumeSession: true,
3481 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003482 })
3483
3484 tests = append(tests, testCase{
3485 testType: serverTest,
3486 name: "TLS13-1RTT-Server",
3487 config: Config{
3488 MaxVersion: VersionTLS13,
3489 MinVersion: VersionTLS13,
3490 },
David Benjamin46662482016-08-17 00:51:00 -04003491 resumeSession: true,
3492 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003493 })
3494
3495 tests = append(tests, testCase{
3496 name: "TLS13-HelloRetryRequest-Client",
3497 config: Config{
3498 MaxVersion: VersionTLS13,
3499 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003500 // P-384 requires a HelloRetryRequest against BoringSSL's default
3501 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003502 CurvePreferences: []CurveID{CurveP384},
3503 Bugs: ProtocolBugs{
3504 ExpectMissingKeyShare: true,
3505 },
3506 },
3507 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3508 resumeSession: true,
3509 })
3510
3511 tests = append(tests, testCase{
3512 testType: serverTest,
3513 name: "TLS13-HelloRetryRequest-Server",
3514 config: Config{
3515 MaxVersion: VersionTLS13,
3516 MinVersion: VersionTLS13,
3517 // Require a HelloRetryRequest for every curve.
3518 DefaultCurves: []CurveID{},
3519 },
3520 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3521 resumeSession: true,
3522 })
3523 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003524
David Benjamin760b1dd2015-05-15 23:33:48 -04003525 // TLS client auth.
3526 tests = append(tests, testCase{
3527 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003528 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003529 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003530 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003531 ClientAuth: RequestClientCert,
3532 },
3533 })
3534 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003535 testType: serverTest,
3536 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003537 config: Config{
3538 MaxVersion: VersionTLS12,
3539 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003540 // Setting SSL_VERIFY_PEER allows anonymous clients.
3541 flags: []string{"-verify-peer"},
3542 })
David Benjamin582ba042016-07-07 12:33:25 -07003543 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003544 tests = append(tests, testCase{
3545 testType: clientTest,
3546 name: "ClientAuth-NoCertificate-Client-SSL3",
3547 config: Config{
3548 MaxVersion: VersionSSL30,
3549 ClientAuth: RequestClientCert,
3550 },
3551 })
3552 tests = append(tests, testCase{
3553 testType: serverTest,
3554 name: "ClientAuth-NoCertificate-Server-SSL3",
3555 config: Config{
3556 MaxVersion: VersionSSL30,
3557 },
3558 // Setting SSL_VERIFY_PEER allows anonymous clients.
3559 flags: []string{"-verify-peer"},
3560 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003561 tests = append(tests, testCase{
3562 testType: clientTest,
3563 name: "ClientAuth-NoCertificate-Client-TLS13",
3564 config: Config{
3565 MaxVersion: VersionTLS13,
3566 ClientAuth: RequestClientCert,
3567 },
3568 })
3569 tests = append(tests, testCase{
3570 testType: serverTest,
3571 name: "ClientAuth-NoCertificate-Server-TLS13",
3572 config: Config{
3573 MaxVersion: VersionTLS13,
3574 },
3575 // Setting SSL_VERIFY_PEER allows anonymous clients.
3576 flags: []string{"-verify-peer"},
3577 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003578 }
3579 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003580 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003581 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003582 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003583 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003584 ClientAuth: RequireAnyClientCert,
3585 },
3586 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003587 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3588 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003589 },
3590 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003591 tests = append(tests, testCase{
3592 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003593 name: "ClientAuth-RSA-Client-TLS13",
3594 config: Config{
3595 MaxVersion: VersionTLS13,
3596 ClientAuth: RequireAnyClientCert,
3597 },
3598 flags: []string{
3599 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3600 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3601 },
3602 })
3603 tests = append(tests, testCase{
3604 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003605 name: "ClientAuth-ECDSA-Client",
3606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003607 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003608 ClientAuth: RequireAnyClientCert,
3609 },
3610 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003611 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3612 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003613 },
3614 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003615 tests = append(tests, testCase{
3616 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003617 name: "ClientAuth-ECDSA-Client-TLS13",
3618 config: Config{
3619 MaxVersion: VersionTLS13,
3620 ClientAuth: RequireAnyClientCert,
3621 },
3622 flags: []string{
3623 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3624 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3625 },
3626 })
3627 tests = append(tests, testCase{
3628 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003629 name: "ClientAuth-NoCertificate-OldCallback",
3630 config: Config{
3631 MaxVersion: VersionTLS12,
3632 ClientAuth: RequestClientCert,
3633 },
3634 flags: []string{"-use-old-client-cert-callback"},
3635 })
3636 tests = append(tests, testCase{
3637 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003638 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3639 config: Config{
3640 MaxVersion: VersionTLS13,
3641 ClientAuth: RequestClientCert,
3642 },
3643 flags: []string{"-use-old-client-cert-callback"},
3644 })
3645 tests = append(tests, testCase{
3646 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003647 name: "ClientAuth-OldCallback",
3648 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003649 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003650 ClientAuth: RequireAnyClientCert,
3651 },
3652 flags: []string{
3653 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3654 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3655 "-use-old-client-cert-callback",
3656 },
3657 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003658 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003659 testType: clientTest,
3660 name: "ClientAuth-OldCallback-TLS13",
3661 config: Config{
3662 MaxVersion: VersionTLS13,
3663 ClientAuth: RequireAnyClientCert,
3664 },
3665 flags: []string{
3666 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3667 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3668 "-use-old-client-cert-callback",
3669 },
3670 })
3671 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003672 testType: serverTest,
3673 name: "ClientAuth-Server",
3674 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003675 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003676 Certificates: []Certificate{rsaCertificate},
3677 },
3678 flags: []string{"-require-any-client-certificate"},
3679 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003680 tests = append(tests, testCase{
3681 testType: serverTest,
3682 name: "ClientAuth-Server-TLS13",
3683 config: Config{
3684 MaxVersion: VersionTLS13,
3685 Certificates: []Certificate{rsaCertificate},
3686 },
3687 flags: []string{"-require-any-client-certificate"},
3688 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003689
David Benjamin4c3ddf72016-06-29 18:13:53 -04003690 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003691 tests = append(tests, testCase{
3692 testType: serverTest,
3693 name: "Basic-Server-RSA",
3694 config: Config{
3695 MaxVersion: VersionTLS12,
3696 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3697 },
3698 flags: []string{
3699 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3700 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3701 },
3702 })
3703 tests = append(tests, testCase{
3704 testType: serverTest,
3705 name: "Basic-Server-ECDHE-RSA",
3706 config: Config{
3707 MaxVersion: VersionTLS12,
3708 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3709 },
3710 flags: []string{
3711 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3712 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3713 },
3714 })
3715 tests = append(tests, testCase{
3716 testType: serverTest,
3717 name: "Basic-Server-ECDHE-ECDSA",
3718 config: Config{
3719 MaxVersion: VersionTLS12,
3720 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3721 },
3722 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003723 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3724 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003725 },
3726 })
3727
David Benjamin760b1dd2015-05-15 23:33:48 -04003728 // No session ticket support; server doesn't send NewSessionTicket.
3729 tests = append(tests, testCase{
3730 name: "SessionTicketsDisabled-Client",
3731 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003732 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003733 SessionTicketsDisabled: true,
3734 },
3735 })
3736 tests = append(tests, testCase{
3737 testType: serverTest,
3738 name: "SessionTicketsDisabled-Server",
3739 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003740 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003741 SessionTicketsDisabled: true,
3742 },
3743 })
3744
3745 // Skip ServerKeyExchange in PSK key exchange if there's no
3746 // identity hint.
3747 tests = append(tests, testCase{
3748 name: "EmptyPSKHint-Client",
3749 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003750 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003751 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3752 PreSharedKey: []byte("secret"),
3753 },
3754 flags: []string{"-psk", "secret"},
3755 })
3756 tests = append(tests, testCase{
3757 testType: serverTest,
3758 name: "EmptyPSKHint-Server",
3759 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003760 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003761 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3762 PreSharedKey: []byte("secret"),
3763 },
3764 flags: []string{"-psk", "secret"},
3765 })
3766
David Benjamin4c3ddf72016-06-29 18:13:53 -04003767 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003768 tests = append(tests, testCase{
3769 testType: clientTest,
3770 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003771 config: Config{
3772 MaxVersion: VersionTLS12,
3773 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003774 flags: []string{
3775 "-enable-ocsp-stapling",
3776 "-expect-ocsp-response",
3777 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003778 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003779 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003780 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003781 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003782 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003783 testType: serverTest,
3784 name: "OCSPStapling-Server",
3785 config: Config{
3786 MaxVersion: VersionTLS12,
3787 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003788 expectedOCSPResponse: testOCSPResponse,
3789 flags: []string{
3790 "-ocsp-response",
3791 base64.StdEncoding.EncodeToString(testOCSPResponse),
3792 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003793 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003794 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003795 tests = append(tests, testCase{
3796 testType: clientTest,
3797 name: "OCSPStapling-Client-TLS13",
3798 config: Config{
3799 MaxVersion: VersionTLS13,
3800 },
3801 flags: []string{
3802 "-enable-ocsp-stapling",
3803 "-expect-ocsp-response",
3804 base64.StdEncoding.EncodeToString(testOCSPResponse),
3805 "-verify-peer",
3806 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003807 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003808 })
3809 tests = append(tests, testCase{
3810 testType: serverTest,
3811 name: "OCSPStapling-Server-TLS13",
3812 config: Config{
3813 MaxVersion: VersionTLS13,
3814 },
3815 expectedOCSPResponse: testOCSPResponse,
3816 flags: []string{
3817 "-ocsp-response",
3818 base64.StdEncoding.EncodeToString(testOCSPResponse),
3819 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003820 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003821 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003822
David Benjamin4c3ddf72016-06-29 18:13:53 -04003823 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003824 for _, vers := range tlsVersions {
3825 if config.protocol == dtls && !vers.hasDTLS {
3826 continue
3827 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003828 for _, testType := range []testType{clientTest, serverTest} {
3829 suffix := "-Client"
3830 if testType == serverTest {
3831 suffix = "-Server"
3832 }
3833 suffix += "-" + vers.name
3834
3835 flag := "-verify-peer"
3836 if testType == serverTest {
3837 flag = "-require-any-client-certificate"
3838 }
3839
3840 tests = append(tests, testCase{
3841 testType: testType,
3842 name: "CertificateVerificationSucceed" + suffix,
3843 config: Config{
3844 MaxVersion: vers.version,
3845 Certificates: []Certificate{rsaCertificate},
3846 },
3847 flags: []string{
3848 flag,
3849 "-expect-verify-result",
3850 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003851 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003852 })
3853 tests = append(tests, testCase{
3854 testType: testType,
3855 name: "CertificateVerificationFail" + suffix,
3856 config: Config{
3857 MaxVersion: vers.version,
3858 Certificates: []Certificate{rsaCertificate},
3859 },
3860 flags: []string{
3861 flag,
3862 "-verify-fail",
3863 },
3864 shouldFail: true,
3865 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3866 })
3867 }
3868
3869 // By default, the client is in a soft fail mode where the peer
3870 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003871 tests = append(tests, testCase{
3872 testType: clientTest,
3873 name: "CertificateVerificationSoftFail-" + vers.name,
3874 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003875 MaxVersion: vers.version,
3876 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003877 },
3878 flags: []string{
3879 "-verify-fail",
3880 "-expect-verify-result",
3881 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003882 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003883 })
3884 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003885
David Benjamin1d4f4c02016-07-26 18:03:08 -04003886 tests = append(tests, testCase{
3887 name: "ShimSendAlert",
3888 flags: []string{"-send-alert"},
3889 shimWritesFirst: true,
3890 shouldFail: true,
3891 expectedLocalError: "remote error: decompression failure",
3892 })
3893
David Benjamin582ba042016-07-07 12:33:25 -07003894 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003895 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003896 name: "Renegotiate-Client",
3897 config: Config{
3898 MaxVersion: VersionTLS12,
3899 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003900 renegotiate: 1,
3901 flags: []string{
3902 "-renegotiate-freely",
3903 "-expect-total-renegotiations", "1",
3904 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003905 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003906
David Benjamin47921102016-07-28 11:29:18 -04003907 tests = append(tests, testCase{
3908 name: "SendHalfHelloRequest",
3909 config: Config{
3910 MaxVersion: VersionTLS12,
3911 Bugs: ProtocolBugs{
3912 PackHelloRequestWithFinished: config.packHandshakeFlight,
3913 },
3914 },
3915 sendHalfHelloRequest: true,
3916 flags: []string{"-renegotiate-ignore"},
3917 shouldFail: true,
3918 expectedError: ":UNEXPECTED_RECORD:",
3919 })
3920
David Benjamin760b1dd2015-05-15 23:33:48 -04003921 // NPN on client and server; results in post-handshake message.
3922 tests = append(tests, testCase{
3923 name: "NPN-Client",
3924 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003925 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003926 NextProtos: []string{"foo"},
3927 },
3928 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003929 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003930 expectedNextProto: "foo",
3931 expectedNextProtoType: npn,
3932 })
3933 tests = append(tests, testCase{
3934 testType: serverTest,
3935 name: "NPN-Server",
3936 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003937 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003938 NextProtos: []string{"bar"},
3939 },
3940 flags: []string{
3941 "-advertise-npn", "\x03foo\x03bar\x03baz",
3942 "-expect-next-proto", "bar",
3943 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003944 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003945 expectedNextProto: "bar",
3946 expectedNextProtoType: npn,
3947 })
3948
3949 // TODO(davidben): Add tests for when False Start doesn't trigger.
3950
3951 // Client does False Start and negotiates NPN.
3952 tests = append(tests, testCase{
3953 name: "FalseStart",
3954 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003955 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003956 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3957 NextProtos: []string{"foo"},
3958 Bugs: ProtocolBugs{
3959 ExpectFalseStart: true,
3960 },
3961 },
3962 flags: []string{
3963 "-false-start",
3964 "-select-next-proto", "foo",
3965 },
3966 shimWritesFirst: true,
3967 resumeSession: true,
3968 })
3969
3970 // Client does False Start and negotiates ALPN.
3971 tests = append(tests, testCase{
3972 name: "FalseStart-ALPN",
3973 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003974 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003975 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3976 NextProtos: []string{"foo"},
3977 Bugs: ProtocolBugs{
3978 ExpectFalseStart: true,
3979 },
3980 },
3981 flags: []string{
3982 "-false-start",
3983 "-advertise-alpn", "\x03foo",
3984 },
3985 shimWritesFirst: true,
3986 resumeSession: true,
3987 })
3988
3989 // Client does False Start but doesn't explicitly call
3990 // SSL_connect.
3991 tests = append(tests, testCase{
3992 name: "FalseStart-Implicit",
3993 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003994 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003995 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3996 NextProtos: []string{"foo"},
3997 },
3998 flags: []string{
3999 "-implicit-handshake",
4000 "-false-start",
4001 "-advertise-alpn", "\x03foo",
4002 },
4003 })
4004
4005 // False Start without session tickets.
4006 tests = append(tests, testCase{
4007 name: "FalseStart-SessionTicketsDisabled",
4008 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004009 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004010 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4011 NextProtos: []string{"foo"},
4012 SessionTicketsDisabled: true,
4013 Bugs: ProtocolBugs{
4014 ExpectFalseStart: true,
4015 },
4016 },
4017 flags: []string{
4018 "-false-start",
4019 "-select-next-proto", "foo",
4020 },
4021 shimWritesFirst: true,
4022 })
4023
4024 // Server parses a V2ClientHello.
4025 tests = append(tests, testCase{
4026 testType: serverTest,
4027 name: "SendV2ClientHello",
4028 config: Config{
4029 // Choose a cipher suite that does not involve
4030 // elliptic curves, so no extensions are
4031 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004032 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004033 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004034 Bugs: ProtocolBugs{
4035 SendV2ClientHello: true,
4036 },
4037 },
4038 })
4039
Nick Harper60a85cb2016-09-23 16:25:11 -07004040 // Test Channel ID
4041 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004042 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004043 continue
4044 }
4045 // Client sends a Channel ID.
4046 tests = append(tests, testCase{
4047 name: "ChannelID-Client-" + ver.name,
4048 config: Config{
4049 MaxVersion: ver.version,
4050 RequestChannelID: true,
4051 },
4052 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4053 resumeSession: true,
4054 expectChannelID: true,
4055 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004056
Nick Harper60a85cb2016-09-23 16:25:11 -07004057 // Server accepts a Channel ID.
4058 tests = append(tests, testCase{
4059 testType: serverTest,
4060 name: "ChannelID-Server-" + ver.name,
4061 config: Config{
4062 MaxVersion: ver.version,
4063 ChannelID: channelIDKey,
4064 },
4065 flags: []string{
4066 "-expect-channel-id",
4067 base64.StdEncoding.EncodeToString(channelIDBytes),
4068 },
4069 resumeSession: true,
4070 expectChannelID: true,
4071 })
4072
4073 tests = append(tests, testCase{
4074 testType: serverTest,
4075 name: "InvalidChannelIDSignature-" + ver.name,
4076 config: Config{
4077 MaxVersion: ver.version,
4078 ChannelID: channelIDKey,
4079 Bugs: ProtocolBugs{
4080 InvalidChannelIDSignature: true,
4081 },
4082 },
4083 flags: []string{"-enable-channel-id"},
4084 shouldFail: true,
4085 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4086 })
4087 }
David Benjamin30789da2015-08-29 22:56:45 -04004088
David Benjaminf8fcdf32016-06-08 15:56:13 -04004089 // Channel ID and NPN at the same time, to ensure their relative
4090 // ordering is correct.
4091 tests = append(tests, testCase{
4092 name: "ChannelID-NPN-Client",
4093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004094 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004095 RequestChannelID: true,
4096 NextProtos: []string{"foo"},
4097 },
4098 flags: []string{
4099 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4100 "-select-next-proto", "foo",
4101 },
4102 resumeSession: true,
4103 expectChannelID: true,
4104 expectedNextProto: "foo",
4105 expectedNextProtoType: npn,
4106 })
4107 tests = append(tests, testCase{
4108 testType: serverTest,
4109 name: "ChannelID-NPN-Server",
4110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004111 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004112 ChannelID: channelIDKey,
4113 NextProtos: []string{"bar"},
4114 },
4115 flags: []string{
4116 "-expect-channel-id",
4117 base64.StdEncoding.EncodeToString(channelIDBytes),
4118 "-advertise-npn", "\x03foo\x03bar\x03baz",
4119 "-expect-next-proto", "bar",
4120 },
4121 resumeSession: true,
4122 expectChannelID: true,
4123 expectedNextProto: "bar",
4124 expectedNextProtoType: npn,
4125 })
4126
David Benjamin30789da2015-08-29 22:56:45 -04004127 // Bidirectional shutdown with the runner initiating.
4128 tests = append(tests, testCase{
4129 name: "Shutdown-Runner",
4130 config: Config{
4131 Bugs: ProtocolBugs{
4132 ExpectCloseNotify: true,
4133 },
4134 },
4135 flags: []string{"-check-close-notify"},
4136 })
4137
4138 // Bidirectional shutdown with the shim initiating. The runner,
4139 // in the meantime, sends garbage before the close_notify which
4140 // the shim must ignore.
4141 tests = append(tests, testCase{
4142 name: "Shutdown-Shim",
4143 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004144 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004145 Bugs: ProtocolBugs{
4146 ExpectCloseNotify: true,
4147 },
4148 },
4149 shimShutsDown: true,
4150 sendEmptyRecords: 1,
4151 sendWarningAlerts: 1,
4152 flags: []string{"-check-close-notify"},
4153 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004154 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004155 // TODO(davidben): DTLS 1.3 will want a similar thing for
4156 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004157 tests = append(tests, testCase{
4158 name: "SkipHelloVerifyRequest",
4159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004160 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004161 Bugs: ProtocolBugs{
4162 SkipHelloVerifyRequest: true,
4163 },
4164 },
4165 })
4166 }
4167
David Benjamin760b1dd2015-05-15 23:33:48 -04004168 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004169 test.protocol = config.protocol
4170 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004171 test.name += "-DTLS"
4172 }
David Benjamin582ba042016-07-07 12:33:25 -07004173 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004174 test.name += "-Async"
4175 test.flags = append(test.flags, "-async")
4176 } else {
4177 test.name += "-Sync"
4178 }
David Benjamin582ba042016-07-07 12:33:25 -07004179 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004180 test.name += "-SplitHandshakeRecords"
4181 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004182 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004183 test.config.Bugs.MaxPacketLength = 256
4184 test.flags = append(test.flags, "-mtu", "256")
4185 }
4186 }
David Benjamin582ba042016-07-07 12:33:25 -07004187 if config.packHandshakeFlight {
4188 test.name += "-PackHandshakeFlight"
4189 test.config.Bugs.PackHandshakeFlight = true
4190 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004191 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004192 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004193}
4194
Adam Langley524e7172015-02-20 16:04:00 -08004195func addDDoSCallbackTests() {
4196 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004197 for _, resume := range []bool{false, true} {
4198 suffix := "Resume"
4199 if resume {
4200 suffix = "No" + suffix
4201 }
4202
4203 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004204 testType: serverTest,
4205 name: "Server-DDoS-OK-" + suffix,
4206 config: Config{
4207 MaxVersion: VersionTLS12,
4208 },
Adam Langley524e7172015-02-20 16:04:00 -08004209 flags: []string{"-install-ddos-callback"},
4210 resumeSession: resume,
4211 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004212 testCases = append(testCases, testCase{
4213 testType: serverTest,
4214 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4215 config: Config{
4216 MaxVersion: VersionTLS13,
4217 },
4218 flags: []string{"-install-ddos-callback"},
4219 resumeSession: resume,
4220 })
Adam Langley524e7172015-02-20 16:04:00 -08004221
4222 failFlag := "-fail-ddos-callback"
4223 if resume {
4224 failFlag = "-fail-second-ddos-callback"
4225 }
4226 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004227 testType: serverTest,
4228 name: "Server-DDoS-Reject-" + suffix,
4229 config: Config{
4230 MaxVersion: VersionTLS12,
4231 },
David Benjamin2c66e072016-09-16 15:58:00 -04004232 flags: []string{"-install-ddos-callback", failFlag},
4233 resumeSession: resume,
4234 shouldFail: true,
4235 expectedError: ":CONNECTION_REJECTED:",
4236 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004237 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004238 testCases = append(testCases, testCase{
4239 testType: serverTest,
4240 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4241 config: Config{
4242 MaxVersion: VersionTLS13,
4243 },
David Benjamin2c66e072016-09-16 15:58:00 -04004244 flags: []string{"-install-ddos-callback", failFlag},
4245 resumeSession: resume,
4246 shouldFail: true,
4247 expectedError: ":CONNECTION_REJECTED:",
4248 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004249 })
Adam Langley524e7172015-02-20 16:04:00 -08004250 }
4251}
4252
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004253func addVersionNegotiationTests() {
4254 for i, shimVers := range tlsVersions {
4255 // Assemble flags to disable all newer versions on the shim.
4256 var flags []string
4257 for _, vers := range tlsVersions[i+1:] {
4258 flags = append(flags, vers.flag)
4259 }
4260
Steven Valdezfdd10992016-09-15 16:27:05 -04004261 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004262 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004263 protocols := []protocol{tls}
4264 if runnerVers.hasDTLS && shimVers.hasDTLS {
4265 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004266 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004267 for _, protocol := range protocols {
4268 expectedVersion := shimVers.version
4269 if runnerVers.version < shimVers.version {
4270 expectedVersion = runnerVers.version
4271 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004272
David Benjamin8b8c0062014-11-23 02:47:52 -05004273 suffix := shimVers.name + "-" + runnerVers.name
4274 if protocol == dtls {
4275 suffix += "-DTLS"
4276 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004277
David Benjamin1eb367c2014-12-12 18:17:51 -05004278 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4279
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004280 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004281 clientVers := shimVers.version
4282 if clientVers > VersionTLS10 {
4283 clientVers = VersionTLS10
4284 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004285 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004286 serverVers := expectedVersion
4287 if expectedVersion >= VersionTLS13 {
4288 serverVers = VersionTLS10
4289 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004290 serverVers = versionToWire(serverVers, protocol == dtls)
4291
David Benjamin8b8c0062014-11-23 02:47:52 -05004292 testCases = append(testCases, testCase{
4293 protocol: protocol,
4294 testType: clientTest,
4295 name: "VersionNegotiation-Client-" + suffix,
4296 config: Config{
4297 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004298 Bugs: ProtocolBugs{
4299 ExpectInitialRecordVersion: clientVers,
4300 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004301 },
4302 flags: flags,
4303 expectedVersion: expectedVersion,
4304 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004305 testCases = append(testCases, testCase{
4306 protocol: protocol,
4307 testType: clientTest,
4308 name: "VersionNegotiation-Client2-" + suffix,
4309 config: Config{
4310 MaxVersion: runnerVers.version,
4311 Bugs: ProtocolBugs{
4312 ExpectInitialRecordVersion: clientVers,
4313 },
4314 },
4315 flags: []string{"-max-version", shimVersFlag},
4316 expectedVersion: expectedVersion,
4317 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004318
4319 testCases = append(testCases, testCase{
4320 protocol: protocol,
4321 testType: serverTest,
4322 name: "VersionNegotiation-Server-" + suffix,
4323 config: Config{
4324 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004325 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004326 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004327 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004328 },
4329 flags: flags,
4330 expectedVersion: expectedVersion,
4331 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004332 testCases = append(testCases, testCase{
4333 protocol: protocol,
4334 testType: serverTest,
4335 name: "VersionNegotiation-Server2-" + suffix,
4336 config: Config{
4337 MaxVersion: runnerVers.version,
4338 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004339 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004340 },
4341 },
4342 flags: []string{"-max-version", shimVersFlag},
4343 expectedVersion: expectedVersion,
4344 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004345 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004346 }
4347 }
David Benjamin95c69562016-06-29 18:15:03 -04004348
Steven Valdezfdd10992016-09-15 16:27:05 -04004349 // Test the version extension at all versions.
4350 for _, vers := range tlsVersions {
4351 protocols := []protocol{tls}
4352 if vers.hasDTLS {
4353 protocols = append(protocols, dtls)
4354 }
4355 for _, protocol := range protocols {
4356 suffix := vers.name
4357 if protocol == dtls {
4358 suffix += "-DTLS"
4359 }
4360
4361 wireVersion := versionToWire(vers.version, protocol == dtls)
4362 testCases = append(testCases, testCase{
4363 protocol: protocol,
4364 testType: serverTest,
4365 name: "VersionNegotiationExtension-" + suffix,
4366 config: Config{
4367 Bugs: ProtocolBugs{
4368 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4369 },
4370 },
4371 expectedVersion: vers.version,
4372 })
4373 }
4374
4375 }
4376
4377 // If all versions are unknown, negotiation fails.
4378 testCases = append(testCases, testCase{
4379 testType: serverTest,
4380 name: "NoSupportedVersions",
4381 config: Config{
4382 Bugs: ProtocolBugs{
4383 SendSupportedVersions: []uint16{0x1111},
4384 },
4385 },
4386 shouldFail: true,
4387 expectedError: ":UNSUPPORTED_PROTOCOL:",
4388 })
4389 testCases = append(testCases, testCase{
4390 protocol: dtls,
4391 testType: serverTest,
4392 name: "NoSupportedVersions-DTLS",
4393 config: Config{
4394 Bugs: ProtocolBugs{
4395 SendSupportedVersions: []uint16{0x1111},
4396 },
4397 },
4398 shouldFail: true,
4399 expectedError: ":UNSUPPORTED_PROTOCOL:",
4400 })
4401
4402 testCases = append(testCases, testCase{
4403 testType: serverTest,
4404 name: "ClientHelloVersionTooHigh",
4405 config: Config{
4406 MaxVersion: VersionTLS13,
4407 Bugs: ProtocolBugs{
4408 SendClientVersion: 0x0304,
4409 OmitSupportedVersions: true,
4410 },
4411 },
4412 expectedVersion: VersionTLS12,
4413 })
4414
4415 testCases = append(testCases, testCase{
4416 testType: serverTest,
4417 name: "ConflictingVersionNegotiation",
4418 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004419 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004420 SendClientVersion: VersionTLS12,
4421 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004422 },
4423 },
David Benjaminad75a662016-09-30 15:42:59 -04004424 // The extension takes precedence over the ClientHello version.
4425 expectedVersion: VersionTLS11,
4426 })
4427
4428 testCases = append(testCases, testCase{
4429 testType: serverTest,
4430 name: "ConflictingVersionNegotiation-2",
4431 config: Config{
4432 Bugs: ProtocolBugs{
4433 SendClientVersion: VersionTLS11,
4434 SendSupportedVersions: []uint16{VersionTLS12},
4435 },
4436 },
4437 // The extension takes precedence over the ClientHello version.
4438 expectedVersion: VersionTLS12,
4439 })
4440
4441 testCases = append(testCases, testCase{
4442 testType: serverTest,
4443 name: "RejectFinalTLS13",
4444 config: Config{
4445 Bugs: ProtocolBugs{
4446 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4447 },
4448 },
4449 // We currently implement a draft TLS 1.3 version. Ensure that
4450 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004451 expectedVersion: VersionTLS12,
4452 })
4453
Brian Smithf85d3232016-10-28 10:34:06 -10004454 // Test that the maximum version is selected regardless of the
4455 // client-sent order.
4456 testCases = append(testCases, testCase{
4457 testType: serverTest,
4458 name: "IgnoreClientVersionOrder",
4459 config: Config{
4460 Bugs: ProtocolBugs{
4461 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4462 },
4463 },
4464 expectedVersion: VersionTLS13,
4465 })
4466
David Benjamin95c69562016-06-29 18:15:03 -04004467 // Test for version tolerance.
4468 testCases = append(testCases, testCase{
4469 testType: serverTest,
4470 name: "MinorVersionTolerance",
4471 config: Config{
4472 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004473 SendClientVersion: 0x03ff,
4474 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004475 },
4476 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004477 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004478 })
4479 testCases = append(testCases, testCase{
4480 testType: serverTest,
4481 name: "MajorVersionTolerance",
4482 config: Config{
4483 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004484 SendClientVersion: 0x0400,
4485 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004486 },
4487 },
David Benjaminad75a662016-09-30 15:42:59 -04004488 // TLS 1.3 must be negotiated with the supported_versions
4489 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004490 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004491 })
David Benjaminad75a662016-09-30 15:42:59 -04004492 testCases = append(testCases, testCase{
4493 testType: serverTest,
4494 name: "VersionTolerance-TLS13",
4495 config: Config{
4496 Bugs: ProtocolBugs{
4497 // Although TLS 1.3 does not use
4498 // ClientHello.version, it still tolerates high
4499 // values there.
4500 SendClientVersion: 0x0400,
4501 },
4502 },
4503 expectedVersion: VersionTLS13,
4504 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004505
David Benjamin95c69562016-06-29 18:15:03 -04004506 testCases = append(testCases, testCase{
4507 protocol: dtls,
4508 testType: serverTest,
4509 name: "MinorVersionTolerance-DTLS",
4510 config: Config{
4511 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004512 SendClientVersion: 0xfe00,
4513 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004514 },
4515 },
4516 expectedVersion: VersionTLS12,
4517 })
4518 testCases = append(testCases, testCase{
4519 protocol: dtls,
4520 testType: serverTest,
4521 name: "MajorVersionTolerance-DTLS",
4522 config: Config{
4523 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004524 SendClientVersion: 0xfdff,
4525 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004526 },
4527 },
4528 expectedVersion: VersionTLS12,
4529 })
4530
4531 // Test that versions below 3.0 are rejected.
4532 testCases = append(testCases, testCase{
4533 testType: serverTest,
4534 name: "VersionTooLow",
4535 config: Config{
4536 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004537 SendClientVersion: 0x0200,
4538 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004539 },
4540 },
4541 shouldFail: true,
4542 expectedError: ":UNSUPPORTED_PROTOCOL:",
4543 })
4544 testCases = append(testCases, testCase{
4545 protocol: dtls,
4546 testType: serverTest,
4547 name: "VersionTooLow-DTLS",
4548 config: Config{
4549 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004550 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004551 },
4552 },
4553 shouldFail: true,
4554 expectedError: ":UNSUPPORTED_PROTOCOL:",
4555 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004556
David Benjamin2dc02042016-09-19 19:57:37 -04004557 testCases = append(testCases, testCase{
4558 name: "ServerBogusVersion",
4559 config: Config{
4560 Bugs: ProtocolBugs{
4561 SendServerHelloVersion: 0x1234,
4562 },
4563 },
4564 shouldFail: true,
4565 expectedError: ":UNSUPPORTED_PROTOCOL:",
4566 })
4567
David Benjamin1f61f0d2016-07-10 12:20:35 -04004568 // Test TLS 1.3's downgrade signal.
4569 testCases = append(testCases, testCase{
4570 name: "Downgrade-TLS12-Client",
4571 config: Config{
4572 Bugs: ProtocolBugs{
4573 NegotiateVersion: VersionTLS12,
4574 },
4575 },
David Benjamin592b5322016-09-30 15:15:01 -04004576 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004577 // TODO(davidben): This test should fail once TLS 1.3 is final
4578 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004579 })
4580 testCases = append(testCases, testCase{
4581 testType: serverTest,
4582 name: "Downgrade-TLS12-Server",
4583 config: Config{
4584 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004585 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004586 },
4587 },
David Benjamin592b5322016-09-30 15:15:01 -04004588 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004589 // TODO(davidben): This test should fail once TLS 1.3 is final
4590 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004591 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004592}
4593
David Benjaminaccb4542014-12-12 23:44:33 -05004594func addMinimumVersionTests() {
4595 for i, shimVers := range tlsVersions {
4596 // Assemble flags to disable all older versions on the shim.
4597 var flags []string
4598 for _, vers := range tlsVersions[:i] {
4599 flags = append(flags, vers.flag)
4600 }
4601
4602 for _, runnerVers := range tlsVersions {
4603 protocols := []protocol{tls}
4604 if runnerVers.hasDTLS && shimVers.hasDTLS {
4605 protocols = append(protocols, dtls)
4606 }
4607 for _, protocol := range protocols {
4608 suffix := shimVers.name + "-" + runnerVers.name
4609 if protocol == dtls {
4610 suffix += "-DTLS"
4611 }
4612 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4613
David Benjaminaccb4542014-12-12 23:44:33 -05004614 var expectedVersion uint16
4615 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004616 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004617 if runnerVers.version >= shimVers.version {
4618 expectedVersion = runnerVers.version
4619 } else {
4620 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004621 expectedError = ":UNSUPPORTED_PROTOCOL:"
4622 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004623 }
4624
4625 testCases = append(testCases, testCase{
4626 protocol: protocol,
4627 testType: clientTest,
4628 name: "MinimumVersion-Client-" + suffix,
4629 config: Config{
4630 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004631 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004632 // Ensure the server does not decline to
4633 // select a version (versions extension) or
4634 // cipher (some ciphers depend on versions).
4635 NegotiateVersion: runnerVers.version,
4636 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004637 },
David Benjaminaccb4542014-12-12 23:44:33 -05004638 },
David Benjamin87909c02014-12-13 01:55:01 -05004639 flags: flags,
4640 expectedVersion: expectedVersion,
4641 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004642 expectedError: expectedError,
4643 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004644 })
4645 testCases = append(testCases, testCase{
4646 protocol: protocol,
4647 testType: clientTest,
4648 name: "MinimumVersion-Client2-" + suffix,
4649 config: Config{
4650 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004651 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004652 // Ensure the server does not decline to
4653 // select a version (versions extension) or
4654 // cipher (some ciphers depend on versions).
4655 NegotiateVersion: runnerVers.version,
4656 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004657 },
David Benjaminaccb4542014-12-12 23:44:33 -05004658 },
David Benjamin87909c02014-12-13 01:55:01 -05004659 flags: []string{"-min-version", shimVersFlag},
4660 expectedVersion: expectedVersion,
4661 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004662 expectedError: expectedError,
4663 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004664 })
4665
4666 testCases = append(testCases, testCase{
4667 protocol: protocol,
4668 testType: serverTest,
4669 name: "MinimumVersion-Server-" + suffix,
4670 config: Config{
4671 MaxVersion: runnerVers.version,
4672 },
David Benjamin87909c02014-12-13 01:55:01 -05004673 flags: flags,
4674 expectedVersion: expectedVersion,
4675 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004676 expectedError: expectedError,
4677 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004678 })
4679 testCases = append(testCases, testCase{
4680 protocol: protocol,
4681 testType: serverTest,
4682 name: "MinimumVersion-Server2-" + suffix,
4683 config: Config{
4684 MaxVersion: runnerVers.version,
4685 },
David Benjamin87909c02014-12-13 01:55:01 -05004686 flags: []string{"-min-version", shimVersFlag},
4687 expectedVersion: expectedVersion,
4688 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004689 expectedError: expectedError,
4690 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004691 })
4692 }
4693 }
4694 }
4695}
4696
David Benjamine78bfde2014-09-06 12:45:15 -04004697func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004698 // TODO(davidben): Extensions, where applicable, all move their server
4699 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4700 // tests for both. Also test interaction with 0-RTT when implemented.
4701
David Benjamin97d17d92016-07-14 16:12:00 -04004702 // Repeat extensions tests all versions except SSL 3.0.
4703 for _, ver := range tlsVersions {
4704 if ver.version == VersionSSL30 {
4705 continue
4706 }
4707
David Benjamin97d17d92016-07-14 16:12:00 -04004708 // Test that duplicate extensions are rejected.
4709 testCases = append(testCases, testCase{
4710 testType: clientTest,
4711 name: "DuplicateExtensionClient-" + ver.name,
4712 config: Config{
4713 MaxVersion: ver.version,
4714 Bugs: ProtocolBugs{
4715 DuplicateExtension: true,
4716 },
David Benjamine78bfde2014-09-06 12:45:15 -04004717 },
David Benjamin97d17d92016-07-14 16:12:00 -04004718 shouldFail: true,
4719 expectedLocalError: "remote error: error decoding message",
4720 })
4721 testCases = append(testCases, testCase{
4722 testType: serverTest,
4723 name: "DuplicateExtensionServer-" + ver.name,
4724 config: Config{
4725 MaxVersion: ver.version,
4726 Bugs: ProtocolBugs{
4727 DuplicateExtension: true,
4728 },
David Benjamine78bfde2014-09-06 12:45:15 -04004729 },
David Benjamin97d17d92016-07-14 16:12:00 -04004730 shouldFail: true,
4731 expectedLocalError: "remote error: error decoding message",
4732 })
4733
4734 // Test SNI.
4735 testCases = append(testCases, testCase{
4736 testType: clientTest,
4737 name: "ServerNameExtensionClient-" + ver.name,
4738 config: Config{
4739 MaxVersion: ver.version,
4740 Bugs: ProtocolBugs{
4741 ExpectServerName: "example.com",
4742 },
David Benjamine78bfde2014-09-06 12:45:15 -04004743 },
David Benjamin97d17d92016-07-14 16:12:00 -04004744 flags: []string{"-host-name", "example.com"},
4745 })
4746 testCases = append(testCases, testCase{
4747 testType: clientTest,
4748 name: "ServerNameExtensionClientMismatch-" + ver.name,
4749 config: Config{
4750 MaxVersion: ver.version,
4751 Bugs: ProtocolBugs{
4752 ExpectServerName: "mismatch.com",
4753 },
David Benjamine78bfde2014-09-06 12:45:15 -04004754 },
David Benjamin97d17d92016-07-14 16:12:00 -04004755 flags: []string{"-host-name", "example.com"},
4756 shouldFail: true,
4757 expectedLocalError: "tls: unexpected server name",
4758 })
4759 testCases = append(testCases, testCase{
4760 testType: clientTest,
4761 name: "ServerNameExtensionClientMissing-" + ver.name,
4762 config: Config{
4763 MaxVersion: ver.version,
4764 Bugs: ProtocolBugs{
4765 ExpectServerName: "missing.com",
4766 },
David Benjamine78bfde2014-09-06 12:45:15 -04004767 },
David Benjamin97d17d92016-07-14 16:12:00 -04004768 shouldFail: true,
4769 expectedLocalError: "tls: unexpected server name",
4770 })
4771 testCases = append(testCases, testCase{
4772 testType: serverTest,
4773 name: "ServerNameExtensionServer-" + ver.name,
4774 config: Config{
4775 MaxVersion: ver.version,
4776 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004777 },
David Benjamin97d17d92016-07-14 16:12:00 -04004778 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004779 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004780 })
4781
4782 // Test ALPN.
4783 testCases = append(testCases, testCase{
4784 testType: clientTest,
4785 name: "ALPNClient-" + ver.name,
4786 config: Config{
4787 MaxVersion: ver.version,
4788 NextProtos: []string{"foo"},
4789 },
4790 flags: []string{
4791 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4792 "-expect-alpn", "foo",
4793 },
4794 expectedNextProto: "foo",
4795 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004796 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004797 })
4798 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004799 testType: clientTest,
4800 name: "ALPNClient-Mismatch-" + ver.name,
4801 config: Config{
4802 MaxVersion: ver.version,
4803 Bugs: ProtocolBugs{
4804 SendALPN: "baz",
4805 },
4806 },
4807 flags: []string{
4808 "-advertise-alpn", "\x03foo\x03bar",
4809 },
4810 shouldFail: true,
4811 expectedError: ":INVALID_ALPN_PROTOCOL:",
4812 expectedLocalError: "remote error: illegal parameter",
4813 })
4814 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004815 testType: serverTest,
4816 name: "ALPNServer-" + ver.name,
4817 config: Config{
4818 MaxVersion: ver.version,
4819 NextProtos: []string{"foo", "bar", "baz"},
4820 },
4821 flags: []string{
4822 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4823 "-select-alpn", "foo",
4824 },
4825 expectedNextProto: "foo",
4826 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004827 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004828 })
4829 testCases = append(testCases, testCase{
4830 testType: serverTest,
4831 name: "ALPNServer-Decline-" + ver.name,
4832 config: Config{
4833 MaxVersion: ver.version,
4834 NextProtos: []string{"foo", "bar", "baz"},
4835 },
4836 flags: []string{"-decline-alpn"},
4837 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004838 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004839 })
4840
David Benjamin25fe85b2016-08-09 20:00:32 -04004841 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4842 // called once.
4843 testCases = append(testCases, testCase{
4844 testType: serverTest,
4845 name: "ALPNServer-Async-" + ver.name,
4846 config: Config{
4847 MaxVersion: ver.version,
4848 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004849 // Prior to TLS 1.3, exercise the asynchronous session callback.
4850 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004851 },
4852 flags: []string{
4853 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4854 "-select-alpn", "foo",
4855 "-async",
4856 },
4857 expectedNextProto: "foo",
4858 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004859 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004860 })
4861
David Benjamin97d17d92016-07-14 16:12:00 -04004862 var emptyString string
4863 testCases = append(testCases, testCase{
4864 testType: clientTest,
4865 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4866 config: Config{
4867 MaxVersion: ver.version,
4868 NextProtos: []string{""},
4869 Bugs: ProtocolBugs{
4870 // A server returning an empty ALPN protocol
4871 // should be rejected.
4872 ALPNProtocol: &emptyString,
4873 },
4874 },
4875 flags: []string{
4876 "-advertise-alpn", "\x03foo",
4877 },
4878 shouldFail: true,
4879 expectedError: ":PARSE_TLSEXT:",
4880 })
4881 testCases = append(testCases, testCase{
4882 testType: serverTest,
4883 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4884 config: Config{
4885 MaxVersion: ver.version,
4886 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004887 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004888 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004889 },
David Benjamin97d17d92016-07-14 16:12:00 -04004890 flags: []string{
4891 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004892 },
David Benjamin97d17d92016-07-14 16:12:00 -04004893 shouldFail: true,
4894 expectedError: ":PARSE_TLSEXT:",
4895 })
4896
4897 // Test NPN and the interaction with ALPN.
4898 if ver.version < VersionTLS13 {
4899 // Test that the server prefers ALPN over NPN.
4900 testCases = append(testCases, testCase{
4901 testType: serverTest,
4902 name: "ALPNServer-Preferred-" + ver.name,
4903 config: Config{
4904 MaxVersion: ver.version,
4905 NextProtos: []string{"foo", "bar", "baz"},
4906 },
4907 flags: []string{
4908 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4909 "-select-alpn", "foo",
4910 "-advertise-npn", "\x03foo\x03bar\x03baz",
4911 },
4912 expectedNextProto: "foo",
4913 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004914 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004915 })
4916 testCases = append(testCases, testCase{
4917 testType: serverTest,
4918 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4919 config: Config{
4920 MaxVersion: ver.version,
4921 NextProtos: []string{"foo", "bar", "baz"},
4922 Bugs: ProtocolBugs{
4923 SwapNPNAndALPN: true,
4924 },
4925 },
4926 flags: []string{
4927 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4928 "-select-alpn", "foo",
4929 "-advertise-npn", "\x03foo\x03bar\x03baz",
4930 },
4931 expectedNextProto: "foo",
4932 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004933 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004934 })
4935
4936 // Test that negotiating both NPN and ALPN is forbidden.
4937 testCases = append(testCases, testCase{
4938 name: "NegotiateALPNAndNPN-" + ver.name,
4939 config: Config{
4940 MaxVersion: ver.version,
4941 NextProtos: []string{"foo", "bar", "baz"},
4942 Bugs: ProtocolBugs{
4943 NegotiateALPNAndNPN: true,
4944 },
4945 },
4946 flags: []string{
4947 "-advertise-alpn", "\x03foo",
4948 "-select-next-proto", "foo",
4949 },
4950 shouldFail: true,
4951 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4952 })
4953 testCases = append(testCases, testCase{
4954 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4955 config: Config{
4956 MaxVersion: ver.version,
4957 NextProtos: []string{"foo", "bar", "baz"},
4958 Bugs: ProtocolBugs{
4959 NegotiateALPNAndNPN: true,
4960 SwapNPNAndALPN: true,
4961 },
4962 },
4963 flags: []string{
4964 "-advertise-alpn", "\x03foo",
4965 "-select-next-proto", "foo",
4966 },
4967 shouldFail: true,
4968 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4969 })
David Benjamin97d17d92016-07-14 16:12:00 -04004970 }
4971
4972 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004973
4974 // Resume with a corrupt ticket.
4975 testCases = append(testCases, testCase{
4976 testType: serverTest,
4977 name: "CorruptTicket-" + ver.name,
4978 config: Config{
4979 MaxVersion: ver.version,
4980 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004981 FilterTicket: func(in []byte) ([]byte, error) {
4982 in[len(in)-1] ^= 1
4983 return in, nil
4984 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04004985 },
4986 },
4987 resumeSession: true,
4988 expectResumeRejected: true,
4989 })
4990 // Test the ticket callback, with and without renewal.
4991 testCases = append(testCases, testCase{
4992 testType: serverTest,
4993 name: "TicketCallback-" + ver.name,
4994 config: Config{
4995 MaxVersion: ver.version,
4996 },
4997 resumeSession: true,
4998 flags: []string{"-use-ticket-callback"},
4999 })
5000 testCases = append(testCases, testCase{
5001 testType: serverTest,
5002 name: "TicketCallback-Renew-" + ver.name,
5003 config: Config{
5004 MaxVersion: ver.version,
5005 Bugs: ProtocolBugs{
5006 ExpectNewTicket: true,
5007 },
5008 },
5009 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5010 resumeSession: true,
5011 })
5012
5013 // Test that the ticket callback is only called once when everything before
5014 // it in the ClientHello is asynchronous. This corrupts the ticket so
5015 // certificate selection callbacks run.
5016 testCases = append(testCases, testCase{
5017 testType: serverTest,
5018 name: "TicketCallback-SingleCall-" + ver.name,
5019 config: Config{
5020 MaxVersion: ver.version,
5021 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005022 FilterTicket: func(in []byte) ([]byte, error) {
5023 in[len(in)-1] ^= 1
5024 return in, nil
5025 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005026 },
5027 },
5028 resumeSession: true,
5029 expectResumeRejected: true,
5030 flags: []string{
5031 "-use-ticket-callback",
5032 "-async",
5033 },
5034 })
5035
5036 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005037 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005038 testCases = append(testCases, testCase{
5039 testType: serverTest,
5040 name: "OversizedSessionId-" + ver.name,
5041 config: Config{
5042 MaxVersion: ver.version,
5043 Bugs: ProtocolBugs{
5044 OversizedSessionId: true,
5045 },
5046 },
5047 resumeSession: true,
5048 shouldFail: true,
5049 expectedError: ":DECODE_ERROR:",
5050 })
5051 }
5052
5053 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5054 // are ignored.
5055 if ver.hasDTLS {
5056 testCases = append(testCases, testCase{
5057 protocol: dtls,
5058 name: "SRTP-Client-" + ver.name,
5059 config: Config{
5060 MaxVersion: ver.version,
5061 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5062 },
5063 flags: []string{
5064 "-srtp-profiles",
5065 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5066 },
5067 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5068 })
5069 testCases = append(testCases, testCase{
5070 protocol: dtls,
5071 testType: serverTest,
5072 name: "SRTP-Server-" + ver.name,
5073 config: Config{
5074 MaxVersion: ver.version,
5075 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5076 },
5077 flags: []string{
5078 "-srtp-profiles",
5079 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5080 },
5081 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5082 })
5083 // Test that the MKI is ignored.
5084 testCases = append(testCases, testCase{
5085 protocol: dtls,
5086 testType: serverTest,
5087 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5088 config: Config{
5089 MaxVersion: ver.version,
5090 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5091 Bugs: ProtocolBugs{
5092 SRTPMasterKeyIdentifer: "bogus",
5093 },
5094 },
5095 flags: []string{
5096 "-srtp-profiles",
5097 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5098 },
5099 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5100 })
5101 // Test that SRTP isn't negotiated on the server if there were
5102 // no matching profiles.
5103 testCases = append(testCases, testCase{
5104 protocol: dtls,
5105 testType: serverTest,
5106 name: "SRTP-Server-NoMatch-" + ver.name,
5107 config: Config{
5108 MaxVersion: ver.version,
5109 SRTPProtectionProfiles: []uint16{100, 101, 102},
5110 },
5111 flags: []string{
5112 "-srtp-profiles",
5113 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5114 },
5115 expectedSRTPProtectionProfile: 0,
5116 })
5117 // Test that the server returning an invalid SRTP profile is
5118 // flagged as an error by the client.
5119 testCases = append(testCases, testCase{
5120 protocol: dtls,
5121 name: "SRTP-Client-NoMatch-" + ver.name,
5122 config: Config{
5123 MaxVersion: ver.version,
5124 Bugs: ProtocolBugs{
5125 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5126 },
5127 },
5128 flags: []string{
5129 "-srtp-profiles",
5130 "SRTP_AES128_CM_SHA1_80",
5131 },
5132 shouldFail: true,
5133 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5134 })
5135 }
5136
5137 // Test SCT list.
5138 testCases = append(testCases, testCase{
5139 name: "SignedCertificateTimestampList-Client-" + ver.name,
5140 testType: clientTest,
5141 config: Config{
5142 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005143 },
David Benjamin97d17d92016-07-14 16:12:00 -04005144 flags: []string{
5145 "-enable-signed-cert-timestamps",
5146 "-expect-signed-cert-timestamps",
5147 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005148 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005149 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005150 })
David Benjamindaa88502016-10-04 16:32:16 -04005151
Adam Langleycfa08c32016-11-17 13:21:27 -08005152 var differentSCTList []byte
5153 differentSCTList = append(differentSCTList, testSCTList...)
5154 differentSCTList[len(differentSCTList)-1] ^= 1
5155
David Benjamindaa88502016-10-04 16:32:16 -04005156 // The SCT extension did not specify that it must only be sent on resumption as it
5157 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005158 testCases = append(testCases, testCase{
5159 name: "SendSCTListOnResume-" + ver.name,
5160 config: Config{
5161 MaxVersion: ver.version,
5162 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005163 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005164 },
David Benjamind98452d2015-06-16 14:16:23 -04005165 },
David Benjamin97d17d92016-07-14 16:12:00 -04005166 flags: []string{
5167 "-enable-signed-cert-timestamps",
5168 "-expect-signed-cert-timestamps",
5169 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005170 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005171 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005172 })
David Benjamindaa88502016-10-04 16:32:16 -04005173
David Benjamin97d17d92016-07-14 16:12:00 -04005174 testCases = append(testCases, testCase{
5175 name: "SignedCertificateTimestampList-Server-" + ver.name,
5176 testType: serverTest,
5177 config: Config{
5178 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005179 },
David Benjamin97d17d92016-07-14 16:12:00 -04005180 flags: []string{
5181 "-signed-cert-timestamps",
5182 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005183 },
David Benjamin97d17d92016-07-14 16:12:00 -04005184 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005185 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005186 })
David Benjamin53210cb2016-11-16 09:01:48 +09005187
Adam Langleycfa08c32016-11-17 13:21:27 -08005188 emptySCTListCert := *testCerts[0].cert
5189 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5190
5191 // Test empty SCT list.
5192 testCases = append(testCases, testCase{
5193 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5194 testType: clientTest,
5195 config: Config{
5196 MaxVersion: ver.version,
5197 Certificates: []Certificate{emptySCTListCert},
5198 },
5199 flags: []string{
5200 "-enable-signed-cert-timestamps",
5201 },
5202 shouldFail: true,
5203 expectedError: ":ERROR_PARSING_EXTENSION:",
5204 })
5205
5206 emptySCTCert := *testCerts[0].cert
5207 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5208
5209 // Test empty SCT in non-empty list.
5210 testCases = append(testCases, testCase{
5211 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5212 testType: clientTest,
5213 config: Config{
5214 MaxVersion: ver.version,
5215 Certificates: []Certificate{emptySCTCert},
5216 },
5217 flags: []string{
5218 "-enable-signed-cert-timestamps",
5219 },
5220 shouldFail: true,
5221 expectedError: ":ERROR_PARSING_EXTENSION:",
5222 })
5223
David Benjamin53210cb2016-11-16 09:01:48 +09005224 // Test that certificate-related extensions are not sent unsolicited.
5225 testCases = append(testCases, testCase{
5226 testType: serverTest,
5227 name: "UnsolicitedCertificateExtensions-" + ver.name,
5228 config: Config{
5229 MaxVersion: ver.version,
5230 Bugs: ProtocolBugs{
5231 NoOCSPStapling: true,
5232 NoSignedCertificateTimestamps: true,
5233 },
5234 },
5235 flags: []string{
5236 "-ocsp-response",
5237 base64.StdEncoding.EncodeToString(testOCSPResponse),
5238 "-signed-cert-timestamps",
5239 base64.StdEncoding.EncodeToString(testSCTList),
5240 },
5241 })
David Benjamin97d17d92016-07-14 16:12:00 -04005242 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005243
Paul Lietar4fac72e2015-09-09 13:44:55 +01005244 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005245 testType: clientTest,
5246 name: "ClientHelloPadding",
5247 config: Config{
5248 Bugs: ProtocolBugs{
5249 RequireClientHelloSize: 512,
5250 },
5251 },
5252 // This hostname just needs to be long enough to push the
5253 // ClientHello into F5's danger zone between 256 and 511 bytes
5254 // long.
5255 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5256 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005257
5258 // Extensions should not function in SSL 3.0.
5259 testCases = append(testCases, testCase{
5260 testType: serverTest,
5261 name: "SSLv3Extensions-NoALPN",
5262 config: Config{
5263 MaxVersion: VersionSSL30,
5264 NextProtos: []string{"foo", "bar", "baz"},
5265 },
5266 flags: []string{
5267 "-select-alpn", "foo",
5268 },
5269 expectNoNextProto: true,
5270 })
5271
5272 // Test session tickets separately as they follow a different codepath.
5273 testCases = append(testCases, testCase{
5274 testType: serverTest,
5275 name: "SSLv3Extensions-NoTickets",
5276 config: Config{
5277 MaxVersion: VersionSSL30,
5278 Bugs: ProtocolBugs{
5279 // Historically, session tickets in SSL 3.0
5280 // failed in different ways depending on whether
5281 // the client supported renegotiation_info.
5282 NoRenegotiationInfo: true,
5283 },
5284 },
5285 resumeSession: true,
5286 })
5287 testCases = append(testCases, testCase{
5288 testType: serverTest,
5289 name: "SSLv3Extensions-NoTickets2",
5290 config: Config{
5291 MaxVersion: VersionSSL30,
5292 },
5293 resumeSession: true,
5294 })
5295
5296 // But SSL 3.0 does send and process renegotiation_info.
5297 testCases = append(testCases, testCase{
5298 testType: serverTest,
5299 name: "SSLv3Extensions-RenegotiationInfo",
5300 config: Config{
5301 MaxVersion: VersionSSL30,
5302 Bugs: ProtocolBugs{
5303 RequireRenegotiationInfo: true,
5304 },
5305 },
5306 })
5307 testCases = append(testCases, testCase{
5308 testType: serverTest,
5309 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5310 config: Config{
5311 MaxVersion: VersionSSL30,
5312 Bugs: ProtocolBugs{
5313 NoRenegotiationInfo: true,
5314 SendRenegotiationSCSV: true,
5315 RequireRenegotiationInfo: true,
5316 },
5317 },
5318 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005319
5320 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5321 // in ServerHello.
5322 testCases = append(testCases, testCase{
5323 name: "NPN-Forbidden-TLS13",
5324 config: Config{
5325 MaxVersion: VersionTLS13,
5326 NextProtos: []string{"foo"},
5327 Bugs: ProtocolBugs{
5328 NegotiateNPNAtAllVersions: true,
5329 },
5330 },
5331 flags: []string{"-select-next-proto", "foo"},
5332 shouldFail: true,
5333 expectedError: ":ERROR_PARSING_EXTENSION:",
5334 })
5335 testCases = append(testCases, testCase{
5336 name: "EMS-Forbidden-TLS13",
5337 config: Config{
5338 MaxVersion: VersionTLS13,
5339 Bugs: ProtocolBugs{
5340 NegotiateEMSAtAllVersions: true,
5341 },
5342 },
5343 shouldFail: true,
5344 expectedError: ":ERROR_PARSING_EXTENSION:",
5345 })
5346 testCases = append(testCases, testCase{
5347 name: "RenegotiationInfo-Forbidden-TLS13",
5348 config: Config{
5349 MaxVersion: VersionTLS13,
5350 Bugs: ProtocolBugs{
5351 NegotiateRenegotiationInfoAtAllVersions: true,
5352 },
5353 },
5354 shouldFail: true,
5355 expectedError: ":ERROR_PARSING_EXTENSION:",
5356 })
5357 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005358 name: "Ticket-Forbidden-TLS13",
5359 config: Config{
5360 MaxVersion: VersionTLS12,
5361 },
5362 resumeConfig: &Config{
5363 MaxVersion: VersionTLS13,
5364 Bugs: ProtocolBugs{
5365 AdvertiseTicketExtension: true,
5366 },
5367 },
5368 resumeSession: true,
5369 shouldFail: true,
5370 expectedError: ":ERROR_PARSING_EXTENSION:",
5371 })
5372
5373 // Test that illegal extensions in TLS 1.3 are declined by the server if
5374 // offered in ClientHello. The runner's server will fail if this occurs,
5375 // so we exercise the offering path. (EMS and Renegotiation Info are
5376 // implicit in every test.)
5377 testCases = append(testCases, testCase{
5378 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005379 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005380 config: Config{
5381 MaxVersion: VersionTLS13,
5382 NextProtos: []string{"bar"},
5383 },
5384 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5385 })
David Benjamin196df5b2016-09-21 16:23:27 -04005386
David Benjamindaa88502016-10-04 16:32:16 -04005387 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5388 // tolerated.
5389 testCases = append(testCases, testCase{
5390 name: "SendOCSPResponseOnResume-TLS12",
5391 config: Config{
5392 MaxVersion: VersionTLS12,
5393 Bugs: ProtocolBugs{
5394 SendOCSPResponseOnResume: []byte("bogus"),
5395 },
5396 },
5397 flags: []string{
5398 "-enable-ocsp-stapling",
5399 "-expect-ocsp-response",
5400 base64.StdEncoding.EncodeToString(testOCSPResponse),
5401 },
5402 resumeSession: true,
5403 })
5404
David Benjamindaa88502016-10-04 16:32:16 -04005405 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005406 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005407 config: Config{
5408 MaxVersion: VersionTLS13,
5409 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005410 SendExtensionOnCertificate: testOCSPExtension,
5411 },
5412 },
5413 shouldFail: true,
5414 expectedError: ":UNEXPECTED_EXTENSION:",
5415 })
5416
5417 testCases = append(testCases, testCase{
5418 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5419 config: Config{
5420 MaxVersion: VersionTLS13,
5421 Bugs: ProtocolBugs{
5422 SendExtensionOnCertificate: testSCTExtension,
5423 },
5424 },
5425 shouldFail: true,
5426 expectedError: ":UNEXPECTED_EXTENSION:",
5427 })
5428
5429 // Test that extensions on client certificates are never accepted.
5430 testCases = append(testCases, testCase{
5431 name: "SendExtensionOnClientCertificate-TLS13",
5432 testType: serverTest,
5433 config: Config{
5434 MaxVersion: VersionTLS13,
5435 Certificates: []Certificate{rsaCertificate},
5436 Bugs: ProtocolBugs{
5437 SendExtensionOnCertificate: testOCSPExtension,
5438 },
5439 },
5440 flags: []string{
5441 "-enable-ocsp-stapling",
5442 "-require-any-client-certificate",
5443 },
5444 shouldFail: true,
5445 expectedError: ":UNEXPECTED_EXTENSION:",
5446 })
5447
5448 testCases = append(testCases, testCase{
5449 name: "SendUnknownExtensionOnCertificate-TLS13",
5450 config: Config{
5451 MaxVersion: VersionTLS13,
5452 Bugs: ProtocolBugs{
5453 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5454 },
5455 },
5456 shouldFail: true,
5457 expectedError: ":UNEXPECTED_EXTENSION:",
5458 })
5459
Adam Langleycfa08c32016-11-17 13:21:27 -08005460 var differentSCTList []byte
5461 differentSCTList = append(differentSCTList, testSCTList...)
5462 differentSCTList[len(differentSCTList)-1] ^= 1
5463
Steven Valdeza833c352016-11-01 13:39:36 -04005464 // Test that extensions on intermediates are allowed but ignored.
5465 testCases = append(testCases, testCase{
5466 name: "IgnoreExtensionsOnIntermediates-TLS13",
5467 config: Config{
5468 MaxVersion: VersionTLS13,
5469 Certificates: []Certificate{rsaChainCertificate},
5470 Bugs: ProtocolBugs{
5471 // Send different values on the intermediate. This tests
5472 // the intermediate's extensions do not override the
5473 // leaf's.
5474 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005475 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005476 },
5477 },
5478 flags: []string{
5479 "-enable-ocsp-stapling",
5480 "-expect-ocsp-response",
5481 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005482 "-enable-signed-cert-timestamps",
5483 "-expect-signed-cert-timestamps",
5484 base64.StdEncoding.EncodeToString(testSCTList),
5485 },
5486 resumeSession: true,
5487 })
5488
5489 // Test that extensions are not sent on intermediates when configured
5490 // only for a leaf.
5491 testCases = append(testCases, testCase{
5492 testType: serverTest,
5493 name: "SendNoExtensionsOnIntermediate-TLS13",
5494 config: Config{
5495 MaxVersion: VersionTLS13,
5496 Bugs: ProtocolBugs{
5497 ExpectNoExtensionsOnIntermediate: true,
5498 },
5499 },
5500 flags: []string{
5501 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5502 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5503 "-ocsp-response",
5504 base64.StdEncoding.EncodeToString(testOCSPResponse),
5505 "-signed-cert-timestamps",
5506 base64.StdEncoding.EncodeToString(testSCTList),
5507 },
5508 })
5509
5510 // Test that extensions are not sent on client certificates.
5511 testCases = append(testCases, testCase{
5512 name: "SendNoClientCertificateExtensions-TLS13",
5513 config: Config{
5514 MaxVersion: VersionTLS13,
5515 ClientAuth: RequireAnyClientCert,
5516 },
5517 flags: []string{
5518 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5519 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5520 "-ocsp-response",
5521 base64.StdEncoding.EncodeToString(testOCSPResponse),
5522 "-signed-cert-timestamps",
5523 base64.StdEncoding.EncodeToString(testSCTList),
5524 },
5525 })
5526
5527 testCases = append(testCases, testCase{
5528 name: "SendDuplicateExtensionsOnCerts-TLS13",
5529 config: Config{
5530 MaxVersion: VersionTLS13,
5531 Bugs: ProtocolBugs{
5532 SendDuplicateCertExtensions: true,
5533 },
5534 },
5535 flags: []string{
5536 "-enable-ocsp-stapling",
5537 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005538 },
5539 resumeSession: true,
5540 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005541 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005542 })
Adam Langley9b885c52016-11-18 14:21:03 -08005543
5544 testCases = append(testCases, testCase{
5545 name: "SignedCertificateTimestampListInvalid-Server",
5546 testType: serverTest,
5547 flags: []string{
5548 "-signed-cert-timestamps",
5549 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5550 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005551 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005552 expectedError: ":INVALID_SCT_LIST:",
5553 })
David Benjamine78bfde2014-09-06 12:45:15 -04005554}
5555
David Benjamin01fe8202014-09-24 15:21:44 -04005556func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005557 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005558 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005559 // SSL 3.0 does not have tickets and TLS 1.3 does not
5560 // have session IDs, so skip their cross-resumption
5561 // tests.
5562 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5563 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5564 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005565 }
5566
David Benjamin8b8c0062014-11-23 02:47:52 -05005567 protocols := []protocol{tls}
5568 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5569 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005570 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005571 for _, protocol := range protocols {
5572 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5573 if protocol == dtls {
5574 suffix += "-DTLS"
5575 }
5576
David Benjaminece3de92015-03-16 18:02:20 -04005577 if sessionVers.version == resumeVers.version {
5578 testCases = append(testCases, testCase{
5579 protocol: protocol,
5580 name: "Resume-Client" + suffix,
5581 resumeSession: true,
5582 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005583 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005584 Bugs: ProtocolBugs{
5585 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5586 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5587 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005588 },
David Benjaminece3de92015-03-16 18:02:20 -04005589 expectedVersion: sessionVers.version,
5590 expectedResumeVersion: resumeVers.version,
5591 })
5592 } else {
David Benjamin405da482016-08-08 17:25:07 -04005593 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5594
5595 // Offering a TLS 1.3 session sends an empty session ID, so
5596 // there is no way to convince a non-lookahead client the
5597 // session was resumed. It will appear to the client that a
5598 // stray ChangeCipherSpec was sent.
5599 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5600 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005601 }
5602
David Benjaminece3de92015-03-16 18:02:20 -04005603 testCases = append(testCases, testCase{
5604 protocol: protocol,
5605 name: "Resume-Client-Mismatch" + suffix,
5606 resumeSession: true,
5607 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005608 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005609 },
David Benjaminece3de92015-03-16 18:02:20 -04005610 expectedVersion: sessionVers.version,
5611 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005612 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005613 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005614 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005615 },
5616 },
5617 expectedResumeVersion: resumeVers.version,
5618 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005619 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005620 })
5621 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005622
5623 testCases = append(testCases, testCase{
5624 protocol: protocol,
5625 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005626 resumeSession: true,
5627 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005628 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005629 },
5630 expectedVersion: sessionVers.version,
5631 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005632 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005633 },
5634 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005635 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005636 expectedResumeVersion: resumeVers.version,
5637 })
5638
David Benjamin8b8c0062014-11-23 02:47:52 -05005639 testCases = append(testCases, testCase{
5640 protocol: protocol,
5641 testType: serverTest,
5642 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005643 resumeSession: true,
5644 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005645 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005646 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005647 expectedVersion: sessionVers.version,
5648 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005649 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005650 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005651 Bugs: ProtocolBugs{
5652 SendBothTickets: true,
5653 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005654 },
5655 expectedResumeVersion: resumeVers.version,
5656 })
5657 }
David Benjamin01fe8202014-09-24 15:21:44 -04005658 }
5659 }
David Benjaminece3de92015-03-16 18:02:20 -04005660
David Benjamin4199b0d2016-11-01 13:58:25 -04005661 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005662 testCases = append(testCases, testCase{
5663 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005664 name: "ShimTicketRewritable",
5665 resumeSession: true,
5666 config: Config{
5667 MaxVersion: VersionTLS12,
5668 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5669 Bugs: ProtocolBugs{
5670 FilterTicket: func(in []byte) ([]byte, error) {
5671 in, err := SetShimTicketVersion(in, VersionTLS12)
5672 if err != nil {
5673 return nil, err
5674 }
5675 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5676 },
5677 },
5678 },
5679 flags: []string{
5680 "-ticket-key",
5681 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5682 },
5683 })
5684
5685 // Resumptions are declined if the version does not match.
5686 testCases = append(testCases, testCase{
5687 testType: serverTest,
5688 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005689 resumeSession: true,
5690 config: Config{
5691 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005692 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005693 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005694 FilterTicket: func(in []byte) ([]byte, error) {
5695 return SetShimTicketVersion(in, VersionTLS13)
5696 },
5697 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005698 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005699 flags: []string{
5700 "-ticket-key",
5701 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5702 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005703 expectResumeRejected: true,
5704 })
5705
5706 testCases = append(testCases, testCase{
5707 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005708 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005709 resumeSession: true,
5710 config: Config{
5711 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005712 Bugs: ProtocolBugs{
5713 FilterTicket: func(in []byte) ([]byte, error) {
5714 return SetShimTicketVersion(in, VersionTLS12)
5715 },
5716 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005717 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005718 flags: []string{
5719 "-ticket-key",
5720 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5721 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005722 expectResumeRejected: true,
5723 })
5724
David Benjamin4199b0d2016-11-01 13:58:25 -04005725 // Resumptions are declined if the cipher is invalid or disabled.
5726 testCases = append(testCases, testCase{
5727 testType: serverTest,
5728 name: "Resume-Server-DeclineBadCipher",
5729 resumeSession: true,
5730 config: Config{
5731 MaxVersion: VersionTLS12,
5732 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005733 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005734 FilterTicket: func(in []byte) ([]byte, error) {
5735 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5736 },
5737 },
5738 },
5739 flags: []string{
5740 "-ticket-key",
5741 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5742 },
5743 expectResumeRejected: true,
5744 })
5745
5746 testCases = append(testCases, testCase{
5747 testType: serverTest,
5748 name: "Resume-Server-DeclineBadCipher-2",
5749 resumeSession: true,
5750 config: Config{
5751 MaxVersion: VersionTLS12,
5752 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005753 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005754 FilterTicket: func(in []byte) ([]byte, error) {
5755 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5756 },
5757 },
5758 },
5759 flags: []string{
5760 "-cipher", "AES128",
5761 "-ticket-key",
5762 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5763 },
5764 expectResumeRejected: true,
5765 })
5766
David Benjaminf01f42a2016-11-16 19:05:33 +09005767 // Sessions are not resumed if they do not use the preferred cipher.
5768 testCases = append(testCases, testCase{
5769 testType: serverTest,
5770 name: "Resume-Server-CipherNotPreferred",
5771 resumeSession: true,
5772 config: Config{
5773 MaxVersion: VersionTLS12,
5774 Bugs: ProtocolBugs{
5775 ExpectNewTicket: true,
5776 FilterTicket: func(in []byte) ([]byte, error) {
5777 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5778 },
5779 },
5780 },
5781 flags: []string{
5782 "-ticket-key",
5783 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5784 },
5785 shouldFail: false,
5786 expectResumeRejected: true,
5787 })
5788
5789 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5790 // PRF hashes match, but BoringSSL will always decline such resumptions.
5791 testCases = append(testCases, testCase{
5792 testType: serverTest,
5793 name: "Resume-Server-CipherNotPreferred-TLS13",
5794 resumeSession: true,
5795 config: Config{
5796 MaxVersion: VersionTLS13,
5797 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5798 Bugs: ProtocolBugs{
5799 FilterTicket: func(in []byte) ([]byte, error) {
5800 // If the client (runner) offers ChaCha20-Poly1305 first, the
5801 // server (shim) always prefers it. Switch it to AES-GCM.
5802 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5803 },
5804 },
5805 },
5806 flags: []string{
5807 "-ticket-key",
5808 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5809 },
5810 shouldFail: false,
5811 expectResumeRejected: true,
5812 })
5813
5814 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005815 testCases = append(testCases, testCase{
5816 testType: serverTest,
5817 name: "Resume-Server-DeclineBadCipher-TLS13",
5818 resumeSession: true,
5819 config: Config{
5820 MaxVersion: VersionTLS13,
5821 Bugs: ProtocolBugs{
5822 FilterTicket: func(in []byte) ([]byte, error) {
5823 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5824 },
5825 },
5826 },
5827 flags: []string{
5828 "-ticket-key",
5829 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5830 },
5831 expectResumeRejected: true,
5832 })
5833
David Benjaminf01f42a2016-11-16 19:05:33 +09005834 // If the client does not offer the cipher from the session, decline to
5835 // resume. Clients are forbidden from doing this, but BoringSSL selects
5836 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005837 testCases = append(testCases, testCase{
5838 testType: serverTest,
5839 name: "Resume-Server-UnofferedCipher",
5840 resumeSession: true,
5841 config: Config{
5842 MaxVersion: VersionTLS12,
5843 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5844 },
5845 resumeConfig: &Config{
5846 MaxVersion: VersionTLS12,
5847 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5848 Bugs: ProtocolBugs{
5849 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5850 },
5851 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005852 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005853 })
5854
David Benjaminf01f42a2016-11-16 19:05:33 +09005855 // In TLS 1.3, clients may advertise a cipher list which does not
5856 // include the selected cipher. Test that we tolerate this. Servers may
5857 // resume at another cipher if the PRF matches, but BoringSSL will
5858 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005859 testCases = append(testCases, testCase{
5860 testType: serverTest,
5861 name: "Resume-Server-UnofferedCipher-TLS13",
5862 resumeSession: true,
5863 config: Config{
5864 MaxVersion: VersionTLS13,
5865 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5866 },
5867 resumeConfig: &Config{
5868 MaxVersion: VersionTLS13,
5869 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5870 Bugs: ProtocolBugs{
5871 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5872 },
5873 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005874 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005875 })
5876
David Benjamin4199b0d2016-11-01 13:58:25 -04005877 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005878 testCases = append(testCases, testCase{
5879 name: "Resume-Client-CipherMismatch",
5880 resumeSession: true,
5881 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005882 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005883 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5884 },
5885 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005886 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005887 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5888 Bugs: ProtocolBugs{
5889 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5890 },
5891 },
5892 shouldFail: true,
5893 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5894 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005895
David Benjamine1cc35e2016-11-16 16:25:58 +09005896 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5897 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005898 testCases = append(testCases, testCase{
5899 name: "Resume-Client-CipherMismatch-TLS13",
5900 resumeSession: true,
5901 config: Config{
5902 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005903 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005904 },
5905 resumeConfig: &Config{
5906 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005907 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5908 },
5909 })
5910
5911 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5912 testCases = append(testCases, testCase{
5913 name: "Resume-Client-PRFMismatch-TLS13",
5914 resumeSession: true,
5915 config: Config{
5916 MaxVersion: VersionTLS13,
5917 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5918 },
5919 resumeConfig: &Config{
5920 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005921 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005922 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005923 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005924 },
5925 },
5926 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005927 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005928 })
Steven Valdeza833c352016-11-01 13:39:36 -04005929
5930 testCases = append(testCases, testCase{
5931 testType: serverTest,
5932 name: "Resume-Server-BinderWrongLength",
5933 resumeSession: true,
5934 config: Config{
5935 MaxVersion: VersionTLS13,
5936 Bugs: ProtocolBugs{
5937 SendShortPSKBinder: true,
5938 },
5939 },
5940 shouldFail: true,
5941 expectedLocalError: "remote error: error decrypting message",
5942 expectedError: ":DIGEST_CHECK_FAILED:",
5943 })
5944
5945 testCases = append(testCases, testCase{
5946 testType: serverTest,
5947 name: "Resume-Server-NoPSKBinder",
5948 resumeSession: true,
5949 config: Config{
5950 MaxVersion: VersionTLS13,
5951 Bugs: ProtocolBugs{
5952 SendNoPSKBinder: true,
5953 },
5954 },
5955 shouldFail: true,
5956 expectedLocalError: "remote error: error decoding message",
5957 expectedError: ":DECODE_ERROR:",
5958 })
5959
5960 testCases = append(testCases, testCase{
5961 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05005962 name: "Resume-Server-ExtraPSKBinder",
5963 resumeSession: true,
5964 config: Config{
5965 MaxVersion: VersionTLS13,
5966 Bugs: ProtocolBugs{
5967 SendExtraPSKBinder: true,
5968 },
5969 },
5970 shouldFail: true,
5971 expectedLocalError: "remote error: illegal parameter",
5972 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5973 })
5974
5975 testCases = append(testCases, testCase{
5976 testType: serverTest,
5977 name: "Resume-Server-ExtraIdentityNoBinder",
5978 resumeSession: true,
5979 config: Config{
5980 MaxVersion: VersionTLS13,
5981 Bugs: ProtocolBugs{
5982 ExtraPSKIdentity: true,
5983 },
5984 },
5985 shouldFail: true,
5986 expectedLocalError: "remote error: illegal parameter",
5987 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
5988 })
5989
5990 testCases = append(testCases, testCase{
5991 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04005992 name: "Resume-Server-InvalidPSKBinder",
5993 resumeSession: true,
5994 config: Config{
5995 MaxVersion: VersionTLS13,
5996 Bugs: ProtocolBugs{
5997 SendInvalidPSKBinder: true,
5998 },
5999 },
6000 shouldFail: true,
6001 expectedLocalError: "remote error: error decrypting message",
6002 expectedError: ":DIGEST_CHECK_FAILED:",
6003 })
6004
6005 testCases = append(testCases, testCase{
6006 testType: serverTest,
6007 name: "Resume-Server-PSKBinderFirstExtension",
6008 resumeSession: true,
6009 config: Config{
6010 MaxVersion: VersionTLS13,
6011 Bugs: ProtocolBugs{
6012 PSKBinderFirst: true,
6013 },
6014 },
6015 shouldFail: true,
6016 expectedLocalError: "remote error: illegal parameter",
6017 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6018 })
David Benjamin01fe8202014-09-24 15:21:44 -04006019}
6020
Adam Langley2ae77d22014-10-28 17:29:33 -07006021func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006022 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006023 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006024 testType: serverTest,
6025 name: "Renegotiate-Server-Forbidden",
6026 config: Config{
6027 MaxVersion: VersionTLS12,
6028 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006029 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006030 shouldFail: true,
6031 expectedError: ":NO_RENEGOTIATION:",
6032 expectedLocalError: "remote error: no renegotiation",
6033 })
Adam Langley5021b222015-06-12 18:27:58 -07006034 // The server shouldn't echo the renegotiation extension unless
6035 // requested by the client.
6036 testCases = append(testCases, testCase{
6037 testType: serverTest,
6038 name: "Renegotiate-Server-NoExt",
6039 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006040 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006041 Bugs: ProtocolBugs{
6042 NoRenegotiationInfo: true,
6043 RequireRenegotiationInfo: true,
6044 },
6045 },
6046 shouldFail: true,
6047 expectedLocalError: "renegotiation extension missing",
6048 })
6049 // The renegotiation SCSV should be sufficient for the server to echo
6050 // the extension.
6051 testCases = append(testCases, testCase{
6052 testType: serverTest,
6053 name: "Renegotiate-Server-NoExt-SCSV",
6054 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006055 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006056 Bugs: ProtocolBugs{
6057 NoRenegotiationInfo: true,
6058 SendRenegotiationSCSV: true,
6059 RequireRenegotiationInfo: true,
6060 },
6061 },
6062 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006063 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006064 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006065 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006066 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006067 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006068 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006069 },
6070 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006071 renegotiate: 1,
6072 flags: []string{
6073 "-renegotiate-freely",
6074 "-expect-total-renegotiations", "1",
6075 },
David Benjamincdea40c2015-03-19 14:09:43 -04006076 })
6077 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006078 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006079 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006080 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006081 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006082 Bugs: ProtocolBugs{
6083 EmptyRenegotiationInfo: true,
6084 },
6085 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006086 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006087 shouldFail: true,
6088 expectedError: ":RENEGOTIATION_MISMATCH:",
6089 })
6090 testCases = append(testCases, testCase{
6091 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006092 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006093 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006094 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006095 Bugs: ProtocolBugs{
6096 BadRenegotiationInfo: true,
6097 },
6098 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006099 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006100 shouldFail: true,
6101 expectedError: ":RENEGOTIATION_MISMATCH:",
6102 })
6103 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006104 name: "Renegotiate-Client-Downgrade",
6105 renegotiate: 1,
6106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006107 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006108 Bugs: ProtocolBugs{
6109 NoRenegotiationInfoAfterInitial: true,
6110 },
6111 },
6112 flags: []string{"-renegotiate-freely"},
6113 shouldFail: true,
6114 expectedError: ":RENEGOTIATION_MISMATCH:",
6115 })
6116 testCases = append(testCases, testCase{
6117 name: "Renegotiate-Client-Upgrade",
6118 renegotiate: 1,
6119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006120 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006121 Bugs: ProtocolBugs{
6122 NoRenegotiationInfoInInitial: true,
6123 },
6124 },
6125 flags: []string{"-renegotiate-freely"},
6126 shouldFail: true,
6127 expectedError: ":RENEGOTIATION_MISMATCH:",
6128 })
6129 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006130 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006131 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006133 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006134 Bugs: ProtocolBugs{
6135 NoRenegotiationInfo: true,
6136 },
6137 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006138 flags: []string{
6139 "-renegotiate-freely",
6140 "-expect-total-renegotiations", "1",
6141 },
David Benjamincff0b902015-05-15 23:09:47 -04006142 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006143
6144 // Test that the server may switch ciphers on renegotiation without
6145 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006146 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006147 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006148 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006149 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006150 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006151 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006152 },
6153 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006154 flags: []string{
6155 "-renegotiate-freely",
6156 "-expect-total-renegotiations", "1",
6157 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006158 })
6159 testCases = append(testCases, testCase{
6160 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006161 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006162 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006163 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006164 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6165 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006166 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006167 flags: []string{
6168 "-renegotiate-freely",
6169 "-expect-total-renegotiations", "1",
6170 },
David Benjaminb16346b2015-04-08 19:16:58 -04006171 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006172
6173 // Test that the server may not switch versions on renegotiation.
6174 testCases = append(testCases, testCase{
6175 name: "Renegotiate-Client-SwitchVersion",
6176 config: Config{
6177 MaxVersion: VersionTLS12,
6178 // Pick a cipher which exists at both versions.
6179 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6180 Bugs: ProtocolBugs{
6181 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006182 // Avoid failing early at the record layer.
6183 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006184 },
6185 },
6186 renegotiate: 1,
6187 flags: []string{
6188 "-renegotiate-freely",
6189 "-expect-total-renegotiations", "1",
6190 },
6191 shouldFail: true,
6192 expectedError: ":WRONG_SSL_VERSION:",
6193 })
6194
David Benjaminb16346b2015-04-08 19:16:58 -04006195 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006196 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006197 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006198 config: Config{
6199 MaxVersion: VersionTLS10,
6200 Bugs: ProtocolBugs{
6201 RequireSameRenegoClientVersion: true,
6202 },
6203 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006204 flags: []string{
6205 "-renegotiate-freely",
6206 "-expect-total-renegotiations", "1",
6207 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006208 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006209 testCases = append(testCases, testCase{
6210 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006211 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006212 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006213 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006214 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6215 NextProtos: []string{"foo"},
6216 },
6217 flags: []string{
6218 "-false-start",
6219 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006220 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006221 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006222 },
6223 shimWritesFirst: true,
6224 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006225
6226 // Client-side renegotiation controls.
6227 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006228 name: "Renegotiate-Client-Forbidden-1",
6229 config: Config{
6230 MaxVersion: VersionTLS12,
6231 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006232 renegotiate: 1,
6233 shouldFail: true,
6234 expectedError: ":NO_RENEGOTIATION:",
6235 expectedLocalError: "remote error: no renegotiation",
6236 })
6237 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006238 name: "Renegotiate-Client-Once-1",
6239 config: Config{
6240 MaxVersion: VersionTLS12,
6241 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006242 renegotiate: 1,
6243 flags: []string{
6244 "-renegotiate-once",
6245 "-expect-total-renegotiations", "1",
6246 },
6247 })
6248 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006249 name: "Renegotiate-Client-Freely-1",
6250 config: Config{
6251 MaxVersion: VersionTLS12,
6252 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006253 renegotiate: 1,
6254 flags: []string{
6255 "-renegotiate-freely",
6256 "-expect-total-renegotiations", "1",
6257 },
6258 })
6259 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006260 name: "Renegotiate-Client-Once-2",
6261 config: Config{
6262 MaxVersion: VersionTLS12,
6263 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006264 renegotiate: 2,
6265 flags: []string{"-renegotiate-once"},
6266 shouldFail: true,
6267 expectedError: ":NO_RENEGOTIATION:",
6268 expectedLocalError: "remote error: no renegotiation",
6269 })
6270 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006271 name: "Renegotiate-Client-Freely-2",
6272 config: Config{
6273 MaxVersion: VersionTLS12,
6274 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006275 renegotiate: 2,
6276 flags: []string{
6277 "-renegotiate-freely",
6278 "-expect-total-renegotiations", "2",
6279 },
6280 })
Adam Langley27a0d082015-11-03 13:34:10 -08006281 testCases = append(testCases, testCase{
6282 name: "Renegotiate-Client-NoIgnore",
6283 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006284 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006285 Bugs: ProtocolBugs{
6286 SendHelloRequestBeforeEveryAppDataRecord: true,
6287 },
6288 },
6289 shouldFail: true,
6290 expectedError: ":NO_RENEGOTIATION:",
6291 })
6292 testCases = append(testCases, testCase{
6293 name: "Renegotiate-Client-Ignore",
6294 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006295 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006296 Bugs: ProtocolBugs{
6297 SendHelloRequestBeforeEveryAppDataRecord: true,
6298 },
6299 },
6300 flags: []string{
6301 "-renegotiate-ignore",
6302 "-expect-total-renegotiations", "0",
6303 },
6304 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006305
David Benjamin34941c02016-10-08 11:45:31 -04006306 // Renegotiation is not allowed at SSL 3.0.
6307 testCases = append(testCases, testCase{
6308 name: "Renegotiate-Client-SSL3",
6309 config: Config{
6310 MaxVersion: VersionSSL30,
6311 },
6312 renegotiate: 1,
6313 flags: []string{
6314 "-renegotiate-freely",
6315 "-expect-total-renegotiations", "1",
6316 },
6317 shouldFail: true,
6318 expectedError: ":NO_RENEGOTIATION:",
6319 expectedLocalError: "remote error: no renegotiation",
6320 })
6321
David Benjamin397c8e62016-07-08 14:14:36 -07006322 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006323 testCases = append(testCases, testCase{
6324 name: "StrayHelloRequest",
6325 config: Config{
6326 MaxVersion: VersionTLS12,
6327 Bugs: ProtocolBugs{
6328 SendHelloRequestBeforeEveryHandshakeMessage: true,
6329 },
6330 },
6331 })
6332 testCases = append(testCases, testCase{
6333 name: "StrayHelloRequest-Packed",
6334 config: Config{
6335 MaxVersion: VersionTLS12,
6336 Bugs: ProtocolBugs{
6337 PackHandshakeFlight: true,
6338 SendHelloRequestBeforeEveryHandshakeMessage: true,
6339 },
6340 },
6341 })
6342
David Benjamin12d2c482016-07-24 10:56:51 -04006343 // Test renegotiation works if HelloRequest and server Finished come in
6344 // the same record.
6345 testCases = append(testCases, testCase{
6346 name: "Renegotiate-Client-Packed",
6347 config: Config{
6348 MaxVersion: VersionTLS12,
6349 Bugs: ProtocolBugs{
6350 PackHandshakeFlight: true,
6351 PackHelloRequestWithFinished: true,
6352 },
6353 },
6354 renegotiate: 1,
6355 flags: []string{
6356 "-renegotiate-freely",
6357 "-expect-total-renegotiations", "1",
6358 },
6359 })
6360
David Benjamin397c8e62016-07-08 14:14:36 -07006361 // Renegotiation is forbidden in TLS 1.3.
6362 testCases = append(testCases, testCase{
6363 name: "Renegotiate-Client-TLS13",
6364 config: Config{
6365 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006366 Bugs: ProtocolBugs{
6367 SendHelloRequestBeforeEveryAppDataRecord: true,
6368 },
David Benjamin397c8e62016-07-08 14:14:36 -07006369 },
David Benjamin397c8e62016-07-08 14:14:36 -07006370 flags: []string{
6371 "-renegotiate-freely",
6372 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006373 shouldFail: true,
6374 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006375 })
6376
6377 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6378 testCases = append(testCases, testCase{
6379 name: "StrayHelloRequest-TLS13",
6380 config: Config{
6381 MaxVersion: VersionTLS13,
6382 Bugs: ProtocolBugs{
6383 SendHelloRequestBeforeEveryHandshakeMessage: true,
6384 },
6385 },
6386 shouldFail: true,
6387 expectedError: ":UNEXPECTED_MESSAGE:",
6388 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006389}
6390
David Benjamin5e961c12014-11-07 01:48:35 -05006391func addDTLSReplayTests() {
6392 // Test that sequence number replays are detected.
6393 testCases = append(testCases, testCase{
6394 protocol: dtls,
6395 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006396 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006397 replayWrites: true,
6398 })
6399
David Benjamin8e6db492015-07-25 18:29:23 -04006400 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006401 // than the retransmit window.
6402 testCases = append(testCases, testCase{
6403 protocol: dtls,
6404 name: "DTLS-Replay-LargeGaps",
6405 config: Config{
6406 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006407 SequenceNumberMapping: func(in uint64) uint64 {
6408 return in * 127
6409 },
David Benjamin5e961c12014-11-07 01:48:35 -05006410 },
6411 },
David Benjamin8e6db492015-07-25 18:29:23 -04006412 messageCount: 200,
6413 replayWrites: true,
6414 })
6415
6416 // Test the incoming sequence number changing non-monotonically.
6417 testCases = append(testCases, testCase{
6418 protocol: dtls,
6419 name: "DTLS-Replay-NonMonotonic",
6420 config: Config{
6421 Bugs: ProtocolBugs{
6422 SequenceNumberMapping: func(in uint64) uint64 {
6423 return in ^ 31
6424 },
6425 },
6426 },
6427 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006428 replayWrites: true,
6429 })
6430}
6431
Nick Harper60edffd2016-06-21 15:19:24 -07006432var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006433 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006434 id signatureAlgorithm
6435 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006436}{
Nick Harper60edffd2016-06-21 15:19:24 -07006437 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6438 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6439 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6440 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006441 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006442 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6443 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6444 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006445 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6446 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6447 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006448 // Tests for key types prior to TLS 1.2.
6449 {"RSA", 0, testCertRSA},
6450 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006451}
6452
Nick Harper60edffd2016-06-21 15:19:24 -07006453const fakeSigAlg1 signatureAlgorithm = 0x2a01
6454const fakeSigAlg2 signatureAlgorithm = 0xff01
6455
6456func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006457 // Not all ciphers involve a signature. Advertise a list which gives all
6458 // versions a signing cipher.
6459 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006460 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006461 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6462 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6463 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6464 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6465 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6466 }
6467
David Benjaminca3d5452016-07-14 12:51:01 -04006468 var allAlgorithms []signatureAlgorithm
6469 for _, alg := range testSignatureAlgorithms {
6470 if alg.id != 0 {
6471 allAlgorithms = append(allAlgorithms, alg.id)
6472 }
6473 }
6474
Nick Harper60edffd2016-06-21 15:19:24 -07006475 // Make sure each signature algorithm works. Include some fake values in
6476 // the list and ensure they're ignored.
6477 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006478 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006479 if (ver.version < VersionTLS12) != (alg.id == 0) {
6480 continue
6481 }
6482
6483 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6484 // or remove it in C.
6485 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006486 continue
6487 }
Nick Harper60edffd2016-06-21 15:19:24 -07006488
David Benjamin3ef76972016-10-17 17:59:54 -04006489 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006490 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006491 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006492 shouldSignFail = true
6493 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006494 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006495 // RSA-PKCS1 does not exist in TLS 1.3.
6496 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006497 shouldSignFail = true
6498 shouldVerifyFail = true
6499 }
6500
6501 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6502 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6503 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006504 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006505
6506 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006507 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006508 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006509 }
6510 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006511 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006512 }
David Benjamin000800a2014-11-14 01:43:59 -05006513
David Benjamin1fb125c2016-07-08 18:52:12 -07006514 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006515
David Benjamin7a41d372016-07-09 11:21:54 -07006516 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006517 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006518 config: Config{
6519 MaxVersion: ver.version,
6520 ClientAuth: RequireAnyClientCert,
6521 VerifySignatureAlgorithms: []signatureAlgorithm{
6522 fakeSigAlg1,
6523 alg.id,
6524 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006525 },
David Benjamin7a41d372016-07-09 11:21:54 -07006526 },
6527 flags: []string{
6528 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6529 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6530 "-enable-all-curves",
6531 },
David Benjamin3ef76972016-10-17 17:59:54 -04006532 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006533 expectedError: signError,
6534 expectedPeerSignatureAlgorithm: alg.id,
6535 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006536
David Benjamin7a41d372016-07-09 11:21:54 -07006537 testCases = append(testCases, testCase{
6538 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006539 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006540 config: Config{
6541 MaxVersion: ver.version,
6542 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6543 SignSignatureAlgorithms: []signatureAlgorithm{
6544 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006545 },
David Benjamin7a41d372016-07-09 11:21:54 -07006546 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006547 SkipECDSACurveCheck: shouldVerifyFail,
6548 IgnoreSignatureVersionChecks: shouldVerifyFail,
6549 // Some signature algorithms may not be advertised.
6550 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006551 },
David Benjamin7a41d372016-07-09 11:21:54 -07006552 },
6553 flags: []string{
6554 "-require-any-client-certificate",
6555 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6556 "-enable-all-curves",
6557 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006558 // Resume the session to assert the peer signature
6559 // algorithm is reported on both handshakes.
6560 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006561 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006562 expectedError: verifyError,
6563 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006564
6565 testCases = append(testCases, testCase{
6566 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006567 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006568 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006569 MaxVersion: ver.version,
6570 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006571 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006572 fakeSigAlg1,
6573 alg.id,
6574 fakeSigAlg2,
6575 },
6576 },
6577 flags: []string{
6578 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6579 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6580 "-enable-all-curves",
6581 },
David Benjamin3ef76972016-10-17 17:59:54 -04006582 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006583 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006584 expectedPeerSignatureAlgorithm: alg.id,
6585 })
6586
6587 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006588 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006589 config: Config{
6590 MaxVersion: ver.version,
6591 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006592 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006593 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006594 alg.id,
6595 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006596 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006597 SkipECDSACurveCheck: shouldVerifyFail,
6598 IgnoreSignatureVersionChecks: shouldVerifyFail,
6599 // Some signature algorithms may not be advertised.
6600 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006601 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006602 },
6603 flags: []string{
6604 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6605 "-enable-all-curves",
6606 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006607 // Resume the session to assert the peer signature
6608 // algorithm is reported on both handshakes.
6609 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006610 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006611 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006612 })
David Benjamin5208fd42016-07-13 21:43:25 -04006613
David Benjamin3ef76972016-10-17 17:59:54 -04006614 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006615 testCases = append(testCases, testCase{
6616 testType: serverTest,
6617 name: "ClientAuth-InvalidSignature" + suffix,
6618 config: Config{
6619 MaxVersion: ver.version,
6620 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6621 SignSignatureAlgorithms: []signatureAlgorithm{
6622 alg.id,
6623 },
6624 Bugs: ProtocolBugs{
6625 InvalidSignature: true,
6626 },
6627 },
6628 flags: []string{
6629 "-require-any-client-certificate",
6630 "-enable-all-curves",
6631 },
6632 shouldFail: true,
6633 expectedError: ":BAD_SIGNATURE:",
6634 })
6635
6636 testCases = append(testCases, testCase{
6637 name: "ServerAuth-InvalidSignature" + suffix,
6638 config: Config{
6639 MaxVersion: ver.version,
6640 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6641 CipherSuites: signingCiphers,
6642 SignSignatureAlgorithms: []signatureAlgorithm{
6643 alg.id,
6644 },
6645 Bugs: ProtocolBugs{
6646 InvalidSignature: true,
6647 },
6648 },
6649 flags: []string{"-enable-all-curves"},
6650 shouldFail: true,
6651 expectedError: ":BAD_SIGNATURE:",
6652 })
6653 }
David Benjaminca3d5452016-07-14 12:51:01 -04006654
David Benjamin3ef76972016-10-17 17:59:54 -04006655 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006656 testCases = append(testCases, testCase{
6657 name: "ClientAuth-Sign-Negotiate" + suffix,
6658 config: Config{
6659 MaxVersion: ver.version,
6660 ClientAuth: RequireAnyClientCert,
6661 VerifySignatureAlgorithms: allAlgorithms,
6662 },
6663 flags: []string{
6664 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6665 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6666 "-enable-all-curves",
6667 "-signing-prefs", strconv.Itoa(int(alg.id)),
6668 },
6669 expectedPeerSignatureAlgorithm: alg.id,
6670 })
6671
6672 testCases = append(testCases, testCase{
6673 testType: serverTest,
6674 name: "ServerAuth-Sign-Negotiate" + suffix,
6675 config: Config{
6676 MaxVersion: ver.version,
6677 CipherSuites: signingCiphers,
6678 VerifySignatureAlgorithms: allAlgorithms,
6679 },
6680 flags: []string{
6681 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6682 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6683 "-enable-all-curves",
6684 "-signing-prefs", strconv.Itoa(int(alg.id)),
6685 },
6686 expectedPeerSignatureAlgorithm: alg.id,
6687 })
6688 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006689 }
David Benjamin000800a2014-11-14 01:43:59 -05006690 }
6691
Nick Harper60edffd2016-06-21 15:19:24 -07006692 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006693 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006694 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006695 config: Config{
6696 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006697 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006698 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006699 signatureECDSAWithP521AndSHA512,
6700 signatureRSAPKCS1WithSHA384,
6701 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006702 },
6703 },
6704 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006705 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6706 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006707 },
Nick Harper60edffd2016-06-21 15:19:24 -07006708 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006709 })
6710
6711 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006712 name: "ClientAuth-SignatureType-TLS13",
6713 config: Config{
6714 ClientAuth: RequireAnyClientCert,
6715 MaxVersion: VersionTLS13,
6716 VerifySignatureAlgorithms: []signatureAlgorithm{
6717 signatureECDSAWithP521AndSHA512,
6718 signatureRSAPKCS1WithSHA384,
6719 signatureRSAPSSWithSHA384,
6720 signatureECDSAWithSHA1,
6721 },
6722 },
6723 flags: []string{
6724 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6725 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6726 },
6727 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6728 })
6729
6730 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006731 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006732 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006733 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006734 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006735 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006736 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006737 signatureECDSAWithP521AndSHA512,
6738 signatureRSAPKCS1WithSHA384,
6739 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006740 },
6741 },
Nick Harper60edffd2016-06-21 15:19:24 -07006742 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006743 })
6744
Steven Valdez143e8b32016-07-11 13:19:03 -04006745 testCases = append(testCases, testCase{
6746 testType: serverTest,
6747 name: "ServerAuth-SignatureType-TLS13",
6748 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006749 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006750 VerifySignatureAlgorithms: []signatureAlgorithm{
6751 signatureECDSAWithP521AndSHA512,
6752 signatureRSAPKCS1WithSHA384,
6753 signatureRSAPSSWithSHA384,
6754 signatureECDSAWithSHA1,
6755 },
6756 },
6757 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6758 })
6759
David Benjamina95e9f32016-07-08 16:28:04 -07006760 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006761 testCases = append(testCases, testCase{
6762 testType: serverTest,
6763 name: "Verify-ClientAuth-SignatureType",
6764 config: Config{
6765 MaxVersion: VersionTLS12,
6766 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006767 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006768 signatureRSAPKCS1WithSHA256,
6769 },
6770 Bugs: ProtocolBugs{
6771 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6772 },
6773 },
6774 flags: []string{
6775 "-require-any-client-certificate",
6776 },
6777 shouldFail: true,
6778 expectedError: ":WRONG_SIGNATURE_TYPE:",
6779 })
6780
6781 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006782 testType: serverTest,
6783 name: "Verify-ClientAuth-SignatureType-TLS13",
6784 config: Config{
6785 MaxVersion: VersionTLS13,
6786 Certificates: []Certificate{rsaCertificate},
6787 SignSignatureAlgorithms: []signatureAlgorithm{
6788 signatureRSAPSSWithSHA256,
6789 },
6790 Bugs: ProtocolBugs{
6791 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6792 },
6793 },
6794 flags: []string{
6795 "-require-any-client-certificate",
6796 },
6797 shouldFail: true,
6798 expectedError: ":WRONG_SIGNATURE_TYPE:",
6799 })
6800
6801 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006802 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006803 config: Config{
6804 MaxVersion: VersionTLS12,
6805 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006806 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006807 signatureRSAPKCS1WithSHA256,
6808 },
6809 Bugs: ProtocolBugs{
6810 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6811 },
6812 },
6813 shouldFail: true,
6814 expectedError: ":WRONG_SIGNATURE_TYPE:",
6815 })
6816
Steven Valdez143e8b32016-07-11 13:19:03 -04006817 testCases = append(testCases, testCase{
6818 name: "Verify-ServerAuth-SignatureType-TLS13",
6819 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006820 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006821 SignSignatureAlgorithms: []signatureAlgorithm{
6822 signatureRSAPSSWithSHA256,
6823 },
6824 Bugs: ProtocolBugs{
6825 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6826 },
6827 },
6828 shouldFail: true,
6829 expectedError: ":WRONG_SIGNATURE_TYPE:",
6830 })
6831
David Benjamin51dd7d62016-07-08 16:07:01 -07006832 // Test that, if the list is missing, the peer falls back to SHA-1 in
6833 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006834 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006835 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006836 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006837 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006838 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006839 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006840 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006841 },
6842 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006843 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006844 },
6845 },
6846 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006847 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6848 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006849 },
6850 })
6851
6852 testCases = append(testCases, testCase{
6853 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006854 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006855 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006856 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006857 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006858 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006859 },
6860 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006861 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006862 },
6863 },
David Benjaminee32bea2016-08-17 13:36:44 -04006864 flags: []string{
6865 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6866 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6867 },
6868 })
6869
6870 testCases = append(testCases, testCase{
6871 name: "ClientAuth-SHA1-Fallback-ECDSA",
6872 config: Config{
6873 MaxVersion: VersionTLS12,
6874 ClientAuth: RequireAnyClientCert,
6875 VerifySignatureAlgorithms: []signatureAlgorithm{
6876 signatureECDSAWithSHA1,
6877 },
6878 Bugs: ProtocolBugs{
6879 NoSignatureAlgorithms: true,
6880 },
6881 },
6882 flags: []string{
6883 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6884 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6885 },
6886 })
6887
6888 testCases = append(testCases, testCase{
6889 testType: serverTest,
6890 name: "ServerAuth-SHA1-Fallback-ECDSA",
6891 config: Config{
6892 MaxVersion: VersionTLS12,
6893 VerifySignatureAlgorithms: []signatureAlgorithm{
6894 signatureECDSAWithSHA1,
6895 },
6896 Bugs: ProtocolBugs{
6897 NoSignatureAlgorithms: true,
6898 },
6899 },
6900 flags: []string{
6901 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6902 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6903 },
David Benjamin000800a2014-11-14 01:43:59 -05006904 })
David Benjamin72dc7832015-03-16 17:49:43 -04006905
David Benjamin51dd7d62016-07-08 16:07:01 -07006906 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006907 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006908 config: Config{
6909 MaxVersion: VersionTLS13,
6910 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006911 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006912 signatureRSAPKCS1WithSHA1,
6913 },
6914 Bugs: ProtocolBugs{
6915 NoSignatureAlgorithms: true,
6916 },
6917 },
6918 flags: []string{
6919 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6920 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6921 },
David Benjamin48901652016-08-01 12:12:47 -04006922 shouldFail: true,
6923 // An empty CertificateRequest signature algorithm list is a
6924 // syntax error in TLS 1.3.
6925 expectedError: ":DECODE_ERROR:",
6926 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006927 })
6928
6929 testCases = append(testCases, testCase{
6930 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006931 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006932 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006933 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006934 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006935 signatureRSAPKCS1WithSHA1,
6936 },
6937 Bugs: ProtocolBugs{
6938 NoSignatureAlgorithms: true,
6939 },
6940 },
6941 shouldFail: true,
6942 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6943 })
6944
David Benjaminb62d2872016-07-18 14:55:02 +02006945 // Test that hash preferences are enforced. BoringSSL does not implement
6946 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006947 testCases = append(testCases, testCase{
6948 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006949 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006951 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006952 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006953 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006954 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006955 },
6956 Bugs: ProtocolBugs{
6957 IgnorePeerSignatureAlgorithmPreferences: true,
6958 },
6959 },
6960 flags: []string{"-require-any-client-certificate"},
6961 shouldFail: true,
6962 expectedError: ":WRONG_SIGNATURE_TYPE:",
6963 })
6964
6965 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006966 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006967 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006968 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006969 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006970 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006971 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006972 },
6973 Bugs: ProtocolBugs{
6974 IgnorePeerSignatureAlgorithmPreferences: true,
6975 },
6976 },
6977 shouldFail: true,
6978 expectedError: ":WRONG_SIGNATURE_TYPE:",
6979 })
David Benjaminb62d2872016-07-18 14:55:02 +02006980 testCases = append(testCases, testCase{
6981 testType: serverTest,
6982 name: "ClientAuth-Enforced-TLS13",
6983 config: Config{
6984 MaxVersion: VersionTLS13,
6985 Certificates: []Certificate{rsaCertificate},
6986 SignSignatureAlgorithms: []signatureAlgorithm{
6987 signatureRSAPKCS1WithMD5,
6988 },
6989 Bugs: ProtocolBugs{
6990 IgnorePeerSignatureAlgorithmPreferences: true,
6991 IgnoreSignatureVersionChecks: true,
6992 },
6993 },
6994 flags: []string{"-require-any-client-certificate"},
6995 shouldFail: true,
6996 expectedError: ":WRONG_SIGNATURE_TYPE:",
6997 })
6998
6999 testCases = append(testCases, testCase{
7000 name: "ServerAuth-Enforced-TLS13",
7001 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007002 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007003 SignSignatureAlgorithms: []signatureAlgorithm{
7004 signatureRSAPKCS1WithMD5,
7005 },
7006 Bugs: ProtocolBugs{
7007 IgnorePeerSignatureAlgorithmPreferences: true,
7008 IgnoreSignatureVersionChecks: true,
7009 },
7010 },
7011 shouldFail: true,
7012 expectedError: ":WRONG_SIGNATURE_TYPE:",
7013 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007014
7015 // Test that the agreed upon digest respects the client preferences and
7016 // the server digests.
7017 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007018 name: "NoCommonAlgorithms-Digests",
7019 config: Config{
7020 MaxVersion: VersionTLS12,
7021 ClientAuth: RequireAnyClientCert,
7022 VerifySignatureAlgorithms: []signatureAlgorithm{
7023 signatureRSAPKCS1WithSHA512,
7024 signatureRSAPKCS1WithSHA1,
7025 },
7026 },
7027 flags: []string{
7028 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7029 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7030 "-digest-prefs", "SHA256",
7031 },
7032 shouldFail: true,
7033 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7034 })
7035 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007036 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007038 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007039 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007040 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007041 signatureRSAPKCS1WithSHA512,
7042 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007043 },
7044 },
7045 flags: []string{
7046 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7047 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007048 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007049 },
David Benjaminca3d5452016-07-14 12:51:01 -04007050 shouldFail: true,
7051 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7052 })
7053 testCases = append(testCases, testCase{
7054 name: "NoCommonAlgorithms-TLS13",
7055 config: Config{
7056 MaxVersion: VersionTLS13,
7057 ClientAuth: RequireAnyClientCert,
7058 VerifySignatureAlgorithms: []signatureAlgorithm{
7059 signatureRSAPSSWithSHA512,
7060 signatureRSAPSSWithSHA384,
7061 },
7062 },
7063 flags: []string{
7064 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7065 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7066 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7067 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007068 shouldFail: true,
7069 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007070 })
7071 testCases = append(testCases, testCase{
7072 name: "Agree-Digest-SHA256",
7073 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007074 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007075 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007076 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007077 signatureRSAPKCS1WithSHA1,
7078 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007079 },
7080 },
7081 flags: []string{
7082 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7083 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007084 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007085 },
Nick Harper60edffd2016-06-21 15:19:24 -07007086 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007087 })
7088 testCases = append(testCases, testCase{
7089 name: "Agree-Digest-SHA1",
7090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007091 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007092 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007093 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007094 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007095 },
7096 },
7097 flags: []string{
7098 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7099 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007100 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007101 },
Nick Harper60edffd2016-06-21 15:19:24 -07007102 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007103 })
7104 testCases = append(testCases, testCase{
7105 name: "Agree-Digest-Default",
7106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007107 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007108 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007109 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007110 signatureRSAPKCS1WithSHA256,
7111 signatureECDSAWithP256AndSHA256,
7112 signatureRSAPKCS1WithSHA1,
7113 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007114 },
7115 },
7116 flags: []string{
7117 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7118 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7119 },
Nick Harper60edffd2016-06-21 15:19:24 -07007120 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007121 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007122
David Benjaminca3d5452016-07-14 12:51:01 -04007123 // Test that the signing preference list may include extra algorithms
7124 // without negotiation problems.
7125 testCases = append(testCases, testCase{
7126 testType: serverTest,
7127 name: "FilterExtraAlgorithms",
7128 config: Config{
7129 MaxVersion: VersionTLS12,
7130 VerifySignatureAlgorithms: []signatureAlgorithm{
7131 signatureRSAPKCS1WithSHA256,
7132 },
7133 },
7134 flags: []string{
7135 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7136 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7137 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7138 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7139 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7140 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7141 },
7142 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7143 })
7144
David Benjamin4c3ddf72016-06-29 18:13:53 -04007145 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7146 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007147 testCases = append(testCases, testCase{
7148 name: "CheckLeafCurve",
7149 config: Config{
7150 MaxVersion: VersionTLS12,
7151 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007152 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007153 },
7154 flags: []string{"-p384-only"},
7155 shouldFail: true,
7156 expectedError: ":BAD_ECC_CERT:",
7157 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007158
7159 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7160 testCases = append(testCases, testCase{
7161 name: "CheckLeafCurve-TLS13",
7162 config: Config{
7163 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007164 Certificates: []Certificate{ecdsaP256Certificate},
7165 },
7166 flags: []string{"-p384-only"},
7167 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007168
7169 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7170 testCases = append(testCases, testCase{
7171 name: "ECDSACurveMismatch-Verify-TLS12",
7172 config: Config{
7173 MaxVersion: VersionTLS12,
7174 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7175 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007176 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007177 signatureECDSAWithP384AndSHA384,
7178 },
7179 },
7180 })
7181
7182 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7183 testCases = append(testCases, testCase{
7184 name: "ECDSACurveMismatch-Verify-TLS13",
7185 config: Config{
7186 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007187 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007188 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007189 signatureECDSAWithP384AndSHA384,
7190 },
7191 Bugs: ProtocolBugs{
7192 SkipECDSACurveCheck: true,
7193 },
7194 },
7195 shouldFail: true,
7196 expectedError: ":WRONG_SIGNATURE_TYPE:",
7197 })
7198
7199 // Signature algorithm selection in TLS 1.3 should take the curve into
7200 // account.
7201 testCases = append(testCases, testCase{
7202 testType: serverTest,
7203 name: "ECDSACurveMismatch-Sign-TLS13",
7204 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007205 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007206 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007207 signatureECDSAWithP384AndSHA384,
7208 signatureECDSAWithP256AndSHA256,
7209 },
7210 },
7211 flags: []string{
7212 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7213 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7214 },
7215 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7216 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007217
7218 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7219 // server does not attempt to sign in that case.
7220 testCases = append(testCases, testCase{
7221 testType: serverTest,
7222 name: "RSA-PSS-Large",
7223 config: Config{
7224 MaxVersion: VersionTLS13,
7225 VerifySignatureAlgorithms: []signatureAlgorithm{
7226 signatureRSAPSSWithSHA512,
7227 },
7228 },
7229 flags: []string{
7230 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7231 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7232 },
7233 shouldFail: true,
7234 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7235 })
David Benjamin57e929f2016-08-30 00:30:38 -04007236
7237 // Test that RSA-PSS is enabled by default for TLS 1.2.
7238 testCases = append(testCases, testCase{
7239 testType: clientTest,
7240 name: "RSA-PSS-Default-Verify",
7241 config: Config{
7242 MaxVersion: VersionTLS12,
7243 SignSignatureAlgorithms: []signatureAlgorithm{
7244 signatureRSAPSSWithSHA256,
7245 },
7246 },
7247 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7248 })
7249
7250 testCases = append(testCases, testCase{
7251 testType: serverTest,
7252 name: "RSA-PSS-Default-Sign",
7253 config: Config{
7254 MaxVersion: VersionTLS12,
7255 VerifySignatureAlgorithms: []signatureAlgorithm{
7256 signatureRSAPSSWithSHA256,
7257 },
7258 },
7259 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7260 })
David Benjamin000800a2014-11-14 01:43:59 -05007261}
7262
David Benjamin83f90402015-01-27 01:09:43 -05007263// timeouts is the retransmit schedule for BoringSSL. It doubles and
7264// caps at 60 seconds. On the 13th timeout, it gives up.
7265var timeouts = []time.Duration{
7266 1 * time.Second,
7267 2 * time.Second,
7268 4 * time.Second,
7269 8 * time.Second,
7270 16 * time.Second,
7271 32 * time.Second,
7272 60 * time.Second,
7273 60 * time.Second,
7274 60 * time.Second,
7275 60 * time.Second,
7276 60 * time.Second,
7277 60 * time.Second,
7278 60 * time.Second,
7279}
7280
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007281// shortTimeouts is an alternate set of timeouts which would occur if the
7282// initial timeout duration was set to 250ms.
7283var shortTimeouts = []time.Duration{
7284 250 * time.Millisecond,
7285 500 * time.Millisecond,
7286 1 * time.Second,
7287 2 * time.Second,
7288 4 * time.Second,
7289 8 * time.Second,
7290 16 * time.Second,
7291 32 * time.Second,
7292 60 * time.Second,
7293 60 * time.Second,
7294 60 * time.Second,
7295 60 * time.Second,
7296 60 * time.Second,
7297}
7298
David Benjamin83f90402015-01-27 01:09:43 -05007299func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007300 // These tests work by coordinating some behavior on both the shim and
7301 // the runner.
7302 //
7303 // TimeoutSchedule configures the runner to send a series of timeout
7304 // opcodes to the shim (see packetAdaptor) immediately before reading
7305 // each peer handshake flight N. The timeout opcode both simulates a
7306 // timeout in the shim and acts as a synchronization point to help the
7307 // runner bracket each handshake flight.
7308 //
7309 // We assume the shim does not read from the channel eagerly. It must
7310 // first wait until it has sent flight N and is ready to receive
7311 // handshake flight N+1. At this point, it will process the timeout
7312 // opcode. It must then immediately respond with a timeout ACK and act
7313 // as if the shim was idle for the specified amount of time.
7314 //
7315 // The runner then drops all packets received before the ACK and
7316 // continues waiting for flight N. This ordering results in one attempt
7317 // at sending flight N to be dropped. For the test to complete, the
7318 // shim must send flight N again, testing that the shim implements DTLS
7319 // retransmit on a timeout.
7320
Steven Valdez143e8b32016-07-11 13:19:03 -04007321 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007322 // likely be more epochs to cross and the final message's retransmit may
7323 // be more complex.
7324
David Benjamin585d7a42016-06-02 14:58:00 -04007325 for _, async := range []bool{true, false} {
7326 var tests []testCase
7327
7328 // Test that this is indeed the timeout schedule. Stress all
7329 // four patterns of handshake.
7330 for i := 1; i < len(timeouts); i++ {
7331 number := strconv.Itoa(i)
7332 tests = append(tests, testCase{
7333 protocol: dtls,
7334 name: "DTLS-Retransmit-Client-" + number,
7335 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007336 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007337 Bugs: ProtocolBugs{
7338 TimeoutSchedule: timeouts[:i],
7339 },
7340 },
7341 resumeSession: true,
7342 })
7343 tests = append(tests, testCase{
7344 protocol: dtls,
7345 testType: serverTest,
7346 name: "DTLS-Retransmit-Server-" + number,
7347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007349 Bugs: ProtocolBugs{
7350 TimeoutSchedule: timeouts[:i],
7351 },
7352 },
7353 resumeSession: true,
7354 })
7355 }
7356
7357 // Test that exceeding the timeout schedule hits a read
7358 // timeout.
7359 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007360 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007361 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007362 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007363 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007364 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007365 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007366 },
7367 },
7368 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007369 shouldFail: true,
7370 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007371 })
David Benjamin585d7a42016-06-02 14:58:00 -04007372
7373 if async {
7374 // Test that timeout handling has a fudge factor, due to API
7375 // problems.
7376 tests = append(tests, testCase{
7377 protocol: dtls,
7378 name: "DTLS-Retransmit-Fudge",
7379 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007380 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007381 Bugs: ProtocolBugs{
7382 TimeoutSchedule: []time.Duration{
7383 timeouts[0] - 10*time.Millisecond,
7384 },
7385 },
7386 },
7387 resumeSession: true,
7388 })
7389 }
7390
7391 // Test that the final Finished retransmitting isn't
7392 // duplicated if the peer badly fragments everything.
7393 tests = append(tests, testCase{
7394 testType: serverTest,
7395 protocol: dtls,
7396 name: "DTLS-Retransmit-Fragmented",
7397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007398 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007399 Bugs: ProtocolBugs{
7400 TimeoutSchedule: []time.Duration{timeouts[0]},
7401 MaxHandshakeRecordLength: 2,
7402 },
7403 },
7404 })
7405
7406 // Test the timeout schedule when a shorter initial timeout duration is set.
7407 tests = append(tests, testCase{
7408 protocol: dtls,
7409 name: "DTLS-Retransmit-Short-Client",
7410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007411 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007412 Bugs: ProtocolBugs{
7413 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7414 },
7415 },
7416 resumeSession: true,
7417 flags: []string{"-initial-timeout-duration-ms", "250"},
7418 })
7419 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007420 protocol: dtls,
7421 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007422 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007423 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007424 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007425 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007426 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007427 },
7428 },
7429 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007430 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007431 })
David Benjamin585d7a42016-06-02 14:58:00 -04007432
7433 for _, test := range tests {
7434 if async {
7435 test.name += "-Async"
7436 test.flags = append(test.flags, "-async")
7437 }
7438
7439 testCases = append(testCases, test)
7440 }
David Benjamin83f90402015-01-27 01:09:43 -05007441 }
David Benjamin83f90402015-01-27 01:09:43 -05007442}
7443
David Benjaminc565ebb2015-04-03 04:06:36 -04007444func addExportKeyingMaterialTests() {
7445 for _, vers := range tlsVersions {
7446 if vers.version == VersionSSL30 {
7447 continue
7448 }
7449 testCases = append(testCases, testCase{
7450 name: "ExportKeyingMaterial-" + vers.name,
7451 config: Config{
7452 MaxVersion: vers.version,
7453 },
7454 exportKeyingMaterial: 1024,
7455 exportLabel: "label",
7456 exportContext: "context",
7457 useExportContext: true,
7458 })
7459 testCases = append(testCases, testCase{
7460 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7461 config: Config{
7462 MaxVersion: vers.version,
7463 },
7464 exportKeyingMaterial: 1024,
7465 })
7466 testCases = append(testCases, testCase{
7467 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7468 config: Config{
7469 MaxVersion: vers.version,
7470 },
7471 exportKeyingMaterial: 1024,
7472 useExportContext: true,
7473 })
7474 testCases = append(testCases, testCase{
7475 name: "ExportKeyingMaterial-Small-" + vers.name,
7476 config: Config{
7477 MaxVersion: vers.version,
7478 },
7479 exportKeyingMaterial: 1,
7480 exportLabel: "label",
7481 exportContext: "context",
7482 useExportContext: true,
7483 })
7484 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007485
David Benjaminc565ebb2015-04-03 04:06:36 -04007486 testCases = append(testCases, testCase{
7487 name: "ExportKeyingMaterial-SSL3",
7488 config: Config{
7489 MaxVersion: VersionSSL30,
7490 },
7491 exportKeyingMaterial: 1024,
7492 exportLabel: "label",
7493 exportContext: "context",
7494 useExportContext: true,
7495 shouldFail: true,
7496 expectedError: "failed to export keying material",
7497 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007498
7499 // Exporters work during a False Start.
7500 testCases = append(testCases, testCase{
7501 name: "ExportKeyingMaterial-FalseStart",
7502 config: Config{
7503 MaxVersion: VersionTLS12,
7504 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7505 NextProtos: []string{"foo"},
7506 Bugs: ProtocolBugs{
7507 ExpectFalseStart: true,
7508 },
7509 },
7510 flags: []string{
7511 "-false-start",
7512 "-advertise-alpn", "\x03foo",
7513 },
7514 shimWritesFirst: true,
7515 exportKeyingMaterial: 1024,
7516 exportLabel: "label",
7517 exportContext: "context",
7518 useExportContext: true,
7519 })
7520
7521 // Exporters do not work in the middle of a renegotiation. Test this by
7522 // triggering the exporter after every SSL_read call and configuring the
7523 // shim to run asynchronously.
7524 testCases = append(testCases, testCase{
7525 name: "ExportKeyingMaterial-Renegotiate",
7526 config: Config{
7527 MaxVersion: VersionTLS12,
7528 },
7529 renegotiate: 1,
7530 flags: []string{
7531 "-async",
7532 "-use-exporter-between-reads",
7533 "-renegotiate-freely",
7534 "-expect-total-renegotiations", "1",
7535 },
7536 shouldFail: true,
7537 expectedError: "failed to export keying material",
7538 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007539}
7540
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007541func addTLSUniqueTests() {
7542 for _, isClient := range []bool{false, true} {
7543 for _, isResumption := range []bool{false, true} {
7544 for _, hasEMS := range []bool{false, true} {
7545 var suffix string
7546 if isResumption {
7547 suffix = "Resume-"
7548 } else {
7549 suffix = "Full-"
7550 }
7551
7552 if hasEMS {
7553 suffix += "EMS-"
7554 } else {
7555 suffix += "NoEMS-"
7556 }
7557
7558 if isClient {
7559 suffix += "Client"
7560 } else {
7561 suffix += "Server"
7562 }
7563
7564 test := testCase{
7565 name: "TLSUnique-" + suffix,
7566 testTLSUnique: true,
7567 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007568 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007569 Bugs: ProtocolBugs{
7570 NoExtendedMasterSecret: !hasEMS,
7571 },
7572 },
7573 }
7574
7575 if isResumption {
7576 test.resumeSession = true
7577 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007578 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007579 Bugs: ProtocolBugs{
7580 NoExtendedMasterSecret: !hasEMS,
7581 },
7582 }
7583 }
7584
7585 if isResumption && !hasEMS {
7586 test.shouldFail = true
7587 test.expectedError = "failed to get tls-unique"
7588 }
7589
7590 testCases = append(testCases, test)
7591 }
7592 }
7593 }
7594}
7595
Adam Langley09505632015-07-30 18:10:13 -07007596func addCustomExtensionTests() {
7597 expectedContents := "custom extension"
7598 emptyString := ""
7599
7600 for _, isClient := range []bool{false, true} {
7601 suffix := "Server"
7602 flag := "-enable-server-custom-extension"
7603 testType := serverTest
7604 if isClient {
7605 suffix = "Client"
7606 flag = "-enable-client-custom-extension"
7607 testType = clientTest
7608 }
7609
7610 testCases = append(testCases, testCase{
7611 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007612 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007613 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007614 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007615 Bugs: ProtocolBugs{
7616 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007617 ExpectedCustomExtension: &expectedContents,
7618 },
7619 },
7620 flags: []string{flag},
7621 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007622 testCases = append(testCases, testCase{
7623 testType: testType,
7624 name: "CustomExtensions-" + suffix + "-TLS13",
7625 config: Config{
7626 MaxVersion: VersionTLS13,
7627 Bugs: ProtocolBugs{
7628 CustomExtension: expectedContents,
7629 ExpectedCustomExtension: &expectedContents,
7630 },
7631 },
7632 flags: []string{flag},
7633 })
Adam Langley09505632015-07-30 18:10:13 -07007634
7635 // If the parse callback fails, the handshake should also fail.
7636 testCases = append(testCases, testCase{
7637 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007638 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007639 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007640 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007641 Bugs: ProtocolBugs{
7642 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007643 ExpectedCustomExtension: &expectedContents,
7644 },
7645 },
David Benjamin399e7c92015-07-30 23:01:27 -04007646 flags: []string{flag},
7647 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007648 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7649 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007650 testCases = append(testCases, testCase{
7651 testType: testType,
7652 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7653 config: Config{
7654 MaxVersion: VersionTLS13,
7655 Bugs: ProtocolBugs{
7656 CustomExtension: expectedContents + "foo",
7657 ExpectedCustomExtension: &expectedContents,
7658 },
7659 },
7660 flags: []string{flag},
7661 shouldFail: true,
7662 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7663 })
Adam Langley09505632015-07-30 18:10:13 -07007664
7665 // If the add callback fails, the handshake should also fail.
7666 testCases = append(testCases, testCase{
7667 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007668 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007670 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007671 Bugs: ProtocolBugs{
7672 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007673 ExpectedCustomExtension: &expectedContents,
7674 },
7675 },
David Benjamin399e7c92015-07-30 23:01:27 -04007676 flags: []string{flag, "-custom-extension-fail-add"},
7677 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007678 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7679 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007680 testCases = append(testCases, testCase{
7681 testType: testType,
7682 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7683 config: Config{
7684 MaxVersion: VersionTLS13,
7685 Bugs: ProtocolBugs{
7686 CustomExtension: expectedContents,
7687 ExpectedCustomExtension: &expectedContents,
7688 },
7689 },
7690 flags: []string{flag, "-custom-extension-fail-add"},
7691 shouldFail: true,
7692 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7693 })
Adam Langley09505632015-07-30 18:10:13 -07007694
7695 // If the add callback returns zero, no extension should be
7696 // added.
7697 skipCustomExtension := expectedContents
7698 if isClient {
7699 // For the case where the client skips sending the
7700 // custom extension, the server must not “echo” it.
7701 skipCustomExtension = ""
7702 }
7703 testCases = append(testCases, testCase{
7704 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007705 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007706 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007707 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007708 Bugs: ProtocolBugs{
7709 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007710 ExpectedCustomExtension: &emptyString,
7711 },
7712 },
7713 flags: []string{flag, "-custom-extension-skip"},
7714 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007715 testCases = append(testCases, testCase{
7716 testType: testType,
7717 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7718 config: Config{
7719 MaxVersion: VersionTLS13,
7720 Bugs: ProtocolBugs{
7721 CustomExtension: skipCustomExtension,
7722 ExpectedCustomExtension: &emptyString,
7723 },
7724 },
7725 flags: []string{flag, "-custom-extension-skip"},
7726 })
Adam Langley09505632015-07-30 18:10:13 -07007727 }
7728
7729 // The custom extension add callback should not be called if the client
7730 // doesn't send the extension.
7731 testCases = append(testCases, testCase{
7732 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007733 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007734 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007735 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007736 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007737 ExpectedCustomExtension: &emptyString,
7738 },
7739 },
7740 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7741 })
Adam Langley2deb9842015-08-07 11:15:37 -07007742
Steven Valdez143e8b32016-07-11 13:19:03 -04007743 testCases = append(testCases, testCase{
7744 testType: serverTest,
7745 name: "CustomExtensions-NotCalled-Server-TLS13",
7746 config: Config{
7747 MaxVersion: VersionTLS13,
7748 Bugs: ProtocolBugs{
7749 ExpectedCustomExtension: &emptyString,
7750 },
7751 },
7752 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7753 })
7754
Adam Langley2deb9842015-08-07 11:15:37 -07007755 // Test an unknown extension from the server.
7756 testCases = append(testCases, testCase{
7757 testType: clientTest,
7758 name: "UnknownExtension-Client",
7759 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007760 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007761 Bugs: ProtocolBugs{
7762 CustomExtension: expectedContents,
7763 },
7764 },
David Benjamin0c40a962016-08-01 12:05:50 -04007765 shouldFail: true,
7766 expectedError: ":UNEXPECTED_EXTENSION:",
7767 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007768 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007769 testCases = append(testCases, testCase{
7770 testType: clientTest,
7771 name: "UnknownExtension-Client-TLS13",
7772 config: Config{
7773 MaxVersion: VersionTLS13,
7774 Bugs: ProtocolBugs{
7775 CustomExtension: expectedContents,
7776 },
7777 },
David Benjamin0c40a962016-08-01 12:05:50 -04007778 shouldFail: true,
7779 expectedError: ":UNEXPECTED_EXTENSION:",
7780 expectedLocalError: "remote error: unsupported extension",
7781 })
David Benjamin490469f2016-10-05 22:44:38 -04007782 testCases = append(testCases, testCase{
7783 testType: clientTest,
7784 name: "UnknownUnencryptedExtension-Client-TLS13",
7785 config: Config{
7786 MaxVersion: VersionTLS13,
7787 Bugs: ProtocolBugs{
7788 CustomUnencryptedExtension: expectedContents,
7789 },
7790 },
7791 shouldFail: true,
7792 expectedError: ":UNEXPECTED_EXTENSION:",
7793 // The shim must send an alert, but alerts at this point do not
7794 // get successfully decrypted by the runner.
7795 expectedLocalError: "local error: bad record MAC",
7796 })
7797 testCases = append(testCases, testCase{
7798 testType: clientTest,
7799 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7800 config: Config{
7801 MaxVersion: VersionTLS13,
7802 Bugs: ProtocolBugs{
7803 SendUnencryptedALPN: "foo",
7804 },
7805 },
7806 flags: []string{
7807 "-advertise-alpn", "\x03foo\x03bar",
7808 },
7809 shouldFail: true,
7810 expectedError: ":UNEXPECTED_EXTENSION:",
7811 // The shim must send an alert, but alerts at this point do not
7812 // get successfully decrypted by the runner.
7813 expectedLocalError: "local error: bad record MAC",
7814 })
David Benjamin0c40a962016-08-01 12:05:50 -04007815
7816 // Test a known but unoffered extension from the server.
7817 testCases = append(testCases, testCase{
7818 testType: clientTest,
7819 name: "UnofferedExtension-Client",
7820 config: Config{
7821 MaxVersion: VersionTLS12,
7822 Bugs: ProtocolBugs{
7823 SendALPN: "alpn",
7824 },
7825 },
7826 shouldFail: true,
7827 expectedError: ":UNEXPECTED_EXTENSION:",
7828 expectedLocalError: "remote error: unsupported extension",
7829 })
7830 testCases = append(testCases, testCase{
7831 testType: clientTest,
7832 name: "UnofferedExtension-Client-TLS13",
7833 config: Config{
7834 MaxVersion: VersionTLS13,
7835 Bugs: ProtocolBugs{
7836 SendALPN: "alpn",
7837 },
7838 },
7839 shouldFail: true,
7840 expectedError: ":UNEXPECTED_EXTENSION:",
7841 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007842 })
Adam Langley09505632015-07-30 18:10:13 -07007843}
7844
David Benjaminb36a3952015-12-01 18:53:13 -05007845func addRSAClientKeyExchangeTests() {
7846 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7847 testCases = append(testCases, testCase{
7848 testType: serverTest,
7849 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7850 config: Config{
7851 // Ensure the ClientHello version and final
7852 // version are different, to detect if the
7853 // server uses the wrong one.
7854 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007855 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007856 Bugs: ProtocolBugs{
7857 BadRSAClientKeyExchange: bad,
7858 },
7859 },
7860 shouldFail: true,
7861 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7862 })
7863 }
David Benjamine63d9d72016-09-19 18:27:34 -04007864
7865 // The server must compare whatever was in ClientHello.version for the
7866 // RSA premaster.
7867 testCases = append(testCases, testCase{
7868 testType: serverTest,
7869 name: "SendClientVersion-RSA",
7870 config: Config{
7871 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7872 Bugs: ProtocolBugs{
7873 SendClientVersion: 0x1234,
7874 },
7875 },
7876 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7877 })
David Benjaminb36a3952015-12-01 18:53:13 -05007878}
7879
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007880var testCurves = []struct {
7881 name string
7882 id CurveID
7883}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007884 {"P-256", CurveP256},
7885 {"P-384", CurveP384},
7886 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007887 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007888}
7889
Steven Valdez5440fe02016-07-18 12:40:30 -04007890const bogusCurve = 0x1234
7891
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007892func addCurveTests() {
7893 for _, curve := range testCurves {
7894 testCases = append(testCases, testCase{
7895 name: "CurveTest-Client-" + curve.name,
7896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007897 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007898 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7899 CurvePreferences: []CurveID{curve.id},
7900 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007901 flags: []string{
7902 "-enable-all-curves",
7903 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7904 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007905 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007906 })
7907 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007908 name: "CurveTest-Client-" + curve.name + "-TLS13",
7909 config: Config{
7910 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007911 CurvePreferences: []CurveID{curve.id},
7912 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007913 flags: []string{
7914 "-enable-all-curves",
7915 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7916 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007917 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007918 })
7919 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007920 testType: serverTest,
7921 name: "CurveTest-Server-" + curve.name,
7922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007923 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007924 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7925 CurvePreferences: []CurveID{curve.id},
7926 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007927 flags: []string{
7928 "-enable-all-curves",
7929 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7930 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007931 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007932 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007933 testCases = append(testCases, testCase{
7934 testType: serverTest,
7935 name: "CurveTest-Server-" + curve.name + "-TLS13",
7936 config: Config{
7937 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007938 CurvePreferences: []CurveID{curve.id},
7939 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007940 flags: []string{
7941 "-enable-all-curves",
7942 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7943 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007944 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007945 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007946 }
David Benjamin241ae832016-01-15 03:04:54 -05007947
7948 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007949 testCases = append(testCases, testCase{
7950 testType: serverTest,
7951 name: "UnknownCurve",
7952 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007953 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7955 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7956 },
7957 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007958
Steven Valdez803c77a2016-09-06 14:13:43 -04007959 // The server must be tolerant to bogus curves.
7960 testCases = append(testCases, testCase{
7961 testType: serverTest,
7962 name: "UnknownCurve-TLS13",
7963 config: Config{
7964 MaxVersion: VersionTLS13,
7965 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7966 },
7967 })
7968
David Benjamin4c3ddf72016-06-29 18:13:53 -04007969 // The server must not consider ECDHE ciphers when there are no
7970 // supported curves.
7971 testCases = append(testCases, testCase{
7972 testType: serverTest,
7973 name: "NoSupportedCurves",
7974 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007975 MaxVersion: VersionTLS12,
7976 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7977 Bugs: ProtocolBugs{
7978 NoSupportedCurves: true,
7979 },
7980 },
7981 shouldFail: true,
7982 expectedError: ":NO_SHARED_CIPHER:",
7983 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007984 testCases = append(testCases, testCase{
7985 testType: serverTest,
7986 name: "NoSupportedCurves-TLS13",
7987 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007988 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007989 Bugs: ProtocolBugs{
7990 NoSupportedCurves: true,
7991 },
7992 },
7993 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007994 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007995 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007996
7997 // The server must fall back to another cipher when there are no
7998 // supported curves.
7999 testCases = append(testCases, testCase{
8000 testType: serverTest,
8001 name: "NoCommonCurves",
8002 config: Config{
8003 MaxVersion: VersionTLS12,
8004 CipherSuites: []uint16{
8005 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8006 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8007 },
8008 CurvePreferences: []CurveID{CurveP224},
8009 },
8010 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8011 })
8012
8013 // The client must reject bogus curves and disabled curves.
8014 testCases = append(testCases, testCase{
8015 name: "BadECDHECurve",
8016 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008017 MaxVersion: VersionTLS12,
8018 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8019 Bugs: ProtocolBugs{
8020 SendCurve: bogusCurve,
8021 },
8022 },
8023 shouldFail: true,
8024 expectedError: ":WRONG_CURVE:",
8025 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008026 testCases = append(testCases, testCase{
8027 name: "BadECDHECurve-TLS13",
8028 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008029 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008030 Bugs: ProtocolBugs{
8031 SendCurve: bogusCurve,
8032 },
8033 },
8034 shouldFail: true,
8035 expectedError: ":WRONG_CURVE:",
8036 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008037
8038 testCases = append(testCases, testCase{
8039 name: "UnsupportedCurve",
8040 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008041 MaxVersion: VersionTLS12,
8042 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8043 CurvePreferences: []CurveID{CurveP256},
8044 Bugs: ProtocolBugs{
8045 IgnorePeerCurvePreferences: true,
8046 },
8047 },
8048 flags: []string{"-p384-only"},
8049 shouldFail: true,
8050 expectedError: ":WRONG_CURVE:",
8051 })
8052
David Benjamin4f921572016-07-17 14:20:10 +02008053 testCases = append(testCases, testCase{
8054 // TODO(davidben): Add a TLS 1.3 version where
8055 // HelloRetryRequest requests an unsupported curve.
8056 name: "UnsupportedCurve-ServerHello-TLS13",
8057 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008058 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008059 CurvePreferences: []CurveID{CurveP384},
8060 Bugs: ProtocolBugs{
8061 SendCurve: CurveP256,
8062 },
8063 },
8064 flags: []string{"-p384-only"},
8065 shouldFail: true,
8066 expectedError: ":WRONG_CURVE:",
8067 })
8068
David Benjamin4c3ddf72016-06-29 18:13:53 -04008069 // Test invalid curve points.
8070 testCases = append(testCases, testCase{
8071 name: "InvalidECDHPoint-Client",
8072 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008073 MaxVersion: VersionTLS12,
8074 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8075 CurvePreferences: []CurveID{CurveP256},
8076 Bugs: ProtocolBugs{
8077 InvalidECDHPoint: true,
8078 },
8079 },
8080 shouldFail: true,
8081 expectedError: ":INVALID_ENCODING:",
8082 })
8083 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008084 name: "InvalidECDHPoint-Client-TLS13",
8085 config: Config{
8086 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008087 CurvePreferences: []CurveID{CurveP256},
8088 Bugs: ProtocolBugs{
8089 InvalidECDHPoint: true,
8090 },
8091 },
8092 shouldFail: true,
8093 expectedError: ":INVALID_ENCODING:",
8094 })
8095 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008096 testType: serverTest,
8097 name: "InvalidECDHPoint-Server",
8098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008099 MaxVersion: VersionTLS12,
8100 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8101 CurvePreferences: []CurveID{CurveP256},
8102 Bugs: ProtocolBugs{
8103 InvalidECDHPoint: true,
8104 },
8105 },
8106 shouldFail: true,
8107 expectedError: ":INVALID_ENCODING:",
8108 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008109 testCases = append(testCases, testCase{
8110 testType: serverTest,
8111 name: "InvalidECDHPoint-Server-TLS13",
8112 config: Config{
8113 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008114 CurvePreferences: []CurveID{CurveP256},
8115 Bugs: ProtocolBugs{
8116 InvalidECDHPoint: true,
8117 },
8118 },
8119 shouldFail: true,
8120 expectedError: ":INVALID_ENCODING:",
8121 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008122
8123 // The previous curve ID should be reported on TLS 1.2 resumption.
8124 testCases = append(testCases, testCase{
8125 name: "CurveID-Resume-Client",
8126 config: Config{
8127 MaxVersion: VersionTLS12,
8128 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8129 CurvePreferences: []CurveID{CurveX25519},
8130 },
8131 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8132 resumeSession: true,
8133 })
8134 testCases = append(testCases, testCase{
8135 testType: serverTest,
8136 name: "CurveID-Resume-Server",
8137 config: Config{
8138 MaxVersion: VersionTLS12,
8139 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8140 CurvePreferences: []CurveID{CurveX25519},
8141 },
8142 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8143 resumeSession: true,
8144 })
8145
8146 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8147 // one should be reported.
8148 testCases = append(testCases, testCase{
8149 name: "CurveID-Resume-Client-TLS13",
8150 config: Config{
8151 MaxVersion: VersionTLS13,
8152 CurvePreferences: []CurveID{CurveX25519},
8153 },
8154 resumeConfig: &Config{
8155 MaxVersion: VersionTLS13,
8156 CurvePreferences: []CurveID{CurveP256},
8157 },
8158 flags: []string{
8159 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8160 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8161 },
8162 resumeSession: true,
8163 })
8164 testCases = append(testCases, testCase{
8165 testType: serverTest,
8166 name: "CurveID-Resume-Server-TLS13",
8167 config: Config{
8168 MaxVersion: VersionTLS13,
8169 CurvePreferences: []CurveID{CurveX25519},
8170 },
8171 resumeConfig: &Config{
8172 MaxVersion: VersionTLS13,
8173 CurvePreferences: []CurveID{CurveP256},
8174 },
8175 flags: []string{
8176 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8177 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8178 },
8179 resumeSession: true,
8180 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008181}
8182
David Benjaminc9ae27c2016-06-24 22:56:37 -04008183func addTLS13RecordTests() {
8184 testCases = append(testCases, testCase{
8185 name: "TLS13-RecordPadding",
8186 config: Config{
8187 MaxVersion: VersionTLS13,
8188 MinVersion: VersionTLS13,
8189 Bugs: ProtocolBugs{
8190 RecordPadding: 10,
8191 },
8192 },
8193 })
8194
8195 testCases = append(testCases, testCase{
8196 name: "TLS13-EmptyRecords",
8197 config: Config{
8198 MaxVersion: VersionTLS13,
8199 MinVersion: VersionTLS13,
8200 Bugs: ProtocolBugs{
8201 OmitRecordContents: true,
8202 },
8203 },
8204 shouldFail: true,
8205 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8206 })
8207
8208 testCases = append(testCases, testCase{
8209 name: "TLS13-OnlyPadding",
8210 config: Config{
8211 MaxVersion: VersionTLS13,
8212 MinVersion: VersionTLS13,
8213 Bugs: ProtocolBugs{
8214 OmitRecordContents: true,
8215 RecordPadding: 10,
8216 },
8217 },
8218 shouldFail: true,
8219 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8220 })
8221
8222 testCases = append(testCases, testCase{
8223 name: "TLS13-WrongOuterRecord",
8224 config: Config{
8225 MaxVersion: VersionTLS13,
8226 MinVersion: VersionTLS13,
8227 Bugs: ProtocolBugs{
8228 OuterRecordType: recordTypeHandshake,
8229 },
8230 },
8231 shouldFail: true,
8232 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8233 })
8234}
8235
Steven Valdez5b986082016-09-01 12:29:49 -04008236func addSessionTicketTests() {
8237 testCases = append(testCases, testCase{
8238 // In TLS 1.2 and below, empty NewSessionTicket messages
8239 // mean the server changed its mind on sending a ticket.
8240 name: "SendEmptySessionTicket",
8241 config: Config{
8242 MaxVersion: VersionTLS12,
8243 Bugs: ProtocolBugs{
8244 SendEmptySessionTicket: true,
8245 },
8246 },
8247 flags: []string{"-expect-no-session"},
8248 })
8249
8250 // Test that the server ignores unknown PSK modes.
8251 testCases = append(testCases, testCase{
8252 testType: serverTest,
8253 name: "TLS13-SendUnknownModeSessionTicket-Server",
8254 config: Config{
8255 MaxVersion: VersionTLS13,
8256 Bugs: ProtocolBugs{
8257 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008258 },
8259 },
8260 resumeSession: true,
8261 expectedResumeVersion: VersionTLS13,
8262 })
8263
Steven Valdeza833c352016-11-01 13:39:36 -04008264 // Test that the server does not send session tickets with no matching key exchange mode.
8265 testCases = append(testCases, testCase{
8266 testType: serverTest,
8267 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8268 config: Config{
8269 MaxVersion: VersionTLS13,
8270 Bugs: ProtocolBugs{
8271 SendPSKKeyExchangeModes: []byte{0x1a},
8272 ExpectNoNewSessionTicket: true,
8273 },
8274 },
8275 })
8276
8277 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008278 testCases = append(testCases, testCase{
8279 testType: serverTest,
8280 name: "TLS13-SendBadKEModeSessionTicket-Server",
8281 config: Config{
8282 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008283 },
8284 resumeConfig: &Config{
8285 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008286 Bugs: ProtocolBugs{
8287 SendPSKKeyExchangeModes: []byte{0x1a},
8288 },
8289 },
8290 resumeSession: true,
8291 expectResumeRejected: true,
8292 })
8293
Steven Valdeza833c352016-11-01 13:39:36 -04008294 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008295 testCases = append(testCases, testCase{
8296 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008297 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008298 config: Config{
8299 MaxVersion: VersionTLS13,
8300 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008301 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008302 },
8303 },
Steven Valdeza833c352016-11-01 13:39:36 -04008304 resumeSession: true,
8305 flags: []string{
8306 "-resumption-delay", "10",
8307 },
Steven Valdez5b986082016-09-01 12:29:49 -04008308 })
8309
Steven Valdeza833c352016-11-01 13:39:36 -04008310 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008311 testCases = append(testCases, testCase{
8312 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008313 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008314 config: Config{
8315 MaxVersion: VersionTLS13,
8316 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008317 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008318 },
8319 },
Steven Valdeza833c352016-11-01 13:39:36 -04008320 resumeSession: true,
8321 shouldFail: true,
8322 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008323 })
8324
Steven Valdez5b986082016-09-01 12:29:49 -04008325}
8326
David Benjamin82261be2016-07-07 14:32:50 -07008327func addChangeCipherSpecTests() {
8328 // Test missing ChangeCipherSpecs.
8329 testCases = append(testCases, testCase{
8330 name: "SkipChangeCipherSpec-Client",
8331 config: Config{
8332 MaxVersion: VersionTLS12,
8333 Bugs: ProtocolBugs{
8334 SkipChangeCipherSpec: true,
8335 },
8336 },
8337 shouldFail: true,
8338 expectedError: ":UNEXPECTED_RECORD:",
8339 })
8340 testCases = append(testCases, testCase{
8341 testType: serverTest,
8342 name: "SkipChangeCipherSpec-Server",
8343 config: Config{
8344 MaxVersion: VersionTLS12,
8345 Bugs: ProtocolBugs{
8346 SkipChangeCipherSpec: true,
8347 },
8348 },
8349 shouldFail: true,
8350 expectedError: ":UNEXPECTED_RECORD:",
8351 })
8352 testCases = append(testCases, testCase{
8353 testType: serverTest,
8354 name: "SkipChangeCipherSpec-Server-NPN",
8355 config: Config{
8356 MaxVersion: VersionTLS12,
8357 NextProtos: []string{"bar"},
8358 Bugs: ProtocolBugs{
8359 SkipChangeCipherSpec: true,
8360 },
8361 },
8362 flags: []string{
8363 "-advertise-npn", "\x03foo\x03bar\x03baz",
8364 },
8365 shouldFail: true,
8366 expectedError: ":UNEXPECTED_RECORD:",
8367 })
8368
8369 // Test synchronization between the handshake and ChangeCipherSpec.
8370 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8371 // rejected. Test both with and without handshake packing to handle both
8372 // when the partial post-CCS message is in its own record and when it is
8373 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008374 for _, packed := range []bool{false, true} {
8375 var suffix string
8376 if packed {
8377 suffix = "-Packed"
8378 }
8379
8380 testCases = append(testCases, testCase{
8381 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8382 config: Config{
8383 MaxVersion: VersionTLS12,
8384 Bugs: ProtocolBugs{
8385 FragmentAcrossChangeCipherSpec: true,
8386 PackHandshakeFlight: packed,
8387 },
8388 },
8389 shouldFail: true,
8390 expectedError: ":UNEXPECTED_RECORD:",
8391 })
8392 testCases = append(testCases, testCase{
8393 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8394 config: Config{
8395 MaxVersion: VersionTLS12,
8396 },
8397 resumeSession: true,
8398 resumeConfig: &Config{
8399 MaxVersion: VersionTLS12,
8400 Bugs: ProtocolBugs{
8401 FragmentAcrossChangeCipherSpec: true,
8402 PackHandshakeFlight: packed,
8403 },
8404 },
8405 shouldFail: true,
8406 expectedError: ":UNEXPECTED_RECORD:",
8407 })
8408 testCases = append(testCases, testCase{
8409 testType: serverTest,
8410 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8411 config: Config{
8412 MaxVersion: VersionTLS12,
8413 Bugs: ProtocolBugs{
8414 FragmentAcrossChangeCipherSpec: true,
8415 PackHandshakeFlight: packed,
8416 },
8417 },
8418 shouldFail: true,
8419 expectedError: ":UNEXPECTED_RECORD:",
8420 })
8421 testCases = append(testCases, testCase{
8422 testType: serverTest,
8423 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8424 config: Config{
8425 MaxVersion: VersionTLS12,
8426 },
8427 resumeSession: true,
8428 resumeConfig: &Config{
8429 MaxVersion: VersionTLS12,
8430 Bugs: ProtocolBugs{
8431 FragmentAcrossChangeCipherSpec: true,
8432 PackHandshakeFlight: packed,
8433 },
8434 },
8435 shouldFail: true,
8436 expectedError: ":UNEXPECTED_RECORD:",
8437 })
8438 testCases = append(testCases, testCase{
8439 testType: serverTest,
8440 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8441 config: Config{
8442 MaxVersion: VersionTLS12,
8443 NextProtos: []string{"bar"},
8444 Bugs: ProtocolBugs{
8445 FragmentAcrossChangeCipherSpec: true,
8446 PackHandshakeFlight: packed,
8447 },
8448 },
8449 flags: []string{
8450 "-advertise-npn", "\x03foo\x03bar\x03baz",
8451 },
8452 shouldFail: true,
8453 expectedError: ":UNEXPECTED_RECORD:",
8454 })
8455 }
8456
David Benjamin61672812016-07-14 23:10:43 -04008457 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8458 // messages in the handshake queue. Do this by testing the server
8459 // reading the client Finished, reversing the flight so Finished comes
8460 // first.
8461 testCases = append(testCases, testCase{
8462 protocol: dtls,
8463 testType: serverTest,
8464 name: "SendUnencryptedFinished-DTLS",
8465 config: Config{
8466 MaxVersion: VersionTLS12,
8467 Bugs: ProtocolBugs{
8468 SendUnencryptedFinished: true,
8469 ReverseHandshakeFragments: true,
8470 },
8471 },
8472 shouldFail: true,
8473 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8474 })
8475
Steven Valdez143e8b32016-07-11 13:19:03 -04008476 // Test synchronization between encryption changes and the handshake in
8477 // TLS 1.3, where ChangeCipherSpec is implicit.
8478 testCases = append(testCases, testCase{
8479 name: "PartialEncryptedExtensionsWithServerHello",
8480 config: Config{
8481 MaxVersion: VersionTLS13,
8482 Bugs: ProtocolBugs{
8483 PartialEncryptedExtensionsWithServerHello: true,
8484 },
8485 },
8486 shouldFail: true,
8487 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8488 })
8489 testCases = append(testCases, testCase{
8490 testType: serverTest,
8491 name: "PartialClientFinishedWithClientHello",
8492 config: Config{
8493 MaxVersion: VersionTLS13,
8494 Bugs: ProtocolBugs{
8495 PartialClientFinishedWithClientHello: true,
8496 },
8497 },
8498 shouldFail: true,
8499 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8500 })
8501
David Benjamin82261be2016-07-07 14:32:50 -07008502 // Test that early ChangeCipherSpecs are handled correctly.
8503 testCases = append(testCases, testCase{
8504 testType: serverTest,
8505 name: "EarlyChangeCipherSpec-server-1",
8506 config: Config{
8507 MaxVersion: VersionTLS12,
8508 Bugs: ProtocolBugs{
8509 EarlyChangeCipherSpec: 1,
8510 },
8511 },
8512 shouldFail: true,
8513 expectedError: ":UNEXPECTED_RECORD:",
8514 })
8515 testCases = append(testCases, testCase{
8516 testType: serverTest,
8517 name: "EarlyChangeCipherSpec-server-2",
8518 config: Config{
8519 MaxVersion: VersionTLS12,
8520 Bugs: ProtocolBugs{
8521 EarlyChangeCipherSpec: 2,
8522 },
8523 },
8524 shouldFail: true,
8525 expectedError: ":UNEXPECTED_RECORD:",
8526 })
8527 testCases = append(testCases, testCase{
8528 protocol: dtls,
8529 name: "StrayChangeCipherSpec",
8530 config: Config{
8531 // TODO(davidben): Once DTLS 1.3 exists, test
8532 // that stray ChangeCipherSpec messages are
8533 // rejected.
8534 MaxVersion: VersionTLS12,
8535 Bugs: ProtocolBugs{
8536 StrayChangeCipherSpec: true,
8537 },
8538 },
8539 })
8540
8541 // Test that the contents of ChangeCipherSpec are checked.
8542 testCases = append(testCases, testCase{
8543 name: "BadChangeCipherSpec-1",
8544 config: Config{
8545 MaxVersion: VersionTLS12,
8546 Bugs: ProtocolBugs{
8547 BadChangeCipherSpec: []byte{2},
8548 },
8549 },
8550 shouldFail: true,
8551 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8552 })
8553 testCases = append(testCases, testCase{
8554 name: "BadChangeCipherSpec-2",
8555 config: Config{
8556 MaxVersion: VersionTLS12,
8557 Bugs: ProtocolBugs{
8558 BadChangeCipherSpec: []byte{1, 1},
8559 },
8560 },
8561 shouldFail: true,
8562 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8563 })
8564 testCases = append(testCases, testCase{
8565 protocol: dtls,
8566 name: "BadChangeCipherSpec-DTLS-1",
8567 config: Config{
8568 MaxVersion: VersionTLS12,
8569 Bugs: ProtocolBugs{
8570 BadChangeCipherSpec: []byte{2},
8571 },
8572 },
8573 shouldFail: true,
8574 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8575 })
8576 testCases = append(testCases, testCase{
8577 protocol: dtls,
8578 name: "BadChangeCipherSpec-DTLS-2",
8579 config: Config{
8580 MaxVersion: VersionTLS12,
8581 Bugs: ProtocolBugs{
8582 BadChangeCipherSpec: []byte{1, 1},
8583 },
8584 },
8585 shouldFail: true,
8586 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8587 })
8588}
8589
David Benjamincd2c8062016-09-09 11:28:16 -04008590type perMessageTest struct {
8591 messageType uint8
8592 test testCase
8593}
8594
8595// makePerMessageTests returns a series of test templates which cover each
8596// message in the TLS handshake. These may be used with bugs like
8597// WrongMessageType to fully test a per-message bug.
8598func makePerMessageTests() []perMessageTest {
8599 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008600 for _, protocol := range []protocol{tls, dtls} {
8601 var suffix string
8602 if protocol == dtls {
8603 suffix = "-DTLS"
8604 }
8605
David Benjamincd2c8062016-09-09 11:28:16 -04008606 ret = append(ret, perMessageTest{
8607 messageType: typeClientHello,
8608 test: testCase{
8609 protocol: protocol,
8610 testType: serverTest,
8611 name: "ClientHello" + suffix,
8612 config: Config{
8613 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008614 },
8615 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008616 })
8617
8618 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008619 ret = append(ret, perMessageTest{
8620 messageType: typeHelloVerifyRequest,
8621 test: testCase{
8622 protocol: protocol,
8623 name: "HelloVerifyRequest" + suffix,
8624 config: Config{
8625 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008626 },
8627 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008628 })
8629 }
8630
David Benjamincd2c8062016-09-09 11:28:16 -04008631 ret = append(ret, perMessageTest{
8632 messageType: typeServerHello,
8633 test: testCase{
8634 protocol: protocol,
8635 name: "ServerHello" + suffix,
8636 config: Config{
8637 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008638 },
8639 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008640 })
8641
David Benjamincd2c8062016-09-09 11:28:16 -04008642 ret = append(ret, perMessageTest{
8643 messageType: typeCertificate,
8644 test: testCase{
8645 protocol: protocol,
8646 name: "ServerCertificate" + suffix,
8647 config: Config{
8648 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008649 },
8650 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008651 })
8652
David Benjamincd2c8062016-09-09 11:28:16 -04008653 ret = append(ret, perMessageTest{
8654 messageType: typeCertificateStatus,
8655 test: testCase{
8656 protocol: protocol,
8657 name: "CertificateStatus" + suffix,
8658 config: Config{
8659 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008660 },
David Benjamincd2c8062016-09-09 11:28:16 -04008661 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008662 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008663 })
8664
David Benjamincd2c8062016-09-09 11:28:16 -04008665 ret = append(ret, perMessageTest{
8666 messageType: typeServerKeyExchange,
8667 test: testCase{
8668 protocol: protocol,
8669 name: "ServerKeyExchange" + suffix,
8670 config: Config{
8671 MaxVersion: VersionTLS12,
8672 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008673 },
8674 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008675 })
8676
David Benjamincd2c8062016-09-09 11:28:16 -04008677 ret = append(ret, perMessageTest{
8678 messageType: typeCertificateRequest,
8679 test: testCase{
8680 protocol: protocol,
8681 name: "CertificateRequest" + suffix,
8682 config: Config{
8683 MaxVersion: VersionTLS12,
8684 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008685 },
8686 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008687 })
8688
David Benjamincd2c8062016-09-09 11:28:16 -04008689 ret = append(ret, perMessageTest{
8690 messageType: typeServerHelloDone,
8691 test: testCase{
8692 protocol: protocol,
8693 name: "ServerHelloDone" + suffix,
8694 config: Config{
8695 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008696 },
8697 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008698 })
8699
David Benjamincd2c8062016-09-09 11:28:16 -04008700 ret = append(ret, perMessageTest{
8701 messageType: typeCertificate,
8702 test: testCase{
8703 testType: serverTest,
8704 protocol: protocol,
8705 name: "ClientCertificate" + suffix,
8706 config: Config{
8707 Certificates: []Certificate{rsaCertificate},
8708 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008709 },
David Benjamincd2c8062016-09-09 11:28:16 -04008710 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008711 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008712 })
8713
David Benjamincd2c8062016-09-09 11:28:16 -04008714 ret = append(ret, perMessageTest{
8715 messageType: typeCertificateVerify,
8716 test: testCase{
8717 testType: serverTest,
8718 protocol: protocol,
8719 name: "CertificateVerify" + suffix,
8720 config: Config{
8721 Certificates: []Certificate{rsaCertificate},
8722 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008723 },
David Benjamincd2c8062016-09-09 11:28:16 -04008724 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008725 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008726 })
8727
David Benjamincd2c8062016-09-09 11:28:16 -04008728 ret = append(ret, perMessageTest{
8729 messageType: typeClientKeyExchange,
8730 test: testCase{
8731 testType: serverTest,
8732 protocol: protocol,
8733 name: "ClientKeyExchange" + suffix,
8734 config: Config{
8735 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008736 },
8737 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008738 })
8739
8740 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008741 ret = append(ret, perMessageTest{
8742 messageType: typeNextProtocol,
8743 test: testCase{
8744 testType: serverTest,
8745 protocol: protocol,
8746 name: "NextProtocol" + suffix,
8747 config: Config{
8748 MaxVersion: VersionTLS12,
8749 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008750 },
David Benjamincd2c8062016-09-09 11:28:16 -04008751 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008752 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008753 })
8754
David Benjamincd2c8062016-09-09 11:28:16 -04008755 ret = append(ret, perMessageTest{
8756 messageType: typeChannelID,
8757 test: testCase{
8758 testType: serverTest,
8759 protocol: protocol,
8760 name: "ChannelID" + suffix,
8761 config: Config{
8762 MaxVersion: VersionTLS12,
8763 ChannelID: channelIDKey,
8764 },
8765 flags: []string{
8766 "-expect-channel-id",
8767 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008768 },
8769 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008770 })
8771 }
8772
David Benjamincd2c8062016-09-09 11:28:16 -04008773 ret = append(ret, perMessageTest{
8774 messageType: typeFinished,
8775 test: testCase{
8776 testType: serverTest,
8777 protocol: protocol,
8778 name: "ClientFinished" + suffix,
8779 config: Config{
8780 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008781 },
8782 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008783 })
8784
David Benjamincd2c8062016-09-09 11:28:16 -04008785 ret = append(ret, perMessageTest{
8786 messageType: typeNewSessionTicket,
8787 test: testCase{
8788 protocol: protocol,
8789 name: "NewSessionTicket" + suffix,
8790 config: Config{
8791 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008792 },
8793 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008794 })
8795
David Benjamincd2c8062016-09-09 11:28:16 -04008796 ret = append(ret, perMessageTest{
8797 messageType: typeFinished,
8798 test: testCase{
8799 protocol: protocol,
8800 name: "ServerFinished" + suffix,
8801 config: Config{
8802 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008803 },
8804 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008805 })
8806
8807 }
David Benjamincd2c8062016-09-09 11:28:16 -04008808
8809 ret = append(ret, perMessageTest{
8810 messageType: typeClientHello,
8811 test: testCase{
8812 testType: serverTest,
8813 name: "TLS13-ClientHello",
8814 config: Config{
8815 MaxVersion: VersionTLS13,
8816 },
8817 },
8818 })
8819
8820 ret = append(ret, perMessageTest{
8821 messageType: typeServerHello,
8822 test: testCase{
8823 name: "TLS13-ServerHello",
8824 config: Config{
8825 MaxVersion: VersionTLS13,
8826 },
8827 },
8828 })
8829
8830 ret = append(ret, perMessageTest{
8831 messageType: typeEncryptedExtensions,
8832 test: testCase{
8833 name: "TLS13-EncryptedExtensions",
8834 config: Config{
8835 MaxVersion: VersionTLS13,
8836 },
8837 },
8838 })
8839
8840 ret = append(ret, perMessageTest{
8841 messageType: typeCertificateRequest,
8842 test: testCase{
8843 name: "TLS13-CertificateRequest",
8844 config: Config{
8845 MaxVersion: VersionTLS13,
8846 ClientAuth: RequireAnyClientCert,
8847 },
8848 },
8849 })
8850
8851 ret = append(ret, perMessageTest{
8852 messageType: typeCertificate,
8853 test: testCase{
8854 name: "TLS13-ServerCertificate",
8855 config: Config{
8856 MaxVersion: VersionTLS13,
8857 },
8858 },
8859 })
8860
8861 ret = append(ret, perMessageTest{
8862 messageType: typeCertificateVerify,
8863 test: testCase{
8864 name: "TLS13-ServerCertificateVerify",
8865 config: Config{
8866 MaxVersion: VersionTLS13,
8867 },
8868 },
8869 })
8870
8871 ret = append(ret, perMessageTest{
8872 messageType: typeFinished,
8873 test: testCase{
8874 name: "TLS13-ServerFinished",
8875 config: Config{
8876 MaxVersion: VersionTLS13,
8877 },
8878 },
8879 })
8880
8881 ret = append(ret, perMessageTest{
8882 messageType: typeCertificate,
8883 test: testCase{
8884 testType: serverTest,
8885 name: "TLS13-ClientCertificate",
8886 config: Config{
8887 Certificates: []Certificate{rsaCertificate},
8888 MaxVersion: VersionTLS13,
8889 },
8890 flags: []string{"-require-any-client-certificate"},
8891 },
8892 })
8893
8894 ret = append(ret, perMessageTest{
8895 messageType: typeCertificateVerify,
8896 test: testCase{
8897 testType: serverTest,
8898 name: "TLS13-ClientCertificateVerify",
8899 config: Config{
8900 Certificates: []Certificate{rsaCertificate},
8901 MaxVersion: VersionTLS13,
8902 },
8903 flags: []string{"-require-any-client-certificate"},
8904 },
8905 })
8906
8907 ret = append(ret, perMessageTest{
8908 messageType: typeFinished,
8909 test: testCase{
8910 testType: serverTest,
8911 name: "TLS13-ClientFinished",
8912 config: Config{
8913 MaxVersion: VersionTLS13,
8914 },
8915 },
8916 })
8917
8918 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008919}
8920
David Benjamincd2c8062016-09-09 11:28:16 -04008921func addWrongMessageTypeTests() {
8922 for _, t := range makePerMessageTests() {
8923 t.test.name = "WrongMessageType-" + t.test.name
8924 t.test.config.Bugs.SendWrongMessageType = t.messageType
8925 t.test.shouldFail = true
8926 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8927 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008928
David Benjamincd2c8062016-09-09 11:28:16 -04008929 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8930 // In TLS 1.3, a bad ServerHello means the client sends
8931 // an unencrypted alert while the server expects
8932 // encryption, so the alert is not readable by runner.
8933 t.test.expectedLocalError = "local error: bad record MAC"
8934 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008935
David Benjamincd2c8062016-09-09 11:28:16 -04008936 testCases = append(testCases, t.test)
8937 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008938}
8939
David Benjamin639846e2016-09-09 11:41:18 -04008940func addTrailingMessageDataTests() {
8941 for _, t := range makePerMessageTests() {
8942 t.test.name = "TrailingMessageData-" + t.test.name
8943 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8944 t.test.shouldFail = true
8945 t.test.expectedError = ":DECODE_ERROR:"
8946 t.test.expectedLocalError = "remote error: error decoding message"
8947
8948 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8949 // In TLS 1.3, a bad ServerHello means the client sends
8950 // an unencrypted alert while the server expects
8951 // encryption, so the alert is not readable by runner.
8952 t.test.expectedLocalError = "local error: bad record MAC"
8953 }
8954
8955 if t.messageType == typeFinished {
8956 // Bad Finished messages read as the verify data having
8957 // the wrong length.
8958 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8959 t.test.expectedLocalError = "remote error: error decrypting message"
8960 }
8961
8962 testCases = append(testCases, t.test)
8963 }
8964}
8965
Steven Valdez143e8b32016-07-11 13:19:03 -04008966func addTLS13HandshakeTests() {
8967 testCases = append(testCases, testCase{
8968 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008969 name: "NegotiatePSKResumption-TLS13",
8970 config: Config{
8971 MaxVersion: VersionTLS13,
8972 Bugs: ProtocolBugs{
8973 NegotiatePSKResumption: true,
8974 },
8975 },
8976 resumeSession: true,
8977 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05008978 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04008979 })
8980
8981 testCases = append(testCases, testCase{
8982 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008983 name: "MissingKeyShare-Client",
8984 config: Config{
8985 MaxVersion: VersionTLS13,
8986 Bugs: ProtocolBugs{
8987 MissingKeyShare: true,
8988 },
8989 },
8990 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05008991 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008992 })
8993
8994 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008995 testType: serverTest,
8996 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008997 config: Config{
8998 MaxVersion: VersionTLS13,
8999 Bugs: ProtocolBugs{
9000 MissingKeyShare: true,
9001 },
9002 },
9003 shouldFail: true,
9004 expectedError: ":MISSING_KEY_SHARE:",
9005 })
9006
9007 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009008 testType: serverTest,
9009 name: "DuplicateKeyShares",
9010 config: Config{
9011 MaxVersion: VersionTLS13,
9012 Bugs: ProtocolBugs{
9013 DuplicateKeyShares: true,
9014 },
9015 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009016 shouldFail: true,
9017 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009018 })
9019
9020 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009021 testType: serverTest,
9022 name: "SkipEarlyData",
9023 config: Config{
9024 MaxVersion: VersionTLS13,
9025 Bugs: ProtocolBugs{
9026 SendEarlyDataLength: 4,
9027 },
9028 },
9029 })
9030
9031 testCases = append(testCases, testCase{
9032 testType: serverTest,
9033 name: "SkipEarlyData-OmitEarlyDataExtension",
9034 config: Config{
9035 MaxVersion: VersionTLS13,
9036 Bugs: ProtocolBugs{
9037 SendEarlyDataLength: 4,
9038 OmitEarlyDataExtension: true,
9039 },
9040 },
9041 shouldFail: true,
9042 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9043 })
9044
9045 testCases = append(testCases, testCase{
9046 testType: serverTest,
9047 name: "SkipEarlyData-TooMuchData",
9048 config: Config{
9049 MaxVersion: VersionTLS13,
9050 Bugs: ProtocolBugs{
9051 SendEarlyDataLength: 16384 + 1,
9052 },
9053 },
9054 shouldFail: true,
9055 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9056 })
9057
9058 testCases = append(testCases, testCase{
9059 testType: serverTest,
9060 name: "SkipEarlyData-Interleaved",
9061 config: Config{
9062 MaxVersion: VersionTLS13,
9063 Bugs: ProtocolBugs{
9064 SendEarlyDataLength: 4,
9065 InterleaveEarlyData: true,
9066 },
9067 },
9068 shouldFail: true,
9069 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9070 })
9071
9072 testCases = append(testCases, testCase{
9073 testType: serverTest,
9074 name: "SkipEarlyData-EarlyDataInTLS12",
9075 config: Config{
9076 MaxVersion: VersionTLS13,
9077 Bugs: ProtocolBugs{
9078 SendEarlyDataLength: 4,
9079 },
9080 },
9081 shouldFail: true,
9082 expectedError: ":UNEXPECTED_RECORD:",
9083 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9084 })
9085
9086 testCases = append(testCases, testCase{
9087 testType: serverTest,
9088 name: "SkipEarlyData-HRR",
9089 config: Config{
9090 MaxVersion: VersionTLS13,
9091 Bugs: ProtocolBugs{
9092 SendEarlyDataLength: 4,
9093 },
9094 DefaultCurves: []CurveID{},
9095 },
9096 })
9097
9098 testCases = append(testCases, testCase{
9099 testType: serverTest,
9100 name: "SkipEarlyData-HRR-Interleaved",
9101 config: Config{
9102 MaxVersion: VersionTLS13,
9103 Bugs: ProtocolBugs{
9104 SendEarlyDataLength: 4,
9105 InterleaveEarlyData: true,
9106 },
9107 DefaultCurves: []CurveID{},
9108 },
9109 shouldFail: true,
9110 expectedError: ":UNEXPECTED_RECORD:",
9111 })
9112
9113 testCases = append(testCases, testCase{
9114 testType: serverTest,
9115 name: "SkipEarlyData-HRR-TooMuchData",
9116 config: Config{
9117 MaxVersion: VersionTLS13,
9118 Bugs: ProtocolBugs{
9119 SendEarlyDataLength: 16384 + 1,
9120 },
9121 DefaultCurves: []CurveID{},
9122 },
9123 shouldFail: true,
9124 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9125 })
9126
9127 // Test that skipping early data looking for cleartext correctly
9128 // processes an alert record.
9129 testCases = append(testCases, testCase{
9130 testType: serverTest,
9131 name: "SkipEarlyData-HRR-FatalAlert",
9132 config: Config{
9133 MaxVersion: VersionTLS13,
9134 Bugs: ProtocolBugs{
9135 SendEarlyAlert: true,
9136 SendEarlyDataLength: 4,
9137 },
9138 DefaultCurves: []CurveID{},
9139 },
9140 shouldFail: true,
9141 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9142 })
9143
9144 testCases = append(testCases, testCase{
9145 testType: serverTest,
9146 name: "SkipEarlyData-SecondClientHelloEarlyData",
9147 config: Config{
9148 MaxVersion: VersionTLS13,
9149 Bugs: ProtocolBugs{
9150 SendEarlyDataOnSecondClientHello: true,
9151 },
9152 DefaultCurves: []CurveID{},
9153 },
9154 shouldFail: true,
9155 expectedLocalError: "remote error: bad record MAC",
9156 })
9157
9158 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009159 testType: clientTest,
9160 name: "EmptyEncryptedExtensions",
9161 config: Config{
9162 MaxVersion: VersionTLS13,
9163 Bugs: ProtocolBugs{
9164 EmptyEncryptedExtensions: true,
9165 },
9166 },
9167 shouldFail: true,
9168 expectedLocalError: "remote error: error decoding message",
9169 })
9170
9171 testCases = append(testCases, testCase{
9172 testType: clientTest,
9173 name: "EncryptedExtensionsWithKeyShare",
9174 config: Config{
9175 MaxVersion: VersionTLS13,
9176 Bugs: ProtocolBugs{
9177 EncryptedExtensionsWithKeyShare: true,
9178 },
9179 },
9180 shouldFail: true,
9181 expectedLocalError: "remote error: unsupported extension",
9182 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009183
9184 testCases = append(testCases, testCase{
9185 testType: serverTest,
9186 name: "SendHelloRetryRequest",
9187 config: Config{
9188 MaxVersion: VersionTLS13,
9189 // Require a HelloRetryRequest for every curve.
9190 DefaultCurves: []CurveID{},
9191 },
9192 expectedCurveID: CurveX25519,
9193 })
9194
9195 testCases = append(testCases, testCase{
9196 testType: serverTest,
9197 name: "SendHelloRetryRequest-2",
9198 config: Config{
9199 MaxVersion: VersionTLS13,
9200 DefaultCurves: []CurveID{CurveP384},
9201 },
9202 // Although the ClientHello did not predict our preferred curve,
9203 // we always select it whether it is predicted or not.
9204 expectedCurveID: CurveX25519,
9205 })
9206
9207 testCases = append(testCases, testCase{
9208 name: "UnknownCurve-HelloRetryRequest",
9209 config: Config{
9210 MaxVersion: VersionTLS13,
9211 // P-384 requires HelloRetryRequest in BoringSSL.
9212 CurvePreferences: []CurveID{CurveP384},
9213 Bugs: ProtocolBugs{
9214 SendHelloRetryRequestCurve: bogusCurve,
9215 },
9216 },
9217 shouldFail: true,
9218 expectedError: ":WRONG_CURVE:",
9219 })
9220
9221 testCases = append(testCases, testCase{
9222 name: "DisabledCurve-HelloRetryRequest",
9223 config: Config{
9224 MaxVersion: VersionTLS13,
9225 CurvePreferences: []CurveID{CurveP256},
9226 Bugs: ProtocolBugs{
9227 IgnorePeerCurvePreferences: true,
9228 },
9229 },
9230 flags: []string{"-p384-only"},
9231 shouldFail: true,
9232 expectedError: ":WRONG_CURVE:",
9233 })
9234
9235 testCases = append(testCases, testCase{
9236 name: "UnnecessaryHelloRetryRequest",
9237 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009238 MaxVersion: VersionTLS13,
9239 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009240 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009241 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009242 },
9243 },
9244 shouldFail: true,
9245 expectedError: ":WRONG_CURVE:",
9246 })
9247
9248 testCases = append(testCases, testCase{
9249 name: "SecondHelloRetryRequest",
9250 config: Config{
9251 MaxVersion: VersionTLS13,
9252 // P-384 requires HelloRetryRequest in BoringSSL.
9253 CurvePreferences: []CurveID{CurveP384},
9254 Bugs: ProtocolBugs{
9255 SecondHelloRetryRequest: true,
9256 },
9257 },
9258 shouldFail: true,
9259 expectedError: ":UNEXPECTED_MESSAGE:",
9260 })
9261
9262 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009263 name: "HelloRetryRequest-Empty",
9264 config: Config{
9265 MaxVersion: VersionTLS13,
9266 Bugs: ProtocolBugs{
9267 AlwaysSendHelloRetryRequest: true,
9268 },
9269 },
9270 shouldFail: true,
9271 expectedError: ":DECODE_ERROR:",
9272 })
9273
9274 testCases = append(testCases, testCase{
9275 name: "HelloRetryRequest-DuplicateCurve",
9276 config: Config{
9277 MaxVersion: VersionTLS13,
9278 // P-384 requires a HelloRetryRequest against BoringSSL's default
9279 // configuration. Assert this ExpectMissingKeyShare.
9280 CurvePreferences: []CurveID{CurveP384},
9281 Bugs: ProtocolBugs{
9282 ExpectMissingKeyShare: true,
9283 DuplicateHelloRetryRequestExtensions: true,
9284 },
9285 },
9286 shouldFail: true,
9287 expectedError: ":DUPLICATE_EXTENSION:",
9288 expectedLocalError: "remote error: illegal parameter",
9289 })
9290
9291 testCases = append(testCases, testCase{
9292 name: "HelloRetryRequest-Cookie",
9293 config: Config{
9294 MaxVersion: VersionTLS13,
9295 Bugs: ProtocolBugs{
9296 SendHelloRetryRequestCookie: []byte("cookie"),
9297 },
9298 },
9299 })
9300
9301 testCases = append(testCases, testCase{
9302 name: "HelloRetryRequest-DuplicateCookie",
9303 config: Config{
9304 MaxVersion: VersionTLS13,
9305 Bugs: ProtocolBugs{
9306 SendHelloRetryRequestCookie: []byte("cookie"),
9307 DuplicateHelloRetryRequestExtensions: true,
9308 },
9309 },
9310 shouldFail: true,
9311 expectedError: ":DUPLICATE_EXTENSION:",
9312 expectedLocalError: "remote error: illegal parameter",
9313 })
9314
9315 testCases = append(testCases, testCase{
9316 name: "HelloRetryRequest-EmptyCookie",
9317 config: Config{
9318 MaxVersion: VersionTLS13,
9319 Bugs: ProtocolBugs{
9320 SendHelloRetryRequestCookie: []byte{},
9321 },
9322 },
9323 shouldFail: true,
9324 expectedError: ":DECODE_ERROR:",
9325 })
9326
9327 testCases = append(testCases, testCase{
9328 name: "HelloRetryRequest-Cookie-Curve",
9329 config: Config{
9330 MaxVersion: VersionTLS13,
9331 // P-384 requires HelloRetryRequest in BoringSSL.
9332 CurvePreferences: []CurveID{CurveP384},
9333 Bugs: ProtocolBugs{
9334 SendHelloRetryRequestCookie: []byte("cookie"),
9335 ExpectMissingKeyShare: true,
9336 },
9337 },
9338 })
9339
9340 testCases = append(testCases, testCase{
9341 name: "HelloRetryRequest-Unknown",
9342 config: Config{
9343 MaxVersion: VersionTLS13,
9344 Bugs: ProtocolBugs{
9345 CustomHelloRetryRequestExtension: "extension",
9346 },
9347 },
9348 shouldFail: true,
9349 expectedError: ":UNEXPECTED_EXTENSION:",
9350 expectedLocalError: "remote error: unsupported extension",
9351 })
9352
9353 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009354 testType: serverTest,
9355 name: "SecondClientHelloMissingKeyShare",
9356 config: Config{
9357 MaxVersion: VersionTLS13,
9358 DefaultCurves: []CurveID{},
9359 Bugs: ProtocolBugs{
9360 SecondClientHelloMissingKeyShare: true,
9361 },
9362 },
9363 shouldFail: true,
9364 expectedError: ":MISSING_KEY_SHARE:",
9365 })
9366
9367 testCases = append(testCases, testCase{
9368 testType: serverTest,
9369 name: "SecondClientHelloWrongCurve",
9370 config: Config{
9371 MaxVersion: VersionTLS13,
9372 DefaultCurves: []CurveID{},
9373 Bugs: ProtocolBugs{
9374 MisinterpretHelloRetryRequestCurve: CurveP521,
9375 },
9376 },
9377 shouldFail: true,
9378 expectedError: ":WRONG_CURVE:",
9379 })
9380
9381 testCases = append(testCases, testCase{
9382 name: "HelloRetryRequestVersionMismatch",
9383 config: Config{
9384 MaxVersion: VersionTLS13,
9385 // P-384 requires HelloRetryRequest in BoringSSL.
9386 CurvePreferences: []CurveID{CurveP384},
9387 Bugs: ProtocolBugs{
9388 SendServerHelloVersion: 0x0305,
9389 },
9390 },
9391 shouldFail: true,
9392 expectedError: ":WRONG_VERSION_NUMBER:",
9393 })
9394
9395 testCases = append(testCases, testCase{
9396 name: "HelloRetryRequestCurveMismatch",
9397 config: Config{
9398 MaxVersion: VersionTLS13,
9399 // P-384 requires HelloRetryRequest in BoringSSL.
9400 CurvePreferences: []CurveID{CurveP384},
9401 Bugs: ProtocolBugs{
9402 // Send P-384 (correct) in the HelloRetryRequest.
9403 SendHelloRetryRequestCurve: CurveP384,
9404 // But send P-256 in the ServerHello.
9405 SendCurve: CurveP256,
9406 },
9407 },
9408 shouldFail: true,
9409 expectedError: ":WRONG_CURVE:",
9410 })
9411
9412 // Test the server selecting a curve that requires a HelloRetryRequest
9413 // without sending it.
9414 testCases = append(testCases, testCase{
9415 name: "SkipHelloRetryRequest",
9416 config: Config{
9417 MaxVersion: VersionTLS13,
9418 // P-384 requires HelloRetryRequest in BoringSSL.
9419 CurvePreferences: []CurveID{CurveP384},
9420 Bugs: ProtocolBugs{
9421 SkipHelloRetryRequest: true,
9422 },
9423 },
9424 shouldFail: true,
9425 expectedError: ":WRONG_CURVE:",
9426 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009427
9428 testCases = append(testCases, testCase{
9429 name: "TLS13-RequestContextInHandshake",
9430 config: Config{
9431 MaxVersion: VersionTLS13,
9432 MinVersion: VersionTLS13,
9433 ClientAuth: RequireAnyClientCert,
9434 Bugs: ProtocolBugs{
9435 SendRequestContext: []byte("request context"),
9436 },
9437 },
9438 flags: []string{
9439 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9440 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9441 },
9442 shouldFail: true,
9443 expectedError: ":DECODE_ERROR:",
9444 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009445
9446 testCases = append(testCases, testCase{
9447 testType: serverTest,
9448 name: "TLS13-TrailingKeyShareData",
9449 config: Config{
9450 MaxVersion: VersionTLS13,
9451 Bugs: ProtocolBugs{
9452 TrailingKeyShareData: true,
9453 },
9454 },
9455 shouldFail: true,
9456 expectedError: ":DECODE_ERROR:",
9457 })
David Benjamin7f78df42016-10-05 22:33:19 -04009458
9459 testCases = append(testCases, testCase{
9460 name: "TLS13-AlwaysSelectPSKIdentity",
9461 config: Config{
9462 MaxVersion: VersionTLS13,
9463 Bugs: ProtocolBugs{
9464 AlwaysSelectPSKIdentity: true,
9465 },
9466 },
9467 shouldFail: true,
9468 expectedError: ":UNEXPECTED_EXTENSION:",
9469 })
9470
9471 testCases = append(testCases, testCase{
9472 name: "TLS13-InvalidPSKIdentity",
9473 config: Config{
9474 MaxVersion: VersionTLS13,
9475 Bugs: ProtocolBugs{
9476 SelectPSKIdentityOnResume: 1,
9477 },
9478 },
9479 resumeSession: true,
9480 shouldFail: true,
9481 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9482 })
David Benjamin1286bee2016-10-07 15:25:06 -04009483
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009484 testCases = append(testCases, testCase{
9485 testType: serverTest,
9486 name: "TLS13-ExtraPSKIdentity",
9487 config: Config{
9488 MaxVersion: VersionTLS13,
9489 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009490 ExtraPSKIdentity: true,
9491 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009492 },
9493 },
9494 resumeSession: true,
9495 })
9496
David Benjamin1286bee2016-10-07 15:25:06 -04009497 // Test that unknown NewSessionTicket extensions are tolerated.
9498 testCases = append(testCases, testCase{
9499 name: "TLS13-CustomTicketExtension",
9500 config: Config{
9501 MaxVersion: VersionTLS13,
9502 Bugs: ProtocolBugs{
9503 CustomTicketExtension: "1234",
9504 },
9505 },
9506 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009507}
9508
David Benjaminabbbee12016-10-31 19:20:42 -04009509func addTLS13CipherPreferenceTests() {
9510 // Test that client preference is honored if the shim has AES hardware
9511 // and ChaCha20-Poly1305 is preferred otherwise.
9512 testCases = append(testCases, testCase{
9513 testType: serverTest,
9514 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9515 config: Config{
9516 MaxVersion: VersionTLS13,
9517 CipherSuites: []uint16{
9518 TLS_CHACHA20_POLY1305_SHA256,
9519 TLS_AES_128_GCM_SHA256,
9520 },
9521 },
9522 flags: []string{
9523 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9524 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9525 },
9526 })
9527
9528 testCases = append(testCases, testCase{
9529 testType: serverTest,
9530 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9531 config: Config{
9532 MaxVersion: VersionTLS13,
9533 CipherSuites: []uint16{
9534 TLS_AES_128_GCM_SHA256,
9535 TLS_CHACHA20_POLY1305_SHA256,
9536 },
9537 },
9538 flags: []string{
9539 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9540 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9541 },
9542 })
9543
9544 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9545 // whether it has AES hardware.
9546 testCases = append(testCases, testCase{
9547 name: "TLS13-CipherPreference-Client",
9548 config: Config{
9549 MaxVersion: VersionTLS13,
9550 // Use the client cipher order. (This is the default but
9551 // is listed to be explicit.)
9552 PreferServerCipherSuites: false,
9553 },
9554 flags: []string{
9555 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9556 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9557 },
9558 })
9559}
9560
David Benjaminf3fbade2016-09-19 13:08:16 -04009561func addPeekTests() {
9562 // Test SSL_peek works, including on empty records.
9563 testCases = append(testCases, testCase{
9564 name: "Peek-Basic",
9565 sendEmptyRecords: 1,
9566 flags: []string{"-peek-then-read"},
9567 })
9568
9569 // Test SSL_peek can drive the initial handshake.
9570 testCases = append(testCases, testCase{
9571 name: "Peek-ImplicitHandshake",
9572 flags: []string{
9573 "-peek-then-read",
9574 "-implicit-handshake",
9575 },
9576 })
9577
9578 // Test SSL_peek can discover and drive a renegotiation.
9579 testCases = append(testCases, testCase{
9580 name: "Peek-Renegotiate",
9581 config: Config{
9582 MaxVersion: VersionTLS12,
9583 },
9584 renegotiate: 1,
9585 flags: []string{
9586 "-peek-then-read",
9587 "-renegotiate-freely",
9588 "-expect-total-renegotiations", "1",
9589 },
9590 })
9591
9592 // Test SSL_peek can discover a close_notify.
9593 testCases = append(testCases, testCase{
9594 name: "Peek-Shutdown",
9595 config: Config{
9596 Bugs: ProtocolBugs{
9597 ExpectCloseNotify: true,
9598 },
9599 },
9600 flags: []string{
9601 "-peek-then-read",
9602 "-check-close-notify",
9603 },
9604 })
9605
9606 // Test SSL_peek can discover an alert.
9607 testCases = append(testCases, testCase{
9608 name: "Peek-Alert",
9609 config: Config{
9610 Bugs: ProtocolBugs{
9611 SendSpuriousAlert: alertRecordOverflow,
9612 },
9613 },
9614 flags: []string{"-peek-then-read"},
9615 shouldFail: true,
9616 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9617 })
9618
9619 // Test SSL_peek can handle KeyUpdate.
9620 testCases = append(testCases, testCase{
9621 name: "Peek-KeyUpdate",
9622 config: Config{
9623 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009624 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009625 sendKeyUpdates: 1,
9626 keyUpdateRequest: keyUpdateNotRequested,
9627 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009628 })
9629}
9630
David Benjamine6f22212016-11-08 14:28:24 -05009631func addRecordVersionTests() {
9632 for _, ver := range tlsVersions {
9633 // Test that the record version is enforced.
9634 testCases = append(testCases, testCase{
9635 name: "CheckRecordVersion-" + ver.name,
9636 config: Config{
9637 MinVersion: ver.version,
9638 MaxVersion: ver.version,
9639 Bugs: ProtocolBugs{
9640 SendRecordVersion: 0x03ff,
9641 },
9642 },
9643 shouldFail: true,
9644 expectedError: ":WRONG_VERSION_NUMBER:",
9645 })
9646
9647 // Test that the ClientHello may use any record version, for
9648 // compatibility reasons.
9649 testCases = append(testCases, testCase{
9650 testType: serverTest,
9651 name: "LooseInitialRecordVersion-" + ver.name,
9652 config: Config{
9653 MinVersion: ver.version,
9654 MaxVersion: ver.version,
9655 Bugs: ProtocolBugs{
9656 SendInitialRecordVersion: 0x03ff,
9657 },
9658 },
9659 })
9660
9661 // Test that garbage ClientHello record versions are rejected.
9662 testCases = append(testCases, testCase{
9663 testType: serverTest,
9664 name: "GarbageInitialRecordVersion-" + ver.name,
9665 config: Config{
9666 MinVersion: ver.version,
9667 MaxVersion: ver.version,
9668 Bugs: ProtocolBugs{
9669 SendInitialRecordVersion: 0xffff,
9670 },
9671 },
9672 shouldFail: true,
9673 expectedError: ":WRONG_VERSION_NUMBER:",
9674 })
9675 }
9676}
9677
David Benjamin2c516452016-11-15 10:16:54 +09009678func addCertificateTests() {
9679 // Test that a certificate chain with intermediate may be sent and
9680 // received as both client and server.
9681 for _, ver := range tlsVersions {
9682 testCases = append(testCases, testCase{
9683 testType: clientTest,
9684 name: "SendReceiveIntermediate-Client-" + ver.name,
9685 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009686 MinVersion: ver.version,
9687 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009688 Certificates: []Certificate{rsaChainCertificate},
9689 ClientAuth: RequireAnyClientCert,
9690 },
9691 expectPeerCertificate: &rsaChainCertificate,
9692 flags: []string{
9693 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9694 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9695 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9696 },
9697 })
9698
9699 testCases = append(testCases, testCase{
9700 testType: serverTest,
9701 name: "SendReceiveIntermediate-Server-" + ver.name,
9702 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009703 MinVersion: ver.version,
9704 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009705 Certificates: []Certificate{rsaChainCertificate},
9706 },
9707 expectPeerCertificate: &rsaChainCertificate,
9708 flags: []string{
9709 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9710 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9711 "-require-any-client-certificate",
9712 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9713 },
9714 })
9715 }
9716}
9717
David Benjaminbbaf3672016-11-17 10:53:09 +09009718func addRetainOnlySHA256ClientCertTests() {
9719 for _, ver := range tlsVersions {
9720 // Test that enabling
9721 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9722 // actually requesting a client certificate is a no-op.
9723 testCases = append(testCases, testCase{
9724 testType: serverTest,
9725 name: "RetainOnlySHA256-NoCert-" + ver.name,
9726 config: Config{
9727 MinVersion: ver.version,
9728 MaxVersion: ver.version,
9729 },
9730 flags: []string{
9731 "-retain-only-sha256-client-cert-initial",
9732 "-retain-only-sha256-client-cert-resume",
9733 },
9734 resumeSession: true,
9735 })
9736
9737 // Test that when retaining only a SHA-256 certificate is
9738 // enabled, the hash appears as expected.
9739 testCases = append(testCases, testCase{
9740 testType: serverTest,
9741 name: "RetainOnlySHA256-Cert-" + ver.name,
9742 config: Config{
9743 MinVersion: ver.version,
9744 MaxVersion: ver.version,
9745 Certificates: []Certificate{rsaCertificate},
9746 },
9747 flags: []string{
9748 "-verify-peer",
9749 "-retain-only-sha256-client-cert-initial",
9750 "-retain-only-sha256-client-cert-resume",
9751 "-expect-sha256-client-cert-initial",
9752 "-expect-sha256-client-cert-resume",
9753 },
9754 resumeSession: true,
9755 })
9756
9757 // Test that when the config changes from on to off, a
9758 // resumption is rejected because the server now wants the full
9759 // certificate chain.
9760 testCases = append(testCases, testCase{
9761 testType: serverTest,
9762 name: "RetainOnlySHA256-OnOff-" + ver.name,
9763 config: Config{
9764 MinVersion: ver.version,
9765 MaxVersion: ver.version,
9766 Certificates: []Certificate{rsaCertificate},
9767 },
9768 flags: []string{
9769 "-verify-peer",
9770 "-retain-only-sha256-client-cert-initial",
9771 "-expect-sha256-client-cert-initial",
9772 },
9773 resumeSession: true,
9774 expectResumeRejected: true,
9775 })
9776
9777 // Test that when the config changes from off to on, a
9778 // resumption is rejected because the server now wants just the
9779 // hash.
9780 testCases = append(testCases, testCase{
9781 testType: serverTest,
9782 name: "RetainOnlySHA256-OffOn-" + ver.name,
9783 config: Config{
9784 MinVersion: ver.version,
9785 MaxVersion: ver.version,
9786 Certificates: []Certificate{rsaCertificate},
9787 },
9788 flags: []string{
9789 "-verify-peer",
9790 "-retain-only-sha256-client-cert-resume",
9791 "-expect-sha256-client-cert-resume",
9792 },
9793 resumeSession: true,
9794 expectResumeRejected: true,
9795 })
9796 }
9797}
9798
Adam Langleya4b91982016-12-12 12:05:53 -08009799func addECDSAKeyUsageTests() {
9800 p256 := elliptic.P256()
9801 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
9802 if err != nil {
9803 panic(err)
9804 }
9805
9806 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
9807 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
9808 if err != nil {
9809 panic(err)
9810 }
9811
9812 template := x509.Certificate{
9813 SerialNumber: serialNumber,
9814 Subject: pkix.Name{
9815 Organization: []string{"Acme Co"},
9816 },
9817 NotBefore: time.Now(),
9818 NotAfter: time.Now(),
9819
9820 // An ECC certificate with only the keyAgreement key usgae may
9821 // be used with ECDH, but not ECDSA.
9822 KeyUsage: x509.KeyUsageKeyAgreement,
9823 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
9824 BasicConstraintsValid: true,
9825 }
9826
9827 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
9828 if err != nil {
9829 panic(err)
9830 }
9831
9832 cert := Certificate{
9833 Certificate: [][]byte{derBytes},
9834 PrivateKey: priv,
9835 }
9836
9837 for _, ver := range tlsVersions {
9838 if ver.version < VersionTLS12 {
9839 continue
9840 }
9841
9842 testCases = append(testCases, testCase{
9843 testType: clientTest,
9844 name: "ECDSAKeyUsage-" + ver.name,
9845 config: Config{
9846 MinVersion: ver.version,
9847 MaxVersion: ver.version,
9848 Certificates: []Certificate{cert},
9849 },
9850 shouldFail: true,
9851 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
9852 })
9853 }
9854}
9855
Adam Langley7c803a62015-06-15 15:35:05 -07009856func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009857 defer wg.Done()
9858
9859 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009860 var err error
9861
David Benjaminba28dfc2016-11-15 17:47:21 +09009862 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -08009863 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9864 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009865 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009866 if err != nil {
9867 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9868 }
9869 break
9870 }
9871 }
David Benjaminba28dfc2016-11-15 17:47:21 +09009872 } else if *repeatUntilFailure {
9873 for err == nil {
9874 statusChan <- statusMsg{test: test, started: true}
9875 err = runTest(test, shimPath, -1)
9876 }
9877 } else {
9878 statusChan <- statusMsg{test: test, started: true}
9879 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009880 }
Adam Langley95c29f32014-06-20 12:00:00 -07009881 statusChan <- statusMsg{test: test, err: err}
9882 }
9883}
9884
9885type statusMsg struct {
9886 test *testCase
9887 started bool
9888 err error
9889}
9890
David Benjamin5f237bc2015-02-11 17:14:15 -05009891func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009892 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009893
David Benjamin5f237bc2015-02-11 17:14:15 -05009894 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009895 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009896 if !*pipe {
9897 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009898 var erase string
9899 for i := 0; i < lineLen; i++ {
9900 erase += "\b \b"
9901 }
9902 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009903 }
9904
Adam Langley95c29f32014-06-20 12:00:00 -07009905 if msg.started {
9906 started++
9907 } else {
9908 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009909
9910 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009911 if msg.err == errUnimplemented {
9912 if *pipe {
9913 // Print each test instead of a status line.
9914 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9915 }
9916 unimplemented++
9917 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9918 } else {
9919 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9920 failed++
9921 testOutput.addResult(msg.test.name, "FAIL")
9922 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009923 } else {
9924 if *pipe {
9925 // Print each test instead of a status line.
9926 fmt.Printf("PASSED (%s)\n", msg.test.name)
9927 }
9928 testOutput.addResult(msg.test.name, "PASS")
9929 }
Adam Langley95c29f32014-06-20 12:00:00 -07009930 }
9931
David Benjamin5f237bc2015-02-11 17:14:15 -05009932 if !*pipe {
9933 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009934 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009935 lineLen = len(line)
9936 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009937 }
Adam Langley95c29f32014-06-20 12:00:00 -07009938 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009939
9940 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009941}
9942
9943func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009944 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009945 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009946 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009947
Adam Langley7c803a62015-06-15 15:35:05 -07009948 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009949 addCipherSuiteTests()
9950 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009951 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009952 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009953 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009954 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009955 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009956 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009957 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009958 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009959 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009960 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009961 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009962 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009963 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009964 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009965 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009966 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009967 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009968 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009969 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009970 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009971 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009972 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009973 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009974 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009975 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009976 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009977 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009978 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009979 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +09009980 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -08009981 addECDSAKeyUsageTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009982
9983 var wg sync.WaitGroup
9984
Adam Langley7c803a62015-06-15 15:35:05 -07009985 statusChan := make(chan statusMsg, *numWorkers)
9986 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009987 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009988
EKRf71d7ed2016-08-06 13:25:12 -07009989 if len(*shimConfigFile) != 0 {
9990 encoded, err := ioutil.ReadFile(*shimConfigFile)
9991 if err != nil {
9992 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9993 os.Exit(1)
9994 }
9995
9996 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9997 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9998 os.Exit(1)
9999 }
10000 }
10001
David Benjamin025b3d32014-07-01 19:53:04 -040010002 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010003
Adam Langley7c803a62015-06-15 15:35:05 -070010004 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010005 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010006 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010007 }
10008
David Benjamin270f0a72016-03-17 14:41:36 -040010009 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010010 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010011 matched := true
10012 if len(*testToRun) != 0 {
10013 var err error
10014 matched, err = filepath.Match(*testToRun, testCases[i].name)
10015 if err != nil {
10016 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10017 os.Exit(1)
10018 }
10019 }
10020
EKRf71d7ed2016-08-06 13:25:12 -070010021 if !*includeDisabled {
10022 for pattern := range shimConfig.DisabledTests {
10023 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10024 if err != nil {
10025 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10026 os.Exit(1)
10027 }
10028
10029 if isDisabled {
10030 matched = false
10031 break
10032 }
10033 }
10034 }
10035
David Benjamin17e12922016-07-28 18:04:43 -040010036 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010037 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010038 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010039
10040 // Only run one test if repeating until failure.
10041 if *repeatUntilFailure {
10042 break
10043 }
Adam Langley95c29f32014-06-20 12:00:00 -070010044 }
10045 }
David Benjamin17e12922016-07-28 18:04:43 -040010046
David Benjamin270f0a72016-03-17 14:41:36 -040010047 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010048 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010049 os.Exit(1)
10050 }
Adam Langley95c29f32014-06-20 12:00:00 -070010051
10052 close(testChan)
10053 wg.Wait()
10054 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010055 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010056
10057 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010058
10059 if *jsonOutput != "" {
10060 if err := testOutput.writeTo(*jsonOutput); err != nil {
10061 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10062 }
10063 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010064
EKR842ae6c2016-07-27 09:22:05 +020010065 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10066 os.Exit(1)
10067 }
10068
10069 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010070 os.Exit(1)
10071 }
Adam Langley95c29f32014-06-20 12:00:00 -070010072}