blob: fe2cf84708bec7968f40a0e7733f049037599a61 [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 Benjamin33863262016-07-08 17:20:12 -070090 testCertECDSAP256
91 testCertECDSAP384
92 testCertECDSAP521
93)
94
95const (
96 rsaCertificateFile = "cert.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -040097 rsa1024CertificateFile = "rsa_1024_cert.pem"
David Benjamin33863262016-07-08 17:20:12 -070098 ecdsaP256CertificateFile = "ecdsa_p256_cert.pem"
99 ecdsaP384CertificateFile = "ecdsa_p384_cert.pem"
100 ecdsaP521CertificateFile = "ecdsa_p521_cert.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400101)
102
103const (
David Benjamina08e49d2014-08-24 01:46:07 -0400104 rsaKeyFile = "key.pem"
David Benjamin7944a9f2016-07-12 22:27:01 -0400105 rsa1024KeyFile = "rsa_1024_key.pem"
David Benjamin33863262016-07-08 17:20:12 -0700106 ecdsaP256KeyFile = "ecdsa_p256_key.pem"
107 ecdsaP384KeyFile = "ecdsa_p384_key.pem"
108 ecdsaP521KeyFile = "ecdsa_p521_key.pem"
David Benjamina08e49d2014-08-24 01:46:07 -0400109 channelIDKeyFile = "channel_id_key.pem"
David Benjamin025b3d32014-07-01 19:53:04 -0400110)
111
David Benjamin7944a9f2016-07-12 22:27:01 -0400112var (
113 rsaCertificate Certificate
114 rsa1024Certificate Certificate
115 ecdsaP256Certificate Certificate
116 ecdsaP384Certificate Certificate
117 ecdsaP521Certificate Certificate
118)
David Benjamin33863262016-07-08 17:20:12 -0700119
120var testCerts = []struct {
121 id testCert
122 certFile, keyFile string
123 cert *Certificate
124}{
125 {
126 id: testCertRSA,
127 certFile: rsaCertificateFile,
128 keyFile: rsaKeyFile,
129 cert: &rsaCertificate,
130 },
131 {
David Benjamin7944a9f2016-07-12 22:27:01 -0400132 id: testCertRSA1024,
133 certFile: rsa1024CertificateFile,
134 keyFile: rsa1024KeyFile,
135 cert: &rsa1024Certificate,
136 },
137 {
David Benjamin33863262016-07-08 17:20:12 -0700138 id: testCertECDSAP256,
139 certFile: ecdsaP256CertificateFile,
140 keyFile: ecdsaP256KeyFile,
141 cert: &ecdsaP256Certificate,
142 },
143 {
144 id: testCertECDSAP384,
145 certFile: ecdsaP384CertificateFile,
146 keyFile: ecdsaP384KeyFile,
147 cert: &ecdsaP384Certificate,
148 },
149 {
150 id: testCertECDSAP521,
151 certFile: ecdsaP521CertificateFile,
152 keyFile: ecdsaP521KeyFile,
153 cert: &ecdsaP521Certificate,
154 },
155}
156
David Benjamina08e49d2014-08-24 01:46:07 -0400157var channelIDKey *ecdsa.PrivateKey
158var channelIDBytes []byte
Adam Langley95c29f32014-06-20 12:00:00 -0700159
David Benjamin61f95272014-11-25 01:55:35 -0500160var testOCSPResponse = []byte{1, 2, 3, 4}
161var testSCTList = []byte{5, 6, 7, 8}
162
Adam Langley95c29f32014-06-20 12:00:00 -0700163func initCertificates() {
David Benjamin33863262016-07-08 17:20:12 -0700164 for i := range testCerts {
165 cert, err := LoadX509KeyPair(path.Join(*resourceDir, testCerts[i].certFile), path.Join(*resourceDir, testCerts[i].keyFile))
166 if err != nil {
167 panic(err)
168 }
169 cert.OCSPStaple = testOCSPResponse
170 cert.SignedCertificateTimestampList = testSCTList
171 *testCerts[i].cert = cert
Adam Langley95c29f32014-06-20 12:00:00 -0700172 }
David Benjamina08e49d2014-08-24 01:46:07 -0400173
Adam Langley7c803a62015-06-15 15:35:05 -0700174 channelIDPEMBlock, err := ioutil.ReadFile(path.Join(*resourceDir, channelIDKeyFile))
David Benjamina08e49d2014-08-24 01:46:07 -0400175 if err != nil {
176 panic(err)
177 }
178 channelIDDERBlock, _ := pem.Decode(channelIDPEMBlock)
179 if channelIDDERBlock.Type != "EC PRIVATE KEY" {
180 panic("bad key type")
181 }
182 channelIDKey, err = x509.ParseECPrivateKey(channelIDDERBlock.Bytes)
183 if err != nil {
184 panic(err)
185 }
186 if channelIDKey.Curve != elliptic.P256() {
187 panic("bad curve")
188 }
189
190 channelIDBytes = make([]byte, 64)
191 writeIntPadded(channelIDBytes[:32], channelIDKey.X)
192 writeIntPadded(channelIDBytes[32:], channelIDKey.Y)
Adam Langley95c29f32014-06-20 12:00:00 -0700193}
194
David Benjamin33863262016-07-08 17:20:12 -0700195func getRunnerCertificate(t testCert) Certificate {
196 for _, cert := range testCerts {
197 if cert.id == t {
198 return *cert.cert
199 }
200 }
201 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700202}
203
David Benjamin33863262016-07-08 17:20:12 -0700204func getShimCertificate(t testCert) string {
205 for _, cert := range testCerts {
206 if cert.id == t {
207 return cert.certFile
208 }
209 }
210 panic("Unknown test certificate")
211}
212
213func getShimKey(t testCert) string {
214 for _, cert := range testCerts {
215 if cert.id == t {
216 return cert.keyFile
217 }
218 }
219 panic("Unknown test certificate")
Adam Langley95c29f32014-06-20 12:00:00 -0700220}
221
David Benjamin025b3d32014-07-01 19:53:04 -0400222type testType int
223
224const (
225 clientTest testType = iota
226 serverTest
227)
228
David Benjamin6fd297b2014-08-11 18:43:38 -0400229type protocol int
230
231const (
232 tls protocol = iota
233 dtls
234)
235
David Benjaminfc7b0862014-09-06 13:21:53 -0400236const (
237 alpn = 1
238 npn = 2
239)
240
Adam Langley95c29f32014-06-20 12:00:00 -0700241type testCase struct {
David Benjamin025b3d32014-07-01 19:53:04 -0400242 testType testType
David Benjamin6fd297b2014-08-11 18:43:38 -0400243 protocol protocol
Adam Langley95c29f32014-06-20 12:00:00 -0700244 name string
245 config Config
246 shouldFail bool
247 expectedError string
Adam Langleyac61fa32014-06-23 12:03:11 -0700248 // expectedLocalError, if not empty, contains a substring that must be
249 // found in the local error.
250 expectedLocalError string
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400251 // expectedVersion, if non-zero, specifies the TLS version that must be
252 // negotiated.
253 expectedVersion uint16
David Benjamin01fe8202014-09-24 15:21:44 -0400254 // expectedResumeVersion, if non-zero, specifies the TLS version that
255 // must be negotiated on resumption. If zero, expectedVersion is used.
256 expectedResumeVersion uint16
David Benjamin90da8c82015-04-20 14:57:57 -0400257 // expectedCipher, if non-zero, specifies the TLS cipher suite that
258 // should be negotiated.
259 expectedCipher uint16
David Benjamina08e49d2014-08-24 01:46:07 -0400260 // expectChannelID controls whether the connection should have
261 // negotiated a Channel ID with channelIDKey.
262 expectChannelID bool
David Benjaminae2888f2014-09-06 12:58:58 -0400263 // expectedNextProto controls whether the connection should
264 // negotiate a next protocol via NPN or ALPN.
265 expectedNextProto string
David Benjaminc7ce9772015-10-09 19:32:41 -0400266 // expectNoNextProto, if true, means that no next protocol should be
267 // negotiated.
268 expectNoNextProto bool
David Benjaminfc7b0862014-09-06 13:21:53 -0400269 // expectedNextProtoType, if non-zero, is the expected next
270 // protocol negotiation mechanism.
271 expectedNextProtoType int
David Benjaminca6c8262014-11-15 19:06:08 -0500272 // expectedSRTPProtectionProfile is the DTLS-SRTP profile that
273 // should be negotiated. If zero, none should be negotiated.
274 expectedSRTPProtectionProfile uint16
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100275 // expectedOCSPResponse, if not nil, is the expected OCSP response to be received.
276 expectedOCSPResponse []uint8
Paul Lietar4fac72e2015-09-09 13:44:55 +0100277 // expectedSCTList, if not nil, is the expected SCT list to be received.
278 expectedSCTList []uint8
Nick Harper60edffd2016-06-21 15:19:24 -0700279 // expectedPeerSignatureAlgorithm, if not zero, is the signature
280 // algorithm that the peer should have used in the handshake.
281 expectedPeerSignatureAlgorithm signatureAlgorithm
Steven Valdez5440fe02016-07-18 12:40:30 -0400282 // expectedCurveID, if not zero, is the curve that the handshake should
283 // have used.
284 expectedCurveID CurveID
Adam Langley80842bd2014-06-20 12:00:00 -0700285 // messageLen is the length, in bytes, of the test message that will be
286 // sent.
287 messageLen int
David Benjamin8e6db492015-07-25 18:29:23 -0400288 // messageCount is the number of test messages that will be sent.
289 messageCount int
David Benjamin025b3d32014-07-01 19:53:04 -0400290 // certFile is the path to the certificate to use for the server.
291 certFile string
292 // keyFile is the path to the private key to use for the server.
293 keyFile string
David Benjamin1d5c83e2014-07-22 19:20:02 -0400294 // resumeSession controls whether a second connection should be tested
David Benjamin01fe8202014-09-24 15:21:44 -0400295 // which attempts to resume the first session.
David Benjamin1d5c83e2014-07-22 19:20:02 -0400296 resumeSession bool
David Benjamin46662482016-08-17 00:51:00 -0400297 // resumeRenewedSession controls whether a third connection should be
298 // tested which attempts to resume the second connection's session.
299 resumeRenewedSession bool
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700300 // expectResumeRejected, if true, specifies that the attempted
301 // resumption must be rejected by the client. This is only valid for a
302 // serverTest.
303 expectResumeRejected bool
David Benjamin01fe8202014-09-24 15:21:44 -0400304 // resumeConfig, if not nil, points to a Config to be used on
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500305 // resumption. Unless newSessionsOnResume is set,
306 // SessionTicketKey, ServerSessionCache, and
307 // ClientSessionCache are copied from the initial connection's
308 // config. If nil, the initial connection's config is used.
David Benjamin01fe8202014-09-24 15:21:44 -0400309 resumeConfig *Config
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500310 // newSessionsOnResume, if true, will cause resumeConfig to
311 // use a different session resumption context.
312 newSessionsOnResume bool
David Benjaminba4594a2015-06-18 18:36:15 -0400313 // noSessionCache, if true, will cause the server to run without a
314 // session cache.
315 noSessionCache bool
David Benjamin98e882e2014-08-08 13:24:34 -0400316 // sendPrefix sends a prefix on the socket before actually performing a
317 // handshake.
318 sendPrefix string
David Benjamine58c4f52014-08-24 03:47:07 -0400319 // shimWritesFirst controls whether the shim sends an initial "hello"
320 // message before doing a roundtrip with the runner.
321 shimWritesFirst bool
David Benjamin30789da2015-08-29 22:56:45 -0400322 // shimShutsDown, if true, runs a test where the shim shuts down the
323 // connection immediately after the handshake rather than echoing
324 // messages from the runner.
325 shimShutsDown bool
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400326 // renegotiate indicates the number of times the connection should be
327 // renegotiated during the exchange.
328 renegotiate int
David Benjamin47921102016-07-28 11:29:18 -0400329 // sendHalfHelloRequest, if true, causes the server to send half a
330 // HelloRequest when the handshake completes.
331 sendHalfHelloRequest bool
Adam Langleycf2d4f42014-10-28 19:06:14 -0700332 // renegotiateCiphers is a list of ciphersuite ids that will be
333 // switched in just before renegotiation.
334 renegotiateCiphers []uint16
David Benjamin5e961c12014-11-07 01:48:35 -0500335 // replayWrites, if true, configures the underlying transport
336 // to replay every write it makes in DTLS tests.
337 replayWrites bool
David Benjamin5fa3eba2015-01-22 16:35:40 -0500338 // damageFirstWrite, if true, configures the underlying transport to
339 // damage the final byte of the first application data write.
340 damageFirstWrite bool
David Benjaminc565ebb2015-04-03 04:06:36 -0400341 // exportKeyingMaterial, if non-zero, configures the test to exchange
342 // keying material and verify they match.
343 exportKeyingMaterial int
344 exportLabel string
345 exportContext string
346 useExportContext bool
David Benjamin325b5c32014-07-01 19:40:31 -0400347 // flags, if not empty, contains a list of command-line flags that will
348 // be passed to the shim program.
349 flags []string
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700350 // testTLSUnique, if true, causes the shim to send the tls-unique value
351 // which will be compared against the expected value.
352 testTLSUnique bool
David Benjamina8ebe222015-06-06 03:04:39 -0400353 // sendEmptyRecords is the number of consecutive empty records to send
354 // before and after the test message.
355 sendEmptyRecords int
David Benjamin24f346d2015-06-06 03:28:08 -0400356 // sendWarningAlerts is the number of consecutive warning alerts to send
357 // before and after the test message.
358 sendWarningAlerts int
Steven Valdez32635b82016-08-16 11:25:03 -0400359 // sendKeyUpdates is the number of consecutive key updates to send
360 // before and after the test message.
361 sendKeyUpdates int
David Benjamin4f75aaf2015-09-01 16:53:10 -0400362 // expectMessageDropped, if true, means the test message is expected to
363 // be dropped by the client rather than echoed back.
364 expectMessageDropped bool
Adam Langley95c29f32014-06-20 12:00:00 -0700365}
366
Adam Langley7c803a62015-06-15 15:35:05 -0700367var testCases []testCase
Adam Langley95c29f32014-06-20 12:00:00 -0700368
David Benjaminc07afb72016-09-22 10:18:58 -0400369func writeTranscript(test *testCase, num int, data []byte) {
David Benjamin9867b7d2016-03-01 23:25:48 -0500370 if len(data) == 0 {
371 return
372 }
373
374 protocol := "tls"
375 if test.protocol == dtls {
376 protocol = "dtls"
377 }
378
379 side := "client"
380 if test.testType == serverTest {
381 side = "server"
382 }
383
384 dir := path.Join(*transcriptDir, protocol, side)
385 if err := os.MkdirAll(dir, 0755); err != nil {
386 fmt.Fprintf(os.Stderr, "Error making %s: %s\n", dir, err)
387 return
388 }
389
David Benjaminc07afb72016-09-22 10:18:58 -0400390 name := fmt.Sprintf("%s-%d", test.name, num)
David Benjamin9867b7d2016-03-01 23:25:48 -0500391 if err := ioutil.WriteFile(path.Join(dir, name), data, 0644); err != nil {
392 fmt.Fprintf(os.Stderr, "Error writing %s: %s\n", name, err)
393 }
394}
395
David Benjamin3ed59772016-03-08 12:50:21 -0500396// A timeoutConn implements an idle timeout on each Read and Write operation.
397type timeoutConn struct {
398 net.Conn
399 timeout time.Duration
400}
401
402func (t *timeoutConn) Read(b []byte) (int, error) {
403 if err := t.SetReadDeadline(time.Now().Add(t.timeout)); err != nil {
404 return 0, err
405 }
406 return t.Conn.Read(b)
407}
408
409func (t *timeoutConn) Write(b []byte) (int, error) {
410 if err := t.SetWriteDeadline(time.Now().Add(t.timeout)); err != nil {
411 return 0, err
412 }
413 return t.Conn.Write(b)
414}
415
David Benjaminc07afb72016-09-22 10:18:58 -0400416func doExchange(test *testCase, config *Config, conn net.Conn, isResume bool, num int) error {
David Benjamine54af062016-08-08 19:21:18 -0400417 if !test.noSessionCache {
418 if config.ClientSessionCache == nil {
419 config.ClientSessionCache = NewLRUClientSessionCache(1)
420 }
421 if config.ServerSessionCache == nil {
422 config.ServerSessionCache = NewLRUServerSessionCache(1)
423 }
424 }
425 if test.testType == clientTest {
426 if len(config.Certificates) == 0 {
427 config.Certificates = []Certificate{rsaCertificate}
428 }
429 } else {
430 // Supply a ServerName to ensure a constant session cache key,
431 // rather than falling back to net.Conn.RemoteAddr.
432 if len(config.ServerName) == 0 {
433 config.ServerName = "test"
434 }
435 }
436 if *fuzzer {
437 config.Bugs.NullAllCiphers = true
438 }
David Benjamin01a90572016-09-22 00:11:43 -0400439 if *deterministic {
440 config.Time = func() time.Time { return time.Unix(1234, 1234) }
441 }
David Benjamine54af062016-08-08 19:21:18 -0400442
David Benjamin01784b42016-06-07 18:00:52 -0400443 conn = &timeoutConn{conn, *idleTimeout}
David Benjamin65ea8ff2014-11-23 03:01:00 -0500444
David Benjamin6fd297b2014-08-11 18:43:38 -0400445 if test.protocol == dtls {
David Benjamin83f90402015-01-27 01:09:43 -0500446 config.Bugs.PacketAdaptor = newPacketAdaptor(conn)
447 conn = config.Bugs.PacketAdaptor
David Benjaminebda9b32015-11-02 15:33:18 -0500448 }
449
David Benjamin9867b7d2016-03-01 23:25:48 -0500450 if *flagDebug || len(*transcriptDir) != 0 {
David Benjaminebda9b32015-11-02 15:33:18 -0500451 local, peer := "client", "server"
452 if test.testType == clientTest {
453 local, peer = peer, local
David Benjamin5e961c12014-11-07 01:48:35 -0500454 }
David Benjaminebda9b32015-11-02 15:33:18 -0500455 connDebug := &recordingConn{
456 Conn: conn,
457 isDatagram: test.protocol == dtls,
458 local: local,
459 peer: peer,
460 }
461 conn = connDebug
David Benjamin9867b7d2016-03-01 23:25:48 -0500462 if *flagDebug {
463 defer connDebug.WriteTo(os.Stdout)
464 }
465 if len(*transcriptDir) != 0 {
466 defer func() {
David Benjaminc07afb72016-09-22 10:18:58 -0400467 writeTranscript(test, num, connDebug.Transcript())
David Benjamin9867b7d2016-03-01 23:25:48 -0500468 }()
469 }
David Benjaminebda9b32015-11-02 15:33:18 -0500470
471 if config.Bugs.PacketAdaptor != nil {
472 config.Bugs.PacketAdaptor.debug = connDebug
473 }
474 }
475
476 if test.replayWrites {
477 conn = newReplayAdaptor(conn)
David Benjamin6fd297b2014-08-11 18:43:38 -0400478 }
479
David Benjamin3ed59772016-03-08 12:50:21 -0500480 var connDamage *damageAdaptor
David Benjamin5fa3eba2015-01-22 16:35:40 -0500481 if test.damageFirstWrite {
482 connDamage = newDamageAdaptor(conn)
483 conn = connDamage
484 }
485
David Benjamin6fd297b2014-08-11 18:43:38 -0400486 if test.sendPrefix != "" {
487 if _, err := conn.Write([]byte(test.sendPrefix)); err != nil {
488 return err
489 }
David Benjamin98e882e2014-08-08 13:24:34 -0400490 }
491
David Benjamin1d5c83e2014-07-22 19:20:02 -0400492 var tlsConn *Conn
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400493 if test.testType == clientTest {
David Benjamin6fd297b2014-08-11 18:43:38 -0400494 if test.protocol == dtls {
495 tlsConn = DTLSServer(conn, config)
496 } else {
497 tlsConn = Server(conn, config)
498 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400499 } else {
500 config.InsecureSkipVerify = true
David Benjamin6fd297b2014-08-11 18:43:38 -0400501 if test.protocol == dtls {
502 tlsConn = DTLSClient(conn, config)
503 } else {
504 tlsConn = Client(conn, config)
505 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400506 }
David Benjamin30789da2015-08-29 22:56:45 -0400507 defer tlsConn.Close()
David Benjamin1d5c83e2014-07-22 19:20:02 -0400508
Adam Langley95c29f32014-06-20 12:00:00 -0700509 if err := tlsConn.Handshake(); err != nil {
510 return err
511 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700512
David Benjamin01fe8202014-09-24 15:21:44 -0400513 // TODO(davidben): move all per-connection expectations into a dedicated
514 // expectations struct that can be specified separately for the two
515 // legs.
516 expectedVersion := test.expectedVersion
517 if isResume && test.expectedResumeVersion != 0 {
518 expectedVersion = test.expectedResumeVersion
519 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700520 connState := tlsConn.ConnectionState()
521 if vers := connState.Version; expectedVersion != 0 && vers != expectedVersion {
David Benjamin01fe8202014-09-24 15:21:44 -0400522 return fmt.Errorf("got version %x, expected %x", vers, expectedVersion)
David Benjamin7e2e6cf2014-08-07 17:44:24 -0400523 }
524
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700525 if cipher := connState.CipherSuite; test.expectedCipher != 0 && cipher != test.expectedCipher {
David Benjamin90da8c82015-04-20 14:57:57 -0400526 return fmt.Errorf("got cipher %x, expected %x", cipher, test.expectedCipher)
527 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700528 if didResume := connState.DidResume; isResume && didResume == test.expectResumeRejected {
529 return fmt.Errorf("didResume is %t, but we expected the opposite", didResume)
530 }
David Benjamin90da8c82015-04-20 14:57:57 -0400531
David Benjamina08e49d2014-08-24 01:46:07 -0400532 if test.expectChannelID {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700533 channelID := connState.ChannelID
David Benjamina08e49d2014-08-24 01:46:07 -0400534 if channelID == nil {
535 return fmt.Errorf("no channel ID negotiated")
536 }
537 if channelID.Curve != channelIDKey.Curve ||
538 channelIDKey.X.Cmp(channelIDKey.X) != 0 ||
539 channelIDKey.Y.Cmp(channelIDKey.Y) != 0 {
540 return fmt.Errorf("incorrect channel ID")
541 }
542 }
543
David Benjaminae2888f2014-09-06 12:58:58 -0400544 if expected := test.expectedNextProto; expected != "" {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700545 if actual := connState.NegotiatedProtocol; actual != expected {
David Benjaminae2888f2014-09-06 12:58:58 -0400546 return fmt.Errorf("next proto mismatch: got %s, wanted %s", actual, expected)
547 }
548 }
549
David Benjaminc7ce9772015-10-09 19:32:41 -0400550 if test.expectNoNextProto {
551 if actual := connState.NegotiatedProtocol; actual != "" {
552 return fmt.Errorf("got unexpected next proto %s", actual)
553 }
554 }
555
David Benjaminfc7b0862014-09-06 13:21:53 -0400556 if test.expectedNextProtoType != 0 {
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700557 if (test.expectedNextProtoType == alpn) != connState.NegotiatedProtocolFromALPN {
David Benjaminfc7b0862014-09-06 13:21:53 -0400558 return fmt.Errorf("next proto type mismatch")
559 }
560 }
561
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700562 if p := connState.SRTPProtectionProfile; p != test.expectedSRTPProtectionProfile {
David Benjaminca6c8262014-11-15 19:06:08 -0500563 return fmt.Errorf("SRTP profile mismatch: got %d, wanted %d", p, test.expectedSRTPProtectionProfile)
564 }
565
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100566 if test.expectedOCSPResponse != nil && !bytes.Equal(test.expectedOCSPResponse, tlsConn.OCSPResponse()) {
David Benjamin942f4ed2016-07-16 19:03:49 +0300567 return fmt.Errorf("OCSP Response mismatch: got %x, wanted %x", tlsConn.OCSPResponse(), test.expectedOCSPResponse)
Paul Lietaraeeff2c2015-08-12 11:47:11 +0100568 }
569
Paul Lietar4fac72e2015-09-09 13:44:55 +0100570 if test.expectedSCTList != nil && !bytes.Equal(test.expectedSCTList, connState.SCTList) {
571 return fmt.Errorf("SCT list mismatch")
572 }
573
Nick Harper60edffd2016-06-21 15:19:24 -0700574 if expected := test.expectedPeerSignatureAlgorithm; expected != 0 && expected != connState.PeerSignatureAlgorithm {
575 return fmt.Errorf("expected peer to use signature algorithm %04x, but got %04x", expected, connState.PeerSignatureAlgorithm)
Steven Valdez0d62f262015-09-04 12:41:04 -0400576 }
577
Steven Valdez5440fe02016-07-18 12:40:30 -0400578 if expected := test.expectedCurveID; expected != 0 && expected != connState.CurveID {
579 return fmt.Errorf("expected peer to use curve %04x, but got %04x", expected, connState.CurveID)
580 }
581
David Benjaminc565ebb2015-04-03 04:06:36 -0400582 if test.exportKeyingMaterial > 0 {
583 actual := make([]byte, test.exportKeyingMaterial)
584 if _, err := io.ReadFull(tlsConn, actual); err != nil {
585 return err
586 }
587 expected, err := tlsConn.ExportKeyingMaterial(test.exportKeyingMaterial, []byte(test.exportLabel), []byte(test.exportContext), test.useExportContext)
588 if err != nil {
589 return err
590 }
591 if !bytes.Equal(actual, expected) {
592 return fmt.Errorf("keying material mismatch")
593 }
594 }
595
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700596 if test.testTLSUnique {
597 var peersValue [12]byte
598 if _, err := io.ReadFull(tlsConn, peersValue[:]); err != nil {
599 return err
600 }
601 expected := tlsConn.ConnectionState().TLSUnique
602 if !bytes.Equal(peersValue[:], expected) {
603 return fmt.Errorf("tls-unique mismatch: peer sent %x, but %x was expected", peersValue[:], expected)
604 }
605 }
606
David Benjamine58c4f52014-08-24 03:47:07 -0400607 if test.shimWritesFirst {
608 var buf [5]byte
609 _, err := io.ReadFull(tlsConn, buf[:])
610 if err != nil {
611 return err
612 }
613 if string(buf[:]) != "hello" {
614 return fmt.Errorf("bad initial message")
615 }
616 }
617
Steven Valdez32635b82016-08-16 11:25:03 -0400618 for i := 0; i < test.sendKeyUpdates; i++ {
David Benjamin7f0965a2016-09-30 15:14:01 -0400619 if err := tlsConn.SendKeyUpdate(); err != nil {
620 return err
621 }
Steven Valdez32635b82016-08-16 11:25:03 -0400622 }
623
David Benjamina8ebe222015-06-06 03:04:39 -0400624 for i := 0; i < test.sendEmptyRecords; i++ {
625 tlsConn.Write(nil)
626 }
627
David Benjamin24f346d2015-06-06 03:28:08 -0400628 for i := 0; i < test.sendWarningAlerts; i++ {
629 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
630 }
631
David Benjamin47921102016-07-28 11:29:18 -0400632 if test.sendHalfHelloRequest {
633 tlsConn.SendHalfHelloRequest()
634 }
635
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400636 if test.renegotiate > 0 {
Adam Langleycf2d4f42014-10-28 19:06:14 -0700637 if test.renegotiateCiphers != nil {
638 config.CipherSuites = test.renegotiateCiphers
639 }
David Benjamin1d5ef3b2015-10-12 19:54:18 -0400640 for i := 0; i < test.renegotiate; i++ {
641 if err := tlsConn.Renegotiate(); err != nil {
642 return err
643 }
Adam Langleycf2d4f42014-10-28 19:06:14 -0700644 }
645 } else if test.renegotiateCiphers != nil {
646 panic("renegotiateCiphers without renegotiate")
647 }
648
David Benjamin5fa3eba2015-01-22 16:35:40 -0500649 if test.damageFirstWrite {
650 connDamage.setDamage(true)
651 tlsConn.Write([]byte("DAMAGED WRITE"))
652 connDamage.setDamage(false)
653 }
654
David Benjamin8e6db492015-07-25 18:29:23 -0400655 messageLen := test.messageLen
Kenny Root7fdeaf12014-08-05 15:23:37 -0700656 if messageLen < 0 {
David Benjamin6fd297b2014-08-11 18:43:38 -0400657 if test.protocol == dtls {
658 return fmt.Errorf("messageLen < 0 not supported for DTLS tests")
659 }
Kenny Root7fdeaf12014-08-05 15:23:37 -0700660 // Read until EOF.
661 _, err := io.Copy(ioutil.Discard, tlsConn)
662 return err
663 }
David Benjamin4417d052015-04-05 04:17:25 -0400664 if messageLen == 0 {
665 messageLen = 32
Adam Langley80842bd2014-06-20 12:00:00 -0700666 }
Adam Langley95c29f32014-06-20 12:00:00 -0700667
David Benjamin8e6db492015-07-25 18:29:23 -0400668 messageCount := test.messageCount
669 if messageCount == 0 {
670 messageCount = 1
David Benjamina8ebe222015-06-06 03:04:39 -0400671 }
672
David Benjamin8e6db492015-07-25 18:29:23 -0400673 for j := 0; j < messageCount; j++ {
674 testMessage := make([]byte, messageLen)
675 for i := range testMessage {
676 testMessage[i] = 0x42 ^ byte(j)
David Benjamin6fd297b2014-08-11 18:43:38 -0400677 }
David Benjamin8e6db492015-07-25 18:29:23 -0400678 tlsConn.Write(testMessage)
Adam Langley95c29f32014-06-20 12:00:00 -0700679
Steven Valdez32635b82016-08-16 11:25:03 -0400680 for i := 0; i < test.sendKeyUpdates; i++ {
681 tlsConn.SendKeyUpdate()
682 }
683
David Benjamin8e6db492015-07-25 18:29:23 -0400684 for i := 0; i < test.sendEmptyRecords; i++ {
685 tlsConn.Write(nil)
686 }
687
688 for i := 0; i < test.sendWarningAlerts; i++ {
689 tlsConn.SendAlert(alertLevelWarning, alertUnexpectedMessage)
690 }
691
David Benjamin4f75aaf2015-09-01 16:53:10 -0400692 if test.shimShutsDown || test.expectMessageDropped {
David Benjamin30789da2015-08-29 22:56:45 -0400693 // The shim will not respond.
694 continue
695 }
696
David Benjamin8e6db492015-07-25 18:29:23 -0400697 buf := make([]byte, len(testMessage))
698 if test.protocol == dtls {
699 bufTmp := make([]byte, len(buf)+1)
700 n, err := tlsConn.Read(bufTmp)
701 if err != nil {
702 return err
703 }
704 if n != len(buf) {
705 return fmt.Errorf("bad reply; length mismatch (%d vs %d)", n, len(buf))
706 }
707 copy(buf, bufTmp)
708 } else {
709 _, err := io.ReadFull(tlsConn, buf)
710 if err != nil {
711 return err
712 }
713 }
714
715 for i, v := range buf {
716 if v != testMessage[i]^0xff {
717 return fmt.Errorf("bad reply contents at byte %d", i)
718 }
Adam Langley95c29f32014-06-20 12:00:00 -0700719 }
720 }
721
722 return nil
723}
724
David Benjamin325b5c32014-07-01 19:40:31 -0400725func valgrindOf(dbAttach bool, path string, args ...string) *exec.Cmd {
David Benjamind2ba8892016-09-20 19:41:04 -0400726 valgrindArgs := []string{"--error-exitcode=99", "--track-origins=yes", "--leak-check=full", "--quiet"}
Adam Langley95c29f32014-06-20 12:00:00 -0700727 if dbAttach {
David Benjamin325b5c32014-07-01 19:40:31 -0400728 valgrindArgs = append(valgrindArgs, "--db-attach=yes", "--db-command=xterm -e gdb -nw %f %p")
Adam Langley95c29f32014-06-20 12:00:00 -0700729 }
David Benjamin325b5c32014-07-01 19:40:31 -0400730 valgrindArgs = append(valgrindArgs, path)
731 valgrindArgs = append(valgrindArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700732
David Benjamin325b5c32014-07-01 19:40:31 -0400733 return exec.Command("valgrind", valgrindArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700734}
735
David Benjamin325b5c32014-07-01 19:40:31 -0400736func gdbOf(path string, args ...string) *exec.Cmd {
737 xtermArgs := []string{"-e", "gdb", "--args"}
738 xtermArgs = append(xtermArgs, path)
739 xtermArgs = append(xtermArgs, args...)
Adam Langley95c29f32014-06-20 12:00:00 -0700740
David Benjamin325b5c32014-07-01 19:40:31 -0400741 return exec.Command("xterm", xtermArgs...)
Adam Langley95c29f32014-06-20 12:00:00 -0700742}
743
David Benjamind16bf342015-12-18 00:53:12 -0500744func lldbOf(path string, args ...string) *exec.Cmd {
745 xtermArgs := []string{"-e", "lldb", "--"}
746 xtermArgs = append(xtermArgs, path)
747 xtermArgs = append(xtermArgs, args...)
748
749 return exec.Command("xterm", xtermArgs...)
750}
751
EKR842ae6c2016-07-27 09:22:05 +0200752var (
753 errMoreMallocs = errors.New("child process did not exhaust all allocation calls")
754 errUnimplemented = errors.New("child process does not implement needed flags")
755)
Adam Langley69a01602014-11-17 17:26:55 -0800756
David Benjamin87c8a642015-02-21 01:54:29 -0500757// accept accepts a connection from listener, unless waitChan signals a process
758// exit first.
759func acceptOrWait(listener net.Listener, waitChan chan error) (net.Conn, error) {
760 type connOrError struct {
761 conn net.Conn
762 err error
763 }
764 connChan := make(chan connOrError, 1)
765 go func() {
766 conn, err := listener.Accept()
767 connChan <- connOrError{conn, err}
768 close(connChan)
769 }()
770 select {
771 case result := <-connChan:
772 return result.conn, result.err
773 case childErr := <-waitChan:
774 waitChan <- childErr
775 return nil, fmt.Errorf("child exited early: %s", childErr)
776 }
777}
778
EKRf71d7ed2016-08-06 13:25:12 -0700779func translateExpectedError(errorStr string) string {
780 if translated, ok := shimConfig.ErrorMap[errorStr]; ok {
781 return translated
782 }
783
784 if *looseErrors {
785 return ""
786 }
787
788 return errorStr
789}
790
Adam Langley7c803a62015-06-15 15:35:05 -0700791func runTest(test *testCase, shimPath string, mallocNumToFail int64) error {
Steven Valdez803c77a2016-09-06 14:13:43 -0400792 // Help debugging panics on the Go side.
793 defer func() {
794 if r := recover(); r != nil {
795 fmt.Fprintf(os.Stderr, "Test '%s' panicked.\n", test.name)
796 panic(r)
797 }
798 }()
799
Adam Langley38311732014-10-16 19:04:35 -0700800 if !test.shouldFail && (len(test.expectedError) > 0 || len(test.expectedLocalError) > 0) {
801 panic("Error expected without shouldFail in " + test.name)
802 }
803
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700804 if test.expectResumeRejected && !test.resumeSession {
805 panic("expectResumeRejected without resumeSession in " + test.name)
806 }
807
David Benjamin87c8a642015-02-21 01:54:29 -0500808 listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: net.IP{127, 0, 0, 1}})
809 if err != nil {
810 panic(err)
811 }
812 defer func() {
813 if listener != nil {
814 listener.Close()
815 }
816 }()
Adam Langley95c29f32014-06-20 12:00:00 -0700817
David Benjamin87c8a642015-02-21 01:54:29 -0500818 flags := []string{"-port", strconv.Itoa(listener.Addr().(*net.TCPAddr).Port)}
David Benjamin1d5c83e2014-07-22 19:20:02 -0400819 if test.testType == serverTest {
David Benjamin5a593af2014-08-11 19:51:50 -0400820 flags = append(flags, "-server")
821
David Benjamin025b3d32014-07-01 19:53:04 -0400822 flags = append(flags, "-key-file")
823 if test.keyFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700824 flags = append(flags, path.Join(*resourceDir, rsaKeyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400825 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700826 flags = append(flags, path.Join(*resourceDir, test.keyFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400827 }
828
829 flags = append(flags, "-cert-file")
830 if test.certFile == "" {
Adam Langley7c803a62015-06-15 15:35:05 -0700831 flags = append(flags, path.Join(*resourceDir, rsaCertificateFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400832 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700833 flags = append(flags, path.Join(*resourceDir, test.certFile))
David Benjamin025b3d32014-07-01 19:53:04 -0400834 }
835 }
David Benjamin5a593af2014-08-11 19:51:50 -0400836
David Benjamin6fd297b2014-08-11 18:43:38 -0400837 if test.protocol == dtls {
838 flags = append(flags, "-dtls")
839 }
840
David Benjamin46662482016-08-17 00:51:00 -0400841 var resumeCount int
David Benjamin5a593af2014-08-11 19:51:50 -0400842 if test.resumeSession {
David Benjamin46662482016-08-17 00:51:00 -0400843 resumeCount++
844 if test.resumeRenewedSession {
845 resumeCount++
846 }
847 }
848
849 if resumeCount > 0 {
850 flags = append(flags, "-resume-count", strconv.Itoa(resumeCount))
David Benjamin5a593af2014-08-11 19:51:50 -0400851 }
852
David Benjamine58c4f52014-08-24 03:47:07 -0400853 if test.shimWritesFirst {
854 flags = append(flags, "-shim-writes-first")
855 }
856
David Benjamin30789da2015-08-29 22:56:45 -0400857 if test.shimShutsDown {
858 flags = append(flags, "-shim-shuts-down")
859 }
860
David Benjaminc565ebb2015-04-03 04:06:36 -0400861 if test.exportKeyingMaterial > 0 {
862 flags = append(flags, "-export-keying-material", strconv.Itoa(test.exportKeyingMaterial))
863 flags = append(flags, "-export-label", test.exportLabel)
864 flags = append(flags, "-export-context", test.exportContext)
865 if test.useExportContext {
866 flags = append(flags, "-use-export-context")
867 }
868 }
Adam Langleyb0eef0a2015-06-02 10:47:39 -0700869 if test.expectResumeRejected {
870 flags = append(flags, "-expect-session-miss")
871 }
David Benjaminc565ebb2015-04-03 04:06:36 -0400872
Adam Langleyaf0e32c2015-06-03 09:57:23 -0700873 if test.testTLSUnique {
874 flags = append(flags, "-tls-unique")
875 }
876
David Benjamin025b3d32014-07-01 19:53:04 -0400877 flags = append(flags, test.flags...)
878
879 var shim *exec.Cmd
880 if *useValgrind {
Adam Langley7c803a62015-06-15 15:35:05 -0700881 shim = valgrindOf(false, shimPath, flags...)
Adam Langley75712922014-10-10 16:23:43 -0700882 } else if *useGDB {
Adam Langley7c803a62015-06-15 15:35:05 -0700883 shim = gdbOf(shimPath, flags...)
David Benjamind16bf342015-12-18 00:53:12 -0500884 } else if *useLLDB {
885 shim = lldbOf(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400886 } else {
Adam Langley7c803a62015-06-15 15:35:05 -0700887 shim = exec.Command(shimPath, flags...)
David Benjamin025b3d32014-07-01 19:53:04 -0400888 }
David Benjamin025b3d32014-07-01 19:53:04 -0400889 shim.Stdin = os.Stdin
890 var stdoutBuf, stderrBuf bytes.Buffer
891 shim.Stdout = &stdoutBuf
892 shim.Stderr = &stderrBuf
Adam Langley69a01602014-11-17 17:26:55 -0800893 if mallocNumToFail >= 0 {
David Benjamin9e128b02015-02-09 13:13:09 -0500894 shim.Env = os.Environ()
895 shim.Env = append(shim.Env, "MALLOC_NUMBER_TO_FAIL="+strconv.FormatInt(mallocNumToFail, 10))
Adam Langley69a01602014-11-17 17:26:55 -0800896 if *mallocTestDebug {
David Benjamin184494d2015-06-12 18:23:47 -0400897 shim.Env = append(shim.Env, "MALLOC_BREAK_ON_FAIL=1")
Adam Langley69a01602014-11-17 17:26:55 -0800898 }
899 shim.Env = append(shim.Env, "_MALLOC_CHECK=1")
900 }
David Benjamin025b3d32014-07-01 19:53:04 -0400901
902 if err := shim.Start(); err != nil {
Adam Langley95c29f32014-06-20 12:00:00 -0700903 panic(err)
904 }
David Benjamin87c8a642015-02-21 01:54:29 -0500905 waitChan := make(chan error, 1)
906 go func() { waitChan <- shim.Wait() }()
Adam Langley95c29f32014-06-20 12:00:00 -0700907
908 config := test.config
Adam Langley95c29f32014-06-20 12:00:00 -0700909
David Benjamin7a4aaa42016-09-20 17:58:14 -0400910 if *deterministic {
911 config.Rand = &deterministicRand{}
912 }
913
David Benjamin87c8a642015-02-21 01:54:29 -0500914 conn, err := acceptOrWait(listener, waitChan)
915 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400916 err = doExchange(test, &config, conn, false /* not a resumption */, 0)
David Benjamin87c8a642015-02-21 01:54:29 -0500917 conn.Close()
918 }
David Benjamin65ea8ff2014-11-23 03:01:00 -0500919
David Benjamin46662482016-08-17 00:51:00 -0400920 for i := 0; err == nil && i < resumeCount; i++ {
David Benjamin01fe8202014-09-24 15:21:44 -0400921 var resumeConfig Config
922 if test.resumeConfig != nil {
923 resumeConfig = *test.resumeConfig
David Benjamine54af062016-08-08 19:21:18 -0400924 if !test.newSessionsOnResume {
David Benjaminfe8eb9a2014-11-17 03:19:02 -0500925 resumeConfig.SessionTicketKey = config.SessionTicketKey
926 resumeConfig.ClientSessionCache = config.ClientSessionCache
927 resumeConfig.ServerSessionCache = config.ServerSessionCache
928 }
David Benjamin2e045a92016-06-08 13:09:56 -0400929 resumeConfig.Rand = config.Rand
David Benjamin01fe8202014-09-24 15:21:44 -0400930 } else {
931 resumeConfig = config
932 }
David Benjamin87c8a642015-02-21 01:54:29 -0500933 var connResume net.Conn
934 connResume, err = acceptOrWait(listener, waitChan)
935 if err == nil {
David Benjaminc07afb72016-09-22 10:18:58 -0400936 err = doExchange(test, &resumeConfig, connResume, true /* resumption */, i+1)
David Benjamin87c8a642015-02-21 01:54:29 -0500937 connResume.Close()
938 }
David Benjamin1d5c83e2014-07-22 19:20:02 -0400939 }
940
David Benjamin87c8a642015-02-21 01:54:29 -0500941 // Close the listener now. This is to avoid hangs should the shim try to
942 // open more connections than expected.
943 listener.Close()
944 listener = nil
945
946 childErr := <-waitChan
David Benjamind2ba8892016-09-20 19:41:04 -0400947 var isValgrindError bool
Adam Langley69a01602014-11-17 17:26:55 -0800948 if exitError, ok := childErr.(*exec.ExitError); ok {
EKR842ae6c2016-07-27 09:22:05 +0200949 switch exitError.Sys().(syscall.WaitStatus).ExitStatus() {
950 case 88:
Adam Langley69a01602014-11-17 17:26:55 -0800951 return errMoreMallocs
EKR842ae6c2016-07-27 09:22:05 +0200952 case 89:
953 return errUnimplemented
David Benjamind2ba8892016-09-20 19:41:04 -0400954 case 99:
955 isValgrindError = true
Adam Langley69a01602014-11-17 17:26:55 -0800956 }
957 }
Adam Langley95c29f32014-06-20 12:00:00 -0700958
David Benjamin9bea3492016-03-02 10:59:16 -0500959 // Account for Windows line endings.
960 stdout := strings.Replace(string(stdoutBuf.Bytes()), "\r\n", "\n", -1)
961 stderr := strings.Replace(string(stderrBuf.Bytes()), "\r\n", "\n", -1)
David Benjaminff3a1492016-03-02 10:12:06 -0500962
963 // Separate the errors from the shim and those from tools like
964 // AddressSanitizer.
965 var extraStderr string
966 if stderrParts := strings.SplitN(stderr, "--- DONE ---\n", 2); len(stderrParts) == 2 {
967 stderr = stderrParts[0]
968 extraStderr = stderrParts[1]
969 }
970
Adam Langley95c29f32014-06-20 12:00:00 -0700971 failed := err != nil || childErr != nil
EKRf71d7ed2016-08-06 13:25:12 -0700972 expectedError := translateExpectedError(test.expectedError)
973 correctFailure := len(expectedError) == 0 || strings.Contains(stderr, expectedError)
EKR173bf932016-07-29 15:52:49 +0200974
Adam Langleyac61fa32014-06-23 12:03:11 -0700975 localError := "none"
976 if err != nil {
977 localError = err.Error()
978 }
979 if len(test.expectedLocalError) != 0 {
980 correctFailure = correctFailure && strings.Contains(localError, test.expectedLocalError)
981 }
Adam Langley95c29f32014-06-20 12:00:00 -0700982
983 if failed != test.shouldFail || failed && !correctFailure {
Adam Langley95c29f32014-06-20 12:00:00 -0700984 childError := "none"
Adam Langley95c29f32014-06-20 12:00:00 -0700985 if childErr != nil {
986 childError = childErr.Error()
987 }
988
989 var msg string
990 switch {
991 case failed && !test.shouldFail:
992 msg = "unexpected failure"
993 case !failed && test.shouldFail:
994 msg = "unexpected success"
995 case failed && !correctFailure:
EKRf71d7ed2016-08-06 13:25:12 -0700996 msg = "bad error (wanted '" + expectedError + "' / '" + test.expectedLocalError + "')"
Adam Langley95c29f32014-06-20 12:00:00 -0700997 default:
998 panic("internal error")
999 }
1000
David Benjamin9aafb642016-09-20 19:36:53 -04001001 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 -07001002 }
1003
David Benjamind2ba8892016-09-20 19:41:04 -04001004 if len(extraStderr) > 0 || (!failed && len(stderr) > 0) {
David Benjaminff3a1492016-03-02 10:12:06 -05001005 return fmt.Errorf("unexpected error output:\n%s\n%s", stderr, extraStderr)
Adam Langley95c29f32014-06-20 12:00:00 -07001006 }
1007
David Benjamind2ba8892016-09-20 19:41:04 -04001008 if *useValgrind && isValgrindError {
1009 return fmt.Errorf("valgrind error:\n%s\n%s", stderr, extraStderr)
1010 }
1011
Adam Langley95c29f32014-06-20 12:00:00 -07001012 return nil
1013}
1014
1015var tlsVersions = []struct {
1016 name string
1017 version uint16
David Benjamin7e2e6cf2014-08-07 17:44:24 -04001018 flag string
David Benjamin8b8c0062014-11-23 02:47:52 -05001019 hasDTLS bool
Adam Langley95c29f32014-06-20 12:00:00 -07001020}{
David Benjamin8b8c0062014-11-23 02:47:52 -05001021 {"SSL3", VersionSSL30, "-no-ssl3", false},
1022 {"TLS1", VersionTLS10, "-no-tls1", true},
1023 {"TLS11", VersionTLS11, "-no-tls11", false},
1024 {"TLS12", VersionTLS12, "-no-tls12", true},
Steven Valdez143e8b32016-07-11 13:19:03 -04001025 {"TLS13", VersionTLS13, "-no-tls13", false},
Adam Langley95c29f32014-06-20 12:00:00 -07001026}
1027
1028var testCipherSuites = []struct {
1029 name string
1030 id uint16
1031}{
1032 {"3DES-SHA", TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001033 {"AES128-GCM", TLS_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001034 {"AES128-SHA", TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001035 {"AES128-SHA256", TLS_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001036 {"AES256-GCM", TLS_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001037 {"AES256-SHA", TLS_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001038 {"AES256-SHA256", TLS_RSA_WITH_AES_256_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001039 {"DHE-RSA-AES128-GCM", TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1040 {"DHE-RSA-AES128-SHA", TLS_DHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001041 {"DHE-RSA-AES128-SHA256", TLS_DHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001042 {"DHE-RSA-AES256-GCM", TLS_DHE_RSA_WITH_AES_256_GCM_SHA384},
1043 {"DHE-RSA-AES256-SHA", TLS_DHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001044 {"DHE-RSA-AES256-SHA256", TLS_DHE_RSA_WITH_AES_256_CBC_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001045 {"ECDHE-ECDSA-AES128-GCM", TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
1046 {"ECDHE-ECDSA-AES128-SHA", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001047 {"ECDHE-ECDSA-AES128-SHA256", TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256},
1048 {"ECDHE-ECDSA-AES256-GCM", TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001049 {"ECDHE-ECDSA-AES256-SHA", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001050 {"ECDHE-ECDSA-AES256-SHA384", TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001051 {"ECDHE-ECDSA-CHACHA20-POLY1305", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001052 {"ECDHE-ECDSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Adam Langley95c29f32014-06-20 12:00:00 -07001053 {"ECDHE-RSA-AES128-GCM", TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
Adam Langley95c29f32014-06-20 12:00:00 -07001054 {"ECDHE-RSA-AES128-SHA", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001055 {"ECDHE-RSA-AES128-SHA256", TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256},
David Benjaminf4e5c4e2014-08-02 17:35:45 -04001056 {"ECDHE-RSA-AES256-GCM", TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384},
Adam Langley95c29f32014-06-20 12:00:00 -07001057 {"ECDHE-RSA-AES256-SHA", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA},
David Benjaminf7768e42014-08-31 02:06:47 -04001058 {"ECDHE-RSA-AES256-SHA384", TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384},
David Benjamin13414b32015-12-09 23:02:39 -05001059 {"ECDHE-RSA-CHACHA20-POLY1305", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256},
David Benjamine3203922015-12-09 21:21:31 -05001060 {"ECDHE-RSA-CHACHA20-POLY1305-OLD", TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256_OLD},
Matt Braithwaite053931e2016-05-25 12:06:05 -07001061 {"CECPQ1-RSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_RSA_WITH_CHACHA20_POLY1305_SHA256},
1062 {"CECPQ1-ECDSA-CHACHA20-POLY1305-SHA256", TLS_CECPQ1_ECDSA_WITH_CHACHA20_POLY1305_SHA256},
1063 {"CECPQ1-RSA-AES256-GCM-SHA384", TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
1064 {"CECPQ1-ECDSA-AES256-GCM-SHA384", TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384},
David Benjamin48cae082014-10-27 01:06:24 -04001065 {"PSK-AES128-CBC-SHA", TLS_PSK_WITH_AES_128_CBC_SHA},
1066 {"PSK-AES256-CBC-SHA", TLS_PSK_WITH_AES_256_CBC_SHA},
Adam Langley85bc5602015-06-09 09:54:04 -07001067 {"ECDHE-PSK-AES128-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
1068 {"ECDHE-PSK-AES256-CBC-SHA", TLS_ECDHE_PSK_WITH_AES_256_CBC_SHA},
David Benjamin13414b32015-12-09 23:02:39 -05001069 {"ECDHE-PSK-CHACHA20-POLY1305", TLS_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256},
Steven Valdez803c77a2016-09-06 14:13:43 -04001070 {"AEAD-CHACHA20-POLY1305", TLS_CHACHA20_POLY1305_SHA256},
1071 {"AEAD-AES128-GCM-SHA256", TLS_AES_128_GCM_SHA256},
1072 {"AEAD-AES256-GCM-SHA384", TLS_AES_256_GCM_SHA384},
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001073 {"NULL-SHA", TLS_RSA_WITH_NULL_SHA},
Adam Langley95c29f32014-06-20 12:00:00 -07001074}
1075
David Benjamin8b8c0062014-11-23 02:47:52 -05001076func hasComponent(suiteName, component string) bool {
1077 return strings.Contains("-"+suiteName+"-", "-"+component+"-")
1078}
1079
David Benjaminf7768e42014-08-31 02:06:47 -04001080func isTLS12Only(suiteName string) bool {
David Benjamin8b8c0062014-11-23 02:47:52 -05001081 return hasComponent(suiteName, "GCM") ||
1082 hasComponent(suiteName, "SHA256") ||
David Benjamine9a80ff2015-04-07 00:46:46 -04001083 hasComponent(suiteName, "SHA384") ||
1084 hasComponent(suiteName, "POLY1305")
David Benjamin8b8c0062014-11-23 02:47:52 -05001085}
1086
Nick Harper1fd39d82016-06-14 18:14:35 -07001087func isTLS13Suite(suiteName string) bool {
Steven Valdez803c77a2016-09-06 14:13:43 -04001088 return strings.HasPrefix(suiteName, "AEAD-")
Nick Harper1fd39d82016-06-14 18:14:35 -07001089}
1090
David Benjamin8b8c0062014-11-23 02:47:52 -05001091func isDTLSCipher(suiteName string) bool {
Matt Braithwaiteaf096752015-09-02 19:48:16 -07001092 return !hasComponent(suiteName, "RC4") && !hasComponent(suiteName, "NULL")
David Benjaminf7768e42014-08-31 02:06:47 -04001093}
1094
Adam Langleya7997f12015-05-14 17:38:50 -07001095func bigFromHex(hex string) *big.Int {
1096 ret, ok := new(big.Int).SetString(hex, 16)
1097 if !ok {
1098 panic("failed to parse hex number 0x" + hex)
1099 }
1100 return ret
1101}
1102
Adam Langley7c803a62015-06-15 15:35:05 -07001103func addBasicTests() {
1104 basicTests := []testCase{
1105 {
Adam Langley7c803a62015-06-15 15:35:05 -07001106 name: "NoFallbackSCSV",
1107 config: Config{
1108 Bugs: ProtocolBugs{
1109 FailIfNotFallbackSCSV: true,
1110 },
1111 },
1112 shouldFail: true,
1113 expectedLocalError: "no fallback SCSV found",
1114 },
1115 {
1116 name: "SendFallbackSCSV",
1117 config: Config{
1118 Bugs: ProtocolBugs{
1119 FailIfNotFallbackSCSV: true,
1120 },
1121 },
1122 flags: []string{"-fallback-scsv"},
1123 },
1124 {
1125 name: "ClientCertificateTypes",
1126 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001127 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001128 ClientAuth: RequestClientCert,
1129 ClientCertificateTypes: []byte{
1130 CertTypeDSSSign,
1131 CertTypeRSASign,
1132 CertTypeECDSASign,
1133 },
1134 },
1135 flags: []string{
1136 "-expect-certificate-types",
1137 base64.StdEncoding.EncodeToString([]byte{
1138 CertTypeDSSSign,
1139 CertTypeRSASign,
1140 CertTypeECDSASign,
1141 }),
1142 },
1143 },
1144 {
Adam Langley7c803a62015-06-15 15:35:05 -07001145 name: "UnauthenticatedECDH",
1146 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001147 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001148 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1149 Bugs: ProtocolBugs{
1150 UnauthenticatedECDH: true,
1151 },
1152 },
1153 shouldFail: true,
1154 expectedError: ":UNEXPECTED_MESSAGE:",
1155 },
1156 {
1157 name: "SkipCertificateStatus",
1158 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001159 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001160 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1161 Bugs: ProtocolBugs{
1162 SkipCertificateStatus: true,
1163 },
1164 },
1165 flags: []string{
1166 "-enable-ocsp-stapling",
1167 },
1168 },
1169 {
1170 name: "SkipServerKeyExchange",
1171 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001172 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001173 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1174 Bugs: ProtocolBugs{
1175 SkipServerKeyExchange: true,
1176 },
1177 },
1178 shouldFail: true,
1179 expectedError: ":UNEXPECTED_MESSAGE:",
1180 },
1181 {
Adam Langley7c803a62015-06-15 15:35:05 -07001182 testType: serverTest,
1183 name: "Alert",
1184 config: Config{
1185 Bugs: ProtocolBugs{
1186 SendSpuriousAlert: alertRecordOverflow,
1187 },
1188 },
1189 shouldFail: true,
1190 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1191 },
1192 {
1193 protocol: dtls,
1194 testType: serverTest,
1195 name: "Alert-DTLS",
1196 config: Config{
1197 Bugs: ProtocolBugs{
1198 SendSpuriousAlert: alertRecordOverflow,
1199 },
1200 },
1201 shouldFail: true,
1202 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1203 },
1204 {
1205 testType: serverTest,
1206 name: "FragmentAlert",
1207 config: Config{
1208 Bugs: ProtocolBugs{
1209 FragmentAlert: true,
1210 SendSpuriousAlert: alertRecordOverflow,
1211 },
1212 },
1213 shouldFail: true,
1214 expectedError: ":BAD_ALERT:",
1215 },
1216 {
1217 protocol: dtls,
1218 testType: serverTest,
1219 name: "FragmentAlert-DTLS",
1220 config: Config{
1221 Bugs: ProtocolBugs{
1222 FragmentAlert: true,
1223 SendSpuriousAlert: alertRecordOverflow,
1224 },
1225 },
1226 shouldFail: true,
1227 expectedError: ":BAD_ALERT:",
1228 },
1229 {
1230 testType: serverTest,
David Benjamin0d3a8c62016-03-11 22:25:18 -05001231 name: "DoubleAlert",
1232 config: Config{
1233 Bugs: ProtocolBugs{
1234 DoubleAlert: true,
1235 SendSpuriousAlert: alertRecordOverflow,
1236 },
1237 },
1238 shouldFail: true,
1239 expectedError: ":BAD_ALERT:",
1240 },
1241 {
1242 protocol: dtls,
1243 testType: serverTest,
1244 name: "DoubleAlert-DTLS",
1245 config: Config{
1246 Bugs: ProtocolBugs{
1247 DoubleAlert: true,
1248 SendSpuriousAlert: alertRecordOverflow,
1249 },
1250 },
1251 shouldFail: true,
1252 expectedError: ":BAD_ALERT:",
1253 },
1254 {
Adam Langley7c803a62015-06-15 15:35:05 -07001255 name: "SkipNewSessionTicket",
1256 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001257 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001258 Bugs: ProtocolBugs{
1259 SkipNewSessionTicket: true,
1260 },
1261 },
1262 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001263 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001264 },
1265 {
1266 testType: serverTest,
1267 name: "FallbackSCSV",
1268 config: Config{
1269 MaxVersion: VersionTLS11,
1270 Bugs: ProtocolBugs{
1271 SendFallbackSCSV: true,
1272 },
1273 },
1274 shouldFail: true,
1275 expectedError: ":INAPPROPRIATE_FALLBACK:",
1276 },
1277 {
1278 testType: serverTest,
1279 name: "FallbackSCSV-VersionMatch",
1280 config: Config{
1281 Bugs: ProtocolBugs{
1282 SendFallbackSCSV: true,
1283 },
1284 },
1285 },
1286 {
1287 testType: serverTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04001288 name: "FallbackSCSV-VersionMatch-TLS12",
1289 config: Config{
1290 MaxVersion: VersionTLS12,
1291 Bugs: ProtocolBugs{
1292 SendFallbackSCSV: true,
1293 },
1294 },
1295 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
1296 },
1297 {
1298 testType: serverTest,
Adam Langley7c803a62015-06-15 15:35:05 -07001299 name: "FragmentedClientVersion",
1300 config: Config{
1301 Bugs: ProtocolBugs{
1302 MaxHandshakeRecordLength: 1,
1303 FragmentClientVersion: true,
1304 },
1305 },
Nick Harper1fd39d82016-06-14 18:14:35 -07001306 expectedVersion: VersionTLS13,
Adam Langley7c803a62015-06-15 15:35:05 -07001307 },
1308 {
Adam Langley7c803a62015-06-15 15:35:05 -07001309 testType: serverTest,
1310 name: "HttpGET",
1311 sendPrefix: "GET / HTTP/1.0\n",
1312 shouldFail: true,
1313 expectedError: ":HTTP_REQUEST:",
1314 },
1315 {
1316 testType: serverTest,
1317 name: "HttpPOST",
1318 sendPrefix: "POST / HTTP/1.0\n",
1319 shouldFail: true,
1320 expectedError: ":HTTP_REQUEST:",
1321 },
1322 {
1323 testType: serverTest,
1324 name: "HttpHEAD",
1325 sendPrefix: "HEAD / HTTP/1.0\n",
1326 shouldFail: true,
1327 expectedError: ":HTTP_REQUEST:",
1328 },
1329 {
1330 testType: serverTest,
1331 name: "HttpPUT",
1332 sendPrefix: "PUT / HTTP/1.0\n",
1333 shouldFail: true,
1334 expectedError: ":HTTP_REQUEST:",
1335 },
1336 {
1337 testType: serverTest,
1338 name: "HttpCONNECT",
1339 sendPrefix: "CONNECT www.google.com:443 HTTP/1.0\n",
1340 shouldFail: true,
1341 expectedError: ":HTTPS_PROXY_REQUEST:",
1342 },
1343 {
1344 testType: serverTest,
1345 name: "Garbage",
1346 sendPrefix: "blah",
1347 shouldFail: true,
David Benjamin97760d52015-07-24 23:02:49 -04001348 expectedError: ":WRONG_VERSION_NUMBER:",
Adam Langley7c803a62015-06-15 15:35:05 -07001349 },
1350 {
Adam Langley7c803a62015-06-15 15:35:05 -07001351 name: "RSAEphemeralKey",
1352 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001353 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001354 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
1355 Bugs: ProtocolBugs{
1356 RSAEphemeralKey: true,
1357 },
1358 },
1359 shouldFail: true,
1360 expectedError: ":UNEXPECTED_MESSAGE:",
1361 },
1362 {
1363 name: "DisableEverything",
Steven Valdez4f94b1c2016-05-24 12:31:07 -04001364 flags: []string{"-no-tls13", "-no-tls12", "-no-tls11", "-no-tls1", "-no-ssl3"},
Adam Langley7c803a62015-06-15 15:35:05 -07001365 shouldFail: true,
1366 expectedError: ":WRONG_SSL_VERSION:",
1367 },
1368 {
1369 protocol: dtls,
1370 name: "DisableEverything-DTLS",
1371 flags: []string{"-no-tls12", "-no-tls1"},
1372 shouldFail: true,
1373 expectedError: ":WRONG_SSL_VERSION:",
1374 },
1375 {
Adam Langley7c803a62015-06-15 15:35:05 -07001376 protocol: dtls,
1377 testType: serverTest,
1378 name: "MTU",
1379 config: Config{
1380 Bugs: ProtocolBugs{
1381 MaxPacketLength: 256,
1382 },
1383 },
1384 flags: []string{"-mtu", "256"},
1385 },
1386 {
1387 protocol: dtls,
1388 testType: serverTest,
1389 name: "MTUExceeded",
1390 config: Config{
1391 Bugs: ProtocolBugs{
1392 MaxPacketLength: 255,
1393 },
1394 },
1395 flags: []string{"-mtu", "256"},
1396 shouldFail: true,
1397 expectedLocalError: "dtls: exceeded maximum packet length",
1398 },
1399 {
1400 name: "CertMismatchRSA",
1401 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001402 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001403 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001404 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001405 Bugs: ProtocolBugs{
1406 SendCipherSuite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1407 },
1408 },
1409 shouldFail: true,
1410 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1411 },
1412 {
1413 name: "CertMismatchECDSA",
1414 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001415 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001416 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07001417 Certificates: []Certificate{rsaCertificate},
Adam Langley7c803a62015-06-15 15:35:05 -07001418 Bugs: ProtocolBugs{
1419 SendCipherSuite: TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1420 },
1421 },
1422 shouldFail: true,
1423 expectedError: ":WRONG_CERTIFICATE_TYPE:",
1424 },
1425 {
1426 name: "EmptyCertificateList",
1427 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001428 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001429 Bugs: ProtocolBugs{
1430 EmptyCertificateList: true,
1431 },
1432 },
1433 shouldFail: true,
1434 expectedError: ":DECODE_ERROR:",
1435 },
1436 {
David Benjamin9ec1c752016-07-14 12:45:01 -04001437 name: "EmptyCertificateList-TLS13",
1438 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04001439 MaxVersion: VersionTLS13,
David Benjamin9ec1c752016-07-14 12:45:01 -04001440 Bugs: ProtocolBugs{
1441 EmptyCertificateList: true,
1442 },
1443 },
1444 shouldFail: true,
David Benjamin4087df92016-08-01 20:16:31 -04001445 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
David Benjamin9ec1c752016-07-14 12:45:01 -04001446 },
1447 {
Adam Langley7c803a62015-06-15 15:35:05 -07001448 name: "TLSFatalBadPackets",
1449 damageFirstWrite: true,
1450 shouldFail: true,
1451 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
1452 },
1453 {
1454 protocol: dtls,
1455 name: "DTLSIgnoreBadPackets",
1456 damageFirstWrite: true,
1457 },
1458 {
1459 protocol: dtls,
1460 name: "DTLSIgnoreBadPackets-Async",
1461 damageFirstWrite: true,
1462 flags: []string{"-async"},
1463 },
1464 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001465 name: "AppDataBeforeHandshake",
1466 config: Config{
1467 Bugs: ProtocolBugs{
1468 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1469 },
1470 },
1471 shouldFail: true,
1472 expectedError: ":UNEXPECTED_RECORD:",
1473 },
1474 {
1475 name: "AppDataBeforeHandshake-Empty",
1476 config: Config{
1477 Bugs: ProtocolBugs{
1478 AppDataBeforeHandshake: []byte{},
1479 },
1480 },
1481 shouldFail: true,
1482 expectedError: ":UNEXPECTED_RECORD:",
1483 },
1484 {
1485 protocol: dtls,
1486 name: "AppDataBeforeHandshake-DTLS",
1487 config: Config{
1488 Bugs: ProtocolBugs{
1489 AppDataBeforeHandshake: []byte("TEST MESSAGE"),
1490 },
1491 },
1492 shouldFail: true,
1493 expectedError: ":UNEXPECTED_RECORD:",
1494 },
1495 {
1496 protocol: dtls,
1497 name: "AppDataBeforeHandshake-DTLS-Empty",
1498 config: Config{
1499 Bugs: ProtocolBugs{
1500 AppDataBeforeHandshake: []byte{},
1501 },
1502 },
1503 shouldFail: true,
1504 expectedError: ":UNEXPECTED_RECORD:",
1505 },
1506 {
Adam Langley7c803a62015-06-15 15:35:05 -07001507 name: "AppDataAfterChangeCipherSpec",
1508 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001509 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001510 Bugs: ProtocolBugs{
1511 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1512 },
1513 },
1514 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001515 expectedError: ":UNEXPECTED_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001516 },
1517 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001518 name: "AppDataAfterChangeCipherSpec-Empty",
1519 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001520 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001521 Bugs: ProtocolBugs{
1522 AppDataAfterChangeCipherSpec: []byte{},
1523 },
1524 },
1525 shouldFail: true,
David Benjamina41280d2015-11-26 02:16:49 -05001526 expectedError: ":UNEXPECTED_RECORD:",
David Benjamin4cf369b2015-08-22 01:35:43 -04001527 },
1528 {
Adam Langley7c803a62015-06-15 15:35:05 -07001529 protocol: dtls,
1530 name: "AppDataAfterChangeCipherSpec-DTLS",
1531 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001532 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001533 Bugs: ProtocolBugs{
1534 AppDataAfterChangeCipherSpec: []byte("TEST MESSAGE"),
1535 },
1536 },
1537 // BoringSSL's DTLS implementation will drop the out-of-order
1538 // application data.
1539 },
1540 {
David Benjamin4cf369b2015-08-22 01:35:43 -04001541 protocol: dtls,
1542 name: "AppDataAfterChangeCipherSpec-DTLS-Empty",
1543 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001544 MaxVersion: VersionTLS12,
David Benjamin4cf369b2015-08-22 01:35:43 -04001545 Bugs: ProtocolBugs{
1546 AppDataAfterChangeCipherSpec: []byte{},
1547 },
1548 },
1549 // BoringSSL's DTLS implementation will drop the out-of-order
1550 // application data.
1551 },
1552 {
Adam Langley7c803a62015-06-15 15:35:05 -07001553 name: "AlertAfterChangeCipherSpec",
1554 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001555 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001556 Bugs: ProtocolBugs{
1557 AlertAfterChangeCipherSpec: alertRecordOverflow,
1558 },
1559 },
1560 shouldFail: true,
1561 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1562 },
1563 {
1564 protocol: dtls,
1565 name: "AlertAfterChangeCipherSpec-DTLS",
1566 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001567 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001568 Bugs: ProtocolBugs{
1569 AlertAfterChangeCipherSpec: alertRecordOverflow,
1570 },
1571 },
1572 shouldFail: true,
1573 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
1574 },
1575 {
1576 protocol: dtls,
1577 name: "ReorderHandshakeFragments-Small-DTLS",
1578 config: Config{
1579 Bugs: ProtocolBugs{
1580 ReorderHandshakeFragments: true,
1581 // Small enough that every handshake message is
1582 // fragmented.
1583 MaxHandshakeRecordLength: 2,
1584 },
1585 },
1586 },
1587 {
1588 protocol: dtls,
1589 name: "ReorderHandshakeFragments-Large-DTLS",
1590 config: Config{
1591 Bugs: ProtocolBugs{
1592 ReorderHandshakeFragments: true,
1593 // Large enough that no handshake message is
1594 // fragmented.
1595 MaxHandshakeRecordLength: 2048,
1596 },
1597 },
1598 },
1599 {
1600 protocol: dtls,
1601 name: "MixCompleteMessageWithFragments-DTLS",
1602 config: Config{
1603 Bugs: ProtocolBugs{
1604 ReorderHandshakeFragments: true,
1605 MixCompleteMessageWithFragments: true,
1606 MaxHandshakeRecordLength: 2,
1607 },
1608 },
1609 },
1610 {
1611 name: "SendInvalidRecordType",
1612 config: Config{
1613 Bugs: ProtocolBugs{
1614 SendInvalidRecordType: true,
1615 },
1616 },
1617 shouldFail: true,
1618 expectedError: ":UNEXPECTED_RECORD:",
1619 },
1620 {
1621 protocol: dtls,
1622 name: "SendInvalidRecordType-DTLS",
1623 config: Config{
1624 Bugs: ProtocolBugs{
1625 SendInvalidRecordType: true,
1626 },
1627 },
1628 shouldFail: true,
1629 expectedError: ":UNEXPECTED_RECORD:",
1630 },
1631 {
1632 name: "FalseStart-SkipServerSecondLeg",
1633 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001634 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001635 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1636 NextProtos: []string{"foo"},
1637 Bugs: ProtocolBugs{
1638 SkipNewSessionTicket: true,
1639 SkipChangeCipherSpec: true,
1640 SkipFinished: true,
1641 ExpectFalseStart: true,
1642 },
1643 },
1644 flags: []string{
1645 "-false-start",
1646 "-handshake-never-done",
1647 "-advertise-alpn", "\x03foo",
1648 },
1649 shimWritesFirst: true,
1650 shouldFail: true,
1651 expectedError: ":UNEXPECTED_RECORD:",
1652 },
1653 {
1654 name: "FalseStart-SkipServerSecondLeg-Implicit",
1655 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001656 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001657 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1658 NextProtos: []string{"foo"},
1659 Bugs: ProtocolBugs{
1660 SkipNewSessionTicket: true,
1661 SkipChangeCipherSpec: true,
1662 SkipFinished: true,
1663 },
1664 },
1665 flags: []string{
1666 "-implicit-handshake",
1667 "-false-start",
1668 "-handshake-never-done",
1669 "-advertise-alpn", "\x03foo",
1670 },
1671 shouldFail: true,
1672 expectedError: ":UNEXPECTED_RECORD:",
1673 },
1674 {
1675 testType: serverTest,
1676 name: "FailEarlyCallback",
1677 flags: []string{"-fail-early-callback"},
1678 shouldFail: true,
1679 expectedError: ":CONNECTION_REJECTED:",
David Benjamin2c66e072016-09-16 15:58:00 -04001680 expectedLocalError: "remote error: handshake failure",
Adam Langley7c803a62015-06-15 15:35:05 -07001681 },
1682 {
Adam Langley7c803a62015-06-15 15:35:05 -07001683 protocol: dtls,
1684 name: "FragmentMessageTypeMismatch-DTLS",
1685 config: Config{
1686 Bugs: ProtocolBugs{
1687 MaxHandshakeRecordLength: 2,
1688 FragmentMessageTypeMismatch: true,
1689 },
1690 },
1691 shouldFail: true,
1692 expectedError: ":FRAGMENT_MISMATCH:",
1693 },
1694 {
1695 protocol: dtls,
1696 name: "FragmentMessageLengthMismatch-DTLS",
1697 config: Config{
1698 Bugs: ProtocolBugs{
1699 MaxHandshakeRecordLength: 2,
1700 FragmentMessageLengthMismatch: true,
1701 },
1702 },
1703 shouldFail: true,
1704 expectedError: ":FRAGMENT_MISMATCH:",
1705 },
1706 {
1707 protocol: dtls,
1708 name: "SplitFragments-Header-DTLS",
1709 config: Config{
1710 Bugs: ProtocolBugs{
1711 SplitFragments: 2,
1712 },
1713 },
1714 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001715 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001716 },
1717 {
1718 protocol: dtls,
1719 name: "SplitFragments-Boundary-DTLS",
1720 config: Config{
1721 Bugs: ProtocolBugs{
1722 SplitFragments: dtlsRecordHeaderLen,
1723 },
1724 },
1725 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001726 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001727 },
1728 {
1729 protocol: dtls,
1730 name: "SplitFragments-Body-DTLS",
1731 config: Config{
1732 Bugs: ProtocolBugs{
1733 SplitFragments: dtlsRecordHeaderLen + 1,
1734 },
1735 },
1736 shouldFail: true,
David Benjaminc6604172016-06-02 16:38:35 -04001737 expectedError: ":BAD_HANDSHAKE_RECORD:",
Adam Langley7c803a62015-06-15 15:35:05 -07001738 },
1739 {
1740 protocol: dtls,
1741 name: "SendEmptyFragments-DTLS",
1742 config: Config{
1743 Bugs: ProtocolBugs{
1744 SendEmptyFragments: true,
1745 },
1746 },
1747 },
1748 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001749 name: "BadFinished-Client",
1750 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001751 MaxVersion: VersionTLS12,
David Benjaminbf82aed2016-03-01 22:57:40 -05001752 Bugs: ProtocolBugs{
1753 BadFinished: true,
1754 },
1755 },
1756 shouldFail: true,
1757 expectedError: ":DIGEST_CHECK_FAILED:",
1758 },
1759 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001760 name: "BadFinished-Client-TLS13",
1761 config: Config{
1762 MaxVersion: VersionTLS13,
1763 Bugs: ProtocolBugs{
1764 BadFinished: true,
1765 },
1766 },
1767 shouldFail: true,
1768 expectedError: ":DIGEST_CHECK_FAILED:",
1769 },
1770 {
David Benjaminbf82aed2016-03-01 22:57:40 -05001771 testType: serverTest,
1772 name: "BadFinished-Server",
Adam Langley7c803a62015-06-15 15:35:05 -07001773 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001774 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001775 Bugs: ProtocolBugs{
1776 BadFinished: true,
1777 },
1778 },
1779 shouldFail: true,
1780 expectedError: ":DIGEST_CHECK_FAILED:",
1781 },
1782 {
Steven Valdez143e8b32016-07-11 13:19:03 -04001783 testType: serverTest,
1784 name: "BadFinished-Server-TLS13",
1785 config: Config{
1786 MaxVersion: VersionTLS13,
1787 Bugs: ProtocolBugs{
1788 BadFinished: true,
1789 },
1790 },
1791 shouldFail: true,
1792 expectedError: ":DIGEST_CHECK_FAILED:",
1793 },
1794 {
Adam Langley7c803a62015-06-15 15:35:05 -07001795 name: "FalseStart-BadFinished",
1796 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001797 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001798 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1799 NextProtos: []string{"foo"},
1800 Bugs: ProtocolBugs{
1801 BadFinished: true,
1802 ExpectFalseStart: true,
1803 },
1804 },
1805 flags: []string{
1806 "-false-start",
1807 "-handshake-never-done",
1808 "-advertise-alpn", "\x03foo",
1809 },
1810 shimWritesFirst: true,
1811 shouldFail: true,
1812 expectedError: ":DIGEST_CHECK_FAILED:",
1813 },
1814 {
1815 name: "NoFalseStart-NoALPN",
1816 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001817 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001818 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
1819 Bugs: ProtocolBugs{
1820 ExpectFalseStart: true,
1821 AlertBeforeFalseStartTest: alertAccessDenied,
1822 },
1823 },
1824 flags: []string{
1825 "-false-start",
1826 },
1827 shimWritesFirst: true,
1828 shouldFail: true,
1829 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1830 expectedLocalError: "tls: peer did not false start: EOF",
1831 },
1832 {
1833 name: "NoFalseStart-NoAEAD",
1834 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001835 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001836 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
1837 NextProtos: []string{"foo"},
1838 Bugs: ProtocolBugs{
1839 ExpectFalseStart: true,
1840 AlertBeforeFalseStartTest: alertAccessDenied,
1841 },
1842 },
1843 flags: []string{
1844 "-false-start",
1845 "-advertise-alpn", "\x03foo",
1846 },
1847 shimWritesFirst: true,
1848 shouldFail: true,
1849 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1850 expectedLocalError: "tls: peer did not false start: EOF",
1851 },
1852 {
1853 name: "NoFalseStart-RSA",
1854 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001855 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001856 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
1857 NextProtos: []string{"foo"},
1858 Bugs: ProtocolBugs{
1859 ExpectFalseStart: true,
1860 AlertBeforeFalseStartTest: alertAccessDenied,
1861 },
1862 },
1863 flags: []string{
1864 "-false-start",
1865 "-advertise-alpn", "\x03foo",
1866 },
1867 shimWritesFirst: true,
1868 shouldFail: true,
1869 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1870 expectedLocalError: "tls: peer did not false start: EOF",
1871 },
1872 {
1873 name: "NoFalseStart-DHE_RSA",
1874 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07001875 MaxVersion: VersionTLS12,
Adam Langley7c803a62015-06-15 15:35:05 -07001876 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
1877 NextProtos: []string{"foo"},
1878 Bugs: ProtocolBugs{
1879 ExpectFalseStart: true,
1880 AlertBeforeFalseStartTest: alertAccessDenied,
1881 },
1882 },
1883 flags: []string{
1884 "-false-start",
1885 "-advertise-alpn", "\x03foo",
1886 },
1887 shimWritesFirst: true,
1888 shouldFail: true,
1889 expectedError: ":TLSV1_ALERT_ACCESS_DENIED:",
1890 expectedLocalError: "tls: peer did not false start: EOF",
1891 },
1892 {
Adam Langley7c803a62015-06-15 15:35:05 -07001893 protocol: dtls,
1894 name: "SendSplitAlert-Sync",
1895 config: Config{
1896 Bugs: ProtocolBugs{
1897 SendSplitAlert: true,
1898 },
1899 },
1900 },
1901 {
1902 protocol: dtls,
1903 name: "SendSplitAlert-Async",
1904 config: Config{
1905 Bugs: ProtocolBugs{
1906 SendSplitAlert: true,
1907 },
1908 },
1909 flags: []string{"-async"},
1910 },
1911 {
1912 protocol: dtls,
1913 name: "PackDTLSHandshake",
1914 config: Config{
1915 Bugs: ProtocolBugs{
1916 MaxHandshakeRecordLength: 2,
1917 PackHandshakeFragments: 20,
1918 PackHandshakeRecords: 200,
1919 },
1920 },
1921 },
1922 {
Adam Langley7c803a62015-06-15 15:35:05 -07001923 name: "SendEmptyRecords-Pass",
1924 sendEmptyRecords: 32,
1925 },
1926 {
1927 name: "SendEmptyRecords",
1928 sendEmptyRecords: 33,
1929 shouldFail: true,
1930 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1931 },
1932 {
1933 name: "SendEmptyRecords-Async",
1934 sendEmptyRecords: 33,
1935 flags: []string{"-async"},
1936 shouldFail: true,
1937 expectedError: ":TOO_MANY_EMPTY_FRAGMENTS:",
1938 },
1939 {
David Benjamine8e84b92016-08-03 15:39:47 -04001940 name: "SendWarningAlerts-Pass",
1941 config: Config{
1942 MaxVersion: VersionTLS12,
1943 },
Adam Langley7c803a62015-06-15 15:35:05 -07001944 sendWarningAlerts: 4,
1945 },
1946 {
David Benjamine8e84b92016-08-03 15:39:47 -04001947 protocol: dtls,
1948 name: "SendWarningAlerts-DTLS-Pass",
1949 config: Config{
1950 MaxVersion: VersionTLS12,
1951 },
Adam Langley7c803a62015-06-15 15:35:05 -07001952 sendWarningAlerts: 4,
1953 },
1954 {
David Benjamine8e84b92016-08-03 15:39:47 -04001955 name: "SendWarningAlerts-TLS13",
1956 config: Config{
1957 MaxVersion: VersionTLS13,
1958 },
1959 sendWarningAlerts: 4,
1960 shouldFail: true,
1961 expectedError: ":BAD_ALERT:",
1962 expectedLocalError: "remote error: error decoding message",
1963 },
1964 {
1965 name: "SendWarningAlerts",
1966 config: Config{
1967 MaxVersion: VersionTLS12,
1968 },
Adam Langley7c803a62015-06-15 15:35:05 -07001969 sendWarningAlerts: 5,
1970 shouldFail: true,
1971 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1972 },
1973 {
David Benjamine8e84b92016-08-03 15:39:47 -04001974 name: "SendWarningAlerts-Async",
1975 config: Config{
1976 MaxVersion: VersionTLS12,
1977 },
Adam Langley7c803a62015-06-15 15:35:05 -07001978 sendWarningAlerts: 5,
1979 flags: []string{"-async"},
1980 shouldFail: true,
1981 expectedError: ":TOO_MANY_WARNING_ALERTS:",
1982 },
David Benjaminba4594a2015-06-18 18:36:15 -04001983 {
Steven Valdez32635b82016-08-16 11:25:03 -04001984 name: "SendKeyUpdates",
1985 config: Config{
1986 MaxVersion: VersionTLS13,
1987 },
1988 sendKeyUpdates: 33,
1989 shouldFail: true,
1990 expectedError: ":TOO_MANY_KEY_UPDATES:",
1991 },
1992 {
David Benjaminba4594a2015-06-18 18:36:15 -04001993 name: "EmptySessionID",
1994 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04001995 MaxVersion: VersionTLS12,
David Benjaminba4594a2015-06-18 18:36:15 -04001996 SessionTicketsDisabled: true,
1997 },
1998 noSessionCache: true,
1999 flags: []string{"-expect-no-session"},
2000 },
David Benjamin30789da2015-08-29 22:56:45 -04002001 {
2002 name: "Unclean-Shutdown",
2003 config: Config{
2004 Bugs: ProtocolBugs{
2005 NoCloseNotify: true,
2006 ExpectCloseNotify: true,
2007 },
2008 },
2009 shimShutsDown: true,
2010 flags: []string{"-check-close-notify"},
2011 shouldFail: true,
2012 expectedError: "Unexpected SSL_shutdown result: -1 != 1",
2013 },
2014 {
2015 name: "Unclean-Shutdown-Ignored",
2016 config: Config{
2017 Bugs: ProtocolBugs{
2018 NoCloseNotify: true,
2019 },
2020 },
2021 shimShutsDown: true,
2022 },
David Benjamin4f75aaf2015-09-01 16:53:10 -04002023 {
David Benjaminfa214e42016-05-10 17:03:10 -04002024 name: "Unclean-Shutdown-Alert",
2025 config: Config{
2026 Bugs: ProtocolBugs{
2027 SendAlertOnShutdown: alertDecompressionFailure,
2028 ExpectCloseNotify: true,
2029 },
2030 },
2031 shimShutsDown: true,
2032 flags: []string{"-check-close-notify"},
2033 shouldFail: true,
2034 expectedError: ":SSLV3_ALERT_DECOMPRESSION_FAILURE:",
2035 },
2036 {
David Benjamin4f75aaf2015-09-01 16:53:10 -04002037 name: "LargePlaintext",
2038 config: Config{
2039 Bugs: ProtocolBugs{
2040 SendLargeRecords: true,
2041 },
2042 },
2043 messageLen: maxPlaintext + 1,
2044 shouldFail: true,
2045 expectedError: ":DATA_LENGTH_TOO_LONG:",
2046 },
2047 {
2048 protocol: dtls,
2049 name: "LargePlaintext-DTLS",
2050 config: Config{
2051 Bugs: ProtocolBugs{
2052 SendLargeRecords: true,
2053 },
2054 },
2055 messageLen: maxPlaintext + 1,
2056 shouldFail: true,
2057 expectedError: ":DATA_LENGTH_TOO_LONG:",
2058 },
2059 {
2060 name: "LargeCiphertext",
2061 config: Config{
2062 Bugs: ProtocolBugs{
2063 SendLargeRecords: true,
2064 },
2065 },
2066 messageLen: maxPlaintext * 2,
2067 shouldFail: true,
2068 expectedError: ":ENCRYPTED_LENGTH_TOO_LONG:",
2069 },
2070 {
2071 protocol: dtls,
2072 name: "LargeCiphertext-DTLS",
2073 config: Config{
2074 Bugs: ProtocolBugs{
2075 SendLargeRecords: true,
2076 },
2077 },
2078 messageLen: maxPlaintext * 2,
2079 // Unlike the other four cases, DTLS drops records which
2080 // are invalid before authentication, so the connection
2081 // does not fail.
2082 expectMessageDropped: true,
2083 },
David Benjamindd6fed92015-10-23 17:41:12 -04002084 {
David Benjaminef5dfd22015-12-06 13:17:07 -05002085 name: "BadHelloRequest-1",
2086 renegotiate: 1,
2087 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002088 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002089 Bugs: ProtocolBugs{
2090 BadHelloRequest: []byte{typeHelloRequest, 0, 0, 1, 1},
2091 },
2092 },
2093 flags: []string{
2094 "-renegotiate-freely",
2095 "-expect-total-renegotiations", "1",
2096 },
2097 shouldFail: true,
David Benjamin163f29a2016-07-28 11:05:58 -04002098 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
David Benjaminef5dfd22015-12-06 13:17:07 -05002099 },
2100 {
2101 name: "BadHelloRequest-2",
2102 renegotiate: 1,
2103 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002104 MaxVersion: VersionTLS12,
David Benjaminef5dfd22015-12-06 13:17:07 -05002105 Bugs: ProtocolBugs{
2106 BadHelloRequest: []byte{typeServerKeyExchange, 0, 0, 0},
2107 },
2108 },
2109 flags: []string{
2110 "-renegotiate-freely",
2111 "-expect-total-renegotiations", "1",
2112 },
2113 shouldFail: true,
2114 expectedError: ":BAD_HELLO_REQUEST:",
2115 },
David Benjaminef1b0092015-11-21 14:05:44 -05002116 {
2117 testType: serverTest,
2118 name: "SupportTicketsWithSessionID",
2119 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002120 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05002121 SessionTicketsDisabled: true,
2122 },
David Benjamin4c3ddf72016-06-29 18:13:53 -04002123 resumeConfig: &Config{
2124 MaxVersion: VersionTLS12,
2125 },
David Benjaminef1b0092015-11-21 14:05:44 -05002126 resumeSession: true,
2127 },
David Benjamin02edcd02016-07-27 17:40:37 -04002128 {
2129 protocol: dtls,
2130 name: "DTLS-SendExtraFinished",
2131 config: Config{
2132 Bugs: ProtocolBugs{
2133 SendExtraFinished: true,
2134 },
2135 },
2136 shouldFail: true,
2137 expectedError: ":UNEXPECTED_RECORD:",
2138 },
2139 {
2140 protocol: dtls,
2141 name: "DTLS-SendExtraFinished-Reordered",
2142 config: Config{
2143 Bugs: ProtocolBugs{
2144 MaxHandshakeRecordLength: 2,
2145 ReorderHandshakeFragments: true,
2146 SendExtraFinished: true,
2147 },
2148 },
2149 shouldFail: true,
2150 expectedError: ":UNEXPECTED_RECORD:",
2151 },
David Benjamine97fb482016-07-29 09:23:07 -04002152 {
2153 testType: serverTest,
2154 name: "V2ClientHello-EmptyRecordPrefix",
2155 config: Config{
2156 // Choose a cipher suite that does not involve
2157 // elliptic curves, so no extensions are
2158 // involved.
2159 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002160 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002161 Bugs: ProtocolBugs{
2162 SendV2ClientHello: true,
2163 },
2164 },
2165 sendPrefix: string([]byte{
2166 byte(recordTypeHandshake),
2167 3, 1, // version
2168 0, 0, // length
2169 }),
2170 // A no-op empty record may not be sent before V2ClientHello.
2171 shouldFail: true,
2172 expectedError: ":WRONG_VERSION_NUMBER:",
2173 },
2174 {
2175 testType: serverTest,
2176 name: "V2ClientHello-WarningAlertPrefix",
2177 config: Config{
2178 // Choose a cipher suite that does not involve
2179 // elliptic curves, so no extensions are
2180 // involved.
2181 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002182 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamine97fb482016-07-29 09:23:07 -04002183 Bugs: ProtocolBugs{
2184 SendV2ClientHello: true,
2185 },
2186 },
2187 sendPrefix: string([]byte{
2188 byte(recordTypeAlert),
2189 3, 1, // version
2190 0, 2, // length
2191 alertLevelWarning, byte(alertDecompressionFailure),
2192 }),
2193 // A no-op warning alert may not be sent before V2ClientHello.
2194 shouldFail: true,
2195 expectedError: ":WRONG_VERSION_NUMBER:",
2196 },
Steven Valdez1dc53d22016-07-26 12:27:38 -04002197 {
2198 testType: clientTest,
2199 name: "KeyUpdate",
2200 config: Config{
2201 MaxVersion: VersionTLS13,
2202 Bugs: ProtocolBugs{
2203 SendKeyUpdateBeforeEveryAppDataRecord: true,
2204 },
2205 },
2206 },
David Benjaminabe94e32016-09-04 14:18:58 -04002207 {
2208 name: "SendSNIWarningAlert",
2209 config: Config{
2210 MaxVersion: VersionTLS12,
2211 Bugs: ProtocolBugs{
2212 SendSNIWarningAlert: true,
2213 },
2214 },
2215 },
David Benjaminc241d792016-09-09 10:34:20 -04002216 {
2217 testType: serverTest,
2218 name: "ExtraCompressionMethods-TLS12",
2219 config: Config{
2220 MaxVersion: VersionTLS12,
2221 Bugs: ProtocolBugs{
2222 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2223 },
2224 },
2225 },
2226 {
2227 testType: serverTest,
2228 name: "ExtraCompressionMethods-TLS13",
2229 config: Config{
2230 MaxVersion: VersionTLS13,
2231 Bugs: ProtocolBugs{
2232 SendCompressionMethods: []byte{1, 2, 3, compressionNone, 4, 5, 6},
2233 },
2234 },
2235 shouldFail: true,
2236 expectedError: ":INVALID_COMPRESSION_LIST:",
2237 expectedLocalError: "remote error: illegal parameter",
2238 },
2239 {
2240 testType: serverTest,
2241 name: "NoNullCompression-TLS12",
2242 config: Config{
2243 MaxVersion: VersionTLS12,
2244 Bugs: ProtocolBugs{
2245 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2246 },
2247 },
2248 shouldFail: true,
2249 expectedError: ":NO_COMPRESSION_SPECIFIED:",
2250 expectedLocalError: "remote error: illegal parameter",
2251 },
2252 {
2253 testType: serverTest,
2254 name: "NoNullCompression-TLS13",
2255 config: Config{
2256 MaxVersion: VersionTLS13,
2257 Bugs: ProtocolBugs{
2258 SendCompressionMethods: []byte{1, 2, 3, 4, 5, 6},
2259 },
2260 },
2261 shouldFail: true,
2262 expectedError: ":INVALID_COMPRESSION_LIST:",
2263 expectedLocalError: "remote error: illegal parameter",
2264 },
David Benjamin65ac9972016-09-02 21:35:25 -04002265 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002266 name: "GREASE-Client-TLS12",
David Benjamin65ac9972016-09-02 21:35:25 -04002267 config: Config{
2268 MaxVersion: VersionTLS12,
2269 Bugs: ProtocolBugs{
2270 ExpectGREASE: true,
2271 },
2272 },
2273 flags: []string{"-enable-grease"},
2274 },
2275 {
David Benjamin1a5e8ec2016-10-07 15:19:18 -04002276 name: "GREASE-Client-TLS13",
2277 config: Config{
2278 MaxVersion: VersionTLS13,
2279 Bugs: ProtocolBugs{
2280 ExpectGREASE: true,
2281 },
2282 },
2283 flags: []string{"-enable-grease"},
2284 },
2285 {
2286 testType: serverTest,
2287 name: "GREASE-Server-TLS13",
David Benjamin65ac9972016-09-02 21:35:25 -04002288 config: Config{
2289 MaxVersion: VersionTLS13,
2290 Bugs: ProtocolBugs{
2291 ExpectGREASE: true,
2292 },
2293 },
2294 flags: []string{"-enable-grease"},
2295 },
Adam Langley7c803a62015-06-15 15:35:05 -07002296 }
Adam Langley7c803a62015-06-15 15:35:05 -07002297 testCases = append(testCases, basicTests...)
David Benjamina252b342016-09-26 19:57:53 -04002298
2299 // Test that very large messages can be received.
2300 cert := rsaCertificate
2301 for i := 0; i < 50; i++ {
2302 cert.Certificate = append(cert.Certificate, cert.Certificate[0])
2303 }
2304 testCases = append(testCases, testCase{
2305 name: "LargeMessage",
2306 config: Config{
2307 Certificates: []Certificate{cert},
2308 },
2309 })
2310 testCases = append(testCases, testCase{
2311 protocol: dtls,
2312 name: "LargeMessage-DTLS",
2313 config: Config{
2314 Certificates: []Certificate{cert},
2315 },
2316 })
2317
2318 // They are rejected if the maximum certificate chain length is capped.
2319 testCases = append(testCases, testCase{
2320 name: "LargeMessage-Reject",
2321 config: Config{
2322 Certificates: []Certificate{cert},
2323 },
2324 flags: []string{"-max-cert-list", "16384"},
2325 shouldFail: true,
2326 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2327 })
2328 testCases = append(testCases, testCase{
2329 protocol: dtls,
2330 name: "LargeMessage-Reject-DTLS",
2331 config: Config{
2332 Certificates: []Certificate{cert},
2333 },
2334 flags: []string{"-max-cert-list", "16384"},
2335 shouldFail: true,
2336 expectedError: ":EXCESSIVE_MESSAGE_SIZE:",
2337 })
Adam Langley7c803a62015-06-15 15:35:05 -07002338}
2339
Adam Langley95c29f32014-06-20 12:00:00 -07002340func addCipherSuiteTests() {
David Benjamine470e662016-07-18 15:47:32 +02002341 const bogusCipher = 0xfe00
2342
Adam Langley95c29f32014-06-20 12:00:00 -07002343 for _, suite := range testCipherSuites {
David Benjamin48cae082014-10-27 01:06:24 -04002344 const psk = "12345"
2345 const pskIdentity = "luggage combo"
2346
Adam Langley95c29f32014-06-20 12:00:00 -07002347 var cert Certificate
David Benjamin025b3d32014-07-01 19:53:04 -04002348 var certFile string
2349 var keyFile string
David Benjamin8b8c0062014-11-23 02:47:52 -05002350 if hasComponent(suite.name, "ECDSA") {
David Benjamin33863262016-07-08 17:20:12 -07002351 cert = ecdsaP256Certificate
2352 certFile = ecdsaP256CertificateFile
2353 keyFile = ecdsaP256KeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002354 } else {
David Benjamin33863262016-07-08 17:20:12 -07002355 cert = rsaCertificate
David Benjamin025b3d32014-07-01 19:53:04 -04002356 certFile = rsaCertificateFile
2357 keyFile = rsaKeyFile
Adam Langley95c29f32014-06-20 12:00:00 -07002358 }
2359
David Benjamin48cae082014-10-27 01:06:24 -04002360 var flags []string
David Benjamin8b8c0062014-11-23 02:47:52 -05002361 if hasComponent(suite.name, "PSK") {
David Benjamin48cae082014-10-27 01:06:24 -04002362 flags = append(flags,
2363 "-psk", psk,
2364 "-psk-identity", pskIdentity)
2365 }
Matt Braithwaiteaf096752015-09-02 19:48:16 -07002366 if hasComponent(suite.name, "NULL") {
2367 // NULL ciphers must be explicitly enabled.
2368 flags = append(flags, "-cipher", "DEFAULT:NULL-SHA")
2369 }
Matt Braithwaite053931e2016-05-25 12:06:05 -07002370 if hasComponent(suite.name, "CECPQ1") {
2371 // CECPQ1 ciphers must be explicitly enabled.
2372 flags = append(flags, "-cipher", "DEFAULT:kCECPQ1")
2373 }
David Benjamin881f1962016-08-10 18:29:12 -04002374 if hasComponent(suite.name, "ECDHE-PSK") && hasComponent(suite.name, "GCM") {
2375 // ECDHE_PSK AES_GCM ciphers must be explicitly enabled
2376 // for now.
2377 flags = append(flags, "-cipher", suite.name)
2378 }
David Benjamin48cae082014-10-27 01:06:24 -04002379
Adam Langley95c29f32014-06-20 12:00:00 -07002380 for _, ver := range tlsVersions {
David Benjamin0407e762016-06-17 16:41:18 -04002381 for _, protocol := range []protocol{tls, dtls} {
2382 var prefix string
2383 if protocol == dtls {
2384 if !ver.hasDTLS {
2385 continue
2386 }
2387 prefix = "D"
2388 }
Adam Langley95c29f32014-06-20 12:00:00 -07002389
David Benjamin0407e762016-06-17 16:41:18 -04002390 var shouldServerFail, shouldClientFail bool
2391 if hasComponent(suite.name, "ECDHE") && ver.version == VersionSSL30 {
2392 // BoringSSL clients accept ECDHE on SSLv3, but
2393 // a BoringSSL server will never select it
2394 // because the extension is missing.
2395 shouldServerFail = true
2396 }
2397 if isTLS12Only(suite.name) && ver.version < VersionTLS12 {
2398 shouldClientFail = true
2399 shouldServerFail = true
2400 }
David Benjamin54c217c2016-07-13 12:35:25 -04002401 if !isTLS13Suite(suite.name) && ver.version >= VersionTLS13 {
Nick Harper1fd39d82016-06-14 18:14:35 -07002402 shouldClientFail = true
2403 shouldServerFail = true
2404 }
Steven Valdez803c77a2016-09-06 14:13:43 -04002405 if isTLS13Suite(suite.name) && ver.version < VersionTLS13 {
2406 shouldClientFail = true
2407 shouldServerFail = true
2408 }
David Benjamin0407e762016-06-17 16:41:18 -04002409 if !isDTLSCipher(suite.name) && protocol == dtls {
2410 shouldClientFail = true
2411 shouldServerFail = true
2412 }
David Benjamin4298d772015-12-19 00:18:25 -05002413
David Benjamin5ecb88b2016-10-04 17:51:35 -04002414 var sendCipherSuite uint16
David Benjamin0407e762016-06-17 16:41:18 -04002415 var expectedServerError, expectedClientError string
David Benjamin5ecb88b2016-10-04 17:51:35 -04002416 serverCipherSuites := []uint16{suite.id}
David Benjamin0407e762016-06-17 16:41:18 -04002417 if shouldServerFail {
2418 expectedServerError = ":NO_SHARED_CIPHER:"
2419 }
2420 if shouldClientFail {
2421 expectedClientError = ":WRONG_CIPHER_RETURNED:"
David Benjamin5ecb88b2016-10-04 17:51:35 -04002422 // Configure the server to select ciphers as normal but
2423 // select an incompatible cipher in ServerHello.
2424 serverCipherSuites = nil
2425 sendCipherSuite = suite.id
David Benjamin0407e762016-06-17 16:41:18 -04002426 }
David Benjamin025b3d32014-07-01 19:53:04 -04002427
David Benjamin6fd297b2014-08-11 18:43:38 -04002428 testCases = append(testCases, testCase{
2429 testType: serverTest,
David Benjamin0407e762016-06-17 16:41:18 -04002430 protocol: protocol,
2431
2432 name: prefix + ver.name + "-" + suite.name + "-server",
David Benjamin6fd297b2014-08-11 18:43:38 -04002433 config: Config{
David Benjamin48cae082014-10-27 01:06:24 -04002434 MinVersion: ver.version,
2435 MaxVersion: ver.version,
2436 CipherSuites: []uint16{suite.id},
2437 Certificates: []Certificate{cert},
2438 PreSharedKey: []byte(psk),
2439 PreSharedKeyIdentity: pskIdentity,
David Benjamin0407e762016-06-17 16:41:18 -04002440 Bugs: ProtocolBugs{
David Benjamin5ecb88b2016-10-04 17:51:35 -04002441 AdvertiseAllConfiguredCiphers: true,
David Benjamin0407e762016-06-17 16:41:18 -04002442 },
David Benjamin6fd297b2014-08-11 18:43:38 -04002443 },
2444 certFile: certFile,
2445 keyFile: keyFile,
David Benjamin48cae082014-10-27 01:06:24 -04002446 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002447 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002448 shouldFail: shouldServerFail,
2449 expectedError: expectedServerError,
2450 })
2451
2452 testCases = append(testCases, testCase{
2453 testType: clientTest,
2454 protocol: protocol,
2455 name: prefix + ver.name + "-" + suite.name + "-client",
2456 config: Config{
2457 MinVersion: ver.version,
2458 MaxVersion: ver.version,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002459 CipherSuites: serverCipherSuites,
David Benjamin0407e762016-06-17 16:41:18 -04002460 Certificates: []Certificate{cert},
2461 PreSharedKey: []byte(psk),
2462 PreSharedKeyIdentity: pskIdentity,
2463 Bugs: ProtocolBugs{
David Benjamin9acf0ca2016-06-25 00:01:28 -04002464 IgnorePeerCipherPreferences: shouldClientFail,
David Benjamin5ecb88b2016-10-04 17:51:35 -04002465 SendCipherSuite: sendCipherSuite,
David Benjamin0407e762016-06-17 16:41:18 -04002466 },
2467 },
2468 flags: flags,
Steven Valdez4aa154e2016-07-29 14:32:55 -04002469 resumeSession: true,
David Benjamin0407e762016-06-17 16:41:18 -04002470 shouldFail: shouldClientFail,
2471 expectedError: expectedClientError,
David Benjamin6fd297b2014-08-11 18:43:38 -04002472 })
David Benjamin2c99d282015-09-01 10:23:00 -04002473
Nick Harper1fd39d82016-06-14 18:14:35 -07002474 if !shouldClientFail {
2475 // Ensure the maximum record size is accepted.
2476 testCases = append(testCases, testCase{
2477 name: prefix + ver.name + "-" + suite.name + "-LargeRecord",
2478 config: Config{
2479 MinVersion: ver.version,
2480 MaxVersion: ver.version,
2481 CipherSuites: []uint16{suite.id},
2482 Certificates: []Certificate{cert},
2483 PreSharedKey: []byte(psk),
2484 PreSharedKeyIdentity: pskIdentity,
2485 },
2486 flags: flags,
2487 messageLen: maxPlaintext,
2488 })
2489 }
2490 }
David Benjamin2c99d282015-09-01 10:23:00 -04002491 }
Adam Langley95c29f32014-06-20 12:00:00 -07002492 }
Adam Langleya7997f12015-05-14 17:38:50 -07002493
2494 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002495 name: "NoSharedCipher",
2496 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002497 MaxVersion: VersionTLS12,
2498 CipherSuites: []uint16{},
2499 },
2500 shouldFail: true,
2501 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2502 })
2503
2504 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04002505 name: "NoSharedCipher-TLS13",
2506 config: Config{
2507 MaxVersion: VersionTLS13,
2508 CipherSuites: []uint16{},
2509 },
2510 shouldFail: true,
2511 expectedError: ":HANDSHAKE_FAILURE_ON_CLIENT_HELLO:",
2512 })
2513
2514 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04002515 name: "UnsupportedCipherSuite",
2516 config: Config{
2517 MaxVersion: VersionTLS12,
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002518 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002519 Bugs: ProtocolBugs{
2520 IgnorePeerCipherPreferences: true,
2521 },
2522 },
Matt Braithwaite9c8c4182016-08-24 14:36:54 -07002523 flags: []string{"-cipher", "DEFAULT:!AES"},
David Benjamin4c3ddf72016-06-29 18:13:53 -04002524 shouldFail: true,
2525 expectedError: ":WRONG_CIPHER_RETURNED:",
2526 })
2527
2528 testCases = append(testCases, testCase{
David Benjamine470e662016-07-18 15:47:32 +02002529 name: "ServerHelloBogusCipher",
2530 config: Config{
2531 MaxVersion: VersionTLS12,
2532 Bugs: ProtocolBugs{
2533 SendCipherSuite: bogusCipher,
2534 },
2535 },
2536 shouldFail: true,
2537 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2538 })
2539 testCases = append(testCases, testCase{
2540 name: "ServerHelloBogusCipher-TLS13",
2541 config: Config{
2542 MaxVersion: VersionTLS13,
2543 Bugs: ProtocolBugs{
2544 SendCipherSuite: bogusCipher,
2545 },
2546 },
2547 shouldFail: true,
2548 expectedError: ":UNKNOWN_CIPHER_RETURNED:",
2549 })
2550
2551 testCases = append(testCases, testCase{
Adam Langleya7997f12015-05-14 17:38:50 -07002552 name: "WeakDH",
2553 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002554 MaxVersion: VersionTLS12,
Adam Langleya7997f12015-05-14 17:38:50 -07002555 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2556 Bugs: ProtocolBugs{
2557 // This is a 1023-bit prime number, generated
2558 // with:
2559 // openssl gendh 1023 | openssl asn1parse -i
2560 DHGroupPrime: bigFromHex("518E9B7930CE61C6E445C8360584E5FC78D9137C0FFDC880B495D5338ADF7689951A6821C17A76B3ACB8E0156AEA607B7EC406EBEDBB84D8376EB8FE8F8BA1433488BEE0C3EDDFD3A32DBB9481980A7AF6C96BFCF490A094CFFB2B8192C1BB5510B77B658436E27C2D4D023FE3718222AB0CA1273995B51F6D625A4944D0DD4B"),
2561 },
2562 },
2563 shouldFail: true,
David Benjamincd24a392015-11-11 13:23:05 -08002564 expectedError: ":BAD_DH_P_LENGTH:",
Adam Langleya7997f12015-05-14 17:38:50 -07002565 })
Adam Langleycef75832015-09-03 14:51:12 -07002566
David Benjamincd24a392015-11-11 13:23:05 -08002567 testCases = append(testCases, testCase{
2568 name: "SillyDH",
2569 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002570 MaxVersion: VersionTLS12,
David Benjamincd24a392015-11-11 13:23:05 -08002571 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2572 Bugs: ProtocolBugs{
2573 // This is a 4097-bit prime number, generated
2574 // with:
2575 // openssl gendh 4097 | openssl asn1parse -i
2576 DHGroupPrime: bigFromHex("01D366FA64A47419B0CD4A45918E8D8C8430F674621956A9F52B0CA592BC104C6E38D60C58F2CA66792A2B7EBDC6F8FFE75AB7D6862C261F34E96A2AEEF53AB7C21365C2E8FB0582F71EB57B1C227C0E55AE859E9904A25EFECD7B435C4D4357BD840B03649D4A1F8037D89EA4E1967DBEEF1CC17A6111C48F12E9615FFF336D3F07064CB17C0B765A012C850B9E3AA7A6984B96D8C867DDC6D0F4AB52042572244796B7ECFF681CD3B3E2E29AAECA391A775BEE94E502FB15881B0F4AC60314EA947C0C82541C3D16FD8C0E09BB7F8F786582032859D9C13187CE6C0CB6F2D3EE6C3C9727C15F14B21D3CD2E02BDB9D119959B0E03DC9E5A91E2578762300B1517D2352FC1D0BB934A4C3E1B20CE9327DB102E89A6C64A8C3148EDFC5A94913933853442FA84451B31FD21E492F92DD5488E0D871AEBFE335A4B92431DEC69591548010E76A5B365D346786E9A2D3E589867D796AA5E25211201D757560D318A87DFB27F3E625BC373DB48BF94A63161C674C3D4265CB737418441B7650EABC209CF675A439BEB3E9D1AA1B79F67198A40CEFD1C89144F7D8BAF61D6AD36F466DA546B4174A0E0CAF5BD788C8243C7C2DDDCC3DB6FC89F12F17D19FBD9B0BC76FE92891CD6BA07BEA3B66EF12D0D85E788FD58675C1B0FBD16029DCC4D34E7A1A41471BDEDF78BF591A8B4E96D88BEC8EDC093E616292BFC096E69A916E8D624B"),
2577 },
2578 },
2579 shouldFail: true,
2580 expectedError: ":DH_P_TOO_LONG:",
2581 })
2582
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002583 // This test ensures that Diffie-Hellman public values are padded with
2584 // zeros so that they're the same length as the prime. This is to avoid
2585 // hitting a bug in yaSSL.
2586 testCases = append(testCases, testCase{
2587 testType: serverTest,
2588 name: "DHPublicValuePadded",
2589 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002590 MaxVersion: VersionTLS12,
Adam Langleyc4f25ce2015-11-26 16:39:08 -08002591 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
2592 Bugs: ProtocolBugs{
2593 RequireDHPublicValueLen: (1025 + 7) / 8,
2594 },
2595 },
2596 flags: []string{"-use-sparse-dh-prime"},
2597 })
David Benjamincd24a392015-11-11 13:23:05 -08002598
David Benjamin241ae832016-01-15 03:04:54 -05002599 // The server must be tolerant to bogus ciphers.
David Benjamin241ae832016-01-15 03:04:54 -05002600 testCases = append(testCases, testCase{
2601 testType: serverTest,
2602 name: "UnknownCipher",
2603 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002604 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05002605 CipherSuites: []uint16{bogusCipher, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002606 Bugs: ProtocolBugs{
2607 AdvertiseAllConfiguredCiphers: true,
2608 },
2609 },
2610 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002611
2612 // The server must be tolerant to bogus ciphers.
David Benjamin5ecb88b2016-10-04 17:51:35 -04002613 testCases = append(testCases, testCase{
2614 testType: serverTest,
2615 name: "UnknownCipher-TLS13",
2616 config: Config{
2617 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04002618 CipherSuites: []uint16{bogusCipher, TLS_AES_128_GCM_SHA256},
David Benjamin5ecb88b2016-10-04 17:51:35 -04002619 Bugs: ProtocolBugs{
2620 AdvertiseAllConfiguredCiphers: true,
2621 },
David Benjamin241ae832016-01-15 03:04:54 -05002622 },
2623 })
2624
David Benjamin78679342016-09-16 19:42:05 -04002625 // Test empty ECDHE_PSK identity hints work as expected.
2626 testCases = append(testCases, testCase{
2627 name: "EmptyECDHEPSKHint",
2628 config: Config{
2629 MaxVersion: VersionTLS12,
2630 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
2631 PreSharedKey: []byte("secret"),
2632 },
2633 flags: []string{"-psk", "secret"},
2634 })
2635
2636 // Test empty PSK identity hints work as expected, even if an explicit
2637 // ServerKeyExchange is sent.
2638 testCases = append(testCases, testCase{
2639 name: "ExplicitEmptyPSKHint",
2640 config: Config{
2641 MaxVersion: VersionTLS12,
2642 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2643 PreSharedKey: []byte("secret"),
2644 Bugs: ProtocolBugs{
2645 AlwaysSendPreSharedKeyIdentityHint: true,
2646 },
2647 },
2648 flags: []string{"-psk", "secret"},
2649 })
2650
Adam Langleycef75832015-09-03 14:51:12 -07002651 // versionSpecificCiphersTest specifies a test for the TLS 1.0 and TLS
2652 // 1.1 specific cipher suite settings. A server is setup with the given
2653 // cipher lists and then a connection is made for each member of
2654 // expectations. The cipher suite that the server selects must match
2655 // the specified one.
2656 var versionSpecificCiphersTest = []struct {
2657 ciphersDefault, ciphersTLS10, ciphersTLS11 string
2658 // expectations is a map from TLS version to cipher suite id.
2659 expectations map[uint16]uint16
2660 }{
2661 {
2662 // Test that the null case (where no version-specific ciphers are set)
2663 // works as expected.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002664 "DES-CBC3-SHA:AES128-SHA", // default ciphers
2665 "", // no ciphers specifically for TLS ≥ 1.0
2666 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002667 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002668 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2669 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2670 VersionTLS11: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2671 VersionTLS12: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002672 },
2673 },
2674 {
2675 // With ciphers_tls10 set, TLS 1.0, 1.1 and 1.2 should get a different
2676 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002677 "DES-CBC3-SHA:AES128-SHA", // default
2678 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2679 "", // no ciphers specifically for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002680 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002681 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002682 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2683 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2684 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2685 },
2686 },
2687 {
2688 // With ciphers_tls11 set, TLS 1.1 and 1.2 should get a different
2689 // cipher.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002690 "DES-CBC3-SHA:AES128-SHA", // default
2691 "", // no ciphers specifically for TLS ≥ 1.0
2692 "AES128-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002693 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002694 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
2695 VersionTLS10: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002696 VersionTLS11: TLS_RSA_WITH_AES_128_CBC_SHA,
2697 VersionTLS12: TLS_RSA_WITH_AES_128_CBC_SHA,
2698 },
2699 },
2700 {
2701 // With both ciphers_tls10 and ciphers_tls11 set, ciphers_tls11 should
2702 // mask ciphers_tls10 for TLS 1.1 and 1.2.
Matt Braithwaite07e78062016-08-21 14:50:43 -07002703 "DES-CBC3-SHA:AES128-SHA", // default
2704 "AES128-SHA", // these ciphers for TLS ≥ 1.0
2705 "AES256-SHA", // these ciphers for TLS ≥ 1.1
Adam Langleycef75832015-09-03 14:51:12 -07002706 map[uint16]uint16{
Matt Braithwaite07e78062016-08-21 14:50:43 -07002707 VersionSSL30: TLS_RSA_WITH_3DES_EDE_CBC_SHA,
Adam Langleycef75832015-09-03 14:51:12 -07002708 VersionTLS10: TLS_RSA_WITH_AES_128_CBC_SHA,
2709 VersionTLS11: TLS_RSA_WITH_AES_256_CBC_SHA,
2710 VersionTLS12: TLS_RSA_WITH_AES_256_CBC_SHA,
2711 },
2712 },
2713 }
2714
2715 for i, test := range versionSpecificCiphersTest {
2716 for version, expectedCipherSuite := range test.expectations {
2717 flags := []string{"-cipher", test.ciphersDefault}
2718 if len(test.ciphersTLS10) > 0 {
2719 flags = append(flags, "-cipher-tls10", test.ciphersTLS10)
2720 }
2721 if len(test.ciphersTLS11) > 0 {
2722 flags = append(flags, "-cipher-tls11", test.ciphersTLS11)
2723 }
2724
2725 testCases = append(testCases, testCase{
2726 testType: serverTest,
2727 name: fmt.Sprintf("VersionSpecificCiphersTest-%d-%x", i, version),
2728 config: Config{
2729 MaxVersion: version,
2730 MinVersion: version,
Matt Braithwaite07e78062016-08-21 14:50:43 -07002731 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 -07002732 },
2733 flags: flags,
2734 expectedCipher: expectedCipherSuite,
2735 })
2736 }
2737 }
Adam Langley95c29f32014-06-20 12:00:00 -07002738}
2739
2740func addBadECDSASignatureTests() {
2741 for badR := BadValue(1); badR < NumBadValues; badR++ {
2742 for badS := BadValue(1); badS < NumBadValues; badS++ {
David Benjamin025b3d32014-07-01 19:53:04 -04002743 testCases = append(testCases, testCase{
Adam Langley95c29f32014-06-20 12:00:00 -07002744 name: fmt.Sprintf("BadECDSA-%d-%d", badR, badS),
2745 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04002746 MaxVersion: VersionTLS12,
Adam Langley95c29f32014-06-20 12:00:00 -07002747 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07002748 Certificates: []Certificate{ecdsaP256Certificate},
Adam Langley95c29f32014-06-20 12:00:00 -07002749 Bugs: ProtocolBugs{
2750 BadECDSAR: badR,
2751 BadECDSAS: badS,
2752 },
2753 },
2754 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002755 expectedError: ":BAD_SIGNATURE:",
Adam Langley95c29f32014-06-20 12:00:00 -07002756 })
Steven Valdez803c77a2016-09-06 14:13:43 -04002757 testCases = append(testCases, testCase{
2758 name: fmt.Sprintf("BadECDSA-%d-%d-TLS13", badR, badS),
2759 config: Config{
2760 MaxVersion: VersionTLS13,
2761 Certificates: []Certificate{ecdsaP256Certificate},
2762 Bugs: ProtocolBugs{
2763 BadECDSAR: badR,
2764 BadECDSAS: badS,
2765 },
2766 },
2767 shouldFail: true,
2768 expectedError: ":BAD_SIGNATURE:",
2769 })
Adam Langley95c29f32014-06-20 12:00:00 -07002770 }
2771 }
2772}
2773
Adam Langley80842bd2014-06-20 12:00:00 -07002774func addCBCPaddingTests() {
David Benjamin025b3d32014-07-01 19:53:04 -04002775 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002776 name: "MaxCBCPadding",
2777 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002778 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002779 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2780 Bugs: ProtocolBugs{
2781 MaxPadding: true,
2782 },
2783 },
2784 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2785 })
David Benjamin025b3d32014-07-01 19:53:04 -04002786 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002787 name: "BadCBCPadding",
2788 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002789 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002790 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2791 Bugs: ProtocolBugs{
2792 PaddingFirstByteBad: true,
2793 },
2794 },
2795 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002796 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002797 })
2798 // OpenSSL previously had an issue where the first byte of padding in
2799 // 255 bytes of padding wasn't checked.
David Benjamin025b3d32014-07-01 19:53:04 -04002800 testCases = append(testCases, testCase{
Adam Langley80842bd2014-06-20 12:00:00 -07002801 name: "BadCBCPadding255",
2802 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002803 MaxVersion: VersionTLS12,
Adam Langley80842bd2014-06-20 12:00:00 -07002804 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2805 Bugs: ProtocolBugs{
2806 MaxPadding: true,
2807 PaddingFirstByteBadIf255: true,
2808 },
2809 },
2810 messageLen: 12, // 20 bytes of SHA-1 + 12 == 0 % block size
2811 shouldFail: true,
David Benjamin11d50f92016-03-10 15:55:45 -05002812 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
Adam Langley80842bd2014-06-20 12:00:00 -07002813 })
2814}
2815
Kenny Root7fdeaf12014-08-05 15:23:37 -07002816func addCBCSplittingTests() {
2817 testCases = append(testCases, testCase{
2818 name: "CBCRecordSplitting",
2819 config: Config{
2820 MaxVersion: VersionTLS10,
2821 MinVersion: VersionTLS10,
2822 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2823 },
David Benjaminac8302a2015-09-01 17:18:15 -04002824 messageLen: -1, // read until EOF
2825 resumeSession: true,
Kenny Root7fdeaf12014-08-05 15:23:37 -07002826 flags: []string{
2827 "-async",
2828 "-write-different-record-sizes",
2829 "-cbc-record-splitting",
2830 },
David Benjamina8e3e0e2014-08-06 22:11:10 -04002831 })
2832 testCases = append(testCases, testCase{
Kenny Root7fdeaf12014-08-05 15:23:37 -07002833 name: "CBCRecordSplittingPartialWrite",
2834 config: Config{
2835 MaxVersion: VersionTLS10,
2836 MinVersion: VersionTLS10,
2837 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA},
2838 },
2839 messageLen: -1, // read until EOF
2840 flags: []string{
2841 "-async",
2842 "-write-different-record-sizes",
2843 "-cbc-record-splitting",
2844 "-partial-write",
2845 },
2846 })
2847}
2848
David Benjamin636293b2014-07-08 17:59:18 -04002849func addClientAuthTests() {
David Benjamin407a10c2014-07-16 12:58:59 -04002850 // Add a dummy cert pool to stress certificate authority parsing.
2851 // TODO(davidben): Add tests that those values parse out correctly.
2852 certPool := x509.NewCertPool()
2853 cert, err := x509.ParseCertificate(rsaCertificate.Certificate[0])
2854 if err != nil {
2855 panic(err)
2856 }
2857 certPool.AddCert(cert)
2858
David Benjamin636293b2014-07-08 17:59:18 -04002859 for _, ver := range tlsVersions {
David Benjamin636293b2014-07-08 17:59:18 -04002860 testCases = append(testCases, testCase{
2861 testType: clientTest,
David Benjamin67666e72014-07-12 15:47:52 -04002862 name: ver.name + "-Client-ClientAuth-RSA",
David Benjamin636293b2014-07-08 17:59:18 -04002863 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002864 MinVersion: ver.version,
2865 MaxVersion: ver.version,
2866 ClientAuth: RequireAnyClientCert,
2867 ClientCAs: certPool,
David Benjamin636293b2014-07-08 17:59:18 -04002868 },
2869 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07002870 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
2871 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin636293b2014-07-08 17:59:18 -04002872 },
2873 })
2874 testCases = append(testCases, testCase{
David Benjamin67666e72014-07-12 15:47:52 -04002875 testType: serverTest,
2876 name: ver.name + "-Server-ClientAuth-RSA",
2877 config: Config{
David Benjamine098ec22014-08-27 23:13:20 -04002878 MinVersion: ver.version,
2879 MaxVersion: ver.version,
David Benjamin67666e72014-07-12 15:47:52 -04002880 Certificates: []Certificate{rsaCertificate},
2881 },
2882 flags: []string{"-require-any-client-certificate"},
2883 })
David Benjamine098ec22014-08-27 23:13:20 -04002884 if ver.version != VersionSSL30 {
2885 testCases = append(testCases, testCase{
2886 testType: serverTest,
2887 name: ver.name + "-Server-ClientAuth-ECDSA",
2888 config: Config{
2889 MinVersion: ver.version,
2890 MaxVersion: ver.version,
David Benjamin33863262016-07-08 17:20:12 -07002891 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamine098ec22014-08-27 23:13:20 -04002892 },
2893 flags: []string{"-require-any-client-certificate"},
2894 })
2895 testCases = append(testCases, testCase{
2896 testType: clientTest,
2897 name: ver.name + "-Client-ClientAuth-ECDSA",
2898 config: Config{
2899 MinVersion: ver.version,
2900 MaxVersion: ver.version,
2901 ClientAuth: RequireAnyClientCert,
2902 ClientCAs: certPool,
2903 },
2904 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07002905 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
2906 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamine098ec22014-08-27 23:13:20 -04002907 },
2908 })
2909 }
Adam Langley37646832016-08-01 16:16:46 -07002910
2911 testCases = append(testCases, testCase{
2912 name: "NoClientCertificate-" + ver.name,
2913 config: Config{
2914 MinVersion: ver.version,
2915 MaxVersion: ver.version,
2916 ClientAuth: RequireAnyClientCert,
2917 },
2918 shouldFail: true,
2919 expectedLocalError: "client didn't provide a certificate",
2920 })
2921
2922 testCases = append(testCases, testCase{
2923 // Even if not configured to expect a certificate, OpenSSL will
2924 // return X509_V_OK as the verify_result.
2925 testType: serverTest,
2926 name: "NoClientCertificateRequested-Server-" + ver.name,
2927 config: Config{
2928 MinVersion: ver.version,
2929 MaxVersion: ver.version,
2930 },
2931 flags: []string{
2932 "-expect-verify-result",
2933 },
David Benjamin5d9ba812016-10-07 20:51:20 -04002934 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07002935 })
2936
2937 testCases = append(testCases, testCase{
2938 // If a client certificate is not provided, OpenSSL will still
2939 // return X509_V_OK as the verify_result.
2940 testType: serverTest,
2941 name: "NoClientCertificate-Server-" + ver.name,
2942 config: Config{
2943 MinVersion: ver.version,
2944 MaxVersion: ver.version,
2945 },
2946 flags: []string{
2947 "-expect-verify-result",
2948 "-verify-peer",
2949 },
David Benjamin5d9ba812016-10-07 20:51:20 -04002950 resumeSession: true,
Adam Langley37646832016-08-01 16:16:46 -07002951 })
2952
David Benjamin1db9e1b2016-10-07 20:51:43 -04002953 certificateRequired := "remote error: certificate required"
2954 if ver.version < VersionTLS13 {
2955 // Prior to TLS 1.3, the generic handshake_failure alert
2956 // was used.
2957 certificateRequired = "remote error: handshake failure"
2958 }
Adam Langley37646832016-08-01 16:16:46 -07002959 testCases = append(testCases, testCase{
2960 testType: serverTest,
2961 name: "RequireAnyClientCertificate-" + ver.name,
2962 config: Config{
2963 MinVersion: ver.version,
2964 MaxVersion: ver.version,
2965 },
David Benjamin1db9e1b2016-10-07 20:51:43 -04002966 flags: []string{"-require-any-client-certificate"},
2967 shouldFail: true,
2968 expectedError: ":PEER_DID_NOT_RETURN_A_CERTIFICATE:",
2969 expectedLocalError: certificateRequired,
Adam Langley37646832016-08-01 16:16:46 -07002970 })
2971
2972 if ver.version != VersionSSL30 {
2973 testCases = append(testCases, testCase{
2974 testType: serverTest,
2975 name: "SkipClientCertificate-" + ver.name,
2976 config: Config{
2977 MinVersion: ver.version,
2978 MaxVersion: ver.version,
2979 Bugs: ProtocolBugs{
2980 SkipClientCertificate: true,
2981 },
2982 },
2983 // Setting SSL_VERIFY_PEER allows anonymous clients.
2984 flags: []string{"-verify-peer"},
2985 shouldFail: true,
2986 expectedError: ":UNEXPECTED_MESSAGE:",
2987 })
2988 }
David Benjamin636293b2014-07-08 17:59:18 -04002989 }
David Benjamin0b7ca7d2016-03-10 15:44:22 -05002990
David Benjaminc032dfa2016-05-12 14:54:57 -04002991 // Client auth is only legal in certificate-based ciphers.
2992 testCases = append(testCases, testCase{
2993 testType: clientTest,
2994 name: "ClientAuth-PSK",
2995 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07002996 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04002997 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
2998 PreSharedKey: []byte("secret"),
2999 ClientAuth: RequireAnyClientCert,
3000 },
3001 flags: []string{
3002 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3003 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3004 "-psk", "secret",
3005 },
3006 shouldFail: true,
3007 expectedError: ":UNEXPECTED_MESSAGE:",
3008 })
3009 testCases = append(testCases, testCase{
3010 testType: clientTest,
3011 name: "ClientAuth-ECDHE_PSK",
3012 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003013 MaxVersion: VersionTLS12,
David Benjaminc032dfa2016-05-12 14:54:57 -04003014 CipherSuites: []uint16{TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA},
3015 PreSharedKey: []byte("secret"),
3016 ClientAuth: RequireAnyClientCert,
3017 },
3018 flags: []string{
3019 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3020 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3021 "-psk", "secret",
3022 },
3023 shouldFail: true,
3024 expectedError: ":UNEXPECTED_MESSAGE:",
3025 })
David Benjamin2f8935d2016-07-13 19:47:39 -04003026
3027 // Regression test for a bug where the client CA list, if explicitly
3028 // set to NULL, was mis-encoded.
3029 testCases = append(testCases, testCase{
3030 testType: serverTest,
3031 name: "Null-Client-CA-List",
3032 config: Config{
3033 MaxVersion: VersionTLS12,
3034 Certificates: []Certificate{rsaCertificate},
3035 },
3036 flags: []string{
3037 "-require-any-client-certificate",
3038 "-use-null-client-ca-list",
3039 },
3040 })
David Benjamin636293b2014-07-08 17:59:18 -04003041}
3042
Adam Langley75712922014-10-10 16:23:43 -07003043func addExtendedMasterSecretTests() {
3044 const expectEMSFlag = "-expect-extended-master-secret"
3045
3046 for _, with := range []bool{false, true} {
3047 prefix := "No"
Adam Langley75712922014-10-10 16:23:43 -07003048 if with {
3049 prefix = ""
Adam Langley75712922014-10-10 16:23:43 -07003050 }
3051
3052 for _, isClient := range []bool{false, true} {
3053 suffix := "-Server"
3054 testType := serverTest
3055 if isClient {
3056 suffix = "-Client"
3057 testType = clientTest
3058 }
3059
3060 for _, ver := range tlsVersions {
Steven Valdez143e8b32016-07-11 13:19:03 -04003061 // In TLS 1.3, the extension is irrelevant and
3062 // always reports as enabled.
3063 var flags []string
3064 if with || ver.version >= VersionTLS13 {
3065 flags = []string{expectEMSFlag}
3066 }
3067
Adam Langley75712922014-10-10 16:23:43 -07003068 test := testCase{
3069 testType: testType,
3070 name: prefix + "ExtendedMasterSecret-" + ver.name + suffix,
3071 config: Config{
3072 MinVersion: ver.version,
3073 MaxVersion: ver.version,
3074 Bugs: ProtocolBugs{
3075 NoExtendedMasterSecret: !with,
3076 RequireExtendedMasterSecret: with,
3077 },
3078 },
David Benjamin48cae082014-10-27 01:06:24 -04003079 flags: flags,
3080 shouldFail: ver.version == VersionSSL30 && with,
Adam Langley75712922014-10-10 16:23:43 -07003081 }
3082 if test.shouldFail {
3083 test.expectedLocalError = "extended master secret required but not supported by peer"
3084 }
3085 testCases = append(testCases, test)
3086 }
3087 }
3088 }
3089
Adam Langleyba5934b2015-06-02 10:50:35 -07003090 for _, isClient := range []bool{false, true} {
3091 for _, supportedInFirstConnection := range []bool{false, true} {
3092 for _, supportedInResumeConnection := range []bool{false, true} {
3093 boolToWord := func(b bool) string {
3094 if b {
3095 return "Yes"
3096 }
3097 return "No"
3098 }
3099 suffix := boolToWord(supportedInFirstConnection) + "To" + boolToWord(supportedInResumeConnection) + "-"
3100 if isClient {
3101 suffix += "Client"
3102 } else {
3103 suffix += "Server"
3104 }
3105
3106 supportedConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003107 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003108 Bugs: ProtocolBugs{
3109 RequireExtendedMasterSecret: true,
3110 },
3111 }
3112
3113 noSupportConfig := Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003114 MaxVersion: VersionTLS12,
Adam Langleyba5934b2015-06-02 10:50:35 -07003115 Bugs: ProtocolBugs{
3116 NoExtendedMasterSecret: true,
3117 },
3118 }
3119
3120 test := testCase{
3121 name: "ExtendedMasterSecret-" + suffix,
3122 resumeSession: true,
3123 }
3124
3125 if !isClient {
3126 test.testType = serverTest
3127 }
3128
3129 if supportedInFirstConnection {
3130 test.config = supportedConfig
3131 } else {
3132 test.config = noSupportConfig
3133 }
3134
3135 if supportedInResumeConnection {
3136 test.resumeConfig = &supportedConfig
3137 } else {
3138 test.resumeConfig = &noSupportConfig
3139 }
3140
3141 switch suffix {
3142 case "YesToYes-Client", "YesToYes-Server":
3143 // When a session is resumed, it should
3144 // still be aware that its master
3145 // secret was generated via EMS and
3146 // thus it's safe to use tls-unique.
3147 test.flags = []string{expectEMSFlag}
3148 case "NoToYes-Server":
3149 // If an original connection did not
3150 // contain EMS, but a resumption
3151 // handshake does, then a server should
3152 // not resume the session.
3153 test.expectResumeRejected = true
3154 case "YesToNo-Server":
3155 // Resuming an EMS session without the
3156 // EMS extension should cause the
3157 // server to abort the connection.
3158 test.shouldFail = true
3159 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3160 case "NoToYes-Client":
3161 // A client should abort a connection
3162 // where the server resumed a non-EMS
3163 // session but echoed the EMS
3164 // extension.
3165 test.shouldFail = true
3166 test.expectedError = ":RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION:"
3167 case "YesToNo-Client":
3168 // A client should abort a connection
3169 // where the server didn't echo EMS
3170 // when the session used it.
3171 test.shouldFail = true
3172 test.expectedError = ":RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION:"
3173 }
3174
3175 testCases = append(testCases, test)
3176 }
3177 }
3178 }
David Benjamin163c9562016-08-29 23:14:17 -04003179
3180 // Switching EMS on renegotiation is forbidden.
3181 testCases = append(testCases, testCase{
3182 name: "ExtendedMasterSecret-Renego-NoEMS",
3183 config: Config{
3184 MaxVersion: VersionTLS12,
3185 Bugs: ProtocolBugs{
3186 NoExtendedMasterSecret: true,
3187 NoExtendedMasterSecretOnRenegotiation: true,
3188 },
3189 },
3190 renegotiate: 1,
3191 flags: []string{
3192 "-renegotiate-freely",
3193 "-expect-total-renegotiations", "1",
3194 },
3195 })
3196
3197 testCases = append(testCases, testCase{
3198 name: "ExtendedMasterSecret-Renego-Upgrade",
3199 config: Config{
3200 MaxVersion: VersionTLS12,
3201 Bugs: ProtocolBugs{
3202 NoExtendedMasterSecret: true,
3203 },
3204 },
3205 renegotiate: 1,
3206 flags: []string{
3207 "-renegotiate-freely",
3208 "-expect-total-renegotiations", "1",
3209 },
3210 shouldFail: true,
3211 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3212 })
3213
3214 testCases = append(testCases, testCase{
3215 name: "ExtendedMasterSecret-Renego-Downgrade",
3216 config: Config{
3217 MaxVersion: VersionTLS12,
3218 Bugs: ProtocolBugs{
3219 NoExtendedMasterSecretOnRenegotiation: true,
3220 },
3221 },
3222 renegotiate: 1,
3223 flags: []string{
3224 "-renegotiate-freely",
3225 "-expect-total-renegotiations", "1",
3226 },
3227 shouldFail: true,
3228 expectedError: ":RENEGOTIATION_EMS_MISMATCH:",
3229 })
Adam Langley75712922014-10-10 16:23:43 -07003230}
3231
David Benjamin582ba042016-07-07 12:33:25 -07003232type stateMachineTestConfig struct {
3233 protocol protocol
3234 async bool
3235 splitHandshake, packHandshakeFlight bool
3236}
3237
David Benjamin43ec06f2014-08-05 02:28:57 -04003238// Adds tests that try to cover the range of the handshake state machine, under
3239// various conditions. Some of these are redundant with other tests, but they
3240// only cover the synchronous case.
David Benjamin582ba042016-07-07 12:33:25 -07003241func addAllStateMachineCoverageTests() {
3242 for _, async := range []bool{false, true} {
3243 for _, protocol := range []protocol{tls, dtls} {
3244 addStateMachineCoverageTests(stateMachineTestConfig{
3245 protocol: protocol,
3246 async: async,
3247 })
3248 addStateMachineCoverageTests(stateMachineTestConfig{
3249 protocol: protocol,
3250 async: async,
3251 splitHandshake: true,
3252 })
3253 if protocol == tls {
3254 addStateMachineCoverageTests(stateMachineTestConfig{
3255 protocol: protocol,
3256 async: async,
3257 packHandshakeFlight: true,
3258 })
3259 }
3260 }
3261 }
3262}
3263
3264func addStateMachineCoverageTests(config stateMachineTestConfig) {
David Benjamin760b1dd2015-05-15 23:33:48 -04003265 var tests []testCase
3266
3267 // Basic handshake, with resumption. Client and server,
3268 // session ID and session ticket.
3269 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003270 name: "Basic-Client",
3271 config: Config{
3272 MaxVersion: VersionTLS12,
3273 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003274 resumeSession: true,
David Benjaminef1b0092015-11-21 14:05:44 -05003275 // Ensure session tickets are used, not session IDs.
3276 noSessionCache: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003277 })
3278 tests = append(tests, testCase{
3279 name: "Basic-Client-RenewTicket",
3280 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003281 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003282 Bugs: ProtocolBugs{
3283 RenewTicketOnResume: true,
3284 },
3285 },
David Benjamin46662482016-08-17 00:51:00 -04003286 flags: []string{"-expect-ticket-renewal"},
3287 resumeSession: true,
3288 resumeRenewedSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003289 })
3290 tests = append(tests, testCase{
3291 name: "Basic-Client-NoTicket",
3292 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003293 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003294 SessionTicketsDisabled: true,
3295 },
3296 resumeSession: true,
3297 })
3298 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003299 name: "Basic-Client-Implicit",
3300 config: Config{
3301 MaxVersion: VersionTLS12,
3302 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003303 flags: []string{"-implicit-handshake"},
3304 resumeSession: true,
3305 })
3306 tests = append(tests, testCase{
David Benjaminef1b0092015-11-21 14:05:44 -05003307 testType: serverTest,
3308 name: "Basic-Server",
3309 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003310 MaxVersion: VersionTLS12,
David Benjaminef1b0092015-11-21 14:05:44 -05003311 Bugs: ProtocolBugs{
3312 RequireSessionTickets: true,
3313 },
3314 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003315 resumeSession: true,
3316 })
3317 tests = append(tests, testCase{
3318 testType: serverTest,
3319 name: "Basic-Server-NoTickets",
3320 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003321 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003322 SessionTicketsDisabled: true,
3323 },
3324 resumeSession: true,
3325 })
3326 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003327 testType: serverTest,
3328 name: "Basic-Server-Implicit",
3329 config: Config{
3330 MaxVersion: VersionTLS12,
3331 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003332 flags: []string{"-implicit-handshake"},
3333 resumeSession: true,
3334 })
3335 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003336 testType: serverTest,
3337 name: "Basic-Server-EarlyCallback",
3338 config: Config{
3339 MaxVersion: VersionTLS12,
3340 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003341 flags: []string{"-use-early-callback"},
3342 resumeSession: true,
3343 })
3344
Steven Valdez143e8b32016-07-11 13:19:03 -04003345 // TLS 1.3 basic handshake shapes.
David Benjamine73c7f42016-08-17 00:29:33 -04003346 if config.protocol == tls {
3347 tests = append(tests, testCase{
3348 name: "TLS13-1RTT-Client",
3349 config: Config{
3350 MaxVersion: VersionTLS13,
3351 MinVersion: VersionTLS13,
3352 },
David Benjamin46662482016-08-17 00:51:00 -04003353 resumeSession: true,
3354 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003355 })
3356
3357 tests = append(tests, testCase{
3358 testType: serverTest,
3359 name: "TLS13-1RTT-Server",
3360 config: Config{
3361 MaxVersion: VersionTLS13,
3362 MinVersion: VersionTLS13,
3363 },
David Benjamin46662482016-08-17 00:51:00 -04003364 resumeSession: true,
3365 resumeRenewedSession: true,
David Benjamine73c7f42016-08-17 00:29:33 -04003366 })
3367
3368 tests = append(tests, testCase{
3369 name: "TLS13-HelloRetryRequest-Client",
3370 config: Config{
3371 MaxVersion: VersionTLS13,
3372 MinVersion: VersionTLS13,
3373 // P-384 requires a HelloRetryRequest against
3374 // BoringSSL's default configuration. Assert
3375 // that we do indeed test this with
3376 // ExpectMissingKeyShare.
3377 CurvePreferences: []CurveID{CurveP384},
3378 Bugs: ProtocolBugs{
3379 ExpectMissingKeyShare: true,
3380 },
3381 },
3382 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3383 resumeSession: true,
3384 })
3385
3386 tests = append(tests, testCase{
3387 testType: serverTest,
3388 name: "TLS13-HelloRetryRequest-Server",
3389 config: Config{
3390 MaxVersion: VersionTLS13,
3391 MinVersion: VersionTLS13,
3392 // Require a HelloRetryRequest for every curve.
3393 DefaultCurves: []CurveID{},
3394 },
3395 // Cover HelloRetryRequest during an ECDHE-PSK resumption.
3396 resumeSession: true,
3397 })
3398 }
Steven Valdez143e8b32016-07-11 13:19:03 -04003399
David Benjamin760b1dd2015-05-15 23:33:48 -04003400 // TLS client auth.
3401 tests = append(tests, testCase{
3402 testType: clientTest,
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003403 name: "ClientAuth-NoCertificate-Client",
David Benjaminacb6dcc2016-03-10 09:15:01 -05003404 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003405 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003406 ClientAuth: RequestClientCert,
3407 },
3408 })
3409 tests = append(tests, testCase{
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003410 testType: serverTest,
3411 name: "ClientAuth-NoCertificate-Server",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003412 config: Config{
3413 MaxVersion: VersionTLS12,
3414 },
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003415 // Setting SSL_VERIFY_PEER allows anonymous clients.
3416 flags: []string{"-verify-peer"},
3417 })
David Benjamin582ba042016-07-07 12:33:25 -07003418 if config.protocol == tls {
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003419 tests = append(tests, testCase{
3420 testType: clientTest,
3421 name: "ClientAuth-NoCertificate-Client-SSL3",
3422 config: Config{
3423 MaxVersion: VersionSSL30,
3424 ClientAuth: RequestClientCert,
3425 },
3426 })
3427 tests = append(tests, testCase{
3428 testType: serverTest,
3429 name: "ClientAuth-NoCertificate-Server-SSL3",
3430 config: Config{
3431 MaxVersion: VersionSSL30,
3432 },
3433 // Setting SSL_VERIFY_PEER allows anonymous clients.
3434 flags: []string{"-verify-peer"},
3435 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003436 tests = append(tests, testCase{
3437 testType: clientTest,
3438 name: "ClientAuth-NoCertificate-Client-TLS13",
3439 config: Config{
3440 MaxVersion: VersionTLS13,
3441 ClientAuth: RequestClientCert,
3442 },
3443 })
3444 tests = append(tests, testCase{
3445 testType: serverTest,
3446 name: "ClientAuth-NoCertificate-Server-TLS13",
3447 config: Config{
3448 MaxVersion: VersionTLS13,
3449 },
3450 // Setting SSL_VERIFY_PEER allows anonymous clients.
3451 flags: []string{"-verify-peer"},
3452 })
David Benjamin0b7ca7d2016-03-10 15:44:22 -05003453 }
3454 tests = append(tests, testCase{
David Benjaminacb6dcc2016-03-10 09:15:01 -05003455 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003456 name: "ClientAuth-RSA-Client",
David Benjamin760b1dd2015-05-15 23:33:48 -04003457 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003458 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003459 ClientAuth: RequireAnyClientCert,
3460 },
3461 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07003462 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3463 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin760b1dd2015-05-15 23:33:48 -04003464 },
3465 })
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003466 tests = append(tests, testCase{
3467 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003468 name: "ClientAuth-RSA-Client-TLS13",
3469 config: Config{
3470 MaxVersion: VersionTLS13,
3471 ClientAuth: RequireAnyClientCert,
3472 },
3473 flags: []string{
3474 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3475 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3476 },
3477 })
3478 tests = append(tests, testCase{
3479 testType: clientTest,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003480 name: "ClientAuth-ECDSA-Client",
3481 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003482 MaxVersion: VersionTLS12,
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003483 ClientAuth: RequireAnyClientCert,
3484 },
3485 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003486 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3487 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
nagendra modadugu3398dbf2015-08-07 14:07:52 -07003488 },
3489 })
David Benjaminacb6dcc2016-03-10 09:15:01 -05003490 tests = append(tests, testCase{
3491 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003492 name: "ClientAuth-ECDSA-Client-TLS13",
3493 config: Config{
3494 MaxVersion: VersionTLS13,
3495 ClientAuth: RequireAnyClientCert,
3496 },
3497 flags: []string{
3498 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3499 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
3500 },
3501 })
3502 tests = append(tests, testCase{
3503 testType: clientTest,
David Benjamin4c3ddf72016-06-29 18:13:53 -04003504 name: "ClientAuth-NoCertificate-OldCallback",
3505 config: Config{
3506 MaxVersion: VersionTLS12,
3507 ClientAuth: RequestClientCert,
3508 },
3509 flags: []string{"-use-old-client-cert-callback"},
3510 })
3511 tests = append(tests, testCase{
3512 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04003513 name: "ClientAuth-NoCertificate-OldCallback-TLS13",
3514 config: Config{
3515 MaxVersion: VersionTLS13,
3516 ClientAuth: RequestClientCert,
3517 },
3518 flags: []string{"-use-old-client-cert-callback"},
3519 })
3520 tests = append(tests, testCase{
3521 testType: clientTest,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003522 name: "ClientAuth-OldCallback",
3523 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003524 MaxVersion: VersionTLS12,
David Benjaminacb6dcc2016-03-10 09:15:01 -05003525 ClientAuth: RequireAnyClientCert,
3526 },
3527 flags: []string{
3528 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3529 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3530 "-use-old-client-cert-callback",
3531 },
3532 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003533 tests = append(tests, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04003534 testType: clientTest,
3535 name: "ClientAuth-OldCallback-TLS13",
3536 config: Config{
3537 MaxVersion: VersionTLS13,
3538 ClientAuth: RequireAnyClientCert,
3539 },
3540 flags: []string{
3541 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3542 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3543 "-use-old-client-cert-callback",
3544 },
3545 })
3546 tests = append(tests, testCase{
David Benjamin760b1dd2015-05-15 23:33:48 -04003547 testType: serverTest,
3548 name: "ClientAuth-Server",
3549 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003550 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003551 Certificates: []Certificate{rsaCertificate},
3552 },
3553 flags: []string{"-require-any-client-certificate"},
3554 })
Steven Valdez143e8b32016-07-11 13:19:03 -04003555 tests = append(tests, testCase{
3556 testType: serverTest,
3557 name: "ClientAuth-Server-TLS13",
3558 config: Config{
3559 MaxVersion: VersionTLS13,
3560 Certificates: []Certificate{rsaCertificate},
3561 },
3562 flags: []string{"-require-any-client-certificate"},
3563 })
David Benjamin760b1dd2015-05-15 23:33:48 -04003564
David Benjamin4c3ddf72016-06-29 18:13:53 -04003565 // Test each key exchange on the server side for async keys.
David Benjamin4c3ddf72016-06-29 18:13:53 -04003566 tests = append(tests, testCase{
3567 testType: serverTest,
3568 name: "Basic-Server-RSA",
3569 config: Config{
3570 MaxVersion: VersionTLS12,
3571 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
3572 },
3573 flags: []string{
3574 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3575 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3576 },
3577 })
3578 tests = append(tests, testCase{
3579 testType: serverTest,
3580 name: "Basic-Server-ECDHE-RSA",
3581 config: Config{
3582 MaxVersion: VersionTLS12,
3583 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3584 },
3585 flags: []string{
3586 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
3587 "-key-file", path.Join(*resourceDir, rsaKeyFile),
3588 },
3589 })
3590 tests = append(tests, testCase{
3591 testType: serverTest,
3592 name: "Basic-Server-ECDHE-ECDSA",
3593 config: Config{
3594 MaxVersion: VersionTLS12,
3595 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
3596 },
3597 flags: []string{
David Benjamin33863262016-07-08 17:20:12 -07003598 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
3599 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
David Benjamin4c3ddf72016-06-29 18:13:53 -04003600 },
3601 })
3602
David Benjamin760b1dd2015-05-15 23:33:48 -04003603 // No session ticket support; server doesn't send NewSessionTicket.
3604 tests = append(tests, testCase{
3605 name: "SessionTicketsDisabled-Client",
3606 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003607 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003608 SessionTicketsDisabled: true,
3609 },
3610 })
3611 tests = append(tests, testCase{
3612 testType: serverTest,
3613 name: "SessionTicketsDisabled-Server",
3614 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003615 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003616 SessionTicketsDisabled: true,
3617 },
3618 })
3619
3620 // Skip ServerKeyExchange in PSK key exchange if there's no
3621 // identity hint.
3622 tests = append(tests, testCase{
3623 name: "EmptyPSKHint-Client",
3624 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003625 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003626 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3627 PreSharedKey: []byte("secret"),
3628 },
3629 flags: []string{"-psk", "secret"},
3630 })
3631 tests = append(tests, testCase{
3632 testType: serverTest,
3633 name: "EmptyPSKHint-Server",
3634 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003635 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003636 CipherSuites: []uint16{TLS_PSK_WITH_AES_128_CBC_SHA},
3637 PreSharedKey: []byte("secret"),
3638 },
3639 flags: []string{"-psk", "secret"},
3640 })
3641
David Benjamin4c3ddf72016-06-29 18:13:53 -04003642 // OCSP stapling tests.
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003643 tests = append(tests, testCase{
3644 testType: clientTest,
3645 name: "OCSPStapling-Client",
David Benjamin4c3ddf72016-06-29 18:13:53 -04003646 config: Config{
3647 MaxVersion: VersionTLS12,
3648 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003649 flags: []string{
3650 "-enable-ocsp-stapling",
3651 "-expect-ocsp-response",
3652 base64.StdEncoding.EncodeToString(testOCSPResponse),
Paul Lietar8f1c2682015-08-18 12:21:54 +01003653 "-verify-peer",
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003654 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003655 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003656 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003657 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003658 testType: serverTest,
3659 name: "OCSPStapling-Server",
3660 config: Config{
3661 MaxVersion: VersionTLS12,
3662 },
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003663 expectedOCSPResponse: testOCSPResponse,
3664 flags: []string{
3665 "-ocsp-response",
3666 base64.StdEncoding.EncodeToString(testOCSPResponse),
3667 },
Paul Lietar62be8ac2015-09-16 10:03:30 +01003668 resumeSession: true,
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003669 })
David Benjamin942f4ed2016-07-16 19:03:49 +03003670 tests = append(tests, testCase{
3671 testType: clientTest,
3672 name: "OCSPStapling-Client-TLS13",
3673 config: Config{
3674 MaxVersion: VersionTLS13,
3675 },
3676 flags: []string{
3677 "-enable-ocsp-stapling",
3678 "-expect-ocsp-response",
3679 base64.StdEncoding.EncodeToString(testOCSPResponse),
3680 "-verify-peer",
3681 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003682 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003683 })
3684 tests = append(tests, testCase{
3685 testType: serverTest,
3686 name: "OCSPStapling-Server-TLS13",
3687 config: Config{
3688 MaxVersion: VersionTLS13,
3689 },
3690 expectedOCSPResponse: testOCSPResponse,
3691 flags: []string{
3692 "-ocsp-response",
3693 base64.StdEncoding.EncodeToString(testOCSPResponse),
3694 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003695 resumeSession: true,
David Benjamin942f4ed2016-07-16 19:03:49 +03003696 })
Paul Lietaraeeff2c2015-08-12 11:47:11 +01003697
David Benjamin4c3ddf72016-06-29 18:13:53 -04003698 // Certificate verification tests.
Steven Valdez143e8b32016-07-11 13:19:03 -04003699 for _, vers := range tlsVersions {
3700 if config.protocol == dtls && !vers.hasDTLS {
3701 continue
3702 }
David Benjaminbb9e36e2016-08-03 14:14:47 -04003703 for _, testType := range []testType{clientTest, serverTest} {
3704 suffix := "-Client"
3705 if testType == serverTest {
3706 suffix = "-Server"
3707 }
3708 suffix += "-" + vers.name
3709
3710 flag := "-verify-peer"
3711 if testType == serverTest {
3712 flag = "-require-any-client-certificate"
3713 }
3714
3715 tests = append(tests, testCase{
3716 testType: testType,
3717 name: "CertificateVerificationSucceed" + suffix,
3718 config: Config{
3719 MaxVersion: vers.version,
3720 Certificates: []Certificate{rsaCertificate},
3721 },
3722 flags: []string{
3723 flag,
3724 "-expect-verify-result",
3725 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003726 resumeSession: true,
David Benjaminbb9e36e2016-08-03 14:14:47 -04003727 })
3728 tests = append(tests, testCase{
3729 testType: testType,
3730 name: "CertificateVerificationFail" + suffix,
3731 config: Config{
3732 MaxVersion: vers.version,
3733 Certificates: []Certificate{rsaCertificate},
3734 },
3735 flags: []string{
3736 flag,
3737 "-verify-fail",
3738 },
3739 shouldFail: true,
3740 expectedError: ":CERTIFICATE_VERIFY_FAILED:",
3741 })
3742 }
3743
3744 // By default, the client is in a soft fail mode where the peer
3745 // certificate is verified but failures are non-fatal.
Steven Valdez143e8b32016-07-11 13:19:03 -04003746 tests = append(tests, testCase{
3747 testType: clientTest,
3748 name: "CertificateVerificationSoftFail-" + vers.name,
3749 config: Config{
David Benjaminbb9e36e2016-08-03 14:14:47 -04003750 MaxVersion: vers.version,
3751 Certificates: []Certificate{rsaCertificate},
Steven Valdez143e8b32016-07-11 13:19:03 -04003752 },
3753 flags: []string{
3754 "-verify-fail",
3755 "-expect-verify-result",
3756 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04003757 resumeSession: true,
Steven Valdez143e8b32016-07-11 13:19:03 -04003758 })
3759 }
Paul Lietar8f1c2682015-08-18 12:21:54 +01003760
David Benjamin1d4f4c02016-07-26 18:03:08 -04003761 tests = append(tests, testCase{
3762 name: "ShimSendAlert",
3763 flags: []string{"-send-alert"},
3764 shimWritesFirst: true,
3765 shouldFail: true,
3766 expectedLocalError: "remote error: decompression failure",
3767 })
3768
David Benjamin582ba042016-07-07 12:33:25 -07003769 if config.protocol == tls {
David Benjamin760b1dd2015-05-15 23:33:48 -04003770 tests = append(tests, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003771 name: "Renegotiate-Client",
3772 config: Config{
3773 MaxVersion: VersionTLS12,
3774 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04003775 renegotiate: 1,
3776 flags: []string{
3777 "-renegotiate-freely",
3778 "-expect-total-renegotiations", "1",
3779 },
David Benjamin760b1dd2015-05-15 23:33:48 -04003780 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04003781
David Benjamin47921102016-07-28 11:29:18 -04003782 tests = append(tests, testCase{
3783 name: "SendHalfHelloRequest",
3784 config: Config{
3785 MaxVersion: VersionTLS12,
3786 Bugs: ProtocolBugs{
3787 PackHelloRequestWithFinished: config.packHandshakeFlight,
3788 },
3789 },
3790 sendHalfHelloRequest: true,
3791 flags: []string{"-renegotiate-ignore"},
3792 shouldFail: true,
3793 expectedError: ":UNEXPECTED_RECORD:",
3794 })
3795
David Benjamin760b1dd2015-05-15 23:33:48 -04003796 // NPN on client and server; results in post-handshake message.
3797 tests = append(tests, testCase{
3798 name: "NPN-Client",
3799 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003800 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003801 NextProtos: []string{"foo"},
3802 },
3803 flags: []string{"-select-next-proto", "foo"},
David Benjaminf8fcdf32016-06-08 15:56:13 -04003804 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003805 expectedNextProto: "foo",
3806 expectedNextProtoType: npn,
3807 })
3808 tests = append(tests, testCase{
3809 testType: serverTest,
3810 name: "NPN-Server",
3811 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003812 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003813 NextProtos: []string{"bar"},
3814 },
3815 flags: []string{
3816 "-advertise-npn", "\x03foo\x03bar\x03baz",
3817 "-expect-next-proto", "bar",
3818 },
David Benjaminf8fcdf32016-06-08 15:56:13 -04003819 resumeSession: true,
David Benjamin760b1dd2015-05-15 23:33:48 -04003820 expectedNextProto: "bar",
3821 expectedNextProtoType: npn,
3822 })
3823
3824 // TODO(davidben): Add tests for when False Start doesn't trigger.
3825
3826 // Client does False Start and negotiates NPN.
3827 tests = append(tests, testCase{
3828 name: "FalseStart",
3829 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003830 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003831 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3832 NextProtos: []string{"foo"},
3833 Bugs: ProtocolBugs{
3834 ExpectFalseStart: true,
3835 },
3836 },
3837 flags: []string{
3838 "-false-start",
3839 "-select-next-proto", "foo",
3840 },
3841 shimWritesFirst: true,
3842 resumeSession: true,
3843 })
3844
3845 // Client does False Start and negotiates ALPN.
3846 tests = append(tests, testCase{
3847 name: "FalseStart-ALPN",
3848 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003849 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003850 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3851 NextProtos: []string{"foo"},
3852 Bugs: ProtocolBugs{
3853 ExpectFalseStart: true,
3854 },
3855 },
3856 flags: []string{
3857 "-false-start",
3858 "-advertise-alpn", "\x03foo",
3859 },
3860 shimWritesFirst: true,
3861 resumeSession: true,
3862 })
3863
3864 // Client does False Start but doesn't explicitly call
3865 // SSL_connect.
3866 tests = append(tests, testCase{
3867 name: "FalseStart-Implicit",
3868 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003869 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003870 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3871 NextProtos: []string{"foo"},
3872 },
3873 flags: []string{
3874 "-implicit-handshake",
3875 "-false-start",
3876 "-advertise-alpn", "\x03foo",
3877 },
3878 })
3879
3880 // False Start without session tickets.
3881 tests = append(tests, testCase{
3882 name: "FalseStart-SessionTicketsDisabled",
3883 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07003884 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003885 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
3886 NextProtos: []string{"foo"},
3887 SessionTicketsDisabled: true,
3888 Bugs: ProtocolBugs{
3889 ExpectFalseStart: true,
3890 },
3891 },
3892 flags: []string{
3893 "-false-start",
3894 "-select-next-proto", "foo",
3895 },
3896 shimWritesFirst: true,
3897 })
3898
Adam Langleydf759b52016-07-11 15:24:37 -07003899 tests = append(tests, testCase{
3900 name: "FalseStart-CECPQ1",
3901 config: Config{
3902 MaxVersion: VersionTLS12,
3903 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
3904 NextProtos: []string{"foo"},
3905 Bugs: ProtocolBugs{
3906 ExpectFalseStart: true,
3907 },
3908 },
3909 flags: []string{
3910 "-false-start",
3911 "-cipher", "DEFAULT:kCECPQ1",
3912 "-select-next-proto", "foo",
3913 },
3914 shimWritesFirst: true,
3915 resumeSession: true,
3916 })
3917
David Benjamin760b1dd2015-05-15 23:33:48 -04003918 // Server parses a V2ClientHello.
3919 tests = append(tests, testCase{
3920 testType: serverTest,
3921 name: "SendV2ClientHello",
3922 config: Config{
3923 // Choose a cipher suite that does not involve
3924 // elliptic curves, so no extensions are
3925 // involved.
Nick Harper1fd39d82016-06-14 18:14:35 -07003926 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07003927 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin760b1dd2015-05-15 23:33:48 -04003928 Bugs: ProtocolBugs{
3929 SendV2ClientHello: true,
3930 },
3931 },
3932 })
3933
3934 // Client sends a Channel ID.
3935 tests = append(tests, testCase{
3936 name: "ChannelID-Client",
3937 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003938 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04003939 RequestChannelID: true,
3940 },
Adam Langley7c803a62015-06-15 15:35:05 -07003941 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
David Benjamin760b1dd2015-05-15 23:33:48 -04003942 resumeSession: true,
3943 expectChannelID: true,
3944 })
3945
3946 // Server accepts a Channel ID.
3947 tests = append(tests, testCase{
3948 testType: serverTest,
3949 name: "ChannelID-Server",
3950 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003951 MaxVersion: VersionTLS12,
3952 ChannelID: channelIDKey,
David Benjamin760b1dd2015-05-15 23:33:48 -04003953 },
3954 flags: []string{
3955 "-expect-channel-id",
3956 base64.StdEncoding.EncodeToString(channelIDBytes),
3957 },
3958 resumeSession: true,
3959 expectChannelID: true,
3960 })
David Benjamin30789da2015-08-29 22:56:45 -04003961
David Benjaminf8fcdf32016-06-08 15:56:13 -04003962 // Channel ID and NPN at the same time, to ensure their relative
3963 // ordering is correct.
3964 tests = append(tests, testCase{
3965 name: "ChannelID-NPN-Client",
3966 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003967 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003968 RequestChannelID: true,
3969 NextProtos: []string{"foo"},
3970 },
3971 flags: []string{
3972 "-send-channel-id", path.Join(*resourceDir, channelIDKeyFile),
3973 "-select-next-proto", "foo",
3974 },
3975 resumeSession: true,
3976 expectChannelID: true,
3977 expectedNextProto: "foo",
3978 expectedNextProtoType: npn,
3979 })
3980 tests = append(tests, testCase{
3981 testType: serverTest,
3982 name: "ChannelID-NPN-Server",
3983 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04003984 MaxVersion: VersionTLS12,
David Benjaminf8fcdf32016-06-08 15:56:13 -04003985 ChannelID: channelIDKey,
3986 NextProtos: []string{"bar"},
3987 },
3988 flags: []string{
3989 "-expect-channel-id",
3990 base64.StdEncoding.EncodeToString(channelIDBytes),
3991 "-advertise-npn", "\x03foo\x03bar\x03baz",
3992 "-expect-next-proto", "bar",
3993 },
3994 resumeSession: true,
3995 expectChannelID: true,
3996 expectedNextProto: "bar",
3997 expectedNextProtoType: npn,
3998 })
3999
David Benjamin30789da2015-08-29 22:56:45 -04004000 // Bidirectional shutdown with the runner initiating.
4001 tests = append(tests, testCase{
4002 name: "Shutdown-Runner",
4003 config: Config{
4004 Bugs: ProtocolBugs{
4005 ExpectCloseNotify: true,
4006 },
4007 },
4008 flags: []string{"-check-close-notify"},
4009 })
4010
4011 // Bidirectional shutdown with the shim initiating. The runner,
4012 // in the meantime, sends garbage before the close_notify which
4013 // the shim must ignore.
4014 tests = append(tests, testCase{
4015 name: "Shutdown-Shim",
4016 config: Config{
David Benjamine8e84b92016-08-03 15:39:47 -04004017 MaxVersion: VersionTLS12,
David Benjamin30789da2015-08-29 22:56:45 -04004018 Bugs: ProtocolBugs{
4019 ExpectCloseNotify: true,
4020 },
4021 },
4022 shimShutsDown: true,
4023 sendEmptyRecords: 1,
4024 sendWarningAlerts: 1,
4025 flags: []string{"-check-close-notify"},
4026 })
David Benjamin760b1dd2015-05-15 23:33:48 -04004027 } else {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004028 // TODO(davidben): DTLS 1.3 will want a similar thing for
4029 // HelloRetryRequest.
David Benjamin760b1dd2015-05-15 23:33:48 -04004030 tests = append(tests, testCase{
4031 name: "SkipHelloVerifyRequest",
4032 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004033 MaxVersion: VersionTLS12,
David Benjamin760b1dd2015-05-15 23:33:48 -04004034 Bugs: ProtocolBugs{
4035 SkipHelloVerifyRequest: true,
4036 },
4037 },
4038 })
4039 }
4040
David Benjamin760b1dd2015-05-15 23:33:48 -04004041 for _, test := range tests {
David Benjamin582ba042016-07-07 12:33:25 -07004042 test.protocol = config.protocol
4043 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004044 test.name += "-DTLS"
4045 }
David Benjamin582ba042016-07-07 12:33:25 -07004046 if config.async {
David Benjamin16285ea2015-11-03 15:39:45 -05004047 test.name += "-Async"
4048 test.flags = append(test.flags, "-async")
4049 } else {
4050 test.name += "-Sync"
4051 }
David Benjamin582ba042016-07-07 12:33:25 -07004052 if config.splitHandshake {
David Benjamin16285ea2015-11-03 15:39:45 -05004053 test.name += "-SplitHandshakeRecords"
4054 test.config.Bugs.MaxHandshakeRecordLength = 1
David Benjamin582ba042016-07-07 12:33:25 -07004055 if config.protocol == dtls {
David Benjamin16285ea2015-11-03 15:39:45 -05004056 test.config.Bugs.MaxPacketLength = 256
4057 test.flags = append(test.flags, "-mtu", "256")
4058 }
4059 }
David Benjamin582ba042016-07-07 12:33:25 -07004060 if config.packHandshakeFlight {
4061 test.name += "-PackHandshakeFlight"
4062 test.config.Bugs.PackHandshakeFlight = true
4063 }
David Benjamin760b1dd2015-05-15 23:33:48 -04004064 testCases = append(testCases, test)
David Benjamin6fd297b2014-08-11 18:43:38 -04004065 }
David Benjamin43ec06f2014-08-05 02:28:57 -04004066}
4067
Adam Langley524e7172015-02-20 16:04:00 -08004068func addDDoSCallbackTests() {
4069 // DDoS callback.
Adam Langley524e7172015-02-20 16:04:00 -08004070 for _, resume := range []bool{false, true} {
4071 suffix := "Resume"
4072 if resume {
4073 suffix = "No" + suffix
4074 }
4075
4076 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004077 testType: serverTest,
4078 name: "Server-DDoS-OK-" + suffix,
4079 config: Config{
4080 MaxVersion: VersionTLS12,
4081 },
Adam Langley524e7172015-02-20 16:04:00 -08004082 flags: []string{"-install-ddos-callback"},
4083 resumeSession: resume,
4084 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004085 testCases = append(testCases, testCase{
4086 testType: serverTest,
4087 name: "Server-DDoS-OK-" + suffix + "-TLS13",
4088 config: Config{
4089 MaxVersion: VersionTLS13,
4090 },
4091 flags: []string{"-install-ddos-callback"},
4092 resumeSession: resume,
4093 })
Adam Langley524e7172015-02-20 16:04:00 -08004094
4095 failFlag := "-fail-ddos-callback"
4096 if resume {
4097 failFlag = "-fail-second-ddos-callback"
4098 }
4099 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04004100 testType: serverTest,
4101 name: "Server-DDoS-Reject-" + suffix,
4102 config: Config{
4103 MaxVersion: VersionTLS12,
4104 },
David Benjamin2c66e072016-09-16 15:58:00 -04004105 flags: []string{"-install-ddos-callback", failFlag},
4106 resumeSession: resume,
4107 shouldFail: true,
4108 expectedError: ":CONNECTION_REJECTED:",
4109 expectedLocalError: "remote error: internal error",
Adam Langley524e7172015-02-20 16:04:00 -08004110 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04004111 testCases = append(testCases, testCase{
4112 testType: serverTest,
4113 name: "Server-DDoS-Reject-" + suffix + "-TLS13",
4114 config: Config{
4115 MaxVersion: VersionTLS13,
4116 },
David Benjamin2c66e072016-09-16 15:58:00 -04004117 flags: []string{"-install-ddos-callback", failFlag},
4118 resumeSession: resume,
4119 shouldFail: true,
4120 expectedError: ":CONNECTION_REJECTED:",
4121 expectedLocalError: "remote error: internal error",
Steven Valdez4aa154e2016-07-29 14:32:55 -04004122 })
Adam Langley524e7172015-02-20 16:04:00 -08004123 }
4124}
4125
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004126func addVersionNegotiationTests() {
4127 for i, shimVers := range tlsVersions {
4128 // Assemble flags to disable all newer versions on the shim.
4129 var flags []string
4130 for _, vers := range tlsVersions[i+1:] {
4131 flags = append(flags, vers.flag)
4132 }
4133
Steven Valdezfdd10992016-09-15 16:27:05 -04004134 // Test configuring the runner's maximum version.
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004135 for _, runnerVers := range tlsVersions {
David Benjamin8b8c0062014-11-23 02:47:52 -05004136 protocols := []protocol{tls}
4137 if runnerVers.hasDTLS && shimVers.hasDTLS {
4138 protocols = append(protocols, dtls)
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004139 }
David Benjamin8b8c0062014-11-23 02:47:52 -05004140 for _, protocol := range protocols {
4141 expectedVersion := shimVers.version
4142 if runnerVers.version < shimVers.version {
4143 expectedVersion = runnerVers.version
4144 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004145
David Benjamin8b8c0062014-11-23 02:47:52 -05004146 suffix := shimVers.name + "-" + runnerVers.name
4147 if protocol == dtls {
4148 suffix += "-DTLS"
4149 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004150
David Benjamin1eb367c2014-12-12 18:17:51 -05004151 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4152
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004153 // Determine the expected initial record-layer versions.
David Benjamin1e29a6b2014-12-10 02:27:24 -05004154 clientVers := shimVers.version
4155 if clientVers > VersionTLS10 {
4156 clientVers = VersionTLS10
4157 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004158 clientVers = versionToWire(clientVers, protocol == dtls)
Nick Harper1fd39d82016-06-14 18:14:35 -07004159 serverVers := expectedVersion
4160 if expectedVersion >= VersionTLS13 {
4161 serverVers = VersionTLS10
4162 }
David Benjaminb1dd8cd2016-09-26 19:20:48 -04004163 serverVers = versionToWire(serverVers, protocol == dtls)
4164
David Benjamin8b8c0062014-11-23 02:47:52 -05004165 testCases = append(testCases, testCase{
4166 protocol: protocol,
4167 testType: clientTest,
4168 name: "VersionNegotiation-Client-" + suffix,
4169 config: Config{
4170 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004171 Bugs: ProtocolBugs{
4172 ExpectInitialRecordVersion: clientVers,
4173 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004174 },
4175 flags: flags,
4176 expectedVersion: expectedVersion,
4177 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004178 testCases = append(testCases, testCase{
4179 protocol: protocol,
4180 testType: clientTest,
4181 name: "VersionNegotiation-Client2-" + suffix,
4182 config: Config{
4183 MaxVersion: runnerVers.version,
4184 Bugs: ProtocolBugs{
4185 ExpectInitialRecordVersion: clientVers,
4186 },
4187 },
4188 flags: []string{"-max-version", shimVersFlag},
4189 expectedVersion: expectedVersion,
4190 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004191
4192 testCases = append(testCases, testCase{
4193 protocol: protocol,
4194 testType: serverTest,
4195 name: "VersionNegotiation-Server-" + suffix,
4196 config: Config{
4197 MaxVersion: runnerVers.version,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004198 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004199 ExpectInitialRecordVersion: serverVers,
David Benjamin1e29a6b2014-12-10 02:27:24 -05004200 },
David Benjamin8b8c0062014-11-23 02:47:52 -05004201 },
4202 flags: flags,
4203 expectedVersion: expectedVersion,
4204 })
David Benjamin1eb367c2014-12-12 18:17:51 -05004205 testCases = append(testCases, testCase{
4206 protocol: protocol,
4207 testType: serverTest,
4208 name: "VersionNegotiation-Server2-" + suffix,
4209 config: Config{
4210 MaxVersion: runnerVers.version,
4211 Bugs: ProtocolBugs{
Nick Harper1fd39d82016-06-14 18:14:35 -07004212 ExpectInitialRecordVersion: serverVers,
David Benjamin1eb367c2014-12-12 18:17:51 -05004213 },
4214 },
4215 flags: []string{"-max-version", shimVersFlag},
4216 expectedVersion: expectedVersion,
4217 })
David Benjamin8b8c0062014-11-23 02:47:52 -05004218 }
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004219 }
4220 }
David Benjamin95c69562016-06-29 18:15:03 -04004221
Steven Valdezfdd10992016-09-15 16:27:05 -04004222 // Test the version extension at all versions.
4223 for _, vers := range tlsVersions {
4224 protocols := []protocol{tls}
4225 if vers.hasDTLS {
4226 protocols = append(protocols, dtls)
4227 }
4228 for _, protocol := range protocols {
4229 suffix := vers.name
4230 if protocol == dtls {
4231 suffix += "-DTLS"
4232 }
4233
4234 wireVersion := versionToWire(vers.version, protocol == dtls)
4235 testCases = append(testCases, testCase{
4236 protocol: protocol,
4237 testType: serverTest,
4238 name: "VersionNegotiationExtension-" + suffix,
4239 config: Config{
4240 Bugs: ProtocolBugs{
4241 SendSupportedVersions: []uint16{0x1111, wireVersion, 0x2222},
4242 },
4243 },
4244 expectedVersion: vers.version,
4245 })
4246 }
4247
4248 }
4249
4250 // If all versions are unknown, negotiation fails.
4251 testCases = append(testCases, testCase{
4252 testType: serverTest,
4253 name: "NoSupportedVersions",
4254 config: Config{
4255 Bugs: ProtocolBugs{
4256 SendSupportedVersions: []uint16{0x1111},
4257 },
4258 },
4259 shouldFail: true,
4260 expectedError: ":UNSUPPORTED_PROTOCOL:",
4261 })
4262 testCases = append(testCases, testCase{
4263 protocol: dtls,
4264 testType: serverTest,
4265 name: "NoSupportedVersions-DTLS",
4266 config: Config{
4267 Bugs: ProtocolBugs{
4268 SendSupportedVersions: []uint16{0x1111},
4269 },
4270 },
4271 shouldFail: true,
4272 expectedError: ":UNSUPPORTED_PROTOCOL:",
4273 })
4274
4275 testCases = append(testCases, testCase{
4276 testType: serverTest,
4277 name: "ClientHelloVersionTooHigh",
4278 config: Config{
4279 MaxVersion: VersionTLS13,
4280 Bugs: ProtocolBugs{
4281 SendClientVersion: 0x0304,
4282 OmitSupportedVersions: true,
4283 },
4284 },
4285 expectedVersion: VersionTLS12,
4286 })
4287
4288 testCases = append(testCases, testCase{
4289 testType: serverTest,
4290 name: "ConflictingVersionNegotiation",
4291 config: Config{
Steven Valdezfdd10992016-09-15 16:27:05 -04004292 Bugs: ProtocolBugs{
David Benjaminad75a662016-09-30 15:42:59 -04004293 SendClientVersion: VersionTLS12,
4294 SendSupportedVersions: []uint16{VersionTLS11},
Steven Valdezfdd10992016-09-15 16:27:05 -04004295 },
4296 },
David Benjaminad75a662016-09-30 15:42:59 -04004297 // The extension takes precedence over the ClientHello version.
4298 expectedVersion: VersionTLS11,
4299 })
4300
4301 testCases = append(testCases, testCase{
4302 testType: serverTest,
4303 name: "ConflictingVersionNegotiation-2",
4304 config: Config{
4305 Bugs: ProtocolBugs{
4306 SendClientVersion: VersionTLS11,
4307 SendSupportedVersions: []uint16{VersionTLS12},
4308 },
4309 },
4310 // The extension takes precedence over the ClientHello version.
4311 expectedVersion: VersionTLS12,
4312 })
4313
4314 testCases = append(testCases, testCase{
4315 testType: serverTest,
4316 name: "RejectFinalTLS13",
4317 config: Config{
4318 Bugs: ProtocolBugs{
4319 SendSupportedVersions: []uint16{VersionTLS13, VersionTLS12},
4320 },
4321 },
4322 // We currently implement a draft TLS 1.3 version. Ensure that
4323 // the true TLS 1.3 value is ignored for now.
Steven Valdezfdd10992016-09-15 16:27:05 -04004324 expectedVersion: VersionTLS12,
4325 })
4326
David Benjamin95c69562016-06-29 18:15:03 -04004327 // Test for version tolerance.
4328 testCases = append(testCases, testCase{
4329 testType: serverTest,
4330 name: "MinorVersionTolerance",
4331 config: Config{
4332 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004333 SendClientVersion: 0x03ff,
4334 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004335 },
4336 },
Steven Valdezfdd10992016-09-15 16:27:05 -04004337 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004338 })
4339 testCases = append(testCases, testCase{
4340 testType: serverTest,
4341 name: "MajorVersionTolerance",
4342 config: Config{
4343 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004344 SendClientVersion: 0x0400,
4345 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004346 },
4347 },
David Benjaminad75a662016-09-30 15:42:59 -04004348 // TLS 1.3 must be negotiated with the supported_versions
4349 // extension, not ClientHello.version.
Steven Valdezfdd10992016-09-15 16:27:05 -04004350 expectedVersion: VersionTLS12,
David Benjamin95c69562016-06-29 18:15:03 -04004351 })
David Benjaminad75a662016-09-30 15:42:59 -04004352 testCases = append(testCases, testCase{
4353 testType: serverTest,
4354 name: "VersionTolerance-TLS13",
4355 config: Config{
4356 Bugs: ProtocolBugs{
4357 // Although TLS 1.3 does not use
4358 // ClientHello.version, it still tolerates high
4359 // values there.
4360 SendClientVersion: 0x0400,
4361 },
4362 },
4363 expectedVersion: VersionTLS13,
4364 })
Steven Valdezfdd10992016-09-15 16:27:05 -04004365
David Benjamin95c69562016-06-29 18:15:03 -04004366 testCases = append(testCases, testCase{
4367 protocol: dtls,
4368 testType: serverTest,
4369 name: "MinorVersionTolerance-DTLS",
4370 config: Config{
4371 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004372 SendClientVersion: 0xfe00,
4373 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004374 },
4375 },
4376 expectedVersion: VersionTLS12,
4377 })
4378 testCases = append(testCases, testCase{
4379 protocol: dtls,
4380 testType: serverTest,
4381 name: "MajorVersionTolerance-DTLS",
4382 config: Config{
4383 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004384 SendClientVersion: 0xfdff,
4385 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004386 },
4387 },
4388 expectedVersion: VersionTLS12,
4389 })
4390
4391 // Test that versions below 3.0 are rejected.
4392 testCases = append(testCases, testCase{
4393 testType: serverTest,
4394 name: "VersionTooLow",
4395 config: Config{
4396 Bugs: ProtocolBugs{
Steven Valdezfdd10992016-09-15 16:27:05 -04004397 SendClientVersion: 0x0200,
4398 OmitSupportedVersions: true,
David Benjamin95c69562016-06-29 18:15:03 -04004399 },
4400 },
4401 shouldFail: true,
4402 expectedError: ":UNSUPPORTED_PROTOCOL:",
4403 })
4404 testCases = append(testCases, testCase{
4405 protocol: dtls,
4406 testType: serverTest,
4407 name: "VersionTooLow-DTLS",
4408 config: Config{
4409 Bugs: ProtocolBugs{
David Benjamin3c6a1ea2016-09-26 18:30:05 -04004410 SendClientVersion: 0xffff,
David Benjamin95c69562016-06-29 18:15:03 -04004411 },
4412 },
4413 shouldFail: true,
4414 expectedError: ":UNSUPPORTED_PROTOCOL:",
4415 })
David Benjamin1f61f0d2016-07-10 12:20:35 -04004416
David Benjamin2dc02042016-09-19 19:57:37 -04004417 testCases = append(testCases, testCase{
4418 name: "ServerBogusVersion",
4419 config: Config{
4420 Bugs: ProtocolBugs{
4421 SendServerHelloVersion: 0x1234,
4422 },
4423 },
4424 shouldFail: true,
4425 expectedError: ":UNSUPPORTED_PROTOCOL:",
4426 })
4427
David Benjamin1f61f0d2016-07-10 12:20:35 -04004428 // Test TLS 1.3's downgrade signal.
4429 testCases = append(testCases, testCase{
4430 name: "Downgrade-TLS12-Client",
4431 config: Config{
4432 Bugs: ProtocolBugs{
4433 NegotiateVersion: VersionTLS12,
4434 },
4435 },
David Benjamin592b5322016-09-30 15:15:01 -04004436 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004437 // TODO(davidben): This test should fail once TLS 1.3 is final
4438 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004439 })
4440 testCases = append(testCases, testCase{
4441 testType: serverTest,
4442 name: "Downgrade-TLS12-Server",
4443 config: Config{
4444 Bugs: ProtocolBugs{
David Benjamin592b5322016-09-30 15:15:01 -04004445 SendSupportedVersions: []uint16{VersionTLS12},
David Benjamin1f61f0d2016-07-10 12:20:35 -04004446 },
4447 },
David Benjamin592b5322016-09-30 15:15:01 -04004448 expectedVersion: VersionTLS12,
David Benjamin55108632016-08-11 22:01:18 -04004449 // TODO(davidben): This test should fail once TLS 1.3 is final
4450 // and the fallback signal restored.
David Benjamin1f61f0d2016-07-10 12:20:35 -04004451 })
David Benjamin7e2e6cf2014-08-07 17:44:24 -04004452}
4453
David Benjaminaccb4542014-12-12 23:44:33 -05004454func addMinimumVersionTests() {
4455 for i, shimVers := range tlsVersions {
4456 // Assemble flags to disable all older versions on the shim.
4457 var flags []string
4458 for _, vers := range tlsVersions[:i] {
4459 flags = append(flags, vers.flag)
4460 }
4461
4462 for _, runnerVers := range tlsVersions {
4463 protocols := []protocol{tls}
4464 if runnerVers.hasDTLS && shimVers.hasDTLS {
4465 protocols = append(protocols, dtls)
4466 }
4467 for _, protocol := range protocols {
4468 suffix := shimVers.name + "-" + runnerVers.name
4469 if protocol == dtls {
4470 suffix += "-DTLS"
4471 }
4472 shimVersFlag := strconv.Itoa(int(versionToWire(shimVers.version, protocol == dtls)))
4473
David Benjaminaccb4542014-12-12 23:44:33 -05004474 var expectedVersion uint16
4475 var shouldFail bool
David Benjamin6dbde982016-10-03 19:11:14 -04004476 var expectedError, expectedLocalError string
David Benjaminaccb4542014-12-12 23:44:33 -05004477 if runnerVers.version >= shimVers.version {
4478 expectedVersion = runnerVers.version
4479 } else {
4480 shouldFail = true
David Benjamin6dbde982016-10-03 19:11:14 -04004481 expectedError = ":UNSUPPORTED_PROTOCOL:"
4482 expectedLocalError = "remote error: protocol version not supported"
David Benjaminaccb4542014-12-12 23:44:33 -05004483 }
4484
4485 testCases = append(testCases, testCase{
4486 protocol: protocol,
4487 testType: clientTest,
4488 name: "MinimumVersion-Client-" + suffix,
4489 config: Config{
4490 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004491 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004492 // Ensure the server does not decline to
4493 // select a version (versions extension) or
4494 // cipher (some ciphers depend on versions).
4495 NegotiateVersion: runnerVers.version,
4496 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004497 },
David Benjaminaccb4542014-12-12 23:44:33 -05004498 },
David Benjamin87909c02014-12-13 01:55:01 -05004499 flags: flags,
4500 expectedVersion: expectedVersion,
4501 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004502 expectedError: expectedError,
4503 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004504 })
4505 testCases = append(testCases, testCase{
4506 protocol: protocol,
4507 testType: clientTest,
4508 name: "MinimumVersion-Client2-" + suffix,
4509 config: Config{
4510 MaxVersion: runnerVers.version,
Steven Valdezfdd10992016-09-15 16:27:05 -04004511 Bugs: ProtocolBugs{
David Benjamin6dbde982016-10-03 19:11:14 -04004512 // Ensure the server does not decline to
4513 // select a version (versions extension) or
4514 // cipher (some ciphers depend on versions).
4515 NegotiateVersion: runnerVers.version,
4516 IgnorePeerCipherPreferences: shouldFail,
Steven Valdezfdd10992016-09-15 16:27:05 -04004517 },
David Benjaminaccb4542014-12-12 23:44:33 -05004518 },
David Benjamin87909c02014-12-13 01:55:01 -05004519 flags: []string{"-min-version", shimVersFlag},
4520 expectedVersion: expectedVersion,
4521 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004522 expectedError: expectedError,
4523 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004524 })
4525
4526 testCases = append(testCases, testCase{
4527 protocol: protocol,
4528 testType: serverTest,
4529 name: "MinimumVersion-Server-" + suffix,
4530 config: Config{
4531 MaxVersion: runnerVers.version,
4532 },
David Benjamin87909c02014-12-13 01:55:01 -05004533 flags: flags,
4534 expectedVersion: expectedVersion,
4535 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004536 expectedError: expectedError,
4537 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004538 })
4539 testCases = append(testCases, testCase{
4540 protocol: protocol,
4541 testType: serverTest,
4542 name: "MinimumVersion-Server2-" + suffix,
4543 config: Config{
4544 MaxVersion: runnerVers.version,
4545 },
David Benjamin87909c02014-12-13 01:55:01 -05004546 flags: []string{"-min-version", shimVersFlag},
4547 expectedVersion: expectedVersion,
4548 shouldFail: shouldFail,
David Benjamin6dbde982016-10-03 19:11:14 -04004549 expectedError: expectedError,
4550 expectedLocalError: expectedLocalError,
David Benjaminaccb4542014-12-12 23:44:33 -05004551 })
4552 }
4553 }
4554 }
4555}
4556
David Benjamine78bfde2014-09-06 12:45:15 -04004557func addExtensionTests() {
David Benjamin4c3ddf72016-06-29 18:13:53 -04004558 // TODO(davidben): Extensions, where applicable, all move their server
4559 // halves to EncryptedExtensions in TLS 1.3. Duplicate each of these
4560 // tests for both. Also test interaction with 0-RTT when implemented.
4561
David Benjamin97d17d92016-07-14 16:12:00 -04004562 // Repeat extensions tests all versions except SSL 3.0.
4563 for _, ver := range tlsVersions {
4564 if ver.version == VersionSSL30 {
4565 continue
4566 }
4567
David Benjamin97d17d92016-07-14 16:12:00 -04004568 // Test that duplicate extensions are rejected.
4569 testCases = append(testCases, testCase{
4570 testType: clientTest,
4571 name: "DuplicateExtensionClient-" + ver.name,
4572 config: Config{
4573 MaxVersion: ver.version,
4574 Bugs: ProtocolBugs{
4575 DuplicateExtension: true,
4576 },
David Benjamine78bfde2014-09-06 12:45:15 -04004577 },
David Benjamin97d17d92016-07-14 16:12:00 -04004578 shouldFail: true,
4579 expectedLocalError: "remote error: error decoding message",
4580 })
4581 testCases = append(testCases, testCase{
4582 testType: serverTest,
4583 name: "DuplicateExtensionServer-" + ver.name,
4584 config: Config{
4585 MaxVersion: ver.version,
4586 Bugs: ProtocolBugs{
4587 DuplicateExtension: true,
4588 },
David Benjamine78bfde2014-09-06 12:45:15 -04004589 },
David Benjamin97d17d92016-07-14 16:12:00 -04004590 shouldFail: true,
4591 expectedLocalError: "remote error: error decoding message",
4592 })
4593
4594 // Test SNI.
4595 testCases = append(testCases, testCase{
4596 testType: clientTest,
4597 name: "ServerNameExtensionClient-" + ver.name,
4598 config: Config{
4599 MaxVersion: ver.version,
4600 Bugs: ProtocolBugs{
4601 ExpectServerName: "example.com",
4602 },
David Benjamine78bfde2014-09-06 12:45:15 -04004603 },
David Benjamin97d17d92016-07-14 16:12:00 -04004604 flags: []string{"-host-name", "example.com"},
4605 })
4606 testCases = append(testCases, testCase{
4607 testType: clientTest,
4608 name: "ServerNameExtensionClientMismatch-" + ver.name,
4609 config: Config{
4610 MaxVersion: ver.version,
4611 Bugs: ProtocolBugs{
4612 ExpectServerName: "mismatch.com",
4613 },
David Benjamine78bfde2014-09-06 12:45:15 -04004614 },
David Benjamin97d17d92016-07-14 16:12:00 -04004615 flags: []string{"-host-name", "example.com"},
4616 shouldFail: true,
4617 expectedLocalError: "tls: unexpected server name",
4618 })
4619 testCases = append(testCases, testCase{
4620 testType: clientTest,
4621 name: "ServerNameExtensionClientMissing-" + ver.name,
4622 config: Config{
4623 MaxVersion: ver.version,
4624 Bugs: ProtocolBugs{
4625 ExpectServerName: "missing.com",
4626 },
David Benjamine78bfde2014-09-06 12:45:15 -04004627 },
David Benjamin97d17d92016-07-14 16:12:00 -04004628 shouldFail: true,
4629 expectedLocalError: "tls: unexpected server name",
4630 })
4631 testCases = append(testCases, testCase{
4632 testType: serverTest,
4633 name: "ServerNameExtensionServer-" + ver.name,
4634 config: Config{
4635 MaxVersion: ver.version,
4636 ServerName: "example.com",
David Benjaminfc7b0862014-09-06 13:21:53 -04004637 },
David Benjamin97d17d92016-07-14 16:12:00 -04004638 flags: []string{"-expect-server-name", "example.com"},
Steven Valdez4aa154e2016-07-29 14:32:55 -04004639 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004640 })
4641
4642 // Test ALPN.
4643 testCases = append(testCases, testCase{
4644 testType: clientTest,
4645 name: "ALPNClient-" + ver.name,
4646 config: Config{
4647 MaxVersion: ver.version,
4648 NextProtos: []string{"foo"},
4649 },
4650 flags: []string{
4651 "-advertise-alpn", "\x03foo\x03bar\x03baz",
4652 "-expect-alpn", "foo",
4653 },
4654 expectedNextProto: "foo",
4655 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004656 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004657 })
4658 testCases = append(testCases, testCase{
David Benjamin3e517572016-08-11 11:52:23 -04004659 testType: clientTest,
4660 name: "ALPNClient-Mismatch-" + ver.name,
4661 config: Config{
4662 MaxVersion: ver.version,
4663 Bugs: ProtocolBugs{
4664 SendALPN: "baz",
4665 },
4666 },
4667 flags: []string{
4668 "-advertise-alpn", "\x03foo\x03bar",
4669 },
4670 shouldFail: true,
4671 expectedError: ":INVALID_ALPN_PROTOCOL:",
4672 expectedLocalError: "remote error: illegal parameter",
4673 })
4674 testCases = append(testCases, testCase{
David Benjamin97d17d92016-07-14 16:12:00 -04004675 testType: serverTest,
4676 name: "ALPNServer-" + ver.name,
4677 config: Config{
4678 MaxVersion: ver.version,
4679 NextProtos: []string{"foo", "bar", "baz"},
4680 },
4681 flags: []string{
4682 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4683 "-select-alpn", "foo",
4684 },
4685 expectedNextProto: "foo",
4686 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004687 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004688 })
4689 testCases = append(testCases, testCase{
4690 testType: serverTest,
4691 name: "ALPNServer-Decline-" + ver.name,
4692 config: Config{
4693 MaxVersion: ver.version,
4694 NextProtos: []string{"foo", "bar", "baz"},
4695 },
4696 flags: []string{"-decline-alpn"},
4697 expectNoNextProto: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004698 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004699 })
4700
David Benjamin25fe85b2016-08-09 20:00:32 -04004701 // Test ALPN in async mode as well to ensure that extensions callbacks are only
4702 // called once.
4703 testCases = append(testCases, testCase{
4704 testType: serverTest,
4705 name: "ALPNServer-Async-" + ver.name,
4706 config: Config{
4707 MaxVersion: ver.version,
4708 NextProtos: []string{"foo", "bar", "baz"},
4709 },
4710 flags: []string{
4711 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4712 "-select-alpn", "foo",
4713 "-async",
4714 },
4715 expectedNextProto: "foo",
4716 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004717 resumeSession: true,
David Benjamin25fe85b2016-08-09 20:00:32 -04004718 })
4719
David Benjamin97d17d92016-07-14 16:12:00 -04004720 var emptyString string
4721 testCases = append(testCases, testCase{
4722 testType: clientTest,
4723 name: "ALPNClient-EmptyProtocolName-" + ver.name,
4724 config: Config{
4725 MaxVersion: ver.version,
4726 NextProtos: []string{""},
4727 Bugs: ProtocolBugs{
4728 // A server returning an empty ALPN protocol
4729 // should be rejected.
4730 ALPNProtocol: &emptyString,
4731 },
4732 },
4733 flags: []string{
4734 "-advertise-alpn", "\x03foo",
4735 },
4736 shouldFail: true,
4737 expectedError: ":PARSE_TLSEXT:",
4738 })
4739 testCases = append(testCases, testCase{
4740 testType: serverTest,
4741 name: "ALPNServer-EmptyProtocolName-" + ver.name,
4742 config: Config{
4743 MaxVersion: ver.version,
4744 // A ClientHello containing an empty ALPN protocol
Adam Langleyefb0e162015-07-09 11:35:04 -07004745 // should be rejected.
David Benjamin97d17d92016-07-14 16:12:00 -04004746 NextProtos: []string{"foo", "", "baz"},
Adam Langleyefb0e162015-07-09 11:35:04 -07004747 },
David Benjamin97d17d92016-07-14 16:12:00 -04004748 flags: []string{
4749 "-select-alpn", "foo",
David Benjamin76c2efc2015-08-31 14:24:29 -04004750 },
David Benjamin97d17d92016-07-14 16:12:00 -04004751 shouldFail: true,
4752 expectedError: ":PARSE_TLSEXT:",
4753 })
4754
4755 // Test NPN and the interaction with ALPN.
4756 if ver.version < VersionTLS13 {
4757 // Test that the server prefers ALPN over NPN.
4758 testCases = append(testCases, testCase{
4759 testType: serverTest,
4760 name: "ALPNServer-Preferred-" + ver.name,
4761 config: Config{
4762 MaxVersion: ver.version,
4763 NextProtos: []string{"foo", "bar", "baz"},
4764 },
4765 flags: []string{
4766 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4767 "-select-alpn", "foo",
4768 "-advertise-npn", "\x03foo\x03bar\x03baz",
4769 },
4770 expectedNextProto: "foo",
4771 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004772 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004773 })
4774 testCases = append(testCases, testCase{
4775 testType: serverTest,
4776 name: "ALPNServer-Preferred-Swapped-" + ver.name,
4777 config: Config{
4778 MaxVersion: ver.version,
4779 NextProtos: []string{"foo", "bar", "baz"},
4780 Bugs: ProtocolBugs{
4781 SwapNPNAndALPN: true,
4782 },
4783 },
4784 flags: []string{
4785 "-expect-advertised-alpn", "\x03foo\x03bar\x03baz",
4786 "-select-alpn", "foo",
4787 "-advertise-npn", "\x03foo\x03bar\x03baz",
4788 },
4789 expectedNextProto: "foo",
4790 expectedNextProtoType: alpn,
Steven Valdez4aa154e2016-07-29 14:32:55 -04004791 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04004792 })
4793
4794 // Test that negotiating both NPN and ALPN is forbidden.
4795 testCases = append(testCases, testCase{
4796 name: "NegotiateALPNAndNPN-" + ver.name,
4797 config: Config{
4798 MaxVersion: ver.version,
4799 NextProtos: []string{"foo", "bar", "baz"},
4800 Bugs: ProtocolBugs{
4801 NegotiateALPNAndNPN: true,
4802 },
4803 },
4804 flags: []string{
4805 "-advertise-alpn", "\x03foo",
4806 "-select-next-proto", "foo",
4807 },
4808 shouldFail: true,
4809 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4810 })
4811 testCases = append(testCases, testCase{
4812 name: "NegotiateALPNAndNPN-Swapped-" + ver.name,
4813 config: Config{
4814 MaxVersion: ver.version,
4815 NextProtos: []string{"foo", "bar", "baz"},
4816 Bugs: ProtocolBugs{
4817 NegotiateALPNAndNPN: true,
4818 SwapNPNAndALPN: true,
4819 },
4820 },
4821 flags: []string{
4822 "-advertise-alpn", "\x03foo",
4823 "-select-next-proto", "foo",
4824 },
4825 shouldFail: true,
4826 expectedError: ":NEGOTIATED_BOTH_NPN_AND_ALPN:",
4827 })
4828
4829 // Test that NPN can be disabled with SSL_OP_DISABLE_NPN.
4830 testCases = append(testCases, testCase{
4831 name: "DisableNPN-" + ver.name,
4832 config: Config{
4833 MaxVersion: ver.version,
4834 NextProtos: []string{"foo"},
4835 },
4836 flags: []string{
4837 "-select-next-proto", "foo",
4838 "-disable-npn",
4839 },
4840 expectNoNextProto: true,
4841 })
4842 }
4843
4844 // Test ticket behavior.
Steven Valdez4aa154e2016-07-29 14:32:55 -04004845
4846 // Resume with a corrupt ticket.
4847 testCases = append(testCases, testCase{
4848 testType: serverTest,
4849 name: "CorruptTicket-" + ver.name,
4850 config: Config{
4851 MaxVersion: ver.version,
4852 Bugs: ProtocolBugs{
4853 CorruptTicket: true,
4854 },
4855 },
4856 resumeSession: true,
4857 expectResumeRejected: true,
4858 })
4859 // Test the ticket callback, with and without renewal.
4860 testCases = append(testCases, testCase{
4861 testType: serverTest,
4862 name: "TicketCallback-" + ver.name,
4863 config: Config{
4864 MaxVersion: ver.version,
4865 },
4866 resumeSession: true,
4867 flags: []string{"-use-ticket-callback"},
4868 })
4869 testCases = append(testCases, testCase{
4870 testType: serverTest,
4871 name: "TicketCallback-Renew-" + ver.name,
4872 config: Config{
4873 MaxVersion: ver.version,
4874 Bugs: ProtocolBugs{
4875 ExpectNewTicket: true,
4876 },
4877 },
4878 flags: []string{"-use-ticket-callback", "-renew-ticket"},
4879 resumeSession: true,
4880 })
4881
4882 // Test that the ticket callback is only called once when everything before
4883 // it in the ClientHello is asynchronous. This corrupts the ticket so
4884 // certificate selection callbacks run.
4885 testCases = append(testCases, testCase{
4886 testType: serverTest,
4887 name: "TicketCallback-SingleCall-" + ver.name,
4888 config: Config{
4889 MaxVersion: ver.version,
4890 Bugs: ProtocolBugs{
4891 CorruptTicket: true,
4892 },
4893 },
4894 resumeSession: true,
4895 expectResumeRejected: true,
4896 flags: []string{
4897 "-use-ticket-callback",
4898 "-async",
4899 },
4900 })
4901
4902 // Resume with an oversized session id.
David Benjamin97d17d92016-07-14 16:12:00 -04004903 if ver.version < VersionTLS13 {
David Benjamin97d17d92016-07-14 16:12:00 -04004904 testCases = append(testCases, testCase{
4905 testType: serverTest,
4906 name: "OversizedSessionId-" + ver.name,
4907 config: Config{
4908 MaxVersion: ver.version,
4909 Bugs: ProtocolBugs{
4910 OversizedSessionId: true,
4911 },
4912 },
4913 resumeSession: true,
4914 shouldFail: true,
4915 expectedError: ":DECODE_ERROR:",
4916 })
4917 }
4918
4919 // Basic DTLS-SRTP tests. Include fake profiles to ensure they
4920 // are ignored.
4921 if ver.hasDTLS {
4922 testCases = append(testCases, testCase{
4923 protocol: dtls,
4924 name: "SRTP-Client-" + ver.name,
4925 config: Config{
4926 MaxVersion: ver.version,
4927 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4928 },
4929 flags: []string{
4930 "-srtp-profiles",
4931 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4932 },
4933 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4934 })
4935 testCases = append(testCases, testCase{
4936 protocol: dtls,
4937 testType: serverTest,
4938 name: "SRTP-Server-" + ver.name,
4939 config: Config{
4940 MaxVersion: ver.version,
4941 SRTPProtectionProfiles: []uint16{40, SRTP_AES128_CM_HMAC_SHA1_80, 42},
4942 },
4943 flags: []string{
4944 "-srtp-profiles",
4945 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4946 },
4947 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4948 })
4949 // Test that the MKI is ignored.
4950 testCases = append(testCases, testCase{
4951 protocol: dtls,
4952 testType: serverTest,
4953 name: "SRTP-Server-IgnoreMKI-" + ver.name,
4954 config: Config{
4955 MaxVersion: ver.version,
4956 SRTPProtectionProfiles: []uint16{SRTP_AES128_CM_HMAC_SHA1_80},
4957 Bugs: ProtocolBugs{
4958 SRTPMasterKeyIdentifer: "bogus",
4959 },
4960 },
4961 flags: []string{
4962 "-srtp-profiles",
4963 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4964 },
4965 expectedSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_80,
4966 })
4967 // Test that SRTP isn't negotiated on the server if there were
4968 // no matching profiles.
4969 testCases = append(testCases, testCase{
4970 protocol: dtls,
4971 testType: serverTest,
4972 name: "SRTP-Server-NoMatch-" + ver.name,
4973 config: Config{
4974 MaxVersion: ver.version,
4975 SRTPProtectionProfiles: []uint16{100, 101, 102},
4976 },
4977 flags: []string{
4978 "-srtp-profiles",
4979 "SRTP_AES128_CM_SHA1_80:SRTP_AES128_CM_SHA1_32",
4980 },
4981 expectedSRTPProtectionProfile: 0,
4982 })
4983 // Test that the server returning an invalid SRTP profile is
4984 // flagged as an error by the client.
4985 testCases = append(testCases, testCase{
4986 protocol: dtls,
4987 name: "SRTP-Client-NoMatch-" + ver.name,
4988 config: Config{
4989 MaxVersion: ver.version,
4990 Bugs: ProtocolBugs{
4991 SendSRTPProtectionProfile: SRTP_AES128_CM_HMAC_SHA1_32,
4992 },
4993 },
4994 flags: []string{
4995 "-srtp-profiles",
4996 "SRTP_AES128_CM_SHA1_80",
4997 },
4998 shouldFail: true,
4999 expectedError: ":BAD_SRTP_PROTECTION_PROFILE_LIST:",
5000 })
5001 }
5002
5003 // Test SCT list.
5004 testCases = append(testCases, testCase{
5005 name: "SignedCertificateTimestampList-Client-" + ver.name,
5006 testType: clientTest,
5007 config: Config{
5008 MaxVersion: ver.version,
David Benjamin76c2efc2015-08-31 14:24:29 -04005009 },
David Benjamin97d17d92016-07-14 16:12:00 -04005010 flags: []string{
5011 "-enable-signed-cert-timestamps",
5012 "-expect-signed-cert-timestamps",
5013 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005014 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005015 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005016 })
David Benjamindaa88502016-10-04 16:32:16 -04005017
5018 // The SCT extension did not specify that it must only be sent on resumption as it
5019 // should have, so test that we tolerate but ignore it.
David Benjamin97d17d92016-07-14 16:12:00 -04005020 testCases = append(testCases, testCase{
5021 name: "SendSCTListOnResume-" + ver.name,
5022 config: Config{
5023 MaxVersion: ver.version,
5024 Bugs: ProtocolBugs{
5025 SendSCTListOnResume: []byte("bogus"),
5026 },
David Benjamind98452d2015-06-16 14:16:23 -04005027 },
David Benjamin97d17d92016-07-14 16:12:00 -04005028 flags: []string{
5029 "-enable-signed-cert-timestamps",
5030 "-expect-signed-cert-timestamps",
5031 base64.StdEncoding.EncodeToString(testSCTList),
Adam Langley38311732014-10-16 19:04:35 -07005032 },
Steven Valdez4aa154e2016-07-29 14:32:55 -04005033 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005034 })
David Benjamindaa88502016-10-04 16:32:16 -04005035
David Benjamin97d17d92016-07-14 16:12:00 -04005036 testCases = append(testCases, testCase{
5037 name: "SignedCertificateTimestampList-Server-" + ver.name,
5038 testType: serverTest,
5039 config: Config{
5040 MaxVersion: ver.version,
David Benjaminca6c8262014-11-15 19:06:08 -05005041 },
David Benjamin97d17d92016-07-14 16:12:00 -04005042 flags: []string{
5043 "-signed-cert-timestamps",
5044 base64.StdEncoding.EncodeToString(testSCTList),
David Benjaminca6c8262014-11-15 19:06:08 -05005045 },
David Benjamin97d17d92016-07-14 16:12:00 -04005046 expectedSCTList: testSCTList,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005047 resumeSession: true,
David Benjamin97d17d92016-07-14 16:12:00 -04005048 })
5049 }
David Benjamin4c3ddf72016-06-29 18:13:53 -04005050
Paul Lietar4fac72e2015-09-09 13:44:55 +01005051 testCases = append(testCases, testCase{
Adam Langley33ad2b52015-07-20 17:43:53 -07005052 testType: clientTest,
5053 name: "ClientHelloPadding",
5054 config: Config{
5055 Bugs: ProtocolBugs{
5056 RequireClientHelloSize: 512,
5057 },
5058 },
5059 // This hostname just needs to be long enough to push the
5060 // ClientHello into F5's danger zone between 256 and 511 bytes
5061 // long.
5062 flags: []string{"-host-name", "01234567890123456789012345678901234567890123456789012345678901234567890123456789.com"},
5063 })
David Benjaminc7ce9772015-10-09 19:32:41 -04005064
5065 // Extensions should not function in SSL 3.0.
5066 testCases = append(testCases, testCase{
5067 testType: serverTest,
5068 name: "SSLv3Extensions-NoALPN",
5069 config: Config{
5070 MaxVersion: VersionSSL30,
5071 NextProtos: []string{"foo", "bar", "baz"},
5072 },
5073 flags: []string{
5074 "-select-alpn", "foo",
5075 },
5076 expectNoNextProto: true,
5077 })
5078
5079 // Test session tickets separately as they follow a different codepath.
5080 testCases = append(testCases, testCase{
5081 testType: serverTest,
5082 name: "SSLv3Extensions-NoTickets",
5083 config: Config{
5084 MaxVersion: VersionSSL30,
5085 Bugs: ProtocolBugs{
5086 // Historically, session tickets in SSL 3.0
5087 // failed in different ways depending on whether
5088 // the client supported renegotiation_info.
5089 NoRenegotiationInfo: true,
5090 },
5091 },
5092 resumeSession: true,
5093 })
5094 testCases = append(testCases, testCase{
5095 testType: serverTest,
5096 name: "SSLv3Extensions-NoTickets2",
5097 config: Config{
5098 MaxVersion: VersionSSL30,
5099 },
5100 resumeSession: true,
5101 })
5102
5103 // But SSL 3.0 does send and process renegotiation_info.
5104 testCases = append(testCases, testCase{
5105 testType: serverTest,
5106 name: "SSLv3Extensions-RenegotiationInfo",
5107 config: Config{
5108 MaxVersion: VersionSSL30,
5109 Bugs: ProtocolBugs{
5110 RequireRenegotiationInfo: true,
5111 },
5112 },
5113 })
5114 testCases = append(testCases, testCase{
5115 testType: serverTest,
5116 name: "SSLv3Extensions-RenegotiationInfo-SCSV",
5117 config: Config{
5118 MaxVersion: VersionSSL30,
5119 Bugs: ProtocolBugs{
5120 NoRenegotiationInfo: true,
5121 SendRenegotiationSCSV: true,
5122 RequireRenegotiationInfo: true,
5123 },
5124 },
5125 })
Steven Valdez143e8b32016-07-11 13:19:03 -04005126
5127 // Test that illegal extensions in TLS 1.3 are rejected by the client if
5128 // in ServerHello.
5129 testCases = append(testCases, testCase{
5130 name: "NPN-Forbidden-TLS13",
5131 config: Config{
5132 MaxVersion: VersionTLS13,
5133 NextProtos: []string{"foo"},
5134 Bugs: ProtocolBugs{
5135 NegotiateNPNAtAllVersions: true,
5136 },
5137 },
5138 flags: []string{"-select-next-proto", "foo"},
5139 shouldFail: true,
5140 expectedError: ":ERROR_PARSING_EXTENSION:",
5141 })
5142 testCases = append(testCases, testCase{
5143 name: "EMS-Forbidden-TLS13",
5144 config: Config{
5145 MaxVersion: VersionTLS13,
5146 Bugs: ProtocolBugs{
5147 NegotiateEMSAtAllVersions: true,
5148 },
5149 },
5150 shouldFail: true,
5151 expectedError: ":ERROR_PARSING_EXTENSION:",
5152 })
5153 testCases = append(testCases, testCase{
5154 name: "RenegotiationInfo-Forbidden-TLS13",
5155 config: Config{
5156 MaxVersion: VersionTLS13,
5157 Bugs: ProtocolBugs{
5158 NegotiateRenegotiationInfoAtAllVersions: true,
5159 },
5160 },
5161 shouldFail: true,
5162 expectedError: ":ERROR_PARSING_EXTENSION:",
5163 })
5164 testCases = append(testCases, testCase{
5165 name: "ChannelID-Forbidden-TLS13",
5166 config: Config{
5167 MaxVersion: VersionTLS13,
5168 RequestChannelID: true,
5169 Bugs: ProtocolBugs{
5170 NegotiateChannelIDAtAllVersions: true,
5171 },
5172 },
5173 flags: []string{"-send-channel-id", path.Join(*resourceDir, channelIDKeyFile)},
5174 shouldFail: true,
5175 expectedError: ":ERROR_PARSING_EXTENSION:",
5176 })
5177 testCases = append(testCases, testCase{
5178 name: "Ticket-Forbidden-TLS13",
5179 config: Config{
5180 MaxVersion: VersionTLS12,
5181 },
5182 resumeConfig: &Config{
5183 MaxVersion: VersionTLS13,
5184 Bugs: ProtocolBugs{
5185 AdvertiseTicketExtension: true,
5186 },
5187 },
5188 resumeSession: true,
5189 shouldFail: true,
5190 expectedError: ":ERROR_PARSING_EXTENSION:",
5191 })
5192
5193 // Test that illegal extensions in TLS 1.3 are declined by the server if
5194 // offered in ClientHello. The runner's server will fail if this occurs,
5195 // so we exercise the offering path. (EMS and Renegotiation Info are
5196 // implicit in every test.)
5197 testCases = append(testCases, testCase{
5198 testType: serverTest,
5199 name: "ChannelID-Declined-TLS13",
5200 config: Config{
5201 MaxVersion: VersionTLS13,
5202 ChannelID: channelIDKey,
5203 },
5204 flags: []string{"-enable-channel-id"},
5205 })
5206 testCases = append(testCases, testCase{
5207 testType: serverTest,
David Benjamin73647192016-09-22 16:24:04 -04005208 name: "NPN-Declined-TLS13",
Steven Valdez143e8b32016-07-11 13:19:03 -04005209 config: Config{
5210 MaxVersion: VersionTLS13,
5211 NextProtos: []string{"bar"},
5212 },
5213 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
5214 })
David Benjamin196df5b2016-09-21 16:23:27 -04005215
5216 testCases = append(testCases, testCase{
5217 testType: serverTest,
5218 name: "InvalidChannelIDSignature",
5219 config: Config{
5220 MaxVersion: VersionTLS12,
5221 ChannelID: channelIDKey,
5222 Bugs: ProtocolBugs{
5223 InvalidChannelIDSignature: true,
5224 },
5225 },
5226 flags: []string{"-enable-channel-id"},
5227 shouldFail: true,
5228 expectedError: ":CHANNEL_ID_SIGNATURE_INVALID:",
5229 expectedLocalError: "remote error: error decrypting message",
5230 })
David Benjamindaa88502016-10-04 16:32:16 -04005231
5232 // OpenSSL sends the status_request extension on resumption in TLS 1.2. Test that this is
5233 // tolerated.
5234 testCases = append(testCases, testCase{
5235 name: "SendOCSPResponseOnResume-TLS12",
5236 config: Config{
5237 MaxVersion: VersionTLS12,
5238 Bugs: ProtocolBugs{
5239 SendOCSPResponseOnResume: []byte("bogus"),
5240 },
5241 },
5242 flags: []string{
5243 "-enable-ocsp-stapling",
5244 "-expect-ocsp-response",
5245 base64.StdEncoding.EncodeToString(testOCSPResponse),
5246 },
5247 resumeSession: true,
5248 })
5249
5250 // Beginning TLS 1.3, enforce this does not happen.
5251 testCases = append(testCases, testCase{
5252 name: "SendOCSPResponseOnResume-TLS13",
5253 config: Config{
5254 MaxVersion: VersionTLS13,
5255 Bugs: ProtocolBugs{
5256 SendOCSPResponseOnResume: []byte("bogus"),
5257 },
5258 },
5259 flags: []string{
5260 "-enable-ocsp-stapling",
5261 "-expect-ocsp-response",
5262 base64.StdEncoding.EncodeToString(testOCSPResponse),
5263 },
5264 resumeSession: true,
5265 shouldFail: true,
5266 expectedError: ":ERROR_PARSING_EXTENSION:",
5267 })
David Benjamine78bfde2014-09-06 12:45:15 -04005268}
5269
David Benjamin01fe8202014-09-24 15:21:44 -04005270func addResumptionVersionTests() {
David Benjamin01fe8202014-09-24 15:21:44 -04005271 for _, sessionVers := range tlsVersions {
David Benjamin01fe8202014-09-24 15:21:44 -04005272 for _, resumeVers := range tlsVersions {
Steven Valdez803c77a2016-09-06 14:13:43 -04005273 // SSL 3.0 does not have tickets and TLS 1.3 does not
5274 // have session IDs, so skip their cross-resumption
5275 // tests.
5276 if (sessionVers.version >= VersionTLS13 && resumeVers.version == VersionSSL30) ||
5277 (resumeVers.version >= VersionTLS13 && sessionVers.version == VersionSSL30) {
5278 continue
Nick Harper1fd39d82016-06-14 18:14:35 -07005279 }
5280
David Benjamin8b8c0062014-11-23 02:47:52 -05005281 protocols := []protocol{tls}
5282 if sessionVers.hasDTLS && resumeVers.hasDTLS {
5283 protocols = append(protocols, dtls)
David Benjaminbdf5e722014-11-11 00:52:15 -05005284 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005285 for _, protocol := range protocols {
5286 suffix := "-" + sessionVers.name + "-" + resumeVers.name
5287 if protocol == dtls {
5288 suffix += "-DTLS"
5289 }
5290
David Benjaminece3de92015-03-16 18:02:20 -04005291 if sessionVers.version == resumeVers.version {
5292 testCases = append(testCases, testCase{
5293 protocol: protocol,
5294 name: "Resume-Client" + suffix,
5295 resumeSession: true,
5296 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005297 MaxVersion: sessionVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005298 Bugs: ProtocolBugs{
5299 ExpectNoTLS12Session: sessionVers.version >= VersionTLS13,
5300 ExpectNoTLS13PSK: sessionVers.version < VersionTLS13,
5301 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005302 },
David Benjaminece3de92015-03-16 18:02:20 -04005303 expectedVersion: sessionVers.version,
5304 expectedResumeVersion: resumeVers.version,
5305 })
5306 } else {
David Benjamin405da482016-08-08 17:25:07 -04005307 error := ":OLD_SESSION_VERSION_NOT_RETURNED:"
5308
5309 // Offering a TLS 1.3 session sends an empty session ID, so
5310 // there is no way to convince a non-lookahead client the
5311 // session was resumed. It will appear to the client that a
5312 // stray ChangeCipherSpec was sent.
5313 if resumeVers.version < VersionTLS13 && sessionVers.version >= VersionTLS13 {
5314 error = ":UNEXPECTED_RECORD:"
Steven Valdez4aa154e2016-07-29 14:32:55 -04005315 }
5316
David Benjaminece3de92015-03-16 18:02:20 -04005317 testCases = append(testCases, testCase{
5318 protocol: protocol,
5319 name: "Resume-Client-Mismatch" + suffix,
5320 resumeSession: true,
5321 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005322 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005323 },
David Benjaminece3de92015-03-16 18:02:20 -04005324 expectedVersion: sessionVers.version,
5325 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005326 MaxVersion: resumeVers.version,
David Benjaminece3de92015-03-16 18:02:20 -04005327 Bugs: ProtocolBugs{
David Benjamin405da482016-08-08 17:25:07 -04005328 AcceptAnySession: true,
David Benjaminece3de92015-03-16 18:02:20 -04005329 },
5330 },
5331 expectedResumeVersion: resumeVers.version,
5332 shouldFail: true,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005333 expectedError: error,
David Benjaminece3de92015-03-16 18:02:20 -04005334 })
5335 }
David Benjamin8b8c0062014-11-23 02:47:52 -05005336
5337 testCases = append(testCases, testCase{
5338 protocol: protocol,
5339 name: "Resume-Client-NoResume" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005340 resumeSession: true,
5341 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005342 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005343 },
5344 expectedVersion: sessionVers.version,
5345 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005346 MaxVersion: resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005347 },
5348 newSessionsOnResume: true,
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005349 expectResumeRejected: true,
David Benjamin8b8c0062014-11-23 02:47:52 -05005350 expectedResumeVersion: resumeVers.version,
5351 })
5352
David Benjamin8b8c0062014-11-23 02:47:52 -05005353 testCases = append(testCases, testCase{
5354 protocol: protocol,
5355 testType: serverTest,
5356 name: "Resume-Server" + suffix,
David Benjamin8b8c0062014-11-23 02:47:52 -05005357 resumeSession: true,
5358 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005359 MaxVersion: sessionVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005360 },
Adam Langleyb0eef0a2015-06-02 10:47:39 -07005361 expectedVersion: sessionVers.version,
5362 expectResumeRejected: sessionVers.version != resumeVers.version,
David Benjamin8b8c0062014-11-23 02:47:52 -05005363 resumeConfig: &Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04005364 MaxVersion: resumeVers.version,
David Benjamin405da482016-08-08 17:25:07 -04005365 Bugs: ProtocolBugs{
5366 SendBothTickets: true,
5367 },
David Benjamin8b8c0062014-11-23 02:47:52 -05005368 },
5369 expectedResumeVersion: resumeVers.version,
5370 })
5371 }
David Benjamin01fe8202014-09-24 15:21:44 -04005372 }
5373 }
David Benjaminece3de92015-03-16 18:02:20 -04005374
5375 testCases = append(testCases, testCase{
5376 name: "Resume-Client-CipherMismatch",
5377 resumeSession: true,
5378 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005379 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005380 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5381 },
5382 resumeConfig: &Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005383 MaxVersion: VersionTLS12,
David Benjaminece3de92015-03-16 18:02:20 -04005384 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
5385 Bugs: ProtocolBugs{
5386 SendCipherSuite: TLS_RSA_WITH_AES_128_CBC_SHA,
5387 },
5388 },
5389 shouldFail: true,
5390 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5391 })
Steven Valdez4aa154e2016-07-29 14:32:55 -04005392
5393 testCases = append(testCases, testCase{
5394 name: "Resume-Client-CipherMismatch-TLS13",
5395 resumeSession: true,
5396 config: Config{
5397 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005398 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005399 },
5400 resumeConfig: &Config{
5401 MaxVersion: VersionTLS13,
Steven Valdez803c77a2016-09-06 14:13:43 -04005402 CipherSuites: []uint16{TLS_AES_128_GCM_SHA256},
Steven Valdez4aa154e2016-07-29 14:32:55 -04005403 Bugs: ProtocolBugs{
Steven Valdez803c77a2016-09-06 14:13:43 -04005404 SendCipherSuite: TLS_AES_256_GCM_SHA384,
Steven Valdez4aa154e2016-07-29 14:32:55 -04005405 },
5406 },
5407 shouldFail: true,
5408 expectedError: ":OLD_SESSION_CIPHER_NOT_RETURNED:",
5409 })
David Benjamin01fe8202014-09-24 15:21:44 -04005410}
5411
Adam Langley2ae77d22014-10-28 17:29:33 -07005412func addRenegotiationTests() {
David Benjamin44d3eed2015-05-21 01:29:55 -04005413 // Servers cannot renegotiate.
David Benjaminb16346b2015-04-08 19:16:58 -04005414 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005415 testType: serverTest,
5416 name: "Renegotiate-Server-Forbidden",
5417 config: Config{
5418 MaxVersion: VersionTLS12,
5419 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005420 renegotiate: 1,
David Benjaminb16346b2015-04-08 19:16:58 -04005421 shouldFail: true,
5422 expectedError: ":NO_RENEGOTIATION:",
5423 expectedLocalError: "remote error: no renegotiation",
5424 })
Adam Langley5021b222015-06-12 18:27:58 -07005425 // The server shouldn't echo the renegotiation extension unless
5426 // requested by the client.
5427 testCases = append(testCases, testCase{
5428 testType: serverTest,
5429 name: "Renegotiate-Server-NoExt",
5430 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005431 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005432 Bugs: ProtocolBugs{
5433 NoRenegotiationInfo: true,
5434 RequireRenegotiationInfo: true,
5435 },
5436 },
5437 shouldFail: true,
5438 expectedLocalError: "renegotiation extension missing",
5439 })
5440 // The renegotiation SCSV should be sufficient for the server to echo
5441 // the extension.
5442 testCases = append(testCases, testCase{
5443 testType: serverTest,
5444 name: "Renegotiate-Server-NoExt-SCSV",
5445 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005446 MaxVersion: VersionTLS12,
Adam Langley5021b222015-06-12 18:27:58 -07005447 Bugs: ProtocolBugs{
5448 NoRenegotiationInfo: true,
5449 SendRenegotiationSCSV: true,
5450 RequireRenegotiationInfo: true,
5451 },
5452 },
5453 })
Adam Langleycf2d4f42014-10-28 19:06:14 -07005454 testCases = append(testCases, testCase{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005455 name: "Renegotiate-Client",
David Benjamincdea40c2015-03-19 14:09:43 -04005456 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005457 MaxVersion: VersionTLS12,
David Benjamincdea40c2015-03-19 14:09:43 -04005458 Bugs: ProtocolBugs{
David Benjamin4b27d9f2015-05-12 22:42:52 -04005459 FailIfResumeOnRenego: true,
David Benjamincdea40c2015-03-19 14:09:43 -04005460 },
5461 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005462 renegotiate: 1,
5463 flags: []string{
5464 "-renegotiate-freely",
5465 "-expect-total-renegotiations", "1",
5466 },
David Benjamincdea40c2015-03-19 14:09:43 -04005467 })
5468 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005469 name: "Renegotiate-Client-EmptyExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005470 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005471 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005472 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005473 Bugs: ProtocolBugs{
5474 EmptyRenegotiationInfo: true,
5475 },
5476 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005477 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005478 shouldFail: true,
5479 expectedError: ":RENEGOTIATION_MISMATCH:",
5480 })
5481 testCases = append(testCases, testCase{
5482 name: "Renegotiate-Client-BadExt",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005483 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005484 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005485 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005486 Bugs: ProtocolBugs{
5487 BadRenegotiationInfo: true,
5488 },
5489 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005490 flags: []string{"-renegotiate-freely"},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005491 shouldFail: true,
5492 expectedError: ":RENEGOTIATION_MISMATCH:",
5493 })
5494 testCases = append(testCases, testCase{
David Benjamin3e052de2015-11-25 20:10:31 -05005495 name: "Renegotiate-Client-Downgrade",
5496 renegotiate: 1,
5497 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005498 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005499 Bugs: ProtocolBugs{
5500 NoRenegotiationInfoAfterInitial: true,
5501 },
5502 },
5503 flags: []string{"-renegotiate-freely"},
5504 shouldFail: true,
5505 expectedError: ":RENEGOTIATION_MISMATCH:",
5506 })
5507 testCases = append(testCases, testCase{
5508 name: "Renegotiate-Client-Upgrade",
5509 renegotiate: 1,
5510 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005511 MaxVersion: VersionTLS12,
David Benjamin3e052de2015-11-25 20:10:31 -05005512 Bugs: ProtocolBugs{
5513 NoRenegotiationInfoInInitial: true,
5514 },
5515 },
5516 flags: []string{"-renegotiate-freely"},
5517 shouldFail: true,
5518 expectedError: ":RENEGOTIATION_MISMATCH:",
5519 })
5520 testCases = append(testCases, testCase{
David Benjamincff0b902015-05-15 23:09:47 -04005521 name: "Renegotiate-Client-NoExt-Allowed",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005522 renegotiate: 1,
David Benjamincff0b902015-05-15 23:09:47 -04005523 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005524 MaxVersion: VersionTLS12,
David Benjamincff0b902015-05-15 23:09:47 -04005525 Bugs: ProtocolBugs{
5526 NoRenegotiationInfo: true,
5527 },
5528 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005529 flags: []string{
5530 "-renegotiate-freely",
5531 "-expect-total-renegotiations", "1",
5532 },
David Benjamincff0b902015-05-15 23:09:47 -04005533 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005534
5535 // Test that the server may switch ciphers on renegotiation without
5536 // problems.
David Benjamincff0b902015-05-15 23:09:47 -04005537 testCases = append(testCases, testCase{
Adam Langleycf2d4f42014-10-28 19:06:14 -07005538 name: "Renegotiate-Client-SwitchCiphers",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005539 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005540 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005541 MaxVersion: VersionTLS12,
Matt Braithwaite07e78062016-08-21 14:50:43 -07005542 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
Adam Langleycf2d4f42014-10-28 19:06:14 -07005543 },
5544 renegotiateCiphers: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005545 flags: []string{
5546 "-renegotiate-freely",
5547 "-expect-total-renegotiations", "1",
5548 },
Adam Langleycf2d4f42014-10-28 19:06:14 -07005549 })
5550 testCases = append(testCases, testCase{
5551 name: "Renegotiate-Client-SwitchCiphers2",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005552 renegotiate: 1,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005553 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005554 MaxVersion: VersionTLS12,
Adam Langleycf2d4f42014-10-28 19:06:14 -07005555 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5556 },
Matt Braithwaite07e78062016-08-21 14:50:43 -07005557 renegotiateCiphers: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005558 flags: []string{
5559 "-renegotiate-freely",
5560 "-expect-total-renegotiations", "1",
5561 },
David Benjaminb16346b2015-04-08 19:16:58 -04005562 })
David Benjamine7e36aa2016-08-08 12:39:41 -04005563
5564 // Test that the server may not switch versions on renegotiation.
5565 testCases = append(testCases, testCase{
5566 name: "Renegotiate-Client-SwitchVersion",
5567 config: Config{
5568 MaxVersion: VersionTLS12,
5569 // Pick a cipher which exists at both versions.
5570 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_CBC_SHA},
5571 Bugs: ProtocolBugs{
5572 NegotiateVersionOnRenego: VersionTLS11,
5573 },
5574 },
5575 renegotiate: 1,
5576 flags: []string{
5577 "-renegotiate-freely",
5578 "-expect-total-renegotiations", "1",
5579 },
5580 shouldFail: true,
5581 expectedError: ":WRONG_SSL_VERSION:",
5582 })
5583
David Benjaminb16346b2015-04-08 19:16:58 -04005584 testCases = append(testCases, testCase{
David Benjaminc44b1df2014-11-23 12:11:01 -05005585 name: "Renegotiate-SameClientVersion",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005586 renegotiate: 1,
David Benjaminc44b1df2014-11-23 12:11:01 -05005587 config: Config{
5588 MaxVersion: VersionTLS10,
5589 Bugs: ProtocolBugs{
5590 RequireSameRenegoClientVersion: true,
5591 },
5592 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005593 flags: []string{
5594 "-renegotiate-freely",
5595 "-expect-total-renegotiations", "1",
5596 },
David Benjaminc44b1df2014-11-23 12:11:01 -05005597 })
Adam Langleyb558c4c2015-07-08 12:16:38 -07005598 testCases = append(testCases, testCase{
5599 name: "Renegotiate-FalseStart",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005600 renegotiate: 1,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005601 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07005602 MaxVersion: VersionTLS12,
Adam Langleyb558c4c2015-07-08 12:16:38 -07005603 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
5604 NextProtos: []string{"foo"},
5605 },
5606 flags: []string{
5607 "-false-start",
5608 "-select-next-proto", "foo",
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005609 "-renegotiate-freely",
David Benjamin324dce42015-10-12 19:49:00 -04005610 "-expect-total-renegotiations", "1",
Adam Langleyb558c4c2015-07-08 12:16:38 -07005611 },
5612 shimWritesFirst: true,
5613 })
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005614
5615 // Client-side renegotiation controls.
5616 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005617 name: "Renegotiate-Client-Forbidden-1",
5618 config: Config{
5619 MaxVersion: VersionTLS12,
5620 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005621 renegotiate: 1,
5622 shouldFail: true,
5623 expectedError: ":NO_RENEGOTIATION:",
5624 expectedLocalError: "remote error: no renegotiation",
5625 })
5626 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005627 name: "Renegotiate-Client-Once-1",
5628 config: Config{
5629 MaxVersion: VersionTLS12,
5630 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005631 renegotiate: 1,
5632 flags: []string{
5633 "-renegotiate-once",
5634 "-expect-total-renegotiations", "1",
5635 },
5636 })
5637 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005638 name: "Renegotiate-Client-Freely-1",
5639 config: Config{
5640 MaxVersion: VersionTLS12,
5641 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005642 renegotiate: 1,
5643 flags: []string{
5644 "-renegotiate-freely",
5645 "-expect-total-renegotiations", "1",
5646 },
5647 })
5648 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005649 name: "Renegotiate-Client-Once-2",
5650 config: Config{
5651 MaxVersion: VersionTLS12,
5652 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005653 renegotiate: 2,
5654 flags: []string{"-renegotiate-once"},
5655 shouldFail: true,
5656 expectedError: ":NO_RENEGOTIATION:",
5657 expectedLocalError: "remote error: no renegotiation",
5658 })
5659 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005660 name: "Renegotiate-Client-Freely-2",
5661 config: Config{
5662 MaxVersion: VersionTLS12,
5663 },
David Benjamin1d5ef3b2015-10-12 19:54:18 -04005664 renegotiate: 2,
5665 flags: []string{
5666 "-renegotiate-freely",
5667 "-expect-total-renegotiations", "2",
5668 },
5669 })
Adam Langley27a0d082015-11-03 13:34:10 -08005670 testCases = append(testCases, testCase{
5671 name: "Renegotiate-Client-NoIgnore",
5672 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005673 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005674 Bugs: ProtocolBugs{
5675 SendHelloRequestBeforeEveryAppDataRecord: true,
5676 },
5677 },
5678 shouldFail: true,
5679 expectedError: ":NO_RENEGOTIATION:",
5680 })
5681 testCases = append(testCases, testCase{
5682 name: "Renegotiate-Client-Ignore",
5683 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04005684 MaxVersion: VersionTLS12,
Adam Langley27a0d082015-11-03 13:34:10 -08005685 Bugs: ProtocolBugs{
5686 SendHelloRequestBeforeEveryAppDataRecord: true,
5687 },
5688 },
5689 flags: []string{
5690 "-renegotiate-ignore",
5691 "-expect-total-renegotiations", "0",
5692 },
5693 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04005694
David Benjamin34941c02016-10-08 11:45:31 -04005695 // Renegotiation is not allowed at SSL 3.0.
5696 testCases = append(testCases, testCase{
5697 name: "Renegotiate-Client-SSL3",
5698 config: Config{
5699 MaxVersion: VersionSSL30,
5700 },
5701 renegotiate: 1,
5702 flags: []string{
5703 "-renegotiate-freely",
5704 "-expect-total-renegotiations", "1",
5705 },
5706 shouldFail: true,
5707 expectedError: ":NO_RENEGOTIATION:",
5708 expectedLocalError: "remote error: no renegotiation",
5709 })
5710
David Benjamin397c8e62016-07-08 14:14:36 -07005711 // Stray HelloRequests during the handshake are ignored in TLS 1.2.
David Benjamin71dd6662016-07-08 14:10:48 -07005712 testCases = append(testCases, testCase{
5713 name: "StrayHelloRequest",
5714 config: Config{
5715 MaxVersion: VersionTLS12,
5716 Bugs: ProtocolBugs{
5717 SendHelloRequestBeforeEveryHandshakeMessage: true,
5718 },
5719 },
5720 })
5721 testCases = append(testCases, testCase{
5722 name: "StrayHelloRequest-Packed",
5723 config: Config{
5724 MaxVersion: VersionTLS12,
5725 Bugs: ProtocolBugs{
5726 PackHandshakeFlight: true,
5727 SendHelloRequestBeforeEveryHandshakeMessage: true,
5728 },
5729 },
5730 })
5731
David Benjamin12d2c482016-07-24 10:56:51 -04005732 // Test renegotiation works if HelloRequest and server Finished come in
5733 // the same record.
5734 testCases = append(testCases, testCase{
5735 name: "Renegotiate-Client-Packed",
5736 config: Config{
5737 MaxVersion: VersionTLS12,
5738 Bugs: ProtocolBugs{
5739 PackHandshakeFlight: true,
5740 PackHelloRequestWithFinished: true,
5741 },
5742 },
5743 renegotiate: 1,
5744 flags: []string{
5745 "-renegotiate-freely",
5746 "-expect-total-renegotiations", "1",
5747 },
5748 })
5749
David Benjamin397c8e62016-07-08 14:14:36 -07005750 // Renegotiation is forbidden in TLS 1.3.
5751 testCases = append(testCases, testCase{
5752 name: "Renegotiate-Client-TLS13",
5753 config: Config{
5754 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04005755 Bugs: ProtocolBugs{
5756 SendHelloRequestBeforeEveryAppDataRecord: true,
5757 },
David Benjamin397c8e62016-07-08 14:14:36 -07005758 },
David Benjamin397c8e62016-07-08 14:14:36 -07005759 flags: []string{
5760 "-renegotiate-freely",
5761 },
Steven Valdez8e1c7be2016-07-26 12:39:22 -04005762 shouldFail: true,
5763 expectedError: ":UNEXPECTED_MESSAGE:",
David Benjamin397c8e62016-07-08 14:14:36 -07005764 })
5765
5766 // Stray HelloRequests during the handshake are forbidden in TLS 1.3.
5767 testCases = append(testCases, testCase{
5768 name: "StrayHelloRequest-TLS13",
5769 config: Config{
5770 MaxVersion: VersionTLS13,
5771 Bugs: ProtocolBugs{
5772 SendHelloRequestBeforeEveryHandshakeMessage: true,
5773 },
5774 },
5775 shouldFail: true,
5776 expectedError: ":UNEXPECTED_MESSAGE:",
5777 })
Adam Langley2ae77d22014-10-28 17:29:33 -07005778}
5779
David Benjamin5e961c12014-11-07 01:48:35 -05005780func addDTLSReplayTests() {
5781 // Test that sequence number replays are detected.
5782 testCases = append(testCases, testCase{
5783 protocol: dtls,
5784 name: "DTLS-Replay",
David Benjamin8e6db492015-07-25 18:29:23 -04005785 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005786 replayWrites: true,
5787 })
5788
David Benjamin8e6db492015-07-25 18:29:23 -04005789 // Test the incoming sequence number skipping by values larger
David Benjamin5e961c12014-11-07 01:48:35 -05005790 // than the retransmit window.
5791 testCases = append(testCases, testCase{
5792 protocol: dtls,
5793 name: "DTLS-Replay-LargeGaps",
5794 config: Config{
5795 Bugs: ProtocolBugs{
David Benjamin8e6db492015-07-25 18:29:23 -04005796 SequenceNumberMapping: func(in uint64) uint64 {
5797 return in * 127
5798 },
David Benjamin5e961c12014-11-07 01:48:35 -05005799 },
5800 },
David Benjamin8e6db492015-07-25 18:29:23 -04005801 messageCount: 200,
5802 replayWrites: true,
5803 })
5804
5805 // Test the incoming sequence number changing non-monotonically.
5806 testCases = append(testCases, testCase{
5807 protocol: dtls,
5808 name: "DTLS-Replay-NonMonotonic",
5809 config: Config{
5810 Bugs: ProtocolBugs{
5811 SequenceNumberMapping: func(in uint64) uint64 {
5812 return in ^ 31
5813 },
5814 },
5815 },
5816 messageCount: 200,
David Benjamin5e961c12014-11-07 01:48:35 -05005817 replayWrites: true,
5818 })
5819}
5820
Nick Harper60edffd2016-06-21 15:19:24 -07005821var testSignatureAlgorithms = []struct {
David Benjamin000800a2014-11-14 01:43:59 -05005822 name string
Nick Harper60edffd2016-06-21 15:19:24 -07005823 id signatureAlgorithm
5824 cert testCert
David Benjamin000800a2014-11-14 01:43:59 -05005825}{
Nick Harper60edffd2016-06-21 15:19:24 -07005826 {"RSA-PKCS1-SHA1", signatureRSAPKCS1WithSHA1, testCertRSA},
5827 {"RSA-PKCS1-SHA256", signatureRSAPKCS1WithSHA256, testCertRSA},
5828 {"RSA-PKCS1-SHA384", signatureRSAPKCS1WithSHA384, testCertRSA},
5829 {"RSA-PKCS1-SHA512", signatureRSAPKCS1WithSHA512, testCertRSA},
David Benjamin33863262016-07-08 17:20:12 -07005830 {"ECDSA-SHA1", signatureECDSAWithSHA1, testCertECDSAP256},
David Benjamin33863262016-07-08 17:20:12 -07005831 {"ECDSA-P256-SHA256", signatureECDSAWithP256AndSHA256, testCertECDSAP256},
5832 {"ECDSA-P384-SHA384", signatureECDSAWithP384AndSHA384, testCertECDSAP384},
5833 {"ECDSA-P521-SHA512", signatureECDSAWithP521AndSHA512, testCertECDSAP521},
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005834 {"RSA-PSS-SHA256", signatureRSAPSSWithSHA256, testCertRSA},
5835 {"RSA-PSS-SHA384", signatureRSAPSSWithSHA384, testCertRSA},
5836 {"RSA-PSS-SHA512", signatureRSAPSSWithSHA512, testCertRSA},
David Benjamin5208fd42016-07-13 21:43:25 -04005837 // Tests for key types prior to TLS 1.2.
5838 {"RSA", 0, testCertRSA},
5839 {"ECDSA", 0, testCertECDSAP256},
David Benjamin000800a2014-11-14 01:43:59 -05005840}
5841
Nick Harper60edffd2016-06-21 15:19:24 -07005842const fakeSigAlg1 signatureAlgorithm = 0x2a01
5843const fakeSigAlg2 signatureAlgorithm = 0xff01
5844
5845func addSignatureAlgorithmTests() {
David Benjamin5208fd42016-07-13 21:43:25 -04005846 // Not all ciphers involve a signature. Advertise a list which gives all
5847 // versions a signing cipher.
5848 signingCiphers := []uint16{
Steven Valdez803c77a2016-09-06 14:13:43 -04005849 TLS_AES_128_GCM_SHA256,
David Benjamin5208fd42016-07-13 21:43:25 -04005850 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
5851 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
5852 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
5853 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
5854 TLS_DHE_RSA_WITH_AES_128_CBC_SHA,
5855 }
5856
David Benjaminca3d5452016-07-14 12:51:01 -04005857 var allAlgorithms []signatureAlgorithm
5858 for _, alg := range testSignatureAlgorithms {
5859 if alg.id != 0 {
5860 allAlgorithms = append(allAlgorithms, alg.id)
5861 }
5862 }
5863
Nick Harper60edffd2016-06-21 15:19:24 -07005864 // Make sure each signature algorithm works. Include some fake values in
5865 // the list and ensure they're ignored.
5866 for _, alg := range testSignatureAlgorithms {
David Benjamin1fb125c2016-07-08 18:52:12 -07005867 for _, ver := range tlsVersions {
David Benjamin5208fd42016-07-13 21:43:25 -04005868 if (ver.version < VersionTLS12) != (alg.id == 0) {
5869 continue
5870 }
5871
5872 // TODO(davidben): Support ECDSA in SSL 3.0 in Go for testing
5873 // or remove it in C.
5874 if ver.version == VersionSSL30 && alg.cert != testCertRSA {
David Benjamin1fb125c2016-07-08 18:52:12 -07005875 continue
5876 }
Nick Harper60edffd2016-06-21 15:19:24 -07005877
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005878 var shouldFail bool
David Benjamin1fb125c2016-07-08 18:52:12 -07005879 // ecdsa_sha1 does not exist in TLS 1.3.
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005880 if ver.version >= VersionTLS13 && alg.id == signatureECDSAWithSHA1 {
5881 shouldFail = true
5882 }
Steven Valdez54ed58e2016-08-18 14:03:49 -04005883 // RSA-PKCS1 does not exist in TLS 1.3.
5884 if ver.version == VersionTLS13 && hasComponent(alg.name, "PKCS1") {
5885 shouldFail = true
5886 }
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005887
5888 var signError, verifyError string
5889 if shouldFail {
5890 signError = ":NO_COMMON_SIGNATURE_ALGORITHMS:"
5891 verifyError = ":WRONG_SIGNATURE_TYPE:"
David Benjamin1fb125c2016-07-08 18:52:12 -07005892 }
David Benjamin000800a2014-11-14 01:43:59 -05005893
David Benjamin1fb125c2016-07-08 18:52:12 -07005894 suffix := "-" + alg.name + "-" + ver.name
David Benjamin6e807652015-11-02 12:02:20 -05005895
David Benjamin7a41d372016-07-09 11:21:54 -07005896 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005897 name: "ClientAuth-Sign" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005898 config: Config{
5899 MaxVersion: ver.version,
5900 ClientAuth: RequireAnyClientCert,
5901 VerifySignatureAlgorithms: []signatureAlgorithm{
5902 fakeSigAlg1,
5903 alg.id,
5904 fakeSigAlg2,
David Benjamin1fb125c2016-07-08 18:52:12 -07005905 },
David Benjamin7a41d372016-07-09 11:21:54 -07005906 },
5907 flags: []string{
5908 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5909 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5910 "-enable-all-curves",
5911 },
5912 shouldFail: shouldFail,
5913 expectedError: signError,
5914 expectedPeerSignatureAlgorithm: alg.id,
5915 })
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005916
David Benjamin7a41d372016-07-09 11:21:54 -07005917 testCases = append(testCases, testCase{
5918 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005919 name: "ClientAuth-Verify" + suffix,
David Benjamin7a41d372016-07-09 11:21:54 -07005920 config: Config{
5921 MaxVersion: ver.version,
5922 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5923 SignSignatureAlgorithms: []signatureAlgorithm{
5924 alg.id,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005925 },
David Benjamin7a41d372016-07-09 11:21:54 -07005926 Bugs: ProtocolBugs{
5927 SkipECDSACurveCheck: shouldFail,
5928 IgnoreSignatureVersionChecks: shouldFail,
5929 // The client won't advertise 1.3-only algorithms after
5930 // version negotiation.
5931 IgnorePeerSignatureAlgorithmPreferences: shouldFail,
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005932 },
David Benjamin7a41d372016-07-09 11:21:54 -07005933 },
5934 flags: []string{
5935 "-require-any-client-certificate",
5936 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5937 "-enable-all-curves",
5938 },
5939 shouldFail: shouldFail,
5940 expectedError: verifyError,
5941 })
David Benjamin1fb125c2016-07-08 18:52:12 -07005942
5943 testCases = append(testCases, testCase{
5944 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04005945 name: "ServerAuth-Sign" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005946 config: Config{
David Benjamin5208fd42016-07-13 21:43:25 -04005947 MaxVersion: ver.version,
5948 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005949 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005950 fakeSigAlg1,
5951 alg.id,
5952 fakeSigAlg2,
5953 },
5954 },
5955 flags: []string{
5956 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
5957 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
5958 "-enable-all-curves",
5959 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005960 shouldFail: shouldFail,
5961 expectedError: signError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005962 expectedPeerSignatureAlgorithm: alg.id,
5963 })
5964
5965 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04005966 name: "ServerAuth-Verify" + suffix,
David Benjamin1fb125c2016-07-08 18:52:12 -07005967 config: Config{
5968 MaxVersion: ver.version,
5969 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
David Benjamin5208fd42016-07-13 21:43:25 -04005970 CipherSuites: signingCiphers,
David Benjamin7a41d372016-07-09 11:21:54 -07005971 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07005972 alg.id,
5973 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005974 Bugs: ProtocolBugs{
5975 SkipECDSACurveCheck: shouldFail,
5976 IgnoreSignatureVersionChecks: shouldFail,
5977 },
David Benjamin1fb125c2016-07-08 18:52:12 -07005978 },
5979 flags: []string{
5980 "-expect-peer-signature-algorithm", strconv.Itoa(int(alg.id)),
5981 "-enable-all-curves",
5982 },
Steven Valdezeff1e8d2016-07-06 14:24:47 -04005983 shouldFail: shouldFail,
5984 expectedError: verifyError,
David Benjamin1fb125c2016-07-08 18:52:12 -07005985 })
David Benjamin5208fd42016-07-13 21:43:25 -04005986
5987 if !shouldFail {
5988 testCases = append(testCases, testCase{
5989 testType: serverTest,
5990 name: "ClientAuth-InvalidSignature" + suffix,
5991 config: Config{
5992 MaxVersion: ver.version,
5993 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
5994 SignSignatureAlgorithms: []signatureAlgorithm{
5995 alg.id,
5996 },
5997 Bugs: ProtocolBugs{
5998 InvalidSignature: true,
5999 },
6000 },
6001 flags: []string{
6002 "-require-any-client-certificate",
6003 "-enable-all-curves",
6004 },
6005 shouldFail: true,
6006 expectedError: ":BAD_SIGNATURE:",
6007 })
6008
6009 testCases = append(testCases, testCase{
6010 name: "ServerAuth-InvalidSignature" + suffix,
6011 config: Config{
6012 MaxVersion: ver.version,
6013 Certificates: []Certificate{getRunnerCertificate(alg.cert)},
6014 CipherSuites: signingCiphers,
6015 SignSignatureAlgorithms: []signatureAlgorithm{
6016 alg.id,
6017 },
6018 Bugs: ProtocolBugs{
6019 InvalidSignature: true,
6020 },
6021 },
6022 flags: []string{"-enable-all-curves"},
6023 shouldFail: true,
6024 expectedError: ":BAD_SIGNATURE:",
6025 })
6026 }
David Benjaminca3d5452016-07-14 12:51:01 -04006027
6028 if ver.version >= VersionTLS12 && !shouldFail {
6029 testCases = append(testCases, testCase{
6030 name: "ClientAuth-Sign-Negotiate" + suffix,
6031 config: Config{
6032 MaxVersion: ver.version,
6033 ClientAuth: RequireAnyClientCert,
6034 VerifySignatureAlgorithms: allAlgorithms,
6035 },
6036 flags: []string{
6037 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6038 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6039 "-enable-all-curves",
6040 "-signing-prefs", strconv.Itoa(int(alg.id)),
6041 },
6042 expectedPeerSignatureAlgorithm: alg.id,
6043 })
6044
6045 testCases = append(testCases, testCase{
6046 testType: serverTest,
6047 name: "ServerAuth-Sign-Negotiate" + suffix,
6048 config: Config{
6049 MaxVersion: ver.version,
6050 CipherSuites: signingCiphers,
6051 VerifySignatureAlgorithms: allAlgorithms,
6052 },
6053 flags: []string{
6054 "-cert-file", path.Join(*resourceDir, getShimCertificate(alg.cert)),
6055 "-key-file", path.Join(*resourceDir, getShimKey(alg.cert)),
6056 "-enable-all-curves",
6057 "-signing-prefs", strconv.Itoa(int(alg.id)),
6058 },
6059 expectedPeerSignatureAlgorithm: alg.id,
6060 })
6061 }
David Benjamin1fb125c2016-07-08 18:52:12 -07006062 }
David Benjamin000800a2014-11-14 01:43:59 -05006063 }
6064
Nick Harper60edffd2016-06-21 15:19:24 -07006065 // Test that algorithm selection takes the key type into account.
David Benjamin000800a2014-11-14 01:43:59 -05006066 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006067 name: "ClientAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006068 config: Config{
6069 ClientAuth: RequireAnyClientCert,
David Benjamin4c3ddf72016-06-29 18:13:53 -04006070 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006071 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006072 signatureECDSAWithP521AndSHA512,
6073 signatureRSAPKCS1WithSHA384,
6074 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006075 },
6076 },
6077 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006078 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6079 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006080 },
Nick Harper60edffd2016-06-21 15:19:24 -07006081 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006082 })
6083
6084 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006085 name: "ClientAuth-SignatureType-TLS13",
6086 config: Config{
6087 ClientAuth: RequireAnyClientCert,
6088 MaxVersion: VersionTLS13,
6089 VerifySignatureAlgorithms: []signatureAlgorithm{
6090 signatureECDSAWithP521AndSHA512,
6091 signatureRSAPKCS1WithSHA384,
6092 signatureRSAPSSWithSHA384,
6093 signatureECDSAWithSHA1,
6094 },
6095 },
6096 flags: []string{
6097 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6098 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6099 },
6100 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6101 })
6102
6103 testCases = append(testCases, testCase{
David Benjamin000800a2014-11-14 01:43:59 -05006104 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006105 name: "ServerAuth-SignatureType",
David Benjamin000800a2014-11-14 01:43:59 -05006106 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006107 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006108 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006109 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006110 signatureECDSAWithP521AndSHA512,
6111 signatureRSAPKCS1WithSHA384,
6112 signatureECDSAWithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006113 },
6114 },
Nick Harper60edffd2016-06-21 15:19:24 -07006115 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA384,
David Benjamin000800a2014-11-14 01:43:59 -05006116 })
6117
Steven Valdez143e8b32016-07-11 13:19:03 -04006118 testCases = append(testCases, testCase{
6119 testType: serverTest,
6120 name: "ServerAuth-SignatureType-TLS13",
6121 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006122 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006123 VerifySignatureAlgorithms: []signatureAlgorithm{
6124 signatureECDSAWithP521AndSHA512,
6125 signatureRSAPKCS1WithSHA384,
6126 signatureRSAPSSWithSHA384,
6127 signatureECDSAWithSHA1,
6128 },
6129 },
6130 expectedPeerSignatureAlgorithm: signatureRSAPSSWithSHA384,
6131 })
6132
David Benjamina95e9f32016-07-08 16:28:04 -07006133 // Test that signature verification takes the key type into account.
David Benjamina95e9f32016-07-08 16:28:04 -07006134 testCases = append(testCases, testCase{
6135 testType: serverTest,
6136 name: "Verify-ClientAuth-SignatureType",
6137 config: Config{
6138 MaxVersion: VersionTLS12,
6139 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006140 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006141 signatureRSAPKCS1WithSHA256,
6142 },
6143 Bugs: ProtocolBugs{
6144 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6145 },
6146 },
6147 flags: []string{
6148 "-require-any-client-certificate",
6149 },
6150 shouldFail: true,
6151 expectedError: ":WRONG_SIGNATURE_TYPE:",
6152 })
6153
6154 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04006155 testType: serverTest,
6156 name: "Verify-ClientAuth-SignatureType-TLS13",
6157 config: Config{
6158 MaxVersion: VersionTLS13,
6159 Certificates: []Certificate{rsaCertificate},
6160 SignSignatureAlgorithms: []signatureAlgorithm{
6161 signatureRSAPSSWithSHA256,
6162 },
6163 Bugs: ProtocolBugs{
6164 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6165 },
6166 },
6167 flags: []string{
6168 "-require-any-client-certificate",
6169 },
6170 shouldFail: true,
6171 expectedError: ":WRONG_SIGNATURE_TYPE:",
6172 })
6173
6174 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006175 name: "Verify-ServerAuth-SignatureType",
David Benjamina95e9f32016-07-08 16:28:04 -07006176 config: Config{
6177 MaxVersion: VersionTLS12,
6178 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006179 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamina95e9f32016-07-08 16:28:04 -07006180 signatureRSAPKCS1WithSHA256,
6181 },
6182 Bugs: ProtocolBugs{
6183 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6184 },
6185 },
6186 shouldFail: true,
6187 expectedError: ":WRONG_SIGNATURE_TYPE:",
6188 })
6189
Steven Valdez143e8b32016-07-11 13:19:03 -04006190 testCases = append(testCases, testCase{
6191 name: "Verify-ServerAuth-SignatureType-TLS13",
6192 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006193 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04006194 SignSignatureAlgorithms: []signatureAlgorithm{
6195 signatureRSAPSSWithSHA256,
6196 },
6197 Bugs: ProtocolBugs{
6198 SendSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6199 },
6200 },
6201 shouldFail: true,
6202 expectedError: ":WRONG_SIGNATURE_TYPE:",
6203 })
6204
David Benjamin51dd7d62016-07-08 16:07:01 -07006205 // Test that, if the list is missing, the peer falls back to SHA-1 in
6206 // TLS 1.2, but not TLS 1.3.
David Benjamin000800a2014-11-14 01:43:59 -05006207 testCases = append(testCases, testCase{
David Benjaminee32bea2016-08-17 13:36:44 -04006208 name: "ClientAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006209 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006210 MaxVersion: VersionTLS12,
David Benjamin000800a2014-11-14 01:43:59 -05006211 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006212 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006213 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006214 },
6215 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006216 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006217 },
6218 },
6219 flags: []string{
Adam Langley7c803a62015-06-15 15:35:05 -07006220 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6221 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjamin000800a2014-11-14 01:43:59 -05006222 },
6223 })
6224
6225 testCases = append(testCases, testCase{
6226 testType: serverTest,
David Benjaminee32bea2016-08-17 13:36:44 -04006227 name: "ServerAuth-SHA1-Fallback-RSA",
David Benjamin000800a2014-11-14 01:43:59 -05006228 config: Config{
David Benjaminee32bea2016-08-17 13:36:44 -04006229 MaxVersion: VersionTLS12,
David Benjamin7a41d372016-07-09 11:21:54 -07006230 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006231 signatureRSAPKCS1WithSHA1,
David Benjamin000800a2014-11-14 01:43:59 -05006232 },
6233 Bugs: ProtocolBugs{
Nick Harper60edffd2016-06-21 15:19:24 -07006234 NoSignatureAlgorithms: true,
David Benjamin000800a2014-11-14 01:43:59 -05006235 },
6236 },
David Benjaminee32bea2016-08-17 13:36:44 -04006237 flags: []string{
6238 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6239 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6240 },
6241 })
6242
6243 testCases = append(testCases, testCase{
6244 name: "ClientAuth-SHA1-Fallback-ECDSA",
6245 config: Config{
6246 MaxVersion: VersionTLS12,
6247 ClientAuth: RequireAnyClientCert,
6248 VerifySignatureAlgorithms: []signatureAlgorithm{
6249 signatureECDSAWithSHA1,
6250 },
6251 Bugs: ProtocolBugs{
6252 NoSignatureAlgorithms: true,
6253 },
6254 },
6255 flags: []string{
6256 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6257 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6258 },
6259 })
6260
6261 testCases = append(testCases, testCase{
6262 testType: serverTest,
6263 name: "ServerAuth-SHA1-Fallback-ECDSA",
6264 config: Config{
6265 MaxVersion: VersionTLS12,
6266 VerifySignatureAlgorithms: []signatureAlgorithm{
6267 signatureECDSAWithSHA1,
6268 },
6269 Bugs: ProtocolBugs{
6270 NoSignatureAlgorithms: true,
6271 },
6272 },
6273 flags: []string{
6274 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6275 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6276 },
David Benjamin000800a2014-11-14 01:43:59 -05006277 })
David Benjamin72dc7832015-03-16 17:49:43 -04006278
David Benjamin51dd7d62016-07-08 16:07:01 -07006279 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006280 name: "ClientAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006281 config: Config{
6282 MaxVersion: VersionTLS13,
6283 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006284 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006285 signatureRSAPKCS1WithSHA1,
6286 },
6287 Bugs: ProtocolBugs{
6288 NoSignatureAlgorithms: true,
6289 },
6290 },
6291 flags: []string{
6292 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6293 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6294 },
David Benjamin48901652016-08-01 12:12:47 -04006295 shouldFail: true,
6296 // An empty CertificateRequest signature algorithm list is a
6297 // syntax error in TLS 1.3.
6298 expectedError: ":DECODE_ERROR:",
6299 expectedLocalError: "remote error: error decoding message",
David Benjamin51dd7d62016-07-08 16:07:01 -07006300 })
6301
6302 testCases = append(testCases, testCase{
6303 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006304 name: "ServerAuth-NoFallback-TLS13",
David Benjamin51dd7d62016-07-08 16:07:01 -07006305 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006306 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006307 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin51dd7d62016-07-08 16:07:01 -07006308 signatureRSAPKCS1WithSHA1,
6309 },
6310 Bugs: ProtocolBugs{
6311 NoSignatureAlgorithms: true,
6312 },
6313 },
6314 shouldFail: true,
6315 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6316 })
6317
David Benjaminb62d2872016-07-18 14:55:02 +02006318 // Test that hash preferences are enforced. BoringSSL does not implement
6319 // MD5 signatures.
David Benjamin72dc7832015-03-16 17:49:43 -04006320 testCases = append(testCases, testCase{
6321 testType: serverTest,
David Benjaminbbfff7c2016-07-13 21:08:33 -04006322 name: "ClientAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006323 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006324 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006325 Certificates: []Certificate{rsaCertificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006326 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006327 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006328 },
6329 Bugs: ProtocolBugs{
6330 IgnorePeerSignatureAlgorithmPreferences: true,
6331 },
6332 },
6333 flags: []string{"-require-any-client-certificate"},
6334 shouldFail: true,
6335 expectedError: ":WRONG_SIGNATURE_TYPE:",
6336 })
6337
6338 testCases = append(testCases, testCase{
David Benjaminbbfff7c2016-07-13 21:08:33 -04006339 name: "ServerAuth-Enforced",
David Benjamin72dc7832015-03-16 17:49:43 -04006340 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006341 MaxVersion: VersionTLS12,
David Benjamin72dc7832015-03-16 17:49:43 -04006342 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin7a41d372016-07-09 11:21:54 -07006343 SignSignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006344 signatureRSAPKCS1WithMD5,
David Benjamin72dc7832015-03-16 17:49:43 -04006345 },
6346 Bugs: ProtocolBugs{
6347 IgnorePeerSignatureAlgorithmPreferences: true,
6348 },
6349 },
6350 shouldFail: true,
6351 expectedError: ":WRONG_SIGNATURE_TYPE:",
6352 })
David Benjaminb62d2872016-07-18 14:55:02 +02006353 testCases = append(testCases, testCase{
6354 testType: serverTest,
6355 name: "ClientAuth-Enforced-TLS13",
6356 config: Config{
6357 MaxVersion: VersionTLS13,
6358 Certificates: []Certificate{rsaCertificate},
6359 SignSignatureAlgorithms: []signatureAlgorithm{
6360 signatureRSAPKCS1WithMD5,
6361 },
6362 Bugs: ProtocolBugs{
6363 IgnorePeerSignatureAlgorithmPreferences: true,
6364 IgnoreSignatureVersionChecks: true,
6365 },
6366 },
6367 flags: []string{"-require-any-client-certificate"},
6368 shouldFail: true,
6369 expectedError: ":WRONG_SIGNATURE_TYPE:",
6370 })
6371
6372 testCases = append(testCases, testCase{
6373 name: "ServerAuth-Enforced-TLS13",
6374 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006375 MaxVersion: VersionTLS13,
David Benjaminb62d2872016-07-18 14:55:02 +02006376 SignSignatureAlgorithms: []signatureAlgorithm{
6377 signatureRSAPKCS1WithMD5,
6378 },
6379 Bugs: ProtocolBugs{
6380 IgnorePeerSignatureAlgorithmPreferences: true,
6381 IgnoreSignatureVersionChecks: true,
6382 },
6383 },
6384 shouldFail: true,
6385 expectedError: ":WRONG_SIGNATURE_TYPE:",
6386 })
Steven Valdez0d62f262015-09-04 12:41:04 -04006387
6388 // Test that the agreed upon digest respects the client preferences and
6389 // the server digests.
6390 testCases = append(testCases, testCase{
David Benjaminca3d5452016-07-14 12:51:01 -04006391 name: "NoCommonAlgorithms-Digests",
6392 config: Config{
6393 MaxVersion: VersionTLS12,
6394 ClientAuth: RequireAnyClientCert,
6395 VerifySignatureAlgorithms: []signatureAlgorithm{
6396 signatureRSAPKCS1WithSHA512,
6397 signatureRSAPKCS1WithSHA1,
6398 },
6399 },
6400 flags: []string{
6401 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6402 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6403 "-digest-prefs", "SHA256",
6404 },
6405 shouldFail: true,
6406 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6407 })
6408 testCases = append(testCases, testCase{
David Benjaminea9a0d52016-07-08 15:52:59 -07006409 name: "NoCommonAlgorithms",
Steven Valdez0d62f262015-09-04 12:41:04 -04006410 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006411 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006412 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006413 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006414 signatureRSAPKCS1WithSHA512,
6415 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006416 },
6417 },
6418 flags: []string{
6419 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6420 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006421 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
Steven Valdez0d62f262015-09-04 12:41:04 -04006422 },
David Benjaminca3d5452016-07-14 12:51:01 -04006423 shouldFail: true,
6424 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6425 })
6426 testCases = append(testCases, testCase{
6427 name: "NoCommonAlgorithms-TLS13",
6428 config: Config{
6429 MaxVersion: VersionTLS13,
6430 ClientAuth: RequireAnyClientCert,
6431 VerifySignatureAlgorithms: []signatureAlgorithm{
6432 signatureRSAPSSWithSHA512,
6433 signatureRSAPSSWithSHA384,
6434 },
6435 },
6436 flags: []string{
6437 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6438 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6439 "-signing-prefs", strconv.Itoa(int(signatureRSAPSSWithSHA256)),
6440 },
David Benjaminea9a0d52016-07-08 15:52:59 -07006441 shouldFail: true,
6442 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
Steven Valdez0d62f262015-09-04 12:41:04 -04006443 })
6444 testCases = append(testCases, testCase{
6445 name: "Agree-Digest-SHA256",
6446 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006447 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006448 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006449 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006450 signatureRSAPKCS1WithSHA1,
6451 signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006452 },
6453 },
6454 flags: []string{
6455 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6456 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006457 "-digest-prefs", "SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006458 },
Nick Harper60edffd2016-06-21 15:19:24 -07006459 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006460 })
6461 testCases = append(testCases, testCase{
6462 name: "Agree-Digest-SHA1",
6463 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006464 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006465 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006466 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006467 signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006468 },
6469 },
6470 flags: []string{
6471 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6472 "-key-file", path.Join(*resourceDir, rsaKeyFile),
David Benjaminca3d5452016-07-14 12:51:01 -04006473 "-digest-prefs", "SHA512,SHA256,SHA1",
Steven Valdez0d62f262015-09-04 12:41:04 -04006474 },
Nick Harper60edffd2016-06-21 15:19:24 -07006475 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006476 })
6477 testCases = append(testCases, testCase{
6478 name: "Agree-Digest-Default",
6479 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006480 MaxVersion: VersionTLS12,
Steven Valdez0d62f262015-09-04 12:41:04 -04006481 ClientAuth: RequireAnyClientCert,
David Benjamin7a41d372016-07-09 11:21:54 -07006482 VerifySignatureAlgorithms: []signatureAlgorithm{
Nick Harper60edffd2016-06-21 15:19:24 -07006483 signatureRSAPKCS1WithSHA256,
6484 signatureECDSAWithP256AndSHA256,
6485 signatureRSAPKCS1WithSHA1,
6486 signatureECDSAWithSHA1,
Steven Valdez0d62f262015-09-04 12:41:04 -04006487 },
6488 },
6489 flags: []string{
6490 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6491 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6492 },
Nick Harper60edffd2016-06-21 15:19:24 -07006493 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
Steven Valdez0d62f262015-09-04 12:41:04 -04006494 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04006495
David Benjaminca3d5452016-07-14 12:51:01 -04006496 // Test that the signing preference list may include extra algorithms
6497 // without negotiation problems.
6498 testCases = append(testCases, testCase{
6499 testType: serverTest,
6500 name: "FilterExtraAlgorithms",
6501 config: Config{
6502 MaxVersion: VersionTLS12,
6503 VerifySignatureAlgorithms: []signatureAlgorithm{
6504 signatureRSAPKCS1WithSHA256,
6505 },
6506 },
6507 flags: []string{
6508 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
6509 "-key-file", path.Join(*resourceDir, rsaKeyFile),
6510 "-signing-prefs", strconv.Itoa(int(fakeSigAlg1)),
6511 "-signing-prefs", strconv.Itoa(int(signatureECDSAWithP256AndSHA256)),
6512 "-signing-prefs", strconv.Itoa(int(signatureRSAPKCS1WithSHA256)),
6513 "-signing-prefs", strconv.Itoa(int(fakeSigAlg2)),
6514 },
6515 expectedPeerSignatureAlgorithm: signatureRSAPKCS1WithSHA256,
6516 })
6517
David Benjamin4c3ddf72016-06-29 18:13:53 -04006518 // In TLS 1.2 and below, ECDSA uses the curve list rather than the
6519 // signature algorithms.
David Benjamin4c3ddf72016-06-29 18:13:53 -04006520 testCases = append(testCases, testCase{
6521 name: "CheckLeafCurve",
6522 config: Config{
6523 MaxVersion: VersionTLS12,
6524 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
David Benjamin33863262016-07-08 17:20:12 -07006525 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin4c3ddf72016-06-29 18:13:53 -04006526 },
6527 flags: []string{"-p384-only"},
6528 shouldFail: true,
6529 expectedError: ":BAD_ECC_CERT:",
6530 })
David Benjamin75ea5bb2016-07-08 17:43:29 -07006531
6532 // In TLS 1.3, ECDSA does not use the ECDHE curve list.
6533 testCases = append(testCases, testCase{
6534 name: "CheckLeafCurve-TLS13",
6535 config: Config{
6536 MaxVersion: VersionTLS13,
David Benjamin75ea5bb2016-07-08 17:43:29 -07006537 Certificates: []Certificate{ecdsaP256Certificate},
6538 },
6539 flags: []string{"-p384-only"},
6540 })
David Benjamin1fb125c2016-07-08 18:52:12 -07006541
6542 // In TLS 1.2, the ECDSA curve is not in the signature algorithm.
6543 testCases = append(testCases, testCase{
6544 name: "ECDSACurveMismatch-Verify-TLS12",
6545 config: Config{
6546 MaxVersion: VersionTLS12,
6547 CipherSuites: []uint16{TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256},
6548 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006549 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006550 signatureECDSAWithP384AndSHA384,
6551 },
6552 },
6553 })
6554
6555 // In TLS 1.3, the ECDSA curve comes from the signature algorithm.
6556 testCases = append(testCases, testCase{
6557 name: "ECDSACurveMismatch-Verify-TLS13",
6558 config: Config{
6559 MaxVersion: VersionTLS13,
David Benjamin1fb125c2016-07-08 18:52:12 -07006560 Certificates: []Certificate{ecdsaP256Certificate},
David Benjamin7a41d372016-07-09 11:21:54 -07006561 SignSignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006562 signatureECDSAWithP384AndSHA384,
6563 },
6564 Bugs: ProtocolBugs{
6565 SkipECDSACurveCheck: true,
6566 },
6567 },
6568 shouldFail: true,
6569 expectedError: ":WRONG_SIGNATURE_TYPE:",
6570 })
6571
6572 // Signature algorithm selection in TLS 1.3 should take the curve into
6573 // account.
6574 testCases = append(testCases, testCase{
6575 testType: serverTest,
6576 name: "ECDSACurveMismatch-Sign-TLS13",
6577 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04006578 MaxVersion: VersionTLS13,
David Benjamin7a41d372016-07-09 11:21:54 -07006579 VerifySignatureAlgorithms: []signatureAlgorithm{
David Benjamin1fb125c2016-07-08 18:52:12 -07006580 signatureECDSAWithP384AndSHA384,
6581 signatureECDSAWithP256AndSHA256,
6582 },
6583 },
6584 flags: []string{
6585 "-cert-file", path.Join(*resourceDir, ecdsaP256CertificateFile),
6586 "-key-file", path.Join(*resourceDir, ecdsaP256KeyFile),
6587 },
6588 expectedPeerSignatureAlgorithm: signatureECDSAWithP256AndSHA256,
6589 })
David Benjamin7944a9f2016-07-12 22:27:01 -04006590
6591 // RSASSA-PSS with SHA-512 is too large for 1024-bit RSA. Test that the
6592 // server does not attempt to sign in that case.
6593 testCases = append(testCases, testCase{
6594 testType: serverTest,
6595 name: "RSA-PSS-Large",
6596 config: Config{
6597 MaxVersion: VersionTLS13,
6598 VerifySignatureAlgorithms: []signatureAlgorithm{
6599 signatureRSAPSSWithSHA512,
6600 },
6601 },
6602 flags: []string{
6603 "-cert-file", path.Join(*resourceDir, rsa1024CertificateFile),
6604 "-key-file", path.Join(*resourceDir, rsa1024KeyFile),
6605 },
6606 shouldFail: true,
6607 expectedError: ":NO_COMMON_SIGNATURE_ALGORITHMS:",
6608 })
David Benjamin57e929f2016-08-30 00:30:38 -04006609
6610 // Test that RSA-PSS is enabled by default for TLS 1.2.
6611 testCases = append(testCases, testCase{
6612 testType: clientTest,
6613 name: "RSA-PSS-Default-Verify",
6614 config: Config{
6615 MaxVersion: VersionTLS12,
6616 SignSignatureAlgorithms: []signatureAlgorithm{
6617 signatureRSAPSSWithSHA256,
6618 },
6619 },
6620 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6621 })
6622
6623 testCases = append(testCases, testCase{
6624 testType: serverTest,
6625 name: "RSA-PSS-Default-Sign",
6626 config: Config{
6627 MaxVersion: VersionTLS12,
6628 VerifySignatureAlgorithms: []signatureAlgorithm{
6629 signatureRSAPSSWithSHA256,
6630 },
6631 },
6632 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
6633 })
David Benjamin000800a2014-11-14 01:43:59 -05006634}
6635
David Benjamin83f90402015-01-27 01:09:43 -05006636// timeouts is the retransmit schedule for BoringSSL. It doubles and
6637// caps at 60 seconds. On the 13th timeout, it gives up.
6638var timeouts = []time.Duration{
6639 1 * time.Second,
6640 2 * time.Second,
6641 4 * time.Second,
6642 8 * time.Second,
6643 16 * time.Second,
6644 32 * time.Second,
6645 60 * time.Second,
6646 60 * time.Second,
6647 60 * time.Second,
6648 60 * time.Second,
6649 60 * time.Second,
6650 60 * time.Second,
6651 60 * time.Second,
6652}
6653
Taylor Brandstetter376a0fe2016-05-10 19:30:28 -07006654// shortTimeouts is an alternate set of timeouts which would occur if the
6655// initial timeout duration was set to 250ms.
6656var shortTimeouts = []time.Duration{
6657 250 * time.Millisecond,
6658 500 * time.Millisecond,
6659 1 * time.Second,
6660 2 * time.Second,
6661 4 * time.Second,
6662 8 * time.Second,
6663 16 * time.Second,
6664 32 * time.Second,
6665 60 * time.Second,
6666 60 * time.Second,
6667 60 * time.Second,
6668 60 * time.Second,
6669 60 * time.Second,
6670}
6671
David Benjamin83f90402015-01-27 01:09:43 -05006672func addDTLSRetransmitTests() {
David Benjamin585d7a42016-06-02 14:58:00 -04006673 // These tests work by coordinating some behavior on both the shim and
6674 // the runner.
6675 //
6676 // TimeoutSchedule configures the runner to send a series of timeout
6677 // opcodes to the shim (see packetAdaptor) immediately before reading
6678 // each peer handshake flight N. The timeout opcode both simulates a
6679 // timeout in the shim and acts as a synchronization point to help the
6680 // runner bracket each handshake flight.
6681 //
6682 // We assume the shim does not read from the channel eagerly. It must
6683 // first wait until it has sent flight N and is ready to receive
6684 // handshake flight N+1. At this point, it will process the timeout
6685 // opcode. It must then immediately respond with a timeout ACK and act
6686 // as if the shim was idle for the specified amount of time.
6687 //
6688 // The runner then drops all packets received before the ACK and
6689 // continues waiting for flight N. This ordering results in one attempt
6690 // at sending flight N to be dropped. For the test to complete, the
6691 // shim must send flight N again, testing that the shim implements DTLS
6692 // retransmit on a timeout.
6693
Steven Valdez143e8b32016-07-11 13:19:03 -04006694 // TODO(davidben): Add DTLS 1.3 versions of these tests. There will
David Benjamin4c3ddf72016-06-29 18:13:53 -04006695 // likely be more epochs to cross and the final message's retransmit may
6696 // be more complex.
6697
David Benjamin585d7a42016-06-02 14:58:00 -04006698 for _, async := range []bool{true, false} {
6699 var tests []testCase
6700
6701 // Test that this is indeed the timeout schedule. Stress all
6702 // four patterns of handshake.
6703 for i := 1; i < len(timeouts); i++ {
6704 number := strconv.Itoa(i)
6705 tests = append(tests, testCase{
6706 protocol: dtls,
6707 name: "DTLS-Retransmit-Client-" + number,
6708 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006709 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006710 Bugs: ProtocolBugs{
6711 TimeoutSchedule: timeouts[:i],
6712 },
6713 },
6714 resumeSession: true,
6715 })
6716 tests = append(tests, testCase{
6717 protocol: dtls,
6718 testType: serverTest,
6719 name: "DTLS-Retransmit-Server-" + number,
6720 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006721 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006722 Bugs: ProtocolBugs{
6723 TimeoutSchedule: timeouts[:i],
6724 },
6725 },
6726 resumeSession: true,
6727 })
6728 }
6729
6730 // Test that exceeding the timeout schedule hits a read
6731 // timeout.
6732 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006733 protocol: dtls,
David Benjamin585d7a42016-06-02 14:58:00 -04006734 name: "DTLS-Retransmit-Timeout",
David Benjamin83f90402015-01-27 01:09:43 -05006735 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006736 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006737 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006738 TimeoutSchedule: timeouts,
David Benjamin83f90402015-01-27 01:09:43 -05006739 },
6740 },
6741 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006742 shouldFail: true,
6743 expectedError: ":READ_TIMEOUT_EXPIRED:",
David Benjamin83f90402015-01-27 01:09:43 -05006744 })
David Benjamin585d7a42016-06-02 14:58:00 -04006745
6746 if async {
6747 // Test that timeout handling has a fudge factor, due to API
6748 // problems.
6749 tests = append(tests, testCase{
6750 protocol: dtls,
6751 name: "DTLS-Retransmit-Fudge",
6752 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006753 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006754 Bugs: ProtocolBugs{
6755 TimeoutSchedule: []time.Duration{
6756 timeouts[0] - 10*time.Millisecond,
6757 },
6758 },
6759 },
6760 resumeSession: true,
6761 })
6762 }
6763
6764 // Test that the final Finished retransmitting isn't
6765 // duplicated if the peer badly fragments everything.
6766 tests = append(tests, testCase{
6767 testType: serverTest,
6768 protocol: dtls,
6769 name: "DTLS-Retransmit-Fragmented",
6770 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006771 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006772 Bugs: ProtocolBugs{
6773 TimeoutSchedule: []time.Duration{timeouts[0]},
6774 MaxHandshakeRecordLength: 2,
6775 },
6776 },
6777 })
6778
6779 // Test the timeout schedule when a shorter initial timeout duration is set.
6780 tests = append(tests, testCase{
6781 protocol: dtls,
6782 name: "DTLS-Retransmit-Short-Client",
6783 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006784 MaxVersion: VersionTLS12,
David Benjamin585d7a42016-06-02 14:58:00 -04006785 Bugs: ProtocolBugs{
6786 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
6787 },
6788 },
6789 resumeSession: true,
6790 flags: []string{"-initial-timeout-duration-ms", "250"},
6791 })
6792 tests = append(tests, testCase{
David Benjamin83f90402015-01-27 01:09:43 -05006793 protocol: dtls,
6794 testType: serverTest,
David Benjamin585d7a42016-06-02 14:58:00 -04006795 name: "DTLS-Retransmit-Short-Server",
David Benjamin83f90402015-01-27 01:09:43 -05006796 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006797 MaxVersion: VersionTLS12,
David Benjamin83f90402015-01-27 01:09:43 -05006798 Bugs: ProtocolBugs{
David Benjamin585d7a42016-06-02 14:58:00 -04006799 TimeoutSchedule: shortTimeouts[:len(shortTimeouts)-1],
David Benjamin83f90402015-01-27 01:09:43 -05006800 },
6801 },
6802 resumeSession: true,
David Benjamin585d7a42016-06-02 14:58:00 -04006803 flags: []string{"-initial-timeout-duration-ms", "250"},
David Benjamin83f90402015-01-27 01:09:43 -05006804 })
David Benjamin585d7a42016-06-02 14:58:00 -04006805
6806 for _, test := range tests {
6807 if async {
6808 test.name += "-Async"
6809 test.flags = append(test.flags, "-async")
6810 }
6811
6812 testCases = append(testCases, test)
6813 }
David Benjamin83f90402015-01-27 01:09:43 -05006814 }
David Benjamin83f90402015-01-27 01:09:43 -05006815}
6816
David Benjaminc565ebb2015-04-03 04:06:36 -04006817func addExportKeyingMaterialTests() {
6818 for _, vers := range tlsVersions {
6819 if vers.version == VersionSSL30 {
6820 continue
6821 }
6822 testCases = append(testCases, testCase{
6823 name: "ExportKeyingMaterial-" + vers.name,
6824 config: Config{
6825 MaxVersion: vers.version,
6826 },
6827 exportKeyingMaterial: 1024,
6828 exportLabel: "label",
6829 exportContext: "context",
6830 useExportContext: true,
6831 })
6832 testCases = append(testCases, testCase{
6833 name: "ExportKeyingMaterial-NoContext-" + vers.name,
6834 config: Config{
6835 MaxVersion: vers.version,
6836 },
6837 exportKeyingMaterial: 1024,
6838 })
6839 testCases = append(testCases, testCase{
6840 name: "ExportKeyingMaterial-EmptyContext-" + vers.name,
6841 config: Config{
6842 MaxVersion: vers.version,
6843 },
6844 exportKeyingMaterial: 1024,
6845 useExportContext: true,
6846 })
6847 testCases = append(testCases, testCase{
6848 name: "ExportKeyingMaterial-Small-" + vers.name,
6849 config: Config{
6850 MaxVersion: vers.version,
6851 },
6852 exportKeyingMaterial: 1,
6853 exportLabel: "label",
6854 exportContext: "context",
6855 useExportContext: true,
6856 })
6857 }
6858 testCases = append(testCases, testCase{
6859 name: "ExportKeyingMaterial-SSL3",
6860 config: Config{
6861 MaxVersion: VersionSSL30,
6862 },
6863 exportKeyingMaterial: 1024,
6864 exportLabel: "label",
6865 exportContext: "context",
6866 useExportContext: true,
6867 shouldFail: true,
6868 expectedError: "failed to export keying material",
6869 })
6870}
6871
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006872func addTLSUniqueTests() {
6873 for _, isClient := range []bool{false, true} {
6874 for _, isResumption := range []bool{false, true} {
6875 for _, hasEMS := range []bool{false, true} {
6876 var suffix string
6877 if isResumption {
6878 suffix = "Resume-"
6879 } else {
6880 suffix = "Full-"
6881 }
6882
6883 if hasEMS {
6884 suffix += "EMS-"
6885 } else {
6886 suffix += "NoEMS-"
6887 }
6888
6889 if isClient {
6890 suffix += "Client"
6891 } else {
6892 suffix += "Server"
6893 }
6894
6895 test := testCase{
6896 name: "TLSUnique-" + suffix,
6897 testTLSUnique: true,
6898 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006899 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006900 Bugs: ProtocolBugs{
6901 NoExtendedMasterSecret: !hasEMS,
6902 },
6903 },
6904 }
6905
6906 if isResumption {
6907 test.resumeSession = true
6908 test.resumeConfig = &Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006909 MaxVersion: VersionTLS12,
Adam Langleyaf0e32c2015-06-03 09:57:23 -07006910 Bugs: ProtocolBugs{
6911 NoExtendedMasterSecret: !hasEMS,
6912 },
6913 }
6914 }
6915
6916 if isResumption && !hasEMS {
6917 test.shouldFail = true
6918 test.expectedError = "failed to get tls-unique"
6919 }
6920
6921 testCases = append(testCases, test)
6922 }
6923 }
6924 }
6925}
6926
Adam Langley09505632015-07-30 18:10:13 -07006927func addCustomExtensionTests() {
6928 expectedContents := "custom extension"
6929 emptyString := ""
6930
6931 for _, isClient := range []bool{false, true} {
6932 suffix := "Server"
6933 flag := "-enable-server-custom-extension"
6934 testType := serverTest
6935 if isClient {
6936 suffix = "Client"
6937 flag = "-enable-client-custom-extension"
6938 testType = clientTest
6939 }
6940
6941 testCases = append(testCases, testCase{
6942 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006943 name: "CustomExtensions-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006944 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006945 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006946 Bugs: ProtocolBugs{
6947 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07006948 ExpectedCustomExtension: &expectedContents,
6949 },
6950 },
6951 flags: []string{flag},
6952 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006953 testCases = append(testCases, testCase{
6954 testType: testType,
6955 name: "CustomExtensions-" + suffix + "-TLS13",
6956 config: Config{
6957 MaxVersion: VersionTLS13,
6958 Bugs: ProtocolBugs{
6959 CustomExtension: expectedContents,
6960 ExpectedCustomExtension: &expectedContents,
6961 },
6962 },
6963 flags: []string{flag},
6964 })
Adam Langley09505632015-07-30 18:10:13 -07006965
6966 // If the parse callback fails, the handshake should also fail.
6967 testCases = append(testCases, testCase{
6968 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006969 name: "CustomExtensions-ParseError-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07006970 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04006971 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04006972 Bugs: ProtocolBugs{
6973 CustomExtension: expectedContents + "foo",
Adam Langley09505632015-07-30 18:10:13 -07006974 ExpectedCustomExtension: &expectedContents,
6975 },
6976 },
David Benjamin399e7c92015-07-30 23:01:27 -04006977 flags: []string{flag},
6978 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07006979 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6980 })
Steven Valdez143e8b32016-07-11 13:19:03 -04006981 testCases = append(testCases, testCase{
6982 testType: testType,
6983 name: "CustomExtensions-ParseError-" + suffix + "-TLS13",
6984 config: Config{
6985 MaxVersion: VersionTLS13,
6986 Bugs: ProtocolBugs{
6987 CustomExtension: expectedContents + "foo",
6988 ExpectedCustomExtension: &expectedContents,
6989 },
6990 },
6991 flags: []string{flag},
6992 shouldFail: true,
6993 expectedError: ":CUSTOM_EXTENSION_ERROR:",
6994 })
Adam Langley09505632015-07-30 18:10:13 -07006995
6996 // If the add callback fails, the handshake should also fail.
6997 testCases = append(testCases, testCase{
6998 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04006999 name: "CustomExtensions-FailAdd-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007000 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007001 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007002 Bugs: ProtocolBugs{
7003 CustomExtension: expectedContents,
Adam Langley09505632015-07-30 18:10:13 -07007004 ExpectedCustomExtension: &expectedContents,
7005 },
7006 },
David Benjamin399e7c92015-07-30 23:01:27 -04007007 flags: []string{flag, "-custom-extension-fail-add"},
7008 shouldFail: true,
Adam Langley09505632015-07-30 18:10:13 -07007009 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7010 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007011 testCases = append(testCases, testCase{
7012 testType: testType,
7013 name: "CustomExtensions-FailAdd-" + suffix + "-TLS13",
7014 config: Config{
7015 MaxVersion: VersionTLS13,
7016 Bugs: ProtocolBugs{
7017 CustomExtension: expectedContents,
7018 ExpectedCustomExtension: &expectedContents,
7019 },
7020 },
7021 flags: []string{flag, "-custom-extension-fail-add"},
7022 shouldFail: true,
7023 expectedError: ":CUSTOM_EXTENSION_ERROR:",
7024 })
Adam Langley09505632015-07-30 18:10:13 -07007025
7026 // If the add callback returns zero, no extension should be
7027 // added.
7028 skipCustomExtension := expectedContents
7029 if isClient {
7030 // For the case where the client skips sending the
7031 // custom extension, the server must not “echo” it.
7032 skipCustomExtension = ""
7033 }
7034 testCases = append(testCases, testCase{
7035 testType: testType,
David Benjamin399e7c92015-07-30 23:01:27 -04007036 name: "CustomExtensions-Skip-" + suffix,
Adam Langley09505632015-07-30 18:10:13 -07007037 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007038 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007039 Bugs: ProtocolBugs{
7040 CustomExtension: skipCustomExtension,
Adam Langley09505632015-07-30 18:10:13 -07007041 ExpectedCustomExtension: &emptyString,
7042 },
7043 },
7044 flags: []string{flag, "-custom-extension-skip"},
7045 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007046 testCases = append(testCases, testCase{
7047 testType: testType,
7048 name: "CustomExtensions-Skip-" + suffix + "-TLS13",
7049 config: Config{
7050 MaxVersion: VersionTLS13,
7051 Bugs: ProtocolBugs{
7052 CustomExtension: skipCustomExtension,
7053 ExpectedCustomExtension: &emptyString,
7054 },
7055 },
7056 flags: []string{flag, "-custom-extension-skip"},
7057 })
Adam Langley09505632015-07-30 18:10:13 -07007058 }
7059
7060 // The custom extension add callback should not be called if the client
7061 // doesn't send the extension.
7062 testCases = append(testCases, testCase{
7063 testType: serverTest,
David Benjamin399e7c92015-07-30 23:01:27 -04007064 name: "CustomExtensions-NotCalled-Server",
Adam Langley09505632015-07-30 18:10:13 -07007065 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007066 MaxVersion: VersionTLS12,
David Benjamin399e7c92015-07-30 23:01:27 -04007067 Bugs: ProtocolBugs{
Adam Langley09505632015-07-30 18:10:13 -07007068 ExpectedCustomExtension: &emptyString,
7069 },
7070 },
7071 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7072 })
Adam Langley2deb9842015-08-07 11:15:37 -07007073
Steven Valdez143e8b32016-07-11 13:19:03 -04007074 testCases = append(testCases, testCase{
7075 testType: serverTest,
7076 name: "CustomExtensions-NotCalled-Server-TLS13",
7077 config: Config{
7078 MaxVersion: VersionTLS13,
7079 Bugs: ProtocolBugs{
7080 ExpectedCustomExtension: &emptyString,
7081 },
7082 },
7083 flags: []string{"-enable-server-custom-extension", "-custom-extension-fail-add"},
7084 })
7085
Adam Langley2deb9842015-08-07 11:15:37 -07007086 // Test an unknown extension from the server.
7087 testCases = append(testCases, testCase{
7088 testType: clientTest,
7089 name: "UnknownExtension-Client",
7090 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007091 MaxVersion: VersionTLS12,
Adam Langley2deb9842015-08-07 11:15:37 -07007092 Bugs: ProtocolBugs{
7093 CustomExtension: expectedContents,
7094 },
7095 },
David Benjamin0c40a962016-08-01 12:05:50 -04007096 shouldFail: true,
7097 expectedError: ":UNEXPECTED_EXTENSION:",
7098 expectedLocalError: "remote error: unsupported extension",
Adam Langley2deb9842015-08-07 11:15:37 -07007099 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007100 testCases = append(testCases, testCase{
7101 testType: clientTest,
7102 name: "UnknownExtension-Client-TLS13",
7103 config: Config{
7104 MaxVersion: VersionTLS13,
7105 Bugs: ProtocolBugs{
7106 CustomExtension: expectedContents,
7107 },
7108 },
David Benjamin0c40a962016-08-01 12:05:50 -04007109 shouldFail: true,
7110 expectedError: ":UNEXPECTED_EXTENSION:",
7111 expectedLocalError: "remote error: unsupported extension",
7112 })
David Benjamin490469f2016-10-05 22:44:38 -04007113 testCases = append(testCases, testCase{
7114 testType: clientTest,
7115 name: "UnknownUnencryptedExtension-Client-TLS13",
7116 config: Config{
7117 MaxVersion: VersionTLS13,
7118 Bugs: ProtocolBugs{
7119 CustomUnencryptedExtension: expectedContents,
7120 },
7121 },
7122 shouldFail: true,
7123 expectedError: ":UNEXPECTED_EXTENSION:",
7124 // The shim must send an alert, but alerts at this point do not
7125 // get successfully decrypted by the runner.
7126 expectedLocalError: "local error: bad record MAC",
7127 })
7128 testCases = append(testCases, testCase{
7129 testType: clientTest,
7130 name: "UnexpectedUnencryptedExtension-Client-TLS13",
7131 config: Config{
7132 MaxVersion: VersionTLS13,
7133 Bugs: ProtocolBugs{
7134 SendUnencryptedALPN: "foo",
7135 },
7136 },
7137 flags: []string{
7138 "-advertise-alpn", "\x03foo\x03bar",
7139 },
7140 shouldFail: true,
7141 expectedError: ":UNEXPECTED_EXTENSION:",
7142 // The shim must send an alert, but alerts at this point do not
7143 // get successfully decrypted by the runner.
7144 expectedLocalError: "local error: bad record MAC",
7145 })
David Benjamin0c40a962016-08-01 12:05:50 -04007146
7147 // Test a known but unoffered extension from the server.
7148 testCases = append(testCases, testCase{
7149 testType: clientTest,
7150 name: "UnofferedExtension-Client",
7151 config: Config{
7152 MaxVersion: VersionTLS12,
7153 Bugs: ProtocolBugs{
7154 SendALPN: "alpn",
7155 },
7156 },
7157 shouldFail: true,
7158 expectedError: ":UNEXPECTED_EXTENSION:",
7159 expectedLocalError: "remote error: unsupported extension",
7160 })
7161 testCases = append(testCases, testCase{
7162 testType: clientTest,
7163 name: "UnofferedExtension-Client-TLS13",
7164 config: Config{
7165 MaxVersion: VersionTLS13,
7166 Bugs: ProtocolBugs{
7167 SendALPN: "alpn",
7168 },
7169 },
7170 shouldFail: true,
7171 expectedError: ":UNEXPECTED_EXTENSION:",
7172 expectedLocalError: "remote error: unsupported extension",
Steven Valdez143e8b32016-07-11 13:19:03 -04007173 })
Adam Langley09505632015-07-30 18:10:13 -07007174}
7175
David Benjaminb36a3952015-12-01 18:53:13 -05007176func addRSAClientKeyExchangeTests() {
7177 for bad := RSABadValue(1); bad < NumRSABadValues; bad++ {
7178 testCases = append(testCases, testCase{
7179 testType: serverTest,
7180 name: fmt.Sprintf("BadRSAClientKeyExchange-%d", bad),
7181 config: Config{
7182 // Ensure the ClientHello version and final
7183 // version are different, to detect if the
7184 // server uses the wrong one.
7185 MaxVersion: VersionTLS11,
Matt Braithwaite07e78062016-08-21 14:50:43 -07007186 CipherSuites: []uint16{TLS_RSA_WITH_3DES_EDE_CBC_SHA},
David Benjaminb36a3952015-12-01 18:53:13 -05007187 Bugs: ProtocolBugs{
7188 BadRSAClientKeyExchange: bad,
7189 },
7190 },
7191 shouldFail: true,
7192 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7193 })
7194 }
David Benjamine63d9d72016-09-19 18:27:34 -04007195
7196 // The server must compare whatever was in ClientHello.version for the
7197 // RSA premaster.
7198 testCases = append(testCases, testCase{
7199 testType: serverTest,
7200 name: "SendClientVersion-RSA",
7201 config: Config{
7202 CipherSuites: []uint16{TLS_RSA_WITH_AES_128_GCM_SHA256},
7203 Bugs: ProtocolBugs{
7204 SendClientVersion: 0x1234,
7205 },
7206 },
7207 flags: []string{"-max-version", strconv.Itoa(VersionTLS12)},
7208 })
David Benjaminb36a3952015-12-01 18:53:13 -05007209}
7210
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007211var testCurves = []struct {
7212 name string
7213 id CurveID
7214}{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007215 {"P-256", CurveP256},
7216 {"P-384", CurveP384},
7217 {"P-521", CurveP521},
David Benjamin4298d772015-12-19 00:18:25 -05007218 {"X25519", CurveX25519},
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007219}
7220
Steven Valdez5440fe02016-07-18 12:40:30 -04007221const bogusCurve = 0x1234
7222
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007223func addCurveTests() {
7224 for _, curve := range testCurves {
7225 testCases = append(testCases, testCase{
7226 name: "CurveTest-Client-" + curve.name,
7227 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007228 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007229 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7230 CurvePreferences: []CurveID{curve.id},
7231 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007232 flags: []string{
7233 "-enable-all-curves",
7234 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7235 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007236 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007237 })
7238 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007239 name: "CurveTest-Client-" + curve.name + "-TLS13",
7240 config: Config{
7241 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007242 CurvePreferences: []CurveID{curve.id},
7243 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007244 flags: []string{
7245 "-enable-all-curves",
7246 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7247 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007248 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007249 })
7250 testCases = append(testCases, testCase{
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007251 testType: serverTest,
7252 name: "CurveTest-Server-" + curve.name,
7253 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007254 MaxVersion: VersionTLS12,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007255 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7256 CurvePreferences: []CurveID{curve.id},
7257 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007258 flags: []string{
7259 "-enable-all-curves",
7260 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7261 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007262 expectedCurveID: curve.id,
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007263 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007264 testCases = append(testCases, testCase{
7265 testType: serverTest,
7266 name: "CurveTest-Server-" + curve.name + "-TLS13",
7267 config: Config{
7268 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007269 CurvePreferences: []CurveID{curve.id},
7270 },
David Benjamin5c4e8572016-08-19 17:44:53 -04007271 flags: []string{
7272 "-enable-all-curves",
7273 "-expect-curve-id", strconv.Itoa(int(curve.id)),
7274 },
Steven Valdez5440fe02016-07-18 12:40:30 -04007275 expectedCurveID: curve.id,
Steven Valdez143e8b32016-07-11 13:19:03 -04007276 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007277 }
David Benjamin241ae832016-01-15 03:04:54 -05007278
7279 // The server must be tolerant to bogus curves.
David Benjamin241ae832016-01-15 03:04:54 -05007280 testCases = append(testCases, testCase{
7281 testType: serverTest,
7282 name: "UnknownCurve",
7283 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007284 MaxVersion: VersionTLS12,
David Benjamin241ae832016-01-15 03:04:54 -05007285 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7286 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7287 },
7288 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007289
Steven Valdez803c77a2016-09-06 14:13:43 -04007290 // The server must be tolerant to bogus curves.
7291 testCases = append(testCases, testCase{
7292 testType: serverTest,
7293 name: "UnknownCurve-TLS13",
7294 config: Config{
7295 MaxVersion: VersionTLS13,
7296 CurvePreferences: []CurveID{bogusCurve, CurveP256},
7297 },
7298 })
7299
David Benjamin4c3ddf72016-06-29 18:13:53 -04007300 // The server must not consider ECDHE ciphers when there are no
7301 // supported curves.
7302 testCases = append(testCases, testCase{
7303 testType: serverTest,
7304 name: "NoSupportedCurves",
7305 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007306 MaxVersion: VersionTLS12,
7307 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7308 Bugs: ProtocolBugs{
7309 NoSupportedCurves: true,
7310 },
7311 },
7312 shouldFail: true,
7313 expectedError: ":NO_SHARED_CIPHER:",
7314 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007315 testCases = append(testCases, testCase{
7316 testType: serverTest,
7317 name: "NoSupportedCurves-TLS13",
7318 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007319 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007320 Bugs: ProtocolBugs{
7321 NoSupportedCurves: true,
7322 },
7323 },
7324 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04007325 expectedError: ":NO_SHARED_GROUP:",
Steven Valdez143e8b32016-07-11 13:19:03 -04007326 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007327
7328 // The server must fall back to another cipher when there are no
7329 // supported curves.
7330 testCases = append(testCases, testCase{
7331 testType: serverTest,
7332 name: "NoCommonCurves",
7333 config: Config{
7334 MaxVersion: VersionTLS12,
7335 CipherSuites: []uint16{
7336 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
7337 TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7338 },
7339 CurvePreferences: []CurveID{CurveP224},
7340 },
7341 expectedCipher: TLS_DHE_RSA_WITH_AES_128_GCM_SHA256,
7342 })
7343
7344 // The client must reject bogus curves and disabled curves.
7345 testCases = append(testCases, testCase{
7346 name: "BadECDHECurve",
7347 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007348 MaxVersion: VersionTLS12,
7349 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7350 Bugs: ProtocolBugs{
7351 SendCurve: bogusCurve,
7352 },
7353 },
7354 shouldFail: true,
7355 expectedError: ":WRONG_CURVE:",
7356 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007357 testCases = append(testCases, testCase{
7358 name: "BadECDHECurve-TLS13",
7359 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007360 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007361 Bugs: ProtocolBugs{
7362 SendCurve: bogusCurve,
7363 },
7364 },
7365 shouldFail: true,
7366 expectedError: ":WRONG_CURVE:",
7367 })
David Benjamin4c3ddf72016-06-29 18:13:53 -04007368
7369 testCases = append(testCases, testCase{
7370 name: "UnsupportedCurve",
7371 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007372 MaxVersion: VersionTLS12,
7373 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7374 CurvePreferences: []CurveID{CurveP256},
7375 Bugs: ProtocolBugs{
7376 IgnorePeerCurvePreferences: true,
7377 },
7378 },
7379 flags: []string{"-p384-only"},
7380 shouldFail: true,
7381 expectedError: ":WRONG_CURVE:",
7382 })
7383
David Benjamin4f921572016-07-17 14:20:10 +02007384 testCases = append(testCases, testCase{
7385 // TODO(davidben): Add a TLS 1.3 version where
7386 // HelloRetryRequest requests an unsupported curve.
7387 name: "UnsupportedCurve-ServerHello-TLS13",
7388 config: Config{
Steven Valdez803c77a2016-09-06 14:13:43 -04007389 MaxVersion: VersionTLS13,
David Benjamin4f921572016-07-17 14:20:10 +02007390 CurvePreferences: []CurveID{CurveP384},
7391 Bugs: ProtocolBugs{
7392 SendCurve: CurveP256,
7393 },
7394 },
7395 flags: []string{"-p384-only"},
7396 shouldFail: true,
7397 expectedError: ":WRONG_CURVE:",
7398 })
7399
David Benjamin4c3ddf72016-06-29 18:13:53 -04007400 // Test invalid curve points.
7401 testCases = append(testCases, testCase{
7402 name: "InvalidECDHPoint-Client",
7403 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007404 MaxVersion: VersionTLS12,
7405 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7406 CurvePreferences: []CurveID{CurveP256},
7407 Bugs: ProtocolBugs{
7408 InvalidECDHPoint: true,
7409 },
7410 },
7411 shouldFail: true,
7412 expectedError: ":INVALID_ENCODING:",
7413 })
7414 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04007415 name: "InvalidECDHPoint-Client-TLS13",
7416 config: Config{
7417 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007418 CurvePreferences: []CurveID{CurveP256},
7419 Bugs: ProtocolBugs{
7420 InvalidECDHPoint: true,
7421 },
7422 },
7423 shouldFail: true,
7424 expectedError: ":INVALID_ENCODING:",
7425 })
7426 testCases = append(testCases, testCase{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007427 testType: serverTest,
7428 name: "InvalidECDHPoint-Server",
7429 config: Config{
David Benjamin4c3ddf72016-06-29 18:13:53 -04007430 MaxVersion: VersionTLS12,
7431 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
7432 CurvePreferences: []CurveID{CurveP256},
7433 Bugs: ProtocolBugs{
7434 InvalidECDHPoint: true,
7435 },
7436 },
7437 shouldFail: true,
7438 expectedError: ":INVALID_ENCODING:",
7439 })
Steven Valdez143e8b32016-07-11 13:19:03 -04007440 testCases = append(testCases, testCase{
7441 testType: serverTest,
7442 name: "InvalidECDHPoint-Server-TLS13",
7443 config: Config{
7444 MaxVersion: VersionTLS13,
Steven Valdez143e8b32016-07-11 13:19:03 -04007445 CurvePreferences: []CurveID{CurveP256},
7446 Bugs: ProtocolBugs{
7447 InvalidECDHPoint: true,
7448 },
7449 },
7450 shouldFail: true,
7451 expectedError: ":INVALID_ENCODING:",
7452 })
David Benjamin8c2b3bf2015-12-18 20:55:44 -05007453}
7454
Matt Braithwaite54217e42016-06-13 13:03:47 -07007455func addCECPQ1Tests() {
7456 testCases = append(testCases, testCase{
7457 testType: clientTest,
7458 name: "CECPQ1-Client-BadX25519Part",
7459 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007460 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007461 MinVersion: VersionTLS12,
7462 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7463 Bugs: ProtocolBugs{
7464 CECPQ1BadX25519Part: true,
7465 },
7466 },
7467 flags: []string{"-cipher", "kCECPQ1"},
7468 shouldFail: true,
7469 expectedLocalError: "local error: bad record MAC",
7470 })
7471 testCases = append(testCases, testCase{
7472 testType: clientTest,
7473 name: "CECPQ1-Client-BadNewhopePart",
7474 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007475 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007476 MinVersion: VersionTLS12,
7477 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7478 Bugs: ProtocolBugs{
7479 CECPQ1BadNewhopePart: true,
7480 },
7481 },
7482 flags: []string{"-cipher", "kCECPQ1"},
7483 shouldFail: true,
7484 expectedLocalError: "local error: bad record MAC",
7485 })
7486 testCases = append(testCases, testCase{
7487 testType: serverTest,
7488 name: "CECPQ1-Server-BadX25519Part",
7489 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007490 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007491 MinVersion: VersionTLS12,
7492 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7493 Bugs: ProtocolBugs{
7494 CECPQ1BadX25519Part: true,
7495 },
7496 },
7497 flags: []string{"-cipher", "kCECPQ1"},
7498 shouldFail: true,
7499 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7500 })
7501 testCases = append(testCases, testCase{
7502 testType: serverTest,
7503 name: "CECPQ1-Server-BadNewhopePart",
7504 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007505 MaxVersion: VersionTLS12,
Matt Braithwaite54217e42016-06-13 13:03:47 -07007506 MinVersion: VersionTLS12,
7507 CipherSuites: []uint16{TLS_CECPQ1_RSA_WITH_AES_256_GCM_SHA384},
7508 Bugs: ProtocolBugs{
7509 CECPQ1BadNewhopePart: true,
7510 },
7511 },
7512 flags: []string{"-cipher", "kCECPQ1"},
7513 shouldFail: true,
7514 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7515 })
7516}
7517
David Benjamin5c4e8572016-08-19 17:44:53 -04007518func addDHEGroupSizeTests() {
David Benjamin4cc36ad2015-12-19 14:23:26 -05007519 testCases = append(testCases, testCase{
David Benjamin5c4e8572016-08-19 17:44:53 -04007520 name: "DHEGroupSize-Client",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007521 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007522 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007523 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7524 Bugs: ProtocolBugs{
7525 // This is a 1234-bit prime number, generated
7526 // with:
7527 // openssl gendh 1234 | openssl asn1parse -i
7528 DHGroupPrime: bigFromHex("0215C589A86BE450D1255A86D7A08877A70E124C11F0C75E476BA6A2186B1C830D4A132555973F2D5881D5F737BB800B7F417C01EC5960AEBF79478F8E0BBB6A021269BD10590C64C57F50AD8169D5488B56EE38DC5E02DA1A16ED3B5F41FEB2AD184B78A31F3A5B2BEC8441928343DA35DE3D4F89F0D4CEDE0034045084A0D1E6182E5EF7FCA325DD33CE81BE7FA87D43613E8FA7A1457099AB53"),
7529 },
7530 },
David Benjamin9e68f192016-06-30 14:55:33 -04007531 flags: []string{"-expect-dhe-group-size", "1234"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007532 })
7533 testCases = append(testCases, testCase{
7534 testType: serverTest,
David Benjamin5c4e8572016-08-19 17:44:53 -04007535 name: "DHEGroupSize-Server",
David Benjamin4cc36ad2015-12-19 14:23:26 -05007536 config: Config{
Nick Harper1fd39d82016-06-14 18:14:35 -07007537 MaxVersion: VersionTLS12,
David Benjamin4cc36ad2015-12-19 14:23:26 -05007538 CipherSuites: []uint16{TLS_DHE_RSA_WITH_AES_128_GCM_SHA256},
7539 },
7540 // bssl_shim as a server configures a 2048-bit DHE group.
David Benjamin9e68f192016-06-30 14:55:33 -04007541 flags: []string{"-expect-dhe-group-size", "2048"},
David Benjamin4cc36ad2015-12-19 14:23:26 -05007542 })
David Benjamin4cc36ad2015-12-19 14:23:26 -05007543}
7544
David Benjaminc9ae27c2016-06-24 22:56:37 -04007545func addTLS13RecordTests() {
7546 testCases = append(testCases, testCase{
7547 name: "TLS13-RecordPadding",
7548 config: Config{
7549 MaxVersion: VersionTLS13,
7550 MinVersion: VersionTLS13,
7551 Bugs: ProtocolBugs{
7552 RecordPadding: 10,
7553 },
7554 },
7555 })
7556
7557 testCases = append(testCases, testCase{
7558 name: "TLS13-EmptyRecords",
7559 config: Config{
7560 MaxVersion: VersionTLS13,
7561 MinVersion: VersionTLS13,
7562 Bugs: ProtocolBugs{
7563 OmitRecordContents: true,
7564 },
7565 },
7566 shouldFail: true,
7567 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7568 })
7569
7570 testCases = append(testCases, testCase{
7571 name: "TLS13-OnlyPadding",
7572 config: Config{
7573 MaxVersion: VersionTLS13,
7574 MinVersion: VersionTLS13,
7575 Bugs: ProtocolBugs{
7576 OmitRecordContents: true,
7577 RecordPadding: 10,
7578 },
7579 },
7580 shouldFail: true,
7581 expectedError: ":DECRYPTION_FAILED_OR_BAD_RECORD_MAC:",
7582 })
7583
7584 testCases = append(testCases, testCase{
7585 name: "TLS13-WrongOuterRecord",
7586 config: Config{
7587 MaxVersion: VersionTLS13,
7588 MinVersion: VersionTLS13,
7589 Bugs: ProtocolBugs{
7590 OuterRecordType: recordTypeHandshake,
7591 },
7592 },
7593 shouldFail: true,
7594 expectedError: ":INVALID_OUTER_RECORD_TYPE:",
7595 })
7596}
7597
Steven Valdez5b986082016-09-01 12:29:49 -04007598func addSessionTicketTests() {
7599 testCases = append(testCases, testCase{
7600 // In TLS 1.2 and below, empty NewSessionTicket messages
7601 // mean the server changed its mind on sending a ticket.
7602 name: "SendEmptySessionTicket",
7603 config: Config{
7604 MaxVersion: VersionTLS12,
7605 Bugs: ProtocolBugs{
7606 SendEmptySessionTicket: true,
7607 },
7608 },
7609 flags: []string{"-expect-no-session"},
7610 })
7611
7612 // Test that the server ignores unknown PSK modes.
7613 testCases = append(testCases, testCase{
7614 testType: serverTest,
7615 name: "TLS13-SendUnknownModeSessionTicket-Server",
7616 config: Config{
7617 MaxVersion: VersionTLS13,
7618 Bugs: ProtocolBugs{
7619 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7620 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7621 },
7622 },
7623 resumeSession: true,
7624 expectedResumeVersion: VersionTLS13,
7625 })
7626
7627 // Test that the server declines sessions with no matching key exchange mode.
7628 testCases = append(testCases, testCase{
7629 testType: serverTest,
7630 name: "TLS13-SendBadKEModeSessionTicket-Server",
7631 config: Config{
7632 MaxVersion: VersionTLS13,
7633 Bugs: ProtocolBugs{
7634 SendPSKKeyExchangeModes: []byte{0x1a},
7635 },
7636 },
7637 resumeSession: true,
7638 expectResumeRejected: true,
7639 })
7640
7641 // Test that the server declines sessions with no matching auth mode.
7642 testCases = append(testCases, testCase{
7643 testType: serverTest,
7644 name: "TLS13-SendBadAuthModeSessionTicket-Server",
7645 config: Config{
7646 MaxVersion: VersionTLS13,
7647 Bugs: ProtocolBugs{
7648 SendPSKAuthModes: []byte{0x1a},
7649 },
7650 },
7651 resumeSession: true,
7652 expectResumeRejected: true,
7653 })
7654
7655 // Test that the client ignores unknown PSK modes.
7656 testCases = append(testCases, testCase{
7657 testType: clientTest,
7658 name: "TLS13-SendUnknownModeSessionTicket-Client",
7659 config: Config{
7660 MaxVersion: VersionTLS13,
7661 Bugs: ProtocolBugs{
7662 SendPSKKeyExchangeModes: []byte{0x1a, pskDHEKEMode, 0x2a},
7663 SendPSKAuthModes: []byte{0x1a, pskAuthMode, 0x2a},
7664 },
7665 },
7666 resumeSession: true,
7667 expectedResumeVersion: VersionTLS13,
7668 })
7669
7670 // Test that the client ignores tickets with no matching key exchange mode.
7671 testCases = append(testCases, testCase{
7672 testType: clientTest,
7673 name: "TLS13-SendBadKEModeSessionTicket-Client",
7674 config: Config{
7675 MaxVersion: VersionTLS13,
7676 Bugs: ProtocolBugs{
7677 SendPSKKeyExchangeModes: []byte{0x1a},
7678 },
7679 },
7680 flags: []string{"-expect-no-session"},
7681 })
7682
7683 // Test that the client ignores tickets with no matching auth mode.
7684 testCases = append(testCases, testCase{
7685 testType: clientTest,
7686 name: "TLS13-SendBadAuthModeSessionTicket-Client",
7687 config: Config{
7688 MaxVersion: VersionTLS13,
7689 Bugs: ProtocolBugs{
7690 SendPSKAuthModes: []byte{0x1a},
7691 },
7692 },
7693 flags: []string{"-expect-no-session"},
7694 })
7695}
7696
David Benjamin82261be2016-07-07 14:32:50 -07007697func addChangeCipherSpecTests() {
7698 // Test missing ChangeCipherSpecs.
7699 testCases = append(testCases, testCase{
7700 name: "SkipChangeCipherSpec-Client",
7701 config: Config{
7702 MaxVersion: VersionTLS12,
7703 Bugs: ProtocolBugs{
7704 SkipChangeCipherSpec: true,
7705 },
7706 },
7707 shouldFail: true,
7708 expectedError: ":UNEXPECTED_RECORD:",
7709 })
7710 testCases = append(testCases, testCase{
7711 testType: serverTest,
7712 name: "SkipChangeCipherSpec-Server",
7713 config: Config{
7714 MaxVersion: VersionTLS12,
7715 Bugs: ProtocolBugs{
7716 SkipChangeCipherSpec: true,
7717 },
7718 },
7719 shouldFail: true,
7720 expectedError: ":UNEXPECTED_RECORD:",
7721 })
7722 testCases = append(testCases, testCase{
7723 testType: serverTest,
7724 name: "SkipChangeCipherSpec-Server-NPN",
7725 config: Config{
7726 MaxVersion: VersionTLS12,
7727 NextProtos: []string{"bar"},
7728 Bugs: ProtocolBugs{
7729 SkipChangeCipherSpec: true,
7730 },
7731 },
7732 flags: []string{
7733 "-advertise-npn", "\x03foo\x03bar\x03baz",
7734 },
7735 shouldFail: true,
7736 expectedError: ":UNEXPECTED_RECORD:",
7737 })
7738
7739 // Test synchronization between the handshake and ChangeCipherSpec.
7740 // Partial post-CCS handshake messages before ChangeCipherSpec should be
7741 // rejected. Test both with and without handshake packing to handle both
7742 // when the partial post-CCS message is in its own record and when it is
7743 // attached to the pre-CCS message.
David Benjamin82261be2016-07-07 14:32:50 -07007744 for _, packed := range []bool{false, true} {
7745 var suffix string
7746 if packed {
7747 suffix = "-Packed"
7748 }
7749
7750 testCases = append(testCases, testCase{
7751 name: "FragmentAcrossChangeCipherSpec-Client" + suffix,
7752 config: Config{
7753 MaxVersion: VersionTLS12,
7754 Bugs: ProtocolBugs{
7755 FragmentAcrossChangeCipherSpec: true,
7756 PackHandshakeFlight: packed,
7757 },
7758 },
7759 shouldFail: true,
7760 expectedError: ":UNEXPECTED_RECORD:",
7761 })
7762 testCases = append(testCases, testCase{
7763 name: "FragmentAcrossChangeCipherSpec-Client-Resume" + suffix,
7764 config: Config{
7765 MaxVersion: VersionTLS12,
7766 },
7767 resumeSession: true,
7768 resumeConfig: &Config{
7769 MaxVersion: VersionTLS12,
7770 Bugs: ProtocolBugs{
7771 FragmentAcrossChangeCipherSpec: true,
7772 PackHandshakeFlight: packed,
7773 },
7774 },
7775 shouldFail: true,
7776 expectedError: ":UNEXPECTED_RECORD:",
7777 })
7778 testCases = append(testCases, testCase{
7779 testType: serverTest,
7780 name: "FragmentAcrossChangeCipherSpec-Server" + suffix,
7781 config: Config{
7782 MaxVersion: VersionTLS12,
7783 Bugs: ProtocolBugs{
7784 FragmentAcrossChangeCipherSpec: true,
7785 PackHandshakeFlight: packed,
7786 },
7787 },
7788 shouldFail: true,
7789 expectedError: ":UNEXPECTED_RECORD:",
7790 })
7791 testCases = append(testCases, testCase{
7792 testType: serverTest,
7793 name: "FragmentAcrossChangeCipherSpec-Server-Resume" + suffix,
7794 config: Config{
7795 MaxVersion: VersionTLS12,
7796 },
7797 resumeSession: true,
7798 resumeConfig: &Config{
7799 MaxVersion: VersionTLS12,
7800 Bugs: ProtocolBugs{
7801 FragmentAcrossChangeCipherSpec: true,
7802 PackHandshakeFlight: packed,
7803 },
7804 },
7805 shouldFail: true,
7806 expectedError: ":UNEXPECTED_RECORD:",
7807 })
7808 testCases = append(testCases, testCase{
7809 testType: serverTest,
7810 name: "FragmentAcrossChangeCipherSpec-Server-NPN" + suffix,
7811 config: Config{
7812 MaxVersion: VersionTLS12,
7813 NextProtos: []string{"bar"},
7814 Bugs: ProtocolBugs{
7815 FragmentAcrossChangeCipherSpec: true,
7816 PackHandshakeFlight: packed,
7817 },
7818 },
7819 flags: []string{
7820 "-advertise-npn", "\x03foo\x03bar\x03baz",
7821 },
7822 shouldFail: true,
7823 expectedError: ":UNEXPECTED_RECORD:",
7824 })
7825 }
7826
David Benjamin61672812016-07-14 23:10:43 -04007827 // Test that, in DTLS, ChangeCipherSpec is not allowed when there are
7828 // messages in the handshake queue. Do this by testing the server
7829 // reading the client Finished, reversing the flight so Finished comes
7830 // first.
7831 testCases = append(testCases, testCase{
7832 protocol: dtls,
7833 testType: serverTest,
7834 name: "SendUnencryptedFinished-DTLS",
7835 config: Config{
7836 MaxVersion: VersionTLS12,
7837 Bugs: ProtocolBugs{
7838 SendUnencryptedFinished: true,
7839 ReverseHandshakeFragments: true,
7840 },
7841 },
7842 shouldFail: true,
7843 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7844 })
7845
Steven Valdez143e8b32016-07-11 13:19:03 -04007846 // Test synchronization between encryption changes and the handshake in
7847 // TLS 1.3, where ChangeCipherSpec is implicit.
7848 testCases = append(testCases, testCase{
7849 name: "PartialEncryptedExtensionsWithServerHello",
7850 config: Config{
7851 MaxVersion: VersionTLS13,
7852 Bugs: ProtocolBugs{
7853 PartialEncryptedExtensionsWithServerHello: true,
7854 },
7855 },
7856 shouldFail: true,
7857 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7858 })
7859 testCases = append(testCases, testCase{
7860 testType: serverTest,
7861 name: "PartialClientFinishedWithClientHello",
7862 config: Config{
7863 MaxVersion: VersionTLS13,
7864 Bugs: ProtocolBugs{
7865 PartialClientFinishedWithClientHello: true,
7866 },
7867 },
7868 shouldFail: true,
7869 expectedError: ":BUFFERED_MESSAGES_ON_CIPHER_CHANGE:",
7870 })
7871
David Benjamin82261be2016-07-07 14:32:50 -07007872 // Test that early ChangeCipherSpecs are handled correctly.
7873 testCases = append(testCases, testCase{
7874 testType: serverTest,
7875 name: "EarlyChangeCipherSpec-server-1",
7876 config: Config{
7877 MaxVersion: VersionTLS12,
7878 Bugs: ProtocolBugs{
7879 EarlyChangeCipherSpec: 1,
7880 },
7881 },
7882 shouldFail: true,
7883 expectedError: ":UNEXPECTED_RECORD:",
7884 })
7885 testCases = append(testCases, testCase{
7886 testType: serverTest,
7887 name: "EarlyChangeCipherSpec-server-2",
7888 config: Config{
7889 MaxVersion: VersionTLS12,
7890 Bugs: ProtocolBugs{
7891 EarlyChangeCipherSpec: 2,
7892 },
7893 },
7894 shouldFail: true,
7895 expectedError: ":UNEXPECTED_RECORD:",
7896 })
7897 testCases = append(testCases, testCase{
7898 protocol: dtls,
7899 name: "StrayChangeCipherSpec",
7900 config: Config{
7901 // TODO(davidben): Once DTLS 1.3 exists, test
7902 // that stray ChangeCipherSpec messages are
7903 // rejected.
7904 MaxVersion: VersionTLS12,
7905 Bugs: ProtocolBugs{
7906 StrayChangeCipherSpec: true,
7907 },
7908 },
7909 })
7910
7911 // Test that the contents of ChangeCipherSpec are checked.
7912 testCases = append(testCases, testCase{
7913 name: "BadChangeCipherSpec-1",
7914 config: Config{
7915 MaxVersion: VersionTLS12,
7916 Bugs: ProtocolBugs{
7917 BadChangeCipherSpec: []byte{2},
7918 },
7919 },
7920 shouldFail: true,
7921 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7922 })
7923 testCases = append(testCases, testCase{
7924 name: "BadChangeCipherSpec-2",
7925 config: Config{
7926 MaxVersion: VersionTLS12,
7927 Bugs: ProtocolBugs{
7928 BadChangeCipherSpec: []byte{1, 1},
7929 },
7930 },
7931 shouldFail: true,
7932 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7933 })
7934 testCases = append(testCases, testCase{
7935 protocol: dtls,
7936 name: "BadChangeCipherSpec-DTLS-1",
7937 config: Config{
7938 MaxVersion: VersionTLS12,
7939 Bugs: ProtocolBugs{
7940 BadChangeCipherSpec: []byte{2},
7941 },
7942 },
7943 shouldFail: true,
7944 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7945 })
7946 testCases = append(testCases, testCase{
7947 protocol: dtls,
7948 name: "BadChangeCipherSpec-DTLS-2",
7949 config: Config{
7950 MaxVersion: VersionTLS12,
7951 Bugs: ProtocolBugs{
7952 BadChangeCipherSpec: []byte{1, 1},
7953 },
7954 },
7955 shouldFail: true,
7956 expectedError: ":BAD_CHANGE_CIPHER_SPEC:",
7957 })
7958}
7959
David Benjamincd2c8062016-09-09 11:28:16 -04007960type perMessageTest struct {
7961 messageType uint8
7962 test testCase
7963}
7964
7965// makePerMessageTests returns a series of test templates which cover each
7966// message in the TLS handshake. These may be used with bugs like
7967// WrongMessageType to fully test a per-message bug.
7968func makePerMessageTests() []perMessageTest {
7969 var ret []perMessageTest
David Benjamin0b8d5da2016-07-15 00:39:56 -04007970 for _, protocol := range []protocol{tls, dtls} {
7971 var suffix string
7972 if protocol == dtls {
7973 suffix = "-DTLS"
7974 }
7975
David Benjamincd2c8062016-09-09 11:28:16 -04007976 ret = append(ret, perMessageTest{
7977 messageType: typeClientHello,
7978 test: testCase{
7979 protocol: protocol,
7980 testType: serverTest,
7981 name: "ClientHello" + suffix,
7982 config: Config{
7983 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007984 },
7985 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007986 })
7987
7988 if protocol == dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04007989 ret = append(ret, perMessageTest{
7990 messageType: typeHelloVerifyRequest,
7991 test: testCase{
7992 protocol: protocol,
7993 name: "HelloVerifyRequest" + suffix,
7994 config: Config{
7995 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04007996 },
7997 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04007998 })
7999 }
8000
David Benjamincd2c8062016-09-09 11:28:16 -04008001 ret = append(ret, perMessageTest{
8002 messageType: typeServerHello,
8003 test: testCase{
8004 protocol: protocol,
8005 name: "ServerHello" + suffix,
8006 config: Config{
8007 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008008 },
8009 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008010 })
8011
David Benjamincd2c8062016-09-09 11:28:16 -04008012 ret = append(ret, perMessageTest{
8013 messageType: typeCertificate,
8014 test: testCase{
8015 protocol: protocol,
8016 name: "ServerCertificate" + suffix,
8017 config: Config{
8018 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008019 },
8020 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008021 })
8022
David Benjamincd2c8062016-09-09 11:28:16 -04008023 ret = append(ret, perMessageTest{
8024 messageType: typeCertificateStatus,
8025 test: testCase{
8026 protocol: protocol,
8027 name: "CertificateStatus" + suffix,
8028 config: Config{
8029 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008030 },
David Benjamincd2c8062016-09-09 11:28:16 -04008031 flags: []string{"-enable-ocsp-stapling"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008032 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008033 })
8034
David Benjamincd2c8062016-09-09 11:28:16 -04008035 ret = append(ret, perMessageTest{
8036 messageType: typeServerKeyExchange,
8037 test: testCase{
8038 protocol: protocol,
8039 name: "ServerKeyExchange" + suffix,
8040 config: Config{
8041 MaxVersion: VersionTLS12,
8042 CipherSuites: []uint16{TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008043 },
8044 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008045 })
8046
David Benjamincd2c8062016-09-09 11:28:16 -04008047 ret = append(ret, perMessageTest{
8048 messageType: typeCertificateRequest,
8049 test: testCase{
8050 protocol: protocol,
8051 name: "CertificateRequest" + suffix,
8052 config: Config{
8053 MaxVersion: VersionTLS12,
8054 ClientAuth: RequireAnyClientCert,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008055 },
8056 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008057 })
8058
David Benjamincd2c8062016-09-09 11:28:16 -04008059 ret = append(ret, perMessageTest{
8060 messageType: typeServerHelloDone,
8061 test: testCase{
8062 protocol: protocol,
8063 name: "ServerHelloDone" + suffix,
8064 config: Config{
8065 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008066 },
8067 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008068 })
8069
David Benjamincd2c8062016-09-09 11:28:16 -04008070 ret = append(ret, perMessageTest{
8071 messageType: typeCertificate,
8072 test: testCase{
8073 testType: serverTest,
8074 protocol: protocol,
8075 name: "ClientCertificate" + suffix,
8076 config: Config{
8077 Certificates: []Certificate{rsaCertificate},
8078 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008079 },
David Benjamincd2c8062016-09-09 11:28:16 -04008080 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008081 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008082 })
8083
David Benjamincd2c8062016-09-09 11:28:16 -04008084 ret = append(ret, perMessageTest{
8085 messageType: typeCertificateVerify,
8086 test: testCase{
8087 testType: serverTest,
8088 protocol: protocol,
8089 name: "CertificateVerify" + suffix,
8090 config: Config{
8091 Certificates: []Certificate{rsaCertificate},
8092 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008093 },
David Benjamincd2c8062016-09-09 11:28:16 -04008094 flags: []string{"-require-any-client-certificate"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008095 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008096 })
8097
David Benjamincd2c8062016-09-09 11:28:16 -04008098 ret = append(ret, perMessageTest{
8099 messageType: typeClientKeyExchange,
8100 test: testCase{
8101 testType: serverTest,
8102 protocol: protocol,
8103 name: "ClientKeyExchange" + suffix,
8104 config: Config{
8105 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008106 },
8107 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008108 })
8109
8110 if protocol != dtls {
David Benjamincd2c8062016-09-09 11:28:16 -04008111 ret = append(ret, perMessageTest{
8112 messageType: typeNextProtocol,
8113 test: testCase{
8114 testType: serverTest,
8115 protocol: protocol,
8116 name: "NextProtocol" + suffix,
8117 config: Config{
8118 MaxVersion: VersionTLS12,
8119 NextProtos: []string{"bar"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008120 },
David Benjamincd2c8062016-09-09 11:28:16 -04008121 flags: []string{"-advertise-npn", "\x03foo\x03bar\x03baz"},
David Benjamin0b8d5da2016-07-15 00:39:56 -04008122 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008123 })
8124
David Benjamincd2c8062016-09-09 11:28:16 -04008125 ret = append(ret, perMessageTest{
8126 messageType: typeChannelID,
8127 test: testCase{
8128 testType: serverTest,
8129 protocol: protocol,
8130 name: "ChannelID" + suffix,
8131 config: Config{
8132 MaxVersion: VersionTLS12,
8133 ChannelID: channelIDKey,
8134 },
8135 flags: []string{
8136 "-expect-channel-id",
8137 base64.StdEncoding.EncodeToString(channelIDBytes),
David Benjamin0b8d5da2016-07-15 00:39:56 -04008138 },
8139 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008140 })
8141 }
8142
David Benjamincd2c8062016-09-09 11:28:16 -04008143 ret = append(ret, perMessageTest{
8144 messageType: typeFinished,
8145 test: testCase{
8146 testType: serverTest,
8147 protocol: protocol,
8148 name: "ClientFinished" + suffix,
8149 config: Config{
8150 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008151 },
8152 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008153 })
8154
David Benjamincd2c8062016-09-09 11:28:16 -04008155 ret = append(ret, perMessageTest{
8156 messageType: typeNewSessionTicket,
8157 test: testCase{
8158 protocol: protocol,
8159 name: "NewSessionTicket" + suffix,
8160 config: Config{
8161 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008162 },
8163 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008164 })
8165
David Benjamincd2c8062016-09-09 11:28:16 -04008166 ret = append(ret, perMessageTest{
8167 messageType: typeFinished,
8168 test: testCase{
8169 protocol: protocol,
8170 name: "ServerFinished" + suffix,
8171 config: Config{
8172 MaxVersion: VersionTLS12,
David Benjamin0b8d5da2016-07-15 00:39:56 -04008173 },
8174 },
David Benjamin0b8d5da2016-07-15 00:39:56 -04008175 })
8176
8177 }
David Benjamincd2c8062016-09-09 11:28:16 -04008178
8179 ret = append(ret, perMessageTest{
8180 messageType: typeClientHello,
8181 test: testCase{
8182 testType: serverTest,
8183 name: "TLS13-ClientHello",
8184 config: Config{
8185 MaxVersion: VersionTLS13,
8186 },
8187 },
8188 })
8189
8190 ret = append(ret, perMessageTest{
8191 messageType: typeServerHello,
8192 test: testCase{
8193 name: "TLS13-ServerHello",
8194 config: Config{
8195 MaxVersion: VersionTLS13,
8196 },
8197 },
8198 })
8199
8200 ret = append(ret, perMessageTest{
8201 messageType: typeEncryptedExtensions,
8202 test: testCase{
8203 name: "TLS13-EncryptedExtensions",
8204 config: Config{
8205 MaxVersion: VersionTLS13,
8206 },
8207 },
8208 })
8209
8210 ret = append(ret, perMessageTest{
8211 messageType: typeCertificateRequest,
8212 test: testCase{
8213 name: "TLS13-CertificateRequest",
8214 config: Config{
8215 MaxVersion: VersionTLS13,
8216 ClientAuth: RequireAnyClientCert,
8217 },
8218 },
8219 })
8220
8221 ret = append(ret, perMessageTest{
8222 messageType: typeCertificate,
8223 test: testCase{
8224 name: "TLS13-ServerCertificate",
8225 config: Config{
8226 MaxVersion: VersionTLS13,
8227 },
8228 },
8229 })
8230
8231 ret = append(ret, perMessageTest{
8232 messageType: typeCertificateVerify,
8233 test: testCase{
8234 name: "TLS13-ServerCertificateVerify",
8235 config: Config{
8236 MaxVersion: VersionTLS13,
8237 },
8238 },
8239 })
8240
8241 ret = append(ret, perMessageTest{
8242 messageType: typeFinished,
8243 test: testCase{
8244 name: "TLS13-ServerFinished",
8245 config: Config{
8246 MaxVersion: VersionTLS13,
8247 },
8248 },
8249 })
8250
8251 ret = append(ret, perMessageTest{
8252 messageType: typeCertificate,
8253 test: testCase{
8254 testType: serverTest,
8255 name: "TLS13-ClientCertificate",
8256 config: Config{
8257 Certificates: []Certificate{rsaCertificate},
8258 MaxVersion: VersionTLS13,
8259 },
8260 flags: []string{"-require-any-client-certificate"},
8261 },
8262 })
8263
8264 ret = append(ret, perMessageTest{
8265 messageType: typeCertificateVerify,
8266 test: testCase{
8267 testType: serverTest,
8268 name: "TLS13-ClientCertificateVerify",
8269 config: Config{
8270 Certificates: []Certificate{rsaCertificate},
8271 MaxVersion: VersionTLS13,
8272 },
8273 flags: []string{"-require-any-client-certificate"},
8274 },
8275 })
8276
8277 ret = append(ret, perMessageTest{
8278 messageType: typeFinished,
8279 test: testCase{
8280 testType: serverTest,
8281 name: "TLS13-ClientFinished",
8282 config: Config{
8283 MaxVersion: VersionTLS13,
8284 },
8285 },
8286 })
8287
8288 return ret
David Benjamin0b8d5da2016-07-15 00:39:56 -04008289}
8290
David Benjamincd2c8062016-09-09 11:28:16 -04008291func addWrongMessageTypeTests() {
8292 for _, t := range makePerMessageTests() {
8293 t.test.name = "WrongMessageType-" + t.test.name
8294 t.test.config.Bugs.SendWrongMessageType = t.messageType
8295 t.test.shouldFail = true
8296 t.test.expectedError = ":UNEXPECTED_MESSAGE:"
8297 t.test.expectedLocalError = "remote error: unexpected message"
Steven Valdez143e8b32016-07-11 13:19:03 -04008298
David Benjamincd2c8062016-09-09 11:28:16 -04008299 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8300 // In TLS 1.3, a bad ServerHello means the client sends
8301 // an unencrypted alert while the server expects
8302 // encryption, so the alert is not readable by runner.
8303 t.test.expectedLocalError = "local error: bad record MAC"
8304 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008305
David Benjamincd2c8062016-09-09 11:28:16 -04008306 testCases = append(testCases, t.test)
8307 }
Steven Valdez143e8b32016-07-11 13:19:03 -04008308}
8309
David Benjamin639846e2016-09-09 11:41:18 -04008310func addTrailingMessageDataTests() {
8311 for _, t := range makePerMessageTests() {
8312 t.test.name = "TrailingMessageData-" + t.test.name
8313 t.test.config.Bugs.SendTrailingMessageData = t.messageType
8314 t.test.shouldFail = true
8315 t.test.expectedError = ":DECODE_ERROR:"
8316 t.test.expectedLocalError = "remote error: error decoding message"
8317
8318 if t.test.config.MaxVersion >= VersionTLS13 && t.messageType == typeServerHello {
8319 // In TLS 1.3, a bad ServerHello means the client sends
8320 // an unencrypted alert while the server expects
8321 // encryption, so the alert is not readable by runner.
8322 t.test.expectedLocalError = "local error: bad record MAC"
8323 }
8324
8325 if t.messageType == typeFinished {
8326 // Bad Finished messages read as the verify data having
8327 // the wrong length.
8328 t.test.expectedError = ":DIGEST_CHECK_FAILED:"
8329 t.test.expectedLocalError = "remote error: error decrypting message"
8330 }
8331
8332 testCases = append(testCases, t.test)
8333 }
8334}
8335
Steven Valdez143e8b32016-07-11 13:19:03 -04008336func addTLS13HandshakeTests() {
8337 testCases = append(testCases, testCase{
8338 testType: clientTest,
Steven Valdez803c77a2016-09-06 14:13:43 -04008339 name: "NegotiatePSKResumption-TLS13",
8340 config: Config{
8341 MaxVersion: VersionTLS13,
8342 Bugs: ProtocolBugs{
8343 NegotiatePSKResumption: true,
8344 },
8345 },
8346 resumeSession: true,
8347 shouldFail: true,
8348 expectedError: ":UNEXPECTED_EXTENSION:",
8349 })
8350
8351 testCases = append(testCases, testCase{
8352 testType: clientTest,
8353 name: "OmitServerHelloSignatureAlgorithms",
8354 config: Config{
8355 MaxVersion: VersionTLS13,
8356 Bugs: ProtocolBugs{
8357 OmitServerHelloSignatureAlgorithms: true,
8358 },
8359 },
8360 shouldFail: true,
8361 expectedError: ":UNEXPECTED_EXTENSION:",
8362 })
8363
8364 testCases = append(testCases, testCase{
8365 testType: clientTest,
8366 name: "IncludeServerHelloSignatureAlgorithms",
8367 config: Config{
8368 MaxVersion: VersionTLS13,
8369 Bugs: ProtocolBugs{
8370 IncludeServerHelloSignatureAlgorithms: true,
8371 },
8372 },
8373 resumeSession: true,
8374 shouldFail: true,
8375 expectedError: ":UNEXPECTED_EXTENSION:",
8376 })
8377
8378 testCases = append(testCases, testCase{
8379 testType: clientTest,
Steven Valdez143e8b32016-07-11 13:19:03 -04008380 name: "MissingKeyShare-Client",
8381 config: Config{
8382 MaxVersion: VersionTLS13,
8383 Bugs: ProtocolBugs{
8384 MissingKeyShare: true,
8385 },
8386 },
8387 shouldFail: true,
Steven Valdez803c77a2016-09-06 14:13:43 -04008388 expectedError: ":UNEXPECTED_EXTENSION:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008389 })
8390
8391 testCases = append(testCases, testCase{
Steven Valdez5440fe02016-07-18 12:40:30 -04008392 testType: serverTest,
8393 name: "MissingKeyShare-Server",
Steven Valdez143e8b32016-07-11 13:19:03 -04008394 config: Config{
8395 MaxVersion: VersionTLS13,
8396 Bugs: ProtocolBugs{
8397 MissingKeyShare: true,
8398 },
8399 },
8400 shouldFail: true,
8401 expectedError: ":MISSING_KEY_SHARE:",
8402 })
8403
8404 testCases = append(testCases, testCase{
Steven Valdez143e8b32016-07-11 13:19:03 -04008405 testType: serverTest,
8406 name: "DuplicateKeyShares",
8407 config: Config{
8408 MaxVersion: VersionTLS13,
8409 Bugs: ProtocolBugs{
8410 DuplicateKeyShares: true,
8411 },
8412 },
David Benjamin7e1f9842016-09-20 19:24:40 -04008413 shouldFail: true,
8414 expectedError: ":DUPLICATE_KEY_SHARE:",
Steven Valdez143e8b32016-07-11 13:19:03 -04008415 })
8416
8417 testCases = append(testCases, testCase{
8418 testType: clientTest,
8419 name: "EmptyEncryptedExtensions",
8420 config: Config{
8421 MaxVersion: VersionTLS13,
8422 Bugs: ProtocolBugs{
8423 EmptyEncryptedExtensions: true,
8424 },
8425 },
8426 shouldFail: true,
8427 expectedLocalError: "remote error: error decoding message",
8428 })
8429
8430 testCases = append(testCases, testCase{
8431 testType: clientTest,
8432 name: "EncryptedExtensionsWithKeyShare",
8433 config: Config{
8434 MaxVersion: VersionTLS13,
8435 Bugs: ProtocolBugs{
8436 EncryptedExtensionsWithKeyShare: true,
8437 },
8438 },
8439 shouldFail: true,
8440 expectedLocalError: "remote error: unsupported extension",
8441 })
Steven Valdez5440fe02016-07-18 12:40:30 -04008442
8443 testCases = append(testCases, testCase{
8444 testType: serverTest,
8445 name: "SendHelloRetryRequest",
8446 config: Config{
8447 MaxVersion: VersionTLS13,
8448 // Require a HelloRetryRequest for every curve.
8449 DefaultCurves: []CurveID{},
8450 },
8451 expectedCurveID: CurveX25519,
8452 })
8453
8454 testCases = append(testCases, testCase{
8455 testType: serverTest,
8456 name: "SendHelloRetryRequest-2",
8457 config: Config{
8458 MaxVersion: VersionTLS13,
8459 DefaultCurves: []CurveID{CurveP384},
8460 },
8461 // Although the ClientHello did not predict our preferred curve,
8462 // we always select it whether it is predicted or not.
8463 expectedCurveID: CurveX25519,
8464 })
8465
8466 testCases = append(testCases, testCase{
8467 name: "UnknownCurve-HelloRetryRequest",
8468 config: Config{
8469 MaxVersion: VersionTLS13,
8470 // P-384 requires HelloRetryRequest in BoringSSL.
8471 CurvePreferences: []CurveID{CurveP384},
8472 Bugs: ProtocolBugs{
8473 SendHelloRetryRequestCurve: bogusCurve,
8474 },
8475 },
8476 shouldFail: true,
8477 expectedError: ":WRONG_CURVE:",
8478 })
8479
8480 testCases = append(testCases, testCase{
8481 name: "DisabledCurve-HelloRetryRequest",
8482 config: Config{
8483 MaxVersion: VersionTLS13,
8484 CurvePreferences: []CurveID{CurveP256},
8485 Bugs: ProtocolBugs{
8486 IgnorePeerCurvePreferences: true,
8487 },
8488 },
8489 flags: []string{"-p384-only"},
8490 shouldFail: true,
8491 expectedError: ":WRONG_CURVE:",
8492 })
8493
8494 testCases = append(testCases, testCase{
8495 name: "UnnecessaryHelloRetryRequest",
8496 config: Config{
8497 MaxVersion: VersionTLS13,
8498 Bugs: ProtocolBugs{
8499 UnnecessaryHelloRetryRequest: true,
8500 },
8501 },
8502 shouldFail: true,
8503 expectedError: ":WRONG_CURVE:",
8504 })
8505
8506 testCases = append(testCases, testCase{
8507 name: "SecondHelloRetryRequest",
8508 config: Config{
8509 MaxVersion: VersionTLS13,
8510 // P-384 requires HelloRetryRequest in BoringSSL.
8511 CurvePreferences: []CurveID{CurveP384},
8512 Bugs: ProtocolBugs{
8513 SecondHelloRetryRequest: true,
8514 },
8515 },
8516 shouldFail: true,
8517 expectedError: ":UNEXPECTED_MESSAGE:",
8518 })
8519
8520 testCases = append(testCases, testCase{
8521 testType: serverTest,
8522 name: "SecondClientHelloMissingKeyShare",
8523 config: Config{
8524 MaxVersion: VersionTLS13,
8525 DefaultCurves: []CurveID{},
8526 Bugs: ProtocolBugs{
8527 SecondClientHelloMissingKeyShare: true,
8528 },
8529 },
8530 shouldFail: true,
8531 expectedError: ":MISSING_KEY_SHARE:",
8532 })
8533
8534 testCases = append(testCases, testCase{
8535 testType: serverTest,
8536 name: "SecondClientHelloWrongCurve",
8537 config: Config{
8538 MaxVersion: VersionTLS13,
8539 DefaultCurves: []CurveID{},
8540 Bugs: ProtocolBugs{
8541 MisinterpretHelloRetryRequestCurve: CurveP521,
8542 },
8543 },
8544 shouldFail: true,
8545 expectedError: ":WRONG_CURVE:",
8546 })
8547
8548 testCases = append(testCases, testCase{
8549 name: "HelloRetryRequestVersionMismatch",
8550 config: Config{
8551 MaxVersion: VersionTLS13,
8552 // P-384 requires HelloRetryRequest in BoringSSL.
8553 CurvePreferences: []CurveID{CurveP384},
8554 Bugs: ProtocolBugs{
8555 SendServerHelloVersion: 0x0305,
8556 },
8557 },
8558 shouldFail: true,
8559 expectedError: ":WRONG_VERSION_NUMBER:",
8560 })
8561
8562 testCases = append(testCases, testCase{
8563 name: "HelloRetryRequestCurveMismatch",
8564 config: Config{
8565 MaxVersion: VersionTLS13,
8566 // P-384 requires HelloRetryRequest in BoringSSL.
8567 CurvePreferences: []CurveID{CurveP384},
8568 Bugs: ProtocolBugs{
8569 // Send P-384 (correct) in the HelloRetryRequest.
8570 SendHelloRetryRequestCurve: CurveP384,
8571 // But send P-256 in the ServerHello.
8572 SendCurve: CurveP256,
8573 },
8574 },
8575 shouldFail: true,
8576 expectedError: ":WRONG_CURVE:",
8577 })
8578
8579 // Test the server selecting a curve that requires a HelloRetryRequest
8580 // without sending it.
8581 testCases = append(testCases, testCase{
8582 name: "SkipHelloRetryRequest",
8583 config: Config{
8584 MaxVersion: VersionTLS13,
8585 // P-384 requires HelloRetryRequest in BoringSSL.
8586 CurvePreferences: []CurveID{CurveP384},
8587 Bugs: ProtocolBugs{
8588 SkipHelloRetryRequest: true,
8589 },
8590 },
8591 shouldFail: true,
8592 expectedError: ":WRONG_CURVE:",
8593 })
David Benjamin8a8349b2016-08-18 02:32:23 -04008594
8595 testCases = append(testCases, testCase{
8596 name: "TLS13-RequestContextInHandshake",
8597 config: Config{
8598 MaxVersion: VersionTLS13,
8599 MinVersion: VersionTLS13,
8600 ClientAuth: RequireAnyClientCert,
8601 Bugs: ProtocolBugs{
8602 SendRequestContext: []byte("request context"),
8603 },
8604 },
8605 flags: []string{
8606 "-cert-file", path.Join(*resourceDir, rsaCertificateFile),
8607 "-key-file", path.Join(*resourceDir, rsaKeyFile),
8608 },
8609 shouldFail: true,
8610 expectedError: ":DECODE_ERROR:",
8611 })
David Benjamin7e1f9842016-09-20 19:24:40 -04008612
8613 testCases = append(testCases, testCase{
8614 testType: serverTest,
8615 name: "TLS13-TrailingKeyShareData",
8616 config: Config{
8617 MaxVersion: VersionTLS13,
8618 Bugs: ProtocolBugs{
8619 TrailingKeyShareData: true,
8620 },
8621 },
8622 shouldFail: true,
8623 expectedError: ":DECODE_ERROR:",
8624 })
David Benjamin7f78df42016-10-05 22:33:19 -04008625
8626 testCases = append(testCases, testCase{
8627 name: "TLS13-AlwaysSelectPSKIdentity",
8628 config: Config{
8629 MaxVersion: VersionTLS13,
8630 Bugs: ProtocolBugs{
8631 AlwaysSelectPSKIdentity: true,
8632 },
8633 },
8634 shouldFail: true,
8635 expectedError: ":UNEXPECTED_EXTENSION:",
8636 })
8637
8638 testCases = append(testCases, testCase{
8639 name: "TLS13-InvalidPSKIdentity",
8640 config: Config{
8641 MaxVersion: VersionTLS13,
8642 Bugs: ProtocolBugs{
8643 SelectPSKIdentityOnResume: 1,
8644 },
8645 },
8646 resumeSession: true,
8647 shouldFail: true,
8648 expectedError: ":PSK_IDENTITY_NOT_FOUND:",
8649 })
David Benjamin1286bee2016-10-07 15:25:06 -04008650
8651 // Test that unknown NewSessionTicket extensions are tolerated.
8652 testCases = append(testCases, testCase{
8653 name: "TLS13-CustomTicketExtension",
8654 config: Config{
8655 MaxVersion: VersionTLS13,
8656 Bugs: ProtocolBugs{
8657 CustomTicketExtension: "1234",
8658 },
8659 },
8660 })
Steven Valdez143e8b32016-07-11 13:19:03 -04008661}
8662
David Benjaminf3fbade2016-09-19 13:08:16 -04008663func addPeekTests() {
8664 // Test SSL_peek works, including on empty records.
8665 testCases = append(testCases, testCase{
8666 name: "Peek-Basic",
8667 sendEmptyRecords: 1,
8668 flags: []string{"-peek-then-read"},
8669 })
8670
8671 // Test SSL_peek can drive the initial handshake.
8672 testCases = append(testCases, testCase{
8673 name: "Peek-ImplicitHandshake",
8674 flags: []string{
8675 "-peek-then-read",
8676 "-implicit-handshake",
8677 },
8678 })
8679
8680 // Test SSL_peek can discover and drive a renegotiation.
8681 testCases = append(testCases, testCase{
8682 name: "Peek-Renegotiate",
8683 config: Config{
8684 MaxVersion: VersionTLS12,
8685 },
8686 renegotiate: 1,
8687 flags: []string{
8688 "-peek-then-read",
8689 "-renegotiate-freely",
8690 "-expect-total-renegotiations", "1",
8691 },
8692 })
8693
8694 // Test SSL_peek can discover a close_notify.
8695 testCases = append(testCases, testCase{
8696 name: "Peek-Shutdown",
8697 config: Config{
8698 Bugs: ProtocolBugs{
8699 ExpectCloseNotify: true,
8700 },
8701 },
8702 flags: []string{
8703 "-peek-then-read",
8704 "-check-close-notify",
8705 },
8706 })
8707
8708 // Test SSL_peek can discover an alert.
8709 testCases = append(testCases, testCase{
8710 name: "Peek-Alert",
8711 config: Config{
8712 Bugs: ProtocolBugs{
8713 SendSpuriousAlert: alertRecordOverflow,
8714 },
8715 },
8716 flags: []string{"-peek-then-read"},
8717 shouldFail: true,
8718 expectedError: ":TLSV1_ALERT_RECORD_OVERFLOW:",
8719 })
8720
8721 // Test SSL_peek can handle KeyUpdate.
8722 testCases = append(testCases, testCase{
8723 name: "Peek-KeyUpdate",
8724 config: Config{
8725 MaxVersion: VersionTLS13,
8726 Bugs: ProtocolBugs{
8727 SendKeyUpdateBeforeEveryAppDataRecord: true,
8728 },
8729 },
8730 flags: []string{"-peek-then-read"},
8731 })
8732}
8733
Adam Langley7c803a62015-06-15 15:35:05 -07008734func worker(statusChan chan statusMsg, c chan *testCase, shimPath string, wg *sync.WaitGroup) {
Adam Langley95c29f32014-06-20 12:00:00 -07008735 defer wg.Done()
8736
8737 for test := range c {
Adam Langley69a01602014-11-17 17:26:55 -08008738 var err error
8739
8740 if *mallocTest < 0 {
8741 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008742 err = runTest(test, shimPath, -1)
Adam Langley69a01602014-11-17 17:26:55 -08008743 } else {
8744 for mallocNumToFail := int64(*mallocTest); ; mallocNumToFail++ {
8745 statusChan <- statusMsg{test: test, started: true}
Adam Langley7c803a62015-06-15 15:35:05 -07008746 if err = runTest(test, shimPath, mallocNumToFail); err != errMoreMallocs {
Adam Langley69a01602014-11-17 17:26:55 -08008747 if err != nil {
8748 fmt.Printf("\n\nmalloc test failed at %d: %s\n", mallocNumToFail, err)
8749 }
8750 break
8751 }
8752 }
8753 }
Adam Langley95c29f32014-06-20 12:00:00 -07008754 statusChan <- statusMsg{test: test, err: err}
8755 }
8756}
8757
8758type statusMsg struct {
8759 test *testCase
8760 started bool
8761 err error
8762}
8763
David Benjamin5f237bc2015-02-11 17:14:15 -05008764func statusPrinter(doneChan chan *testOutput, statusChan chan statusMsg, total int) {
EKR842ae6c2016-07-27 09:22:05 +02008765 var started, done, failed, unimplemented, lineLen int
Adam Langley95c29f32014-06-20 12:00:00 -07008766
David Benjamin5f237bc2015-02-11 17:14:15 -05008767 testOutput := newTestOutput()
Adam Langley95c29f32014-06-20 12:00:00 -07008768 for msg := range statusChan {
David Benjamin5f237bc2015-02-11 17:14:15 -05008769 if !*pipe {
8770 // Erase the previous status line.
David Benjamin87c8a642015-02-21 01:54:29 -05008771 var erase string
8772 for i := 0; i < lineLen; i++ {
8773 erase += "\b \b"
8774 }
8775 fmt.Print(erase)
David Benjamin5f237bc2015-02-11 17:14:15 -05008776 }
8777
Adam Langley95c29f32014-06-20 12:00:00 -07008778 if msg.started {
8779 started++
8780 } else {
8781 done++
David Benjamin5f237bc2015-02-11 17:14:15 -05008782
8783 if msg.err != nil {
EKR842ae6c2016-07-27 09:22:05 +02008784 if msg.err == errUnimplemented {
8785 if *pipe {
8786 // Print each test instead of a status line.
8787 fmt.Printf("UNIMPLEMENTED (%s)\n", msg.test.name)
8788 }
8789 unimplemented++
8790 testOutput.addResult(msg.test.name, "UNIMPLEMENTED")
8791 } else {
8792 fmt.Printf("FAILED (%s)\n%s\n", msg.test.name, msg.err)
8793 failed++
8794 testOutput.addResult(msg.test.name, "FAIL")
8795 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008796 } else {
8797 if *pipe {
8798 // Print each test instead of a status line.
8799 fmt.Printf("PASSED (%s)\n", msg.test.name)
8800 }
8801 testOutput.addResult(msg.test.name, "PASS")
8802 }
Adam Langley95c29f32014-06-20 12:00:00 -07008803 }
8804
David Benjamin5f237bc2015-02-11 17:14:15 -05008805 if !*pipe {
8806 // Print a new status line.
EKR842ae6c2016-07-27 09:22:05 +02008807 line := fmt.Sprintf("%d/%d/%d/%d/%d", failed, unimplemented, done, started, total)
David Benjamin5f237bc2015-02-11 17:14:15 -05008808 lineLen = len(line)
8809 os.Stdout.WriteString(line)
Adam Langley95c29f32014-06-20 12:00:00 -07008810 }
Adam Langley95c29f32014-06-20 12:00:00 -07008811 }
David Benjamin5f237bc2015-02-11 17:14:15 -05008812
8813 doneChan <- testOutput
Adam Langley95c29f32014-06-20 12:00:00 -07008814}
8815
8816func main() {
Adam Langley95c29f32014-06-20 12:00:00 -07008817 flag.Parse()
Adam Langley7c803a62015-06-15 15:35:05 -07008818 *resourceDir = path.Clean(*resourceDir)
David Benjamin33863262016-07-08 17:20:12 -07008819 initCertificates()
Adam Langley95c29f32014-06-20 12:00:00 -07008820
Adam Langley7c803a62015-06-15 15:35:05 -07008821 addBasicTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008822 addCipherSuiteTests()
8823 addBadECDSASignatureTests()
Adam Langley80842bd2014-06-20 12:00:00 -07008824 addCBCPaddingTests()
Kenny Root7fdeaf12014-08-05 15:23:37 -07008825 addCBCSplittingTests()
David Benjamin636293b2014-07-08 17:59:18 -04008826 addClientAuthTests()
Adam Langley524e7172015-02-20 16:04:00 -08008827 addDDoSCallbackTests()
David Benjamin7e2e6cf2014-08-07 17:44:24 -04008828 addVersionNegotiationTests()
David Benjaminaccb4542014-12-12 23:44:33 -05008829 addMinimumVersionTests()
David Benjamine78bfde2014-09-06 12:45:15 -04008830 addExtensionTests()
David Benjamin01fe8202014-09-24 15:21:44 -04008831 addResumptionVersionTests()
Adam Langley75712922014-10-10 16:23:43 -07008832 addExtendedMasterSecretTests()
Adam Langley2ae77d22014-10-28 17:29:33 -07008833 addRenegotiationTests()
David Benjamin5e961c12014-11-07 01:48:35 -05008834 addDTLSReplayTests()
Nick Harper60edffd2016-06-21 15:19:24 -07008835 addSignatureAlgorithmTests()
David Benjamin83f90402015-01-27 01:09:43 -05008836 addDTLSRetransmitTests()
David Benjaminc565ebb2015-04-03 04:06:36 -04008837 addExportKeyingMaterialTests()
Adam Langleyaf0e32c2015-06-03 09:57:23 -07008838 addTLSUniqueTests()
Adam Langley09505632015-07-30 18:10:13 -07008839 addCustomExtensionTests()
David Benjaminb36a3952015-12-01 18:53:13 -05008840 addRSAClientKeyExchangeTests()
David Benjamin8c2b3bf2015-12-18 20:55:44 -05008841 addCurveTests()
Matt Braithwaite54217e42016-06-13 13:03:47 -07008842 addCECPQ1Tests()
David Benjamin5c4e8572016-08-19 17:44:53 -04008843 addDHEGroupSizeTests()
Steven Valdez5b986082016-09-01 12:29:49 -04008844 addSessionTicketTests()
David Benjaminc9ae27c2016-06-24 22:56:37 -04008845 addTLS13RecordTests()
David Benjamin582ba042016-07-07 12:33:25 -07008846 addAllStateMachineCoverageTests()
David Benjamin82261be2016-07-07 14:32:50 -07008847 addChangeCipherSpecTests()
David Benjamin0b8d5da2016-07-15 00:39:56 -04008848 addWrongMessageTypeTests()
David Benjamin639846e2016-09-09 11:41:18 -04008849 addTrailingMessageDataTests()
Steven Valdez143e8b32016-07-11 13:19:03 -04008850 addTLS13HandshakeTests()
David Benjaminf3fbade2016-09-19 13:08:16 -04008851 addPeekTests()
Adam Langley95c29f32014-06-20 12:00:00 -07008852
8853 var wg sync.WaitGroup
8854
Adam Langley7c803a62015-06-15 15:35:05 -07008855 statusChan := make(chan statusMsg, *numWorkers)
8856 testChan := make(chan *testCase, *numWorkers)
David Benjamin5f237bc2015-02-11 17:14:15 -05008857 doneChan := make(chan *testOutput)
Adam Langley95c29f32014-06-20 12:00:00 -07008858
EKRf71d7ed2016-08-06 13:25:12 -07008859 if len(*shimConfigFile) != 0 {
8860 encoded, err := ioutil.ReadFile(*shimConfigFile)
8861 if err != nil {
8862 fmt.Fprintf(os.Stderr, "Couldn't read config file %q: %s\n", *shimConfigFile, err)
8863 os.Exit(1)
8864 }
8865
8866 if err := json.Unmarshal(encoded, &shimConfig); err != nil {
8867 fmt.Fprintf(os.Stderr, "Couldn't decode config file %q: %s\n", *shimConfigFile, err)
8868 os.Exit(1)
8869 }
8870 }
8871
David Benjamin025b3d32014-07-01 19:53:04 -04008872 go statusPrinter(doneChan, statusChan, len(testCases))
Adam Langley95c29f32014-06-20 12:00:00 -07008873
Adam Langley7c803a62015-06-15 15:35:05 -07008874 for i := 0; i < *numWorkers; i++ {
Adam Langley95c29f32014-06-20 12:00:00 -07008875 wg.Add(1)
Adam Langley7c803a62015-06-15 15:35:05 -07008876 go worker(statusChan, testChan, *shimPath, &wg)
Adam Langley95c29f32014-06-20 12:00:00 -07008877 }
8878
David Benjamin270f0a72016-03-17 14:41:36 -04008879 var foundTest bool
David Benjamin025b3d32014-07-01 19:53:04 -04008880 for i := range testCases {
David Benjamin17e12922016-07-28 18:04:43 -04008881 matched := true
8882 if len(*testToRun) != 0 {
8883 var err error
8884 matched, err = filepath.Match(*testToRun, testCases[i].name)
8885 if err != nil {
8886 fmt.Fprintf(os.Stderr, "Error matching pattern: %s\n", err)
8887 os.Exit(1)
8888 }
8889 }
8890
EKRf71d7ed2016-08-06 13:25:12 -07008891 if !*includeDisabled {
8892 for pattern := range shimConfig.DisabledTests {
8893 isDisabled, err := filepath.Match(pattern, testCases[i].name)
8894 if err != nil {
8895 fmt.Fprintf(os.Stderr, "Error matching pattern %q from config file: %s\n", pattern, err)
8896 os.Exit(1)
8897 }
8898
8899 if isDisabled {
8900 matched = false
8901 break
8902 }
8903 }
8904 }
8905
David Benjamin17e12922016-07-28 18:04:43 -04008906 if matched {
David Benjamin270f0a72016-03-17 14:41:36 -04008907 foundTest = true
David Benjamin025b3d32014-07-01 19:53:04 -04008908 testChan <- &testCases[i]
Adam Langley95c29f32014-06-20 12:00:00 -07008909 }
8910 }
David Benjamin17e12922016-07-28 18:04:43 -04008911
David Benjamin270f0a72016-03-17 14:41:36 -04008912 if !foundTest {
EKRf71d7ed2016-08-06 13:25:12 -07008913 fmt.Fprintf(os.Stderr, "No tests run\n")
David Benjamin270f0a72016-03-17 14:41:36 -04008914 os.Exit(1)
8915 }
Adam Langley95c29f32014-06-20 12:00:00 -07008916
8917 close(testChan)
8918 wg.Wait()
8919 close(statusChan)
David Benjamin5f237bc2015-02-11 17:14:15 -05008920 testOutput := <-doneChan
Adam Langley95c29f32014-06-20 12:00:00 -07008921
8922 fmt.Printf("\n")
David Benjamin5f237bc2015-02-11 17:14:15 -05008923
8924 if *jsonOutput != "" {
8925 if err := testOutput.writeTo(*jsonOutput); err != nil {
8926 fmt.Fprintf(os.Stderr, "Error: %s\n", err)
8927 }
8928 }
David Benjamin2ab7a862015-04-04 17:02:18 -04008929
EKR842ae6c2016-07-27 09:22:05 +02008930 if !*allowUnimplemented && testOutput.NumFailuresByType["UNIMPLEMENTED"] > 0 {
8931 os.Exit(1)
8932 }
8933
8934 if !testOutput.noneFailed {
David Benjamin2ab7a862015-04-04 17:02:18 -04008935 os.Exit(1)
8936 }
Adam Langley95c29f32014-06-20 12:00:00 -07008937}