blob: d7bad5bf435085b934957a1ba7651151cfc0255e [file] [log] [blame]
Adam Langley7fcfd3b2016-05-20 11:02:50 -07001// Copyright (c) 2016, Google Inc.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
David Benjamin0d1b0962016-08-01 09:50:57 -040013// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Adam Langley7fcfd3b2016-05-20 11:02:50 -070014
Adam Langleydc7e9c42015-09-29 15:21:04 -070015package runner
Adam Langley95c29f32014-06-20 12:00:00 -070016
17import (
18 "bytes"
David Benjamina08e49d2014-08-24 01:46:07 -040019 "crypto/ecdsa"
20 "crypto/elliptic"
Adam Langleya4b91982016-12-12 12:05:53 -080021 "crypto/rand"
David Benjamin407a10c2014-07-16 12:58:59 -040022 "crypto/x509"
Adam Langleya4b91982016-12-12 12:05:53 -080023 "crypto/x509/pkix"
David Benjamin2561dc32014-08-24 01:25:27 -040024 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070025 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040026 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020027 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070028 "flag"
29 "fmt"
30 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070031 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070032 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070033 "net"
34 "os"
35 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040036 "path"
David Benjamin17e12922016-07-28 18:04:43 -040037 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040038 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080039 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070040 "strings"
41 "sync"
42 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050043 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070044)
45
Adam Langley69a01602014-11-17 17:26:55 -080046var (
EKR842ae6c2016-07-27 09:22:05 +020047 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
48 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
49 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
50 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
51 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
52 mallocTestDebug = flag.Bool("malloc-test-debug", false, "If true, ask bssl_shim to abort rather than fail a malloc. This can be used with a specific value for --malloc-test to identity the malloc failing that is causing problems.")
53 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
54 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040055 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020056 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
57 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
58 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
59 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
60 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
61 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
62 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
63 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020064 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070065 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
66 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
David Benjaminba28dfc2016-11-15 17:47:21 +090067 repeatUntilFailure = flag.Bool("repeat-until-failure", false, "If true, the first selected test will be run repeatedly until failure.")
Adam Langley69a01602014-11-17 17:26:55 -080068)
Adam Langley95c29f32014-06-20 12:00:00 -070069
EKRf71d7ed2016-08-06 13:25:12 -070070// ShimConfigurations is used with the “json” package and represents a shim
71// config file.
72type ShimConfiguration struct {
73 // DisabledTests maps from a glob-based pattern to a freeform string.
74 // The glob pattern is used to exclude tests from being run and the
75 // freeform string is unparsed but expected to explain why the test is
76 // disabled.
77 DisabledTests map[string]string
78
79 // ErrorMap maps from expected error strings to the correct error
80 // string for the shim in question. For example, it might map
81 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
82 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
83 ErrorMap map[string]string
84}
85
86var shimConfig ShimConfiguration
87
David Benjamin33863262016-07-08 17:20:12 -070088type testCert int
89
David Benjamin025b3d32014-07-01 19:53:04 -040090const (
David Benjamin33863262016-07-08 17:20:12 -070091 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040092 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090093 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070094 testCertECDSAP256
95 testCertECDSAP384
96 testCertECDSAP521
97)
98
99const (
100 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400101 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900102 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700103 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
104 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
105 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400106)
107
108const (
David Benjamina08e49d2014-08-24 01:46:07 -0400109 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400110 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900111 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700112 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
113 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
114 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400115 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400116)
117
David Benjamin7944a9f2016-07-12 22:27:01 -0400118var (
119 rsaCertificate Certificate
120 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900121 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400122 ecdsaP256Certificate Certificate
123 ecdsaP384Certificate Certificate
124 ecdsaP521Certificate Certificate
125)
David Benjamin33863262016-07-08 17:20:12 -0700126
127var testCerts = []struct {
128 id testCert
129 certFile, keyFile string
130 cert *Certificate
131}{
132 {
133 id: testCertRSA,
134 certFile: rsaCertificateFile,
135 keyFile: rsaKeyFile,
136 cert: &rsaCertificate,
137 },
138 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400139 id: testCertRSA1024,
140 certFile: rsa1024CertificateFile,
141 keyFile: rsa1024KeyFile,
142 cert: &rsa1024Certificate,
143 },
144 {
David Benjamin2c516452016-11-15 10:16:54 +0900145 id: testCertRSAChain,
146 certFile: rsaChainCertificateFile,
147 keyFile: rsaChainKeyFile,
148 cert: &rsaChainCertificate,
149 },
150 {
David Benjamin33863262016-07-08 17:20:12 -0700151 id: testCertECDSAP256,
152 certFile: ecdsaP256CertificateFile,
153 keyFile: ecdsaP256KeyFile,
154 cert: &ecdsaP256Certificate,
155 },
156 {
157 id: testCertECDSAP384,
158 certFile: ecdsaP384CertificateFile,
159 keyFile: ecdsaP384KeyFile,
160 cert: &ecdsaP384Certificate,
161 },
162 {
163 id: testCertECDSAP521,
164 certFile: ecdsaP521CertificateFile,
165 keyFile: ecdsaP521KeyFile,
166 cert: &ecdsaP521Certificate,
167 },
168}
169
David Benjamina08e49d2014-08-24 01:46:07 -0400170var channelIDKey *ecdsa.PrivateKey
171var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700172
David Benjamin61f95272014-11-25 01:55:35 -0500173var testOCSPResponse = []byte{1, 2, 3, 4}
Adam Langleycfa08c32016-11-17 13:21:27 -0800174var testSCTList = []byte{0, 6, 0, 4, 5, 6, 7, 8}
David Benjamin61f95272014-11-25 01:55:35 -0500175
Steven Valdeza833c352016-11-01 13:39:36 -0400176var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
Adam Langleycfa08c32016-11-17 13:21:27 -0800177var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, byte(len(testSCTList))}, testSCTList...)
Steven Valdeza833c352016-11-01 13:39:36 -0400178
Adam Langley95c29f32014-06-20 12:00:00 -0700179func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700180 for i := range testCerts {
181 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
182 if err != nil {
183 panic(err)
184 }
185 cert.OCSPStaple = testOCSPResponse
186 cert.SignedCertificateTimestampList = testSCTList
187 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700188 }
David Benjamina08e49d2014-08-24 01:46:07 -0400189
Adam Langley7c803a62015-06-15 15:35:05 -0700190 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400191 if err != nil {
192 panic(err)
193 }
194 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
195 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
196 panic("bad key type")
197 }
198 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
199 if err != nil {
200 panic(err)
201 }
202 if channelIDKey.Curve != elliptic.P256() {
203 panic("bad curve")
204 }
205
206 channelIDBytes = make([]byte, 64)
207 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
208 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700209}
210
David Benjamin33863262016-07-08 17:20:12 -0700211func getRunnerCertificate(t testCert) Certificate {
212 for _, cert := range testCerts {
213 if cert.id == t {
214 return *cert.cert
215 }
216 }
217 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700218}
219
David Benjamin33863262016-07-08 17:20:12 -0700220func getShimCertificate(t testCert) string {
221 for _, cert := range testCerts {
222 if cert.id == t {
223 return cert.certFile
224 }
225 }
226 panic("Unknown test certificate")
227}
228
229func getShimKey(t testCert) string {
230 for _, cert := range testCerts {
231 if cert.id == t {
232 return cert.keyFile
233 }
234 }
235 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700236}
237
David Benjamin025b3d32014-07-01 19:53:04 -0400238type testType int
239
240const (
241 clientTest testType = iota
242 serverTest
243)
244
David Benjamin6fd297b2014-08-11 18:43:38 -0400245type protocol int
246
247const (
248 tls protocol = iota
249 dtls
250)
251
David Benjaminfc7b0862014-09-06 13:21:53 -0400252const (
253 alpn = 1
254 npn = 2
255)
256
Adam Langley95c29f32014-06-20 12:00:00 -0700257type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400258 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400259 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700260 name string
261 config Config
262 shouldFail bool
263 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700264 // expectedLocalError, if not empty, contains a substring that must be
265 // found in the local error.
266 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400267 // expectedVersion, if non-zero, specifies the TLS version that must be
268 // negotiated.
269 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400270 // expectedResumeVersion, if non-zero, specifies the TLS version that
271 // must be negotiated on resumption. If zero, expectedVersion is used.
272 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400273 // expectedCipher, if non-zero, specifies the TLS cipher suite that
274 // should be negotiated.
275 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400276 // expectChannelID controls whether the connection should have
277 // negotiated a Channel ID with channelIDKey.
278 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400279 // expectedNextProto controls whether the connection should
280 // negotiate a next protocol via NPN or ALPN.
281 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400282 // expectNoNextProto, if true, means that no next protocol should be
283 // negotiated.
284 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400285 // expectedNextProtoType, if non-zero, is the expected next
286 // protocol negotiation mechanism.
287 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500288 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
289 // should be negotiated. If zero, none should be negotiated.
290 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100291 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
292 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100293 // expectedSCTList, if not nil, is the expected SCT list to be received.
294 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700295 // expectedPeerSignatureAlgorithm, if not zero, is the signature
296 // algorithm that the peer should have used in the handshake.
297 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400298 // expectedCurveID, if not zero, is the curve that the handshake should
299 // have used.
300 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700301 // messageLen is the length, in bytes, of the test message that will be
302 // sent.
303 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400304 // messageCount is the number of test messages that will be sent.
305 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400306 // certFile is the path to the certificate to use for the server.
307 certFile string
308 // keyFile is the path to the private key to use for the server.
309 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400310 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400311 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400312 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400313 // resumeRenewedSession controls whether a third connection should be
314 // tested which attempts to resume the second connection's session.
315 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700316 // expectResumeRejected, if true, specifies that the attempted
317 // resumption must be rejected by the client. This is only valid for a
318 // serverTest.
319 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400320 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500321 // resumption. Unless newSessionsOnResume is set,
322 // SessionTicketKey, ServerSessionCache, and
323 // ClientSessionCache are copied from the initial connection's
324 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400325 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500326 // newSessionsOnResume, if true, will cause resumeConfig to
327 // use a different session resumption context.
328 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400329 // noSessionCache, if true, will cause the server to run without a
330 // session cache.
331 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400332 // sendPrefix sends a prefix on the socket before actually performing a
333 // handshake.
334 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400335 // shimWritesFirst controls whether the shim sends an initial "hello"
336 // message before doing a roundtrip with the runner.
337 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400338 // shimShutsDown, if true, runs a test where the shim shuts down the
339 // connection immediately after the handshake rather than echoing
340 // messages from the runner.
341 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400342 // renegotiate indicates the number of times the connection should be
343 // renegotiated during the exchange.
344 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400345 // sendHalfHelloRequest, if true, causes the server to send half a
346 // HelloRequest when the handshake completes.
347 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700348 // renegotiateCiphers is a list of ciphersuite ids that will be
349 // switched in just before renegotiation.
350 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500351 // replayWrites, if true, configures the underlying transport
352 // to replay every write it makes in DTLS tests.
353 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500354 // damageFirstWrite, if true, configures the underlying transport to
355 // damage the final byte of the first application data write.
356 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400357 // exportKeyingMaterial, if non-zero, configures the test to exchange
358 // keying material and verify they match.
359 exportKeyingMaterial int
360 exportLabel string
361 exportContext string
362 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400363 // flags, if not empty, contains a list of command-line flags that will
364 // be passed to the shim program.
365 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700366 // testTLSUnique, if true, causes the shim to send the tls-unique value
367 // which will be compared against the expected value.
368 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400369 // sendEmptyRecords is the number of consecutive empty records to send
370 // before and after the test message.
371 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400372 // sendWarningAlerts is the number of consecutive warning alerts to send
373 // before and after the test message.
374 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400375 // sendKeyUpdates is the number of consecutive key updates to send
376 // before and after the test message.
377 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400378 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
379 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400380 // expectMessageDropped, if true, means the test message is expected to
381 // be dropped by the client rather than echoed back.
382 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900383 // expectPeerCertificate, if not nil, is the certificate chain the peer
384 // is expected to send.
385 expectPeerCertificate *Certificate
David Benjamin6f600d62016-12-21 16:06:54 -0500386 // expectShortHeader is whether the short header extension should be negotiated.
387 expectShortHeader bool
Adam Langley95c29f32014-06-20 12:00:00 -0700388}
389
Adam Langley7c803a62015-06-15 15:35:05 -0700390var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700391
David Benjaminc07afb72016-09-22 10:18:58 -0400392func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500393 if len(data) == 0 {
394 return
395 }
396
397 protocol := "tls"
398 if test.protocol == dtls {
399 protocol = "dtls"
400 }
401
402 side := "client"
403 if test.testType == serverTest {
404 side = "server"
405 }
406
407 dir := path.Join(*transcriptDir, protocol, side)
408 if err := os.MkdirAll(dir, 0755); err != nil {
409 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
410 return
411 }
412
David Benjaminc07afb72016-09-22 10:18:58 -0400413 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500414 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
415 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
416 }
417}
418
David Benjamin3ed59772016-03-08 12:50:21 -0500419// A timeoutConn implements an idle timeout on each Read and Write operation.
420type timeoutConn struct {
421 net.Conn
422 timeout time.Duration
423}
424
425func (t *timeoutConn) Read(b []byte) (int, error) {
426 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
427 return 0, err
428 }
429 return t.Conn.Read(b)
430}
431
432func (t *timeoutConn) Write(b []byte) (int, error) {
433 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
434 return 0, err
435 }
436 return t.Conn.Write(b)
437}
438
David Benjaminc07afb72016-09-22 10:18:58 -0400439func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400440 if !test.noSessionCache {
441 if config.ClientSessionCache == nil {
442 config.ClientSessionCache = NewLRUClientSessionCache(1)
443 }
444 if config.ServerSessionCache == nil {
445 config.ServerSessionCache = NewLRUServerSessionCache(1)
446 }
447 }
448 if test.testType == clientTest {
449 if len(config.Certificates) == 0 {
450 config.Certificates = []Certificate{rsaCertificate}
451 }
452 } else {
453 // Supply a ServerName to ensure a constant session cache key,
454 // rather than falling back to net.Conn.RemoteAddr.
455 if len(config.ServerName) == 0 {
456 config.ServerName = "test"
457 }
458 }
459 if *fuzzer {
460 config.Bugs.NullAllCiphers = true
461 }
David Benjamin01a90572016-09-22 00:11:43 -0400462 if *deterministic {
463 config.Time = func() time.Time { return time.Unix(1234, 1234) }
464 }
David Benjamine54af062016-08-08 19:21:18 -0400465
David Benjamin01784b42016-06-07 18:00:52 -0400466 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500467
David Benjamin6fd297b2014-08-11 18:43:38 -0400468 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500469 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
470 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500471 }
472
David Benjamin9867b7d2016-03-01 23:25:48 -0500473 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500474 local, peer := "client", "server"
475 if test.testType == clientTest {
476 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500477 }
David Benjaminebda9b32015-11-02 15:33:18 -0500478 connDebug := &recordingConn{
479 Conn: conn,
480 isDatagram: test.protocol == dtls,
481 local: local,
482 peer: peer,
483 }
484 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500485 if *flagDebug {
486 defer connDebug.WriteTo(os.Stdout)
487 }
488 if len(*transcriptDir) != 0 {
489 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400490 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500491 }()
492 }
David Benjaminebda9b32015-11-02 15:33:18 -0500493
494 if config.Bugs.PacketAdaptor != nil {
495 config.Bugs.PacketAdaptor.debug = connDebug
496 }
497 }
498
499 if test.replayWrites {
500 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 }
502
David Benjamin3ed59772016-03-08 12:50:21 -0500503 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500504 if test.damageFirstWrite {
505 connDamage = newDamageAdaptor(conn)
506 conn = connDamage
507 }
508
David Benjamin6fd297b2014-08-11 18:43:38 -0400509 if test.sendPrefix != "" {
510 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
511 return err
512 }
David Benjamin98e882e2014-08-08 13:24:34 -0400513 }
514
David Benjamin1d5c83e2014-07-22 19:20:02 -0400515 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400516 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400517 if test.protocol == dtls {
518 tlsConn = DTLSServer(conn, config)
519 } else {
520 tlsConn = Server(conn, config)
521 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400522 } else {
523 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400524 if test.protocol == dtls {
525 tlsConn = DTLSClient(conn, config)
526 } else {
527 tlsConn = Client(conn, config)
528 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400529 }
David Benjamin30789da2015-08-29 22:56:45 -0400530 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400531
Adam Langley95c29f32014-06-20 12:00:00 -0700532 if err := tlsConn.Handshake(); err != nil {
533 return err
534 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700535
David Benjamin01fe8202014-09-24 15:21:44 -0400536 // TODO(davidben): move all per-connection expectations into a dedicated
537 // expectations struct that can be specified separately for the two
538 // legs.
539 expectedVersion := test.expectedVersion
540 if isResume && test.expectedResumeVersion != 0 {
541 expectedVersion = test.expectedResumeVersion
542 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700543 connState := tlsConn.ConnectionState()
544 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400545 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400546 }
547
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700548 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400549 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
550 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700551 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
552 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
553 }
David Benjamin90da8c82015-04-20 14:57:57 -0400554
David Benjamina08e49d2014-08-24 01:46:07 -0400555 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700556 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400557 if channelID == nil {
558 return fmt.Errorf("no channel ID negotiated")
559 }
560 if channelID.Curve != channelIDKey.Curve ||
561 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
562 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
563 return fmt.Errorf("incorrect channel ID")
564 }
565 }
566
David Benjaminae2888f2014-09-06 12:58:58 -0400567 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700568 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400569 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
570 }
571 }
572
David Benjaminc7ce9772015-10-09 19:32:41 -0400573 if test.expectNoNextProto {
574 if actual := connState.NegotiatedProtocol; actual != "" {
575 return fmt.Errorf("got unexpected next proto %s", actual)
576 }
577 }
578
David Benjaminfc7b0862014-09-06 13:21:53 -0400579 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700580 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400581 return fmt.Errorf("next proto type mismatch")
582 }
583 }
584
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700585 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500586 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
587 }
588
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100589 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300590 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100591 }
592
Paul Lietar4fac72e2015-09-09 13:44:55 +0100593 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
594 return fmt.Errorf("SCT list mismatch")
595 }
596
Nick Harper60edffd2016-06-21 15:19:24 -0700597 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
598 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400599 }
600
Steven Valdez5440fe02016-07-18 12:40:30 -0400601 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
602 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
603 }
604
David Benjamin2c516452016-11-15 10:16:54 +0900605 if test.expectPeerCertificate != nil {
606 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
607 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
608 }
609 for i, cert := range connState.PeerCertificates {
610 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
611 return fmt.Errorf("peer certificate %d did not match", i+1)
612 }
613 }
614 }
615
David Benjamin6f600d62016-12-21 16:06:54 -0500616 if test.expectShortHeader != connState.ShortHeader {
617 return fmt.Errorf("ShortHeader is %t, but we expected the opposite", connState.ShortHeader)
618 }
619
David Benjaminc565ebb2015-04-03 04:06:36 -0400620 if test.exportKeyingMaterial > 0 {
621 actual := make([]byte, test.exportKeyingMaterial)
622 if _, err := io.ReadFull(tlsConn, actual); err != nil {
623 return err
624 }
625 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
626 if err != nil {
627 return err
628 }
629 if !bytes.Equal(actual, expected) {
630 return fmt.Errorf("keying material mismatch")
631 }
632 }
633
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700634 if test.testTLSUnique {
635 var peersValue [12]byte
636 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
637 return err
638 }
639 expected := tlsConn.ConnectionState().TLSUnique
640 if !bytes.Equal(peersValue[:], expected) {
641 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
642 }
643 }
644
David Benjamine58c4f52014-08-24 03:47:07 -0400645 if test.shimWritesFirst {
646 var buf [5]byte
647 _, err := io.ReadFull(tlsConn, buf[:])
648 if err != nil {
649 return err
650 }
651 if string(buf[:]) != "hello" {
652 return fmt.Errorf("bad initial message")
653 }
654 }
655
Steven Valdez32635b82016-08-16 11:25:03 -0400656 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400657 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400658 return err
659 }
Steven Valdez32635b82016-08-16 11:25:03 -0400660 }
661
David Benjamina8ebe222015-06-06 03:04:39 -0400662 for i := 0; i < test.sendEmptyRecords; i++ {
663 tlsConn.Write(nil)
664 }
665
David Benjamin24f346d2015-06-06 03:28:08 -0400666 for i := 0; i < test.sendWarningAlerts; i++ {
667 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
668 }
669
David Benjamin47921102016-07-28 11:29:18 -0400670 if test.sendHalfHelloRequest {
671 tlsConn.SendHalfHelloRequest()
672 }
673
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400674 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700675 if test.renegotiateCiphers != nil {
676 config.CipherSuites = test.renegotiateCiphers
677 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400678 for i := 0; i < test.renegotiate; i++ {
679 if err := tlsConn.Renegotiate(); err != nil {
680 return err
681 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700682 }
683 } else if test.renegotiateCiphers != nil {
684 panic("renegotiateCiphers without renegotiate")
685 }
686
David Benjamin5fa3eba2015-01-22 16:35:40 -0500687 if test.damageFirstWrite {
688 connDamage.setDamage(true)
689 tlsConn.Write([]byte("DAMAGED WRITE"))
690 connDamage.setDamage(false)
691 }
692
David Benjamin8e6db492015-07-25 18:29:23 -0400693 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700694 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400695 if test.protocol == dtls {
696 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
697 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700698 // Read until EOF.
699 _, err := io.Copy(ioutil.Discard, tlsConn)
700 return err
701 }
David Benjamin4417d052015-04-05 04:17:25 -0400702 if messageLen == 0 {
703 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700704 }
Adam Langley95c29f32014-06-20 12:00:00 -0700705
David Benjamin8e6db492015-07-25 18:29:23 -0400706 messageCount := test.messageCount
707 if messageCount == 0 {
708 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400709 }
710
David Benjamin8e6db492015-07-25 18:29:23 -0400711 for j := 0; j < messageCount; j++ {
712 testMessage := make([]byte, messageLen)
713 for i := range testMessage {
714 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400715 }
David Benjamin8e6db492015-07-25 18:29:23 -0400716 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700717
Steven Valdez32635b82016-08-16 11:25:03 -0400718 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400719 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400720 }
721
David Benjamin8e6db492015-07-25 18:29:23 -0400722 for i := 0; i < test.sendEmptyRecords; i++ {
723 tlsConn.Write(nil)
724 }
725
726 for i := 0; i < test.sendWarningAlerts; i++ {
727 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
728 }
729
David Benjamin4f75aaf2015-09-01 16:53:10 -0400730 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400731 // The shim will not respond.
732 continue
733 }
734
David Benjamin8e6db492015-07-25 18:29:23 -0400735 buf := make([]byte, len(testMessage))
736 if test.protocol == dtls {
737 bufTmp := make([]byte, len(buf)+1)
738 n, err := tlsConn.Read(bufTmp)
739 if err != nil {
740 return err
741 }
742 if n != len(buf) {
743 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
744 }
745 copy(buf, bufTmp)
746 } else {
747 _, err := io.ReadFull(tlsConn, buf)
748 if err != nil {
749 return err
750 }
751 }
752
753 for i, v := range buf {
754 if v != testMessage[i]^0xff {
755 return fmt.Errorf("bad reply contents at byte %d", i)
756 }
Adam Langley95c29f32014-06-20 12:00:00 -0700757 }
758 }
759
760 return nil
761}
762
David Benjamin325b5c32014-07-01 19:40:31 -0400763func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400764 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700765 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400766 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700767 }
David Benjamin325b5c32014-07-01 19:40:31 -0400768 valgrindArgs = append(valgrindArgs, path)
769 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700770
David Benjamin325b5c32014-07-01 19:40:31 -0400771 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700772}
773
David Benjamin325b5c32014-07-01 19:40:31 -0400774func gdbOf(path string, args ...string) *exec.Cmd {
775 xtermArgs := []string{"-e", "gdb", "--args"}
776 xtermArgs = append(xtermArgs, path)
777 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700778
David Benjamin325b5c32014-07-01 19:40:31 -0400779 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700780}
781
David Benjamind16bf342015-12-18 00:53:12 -0500782func lldbOf(path string, args ...string) *exec.Cmd {
783 xtermArgs := []string{"-e", "lldb", "--"}
784 xtermArgs = append(xtermArgs, path)
785 xtermArgs = append(xtermArgs, args...)
786
787 return exec.Command("xterm", xtermArgs...)
788}
789
EKR842ae6c2016-07-27 09:22:05 +0200790var (
791 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
792 errUnimplemented = errors.New("child process does not implement needed flags")
793)
Adam Langley69a01602014-11-17 17:26:55 -0800794
David Benjamin87c8a642015-02-21 01:54:29 -0500795// accept accepts a connection from listener, unless waitChan signals a process
796// exit first.
797func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
798 type connOrError struct {
799 conn net.Conn
800 err error
801 }
802 connChan := make(chan connOrError, 1)
803 go func() {
804 conn, err := listener.Accept()
805 connChan <- connOrError{conn, err}
806 close(connChan)
807 }()
808 select {
809 case result := <-connChan:
810 return result.conn, result.err
811 case childErr := <-waitChan:
812 waitChan <- childErr
813 return nil, fmt.Errorf("child exited early: %s", childErr)
814 }
815}
816
EKRf71d7ed2016-08-06 13:25:12 -0700817func translateExpectedError(errorStr string) string {
818 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
819 return translated
820 }
821
822 if *looseErrors {
823 return ""
824 }
825
826 return errorStr
827}
828
Adam Langley7c803a62015-06-15 15:35:05 -0700829func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400830 // Help debugging panics on the Go side.
831 defer func() {
832 if r := recover(); r != nil {
833 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
834 panic(r)
835 }
836 }()
837
Adam Langley38311732014-10-16 19:04:35 -0700838 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
839 panic("Error expected without shouldFail in " + test.name)
840 }
841
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700842 if test.expectResumeRejected && !test.resumeSession {
843 panic("expectResumeRejected without resumeSession in " + test.name)
844 }
845
Adam Langley33b1d4f2016-12-07 15:03:45 -0800846 for _, ver := range tlsVersions {
847 if !strings.Contains("-"+test.name+"-", "-"+ver.name+"-") {
848 continue
849 }
850
851 if test.config.MaxVersion != 0 || test.config.MinVersion != 0 || test.expectedVersion != 0 {
852 continue
853 }
854
855 panic(fmt.Sprintf("The name of test %q suggests that it's version specific, but min/max version in the Config is %x/%x. One of them should probably be %x", test.name, test.config.MinVersion, test.config.MaxVersion, ver.version))
856 }
857
David Benjamin87c8a642015-02-21 01:54:29 -0500858 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
859 if err != nil {
860 panic(err)
861 }
862 defer func() {
863 if listener != nil {
864 listener.Close()
865 }
866 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700867
David Benjamin87c8a642015-02-21 01:54:29 -0500868 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400869 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400870 flags = append(flags, "-server")
871
David Benjamin025b3d32014-07-01 19:53:04 -0400872 flags = append(flags, "-key-file")
873 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700874 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400875 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700876 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400877 }
878
879 flags = append(flags, "-cert-file")
880 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700881 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400882 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400884 }
885 }
David Benjamin5a593af2014-08-11 19:51:50 -0400886
David Benjamin6fd297b2014-08-11 18:43:38 -0400887 if test.protocol == dtls {
888 flags = append(flags, "-dtls")
889 }
890
David Benjamin46662482016-08-17 00:51:00 -0400891 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400892 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400893 resumeCount++
894 if test.resumeRenewedSession {
895 resumeCount++
896 }
897 }
898
899 if resumeCount > 0 {
900 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400901 }
902
David Benjamine58c4f52014-08-24 03:47:07 -0400903 if test.shimWritesFirst {
904 flags = append(flags, "-shim-writes-first")
905 }
906
David Benjamin30789da2015-08-29 22:56:45 -0400907 if test.shimShutsDown {
908 flags = append(flags, "-shim-shuts-down")
909 }
910
David Benjaminc565ebb2015-04-03 04:06:36 -0400911 if test.exportKeyingMaterial > 0 {
912 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
913 flags = append(flags, "-export-label", test.exportLabel)
914 flags = append(flags, "-export-context", test.exportContext)
915 if test.useExportContext {
916 flags = append(flags, "-use-export-context")
917 }
918 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700919 if test.expectResumeRejected {
920 flags = append(flags, "-expect-session-miss")
921 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400922
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700923 if test.testTLSUnique {
924 flags = append(flags, "-tls-unique")
925 }
926
David Benjamin025b3d32014-07-01 19:53:04 -0400927 flags = append(flags, test.flags...)
928
929 var shim *exec.Cmd
930 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700931 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700932 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700933 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500934 } else if *useLLDB {
935 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400936 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700937 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400938 }
David Benjamin025b3d32014-07-01 19:53:04 -0400939 shim.Stdin = os.Stdin
940 var stdoutBuf, stderrBuf bytes.Buffer
941 shim.Stdout = &stdoutBuf
942 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800943 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500944 shim.Env = os.Environ()
945 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800946 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400947 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800948 }
949 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
950 }
David Benjamin025b3d32014-07-01 19:53:04 -0400951
952 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700953 panic(err)
954 }
David Benjamin87c8a642015-02-21 01:54:29 -0500955 waitChan := make(chan error, 1)
956 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700957
958 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700959
David Benjamin7a4aaa42016-09-20 17:58:14 -0400960 if *deterministic {
961 config.Rand = &deterministicRand{}
962 }
963
David Benjamin87c8a642015-02-21 01:54:29 -0500964 conn, err := acceptOrWait(listener, waitChan)
965 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400966 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500967 conn.Close()
968 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500969
David Benjamin46662482016-08-17 00:51:00 -0400970 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400971 var resumeConfig Config
972 if test.resumeConfig != nil {
973 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400974 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500975 resumeConfig.SessionTicketKey = config.SessionTicketKey
976 resumeConfig.ClientSessionCache = config.ClientSessionCache
977 resumeConfig.ServerSessionCache = config.ServerSessionCache
978 }
David Benjamin2e045a92016-06-08 13:09:56 -0400979 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400980 } else {
981 resumeConfig = config
982 }
David Benjamin87c8a642015-02-21 01:54:29 -0500983 var connResume net.Conn
984 connResume, err = acceptOrWait(listener, waitChan)
985 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400986 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500987 connResume.Close()
988 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400989 }
990
David Benjamin87c8a642015-02-21 01:54:29 -0500991 // Close the listener now. This is to avoid hangs should the shim try to
992 // open more connections than expected.
993 listener.Close()
994 listener = nil
995
996 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400997 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800998 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200999 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
1000 case 88:
Adam Langley69a01602014-11-17 17:26:55 -08001001 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +02001002 case 89:
1003 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -04001004 case 99:
1005 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -08001006 }
1007 }
Adam Langley95c29f32014-06-20 12:00:00 -07001008
David Benjamin9bea3492016-03-02 10:59:16 -05001009 // Account for Windows line endings.
1010 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
1011 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -05001012
1013 // Separate the errors from the shim and those from tools like
1014 // AddressSanitizer.
1015 var extraStderr string
1016 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
1017 stderr = stderrParts[0]
1018 extraStderr = stderrParts[1]
1019 }
1020
Adam Langley95c29f32014-06-20 12:00:00 -07001021 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001022 expectedError := translateExpectedError(test.expectedError)
1023 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001024
Adam Langleyac61fa32014-06-23 12:03:11 -07001025 localError := "none"
1026 if err != nil {
1027 localError = err.Error()
1028 }
1029 if len(test.expectedLocalError) != 0 {
1030 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1031 }
Adam Langley95c29f32014-06-20 12:00:00 -07001032
1033 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001034 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001035 if childErr != nil {
1036 childError = childErr.Error()
1037 }
1038
1039 var msg string
1040 switch {
1041 case failed && !test.shouldFail:
1042 msg = "unexpected failure"
1043 case !failed && test.shouldFail:
1044 msg = "unexpected success"
1045 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001046 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001047 default:
1048 panic("internal error")
1049 }
1050
David Benjamin9aafb642016-09-20 19:36:53 -04001051 return fmt.Errorf("%s: local error '%s', child error '%s', stdout:\n%s\nstderr:\n%s\n%s", msg, localError, childError, stdout, stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001052 }
1053
David Benjamind2ba8892016-09-20 19:41:04 -04001054 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001055 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001056 }
1057
David Benjamind2ba8892016-09-20 19:41:04 -04001058 if *useValgrind && isValgrindError {
1059 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1060 }
1061
Adam Langley95c29f32014-06-20 12:00:00 -07001062 return nil
1063}
1064
David Benjaminaa012042016-12-10 13:33:05 -05001065type tlsVersion struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001066 name string
1067 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001068 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001069 hasDTLS bool
David Benjaminaa012042016-12-10 13:33:05 -05001070}
1071
1072var tlsVersions = []tlsVersion{
David Benjamin8b8c0062014-11-23 02:47:52 -05001073 {"SSL3", VersionSSL30, "-no-ssl3", false},
1074 {"TLS1", VersionTLS10, "-no-tls1", true},
1075 {"TLS11", VersionTLS11, "-no-tls11", false},
1076 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001077 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001078}
1079
David Benjaminaa012042016-12-10 13:33:05 -05001080type testCipherSuite struct {
Adam Langley95c29f32014-06-20 12:00:00 -07001081 name string
1082 id uint16
David Benjaminaa012042016-12-10 13:33:05 -05001083}
1084
1085var testCipherSuites = []testCipherSuite{
Adam Langley95c29f32014-06-20 12:00:00 -07001086 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001087 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001088 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001089 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001090 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001091 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001092 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001093 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1094 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001095 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001096 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1097 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001098 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001099 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1100 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001101 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1102 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001103 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001104 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001105 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001106 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001107 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001108 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001109 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001110 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001111 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001112 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamin48cae082014-10-27 01:06:24 -04001113 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1114 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001115 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1116 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001117 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001118 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1119 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1120 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001121 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001122}
1123
David Benjamin8b8c0062014-11-23 02:47:52 -05001124func hasComponent(suiteName, component string) bool {
1125 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1126}
1127
David Benjaminf7768e42014-08-31 02:06:47 -04001128func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001129 return hasComponent(suiteName, "GCM") ||
1130 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001131 hasComponent(suiteName, "SHA384") ||
1132 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001133}
1134
Nick Harper1fd39d82016-06-14 18:14:35 -07001135func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001136 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001137}
1138
David Benjamin8b8c0062014-11-23 02:47:52 -05001139func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001140 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001141}
1142
Adam Langleya7997f12015-05-14 17:38:50 -07001143func bigFromHex(hex string) *big.Int {
1144 ret, ok := new(big.Int).SetString(hex, 16)
1145 if !ok {
1146 panic("failed to parse hex number 0x" + hex)
1147 }
1148 return ret
1149}
1150
Adam Langley7c803a62015-06-15 15:35:05 -07001151func addBasicTests() {
1152 basicTests := []testCase{
1153 {
Adam Langley7c803a62015-06-15 15:35:05 -07001154 name: "NoFallbackSCSV",
1155 config: Config{
1156 Bugs: ProtocolBugs{
1157 FailIfNotFallbackSCSV: true,
1158 },
1159 },
1160 shouldFail: true,
1161 expectedLocalError: "no fallback SCSV found",
1162 },
1163 {
1164 name: "SendFallbackSCSV",
1165 config: Config{
1166 Bugs: ProtocolBugs{
1167 FailIfNotFallbackSCSV: true,
1168 },
1169 },
1170 flags: []string{"-fallback-scsv"},
1171 },
1172 {
1173 name: "ClientCertificateTypes",
1174 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001175 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001176 ClientAuth: RequestClientCert,
1177 ClientCertificateTypes: []byte{
1178 CertTypeDSSSign,
1179 CertTypeRSASign,
1180 CertTypeECDSASign,
1181 },
1182 },
1183 flags: []string{
1184 "-expect-certificate-types",
1185 base64.StdEncoding.EncodeToString([]byte{
1186 CertTypeDSSSign,
1187 CertTypeRSASign,
1188 CertTypeECDSASign,
1189 }),
1190 },
1191 },
1192 {
Adam Langley7c803a62015-06-15 15:35:05 -07001193 name: "UnauthenticatedECDH",
1194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001195 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1197 Bugs: ProtocolBugs{
1198 UnauthenticatedECDH: true,
1199 },
1200 },
1201 shouldFail: true,
1202 expectedError: ":UNEXPECTED_MESSAGE:",
1203 },
1204 {
1205 name: "SkipCertificateStatus",
1206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001207 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001208 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1209 Bugs: ProtocolBugs{
1210 SkipCertificateStatus: true,
1211 },
1212 },
1213 flags: []string{
1214 "-enable-ocsp-stapling",
1215 },
1216 },
1217 {
1218 name: "SkipServerKeyExchange",
1219 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001220 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001221 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1222 Bugs: ProtocolBugs{
1223 SkipServerKeyExchange: true,
1224 },
1225 },
1226 shouldFail: true,
1227 expectedError: ":UNEXPECTED_MESSAGE:",
1228 },
1229 {
Adam Langley7c803a62015-06-15 15:35:05 -07001230 testType: serverTest,
1231 name: "Alert",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 SendSpuriousAlert: alertRecordOverflow,
1235 },
1236 },
1237 shouldFail: true,
1238 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1239 },
1240 {
1241 protocol: dtls,
1242 testType: serverTest,
1243 name: "Alert-DTLS",
1244 config: Config{
1245 Bugs: ProtocolBugs{
1246 SendSpuriousAlert: alertRecordOverflow,
1247 },
1248 },
1249 shouldFail: true,
1250 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1251 },
1252 {
1253 testType: serverTest,
1254 name: "FragmentAlert",
1255 config: Config{
1256 Bugs: ProtocolBugs{
1257 FragmentAlert: true,
1258 SendSpuriousAlert: alertRecordOverflow,
1259 },
1260 },
1261 shouldFail: true,
1262 expectedError: ":BAD_ALERT:",
1263 },
1264 {
1265 protocol: dtls,
1266 testType: serverTest,
1267 name: "FragmentAlert-DTLS",
1268 config: Config{
1269 Bugs: ProtocolBugs{
1270 FragmentAlert: true,
1271 SendSpuriousAlert: alertRecordOverflow,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":BAD_ALERT:",
1276 },
1277 {
1278 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001279 name: "DoubleAlert",
1280 config: Config{
1281 Bugs: ProtocolBugs{
1282 DoubleAlert: true,
1283 SendSpuriousAlert: alertRecordOverflow,
1284 },
1285 },
1286 shouldFail: true,
1287 expectedError: ":BAD_ALERT:",
1288 },
1289 {
1290 protocol: dtls,
1291 testType: serverTest,
1292 name: "DoubleAlert-DTLS",
1293 config: Config{
1294 Bugs: ProtocolBugs{
1295 DoubleAlert: true,
1296 SendSpuriousAlert: alertRecordOverflow,
1297 },
1298 },
1299 shouldFail: true,
1300 expectedError: ":BAD_ALERT:",
1301 },
1302 {
Adam Langley7c803a62015-06-15 15:35:05 -07001303 name: "SkipNewSessionTicket",
1304 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001305 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001306 Bugs: ProtocolBugs{
1307 SkipNewSessionTicket: true,
1308 },
1309 },
1310 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001311 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001312 },
1313 {
1314 testType: serverTest,
1315 name: "FallbackSCSV",
1316 config: Config{
1317 MaxVersion: VersionTLS11,
1318 Bugs: ProtocolBugs{
1319 SendFallbackSCSV: true,
1320 },
1321 },
David Benjamin56cadc32016-12-16 19:54:11 -05001322 shouldFail: true,
1323 expectedError: ":INAPPROPRIATE_FALLBACK:",
1324 expectedLocalError: "remote error: inappropriate fallback",
Adam Langley7c803a62015-06-15 15:35:05 -07001325 },
1326 {
1327 testType: serverTest,
David Benjaminb442dee2016-12-19 22:15:08 -05001328 name: "FallbackSCSV-VersionMatch-TLS13",
Adam Langley7c803a62015-06-15 15:35:05 -07001329 config: Config{
David Benjaminb442dee2016-12-19 22:15:08 -05001330 MaxVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001331 Bugs: ProtocolBugs{
1332 SendFallbackSCSV: true,
1333 },
1334 },
1335 },
1336 {
1337 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001338 name: "FallbackSCSV-VersionMatch-TLS12",
1339 config: Config{
1340 MaxVersion: VersionTLS12,
1341 Bugs: ProtocolBugs{
1342 SendFallbackSCSV: true,
1343 },
1344 },
1345 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1346 },
1347 {
1348 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001349 name: "FragmentedClientVersion",
1350 config: Config{
1351 Bugs: ProtocolBugs{
1352 MaxHandshakeRecordLength: 1,
1353 FragmentClientVersion: true,
1354 },
1355 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001356 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001357 },
1358 {
Adam Langley7c803a62015-06-15 15:35:05 -07001359 testType: serverTest,
1360 name: "HttpGET",
1361 sendPrefix: "GET / HTTP/1.0\n",
1362 shouldFail: true,
1363 expectedError: ":HTTP_REQUEST:",
1364 },
1365 {
1366 testType: serverTest,
1367 name: "HttpPOST",
1368 sendPrefix: "POST / HTTP/1.0\n",
1369 shouldFail: true,
1370 expectedError: ":HTTP_REQUEST:",
1371 },
1372 {
1373 testType: serverTest,
1374 name: "HttpHEAD",
1375 sendPrefix: "HEAD / HTTP/1.0\n",
1376 shouldFail: true,
1377 expectedError: ":HTTP_REQUEST:",
1378 },
1379 {
1380 testType: serverTest,
1381 name: "HttpPUT",
1382 sendPrefix: "PUT / HTTP/1.0\n",
1383 shouldFail: true,
1384 expectedError: ":HTTP_REQUEST:",
1385 },
1386 {
1387 testType: serverTest,
1388 name: "HttpCONNECT",
1389 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1390 shouldFail: true,
1391 expectedError: ":HTTPS_PROXY_REQUEST:",
1392 },
1393 {
1394 testType: serverTest,
1395 name: "Garbage",
1396 sendPrefix: "blah",
1397 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001398 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001399 },
1400 {
Adam Langley7c803a62015-06-15 15:35:05 -07001401 name: "RSAEphemeralKey",
1402 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001403 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001404 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1405 Bugs: ProtocolBugs{
1406 RSAEphemeralKey: true,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedError: ":UNEXPECTED_MESSAGE:",
1411 },
1412 {
1413 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001414 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001415 shouldFail: true,
1416 expectedError: ":WRONG_SSL_VERSION:",
1417 },
1418 {
1419 protocol: dtls,
1420 name: "DisableEverything-DTLS",
1421 flags: []string{"-no-tls12", "-no-tls1"},
1422 shouldFail: true,
1423 expectedError: ":WRONG_SSL_VERSION:",
1424 },
1425 {
Adam Langley7c803a62015-06-15 15:35:05 -07001426 protocol: dtls,
1427 testType: serverTest,
1428 name: "MTU",
1429 config: Config{
1430 Bugs: ProtocolBugs{
1431 MaxPacketLength: 256,
1432 },
1433 },
1434 flags: []string{"-mtu", "256"},
1435 },
1436 {
1437 protocol: dtls,
1438 testType: serverTest,
1439 name: "MTUExceeded",
1440 config: Config{
1441 Bugs: ProtocolBugs{
1442 MaxPacketLength: 255,
1443 },
1444 },
1445 flags: []string{"-mtu", "256"},
1446 shouldFail: true,
1447 expectedLocalError: "dtls: exceeded maximum packet length",
1448 },
1449 {
1450 name: "CertMismatchRSA",
1451 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001452 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001453 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001454 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001455 Bugs: ProtocolBugs{
1456 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1457 },
1458 },
1459 shouldFail: true,
1460 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1461 },
1462 {
1463 name: "CertMismatchECDSA",
1464 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001465 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001466 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001467 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001468 Bugs: ProtocolBugs{
1469 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1470 },
1471 },
1472 shouldFail: true,
1473 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1474 },
1475 {
1476 name: "EmptyCertificateList",
1477 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001478 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001479 Bugs: ProtocolBugs{
1480 EmptyCertificateList: true,
1481 },
1482 },
1483 shouldFail: true,
1484 expectedError: ":DECODE_ERROR:",
1485 },
1486 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001487 name: "EmptyCertificateList-TLS13",
1488 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001489 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001490 Bugs: ProtocolBugs{
1491 EmptyCertificateList: true,
1492 },
1493 },
1494 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001495 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001496 },
1497 {
Adam Langley7c803a62015-06-15 15:35:05 -07001498 name: "TLSFatalBadPackets",
1499 damageFirstWrite: true,
1500 shouldFail: true,
1501 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1502 },
1503 {
1504 protocol: dtls,
1505 name: "DTLSIgnoreBadPackets",
1506 damageFirstWrite: true,
1507 },
1508 {
1509 protocol: dtls,
1510 name: "DTLSIgnoreBadPackets-Async",
1511 damageFirstWrite: true,
1512 flags: []string{"-async"},
1513 },
1514 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001515 name: "AppDataBeforeHandshake",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":UNEXPECTED_RECORD:",
1523 },
1524 {
1525 name: "AppDataBeforeHandshake-Empty",
1526 config: Config{
1527 Bugs: ProtocolBugs{
1528 AppDataBeforeHandshake: []byte{},
1529 },
1530 },
1531 shouldFail: true,
1532 expectedError: ":UNEXPECTED_RECORD:",
1533 },
1534 {
1535 protocol: dtls,
1536 name: "AppDataBeforeHandshake-DTLS",
1537 config: Config{
1538 Bugs: ProtocolBugs{
1539 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1540 },
1541 },
1542 shouldFail: true,
1543 expectedError: ":UNEXPECTED_RECORD:",
1544 },
1545 {
1546 protocol: dtls,
1547 name: "AppDataBeforeHandshake-DTLS-Empty",
1548 config: Config{
1549 Bugs: ProtocolBugs{
1550 AppDataBeforeHandshake: []byte{},
1551 },
1552 },
1553 shouldFail: true,
1554 expectedError: ":UNEXPECTED_RECORD:",
1555 },
1556 {
Adam Langley7c803a62015-06-15 15:35:05 -07001557 name: "AppDataAfterChangeCipherSpec",
1558 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001559 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001560 Bugs: ProtocolBugs{
1561 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1562 },
1563 },
1564 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001565 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001566 },
1567 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001568 name: "AppDataAfterChangeCipherSpec-Empty",
1569 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001570 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001571 Bugs: ProtocolBugs{
1572 AppDataAfterChangeCipherSpec: []byte{},
1573 },
1574 },
1575 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001576 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001577 },
1578 {
Adam Langley7c803a62015-06-15 15:35:05 -07001579 protocol: dtls,
1580 name: "AppDataAfterChangeCipherSpec-DTLS",
1581 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001582 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001583 Bugs: ProtocolBugs{
1584 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1585 },
1586 },
1587 // BoringSSL's DTLS implementation will drop the out-of-order
1588 // application data.
1589 },
1590 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001591 protocol: dtls,
1592 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001594 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001595 Bugs: ProtocolBugs{
1596 AppDataAfterChangeCipherSpec: []byte{},
1597 },
1598 },
1599 // BoringSSL's DTLS implementation will drop the out-of-order
1600 // application data.
1601 },
1602 {
Adam Langley7c803a62015-06-15 15:35:05 -07001603 name: "AlertAfterChangeCipherSpec",
1604 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001605 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001606 Bugs: ProtocolBugs{
1607 AlertAfterChangeCipherSpec: alertRecordOverflow,
1608 },
1609 },
1610 shouldFail: true,
1611 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1612 },
1613 {
1614 protocol: dtls,
1615 name: "AlertAfterChangeCipherSpec-DTLS",
1616 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001617 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001618 Bugs: ProtocolBugs{
1619 AlertAfterChangeCipherSpec: alertRecordOverflow,
1620 },
1621 },
1622 shouldFail: true,
1623 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1624 },
1625 {
1626 protocol: dtls,
1627 name: "ReorderHandshakeFragments-Small-DTLS",
1628 config: Config{
1629 Bugs: ProtocolBugs{
1630 ReorderHandshakeFragments: true,
1631 // Small enough that every handshake message is
1632 // fragmented.
1633 MaxHandshakeRecordLength: 2,
1634 },
1635 },
1636 },
1637 {
1638 protocol: dtls,
1639 name: "ReorderHandshakeFragments-Large-DTLS",
1640 config: Config{
1641 Bugs: ProtocolBugs{
1642 ReorderHandshakeFragments: true,
1643 // Large enough that no handshake message is
1644 // fragmented.
1645 MaxHandshakeRecordLength: 2048,
1646 },
1647 },
1648 },
1649 {
1650 protocol: dtls,
1651 name: "MixCompleteMessageWithFragments-DTLS",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 ReorderHandshakeFragments: true,
1655 MixCompleteMessageWithFragments: true,
1656 MaxHandshakeRecordLength: 2,
1657 },
1658 },
1659 },
1660 {
1661 name: "SendInvalidRecordType",
1662 config: Config{
1663 Bugs: ProtocolBugs{
1664 SendInvalidRecordType: true,
1665 },
1666 },
1667 shouldFail: true,
1668 expectedError: ":UNEXPECTED_RECORD:",
1669 },
1670 {
1671 protocol: dtls,
1672 name: "SendInvalidRecordType-DTLS",
1673 config: Config{
1674 Bugs: ProtocolBugs{
1675 SendInvalidRecordType: true,
1676 },
1677 },
1678 shouldFail: true,
1679 expectedError: ":UNEXPECTED_RECORD:",
1680 },
1681 {
1682 name: "FalseStart-SkipServerSecondLeg",
1683 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001684 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001685 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1686 NextProtos: []string{"foo"},
1687 Bugs: ProtocolBugs{
1688 SkipNewSessionTicket: true,
1689 SkipChangeCipherSpec: true,
1690 SkipFinished: true,
1691 ExpectFalseStart: true,
1692 },
1693 },
1694 flags: []string{
1695 "-false-start",
1696 "-handshake-never-done",
1697 "-advertise-alpn", "\x03foo",
1698 },
1699 shimWritesFirst: true,
1700 shouldFail: true,
1701 expectedError: ":UNEXPECTED_RECORD:",
1702 },
1703 {
1704 name: "FalseStart-SkipServerSecondLeg-Implicit",
1705 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001706 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001707 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1708 NextProtos: []string{"foo"},
1709 Bugs: ProtocolBugs{
1710 SkipNewSessionTicket: true,
1711 SkipChangeCipherSpec: true,
1712 SkipFinished: true,
1713 },
1714 },
1715 flags: []string{
1716 "-implicit-handshake",
1717 "-false-start",
1718 "-handshake-never-done",
1719 "-advertise-alpn", "\x03foo",
1720 },
1721 shouldFail: true,
1722 expectedError: ":UNEXPECTED_RECORD:",
1723 },
1724 {
1725 testType: serverTest,
1726 name: "FailEarlyCallback",
1727 flags: []string{"-fail-early-callback"},
1728 shouldFail: true,
1729 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001730 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001731 },
1732 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001733 name: "FailCertCallback-Client-TLS12",
1734 config: Config{
1735 MaxVersion: VersionTLS12,
1736 ClientAuth: RequestClientCert,
1737 },
1738 flags: []string{"-fail-cert-callback"},
1739 shouldFail: true,
1740 expectedError: ":CERT_CB_ERROR:",
1741 expectedLocalError: "remote error: internal error",
1742 },
1743 {
1744 testType: serverTest,
1745 name: "FailCertCallback-Server-TLS12",
1746 config: Config{
1747 MaxVersion: VersionTLS12,
1748 },
1749 flags: []string{"-fail-cert-callback"},
1750 shouldFail: true,
1751 expectedError: ":CERT_CB_ERROR:",
1752 expectedLocalError: "remote error: internal error",
1753 },
1754 {
1755 name: "FailCertCallback-Client-TLS13",
1756 config: Config{
1757 MaxVersion: VersionTLS13,
1758 ClientAuth: RequestClientCert,
1759 },
1760 flags: []string{"-fail-cert-callback"},
1761 shouldFail: true,
1762 expectedError: ":CERT_CB_ERROR:",
1763 expectedLocalError: "remote error: internal error",
1764 },
1765 {
1766 testType: serverTest,
1767 name: "FailCertCallback-Server-TLS13",
1768 config: Config{
1769 MaxVersion: VersionTLS13,
1770 },
1771 flags: []string{"-fail-cert-callback"},
1772 shouldFail: true,
1773 expectedError: ":CERT_CB_ERROR:",
1774 expectedLocalError: "remote error: internal error",
1775 },
1776 {
Adam Langley7c803a62015-06-15 15:35:05 -07001777 protocol: dtls,
1778 name: "FragmentMessageTypeMismatch-DTLS",
1779 config: Config{
1780 Bugs: ProtocolBugs{
1781 MaxHandshakeRecordLength: 2,
1782 FragmentMessageTypeMismatch: true,
1783 },
1784 },
1785 shouldFail: true,
1786 expectedError: ":FRAGMENT_MISMATCH:",
1787 },
1788 {
1789 protocol: dtls,
1790 name: "FragmentMessageLengthMismatch-DTLS",
1791 config: Config{
1792 Bugs: ProtocolBugs{
1793 MaxHandshakeRecordLength: 2,
1794 FragmentMessageLengthMismatch: true,
1795 },
1796 },
1797 shouldFail: true,
1798 expectedError: ":FRAGMENT_MISMATCH:",
1799 },
1800 {
1801 protocol: dtls,
1802 name: "SplitFragments-Header-DTLS",
1803 config: Config{
1804 Bugs: ProtocolBugs{
1805 SplitFragments: 2,
1806 },
1807 },
1808 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001809 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001810 },
1811 {
1812 protocol: dtls,
1813 name: "SplitFragments-Boundary-DTLS",
1814 config: Config{
1815 Bugs: ProtocolBugs{
1816 SplitFragments: dtlsRecordHeaderLen,
1817 },
1818 },
1819 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001820 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001821 },
1822 {
1823 protocol: dtls,
1824 name: "SplitFragments-Body-DTLS",
1825 config: Config{
1826 Bugs: ProtocolBugs{
1827 SplitFragments: dtlsRecordHeaderLen + 1,
1828 },
1829 },
1830 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001831 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001832 },
1833 {
1834 protocol: dtls,
1835 name: "SendEmptyFragments-DTLS",
1836 config: Config{
1837 Bugs: ProtocolBugs{
1838 SendEmptyFragments: true,
1839 },
1840 },
1841 },
1842 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001843 name: "BadFinished-Client",
1844 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001845 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001846 Bugs: ProtocolBugs{
1847 BadFinished: true,
1848 },
1849 },
1850 shouldFail: true,
1851 expectedError: ":DIGEST_CHECK_FAILED:",
1852 },
1853 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001854 name: "BadFinished-Client-TLS13",
1855 config: Config{
1856 MaxVersion: VersionTLS13,
1857 Bugs: ProtocolBugs{
1858 BadFinished: true,
1859 },
1860 },
1861 shouldFail: true,
1862 expectedError: ":DIGEST_CHECK_FAILED:",
1863 },
1864 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001865 testType: serverTest,
1866 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001867 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001868 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001869 Bugs: ProtocolBugs{
1870 BadFinished: true,
1871 },
1872 },
1873 shouldFail: true,
1874 expectedError: ":DIGEST_CHECK_FAILED:",
1875 },
1876 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001877 testType: serverTest,
1878 name: "BadFinished-Server-TLS13",
1879 config: Config{
1880 MaxVersion: VersionTLS13,
1881 Bugs: ProtocolBugs{
1882 BadFinished: true,
1883 },
1884 },
1885 shouldFail: true,
1886 expectedError: ":DIGEST_CHECK_FAILED:",
1887 },
1888 {
Adam Langley7c803a62015-06-15 15:35:05 -07001889 name: "FalseStart-BadFinished",
1890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001891 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1893 NextProtos: []string{"foo"},
1894 Bugs: ProtocolBugs{
1895 BadFinished: true,
1896 ExpectFalseStart: true,
1897 },
1898 },
1899 flags: []string{
1900 "-false-start",
1901 "-handshake-never-done",
1902 "-advertise-alpn", "\x03foo",
1903 },
1904 shimWritesFirst: true,
1905 shouldFail: true,
1906 expectedError: ":DIGEST_CHECK_FAILED:",
1907 },
1908 {
1909 name: "NoFalseStart-NoALPN",
1910 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001911 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001912 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1913 Bugs: ProtocolBugs{
1914 ExpectFalseStart: true,
1915 AlertBeforeFalseStartTest: alertAccessDenied,
1916 },
1917 },
1918 flags: []string{
1919 "-false-start",
1920 },
1921 shimWritesFirst: true,
1922 shouldFail: true,
1923 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1924 expectedLocalError: "tls: peer did not false start: EOF",
1925 },
1926 {
1927 name: "NoFalseStart-NoAEAD",
1928 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001929 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001930 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1931 NextProtos: []string{"foo"},
1932 Bugs: ProtocolBugs{
1933 ExpectFalseStart: true,
1934 AlertBeforeFalseStartTest: alertAccessDenied,
1935 },
1936 },
1937 flags: []string{
1938 "-false-start",
1939 "-advertise-alpn", "\x03foo",
1940 },
1941 shimWritesFirst: true,
1942 shouldFail: true,
1943 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1944 expectedLocalError: "tls: peer did not false start: EOF",
1945 },
1946 {
1947 name: "NoFalseStart-RSA",
1948 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001949 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001950 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1951 NextProtos: []string{"foo"},
1952 Bugs: ProtocolBugs{
1953 ExpectFalseStart: true,
1954 AlertBeforeFalseStartTest: alertAccessDenied,
1955 },
1956 },
1957 flags: []string{
1958 "-false-start",
1959 "-advertise-alpn", "\x03foo",
1960 },
1961 shimWritesFirst: true,
1962 shouldFail: true,
1963 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1964 expectedLocalError: "tls: peer did not false start: EOF",
1965 },
1966 {
1967 name: "NoFalseStart-DHE_RSA",
1968 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001969 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001970 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1971 NextProtos: []string{"foo"},
1972 Bugs: ProtocolBugs{
1973 ExpectFalseStart: true,
1974 AlertBeforeFalseStartTest: alertAccessDenied,
1975 },
1976 },
1977 flags: []string{
1978 "-false-start",
1979 "-advertise-alpn", "\x03foo",
1980 },
1981 shimWritesFirst: true,
1982 shouldFail: true,
1983 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1984 expectedLocalError: "tls: peer did not false start: EOF",
1985 },
1986 {
Adam Langley7c803a62015-06-15 15:35:05 -07001987 protocol: dtls,
1988 name: "SendSplitAlert-Sync",
1989 config: Config{
1990 Bugs: ProtocolBugs{
1991 SendSplitAlert: true,
1992 },
1993 },
1994 },
1995 {
1996 protocol: dtls,
1997 name: "SendSplitAlert-Async",
1998 config: Config{
1999 Bugs: ProtocolBugs{
2000 SendSplitAlert: true,
2001 },
2002 },
2003 flags: []string{"-async"},
2004 },
2005 {
2006 protocol: dtls,
2007 name: "PackDTLSHandshake",
2008 config: Config{
2009 Bugs: ProtocolBugs{
2010 MaxHandshakeRecordLength: 2,
2011 PackHandshakeFragments: 20,
2012 PackHandshakeRecords: 200,
2013 },
2014 },
2015 },
2016 {
Adam Langley7c803a62015-06-15 15:35:05 -07002017 name: "SendEmptyRecords-Pass",
2018 sendEmptyRecords: 32,
2019 },
2020 {
2021 name: "SendEmptyRecords",
2022 sendEmptyRecords: 33,
2023 shouldFail: true,
2024 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2025 },
2026 {
2027 name: "SendEmptyRecords-Async",
2028 sendEmptyRecords: 33,
2029 flags: []string{"-async"},
2030 shouldFail: true,
2031 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2032 },
2033 {
David Benjamine8e84b92016-08-03 15:39:47 -04002034 name: "SendWarningAlerts-Pass",
2035 config: Config{
2036 MaxVersion: VersionTLS12,
2037 },
Adam Langley7c803a62015-06-15 15:35:05 -07002038 sendWarningAlerts: 4,
2039 },
2040 {
David Benjamine8e84b92016-08-03 15:39:47 -04002041 protocol: dtls,
2042 name: "SendWarningAlerts-DTLS-Pass",
2043 config: Config{
2044 MaxVersion: VersionTLS12,
2045 },
Adam Langley7c803a62015-06-15 15:35:05 -07002046 sendWarningAlerts: 4,
2047 },
2048 {
David Benjamine8e84b92016-08-03 15:39:47 -04002049 name: "SendWarningAlerts-TLS13",
2050 config: Config{
2051 MaxVersion: VersionTLS13,
2052 },
2053 sendWarningAlerts: 4,
2054 shouldFail: true,
2055 expectedError: ":BAD_ALERT:",
2056 expectedLocalError: "remote error: error decoding message",
2057 },
2058 {
2059 name: "SendWarningAlerts",
2060 config: Config{
2061 MaxVersion: VersionTLS12,
2062 },
Adam Langley7c803a62015-06-15 15:35:05 -07002063 sendWarningAlerts: 5,
2064 shouldFail: true,
2065 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2066 },
2067 {
David Benjamine8e84b92016-08-03 15:39:47 -04002068 name: "SendWarningAlerts-Async",
2069 config: Config{
2070 MaxVersion: VersionTLS12,
2071 },
Adam Langley7c803a62015-06-15 15:35:05 -07002072 sendWarningAlerts: 5,
2073 flags: []string{"-async"},
2074 shouldFail: true,
2075 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2076 },
David Benjaminba4594a2015-06-18 18:36:15 -04002077 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002078 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002079 config: Config{
2080 MaxVersion: VersionTLS13,
2081 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002082 sendKeyUpdates: 33,
2083 keyUpdateRequest: keyUpdateNotRequested,
2084 shouldFail: true,
2085 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002086 },
2087 {
David Benjaminba4594a2015-06-18 18:36:15 -04002088 name: "EmptySessionID",
2089 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002090 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002091 SessionTicketsDisabled: true,
2092 },
2093 noSessionCache: true,
2094 flags: []string{"-expect-no-session"},
2095 },
David Benjamin30789da2015-08-29 22:56:45 -04002096 {
2097 name: "Unclean-Shutdown",
2098 config: Config{
2099 Bugs: ProtocolBugs{
2100 NoCloseNotify: true,
2101 ExpectCloseNotify: true,
2102 },
2103 },
2104 shimShutsDown: true,
2105 flags: []string{"-check-close-notify"},
2106 shouldFail: true,
2107 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2108 },
2109 {
2110 name: "Unclean-Shutdown-Ignored",
2111 config: Config{
2112 Bugs: ProtocolBugs{
2113 NoCloseNotify: true,
2114 },
2115 },
2116 shimShutsDown: true,
2117 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002118 {
David Benjaminfa214e42016-05-10 17:03:10 -04002119 name: "Unclean-Shutdown-Alert",
2120 config: Config{
2121 Bugs: ProtocolBugs{
2122 SendAlertOnShutdown: alertDecompressionFailure,
2123 ExpectCloseNotify: true,
2124 },
2125 },
2126 shimShutsDown: true,
2127 flags: []string{"-check-close-notify"},
2128 shouldFail: true,
2129 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2130 },
2131 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002132 name: "LargePlaintext",
2133 config: Config{
2134 Bugs: ProtocolBugs{
2135 SendLargeRecords: true,
2136 },
2137 },
2138 messageLen: maxPlaintext + 1,
2139 shouldFail: true,
2140 expectedError: ":DATA_LENGTH_TOO_LONG:",
2141 },
2142 {
2143 protocol: dtls,
2144 name: "LargePlaintext-DTLS",
2145 config: Config{
2146 Bugs: ProtocolBugs{
2147 SendLargeRecords: true,
2148 },
2149 },
2150 messageLen: maxPlaintext + 1,
2151 shouldFail: true,
2152 expectedError: ":DATA_LENGTH_TOO_LONG:",
2153 },
2154 {
2155 name: "LargeCiphertext",
2156 config: Config{
2157 Bugs: ProtocolBugs{
2158 SendLargeRecords: true,
2159 },
2160 },
2161 messageLen: maxPlaintext * 2,
2162 shouldFail: true,
2163 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2164 },
2165 {
2166 protocol: dtls,
2167 name: "LargeCiphertext-DTLS",
2168 config: Config{
2169 Bugs: ProtocolBugs{
2170 SendLargeRecords: true,
2171 },
2172 },
2173 messageLen: maxPlaintext * 2,
2174 // Unlike the other four cases, DTLS drops records which
2175 // are invalid before authentication, so the connection
2176 // does not fail.
2177 expectMessageDropped: true,
2178 },
David Benjamindd6fed92015-10-23 17:41:12 -04002179 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002180 name: "BadHelloRequest-1",
2181 renegotiate: 1,
2182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002183 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002184 Bugs: ProtocolBugs{
2185 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2186 },
2187 },
2188 flags: []string{
2189 "-renegotiate-freely",
2190 "-expect-total-renegotiations", "1",
2191 },
2192 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002193 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002194 },
2195 {
2196 name: "BadHelloRequest-2",
2197 renegotiate: 1,
2198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002199 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002200 Bugs: ProtocolBugs{
2201 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2202 },
2203 },
2204 flags: []string{
2205 "-renegotiate-freely",
2206 "-expect-total-renegotiations", "1",
2207 },
2208 shouldFail: true,
2209 expectedError: ":BAD_HELLO_REQUEST:",
2210 },
David Benjaminef1b0092015-11-21 14:05:44 -05002211 {
2212 testType: serverTest,
2213 name: "SupportTicketsWithSessionID",
2214 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002215 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002216 SessionTicketsDisabled: true,
2217 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002218 resumeConfig: &Config{
2219 MaxVersion: VersionTLS12,
2220 },
David Benjaminef1b0092015-11-21 14:05:44 -05002221 resumeSession: true,
2222 },
David Benjamin02edcd02016-07-27 17:40:37 -04002223 {
2224 protocol: dtls,
2225 name: "DTLS-SendExtraFinished",
2226 config: Config{
2227 Bugs: ProtocolBugs{
2228 SendExtraFinished: true,
2229 },
2230 },
2231 shouldFail: true,
2232 expectedError: ":UNEXPECTED_RECORD:",
2233 },
2234 {
2235 protocol: dtls,
2236 name: "DTLS-SendExtraFinished-Reordered",
2237 config: Config{
2238 Bugs: ProtocolBugs{
2239 MaxHandshakeRecordLength: 2,
2240 ReorderHandshakeFragments: true,
2241 SendExtraFinished: true,
2242 },
2243 },
2244 shouldFail: true,
2245 expectedError: ":UNEXPECTED_RECORD:",
2246 },
David Benjamine97fb482016-07-29 09:23:07 -04002247 {
2248 testType: serverTest,
2249 name: "V2ClientHello-EmptyRecordPrefix",
2250 config: Config{
2251 // Choose a cipher suite that does not involve
2252 // elliptic curves, so no extensions are
2253 // involved.
2254 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002255 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002256 Bugs: ProtocolBugs{
2257 SendV2ClientHello: true,
2258 },
2259 },
2260 sendPrefix: string([]byte{
2261 byte(recordTypeHandshake),
2262 3, 1, // version
2263 0, 0, // length
2264 }),
2265 // A no-op empty record may not be sent before V2ClientHello.
2266 shouldFail: true,
2267 expectedError: ":WRONG_VERSION_NUMBER:",
2268 },
2269 {
2270 testType: serverTest,
2271 name: "V2ClientHello-WarningAlertPrefix",
2272 config: Config{
2273 // Choose a cipher suite that does not involve
2274 // elliptic curves, so no extensions are
2275 // involved.
2276 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002277 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002278 Bugs: ProtocolBugs{
2279 SendV2ClientHello: true,
2280 },
2281 },
2282 sendPrefix: string([]byte{
2283 byte(recordTypeAlert),
2284 3, 1, // version
2285 0, 2, // length
2286 alertLevelWarning, byte(alertDecompressionFailure),
2287 }),
2288 // A no-op warning alert may not be sent before V2ClientHello.
2289 shouldFail: true,
2290 expectedError: ":WRONG_VERSION_NUMBER:",
2291 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002292 {
David Benjamin7ebe61a2017-02-10 13:14:01 -05002293 name: "KeyUpdate-Client",
2294 config: Config{
2295 MaxVersion: VersionTLS13,
2296 },
2297 sendKeyUpdates: 1,
2298 keyUpdateRequest: keyUpdateNotRequested,
2299 },
2300 {
2301 testType: serverTest,
2302 name: "KeyUpdate-Server",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002303 config: Config{
2304 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002305 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002306 sendKeyUpdates: 1,
2307 keyUpdateRequest: keyUpdateNotRequested,
2308 },
2309 {
2310 name: "KeyUpdate-InvalidRequestMode",
2311 config: Config{
2312 MaxVersion: VersionTLS13,
2313 },
2314 sendKeyUpdates: 1,
2315 keyUpdateRequest: 42,
2316 shouldFail: true,
2317 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002318 },
David Benjaminabe94e32016-09-04 14:18:58 -04002319 {
2320 name: "SendSNIWarningAlert",
2321 config: Config{
2322 MaxVersion: VersionTLS12,
2323 Bugs: ProtocolBugs{
2324 SendSNIWarningAlert: true,
2325 },
2326 },
2327 },
David Benjaminc241d792016-09-09 10:34:20 -04002328 {
2329 testType: serverTest,
2330 name: "ExtraCompressionMethods-TLS12",
2331 config: Config{
2332 MaxVersion: VersionTLS12,
2333 Bugs: ProtocolBugs{
2334 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2335 },
2336 },
2337 },
2338 {
2339 testType: serverTest,
2340 name: "ExtraCompressionMethods-TLS13",
2341 config: Config{
2342 MaxVersion: VersionTLS13,
2343 Bugs: ProtocolBugs{
2344 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2345 },
2346 },
2347 shouldFail: true,
2348 expectedError: ":INVALID_COMPRESSION_LIST:",
2349 expectedLocalError: "remote error: illegal parameter",
2350 },
2351 {
2352 testType: serverTest,
2353 name: "NoNullCompression-TLS12",
2354 config: Config{
2355 MaxVersion: VersionTLS12,
2356 Bugs: ProtocolBugs{
2357 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2358 },
2359 },
2360 shouldFail: true,
David Benjamindaa05392017-02-02 23:33:21 -05002361 expectedError: ":INVALID_COMPRESSION_LIST:",
David Benjaminc241d792016-09-09 10:34:20 -04002362 expectedLocalError: "remote error: illegal parameter",
2363 },
2364 {
2365 testType: serverTest,
2366 name: "NoNullCompression-TLS13",
2367 config: Config{
2368 MaxVersion: VersionTLS13,
2369 Bugs: ProtocolBugs{
2370 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2371 },
2372 },
2373 shouldFail: true,
2374 expectedError: ":INVALID_COMPRESSION_LIST:",
2375 expectedLocalError: "remote error: illegal parameter",
2376 },
David Benjamin65ac9972016-09-02 21:35:25 -04002377 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002378 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002379 config: Config{
2380 MaxVersion: VersionTLS12,
2381 Bugs: ProtocolBugs{
2382 ExpectGREASE: true,
2383 },
2384 },
2385 flags: []string{"-enable-grease"},
2386 },
2387 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002388 name: "GREASE-Client-TLS13",
2389 config: Config{
2390 MaxVersion: VersionTLS13,
2391 Bugs: ProtocolBugs{
2392 ExpectGREASE: true,
2393 },
2394 },
2395 flags: []string{"-enable-grease"},
2396 },
2397 {
2398 testType: serverTest,
2399 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002400 config: Config{
2401 MaxVersion: VersionTLS13,
2402 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002403 // TLS 1.3 servers are expected to
2404 // always enable GREASE. TLS 1.3 is new,
2405 // so there is no existing ecosystem to
2406 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002407 ExpectGREASE: true,
2408 },
2409 },
David Benjamin65ac9972016-09-02 21:35:25 -04002410 },
David Benjamine3fbb362017-01-06 16:19:28 -05002411 {
2412 // Test the server so there is a large certificate as
2413 // well as application data.
2414 testType: serverTest,
2415 name: "MaxSendFragment",
2416 config: Config{
2417 Bugs: ProtocolBugs{
2418 MaxReceivePlaintext: 512,
2419 },
2420 },
2421 messageLen: 1024,
2422 flags: []string{
2423 "-max-send-fragment", "512",
2424 "-read-size", "1024",
2425 },
2426 },
2427 {
2428 // Test the server so there is a large certificate as
2429 // well as application data.
2430 testType: serverTest,
2431 name: "MaxSendFragment-TooLarge",
2432 config: Config{
2433 Bugs: ProtocolBugs{
2434 // Ensure that some of the records are
2435 // 512.
2436 MaxReceivePlaintext: 511,
2437 },
2438 },
2439 messageLen: 1024,
2440 flags: []string{
2441 "-max-send-fragment", "512",
2442 "-read-size", "1024",
2443 },
2444 shouldFail: true,
2445 expectedLocalError: "local error: record overflow",
2446 },
Adam Langley7c803a62015-06-15 15:35:05 -07002447 }
Adam Langley7c803a62015-06-15 15:35:05 -07002448 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002449
2450 // Test that very large messages can be received.
2451 cert := rsaCertificate
2452 for i := 0; i < 50; i++ {
2453 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2454 }
2455 testCases = append(testCases, testCase{
2456 name: "LargeMessage",
2457 config: Config{
2458 Certificates: []Certificate{cert},
2459 },
2460 })
2461 testCases = append(testCases, testCase{
2462 protocol: dtls,
2463 name: "LargeMessage-DTLS",
2464 config: Config{
2465 Certificates: []Certificate{cert},
2466 },
2467 })
2468
2469 // They are rejected if the maximum certificate chain length is capped.
2470 testCases = append(testCases, testCase{
2471 name: "LargeMessage-Reject",
2472 config: Config{
2473 Certificates: []Certificate{cert},
2474 },
2475 flags: []string{"-max-cert-list", "16384"},
2476 shouldFail: true,
2477 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2478 })
2479 testCases = append(testCases, testCase{
2480 protocol: dtls,
2481 name: "LargeMessage-Reject-DTLS",
2482 config: Config{
2483 Certificates: []Certificate{cert},
2484 },
2485 flags: []string{"-max-cert-list", "16384"},
2486 shouldFail: true,
2487 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2488 })
Adam Langley7c803a62015-06-15 15:35:05 -07002489}
2490
David Benjaminaa012042016-12-10 13:33:05 -05002491func addTestForCipherSuite(suite testCipherSuite, ver tlsVersion, protocol protocol) {
2492 const psk = "12345"
2493 const pskIdentity = "luggage combo"
2494
2495 var prefix string
2496 if protocol == dtls {
2497 if !ver.hasDTLS {
2498 return
2499 }
2500 prefix = "D"
2501 }
2502
2503 var cert Certificate
2504 var certFile string
2505 var keyFile string
2506 if hasComponent(suite.name, "ECDSA") {
2507 cert = ecdsaP256Certificate
2508 certFile = ecdsaP256CertificateFile
2509 keyFile = ecdsaP256KeyFile
2510 } else {
2511 cert = rsaCertificate
2512 certFile = rsaCertificateFile
2513 keyFile = rsaKeyFile
2514 }
2515
2516 var flags []string
2517 if hasComponent(suite.name, "PSK") {
2518 flags = append(flags,
2519 "-psk", psk,
2520 "-psk-identity", pskIdentity)
2521 }
2522 if hasComponent(suite.name, "NULL") {
2523 // NULL ciphers must be explicitly enabled.
2524 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2525 }
David Benjaminaa012042016-12-10 13:33:05 -05002526
2527 var shouldServerFail, shouldClientFail bool
2528 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2529 // BoringSSL clients accept ECDHE on SSLv3, but
2530 // a BoringSSL server will never select it
2531 // because the extension is missing.
2532 shouldServerFail = true
2533 }
2534 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2535 shouldClientFail = true
2536 shouldServerFail = true
2537 }
2538 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
2539 shouldClientFail = true
2540 shouldServerFail = true
2541 }
2542 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2543 shouldClientFail = true
2544 shouldServerFail = true
2545 }
2546 if !isDTLSCipher(suite.name) && protocol == dtls {
2547 shouldClientFail = true
2548 shouldServerFail = true
2549 }
2550
2551 var sendCipherSuite uint16
2552 var expectedServerError, expectedClientError string
2553 serverCipherSuites := []uint16{suite.id}
2554 if shouldServerFail {
2555 expectedServerError = ":NO_SHARED_CIPHER:"
2556 }
2557 if shouldClientFail {
2558 expectedClientError = ":WRONG_CIPHER_RETURNED:"
2559 // Configure the server to select ciphers as normal but
2560 // select an incompatible cipher in ServerHello.
2561 serverCipherSuites = nil
2562 sendCipherSuite = suite.id
2563 }
2564
David Benjamincdb6fe92017-02-07 16:06:48 -05002565 // For cipher suites and versions where exporters are defined, verify
2566 // that they interoperate.
2567 var exportKeyingMaterial int
2568 if ver.version > VersionSSL30 {
2569 exportKeyingMaterial = 1024
2570 }
2571
David Benjaminaa012042016-12-10 13:33:05 -05002572 testCases = append(testCases, testCase{
2573 testType: serverTest,
2574 protocol: protocol,
2575 name: prefix + ver.name + "-" + suite.name + "-server",
2576 config: Config{
2577 MinVersion: ver.version,
2578 MaxVersion: ver.version,
2579 CipherSuites: []uint16{suite.id},
2580 Certificates: []Certificate{cert},
2581 PreSharedKey: []byte(psk),
2582 PreSharedKeyIdentity: pskIdentity,
2583 Bugs: ProtocolBugs{
2584 AdvertiseAllConfiguredCiphers: true,
2585 },
2586 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002587 certFile: certFile,
2588 keyFile: keyFile,
2589 flags: flags,
2590 resumeSession: true,
2591 shouldFail: shouldServerFail,
2592 expectedError: expectedServerError,
2593 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002594 })
2595
2596 testCases = append(testCases, testCase{
2597 testType: clientTest,
2598 protocol: protocol,
2599 name: prefix + ver.name + "-" + suite.name + "-client",
2600 config: Config{
2601 MinVersion: ver.version,
2602 MaxVersion: ver.version,
2603 CipherSuites: serverCipherSuites,
2604 Certificates: []Certificate{cert},
2605 PreSharedKey: []byte(psk),
2606 PreSharedKeyIdentity: pskIdentity,
2607 Bugs: ProtocolBugs{
2608 IgnorePeerCipherPreferences: shouldClientFail,
2609 SendCipherSuite: sendCipherSuite,
2610 },
2611 },
David Benjamincdb6fe92017-02-07 16:06:48 -05002612 flags: flags,
2613 resumeSession: true,
2614 shouldFail: shouldClientFail,
2615 expectedError: expectedClientError,
2616 exportKeyingMaterial: exportKeyingMaterial,
David Benjaminaa012042016-12-10 13:33:05 -05002617 })
2618
David Benjamin6f600d62016-12-21 16:06:54 -05002619 if shouldClientFail {
2620 return
2621 }
2622
2623 // Ensure the maximum record size is accepted.
2624 testCases = append(testCases, testCase{
2625 protocol: protocol,
2626 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2627 config: Config{
2628 MinVersion: ver.version,
2629 MaxVersion: ver.version,
2630 CipherSuites: []uint16{suite.id},
2631 Certificates: []Certificate{cert},
2632 PreSharedKey: []byte(psk),
2633 PreSharedKeyIdentity: pskIdentity,
2634 },
2635 flags: flags,
2636 messageLen: maxPlaintext,
2637 })
2638
2639 // Test bad records for all ciphers. Bad records are fatal in TLS
2640 // and ignored in DTLS.
2641 var shouldFail bool
2642 var expectedError string
2643 if protocol == tls {
2644 shouldFail = true
2645 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2646 }
2647
2648 testCases = append(testCases, testCase{
2649 protocol: protocol,
2650 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2651 config: Config{
2652 MinVersion: ver.version,
2653 MaxVersion: ver.version,
2654 CipherSuites: []uint16{suite.id},
2655 Certificates: []Certificate{cert},
2656 PreSharedKey: []byte(psk),
2657 PreSharedKeyIdentity: pskIdentity,
2658 },
2659 flags: flags,
2660 damageFirstWrite: true,
2661 messageLen: maxPlaintext,
2662 shouldFail: shouldFail,
2663 expectedError: expectedError,
2664 })
2665
2666 if ver.version >= VersionTLS13 {
David Benjaminaa012042016-12-10 13:33:05 -05002667 testCases = append(testCases, testCase{
2668 protocol: protocol,
David Benjamin6f600d62016-12-21 16:06:54 -05002669 name: prefix + ver.name + "-" + suite.name + "-ShortHeader",
David Benjaminaa012042016-12-10 13:33:05 -05002670 config: Config{
2671 MinVersion: ver.version,
2672 MaxVersion: ver.version,
2673 CipherSuites: []uint16{suite.id},
2674 Certificates: []Certificate{cert},
2675 PreSharedKey: []byte(psk),
2676 PreSharedKeyIdentity: pskIdentity,
David Benjamin6f600d62016-12-21 16:06:54 -05002677 Bugs: ProtocolBugs{
2678 EnableShortHeader: true,
2679 },
David Benjaminaa012042016-12-10 13:33:05 -05002680 },
David Benjamin6f600d62016-12-21 16:06:54 -05002681 flags: append([]string{"-enable-short-header"}, flags...),
2682 resumeSession: true,
2683 expectShortHeader: true,
David Benjaminaa012042016-12-10 13:33:05 -05002684 })
2685 }
2686}
2687
Adam Langley95c29f32014-06-20 12:00:00 -07002688func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002689 const bogusCipher = 0xfe00
2690
Adam Langley95c29f32014-06-20 12:00:00 -07002691 for _, suite := range testCipherSuites {
Adam Langley95c29f32014-06-20 12:00:00 -07002692 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002693 for _, protocol := range []protocol{tls, dtls} {
David Benjaminaa012042016-12-10 13:33:05 -05002694 addTestForCipherSuite(suite, ver, protocol)
Nick Harper1fd39d82016-06-14 18:14:35 -07002695 }
David Benjamin2c99d282015-09-01 10:23:00 -04002696 }
Adam Langley95c29f32014-06-20 12:00:00 -07002697 }
Adam Langleya7997f12015-05-14 17:38:50 -07002698
2699 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002700 name: "NoSharedCipher",
2701 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002702 MaxVersion: VersionTLS12,
2703 CipherSuites: []uint16{},
2704 },
2705 shouldFail: true,
2706 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2707 })
2708
2709 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002710 name: "NoSharedCipher-TLS13",
2711 config: Config{
2712 MaxVersion: VersionTLS13,
2713 CipherSuites: []uint16{},
2714 },
2715 shouldFail: true,
2716 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2717 })
2718
2719 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002720 name: "UnsupportedCipherSuite",
2721 config: Config{
2722 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002723 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002724 Bugs: ProtocolBugs{
2725 IgnorePeerCipherPreferences: true,
2726 },
2727 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002728 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002729 shouldFail: true,
2730 expectedError: ":WRONG_CIPHER_RETURNED:",
2731 })
2732
2733 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002734 name: "ServerHelloBogusCipher",
2735 config: Config{
2736 MaxVersion: VersionTLS12,
2737 Bugs: ProtocolBugs{
2738 SendCipherSuite: bogusCipher,
2739 },
2740 },
2741 shouldFail: true,
2742 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2743 })
2744 testCases = append(testCases, testCase{
2745 name: "ServerHelloBogusCipher-TLS13",
2746 config: Config{
2747 MaxVersion: VersionTLS13,
2748 Bugs: ProtocolBugs{
2749 SendCipherSuite: bogusCipher,
2750 },
2751 },
2752 shouldFail: true,
2753 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2754 })
2755
2756 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002757 name: "WeakDH",
2758 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002759 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002760 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2761 Bugs: ProtocolBugs{
2762 // This is a 1023-bit prime number, generated
2763 // with:
2764 // openssl gendh 1023 | openssl asn1parse -i
2765 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2766 },
2767 },
2768 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002769 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002770 })
Adam Langleycef75832015-09-03 14:51:12 -07002771
David Benjamincd24a392015-11-11 13:23:05 -08002772 testCases = append(testCases, testCase{
2773 name: "SillyDH",
2774 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002775 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002776 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2777 Bugs: ProtocolBugs{
2778 // This is a 4097-bit prime number, generated
2779 // with:
2780 // openssl gendh 4097 | openssl asn1parse -i
2781 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2782 },
2783 },
2784 shouldFail: true,
2785 expectedError: ":DH_P_TOO_LONG:",
2786 })
2787
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002788 // This test ensures that Diffie-Hellman public values are padded with
2789 // zeros so that they're the same length as the prime. This is to avoid
2790 // hitting a bug in yaSSL.
2791 testCases = append(testCases, testCase{
2792 testType: serverTest,
2793 name: "DHPublicValuePadded",
2794 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002795 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002796 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2797 Bugs: ProtocolBugs{
2798 RequireDHPublicValueLen: (1025 + 7) / 8,
2799 },
2800 },
2801 flags: []string{"-use-sparse-dh-prime"},
2802 })
David Benjamincd24a392015-11-11 13:23:05 -08002803
David Benjamin241ae832016-01-15 03:04:54 -05002804 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002805 testCases = append(testCases, testCase{
2806 testType: serverTest,
2807 name: "UnknownCipher",
2808 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002809 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002810 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002811 Bugs: ProtocolBugs{
2812 AdvertiseAllConfiguredCiphers: true,
2813 },
2814 },
2815 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002816
2817 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002818 testCases = append(testCases, testCase{
2819 testType: serverTest,
2820 name: "UnknownCipher-TLS13",
2821 config: Config{
2822 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002823 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002824 Bugs: ProtocolBugs{
2825 AdvertiseAllConfiguredCiphers: true,
2826 },
David Benjamin241ae832016-01-15 03:04:54 -05002827 },
2828 })
2829
David Benjamin78679342016-09-16 19:42:05 -04002830 // Test empty ECDHE_PSK identity hints work as expected.
2831 testCases = append(testCases, testCase{
2832 name: "EmptyECDHEPSKHint",
2833 config: Config{
2834 MaxVersion: VersionTLS12,
2835 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2836 PreSharedKey: []byte("secret"),
2837 },
2838 flags: []string{"-psk", "secret"},
2839 })
2840
2841 // Test empty PSK identity hints work as expected, even if an explicit
2842 // ServerKeyExchange is sent.
2843 testCases = append(testCases, testCase{
2844 name: "ExplicitEmptyPSKHint",
2845 config: Config{
2846 MaxVersion: VersionTLS12,
2847 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2848 PreSharedKey: []byte("secret"),
2849 Bugs: ProtocolBugs{
2850 AlwaysSendPreSharedKeyIdentityHint: true,
2851 },
2852 },
2853 flags: []string{"-psk", "secret"},
2854 })
Adam Langley95c29f32014-06-20 12:00:00 -07002855}
2856
2857func addBadECDSASignatureTests() {
2858 for badR := BadValue(1); badR < NumBadValues; badR++ {
2859 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002860 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002861 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2862 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002863 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002864 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002865 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002866 Bugs: ProtocolBugs{
2867 BadECDSAR: badR,
2868 BadECDSAS: badS,
2869 },
2870 },
2871 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002872 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002873 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002874 testCases = append(testCases, testCase{
2875 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2876 config: Config{
2877 MaxVersion: VersionTLS13,
2878 Certificates: []Certificate{ecdsaP256Certificate},
2879 Bugs: ProtocolBugs{
2880 BadECDSAR: badR,
2881 BadECDSAS: badS,
2882 },
2883 },
2884 shouldFail: true,
2885 expectedError: ":BAD_SIGNATURE:",
2886 })
Adam Langley95c29f32014-06-20 12:00:00 -07002887 }
2888 }
2889}
2890
Adam Langley80842bd2014-06-20 12:00:00 -07002891func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002892 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002893 name: "MaxCBCPadding",
2894 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002895 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002896 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2897 Bugs: ProtocolBugs{
2898 MaxPadding: true,
2899 },
2900 },
2901 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2902 })
David Benjamin025b3d32014-07-01 19:53:04 -04002903 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002904 name: "BadCBCPadding",
2905 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002906 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002907 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2908 Bugs: ProtocolBugs{
2909 PaddingFirstByteBad: true,
2910 },
2911 },
2912 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002913 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002914 })
2915 // OpenSSL previously had an issue where the first byte of padding in
2916 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002917 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002918 name: "BadCBCPadding255",
2919 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002920 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002921 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2922 Bugs: ProtocolBugs{
2923 MaxPadding: true,
2924 PaddingFirstByteBadIf255: true,
2925 },
2926 },
2927 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2928 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002929 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002930 })
2931}
2932
Kenny Root7fdeaf12014-08-05 15:23:37 -07002933func addCBCSplittingTests() {
2934 testCases = append(testCases, testCase{
2935 name: "CBCRecordSplitting",
2936 config: Config{
2937 MaxVersion: VersionTLS10,
2938 MinVersion: VersionTLS10,
2939 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2940 },
David Benjaminac8302a2015-09-01 17:18:15 -04002941 messageLen: -1, // read until EOF
2942 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002943 flags: []string{
2944 "-async",
2945 "-write-different-record-sizes",
2946 "-cbc-record-splitting",
2947 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002948 })
2949 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002950 name: "CBCRecordSplittingPartialWrite",
2951 config: Config{
2952 MaxVersion: VersionTLS10,
2953 MinVersion: VersionTLS10,
2954 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2955 },
2956 messageLen: -1, // read until EOF
2957 flags: []string{
2958 "-async",
2959 "-write-different-record-sizes",
2960 "-cbc-record-splitting",
2961 "-partial-write",
2962 },
2963 })
2964}
2965
David Benjamin636293b2014-07-08 17:59:18 -04002966func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002967 // Add a dummy cert pool to stress certificate authority parsing.
2968 // TODO(davidben): Add tests that those values parse out correctly.
2969 certPool := x509.NewCertPool()
2970 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2971 if err != nil {
2972 panic(err)
2973 }
2974 certPool.AddCert(cert)
2975
David Benjamin636293b2014-07-08 17:59:18 -04002976 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002977 testCases = append(testCases, testCase{
2978 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002979 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002980 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002981 MinVersion: ver.version,
2982 MaxVersion: ver.version,
2983 ClientAuth: RequireAnyClientCert,
2984 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002985 },
2986 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002987 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2988 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002989 },
2990 })
2991 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002992 testType: serverTest,
2993 name: ver.name + "-Server-ClientAuth-RSA",
2994 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002995 MinVersion: ver.version,
2996 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002997 Certificates: []Certificate{rsaCertificate},
2998 },
2999 flags: []string{"-require-any-client-certificate"},
3000 })
David Benjamine098ec22014-08-27 23:13:20 -04003001 if ver.version != VersionSSL30 {
3002 testCases = append(testCases, testCase{
3003 testType: serverTest,
3004 name: ver.name + "-Server-ClientAuth-ECDSA",
3005 config: Config{
3006 MinVersion: ver.version,
3007 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003008 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003009 },
3010 flags: []string{"-require-any-client-certificate"},
3011 })
3012 testCases = append(testCases, testCase{
3013 testType: clientTest,
3014 name: ver.name + "-Client-ClientAuth-ECDSA",
3015 config: Config{
3016 MinVersion: ver.version,
3017 MaxVersion: ver.version,
3018 ClientAuth: RequireAnyClientCert,
3019 ClientCAs: certPool,
3020 },
3021 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003022 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3023 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003024 },
3025 })
3026 }
Adam Langley37646832016-08-01 16:16:46 -07003027
3028 testCases = append(testCases, testCase{
3029 name: "NoClientCertificate-" + ver.name,
3030 config: Config{
3031 MinVersion: ver.version,
3032 MaxVersion: ver.version,
3033 ClientAuth: RequireAnyClientCert,
3034 },
3035 shouldFail: true,
3036 expectedLocalError: "client didn't provide a certificate",
3037 })
3038
3039 testCases = append(testCases, testCase{
3040 // Even if not configured to expect a certificate, OpenSSL will
3041 // return X509_V_OK as the verify_result.
3042 testType: serverTest,
3043 name: "NoClientCertificateRequested-Server-" + ver.name,
3044 config: Config{
3045 MinVersion: ver.version,
3046 MaxVersion: ver.version,
3047 },
3048 flags: []string{
3049 "-expect-verify-result",
3050 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003051 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003052 })
3053
3054 testCases = append(testCases, testCase{
3055 // If a client certificate is not provided, OpenSSL will still
3056 // return X509_V_OK as the verify_result.
3057 testType: serverTest,
3058 name: "NoClientCertificate-Server-" + ver.name,
3059 config: Config{
3060 MinVersion: ver.version,
3061 MaxVersion: ver.version,
3062 },
3063 flags: []string{
3064 "-expect-verify-result",
3065 "-verify-peer",
3066 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003067 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003068 })
3069
David Benjamin1db9e1b2016-10-07 20:51:43 -04003070 certificateRequired := "remote error: certificate required"
3071 if ver.version < VersionTLS13 {
3072 // Prior to TLS 1.3, the generic handshake_failure alert
3073 // was used.
3074 certificateRequired = "remote error: handshake failure"
3075 }
Adam Langley37646832016-08-01 16:16:46 -07003076 testCases = append(testCases, testCase{
3077 testType: serverTest,
3078 name: "RequireAnyClientCertificate-" + ver.name,
3079 config: Config{
3080 MinVersion: ver.version,
3081 MaxVersion: ver.version,
3082 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003083 flags: []string{"-require-any-client-certificate"},
3084 shouldFail: true,
3085 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3086 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003087 })
3088
3089 if ver.version != VersionSSL30 {
3090 testCases = append(testCases, testCase{
3091 testType: serverTest,
3092 name: "SkipClientCertificate-" + ver.name,
3093 config: Config{
3094 MinVersion: ver.version,
3095 MaxVersion: ver.version,
3096 Bugs: ProtocolBugs{
3097 SkipClientCertificate: true,
3098 },
3099 },
3100 // Setting SSL_VERIFY_PEER allows anonymous clients.
3101 flags: []string{"-verify-peer"},
3102 shouldFail: true,
3103 expectedError: ":UNEXPECTED_MESSAGE:",
3104 })
3105 }
David Benjamin636293b2014-07-08 17:59:18 -04003106 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003107
David Benjaminc032dfa2016-05-12 14:54:57 -04003108 // Client auth is only legal in certificate-based ciphers.
3109 testCases = append(testCases, testCase{
3110 testType: clientTest,
3111 name: "ClientAuth-PSK",
3112 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003113 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003114 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3115 PreSharedKey: []byte("secret"),
3116 ClientAuth: RequireAnyClientCert,
3117 },
3118 flags: []string{
3119 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3120 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3121 "-psk", "secret",
3122 },
3123 shouldFail: true,
3124 expectedError: ":UNEXPECTED_MESSAGE:",
3125 })
3126 testCases = append(testCases, testCase{
3127 testType: clientTest,
3128 name: "ClientAuth-ECDHE_PSK",
3129 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003130 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003131 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3132 PreSharedKey: []byte("secret"),
3133 ClientAuth: RequireAnyClientCert,
3134 },
3135 flags: []string{
3136 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3137 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3138 "-psk", "secret",
3139 },
3140 shouldFail: true,
3141 expectedError: ":UNEXPECTED_MESSAGE:",
3142 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003143
3144 // Regression test for a bug where the client CA list, if explicitly
3145 // set to NULL, was mis-encoded.
3146 testCases = append(testCases, testCase{
3147 testType: serverTest,
3148 name: "Null-Client-CA-List",
3149 config: Config{
3150 MaxVersion: VersionTLS12,
3151 Certificates: []Certificate{rsaCertificate},
3152 },
3153 flags: []string{
3154 "-require-any-client-certificate",
3155 "-use-null-client-ca-list",
3156 },
3157 })
David Benjamin636293b2014-07-08 17:59:18 -04003158}
3159
Adam Langley75712922014-10-10 16:23:43 -07003160func addExtendedMasterSecretTests() {
3161 const expectEMSFlag = "-expect-extended-master-secret"
3162
3163 for _, with := range []bool{false, true} {
3164 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003165 if with {
3166 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003167 }
3168
3169 for _, isClient := range []bool{false, true} {
3170 suffix := "-Server"
3171 testType := serverTest
3172 if isClient {
3173 suffix = "-Client"
3174 testType = clientTest
3175 }
3176
3177 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003178 // In TLS 1.3, the extension is irrelevant and
3179 // always reports as enabled.
3180 var flags []string
3181 if with || ver.version >= VersionTLS13 {
3182 flags = []string{expectEMSFlag}
3183 }
3184
Adam Langley75712922014-10-10 16:23:43 -07003185 test := testCase{
3186 testType: testType,
3187 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3188 config: Config{
3189 MinVersion: ver.version,
3190 MaxVersion: ver.version,
3191 Bugs: ProtocolBugs{
3192 NoExtendedMasterSecret: !with,
3193 RequireExtendedMasterSecret: with,
3194 },
3195 },
David Benjamin48cae082014-10-27 01:06:24 -04003196 flags: flags,
3197 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003198 }
3199 if test.shouldFail {
3200 test.expectedLocalError = "extended master secret required but not supported by peer"
3201 }
3202 testCases = append(testCases, test)
3203 }
3204 }
3205 }
3206
Adam Langleyba5934b2015-06-02 10:50:35 -07003207 for _, isClient := range []bool{false, true} {
3208 for _, supportedInFirstConnection := range []bool{false, true} {
3209 for _, supportedInResumeConnection := range []bool{false, true} {
3210 boolToWord := func(b bool) string {
3211 if b {
3212 return "Yes"
3213 }
3214 return "No"
3215 }
3216 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3217 if isClient {
3218 suffix += "Client"
3219 } else {
3220 suffix += "Server"
3221 }
3222
3223 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003224 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003225 Bugs: ProtocolBugs{
3226 RequireExtendedMasterSecret: true,
3227 },
3228 }
3229
3230 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003231 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003232 Bugs: ProtocolBugs{
3233 NoExtendedMasterSecret: true,
3234 },
3235 }
3236
3237 test := testCase{
3238 name: "ExtendedMasterSecret-" + suffix,
3239 resumeSession: true,
3240 }
3241
3242 if !isClient {
3243 test.testType = serverTest
3244 }
3245
3246 if supportedInFirstConnection {
3247 test.config = supportedConfig
3248 } else {
3249 test.config = noSupportConfig
3250 }
3251
3252 if supportedInResumeConnection {
3253 test.resumeConfig = &supportedConfig
3254 } else {
3255 test.resumeConfig = &noSupportConfig
3256 }
3257
3258 switch suffix {
3259 case "YesToYes-Client", "YesToYes-Server":
3260 // When a session is resumed, it should
3261 // still be aware that its master
3262 // secret was generated via EMS and
3263 // thus it's safe to use tls-unique.
3264 test.flags = []string{expectEMSFlag}
3265 case "NoToYes-Server":
3266 // If an original connection did not
3267 // contain EMS, but a resumption
3268 // handshake does, then a server should
3269 // not resume the session.
3270 test.expectResumeRejected = true
3271 case "YesToNo-Server":
3272 // Resuming an EMS session without the
3273 // EMS extension should cause the
3274 // server to abort the connection.
3275 test.shouldFail = true
3276 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3277 case "NoToYes-Client":
3278 // A client should abort a connection
3279 // where the server resumed a non-EMS
3280 // session but echoed the EMS
3281 // extension.
3282 test.shouldFail = true
3283 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3284 case "YesToNo-Client":
3285 // A client should abort a connection
3286 // where the server didn't echo EMS
3287 // when the session used it.
3288 test.shouldFail = true
3289 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3290 }
3291
3292 testCases = append(testCases, test)
3293 }
3294 }
3295 }
David Benjamin163c9562016-08-29 23:14:17 -04003296
3297 // Switching EMS on renegotiation is forbidden.
3298 testCases = append(testCases, testCase{
3299 name: "ExtendedMasterSecret-Renego-NoEMS",
3300 config: Config{
3301 MaxVersion: VersionTLS12,
3302 Bugs: ProtocolBugs{
3303 NoExtendedMasterSecret: true,
3304 NoExtendedMasterSecretOnRenegotiation: true,
3305 },
3306 },
3307 renegotiate: 1,
3308 flags: []string{
3309 "-renegotiate-freely",
3310 "-expect-total-renegotiations", "1",
3311 },
3312 })
3313
3314 testCases = append(testCases, testCase{
3315 name: "ExtendedMasterSecret-Renego-Upgrade",
3316 config: Config{
3317 MaxVersion: VersionTLS12,
3318 Bugs: ProtocolBugs{
3319 NoExtendedMasterSecret: true,
3320 },
3321 },
3322 renegotiate: 1,
3323 flags: []string{
3324 "-renegotiate-freely",
3325 "-expect-total-renegotiations", "1",
3326 },
3327 shouldFail: true,
3328 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3329 })
3330
3331 testCases = append(testCases, testCase{
3332 name: "ExtendedMasterSecret-Renego-Downgrade",
3333 config: Config{
3334 MaxVersion: VersionTLS12,
3335 Bugs: ProtocolBugs{
3336 NoExtendedMasterSecretOnRenegotiation: true,
3337 },
3338 },
3339 renegotiate: 1,
3340 flags: []string{
3341 "-renegotiate-freely",
3342 "-expect-total-renegotiations", "1",
3343 },
3344 shouldFail: true,
3345 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3346 })
Adam Langley75712922014-10-10 16:23:43 -07003347}
3348
David Benjamin582ba042016-07-07 12:33:25 -07003349type stateMachineTestConfig struct {
3350 protocol protocol
3351 async bool
3352 splitHandshake, packHandshakeFlight bool
3353}
3354
David Benjamin43ec06f2014-08-05 02:28:57 -04003355// Adds tests that try to cover the range of the handshake state machine, under
3356// various conditions. Some of these are redundant with other tests, but they
3357// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003358func addAllStateMachineCoverageTests() {
3359 for _, async := range []bool{false, true} {
3360 for _, protocol := range []protocol{tls, dtls} {
3361 addStateMachineCoverageTests(stateMachineTestConfig{
3362 protocol: protocol,
3363 async: async,
3364 })
3365 addStateMachineCoverageTests(stateMachineTestConfig{
3366 protocol: protocol,
3367 async: async,
3368 splitHandshake: true,
3369 })
3370 if protocol == tls {
3371 addStateMachineCoverageTests(stateMachineTestConfig{
3372 protocol: protocol,
3373 async: async,
3374 packHandshakeFlight: true,
3375 })
3376 }
3377 }
3378 }
3379}
3380
3381func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003382 var tests []testCase
3383
3384 // Basic handshake, with resumption. Client and server,
3385 // session ID and session ticket.
3386 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003387 name: "Basic-Client",
3388 config: Config{
3389 MaxVersion: VersionTLS12,
3390 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003391 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003392 // Ensure session tickets are used, not session IDs.
3393 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003394 })
3395 tests = append(tests, testCase{
3396 name: "Basic-Client-RenewTicket",
3397 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003398 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003399 Bugs: ProtocolBugs{
3400 RenewTicketOnResume: true,
3401 },
3402 },
David Benjamin46662482016-08-17 00:51:00 -04003403 flags: []string{"-expect-ticket-renewal"},
3404 resumeSession: true,
3405 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003406 })
3407 tests = append(tests, testCase{
3408 name: "Basic-Client-NoTicket",
3409 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003410 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003411 SessionTicketsDisabled: true,
3412 },
3413 resumeSession: true,
3414 })
3415 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003416 name: "Basic-Client-Implicit",
3417 config: Config{
3418 MaxVersion: VersionTLS12,
3419 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003420 flags: []string{"-implicit-handshake"},
3421 resumeSession: true,
3422 })
3423 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003424 testType: serverTest,
3425 name: "Basic-Server",
3426 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003427 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003428 Bugs: ProtocolBugs{
3429 RequireSessionTickets: true,
3430 },
3431 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003432 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003433 flags: []string{"-expect-no-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003434 })
3435 tests = append(tests, testCase{
3436 testType: serverTest,
3437 name: "Basic-Server-NoTickets",
3438 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003439 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003440 SessionTicketsDisabled: true,
3441 },
3442 resumeSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003443 flags: []string{"-expect-session-id"},
David Benjamin760b1dd2015-05-15 23:33:48 -04003444 })
3445 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003446 testType: serverTest,
3447 name: "Basic-Server-Implicit",
3448 config: Config{
3449 MaxVersion: VersionTLS12,
3450 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003451 flags: []string{"-implicit-handshake"},
3452 resumeSession: true,
3453 })
3454 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003455 testType: serverTest,
3456 name: "Basic-Server-EarlyCallback",
3457 config: Config{
3458 MaxVersion: VersionTLS12,
3459 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003460 flags: []string{"-use-early-callback"},
3461 resumeSession: true,
3462 })
3463
Steven Valdez143e8b32016-07-11 13:19:03 -04003464 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003465 if config.protocol == tls {
3466 tests = append(tests, testCase{
3467 name: "TLS13-1RTT-Client",
3468 config: Config{
3469 MaxVersion: VersionTLS13,
3470 MinVersion: VersionTLS13,
3471 },
David Benjamin46662482016-08-17 00:51:00 -04003472 resumeSession: true,
3473 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003474 })
3475
3476 tests = append(tests, testCase{
3477 testType: serverTest,
3478 name: "TLS13-1RTT-Server",
3479 config: Config{
3480 MaxVersion: VersionTLS13,
3481 MinVersion: VersionTLS13,
3482 },
David Benjamin46662482016-08-17 00:51:00 -04003483 resumeSession: true,
3484 resumeRenewedSession: true,
David Benjaminb5c58db2017-01-28 01:39:29 -05003485 // TLS 1.3 uses tickets, so the session should not be
3486 // cached statefully.
3487 flags: []string{"-expect-no-session-id"},
David Benjamine73c7f42016-08-17 00:29:33 -04003488 })
3489
3490 tests = append(tests, testCase{
3491 name: "TLS13-HelloRetryRequest-Client",
3492 config: Config{
3493 MaxVersion: VersionTLS13,
3494 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003495 // P-384 requires a HelloRetryRequest against BoringSSL's default
3496 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003497 CurvePreferences: []CurveID{CurveP384},
3498 Bugs: ProtocolBugs{
3499 ExpectMissingKeyShare: true,
3500 },
3501 },
3502 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3503 resumeSession: true,
3504 })
3505
3506 tests = append(tests, testCase{
3507 testType: serverTest,
3508 name: "TLS13-HelloRetryRequest-Server",
3509 config: Config{
3510 MaxVersion: VersionTLS13,
3511 MinVersion: VersionTLS13,
3512 // Require a HelloRetryRequest for every curve.
3513 DefaultCurves: []CurveID{},
3514 },
3515 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3516 resumeSession: true,
3517 })
3518 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003519
David Benjamin760b1dd2015-05-15 23:33:48 -04003520 // TLS client auth.
3521 tests = append(tests, testCase{
3522 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003523 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003524 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003525 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003526 ClientAuth: RequestClientCert,
3527 },
3528 })
3529 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003530 testType: serverTest,
3531 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003532 config: Config{
3533 MaxVersion: VersionTLS12,
3534 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003535 // Setting SSL_VERIFY_PEER allows anonymous clients.
3536 flags: []string{"-verify-peer"},
3537 })
David Benjamin582ba042016-07-07 12:33:25 -07003538 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003539 tests = append(tests, testCase{
3540 testType: clientTest,
3541 name: "ClientAuth-NoCertificate-Client-SSL3",
3542 config: Config{
3543 MaxVersion: VersionSSL30,
3544 ClientAuth: RequestClientCert,
3545 },
3546 })
3547 tests = append(tests, testCase{
3548 testType: serverTest,
3549 name: "ClientAuth-NoCertificate-Server-SSL3",
3550 config: Config{
3551 MaxVersion: VersionSSL30,
3552 },
3553 // Setting SSL_VERIFY_PEER allows anonymous clients.
3554 flags: []string{"-verify-peer"},
3555 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003556 tests = append(tests, testCase{
3557 testType: clientTest,
3558 name: "ClientAuth-NoCertificate-Client-TLS13",
3559 config: Config{
3560 MaxVersion: VersionTLS13,
3561 ClientAuth: RequestClientCert,
3562 },
3563 })
3564 tests = append(tests, testCase{
3565 testType: serverTest,
3566 name: "ClientAuth-NoCertificate-Server-TLS13",
3567 config: Config{
3568 MaxVersion: VersionTLS13,
3569 },
3570 // Setting SSL_VERIFY_PEER allows anonymous clients.
3571 flags: []string{"-verify-peer"},
3572 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003573 }
3574 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003575 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003576 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003577 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003578 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003579 ClientAuth: RequireAnyClientCert,
3580 },
3581 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003582 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3583 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003584 },
3585 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003586 tests = append(tests, testCase{
3587 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003588 name: "ClientAuth-RSA-Client-TLS13",
3589 config: Config{
3590 MaxVersion: VersionTLS13,
3591 ClientAuth: RequireAnyClientCert,
3592 },
3593 flags: []string{
3594 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3595 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3596 },
3597 })
3598 tests = append(tests, testCase{
3599 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003600 name: "ClientAuth-ECDSA-Client",
3601 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003602 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003603 ClientAuth: RequireAnyClientCert,
3604 },
3605 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003606 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3607 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003608 },
3609 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003610 tests = append(tests, testCase{
3611 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003612 name: "ClientAuth-ECDSA-Client-TLS13",
3613 config: Config{
3614 MaxVersion: VersionTLS13,
3615 ClientAuth: RequireAnyClientCert,
3616 },
3617 flags: []string{
3618 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3619 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3620 },
3621 })
3622 tests = append(tests, testCase{
3623 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003624 name: "ClientAuth-NoCertificate-OldCallback",
3625 config: Config{
3626 MaxVersion: VersionTLS12,
3627 ClientAuth: RequestClientCert,
3628 },
3629 flags: []string{"-use-old-client-cert-callback"},
3630 })
3631 tests = append(tests, testCase{
3632 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003633 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3634 config: Config{
3635 MaxVersion: VersionTLS13,
3636 ClientAuth: RequestClientCert,
3637 },
3638 flags: []string{"-use-old-client-cert-callback"},
3639 })
3640 tests = append(tests, testCase{
3641 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003642 name: "ClientAuth-OldCallback",
3643 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003644 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003645 ClientAuth: RequireAnyClientCert,
3646 },
3647 flags: []string{
3648 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3649 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3650 "-use-old-client-cert-callback",
3651 },
3652 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003653 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003654 testType: clientTest,
3655 name: "ClientAuth-OldCallback-TLS13",
3656 config: Config{
3657 MaxVersion: VersionTLS13,
3658 ClientAuth: RequireAnyClientCert,
3659 },
3660 flags: []string{
3661 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3662 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3663 "-use-old-client-cert-callback",
3664 },
3665 })
3666 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003667 testType: serverTest,
3668 name: "ClientAuth-Server",
3669 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003670 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003671 Certificates: []Certificate{rsaCertificate},
3672 },
3673 flags: []string{"-require-any-client-certificate"},
3674 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003675 tests = append(tests, testCase{
3676 testType: serverTest,
3677 name: "ClientAuth-Server-TLS13",
3678 config: Config{
3679 MaxVersion: VersionTLS13,
3680 Certificates: []Certificate{rsaCertificate},
3681 },
3682 flags: []string{"-require-any-client-certificate"},
3683 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003684
David Benjamin4c3ddf72016-06-29 18:13:53 -04003685 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003686 tests = append(tests, testCase{
3687 testType: serverTest,
3688 name: "Basic-Server-RSA",
3689 config: Config{
3690 MaxVersion: VersionTLS12,
3691 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3692 },
3693 flags: []string{
3694 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3695 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3696 },
3697 })
3698 tests = append(tests, testCase{
3699 testType: serverTest,
3700 name: "Basic-Server-ECDHE-RSA",
3701 config: Config{
3702 MaxVersion: VersionTLS12,
3703 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3704 },
3705 flags: []string{
3706 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3707 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3708 },
3709 })
3710 tests = append(tests, testCase{
3711 testType: serverTest,
3712 name: "Basic-Server-ECDHE-ECDSA",
3713 config: Config{
3714 MaxVersion: VersionTLS12,
3715 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3716 },
3717 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003718 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3719 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003720 },
3721 })
3722
David Benjamin760b1dd2015-05-15 23:33:48 -04003723 // No session ticket support; server doesn't send NewSessionTicket.
3724 tests = append(tests, testCase{
3725 name: "SessionTicketsDisabled-Client",
3726 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003727 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003728 SessionTicketsDisabled: true,
3729 },
3730 })
3731 tests = append(tests, testCase{
3732 testType: serverTest,
3733 name: "SessionTicketsDisabled-Server",
3734 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003735 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003736 SessionTicketsDisabled: true,
3737 },
3738 })
3739
3740 // Skip ServerKeyExchange in PSK key exchange if there's no
3741 // identity hint.
3742 tests = append(tests, testCase{
3743 name: "EmptyPSKHint-Client",
3744 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003745 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003746 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3747 PreSharedKey: []byte("secret"),
3748 },
3749 flags: []string{"-psk", "secret"},
3750 })
3751 tests = append(tests, testCase{
3752 testType: serverTest,
3753 name: "EmptyPSKHint-Server",
3754 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003755 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003756 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3757 PreSharedKey: []byte("secret"),
3758 },
3759 flags: []string{"-psk", "secret"},
3760 })
3761
David Benjamin4c3ddf72016-06-29 18:13:53 -04003762 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003763 tests = append(tests, testCase{
3764 testType: clientTest,
3765 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003766 config: Config{
3767 MaxVersion: VersionTLS12,
3768 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003769 flags: []string{
3770 "-enable-ocsp-stapling",
3771 "-expect-ocsp-response",
3772 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003773 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003774 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003775 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003776 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003777 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003778 testType: serverTest,
3779 name: "OCSPStapling-Server",
3780 config: Config{
3781 MaxVersion: VersionTLS12,
3782 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003783 expectedOCSPResponse: testOCSPResponse,
3784 flags: []string{
3785 "-ocsp-response",
3786 base64.StdEncoding.EncodeToString(testOCSPResponse),
3787 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003788 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003789 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003790 tests = append(tests, testCase{
3791 testType: clientTest,
3792 name: "OCSPStapling-Client-TLS13",
3793 config: Config{
3794 MaxVersion: VersionTLS13,
3795 },
3796 flags: []string{
3797 "-enable-ocsp-stapling",
3798 "-expect-ocsp-response",
3799 base64.StdEncoding.EncodeToString(testOCSPResponse),
3800 "-verify-peer",
3801 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003802 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003803 })
3804 tests = append(tests, testCase{
3805 testType: serverTest,
3806 name: "OCSPStapling-Server-TLS13",
3807 config: Config{
3808 MaxVersion: VersionTLS13,
3809 },
3810 expectedOCSPResponse: testOCSPResponse,
3811 flags: []string{
3812 "-ocsp-response",
3813 base64.StdEncoding.EncodeToString(testOCSPResponse),
3814 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003815 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003816 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003817
David Benjamin4c3ddf72016-06-29 18:13:53 -04003818 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003819 for _, vers := range tlsVersions {
3820 if config.protocol == dtls && !vers.hasDTLS {
3821 continue
3822 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003823 for _, testType := range []testType{clientTest, serverTest} {
3824 suffix := "-Client"
3825 if testType == serverTest {
3826 suffix = "-Server"
3827 }
3828 suffix += "-" + vers.name
3829
3830 flag := "-verify-peer"
3831 if testType == serverTest {
3832 flag = "-require-any-client-certificate"
3833 }
3834
3835 tests = append(tests, testCase{
3836 testType: testType,
3837 name: "CertificateVerificationSucceed" + suffix,
3838 config: Config{
3839 MaxVersion: vers.version,
3840 Certificates: []Certificate{rsaCertificate},
3841 },
3842 flags: []string{
3843 flag,
3844 "-expect-verify-result",
3845 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003846 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003847 })
3848 tests = append(tests, testCase{
3849 testType: testType,
3850 name: "CertificateVerificationFail" + suffix,
3851 config: Config{
3852 MaxVersion: vers.version,
3853 Certificates: []Certificate{rsaCertificate},
3854 },
3855 flags: []string{
3856 flag,
3857 "-verify-fail",
3858 },
3859 shouldFail: true,
3860 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3861 })
3862 }
3863
3864 // By default, the client is in a soft fail mode where the peer
3865 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003866 tests = append(tests, testCase{
3867 testType: clientTest,
3868 name: "CertificateVerificationSoftFail-" + vers.name,
3869 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003870 MaxVersion: vers.version,
3871 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003872 },
3873 flags: []string{
3874 "-verify-fail",
3875 "-expect-verify-result",
3876 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003877 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003878 })
3879 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003880
David Benjamin1d4f4c02016-07-26 18:03:08 -04003881 tests = append(tests, testCase{
3882 name: "ShimSendAlert",
3883 flags: []string{"-send-alert"},
3884 shimWritesFirst: true,
3885 shouldFail: true,
3886 expectedLocalError: "remote error: decompression failure",
3887 })
3888
David Benjamin582ba042016-07-07 12:33:25 -07003889 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003890 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003891 name: "Renegotiate-Client",
3892 config: Config{
3893 MaxVersion: VersionTLS12,
3894 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003895 renegotiate: 1,
3896 flags: []string{
3897 "-renegotiate-freely",
3898 "-expect-total-renegotiations", "1",
3899 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003900 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003901
David Benjamin47921102016-07-28 11:29:18 -04003902 tests = append(tests, testCase{
3903 name: "SendHalfHelloRequest",
3904 config: Config{
3905 MaxVersion: VersionTLS12,
3906 Bugs: ProtocolBugs{
3907 PackHelloRequestWithFinished: config.packHandshakeFlight,
3908 },
3909 },
3910 sendHalfHelloRequest: true,
3911 flags: []string{"-renegotiate-ignore"},
3912 shouldFail: true,
3913 expectedError: ":UNEXPECTED_RECORD:",
3914 })
3915
David Benjamin760b1dd2015-05-15 23:33:48 -04003916 // NPN on client and server; results in post-handshake message.
3917 tests = append(tests, testCase{
3918 name: "NPN-Client",
3919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003920 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003921 NextProtos: []string{"foo"},
3922 },
3923 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003924 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003925 expectedNextProto: "foo",
3926 expectedNextProtoType: npn,
3927 })
3928 tests = append(tests, testCase{
3929 testType: serverTest,
3930 name: "NPN-Server",
3931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003932 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003933 NextProtos: []string{"bar"},
3934 },
3935 flags: []string{
3936 "-advertise-npn", "\x03foo\x03bar\x03baz",
3937 "-expect-next-proto", "bar",
3938 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003939 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003940 expectedNextProto: "bar",
3941 expectedNextProtoType: npn,
3942 })
3943
3944 // TODO(davidben): Add tests for when False Start doesn't trigger.
3945
3946 // Client does False Start and negotiates NPN.
3947 tests = append(tests, testCase{
3948 name: "FalseStart",
3949 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003950 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003951 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3952 NextProtos: []string{"foo"},
3953 Bugs: ProtocolBugs{
3954 ExpectFalseStart: true,
3955 },
3956 },
3957 flags: []string{
3958 "-false-start",
3959 "-select-next-proto", "foo",
3960 },
3961 shimWritesFirst: true,
3962 resumeSession: true,
3963 })
3964
3965 // Client does False Start and negotiates ALPN.
3966 tests = append(tests, testCase{
3967 name: "FalseStart-ALPN",
3968 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003969 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003970 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3971 NextProtos: []string{"foo"},
3972 Bugs: ProtocolBugs{
3973 ExpectFalseStart: true,
3974 },
3975 },
3976 flags: []string{
3977 "-false-start",
3978 "-advertise-alpn", "\x03foo",
3979 },
3980 shimWritesFirst: true,
3981 resumeSession: true,
3982 })
3983
3984 // Client does False Start but doesn't explicitly call
3985 // SSL_connect.
3986 tests = append(tests, testCase{
3987 name: "FalseStart-Implicit",
3988 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003989 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3991 NextProtos: []string{"foo"},
3992 },
3993 flags: []string{
3994 "-implicit-handshake",
3995 "-false-start",
3996 "-advertise-alpn", "\x03foo",
3997 },
3998 })
3999
4000 // False Start without session tickets.
4001 tests = append(tests, testCase{
4002 name: "FalseStart-SessionTicketsDisabled",
4003 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07004004 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004005 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
4006 NextProtos: []string{"foo"},
4007 SessionTicketsDisabled: true,
4008 Bugs: ProtocolBugs{
4009 ExpectFalseStart: true,
4010 },
4011 },
4012 flags: []string{
4013 "-false-start",
4014 "-select-next-proto", "foo",
4015 },
4016 shimWritesFirst: true,
4017 })
4018
4019 // Server parses a V2ClientHello.
4020 tests = append(tests, testCase{
4021 testType: serverTest,
4022 name: "SendV2ClientHello",
4023 config: Config{
4024 // Choose a cipher suite that does not involve
4025 // elliptic curves, so no extensions are
4026 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004027 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004028 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004029 Bugs: ProtocolBugs{
4030 SendV2ClientHello: true,
4031 },
4032 },
4033 })
4034
Nick Harper60a85cb2016-09-23 16:25:11 -07004035 // Test Channel ID
4036 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004037 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004038 continue
4039 }
4040 // Client sends a Channel ID.
4041 tests = append(tests, testCase{
4042 name: "ChannelID-Client-" + ver.name,
4043 config: Config{
4044 MaxVersion: ver.version,
4045 RequestChannelID: true,
4046 },
4047 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4048 resumeSession: true,
4049 expectChannelID: true,
4050 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004051
Nick Harper60a85cb2016-09-23 16:25:11 -07004052 // Server accepts a Channel ID.
4053 tests = append(tests, testCase{
4054 testType: serverTest,
4055 name: "ChannelID-Server-" + ver.name,
4056 config: Config{
4057 MaxVersion: ver.version,
4058 ChannelID: channelIDKey,
4059 },
4060 flags: []string{
4061 "-expect-channel-id",
4062 base64.StdEncoding.EncodeToString(channelIDBytes),
4063 },
4064 resumeSession: true,
4065 expectChannelID: true,
4066 })
4067
4068 tests = append(tests, testCase{
4069 testType: serverTest,
4070 name: "InvalidChannelIDSignature-" + ver.name,
4071 config: Config{
4072 MaxVersion: ver.version,
4073 ChannelID: channelIDKey,
4074 Bugs: ProtocolBugs{
4075 InvalidChannelIDSignature: true,
4076 },
4077 },
4078 flags: []string{"-enable-channel-id"},
4079 shouldFail: true,
4080 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4081 })
4082 }
David Benjamin30789da2015-08-29 22:56:45 -04004083
David Benjaminf8fcdf32016-06-08 15:56:13 -04004084 // Channel ID and NPN at the same time, to ensure their relative
4085 // ordering is correct.
4086 tests = append(tests, testCase{
4087 name: "ChannelID-NPN-Client",
4088 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004089 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004090 RequestChannelID: true,
4091 NextProtos: []string{"foo"},
4092 },
4093 flags: []string{
4094 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4095 "-select-next-proto", "foo",
4096 },
4097 resumeSession: true,
4098 expectChannelID: true,
4099 expectedNextProto: "foo",
4100 expectedNextProtoType: npn,
4101 })
4102 tests = append(tests, testCase{
4103 testType: serverTest,
4104 name: "ChannelID-NPN-Server",
4105 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004106 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004107 ChannelID: channelIDKey,
4108 NextProtos: []string{"bar"},
4109 },
4110 flags: []string{
4111 "-expect-channel-id",
4112 base64.StdEncoding.EncodeToString(channelIDBytes),
4113 "-advertise-npn", "\x03foo\x03bar\x03baz",
4114 "-expect-next-proto", "bar",
4115 },
4116 resumeSession: true,
4117 expectChannelID: true,
4118 expectedNextProto: "bar",
4119 expectedNextProtoType: npn,
4120 })
4121
David Benjamin30789da2015-08-29 22:56:45 -04004122 // Bidirectional shutdown with the runner initiating.
4123 tests = append(tests, testCase{
4124 name: "Shutdown-Runner",
4125 config: Config{
4126 Bugs: ProtocolBugs{
4127 ExpectCloseNotify: true,
4128 },
4129 },
4130 flags: []string{"-check-close-notify"},
4131 })
4132
4133 // Bidirectional shutdown with the shim initiating. The runner,
4134 // in the meantime, sends garbage before the close_notify which
4135 // the shim must ignore.
4136 tests = append(tests, testCase{
4137 name: "Shutdown-Shim",
4138 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004139 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004140 Bugs: ProtocolBugs{
4141 ExpectCloseNotify: true,
4142 },
4143 },
4144 shimShutsDown: true,
4145 sendEmptyRecords: 1,
4146 sendWarningAlerts: 1,
4147 flags: []string{"-check-close-notify"},
4148 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004149 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004150 // TODO(davidben): DTLS 1.3 will want a similar thing for
4151 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004152 tests = append(tests, testCase{
4153 name: "SkipHelloVerifyRequest",
4154 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004155 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004156 Bugs: ProtocolBugs{
4157 SkipHelloVerifyRequest: true,
4158 },
4159 },
4160 })
4161 }
4162
David Benjamin760b1dd2015-05-15 23:33:48 -04004163 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004164 test.protocol = config.protocol
4165 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004166 test.name += "-DTLS"
4167 }
David Benjamin582ba042016-07-07 12:33:25 -07004168 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004169 test.name += "-Async"
4170 test.flags = append(test.flags, "-async")
4171 } else {
4172 test.name += "-Sync"
4173 }
David Benjamin582ba042016-07-07 12:33:25 -07004174 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004175 test.name += "-SplitHandshakeRecords"
4176 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004177 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004178 test.config.Bugs.MaxPacketLength = 256
4179 test.flags = append(test.flags, "-mtu", "256")
4180 }
4181 }
David Benjamin582ba042016-07-07 12:33:25 -07004182 if config.packHandshakeFlight {
4183 test.name += "-PackHandshakeFlight"
4184 test.config.Bugs.PackHandshakeFlight = true
4185 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004186 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004187 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004188}
4189
Adam Langley524e7172015-02-20 16:04:00 -08004190func addDDoSCallbackTests() {
4191 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004192 for _, resume := range []bool{false, true} {
4193 suffix := "Resume"
4194 if resume {
4195 suffix = "No" + suffix
4196 }
4197
4198 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004199 testType: serverTest,
4200 name: "Server-DDoS-OK-" + suffix,
4201 config: Config{
4202 MaxVersion: VersionTLS12,
4203 },
Adam Langley524e7172015-02-20 16:04:00 -08004204 flags: []string{"-install-ddos-callback"},
4205 resumeSession: resume,
4206 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004207 testCases = append(testCases, testCase{
4208 testType: serverTest,
4209 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4210 config: Config{
4211 MaxVersion: VersionTLS13,
4212 },
4213 flags: []string{"-install-ddos-callback"},
4214 resumeSession: resume,
4215 })
Adam Langley524e7172015-02-20 16:04:00 -08004216
4217 failFlag := "-fail-ddos-callback"
4218 if resume {
4219 failFlag = "-fail-second-ddos-callback"
4220 }
4221 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004222 testType: serverTest,
4223 name: "Server-DDoS-Reject-" + suffix,
4224 config: Config{
4225 MaxVersion: VersionTLS12,
4226 },
David Benjamin2c66e072016-09-16 15:58:00 -04004227 flags: []string{"-install-ddos-callback", failFlag},
4228 resumeSession: resume,
4229 shouldFail: true,
4230 expectedError: ":CONNECTION_REJECTED:",
4231 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004232 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004233 testCases = append(testCases, testCase{
4234 testType: serverTest,
4235 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4236 config: Config{
4237 MaxVersion: VersionTLS13,
4238 },
David Benjamin2c66e072016-09-16 15:58:00 -04004239 flags: []string{"-install-ddos-callback", failFlag},
4240 resumeSession: resume,
4241 shouldFail: true,
4242 expectedError: ":CONNECTION_REJECTED:",
4243 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004244 })
Adam Langley524e7172015-02-20 16:04:00 -08004245 }
4246}
4247
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004248func addVersionNegotiationTests() {
4249 for i, shimVers := range tlsVersions {
4250 // Assemble flags to disable all newer versions on the shim.
4251 var flags []string
4252 for _, vers := range tlsVersions[i+1:] {
4253 flags = append(flags, vers.flag)
4254 }
4255
Steven Valdezfdd10992016-09-15 16:27:05 -04004256 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004257 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004258 protocols := []protocol{tls}
4259 if runnerVers.hasDTLS && shimVers.hasDTLS {
4260 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004261 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004262 for _, protocol := range protocols {
4263 expectedVersion := shimVers.version
4264 if runnerVers.version < shimVers.version {
4265 expectedVersion = runnerVers.version
4266 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004267
David Benjamin8b8c0062014-11-23 02:47:52 -05004268 suffix := shimVers.name + "-" + runnerVers.name
4269 if protocol == dtls {
4270 suffix += "-DTLS"
4271 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004272
David Benjamin1eb367c2014-12-12 18:17:51 -05004273 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4274
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004275 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004276 clientVers := shimVers.version
4277 if clientVers > VersionTLS10 {
4278 clientVers = VersionTLS10
4279 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004280 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004281 serverVers := expectedVersion
4282 if expectedVersion >= VersionTLS13 {
4283 serverVers = VersionTLS10
4284 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004285 serverVers = versionToWire(serverVers, protocol == dtls)
4286
David Benjamin8b8c0062014-11-23 02:47:52 -05004287 testCases = append(testCases, testCase{
4288 protocol: protocol,
4289 testType: clientTest,
4290 name: "VersionNegotiation-Client-" + suffix,
4291 config: Config{
4292 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004293 Bugs: ProtocolBugs{
4294 ExpectInitialRecordVersion: clientVers,
4295 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004296 },
4297 flags: flags,
4298 expectedVersion: expectedVersion,
4299 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004300 testCases = append(testCases, testCase{
4301 protocol: protocol,
4302 testType: clientTest,
4303 name: "VersionNegotiation-Client2-" + suffix,
4304 config: Config{
4305 MaxVersion: runnerVers.version,
4306 Bugs: ProtocolBugs{
4307 ExpectInitialRecordVersion: clientVers,
4308 },
4309 },
4310 flags: []string{"-max-version", shimVersFlag},
4311 expectedVersion: expectedVersion,
4312 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004313
4314 testCases = append(testCases, testCase{
4315 protocol: protocol,
4316 testType: serverTest,
4317 name: "VersionNegotiation-Server-" + suffix,
4318 config: Config{
4319 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004320 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004321 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004322 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004323 },
4324 flags: flags,
4325 expectedVersion: expectedVersion,
4326 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004327 testCases = append(testCases, testCase{
4328 protocol: protocol,
4329 testType: serverTest,
4330 name: "VersionNegotiation-Server2-" + suffix,
4331 config: Config{
4332 MaxVersion: runnerVers.version,
4333 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004334 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004335 },
4336 },
4337 flags: []string{"-max-version", shimVersFlag},
4338 expectedVersion: expectedVersion,
4339 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004340 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004341 }
4342 }
David Benjamin95c69562016-06-29 18:15:03 -04004343
Steven Valdezfdd10992016-09-15 16:27:05 -04004344 // Test the version extension at all versions.
4345 for _, vers := range tlsVersions {
4346 protocols := []protocol{tls}
4347 if vers.hasDTLS {
4348 protocols = append(protocols, dtls)
4349 }
4350 for _, protocol := range protocols {
4351 suffix := vers.name
4352 if protocol == dtls {
4353 suffix += "-DTLS"
4354 }
4355
4356 wireVersion := versionToWire(vers.version, protocol == dtls)
4357 testCases = append(testCases, testCase{
4358 protocol: protocol,
4359 testType: serverTest,
4360 name: "VersionNegotiationExtension-" + suffix,
4361 config: Config{
4362 Bugs: ProtocolBugs{
4363 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4364 },
4365 },
4366 expectedVersion: vers.version,
4367 })
4368 }
4369
4370 }
4371
4372 // If all versions are unknown, negotiation fails.
4373 testCases = append(testCases, testCase{
4374 testType: serverTest,
4375 name: "NoSupportedVersions",
4376 config: Config{
4377 Bugs: ProtocolBugs{
4378 SendSupportedVersions: []uint16{0x1111},
4379 },
4380 },
4381 shouldFail: true,
4382 expectedError: ":UNSUPPORTED_PROTOCOL:",
4383 })
4384 testCases = append(testCases, testCase{
4385 protocol: dtls,
4386 testType: serverTest,
4387 name: "NoSupportedVersions-DTLS",
4388 config: Config{
4389 Bugs: ProtocolBugs{
4390 SendSupportedVersions: []uint16{0x1111},
4391 },
4392 },
4393 shouldFail: true,
4394 expectedError: ":UNSUPPORTED_PROTOCOL:",
4395 })
4396
4397 testCases = append(testCases, testCase{
4398 testType: serverTest,
4399 name: "ClientHelloVersionTooHigh",
4400 config: Config{
4401 MaxVersion: VersionTLS13,
4402 Bugs: ProtocolBugs{
4403 SendClientVersion: 0x0304,
4404 OmitSupportedVersions: true,
4405 },
4406 },
4407 expectedVersion: VersionTLS12,
4408 })
4409
4410 testCases = append(testCases, testCase{
4411 testType: serverTest,
4412 name: "ConflictingVersionNegotiation",
4413 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004414 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004415 SendClientVersion: VersionTLS12,
4416 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004417 },
4418 },
David Benjaminad75a662016-09-30 15:42:59 -04004419 // The extension takes precedence over the ClientHello version.
4420 expectedVersion: VersionTLS11,
4421 })
4422
4423 testCases = append(testCases, testCase{
4424 testType: serverTest,
4425 name: "ConflictingVersionNegotiation-2",
4426 config: Config{
4427 Bugs: ProtocolBugs{
4428 SendClientVersion: VersionTLS11,
4429 SendSupportedVersions: []uint16{VersionTLS12},
4430 },
4431 },
4432 // The extension takes precedence over the ClientHello version.
4433 expectedVersion: VersionTLS12,
4434 })
4435
4436 testCases = append(testCases, testCase{
4437 testType: serverTest,
4438 name: "RejectFinalTLS13",
4439 config: Config{
4440 Bugs: ProtocolBugs{
4441 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4442 },
4443 },
4444 // We currently implement a draft TLS 1.3 version. Ensure that
4445 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004446 expectedVersion: VersionTLS12,
4447 })
4448
Brian Smithf85d3232016-10-28 10:34:06 -10004449 // Test that the maximum version is selected regardless of the
4450 // client-sent order.
4451 testCases = append(testCases, testCase{
4452 testType: serverTest,
4453 name: "IgnoreClientVersionOrder",
4454 config: Config{
4455 Bugs: ProtocolBugs{
4456 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4457 },
4458 },
4459 expectedVersion: VersionTLS13,
4460 })
4461
David Benjamin95c69562016-06-29 18:15:03 -04004462 // Test for version tolerance.
4463 testCases = append(testCases, testCase{
4464 testType: serverTest,
4465 name: "MinorVersionTolerance",
4466 config: Config{
4467 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004468 SendClientVersion: 0x03ff,
4469 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004470 },
4471 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004472 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004473 })
4474 testCases = append(testCases, testCase{
4475 testType: serverTest,
4476 name: "MajorVersionTolerance",
4477 config: Config{
4478 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004479 SendClientVersion: 0x0400,
4480 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004481 },
4482 },
David Benjaminad75a662016-09-30 15:42:59 -04004483 // TLS 1.3 must be negotiated with the supported_versions
4484 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004485 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004486 })
David Benjaminad75a662016-09-30 15:42:59 -04004487 testCases = append(testCases, testCase{
4488 testType: serverTest,
4489 name: "VersionTolerance-TLS13",
4490 config: Config{
4491 Bugs: ProtocolBugs{
4492 // Although TLS 1.3 does not use
4493 // ClientHello.version, it still tolerates high
4494 // values there.
4495 SendClientVersion: 0x0400,
4496 },
4497 },
4498 expectedVersion: VersionTLS13,
4499 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004500
David Benjamin95c69562016-06-29 18:15:03 -04004501 testCases = append(testCases, testCase{
4502 protocol: dtls,
4503 testType: serverTest,
4504 name: "MinorVersionTolerance-DTLS",
4505 config: Config{
4506 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004507 SendClientVersion: 0xfe00,
4508 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004509 },
4510 },
4511 expectedVersion: VersionTLS12,
4512 })
4513 testCases = append(testCases, testCase{
4514 protocol: dtls,
4515 testType: serverTest,
4516 name: "MajorVersionTolerance-DTLS",
4517 config: Config{
4518 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004519 SendClientVersion: 0xfdff,
4520 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004521 },
4522 },
4523 expectedVersion: VersionTLS12,
4524 })
4525
4526 // Test that versions below 3.0 are rejected.
4527 testCases = append(testCases, testCase{
4528 testType: serverTest,
4529 name: "VersionTooLow",
4530 config: Config{
4531 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004532 SendClientVersion: 0x0200,
4533 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004534 },
4535 },
4536 shouldFail: true,
4537 expectedError: ":UNSUPPORTED_PROTOCOL:",
4538 })
4539 testCases = append(testCases, testCase{
4540 protocol: dtls,
4541 testType: serverTest,
4542 name: "VersionTooLow-DTLS",
4543 config: Config{
4544 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004545 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004546 },
4547 },
4548 shouldFail: true,
4549 expectedError: ":UNSUPPORTED_PROTOCOL:",
4550 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004551
David Benjamin2dc02042016-09-19 19:57:37 -04004552 testCases = append(testCases, testCase{
4553 name: "ServerBogusVersion",
4554 config: Config{
4555 Bugs: ProtocolBugs{
4556 SendServerHelloVersion: 0x1234,
4557 },
4558 },
4559 shouldFail: true,
4560 expectedError: ":UNSUPPORTED_PROTOCOL:",
4561 })
4562
David Benjamin1f61f0d2016-07-10 12:20:35 -04004563 // Test TLS 1.3's downgrade signal.
4564 testCases = append(testCases, testCase{
4565 name: "Downgrade-TLS12-Client",
4566 config: Config{
4567 Bugs: ProtocolBugs{
4568 NegotiateVersion: VersionTLS12,
4569 },
4570 },
David Benjamin592b5322016-09-30 15:15:01 -04004571 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004572 // TODO(davidben): This test should fail once TLS 1.3 is final
4573 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004574 })
4575 testCases = append(testCases, testCase{
4576 testType: serverTest,
4577 name: "Downgrade-TLS12-Server",
4578 config: Config{
4579 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004580 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004581 },
4582 },
David Benjamin592b5322016-09-30 15:15:01 -04004583 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004584 // TODO(davidben): This test should fail once TLS 1.3 is final
4585 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004586 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004587}
4588
David Benjaminaccb4542014-12-12 23:44:33 -05004589func addMinimumVersionTests() {
4590 for i, shimVers := range tlsVersions {
4591 // Assemble flags to disable all older versions on the shim.
4592 var flags []string
4593 for _, vers := range tlsVersions[:i] {
4594 flags = append(flags, vers.flag)
4595 }
4596
4597 for _, runnerVers := range tlsVersions {
4598 protocols := []protocol{tls}
4599 if runnerVers.hasDTLS && shimVers.hasDTLS {
4600 protocols = append(protocols, dtls)
4601 }
4602 for _, protocol := range protocols {
4603 suffix := shimVers.name + "-" + runnerVers.name
4604 if protocol == dtls {
4605 suffix += "-DTLS"
4606 }
4607 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4608
David Benjaminaccb4542014-12-12 23:44:33 -05004609 var expectedVersion uint16
4610 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004611 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004612 if runnerVers.version >= shimVers.version {
4613 expectedVersion = runnerVers.version
4614 } else {
4615 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004616 expectedError = ":UNSUPPORTED_PROTOCOL:"
4617 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004618 }
4619
4620 testCases = append(testCases, testCase{
4621 protocol: protocol,
4622 testType: clientTest,
4623 name: "MinimumVersion-Client-" + suffix,
4624 config: Config{
4625 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004626 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004627 // Ensure the server does not decline to
4628 // select a version (versions extension) or
4629 // cipher (some ciphers depend on versions).
4630 NegotiateVersion: runnerVers.version,
4631 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004632 },
David Benjaminaccb4542014-12-12 23:44:33 -05004633 },
David Benjamin87909c02014-12-13 01:55:01 -05004634 flags: flags,
4635 expectedVersion: expectedVersion,
4636 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004637 expectedError: expectedError,
4638 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004639 })
4640 testCases = append(testCases, testCase{
4641 protocol: protocol,
4642 testType: clientTest,
4643 name: "MinimumVersion-Client2-" + suffix,
4644 config: Config{
4645 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004646 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004647 // Ensure the server does not decline to
4648 // select a version (versions extension) or
4649 // cipher (some ciphers depend on versions).
4650 NegotiateVersion: runnerVers.version,
4651 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004652 },
David Benjaminaccb4542014-12-12 23:44:33 -05004653 },
David Benjamin87909c02014-12-13 01:55:01 -05004654 flags: []string{"-min-version", shimVersFlag},
4655 expectedVersion: expectedVersion,
4656 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004657 expectedError: expectedError,
4658 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004659 })
4660
4661 testCases = append(testCases, testCase{
4662 protocol: protocol,
4663 testType: serverTest,
4664 name: "MinimumVersion-Server-" + suffix,
4665 config: Config{
4666 MaxVersion: runnerVers.version,
4667 },
David Benjamin87909c02014-12-13 01:55:01 -05004668 flags: flags,
4669 expectedVersion: expectedVersion,
4670 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004671 expectedError: expectedError,
4672 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004673 })
4674 testCases = append(testCases, testCase{
4675 protocol: protocol,
4676 testType: serverTest,
4677 name: "MinimumVersion-Server2-" + suffix,
4678 config: Config{
4679 MaxVersion: runnerVers.version,
4680 },
David Benjamin87909c02014-12-13 01:55:01 -05004681 flags: []string{"-min-version", shimVersFlag},
4682 expectedVersion: expectedVersion,
4683 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004684 expectedError: expectedError,
4685 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004686 })
4687 }
4688 }
4689 }
4690}
4691
David Benjamine78bfde2014-09-06 12:45:15 -04004692func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004693 // TODO(davidben): Extensions, where applicable, all move their server
4694 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4695 // tests for both. Also test interaction with 0-RTT when implemented.
4696
David Benjamin97d17d92016-07-14 16:12:00 -04004697 // Repeat extensions tests all versions except SSL 3.0.
4698 for _, ver := range tlsVersions {
4699 if ver.version == VersionSSL30 {
4700 continue
4701 }
4702
David Benjamin97d17d92016-07-14 16:12:00 -04004703 // Test that duplicate extensions are rejected.
4704 testCases = append(testCases, testCase{
4705 testType: clientTest,
4706 name: "DuplicateExtensionClient-" + ver.name,
4707 config: Config{
4708 MaxVersion: ver.version,
4709 Bugs: ProtocolBugs{
4710 DuplicateExtension: true,
4711 },
David Benjamine78bfde2014-09-06 12:45:15 -04004712 },
David Benjamin97d17d92016-07-14 16:12:00 -04004713 shouldFail: true,
4714 expectedLocalError: "remote error: error decoding message",
4715 })
4716 testCases = append(testCases, testCase{
4717 testType: serverTest,
4718 name: "DuplicateExtensionServer-" + ver.name,
4719 config: Config{
4720 MaxVersion: ver.version,
4721 Bugs: ProtocolBugs{
4722 DuplicateExtension: true,
4723 },
David Benjamine78bfde2014-09-06 12:45:15 -04004724 },
David Benjamin97d17d92016-07-14 16:12:00 -04004725 shouldFail: true,
4726 expectedLocalError: "remote error: error decoding message",
4727 })
4728
4729 // Test SNI.
4730 testCases = append(testCases, testCase{
4731 testType: clientTest,
4732 name: "ServerNameExtensionClient-" + ver.name,
4733 config: Config{
4734 MaxVersion: ver.version,
4735 Bugs: ProtocolBugs{
4736 ExpectServerName: "example.com",
4737 },
David Benjamine78bfde2014-09-06 12:45:15 -04004738 },
David Benjamin97d17d92016-07-14 16:12:00 -04004739 flags: []string{"-host-name", "example.com"},
4740 })
4741 testCases = append(testCases, testCase{
4742 testType: clientTest,
4743 name: "ServerNameExtensionClientMismatch-" + ver.name,
4744 config: Config{
4745 MaxVersion: ver.version,
4746 Bugs: ProtocolBugs{
4747 ExpectServerName: "mismatch.com",
4748 },
David Benjamine78bfde2014-09-06 12:45:15 -04004749 },
David Benjamin97d17d92016-07-14 16:12:00 -04004750 flags: []string{"-host-name", "example.com"},
4751 shouldFail: true,
4752 expectedLocalError: "tls: unexpected server name",
4753 })
4754 testCases = append(testCases, testCase{
4755 testType: clientTest,
4756 name: "ServerNameExtensionClientMissing-" + ver.name,
4757 config: Config{
4758 MaxVersion: ver.version,
4759 Bugs: ProtocolBugs{
4760 ExpectServerName: "missing.com",
4761 },
David Benjamine78bfde2014-09-06 12:45:15 -04004762 },
David Benjamin97d17d92016-07-14 16:12:00 -04004763 shouldFail: true,
4764 expectedLocalError: "tls: unexpected server name",
4765 })
4766 testCases = append(testCases, testCase{
David Benjamin023d4192017-02-06 13:49:07 -05004767 testType: clientTest,
4768 name: "TolerateServerNameAck-" + ver.name,
4769 config: Config{
4770 MaxVersion: ver.version,
4771 Bugs: ProtocolBugs{
4772 SendServerNameAck: true,
4773 },
4774 },
4775 flags: []string{"-host-name", "example.com"},
4776 resumeSession: true,
4777 })
4778 testCases = append(testCases, testCase{
4779 testType: clientTest,
4780 name: "UnsolicitedServerNameAck-" + ver.name,
4781 config: Config{
4782 MaxVersion: ver.version,
4783 Bugs: ProtocolBugs{
4784 SendServerNameAck: true,
4785 },
4786 },
4787 shouldFail: true,
4788 expectedError: ":UNEXPECTED_EXTENSION:",
4789 expectedLocalError: "remote error: unsupported extension",
4790 })
4791 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004792 testType: serverTest,
4793 name: "ServerNameExtensionServer-" + ver.name,
4794 config: Config{
4795 MaxVersion: ver.version,
4796 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004797 },
David Benjamin97d17d92016-07-14 16:12:00 -04004798 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004799 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004800 })
4801
4802 // Test ALPN.
4803 testCases = append(testCases, testCase{
4804 testType: clientTest,
4805 name: "ALPNClient-" + ver.name,
4806 config: Config{
4807 MaxVersion: ver.version,
4808 NextProtos: []string{"foo"},
4809 },
4810 flags: []string{
4811 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4812 "-expect-alpn", "foo",
4813 },
4814 expectedNextProto: "foo",
4815 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004816 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004817 })
4818 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004819 testType: clientTest,
4820 name: "ALPNClient-Mismatch-" + ver.name,
4821 config: Config{
4822 MaxVersion: ver.version,
4823 Bugs: ProtocolBugs{
4824 SendALPN: "baz",
4825 },
4826 },
4827 flags: []string{
4828 "-advertise-alpn", "\x03foo\x03bar",
4829 },
4830 shouldFail: true,
4831 expectedError: ":INVALID_ALPN_PROTOCOL:",
4832 expectedLocalError: "remote error: illegal parameter",
4833 })
4834 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004835 testType: serverTest,
4836 name: "ALPNServer-" + ver.name,
4837 config: Config{
4838 MaxVersion: ver.version,
4839 NextProtos: []string{"foo", "bar", "baz"},
4840 },
4841 flags: []string{
4842 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4843 "-select-alpn", "foo",
4844 },
4845 expectedNextProto: "foo",
4846 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004847 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004848 })
4849 testCases = append(testCases, testCase{
4850 testType: serverTest,
4851 name: "ALPNServer-Decline-" + ver.name,
4852 config: Config{
4853 MaxVersion: ver.version,
4854 NextProtos: []string{"foo", "bar", "baz"},
4855 },
4856 flags: []string{"-decline-alpn"},
4857 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004858 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004859 })
4860
David Benjamin25fe85b2016-08-09 20:00:32 -04004861 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4862 // called once.
4863 testCases = append(testCases, testCase{
4864 testType: serverTest,
4865 name: "ALPNServer-Async-" + ver.name,
4866 config: Config{
4867 MaxVersion: ver.version,
4868 NextProtos: []string{"foo", "bar", "baz"},
David Benjamin4eb95cc2016-11-16 17:08:23 +09004869 // Prior to TLS 1.3, exercise the asynchronous session callback.
4870 SessionTicketsDisabled: ver.version < VersionTLS13,
David Benjamin25fe85b2016-08-09 20:00:32 -04004871 },
4872 flags: []string{
4873 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4874 "-select-alpn", "foo",
4875 "-async",
4876 },
4877 expectedNextProto: "foo",
4878 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004879 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004880 })
4881
David Benjamin97d17d92016-07-14 16:12:00 -04004882 var emptyString string
4883 testCases = append(testCases, testCase{
4884 testType: clientTest,
4885 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4886 config: Config{
4887 MaxVersion: ver.version,
4888 NextProtos: []string{""},
4889 Bugs: ProtocolBugs{
4890 // A server returning an empty ALPN protocol
4891 // should be rejected.
4892 ALPNProtocol: &emptyString,
4893 },
4894 },
4895 flags: []string{
4896 "-advertise-alpn", "\x03foo",
4897 },
4898 shouldFail: true,
4899 expectedError: ":PARSE_TLSEXT:",
4900 })
4901 testCases = append(testCases, testCase{
4902 testType: serverTest,
4903 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4904 config: Config{
4905 MaxVersion: ver.version,
4906 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004907 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004908 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004909 },
David Benjamin97d17d92016-07-14 16:12:00 -04004910 flags: []string{
4911 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004912 },
David Benjamin97d17d92016-07-14 16:12:00 -04004913 shouldFail: true,
4914 expectedError: ":PARSE_TLSEXT:",
4915 })
4916
4917 // Test NPN and the interaction with ALPN.
4918 if ver.version < VersionTLS13 {
4919 // Test that the server prefers ALPN over NPN.
4920 testCases = append(testCases, testCase{
4921 testType: serverTest,
4922 name: "ALPNServer-Preferred-" + ver.name,
4923 config: Config{
4924 MaxVersion: ver.version,
4925 NextProtos: []string{"foo", "bar", "baz"},
4926 },
4927 flags: []string{
4928 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4929 "-select-alpn", "foo",
4930 "-advertise-npn", "\x03foo\x03bar\x03baz",
4931 },
4932 expectedNextProto: "foo",
4933 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004934 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004935 })
4936 testCases = append(testCases, testCase{
4937 testType: serverTest,
4938 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4939 config: Config{
4940 MaxVersion: ver.version,
4941 NextProtos: []string{"foo", "bar", "baz"},
4942 Bugs: ProtocolBugs{
4943 SwapNPNAndALPN: true,
4944 },
4945 },
4946 flags: []string{
4947 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4948 "-select-alpn", "foo",
4949 "-advertise-npn", "\x03foo\x03bar\x03baz",
4950 },
4951 expectedNextProto: "foo",
4952 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004953 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004954 })
4955
4956 // Test that negotiating both NPN and ALPN is forbidden.
4957 testCases = append(testCases, testCase{
4958 name: "NegotiateALPNAndNPN-" + ver.name,
4959 config: Config{
4960 MaxVersion: ver.version,
4961 NextProtos: []string{"foo", "bar", "baz"},
4962 Bugs: ProtocolBugs{
4963 NegotiateALPNAndNPN: true,
4964 },
4965 },
4966 flags: []string{
4967 "-advertise-alpn", "\x03foo",
4968 "-select-next-proto", "foo",
4969 },
4970 shouldFail: true,
4971 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4972 })
4973 testCases = append(testCases, testCase{
4974 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4975 config: Config{
4976 MaxVersion: ver.version,
4977 NextProtos: []string{"foo", "bar", "baz"},
4978 Bugs: ProtocolBugs{
4979 NegotiateALPNAndNPN: true,
4980 SwapNPNAndALPN: true,
4981 },
4982 },
4983 flags: []string{
4984 "-advertise-alpn", "\x03foo",
4985 "-select-next-proto", "foo",
4986 },
4987 shouldFail: true,
4988 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4989 })
David Benjamin97d17d92016-07-14 16:12:00 -04004990 }
4991
4992 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004993
4994 // Resume with a corrupt ticket.
4995 testCases = append(testCases, testCase{
4996 testType: serverTest,
4997 name: "CorruptTicket-" + ver.name,
4998 config: Config{
4999 MaxVersion: ver.version,
5000 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005001 FilterTicket: func(in []byte) ([]byte, error) {
5002 in[len(in)-1] ^= 1
5003 return in, nil
5004 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005005 },
5006 },
5007 resumeSession: true,
5008 expectResumeRejected: true,
5009 })
5010 // Test the ticket callback, with and without renewal.
5011 testCases = append(testCases, testCase{
5012 testType: serverTest,
5013 name: "TicketCallback-" + ver.name,
5014 config: Config{
5015 MaxVersion: ver.version,
5016 },
5017 resumeSession: true,
5018 flags: []string{"-use-ticket-callback"},
5019 })
5020 testCases = append(testCases, testCase{
5021 testType: serverTest,
5022 name: "TicketCallback-Renew-" + ver.name,
5023 config: Config{
5024 MaxVersion: ver.version,
5025 Bugs: ProtocolBugs{
5026 ExpectNewTicket: true,
5027 },
5028 },
5029 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5030 resumeSession: true,
5031 })
5032
5033 // Test that the ticket callback is only called once when everything before
5034 // it in the ClientHello is asynchronous. This corrupts the ticket so
5035 // certificate selection callbacks run.
5036 testCases = append(testCases, testCase{
5037 testType: serverTest,
5038 name: "TicketCallback-SingleCall-" + ver.name,
5039 config: Config{
5040 MaxVersion: ver.version,
5041 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005042 FilterTicket: func(in []byte) ([]byte, error) {
5043 in[len(in)-1] ^= 1
5044 return in, nil
5045 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005046 },
5047 },
5048 resumeSession: true,
5049 expectResumeRejected: true,
5050 flags: []string{
5051 "-use-ticket-callback",
5052 "-async",
5053 },
5054 })
5055
David Benjamind4c349b2017-02-09 14:07:17 -05005056 // Resume with various lengths of ticket session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005057 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005058 testCases = append(testCases, testCase{
5059 testType: serverTest,
David Benjamind4c349b2017-02-09 14:07:17 -05005060 name: "TicketSessionIDLength-0-" + ver.name,
David Benjamin97d17d92016-07-14 16:12:00 -04005061 config: Config{
5062 MaxVersion: ver.version,
5063 Bugs: ProtocolBugs{
David Benjamind4c349b2017-02-09 14:07:17 -05005064 EmptyTicketSessionID: true,
5065 },
5066 },
5067 resumeSession: true,
5068 })
5069 testCases = append(testCases, testCase{
5070 testType: serverTest,
5071 name: "TicketSessionIDLength-16-" + ver.name,
5072 config: Config{
5073 MaxVersion: ver.version,
5074 Bugs: ProtocolBugs{
5075 TicketSessionIDLength: 16,
5076 },
5077 },
5078 resumeSession: true,
5079 })
5080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "TicketSessionIDLength-32-" + ver.name,
5083 config: Config{
5084 MaxVersion: ver.version,
5085 Bugs: ProtocolBugs{
5086 TicketSessionIDLength: 32,
5087 },
5088 },
5089 resumeSession: true,
5090 })
5091 testCases = append(testCases, testCase{
5092 testType: serverTest,
5093 name: "TicketSessionIDLength-33-" + ver.name,
5094 config: Config{
5095 MaxVersion: ver.version,
5096 Bugs: ProtocolBugs{
5097 TicketSessionIDLength: 33,
David Benjamin97d17d92016-07-14 16:12:00 -04005098 },
5099 },
5100 resumeSession: true,
5101 shouldFail: true,
David Benjamind4c349b2017-02-09 14:07:17 -05005102 // The maximum session ID length is 32.
David Benjamin97d17d92016-07-14 16:12:00 -04005103 expectedError: ":DECODE_ERROR:",
5104 })
5105 }
5106
5107 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5108 // are ignored.
5109 if ver.hasDTLS {
5110 testCases = append(testCases, testCase{
5111 protocol: dtls,
5112 name: "SRTP-Client-" + ver.name,
5113 config: Config{
5114 MaxVersion: ver.version,
5115 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5116 },
5117 flags: []string{
5118 "-srtp-profiles",
5119 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5120 },
5121 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5122 })
5123 testCases = append(testCases, testCase{
5124 protocol: dtls,
5125 testType: serverTest,
5126 name: "SRTP-Server-" + ver.name,
5127 config: Config{
5128 MaxVersion: ver.version,
5129 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5130 },
5131 flags: []string{
5132 "-srtp-profiles",
5133 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5134 },
5135 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5136 })
5137 // Test that the MKI is ignored.
5138 testCases = append(testCases, testCase{
5139 protocol: dtls,
5140 testType: serverTest,
5141 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5142 config: Config{
5143 MaxVersion: ver.version,
5144 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5145 Bugs: ProtocolBugs{
5146 SRTPMasterKeyIdentifer: "bogus",
5147 },
5148 },
5149 flags: []string{
5150 "-srtp-profiles",
5151 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5152 },
5153 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5154 })
5155 // Test that SRTP isn't negotiated on the server if there were
5156 // no matching profiles.
5157 testCases = append(testCases, testCase{
5158 protocol: dtls,
5159 testType: serverTest,
5160 name: "SRTP-Server-NoMatch-" + ver.name,
5161 config: Config{
5162 MaxVersion: ver.version,
5163 SRTPProtectionProfiles: []uint16{100, 101, 102},
5164 },
5165 flags: []string{
5166 "-srtp-profiles",
5167 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5168 },
5169 expectedSRTPProtectionProfile: 0,
5170 })
5171 // Test that the server returning an invalid SRTP profile is
5172 // flagged as an error by the client.
5173 testCases = append(testCases, testCase{
5174 protocol: dtls,
5175 name: "SRTP-Client-NoMatch-" + ver.name,
5176 config: Config{
5177 MaxVersion: ver.version,
5178 Bugs: ProtocolBugs{
5179 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5180 },
5181 },
5182 flags: []string{
5183 "-srtp-profiles",
5184 "SRTP_AES128_CM_SHA1_80",
5185 },
5186 shouldFail: true,
5187 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5188 })
5189 }
5190
5191 // Test SCT list.
5192 testCases = append(testCases, testCase{
5193 name: "SignedCertificateTimestampList-Client-" + ver.name,
5194 testType: clientTest,
5195 config: Config{
5196 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005197 },
David Benjamin97d17d92016-07-14 16:12:00 -04005198 flags: []string{
5199 "-enable-signed-cert-timestamps",
5200 "-expect-signed-cert-timestamps",
5201 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005202 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005203 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005204 })
David Benjamindaa88502016-10-04 16:32:16 -04005205
Adam Langleycfa08c32016-11-17 13:21:27 -08005206 var differentSCTList []byte
5207 differentSCTList = append(differentSCTList, testSCTList...)
5208 differentSCTList[len(differentSCTList)-1] ^= 1
5209
David Benjamindaa88502016-10-04 16:32:16 -04005210 // The SCT extension did not specify that it must only be sent on resumption as it
5211 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005212 testCases = append(testCases, testCase{
5213 name: "SendSCTListOnResume-" + ver.name,
5214 config: Config{
5215 MaxVersion: ver.version,
5216 Bugs: ProtocolBugs{
Adam Langleycfa08c32016-11-17 13:21:27 -08005217 SendSCTListOnResume: differentSCTList,
David Benjamin97d17d92016-07-14 16:12:00 -04005218 },
David Benjamind98452d2015-06-16 14:16:23 -04005219 },
David Benjamin97d17d92016-07-14 16:12:00 -04005220 flags: []string{
5221 "-enable-signed-cert-timestamps",
5222 "-expect-signed-cert-timestamps",
5223 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005224 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005225 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005226 })
David Benjamindaa88502016-10-04 16:32:16 -04005227
David Benjamin97d17d92016-07-14 16:12:00 -04005228 testCases = append(testCases, testCase{
5229 name: "SignedCertificateTimestampList-Server-" + ver.name,
5230 testType: serverTest,
5231 config: Config{
5232 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005233 },
David Benjamin97d17d92016-07-14 16:12:00 -04005234 flags: []string{
5235 "-signed-cert-timestamps",
5236 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005237 },
David Benjamin97d17d92016-07-14 16:12:00 -04005238 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005239 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005240 })
David Benjamin53210cb2016-11-16 09:01:48 +09005241
Adam Langleycfa08c32016-11-17 13:21:27 -08005242 emptySCTListCert := *testCerts[0].cert
5243 emptySCTListCert.SignedCertificateTimestampList = []byte{0, 0}
5244
5245 // Test empty SCT list.
5246 testCases = append(testCases, testCase{
5247 name: "SignedCertificateTimestampListEmpty-Client-" + ver.name,
5248 testType: clientTest,
5249 config: Config{
5250 MaxVersion: ver.version,
5251 Certificates: []Certificate{emptySCTListCert},
5252 },
5253 flags: []string{
5254 "-enable-signed-cert-timestamps",
5255 },
5256 shouldFail: true,
5257 expectedError: ":ERROR_PARSING_EXTENSION:",
5258 })
5259
5260 emptySCTCert := *testCerts[0].cert
5261 emptySCTCert.SignedCertificateTimestampList = []byte{0, 6, 0, 2, 1, 2, 0, 0}
5262
5263 // Test empty SCT in non-empty list.
5264 testCases = append(testCases, testCase{
5265 name: "SignedCertificateTimestampListEmptySCT-Client-" + ver.name,
5266 testType: clientTest,
5267 config: Config{
5268 MaxVersion: ver.version,
5269 Certificates: []Certificate{emptySCTCert},
5270 },
5271 flags: []string{
5272 "-enable-signed-cert-timestamps",
5273 },
5274 shouldFail: true,
5275 expectedError: ":ERROR_PARSING_EXTENSION:",
5276 })
5277
David Benjamin53210cb2016-11-16 09:01:48 +09005278 // Test that certificate-related extensions are not sent unsolicited.
5279 testCases = append(testCases, testCase{
5280 testType: serverTest,
5281 name: "UnsolicitedCertificateExtensions-" + ver.name,
5282 config: Config{
5283 MaxVersion: ver.version,
5284 Bugs: ProtocolBugs{
5285 NoOCSPStapling: true,
5286 NoSignedCertificateTimestamps: true,
5287 },
5288 },
5289 flags: []string{
5290 "-ocsp-response",
5291 base64.StdEncoding.EncodeToString(testOCSPResponse),
5292 "-signed-cert-timestamps",
5293 base64.StdEncoding.EncodeToString(testSCTList),
5294 },
5295 })
David Benjamin97d17d92016-07-14 16:12:00 -04005296 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005297
Paul Lietar4fac72e2015-09-09 13:44:55 +01005298 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005299 testType: clientTest,
5300 name: "ClientHelloPadding",
5301 config: Config{
5302 Bugs: ProtocolBugs{
5303 RequireClientHelloSize: 512,
5304 },
5305 },
5306 // This hostname just needs to be long enough to push the
5307 // ClientHello into F5's danger zone between 256 and 511 bytes
5308 // long.
5309 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5310 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005311
5312 // Extensions should not function in SSL 3.0.
5313 testCases = append(testCases, testCase{
5314 testType: serverTest,
5315 name: "SSLv3Extensions-NoALPN",
5316 config: Config{
5317 MaxVersion: VersionSSL30,
5318 NextProtos: []string{"foo", "bar", "baz"},
5319 },
5320 flags: []string{
5321 "-select-alpn", "foo",
5322 },
5323 expectNoNextProto: true,
5324 })
5325
5326 // Test session tickets separately as they follow a different codepath.
5327 testCases = append(testCases, testCase{
5328 testType: serverTest,
5329 name: "SSLv3Extensions-NoTickets",
5330 config: Config{
5331 MaxVersion: VersionSSL30,
5332 Bugs: ProtocolBugs{
5333 // Historically, session tickets in SSL 3.0
5334 // failed in different ways depending on whether
5335 // the client supported renegotiation_info.
5336 NoRenegotiationInfo: true,
5337 },
5338 },
5339 resumeSession: true,
5340 })
5341 testCases = append(testCases, testCase{
5342 testType: serverTest,
5343 name: "SSLv3Extensions-NoTickets2",
5344 config: Config{
5345 MaxVersion: VersionSSL30,
5346 },
5347 resumeSession: true,
5348 })
5349
5350 // But SSL 3.0 does send and process renegotiation_info.
5351 testCases = append(testCases, testCase{
5352 testType: serverTest,
5353 name: "SSLv3Extensions-RenegotiationInfo",
5354 config: Config{
5355 MaxVersion: VersionSSL30,
5356 Bugs: ProtocolBugs{
5357 RequireRenegotiationInfo: true,
5358 },
5359 },
David Benjamind2610042017-01-03 10:49:28 -05005360 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005361 })
5362 testCases = append(testCases, testCase{
5363 testType: serverTest,
5364 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5365 config: Config{
5366 MaxVersion: VersionSSL30,
5367 Bugs: ProtocolBugs{
5368 NoRenegotiationInfo: true,
5369 SendRenegotiationSCSV: true,
5370 RequireRenegotiationInfo: true,
5371 },
5372 },
David Benjamind2610042017-01-03 10:49:28 -05005373 flags: []string{"-expect-secure-renegotiation"},
David Benjaminc7ce9772015-10-09 19:32:41 -04005374 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005375
5376 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5377 // in ServerHello.
5378 testCases = append(testCases, testCase{
5379 name: "NPN-Forbidden-TLS13",
5380 config: Config{
5381 MaxVersion: VersionTLS13,
5382 NextProtos: []string{"foo"},
5383 Bugs: ProtocolBugs{
5384 NegotiateNPNAtAllVersions: true,
5385 },
5386 },
5387 flags: []string{"-select-next-proto", "foo"},
5388 shouldFail: true,
5389 expectedError: ":ERROR_PARSING_EXTENSION:",
5390 })
5391 testCases = append(testCases, testCase{
5392 name: "EMS-Forbidden-TLS13",
5393 config: Config{
5394 MaxVersion: VersionTLS13,
5395 Bugs: ProtocolBugs{
5396 NegotiateEMSAtAllVersions: true,
5397 },
5398 },
5399 shouldFail: true,
5400 expectedError: ":ERROR_PARSING_EXTENSION:",
5401 })
5402 testCases = append(testCases, testCase{
5403 name: "RenegotiationInfo-Forbidden-TLS13",
5404 config: Config{
5405 MaxVersion: VersionTLS13,
5406 Bugs: ProtocolBugs{
5407 NegotiateRenegotiationInfoAtAllVersions: true,
5408 },
5409 },
5410 shouldFail: true,
5411 expectedError: ":ERROR_PARSING_EXTENSION:",
5412 })
5413 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005414 name: "Ticket-Forbidden-TLS13",
5415 config: Config{
5416 MaxVersion: VersionTLS12,
5417 },
5418 resumeConfig: &Config{
5419 MaxVersion: VersionTLS13,
5420 Bugs: ProtocolBugs{
5421 AdvertiseTicketExtension: true,
5422 },
5423 },
5424 resumeSession: true,
5425 shouldFail: true,
5426 expectedError: ":ERROR_PARSING_EXTENSION:",
5427 })
5428
5429 // Test that illegal extensions in TLS 1.3 are declined by the server if
5430 // offered in ClientHello. The runner's server will fail if this occurs,
5431 // so we exercise the offering path. (EMS and Renegotiation Info are
5432 // implicit in every test.)
5433 testCases = append(testCases, testCase{
5434 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005435 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005436 config: Config{
5437 MaxVersion: VersionTLS13,
5438 NextProtos: []string{"bar"},
5439 },
5440 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5441 })
David Benjamin196df5b2016-09-21 16:23:27 -04005442
David Benjamindaa88502016-10-04 16:32:16 -04005443 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5444 // tolerated.
5445 testCases = append(testCases, testCase{
5446 name: "SendOCSPResponseOnResume-TLS12",
5447 config: Config{
5448 MaxVersion: VersionTLS12,
5449 Bugs: ProtocolBugs{
5450 SendOCSPResponseOnResume: []byte("bogus"),
5451 },
5452 },
5453 flags: []string{
5454 "-enable-ocsp-stapling",
5455 "-expect-ocsp-response",
5456 base64.StdEncoding.EncodeToString(testOCSPResponse),
5457 },
5458 resumeSession: true,
5459 })
5460
David Benjamindaa88502016-10-04 16:32:16 -04005461 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005462 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005463 config: Config{
5464 MaxVersion: VersionTLS13,
5465 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005466 SendExtensionOnCertificate: testOCSPExtension,
5467 },
5468 },
5469 shouldFail: true,
5470 expectedError: ":UNEXPECTED_EXTENSION:",
5471 })
5472
5473 testCases = append(testCases, testCase{
5474 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5475 config: Config{
5476 MaxVersion: VersionTLS13,
5477 Bugs: ProtocolBugs{
5478 SendExtensionOnCertificate: testSCTExtension,
5479 },
5480 },
5481 shouldFail: true,
5482 expectedError: ":UNEXPECTED_EXTENSION:",
5483 })
5484
5485 // Test that extensions on client certificates are never accepted.
5486 testCases = append(testCases, testCase{
5487 name: "SendExtensionOnClientCertificate-TLS13",
5488 testType: serverTest,
5489 config: Config{
5490 MaxVersion: VersionTLS13,
5491 Certificates: []Certificate{rsaCertificate},
5492 Bugs: ProtocolBugs{
5493 SendExtensionOnCertificate: testOCSPExtension,
5494 },
5495 },
5496 flags: []string{
5497 "-enable-ocsp-stapling",
5498 "-require-any-client-certificate",
5499 },
5500 shouldFail: true,
5501 expectedError: ":UNEXPECTED_EXTENSION:",
5502 })
5503
5504 testCases = append(testCases, testCase{
5505 name: "SendUnknownExtensionOnCertificate-TLS13",
5506 config: Config{
5507 MaxVersion: VersionTLS13,
5508 Bugs: ProtocolBugs{
5509 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5510 },
5511 },
5512 shouldFail: true,
5513 expectedError: ":UNEXPECTED_EXTENSION:",
5514 })
5515
Adam Langleycfa08c32016-11-17 13:21:27 -08005516 var differentSCTList []byte
5517 differentSCTList = append(differentSCTList, testSCTList...)
5518 differentSCTList[len(differentSCTList)-1] ^= 1
5519
Steven Valdeza833c352016-11-01 13:39:36 -04005520 // Test that extensions on intermediates are allowed but ignored.
5521 testCases = append(testCases, testCase{
5522 name: "IgnoreExtensionsOnIntermediates-TLS13",
5523 config: Config{
5524 MaxVersion: VersionTLS13,
5525 Certificates: []Certificate{rsaChainCertificate},
5526 Bugs: ProtocolBugs{
5527 // Send different values on the intermediate. This tests
5528 // the intermediate's extensions do not override the
5529 // leaf's.
5530 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
Adam Langleycfa08c32016-11-17 13:21:27 -08005531 SendSCTOnIntermediates: differentSCTList,
David Benjamindaa88502016-10-04 16:32:16 -04005532 },
5533 },
5534 flags: []string{
5535 "-enable-ocsp-stapling",
5536 "-expect-ocsp-response",
5537 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005538 "-enable-signed-cert-timestamps",
5539 "-expect-signed-cert-timestamps",
5540 base64.StdEncoding.EncodeToString(testSCTList),
5541 },
5542 resumeSession: true,
5543 })
5544
5545 // Test that extensions are not sent on intermediates when configured
5546 // only for a leaf.
5547 testCases = append(testCases, testCase{
5548 testType: serverTest,
5549 name: "SendNoExtensionsOnIntermediate-TLS13",
5550 config: Config{
5551 MaxVersion: VersionTLS13,
5552 Bugs: ProtocolBugs{
5553 ExpectNoExtensionsOnIntermediate: true,
5554 },
5555 },
5556 flags: []string{
5557 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5558 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5559 "-ocsp-response",
5560 base64.StdEncoding.EncodeToString(testOCSPResponse),
5561 "-signed-cert-timestamps",
5562 base64.StdEncoding.EncodeToString(testSCTList),
5563 },
5564 })
5565
5566 // Test that extensions are not sent on client certificates.
5567 testCases = append(testCases, testCase{
5568 name: "SendNoClientCertificateExtensions-TLS13",
5569 config: Config{
5570 MaxVersion: VersionTLS13,
5571 ClientAuth: RequireAnyClientCert,
5572 },
5573 flags: []string{
5574 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5575 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5576 "-ocsp-response",
5577 base64.StdEncoding.EncodeToString(testOCSPResponse),
5578 "-signed-cert-timestamps",
5579 base64.StdEncoding.EncodeToString(testSCTList),
5580 },
5581 })
5582
5583 testCases = append(testCases, testCase{
5584 name: "SendDuplicateExtensionsOnCerts-TLS13",
5585 config: Config{
5586 MaxVersion: VersionTLS13,
5587 Bugs: ProtocolBugs{
5588 SendDuplicateCertExtensions: true,
5589 },
5590 },
5591 flags: []string{
5592 "-enable-ocsp-stapling",
5593 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005594 },
5595 resumeSession: true,
5596 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005597 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005598 })
Adam Langley9b885c52016-11-18 14:21:03 -08005599
5600 testCases = append(testCases, testCase{
5601 name: "SignedCertificateTimestampListInvalid-Server",
5602 testType: serverTest,
5603 flags: []string{
5604 "-signed-cert-timestamps",
5605 base64.StdEncoding.EncodeToString([]byte{0, 0}),
5606 },
Steven Valdeza4ee74d2016-11-29 13:36:45 -05005607 shouldFail: true,
Adam Langley9b885c52016-11-18 14:21:03 -08005608 expectedError: ":INVALID_SCT_LIST:",
5609 })
David Benjamine78bfde2014-09-06 12:45:15 -04005610}
5611
David Benjamin01fe8202014-09-24 15:21:44 -04005612func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005613 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005614 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005615 // SSL 3.0 does not have tickets and TLS 1.3 does not
5616 // have session IDs, so skip their cross-resumption
5617 // tests.
5618 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5619 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5620 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005621 }
5622
David Benjamin8b8c0062014-11-23 02:47:52 -05005623 protocols := []protocol{tls}
5624 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5625 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005626 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005627 for _, protocol := range protocols {
5628 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5629 if protocol == dtls {
5630 suffix += "-DTLS"
5631 }
5632
David Benjaminece3de92015-03-16 18:02:20 -04005633 if sessionVers.version == resumeVers.version {
5634 testCases = append(testCases, testCase{
5635 protocol: protocol,
5636 name: "Resume-Client" + suffix,
5637 resumeSession: true,
5638 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005639 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005640 Bugs: ProtocolBugs{
5641 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5642 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5643 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005644 },
David Benjaminece3de92015-03-16 18:02:20 -04005645 expectedVersion: sessionVers.version,
5646 expectedResumeVersion: resumeVers.version,
5647 })
5648 } else {
David Benjamin405da482016-08-08 17:25:07 -04005649 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5650
5651 // Offering a TLS 1.3 session sends an empty session ID, so
5652 // there is no way to convince a non-lookahead client the
5653 // session was resumed. It will appear to the client that a
5654 // stray ChangeCipherSpec was sent.
5655 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5656 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005657 }
5658
David Benjaminece3de92015-03-16 18:02:20 -04005659 testCases = append(testCases, testCase{
5660 protocol: protocol,
5661 name: "Resume-Client-Mismatch" + suffix,
5662 resumeSession: true,
5663 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005664 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005665 },
David Benjaminece3de92015-03-16 18:02:20 -04005666 expectedVersion: sessionVers.version,
5667 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005668 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005669 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005670 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005671 },
5672 },
5673 expectedResumeVersion: resumeVers.version,
5674 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005675 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005676 })
5677 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005678
5679 testCases = append(testCases, testCase{
5680 protocol: protocol,
5681 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005682 resumeSession: true,
5683 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005684 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005685 },
5686 expectedVersion: sessionVers.version,
5687 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005688 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005689 },
5690 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005691 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005692 expectedResumeVersion: resumeVers.version,
5693 })
5694
David Benjamin8b8c0062014-11-23 02:47:52 -05005695 testCases = append(testCases, testCase{
5696 protocol: protocol,
5697 testType: serverTest,
5698 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005699 resumeSession: true,
5700 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005701 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005702 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005703 expectedVersion: sessionVers.version,
5704 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005705 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005706 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005707 Bugs: ProtocolBugs{
5708 SendBothTickets: true,
5709 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005710 },
5711 expectedResumeVersion: resumeVers.version,
5712 })
5713 }
David Benjamin01fe8202014-09-24 15:21:44 -04005714 }
5715 }
David Benjaminece3de92015-03-16 18:02:20 -04005716
David Benjamin4199b0d2016-11-01 13:58:25 -04005717 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005718 testCases = append(testCases, testCase{
5719 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005720 name: "ShimTicketRewritable",
5721 resumeSession: true,
5722 config: Config{
5723 MaxVersion: VersionTLS12,
5724 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5725 Bugs: ProtocolBugs{
5726 FilterTicket: func(in []byte) ([]byte, error) {
5727 in, err := SetShimTicketVersion(in, VersionTLS12)
5728 if err != nil {
5729 return nil, err
5730 }
5731 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5732 },
5733 },
5734 },
5735 flags: []string{
5736 "-ticket-key",
5737 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5738 },
5739 })
5740
5741 // Resumptions are declined if the version does not match.
5742 testCases = append(testCases, testCase{
5743 testType: serverTest,
5744 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005745 resumeSession: true,
5746 config: Config{
5747 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005748 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005749 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005750 FilterTicket: func(in []byte) ([]byte, error) {
5751 return SetShimTicketVersion(in, VersionTLS13)
5752 },
5753 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005754 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005755 flags: []string{
5756 "-ticket-key",
5757 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5758 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005759 expectResumeRejected: true,
5760 })
5761
5762 testCases = append(testCases, testCase{
5763 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005764 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005765 resumeSession: true,
5766 config: Config{
5767 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005768 Bugs: ProtocolBugs{
5769 FilterTicket: func(in []byte) ([]byte, error) {
5770 return SetShimTicketVersion(in, VersionTLS12)
5771 },
5772 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005773 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005774 flags: []string{
5775 "-ticket-key",
5776 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5777 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005778 expectResumeRejected: true,
5779 })
5780
David Benjamin4199b0d2016-11-01 13:58:25 -04005781 // Resumptions are declined if the cipher is invalid or disabled.
5782 testCases = append(testCases, testCase{
5783 testType: serverTest,
5784 name: "Resume-Server-DeclineBadCipher",
5785 resumeSession: true,
5786 config: Config{
5787 MaxVersion: VersionTLS12,
5788 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005789 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005790 FilterTicket: func(in []byte) ([]byte, error) {
5791 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5792 },
5793 },
5794 },
5795 flags: []string{
5796 "-ticket-key",
5797 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5798 },
5799 expectResumeRejected: true,
5800 })
5801
5802 testCases = append(testCases, testCase{
5803 testType: serverTest,
5804 name: "Resume-Server-DeclineBadCipher-2",
5805 resumeSession: true,
5806 config: Config{
5807 MaxVersion: VersionTLS12,
5808 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005809 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005810 FilterTicket: func(in []byte) ([]byte, error) {
5811 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5812 },
5813 },
5814 },
5815 flags: []string{
5816 "-cipher", "AES128",
5817 "-ticket-key",
5818 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5819 },
5820 expectResumeRejected: true,
5821 })
5822
David Benjaminf01f42a2016-11-16 19:05:33 +09005823 // Sessions are not resumed if they do not use the preferred cipher.
5824 testCases = append(testCases, testCase{
5825 testType: serverTest,
5826 name: "Resume-Server-CipherNotPreferred",
5827 resumeSession: true,
5828 config: Config{
5829 MaxVersion: VersionTLS12,
5830 Bugs: ProtocolBugs{
5831 ExpectNewTicket: true,
5832 FilterTicket: func(in []byte) ([]byte, error) {
5833 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA)
5834 },
5835 },
5836 },
5837 flags: []string{
5838 "-ticket-key",
5839 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5840 },
5841 shouldFail: false,
5842 expectResumeRejected: true,
5843 })
5844
5845 // TLS 1.3 allows sessions to be resumed at a different cipher if their
5846 // PRF hashes match, but BoringSSL will always decline such resumptions.
5847 testCases = append(testCases, testCase{
5848 testType: serverTest,
5849 name: "Resume-Server-CipherNotPreferred-TLS13",
5850 resumeSession: true,
5851 config: Config{
5852 MaxVersion: VersionTLS13,
5853 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256, TLS_AES_128_GCM_SHA256},
5854 Bugs: ProtocolBugs{
5855 FilterTicket: func(in []byte) ([]byte, error) {
5856 // If the client (runner) offers ChaCha20-Poly1305 first, the
5857 // server (shim) always prefers it. Switch it to AES-GCM.
5858 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5859 },
5860 },
5861 },
5862 flags: []string{
5863 "-ticket-key",
5864 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5865 },
5866 shouldFail: false,
5867 expectResumeRejected: true,
5868 })
5869
5870 // Sessions may not be resumed if they contain another version's cipher.
David Benjamin4199b0d2016-11-01 13:58:25 -04005871 testCases = append(testCases, testCase{
5872 testType: serverTest,
5873 name: "Resume-Server-DeclineBadCipher-TLS13",
5874 resumeSession: true,
5875 config: Config{
5876 MaxVersion: VersionTLS13,
5877 Bugs: ProtocolBugs{
5878 FilterTicket: func(in []byte) ([]byte, error) {
5879 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5880 },
5881 },
5882 },
5883 flags: []string{
5884 "-ticket-key",
5885 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5886 },
5887 expectResumeRejected: true,
5888 })
5889
David Benjaminf01f42a2016-11-16 19:05:33 +09005890 // If the client does not offer the cipher from the session, decline to
5891 // resume. Clients are forbidden from doing this, but BoringSSL selects
5892 // the cipher first, so we only decline.
David Benjamin75f99142016-11-12 12:36:06 +09005893 testCases = append(testCases, testCase{
5894 testType: serverTest,
5895 name: "Resume-Server-UnofferedCipher",
5896 resumeSession: true,
5897 config: Config{
5898 MaxVersion: VersionTLS12,
5899 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5900 },
5901 resumeConfig: &Config{
5902 MaxVersion: VersionTLS12,
5903 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5904 Bugs: ProtocolBugs{
5905 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5906 },
5907 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005908 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005909 })
5910
David Benjaminf01f42a2016-11-16 19:05:33 +09005911 // In TLS 1.3, clients may advertise a cipher list which does not
5912 // include the selected cipher. Test that we tolerate this. Servers may
5913 // resume at another cipher if the PRF matches, but BoringSSL will
5914 // always decline.
David Benjamin75f99142016-11-12 12:36:06 +09005915 testCases = append(testCases, testCase{
5916 testType: serverTest,
5917 name: "Resume-Server-UnofferedCipher-TLS13",
5918 resumeSession: true,
5919 config: Config{
5920 MaxVersion: VersionTLS13,
5921 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5922 },
5923 resumeConfig: &Config{
5924 MaxVersion: VersionTLS13,
5925 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5926 Bugs: ProtocolBugs{
5927 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5928 },
5929 },
David Benjaminf01f42a2016-11-16 19:05:33 +09005930 expectResumeRejected: true,
David Benjamin75f99142016-11-12 12:36:06 +09005931 })
5932
David Benjamin4199b0d2016-11-01 13:58:25 -04005933 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005934 testCases = append(testCases, testCase{
5935 name: "Resume-Client-CipherMismatch",
5936 resumeSession: true,
5937 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005938 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005939 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5940 },
5941 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005942 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005943 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5944 Bugs: ProtocolBugs{
5945 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5946 },
5947 },
5948 shouldFail: true,
5949 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5950 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005951
David Benjamine1cc35e2016-11-16 16:25:58 +09005952 // Session resumption in TLS 1.3 may change the cipher suite if the PRF
5953 // matches.
Steven Valdez4aa154e2016-07-29 14:32:55 -04005954 testCases = append(testCases, testCase{
5955 name: "Resume-Client-CipherMismatch-TLS13",
5956 resumeSession: true,
5957 config: Config{
5958 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005959 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005960 },
5961 resumeConfig: &Config{
5962 MaxVersion: VersionTLS13,
David Benjamine1cc35e2016-11-16 16:25:58 +09005963 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5964 },
5965 })
5966
5967 // Session resumption in TLS 1.3 is forbidden if the PRF does not match.
5968 testCases = append(testCases, testCase{
5969 name: "Resume-Client-PRFMismatch-TLS13",
5970 resumeSession: true,
5971 config: Config{
5972 MaxVersion: VersionTLS13,
5973 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5974 },
5975 resumeConfig: &Config{
5976 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005977 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005978 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005979 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005980 },
5981 },
5982 shouldFail: true,
David Benjamine1cc35e2016-11-16 16:25:58 +09005983 expectedError: ":OLD_SESSION_PRF_HASH_MISMATCH:",
Steven Valdez4aa154e2016-07-29 14:32:55 -04005984 })
Steven Valdeza833c352016-11-01 13:39:36 -04005985
5986 testCases = append(testCases, testCase{
5987 testType: serverTest,
5988 name: "Resume-Server-BinderWrongLength",
5989 resumeSession: true,
5990 config: Config{
5991 MaxVersion: VersionTLS13,
5992 Bugs: ProtocolBugs{
5993 SendShortPSKBinder: true,
5994 },
5995 },
5996 shouldFail: true,
5997 expectedLocalError: "remote error: error decrypting message",
5998 expectedError: ":DIGEST_CHECK_FAILED:",
5999 })
6000
6001 testCases = append(testCases, testCase{
6002 testType: serverTest,
6003 name: "Resume-Server-NoPSKBinder",
6004 resumeSession: true,
6005 config: Config{
6006 MaxVersion: VersionTLS13,
6007 Bugs: ProtocolBugs{
6008 SendNoPSKBinder: true,
6009 },
6010 },
6011 shouldFail: true,
6012 expectedLocalError: "remote error: error decoding message",
6013 expectedError: ":DECODE_ERROR:",
6014 })
6015
6016 testCases = append(testCases, testCase{
6017 testType: serverTest,
David Benjaminaedf3032016-12-01 16:47:56 -05006018 name: "Resume-Server-ExtraPSKBinder",
6019 resumeSession: true,
6020 config: Config{
6021 MaxVersion: VersionTLS13,
6022 Bugs: ProtocolBugs{
6023 SendExtraPSKBinder: true,
6024 },
6025 },
6026 shouldFail: true,
6027 expectedLocalError: "remote error: illegal parameter",
6028 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6029 })
6030
6031 testCases = append(testCases, testCase{
6032 testType: serverTest,
6033 name: "Resume-Server-ExtraIdentityNoBinder",
6034 resumeSession: true,
6035 config: Config{
6036 MaxVersion: VersionTLS13,
6037 Bugs: ProtocolBugs{
6038 ExtraPSKIdentity: true,
6039 },
6040 },
6041 shouldFail: true,
6042 expectedLocalError: "remote error: illegal parameter",
6043 expectedError: ":PSK_IDENTITY_BINDER_COUNT_MISMATCH:",
6044 })
6045
6046 testCases = append(testCases, testCase{
6047 testType: serverTest,
Steven Valdeza833c352016-11-01 13:39:36 -04006048 name: "Resume-Server-InvalidPSKBinder",
6049 resumeSession: true,
6050 config: Config{
6051 MaxVersion: VersionTLS13,
6052 Bugs: ProtocolBugs{
6053 SendInvalidPSKBinder: true,
6054 },
6055 },
6056 shouldFail: true,
6057 expectedLocalError: "remote error: error decrypting message",
6058 expectedError: ":DIGEST_CHECK_FAILED:",
6059 })
6060
6061 testCases = append(testCases, testCase{
6062 testType: serverTest,
6063 name: "Resume-Server-PSKBinderFirstExtension",
6064 resumeSession: true,
6065 config: Config{
6066 MaxVersion: VersionTLS13,
6067 Bugs: ProtocolBugs{
6068 PSKBinderFirst: true,
6069 },
6070 },
6071 shouldFail: true,
6072 expectedLocalError: "remote error: illegal parameter",
6073 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
6074 })
David Benjamin01fe8202014-09-24 15:21:44 -04006075}
6076
Adam Langley2ae77d22014-10-28 17:29:33 -07006077func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04006078 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04006079 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006080 testType: serverTest,
6081 name: "Renegotiate-Server-Forbidden",
6082 config: Config{
6083 MaxVersion: VersionTLS12,
6084 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006085 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04006086 shouldFail: true,
6087 expectedError: ":NO_RENEGOTIATION:",
6088 expectedLocalError: "remote error: no renegotiation",
6089 })
Adam Langley5021b222015-06-12 18:27:58 -07006090 // The server shouldn't echo the renegotiation extension unless
6091 // requested by the client.
6092 testCases = append(testCases, testCase{
6093 testType: serverTest,
6094 name: "Renegotiate-Server-NoExt",
6095 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006096 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006097 Bugs: ProtocolBugs{
6098 NoRenegotiationInfo: true,
6099 RequireRenegotiationInfo: true,
6100 },
6101 },
6102 shouldFail: true,
6103 expectedLocalError: "renegotiation extension missing",
6104 })
6105 // The renegotiation SCSV should be sufficient for the server to echo
6106 // the extension.
6107 testCases = append(testCases, testCase{
6108 testType: serverTest,
6109 name: "Renegotiate-Server-NoExt-SCSV",
6110 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006111 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07006112 Bugs: ProtocolBugs{
6113 NoRenegotiationInfo: true,
6114 SendRenegotiationSCSV: true,
6115 RequireRenegotiationInfo: true,
6116 },
6117 },
6118 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07006119 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006120 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04006121 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006122 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04006123 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04006124 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04006125 },
6126 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006127 renegotiate: 1,
6128 flags: []string{
6129 "-renegotiate-freely",
6130 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006131 "-expect-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006132 },
David Benjamincdea40c2015-03-19 14:09:43 -04006133 })
6134 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006135 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006136 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006137 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006138 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006139 Bugs: ProtocolBugs{
6140 EmptyRenegotiationInfo: true,
6141 },
6142 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006143 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006144 shouldFail: true,
6145 expectedError: ":RENEGOTIATION_MISMATCH:",
6146 })
6147 testCases = append(testCases, testCase{
6148 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006149 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006150 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006151 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006152 Bugs: ProtocolBugs{
6153 BadRenegotiationInfo: true,
6154 },
6155 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006156 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006157 shouldFail: true,
6158 expectedError: ":RENEGOTIATION_MISMATCH:",
6159 })
6160 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05006161 name: "Renegotiate-Client-Downgrade",
6162 renegotiate: 1,
6163 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006164 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006165 Bugs: ProtocolBugs{
6166 NoRenegotiationInfoAfterInitial: true,
6167 },
6168 },
6169 flags: []string{"-renegotiate-freely"},
6170 shouldFail: true,
6171 expectedError: ":RENEGOTIATION_MISMATCH:",
6172 })
6173 testCases = append(testCases, testCase{
6174 name: "Renegotiate-Client-Upgrade",
6175 renegotiate: 1,
6176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006177 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05006178 Bugs: ProtocolBugs{
6179 NoRenegotiationInfoInInitial: true,
6180 },
6181 },
6182 flags: []string{"-renegotiate-freely"},
6183 shouldFail: true,
6184 expectedError: ":RENEGOTIATION_MISMATCH:",
6185 })
6186 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04006187 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006188 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04006189 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006190 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04006191 Bugs: ProtocolBugs{
6192 NoRenegotiationInfo: true,
6193 },
6194 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006195 flags: []string{
6196 "-renegotiate-freely",
6197 "-expect-total-renegotiations", "1",
David Benjamind2610042017-01-03 10:49:28 -05006198 "-expect-no-secure-renegotiation",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006199 },
David Benjamincff0b902015-05-15 23:09:47 -04006200 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006201
6202 // Test that the server may switch ciphers on renegotiation without
6203 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006204 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006205 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006206 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006207 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006208 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006209 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006210 },
6211 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006212 flags: []string{
6213 "-renegotiate-freely",
6214 "-expect-total-renegotiations", "1",
6215 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006216 })
6217 testCases = append(testCases, testCase{
6218 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006219 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006220 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006221 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006222 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6223 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006224 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006225 flags: []string{
6226 "-renegotiate-freely",
6227 "-expect-total-renegotiations", "1",
6228 },
David Benjaminb16346b2015-04-08 19:16:58 -04006229 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006230
6231 // Test that the server may not switch versions on renegotiation.
6232 testCases = append(testCases, testCase{
6233 name: "Renegotiate-Client-SwitchVersion",
6234 config: Config{
6235 MaxVersion: VersionTLS12,
6236 // Pick a cipher which exists at both versions.
6237 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6238 Bugs: ProtocolBugs{
6239 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006240 // Avoid failing early at the record layer.
6241 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006242 },
6243 },
6244 renegotiate: 1,
6245 flags: []string{
6246 "-renegotiate-freely",
6247 "-expect-total-renegotiations", "1",
6248 },
6249 shouldFail: true,
6250 expectedError: ":WRONG_SSL_VERSION:",
6251 })
6252
David Benjaminb16346b2015-04-08 19:16:58 -04006253 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006254 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006255 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006256 config: Config{
6257 MaxVersion: VersionTLS10,
6258 Bugs: ProtocolBugs{
6259 RequireSameRenegoClientVersion: true,
6260 },
6261 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006262 flags: []string{
6263 "-renegotiate-freely",
6264 "-expect-total-renegotiations", "1",
6265 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006266 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006267 testCases = append(testCases, testCase{
6268 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006269 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006270 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006271 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006272 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6273 NextProtos: []string{"foo"},
6274 },
6275 flags: []string{
6276 "-false-start",
6277 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006278 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006279 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006280 },
6281 shimWritesFirst: true,
6282 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006283
6284 // Client-side renegotiation controls.
6285 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006286 name: "Renegotiate-Client-Forbidden-1",
6287 config: Config{
6288 MaxVersion: VersionTLS12,
6289 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006290 renegotiate: 1,
6291 shouldFail: true,
6292 expectedError: ":NO_RENEGOTIATION:",
6293 expectedLocalError: "remote error: no renegotiation",
6294 })
6295 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006296 name: "Renegotiate-Client-Once-1",
6297 config: Config{
6298 MaxVersion: VersionTLS12,
6299 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006300 renegotiate: 1,
6301 flags: []string{
6302 "-renegotiate-once",
6303 "-expect-total-renegotiations", "1",
6304 },
6305 })
6306 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006307 name: "Renegotiate-Client-Freely-1",
6308 config: Config{
6309 MaxVersion: VersionTLS12,
6310 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006311 renegotiate: 1,
6312 flags: []string{
6313 "-renegotiate-freely",
6314 "-expect-total-renegotiations", "1",
6315 },
6316 })
6317 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006318 name: "Renegotiate-Client-Once-2",
6319 config: Config{
6320 MaxVersion: VersionTLS12,
6321 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006322 renegotiate: 2,
6323 flags: []string{"-renegotiate-once"},
6324 shouldFail: true,
6325 expectedError: ":NO_RENEGOTIATION:",
6326 expectedLocalError: "remote error: no renegotiation",
6327 })
6328 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006329 name: "Renegotiate-Client-Freely-2",
6330 config: Config{
6331 MaxVersion: VersionTLS12,
6332 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006333 renegotiate: 2,
6334 flags: []string{
6335 "-renegotiate-freely",
6336 "-expect-total-renegotiations", "2",
6337 },
6338 })
Adam Langley27a0d082015-11-03 13:34:10 -08006339 testCases = append(testCases, testCase{
6340 name: "Renegotiate-Client-NoIgnore",
6341 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006342 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006343 Bugs: ProtocolBugs{
6344 SendHelloRequestBeforeEveryAppDataRecord: true,
6345 },
6346 },
6347 shouldFail: true,
6348 expectedError: ":NO_RENEGOTIATION:",
6349 })
6350 testCases = append(testCases, testCase{
6351 name: "Renegotiate-Client-Ignore",
6352 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006353 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006354 Bugs: ProtocolBugs{
6355 SendHelloRequestBeforeEveryAppDataRecord: true,
6356 },
6357 },
6358 flags: []string{
6359 "-renegotiate-ignore",
6360 "-expect-total-renegotiations", "0",
6361 },
6362 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006363
David Benjamin34941c02016-10-08 11:45:31 -04006364 // Renegotiation is not allowed at SSL 3.0.
6365 testCases = append(testCases, testCase{
6366 name: "Renegotiate-Client-SSL3",
6367 config: Config{
6368 MaxVersion: VersionSSL30,
6369 },
6370 renegotiate: 1,
6371 flags: []string{
6372 "-renegotiate-freely",
6373 "-expect-total-renegotiations", "1",
6374 },
6375 shouldFail: true,
6376 expectedError: ":NO_RENEGOTIATION:",
6377 expectedLocalError: "remote error: no renegotiation",
6378 })
6379
David Benjamina1eaba12017-01-01 23:19:22 -05006380 // Renegotiation is not allowed when there is an unfinished write.
6381 testCases = append(testCases, testCase{
6382 name: "Renegotiate-Client-UnfinishedWrite",
6383 config: Config{
6384 MaxVersion: VersionTLS12,
6385 },
6386 renegotiate: 1,
6387 flags: []string{
6388 "-async",
6389 "-renegotiate-freely",
6390 "-read-with-unfinished-write",
6391 },
6392 shouldFail: true,
6393 expectedError: ":NO_RENEGOTIATION:",
6394 // We do not successfully send the no_renegotiation alert in
6395 // this case. https://crbug.com/boringssl/130
6396 })
6397
David Benjamin07ab5d42017-02-09 20:11:41 -05006398 // We reject stray HelloRequests during the handshake in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006399 testCases = append(testCases, testCase{
6400 name: "StrayHelloRequest",
6401 config: Config{
6402 MaxVersion: VersionTLS12,
6403 Bugs: ProtocolBugs{
6404 SendHelloRequestBeforeEveryHandshakeMessage: true,
6405 },
6406 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006407 shouldFail: true,
6408 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006409 })
6410 testCases = append(testCases, testCase{
6411 name: "StrayHelloRequest-Packed",
6412 config: Config{
6413 MaxVersion: VersionTLS12,
6414 Bugs: ProtocolBugs{
6415 PackHandshakeFlight: true,
6416 SendHelloRequestBeforeEveryHandshakeMessage: true,
6417 },
6418 },
David Benjamin07ab5d42017-02-09 20:11:41 -05006419 shouldFail: true,
6420 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin71dd6662016-07-08 14:10:48 -07006421 })
6422
David Benjamin12d2c482016-07-24 10:56:51 -04006423 // Test renegotiation works if HelloRequest and server Finished come in
6424 // the same record.
6425 testCases = append(testCases, testCase{
6426 name: "Renegotiate-Client-Packed",
6427 config: Config{
6428 MaxVersion: VersionTLS12,
6429 Bugs: ProtocolBugs{
6430 PackHandshakeFlight: true,
6431 PackHelloRequestWithFinished: true,
6432 },
6433 },
6434 renegotiate: 1,
6435 flags: []string{
6436 "-renegotiate-freely",
6437 "-expect-total-renegotiations", "1",
6438 },
6439 })
6440
David Benjamin397c8e62016-07-08 14:14:36 -07006441 // Renegotiation is forbidden in TLS 1.3.
6442 testCases = append(testCases, testCase{
6443 name: "Renegotiate-Client-TLS13",
6444 config: Config{
6445 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006446 Bugs: ProtocolBugs{
6447 SendHelloRequestBeforeEveryAppDataRecord: true,
6448 },
David Benjamin397c8e62016-07-08 14:14:36 -07006449 },
David Benjamin397c8e62016-07-08 14:14:36 -07006450 flags: []string{
6451 "-renegotiate-freely",
6452 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006453 shouldFail: true,
6454 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006455 })
6456
6457 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6458 testCases = append(testCases, testCase{
6459 name: "StrayHelloRequest-TLS13",
6460 config: Config{
6461 MaxVersion: VersionTLS13,
6462 Bugs: ProtocolBugs{
6463 SendHelloRequestBeforeEveryHandshakeMessage: true,
6464 },
6465 },
6466 shouldFail: true,
6467 expectedError: ":UNEXPECTED_MESSAGE:",
6468 })
David Benjamind2610042017-01-03 10:49:28 -05006469
6470 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6471 // always reads as supporting it, regardless of whether it was
6472 // negotiated.
6473 testCases = append(testCases, testCase{
6474 name: "AlwaysReportRenegotiationInfo-TLS13",
6475 config: Config{
6476 MaxVersion: VersionTLS13,
6477 Bugs: ProtocolBugs{
6478 NoRenegotiationInfo: true,
6479 },
6480 },
6481 flags: []string{
6482 "-expect-secure-renegotiation",
6483 },
6484 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006485}
6486
David Benjamin5e961c12014-11-07 01:48:35 -05006487func addDTLSReplayTests() {
6488 // Test that sequence number replays are detected.
6489 testCases = append(testCases, testCase{
6490 protocol: dtls,
6491 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006492 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006493 replayWrites: true,
6494 })
6495
David Benjamin8e6db492015-07-25 18:29:23 -04006496 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006497 // than the retransmit window.
6498 testCases = append(testCases, testCase{
6499 protocol: dtls,
6500 name: "DTLS-Replay-LargeGaps",
6501 config: Config{
6502 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006503 SequenceNumberMapping: func(in uint64) uint64 {
6504 return in * 127
6505 },
David Benjamin5e961c12014-11-07 01:48:35 -05006506 },
6507 },
David Benjamin8e6db492015-07-25 18:29:23 -04006508 messageCount: 200,
6509 replayWrites: true,
6510 })
6511
6512 // Test the incoming sequence number changing non-monotonically.
6513 testCases = append(testCases, testCase{
6514 protocol: dtls,
6515 name: "DTLS-Replay-NonMonotonic",
6516 config: Config{
6517 Bugs: ProtocolBugs{
6518 SequenceNumberMapping: func(in uint64) uint64 {
6519 return in ^ 31
6520 },
6521 },
6522 },
6523 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006524 replayWrites: true,
6525 })
6526}
6527
Nick Harper60edffd2016-06-21 15:19:24 -07006528var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006529 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006530 id signatureAlgorithm
6531 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006532}{
Nick Harper60edffd2016-06-21 15:19:24 -07006533 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6534 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6535 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6536 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006537 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006538 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6539 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6540 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006541 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6542 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6543 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006544 // Tests for key types prior to TLS 1.2.
6545 {"RSA", 0, testCertRSA},
6546 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006547}
6548
Nick Harper60edffd2016-06-21 15:19:24 -07006549const fakeSigAlg1 signatureAlgorithm = 0x2a01
6550const fakeSigAlg2 signatureAlgorithm = 0xff01
6551
6552func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006553 // Not all ciphers involve a signature. Advertise a list which gives all
6554 // versions a signing cipher.
6555 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006556 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006557 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6558 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6559 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6560 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6561 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6562 }
6563
David Benjaminca3d5452016-07-14 12:51:01 -04006564 var allAlgorithms []signatureAlgorithm
6565 for _, alg := range testSignatureAlgorithms {
6566 if alg.id != 0 {
6567 allAlgorithms = append(allAlgorithms, alg.id)
6568 }
6569 }
6570
Nick Harper60edffd2016-06-21 15:19:24 -07006571 // Make sure each signature algorithm works. Include some fake values in
6572 // the list and ensure they're ignored.
6573 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006574 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006575 if (ver.version < VersionTLS12) != (alg.id == 0) {
6576 continue
6577 }
6578
6579 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6580 // or remove it in C.
6581 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006582 continue
6583 }
Nick Harper60edffd2016-06-21 15:19:24 -07006584
David Benjamin3ef76972016-10-17 17:59:54 -04006585 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006586 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006587 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006588 shouldSignFail = true
6589 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006590 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006591 // RSA-PKCS1 does not exist in TLS 1.3.
6592 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006593 shouldSignFail = true
6594 shouldVerifyFail = true
6595 }
6596
6597 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6598 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6599 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006600 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006601
6602 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006603 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006604 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006605 }
6606 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006607 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006608 }
David Benjamin000800a2014-11-14 01:43:59 -05006609
David Benjamin1fb125c2016-07-08 18:52:12 -07006610 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006611
David Benjamin7a41d372016-07-09 11:21:54 -07006612 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006613 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006614 config: Config{
6615 MaxVersion: ver.version,
6616 ClientAuth: RequireAnyClientCert,
6617 VerifySignatureAlgorithms: []signatureAlgorithm{
6618 fakeSigAlg1,
6619 alg.id,
6620 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006621 },
David Benjamin7a41d372016-07-09 11:21:54 -07006622 },
6623 flags: []string{
6624 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6625 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6626 "-enable-all-curves",
6627 },
David Benjamin3ef76972016-10-17 17:59:54 -04006628 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006629 expectedError: signError,
6630 expectedPeerSignatureAlgorithm: alg.id,
6631 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006632
David Benjamin7a41d372016-07-09 11:21:54 -07006633 testCases = append(testCases, testCase{
6634 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006635 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006636 config: Config{
6637 MaxVersion: ver.version,
6638 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6639 SignSignatureAlgorithms: []signatureAlgorithm{
6640 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006641 },
David Benjamin7a41d372016-07-09 11:21:54 -07006642 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006643 SkipECDSACurveCheck: shouldVerifyFail,
6644 IgnoreSignatureVersionChecks: shouldVerifyFail,
6645 // Some signature algorithms may not be advertised.
6646 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006647 },
David Benjamin7a41d372016-07-09 11:21:54 -07006648 },
6649 flags: []string{
6650 "-require-any-client-certificate",
6651 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6652 "-enable-all-curves",
6653 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006654 // Resume the session to assert the peer signature
6655 // algorithm is reported on both handshakes.
6656 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006657 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006658 expectedError: verifyError,
6659 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006660
6661 testCases = append(testCases, testCase{
6662 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006663 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006664 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006665 MaxVersion: ver.version,
6666 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006667 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006668 fakeSigAlg1,
6669 alg.id,
6670 fakeSigAlg2,
6671 },
6672 },
6673 flags: []string{
6674 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6675 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6676 "-enable-all-curves",
6677 },
David Benjamin3ef76972016-10-17 17:59:54 -04006678 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006679 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006680 expectedPeerSignatureAlgorithm: alg.id,
6681 })
6682
6683 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006684 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006685 config: Config{
6686 MaxVersion: ver.version,
6687 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006688 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006689 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006690 alg.id,
6691 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006692 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006693 SkipECDSACurveCheck: shouldVerifyFail,
6694 IgnoreSignatureVersionChecks: shouldVerifyFail,
6695 // Some signature algorithms may not be advertised.
6696 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006697 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006698 },
6699 flags: []string{
6700 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6701 "-enable-all-curves",
6702 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006703 // Resume the session to assert the peer signature
6704 // algorithm is reported on both handshakes.
6705 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006706 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006707 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006708 })
David Benjamin5208fd42016-07-13 21:43:25 -04006709
David Benjamin3ef76972016-10-17 17:59:54 -04006710 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006711 testCases = append(testCases, testCase{
6712 testType: serverTest,
6713 name: "ClientAuth-InvalidSignature" + suffix,
6714 config: Config{
6715 MaxVersion: ver.version,
6716 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6717 SignSignatureAlgorithms: []signatureAlgorithm{
6718 alg.id,
6719 },
6720 Bugs: ProtocolBugs{
6721 InvalidSignature: true,
6722 },
6723 },
6724 flags: []string{
6725 "-require-any-client-certificate",
6726 "-enable-all-curves",
6727 },
6728 shouldFail: true,
6729 expectedError: ":BAD_SIGNATURE:",
6730 })
6731
6732 testCases = append(testCases, testCase{
6733 name: "ServerAuth-InvalidSignature" + suffix,
6734 config: Config{
6735 MaxVersion: ver.version,
6736 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6737 CipherSuites: signingCiphers,
6738 SignSignatureAlgorithms: []signatureAlgorithm{
6739 alg.id,
6740 },
6741 Bugs: ProtocolBugs{
6742 InvalidSignature: true,
6743 },
6744 },
6745 flags: []string{"-enable-all-curves"},
6746 shouldFail: true,
6747 expectedError: ":BAD_SIGNATURE:",
6748 })
6749 }
David Benjaminca3d5452016-07-14 12:51:01 -04006750
David Benjamin3ef76972016-10-17 17:59:54 -04006751 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006752 testCases = append(testCases, testCase{
6753 name: "ClientAuth-Sign-Negotiate" + suffix,
6754 config: Config{
6755 MaxVersion: ver.version,
6756 ClientAuth: RequireAnyClientCert,
6757 VerifySignatureAlgorithms: allAlgorithms,
6758 },
6759 flags: []string{
6760 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6761 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6762 "-enable-all-curves",
6763 "-signing-prefs", strconv.Itoa(int(alg.id)),
6764 },
6765 expectedPeerSignatureAlgorithm: alg.id,
6766 })
6767
6768 testCases = append(testCases, testCase{
6769 testType: serverTest,
6770 name: "ServerAuth-Sign-Negotiate" + suffix,
6771 config: Config{
6772 MaxVersion: ver.version,
6773 CipherSuites: signingCiphers,
6774 VerifySignatureAlgorithms: allAlgorithms,
6775 },
6776 flags: []string{
6777 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6778 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6779 "-enable-all-curves",
6780 "-signing-prefs", strconv.Itoa(int(alg.id)),
6781 },
6782 expectedPeerSignatureAlgorithm: alg.id,
6783 })
6784 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006785 }
David Benjamin000800a2014-11-14 01:43:59 -05006786 }
6787
Nick Harper60edffd2016-06-21 15:19:24 -07006788 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006789 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006790 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006791 config: Config{
6792 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006793 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006794 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006795 signatureECDSAWithP521AndSHA512,
6796 signatureRSAPKCS1WithSHA384,
6797 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006798 },
6799 },
6800 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006801 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6802 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006803 },
Nick Harper60edffd2016-06-21 15:19:24 -07006804 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006805 })
6806
6807 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006808 name: "ClientAuth-SignatureType-TLS13",
6809 config: Config{
6810 ClientAuth: RequireAnyClientCert,
6811 MaxVersion: VersionTLS13,
6812 VerifySignatureAlgorithms: []signatureAlgorithm{
6813 signatureECDSAWithP521AndSHA512,
6814 signatureRSAPKCS1WithSHA384,
6815 signatureRSAPSSWithSHA384,
6816 signatureECDSAWithSHA1,
6817 },
6818 },
6819 flags: []string{
6820 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6821 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6822 },
6823 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6824 })
6825
6826 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006827 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006828 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006829 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006830 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006831 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006832 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006833 signatureECDSAWithP521AndSHA512,
6834 signatureRSAPKCS1WithSHA384,
6835 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006836 },
6837 },
Nick Harper60edffd2016-06-21 15:19:24 -07006838 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006839 })
6840
Steven Valdez143e8b32016-07-11 13:19:03 -04006841 testCases = append(testCases, testCase{
6842 testType: serverTest,
6843 name: "ServerAuth-SignatureType-TLS13",
6844 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006845 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006846 VerifySignatureAlgorithms: []signatureAlgorithm{
6847 signatureECDSAWithP521AndSHA512,
6848 signatureRSAPKCS1WithSHA384,
6849 signatureRSAPSSWithSHA384,
6850 signatureECDSAWithSHA1,
6851 },
6852 },
6853 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6854 })
6855
David Benjamina95e9f32016-07-08 16:28:04 -07006856 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006857 testCases = append(testCases, testCase{
6858 testType: serverTest,
6859 name: "Verify-ClientAuth-SignatureType",
6860 config: Config{
6861 MaxVersion: VersionTLS12,
6862 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006863 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006864 signatureRSAPKCS1WithSHA256,
6865 },
6866 Bugs: ProtocolBugs{
6867 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6868 },
6869 },
6870 flags: []string{
6871 "-require-any-client-certificate",
6872 },
6873 shouldFail: true,
6874 expectedError: ":WRONG_SIGNATURE_TYPE:",
6875 })
6876
6877 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006878 testType: serverTest,
6879 name: "Verify-ClientAuth-SignatureType-TLS13",
6880 config: Config{
6881 MaxVersion: VersionTLS13,
6882 Certificates: []Certificate{rsaCertificate},
6883 SignSignatureAlgorithms: []signatureAlgorithm{
6884 signatureRSAPSSWithSHA256,
6885 },
6886 Bugs: ProtocolBugs{
6887 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6888 },
6889 },
6890 flags: []string{
6891 "-require-any-client-certificate",
6892 },
6893 shouldFail: true,
6894 expectedError: ":WRONG_SIGNATURE_TYPE:",
6895 })
6896
6897 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006898 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006899 config: Config{
6900 MaxVersion: VersionTLS12,
6901 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006902 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006903 signatureRSAPKCS1WithSHA256,
6904 },
6905 Bugs: ProtocolBugs{
6906 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6907 },
6908 },
6909 shouldFail: true,
6910 expectedError: ":WRONG_SIGNATURE_TYPE:",
6911 })
6912
Steven Valdez143e8b32016-07-11 13:19:03 -04006913 testCases = append(testCases, testCase{
6914 name: "Verify-ServerAuth-SignatureType-TLS13",
6915 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006916 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006917 SignSignatureAlgorithms: []signatureAlgorithm{
6918 signatureRSAPSSWithSHA256,
6919 },
6920 Bugs: ProtocolBugs{
6921 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6922 },
6923 },
6924 shouldFail: true,
6925 expectedError: ":WRONG_SIGNATURE_TYPE:",
6926 })
6927
David Benjamin51dd7d62016-07-08 16:07:01 -07006928 // Test that, if the list is missing, the peer falls back to SHA-1 in
6929 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006930 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006931 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006933 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006934 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006935 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006936 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006937 },
6938 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006939 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006940 },
6941 },
6942 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006943 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6944 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006945 },
6946 })
6947
6948 testCases = append(testCases, testCase{
6949 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006950 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006951 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006952 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006953 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006954 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006955 },
6956 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006957 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006958 },
6959 },
David Benjaminee32bea2016-08-17 13:36:44 -04006960 flags: []string{
6961 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6962 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6963 },
6964 })
6965
6966 testCases = append(testCases, testCase{
6967 name: "ClientAuth-SHA1-Fallback-ECDSA",
6968 config: Config{
6969 MaxVersion: VersionTLS12,
6970 ClientAuth: RequireAnyClientCert,
6971 VerifySignatureAlgorithms: []signatureAlgorithm{
6972 signatureECDSAWithSHA1,
6973 },
6974 Bugs: ProtocolBugs{
6975 NoSignatureAlgorithms: true,
6976 },
6977 },
6978 flags: []string{
6979 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6980 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6981 },
6982 })
6983
6984 testCases = append(testCases, testCase{
6985 testType: serverTest,
6986 name: "ServerAuth-SHA1-Fallback-ECDSA",
6987 config: Config{
6988 MaxVersion: VersionTLS12,
6989 VerifySignatureAlgorithms: []signatureAlgorithm{
6990 signatureECDSAWithSHA1,
6991 },
6992 Bugs: ProtocolBugs{
6993 NoSignatureAlgorithms: true,
6994 },
6995 },
6996 flags: []string{
6997 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6998 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6999 },
David Benjamin000800a2014-11-14 01:43:59 -05007000 })
David Benjamin72dc7832015-03-16 17:49:43 -04007001
David Benjamin51dd7d62016-07-08 16:07:01 -07007002 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007003 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007004 config: Config{
7005 MaxVersion: VersionTLS13,
7006 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007007 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007008 signatureRSAPKCS1WithSHA1,
7009 },
7010 Bugs: ProtocolBugs{
7011 NoSignatureAlgorithms: true,
7012 },
7013 },
7014 flags: []string{
7015 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7016 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7017 },
David Benjamin48901652016-08-01 12:12:47 -04007018 shouldFail: true,
7019 // An empty CertificateRequest signature algorithm list is a
7020 // syntax error in TLS 1.3.
7021 expectedError: ":DECODE_ERROR:",
7022 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007023 })
7024
7025 testCases = append(testCases, testCase{
7026 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007027 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007028 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007029 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007030 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007031 signatureRSAPKCS1WithSHA1,
7032 },
7033 Bugs: ProtocolBugs{
7034 NoSignatureAlgorithms: true,
7035 },
7036 },
7037 shouldFail: true,
7038 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7039 })
7040
David Benjaminb62d2872016-07-18 14:55:02 +02007041 // Test that hash preferences are enforced. BoringSSL does not implement
7042 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007043 testCases = append(testCases, testCase{
7044 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007045 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007046 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007047 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007048 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007049 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007050 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007051 },
7052 Bugs: ProtocolBugs{
7053 IgnorePeerSignatureAlgorithmPreferences: true,
7054 },
7055 },
7056 flags: []string{"-require-any-client-certificate"},
7057 shouldFail: true,
7058 expectedError: ":WRONG_SIGNATURE_TYPE:",
7059 })
7060
7061 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007062 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007063 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007064 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007065 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007066 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007067 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007068 },
7069 Bugs: ProtocolBugs{
7070 IgnorePeerSignatureAlgorithmPreferences: true,
7071 },
7072 },
7073 shouldFail: true,
7074 expectedError: ":WRONG_SIGNATURE_TYPE:",
7075 })
David Benjaminb62d2872016-07-18 14:55:02 +02007076 testCases = append(testCases, testCase{
7077 testType: serverTest,
7078 name: "ClientAuth-Enforced-TLS13",
7079 config: Config{
7080 MaxVersion: VersionTLS13,
7081 Certificates: []Certificate{rsaCertificate},
7082 SignSignatureAlgorithms: []signatureAlgorithm{
7083 signatureRSAPKCS1WithMD5,
7084 },
7085 Bugs: ProtocolBugs{
7086 IgnorePeerSignatureAlgorithmPreferences: true,
7087 IgnoreSignatureVersionChecks: true,
7088 },
7089 },
7090 flags: []string{"-require-any-client-certificate"},
7091 shouldFail: true,
7092 expectedError: ":WRONG_SIGNATURE_TYPE:",
7093 })
7094
7095 testCases = append(testCases, testCase{
7096 name: "ServerAuth-Enforced-TLS13",
7097 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007098 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007099 SignSignatureAlgorithms: []signatureAlgorithm{
7100 signatureRSAPKCS1WithMD5,
7101 },
7102 Bugs: ProtocolBugs{
7103 IgnorePeerSignatureAlgorithmPreferences: true,
7104 IgnoreSignatureVersionChecks: true,
7105 },
7106 },
7107 shouldFail: true,
7108 expectedError: ":WRONG_SIGNATURE_TYPE:",
7109 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007110
7111 // Test that the agreed upon digest respects the client preferences and
7112 // the server digests.
7113 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007114 name: "NoCommonAlgorithms-Digests",
7115 config: Config{
7116 MaxVersion: VersionTLS12,
7117 ClientAuth: RequireAnyClientCert,
7118 VerifySignatureAlgorithms: []signatureAlgorithm{
7119 signatureRSAPKCS1WithSHA512,
7120 signatureRSAPKCS1WithSHA1,
7121 },
7122 },
7123 flags: []string{
7124 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7125 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7126 "-digest-prefs", "SHA256",
7127 },
7128 shouldFail: true,
7129 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7130 })
7131 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007132 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007133 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007134 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007135 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007136 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007137 signatureRSAPKCS1WithSHA512,
7138 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007139 },
7140 },
7141 flags: []string{
7142 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7143 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007144 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007145 },
David Benjaminca3d5452016-07-14 12:51:01 -04007146 shouldFail: true,
7147 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7148 })
7149 testCases = append(testCases, testCase{
7150 name: "NoCommonAlgorithms-TLS13",
7151 config: Config{
7152 MaxVersion: VersionTLS13,
7153 ClientAuth: RequireAnyClientCert,
7154 VerifySignatureAlgorithms: []signatureAlgorithm{
7155 signatureRSAPSSWithSHA512,
7156 signatureRSAPSSWithSHA384,
7157 },
7158 },
7159 flags: []string{
7160 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7161 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7162 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7163 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007164 shouldFail: true,
7165 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007166 })
7167 testCases = append(testCases, testCase{
7168 name: "Agree-Digest-SHA256",
7169 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007170 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007171 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007172 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007173 signatureRSAPKCS1WithSHA1,
7174 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007175 },
7176 },
7177 flags: []string{
7178 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7179 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007180 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007181 },
Nick Harper60edffd2016-06-21 15:19:24 -07007182 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007183 })
7184 testCases = append(testCases, testCase{
7185 name: "Agree-Digest-SHA1",
7186 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007187 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007188 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007189 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007190 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007191 },
7192 },
7193 flags: []string{
7194 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7195 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007196 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007197 },
Nick Harper60edffd2016-06-21 15:19:24 -07007198 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007199 })
7200 testCases = append(testCases, testCase{
7201 name: "Agree-Digest-Default",
7202 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007203 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007204 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007205 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007206 signatureRSAPKCS1WithSHA256,
7207 signatureECDSAWithP256AndSHA256,
7208 signatureRSAPKCS1WithSHA1,
7209 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007210 },
7211 },
7212 flags: []string{
7213 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7214 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7215 },
Nick Harper60edffd2016-06-21 15:19:24 -07007216 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007217 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007218
David Benjaminca3d5452016-07-14 12:51:01 -04007219 // Test that the signing preference list may include extra algorithms
7220 // without negotiation problems.
7221 testCases = append(testCases, testCase{
7222 testType: serverTest,
7223 name: "FilterExtraAlgorithms",
7224 config: Config{
7225 MaxVersion: VersionTLS12,
7226 VerifySignatureAlgorithms: []signatureAlgorithm{
7227 signatureRSAPKCS1WithSHA256,
7228 },
7229 },
7230 flags: []string{
7231 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7232 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7233 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7234 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7235 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7236 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7237 },
7238 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7239 })
7240
David Benjamin4c3ddf72016-06-29 18:13:53 -04007241 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7242 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007243 testCases = append(testCases, testCase{
7244 name: "CheckLeafCurve",
7245 config: Config{
7246 MaxVersion: VersionTLS12,
7247 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007248 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007249 },
7250 flags: []string{"-p384-only"},
7251 shouldFail: true,
7252 expectedError: ":BAD_ECC_CERT:",
7253 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007254
7255 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7256 testCases = append(testCases, testCase{
7257 name: "CheckLeafCurve-TLS13",
7258 config: Config{
7259 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007260 Certificates: []Certificate{ecdsaP256Certificate},
7261 },
7262 flags: []string{"-p384-only"},
7263 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007264
7265 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7266 testCases = append(testCases, testCase{
7267 name: "ECDSACurveMismatch-Verify-TLS12",
7268 config: Config{
7269 MaxVersion: VersionTLS12,
7270 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7271 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007272 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007273 signatureECDSAWithP384AndSHA384,
7274 },
7275 },
7276 })
7277
7278 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7279 testCases = append(testCases, testCase{
7280 name: "ECDSACurveMismatch-Verify-TLS13",
7281 config: Config{
7282 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007283 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007284 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007285 signatureECDSAWithP384AndSHA384,
7286 },
7287 Bugs: ProtocolBugs{
7288 SkipECDSACurveCheck: true,
7289 },
7290 },
7291 shouldFail: true,
7292 expectedError: ":WRONG_SIGNATURE_TYPE:",
7293 })
7294
7295 // Signature algorithm selection in TLS 1.3 should take the curve into
7296 // account.
7297 testCases = append(testCases, testCase{
7298 testType: serverTest,
7299 name: "ECDSACurveMismatch-Sign-TLS13",
7300 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007301 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007302 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007303 signatureECDSAWithP384AndSHA384,
7304 signatureECDSAWithP256AndSHA256,
7305 },
7306 },
7307 flags: []string{
7308 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7309 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7310 },
7311 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7312 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007313
7314 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7315 // server does not attempt to sign in that case.
7316 testCases = append(testCases, testCase{
7317 testType: serverTest,
7318 name: "RSA-PSS-Large",
7319 config: Config{
7320 MaxVersion: VersionTLS13,
7321 VerifySignatureAlgorithms: []signatureAlgorithm{
7322 signatureRSAPSSWithSHA512,
7323 },
7324 },
7325 flags: []string{
7326 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7327 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7328 },
7329 shouldFail: true,
7330 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7331 })
David Benjamin57e929f2016-08-30 00:30:38 -04007332
7333 // Test that RSA-PSS is enabled by default for TLS 1.2.
7334 testCases = append(testCases, testCase{
7335 testType: clientTest,
7336 name: "RSA-PSS-Default-Verify",
7337 config: Config{
7338 MaxVersion: VersionTLS12,
7339 SignSignatureAlgorithms: []signatureAlgorithm{
7340 signatureRSAPSSWithSHA256,
7341 },
7342 },
7343 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7344 })
7345
7346 testCases = append(testCases, testCase{
7347 testType: serverTest,
7348 name: "RSA-PSS-Default-Sign",
7349 config: Config{
7350 MaxVersion: VersionTLS12,
7351 VerifySignatureAlgorithms: []signatureAlgorithm{
7352 signatureRSAPSSWithSHA256,
7353 },
7354 },
7355 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7356 })
David Benjamin000800a2014-11-14 01:43:59 -05007357}
7358
David Benjamin83f90402015-01-27 01:09:43 -05007359// timeouts is the retransmit schedule for BoringSSL. It doubles and
7360// caps at 60 seconds. On the 13th timeout, it gives up.
7361var timeouts = []time.Duration{
7362 1 * time.Second,
7363 2 * time.Second,
7364 4 * time.Second,
7365 8 * time.Second,
7366 16 * time.Second,
7367 32 * time.Second,
7368 60 * time.Second,
7369 60 * time.Second,
7370 60 * time.Second,
7371 60 * time.Second,
7372 60 * time.Second,
7373 60 * time.Second,
7374 60 * time.Second,
7375}
7376
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007377// shortTimeouts is an alternate set of timeouts which would occur if the
7378// initial timeout duration was set to 250ms.
7379var shortTimeouts = []time.Duration{
7380 250 * time.Millisecond,
7381 500 * time.Millisecond,
7382 1 * time.Second,
7383 2 * time.Second,
7384 4 * time.Second,
7385 8 * time.Second,
7386 16 * time.Second,
7387 32 * time.Second,
7388 60 * time.Second,
7389 60 * time.Second,
7390 60 * time.Second,
7391 60 * time.Second,
7392 60 * time.Second,
7393}
7394
David Benjamin83f90402015-01-27 01:09:43 -05007395func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007396 // These tests work by coordinating some behavior on both the shim and
7397 // the runner.
7398 //
7399 // TimeoutSchedule configures the runner to send a series of timeout
7400 // opcodes to the shim (see packetAdaptor) immediately before reading
7401 // each peer handshake flight N. The timeout opcode both simulates a
7402 // timeout in the shim and acts as a synchronization point to help the
7403 // runner bracket each handshake flight.
7404 //
7405 // We assume the shim does not read from the channel eagerly. It must
7406 // first wait until it has sent flight N and is ready to receive
7407 // handshake flight N+1. At this point, it will process the timeout
7408 // opcode. It must then immediately respond with a timeout ACK and act
7409 // as if the shim was idle for the specified amount of time.
7410 //
7411 // The runner then drops all packets received before the ACK and
7412 // continues waiting for flight N. This ordering results in one attempt
7413 // at sending flight N to be dropped. For the test to complete, the
7414 // shim must send flight N again, testing that the shim implements DTLS
7415 // retransmit on a timeout.
7416
Steven Valdez143e8b32016-07-11 13:19:03 -04007417 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007418 // likely be more epochs to cross and the final message's retransmit may
7419 // be more complex.
7420
David Benjamin585d7a42016-06-02 14:58:00 -04007421 for _, async := range []bool{true, false} {
7422 var tests []testCase
7423
7424 // Test that this is indeed the timeout schedule. Stress all
7425 // four patterns of handshake.
7426 for i := 1; i < len(timeouts); i++ {
7427 number := strconv.Itoa(i)
7428 tests = append(tests, testCase{
7429 protocol: dtls,
7430 name: "DTLS-Retransmit-Client-" + number,
7431 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007432 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007433 Bugs: ProtocolBugs{
7434 TimeoutSchedule: timeouts[:i],
7435 },
7436 },
7437 resumeSession: true,
7438 })
7439 tests = append(tests, testCase{
7440 protocol: dtls,
7441 testType: serverTest,
7442 name: "DTLS-Retransmit-Server-" + number,
7443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007444 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007445 Bugs: ProtocolBugs{
7446 TimeoutSchedule: timeouts[:i],
7447 },
7448 },
7449 resumeSession: true,
7450 })
7451 }
7452
7453 // Test that exceeding the timeout schedule hits a read
7454 // timeout.
7455 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007456 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007457 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007458 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007459 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007460 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007461 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007462 },
7463 },
7464 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007465 shouldFail: true,
7466 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007467 })
David Benjamin585d7a42016-06-02 14:58:00 -04007468
7469 if async {
7470 // Test that timeout handling has a fudge factor, due to API
7471 // problems.
7472 tests = append(tests, testCase{
7473 protocol: dtls,
7474 name: "DTLS-Retransmit-Fudge",
7475 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007476 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007477 Bugs: ProtocolBugs{
7478 TimeoutSchedule: []time.Duration{
7479 timeouts[0] - 10*time.Millisecond,
7480 },
7481 },
7482 },
7483 resumeSession: true,
7484 })
7485 }
7486
7487 // Test that the final Finished retransmitting isn't
7488 // duplicated if the peer badly fragments everything.
7489 tests = append(tests, testCase{
7490 testType: serverTest,
7491 protocol: dtls,
7492 name: "DTLS-Retransmit-Fragmented",
7493 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007494 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007495 Bugs: ProtocolBugs{
7496 TimeoutSchedule: []time.Duration{timeouts[0]},
7497 MaxHandshakeRecordLength: 2,
7498 },
7499 },
7500 })
7501
7502 // Test the timeout schedule when a shorter initial timeout duration is set.
7503 tests = append(tests, testCase{
7504 protocol: dtls,
7505 name: "DTLS-Retransmit-Short-Client",
7506 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007507 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007508 Bugs: ProtocolBugs{
7509 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7510 },
7511 },
7512 resumeSession: true,
7513 flags: []string{"-initial-timeout-duration-ms", "250"},
7514 })
7515 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007516 protocol: dtls,
7517 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007518 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007520 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007521 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007522 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007523 },
7524 },
7525 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007526 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007527 })
David Benjamin585d7a42016-06-02 14:58:00 -04007528
7529 for _, test := range tests {
7530 if async {
7531 test.name += "-Async"
7532 test.flags = append(test.flags, "-async")
7533 }
7534
7535 testCases = append(testCases, test)
7536 }
David Benjamin83f90402015-01-27 01:09:43 -05007537 }
David Benjamin83f90402015-01-27 01:09:43 -05007538}
7539
David Benjaminc565ebb2015-04-03 04:06:36 -04007540func addExportKeyingMaterialTests() {
7541 for _, vers := range tlsVersions {
7542 if vers.version == VersionSSL30 {
7543 continue
7544 }
7545 testCases = append(testCases, testCase{
7546 name: "ExportKeyingMaterial-" + vers.name,
7547 config: Config{
7548 MaxVersion: vers.version,
7549 },
7550 exportKeyingMaterial: 1024,
7551 exportLabel: "label",
7552 exportContext: "context",
7553 useExportContext: true,
7554 })
7555 testCases = append(testCases, testCase{
7556 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7557 config: Config{
7558 MaxVersion: vers.version,
7559 },
7560 exportKeyingMaterial: 1024,
7561 })
7562 testCases = append(testCases, testCase{
7563 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7564 config: Config{
7565 MaxVersion: vers.version,
7566 },
7567 exportKeyingMaterial: 1024,
7568 useExportContext: true,
7569 })
7570 testCases = append(testCases, testCase{
7571 name: "ExportKeyingMaterial-Small-" + vers.name,
7572 config: Config{
7573 MaxVersion: vers.version,
7574 },
7575 exportKeyingMaterial: 1,
7576 exportLabel: "label",
7577 exportContext: "context",
7578 useExportContext: true,
7579 })
7580 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007581
David Benjaminc565ebb2015-04-03 04:06:36 -04007582 testCases = append(testCases, testCase{
7583 name: "ExportKeyingMaterial-SSL3",
7584 config: Config{
7585 MaxVersion: VersionSSL30,
7586 },
7587 exportKeyingMaterial: 1024,
7588 exportLabel: "label",
7589 exportContext: "context",
7590 useExportContext: true,
7591 shouldFail: true,
7592 expectedError: "failed to export keying material",
7593 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007594
7595 // Exporters work during a False Start.
7596 testCases = append(testCases, testCase{
7597 name: "ExportKeyingMaterial-FalseStart",
7598 config: Config{
7599 MaxVersion: VersionTLS12,
7600 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7601 NextProtos: []string{"foo"},
7602 Bugs: ProtocolBugs{
7603 ExpectFalseStart: true,
7604 },
7605 },
7606 flags: []string{
7607 "-false-start",
7608 "-advertise-alpn", "\x03foo",
7609 },
7610 shimWritesFirst: true,
7611 exportKeyingMaterial: 1024,
7612 exportLabel: "label",
7613 exportContext: "context",
7614 useExportContext: true,
7615 })
7616
7617 // Exporters do not work in the middle of a renegotiation. Test this by
7618 // triggering the exporter after every SSL_read call and configuring the
7619 // shim to run asynchronously.
7620 testCases = append(testCases, testCase{
7621 name: "ExportKeyingMaterial-Renegotiate",
7622 config: Config{
7623 MaxVersion: VersionTLS12,
7624 },
7625 renegotiate: 1,
7626 flags: []string{
7627 "-async",
7628 "-use-exporter-between-reads",
7629 "-renegotiate-freely",
7630 "-expect-total-renegotiations", "1",
7631 },
7632 shouldFail: true,
7633 expectedError: "failed to export keying material",
7634 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007635}
7636
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007637func addTLSUniqueTests() {
7638 for _, isClient := range []bool{false, true} {
7639 for _, isResumption := range []bool{false, true} {
7640 for _, hasEMS := range []bool{false, true} {
7641 var suffix string
7642 if isResumption {
7643 suffix = "Resume-"
7644 } else {
7645 suffix = "Full-"
7646 }
7647
7648 if hasEMS {
7649 suffix += "EMS-"
7650 } else {
7651 suffix += "NoEMS-"
7652 }
7653
7654 if isClient {
7655 suffix += "Client"
7656 } else {
7657 suffix += "Server"
7658 }
7659
7660 test := testCase{
7661 name: "TLSUnique-" + suffix,
7662 testTLSUnique: true,
7663 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007664 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007665 Bugs: ProtocolBugs{
7666 NoExtendedMasterSecret: !hasEMS,
7667 },
7668 },
7669 }
7670
7671 if isResumption {
7672 test.resumeSession = true
7673 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007674 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007675 Bugs: ProtocolBugs{
7676 NoExtendedMasterSecret: !hasEMS,
7677 },
7678 }
7679 }
7680
7681 if isResumption && !hasEMS {
7682 test.shouldFail = true
7683 test.expectedError = "failed to get tls-unique"
7684 }
7685
7686 testCases = append(testCases, test)
7687 }
7688 }
7689 }
7690}
7691
Adam Langley09505632015-07-30 18:10:13 -07007692func addCustomExtensionTests() {
7693 expectedContents := "custom extension"
7694 emptyString := ""
7695
7696 for _, isClient := range []bool{false, true} {
7697 suffix := "Server"
7698 flag := "-enable-server-custom-extension"
7699 testType := serverTest
7700 if isClient {
7701 suffix = "Client"
7702 flag = "-enable-client-custom-extension"
7703 testType = clientTest
7704 }
7705
7706 testCases = append(testCases, testCase{
7707 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007708 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007709 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007710 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007711 Bugs: ProtocolBugs{
7712 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007713 ExpectedCustomExtension: &expectedContents,
7714 },
7715 },
7716 flags: []string{flag},
7717 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007718 testCases = append(testCases, testCase{
7719 testType: testType,
7720 name: "CustomExtensions-" + suffix + "-TLS13",
7721 config: Config{
7722 MaxVersion: VersionTLS13,
7723 Bugs: ProtocolBugs{
7724 CustomExtension: expectedContents,
7725 ExpectedCustomExtension: &expectedContents,
7726 },
7727 },
7728 flags: []string{flag},
7729 })
Adam Langley09505632015-07-30 18:10:13 -07007730
7731 // If the parse callback fails, the handshake should also fail.
7732 testCases = append(testCases, testCase{
7733 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007734 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007736 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007737 Bugs: ProtocolBugs{
7738 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007739 ExpectedCustomExtension: &expectedContents,
7740 },
7741 },
David Benjamin399e7c92015-07-30 23:01:27 -04007742 flags: []string{flag},
7743 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007744 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7745 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007746 testCases = append(testCases, testCase{
7747 testType: testType,
7748 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7749 config: Config{
7750 MaxVersion: VersionTLS13,
7751 Bugs: ProtocolBugs{
7752 CustomExtension: expectedContents + "foo",
7753 ExpectedCustomExtension: &expectedContents,
7754 },
7755 },
7756 flags: []string{flag},
7757 shouldFail: true,
7758 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7759 })
Adam Langley09505632015-07-30 18:10:13 -07007760
7761 // If the add callback fails, the handshake should also fail.
7762 testCases = append(testCases, testCase{
7763 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007764 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007765 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007766 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007767 Bugs: ProtocolBugs{
7768 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007769 ExpectedCustomExtension: &expectedContents,
7770 },
7771 },
David Benjamin399e7c92015-07-30 23:01:27 -04007772 flags: []string{flag, "-custom-extension-fail-add"},
7773 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007774 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7775 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007776 testCases = append(testCases, testCase{
7777 testType: testType,
7778 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7779 config: Config{
7780 MaxVersion: VersionTLS13,
7781 Bugs: ProtocolBugs{
7782 CustomExtension: expectedContents,
7783 ExpectedCustomExtension: &expectedContents,
7784 },
7785 },
7786 flags: []string{flag, "-custom-extension-fail-add"},
7787 shouldFail: true,
7788 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7789 })
Adam Langley09505632015-07-30 18:10:13 -07007790
7791 // If the add callback returns zero, no extension should be
7792 // added.
7793 skipCustomExtension := expectedContents
7794 if isClient {
7795 // For the case where the client skips sending the
7796 // custom extension, the server must not “echo” it.
7797 skipCustomExtension = ""
7798 }
7799 testCases = append(testCases, testCase{
7800 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007801 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007802 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007803 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007804 Bugs: ProtocolBugs{
7805 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007806 ExpectedCustomExtension: &emptyString,
7807 },
7808 },
7809 flags: []string{flag, "-custom-extension-skip"},
7810 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007811 testCases = append(testCases, testCase{
7812 testType: testType,
7813 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7814 config: Config{
7815 MaxVersion: VersionTLS13,
7816 Bugs: ProtocolBugs{
7817 CustomExtension: skipCustomExtension,
7818 ExpectedCustomExtension: &emptyString,
7819 },
7820 },
7821 flags: []string{flag, "-custom-extension-skip"},
7822 })
Adam Langley09505632015-07-30 18:10:13 -07007823 }
7824
7825 // The custom extension add callback should not be called if the client
7826 // doesn't send the extension.
7827 testCases = append(testCases, testCase{
7828 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007829 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007830 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007831 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007832 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007833 ExpectedCustomExtension: &emptyString,
7834 },
7835 },
7836 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7837 })
Adam Langley2deb9842015-08-07 11:15:37 -07007838
Steven Valdez143e8b32016-07-11 13:19:03 -04007839 testCases = append(testCases, testCase{
7840 testType: serverTest,
7841 name: "CustomExtensions-NotCalled-Server-TLS13",
7842 config: Config{
7843 MaxVersion: VersionTLS13,
7844 Bugs: ProtocolBugs{
7845 ExpectedCustomExtension: &emptyString,
7846 },
7847 },
7848 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7849 })
7850
Adam Langley2deb9842015-08-07 11:15:37 -07007851 // Test an unknown extension from the server.
7852 testCases = append(testCases, testCase{
7853 testType: clientTest,
7854 name: "UnknownExtension-Client",
7855 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007856 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007857 Bugs: ProtocolBugs{
7858 CustomExtension: expectedContents,
7859 },
7860 },
David Benjamin0c40a962016-08-01 12:05:50 -04007861 shouldFail: true,
7862 expectedError: ":UNEXPECTED_EXTENSION:",
7863 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007864 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007865 testCases = append(testCases, testCase{
7866 testType: clientTest,
7867 name: "UnknownExtension-Client-TLS13",
7868 config: Config{
7869 MaxVersion: VersionTLS13,
7870 Bugs: ProtocolBugs{
7871 CustomExtension: expectedContents,
7872 },
7873 },
David Benjamin0c40a962016-08-01 12:05:50 -04007874 shouldFail: true,
7875 expectedError: ":UNEXPECTED_EXTENSION:",
7876 expectedLocalError: "remote error: unsupported extension",
7877 })
David Benjamin490469f2016-10-05 22:44:38 -04007878 testCases = append(testCases, testCase{
7879 testType: clientTest,
7880 name: "UnknownUnencryptedExtension-Client-TLS13",
7881 config: Config{
7882 MaxVersion: VersionTLS13,
7883 Bugs: ProtocolBugs{
7884 CustomUnencryptedExtension: expectedContents,
7885 },
7886 },
7887 shouldFail: true,
7888 expectedError: ":UNEXPECTED_EXTENSION:",
7889 // The shim must send an alert, but alerts at this point do not
7890 // get successfully decrypted by the runner.
7891 expectedLocalError: "local error: bad record MAC",
7892 })
7893 testCases = append(testCases, testCase{
7894 testType: clientTest,
7895 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7896 config: Config{
7897 MaxVersion: VersionTLS13,
7898 Bugs: ProtocolBugs{
7899 SendUnencryptedALPN: "foo",
7900 },
7901 },
7902 flags: []string{
7903 "-advertise-alpn", "\x03foo\x03bar",
7904 },
7905 shouldFail: true,
7906 expectedError: ":UNEXPECTED_EXTENSION:",
7907 // The shim must send an alert, but alerts at this point do not
7908 // get successfully decrypted by the runner.
7909 expectedLocalError: "local error: bad record MAC",
7910 })
David Benjamin0c40a962016-08-01 12:05:50 -04007911
7912 // Test a known but unoffered extension from the server.
7913 testCases = append(testCases, testCase{
7914 testType: clientTest,
7915 name: "UnofferedExtension-Client",
7916 config: Config{
7917 MaxVersion: VersionTLS12,
7918 Bugs: ProtocolBugs{
7919 SendALPN: "alpn",
7920 },
7921 },
7922 shouldFail: true,
7923 expectedError: ":UNEXPECTED_EXTENSION:",
7924 expectedLocalError: "remote error: unsupported extension",
7925 })
7926 testCases = append(testCases, testCase{
7927 testType: clientTest,
7928 name: "UnofferedExtension-Client-TLS13",
7929 config: Config{
7930 MaxVersion: VersionTLS13,
7931 Bugs: ProtocolBugs{
7932 SendALPN: "alpn",
7933 },
7934 },
7935 shouldFail: true,
7936 expectedError: ":UNEXPECTED_EXTENSION:",
7937 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007938 })
Adam Langley09505632015-07-30 18:10:13 -07007939}
7940
David Benjaminb36a3952015-12-01 18:53:13 -05007941func addRSAClientKeyExchangeTests() {
7942 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7943 testCases = append(testCases, testCase{
7944 testType: serverTest,
7945 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7946 config: Config{
7947 // Ensure the ClientHello version and final
7948 // version are different, to detect if the
7949 // server uses the wrong one.
7950 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007951 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007952 Bugs: ProtocolBugs{
7953 BadRSAClientKeyExchange: bad,
7954 },
7955 },
7956 shouldFail: true,
7957 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7958 })
7959 }
David Benjamine63d9d72016-09-19 18:27:34 -04007960
7961 // The server must compare whatever was in ClientHello.version for the
7962 // RSA premaster.
7963 testCases = append(testCases, testCase{
7964 testType: serverTest,
7965 name: "SendClientVersion-RSA",
7966 config: Config{
7967 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7968 Bugs: ProtocolBugs{
7969 SendClientVersion: 0x1234,
7970 },
7971 },
7972 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7973 })
David Benjaminb36a3952015-12-01 18:53:13 -05007974}
7975
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007976var testCurves = []struct {
7977 name string
7978 id CurveID
7979}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007980 {"P-256", CurveP256},
7981 {"P-384", CurveP384},
7982 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007983 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007984}
7985
Steven Valdez5440fe02016-07-18 12:40:30 -04007986const bogusCurve = 0x1234
7987
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007988func addCurveTests() {
7989 for _, curve := range testCurves {
7990 testCases = append(testCases, testCase{
7991 name: "CurveTest-Client-" + curve.name,
7992 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007993 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007994 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7995 CurvePreferences: []CurveID{curve.id},
7996 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007997 flags: []string{
7998 "-enable-all-curves",
7999 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8000 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008001 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008002 })
8003 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008004 name: "CurveTest-Client-" + curve.name + "-TLS13",
8005 config: Config{
8006 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008007 CurvePreferences: []CurveID{curve.id},
8008 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008009 flags: []string{
8010 "-enable-all-curves",
8011 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8012 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008013 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008014 })
8015 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008016 testType: serverTest,
8017 name: "CurveTest-Server-" + curve.name,
8018 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008019 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008020 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8021 CurvePreferences: []CurveID{curve.id},
8022 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008023 flags: []string{
8024 "-enable-all-curves",
8025 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8026 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008027 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008028 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008029 testCases = append(testCases, testCase{
8030 testType: serverTest,
8031 name: "CurveTest-Server-" + curve.name + "-TLS13",
8032 config: Config{
8033 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008034 CurvePreferences: []CurveID{curve.id},
8035 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008036 flags: []string{
8037 "-enable-all-curves",
8038 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8039 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008040 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008041 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008042 }
David Benjamin241ae832016-01-15 03:04:54 -05008043
8044 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008045 testCases = append(testCases, testCase{
8046 testType: serverTest,
8047 name: "UnknownCurve",
8048 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008049 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008050 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8051 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8052 },
8053 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008054
Steven Valdez803c77a2016-09-06 14:13:43 -04008055 // The server must be tolerant to bogus curves.
8056 testCases = append(testCases, testCase{
8057 testType: serverTest,
8058 name: "UnknownCurve-TLS13",
8059 config: Config{
8060 MaxVersion: VersionTLS13,
8061 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8062 },
8063 })
8064
David Benjamin4c3ddf72016-06-29 18:13:53 -04008065 // The server must not consider ECDHE ciphers when there are no
8066 // supported curves.
8067 testCases = append(testCases, testCase{
8068 testType: serverTest,
8069 name: "NoSupportedCurves",
8070 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008071 MaxVersion: VersionTLS12,
8072 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8073 Bugs: ProtocolBugs{
8074 NoSupportedCurves: true,
8075 },
8076 },
8077 shouldFail: true,
8078 expectedError: ":NO_SHARED_CIPHER:",
8079 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008080 testCases = append(testCases, testCase{
8081 testType: serverTest,
8082 name: "NoSupportedCurves-TLS13",
8083 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008084 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008085 Bugs: ProtocolBugs{
8086 NoSupportedCurves: true,
8087 },
8088 },
8089 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008090 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008091 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008092
8093 // The server must fall back to another cipher when there are no
8094 // supported curves.
8095 testCases = append(testCases, testCase{
8096 testType: serverTest,
8097 name: "NoCommonCurves",
8098 config: Config{
8099 MaxVersion: VersionTLS12,
8100 CipherSuites: []uint16{
8101 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8102 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8103 },
8104 CurvePreferences: []CurveID{CurveP224},
8105 },
8106 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8107 })
8108
8109 // The client must reject bogus curves and disabled curves.
8110 testCases = append(testCases, testCase{
8111 name: "BadECDHECurve",
8112 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008113 MaxVersion: VersionTLS12,
8114 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8115 Bugs: ProtocolBugs{
8116 SendCurve: bogusCurve,
8117 },
8118 },
8119 shouldFail: true,
8120 expectedError: ":WRONG_CURVE:",
8121 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008122 testCases = append(testCases, testCase{
8123 name: "BadECDHECurve-TLS13",
8124 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008125 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008126 Bugs: ProtocolBugs{
8127 SendCurve: bogusCurve,
8128 },
8129 },
8130 shouldFail: true,
8131 expectedError: ":WRONG_CURVE:",
8132 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008133
8134 testCases = append(testCases, testCase{
8135 name: "UnsupportedCurve",
8136 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008137 MaxVersion: VersionTLS12,
8138 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8139 CurvePreferences: []CurveID{CurveP256},
8140 Bugs: ProtocolBugs{
8141 IgnorePeerCurvePreferences: true,
8142 },
8143 },
8144 flags: []string{"-p384-only"},
8145 shouldFail: true,
8146 expectedError: ":WRONG_CURVE:",
8147 })
8148
David Benjamin4f921572016-07-17 14:20:10 +02008149 testCases = append(testCases, testCase{
8150 // TODO(davidben): Add a TLS 1.3 version where
8151 // HelloRetryRequest requests an unsupported curve.
8152 name: "UnsupportedCurve-ServerHello-TLS13",
8153 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008154 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008155 CurvePreferences: []CurveID{CurveP384},
8156 Bugs: ProtocolBugs{
8157 SendCurve: CurveP256,
8158 },
8159 },
8160 flags: []string{"-p384-only"},
8161 shouldFail: true,
8162 expectedError: ":WRONG_CURVE:",
8163 })
8164
David Benjamin4c3ddf72016-06-29 18:13:53 -04008165 // Test invalid curve points.
8166 testCases = append(testCases, testCase{
8167 name: "InvalidECDHPoint-Client",
8168 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008169 MaxVersion: VersionTLS12,
8170 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8171 CurvePreferences: []CurveID{CurveP256},
8172 Bugs: ProtocolBugs{
8173 InvalidECDHPoint: true,
8174 },
8175 },
8176 shouldFail: true,
8177 expectedError: ":INVALID_ENCODING:",
8178 })
8179 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008180 name: "InvalidECDHPoint-Client-TLS13",
8181 config: Config{
8182 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008183 CurvePreferences: []CurveID{CurveP256},
8184 Bugs: ProtocolBugs{
8185 InvalidECDHPoint: true,
8186 },
8187 },
8188 shouldFail: true,
8189 expectedError: ":INVALID_ENCODING:",
8190 })
8191 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008192 testType: serverTest,
8193 name: "InvalidECDHPoint-Server",
8194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008195 MaxVersion: VersionTLS12,
8196 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8197 CurvePreferences: []CurveID{CurveP256},
8198 Bugs: ProtocolBugs{
8199 InvalidECDHPoint: true,
8200 },
8201 },
8202 shouldFail: true,
8203 expectedError: ":INVALID_ENCODING:",
8204 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008205 testCases = append(testCases, testCase{
8206 testType: serverTest,
8207 name: "InvalidECDHPoint-Server-TLS13",
8208 config: Config{
8209 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008210 CurvePreferences: []CurveID{CurveP256},
8211 Bugs: ProtocolBugs{
8212 InvalidECDHPoint: true,
8213 },
8214 },
8215 shouldFail: true,
8216 expectedError: ":INVALID_ENCODING:",
8217 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008218
8219 // The previous curve ID should be reported on TLS 1.2 resumption.
8220 testCases = append(testCases, testCase{
8221 name: "CurveID-Resume-Client",
8222 config: Config{
8223 MaxVersion: VersionTLS12,
8224 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8225 CurvePreferences: []CurveID{CurveX25519},
8226 },
8227 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8228 resumeSession: true,
8229 })
8230 testCases = append(testCases, testCase{
8231 testType: serverTest,
8232 name: "CurveID-Resume-Server",
8233 config: Config{
8234 MaxVersion: VersionTLS12,
8235 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8236 CurvePreferences: []CurveID{CurveX25519},
8237 },
8238 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8239 resumeSession: true,
8240 })
8241
8242 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8243 // one should be reported.
8244 testCases = append(testCases, testCase{
8245 name: "CurveID-Resume-Client-TLS13",
8246 config: Config{
8247 MaxVersion: VersionTLS13,
8248 CurvePreferences: []CurveID{CurveX25519},
8249 },
8250 resumeConfig: &Config{
8251 MaxVersion: VersionTLS13,
8252 CurvePreferences: []CurveID{CurveP256},
8253 },
8254 flags: []string{
8255 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8256 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8257 },
8258 resumeSession: true,
8259 })
8260 testCases = append(testCases, testCase{
8261 testType: serverTest,
8262 name: "CurveID-Resume-Server-TLS13",
8263 config: Config{
8264 MaxVersion: VersionTLS13,
8265 CurvePreferences: []CurveID{CurveX25519},
8266 },
8267 resumeConfig: &Config{
8268 MaxVersion: VersionTLS13,
8269 CurvePreferences: []CurveID{CurveP256},
8270 },
8271 flags: []string{
8272 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8273 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8274 },
8275 resumeSession: true,
8276 })
David Benjamina81967b2016-12-22 09:16:57 -05008277
8278 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8279 testCases = append(testCases, testCase{
8280 name: "PointFormat-ServerHello-TLS12",
8281 config: Config{
8282 MaxVersion: VersionTLS12,
8283 Bugs: ProtocolBugs{
8284 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8285 },
8286 },
8287 })
8288 testCases = append(testCases, testCase{
8289 name: "PointFormat-EncryptedExtensions-TLS13",
8290 config: Config{
8291 MaxVersion: VersionTLS13,
8292 Bugs: ProtocolBugs{
8293 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8294 },
8295 },
8296 shouldFail: true,
8297 expectedError: ":ERROR_PARSING_EXTENSION:",
8298 })
8299
8300 // Test that we tolerate unknown point formats, as long as
8301 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8302 // check they are still functional.
8303 testCases = append(testCases, testCase{
8304 name: "PointFormat-Client-Tolerance",
8305 config: Config{
8306 MaxVersion: VersionTLS12,
8307 Bugs: ProtocolBugs{
8308 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8309 },
8310 },
8311 })
8312 testCases = append(testCases, testCase{
8313 testType: serverTest,
8314 name: "PointFormat-Server-Tolerance",
8315 config: Config{
8316 MaxVersion: VersionTLS12,
8317 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8318 Bugs: ProtocolBugs{
8319 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8320 },
8321 },
8322 })
8323
8324 // Test TLS 1.2 does not require the point format extension to be
8325 // present.
8326 testCases = append(testCases, testCase{
8327 name: "PointFormat-Client-Missing",
8328 config: Config{
8329 MaxVersion: VersionTLS12,
8330 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8331 Bugs: ProtocolBugs{
8332 SendSupportedPointFormats: []byte{},
8333 },
8334 },
8335 })
8336 testCases = append(testCases, testCase{
8337 testType: serverTest,
8338 name: "PointFormat-Server-Missing",
8339 config: Config{
8340 MaxVersion: VersionTLS12,
8341 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8342 Bugs: ProtocolBugs{
8343 SendSupportedPointFormats: []byte{},
8344 },
8345 },
8346 })
8347
8348 // If the point format extension is present, uncompressed points must be
8349 // offered. BoringSSL requires this whether or not ECDHE is used.
8350 testCases = append(testCases, testCase{
8351 name: "PointFormat-Client-MissingUncompressed",
8352 config: Config{
8353 MaxVersion: VersionTLS12,
8354 Bugs: ProtocolBugs{
8355 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8356 },
8357 },
8358 shouldFail: true,
8359 expectedError: ":ERROR_PARSING_EXTENSION:",
8360 })
8361 testCases = append(testCases, testCase{
8362 testType: serverTest,
8363 name: "PointFormat-Server-MissingUncompressed",
8364 config: Config{
8365 MaxVersion: VersionTLS12,
8366 Bugs: ProtocolBugs{
8367 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8368 },
8369 },
8370 shouldFail: true,
8371 expectedError: ":ERROR_PARSING_EXTENSION:",
8372 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008373}
8374
David Benjaminc9ae27c2016-06-24 22:56:37 -04008375func addTLS13RecordTests() {
8376 testCases = append(testCases, testCase{
8377 name: "TLS13-RecordPadding",
8378 config: Config{
8379 MaxVersion: VersionTLS13,
8380 MinVersion: VersionTLS13,
8381 Bugs: ProtocolBugs{
8382 RecordPadding: 10,
8383 },
8384 },
8385 })
8386
8387 testCases = append(testCases, testCase{
8388 name: "TLS13-EmptyRecords",
8389 config: Config{
8390 MaxVersion: VersionTLS13,
8391 MinVersion: VersionTLS13,
8392 Bugs: ProtocolBugs{
8393 OmitRecordContents: true,
8394 },
8395 },
8396 shouldFail: true,
8397 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8398 })
8399
8400 testCases = append(testCases, testCase{
8401 name: "TLS13-OnlyPadding",
8402 config: Config{
8403 MaxVersion: VersionTLS13,
8404 MinVersion: VersionTLS13,
8405 Bugs: ProtocolBugs{
8406 OmitRecordContents: true,
8407 RecordPadding: 10,
8408 },
8409 },
8410 shouldFail: true,
8411 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8412 })
8413
8414 testCases = append(testCases, testCase{
8415 name: "TLS13-WrongOuterRecord",
8416 config: Config{
8417 MaxVersion: VersionTLS13,
8418 MinVersion: VersionTLS13,
8419 Bugs: ProtocolBugs{
8420 OuterRecordType: recordTypeHandshake,
8421 },
8422 },
8423 shouldFail: true,
8424 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8425 })
8426}
8427
Steven Valdez5b986082016-09-01 12:29:49 -04008428func addSessionTicketTests() {
8429 testCases = append(testCases, testCase{
8430 // In TLS 1.2 and below, empty NewSessionTicket messages
8431 // mean the server changed its mind on sending a ticket.
8432 name: "SendEmptySessionTicket",
8433 config: Config{
8434 MaxVersion: VersionTLS12,
8435 Bugs: ProtocolBugs{
8436 SendEmptySessionTicket: true,
8437 },
8438 },
8439 flags: []string{"-expect-no-session"},
8440 })
8441
8442 // Test that the server ignores unknown PSK modes.
8443 testCases = append(testCases, testCase{
8444 testType: serverTest,
8445 name: "TLS13-SendUnknownModeSessionTicket-Server",
8446 config: Config{
8447 MaxVersion: VersionTLS13,
8448 Bugs: ProtocolBugs{
8449 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008450 },
8451 },
8452 resumeSession: true,
8453 expectedResumeVersion: VersionTLS13,
8454 })
8455
Steven Valdeza833c352016-11-01 13:39:36 -04008456 // Test that the server does not send session tickets with no matching key exchange mode.
8457 testCases = append(testCases, testCase{
8458 testType: serverTest,
8459 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8460 config: Config{
8461 MaxVersion: VersionTLS13,
8462 Bugs: ProtocolBugs{
8463 SendPSKKeyExchangeModes: []byte{0x1a},
8464 ExpectNoNewSessionTicket: true,
8465 },
8466 },
8467 })
8468
8469 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008470 testCases = append(testCases, testCase{
8471 testType: serverTest,
8472 name: "TLS13-SendBadKEModeSessionTicket-Server",
8473 config: Config{
8474 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008475 },
8476 resumeConfig: &Config{
8477 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008478 Bugs: ProtocolBugs{
8479 SendPSKKeyExchangeModes: []byte{0x1a},
8480 },
8481 },
8482 resumeSession: true,
8483 expectResumeRejected: true,
8484 })
8485
Steven Valdeza833c352016-11-01 13:39:36 -04008486 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008487 testCases = append(testCases, testCase{
8488 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008489 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008490 config: Config{
8491 MaxVersion: VersionTLS13,
8492 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008493 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008494 },
8495 },
Steven Valdeza833c352016-11-01 13:39:36 -04008496 resumeSession: true,
8497 flags: []string{
8498 "-resumption-delay", "10",
8499 },
Steven Valdez5b986082016-09-01 12:29:49 -04008500 })
8501
Steven Valdeza833c352016-11-01 13:39:36 -04008502 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008503 testCases = append(testCases, testCase{
8504 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008505 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008506 config: Config{
8507 MaxVersion: VersionTLS13,
8508 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008509 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008510 },
8511 },
Steven Valdeza833c352016-11-01 13:39:36 -04008512 resumeSession: true,
8513 shouldFail: true,
8514 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008515 })
8516
Steven Valdez08b65f42016-12-07 15:29:45 -05008517 testCases = append(testCases, testCase{
8518 testType: clientTest,
8519 name: "TLS13-SendTicketEarlyDataInfo",
8520 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008521 MaxVersion: VersionTLS13,
8522 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008523 },
8524 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008525 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008526 "-expect-early-data-info",
8527 },
8528 })
8529
David Benjamin9b160662017-01-25 19:53:43 -05008530 // Test that 0-RTT tickets are ignored in clients unless opted in.
8531 testCases = append(testCases, testCase{
8532 testType: clientTest,
8533 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8534 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008535 MaxVersion: VersionTLS13,
8536 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008537 },
8538 })
8539
Steven Valdez08b65f42016-12-07 15:29:45 -05008540 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008541 testType: clientTest,
8542 name: "TLS13-DuplicateTicketEarlyDataInfo",
8543 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008544 MaxVersion: VersionTLS13,
8545 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008546 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008547 DuplicateTicketEarlyDataInfo: true,
8548 },
8549 },
8550 shouldFail: true,
8551 expectedError: ":DUPLICATE_EXTENSION:",
8552 expectedLocalError: "remote error: illegal parameter",
8553 })
8554
8555 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008556 testType: serverTest,
8557 name: "TLS13-ExpectTicketEarlyDataInfo",
8558 config: Config{
8559 MaxVersion: VersionTLS13,
8560 Bugs: ProtocolBugs{
8561 ExpectTicketEarlyDataInfo: true,
8562 },
8563 },
8564 flags: []string{
8565 "-enable-early-data",
8566 },
8567 })
David Benjamin17b30832017-01-28 14:00:32 -05008568
8569 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8570 // is honored.
8571 testCases = append(testCases, testCase{
8572 testType: clientTest,
8573 name: "TLS13-HonorServerSessionTicketLifetime",
8574 config: Config{
8575 MaxVersion: VersionTLS13,
8576 Bugs: ProtocolBugs{
8577 SendTicketLifetime: 20 * time.Second,
8578 },
8579 },
8580 flags: []string{
8581 "-resumption-delay", "19",
8582 },
8583 resumeSession: true,
8584 })
8585 testCases = append(testCases, testCase{
8586 testType: clientTest,
8587 name: "TLS13-HonorServerSessionTicketLifetime-2",
8588 config: Config{
8589 MaxVersion: VersionTLS13,
8590 Bugs: ProtocolBugs{
8591 SendTicketLifetime: 20 * time.Second,
8592 // The client should not offer the expired session.
8593 ExpectNoTLS13PSK: true,
8594 },
8595 },
8596 flags: []string{
8597 "-resumption-delay", "21",
8598 },
David Benjamin023d4192017-02-06 13:49:07 -05008599 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008600 expectResumeRejected: true,
8601 })
Steven Valdez5b986082016-09-01 12:29:49 -04008602}
8603
David Benjamin82261be2016-07-07 14:32:50 -07008604func addChangeCipherSpecTests() {
8605 // Test missing ChangeCipherSpecs.
8606 testCases = append(testCases, testCase{
8607 name: "SkipChangeCipherSpec-Client",
8608 config: Config{
8609 MaxVersion: VersionTLS12,
8610 Bugs: ProtocolBugs{
8611 SkipChangeCipherSpec: true,
8612 },
8613 },
8614 shouldFail: true,
8615 expectedError: ":UNEXPECTED_RECORD:",
8616 })
8617 testCases = append(testCases, testCase{
8618 testType: serverTest,
8619 name: "SkipChangeCipherSpec-Server",
8620 config: Config{
8621 MaxVersion: VersionTLS12,
8622 Bugs: ProtocolBugs{
8623 SkipChangeCipherSpec: true,
8624 },
8625 },
8626 shouldFail: true,
8627 expectedError: ":UNEXPECTED_RECORD:",
8628 })
8629 testCases = append(testCases, testCase{
8630 testType: serverTest,
8631 name: "SkipChangeCipherSpec-Server-NPN",
8632 config: Config{
8633 MaxVersion: VersionTLS12,
8634 NextProtos: []string{"bar"},
8635 Bugs: ProtocolBugs{
8636 SkipChangeCipherSpec: true,
8637 },
8638 },
8639 flags: []string{
8640 "-advertise-npn", "\x03foo\x03bar\x03baz",
8641 },
8642 shouldFail: true,
8643 expectedError: ":UNEXPECTED_RECORD:",
8644 })
8645
8646 // Test synchronization between the handshake and ChangeCipherSpec.
8647 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8648 // rejected. Test both with and without handshake packing to handle both
8649 // when the partial post-CCS message is in its own record and when it is
8650 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008651 for _, packed := range []bool{false, true} {
8652 var suffix string
8653 if packed {
8654 suffix = "-Packed"
8655 }
8656
8657 testCases = append(testCases, testCase{
8658 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8659 config: Config{
8660 MaxVersion: VersionTLS12,
8661 Bugs: ProtocolBugs{
8662 FragmentAcrossChangeCipherSpec: true,
8663 PackHandshakeFlight: packed,
8664 },
8665 },
8666 shouldFail: true,
8667 expectedError: ":UNEXPECTED_RECORD:",
8668 })
8669 testCases = append(testCases, testCase{
8670 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8671 config: Config{
8672 MaxVersion: VersionTLS12,
8673 },
8674 resumeSession: true,
8675 resumeConfig: &Config{
8676 MaxVersion: VersionTLS12,
8677 Bugs: ProtocolBugs{
8678 FragmentAcrossChangeCipherSpec: true,
8679 PackHandshakeFlight: packed,
8680 },
8681 },
8682 shouldFail: true,
8683 expectedError: ":UNEXPECTED_RECORD:",
8684 })
8685 testCases = append(testCases, testCase{
8686 testType: serverTest,
8687 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8688 config: Config{
8689 MaxVersion: VersionTLS12,
8690 Bugs: ProtocolBugs{
8691 FragmentAcrossChangeCipherSpec: true,
8692 PackHandshakeFlight: packed,
8693 },
8694 },
8695 shouldFail: true,
8696 expectedError: ":UNEXPECTED_RECORD:",
8697 })
8698 testCases = append(testCases, testCase{
8699 testType: serverTest,
8700 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8701 config: Config{
8702 MaxVersion: VersionTLS12,
8703 },
8704 resumeSession: true,
8705 resumeConfig: &Config{
8706 MaxVersion: VersionTLS12,
8707 Bugs: ProtocolBugs{
8708 FragmentAcrossChangeCipherSpec: true,
8709 PackHandshakeFlight: packed,
8710 },
8711 },
8712 shouldFail: true,
8713 expectedError: ":UNEXPECTED_RECORD:",
8714 })
8715 testCases = append(testCases, testCase{
8716 testType: serverTest,
8717 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8718 config: Config{
8719 MaxVersion: VersionTLS12,
8720 NextProtos: []string{"bar"},
8721 Bugs: ProtocolBugs{
8722 FragmentAcrossChangeCipherSpec: true,
8723 PackHandshakeFlight: packed,
8724 },
8725 },
8726 flags: []string{
8727 "-advertise-npn", "\x03foo\x03bar\x03baz",
8728 },
8729 shouldFail: true,
8730 expectedError: ":UNEXPECTED_RECORD:",
8731 })
8732 }
8733
David Benjamin61672812016-07-14 23:10:43 -04008734 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8735 // messages in the handshake queue. Do this by testing the server
8736 // reading the client Finished, reversing the flight so Finished comes
8737 // first.
8738 testCases = append(testCases, testCase{
8739 protocol: dtls,
8740 testType: serverTest,
8741 name: "SendUnencryptedFinished-DTLS",
8742 config: Config{
8743 MaxVersion: VersionTLS12,
8744 Bugs: ProtocolBugs{
8745 SendUnencryptedFinished: true,
8746 ReverseHandshakeFragments: true,
8747 },
8748 },
8749 shouldFail: true,
8750 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8751 })
8752
Steven Valdez143e8b32016-07-11 13:19:03 -04008753 // Test synchronization between encryption changes and the handshake in
8754 // TLS 1.3, where ChangeCipherSpec is implicit.
8755 testCases = append(testCases, testCase{
8756 name: "PartialEncryptedExtensionsWithServerHello",
8757 config: Config{
8758 MaxVersion: VersionTLS13,
8759 Bugs: ProtocolBugs{
8760 PartialEncryptedExtensionsWithServerHello: true,
8761 },
8762 },
8763 shouldFail: true,
8764 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8765 })
8766 testCases = append(testCases, testCase{
8767 testType: serverTest,
8768 name: "PartialClientFinishedWithClientHello",
8769 config: Config{
8770 MaxVersion: VersionTLS13,
8771 Bugs: ProtocolBugs{
8772 PartialClientFinishedWithClientHello: true,
8773 },
8774 },
8775 shouldFail: true,
8776 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8777 })
8778
David Benjamin82261be2016-07-07 14:32:50 -07008779 // Test that early ChangeCipherSpecs are handled correctly.
8780 testCases = append(testCases, testCase{
8781 testType: serverTest,
8782 name: "EarlyChangeCipherSpec-server-1",
8783 config: Config{
8784 MaxVersion: VersionTLS12,
8785 Bugs: ProtocolBugs{
8786 EarlyChangeCipherSpec: 1,
8787 },
8788 },
8789 shouldFail: true,
8790 expectedError: ":UNEXPECTED_RECORD:",
8791 })
8792 testCases = append(testCases, testCase{
8793 testType: serverTest,
8794 name: "EarlyChangeCipherSpec-server-2",
8795 config: Config{
8796 MaxVersion: VersionTLS12,
8797 Bugs: ProtocolBugs{
8798 EarlyChangeCipherSpec: 2,
8799 },
8800 },
8801 shouldFail: true,
8802 expectedError: ":UNEXPECTED_RECORD:",
8803 })
8804 testCases = append(testCases, testCase{
8805 protocol: dtls,
8806 name: "StrayChangeCipherSpec",
8807 config: Config{
8808 // TODO(davidben): Once DTLS 1.3 exists, test
8809 // that stray ChangeCipherSpec messages are
8810 // rejected.
8811 MaxVersion: VersionTLS12,
8812 Bugs: ProtocolBugs{
8813 StrayChangeCipherSpec: true,
8814 },
8815 },
8816 })
8817
8818 // Test that the contents of ChangeCipherSpec are checked.
8819 testCases = append(testCases, testCase{
8820 name: "BadChangeCipherSpec-1",
8821 config: Config{
8822 MaxVersion: VersionTLS12,
8823 Bugs: ProtocolBugs{
8824 BadChangeCipherSpec: []byte{2},
8825 },
8826 },
8827 shouldFail: true,
8828 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8829 })
8830 testCases = append(testCases, testCase{
8831 name: "BadChangeCipherSpec-2",
8832 config: Config{
8833 MaxVersion: VersionTLS12,
8834 Bugs: ProtocolBugs{
8835 BadChangeCipherSpec: []byte{1, 1},
8836 },
8837 },
8838 shouldFail: true,
8839 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8840 })
8841 testCases = append(testCases, testCase{
8842 protocol: dtls,
8843 name: "BadChangeCipherSpec-DTLS-1",
8844 config: Config{
8845 MaxVersion: VersionTLS12,
8846 Bugs: ProtocolBugs{
8847 BadChangeCipherSpec: []byte{2},
8848 },
8849 },
8850 shouldFail: true,
8851 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8852 })
8853 testCases = append(testCases, testCase{
8854 protocol: dtls,
8855 name: "BadChangeCipherSpec-DTLS-2",
8856 config: Config{
8857 MaxVersion: VersionTLS12,
8858 Bugs: ProtocolBugs{
8859 BadChangeCipherSpec: []byte{1, 1},
8860 },
8861 },
8862 shouldFail: true,
8863 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8864 })
8865}
8866
David Benjamincd2c8062016-09-09 11:28:16 -04008867type perMessageTest struct {
8868 messageType uint8
8869 test testCase
8870}
8871
8872// makePerMessageTests returns a series of test templates which cover each
8873// message in the TLS handshake. These may be used with bugs like
8874// WrongMessageType to fully test a per-message bug.
8875func makePerMessageTests() []perMessageTest {
8876 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008877 for _, protocol := range []protocol{tls, dtls} {
8878 var suffix string
8879 if protocol == dtls {
8880 suffix = "-DTLS"
8881 }
8882
David Benjamincd2c8062016-09-09 11:28:16 -04008883 ret = append(ret, perMessageTest{
8884 messageType: typeClientHello,
8885 test: testCase{
8886 protocol: protocol,
8887 testType: serverTest,
8888 name: "ClientHello" + suffix,
8889 config: Config{
8890 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008891 },
8892 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008893 })
8894
8895 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008896 ret = append(ret, perMessageTest{
8897 messageType: typeHelloVerifyRequest,
8898 test: testCase{
8899 protocol: protocol,
8900 name: "HelloVerifyRequest" + suffix,
8901 config: Config{
8902 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008903 },
8904 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008905 })
8906 }
8907
David Benjamincd2c8062016-09-09 11:28:16 -04008908 ret = append(ret, perMessageTest{
8909 messageType: typeServerHello,
8910 test: testCase{
8911 protocol: protocol,
8912 name: "ServerHello" + suffix,
8913 config: Config{
8914 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008915 },
8916 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008917 })
8918
David Benjamincd2c8062016-09-09 11:28:16 -04008919 ret = append(ret, perMessageTest{
8920 messageType: typeCertificate,
8921 test: testCase{
8922 protocol: protocol,
8923 name: "ServerCertificate" + suffix,
8924 config: Config{
8925 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008926 },
8927 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008928 })
8929
David Benjamincd2c8062016-09-09 11:28:16 -04008930 ret = append(ret, perMessageTest{
8931 messageType: typeCertificateStatus,
8932 test: testCase{
8933 protocol: protocol,
8934 name: "CertificateStatus" + suffix,
8935 config: Config{
8936 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008937 },
David Benjamincd2c8062016-09-09 11:28:16 -04008938 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008939 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008940 })
8941
David Benjamincd2c8062016-09-09 11:28:16 -04008942 ret = append(ret, perMessageTest{
8943 messageType: typeServerKeyExchange,
8944 test: testCase{
8945 protocol: protocol,
8946 name: "ServerKeyExchange" + suffix,
8947 config: Config{
8948 MaxVersion: VersionTLS12,
8949 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008950 },
8951 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008952 })
8953
David Benjamincd2c8062016-09-09 11:28:16 -04008954 ret = append(ret, perMessageTest{
8955 messageType: typeCertificateRequest,
8956 test: testCase{
8957 protocol: protocol,
8958 name: "CertificateRequest" + suffix,
8959 config: Config{
8960 MaxVersion: VersionTLS12,
8961 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008962 },
8963 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008964 })
8965
David Benjamincd2c8062016-09-09 11:28:16 -04008966 ret = append(ret, perMessageTest{
8967 messageType: typeServerHelloDone,
8968 test: testCase{
8969 protocol: protocol,
8970 name: "ServerHelloDone" + suffix,
8971 config: Config{
8972 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008973 },
8974 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008975 })
8976
David Benjamincd2c8062016-09-09 11:28:16 -04008977 ret = append(ret, perMessageTest{
8978 messageType: typeCertificate,
8979 test: testCase{
8980 testType: serverTest,
8981 protocol: protocol,
8982 name: "ClientCertificate" + suffix,
8983 config: Config{
8984 Certificates: []Certificate{rsaCertificate},
8985 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008986 },
David Benjamincd2c8062016-09-09 11:28:16 -04008987 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008988 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008989 })
8990
David Benjamincd2c8062016-09-09 11:28:16 -04008991 ret = append(ret, perMessageTest{
8992 messageType: typeCertificateVerify,
8993 test: testCase{
8994 testType: serverTest,
8995 protocol: protocol,
8996 name: "CertificateVerify" + suffix,
8997 config: Config{
8998 Certificates: []Certificate{rsaCertificate},
8999 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009000 },
David Benjamincd2c8062016-09-09 11:28:16 -04009001 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009002 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009003 })
9004
David Benjamincd2c8062016-09-09 11:28:16 -04009005 ret = append(ret, perMessageTest{
9006 messageType: typeClientKeyExchange,
9007 test: testCase{
9008 testType: serverTest,
9009 protocol: protocol,
9010 name: "ClientKeyExchange" + suffix,
9011 config: Config{
9012 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009013 },
9014 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009015 })
9016
9017 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009018 ret = append(ret, perMessageTest{
9019 messageType: typeNextProtocol,
9020 test: testCase{
9021 testType: serverTest,
9022 protocol: protocol,
9023 name: "NextProtocol" + suffix,
9024 config: Config{
9025 MaxVersion: VersionTLS12,
9026 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009027 },
David Benjamincd2c8062016-09-09 11:28:16 -04009028 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009029 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009030 })
9031
David Benjamincd2c8062016-09-09 11:28:16 -04009032 ret = append(ret, perMessageTest{
9033 messageType: typeChannelID,
9034 test: testCase{
9035 testType: serverTest,
9036 protocol: protocol,
9037 name: "ChannelID" + suffix,
9038 config: Config{
9039 MaxVersion: VersionTLS12,
9040 ChannelID: channelIDKey,
9041 },
9042 flags: []string{
9043 "-expect-channel-id",
9044 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009045 },
9046 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009047 })
9048 }
9049
David Benjamincd2c8062016-09-09 11:28:16 -04009050 ret = append(ret, perMessageTest{
9051 messageType: typeFinished,
9052 test: testCase{
9053 testType: serverTest,
9054 protocol: protocol,
9055 name: "ClientFinished" + suffix,
9056 config: Config{
9057 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009058 },
9059 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009060 })
9061
David Benjamincd2c8062016-09-09 11:28:16 -04009062 ret = append(ret, perMessageTest{
9063 messageType: typeNewSessionTicket,
9064 test: testCase{
9065 protocol: protocol,
9066 name: "NewSessionTicket" + suffix,
9067 config: Config{
9068 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009069 },
9070 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009071 })
9072
David Benjamincd2c8062016-09-09 11:28:16 -04009073 ret = append(ret, perMessageTest{
9074 messageType: typeFinished,
9075 test: testCase{
9076 protocol: protocol,
9077 name: "ServerFinished" + suffix,
9078 config: Config{
9079 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009080 },
9081 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009082 })
9083
9084 }
David Benjamincd2c8062016-09-09 11:28:16 -04009085
9086 ret = append(ret, perMessageTest{
9087 messageType: typeClientHello,
9088 test: testCase{
9089 testType: serverTest,
9090 name: "TLS13-ClientHello",
9091 config: Config{
9092 MaxVersion: VersionTLS13,
9093 },
9094 },
9095 })
9096
9097 ret = append(ret, perMessageTest{
9098 messageType: typeServerHello,
9099 test: testCase{
9100 name: "TLS13-ServerHello",
9101 config: Config{
9102 MaxVersion: VersionTLS13,
9103 },
9104 },
9105 })
9106
9107 ret = append(ret, perMessageTest{
9108 messageType: typeEncryptedExtensions,
9109 test: testCase{
9110 name: "TLS13-EncryptedExtensions",
9111 config: Config{
9112 MaxVersion: VersionTLS13,
9113 },
9114 },
9115 })
9116
9117 ret = append(ret, perMessageTest{
9118 messageType: typeCertificateRequest,
9119 test: testCase{
9120 name: "TLS13-CertificateRequest",
9121 config: Config{
9122 MaxVersion: VersionTLS13,
9123 ClientAuth: RequireAnyClientCert,
9124 },
9125 },
9126 })
9127
9128 ret = append(ret, perMessageTest{
9129 messageType: typeCertificate,
9130 test: testCase{
9131 name: "TLS13-ServerCertificate",
9132 config: Config{
9133 MaxVersion: VersionTLS13,
9134 },
9135 },
9136 })
9137
9138 ret = append(ret, perMessageTest{
9139 messageType: typeCertificateVerify,
9140 test: testCase{
9141 name: "TLS13-ServerCertificateVerify",
9142 config: Config{
9143 MaxVersion: VersionTLS13,
9144 },
9145 },
9146 })
9147
9148 ret = append(ret, perMessageTest{
9149 messageType: typeFinished,
9150 test: testCase{
9151 name: "TLS13-ServerFinished",
9152 config: Config{
9153 MaxVersion: VersionTLS13,
9154 },
9155 },
9156 })
9157
9158 ret = append(ret, perMessageTest{
9159 messageType: typeCertificate,
9160 test: testCase{
9161 testType: serverTest,
9162 name: "TLS13-ClientCertificate",
9163 config: Config{
9164 Certificates: []Certificate{rsaCertificate},
9165 MaxVersion: VersionTLS13,
9166 },
9167 flags: []string{"-require-any-client-certificate"},
9168 },
9169 })
9170
9171 ret = append(ret, perMessageTest{
9172 messageType: typeCertificateVerify,
9173 test: testCase{
9174 testType: serverTest,
9175 name: "TLS13-ClientCertificateVerify",
9176 config: Config{
9177 Certificates: []Certificate{rsaCertificate},
9178 MaxVersion: VersionTLS13,
9179 },
9180 flags: []string{"-require-any-client-certificate"},
9181 },
9182 })
9183
9184 ret = append(ret, perMessageTest{
9185 messageType: typeFinished,
9186 test: testCase{
9187 testType: serverTest,
9188 name: "TLS13-ClientFinished",
9189 config: Config{
9190 MaxVersion: VersionTLS13,
9191 },
9192 },
9193 })
9194
9195 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009196}
9197
David Benjamincd2c8062016-09-09 11:28:16 -04009198func addWrongMessageTypeTests() {
9199 for _, t := range makePerMessageTests() {
9200 t.test.name = "WrongMessageType-" + t.test.name
9201 t.test.config.Bugs.SendWrongMessageType = t.messageType
9202 t.test.shouldFail = true
9203 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9204 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009205
David Benjamincd2c8062016-09-09 11:28:16 -04009206 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9207 // In TLS 1.3, a bad ServerHello means the client sends
9208 // an unencrypted alert while the server expects
9209 // encryption, so the alert is not readable by runner.
9210 t.test.expectedLocalError = "local error: bad record MAC"
9211 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009212
David Benjamincd2c8062016-09-09 11:28:16 -04009213 testCases = append(testCases, t.test)
9214 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009215}
9216
David Benjamin639846e2016-09-09 11:41:18 -04009217func addTrailingMessageDataTests() {
9218 for _, t := range makePerMessageTests() {
9219 t.test.name = "TrailingMessageData-" + t.test.name
9220 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9221 t.test.shouldFail = true
9222 t.test.expectedError = ":DECODE_ERROR:"
9223 t.test.expectedLocalError = "remote error: error decoding message"
9224
9225 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9226 // In TLS 1.3, a bad ServerHello means the client sends
9227 // an unencrypted alert while the server expects
9228 // encryption, so the alert is not readable by runner.
9229 t.test.expectedLocalError = "local error: bad record MAC"
9230 }
9231
9232 if t.messageType == typeFinished {
9233 // Bad Finished messages read as the verify data having
9234 // the wrong length.
9235 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9236 t.test.expectedLocalError = "remote error: error decrypting message"
9237 }
9238
9239 testCases = append(testCases, t.test)
9240 }
9241}
9242
Steven Valdez143e8b32016-07-11 13:19:03 -04009243func addTLS13HandshakeTests() {
9244 testCases = append(testCases, testCase{
9245 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009246 name: "NegotiatePSKResumption-TLS13",
9247 config: Config{
9248 MaxVersion: VersionTLS13,
9249 Bugs: ProtocolBugs{
9250 NegotiatePSKResumption: true,
9251 },
9252 },
9253 resumeSession: true,
9254 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009255 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009256 })
9257
9258 testCases = append(testCases, testCase{
9259 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009260 name: "MissingKeyShare-Client",
9261 config: Config{
9262 MaxVersion: VersionTLS13,
9263 Bugs: ProtocolBugs{
9264 MissingKeyShare: true,
9265 },
9266 },
9267 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009268 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009269 })
9270
9271 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009272 testType: serverTest,
9273 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009274 config: Config{
9275 MaxVersion: VersionTLS13,
9276 Bugs: ProtocolBugs{
9277 MissingKeyShare: true,
9278 },
9279 },
9280 shouldFail: true,
9281 expectedError: ":MISSING_KEY_SHARE:",
9282 })
9283
9284 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009285 testType: serverTest,
9286 name: "DuplicateKeyShares",
9287 config: Config{
9288 MaxVersion: VersionTLS13,
9289 Bugs: ProtocolBugs{
9290 DuplicateKeyShares: true,
9291 },
9292 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009293 shouldFail: true,
9294 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009295 })
9296
9297 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009298 testType: serverTest,
9299 name: "SkipEarlyData",
9300 config: Config{
9301 MaxVersion: VersionTLS13,
9302 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009303 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009304 },
9305 },
9306 })
9307
9308 testCases = append(testCases, testCase{
9309 testType: serverTest,
9310 name: "SkipEarlyData-OmitEarlyDataExtension",
9311 config: Config{
9312 MaxVersion: VersionTLS13,
9313 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009314 SendFakeEarlyDataLength: 4,
9315 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009316 },
9317 },
9318 shouldFail: true,
9319 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9320 })
9321
9322 testCases = append(testCases, testCase{
9323 testType: serverTest,
9324 name: "SkipEarlyData-TooMuchData",
9325 config: Config{
9326 MaxVersion: VersionTLS13,
9327 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009328 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009329 },
9330 },
9331 shouldFail: true,
9332 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9333 })
9334
9335 testCases = append(testCases, testCase{
9336 testType: serverTest,
9337 name: "SkipEarlyData-Interleaved",
9338 config: Config{
9339 MaxVersion: VersionTLS13,
9340 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009341 SendFakeEarlyDataLength: 4,
9342 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009343 },
9344 },
9345 shouldFail: true,
9346 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9347 })
9348
9349 testCases = append(testCases, testCase{
9350 testType: serverTest,
9351 name: "SkipEarlyData-EarlyDataInTLS12",
9352 config: Config{
9353 MaxVersion: VersionTLS13,
9354 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009355 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009356 },
9357 },
9358 shouldFail: true,
9359 expectedError: ":UNEXPECTED_RECORD:",
9360 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9361 })
9362
9363 testCases = append(testCases, testCase{
9364 testType: serverTest,
9365 name: "SkipEarlyData-HRR",
9366 config: Config{
9367 MaxVersion: VersionTLS13,
9368 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009369 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009370 },
9371 DefaultCurves: []CurveID{},
9372 },
9373 })
9374
9375 testCases = append(testCases, testCase{
9376 testType: serverTest,
9377 name: "SkipEarlyData-HRR-Interleaved",
9378 config: Config{
9379 MaxVersion: VersionTLS13,
9380 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009381 SendFakeEarlyDataLength: 4,
9382 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009383 },
9384 DefaultCurves: []CurveID{},
9385 },
9386 shouldFail: true,
9387 expectedError: ":UNEXPECTED_RECORD:",
9388 })
9389
9390 testCases = append(testCases, testCase{
9391 testType: serverTest,
9392 name: "SkipEarlyData-HRR-TooMuchData",
9393 config: Config{
9394 MaxVersion: VersionTLS13,
9395 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009396 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009397 },
9398 DefaultCurves: []CurveID{},
9399 },
9400 shouldFail: true,
9401 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9402 })
9403
9404 // Test that skipping early data looking for cleartext correctly
9405 // processes an alert record.
9406 testCases = append(testCases, testCase{
9407 testType: serverTest,
9408 name: "SkipEarlyData-HRR-FatalAlert",
9409 config: Config{
9410 MaxVersion: VersionTLS13,
9411 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009412 SendEarlyAlert: true,
9413 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009414 },
9415 DefaultCurves: []CurveID{},
9416 },
9417 shouldFail: true,
9418 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9419 })
9420
9421 testCases = append(testCases, testCase{
9422 testType: serverTest,
9423 name: "SkipEarlyData-SecondClientHelloEarlyData",
9424 config: Config{
9425 MaxVersion: VersionTLS13,
9426 Bugs: ProtocolBugs{
9427 SendEarlyDataOnSecondClientHello: true,
9428 },
9429 DefaultCurves: []CurveID{},
9430 },
9431 shouldFail: true,
9432 expectedLocalError: "remote error: bad record MAC",
9433 })
9434
9435 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009436 testType: clientTest,
9437 name: "EmptyEncryptedExtensions",
9438 config: Config{
9439 MaxVersion: VersionTLS13,
9440 Bugs: ProtocolBugs{
9441 EmptyEncryptedExtensions: true,
9442 },
9443 },
9444 shouldFail: true,
9445 expectedLocalError: "remote error: error decoding message",
9446 })
9447
9448 testCases = append(testCases, testCase{
9449 testType: clientTest,
9450 name: "EncryptedExtensionsWithKeyShare",
9451 config: Config{
9452 MaxVersion: VersionTLS13,
9453 Bugs: ProtocolBugs{
9454 EncryptedExtensionsWithKeyShare: true,
9455 },
9456 },
9457 shouldFail: true,
9458 expectedLocalError: "remote error: unsupported extension",
9459 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009460
9461 testCases = append(testCases, testCase{
9462 testType: serverTest,
9463 name: "SendHelloRetryRequest",
9464 config: Config{
9465 MaxVersion: VersionTLS13,
9466 // Require a HelloRetryRequest for every curve.
9467 DefaultCurves: []CurveID{},
9468 },
9469 expectedCurveID: CurveX25519,
9470 })
9471
9472 testCases = append(testCases, testCase{
9473 testType: serverTest,
9474 name: "SendHelloRetryRequest-2",
9475 config: Config{
9476 MaxVersion: VersionTLS13,
9477 DefaultCurves: []CurveID{CurveP384},
9478 },
9479 // Although the ClientHello did not predict our preferred curve,
9480 // we always select it whether it is predicted or not.
9481 expectedCurveID: CurveX25519,
9482 })
9483
9484 testCases = append(testCases, testCase{
9485 name: "UnknownCurve-HelloRetryRequest",
9486 config: Config{
9487 MaxVersion: VersionTLS13,
9488 // P-384 requires HelloRetryRequest in BoringSSL.
9489 CurvePreferences: []CurveID{CurveP384},
9490 Bugs: ProtocolBugs{
9491 SendHelloRetryRequestCurve: bogusCurve,
9492 },
9493 },
9494 shouldFail: true,
9495 expectedError: ":WRONG_CURVE:",
9496 })
9497
9498 testCases = append(testCases, testCase{
9499 name: "DisabledCurve-HelloRetryRequest",
9500 config: Config{
9501 MaxVersion: VersionTLS13,
9502 CurvePreferences: []CurveID{CurveP256},
9503 Bugs: ProtocolBugs{
9504 IgnorePeerCurvePreferences: true,
9505 },
9506 },
9507 flags: []string{"-p384-only"},
9508 shouldFail: true,
9509 expectedError: ":WRONG_CURVE:",
9510 })
9511
9512 testCases = append(testCases, testCase{
9513 name: "UnnecessaryHelloRetryRequest",
9514 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009515 MaxVersion: VersionTLS13,
9516 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009517 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009518 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009519 },
9520 },
9521 shouldFail: true,
9522 expectedError: ":WRONG_CURVE:",
9523 })
9524
9525 testCases = append(testCases, testCase{
9526 name: "SecondHelloRetryRequest",
9527 config: Config{
9528 MaxVersion: VersionTLS13,
9529 // P-384 requires HelloRetryRequest in BoringSSL.
9530 CurvePreferences: []CurveID{CurveP384},
9531 Bugs: ProtocolBugs{
9532 SecondHelloRetryRequest: true,
9533 },
9534 },
9535 shouldFail: true,
9536 expectedError: ":UNEXPECTED_MESSAGE:",
9537 })
9538
9539 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009540 name: "HelloRetryRequest-Empty",
9541 config: Config{
9542 MaxVersion: VersionTLS13,
9543 Bugs: ProtocolBugs{
9544 AlwaysSendHelloRetryRequest: true,
9545 },
9546 },
9547 shouldFail: true,
9548 expectedError: ":DECODE_ERROR:",
9549 })
9550
9551 testCases = append(testCases, testCase{
9552 name: "HelloRetryRequest-DuplicateCurve",
9553 config: Config{
9554 MaxVersion: VersionTLS13,
9555 // P-384 requires a HelloRetryRequest against BoringSSL's default
9556 // configuration. Assert this ExpectMissingKeyShare.
9557 CurvePreferences: []CurveID{CurveP384},
9558 Bugs: ProtocolBugs{
9559 ExpectMissingKeyShare: true,
9560 DuplicateHelloRetryRequestExtensions: true,
9561 },
9562 },
9563 shouldFail: true,
9564 expectedError: ":DUPLICATE_EXTENSION:",
9565 expectedLocalError: "remote error: illegal parameter",
9566 })
9567
9568 testCases = append(testCases, testCase{
9569 name: "HelloRetryRequest-Cookie",
9570 config: Config{
9571 MaxVersion: VersionTLS13,
9572 Bugs: ProtocolBugs{
9573 SendHelloRetryRequestCookie: []byte("cookie"),
9574 },
9575 },
9576 })
9577
9578 testCases = append(testCases, testCase{
9579 name: "HelloRetryRequest-DuplicateCookie",
9580 config: Config{
9581 MaxVersion: VersionTLS13,
9582 Bugs: ProtocolBugs{
9583 SendHelloRetryRequestCookie: []byte("cookie"),
9584 DuplicateHelloRetryRequestExtensions: true,
9585 },
9586 },
9587 shouldFail: true,
9588 expectedError: ":DUPLICATE_EXTENSION:",
9589 expectedLocalError: "remote error: illegal parameter",
9590 })
9591
9592 testCases = append(testCases, testCase{
9593 name: "HelloRetryRequest-EmptyCookie",
9594 config: Config{
9595 MaxVersion: VersionTLS13,
9596 Bugs: ProtocolBugs{
9597 SendHelloRetryRequestCookie: []byte{},
9598 },
9599 },
9600 shouldFail: true,
9601 expectedError: ":DECODE_ERROR:",
9602 })
9603
9604 testCases = append(testCases, testCase{
9605 name: "HelloRetryRequest-Cookie-Curve",
9606 config: Config{
9607 MaxVersion: VersionTLS13,
9608 // P-384 requires HelloRetryRequest in BoringSSL.
9609 CurvePreferences: []CurveID{CurveP384},
9610 Bugs: ProtocolBugs{
9611 SendHelloRetryRequestCookie: []byte("cookie"),
9612 ExpectMissingKeyShare: true,
9613 },
9614 },
9615 })
9616
9617 testCases = append(testCases, testCase{
9618 name: "HelloRetryRequest-Unknown",
9619 config: Config{
9620 MaxVersion: VersionTLS13,
9621 Bugs: ProtocolBugs{
9622 CustomHelloRetryRequestExtension: "extension",
9623 },
9624 },
9625 shouldFail: true,
9626 expectedError: ":UNEXPECTED_EXTENSION:",
9627 expectedLocalError: "remote error: unsupported extension",
9628 })
9629
9630 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009631 testType: serverTest,
9632 name: "SecondClientHelloMissingKeyShare",
9633 config: Config{
9634 MaxVersion: VersionTLS13,
9635 DefaultCurves: []CurveID{},
9636 Bugs: ProtocolBugs{
9637 SecondClientHelloMissingKeyShare: true,
9638 },
9639 },
9640 shouldFail: true,
9641 expectedError: ":MISSING_KEY_SHARE:",
9642 })
9643
9644 testCases = append(testCases, testCase{
9645 testType: serverTest,
9646 name: "SecondClientHelloWrongCurve",
9647 config: Config{
9648 MaxVersion: VersionTLS13,
9649 DefaultCurves: []CurveID{},
9650 Bugs: ProtocolBugs{
9651 MisinterpretHelloRetryRequestCurve: CurveP521,
9652 },
9653 },
9654 shouldFail: true,
9655 expectedError: ":WRONG_CURVE:",
9656 })
9657
9658 testCases = append(testCases, testCase{
9659 name: "HelloRetryRequestVersionMismatch",
9660 config: Config{
9661 MaxVersion: VersionTLS13,
9662 // P-384 requires HelloRetryRequest in BoringSSL.
9663 CurvePreferences: []CurveID{CurveP384},
9664 Bugs: ProtocolBugs{
9665 SendServerHelloVersion: 0x0305,
9666 },
9667 },
9668 shouldFail: true,
9669 expectedError: ":WRONG_VERSION_NUMBER:",
9670 })
9671
9672 testCases = append(testCases, testCase{
9673 name: "HelloRetryRequestCurveMismatch",
9674 config: Config{
9675 MaxVersion: VersionTLS13,
9676 // P-384 requires HelloRetryRequest in BoringSSL.
9677 CurvePreferences: []CurveID{CurveP384},
9678 Bugs: ProtocolBugs{
9679 // Send P-384 (correct) in the HelloRetryRequest.
9680 SendHelloRetryRequestCurve: CurveP384,
9681 // But send P-256 in the ServerHello.
9682 SendCurve: CurveP256,
9683 },
9684 },
9685 shouldFail: true,
9686 expectedError: ":WRONG_CURVE:",
9687 })
9688
9689 // Test the server selecting a curve that requires a HelloRetryRequest
9690 // without sending it.
9691 testCases = append(testCases, testCase{
9692 name: "SkipHelloRetryRequest",
9693 config: Config{
9694 MaxVersion: VersionTLS13,
9695 // P-384 requires HelloRetryRequest in BoringSSL.
9696 CurvePreferences: []CurveID{CurveP384},
9697 Bugs: ProtocolBugs{
9698 SkipHelloRetryRequest: true,
9699 },
9700 },
9701 shouldFail: true,
9702 expectedError: ":WRONG_CURVE:",
9703 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009704
9705 testCases = append(testCases, testCase{
9706 name: "TLS13-RequestContextInHandshake",
9707 config: Config{
9708 MaxVersion: VersionTLS13,
9709 MinVersion: VersionTLS13,
9710 ClientAuth: RequireAnyClientCert,
9711 Bugs: ProtocolBugs{
9712 SendRequestContext: []byte("request context"),
9713 },
9714 },
9715 flags: []string{
9716 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9717 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9718 },
9719 shouldFail: true,
9720 expectedError: ":DECODE_ERROR:",
9721 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009722
9723 testCases = append(testCases, testCase{
9724 testType: serverTest,
9725 name: "TLS13-TrailingKeyShareData",
9726 config: Config{
9727 MaxVersion: VersionTLS13,
9728 Bugs: ProtocolBugs{
9729 TrailingKeyShareData: true,
9730 },
9731 },
9732 shouldFail: true,
9733 expectedError: ":DECODE_ERROR:",
9734 })
David Benjamin7f78df42016-10-05 22:33:19 -04009735
9736 testCases = append(testCases, testCase{
9737 name: "TLS13-AlwaysSelectPSKIdentity",
9738 config: Config{
9739 MaxVersion: VersionTLS13,
9740 Bugs: ProtocolBugs{
9741 AlwaysSelectPSKIdentity: true,
9742 },
9743 },
9744 shouldFail: true,
9745 expectedError: ":UNEXPECTED_EXTENSION:",
9746 })
9747
9748 testCases = append(testCases, testCase{
9749 name: "TLS13-InvalidPSKIdentity",
9750 config: Config{
9751 MaxVersion: VersionTLS13,
9752 Bugs: ProtocolBugs{
9753 SelectPSKIdentityOnResume: 1,
9754 },
9755 },
9756 resumeSession: true,
9757 shouldFail: true,
9758 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9759 })
David Benjamin1286bee2016-10-07 15:25:06 -04009760
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009761 testCases = append(testCases, testCase{
9762 testType: serverTest,
9763 name: "TLS13-ExtraPSKIdentity",
9764 config: Config{
9765 MaxVersion: VersionTLS13,
9766 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009767 ExtraPSKIdentity: true,
9768 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009769 },
9770 },
9771 resumeSession: true,
9772 })
9773
David Benjamin1286bee2016-10-07 15:25:06 -04009774 // Test that unknown NewSessionTicket extensions are tolerated.
9775 testCases = append(testCases, testCase{
9776 name: "TLS13-CustomTicketExtension",
9777 config: Config{
9778 MaxVersion: VersionTLS13,
9779 Bugs: ProtocolBugs{
9780 CustomTicketExtension: "1234",
9781 },
9782 },
9783 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009784}
9785
David Benjaminabbbee12016-10-31 19:20:42 -04009786func addTLS13CipherPreferenceTests() {
9787 // Test that client preference is honored if the shim has AES hardware
9788 // and ChaCha20-Poly1305 is preferred otherwise.
9789 testCases = append(testCases, testCase{
9790 testType: serverTest,
9791 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9792 config: Config{
9793 MaxVersion: VersionTLS13,
9794 CipherSuites: []uint16{
9795 TLS_CHACHA20_POLY1305_SHA256,
9796 TLS_AES_128_GCM_SHA256,
9797 },
9798 },
9799 flags: []string{
9800 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9801 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9802 },
9803 })
9804
9805 testCases = append(testCases, testCase{
9806 testType: serverTest,
9807 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9808 config: Config{
9809 MaxVersion: VersionTLS13,
9810 CipherSuites: []uint16{
9811 TLS_AES_128_GCM_SHA256,
9812 TLS_CHACHA20_POLY1305_SHA256,
9813 },
9814 },
9815 flags: []string{
9816 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9817 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9818 },
9819 })
9820
9821 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9822 // whether it has AES hardware.
9823 testCases = append(testCases, testCase{
9824 name: "TLS13-CipherPreference-Client",
9825 config: Config{
9826 MaxVersion: VersionTLS13,
9827 // Use the client cipher order. (This is the default but
9828 // is listed to be explicit.)
9829 PreferServerCipherSuites: false,
9830 },
9831 flags: []string{
9832 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9833 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9834 },
9835 })
9836}
9837
David Benjaminf3fbade2016-09-19 13:08:16 -04009838func addPeekTests() {
9839 // Test SSL_peek works, including on empty records.
9840 testCases = append(testCases, testCase{
9841 name: "Peek-Basic",
9842 sendEmptyRecords: 1,
9843 flags: []string{"-peek-then-read"},
9844 })
9845
9846 // Test SSL_peek can drive the initial handshake.
9847 testCases = append(testCases, testCase{
9848 name: "Peek-ImplicitHandshake",
9849 flags: []string{
9850 "-peek-then-read",
9851 "-implicit-handshake",
9852 },
9853 })
9854
9855 // Test SSL_peek can discover and drive a renegotiation.
9856 testCases = append(testCases, testCase{
9857 name: "Peek-Renegotiate",
9858 config: Config{
9859 MaxVersion: VersionTLS12,
9860 },
9861 renegotiate: 1,
9862 flags: []string{
9863 "-peek-then-read",
9864 "-renegotiate-freely",
9865 "-expect-total-renegotiations", "1",
9866 },
9867 })
9868
9869 // Test SSL_peek can discover a close_notify.
9870 testCases = append(testCases, testCase{
9871 name: "Peek-Shutdown",
9872 config: Config{
9873 Bugs: ProtocolBugs{
9874 ExpectCloseNotify: true,
9875 },
9876 },
9877 flags: []string{
9878 "-peek-then-read",
9879 "-check-close-notify",
9880 },
9881 })
9882
9883 // Test SSL_peek can discover an alert.
9884 testCases = append(testCases, testCase{
9885 name: "Peek-Alert",
9886 config: Config{
9887 Bugs: ProtocolBugs{
9888 SendSpuriousAlert: alertRecordOverflow,
9889 },
9890 },
9891 flags: []string{"-peek-then-read"},
9892 shouldFail: true,
9893 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9894 })
9895
9896 // Test SSL_peek can handle KeyUpdate.
9897 testCases = append(testCases, testCase{
9898 name: "Peek-KeyUpdate",
9899 config: Config{
9900 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009901 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009902 sendKeyUpdates: 1,
9903 keyUpdateRequest: keyUpdateNotRequested,
9904 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009905 })
9906}
9907
David Benjamine6f22212016-11-08 14:28:24 -05009908func addRecordVersionTests() {
9909 for _, ver := range tlsVersions {
9910 // Test that the record version is enforced.
9911 testCases = append(testCases, testCase{
9912 name: "CheckRecordVersion-" + ver.name,
9913 config: Config{
9914 MinVersion: ver.version,
9915 MaxVersion: ver.version,
9916 Bugs: ProtocolBugs{
9917 SendRecordVersion: 0x03ff,
9918 },
9919 },
9920 shouldFail: true,
9921 expectedError: ":WRONG_VERSION_NUMBER:",
9922 })
9923
9924 // Test that the ClientHello may use any record version, for
9925 // compatibility reasons.
9926 testCases = append(testCases, testCase{
9927 testType: serverTest,
9928 name: "LooseInitialRecordVersion-" + ver.name,
9929 config: Config{
9930 MinVersion: ver.version,
9931 MaxVersion: ver.version,
9932 Bugs: ProtocolBugs{
9933 SendInitialRecordVersion: 0x03ff,
9934 },
9935 },
9936 })
9937
9938 // Test that garbage ClientHello record versions are rejected.
9939 testCases = append(testCases, testCase{
9940 testType: serverTest,
9941 name: "GarbageInitialRecordVersion-" + ver.name,
9942 config: Config{
9943 MinVersion: ver.version,
9944 MaxVersion: ver.version,
9945 Bugs: ProtocolBugs{
9946 SendInitialRecordVersion: 0xffff,
9947 },
9948 },
9949 shouldFail: true,
9950 expectedError: ":WRONG_VERSION_NUMBER:",
9951 })
9952 }
9953}
9954
David Benjamin2c516452016-11-15 10:16:54 +09009955func addCertificateTests() {
9956 // Test that a certificate chain with intermediate may be sent and
9957 // received as both client and server.
9958 for _, ver := range tlsVersions {
9959 testCases = append(testCases, testCase{
9960 testType: clientTest,
9961 name: "SendReceiveIntermediate-Client-" + ver.name,
9962 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009963 MinVersion: ver.version,
9964 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009965 Certificates: []Certificate{rsaChainCertificate},
9966 ClientAuth: RequireAnyClientCert,
9967 },
9968 expectPeerCertificate: &rsaChainCertificate,
9969 flags: []string{
9970 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9971 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9972 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9973 },
9974 })
9975
9976 testCases = append(testCases, testCase{
9977 testType: serverTest,
9978 name: "SendReceiveIntermediate-Server-" + ver.name,
9979 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009980 MinVersion: ver.version,
9981 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009982 Certificates: []Certificate{rsaChainCertificate},
9983 },
9984 expectPeerCertificate: &rsaChainCertificate,
9985 flags: []string{
9986 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9987 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9988 "-require-any-client-certificate",
9989 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9990 },
9991 })
9992 }
9993}
9994
David Benjaminbbaf3672016-11-17 10:53:09 +09009995func addRetainOnlySHA256ClientCertTests() {
9996 for _, ver := range tlsVersions {
9997 // Test that enabling
9998 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9999 // actually requesting a client certificate is a no-op.
10000 testCases = append(testCases, testCase{
10001 testType: serverTest,
10002 name: "RetainOnlySHA256-NoCert-" + ver.name,
10003 config: Config{
10004 MinVersion: ver.version,
10005 MaxVersion: ver.version,
10006 },
10007 flags: []string{
10008 "-retain-only-sha256-client-cert-initial",
10009 "-retain-only-sha256-client-cert-resume",
10010 },
10011 resumeSession: true,
10012 })
10013
10014 // Test that when retaining only a SHA-256 certificate is
10015 // enabled, the hash appears as expected.
10016 testCases = append(testCases, testCase{
10017 testType: serverTest,
10018 name: "RetainOnlySHA256-Cert-" + ver.name,
10019 config: Config{
10020 MinVersion: ver.version,
10021 MaxVersion: ver.version,
10022 Certificates: []Certificate{rsaCertificate},
10023 },
10024 flags: []string{
10025 "-verify-peer",
10026 "-retain-only-sha256-client-cert-initial",
10027 "-retain-only-sha256-client-cert-resume",
10028 "-expect-sha256-client-cert-initial",
10029 "-expect-sha256-client-cert-resume",
10030 },
10031 resumeSession: true,
10032 })
10033
10034 // Test that when the config changes from on to off, a
10035 // resumption is rejected because the server now wants the full
10036 // certificate chain.
10037 testCases = append(testCases, testCase{
10038 testType: serverTest,
10039 name: "RetainOnlySHA256-OnOff-" + ver.name,
10040 config: Config{
10041 MinVersion: ver.version,
10042 MaxVersion: ver.version,
10043 Certificates: []Certificate{rsaCertificate},
10044 },
10045 flags: []string{
10046 "-verify-peer",
10047 "-retain-only-sha256-client-cert-initial",
10048 "-expect-sha256-client-cert-initial",
10049 },
10050 resumeSession: true,
10051 expectResumeRejected: true,
10052 })
10053
10054 // Test that when the config changes from off to on, a
10055 // resumption is rejected because the server now wants just the
10056 // hash.
10057 testCases = append(testCases, testCase{
10058 testType: serverTest,
10059 name: "RetainOnlySHA256-OffOn-" + ver.name,
10060 config: Config{
10061 MinVersion: ver.version,
10062 MaxVersion: ver.version,
10063 Certificates: []Certificate{rsaCertificate},
10064 },
10065 flags: []string{
10066 "-verify-peer",
10067 "-retain-only-sha256-client-cert-resume",
10068 "-expect-sha256-client-cert-resume",
10069 },
10070 resumeSession: true,
10071 expectResumeRejected: true,
10072 })
10073 }
10074}
10075
Adam Langleya4b91982016-12-12 12:05:53 -080010076func addECDSAKeyUsageTests() {
10077 p256 := elliptic.P256()
10078 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10079 if err != nil {
10080 panic(err)
10081 }
10082
10083 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10084 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10085 if err != nil {
10086 panic(err)
10087 }
10088
10089 template := x509.Certificate{
10090 SerialNumber: serialNumber,
10091 Subject: pkix.Name{
10092 Organization: []string{"Acme Co"},
10093 },
10094 NotBefore: time.Now(),
10095 NotAfter: time.Now(),
10096
10097 // An ECC certificate with only the keyAgreement key usgae may
10098 // be used with ECDH, but not ECDSA.
10099 KeyUsage: x509.KeyUsageKeyAgreement,
10100 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10101 BasicConstraintsValid: true,
10102 }
10103
10104 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10105 if err != nil {
10106 panic(err)
10107 }
10108
10109 cert := Certificate{
10110 Certificate: [][]byte{derBytes},
10111 PrivateKey: priv,
10112 }
10113
10114 for _, ver := range tlsVersions {
10115 if ver.version < VersionTLS12 {
10116 continue
10117 }
10118
10119 testCases = append(testCases, testCase{
10120 testType: clientTest,
10121 name: "ECDSAKeyUsage-" + ver.name,
10122 config: Config{
10123 MinVersion: ver.version,
10124 MaxVersion: ver.version,
10125 Certificates: []Certificate{cert},
10126 },
10127 shouldFail: true,
10128 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10129 })
10130 }
10131}
10132
David Benjamin6f600d62016-12-21 16:06:54 -050010133func addShortHeaderTests() {
10134 // The short header extension may be negotiated as either client or
10135 // server.
10136 testCases = append(testCases, testCase{
10137 name: "ShortHeader-Client",
10138 config: Config{
10139 MaxVersion: VersionTLS13,
10140 Bugs: ProtocolBugs{
10141 EnableShortHeader: true,
10142 },
10143 },
10144 flags: []string{"-enable-short-header"},
10145 expectShortHeader: true,
10146 })
10147 testCases = append(testCases, testCase{
10148 testType: serverTest,
10149 name: "ShortHeader-Server",
10150 config: Config{
10151 MaxVersion: VersionTLS13,
10152 Bugs: ProtocolBugs{
10153 EnableShortHeader: true,
10154 },
10155 },
10156 flags: []string{"-enable-short-header"},
10157 expectShortHeader: true,
10158 })
10159
10160 // If the peer doesn't support it, it will not be negotiated.
10161 testCases = append(testCases, testCase{
10162 name: "ShortHeader-No-Yes-Client",
10163 config: Config{
10164 MaxVersion: VersionTLS13,
10165 },
10166 flags: []string{"-enable-short-header"},
10167 })
10168 testCases = append(testCases, testCase{
10169 testType: serverTest,
10170 name: "ShortHeader-No-Yes-Server",
10171 config: Config{
10172 MaxVersion: VersionTLS13,
10173 },
10174 flags: []string{"-enable-short-header"},
10175 })
10176
10177 // If we don't support it, it will not be negotiated.
10178 testCases = append(testCases, testCase{
10179 name: "ShortHeader-Yes-No-Client",
10180 config: Config{
10181 MaxVersion: VersionTLS13,
10182 Bugs: ProtocolBugs{
10183 EnableShortHeader: true,
10184 },
10185 },
10186 })
10187 testCases = append(testCases, testCase{
10188 testType: serverTest,
10189 name: "ShortHeader-Yes-No-Server",
10190 config: Config{
10191 MaxVersion: VersionTLS13,
10192 Bugs: ProtocolBugs{
10193 EnableShortHeader: true,
10194 },
10195 },
10196 })
10197
10198 // It will not be negotiated at TLS 1.2.
10199 testCases = append(testCases, testCase{
10200 name: "ShortHeader-TLS12-Client",
10201 config: Config{
10202 MaxVersion: VersionTLS12,
10203 Bugs: ProtocolBugs{
10204 EnableShortHeader: true,
10205 },
10206 },
10207 flags: []string{"-enable-short-header"},
10208 })
10209 testCases = append(testCases, testCase{
10210 testType: serverTest,
10211 name: "ShortHeader-TLS12-Server",
10212 config: Config{
10213 MaxVersion: VersionTLS12,
10214 Bugs: ProtocolBugs{
10215 EnableShortHeader: true,
10216 },
10217 },
10218 flags: []string{"-enable-short-header"},
10219 })
10220
10221 // Servers reject early data and short header sent together.
10222 testCases = append(testCases, testCase{
10223 testType: serverTest,
10224 name: "ShortHeader-EarlyData",
10225 config: Config{
10226 MaxVersion: VersionTLS13,
10227 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010228 EnableShortHeader: true,
10229 SendFakeEarlyDataLength: 1,
David Benjamin6f600d62016-12-21 16:06:54 -050010230 },
10231 },
10232 flags: []string{"-enable-short-header"},
10233 shouldFail: true,
10234 expectedError: ":UNEXPECTED_EXTENSION:",
10235 })
10236
10237 // Clients reject unsolicited short header extensions.
10238 testCases = append(testCases, testCase{
10239 name: "ShortHeader-Unsolicited",
10240 config: Config{
10241 MaxVersion: VersionTLS13,
10242 Bugs: ProtocolBugs{
10243 AlwaysNegotiateShortHeader: true,
10244 },
10245 },
10246 shouldFail: true,
10247 expectedError: ":UNEXPECTED_EXTENSION:",
10248 })
10249 testCases = append(testCases, testCase{
10250 name: "ShortHeader-Unsolicited-TLS12",
10251 config: Config{
10252 MaxVersion: VersionTLS12,
10253 Bugs: ProtocolBugs{
10254 AlwaysNegotiateShortHeader: true,
10255 },
10256 },
10257 shouldFail: true,
10258 expectedError: ":UNEXPECTED_EXTENSION:",
10259 })
10260
10261 // The high bit must be checked in short headers.
10262 testCases = append(testCases, testCase{
10263 name: "ShortHeader-ClearShortHeaderBit",
10264 config: Config{
10265 Bugs: ProtocolBugs{
10266 EnableShortHeader: true,
10267 ClearShortHeaderBit: true,
10268 },
10269 },
10270 flags: []string{"-enable-short-header"},
10271 shouldFail: true,
10272 expectedError: ":DECODE_ERROR:",
10273 expectedLocalError: "remote error: error decoding message",
10274 })
10275}
10276
Adam Langley7c803a62015-06-15 15:35:05 -070010277func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010278 defer wg.Done()
10279
10280 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010281 var err error
10282
David Benjaminba28dfc2016-11-15 17:47:21 +090010283 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010284 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10285 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010286 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010287 if err != nil {
10288 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10289 }
10290 break
10291 }
10292 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010293 } else if *repeatUntilFailure {
10294 for err == nil {
10295 statusChan <- statusMsg{test: test, started: true}
10296 err = runTest(test, shimPath, -1)
10297 }
10298 } else {
10299 statusChan <- statusMsg{test: test, started: true}
10300 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010301 }
Adam Langley95c29f32014-06-20 12:00:00 -070010302 statusChan <- statusMsg{test: test, err: err}
10303 }
10304}
10305
10306type statusMsg struct {
10307 test *testCase
10308 started bool
10309 err error
10310}
10311
David Benjamin5f237bc2015-02-11 17:14:15 -050010312func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010313 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010314
David Benjamin5f237bc2015-02-11 17:14:15 -050010315 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010316 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010317 if !*pipe {
10318 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010319 var erase string
10320 for i := 0; i < lineLen; i++ {
10321 erase += "\b \b"
10322 }
10323 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010324 }
10325
Adam Langley95c29f32014-06-20 12:00:00 -070010326 if msg.started {
10327 started++
10328 } else {
10329 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010330
10331 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010332 if msg.err == errUnimplemented {
10333 if *pipe {
10334 // Print each test instead of a status line.
10335 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10336 }
10337 unimplemented++
10338 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10339 } else {
10340 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10341 failed++
10342 testOutput.addResult(msg.test.name, "FAIL")
10343 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010344 } else {
10345 if *pipe {
10346 // Print each test instead of a status line.
10347 fmt.Printf("PASSED (%s)\n", msg.test.name)
10348 }
10349 testOutput.addResult(msg.test.name, "PASS")
10350 }
Adam Langley95c29f32014-06-20 12:00:00 -070010351 }
10352
David Benjamin5f237bc2015-02-11 17:14:15 -050010353 if !*pipe {
10354 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010355 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010356 lineLen = len(line)
10357 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010358 }
Adam Langley95c29f32014-06-20 12:00:00 -070010359 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010360
10361 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010362}
10363
10364func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010365 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010366 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010367 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010368
Adam Langley7c803a62015-06-15 15:35:05 -070010369 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010370 addCipherSuiteTests()
10371 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010372 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010373 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010374 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010375 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010376 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010377 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010378 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010379 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010380 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010381 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010382 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010383 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010384 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010385 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010386 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010387 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010388 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010389 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010390 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010391 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010392 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010393 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010394 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010395 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010396 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010397 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010398 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010399 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010400 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010401 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010402 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010403 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010404
10405 var wg sync.WaitGroup
10406
Adam Langley7c803a62015-06-15 15:35:05 -070010407 statusChan := make(chan statusMsg, *numWorkers)
10408 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010409 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010410
EKRf71d7ed2016-08-06 13:25:12 -070010411 if len(*shimConfigFile) != 0 {
10412 encoded, err := ioutil.ReadFile(*shimConfigFile)
10413 if err != nil {
10414 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10415 os.Exit(1)
10416 }
10417
10418 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10419 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10420 os.Exit(1)
10421 }
10422 }
10423
David Benjamin025b3d32014-07-01 19:53:04 -040010424 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010425
Adam Langley7c803a62015-06-15 15:35:05 -070010426 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010427 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010428 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010429 }
10430
David Benjamin270f0a72016-03-17 14:41:36 -040010431 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010432 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010433 matched := true
10434 if len(*testToRun) != 0 {
10435 var err error
10436 matched, err = filepath.Match(*testToRun, testCases[i].name)
10437 if err != nil {
10438 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10439 os.Exit(1)
10440 }
10441 }
10442
EKRf71d7ed2016-08-06 13:25:12 -070010443 if !*includeDisabled {
10444 for pattern := range shimConfig.DisabledTests {
10445 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10446 if err != nil {
10447 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10448 os.Exit(1)
10449 }
10450
10451 if isDisabled {
10452 matched = false
10453 break
10454 }
10455 }
10456 }
10457
David Benjamin17e12922016-07-28 18:04:43 -040010458 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010459 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010460 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010461
10462 // Only run one test if repeating until failure.
10463 if *repeatUntilFailure {
10464 break
10465 }
Adam Langley95c29f32014-06-20 12:00:00 -070010466 }
10467 }
David Benjamin17e12922016-07-28 18:04:43 -040010468
David Benjamin270f0a72016-03-17 14:41:36 -040010469 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010470 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010471 os.Exit(1)
10472 }
Adam Langley95c29f32014-06-20 12:00:00 -070010473
10474 close(testChan)
10475 wg.Wait()
10476 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010477 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010478
10479 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010480
10481 if *jsonOutput != "" {
10482 if err := testOutput.writeTo(*jsonOutput); err != nil {
10483 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10484 }
10485 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010486
EKR842ae6c2016-07-27 09:22:05 +020010487 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10488 os.Exit(1)
10489 }
10490
10491 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010492 os.Exit(1)
10493 }
Adam Langley95c29f32014-06-20 12:00:00 -070010494}