blob: 8f43e5cd73324c73e4a632e75fef42731e7aa78a [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"
David Benjamin407a10c2014-07-16 12:58:59 -040021 "crypto/x509"
David Benjamin2561dc32014-08-24 01:25:27 -040022 "encoding/base64"
EKRf71d7ed2016-08-06 13:25:12 -070023 "encoding/json"
David Benjamina08e49d2014-08-24 01:46:07 -040024 "encoding/pem"
EKR842ae6c2016-07-27 09:22:05 +020025 "errors"
Adam Langley95c29f32014-06-20 12:00:00 -070026 "flag"
27 "fmt"
28 "io"
Kenny Root7fdeaf12014-08-05 15:23:37 -070029 "io/ioutil"
Adam Langleya7997f12015-05-14 17:38:50 -070030 "math/big"
Adam Langley95c29f32014-06-20 12:00:00 -070031 "net"
32 "os"
33 "os/exec"
David Benjamin884fdf12014-08-02 15:28:23 -040034 "path"
David Benjamin17e12922016-07-28 18:04:43 -040035 "path/filepath"
David Benjamin2bc8e6f2014-08-02 15:22:37 -040036 "runtime"
Adam Langley69a01602014-11-17 17:26:55 -080037 "strconv"
Adam Langley95c29f32014-06-20 12:00:00 -070038 "strings"
39 "sync"
40 "syscall"
David Benjamin83f90402015-01-27 01:09:43 -050041 "time"
Adam Langley95c29f32014-06-20 12:00:00 -070042)
43
Adam Langley69a01602014-11-17 17:26:55 -080044var (
EKR842ae6c2016-07-27 09:22:05 +020045 useValgrind = flag.Bool("valgrind", false, "If true, run code under valgrind")
46 useGDB = flag.Bool("gdb", false, "If true, run BoringSSL code under gdb")
47 useLLDB = flag.Bool("lldb", false, "If true, run BoringSSL code under lldb")
48 flagDebug = flag.Bool("debug", false, "Hexdump the contents of the connection")
49 mallocTest = flag.Int64("malloc-test", -1, "If non-negative, run each test with each malloc in turn failing from the given number onwards.")
50 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.")
51 jsonOutput = flag.String("json-output", "", "The file to output JSON results to.")
52 pipe = flag.Bool("pipe", false, "If true, print status output suitable for piping into another program.")
David Benjamin17e12922016-07-28 18:04:43 -040053 testToRun = flag.String("test", "", "The pattern to filter tests to run, or empty to run all tests")
EKR842ae6c2016-07-27 09:22:05 +020054 numWorkers = flag.Int("num-workers", runtime.NumCPU(), "The number of workers to run in parallel.")
55 shimPath = flag.String("shim-path", "../../../build/ssl/test/bssl_shim", "The location of the shim binary.")
56 resourceDir = flag.String("resource-dir", ".", "The directory in which to find certificate and key files.")
57 fuzzer = flag.Bool("fuzzer", false, "If true, tests against a BoringSSL built in fuzzer mode.")
58 transcriptDir = flag.String("transcript-dir", "", "The directory in which to write transcripts.")
59 idleTimeout = flag.Duration("idle-timeout", 15*time.Second, "The number of seconds to wait for a read or write to bssl_shim.")
60 deterministic = flag.Bool("deterministic", false, "If true, uses a deterministic PRNG in the runner.")
61 allowUnimplemented = flag.Bool("allow-unimplemented", false, "If true, report pass even if some tests are unimplemented.")
EKR173bf932016-07-29 15:52:49 +020062 looseErrors = flag.Bool("loose-errors", false, "If true, allow shims to report an untranslated error code.")
EKRf71d7ed2016-08-06 13:25:12 -070063 shimConfigFile = flag.String("shim-config", "", "A config file to use to configure the tests for this shim.")
64 includeDisabled = flag.Bool("include-disabled", false, "If true, also runs disabled tests.")
Adam Langley69a01602014-11-17 17:26:55 -080065)
Adam Langley95c29f32014-06-20 12:00:00 -070066
EKRf71d7ed2016-08-06 13:25:12 -070067// ShimConfigurations is used with the “json” package and represents a shim
68// config file.
69type ShimConfiguration struct {
70 // DisabledTests maps from a glob-based pattern to a freeform string.
71 // The glob pattern is used to exclude tests from being run and the
72 // freeform string is unparsed but expected to explain why the test is
73 // disabled.
74 DisabledTests map[string]string
75
76 // ErrorMap maps from expected error strings to the correct error
77 // string for the shim in question. For example, it might map
78 // “:NO_SHARED_CIPHER:” (a BoringSSL error string) to something
79 // like “SSL_ERROR_NO_CYPHER_OVERLAP”.
80 ErrorMap map[string]string
81}
82
83var shimConfig ShimConfiguration
84
David Benjamin33863262016-07-08 17:20:12 -070085type testCert int
86
David Benjamin025b3d32014-07-01 19:53:04 -040087const (
David Benjamin33863262016-07-08 17:20:12 -070088 testCertRSA testCert = iota
David Benjamin7944a9f2016-07-12 22:27:01 -040089 testCertRSA1024
David Benjamin2c516452016-11-15 10:16:54 +090090 testCertRSAChain
David Benjamin33863262016-07-08 17:20:12 -070091 testCertECDSAP256
92 testCertECDSAP384
93 testCertECDSAP521
94)
95
96const (
97 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040098 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin2c516452016-11-15 10:16:54 +090099 rsaChainCertificateFile = "rsa_chain_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -0700100 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
101 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
102 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400103)
104
105const (
David Benjamina08e49d2014-08-24 01:46:07 -0400106 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400107 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin2c516452016-11-15 10:16:54 +0900108 rsaChainKeyFile = "rsa_chain_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700109 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
110 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
111 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400112 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400113)
114
David Benjamin7944a9f2016-07-12 22:27:01 -0400115var (
116 rsaCertificate Certificate
117 rsa1024Certificate Certificate
David Benjamin2c516452016-11-15 10:16:54 +0900118 rsaChainCertificate Certificate
David Benjamin7944a9f2016-07-12 22:27:01 -0400119 ecdsaP256Certificate Certificate
120 ecdsaP384Certificate Certificate
121 ecdsaP521Certificate Certificate
122)
David Benjamin33863262016-07-08 17:20:12 -0700123
124var testCerts = []struct {
125 id testCert
126 certFile, keyFile string
127 cert *Certificate
128}{
129 {
130 id: testCertRSA,
131 certFile: rsaCertificateFile,
132 keyFile: rsaKeyFile,
133 cert: &rsaCertificate,
134 },
135 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400136 id: testCertRSA1024,
137 certFile: rsa1024CertificateFile,
138 keyFile: rsa1024KeyFile,
139 cert: &rsa1024Certificate,
140 },
141 {
David Benjamin2c516452016-11-15 10:16:54 +0900142 id: testCertRSAChain,
143 certFile: rsaChainCertificateFile,
144 keyFile: rsaChainKeyFile,
145 cert: &rsaChainCertificate,
146 },
147 {
David Benjamin33863262016-07-08 17:20:12 -0700148 id: testCertECDSAP256,
149 certFile: ecdsaP256CertificateFile,
150 keyFile: ecdsaP256KeyFile,
151 cert: &ecdsaP256Certificate,
152 },
153 {
154 id: testCertECDSAP384,
155 certFile: ecdsaP384CertificateFile,
156 keyFile: ecdsaP384KeyFile,
157 cert: &ecdsaP384Certificate,
158 },
159 {
160 id: testCertECDSAP521,
161 certFile: ecdsaP521CertificateFile,
162 keyFile: ecdsaP521KeyFile,
163 cert: &ecdsaP521Certificate,
164 },
165}
166
David Benjamina08e49d2014-08-24 01:46:07 -0400167var channelIDKey *ecdsa.PrivateKey
168var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700169
David Benjamin61f95272014-11-25 01:55:35 -0500170var testOCSPResponse = []byte{1, 2, 3, 4}
171var testSCTList = []byte{5, 6, 7, 8}
172
Steven Valdeza833c352016-11-01 13:39:36 -0400173var testOCSPExtension = append([]byte{byte(extensionStatusRequest) >> 8, byte(extensionStatusRequest), 0, 8, statusTypeOCSP, 0, 0, 4}, testOCSPResponse...)
174var testSCTExtension = append([]byte{byte(extensionSignedCertificateTimestamp) >> 8, byte(extensionSignedCertificateTimestamp), 0, 4}, testSCTList...)
175
Adam Langley95c29f32014-06-20 12:00:00 -0700176func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700177 for i := range testCerts {
178 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
179 if err != nil {
180 panic(err)
181 }
182 cert.OCSPStaple = testOCSPResponse
183 cert.SignedCertificateTimestampList = testSCTList
184 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700185 }
David Benjamina08e49d2014-08-24 01:46:07 -0400186
Adam Langley7c803a62015-06-15 15:35:05 -0700187 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400188 if err != nil {
189 panic(err)
190 }
191 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
192 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
193 panic("bad key type")
194 }
195 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
196 if err != nil {
197 panic(err)
198 }
199 if channelIDKey.Curve != elliptic.P256() {
200 panic("bad curve")
201 }
202
203 channelIDBytes = make([]byte, 64)
204 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
205 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700206}
207
David Benjamin33863262016-07-08 17:20:12 -0700208func getRunnerCertificate(t testCert) Certificate {
209 for _, cert := range testCerts {
210 if cert.id == t {
211 return *cert.cert
212 }
213 }
214 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700215}
216
David Benjamin33863262016-07-08 17:20:12 -0700217func getShimCertificate(t testCert) string {
218 for _, cert := range testCerts {
219 if cert.id == t {
220 return cert.certFile
221 }
222 }
223 panic("Unknown test certificate")
224}
225
226func getShimKey(t testCert) string {
227 for _, cert := range testCerts {
228 if cert.id == t {
229 return cert.keyFile
230 }
231 }
232 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700233}
234
David Benjamin025b3d32014-07-01 19:53:04 -0400235type testType int
236
237const (
238 clientTest testType = iota
239 serverTest
240)
241
David Benjamin6fd297b2014-08-11 18:43:38 -0400242type protocol int
243
244const (
245 tls protocol = iota
246 dtls
247)
248
David Benjaminfc7b0862014-09-06 13:21:53 -0400249const (
250 alpn = 1
251 npn = 2
252)
253
Adam Langley95c29f32014-06-20 12:00:00 -0700254type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400255 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400256 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700257 name string
258 config Config
259 shouldFail bool
260 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700261 // expectedLocalError, if not empty, contains a substring that must be
262 // found in the local error.
263 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400264 // expectedVersion, if non-zero, specifies the TLS version that must be
265 // negotiated.
266 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400267 // expectedResumeVersion, if non-zero, specifies the TLS version that
268 // must be negotiated on resumption. If zero, expectedVersion is used.
269 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400270 // expectedCipher, if non-zero, specifies the TLS cipher suite that
271 // should be negotiated.
272 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400273 // expectChannelID controls whether the connection should have
274 // negotiated a Channel ID with channelIDKey.
275 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400276 // expectedNextProto controls whether the connection should
277 // negotiate a next protocol via NPN or ALPN.
278 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400279 // expectNoNextProto, if true, means that no next protocol should be
280 // negotiated.
281 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400282 // expectedNextProtoType, if non-zero, is the expected next
283 // protocol negotiation mechanism.
284 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500285 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
286 // should be negotiated. If zero, none should be negotiated.
287 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100288 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
289 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100290 // expectedSCTList, if not nil, is the expected SCT list to be received.
291 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700292 // expectedPeerSignatureAlgorithm, if not zero, is the signature
293 // algorithm that the peer should have used in the handshake.
294 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400295 // expectedCurveID, if not zero, is the curve that the handshake should
296 // have used.
297 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700298 // messageLen is the length, in bytes, of the test message that will be
299 // sent.
300 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400301 // messageCount is the number of test messages that will be sent.
302 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400303 // certFile is the path to the certificate to use for the server.
304 certFile string
305 // keyFile is the path to the private key to use for the server.
306 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400307 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400308 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400309 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400310 // resumeRenewedSession controls whether a third connection should be
311 // tested which attempts to resume the second connection's session.
312 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700313 // expectResumeRejected, if true, specifies that the attempted
314 // resumption must be rejected by the client. This is only valid for a
315 // serverTest.
316 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400317 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500318 // resumption. Unless newSessionsOnResume is set,
319 // SessionTicketKey, ServerSessionCache, and
320 // ClientSessionCache are copied from the initial connection's
321 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400322 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500323 // newSessionsOnResume, if true, will cause resumeConfig to
324 // use a different session resumption context.
325 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400326 // noSessionCache, if true, will cause the server to run without a
327 // session cache.
328 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400329 // sendPrefix sends a prefix on the socket before actually performing a
330 // handshake.
331 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400332 // shimWritesFirst controls whether the shim sends an initial "hello"
333 // message before doing a roundtrip with the runner.
334 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400335 // shimShutsDown, if true, runs a test where the shim shuts down the
336 // connection immediately after the handshake rather than echoing
337 // messages from the runner.
338 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400339 // renegotiate indicates the number of times the connection should be
340 // renegotiated during the exchange.
341 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400342 // sendHalfHelloRequest, if true, causes the server to send half a
343 // HelloRequest when the handshake completes.
344 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700345 // renegotiateCiphers is a list of ciphersuite ids that will be
346 // switched in just before renegotiation.
347 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500348 // replayWrites, if true, configures the underlying transport
349 // to replay every write it makes in DTLS tests.
350 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500351 // damageFirstWrite, if true, configures the underlying transport to
352 // damage the final byte of the first application data write.
353 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400354 // exportKeyingMaterial, if non-zero, configures the test to exchange
355 // keying material and verify they match.
356 exportKeyingMaterial int
357 exportLabel string
358 exportContext string
359 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400360 // flags, if not empty, contains a list of command-line flags that will
361 // be passed to the shim program.
362 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700363 // testTLSUnique, if true, causes the shim to send the tls-unique value
364 // which will be compared against the expected value.
365 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400366 // sendEmptyRecords is the number of consecutive empty records to send
367 // before and after the test message.
368 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400369 // sendWarningAlerts is the number of consecutive warning alerts to send
370 // before and after the test message.
371 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400372 // sendKeyUpdates is the number of consecutive key updates to send
373 // before and after the test message.
374 sendKeyUpdates int
Steven Valdezc4aa7272016-10-03 12:25:56 -0400375 // keyUpdateRequest is the KeyUpdateRequest value to send in KeyUpdate messages.
376 keyUpdateRequest byte
David Benjamin4f75aaf2015-09-01 16:53:10 -0400377 // expectMessageDropped, if true, means the test message is expected to
378 // be dropped by the client rather than echoed back.
379 expectMessageDropped bool
David Benjamin2c516452016-11-15 10:16:54 +0900380 // expectPeerCertificate, if not nil, is the certificate chain the peer
381 // is expected to send.
382 expectPeerCertificate *Certificate
Adam Langley95c29f32014-06-20 12:00:00 -0700383}
384
Adam Langley7c803a62015-06-15 15:35:05 -0700385var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700386
David Benjaminc07afb72016-09-22 10:18:58 -0400387func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500388 if len(data) == 0 {
389 return
390 }
391
392 protocol := "tls"
393 if test.protocol == dtls {
394 protocol = "dtls"
395 }
396
397 side := "client"
398 if test.testType == serverTest {
399 side = "server"
400 }
401
402 dir := path.Join(*transcriptDir, protocol, side)
403 if err := os.MkdirAll(dir, 0755); err != nil {
404 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
405 return
406 }
407
David Benjaminc07afb72016-09-22 10:18:58 -0400408 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500409 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
410 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
411 }
412}
413
David Benjamin3ed59772016-03-08 12:50:21 -0500414// A timeoutConn implements an idle timeout on each Read and Write operation.
415type timeoutConn struct {
416 net.Conn
417 timeout time.Duration
418}
419
420func (t *timeoutConn) Read(b []byte) (int, error) {
421 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
422 return 0, err
423 }
424 return t.Conn.Read(b)
425}
426
427func (t *timeoutConn) Write(b []byte) (int, error) {
428 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
429 return 0, err
430 }
431 return t.Conn.Write(b)
432}
433
David Benjaminc07afb72016-09-22 10:18:58 -0400434func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400435 if !test.noSessionCache {
436 if config.ClientSessionCache == nil {
437 config.ClientSessionCache = NewLRUClientSessionCache(1)
438 }
439 if config.ServerSessionCache == nil {
440 config.ServerSessionCache = NewLRUServerSessionCache(1)
441 }
442 }
443 if test.testType == clientTest {
444 if len(config.Certificates) == 0 {
445 config.Certificates = []Certificate{rsaCertificate}
446 }
447 } else {
448 // Supply a ServerName to ensure a constant session cache key,
449 // rather than falling back to net.Conn.RemoteAddr.
450 if len(config.ServerName) == 0 {
451 config.ServerName = "test"
452 }
453 }
454 if *fuzzer {
455 config.Bugs.NullAllCiphers = true
456 }
David Benjamin01a90572016-09-22 00:11:43 -0400457 if *deterministic {
458 config.Time = func() time.Time { return time.Unix(1234, 1234) }
459 }
David Benjamine54af062016-08-08 19:21:18 -0400460
David Benjamin01784b42016-06-07 18:00:52 -0400461 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500462
David Benjamin6fd297b2014-08-11 18:43:38 -0400463 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500464 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
465 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500466 }
467
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500469 local, peer := "client", "server"
470 if test.testType == clientTest {
471 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500472 }
David Benjaminebda9b32015-11-02 15:33:18 -0500473 connDebug := &recordingConn{
474 Conn: conn,
475 isDatagram: test.protocol == dtls,
476 local: local,
477 peer: peer,
478 }
479 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500480 if *flagDebug {
481 defer connDebug.WriteTo(os.Stdout)
482 }
483 if len(*transcriptDir) != 0 {
484 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400485 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500486 }()
487 }
David Benjaminebda9b32015-11-02 15:33:18 -0500488
489 if config.Bugs.PacketAdaptor != nil {
490 config.Bugs.PacketAdaptor.debug = connDebug
491 }
492 }
493
494 if test.replayWrites {
495 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400496 }
497
David Benjamin3ed59772016-03-08 12:50:21 -0500498 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500499 if test.damageFirstWrite {
500 connDamage = newDamageAdaptor(conn)
501 conn = connDamage
502 }
503
David Benjamin6fd297b2014-08-11 18:43:38 -0400504 if test.sendPrefix != "" {
505 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
506 return err
507 }
David Benjamin98e882e2014-08-08 13:24:34 -0400508 }
509
David Benjamin1d5c83e2014-07-22 19:20:02 -0400510 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400511 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400512 if test.protocol == dtls {
513 tlsConn = DTLSServer(conn, config)
514 } else {
515 tlsConn = Server(conn, config)
516 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400517 } else {
518 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400519 if test.protocol == dtls {
520 tlsConn = DTLSClient(conn, config)
521 } else {
522 tlsConn = Client(conn, config)
523 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400524 }
David Benjamin30789da2015-08-29 22:56:45 -0400525 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400526
Adam Langley95c29f32014-06-20 12:00:00 -0700527 if err := tlsConn.Handshake(); err != nil {
528 return err
529 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700530
David Benjamin01fe8202014-09-24 15:21:44 -0400531 // TODO(davidben): move all per-connection expectations into a dedicated
532 // expectations struct that can be specified separately for the two
533 // legs.
534 expectedVersion := test.expectedVersion
535 if isResume && test.expectedResumeVersion != 0 {
536 expectedVersion = test.expectedResumeVersion
537 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700538 connState := tlsConn.ConnectionState()
539 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400540 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400541 }
542
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700543 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400544 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
545 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700546 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
547 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
548 }
David Benjamin90da8c82015-04-20 14:57:57 -0400549
David Benjamina08e49d2014-08-24 01:46:07 -0400550 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700551 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400552 if channelID == nil {
553 return fmt.Errorf("no channel ID negotiated")
554 }
555 if channelID.Curve != channelIDKey.Curve ||
556 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
557 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
558 return fmt.Errorf("incorrect channel ID")
559 }
560 }
561
David Benjaminae2888f2014-09-06 12:58:58 -0400562 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700563 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400564 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
565 }
566 }
567
David Benjaminc7ce9772015-10-09 19:32:41 -0400568 if test.expectNoNextProto {
569 if actual := connState.NegotiatedProtocol; actual != "" {
570 return fmt.Errorf("got unexpected next proto %s", actual)
571 }
572 }
573
David Benjaminfc7b0862014-09-06 13:21:53 -0400574 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700575 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400576 return fmt.Errorf("next proto type mismatch")
577 }
578 }
579
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700580 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500581 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
582 }
583
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100584 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300585 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100586 }
587
Paul Lietar4fac72e2015-09-09 13:44:55 +0100588 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
589 return fmt.Errorf("SCT list mismatch")
590 }
591
Nick Harper60edffd2016-06-21 15:19:24 -0700592 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
593 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400594 }
595
Steven Valdez5440fe02016-07-18 12:40:30 -0400596 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
597 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
598 }
599
David Benjamin2c516452016-11-15 10:16:54 +0900600 if test.expectPeerCertificate != nil {
601 if len(connState.PeerCertificates) != len(test.expectPeerCertificate.Certificate) {
602 return fmt.Errorf("expected peer to send %d certificates, but got %d", len(connState.PeerCertificates), len(test.expectPeerCertificate.Certificate))
603 }
604 for i, cert := range connState.PeerCertificates {
605 if !bytes.Equal(cert.Raw, test.expectPeerCertificate.Certificate[i]) {
606 return fmt.Errorf("peer certificate %d did not match", i+1)
607 }
608 }
609 }
610
David Benjaminc565ebb2015-04-03 04:06:36 -0400611 if test.exportKeyingMaterial > 0 {
612 actual := make([]byte, test.exportKeyingMaterial)
613 if _, err := io.ReadFull(tlsConn, actual); err != nil {
614 return err
615 }
616 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
617 if err != nil {
618 return err
619 }
620 if !bytes.Equal(actual, expected) {
621 return fmt.Errorf("keying material mismatch")
622 }
623 }
624
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700625 if test.testTLSUnique {
626 var peersValue [12]byte
627 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
628 return err
629 }
630 expected := tlsConn.ConnectionState().TLSUnique
631 if !bytes.Equal(peersValue[:], expected) {
632 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
633 }
634 }
635
David Benjamine58c4f52014-08-24 03:47:07 -0400636 if test.shimWritesFirst {
637 var buf [5]byte
638 _, err := io.ReadFull(tlsConn, buf[:])
639 if err != nil {
640 return err
641 }
642 if string(buf[:]) != "hello" {
643 return fmt.Errorf("bad initial message")
644 }
645 }
646
Steven Valdez32635b82016-08-16 11:25:03 -0400647 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400648 if err := tlsConn.SendKeyUpdate(test.keyUpdateRequest); err != nil {
David Benjamin7f0965a2016-09-30 15:14:01 -0400649 return err
650 }
Steven Valdez32635b82016-08-16 11:25:03 -0400651 }
652
David Benjamina8ebe222015-06-06 03:04:39 -0400653 for i := 0; i < test.sendEmptyRecords; i++ {
654 tlsConn.Write(nil)
655 }
656
David Benjamin24f346d2015-06-06 03:28:08 -0400657 for i := 0; i < test.sendWarningAlerts; i++ {
658 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
659 }
660
David Benjamin47921102016-07-28 11:29:18 -0400661 if test.sendHalfHelloRequest {
662 tlsConn.SendHalfHelloRequest()
663 }
664
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400665 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700666 if test.renegotiateCiphers != nil {
667 config.CipherSuites = test.renegotiateCiphers
668 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400669 for i := 0; i < test.renegotiate; i++ {
670 if err := tlsConn.Renegotiate(); err != nil {
671 return err
672 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700673 }
674 } else if test.renegotiateCiphers != nil {
675 panic("renegotiateCiphers without renegotiate")
676 }
677
David Benjamin5fa3eba2015-01-22 16:35:40 -0500678 if test.damageFirstWrite {
679 connDamage.setDamage(true)
680 tlsConn.Write([]byte("DAMAGED WRITE"))
681 connDamage.setDamage(false)
682 }
683
David Benjamin8e6db492015-07-25 18:29:23 -0400684 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700685 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400686 if test.protocol == dtls {
687 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
688 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700689 // Read until EOF.
690 _, err := io.Copy(ioutil.Discard, tlsConn)
691 return err
692 }
David Benjamin4417d052015-04-05 04:17:25 -0400693 if messageLen == 0 {
694 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700695 }
Adam Langley95c29f32014-06-20 12:00:00 -0700696
David Benjamin8e6db492015-07-25 18:29:23 -0400697 messageCount := test.messageCount
698 if messageCount == 0 {
699 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400700 }
701
David Benjamin8e6db492015-07-25 18:29:23 -0400702 for j := 0; j < messageCount; j++ {
703 testMessage := make([]byte, messageLen)
704 for i := range testMessage {
705 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400706 }
David Benjamin8e6db492015-07-25 18:29:23 -0400707 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700708
Steven Valdez32635b82016-08-16 11:25:03 -0400709 for i := 0; i < test.sendKeyUpdates; i++ {
Steven Valdezc4aa7272016-10-03 12:25:56 -0400710 tlsConn.SendKeyUpdate(test.keyUpdateRequest)
Steven Valdez32635b82016-08-16 11:25:03 -0400711 }
712
David Benjamin8e6db492015-07-25 18:29:23 -0400713 for i := 0; i < test.sendEmptyRecords; i++ {
714 tlsConn.Write(nil)
715 }
716
717 for i := 0; i < test.sendWarningAlerts; i++ {
718 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
719 }
720
David Benjamin4f75aaf2015-09-01 16:53:10 -0400721 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400722 // The shim will not respond.
723 continue
724 }
725
David Benjamin8e6db492015-07-25 18:29:23 -0400726 buf := make([]byte, len(testMessage))
727 if test.protocol == dtls {
728 bufTmp := make([]byte, len(buf)+1)
729 n, err := tlsConn.Read(bufTmp)
730 if err != nil {
731 return err
732 }
733 if n != len(buf) {
734 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
735 }
736 copy(buf, bufTmp)
737 } else {
738 _, err := io.ReadFull(tlsConn, buf)
739 if err != nil {
740 return err
741 }
742 }
743
744 for i, v := range buf {
745 if v != testMessage[i]^0xff {
746 return fmt.Errorf("bad reply contents at byte %d", i)
747 }
Adam Langley95c29f32014-06-20 12:00:00 -0700748 }
749 }
750
751 return nil
752}
753
David Benjamin325b5c32014-07-01 19:40:31 -0400754func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400755 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700756 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400757 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700758 }
David Benjamin325b5c32014-07-01 19:40:31 -0400759 valgrindArgs = append(valgrindArgs, path)
760 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700761
David Benjamin325b5c32014-07-01 19:40:31 -0400762 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700763}
764
David Benjamin325b5c32014-07-01 19:40:31 -0400765func gdbOf(path string, args ...string) *exec.Cmd {
766 xtermArgs := []string{"-e", "gdb", "--args"}
767 xtermArgs = append(xtermArgs, path)
768 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700769
David Benjamin325b5c32014-07-01 19:40:31 -0400770 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700771}
772
David Benjamind16bf342015-12-18 00:53:12 -0500773func lldbOf(path string, args ...string) *exec.Cmd {
774 xtermArgs := []string{"-e", "lldb", "--"}
775 xtermArgs = append(xtermArgs, path)
776 xtermArgs = append(xtermArgs, args...)
777
778 return exec.Command("xterm", xtermArgs...)
779}
780
EKR842ae6c2016-07-27 09:22:05 +0200781var (
782 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
783 errUnimplemented = errors.New("child process does not implement needed flags")
784)
Adam Langley69a01602014-11-17 17:26:55 -0800785
David Benjamin87c8a642015-02-21 01:54:29 -0500786// accept accepts a connection from listener, unless waitChan signals a process
787// exit first.
788func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
789 type connOrError struct {
790 conn net.Conn
791 err error
792 }
793 connChan := make(chan connOrError, 1)
794 go func() {
795 conn, err := listener.Accept()
796 connChan <- connOrError{conn, err}
797 close(connChan)
798 }()
799 select {
800 case result := <-connChan:
801 return result.conn, result.err
802 case childErr := <-waitChan:
803 waitChan <- childErr
804 return nil, fmt.Errorf("child exited early: %s", childErr)
805 }
806}
807
EKRf71d7ed2016-08-06 13:25:12 -0700808func translateExpectedError(errorStr string) string {
809 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
810 return translated
811 }
812
813 if *looseErrors {
814 return ""
815 }
816
817 return errorStr
818}
819
Adam Langley7c803a62015-06-15 15:35:05 -0700820func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400821 // Help debugging panics on the Go side.
822 defer func() {
823 if r := recover(); r != nil {
824 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
825 panic(r)
826 }
827 }()
828
Adam Langley38311732014-10-16 19:04:35 -0700829 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
830 panic("Error expected without shouldFail in " + test.name)
831 }
832
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700833 if test.expectResumeRejected && !test.resumeSession {
834 panic("expectResumeRejected without resumeSession in " + test.name)
835 }
836
David Benjamin87c8a642015-02-21 01:54:29 -0500837 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
838 if err != nil {
839 panic(err)
840 }
841 defer func() {
842 if listener != nil {
843 listener.Close()
844 }
845 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700846
David Benjamin87c8a642015-02-21 01:54:29 -0500847 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400848 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400849 flags = append(flags, "-server")
850
David Benjamin025b3d32014-07-01 19:53:04 -0400851 flags = append(flags, "-key-file")
852 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700853 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400854 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700855 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400856 }
857
858 flags = append(flags, "-cert-file")
859 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700860 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400861 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700862 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400863 }
864 }
David Benjamin5a593af2014-08-11 19:51:50 -0400865
David Benjamin6fd297b2014-08-11 18:43:38 -0400866 if test.protocol == dtls {
867 flags = append(flags, "-dtls")
868 }
869
David Benjamin46662482016-08-17 00:51:00 -0400870 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400871 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400872 resumeCount++
873 if test.resumeRenewedSession {
874 resumeCount++
875 }
876 }
877
878 if resumeCount > 0 {
879 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400880 }
881
David Benjamine58c4f52014-08-24 03:47:07 -0400882 if test.shimWritesFirst {
883 flags = append(flags, "-shim-writes-first")
884 }
885
David Benjamin30789da2015-08-29 22:56:45 -0400886 if test.shimShutsDown {
887 flags = append(flags, "-shim-shuts-down")
888 }
889
David Benjaminc565ebb2015-04-03 04:06:36 -0400890 if test.exportKeyingMaterial > 0 {
891 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
892 flags = append(flags, "-export-label", test.exportLabel)
893 flags = append(flags, "-export-context", test.exportContext)
894 if test.useExportContext {
895 flags = append(flags, "-use-export-context")
896 }
897 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700898 if test.expectResumeRejected {
899 flags = append(flags, "-expect-session-miss")
900 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400901
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700902 if test.testTLSUnique {
903 flags = append(flags, "-tls-unique")
904 }
905
David Benjamin025b3d32014-07-01 19:53:04 -0400906 flags = append(flags, test.flags...)
907
908 var shim *exec.Cmd
909 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700910 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700911 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700912 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500913 } else if *useLLDB {
914 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400915 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700916 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400917 }
David Benjamin025b3d32014-07-01 19:53:04 -0400918 shim.Stdin = os.Stdin
919 var stdoutBuf, stderrBuf bytes.Buffer
920 shim.Stdout = &stdoutBuf
921 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800922 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500923 shim.Env = os.Environ()
924 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800925 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400926 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800927 }
928 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
929 }
David Benjamin025b3d32014-07-01 19:53:04 -0400930
931 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700932 panic(err)
933 }
David Benjamin87c8a642015-02-21 01:54:29 -0500934 waitChan := make(chan error, 1)
935 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700936
937 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700938
David Benjamin7a4aaa42016-09-20 17:58:14 -0400939 if *deterministic {
940 config.Rand = &deterministicRand{}
941 }
942
David Benjamin87c8a642015-02-21 01:54:29 -0500943 conn, err := acceptOrWait(listener, waitChan)
944 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400945 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500946 conn.Close()
947 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500948
David Benjamin46662482016-08-17 00:51:00 -0400949 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400950 var resumeConfig Config
951 if test.resumeConfig != nil {
952 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400953 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500954 resumeConfig.SessionTicketKey = config.SessionTicketKey
955 resumeConfig.ClientSessionCache = config.ClientSessionCache
956 resumeConfig.ServerSessionCache = config.ServerSessionCache
957 }
David Benjamin2e045a92016-06-08 13:09:56 -0400958 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400959 } else {
960 resumeConfig = config
961 }
David Benjamin87c8a642015-02-21 01:54:29 -0500962 var connResume net.Conn
963 connResume, err = acceptOrWait(listener, waitChan)
964 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400965 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500966 connResume.Close()
967 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400968 }
969
David Benjamin87c8a642015-02-21 01:54:29 -0500970 // Close the listener now. This is to avoid hangs should the shim try to
971 // open more connections than expected.
972 listener.Close()
973 listener = nil
974
975 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400976 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800977 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200978 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
979 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800980 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200981 case 89:
982 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400983 case 99:
984 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800985 }
986 }
Adam Langley95c29f32014-06-20 12:00:00 -0700987
David Benjamin9bea3492016-03-02 10:59:16 -0500988 // Account for Windows line endings.
989 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
990 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500991
992 // Separate the errors from the shim and those from tools like
993 // AddressSanitizer.
994 var extraStderr string
995 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
996 stderr = stderrParts[0]
997 extraStderr = stderrParts[1]
998 }
999
Adam Langley95c29f32014-06-20 12:00:00 -07001000 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -07001001 expectedError := translateExpectedError(test.expectedError)
1002 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +02001003
Adam Langleyac61fa32014-06-23 12:03:11 -07001004 localError := "none"
1005 if err != nil {
1006 localError = err.Error()
1007 }
1008 if len(test.expectedLocalError) != 0 {
1009 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
1010 }
Adam Langley95c29f32014-06-20 12:00:00 -07001011
1012 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -07001013 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -07001014 if childErr != nil {
1015 childError = childErr.Error()
1016 }
1017
1018 var msg string
1019 switch {
1020 case failed && !test.shouldFail:
1021 msg = "unexpected failure"
1022 case !failed && test.shouldFail:
1023 msg = "unexpected success"
1024 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -07001025 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -07001026 default:
1027 panic("internal error")
1028 }
1029
David Benjamin9aafb642016-09-20 19:36:53 -04001030 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 -07001031 }
1032
David Benjamind2ba8892016-09-20 19:41:04 -04001033 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001034 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001035 }
1036
David Benjamind2ba8892016-09-20 19:41:04 -04001037 if *useValgrind && isValgrindError {
1038 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1039 }
1040
Adam Langley95c29f32014-06-20 12:00:00 -07001041 return nil
1042}
1043
1044var tlsVersions = []struct {
1045 name string
1046 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001047 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001048 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001049}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001050 {"SSL3", VersionSSL30, "-no-ssl3", false},
1051 {"TLS1", VersionTLS10, "-no-tls1", true},
1052 {"TLS11", VersionTLS11, "-no-tls11", false},
1053 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001054 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001055}
1056
1057var testCipherSuites = []struct {
1058 name string
1059 id uint16
1060}{
1061 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001062 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001063 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001064 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001065 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001066 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001067 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001068 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1069 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001070 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001071 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1072 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001073 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001074 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1075 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001076 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1077 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001078 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001079 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001080 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001081 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001082 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001083 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001084 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001085 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001086 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001087 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001088 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001089 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001090 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1091 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1092 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1093 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001094 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1095 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001096 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1097 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001098 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001099 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1100 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1101 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001102 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001103}
1104
David Benjamin8b8c0062014-11-23 02:47:52 -05001105func hasComponent(suiteName, component string) bool {
1106 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1107}
1108
David Benjaminf7768e42014-08-31 02:06:47 -04001109func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001110 return hasComponent(suiteName, "GCM") ||
1111 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001112 hasComponent(suiteName, "SHA384") ||
1113 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001114}
1115
Nick Harper1fd39d82016-06-14 18:14:35 -07001116func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001117 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001118}
1119
David Benjamin8b8c0062014-11-23 02:47:52 -05001120func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001121 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001122}
1123
Adam Langleya7997f12015-05-14 17:38:50 -07001124func bigFromHex(hex string) *big.Int {
1125 ret, ok := new(big.Int).SetString(hex, 16)
1126 if !ok {
1127 panic("failed to parse hex number 0x" + hex)
1128 }
1129 return ret
1130}
1131
Adam Langley7c803a62015-06-15 15:35:05 -07001132func addBasicTests() {
1133 basicTests := []testCase{
1134 {
Adam Langley7c803a62015-06-15 15:35:05 -07001135 name: "NoFallbackSCSV",
1136 config: Config{
1137 Bugs: ProtocolBugs{
1138 FailIfNotFallbackSCSV: true,
1139 },
1140 },
1141 shouldFail: true,
1142 expectedLocalError: "no fallback SCSV found",
1143 },
1144 {
1145 name: "SendFallbackSCSV",
1146 config: Config{
1147 Bugs: ProtocolBugs{
1148 FailIfNotFallbackSCSV: true,
1149 },
1150 },
1151 flags: []string{"-fallback-scsv"},
1152 },
1153 {
1154 name: "ClientCertificateTypes",
1155 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001156 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001157 ClientAuth: RequestClientCert,
1158 ClientCertificateTypes: []byte{
1159 CertTypeDSSSign,
1160 CertTypeRSASign,
1161 CertTypeECDSASign,
1162 },
1163 },
1164 flags: []string{
1165 "-expect-certificate-types",
1166 base64.StdEncoding.EncodeToString([]byte{
1167 CertTypeDSSSign,
1168 CertTypeRSASign,
1169 CertTypeECDSASign,
1170 }),
1171 },
1172 },
1173 {
Adam Langley7c803a62015-06-15 15:35:05 -07001174 name: "UnauthenticatedECDH",
1175 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001176 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001177 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1178 Bugs: ProtocolBugs{
1179 UnauthenticatedECDH: true,
1180 },
1181 },
1182 shouldFail: true,
1183 expectedError: ":UNEXPECTED_MESSAGE:",
1184 },
1185 {
1186 name: "SkipCertificateStatus",
1187 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001188 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001189 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1190 Bugs: ProtocolBugs{
1191 SkipCertificateStatus: true,
1192 },
1193 },
1194 flags: []string{
1195 "-enable-ocsp-stapling",
1196 },
1197 },
1198 {
1199 name: "SkipServerKeyExchange",
1200 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001201 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001202 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1203 Bugs: ProtocolBugs{
1204 SkipServerKeyExchange: true,
1205 },
1206 },
1207 shouldFail: true,
1208 expectedError: ":UNEXPECTED_MESSAGE:",
1209 },
1210 {
Adam Langley7c803a62015-06-15 15:35:05 -07001211 testType: serverTest,
1212 name: "Alert",
1213 config: Config{
1214 Bugs: ProtocolBugs{
1215 SendSpuriousAlert: alertRecordOverflow,
1216 },
1217 },
1218 shouldFail: true,
1219 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1220 },
1221 {
1222 protocol: dtls,
1223 testType: serverTest,
1224 name: "Alert-DTLS",
1225 config: Config{
1226 Bugs: ProtocolBugs{
1227 SendSpuriousAlert: alertRecordOverflow,
1228 },
1229 },
1230 shouldFail: true,
1231 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1232 },
1233 {
1234 testType: serverTest,
1235 name: "FragmentAlert",
1236 config: Config{
1237 Bugs: ProtocolBugs{
1238 FragmentAlert: true,
1239 SendSpuriousAlert: alertRecordOverflow,
1240 },
1241 },
1242 shouldFail: true,
1243 expectedError: ":BAD_ALERT:",
1244 },
1245 {
1246 protocol: dtls,
1247 testType: serverTest,
1248 name: "FragmentAlert-DTLS",
1249 config: Config{
1250 Bugs: ProtocolBugs{
1251 FragmentAlert: true,
1252 SendSpuriousAlert: alertRecordOverflow,
1253 },
1254 },
1255 shouldFail: true,
1256 expectedError: ":BAD_ALERT:",
1257 },
1258 {
1259 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001260 name: "DoubleAlert",
1261 config: Config{
1262 Bugs: ProtocolBugs{
1263 DoubleAlert: true,
1264 SendSpuriousAlert: alertRecordOverflow,
1265 },
1266 },
1267 shouldFail: true,
1268 expectedError: ":BAD_ALERT:",
1269 },
1270 {
1271 protocol: dtls,
1272 testType: serverTest,
1273 name: "DoubleAlert-DTLS",
1274 config: Config{
1275 Bugs: ProtocolBugs{
1276 DoubleAlert: true,
1277 SendSpuriousAlert: alertRecordOverflow,
1278 },
1279 },
1280 shouldFail: true,
1281 expectedError: ":BAD_ALERT:",
1282 },
1283 {
Adam Langley7c803a62015-06-15 15:35:05 -07001284 name: "SkipNewSessionTicket",
1285 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001286 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001287 Bugs: ProtocolBugs{
1288 SkipNewSessionTicket: true,
1289 },
1290 },
1291 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001292 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001293 },
1294 {
1295 testType: serverTest,
1296 name: "FallbackSCSV",
1297 config: Config{
1298 MaxVersion: VersionTLS11,
1299 Bugs: ProtocolBugs{
1300 SendFallbackSCSV: true,
1301 },
1302 },
1303 shouldFail: true,
1304 expectedError: ":INAPPROPRIATE_FALLBACK:",
1305 },
1306 {
1307 testType: serverTest,
1308 name: "FallbackSCSV-VersionMatch",
1309 config: Config{
1310 Bugs: ProtocolBugs{
1311 SendFallbackSCSV: true,
1312 },
1313 },
1314 },
1315 {
1316 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001317 name: "FallbackSCSV-VersionMatch-TLS12",
1318 config: Config{
1319 MaxVersion: VersionTLS12,
1320 Bugs: ProtocolBugs{
1321 SendFallbackSCSV: true,
1322 },
1323 },
1324 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1325 },
1326 {
1327 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001328 name: "FragmentedClientVersion",
1329 config: Config{
1330 Bugs: ProtocolBugs{
1331 MaxHandshakeRecordLength: 1,
1332 FragmentClientVersion: true,
1333 },
1334 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001335 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001336 },
1337 {
Adam Langley7c803a62015-06-15 15:35:05 -07001338 testType: serverTest,
1339 name: "HttpGET",
1340 sendPrefix: "GET / HTTP/1.0\n",
1341 shouldFail: true,
1342 expectedError: ":HTTP_REQUEST:",
1343 },
1344 {
1345 testType: serverTest,
1346 name: "HttpPOST",
1347 sendPrefix: "POST / HTTP/1.0\n",
1348 shouldFail: true,
1349 expectedError: ":HTTP_REQUEST:",
1350 },
1351 {
1352 testType: serverTest,
1353 name: "HttpHEAD",
1354 sendPrefix: "HEAD / HTTP/1.0\n",
1355 shouldFail: true,
1356 expectedError: ":HTTP_REQUEST:",
1357 },
1358 {
1359 testType: serverTest,
1360 name: "HttpPUT",
1361 sendPrefix: "PUT / HTTP/1.0\n",
1362 shouldFail: true,
1363 expectedError: ":HTTP_REQUEST:",
1364 },
1365 {
1366 testType: serverTest,
1367 name: "HttpCONNECT",
1368 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1369 shouldFail: true,
1370 expectedError: ":HTTPS_PROXY_REQUEST:",
1371 },
1372 {
1373 testType: serverTest,
1374 name: "Garbage",
1375 sendPrefix: "blah",
1376 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001377 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001378 },
1379 {
Adam Langley7c803a62015-06-15 15:35:05 -07001380 name: "RSAEphemeralKey",
1381 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001382 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001383 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1384 Bugs: ProtocolBugs{
1385 RSAEphemeralKey: true,
1386 },
1387 },
1388 shouldFail: true,
1389 expectedError: ":UNEXPECTED_MESSAGE:",
1390 },
1391 {
1392 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001393 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001394 shouldFail: true,
1395 expectedError: ":WRONG_SSL_VERSION:",
1396 },
1397 {
1398 protocol: dtls,
1399 name: "DisableEverything-DTLS",
1400 flags: []string{"-no-tls12", "-no-tls1"},
1401 shouldFail: true,
1402 expectedError: ":WRONG_SSL_VERSION:",
1403 },
1404 {
Adam Langley7c803a62015-06-15 15:35:05 -07001405 protocol: dtls,
1406 testType: serverTest,
1407 name: "MTU",
1408 config: Config{
1409 Bugs: ProtocolBugs{
1410 MaxPacketLength: 256,
1411 },
1412 },
1413 flags: []string{"-mtu", "256"},
1414 },
1415 {
1416 protocol: dtls,
1417 testType: serverTest,
1418 name: "MTUExceeded",
1419 config: Config{
1420 Bugs: ProtocolBugs{
1421 MaxPacketLength: 255,
1422 },
1423 },
1424 flags: []string{"-mtu", "256"},
1425 shouldFail: true,
1426 expectedLocalError: "dtls: exceeded maximum packet length",
1427 },
1428 {
1429 name: "CertMismatchRSA",
1430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001431 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001432 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001433 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001434 Bugs: ProtocolBugs{
1435 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1436 },
1437 },
1438 shouldFail: true,
1439 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1440 },
1441 {
1442 name: "CertMismatchECDSA",
1443 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001444 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001445 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001446 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001447 Bugs: ProtocolBugs{
1448 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1449 },
1450 },
1451 shouldFail: true,
1452 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1453 },
1454 {
1455 name: "EmptyCertificateList",
1456 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001457 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001458 Bugs: ProtocolBugs{
1459 EmptyCertificateList: true,
1460 },
1461 },
1462 shouldFail: true,
1463 expectedError: ":DECODE_ERROR:",
1464 },
1465 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001466 name: "EmptyCertificateList-TLS13",
1467 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001468 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001469 Bugs: ProtocolBugs{
1470 EmptyCertificateList: true,
1471 },
1472 },
1473 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001474 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001475 },
1476 {
Adam Langley7c803a62015-06-15 15:35:05 -07001477 name: "TLSFatalBadPackets",
1478 damageFirstWrite: true,
1479 shouldFail: true,
1480 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1481 },
1482 {
1483 protocol: dtls,
1484 name: "DTLSIgnoreBadPackets",
1485 damageFirstWrite: true,
1486 },
1487 {
1488 protocol: dtls,
1489 name: "DTLSIgnoreBadPackets-Async",
1490 damageFirstWrite: true,
1491 flags: []string{"-async"},
1492 },
1493 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001494 name: "AppDataBeforeHandshake",
1495 config: Config{
1496 Bugs: ProtocolBugs{
1497 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1498 },
1499 },
1500 shouldFail: true,
1501 expectedError: ":UNEXPECTED_RECORD:",
1502 },
1503 {
1504 name: "AppDataBeforeHandshake-Empty",
1505 config: Config{
1506 Bugs: ProtocolBugs{
1507 AppDataBeforeHandshake: []byte{},
1508 },
1509 },
1510 shouldFail: true,
1511 expectedError: ":UNEXPECTED_RECORD:",
1512 },
1513 {
1514 protocol: dtls,
1515 name: "AppDataBeforeHandshake-DTLS",
1516 config: Config{
1517 Bugs: ProtocolBugs{
1518 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1519 },
1520 },
1521 shouldFail: true,
1522 expectedError: ":UNEXPECTED_RECORD:",
1523 },
1524 {
1525 protocol: dtls,
1526 name: "AppDataBeforeHandshake-DTLS-Empty",
1527 config: Config{
1528 Bugs: ProtocolBugs{
1529 AppDataBeforeHandshake: []byte{},
1530 },
1531 },
1532 shouldFail: true,
1533 expectedError: ":UNEXPECTED_RECORD:",
1534 },
1535 {
Adam Langley7c803a62015-06-15 15:35:05 -07001536 name: "AppDataAfterChangeCipherSpec",
1537 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001538 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001539 Bugs: ProtocolBugs{
1540 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1541 },
1542 },
1543 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001544 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001545 },
1546 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001547 name: "AppDataAfterChangeCipherSpec-Empty",
1548 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001549 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001550 Bugs: ProtocolBugs{
1551 AppDataAfterChangeCipherSpec: []byte{},
1552 },
1553 },
1554 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001555 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001556 },
1557 {
Adam Langley7c803a62015-06-15 15:35:05 -07001558 protocol: dtls,
1559 name: "AppDataAfterChangeCipherSpec-DTLS",
1560 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001561 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001562 Bugs: ProtocolBugs{
1563 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1564 },
1565 },
1566 // BoringSSL's DTLS implementation will drop the out-of-order
1567 // application data.
1568 },
1569 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001570 protocol: dtls,
1571 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1572 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001573 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001574 Bugs: ProtocolBugs{
1575 AppDataAfterChangeCipherSpec: []byte{},
1576 },
1577 },
1578 // BoringSSL's DTLS implementation will drop the out-of-order
1579 // application data.
1580 },
1581 {
Adam Langley7c803a62015-06-15 15:35:05 -07001582 name: "AlertAfterChangeCipherSpec",
1583 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001584 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001585 Bugs: ProtocolBugs{
1586 AlertAfterChangeCipherSpec: alertRecordOverflow,
1587 },
1588 },
1589 shouldFail: true,
1590 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1591 },
1592 {
1593 protocol: dtls,
1594 name: "AlertAfterChangeCipherSpec-DTLS",
1595 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001596 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001597 Bugs: ProtocolBugs{
1598 AlertAfterChangeCipherSpec: alertRecordOverflow,
1599 },
1600 },
1601 shouldFail: true,
1602 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1603 },
1604 {
1605 protocol: dtls,
1606 name: "ReorderHandshakeFragments-Small-DTLS",
1607 config: Config{
1608 Bugs: ProtocolBugs{
1609 ReorderHandshakeFragments: true,
1610 // Small enough that every handshake message is
1611 // fragmented.
1612 MaxHandshakeRecordLength: 2,
1613 },
1614 },
1615 },
1616 {
1617 protocol: dtls,
1618 name: "ReorderHandshakeFragments-Large-DTLS",
1619 config: Config{
1620 Bugs: ProtocolBugs{
1621 ReorderHandshakeFragments: true,
1622 // Large enough that no handshake message is
1623 // fragmented.
1624 MaxHandshakeRecordLength: 2048,
1625 },
1626 },
1627 },
1628 {
1629 protocol: dtls,
1630 name: "MixCompleteMessageWithFragments-DTLS",
1631 config: Config{
1632 Bugs: ProtocolBugs{
1633 ReorderHandshakeFragments: true,
1634 MixCompleteMessageWithFragments: true,
1635 MaxHandshakeRecordLength: 2,
1636 },
1637 },
1638 },
1639 {
1640 name: "SendInvalidRecordType",
1641 config: Config{
1642 Bugs: ProtocolBugs{
1643 SendInvalidRecordType: true,
1644 },
1645 },
1646 shouldFail: true,
1647 expectedError: ":UNEXPECTED_RECORD:",
1648 },
1649 {
1650 protocol: dtls,
1651 name: "SendInvalidRecordType-DTLS",
1652 config: Config{
1653 Bugs: ProtocolBugs{
1654 SendInvalidRecordType: true,
1655 },
1656 },
1657 shouldFail: true,
1658 expectedError: ":UNEXPECTED_RECORD:",
1659 },
1660 {
1661 name: "FalseStart-SkipServerSecondLeg",
1662 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001663 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001664 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1665 NextProtos: []string{"foo"},
1666 Bugs: ProtocolBugs{
1667 SkipNewSessionTicket: true,
1668 SkipChangeCipherSpec: true,
1669 SkipFinished: true,
1670 ExpectFalseStart: true,
1671 },
1672 },
1673 flags: []string{
1674 "-false-start",
1675 "-handshake-never-done",
1676 "-advertise-alpn", "\x03foo",
1677 },
1678 shimWritesFirst: true,
1679 shouldFail: true,
1680 expectedError: ":UNEXPECTED_RECORD:",
1681 },
1682 {
1683 name: "FalseStart-SkipServerSecondLeg-Implicit",
1684 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001685 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001686 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1687 NextProtos: []string{"foo"},
1688 Bugs: ProtocolBugs{
1689 SkipNewSessionTicket: true,
1690 SkipChangeCipherSpec: true,
1691 SkipFinished: true,
1692 },
1693 },
1694 flags: []string{
1695 "-implicit-handshake",
1696 "-false-start",
1697 "-handshake-never-done",
1698 "-advertise-alpn", "\x03foo",
1699 },
1700 shouldFail: true,
1701 expectedError: ":UNEXPECTED_RECORD:",
1702 },
1703 {
1704 testType: serverTest,
1705 name: "FailEarlyCallback",
1706 flags: []string{"-fail-early-callback"},
1707 shouldFail: true,
1708 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001709 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001710 },
1711 {
David Benjaminb8d74f52016-11-14 22:02:50 +09001712 name: "FailCertCallback-Client-TLS12",
1713 config: Config{
1714 MaxVersion: VersionTLS12,
1715 ClientAuth: RequestClientCert,
1716 },
1717 flags: []string{"-fail-cert-callback"},
1718 shouldFail: true,
1719 expectedError: ":CERT_CB_ERROR:",
1720 expectedLocalError: "remote error: internal error",
1721 },
1722 {
1723 testType: serverTest,
1724 name: "FailCertCallback-Server-TLS12",
1725 config: Config{
1726 MaxVersion: VersionTLS12,
1727 },
1728 flags: []string{"-fail-cert-callback"},
1729 shouldFail: true,
1730 expectedError: ":CERT_CB_ERROR:",
1731 expectedLocalError: "remote error: internal error",
1732 },
1733 {
1734 name: "FailCertCallback-Client-TLS13",
1735 config: Config{
1736 MaxVersion: VersionTLS13,
1737 ClientAuth: RequestClientCert,
1738 },
1739 flags: []string{"-fail-cert-callback"},
1740 shouldFail: true,
1741 expectedError: ":CERT_CB_ERROR:",
1742 expectedLocalError: "remote error: internal error",
1743 },
1744 {
1745 testType: serverTest,
1746 name: "FailCertCallback-Server-TLS13",
1747 config: Config{
1748 MaxVersion: VersionTLS13,
1749 },
1750 flags: []string{"-fail-cert-callback"},
1751 shouldFail: true,
1752 expectedError: ":CERT_CB_ERROR:",
1753 expectedLocalError: "remote error: internal error",
1754 },
1755 {
Adam Langley7c803a62015-06-15 15:35:05 -07001756 protocol: dtls,
1757 name: "FragmentMessageTypeMismatch-DTLS",
1758 config: Config{
1759 Bugs: ProtocolBugs{
1760 MaxHandshakeRecordLength: 2,
1761 FragmentMessageTypeMismatch: true,
1762 },
1763 },
1764 shouldFail: true,
1765 expectedError: ":FRAGMENT_MISMATCH:",
1766 },
1767 {
1768 protocol: dtls,
1769 name: "FragmentMessageLengthMismatch-DTLS",
1770 config: Config{
1771 Bugs: ProtocolBugs{
1772 MaxHandshakeRecordLength: 2,
1773 FragmentMessageLengthMismatch: true,
1774 },
1775 },
1776 shouldFail: true,
1777 expectedError: ":FRAGMENT_MISMATCH:",
1778 },
1779 {
1780 protocol: dtls,
1781 name: "SplitFragments-Header-DTLS",
1782 config: Config{
1783 Bugs: ProtocolBugs{
1784 SplitFragments: 2,
1785 },
1786 },
1787 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001788 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001789 },
1790 {
1791 protocol: dtls,
1792 name: "SplitFragments-Boundary-DTLS",
1793 config: Config{
1794 Bugs: ProtocolBugs{
1795 SplitFragments: dtlsRecordHeaderLen,
1796 },
1797 },
1798 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001799 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001800 },
1801 {
1802 protocol: dtls,
1803 name: "SplitFragments-Body-DTLS",
1804 config: Config{
1805 Bugs: ProtocolBugs{
1806 SplitFragments: dtlsRecordHeaderLen + 1,
1807 },
1808 },
1809 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001810 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001811 },
1812 {
1813 protocol: dtls,
1814 name: "SendEmptyFragments-DTLS",
1815 config: Config{
1816 Bugs: ProtocolBugs{
1817 SendEmptyFragments: true,
1818 },
1819 },
1820 },
1821 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001822 name: "BadFinished-Client",
1823 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001824 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001825 Bugs: ProtocolBugs{
1826 BadFinished: true,
1827 },
1828 },
1829 shouldFail: true,
1830 expectedError: ":DIGEST_CHECK_FAILED:",
1831 },
1832 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001833 name: "BadFinished-Client-TLS13",
1834 config: Config{
1835 MaxVersion: VersionTLS13,
1836 Bugs: ProtocolBugs{
1837 BadFinished: true,
1838 },
1839 },
1840 shouldFail: true,
1841 expectedError: ":DIGEST_CHECK_FAILED:",
1842 },
1843 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001844 testType: serverTest,
1845 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001846 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001847 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001848 Bugs: ProtocolBugs{
1849 BadFinished: true,
1850 },
1851 },
1852 shouldFail: true,
1853 expectedError: ":DIGEST_CHECK_FAILED:",
1854 },
1855 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001856 testType: serverTest,
1857 name: "BadFinished-Server-TLS13",
1858 config: Config{
1859 MaxVersion: VersionTLS13,
1860 Bugs: ProtocolBugs{
1861 BadFinished: true,
1862 },
1863 },
1864 shouldFail: true,
1865 expectedError: ":DIGEST_CHECK_FAILED:",
1866 },
1867 {
Adam Langley7c803a62015-06-15 15:35:05 -07001868 name: "FalseStart-BadFinished",
1869 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001870 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1872 NextProtos: []string{"foo"},
1873 Bugs: ProtocolBugs{
1874 BadFinished: true,
1875 ExpectFalseStart: true,
1876 },
1877 },
1878 flags: []string{
1879 "-false-start",
1880 "-handshake-never-done",
1881 "-advertise-alpn", "\x03foo",
1882 },
1883 shimWritesFirst: true,
1884 shouldFail: true,
1885 expectedError: ":DIGEST_CHECK_FAILED:",
1886 },
1887 {
1888 name: "NoFalseStart-NoALPN",
1889 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001890 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001891 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1892 Bugs: ProtocolBugs{
1893 ExpectFalseStart: true,
1894 AlertBeforeFalseStartTest: alertAccessDenied,
1895 },
1896 },
1897 flags: []string{
1898 "-false-start",
1899 },
1900 shimWritesFirst: true,
1901 shouldFail: true,
1902 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1903 expectedLocalError: "tls: peer did not false start: EOF",
1904 },
1905 {
1906 name: "NoFalseStart-NoAEAD",
1907 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001908 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001909 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1910 NextProtos: []string{"foo"},
1911 Bugs: ProtocolBugs{
1912 ExpectFalseStart: true,
1913 AlertBeforeFalseStartTest: alertAccessDenied,
1914 },
1915 },
1916 flags: []string{
1917 "-false-start",
1918 "-advertise-alpn", "\x03foo",
1919 },
1920 shimWritesFirst: true,
1921 shouldFail: true,
1922 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1923 expectedLocalError: "tls: peer did not false start: EOF",
1924 },
1925 {
1926 name: "NoFalseStart-RSA",
1927 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001928 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001929 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1930 NextProtos: []string{"foo"},
1931 Bugs: ProtocolBugs{
1932 ExpectFalseStart: true,
1933 AlertBeforeFalseStartTest: alertAccessDenied,
1934 },
1935 },
1936 flags: []string{
1937 "-false-start",
1938 "-advertise-alpn", "\x03foo",
1939 },
1940 shimWritesFirst: true,
1941 shouldFail: true,
1942 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1943 expectedLocalError: "tls: peer did not false start: EOF",
1944 },
1945 {
1946 name: "NoFalseStart-DHE_RSA",
1947 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001948 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001949 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1950 NextProtos: []string{"foo"},
1951 Bugs: ProtocolBugs{
1952 ExpectFalseStart: true,
1953 AlertBeforeFalseStartTest: alertAccessDenied,
1954 },
1955 },
1956 flags: []string{
1957 "-false-start",
1958 "-advertise-alpn", "\x03foo",
1959 },
1960 shimWritesFirst: true,
1961 shouldFail: true,
1962 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1963 expectedLocalError: "tls: peer did not false start: EOF",
1964 },
1965 {
Adam Langley7c803a62015-06-15 15:35:05 -07001966 protocol: dtls,
1967 name: "SendSplitAlert-Sync",
1968 config: Config{
1969 Bugs: ProtocolBugs{
1970 SendSplitAlert: true,
1971 },
1972 },
1973 },
1974 {
1975 protocol: dtls,
1976 name: "SendSplitAlert-Async",
1977 config: Config{
1978 Bugs: ProtocolBugs{
1979 SendSplitAlert: true,
1980 },
1981 },
1982 flags: []string{"-async"},
1983 },
1984 {
1985 protocol: dtls,
1986 name: "PackDTLSHandshake",
1987 config: Config{
1988 Bugs: ProtocolBugs{
1989 MaxHandshakeRecordLength: 2,
1990 PackHandshakeFragments: 20,
1991 PackHandshakeRecords: 200,
1992 },
1993 },
1994 },
1995 {
Adam Langley7c803a62015-06-15 15:35:05 -07001996 name: "SendEmptyRecords-Pass",
1997 sendEmptyRecords: 32,
1998 },
1999 {
2000 name: "SendEmptyRecords",
2001 sendEmptyRecords: 33,
2002 shouldFail: true,
2003 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2004 },
2005 {
2006 name: "SendEmptyRecords-Async",
2007 sendEmptyRecords: 33,
2008 flags: []string{"-async"},
2009 shouldFail: true,
2010 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
2011 },
2012 {
David Benjamine8e84b92016-08-03 15:39:47 -04002013 name: "SendWarningAlerts-Pass",
2014 config: Config{
2015 MaxVersion: VersionTLS12,
2016 },
Adam Langley7c803a62015-06-15 15:35:05 -07002017 sendWarningAlerts: 4,
2018 },
2019 {
David Benjamine8e84b92016-08-03 15:39:47 -04002020 protocol: dtls,
2021 name: "SendWarningAlerts-DTLS-Pass",
2022 config: Config{
2023 MaxVersion: VersionTLS12,
2024 },
Adam Langley7c803a62015-06-15 15:35:05 -07002025 sendWarningAlerts: 4,
2026 },
2027 {
David Benjamine8e84b92016-08-03 15:39:47 -04002028 name: "SendWarningAlerts-TLS13",
2029 config: Config{
2030 MaxVersion: VersionTLS13,
2031 },
2032 sendWarningAlerts: 4,
2033 shouldFail: true,
2034 expectedError: ":BAD_ALERT:",
2035 expectedLocalError: "remote error: error decoding message",
2036 },
2037 {
2038 name: "SendWarningAlerts",
2039 config: Config{
2040 MaxVersion: VersionTLS12,
2041 },
Adam Langley7c803a62015-06-15 15:35:05 -07002042 sendWarningAlerts: 5,
2043 shouldFail: true,
2044 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2045 },
2046 {
David Benjamine8e84b92016-08-03 15:39:47 -04002047 name: "SendWarningAlerts-Async",
2048 config: Config{
2049 MaxVersion: VersionTLS12,
2050 },
Adam Langley7c803a62015-06-15 15:35:05 -07002051 sendWarningAlerts: 5,
2052 flags: []string{"-async"},
2053 shouldFail: true,
2054 expectedError: ":TOO_MANY_WARNING_ALERTS:",
2055 },
David Benjaminba4594a2015-06-18 18:36:15 -04002056 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002057 name: "TooManyKeyUpdates",
Steven Valdez32635b82016-08-16 11:25:03 -04002058 config: Config{
2059 MaxVersion: VersionTLS13,
2060 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002061 sendKeyUpdates: 33,
2062 keyUpdateRequest: keyUpdateNotRequested,
2063 shouldFail: true,
2064 expectedError: ":TOO_MANY_KEY_UPDATES:",
Steven Valdez32635b82016-08-16 11:25:03 -04002065 },
2066 {
David Benjaminba4594a2015-06-18 18:36:15 -04002067 name: "EmptySessionID",
2068 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002069 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04002070 SessionTicketsDisabled: true,
2071 },
2072 noSessionCache: true,
2073 flags: []string{"-expect-no-session"},
2074 },
David Benjamin30789da2015-08-29 22:56:45 -04002075 {
2076 name: "Unclean-Shutdown",
2077 config: Config{
2078 Bugs: ProtocolBugs{
2079 NoCloseNotify: true,
2080 ExpectCloseNotify: true,
2081 },
2082 },
2083 shimShutsDown: true,
2084 flags: []string{"-check-close-notify"},
2085 shouldFail: true,
2086 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2087 },
2088 {
2089 name: "Unclean-Shutdown-Ignored",
2090 config: Config{
2091 Bugs: ProtocolBugs{
2092 NoCloseNotify: true,
2093 },
2094 },
2095 shimShutsDown: true,
2096 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002097 {
David Benjaminfa214e42016-05-10 17:03:10 -04002098 name: "Unclean-Shutdown-Alert",
2099 config: Config{
2100 Bugs: ProtocolBugs{
2101 SendAlertOnShutdown: alertDecompressionFailure,
2102 ExpectCloseNotify: true,
2103 },
2104 },
2105 shimShutsDown: true,
2106 flags: []string{"-check-close-notify"},
2107 shouldFail: true,
2108 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2109 },
2110 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002111 name: "LargePlaintext",
2112 config: Config{
2113 Bugs: ProtocolBugs{
2114 SendLargeRecords: true,
2115 },
2116 },
2117 messageLen: maxPlaintext + 1,
2118 shouldFail: true,
2119 expectedError: ":DATA_LENGTH_TOO_LONG:",
2120 },
2121 {
2122 protocol: dtls,
2123 name: "LargePlaintext-DTLS",
2124 config: Config{
2125 Bugs: ProtocolBugs{
2126 SendLargeRecords: true,
2127 },
2128 },
2129 messageLen: maxPlaintext + 1,
2130 shouldFail: true,
2131 expectedError: ":DATA_LENGTH_TOO_LONG:",
2132 },
2133 {
2134 name: "LargeCiphertext",
2135 config: Config{
2136 Bugs: ProtocolBugs{
2137 SendLargeRecords: true,
2138 },
2139 },
2140 messageLen: maxPlaintext * 2,
2141 shouldFail: true,
2142 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2143 },
2144 {
2145 protocol: dtls,
2146 name: "LargeCiphertext-DTLS",
2147 config: Config{
2148 Bugs: ProtocolBugs{
2149 SendLargeRecords: true,
2150 },
2151 },
2152 messageLen: maxPlaintext * 2,
2153 // Unlike the other four cases, DTLS drops records which
2154 // are invalid before authentication, so the connection
2155 // does not fail.
2156 expectMessageDropped: true,
2157 },
David Benjamindd6fed92015-10-23 17:41:12 -04002158 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002159 name: "BadHelloRequest-1",
2160 renegotiate: 1,
2161 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002162 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002163 Bugs: ProtocolBugs{
2164 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2165 },
2166 },
2167 flags: []string{
2168 "-renegotiate-freely",
2169 "-expect-total-renegotiations", "1",
2170 },
2171 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002172 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002173 },
2174 {
2175 name: "BadHelloRequest-2",
2176 renegotiate: 1,
2177 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002178 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002179 Bugs: ProtocolBugs{
2180 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2181 },
2182 },
2183 flags: []string{
2184 "-renegotiate-freely",
2185 "-expect-total-renegotiations", "1",
2186 },
2187 shouldFail: true,
2188 expectedError: ":BAD_HELLO_REQUEST:",
2189 },
David Benjaminef1b0092015-11-21 14:05:44 -05002190 {
2191 testType: serverTest,
2192 name: "SupportTicketsWithSessionID",
2193 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002194 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002195 SessionTicketsDisabled: true,
2196 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002197 resumeConfig: &Config{
2198 MaxVersion: VersionTLS12,
2199 },
David Benjaminef1b0092015-11-21 14:05:44 -05002200 resumeSession: true,
2201 },
David Benjamin02edcd02016-07-27 17:40:37 -04002202 {
2203 protocol: dtls,
2204 name: "DTLS-SendExtraFinished",
2205 config: Config{
2206 Bugs: ProtocolBugs{
2207 SendExtraFinished: true,
2208 },
2209 },
2210 shouldFail: true,
2211 expectedError: ":UNEXPECTED_RECORD:",
2212 },
2213 {
2214 protocol: dtls,
2215 name: "DTLS-SendExtraFinished-Reordered",
2216 config: Config{
2217 Bugs: ProtocolBugs{
2218 MaxHandshakeRecordLength: 2,
2219 ReorderHandshakeFragments: true,
2220 SendExtraFinished: true,
2221 },
2222 },
2223 shouldFail: true,
2224 expectedError: ":UNEXPECTED_RECORD:",
2225 },
David Benjamine97fb482016-07-29 09:23:07 -04002226 {
2227 testType: serverTest,
2228 name: "V2ClientHello-EmptyRecordPrefix",
2229 config: Config{
2230 // Choose a cipher suite that does not involve
2231 // elliptic curves, so no extensions are
2232 // involved.
2233 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002234 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002235 Bugs: ProtocolBugs{
2236 SendV2ClientHello: true,
2237 },
2238 },
2239 sendPrefix: string([]byte{
2240 byte(recordTypeHandshake),
2241 3, 1, // version
2242 0, 0, // length
2243 }),
2244 // A no-op empty record may not be sent before V2ClientHello.
2245 shouldFail: true,
2246 expectedError: ":WRONG_VERSION_NUMBER:",
2247 },
2248 {
2249 testType: serverTest,
2250 name: "V2ClientHello-WarningAlertPrefix",
2251 config: Config{
2252 // Choose a cipher suite that does not involve
2253 // elliptic curves, so no extensions are
2254 // involved.
2255 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002256 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002257 Bugs: ProtocolBugs{
2258 SendV2ClientHello: true,
2259 },
2260 },
2261 sendPrefix: string([]byte{
2262 byte(recordTypeAlert),
2263 3, 1, // version
2264 0, 2, // length
2265 alertLevelWarning, byte(alertDecompressionFailure),
2266 }),
2267 // A no-op warning alert may not be sent before V2ClientHello.
2268 shouldFail: true,
2269 expectedError: ":WRONG_VERSION_NUMBER:",
2270 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002271 {
Steven Valdezc4aa7272016-10-03 12:25:56 -04002272 name: "KeyUpdate",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002273 config: Config{
2274 MaxVersion: VersionTLS13,
Steven Valdez1dc53d22016-07-26 12:27:38 -04002275 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04002276 sendKeyUpdates: 1,
2277 keyUpdateRequest: keyUpdateNotRequested,
2278 },
2279 {
2280 name: "KeyUpdate-InvalidRequestMode",
2281 config: Config{
2282 MaxVersion: VersionTLS13,
2283 },
2284 sendKeyUpdates: 1,
2285 keyUpdateRequest: 42,
2286 shouldFail: true,
2287 expectedError: ":DECODE_ERROR:",
Steven Valdez1dc53d22016-07-26 12:27:38 -04002288 },
David Benjaminabe94e32016-09-04 14:18:58 -04002289 {
2290 name: "SendSNIWarningAlert",
2291 config: Config{
2292 MaxVersion: VersionTLS12,
2293 Bugs: ProtocolBugs{
2294 SendSNIWarningAlert: true,
2295 },
2296 },
2297 },
David Benjaminc241d792016-09-09 10:34:20 -04002298 {
2299 testType: serverTest,
2300 name: "ExtraCompressionMethods-TLS12",
2301 config: Config{
2302 MaxVersion: VersionTLS12,
2303 Bugs: ProtocolBugs{
2304 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2305 },
2306 },
2307 },
2308 {
2309 testType: serverTest,
2310 name: "ExtraCompressionMethods-TLS13",
2311 config: Config{
2312 MaxVersion: VersionTLS13,
2313 Bugs: ProtocolBugs{
2314 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2315 },
2316 },
2317 shouldFail: true,
2318 expectedError: ":INVALID_COMPRESSION_LIST:",
2319 expectedLocalError: "remote error: illegal parameter",
2320 },
2321 {
2322 testType: serverTest,
2323 name: "NoNullCompression-TLS12",
2324 config: Config{
2325 MaxVersion: VersionTLS12,
2326 Bugs: ProtocolBugs{
2327 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2328 },
2329 },
2330 shouldFail: true,
2331 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2332 expectedLocalError: "remote error: illegal parameter",
2333 },
2334 {
2335 testType: serverTest,
2336 name: "NoNullCompression-TLS13",
2337 config: Config{
2338 MaxVersion: VersionTLS13,
2339 Bugs: ProtocolBugs{
2340 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2341 },
2342 },
2343 shouldFail: true,
2344 expectedError: ":INVALID_COMPRESSION_LIST:",
2345 expectedLocalError: "remote error: illegal parameter",
2346 },
David Benjamin65ac9972016-09-02 21:35:25 -04002347 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002348 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002349 config: Config{
2350 MaxVersion: VersionTLS12,
2351 Bugs: ProtocolBugs{
2352 ExpectGREASE: true,
2353 },
2354 },
2355 flags: []string{"-enable-grease"},
2356 },
2357 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002358 name: "GREASE-Client-TLS13",
2359 config: Config{
2360 MaxVersion: VersionTLS13,
2361 Bugs: ProtocolBugs{
2362 ExpectGREASE: true,
2363 },
2364 },
2365 flags: []string{"-enable-grease"},
2366 },
2367 {
2368 testType: serverTest,
2369 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002370 config: Config{
2371 MaxVersion: VersionTLS13,
2372 Bugs: ProtocolBugs{
David Benjamin079b3942016-10-20 13:19:20 -04002373 // TLS 1.3 servers are expected to
2374 // always enable GREASE. TLS 1.3 is new,
2375 // so there is no existing ecosystem to
2376 // worry about.
David Benjamin65ac9972016-09-02 21:35:25 -04002377 ExpectGREASE: true,
2378 },
2379 },
David Benjamin65ac9972016-09-02 21:35:25 -04002380 },
Adam Langley7c803a62015-06-15 15:35:05 -07002381 }
Adam Langley7c803a62015-06-15 15:35:05 -07002382 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002383
2384 // Test that very large messages can be received.
2385 cert := rsaCertificate
2386 for i := 0; i < 50; i++ {
2387 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2388 }
2389 testCases = append(testCases, testCase{
2390 name: "LargeMessage",
2391 config: Config{
2392 Certificates: []Certificate{cert},
2393 },
2394 })
2395 testCases = append(testCases, testCase{
2396 protocol: dtls,
2397 name: "LargeMessage-DTLS",
2398 config: Config{
2399 Certificates: []Certificate{cert},
2400 },
2401 })
2402
2403 // They are rejected if the maximum certificate chain length is capped.
2404 testCases = append(testCases, testCase{
2405 name: "LargeMessage-Reject",
2406 config: Config{
2407 Certificates: []Certificate{cert},
2408 },
2409 flags: []string{"-max-cert-list", "16384"},
2410 shouldFail: true,
2411 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2412 })
2413 testCases = append(testCases, testCase{
2414 protocol: dtls,
2415 name: "LargeMessage-Reject-DTLS",
2416 config: Config{
2417 Certificates: []Certificate{cert},
2418 },
2419 flags: []string{"-max-cert-list", "16384"},
2420 shouldFail: true,
2421 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2422 })
Adam Langley7c803a62015-06-15 15:35:05 -07002423}
2424
Adam Langley95c29f32014-06-20 12:00:00 -07002425func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002426 const bogusCipher = 0xfe00
2427
Adam Langley95c29f32014-06-20 12:00:00 -07002428 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002429 const psk = "12345"
2430 const pskIdentity = "luggage combo"
2431
Adam Langley95c29f32014-06-20 12:00:00 -07002432 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002433 var certFile string
2434 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002435 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002436 cert = ecdsaP256Certificate
2437 certFile = ecdsaP256CertificateFile
2438 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002439 } else {
David Benjamin33863262016-07-08 17:20:12 -07002440 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002441 certFile = rsaCertificateFile
2442 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002443 }
2444
David Benjamin48cae082014-10-27 01:06:24 -04002445 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002446 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002447 flags = append(flags,
2448 "-psk", psk,
2449 "-psk-identity", pskIdentity)
2450 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002451 if hasComponent(suite.name, "NULL") {
2452 // NULL ciphers must be explicitly enabled.
2453 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2454 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002455 if hasComponent(suite.name, "CECPQ1") {
2456 // CECPQ1 ciphers must be explicitly enabled.
2457 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2458 }
David Benjamin881f1962016-08-10 18:29:12 -04002459 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2460 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2461 // for now.
2462 flags = append(flags, "-cipher", suite.name)
2463 }
David Benjamin48cae082014-10-27 01:06:24 -04002464
Adam Langley95c29f32014-06-20 12:00:00 -07002465 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002466 for _, protocol := range []protocol{tls, dtls} {
2467 var prefix string
2468 if protocol == dtls {
2469 if !ver.hasDTLS {
2470 continue
2471 }
2472 prefix = "D"
2473 }
Adam Langley95c29f32014-06-20 12:00:00 -07002474
David Benjamin0407e762016-06-17 16:41:18 -04002475 var shouldServerFail, shouldClientFail bool
2476 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2477 // BoringSSL clients accept ECDHE on SSLv3, but
2478 // a BoringSSL server will never select it
2479 // because the extension is missing.
2480 shouldServerFail = true
2481 }
2482 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2483 shouldClientFail = true
2484 shouldServerFail = true
2485 }
David Benjamin54c217c2016-07-13 12:35:25 -04002486 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002487 shouldClientFail = true
2488 shouldServerFail = true
2489 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002490 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2491 shouldClientFail = true
2492 shouldServerFail = true
2493 }
David Benjamin0407e762016-06-17 16:41:18 -04002494 if !isDTLSCipher(suite.name) && protocol == dtls {
2495 shouldClientFail = true
2496 shouldServerFail = true
2497 }
David Benjamin4298d772015-12-19 00:18:25 -05002498
David Benjamin5ecb88b2016-10-04 17:51:35 -04002499 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002500 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002501 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002502 if shouldServerFail {
2503 expectedServerError = ":NO_SHARED_CIPHER:"
2504 }
2505 if shouldClientFail {
2506 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002507 // Configure the server to select ciphers as normal but
2508 // select an incompatible cipher in ServerHello.
2509 serverCipherSuites = nil
2510 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002511 }
David Benjamin025b3d32014-07-01 19:53:04 -04002512
David Benjamin6fd297b2014-08-11 18:43:38 -04002513 testCases = append(testCases, testCase{
2514 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002515 protocol: protocol,
2516
2517 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002518 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002519 MinVersion: ver.version,
2520 MaxVersion: ver.version,
2521 CipherSuites: []uint16{suite.id},
2522 Certificates: []Certificate{cert},
2523 PreSharedKey: []byte(psk),
2524 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002525 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002526 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002527 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002528 },
2529 certFile: certFile,
2530 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002531 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002532 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002533 shouldFail: shouldServerFail,
2534 expectedError: expectedServerError,
2535 })
2536
2537 testCases = append(testCases, testCase{
2538 testType: clientTest,
2539 protocol: protocol,
2540 name: prefix + ver.name + "-" + suite.name + "-client",
2541 config: Config{
2542 MinVersion: ver.version,
2543 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002544 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002545 Certificates: []Certificate{cert},
2546 PreSharedKey: []byte(psk),
2547 PreSharedKeyIdentity: pskIdentity,
2548 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002549 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002550 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002551 },
2552 },
2553 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002554 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002555 shouldFail: shouldClientFail,
2556 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002557 })
David Benjamin2c99d282015-09-01 10:23:00 -04002558
Nick Harper1fd39d82016-06-14 18:14:35 -07002559 if !shouldClientFail {
2560 // Ensure the maximum record size is accepted.
2561 testCases = append(testCases, testCase{
David Benjamin231a4752016-11-10 10:46:00 -05002562 protocol: protocol,
2563 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
Nick Harper1fd39d82016-06-14 18:14:35 -07002564 config: Config{
2565 MinVersion: ver.version,
2566 MaxVersion: ver.version,
2567 CipherSuites: []uint16{suite.id},
2568 Certificates: []Certificate{cert},
2569 PreSharedKey: []byte(psk),
2570 PreSharedKeyIdentity: pskIdentity,
2571 },
2572 flags: flags,
2573 messageLen: maxPlaintext,
2574 })
David Benjamin231a4752016-11-10 10:46:00 -05002575
2576 // Test bad records for all ciphers. Bad records are fatal in TLS
2577 // and ignored in DTLS.
2578 var shouldFail bool
2579 var expectedError string
2580 if protocol == tls {
2581 shouldFail = true
2582 expectedError = ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:"
2583 }
2584
2585 testCases = append(testCases, testCase{
2586 protocol: protocol,
2587 name: prefix + ver.name + "-" + suite.name + "-BadRecord",
2588 config: Config{
2589 MinVersion: ver.version,
2590 MaxVersion: ver.version,
2591 CipherSuites: []uint16{suite.id},
2592 Certificates: []Certificate{cert},
2593 PreSharedKey: []byte(psk),
2594 PreSharedKeyIdentity: pskIdentity,
2595 },
2596 flags: flags,
2597 damageFirstWrite: true,
2598 messageLen: maxPlaintext,
2599 shouldFail: shouldFail,
2600 expectedError: expectedError,
2601 })
Nick Harper1fd39d82016-06-14 18:14:35 -07002602 }
2603 }
David Benjamin2c99d282015-09-01 10:23:00 -04002604 }
Adam Langley95c29f32014-06-20 12:00:00 -07002605 }
Adam Langleya7997f12015-05-14 17:38:50 -07002606
2607 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002608 name: "NoSharedCipher",
2609 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002610 MaxVersion: VersionTLS12,
2611 CipherSuites: []uint16{},
2612 },
2613 shouldFail: true,
2614 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2615 })
2616
2617 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002618 name: "NoSharedCipher-TLS13",
2619 config: Config{
2620 MaxVersion: VersionTLS13,
2621 CipherSuites: []uint16{},
2622 },
2623 shouldFail: true,
2624 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2625 })
2626
2627 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002628 name: "UnsupportedCipherSuite",
2629 config: Config{
2630 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002631 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002632 Bugs: ProtocolBugs{
2633 IgnorePeerCipherPreferences: true,
2634 },
2635 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002636 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002637 shouldFail: true,
2638 expectedError: ":WRONG_CIPHER_RETURNED:",
2639 })
2640
2641 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002642 name: "ServerHelloBogusCipher",
2643 config: Config{
2644 MaxVersion: VersionTLS12,
2645 Bugs: ProtocolBugs{
2646 SendCipherSuite: bogusCipher,
2647 },
2648 },
2649 shouldFail: true,
2650 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2651 })
2652 testCases = append(testCases, testCase{
2653 name: "ServerHelloBogusCipher-TLS13",
2654 config: Config{
2655 MaxVersion: VersionTLS13,
2656 Bugs: ProtocolBugs{
2657 SendCipherSuite: bogusCipher,
2658 },
2659 },
2660 shouldFail: true,
2661 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2662 })
2663
2664 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002665 name: "WeakDH",
2666 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002667 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002668 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2669 Bugs: ProtocolBugs{
2670 // This is a 1023-bit prime number, generated
2671 // with:
2672 // openssl gendh 1023 | openssl asn1parse -i
2673 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2674 },
2675 },
2676 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002677 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002678 })
Adam Langleycef75832015-09-03 14:51:12 -07002679
David Benjamincd24a392015-11-11 13:23:05 -08002680 testCases = append(testCases, testCase{
2681 name: "SillyDH",
2682 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002683 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002684 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2685 Bugs: ProtocolBugs{
2686 // This is a 4097-bit prime number, generated
2687 // with:
2688 // openssl gendh 4097 | openssl asn1parse -i
2689 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2690 },
2691 },
2692 shouldFail: true,
2693 expectedError: ":DH_P_TOO_LONG:",
2694 })
2695
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002696 // This test ensures that Diffie-Hellman public values are padded with
2697 // zeros so that they're the same length as the prime. This is to avoid
2698 // hitting a bug in yaSSL.
2699 testCases = append(testCases, testCase{
2700 testType: serverTest,
2701 name: "DHPublicValuePadded",
2702 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002703 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002704 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2705 Bugs: ProtocolBugs{
2706 RequireDHPublicValueLen: (1025 + 7) / 8,
2707 },
2708 },
2709 flags: []string{"-use-sparse-dh-prime"},
2710 })
David Benjamincd24a392015-11-11 13:23:05 -08002711
David Benjamin241ae832016-01-15 03:04:54 -05002712 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002713 testCases = append(testCases, testCase{
2714 testType: serverTest,
2715 name: "UnknownCipher",
2716 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002717 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002718 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002719 Bugs: ProtocolBugs{
2720 AdvertiseAllConfiguredCiphers: true,
2721 },
2722 },
2723 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002724
2725 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002726 testCases = append(testCases, testCase{
2727 testType: serverTest,
2728 name: "UnknownCipher-TLS13",
2729 config: Config{
2730 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002731 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002732 Bugs: ProtocolBugs{
2733 AdvertiseAllConfiguredCiphers: true,
2734 },
David Benjamin241ae832016-01-15 03:04:54 -05002735 },
2736 })
2737
David Benjamin78679342016-09-16 19:42:05 -04002738 // Test empty ECDHE_PSK identity hints work as expected.
2739 testCases = append(testCases, testCase{
2740 name: "EmptyECDHEPSKHint",
2741 config: Config{
2742 MaxVersion: VersionTLS12,
2743 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2744 PreSharedKey: []byte("secret"),
2745 },
2746 flags: []string{"-psk", "secret"},
2747 })
2748
2749 // Test empty PSK identity hints work as expected, even if an explicit
2750 // ServerKeyExchange is sent.
2751 testCases = append(testCases, testCase{
2752 name: "ExplicitEmptyPSKHint",
2753 config: Config{
2754 MaxVersion: VersionTLS12,
2755 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2756 PreSharedKey: []byte("secret"),
2757 Bugs: ProtocolBugs{
2758 AlwaysSendPreSharedKeyIdentityHint: true,
2759 },
2760 },
2761 flags: []string{"-psk", "secret"},
2762 })
2763
Adam Langleycef75832015-09-03 14:51:12 -07002764 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2765 // 1.1 specific cipher suite settings. A server is setup with the given
2766 // cipher lists and then a connection is made for each member of
2767 // expectations. The cipher suite that the server selects must match
2768 // the specified one.
2769 var versionSpecificCiphersTest = []struct {
2770 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2771 // expectations is a map from TLS version to cipher suite id.
2772 expectations map[uint16]uint16
2773 }{
2774 {
2775 // Test that the null case (where no version-specific ciphers are set)
2776 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002777 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2778 "", // no ciphers specifically for TLS ≥ 1.0
2779 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002780 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002781 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2782 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2783 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2784 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002785 },
2786 },
2787 {
2788 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2789 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002790 "DES-CBC3-SHA:AES128-SHA", // default
2791 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2792 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002793 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002794 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002795 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2796 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2797 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2798 },
2799 },
2800 {
2801 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2802 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002803 "DES-CBC3-SHA:AES128-SHA", // default
2804 "", // no ciphers specifically for TLS ≥ 1.0
2805 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002806 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002807 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2808 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002809 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2810 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2811 },
2812 },
2813 {
2814 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2815 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002816 "DES-CBC3-SHA:AES128-SHA", // default
2817 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2818 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002819 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002820 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002821 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2822 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2823 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2824 },
2825 },
2826 }
2827
2828 for i, test := range versionSpecificCiphersTest {
2829 for version, expectedCipherSuite := range test.expectations {
2830 flags := []string{"-cipher", test.ciphersDefault}
2831 if len(test.ciphersTLS10) > 0 {
2832 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2833 }
2834 if len(test.ciphersTLS11) > 0 {
2835 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2836 }
2837
2838 testCases = append(testCases, testCase{
2839 testType: serverTest,
2840 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2841 config: Config{
2842 MaxVersion: version,
2843 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002844 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA},
Adam Langleycef75832015-09-03 14:51:12 -07002845 },
2846 flags: flags,
2847 expectedCipher: expectedCipherSuite,
2848 })
2849 }
2850 }
Adam Langley95c29f32014-06-20 12:00:00 -07002851}
2852
2853func addBadECDSASignatureTests() {
2854 for badR := BadValue(1); badR < NumBadValues; badR++ {
2855 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002856 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002857 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2858 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002859 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002860 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002861 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002862 Bugs: ProtocolBugs{
2863 BadECDSAR: badR,
2864 BadECDSAS: badS,
2865 },
2866 },
2867 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002868 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002869 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002870 testCases = append(testCases, testCase{
2871 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2872 config: Config{
2873 MaxVersion: VersionTLS13,
2874 Certificates: []Certificate{ecdsaP256Certificate},
2875 Bugs: ProtocolBugs{
2876 BadECDSAR: badR,
2877 BadECDSAS: badS,
2878 },
2879 },
2880 shouldFail: true,
2881 expectedError: ":BAD_SIGNATURE:",
2882 })
Adam Langley95c29f32014-06-20 12:00:00 -07002883 }
2884 }
2885}
2886
Adam Langley80842bd2014-06-20 12:00:00 -07002887func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002888 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002889 name: "MaxCBCPadding",
2890 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002891 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002892 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2893 Bugs: ProtocolBugs{
2894 MaxPadding: true,
2895 },
2896 },
2897 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2898 })
David Benjamin025b3d32014-07-01 19:53:04 -04002899 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002900 name: "BadCBCPadding",
2901 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002902 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002903 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2904 Bugs: ProtocolBugs{
2905 PaddingFirstByteBad: true,
2906 },
2907 },
2908 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002909 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002910 })
2911 // OpenSSL previously had an issue where the first byte of padding in
2912 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002913 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002914 name: "BadCBCPadding255",
2915 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002916 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002917 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2918 Bugs: ProtocolBugs{
2919 MaxPadding: true,
2920 PaddingFirstByteBadIf255: true,
2921 },
2922 },
2923 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2924 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002925 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002926 })
2927}
2928
Kenny Root7fdeaf12014-08-05 15:23:37 -07002929func addCBCSplittingTests() {
2930 testCases = append(testCases, testCase{
2931 name: "CBCRecordSplitting",
2932 config: Config{
2933 MaxVersion: VersionTLS10,
2934 MinVersion: VersionTLS10,
2935 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2936 },
David Benjaminac8302a2015-09-01 17:18:15 -04002937 messageLen: -1, // read until EOF
2938 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002939 flags: []string{
2940 "-async",
2941 "-write-different-record-sizes",
2942 "-cbc-record-splitting",
2943 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002944 })
2945 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002946 name: "CBCRecordSplittingPartialWrite",
2947 config: Config{
2948 MaxVersion: VersionTLS10,
2949 MinVersion: VersionTLS10,
2950 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2951 },
2952 messageLen: -1, // read until EOF
2953 flags: []string{
2954 "-async",
2955 "-write-different-record-sizes",
2956 "-cbc-record-splitting",
2957 "-partial-write",
2958 },
2959 })
2960}
2961
David Benjamin636293b2014-07-08 17:59:18 -04002962func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002963 // Add a dummy cert pool to stress certificate authority parsing.
2964 // TODO(davidben): Add tests that those values parse out correctly.
2965 certPool := x509.NewCertPool()
2966 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2967 if err != nil {
2968 panic(err)
2969 }
2970 certPool.AddCert(cert)
2971
David Benjamin636293b2014-07-08 17:59:18 -04002972 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002973 testCases = append(testCases, testCase{
2974 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002975 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002976 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002977 MinVersion: ver.version,
2978 MaxVersion: ver.version,
2979 ClientAuth: RequireAnyClientCert,
2980 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002981 },
2982 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002983 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2984 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002985 },
2986 })
2987 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002988 testType: serverTest,
2989 name: ver.name + "-Server-ClientAuth-RSA",
2990 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002991 MinVersion: ver.version,
2992 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002993 Certificates: []Certificate{rsaCertificate},
2994 },
2995 flags: []string{"-require-any-client-certificate"},
2996 })
David Benjamine098ec22014-08-27 23:13:20 -04002997 if ver.version != VersionSSL30 {
2998 testCases = append(testCases, testCase{
2999 testType: serverTest,
3000 name: ver.name + "-Server-ClientAuth-ECDSA",
3001 config: Config{
3002 MinVersion: ver.version,
3003 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07003004 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04003005 },
3006 flags: []string{"-require-any-client-certificate"},
3007 })
3008 testCases = append(testCases, testCase{
3009 testType: clientTest,
3010 name: ver.name + "-Client-ClientAuth-ECDSA",
3011 config: Config{
3012 MinVersion: ver.version,
3013 MaxVersion: ver.version,
3014 ClientAuth: RequireAnyClientCert,
3015 ClientCAs: certPool,
3016 },
3017 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003018 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3019 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04003020 },
3021 })
3022 }
Adam Langley37646832016-08-01 16:16:46 -07003023
3024 testCases = append(testCases, testCase{
3025 name: "NoClientCertificate-" + ver.name,
3026 config: Config{
3027 MinVersion: ver.version,
3028 MaxVersion: ver.version,
3029 ClientAuth: RequireAnyClientCert,
3030 },
3031 shouldFail: true,
3032 expectedLocalError: "client didn't provide a certificate",
3033 })
3034
3035 testCases = append(testCases, testCase{
3036 // Even if not configured to expect a certificate, OpenSSL will
3037 // return X509_V_OK as the verify_result.
3038 testType: serverTest,
3039 name: "NoClientCertificateRequested-Server-" + ver.name,
3040 config: Config{
3041 MinVersion: ver.version,
3042 MaxVersion: ver.version,
3043 },
3044 flags: []string{
3045 "-expect-verify-result",
3046 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003047 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003048 })
3049
3050 testCases = append(testCases, testCase{
3051 // If a client certificate is not provided, OpenSSL will still
3052 // return X509_V_OK as the verify_result.
3053 testType: serverTest,
3054 name: "NoClientCertificate-Server-" + ver.name,
3055 config: Config{
3056 MinVersion: ver.version,
3057 MaxVersion: ver.version,
3058 },
3059 flags: []string{
3060 "-expect-verify-result",
3061 "-verify-peer",
3062 },
David Benjamin5d9ba812016-10-07 20:51:20 -04003063 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07003064 })
3065
David Benjamin1db9e1b2016-10-07 20:51:43 -04003066 certificateRequired := "remote error: certificate required"
3067 if ver.version < VersionTLS13 {
3068 // Prior to TLS 1.3, the generic handshake_failure alert
3069 // was used.
3070 certificateRequired = "remote error: handshake failure"
3071 }
Adam Langley37646832016-08-01 16:16:46 -07003072 testCases = append(testCases, testCase{
3073 testType: serverTest,
3074 name: "RequireAnyClientCertificate-" + ver.name,
3075 config: Config{
3076 MinVersion: ver.version,
3077 MaxVersion: ver.version,
3078 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04003079 flags: []string{"-require-any-client-certificate"},
3080 shouldFail: true,
3081 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
3082 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07003083 })
3084
3085 if ver.version != VersionSSL30 {
3086 testCases = append(testCases, testCase{
3087 testType: serverTest,
3088 name: "SkipClientCertificate-" + ver.name,
3089 config: Config{
3090 MinVersion: ver.version,
3091 MaxVersion: ver.version,
3092 Bugs: ProtocolBugs{
3093 SkipClientCertificate: true,
3094 },
3095 },
3096 // Setting SSL_VERIFY_PEER allows anonymous clients.
3097 flags: []string{"-verify-peer"},
3098 shouldFail: true,
3099 expectedError: ":UNEXPECTED_MESSAGE:",
3100 })
3101 }
David Benjamin636293b2014-07-08 17:59:18 -04003102 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003103
David Benjaminc032dfa2016-05-12 14:54:57 -04003104 // Client auth is only legal in certificate-based ciphers.
3105 testCases = append(testCases, testCase{
3106 testType: clientTest,
3107 name: "ClientAuth-PSK",
3108 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003109 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003110 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3111 PreSharedKey: []byte("secret"),
3112 ClientAuth: RequireAnyClientCert,
3113 },
3114 flags: []string{
3115 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3116 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3117 "-psk", "secret",
3118 },
3119 shouldFail: true,
3120 expectedError: ":UNEXPECTED_MESSAGE:",
3121 })
3122 testCases = append(testCases, testCase{
3123 testType: clientTest,
3124 name: "ClientAuth-ECDHE_PSK",
3125 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003126 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003127 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3128 PreSharedKey: []byte("secret"),
3129 ClientAuth: RequireAnyClientCert,
3130 },
3131 flags: []string{
3132 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3133 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3134 "-psk", "secret",
3135 },
3136 shouldFail: true,
3137 expectedError: ":UNEXPECTED_MESSAGE:",
3138 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003139
3140 // Regression test for a bug where the client CA list, if explicitly
3141 // set to NULL, was mis-encoded.
3142 testCases = append(testCases, testCase{
3143 testType: serverTest,
3144 name: "Null-Client-CA-List",
3145 config: Config{
3146 MaxVersion: VersionTLS12,
3147 Certificates: []Certificate{rsaCertificate},
3148 },
3149 flags: []string{
3150 "-require-any-client-certificate",
3151 "-use-null-client-ca-list",
3152 },
3153 })
David Benjamin636293b2014-07-08 17:59:18 -04003154}
3155
Adam Langley75712922014-10-10 16:23:43 -07003156func addExtendedMasterSecretTests() {
3157 const expectEMSFlag = "-expect-extended-master-secret"
3158
3159 for _, with := range []bool{false, true} {
3160 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003161 if with {
3162 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003163 }
3164
3165 for _, isClient := range []bool{false, true} {
3166 suffix := "-Server"
3167 testType := serverTest
3168 if isClient {
3169 suffix = "-Client"
3170 testType = clientTest
3171 }
3172
3173 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003174 // In TLS 1.3, the extension is irrelevant and
3175 // always reports as enabled.
3176 var flags []string
3177 if with || ver.version >= VersionTLS13 {
3178 flags = []string{expectEMSFlag}
3179 }
3180
Adam Langley75712922014-10-10 16:23:43 -07003181 test := testCase{
3182 testType: testType,
3183 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3184 config: Config{
3185 MinVersion: ver.version,
3186 MaxVersion: ver.version,
3187 Bugs: ProtocolBugs{
3188 NoExtendedMasterSecret: !with,
3189 RequireExtendedMasterSecret: with,
3190 },
3191 },
David Benjamin48cae082014-10-27 01:06:24 -04003192 flags: flags,
3193 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003194 }
3195 if test.shouldFail {
3196 test.expectedLocalError = "extended master secret required but not supported by peer"
3197 }
3198 testCases = append(testCases, test)
3199 }
3200 }
3201 }
3202
Adam Langleyba5934b2015-06-02 10:50:35 -07003203 for _, isClient := range []bool{false, true} {
3204 for _, supportedInFirstConnection := range []bool{false, true} {
3205 for _, supportedInResumeConnection := range []bool{false, true} {
3206 boolToWord := func(b bool) string {
3207 if b {
3208 return "Yes"
3209 }
3210 return "No"
3211 }
3212 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3213 if isClient {
3214 suffix += "Client"
3215 } else {
3216 suffix += "Server"
3217 }
3218
3219 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003220 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003221 Bugs: ProtocolBugs{
3222 RequireExtendedMasterSecret: true,
3223 },
3224 }
3225
3226 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003227 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003228 Bugs: ProtocolBugs{
3229 NoExtendedMasterSecret: true,
3230 },
3231 }
3232
3233 test := testCase{
3234 name: "ExtendedMasterSecret-" + suffix,
3235 resumeSession: true,
3236 }
3237
3238 if !isClient {
3239 test.testType = serverTest
3240 }
3241
3242 if supportedInFirstConnection {
3243 test.config = supportedConfig
3244 } else {
3245 test.config = noSupportConfig
3246 }
3247
3248 if supportedInResumeConnection {
3249 test.resumeConfig = &supportedConfig
3250 } else {
3251 test.resumeConfig = &noSupportConfig
3252 }
3253
3254 switch suffix {
3255 case "YesToYes-Client", "YesToYes-Server":
3256 // When a session is resumed, it should
3257 // still be aware that its master
3258 // secret was generated via EMS and
3259 // thus it's safe to use tls-unique.
3260 test.flags = []string{expectEMSFlag}
3261 case "NoToYes-Server":
3262 // If an original connection did not
3263 // contain EMS, but a resumption
3264 // handshake does, then a server should
3265 // not resume the session.
3266 test.expectResumeRejected = true
3267 case "YesToNo-Server":
3268 // Resuming an EMS session without the
3269 // EMS extension should cause the
3270 // server to abort the connection.
3271 test.shouldFail = true
3272 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3273 case "NoToYes-Client":
3274 // A client should abort a connection
3275 // where the server resumed a non-EMS
3276 // session but echoed the EMS
3277 // extension.
3278 test.shouldFail = true
3279 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3280 case "YesToNo-Client":
3281 // A client should abort a connection
3282 // where the server didn't echo EMS
3283 // when the session used it.
3284 test.shouldFail = true
3285 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3286 }
3287
3288 testCases = append(testCases, test)
3289 }
3290 }
3291 }
David Benjamin163c9562016-08-29 23:14:17 -04003292
3293 // Switching EMS on renegotiation is forbidden.
3294 testCases = append(testCases, testCase{
3295 name: "ExtendedMasterSecret-Renego-NoEMS",
3296 config: Config{
3297 MaxVersion: VersionTLS12,
3298 Bugs: ProtocolBugs{
3299 NoExtendedMasterSecret: true,
3300 NoExtendedMasterSecretOnRenegotiation: true,
3301 },
3302 },
3303 renegotiate: 1,
3304 flags: []string{
3305 "-renegotiate-freely",
3306 "-expect-total-renegotiations", "1",
3307 },
3308 })
3309
3310 testCases = append(testCases, testCase{
3311 name: "ExtendedMasterSecret-Renego-Upgrade",
3312 config: Config{
3313 MaxVersion: VersionTLS12,
3314 Bugs: ProtocolBugs{
3315 NoExtendedMasterSecret: true,
3316 },
3317 },
3318 renegotiate: 1,
3319 flags: []string{
3320 "-renegotiate-freely",
3321 "-expect-total-renegotiations", "1",
3322 },
3323 shouldFail: true,
3324 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3325 })
3326
3327 testCases = append(testCases, testCase{
3328 name: "ExtendedMasterSecret-Renego-Downgrade",
3329 config: Config{
3330 MaxVersion: VersionTLS12,
3331 Bugs: ProtocolBugs{
3332 NoExtendedMasterSecretOnRenegotiation: true,
3333 },
3334 },
3335 renegotiate: 1,
3336 flags: []string{
3337 "-renegotiate-freely",
3338 "-expect-total-renegotiations", "1",
3339 },
3340 shouldFail: true,
3341 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3342 })
Adam Langley75712922014-10-10 16:23:43 -07003343}
3344
David Benjamin582ba042016-07-07 12:33:25 -07003345type stateMachineTestConfig struct {
3346 protocol protocol
3347 async bool
3348 splitHandshake, packHandshakeFlight bool
3349}
3350
David Benjamin43ec06f2014-08-05 02:28:57 -04003351// Adds tests that try to cover the range of the handshake state machine, under
3352// various conditions. Some of these are redundant with other tests, but they
3353// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003354func addAllStateMachineCoverageTests() {
3355 for _, async := range []bool{false, true} {
3356 for _, protocol := range []protocol{tls, dtls} {
3357 addStateMachineCoverageTests(stateMachineTestConfig{
3358 protocol: protocol,
3359 async: async,
3360 })
3361 addStateMachineCoverageTests(stateMachineTestConfig{
3362 protocol: protocol,
3363 async: async,
3364 splitHandshake: true,
3365 })
3366 if protocol == tls {
3367 addStateMachineCoverageTests(stateMachineTestConfig{
3368 protocol: protocol,
3369 async: async,
3370 packHandshakeFlight: true,
3371 })
3372 }
3373 }
3374 }
3375}
3376
3377func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003378 var tests []testCase
3379
3380 // Basic handshake, with resumption. Client and server,
3381 // session ID and session ticket.
3382 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003383 name: "Basic-Client",
3384 config: Config{
3385 MaxVersion: VersionTLS12,
3386 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003387 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003388 // Ensure session tickets are used, not session IDs.
3389 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003390 })
3391 tests = append(tests, testCase{
3392 name: "Basic-Client-RenewTicket",
3393 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003394 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003395 Bugs: ProtocolBugs{
3396 RenewTicketOnResume: true,
3397 },
3398 },
David Benjamin46662482016-08-17 00:51:00 -04003399 flags: []string{"-expect-ticket-renewal"},
3400 resumeSession: true,
3401 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003402 })
3403 tests = append(tests, testCase{
3404 name: "Basic-Client-NoTicket",
3405 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003406 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003407 SessionTicketsDisabled: true,
3408 },
3409 resumeSession: true,
3410 })
3411 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003412 name: "Basic-Client-Implicit",
3413 config: Config{
3414 MaxVersion: VersionTLS12,
3415 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003416 flags: []string{"-implicit-handshake"},
3417 resumeSession: true,
3418 })
3419 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003420 testType: serverTest,
3421 name: "Basic-Server",
3422 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003423 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003424 Bugs: ProtocolBugs{
3425 RequireSessionTickets: true,
3426 },
3427 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003428 resumeSession: true,
3429 })
3430 tests = append(tests, testCase{
3431 testType: serverTest,
3432 name: "Basic-Server-NoTickets",
3433 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003434 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003435 SessionTicketsDisabled: true,
3436 },
3437 resumeSession: true,
3438 })
3439 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003440 testType: serverTest,
3441 name: "Basic-Server-Implicit",
3442 config: Config{
3443 MaxVersion: VersionTLS12,
3444 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003445 flags: []string{"-implicit-handshake"},
3446 resumeSession: true,
3447 })
3448 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003449 testType: serverTest,
3450 name: "Basic-Server-EarlyCallback",
3451 config: Config{
3452 MaxVersion: VersionTLS12,
3453 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003454 flags: []string{"-use-early-callback"},
3455 resumeSession: true,
3456 })
3457
Steven Valdez143e8b32016-07-11 13:19:03 -04003458 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003459 if config.protocol == tls {
3460 tests = append(tests, testCase{
3461 name: "TLS13-1RTT-Client",
3462 config: Config{
3463 MaxVersion: VersionTLS13,
3464 MinVersion: VersionTLS13,
3465 },
David Benjamin46662482016-08-17 00:51:00 -04003466 resumeSession: true,
3467 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003468 })
3469
3470 tests = append(tests, testCase{
3471 testType: serverTest,
3472 name: "TLS13-1RTT-Server",
3473 config: Config{
3474 MaxVersion: VersionTLS13,
3475 MinVersion: VersionTLS13,
3476 },
David Benjamin46662482016-08-17 00:51:00 -04003477 resumeSession: true,
3478 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003479 })
3480
3481 tests = append(tests, testCase{
3482 name: "TLS13-HelloRetryRequest-Client",
3483 config: Config{
3484 MaxVersion: VersionTLS13,
3485 MinVersion: VersionTLS13,
David Benjamin3baa6e12016-10-07 21:10:38 -04003486 // P-384 requires a HelloRetryRequest against BoringSSL's default
3487 // configuration. Assert this with ExpectMissingKeyShare.
David Benjamine73c7f42016-08-17 00:29:33 -04003488 CurvePreferences: []CurveID{CurveP384},
3489 Bugs: ProtocolBugs{
3490 ExpectMissingKeyShare: true,
3491 },
3492 },
3493 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3494 resumeSession: true,
3495 })
3496
3497 tests = append(tests, testCase{
3498 testType: serverTest,
3499 name: "TLS13-HelloRetryRequest-Server",
3500 config: Config{
3501 MaxVersion: VersionTLS13,
3502 MinVersion: VersionTLS13,
3503 // Require a HelloRetryRequest for every curve.
3504 DefaultCurves: []CurveID{},
3505 },
3506 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3507 resumeSession: true,
3508 })
3509 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003510
David Benjamin760b1dd2015-05-15 23:33:48 -04003511 // TLS client auth.
3512 tests = append(tests, testCase{
3513 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003514 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003515 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003516 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003517 ClientAuth: RequestClientCert,
3518 },
3519 })
3520 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003521 testType: serverTest,
3522 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003523 config: Config{
3524 MaxVersion: VersionTLS12,
3525 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003526 // Setting SSL_VERIFY_PEER allows anonymous clients.
3527 flags: []string{"-verify-peer"},
3528 })
David Benjamin582ba042016-07-07 12:33:25 -07003529 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003530 tests = append(tests, testCase{
3531 testType: clientTest,
3532 name: "ClientAuth-NoCertificate-Client-SSL3",
3533 config: Config{
3534 MaxVersion: VersionSSL30,
3535 ClientAuth: RequestClientCert,
3536 },
3537 })
3538 tests = append(tests, testCase{
3539 testType: serverTest,
3540 name: "ClientAuth-NoCertificate-Server-SSL3",
3541 config: Config{
3542 MaxVersion: VersionSSL30,
3543 },
3544 // Setting SSL_VERIFY_PEER allows anonymous clients.
3545 flags: []string{"-verify-peer"},
3546 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003547 tests = append(tests, testCase{
3548 testType: clientTest,
3549 name: "ClientAuth-NoCertificate-Client-TLS13",
3550 config: Config{
3551 MaxVersion: VersionTLS13,
3552 ClientAuth: RequestClientCert,
3553 },
3554 })
3555 tests = append(tests, testCase{
3556 testType: serverTest,
3557 name: "ClientAuth-NoCertificate-Server-TLS13",
3558 config: Config{
3559 MaxVersion: VersionTLS13,
3560 },
3561 // Setting SSL_VERIFY_PEER allows anonymous clients.
3562 flags: []string{"-verify-peer"},
3563 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003564 }
3565 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003566 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003567 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003568 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003569 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003570 ClientAuth: RequireAnyClientCert,
3571 },
3572 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003573 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3574 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003575 },
3576 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003577 tests = append(tests, testCase{
3578 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003579 name: "ClientAuth-RSA-Client-TLS13",
3580 config: Config{
3581 MaxVersion: VersionTLS13,
3582 ClientAuth: RequireAnyClientCert,
3583 },
3584 flags: []string{
3585 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3586 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3587 },
3588 })
3589 tests = append(tests, testCase{
3590 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003591 name: "ClientAuth-ECDSA-Client",
3592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003593 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003594 ClientAuth: RequireAnyClientCert,
3595 },
3596 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003597 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3598 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003599 },
3600 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003601 tests = append(tests, testCase{
3602 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003603 name: "ClientAuth-ECDSA-Client-TLS13",
3604 config: Config{
3605 MaxVersion: VersionTLS13,
3606 ClientAuth: RequireAnyClientCert,
3607 },
3608 flags: []string{
3609 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3610 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3611 },
3612 })
3613 tests = append(tests, testCase{
3614 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003615 name: "ClientAuth-NoCertificate-OldCallback",
3616 config: Config{
3617 MaxVersion: VersionTLS12,
3618 ClientAuth: RequestClientCert,
3619 },
3620 flags: []string{"-use-old-client-cert-callback"},
3621 })
3622 tests = append(tests, testCase{
3623 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003624 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3625 config: Config{
3626 MaxVersion: VersionTLS13,
3627 ClientAuth: RequestClientCert,
3628 },
3629 flags: []string{"-use-old-client-cert-callback"},
3630 })
3631 tests = append(tests, testCase{
3632 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003633 name: "ClientAuth-OldCallback",
3634 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003635 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003636 ClientAuth: RequireAnyClientCert,
3637 },
3638 flags: []string{
3639 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3640 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3641 "-use-old-client-cert-callback",
3642 },
3643 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003644 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003645 testType: clientTest,
3646 name: "ClientAuth-OldCallback-TLS13",
3647 config: Config{
3648 MaxVersion: VersionTLS13,
3649 ClientAuth: RequireAnyClientCert,
3650 },
3651 flags: []string{
3652 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3653 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3654 "-use-old-client-cert-callback",
3655 },
3656 })
3657 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003658 testType: serverTest,
3659 name: "ClientAuth-Server",
3660 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003661 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003662 Certificates: []Certificate{rsaCertificate},
3663 },
3664 flags: []string{"-require-any-client-certificate"},
3665 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003666 tests = append(tests, testCase{
3667 testType: serverTest,
3668 name: "ClientAuth-Server-TLS13",
3669 config: Config{
3670 MaxVersion: VersionTLS13,
3671 Certificates: []Certificate{rsaCertificate},
3672 },
3673 flags: []string{"-require-any-client-certificate"},
3674 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003675
David Benjamin4c3ddf72016-06-29 18:13:53 -04003676 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003677 tests = append(tests, testCase{
3678 testType: serverTest,
3679 name: "Basic-Server-RSA",
3680 config: Config{
3681 MaxVersion: VersionTLS12,
3682 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3683 },
3684 flags: []string{
3685 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3686 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3687 },
3688 })
3689 tests = append(tests, testCase{
3690 testType: serverTest,
3691 name: "Basic-Server-ECDHE-RSA",
3692 config: Config{
3693 MaxVersion: VersionTLS12,
3694 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3695 },
3696 flags: []string{
3697 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3698 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3699 },
3700 })
3701 tests = append(tests, testCase{
3702 testType: serverTest,
3703 name: "Basic-Server-ECDHE-ECDSA",
3704 config: Config{
3705 MaxVersion: VersionTLS12,
3706 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3707 },
3708 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003709 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3710 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003711 },
3712 })
3713
David Benjamin760b1dd2015-05-15 23:33:48 -04003714 // No session ticket support; server doesn't send NewSessionTicket.
3715 tests = append(tests, testCase{
3716 name: "SessionTicketsDisabled-Client",
3717 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003718 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003719 SessionTicketsDisabled: true,
3720 },
3721 })
3722 tests = append(tests, testCase{
3723 testType: serverTest,
3724 name: "SessionTicketsDisabled-Server",
3725 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003726 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003727 SessionTicketsDisabled: true,
3728 },
3729 })
3730
3731 // Skip ServerKeyExchange in PSK key exchange if there's no
3732 // identity hint.
3733 tests = append(tests, testCase{
3734 name: "EmptyPSKHint-Client",
3735 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003736 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003737 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3738 PreSharedKey: []byte("secret"),
3739 },
3740 flags: []string{"-psk", "secret"},
3741 })
3742 tests = append(tests, testCase{
3743 testType: serverTest,
3744 name: "EmptyPSKHint-Server",
3745 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003746 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003747 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3748 PreSharedKey: []byte("secret"),
3749 },
3750 flags: []string{"-psk", "secret"},
3751 })
3752
David Benjamin4c3ddf72016-06-29 18:13:53 -04003753 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003754 tests = append(tests, testCase{
3755 testType: clientTest,
3756 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003757 config: Config{
3758 MaxVersion: VersionTLS12,
3759 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003760 flags: []string{
3761 "-enable-ocsp-stapling",
3762 "-expect-ocsp-response",
3763 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003764 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003765 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003766 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003767 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003768 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003769 testType: serverTest,
3770 name: "OCSPStapling-Server",
3771 config: Config{
3772 MaxVersion: VersionTLS12,
3773 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003774 expectedOCSPResponse: testOCSPResponse,
3775 flags: []string{
3776 "-ocsp-response",
3777 base64.StdEncoding.EncodeToString(testOCSPResponse),
3778 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003779 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003780 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003781 tests = append(tests, testCase{
3782 testType: clientTest,
3783 name: "OCSPStapling-Client-TLS13",
3784 config: Config{
3785 MaxVersion: VersionTLS13,
3786 },
3787 flags: []string{
3788 "-enable-ocsp-stapling",
3789 "-expect-ocsp-response",
3790 base64.StdEncoding.EncodeToString(testOCSPResponse),
3791 "-verify-peer",
3792 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003793 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003794 })
3795 tests = append(tests, testCase{
3796 testType: serverTest,
3797 name: "OCSPStapling-Server-TLS13",
3798 config: Config{
3799 MaxVersion: VersionTLS13,
3800 },
3801 expectedOCSPResponse: testOCSPResponse,
3802 flags: []string{
3803 "-ocsp-response",
3804 base64.StdEncoding.EncodeToString(testOCSPResponse),
3805 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003806 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003807 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003808
David Benjamin4c3ddf72016-06-29 18:13:53 -04003809 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003810 for _, vers := range tlsVersions {
3811 if config.protocol == dtls && !vers.hasDTLS {
3812 continue
3813 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003814 for _, testType := range []testType{clientTest, serverTest} {
3815 suffix := "-Client"
3816 if testType == serverTest {
3817 suffix = "-Server"
3818 }
3819 suffix += "-" + vers.name
3820
3821 flag := "-verify-peer"
3822 if testType == serverTest {
3823 flag = "-require-any-client-certificate"
3824 }
3825
3826 tests = append(tests, testCase{
3827 testType: testType,
3828 name: "CertificateVerificationSucceed" + suffix,
3829 config: Config{
3830 MaxVersion: vers.version,
3831 Certificates: []Certificate{rsaCertificate},
3832 },
3833 flags: []string{
3834 flag,
3835 "-expect-verify-result",
3836 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003837 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003838 })
3839 tests = append(tests, testCase{
3840 testType: testType,
3841 name: "CertificateVerificationFail" + suffix,
3842 config: Config{
3843 MaxVersion: vers.version,
3844 Certificates: []Certificate{rsaCertificate},
3845 },
3846 flags: []string{
3847 flag,
3848 "-verify-fail",
3849 },
3850 shouldFail: true,
3851 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3852 })
3853 }
3854
3855 // By default, the client is in a soft fail mode where the peer
3856 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003857 tests = append(tests, testCase{
3858 testType: clientTest,
3859 name: "CertificateVerificationSoftFail-" + vers.name,
3860 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003861 MaxVersion: vers.version,
3862 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003863 },
3864 flags: []string{
3865 "-verify-fail",
3866 "-expect-verify-result",
3867 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003868 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003869 })
3870 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003871
David Benjamin1d4f4c02016-07-26 18:03:08 -04003872 tests = append(tests, testCase{
3873 name: "ShimSendAlert",
3874 flags: []string{"-send-alert"},
3875 shimWritesFirst: true,
3876 shouldFail: true,
3877 expectedLocalError: "remote error: decompression failure",
3878 })
3879
David Benjamin582ba042016-07-07 12:33:25 -07003880 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003881 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003882 name: "Renegotiate-Client",
3883 config: Config{
3884 MaxVersion: VersionTLS12,
3885 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003886 renegotiate: 1,
3887 flags: []string{
3888 "-renegotiate-freely",
3889 "-expect-total-renegotiations", "1",
3890 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003891 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003892
David Benjamin47921102016-07-28 11:29:18 -04003893 tests = append(tests, testCase{
3894 name: "SendHalfHelloRequest",
3895 config: Config{
3896 MaxVersion: VersionTLS12,
3897 Bugs: ProtocolBugs{
3898 PackHelloRequestWithFinished: config.packHandshakeFlight,
3899 },
3900 },
3901 sendHalfHelloRequest: true,
3902 flags: []string{"-renegotiate-ignore"},
3903 shouldFail: true,
3904 expectedError: ":UNEXPECTED_RECORD:",
3905 })
3906
David Benjamin760b1dd2015-05-15 23:33:48 -04003907 // NPN on client and server; results in post-handshake message.
3908 tests = append(tests, testCase{
3909 name: "NPN-Client",
3910 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003911 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003912 NextProtos: []string{"foo"},
3913 },
3914 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003915 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003916 expectedNextProto: "foo",
3917 expectedNextProtoType: npn,
3918 })
3919 tests = append(tests, testCase{
3920 testType: serverTest,
3921 name: "NPN-Server",
3922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003923 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003924 NextProtos: []string{"bar"},
3925 },
3926 flags: []string{
3927 "-advertise-npn", "\x03foo\x03bar\x03baz",
3928 "-expect-next-proto", "bar",
3929 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003930 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003931 expectedNextProto: "bar",
3932 expectedNextProtoType: npn,
3933 })
3934
3935 // TODO(davidben): Add tests for when False Start doesn't trigger.
3936
3937 // Client does False Start and negotiates NPN.
3938 tests = append(tests, testCase{
3939 name: "FalseStart",
3940 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003941 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003942 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3943 NextProtos: []string{"foo"},
3944 Bugs: ProtocolBugs{
3945 ExpectFalseStart: true,
3946 },
3947 },
3948 flags: []string{
3949 "-false-start",
3950 "-select-next-proto", "foo",
3951 },
3952 shimWritesFirst: true,
3953 resumeSession: true,
3954 })
3955
3956 // Client does False Start and negotiates ALPN.
3957 tests = append(tests, testCase{
3958 name: "FalseStart-ALPN",
3959 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003960 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003961 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3962 NextProtos: []string{"foo"},
3963 Bugs: ProtocolBugs{
3964 ExpectFalseStart: true,
3965 },
3966 },
3967 flags: []string{
3968 "-false-start",
3969 "-advertise-alpn", "\x03foo",
3970 },
3971 shimWritesFirst: true,
3972 resumeSession: true,
3973 })
3974
3975 // Client does False Start but doesn't explicitly call
3976 // SSL_connect.
3977 tests = append(tests, testCase{
3978 name: "FalseStart-Implicit",
3979 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003980 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003981 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3982 NextProtos: []string{"foo"},
3983 },
3984 flags: []string{
3985 "-implicit-handshake",
3986 "-false-start",
3987 "-advertise-alpn", "\x03foo",
3988 },
3989 })
3990
3991 // False Start without session tickets.
3992 tests = append(tests, testCase{
3993 name: "FalseStart-SessionTicketsDisabled",
3994 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003995 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003996 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3997 NextProtos: []string{"foo"},
3998 SessionTicketsDisabled: true,
3999 Bugs: ProtocolBugs{
4000 ExpectFalseStart: true,
4001 },
4002 },
4003 flags: []string{
4004 "-false-start",
4005 "-select-next-proto", "foo",
4006 },
4007 shimWritesFirst: true,
4008 })
4009
Adam Langleydf759b52016-07-11 15:24:37 -07004010 tests = append(tests, testCase{
4011 name: "FalseStart-CECPQ1",
4012 config: Config{
4013 MaxVersion: VersionTLS12,
4014 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
4015 NextProtos: []string{"foo"},
4016 Bugs: ProtocolBugs{
4017 ExpectFalseStart: true,
4018 },
4019 },
4020 flags: []string{
4021 "-false-start",
4022 "-cipher", "DEFAULT:kCECPQ1",
4023 "-select-next-proto", "foo",
4024 },
4025 shimWritesFirst: true,
4026 resumeSession: true,
4027 })
4028
David Benjamin760b1dd2015-05-15 23:33:48 -04004029 // Server parses a V2ClientHello.
4030 tests = append(tests, testCase{
4031 testType: serverTest,
4032 name: "SendV2ClientHello",
4033 config: Config{
4034 // Choose a cipher suite that does not involve
4035 // elliptic curves, so no extensions are
4036 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07004037 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07004038 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04004039 Bugs: ProtocolBugs{
4040 SendV2ClientHello: true,
4041 },
4042 },
4043 })
4044
Nick Harper60a85cb2016-09-23 16:25:11 -07004045 // Test Channel ID
4046 for _, ver := range tlsVersions {
Nick Harperc9846112016-10-17 15:05:35 -07004047 if ver.version < VersionTLS10 {
Nick Harper60a85cb2016-09-23 16:25:11 -07004048 continue
4049 }
4050 // Client sends a Channel ID.
4051 tests = append(tests, testCase{
4052 name: "ChannelID-Client-" + ver.name,
4053 config: Config{
4054 MaxVersion: ver.version,
4055 RequestChannelID: true,
4056 },
4057 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
4058 resumeSession: true,
4059 expectChannelID: true,
4060 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004061
Nick Harper60a85cb2016-09-23 16:25:11 -07004062 // Server accepts a Channel ID.
4063 tests = append(tests, testCase{
4064 testType: serverTest,
4065 name: "ChannelID-Server-" + ver.name,
4066 config: Config{
4067 MaxVersion: ver.version,
4068 ChannelID: channelIDKey,
4069 },
4070 flags: []string{
4071 "-expect-channel-id",
4072 base64.StdEncoding.EncodeToString(channelIDBytes),
4073 },
4074 resumeSession: true,
4075 expectChannelID: true,
4076 })
4077
4078 tests = append(tests, testCase{
4079 testType: serverTest,
4080 name: "InvalidChannelIDSignature-" + ver.name,
4081 config: Config{
4082 MaxVersion: ver.version,
4083 ChannelID: channelIDKey,
4084 Bugs: ProtocolBugs{
4085 InvalidChannelIDSignature: true,
4086 },
4087 },
4088 flags: []string{"-enable-channel-id"},
4089 shouldFail: true,
4090 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
4091 })
4092 }
David Benjamin30789da2015-08-29 22:56:45 -04004093
David Benjaminf8fcdf32016-06-08 15:56:13 -04004094 // Channel ID and NPN at the same time, to ensure their relative
4095 // ordering is correct.
4096 tests = append(tests, testCase{
4097 name: "ChannelID-NPN-Client",
4098 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004099 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004100 RequestChannelID: true,
4101 NextProtos: []string{"foo"},
4102 },
4103 flags: []string{
4104 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
4105 "-select-next-proto", "foo",
4106 },
4107 resumeSession: true,
4108 expectChannelID: true,
4109 expectedNextProto: "foo",
4110 expectedNextProtoType: npn,
4111 })
4112 tests = append(tests, testCase{
4113 testType: serverTest,
4114 name: "ChannelID-NPN-Server",
4115 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004116 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04004117 ChannelID: channelIDKey,
4118 NextProtos: []string{"bar"},
4119 },
4120 flags: []string{
4121 "-expect-channel-id",
4122 base64.StdEncoding.EncodeToString(channelIDBytes),
4123 "-advertise-npn", "\x03foo\x03bar\x03baz",
4124 "-expect-next-proto", "bar",
4125 },
4126 resumeSession: true,
4127 expectChannelID: true,
4128 expectedNextProto: "bar",
4129 expectedNextProtoType: npn,
4130 })
4131
David Benjamin30789da2015-08-29 22:56:45 -04004132 // Bidirectional shutdown with the runner initiating.
4133 tests = append(tests, testCase{
4134 name: "Shutdown-Runner",
4135 config: Config{
4136 Bugs: ProtocolBugs{
4137 ExpectCloseNotify: true,
4138 },
4139 },
4140 flags: []string{"-check-close-notify"},
4141 })
4142
4143 // Bidirectional shutdown with the shim initiating. The runner,
4144 // in the meantime, sends garbage before the close_notify which
4145 // the shim must ignore.
4146 tests = append(tests, testCase{
4147 name: "Shutdown-Shim",
4148 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004149 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004150 Bugs: ProtocolBugs{
4151 ExpectCloseNotify: true,
4152 },
4153 },
4154 shimShutsDown: true,
4155 sendEmptyRecords: 1,
4156 sendWarningAlerts: 1,
4157 flags: []string{"-check-close-notify"},
4158 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004159 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004160 // TODO(davidben): DTLS 1.3 will want a similar thing for
4161 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004162 tests = append(tests, testCase{
4163 name: "SkipHelloVerifyRequest",
4164 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004165 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004166 Bugs: ProtocolBugs{
4167 SkipHelloVerifyRequest: true,
4168 },
4169 },
4170 })
4171 }
4172
David Benjamin760b1dd2015-05-15 23:33:48 -04004173 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004174 test.protocol = config.protocol
4175 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004176 test.name += "-DTLS"
4177 }
David Benjamin582ba042016-07-07 12:33:25 -07004178 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004179 test.name += "-Async"
4180 test.flags = append(test.flags, "-async")
4181 } else {
4182 test.name += "-Sync"
4183 }
David Benjamin582ba042016-07-07 12:33:25 -07004184 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004185 test.name += "-SplitHandshakeRecords"
4186 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004187 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004188 test.config.Bugs.MaxPacketLength = 256
4189 test.flags = append(test.flags, "-mtu", "256")
4190 }
4191 }
David Benjamin582ba042016-07-07 12:33:25 -07004192 if config.packHandshakeFlight {
4193 test.name += "-PackHandshakeFlight"
4194 test.config.Bugs.PackHandshakeFlight = true
4195 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004196 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004197 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004198}
4199
Adam Langley524e7172015-02-20 16:04:00 -08004200func addDDoSCallbackTests() {
4201 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004202 for _, resume := range []bool{false, true} {
4203 suffix := "Resume"
4204 if resume {
4205 suffix = "No" + suffix
4206 }
4207
4208 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004209 testType: serverTest,
4210 name: "Server-DDoS-OK-" + suffix,
4211 config: Config{
4212 MaxVersion: VersionTLS12,
4213 },
Adam Langley524e7172015-02-20 16:04:00 -08004214 flags: []string{"-install-ddos-callback"},
4215 resumeSession: resume,
4216 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004217 testCases = append(testCases, testCase{
4218 testType: serverTest,
4219 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4220 config: Config{
4221 MaxVersion: VersionTLS13,
4222 },
4223 flags: []string{"-install-ddos-callback"},
4224 resumeSession: resume,
4225 })
Adam Langley524e7172015-02-20 16:04:00 -08004226
4227 failFlag := "-fail-ddos-callback"
4228 if resume {
4229 failFlag = "-fail-second-ddos-callback"
4230 }
4231 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004232 testType: serverTest,
4233 name: "Server-DDoS-Reject-" + suffix,
4234 config: Config{
4235 MaxVersion: VersionTLS12,
4236 },
David Benjamin2c66e072016-09-16 15:58:00 -04004237 flags: []string{"-install-ddos-callback", failFlag},
4238 resumeSession: resume,
4239 shouldFail: true,
4240 expectedError: ":CONNECTION_REJECTED:",
4241 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004242 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004243 testCases = append(testCases, testCase{
4244 testType: serverTest,
4245 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4246 config: Config{
4247 MaxVersion: VersionTLS13,
4248 },
David Benjamin2c66e072016-09-16 15:58:00 -04004249 flags: []string{"-install-ddos-callback", failFlag},
4250 resumeSession: resume,
4251 shouldFail: true,
4252 expectedError: ":CONNECTION_REJECTED:",
4253 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004254 })
Adam Langley524e7172015-02-20 16:04:00 -08004255 }
4256}
4257
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004258func addVersionNegotiationTests() {
4259 for i, shimVers := range tlsVersions {
4260 // Assemble flags to disable all newer versions on the shim.
4261 var flags []string
4262 for _, vers := range tlsVersions[i+1:] {
4263 flags = append(flags, vers.flag)
4264 }
4265
Steven Valdezfdd10992016-09-15 16:27:05 -04004266 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004267 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004268 protocols := []protocol{tls}
4269 if runnerVers.hasDTLS && shimVers.hasDTLS {
4270 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004271 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004272 for _, protocol := range protocols {
4273 expectedVersion := shimVers.version
4274 if runnerVers.version < shimVers.version {
4275 expectedVersion = runnerVers.version
4276 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004277
David Benjamin8b8c0062014-11-23 02:47:52 -05004278 suffix := shimVers.name + "-" + runnerVers.name
4279 if protocol == dtls {
4280 suffix += "-DTLS"
4281 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004282
David Benjamin1eb367c2014-12-12 18:17:51 -05004283 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4284
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004285 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004286 clientVers := shimVers.version
4287 if clientVers > VersionTLS10 {
4288 clientVers = VersionTLS10
4289 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004290 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004291 serverVers := expectedVersion
4292 if expectedVersion >= VersionTLS13 {
4293 serverVers = VersionTLS10
4294 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004295 serverVers = versionToWire(serverVers, protocol == dtls)
4296
David Benjamin8b8c0062014-11-23 02:47:52 -05004297 testCases = append(testCases, testCase{
4298 protocol: protocol,
4299 testType: clientTest,
4300 name: "VersionNegotiation-Client-" + suffix,
4301 config: Config{
4302 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004303 Bugs: ProtocolBugs{
4304 ExpectInitialRecordVersion: clientVers,
4305 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004306 },
4307 flags: flags,
4308 expectedVersion: expectedVersion,
4309 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004310 testCases = append(testCases, testCase{
4311 protocol: protocol,
4312 testType: clientTest,
4313 name: "VersionNegotiation-Client2-" + suffix,
4314 config: Config{
4315 MaxVersion: runnerVers.version,
4316 Bugs: ProtocolBugs{
4317 ExpectInitialRecordVersion: clientVers,
4318 },
4319 },
4320 flags: []string{"-max-version", shimVersFlag},
4321 expectedVersion: expectedVersion,
4322 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004323
4324 testCases = append(testCases, testCase{
4325 protocol: protocol,
4326 testType: serverTest,
4327 name: "VersionNegotiation-Server-" + suffix,
4328 config: Config{
4329 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004330 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004331 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004332 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004333 },
4334 flags: flags,
4335 expectedVersion: expectedVersion,
4336 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004337 testCases = append(testCases, testCase{
4338 protocol: protocol,
4339 testType: serverTest,
4340 name: "VersionNegotiation-Server2-" + suffix,
4341 config: Config{
4342 MaxVersion: runnerVers.version,
4343 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004344 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004345 },
4346 },
4347 flags: []string{"-max-version", shimVersFlag},
4348 expectedVersion: expectedVersion,
4349 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004350 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004351 }
4352 }
David Benjamin95c69562016-06-29 18:15:03 -04004353
Steven Valdezfdd10992016-09-15 16:27:05 -04004354 // Test the version extension at all versions.
4355 for _, vers := range tlsVersions {
4356 protocols := []protocol{tls}
4357 if vers.hasDTLS {
4358 protocols = append(protocols, dtls)
4359 }
4360 for _, protocol := range protocols {
4361 suffix := vers.name
4362 if protocol == dtls {
4363 suffix += "-DTLS"
4364 }
4365
4366 wireVersion := versionToWire(vers.version, protocol == dtls)
4367 testCases = append(testCases, testCase{
4368 protocol: protocol,
4369 testType: serverTest,
4370 name: "VersionNegotiationExtension-" + suffix,
4371 config: Config{
4372 Bugs: ProtocolBugs{
4373 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4374 },
4375 },
4376 expectedVersion: vers.version,
4377 })
4378 }
4379
4380 }
4381
4382 // If all versions are unknown, negotiation fails.
4383 testCases = append(testCases, testCase{
4384 testType: serverTest,
4385 name: "NoSupportedVersions",
4386 config: Config{
4387 Bugs: ProtocolBugs{
4388 SendSupportedVersions: []uint16{0x1111},
4389 },
4390 },
4391 shouldFail: true,
4392 expectedError: ":UNSUPPORTED_PROTOCOL:",
4393 })
4394 testCases = append(testCases, testCase{
4395 protocol: dtls,
4396 testType: serverTest,
4397 name: "NoSupportedVersions-DTLS",
4398 config: Config{
4399 Bugs: ProtocolBugs{
4400 SendSupportedVersions: []uint16{0x1111},
4401 },
4402 },
4403 shouldFail: true,
4404 expectedError: ":UNSUPPORTED_PROTOCOL:",
4405 })
4406
4407 testCases = append(testCases, testCase{
4408 testType: serverTest,
4409 name: "ClientHelloVersionTooHigh",
4410 config: Config{
4411 MaxVersion: VersionTLS13,
4412 Bugs: ProtocolBugs{
4413 SendClientVersion: 0x0304,
4414 OmitSupportedVersions: true,
4415 },
4416 },
4417 expectedVersion: VersionTLS12,
4418 })
4419
4420 testCases = append(testCases, testCase{
4421 testType: serverTest,
4422 name: "ConflictingVersionNegotiation",
4423 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004424 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004425 SendClientVersion: VersionTLS12,
4426 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004427 },
4428 },
David Benjaminad75a662016-09-30 15:42:59 -04004429 // The extension takes precedence over the ClientHello version.
4430 expectedVersion: VersionTLS11,
4431 })
4432
4433 testCases = append(testCases, testCase{
4434 testType: serverTest,
4435 name: "ConflictingVersionNegotiation-2",
4436 config: Config{
4437 Bugs: ProtocolBugs{
4438 SendClientVersion: VersionTLS11,
4439 SendSupportedVersions: []uint16{VersionTLS12},
4440 },
4441 },
4442 // The extension takes precedence over the ClientHello version.
4443 expectedVersion: VersionTLS12,
4444 })
4445
4446 testCases = append(testCases, testCase{
4447 testType: serverTest,
4448 name: "RejectFinalTLS13",
4449 config: Config{
4450 Bugs: ProtocolBugs{
4451 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4452 },
4453 },
4454 // We currently implement a draft TLS 1.3 version. Ensure that
4455 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004456 expectedVersion: VersionTLS12,
4457 })
4458
Brian Smithf85d3232016-10-28 10:34:06 -10004459 // Test that the maximum version is selected regardless of the
4460 // client-sent order.
4461 testCases = append(testCases, testCase{
4462 testType: serverTest,
4463 name: "IgnoreClientVersionOrder",
4464 config: Config{
4465 Bugs: ProtocolBugs{
4466 SendSupportedVersions: []uint16{VersionTLS12, tls13DraftVersion},
4467 },
4468 },
4469 expectedVersion: VersionTLS13,
4470 })
4471
David Benjamin95c69562016-06-29 18:15:03 -04004472 // Test for version tolerance.
4473 testCases = append(testCases, testCase{
4474 testType: serverTest,
4475 name: "MinorVersionTolerance",
4476 config: Config{
4477 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004478 SendClientVersion: 0x03ff,
4479 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004480 },
4481 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004482 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004483 })
4484 testCases = append(testCases, testCase{
4485 testType: serverTest,
4486 name: "MajorVersionTolerance",
4487 config: Config{
4488 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004489 SendClientVersion: 0x0400,
4490 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004491 },
4492 },
David Benjaminad75a662016-09-30 15:42:59 -04004493 // TLS 1.3 must be negotiated with the supported_versions
4494 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004495 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004496 })
David Benjaminad75a662016-09-30 15:42:59 -04004497 testCases = append(testCases, testCase{
4498 testType: serverTest,
4499 name: "VersionTolerance-TLS13",
4500 config: Config{
4501 Bugs: ProtocolBugs{
4502 // Although TLS 1.3 does not use
4503 // ClientHello.version, it still tolerates high
4504 // values there.
4505 SendClientVersion: 0x0400,
4506 },
4507 },
4508 expectedVersion: VersionTLS13,
4509 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004510
David Benjamin95c69562016-06-29 18:15:03 -04004511 testCases = append(testCases, testCase{
4512 protocol: dtls,
4513 testType: serverTest,
4514 name: "MinorVersionTolerance-DTLS",
4515 config: Config{
4516 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004517 SendClientVersion: 0xfe00,
4518 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004519 },
4520 },
4521 expectedVersion: VersionTLS12,
4522 })
4523 testCases = append(testCases, testCase{
4524 protocol: dtls,
4525 testType: serverTest,
4526 name: "MajorVersionTolerance-DTLS",
4527 config: Config{
4528 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004529 SendClientVersion: 0xfdff,
4530 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004531 },
4532 },
4533 expectedVersion: VersionTLS12,
4534 })
4535
4536 // Test that versions below 3.0 are rejected.
4537 testCases = append(testCases, testCase{
4538 testType: serverTest,
4539 name: "VersionTooLow",
4540 config: Config{
4541 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004542 SendClientVersion: 0x0200,
4543 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004544 },
4545 },
4546 shouldFail: true,
4547 expectedError: ":UNSUPPORTED_PROTOCOL:",
4548 })
4549 testCases = append(testCases, testCase{
4550 protocol: dtls,
4551 testType: serverTest,
4552 name: "VersionTooLow-DTLS",
4553 config: Config{
4554 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004555 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004556 },
4557 },
4558 shouldFail: true,
4559 expectedError: ":UNSUPPORTED_PROTOCOL:",
4560 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004561
David Benjamin2dc02042016-09-19 19:57:37 -04004562 testCases = append(testCases, testCase{
4563 name: "ServerBogusVersion",
4564 config: Config{
4565 Bugs: ProtocolBugs{
4566 SendServerHelloVersion: 0x1234,
4567 },
4568 },
4569 shouldFail: true,
4570 expectedError: ":UNSUPPORTED_PROTOCOL:",
4571 })
4572
David Benjamin1f61f0d2016-07-10 12:20:35 -04004573 // Test TLS 1.3's downgrade signal.
4574 testCases = append(testCases, testCase{
4575 name: "Downgrade-TLS12-Client",
4576 config: Config{
4577 Bugs: ProtocolBugs{
4578 NegotiateVersion: VersionTLS12,
4579 },
4580 },
David Benjamin592b5322016-09-30 15:15:01 -04004581 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004582 // TODO(davidben): This test should fail once TLS 1.3 is final
4583 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004584 })
4585 testCases = append(testCases, testCase{
4586 testType: serverTest,
4587 name: "Downgrade-TLS12-Server",
4588 config: Config{
4589 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004590 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004591 },
4592 },
David Benjamin592b5322016-09-30 15:15:01 -04004593 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004594 // TODO(davidben): This test should fail once TLS 1.3 is final
4595 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004596 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004597}
4598
David Benjaminaccb4542014-12-12 23:44:33 -05004599func addMinimumVersionTests() {
4600 for i, shimVers := range tlsVersions {
4601 // Assemble flags to disable all older versions on the shim.
4602 var flags []string
4603 for _, vers := range tlsVersions[:i] {
4604 flags = append(flags, vers.flag)
4605 }
4606
4607 for _, runnerVers := range tlsVersions {
4608 protocols := []protocol{tls}
4609 if runnerVers.hasDTLS && shimVers.hasDTLS {
4610 protocols = append(protocols, dtls)
4611 }
4612 for _, protocol := range protocols {
4613 suffix := shimVers.name + "-" + runnerVers.name
4614 if protocol == dtls {
4615 suffix += "-DTLS"
4616 }
4617 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4618
David Benjaminaccb4542014-12-12 23:44:33 -05004619 var expectedVersion uint16
4620 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004621 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004622 if runnerVers.version >= shimVers.version {
4623 expectedVersion = runnerVers.version
4624 } else {
4625 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004626 expectedError = ":UNSUPPORTED_PROTOCOL:"
4627 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004628 }
4629
4630 testCases = append(testCases, testCase{
4631 protocol: protocol,
4632 testType: clientTest,
4633 name: "MinimumVersion-Client-" + suffix,
4634 config: Config{
4635 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004636 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004637 // Ensure the server does not decline to
4638 // select a version (versions extension) or
4639 // cipher (some ciphers depend on versions).
4640 NegotiateVersion: runnerVers.version,
4641 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004642 },
David Benjaminaccb4542014-12-12 23:44:33 -05004643 },
David Benjamin87909c02014-12-13 01:55:01 -05004644 flags: flags,
4645 expectedVersion: expectedVersion,
4646 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004647 expectedError: expectedError,
4648 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004649 })
4650 testCases = append(testCases, testCase{
4651 protocol: protocol,
4652 testType: clientTest,
4653 name: "MinimumVersion-Client2-" + suffix,
4654 config: Config{
4655 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004656 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004657 // Ensure the server does not decline to
4658 // select a version (versions extension) or
4659 // cipher (some ciphers depend on versions).
4660 NegotiateVersion: runnerVers.version,
4661 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004662 },
David Benjaminaccb4542014-12-12 23:44:33 -05004663 },
David Benjamin87909c02014-12-13 01:55:01 -05004664 flags: []string{"-min-version", shimVersFlag},
4665 expectedVersion: expectedVersion,
4666 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004667 expectedError: expectedError,
4668 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004669 })
4670
4671 testCases = append(testCases, testCase{
4672 protocol: protocol,
4673 testType: serverTest,
4674 name: "MinimumVersion-Server-" + suffix,
4675 config: Config{
4676 MaxVersion: runnerVers.version,
4677 },
David Benjamin87909c02014-12-13 01:55:01 -05004678 flags: flags,
4679 expectedVersion: expectedVersion,
4680 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004681 expectedError: expectedError,
4682 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004683 })
4684 testCases = append(testCases, testCase{
4685 protocol: protocol,
4686 testType: serverTest,
4687 name: "MinimumVersion-Server2-" + suffix,
4688 config: Config{
4689 MaxVersion: runnerVers.version,
4690 },
David Benjamin87909c02014-12-13 01:55:01 -05004691 flags: []string{"-min-version", shimVersFlag},
4692 expectedVersion: expectedVersion,
4693 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004694 expectedError: expectedError,
4695 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004696 })
4697 }
4698 }
4699 }
4700}
4701
David Benjamine78bfde2014-09-06 12:45:15 -04004702func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004703 // TODO(davidben): Extensions, where applicable, all move their server
4704 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4705 // tests for both. Also test interaction with 0-RTT when implemented.
4706
David Benjamin97d17d92016-07-14 16:12:00 -04004707 // Repeat extensions tests all versions except SSL 3.0.
4708 for _, ver := range tlsVersions {
4709 if ver.version == VersionSSL30 {
4710 continue
4711 }
4712
David Benjamin97d17d92016-07-14 16:12:00 -04004713 // Test that duplicate extensions are rejected.
4714 testCases = append(testCases, testCase{
4715 testType: clientTest,
4716 name: "DuplicateExtensionClient-" + ver.name,
4717 config: Config{
4718 MaxVersion: ver.version,
4719 Bugs: ProtocolBugs{
4720 DuplicateExtension: true,
4721 },
David Benjamine78bfde2014-09-06 12:45:15 -04004722 },
David Benjamin97d17d92016-07-14 16:12:00 -04004723 shouldFail: true,
4724 expectedLocalError: "remote error: error decoding message",
4725 })
4726 testCases = append(testCases, testCase{
4727 testType: serverTest,
4728 name: "DuplicateExtensionServer-" + ver.name,
4729 config: Config{
4730 MaxVersion: ver.version,
4731 Bugs: ProtocolBugs{
4732 DuplicateExtension: true,
4733 },
David Benjamine78bfde2014-09-06 12:45:15 -04004734 },
David Benjamin97d17d92016-07-14 16:12:00 -04004735 shouldFail: true,
4736 expectedLocalError: "remote error: error decoding message",
4737 })
4738
4739 // Test SNI.
4740 testCases = append(testCases, testCase{
4741 testType: clientTest,
4742 name: "ServerNameExtensionClient-" + ver.name,
4743 config: Config{
4744 MaxVersion: ver.version,
4745 Bugs: ProtocolBugs{
4746 ExpectServerName: "example.com",
4747 },
David Benjamine78bfde2014-09-06 12:45:15 -04004748 },
David Benjamin97d17d92016-07-14 16:12:00 -04004749 flags: []string{"-host-name", "example.com"},
4750 })
4751 testCases = append(testCases, testCase{
4752 testType: clientTest,
4753 name: "ServerNameExtensionClientMismatch-" + ver.name,
4754 config: Config{
4755 MaxVersion: ver.version,
4756 Bugs: ProtocolBugs{
4757 ExpectServerName: "mismatch.com",
4758 },
David Benjamine78bfde2014-09-06 12:45:15 -04004759 },
David Benjamin97d17d92016-07-14 16:12:00 -04004760 flags: []string{"-host-name", "example.com"},
4761 shouldFail: true,
4762 expectedLocalError: "tls: unexpected server name",
4763 })
4764 testCases = append(testCases, testCase{
4765 testType: clientTest,
4766 name: "ServerNameExtensionClientMissing-" + ver.name,
4767 config: Config{
4768 MaxVersion: ver.version,
4769 Bugs: ProtocolBugs{
4770 ExpectServerName: "missing.com",
4771 },
David Benjamine78bfde2014-09-06 12:45:15 -04004772 },
David Benjamin97d17d92016-07-14 16:12:00 -04004773 shouldFail: true,
4774 expectedLocalError: "tls: unexpected server name",
4775 })
4776 testCases = append(testCases, testCase{
4777 testType: serverTest,
4778 name: "ServerNameExtensionServer-" + ver.name,
4779 config: Config{
4780 MaxVersion: ver.version,
4781 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004782 },
David Benjamin97d17d92016-07-14 16:12:00 -04004783 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004784 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004785 })
4786
4787 // Test ALPN.
4788 testCases = append(testCases, testCase{
4789 testType: clientTest,
4790 name: "ALPNClient-" + ver.name,
4791 config: Config{
4792 MaxVersion: ver.version,
4793 NextProtos: []string{"foo"},
4794 },
4795 flags: []string{
4796 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4797 "-expect-alpn", "foo",
4798 },
4799 expectedNextProto: "foo",
4800 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004801 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004802 })
4803 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004804 testType: clientTest,
4805 name: "ALPNClient-Mismatch-" + ver.name,
4806 config: Config{
4807 MaxVersion: ver.version,
4808 Bugs: ProtocolBugs{
4809 SendALPN: "baz",
4810 },
4811 },
4812 flags: []string{
4813 "-advertise-alpn", "\x03foo\x03bar",
4814 },
4815 shouldFail: true,
4816 expectedError: ":INVALID_ALPN_PROTOCOL:",
4817 expectedLocalError: "remote error: illegal parameter",
4818 })
4819 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004820 testType: serverTest,
4821 name: "ALPNServer-" + ver.name,
4822 config: Config{
4823 MaxVersion: ver.version,
4824 NextProtos: []string{"foo", "bar", "baz"},
4825 },
4826 flags: []string{
4827 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4828 "-select-alpn", "foo",
4829 },
4830 expectedNextProto: "foo",
4831 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004832 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004833 })
4834 testCases = append(testCases, testCase{
4835 testType: serverTest,
4836 name: "ALPNServer-Decline-" + ver.name,
4837 config: Config{
4838 MaxVersion: ver.version,
4839 NextProtos: []string{"foo", "bar", "baz"},
4840 },
4841 flags: []string{"-decline-alpn"},
4842 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004843 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004844 })
4845
David Benjamin25fe85b2016-08-09 20:00:32 -04004846 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4847 // called once.
4848 testCases = append(testCases, testCase{
4849 testType: serverTest,
4850 name: "ALPNServer-Async-" + ver.name,
4851 config: Config{
4852 MaxVersion: ver.version,
4853 NextProtos: []string{"foo", "bar", "baz"},
4854 },
4855 flags: []string{
4856 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4857 "-select-alpn", "foo",
4858 "-async",
4859 },
4860 expectedNextProto: "foo",
4861 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004862 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004863 })
4864
David Benjamin97d17d92016-07-14 16:12:00 -04004865 var emptyString string
4866 testCases = append(testCases, testCase{
4867 testType: clientTest,
4868 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4869 config: Config{
4870 MaxVersion: ver.version,
4871 NextProtos: []string{""},
4872 Bugs: ProtocolBugs{
4873 // A server returning an empty ALPN protocol
4874 // should be rejected.
4875 ALPNProtocol: &emptyString,
4876 },
4877 },
4878 flags: []string{
4879 "-advertise-alpn", "\x03foo",
4880 },
4881 shouldFail: true,
4882 expectedError: ":PARSE_TLSEXT:",
4883 })
4884 testCases = append(testCases, testCase{
4885 testType: serverTest,
4886 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4887 config: Config{
4888 MaxVersion: ver.version,
4889 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004890 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004891 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004892 },
David Benjamin97d17d92016-07-14 16:12:00 -04004893 flags: []string{
4894 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004895 },
David Benjamin97d17d92016-07-14 16:12:00 -04004896 shouldFail: true,
4897 expectedError: ":PARSE_TLSEXT:",
4898 })
4899
4900 // Test NPN and the interaction with ALPN.
4901 if ver.version < VersionTLS13 {
4902 // Test that the server prefers ALPN over NPN.
4903 testCases = append(testCases, testCase{
4904 testType: serverTest,
4905 name: "ALPNServer-Preferred-" + ver.name,
4906 config: Config{
4907 MaxVersion: ver.version,
4908 NextProtos: []string{"foo", "bar", "baz"},
4909 },
4910 flags: []string{
4911 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4912 "-select-alpn", "foo",
4913 "-advertise-npn", "\x03foo\x03bar\x03baz",
4914 },
4915 expectedNextProto: "foo",
4916 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004917 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004918 })
4919 testCases = append(testCases, testCase{
4920 testType: serverTest,
4921 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4922 config: Config{
4923 MaxVersion: ver.version,
4924 NextProtos: []string{"foo", "bar", "baz"},
4925 Bugs: ProtocolBugs{
4926 SwapNPNAndALPN: true,
4927 },
4928 },
4929 flags: []string{
4930 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4931 "-select-alpn", "foo",
4932 "-advertise-npn", "\x03foo\x03bar\x03baz",
4933 },
4934 expectedNextProto: "foo",
4935 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004936 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004937 })
4938
4939 // Test that negotiating both NPN and ALPN is forbidden.
4940 testCases = append(testCases, testCase{
4941 name: "NegotiateALPNAndNPN-" + ver.name,
4942 config: Config{
4943 MaxVersion: ver.version,
4944 NextProtos: []string{"foo", "bar", "baz"},
4945 Bugs: ProtocolBugs{
4946 NegotiateALPNAndNPN: true,
4947 },
4948 },
4949 flags: []string{
4950 "-advertise-alpn", "\x03foo",
4951 "-select-next-proto", "foo",
4952 },
4953 shouldFail: true,
4954 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4955 })
4956 testCases = append(testCases, testCase{
4957 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4958 config: Config{
4959 MaxVersion: ver.version,
4960 NextProtos: []string{"foo", "bar", "baz"},
4961 Bugs: ProtocolBugs{
4962 NegotiateALPNAndNPN: true,
4963 SwapNPNAndALPN: 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
4974 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4975 testCases = append(testCases, testCase{
4976 name: "DisableNPN-" + ver.name,
4977 config: Config{
4978 MaxVersion: ver.version,
4979 NextProtos: []string{"foo"},
4980 },
4981 flags: []string{
4982 "-select-next-proto", "foo",
4983 "-disable-npn",
4984 },
4985 expectNoNextProto: true,
4986 })
4987 }
4988
4989 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004990
4991 // Resume with a corrupt ticket.
4992 testCases = append(testCases, testCase{
4993 testType: serverTest,
4994 name: "CorruptTicket-" + ver.name,
4995 config: Config{
4996 MaxVersion: ver.version,
4997 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04004998 FilterTicket: func(in []byte) ([]byte, error) {
4999 in[len(in)-1] ^= 1
5000 return in, nil
5001 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005002 },
5003 },
5004 resumeSession: true,
5005 expectResumeRejected: true,
5006 })
5007 // Test the ticket callback, with and without renewal.
5008 testCases = append(testCases, testCase{
5009 testType: serverTest,
5010 name: "TicketCallback-" + ver.name,
5011 config: Config{
5012 MaxVersion: ver.version,
5013 },
5014 resumeSession: true,
5015 flags: []string{"-use-ticket-callback"},
5016 })
5017 testCases = append(testCases, testCase{
5018 testType: serverTest,
5019 name: "TicketCallback-Renew-" + ver.name,
5020 config: Config{
5021 MaxVersion: ver.version,
5022 Bugs: ProtocolBugs{
5023 ExpectNewTicket: true,
5024 },
5025 },
5026 flags: []string{"-use-ticket-callback", "-renew-ticket"},
5027 resumeSession: true,
5028 })
5029
5030 // Test that the ticket callback is only called once when everything before
5031 // it in the ClientHello is asynchronous. This corrupts the ticket so
5032 // certificate selection callbacks run.
5033 testCases = append(testCases, testCase{
5034 testType: serverTest,
5035 name: "TicketCallback-SingleCall-" + ver.name,
5036 config: Config{
5037 MaxVersion: ver.version,
5038 Bugs: ProtocolBugs{
David Benjamin4199b0d2016-11-01 13:58:25 -04005039 FilterTicket: func(in []byte) ([]byte, error) {
5040 in[len(in)-1] ^= 1
5041 return in, nil
5042 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005043 },
5044 },
5045 resumeSession: true,
5046 expectResumeRejected: true,
5047 flags: []string{
5048 "-use-ticket-callback",
5049 "-async",
5050 },
5051 })
5052
5053 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04005054 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04005055 testCases = append(testCases, testCase{
5056 testType: serverTest,
5057 name: "OversizedSessionId-" + ver.name,
5058 config: Config{
5059 MaxVersion: ver.version,
5060 Bugs: ProtocolBugs{
5061 OversizedSessionId: true,
5062 },
5063 },
5064 resumeSession: true,
5065 shouldFail: true,
5066 expectedError: ":DECODE_ERROR:",
5067 })
5068 }
5069
5070 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
5071 // are ignored.
5072 if ver.hasDTLS {
5073 testCases = append(testCases, testCase{
5074 protocol: dtls,
5075 name: "SRTP-Client-" + ver.name,
5076 config: Config{
5077 MaxVersion: ver.version,
5078 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5079 },
5080 flags: []string{
5081 "-srtp-profiles",
5082 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5083 },
5084 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5085 })
5086 testCases = append(testCases, testCase{
5087 protocol: dtls,
5088 testType: serverTest,
5089 name: "SRTP-Server-" + ver.name,
5090 config: Config{
5091 MaxVersion: ver.version,
5092 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
5093 },
5094 flags: []string{
5095 "-srtp-profiles",
5096 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5097 },
5098 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5099 })
5100 // Test that the MKI is ignored.
5101 testCases = append(testCases, testCase{
5102 protocol: dtls,
5103 testType: serverTest,
5104 name: "SRTP-Server-IgnoreMKI-" + ver.name,
5105 config: Config{
5106 MaxVersion: ver.version,
5107 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
5108 Bugs: ProtocolBugs{
5109 SRTPMasterKeyIdentifer: "bogus",
5110 },
5111 },
5112 flags: []string{
5113 "-srtp-profiles",
5114 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5115 },
5116 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
5117 })
5118 // Test that SRTP isn't negotiated on the server if there were
5119 // no matching profiles.
5120 testCases = append(testCases, testCase{
5121 protocol: dtls,
5122 testType: serverTest,
5123 name: "SRTP-Server-NoMatch-" + ver.name,
5124 config: Config{
5125 MaxVersion: ver.version,
5126 SRTPProtectionProfiles: []uint16{100, 101, 102},
5127 },
5128 flags: []string{
5129 "-srtp-profiles",
5130 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
5131 },
5132 expectedSRTPProtectionProfile: 0,
5133 })
5134 // Test that the server returning an invalid SRTP profile is
5135 // flagged as an error by the client.
5136 testCases = append(testCases, testCase{
5137 protocol: dtls,
5138 name: "SRTP-Client-NoMatch-" + ver.name,
5139 config: Config{
5140 MaxVersion: ver.version,
5141 Bugs: ProtocolBugs{
5142 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
5143 },
5144 },
5145 flags: []string{
5146 "-srtp-profiles",
5147 "SRTP_AES128_CM_SHA1_80",
5148 },
5149 shouldFail: true,
5150 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5151 })
5152 }
5153
5154 // Test SCT list.
5155 testCases = append(testCases, testCase{
5156 name: "SignedCertificateTimestampList-Client-" + ver.name,
5157 testType: clientTest,
5158 config: Config{
5159 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005160 },
David Benjamin97d17d92016-07-14 16:12:00 -04005161 flags: []string{
5162 "-enable-signed-cert-timestamps",
5163 "-expect-signed-cert-timestamps",
5164 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005165 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005166 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005167 })
David Benjamindaa88502016-10-04 16:32:16 -04005168
5169 // The SCT extension did not specify that it must only be sent on resumption as it
5170 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005171 testCases = append(testCases, testCase{
5172 name: "SendSCTListOnResume-" + ver.name,
5173 config: Config{
5174 MaxVersion: ver.version,
5175 Bugs: ProtocolBugs{
5176 SendSCTListOnResume: []byte("bogus"),
5177 },
David Benjamind98452d2015-06-16 14:16:23 -04005178 },
David Benjamin97d17d92016-07-14 16:12:00 -04005179 flags: []string{
5180 "-enable-signed-cert-timestamps",
5181 "-expect-signed-cert-timestamps",
5182 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005183 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005184 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005185 })
David Benjamindaa88502016-10-04 16:32:16 -04005186
David Benjamin97d17d92016-07-14 16:12:00 -04005187 testCases = append(testCases, testCase{
5188 name: "SignedCertificateTimestampList-Server-" + ver.name,
5189 testType: serverTest,
5190 config: Config{
5191 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005192 },
David Benjamin97d17d92016-07-14 16:12:00 -04005193 flags: []string{
5194 "-signed-cert-timestamps",
5195 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005196 },
David Benjamin97d17d92016-07-14 16:12:00 -04005197 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005198 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005199 })
5200 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005201
Paul Lietar4fac72e2015-09-09 13:44:55 +01005202 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005203 testType: clientTest,
5204 name: "ClientHelloPadding",
5205 config: Config{
5206 Bugs: ProtocolBugs{
5207 RequireClientHelloSize: 512,
5208 },
5209 },
5210 // This hostname just needs to be long enough to push the
5211 // ClientHello into F5's danger zone between 256 and 511 bytes
5212 // long.
5213 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5214 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005215
5216 // Extensions should not function in SSL 3.0.
5217 testCases = append(testCases, testCase{
5218 testType: serverTest,
5219 name: "SSLv3Extensions-NoALPN",
5220 config: Config{
5221 MaxVersion: VersionSSL30,
5222 NextProtos: []string{"foo", "bar", "baz"},
5223 },
5224 flags: []string{
5225 "-select-alpn", "foo",
5226 },
5227 expectNoNextProto: true,
5228 })
5229
5230 // Test session tickets separately as they follow a different codepath.
5231 testCases = append(testCases, testCase{
5232 testType: serverTest,
5233 name: "SSLv3Extensions-NoTickets",
5234 config: Config{
5235 MaxVersion: VersionSSL30,
5236 Bugs: ProtocolBugs{
5237 // Historically, session tickets in SSL 3.0
5238 // failed in different ways depending on whether
5239 // the client supported renegotiation_info.
5240 NoRenegotiationInfo: true,
5241 },
5242 },
5243 resumeSession: true,
5244 })
5245 testCases = append(testCases, testCase{
5246 testType: serverTest,
5247 name: "SSLv3Extensions-NoTickets2",
5248 config: Config{
5249 MaxVersion: VersionSSL30,
5250 },
5251 resumeSession: true,
5252 })
5253
5254 // But SSL 3.0 does send and process renegotiation_info.
5255 testCases = append(testCases, testCase{
5256 testType: serverTest,
5257 name: "SSLv3Extensions-RenegotiationInfo",
5258 config: Config{
5259 MaxVersion: VersionSSL30,
5260 Bugs: ProtocolBugs{
5261 RequireRenegotiationInfo: true,
5262 },
5263 },
5264 })
5265 testCases = append(testCases, testCase{
5266 testType: serverTest,
5267 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5268 config: Config{
5269 MaxVersion: VersionSSL30,
5270 Bugs: ProtocolBugs{
5271 NoRenegotiationInfo: true,
5272 SendRenegotiationSCSV: true,
5273 RequireRenegotiationInfo: true,
5274 },
5275 },
5276 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005277
5278 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5279 // in ServerHello.
5280 testCases = append(testCases, testCase{
5281 name: "NPN-Forbidden-TLS13",
5282 config: Config{
5283 MaxVersion: VersionTLS13,
5284 NextProtos: []string{"foo"},
5285 Bugs: ProtocolBugs{
5286 NegotiateNPNAtAllVersions: true,
5287 },
5288 },
5289 flags: []string{"-select-next-proto", "foo"},
5290 shouldFail: true,
5291 expectedError: ":ERROR_PARSING_EXTENSION:",
5292 })
5293 testCases = append(testCases, testCase{
5294 name: "EMS-Forbidden-TLS13",
5295 config: Config{
5296 MaxVersion: VersionTLS13,
5297 Bugs: ProtocolBugs{
5298 NegotiateEMSAtAllVersions: true,
5299 },
5300 },
5301 shouldFail: true,
5302 expectedError: ":ERROR_PARSING_EXTENSION:",
5303 })
5304 testCases = append(testCases, testCase{
5305 name: "RenegotiationInfo-Forbidden-TLS13",
5306 config: Config{
5307 MaxVersion: VersionTLS13,
5308 Bugs: ProtocolBugs{
5309 NegotiateRenegotiationInfoAtAllVersions: true,
5310 },
5311 },
5312 shouldFail: true,
5313 expectedError: ":ERROR_PARSING_EXTENSION:",
5314 })
5315 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005316 name: "Ticket-Forbidden-TLS13",
5317 config: Config{
5318 MaxVersion: VersionTLS12,
5319 },
5320 resumeConfig: &Config{
5321 MaxVersion: VersionTLS13,
5322 Bugs: ProtocolBugs{
5323 AdvertiseTicketExtension: true,
5324 },
5325 },
5326 resumeSession: true,
5327 shouldFail: true,
5328 expectedError: ":ERROR_PARSING_EXTENSION:",
5329 })
5330
5331 // Test that illegal extensions in TLS 1.3 are declined by the server if
5332 // offered in ClientHello. The runner's server will fail if this occurs,
5333 // so we exercise the offering path. (EMS and Renegotiation Info are
5334 // implicit in every test.)
5335 testCases = append(testCases, testCase{
5336 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005337 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005338 config: Config{
5339 MaxVersion: VersionTLS13,
5340 NextProtos: []string{"bar"},
5341 },
5342 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5343 })
David Benjamin196df5b2016-09-21 16:23:27 -04005344
David Benjamindaa88502016-10-04 16:32:16 -04005345 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5346 // tolerated.
5347 testCases = append(testCases, testCase{
5348 name: "SendOCSPResponseOnResume-TLS12",
5349 config: Config{
5350 MaxVersion: VersionTLS12,
5351 Bugs: ProtocolBugs{
5352 SendOCSPResponseOnResume: []byte("bogus"),
5353 },
5354 },
5355 flags: []string{
5356 "-enable-ocsp-stapling",
5357 "-expect-ocsp-response",
5358 base64.StdEncoding.EncodeToString(testOCSPResponse),
5359 },
5360 resumeSession: true,
5361 })
5362
David Benjamindaa88502016-10-04 16:32:16 -04005363 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005364 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005365 config: Config{
5366 MaxVersion: VersionTLS13,
5367 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005368 SendExtensionOnCertificate: testOCSPExtension,
5369 },
5370 },
5371 shouldFail: true,
5372 expectedError: ":UNEXPECTED_EXTENSION:",
5373 })
5374
5375 testCases = append(testCases, testCase{
5376 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5377 config: Config{
5378 MaxVersion: VersionTLS13,
5379 Bugs: ProtocolBugs{
5380 SendExtensionOnCertificate: testSCTExtension,
5381 },
5382 },
5383 shouldFail: true,
5384 expectedError: ":UNEXPECTED_EXTENSION:",
5385 })
5386
5387 // Test that extensions on client certificates are never accepted.
5388 testCases = append(testCases, testCase{
5389 name: "SendExtensionOnClientCertificate-TLS13",
5390 testType: serverTest,
5391 config: Config{
5392 MaxVersion: VersionTLS13,
5393 Certificates: []Certificate{rsaCertificate},
5394 Bugs: ProtocolBugs{
5395 SendExtensionOnCertificate: testOCSPExtension,
5396 },
5397 },
5398 flags: []string{
5399 "-enable-ocsp-stapling",
5400 "-require-any-client-certificate",
5401 },
5402 shouldFail: true,
5403 expectedError: ":UNEXPECTED_EXTENSION:",
5404 })
5405
5406 testCases = append(testCases, testCase{
5407 name: "SendUnknownExtensionOnCertificate-TLS13",
5408 config: Config{
5409 MaxVersion: VersionTLS13,
5410 Bugs: ProtocolBugs{
5411 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5412 },
5413 },
5414 shouldFail: true,
5415 expectedError: ":UNEXPECTED_EXTENSION:",
5416 })
5417
5418 // Test that extensions on intermediates are allowed but ignored.
5419 testCases = append(testCases, testCase{
5420 name: "IgnoreExtensionsOnIntermediates-TLS13",
5421 config: Config{
5422 MaxVersion: VersionTLS13,
5423 Certificates: []Certificate{rsaChainCertificate},
5424 Bugs: ProtocolBugs{
5425 // Send different values on the intermediate. This tests
5426 // the intermediate's extensions do not override the
5427 // leaf's.
5428 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
5429 SendSCTOnIntermediates: []byte{1, 3, 3, 7},
David Benjamindaa88502016-10-04 16:32:16 -04005430 },
5431 },
5432 flags: []string{
5433 "-enable-ocsp-stapling",
5434 "-expect-ocsp-response",
5435 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005436 "-enable-signed-cert-timestamps",
5437 "-expect-signed-cert-timestamps",
5438 base64.StdEncoding.EncodeToString(testSCTList),
5439 },
5440 resumeSession: true,
5441 })
5442
5443 // Test that extensions are not sent on intermediates when configured
5444 // only for a leaf.
5445 testCases = append(testCases, testCase{
5446 testType: serverTest,
5447 name: "SendNoExtensionsOnIntermediate-TLS13",
5448 config: Config{
5449 MaxVersion: VersionTLS13,
5450 Bugs: ProtocolBugs{
5451 ExpectNoExtensionsOnIntermediate: true,
5452 },
5453 },
5454 flags: []string{
5455 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5456 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5457 "-ocsp-response",
5458 base64.StdEncoding.EncodeToString(testOCSPResponse),
5459 "-signed-cert-timestamps",
5460 base64.StdEncoding.EncodeToString(testSCTList),
5461 },
5462 })
5463
5464 // Test that extensions are not sent on client certificates.
5465 testCases = append(testCases, testCase{
5466 name: "SendNoClientCertificateExtensions-TLS13",
5467 config: Config{
5468 MaxVersion: VersionTLS13,
5469 ClientAuth: RequireAnyClientCert,
5470 },
5471 flags: []string{
5472 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5473 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5474 "-ocsp-response",
5475 base64.StdEncoding.EncodeToString(testOCSPResponse),
5476 "-signed-cert-timestamps",
5477 base64.StdEncoding.EncodeToString(testSCTList),
5478 },
5479 })
5480
5481 testCases = append(testCases, testCase{
5482 name: "SendDuplicateExtensionsOnCerts-TLS13",
5483 config: Config{
5484 MaxVersion: VersionTLS13,
5485 Bugs: ProtocolBugs{
5486 SendDuplicateCertExtensions: true,
5487 },
5488 },
5489 flags: []string{
5490 "-enable-ocsp-stapling",
5491 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005492 },
5493 resumeSession: true,
5494 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005495 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005496 })
David Benjamine78bfde2014-09-06 12:45:15 -04005497}
5498
David Benjamin01fe8202014-09-24 15:21:44 -04005499func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005500 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005501 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005502 // SSL 3.0 does not have tickets and TLS 1.3 does not
5503 // have session IDs, so skip their cross-resumption
5504 // tests.
5505 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5506 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5507 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005508 }
5509
David Benjamin8b8c0062014-11-23 02:47:52 -05005510 protocols := []protocol{tls}
5511 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5512 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005513 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005514 for _, protocol := range protocols {
5515 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5516 if protocol == dtls {
5517 suffix += "-DTLS"
5518 }
5519
David Benjaminece3de92015-03-16 18:02:20 -04005520 if sessionVers.version == resumeVers.version {
5521 testCases = append(testCases, testCase{
5522 protocol: protocol,
5523 name: "Resume-Client" + suffix,
5524 resumeSession: true,
5525 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005526 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005527 Bugs: ProtocolBugs{
5528 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5529 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5530 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005531 },
David Benjaminece3de92015-03-16 18:02:20 -04005532 expectedVersion: sessionVers.version,
5533 expectedResumeVersion: resumeVers.version,
5534 })
5535 } else {
David Benjamin405da482016-08-08 17:25:07 -04005536 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5537
5538 // Offering a TLS 1.3 session sends an empty session ID, so
5539 // there is no way to convince a non-lookahead client the
5540 // session was resumed. It will appear to the client that a
5541 // stray ChangeCipherSpec was sent.
5542 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5543 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005544 }
5545
David Benjaminece3de92015-03-16 18:02:20 -04005546 testCases = append(testCases, testCase{
5547 protocol: protocol,
5548 name: "Resume-Client-Mismatch" + suffix,
5549 resumeSession: true,
5550 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005551 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005552 },
David Benjaminece3de92015-03-16 18:02:20 -04005553 expectedVersion: sessionVers.version,
5554 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005555 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005556 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005557 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005558 },
5559 },
5560 expectedResumeVersion: resumeVers.version,
5561 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005562 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005563 })
5564 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005565
5566 testCases = append(testCases, testCase{
5567 protocol: protocol,
5568 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005569 resumeSession: true,
5570 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005571 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005572 },
5573 expectedVersion: sessionVers.version,
5574 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005575 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005576 },
5577 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005578 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005579 expectedResumeVersion: resumeVers.version,
5580 })
5581
David Benjamin8b8c0062014-11-23 02:47:52 -05005582 testCases = append(testCases, testCase{
5583 protocol: protocol,
5584 testType: serverTest,
5585 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005586 resumeSession: true,
5587 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005588 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005589 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005590 expectedVersion: sessionVers.version,
5591 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005592 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005593 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005594 Bugs: ProtocolBugs{
5595 SendBothTickets: true,
5596 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005597 },
5598 expectedResumeVersion: resumeVers.version,
5599 })
5600 }
David Benjamin01fe8202014-09-24 15:21:44 -04005601 }
5602 }
David Benjaminece3de92015-03-16 18:02:20 -04005603
David Benjamin4199b0d2016-11-01 13:58:25 -04005604 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005605 testCases = append(testCases, testCase{
5606 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005607 name: "ShimTicketRewritable",
5608 resumeSession: true,
5609 config: Config{
5610 MaxVersion: VersionTLS12,
5611 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5612 Bugs: ProtocolBugs{
5613 FilterTicket: func(in []byte) ([]byte, error) {
5614 in, err := SetShimTicketVersion(in, VersionTLS12)
5615 if err != nil {
5616 return nil, err
5617 }
5618 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5619 },
5620 },
5621 },
5622 flags: []string{
5623 "-ticket-key",
5624 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5625 },
5626 })
5627
5628 // Resumptions are declined if the version does not match.
5629 testCases = append(testCases, testCase{
5630 testType: serverTest,
5631 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005632 resumeSession: true,
5633 config: Config{
5634 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005635 Bugs: ProtocolBugs{
5636 FilterTicket: func(in []byte) ([]byte, error) {
5637 return SetShimTicketVersion(in, VersionTLS13)
5638 },
5639 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005640 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005641 flags: []string{
5642 "-ticket-key",
5643 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5644 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005645 expectResumeRejected: true,
5646 })
5647
5648 testCases = append(testCases, testCase{
5649 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005650 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005651 resumeSession: true,
5652 config: Config{
5653 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005654 Bugs: ProtocolBugs{
5655 FilterTicket: func(in []byte) ([]byte, error) {
5656 return SetShimTicketVersion(in, VersionTLS12)
5657 },
5658 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005659 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005660 flags: []string{
5661 "-ticket-key",
5662 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5663 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005664 expectResumeRejected: true,
5665 })
5666
David Benjamin4199b0d2016-11-01 13:58:25 -04005667 // Resumptions are declined if the cipher is invalid or disabled.
5668 testCases = append(testCases, testCase{
5669 testType: serverTest,
5670 name: "Resume-Server-DeclineBadCipher",
5671 resumeSession: true,
5672 config: Config{
5673 MaxVersion: VersionTLS12,
5674 Bugs: ProtocolBugs{
5675 FilterTicket: func(in []byte) ([]byte, error) {
5676 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5677 },
5678 },
5679 },
5680 flags: []string{
5681 "-ticket-key",
5682 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5683 },
5684 expectResumeRejected: true,
5685 })
5686
5687 testCases = append(testCases, testCase{
5688 testType: serverTest,
5689 name: "Resume-Server-DeclineBadCipher-2",
5690 resumeSession: true,
5691 config: Config{
5692 MaxVersion: VersionTLS12,
5693 Bugs: ProtocolBugs{
5694 FilterTicket: func(in []byte) ([]byte, error) {
5695 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5696 },
5697 },
5698 },
5699 flags: []string{
5700 "-cipher", "AES128",
5701 "-ticket-key",
5702 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5703 },
5704 expectResumeRejected: true,
5705 })
5706
5707 testCases = append(testCases, testCase{
5708 testType: serverTest,
5709 name: "Resume-Server-DeclineBadCipher-TLS13",
5710 resumeSession: true,
5711 config: Config{
5712 MaxVersion: VersionTLS13,
5713 Bugs: ProtocolBugs{
5714 FilterTicket: func(in []byte) ([]byte, error) {
5715 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5716 },
5717 },
5718 },
5719 flags: []string{
5720 "-ticket-key",
5721 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5722 },
5723 expectResumeRejected: true,
5724 })
5725
David Benjamin4199b0d2016-11-01 13:58:25 -04005726 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005727 testCases = append(testCases, testCase{
5728 name: "Resume-Client-CipherMismatch",
5729 resumeSession: true,
5730 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005731 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005732 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5733 },
5734 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005735 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005736 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5737 Bugs: ProtocolBugs{
5738 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5739 },
5740 },
5741 shouldFail: true,
5742 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5743 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005744
5745 testCases = append(testCases, testCase{
5746 name: "Resume-Client-CipherMismatch-TLS13",
5747 resumeSession: true,
5748 config: Config{
5749 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005750 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005751 },
5752 resumeConfig: &Config{
5753 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005754 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005755 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005756 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005757 },
5758 },
5759 shouldFail: true,
5760 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5761 })
Steven Valdeza833c352016-11-01 13:39:36 -04005762
5763 testCases = append(testCases, testCase{
5764 testType: serverTest,
5765 name: "Resume-Server-BinderWrongLength",
5766 resumeSession: true,
5767 config: Config{
5768 MaxVersion: VersionTLS13,
5769 Bugs: ProtocolBugs{
5770 SendShortPSKBinder: true,
5771 },
5772 },
5773 shouldFail: true,
5774 expectedLocalError: "remote error: error decrypting message",
5775 expectedError: ":DIGEST_CHECK_FAILED:",
5776 })
5777
5778 testCases = append(testCases, testCase{
5779 testType: serverTest,
5780 name: "Resume-Server-NoPSKBinder",
5781 resumeSession: true,
5782 config: Config{
5783 MaxVersion: VersionTLS13,
5784 Bugs: ProtocolBugs{
5785 SendNoPSKBinder: true,
5786 },
5787 },
5788 shouldFail: true,
5789 expectedLocalError: "remote error: error decoding message",
5790 expectedError: ":DECODE_ERROR:",
5791 })
5792
5793 testCases = append(testCases, testCase{
5794 testType: serverTest,
5795 name: "Resume-Server-InvalidPSKBinder",
5796 resumeSession: true,
5797 config: Config{
5798 MaxVersion: VersionTLS13,
5799 Bugs: ProtocolBugs{
5800 SendInvalidPSKBinder: true,
5801 },
5802 },
5803 shouldFail: true,
5804 expectedLocalError: "remote error: error decrypting message",
5805 expectedError: ":DIGEST_CHECK_FAILED:",
5806 })
5807
5808 testCases = append(testCases, testCase{
5809 testType: serverTest,
5810 name: "Resume-Server-PSKBinderFirstExtension",
5811 resumeSession: true,
5812 config: Config{
5813 MaxVersion: VersionTLS13,
5814 Bugs: ProtocolBugs{
5815 PSKBinderFirst: true,
5816 },
5817 },
5818 shouldFail: true,
5819 expectedLocalError: "remote error: illegal parameter",
5820 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
5821 })
David Benjamin01fe8202014-09-24 15:21:44 -04005822}
5823
Adam Langley2ae77d22014-10-28 17:29:33 -07005824func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005825 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005826 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005827 testType: serverTest,
5828 name: "Renegotiate-Server-Forbidden",
5829 config: Config{
5830 MaxVersion: VersionTLS12,
5831 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005832 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005833 shouldFail: true,
5834 expectedError: ":NO_RENEGOTIATION:",
5835 expectedLocalError: "remote error: no renegotiation",
5836 })
Adam Langley5021b222015-06-12 18:27:58 -07005837 // The server shouldn't echo the renegotiation extension unless
5838 // requested by the client.
5839 testCases = append(testCases, testCase{
5840 testType: serverTest,
5841 name: "Renegotiate-Server-NoExt",
5842 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005843 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005844 Bugs: ProtocolBugs{
5845 NoRenegotiationInfo: true,
5846 RequireRenegotiationInfo: true,
5847 },
5848 },
5849 shouldFail: true,
5850 expectedLocalError: "renegotiation extension missing",
5851 })
5852 // The renegotiation SCSV should be sufficient for the server to echo
5853 // the extension.
5854 testCases = append(testCases, testCase{
5855 testType: serverTest,
5856 name: "Renegotiate-Server-NoExt-SCSV",
5857 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005858 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005859 Bugs: ProtocolBugs{
5860 NoRenegotiationInfo: true,
5861 SendRenegotiationSCSV: true,
5862 RequireRenegotiationInfo: true,
5863 },
5864 },
5865 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005866 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005867 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005868 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005869 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005870 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005871 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005872 },
5873 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005874 renegotiate: 1,
5875 flags: []string{
5876 "-renegotiate-freely",
5877 "-expect-total-renegotiations", "1",
5878 },
David Benjamincdea40c2015-03-19 14:09:43 -04005879 })
5880 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005881 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005882 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005883 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005884 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005885 Bugs: ProtocolBugs{
5886 EmptyRenegotiationInfo: true,
5887 },
5888 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005889 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005890 shouldFail: true,
5891 expectedError: ":RENEGOTIATION_MISMATCH:",
5892 })
5893 testCases = append(testCases, testCase{
5894 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005895 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005897 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005898 Bugs: ProtocolBugs{
5899 BadRenegotiationInfo: true,
5900 },
5901 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005902 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005903 shouldFail: true,
5904 expectedError: ":RENEGOTIATION_MISMATCH:",
5905 })
5906 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005907 name: "Renegotiate-Client-Downgrade",
5908 renegotiate: 1,
5909 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005910 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005911 Bugs: ProtocolBugs{
5912 NoRenegotiationInfoAfterInitial: true,
5913 },
5914 },
5915 flags: []string{"-renegotiate-freely"},
5916 shouldFail: true,
5917 expectedError: ":RENEGOTIATION_MISMATCH:",
5918 })
5919 testCases = append(testCases, testCase{
5920 name: "Renegotiate-Client-Upgrade",
5921 renegotiate: 1,
5922 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005923 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005924 Bugs: ProtocolBugs{
5925 NoRenegotiationInfoInInitial: true,
5926 },
5927 },
5928 flags: []string{"-renegotiate-freely"},
5929 shouldFail: true,
5930 expectedError: ":RENEGOTIATION_MISMATCH:",
5931 })
5932 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005933 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005934 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005935 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005936 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005937 Bugs: ProtocolBugs{
5938 NoRenegotiationInfo: true,
5939 },
5940 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005941 flags: []string{
5942 "-renegotiate-freely",
5943 "-expect-total-renegotiations", "1",
5944 },
David Benjamincff0b902015-05-15 23:09:47 -04005945 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005946
5947 // Test that the server may switch ciphers on renegotiation without
5948 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005949 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005950 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005951 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005952 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005953 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005954 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005955 },
5956 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005957 flags: []string{
5958 "-renegotiate-freely",
5959 "-expect-total-renegotiations", "1",
5960 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005961 })
5962 testCases = append(testCases, testCase{
5963 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005964 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005965 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005966 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005967 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5968 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005969 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005970 flags: []string{
5971 "-renegotiate-freely",
5972 "-expect-total-renegotiations", "1",
5973 },
David Benjaminb16346b2015-04-08 19:16:58 -04005974 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005975
5976 // Test that the server may not switch versions on renegotiation.
5977 testCases = append(testCases, testCase{
5978 name: "Renegotiate-Client-SwitchVersion",
5979 config: Config{
5980 MaxVersion: VersionTLS12,
5981 // Pick a cipher which exists at both versions.
5982 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5983 Bugs: ProtocolBugs{
5984 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05005985 // Avoid failing early at the record layer.
5986 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04005987 },
5988 },
5989 renegotiate: 1,
5990 flags: []string{
5991 "-renegotiate-freely",
5992 "-expect-total-renegotiations", "1",
5993 },
5994 shouldFail: true,
5995 expectedError: ":WRONG_SSL_VERSION:",
5996 })
5997
David Benjaminb16346b2015-04-08 19:16:58 -04005998 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005999 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006000 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006001 config: Config{
6002 MaxVersion: VersionTLS10,
6003 Bugs: ProtocolBugs{
6004 RequireSameRenegoClientVersion: true,
6005 },
6006 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006007 flags: []string{
6008 "-renegotiate-freely",
6009 "-expect-total-renegotiations", "1",
6010 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006011 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006012 testCases = append(testCases, testCase{
6013 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006014 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006015 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006016 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006017 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6018 NextProtos: []string{"foo"},
6019 },
6020 flags: []string{
6021 "-false-start",
6022 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006023 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006024 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006025 },
6026 shimWritesFirst: true,
6027 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006028
6029 // Client-side renegotiation controls.
6030 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006031 name: "Renegotiate-Client-Forbidden-1",
6032 config: Config{
6033 MaxVersion: VersionTLS12,
6034 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006035 renegotiate: 1,
6036 shouldFail: true,
6037 expectedError: ":NO_RENEGOTIATION:",
6038 expectedLocalError: "remote error: no renegotiation",
6039 })
6040 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006041 name: "Renegotiate-Client-Once-1",
6042 config: Config{
6043 MaxVersion: VersionTLS12,
6044 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006045 renegotiate: 1,
6046 flags: []string{
6047 "-renegotiate-once",
6048 "-expect-total-renegotiations", "1",
6049 },
6050 })
6051 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006052 name: "Renegotiate-Client-Freely-1",
6053 config: Config{
6054 MaxVersion: VersionTLS12,
6055 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006056 renegotiate: 1,
6057 flags: []string{
6058 "-renegotiate-freely",
6059 "-expect-total-renegotiations", "1",
6060 },
6061 })
6062 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006063 name: "Renegotiate-Client-Once-2",
6064 config: Config{
6065 MaxVersion: VersionTLS12,
6066 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006067 renegotiate: 2,
6068 flags: []string{"-renegotiate-once"},
6069 shouldFail: true,
6070 expectedError: ":NO_RENEGOTIATION:",
6071 expectedLocalError: "remote error: no renegotiation",
6072 })
6073 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006074 name: "Renegotiate-Client-Freely-2",
6075 config: Config{
6076 MaxVersion: VersionTLS12,
6077 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006078 renegotiate: 2,
6079 flags: []string{
6080 "-renegotiate-freely",
6081 "-expect-total-renegotiations", "2",
6082 },
6083 })
Adam Langley27a0d082015-11-03 13:34:10 -08006084 testCases = append(testCases, testCase{
6085 name: "Renegotiate-Client-NoIgnore",
6086 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006087 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006088 Bugs: ProtocolBugs{
6089 SendHelloRequestBeforeEveryAppDataRecord: true,
6090 },
6091 },
6092 shouldFail: true,
6093 expectedError: ":NO_RENEGOTIATION:",
6094 })
6095 testCases = append(testCases, testCase{
6096 name: "Renegotiate-Client-Ignore",
6097 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006098 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006099 Bugs: ProtocolBugs{
6100 SendHelloRequestBeforeEveryAppDataRecord: true,
6101 },
6102 },
6103 flags: []string{
6104 "-renegotiate-ignore",
6105 "-expect-total-renegotiations", "0",
6106 },
6107 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006108
David Benjamin34941c02016-10-08 11:45:31 -04006109 // Renegotiation is not allowed at SSL 3.0.
6110 testCases = append(testCases, testCase{
6111 name: "Renegotiate-Client-SSL3",
6112 config: Config{
6113 MaxVersion: VersionSSL30,
6114 },
6115 renegotiate: 1,
6116 flags: []string{
6117 "-renegotiate-freely",
6118 "-expect-total-renegotiations", "1",
6119 },
6120 shouldFail: true,
6121 expectedError: ":NO_RENEGOTIATION:",
6122 expectedLocalError: "remote error: no renegotiation",
6123 })
6124
David Benjamin397c8e62016-07-08 14:14:36 -07006125 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006126 testCases = append(testCases, testCase{
6127 name: "StrayHelloRequest",
6128 config: Config{
6129 MaxVersion: VersionTLS12,
6130 Bugs: ProtocolBugs{
6131 SendHelloRequestBeforeEveryHandshakeMessage: true,
6132 },
6133 },
6134 })
6135 testCases = append(testCases, testCase{
6136 name: "StrayHelloRequest-Packed",
6137 config: Config{
6138 MaxVersion: VersionTLS12,
6139 Bugs: ProtocolBugs{
6140 PackHandshakeFlight: true,
6141 SendHelloRequestBeforeEveryHandshakeMessage: true,
6142 },
6143 },
6144 })
6145
David Benjamin12d2c482016-07-24 10:56:51 -04006146 // Test renegotiation works if HelloRequest and server Finished come in
6147 // the same record.
6148 testCases = append(testCases, testCase{
6149 name: "Renegotiate-Client-Packed",
6150 config: Config{
6151 MaxVersion: VersionTLS12,
6152 Bugs: ProtocolBugs{
6153 PackHandshakeFlight: true,
6154 PackHelloRequestWithFinished: true,
6155 },
6156 },
6157 renegotiate: 1,
6158 flags: []string{
6159 "-renegotiate-freely",
6160 "-expect-total-renegotiations", "1",
6161 },
6162 })
6163
David Benjamin397c8e62016-07-08 14:14:36 -07006164 // Renegotiation is forbidden in TLS 1.3.
6165 testCases = append(testCases, testCase{
6166 name: "Renegotiate-Client-TLS13",
6167 config: Config{
6168 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006169 Bugs: ProtocolBugs{
6170 SendHelloRequestBeforeEveryAppDataRecord: true,
6171 },
David Benjamin397c8e62016-07-08 14:14:36 -07006172 },
David Benjamin397c8e62016-07-08 14:14:36 -07006173 flags: []string{
6174 "-renegotiate-freely",
6175 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006176 shouldFail: true,
6177 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006178 })
6179
6180 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6181 testCases = append(testCases, testCase{
6182 name: "StrayHelloRequest-TLS13",
6183 config: Config{
6184 MaxVersion: VersionTLS13,
6185 Bugs: ProtocolBugs{
6186 SendHelloRequestBeforeEveryHandshakeMessage: true,
6187 },
6188 },
6189 shouldFail: true,
6190 expectedError: ":UNEXPECTED_MESSAGE:",
6191 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006192}
6193
David Benjamin5e961c12014-11-07 01:48:35 -05006194func addDTLSReplayTests() {
6195 // Test that sequence number replays are detected.
6196 testCases = append(testCases, testCase{
6197 protocol: dtls,
6198 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006199 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006200 replayWrites: true,
6201 })
6202
David Benjamin8e6db492015-07-25 18:29:23 -04006203 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006204 // than the retransmit window.
6205 testCases = append(testCases, testCase{
6206 protocol: dtls,
6207 name: "DTLS-Replay-LargeGaps",
6208 config: Config{
6209 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006210 SequenceNumberMapping: func(in uint64) uint64 {
6211 return in * 127
6212 },
David Benjamin5e961c12014-11-07 01:48:35 -05006213 },
6214 },
David Benjamin8e6db492015-07-25 18:29:23 -04006215 messageCount: 200,
6216 replayWrites: true,
6217 })
6218
6219 // Test the incoming sequence number changing non-monotonically.
6220 testCases = append(testCases, testCase{
6221 protocol: dtls,
6222 name: "DTLS-Replay-NonMonotonic",
6223 config: Config{
6224 Bugs: ProtocolBugs{
6225 SequenceNumberMapping: func(in uint64) uint64 {
6226 return in ^ 31
6227 },
6228 },
6229 },
6230 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006231 replayWrites: true,
6232 })
6233}
6234
Nick Harper60edffd2016-06-21 15:19:24 -07006235var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006236 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006237 id signatureAlgorithm
6238 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006239}{
Nick Harper60edffd2016-06-21 15:19:24 -07006240 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6241 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6242 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6243 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006244 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006245 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6246 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6247 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006248 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6249 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6250 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006251 // Tests for key types prior to TLS 1.2.
6252 {"RSA", 0, testCertRSA},
6253 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006254}
6255
Nick Harper60edffd2016-06-21 15:19:24 -07006256const fakeSigAlg1 signatureAlgorithm = 0x2a01
6257const fakeSigAlg2 signatureAlgorithm = 0xff01
6258
6259func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006260 // Not all ciphers involve a signature. Advertise a list which gives all
6261 // versions a signing cipher.
6262 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006263 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006264 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6265 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6266 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6267 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6268 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6269 }
6270
David Benjaminca3d5452016-07-14 12:51:01 -04006271 var allAlgorithms []signatureAlgorithm
6272 for _, alg := range testSignatureAlgorithms {
6273 if alg.id != 0 {
6274 allAlgorithms = append(allAlgorithms, alg.id)
6275 }
6276 }
6277
Nick Harper60edffd2016-06-21 15:19:24 -07006278 // Make sure each signature algorithm works. Include some fake values in
6279 // the list and ensure they're ignored.
6280 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006281 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006282 if (ver.version < VersionTLS12) != (alg.id == 0) {
6283 continue
6284 }
6285
6286 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6287 // or remove it in C.
6288 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006289 continue
6290 }
Nick Harper60edffd2016-06-21 15:19:24 -07006291
David Benjamin3ef76972016-10-17 17:59:54 -04006292 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006293 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006294 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006295 shouldSignFail = true
6296 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006297 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006298 // RSA-PKCS1 does not exist in TLS 1.3.
6299 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006300 shouldSignFail = true
6301 shouldVerifyFail = true
6302 }
6303
6304 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6305 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6306 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006307 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006308
6309 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006310 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006311 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006312 }
6313 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006314 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006315 }
David Benjamin000800a2014-11-14 01:43:59 -05006316
David Benjamin1fb125c2016-07-08 18:52:12 -07006317 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006318
David Benjamin7a41d372016-07-09 11:21:54 -07006319 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006320 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006321 config: Config{
6322 MaxVersion: ver.version,
6323 ClientAuth: RequireAnyClientCert,
6324 VerifySignatureAlgorithms: []signatureAlgorithm{
6325 fakeSigAlg1,
6326 alg.id,
6327 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006328 },
David Benjamin7a41d372016-07-09 11:21:54 -07006329 },
6330 flags: []string{
6331 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6332 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6333 "-enable-all-curves",
6334 },
David Benjamin3ef76972016-10-17 17:59:54 -04006335 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006336 expectedError: signError,
6337 expectedPeerSignatureAlgorithm: alg.id,
6338 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006339
David Benjamin7a41d372016-07-09 11:21:54 -07006340 testCases = append(testCases, testCase{
6341 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006342 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006343 config: Config{
6344 MaxVersion: ver.version,
6345 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6346 SignSignatureAlgorithms: []signatureAlgorithm{
6347 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006348 },
David Benjamin7a41d372016-07-09 11:21:54 -07006349 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006350 SkipECDSACurveCheck: shouldVerifyFail,
6351 IgnoreSignatureVersionChecks: shouldVerifyFail,
6352 // Some signature algorithms may not be advertised.
6353 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006354 },
David Benjamin7a41d372016-07-09 11:21:54 -07006355 },
6356 flags: []string{
6357 "-require-any-client-certificate",
6358 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6359 "-enable-all-curves",
6360 },
David Benjamin3ef76972016-10-17 17:59:54 -04006361 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006362 expectedError: verifyError,
6363 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006364
6365 testCases = append(testCases, testCase{
6366 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006367 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006368 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006369 MaxVersion: ver.version,
6370 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006371 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006372 fakeSigAlg1,
6373 alg.id,
6374 fakeSigAlg2,
6375 },
6376 },
6377 flags: []string{
6378 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6379 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6380 "-enable-all-curves",
6381 },
David Benjamin3ef76972016-10-17 17:59:54 -04006382 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006383 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006384 expectedPeerSignatureAlgorithm: alg.id,
6385 })
6386
6387 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006388 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006389 config: Config{
6390 MaxVersion: ver.version,
6391 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006392 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006393 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006394 alg.id,
6395 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006396 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006397 SkipECDSACurveCheck: shouldVerifyFail,
6398 IgnoreSignatureVersionChecks: shouldVerifyFail,
6399 // Some signature algorithms may not be advertised.
6400 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006401 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006402 },
6403 flags: []string{
6404 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6405 "-enable-all-curves",
6406 },
David Benjamin3ef76972016-10-17 17:59:54 -04006407 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006408 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006409 })
David Benjamin5208fd42016-07-13 21:43:25 -04006410
David Benjamin3ef76972016-10-17 17:59:54 -04006411 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006412 testCases = append(testCases, testCase{
6413 testType: serverTest,
6414 name: "ClientAuth-InvalidSignature" + suffix,
6415 config: Config{
6416 MaxVersion: ver.version,
6417 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6418 SignSignatureAlgorithms: []signatureAlgorithm{
6419 alg.id,
6420 },
6421 Bugs: ProtocolBugs{
6422 InvalidSignature: true,
6423 },
6424 },
6425 flags: []string{
6426 "-require-any-client-certificate",
6427 "-enable-all-curves",
6428 },
6429 shouldFail: true,
6430 expectedError: ":BAD_SIGNATURE:",
6431 })
6432
6433 testCases = append(testCases, testCase{
6434 name: "ServerAuth-InvalidSignature" + suffix,
6435 config: Config{
6436 MaxVersion: ver.version,
6437 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6438 CipherSuites: signingCiphers,
6439 SignSignatureAlgorithms: []signatureAlgorithm{
6440 alg.id,
6441 },
6442 Bugs: ProtocolBugs{
6443 InvalidSignature: true,
6444 },
6445 },
6446 flags: []string{"-enable-all-curves"},
6447 shouldFail: true,
6448 expectedError: ":BAD_SIGNATURE:",
6449 })
6450 }
David Benjaminca3d5452016-07-14 12:51:01 -04006451
David Benjamin3ef76972016-10-17 17:59:54 -04006452 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006453 testCases = append(testCases, testCase{
6454 name: "ClientAuth-Sign-Negotiate" + suffix,
6455 config: Config{
6456 MaxVersion: ver.version,
6457 ClientAuth: RequireAnyClientCert,
6458 VerifySignatureAlgorithms: allAlgorithms,
6459 },
6460 flags: []string{
6461 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6462 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6463 "-enable-all-curves",
6464 "-signing-prefs", strconv.Itoa(int(alg.id)),
6465 },
6466 expectedPeerSignatureAlgorithm: alg.id,
6467 })
6468
6469 testCases = append(testCases, testCase{
6470 testType: serverTest,
6471 name: "ServerAuth-Sign-Negotiate" + suffix,
6472 config: Config{
6473 MaxVersion: ver.version,
6474 CipherSuites: signingCiphers,
6475 VerifySignatureAlgorithms: allAlgorithms,
6476 },
6477 flags: []string{
6478 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6479 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6480 "-enable-all-curves",
6481 "-signing-prefs", strconv.Itoa(int(alg.id)),
6482 },
6483 expectedPeerSignatureAlgorithm: alg.id,
6484 })
6485 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006486 }
David Benjamin000800a2014-11-14 01:43:59 -05006487 }
6488
Nick Harper60edffd2016-06-21 15:19:24 -07006489 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006490 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006491 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006492 config: Config{
6493 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006494 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006495 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006496 signatureECDSAWithP521AndSHA512,
6497 signatureRSAPKCS1WithSHA384,
6498 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006499 },
6500 },
6501 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006502 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6503 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006504 },
Nick Harper60edffd2016-06-21 15:19:24 -07006505 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006506 })
6507
6508 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006509 name: "ClientAuth-SignatureType-TLS13",
6510 config: Config{
6511 ClientAuth: RequireAnyClientCert,
6512 MaxVersion: VersionTLS13,
6513 VerifySignatureAlgorithms: []signatureAlgorithm{
6514 signatureECDSAWithP521AndSHA512,
6515 signatureRSAPKCS1WithSHA384,
6516 signatureRSAPSSWithSHA384,
6517 signatureECDSAWithSHA1,
6518 },
6519 },
6520 flags: []string{
6521 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6522 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6523 },
6524 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6525 })
6526
6527 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006528 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006529 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006530 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006531 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006532 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006533 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006534 signatureECDSAWithP521AndSHA512,
6535 signatureRSAPKCS1WithSHA384,
6536 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006537 },
6538 },
Nick Harper60edffd2016-06-21 15:19:24 -07006539 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006540 })
6541
Steven Valdez143e8b32016-07-11 13:19:03 -04006542 testCases = append(testCases, testCase{
6543 testType: serverTest,
6544 name: "ServerAuth-SignatureType-TLS13",
6545 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006546 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006547 VerifySignatureAlgorithms: []signatureAlgorithm{
6548 signatureECDSAWithP521AndSHA512,
6549 signatureRSAPKCS1WithSHA384,
6550 signatureRSAPSSWithSHA384,
6551 signatureECDSAWithSHA1,
6552 },
6553 },
6554 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6555 })
6556
David Benjamina95e9f32016-07-08 16:28:04 -07006557 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006558 testCases = append(testCases, testCase{
6559 testType: serverTest,
6560 name: "Verify-ClientAuth-SignatureType",
6561 config: Config{
6562 MaxVersion: VersionTLS12,
6563 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006564 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006565 signatureRSAPKCS1WithSHA256,
6566 },
6567 Bugs: ProtocolBugs{
6568 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6569 },
6570 },
6571 flags: []string{
6572 "-require-any-client-certificate",
6573 },
6574 shouldFail: true,
6575 expectedError: ":WRONG_SIGNATURE_TYPE:",
6576 })
6577
6578 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006579 testType: serverTest,
6580 name: "Verify-ClientAuth-SignatureType-TLS13",
6581 config: Config{
6582 MaxVersion: VersionTLS13,
6583 Certificates: []Certificate{rsaCertificate},
6584 SignSignatureAlgorithms: []signatureAlgorithm{
6585 signatureRSAPSSWithSHA256,
6586 },
6587 Bugs: ProtocolBugs{
6588 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6589 },
6590 },
6591 flags: []string{
6592 "-require-any-client-certificate",
6593 },
6594 shouldFail: true,
6595 expectedError: ":WRONG_SIGNATURE_TYPE:",
6596 })
6597
6598 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006599 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006600 config: Config{
6601 MaxVersion: VersionTLS12,
6602 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006603 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006604 signatureRSAPKCS1WithSHA256,
6605 },
6606 Bugs: ProtocolBugs{
6607 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6608 },
6609 },
6610 shouldFail: true,
6611 expectedError: ":WRONG_SIGNATURE_TYPE:",
6612 })
6613
Steven Valdez143e8b32016-07-11 13:19:03 -04006614 testCases = append(testCases, testCase{
6615 name: "Verify-ServerAuth-SignatureType-TLS13",
6616 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006617 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006618 SignSignatureAlgorithms: []signatureAlgorithm{
6619 signatureRSAPSSWithSHA256,
6620 },
6621 Bugs: ProtocolBugs{
6622 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6623 },
6624 },
6625 shouldFail: true,
6626 expectedError: ":WRONG_SIGNATURE_TYPE:",
6627 })
6628
David Benjamin51dd7d62016-07-08 16:07:01 -07006629 // Test that, if the list is missing, the peer falls back to SHA-1 in
6630 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006631 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006632 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006633 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006634 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006635 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006636 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006637 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006638 },
6639 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006640 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006641 },
6642 },
6643 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006644 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6645 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006646 },
6647 })
6648
6649 testCases = append(testCases, testCase{
6650 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006651 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006652 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006653 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006654 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006655 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006656 },
6657 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006658 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006659 },
6660 },
David Benjaminee32bea2016-08-17 13:36:44 -04006661 flags: []string{
6662 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6663 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6664 },
6665 })
6666
6667 testCases = append(testCases, testCase{
6668 name: "ClientAuth-SHA1-Fallback-ECDSA",
6669 config: Config{
6670 MaxVersion: VersionTLS12,
6671 ClientAuth: RequireAnyClientCert,
6672 VerifySignatureAlgorithms: []signatureAlgorithm{
6673 signatureECDSAWithSHA1,
6674 },
6675 Bugs: ProtocolBugs{
6676 NoSignatureAlgorithms: true,
6677 },
6678 },
6679 flags: []string{
6680 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6681 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6682 },
6683 })
6684
6685 testCases = append(testCases, testCase{
6686 testType: serverTest,
6687 name: "ServerAuth-SHA1-Fallback-ECDSA",
6688 config: Config{
6689 MaxVersion: VersionTLS12,
6690 VerifySignatureAlgorithms: []signatureAlgorithm{
6691 signatureECDSAWithSHA1,
6692 },
6693 Bugs: ProtocolBugs{
6694 NoSignatureAlgorithms: true,
6695 },
6696 },
6697 flags: []string{
6698 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6699 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6700 },
David Benjamin000800a2014-11-14 01:43:59 -05006701 })
David Benjamin72dc7832015-03-16 17:49:43 -04006702
David Benjamin51dd7d62016-07-08 16:07:01 -07006703 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006704 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006705 config: Config{
6706 MaxVersion: VersionTLS13,
6707 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006708 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006709 signatureRSAPKCS1WithSHA1,
6710 },
6711 Bugs: ProtocolBugs{
6712 NoSignatureAlgorithms: true,
6713 },
6714 },
6715 flags: []string{
6716 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6717 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6718 },
David Benjamin48901652016-08-01 12:12:47 -04006719 shouldFail: true,
6720 // An empty CertificateRequest signature algorithm list is a
6721 // syntax error in TLS 1.3.
6722 expectedError: ":DECODE_ERROR:",
6723 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006724 })
6725
6726 testCases = append(testCases, testCase{
6727 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006728 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006729 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006730 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006731 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006732 signatureRSAPKCS1WithSHA1,
6733 },
6734 Bugs: ProtocolBugs{
6735 NoSignatureAlgorithms: true,
6736 },
6737 },
6738 shouldFail: true,
6739 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6740 })
6741
David Benjaminb62d2872016-07-18 14:55:02 +02006742 // Test that hash preferences are enforced. BoringSSL does not implement
6743 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006744 testCases = append(testCases, testCase{
6745 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006746 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006747 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006748 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006749 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006750 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006751 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006752 },
6753 Bugs: ProtocolBugs{
6754 IgnorePeerSignatureAlgorithmPreferences: true,
6755 },
6756 },
6757 flags: []string{"-require-any-client-certificate"},
6758 shouldFail: true,
6759 expectedError: ":WRONG_SIGNATURE_TYPE:",
6760 })
6761
6762 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006763 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006764 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006765 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006766 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006767 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006768 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006769 },
6770 Bugs: ProtocolBugs{
6771 IgnorePeerSignatureAlgorithmPreferences: true,
6772 },
6773 },
6774 shouldFail: true,
6775 expectedError: ":WRONG_SIGNATURE_TYPE:",
6776 })
David Benjaminb62d2872016-07-18 14:55:02 +02006777 testCases = append(testCases, testCase{
6778 testType: serverTest,
6779 name: "ClientAuth-Enforced-TLS13",
6780 config: Config{
6781 MaxVersion: VersionTLS13,
6782 Certificates: []Certificate{rsaCertificate},
6783 SignSignatureAlgorithms: []signatureAlgorithm{
6784 signatureRSAPKCS1WithMD5,
6785 },
6786 Bugs: ProtocolBugs{
6787 IgnorePeerSignatureAlgorithmPreferences: true,
6788 IgnoreSignatureVersionChecks: true,
6789 },
6790 },
6791 flags: []string{"-require-any-client-certificate"},
6792 shouldFail: true,
6793 expectedError: ":WRONG_SIGNATURE_TYPE:",
6794 })
6795
6796 testCases = append(testCases, testCase{
6797 name: "ServerAuth-Enforced-TLS13",
6798 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006799 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006800 SignSignatureAlgorithms: []signatureAlgorithm{
6801 signatureRSAPKCS1WithMD5,
6802 },
6803 Bugs: ProtocolBugs{
6804 IgnorePeerSignatureAlgorithmPreferences: true,
6805 IgnoreSignatureVersionChecks: true,
6806 },
6807 },
6808 shouldFail: true,
6809 expectedError: ":WRONG_SIGNATURE_TYPE:",
6810 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006811
6812 // Test that the agreed upon digest respects the client preferences and
6813 // the server digests.
6814 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006815 name: "NoCommonAlgorithms-Digests",
6816 config: Config{
6817 MaxVersion: VersionTLS12,
6818 ClientAuth: RequireAnyClientCert,
6819 VerifySignatureAlgorithms: []signatureAlgorithm{
6820 signatureRSAPKCS1WithSHA512,
6821 signatureRSAPKCS1WithSHA1,
6822 },
6823 },
6824 flags: []string{
6825 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6826 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6827 "-digest-prefs", "SHA256",
6828 },
6829 shouldFail: true,
6830 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6831 })
6832 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006833 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006834 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006835 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006836 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006837 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006838 signatureRSAPKCS1WithSHA512,
6839 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006840 },
6841 },
6842 flags: []string{
6843 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6844 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006845 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006846 },
David Benjaminca3d5452016-07-14 12:51:01 -04006847 shouldFail: true,
6848 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6849 })
6850 testCases = append(testCases, testCase{
6851 name: "NoCommonAlgorithms-TLS13",
6852 config: Config{
6853 MaxVersion: VersionTLS13,
6854 ClientAuth: RequireAnyClientCert,
6855 VerifySignatureAlgorithms: []signatureAlgorithm{
6856 signatureRSAPSSWithSHA512,
6857 signatureRSAPSSWithSHA384,
6858 },
6859 },
6860 flags: []string{
6861 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6862 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6863 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6864 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006865 shouldFail: true,
6866 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006867 })
6868 testCases = append(testCases, testCase{
6869 name: "Agree-Digest-SHA256",
6870 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006871 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006872 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006873 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006874 signatureRSAPKCS1WithSHA1,
6875 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006876 },
6877 },
6878 flags: []string{
6879 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6880 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006881 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006882 },
Nick Harper60edffd2016-06-21 15:19:24 -07006883 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006884 })
6885 testCases = append(testCases, testCase{
6886 name: "Agree-Digest-SHA1",
6887 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006888 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006889 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006890 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006891 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006892 },
6893 },
6894 flags: []string{
6895 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6896 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006897 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006898 },
Nick Harper60edffd2016-06-21 15:19:24 -07006899 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006900 })
6901 testCases = append(testCases, testCase{
6902 name: "Agree-Digest-Default",
6903 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006904 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006905 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006906 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006907 signatureRSAPKCS1WithSHA256,
6908 signatureECDSAWithP256AndSHA256,
6909 signatureRSAPKCS1WithSHA1,
6910 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006911 },
6912 },
6913 flags: []string{
6914 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6915 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6916 },
Nick Harper60edffd2016-06-21 15:19:24 -07006917 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006918 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006919
David Benjaminca3d5452016-07-14 12:51:01 -04006920 // Test that the signing preference list may include extra algorithms
6921 // without negotiation problems.
6922 testCases = append(testCases, testCase{
6923 testType: serverTest,
6924 name: "FilterExtraAlgorithms",
6925 config: Config{
6926 MaxVersion: VersionTLS12,
6927 VerifySignatureAlgorithms: []signatureAlgorithm{
6928 signatureRSAPKCS1WithSHA256,
6929 },
6930 },
6931 flags: []string{
6932 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6933 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6934 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6935 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6936 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6937 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6938 },
6939 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6940 })
6941
David Benjamin4c3ddf72016-06-29 18:13:53 -04006942 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6943 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006944 testCases = append(testCases, testCase{
6945 name: "CheckLeafCurve",
6946 config: Config{
6947 MaxVersion: VersionTLS12,
6948 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006949 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006950 },
6951 flags: []string{"-p384-only"},
6952 shouldFail: true,
6953 expectedError: ":BAD_ECC_CERT:",
6954 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006955
6956 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6957 testCases = append(testCases, testCase{
6958 name: "CheckLeafCurve-TLS13",
6959 config: Config{
6960 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006961 Certificates: []Certificate{ecdsaP256Certificate},
6962 },
6963 flags: []string{"-p384-only"},
6964 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006965
6966 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6967 testCases = append(testCases, testCase{
6968 name: "ECDSACurveMismatch-Verify-TLS12",
6969 config: Config{
6970 MaxVersion: VersionTLS12,
6971 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6972 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006973 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006974 signatureECDSAWithP384AndSHA384,
6975 },
6976 },
6977 })
6978
6979 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6980 testCases = append(testCases, testCase{
6981 name: "ECDSACurveMismatch-Verify-TLS13",
6982 config: Config{
6983 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006984 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006985 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006986 signatureECDSAWithP384AndSHA384,
6987 },
6988 Bugs: ProtocolBugs{
6989 SkipECDSACurveCheck: true,
6990 },
6991 },
6992 shouldFail: true,
6993 expectedError: ":WRONG_SIGNATURE_TYPE:",
6994 })
6995
6996 // Signature algorithm selection in TLS 1.3 should take the curve into
6997 // account.
6998 testCases = append(testCases, testCase{
6999 testType: serverTest,
7000 name: "ECDSACurveMismatch-Sign-TLS13",
7001 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007002 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007003 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007004 signatureECDSAWithP384AndSHA384,
7005 signatureECDSAWithP256AndSHA256,
7006 },
7007 },
7008 flags: []string{
7009 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7010 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7011 },
7012 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7013 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007014
7015 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7016 // server does not attempt to sign in that case.
7017 testCases = append(testCases, testCase{
7018 testType: serverTest,
7019 name: "RSA-PSS-Large",
7020 config: Config{
7021 MaxVersion: VersionTLS13,
7022 VerifySignatureAlgorithms: []signatureAlgorithm{
7023 signatureRSAPSSWithSHA512,
7024 },
7025 },
7026 flags: []string{
7027 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7028 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7029 },
7030 shouldFail: true,
7031 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7032 })
David Benjamin57e929f2016-08-30 00:30:38 -04007033
7034 // Test that RSA-PSS is enabled by default for TLS 1.2.
7035 testCases = append(testCases, testCase{
7036 testType: clientTest,
7037 name: "RSA-PSS-Default-Verify",
7038 config: Config{
7039 MaxVersion: VersionTLS12,
7040 SignSignatureAlgorithms: []signatureAlgorithm{
7041 signatureRSAPSSWithSHA256,
7042 },
7043 },
7044 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7045 })
7046
7047 testCases = append(testCases, testCase{
7048 testType: serverTest,
7049 name: "RSA-PSS-Default-Sign",
7050 config: Config{
7051 MaxVersion: VersionTLS12,
7052 VerifySignatureAlgorithms: []signatureAlgorithm{
7053 signatureRSAPSSWithSHA256,
7054 },
7055 },
7056 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7057 })
David Benjamin000800a2014-11-14 01:43:59 -05007058}
7059
David Benjamin83f90402015-01-27 01:09:43 -05007060// timeouts is the retransmit schedule for BoringSSL. It doubles and
7061// caps at 60 seconds. On the 13th timeout, it gives up.
7062var timeouts = []time.Duration{
7063 1 * time.Second,
7064 2 * time.Second,
7065 4 * time.Second,
7066 8 * time.Second,
7067 16 * time.Second,
7068 32 * time.Second,
7069 60 * time.Second,
7070 60 * time.Second,
7071 60 * time.Second,
7072 60 * time.Second,
7073 60 * time.Second,
7074 60 * time.Second,
7075 60 * time.Second,
7076}
7077
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007078// shortTimeouts is an alternate set of timeouts which would occur if the
7079// initial timeout duration was set to 250ms.
7080var shortTimeouts = []time.Duration{
7081 250 * time.Millisecond,
7082 500 * time.Millisecond,
7083 1 * time.Second,
7084 2 * time.Second,
7085 4 * time.Second,
7086 8 * time.Second,
7087 16 * time.Second,
7088 32 * time.Second,
7089 60 * time.Second,
7090 60 * time.Second,
7091 60 * time.Second,
7092 60 * time.Second,
7093 60 * time.Second,
7094}
7095
David Benjamin83f90402015-01-27 01:09:43 -05007096func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007097 // These tests work by coordinating some behavior on both the shim and
7098 // the runner.
7099 //
7100 // TimeoutSchedule configures the runner to send a series of timeout
7101 // opcodes to the shim (see packetAdaptor) immediately before reading
7102 // each peer handshake flight N. The timeout opcode both simulates a
7103 // timeout in the shim and acts as a synchronization point to help the
7104 // runner bracket each handshake flight.
7105 //
7106 // We assume the shim does not read from the channel eagerly. It must
7107 // first wait until it has sent flight N and is ready to receive
7108 // handshake flight N+1. At this point, it will process the timeout
7109 // opcode. It must then immediately respond with a timeout ACK and act
7110 // as if the shim was idle for the specified amount of time.
7111 //
7112 // The runner then drops all packets received before the ACK and
7113 // continues waiting for flight N. This ordering results in one attempt
7114 // at sending flight N to be dropped. For the test to complete, the
7115 // shim must send flight N again, testing that the shim implements DTLS
7116 // retransmit on a timeout.
7117
Steven Valdez143e8b32016-07-11 13:19:03 -04007118 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007119 // likely be more epochs to cross and the final message's retransmit may
7120 // be more complex.
7121
David Benjamin585d7a42016-06-02 14:58:00 -04007122 for _, async := range []bool{true, false} {
7123 var tests []testCase
7124
7125 // Test that this is indeed the timeout schedule. Stress all
7126 // four patterns of handshake.
7127 for i := 1; i < len(timeouts); i++ {
7128 number := strconv.Itoa(i)
7129 tests = append(tests, testCase{
7130 protocol: dtls,
7131 name: "DTLS-Retransmit-Client-" + number,
7132 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007133 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007134 Bugs: ProtocolBugs{
7135 TimeoutSchedule: timeouts[:i],
7136 },
7137 },
7138 resumeSession: true,
7139 })
7140 tests = append(tests, testCase{
7141 protocol: dtls,
7142 testType: serverTest,
7143 name: "DTLS-Retransmit-Server-" + number,
7144 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007145 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007146 Bugs: ProtocolBugs{
7147 TimeoutSchedule: timeouts[:i],
7148 },
7149 },
7150 resumeSession: true,
7151 })
7152 }
7153
7154 // Test that exceeding the timeout schedule hits a read
7155 // timeout.
7156 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007157 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007158 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007160 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007161 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007162 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007163 },
7164 },
7165 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007166 shouldFail: true,
7167 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007168 })
David Benjamin585d7a42016-06-02 14:58:00 -04007169
7170 if async {
7171 // Test that timeout handling has a fudge factor, due to API
7172 // problems.
7173 tests = append(tests, testCase{
7174 protocol: dtls,
7175 name: "DTLS-Retransmit-Fudge",
7176 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007177 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007178 Bugs: ProtocolBugs{
7179 TimeoutSchedule: []time.Duration{
7180 timeouts[0] - 10*time.Millisecond,
7181 },
7182 },
7183 },
7184 resumeSession: true,
7185 })
7186 }
7187
7188 // Test that the final Finished retransmitting isn't
7189 // duplicated if the peer badly fragments everything.
7190 tests = append(tests, testCase{
7191 testType: serverTest,
7192 protocol: dtls,
7193 name: "DTLS-Retransmit-Fragmented",
7194 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007195 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007196 Bugs: ProtocolBugs{
7197 TimeoutSchedule: []time.Duration{timeouts[0]},
7198 MaxHandshakeRecordLength: 2,
7199 },
7200 },
7201 })
7202
7203 // Test the timeout schedule when a shorter initial timeout duration is set.
7204 tests = append(tests, testCase{
7205 protocol: dtls,
7206 name: "DTLS-Retransmit-Short-Client",
7207 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007208 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007209 Bugs: ProtocolBugs{
7210 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7211 },
7212 },
7213 resumeSession: true,
7214 flags: []string{"-initial-timeout-duration-ms", "250"},
7215 })
7216 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007217 protocol: dtls,
7218 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007219 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007220 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007221 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007222 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007223 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007224 },
7225 },
7226 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007227 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007228 })
David Benjamin585d7a42016-06-02 14:58:00 -04007229
7230 for _, test := range tests {
7231 if async {
7232 test.name += "-Async"
7233 test.flags = append(test.flags, "-async")
7234 }
7235
7236 testCases = append(testCases, test)
7237 }
David Benjamin83f90402015-01-27 01:09:43 -05007238 }
David Benjamin83f90402015-01-27 01:09:43 -05007239}
7240
David Benjaminc565ebb2015-04-03 04:06:36 -04007241func addExportKeyingMaterialTests() {
7242 for _, vers := range tlsVersions {
7243 if vers.version == VersionSSL30 {
7244 continue
7245 }
7246 testCases = append(testCases, testCase{
7247 name: "ExportKeyingMaterial-" + vers.name,
7248 config: Config{
7249 MaxVersion: vers.version,
7250 },
7251 exportKeyingMaterial: 1024,
7252 exportLabel: "label",
7253 exportContext: "context",
7254 useExportContext: true,
7255 })
7256 testCases = append(testCases, testCase{
7257 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7258 config: Config{
7259 MaxVersion: vers.version,
7260 },
7261 exportKeyingMaterial: 1024,
7262 })
7263 testCases = append(testCases, testCase{
7264 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7265 config: Config{
7266 MaxVersion: vers.version,
7267 },
7268 exportKeyingMaterial: 1024,
7269 useExportContext: true,
7270 })
7271 testCases = append(testCases, testCase{
7272 name: "ExportKeyingMaterial-Small-" + vers.name,
7273 config: Config{
7274 MaxVersion: vers.version,
7275 },
7276 exportKeyingMaterial: 1,
7277 exportLabel: "label",
7278 exportContext: "context",
7279 useExportContext: true,
7280 })
7281 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007282
David Benjaminc565ebb2015-04-03 04:06:36 -04007283 testCases = append(testCases, testCase{
7284 name: "ExportKeyingMaterial-SSL3",
7285 config: Config{
7286 MaxVersion: VersionSSL30,
7287 },
7288 exportKeyingMaterial: 1024,
7289 exportLabel: "label",
7290 exportContext: "context",
7291 useExportContext: true,
7292 shouldFail: true,
7293 expectedError: "failed to export keying material",
7294 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007295
7296 // Exporters work during a False Start.
7297 testCases = append(testCases, testCase{
7298 name: "ExportKeyingMaterial-FalseStart",
7299 config: Config{
7300 MaxVersion: VersionTLS12,
7301 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7302 NextProtos: []string{"foo"},
7303 Bugs: ProtocolBugs{
7304 ExpectFalseStart: true,
7305 },
7306 },
7307 flags: []string{
7308 "-false-start",
7309 "-advertise-alpn", "\x03foo",
7310 },
7311 shimWritesFirst: true,
7312 exportKeyingMaterial: 1024,
7313 exportLabel: "label",
7314 exportContext: "context",
7315 useExportContext: true,
7316 })
7317
7318 // Exporters do not work in the middle of a renegotiation. Test this by
7319 // triggering the exporter after every SSL_read call and configuring the
7320 // shim to run asynchronously.
7321 testCases = append(testCases, testCase{
7322 name: "ExportKeyingMaterial-Renegotiate",
7323 config: Config{
7324 MaxVersion: VersionTLS12,
7325 },
7326 renegotiate: 1,
7327 flags: []string{
7328 "-async",
7329 "-use-exporter-between-reads",
7330 "-renegotiate-freely",
7331 "-expect-total-renegotiations", "1",
7332 },
7333 shouldFail: true,
7334 expectedError: "failed to export keying material",
7335 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007336}
7337
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007338func addTLSUniqueTests() {
7339 for _, isClient := range []bool{false, true} {
7340 for _, isResumption := range []bool{false, true} {
7341 for _, hasEMS := range []bool{false, true} {
7342 var suffix string
7343 if isResumption {
7344 suffix = "Resume-"
7345 } else {
7346 suffix = "Full-"
7347 }
7348
7349 if hasEMS {
7350 suffix += "EMS-"
7351 } else {
7352 suffix += "NoEMS-"
7353 }
7354
7355 if isClient {
7356 suffix += "Client"
7357 } else {
7358 suffix += "Server"
7359 }
7360
7361 test := testCase{
7362 name: "TLSUnique-" + suffix,
7363 testTLSUnique: true,
7364 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007365 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007366 Bugs: ProtocolBugs{
7367 NoExtendedMasterSecret: !hasEMS,
7368 },
7369 },
7370 }
7371
7372 if isResumption {
7373 test.resumeSession = true
7374 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007375 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007376 Bugs: ProtocolBugs{
7377 NoExtendedMasterSecret: !hasEMS,
7378 },
7379 }
7380 }
7381
7382 if isResumption && !hasEMS {
7383 test.shouldFail = true
7384 test.expectedError = "failed to get tls-unique"
7385 }
7386
7387 testCases = append(testCases, test)
7388 }
7389 }
7390 }
7391}
7392
Adam Langley09505632015-07-30 18:10:13 -07007393func addCustomExtensionTests() {
7394 expectedContents := "custom extension"
7395 emptyString := ""
7396
7397 for _, isClient := range []bool{false, true} {
7398 suffix := "Server"
7399 flag := "-enable-server-custom-extension"
7400 testType := serverTest
7401 if isClient {
7402 suffix = "Client"
7403 flag = "-enable-client-custom-extension"
7404 testType = clientTest
7405 }
7406
7407 testCases = append(testCases, testCase{
7408 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007409 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007411 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007412 Bugs: ProtocolBugs{
7413 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007414 ExpectedCustomExtension: &expectedContents,
7415 },
7416 },
7417 flags: []string{flag},
7418 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007419 testCases = append(testCases, testCase{
7420 testType: testType,
7421 name: "CustomExtensions-" + suffix + "-TLS13",
7422 config: Config{
7423 MaxVersion: VersionTLS13,
7424 Bugs: ProtocolBugs{
7425 CustomExtension: expectedContents,
7426 ExpectedCustomExtension: &expectedContents,
7427 },
7428 },
7429 flags: []string{flag},
7430 })
Adam Langley09505632015-07-30 18:10:13 -07007431
7432 // If the parse callback fails, the handshake should also fail.
7433 testCases = append(testCases, testCase{
7434 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007435 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007436 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007437 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007438 Bugs: ProtocolBugs{
7439 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007440 ExpectedCustomExtension: &expectedContents,
7441 },
7442 },
David Benjamin399e7c92015-07-30 23:01:27 -04007443 flags: []string{flag},
7444 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007445 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7446 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007447 testCases = append(testCases, testCase{
7448 testType: testType,
7449 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7450 config: Config{
7451 MaxVersion: VersionTLS13,
7452 Bugs: ProtocolBugs{
7453 CustomExtension: expectedContents + "foo",
7454 ExpectedCustomExtension: &expectedContents,
7455 },
7456 },
7457 flags: []string{flag},
7458 shouldFail: true,
7459 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7460 })
Adam Langley09505632015-07-30 18:10:13 -07007461
7462 // If the add callback fails, the handshake should also fail.
7463 testCases = append(testCases, testCase{
7464 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007465 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007466 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007467 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007468 Bugs: ProtocolBugs{
7469 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007470 ExpectedCustomExtension: &expectedContents,
7471 },
7472 },
David Benjamin399e7c92015-07-30 23:01:27 -04007473 flags: []string{flag, "-custom-extension-fail-add"},
7474 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007475 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7476 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007477 testCases = append(testCases, testCase{
7478 testType: testType,
7479 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7480 config: Config{
7481 MaxVersion: VersionTLS13,
7482 Bugs: ProtocolBugs{
7483 CustomExtension: expectedContents,
7484 ExpectedCustomExtension: &expectedContents,
7485 },
7486 },
7487 flags: []string{flag, "-custom-extension-fail-add"},
7488 shouldFail: true,
7489 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7490 })
Adam Langley09505632015-07-30 18:10:13 -07007491
7492 // If the add callback returns zero, no extension should be
7493 // added.
7494 skipCustomExtension := expectedContents
7495 if isClient {
7496 // For the case where the client skips sending the
7497 // custom extension, the server must not “echo” it.
7498 skipCustomExtension = ""
7499 }
7500 testCases = append(testCases, testCase{
7501 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007502 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007503 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007504 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007505 Bugs: ProtocolBugs{
7506 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007507 ExpectedCustomExtension: &emptyString,
7508 },
7509 },
7510 flags: []string{flag, "-custom-extension-skip"},
7511 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007512 testCases = append(testCases, testCase{
7513 testType: testType,
7514 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7515 config: Config{
7516 MaxVersion: VersionTLS13,
7517 Bugs: ProtocolBugs{
7518 CustomExtension: skipCustomExtension,
7519 ExpectedCustomExtension: &emptyString,
7520 },
7521 },
7522 flags: []string{flag, "-custom-extension-skip"},
7523 })
Adam Langley09505632015-07-30 18:10:13 -07007524 }
7525
7526 // The custom extension add callback should not be called if the client
7527 // doesn't send the extension.
7528 testCases = append(testCases, testCase{
7529 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007530 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007532 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007533 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007534 ExpectedCustomExtension: &emptyString,
7535 },
7536 },
7537 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7538 })
Adam Langley2deb9842015-08-07 11:15:37 -07007539
Steven Valdez143e8b32016-07-11 13:19:03 -04007540 testCases = append(testCases, testCase{
7541 testType: serverTest,
7542 name: "CustomExtensions-NotCalled-Server-TLS13",
7543 config: Config{
7544 MaxVersion: VersionTLS13,
7545 Bugs: ProtocolBugs{
7546 ExpectedCustomExtension: &emptyString,
7547 },
7548 },
7549 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7550 })
7551
Adam Langley2deb9842015-08-07 11:15:37 -07007552 // Test an unknown extension from the server.
7553 testCases = append(testCases, testCase{
7554 testType: clientTest,
7555 name: "UnknownExtension-Client",
7556 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007557 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007558 Bugs: ProtocolBugs{
7559 CustomExtension: expectedContents,
7560 },
7561 },
David Benjamin0c40a962016-08-01 12:05:50 -04007562 shouldFail: true,
7563 expectedError: ":UNEXPECTED_EXTENSION:",
7564 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007565 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007566 testCases = append(testCases, testCase{
7567 testType: clientTest,
7568 name: "UnknownExtension-Client-TLS13",
7569 config: Config{
7570 MaxVersion: VersionTLS13,
7571 Bugs: ProtocolBugs{
7572 CustomExtension: expectedContents,
7573 },
7574 },
David Benjamin0c40a962016-08-01 12:05:50 -04007575 shouldFail: true,
7576 expectedError: ":UNEXPECTED_EXTENSION:",
7577 expectedLocalError: "remote error: unsupported extension",
7578 })
David Benjamin490469f2016-10-05 22:44:38 -04007579 testCases = append(testCases, testCase{
7580 testType: clientTest,
7581 name: "UnknownUnencryptedExtension-Client-TLS13",
7582 config: Config{
7583 MaxVersion: VersionTLS13,
7584 Bugs: ProtocolBugs{
7585 CustomUnencryptedExtension: expectedContents,
7586 },
7587 },
7588 shouldFail: true,
7589 expectedError: ":UNEXPECTED_EXTENSION:",
7590 // The shim must send an alert, but alerts at this point do not
7591 // get successfully decrypted by the runner.
7592 expectedLocalError: "local error: bad record MAC",
7593 })
7594 testCases = append(testCases, testCase{
7595 testType: clientTest,
7596 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7597 config: Config{
7598 MaxVersion: VersionTLS13,
7599 Bugs: ProtocolBugs{
7600 SendUnencryptedALPN: "foo",
7601 },
7602 },
7603 flags: []string{
7604 "-advertise-alpn", "\x03foo\x03bar",
7605 },
7606 shouldFail: true,
7607 expectedError: ":UNEXPECTED_EXTENSION:",
7608 // The shim must send an alert, but alerts at this point do not
7609 // get successfully decrypted by the runner.
7610 expectedLocalError: "local error: bad record MAC",
7611 })
David Benjamin0c40a962016-08-01 12:05:50 -04007612
7613 // Test a known but unoffered extension from the server.
7614 testCases = append(testCases, testCase{
7615 testType: clientTest,
7616 name: "UnofferedExtension-Client",
7617 config: Config{
7618 MaxVersion: VersionTLS12,
7619 Bugs: ProtocolBugs{
7620 SendALPN: "alpn",
7621 },
7622 },
7623 shouldFail: true,
7624 expectedError: ":UNEXPECTED_EXTENSION:",
7625 expectedLocalError: "remote error: unsupported extension",
7626 })
7627 testCases = append(testCases, testCase{
7628 testType: clientTest,
7629 name: "UnofferedExtension-Client-TLS13",
7630 config: Config{
7631 MaxVersion: VersionTLS13,
7632 Bugs: ProtocolBugs{
7633 SendALPN: "alpn",
7634 },
7635 },
7636 shouldFail: true,
7637 expectedError: ":UNEXPECTED_EXTENSION:",
7638 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007639 })
Adam Langley09505632015-07-30 18:10:13 -07007640}
7641
David Benjaminb36a3952015-12-01 18:53:13 -05007642func addRSAClientKeyExchangeTests() {
7643 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7644 testCases = append(testCases, testCase{
7645 testType: serverTest,
7646 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7647 config: Config{
7648 // Ensure the ClientHello version and final
7649 // version are different, to detect if the
7650 // server uses the wrong one.
7651 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007652 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007653 Bugs: ProtocolBugs{
7654 BadRSAClientKeyExchange: bad,
7655 },
7656 },
7657 shouldFail: true,
7658 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7659 })
7660 }
David Benjamine63d9d72016-09-19 18:27:34 -04007661
7662 // The server must compare whatever was in ClientHello.version for the
7663 // RSA premaster.
7664 testCases = append(testCases, testCase{
7665 testType: serverTest,
7666 name: "SendClientVersion-RSA",
7667 config: Config{
7668 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7669 Bugs: ProtocolBugs{
7670 SendClientVersion: 0x1234,
7671 },
7672 },
7673 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7674 })
David Benjaminb36a3952015-12-01 18:53:13 -05007675}
7676
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007677var testCurves = []struct {
7678 name string
7679 id CurveID
7680}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007681 {"P-256", CurveP256},
7682 {"P-384", CurveP384},
7683 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007684 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007685}
7686
Steven Valdez5440fe02016-07-18 12:40:30 -04007687const bogusCurve = 0x1234
7688
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007689func addCurveTests() {
7690 for _, curve := range testCurves {
7691 testCases = append(testCases, testCase{
7692 name: "CurveTest-Client-" + curve.name,
7693 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007694 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007695 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7696 CurvePreferences: []CurveID{curve.id},
7697 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007698 flags: []string{
7699 "-enable-all-curves",
7700 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7701 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007702 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007703 })
7704 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007705 name: "CurveTest-Client-" + curve.name + "-TLS13",
7706 config: Config{
7707 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007708 CurvePreferences: []CurveID{curve.id},
7709 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007710 flags: []string{
7711 "-enable-all-curves",
7712 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7713 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007714 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007715 })
7716 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007717 testType: serverTest,
7718 name: "CurveTest-Server-" + curve.name,
7719 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007720 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007721 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7722 CurvePreferences: []CurveID{curve.id},
7723 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007724 flags: []string{
7725 "-enable-all-curves",
7726 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7727 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007728 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007729 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007730 testCases = append(testCases, testCase{
7731 testType: serverTest,
7732 name: "CurveTest-Server-" + curve.name + "-TLS13",
7733 config: Config{
7734 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007735 CurvePreferences: []CurveID{curve.id},
7736 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007737 flags: []string{
7738 "-enable-all-curves",
7739 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7740 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007741 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007742 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007743 }
David Benjamin241ae832016-01-15 03:04:54 -05007744
7745 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007746 testCases = append(testCases, testCase{
7747 testType: serverTest,
7748 name: "UnknownCurve",
7749 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007750 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007751 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7752 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7753 },
7754 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007755
Steven Valdez803c77a2016-09-06 14:13:43 -04007756 // The server must be tolerant to bogus curves.
7757 testCases = append(testCases, testCase{
7758 testType: serverTest,
7759 name: "UnknownCurve-TLS13",
7760 config: Config{
7761 MaxVersion: VersionTLS13,
7762 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7763 },
7764 })
7765
David Benjamin4c3ddf72016-06-29 18:13:53 -04007766 // The server must not consider ECDHE ciphers when there are no
7767 // supported curves.
7768 testCases = append(testCases, testCase{
7769 testType: serverTest,
7770 name: "NoSupportedCurves",
7771 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007772 MaxVersion: VersionTLS12,
7773 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7774 Bugs: ProtocolBugs{
7775 NoSupportedCurves: true,
7776 },
7777 },
7778 shouldFail: true,
7779 expectedError: ":NO_SHARED_CIPHER:",
7780 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007781 testCases = append(testCases, testCase{
7782 testType: serverTest,
7783 name: "NoSupportedCurves-TLS13",
7784 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007785 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007786 Bugs: ProtocolBugs{
7787 NoSupportedCurves: true,
7788 },
7789 },
7790 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007791 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007792 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007793
7794 // The server must fall back to another cipher when there are no
7795 // supported curves.
7796 testCases = append(testCases, testCase{
7797 testType: serverTest,
7798 name: "NoCommonCurves",
7799 config: Config{
7800 MaxVersion: VersionTLS12,
7801 CipherSuites: []uint16{
7802 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7803 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7804 },
7805 CurvePreferences: []CurveID{CurveP224},
7806 },
7807 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7808 })
7809
7810 // The client must reject bogus curves and disabled curves.
7811 testCases = append(testCases, testCase{
7812 name: "BadECDHECurve",
7813 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007814 MaxVersion: VersionTLS12,
7815 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7816 Bugs: ProtocolBugs{
7817 SendCurve: bogusCurve,
7818 },
7819 },
7820 shouldFail: true,
7821 expectedError: ":WRONG_CURVE:",
7822 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007823 testCases = append(testCases, testCase{
7824 name: "BadECDHECurve-TLS13",
7825 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007826 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007827 Bugs: ProtocolBugs{
7828 SendCurve: bogusCurve,
7829 },
7830 },
7831 shouldFail: true,
7832 expectedError: ":WRONG_CURVE:",
7833 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007834
7835 testCases = append(testCases, testCase{
7836 name: "UnsupportedCurve",
7837 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007838 MaxVersion: VersionTLS12,
7839 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7840 CurvePreferences: []CurveID{CurveP256},
7841 Bugs: ProtocolBugs{
7842 IgnorePeerCurvePreferences: true,
7843 },
7844 },
7845 flags: []string{"-p384-only"},
7846 shouldFail: true,
7847 expectedError: ":WRONG_CURVE:",
7848 })
7849
David Benjamin4f921572016-07-17 14:20:10 +02007850 testCases = append(testCases, testCase{
7851 // TODO(davidben): Add a TLS 1.3 version where
7852 // HelloRetryRequest requests an unsupported curve.
7853 name: "UnsupportedCurve-ServerHello-TLS13",
7854 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007855 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007856 CurvePreferences: []CurveID{CurveP384},
7857 Bugs: ProtocolBugs{
7858 SendCurve: CurveP256,
7859 },
7860 },
7861 flags: []string{"-p384-only"},
7862 shouldFail: true,
7863 expectedError: ":WRONG_CURVE:",
7864 })
7865
David Benjamin4c3ddf72016-06-29 18:13:53 -04007866 // Test invalid curve points.
7867 testCases = append(testCases, testCase{
7868 name: "InvalidECDHPoint-Client",
7869 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007870 MaxVersion: VersionTLS12,
7871 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7872 CurvePreferences: []CurveID{CurveP256},
7873 Bugs: ProtocolBugs{
7874 InvalidECDHPoint: true,
7875 },
7876 },
7877 shouldFail: true,
7878 expectedError: ":INVALID_ENCODING:",
7879 })
7880 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007881 name: "InvalidECDHPoint-Client-TLS13",
7882 config: Config{
7883 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007884 CurvePreferences: []CurveID{CurveP256},
7885 Bugs: ProtocolBugs{
7886 InvalidECDHPoint: true,
7887 },
7888 },
7889 shouldFail: true,
7890 expectedError: ":INVALID_ENCODING:",
7891 })
7892 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007893 testType: serverTest,
7894 name: "InvalidECDHPoint-Server",
7895 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007896 MaxVersion: VersionTLS12,
7897 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7898 CurvePreferences: []CurveID{CurveP256},
7899 Bugs: ProtocolBugs{
7900 InvalidECDHPoint: true,
7901 },
7902 },
7903 shouldFail: true,
7904 expectedError: ":INVALID_ENCODING:",
7905 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007906 testCases = append(testCases, testCase{
7907 testType: serverTest,
7908 name: "InvalidECDHPoint-Server-TLS13",
7909 config: Config{
7910 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007911 CurvePreferences: []CurveID{CurveP256},
7912 Bugs: ProtocolBugs{
7913 InvalidECDHPoint: true,
7914 },
7915 },
7916 shouldFail: true,
7917 expectedError: ":INVALID_ENCODING:",
7918 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007919}
7920
Matt Braithwaite54217e42016-06-13 13:03:47 -07007921func addCECPQ1Tests() {
7922 testCases = append(testCases, testCase{
7923 testType: clientTest,
7924 name: "CECPQ1-Client-BadX25519Part",
7925 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007926 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007927 MinVersion: VersionTLS12,
7928 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7929 Bugs: ProtocolBugs{
7930 CECPQ1BadX25519Part: true,
7931 },
7932 },
7933 flags: []string{"-cipher", "kCECPQ1"},
7934 shouldFail: true,
7935 expectedLocalError: "local error: bad record MAC",
7936 })
7937 testCases = append(testCases, testCase{
7938 testType: clientTest,
7939 name: "CECPQ1-Client-BadNewhopePart",
7940 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007941 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007942 MinVersion: VersionTLS12,
7943 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7944 Bugs: ProtocolBugs{
7945 CECPQ1BadNewhopePart: true,
7946 },
7947 },
7948 flags: []string{"-cipher", "kCECPQ1"},
7949 shouldFail: true,
7950 expectedLocalError: "local error: bad record MAC",
7951 })
7952 testCases = append(testCases, testCase{
7953 testType: serverTest,
7954 name: "CECPQ1-Server-BadX25519Part",
7955 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007956 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007957 MinVersion: VersionTLS12,
7958 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7959 Bugs: ProtocolBugs{
7960 CECPQ1BadX25519Part: true,
7961 },
7962 },
7963 flags: []string{"-cipher", "kCECPQ1"},
7964 shouldFail: true,
7965 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7966 })
7967 testCases = append(testCases, testCase{
7968 testType: serverTest,
7969 name: "CECPQ1-Server-BadNewhopePart",
7970 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007971 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007972 MinVersion: VersionTLS12,
7973 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7974 Bugs: ProtocolBugs{
7975 CECPQ1BadNewhopePart: true,
7976 },
7977 },
7978 flags: []string{"-cipher", "kCECPQ1"},
7979 shouldFail: true,
7980 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7981 })
7982}
7983
David Benjamin5c4e8572016-08-19 17:44:53 -04007984func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007985 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007986 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007987 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007988 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007989 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7990 Bugs: ProtocolBugs{
7991 // This is a 1234-bit prime number, generated
7992 // with:
7993 // openssl gendh 1234 | openssl asn1parse -i
7994 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7995 },
7996 },
David Benjamin9e68f192016-06-30 14:55:33 -04007997 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007998 })
7999 testCases = append(testCases, testCase{
8000 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008001 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008002 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008003 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008004 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8005 },
8006 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008007 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008008 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008009}
8010
David Benjaminc9ae27c2016-06-24 22:56:37 -04008011func addTLS13RecordTests() {
8012 testCases = append(testCases, testCase{
8013 name: "TLS13-RecordPadding",
8014 config: Config{
8015 MaxVersion: VersionTLS13,
8016 MinVersion: VersionTLS13,
8017 Bugs: ProtocolBugs{
8018 RecordPadding: 10,
8019 },
8020 },
8021 })
8022
8023 testCases = append(testCases, testCase{
8024 name: "TLS13-EmptyRecords",
8025 config: Config{
8026 MaxVersion: VersionTLS13,
8027 MinVersion: VersionTLS13,
8028 Bugs: ProtocolBugs{
8029 OmitRecordContents: true,
8030 },
8031 },
8032 shouldFail: true,
8033 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8034 })
8035
8036 testCases = append(testCases, testCase{
8037 name: "TLS13-OnlyPadding",
8038 config: Config{
8039 MaxVersion: VersionTLS13,
8040 MinVersion: VersionTLS13,
8041 Bugs: ProtocolBugs{
8042 OmitRecordContents: true,
8043 RecordPadding: 10,
8044 },
8045 },
8046 shouldFail: true,
8047 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8048 })
8049
8050 testCases = append(testCases, testCase{
8051 name: "TLS13-WrongOuterRecord",
8052 config: Config{
8053 MaxVersion: VersionTLS13,
8054 MinVersion: VersionTLS13,
8055 Bugs: ProtocolBugs{
8056 OuterRecordType: recordTypeHandshake,
8057 },
8058 },
8059 shouldFail: true,
8060 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8061 })
8062}
8063
Steven Valdez5b986082016-09-01 12:29:49 -04008064func addSessionTicketTests() {
8065 testCases = append(testCases, testCase{
8066 // In TLS 1.2 and below, empty NewSessionTicket messages
8067 // mean the server changed its mind on sending a ticket.
8068 name: "SendEmptySessionTicket",
8069 config: Config{
8070 MaxVersion: VersionTLS12,
8071 Bugs: ProtocolBugs{
8072 SendEmptySessionTicket: true,
8073 },
8074 },
8075 flags: []string{"-expect-no-session"},
8076 })
8077
8078 // Test that the server ignores unknown PSK modes.
8079 testCases = append(testCases, testCase{
8080 testType: serverTest,
8081 name: "TLS13-SendUnknownModeSessionTicket-Server",
8082 config: Config{
8083 MaxVersion: VersionTLS13,
8084 Bugs: ProtocolBugs{
8085 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008086 },
8087 },
8088 resumeSession: true,
8089 expectedResumeVersion: VersionTLS13,
8090 })
8091
Steven Valdeza833c352016-11-01 13:39:36 -04008092 // Test that the server does not send session tickets with no matching key exchange mode.
8093 testCases = append(testCases, testCase{
8094 testType: serverTest,
8095 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8096 config: Config{
8097 MaxVersion: VersionTLS13,
8098 Bugs: ProtocolBugs{
8099 SendPSKKeyExchangeModes: []byte{0x1a},
8100 ExpectNoNewSessionTicket: true,
8101 },
8102 },
8103 })
8104
8105 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008106 testCases = append(testCases, testCase{
8107 testType: serverTest,
8108 name: "TLS13-SendBadKEModeSessionTicket-Server",
8109 config: Config{
8110 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008111 },
8112 resumeConfig: &Config{
8113 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008114 Bugs: ProtocolBugs{
8115 SendPSKKeyExchangeModes: []byte{0x1a},
8116 },
8117 },
8118 resumeSession: true,
8119 expectResumeRejected: true,
8120 })
8121
Steven Valdeza833c352016-11-01 13:39:36 -04008122 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008123 testCases = append(testCases, testCase{
8124 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008125 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008126 config: Config{
8127 MaxVersion: VersionTLS13,
8128 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008129 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008130 },
8131 },
Steven Valdeza833c352016-11-01 13:39:36 -04008132 resumeSession: true,
8133 flags: []string{
8134 "-resumption-delay", "10",
8135 },
Steven Valdez5b986082016-09-01 12:29:49 -04008136 })
8137
Steven Valdeza833c352016-11-01 13:39:36 -04008138 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008139 testCases = append(testCases, testCase{
8140 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008141 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008142 config: Config{
8143 MaxVersion: VersionTLS13,
8144 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008145 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008146 },
8147 },
Steven Valdeza833c352016-11-01 13:39:36 -04008148 resumeSession: true,
8149 shouldFail: true,
8150 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008151 })
8152
Steven Valdez5b986082016-09-01 12:29:49 -04008153}
8154
David Benjamin82261be2016-07-07 14:32:50 -07008155func addChangeCipherSpecTests() {
8156 // Test missing ChangeCipherSpecs.
8157 testCases = append(testCases, testCase{
8158 name: "SkipChangeCipherSpec-Client",
8159 config: Config{
8160 MaxVersion: VersionTLS12,
8161 Bugs: ProtocolBugs{
8162 SkipChangeCipherSpec: true,
8163 },
8164 },
8165 shouldFail: true,
8166 expectedError: ":UNEXPECTED_RECORD:",
8167 })
8168 testCases = append(testCases, testCase{
8169 testType: serverTest,
8170 name: "SkipChangeCipherSpec-Server",
8171 config: Config{
8172 MaxVersion: VersionTLS12,
8173 Bugs: ProtocolBugs{
8174 SkipChangeCipherSpec: true,
8175 },
8176 },
8177 shouldFail: true,
8178 expectedError: ":UNEXPECTED_RECORD:",
8179 })
8180 testCases = append(testCases, testCase{
8181 testType: serverTest,
8182 name: "SkipChangeCipherSpec-Server-NPN",
8183 config: Config{
8184 MaxVersion: VersionTLS12,
8185 NextProtos: []string{"bar"},
8186 Bugs: ProtocolBugs{
8187 SkipChangeCipherSpec: true,
8188 },
8189 },
8190 flags: []string{
8191 "-advertise-npn", "\x03foo\x03bar\x03baz",
8192 },
8193 shouldFail: true,
8194 expectedError: ":UNEXPECTED_RECORD:",
8195 })
8196
8197 // Test synchronization between the handshake and ChangeCipherSpec.
8198 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8199 // rejected. Test both with and without handshake packing to handle both
8200 // when the partial post-CCS message is in its own record and when it is
8201 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008202 for _, packed := range []bool{false, true} {
8203 var suffix string
8204 if packed {
8205 suffix = "-Packed"
8206 }
8207
8208 testCases = append(testCases, testCase{
8209 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8210 config: Config{
8211 MaxVersion: VersionTLS12,
8212 Bugs: ProtocolBugs{
8213 FragmentAcrossChangeCipherSpec: true,
8214 PackHandshakeFlight: packed,
8215 },
8216 },
8217 shouldFail: true,
8218 expectedError: ":UNEXPECTED_RECORD:",
8219 })
8220 testCases = append(testCases, testCase{
8221 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8222 config: Config{
8223 MaxVersion: VersionTLS12,
8224 },
8225 resumeSession: true,
8226 resumeConfig: &Config{
8227 MaxVersion: VersionTLS12,
8228 Bugs: ProtocolBugs{
8229 FragmentAcrossChangeCipherSpec: true,
8230 PackHandshakeFlight: packed,
8231 },
8232 },
8233 shouldFail: true,
8234 expectedError: ":UNEXPECTED_RECORD:",
8235 })
8236 testCases = append(testCases, testCase{
8237 testType: serverTest,
8238 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8239 config: Config{
8240 MaxVersion: VersionTLS12,
8241 Bugs: ProtocolBugs{
8242 FragmentAcrossChangeCipherSpec: true,
8243 PackHandshakeFlight: packed,
8244 },
8245 },
8246 shouldFail: true,
8247 expectedError: ":UNEXPECTED_RECORD:",
8248 })
8249 testCases = append(testCases, testCase{
8250 testType: serverTest,
8251 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8252 config: Config{
8253 MaxVersion: VersionTLS12,
8254 },
8255 resumeSession: true,
8256 resumeConfig: &Config{
8257 MaxVersion: VersionTLS12,
8258 Bugs: ProtocolBugs{
8259 FragmentAcrossChangeCipherSpec: true,
8260 PackHandshakeFlight: packed,
8261 },
8262 },
8263 shouldFail: true,
8264 expectedError: ":UNEXPECTED_RECORD:",
8265 })
8266 testCases = append(testCases, testCase{
8267 testType: serverTest,
8268 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8269 config: Config{
8270 MaxVersion: VersionTLS12,
8271 NextProtos: []string{"bar"},
8272 Bugs: ProtocolBugs{
8273 FragmentAcrossChangeCipherSpec: true,
8274 PackHandshakeFlight: packed,
8275 },
8276 },
8277 flags: []string{
8278 "-advertise-npn", "\x03foo\x03bar\x03baz",
8279 },
8280 shouldFail: true,
8281 expectedError: ":UNEXPECTED_RECORD:",
8282 })
8283 }
8284
David Benjamin61672812016-07-14 23:10:43 -04008285 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8286 // messages in the handshake queue. Do this by testing the server
8287 // reading the client Finished, reversing the flight so Finished comes
8288 // first.
8289 testCases = append(testCases, testCase{
8290 protocol: dtls,
8291 testType: serverTest,
8292 name: "SendUnencryptedFinished-DTLS",
8293 config: Config{
8294 MaxVersion: VersionTLS12,
8295 Bugs: ProtocolBugs{
8296 SendUnencryptedFinished: true,
8297 ReverseHandshakeFragments: true,
8298 },
8299 },
8300 shouldFail: true,
8301 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8302 })
8303
Steven Valdez143e8b32016-07-11 13:19:03 -04008304 // Test synchronization between encryption changes and the handshake in
8305 // TLS 1.3, where ChangeCipherSpec is implicit.
8306 testCases = append(testCases, testCase{
8307 name: "PartialEncryptedExtensionsWithServerHello",
8308 config: Config{
8309 MaxVersion: VersionTLS13,
8310 Bugs: ProtocolBugs{
8311 PartialEncryptedExtensionsWithServerHello: true,
8312 },
8313 },
8314 shouldFail: true,
8315 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8316 })
8317 testCases = append(testCases, testCase{
8318 testType: serverTest,
8319 name: "PartialClientFinishedWithClientHello",
8320 config: Config{
8321 MaxVersion: VersionTLS13,
8322 Bugs: ProtocolBugs{
8323 PartialClientFinishedWithClientHello: true,
8324 },
8325 },
8326 shouldFail: true,
8327 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8328 })
8329
David Benjamin82261be2016-07-07 14:32:50 -07008330 // Test that early ChangeCipherSpecs are handled correctly.
8331 testCases = append(testCases, testCase{
8332 testType: serverTest,
8333 name: "EarlyChangeCipherSpec-server-1",
8334 config: Config{
8335 MaxVersion: VersionTLS12,
8336 Bugs: ProtocolBugs{
8337 EarlyChangeCipherSpec: 1,
8338 },
8339 },
8340 shouldFail: true,
8341 expectedError: ":UNEXPECTED_RECORD:",
8342 })
8343 testCases = append(testCases, testCase{
8344 testType: serverTest,
8345 name: "EarlyChangeCipherSpec-server-2",
8346 config: Config{
8347 MaxVersion: VersionTLS12,
8348 Bugs: ProtocolBugs{
8349 EarlyChangeCipherSpec: 2,
8350 },
8351 },
8352 shouldFail: true,
8353 expectedError: ":UNEXPECTED_RECORD:",
8354 })
8355 testCases = append(testCases, testCase{
8356 protocol: dtls,
8357 name: "StrayChangeCipherSpec",
8358 config: Config{
8359 // TODO(davidben): Once DTLS 1.3 exists, test
8360 // that stray ChangeCipherSpec messages are
8361 // rejected.
8362 MaxVersion: VersionTLS12,
8363 Bugs: ProtocolBugs{
8364 StrayChangeCipherSpec: true,
8365 },
8366 },
8367 })
8368
8369 // Test that the contents of ChangeCipherSpec are checked.
8370 testCases = append(testCases, testCase{
8371 name: "BadChangeCipherSpec-1",
8372 config: Config{
8373 MaxVersion: VersionTLS12,
8374 Bugs: ProtocolBugs{
8375 BadChangeCipherSpec: []byte{2},
8376 },
8377 },
8378 shouldFail: true,
8379 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8380 })
8381 testCases = append(testCases, testCase{
8382 name: "BadChangeCipherSpec-2",
8383 config: Config{
8384 MaxVersion: VersionTLS12,
8385 Bugs: ProtocolBugs{
8386 BadChangeCipherSpec: []byte{1, 1},
8387 },
8388 },
8389 shouldFail: true,
8390 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8391 })
8392 testCases = append(testCases, testCase{
8393 protocol: dtls,
8394 name: "BadChangeCipherSpec-DTLS-1",
8395 config: Config{
8396 MaxVersion: VersionTLS12,
8397 Bugs: ProtocolBugs{
8398 BadChangeCipherSpec: []byte{2},
8399 },
8400 },
8401 shouldFail: true,
8402 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8403 })
8404 testCases = append(testCases, testCase{
8405 protocol: dtls,
8406 name: "BadChangeCipherSpec-DTLS-2",
8407 config: Config{
8408 MaxVersion: VersionTLS12,
8409 Bugs: ProtocolBugs{
8410 BadChangeCipherSpec: []byte{1, 1},
8411 },
8412 },
8413 shouldFail: true,
8414 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8415 })
8416}
8417
David Benjamincd2c8062016-09-09 11:28:16 -04008418type perMessageTest struct {
8419 messageType uint8
8420 test testCase
8421}
8422
8423// makePerMessageTests returns a series of test templates which cover each
8424// message in the TLS handshake. These may be used with bugs like
8425// WrongMessageType to fully test a per-message bug.
8426func makePerMessageTests() []perMessageTest {
8427 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008428 for _, protocol := range []protocol{tls, dtls} {
8429 var suffix string
8430 if protocol == dtls {
8431 suffix = "-DTLS"
8432 }
8433
David Benjamincd2c8062016-09-09 11:28:16 -04008434 ret = append(ret, perMessageTest{
8435 messageType: typeClientHello,
8436 test: testCase{
8437 protocol: protocol,
8438 testType: serverTest,
8439 name: "ClientHello" + suffix,
8440 config: Config{
8441 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008442 },
8443 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008444 })
8445
8446 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008447 ret = append(ret, perMessageTest{
8448 messageType: typeHelloVerifyRequest,
8449 test: testCase{
8450 protocol: protocol,
8451 name: "HelloVerifyRequest" + suffix,
8452 config: Config{
8453 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008454 },
8455 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008456 })
8457 }
8458
David Benjamincd2c8062016-09-09 11:28:16 -04008459 ret = append(ret, perMessageTest{
8460 messageType: typeServerHello,
8461 test: testCase{
8462 protocol: protocol,
8463 name: "ServerHello" + suffix,
8464 config: Config{
8465 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008466 },
8467 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008468 })
8469
David Benjamincd2c8062016-09-09 11:28:16 -04008470 ret = append(ret, perMessageTest{
8471 messageType: typeCertificate,
8472 test: testCase{
8473 protocol: protocol,
8474 name: "ServerCertificate" + suffix,
8475 config: Config{
8476 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008477 },
8478 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008479 })
8480
David Benjamincd2c8062016-09-09 11:28:16 -04008481 ret = append(ret, perMessageTest{
8482 messageType: typeCertificateStatus,
8483 test: testCase{
8484 protocol: protocol,
8485 name: "CertificateStatus" + suffix,
8486 config: Config{
8487 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008488 },
David Benjamincd2c8062016-09-09 11:28:16 -04008489 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008490 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008491 })
8492
David Benjamincd2c8062016-09-09 11:28:16 -04008493 ret = append(ret, perMessageTest{
8494 messageType: typeServerKeyExchange,
8495 test: testCase{
8496 protocol: protocol,
8497 name: "ServerKeyExchange" + suffix,
8498 config: Config{
8499 MaxVersion: VersionTLS12,
8500 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008501 },
8502 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008503 })
8504
David Benjamincd2c8062016-09-09 11:28:16 -04008505 ret = append(ret, perMessageTest{
8506 messageType: typeCertificateRequest,
8507 test: testCase{
8508 protocol: protocol,
8509 name: "CertificateRequest" + suffix,
8510 config: Config{
8511 MaxVersion: VersionTLS12,
8512 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008513 },
8514 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008515 })
8516
David Benjamincd2c8062016-09-09 11:28:16 -04008517 ret = append(ret, perMessageTest{
8518 messageType: typeServerHelloDone,
8519 test: testCase{
8520 protocol: protocol,
8521 name: "ServerHelloDone" + suffix,
8522 config: Config{
8523 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008524 },
8525 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008526 })
8527
David Benjamincd2c8062016-09-09 11:28:16 -04008528 ret = append(ret, perMessageTest{
8529 messageType: typeCertificate,
8530 test: testCase{
8531 testType: serverTest,
8532 protocol: protocol,
8533 name: "ClientCertificate" + suffix,
8534 config: Config{
8535 Certificates: []Certificate{rsaCertificate},
8536 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008537 },
David Benjamincd2c8062016-09-09 11:28:16 -04008538 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008539 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008540 })
8541
David Benjamincd2c8062016-09-09 11:28:16 -04008542 ret = append(ret, perMessageTest{
8543 messageType: typeCertificateVerify,
8544 test: testCase{
8545 testType: serverTest,
8546 protocol: protocol,
8547 name: "CertificateVerify" + suffix,
8548 config: Config{
8549 Certificates: []Certificate{rsaCertificate},
8550 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008551 },
David Benjamincd2c8062016-09-09 11:28:16 -04008552 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008553 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008554 })
8555
David Benjamincd2c8062016-09-09 11:28:16 -04008556 ret = append(ret, perMessageTest{
8557 messageType: typeClientKeyExchange,
8558 test: testCase{
8559 testType: serverTest,
8560 protocol: protocol,
8561 name: "ClientKeyExchange" + suffix,
8562 config: Config{
8563 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008564 },
8565 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008566 })
8567
8568 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008569 ret = append(ret, perMessageTest{
8570 messageType: typeNextProtocol,
8571 test: testCase{
8572 testType: serverTest,
8573 protocol: protocol,
8574 name: "NextProtocol" + suffix,
8575 config: Config{
8576 MaxVersion: VersionTLS12,
8577 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008578 },
David Benjamincd2c8062016-09-09 11:28:16 -04008579 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008580 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008581 })
8582
David Benjamincd2c8062016-09-09 11:28:16 -04008583 ret = append(ret, perMessageTest{
8584 messageType: typeChannelID,
8585 test: testCase{
8586 testType: serverTest,
8587 protocol: protocol,
8588 name: "ChannelID" + suffix,
8589 config: Config{
8590 MaxVersion: VersionTLS12,
8591 ChannelID: channelIDKey,
8592 },
8593 flags: []string{
8594 "-expect-channel-id",
8595 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008596 },
8597 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008598 })
8599 }
8600
David Benjamincd2c8062016-09-09 11:28:16 -04008601 ret = append(ret, perMessageTest{
8602 messageType: typeFinished,
8603 test: testCase{
8604 testType: serverTest,
8605 protocol: protocol,
8606 name: "ClientFinished" + suffix,
8607 config: Config{
8608 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008609 },
8610 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008611 })
8612
David Benjamincd2c8062016-09-09 11:28:16 -04008613 ret = append(ret, perMessageTest{
8614 messageType: typeNewSessionTicket,
8615 test: testCase{
8616 protocol: protocol,
8617 name: "NewSessionTicket" + suffix,
8618 config: Config{
8619 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008620 },
8621 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008622 })
8623
David Benjamincd2c8062016-09-09 11:28:16 -04008624 ret = append(ret, perMessageTest{
8625 messageType: typeFinished,
8626 test: testCase{
8627 protocol: protocol,
8628 name: "ServerFinished" + suffix,
8629 config: Config{
8630 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008631 },
8632 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008633 })
8634
8635 }
David Benjamincd2c8062016-09-09 11:28:16 -04008636
8637 ret = append(ret, perMessageTest{
8638 messageType: typeClientHello,
8639 test: testCase{
8640 testType: serverTest,
8641 name: "TLS13-ClientHello",
8642 config: Config{
8643 MaxVersion: VersionTLS13,
8644 },
8645 },
8646 })
8647
8648 ret = append(ret, perMessageTest{
8649 messageType: typeServerHello,
8650 test: testCase{
8651 name: "TLS13-ServerHello",
8652 config: Config{
8653 MaxVersion: VersionTLS13,
8654 },
8655 },
8656 })
8657
8658 ret = append(ret, perMessageTest{
8659 messageType: typeEncryptedExtensions,
8660 test: testCase{
8661 name: "TLS13-EncryptedExtensions",
8662 config: Config{
8663 MaxVersion: VersionTLS13,
8664 },
8665 },
8666 })
8667
8668 ret = append(ret, perMessageTest{
8669 messageType: typeCertificateRequest,
8670 test: testCase{
8671 name: "TLS13-CertificateRequest",
8672 config: Config{
8673 MaxVersion: VersionTLS13,
8674 ClientAuth: RequireAnyClientCert,
8675 },
8676 },
8677 })
8678
8679 ret = append(ret, perMessageTest{
8680 messageType: typeCertificate,
8681 test: testCase{
8682 name: "TLS13-ServerCertificate",
8683 config: Config{
8684 MaxVersion: VersionTLS13,
8685 },
8686 },
8687 })
8688
8689 ret = append(ret, perMessageTest{
8690 messageType: typeCertificateVerify,
8691 test: testCase{
8692 name: "TLS13-ServerCertificateVerify",
8693 config: Config{
8694 MaxVersion: VersionTLS13,
8695 },
8696 },
8697 })
8698
8699 ret = append(ret, perMessageTest{
8700 messageType: typeFinished,
8701 test: testCase{
8702 name: "TLS13-ServerFinished",
8703 config: Config{
8704 MaxVersion: VersionTLS13,
8705 },
8706 },
8707 })
8708
8709 ret = append(ret, perMessageTest{
8710 messageType: typeCertificate,
8711 test: testCase{
8712 testType: serverTest,
8713 name: "TLS13-ClientCertificate",
8714 config: Config{
8715 Certificates: []Certificate{rsaCertificate},
8716 MaxVersion: VersionTLS13,
8717 },
8718 flags: []string{"-require-any-client-certificate"},
8719 },
8720 })
8721
8722 ret = append(ret, perMessageTest{
8723 messageType: typeCertificateVerify,
8724 test: testCase{
8725 testType: serverTest,
8726 name: "TLS13-ClientCertificateVerify",
8727 config: Config{
8728 Certificates: []Certificate{rsaCertificate},
8729 MaxVersion: VersionTLS13,
8730 },
8731 flags: []string{"-require-any-client-certificate"},
8732 },
8733 })
8734
8735 ret = append(ret, perMessageTest{
8736 messageType: typeFinished,
8737 test: testCase{
8738 testType: serverTest,
8739 name: "TLS13-ClientFinished",
8740 config: Config{
8741 MaxVersion: VersionTLS13,
8742 },
8743 },
8744 })
8745
8746 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008747}
8748
David Benjamincd2c8062016-09-09 11:28:16 -04008749func addWrongMessageTypeTests() {
8750 for _, t := range makePerMessageTests() {
8751 t.test.name = "WrongMessageType-" + t.test.name
8752 t.test.config.Bugs.SendWrongMessageType = t.messageType
8753 t.test.shouldFail = true
8754 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8755 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008756
David Benjamincd2c8062016-09-09 11:28:16 -04008757 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8758 // In TLS 1.3, a bad ServerHello means the client sends
8759 // an unencrypted alert while the server expects
8760 // encryption, so the alert is not readable by runner.
8761 t.test.expectedLocalError = "local error: bad record MAC"
8762 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008763
David Benjamincd2c8062016-09-09 11:28:16 -04008764 testCases = append(testCases, t.test)
8765 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008766}
8767
David Benjamin639846e2016-09-09 11:41:18 -04008768func addTrailingMessageDataTests() {
8769 for _, t := range makePerMessageTests() {
8770 t.test.name = "TrailingMessageData-" + t.test.name
8771 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8772 t.test.shouldFail = true
8773 t.test.expectedError = ":DECODE_ERROR:"
8774 t.test.expectedLocalError = "remote error: error decoding message"
8775
8776 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8777 // In TLS 1.3, a bad ServerHello means the client sends
8778 // an unencrypted alert while the server expects
8779 // encryption, so the alert is not readable by runner.
8780 t.test.expectedLocalError = "local error: bad record MAC"
8781 }
8782
8783 if t.messageType == typeFinished {
8784 // Bad Finished messages read as the verify data having
8785 // the wrong length.
8786 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8787 t.test.expectedLocalError = "remote error: error decrypting message"
8788 }
8789
8790 testCases = append(testCases, t.test)
8791 }
8792}
8793
Steven Valdez143e8b32016-07-11 13:19:03 -04008794func addTLS13HandshakeTests() {
8795 testCases = append(testCases, testCase{
8796 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008797 name: "NegotiatePSKResumption-TLS13",
8798 config: Config{
8799 MaxVersion: VersionTLS13,
8800 Bugs: ProtocolBugs{
8801 NegotiatePSKResumption: true,
8802 },
8803 },
8804 resumeSession: true,
8805 shouldFail: true,
8806 expectedError: ":UNEXPECTED_EXTENSION:",
8807 })
8808
8809 testCases = append(testCases, testCase{
8810 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008811 name: "MissingKeyShare-Client",
8812 config: Config{
8813 MaxVersion: VersionTLS13,
8814 Bugs: ProtocolBugs{
8815 MissingKeyShare: true,
8816 },
8817 },
8818 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008819 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008820 })
8821
8822 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008823 testType: serverTest,
8824 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008825 config: Config{
8826 MaxVersion: VersionTLS13,
8827 Bugs: ProtocolBugs{
8828 MissingKeyShare: true,
8829 },
8830 },
8831 shouldFail: true,
8832 expectedError: ":MISSING_KEY_SHARE:",
8833 })
8834
8835 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008836 testType: serverTest,
8837 name: "DuplicateKeyShares",
8838 config: Config{
8839 MaxVersion: VersionTLS13,
8840 Bugs: ProtocolBugs{
8841 DuplicateKeyShares: true,
8842 },
8843 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008844 shouldFail: true,
8845 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008846 })
8847
8848 testCases = append(testCases, testCase{
8849 testType: clientTest,
8850 name: "EmptyEncryptedExtensions",
8851 config: Config{
8852 MaxVersion: VersionTLS13,
8853 Bugs: ProtocolBugs{
8854 EmptyEncryptedExtensions: true,
8855 },
8856 },
8857 shouldFail: true,
8858 expectedLocalError: "remote error: error decoding message",
8859 })
8860
8861 testCases = append(testCases, testCase{
8862 testType: clientTest,
8863 name: "EncryptedExtensionsWithKeyShare",
8864 config: Config{
8865 MaxVersion: VersionTLS13,
8866 Bugs: ProtocolBugs{
8867 EncryptedExtensionsWithKeyShare: true,
8868 },
8869 },
8870 shouldFail: true,
8871 expectedLocalError: "remote error: unsupported extension",
8872 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008873
8874 testCases = append(testCases, testCase{
8875 testType: serverTest,
8876 name: "SendHelloRetryRequest",
8877 config: Config{
8878 MaxVersion: VersionTLS13,
8879 // Require a HelloRetryRequest for every curve.
8880 DefaultCurves: []CurveID{},
8881 },
8882 expectedCurveID: CurveX25519,
8883 })
8884
8885 testCases = append(testCases, testCase{
8886 testType: serverTest,
8887 name: "SendHelloRetryRequest-2",
8888 config: Config{
8889 MaxVersion: VersionTLS13,
8890 DefaultCurves: []CurveID{CurveP384},
8891 },
8892 // Although the ClientHello did not predict our preferred curve,
8893 // we always select it whether it is predicted or not.
8894 expectedCurveID: CurveX25519,
8895 })
8896
8897 testCases = append(testCases, testCase{
8898 name: "UnknownCurve-HelloRetryRequest",
8899 config: Config{
8900 MaxVersion: VersionTLS13,
8901 // P-384 requires HelloRetryRequest in BoringSSL.
8902 CurvePreferences: []CurveID{CurveP384},
8903 Bugs: ProtocolBugs{
8904 SendHelloRetryRequestCurve: bogusCurve,
8905 },
8906 },
8907 shouldFail: true,
8908 expectedError: ":WRONG_CURVE:",
8909 })
8910
8911 testCases = append(testCases, testCase{
8912 name: "DisabledCurve-HelloRetryRequest",
8913 config: Config{
8914 MaxVersion: VersionTLS13,
8915 CurvePreferences: []CurveID{CurveP256},
8916 Bugs: ProtocolBugs{
8917 IgnorePeerCurvePreferences: true,
8918 },
8919 },
8920 flags: []string{"-p384-only"},
8921 shouldFail: true,
8922 expectedError: ":WRONG_CURVE:",
8923 })
8924
8925 testCases = append(testCases, testCase{
8926 name: "UnnecessaryHelloRetryRequest",
8927 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04008928 MaxVersion: VersionTLS13,
8929 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04008930 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04008931 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04008932 },
8933 },
8934 shouldFail: true,
8935 expectedError: ":WRONG_CURVE:",
8936 })
8937
8938 testCases = append(testCases, testCase{
8939 name: "SecondHelloRetryRequest",
8940 config: Config{
8941 MaxVersion: VersionTLS13,
8942 // P-384 requires HelloRetryRequest in BoringSSL.
8943 CurvePreferences: []CurveID{CurveP384},
8944 Bugs: ProtocolBugs{
8945 SecondHelloRetryRequest: true,
8946 },
8947 },
8948 shouldFail: true,
8949 expectedError: ":UNEXPECTED_MESSAGE:",
8950 })
8951
8952 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04008953 name: "HelloRetryRequest-Empty",
8954 config: Config{
8955 MaxVersion: VersionTLS13,
8956 Bugs: ProtocolBugs{
8957 AlwaysSendHelloRetryRequest: true,
8958 },
8959 },
8960 shouldFail: true,
8961 expectedError: ":DECODE_ERROR:",
8962 })
8963
8964 testCases = append(testCases, testCase{
8965 name: "HelloRetryRequest-DuplicateCurve",
8966 config: Config{
8967 MaxVersion: VersionTLS13,
8968 // P-384 requires a HelloRetryRequest against BoringSSL's default
8969 // configuration. Assert this ExpectMissingKeyShare.
8970 CurvePreferences: []CurveID{CurveP384},
8971 Bugs: ProtocolBugs{
8972 ExpectMissingKeyShare: true,
8973 DuplicateHelloRetryRequestExtensions: true,
8974 },
8975 },
8976 shouldFail: true,
8977 expectedError: ":DUPLICATE_EXTENSION:",
8978 expectedLocalError: "remote error: illegal parameter",
8979 })
8980
8981 testCases = append(testCases, testCase{
8982 name: "HelloRetryRequest-Cookie",
8983 config: Config{
8984 MaxVersion: VersionTLS13,
8985 Bugs: ProtocolBugs{
8986 SendHelloRetryRequestCookie: []byte("cookie"),
8987 },
8988 },
8989 })
8990
8991 testCases = append(testCases, testCase{
8992 name: "HelloRetryRequest-DuplicateCookie",
8993 config: Config{
8994 MaxVersion: VersionTLS13,
8995 Bugs: ProtocolBugs{
8996 SendHelloRetryRequestCookie: []byte("cookie"),
8997 DuplicateHelloRetryRequestExtensions: true,
8998 },
8999 },
9000 shouldFail: true,
9001 expectedError: ":DUPLICATE_EXTENSION:",
9002 expectedLocalError: "remote error: illegal parameter",
9003 })
9004
9005 testCases = append(testCases, testCase{
9006 name: "HelloRetryRequest-EmptyCookie",
9007 config: Config{
9008 MaxVersion: VersionTLS13,
9009 Bugs: ProtocolBugs{
9010 SendHelloRetryRequestCookie: []byte{},
9011 },
9012 },
9013 shouldFail: true,
9014 expectedError: ":DECODE_ERROR:",
9015 })
9016
9017 testCases = append(testCases, testCase{
9018 name: "HelloRetryRequest-Cookie-Curve",
9019 config: Config{
9020 MaxVersion: VersionTLS13,
9021 // P-384 requires HelloRetryRequest in BoringSSL.
9022 CurvePreferences: []CurveID{CurveP384},
9023 Bugs: ProtocolBugs{
9024 SendHelloRetryRequestCookie: []byte("cookie"),
9025 ExpectMissingKeyShare: true,
9026 },
9027 },
9028 })
9029
9030 testCases = append(testCases, testCase{
9031 name: "HelloRetryRequest-Unknown",
9032 config: Config{
9033 MaxVersion: VersionTLS13,
9034 Bugs: ProtocolBugs{
9035 CustomHelloRetryRequestExtension: "extension",
9036 },
9037 },
9038 shouldFail: true,
9039 expectedError: ":UNEXPECTED_EXTENSION:",
9040 expectedLocalError: "remote error: unsupported extension",
9041 })
9042
9043 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009044 testType: serverTest,
9045 name: "SecondClientHelloMissingKeyShare",
9046 config: Config{
9047 MaxVersion: VersionTLS13,
9048 DefaultCurves: []CurveID{},
9049 Bugs: ProtocolBugs{
9050 SecondClientHelloMissingKeyShare: true,
9051 },
9052 },
9053 shouldFail: true,
9054 expectedError: ":MISSING_KEY_SHARE:",
9055 })
9056
9057 testCases = append(testCases, testCase{
9058 testType: serverTest,
9059 name: "SecondClientHelloWrongCurve",
9060 config: Config{
9061 MaxVersion: VersionTLS13,
9062 DefaultCurves: []CurveID{},
9063 Bugs: ProtocolBugs{
9064 MisinterpretHelloRetryRequestCurve: CurveP521,
9065 },
9066 },
9067 shouldFail: true,
9068 expectedError: ":WRONG_CURVE:",
9069 })
9070
9071 testCases = append(testCases, testCase{
9072 name: "HelloRetryRequestVersionMismatch",
9073 config: Config{
9074 MaxVersion: VersionTLS13,
9075 // P-384 requires HelloRetryRequest in BoringSSL.
9076 CurvePreferences: []CurveID{CurveP384},
9077 Bugs: ProtocolBugs{
9078 SendServerHelloVersion: 0x0305,
9079 },
9080 },
9081 shouldFail: true,
9082 expectedError: ":WRONG_VERSION_NUMBER:",
9083 })
9084
9085 testCases = append(testCases, testCase{
9086 name: "HelloRetryRequestCurveMismatch",
9087 config: Config{
9088 MaxVersion: VersionTLS13,
9089 // P-384 requires HelloRetryRequest in BoringSSL.
9090 CurvePreferences: []CurveID{CurveP384},
9091 Bugs: ProtocolBugs{
9092 // Send P-384 (correct) in the HelloRetryRequest.
9093 SendHelloRetryRequestCurve: CurveP384,
9094 // But send P-256 in the ServerHello.
9095 SendCurve: CurveP256,
9096 },
9097 },
9098 shouldFail: true,
9099 expectedError: ":WRONG_CURVE:",
9100 })
9101
9102 // Test the server selecting a curve that requires a HelloRetryRequest
9103 // without sending it.
9104 testCases = append(testCases, testCase{
9105 name: "SkipHelloRetryRequest",
9106 config: Config{
9107 MaxVersion: VersionTLS13,
9108 // P-384 requires HelloRetryRequest in BoringSSL.
9109 CurvePreferences: []CurveID{CurveP384},
9110 Bugs: ProtocolBugs{
9111 SkipHelloRetryRequest: true,
9112 },
9113 },
9114 shouldFail: true,
9115 expectedError: ":WRONG_CURVE:",
9116 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009117
9118 testCases = append(testCases, testCase{
9119 name: "TLS13-RequestContextInHandshake",
9120 config: Config{
9121 MaxVersion: VersionTLS13,
9122 MinVersion: VersionTLS13,
9123 ClientAuth: RequireAnyClientCert,
9124 Bugs: ProtocolBugs{
9125 SendRequestContext: []byte("request context"),
9126 },
9127 },
9128 flags: []string{
9129 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9130 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9131 },
9132 shouldFail: true,
9133 expectedError: ":DECODE_ERROR:",
9134 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009135
9136 testCases = append(testCases, testCase{
9137 testType: serverTest,
9138 name: "TLS13-TrailingKeyShareData",
9139 config: Config{
9140 MaxVersion: VersionTLS13,
9141 Bugs: ProtocolBugs{
9142 TrailingKeyShareData: true,
9143 },
9144 },
9145 shouldFail: true,
9146 expectedError: ":DECODE_ERROR:",
9147 })
David Benjamin7f78df42016-10-05 22:33:19 -04009148
9149 testCases = append(testCases, testCase{
9150 name: "TLS13-AlwaysSelectPSKIdentity",
9151 config: Config{
9152 MaxVersion: VersionTLS13,
9153 Bugs: ProtocolBugs{
9154 AlwaysSelectPSKIdentity: true,
9155 },
9156 },
9157 shouldFail: true,
9158 expectedError: ":UNEXPECTED_EXTENSION:",
9159 })
9160
9161 testCases = append(testCases, testCase{
9162 name: "TLS13-InvalidPSKIdentity",
9163 config: Config{
9164 MaxVersion: VersionTLS13,
9165 Bugs: ProtocolBugs{
9166 SelectPSKIdentityOnResume: 1,
9167 },
9168 },
9169 resumeSession: true,
9170 shouldFail: true,
9171 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9172 })
David Benjamin1286bee2016-10-07 15:25:06 -04009173
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009174 testCases = append(testCases, testCase{
9175 testType: serverTest,
9176 name: "TLS13-ExtraPSKIdentity",
9177 config: Config{
9178 MaxVersion: VersionTLS13,
9179 Bugs: ProtocolBugs{
9180 ExtraPSKIdentity: true,
9181 },
9182 },
9183 resumeSession: true,
9184 })
9185
David Benjamin1286bee2016-10-07 15:25:06 -04009186 // Test that unknown NewSessionTicket extensions are tolerated.
9187 testCases = append(testCases, testCase{
9188 name: "TLS13-CustomTicketExtension",
9189 config: Config{
9190 MaxVersion: VersionTLS13,
9191 Bugs: ProtocolBugs{
9192 CustomTicketExtension: "1234",
9193 },
9194 },
9195 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009196}
9197
David Benjaminabbbee12016-10-31 19:20:42 -04009198func addTLS13CipherPreferenceTests() {
9199 // Test that client preference is honored if the shim has AES hardware
9200 // and ChaCha20-Poly1305 is preferred otherwise.
9201 testCases = append(testCases, testCase{
9202 testType: serverTest,
9203 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9204 config: Config{
9205 MaxVersion: VersionTLS13,
9206 CipherSuites: []uint16{
9207 TLS_CHACHA20_POLY1305_SHA256,
9208 TLS_AES_128_GCM_SHA256,
9209 },
9210 },
9211 flags: []string{
9212 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9213 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9214 },
9215 })
9216
9217 testCases = append(testCases, testCase{
9218 testType: serverTest,
9219 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9220 config: Config{
9221 MaxVersion: VersionTLS13,
9222 CipherSuites: []uint16{
9223 TLS_AES_128_GCM_SHA256,
9224 TLS_CHACHA20_POLY1305_SHA256,
9225 },
9226 },
9227 flags: []string{
9228 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9229 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9230 },
9231 })
9232
9233 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9234 // whether it has AES hardware.
9235 testCases = append(testCases, testCase{
9236 name: "TLS13-CipherPreference-Client",
9237 config: Config{
9238 MaxVersion: VersionTLS13,
9239 // Use the client cipher order. (This is the default but
9240 // is listed to be explicit.)
9241 PreferServerCipherSuites: false,
9242 },
9243 flags: []string{
9244 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9245 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9246 },
9247 })
9248}
9249
David Benjaminf3fbade2016-09-19 13:08:16 -04009250func addPeekTests() {
9251 // Test SSL_peek works, including on empty records.
9252 testCases = append(testCases, testCase{
9253 name: "Peek-Basic",
9254 sendEmptyRecords: 1,
9255 flags: []string{"-peek-then-read"},
9256 })
9257
9258 // Test SSL_peek can drive the initial handshake.
9259 testCases = append(testCases, testCase{
9260 name: "Peek-ImplicitHandshake",
9261 flags: []string{
9262 "-peek-then-read",
9263 "-implicit-handshake",
9264 },
9265 })
9266
9267 // Test SSL_peek can discover and drive a renegotiation.
9268 testCases = append(testCases, testCase{
9269 name: "Peek-Renegotiate",
9270 config: Config{
9271 MaxVersion: VersionTLS12,
9272 },
9273 renegotiate: 1,
9274 flags: []string{
9275 "-peek-then-read",
9276 "-renegotiate-freely",
9277 "-expect-total-renegotiations", "1",
9278 },
9279 })
9280
9281 // Test SSL_peek can discover a close_notify.
9282 testCases = append(testCases, testCase{
9283 name: "Peek-Shutdown",
9284 config: Config{
9285 Bugs: ProtocolBugs{
9286 ExpectCloseNotify: true,
9287 },
9288 },
9289 flags: []string{
9290 "-peek-then-read",
9291 "-check-close-notify",
9292 },
9293 })
9294
9295 // Test SSL_peek can discover an alert.
9296 testCases = append(testCases, testCase{
9297 name: "Peek-Alert",
9298 config: Config{
9299 Bugs: ProtocolBugs{
9300 SendSpuriousAlert: alertRecordOverflow,
9301 },
9302 },
9303 flags: []string{"-peek-then-read"},
9304 shouldFail: true,
9305 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9306 })
9307
9308 // Test SSL_peek can handle KeyUpdate.
9309 testCases = append(testCases, testCase{
9310 name: "Peek-KeyUpdate",
9311 config: Config{
9312 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009313 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009314 sendKeyUpdates: 1,
9315 keyUpdateRequest: keyUpdateNotRequested,
9316 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009317 })
9318}
9319
David Benjamine6f22212016-11-08 14:28:24 -05009320func addRecordVersionTests() {
9321 for _, ver := range tlsVersions {
9322 // Test that the record version is enforced.
9323 testCases = append(testCases, testCase{
9324 name: "CheckRecordVersion-" + ver.name,
9325 config: Config{
9326 MinVersion: ver.version,
9327 MaxVersion: ver.version,
9328 Bugs: ProtocolBugs{
9329 SendRecordVersion: 0x03ff,
9330 },
9331 },
9332 shouldFail: true,
9333 expectedError: ":WRONG_VERSION_NUMBER:",
9334 })
9335
9336 // Test that the ClientHello may use any record version, for
9337 // compatibility reasons.
9338 testCases = append(testCases, testCase{
9339 testType: serverTest,
9340 name: "LooseInitialRecordVersion-" + ver.name,
9341 config: Config{
9342 MinVersion: ver.version,
9343 MaxVersion: ver.version,
9344 Bugs: ProtocolBugs{
9345 SendInitialRecordVersion: 0x03ff,
9346 },
9347 },
9348 })
9349
9350 // Test that garbage ClientHello record versions are rejected.
9351 testCases = append(testCases, testCase{
9352 testType: serverTest,
9353 name: "GarbageInitialRecordVersion-" + ver.name,
9354 config: Config{
9355 MinVersion: ver.version,
9356 MaxVersion: ver.version,
9357 Bugs: ProtocolBugs{
9358 SendInitialRecordVersion: 0xffff,
9359 },
9360 },
9361 shouldFail: true,
9362 expectedError: ":WRONG_VERSION_NUMBER:",
9363 })
9364 }
9365}
9366
David Benjamin2c516452016-11-15 10:16:54 +09009367func addCertificateTests() {
9368 // Test that a certificate chain with intermediate may be sent and
9369 // received as both client and server.
9370 for _, ver := range tlsVersions {
9371 testCases = append(testCases, testCase{
9372 testType: clientTest,
9373 name: "SendReceiveIntermediate-Client-" + ver.name,
9374 config: Config{
9375 Certificates: []Certificate{rsaChainCertificate},
9376 ClientAuth: RequireAnyClientCert,
9377 },
9378 expectPeerCertificate: &rsaChainCertificate,
9379 flags: []string{
9380 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9381 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9382 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9383 },
9384 })
9385
9386 testCases = append(testCases, testCase{
9387 testType: serverTest,
9388 name: "SendReceiveIntermediate-Server-" + ver.name,
9389 config: Config{
9390 Certificates: []Certificate{rsaChainCertificate},
9391 },
9392 expectPeerCertificate: &rsaChainCertificate,
9393 flags: []string{
9394 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9395 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9396 "-require-any-client-certificate",
9397 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9398 },
9399 })
9400 }
9401}
9402
Adam Langley7c803a62015-06-15 15:35:05 -07009403func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009404 defer wg.Done()
9405
9406 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009407 var err error
9408
9409 if *mallocTest < 0 {
9410 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009411 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009412 } else {
9413 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9414 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009415 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009416 if err != nil {
9417 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9418 }
9419 break
9420 }
9421 }
9422 }
Adam Langley95c29f32014-06-20 12:00:00 -07009423 statusChan <- statusMsg{test: test, err: err}
9424 }
9425}
9426
9427type statusMsg struct {
9428 test *testCase
9429 started bool
9430 err error
9431}
9432
David Benjamin5f237bc2015-02-11 17:14:15 -05009433func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009434 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009435
David Benjamin5f237bc2015-02-11 17:14:15 -05009436 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009437 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009438 if !*pipe {
9439 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009440 var erase string
9441 for i := 0; i < lineLen; i++ {
9442 erase += "\b \b"
9443 }
9444 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009445 }
9446
Adam Langley95c29f32014-06-20 12:00:00 -07009447 if msg.started {
9448 started++
9449 } else {
9450 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009451
9452 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009453 if msg.err == errUnimplemented {
9454 if *pipe {
9455 // Print each test instead of a status line.
9456 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9457 }
9458 unimplemented++
9459 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9460 } else {
9461 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9462 failed++
9463 testOutput.addResult(msg.test.name, "FAIL")
9464 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009465 } else {
9466 if *pipe {
9467 // Print each test instead of a status line.
9468 fmt.Printf("PASSED (%s)\n", msg.test.name)
9469 }
9470 testOutput.addResult(msg.test.name, "PASS")
9471 }
Adam Langley95c29f32014-06-20 12:00:00 -07009472 }
9473
David Benjamin5f237bc2015-02-11 17:14:15 -05009474 if !*pipe {
9475 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009476 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009477 lineLen = len(line)
9478 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009479 }
Adam Langley95c29f32014-06-20 12:00:00 -07009480 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009481
9482 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009483}
9484
9485func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009486 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009487 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009488 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009489
Adam Langley7c803a62015-06-15 15:35:05 -07009490 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009491 addCipherSuiteTests()
9492 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009493 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009494 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009495 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009496 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009497 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009498 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009499 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009500 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009501 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009502 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009503 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009504 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009505 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009506 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009507 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009508 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009509 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009510 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009511 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009512 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009513 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009514 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009515 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009516 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009517 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009518 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009519 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009520 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009521 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009522 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009523 addCertificateTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009524
9525 var wg sync.WaitGroup
9526
Adam Langley7c803a62015-06-15 15:35:05 -07009527 statusChan := make(chan statusMsg, *numWorkers)
9528 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009529 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009530
EKRf71d7ed2016-08-06 13:25:12 -07009531 if len(*shimConfigFile) != 0 {
9532 encoded, err := ioutil.ReadFile(*shimConfigFile)
9533 if err != nil {
9534 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9535 os.Exit(1)
9536 }
9537
9538 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9539 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9540 os.Exit(1)
9541 }
9542 }
9543
David Benjamin025b3d32014-07-01 19:53:04 -04009544 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009545
Adam Langley7c803a62015-06-15 15:35:05 -07009546 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009547 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009548 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009549 }
9550
David Benjamin270f0a72016-03-17 14:41:36 -04009551 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009552 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009553 matched := true
9554 if len(*testToRun) != 0 {
9555 var err error
9556 matched, err = filepath.Match(*testToRun, testCases[i].name)
9557 if err != nil {
9558 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9559 os.Exit(1)
9560 }
9561 }
9562
EKRf71d7ed2016-08-06 13:25:12 -07009563 if !*includeDisabled {
9564 for pattern := range shimConfig.DisabledTests {
9565 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9566 if err != nil {
9567 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9568 os.Exit(1)
9569 }
9570
9571 if isDisabled {
9572 matched = false
9573 break
9574 }
9575 }
9576 }
9577
David Benjamin17e12922016-07-28 18:04:43 -04009578 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009579 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009580 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07009581 }
9582 }
David Benjamin17e12922016-07-28 18:04:43 -04009583
David Benjamin270f0a72016-03-17 14:41:36 -04009584 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009585 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009586 os.Exit(1)
9587 }
Adam Langley95c29f32014-06-20 12:00:00 -07009588
9589 close(testChan)
9590 wg.Wait()
9591 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009592 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009593
9594 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009595
9596 if *jsonOutput != "" {
9597 if err := testOutput.writeTo(*jsonOutput); err != nil {
9598 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9599 }
9600 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009601
EKR842ae6c2016-07-27 09:22:05 +02009602 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9603 os.Exit(1)
9604 }
9605
9606 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009607 os.Exit(1)
9608 }
Adam Langley95c29f32014-06-20 12:00:00 -07009609}