blob: 918618dfc91d118153123cb29b6c5fec729ea7ab [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 })
David Benjamin53210cb2016-11-16 09:01:48 +09005200
5201 // Test that certificate-related extensions are not sent unsolicited.
5202 testCases = append(testCases, testCase{
5203 testType: serverTest,
5204 name: "UnsolicitedCertificateExtensions-" + ver.name,
5205 config: Config{
5206 MaxVersion: ver.version,
5207 Bugs: ProtocolBugs{
5208 NoOCSPStapling: true,
5209 NoSignedCertificateTimestamps: true,
5210 },
5211 },
5212 flags: []string{
5213 "-ocsp-response",
5214 base64.StdEncoding.EncodeToString(testOCSPResponse),
5215 "-signed-cert-timestamps",
5216 base64.StdEncoding.EncodeToString(testSCTList),
5217 },
5218 })
David Benjamin97d17d92016-07-14 16:12:00 -04005219 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005220
Paul Lietar4fac72e2015-09-09 13:44:55 +01005221 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005222 testType: clientTest,
5223 name: "ClientHelloPadding",
5224 config: Config{
5225 Bugs: ProtocolBugs{
5226 RequireClientHelloSize: 512,
5227 },
5228 },
5229 // This hostname just needs to be long enough to push the
5230 // ClientHello into F5's danger zone between 256 and 511 bytes
5231 // long.
5232 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5233 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005234
5235 // Extensions should not function in SSL 3.0.
5236 testCases = append(testCases, testCase{
5237 testType: serverTest,
5238 name: "SSLv3Extensions-NoALPN",
5239 config: Config{
5240 MaxVersion: VersionSSL30,
5241 NextProtos: []string{"foo", "bar", "baz"},
5242 },
5243 flags: []string{
5244 "-select-alpn", "foo",
5245 },
5246 expectNoNextProto: true,
5247 })
5248
5249 // Test session tickets separately as they follow a different codepath.
5250 testCases = append(testCases, testCase{
5251 testType: serverTest,
5252 name: "SSLv3Extensions-NoTickets",
5253 config: Config{
5254 MaxVersion: VersionSSL30,
5255 Bugs: ProtocolBugs{
5256 // Historically, session tickets in SSL 3.0
5257 // failed in different ways depending on whether
5258 // the client supported renegotiation_info.
5259 NoRenegotiationInfo: true,
5260 },
5261 },
5262 resumeSession: true,
5263 })
5264 testCases = append(testCases, testCase{
5265 testType: serverTest,
5266 name: "SSLv3Extensions-NoTickets2",
5267 config: Config{
5268 MaxVersion: VersionSSL30,
5269 },
5270 resumeSession: true,
5271 })
5272
5273 // But SSL 3.0 does send and process renegotiation_info.
5274 testCases = append(testCases, testCase{
5275 testType: serverTest,
5276 name: "SSLv3Extensions-RenegotiationInfo",
5277 config: Config{
5278 MaxVersion: VersionSSL30,
5279 Bugs: ProtocolBugs{
5280 RequireRenegotiationInfo: true,
5281 },
5282 },
5283 })
5284 testCases = append(testCases, testCase{
5285 testType: serverTest,
5286 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5287 config: Config{
5288 MaxVersion: VersionSSL30,
5289 Bugs: ProtocolBugs{
5290 NoRenegotiationInfo: true,
5291 SendRenegotiationSCSV: true,
5292 RequireRenegotiationInfo: true,
5293 },
5294 },
5295 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005296
5297 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5298 // in ServerHello.
5299 testCases = append(testCases, testCase{
5300 name: "NPN-Forbidden-TLS13",
5301 config: Config{
5302 MaxVersion: VersionTLS13,
5303 NextProtos: []string{"foo"},
5304 Bugs: ProtocolBugs{
5305 NegotiateNPNAtAllVersions: true,
5306 },
5307 },
5308 flags: []string{"-select-next-proto", "foo"},
5309 shouldFail: true,
5310 expectedError: ":ERROR_PARSING_EXTENSION:",
5311 })
5312 testCases = append(testCases, testCase{
5313 name: "EMS-Forbidden-TLS13",
5314 config: Config{
5315 MaxVersion: VersionTLS13,
5316 Bugs: ProtocolBugs{
5317 NegotiateEMSAtAllVersions: true,
5318 },
5319 },
5320 shouldFail: true,
5321 expectedError: ":ERROR_PARSING_EXTENSION:",
5322 })
5323 testCases = append(testCases, testCase{
5324 name: "RenegotiationInfo-Forbidden-TLS13",
5325 config: Config{
5326 MaxVersion: VersionTLS13,
5327 Bugs: ProtocolBugs{
5328 NegotiateRenegotiationInfoAtAllVersions: true,
5329 },
5330 },
5331 shouldFail: true,
5332 expectedError: ":ERROR_PARSING_EXTENSION:",
5333 })
5334 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04005335 name: "Ticket-Forbidden-TLS13",
5336 config: Config{
5337 MaxVersion: VersionTLS12,
5338 },
5339 resumeConfig: &Config{
5340 MaxVersion: VersionTLS13,
5341 Bugs: ProtocolBugs{
5342 AdvertiseTicketExtension: true,
5343 },
5344 },
5345 resumeSession: true,
5346 shouldFail: true,
5347 expectedError: ":ERROR_PARSING_EXTENSION:",
5348 })
5349
5350 // Test that illegal extensions in TLS 1.3 are declined by the server if
5351 // offered in ClientHello. The runner's server will fail if this occurs,
5352 // so we exercise the offering path. (EMS and Renegotiation Info are
5353 // implicit in every test.)
5354 testCases = append(testCases, testCase{
5355 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005356 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005357 config: Config{
5358 MaxVersion: VersionTLS13,
5359 NextProtos: []string{"bar"},
5360 },
5361 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5362 })
David Benjamin196df5b2016-09-21 16:23:27 -04005363
David Benjamindaa88502016-10-04 16:32:16 -04005364 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5365 // tolerated.
5366 testCases = append(testCases, testCase{
5367 name: "SendOCSPResponseOnResume-TLS12",
5368 config: Config{
5369 MaxVersion: VersionTLS12,
5370 Bugs: ProtocolBugs{
5371 SendOCSPResponseOnResume: []byte("bogus"),
5372 },
5373 },
5374 flags: []string{
5375 "-enable-ocsp-stapling",
5376 "-expect-ocsp-response",
5377 base64.StdEncoding.EncodeToString(testOCSPResponse),
5378 },
5379 resumeSession: true,
5380 })
5381
David Benjamindaa88502016-10-04 16:32:16 -04005382 testCases = append(testCases, testCase{
Steven Valdeza833c352016-11-01 13:39:36 -04005383 name: "SendUnsolicitedOCSPOnCertificate-TLS13",
David Benjamindaa88502016-10-04 16:32:16 -04005384 config: Config{
5385 MaxVersion: VersionTLS13,
5386 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04005387 SendExtensionOnCertificate: testOCSPExtension,
5388 },
5389 },
5390 shouldFail: true,
5391 expectedError: ":UNEXPECTED_EXTENSION:",
5392 })
5393
5394 testCases = append(testCases, testCase{
5395 name: "SendUnsolicitedSCTOnCertificate-TLS13",
5396 config: Config{
5397 MaxVersion: VersionTLS13,
5398 Bugs: ProtocolBugs{
5399 SendExtensionOnCertificate: testSCTExtension,
5400 },
5401 },
5402 shouldFail: true,
5403 expectedError: ":UNEXPECTED_EXTENSION:",
5404 })
5405
5406 // Test that extensions on client certificates are never accepted.
5407 testCases = append(testCases, testCase{
5408 name: "SendExtensionOnClientCertificate-TLS13",
5409 testType: serverTest,
5410 config: Config{
5411 MaxVersion: VersionTLS13,
5412 Certificates: []Certificate{rsaCertificate},
5413 Bugs: ProtocolBugs{
5414 SendExtensionOnCertificate: testOCSPExtension,
5415 },
5416 },
5417 flags: []string{
5418 "-enable-ocsp-stapling",
5419 "-require-any-client-certificate",
5420 },
5421 shouldFail: true,
5422 expectedError: ":UNEXPECTED_EXTENSION:",
5423 })
5424
5425 testCases = append(testCases, testCase{
5426 name: "SendUnknownExtensionOnCertificate-TLS13",
5427 config: Config{
5428 MaxVersion: VersionTLS13,
5429 Bugs: ProtocolBugs{
5430 SendExtensionOnCertificate: []byte{0x00, 0x7f, 0, 0},
5431 },
5432 },
5433 shouldFail: true,
5434 expectedError: ":UNEXPECTED_EXTENSION:",
5435 })
5436
5437 // Test that extensions on intermediates are allowed but ignored.
5438 testCases = append(testCases, testCase{
5439 name: "IgnoreExtensionsOnIntermediates-TLS13",
5440 config: Config{
5441 MaxVersion: VersionTLS13,
5442 Certificates: []Certificate{rsaChainCertificate},
5443 Bugs: ProtocolBugs{
5444 // Send different values on the intermediate. This tests
5445 // the intermediate's extensions do not override the
5446 // leaf's.
5447 SendOCSPOnIntermediates: []byte{1, 3, 3, 7},
5448 SendSCTOnIntermediates: []byte{1, 3, 3, 7},
David Benjamindaa88502016-10-04 16:32:16 -04005449 },
5450 },
5451 flags: []string{
5452 "-enable-ocsp-stapling",
5453 "-expect-ocsp-response",
5454 base64.StdEncoding.EncodeToString(testOCSPResponse),
Steven Valdeza833c352016-11-01 13:39:36 -04005455 "-enable-signed-cert-timestamps",
5456 "-expect-signed-cert-timestamps",
5457 base64.StdEncoding.EncodeToString(testSCTList),
5458 },
5459 resumeSession: true,
5460 })
5461
5462 // Test that extensions are not sent on intermediates when configured
5463 // only for a leaf.
5464 testCases = append(testCases, testCase{
5465 testType: serverTest,
5466 name: "SendNoExtensionsOnIntermediate-TLS13",
5467 config: Config{
5468 MaxVersion: VersionTLS13,
5469 Bugs: ProtocolBugs{
5470 ExpectNoExtensionsOnIntermediate: true,
5471 },
5472 },
5473 flags: []string{
5474 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
5475 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
5476 "-ocsp-response",
5477 base64.StdEncoding.EncodeToString(testOCSPResponse),
5478 "-signed-cert-timestamps",
5479 base64.StdEncoding.EncodeToString(testSCTList),
5480 },
5481 })
5482
5483 // Test that extensions are not sent on client certificates.
5484 testCases = append(testCases, testCase{
5485 name: "SendNoClientCertificateExtensions-TLS13",
5486 config: Config{
5487 MaxVersion: VersionTLS13,
5488 ClientAuth: RequireAnyClientCert,
5489 },
5490 flags: []string{
5491 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
5492 "-key-file", path.Join(*resourceDir, rsaKeyFile),
5493 "-ocsp-response",
5494 base64.StdEncoding.EncodeToString(testOCSPResponse),
5495 "-signed-cert-timestamps",
5496 base64.StdEncoding.EncodeToString(testSCTList),
5497 },
5498 })
5499
5500 testCases = append(testCases, testCase{
5501 name: "SendDuplicateExtensionsOnCerts-TLS13",
5502 config: Config{
5503 MaxVersion: VersionTLS13,
5504 Bugs: ProtocolBugs{
5505 SendDuplicateCertExtensions: true,
5506 },
5507 },
5508 flags: []string{
5509 "-enable-ocsp-stapling",
5510 "-enable-signed-cert-timestamps",
David Benjamindaa88502016-10-04 16:32:16 -04005511 },
5512 resumeSession: true,
5513 shouldFail: true,
Steven Valdeza833c352016-11-01 13:39:36 -04005514 expectedError: ":DUPLICATE_EXTENSION:",
David Benjamindaa88502016-10-04 16:32:16 -04005515 })
David Benjamine78bfde2014-09-06 12:45:15 -04005516}
5517
David Benjamin01fe8202014-09-24 15:21:44 -04005518func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005519 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005520 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005521 // SSL 3.0 does not have tickets and TLS 1.3 does not
5522 // have session IDs, so skip their cross-resumption
5523 // tests.
5524 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5525 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5526 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005527 }
5528
David Benjamin8b8c0062014-11-23 02:47:52 -05005529 protocols := []protocol{tls}
5530 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5531 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005532 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005533 for _, protocol := range protocols {
5534 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5535 if protocol == dtls {
5536 suffix += "-DTLS"
5537 }
5538
David Benjaminece3de92015-03-16 18:02:20 -04005539 if sessionVers.version == resumeVers.version {
5540 testCases = append(testCases, testCase{
5541 protocol: protocol,
5542 name: "Resume-Client" + suffix,
5543 resumeSession: true,
5544 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005545 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005546 Bugs: ProtocolBugs{
5547 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5548 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5549 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005550 },
David Benjaminece3de92015-03-16 18:02:20 -04005551 expectedVersion: sessionVers.version,
5552 expectedResumeVersion: resumeVers.version,
5553 })
5554 } else {
David Benjamin405da482016-08-08 17:25:07 -04005555 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5556
5557 // Offering a TLS 1.3 session sends an empty session ID, so
5558 // there is no way to convince a non-lookahead client the
5559 // session was resumed. It will appear to the client that a
5560 // stray ChangeCipherSpec was sent.
5561 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5562 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005563 }
5564
David Benjaminece3de92015-03-16 18:02:20 -04005565 testCases = append(testCases, testCase{
5566 protocol: protocol,
5567 name: "Resume-Client-Mismatch" + suffix,
5568 resumeSession: true,
5569 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005570 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005571 },
David Benjaminece3de92015-03-16 18:02:20 -04005572 expectedVersion: sessionVers.version,
5573 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005574 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005575 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005576 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005577 },
5578 },
5579 expectedResumeVersion: resumeVers.version,
5580 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005581 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005582 })
5583 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005584
5585 testCases = append(testCases, testCase{
5586 protocol: protocol,
5587 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005588 resumeSession: true,
5589 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005590 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005591 },
5592 expectedVersion: sessionVers.version,
5593 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005594 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005595 },
5596 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005597 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005598 expectedResumeVersion: resumeVers.version,
5599 })
5600
David Benjamin8b8c0062014-11-23 02:47:52 -05005601 testCases = append(testCases, testCase{
5602 protocol: protocol,
5603 testType: serverTest,
5604 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005605 resumeSession: true,
5606 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005607 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005608 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005609 expectedVersion: sessionVers.version,
5610 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005611 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005612 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005613 Bugs: ProtocolBugs{
5614 SendBothTickets: true,
5615 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005616 },
5617 expectedResumeVersion: resumeVers.version,
5618 })
5619 }
David Benjamin01fe8202014-09-24 15:21:44 -04005620 }
5621 }
David Benjaminece3de92015-03-16 18:02:20 -04005622
David Benjamin4199b0d2016-11-01 13:58:25 -04005623 // Make sure shim ticket mutations are functional.
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005624 testCases = append(testCases, testCase{
5625 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005626 name: "ShimTicketRewritable",
5627 resumeSession: true,
5628 config: Config{
5629 MaxVersion: VersionTLS12,
5630 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5631 Bugs: ProtocolBugs{
5632 FilterTicket: func(in []byte) ([]byte, error) {
5633 in, err := SetShimTicketVersion(in, VersionTLS12)
5634 if err != nil {
5635 return nil, err
5636 }
5637 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5638 },
5639 },
5640 },
5641 flags: []string{
5642 "-ticket-key",
5643 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5644 },
5645 })
5646
5647 // Resumptions are declined if the version does not match.
5648 testCases = append(testCases, testCase{
5649 testType: serverTest,
5650 name: "Resume-Server-DeclineCrossVersion",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005651 resumeSession: true,
5652 config: Config{
5653 MaxVersion: VersionTLS12,
David Benjamin4199b0d2016-11-01 13:58:25 -04005654 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005655 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005656 FilterTicket: func(in []byte) ([]byte, error) {
5657 return SetShimTicketVersion(in, VersionTLS13)
5658 },
5659 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005660 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005661 flags: []string{
5662 "-ticket-key",
5663 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5664 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005665 expectResumeRejected: true,
5666 })
5667
5668 testCases = append(testCases, testCase{
5669 testType: serverTest,
David Benjamin4199b0d2016-11-01 13:58:25 -04005670 name: "Resume-Server-DeclineCrossVersion-TLS13",
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005671 resumeSession: true,
5672 config: Config{
5673 MaxVersion: VersionTLS13,
David Benjamin4199b0d2016-11-01 13:58:25 -04005674 Bugs: ProtocolBugs{
5675 FilterTicket: func(in []byte) ([]byte, error) {
5676 return SetShimTicketVersion(in, VersionTLS12)
5677 },
5678 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005679 },
David Benjamin4199b0d2016-11-01 13:58:25 -04005680 flags: []string{
5681 "-ticket-key",
5682 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5683 },
Steven Valdezb6b6ff32016-10-26 11:56:35 -04005684 expectResumeRejected: true,
5685 })
5686
David Benjamin4199b0d2016-11-01 13:58:25 -04005687 // Resumptions are declined if the cipher is invalid or disabled.
5688 testCases = append(testCases, testCase{
5689 testType: serverTest,
5690 name: "Resume-Server-DeclineBadCipher",
5691 resumeSession: true,
5692 config: Config{
5693 MaxVersion: VersionTLS12,
5694 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005695 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005696 FilterTicket: func(in []byte) ([]byte, error) {
5697 return SetShimTicketCipherSuite(in, TLS_AES_128_GCM_SHA256)
5698 },
5699 },
5700 },
5701 flags: []string{
5702 "-ticket-key",
5703 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5704 },
5705 expectResumeRejected: true,
5706 })
5707
5708 testCases = append(testCases, testCase{
5709 testType: serverTest,
5710 name: "Resume-Server-DeclineBadCipher-2",
5711 resumeSession: true,
5712 config: Config{
5713 MaxVersion: VersionTLS12,
5714 Bugs: ProtocolBugs{
David Benjamin75f99142016-11-12 12:36:06 +09005715 ExpectNewTicket: true,
David Benjamin4199b0d2016-11-01 13:58:25 -04005716 FilterTicket: func(in []byte) ([]byte, error) {
5717 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384)
5718 },
5719 },
5720 },
5721 flags: []string{
5722 "-cipher", "AES128",
5723 "-ticket-key",
5724 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5725 },
5726 expectResumeRejected: true,
5727 })
5728
5729 testCases = append(testCases, testCase{
5730 testType: serverTest,
5731 name: "Resume-Server-DeclineBadCipher-TLS13",
5732 resumeSession: true,
5733 config: Config{
5734 MaxVersion: VersionTLS13,
5735 Bugs: ProtocolBugs{
5736 FilterTicket: func(in []byte) ([]byte, error) {
5737 return SetShimTicketCipherSuite(in, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256)
5738 },
5739 },
5740 },
5741 flags: []string{
5742 "-ticket-key",
5743 base64.StdEncoding.EncodeToString(TestShimTicketKey),
5744 },
5745 expectResumeRejected: true,
5746 })
5747
David Benjamin75f99142016-11-12 12:36:06 +09005748 // Clients must not advertise a session without also advertising the
5749 // cipher.
5750 testCases = append(testCases, testCase{
5751 testType: serverTest,
5752 name: "Resume-Server-UnofferedCipher",
5753 resumeSession: true,
5754 config: Config{
5755 MaxVersion: VersionTLS12,
5756 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5757 },
5758 resumeConfig: &Config{
5759 MaxVersion: VersionTLS12,
5760 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
5761 Bugs: ProtocolBugs{
5762 SendCipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5763 },
5764 },
5765 shouldFail: true,
5766 expectedError: ":REQUIRED_CIPHER_MISSING:",
5767 })
5768
5769 testCases = append(testCases, testCase{
5770 testType: serverTest,
5771 name: "Resume-Server-UnofferedCipher-TLS13",
5772 resumeSession: true,
5773 config: Config{
5774 MaxVersion: VersionTLS13,
5775 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5776 },
5777 resumeConfig: &Config{
5778 MaxVersion: VersionTLS13,
5779 CipherSuites: []uint16{TLS_CHACHA20_POLY1305_SHA256},
5780 Bugs: ProtocolBugs{
5781 SendCipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
5782 },
5783 },
5784 shouldFail: true,
5785 expectedError: ":REQUIRED_CIPHER_MISSING:",
5786 })
5787
David Benjamin4199b0d2016-11-01 13:58:25 -04005788 // Sessions may not be resumed at a different cipher.
David Benjaminece3de92015-03-16 18:02:20 -04005789 testCases = append(testCases, testCase{
5790 name: "Resume-Client-CipherMismatch",
5791 resumeSession: true,
5792 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005793 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005794 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5795 },
5796 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005797 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005798 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5799 Bugs: ProtocolBugs{
5800 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5801 },
5802 },
5803 shouldFail: true,
5804 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5805 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005806
5807 testCases = append(testCases, testCase{
5808 name: "Resume-Client-CipherMismatch-TLS13",
5809 resumeSession: true,
5810 config: Config{
5811 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005812 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005813 },
5814 resumeConfig: &Config{
5815 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005816 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005817 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005818 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005819 },
5820 },
5821 shouldFail: true,
5822 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5823 })
Steven Valdeza833c352016-11-01 13:39:36 -04005824
5825 testCases = append(testCases, testCase{
5826 testType: serverTest,
5827 name: "Resume-Server-BinderWrongLength",
5828 resumeSession: true,
5829 config: Config{
5830 MaxVersion: VersionTLS13,
5831 Bugs: ProtocolBugs{
5832 SendShortPSKBinder: true,
5833 },
5834 },
5835 shouldFail: true,
5836 expectedLocalError: "remote error: error decrypting message",
5837 expectedError: ":DIGEST_CHECK_FAILED:",
5838 })
5839
5840 testCases = append(testCases, testCase{
5841 testType: serverTest,
5842 name: "Resume-Server-NoPSKBinder",
5843 resumeSession: true,
5844 config: Config{
5845 MaxVersion: VersionTLS13,
5846 Bugs: ProtocolBugs{
5847 SendNoPSKBinder: true,
5848 },
5849 },
5850 shouldFail: true,
5851 expectedLocalError: "remote error: error decoding message",
5852 expectedError: ":DECODE_ERROR:",
5853 })
5854
5855 testCases = append(testCases, testCase{
5856 testType: serverTest,
5857 name: "Resume-Server-InvalidPSKBinder",
5858 resumeSession: true,
5859 config: Config{
5860 MaxVersion: VersionTLS13,
5861 Bugs: ProtocolBugs{
5862 SendInvalidPSKBinder: true,
5863 },
5864 },
5865 shouldFail: true,
5866 expectedLocalError: "remote error: error decrypting message",
5867 expectedError: ":DIGEST_CHECK_FAILED:",
5868 })
5869
5870 testCases = append(testCases, testCase{
5871 testType: serverTest,
5872 name: "Resume-Server-PSKBinderFirstExtension",
5873 resumeSession: true,
5874 config: Config{
5875 MaxVersion: VersionTLS13,
5876 Bugs: ProtocolBugs{
5877 PSKBinderFirst: true,
5878 },
5879 },
5880 shouldFail: true,
5881 expectedLocalError: "remote error: illegal parameter",
5882 expectedError: ":PRE_SHARED_KEY_MUST_BE_LAST:",
5883 })
David Benjamin01fe8202014-09-24 15:21:44 -04005884}
5885
Adam Langley2ae77d22014-10-28 17:29:33 -07005886func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005887 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005888 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005889 testType: serverTest,
5890 name: "Renegotiate-Server-Forbidden",
5891 config: Config{
5892 MaxVersion: VersionTLS12,
5893 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005894 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005895 shouldFail: true,
5896 expectedError: ":NO_RENEGOTIATION:",
5897 expectedLocalError: "remote error: no renegotiation",
5898 })
Adam Langley5021b222015-06-12 18:27:58 -07005899 // The server shouldn't echo the renegotiation extension unless
5900 // requested by the client.
5901 testCases = append(testCases, testCase{
5902 testType: serverTest,
5903 name: "Renegotiate-Server-NoExt",
5904 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005905 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005906 Bugs: ProtocolBugs{
5907 NoRenegotiationInfo: true,
5908 RequireRenegotiationInfo: true,
5909 },
5910 },
5911 shouldFail: true,
5912 expectedLocalError: "renegotiation extension missing",
5913 })
5914 // The renegotiation SCSV should be sufficient for the server to echo
5915 // the extension.
5916 testCases = append(testCases, testCase{
5917 testType: serverTest,
5918 name: "Renegotiate-Server-NoExt-SCSV",
5919 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005920 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005921 Bugs: ProtocolBugs{
5922 NoRenegotiationInfo: true,
5923 SendRenegotiationSCSV: true,
5924 RequireRenegotiationInfo: true,
5925 },
5926 },
5927 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005928 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005929 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005930 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005931 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005932 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005933 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005934 },
5935 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005936 renegotiate: 1,
5937 flags: []string{
5938 "-renegotiate-freely",
5939 "-expect-total-renegotiations", "1",
5940 },
David Benjamincdea40c2015-03-19 14:09:43 -04005941 })
5942 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005943 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005944 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005945 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005946 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005947 Bugs: ProtocolBugs{
5948 EmptyRenegotiationInfo: true,
5949 },
5950 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005951 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005952 shouldFail: true,
5953 expectedError: ":RENEGOTIATION_MISMATCH:",
5954 })
5955 testCases = append(testCases, testCase{
5956 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005957 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005958 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005959 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005960 Bugs: ProtocolBugs{
5961 BadRenegotiationInfo: true,
5962 },
5963 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005964 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005965 shouldFail: true,
5966 expectedError: ":RENEGOTIATION_MISMATCH:",
5967 })
5968 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005969 name: "Renegotiate-Client-Downgrade",
5970 renegotiate: 1,
5971 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005972 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005973 Bugs: ProtocolBugs{
5974 NoRenegotiationInfoAfterInitial: true,
5975 },
5976 },
5977 flags: []string{"-renegotiate-freely"},
5978 shouldFail: true,
5979 expectedError: ":RENEGOTIATION_MISMATCH:",
5980 })
5981 testCases = append(testCases, testCase{
5982 name: "Renegotiate-Client-Upgrade",
5983 renegotiate: 1,
5984 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005985 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005986 Bugs: ProtocolBugs{
5987 NoRenegotiationInfoInInitial: true,
5988 },
5989 },
5990 flags: []string{"-renegotiate-freely"},
5991 shouldFail: true,
5992 expectedError: ":RENEGOTIATION_MISMATCH:",
5993 })
5994 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005995 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005996 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005997 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005998 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005999 Bugs: ProtocolBugs{
6000 NoRenegotiationInfo: true,
6001 },
6002 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006003 flags: []string{
6004 "-renegotiate-freely",
6005 "-expect-total-renegotiations", "1",
6006 },
David Benjamincff0b902015-05-15 23:09:47 -04006007 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006008
6009 // Test that the server may switch ciphers on renegotiation without
6010 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04006011 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07006012 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006013 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006014 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006015 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07006016 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07006017 },
6018 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006019 flags: []string{
6020 "-renegotiate-freely",
6021 "-expect-total-renegotiations", "1",
6022 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07006023 })
6024 testCases = append(testCases, testCase{
6025 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006026 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006027 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006028 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07006029 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6030 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07006031 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006032 flags: []string{
6033 "-renegotiate-freely",
6034 "-expect-total-renegotiations", "1",
6035 },
David Benjaminb16346b2015-04-08 19:16:58 -04006036 })
David Benjamine7e36aa2016-08-08 12:39:41 -04006037
6038 // Test that the server may not switch versions on renegotiation.
6039 testCases = append(testCases, testCase{
6040 name: "Renegotiate-Client-SwitchVersion",
6041 config: Config{
6042 MaxVersion: VersionTLS12,
6043 // Pick a cipher which exists at both versions.
6044 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
6045 Bugs: ProtocolBugs{
6046 NegotiateVersionOnRenego: VersionTLS11,
David Benjamine6f22212016-11-08 14:28:24 -05006047 // Avoid failing early at the record layer.
6048 SendRecordVersion: VersionTLS12,
David Benjamine7e36aa2016-08-08 12:39:41 -04006049 },
6050 },
6051 renegotiate: 1,
6052 flags: []string{
6053 "-renegotiate-freely",
6054 "-expect-total-renegotiations", "1",
6055 },
6056 shouldFail: true,
6057 expectedError: ":WRONG_SSL_VERSION:",
6058 })
6059
David Benjaminb16346b2015-04-08 19:16:58 -04006060 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05006061 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006062 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05006063 config: Config{
6064 MaxVersion: VersionTLS10,
6065 Bugs: ProtocolBugs{
6066 RequireSameRenegoClientVersion: true,
6067 },
6068 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006069 flags: []string{
6070 "-renegotiate-freely",
6071 "-expect-total-renegotiations", "1",
6072 },
David Benjaminc44b1df2014-11-23 12:11:01 -05006073 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07006074 testCases = append(testCases, testCase{
6075 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006076 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006077 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07006078 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07006079 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
6080 NextProtos: []string{"foo"},
6081 },
6082 flags: []string{
6083 "-false-start",
6084 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006085 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04006086 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07006087 },
6088 shimWritesFirst: true,
6089 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006090
6091 // Client-side renegotiation controls.
6092 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006093 name: "Renegotiate-Client-Forbidden-1",
6094 config: Config{
6095 MaxVersion: VersionTLS12,
6096 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006097 renegotiate: 1,
6098 shouldFail: true,
6099 expectedError: ":NO_RENEGOTIATION:",
6100 expectedLocalError: "remote error: no renegotiation",
6101 })
6102 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006103 name: "Renegotiate-Client-Once-1",
6104 config: Config{
6105 MaxVersion: VersionTLS12,
6106 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006107 renegotiate: 1,
6108 flags: []string{
6109 "-renegotiate-once",
6110 "-expect-total-renegotiations", "1",
6111 },
6112 })
6113 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006114 name: "Renegotiate-Client-Freely-1",
6115 config: Config{
6116 MaxVersion: VersionTLS12,
6117 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006118 renegotiate: 1,
6119 flags: []string{
6120 "-renegotiate-freely",
6121 "-expect-total-renegotiations", "1",
6122 },
6123 })
6124 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006125 name: "Renegotiate-Client-Once-2",
6126 config: Config{
6127 MaxVersion: VersionTLS12,
6128 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006129 renegotiate: 2,
6130 flags: []string{"-renegotiate-once"},
6131 shouldFail: true,
6132 expectedError: ":NO_RENEGOTIATION:",
6133 expectedLocalError: "remote error: no renegotiation",
6134 })
6135 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006136 name: "Renegotiate-Client-Freely-2",
6137 config: Config{
6138 MaxVersion: VersionTLS12,
6139 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04006140 renegotiate: 2,
6141 flags: []string{
6142 "-renegotiate-freely",
6143 "-expect-total-renegotiations", "2",
6144 },
6145 })
Adam Langley27a0d082015-11-03 13:34:10 -08006146 testCases = append(testCases, testCase{
6147 name: "Renegotiate-Client-NoIgnore",
6148 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006149 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006150 Bugs: ProtocolBugs{
6151 SendHelloRequestBeforeEveryAppDataRecord: true,
6152 },
6153 },
6154 shouldFail: true,
6155 expectedError: ":NO_RENEGOTIATION:",
6156 })
6157 testCases = append(testCases, testCase{
6158 name: "Renegotiate-Client-Ignore",
6159 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006160 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08006161 Bugs: ProtocolBugs{
6162 SendHelloRequestBeforeEveryAppDataRecord: true,
6163 },
6164 },
6165 flags: []string{
6166 "-renegotiate-ignore",
6167 "-expect-total-renegotiations", "0",
6168 },
6169 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006170
David Benjamin34941c02016-10-08 11:45:31 -04006171 // Renegotiation is not allowed at SSL 3.0.
6172 testCases = append(testCases, testCase{
6173 name: "Renegotiate-Client-SSL3",
6174 config: Config{
6175 MaxVersion: VersionSSL30,
6176 },
6177 renegotiate: 1,
6178 flags: []string{
6179 "-renegotiate-freely",
6180 "-expect-total-renegotiations", "1",
6181 },
6182 shouldFail: true,
6183 expectedError: ":NO_RENEGOTIATION:",
6184 expectedLocalError: "remote error: no renegotiation",
6185 })
6186
David Benjamin397c8e62016-07-08 14:14:36 -07006187 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07006188 testCases = append(testCases, testCase{
6189 name: "StrayHelloRequest",
6190 config: Config{
6191 MaxVersion: VersionTLS12,
6192 Bugs: ProtocolBugs{
6193 SendHelloRequestBeforeEveryHandshakeMessage: true,
6194 },
6195 },
6196 })
6197 testCases = append(testCases, testCase{
6198 name: "StrayHelloRequest-Packed",
6199 config: Config{
6200 MaxVersion: VersionTLS12,
6201 Bugs: ProtocolBugs{
6202 PackHandshakeFlight: true,
6203 SendHelloRequestBeforeEveryHandshakeMessage: true,
6204 },
6205 },
6206 })
6207
David Benjamin12d2c482016-07-24 10:56:51 -04006208 // Test renegotiation works if HelloRequest and server Finished come in
6209 // the same record.
6210 testCases = append(testCases, testCase{
6211 name: "Renegotiate-Client-Packed",
6212 config: Config{
6213 MaxVersion: VersionTLS12,
6214 Bugs: ProtocolBugs{
6215 PackHandshakeFlight: true,
6216 PackHelloRequestWithFinished: true,
6217 },
6218 },
6219 renegotiate: 1,
6220 flags: []string{
6221 "-renegotiate-freely",
6222 "-expect-total-renegotiations", "1",
6223 },
6224 })
6225
David Benjamin397c8e62016-07-08 14:14:36 -07006226 // Renegotiation is forbidden in TLS 1.3.
6227 testCases = append(testCases, testCase{
6228 name: "Renegotiate-Client-TLS13",
6229 config: Config{
6230 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006231 Bugs: ProtocolBugs{
6232 SendHelloRequestBeforeEveryAppDataRecord: true,
6233 },
David Benjamin397c8e62016-07-08 14:14:36 -07006234 },
David Benjamin397c8e62016-07-08 14:14:36 -07006235 flags: []string{
6236 "-renegotiate-freely",
6237 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04006238 shouldFail: true,
6239 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07006240 })
6241
6242 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
6243 testCases = append(testCases, testCase{
6244 name: "StrayHelloRequest-TLS13",
6245 config: Config{
6246 MaxVersion: VersionTLS13,
6247 Bugs: ProtocolBugs{
6248 SendHelloRequestBeforeEveryHandshakeMessage: true,
6249 },
6250 },
6251 shouldFail: true,
6252 expectedError: ":UNEXPECTED_MESSAGE:",
6253 })
Adam Langley2ae77d22014-10-28 17:29:33 -07006254}
6255
David Benjamin5e961c12014-11-07 01:48:35 -05006256func addDTLSReplayTests() {
6257 // Test that sequence number replays are detected.
6258 testCases = append(testCases, testCase{
6259 protocol: dtls,
6260 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04006261 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006262 replayWrites: true,
6263 })
6264
David Benjamin8e6db492015-07-25 18:29:23 -04006265 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05006266 // than the retransmit window.
6267 testCases = append(testCases, testCase{
6268 protocol: dtls,
6269 name: "DTLS-Replay-LargeGaps",
6270 config: Config{
6271 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04006272 SequenceNumberMapping: func(in uint64) uint64 {
6273 return in * 127
6274 },
David Benjamin5e961c12014-11-07 01:48:35 -05006275 },
6276 },
David Benjamin8e6db492015-07-25 18:29:23 -04006277 messageCount: 200,
6278 replayWrites: true,
6279 })
6280
6281 // Test the incoming sequence number changing non-monotonically.
6282 testCases = append(testCases, testCase{
6283 protocol: dtls,
6284 name: "DTLS-Replay-NonMonotonic",
6285 config: Config{
6286 Bugs: ProtocolBugs{
6287 SequenceNumberMapping: func(in uint64) uint64 {
6288 return in ^ 31
6289 },
6290 },
6291 },
6292 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05006293 replayWrites: true,
6294 })
6295}
6296
Nick Harper60edffd2016-06-21 15:19:24 -07006297var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05006298 name string
Nick Harper60edffd2016-06-21 15:19:24 -07006299 id signatureAlgorithm
6300 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05006301}{
Nick Harper60edffd2016-06-21 15:19:24 -07006302 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
6303 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
6304 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
6305 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07006306 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07006307 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
6308 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
6309 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006310 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
6311 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
6312 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04006313 // Tests for key types prior to TLS 1.2.
6314 {"RSA", 0, testCertRSA},
6315 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05006316}
6317
Nick Harper60edffd2016-06-21 15:19:24 -07006318const fakeSigAlg1 signatureAlgorithm = 0x2a01
6319const fakeSigAlg2 signatureAlgorithm = 0xff01
6320
6321func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04006322 // Not all ciphers involve a signature. Advertise a list which gives all
6323 // versions a signing cipher.
6324 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04006325 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04006326 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
6327 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
6328 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
6329 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
6330 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
6331 }
6332
David Benjaminca3d5452016-07-14 12:51:01 -04006333 var allAlgorithms []signatureAlgorithm
6334 for _, alg := range testSignatureAlgorithms {
6335 if alg.id != 0 {
6336 allAlgorithms = append(allAlgorithms, alg.id)
6337 }
6338 }
6339
Nick Harper60edffd2016-06-21 15:19:24 -07006340 // Make sure each signature algorithm works. Include some fake values in
6341 // the list and ensure they're ignored.
6342 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07006343 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04006344 if (ver.version < VersionTLS12) != (alg.id == 0) {
6345 continue
6346 }
6347
6348 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
6349 // or remove it in C.
6350 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07006351 continue
6352 }
Nick Harper60edffd2016-06-21 15:19:24 -07006353
David Benjamin3ef76972016-10-17 17:59:54 -04006354 var shouldSignFail, shouldVerifyFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07006355 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006356 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
David Benjamin3ef76972016-10-17 17:59:54 -04006357 shouldSignFail = true
6358 shouldVerifyFail = true
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006359 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04006360 // RSA-PKCS1 does not exist in TLS 1.3.
6361 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
David Benjamin3ef76972016-10-17 17:59:54 -04006362 shouldSignFail = true
6363 shouldVerifyFail = true
6364 }
6365
6366 // BoringSSL will sign SHA-1 and SHA-512 with ECDSA but not accept them.
6367 if alg.id == signatureECDSAWithSHA1 || alg.id == signatureECDSAWithP521AndSHA512 {
6368 shouldVerifyFail = true
Steven Valdez54ed58e2016-08-18 14:03:49 -04006369 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006370
6371 var signError, verifyError string
David Benjamin3ef76972016-10-17 17:59:54 -04006372 if shouldSignFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006373 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
David Benjamin3ef76972016-10-17 17:59:54 -04006374 }
6375 if shouldVerifyFail {
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006376 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07006377 }
David Benjamin000800a2014-11-14 01:43:59 -05006378
David Benjamin1fb125c2016-07-08 18:52:12 -07006379 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05006380
David Benjamin7a41d372016-07-09 11:21:54 -07006381 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006382 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006383 config: Config{
6384 MaxVersion: ver.version,
6385 ClientAuth: RequireAnyClientCert,
6386 VerifySignatureAlgorithms: []signatureAlgorithm{
6387 fakeSigAlg1,
6388 alg.id,
6389 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07006390 },
David Benjamin7a41d372016-07-09 11:21:54 -07006391 },
6392 flags: []string{
6393 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6394 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6395 "-enable-all-curves",
6396 },
David Benjamin3ef76972016-10-17 17:59:54 -04006397 shouldFail: shouldSignFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006398 expectedError: signError,
6399 expectedPeerSignatureAlgorithm: alg.id,
6400 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006401
David Benjamin7a41d372016-07-09 11:21:54 -07006402 testCases = append(testCases, testCase{
6403 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006404 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07006405 config: Config{
6406 MaxVersion: ver.version,
6407 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6408 SignSignatureAlgorithms: []signatureAlgorithm{
6409 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006410 },
David Benjamin7a41d372016-07-09 11:21:54 -07006411 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006412 SkipECDSACurveCheck: shouldVerifyFail,
6413 IgnoreSignatureVersionChecks: shouldVerifyFail,
6414 // Some signature algorithms may not be advertised.
6415 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006416 },
David Benjamin7a41d372016-07-09 11:21:54 -07006417 },
6418 flags: []string{
6419 "-require-any-client-certificate",
6420 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6421 "-enable-all-curves",
6422 },
David Benjamin3ef76972016-10-17 17:59:54 -04006423 shouldFail: shouldVerifyFail,
David Benjamin7a41d372016-07-09 11:21:54 -07006424 expectedError: verifyError,
6425 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006426
6427 testCases = append(testCases, testCase{
6428 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006429 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006430 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04006431 MaxVersion: ver.version,
6432 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006433 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006434 fakeSigAlg1,
6435 alg.id,
6436 fakeSigAlg2,
6437 },
6438 },
6439 flags: []string{
6440 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6441 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6442 "-enable-all-curves",
6443 },
David Benjamin3ef76972016-10-17 17:59:54 -04006444 shouldFail: shouldSignFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006445 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006446 expectedPeerSignatureAlgorithm: alg.id,
6447 })
6448
6449 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006450 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07006451 config: Config{
6452 MaxVersion: ver.version,
6453 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04006454 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07006455 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006456 alg.id,
6457 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006458 Bugs: ProtocolBugs{
David Benjamin3ef76972016-10-17 17:59:54 -04006459 SkipECDSACurveCheck: shouldVerifyFail,
6460 IgnoreSignatureVersionChecks: shouldVerifyFail,
6461 // Some signature algorithms may not be advertised.
6462 IgnorePeerSignatureAlgorithmPreferences: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006463 },
David Benjamin1fb125c2016-07-08 18:52:12 -07006464 },
6465 flags: []string{
6466 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
6467 "-enable-all-curves",
6468 },
David Benjamin3ef76972016-10-17 17:59:54 -04006469 shouldFail: shouldVerifyFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04006470 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07006471 })
David Benjamin5208fd42016-07-13 21:43:25 -04006472
David Benjamin3ef76972016-10-17 17:59:54 -04006473 if !shouldVerifyFail {
David Benjamin5208fd42016-07-13 21:43:25 -04006474 testCases = append(testCases, testCase{
6475 testType: serverTest,
6476 name: "ClientAuth-InvalidSignature" + suffix,
6477 config: Config{
6478 MaxVersion: ver.version,
6479 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6480 SignSignatureAlgorithms: []signatureAlgorithm{
6481 alg.id,
6482 },
6483 Bugs: ProtocolBugs{
6484 InvalidSignature: true,
6485 },
6486 },
6487 flags: []string{
6488 "-require-any-client-certificate",
6489 "-enable-all-curves",
6490 },
6491 shouldFail: true,
6492 expectedError: ":BAD_SIGNATURE:",
6493 })
6494
6495 testCases = append(testCases, testCase{
6496 name: "ServerAuth-InvalidSignature" + suffix,
6497 config: Config{
6498 MaxVersion: ver.version,
6499 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6500 CipherSuites: signingCiphers,
6501 SignSignatureAlgorithms: []signatureAlgorithm{
6502 alg.id,
6503 },
6504 Bugs: ProtocolBugs{
6505 InvalidSignature: true,
6506 },
6507 },
6508 flags: []string{"-enable-all-curves"},
6509 shouldFail: true,
6510 expectedError: ":BAD_SIGNATURE:",
6511 })
6512 }
David Benjaminca3d5452016-07-14 12:51:01 -04006513
David Benjamin3ef76972016-10-17 17:59:54 -04006514 if ver.version >= VersionTLS12 && !shouldSignFail {
David Benjaminca3d5452016-07-14 12:51:01 -04006515 testCases = append(testCases, testCase{
6516 name: "ClientAuth-Sign-Negotiate" + suffix,
6517 config: Config{
6518 MaxVersion: ver.version,
6519 ClientAuth: RequireAnyClientCert,
6520 VerifySignatureAlgorithms: allAlgorithms,
6521 },
6522 flags: []string{
6523 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6524 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6525 "-enable-all-curves",
6526 "-signing-prefs", strconv.Itoa(int(alg.id)),
6527 },
6528 expectedPeerSignatureAlgorithm: alg.id,
6529 })
6530
6531 testCases = append(testCases, testCase{
6532 testType: serverTest,
6533 name: "ServerAuth-Sign-Negotiate" + suffix,
6534 config: Config{
6535 MaxVersion: ver.version,
6536 CipherSuites: signingCiphers,
6537 VerifySignatureAlgorithms: allAlgorithms,
6538 },
6539 flags: []string{
6540 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6541 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6542 "-enable-all-curves",
6543 "-signing-prefs", strconv.Itoa(int(alg.id)),
6544 },
6545 expectedPeerSignatureAlgorithm: alg.id,
6546 })
6547 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006548 }
David Benjamin000800a2014-11-14 01:43:59 -05006549 }
6550
Nick Harper60edffd2016-06-21 15:19:24 -07006551 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006552 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006553 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006554 config: Config{
6555 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006556 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006557 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006558 signatureECDSAWithP521AndSHA512,
6559 signatureRSAPKCS1WithSHA384,
6560 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006561 },
6562 },
6563 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006564 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6565 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006566 },
Nick Harper60edffd2016-06-21 15:19:24 -07006567 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006568 })
6569
6570 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006571 name: "ClientAuth-SignatureType-TLS13",
6572 config: Config{
6573 ClientAuth: RequireAnyClientCert,
6574 MaxVersion: VersionTLS13,
6575 VerifySignatureAlgorithms: []signatureAlgorithm{
6576 signatureECDSAWithP521AndSHA512,
6577 signatureRSAPKCS1WithSHA384,
6578 signatureRSAPSSWithSHA384,
6579 signatureECDSAWithSHA1,
6580 },
6581 },
6582 flags: []string{
6583 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6584 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6585 },
6586 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6587 })
6588
6589 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006590 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006591 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006592 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006593 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006594 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006595 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006596 signatureECDSAWithP521AndSHA512,
6597 signatureRSAPKCS1WithSHA384,
6598 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006599 },
6600 },
Nick Harper60edffd2016-06-21 15:19:24 -07006601 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006602 })
6603
Steven Valdez143e8b32016-07-11 13:19:03 -04006604 testCases = append(testCases, testCase{
6605 testType: serverTest,
6606 name: "ServerAuth-SignatureType-TLS13",
6607 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006608 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006609 VerifySignatureAlgorithms: []signatureAlgorithm{
6610 signatureECDSAWithP521AndSHA512,
6611 signatureRSAPKCS1WithSHA384,
6612 signatureRSAPSSWithSHA384,
6613 signatureECDSAWithSHA1,
6614 },
6615 },
6616 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6617 })
6618
David Benjamina95e9f32016-07-08 16:28:04 -07006619 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006620 testCases = append(testCases, testCase{
6621 testType: serverTest,
6622 name: "Verify-ClientAuth-SignatureType",
6623 config: Config{
6624 MaxVersion: VersionTLS12,
6625 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006626 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006627 signatureRSAPKCS1WithSHA256,
6628 },
6629 Bugs: ProtocolBugs{
6630 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6631 },
6632 },
6633 flags: []string{
6634 "-require-any-client-certificate",
6635 },
6636 shouldFail: true,
6637 expectedError: ":WRONG_SIGNATURE_TYPE:",
6638 })
6639
6640 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006641 testType: serverTest,
6642 name: "Verify-ClientAuth-SignatureType-TLS13",
6643 config: Config{
6644 MaxVersion: VersionTLS13,
6645 Certificates: []Certificate{rsaCertificate},
6646 SignSignatureAlgorithms: []signatureAlgorithm{
6647 signatureRSAPSSWithSHA256,
6648 },
6649 Bugs: ProtocolBugs{
6650 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6651 },
6652 },
6653 flags: []string{
6654 "-require-any-client-certificate",
6655 },
6656 shouldFail: true,
6657 expectedError: ":WRONG_SIGNATURE_TYPE:",
6658 })
6659
6660 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006661 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006662 config: Config{
6663 MaxVersion: VersionTLS12,
6664 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006665 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006666 signatureRSAPKCS1WithSHA256,
6667 },
6668 Bugs: ProtocolBugs{
6669 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6670 },
6671 },
6672 shouldFail: true,
6673 expectedError: ":WRONG_SIGNATURE_TYPE:",
6674 })
6675
Steven Valdez143e8b32016-07-11 13:19:03 -04006676 testCases = append(testCases, testCase{
6677 name: "Verify-ServerAuth-SignatureType-TLS13",
6678 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006679 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006680 SignSignatureAlgorithms: []signatureAlgorithm{
6681 signatureRSAPSSWithSHA256,
6682 },
6683 Bugs: ProtocolBugs{
6684 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6685 },
6686 },
6687 shouldFail: true,
6688 expectedError: ":WRONG_SIGNATURE_TYPE:",
6689 })
6690
David Benjamin51dd7d62016-07-08 16:07:01 -07006691 // Test that, if the list is missing, the peer falls back to SHA-1 in
6692 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006693 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006694 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006695 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006696 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006697 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006698 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006699 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006700 },
6701 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006702 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006703 },
6704 },
6705 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006706 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6707 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006708 },
6709 })
6710
6711 testCases = append(testCases, testCase{
6712 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006713 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006714 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006715 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006716 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006717 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006718 },
6719 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006720 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006721 },
6722 },
David Benjaminee32bea2016-08-17 13:36:44 -04006723 flags: []string{
6724 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6725 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6726 },
6727 })
6728
6729 testCases = append(testCases, testCase{
6730 name: "ClientAuth-SHA1-Fallback-ECDSA",
6731 config: Config{
6732 MaxVersion: VersionTLS12,
6733 ClientAuth: RequireAnyClientCert,
6734 VerifySignatureAlgorithms: []signatureAlgorithm{
6735 signatureECDSAWithSHA1,
6736 },
6737 Bugs: ProtocolBugs{
6738 NoSignatureAlgorithms: true,
6739 },
6740 },
6741 flags: []string{
6742 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6743 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6744 },
6745 })
6746
6747 testCases = append(testCases, testCase{
6748 testType: serverTest,
6749 name: "ServerAuth-SHA1-Fallback-ECDSA",
6750 config: Config{
6751 MaxVersion: VersionTLS12,
6752 VerifySignatureAlgorithms: []signatureAlgorithm{
6753 signatureECDSAWithSHA1,
6754 },
6755 Bugs: ProtocolBugs{
6756 NoSignatureAlgorithms: true,
6757 },
6758 },
6759 flags: []string{
6760 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6761 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6762 },
David Benjamin000800a2014-11-14 01:43:59 -05006763 })
David Benjamin72dc7832015-03-16 17:49:43 -04006764
David Benjamin51dd7d62016-07-08 16:07:01 -07006765 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006766 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006767 config: Config{
6768 MaxVersion: VersionTLS13,
6769 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006770 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006771 signatureRSAPKCS1WithSHA1,
6772 },
6773 Bugs: ProtocolBugs{
6774 NoSignatureAlgorithms: true,
6775 },
6776 },
6777 flags: []string{
6778 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6779 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6780 },
David Benjamin48901652016-08-01 12:12:47 -04006781 shouldFail: true,
6782 // An empty CertificateRequest signature algorithm list is a
6783 // syntax error in TLS 1.3.
6784 expectedError: ":DECODE_ERROR:",
6785 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006786 })
6787
6788 testCases = append(testCases, testCase{
6789 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006790 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006791 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006792 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006793 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006794 signatureRSAPKCS1WithSHA1,
6795 },
6796 Bugs: ProtocolBugs{
6797 NoSignatureAlgorithms: true,
6798 },
6799 },
6800 shouldFail: true,
6801 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6802 })
6803
David Benjaminb62d2872016-07-18 14:55:02 +02006804 // Test that hash preferences are enforced. BoringSSL does not implement
6805 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006806 testCases = append(testCases, testCase{
6807 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006808 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006809 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006810 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006811 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006812 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006813 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006814 },
6815 Bugs: ProtocolBugs{
6816 IgnorePeerSignatureAlgorithmPreferences: true,
6817 },
6818 },
6819 flags: []string{"-require-any-client-certificate"},
6820 shouldFail: true,
6821 expectedError: ":WRONG_SIGNATURE_TYPE:",
6822 })
6823
6824 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006825 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006826 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006827 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006828 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006829 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006830 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006831 },
6832 Bugs: ProtocolBugs{
6833 IgnorePeerSignatureAlgorithmPreferences: true,
6834 },
6835 },
6836 shouldFail: true,
6837 expectedError: ":WRONG_SIGNATURE_TYPE:",
6838 })
David Benjaminb62d2872016-07-18 14:55:02 +02006839 testCases = append(testCases, testCase{
6840 testType: serverTest,
6841 name: "ClientAuth-Enforced-TLS13",
6842 config: Config{
6843 MaxVersion: VersionTLS13,
6844 Certificates: []Certificate{rsaCertificate},
6845 SignSignatureAlgorithms: []signatureAlgorithm{
6846 signatureRSAPKCS1WithMD5,
6847 },
6848 Bugs: ProtocolBugs{
6849 IgnorePeerSignatureAlgorithmPreferences: true,
6850 IgnoreSignatureVersionChecks: true,
6851 },
6852 },
6853 flags: []string{"-require-any-client-certificate"},
6854 shouldFail: true,
6855 expectedError: ":WRONG_SIGNATURE_TYPE:",
6856 })
6857
6858 testCases = append(testCases, testCase{
6859 name: "ServerAuth-Enforced-TLS13",
6860 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006861 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006862 SignSignatureAlgorithms: []signatureAlgorithm{
6863 signatureRSAPKCS1WithMD5,
6864 },
6865 Bugs: ProtocolBugs{
6866 IgnorePeerSignatureAlgorithmPreferences: true,
6867 IgnoreSignatureVersionChecks: true,
6868 },
6869 },
6870 shouldFail: true,
6871 expectedError: ":WRONG_SIGNATURE_TYPE:",
6872 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006873
6874 // Test that the agreed upon digest respects the client preferences and
6875 // the server digests.
6876 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006877 name: "NoCommonAlgorithms-Digests",
6878 config: Config{
6879 MaxVersion: VersionTLS12,
6880 ClientAuth: RequireAnyClientCert,
6881 VerifySignatureAlgorithms: []signatureAlgorithm{
6882 signatureRSAPKCS1WithSHA512,
6883 signatureRSAPKCS1WithSHA1,
6884 },
6885 },
6886 flags: []string{
6887 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6888 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6889 "-digest-prefs", "SHA256",
6890 },
6891 shouldFail: true,
6892 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6893 })
6894 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006895 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006896 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006897 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006898 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006899 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006900 signatureRSAPKCS1WithSHA512,
6901 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006902 },
6903 },
6904 flags: []string{
6905 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6906 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006907 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006908 },
David Benjaminca3d5452016-07-14 12:51:01 -04006909 shouldFail: true,
6910 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6911 })
6912 testCases = append(testCases, testCase{
6913 name: "NoCommonAlgorithms-TLS13",
6914 config: Config{
6915 MaxVersion: VersionTLS13,
6916 ClientAuth: RequireAnyClientCert,
6917 VerifySignatureAlgorithms: []signatureAlgorithm{
6918 signatureRSAPSSWithSHA512,
6919 signatureRSAPSSWithSHA384,
6920 },
6921 },
6922 flags: []string{
6923 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6924 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6925 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6926 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006927 shouldFail: true,
6928 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006929 })
6930 testCases = append(testCases, testCase{
6931 name: "Agree-Digest-SHA256",
6932 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006933 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006934 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006935 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006936 signatureRSAPKCS1WithSHA1,
6937 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006938 },
6939 },
6940 flags: []string{
6941 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6942 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006943 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006944 },
Nick Harper60edffd2016-06-21 15:19:24 -07006945 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006946 })
6947 testCases = append(testCases, testCase{
6948 name: "Agree-Digest-SHA1",
6949 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006950 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006951 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006952 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006953 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006954 },
6955 },
6956 flags: []string{
6957 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6958 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006959 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006960 },
Nick Harper60edffd2016-06-21 15:19:24 -07006961 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006962 })
6963 testCases = append(testCases, testCase{
6964 name: "Agree-Digest-Default",
6965 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006966 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006967 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006968 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006969 signatureRSAPKCS1WithSHA256,
6970 signatureECDSAWithP256AndSHA256,
6971 signatureRSAPKCS1WithSHA1,
6972 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006973 },
6974 },
6975 flags: []string{
6976 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6977 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6978 },
Nick Harper60edffd2016-06-21 15:19:24 -07006979 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006980 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006981
David Benjaminca3d5452016-07-14 12:51:01 -04006982 // Test that the signing preference list may include extra algorithms
6983 // without negotiation problems.
6984 testCases = append(testCases, testCase{
6985 testType: serverTest,
6986 name: "FilterExtraAlgorithms",
6987 config: Config{
6988 MaxVersion: VersionTLS12,
6989 VerifySignatureAlgorithms: []signatureAlgorithm{
6990 signatureRSAPKCS1WithSHA256,
6991 },
6992 },
6993 flags: []string{
6994 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6995 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6996 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6997 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6998 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6999 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
7000 },
7001 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
7002 })
7003
David Benjamin4c3ddf72016-06-29 18:13:53 -04007004 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
7005 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04007006 testCases = append(testCases, testCase{
7007 name: "CheckLeafCurve",
7008 config: Config{
7009 MaxVersion: VersionTLS12,
7010 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07007011 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04007012 },
7013 flags: []string{"-p384-only"},
7014 shouldFail: true,
7015 expectedError: ":BAD_ECC_CERT:",
7016 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07007017
7018 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
7019 testCases = append(testCases, testCase{
7020 name: "CheckLeafCurve-TLS13",
7021 config: Config{
7022 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07007023 Certificates: []Certificate{ecdsaP256Certificate},
7024 },
7025 flags: []string{"-p384-only"},
7026 })
David Benjamin1fb125c2016-07-08 18:52:12 -07007027
7028 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
7029 testCases = append(testCases, testCase{
7030 name: "ECDSACurveMismatch-Verify-TLS12",
7031 config: Config{
7032 MaxVersion: VersionTLS12,
7033 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
7034 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007035 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007036 signatureECDSAWithP384AndSHA384,
7037 },
7038 },
7039 })
7040
7041 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
7042 testCases = append(testCases, testCase{
7043 name: "ECDSACurveMismatch-Verify-TLS13",
7044 config: Config{
7045 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07007046 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07007047 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007048 signatureECDSAWithP384AndSHA384,
7049 },
7050 Bugs: ProtocolBugs{
7051 SkipECDSACurveCheck: true,
7052 },
7053 },
7054 shouldFail: true,
7055 expectedError: ":WRONG_SIGNATURE_TYPE:",
7056 })
7057
7058 // Signature algorithm selection in TLS 1.3 should take the curve into
7059 // account.
7060 testCases = append(testCases, testCase{
7061 testType: serverTest,
7062 name: "ECDSACurveMismatch-Sign-TLS13",
7063 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007064 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07007065 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07007066 signatureECDSAWithP384AndSHA384,
7067 signatureECDSAWithP256AndSHA256,
7068 },
7069 },
7070 flags: []string{
7071 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
7072 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
7073 },
7074 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
7075 })
David Benjamin7944a9f2016-07-12 22:27:01 -04007076
7077 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
7078 // server does not attempt to sign in that case.
7079 testCases = append(testCases, testCase{
7080 testType: serverTest,
7081 name: "RSA-PSS-Large",
7082 config: Config{
7083 MaxVersion: VersionTLS13,
7084 VerifySignatureAlgorithms: []signatureAlgorithm{
7085 signatureRSAPSSWithSHA512,
7086 },
7087 },
7088 flags: []string{
7089 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
7090 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
7091 },
7092 shouldFail: true,
7093 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
7094 })
David Benjamin57e929f2016-08-30 00:30:38 -04007095
7096 // Test that RSA-PSS is enabled by default for TLS 1.2.
7097 testCases = append(testCases, testCase{
7098 testType: clientTest,
7099 name: "RSA-PSS-Default-Verify",
7100 config: Config{
7101 MaxVersion: VersionTLS12,
7102 SignSignatureAlgorithms: []signatureAlgorithm{
7103 signatureRSAPSSWithSHA256,
7104 },
7105 },
7106 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7107 })
7108
7109 testCases = append(testCases, testCase{
7110 testType: serverTest,
7111 name: "RSA-PSS-Default-Sign",
7112 config: Config{
7113 MaxVersion: VersionTLS12,
7114 VerifySignatureAlgorithms: []signatureAlgorithm{
7115 signatureRSAPSSWithSHA256,
7116 },
7117 },
7118 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7119 })
David Benjamin000800a2014-11-14 01:43:59 -05007120}
7121
David Benjamin83f90402015-01-27 01:09:43 -05007122// timeouts is the retransmit schedule for BoringSSL. It doubles and
7123// caps at 60 seconds. On the 13th timeout, it gives up.
7124var timeouts = []time.Duration{
7125 1 * time.Second,
7126 2 * time.Second,
7127 4 * time.Second,
7128 8 * time.Second,
7129 16 * time.Second,
7130 32 * time.Second,
7131 60 * time.Second,
7132 60 * time.Second,
7133 60 * time.Second,
7134 60 * time.Second,
7135 60 * time.Second,
7136 60 * time.Second,
7137 60 * time.Second,
7138}
7139
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07007140// shortTimeouts is an alternate set of timeouts which would occur if the
7141// initial timeout duration was set to 250ms.
7142var shortTimeouts = []time.Duration{
7143 250 * time.Millisecond,
7144 500 * time.Millisecond,
7145 1 * time.Second,
7146 2 * time.Second,
7147 4 * time.Second,
7148 8 * time.Second,
7149 16 * time.Second,
7150 32 * time.Second,
7151 60 * time.Second,
7152 60 * time.Second,
7153 60 * time.Second,
7154 60 * time.Second,
7155 60 * time.Second,
7156}
7157
David Benjamin83f90402015-01-27 01:09:43 -05007158func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04007159 // These tests work by coordinating some behavior on both the shim and
7160 // the runner.
7161 //
7162 // TimeoutSchedule configures the runner to send a series of timeout
7163 // opcodes to the shim (see packetAdaptor) immediately before reading
7164 // each peer handshake flight N. The timeout opcode both simulates a
7165 // timeout in the shim and acts as a synchronization point to help the
7166 // runner bracket each handshake flight.
7167 //
7168 // We assume the shim does not read from the channel eagerly. It must
7169 // first wait until it has sent flight N and is ready to receive
7170 // handshake flight N+1. At this point, it will process the timeout
7171 // opcode. It must then immediately respond with a timeout ACK and act
7172 // as if the shim was idle for the specified amount of time.
7173 //
7174 // The runner then drops all packets received before the ACK and
7175 // continues waiting for flight N. This ordering results in one attempt
7176 // at sending flight N to be dropped. For the test to complete, the
7177 // shim must send flight N again, testing that the shim implements DTLS
7178 // retransmit on a timeout.
7179
Steven Valdez143e8b32016-07-11 13:19:03 -04007180 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04007181 // likely be more epochs to cross and the final message's retransmit may
7182 // be more complex.
7183
David Benjamin585d7a42016-06-02 14:58:00 -04007184 for _, async := range []bool{true, false} {
7185 var tests []testCase
7186
7187 // Test that this is indeed the timeout schedule. Stress all
7188 // four patterns of handshake.
7189 for i := 1; i < len(timeouts); i++ {
7190 number := strconv.Itoa(i)
7191 tests = append(tests, testCase{
7192 protocol: dtls,
7193 name: "DTLS-Retransmit-Client-" + number,
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: timeouts[:i],
7198 },
7199 },
7200 resumeSession: true,
7201 })
7202 tests = append(tests, testCase{
7203 protocol: dtls,
7204 testType: serverTest,
7205 name: "DTLS-Retransmit-Server-" + number,
7206 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007207 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007208 Bugs: ProtocolBugs{
7209 TimeoutSchedule: timeouts[:i],
7210 },
7211 },
7212 resumeSession: true,
7213 })
7214 }
7215
7216 // Test that exceeding the timeout schedule hits a read
7217 // timeout.
7218 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007219 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04007220 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05007221 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007222 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007223 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007224 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05007225 },
7226 },
7227 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007228 shouldFail: true,
7229 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05007230 })
David Benjamin585d7a42016-06-02 14:58:00 -04007231
7232 if async {
7233 // Test that timeout handling has a fudge factor, due to API
7234 // problems.
7235 tests = append(tests, testCase{
7236 protocol: dtls,
7237 name: "DTLS-Retransmit-Fudge",
7238 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007239 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007240 Bugs: ProtocolBugs{
7241 TimeoutSchedule: []time.Duration{
7242 timeouts[0] - 10*time.Millisecond,
7243 },
7244 },
7245 },
7246 resumeSession: true,
7247 })
7248 }
7249
7250 // Test that the final Finished retransmitting isn't
7251 // duplicated if the peer badly fragments everything.
7252 tests = append(tests, testCase{
7253 testType: serverTest,
7254 protocol: dtls,
7255 name: "DTLS-Retransmit-Fragmented",
7256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007257 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007258 Bugs: ProtocolBugs{
7259 TimeoutSchedule: []time.Duration{timeouts[0]},
7260 MaxHandshakeRecordLength: 2,
7261 },
7262 },
7263 })
7264
7265 // Test the timeout schedule when a shorter initial timeout duration is set.
7266 tests = append(tests, testCase{
7267 protocol: dtls,
7268 name: "DTLS-Retransmit-Short-Client",
7269 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007270 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04007271 Bugs: ProtocolBugs{
7272 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
7273 },
7274 },
7275 resumeSession: true,
7276 flags: []string{"-initial-timeout-duration-ms", "250"},
7277 })
7278 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05007279 protocol: dtls,
7280 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04007281 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05007282 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007283 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05007284 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04007285 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05007286 },
7287 },
7288 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04007289 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05007290 })
David Benjamin585d7a42016-06-02 14:58:00 -04007291
7292 for _, test := range tests {
7293 if async {
7294 test.name += "-Async"
7295 test.flags = append(test.flags, "-async")
7296 }
7297
7298 testCases = append(testCases, test)
7299 }
David Benjamin83f90402015-01-27 01:09:43 -05007300 }
David Benjamin83f90402015-01-27 01:09:43 -05007301}
7302
David Benjaminc565ebb2015-04-03 04:06:36 -04007303func addExportKeyingMaterialTests() {
7304 for _, vers := range tlsVersions {
7305 if vers.version == VersionSSL30 {
7306 continue
7307 }
7308 testCases = append(testCases, testCase{
7309 name: "ExportKeyingMaterial-" + vers.name,
7310 config: Config{
7311 MaxVersion: vers.version,
7312 },
7313 exportKeyingMaterial: 1024,
7314 exportLabel: "label",
7315 exportContext: "context",
7316 useExportContext: true,
7317 })
7318 testCases = append(testCases, testCase{
7319 name: "ExportKeyingMaterial-NoContext-" + vers.name,
7320 config: Config{
7321 MaxVersion: vers.version,
7322 },
7323 exportKeyingMaterial: 1024,
7324 })
7325 testCases = append(testCases, testCase{
7326 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
7327 config: Config{
7328 MaxVersion: vers.version,
7329 },
7330 exportKeyingMaterial: 1024,
7331 useExportContext: true,
7332 })
7333 testCases = append(testCases, testCase{
7334 name: "ExportKeyingMaterial-Small-" + vers.name,
7335 config: Config{
7336 MaxVersion: vers.version,
7337 },
7338 exportKeyingMaterial: 1,
7339 exportLabel: "label",
7340 exportContext: "context",
7341 useExportContext: true,
7342 })
7343 }
David Benjamin7bb1d292016-11-01 19:45:06 -04007344
David Benjaminc565ebb2015-04-03 04:06:36 -04007345 testCases = append(testCases, testCase{
7346 name: "ExportKeyingMaterial-SSL3",
7347 config: Config{
7348 MaxVersion: VersionSSL30,
7349 },
7350 exportKeyingMaterial: 1024,
7351 exportLabel: "label",
7352 exportContext: "context",
7353 useExportContext: true,
7354 shouldFail: true,
7355 expectedError: "failed to export keying material",
7356 })
David Benjamin7bb1d292016-11-01 19:45:06 -04007357
7358 // Exporters work during a False Start.
7359 testCases = append(testCases, testCase{
7360 name: "ExportKeyingMaterial-FalseStart",
7361 config: Config{
7362 MaxVersion: VersionTLS12,
7363 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7364 NextProtos: []string{"foo"},
7365 Bugs: ProtocolBugs{
7366 ExpectFalseStart: true,
7367 },
7368 },
7369 flags: []string{
7370 "-false-start",
7371 "-advertise-alpn", "\x03foo",
7372 },
7373 shimWritesFirst: true,
7374 exportKeyingMaterial: 1024,
7375 exportLabel: "label",
7376 exportContext: "context",
7377 useExportContext: true,
7378 })
7379
7380 // Exporters do not work in the middle of a renegotiation. Test this by
7381 // triggering the exporter after every SSL_read call and configuring the
7382 // shim to run asynchronously.
7383 testCases = append(testCases, testCase{
7384 name: "ExportKeyingMaterial-Renegotiate",
7385 config: Config{
7386 MaxVersion: VersionTLS12,
7387 },
7388 renegotiate: 1,
7389 flags: []string{
7390 "-async",
7391 "-use-exporter-between-reads",
7392 "-renegotiate-freely",
7393 "-expect-total-renegotiations", "1",
7394 },
7395 shouldFail: true,
7396 expectedError: "failed to export keying material",
7397 })
David Benjaminc565ebb2015-04-03 04:06:36 -04007398}
7399
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007400func addTLSUniqueTests() {
7401 for _, isClient := range []bool{false, true} {
7402 for _, isResumption := range []bool{false, true} {
7403 for _, hasEMS := range []bool{false, true} {
7404 var suffix string
7405 if isResumption {
7406 suffix = "Resume-"
7407 } else {
7408 suffix = "Full-"
7409 }
7410
7411 if hasEMS {
7412 suffix += "EMS-"
7413 } else {
7414 suffix += "NoEMS-"
7415 }
7416
7417 if isClient {
7418 suffix += "Client"
7419 } else {
7420 suffix += "Server"
7421 }
7422
7423 test := testCase{
7424 name: "TLSUnique-" + suffix,
7425 testTLSUnique: true,
7426 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007427 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007428 Bugs: ProtocolBugs{
7429 NoExtendedMasterSecret: !hasEMS,
7430 },
7431 },
7432 }
7433
7434 if isResumption {
7435 test.resumeSession = true
7436 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007437 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07007438 Bugs: ProtocolBugs{
7439 NoExtendedMasterSecret: !hasEMS,
7440 },
7441 }
7442 }
7443
7444 if isResumption && !hasEMS {
7445 test.shouldFail = true
7446 test.expectedError = "failed to get tls-unique"
7447 }
7448
7449 testCases = append(testCases, test)
7450 }
7451 }
7452 }
7453}
7454
Adam Langley09505632015-07-30 18:10:13 -07007455func addCustomExtensionTests() {
7456 expectedContents := "custom extension"
7457 emptyString := ""
7458
7459 for _, isClient := range []bool{false, true} {
7460 suffix := "Server"
7461 flag := "-enable-server-custom-extension"
7462 testType := serverTest
7463 if isClient {
7464 suffix = "Client"
7465 flag = "-enable-client-custom-extension"
7466 testType = clientTest
7467 }
7468
7469 testCases = append(testCases, testCase{
7470 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007471 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007472 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007473 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007474 Bugs: ProtocolBugs{
7475 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007476 ExpectedCustomExtension: &expectedContents,
7477 },
7478 },
7479 flags: []string{flag},
7480 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007481 testCases = append(testCases, testCase{
7482 testType: testType,
7483 name: "CustomExtensions-" + suffix + "-TLS13",
7484 config: Config{
7485 MaxVersion: VersionTLS13,
7486 Bugs: ProtocolBugs{
7487 CustomExtension: expectedContents,
7488 ExpectedCustomExtension: &expectedContents,
7489 },
7490 },
7491 flags: []string{flag},
7492 })
Adam Langley09505632015-07-30 18:10:13 -07007493
7494 // If the parse callback fails, the handshake should also fail.
7495 testCases = append(testCases, testCase{
7496 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007497 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007498 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007499 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007500 Bugs: ProtocolBugs{
7501 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07007502 ExpectedCustomExtension: &expectedContents,
7503 },
7504 },
David Benjamin399e7c92015-07-30 23:01:27 -04007505 flags: []string{flag},
7506 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007507 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7508 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007509 testCases = append(testCases, testCase{
7510 testType: testType,
7511 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
7512 config: Config{
7513 MaxVersion: VersionTLS13,
7514 Bugs: ProtocolBugs{
7515 CustomExtension: expectedContents + "foo",
7516 ExpectedCustomExtension: &expectedContents,
7517 },
7518 },
7519 flags: []string{flag},
7520 shouldFail: true,
7521 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7522 })
Adam Langley09505632015-07-30 18:10:13 -07007523
7524 // If the add callback fails, the handshake should also fail.
7525 testCases = append(testCases, testCase{
7526 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007527 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007528 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007529 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007530 Bugs: ProtocolBugs{
7531 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007532 ExpectedCustomExtension: &expectedContents,
7533 },
7534 },
David Benjamin399e7c92015-07-30 23:01:27 -04007535 flags: []string{flag, "-custom-extension-fail-add"},
7536 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007537 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7538 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007539 testCases = append(testCases, testCase{
7540 testType: testType,
7541 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7542 config: Config{
7543 MaxVersion: VersionTLS13,
7544 Bugs: ProtocolBugs{
7545 CustomExtension: expectedContents,
7546 ExpectedCustomExtension: &expectedContents,
7547 },
7548 },
7549 flags: []string{flag, "-custom-extension-fail-add"},
7550 shouldFail: true,
7551 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7552 })
Adam Langley09505632015-07-30 18:10:13 -07007553
7554 // If the add callback returns zero, no extension should be
7555 // added.
7556 skipCustomExtension := expectedContents
7557 if isClient {
7558 // For the case where the client skips sending the
7559 // custom extension, the server must not “echo” it.
7560 skipCustomExtension = ""
7561 }
7562 testCases = append(testCases, testCase{
7563 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007564 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007565 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007566 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007567 Bugs: ProtocolBugs{
7568 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007569 ExpectedCustomExtension: &emptyString,
7570 },
7571 },
7572 flags: []string{flag, "-custom-extension-skip"},
7573 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007574 testCases = append(testCases, testCase{
7575 testType: testType,
7576 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7577 config: Config{
7578 MaxVersion: VersionTLS13,
7579 Bugs: ProtocolBugs{
7580 CustomExtension: skipCustomExtension,
7581 ExpectedCustomExtension: &emptyString,
7582 },
7583 },
7584 flags: []string{flag, "-custom-extension-skip"},
7585 })
Adam Langley09505632015-07-30 18:10:13 -07007586 }
7587
7588 // The custom extension add callback should not be called if the client
7589 // doesn't send the extension.
7590 testCases = append(testCases, testCase{
7591 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007592 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007593 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007594 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007595 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007596 ExpectedCustomExtension: &emptyString,
7597 },
7598 },
7599 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7600 })
Adam Langley2deb9842015-08-07 11:15:37 -07007601
Steven Valdez143e8b32016-07-11 13:19:03 -04007602 testCases = append(testCases, testCase{
7603 testType: serverTest,
7604 name: "CustomExtensions-NotCalled-Server-TLS13",
7605 config: Config{
7606 MaxVersion: VersionTLS13,
7607 Bugs: ProtocolBugs{
7608 ExpectedCustomExtension: &emptyString,
7609 },
7610 },
7611 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7612 })
7613
Adam Langley2deb9842015-08-07 11:15:37 -07007614 // Test an unknown extension from the server.
7615 testCases = append(testCases, testCase{
7616 testType: clientTest,
7617 name: "UnknownExtension-Client",
7618 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007619 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007620 Bugs: ProtocolBugs{
7621 CustomExtension: expectedContents,
7622 },
7623 },
David Benjamin0c40a962016-08-01 12:05:50 -04007624 shouldFail: true,
7625 expectedError: ":UNEXPECTED_EXTENSION:",
7626 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007627 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007628 testCases = append(testCases, testCase{
7629 testType: clientTest,
7630 name: "UnknownExtension-Client-TLS13",
7631 config: Config{
7632 MaxVersion: VersionTLS13,
7633 Bugs: ProtocolBugs{
7634 CustomExtension: expectedContents,
7635 },
7636 },
David Benjamin0c40a962016-08-01 12:05:50 -04007637 shouldFail: true,
7638 expectedError: ":UNEXPECTED_EXTENSION:",
7639 expectedLocalError: "remote error: unsupported extension",
7640 })
David Benjamin490469f2016-10-05 22:44:38 -04007641 testCases = append(testCases, testCase{
7642 testType: clientTest,
7643 name: "UnknownUnencryptedExtension-Client-TLS13",
7644 config: Config{
7645 MaxVersion: VersionTLS13,
7646 Bugs: ProtocolBugs{
7647 CustomUnencryptedExtension: expectedContents,
7648 },
7649 },
7650 shouldFail: true,
7651 expectedError: ":UNEXPECTED_EXTENSION:",
7652 // The shim must send an alert, but alerts at this point do not
7653 // get successfully decrypted by the runner.
7654 expectedLocalError: "local error: bad record MAC",
7655 })
7656 testCases = append(testCases, testCase{
7657 testType: clientTest,
7658 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7659 config: Config{
7660 MaxVersion: VersionTLS13,
7661 Bugs: ProtocolBugs{
7662 SendUnencryptedALPN: "foo",
7663 },
7664 },
7665 flags: []string{
7666 "-advertise-alpn", "\x03foo\x03bar",
7667 },
7668 shouldFail: true,
7669 expectedError: ":UNEXPECTED_EXTENSION:",
7670 // The shim must send an alert, but alerts at this point do not
7671 // get successfully decrypted by the runner.
7672 expectedLocalError: "local error: bad record MAC",
7673 })
David Benjamin0c40a962016-08-01 12:05:50 -04007674
7675 // Test a known but unoffered extension from the server.
7676 testCases = append(testCases, testCase{
7677 testType: clientTest,
7678 name: "UnofferedExtension-Client",
7679 config: Config{
7680 MaxVersion: VersionTLS12,
7681 Bugs: ProtocolBugs{
7682 SendALPN: "alpn",
7683 },
7684 },
7685 shouldFail: true,
7686 expectedError: ":UNEXPECTED_EXTENSION:",
7687 expectedLocalError: "remote error: unsupported extension",
7688 })
7689 testCases = append(testCases, testCase{
7690 testType: clientTest,
7691 name: "UnofferedExtension-Client-TLS13",
7692 config: Config{
7693 MaxVersion: VersionTLS13,
7694 Bugs: ProtocolBugs{
7695 SendALPN: "alpn",
7696 },
7697 },
7698 shouldFail: true,
7699 expectedError: ":UNEXPECTED_EXTENSION:",
7700 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007701 })
Adam Langley09505632015-07-30 18:10:13 -07007702}
7703
David Benjaminb36a3952015-12-01 18:53:13 -05007704func addRSAClientKeyExchangeTests() {
7705 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7706 testCases = append(testCases, testCase{
7707 testType: serverTest,
7708 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7709 config: Config{
7710 // Ensure the ClientHello version and final
7711 // version are different, to detect if the
7712 // server uses the wrong one.
7713 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007714 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007715 Bugs: ProtocolBugs{
7716 BadRSAClientKeyExchange: bad,
7717 },
7718 },
7719 shouldFail: true,
7720 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7721 })
7722 }
David Benjamine63d9d72016-09-19 18:27:34 -04007723
7724 // The server must compare whatever was in ClientHello.version for the
7725 // RSA premaster.
7726 testCases = append(testCases, testCase{
7727 testType: serverTest,
7728 name: "SendClientVersion-RSA",
7729 config: Config{
7730 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7731 Bugs: ProtocolBugs{
7732 SendClientVersion: 0x1234,
7733 },
7734 },
7735 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7736 })
David Benjaminb36a3952015-12-01 18:53:13 -05007737}
7738
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007739var testCurves = []struct {
7740 name string
7741 id CurveID
7742}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007743 {"P-256", CurveP256},
7744 {"P-384", CurveP384},
7745 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007746 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007747}
7748
Steven Valdez5440fe02016-07-18 12:40:30 -04007749const bogusCurve = 0x1234
7750
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007751func addCurveTests() {
7752 for _, curve := range testCurves {
7753 testCases = append(testCases, testCase{
7754 name: "CurveTest-Client-" + curve.name,
7755 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007756 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007757 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7758 CurvePreferences: []CurveID{curve.id},
7759 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007760 flags: []string{
7761 "-enable-all-curves",
7762 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7763 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007764 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007765 })
7766 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007767 name: "CurveTest-Client-" + curve.name + "-TLS13",
7768 config: Config{
7769 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007770 CurvePreferences: []CurveID{curve.id},
7771 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007772 flags: []string{
7773 "-enable-all-curves",
7774 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7775 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007776 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007777 })
7778 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007779 testType: serverTest,
7780 name: "CurveTest-Server-" + curve.name,
7781 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007782 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007783 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7784 CurvePreferences: []CurveID{curve.id},
7785 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007786 flags: []string{
7787 "-enable-all-curves",
7788 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7789 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007790 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007791 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007792 testCases = append(testCases, testCase{
7793 testType: serverTest,
7794 name: "CurveTest-Server-" + curve.name + "-TLS13",
7795 config: Config{
7796 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007797 CurvePreferences: []CurveID{curve.id},
7798 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007799 flags: []string{
7800 "-enable-all-curves",
7801 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7802 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007803 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007804 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007805 }
David Benjamin241ae832016-01-15 03:04:54 -05007806
7807 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007808 testCases = append(testCases, testCase{
7809 testType: serverTest,
7810 name: "UnknownCurve",
7811 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007812 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007813 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7814 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7815 },
7816 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007817
Steven Valdez803c77a2016-09-06 14:13:43 -04007818 // The server must be tolerant to bogus curves.
7819 testCases = append(testCases, testCase{
7820 testType: serverTest,
7821 name: "UnknownCurve-TLS13",
7822 config: Config{
7823 MaxVersion: VersionTLS13,
7824 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7825 },
7826 })
7827
David Benjamin4c3ddf72016-06-29 18:13:53 -04007828 // The server must not consider ECDHE ciphers when there are no
7829 // supported curves.
7830 testCases = append(testCases, testCase{
7831 testType: serverTest,
7832 name: "NoSupportedCurves",
7833 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007834 MaxVersion: VersionTLS12,
7835 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7836 Bugs: ProtocolBugs{
7837 NoSupportedCurves: true,
7838 },
7839 },
7840 shouldFail: true,
7841 expectedError: ":NO_SHARED_CIPHER:",
7842 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007843 testCases = append(testCases, testCase{
7844 testType: serverTest,
7845 name: "NoSupportedCurves-TLS13",
7846 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007847 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007848 Bugs: ProtocolBugs{
7849 NoSupportedCurves: true,
7850 },
7851 },
7852 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007853 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007854 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007855
7856 // The server must fall back to another cipher when there are no
7857 // supported curves.
7858 testCases = append(testCases, testCase{
7859 testType: serverTest,
7860 name: "NoCommonCurves",
7861 config: Config{
7862 MaxVersion: VersionTLS12,
7863 CipherSuites: []uint16{
7864 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7865 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7866 },
7867 CurvePreferences: []CurveID{CurveP224},
7868 },
7869 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7870 })
7871
7872 // The client must reject bogus curves and disabled curves.
7873 testCases = append(testCases, testCase{
7874 name: "BadECDHECurve",
7875 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007876 MaxVersion: VersionTLS12,
7877 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7878 Bugs: ProtocolBugs{
7879 SendCurve: bogusCurve,
7880 },
7881 },
7882 shouldFail: true,
7883 expectedError: ":WRONG_CURVE:",
7884 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007885 testCases = append(testCases, testCase{
7886 name: "BadECDHECurve-TLS13",
7887 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007888 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007889 Bugs: ProtocolBugs{
7890 SendCurve: bogusCurve,
7891 },
7892 },
7893 shouldFail: true,
7894 expectedError: ":WRONG_CURVE:",
7895 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007896
7897 testCases = append(testCases, testCase{
7898 name: "UnsupportedCurve",
7899 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007900 MaxVersion: VersionTLS12,
7901 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7902 CurvePreferences: []CurveID{CurveP256},
7903 Bugs: ProtocolBugs{
7904 IgnorePeerCurvePreferences: true,
7905 },
7906 },
7907 flags: []string{"-p384-only"},
7908 shouldFail: true,
7909 expectedError: ":WRONG_CURVE:",
7910 })
7911
David Benjamin4f921572016-07-17 14:20:10 +02007912 testCases = append(testCases, testCase{
7913 // TODO(davidben): Add a TLS 1.3 version where
7914 // HelloRetryRequest requests an unsupported curve.
7915 name: "UnsupportedCurve-ServerHello-TLS13",
7916 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007917 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007918 CurvePreferences: []CurveID{CurveP384},
7919 Bugs: ProtocolBugs{
7920 SendCurve: CurveP256,
7921 },
7922 },
7923 flags: []string{"-p384-only"},
7924 shouldFail: true,
7925 expectedError: ":WRONG_CURVE:",
7926 })
7927
David Benjamin4c3ddf72016-06-29 18:13:53 -04007928 // Test invalid curve points.
7929 testCases = append(testCases, testCase{
7930 name: "InvalidECDHPoint-Client",
7931 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007932 MaxVersion: VersionTLS12,
7933 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7934 CurvePreferences: []CurveID{CurveP256},
7935 Bugs: ProtocolBugs{
7936 InvalidECDHPoint: true,
7937 },
7938 },
7939 shouldFail: true,
7940 expectedError: ":INVALID_ENCODING:",
7941 })
7942 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007943 name: "InvalidECDHPoint-Client-TLS13",
7944 config: Config{
7945 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007946 CurvePreferences: []CurveID{CurveP256},
7947 Bugs: ProtocolBugs{
7948 InvalidECDHPoint: true,
7949 },
7950 },
7951 shouldFail: true,
7952 expectedError: ":INVALID_ENCODING:",
7953 })
7954 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007955 testType: serverTest,
7956 name: "InvalidECDHPoint-Server",
7957 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007958 MaxVersion: VersionTLS12,
7959 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7960 CurvePreferences: []CurveID{CurveP256},
7961 Bugs: ProtocolBugs{
7962 InvalidECDHPoint: true,
7963 },
7964 },
7965 shouldFail: true,
7966 expectedError: ":INVALID_ENCODING:",
7967 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007968 testCases = append(testCases, testCase{
7969 testType: serverTest,
7970 name: "InvalidECDHPoint-Server-TLS13",
7971 config: Config{
7972 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007973 CurvePreferences: []CurveID{CurveP256},
7974 Bugs: ProtocolBugs{
7975 InvalidECDHPoint: true,
7976 },
7977 },
7978 shouldFail: true,
7979 expectedError: ":INVALID_ENCODING:",
7980 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007981}
7982
Matt Braithwaite54217e42016-06-13 13:03:47 -07007983func addCECPQ1Tests() {
7984 testCases = append(testCases, testCase{
7985 testType: clientTest,
7986 name: "CECPQ1-Client-BadX25519Part",
7987 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007988 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007989 MinVersion: VersionTLS12,
7990 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7991 Bugs: ProtocolBugs{
7992 CECPQ1BadX25519Part: true,
7993 },
7994 },
7995 flags: []string{"-cipher", "kCECPQ1"},
7996 shouldFail: true,
7997 expectedLocalError: "local error: bad record MAC",
7998 })
7999 testCases = append(testCases, testCase{
8000 testType: clientTest,
8001 name: "CECPQ1-Client-BadNewhopePart",
8002 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008003 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008004 MinVersion: VersionTLS12,
8005 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8006 Bugs: ProtocolBugs{
8007 CECPQ1BadNewhopePart: true,
8008 },
8009 },
8010 flags: []string{"-cipher", "kCECPQ1"},
8011 shouldFail: true,
8012 expectedLocalError: "local error: bad record MAC",
8013 })
8014 testCases = append(testCases, testCase{
8015 testType: serverTest,
8016 name: "CECPQ1-Server-BadX25519Part",
8017 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008018 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008019 MinVersion: VersionTLS12,
8020 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8021 Bugs: ProtocolBugs{
8022 CECPQ1BadX25519Part: true,
8023 },
8024 },
8025 flags: []string{"-cipher", "kCECPQ1"},
8026 shouldFail: true,
8027 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8028 })
8029 testCases = append(testCases, testCase{
8030 testType: serverTest,
8031 name: "CECPQ1-Server-BadNewhopePart",
8032 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008033 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07008034 MinVersion: VersionTLS12,
8035 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
8036 Bugs: ProtocolBugs{
8037 CECPQ1BadNewhopePart: true,
8038 },
8039 },
8040 flags: []string{"-cipher", "kCECPQ1"},
8041 shouldFail: true,
8042 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8043 })
8044}
8045
David Benjamin5c4e8572016-08-19 17:44:53 -04008046func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05008047 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04008048 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008049 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008050 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008051 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8052 Bugs: ProtocolBugs{
8053 // This is a 1234-bit prime number, generated
8054 // with:
8055 // openssl gendh 1234 | openssl asn1parse -i
8056 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
8057 },
8058 },
David Benjamin9e68f192016-06-30 14:55:33 -04008059 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008060 })
8061 testCases = append(testCases, testCase{
8062 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04008063 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05008064 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07008065 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05008066 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
8067 },
8068 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04008069 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05008070 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05008071}
8072
David Benjaminc9ae27c2016-06-24 22:56:37 -04008073func addTLS13RecordTests() {
8074 testCases = append(testCases, testCase{
8075 name: "TLS13-RecordPadding",
8076 config: Config{
8077 MaxVersion: VersionTLS13,
8078 MinVersion: VersionTLS13,
8079 Bugs: ProtocolBugs{
8080 RecordPadding: 10,
8081 },
8082 },
8083 })
8084
8085 testCases = append(testCases, testCase{
8086 name: "TLS13-EmptyRecords",
8087 config: Config{
8088 MaxVersion: VersionTLS13,
8089 MinVersion: VersionTLS13,
8090 Bugs: ProtocolBugs{
8091 OmitRecordContents: true,
8092 },
8093 },
8094 shouldFail: true,
8095 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8096 })
8097
8098 testCases = append(testCases, testCase{
8099 name: "TLS13-OnlyPadding",
8100 config: Config{
8101 MaxVersion: VersionTLS13,
8102 MinVersion: VersionTLS13,
8103 Bugs: ProtocolBugs{
8104 OmitRecordContents: true,
8105 RecordPadding: 10,
8106 },
8107 },
8108 shouldFail: true,
8109 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
8110 })
8111
8112 testCases = append(testCases, testCase{
8113 name: "TLS13-WrongOuterRecord",
8114 config: Config{
8115 MaxVersion: VersionTLS13,
8116 MinVersion: VersionTLS13,
8117 Bugs: ProtocolBugs{
8118 OuterRecordType: recordTypeHandshake,
8119 },
8120 },
8121 shouldFail: true,
8122 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
8123 })
8124}
8125
Steven Valdez5b986082016-09-01 12:29:49 -04008126func addSessionTicketTests() {
8127 testCases = append(testCases, testCase{
8128 // In TLS 1.2 and below, empty NewSessionTicket messages
8129 // mean the server changed its mind on sending a ticket.
8130 name: "SendEmptySessionTicket",
8131 config: Config{
8132 MaxVersion: VersionTLS12,
8133 Bugs: ProtocolBugs{
8134 SendEmptySessionTicket: true,
8135 },
8136 },
8137 flags: []string{"-expect-no-session"},
8138 })
8139
8140 // Test that the server ignores unknown PSK modes.
8141 testCases = append(testCases, testCase{
8142 testType: serverTest,
8143 name: "TLS13-SendUnknownModeSessionTicket-Server",
8144 config: Config{
8145 MaxVersion: VersionTLS13,
8146 Bugs: ProtocolBugs{
8147 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
Steven Valdez5b986082016-09-01 12:29:49 -04008148 },
8149 },
8150 resumeSession: true,
8151 expectedResumeVersion: VersionTLS13,
8152 })
8153
Steven Valdeza833c352016-11-01 13:39:36 -04008154 // Test that the server does not send session tickets with no matching key exchange mode.
8155 testCases = append(testCases, testCase{
8156 testType: serverTest,
8157 name: "TLS13-ExpectNoSessionTicketOnBadKEMode-Server",
8158 config: Config{
8159 MaxVersion: VersionTLS13,
8160 Bugs: ProtocolBugs{
8161 SendPSKKeyExchangeModes: []byte{0x1a},
8162 ExpectNoNewSessionTicket: true,
8163 },
8164 },
8165 })
8166
8167 // Test that the server does not accept a session with no matching key exchange mode.
Steven Valdez5b986082016-09-01 12:29:49 -04008168 testCases = append(testCases, testCase{
8169 testType: serverTest,
8170 name: "TLS13-SendBadKEModeSessionTicket-Server",
8171 config: Config{
8172 MaxVersion: VersionTLS13,
Steven Valdeza833c352016-11-01 13:39:36 -04008173 },
8174 resumeConfig: &Config{
8175 MaxVersion: VersionTLS13,
Steven Valdez5b986082016-09-01 12:29:49 -04008176 Bugs: ProtocolBugs{
8177 SendPSKKeyExchangeModes: []byte{0x1a},
8178 },
8179 },
8180 resumeSession: true,
8181 expectResumeRejected: true,
8182 })
8183
Steven Valdeza833c352016-11-01 13:39:36 -04008184 // Test that the client ticket age is sent correctly.
Steven Valdez5b986082016-09-01 12:29:49 -04008185 testCases = append(testCases, testCase{
8186 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008187 name: "TLS13-TestValidTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008188 config: Config{
8189 MaxVersion: VersionTLS13,
8190 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008191 ExpectTicketAge: 10 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008192 },
8193 },
Steven Valdeza833c352016-11-01 13:39:36 -04008194 resumeSession: true,
8195 flags: []string{
8196 "-resumption-delay", "10",
8197 },
Steven Valdez5b986082016-09-01 12:29:49 -04008198 })
8199
Steven Valdeza833c352016-11-01 13:39:36 -04008200 // Test that the client ticket age is enforced.
Steven Valdez5b986082016-09-01 12:29:49 -04008201 testCases = append(testCases, testCase{
8202 testType: clientTest,
Steven Valdeza833c352016-11-01 13:39:36 -04008203 name: "TLS13-TestBadTicketAge-Client",
Steven Valdez5b986082016-09-01 12:29:49 -04008204 config: Config{
8205 MaxVersion: VersionTLS13,
8206 Bugs: ProtocolBugs{
Steven Valdeza833c352016-11-01 13:39:36 -04008207 ExpectTicketAge: 1000 * time.Second,
Steven Valdez5b986082016-09-01 12:29:49 -04008208 },
8209 },
Steven Valdeza833c352016-11-01 13:39:36 -04008210 resumeSession: true,
8211 shouldFail: true,
8212 expectedLocalError: "tls: invalid ticket age",
Steven Valdez5b986082016-09-01 12:29:49 -04008213 })
8214
Steven Valdez5b986082016-09-01 12:29:49 -04008215}
8216
David Benjamin82261be2016-07-07 14:32:50 -07008217func addChangeCipherSpecTests() {
8218 // Test missing ChangeCipherSpecs.
8219 testCases = append(testCases, testCase{
8220 name: "SkipChangeCipherSpec-Client",
8221 config: Config{
8222 MaxVersion: VersionTLS12,
8223 Bugs: ProtocolBugs{
8224 SkipChangeCipherSpec: true,
8225 },
8226 },
8227 shouldFail: true,
8228 expectedError: ":UNEXPECTED_RECORD:",
8229 })
8230 testCases = append(testCases, testCase{
8231 testType: serverTest,
8232 name: "SkipChangeCipherSpec-Server",
8233 config: Config{
8234 MaxVersion: VersionTLS12,
8235 Bugs: ProtocolBugs{
8236 SkipChangeCipherSpec: true,
8237 },
8238 },
8239 shouldFail: true,
8240 expectedError: ":UNEXPECTED_RECORD:",
8241 })
8242 testCases = append(testCases, testCase{
8243 testType: serverTest,
8244 name: "SkipChangeCipherSpec-Server-NPN",
8245 config: Config{
8246 MaxVersion: VersionTLS12,
8247 NextProtos: []string{"bar"},
8248 Bugs: ProtocolBugs{
8249 SkipChangeCipherSpec: true,
8250 },
8251 },
8252 flags: []string{
8253 "-advertise-npn", "\x03foo\x03bar\x03baz",
8254 },
8255 shouldFail: true,
8256 expectedError: ":UNEXPECTED_RECORD:",
8257 })
8258
8259 // Test synchronization between the handshake and ChangeCipherSpec.
8260 // Partial post-CCS handshake messages before ChangeCipherSpec should be
8261 // rejected. Test both with and without handshake packing to handle both
8262 // when the partial post-CCS message is in its own record and when it is
8263 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07008264 for _, packed := range []bool{false, true} {
8265 var suffix string
8266 if packed {
8267 suffix = "-Packed"
8268 }
8269
8270 testCases = append(testCases, testCase{
8271 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
8272 config: Config{
8273 MaxVersion: VersionTLS12,
8274 Bugs: ProtocolBugs{
8275 FragmentAcrossChangeCipherSpec: true,
8276 PackHandshakeFlight: packed,
8277 },
8278 },
8279 shouldFail: true,
8280 expectedError: ":UNEXPECTED_RECORD:",
8281 })
8282 testCases = append(testCases, testCase{
8283 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
8284 config: Config{
8285 MaxVersion: VersionTLS12,
8286 },
8287 resumeSession: true,
8288 resumeConfig: &Config{
8289 MaxVersion: VersionTLS12,
8290 Bugs: ProtocolBugs{
8291 FragmentAcrossChangeCipherSpec: true,
8292 PackHandshakeFlight: packed,
8293 },
8294 },
8295 shouldFail: true,
8296 expectedError: ":UNEXPECTED_RECORD:",
8297 })
8298 testCases = append(testCases, testCase{
8299 testType: serverTest,
8300 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
8301 config: Config{
8302 MaxVersion: VersionTLS12,
8303 Bugs: ProtocolBugs{
8304 FragmentAcrossChangeCipherSpec: true,
8305 PackHandshakeFlight: packed,
8306 },
8307 },
8308 shouldFail: true,
8309 expectedError: ":UNEXPECTED_RECORD:",
8310 })
8311 testCases = append(testCases, testCase{
8312 testType: serverTest,
8313 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
8314 config: Config{
8315 MaxVersion: VersionTLS12,
8316 },
8317 resumeSession: true,
8318 resumeConfig: &Config{
8319 MaxVersion: VersionTLS12,
8320 Bugs: ProtocolBugs{
8321 FragmentAcrossChangeCipherSpec: true,
8322 PackHandshakeFlight: packed,
8323 },
8324 },
8325 shouldFail: true,
8326 expectedError: ":UNEXPECTED_RECORD:",
8327 })
8328 testCases = append(testCases, testCase{
8329 testType: serverTest,
8330 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
8331 config: Config{
8332 MaxVersion: VersionTLS12,
8333 NextProtos: []string{"bar"},
8334 Bugs: ProtocolBugs{
8335 FragmentAcrossChangeCipherSpec: true,
8336 PackHandshakeFlight: packed,
8337 },
8338 },
8339 flags: []string{
8340 "-advertise-npn", "\x03foo\x03bar\x03baz",
8341 },
8342 shouldFail: true,
8343 expectedError: ":UNEXPECTED_RECORD:",
8344 })
8345 }
8346
David Benjamin61672812016-07-14 23:10:43 -04008347 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
8348 // messages in the handshake queue. Do this by testing the server
8349 // reading the client Finished, reversing the flight so Finished comes
8350 // first.
8351 testCases = append(testCases, testCase{
8352 protocol: dtls,
8353 testType: serverTest,
8354 name: "SendUnencryptedFinished-DTLS",
8355 config: Config{
8356 MaxVersion: VersionTLS12,
8357 Bugs: ProtocolBugs{
8358 SendUnencryptedFinished: true,
8359 ReverseHandshakeFragments: true,
8360 },
8361 },
8362 shouldFail: true,
8363 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8364 })
8365
Steven Valdez143e8b32016-07-11 13:19:03 -04008366 // Test synchronization between encryption changes and the handshake in
8367 // TLS 1.3, where ChangeCipherSpec is implicit.
8368 testCases = append(testCases, testCase{
8369 name: "PartialEncryptedExtensionsWithServerHello",
8370 config: Config{
8371 MaxVersion: VersionTLS13,
8372 Bugs: ProtocolBugs{
8373 PartialEncryptedExtensionsWithServerHello: true,
8374 },
8375 },
8376 shouldFail: true,
8377 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8378 })
8379 testCases = append(testCases, testCase{
8380 testType: serverTest,
8381 name: "PartialClientFinishedWithClientHello",
8382 config: Config{
8383 MaxVersion: VersionTLS13,
8384 Bugs: ProtocolBugs{
8385 PartialClientFinishedWithClientHello: true,
8386 },
8387 },
8388 shouldFail: true,
8389 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
8390 })
8391
David Benjamin82261be2016-07-07 14:32:50 -07008392 // Test that early ChangeCipherSpecs are handled correctly.
8393 testCases = append(testCases, testCase{
8394 testType: serverTest,
8395 name: "EarlyChangeCipherSpec-server-1",
8396 config: Config{
8397 MaxVersion: VersionTLS12,
8398 Bugs: ProtocolBugs{
8399 EarlyChangeCipherSpec: 1,
8400 },
8401 },
8402 shouldFail: true,
8403 expectedError: ":UNEXPECTED_RECORD:",
8404 })
8405 testCases = append(testCases, testCase{
8406 testType: serverTest,
8407 name: "EarlyChangeCipherSpec-server-2",
8408 config: Config{
8409 MaxVersion: VersionTLS12,
8410 Bugs: ProtocolBugs{
8411 EarlyChangeCipherSpec: 2,
8412 },
8413 },
8414 shouldFail: true,
8415 expectedError: ":UNEXPECTED_RECORD:",
8416 })
8417 testCases = append(testCases, testCase{
8418 protocol: dtls,
8419 name: "StrayChangeCipherSpec",
8420 config: Config{
8421 // TODO(davidben): Once DTLS 1.3 exists, test
8422 // that stray ChangeCipherSpec messages are
8423 // rejected.
8424 MaxVersion: VersionTLS12,
8425 Bugs: ProtocolBugs{
8426 StrayChangeCipherSpec: true,
8427 },
8428 },
8429 })
8430
8431 // Test that the contents of ChangeCipherSpec are checked.
8432 testCases = append(testCases, testCase{
8433 name: "BadChangeCipherSpec-1",
8434 config: Config{
8435 MaxVersion: VersionTLS12,
8436 Bugs: ProtocolBugs{
8437 BadChangeCipherSpec: []byte{2},
8438 },
8439 },
8440 shouldFail: true,
8441 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8442 })
8443 testCases = append(testCases, testCase{
8444 name: "BadChangeCipherSpec-2",
8445 config: Config{
8446 MaxVersion: VersionTLS12,
8447 Bugs: ProtocolBugs{
8448 BadChangeCipherSpec: []byte{1, 1},
8449 },
8450 },
8451 shouldFail: true,
8452 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8453 })
8454 testCases = append(testCases, testCase{
8455 protocol: dtls,
8456 name: "BadChangeCipherSpec-DTLS-1",
8457 config: Config{
8458 MaxVersion: VersionTLS12,
8459 Bugs: ProtocolBugs{
8460 BadChangeCipherSpec: []byte{2},
8461 },
8462 },
8463 shouldFail: true,
8464 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8465 })
8466 testCases = append(testCases, testCase{
8467 protocol: dtls,
8468 name: "BadChangeCipherSpec-DTLS-2",
8469 config: Config{
8470 MaxVersion: VersionTLS12,
8471 Bugs: ProtocolBugs{
8472 BadChangeCipherSpec: []byte{1, 1},
8473 },
8474 },
8475 shouldFail: true,
8476 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
8477 })
8478}
8479
David Benjamincd2c8062016-09-09 11:28:16 -04008480type perMessageTest struct {
8481 messageType uint8
8482 test testCase
8483}
8484
8485// makePerMessageTests returns a series of test templates which cover each
8486// message in the TLS handshake. These may be used with bugs like
8487// WrongMessageType to fully test a per-message bug.
8488func makePerMessageTests() []perMessageTest {
8489 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04008490 for _, protocol := range []protocol{tls, dtls} {
8491 var suffix string
8492 if protocol == dtls {
8493 suffix = "-DTLS"
8494 }
8495
David Benjamincd2c8062016-09-09 11:28:16 -04008496 ret = append(ret, perMessageTest{
8497 messageType: typeClientHello,
8498 test: testCase{
8499 protocol: protocol,
8500 testType: serverTest,
8501 name: "ClientHello" + suffix,
8502 config: Config{
8503 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008504 },
8505 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008506 })
8507
8508 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008509 ret = append(ret, perMessageTest{
8510 messageType: typeHelloVerifyRequest,
8511 test: testCase{
8512 protocol: protocol,
8513 name: "HelloVerifyRequest" + suffix,
8514 config: Config{
8515 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008516 },
8517 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008518 })
8519 }
8520
David Benjamincd2c8062016-09-09 11:28:16 -04008521 ret = append(ret, perMessageTest{
8522 messageType: typeServerHello,
8523 test: testCase{
8524 protocol: protocol,
8525 name: "ServerHello" + suffix,
8526 config: Config{
8527 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008528 },
8529 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008530 })
8531
David Benjamincd2c8062016-09-09 11:28:16 -04008532 ret = append(ret, perMessageTest{
8533 messageType: typeCertificate,
8534 test: testCase{
8535 protocol: protocol,
8536 name: "ServerCertificate" + suffix,
8537 config: Config{
8538 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008539 },
8540 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008541 })
8542
David Benjamincd2c8062016-09-09 11:28:16 -04008543 ret = append(ret, perMessageTest{
8544 messageType: typeCertificateStatus,
8545 test: testCase{
8546 protocol: protocol,
8547 name: "CertificateStatus" + suffix,
8548 config: Config{
8549 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008550 },
David Benjamincd2c8062016-09-09 11:28:16 -04008551 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008552 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008553 })
8554
David Benjamincd2c8062016-09-09 11:28:16 -04008555 ret = append(ret, perMessageTest{
8556 messageType: typeServerKeyExchange,
8557 test: testCase{
8558 protocol: protocol,
8559 name: "ServerKeyExchange" + suffix,
8560 config: Config{
8561 MaxVersion: VersionTLS12,
8562 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008563 },
8564 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008565 })
8566
David Benjamincd2c8062016-09-09 11:28:16 -04008567 ret = append(ret, perMessageTest{
8568 messageType: typeCertificateRequest,
8569 test: testCase{
8570 protocol: protocol,
8571 name: "CertificateRequest" + suffix,
8572 config: Config{
8573 MaxVersion: VersionTLS12,
8574 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008575 },
8576 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008577 })
8578
David Benjamincd2c8062016-09-09 11:28:16 -04008579 ret = append(ret, perMessageTest{
8580 messageType: typeServerHelloDone,
8581 test: testCase{
8582 protocol: protocol,
8583 name: "ServerHelloDone" + suffix,
8584 config: Config{
8585 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008586 },
8587 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008588 })
8589
David Benjamincd2c8062016-09-09 11:28:16 -04008590 ret = append(ret, perMessageTest{
8591 messageType: typeCertificate,
8592 test: testCase{
8593 testType: serverTest,
8594 protocol: protocol,
8595 name: "ClientCertificate" + suffix,
8596 config: Config{
8597 Certificates: []Certificate{rsaCertificate},
8598 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008599 },
David Benjamincd2c8062016-09-09 11:28:16 -04008600 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008601 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008602 })
8603
David Benjamincd2c8062016-09-09 11:28:16 -04008604 ret = append(ret, perMessageTest{
8605 messageType: typeCertificateVerify,
8606 test: testCase{
8607 testType: serverTest,
8608 protocol: protocol,
8609 name: "CertificateVerify" + suffix,
8610 config: Config{
8611 Certificates: []Certificate{rsaCertificate},
8612 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008613 },
David Benjamincd2c8062016-09-09 11:28:16 -04008614 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008615 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008616 })
8617
David Benjamincd2c8062016-09-09 11:28:16 -04008618 ret = append(ret, perMessageTest{
8619 messageType: typeClientKeyExchange,
8620 test: testCase{
8621 testType: serverTest,
8622 protocol: protocol,
8623 name: "ClientKeyExchange" + suffix,
8624 config: Config{
8625 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008626 },
8627 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008628 })
8629
8630 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008631 ret = append(ret, perMessageTest{
8632 messageType: typeNextProtocol,
8633 test: testCase{
8634 testType: serverTest,
8635 protocol: protocol,
8636 name: "NextProtocol" + suffix,
8637 config: Config{
8638 MaxVersion: VersionTLS12,
8639 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008640 },
David Benjamincd2c8062016-09-09 11:28:16 -04008641 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008642 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008643 })
8644
David Benjamincd2c8062016-09-09 11:28:16 -04008645 ret = append(ret, perMessageTest{
8646 messageType: typeChannelID,
8647 test: testCase{
8648 testType: serverTest,
8649 protocol: protocol,
8650 name: "ChannelID" + suffix,
8651 config: Config{
8652 MaxVersion: VersionTLS12,
8653 ChannelID: channelIDKey,
8654 },
8655 flags: []string{
8656 "-expect-channel-id",
8657 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008658 },
8659 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008660 })
8661 }
8662
David Benjamincd2c8062016-09-09 11:28:16 -04008663 ret = append(ret, perMessageTest{
8664 messageType: typeFinished,
8665 test: testCase{
8666 testType: serverTest,
8667 protocol: protocol,
8668 name: "ClientFinished" + suffix,
8669 config: Config{
8670 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008671 },
8672 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008673 })
8674
David Benjamincd2c8062016-09-09 11:28:16 -04008675 ret = append(ret, perMessageTest{
8676 messageType: typeNewSessionTicket,
8677 test: testCase{
8678 protocol: protocol,
8679 name: "NewSessionTicket" + suffix,
8680 config: Config{
8681 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008682 },
8683 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008684 })
8685
David Benjamincd2c8062016-09-09 11:28:16 -04008686 ret = append(ret, perMessageTest{
8687 messageType: typeFinished,
8688 test: testCase{
8689 protocol: protocol,
8690 name: "ServerFinished" + suffix,
8691 config: Config{
8692 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008693 },
8694 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008695 })
8696
8697 }
David Benjamincd2c8062016-09-09 11:28:16 -04008698
8699 ret = append(ret, perMessageTest{
8700 messageType: typeClientHello,
8701 test: testCase{
8702 testType: serverTest,
8703 name: "TLS13-ClientHello",
8704 config: Config{
8705 MaxVersion: VersionTLS13,
8706 },
8707 },
8708 })
8709
8710 ret = append(ret, perMessageTest{
8711 messageType: typeServerHello,
8712 test: testCase{
8713 name: "TLS13-ServerHello",
8714 config: Config{
8715 MaxVersion: VersionTLS13,
8716 },
8717 },
8718 })
8719
8720 ret = append(ret, perMessageTest{
8721 messageType: typeEncryptedExtensions,
8722 test: testCase{
8723 name: "TLS13-EncryptedExtensions",
8724 config: Config{
8725 MaxVersion: VersionTLS13,
8726 },
8727 },
8728 })
8729
8730 ret = append(ret, perMessageTest{
8731 messageType: typeCertificateRequest,
8732 test: testCase{
8733 name: "TLS13-CertificateRequest",
8734 config: Config{
8735 MaxVersion: VersionTLS13,
8736 ClientAuth: RequireAnyClientCert,
8737 },
8738 },
8739 })
8740
8741 ret = append(ret, perMessageTest{
8742 messageType: typeCertificate,
8743 test: testCase{
8744 name: "TLS13-ServerCertificate",
8745 config: Config{
8746 MaxVersion: VersionTLS13,
8747 },
8748 },
8749 })
8750
8751 ret = append(ret, perMessageTest{
8752 messageType: typeCertificateVerify,
8753 test: testCase{
8754 name: "TLS13-ServerCertificateVerify",
8755 config: Config{
8756 MaxVersion: VersionTLS13,
8757 },
8758 },
8759 })
8760
8761 ret = append(ret, perMessageTest{
8762 messageType: typeFinished,
8763 test: testCase{
8764 name: "TLS13-ServerFinished",
8765 config: Config{
8766 MaxVersion: VersionTLS13,
8767 },
8768 },
8769 })
8770
8771 ret = append(ret, perMessageTest{
8772 messageType: typeCertificate,
8773 test: testCase{
8774 testType: serverTest,
8775 name: "TLS13-ClientCertificate",
8776 config: Config{
8777 Certificates: []Certificate{rsaCertificate},
8778 MaxVersion: VersionTLS13,
8779 },
8780 flags: []string{"-require-any-client-certificate"},
8781 },
8782 })
8783
8784 ret = append(ret, perMessageTest{
8785 messageType: typeCertificateVerify,
8786 test: testCase{
8787 testType: serverTest,
8788 name: "TLS13-ClientCertificateVerify",
8789 config: Config{
8790 Certificates: []Certificate{rsaCertificate},
8791 MaxVersion: VersionTLS13,
8792 },
8793 flags: []string{"-require-any-client-certificate"},
8794 },
8795 })
8796
8797 ret = append(ret, perMessageTest{
8798 messageType: typeFinished,
8799 test: testCase{
8800 testType: serverTest,
8801 name: "TLS13-ClientFinished",
8802 config: Config{
8803 MaxVersion: VersionTLS13,
8804 },
8805 },
8806 })
8807
8808 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008809}
8810
David Benjamincd2c8062016-09-09 11:28:16 -04008811func addWrongMessageTypeTests() {
8812 for _, t := range makePerMessageTests() {
8813 t.test.name = "WrongMessageType-" + t.test.name
8814 t.test.config.Bugs.SendWrongMessageType = t.messageType
8815 t.test.shouldFail = true
8816 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8817 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008818
David Benjamincd2c8062016-09-09 11:28:16 -04008819 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8820 // In TLS 1.3, a bad ServerHello means the client sends
8821 // an unencrypted alert while the server expects
8822 // encryption, so the alert is not readable by runner.
8823 t.test.expectedLocalError = "local error: bad record MAC"
8824 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008825
David Benjamincd2c8062016-09-09 11:28:16 -04008826 testCases = append(testCases, t.test)
8827 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008828}
8829
David Benjamin639846e2016-09-09 11:41:18 -04008830func addTrailingMessageDataTests() {
8831 for _, t := range makePerMessageTests() {
8832 t.test.name = "TrailingMessageData-" + t.test.name
8833 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8834 t.test.shouldFail = true
8835 t.test.expectedError = ":DECODE_ERROR:"
8836 t.test.expectedLocalError = "remote error: error decoding message"
8837
8838 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8839 // In TLS 1.3, a bad ServerHello means the client sends
8840 // an unencrypted alert while the server expects
8841 // encryption, so the alert is not readable by runner.
8842 t.test.expectedLocalError = "local error: bad record MAC"
8843 }
8844
8845 if t.messageType == typeFinished {
8846 // Bad Finished messages read as the verify data having
8847 // the wrong length.
8848 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8849 t.test.expectedLocalError = "remote error: error decrypting message"
8850 }
8851
8852 testCases = append(testCases, t.test)
8853 }
8854}
8855
Steven Valdez143e8b32016-07-11 13:19:03 -04008856func addTLS13HandshakeTests() {
8857 testCases = append(testCases, testCase{
8858 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008859 name: "NegotiatePSKResumption-TLS13",
8860 config: Config{
8861 MaxVersion: VersionTLS13,
8862 Bugs: ProtocolBugs{
8863 NegotiatePSKResumption: true,
8864 },
8865 },
8866 resumeSession: true,
8867 shouldFail: true,
8868 expectedError: ":UNEXPECTED_EXTENSION:",
8869 })
8870
8871 testCases = append(testCases, testCase{
8872 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008873 name: "MissingKeyShare-Client",
8874 config: Config{
8875 MaxVersion: VersionTLS13,
8876 Bugs: ProtocolBugs{
8877 MissingKeyShare: true,
8878 },
8879 },
8880 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008881 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008882 })
8883
8884 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008885 testType: serverTest,
8886 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008887 config: Config{
8888 MaxVersion: VersionTLS13,
8889 Bugs: ProtocolBugs{
8890 MissingKeyShare: true,
8891 },
8892 },
8893 shouldFail: true,
8894 expectedError: ":MISSING_KEY_SHARE:",
8895 })
8896
8897 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008898 testType: serverTest,
8899 name: "DuplicateKeyShares",
8900 config: Config{
8901 MaxVersion: VersionTLS13,
8902 Bugs: ProtocolBugs{
8903 DuplicateKeyShares: true,
8904 },
8905 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008906 shouldFail: true,
8907 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008908 })
8909
8910 testCases = append(testCases, testCase{
8911 testType: clientTest,
8912 name: "EmptyEncryptedExtensions",
8913 config: Config{
8914 MaxVersion: VersionTLS13,
8915 Bugs: ProtocolBugs{
8916 EmptyEncryptedExtensions: true,
8917 },
8918 },
8919 shouldFail: true,
8920 expectedLocalError: "remote error: error decoding message",
8921 })
8922
8923 testCases = append(testCases, testCase{
8924 testType: clientTest,
8925 name: "EncryptedExtensionsWithKeyShare",
8926 config: Config{
8927 MaxVersion: VersionTLS13,
8928 Bugs: ProtocolBugs{
8929 EncryptedExtensionsWithKeyShare: true,
8930 },
8931 },
8932 shouldFail: true,
8933 expectedLocalError: "remote error: unsupported extension",
8934 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008935
8936 testCases = append(testCases, testCase{
8937 testType: serverTest,
8938 name: "SendHelloRetryRequest",
8939 config: Config{
8940 MaxVersion: VersionTLS13,
8941 // Require a HelloRetryRequest for every curve.
8942 DefaultCurves: []CurveID{},
8943 },
8944 expectedCurveID: CurveX25519,
8945 })
8946
8947 testCases = append(testCases, testCase{
8948 testType: serverTest,
8949 name: "SendHelloRetryRequest-2",
8950 config: Config{
8951 MaxVersion: VersionTLS13,
8952 DefaultCurves: []CurveID{CurveP384},
8953 },
8954 // Although the ClientHello did not predict our preferred curve,
8955 // we always select it whether it is predicted or not.
8956 expectedCurveID: CurveX25519,
8957 })
8958
8959 testCases = append(testCases, testCase{
8960 name: "UnknownCurve-HelloRetryRequest",
8961 config: Config{
8962 MaxVersion: VersionTLS13,
8963 // P-384 requires HelloRetryRequest in BoringSSL.
8964 CurvePreferences: []CurveID{CurveP384},
8965 Bugs: ProtocolBugs{
8966 SendHelloRetryRequestCurve: bogusCurve,
8967 },
8968 },
8969 shouldFail: true,
8970 expectedError: ":WRONG_CURVE:",
8971 })
8972
8973 testCases = append(testCases, testCase{
8974 name: "DisabledCurve-HelloRetryRequest",
8975 config: Config{
8976 MaxVersion: VersionTLS13,
8977 CurvePreferences: []CurveID{CurveP256},
8978 Bugs: ProtocolBugs{
8979 IgnorePeerCurvePreferences: true,
8980 },
8981 },
8982 flags: []string{"-p384-only"},
8983 shouldFail: true,
8984 expectedError: ":WRONG_CURVE:",
8985 })
8986
8987 testCases = append(testCases, testCase{
8988 name: "UnnecessaryHelloRetryRequest",
8989 config: Config{
David Benjamin3baa6e12016-10-07 21:10:38 -04008990 MaxVersion: VersionTLS13,
8991 CurvePreferences: []CurveID{CurveX25519},
Steven Valdez5440fe02016-07-18 12:40:30 -04008992 Bugs: ProtocolBugs{
David Benjamin3baa6e12016-10-07 21:10:38 -04008993 SendHelloRetryRequestCurve: CurveX25519,
Steven Valdez5440fe02016-07-18 12:40:30 -04008994 },
8995 },
8996 shouldFail: true,
8997 expectedError: ":WRONG_CURVE:",
8998 })
8999
9000 testCases = append(testCases, testCase{
9001 name: "SecondHelloRetryRequest",
9002 config: Config{
9003 MaxVersion: VersionTLS13,
9004 // P-384 requires HelloRetryRequest in BoringSSL.
9005 CurvePreferences: []CurveID{CurveP384},
9006 Bugs: ProtocolBugs{
9007 SecondHelloRetryRequest: true,
9008 },
9009 },
9010 shouldFail: true,
9011 expectedError: ":UNEXPECTED_MESSAGE:",
9012 })
9013
9014 testCases = append(testCases, testCase{
David Benjamin3baa6e12016-10-07 21:10:38 -04009015 name: "HelloRetryRequest-Empty",
9016 config: Config{
9017 MaxVersion: VersionTLS13,
9018 Bugs: ProtocolBugs{
9019 AlwaysSendHelloRetryRequest: true,
9020 },
9021 },
9022 shouldFail: true,
9023 expectedError: ":DECODE_ERROR:",
9024 })
9025
9026 testCases = append(testCases, testCase{
9027 name: "HelloRetryRequest-DuplicateCurve",
9028 config: Config{
9029 MaxVersion: VersionTLS13,
9030 // P-384 requires a HelloRetryRequest against BoringSSL's default
9031 // configuration. Assert this ExpectMissingKeyShare.
9032 CurvePreferences: []CurveID{CurveP384},
9033 Bugs: ProtocolBugs{
9034 ExpectMissingKeyShare: true,
9035 DuplicateHelloRetryRequestExtensions: true,
9036 },
9037 },
9038 shouldFail: true,
9039 expectedError: ":DUPLICATE_EXTENSION:",
9040 expectedLocalError: "remote error: illegal parameter",
9041 })
9042
9043 testCases = append(testCases, testCase{
9044 name: "HelloRetryRequest-Cookie",
9045 config: Config{
9046 MaxVersion: VersionTLS13,
9047 Bugs: ProtocolBugs{
9048 SendHelloRetryRequestCookie: []byte("cookie"),
9049 },
9050 },
9051 })
9052
9053 testCases = append(testCases, testCase{
9054 name: "HelloRetryRequest-DuplicateCookie",
9055 config: Config{
9056 MaxVersion: VersionTLS13,
9057 Bugs: ProtocolBugs{
9058 SendHelloRetryRequestCookie: []byte("cookie"),
9059 DuplicateHelloRetryRequestExtensions: true,
9060 },
9061 },
9062 shouldFail: true,
9063 expectedError: ":DUPLICATE_EXTENSION:",
9064 expectedLocalError: "remote error: illegal parameter",
9065 })
9066
9067 testCases = append(testCases, testCase{
9068 name: "HelloRetryRequest-EmptyCookie",
9069 config: Config{
9070 MaxVersion: VersionTLS13,
9071 Bugs: ProtocolBugs{
9072 SendHelloRetryRequestCookie: []byte{},
9073 },
9074 },
9075 shouldFail: true,
9076 expectedError: ":DECODE_ERROR:",
9077 })
9078
9079 testCases = append(testCases, testCase{
9080 name: "HelloRetryRequest-Cookie-Curve",
9081 config: Config{
9082 MaxVersion: VersionTLS13,
9083 // P-384 requires HelloRetryRequest in BoringSSL.
9084 CurvePreferences: []CurveID{CurveP384},
9085 Bugs: ProtocolBugs{
9086 SendHelloRetryRequestCookie: []byte("cookie"),
9087 ExpectMissingKeyShare: true,
9088 },
9089 },
9090 })
9091
9092 testCases = append(testCases, testCase{
9093 name: "HelloRetryRequest-Unknown",
9094 config: Config{
9095 MaxVersion: VersionTLS13,
9096 Bugs: ProtocolBugs{
9097 CustomHelloRetryRequestExtension: "extension",
9098 },
9099 },
9100 shouldFail: true,
9101 expectedError: ":UNEXPECTED_EXTENSION:",
9102 expectedLocalError: "remote error: unsupported extension",
9103 })
9104
9105 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04009106 testType: serverTest,
9107 name: "SecondClientHelloMissingKeyShare",
9108 config: Config{
9109 MaxVersion: VersionTLS13,
9110 DefaultCurves: []CurveID{},
9111 Bugs: ProtocolBugs{
9112 SecondClientHelloMissingKeyShare: true,
9113 },
9114 },
9115 shouldFail: true,
9116 expectedError: ":MISSING_KEY_SHARE:",
9117 })
9118
9119 testCases = append(testCases, testCase{
9120 testType: serverTest,
9121 name: "SecondClientHelloWrongCurve",
9122 config: Config{
9123 MaxVersion: VersionTLS13,
9124 DefaultCurves: []CurveID{},
9125 Bugs: ProtocolBugs{
9126 MisinterpretHelloRetryRequestCurve: CurveP521,
9127 },
9128 },
9129 shouldFail: true,
9130 expectedError: ":WRONG_CURVE:",
9131 })
9132
9133 testCases = append(testCases, testCase{
9134 name: "HelloRetryRequestVersionMismatch",
9135 config: Config{
9136 MaxVersion: VersionTLS13,
9137 // P-384 requires HelloRetryRequest in BoringSSL.
9138 CurvePreferences: []CurveID{CurveP384},
9139 Bugs: ProtocolBugs{
9140 SendServerHelloVersion: 0x0305,
9141 },
9142 },
9143 shouldFail: true,
9144 expectedError: ":WRONG_VERSION_NUMBER:",
9145 })
9146
9147 testCases = append(testCases, testCase{
9148 name: "HelloRetryRequestCurveMismatch",
9149 config: Config{
9150 MaxVersion: VersionTLS13,
9151 // P-384 requires HelloRetryRequest in BoringSSL.
9152 CurvePreferences: []CurveID{CurveP384},
9153 Bugs: ProtocolBugs{
9154 // Send P-384 (correct) in the HelloRetryRequest.
9155 SendHelloRetryRequestCurve: CurveP384,
9156 // But send P-256 in the ServerHello.
9157 SendCurve: CurveP256,
9158 },
9159 },
9160 shouldFail: true,
9161 expectedError: ":WRONG_CURVE:",
9162 })
9163
9164 // Test the server selecting a curve that requires a HelloRetryRequest
9165 // without sending it.
9166 testCases = append(testCases, testCase{
9167 name: "SkipHelloRetryRequest",
9168 config: Config{
9169 MaxVersion: VersionTLS13,
9170 // P-384 requires HelloRetryRequest in BoringSSL.
9171 CurvePreferences: []CurveID{CurveP384},
9172 Bugs: ProtocolBugs{
9173 SkipHelloRetryRequest: true,
9174 },
9175 },
9176 shouldFail: true,
9177 expectedError: ":WRONG_CURVE:",
9178 })
David Benjamin8a8349b2016-08-18 02:32:23 -04009179
9180 testCases = append(testCases, testCase{
9181 name: "TLS13-RequestContextInHandshake",
9182 config: Config{
9183 MaxVersion: VersionTLS13,
9184 MinVersion: VersionTLS13,
9185 ClientAuth: RequireAnyClientCert,
9186 Bugs: ProtocolBugs{
9187 SendRequestContext: []byte("request context"),
9188 },
9189 },
9190 flags: []string{
9191 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
9192 "-key-file", path.Join(*resourceDir, rsaKeyFile),
9193 },
9194 shouldFail: true,
9195 expectedError: ":DECODE_ERROR:",
9196 })
David Benjamin7e1f9842016-09-20 19:24:40 -04009197
9198 testCases = append(testCases, testCase{
9199 testType: serverTest,
9200 name: "TLS13-TrailingKeyShareData",
9201 config: Config{
9202 MaxVersion: VersionTLS13,
9203 Bugs: ProtocolBugs{
9204 TrailingKeyShareData: true,
9205 },
9206 },
9207 shouldFail: true,
9208 expectedError: ":DECODE_ERROR:",
9209 })
David Benjamin7f78df42016-10-05 22:33:19 -04009210
9211 testCases = append(testCases, testCase{
9212 name: "TLS13-AlwaysSelectPSKIdentity",
9213 config: Config{
9214 MaxVersion: VersionTLS13,
9215 Bugs: ProtocolBugs{
9216 AlwaysSelectPSKIdentity: true,
9217 },
9218 },
9219 shouldFail: true,
9220 expectedError: ":UNEXPECTED_EXTENSION:",
9221 })
9222
9223 testCases = append(testCases, testCase{
9224 name: "TLS13-InvalidPSKIdentity",
9225 config: Config{
9226 MaxVersion: VersionTLS13,
9227 Bugs: ProtocolBugs{
9228 SelectPSKIdentityOnResume: 1,
9229 },
9230 },
9231 resumeSession: true,
9232 shouldFail: true,
9233 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
9234 })
David Benjamin1286bee2016-10-07 15:25:06 -04009235
Steven Valdezaf3b8a92016-11-01 12:49:22 -04009236 testCases = append(testCases, testCase{
9237 testType: serverTest,
9238 name: "TLS13-ExtraPSKIdentity",
9239 config: Config{
9240 MaxVersion: VersionTLS13,
9241 Bugs: ProtocolBugs{
9242 ExtraPSKIdentity: true,
9243 },
9244 },
9245 resumeSession: true,
9246 })
9247
David Benjamin1286bee2016-10-07 15:25:06 -04009248 // Test that unknown NewSessionTicket extensions are tolerated.
9249 testCases = append(testCases, testCase{
9250 name: "TLS13-CustomTicketExtension",
9251 config: Config{
9252 MaxVersion: VersionTLS13,
9253 Bugs: ProtocolBugs{
9254 CustomTicketExtension: "1234",
9255 },
9256 },
9257 })
Steven Valdez143e8b32016-07-11 13:19:03 -04009258}
9259
David Benjaminabbbee12016-10-31 19:20:42 -04009260func addTLS13CipherPreferenceTests() {
9261 // Test that client preference is honored if the shim has AES hardware
9262 // and ChaCha20-Poly1305 is preferred otherwise.
9263 testCases = append(testCases, testCase{
9264 testType: serverTest,
9265 name: "TLS13-CipherPreference-Server-ChaCha20-AES",
9266 config: Config{
9267 MaxVersion: VersionTLS13,
9268 CipherSuites: []uint16{
9269 TLS_CHACHA20_POLY1305_SHA256,
9270 TLS_AES_128_GCM_SHA256,
9271 },
9272 },
9273 flags: []string{
9274 "-expect-cipher-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9275 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9276 },
9277 })
9278
9279 testCases = append(testCases, testCase{
9280 testType: serverTest,
9281 name: "TLS13-CipherPreference-Server-AES-ChaCha20",
9282 config: Config{
9283 MaxVersion: VersionTLS13,
9284 CipherSuites: []uint16{
9285 TLS_AES_128_GCM_SHA256,
9286 TLS_CHACHA20_POLY1305_SHA256,
9287 },
9288 },
9289 flags: []string{
9290 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9291 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9292 },
9293 })
9294
9295 // Test that the client orders ChaCha20-Poly1305 and AES-GCM based on
9296 // whether it has AES hardware.
9297 testCases = append(testCases, testCase{
9298 name: "TLS13-CipherPreference-Client",
9299 config: Config{
9300 MaxVersion: VersionTLS13,
9301 // Use the client cipher order. (This is the default but
9302 // is listed to be explicit.)
9303 PreferServerCipherSuites: false,
9304 },
9305 flags: []string{
9306 "-expect-cipher-aes", strconv.Itoa(int(TLS_AES_128_GCM_SHA256)),
9307 "-expect-cipher-no-aes", strconv.Itoa(int(TLS_CHACHA20_POLY1305_SHA256)),
9308 },
9309 })
9310}
9311
David Benjaminf3fbade2016-09-19 13:08:16 -04009312func addPeekTests() {
9313 // Test SSL_peek works, including on empty records.
9314 testCases = append(testCases, testCase{
9315 name: "Peek-Basic",
9316 sendEmptyRecords: 1,
9317 flags: []string{"-peek-then-read"},
9318 })
9319
9320 // Test SSL_peek can drive the initial handshake.
9321 testCases = append(testCases, testCase{
9322 name: "Peek-ImplicitHandshake",
9323 flags: []string{
9324 "-peek-then-read",
9325 "-implicit-handshake",
9326 },
9327 })
9328
9329 // Test SSL_peek can discover and drive a renegotiation.
9330 testCases = append(testCases, testCase{
9331 name: "Peek-Renegotiate",
9332 config: Config{
9333 MaxVersion: VersionTLS12,
9334 },
9335 renegotiate: 1,
9336 flags: []string{
9337 "-peek-then-read",
9338 "-renegotiate-freely",
9339 "-expect-total-renegotiations", "1",
9340 },
9341 })
9342
9343 // Test SSL_peek can discover a close_notify.
9344 testCases = append(testCases, testCase{
9345 name: "Peek-Shutdown",
9346 config: Config{
9347 Bugs: ProtocolBugs{
9348 ExpectCloseNotify: true,
9349 },
9350 },
9351 flags: []string{
9352 "-peek-then-read",
9353 "-check-close-notify",
9354 },
9355 })
9356
9357 // Test SSL_peek can discover an alert.
9358 testCases = append(testCases, testCase{
9359 name: "Peek-Alert",
9360 config: Config{
9361 Bugs: ProtocolBugs{
9362 SendSpuriousAlert: alertRecordOverflow,
9363 },
9364 },
9365 flags: []string{"-peek-then-read"},
9366 shouldFail: true,
9367 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
9368 })
9369
9370 // Test SSL_peek can handle KeyUpdate.
9371 testCases = append(testCases, testCase{
9372 name: "Peek-KeyUpdate",
9373 config: Config{
9374 MaxVersion: VersionTLS13,
David Benjaminf3fbade2016-09-19 13:08:16 -04009375 },
Steven Valdezc4aa7272016-10-03 12:25:56 -04009376 sendKeyUpdates: 1,
9377 keyUpdateRequest: keyUpdateNotRequested,
9378 flags: []string{"-peek-then-read"},
David Benjaminf3fbade2016-09-19 13:08:16 -04009379 })
9380}
9381
David Benjamine6f22212016-11-08 14:28:24 -05009382func addRecordVersionTests() {
9383 for _, ver := range tlsVersions {
9384 // Test that the record version is enforced.
9385 testCases = append(testCases, testCase{
9386 name: "CheckRecordVersion-" + ver.name,
9387 config: Config{
9388 MinVersion: ver.version,
9389 MaxVersion: ver.version,
9390 Bugs: ProtocolBugs{
9391 SendRecordVersion: 0x03ff,
9392 },
9393 },
9394 shouldFail: true,
9395 expectedError: ":WRONG_VERSION_NUMBER:",
9396 })
9397
9398 // Test that the ClientHello may use any record version, for
9399 // compatibility reasons.
9400 testCases = append(testCases, testCase{
9401 testType: serverTest,
9402 name: "LooseInitialRecordVersion-" + ver.name,
9403 config: Config{
9404 MinVersion: ver.version,
9405 MaxVersion: ver.version,
9406 Bugs: ProtocolBugs{
9407 SendInitialRecordVersion: 0x03ff,
9408 },
9409 },
9410 })
9411
9412 // Test that garbage ClientHello record versions are rejected.
9413 testCases = append(testCases, testCase{
9414 testType: serverTest,
9415 name: "GarbageInitialRecordVersion-" + ver.name,
9416 config: Config{
9417 MinVersion: ver.version,
9418 MaxVersion: ver.version,
9419 Bugs: ProtocolBugs{
9420 SendInitialRecordVersion: 0xffff,
9421 },
9422 },
9423 shouldFail: true,
9424 expectedError: ":WRONG_VERSION_NUMBER:",
9425 })
9426 }
9427}
9428
David Benjamin2c516452016-11-15 10:16:54 +09009429func addCertificateTests() {
9430 // Test that a certificate chain with intermediate may be sent and
9431 // received as both client and server.
9432 for _, ver := range tlsVersions {
9433 testCases = append(testCases, testCase{
9434 testType: clientTest,
9435 name: "SendReceiveIntermediate-Client-" + ver.name,
9436 config: Config{
9437 Certificates: []Certificate{rsaChainCertificate},
9438 ClientAuth: RequireAnyClientCert,
9439 },
9440 expectPeerCertificate: &rsaChainCertificate,
9441 flags: []string{
9442 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9443 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9444 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9445 },
9446 })
9447
9448 testCases = append(testCases, testCase{
9449 testType: serverTest,
9450 name: "SendReceiveIntermediate-Server-" + ver.name,
9451 config: Config{
9452 Certificates: []Certificate{rsaChainCertificate},
9453 },
9454 expectPeerCertificate: &rsaChainCertificate,
9455 flags: []string{
9456 "-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9457 "-key-file", path.Join(*resourceDir, rsaChainKeyFile),
9458 "-require-any-client-certificate",
9459 "-expect-peer-cert-file", path.Join(*resourceDir, rsaChainCertificateFile),
9460 },
9461 })
9462 }
9463}
9464
Adam Langley7c803a62015-06-15 15:35:05 -07009465func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07009466 defer wg.Done()
9467
9468 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08009469 var err error
9470
9471 if *mallocTest < 0 {
9472 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009473 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08009474 } else {
9475 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
9476 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07009477 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08009478 if err != nil {
9479 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
9480 }
9481 break
9482 }
9483 }
9484 }
Adam Langley95c29f32014-06-20 12:00:00 -07009485 statusChan <- statusMsg{test: test, err: err}
9486 }
9487}
9488
9489type statusMsg struct {
9490 test *testCase
9491 started bool
9492 err error
9493}
9494
David Benjamin5f237bc2015-02-11 17:14:15 -05009495func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02009496 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07009497
David Benjamin5f237bc2015-02-11 17:14:15 -05009498 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07009499 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05009500 if !*pipe {
9501 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05009502 var erase string
9503 for i := 0; i < lineLen; i++ {
9504 erase += "\b \b"
9505 }
9506 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05009507 }
9508
Adam Langley95c29f32014-06-20 12:00:00 -07009509 if msg.started {
9510 started++
9511 } else {
9512 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05009513
9514 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02009515 if msg.err == errUnimplemented {
9516 if *pipe {
9517 // Print each test instead of a status line.
9518 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
9519 }
9520 unimplemented++
9521 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
9522 } else {
9523 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
9524 failed++
9525 testOutput.addResult(msg.test.name, "FAIL")
9526 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009527 } else {
9528 if *pipe {
9529 // Print each test instead of a status line.
9530 fmt.Printf("PASSED (%s)\n", msg.test.name)
9531 }
9532 testOutput.addResult(msg.test.name, "PASS")
9533 }
Adam Langley95c29f32014-06-20 12:00:00 -07009534 }
9535
David Benjamin5f237bc2015-02-11 17:14:15 -05009536 if !*pipe {
9537 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02009538 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05009539 lineLen = len(line)
9540 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07009541 }
Adam Langley95c29f32014-06-20 12:00:00 -07009542 }
David Benjamin5f237bc2015-02-11 17:14:15 -05009543
9544 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07009545}
9546
9547func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07009548 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07009549 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07009550 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07009551
Adam Langley7c803a62015-06-15 15:35:05 -07009552 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009553 addCipherSuiteTests()
9554 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07009555 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07009556 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04009557 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08009558 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04009559 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05009560 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04009561 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04009562 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07009563 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07009564 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05009565 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07009566 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05009567 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04009568 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07009569 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07009570 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05009571 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05009572 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07009573 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04009574 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04009575 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04009576 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07009577 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07009578 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04009579 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04009580 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04009581 addTLS13HandshakeTests()
David Benjaminabbbee12016-10-31 19:20:42 -04009582 addTLS13CipherPreferenceTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04009583 addPeekTests()
David Benjamine6f22212016-11-08 14:28:24 -05009584 addRecordVersionTests()
David Benjamin2c516452016-11-15 10:16:54 +09009585 addCertificateTests()
Adam Langley95c29f32014-06-20 12:00:00 -07009586
9587 var wg sync.WaitGroup
9588
Adam Langley7c803a62015-06-15 15:35:05 -07009589 statusChan := make(chan statusMsg, *numWorkers)
9590 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05009591 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07009592
EKRf71d7ed2016-08-06 13:25:12 -07009593 if len(*shimConfigFile) != 0 {
9594 encoded, err := ioutil.ReadFile(*shimConfigFile)
9595 if err != nil {
9596 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
9597 os.Exit(1)
9598 }
9599
9600 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
9601 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
9602 os.Exit(1)
9603 }
9604 }
9605
David Benjamin025b3d32014-07-01 19:53:04 -04009606 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07009607
Adam Langley7c803a62015-06-15 15:35:05 -07009608 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07009609 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07009610 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07009611 }
9612
David Benjamin270f0a72016-03-17 14:41:36 -04009613 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04009614 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04009615 matched := true
9616 if len(*testToRun) != 0 {
9617 var err error
9618 matched, err = filepath.Match(*testToRun, testCases[i].name)
9619 if err != nil {
9620 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
9621 os.Exit(1)
9622 }
9623 }
9624
EKRf71d7ed2016-08-06 13:25:12 -07009625 if !*includeDisabled {
9626 for pattern := range shimConfig.DisabledTests {
9627 isDisabled, err := filepath.Match(pattern, testCases[i].name)
9628 if err != nil {
9629 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
9630 os.Exit(1)
9631 }
9632
9633 if isDisabled {
9634 matched = false
9635 break
9636 }
9637 }
9638 }
9639
David Benjamin17e12922016-07-28 18:04:43 -04009640 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04009641 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04009642 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07009643 }
9644 }
David Benjamin17e12922016-07-28 18:04:43 -04009645
David Benjamin270f0a72016-03-17 14:41:36 -04009646 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07009647 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04009648 os.Exit(1)
9649 }
Adam Langley95c29f32014-06-20 12:00:00 -07009650
9651 close(testChan)
9652 wg.Wait()
9653 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05009654 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07009655
9656 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05009657
9658 if *jsonOutput != "" {
9659 if err := testOutput.writeTo(*jsonOutput); err != nil {
9660 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
9661 }
9662 }
David Benjamin2ab7a862015-04-04 17:02:18 -04009663
EKR842ae6c2016-07-27 09:22:05 +02009664 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
9665 os.Exit(1)
9666 }
9667
9668 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04009669 os.Exit(1)
9670 }
Adam Langley95c29f32014-06-20 12:00:00 -07009671}