blob: d6e984a0916408b312393d8ee4f07d6c5b3677df [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 Benjamin397c8e62016-07-08 14:14:36 -07006398 // Stray HelloRequests during the handshake are ignored 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 },
6407 })
6408 testCases = append(testCases, testCase{
6409 name: "StrayHelloRequest-Packed",
6410 config: Config{
6411 MaxVersion: VersionTLS12,
6412 Bugs: ProtocolBugs{
6413 PackHandshakeFlight: true,
6414 SendHelloRequestBeforeEveryHandshakeMessage: true,
6415 },
6416 },
6417 })
6418
David Benjamin12d2c482016-07-24 10:56:51 -04006419 // Test renegotiation works if HelloRequest and server Finished come in
6420 // the same record.
6421 testCases = append(testCases, testCase{
6422 name: "Renegotiate-Client-Packed",
6423 config: Config{
6424 MaxVersion: VersionTLS12,
6425 Bugs: ProtocolBugs{
6426 PackHandshakeFlight: true,
6427 PackHelloRequestWithFinished: true,
6428 },
6429 },
6430 renegotiate: 1,
6431 flags: []string{
6432 "-renegotiate-freely",
6433 "-expect-total-renegotiations", "1",
6434 },
6435 })
6436
David Benjamin397c8e62016-07-08 14:14:36 -07006437 // Renegotiation is forbidden in TLS 1.3.
6438 testCases = append(testCases, testCase{
6439 name: "Renegotiate-Client-TLS13",
6440 config: Config{
6441 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006442 Bugs: ProtocolBugs{
6443 SendHelloRequestBeforeEveryAppDataRecord: true,
6444 },
David Benjamin397c8e62016-07-08 14:14:36 -07006445 },
David Benjamin397c8e62016-07-08 14:14:36 -07006446 flags: []string{
6447 "-renegotiate-freely",
6448 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006449 shouldFail: true,
6450 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006451 })
6452
6453 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6454 testCases = append(testCases, testCase{
6455 name: "StrayHelloRequest-TLS13",
6456 config: Config{
6457 MaxVersion: VersionTLS13,
6458 Bugs: ProtocolBugs{
6459 SendHelloRequestBeforeEveryHandshakeMessage: true,
6460 },
6461 },
6462 shouldFail: true,
6463 expectedError: ":UNEXPECTED_MESSAGE:",
6464 })
David Benjamind2610042017-01-03 10:49:28 -05006465
6466 // The renegotiation_info extension is not sent in TLS 1.3, but TLS 1.3
6467 // always reads as supporting it, regardless of whether it was
6468 // negotiated.
6469 testCases = append(testCases, testCase{
6470 name: "AlwaysReportRenegotiationInfo-TLS13",
6471 config: Config{
6472 MaxVersion: VersionTLS13,
6473 Bugs: ProtocolBugs{
6474 NoRenegotiationInfo: true,
6475 },
6476 },
6477 flags: []string{
6478 "-expect-secure-renegotiation",
6479 },
6480 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006481}
6482
David Benjamin5e961c12014-11-07 01:48:35 -05006483func addDTLSReplayTests() {
6484 // Test that sequence number replays are detected.
6485 testCases = append(testCases, testCase{
6486 protocol: dtls,
6487 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006488 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006489 replayWrites: true,
6490 })
6491
David Benjamin8e6db492015-07-25 18:29:23 -04006492 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006493 // than the retransmit window.
6494 testCases = append(testCases, testCase{
6495 protocol: dtls,
6496 name: "DTLS-Replay-LargeGaps",
6497 config: Config{
6498 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006499 SequenceNumberMapping: func(in uint64) uint64 {
6500 return in * 127
6501 },
David Benjamin5e961c12014-11-07 01:48:35 -05006502 },
6503 },
David Benjamin8e6db492015-07-25 18:29:23 -04006504 messageCount: 200,
6505 replayWrites: true,
6506 })
6507
6508 // Test the incoming sequence number changing non-monotonically.
6509 testCases = append(testCases, testCase{
6510 protocol: dtls,
6511 name: "DTLS-Replay-NonMonotonic",
6512 config: Config{
6513 Bugs: ProtocolBugs{
6514 SequenceNumberMapping: func(in uint64) uint64 {
6515 return in ^ 31
6516 },
6517 },
6518 },
6519 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006520 replayWrites: true,
6521 })
6522}
6523
Nick Harper60edffd2016-06-21 15:19:24 -07006524var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006525 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006526 id signatureAlgorithm
6527 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006528}{
Nick Harper60edffd2016-06-21 15:19:24 -07006529 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6530 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6531 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6532 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006533 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006534 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6535 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6536 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006537 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6538 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6539 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006540 // Tests for key types prior to TLS 1.2.
6541 {"RSA", 0, testCertRSA},
6542 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006543}
6544
Nick Harper60edffd2016-06-21 15:19:24 -07006545const fakeSigAlg1 signatureAlgorithm = 0x2a01
6546const fakeSigAlg2 signatureAlgorithm = 0xff01
6547
6548func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006549 // Not all ciphers involve a signature. Advertise a list which gives all
6550 // versions a signing cipher.
6551 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006552 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006553 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6554 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6555 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6556 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6557 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6558 }
6559
David Benjaminca3d5452016-07-14 12:51:01 -04006560 var allAlgorithms []signatureAlgorithm
6561 for _, alg := range testSignatureAlgorithms {
6562 if alg.id != 0 {
6563 allAlgorithms = append(allAlgorithms, alg.id)
6564 }
6565 }
6566
Nick Harper60edffd2016-06-21 15:19:24 -07006567 // Make sure each signature algorithm works. Include some fake values in
6568 // the list and ensure they're ignored.
6569 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006570 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006571 if (ver.version < VersionTLS12) != (alg.id == 0) {
6572 continue
6573 }
6574
6575 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6576 // or remove it in C.
6577 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006578 continue
6579 }
Nick Harper60edffd2016-06-21 15:19:24 -07006580
David Benjamin3ef76972016-10-17 17:59:54 -04006581 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006582 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006583 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006584 shouldSignFail = true
6585 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006586 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006587 // RSA-PKCS1 does not exist in TLS 1.3.
6588 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006589 shouldSignFail = true
6590 shouldVerifyFail = true
6591 }
6592
6593 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6594 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6595 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006596 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006597
6598 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006599 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006600 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006601 }
6602 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006603 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006604 }
David Benjamin000800a2014-11-14 01:43:59 -05006605
David Benjamin1fb125c2016-07-08 18:52:12 -07006606 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006607
David Benjamin7a41d372016-07-09 11:21:54 -07006608 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006609 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006610 config: Config{
6611 MaxVersion: ver.version,
6612 ClientAuth: RequireAnyClientCert,
6613 VerifySignatureAlgorithms: []signatureAlgorithm{
6614 fakeSigAlg1,
6615 alg.id,
6616 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006617 },
David Benjamin7a41d372016-07-09 11:21:54 -07006618 },
6619 flags: []string{
6620 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6621 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6622 "-enable-all-curves",
6623 },
David Benjamin3ef76972016-10-17 17:59:54 -04006624 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006625 expectedError: signError,
6626 expectedPeerSignatureAlgorithm: alg.id,
6627 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006628
David Benjamin7a41d372016-07-09 11:21:54 -07006629 testCases = append(testCases, testCase{
6630 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006631 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006632 config: Config{
6633 MaxVersion: ver.version,
6634 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6635 SignSignatureAlgorithms: []signatureAlgorithm{
6636 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006637 },
David Benjamin7a41d372016-07-09 11:21:54 -07006638 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006639 SkipECDSACurveCheck: shouldVerifyFail,
6640 IgnoreSignatureVersionChecks: shouldVerifyFail,
6641 // Some signature algorithms may not be advertised.
6642 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006643 },
David Benjamin7a41d372016-07-09 11:21:54 -07006644 },
6645 flags: []string{
6646 "-require-any-client-certificate",
6647 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6648 "-enable-all-curves",
6649 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006650 // Resume the session to assert the peer signature
6651 // algorithm is reported on both handshakes.
6652 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006653 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006654 expectedError: verifyError,
6655 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006656
6657 testCases = append(testCases, testCase{
6658 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006659 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006660 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006661 MaxVersion: ver.version,
6662 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006663 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006664 fakeSigAlg1,
6665 alg.id,
6666 fakeSigAlg2,
6667 },
6668 },
6669 flags: []string{
6670 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6671 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6672 "-enable-all-curves",
6673 },
David Benjamin3ef76972016-10-17 17:59:54 -04006674 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006675 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006676 expectedPeerSignatureAlgorithm: alg.id,
6677 })
6678
6679 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006680 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006681 config: Config{
6682 MaxVersion: ver.version,
6683 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006684 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006685 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006686 alg.id,
6687 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006688 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006689 SkipECDSACurveCheck: shouldVerifyFail,
6690 IgnoreSignatureVersionChecks: shouldVerifyFail,
6691 // Some signature algorithms may not be advertised.
6692 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006693 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006694 },
6695 flags: []string{
6696 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6697 "-enable-all-curves",
6698 },
David Benjaminf1050fd2016-12-13 20:05:36 -05006699 // Resume the session to assert the peer signature
6700 // algorithm is reported on both handshakes.
6701 resumeSession: !shouldVerifyFail,
David Benjamin3ef76972016-10-17 17:59:54 -04006702 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006703 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006704 })
David Benjamin5208fd42016-07-13 21:43:25 -04006705
David Benjamin3ef76972016-10-17 17:59:54 -04006706 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006707 testCases = append(testCases, testCase{
6708 testType: serverTest,
6709 name: "ClientAuth-InvalidSignature" + suffix,
6710 config: Config{
6711 MaxVersion: ver.version,
6712 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6713 SignSignatureAlgorithms: []signatureAlgorithm{
6714 alg.id,
6715 },
6716 Bugs: ProtocolBugs{
6717 InvalidSignature: true,
6718 },
6719 },
6720 flags: []string{
6721 "-require-any-client-certificate",
6722 "-enable-all-curves",
6723 },
6724 shouldFail: true,
6725 expectedError: ":BAD_SIGNATURE:",
6726 })
6727
6728 testCases = append(testCases, testCase{
6729 name: "ServerAuth-InvalidSignature" + suffix,
6730 config: Config{
6731 MaxVersion: ver.version,
6732 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6733 CipherSuites: signingCiphers,
6734 SignSignatureAlgorithms: []signatureAlgorithm{
6735 alg.id,
6736 },
6737 Bugs: ProtocolBugs{
6738 InvalidSignature: true,
6739 },
6740 },
6741 flags: []string{"-enable-all-curves"},
6742 shouldFail: true,
6743 expectedError: ":BAD_SIGNATURE:",
6744 })
6745 }
David Benjaminca3d5452016-07-14 12:51:01 -04006746
David Benjamin3ef76972016-10-17 17:59:54 -04006747 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006748 testCases = append(testCases, testCase{
6749 name: "ClientAuth-Sign-Negotiate" + suffix,
6750 config: Config{
6751 MaxVersion: ver.version,
6752 ClientAuth: RequireAnyClientCert,
6753 VerifySignatureAlgorithms: allAlgorithms,
6754 },
6755 flags: []string{
6756 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6757 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6758 "-enable-all-curves",
6759 "-signing-prefs", strconv.Itoa(int(alg.id)),
6760 },
6761 expectedPeerSignatureAlgorithm: alg.id,
6762 })
6763
6764 testCases = append(testCases, testCase{
6765 testType: serverTest,
6766 name: "ServerAuth-Sign-Negotiate" + suffix,
6767 config: Config{
6768 MaxVersion: ver.version,
6769 CipherSuites: signingCiphers,
6770 VerifySignatureAlgorithms: allAlgorithms,
6771 },
6772 flags: []string{
6773 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6774 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6775 "-enable-all-curves",
6776 "-signing-prefs", strconv.Itoa(int(alg.id)),
6777 },
6778 expectedPeerSignatureAlgorithm: alg.id,
6779 })
6780 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006781 }
David Benjamin000800a2014-11-14 01:43:59 -05006782 }
6783
Nick Harper60edffd2016-06-21 15:19:24 -07006784 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006785 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006786 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006787 config: Config{
6788 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006789 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006790 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006791 signatureECDSAWithP521AndSHA512,
6792 signatureRSAPKCS1WithSHA384,
6793 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006794 },
6795 },
6796 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006797 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6798 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006799 },
Nick Harper60edffd2016-06-21 15:19:24 -07006800 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006801 })
6802
6803 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006804 name: "ClientAuth-SignatureType-TLS13",
6805 config: Config{
6806 ClientAuth: RequireAnyClientCert,
6807 MaxVersion: VersionTLS13,
6808 VerifySignatureAlgorithms: []signatureAlgorithm{
6809 signatureECDSAWithP521AndSHA512,
6810 signatureRSAPKCS1WithSHA384,
6811 signatureRSAPSSWithSHA384,
6812 signatureECDSAWithSHA1,
6813 },
6814 },
6815 flags: []string{
6816 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6817 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6818 },
6819 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6820 })
6821
6822 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006823 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006824 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006825 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006826 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006827 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006828 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006829 signatureECDSAWithP521AndSHA512,
6830 signatureRSAPKCS1WithSHA384,
6831 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006832 },
6833 },
Nick Harper60edffd2016-06-21 15:19:24 -07006834 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006835 })
6836
Steven Valdez143e8b32016-07-11 13:19:03 -04006837 testCases = append(testCases, testCase{
6838 testType: serverTest,
6839 name: "ServerAuth-SignatureType-TLS13",
6840 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006841 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006842 VerifySignatureAlgorithms: []signatureAlgorithm{
6843 signatureECDSAWithP521AndSHA512,
6844 signatureRSAPKCS1WithSHA384,
6845 signatureRSAPSSWithSHA384,
6846 signatureECDSAWithSHA1,
6847 },
6848 },
6849 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6850 })
6851
David Benjamina95e9f32016-07-08 16:28:04 -07006852 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006853 testCases = append(testCases, testCase{
6854 testType: serverTest,
6855 name: "Verify-ClientAuth-SignatureType",
6856 config: Config{
6857 MaxVersion: VersionTLS12,
6858 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006859 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006860 signatureRSAPKCS1WithSHA256,
6861 },
6862 Bugs: ProtocolBugs{
6863 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6864 },
6865 },
6866 flags: []string{
6867 "-require-any-client-certificate",
6868 },
6869 shouldFail: true,
6870 expectedError: ":WRONG_SIGNATURE_TYPE:",
6871 })
6872
6873 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006874 testType: serverTest,
6875 name: "Verify-ClientAuth-SignatureType-TLS13",
6876 config: Config{
6877 MaxVersion: VersionTLS13,
6878 Certificates: []Certificate{rsaCertificate},
6879 SignSignatureAlgorithms: []signatureAlgorithm{
6880 signatureRSAPSSWithSHA256,
6881 },
6882 Bugs: ProtocolBugs{
6883 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6884 },
6885 },
6886 flags: []string{
6887 "-require-any-client-certificate",
6888 },
6889 shouldFail: true,
6890 expectedError: ":WRONG_SIGNATURE_TYPE:",
6891 })
6892
6893 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006894 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006895 config: Config{
6896 MaxVersion: VersionTLS12,
6897 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006898 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006899 signatureRSAPKCS1WithSHA256,
6900 },
6901 Bugs: ProtocolBugs{
6902 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6903 },
6904 },
6905 shouldFail: true,
6906 expectedError: ":WRONG_SIGNATURE_TYPE:",
6907 })
6908
Steven Valdez143e8b32016-07-11 13:19:03 -04006909 testCases = append(testCases, testCase{
6910 name: "Verify-ServerAuth-SignatureType-TLS13",
6911 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006912 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006913 SignSignatureAlgorithms: []signatureAlgorithm{
6914 signatureRSAPSSWithSHA256,
6915 },
6916 Bugs: ProtocolBugs{
6917 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6918 },
6919 },
6920 shouldFail: true,
6921 expectedError: ":WRONG_SIGNATURE_TYPE:",
6922 })
6923
David Benjamin51dd7d62016-07-08 16:07:01 -07006924 // Test that, if the list is missing, the peer falls back to SHA-1 in
6925 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006926 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006927 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006928 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006929 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006930 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006931 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006932 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006933 },
6934 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006935 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006936 },
6937 },
6938 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006939 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6940 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006941 },
6942 })
6943
6944 testCases = append(testCases, testCase{
6945 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006946 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006947 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006948 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006949 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006950 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006951 },
6952 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006953 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006954 },
6955 },
David Benjaminee32bea2016-08-17 13:36:44 -04006956 flags: []string{
6957 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6958 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6959 },
6960 })
6961
6962 testCases = append(testCases, testCase{
6963 name: "ClientAuth-SHA1-Fallback-ECDSA",
6964 config: Config{
6965 MaxVersion: VersionTLS12,
6966 ClientAuth: RequireAnyClientCert,
6967 VerifySignatureAlgorithms: []signatureAlgorithm{
6968 signatureECDSAWithSHA1,
6969 },
6970 Bugs: ProtocolBugs{
6971 NoSignatureAlgorithms: true,
6972 },
6973 },
6974 flags: []string{
6975 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6976 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6977 },
6978 })
6979
6980 testCases = append(testCases, testCase{
6981 testType: serverTest,
6982 name: "ServerAuth-SHA1-Fallback-ECDSA",
6983 config: Config{
6984 MaxVersion: VersionTLS12,
6985 VerifySignatureAlgorithms: []signatureAlgorithm{
6986 signatureECDSAWithSHA1,
6987 },
6988 Bugs: ProtocolBugs{
6989 NoSignatureAlgorithms: true,
6990 },
6991 },
6992 flags: []string{
6993 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6994 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6995 },
David Benjamin000800a2014-11-14 01:43:59 -05006996 })
David Benjamin72dc7832015-03-16 17:49:43 -04006997
David Benjamin51dd7d62016-07-08 16:07:01 -07006998 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006999 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007000 config: Config{
7001 MaxVersion: VersionTLS13,
7002 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007003 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007004 signatureRSAPKCS1WithSHA1,
7005 },
7006 Bugs: ProtocolBugs{
7007 NoSignatureAlgorithms: true,
7008 },
7009 },
7010 flags: []string{
7011 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7012 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7013 },
David Benjamin48901652016-08-01 12:12:47 -04007014 shouldFail: true,
7015 // An empty CertificateRequest signature algorithm list is a
7016 // syntax error in TLS 1.3.
7017 expectedError: ":DECODE_ERROR:",
7018 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07007019 })
7020
7021 testCases = append(testCases, testCase{
7022 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007023 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07007024 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007025 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007026 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07007027 signatureRSAPKCS1WithSHA1,
7028 },
7029 Bugs: ProtocolBugs{
7030 NoSignatureAlgorithms: true,
7031 },
7032 },
7033 shouldFail: true,
7034 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7035 })
7036
David Benjaminb62d2872016-07-18 14:55:02 +02007037 // Test that hash preferences are enforced. BoringSSL does not implement
7038 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04007039 testCases = append(testCases, testCase{
7040 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04007041 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007042 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007043 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007044 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007045 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007046 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007047 },
7048 Bugs: ProtocolBugs{
7049 IgnorePeerSignatureAlgorithmPreferences: true,
7050 },
7051 },
7052 flags: []string{"-require-any-client-certificate"},
7053 shouldFail: true,
7054 expectedError: ":WRONG_SIGNATURE_TYPE:",
7055 })
7056
7057 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04007058 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04007059 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007060 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04007061 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07007062 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007063 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04007064 },
7065 Bugs: ProtocolBugs{
7066 IgnorePeerSignatureAlgorithmPreferences: true,
7067 },
7068 },
7069 shouldFail: true,
7070 expectedError: ":WRONG_SIGNATURE_TYPE:",
7071 })
David Benjaminb62d2872016-07-18 14:55:02 +02007072 testCases = append(testCases, testCase{
7073 testType: serverTest,
7074 name: "ClientAuth-Enforced-TLS13",
7075 config: Config{
7076 MaxVersion: VersionTLS13,
7077 Certificates: []Certificate{rsaCertificate},
7078 SignSignatureAlgorithms: []signatureAlgorithm{
7079 signatureRSAPKCS1WithMD5,
7080 },
7081 Bugs: ProtocolBugs{
7082 IgnorePeerSignatureAlgorithmPreferences: true,
7083 IgnoreSignatureVersionChecks: true,
7084 },
7085 },
7086 flags: []string{"-require-any-client-certificate"},
7087 shouldFail: true,
7088 expectedError: ":WRONG_SIGNATURE_TYPE:",
7089 })
7090
7091 testCases = append(testCases, testCase{
7092 name: "ServerAuth-Enforced-TLS13",
7093 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007094 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02007095 SignSignatureAlgorithms: []signatureAlgorithm{
7096 signatureRSAPKCS1WithMD5,
7097 },
7098 Bugs: ProtocolBugs{
7099 IgnorePeerSignatureAlgorithmPreferences: true,
7100 IgnoreSignatureVersionChecks: true,
7101 },
7102 },
7103 shouldFail: true,
7104 expectedError: ":WRONG_SIGNATURE_TYPE:",
7105 })
Steven Valdez0d62f262015-09-04 12:41:04 -04007106
7107 // Test that the agreed upon digest respects the client preferences and
7108 // the server digests.
7109 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04007110 name: "NoCommonAlgorithms-Digests",
7111 config: Config{
7112 MaxVersion: VersionTLS12,
7113 ClientAuth: RequireAnyClientCert,
7114 VerifySignatureAlgorithms: []signatureAlgorithm{
7115 signatureRSAPKCS1WithSHA512,
7116 signatureRSAPKCS1WithSHA1,
7117 },
7118 },
7119 flags: []string{
7120 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7121 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7122 "-digest-prefs", "SHA256",
7123 },
7124 shouldFail: true,
7125 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7126 })
7127 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07007128 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04007129 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007130 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007131 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007132 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007133 signatureRSAPKCS1WithSHA512,
7134 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007135 },
7136 },
7137 flags: []string{
7138 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7139 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007140 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04007141 },
David Benjaminca3d5452016-07-14 12:51:01 -04007142 shouldFail: true,
7143 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7144 })
7145 testCases = append(testCases, testCase{
7146 name: "NoCommonAlgorithms-TLS13",
7147 config: Config{
7148 MaxVersion: VersionTLS13,
7149 ClientAuth: RequireAnyClientCert,
7150 VerifySignatureAlgorithms: []signatureAlgorithm{
7151 signatureRSAPSSWithSHA512,
7152 signatureRSAPSSWithSHA384,
7153 },
7154 },
7155 flags: []string{
7156 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7157 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7158 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
7159 },
David Benjaminea9a0d52016-07-08 15:52:59 -07007160 shouldFail: true,
7161 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04007162 })
7163 testCases = append(testCases, testCase{
7164 name: "Agree-Digest-SHA256",
7165 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007166 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007167 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007168 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007169 signatureRSAPKCS1WithSHA1,
7170 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007171 },
7172 },
7173 flags: []string{
7174 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7175 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007176 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007177 },
Nick Harper60edffd2016-06-21 15:19:24 -07007178 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007179 })
7180 testCases = append(testCases, testCase{
7181 name: "Agree-Digest-SHA1",
7182 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007183 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007184 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007185 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007186 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007187 },
7188 },
7189 flags: []string{
7190 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7191 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04007192 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04007193 },
Nick Harper60edffd2016-06-21 15:19:24 -07007194 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007195 })
7196 testCases = append(testCases, testCase{
7197 name: "Agree-Digest-Default",
7198 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007199 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04007200 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07007201 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07007202 signatureRSAPKCS1WithSHA256,
7203 signatureECDSAWithP256AndSHA256,
7204 signatureRSAPKCS1WithSHA1,
7205 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04007206 },
7207 },
7208 flags: []string{
7209 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7210 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7211 },
Nick Harper60edffd2016-06-21 15:19:24 -07007212 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04007213 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007214
David Benjaminca3d5452016-07-14 12:51:01 -04007215 // Test that the signing preference list may include extra algorithms
7216 // without negotiation problems.
7217 testCases = append(testCases, testCase{
7218 testType: serverTest,
7219 name: "FilterExtraAlgorithms",
7220 config: Config{
7221 MaxVersion: VersionTLS12,
7222 VerifySignatureAlgorithms: []signatureAlgorithm{
7223 signatureRSAPKCS1WithSHA256,
7224 },
7225 },
7226 flags: []string{
7227 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
7228 "-key-file", path.Join(*resourceDir, rsaKeyFile),
7229 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
7230 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
7231 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
7232 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7233 },
7234 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7235 })
7236
David Benjamin4c3ddf72016-06-29 18:13:53 -04007237 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7238 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007239 testCases = append(testCases, testCase{
7240 name: "CheckLeafCurve",
7241 config: Config{
7242 MaxVersion: VersionTLS12,
7243 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007244 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007245 },
7246 flags: []string{"-p384-only"},
7247 shouldFail: true,
7248 expectedError: ":BAD_ECC_CERT:",
7249 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007250
7251 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7252 testCases = append(testCases, testCase{
7253 name: "CheckLeafCurve-TLS13",
7254 config: Config{
7255 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007256 Certificates: []Certificate{ecdsaP256Certificate},
7257 },
7258 flags: []string{"-p384-only"},
7259 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007260
7261 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7262 testCases = append(testCases, testCase{
7263 name: "ECDSACurveMismatch-Verify-TLS12",
7264 config: Config{
7265 MaxVersion: VersionTLS12,
7266 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7267 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007268 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007269 signatureECDSAWithP384AndSHA384,
7270 },
7271 },
7272 })
7273
7274 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7275 testCases = append(testCases, testCase{
7276 name: "ECDSACurveMismatch-Verify-TLS13",
7277 config: Config{
7278 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007279 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007280 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007281 signatureECDSAWithP384AndSHA384,
7282 },
7283 Bugs: ProtocolBugs{
7284 SkipECDSACurveCheck: true,
7285 },
7286 },
7287 shouldFail: true,
7288 expectedError: ":WRONG_SIGNATURE_TYPE:",
7289 })
7290
7291 // Signature algorithm selection in TLS 1.3 should take the curve into
7292 // account.
7293 testCases = append(testCases, testCase{
7294 testType: serverTest,
7295 name: "ECDSACurveMismatch-Sign-TLS13",
7296 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007297 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007298 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007299 signatureECDSAWithP384AndSHA384,
7300 signatureECDSAWithP256AndSHA256,
7301 },
7302 },
7303 flags: []string{
7304 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7305 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7306 },
7307 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7308 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007309
7310 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7311 // server does not attempt to sign in that case.
7312 testCases = append(testCases, testCase{
7313 testType: serverTest,
7314 name: "RSA-PSS-Large",
7315 config: Config{
7316 MaxVersion: VersionTLS13,
7317 VerifySignatureAlgorithms: []signatureAlgorithm{
7318 signatureRSAPSSWithSHA512,
7319 },
7320 },
7321 flags: []string{
7322 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7323 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7324 },
7325 shouldFail: true,
7326 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7327 })
David Benjamin57e929f2016-08-30 00:30:38 -04007328
7329 // Test that RSA-PSS is enabled by default for TLS 1.2.
7330 testCases = append(testCases, testCase{
7331 testType: clientTest,
7332 name: "RSA-PSS-Default-Verify",
7333 config: Config{
7334 MaxVersion: VersionTLS12,
7335 SignSignatureAlgorithms: []signatureAlgorithm{
7336 signatureRSAPSSWithSHA256,
7337 },
7338 },
7339 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7340 })
7341
7342 testCases = append(testCases, testCase{
7343 testType: serverTest,
7344 name: "RSA-PSS-Default-Sign",
7345 config: Config{
7346 MaxVersion: VersionTLS12,
7347 VerifySignatureAlgorithms: []signatureAlgorithm{
7348 signatureRSAPSSWithSHA256,
7349 },
7350 },
7351 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7352 })
David Benjamin000800a2014-11-14 01:43:59 -05007353}
7354
David Benjamin83f90402015-01-27 01:09:43 -05007355// timeouts is the retransmit schedule for BoringSSL. It doubles and
7356// caps at 60 seconds. On the 13th timeout, it gives up.
7357var timeouts = []time.Duration{
7358 1 * time.Second,
7359 2 * time.Second,
7360 4 * time.Second,
7361 8 * time.Second,
7362 16 * time.Second,
7363 32 * time.Second,
7364 60 * time.Second,
7365 60 * time.Second,
7366 60 * time.Second,
7367 60 * time.Second,
7368 60 * time.Second,
7369 60 * time.Second,
7370 60 * time.Second,
7371}
7372
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007373// shortTimeouts is an alternate set of timeouts which would occur if the
7374// initial timeout duration was set to 250ms.
7375var shortTimeouts = []time.Duration{
7376 250 * time.Millisecond,
7377 500 * time.Millisecond,
7378 1 * time.Second,
7379 2 * time.Second,
7380 4 * time.Second,
7381 8 * time.Second,
7382 16 * time.Second,
7383 32 * time.Second,
7384 60 * time.Second,
7385 60 * time.Second,
7386 60 * time.Second,
7387 60 * time.Second,
7388 60 * time.Second,
7389}
7390
David Benjamin83f90402015-01-27 01:09:43 -05007391func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007392 // These tests work by coordinating some behavior on both the shim and
7393 // the runner.
7394 //
7395 // TimeoutSchedule configures the runner to send a series of timeout
7396 // opcodes to the shim (see packetAdaptor) immediately before reading
7397 // each peer handshake flight N. The timeout opcode both simulates a
7398 // timeout in the shim and acts as a synchronization point to help the
7399 // runner bracket each handshake flight.
7400 //
7401 // We assume the shim does not read from the channel eagerly. It must
7402 // first wait until it has sent flight N and is ready to receive
7403 // handshake flight N+1. At this point, it will process the timeout
7404 // opcode. It must then immediately respond with a timeout ACK and act
7405 // as if the shim was idle for the specified amount of time.
7406 //
7407 // The runner then drops all packets received before the ACK and
7408 // continues waiting for flight N. This ordering results in one attempt
7409 // at sending flight N to be dropped. For the test to complete, the
7410 // shim must send flight N again, testing that the shim implements DTLS
7411 // retransmit on a timeout.
7412
Steven Valdez143e8b32016-07-11 13:19:03 -04007413 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007414 // likely be more epochs to cross and the final message's retransmit may
7415 // be more complex.
7416
David Benjamin585d7a42016-06-02 14:58:00 -04007417 for _, async := range []bool{true, false} {
7418 var tests []testCase
7419
7420 // Test that this is indeed the timeout schedule. Stress all
7421 // four patterns of handshake.
7422 for i := 1; i < len(timeouts); i++ {
7423 number := strconv.Itoa(i)
7424 tests = append(tests, testCase{
7425 protocol: dtls,
7426 name: "DTLS-Retransmit-Client-" + number,
7427 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007428 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007429 Bugs: ProtocolBugs{
7430 TimeoutSchedule: timeouts[:i],
7431 },
7432 },
7433 resumeSession: true,
7434 })
7435 tests = append(tests, testCase{
7436 protocol: dtls,
7437 testType: serverTest,
7438 name: "DTLS-Retransmit-Server-" + number,
7439 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007440 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007441 Bugs: ProtocolBugs{
7442 TimeoutSchedule: timeouts[:i],
7443 },
7444 },
7445 resumeSession: true,
7446 })
7447 }
7448
7449 // Test that exceeding the timeout schedule hits a read
7450 // timeout.
7451 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007452 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007453 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007454 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007455 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007456 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007457 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007458 },
7459 },
7460 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007461 shouldFail: true,
7462 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007463 })
David Benjamin585d7a42016-06-02 14:58:00 -04007464
7465 if async {
7466 // Test that timeout handling has a fudge factor, due to API
7467 // problems.
7468 tests = append(tests, testCase{
7469 protocol: dtls,
7470 name: "DTLS-Retransmit-Fudge",
7471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007472 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007473 Bugs: ProtocolBugs{
7474 TimeoutSchedule: []time.Duration{
7475 timeouts[0] - 10*time.Millisecond,
7476 },
7477 },
7478 },
7479 resumeSession: true,
7480 })
7481 }
7482
7483 // Test that the final Finished retransmitting isn't
7484 // duplicated if the peer badly fragments everything.
7485 tests = append(tests, testCase{
7486 testType: serverTest,
7487 protocol: dtls,
7488 name: "DTLS-Retransmit-Fragmented",
7489 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007490 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007491 Bugs: ProtocolBugs{
7492 TimeoutSchedule: []time.Duration{timeouts[0]},
7493 MaxHandshakeRecordLength: 2,
7494 },
7495 },
7496 })
7497
7498 // Test the timeout schedule when a shorter initial timeout duration is set.
7499 tests = append(tests, testCase{
7500 protocol: dtls,
7501 name: "DTLS-Retransmit-Short-Client",
7502 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007503 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007504 Bugs: ProtocolBugs{
7505 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7506 },
7507 },
7508 resumeSession: true,
7509 flags: []string{"-initial-timeout-duration-ms", "250"},
7510 })
7511 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007512 protocol: dtls,
7513 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007514 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007516 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007517 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007518 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007519 },
7520 },
7521 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007522 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007523 })
David Benjamin585d7a42016-06-02 14:58:00 -04007524
7525 for _, test := range tests {
7526 if async {
7527 test.name += "-Async"
7528 test.flags = append(test.flags, "-async")
7529 }
7530
7531 testCases = append(testCases, test)
7532 }
David Benjamin83f90402015-01-27 01:09:43 -05007533 }
David Benjamin83f90402015-01-27 01:09:43 -05007534}
7535
David Benjaminc565ebb2015-04-03 04:06:36 -04007536func addExportKeyingMaterialTests() {
7537 for _, vers := range tlsVersions {
7538 if vers.version == VersionSSL30 {
7539 continue
7540 }
7541 testCases = append(testCases, testCase{
7542 name: "ExportKeyingMaterial-" + vers.name,
7543 config: Config{
7544 MaxVersion: vers.version,
7545 },
7546 exportKeyingMaterial: 1024,
7547 exportLabel: "label",
7548 exportContext: "context",
7549 useExportContext: true,
7550 })
7551 testCases = append(testCases, testCase{
7552 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7553 config: Config{
7554 MaxVersion: vers.version,
7555 },
7556 exportKeyingMaterial: 1024,
7557 })
7558 testCases = append(testCases, testCase{
7559 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7560 config: Config{
7561 MaxVersion: vers.version,
7562 },
7563 exportKeyingMaterial: 1024,
7564 useExportContext: true,
7565 })
7566 testCases = append(testCases, testCase{
7567 name: "ExportKeyingMaterial-Small-" + vers.name,
7568 config: Config{
7569 MaxVersion: vers.version,
7570 },
7571 exportKeyingMaterial: 1,
7572 exportLabel: "label",
7573 exportContext: "context",
7574 useExportContext: true,
7575 })
7576 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007577
David Benjaminc565ebb2015-04-03 04:06:36 -04007578 testCases = append(testCases, testCase{
7579 name: "ExportKeyingMaterial-SSL3",
7580 config: Config{
7581 MaxVersion: VersionSSL30,
7582 },
7583 exportKeyingMaterial: 1024,
7584 exportLabel: "label",
7585 exportContext: "context",
7586 useExportContext: true,
7587 shouldFail: true,
7588 expectedError: "failed to export keying material",
7589 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007590
7591 // Exporters work during a False Start.
7592 testCases = append(testCases, testCase{
7593 name: "ExportKeyingMaterial-FalseStart",
7594 config: Config{
7595 MaxVersion: VersionTLS12,
7596 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7597 NextProtos: []string{"foo"},
7598 Bugs: ProtocolBugs{
7599 ExpectFalseStart: true,
7600 },
7601 },
7602 flags: []string{
7603 "-false-start",
7604 "-advertise-alpn", "\x03foo",
7605 },
7606 shimWritesFirst: true,
7607 exportKeyingMaterial: 1024,
7608 exportLabel: "label",
7609 exportContext: "context",
7610 useExportContext: true,
7611 })
7612
7613 // Exporters do not work in the middle of a renegotiation. Test this by
7614 // triggering the exporter after every SSL_read call and configuring the
7615 // shim to run asynchronously.
7616 testCases = append(testCases, testCase{
7617 name: "ExportKeyingMaterial-Renegotiate",
7618 config: Config{
7619 MaxVersion: VersionTLS12,
7620 },
7621 renegotiate: 1,
7622 flags: []string{
7623 "-async",
7624 "-use-exporter-between-reads",
7625 "-renegotiate-freely",
7626 "-expect-total-renegotiations", "1",
7627 },
7628 shouldFail: true,
7629 expectedError: "failed to export keying material",
7630 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007631}
7632
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007633func addTLSUniqueTests() {
7634 for _, isClient := range []bool{false, true} {
7635 for _, isResumption := range []bool{false, true} {
7636 for _, hasEMS := range []bool{false, true} {
7637 var suffix string
7638 if isResumption {
7639 suffix = "Resume-"
7640 } else {
7641 suffix = "Full-"
7642 }
7643
7644 if hasEMS {
7645 suffix += "EMS-"
7646 } else {
7647 suffix += "NoEMS-"
7648 }
7649
7650 if isClient {
7651 suffix += "Client"
7652 } else {
7653 suffix += "Server"
7654 }
7655
7656 test := testCase{
7657 name: "TLSUnique-" + suffix,
7658 testTLSUnique: true,
7659 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007660 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007661 Bugs: ProtocolBugs{
7662 NoExtendedMasterSecret: !hasEMS,
7663 },
7664 },
7665 }
7666
7667 if isResumption {
7668 test.resumeSession = true
7669 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007670 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007671 Bugs: ProtocolBugs{
7672 NoExtendedMasterSecret: !hasEMS,
7673 },
7674 }
7675 }
7676
7677 if isResumption && !hasEMS {
7678 test.shouldFail = true
7679 test.expectedError = "failed to get tls-unique"
7680 }
7681
7682 testCases = append(testCases, test)
7683 }
7684 }
7685 }
7686}
7687
Adam Langley09505632015-07-30 18:10:13 -07007688func addCustomExtensionTests() {
7689 expectedContents := "custom extension"
7690 emptyString := ""
7691
7692 for _, isClient := range []bool{false, true} {
7693 suffix := "Server"
7694 flag := "-enable-server-custom-extension"
7695 testType := serverTest
7696 if isClient {
7697 suffix = "Client"
7698 flag = "-enable-client-custom-extension"
7699 testType = clientTest
7700 }
7701
7702 testCases = append(testCases, testCase{
7703 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007704 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007705 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007706 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007707 Bugs: ProtocolBugs{
7708 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007709 ExpectedCustomExtension: &expectedContents,
7710 },
7711 },
7712 flags: []string{flag},
7713 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007714 testCases = append(testCases, testCase{
7715 testType: testType,
7716 name: "CustomExtensions-" + suffix + "-TLS13",
7717 config: Config{
7718 MaxVersion: VersionTLS13,
7719 Bugs: ProtocolBugs{
7720 CustomExtension: expectedContents,
7721 ExpectedCustomExtension: &expectedContents,
7722 },
7723 },
7724 flags: []string{flag},
7725 })
Adam Langley09505632015-07-30 18:10:13 -07007726
7727 // If the parse callback fails, the handshake should also fail.
7728 testCases = append(testCases, testCase{
7729 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007730 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007731 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007732 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007733 Bugs: ProtocolBugs{
7734 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007735 ExpectedCustomExtension: &expectedContents,
7736 },
7737 },
David Benjamin399e7c92015-07-30 23:01:27 -04007738 flags: []string{flag},
7739 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007740 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7741 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007742 testCases = append(testCases, testCase{
7743 testType: testType,
7744 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7745 config: Config{
7746 MaxVersion: VersionTLS13,
7747 Bugs: ProtocolBugs{
7748 CustomExtension: expectedContents + "foo",
7749 ExpectedCustomExtension: &expectedContents,
7750 },
7751 },
7752 flags: []string{flag},
7753 shouldFail: true,
7754 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7755 })
Adam Langley09505632015-07-30 18:10:13 -07007756
7757 // If the add callback fails, the handshake should also fail.
7758 testCases = append(testCases, testCase{
7759 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007760 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007761 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007762 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007763 Bugs: ProtocolBugs{
7764 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007765 ExpectedCustomExtension: &expectedContents,
7766 },
7767 },
David Benjamin399e7c92015-07-30 23:01:27 -04007768 flags: []string{flag, "-custom-extension-fail-add"},
7769 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007770 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7771 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007772 testCases = append(testCases, testCase{
7773 testType: testType,
7774 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7775 config: Config{
7776 MaxVersion: VersionTLS13,
7777 Bugs: ProtocolBugs{
7778 CustomExtension: expectedContents,
7779 ExpectedCustomExtension: &expectedContents,
7780 },
7781 },
7782 flags: []string{flag, "-custom-extension-fail-add"},
7783 shouldFail: true,
7784 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7785 })
Adam Langley09505632015-07-30 18:10:13 -07007786
7787 // If the add callback returns zero, no extension should be
7788 // added.
7789 skipCustomExtension := expectedContents
7790 if isClient {
7791 // For the case where the client skips sending the
7792 // custom extension, the server must not “echo” it.
7793 skipCustomExtension = ""
7794 }
7795 testCases = append(testCases, testCase{
7796 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007797 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007798 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007799 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007800 Bugs: ProtocolBugs{
7801 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007802 ExpectedCustomExtension: &emptyString,
7803 },
7804 },
7805 flags: []string{flag, "-custom-extension-skip"},
7806 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007807 testCases = append(testCases, testCase{
7808 testType: testType,
7809 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7810 config: Config{
7811 MaxVersion: VersionTLS13,
7812 Bugs: ProtocolBugs{
7813 CustomExtension: skipCustomExtension,
7814 ExpectedCustomExtension: &emptyString,
7815 },
7816 },
7817 flags: []string{flag, "-custom-extension-skip"},
7818 })
Adam Langley09505632015-07-30 18:10:13 -07007819 }
7820
7821 // The custom extension add callback should not be called if the client
7822 // doesn't send the extension.
7823 testCases = append(testCases, testCase{
7824 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007825 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007827 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007828 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007829 ExpectedCustomExtension: &emptyString,
7830 },
7831 },
7832 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7833 })
Adam Langley2deb9842015-08-07 11:15:37 -07007834
Steven Valdez143e8b32016-07-11 13:19:03 -04007835 testCases = append(testCases, testCase{
7836 testType: serverTest,
7837 name: "CustomExtensions-NotCalled-Server-TLS13",
7838 config: Config{
7839 MaxVersion: VersionTLS13,
7840 Bugs: ProtocolBugs{
7841 ExpectedCustomExtension: &emptyString,
7842 },
7843 },
7844 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7845 })
7846
Adam Langley2deb9842015-08-07 11:15:37 -07007847 // Test an unknown extension from the server.
7848 testCases = append(testCases, testCase{
7849 testType: clientTest,
7850 name: "UnknownExtension-Client",
7851 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007852 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007853 Bugs: ProtocolBugs{
7854 CustomExtension: expectedContents,
7855 },
7856 },
David Benjamin0c40a962016-08-01 12:05:50 -04007857 shouldFail: true,
7858 expectedError: ":UNEXPECTED_EXTENSION:",
7859 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007860 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007861 testCases = append(testCases, testCase{
7862 testType: clientTest,
7863 name: "UnknownExtension-Client-TLS13",
7864 config: Config{
7865 MaxVersion: VersionTLS13,
7866 Bugs: ProtocolBugs{
7867 CustomExtension: expectedContents,
7868 },
7869 },
David Benjamin0c40a962016-08-01 12:05:50 -04007870 shouldFail: true,
7871 expectedError: ":UNEXPECTED_EXTENSION:",
7872 expectedLocalError: "remote error: unsupported extension",
7873 })
David Benjamin490469f2016-10-05 22:44:38 -04007874 testCases = append(testCases, testCase{
7875 testType: clientTest,
7876 name: "UnknownUnencryptedExtension-Client-TLS13",
7877 config: Config{
7878 MaxVersion: VersionTLS13,
7879 Bugs: ProtocolBugs{
7880 CustomUnencryptedExtension: expectedContents,
7881 },
7882 },
7883 shouldFail: true,
7884 expectedError: ":UNEXPECTED_EXTENSION:",
7885 // The shim must send an alert, but alerts at this point do not
7886 // get successfully decrypted by the runner.
7887 expectedLocalError: "local error: bad record MAC",
7888 })
7889 testCases = append(testCases, testCase{
7890 testType: clientTest,
7891 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7892 config: Config{
7893 MaxVersion: VersionTLS13,
7894 Bugs: ProtocolBugs{
7895 SendUnencryptedALPN: "foo",
7896 },
7897 },
7898 flags: []string{
7899 "-advertise-alpn", "\x03foo\x03bar",
7900 },
7901 shouldFail: true,
7902 expectedError: ":UNEXPECTED_EXTENSION:",
7903 // The shim must send an alert, but alerts at this point do not
7904 // get successfully decrypted by the runner.
7905 expectedLocalError: "local error: bad record MAC",
7906 })
David Benjamin0c40a962016-08-01 12:05:50 -04007907
7908 // Test a known but unoffered extension from the server.
7909 testCases = append(testCases, testCase{
7910 testType: clientTest,
7911 name: "UnofferedExtension-Client",
7912 config: Config{
7913 MaxVersion: VersionTLS12,
7914 Bugs: ProtocolBugs{
7915 SendALPN: "alpn",
7916 },
7917 },
7918 shouldFail: true,
7919 expectedError: ":UNEXPECTED_EXTENSION:",
7920 expectedLocalError: "remote error: unsupported extension",
7921 })
7922 testCases = append(testCases, testCase{
7923 testType: clientTest,
7924 name: "UnofferedExtension-Client-TLS13",
7925 config: Config{
7926 MaxVersion: VersionTLS13,
7927 Bugs: ProtocolBugs{
7928 SendALPN: "alpn",
7929 },
7930 },
7931 shouldFail: true,
7932 expectedError: ":UNEXPECTED_EXTENSION:",
7933 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007934 })
Adam Langley09505632015-07-30 18:10:13 -07007935}
7936
David Benjaminb36a3952015-12-01 18:53:13 -05007937func addRSAClientKeyExchangeTests() {
7938 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7939 testCases = append(testCases, testCase{
7940 testType: serverTest,
7941 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7942 config: Config{
7943 // Ensure the ClientHello version and final
7944 // version are different, to detect if the
7945 // server uses the wrong one.
7946 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007947 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007948 Bugs: ProtocolBugs{
7949 BadRSAClientKeyExchange: bad,
7950 },
7951 },
7952 shouldFail: true,
7953 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7954 })
7955 }
David Benjamine63d9d72016-09-19 18:27:34 -04007956
7957 // The server must compare whatever was in ClientHello.version for the
7958 // RSA premaster.
7959 testCases = append(testCases, testCase{
7960 testType: serverTest,
7961 name: "SendClientVersion-RSA",
7962 config: Config{
7963 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7964 Bugs: ProtocolBugs{
7965 SendClientVersion: 0x1234,
7966 },
7967 },
7968 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7969 })
David Benjaminb36a3952015-12-01 18:53:13 -05007970}
7971
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007972var testCurves = []struct {
7973 name string
7974 id CurveID
7975}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007976 {"P-256", CurveP256},
7977 {"P-384", CurveP384},
7978 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007979 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007980}
7981
Steven Valdez5440fe02016-07-18 12:40:30 -04007982const bogusCurve = 0x1234
7983
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007984func addCurveTests() {
7985 for _, curve := range testCurves {
7986 testCases = append(testCases, testCase{
7987 name: "CurveTest-Client-" + curve.name,
7988 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007989 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007990 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7991 CurvePreferences: []CurveID{curve.id},
7992 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007993 flags: []string{
7994 "-enable-all-curves",
7995 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7996 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007997 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007998 })
7999 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008000 name: "CurveTest-Client-" + curve.name + "-TLS13",
8001 config: Config{
8002 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008003 CurvePreferences: []CurveID{curve.id},
8004 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008005 flags: []string{
8006 "-enable-all-curves",
8007 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8008 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008009 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008010 })
8011 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008012 testType: serverTest,
8013 name: "CurveTest-Server-" + curve.name,
8014 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008015 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008016 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8017 CurvePreferences: []CurveID{curve.id},
8018 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008019 flags: []string{
8020 "-enable-all-curves",
8021 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8022 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008023 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008024 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008025 testCases = append(testCases, testCase{
8026 testType: serverTest,
8027 name: "CurveTest-Server-" + curve.name + "-TLS13",
8028 config: Config{
8029 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008030 CurvePreferences: []CurveID{curve.id},
8031 },
David Benjamin5c4e8572016-08-19 17:44:53 -04008032 flags: []string{
8033 "-enable-all-curves",
8034 "-expect-curve-id", strconv.Itoa(int(curve.id)),
8035 },
Steven Valdez5440fe02016-07-18 12:40:30 -04008036 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04008037 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008038 }
David Benjamin241ae832016-01-15 03:04:54 -05008039
8040 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05008041 testCases = append(testCases, testCase{
8042 testType: serverTest,
8043 name: "UnknownCurve",
8044 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008045 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05008046 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8047 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8048 },
8049 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008050
Steven Valdez803c77a2016-09-06 14:13:43 -04008051 // The server must be tolerant to bogus curves.
8052 testCases = append(testCases, testCase{
8053 testType: serverTest,
8054 name: "UnknownCurve-TLS13",
8055 config: Config{
8056 MaxVersion: VersionTLS13,
8057 CurvePreferences: []CurveID{bogusCurve, CurveP256},
8058 },
8059 })
8060
David Benjamin4c3ddf72016-06-29 18:13:53 -04008061 // The server must not consider ECDHE ciphers when there are no
8062 // supported curves.
8063 testCases = append(testCases, testCase{
8064 testType: serverTest,
8065 name: "NoSupportedCurves",
8066 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008067 MaxVersion: VersionTLS12,
8068 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8069 Bugs: ProtocolBugs{
8070 NoSupportedCurves: true,
8071 },
8072 },
8073 shouldFail: true,
8074 expectedError: ":NO_SHARED_CIPHER:",
8075 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008076 testCases = append(testCases, testCase{
8077 testType: serverTest,
8078 name: "NoSupportedCurves-TLS13",
8079 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008080 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008081 Bugs: ProtocolBugs{
8082 NoSupportedCurves: true,
8083 },
8084 },
8085 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008086 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008087 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008088
8089 // The server must fall back to another cipher when there are no
8090 // supported curves.
8091 testCases = append(testCases, testCase{
8092 testType: serverTest,
8093 name: "NoCommonCurves",
8094 config: Config{
8095 MaxVersion: VersionTLS12,
8096 CipherSuites: []uint16{
8097 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
8098 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8099 },
8100 CurvePreferences: []CurveID{CurveP224},
8101 },
8102 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
8103 })
8104
8105 // The client must reject bogus curves and disabled curves.
8106 testCases = append(testCases, testCase{
8107 name: "BadECDHECurve",
8108 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008109 MaxVersion: VersionTLS12,
8110 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8111 Bugs: ProtocolBugs{
8112 SendCurve: bogusCurve,
8113 },
8114 },
8115 shouldFail: true,
8116 expectedError: ":WRONG_CURVE:",
8117 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008118 testCases = append(testCases, testCase{
8119 name: "BadECDHECurve-TLS13",
8120 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008121 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008122 Bugs: ProtocolBugs{
8123 SendCurve: bogusCurve,
8124 },
8125 },
8126 shouldFail: true,
8127 expectedError: ":WRONG_CURVE:",
8128 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04008129
8130 testCases = append(testCases, testCase{
8131 name: "UnsupportedCurve",
8132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008133 MaxVersion: VersionTLS12,
8134 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8135 CurvePreferences: []CurveID{CurveP256},
8136 Bugs: ProtocolBugs{
8137 IgnorePeerCurvePreferences: true,
8138 },
8139 },
8140 flags: []string{"-p384-only"},
8141 shouldFail: true,
8142 expectedError: ":WRONG_CURVE:",
8143 })
8144
David Benjamin4f921572016-07-17 14:20:10 +02008145 testCases = append(testCases, testCase{
8146 // TODO(davidben): Add a TLS 1.3 version where
8147 // HelloRetryRequest requests an unsupported curve.
8148 name: "UnsupportedCurve-ServerHello-TLS13",
8149 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04008150 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02008151 CurvePreferences: []CurveID{CurveP384},
8152 Bugs: ProtocolBugs{
8153 SendCurve: CurveP256,
8154 },
8155 },
8156 flags: []string{"-p384-only"},
8157 shouldFail: true,
8158 expectedError: ":WRONG_CURVE:",
8159 })
8160
David Benjamin4c3ddf72016-06-29 18:13:53 -04008161 // Test invalid curve points.
8162 testCases = append(testCases, testCase{
8163 name: "InvalidECDHPoint-Client",
8164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008165 MaxVersion: VersionTLS12,
8166 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8167 CurvePreferences: []CurveID{CurveP256},
8168 Bugs: ProtocolBugs{
8169 InvalidECDHPoint: true,
8170 },
8171 },
8172 shouldFail: true,
8173 expectedError: ":INVALID_ENCODING:",
8174 })
8175 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008176 name: "InvalidECDHPoint-Client-TLS13",
8177 config: Config{
8178 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008179 CurvePreferences: []CurveID{CurveP256},
8180 Bugs: ProtocolBugs{
8181 InvalidECDHPoint: true,
8182 },
8183 },
8184 shouldFail: true,
8185 expectedError: ":INVALID_ENCODING:",
8186 })
8187 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008188 testType: serverTest,
8189 name: "InvalidECDHPoint-Server",
8190 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04008191 MaxVersion: VersionTLS12,
8192 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8193 CurvePreferences: []CurveID{CurveP256},
8194 Bugs: ProtocolBugs{
8195 InvalidECDHPoint: true,
8196 },
8197 },
8198 shouldFail: true,
8199 expectedError: ":INVALID_ENCODING:",
8200 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008201 testCases = append(testCases, testCase{
8202 testType: serverTest,
8203 name: "InvalidECDHPoint-Server-TLS13",
8204 config: Config{
8205 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04008206 CurvePreferences: []CurveID{CurveP256},
8207 Bugs: ProtocolBugs{
8208 InvalidECDHPoint: true,
8209 },
8210 },
8211 shouldFail: true,
8212 expectedError: ":INVALID_ENCODING:",
8213 })
David Benjamin8a55ce42016-12-11 03:03:42 -05008214
8215 // The previous curve ID should be reported on TLS 1.2 resumption.
8216 testCases = append(testCases, testCase{
8217 name: "CurveID-Resume-Client",
8218 config: Config{
8219 MaxVersion: VersionTLS12,
8220 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8221 CurvePreferences: []CurveID{CurveX25519},
8222 },
8223 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8224 resumeSession: true,
8225 })
8226 testCases = append(testCases, testCase{
8227 testType: serverTest,
8228 name: "CurveID-Resume-Server",
8229 config: Config{
8230 MaxVersion: VersionTLS12,
8231 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
8232 CurvePreferences: []CurveID{CurveX25519},
8233 },
8234 flags: []string{"-expect-curve-id", strconv.Itoa(int(CurveX25519))},
8235 resumeSession: true,
8236 })
8237
8238 // TLS 1.3 allows resuming at a differet curve. If this happens, the new
8239 // one should be reported.
8240 testCases = append(testCases, testCase{
8241 name: "CurveID-Resume-Client-TLS13",
8242 config: Config{
8243 MaxVersion: VersionTLS13,
8244 CurvePreferences: []CurveID{CurveX25519},
8245 },
8246 resumeConfig: &Config{
8247 MaxVersion: VersionTLS13,
8248 CurvePreferences: []CurveID{CurveP256},
8249 },
8250 flags: []string{
8251 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8252 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8253 },
8254 resumeSession: true,
8255 })
8256 testCases = append(testCases, testCase{
8257 testType: serverTest,
8258 name: "CurveID-Resume-Server-TLS13",
8259 config: Config{
8260 MaxVersion: VersionTLS13,
8261 CurvePreferences: []CurveID{CurveX25519},
8262 },
8263 resumeConfig: &Config{
8264 MaxVersion: VersionTLS13,
8265 CurvePreferences: []CurveID{CurveP256},
8266 },
8267 flags: []string{
8268 "-expect-curve-id", strconv.Itoa(int(CurveX25519)),
8269 "-expect-resume-curve-id", strconv.Itoa(int(CurveP256)),
8270 },
8271 resumeSession: true,
8272 })
David Benjamina81967b2016-12-22 09:16:57 -05008273
8274 // Server-sent point formats are legal in TLS 1.2, but not in TLS 1.3.
8275 testCases = append(testCases, testCase{
8276 name: "PointFormat-ServerHello-TLS12",
8277 config: Config{
8278 MaxVersion: VersionTLS12,
8279 Bugs: ProtocolBugs{
8280 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8281 },
8282 },
8283 })
8284 testCases = append(testCases, testCase{
8285 name: "PointFormat-EncryptedExtensions-TLS13",
8286 config: Config{
8287 MaxVersion: VersionTLS13,
8288 Bugs: ProtocolBugs{
8289 SendSupportedPointFormats: []byte{pointFormatUncompressed},
8290 },
8291 },
8292 shouldFail: true,
8293 expectedError: ":ERROR_PARSING_EXTENSION:",
8294 })
8295
8296 // Test that we tolerate unknown point formats, as long as
8297 // pointFormatUncompressed is present. Limit ciphers to ECDHE ciphers to
8298 // check they are still functional.
8299 testCases = append(testCases, testCase{
8300 name: "PointFormat-Client-Tolerance",
8301 config: Config{
8302 MaxVersion: VersionTLS12,
8303 Bugs: ProtocolBugs{
8304 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8305 },
8306 },
8307 })
8308 testCases = append(testCases, testCase{
8309 testType: serverTest,
8310 name: "PointFormat-Server-Tolerance",
8311 config: Config{
8312 MaxVersion: VersionTLS12,
8313 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8314 Bugs: ProtocolBugs{
8315 SendSupportedPointFormats: []byte{42, pointFormatUncompressed, 99, pointFormatCompressedPrime},
8316 },
8317 },
8318 })
8319
8320 // Test TLS 1.2 does not require the point format extension to be
8321 // present.
8322 testCases = append(testCases, testCase{
8323 name: "PointFormat-Client-Missing",
8324 config: Config{
8325 MaxVersion: VersionTLS12,
8326 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8327 Bugs: ProtocolBugs{
8328 SendSupportedPointFormats: []byte{},
8329 },
8330 },
8331 })
8332 testCases = append(testCases, testCase{
8333 testType: serverTest,
8334 name: "PointFormat-Server-Missing",
8335 config: Config{
8336 MaxVersion: VersionTLS12,
8337 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
8338 Bugs: ProtocolBugs{
8339 SendSupportedPointFormats: []byte{},
8340 },
8341 },
8342 })
8343
8344 // If the point format extension is present, uncompressed points must be
8345 // offered. BoringSSL requires this whether or not ECDHE is used.
8346 testCases = append(testCases, testCase{
8347 name: "PointFormat-Client-MissingUncompressed",
8348 config: Config{
8349 MaxVersion: VersionTLS12,
8350 Bugs: ProtocolBugs{
8351 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8352 },
8353 },
8354 shouldFail: true,
8355 expectedError: ":ERROR_PARSING_EXTENSION:",
8356 })
8357 testCases = append(testCases, testCase{
8358 testType: serverTest,
8359 name: "PointFormat-Server-MissingUncompressed",
8360 config: Config{
8361 MaxVersion: VersionTLS12,
8362 Bugs: ProtocolBugs{
8363 SendSupportedPointFormats: []byte{pointFormatCompressedPrime},
8364 },
8365 },
8366 shouldFail: true,
8367 expectedError: ":ERROR_PARSING_EXTENSION:",
8368 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008369}
8370
David Benjaminc9ae27c2016-06-24 22:56:37 -04008371func addTLS13RecordTests() {
8372 testCases = append(testCases, testCase{
8373 name: "TLS13-RecordPadding",
8374 config: Config{
8375 MaxVersion: VersionTLS13,
8376 MinVersion: VersionTLS13,
8377 Bugs: ProtocolBugs{
8378 RecordPadding: 10,
8379 },
8380 },
8381 })
8382
8383 testCases = append(testCases, testCase{
8384 name: "TLS13-EmptyRecords",
8385 config: Config{
8386 MaxVersion: VersionTLS13,
8387 MinVersion: VersionTLS13,
8388 Bugs: ProtocolBugs{
8389 OmitRecordContents: true,
8390 },
8391 },
8392 shouldFail: true,
8393 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8394 })
8395
8396 testCases = append(testCases, testCase{
8397 name: "TLS13-OnlyPadding",
8398 config: Config{
8399 MaxVersion: VersionTLS13,
8400 MinVersion: VersionTLS13,
8401 Bugs: ProtocolBugs{
8402 OmitRecordContents: true,
8403 RecordPadding: 10,
8404 },
8405 },
8406 shouldFail: true,
8407 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8408 })
8409
8410 testCases = append(testCases, testCase{
8411 name: "TLS13-WrongOuterRecord",
8412 config: Config{
8413 MaxVersion: VersionTLS13,
8414 MinVersion: VersionTLS13,
8415 Bugs: ProtocolBugs{
8416 OuterRecordType: recordTypeHandshake,
8417 },
8418 },
8419 shouldFail: true,
8420 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8421 })
8422}
8423
Steven Valdez5b986082016-09-01 12:29:49 -04008424func addSessionTicketTests() {
8425 testCases = append(testCases, testCase{
8426 // In TLS 1.2 and below, empty NewSessionTicket messages
8427 // mean the server changed its mind on sending a ticket.
8428 name: "SendEmptySessionTicket",
8429 config: Config{
8430 MaxVersion: VersionTLS12,
8431 Bugs: ProtocolBugs{
8432 SendEmptySessionTicket: true,
8433 },
8434 },
8435 flags: []string{"-expect-no-session"},
8436 })
8437
8438 // Test that the server ignores unknown PSK modes.
8439 testCases = append(testCases, testCase{
8440 testType: serverTest,
8441 name: "TLS13-SendUnknownModeSessionTicket-Server",
8442 config: Config{
8443 MaxVersion: VersionTLS13,
8444 Bugs: ProtocolBugs{
8445 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008446 },
8447 },
8448 resumeSession: true,
8449 expectedResumeVersion: VersionTLS13,
8450 })
8451
Steven Valdeza833c352016-11-01 13:39:36 -04008452 // Test that the server does not send session tickets with no matching key exchange mode.
8453 testCases = append(testCases, testCase{
8454 testType: serverTest,
8455 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8456 config: Config{
8457 MaxVersion: VersionTLS13,
8458 Bugs: ProtocolBugs{
8459 SendPSKKeyExchangeModes: []byte{0x1a},
8460 ExpectNoNewSessionTicket: true,
8461 },
8462 },
8463 })
8464
8465 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008466 testCases = append(testCases, testCase{
8467 testType: serverTest,
8468 name: "TLS13-SendBadKEModeSessionTicket-Server",
8469 config: Config{
8470 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008471 },
8472 resumeConfig: &Config{
8473 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008474 Bugs: ProtocolBugs{
8475 SendPSKKeyExchangeModes: []byte{0x1a},
8476 },
8477 },
8478 resumeSession: true,
8479 expectResumeRejected: true,
8480 })
8481
Steven Valdeza833c352016-11-01 13:39:36 -04008482 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008483 testCases = append(testCases, testCase{
8484 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008485 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008486 config: Config{
8487 MaxVersion: VersionTLS13,
8488 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008489 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008490 },
8491 },
Steven Valdeza833c352016-11-01 13:39:36 -04008492 resumeSession: true,
8493 flags: []string{
8494 "-resumption-delay", "10",
8495 },
Steven Valdez5b986082016-09-01 12:29:49 -04008496 })
8497
Steven Valdeza833c352016-11-01 13:39:36 -04008498 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008499 testCases = append(testCases, testCase{
8500 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008501 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008502 config: Config{
8503 MaxVersion: VersionTLS13,
8504 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008505 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008506 },
8507 },
Steven Valdeza833c352016-11-01 13:39:36 -04008508 resumeSession: true,
8509 shouldFail: true,
8510 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008511 })
8512
Steven Valdez08b65f42016-12-07 15:29:45 -05008513 testCases = append(testCases, testCase{
8514 testType: clientTest,
8515 name: "TLS13-SendTicketEarlyDataInfo",
8516 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008517 MaxVersion: VersionTLS13,
8518 MaxEarlyDataSize: 16384,
Steven Valdez08b65f42016-12-07 15:29:45 -05008519 },
8520 flags: []string{
David Benjamin9b160662017-01-25 19:53:43 -05008521 "-enable-early-data",
Steven Valdez08b65f42016-12-07 15:29:45 -05008522 "-expect-early-data-info",
8523 },
8524 })
8525
David Benjamin9b160662017-01-25 19:53:43 -05008526 // Test that 0-RTT tickets are ignored in clients unless opted in.
8527 testCases = append(testCases, testCase{
8528 testType: clientTest,
8529 name: "TLS13-SendTicketEarlyDataInfo-Disabled",
8530 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008531 MaxVersion: VersionTLS13,
8532 MaxEarlyDataSize: 16384,
David Benjamin9b160662017-01-25 19:53:43 -05008533 },
8534 })
8535
Steven Valdez08b65f42016-12-07 15:29:45 -05008536 testCases = append(testCases, testCase{
David Benjamin9c33ae82017-01-08 06:04:43 -05008537 testType: clientTest,
8538 name: "TLS13-DuplicateTicketEarlyDataInfo",
8539 config: Config{
Nick Harperab20cec2016-12-19 17:38:41 -08008540 MaxVersion: VersionTLS13,
8541 MaxEarlyDataSize: 16384,
David Benjamin9c33ae82017-01-08 06:04:43 -05008542 Bugs: ProtocolBugs{
David Benjamin9c33ae82017-01-08 06:04:43 -05008543 DuplicateTicketEarlyDataInfo: true,
8544 },
8545 },
8546 shouldFail: true,
8547 expectedError: ":DUPLICATE_EXTENSION:",
8548 expectedLocalError: "remote error: illegal parameter",
8549 })
8550
8551 testCases = append(testCases, testCase{
Steven Valdez08b65f42016-12-07 15:29:45 -05008552 testType: serverTest,
8553 name: "TLS13-ExpectTicketEarlyDataInfo",
8554 config: Config{
8555 MaxVersion: VersionTLS13,
8556 Bugs: ProtocolBugs{
8557 ExpectTicketEarlyDataInfo: true,
8558 },
8559 },
8560 flags: []string{
8561 "-enable-early-data",
8562 },
8563 })
David Benjamin17b30832017-01-28 14:00:32 -05008564
8565 // Test that, in TLS 1.3, the server-offered NewSessionTicket lifetime
8566 // is honored.
8567 testCases = append(testCases, testCase{
8568 testType: clientTest,
8569 name: "TLS13-HonorServerSessionTicketLifetime",
8570 config: Config{
8571 MaxVersion: VersionTLS13,
8572 Bugs: ProtocolBugs{
8573 SendTicketLifetime: 20 * time.Second,
8574 },
8575 },
8576 flags: []string{
8577 "-resumption-delay", "19",
8578 },
8579 resumeSession: true,
8580 })
8581 testCases = append(testCases, testCase{
8582 testType: clientTest,
8583 name: "TLS13-HonorServerSessionTicketLifetime-2",
8584 config: Config{
8585 MaxVersion: VersionTLS13,
8586 Bugs: ProtocolBugs{
8587 SendTicketLifetime: 20 * time.Second,
8588 // The client should not offer the expired session.
8589 ExpectNoTLS13PSK: true,
8590 },
8591 },
8592 flags: []string{
8593 "-resumption-delay", "21",
8594 },
David Benjamin023d4192017-02-06 13:49:07 -05008595 resumeSession: true,
David Benjamin17b30832017-01-28 14:00:32 -05008596 expectResumeRejected: true,
8597 })
Steven Valdez5b986082016-09-01 12:29:49 -04008598}
8599
David Benjamin82261be2016-07-07 14:32:50 -07008600func addChangeCipherSpecTests() {
8601 // Test missing ChangeCipherSpecs.
8602 testCases = append(testCases, testCase{
8603 name: "SkipChangeCipherSpec-Client",
8604 config: Config{
8605 MaxVersion: VersionTLS12,
8606 Bugs: ProtocolBugs{
8607 SkipChangeCipherSpec: true,
8608 },
8609 },
8610 shouldFail: true,
8611 expectedError: ":UNEXPECTED_RECORD:",
8612 })
8613 testCases = append(testCases, testCase{
8614 testType: serverTest,
8615 name: "SkipChangeCipherSpec-Server",
8616 config: Config{
8617 MaxVersion: VersionTLS12,
8618 Bugs: ProtocolBugs{
8619 SkipChangeCipherSpec: true,
8620 },
8621 },
8622 shouldFail: true,
8623 expectedError: ":UNEXPECTED_RECORD:",
8624 })
8625 testCases = append(testCases, testCase{
8626 testType: serverTest,
8627 name: "SkipChangeCipherSpec-Server-NPN",
8628 config: Config{
8629 MaxVersion: VersionTLS12,
8630 NextProtos: []string{"bar"},
8631 Bugs: ProtocolBugs{
8632 SkipChangeCipherSpec: true,
8633 },
8634 },
8635 flags: []string{
8636 "-advertise-npn", "\x03foo\x03bar\x03baz",
8637 },
8638 shouldFail: true,
8639 expectedError: ":UNEXPECTED_RECORD:",
8640 })
8641
8642 // Test synchronization between the handshake and ChangeCipherSpec.
8643 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8644 // rejected. Test both with and without handshake packing to handle both
8645 // when the partial post-CCS message is in its own record and when it is
8646 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008647 for _, packed := range []bool{false, true} {
8648 var suffix string
8649 if packed {
8650 suffix = "-Packed"
8651 }
8652
8653 testCases = append(testCases, testCase{
8654 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8655 config: Config{
8656 MaxVersion: VersionTLS12,
8657 Bugs: ProtocolBugs{
8658 FragmentAcrossChangeCipherSpec: true,
8659 PackHandshakeFlight: packed,
8660 },
8661 },
8662 shouldFail: true,
8663 expectedError: ":UNEXPECTED_RECORD:",
8664 })
8665 testCases = append(testCases, testCase{
8666 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8667 config: Config{
8668 MaxVersion: VersionTLS12,
8669 },
8670 resumeSession: true,
8671 resumeConfig: &Config{
8672 MaxVersion: VersionTLS12,
8673 Bugs: ProtocolBugs{
8674 FragmentAcrossChangeCipherSpec: true,
8675 PackHandshakeFlight: packed,
8676 },
8677 },
8678 shouldFail: true,
8679 expectedError: ":UNEXPECTED_RECORD:",
8680 })
8681 testCases = append(testCases, testCase{
8682 testType: serverTest,
8683 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8684 config: Config{
8685 MaxVersion: VersionTLS12,
8686 Bugs: ProtocolBugs{
8687 FragmentAcrossChangeCipherSpec: true,
8688 PackHandshakeFlight: packed,
8689 },
8690 },
8691 shouldFail: true,
8692 expectedError: ":UNEXPECTED_RECORD:",
8693 })
8694 testCases = append(testCases, testCase{
8695 testType: serverTest,
8696 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8697 config: Config{
8698 MaxVersion: VersionTLS12,
8699 },
8700 resumeSession: true,
8701 resumeConfig: &Config{
8702 MaxVersion: VersionTLS12,
8703 Bugs: ProtocolBugs{
8704 FragmentAcrossChangeCipherSpec: true,
8705 PackHandshakeFlight: packed,
8706 },
8707 },
8708 shouldFail: true,
8709 expectedError: ":UNEXPECTED_RECORD:",
8710 })
8711 testCases = append(testCases, testCase{
8712 testType: serverTest,
8713 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8714 config: Config{
8715 MaxVersion: VersionTLS12,
8716 NextProtos: []string{"bar"},
8717 Bugs: ProtocolBugs{
8718 FragmentAcrossChangeCipherSpec: true,
8719 PackHandshakeFlight: packed,
8720 },
8721 },
8722 flags: []string{
8723 "-advertise-npn", "\x03foo\x03bar\x03baz",
8724 },
8725 shouldFail: true,
8726 expectedError: ":UNEXPECTED_RECORD:",
8727 })
8728 }
8729
David Benjamin61672812016-07-14 23:10:43 -04008730 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8731 // messages in the handshake queue. Do this by testing the server
8732 // reading the client Finished, reversing the flight so Finished comes
8733 // first.
8734 testCases = append(testCases, testCase{
8735 protocol: dtls,
8736 testType: serverTest,
8737 name: "SendUnencryptedFinished-DTLS",
8738 config: Config{
8739 MaxVersion: VersionTLS12,
8740 Bugs: ProtocolBugs{
8741 SendUnencryptedFinished: true,
8742 ReverseHandshakeFragments: true,
8743 },
8744 },
8745 shouldFail: true,
8746 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8747 })
8748
Steven Valdez143e8b32016-07-11 13:19:03 -04008749 // Test synchronization between encryption changes and the handshake in
8750 // TLS 1.3, where ChangeCipherSpec is implicit.
8751 testCases = append(testCases, testCase{
8752 name: "PartialEncryptedExtensionsWithServerHello",
8753 config: Config{
8754 MaxVersion: VersionTLS13,
8755 Bugs: ProtocolBugs{
8756 PartialEncryptedExtensionsWithServerHello: true,
8757 },
8758 },
8759 shouldFail: true,
8760 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8761 })
8762 testCases = append(testCases, testCase{
8763 testType: serverTest,
8764 name: "PartialClientFinishedWithClientHello",
8765 config: Config{
8766 MaxVersion: VersionTLS13,
8767 Bugs: ProtocolBugs{
8768 PartialClientFinishedWithClientHello: true,
8769 },
8770 },
8771 shouldFail: true,
8772 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8773 })
8774
David Benjamin82261be2016-07-07 14:32:50 -07008775 // Test that early ChangeCipherSpecs are handled correctly.
8776 testCases = append(testCases, testCase{
8777 testType: serverTest,
8778 name: "EarlyChangeCipherSpec-server-1",
8779 config: Config{
8780 MaxVersion: VersionTLS12,
8781 Bugs: ProtocolBugs{
8782 EarlyChangeCipherSpec: 1,
8783 },
8784 },
8785 shouldFail: true,
8786 expectedError: ":UNEXPECTED_RECORD:",
8787 })
8788 testCases = append(testCases, testCase{
8789 testType: serverTest,
8790 name: "EarlyChangeCipherSpec-server-2",
8791 config: Config{
8792 MaxVersion: VersionTLS12,
8793 Bugs: ProtocolBugs{
8794 EarlyChangeCipherSpec: 2,
8795 },
8796 },
8797 shouldFail: true,
8798 expectedError: ":UNEXPECTED_RECORD:",
8799 })
8800 testCases = append(testCases, testCase{
8801 protocol: dtls,
8802 name: "StrayChangeCipherSpec",
8803 config: Config{
8804 // TODO(davidben): Once DTLS 1.3 exists, test
8805 // that stray ChangeCipherSpec messages are
8806 // rejected.
8807 MaxVersion: VersionTLS12,
8808 Bugs: ProtocolBugs{
8809 StrayChangeCipherSpec: true,
8810 },
8811 },
8812 })
8813
8814 // Test that the contents of ChangeCipherSpec are checked.
8815 testCases = append(testCases, testCase{
8816 name: "BadChangeCipherSpec-1",
8817 config: Config{
8818 MaxVersion: VersionTLS12,
8819 Bugs: ProtocolBugs{
8820 BadChangeCipherSpec: []byte{2},
8821 },
8822 },
8823 shouldFail: true,
8824 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8825 })
8826 testCases = append(testCases, testCase{
8827 name: "BadChangeCipherSpec-2",
8828 config: Config{
8829 MaxVersion: VersionTLS12,
8830 Bugs: ProtocolBugs{
8831 BadChangeCipherSpec: []byte{1, 1},
8832 },
8833 },
8834 shouldFail: true,
8835 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8836 })
8837 testCases = append(testCases, testCase{
8838 protocol: dtls,
8839 name: "BadChangeCipherSpec-DTLS-1",
8840 config: Config{
8841 MaxVersion: VersionTLS12,
8842 Bugs: ProtocolBugs{
8843 BadChangeCipherSpec: []byte{2},
8844 },
8845 },
8846 shouldFail: true,
8847 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8848 })
8849 testCases = append(testCases, testCase{
8850 protocol: dtls,
8851 name: "BadChangeCipherSpec-DTLS-2",
8852 config: Config{
8853 MaxVersion: VersionTLS12,
8854 Bugs: ProtocolBugs{
8855 BadChangeCipherSpec: []byte{1, 1},
8856 },
8857 },
8858 shouldFail: true,
8859 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8860 })
8861}
8862
David Benjamincd2c8062016-09-09 11:28:16 -04008863type perMessageTest struct {
8864 messageType uint8
8865 test testCase
8866}
8867
8868// makePerMessageTests returns a series of test templates which cover each
8869// message in the TLS handshake. These may be used with bugs like
8870// WrongMessageType to fully test a per-message bug.
8871func makePerMessageTests() []perMessageTest {
8872 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008873 for _, protocol := range []protocol{tls, dtls} {
8874 var suffix string
8875 if protocol == dtls {
8876 suffix = "-DTLS"
8877 }
8878
David Benjamincd2c8062016-09-09 11:28:16 -04008879 ret = append(ret, perMessageTest{
8880 messageType: typeClientHello,
8881 test: testCase{
8882 protocol: protocol,
8883 testType: serverTest,
8884 name: "ClientHello" + suffix,
8885 config: Config{
8886 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008887 },
8888 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008889 })
8890
8891 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008892 ret = append(ret, perMessageTest{
8893 messageType: typeHelloVerifyRequest,
8894 test: testCase{
8895 protocol: protocol,
8896 name: "HelloVerifyRequest" + suffix,
8897 config: Config{
8898 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008899 },
8900 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008901 })
8902 }
8903
David Benjamincd2c8062016-09-09 11:28:16 -04008904 ret = append(ret, perMessageTest{
8905 messageType: typeServerHello,
8906 test: testCase{
8907 protocol: protocol,
8908 name: "ServerHello" + suffix,
8909 config: Config{
8910 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008911 },
8912 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008913 })
8914
David Benjamincd2c8062016-09-09 11:28:16 -04008915 ret = append(ret, perMessageTest{
8916 messageType: typeCertificate,
8917 test: testCase{
8918 protocol: protocol,
8919 name: "ServerCertificate" + suffix,
8920 config: Config{
8921 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008922 },
8923 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008924 })
8925
David Benjamincd2c8062016-09-09 11:28:16 -04008926 ret = append(ret, perMessageTest{
8927 messageType: typeCertificateStatus,
8928 test: testCase{
8929 protocol: protocol,
8930 name: "CertificateStatus" + suffix,
8931 config: Config{
8932 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008933 },
David Benjamincd2c8062016-09-09 11:28:16 -04008934 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008935 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008936 })
8937
David Benjamincd2c8062016-09-09 11:28:16 -04008938 ret = append(ret, perMessageTest{
8939 messageType: typeServerKeyExchange,
8940 test: testCase{
8941 protocol: protocol,
8942 name: "ServerKeyExchange" + suffix,
8943 config: Config{
8944 MaxVersion: VersionTLS12,
8945 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008946 },
8947 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008948 })
8949
David Benjamincd2c8062016-09-09 11:28:16 -04008950 ret = append(ret, perMessageTest{
8951 messageType: typeCertificateRequest,
8952 test: testCase{
8953 protocol: protocol,
8954 name: "CertificateRequest" + suffix,
8955 config: Config{
8956 MaxVersion: VersionTLS12,
8957 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008958 },
8959 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008960 })
8961
David Benjamincd2c8062016-09-09 11:28:16 -04008962 ret = append(ret, perMessageTest{
8963 messageType: typeServerHelloDone,
8964 test: testCase{
8965 protocol: protocol,
8966 name: "ServerHelloDone" + suffix,
8967 config: Config{
8968 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008969 },
8970 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008971 })
8972
David Benjamincd2c8062016-09-09 11:28:16 -04008973 ret = append(ret, perMessageTest{
8974 messageType: typeCertificate,
8975 test: testCase{
8976 testType: serverTest,
8977 protocol: protocol,
8978 name: "ClientCertificate" + suffix,
8979 config: Config{
8980 Certificates: []Certificate{rsaCertificate},
8981 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008982 },
David Benjamincd2c8062016-09-09 11:28:16 -04008983 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008984 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008985 })
8986
David Benjamincd2c8062016-09-09 11:28:16 -04008987 ret = append(ret, perMessageTest{
8988 messageType: typeCertificateVerify,
8989 test: testCase{
8990 testType: serverTest,
8991 protocol: protocol,
8992 name: "CertificateVerify" + suffix,
8993 config: Config{
8994 Certificates: []Certificate{rsaCertificate},
8995 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008996 },
David Benjamincd2c8062016-09-09 11:28:16 -04008997 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008998 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008999 })
9000
David Benjamincd2c8062016-09-09 11:28:16 -04009001 ret = append(ret, perMessageTest{
9002 messageType: typeClientKeyExchange,
9003 test: testCase{
9004 testType: serverTest,
9005 protocol: protocol,
9006 name: "ClientKeyExchange" + suffix,
9007 config: Config{
9008 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009009 },
9010 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009011 })
9012
9013 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04009014 ret = append(ret, perMessageTest{
9015 messageType: typeNextProtocol,
9016 test: testCase{
9017 testType: serverTest,
9018 protocol: protocol,
9019 name: "NextProtocol" + suffix,
9020 config: Config{
9021 MaxVersion: VersionTLS12,
9022 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009023 },
David Benjamincd2c8062016-09-09 11:28:16 -04009024 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04009025 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009026 })
9027
David Benjamincd2c8062016-09-09 11:28:16 -04009028 ret = append(ret, perMessageTest{
9029 messageType: typeChannelID,
9030 test: testCase{
9031 testType: serverTest,
9032 protocol: protocol,
9033 name: "ChannelID" + suffix,
9034 config: Config{
9035 MaxVersion: VersionTLS12,
9036 ChannelID: channelIDKey,
9037 },
9038 flags: []string{
9039 "-expect-channel-id",
9040 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04009041 },
9042 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009043 })
9044 }
9045
David Benjamincd2c8062016-09-09 11:28:16 -04009046 ret = append(ret, perMessageTest{
9047 messageType: typeFinished,
9048 test: testCase{
9049 testType: serverTest,
9050 protocol: protocol,
9051 name: "ClientFinished" + suffix,
9052 config: Config{
9053 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009054 },
9055 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009056 })
9057
David Benjamincd2c8062016-09-09 11:28:16 -04009058 ret = append(ret, perMessageTest{
9059 messageType: typeNewSessionTicket,
9060 test: testCase{
9061 protocol: protocol,
9062 name: "NewSessionTicket" + suffix,
9063 config: Config{
9064 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009065 },
9066 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009067 })
9068
David Benjamincd2c8062016-09-09 11:28:16 -04009069 ret = append(ret, perMessageTest{
9070 messageType: typeFinished,
9071 test: testCase{
9072 protocol: protocol,
9073 name: "ServerFinished" + suffix,
9074 config: Config{
9075 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04009076 },
9077 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04009078 })
9079
9080 }
David Benjamincd2c8062016-09-09 11:28:16 -04009081
9082 ret = append(ret, perMessageTest{
9083 messageType: typeClientHello,
9084 test: testCase{
9085 testType: serverTest,
9086 name: "TLS13-ClientHello",
9087 config: Config{
9088 MaxVersion: VersionTLS13,
9089 },
9090 },
9091 })
9092
9093 ret = append(ret, perMessageTest{
9094 messageType: typeServerHello,
9095 test: testCase{
9096 name: "TLS13-ServerHello",
9097 config: Config{
9098 MaxVersion: VersionTLS13,
9099 },
9100 },
9101 })
9102
9103 ret = append(ret, perMessageTest{
9104 messageType: typeEncryptedExtensions,
9105 test: testCase{
9106 name: "TLS13-EncryptedExtensions",
9107 config: Config{
9108 MaxVersion: VersionTLS13,
9109 },
9110 },
9111 })
9112
9113 ret = append(ret, perMessageTest{
9114 messageType: typeCertificateRequest,
9115 test: testCase{
9116 name: "TLS13-CertificateRequest",
9117 config: Config{
9118 MaxVersion: VersionTLS13,
9119 ClientAuth: RequireAnyClientCert,
9120 },
9121 },
9122 })
9123
9124 ret = append(ret, perMessageTest{
9125 messageType: typeCertificate,
9126 test: testCase{
9127 name: "TLS13-ServerCertificate",
9128 config: Config{
9129 MaxVersion: VersionTLS13,
9130 },
9131 },
9132 })
9133
9134 ret = append(ret, perMessageTest{
9135 messageType: typeCertificateVerify,
9136 test: testCase{
9137 name: "TLS13-ServerCertificateVerify",
9138 config: Config{
9139 MaxVersion: VersionTLS13,
9140 },
9141 },
9142 })
9143
9144 ret = append(ret, perMessageTest{
9145 messageType: typeFinished,
9146 test: testCase{
9147 name: "TLS13-ServerFinished",
9148 config: Config{
9149 MaxVersion: VersionTLS13,
9150 },
9151 },
9152 })
9153
9154 ret = append(ret, perMessageTest{
9155 messageType: typeCertificate,
9156 test: testCase{
9157 testType: serverTest,
9158 name: "TLS13-ClientCertificate",
9159 config: Config{
9160 Certificates: []Certificate{rsaCertificate},
9161 MaxVersion: VersionTLS13,
9162 },
9163 flags: []string{"-require-any-client-certificate"},
9164 },
9165 })
9166
9167 ret = append(ret, perMessageTest{
9168 messageType: typeCertificateVerify,
9169 test: testCase{
9170 testType: serverTest,
9171 name: "TLS13-ClientCertificateVerify",
9172 config: Config{
9173 Certificates: []Certificate{rsaCertificate},
9174 MaxVersion: VersionTLS13,
9175 },
9176 flags: []string{"-require-any-client-certificate"},
9177 },
9178 })
9179
9180 ret = append(ret, perMessageTest{
9181 messageType: typeFinished,
9182 test: testCase{
9183 testType: serverTest,
9184 name: "TLS13-ClientFinished",
9185 config: Config{
9186 MaxVersion: VersionTLS13,
9187 },
9188 },
9189 })
9190
9191 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04009192}
9193
David Benjamincd2c8062016-09-09 11:28:16 -04009194func addWrongMessageTypeTests() {
9195 for _, t := range makePerMessageTests() {
9196 t.test.name = "WrongMessageType-" + t.test.name
9197 t.test.config.Bugs.SendWrongMessageType = t.messageType
9198 t.test.shouldFail = true
9199 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
9200 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04009201
David Benjamincd2c8062016-09-09 11:28:16 -04009202 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9203 // In TLS 1.3, a bad ServerHello means the client sends
9204 // an unencrypted alert while the server expects
9205 // encryption, so the alert is not readable by runner.
9206 t.test.expectedLocalError = "local error: bad record MAC"
9207 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009208
David Benjamincd2c8062016-09-09 11:28:16 -04009209 testCases = append(testCases, t.test)
9210 }
Steven Valdez143e8b32016-07-11 13:19:03 -04009211}
9212
David Benjamin639846e2016-09-09 11:41:18 -04009213func addTrailingMessageDataTests() {
9214 for _, t := range makePerMessageTests() {
9215 t.test.name = "TrailingMessageData-" + t.test.name
9216 t.test.config.Bugs.SendTrailingMessageData = t.messageType
9217 t.test.shouldFail = true
9218 t.test.expectedError = ":DECODE_ERROR:"
9219 t.test.expectedLocalError = "remote error: error decoding message"
9220
9221 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
9222 // In TLS 1.3, a bad ServerHello means the client sends
9223 // an unencrypted alert while the server expects
9224 // encryption, so the alert is not readable by runner.
9225 t.test.expectedLocalError = "local error: bad record MAC"
9226 }
9227
9228 if t.messageType == typeFinished {
9229 // Bad Finished messages read as the verify data having
9230 // the wrong length.
9231 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
9232 t.test.expectedLocalError = "remote error: error decrypting message"
9233 }
9234
9235 testCases = append(testCases, t.test)
9236 }
9237}
9238
Steven Valdez143e8b32016-07-11 13:19:03 -04009239func addTLS13HandshakeTests() {
9240 testCases = append(testCases, testCase{
9241 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04009242 name: "NegotiatePSKResumption-TLS13",
9243 config: Config{
9244 MaxVersion: VersionTLS13,
9245 Bugs: ProtocolBugs{
9246 NegotiatePSKResumption: true,
9247 },
9248 },
9249 resumeSession: true,
9250 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009251 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez803c77a2016-09-06 14:13:43 -04009252 })
9253
9254 testCases = append(testCases, testCase{
9255 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04009256 name: "MissingKeyShare-Client",
9257 config: Config{
9258 MaxVersion: VersionTLS13,
9259 Bugs: ProtocolBugs{
9260 MissingKeyShare: true,
9261 },
9262 },
9263 shouldFail: true,
David Benjamindb5bd722016-12-08 18:21:27 -05009264 expectedError: ":MISSING_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009265 })
9266
9267 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009268 testType: serverTest,
9269 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04009270 config: Config{
9271 MaxVersion: VersionTLS13,
9272 Bugs: ProtocolBugs{
9273 MissingKeyShare: true,
9274 },
9275 },
9276 shouldFail: true,
9277 expectedError: ":MISSING_KEY_SHARE:",
9278 })
9279
9280 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009281 testType: serverTest,
9282 name: "DuplicateKeyShares",
9283 config: Config{
9284 MaxVersion: VersionTLS13,
9285 Bugs: ProtocolBugs{
9286 DuplicateKeyShares: true,
9287 },
9288 },
David Benjamin7e1f9842016-09-20 19:24:40 -04009289 shouldFail: true,
9290 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04009291 })
9292
9293 testCases = append(testCases, testCase{
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009294 testType: serverTest,
9295 name: "SkipEarlyData",
9296 config: Config{
9297 MaxVersion: VersionTLS13,
9298 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009299 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009300 },
9301 },
9302 })
9303
9304 testCases = append(testCases, testCase{
9305 testType: serverTest,
9306 name: "SkipEarlyData-OmitEarlyDataExtension",
9307 config: Config{
9308 MaxVersion: VersionTLS13,
9309 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009310 SendFakeEarlyDataLength: 4,
9311 OmitEarlyDataExtension: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009312 },
9313 },
9314 shouldFail: true,
9315 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9316 })
9317
9318 testCases = append(testCases, testCase{
9319 testType: serverTest,
9320 name: "SkipEarlyData-TooMuchData",
9321 config: Config{
9322 MaxVersion: VersionTLS13,
9323 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009324 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009325 },
9326 },
9327 shouldFail: true,
9328 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9329 })
9330
9331 testCases = append(testCases, testCase{
9332 testType: serverTest,
9333 name: "SkipEarlyData-Interleaved",
9334 config: Config{
9335 MaxVersion: VersionTLS13,
9336 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009337 SendFakeEarlyDataLength: 4,
9338 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009339 },
9340 },
9341 shouldFail: true,
9342 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
9343 })
9344
9345 testCases = append(testCases, testCase{
9346 testType: serverTest,
9347 name: "SkipEarlyData-EarlyDataInTLS12",
9348 config: Config{
9349 MaxVersion: VersionTLS13,
9350 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009351 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009352 },
9353 },
9354 shouldFail: true,
9355 expectedError: ":UNEXPECTED_RECORD:",
9356 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
9357 })
9358
9359 testCases = append(testCases, testCase{
9360 testType: serverTest,
9361 name: "SkipEarlyData-HRR",
9362 config: Config{
9363 MaxVersion: VersionTLS13,
9364 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009365 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009366 },
9367 DefaultCurves: []CurveID{},
9368 },
9369 })
9370
9371 testCases = append(testCases, testCase{
9372 testType: serverTest,
9373 name: "SkipEarlyData-HRR-Interleaved",
9374 config: Config{
9375 MaxVersion: VersionTLS13,
9376 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009377 SendFakeEarlyDataLength: 4,
9378 InterleaveEarlyData: true,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009379 },
9380 DefaultCurves: []CurveID{},
9381 },
9382 shouldFail: true,
9383 expectedError: ":UNEXPECTED_RECORD:",
9384 })
9385
9386 testCases = append(testCases, testCase{
9387 testType: serverTest,
9388 name: "SkipEarlyData-HRR-TooMuchData",
9389 config: Config{
9390 MaxVersion: VersionTLS13,
9391 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009392 SendFakeEarlyDataLength: 16384 + 1,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009393 },
9394 DefaultCurves: []CurveID{},
9395 },
9396 shouldFail: true,
9397 expectedError: ":TOO_MUCH_SKIPPED_EARLY_DATA:",
9398 })
9399
9400 // Test that skipping early data looking for cleartext correctly
9401 // processes an alert record.
9402 testCases = append(testCases, testCase{
9403 testType: serverTest,
9404 name: "SkipEarlyData-HRR-FatalAlert",
9405 config: Config{
9406 MaxVersion: VersionTLS13,
9407 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -08009408 SendEarlyAlert: true,
9409 SendFakeEarlyDataLength: 4,
Steven Valdeza4ee74d2016-11-29 13:36:45 -05009410 },
9411 DefaultCurves: []CurveID{},
9412 },
9413 shouldFail: true,
9414 expectedError: ":SSLV3_ALERT_HANDSHAKE_FAILURE:",
9415 })
9416
9417 testCases = append(testCases, testCase{
9418 testType: serverTest,
9419 name: "SkipEarlyData-SecondClientHelloEarlyData",
9420 config: Config{
9421 MaxVersion: VersionTLS13,
9422 Bugs: ProtocolBugs{
9423 SendEarlyDataOnSecondClientHello: true,
9424 },
9425 DefaultCurves: []CurveID{},
9426 },
9427 shouldFail: true,
9428 expectedLocalError: "remote error: bad record MAC",
9429 })
9430
9431 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04009432 testType: clientTest,
9433 name: "EmptyEncryptedExtensions",
9434 config: Config{
9435 MaxVersion: VersionTLS13,
9436 Bugs: ProtocolBugs{
9437 EmptyEncryptedExtensions: true,
9438 },
9439 },
9440 shouldFail: true,
9441 expectedLocalError: "remote error: error decoding message",
9442 })
9443
9444 testCases = append(testCases, testCase{
9445 testType: clientTest,
9446 name: "EncryptedExtensionsWithKeyShare",
9447 config: Config{
9448 MaxVersion: VersionTLS13,
9449 Bugs: ProtocolBugs{
9450 EncryptedExtensionsWithKeyShare: true,
9451 },
9452 },
9453 shouldFail: true,
9454 expectedLocalError: "remote error: unsupported extension",
9455 })
Steven Valdez5440fe02016-07-18 12:40:30 -04009456
9457 testCases = append(testCases, testCase{
9458 testType: serverTest,
9459 name: "SendHelloRetryRequest",
9460 config: Config{
9461 MaxVersion: VersionTLS13,
9462 // Require a HelloRetryRequest for every curve.
9463 DefaultCurves: []CurveID{},
9464 },
9465 expectedCurveID: CurveX25519,
9466 })
9467
9468 testCases = append(testCases, testCase{
9469 testType: serverTest,
9470 name: "SendHelloRetryRequest-2",
9471 config: Config{
9472 MaxVersion: VersionTLS13,
9473 DefaultCurves: []CurveID{CurveP384},
9474 },
9475 // Although the ClientHello did not predict our preferred curve,
9476 // we always select it whether it is predicted or not.
9477 expectedCurveID: CurveX25519,
9478 })
9479
9480 testCases = append(testCases, testCase{
9481 name: "UnknownCurve-HelloRetryRequest",
9482 config: Config{
9483 MaxVersion: VersionTLS13,
9484 // P-384 requires HelloRetryRequest in BoringSSL.
9485 CurvePreferences: []CurveID{CurveP384},
9486 Bugs: ProtocolBugs{
9487 SendHelloRetryRequestCurve: bogusCurve,
9488 },
9489 },
9490 shouldFail: true,
9491 expectedError: ":WRONG_CURVE:",
9492 })
9493
9494 testCases = append(testCases, testCase{
9495 name: "DisabledCurve-HelloRetryRequest",
9496 config: Config{
9497 MaxVersion: VersionTLS13,
9498 CurvePreferences: []CurveID{CurveP256},
9499 Bugs: ProtocolBugs{
9500 IgnorePeerCurvePreferences: true,
9501 },
9502 },
9503 flags: []string{"-p384-only"},
9504 shouldFail: true,
9505 expectedError: ":WRONG_CURVE:",
9506 })
9507
9508 testCases = append(testCases, testCase{
9509 name: "UnnecessaryHelloRetryRequest",
9510 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04009511 MaxVersion: VersionTLS13,
9512 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04009513 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04009514 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04009515 },
9516 },
9517 shouldFail: true,
9518 expectedError: ":WRONG_CURVE:",
9519 })
9520
9521 testCases = append(testCases, testCase{
9522 name: "SecondHelloRetryRequest",
9523 config: Config{
9524 MaxVersion: VersionTLS13,
9525 // P-384 requires HelloRetryRequest in BoringSSL.
9526 CurvePreferences: []CurveID{CurveP384},
9527 Bugs: ProtocolBugs{
9528 SecondHelloRetryRequest: true,
9529 },
9530 },
9531 shouldFail: true,
9532 expectedError: ":UNEXPECTED_MESSAGE:",
9533 })
9534
9535 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009536 name: "HelloRetryRequest-Empty",
9537 config: Config{
9538 MaxVersion: VersionTLS13,
9539 Bugs: ProtocolBugs{
9540 AlwaysSendHelloRetryRequest: true,
9541 },
9542 },
9543 shouldFail: true,
9544 expectedError: ":DECODE_ERROR:",
9545 })
9546
9547 testCases = append(testCases, testCase{
9548 name: "HelloRetryRequest-DuplicateCurve",
9549 config: Config{
9550 MaxVersion: VersionTLS13,
9551 // P-384 requires a HelloRetryRequest against BoringSSL's default
9552 // configuration. Assert this ExpectMissingKeyShare.
9553 CurvePreferences: []CurveID{CurveP384},
9554 Bugs: ProtocolBugs{
9555 ExpectMissingKeyShare: true,
9556 DuplicateHelloRetryRequestExtensions: true,
9557 },
9558 },
9559 shouldFail: true,
9560 expectedError: ":DUPLICATE_EXTENSION:",
9561 expectedLocalError: "remote error: illegal parameter",
9562 })
9563
9564 testCases = append(testCases, testCase{
9565 name: "HelloRetryRequest-Cookie",
9566 config: Config{
9567 MaxVersion: VersionTLS13,
9568 Bugs: ProtocolBugs{
9569 SendHelloRetryRequestCookie: []byte("cookie"),
9570 },
9571 },
9572 })
9573
9574 testCases = append(testCases, testCase{
9575 name: "HelloRetryRequest-DuplicateCookie",
9576 config: Config{
9577 MaxVersion: VersionTLS13,
9578 Bugs: ProtocolBugs{
9579 SendHelloRetryRequestCookie: []byte("cookie"),
9580 DuplicateHelloRetryRequestExtensions: true,
9581 },
9582 },
9583 shouldFail: true,
9584 expectedError: ":DUPLICATE_EXTENSION:",
9585 expectedLocalError: "remote error: illegal parameter",
9586 })
9587
9588 testCases = append(testCases, testCase{
9589 name: "HelloRetryRequest-EmptyCookie",
9590 config: Config{
9591 MaxVersion: VersionTLS13,
9592 Bugs: ProtocolBugs{
9593 SendHelloRetryRequestCookie: []byte{},
9594 },
9595 },
9596 shouldFail: true,
9597 expectedError: ":DECODE_ERROR:",
9598 })
9599
9600 testCases = append(testCases, testCase{
9601 name: "HelloRetryRequest-Cookie-Curve",
9602 config: Config{
9603 MaxVersion: VersionTLS13,
9604 // P-384 requires HelloRetryRequest in BoringSSL.
9605 CurvePreferences: []CurveID{CurveP384},
9606 Bugs: ProtocolBugs{
9607 SendHelloRetryRequestCookie: []byte("cookie"),
9608 ExpectMissingKeyShare: true,
9609 },
9610 },
9611 })
9612
9613 testCases = append(testCases, testCase{
9614 name: "HelloRetryRequest-Unknown",
9615 config: Config{
9616 MaxVersion: VersionTLS13,
9617 Bugs: ProtocolBugs{
9618 CustomHelloRetryRequestExtension: "extension",
9619 },
9620 },
9621 shouldFail: true,
9622 expectedError: ":UNEXPECTED_EXTENSION:",
9623 expectedLocalError: "remote error: unsupported extension",
9624 })
9625
9626 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009627 testType: serverTest,
9628 name: "SecondClientHelloMissingKeyShare",
9629 config: Config{
9630 MaxVersion: VersionTLS13,
9631 DefaultCurves: []CurveID{},
9632 Bugs: ProtocolBugs{
9633 SecondClientHelloMissingKeyShare: true,
9634 },
9635 },
9636 shouldFail: true,
9637 expectedError: ":MISSING_KEY_SHARE:",
9638 })
9639
9640 testCases = append(testCases, testCase{
9641 testType: serverTest,
9642 name: "SecondClientHelloWrongCurve",
9643 config: Config{
9644 MaxVersion: VersionTLS13,
9645 DefaultCurves: []CurveID{},
9646 Bugs: ProtocolBugs{
9647 MisinterpretHelloRetryRequestCurve: CurveP521,
9648 },
9649 },
9650 shouldFail: true,
9651 expectedError: ":WRONG_CURVE:",
9652 })
9653
9654 testCases = append(testCases, testCase{
9655 name: "HelloRetryRequestVersionMismatch",
9656 config: Config{
9657 MaxVersion: VersionTLS13,
9658 // P-384 requires HelloRetryRequest in BoringSSL.
9659 CurvePreferences: []CurveID{CurveP384},
9660 Bugs: ProtocolBugs{
9661 SendServerHelloVersion: 0x0305,
9662 },
9663 },
9664 shouldFail: true,
9665 expectedError: ":WRONG_VERSION_NUMBER:",
9666 })
9667
9668 testCases = append(testCases, testCase{
9669 name: "HelloRetryRequestCurveMismatch",
9670 config: Config{
9671 MaxVersion: VersionTLS13,
9672 // P-384 requires HelloRetryRequest in BoringSSL.
9673 CurvePreferences: []CurveID{CurveP384},
9674 Bugs: ProtocolBugs{
9675 // Send P-384 (correct) in the HelloRetryRequest.
9676 SendHelloRetryRequestCurve: CurveP384,
9677 // But send P-256 in the ServerHello.
9678 SendCurve: CurveP256,
9679 },
9680 },
9681 shouldFail: true,
9682 expectedError: ":WRONG_CURVE:",
9683 })
9684
9685 // Test the server selecting a curve that requires a HelloRetryRequest
9686 // without sending it.
9687 testCases = append(testCases, testCase{
9688 name: "SkipHelloRetryRequest",
9689 config: Config{
9690 MaxVersion: VersionTLS13,
9691 // P-384 requires HelloRetryRequest in BoringSSL.
9692 CurvePreferences: []CurveID{CurveP384},
9693 Bugs: ProtocolBugs{
9694 SkipHelloRetryRequest: true,
9695 },
9696 },
9697 shouldFail: true,
9698 expectedError: ":WRONG_CURVE:",
9699 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009700
9701 testCases = append(testCases, testCase{
9702 name: "TLS13-RequestContextInHandshake",
9703 config: Config{
9704 MaxVersion: VersionTLS13,
9705 MinVersion: VersionTLS13,
9706 ClientAuth: RequireAnyClientCert,
9707 Bugs: ProtocolBugs{
9708 SendRequestContext: []byte("request context"),
9709 },
9710 },
9711 flags: []string{
9712 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9713 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9714 },
9715 shouldFail: true,
9716 expectedError: ":DECODE_ERROR:",
9717 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009718
9719 testCases = append(testCases, testCase{
9720 testType: serverTest,
9721 name: "TLS13-TrailingKeyShareData",
9722 config: Config{
9723 MaxVersion: VersionTLS13,
9724 Bugs: ProtocolBugs{
9725 TrailingKeyShareData: true,
9726 },
9727 },
9728 shouldFail: true,
9729 expectedError: ":DECODE_ERROR:",
9730 })
David Benjamin7f78df42016-10-05 22:33:19 -04009731
9732 testCases = append(testCases, testCase{
9733 name: "TLS13-AlwaysSelectPSKIdentity",
9734 config: Config{
9735 MaxVersion: VersionTLS13,
9736 Bugs: ProtocolBugs{
9737 AlwaysSelectPSKIdentity: true,
9738 },
9739 },
9740 shouldFail: true,
9741 expectedError: ":UNEXPECTED_EXTENSION:",
9742 })
9743
9744 testCases = append(testCases, testCase{
9745 name: "TLS13-InvalidPSKIdentity",
9746 config: Config{
9747 MaxVersion: VersionTLS13,
9748 Bugs: ProtocolBugs{
9749 SelectPSKIdentityOnResume: 1,
9750 },
9751 },
9752 resumeSession: true,
9753 shouldFail: true,
9754 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9755 })
David Benjamin1286bee2016-10-07 15:25:06 -04009756
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009757 testCases = append(testCases, testCase{
9758 testType: serverTest,
9759 name: "TLS13-ExtraPSKIdentity",
9760 config: Config{
9761 MaxVersion: VersionTLS13,
9762 Bugs: ProtocolBugs{
David Benjaminaedf3032016-12-01 16:47:56 -05009763 ExtraPSKIdentity: true,
9764 SendExtraPSKBinder: true,
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009765 },
9766 },
9767 resumeSession: true,
9768 })
9769
David Benjamin1286bee2016-10-07 15:25:06 -04009770 // Test that unknown NewSessionTicket extensions are tolerated.
9771 testCases = append(testCases, testCase{
9772 name: "TLS13-CustomTicketExtension",
9773 config: Config{
9774 MaxVersion: VersionTLS13,
9775 Bugs: ProtocolBugs{
9776 CustomTicketExtension: "1234",
9777 },
9778 },
9779 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009780}
9781
David Benjaminabbbee12016-10-31 19:20:42 -04009782func addTLS13CipherPreferenceTests() {
9783 // Test that client preference is honored if the shim has AES hardware
9784 // and ChaCha20-Poly1305 is preferred otherwise.
9785 testCases = append(testCases, testCase{
9786 testType: serverTest,
9787 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9788 config: Config{
9789 MaxVersion: VersionTLS13,
9790 CipherSuites: []uint16{
9791 TLS_CHACHA20_POLY1305_SHA256,
9792 TLS_AES_128_GCM_SHA256,
9793 },
9794 },
9795 flags: []string{
9796 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9797 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9798 },
9799 })
9800
9801 testCases = append(testCases, testCase{
9802 testType: serverTest,
9803 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9804 config: Config{
9805 MaxVersion: VersionTLS13,
9806 CipherSuites: []uint16{
9807 TLS_AES_128_GCM_SHA256,
9808 TLS_CHACHA20_POLY1305_SHA256,
9809 },
9810 },
9811 flags: []string{
9812 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9813 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9814 },
9815 })
9816
9817 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9818 // whether it has AES hardware.
9819 testCases = append(testCases, testCase{
9820 name: "TLS13-CipherPreference-Client",
9821 config: Config{
9822 MaxVersion: VersionTLS13,
9823 // Use the client cipher order. (This is the default but
9824 // is listed to be explicit.)
9825 PreferServerCipherSuites: false,
9826 },
9827 flags: []string{
9828 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9829 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9830 },
9831 })
9832}
9833
David Benjaminf3fbade2016-09-19 13:08:16 -04009834func addPeekTests() {
9835 // Test SSL_peek works, including on empty records.
9836 testCases = append(testCases, testCase{
9837 name: "Peek-Basic",
9838 sendEmptyRecords: 1,
9839 flags: []string{"-peek-then-read"},
9840 })
9841
9842 // Test SSL_peek can drive the initial handshake.
9843 testCases = append(testCases, testCase{
9844 name: "Peek-ImplicitHandshake",
9845 flags: []string{
9846 "-peek-then-read",
9847 "-implicit-handshake",
9848 },
9849 })
9850
9851 // Test SSL_peek can discover and drive a renegotiation.
9852 testCases = append(testCases, testCase{
9853 name: "Peek-Renegotiate",
9854 config: Config{
9855 MaxVersion: VersionTLS12,
9856 },
9857 renegotiate: 1,
9858 flags: []string{
9859 "-peek-then-read",
9860 "-renegotiate-freely",
9861 "-expect-total-renegotiations", "1",
9862 },
9863 })
9864
9865 // Test SSL_peek can discover a close_notify.
9866 testCases = append(testCases, testCase{
9867 name: "Peek-Shutdown",
9868 config: Config{
9869 Bugs: ProtocolBugs{
9870 ExpectCloseNotify: true,
9871 },
9872 },
9873 flags: []string{
9874 "-peek-then-read",
9875 "-check-close-notify",
9876 },
9877 })
9878
9879 // Test SSL_peek can discover an alert.
9880 testCases = append(testCases, testCase{
9881 name: "Peek-Alert",
9882 config: Config{
9883 Bugs: ProtocolBugs{
9884 SendSpuriousAlert: alertRecordOverflow,
9885 },
9886 },
9887 flags: []string{"-peek-then-read"},
9888 shouldFail: true,
9889 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9890 })
9891
9892 // Test SSL_peek can handle KeyUpdate.
9893 testCases = append(testCases, testCase{
9894 name: "Peek-KeyUpdate",
9895 config: Config{
9896 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009897 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009898 sendKeyUpdates: 1,
9899 keyUpdateRequest: keyUpdateNotRequested,
9900 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009901 })
9902}
9903
David Benjamine6f22212016-11-08 14:28:24 -05009904func addRecordVersionTests() {
9905 for _, ver := range tlsVersions {
9906 // Test that the record version is enforced.
9907 testCases = append(testCases, testCase{
9908 name: "CheckRecordVersion-" + ver.name,
9909 config: Config{
9910 MinVersion: ver.version,
9911 MaxVersion: ver.version,
9912 Bugs: ProtocolBugs{
9913 SendRecordVersion: 0x03ff,
9914 },
9915 },
9916 shouldFail: true,
9917 expectedError: ":WRONG_VERSION_NUMBER:",
9918 })
9919
9920 // Test that the ClientHello may use any record version, for
9921 // compatibility reasons.
9922 testCases = append(testCases, testCase{
9923 testType: serverTest,
9924 name: "LooseInitialRecordVersion-" + ver.name,
9925 config: Config{
9926 MinVersion: ver.version,
9927 MaxVersion: ver.version,
9928 Bugs: ProtocolBugs{
9929 SendInitialRecordVersion: 0x03ff,
9930 },
9931 },
9932 })
9933
9934 // Test that garbage ClientHello record versions are rejected.
9935 testCases = append(testCases, testCase{
9936 testType: serverTest,
9937 name: "GarbageInitialRecordVersion-" + ver.name,
9938 config: Config{
9939 MinVersion: ver.version,
9940 MaxVersion: ver.version,
9941 Bugs: ProtocolBugs{
9942 SendInitialRecordVersion: 0xffff,
9943 },
9944 },
9945 shouldFail: true,
9946 expectedError: ":WRONG_VERSION_NUMBER:",
9947 })
9948 }
9949}
9950
David Benjamin2c516452016-11-15 10:16:54 +09009951func addCertificateTests() {
9952 // Test that a certificate chain with intermediate may be sent and
9953 // received as both client and server.
9954 for _, ver := range tlsVersions {
9955 testCases = append(testCases, testCase{
9956 testType: clientTest,
9957 name: "SendReceiveIntermediate-Client-" + ver.name,
9958 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009959 MinVersion: ver.version,
9960 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009961 Certificates: []Certificate{rsaChainCertificate},
9962 ClientAuth: RequireAnyClientCert,
9963 },
9964 expectPeerCertificate: &rsaChainCertificate,
9965 flags: []string{
9966 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9967 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9968 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9969 },
9970 })
9971
9972 testCases = append(testCases, testCase{
9973 testType: serverTest,
9974 name: "SendReceiveIntermediate-Server-" + ver.name,
9975 config: Config{
Adam Langleycd6cfb02016-12-06 15:11:00 -08009976 MinVersion: ver.version,
9977 MaxVersion: ver.version,
David Benjamin2c516452016-11-15 10:16:54 +09009978 Certificates: []Certificate{rsaChainCertificate},
9979 },
9980 expectPeerCertificate: &rsaChainCertificate,
9981 flags: []string{
9982 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9983 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9984 "-require-any-client-certificate",
9985 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9986 },
9987 })
9988 }
9989}
9990
David Benjaminbbaf3672016-11-17 10:53:09 +09009991func addRetainOnlySHA256ClientCertTests() {
9992 for _, ver := range tlsVersions {
9993 // Test that enabling
9994 // SSL_CTX_set_retain_only_sha256_of_client_certs without
9995 // actually requesting a client certificate is a no-op.
9996 testCases = append(testCases, testCase{
9997 testType: serverTest,
9998 name: "RetainOnlySHA256-NoCert-" + ver.name,
9999 config: Config{
10000 MinVersion: ver.version,
10001 MaxVersion: ver.version,
10002 },
10003 flags: []string{
10004 "-retain-only-sha256-client-cert-initial",
10005 "-retain-only-sha256-client-cert-resume",
10006 },
10007 resumeSession: true,
10008 })
10009
10010 // Test that when retaining only a SHA-256 certificate is
10011 // enabled, the hash appears as expected.
10012 testCases = append(testCases, testCase{
10013 testType: serverTest,
10014 name: "RetainOnlySHA256-Cert-" + ver.name,
10015 config: Config{
10016 MinVersion: ver.version,
10017 MaxVersion: ver.version,
10018 Certificates: []Certificate{rsaCertificate},
10019 },
10020 flags: []string{
10021 "-verify-peer",
10022 "-retain-only-sha256-client-cert-initial",
10023 "-retain-only-sha256-client-cert-resume",
10024 "-expect-sha256-client-cert-initial",
10025 "-expect-sha256-client-cert-resume",
10026 },
10027 resumeSession: true,
10028 })
10029
10030 // Test that when the config changes from on to off, a
10031 // resumption is rejected because the server now wants the full
10032 // certificate chain.
10033 testCases = append(testCases, testCase{
10034 testType: serverTest,
10035 name: "RetainOnlySHA256-OnOff-" + ver.name,
10036 config: Config{
10037 MinVersion: ver.version,
10038 MaxVersion: ver.version,
10039 Certificates: []Certificate{rsaCertificate},
10040 },
10041 flags: []string{
10042 "-verify-peer",
10043 "-retain-only-sha256-client-cert-initial",
10044 "-expect-sha256-client-cert-initial",
10045 },
10046 resumeSession: true,
10047 expectResumeRejected: true,
10048 })
10049
10050 // Test that when the config changes from off to on, a
10051 // resumption is rejected because the server now wants just the
10052 // hash.
10053 testCases = append(testCases, testCase{
10054 testType: serverTest,
10055 name: "RetainOnlySHA256-OffOn-" + ver.name,
10056 config: Config{
10057 MinVersion: ver.version,
10058 MaxVersion: ver.version,
10059 Certificates: []Certificate{rsaCertificate},
10060 },
10061 flags: []string{
10062 "-verify-peer",
10063 "-retain-only-sha256-client-cert-resume",
10064 "-expect-sha256-client-cert-resume",
10065 },
10066 resumeSession: true,
10067 expectResumeRejected: true,
10068 })
10069 }
10070}
10071
Adam Langleya4b91982016-12-12 12:05:53 -080010072func addECDSAKeyUsageTests() {
10073 p256 := elliptic.P256()
10074 priv, err := ecdsa.GenerateKey(p256, rand.Reader)
10075 if err != nil {
10076 panic(err)
10077 }
10078
10079 serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
10080 serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
10081 if err != nil {
10082 panic(err)
10083 }
10084
10085 template := x509.Certificate{
10086 SerialNumber: serialNumber,
10087 Subject: pkix.Name{
10088 Organization: []string{"Acme Co"},
10089 },
10090 NotBefore: time.Now(),
10091 NotAfter: time.Now(),
10092
10093 // An ECC certificate with only the keyAgreement key usgae may
10094 // be used with ECDH, but not ECDSA.
10095 KeyUsage: x509.KeyUsageKeyAgreement,
10096 ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
10097 BasicConstraintsValid: true,
10098 }
10099
10100 derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
10101 if err != nil {
10102 panic(err)
10103 }
10104
10105 cert := Certificate{
10106 Certificate: [][]byte{derBytes},
10107 PrivateKey: priv,
10108 }
10109
10110 for _, ver := range tlsVersions {
10111 if ver.version < VersionTLS12 {
10112 continue
10113 }
10114
10115 testCases = append(testCases, testCase{
10116 testType: clientTest,
10117 name: "ECDSAKeyUsage-" + ver.name,
10118 config: Config{
10119 MinVersion: ver.version,
10120 MaxVersion: ver.version,
10121 Certificates: []Certificate{cert},
10122 },
10123 shouldFail: true,
10124 expectedError: ":ECC_CERT_NOT_FOR_SIGNING:",
10125 })
10126 }
10127}
10128
David Benjamin6f600d62016-12-21 16:06:54 -050010129func addShortHeaderTests() {
10130 // The short header extension may be negotiated as either client or
10131 // server.
10132 testCases = append(testCases, testCase{
10133 name: "ShortHeader-Client",
10134 config: Config{
10135 MaxVersion: VersionTLS13,
10136 Bugs: ProtocolBugs{
10137 EnableShortHeader: true,
10138 },
10139 },
10140 flags: []string{"-enable-short-header"},
10141 expectShortHeader: true,
10142 })
10143 testCases = append(testCases, testCase{
10144 testType: serverTest,
10145 name: "ShortHeader-Server",
10146 config: Config{
10147 MaxVersion: VersionTLS13,
10148 Bugs: ProtocolBugs{
10149 EnableShortHeader: true,
10150 },
10151 },
10152 flags: []string{"-enable-short-header"},
10153 expectShortHeader: true,
10154 })
10155
10156 // If the peer doesn't support it, it will not be negotiated.
10157 testCases = append(testCases, testCase{
10158 name: "ShortHeader-No-Yes-Client",
10159 config: Config{
10160 MaxVersion: VersionTLS13,
10161 },
10162 flags: []string{"-enable-short-header"},
10163 })
10164 testCases = append(testCases, testCase{
10165 testType: serverTest,
10166 name: "ShortHeader-No-Yes-Server",
10167 config: Config{
10168 MaxVersion: VersionTLS13,
10169 },
10170 flags: []string{"-enable-short-header"},
10171 })
10172
10173 // If we don't support it, it will not be negotiated.
10174 testCases = append(testCases, testCase{
10175 name: "ShortHeader-Yes-No-Client",
10176 config: Config{
10177 MaxVersion: VersionTLS13,
10178 Bugs: ProtocolBugs{
10179 EnableShortHeader: true,
10180 },
10181 },
10182 })
10183 testCases = append(testCases, testCase{
10184 testType: serverTest,
10185 name: "ShortHeader-Yes-No-Server",
10186 config: Config{
10187 MaxVersion: VersionTLS13,
10188 Bugs: ProtocolBugs{
10189 EnableShortHeader: true,
10190 },
10191 },
10192 })
10193
10194 // It will not be negotiated at TLS 1.2.
10195 testCases = append(testCases, testCase{
10196 name: "ShortHeader-TLS12-Client",
10197 config: Config{
10198 MaxVersion: VersionTLS12,
10199 Bugs: ProtocolBugs{
10200 EnableShortHeader: true,
10201 },
10202 },
10203 flags: []string{"-enable-short-header"},
10204 })
10205 testCases = append(testCases, testCase{
10206 testType: serverTest,
10207 name: "ShortHeader-TLS12-Server",
10208 config: Config{
10209 MaxVersion: VersionTLS12,
10210 Bugs: ProtocolBugs{
10211 EnableShortHeader: true,
10212 },
10213 },
10214 flags: []string{"-enable-short-header"},
10215 })
10216
10217 // Servers reject early data and short header sent together.
10218 testCases = append(testCases, testCase{
10219 testType: serverTest,
10220 name: "ShortHeader-EarlyData",
10221 config: Config{
10222 MaxVersion: VersionTLS13,
10223 Bugs: ProtocolBugs{
Nick Harperf2511f12016-12-06 16:02:31 -080010224 EnableShortHeader: true,
10225 SendFakeEarlyDataLength: 1,
David Benjamin6f600d62016-12-21 16:06:54 -050010226 },
10227 },
10228 flags: []string{"-enable-short-header"},
10229 shouldFail: true,
10230 expectedError: ":UNEXPECTED_EXTENSION:",
10231 })
10232
10233 // Clients reject unsolicited short header extensions.
10234 testCases = append(testCases, testCase{
10235 name: "ShortHeader-Unsolicited",
10236 config: Config{
10237 MaxVersion: VersionTLS13,
10238 Bugs: ProtocolBugs{
10239 AlwaysNegotiateShortHeader: true,
10240 },
10241 },
10242 shouldFail: true,
10243 expectedError: ":UNEXPECTED_EXTENSION:",
10244 })
10245 testCases = append(testCases, testCase{
10246 name: "ShortHeader-Unsolicited-TLS12",
10247 config: Config{
10248 MaxVersion: VersionTLS12,
10249 Bugs: ProtocolBugs{
10250 AlwaysNegotiateShortHeader: true,
10251 },
10252 },
10253 shouldFail: true,
10254 expectedError: ":UNEXPECTED_EXTENSION:",
10255 })
10256
10257 // The high bit must be checked in short headers.
10258 testCases = append(testCases, testCase{
10259 name: "ShortHeader-ClearShortHeaderBit",
10260 config: Config{
10261 Bugs: ProtocolBugs{
10262 EnableShortHeader: true,
10263 ClearShortHeaderBit: true,
10264 },
10265 },
10266 flags: []string{"-enable-short-header"},
10267 shouldFail: true,
10268 expectedError: ":DECODE_ERROR:",
10269 expectedLocalError: "remote error: error decoding message",
10270 })
10271}
10272
Adam Langley7c803a62015-06-15 15:35:05 -070010273func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -070010274 defer wg.Done()
10275
10276 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -080010277 var err error
10278
David Benjaminba28dfc2016-11-15 17:47:21 +090010279 if *mallocTest >= 0 {
Adam Langley69a01602014-11-17 17:26:55 -080010280 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
10281 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -070010282 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -080010283 if err != nil {
10284 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
10285 }
10286 break
10287 }
10288 }
David Benjaminba28dfc2016-11-15 17:47:21 +090010289 } else if *repeatUntilFailure {
10290 for err == nil {
10291 statusChan <- statusMsg{test: test, started: true}
10292 err = runTest(test, shimPath, -1)
10293 }
10294 } else {
10295 statusChan <- statusMsg{test: test, started: true}
10296 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -080010297 }
Adam Langley95c29f32014-06-20 12:00:00 -070010298 statusChan <- statusMsg{test: test, err: err}
10299 }
10300}
10301
10302type statusMsg struct {
10303 test *testCase
10304 started bool
10305 err error
10306}
10307
David Benjamin5f237bc2015-02-11 17:14:15 -050010308func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +020010309 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -070010310
David Benjamin5f237bc2015-02-11 17:14:15 -050010311 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -070010312 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -050010313 if !*pipe {
10314 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -050010315 var erase string
10316 for i := 0; i < lineLen; i++ {
10317 erase += "\b \b"
10318 }
10319 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -050010320 }
10321
Adam Langley95c29f32014-06-20 12:00:00 -070010322 if msg.started {
10323 started++
10324 } else {
10325 done++
David Benjamin5f237bc2015-02-11 17:14:15 -050010326
10327 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +020010328 if msg.err == errUnimplemented {
10329 if *pipe {
10330 // Print each test instead of a status line.
10331 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
10332 }
10333 unimplemented++
10334 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
10335 } else {
10336 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
10337 failed++
10338 testOutput.addResult(msg.test.name, "FAIL")
10339 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010340 } else {
10341 if *pipe {
10342 // Print each test instead of a status line.
10343 fmt.Printf("PASSED (%s)\n", msg.test.name)
10344 }
10345 testOutput.addResult(msg.test.name, "PASS")
10346 }
Adam Langley95c29f32014-06-20 12:00:00 -070010347 }
10348
David Benjamin5f237bc2015-02-11 17:14:15 -050010349 if !*pipe {
10350 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +020010351 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -050010352 lineLen = len(line)
10353 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -070010354 }
Adam Langley95c29f32014-06-20 12:00:00 -070010355 }
David Benjamin5f237bc2015-02-11 17:14:15 -050010356
10357 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -070010358}
10359
10360func main() {
Adam Langley95c29f32014-06-20 12:00:00 -070010361 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -070010362 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -070010363 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -070010364
Adam Langley7c803a62015-06-15 15:35:05 -070010365 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010366 addCipherSuiteTests()
10367 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -070010368 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -070010369 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -040010370 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -080010371 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -040010372 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -050010373 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -040010374 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -040010375 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -070010376 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -070010377 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -050010378 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -070010379 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -050010380 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -040010381 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -070010382 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -070010383 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -050010384 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -050010385 addCurveTests()
Steven Valdez5b986082016-09-01 12:29:49 -040010386 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -040010387 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -070010388 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -070010389 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -040010390 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -040010391 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -040010392 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -040010393 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -040010394 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -050010395 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +090010396 addCertificateTests()
David Benjaminbbaf3672016-11-17 10:53:09 +090010397 addRetainOnlySHA256ClientCertTests()
Adam Langleya4b91982016-12-12 12:05:53 -080010398 addECDSAKeyUsageTests()
David Benjamin6f600d62016-12-21 16:06:54 -050010399 addShortHeaderTests()
Adam Langley95c29f32014-06-20 12:00:00 -070010400
10401 var wg sync.WaitGroup
10402
Adam Langley7c803a62015-06-15 15:35:05 -070010403 statusChan := make(chan statusMsg, *numWorkers)
10404 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -050010405 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -070010406
EKRf71d7ed2016-08-06 13:25:12 -070010407 if len(*shimConfigFile) != 0 {
10408 encoded, err := ioutil.ReadFile(*shimConfigFile)
10409 if err != nil {
10410 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
10411 os.Exit(1)
10412 }
10413
10414 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
10415 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
10416 os.Exit(1)
10417 }
10418 }
10419
David Benjamin025b3d32014-07-01 19:53:04 -040010420 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -070010421
Adam Langley7c803a62015-06-15 15:35:05 -070010422 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -070010423 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -070010424 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -070010425 }
10426
David Benjamin270f0a72016-03-17 14:41:36 -040010427 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -040010428 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -040010429 matched := true
10430 if len(*testToRun) != 0 {
10431 var err error
10432 matched, err = filepath.Match(*testToRun, testCases[i].name)
10433 if err != nil {
10434 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
10435 os.Exit(1)
10436 }
10437 }
10438
EKRf71d7ed2016-08-06 13:25:12 -070010439 if !*includeDisabled {
10440 for pattern := range shimConfig.DisabledTests {
10441 isDisabled, err := filepath.Match(pattern, testCases[i].name)
10442 if err != nil {
10443 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
10444 os.Exit(1)
10445 }
10446
10447 if isDisabled {
10448 matched = false
10449 break
10450 }
10451 }
10452 }
10453
David Benjamin17e12922016-07-28 18:04:43 -040010454 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -040010455 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -040010456 testChan <- &testCases[i]
David Benjaminba28dfc2016-11-15 17:47:21 +090010457
10458 // Only run one test if repeating until failure.
10459 if *repeatUntilFailure {
10460 break
10461 }
Adam Langley95c29f32014-06-20 12:00:00 -070010462 }
10463 }
David Benjamin17e12922016-07-28 18:04:43 -040010464
David Benjamin270f0a72016-03-17 14:41:36 -040010465 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -070010466 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -040010467 os.Exit(1)
10468 }
Adam Langley95c29f32014-06-20 12:00:00 -070010469
10470 close(testChan)
10471 wg.Wait()
10472 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -050010473 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -070010474
10475 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -050010476
10477 if *jsonOutput != "" {
10478 if err := testOutput.writeTo(*jsonOutput); err != nil {
10479 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
10480 }
10481 }
David Benjamin2ab7a862015-04-04 17:02:18 -040010482
EKR842ae6c2016-07-27 09:22:05 +020010483 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
10484 os.Exit(1)
10485 }
10486
10487 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -040010488 os.Exit(1)
10489 }
Adam Langley95c29f32014-06-20 12:00:00 -070010490}